| 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 |
| Guillem Jover | a273733 | 2012-11-20 16:27:55 +0100 | [diff] [blame^] | 18 | .BI "int setexecfilecon(const char *" filename ", const char *" fallback_type ); |
| 19 | .sp |
| Joshua Brindle | 13cd4c8 | 2008-08-19 15:30:36 -0400 | [diff] [blame] | 20 | .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] | 21 | . |
| Joshua Brindle | 13cd4c8 | 2008-08-19 15:30:36 -0400 | [diff] [blame] | 22 | .SH "DESCRIPTION" |
| Guillem Jover | 6ef13ee | 2012-11-13 21:15:34 +0100 | [diff] [blame] | 23 | .BR getexeccon () |
| Joshua Brindle | 13cd4c8 | 2008-08-19 15:30:36 -0400 | [diff] [blame] | 24 | retrieves the context used for executing a new process. |
| Guillem Jover | 6ef13ee | 2012-11-13 21:15:34 +0100 | [diff] [blame] | 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 |
| Joshua Brindle | 13cd4c8 | 2008-08-19 15:30:36 -0400 | [diff] [blame] | 32 | set by the program (i.e. using the default policy behavior). |
| 33 | |
| Guillem Jover | 6ef13ee | 2012-11-13 21:15:34 +0100 | [diff] [blame] | 34 | .BR setexeccon () |
| 35 | sets the context used for the next |
| 36 | .BR execve (2) |
| 37 | call. |
| Joshua Brindle | 13cd4c8 | 2008-08-19 15:30:36 -0400 | [diff] [blame] | 38 | NULL can be passed to |
| Guillem Jover | 6ef13ee | 2012-11-13 21:15:34 +0100 | [diff] [blame] | 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. |
| Joshua Brindle | 13cd4c8 | 2008-08-19 15:30:36 -0400 | [diff] [blame] | 44 | |
| Guillem Jover | 6ef13ee | 2012-11-13 21:15:34 +0100 | [diff] [blame] | 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), |
| Joshua Brindle | 13cd4c8 | 2008-08-19 15:30:36 -0400 | [diff] [blame] | 53 | in order to set an exec context for that operation. |
| 54 | |
| Guillem Jover | 9acdd37 | 2012-11-10 04:32:07 +0100 | [diff] [blame] | 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 | |
| Guillem Jover | 6ef13ee | 2012-11-13 21:15:34 +0100 | [diff] [blame] | 61 | .B Note: |
| 62 | Signal handlers that perform an |
| 63 | .BR execve (2) |
| 64 | must take care to |
| Joshua Brindle | 13cd4c8 | 2008-08-19 15:30:36 -0400 | [diff] [blame] | 65 | save, reset, and restore the exec context to avoid unexpected behavior. |
| 66 | |
| Guillem Jover | a273733 | 2012-11-20 16:27:55 +0100 | [diff] [blame^] | 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 | |
| Guillem Jover | 6ef13ee | 2012-11-13 21:15:34 +0100 | [diff] [blame] | 76 | .BR rpm_execcon () |
| Guillem Jover | a273733 | 2012-11-20 16:27:55 +0100 | [diff] [blame^] | 77 | is deprecated; please use |
| 78 | .BR setexecfilecon () |
| 79 | in conjunction with |
| 80 | .BR execve (2) |
| 81 | in all new code. This function |
| Joshua Brindle | 13cd4c8 | 2008-08-19 15:30:36 -0400 | [diff] [blame] | 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. |
| Guillem Jover | 6ef13ee | 2012-11-13 21:15:34 +0100 | [diff] [blame] | 90 | . |
| Joshua Brindle | 13cd4c8 | 2008-08-19 15:30:36 -0400 | [diff] [blame] | 91 | .SH "RETURN VALUE" |
| Guillem Jover | 6ef13ee | 2012-11-13 21:15:34 +0100 | [diff] [blame] | 92 | On error \-1 is returned. |
| Joshua Brindle | 13cd4c8 | 2008-08-19 15:30:36 -0400 | [diff] [blame] | 93 | |
| Guillem Jover | 6ef13ee | 2012-11-13 21:15:34 +0100 | [diff] [blame] | 94 | On success |
| Guillem Jover | a273733 | 2012-11-20 16:27:55 +0100 | [diff] [blame^] | 95 | .BR getexeccon (), |
| Guillem Jover | 6ef13ee | 2012-11-13 21:15:34 +0100 | [diff] [blame] | 96 | .BR setexeccon () |
| Guillem Jover | a273733 | 2012-11-20 16:27:55 +0100 | [diff] [blame^] | 97 | and |
| 98 | .BR setexecfilecon () |
| 99 | return 0. |
| Guillem Jover | 6ef13ee | 2012-11-13 21:15:34 +0100 | [diff] [blame] | 100 | .BR rpm_execcon () |
| 101 | only returns upon errors, as it calls |
| 102 | .BR execve (2). |
| 103 | . |
| Joshua Brindle | 13cd4c8 | 2008-08-19 15:30:36 -0400 | [diff] [blame] | 104 | .SH "SEE ALSO" |
| 105 | .BR selinux "(8), " freecon "(3), " getcon "(3)" |