2 * Copyright (c) 1989 - 1994, Julianne Frances Haugh
3 * Copyright (c) 1996 - 2000, Marek Michałkiewicz
4 * Copyright (c) 2000 - 2006, Tomasz Kłoczko
5 * Copyright (c) 2007 - 2009, Nicolas François
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the copyright holders or contributors may not be used to
17 * endorse or promote products derived from this software without
18 * specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 /* Some parts substantially derived from an ancestor of:
34 su for GNU. Run a shell with substitute user and group IDs.
36 Copyright (C) 1992-2003 Free Software Foundation, Inc.
38 This program is free software; you can redistribute it and/or modify
39 it under the terms of the GNU General Public License as published by
40 the Free Software Foundation; either version 2, or (at your option)
43 This program is distributed in the hope that it will be useful,
44 but WITHOUT ANY WARRANTY; without even the implied warranty of
45 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46 GNU General Public License for more details.
48 You should have received a copy of the GNU General Public License
49 along with this program; if not, write to the Free Software
50 Foundation, Inc., 51 Franklin Street, Fifth Floor,
51 Boston, MA 02110-1301, USA. */
63 #include <sys/types.h>
64 #include "prototypes.h"
72 #include "exitcodes.h"
75 * Assorted #defines to control su's behavior
81 /* PID of the child, in case it needs to be killed */
82 static pid_t pid_child = 0;
84 /* not needed by sulog.c anymore */
85 static char name[BUFSIZ];
86 static char oldname[BUFSIZ];
88 /* If nonzero, change some environment vars to indicate the user su'd to. */
89 static bool change_environment;
92 static pam_handle_t *pamh = NULL;
93 static bool caught = false;
96 extern struct passwd pwent;
99 * External identifiers
102 extern char **newenvp;
103 extern char **environ;
104 extern size_t newenvc;
106 /* local function prototypes */
108 static void execve_shell (const char *shellstr,
111 static RETSIGTYPE kill_child (int s);
113 static RETSIGTYPE die (int);
114 static int iswheel (const char *);
115 #endif /* !USE_PAM */
119 * die - set or reset termio modes.
121 * die() is called before processing begins. signal() is then called
122 * with die() as the signal handler. If signal later calls die() with a
123 * signal number, the terminal modes are then reset.
125 static RETSIGTYPE die (int killed)
140 static int iswheel (const char *username)
144 grp = getgrnam ("wheel"); /* !USE_PAM, no need for xgetgrnam */
146 || (NULL == grp->gr_mem)) {
149 return is_on_list (grp->gr_mem, username);
151 #endif /* !USE_PAM */
153 static RETSIGTYPE kill_child (int unused(s))
155 if (0 != pid_child) {
156 (void) kill (pid_child, SIGKILL);
157 (void) fputs (_(" ...killed.\n"), stderr);
159 (void) fputs (_(" ...waiting for child to terminate.\n"),
165 /* borrowed from GNU sh-utils' "su.c" */
166 static bool restricted_shell (const char *shellstr)
171 while ((line = getusershell ()) != NULL) {
172 if (('#' != *line) && (strcmp (line, shellstr) == 0)) {
181 static void su_failure (const char *tty)
183 sulog (tty, false, oldname, name); /* log failed attempt */
185 if (getdef_bool ("SYSLOG_SU_ENAB")) {
186 SYSLOG (((0 != pwent.pw_uid) ? LOG_INFO : LOG_NOTICE,
188 ('\0' != oldname[0]) ? oldname : "???",
189 ('\0' != name[0]) ? name : "???"));
197 * execve_shell - Execute a shell with execve, or interpret it with
200 static void execve_shell (const char *shellstr,
205 (void) execve (shellstr, (char **) args, envp);
208 if (access (shellstr, R_OK|X_OK) == 0) {
210 * Assume this is a shell script (with no shebang).
211 * Interpret it with /bin/sh
215 while (NULL != args[n_args]) {
218 targs = (char **) xmalloc ((n_args + 3) * sizeof (args[0]));
221 targs[2] = xstrdup (shellstr);
222 targs[n_args+2] = NULL;
223 while (1 != n_args) {
224 targs[n_args+1] = args[n_args - 1];
228 (void) execve (SHELL, targs, envp);
235 /* Signal handler for parent process later */
236 static void catch_signals (unused int sig)
241 /* This I ripped out of su.c from sh-utils after the Mandrake pam patch
242 * have been applied. Some work was needed to get it integrated into
245 static void run_shell (const char *shellstr, char *args[], bool doshell,
254 if (child == 0) { /* child shell */
256 * PAM_DATA_SILENT is not supported by some modules, and
257 * there is no strong need to clean up the process space's
258 * memory since we will either call exec or exit.
259 pam_end (pamh, PAM_SUCCESS | PAM_DATA_SILENT);
263 (void) shell (shellstr, (char *) args[0], envp);
265 execve_shell (shellstr, (char **) args, envp);
268 exit (errno == ENOENT ? E_CMD_NOTFOUND : E_CMD_NOEXEC);
269 } else if ((pid_t)-1 == child) {
270 (void) fprintf (stderr,
271 _("%s: Cannot fork user shell\n"),
273 SYSLOG ((LOG_WARN, "Cannot execute %s", shellstr));
279 sigfillset (&ourset);
280 if (sigprocmask (SIG_BLOCK, &ourset, NULL) != 0) {
281 (void) fprintf (stderr,
282 _("%s: signal malfunction\n"),
287 struct sigaction action;
289 action.sa_handler = catch_signals;
290 sigemptyset (&action.sa_mask);
292 sigemptyset (&ourset);
294 if ( (sigaddset (&ourset, SIGTERM) != 0)
295 || (sigaddset (&ourset, SIGALRM) != 0)
296 || (sigaction (SIGTERM, &action, NULL) != 0)
297 || (sigprocmask (SIG_UNBLOCK, &ourset, NULL) != 0)
300 _("%s: signal masking malfunction\n"),
310 pid = waitpid (-1, &status, WUNTRACED);
312 if (((pid_t)-1 != pid) && (0 != WIFSTOPPED (status))) {
313 /* The child (shell) was suspended.
315 kill (getpid (), WSTOPSIG(status));
316 /* wake child when resumed */
319 } while (0 != WIFSTOPPED (status));
323 (void) fputs ("\n", stderr);
324 (void) fputs (_("Session terminated, terminating shell..."),
326 (void) kill (child, SIGTERM);
329 ret = pam_close_session (pamh, 0);
330 if (PAM_SUCCESS != ret) {
331 SYSLOG ((LOG_ERR, "pam_close_session: %s",
332 pam_strerror (pamh, ret)));
333 fprintf (stderr, _("%s: %s\n"), Prog, pam_strerror (pamh, ret));
334 (void) pam_end (pamh, ret);
338 ret = pam_end (pamh, PAM_SUCCESS);
341 (void) signal (SIGALRM, kill_child);
344 (void) wait (&status);
345 (void) fputs (_(" ...terminated.\n"), stderr);
348 exit ((0 != WIFEXITED (status)) ? WEXITSTATUS (status)
349 : WTERMSIG (status) + 128);
354 * usage - print command line syntax and exit
356 static void usage (int status)
358 fputs (_("Usage: su [options] [LOGIN]\n"
361 " -c, --command COMMAND pass COMMAND to the invoked shell\n"
362 " -h, --help display this help message and exit\n"
363 " -, -l, --login make the shell a login shell\n"
365 " --preserve-environment do not reset environment variables, and\n"
366 " keep the same shell\n"
367 " -s, --shell SHELL use SHELL instead of the default in passwd\n"
368 "\n"), (E_SUCCESS != status) ? stderr : stdout);
373 * su - switch user id
375 * su changes the user's ids to the values for the specified user. if
376 * no new user name is specified, "root" or UID 0 is used by default.
378 * Any additional arguments are passed to the user's shell. In
379 * particular, the argument "-c" will cause the next argument to be
380 * interpreted as a command by the common shell programs.
382 int main (int argc, char **argv)
385 const char *tty = NULL; /* Name of tty SU is run from */
386 bool doshell = false;
387 bool fakelogin = false;
390 struct passwd *pw = NULL;
391 char **envp = environ;
392 char *shellstr = NULL;
393 char *command = NULL;
401 RETSIGTYPE (*oldsig) (int);
404 struct spwd *spwd = 0;
409 #endif /* !USE_PAM */
413 (void) setlocale (LC_ALL, "");
414 (void) bindtextdomain (PACKAGE, LOCALEDIR);
415 (void) textdomain (PACKAGE);
417 change_environment = true;
420 * Get the program name. The program name is used as a prefix to
421 * most error messages.
423 Prog = Basename (argv[0]);
428 * Process the command line arguments.
433 * Parse the command line options.
435 int option_index = 0;
437 static struct option long_options[] = {
438 {"command", required_argument, NULL, 'c'},
439 {"help", no_argument, NULL, 'h'},
440 {"login", no_argument, NULL, 'l'},
441 {"preserve-environment", no_argument, NULL, 'p'},
442 {"shell", required_argument, NULL, 's'},
443 {NULL, 0, NULL, '\0'}
447 getopt_long (argc, argv, "c:hlmps:", long_options,
448 &option_index)) != -1) {
461 /* This will only have an effect if the target
462 * user do not have a restricted shell, or if
463 * su is called by root.
465 change_environment = false;
471 usage (E_USAGE); /* NOT REACHED */
475 if ((optind < argc) && (strcmp (argv[optind], "-") == 0)) {
479 && (strcmp (argv[optind], "--") == 0)) {
488 amroot = (my_uid == 0);
491 * Get the tty name. Entries will be logged indicating that the user
492 * tried to change to the named new user from the current terminal.
495 if ((isatty (0) != 0) && (NULL != tty)) {
497 is_console = console (tty);
501 * Be more paranoid, like su from SimplePAMApps. --marekm
505 _("%s: must be run from a terminal\n"),
513 * The next argument must be either a user ID, or some flag to a
514 * subshell. Pretty sticky since you can't have an argument which
515 * doesn't start with a "-" unless you specify the new user name.
516 * Any remaining arguments will be passed to the user's login shell.
518 if ((optind < argc) && ('-' != argv[optind][0])) {
519 STRFCPY (name, argv[optind++]); /* use this login id */
520 if ((optind < argc) && (strcmp (argv[optind], "--") == 0)) {
524 if ('\0' == name[0]) { /* use default user */
525 struct passwd *root_pw = getpwnam ("root");
526 if ((NULL != root_pw) && (0 == root_pw->pw_uid)) {
527 (void) strcpy (name, "root");
529 root_pw = getpwuid (0);
530 if (NULL == root_pw) {
531 SYSLOG ((LOG_CRIT, "There is no UID 0 user."));
534 (void) strcpy (name, root_pw->pw_name);
538 doshell = (argc == optind); /* any arguments remaining? */
539 if (NULL != command) {
544 * Get the user's real name. The current UID is used to determine
545 * who has executed su. That user ID must exist.
547 pw = get_my_pwent ();
550 _("%s: Cannot determine your user name.\n"),
552 SYSLOG ((LOG_WARN, "Cannot determine the user name of the caller (UID %lu)",
553 (unsigned long) my_uid));
556 STRFCPY (oldname, pw->pw_name);
561 * Sort out the password of user calling su, in case needed later
564 spwd = getspnam (oldname); /* !USE_PAM, no need for xgetspnam */
566 pw->pw_passwd = spwd->sp_pwdp;
568 oldpass = xstrdup (pw->pw_passwd);
569 #endif /* SU_ACCESS */
572 ret = pam_start ("su", name, &conv, &pamh);
573 if (PAM_SUCCESS != ret) {
574 SYSLOG ((LOG_ERR, "pam_start: error %d", ret);
576 _("%s: pam_start: error %d\n"),
581 ret = pam_set_item (pamh, PAM_TTY, (const void *) tty);
582 if (PAM_SUCCESS == ret) {
583 ret = pam_set_item (pamh, PAM_RUSER, (const void *) oldname);
585 if (PAM_SUCCESS != ret) {
586 SYSLOG ((LOG_ERR, "pam_set_item: %s",
587 pam_strerror (pamh, ret)));
588 fprintf (stderr, _("%s: %s\n"), Prog, pam_strerror (pamh, ret));
596 * This is the common point for validating a user whose name is
597 * known. It will be reached either by normal processing, or if the
598 * user is to be logged into a subsystem root.
600 * The password file entries for the user is gotten and the account
603 pw = xgetpwnam (name);
605 (void) fprintf (stderr, _("Unknown id: %s\n"), name);
611 if (strcmp (pw->pw_passwd, SHADOW_PASSWD_STRING) == 0) {
612 spwd = getspnam (name); /* !USE_PAM, no need for xgetspnam */
614 pw->pw_passwd = spwd->sp_pwdp;
617 #endif /* !USE_PAM */
620 /* If su is not called by root, and the target user has a restricted
621 * shell, the environment must be changed.
623 change_environment |= (restricted_shell (pwent.pw_shell) && !amroot);
626 * If a new login is being set up, the old environment will be
627 * ignored and a new one created later on.
628 * (note: in the case of a subsystem, the shell will be restricted,
629 * and this won't be executed on the first pass)
631 if (change_environment && fakelogin) {
633 * The terminal type will be left alone if it is present in
634 * the environment already.
636 cp = getenv ("TERM");
642 * For some terminals COLORTERM seems to be the only way
643 * for checking for that specific terminal. For instance,
644 * gnome-terminal sets its TERM as "xterm" but its
645 * COLORTERM as "gnome-terminal". The COLORTERM variable
646 * is also of use when running GNU screen since it sets
647 * TERM to "screen" but doesn't touch COLORTERM.
649 cp = getenv ("COLORTERM");
651 addenv ("COLORTERM", cp);
655 cp = getdef_str ("ENV_TZ");
657 addenv (('/' == *cp) ? tz (cp) : cp, NULL);
661 * The clock frequency will be reset to the login value if required
663 cp = getdef_str ("ENV_HZ");
665 addenv (cp, NULL); /* set the default $HZ, if one */
667 #endif /* !USE_PAM */
670 * Also leave DISPLAY and XAUTHORITY if present, else
671 * pam_xauth will not work.
673 cp = getenv ("DISPLAY");
675 addenv ("DISPLAY", cp);
677 cp = getenv ("XAUTHORITY");
679 addenv ("XAUTHORITY", cp);
682 while (NULL != *envp) {
683 addenv (*envp, NULL);
690 * BSD systems only allow "wheel" to SU to root. USG systems don't,
691 * so we make this a configurable option.
694 /* The original Shadow 3.3.2 did this differently. Do it like BSD:
696 * - check for UID 0 instead of name "root" - there are systems with
697 * several root accounts under different names,
699 * - check the contents of /etc/group instead of the current group
700 * set (you must be listed as a member, GID 0 is not sufficient).
702 * In addition to this traditional feature, we now have complete su
703 * access control (allow, deny, no password, own password). Thanks
704 * to Chris Evans <lady0110@sable.ox.ac.uk>.
708 if ( (0 == pwent.pw_uid)
709 && getdef_bool ("SU_WHEEL_ONLY")
710 && !iswheel (oldname)) {
712 _("You are not authorized to su %s\n"),
717 switch (check_su_auth (oldname, name)) {
718 case 0: /* normal su, require target user's password */
720 case 1: /* require no password */
721 pwent.pw_passwd = ""; /* XXX warning: const */
723 case 2: /* require own password */
724 puts (_("(Enter your own password)"));
725 pwent.pw_passwd = oldpass;
727 default: /* access denied (-1) or unexpected value */
729 _("You are not authorized to su %s\n"),
733 #endif /* SU_ACCESS */
735 #endif /* !USE_PAM */
737 /* If the user do not want to change the environment,
738 * use the current SHELL.
739 * (unless another shell is required by the command line)
741 if ((NULL == shellstr) && !change_environment) {
742 shellstr = getenv ("SHELL");
744 /* For users with non null UID, if this user has a restricted
745 * shell, the shell must be the one specified in /etc/passwd
747 if ( (NULL != shellstr)
749 && restricted_shell (pwent.pw_shell)) {
752 /* If the shell is not set at this time, use the shell specified
755 if (NULL == shellstr) {
756 shellstr = (char *) strdup (pwent.pw_shell);
760 * Set the default shell.
762 if ((NULL == shellstr) || ('\0' == shellstr[0])) {
766 (void) signal (SIGINT, SIG_IGN);
767 (void) signal (SIGQUIT, SIG_IGN);
769 ret = pam_authenticate (pamh, 0);
770 if (PAM_SUCCESS != ret) {
771 SYSLOG ((LOG_ERR, "pam_authenticate: %s",
772 pam_strerror (pamh, ret)));
773 fprintf (stderr, _("%s: %s\n"), Prog, pam_strerror (pamh, ret));
774 (void) pam_end (pamh, ret);
778 ret = pam_acct_mgmt (pamh, 0);
779 if (PAM_SUCCESS != ret) {
782 _("%s: %s\n(Ignored)\n"),
783 Prog, pam_strerror (pamh, ret));
784 } else if (PAM_NEW_AUTHTOK_REQD == ret) {
785 ret = pam_chauthtok (pamh, PAM_CHANGE_EXPIRED_AUTHTOK);
786 if (PAM_SUCCESS != ret) {
787 SYSLOG ((LOG_ERR, "pam_chauthtok: %s",
788 pam_strerror (pamh, ret)));
791 Prog, pam_strerror (pamh, ret));
792 (void) pam_end (pamh, ret);
796 SYSLOG ((LOG_ERR, "pam_acct_mgmt: %s",
797 pam_strerror (pamh, ret)));
800 Prog, pam_strerror (pamh, ret));
801 (void) pam_end (pamh, ret);
807 * Set up a signal handler in case the user types QUIT.
810 oldsig = signal (SIGQUIT, die);
813 * See if the system defined authentication method is being used.
814 * The first character of an administrator defined method is an '@'
817 if (!amroot && pw_auth (pwent.pw_passwd, name, PW_SU, (char *) 0)) {
818 SYSLOG ((pwent.pw_uid ? LOG_NOTICE : LOG_WARN,
819 "Authentication failed for %s", name));
820 fprintf(stderr, _("%s: Authentication failure\n"), Prog);
823 (void) signal (SIGQUIT, oldsig);
826 * Check to see if the account is expired. root gets to ignore any
827 * expired accounts, but normal users can't become a user with an
832 spwd = pwd_to_spwd (&pwent);
835 if (expire (&pwent, spwd)) {
836 /* !USE_PAM, no need for xgetpwnam */
837 struct passwd *pwd = getpwnam (name);
839 /* !USE_PAM, no need for xgetspnam */
840 spwd = getspnam (name);
848 * Check to see if the account permits "su". root gets to ignore any
849 * restricted accounts, but normal users can't become a user if
850 * there is a "SU" entry in the /etc/porttime file denying access to
854 if (!isttytime (pwent.pw_name, "SU", time ((time_t *) 0))) {
855 SYSLOG (((0 != pwent.pw_uid) ? LOG_WARN : LOG_CRIT,
856 "SU by %s to restricted account %s",
859 _("%s: You are not authorized to su at that time\n"),
864 #endif /* !USE_PAM */
866 (void) signal (SIGINT, SIG_DFL);
867 (void) signal (SIGQUIT, SIG_DFL);
869 cp = getdef_str ((pwent.pw_uid == 0) ? "ENV_SUPATH" : "ENV_PATH");
871 addenv ("PATH=/bin:/usr/bin", NULL);
872 } else if (strchr (cp, '=') != NULL) {
878 if (getenv ("IFS") != NULL) { /* don't export user IFS ... */
879 addenv ("IFS= \t\n", NULL); /* ... instead, set a safe IFS */
883 * Even if --shell is specified, the subsystem login test is based on
884 * the shell specified in /etc/passwd (not the one specified with
885 * --shell, which will be the one executed in the chroot later).
887 if ('*' == pwent.pw_shell[0]) { /* subsystem root required */
888 pwent.pw_shell++; /* skip the '*' */
889 subsystem (&pwent); /* figure out what to execute */
895 sulog (tty, true, oldname, name); /* save SU information */
899 if (getdef_bool ("SYSLOG_SU_ENAB")) {
900 SYSLOG ((LOG_INFO, "+ %s %s:%s", tty,
901 ('\0' != oldname[0]) ? oldname : "???",
902 ('\0' != name[0]) ? name : "???"));
907 /* set primary group id and supplementary groups */
908 if (setup_groups (&pwent) != 0) {
909 pam_end (pamh, PAM_ABORT);
914 * pam_setcred() may do things like resource limits, console groups,
915 * and much more, depending on the configured modules
917 ret = pam_setcred (pamh, PAM_ESTABLISH_CRED);
918 if (PAM_SUCCESS != ret) {
919 SYSLOG ((LOG_ERR, "pam_setcred: %s", pam_strerror (pamh, ret)));
920 fprintf (stderr, _("%s: %s\n"), Prog, pam_strerror (pamh, ret));
921 (void) pam_end (pamh, ret);
925 ret = pam_open_session (pamh, 0);
926 if (PAM_SUCCESS != ret) {
927 SYSLOG ((LOG_ERR, "pam_open_session: %s",
928 pam_strerror (pamh, ret)));
929 fprintf (stderr, _("%s: %s\n"), Prog, pam_strerror (pamh, ret));
930 pam_setcred (pamh, PAM_DELETE_CRED);
931 (void) pam_end (pamh, ret);
935 if (change_environment) {
936 /* we need to setup the environment *after* pam_open_session(),
937 * else the UID is changed before stuff like pam_xauth could
938 * run, and we cannot access /etc/shadow and co
940 environ = newenvp; /* make new environment active */
942 /* update environment with all pam set variables */
943 envcp = pam_getenvlist (pamh);
945 while (NULL != *envcp) {
946 addenv (*envcp, NULL);
952 /* become the new user */
953 if (change_uid (&pwent) != 0) {
954 pam_close_session (pamh, 0);
955 pam_setcred (pamh, PAM_DELETE_CRED);
956 (void) pam_end (pamh, PAM_ABORT);
960 environ = newenvp; /* make new environment active */
962 /* no limits if su from root (unless su must fake login's behavior) */
963 if (!amroot || fakelogin) {
964 setup_limits (&pwent);
967 if (setup_uid_gid (&pwent, is_console) != 0) {
970 #endif /* !USE_PAM */
972 if (change_environment) {
974 pwent.pw_shell = shellstr;
977 addenv ("HOME", pwent.pw_dir);
978 addenv ("USER", pwent.pw_name);
979 addenv ("LOGNAME", pwent.pw_name);
980 addenv ("SHELL", shellstr);
985 * This is a workaround for Linux libc bug/feature (?) - the
986 * /dev/log file descriptor is open without the close-on-exec flag
987 * and used to be passed to the new shell. There is "fcntl(LogFile,
988 * F_SETFD, 1)" in libc/misc/syslog.c, but it is commented out (at
989 * least in 5.4.33). Why? --marekm
994 * See if the user has extra arguments on the command line. In that
995 * case they will be provided to the new user's shell as arguments.
1000 cp = getdef_str ("SU_NAME");
1002 cp = Basename (shellstr);
1005 arg0 = xmalloc (strlen (cp) + 2);
1007 strcpy (arg0 + 1, cp);
1010 cp = Basename (shellstr);
1014 /* Position argv to the remaining arguments */
1016 if (NULL != command) {
1022 * Use the shell and create an argv
1023 * with the rest of the command line included.
1025 argv[-1] = shellstr;
1027 execve_shell (shellstr, &argv[-1], environ);
1029 (void) fputs (_("No shell\n"), stderr);
1030 SYSLOG ((LOG_WARN, "Cannot execute %s", shellstr));
1032 exit ((ENOENT == err) ? E_CMD_NOTFOUND : E_CMD_NOEXEC);
1034 run_shell (shellstr, &argv[-1], false, environ); /* no return */
1038 err = shell (shellstr, cp, environ);
1039 exit ((ENOENT == err) ? E_CMD_NOTFOUND : E_CMD_NOEXEC);
1041 run_shell (shellstr, &cp, true, environ);