LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   "su -l user -c command" behaves differently to other Linux/UNIX (https://www.linuxquestions.org/questions/slackware-14/su-l-user-c-command-behaves-differently-to-other-linux-unix-817162/)

GazL 06-30-2010 07:20 AM

"su -l user -c command" behaves differently to other Linux/UNIX
 
Hey guys, I've just noticed something odd with 'su'

When you run 'su' with both the '-' (aka -l) and -c command options like this: "su -l user -c command" it doesn't appear to run /etc/profile before running the specified command even though the -l option is specified.

If you run "su -l user" without the -c it does run /etc/profile.

Now, on other linux such as fedora it works as expected and runs both /etc/profile followed by the command specified on the '-c'. I'm fairly sure it used to work this way on Slackware (and every other UNIX I've ever used) too.

If someone could confirm they get the same thing on 13.1 and also if someone could test this on an older slackware box still using the previous version of shadow and let us know I'd appreciate it.
"su -l root -c env" is a good way to see, as you'll find most the environment variables are missing.

My suspicion is that this could be a bug in shadow.

gapan 06-30-2010 07:34 AM

I've seen a report that says that this is indeed a bug in shadow. This patch was proposed:

Code:

diff -urN shadow-4.1.4.2/libmisc/env.c shadow-4.1.4.2.new/libmisc/env.c
--- shadow-4.1.4.2/libmisc/env.c        2009-04-27 23:07:56.000000000 +0300
+++ shadow-4.1.4.2.new/libmisc/env.c        2010-06-22 12:32:07.000000000 +0300
@@ -251,7 +251,7 @@
                        if (strncmp (*cur, *bad, strlen (*bad)) != 0) {
                                continue;
                        }
-                        if (strchr (*cur, '/') != NULL) {
+                        if (strchr (*cur, '/') == NULL) {
                                continue;        /* OK */
                        }
                        for (move = cur; NULL != *move; move++) {

I haven't tried it, so I don't know if it's actually the case or if the patch works.

bgeddy 06-30-2010 07:37 AM

Odd - it works for me on Slackware64 13.1

GazL 06-30-2010 07:38 AM

Many thanks gapan, I'll give it a try.

I did try googling for it but couldn't see the wood for the trees. Where did you find that?

GazL 06-30-2010 07:43 AM

Quote:

Originally Posted by bgeddy (Post 4019316)
Odd - it works for me on Slackware64 13.1

How strange. This is all I get:
Code:

bash-4.1$ su -l root -c 'env'     
Password:
HZ=100
SHELL=/bin/bash
TERM=xterm
USER=root
MAIL=/var/spool/mail/root
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin
PWD=/root
SHLVL=1
HOME=/root
LOGNAME=root
DISPLAY=:0
_=/bin/env
bash-4.1$

I wonder if I've got something left over from running current that's messing things up then.

bgeddy 06-30-2010 07:52 AM

Oops - sorry I had a bit of a brain freeze there somehow. Works the same for me as you. Must be half asleep :)

GazL 06-30-2010 09:51 AM

BINGO! It wasn't the one mentioned above, but I eventually found:

upstream/trunk/src/su.c Revision 3194 :

* src/su.c: shell's name must be -su when a su fakes a login.

Code:

--- upstream/trunk/src/su.c    2010/03/23 13:05:06    3183
+++ upstream/trunk/src/su.c    2010/03/30 21:32:36    3194
@@ -1021,7 +1021,7 @@
                * Use the shell and create an argv
                * with the rest of the command line included.
                */
-              argv[-1] = shellstr;
+              argv[-1] = cp;
 #ifndef USE_PAM
                execve_shell (shellstr, &argv[-1], environ);
                err = errno;

Rebuilt after applying that and all is fine and dandy again.

Just sent a note and a patch for the slackbuild to Pat.


All times are GMT -5. The time now is 11:35 AM.