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(const 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 447 #ifdef __GNUC__ 448 __attribute__ ((format(printf, 1, 2))) 449 #endif 450 (*f) (const char *fmt, ...)); 451 452 /* Set the function used by matchpathcon_init when checking the 453 validity of a context in the file contexts configuration. If not set, 454 then this defaults to a test based on security_check_context(). 455 The function is also responsible for reporting any such error, and 456 may include the 'path' and 'lineno' in such error messages. */ 457 extern void set_matchpathcon_invalidcon(int (*f) (const char *path, 458 unsigned lineno, 459 char *context)); 460 461 /* Same as above, but also allows canonicalization of the context, 462 by changing *context to refer to the canonical form. If not set, 463 and invalidcon is also not set, then this defaults to calling 464 security_canonicalize_context(). */ 465 extern void set_matchpathcon_canoncon(int (*f) (const char *path, 466 unsigned lineno, 467 char **context)); 468 469 /* Set flags controlling operation of matchpathcon_init or matchpathcon. */ 470 #define MATCHPATHCON_BASEONLY 1 /* Only process the base file_contexts file. */ 471 #define MATCHPATHCON_NOTRANS 2 /* Do not perform any context translation. */ 472 #define MATCHPATHCON_VALIDATE 4 /* Validate/canonicalize contexts at init time. */ 473 extern void set_matchpathcon_flags(unsigned int flags); 474 475 /* Load the file contexts configuration specified by 'path' 476 into memory for use by subsequent matchpathcon calls. 477 If 'path' is NULL, then load the active file contexts configuration, 478 i.e. the path returned by selinux_file_context_path(). 479 Unless the MATCHPATHCON_BASEONLY flag has been set, this 480 function also checks for a 'path'.homedirs file and 481 a 'path'.local file and loads additional specifications 482 from them if present. */ 483 extern int matchpathcon_init(const char *path) 484 #ifdef __GNUC__ 485 __attribute__ ((deprecated("Use selabel_open with backend SELABEL_CTX_FILE"))) 486 #endif 487 ; 488 489 /* Same as matchpathcon_init, but only load entries with 490 regexes that have stems that are prefixes of 'prefix'. */ 491 extern int matchpathcon_init_prefix(const char *path, const char *prefix); 492 493 /* Free the memory allocated by matchpathcon_init. */ 494 extern void matchpathcon_fini(void) 495 #ifdef __GNUC__ 496 __attribute__ ((deprecated("Use selabel_close"))) 497 #endif 498 ; 499 500 /* Resolve all of the symlinks and relative portions of a pathname, but NOT 501 * the final component (same a realpath() unless the final component is a 502 * symlink. Resolved path must be a path of size PATH_MAX + 1 */ 503 extern int realpath_not_final(const char *name, char *resolved_path); 504 505 /* Match the specified pathname and mode against the file contexts 506 configuration and set *con to refer to the resulting context. 507 'mode' can be 0 to disable mode matching. 508 Caller must free via freecon. 509 If matchpathcon_init has not already been called, then this function 510 will call it upon its first invocation with a NULL path. */ 511 extern int matchpathcon(const char *path, 512 mode_t mode, char ** con) 513 #ifdef __GNUC__ 514 __attribute__ ((deprecated("Use selabel_lookup instead"))) 515 #endif 516 ; 517 518 /* Same as above, but return a specification index for 519 later use in a matchpathcon_filespec_add() call - see below. */ 520 extern int matchpathcon_index(const char *path, 521 mode_t mode, char ** con); 522 523 /* Maintain an association between an inode and a specification index, 524 and check whether a conflicting specification is already associated 525 with the same inode (e.g. due to multiple hard links). If so, then 526 use the latter of the two specifications based on their order in the 527 file contexts configuration. Return the used specification index. */ 528 extern int matchpathcon_filespec_add(ino_t ino, int specind, const char *file); 529 530 /* Destroy any inode associations that have been added, e.g. to restart 531 for a new filesystem. */ 532 extern void matchpathcon_filespec_destroy(void); 533 534 /* Display statistics on the hash table usage for the associations. */ 535 extern void matchpathcon_filespec_eval(void); 536 537 /* Check to see whether any specifications had no matches and report them. 538 The 'str' is used as a prefix for any warning messages. */ 539 extern void matchpathcon_checkmatches(char *str); 540 541 /* Match the specified media and against the media contexts 542 configuration and set *con to refer to the resulting context. 543 Caller must free con via freecon. */ 544 extern int matchmediacon(const char *media, char ** con); 545 546 /* 547 selinux_getenforcemode reads the /etc/selinux/config file and determines 548 whether the machine should be started in enforcing (1), permissive (0) or 549 disabled (-1) mode. 550 */ 551 extern int selinux_getenforcemode(int *enforce); 552 553 /* 554 selinux_boolean_sub reads the /etc/selinux/TYPE/booleans.subs_dist file 555 looking for a record with boolean_name. If a record exists selinux_boolean_sub 556 returns the translated name otherwise it returns the original name. 557 The returned value needs to be freed. On failure NULL will be returned. 558 */ 559 extern char *selinux_boolean_sub(const char *boolean_name); 560 561 /* 562 selinux_getpolicytype reads the /etc/selinux/config file and determines 563 what the default policy for the machine is. Calling application must 564 free policytype. 565 */ 566 extern int selinux_getpolicytype(char **policytype); 567 568 /* 569 selinux_policy_root reads the /etc/selinux/config file and returns 570 the directory path under which the compiled policy file and context 571 configuration files exist. 572 */ 573 extern const char *selinux_policy_root(void); 574 575 /* 576 selinux_set_policy_root sets an alternate policy root directory path under 577 which the compiled policy file and context configuration files exist. 578 */ 579 extern int selinux_set_policy_root(const char *rootpath); 580 581 /* These functions return the paths to specific files under the 582 policy root directory. */ 583 extern const char *selinux_current_policy_path(void); 584 extern const char *selinux_binary_policy_path(void); 585 extern const char *selinux_failsafe_context_path(void); 586 extern const char *selinux_removable_context_path(void); 587 extern const char *selinux_default_context_path(void); 588 extern const char *selinux_user_contexts_path(void); 589 extern const char *selinux_file_context_path(void); 590 extern const char *selinux_file_context_homedir_path(void); 591 extern const char *selinux_file_context_local_path(void); 592 extern const char *selinux_file_context_subs_path(void); 593 extern const char *selinux_file_context_subs_dist_path(void); 594 extern const char *selinux_homedir_context_path(void); 595 extern const char *selinux_media_context_path(void); 596 extern const char *selinux_virtual_domain_context_path(void); 597 extern const char *selinux_virtual_image_context_path(void); 598 extern const char *selinux_lxc_contexts_path(void); 599 extern const char *selinux_x_context_path(void); 600 extern const char *selinux_sepgsql_context_path(void); 601 extern const char *selinux_openrc_contexts_path(void); 602 extern const char *selinux_openssh_contexts_path(void); 603 extern const char *selinux_snapperd_contexts_path(void); 604 extern const char *selinux_systemd_contexts_path(void); 605 extern const char *selinux_contexts_path(void); 606 extern const char *selinux_securetty_types_path(void); 607 extern const char *selinux_booleans_subs_path(void); 608 /* Deprecated as local policy booleans no longer supported. */ 609 extern const char *selinux_booleans_path(void) 610 #ifdef __GNUC__ 611 __attribute__ ((deprecated)) 612 #endif 613 ; 614 extern const char *selinux_customizable_types_path(void); 615 /* Deprecated as policy ./users no longer supported. */ 616 extern const char *selinux_users_path(void) 617 #ifdef __GNUC__ 618 __attribute__ ((deprecated)) 619 #endif 620 ; 621 extern const char *selinux_usersconf_path(void); 622 extern const char *selinux_translations_path(void); 623 extern const char *selinux_colors_path(void); 624 extern const char *selinux_netfilter_context_path(void); 625 extern const char *selinux_path(void); 626 627 /** 628 * selinux_check_access - Check permissions and perform appropriate auditing. 629 * @scon: source security context 630 * @tcon: target security context 631 * @tclass: target security class string 632 * @perm: requested permissions string, interpreted based on @tclass 633 * @auditdata: auxiliary audit data 634 * 635 * Check the AVC to determine whether the @perm permissions are granted 636 * for the SID pair (@scon, @tcon), interpreting the permissions 637 * based on @tclass. 638 * Return %0 if all @perm permissions are granted, -%1 with 639 * @errno set to %EACCES if any permissions are denied or to another 640 * value upon other errors. 641 * If auditing or logging is configured the appropriate callbacks will be called 642 * and passed the auditdata field 643 */ 644 extern int selinux_check_access(const char * scon, const char * tcon, const char *tclass, const char *perm, void *auditdata); 645 646 /* Check a permission in the passwd class. 647 Return 0 if granted or -1 otherwise. */ 648 extern int selinux_check_passwd_access(access_vector_t requested) 649 #ifdef __GNUC__ 650 __attribute__ ((deprecated("Use selinux_check_access"))) 651 #endif 652 ; 653 654 extern int checkPasswdAccess(access_vector_t requested) 655 #ifdef __GNUC__ 656 __attribute__ ((deprecated("Use selinux_check_access"))) 657 #endif 658 ; 659 660 /* Check if the tty_context is defined as a securetty 661 Return 0 if secure, < 0 otherwise. */ 662 extern int selinux_check_securetty_context(const char * tty_context); 663 664 /* Set the path to the selinuxfs mount point explicitly. 665 Normally, this is determined automatically during libselinux 666 initialization, but this is not always possible, e.g. for /sbin/init 667 which performs the initial mount of selinuxfs. */ 668 extern void set_selinuxmnt(const char *mnt); 669 670 /* Check if selinuxfs exists as a kernel filesystem */ 671 extern int selinuxfs_exists(void); 672 673 /* clear selinuxmnt variable and free allocated memory */ 674 extern void fini_selinuxmnt(void); 675 676 /* Set an appropriate security context based on the filename of a helper 677 * program, falling back to a new context with the specified type. */ 678 extern int setexecfilecon(const char *filename, const char *fallback_type); 679 680 #ifndef DISABLE_RPM 681 /* Execute a helper for rpm in an appropriate security context. */ 682 extern int rpm_execcon(unsigned int verified, 683 const char *filename, 684 char *const argv[], char *const envp[]) 685 #ifdef __GNUC__ 686 __attribute__((deprecated("Use setexecfilecon and execve"))) 687 #endif 688 ; 689 #endif 690 691 /* Returns whether a file context is customizable, and should not 692 be relabeled . */ 693 extern int is_context_customizable(const char * scontext); 694 695 /* Perform context translation between the human-readable format 696 ("translated") and the internal system format ("raw"). 697 Caller must free the resulting context via freecon. 698 Returns -1 upon an error or 0 otherwise. 699 If passed NULL, sets the returned context to NULL and returns 0. */ 700 extern int selinux_trans_to_raw_context(const char * trans, 701 char ** rawp); 702 extern int selinux_raw_to_trans_context(const char * raw, 703 char ** transp); 704 705 /* Perform context translation between security contexts 706 and display colors. Returns a space-separated list of ten 707 ten hex RGB triples prefixed by hash marks, e.g. "#ff0000". 708 Caller must free the resulting string via free. 709 Returns -1 upon an error or 0 otherwise. */ 710 extern int selinux_raw_context_to_color(const char * raw, 711 char **color_str); 712 713 /* Get the SELinux username and level to use for a given Linux username. 714 These values may then be passed into the get_ordered_context_list* 715 and get_default_context* functions to obtain a context for the user. 716 Returns 0 on success or -1 otherwise. 717 Caller must free the returned strings via free. */ 718 extern int getseuserbyname(const char *linuxuser, char **seuser, char **level); 719 720 /* Get the SELinux username and level to use for a given Linux username and service. 721 These values may then be passed into the get_ordered_context_list* 722 and get_default_context* functions to obtain a context for the user. 723 Returns 0 on success or -1 otherwise. 724 Caller must free the returned strings via free. */ 725 extern int getseuser(const char *username, const char *service, 726 char **r_seuser, char **r_level); 727 728 /* Compare two file contexts, return 0 if equivalent. */ 729 extern int selinux_file_context_cmp(const char * a, 730 const char * b); 731 732 /* 733 * Verify the context of the file 'path' against policy. 734 * Return 1 if match, 0 if not and -1 on error. 735 */ 736 extern int selinux_file_context_verify(const char *path, mode_t mode); 737 738 /* This function sets the file context on to the system defaults returns 0 on success */ 739 extern int selinux_lsetfilecon_default(const char *path); 740 741 /* 742 * Force a reset of the loaded configuration 743 * WARNING: This is not thread safe. Be very sure that no other threads 744 * are calling into libselinux when this is called. 745 */ 746 extern void selinux_reset_config(void); 747 748 /** 749 * Frees the ignore path configurations and resets the system and vendor configuration load states. 750 * 751 * This function frees two types of ignore paths: paths ending with a slash and paths ending with a star. 752 * It also resets the load states of the system and vendor configurations to not loaded. 753 */ 754 extern void free_ignore_cfg(); 755 756 #ifdef __cplusplus 757 } 758 #endif 759 #endif 760