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