1getfilecon(3) SELinux API documentation getfilecon(3)
2
3
4
6 getfilecon, fgetfilecon, lgetfilecon - get SELinux security context of
7 a file
8
10 #include <selinux/selinux.h>
11
12 int getfilecon(const char *path, char **con);
13
14 int getfilecon_raw(const char *path, char **con);
15
16 int lgetfilecon(const char *path, char **con);
17
18 int lgetfilecon_raw(const char *path, char **con);
19
20 int fgetfilecon(int fd, char **con);
21
22 int fgetfilecon_raw(int fd, char **con);
23
25 getfilecon() retrieves the context associated with the given path in
26 the file system, the length of the context is returned.
27
28 lgetfilecon() is identical to getfilecon(), except in the case of a
29 symbolic link, where the link itself is interrogated, not the file that
30 it refers to.
31
32 fgetfilecon() is identical to getfilecon(), only the open file pointed
33 to by filedes (as returned by open(2)) is interrogated in place of
34 path. Since libselinux 3.4 a file opened via O_PATH is supported.
35
36 getfilecon_raw(), lgetfilecon_raw() and fgetfilecon_raw() behave iden‐
37 tically to their non-raw counterparts but do not perform context trans‐
38 lation.
39
40 The returned context should be freed with freecon(3) if non-NULL.
41
43 On success, a positive number is returned indicating the size of the
44 extended attribute value. On failure, -1 is returned and errno is set
45 appropriately.
46
47 If the context does not exist, or the process has no access to this at‐
48 tribute, errno is set to ENODATA.
49
50 If extended attributes are not supported by the filesystem, or are dis‐
51 abled, errno is set to ENOTSUP.
52
53 The errors documented for the stat(2) system call are also applicable
54 here.
55
57 selinux(8), freecon(3), setfilecon(3), setfscreatecon(3)
58
59
60
61russell@coker.com.au 1 January 2004 getfilecon(3)