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 /* Disable SELinux at runtime (must be done prior to initial policy load). */ 335 extern int security_disable(void); 336 337 /* Get the policy version number. */ 338 extern int security_policyvers(void); 339 340 /* Get the boolean names */ 341 extern int security_get_boolean_names(char ***names, int *len); 342 343 /* Get the pending value for the boolean */ 344 extern int security_get_boolean_pending(const char *name); 345 346 /* Get the active value for the boolean */ 347 extern int security_get_boolean_active(const char *name); 348 349 /* Set the pending value for the boolean */ 350 extern int security_set_boolean(const char *name, int value); 351 352 /* Commit the pending values for the booleans */ 353 extern int security_commit_booleans(void); 354 355 /* Userspace class mapping support */ 356 struct security_class_mapping { 357 const char *name; 358 const char *perms[sizeof(access_vector_t) * 8 + 1]; 359 }; 360 361 /** 362 * selinux_set_mapping - Enable dynamic mapping between integer offsets and security class names 363 * @map: array of security_class_mapping structures 364 * 365 * The core avc_has_perm() API uses integers to represent security 366 * classes; previous to the introduction of this function, it was 367 * common for userspace object managers to be compiled using generated 368 * offsets for a particular policy. However, that strongly ties the build of the userspace components to a particular policy. 369 * 370 * By using this function to map between integer offsets and security 371 * class names, it's possible to replace a system policies that have 372 * at least the same set of security class names as used by the 373 * userspace object managers. 374 * 375 * To correctly use this function, you should override the generated 376 * security class defines from the system policy in a local header, 377 * starting at 1, and have one security_class_mapping structure entry 378 * per define. 379 */ 380 extern int selinux_set_mapping(struct security_class_mapping *map); 381 382 /* Common helpers */ 383 384 /* Convert between mode and security class values */ 385 extern security_class_t mode_to_security_class(mode_t mode); 386 /* Convert between security class values and string names */ 387 extern security_class_t string_to_security_class(const char *name); 388 extern const char *security_class_to_string(security_class_t cls); 389 390 /* Convert between individual access vector permissions and string names */ 391 extern const char *security_av_perm_to_string(security_class_t tclass, 392 access_vector_t perm); 393 extern access_vector_t string_to_av_perm(security_class_t tclass, 394 const char *name); 395 396 /* Returns an access vector in a string representation. User must free the 397 * returned string via free(). */ 398 extern int security_av_string(security_class_t tclass, 399 access_vector_t av, char **result); 400 401 /* Display an access vector in a string representation. */ 402 extern void print_access_vector(security_class_t tclass, access_vector_t av); 403 404 /* Set the function used by matchpathcon_init when displaying 405 errors about the file_contexts configuration. If not set, 406 then this defaults to fprintf(stderr, fmt, ...). */ 407 extern void set_matchpathcon_printf(void (*f) (const char *fmt, ...)); 408 409 /* Set the function used by matchpathcon_init when checking the 410 validity of a context in the file contexts configuration. If not set, 411 then this defaults to a test based on security_check_context(). 412 The function is also responsible for reporting any such error, and 413 may include the 'path' and 'lineno' in such error messages. */ 414 extern void set_matchpathcon_invalidcon(int (*f) (const char *path, 415 unsigned lineno, 416 char *context)); 417 418 /* Same as above, but also allows canonicalization of the context, 419 by changing *context to refer to the canonical form. If not set, 420 and invalidcon is also not set, then this defaults to calling 421 security_canonicalize_context(). */ 422 extern void set_matchpathcon_canoncon(int (*f) (const char *path, 423 unsigned lineno, 424 char **context)); 425 426 /* Set flags controlling operation of matchpathcon_init or matchpathcon. */ 427 #define MATCHPATHCON_BASEONLY 1 /* Only process the base file_contexts file. */ 428 #define MATCHPATHCON_NOTRANS 2 /* Do not perform any context translation. */ 429 #define MATCHPATHCON_VALIDATE 4 /* Validate/canonicalize contexts at init time. */ 430 extern void set_matchpathcon_flags(unsigned int flags); 431 432 /* Load the file contexts configuration specified by 'path' 433 into memory for use by subsequent matchpathcon calls. 434 If 'path' is NULL, then load the active file contexts configuration, 435 i.e. the path returned by selinux_file_context_path(). 436 Unless the MATCHPATHCON_BASEONLY flag has been set, this 437 function also checks for a 'path'.homedirs file and 438 a 'path'.local file and loads additional specifications 439 from them if present. */ 440 extern int matchpathcon_init(const char *path); 441 442 /* Same as matchpathcon_init, but only load entries with 443 regexes that have stems that are prefixes of 'prefix'. */ 444 extern int matchpathcon_init_prefix(const char *path, const char *prefix); 445 446 /* Free the memory allocated by matchpathcon_init. */ 447 extern void matchpathcon_fini(void); 448 449 /* Resolve all of the symlinks and relative portions of a pathname, but NOT 450 * the final component (same a realpath() unless the final component is a 451 * symlink. Resolved path must be a path of size PATH_MAX + 1 */ 452 extern int realpath_not_final(const char *name, char *resolved_path); 453 454 /* Match the specified pathname and mode against the file contexts 455 configuration and set *con to refer to the resulting context. 456 'mode' can be 0 to disable mode matching. 457 Caller must free via freecon. 458 If matchpathcon_init has not already been called, then this function 459 will call it upon its first invocation with a NULL path. */ 460 extern int matchpathcon(const char *path, 461 mode_t mode, char ** con); 462 463 /* Same as above, but return a specification index for 464 later use in a matchpathcon_filespec_add() call - see below. */ 465 extern int matchpathcon_index(const char *path, 466 mode_t mode, char ** con); 467 468 /* Maintain an association between an inode and a specification index, 469 and check whether a conflicting specification is already associated 470 with the same inode (e.g. due to multiple hard links). If so, then 471 use the latter of the two specifications based on their order in the 472 file contexts configuration. Return the used specification index. */ 473 extern int matchpathcon_filespec_add(ino_t ino, int specind, const char *file); 474 475 /* Destroy any inode associations that have been added, e.g. to restart 476 for a new filesystem. */ 477 extern void matchpathcon_filespec_destroy(void); 478 479 /* Display statistics on the hash table usage for the associations. */ 480 extern void matchpathcon_filespec_eval(void); 481 482 /* Check to see whether any specifications had no matches and report them. 483 The 'str' is used as a prefix for any warning messages. */ 484 extern void matchpathcon_checkmatches(char *str); 485 486 /* Match the specified media and against the media contexts 487 configuration and set *con to refer to the resulting context. 488 Caller must free con via freecon. */ 489 extern int matchmediacon(const char *media, char ** con); 490 491 /* 492 selinux_getenforcemode reads the /etc/selinux/config file and determines 493 whether the machine should be started in enforcing (1), permissive (0) or 494 disabled (-1) mode. 495 */ 496 extern int selinux_getenforcemode(int *enforce); 497 498 /* 499 selinux_boolean_sub reads the /etc/selinux/TYPE/booleans.subs_dist file 500 looking for a record with boolean_name. If a record exists selinux_boolean_sub 501 returns the translated name otherwise it returns the original name. 502 The returned value needs to be freed. On failure NULL will be returned. 503 */ 504 extern char *selinux_boolean_sub(const char *boolean_name); 505 506 /* 507 selinux_getpolicytype reads the /etc/selinux/config file and determines 508 what the default policy for the machine is. Calling application must 509 free policytype. 510 */ 511 extern int selinux_getpolicytype(char **policytype); 512 513 /* 514 selinux_policy_root reads the /etc/selinux/config file and returns 515 the directory path under which the compiled policy file and context 516 configuration files exist. 517 */ 518 extern const char *selinux_policy_root(void); 519 520 /* 521 selinux_set_policy_root sets an alternate policy root directory path under 522 which the compiled policy file and context configuration files exist. 523 */ 524 extern int selinux_set_policy_root(const char *rootpath); 525 526 /* These functions return the paths to specific files under the 527 policy root directory. */ 528 extern const char *selinux_current_policy_path(void); 529 extern const char *selinux_binary_policy_path(void); 530 extern const char *selinux_failsafe_context_path(void); 531 extern const char *selinux_removable_context_path(void); 532 extern const char *selinux_default_context_path(void); 533 extern const char *selinux_user_contexts_path(void); 534 extern const char *selinux_file_context_path(void); 535 extern const char *selinux_file_context_homedir_path(void); 536 extern const char *selinux_file_context_local_path(void); 537 extern const char *selinux_file_context_subs_path(void); 538 extern const char *selinux_file_context_subs_dist_path(void); 539 extern const char *selinux_homedir_context_path(void); 540 extern const char *selinux_media_context_path(void); 541 extern const char *selinux_virtual_domain_context_path(void); 542 extern const char *selinux_virtual_image_context_path(void); 543 extern const char *selinux_lxc_contexts_path(void); 544 extern const char *selinux_x_context_path(void); 545 extern const char *selinux_sepgsql_context_path(void); 546 extern const char *selinux_systemd_contexts_path(void); 547 extern const char *selinux_contexts_path(void); 548 extern const char *selinux_securetty_types_path(void); 549 extern const char *selinux_booleans_subs_path(void); 550 extern const char *selinux_booleans_path(void); 551 extern const char *selinux_customizable_types_path(void); 552 extern const char *selinux_users_path(void); 553 extern const char *selinux_usersconf_path(void); 554 extern const char *selinux_translations_path(void); 555 extern const char *selinux_colors_path(void); 556 extern const char *selinux_netfilter_context_path(void); 557 extern const char *selinux_path(void); 558 559 /** 560 * selinux_check_access - Check permissions and perform appropriate auditing. 561 * @scon: source security context 562 * @tcon: target security context 563 * @tclass: target security class string 564 * @perm: requested permissions string, interpreted based on @tclass 565 * @auditdata: auxiliary audit data 566 * 567 * Check the AVC to determine whether the @perm permissions are granted 568 * for the SID pair (@scon, @tcon), interpreting the permissions 569 * based on @tclass. 570 * Return %0 if all @perm permissions are granted, -%1 with 571 * @errno set to %EACCES if any permissions are denied or to another 572 * value upon other errors. 573 * If auditing or logging is configured the appropriate callbacks will be called 574 * and passed the auditdata field 575 */ 576 extern int selinux_check_access(const char * scon, const char * tcon, const char *tclass, const char *perm, void *auditdata); 577 578 /* Check a permission in the passwd class. 579 Return 0 if granted or -1 otherwise. */ 580 extern int selinux_check_passwd_access(access_vector_t requested); 581 extern int checkPasswdAccess(access_vector_t requested); 582 583 /* Check if the tty_context is defined as a securetty 584 Return 0 if secure, < 0 otherwise. */ 585 extern int selinux_check_securetty_context(const char * tty_context); 586 587 /* Set the path to the selinuxfs mount point explicitly. 588 Normally, this is determined automatically during libselinux 589 initialization, but this is not always possible, e.g. for /sbin/init 590 which performs the initial mount of selinuxfs. */ 591 void set_selinuxmnt(const char *mnt); 592 593 /* Check if selinuxfs exists as a kernel filesystem */ 594 int selinuxfs_exists(void); 595 596 /* clear selinuxmnt variable and free allocated memory */ 597 void fini_selinuxmnt(void); 598 599 /* Set an appropriate security context based on the filename of a helper 600 * program, falling back to a new context with the specified type. */ 601 extern int setexecfilecon(const char *filename, const char *fallback_type); 602 603 /* Execute a helper for rpm in an appropriate security context. */ 604 extern int rpm_execcon(unsigned int verified, 605 const char *filename, 606 char *const argv[], char *const envp[]); 607 608 /* Returns whether a file context is customizable, and should not 609 be relabeled . */ 610 extern int is_context_customizable(const char * scontext); 611 612 /* Perform context translation between the human-readable format 613 ("translated") and the internal system format ("raw"). 614 Caller must free the resulting context via freecon. 615 Returns -1 upon an error or 0 otherwise. 616 If passed NULL, sets the returned context to NULL and returns 0. */ 617 extern int selinux_trans_to_raw_context(const char * trans, 618 char ** rawp); 619 extern int selinux_raw_to_trans_context(const char * raw, 620 char ** transp); 621 622 /* Perform context translation between security contexts 623 and display colors. Returns a space-separated list of ten 624 ten hex RGB triples prefixed by hash marks, e.g. "#ff0000". 625 Caller must free the resulting string via free. 626 Returns -1 upon an error or 0 otherwise. */ 627 extern int selinux_raw_context_to_color(const char * raw, 628 char **color_str); 629 630 /* Get the SELinux username and level to use for a given Linux username. 631 These values may then be passed into the get_ordered_context_list* 632 and get_default_context* functions to obtain a context for the user. 633 Returns 0 on success or -1 otherwise. 634 Caller must free the returned strings via free. */ 635 extern int getseuserbyname(const char *linuxuser, char **seuser, char **level); 636 637 /* Get the SELinux username and level to use for a given Linux username and service. 638 These values may then be passed into the get_ordered_context_list* 639 and get_default_context* functions to obtain a context for the user. 640 Returns 0 on success or -1 otherwise. 641 Caller must free the returned strings via free. */ 642 extern int getseuser(const char *username, const char *service, 643 char **r_seuser, char **r_level); 644 645 /* Compare two file contexts, return 0 if equivalent. */ 646 extern int selinux_file_context_cmp(const char * a, 647 const char * b); 648 649 /* 650 * Verify the context of the file 'path' against policy. 651 * Return 1 if match, 0 if not and -1 on error. 652 */ 653 extern int selinux_file_context_verify(const char *path, mode_t mode); 654 655 /* This function sets the file context on to the system defaults returns 0 on success */ 656 extern int selinux_lsetfilecon_default(const char *path); 657 658 /* 659 * Force a reset of the loaded configuration 660 * WARNING: This is not thread safe. Be very sure that no other threads 661 * are calling into libselinux when this is called. 662 */ 663 extern void selinux_reset_config(void); 664 665 #ifdef __cplusplus 666 } 667 #endif 668 #endif 669