[Pkg-shadow-devel] Bug#276419: su appends the positional args to the command line

Nicolas François Nicolas François <nicolas.francois@centraliens.net>, 276419@bugs.debian.org
Fri, 8 Jul 2005 15:03:32 +0200


Hello Helmut,

a patch was included in the 4.0.3-36 release, but this one breaks some
scripts (see #317264).
Thus, I'm considering to revert this patch and fix your bug by documenting
the su behavior in its man page.

Here are some details on the issues introduced by the patch:

 * arguments are no more concatenated to provide only one string to the -c
   option of the shell:
   if some arguments are provided after the command provided by -c, these
   arguments are provided to the shell that interprets the command, not to
   the command itself.
   For example:
     $ bash -c 'echo $@' a b c
   will print "b c"
   but:
     $ bash -c echo a b c
   will only display an empty line
 * -c is no more provided to the shell when it is not provided to su:
   This break invocation of su like:
     $ su $LOGNAME bash
     /bin/bash: /bin/bash: cannot execute binary file

As the old behaviors are assumed by some packages (at least pbuilder,
and probably others), I think it is better to revert the patch, and just
document the fact that -c is always provided to the invoked shell (if
there are additional arguments), and that the arguments are provided in a
concatenated form to the -c flag. I will also indicate that since this
command line will be interpreted by the shell, an additional level of
escape may be needed.


Do you agree with this?


To fix your issues, there will still be the solutions of:
  * escaping quotes
  * writing the script in a file, so that there is no argument

  * use su -- - "$LOGNAME" bash -x
    instead of su -- - "$LOGNAME" -x

PS: I'm BCC'ing you to your address without nospam, sorry if you receive
this mail twice)

Best Regards,
-- 
Nekral