1CAP_GET_PROC(3)            Linux Programmer's Manual           CAP_GET_PROC(3)
2
3
4

NAME

6       cap_get_proc,  cap_set_proc,  capgetp,  cap_get_bound, cap_drop_bound -
7       capability manipulation on processes
8

SYNOPSIS

10       #include <sys/capability.h>
11
12       cap_t cap_get_proc(void);
13
14       int cap_set_proc(cap_t cap_p);
15
16       int cap_get_bound(cap_value_t cap);
17
18       CAP_IS_SUPPORTED(cap_value_t cap);
19
20       int cap_drop_bound(cap_value_t cap);
21
22       #include <sys/types.h>
23
24       cap_t cap_get_pid(pid_t pid);
25
26       Link with -lcap.
27

DESCRIPTION

29       cap_get_proc() allocates a capability state in  working  storage,  sets
30       its state to that of the calling process, and returns a pointer to this
31       newly created capability state.  The caller should free any  releasable
32       memory,  when  the  capability  state  in  working storage is no longer
33       required, by calling cap_free() with the cap_t as an argument.
34
35       cap_set_proc() sets the values for all capability flags for  all  capa‐
36       bilities to the capability state identified by cap_p.  The new capabil‐
37       ity state of the process will be completely determined by the  contents
38       of  cap_p  upon  successful  return from this function.  If any flag in
39       cap_p is set for any capability not currently permitted for the calling
40       process,  the  function  will  fail,  and  the  capability state of the
41       process will remain unchanged.
42
43       cap_get_pid() returns cap_t, see cap_init(3), with the process capabil‐
44       ities  of  the  process indicated by pid.  This information can also be
45       obtained from the /proc/<pid>/status file.
46
47       cap_get_bound() with a cap as an argument returns the current value  of
48       this  bounding  set  capability flag in effect for the current process.
49       This operation  is  unpriveged.  Note,  a  macro  function  CAP_IS_SUP‐
50       PORTED(cap_value_t  cap)  is provided that evaluates to true (1) if the
51       system supports the specified capability, cap.  If the system does  not
52       support  the  capability,  this function returns 0. This macro works by
53       testing for an error condition with cap_get_bound().
54
55       cap_drop_bound() can be used to lower the specified bounding set  capa‐
56       bility,  cap,  To complete successfully, the prevailing effective capa‐
57       bility set must have a raised CAP_SETPCAP.
58

RETURN VALUE

60       The functions cap_get_proc() and cap_get_pid() return a non-NULL  value
61       on success, and NULL on failure.
62
63       The  function cap_get_bound() returns -1 if the requested capability is
64       unknown, otherwise the return value reflects the current state of  that
65       capability in the prevailing bounding set. Note, a macro function,
66
67       The  functions cap_set_proc() and cap_drop_bound() return zero for suc‐
68       cess, and -1 on failure.
69
70       On failure, errno is set to EINVAL, EPERM, or ENOMEM.
71

CONFORMING TO

73       cap_set_proc()  and  cap_get_proc()  are  specified  in  the  withdrawn
74       POSIX.1e draft specification.  cap_get_pid() is a Linux extension.
75

NOTES

77       The library also supports the deprecated functions:
78
79       int capgetp(pid_t pid, cap_t cap_d);
80
81       int capsetp(pid_t pid, cap_t cap_d);
82
83       capgetp()  attempts  to  obtain the capabilities of some other process;
84       storing the capabilities in a pre-allocated  cap_d.See  cap_init()  for
85       information  on  allocating  an  empty  capability  set. This function,
86       capgetp(), is deprecated, you should use cap_get_pid().
87
88       capsetp() attempts to set the capabilities of some  other  process(es),
89       pid.   If  pid  is  positive it refers to a specific process;  if it is
90       zero, it refers to the current process;  -1  refers  to  all  processes
91       other  than  the  current  process and process '1' (typically init(8));
92       other negative values refer to the -pid process group.  In order to use
93       this  function, the kernel must support it and the current process must
94       have CAP_SETPCAP raised in its Effective capability set. The  capabili‐
95       ties  set in the target process(es) are those contained in cap_d.  Ker‐
96       nels that support filesystem capabilities  redefine  the  semantics  of
97       CAP_SETPCAP  and on such systems this function will always fail for any
98       target not equal to the current process.  capsetp()  returns  zero  for
99       success, and -1 on failure.
100
101       Where  supported  by  the kernel, the function capsetp() should be used
102       with care.  It existed, primarily, to overcome an early lack of support
103       for  capabilities in the filesystems supported by Linux.  Note that, by
104       default, the only processes that have CAP_SETPCAP available to them are
105       processes  started  as  a  kernel  thread.   (Typically  this  includes
106       init(8), kflushd and kswapd). You will need to recompile the kernel  to
107       modify this default.
108

EXAMPLE

110       The  code segment below raises the CAP_FOWNER and CAP_SETFCAP effective
111       capabilities for the caller:
112
113           cap_t caps;
114           cap_value_t cap_list[2];
115
116           if (!CAP_IS_SUPPORTED(CAP_SETFCAP))
117               /* handle error */
118
119           caps = cap_get_proc();
120           if (caps == NULL)
121               /* handle error */;
122
123           cap_list[0] = CAP_FOWNER;
124           cap_list[1] = CAP_SETFCAP;
125           if (cap_set_flag(caps, CAP_EFFECTIVE, 2, cap_list, CAP_SET) == -1)
126               /* handle error */;
127
128           if (cap_set_proc(caps) == -1)
129               /* handle error */;
130
131           if (cap_free(caps) == -1)
132               /* handle error */;
133

SEE ALSO

135       libcap(3),     cap_clear(3),     cap_copy_ext(3),     cap_from_text(3),
136       cap_get_file(3), cap_init(3), capabilities(7)
137
138
139
140                                  2008-05-11                   CAP_GET_PROC(3)
Impressum