LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 06-30-2010, 07:20 AM   #1
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,895

Rep: Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015
"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.

Last edited by GazL; 06-30-2010 at 07:29 AM.
 
Old 06-30-2010, 07:34 AM   #2
gapan
Member
 
Registered: Feb 2007
Posts: 378

Rep: Reputation: 163Reputation: 163
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.
 
Old 06-30-2010, 07:37 AM   #3
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
Odd - it works for me on Slackware64 13.1
 
Old 06-30-2010, 07:38 AM   #4
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,895

Original Poster
Rep: Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015
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?
 
Old 06-30-2010, 07:43 AM   #5
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,895

Original Poster
Rep: Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015
Quote:
Originally Posted by bgeddy View Post
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.

Last edited by GazL; 06-30-2010 at 07:47 AM.
 
Old 06-30-2010, 07:52 AM   #6
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
Oops - sorry I had a bit of a brain freeze there somehow. Works the same for me as you. Must be half asleep
 
Old 06-30-2010, 09:51 AM   #7
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,895

Original Poster
Rep: Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015Reputation: 5015
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: A Unix/Linux "Where's Waldo?" Or "Who Wants Some PI?" LXer Syndicated Linux News 0 01-23-2009 01:00 PM
X: video drivers "ati" and "fglrx" show same fonts differently simopal6 Linux - Software 7 07-30-2008 02:36 AM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM
why java panels behaves differently in linux and solaris ?? alred Programming 2 07-20-2006 02:21 AM
applet on linux server behaves differently naijaguy Programming 3 01-07-2005 02:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 03:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration