diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-21 02:14:19 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-21 02:14:19 +0200 |
| commit | 44b3f2ffbc01c0a9fcfb5d60af3e292f505ac67c (patch) | |
| tree | f892e9df211798dd5335b6bc363c0afa0effd462 /util-linux | |
| parent | ec2482e966c505d9076cf8581dabc4925c4c8bfe (diff) | |
| download | busybox-w32-44b3f2ffbc01c0a9fcfb5d60af3e292f505ac67c.tar.gz busybox-w32-44b3f2ffbc01c0a9fcfb5d60af3e292f505ac67c.tar.bz2 busybox-w32-44b3f2ffbc01c0a9fcfb5d60af3e292f505ac67c.zip | |
libbb: move capability names code to libbb
function old new delta
cap_name_to_number - 77 +77
parse_cap 117 29 -88
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/1 up/down: 77/-88) Total: -11 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux')
| -rw-r--r-- | util-linux/setpriv.c | 82 |
1 files changed, 5 insertions, 77 deletions
diff --git a/util-linux/setpriv.c b/util-linux/setpriv.c index c549bcaf8..9f2793949 100644 --- a/util-linux/setpriv.c +++ b/util-linux/setpriv.c | |||
| @@ -5,7 +5,6 @@ | |||
| 5 | * Copyright (C) 2017 by <assafgordon@gmail.com> | 5 | * Copyright (C) 2017 by <assafgordon@gmail.com> |
| 6 | * | 6 | * |
| 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
| 8 | * | ||
| 9 | */ | 8 | */ |
| 10 | //config:config SETPRIV | 9 | //config:config SETPRIV |
| 11 | //config: bool "setpriv (3.4 kb)" | 10 | //config: bool "setpriv (3.4 kb)" |
| @@ -131,49 +130,6 @@ struct caps { | |||
| 131 | int u32s; | 130 | int u32s; |
| 132 | }; | 131 | }; |
| 133 | 132 | ||
| 134 | # if ENABLE_FEATURE_SETPRIV_CAPABILITY_NAMES | ||
| 135 | static const char *const capabilities[] = { | ||
| 136 | "chown", | ||
| 137 | "dac_override", | ||
| 138 | "dac_read_search", | ||
| 139 | "fowner", | ||
| 140 | "fsetid", | ||
| 141 | "kill", | ||
| 142 | "setgid", | ||
| 143 | "setuid", | ||
| 144 | "setpcap", | ||
| 145 | "linux_immutable", | ||
| 146 | "net_bind_service", | ||
| 147 | "net_broadcast", | ||
| 148 | "net_admin", | ||
| 149 | "net_raw", | ||
| 150 | "ipc_lock", | ||
| 151 | "ipc_owner", | ||
| 152 | "sys_module", | ||
| 153 | "sys_rawio", | ||
| 154 | "sys_chroot", | ||
| 155 | "sys_ptrace", | ||
| 156 | "sys_pacct", | ||
| 157 | "sys_admin", | ||
| 158 | "sys_boot", | ||
| 159 | "sys_nice", | ||
| 160 | "sys_resource", | ||
| 161 | "sys_time", | ||
| 162 | "sys_tty_config", | ||
| 163 | "mknod", | ||
| 164 | "lease", | ||
| 165 | "audit_write", | ||
| 166 | "audit_control", | ||
| 167 | "setfcap", | ||
| 168 | "mac_override", | ||
| 169 | "mac_admin", | ||
| 170 | "syslog", | ||
| 171 | "wake_alarm", | ||
| 172 | "block_suspend", | ||
| 173 | "audit_read", | ||
| 174 | }; | ||
| 175 | # endif /* FEATURE_SETPRIV_CAPABILITY_NAMES */ | ||
| 176 | |||
| 177 | static void getcaps(struct caps *caps) | 133 | static void getcaps(struct caps *caps) |
| 178 | { | 134 | { |
| 179 | static const uint8_t versions[] = { | 135 | static const uint8_t versions[] = { |
| @@ -211,10 +167,8 @@ static void getcaps(struct caps *caps) | |||
| 211 | bb_simple_perror_msg_and_die("capget"); | 167 | bb_simple_perror_msg_and_die("capget"); |
| 212 | } | 168 | } |
| 213 | 169 | ||
| 214 | static unsigned long parse_cap(const char *cap) | 170 | static unsigned parse_cap(const char *cap) |
| 215 | { | 171 | { |
| 216 | unsigned long i; | ||
| 217 | |||
| 218 | switch (cap[0]) { | 172 | switch (cap[0]) { |
| 219 | case '-': | 173 | case '-': |
| 220 | break; | 174 | break; |
| @@ -226,24 +180,7 @@ static unsigned long parse_cap(const char *cap) | |||
| 226 | } | 180 | } |
| 227 | 181 | ||
| 228 | cap++; | 182 | cap++; |
| 229 | if ((sscanf(cap, "cap_%lu", &i)) == 1) { | 183 | return cap_name_to_number(cap); |
| 230 | if (!cap_valid(i)) | ||
| 231 | bb_error_msg_and_die("unsupported capability '%s'", cap); | ||
| 232 | return i; | ||
| 233 | } | ||
| 234 | |||
| 235 | # if ENABLE_FEATURE_SETPRIV_CAPABILITY_NAMES | ||
| 236 | for (i = 0; i < ARRAY_SIZE(capabilities); i++) { | ||
| 237 | if (strcasecmp(capabilities[i], cap) != 0) | ||
| 238 | continue; | ||
| 239 | |||
| 240 | if (!cap_valid(i)) | ||
| 241 | bb_error_msg_and_die("unsupported capability '%s'", cap); | ||
| 242 | return i; | ||
| 243 | } | ||
| 244 | # endif | ||
| 245 | |||
| 246 | bb_error_msg_and_die("unknown capability '%s'", cap); | ||
| 247 | } | 184 | } |
| 248 | 185 | ||
| 249 | static void set_inh_caps(char *capstring) | 186 | static void set_inh_caps(char *capstring) |
| @@ -254,7 +191,7 @@ static void set_inh_caps(char *capstring) | |||
| 254 | 191 | ||
| 255 | capstring = strtok(capstring, ","); | 192 | capstring = strtok(capstring, ","); |
| 256 | while (capstring) { | 193 | while (capstring) { |
| 257 | unsigned long cap; | 194 | unsigned cap; |
| 258 | 195 | ||
| 259 | cap = parse_cap(capstring); | 196 | cap = parse_cap(capstring); |
| 260 | if (CAP_TO_INDEX(cap) >= caps.u32s) | 197 | if (CAP_TO_INDEX(cap) >= caps.u32s) |
| @@ -280,7 +217,7 @@ static void set_ambient_caps(char *string) | |||
| 280 | 217 | ||
| 281 | cap = strtok(string, ","); | 218 | cap = strtok(string, ","); |
| 282 | while (cap) { | 219 | while (cap) { |
| 283 | unsigned long index; | 220 | unsigned index; |
| 284 | 221 | ||
| 285 | index = parse_cap(cap); | 222 | index = parse_cap(cap); |
| 286 | if (cap[0] == '+') { | 223 | if (cap[0] == '+') { |
| @@ -296,16 +233,7 @@ static void set_ambient_caps(char *string) | |||
| 296 | #endif /* FEATURE_SETPRIV_CAPABILITIES */ | 233 | #endif /* FEATURE_SETPRIV_CAPABILITIES */ |
| 297 | 234 | ||
| 298 | #if ENABLE_FEATURE_SETPRIV_DUMP | 235 | #if ENABLE_FEATURE_SETPRIV_DUMP |
| 299 | # if ENABLE_FEATURE_SETPRIV_CAPABILITY_NAMES | 236 | # if !ENABLE_FEATURE_SETPRIV_CAPABILITY_NAMES |
| 300 | static void printf_cap(const char *pfx, unsigned cap_no) | ||
| 301 | { | ||
| 302 | if (cap_no < ARRAY_SIZE(capabilities)) { | ||
| 303 | printf("%s%s", pfx, capabilities[cap_no]); | ||
| 304 | return; | ||
| 305 | } | ||
| 306 | printf("%scap_%u", pfx, cap_no); | ||
| 307 | } | ||
| 308 | # else | ||
| 309 | # define printf_cap(pfx, cap_no) printf("%scap_%u", (pfx), (cap_no)) | 237 | # define printf_cap(pfx, cap_no) printf("%scap_%u", (pfx), (cap_no)) |
| 310 | # endif | 238 | # endif |
| 311 | 239 | ||
