Convert a chunk of usage.h to USE_ and SKIP_ (more to do there), and fix a
[oweals/busybox.git] / loginutils / su.c
index 04c213e4e9c0d86035834f98dd4538c7b5b323d7..b0227787ad3095c386da60ea50d38650c468c220 100644 (file)
@@ -1,4 +1,7 @@
 /* vi: set sw=4 ts=4: */
+/*
+   Licensed under the GPL v2, see the file LICENSE in this tarball.
+*/
 
 #include <fcntl.h>
 #include <signal.h>
 
 #include "busybox.h"
 
-
-
 /* The shell to run if none is given in the user's passwd entry.  */
+#ifndef DEFAULT_SHELL
 #define DEFAULT_SHELL "/bin/sh"
+#endif
+
+/* Default user.  */
 #define DEFAULT_USER  "root"
 
-//#define SYSLOG_SUCCESS
+/* #define SYSLOG_SUCCESS */
 #define SYSLOG_FAILURE
 
 
@@ -32,7 +37,8 @@
 /* Log the fact that someone has run su */
 
 # if defined( SYSLOG_SUCCESS ) && defined( SYSLOG_FAILURE )
-static void log_su (const char *successful, const char *old_user, const char *tty)
+static void log_su (const char *successful, const char *old_user,
+                                       const char *tty)
 {
        syslog ( LOG_NOTICE, "%s%s on %s", successful, old_user, tty);
 }
@@ -85,21 +91,22 @@ int su_main ( int argc, char **argv )
     }
 
        /* get user if specified */
-       if ( optind < argc ) 
+       if ( optind < argc )
                opt_username = argv [optind++];
 
        if ( optind < argc )
                opt_args = argv + optind;
-               
+
 #if defined( SYSLOG_SUCCESS ) || defined( SYSLOG_FAILURE )
-#ifdef CONFIG_FEATURE_U_W_TMP
+#ifdef CONFIG_FEATURE_UTMP
        /* The utmp entry (via getlogin) is probably the best way to identify
           the user, especially if someone su's from a su-shell.  */
        old_user = getlogin ( );
        if ( !old_user )
 #endif
                {
-               /* getlogin can fail -- usually due to lack of utmp entry. Resort to getpwuid.  */
+               /* getlogin can fail -- usually due to lack of utmp entry.
+                  Resort to getpwuid.  */
                pw = getpwuid ( cur_uid );
                old_user = ( pw ? pw->pw_name : "" );
        }
@@ -109,16 +116,16 @@ int su_main ( int argc, char **argv )
 
        openlog ( bb_applet_name, 0, LOG_AUTH );
 #endif
-               
+
        pw = getpwnam ( opt_username );
        if ( !pw )
                bb_error_msg_and_die ( "user %s does not exist", opt_username );
-               
+
        /* Make sure pw->pw_shell is non-NULL.  It may be NULL when NEW_USER
           is a username that is retrieved via NIS (YP), but that doesn't have
           a default shell listed.  */
-       if ( !pw-> pw_shell || !pw->pw_shell [0] )
-               pw-> pw_shell = (char *) DEFAULT_SHELL;
+       if ( !pw->pw_shell || !pw->pw_shell [0] )
+               pw->pw_shell = (char *) DEFAULT_SHELL;
 
        if ((( cur_uid == 0 ) || correct_password ( pw ))) {
                log_su_successful(pw->pw_uid, old_user, tty );
@@ -134,7 +141,7 @@ int su_main ( int argc, char **argv )
        if ( !opt_shell && opt_preserve )
                opt_shell = getenv ( "SHELL" );
 
-       if ( opt_shell && cur_uid && restricted_shell ( pw-> pw_shell )) {
+       if ( opt_shell && cur_uid && restricted_shell ( pw->pw_shell )) {
                /* The user being su'd to has a nonstandard shell, and so is
                   probably a uucp account or has restricted access.  Don't
                   compromise the account by allowing access with a standard
@@ -146,13 +153,12 @@ int su_main ( int argc, char **argv )
        if ( !opt_shell )
                opt_shell = pw->pw_shell;
 
-       change_identity ( pw ); 
+       change_identity ( pw );
        setup_environment ( opt_shell, opt_loginshell, !opt_preserve, pw );
-       run_shell ( opt_shell, opt_loginshell, opt_command, (const char**)opt_args
-#ifdef CONFIG_SELINUX
-       , 0
+#if ENABLE_SELINUX
+       set_current_security_context(NULL);
 #endif
-       );
-       
+       run_shell ( opt_shell, opt_loginshell, opt_command, (const char**)opt_args);
+
        return EXIT_FAILURE;
 }