Debian Codegraph @

libselinux/man/man3/getcon.3

raw
1 .TH "getcon" "3" "21 December 2011" "[email protected]" "SELinux API documentation"
2 .SH "NAME"
3 getcon, getprevcon, getpidcon \- get SELinux security context of a process
4
5 freecon, freeconary \- free memory associated with SELinux security contexts
6
7 getpeercon \- get security context of a peer socket
8
9 setcon \- set current security context of a process
10 .
11 .SH "SYNOPSIS"
12 .B #include <selinux/selinux.h>
13 .sp
14 .BI "int getcon(char **" context );
15 .sp
16 .BI "int getcon_raw(char **" context );
17 .sp
18 .BI "int getprevcon(char **" context );
19 .sp
20 .BI "int getprevcon_raw(char **" context );
21 .sp
22 .BI "int getpidcon(pid_t " pid ", char **" context );
23 .sp
24 .BI "int getpidcon_raw(pid_t " pid ", char **" context );
25 .sp
26 .BI "int getpeercon(int " fd ", char **" context );
27 .sp
28 .BI "int getpeercon_raw(int " fd ", char **" context );
29 .sp
30 .BI "void freecon(char *" con );
31 .sp
32 .BI "void freeconary(char **" con );
33 .sp
34 .BI "int setcon(char *" context );
35 .sp
36 .BI "int setcon_raw(char *" context );
37 .
38 .SH "DESCRIPTION"
39 .BR getcon ()
40 retrieves the context of the current process, which must be free'd with
41 freecon.
42
43 .BR getprevcon ()
44 same as getcon but gets the context before the last exec.
45
46 .BR getpidcon ()
47 returns the process context for the specified PID.
48
49 .BR getpeercon ()
50 retrieves context of peer socket, and set
51 .BI * context
52 to refer to it, which must be free'd with
53 .BR freecon ().
54
55 .BR freecon ()
56 frees the memory allocated for a security context.
57
58 .BR freeconary ()
59 frees the memory allocated for a context array.
60
61 If
62 .I con
63 is NULL, no operation is performed.
64
65 .BR setcon ()
66 sets the current security context of the process to a new value. Note
67 that use of this function requires that the entire application be
68 trusted to maintain any desired separation between the old and new
69 security contexts, unlike exec-based transitions performed via
70 .BR setexeccon (3).
71 When possible, decompose your application and use
72 .BR setexeccon (3)
73 and
74 .BR execve (3)
75 instead.
76
77 Since access to file descriptors is revalidated upon use by SELinux,
78 the new context must be explicitly authorized in the policy to use the
79 descriptors opened by the old context if that is desired. Otherwise,
80 attempts by the process to use any existing descriptors (including
81 .IR stdin ,
82 .IR stdout ,
83 and
84 .IR stderr )
85 after performing the
86 .BR setcon ()
87 will fail.
88
89 A multi-threaded application can perform a
90 .BR setcon ()
91 prior to creating
92 any child threads, in which case all of the child threads will inherit
93 the new context. However, prior to Linux 2.6.28,
94 .BR setcon ()
95 would fail if there are any other
96 threads running in the same process since this would yield
97 an inconsistency among the security contexts of threads sharing
98 the same memory space. Since Linux 2.6.28,
99 .BR setcon()
100 is permitted for threads within a multi-threaded process if the
101 new security context is bounded by the old security context, where
102 the bounded relation is defined through typebounds statements in the
103 policy and guarantees that the new security context has a subset of
104 the permissions of the old security context.
105
106 If the process was being ptraced at the time of the
107 .BR setcon ()
108 operation, ptrace permission will be revalidated against the new
109 context and the
110 .BR setcon ()
111 will fail if it is not allowed by policy.
112
113 .BR getcon_raw (),
114 .BR getprevcon_raw (),
115 .BR getpidcon_raw (),
116 .BR getpeercon_raw ()
117 and
118 .BR setcon_raw ()
119 behave identically to their non-raw counterparts but do not perform context
120 translation.
121 .
122 .SH "RETURN VALUE"
123 On error \-1 is returned. On success 0 is returned.
124 .
125 .SH "SEE ALSO"
126 .BR selinux "(8), " setexeccon "(3)"