blob: c188a3a82071c57d6b879fe7c9f406e736580f5f [file] [log] [blame]
Joshua Brindle13cd4c82008-08-19 15:30:36 -04001.TH "getexeccon" "3" "1 January 2004" "russell@coker.com.au" "SELinux API documentation"
2.SH "NAME"
Guillem Jover6ef13ee2012-11-13 21:15:34 +01003getexeccon, setexeccon \- get or set the SELinux security context used for executing a new process
Joshua Brindle13cd4c82008-08-19 15:30:36 -04004
5rpm_execcon \- run a helper for rpm in an appropriate security context
Guillem Jover6ef13ee2012-11-13 21:15:34 +01006.
Joshua Brindle13cd4c82008-08-19 15:30:36 -04007.SH "SYNOPSIS"
8.B #include <selinux/selinux.h>
9.sp
10.BI "int getexeccon(security_context_t *" context );
Guillem Jover6ef13ee2012-11-13 21:15:34 +010011.sp
Guillem Jover9acdd372012-11-10 04:32:07 +010012.BI "int getexeccon_raw(security_context_t *" context );
13.sp
Joshua Brindle13cd4c82008-08-19 15:30:36 -040014.BI "int setexeccon(security_context_t "context );
Guillem Jover6ef13ee2012-11-13 21:15:34 +010015.sp
Guillem Jover9acdd372012-11-10 04:32:07 +010016.BI "int setexeccon_raw(security_context_t "context );
17.sp
Joshua Brindle13cd4c82008-08-19 15:30:36 -040018.BI "int rpm_execcon(unsigned int " verified ", const char *" filename ", char *const " argv "[] , char *const " envp "[]);
Guillem Jover6ef13ee2012-11-13 21:15:34 +010019.
Joshua Brindle13cd4c82008-08-19 15:30:36 -040020.SH "DESCRIPTION"
Guillem Jover6ef13ee2012-11-13 21:15:34 +010021.BR getexeccon ()
Joshua Brindle13cd4c82008-08-19 15:30:36 -040022retrieves the context used for executing a new process.
Guillem Jover6ef13ee2012-11-13 21:15:34 +010023This returned context should be freed with
24.BR freecon (3)
25if non-NULL.
26.BR getexeccon ()
27sets
28.BI * context
29to NULL if no exec context has been explicitly
Joshua Brindle13cd4c82008-08-19 15:30:36 -040030set by the program (i.e. using the default policy behavior).
31
Guillem Jover6ef13ee2012-11-13 21:15:34 +010032.BR setexeccon ()
33sets the context used for the next
34.BR execve (2)
35call.
Joshua Brindle13cd4c82008-08-19 15:30:36 -040036NULL can be passed to
Guillem Jover6ef13ee2012-11-13 21:15:34 +010037.BR setexeccon ()
38to reset to the default policy behavior.
39The exec context is automatically reset after the next
40.BR execve (2),
41so a program doesn't need to explicitly sanitize it upon startup.
Joshua Brindle13cd4c82008-08-19 15:30:36 -040042
Guillem Jover6ef13ee2012-11-13 21:15:34 +010043.BR setexeccon ()
44can be applied prior to library
45functions that internally perform an
46.BR execve (2),
47e.g.
48.BR execl *(3),
49.BR execv *(3),
50.BR popen (3),
Joshua Brindle13cd4c82008-08-19 15:30:36 -040051in order to set an exec context for that operation.
52
Guillem Jover9acdd372012-11-10 04:32:07 +010053.BR getexeccon_raw ()
54and
55.BR setexeccon_raw ()
56behave identically to their non-raw counterparts but do not perform context
57translation.
58
Guillem Jover6ef13ee2012-11-13 21:15:34 +010059.B Note:
60Signal handlers that perform an
61.BR execve (2)
62must take care to
Joshua Brindle13cd4c82008-08-19 15:30:36 -040063save, reset, and restore the exec context to avoid unexpected behavior.
64
Guillem Jover6ef13ee2012-11-13 21:15:34 +010065.BR rpm_execcon ()
Joshua Brindle13cd4c82008-08-19 15:30:36 -040066runs a helper for rpm in an appropriate security context. The
67verified parameter should contain the return code from the signature
68verification (0 == ok, 1 == notfound, 2 == verifyfail, 3 ==
69nottrusted, 4 == nokey), although this information is not yet used by
70the function. The function determines the proper security context for
71the helper based on policy, sets the exec context accordingly, and
72then executes the specified filename with the provided argument and
73environment arrays.
Guillem Jover6ef13ee2012-11-13 21:15:34 +010074.
Joshua Brindle13cd4c82008-08-19 15:30:36 -040075.SH "RETURN VALUE"
Guillem Jover6ef13ee2012-11-13 21:15:34 +010076On error \-1 is returned.
Joshua Brindle13cd4c82008-08-19 15:30:36 -040077
Guillem Jover6ef13ee2012-11-13 21:15:34 +010078On success
79.BR getexeccon ()
80and
81.BR setexeccon ()
82returns 0.
83.BR rpm_execcon ()
84only returns upon errors, as it calls
85.BR execve (2).
86.
Joshua Brindle13cd4c82008-08-19 15:30:36 -040087.SH "SEE ALSO"
88.BR selinux "(8), " freecon "(3), " getcon "(3)"