Bug 121629

Summary: su ignores all options except -s shell when passed -s shell; effects /etc/init.d/functions daemon() function
Product: [Fedora] Fedora Reporter: regs
Component: coreutilsAssignee: Tim Waugh <twaugh>
Status: CLOSED RAWHIDE QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 1   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2004-04-30 08:06:59 EDT Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Description regs 2004-04-23 21:22:59 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040124

Description of problem:
When su is passed the -s flag to specify a shell, it will do nothing
but open that shell.   The documentation for su seems to indicate that
-s shell should just override using the shell from /etc/passwd.

The upshot of this problem is that you can't script the running
commands as a different user and override the shell.  This breaks the
--user option to daemon() in /etc/init.d/functions.

Version-Release number of selected component (if applicable):
coreutils-5.0-24

How reproducible:
Always

Steps to Reproduce:
1. As root, execute 'su - rpm -s /bin/bash -c "ls /"

    

Actual Results:  You get an interactive shell for user rpm.

Expected Results:  The command 'ls /' should have been run as the user rpm

Additional info:

An example:

safe|18:24|~# su - rpm -c "ls /"      
bin      dev   home-old  lost+found  old-home       proc  scratch  var
boot     etc   initrd    media       opt            root  tmp      web
cvsroot  home  lib       mnt         perllocal.pod  sbin  usr
safe|18:25|~# su - rpm -s /bin/bash -c "ls /"
-su-2.05b$ id
uid=37(rpm) gid=37(rpm) groups=37(rpm)
-su-2.05b$ exit
logout
safe|18:25|~# id
uid=0(root) gid=0(root)
groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
safe|18:25|~# 

Here's a workaround to make --user work for daemon():

--- /etc/init.d/functions       2003-10-28 14:26:39.000000000 -0800
+++ /tmp/functions      2004-04-23 18:21:45.000000000 -0700
@@ -147,7 +147,8 @@
        if [ -z "$user" ]; then
           $nice initlog $INITLOG_ARGS -c "$*"
        else
-          $nice initlog $INITLOG_ARGS -c "su -s /bin/bash - $user -c
\"$*\""
+          #$nice initlog $INITLOG_ARGS -c "su -s /bin/bash - $user -c
\"$*\""
+          $nice initlog $INITLOG_ARGS -c "su - $user -c \"$*\""
        fi
        [ "$?" -eq 0 ] && success $"$base startup" || failure $"$base
startup"
 }
Comment 1 Tim Waugh 2004-04-29 11:01:55 EDT
Cross-linking for completeness:
http://mail.gnu.org/archive/html/bug-coreutils/2004-04/msg00169.html
Comment 2 Tim Waugh 2004-04-30 08:06:59 EDT
This seems to work fine in coreutils-5.2.1-6:

[tim@cyberelk tim]$ su -
Password:
[root@cyberelk root]# su - rpm -s /bin/bash -c "ls /"
Your default context is user_u:user_r:user_t.
 
Do you want to choose a different one? [n]
bin   dev  home    lib         misc  opt   root  selinux  tmp  var
boot  etc  initrd  lost+found  mnt   proc  sbin  sys      usr
[root@cyberelk root]# rpm -q coreutils
coreutils-5.2.1-6