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