aboutsummaryrefslogtreecommitdiff
path: root/libbb/run_shell.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/run_shell.c')
-rw-r--r--libbb/run_shell.c43
1 files changed, 33 insertions, 10 deletions
diff --git a/libbb/run_shell.c b/libbb/run_shell.c
index 993b4e711..67ff2a5f8 100644
--- a/libbb/run_shell.c
+++ b/libbb/run_shell.c
@@ -37,7 +37,33 @@
37#include <ctype.h> 37#include <ctype.h>
38#include "libbb.h" 38#include "libbb.h"
39#ifdef CONFIG_SELINUX 39#ifdef CONFIG_SELINUX
40#include <proc_secure.h> 40#include <selinux/selinux.h> /* for setexeccon */
41#endif
42
43#ifdef CONFIG_SELINUX
44static security_context_t current_sid=NULL;
45
46void
47renew_current_security_context(void)
48{
49 if (current_sid)
50 freecon(current_sid); /* Release old context */
51
52 getcon(&current_sid); /* update */
53
54 return;
55}
56void
57set_current_security_context(security_context_t sid)
58{
59 if (current_sid)
60 freecon(current_sid); /* Release old context */
61
62 current_sid=sid;
63
64 return;
65}
66
41#endif 67#endif
42 68
43/* Run SHELL, or DEFAULT_SHELL if SHELL is empty. 69/* Run SHELL, or DEFAULT_SHELL if SHELL is empty.
@@ -45,11 +71,7 @@
45 If ADDITIONAL_ARGS is nonzero, pass it to the shell as more 71 If ADDITIONAL_ARGS is nonzero, pass it to the shell as more
46 arguments. */ 72 arguments. */
47 73
48void run_shell ( const char *shell, int loginshell, const char *command, const char **additional_args 74void run_shell ( const char *shell, int loginshell, const char *command, const char **additional_args)
49#ifdef CONFIG_SELINUX
50 , security_id_t sid
51#endif
52)
53{ 75{
54 const char **args; 76 const char **args;
55 int argno = 1; 77 int argno = 1;
@@ -78,10 +100,11 @@ void run_shell ( const char *shell, int loginshell, const char *command, const c
78 } 100 }
79 args [argno] = 0; 101 args [argno] = 0;
80#ifdef CONFIG_SELINUX 102#ifdef CONFIG_SELINUX
81 if(sid) 103 if ( (current_sid) && (!setexeccon(current_sid)) ) {
82 execve_secure(shell, (char **) args, environ, sid); 104 freecon(current_sid);
83 else 105 execve(shell, (char **) args, environ);
106 } else
84#endif 107#endif
85 execv ( shell, (char **) args ); 108 execv ( shell, (char **) args );
86 bb_perror_msg_and_die ( "cannot run %s", shell ); 109 bb_perror_msg_and_die ( "cannot run %s", shell );
87} 110}