aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/find_pid_by_name.c7
-rw-r--r--libbb/procps.c15
-rw-r--r--libbb/run_shell.c43
3 files changed, 37 insertions, 28 deletions
diff --git a/libbb/find_pid_by_name.c b/libbb/find_pid_by_name.c
index 930710f32..570e7bd93 100644
--- a/libbb/find_pid_by_name.c
+++ b/libbb/find_pid_by_name.c
@@ -45,11 +45,8 @@ extern long* find_pid_by_name( const char* pidName)
45 procps_status_t * p; 45 procps_status_t * p;
46 46
47 pidList = xmalloc(sizeof(long)); 47 pidList = xmalloc(sizeof(long));
48#ifdef CONFIG_SELINUX 48 while ((p = procps_scan(0)) != 0)
49 while ((p = procps_scan(0, 0, NULL)) != 0) { 49 {
50#else
51 while ((p = procps_scan(0)) != 0) {
52#endif
53 if (strncmp(p->short_cmd, pidName, COMM_LEN-1) == 0) { 50 if (strncmp(p->short_cmd, pidName, COMM_LEN-1) == 0) {
54 pidList=xrealloc( pidList, sizeof(long) * (i+2)); 51 pidList=xrealloc( pidList, sizeof(long) * (i+2));
55 pidList[i++]=p->pid; 52 pidList[i++]=p->pid;
diff --git a/libbb/procps.c b/libbb/procps.c
index e405fb7ef..72f627f15 100644
--- a/libbb/procps.c
+++ b/libbb/procps.c
@@ -16,11 +16,7 @@
16 16
17#include "libbb.h" 17#include "libbb.h"
18 18
19extern procps_status_t * procps_scan(int save_user_arg0 19extern procps_status_t * procps_scan(int save_user_arg0)
20#ifdef CONFIG_SELINUX
21 , int use_selinux , security_id_t *sid
22#endif
23 )
24{ 20{
25 static DIR *dir; 21 static DIR *dir;
26 struct dirent *entry; 22 struct dirent *entry;
@@ -60,16 +56,9 @@ extern procps_status_t * procps_scan(int save_user_arg0
60 my_getpwuid(curstatus.user, sb.st_uid, sizeof(curstatus.user)); 56 my_getpwuid(curstatus.user, sb.st_uid, sizeof(curstatus.user));
61 57
62 sprintf(status, "/proc/%d/stat", pid); 58 sprintf(status, "/proc/%d/stat", pid);
59
63 if((fp = fopen(status, "r")) == NULL) 60 if((fp = fopen(status, "r")) == NULL)
64 continue; 61 continue;
65#ifdef CONFIG_SELINUX
66 if(use_selinux)
67 {
68 if(fstat_secure(fileno(fp), &sb, sid))
69 continue;
70 }
71 else
72#endif
73 name = fgets(buf, sizeof(buf), fp); 62 name = fgets(buf, sizeof(buf), fp);
74 fclose(fp); 63 fclose(fp);
75 if(name == NULL) 64 if(name == NULL)
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}