diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-03-10 16:58:49 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-03-10 16:58:49 +0000 |
commit | 49622d784672bf2f7b2fe80589714cdef5adde0c (patch) | |
tree | 892bb79b0ef031d729e688d6be4950f6d17f13b9 /coreutils/id.c | |
parent | 4eb8b936cb0aeb27c3e12f9a93fc43aa1e9668f5 (diff) | |
download | busybox-w32-49622d784672bf2f7b2fe80589714cdef5adde0c.tar.gz busybox-w32-49622d784672bf2f7b2fe80589714cdef5adde0c.tar.bz2 busybox-w32-49622d784672bf2f7b2fe80589714cdef5adde0c.zip |
selinux support by Yuichi Nakamura <ynakam@hitachisoft.jp> (HitachiSoft)
Diffstat (limited to 'coreutils/id.c')
-rw-r--r-- | coreutils/id.c | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/coreutils/id.c b/coreutils/id.c index 963ee0566..a0364675f 100644 --- a/coreutils/id.c +++ b/coreutils/id.c | |||
@@ -10,6 +10,7 @@ | |||
10 | /* BB_AUDIT SUSv3 _NOT_ compliant -- option -G is not currently supported. */ | 10 | /* BB_AUDIT SUSv3 _NOT_ compliant -- option -G is not currently supported. */ |
11 | /* Hacked by Tito Ragusa (C) 2004 to handle usernames of whatever length and to | 11 | /* Hacked by Tito Ragusa (C) 2004 to handle usernames of whatever length and to |
12 | * be more similar to GNU id. | 12 | * be more similar to GNU id. |
13 | * -Z option support: by Yuichi Nakamura <ynakam@hitachisoft.jp> | ||
13 | */ | 14 | */ |
14 | 15 | ||
15 | #include "busybox.h" | 16 | #include "busybox.h" |
@@ -17,14 +18,13 @@ | |||
17 | #include <unistd.h> | 18 | #include <unistd.h> |
18 | #include <sys/types.h> | 19 | #include <sys/types.h> |
19 | 20 | ||
20 | #ifdef CONFIG_SELINUX | ||
21 | #include <selinux/selinux.h> /* for is_selinux_enabled() */ | ||
22 | #endif | ||
23 | |||
24 | #define PRINT_REAL 1 | 21 | #define PRINT_REAL 1 |
25 | #define NAME_NOT_NUMBER 2 | 22 | #define NAME_NOT_NUMBER 2 |
26 | #define JUST_USER 4 | 23 | #define JUST_USER 4 |
27 | #define JUST_GROUP 8 | 24 | #define JUST_GROUP 8 |
25 | #if ENABLE_SELINUX | ||
26 | #define JUST_CONTEXT 16 | ||
27 | #endif | ||
28 | 28 | ||
29 | static short printf_full(unsigned int id, const char *arg, const char prefix) | 29 | static short printf_full(unsigned int id, const char *arg, const char prefix) |
30 | { | 30 | { |
@@ -47,11 +47,13 @@ int id_main(int argc, char **argv) | |||
47 | gid_t gid; | 47 | gid_t gid; |
48 | unsigned long flags; | 48 | unsigned long flags; |
49 | short status; | 49 | short status; |
50 | 50 | #if ENABLE_SELINUX | |
51 | security_context_t scontext; | ||
52 | #endif | ||
51 | /* Don't allow -n -r -nr -ug -rug -nug -rnug */ | 53 | /* Don't allow -n -r -nr -ug -rug -nug -rnug */ |
52 | /* Don't allow more than one username */ | 54 | /* Don't allow more than one username */ |
53 | opt_complementary = "?1:?:u--g:g--u:r?ug:n?ug"; | 55 | opt_complementary = "?1:?:u--g:g--u:r?ug:n?ug" USE_SELINUX(":u--Z:Z--u:g--Z:Z--g"); |
54 | flags = getopt32(argc, argv, "rnug"); | 56 | flags = getopt32(argc, argv, "rnug" USE_SELINUX("Z")); |
55 | 57 | ||
56 | /* This values could be overwritten later */ | 58 | /* This values could be overwritten later */ |
57 | uid = geteuid(); | 59 | uid = geteuid(); |
@@ -69,14 +71,33 @@ int id_main(int argc, char **argv) | |||
69 | /* in this case PRINT_REAL is the same */ | 71 | /* in this case PRINT_REAL is the same */ |
70 | } | 72 | } |
71 | 73 | ||
72 | if (flags & (JUST_GROUP | JUST_USER)) { | 74 | if (flags & (JUST_GROUP | JUST_USER USE_SELINUX(| JUST_CONTEXT))) { |
73 | /* JUST_GROUP and JUST_USER are mutually exclusive */ | 75 | /* JUST_GROUP and JUST_USER are mutually exclusive */ |
74 | if (flags & NAME_NOT_NUMBER) { | 76 | if (flags & NAME_NOT_NUMBER) { |
75 | /* bb_getpwuid and bb_getgrgid exit on failure so puts cannot segfault */ | 77 | /* bb_getpwuid and bb_getgrgid exit on failure so puts cannot segfault */ |
76 | puts((flags & JUST_USER) ? bb_getpwuid(NULL, uid, -1 ) : bb_getgrgid(NULL, gid, -1 )); | 78 | puts((flags & JUST_USER) ? bb_getpwuid(NULL, uid, -1 ) : bb_getgrgid(NULL, gid, -1 )); |
77 | } else { | 79 | } else { |
78 | printf("%u\n", (flags & JUST_USER) ? uid : gid); | 80 | if (flags & JUST_USER) { |
79 | } | 81 | printf("%u\n", uid); |
82 | } | ||
83 | if (flags & JUST_GROUP) { | ||
84 | printf("%u\n", gid); | ||
85 | } | ||
86 | } | ||
87 | |||
88 | #if ENABLE_SELINUX | ||
89 | if (flags & JUST_CONTEXT) { | ||
90 | selinux_or_die(); | ||
91 | if (argc - optind == 1) { | ||
92 | bb_error_msg_and_die("can't print security context when user specified"); | ||
93 | } | ||
94 | |||
95 | if (getcon(&scontext)) { | ||
96 | bb_error_msg_and_die("can't get process context"); | ||
97 | } | ||
98 | printf("%s\n", scontext); | ||
99 | } | ||
100 | #endif | ||
80 | /* exit */ | 101 | /* exit */ |
81 | fflush_stdout_and_exit(EXIT_SUCCESS); | 102 | fflush_stdout_and_exit(EXIT_SUCCESS); |
82 | } | 103 | } |
@@ -88,7 +109,7 @@ int id_main(int argc, char **argv) | |||
88 | /* bb_getgrgid doesn't exit on failure here */ | 109 | /* bb_getgrgid doesn't exit on failure here */ |
89 | status |= printf_full(gid, bb_getgrgid(NULL, gid, 0), 'g'); | 110 | status |= printf_full(gid, bb_getgrgid(NULL, gid, 0), 'g'); |
90 | 111 | ||
91 | #ifdef CONFIG_SELINUX | 112 | #if ENABLE_SELINUX |
92 | if (is_selinux_enabled()) { | 113 | if (is_selinux_enabled()) { |
93 | security_context_t mysid; | 114 | security_context_t mysid; |
94 | const char *context; | 115 | const char *context; |