1 /* 2 * Copyright (c) 1997,2008 Andrew G. Morgan <morgan (at) kernel.org> 3 * 4 * This displays the capabilities of given target process(es). 5 */ 6 7 #include <sys/types.h> 8 #include <errno.h> 9 #include <stdio.h> 10 #include <string.h> 11 #include <stdlib.h> 12 #include <sys/capability.h> 13 14 static void usage(void) 15 { 16 fprintf(stderr, 17 "usage: getcaps <pid> [<pid> ...]\n\n" 18 " This program displays the capabilities on the queried process(es).\n" 19 " The capabilities are displayed in the cap_from_text(3) format.\n\n" 20 "[Copyright (c) 1997-8,2007 Andrew G. Morgan <morgan (at) kernel.org>]\n" 21 ); 22 exit(1); 23 } 24 25 int main(int argc, char **argv) 26 { 27 int retval = 0; 28 29 if (argc < 2) { 30 usage(); 31 } 32 33 for ( ++argv; --argc > 0; ++argv ) { 34 ssize_t length; 35 int pid; 36 cap_t cap_d; 37 38 pid = atoi(argv[0]); 39 40 cap_d = cap_get_pid(pid); 41 if (cap_d == NULL) { 42 fprintf(stderr, "Failed to get cap's for proccess %d:" 43 " (%s)\n", pid, strerror(errno)); 44 retval = 1; 45 continue; 46 } else { 47 char *result = cap_to_text(cap_d, &length); 48 fprintf(stderr, "Capabilities for `%s': %s\n", *argv, result); 49 cap_free(result); 50 result = NULL; 51 cap_free(cap_d); 52 } 53 } 54 55 return retval; 56 } 57