diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-07 16:09:45 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-07 16:09:45 +0200 |
| commit | 2bfe7838abd64efa7b18d7d428c5477669f967b0 (patch) | |
| tree | 48cdb2ef0d6718640db9a192606b17b4e70e2a66 | |
| parent | cf5748cc892f78c004359ed321bf72bc8e3772ac (diff) | |
| download | busybox-w32-2bfe7838abd64efa7b18d7d428c5477669f967b0.tar.gz busybox-w32-2bfe7838abd64efa7b18d7d428c5477669f967b0.tar.bz2 busybox-w32-2bfe7838abd64efa7b18d7d428c5477669f967b0.zip | |
setpriv: factor out capability name printing
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | util-linux/setpriv.c | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/util-linux/setpriv.c b/util-linux/setpriv.c index dc83549ba..3a7e68006 100644 --- a/util-linux/setpriv.c +++ b/util-linux/setpriv.c | |||
| @@ -291,6 +291,19 @@ static void set_ambient_caps(char *string) | |||
| 291 | #endif /* FEATURE_SETPRIV_CAPABILITIES */ | 291 | #endif /* FEATURE_SETPRIV_CAPABILITIES */ |
| 292 | 292 | ||
| 293 | #if ENABLE_FEATURE_SETPRIV_DUMP | 293 | #if ENABLE_FEATURE_SETPRIV_DUMP |
| 294 | # if ENABLE_FEATURE_SETPRIV_CAPABILITY_NAMES | ||
| 295 | static void printf_cap(const char *pfx, unsigned cap_no) | ||
| 296 | { | ||
| 297 | if (cap_no < ARRAY_SIZE(capabilities)) { | ||
| 298 | printf("%s%s", pfx, capabilities[cap_no]); | ||
| 299 | return; | ||
| 300 | } | ||
| 301 | printf("%scap_%u", pfx, cap_no); | ||
| 302 | } | ||
| 303 | # else | ||
| 304 | # define printf_cap(pfx, cap_no) printf("%scap_%u", (pfx), (cap_no)) | ||
| 305 | # endif | ||
| 306 | |||
| 294 | static int dump(void) | 307 | static int dump(void) |
| 295 | { | 308 | { |
| 296 | IF_FEATURE_SETPRIV_CAPABILITIES(struct caps caps;) | 309 | IF_FEATURE_SETPRIV_CAPABILITIES(struct caps caps;) |
| @@ -337,12 +350,7 @@ static int dump(void) | |||
| 337 | bb_error_msg_and_die("unsupported capability"); | 350 | bb_error_msg_and_die("unsupported capability"); |
| 338 | } | 351 | } |
| 339 | if (caps.data[idx].inheritable & CAP_TO_MASK(i)) { | 352 | if (caps.data[idx].inheritable & CAP_TO_MASK(i)) { |
| 340 | # if ENABLE_FEATURE_SETPRIV_CAPABILITY_NAMES | 353 | printf_cap(fmt, i); |
| 341 | if (i < ARRAY_SIZE(capabilities)) | ||
| 342 | printf("%s%s", fmt, capabilities[i]); | ||
| 343 | else | ||
| 344 | # endif | ||
| 345 | printf("%scap_%u", fmt, i); | ||
| 346 | fmt = ","; | 354 | fmt = ","; |
| 347 | } | 355 | } |
| 348 | } | 356 | } |
| @@ -356,12 +364,7 @@ static int dump(void) | |||
| 356 | if (ret < 0) | 364 | if (ret < 0) |
| 357 | bb_perror_msg_and_die("prctl: %s", "CAP_AMBIENT_IS_SET"); | 365 | bb_perror_msg_and_die("prctl: %s", "CAP_AMBIENT_IS_SET"); |
| 358 | if (ret) { | 366 | if (ret) { |
| 359 | # if ENABLE_FEATURE_SETPRIV_CAPABILITY_NAMES | 367 | printf_cap(fmt, i); |
| 360 | if (i < ARRAY_SIZE(capabilities)) | ||
| 361 | printf("%s%s", fmt, capabilities[i]); | ||
| 362 | else | ||
| 363 | # endif | ||
| 364 | printf("%scap_%u", fmt, i); | ||
| 365 | fmt = ","; | 368 | fmt = ","; |
| 366 | } | 369 | } |
| 367 | } | 370 | } |
| @@ -377,12 +380,7 @@ static int dump(void) | |||
| 377 | if (ret < 0) | 380 | if (ret < 0) |
| 378 | bb_perror_msg_and_die("prctl: %s", "CAPBSET_READ"); | 381 | bb_perror_msg_and_die("prctl: %s", "CAPBSET_READ"); |
| 379 | if (ret) { | 382 | if (ret) { |
| 380 | # if ENABLE_FEATURE_SETPRIV_CAPABILITY_NAMES | 383 | printf_cap(fmt, i); |
| 381 | if (i < ARRAY_SIZE(capabilities)) | ||
| 382 | printf("%s%s", fmt, capabilities[i]); | ||
| 383 | else | ||
| 384 | # endif | ||
| 385 | printf("%scap_%u", fmt, i); | ||
| 386 | fmt = ","; | 384 | fmt = ","; |
| 387 | } | 385 | } |
| 388 | } | 386 | } |
