|
Bugzilla – Full Text Bug Listing |
| Summary: | Scripts without proper shell header seem to execute with /bin/sh and not the SHELL env variable | ||
|---|---|---|---|
| Product: | Sudo | Reporter: | philburg2 |
| Component: | Sudo | Assignee: | Todd C. Miller <Todd.Miller> |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | CC: | philburg2 |
| Priority: | low | ||
| Version: | 1.8.10 | ||
| Hardware: | IBM | ||
| OS: | AIX | ||
When a script lacks the #! interpreter, sudo attempts to run it through /bin/sh as a last resort, which is consistent with most version of the execcp() function. Using the SHELL environment variable would be dangerous as it would allow the user to bypass /etc/sudoers and run any command simply by changing SHELL. It might make sense to use the login shell of the user the command is being run as but this represents a change in behavior from previous versions of sudo. Sudo 1.6.6 used the execvp() function directly which should have had the same behavior. The difference compared to sudo 1.6.6 is that AIX execvp() uses /usr/bin/sh to ezxecute scripts without the #! magic number but sudo is using the value of _PATH_BSHELL from paths.h which, on AIX, is /usr/bin/bsh. Sudo 1.8.11 will use /usr/bin/sh instead which should be consistent with the old sudo 1.6.6 behavior. Sudo 1.8.11 will use /usr/bin/sh instead of /usr/bin/bsh which restores the previous sudo behavior. |
Overview: Running a simple script results in failures if #!/bin/ksh or /bin/bash is omitted and script uses related ksh or bash functionality (functions in this example). This code functionality seems to be different from past sudo functionality (1.6.6 and 1.8.4 specifically). Reproduction: Seen in 1.8.9p5 and 1.8.10p3 thus far. Parameters used: Defaults !lecture, mail_no_perms, !umask, !env_reset Actual Results: Hypothetical faulty code: env|grep SHELL echo $SHELL function testing { echo "works" } testing exit 0 Produces faulty output: SHELL=/bin/ksh /bin/ksh /tmp/testfile.ksh: function: not found. works /tmp/testfile.ksh: Syntax error at line 8: `}' not expected. Expected Results: However, adding a shell header resolves the issue: #! /bin/ksh env|grep SHELL echo $SHELL function testing { echo "works" } testing exit 0 This produces a working output: SHELL=/bin/ksh /bin/ksh works Build: prebuilt bffs from the website. # sudo -V Sudo version 1.8.10p3 Configure options: --prefix=/opt/freeware --mandir=/opt/freeware/man --with-insults=disabled --with-logging=syslog --with-logfac=auth --with-editor=/usr/bin/vi --with-env-editor --enable-zlib=builtin --disable-nls --with-sendmail=/usr/sbin/sendmail --with-pam Sudoers policy plugin version 1.8.10p3 Sudoers file grammar version 43 Sudoers path: /etc/sudoers Authentication methods: 'pam' Platform: AIX, multiple OS levels. Above example came from 7100-02 server.