1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- #include "libbb.h"
- #if ENABLE_SELINUX
- #include <selinux/selinux.h> /* for setexeccon */
- #endif
- #if ENABLE_SELINUX
- static security_context_t current_sid;
- void FAST_FUNC renew_current_security_context(void)
- {
- freecon(current_sid);
- getcon(¤t_sid);
- }
- void FAST_FUNC set_current_security_context(security_context_t sid)
- {
- freecon(current_sid);
- current_sid = sid;
- }
- #endif
- void FAST_FUNC run_shell(const char *shell, int loginshell, const char **additional_args)
- {
- const char **args;
- args = additional_args;
- while (args && *args)
- args++;
- args = xmalloc(sizeof(char*) * (2 + (args - additional_args)));
- if (!shell || !shell[0])
- shell = DEFAULT_SHELL;
- args[0] = bb_get_last_path_component_nostrip(shell);
- if (loginshell)
- args[0] = xasprintf("-%s", args[0]);
- args[1] = NULL;
- if (additional_args) {
- int cnt = 1;
- for (;;)
- if ((args[cnt++] = *additional_args++) == NULL)
- break;
- }
- #if ENABLE_SELINUX
- if (current_sid)
- setexeccon(current_sid);
- if (ENABLE_FEATURE_CLEAN_UP)
- freecon(current_sid);
- #endif
- execv(shell, (char **) args);
- bb_perror_msg_and_die("can't execute '%s'", shell);
- }
|