On Tue, 2016 May 24 22:42+0200, Arthur de Jong wrote:
>
> At the very least it is weird behaviour. I don't expect any NSS module
> would return useful information. It could be a compat lookup thing but
> I thought it only worked on "+" entries, not "*" and those entries are
> only supported in flat files (/etc/passwd, /etc/shadow).
>
> If you could track it down I would be very interested to know why some
> application would do that. If this is some kind of standard use of the
> API I'm not aware of perhaps that would be an argument to change the
> behaviour of nslcd.
>
> Running nslcd in debug mode will show application pids that perform
> the request, that will probably help in tracking it down.
Ah, yes, that is very helpful. I have some information for you.
The culprit here is Bash, although what specifically within Bash is
harder to suss out. The issue does appear to be in the bash_completion
logic, because if I disable that, the "*" requests go away.
The completion logic is about as close to line noise as typical Perl, so
I can't make much headway in there. But strace shows a connect() call to
the nslcd socket for each request, and no other connect()s, so I ran a
debug build of bash in a debugger.
After picking through the backtrace, I've found exactly what is
generating the request. Below, I've copied the entire shell function in
question (from /usr/share/bash-completion/bash_completion), and have
marked the offending line:
# This function quotes the argument in a way so that readline dequoting
# results in the original argument. This is necessary for at least
# `compgen' which requires its arguments quoted/escaped:
#
# $ ls "a'b/"
# c
# $ compgen -f "a'b/" # Wrong, doesn't return output
# $ compgen -f "a\'b/" # Good
# a\'b/c
#
# See also:
# -
http://lists.gnu.org/archive/html/bug-bash/2009-03/msg00155.html
# -
http://www.mail-archive.com/bash-compl...@lists.alioth.\
#
debian.org/msg01944.html
# @param $1 Argument to quote
# @param $2 Name of variable to return result to
_quote_readline_by_ref()
{
if [ -z "$1" ]; then
# avoid quoting if empty
printf -v $2 %s "$1"
elif [[ $1 == \'* ]]; then
# Leave out first character
printf -v $2 %s "${1:1}"
elif [[ $1 == ~* ]]; then <---------------- HERE
# avoid escaping first ~
printf -v $2 ~%q "${1:1}"
else
printf -v $2 %q "$1"
fi
# Replace double escaping ( \\ ) by single ( \ )
# This happens always when argument is already escaped at cmdline,
# and passed to this function as e.g.: file\ with\ spaces
[[ ${!2} == *\\* ]] && printf -v $2 %s "${1//\\\\/\\}"
# If result becomes quoted like this: $'string', re-evaluate in order to
# drop the additional quoting. See also:
http://www.mail-archive.com/
#
bash-compl...@lists.alioth.debian.org/msg01942.html
[[ ${!2} == \$* ]] && eval $2=${!2}
} # _quote_readline_by_ref()
There are other instances of "~*" in the file, but they all have a
backslash escaping the tilde.
Would you agree that this appears to be a bug in bash-completion?