• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _SELINUX_H_
2 #define _SELINUX_H_
3 
4 #include <sys/types.h>
5 #include <stdarg.h>
6 
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10 
11 /* Return 1 if we are running on a SELinux kernel, or 0 if not or -1 if we get an error. */
12 extern int is_selinux_enabled(void);
13 /* Return 1 if we are running on a SELinux MLS kernel, or 0 otherwise. */
14 extern int is_selinux_mls_enabled(void);
15 
16 /* No longer used; here for compatibility with legacy callers. */
17 typedef char *security_context_t;
18 
19 /* Free the memory allocated for a context by any of the below get* calls. */
20 extern void freecon(char * con);
21 
22 /* Free the memory allocated for a context array by security_compute_user. */
23 extern void freeconary(char ** con);
24 
25 /* Wrappers for the /proc/pid/attr API. */
26 
27 /* Get current context, and set *con to refer to it.
28    Caller must free via freecon. */
29 extern int getcon(char ** con);
30 extern int getcon_raw(char ** con);
31 
32 /* Set the current security context to con.
33    Note that use of this function requires that the entire application
34    be trusted to maintain any desired separation between the old and new
35    security contexts, unlike exec-based transitions performed via setexeccon.
36    When possible, decompose your application and use setexeccon()+execve()
37    instead. Note that the application may lose access to its open descriptors
38    as a result of a setcon() unless policy allows it to use descriptors opened
39    by the old context. */
40 extern int setcon(const char * con);
41 extern int setcon_raw(const char * con);
42 
43 /* Get context of process identified by pid, and
44    set *con to refer to it.  Caller must free via freecon. */
45 extern int getpidcon(pid_t pid, char ** con);
46 extern int getpidcon_raw(pid_t pid, char ** con);
47 
48 /* Get previous context (prior to last exec), and set *con to refer to it.
49    Caller must free via freecon. */
50 extern int getprevcon(char ** con);
51 extern int getprevcon_raw(char ** con);
52 
53 /* Get exec context, and set *con to refer to it.
54    Sets *con to NULL if no exec context has been set, i.e. using default.
55    If non-NULL, caller must free via freecon. */
56 extern int getexeccon(char ** con);
57 extern int getexeccon_raw(char ** con);
58 
59 /* Set exec security context for the next execve.
60    Call with NULL if you want to reset to the default. */
61 extern int setexeccon(const char * con);
62 extern int setexeccon_raw(const char * con);
63 
64 /* Get fscreate context, and set *con to refer to it.
65    Sets *con to NULL if no fs create context has been set, i.e. using default.
66    If non-NULL, caller must free via freecon. */
67 extern int getfscreatecon(char ** con);
68 extern int getfscreatecon_raw(char ** con);
69 
70 /* Set the fscreate security context for subsequent file creations.
71    Call with NULL if you want to reset to the default. */
72 extern int setfscreatecon(const char * context);
73 extern int setfscreatecon_raw(const char * context);
74 
75 /* Get keycreate context, and set *con to refer to it.
76    Sets *con to NULL if no key create context has been set, i.e. using default.
77    If non-NULL, caller must free via freecon. */
78 extern int getkeycreatecon(char ** con);
79 extern int getkeycreatecon_raw(char ** con);
80 
81 /* Set the keycreate security context for subsequent key creations.
82    Call with NULL if you want to reset to the default. */
83 extern int setkeycreatecon(const char * context);
84 extern int setkeycreatecon_raw(const char * context);
85 
86 /* Get sockcreate context, and set *con to refer to it.
87    Sets *con to NULL if no socket create context has been set, i.e. using default.
88    If non-NULL, caller must free via freecon. */
89 extern int getsockcreatecon(char ** con);
90 extern int getsockcreatecon_raw(char ** con);
91 
92 /* Set the sockcreate security context for subsequent socket creations.
93    Call with NULL if you want to reset to the default. */
94 extern int setsockcreatecon(const char * context);
95 extern int setsockcreatecon_raw(const char * context);
96 
97 /* Wrappers for the xattr API. */
98 
99 /* Get file context, and set *con to refer to it.
100    Caller must free via freecon. */
101 extern int getfilecon(const char *path, char ** con);
102 extern int getfilecon_raw(const char *path, char ** con);
103 extern int lgetfilecon(const char *path, char ** con);
104 extern int lgetfilecon_raw(const char *path, char ** con);
105 extern int fgetfilecon(int fd, char ** con);
106 extern int fgetfilecon_raw(int fd, char ** con);
107 
108 /* Set file context */
109 extern int setfilecon(const char *path, const char * con);
110 extern int setfilecon_raw(const char *path, const char * con);
111 extern int lsetfilecon(const char *path, const char * con);
112 extern int lsetfilecon_raw(const char *path, const char * con);
113 extern int fsetfilecon(int fd, const char * con);
114 extern int fsetfilecon_raw(int fd, const char * con);
115 
116 /* Wrappers for the socket API */
117 
118 /* Get context of peer socket, and set *con to refer to it.
119    Caller must free via freecon. */
120 extern int getpeercon(int fd, char ** con);
121 extern int getpeercon_raw(int fd, char ** con);
122 
123 /* Wrappers for the selinuxfs (policy) API. */
124 
125 typedef unsigned int access_vector_t;
126 typedef unsigned short security_class_t;
127 
128 struct av_decision {
129 	access_vector_t allowed;
130 	access_vector_t decided;
131 	access_vector_t auditallow;
132 	access_vector_t auditdeny;
133 	unsigned int seqno;
134 	unsigned int flags;
135 };
136 
137 /* Definitions of av_decision.flags */
138 #define SELINUX_AVD_FLAGS_PERMISSIVE	0x0001
139 
140 /* Structure for passing options, used by AVC and label subsystems */
141 struct selinux_opt {
142 	int type;
143 	const char *value;
144 };
145 
146 /* Callback facilities */
147 union selinux_callback {
148 	/* log the printf-style format and arguments,
149 	   with the type code indicating the type of message */
150 	int
151 #ifdef __GNUC__
152 __attribute__ ((format(printf, 2, 3)))
153 #endif
154 	(*func_log) (int type, const char *fmt, ...);
155 	/* store a string representation of auditdata (corresponding
156 	   to the given security class) into msgbuf. */
157 	int (*func_audit) (void *auditdata, security_class_t cls,
158 			   char *msgbuf, size_t msgbufsize);
159 	/* validate the supplied context, modifying if necessary */
160 	int (*func_validate) (char **ctx);
161 	/* netlink callback for setenforce message */
162 	int (*func_setenforce) (int enforcing);
163 	/* netlink callback for policyload message */
164 	int (*func_policyload) (int seqno);
165 };
166 
167 #define SELINUX_CB_LOG		0
168 #define SELINUX_CB_AUDIT	1
169 #define SELINUX_CB_VALIDATE	2
170 #define SELINUX_CB_SETENFORCE	3
171 #define SELINUX_CB_POLICYLOAD	4
172 
173 extern union selinux_callback selinux_get_callback(int type);
174 extern void selinux_set_callback(int type, union selinux_callback cb);
175 
176 	/* Logging type codes, passed to the logging callback */
177 #define SELINUX_ERROR	        0
178 #define SELINUX_WARNING		1
179 #define SELINUX_INFO		2
180 #define SELINUX_AVC		3
181 #define SELINUX_TRANS_DIR	"/var/run/setrans"
182 
183 /* Compute an access decision. */
184 extern int security_compute_av(const char * scon,
185 			       const char * tcon,
186 			       security_class_t tclass,
187 			       access_vector_t requested,
188 			       struct av_decision *avd);
189 extern int security_compute_av_raw(const char * scon,
190 				   const char * tcon,
191 				   security_class_t tclass,
192 				   access_vector_t requested,
193 				   struct av_decision *avd);
194 
195 extern int security_compute_av_flags(const char * scon,
196 				     const char * tcon,
197 				     security_class_t tclass,
198 				     access_vector_t requested,
199 				     struct av_decision *avd);
200 extern int security_compute_av_flags_raw(const char * scon,
201 					 const char * tcon,
202 					 security_class_t tclass,
203 					 access_vector_t requested,
204 					 struct av_decision *avd);
205 
206 /* Compute a labeling decision and set *newcon to refer to it.
207    Caller must free via freecon. */
208 extern int security_compute_create(const char * scon,
209 				   const char * tcon,
210 				   security_class_t tclass,
211 				   char ** newcon);
212 extern int security_compute_create_raw(const char * scon,
213 				       const char * tcon,
214 				       security_class_t tclass,
215 				       char ** newcon);
216 extern int security_compute_create_name(const char * scon,
217 					const char * tcon,
218 					security_class_t tclass,
219 					const char *objname,
220 					char ** newcon);
221 extern int security_compute_create_name_raw(const char * scon,
222 					    const char * tcon,
223 					    security_class_t tclass,
224 					    const char *objname,
225 					    char ** newcon);
226 
227 /* Compute a relabeling decision and set *newcon to refer to it.
228    Caller must free via freecon. */
229 extern int security_compute_relabel(const char * scon,
230 				    const char * tcon,
231 				    security_class_t tclass,
232 				    char ** newcon);
233 extern int security_compute_relabel_raw(const char * scon,
234 					const char * tcon,
235 					security_class_t tclass,
236 					char ** newcon);
237 
238 /* Compute a polyinstantiation member decision and set *newcon to refer to it.
239    Caller must free via freecon. */
240 extern int security_compute_member(const char * scon,
241 				   const char * tcon,
242 				   security_class_t tclass,
243 				   char ** newcon);
244 extern int security_compute_member_raw(const char * scon,
245 				       const char * tcon,
246 				       security_class_t tclass,
247 				       char ** newcon);
248 
249 /* Compute the set of reachable user contexts and set *con to refer to
250    the NULL-terminated array of contexts.  Caller must free via freeconary. */
251 extern int security_compute_user(const char * scon,
252 				 const char *username,
253 				 char *** con);
254 extern int security_compute_user_raw(const char * scon,
255 				     const char *username,
256 				     char *** con);
257 
258 /* Load a policy configuration. */
259 extern int security_load_policy(void *data, size_t len);
260 
261 /* Get the context of an initial kernel security identifier by name.
262    Caller must free via freecon */
263 extern int security_get_initial_context(const char *name,
264 					char ** con);
265 extern int security_get_initial_context_raw(const char *name,
266 					    char ** con);
267 
268 /*
269  * Make a policy image and load it.
270  * This function provides a higher level interface for loading policy
271  * than security_load_policy, internally determining the right policy
272  * version, locating and opening the policy file, mapping it into memory,
273  * manipulating it as needed for current boolean settings and/or local
274  * definitions, and then calling security_load_policy to load it.
275  *
276  * 'preservebools' is a boolean flag indicating whether current
277  * policy boolean values should be preserved into the new policy (if 1)
278  * or reset to the saved policy settings (if 0).  The former case is the
279  * default for policy reloads, while the latter case is an option for policy
280  * reloads but is primarily for the initial policy load.
281  */
282 extern int selinux_mkload_policy(int preservebools);
283 
284 /*
285  * Perform the initial policy load.
286  * This function determines the desired enforcing mode, sets the
287  * the *enforce argument accordingly for the caller to use, sets the
288  * SELinux kernel enforcing status to match it, and loads the policy.
289  * It also internally handles the initial selinuxfs mount required to
290  * perform these actions.
291  *
292  * The function returns 0 if everything including the policy load succeeds.
293  * In this case, init is expected to re-exec itself in order to transition
294  * to the proper security context.
295  * Otherwise, the function returns -1, and init must check *enforce to
296  * determine how to proceed.  If enforcing (*enforce > 0), then init should
297  * halt the system.  Otherwise, init may proceed normally without a re-exec.
298  */
299 extern int selinux_init_load_policy(int *enforce);
300 
301 /* Translate boolean strict to name value pair. */
302 typedef struct {
303 	char *name;
304 	int value;
305 } SELboolean;
306 /* save a list of booleans in a single transaction.  */
307 extern int security_set_boolean_list(size_t boolcnt,
308 				     SELboolean * boollist, int permanent);
309 
310 /* Load policy boolean settings.
311    Path may be NULL, in which case the booleans are loaded from
312    the active policy boolean configuration file. */
313 extern int security_load_booleans(char *path);
314 
315 /* Check the validity of a security context. */
316 extern int security_check_context(const char * con);
317 extern int security_check_context_raw(const char * con);
318 
319 /* Canonicalize a security context. */
320 extern int security_canonicalize_context(const char * con,
321 					 char ** canoncon);
322 extern int security_canonicalize_context_raw(const char * con,
323 					     char ** canoncon);
324 
325 /* Get the enforce flag value. */
326 extern int security_getenforce(void);
327 
328 /* Set the enforce flag value. */
329 extern int security_setenforce(int value);
330 
331 /* Get the behavior for undefined classes/permissions */
332 extern int security_deny_unknown(void);
333 
334 /* Get the checkreqprot value */
335 extern int security_get_checkreqprot(void);
336 
337 /* Disable SELinux at runtime (must be done prior to initial policy load). */
338 extern int security_disable(void);
339 
340 /* Get the policy version number. */
341 extern int security_policyvers(void);
342 
343 /* Get the boolean names */
344 extern int security_get_boolean_names(char ***names, int *len);
345 
346 /* Get the pending value for the boolean */
347 extern int security_get_boolean_pending(const char *name);
348 
349 /* Get the active value for the boolean */
350 extern int security_get_boolean_active(const char *name);
351 
352 /* Set the pending value for the boolean */
353 extern int security_set_boolean(const char *name, int value);
354 
355 /* Commit the pending values for the booleans */
356 extern int security_commit_booleans(void);
357 
358 /* Userspace class mapping support */
359 struct security_class_mapping {
360 	const char *name;
361 	const char *perms[sizeof(access_vector_t) * 8 + 1];
362 };
363 
364 /**
365  * selinux_set_mapping - Enable dynamic mapping between integer offsets and security class names
366  * @map: array of security_class_mapping structures
367  *
368  * The core avc_has_perm() API uses integers to represent security
369  * classes; previous to the introduction of this function, it was
370  * common for userspace object managers to be compiled using generated
371  * offsets for a particular policy.  However, that strongly ties the build of the userspace components to a particular policy.
372  *
373  * By using this function to map between integer offsets and security
374  * class names, it's possible to replace a system policies that have
375  * at least the same set of security class names as used by the
376  * userspace object managers.
377  *
378  * To correctly use this function, you should override the generated
379  * security class defines from the system policy in a local header,
380  * starting at 1, and have one security_class_mapping structure entry
381  * per define.
382  */
383 extern int selinux_set_mapping(struct security_class_mapping *map);
384 
385 /* Common helpers */
386 
387 /* Convert between mode and security class values */
388 extern security_class_t mode_to_security_class(mode_t mode);
389 /* Convert between security class values and string names */
390 extern security_class_t string_to_security_class(const char *name);
391 extern const char *security_class_to_string(security_class_t cls);
392 
393 /* Convert between individual access vector permissions and string names */
394 extern const char *security_av_perm_to_string(security_class_t tclass,
395 					      access_vector_t perm);
396 extern access_vector_t string_to_av_perm(security_class_t tclass,
397 					 const char *name);
398 
399 /* Returns an access vector in a string representation.  User must free the
400  * returned string via free(). */
401 extern int security_av_string(security_class_t tclass,
402 			      access_vector_t av, char **result);
403 
404 /* Display an access vector in a string representation. */
405 extern void print_access_vector(security_class_t tclass, access_vector_t av);
406 
407 /* Set the function used by matchpathcon_init when displaying
408    errors about the file_contexts configuration.  If not set,
409    then this defaults to fprintf(stderr, fmt, ...). */
410 extern void set_matchpathcon_printf(void (*f) (const char *fmt, ...));
411 
412 /* Set the function used by matchpathcon_init when checking the
413    validity of a context in the file contexts configuration.  If not set,
414    then this defaults to a test based on security_check_context().
415    The function is also responsible for reporting any such error, and
416    may include the 'path' and 'lineno' in such error messages. */
417 extern void set_matchpathcon_invalidcon(int (*f) (const char *path,
418 						  unsigned lineno,
419 						  char *context));
420 
421 /* Same as above, but also allows canonicalization of the context,
422    by changing *context to refer to the canonical form.  If not set,
423    and invalidcon is also not set, then this defaults to calling
424    security_canonicalize_context(). */
425 extern void set_matchpathcon_canoncon(int (*f) (const char *path,
426 						unsigned lineno,
427 						char **context));
428 
429 /* Set flags controlling operation of matchpathcon_init or matchpathcon. */
430 #define MATCHPATHCON_BASEONLY 1	/* Only process the base file_contexts file. */
431 #define MATCHPATHCON_NOTRANS  2	/* Do not perform any context translation. */
432 #define MATCHPATHCON_VALIDATE 4	/* Validate/canonicalize contexts at init time. */
433 extern void set_matchpathcon_flags(unsigned int flags);
434 
435 /* Load the file contexts configuration specified by 'path'
436    into memory for use by subsequent matchpathcon calls.
437    If 'path' is NULL, then load the active file contexts configuration,
438    i.e. the path returned by selinux_file_context_path().
439    Unless the MATCHPATHCON_BASEONLY flag has been set, this
440    function also checks for a 'path'.homedirs file and
441    a 'path'.local file and loads additional specifications
442    from them if present. */
443 extern int matchpathcon_init(const char *path);
444 
445 /* Same as matchpathcon_init, but only load entries with
446    regexes that have stems that are prefixes of 'prefix'. */
447 extern int matchpathcon_init_prefix(const char *path, const char *prefix);
448 
449 /* Free the memory allocated by matchpathcon_init. */
450 extern void matchpathcon_fini(void);
451 
452 /* Resolve all of the symlinks and relative portions of a pathname, but NOT
453  * the final component (same a realpath() unless the final component is a
454  * symlink.  Resolved path must be a path of size PATH_MAX + 1 */
455 extern int realpath_not_final(const char *name, char *resolved_path);
456 
457 /* Match the specified pathname and mode against the file contexts
458    configuration and set *con to refer to the resulting context.
459    'mode' can be 0 to disable mode matching.
460    Caller must free via freecon.
461    If matchpathcon_init has not already been called, then this function
462    will call it upon its first invocation with a NULL path. */
463 extern int matchpathcon(const char *path,
464 			mode_t mode, char ** con);
465 
466 /* Same as above, but return a specification index for
467    later use in a matchpathcon_filespec_add() call - see below. */
468 extern int matchpathcon_index(const char *path,
469 			      mode_t mode, char ** con);
470 
471 /* Maintain an association between an inode and a specification index,
472    and check whether a conflicting specification is already associated
473    with the same inode (e.g. due to multiple hard links).  If so, then
474    use the latter of the two specifications based on their order in the
475    file contexts configuration.  Return the used specification index. */
476 extern int matchpathcon_filespec_add(ino_t ino, int specind, const char *file);
477 
478 /* Destroy any inode associations that have been added, e.g. to restart
479    for a new filesystem. */
480 extern void matchpathcon_filespec_destroy(void);
481 
482 /* Display statistics on the hash table usage for the associations. */
483 extern void matchpathcon_filespec_eval(void);
484 
485 /* Check to see whether any specifications had no matches and report them.
486    The 'str' is used as a prefix for any warning messages. */
487 extern void matchpathcon_checkmatches(char *str);
488 
489 /* Match the specified media and against the media contexts
490    configuration and set *con to refer to the resulting context.
491    Caller must free con via freecon. */
492 extern int matchmediacon(const char *media, char ** con);
493 
494 /*
495   selinux_getenforcemode reads the /etc/selinux/config file and determines
496   whether the machine should be started in enforcing (1), permissive (0) or
497   disabled (-1) mode.
498  */
499 extern int selinux_getenforcemode(int *enforce);
500 
501 /*
502   selinux_boolean_sub reads the /etc/selinux/TYPE/booleans.subs_dist file
503   looking for a record with boolean_name.  If a record exists selinux_boolean_sub
504   returns the translated name otherwise it returns the original name.
505   The returned value needs to be freed. On failure NULL will be returned.
506  */
507 extern char *selinux_boolean_sub(const char *boolean_name);
508 
509 /*
510   selinux_getpolicytype reads the /etc/selinux/config file and determines
511   what the default policy for the machine is.  Calling application must
512   free policytype.
513  */
514 extern int selinux_getpolicytype(char **policytype);
515 
516 /*
517   selinux_policy_root reads the /etc/selinux/config file and returns
518   the directory path under which the compiled policy file and context
519   configuration files exist.
520  */
521 extern const char *selinux_policy_root(void);
522 
523 /*
524   selinux_set_policy_root sets an alternate policy root directory path under
525   which the compiled policy file and context configuration files exist.
526  */
527 extern int selinux_set_policy_root(const char *rootpath);
528 
529 /* These functions return the paths to specific files under the
530    policy root directory. */
531 extern const char *selinux_current_policy_path(void);
532 extern const char *selinux_binary_policy_path(void);
533 extern const char *selinux_failsafe_context_path(void);
534 extern const char *selinux_removable_context_path(void);
535 extern const char *selinux_default_context_path(void);
536 extern const char *selinux_user_contexts_path(void);
537 extern const char *selinux_file_context_path(void);
538 extern const char *selinux_file_context_homedir_path(void);
539 extern const char *selinux_file_context_local_path(void);
540 extern const char *selinux_file_context_subs_path(void);
541 extern const char *selinux_file_context_subs_dist_path(void);
542 extern const char *selinux_homedir_context_path(void);
543 extern const char *selinux_media_context_path(void);
544 extern const char *selinux_virtual_domain_context_path(void);
545 extern const char *selinux_virtual_image_context_path(void);
546 extern const char *selinux_lxc_contexts_path(void);
547 extern const char *selinux_x_context_path(void);
548 extern const char *selinux_sepgsql_context_path(void);
549 extern const char *selinux_openrc_contexts_path(void);
550 extern const char *selinux_openssh_contexts_path(void);
551 extern const char *selinux_snapperd_contexts_path(void);
552 extern const char *selinux_systemd_contexts_path(void);
553 extern const char *selinux_contexts_path(void);
554 extern const char *selinux_securetty_types_path(void);
555 extern const char *selinux_booleans_subs_path(void);
556 extern const char *selinux_booleans_path(void);
557 extern const char *selinux_customizable_types_path(void);
558 extern const char *selinux_users_path(void);
559 extern const char *selinux_usersconf_path(void);
560 extern const char *selinux_translations_path(void);
561 extern const char *selinux_colors_path(void);
562 extern const char *selinux_netfilter_context_path(void);
563 extern const char *selinux_path(void);
564 
565 /**
566  * selinux_check_access - Check permissions and perform appropriate auditing.
567  * @scon: source security context
568  * @tcon: target security context
569  * @tclass: target security class string
570  * @perm: requested permissions string, interpreted based on @tclass
571  * @auditdata: auxiliary audit data
572  *
573  * Check the AVC to determine whether the @perm permissions are granted
574  * for the SID pair (@scon, @tcon), interpreting the permissions
575  * based on @tclass.
576  * Return %0 if all @perm permissions are granted, -%1 with
577  * @errno set to %EACCES if any permissions are denied or to another
578  * value upon other errors.
579  * If auditing or logging is configured the appropriate callbacks will be called
580  * and passed the auditdata field
581  */
582 extern int selinux_check_access(const char * scon, const char * tcon, const char *tclass, const char *perm, void *auditdata);
583 
584 /* Check a permission in the passwd class.
585    Return 0 if granted or -1 otherwise. */
586 extern int selinux_check_passwd_access(access_vector_t requested);
587 extern int checkPasswdAccess(access_vector_t requested);
588 
589 /* Check if the tty_context is defined as a securetty
590    Return 0 if secure, < 0 otherwise. */
591 extern int selinux_check_securetty_context(const char * tty_context);
592 
593 /* Set the path to the selinuxfs mount point explicitly.
594    Normally, this is determined automatically during libselinux
595    initialization, but this is not always possible, e.g. for /sbin/init
596    which performs the initial mount of selinuxfs. */
597 void set_selinuxmnt(const char *mnt);
598 
599 /* Check if selinuxfs exists as a kernel filesystem */
600 int selinuxfs_exists(void);
601 
602 /* clear selinuxmnt variable and free allocated memory */
603 void fini_selinuxmnt(void);
604 
605 /* Set an appropriate security context based on the filename of a helper
606  * program, falling back to a new context with the specified type. */
607 extern int setexecfilecon(const char *filename, const char *fallback_type);
608 
609 #ifndef DISABLE_RPM
610 /* Execute a helper for rpm in an appropriate security context. */
611 extern int rpm_execcon(unsigned int verified,
612 		       const char *filename,
613 		       char *const argv[], char *const envp[]);
614 #endif
615 
616 /* Returns whether a file context is customizable, and should not
617    be relabeled . */
618 extern int is_context_customizable(const char * scontext);
619 
620 /* Perform context translation between the human-readable format
621    ("translated") and the internal system format ("raw").
622    Caller must free the resulting context via freecon.
623    Returns -1 upon an error or 0 otherwise.
624    If passed NULL, sets the returned context to NULL and returns 0. */
625 extern int selinux_trans_to_raw_context(const char * trans,
626 					char ** rawp);
627 extern int selinux_raw_to_trans_context(const char * raw,
628 					char ** transp);
629 
630 /* Perform context translation between security contexts
631    and display colors.  Returns a space-separated list of ten
632    ten hex RGB triples prefixed by hash marks, e.g. "#ff0000".
633    Caller must free the resulting string via free.
634    Returns -1 upon an error or 0 otherwise. */
635 extern int selinux_raw_context_to_color(const char * raw,
636 					char **color_str);
637 
638 /* Get the SELinux username and level to use for a given Linux username.
639    These values may then be passed into the get_ordered_context_list*
640    and get_default_context* functions to obtain a context for the user.
641    Returns 0 on success or -1 otherwise.
642    Caller must free the returned strings via free. */
643 extern int getseuserbyname(const char *linuxuser, char **seuser, char **level);
644 
645 /* Get the SELinux username and level to use for a given Linux username and service.
646    These values may then be passed into the get_ordered_context_list*
647    and get_default_context* functions to obtain a context for the user.
648    Returns 0 on success or -1 otherwise.
649    Caller must free the returned strings via free. */
650 extern int getseuser(const char *username, const char *service,
651 		     char **r_seuser, char **r_level);
652 
653 /* Compare two file contexts, return 0 if equivalent. */
654 extern int selinux_file_context_cmp(const char * a,
655 			     const char * b);
656 
657 /*
658  * Verify the context of the file 'path' against policy.
659  * Return 1 if match, 0 if not and -1 on error.
660  */
661 extern int selinux_file_context_verify(const char *path, mode_t mode);
662 
663 /* This function sets the file context on to the system defaults returns 0 on success */
664 extern int selinux_lsetfilecon_default(const char *path);
665 
666 /*
667  * Force a reset of the loaded configuration
668  * WARNING: This is not thread safe. Be very sure that no other threads
669  * are calling into libselinux when this is called.
670  */
671 extern void selinux_reset_config(void);
672 
673 #ifdef __cplusplus
674 }
675 #endif
676 #endif
677