Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/libbb/run_shell.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/libbb/run_shell.c
r821 r1770 29 29 */ 30 30 31 #include <stdio.h>32 #include <errno.h>33 #include <unistd.h>34 #include <string.h>35 #include <stdlib.h>36 #include <syslog.h>37 #include <ctype.h>38 31 #include "libbb.h" 39 #if def CONFIG_SELINUX32 #if ENABLE_SELINUX 40 33 #include <selinux/selinux.h> /* for setexeccon */ 41 34 #endif 42 35 43 #if def CONFIG_SELINUX44 static security_context_t current_sid =NULL;36 #if ENABLE_SELINUX 37 static security_context_t current_sid; 45 38 46 39 void 47 40 renew_current_security_context(void) 48 41 { 49 if (current_sid) 50 freecon(current_sid); /* Release old context */ 51 52 getcon(¤t_sid); /* update */ 53 54 return; 42 if (current_sid) 43 freecon(current_sid); /* Release old context */ 44 getcon(¤t_sid); /* update */ 55 45 } 56 46 void 57 47 set_current_security_context(security_context_t sid) 58 48 { 59 if (current_sid) 60 freecon(current_sid); /* Release old context */ 61 62 current_sid=sid; 63 64 return; 49 if (current_sid) 50 freecon(current_sid); /* Release old context */ 51 current_sid = sid; 65 52 } 66 53 … … 72 59 arguments. */ 73 60 74 void run_shell (const char *shell, int loginshell, const char *command, const char **additional_args)61 void run_shell(const char *shell, int loginshell, const char *command, const char **additional_args) 75 62 { 76 63 const char **args; … … 78 65 int additional_args_cnt = 0; 79 66 80 for ( args = additional_args; args && *args; args++)67 for (args = additional_args; args && *args; args++) 81 68 additional_args_cnt++; 82 69 83 args = (const char **) xmalloc (sizeof (char *) * ( 4 + additional_args_cnt));70 args = xmalloc(sizeof(char*) * (4 + additional_args_cnt)); 84 71 85 args [0] = bb_get_last_path_component ( bb_xstrdup ( shell));72 args[0] = bb_get_last_path_component(xstrdup(shell)); 86 73 87 if ( loginshell)88 args [0] = bb_xasprintf ("-%s", args[0]);74 if (loginshell) 75 args[0] = xasprintf("-%s", args[0]); 89 76 90 if ( command) {91 args 92 args 77 if (command) { 78 args[argno++] = "-c"; 79 args[argno++] = command; 93 80 } 94 if ( additional_args) {95 for ( ; *additional_args; ++additional_args)96 args 81 if (additional_args) { 82 for (; *additional_args; ++additional_args) 83 args[argno++] = *additional_args; 97 84 } 98 args [argno] = 0;99 #if def CONFIG_SELINUX100 if ( (current_sid) && (!setexeccon(current_sid))) {101 102 85 args[argno] = NULL; 86 #if ENABLE_SELINUX 87 if (current_sid && !setexeccon(current_sid)) { 88 freecon(current_sid); 89 execve(shell, (char **) args, environ); 103 90 } else 104 91 #endif 105 execv ( shell, (char **) args);106 bb_perror_msg_and_die ( "cannot run %s", shell);92 execv(shell, (char **) args); 93 bb_perror_msg_and_die("cannot run %s", shell); 107 94 }
Note:
See TracChangeset
for help on using the changeset viewer.