3 * Copyright (C) 2005 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 /*****************************************************************************
21 * File cap_print.c: An example for capabilities print
23 * Author: S. Piccardi Dec. 2005
25 *****************************************************************************/
26 #include <stdlib.h> /* C standard library */
27 #include <stdio.h> /* standard I/O library */
28 #include <unistd.h> /* unix standard library */
29 #include <sys/capability.h>
34 * Use libcap2 functions and print results
36 /* Help printing routine */
39 int main(int argc, char *argv[])
42 * Variables definition
46 cap_flag_t capset=CAP_EFFECTIVE;
47 cap_flag_value_t capval;
48 cap_value_t capability;
51 * Input section: decode command line parameters
54 opterr = 0; /* don't want writing to stderr */
55 while ( (i = getopt(argc, argv, "hepi")) != -1) {
60 case 'i': /* read inherited set */
61 capset=CAP_INHERITABLE;
63 case 'e': /* read effective set */
66 case 'p': /* read permitted set */
69 case 'h': /* help option */
70 printf("Wrong -h option use\n");
74 case '?': /* unrecognized options */
75 printf("Unrecognized options -%c\n",optopt);
77 default: /* should not reached */
81 /* ***********************************************************
83 * Options processing completed
87 * ***********************************************************/
88 if ((argc - optind) != 0) {
89 printf("Wrong number of arguments %d\n", argc - optind);
92 if ( (capstatus = cap_get_proc()) == NULL) {
93 perror("Lettura delle capabilities fallita");
95 if ( (buffer = cap_to_text(capstatus, NULL)) == NULL) {
96 perror("Cannot convert capability status:");
98 printf("Capabilities:\n %s\n", buffer);
102 * routine to print usage info and exit
105 printf("Program mygethost: do an hostname resolution \n");
107 printf(" mygethost [-h] hostname \n");
108 printf(" -h print this help\n");