diff options
author | Rob Landley <rob@landley.net> | 2005-05-03 06:25:50 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2005-05-03 06:25:50 +0000 |
commit | 60158cb93eb0b3207dd1084cdf5bdd9226bd9e89 (patch) | |
tree | fe97ec71775deb1f3078c6db0cb8db554bc6b76f | |
parent | 988a78c61cffe91b005d37f0b7d6e2cb2c5ea713 (diff) | |
download | busybox-w32-60158cb93eb0b3207dd1084cdf5bdd9226bd9e89.tar.gz busybox-w32-60158cb93eb0b3207dd1084cdf5bdd9226bd9e89.tar.bz2 busybox-w32-60158cb93eb0b3207dd1084cdf5bdd9226bd9e89.zip |
A patch from Takeharu KATO to update/fix SE-Linux support.
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | coreutils/id.c | 29 | ||||
-rw-r--r-- | coreutils/ls.c | 48 | ||||
-rw-r--r-- | include/libbb.h | 14 | ||||
-rw-r--r-- | libbb/find_pid_by_name.c | 7 | ||||
-rw-r--r-- | libbb/procps.c | 15 | ||||
-rw-r--r-- | libbb/run_shell.c | 43 | ||||
-rw-r--r-- | loginutils/login.c | 52 | ||||
-rw-r--r-- | loginutils/su.c | 5 | ||||
-rw-r--r-- | loginutils/sulogin.c | 6 | ||||
-rw-r--r-- | procps/ps.c | 52 | ||||
-rw-r--r-- | procps/top.c | 4 |
12 files changed, 148 insertions, 130 deletions
@@ -47,8 +47,7 @@ DIRS:=applets archival archival/libunarchive coreutils console-tools \ | |||
47 | SRC_DIRS:=$(patsubst %,$(top_srcdir)/%,$(DIRS)) | 47 | SRC_DIRS:=$(patsubst %,$(top_srcdir)/%,$(DIRS)) |
48 | 48 | ||
49 | ifeq ($(strip $(CONFIG_SELINUX)),y) | 49 | ifeq ($(strip $(CONFIG_SELINUX)),y) |
50 | CFLAGS += -I/usr/include/selinux | 50 | LIBRARIES += -lselinux |
51 | LIBRARIES += -lsecure | ||
52 | endif | 51 | endif |
53 | 52 | ||
54 | CONFIG_CONFIG_IN = $(top_srcdir)/sysdeps/$(TARGET_OS)/Config.in | 53 | CONFIG_CONFIG_IN = $(top_srcdir)/sysdeps/$(TARGET_OS)/Config.in |
diff --git a/coreutils/id.c b/coreutils/id.c index d5182b953..541c3d16b 100644 --- a/coreutils/id.c +++ b/coreutils/id.c | |||
@@ -32,8 +32,7 @@ | |||
32 | #include <sys/types.h> | 32 | #include <sys/types.h> |
33 | 33 | ||
34 | #ifdef CONFIG_SELINUX | 34 | #ifdef CONFIG_SELINUX |
35 | #include <proc_secure.h> | 35 | #include <selinux/selinux.h> /* for is_selinux_enabled() */ |
36 | #include <flask_util.h> | ||
37 | #endif | 36 | #endif |
38 | 37 | ||
39 | #define PRINT_REAL 1 | 38 | #define PRINT_REAL 1 |
@@ -61,9 +60,6 @@ extern int id_main(int argc, char **argv) | |||
61 | gid_t gid; | 60 | gid_t gid; |
62 | unsigned long flags; | 61 | unsigned long flags; |
63 | short status; | 62 | short status; |
64 | #ifdef CONFIG_SELINUX | ||
65 | int is_flask_enabled_flag = is_flask_enabled(); | ||
66 | #endif | ||
67 | 63 | ||
68 | bb_opt_complementaly = "u~g:g~u"; | 64 | bb_opt_complementaly = "u~g:g~u"; |
69 | flags = bb_getopt_ulflags(argc, argv, "rnug"); | 65 | flags = bb_getopt_ulflags(argc, argv, "rnug"); |
@@ -109,17 +105,26 @@ extern int id_main(int argc, char **argv) | |||
109 | putchar(' '); | 105 | putchar(' '); |
110 | /* my_getgrgid doesn't exit on failure here */ | 106 | /* my_getgrgid doesn't exit on failure here */ |
111 | status|=printf_full(gid, my_getgrgid(NULL, gid, 0), 'g'); | 107 | status|=printf_full(gid, my_getgrgid(NULL, gid, 0), 'g'); |
108 | |||
112 | #ifdef CONFIG_SELINUX | 109 | #ifdef CONFIG_SELINUX |
113 | if(is_flask_enabled_flag) { | 110 | if ( is_selinux_enabled() ) { |
114 | security_id_t mysid = getsecsid(); | 111 | security_context_t mysid; |
115 | char context[80]; | 112 | char context[80]; |
116 | int len = sizeof(context); | 113 | int len = sizeof(context); |
117 | context[0] = '\0'; | 114 | |
118 | if(security_sid_to_context(mysid, context, &len)) | 115 | getcon(&mysid); |
119 | strcpy(context, "unknown"); | 116 | context[0] = '\0'; |
117 | if (mysid) { | ||
118 | len = strlen(mysid)+1; | ||
119 | safe_strncpy(context, mysid, len); | ||
120 | freecon(mysid); | ||
121 | }else{ | ||
122 | safe_strncpy(context, "unknown",8); | ||
123 | } | ||
120 | bb_printf(" context=%s", context); | 124 | bb_printf(" context=%s", context); |
121 | } | 125 | } |
122 | #endif | 126 | #endif |
127 | |||
123 | putchar('\n'); | 128 | putchar('\n'); |
124 | bb_fflush_stdout_and_exit(status); | 129 | bb_fflush_stdout_and_exit(status); |
125 | } | 130 | } |
diff --git a/coreutils/ls.c b/coreutils/ls.c index 4e21454ce..92e150966 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -64,9 +64,7 @@ enum { | |||
64 | #include <sys/sysmacros.h> /* major() and minor() */ | 64 | #include <sys/sysmacros.h> /* major() and minor() */ |
65 | #include "busybox.h" | 65 | #include "busybox.h" |
66 | #ifdef CONFIG_SELINUX | 66 | #ifdef CONFIG_SELINUX |
67 | #include <fs_secure.h> | 67 | #include <selinux/selinux.h> /* for is_selinux_enabled() */ |
68 | #include <flask_util.h> | ||
69 | #include <ss.h> | ||
70 | #endif | 68 | #endif |
71 | 69 | ||
72 | #ifdef CONFIG_FEATURE_LS_TIMESTAMPS | 70 | #ifdef CONFIG_FEATURE_LS_TIMESTAMPS |
@@ -182,7 +180,7 @@ struct dnode { /* the basic node */ | |||
182 | char *fullname; /* the dir entry name */ | 180 | char *fullname; /* the dir entry name */ |
183 | struct stat dstat; /* the file stat info */ | 181 | struct stat dstat; /* the file stat info */ |
184 | #ifdef CONFIG_SELINUX | 182 | #ifdef CONFIG_SELINUX |
185 | security_id_t sid; | 183 | security_context_t sid; |
186 | #endif | 184 | #endif |
187 | struct dnode *next; /* point at the next node */ | 185 | struct dnode *next; /* point at the next node */ |
188 | }; | 186 | }; |
@@ -195,7 +193,7 @@ static int list_single(struct dnode *); | |||
195 | static unsigned int all_fmt; | 193 | static unsigned int all_fmt; |
196 | 194 | ||
197 | #ifdef CONFIG_SELINUX | 195 | #ifdef CONFIG_SELINUX |
198 | static int is_flask_enabled_flag; | 196 | static int selinux_enabled= 0; |
199 | #endif | 197 | #endif |
200 | 198 | ||
201 | #ifdef CONFIG_FEATURE_AUTOWIDTH | 199 | #ifdef CONFIG_FEATURE_AUTOWIDTH |
@@ -213,18 +211,19 @@ static struct dnode *my_stat(char *fullname, char *name) | |||
213 | struct stat dstat; | 211 | struct stat dstat; |
214 | struct dnode *cur; | 212 | struct dnode *cur; |
215 | #ifdef CONFIG_SELINUX | 213 | #ifdef CONFIG_SELINUX |
216 | security_id_t sid; | 214 | security_context_t sid=NULL; |
217 | #endif | 215 | #endif |
218 | int rc; | 216 | int rc; |
219 | 217 | ||
220 | #ifdef CONFIG_FEATURE_LS_FOLLOWLINKS | 218 | #ifdef CONFIG_FEATURE_LS_FOLLOWLINKS |
221 | if (all_fmt & FOLLOW_LINKS) { | 219 | if (all_fmt & FOLLOW_LINKS) { |
222 | #ifdef CONFIG_SELINUX | 220 | #ifdef CONFIG_SELINUX |
223 | if(is_flask_enabled_flag) | 221 | if (is_selinux_enabled()) { |
224 | rc = stat_secure(fullname, &dstat, &sid); | 222 | rc=0; /* Set the number which means success before hand. */ |
225 | else | 223 | rc = getfilecon(fullname,&sid); |
224 | } | ||
226 | #endif | 225 | #endif |
227 | rc = stat(fullname, &dstat); | 226 | rc = stat(fullname, &dstat); |
228 | if(rc) | 227 | if(rc) |
229 | { | 228 | { |
230 | bb_perror_msg("%s", fullname); | 229 | bb_perror_msg("%s", fullname); |
@@ -235,11 +234,12 @@ static struct dnode *my_stat(char *fullname, char *name) | |||
235 | #endif | 234 | #endif |
236 | { | 235 | { |
237 | #ifdef CONFIG_SELINUX | 236 | #ifdef CONFIG_SELINUX |
238 | if(is_flask_enabled_flag) | 237 | if (is_selinux_enabled()) { |
239 | rc = lstat_secure(fullname, &dstat, &sid); | 238 | rc=0; /* Set the number which means success before hand. */ |
240 | else | 239 | rc = lgetfilecon(fullname,&sid); |
240 | } | ||
241 | #endif | 241 | #endif |
242 | rc = lstat(fullname, &dstat); | 242 | rc = lstat(fullname, &dstat); |
243 | if(rc) | 243 | if(rc) |
244 | { | 244 | { |
245 | bb_perror_msg("%s", fullname); | 245 | bb_perror_msg("%s", fullname); |
@@ -736,12 +736,16 @@ static int list_single(struct dnode *dn) | |||
736 | #ifdef CONFIG_SELINUX | 736 | #ifdef CONFIG_SELINUX |
737 | case LIST_CONTEXT: | 737 | case LIST_CONTEXT: |
738 | { | 738 | { |
739 | char context[64]; | 739 | char context[80]; |
740 | int len = sizeof(context); | 740 | int len; |
741 | if(security_sid_to_context(dn->sid, context, &len)) | 741 | |
742 | { | 742 | if (dn->sid) { |
743 | strcpy(context, "unknown"); | 743 | /* I assume sid initilized with NULL */ |
744 | len = 7; | 744 | len = strlen(dn->sid)+1; |
745 | safe_strncpy(context, dn->sid, len); | ||
746 | freecon(dn->sid); | ||
747 | }else { | ||
748 | safe_strncpy(context, "unknown",8); | ||
745 | } | 749 | } |
746 | printf("%-32s ", context); | 750 | printf("%-32s ", context); |
747 | column += MAX(33, len); | 751 | column += MAX(33, len); |
@@ -963,10 +967,6 @@ extern int ls_main(int argc, char **argv) | |||
963 | char *terminal_width_str = NULL; | 967 | char *terminal_width_str = NULL; |
964 | #endif | 968 | #endif |
965 | 969 | ||
966 | #ifdef CONFIG_SELINUX | ||
967 | is_flask_enabled_flag = is_flask_enabled(); | ||
968 | #endif | ||
969 | |||
970 | all_fmt = LIST_SHORT | DISP_NORMAL | STYLE_AUTO | 970 | all_fmt = LIST_SHORT | DISP_NORMAL | STYLE_AUTO |
971 | #ifdef CONFIG_FEATURE_LS_TIMESTAMPS | 971 | #ifdef CONFIG_FEATURE_LS_TIMESTAMPS |
972 | | TIME_MOD | 972 | | TIME_MOD |
diff --git a/include/libbb.h b/include/libbb.h index 6ae5c4d64..ac60dd6c2 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -423,11 +423,11 @@ void bb_xasprintf(char **string_ptr, const char *format, ...) __attribute__ ((fo | |||
423 | #define FAIL_DELAY 3 | 423 | #define FAIL_DELAY 3 |
424 | extern void change_identity ( const struct passwd *pw ); | 424 | extern void change_identity ( const struct passwd *pw ); |
425 | extern const char *change_identity_e2str ( const struct passwd *pw ); | 425 | extern const char *change_identity_e2str ( const struct passwd *pw ); |
426 | extern void run_shell ( const char *shell, int loginshell, const char *command, const char **additional_args | 426 | extern void run_shell ( const char *shell, int loginshell, const char *command, const char **additional_args); |
427 | #ifdef CONFIG_SELINUX | 427 | #ifdef CONFIG_SELINUX |
428 | , security_context_t sid | 428 | extern void renew_current_security_context(void); |
429 | #endif | 429 | extern void set_current_security_context(security_context_t sid); |
430 | ); | 430 | #endif |
431 | extern int run_parts(char **args, const unsigned char test_mode, char **env); | 431 | extern int run_parts(char **args, const unsigned char test_mode, char **env); |
432 | extern int restricted_shell ( const char *shell ); | 432 | extern int restricted_shell ( const char *shell ); |
433 | extern void setup_environment ( const char *shell, int loginshell, int changeenv, const struct passwd *pw ); | 433 | extern void setup_environment ( const char *shell, int loginshell, int changeenv, const struct passwd *pw ); |
@@ -458,11 +458,7 @@ typedef struct { | |||
458 | char short_cmd[16]; | 458 | char short_cmd[16]; |
459 | } procps_status_t; | 459 | } procps_status_t; |
460 | 460 | ||
461 | extern procps_status_t * procps_scan(int save_user_arg0 | 461 | extern procps_status_t * procps_scan(int save_user_arg0); |
462 | #ifdef CONFIG_SELINUX | ||
463 | , int use_selinux, security_context_t *sid | ||
464 | #endif | ||
465 | ); | ||
466 | extern unsigned short compare_string_array(const char *string_array[], const char *key); | 462 | extern unsigned short compare_string_array(const char *string_array[], const char *key); |
467 | 463 | ||
468 | extern int my_query_module(const char *name, int which, void **buf, size_t *bufsize, size_t *ret); | 464 | extern int my_query_module(const char *name, int which, void **buf, size_t *bufsize, size_t *ret); |
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 | ||
19 | extern procps_status_t * procps_scan(int save_user_arg0 | 19 | extern 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 | ||
44 | static security_context_t current_sid=NULL; | ||
45 | |||
46 | void | ||
47 | renew_current_security_context(void) | ||
48 | { | ||
49 | if (current_sid) | ||
50 | freecon(current_sid); /* Release old context */ | ||
51 | |||
52 | getcon(¤t_sid); /* update */ | ||
53 | |||
54 | return; | ||
55 | } | ||
56 | void | ||
57 | set_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 | ||
48 | void run_shell ( const char *shell, int loginshell, const char *command, const char **additional_args | 74 | void 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 | } |
diff --git a/loginutils/login.c b/loginutils/login.c index 34095a6a7..5186e2369 100644 --- a/loginutils/login.c +++ b/loginutils/login.c | |||
@@ -17,10 +17,10 @@ | |||
17 | 17 | ||
18 | #include "busybox.h" | 18 | #include "busybox.h" |
19 | #ifdef CONFIG_SELINUX | 19 | #ifdef CONFIG_SELINUX |
20 | #include <flask_util.h> | 20 | #include <selinux/selinux.h> /* for is_selinux_enabled() */ |
21 | #include <get_sid_list.h> | 21 | #include <selinux/get_context_list.h> /* for get_default_context() */ |
22 | #include <proc_secure.h> | 22 | #include <selinux/flask.h> /* for security class definitions */ |
23 | #include <fs_secure.h> | 23 | #include <errno.h> |
24 | #endif | 24 | #endif |
25 | 25 | ||
26 | #ifdef CONFIG_FEATURE_U_W_TMP | 26 | #ifdef CONFIG_FEATURE_U_W_TMP |
@@ -79,8 +79,7 @@ extern int login_main(int argc, char **argv) | |||
79 | char *opt_host = 0; | 79 | char *opt_host = 0; |
80 | int alarmstarted = 0; | 80 | int alarmstarted = 0; |
81 | #ifdef CONFIG_SELINUX | 81 | #ifdef CONFIG_SELINUX |
82 | int flask_enabled = is_flask_enabled(); | 82 | security_context_t stat_sid = NULL, sid = NULL, old_tty_sid=NULL, new_tty_sid=NULL; |
83 | security_id_t sid = 0, old_tty_sid, new_tty_sid; | ||
84 | #endif | 83 | #endif |
85 | 84 | ||
86 | username[0]=0; | 85 | username[0]=0; |
@@ -225,41 +224,45 @@ auth_ok: | |||
225 | #ifdef CONFIG_FEATURE_U_W_TMP | 224 | #ifdef CONFIG_FEATURE_U_W_TMP |
226 | setutmp ( username, tty ); | 225 | setutmp ( username, tty ); |
227 | #endif | 226 | #endif |
227 | |||
228 | if ( *tty != '/' ) | ||
229 | snprintf ( full_tty, sizeof( full_tty ) - 1, "/dev/%s", tty); | ||
230 | else | ||
231 | safe_strncpy ( full_tty, tty, sizeof( full_tty ) - 1 ); | ||
232 | |||
228 | #ifdef CONFIG_SELINUX | 233 | #ifdef CONFIG_SELINUX |
229 | if (flask_enabled) | 234 | if (is_selinux_enabled()) |
230 | { | 235 | { |
231 | struct stat st; | 236 | struct stat st; |
237 | int rc; | ||
232 | 238 | ||
233 | if (get_default_sid(username, 0, &sid)) | 239 | if (get_default_context(username, NULL, &sid)) |
234 | { | 240 | { |
235 | fprintf(stderr, "Unable to get SID for %s\n", username); | 241 | fprintf(stderr, "Unable to get SID for %s\n", username); |
236 | exit(1); | 242 | exit(1); |
237 | } | 243 | } |
238 | if (stat_secure(tty, &st, &old_tty_sid)) | 244 | rc = getfilecon(full_tty,&stat_sid); |
245 | freecon(stat_sid); | ||
246 | if ((rc<0) || (stat(full_tty, &st)<0)) | ||
239 | { | 247 | { |
240 | fprintf(stderr, "stat_secure(%.100s) failed: %.100s\n", tty, strerror(errno)); | 248 | fprintf(stderr, "stat_secure(%.100s) failed: %.100s\n", full_tty, strerror(errno)); |
241 | return EXIT_FAILURE; | 249 | return EXIT_FAILURE; |
242 | } | 250 | } |
243 | if (security_change_sid (sid, old_tty_sid, SECCLASS_CHR_FILE, &new_tty_sid) != 0) | 251 | if (security_compute_relabel (sid, old_tty_sid, SECCLASS_CHR_FILE, &new_tty_sid) != 0) |
244 | { | 252 | { |
245 | fprintf(stderr, "security_change_sid(%.100s) failed: %.100s\n", tty, strerror(errno)); | 253 | fprintf(stderr, "security_change_sid(%.100s) failed: %.100s\n", full_tty, strerror(errno)); |
246 | return EXIT_FAILURE; | 254 | return EXIT_FAILURE; |
247 | } | 255 | } |
248 | if(chsid(tty, new_tty_sid) != 0) | 256 | if(setfilecon(full_tty, new_tty_sid) != 0) |
249 | { | 257 | { |
250 | fprintf(stderr, "chsid(%.100s, %d) failed: %.100s\n", tty, new_tty_sid, strerror(errno)); | 258 | fprintf(stderr, "chsid(%.100s, %s) failed: %.100s\n", full_tty, new_tty_sid, strerror(errno)); |
251 | return EXIT_FAILURE; | 259 | return EXIT_FAILURE; |
252 | } | 260 | } |
261 | freecon(sid); | ||
262 | freecon(old_tty_sid); | ||
263 | freecon(new_tty_sid); | ||
253 | } | 264 | } |
254 | else | ||
255 | sid = 0; | ||
256 | #endif | 265 | #endif |
257 | |||
258 | if ( *tty != '/' ) | ||
259 | snprintf ( full_tty, sizeof( full_tty ) - 1, "/dev/%s", tty); | ||
260 | else | ||
261 | safe_strncpy ( full_tty, tty, sizeof( full_tty ) - 1 ); | ||
262 | |||
263 | if ( !is_my_tty ( full_tty )) | 266 | if ( !is_my_tty ( full_tty )) |
264 | syslog ( LOG_ERR, "unable to determine TTY name, got %s\n", full_tty ); | 267 | syslog ( LOG_ERR, "unable to determine TTY name, got %s\n", full_tty ); |
265 | 268 | ||
@@ -279,11 +282,10 @@ auth_ok: | |||
279 | 282 | ||
280 | if ( pw-> pw_uid == 0 ) | 283 | if ( pw-> pw_uid == 0 ) |
281 | syslog ( LOG_INFO, "root login %s\n", fromhost ); | 284 | syslog ( LOG_INFO, "root login %s\n", fromhost ); |
282 | run_shell ( tmp, 1, 0, 0 | ||
283 | #ifdef CONFIG_SELINUX | 285 | #ifdef CONFIG_SELINUX |
284 | , sid | 286 | set_current_security_context(sid); |
285 | #endif | 287 | #endif |
286 | ); /* exec the shell finally. */ | 288 | run_shell ( tmp, 1, 0, 0); /* exec the shell finally. */ |
287 | 289 | ||
288 | return EXIT_FAILURE; | 290 | return EXIT_FAILURE; |
289 | } | 291 | } |
diff --git a/loginutils/su.c b/loginutils/su.c index ec0c16c7d..5f6140917 100644 --- a/loginutils/su.c +++ b/loginutils/su.c | |||
@@ -147,11 +147,10 @@ int su_main ( int argc, char **argv ) | |||
147 | 147 | ||
148 | change_identity ( pw ); | 148 | change_identity ( pw ); |
149 | setup_environment ( opt_shell, opt_loginshell, !opt_preserve, pw ); | 149 | setup_environment ( opt_shell, opt_loginshell, !opt_preserve, pw ); |
150 | run_shell ( opt_shell, opt_loginshell, opt_command, (const char**)opt_args | ||
151 | #ifdef CONFIG_SELINUX | 150 | #ifdef CONFIG_SELINUX |
152 | , 0 | 151 | set_current_security_context(NULL); |
153 | #endif | 152 | #endif |
154 | ); | 153 | run_shell ( opt_shell, opt_loginshell, opt_command, (const char**)opt_args); |
155 | 154 | ||
156 | return EXIT_FAILURE; | 155 | return EXIT_FAILURE; |
157 | } | 156 | } |
diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c index f21b09571..a458b6ed7 100644 --- a/loginutils/sulogin.c +++ b/loginutils/sulogin.c | |||
@@ -153,6 +153,12 @@ extern int sulogin_main(int argc, char **argv) | |||
153 | puts("Entering System Maintenance Mode\n"); | 153 | puts("Entering System Maintenance Mode\n"); |
154 | fflush(stdout); | 154 | fflush(stdout); |
155 | syslog(LOG_INFO, "System Maintenance Mode\n"); | 155 | syslog(LOG_INFO, "System Maintenance Mode\n"); |
156 | |||
157 | #ifdef CONFIG_SELINUX | ||
158 | renew_current_security_context(); | ||
159 | #endif | ||
160 | |||
156 | run_shell(pwent.pw_shell, 1, 0, 0); | 161 | run_shell(pwent.pw_shell, 1, 0, 0); |
162 | |||
157 | return (0); | 163 | return (0); |
158 | } | 164 | } |
diff --git a/procps/ps.c b/procps/ps.c index 0b603314d..18a6db36f 100644 --- a/procps/ps.c +++ b/procps/ps.c | |||
@@ -31,9 +31,7 @@ | |||
31 | #include <sys/ioctl.h> | 31 | #include <sys/ioctl.h> |
32 | #include "busybox.h" | 32 | #include "busybox.h" |
33 | #ifdef CONFIG_SELINUX | 33 | #ifdef CONFIG_SELINUX |
34 | #include <fs_secure.h> | 34 | #include <selinux/selinux.h> /* for is_selinux_enabled() */ |
35 | #include <ss.h> | ||
36 | #include <flask_util.h> /* for is_flask_enabled() */ | ||
37 | #endif | 35 | #endif |
38 | 36 | ||
39 | static const int TERMINAL_WIDTH = 79; /* not 80 in case terminal has linefold bug */ | 37 | static const int TERMINAL_WIDTH = 79; /* not 80 in case terminal has linefold bug */ |
@@ -48,8 +46,8 @@ extern int ps_main(int argc, char **argv) | |||
48 | 46 | ||
49 | #ifdef CONFIG_SELINUX | 47 | #ifdef CONFIG_SELINUX |
50 | int use_selinux = 0; | 48 | int use_selinux = 0; |
51 | security_id_t sid; | 49 | security_context_t sid=NULL; |
52 | if(is_flask_enabled() && argv[1] && !strcmp(argv[1], "-c") ) | 50 | if(is_selinux_enabled() && argv[1] && !strcmp(argv[1], "-c") ) |
53 | use_selinux = 1; | 51 | use_selinux = 1; |
54 | #endif | 52 | #endif |
55 | 53 | ||
@@ -58,34 +56,42 @@ extern int ps_main(int argc, char **argv) | |||
58 | terminal_width--; | 56 | terminal_width--; |
59 | 57 | ||
60 | #ifdef CONFIG_SELINUX | 58 | #ifdef CONFIG_SELINUX |
61 | if(use_selinux) | 59 | if (use_selinux) |
62 | printf(" PID Context Stat Command\n"); | 60 | printf(" PID Context Stat Command\n"); |
63 | else | 61 | else |
64 | #endif | 62 | #endif |
65 | printf(" PID Uid VmSize Stat Command\n"); | 63 | printf(" PID Uid VmSize Stat Command\n"); |
66 | #ifdef CONFIG_SELINUX | ||
67 | while ((p = procps_scan(1, use_selinux, &sid)) != 0) { | ||
68 | #else | ||
69 | while ((p = procps_scan(1)) != 0) { | ||
70 | #endif | ||
71 | char *namecmd = p->cmd; | ||
72 | 64 | ||
65 | while ((p = procps_scan(1)) != 0) { | ||
66 | char *namecmd = p->cmd; | ||
73 | #ifdef CONFIG_SELINUX | 67 | #ifdef CONFIG_SELINUX |
74 | if(use_selinux) | 68 | if ( use_selinux ) |
75 | { | 69 | { |
76 | char sbuf[128]; | 70 | char sbuf[128]; |
77 | len = sizeof(sbuf); | 71 | len = sizeof(sbuf); |
78 | if(security_sid_to_context(sid, (security_context_t)&sbuf, &len)) | ||
79 | strcpy(sbuf, "unknown"); | ||
80 | 72 | ||
73 | if (is_selinux_enabled()) { | ||
74 | if (getpidcon(p->pid,&sid)<0) | ||
75 | sid=NULL; | ||
76 | } | ||
77 | |||
78 | if (sid) { | ||
79 | /* I assume sid initilized with NULL */ | ||
80 | len = strlen(sid)+1; | ||
81 | safe_strncpy(sbuf, sid, len); | ||
82 | freecon(sid); | ||
83 | sid=NULL; | ||
84 | }else { | ||
85 | safe_strncpy(sbuf, "unknown",7); | ||
86 | } | ||
81 | len = printf("%5d %-32s %s ", p->pid, sbuf, p->state); | 87 | len = printf("%5d %-32s %s ", p->pid, sbuf, p->state); |
82 | } | 88 | } |
83 | else | 89 | else |
84 | #endif | 90 | #endif |
85 | if(p->rss == 0) | 91 | if(p->rss == 0) |
86 | len = printf("%5d %-8s %s ", p->pid, p->user, p->state); | 92 | len = printf("%5d %-8s %s ", p->pid, p->user, p->state); |
87 | else | 93 | else |
88 | len = printf("%5d %-8s %6ld %s ", p->pid, p->user, p->rss, p->state); | 94 | len = printf("%5d %-8s %6ld %s ", p->pid, p->user, p->rss, p->state); |
89 | i = terminal_width-len; | 95 | i = terminal_width-len; |
90 | 96 | ||
91 | if(namecmd != 0 && namecmd[0] != 0) { | 97 | if(namecmd != 0 && namecmd[0] != 0) { |
diff --git a/procps/top.c b/procps/top.c index c0f78f794..369a408d8 100644 --- a/procps/top.c +++ b/procps/top.c | |||
@@ -510,11 +510,7 @@ int top_main(int argc, char **argv) | |||
510 | /* read process IDs & status for all the processes */ | 510 | /* read process IDs & status for all the processes */ |
511 | procps_status_t * p; | 511 | procps_status_t * p; |
512 | 512 | ||
513 | #ifdef CONFIG_SELINUX | ||
514 | while ((p = procps_scan(0, 0, NULL) ) != 0) { | ||
515 | #else | ||
516 | while ((p = procps_scan(0)) != 0) { | 513 | while ((p = procps_scan(0)) != 0) { |
517 | #endif | ||
518 | int n = ntop; | 514 | int n = ntop; |
519 | 515 | ||
520 | top = xrealloc(top, (++ntop)*sizeof(procps_status_t)); | 516 | top = xrealloc(top, (++ntop)*sizeof(procps_status_t)); |