| 1 |
.TH "getexeccon" "3" "1 January 2004" "[email protected]" "SELinux API documentation" |
| 2 |
.SH "NAME" |
| 3 |
getexeccon, setexeccon \- get or set the SELinux security context used for executing a new process |
| 4 |
|
| 5 |
rpm_execcon \- run a helper for rpm in an appropriate security context |
| 6 |
. |
| 7 |
.SH "SYNOPSIS" |
| 8 |
.B #include <selinux/selinux.h> |
| 9 |
.sp |
| 10 |
.BI "int getexeccon(char **" context ); |
| 11 |
.sp |
| 12 |
.BI "int getexeccon_raw(char **" context ); |
| 13 |
.sp |
| 14 |
.BI "int setexeccon(char *" context ); |
| 15 |
.sp |
| 16 |
.BI "int setexeccon_raw(char *" context ); |
| 17 |
.sp |
| 18 |
.BI "int setexecfilecon(const char *" filename ", const char *" fallback_type ); |
| 19 |
.sp |
| 20 |
.BI "int rpm_execcon(unsigned int " verified ", const char *" filename ", char *const " argv "[] , char *const " envp "[]); |
| 21 |
. |
| 22 |
.SH "DESCRIPTION" |
| 23 |
.BR getexeccon () |
| 24 |
retrieves the context used for executing a new process. |
| 25 |
This returned context should be freed with |
| 26 |
.BR freecon (3) |
| 27 |
if non-NULL. |
| 28 |
.BR getexeccon () |
| 29 |
sets |
| 30 |
.BI * context |
| 31 |
to NULL if no exec context has been explicitly |
| 32 |
set by the program (i.e. using the default policy behavior). |
| 33 |
|
| 34 |
.BR setexeccon () |
| 35 |
sets the context used for the next |
| 36 |
.BR execve (2) |
| 37 |
call. |
| 38 |
NULL can be passed to |
| 39 |
.BR setexeccon () |
| 40 |
to reset to the default policy behavior. |
| 41 |
The exec context is automatically reset after the next |
| 42 |
.BR execve (2), |
| 43 |
so a program doesn't need to explicitly sanitize it upon startup. |
| 44 |
|
| 45 |
.BR setexeccon () |
| 46 |
can be applied prior to library |
| 47 |
functions that internally perform an |
| 48 |
.BR execve (2), |
| 49 |
e.g. |
| 50 |
.BR execl *(3), |
| 51 |
.BR execv *(3), |
| 52 |
.BR popen (3), |
| 53 |
in order to set an exec context for that operation. |
| 54 |
|
| 55 |
.BR getexeccon_raw () |
| 56 |
and |
| 57 |
.BR setexeccon_raw () |
| 58 |
behave identically to their non-raw counterparts but do not perform context |
| 59 |
translation. |
| 60 |
|
| 61 |
.B Note: |
| 62 |
Signal handlers that perform an |
| 63 |
.BR execve (2) |
| 64 |
must take care to |
| 65 |
save, reset, and restore the exec context to avoid unexpected behavior. |
| 66 |
|
| 67 |
.BR setexecfilecon () |
| 68 |
sets the context used for the next |
| 69 |
.BR execve (2) |
| 70 |
call, based on the policy for the |
| 71 |
.IR filename , |
| 72 |
and falling back to a new context with a |
| 73 |
.I fallback_type |
| 74 |
in case there is no transition. |
| 75 |
|
| 76 |
.BR rpm_execcon () |
| 77 |
is deprecated; please use |
| 78 |
.BR setexecfilecon () |
| 79 |
in conjunction with |
| 80 |
.BR execve (2) |
| 81 |
in all new code. This function |
| 82 |
runs a helper for rpm in an appropriate security context. The |
| 83 |
verified parameter should contain the return code from the signature |
| 84 |
verification (0 == ok, 1 == notfound, 2 == verifyfail, 3 == |
| 85 |
nottrusted, 4 == nokey), although this information is not yet used by |
| 86 |
the function. The function determines the proper security context for |
| 87 |
the helper based on policy, sets the exec context accordingly, and |
| 88 |
then executes the specified filename with the provided argument and |
| 89 |
environment arrays. |
| 90 |
. |
| 91 |
.SH "RETURN VALUE" |
| 92 |
On error \-1 is returned. |
| 93 |
|
| 94 |
On success |
| 95 |
.BR getexeccon (), |
| 96 |
.BR setexeccon () |
| 97 |
and |
| 98 |
.BR setexecfilecon () |
| 99 |
return 0. |
| 100 |
.BR rpm_execcon () |
| 101 |
only returns upon errors, as it calls |
| 102 |
.BR execve (2). |
| 103 |
. |
| 104 |
.SH "SEE ALSO" |
| 105 |
.BR selinux "(8), " freecon "(3), " getcon "(3)" |