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

NAME

6       cap_get_proc,  cap_set_proc,  capgetp - capability manipulation on pro‐
7       cesses
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       #include <sys/types.h>
17
18       cap_t cap_get_pid(pid_t pid);
19
20       Link with -lcap.
21

DESCRIPTION

23       cap_get_proc() allocates a capability state in  working  storage,  sets
24       its state to that of the calling process, and returns a pointer to this
25       newly created capability state.  The caller should free any  releasable
26       memory,  when  the  capability  state  in  working storage is no longer
27       required, by calling cap_free() with the cap_t as an argument.
28
29       cap_set_proc() sets the values for all capability flags for  all  capa‐
30       bilities to the capability state identified by cap_p.  The new capabil‐
31       ity state of the process will be completely determined by the  contents
32       of  cap_p  upon  successful  return from this function.  If any flag in
33       cap_p is set for any capability not currently permitted for the calling
34       process,  the  function  will  fail,  and  the  capability state of the
35       process will remain unchanged.
36
37       cap_get_pid() returns cap_d, see cap_init(3), with the process capabil‐
38       ities  of  the  process indicated by pid.  This information can also be
39       obtained from the /proc/<pid>/status file.
40

RETURN VALUE

42       The functions cap_get_proc() and cap_get_pid() return a non-NULL  value
43       on success, and NULL on failure.
44
45       The function cap_set_proc() return zero for success, and -1 on failure.
46
47       On failure, errno is set to EINVAL, EPERM, or ENOMEM.
48

CONFORMING TO

50       cap_set_proc()  and  cap_get_proc()  are  specified  in  the  withdrawn
51       POSIX.1e draft specification.  cap_get_pid() is a Linux extension.
52

NOTES

54       The library also supports the deprecated functions:
55
56       int capgetp(pid_t pid, cap_t cap_d);
57
58       int capsetp(pid_t pid, cap_t cap_d);
59
60       capgetp() attempts to obtain the capabilities of  some  other  process;
61       storing  the  capabilities  in a pre-allocated cap_d.See cap_init() for
62       information on allocating  an  empty  capability  set.  This  function,
63       capgetp(), is deprecated, you should use cap_get_pid().
64
65       capsetp()  attempts  to set the capabilities of some other process(es),
66       pid.  If pid is positive it refers to a specific  process;   if  it  is
67       zero,  it  refers  to  the  current process; -1 refers to all processes
68       other than the current process and  process  '1'  (typically  init(8));
69       other negative values refer to the -pid process group.  In order to use
70       this function, the kernel must support it and the current process  must
71       have  CAP_SETPCAP raised in its Effective capability set. The capabili‐
72       ties set in the target process(es) are those contained in cap_d.   Ker‐
73       nels  that  support  filesystem  capabilities redefine the semantics of
74       CAP_SETPCAP and on such systems this function will always fail for  any
75       target  not  equal  to the current process.  capsetp() returns zero for
76       success, and -1 on failure.
77
78       Where supported by the kernel, the function capsetp()  should  be  used
79       with care.  It existed, primarily, to overcome an early lack of support
80       for capabilities in the filesystems supported by Linux.  Note that,  by
81       default, the only processes that have CAP_SETPCAP available to them are
82       processes  started  as  a  kernel  thread.   (Typically  this  includes
83       init(8),  kflushd and kswapd). You will need to recompile the kernel to
84       modify this default.
85

EXAMPLE

87       The code segment below raises the CAP_FOWNER and CAP_SETFCAP  effective
88       capabilities for the caller:
89
90           cap_t caps;
91           cap_value_t cap_list[2];
92
93           caps = cap_get_proc();
94           if (caps == NULL)
95               /* handle error */;
96
97           cap_list[0] = CAP_FOWNER;
98           cap_list[1] = CAP_SETFCAP;
99           if (cap_set_flag(caps, CAP_EFFECTIVE, 2, cap_list, CAP_SET) == -1)
100               /* handle error */;
101
102           if (cap_set_proc(caps) == -1)
103               /* handle error */;
104
105           if (cap_free(caps) == -1)
106               /* handle error */;
107

SEE ALSO

109       libcap(3),     cap_clear(3),     cap_copy_ext(3),     cap_from_text(3),
110       cap_get_file(3), cap_init(3), capabilities(7)
111
112
113
114                                  2008-05-11                   CAP_GET_PROC(3)
Impressum