diff options
author | Eric Andersen <andersen@codepoet.org> | 2003-07-03 10:07:04 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2003-07-03 10:07:04 +0000 |
commit | 9e48045e45df7e3e205575a4eb3dc39d634b05aa (patch) | |
tree | e8f993dffc34380fbcc54cc858c81da594bdb95b | |
parent | c48d49ad988a4163cff7f38ee4bd1f9886d0ed11 (diff) | |
download | busybox-w32-9e48045e45df7e3e205575a4eb3dc39d634b05aa.tar.gz busybox-w32-9e48045e45df7e3e205575a4eb3dc39d634b05aa.tar.bz2 busybox-w32-9e48045e45df7e3e205575a4eb3dc39d634b05aa.zip |
Patch from Russell Coker:
I've attached my latest SE Linux patch for busybox against the latest CVS
version of busybox.
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | coreutils/id.c | 34 | ||||
-rw-r--r-- | coreutils/ls.c | 94 | ||||
-rw-r--r-- | include/libbb.h | 15 | ||||
-rw-r--r-- | include/usage.h | 15 | ||||
-rw-r--r-- | libbb/find_pid_by_name.c | 4 | ||||
-rw-r--r-- | libbb/procps.c | 14 | ||||
-rw-r--r-- | libbb/run_shell.c | 15 | ||||
-rw-r--r-- | loginutils/login.c | 47 | ||||
-rw-r--r-- | loginutils/su.c | 6 | ||||
-rw-r--r-- | procps/ps.c | 33 | ||||
-rw-r--r-- | procps/top.c | 4 | ||||
-rw-r--r-- | sysdeps/linux/Config.in | 7 |
13 files changed, 263 insertions, 30 deletions
@@ -31,6 +31,11 @@ DIRS:=applets archival archival/libunarchive coreutils console-tools \ | |||
31 | networking/libiproute networking/udhcp procps loginutils shell \ | 31 | networking/libiproute networking/udhcp procps loginutils shell \ |
32 | sysklogd util-linux libbb libpwdgrp coreutils/libcoreutils | 32 | sysklogd util-linux libbb libpwdgrp coreutils/libcoreutils |
33 | 33 | ||
34 | ifeq ($(strip $(CONFIG_SELINUX)),y) | ||
35 | CFLAGS += -I/usr/include/selinux | ||
36 | LIBRARIES += -lsecure | ||
37 | endif | ||
38 | |||
34 | ifeq ($(strip $(HAVE_DOT_CONFIG)),y) | 39 | ifeq ($(strip $(HAVE_DOT_CONFIG)),y) |
35 | 40 | ||
36 | all: busybox busybox.links #doc | 41 | all: busybox busybox.links #doc |
diff --git a/coreutils/id.c b/coreutils/id.c index 9b2d60dc7..971e7cdad 100644 --- a/coreutils/id.c +++ b/coreutils/id.c | |||
@@ -28,9 +28,13 @@ | |||
28 | #include <getopt.h> | 28 | #include <getopt.h> |
29 | #include <string.h> | 29 | #include <string.h> |
30 | #include <sys/types.h> | 30 | #include <sys/types.h> |
31 | #ifdef CONFIG_SELINUX | ||
32 | #include <proc_secure.h> | ||
33 | #include <flask_util.h> | ||
34 | #endif | ||
31 | 35 | ||
32 | #define NO_GROUP 1 | 36 | #define JUST_USER 1 |
33 | #define NO_USER 2 | 37 | #define JUST_GROUP 2 |
34 | #define PRINT_REAL 4 | 38 | #define PRINT_REAL 4 |
35 | #define NAME_NOT_NUMBER 8 | 39 | #define NAME_NOT_NUMBER 8 |
36 | 40 | ||
@@ -40,10 +44,13 @@ extern int id_main(int argc, char **argv) | |||
40 | long pwnam, grnam; | 44 | long pwnam, grnam; |
41 | int uid, gid; | 45 | int uid, gid; |
42 | int flags; | 46 | int flags; |
47 | #ifdef CONFIG_SELINUX | ||
48 | int is_flask_enabled_flag = is_flask_enabled(); | ||
49 | #endif | ||
43 | 50 | ||
44 | flags = bb_getopt_ulflags(argc, argv, "ugrn"); | 51 | flags = bb_getopt_ulflags(argc, argv, "ugrn"); |
45 | 52 | ||
46 | if (((flags & (NO_USER | NO_GROUP)) == (NO_USER | NO_GROUP)) | 53 | if (((flags & (JUST_USER | JUST_GROUP)) == (JUST_USER | JUST_GROUP)) |
47 | || (argc > optind + 1) | 54 | || (argc > optind + 1) |
48 | ) { | 55 | ) { |
49 | bb_show_usage(); | 56 | bb_show_usage(); |
@@ -67,9 +74,9 @@ extern int id_main(int argc, char **argv) | |||
67 | pwnam=my_getpwnam(user); | 74 | pwnam=my_getpwnam(user); |
68 | grnam=my_getgrnam(group); | 75 | grnam=my_getgrnam(group); |
69 | 76 | ||
70 | if (flags & (NO_GROUP | NO_USER)) { | 77 | if (flags & (JUST_GROUP | JUST_USER)) { |
71 | char *s = group; | 78 | char *s = group; |
72 | if (flags & NO_GROUP) { | 79 | if (flags & JUST_USER) { |
73 | s = user; | 80 | s = user; |
74 | grnam = pwnam; | 81 | grnam = pwnam; |
75 | } | 82 | } |
@@ -79,7 +86,24 @@ extern int id_main(int argc, char **argv) | |||
79 | printf("%ld\n", grnam); | 86 | printf("%ld\n", grnam); |
80 | } | 87 | } |
81 | } else { | 88 | } else { |
89 | #ifdef CONFIG_SELINUX | ||
90 | printf("uid=%ld(%s) gid=%ld(%s)", pwnam, user, grnam, group); | ||
91 | if(is_flask_enabled_flag) | ||
92 | { | ||
93 | security_id_t mysid = getsecsid(); | ||
94 | char context[80]; | ||
95 | int len = sizeof(context); | ||
96 | context[0] = '\0'; | ||
97 | if(security_sid_to_context(mysid, context, &len)) | ||
98 | strcpy(context, "unknown"); | ||
99 | printf(" context=%s\n", context); | ||
100 | } | ||
101 | else | ||
102 | printf("\n"); | ||
103 | #else | ||
82 | printf("uid=%ld(%s) gid=%ld(%s)\n", pwnam, user, grnam, group); | 104 | printf("uid=%ld(%s) gid=%ld(%s)\n", pwnam, user, grnam, group); |
105 | #endif | ||
106 | |||
83 | } | 107 | } |
84 | 108 | ||
85 | bb_fflush_stdout_and_exit(0); | 109 | bb_fflush_stdout_and_exit(0); |
diff --git a/coreutils/ls.c b/coreutils/ls.c index 4a4956611..6245361e9 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -62,6 +62,11 @@ enum { | |||
62 | #include <termios.h> | 62 | #include <termios.h> |
63 | #include <sys/ioctl.h> | 63 | #include <sys/ioctl.h> |
64 | #include "busybox.h" | 64 | #include "busybox.h" |
65 | #ifdef CONFIG_SELINUX | ||
66 | #include <fs_secure.h> | ||
67 | #include <flask_util.h> | ||
68 | #include <ss.h> | ||
69 | #endif | ||
65 | 70 | ||
66 | #ifdef CONFIG_FEATURE_LS_TIMESTAMPS | 71 | #ifdef CONFIG_FEATURE_LS_TIMESTAMPS |
67 | #include <time.h> | 72 | #include <time.h> |
@@ -89,14 +94,15 @@ enum { | |||
89 | #define LIST_NLINKS (1U<<3) | 94 | #define LIST_NLINKS (1U<<3) |
90 | #define LIST_ID_NAME (1U<<4) | 95 | #define LIST_ID_NAME (1U<<4) |
91 | #define LIST_ID_NUMERIC (1U<<5) | 96 | #define LIST_ID_NUMERIC (1U<<5) |
92 | #define LIST_SIZE (1U<<6) | 97 | #define LIST_CONTEXT (1U<<6) |
93 | #define LIST_DEV (1U<<7) | 98 | #define LIST_SIZE (1U<<7) |
94 | #define LIST_DATE_TIME (1U<<8) | 99 | #define LIST_DEV (1U<<8) |
95 | #define LIST_FULLTIME (1U<<9) | 100 | #define LIST_DATE_TIME (1U<<9) |
96 | #define LIST_FILENAME (1U<<10) | 101 | #define LIST_FULLTIME (1U<<10) |
97 | #define LIST_SYMLINK (1U<<11) | 102 | #define LIST_FILENAME (1U<<11) |
98 | #define LIST_FILETYPE (1U<<12) | 103 | #define LIST_SYMLINK (1U<<12) |
99 | #define LIST_EXEC (1U<<13) | 104 | #define LIST_FILETYPE (1U<<13) |
105 | #define LIST_EXEC (1U<<14) | ||
100 | 106 | ||
101 | #define LIST_MASK ((LIST_EXEC << 1) - 1) | 107 | #define LIST_MASK ((LIST_EXEC << 1) - 1) |
102 | 108 | ||
@@ -179,6 +185,9 @@ struct dnode { /* the basic node */ | |||
179 | char *name; /* the dir entry name */ | 185 | char *name; /* the dir entry name */ |
180 | char *fullname; /* the dir entry name */ | 186 | char *fullname; /* the dir entry name */ |
181 | struct stat dstat; /* the file stat info */ | 187 | struct stat dstat; /* the file stat info */ |
188 | #ifdef CONFIG_SELINUX | ||
189 | security_id_t sid; | ||
190 | #endif | ||
182 | struct dnode *next; /* point at the next node */ | 191 | struct dnode *next; /* point at the next node */ |
183 | }; | 192 | }; |
184 | typedef struct dnode dnode_t; | 193 | typedef struct dnode dnode_t; |
@@ -189,6 +198,10 @@ static int list_single(struct dnode *); | |||
189 | 198 | ||
190 | static unsigned int all_fmt; | 199 | static unsigned int all_fmt; |
191 | 200 | ||
201 | #ifdef CONFIG_SELINUX | ||
202 | static int is_flask_enabled_flag; | ||
203 | #endif | ||
204 | |||
192 | #ifdef CONFIG_FEATURE_AUTOWIDTH | 205 | #ifdef CONFIG_FEATURE_AUTOWIDTH |
193 | static unsigned short terminal_width = TERMINAL_WIDTH; | 206 | static unsigned short terminal_width = TERMINAL_WIDTH; |
194 | static unsigned short tabstops = COLUMN_GAP; | 207 | static unsigned short tabstops = COLUMN_GAP; |
@@ -203,26 +216,49 @@ static struct dnode *my_stat(char *fullname, char *name) | |||
203 | { | 216 | { |
204 | struct stat dstat; | 217 | struct stat dstat; |
205 | struct dnode *cur; | 218 | struct dnode *cur; |
219 | #ifdef CONFIG_SELINUX | ||
220 | security_id_t sid; | ||
221 | #endif | ||
222 | int rc; | ||
206 | 223 | ||
207 | #ifdef CONFIG_FEATURE_LS_FOLLOWLINKS | 224 | #ifdef CONFIG_FEATURE_LS_FOLLOWLINKS |
208 | if (all_fmt & FOLLOW_LINKS) { | 225 | if (all_fmt & FOLLOW_LINKS) { |
209 | if (stat(fullname, &dstat)) { | 226 | #ifdef CONFIG_SELINUX |
227 | if(is_flask_enabled_flag) | ||
228 | rc = stat_secure(fullname, &dstat, &sid); | ||
229 | else | ||
230 | #endif | ||
231 | rc = stat(fullname, &dstat); | ||
232 | if(rc) | ||
233 | { | ||
210 | bb_perror_msg("%s", fullname); | 234 | bb_perror_msg("%s", fullname); |
211 | status = EXIT_FAILURE; | 235 | status = EXIT_FAILURE; |
212 | return 0; | 236 | return 0; |
213 | } | 237 | } |
214 | } else | 238 | } else |
215 | #endif | 239 | #endif |
216 | if (lstat(fullname, &dstat)) { | 240 | { |
217 | bb_perror_msg("%s", fullname); | 241 | #ifdef CONFIG_SELINUX |
218 | status = EXIT_FAILURE; | 242 | if(is_flask_enabled_flag) |
219 | return 0; | 243 | rc = lstat_secure(fullname, &dstat, &sid); |
244 | else | ||
245 | #endif | ||
246 | rc = lstat(fullname, &dstat); | ||
247 | if(rc) | ||
248 | { | ||
249 | bb_perror_msg("%s", fullname); | ||
250 | status = EXIT_FAILURE; | ||
251 | return 0; | ||
252 | } | ||
220 | } | 253 | } |
221 | 254 | ||
222 | cur = (struct dnode *) xmalloc(sizeof(struct dnode)); | 255 | cur = (struct dnode *) xmalloc(sizeof(struct dnode)); |
223 | cur->fullname = fullname; | 256 | cur->fullname = fullname; |
224 | cur->name = name; | 257 | cur->name = name; |
225 | cur->dstat = dstat; | 258 | cur->dstat = dstat; |
259 | #ifdef CONFIG_SELINUX | ||
260 | cur->sid = sid; | ||
261 | #endif | ||
226 | return cur; | 262 | return cur; |
227 | } | 263 | } |
228 | 264 | ||
@@ -451,6 +487,9 @@ static void showfiles(struct dnode **dn, int nfiles) | |||
451 | /* find the longest file name- use that as the column width */ | 487 | /* find the longest file name- use that as the column width */ |
452 | for (i = 0; i < nfiles; i++) { | 488 | for (i = 0; i < nfiles; i++) { |
453 | int len = strlen(dn[i]->name) + | 489 | int len = strlen(dn[i]->name) + |
490 | #ifdef CONFIG_SELINUX | ||
491 | ((all_fmt & LIST_CONTEXT) ? 33 : 0) + | ||
492 | #endif | ||
454 | ((all_fmt & LIST_INO) ? 8 : 0) + | 493 | ((all_fmt & LIST_INO) ? 8 : 0) + |
455 | ((all_fmt & LIST_BLOCKS) ? 5 : 0); | 494 | ((all_fmt & LIST_BLOCKS) ? 5 : 0); |
456 | if (column_width < len) | 495 | if (column_width < len) |
@@ -695,6 +734,21 @@ static int list_single(struct dnode *dn) | |||
695 | column += 13; | 734 | column += 13; |
696 | break; | 735 | break; |
697 | #endif | 736 | #endif |
737 | #ifdef CONFIG_SELINUX | ||
738 | case LIST_CONTEXT: | ||
739 | { | ||
740 | char context[64]; | ||
741 | int len = sizeof(context); | ||
742 | if(security_sid_to_context(dn->sid, context, &len)) | ||
743 | { | ||
744 | strcpy(context, "unknown"); | ||
745 | len = 7; | ||
746 | } | ||
747 | printf("%-32s ", context); | ||
748 | column += MAX(33, len); | ||
749 | } | ||
750 | break; | ||
751 | #endif | ||
698 | case LIST_FILENAME: | 752 | case LIST_FILENAME: |
699 | #ifdef CONFIG_FEATURE_LS_COLOR | 753 | #ifdef CONFIG_FEATURE_LS_COLOR |
700 | errno = 0; | 754 | errno = 0; |
@@ -774,6 +828,9 @@ static const char ls_opts[] = "1AaCdgilnsx" | |||
774 | "h" | 828 | "h" |
775 | #endif | 829 | #endif |
776 | "k" | 830 | "k" |
831 | #ifdef CONFIG_SELINUX | ||
832 | "K" | ||
833 | #endif | ||
777 | #ifdef CONFIG_FEATURE_AUTOWIDTH | 834 | #ifdef CONFIG_FEATURE_AUTOWIDTH |
778 | "T:w:" | 835 | "T:w:" |
779 | #endif | 836 | #endif |
@@ -834,7 +891,12 @@ static const unsigned opt_flags[] = { | |||
834 | #ifdef CONFIG_FEATURE_HUMAN_READABLE | 891 | #ifdef CONFIG_FEATURE_HUMAN_READABLE |
835 | LS_DISP_HR, /* h */ | 892 | LS_DISP_HR, /* h */ |
836 | #endif | 893 | #endif |
894 | #ifndef CONFIG_SELINUX | ||
837 | 0, /* k - ingored */ | 895 | 0, /* k - ingored */ |
896 | #else | ||
897 | LIST_CONTEXT, /* k */ | ||
898 | LIST_MODEBITS|LIST_NLINKS|LIST_CONTEXT|LIST_SIZE|LIST_DATE_TIME, /* K */ | ||
899 | #endif | ||
838 | }; | 900 | }; |
839 | 901 | ||
840 | 902 | ||
@@ -849,6 +911,9 @@ extern int ls_main(int argc, char **argv) | |||
849 | int opt; | 911 | int opt; |
850 | int oi, ac; | 912 | int oi, ac; |
851 | char **av; | 913 | char **av; |
914 | #ifdef CONFIG_SELINUX | ||
915 | is_flask_enabled_flag = is_flask_enabled(); | ||
916 | #endif | ||
852 | 917 | ||
853 | #ifdef CONFIG_FEATURE_AUTOWIDTH | 918 | #ifdef CONFIG_FEATURE_AUTOWIDTH |
854 | struct winsize win = { 0, 0, 0, 0 }; | 919 | struct winsize win = { 0, 0, 0, 0 }; |
@@ -911,6 +976,9 @@ extern int ls_main(int argc, char **argv) | |||
911 | if (flags & TIME_MASK_TRIGGER) { | 976 | if (flags & TIME_MASK_TRIGGER) { |
912 | all_fmt &= ~TIME_MASK; | 977 | all_fmt &= ~TIME_MASK; |
913 | } | 978 | } |
979 | if (flags & LIST_CONTEXT) { | ||
980 | all_fmt |= STYLE_SINGLE; | ||
981 | } | ||
914 | #ifdef CONFIG_FEATURE_HUMAN_READABLE | 982 | #ifdef CONFIG_FEATURE_HUMAN_READABLE |
915 | if (opt == 'l') { | 983 | if (opt == 'l') { |
916 | all_fmt &= ~LS_DISP_HR; | 984 | all_fmt &= ~LS_DISP_HR; |
diff --git a/include/libbb.h b/include/libbb.h index 7b3ac4b85..edb8a6ed4 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -39,6 +39,9 @@ | |||
39 | #include <features.h> | 39 | #include <features.h> |
40 | 40 | ||
41 | #include "config.h" | 41 | #include "config.h" |
42 | #ifdef CONFIG_SELINUX | ||
43 | #include <proc_secure.h> | ||
44 | #endif | ||
42 | 45 | ||
43 | #include "pwd_.h" | 46 | #include "pwd_.h" |
44 | #include "grp_.h" | 47 | #include "grp_.h" |
@@ -394,7 +397,11 @@ void bb_xasprintf(char **string_ptr, const char *format, ...) __attribute__ ((fo | |||
394 | 397 | ||
395 | #define FAIL_DELAY 3 | 398 | #define FAIL_DELAY 3 |
396 | extern void change_identity ( const struct passwd *pw ); | 399 | extern void change_identity ( const struct passwd *pw ); |
397 | extern void run_shell ( const char *shell, int loginshell, const char *command, const char **additional_args ); | 400 | extern void run_shell ( const char *shell, int loginshell, const char *command, const char **additional_args |
401 | #ifdef CONFIG_SELINUX | ||
402 | , security_id_t sid | ||
403 | #endif | ||
404 | ); | ||
398 | extern int run_parts(char **args, const unsigned char test_mode); | 405 | extern int run_parts(char **args, const unsigned char test_mode); |
399 | extern int restricted_shell ( const char *shell ); | 406 | extern int restricted_shell ( const char *shell ); |
400 | extern void setup_environment ( const char *shell, int loginshell, int changeenv, const struct passwd *pw ); | 407 | extern void setup_environment ( const char *shell, int loginshell, int changeenv, const struct passwd *pw ); |
@@ -425,7 +432,11 @@ typedef struct { | |||
425 | char short_cmd[16]; | 432 | char short_cmd[16]; |
426 | } procps_status_t; | 433 | } procps_status_t; |
427 | 434 | ||
428 | extern procps_status_t * procps_scan(int save_user_arg0); | 435 | extern procps_status_t * procps_scan(int save_user_arg0 |
436 | #ifdef CONFIG_SELINUX | ||
437 | , int use_selinux, security_id_t *sid | ||
438 | #endif | ||
439 | ); | ||
429 | extern unsigned short compare_string_array(const char *string_array[], const char *key); | 440 | extern unsigned short compare_string_array(const char *string_array[], const char *key); |
430 | 441 | ||
431 | extern int my_query_module(const char *name, int which, void **buf, size_t *bufsize, size_t *ret); | 442 | extern int my_query_module(const char *name, int which, void **buf, size_t *bufsize, size_t *ret); |
diff --git a/include/usage.h b/include/usage.h index 701b40daa..e0cfa7d2f 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -882,6 +882,12 @@ | |||
882 | "\t-u\tthe hardware clock is kept in coordinated universal time\n" \ | 882 | "\t-u\tthe hardware clock is kept in coordinated universal time\n" \ |
883 | "\t-l\tthe hardware clock is kept in local time" | 883 | "\t-l\tthe hardware clock is kept in local time" |
884 | 884 | ||
885 | #ifdef CONFIG_SELINUX | ||
886 | #define USAGE_SELINUX(a, b) a | ||
887 | #else | ||
888 | #define USAGE_SELINUX(a, b) b | ||
889 | #endif | ||
890 | |||
885 | #define id_trivial_usage \ | 891 | #define id_trivial_usage \ |
886 | "[OPTIONS]... [USERNAME]" | 892 | "[OPTIONS]... [USERNAME]" |
887 | #define id_full_usage \ | 893 | #define id_full_usage \ |
@@ -889,6 +895,7 @@ | |||
889 | "Options:\n" \ | 895 | "Options:\n" \ |
890 | "\t-g\tprints only the group ID\n" \ | 896 | "\t-g\tprints only the group ID\n" \ |
891 | "\t-u\tprints only the user ID\n" \ | 897 | "\t-u\tprints only the user ID\n" \ |
898 | USAGE_SELINUX("\t-c\tprints only the security context\n", "") \ | ||
892 | "\t-n\tprint a name instead of a number (with for -ug)\n" \ | 899 | "\t-n\tprint a name instead of a number (with for -ug)\n" \ |
893 | "\t-r\tprints the real user ID instead of the effective ID (with -ug)" | 900 | "\t-r\tprints the real user ID instead of the effective ID (with -ug)" |
894 | #define id_example_usage \ | 901 | #define id_example_usage \ |
@@ -1347,7 +1354,7 @@ | |||
1347 | #define USAGE_AUTOWIDTH(a) | 1354 | #define USAGE_AUTOWIDTH(a) |
1348 | #endif | 1355 | #endif |
1349 | #define ls_trivial_usage \ | 1356 | #define ls_trivial_usage \ |
1350 | "[-1Aa" USAGE_LS_TIMESTAMPS("c") "Cd" USAGE_LS_TIMESTAMPS("e") USAGE_LS_FILETYPES("F") "iln" USAGE_LS_FILETYPES("p") USAGE_LS_FOLLOWLINKS("L") USAGE_LS_RECURSIVE("R") USAGE_LS_SORTFILES("rS") "s" USAGE_AUTOWIDTH("T") USAGE_LS_TIMESTAMPS("tu") USAGE_LS_SORTFILES("v") USAGE_AUTOWIDTH("w") "x" USAGE_LS_SORTFILES("X") USAGE_HUMAN_READABLE("h") USAGE_NOT_HUMAN_READABLE("") "k] [filenames...]" | 1357 | "[-1Aa" USAGE_LS_TIMESTAMPS("c") "Cd" USAGE_LS_TIMESTAMPS("e") USAGE_LS_FILETYPES("F") "iln" USAGE_LS_FILETYPES("p") USAGE_LS_FOLLOWLINKS("L") USAGE_LS_RECURSIVE("R") USAGE_LS_SORTFILES("rS") "s" USAGE_AUTOWIDTH("T") USAGE_LS_TIMESTAMPS("tu") USAGE_LS_SORTFILES("v") USAGE_AUTOWIDTH("w") "x" USAGE_LS_SORTFILES("X") USAGE_HUMAN_READABLE("h") USAGE_NOT_HUMAN_READABLE("") "k" USAGE_SELINUX("K", "") "] [filenames...]" |
1351 | #define ls_full_usage \ | 1358 | #define ls_full_usage \ |
1352 | "List directory contents\n\n" \ | 1359 | "List directory contents\n\n" \ |
1353 | "Options:\n" \ | 1360 | "Options:\n" \ |
@@ -1377,8 +1384,7 @@ | |||
1377 | USAGE_LS_SORTFILES("\t-X\tsort the listing by extension\n") \ | 1384 | USAGE_LS_SORTFILES("\t-X\tsort the listing by extension\n") \ |
1378 | USAGE_HUMAN_READABLE( \ | 1385 | USAGE_HUMAN_READABLE( \ |
1379 | "\t-h\tprint sizes in human readable format (e.g., 1K 243M 2G )\n" \ | 1386 | "\t-h\tprint sizes in human readable format (e.g., 1K 243M 2G )\n" \ |
1380 | "\t-k\tprint sizes in kilobytes(default)") USAGE_NOT_HUMAN_READABLE( \ | 1387 | USAGE_SELINUX("\t-k\tprint security context\n\t-K\tprint security context in long format\n", "") |
1381 | "\t-k\tprint sizes in kilobytes(compatibility)") | ||
1382 | 1388 | ||
1383 | #define lsmod_trivial_usage \ | 1389 | #define lsmod_trivial_usage \ |
1384 | "" | 1390 | "" |
@@ -1786,7 +1792,8 @@ | |||
1786 | "" | 1792 | "" |
1787 | #define ps_full_usage \ | 1793 | #define ps_full_usage \ |
1788 | "Report process status\n" \ | 1794 | "Report process status\n" \ |
1789 | "\nThis version of ps accepts no options." | 1795 | USAGE_SELINUX("\nOptions:\n\t-c\tshow SE Linux context", "\nThis version of ps accepts no options.") |
1796 | |||
1790 | #define ps_example_usage \ | 1797 | #define ps_example_usage \ |
1791 | "$ ps\n" \ | 1798 | "$ ps\n" \ |
1792 | " PID Uid Gid State Command\n" \ | 1799 | " PID Uid Gid State Command\n" \ |
diff --git a/libbb/find_pid_by_name.c b/libbb/find_pid_by_name.c index b6602b942..b8490b724 100644 --- a/libbb/find_pid_by_name.c +++ b/libbb/find_pid_by_name.c | |||
@@ -41,7 +41,11 @@ extern long* find_pid_by_name( const char* pidName) | |||
41 | procps_status_t * p; | 41 | procps_status_t * p; |
42 | 42 | ||
43 | pidList = xmalloc(sizeof(long)); | 43 | pidList = xmalloc(sizeof(long)); |
44 | #ifdef CONFIG_SELINUX | ||
45 | while ((p = procps_scan(0, 0, NULL)) != 0) { | ||
46 | #else | ||
44 | while ((p = procps_scan(0)) != 0) { | 47 | while ((p = procps_scan(0)) != 0) { |
48 | #endif | ||
45 | if (strcmp(p->short_cmd, pidName) == 0) { | 49 | if (strcmp(p->short_cmd, pidName) == 0) { |
46 | pidList=xrealloc( pidList, sizeof(long) * (i+2)); | 50 | pidList=xrealloc( pidList, sizeof(long) * (i+2)); |
47 | pidList[i++]=p->pid; | 51 | pidList[i++]=p->pid; |
diff --git a/libbb/procps.c b/libbb/procps.c index 7df071869..44103fae8 100644 --- a/libbb/procps.c +++ b/libbb/procps.c | |||
@@ -16,7 +16,11 @@ | |||
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 | ) | ||
20 | { | 24 | { |
21 | static DIR *dir; | 25 | static DIR *dir; |
22 | struct dirent *entry; | 26 | struct dirent *entry; |
@@ -53,6 +57,14 @@ extern procps_status_t * procps_scan(int save_user_arg0) | |||
53 | sprintf(status, "/proc/%d/stat", pid); | 57 | sprintf(status, "/proc/%d/stat", pid); |
54 | if((fp = fopen(status, "r")) == NULL) | 58 | if((fp = fopen(status, "r")) == NULL) |
55 | continue; | 59 | continue; |
60 | #ifdef CONFIG_SELINUX | ||
61 | if(use_selinux) | ||
62 | { | ||
63 | if(fstat_secure(fileno(fp), &sb, sid)) | ||
64 | continue; | ||
65 | } | ||
66 | else | ||
67 | #endif | ||
56 | if(fstat(fileno(fp), &sb)) | 68 | if(fstat(fileno(fp), &sb)) |
57 | continue; | 69 | continue; |
58 | my_getpwuid(curstatus.user, sb.st_uid); | 70 | my_getpwuid(curstatus.user, sb.st_uid); |
diff --git a/libbb/run_shell.c b/libbb/run_shell.c index 49e8a76c2..4855d763e 100644 --- a/libbb/run_shell.c +++ b/libbb/run_shell.c | |||
@@ -36,14 +36,20 @@ | |||
36 | #include <syslog.h> | 36 | #include <syslog.h> |
37 | #include <ctype.h> | 37 | #include <ctype.h> |
38 | #include "libbb.h" | 38 | #include "libbb.h" |
39 | 39 | #ifdef CONFIG_SELINUX | |
40 | #include <proc_secure.h> | ||
41 | #endif | ||
40 | 42 | ||
41 | /* Run SHELL, or DEFAULT_SHELL if SHELL is empty. | 43 | /* Run SHELL, or DEFAULT_SHELL if SHELL is empty. |
42 | If COMMAND is nonzero, pass it to the shell with the -c option. | 44 | If COMMAND is nonzero, pass it to the shell with the -c option. |
43 | If ADDITIONAL_ARGS is nonzero, pass it to the shell as more | 45 | If ADDITIONAL_ARGS is nonzero, pass it to the shell as more |
44 | arguments. */ | 46 | arguments. */ |
45 | 47 | ||
46 | void run_shell ( const char *shell, int loginshell, const char *command, const char **additional_args ) | 48 | 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 | ) | ||
47 | { | 53 | { |
48 | const char **args; | 54 | const char **args; |
49 | int argno = 1; | 55 | int argno = 1; |
@@ -71,6 +77,11 @@ void run_shell ( const char *shell, int loginshell, const char *command, const c | |||
71 | args [argno++] = *additional_args; | 77 | args [argno++] = *additional_args; |
72 | } | 78 | } |
73 | args [argno] = 0; | 79 | args [argno] = 0; |
80 | #ifdef CONFIG_SELINUX | ||
81 | if(sid) | ||
82 | execve_secure(shell, (char **) args, environ, sid); | ||
83 | else | ||
84 | #endif | ||
74 | execv ( shell, (char **) args ); | 85 | execv ( shell, (char **) args ); |
75 | bb_perror_msg_and_die ( "cannot run %s", shell ); | 86 | bb_perror_msg_and_die ( "cannot run %s", shell ); |
76 | } | 87 | } |
diff --git a/loginutils/login.c b/loginutils/login.c index e239f421c..741d15c93 100644 --- a/loginutils/login.c +++ b/loginutils/login.c | |||
@@ -16,7 +16,12 @@ | |||
16 | #include <time.h> | 16 | #include <time.h> |
17 | 17 | ||
18 | #include "busybox.h" | 18 | #include "busybox.h" |
19 | 19 | #ifdef CONFIG_SELINUX | |
20 | #include <flask_util.h> | ||
21 | #include <get_sid_list.h> | ||
22 | #include <proc_secure.h> | ||
23 | #include <fs_secure.h> | ||
24 | #endif | ||
20 | 25 | ||
21 | #ifdef CONFIG_FEATURE_U_W_TMP | 26 | #ifdef CONFIG_FEATURE_U_W_TMP |
22 | // import from utmp.c | 27 | // import from utmp.c |
@@ -73,6 +78,10 @@ extern int login_main(int argc, char **argv) | |||
73 | int opt_fflag = 0; | 78 | int opt_fflag = 0; |
74 | char *opt_host = 0; | 79 | char *opt_host = 0; |
75 | int alarmstarted = 0; | 80 | int alarmstarted = 0; |
81 | #ifdef CONFIG_SELINUX | ||
82 | int flask_enabled = is_flask_enabled(); | ||
83 | security_id_t sid = 0, old_tty_sid, new_tty_sid; | ||
84 | #endif | ||
76 | 85 | ||
77 | username[0]=0; | 86 | username[0]=0; |
78 | amroot = ( getuid ( ) == 0 ); | 87 | amroot = ( getuid ( ) == 0 ); |
@@ -217,6 +226,36 @@ auth_ok: | |||
217 | #ifdef CONFIG_FEATURE_U_W_TMP | 226 | #ifdef CONFIG_FEATURE_U_W_TMP |
218 | setutmp ( username, tty ); | 227 | setutmp ( username, tty ); |
219 | #endif | 228 | #endif |
229 | #ifdef CONFIG_SELINUX | ||
230 | if (flask_enabled) | ||
231 | { | ||
232 | struct stat st; | ||
233 | |||
234 | if (get_default_sid(username, 0, &sid)) | ||
235 | { | ||
236 | fprintf(stderr, "Unable to get SID for %s\n", username); | ||
237 | exit(1); | ||
238 | } | ||
239 | if (stat_secure(tty, &st, &old_tty_sid)) | ||
240 | { | ||
241 | fprintf(stderr, "stat_secure(%.100s) failed: %.100s\n", tty, strerror(errno)); | ||
242 | return EXIT_FAILURE; | ||
243 | } | ||
244 | if (security_change_sid (sid, old_tty_sid, SECCLASS_CHR_FILE, &new_tty_sid) != 0) | ||
245 | { | ||
246 | fprintf(stderr, "security_change_sid(%.100s) failed: %.100s\n", tty, strerror(errno)); | ||
247 | return EXIT_FAILURE; | ||
248 | } | ||
249 | if(chsid(tty, new_tty_sid) != 0) | ||
250 | { | ||
251 | fprintf(stderr, "chsid(%.100s, %d) failed: %.100s\n", tty, new_tty_sid, strerror(errno)); | ||
252 | return EXIT_FAILURE; | ||
253 | } | ||
254 | } | ||
255 | else | ||
256 | sid = 0; | ||
257 | #endif | ||
258 | |||
220 | if ( *tty != '/' ) | 259 | if ( *tty != '/' ) |
221 | snprintf ( full_tty, sizeof( full_tty ) - 1, "/dev/%s", tty); | 260 | snprintf ( full_tty, sizeof( full_tty ) - 1, "/dev/%s", tty); |
222 | else | 261 | else |
@@ -239,7 +278,11 @@ auth_ok: | |||
239 | if ( pw-> pw_uid == 0 ) | 278 | if ( pw-> pw_uid == 0 ) |
240 | syslog ( LOG_INFO, "root login %s\n", fromhost ); | 279 | syslog ( LOG_INFO, "root login %s\n", fromhost ); |
241 | 280 | ||
242 | run_shell ( pw-> pw_shell, 1, 0, 0 ); /* exec the shell finally. */ | 281 | run_shell ( pw-> pw_shell, 1, 0, 0 |
282 | #ifdef CONFIG_SELINUX | ||
283 | , sid | ||
284 | #endif | ||
285 | ); /* exec the shell finally. */ | ||
243 | 286 | ||
244 | return EXIT_FAILURE; | 287 | return EXIT_FAILURE; |
245 | } | 288 | } |
diff --git a/loginutils/su.c b/loginutils/su.c index 5e40cf2e4..85f5cbe7b 100644 --- a/loginutils/su.c +++ b/loginutils/su.c | |||
@@ -156,7 +156,11 @@ int su_main ( int argc, char **argv ) | |||
156 | 156 | ||
157 | change_identity ( pw ); | 157 | change_identity ( pw ); |
158 | setup_environment ( opt_shell, opt_loginshell, !opt_preserve, pw ); | 158 | setup_environment ( opt_shell, opt_loginshell, !opt_preserve, pw ); |
159 | run_shell ( opt_shell, opt_loginshell, opt_command, (const char**)opt_args ); | 159 | run_shell ( opt_shell, opt_loginshell, opt_command, (const char**)opt_args |
160 | #ifdef CONFIG_SELINUX | ||
161 | , 0 | ||
162 | #endif | ||
163 | ); | ||
160 | 164 | ||
161 | return EXIT_FAILURE; | 165 | return EXIT_FAILURE; |
162 | } | 166 | } |
diff --git a/procps/ps.c b/procps/ps.c index 5ccac7a95..691f490c7 100644 --- a/procps/ps.c +++ b/procps/ps.c | |||
@@ -31,6 +31,11 @@ | |||
31 | #include <termios.h> | 31 | #include <termios.h> |
32 | #include <sys/ioctl.h> | 32 | #include <sys/ioctl.h> |
33 | #include "busybox.h" | 33 | #include "busybox.h" |
34 | #ifdef CONFIG_SELINUX | ||
35 | #include <fs_secure.h> | ||
36 | #include <ss.h> | ||
37 | #include <flask_util.h> /* for is_flask_enabled() */ | ||
38 | #endif | ||
34 | 39 | ||
35 | static const int TERMINAL_WIDTH = 79; /* not 80 in case terminal has linefold bug */ | 40 | static const int TERMINAL_WIDTH = 79; /* not 80 in case terminal has linefold bug */ |
36 | 41 | ||
@@ -47,6 +52,13 @@ extern int ps_main(int argc, char **argv) | |||
47 | #define terminal_width TERMINAL_WIDTH | 52 | #define terminal_width TERMINAL_WIDTH |
48 | #endif | 53 | #endif |
49 | 54 | ||
55 | #ifdef CONFIG_SELINUX | ||
56 | int use_selinux = 0; | ||
57 | security_id_t sid; | ||
58 | if(is_flask_enabled() && argv[1] && !strcmp(argv[1], "-c") ) | ||
59 | use_selinux = 1; | ||
60 | #endif | ||
61 | |||
50 | 62 | ||
51 | #ifdef CONFIG_FEATURE_AUTOWIDTH | 63 | #ifdef CONFIG_FEATURE_AUTOWIDTH |
52 | ioctl(fileno(stdout), TIOCGWINSZ, &win); | 64 | ioctl(fileno(stdout), TIOCGWINSZ, &win); |
@@ -54,10 +66,31 @@ extern int ps_main(int argc, char **argv) | |||
54 | terminal_width = win.ws_col - 1; | 66 | terminal_width = win.ws_col - 1; |
55 | #endif | 67 | #endif |
56 | 68 | ||
69 | #ifdef CONFIG_SELINUX | ||
70 | if(use_selinux) | ||
71 | printf(" PID Context Stat Command\n"); | ||
72 | else | ||
73 | #endif | ||
57 | printf(" PID Uid VmSize Stat Command\n"); | 74 | printf(" PID Uid VmSize Stat Command\n"); |
75 | #ifdef CONFIG_SELINUX | ||
76 | while ((p = procps_scan(1, use_selinux, &sid)) != 0) { | ||
77 | #else | ||
58 | while ((p = procps_scan(1)) != 0) { | 78 | while ((p = procps_scan(1)) != 0) { |
79 | #endif | ||
59 | char *namecmd = p->cmd; | 80 | char *namecmd = p->cmd; |
60 | 81 | ||
82 | #ifdef CONFIG_SELINUX | ||
83 | if(use_selinux) | ||
84 | { | ||
85 | char sbuf[128]; | ||
86 | len = sizeof(sbuf); | ||
87 | if(security_sid_to_context(sid, (security_context_t)&sbuf, &len)) | ||
88 | strcpy(sbuf, "unknown"); | ||
89 | |||
90 | len = printf("%5d %-32s %s ", p->pid, sbuf, p->state); | ||
91 | } | ||
92 | else | ||
93 | #endif | ||
61 | if(p->rss == 0) | 94 | if(p->rss == 0) |
62 | len = printf("%5d %-8s %s ", p->pid, p->user, p->state); | 95 | len = printf("%5d %-8s %s ", p->pid, p->user, p->state); |
63 | else | 96 | else |
diff --git a/procps/top.c b/procps/top.c index b70a42a72..2e1bd3286 100644 --- a/procps/top.c +++ b/procps/top.c | |||
@@ -501,7 +501,11 @@ int top_main(int argc, char **argv) | |||
501 | /* read process IDs & status for all the processes */ | 501 | /* read process IDs & status for all the processes */ |
502 | procps_status_t * p; | 502 | procps_status_t * p; |
503 | 503 | ||
504 | #ifdef CONFIG_SELINUX | ||
505 | while ((p = procps_scan(0, 0, NULL) ) != 0) { | ||
506 | #else | ||
504 | while ((p = procps_scan(0)) != 0) { | 507 | while ((p = procps_scan(0)) != 0) { |
508 | #endif | ||
505 | int n = ntop; | 509 | int n = ntop; |
506 | 510 | ||
507 | top = xrealloc(top, (++ntop)*sizeof(procps_status_t)); | 511 | top = xrealloc(top, (++ntop)*sizeof(procps_status_t)); |
diff --git a/sysdeps/linux/Config.in b/sysdeps/linux/Config.in index 70dd2ca5e..2e9ddc382 100644 --- a/sysdeps/linux/Config.in +++ b/sysdeps/linux/Config.in | |||
@@ -106,6 +106,13 @@ config CONFIG_FEATURE_SUID_CONFIG_QUIET | |||
106 | help | 106 | help |
107 | Please submit a patch to add help text for this item. | 107 | Please submit a patch to add help text for this item. |
108 | 108 | ||
109 | config CONFIG_SELINUX | ||
110 | bool "Support NSA Security Enhanced Linux" | ||
111 | default n | ||
112 | help | ||
113 | Enable support for SE Linux in applets ls, ps, and id. Also provide | ||
114 | the option of compiling in SE Linux applets. | ||
115 | |||
109 | endmenu | 116 | endmenu |
110 | 117 | ||
111 | menu 'Build Options' | 118 | menu 'Build Options' |