aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew G. Morgan <morgan@kernel.org>2021-08-23 20:09:53 -0700
committerAndrew G. Morgan <morgan@kernel.org>2021-08-23 20:09:53 -0700
commitbe65c32dedbea96760fa7226881fed64f63d9a52 (patch)
tree7f5fee487c9eb6d534069d2e83fc1f5fd6bcf06c
parent5647374b3319796957edfb25400bf4164efca6c2 (diff)
downloadlibcap-be65c32dedbea96760fa7226881fed64f63d9a52.tar.gz
Make 'progs/getpcaps --iab' act like 'go/captree' in output format
The combined options 'getpcaps --iab --verbose' will show everything in detail (even the boring stuff). Also used this exercise to test the libcap changes for iab comparisons. Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
-rw-r--r--progs/getpcaps.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/progs/getpcaps.c b/progs/getpcaps.c
index 3cd3fa0..8fce0a3 100644
--- a/progs/getpcaps.c
+++ b/progs/getpcaps.c
@@ -32,6 +32,7 @@ int main(int argc, char **argv)
int retval = 0;
int verbose = 0;
int iab = 0;
+ cap_iab_t noiab = cap_iab_init();
if (argc < 2) {
usage(1);
@@ -71,24 +72,34 @@ int main(int argc, char **argv)
continue;
} else {
char *result = cap_to_text(cap_d, NULL);
- if (verbose == 1) {
- printf("Capabilities for '%s': %s\n", *argv, result);
- } else if (verbose == 2) {
- fprintf(stderr, "Capabilities for `%s': %s\n", *argv, result);
- } else if (iab) {
+ if (iab) {
+ printf("%s:", *argv);
+ if (verbose || strcmp("=", result) != 0) {
+ printf(" \"%s\"", result);
+ }
cap_iab_t iab_val = cap_iab_get_pid(pid);
if (iab_val == NULL) {
- fprintf(stderr, "no IAB value for %d\n", pid);
+ fprintf(stderr, " no IAB value for %d\n", pid);
exit(1);
}
- char *iab_text = cap_iab_to_text(iab_val);
- if (iab_text == NULL) {
- perror("no text for IAB");
- exit(1);
+ int cf = cap_iab_compare(noiab, iab_val);
+ if (verbose ||
+ CAP_IAB_DIFFERS(cf, CAP_IAB_AMB) ||
+ CAP_IAB_DIFFERS(cf, CAP_IAB_BOUND)) {
+ char *iab_text = cap_iab_to_text(iab_val);
+ if (iab_text == NULL) {
+ perror(" no text for IAB");
+ exit(1);
+ }
+ printf(" [%s]", iab_text);
+ cap_free(iab_text);
}
- printf("%s: \"%s\" [%s]\n", *argv, result, iab_text);
- cap_free(iab_text);
cap_free(iab_val);
+ printf("\n");
+ } else if (verbose == 1) {
+ printf("Capabilities for '%s': %s\n", *argv, result);
+ } else if (verbose == 2) {
+ fprintf(stderr, "Capabilities for `%s': %s\n", *argv, result);
} else {
printf("%s: %s\n", *argv, result);
}