1 /******************************************************************************/
2 /* */
3 /* Copyright (c) International Business Machines Corp., 2008 */
4 /* */
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 */
8 /* (at your option) any later version. */
9 /* */
10 /* This program is distributed in the hope that it will be useful, */
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */
13 /* the GNU General Public License for more details. */
14 /* */
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
18 /* */
19 /******************************************************************************/
20 /*
21 * File: print_caps.c
22 * Author: Serge Hallyn
23 * Purpose: print out the POSIX capabilities with which it runs
24 */
25
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <unistd.h>
30 #include <sys/types.h>
31 #include <sys/stat.h>
32 #include <fcntl.h>
33 #include "config.h"
34
35 #if HAVE_SYS_CAPABILITY_H
36 #include <linux/types.h>
37 #include <sys/capability.h>
38 #endif
39
40 #include "filecaps_common.h"
41
main(int argc,char * argv[])42 int main(int argc, char *argv[])
43 {
44 #ifdef HAVE_LIBCAP
45 cap_t cap = cap_get_proc();
46 int fd;
47 int seqno = 0;
48 char buf[2000];
49
50 if (argc > 1)
51 seqno = atoi(argv[1]);
52
53 if (!cap) {
54 perror("print_caps - cap_get_proc");
55 exit(1);
56 }
57
58 fd = open(get_caps_fifo(), O_WRONLY);
59 if (!fd) {
60 perror("print_caps: open fifo");
61 exit(2);
62 }
63
64 snprintf(buf, 2000, "%d.%s", seqno, cap_to_text(cap, NULL));
65 write(fd, buf, strlen(buf) + 1);
66 close(fd);
67
68 cap_free(cap);
69 #endif
70 return 0;
71 }
72