- don't free user-supplied string (via -e)
[oweals/busybox.git] / libbb / run_shell.c
index 6be09088d76d5308fbbc337b81b672e57d4db25b..2ccb3a12c7d4833efe007afc34f9f26fdd1e057b 100644 (file)
  * SUCH DAMAGE.
  */
 
-#include <stdio.h>
-#include <errno.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <syslog.h>
-#include <ctype.h>
 #include "libbb.h"
-#ifdef CONFIG_SELINUX
+#if ENABLE_SELINUX
 #include <selinux/selinux.h>  /* for setexeccon  */
 #endif
 
-#ifdef CONFIG_SELINUX
+#if ENABLE_SELINUX
 static security_context_t current_sid;
 
-void
-renew_current_security_context(void)
+void FAST_FUNC renew_current_security_context(void)
 {
-       if (current_sid)
-               freecon(current_sid);  /* Release old context  */
+       freecon(current_sid);  /* Release old context  */
        getcon(&current_sid);  /* update */
 }
-void
-set_current_security_context(security_context_t sid)
+void FAST_FUNC set_current_security_context(security_context_t sid)
 {
-       if (current_sid)
-               freecon(current_sid);  /* Release old context  */
+       freecon(current_sid);  /* Release old context  */
        current_sid = sid;
 }
 
@@ -65,7 +54,7 @@ set_current_security_context(security_context_t sid)
    If ADDITIONAL_ARGS is nonzero, pass it to the shell as more
    arguments.  */
 
-void run_shell(const char *shell, int loginshell, const char *command, const char **additional_args)
+void FAST_FUNC run_shell(const char *shell, int loginshell, const char *command, const char **additional_args)
 {
        const char **args;
        int argno = 1;
@@ -76,7 +65,7 @@ void run_shell(const char *shell, int loginshell, const char *command, const cha
 
        args = xmalloc(sizeof(char*) * (4 + additional_args_cnt));
 
-       args[0] = bb_get_last_path_component(xstrdup(shell));
+       args[0] = bb_get_last_path_component_nostrip(xstrdup(shell));
 
        if (loginshell)
                args[0] = xasprintf("-%s", args[0]);
@@ -90,11 +79,11 @@ void run_shell(const char *shell, int loginshell, const char *command, const cha
                        args[argno++] = *additional_args;
        }
        args[argno] = NULL;
-#ifdef CONFIG_SELINUX
-       if (current_sid && !setexeccon(current_sid)) {
+#if ENABLE_SELINUX
+       if (current_sid)
+               setexeccon(current_sid);
+       if (ENABLE_FEATURE_CLEAN_UP)
                freecon(current_sid);
-               execve(shell, (char **) args, environ);
-       } else
 #endif
        execv(shell, (char **) args);
        bb_perror_msg_and_die("cannot run %s", shell);