• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * <sys/capability.h>
3  *
4  * Copyright (C) 1997   Aleph One
5  * Copyright (C) 1997-8,2008 Andrew G. Morgan <morgan@kernel.org>
6  *
7  * defunct POSIX.1e Standard: 25.2 Capabilities           <sys/capability.h>
8  */
9 
10 #ifndef _SYS_CAPABILITY_H
11 #define _SYS_CAPABILITY_H
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 /*
18  * This file complements the kernel file by providing prototype
19  * information for the user library.
20  */
21 
22 #include <sys/types.h>
23 #include <stdint.h>
24 #include <linux/types.h>
25 
26 #ifndef __user
27 #define __user
28 #endif
29 #include <linux/capability.h>
30 
31 /*
32  * POSIX capability types
33  */
34 
35 /*
36  * Opaque capability handle (defined internally by libcap)
37  * internal capability representation
38  */
39 typedef struct _cap_struct *cap_t;
40 
41 /* "external" capability representation is a (void *) */
42 
43 /*
44  * This is the type used to identify capabilities
45  */
46 
47 typedef int cap_value_t;
48 
49 /*
50  * Set identifiers
51  */
52 typedef enum {
53     CAP_EFFECTIVE=0,                        /* Specifies the effective flag */
54     CAP_PERMITTED=1,                        /* Specifies the permitted flag */
55     CAP_INHERITABLE=2                     /* Specifies the inheritable flag */
56 } cap_flag_t;
57 
58 /*
59  * These are the states available to each capability
60  */
61 typedef enum {
62     CAP_CLEAR=0,                            /* The flag is cleared/disabled */
63     CAP_SET=1                                    /* The flag is set/enabled */
64 } cap_flag_value_t;
65 
66 /*
67  * User-space capability manipulation routines
68  */
69 
70 /* libcap/cap_alloc.c */
71 extern cap_t   cap_dup(cap_t);
72 extern int     cap_free(void *);
73 extern cap_t   cap_init(void);
74 
75 /* libcap/cap_flag.c */
76 extern int     cap_get_flag(cap_t, cap_value_t, cap_flag_t, cap_flag_value_t *);
77 extern int     cap_set_flag(cap_t, cap_flag_t, int, const cap_value_t *,
78 			    cap_flag_value_t);
79 extern int     cap_clear(cap_t);
80 extern int     cap_clear_flag(cap_t, cap_flag_t);
81 
82 /* libcap/cap_file.c */
83 extern cap_t   cap_get_fd(int);
84 extern cap_t   cap_get_file(const char *);
85 extern int     cap_set_fd(int, cap_t);
86 extern int     cap_set_file(const char *, cap_t);
87 
88 /* libcap/cap_proc.c */
89 extern cap_t   cap_get_proc(void);
90 extern cap_t   cap_get_pid(pid_t);
91 extern int     cap_set_proc(cap_t);
92 
93 extern int     cap_get_bound(cap_value_t);
94 extern int     cap_drop_bound(cap_value_t);
95 
96 #define CAP_IS_SUPPORTED(cap)  (cap_get_bound(cap) >= 0)
97 
98 /* libcap/cap_extint.c */
99 extern ssize_t cap_size(cap_t);
100 extern ssize_t cap_copy_ext(void *, cap_t, ssize_t);
101 extern cap_t   cap_copy_int(const void *);
102 
103 /* libcap/cap_text.c */
104 extern cap_t   cap_from_text(const char *);
105 extern char *  cap_to_text(cap_t, ssize_t *);
106 extern int     cap_from_name(const char *, cap_value_t *);
107 extern char *  cap_to_name(cap_value_t);
108 
109 #define CAP_DIFFERS(result, flag)  (((result) & (1 << (flag))) != 0)
110 extern int     cap_compare(cap_t, cap_t);
111 
112 /* system calls - look to libc for function to system call mapping */
113 extern int capset(cap_user_header_t header, cap_user_data_t data);
114 extern int capget(cap_user_header_t header, const cap_user_data_t data);
115 
116 /* deprecated - use cap_get_pid() */
117 extern int capgetp(pid_t pid, cap_t cap_d);
118 
119 /* not valid with filesystem capability support - use cap_set_proc() */
120 extern int capsetp(pid_t pid, cap_t cap_d);
121 
122 #ifdef __cplusplus
123 }
124 #endif
125 
126 #endif /* _SYS_CAPABILITY_H */
127