3 * Copyright (C) 2006 Simone Piccardi
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /****************************************************************
22 * Program to test capabilities functions
24 * Author: Simone Piccardi
27 * Usage: getcap -h give all info's
30 ****************************************************************/
32 * Include needed headers
35 #include <errno.h> /* error definitions and routines */
36 #include <stdlib.h> /* C standard library */
37 #include <unistd.h> /* unix standard library */
38 #include <stdio.h> /* standard I/O library */
39 #include <string.h> /* string functions */
40 #include <sys/types.h>
41 #include <sys/capability.h>
43 /* Help printing routine */
46 int main(int argc, char *argv[])
49 * Variables definition
58 * Input section: decode command line parameters
61 opterr = 0; /* don't want writing to stderr */
62 while ( (i = getopt(argc, argv, "hp:")) != -1) {
67 case 'h': /* help option */
68 printf("Wrong -h option use\n");
72 case 'p': /* specify pid */
73 pid = strtol(optarg, NULL, 10);
75 case '?': /* unrecognized options */
76 printf("Unrecognized options -%c\n",optopt);
78 default: /* should not reached */
82 /* ***********************************************************
84 * Options processing completed
88 * ***********************************************************/
89 if ( (argc-optind) != 0) {
90 printf("From %d arguments, removed %d options\n", argc, optind);
95 capab = cap_get_proc();
97 perror("cannot get current process capabilities");
102 res = capgetp(pid, capab);
104 perror("cannot get process capabilities");
109 string = cap_to_text(capab, NULL);
110 printf("Capability: %s\n", string);
117 * routine to print usage info and exit
120 printf("Program getcap: print current process capabilities \n");
122 printf(" getcap [-h] [-p pid] \n");
123 printf(" -h print this help\n");
124 printf(" -p PID print process PID capabilities\n");