1CAP_GET_FILE(3) Linux Programmer's Manual CAP_GET_FILE(3)
2
3
4
6 cap_get_file, cap_set_file, cap_get_fd, cap_set_fd - capability manipu‐
7 lation on files
8
10 #include <sys/capability.h>
11
12 cap_t cap_get_file(const char *path_p);
13
14 int cap_set_file(const char *path_p, cap_t cap_p);
15
16 cap_t cap_get_fd(int fd);
17
18 int cap_set_fd(int fd, cap_t caps);
19
20 Link with -lcap.
21
23 cap_get_file() and cap_get_fd() allocate a capability state in working
24 storage and set it to represent the capability state of the pathname
25 pointed to by path_p or the file open on descriptor fd. These func‐
26 tions return a pointer to the newly created capability state. The
27 effects of reading the capability state from any file other than a reg‐
28 ular file is undefined. The caller should free any releasable memory,
29 when the capability state in working storage is no longer required, by
30 calling cap_free() with the used cap_t as an argument.
31
32 cap_set_file() and cap_set_fd() set the values for all capability flags
33 for all capabilities for the pathname pointed to by path_p or the file
34 open on descriptor fd, with the capability state identified by cap_p.
35 The new capability state of the file is completely determined by the
36 contents of cap_p. A NULL value for cap_p is used to indicate that
37 capabilities for the file should be deleted. For these functions to
38 succeed, the calling process must have the effective capability,
39 CAP_SETFCAP, enabled and either the effective user ID of the process
40 must match the file owner or the calling process must have the
41 CAP_FOWNER flag in its effective capability set. The effects of writ‐
42 ing the capability state to any file type other than a regular file are
43 undefined.
44
46 cap_get_file() and cap_get_fd() return a non-NULL value on success, and
47 NULL on failure.
48
49 cap_set_file() and cap_set_fd() return zero on success, and -1 on fail‐
50 ure.
51
52 On failure, errno is set to EACCES, EBADFD, ENAMETOOLONG, ENOENT,
53 ENOMEM, ENOTDIR, EPERM, or EROFS.
54
56 These functions are specified by withdrawn POSIX.1e draft specifica‐
57 tion.
58
60 Support for file capabilities is provided on Linux since version
61 2.6.24.
62
63 On Linux, the file Effective set is a single bit. If it is enabled,
64 then all Permitted capabilities are enabled in the Effective set of the
65 calling process when the file is executed; otherwise, no capabilities
66 are enabled in the process's Effective set following an execve(2).
67 Because the file Effective set is a single bit, if any capability is
68 enabled in the Effective set of the cap_t given to cap_set_file() or
69 cap_set_fd(), then all capabilities whose Permitted or Inheritable flag
70 is enabled must also have the Effective flag enabled. Conversely, if
71 the Effective bit is enabled on a file, then the cap_t returned by
72 cap_get_file() and cap_get_fd() will have the Effective flag enabled
73 for each capability that has the Permitted or Inheritable flag enabled.
74
76 libcap(3), cap_clear(3), cap_copy_ext(3), cap_from_text(3),
77 cap_get_proc(3), cap_init(3), capabilities(7)
78
79
80
81 2008-05-11 CAP_GET_FILE(3)