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