diff options
Diffstat (limited to 'include/selinux')
-rw-r--r-- | include/selinux/android.h | 56 | ||||
-rw-r--r-- | include/selinux/avc.h | 507 | ||||
-rw-r--r-- | include/selinux/context.h | 50 | ||||
-rw-r--r-- | include/selinux/label.h | 167 | ||||
-rw-r--r-- | include/selinux/selinux.h | 291 |
5 files changed, 0 insertions, 1071 deletions
diff --git a/include/selinux/android.h b/include/selinux/android.h deleted file mode 100644 index 21a41a0..0000000 --- a/include/selinux/android.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _SELINUX_ANDROID_H_ -#define _SELINUX_ANDROID_H_ - -#include <stdbool.h> -#include <sys/types.h> -#include <unistd.h> - -#include <selinux/label.h> - -#ifdef __cplusplus -extern "C" { -#endif - -extern struct selabel_handle* selinux_android_file_context_handle(void); - -extern struct selabel_handle* selinux_android_prop_context_handle(void); - -extern struct selabel_handle* selinux_android_service_context_handle(void); - -extern void selinux_android_set_sehandle(const struct selabel_handle *hndl); - -extern int selinux_android_load_policy(void); - -extern int selinux_android_setcon(const char *con); - -extern int selinux_android_setcontext(uid_t uid, - bool isSystemServer, - const char *seinfo, - const char *name); - -extern int selinux_android_setfilecon(const char *pkgdir, - const char *pkgname, - const char *seinfo, - uid_t uid); - -extern int selinux_log_callback(int type, const char *fmt, ...) - __attribute__ ((format(printf, 2, 3))); - -#define SELINUX_ANDROID_RESTORECON_NOCHANGE 1 -#define SELINUX_ANDROID_RESTORECON_VERBOSE 2 -#define SELINUX_ANDROID_RESTORECON_RECURSE 4 -#define SELINUX_ANDROID_RESTORECON_FORCE 8 -#define SELINUX_ANDROID_RESTORECON_DATADATA 16 -extern int selinux_android_restorecon(const char *file, unsigned int flags); - -extern int selinux_android_restorecon_pkgdir(const char *pkgdir, - const char *seinfo, - uid_t uid, - unsigned int flags); - -extern int selinux_android_seapp_context_reload(void); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/include/selinux/avc.h b/include/selinux/avc.h deleted file mode 100644 index 8a1a6df..0000000 --- a/include/selinux/avc.h +++ /dev/null @@ -1,507 +0,0 @@ -/* - * Access vector cache interface for object managers. - * - * Author : Eamon Walsh <ewalsh@epoch.ncsc.mil> - */ -#ifndef _SELINUX_AVC_H_ -#define _SELINUX_AVC_H_ - -#include <stdint.h> -#include <errno.h> -#include <stdlib.h> -#include <selinux/selinux.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * SID format and operations - */ -struct security_id { - char * ctx; - unsigned int refcnt; -}; -typedef struct security_id *security_id_t; - -#define SECSID_WILD (security_id_t)NULL /* unspecified SID */ - -/** - * avc_sid_to_context - get copy of context corresponding to SID. - * @sid: input SID - * @ctx: pointer to context reference - * - * Return a copy of the security context corresponding to the input - * @sid in the memory referenced by @ctx. The caller is expected to - * free the context with freecon(). Return %0 on success, -%1 on - * failure, with @errno set to %ENOMEM if insufficient memory was - * available to make the copy, or %EINVAL if the input SID is invalid. - */ -int avc_sid_to_context(security_id_t sid, char ** ctx); -int avc_sid_to_context_raw(security_id_t sid, char ** ctx); - -/** - * avc_context_to_sid - get SID for context. - * @ctx: input security context - * @sid: pointer to SID reference - * - * Look up security context @ctx in SID table, making - * a new entry if @ctx is not found. Increment the - * reference counter for the SID. Store a pointer - * to the SID structure into the memory referenced by @sid, - * returning %0 on success or -%1 on error with @errno set. - */ -int avc_context_to_sid(const char * ctx, security_id_t * sid); -int avc_context_to_sid_raw(const char * ctx, security_id_t * sid); - -/** - * sidget - increment SID reference counter. - * @sid: SID reference - * - * Increment the reference counter for @sid, indicating that - * @sid is in use by an (additional) object. Return the - * new reference count, or zero if @sid is invalid (has zero - * reference count). Note that avc_context_to_sid() also - * increments reference counts. - */ -int sidget(security_id_t sid); - -/** - * sidput - decrement SID reference counter. - * @sid: SID reference - * - * Decrement the reference counter for @sid, indicating that - * a reference to @sid is no longer in use. Return the - * new reference count. When the reference count reaches - * zero, the SID is invalid, and avc_context_to_sid() must - * be called to obtain a new SID for the security context. - */ -int sidput(security_id_t sid); - -/** - * avc_get_initial_sid - get SID for an initial kernel security identifier - * @name: input name of initial kernel security identifier - * @sid: pointer to a SID reference - * - * Get the context for an initial kernel security identifier specified by - * @name using security_get_initial_context() and then call - * avc_context_to_sid() to get the corresponding SID. - */ -int avc_get_initial_sid(const char *name, security_id_t * sid); - -/* - * AVC entry - */ -struct avc_entry; -struct avc_entry_ref { - struct avc_entry *ae; -}; - -/** - * avc_entry_ref_init - initialize an AVC entry reference. - * @aeref: pointer to avc entry reference structure - * - * Use this macro to initialize an avc entry reference structure - * before first use. These structures are passed to avc_has_perm(), - * which stores cache entry references in them. They can increase - * performance on repeated queries. - */ -#define avc_entry_ref_init(aeref) ((aeref)->ae = NULL) - -/* - * User-provided callbacks for memory, auditing, and locking - */ - -/* These structures are passed by reference to avc_init(). Passing - * a NULL reference will cause the AVC to use a default. The default - * memory callbacks are malloc() and free(). The default logging method - * is to print on stderr. If no thread callbacks are passed, a separate - * listening thread won't be started for kernel policy change messages. - * If no locking callbacks are passed, no locking will take place. - */ -struct avc_memory_callback { - /* malloc() equivalent. */ - void *(*func_malloc) (size_t size); - /* free() equivalent. */ - void (*func_free) (void *ptr); - /* Note that these functions should set errno on failure. - If not, some avc routines may return -1 without errno set. */ -}; - -struct avc_log_callback { - /* log the printf-style format and arguments. */ - void (*func_log) (const char *fmt, ...); - /* store a string representation of auditdata (corresponding - to the given security class) into msgbuf. */ - void (*func_audit) (void *auditdata, security_class_t cls, - char *msgbuf, size_t msgbufsize); -}; - -struct avc_thread_callback { - /* create and start a thread, returning an opaque pointer to it; - the thread should run the given function. */ - void *(*func_create_thread) (void (*run) (void)); - /* cancel a given thread and free its resources. */ - void (*func_stop_thread) (void *thread); -}; - -struct avc_lock_callback { - /* create a lock and return an opaque pointer to it. */ - void *(*func_alloc_lock) (void); - /* obtain a given lock, blocking if necessary. */ - void (*func_get_lock) (void *lock); - /* release a given lock. */ - void (*func_release_lock) (void *lock); - /* destroy a given lock (free memory, etc.) */ - void (*func_free_lock) (void *lock); -}; - -/* - * Available options - */ - -/* no-op option, useful for unused slots in an array of options */ -#define AVC_OPT_UNUSED 0 -/* override kernel enforcing mode (boolean value) */ -#define AVC_OPT_SETENFORCE 1 - -/* - * AVC operations - */ - -/** - * avc_init - Initialize the AVC. - * @msgprefix: prefix for log messages - * @mem_callbacks: user-supplied memory callbacks - * @log_callbacks: user-supplied logging callbacks - * @thread_callbacks: user-supplied threading callbacks - * @lock_callbacks: user-supplied locking callbacks - * - * Initialize the access vector cache. Return %0 on - * success or -%1 with @errno set on failure. - * If @msgprefix is NULL, use "uavc". If any callback - * structure references are NULL, use default methods - * for those callbacks (see the definition of the callback - * structures above). - */ -int avc_init(const char *msgprefix, - const struct avc_memory_callback *mem_callbacks, - const struct avc_log_callback *log_callbacks, - const struct avc_thread_callback *thread_callbacks, - const struct avc_lock_callback *lock_callbacks); - -/** - * avc_open - Initialize the AVC. - * @opts: array of selabel_opt structures specifying AVC options or NULL. - * @nopts: number of elements in opts array or zero for no options. - * - * This function is identical to avc_init(), except the message prefix - * is set to "avc" and any callbacks desired should be specified via - * selinux_set_callback(). Available options are listed above. - */ -int avc_open(struct selinux_opt *opts, unsigned nopts); - -/** - * avc_cleanup - Remove unused SIDs and AVC entries. - * - * Search the SID table for SID structures with zero - * reference counts, and remove them along with all - * AVC entries that reference them. This can be used - * to return memory to the system. - */ -void avc_cleanup(void); - -/** - * avc_reset - Flush the cache and reset statistics. - * - * Remove all entries from the cache and reset all access - * statistics (as returned by avc_cache_stats()) to zero. - * The SID mapping is not affected. Return %0 on success, - * -%1 with @errno set on error. - */ -int avc_reset(void); - -/** - * avc_destroy - Free all AVC structures. - * - * Destroy all AVC structures and free all allocated - * memory. User-supplied locking, memory, and audit - * callbacks will be retained, but security-event - * callbacks will not. All SID's will be invalidated. - * User must call avc_init() if further use of AVC is desired. - */ -void avc_destroy(void); - -/** - * avc_has_perm_noaudit - Check permissions but perform no auditing. - * @ssid: source security identifier - * @tsid: target security identifier - * @tclass: target security class - * @requested: requested permissions, interpreted based on @tclass - * @aeref: AVC entry reference - * @avd: access vector decisions - * - * Check the AVC to determine whether the @requested permissions are granted - * for the SID pair (@ssid, @tsid), interpreting the permissions - * based on @tclass, and call the security server on a cache miss to obtain - * a new decision and add it to the cache. Update @aeref to refer to an AVC - * entry with the resulting decisions, and return a copy of the decisions - * in @avd. Return %0 if all @requested permissions are granted, -%1 with - * @errno set to %EACCES if any permissions are denied, or to another value - * upon other errors. This function is typically called by avc_has_perm(), - * but may also be called directly to separate permission checking from - * auditing, e.g. in cases where a lock must be held for the check but - * should be released for the auditing. - */ -int avc_has_perm_noaudit(security_id_t ssid, - security_id_t tsid, - security_class_t tclass, - access_vector_t requested, - struct avc_entry_ref *aeref, struct av_decision *avd); - -/** - * avc_has_perm - Check permissions and perform any appropriate auditing. - * @ssid: source security identifier - * @tsid: target security identifier - * @tclass: target security class - * @requested: requested permissions, interpreted based on @tclass - * @aeref: AVC entry reference - * @auditdata: auxiliary audit data - * - * Check the AVC to determine whether the @requested permissions are granted - * for the SID pair (@ssid, @tsid), interpreting the permissions - * based on @tclass, and call the security server on a cache miss to obtain - * a new decision and add it to the cache. Update @aeref to refer to an AVC - * entry with the resulting decisions. Audit the granting or denial of - * permissions in accordance with the policy. Return %0 if all @requested - * permissions are granted, -%1 with @errno set to %EACCES if any permissions - * are denied or to another value upon other errors. - */ -int avc_has_perm(security_id_t ssid, security_id_t tsid, - security_class_t tclass, access_vector_t requested, - struct avc_entry_ref *aeref, void *auditdata); - -/** - * avc_audit - Audit the granting or denial of permissions. - * @ssid: source security identifier - * @tsid: target security identifier - * @tclass: target security class - * @requested: requested permissions - * @avd: access vector decisions - * @result: result from avc_has_perm_noaudit - * @auditdata: auxiliary audit data - * - * Audit the granting or denial of permissions in accordance - * with the policy. This function is typically called by - * avc_has_perm() after a permission check, but can also be - * called directly by callers who use avc_has_perm_noaudit() - * in order to separate the permission check from the auditing. - * For example, this separation is useful when the permission check must - * be performed under a lock, to allow the lock to be released - * before calling the auditing code. - */ -void avc_audit(security_id_t ssid, security_id_t tsid, - security_class_t tclass, access_vector_t requested, - struct av_decision *avd, int result, void *auditdata); - -/** - * avc_compute_create - Compute SID for labeling a new object. - * @ssid: source security identifier - * @tsid: target security identifier - * @tclass: target security class - * @newsid: pointer to SID reference - * - * Call the security server to obtain a context for labeling a - * new object. Look up the context in the SID table, making - * a new entry if not found. Increment the reference counter - * for the SID. Store a pointer to the SID structure into the - * memory referenced by @newsid, returning %0 on success or -%1 on - * error with @errno set. - */ -int avc_compute_create(security_id_t ssid, - security_id_t tsid, - security_class_t tclass, security_id_t * newsid); - -/** - * avc_compute_member - Compute SID for polyinstantation. - * @ssid: source security identifier - * @tsid: target security identifier - * @tclass: target security class - * @newsid: pointer to SID reference - * - * Call the security server to obtain a context for labeling an - * object instance. Look up the context in the SID table, making - * a new entry if not found. Increment the reference counter - * for the SID. Store a pointer to the SID structure into the - * memory referenced by @newsid, returning %0 on success or -%1 on - * error with @errno set. - */ -int avc_compute_member(security_id_t ssid, - security_id_t tsid, - security_class_t tclass, security_id_t * newsid); - -/* - * security event callback facility - */ - -/* security events */ -#define AVC_CALLBACK_GRANT 1 -#define AVC_CALLBACK_TRY_REVOKE 2 -#define AVC_CALLBACK_REVOKE 4 -#define AVC_CALLBACK_RESET 8 -#define AVC_CALLBACK_AUDITALLOW_ENABLE 16 -#define AVC_CALLBACK_AUDITALLOW_DISABLE 32 -#define AVC_CALLBACK_AUDITDENY_ENABLE 64 -#define AVC_CALLBACK_AUDITDENY_DISABLE 128 - -/** - * avc_add_callback - Register a callback for security events. - * @callback: callback function - * @events: bitwise OR of desired security events - * @ssid: source security identifier or %SECSID_WILD - * @tsid: target security identifier or %SECSID_WILD - * @tclass: target security class - * @perms: permissions - * - * Register a callback function for events in the set @events - * related to the SID pair (@ssid, @tsid) and - * and the permissions @perms, interpreting - * @perms based on @tclass. Returns %0 on success or - * -%1 if insufficient memory exists to add the callback. - */ -int avc_add_callback(int (*callback) - (uint32_t event, security_id_t ssid, - security_id_t tsid, security_class_t tclass, - access_vector_t perms, - access_vector_t * out_retained), - uint32_t events, security_id_t ssid, - security_id_t tsid, security_class_t tclass, - access_vector_t perms); - -/* - * AVC statistics - */ - -/* If set, cache statistics are tracked. This may - * become a compile-time option in the future. - */ -#define AVC_CACHE_STATS 1 - -struct avc_cache_stats { - unsigned entry_lookups; - unsigned entry_hits; - unsigned entry_misses; - unsigned entry_discards; - unsigned cav_lookups; - unsigned cav_hits; - unsigned cav_probes; - unsigned cav_misses; -}; - -/** - * avc_cache_stats - get cache access statistics. - * @stats: reference to statistics structure - * - * Fill the supplied structure with information about AVC - * activity since the last call to avc_init() or - * avc_reset(). See the structure definition for - * details. - */ -void avc_cache_stats(struct avc_cache_stats *stats); - -/** - * avc_av_stats - log av table statistics. - * - * Log a message with information about the size and - * distribution of the access vector table. The audit - * callback is used to print the message. - */ -void avc_av_stats(void); - -/** - * avc_sid_stats - log SID table statistics. - * - * Log a message with information about the size and - * distribution of the SID table. The audit callback - * is used to print the message. - */ -void avc_sid_stats(void); - -/** - * avc_netlink_open - Create a netlink socket and connect to the kernel. - */ -int avc_netlink_open(int blocking); - -/** - * avc_netlink_loop - Wait for netlink messages from the kernel - */ -void avc_netlink_loop(void); - -/** - * avc_netlink_close - Close the netlink socket - */ -void avc_netlink_close(void); - -/** - * avc_netlink_acquire_fd - Acquire netlink socket fd. - * - * Allows the application to manage messages from the netlink socket in - * its own main loop. - */ -int avc_netlink_acquire_fd(void); - -/** - * avc_netlink_release_fd - Release netlink socket fd. - * - * Returns ownership of the netlink socket to the library. - */ -void avc_netlink_release_fd(void); - -/** - * avc_netlink_check_nb - Check netlink socket for new messages. - * - * Called by the application when using avc_netlink_acquire_fd() to - * process kernel netlink events. - */ -int avc_netlink_check_nb(void); - -/** - * selinux_status_open - Open and map SELinux kernel status page - * - */ -int selinux_status_open(int fallback); - -/** - * selinux_status_close - Unmap and close SELinux kernel status page - * - */ -void selinux_status_close(void); - -/** - * selinux_status_updated - Inform us whether the kernel status has been updated - * - */ -int selinux_status_updated(void); - -/** - * selinux_status_getenforce - Get the enforce flag value - * - */ -int selinux_status_getenforce(void); - -/** - * selinux_status_policyload - Get the number of policy reloaded - * - */ -int selinux_status_policyload(void); - -/** - * selinux_status_deny_unknown - Get the behavior for undefined classes/permissions - * - */ -int selinux_status_deny_unknown(void); - -#ifdef __cplusplus -} -#endif -#endif /* _SELINUX_AVC_H_ */ diff --git a/include/selinux/context.h b/include/selinux/context.h deleted file mode 100644 index 949fb1e..0000000 --- a/include/selinux/context.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef _SELINUX_CONTEXT_H_ -#define _SELINUX_CONTEXT_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Functions to deal with security contexts in user space. - */ - - typedef struct { - void *ptr; - } context_s_t; - - typedef context_s_t *context_t; - -/* Return a new context initialized to a context string */ - - extern context_t context_new(const char *); - -/* - * Return a pointer to the string value of the context_t - * Valid until the next call to context_str or context_free - * for the same context_t* - */ - - extern char *context_str(context_t); - -/* Free the storage used by a context */ - extern void context_free(context_t); - -/* Get a pointer to the string value of a context component */ - - extern const char *context_type_get(context_t); - extern const char *context_range_get(context_t); - extern const char *context_role_get(context_t); - extern const char *context_user_get(context_t); - -/* Set a context component. Returns nonzero if unsuccessful */ - - extern int context_type_set(context_t, const char *); - extern int context_range_set(context_t, const char *); - extern int context_role_set(context_t, const char *); - extern int context_user_set(context_t, const char *); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/include/selinux/label.h b/include/selinux/label.h deleted file mode 100644 index 07eff74..0000000 --- a/include/selinux/label.h +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Labeling interface for userspace object managers and others. - * - * Author : Eamon Walsh <ewalsh@tycho.nsa.gov> - */ -#ifndef _SELABEL_H_ -#define _SELABEL_H_ - -#include <stdbool.h> -#include <sys/types.h> -#include <selinux/selinux.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Opaque type used for all label handles. - */ - -struct selabel_handle; - -/* - * Available backends. - */ - -/* file contexts */ -#define SELABEL_CTX_FILE 0 -/* media contexts */ -#define SELABEL_CTX_MEDIA 1 -/* x contexts */ -#define SELABEL_CTX_X 2 -/* db objects */ -#define SELABEL_CTX_DB 3 -/* Android property contexts */ -#define SELABEL_CTX_ANDROID_PROP 4 -/* Android service contexts */ -#define SELABEL_CTX_ANDROID_SERVICE 5 - -/* - * Available options - */ - -/* no-op option, useful for unused slots in an array of options */ -#define SELABEL_OPT_UNUSED 0 -/* validate contexts before returning them (boolean value) */ -#define SELABEL_OPT_VALIDATE 1 -/* don't use local customizations to backend data (boolean value) */ -#define SELABEL_OPT_BASEONLY 2 -/* specify an alternate path to use when loading backend data */ -#define SELABEL_OPT_PATH 3 -/* select a subset of the search space as an optimization (file backend) */ -#define SELABEL_OPT_SUBSET 4 -/* total number of options */ -#define SELABEL_NOPT 5 - -/* - * Label operations - */ - -/** - * selabel_open - Create a labeling handle. - * @backend: one of the constants specifying a supported labeling backend. - * @opts: array of selabel_opt structures specifying label options or NULL. - * @nopts: number of elements in opts array or zero for no options. - * - * Open a labeling backend for use. The available backend identifiers are - * listed above. Options may be provided via the opts parameter; available - * options are listed above. Not all options may be supported by every - * backend. Return value is the created handle on success or NULL with - * @errno set on failure. - */ -struct selabel_handle *selabel_open(unsigned int backend, - const struct selinux_opt *opts, - unsigned nopts); - -/** - * selabel_close - Close a labeling handle. - * @handle: specifies handle to close - * - * Destroy the specified handle, closing files, freeing allocated memory, - * etc. The handle may not be further used after it has been closed. - */ -void selabel_close(struct selabel_handle *handle); - -/** - * selabel_lookup - Perform labeling lookup operation. - * @handle: specifies backend instance to query - * @con: returns the appropriate context with which to label the object - * @key: string input to lookup operation - * @type: numeric input to the lookup operation - * - * Perform a labeling lookup operation. Return %0 on success, -%1 with - * @errno set on failure. The key and type arguments are the inputs to the - * lookup operation; appropriate values are dictated by the backend in use. - * The result is returned in the memory pointed to by @con and must be freed - * by the user with freecon(). - */ -int selabel_lookup(struct selabel_handle *handle, char **con, - const char *key, int type); -int selabel_lookup_raw(struct selabel_handle *handle, char **con, - const char *key, int type); - -bool selabel_partial_match(struct selabel_handle *handle, const char *key); - -int selabel_lookup_best_match(struct selabel_handle *rec, char **con, - const char *key, const char **aliases, int type); - -enum selabel_cmp_result { - SELABEL_SUBSET, - SELABEL_EQUAL, - SELABEL_SUPERSET, - SELABEL_INCOMPARABLE -}; - -/** - * selabel_cmp - Compare two label configurations. - * @h1: handle for the first label configuration - * @h2: handle for the first label configuration - * - * Compare two label configurations. - * Return %SELABEL_SUBSET if @h1 is a subset of @h2, %SELABEL_EQUAL - * if @h1 is identical to @h2, %SELABEL_SUPERSET if @h1 is a superset - * of @h2, and %SELABEL_INCOMPARABLE if @h1 and @h2 are incomparable. - */ -enum selabel_cmp_result selabel_cmp(struct selabel_handle *h1, - struct selabel_handle *h2); - -/** - * selabel_stats - log labeling operation statistics. - * @handle: specifies backend instance to query - * - * Log a message with information about the number of queries performed, - * number of unused matching entries, or other operational statistics. - * Message is backend-specific, some backends may not output a message. - */ -void selabel_stats(struct selabel_handle *handle); - -/* - * Type codes used by specific backends - */ - -/* X backend */ -#define SELABEL_X_PROP 1 -#define SELABEL_X_EXT 2 -#define SELABEL_X_CLIENT 3 -#define SELABEL_X_EVENT 4 -#define SELABEL_X_SELN 5 -#define SELABEL_X_POLYPROP 6 -#define SELABEL_X_POLYSELN 7 - -/* DB backend */ -#define SELABEL_DB_DATABASE 1 -#define SELABEL_DB_SCHEMA 2 -#define SELABEL_DB_TABLE 3 -#define SELABEL_DB_COLUMN 4 -#define SELABEL_DB_SEQUENCE 5 -#define SELABEL_DB_VIEW 6 -#define SELABEL_DB_PROCEDURE 7 -#define SELABEL_DB_BLOB 8 -#define SELABEL_DB_TUPLE 9 -#define SELABEL_DB_LANGUAGE 10 - -#ifdef __cplusplus -} -#endif -#endif /* _SELABEL_H_ */ diff --git a/include/selinux/selinux.h b/include/selinux/selinux.h deleted file mode 100644 index 8827da8..0000000 --- a/include/selinux/selinux.h +++ /dev/null @@ -1,291 +0,0 @@ -#ifndef _SELINUX_H_ -#define _SELINUX_H_ - -#include <sys/types.h> -#include <stdarg.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/* Return 1 if we are running on a SELinux kernel, or 0 if not or -1 if we get an error. */ -extern int is_selinux_enabled(void); -/* Return 1 if we are running on a SELinux MLS kernel, or 0 otherwise. */ -extern int is_selinux_mls_enabled(void); - -/* No longer used; here for compatibility with legacy callers. */ -typedef char *security_context_t; - -/* Free the memory allocated for a context by any of the below get* calls. */ -extern void freecon(char * con); - -/* Free the memory allocated for a context array by security_compute_user. */ -extern void freeconary(char ** con); - -/* Wrappers for the /proc/pid/attr API. */ - -/* Get current context, and set *con to refer to it. - Caller must free via freecon. */ -extern int getcon(char ** con); - -/* Set the current security context to con. - Note that use of this function requires that the entire application - be trusted to maintain any desired separation between the old and new - security contexts, unlike exec-based transitions performed via setexeccon. - When possible, decompose your application and use setexeccon()+execve() - instead. Note that the application may lose access to its open descriptors - as a result of a setcon() unless policy allows it to use descriptors opened - by the old context. */ -extern int setcon(const char * con); - -/* Get context of process identified by pid, and - set *con to refer to it. Caller must free via freecon. */ -extern int getpidcon(pid_t pid, char ** con); - -/* Get previous context (prior to last exec), and set *con to refer to it. - Caller must free via freecon. */ -extern int getprevcon(char ** con); - -/* Get exec context, and set *con to refer to it. - Sets *con to NULL if no exec context has been set, i.e. using default. - If non-NULL, caller must free via freecon. */ -extern int getexeccon(char ** con); - -/* Set exec security context for the next execve. - Call with NULL if you want to reset to the default. */ -extern int setexeccon(const char * con); - -/* Get fscreate context, and set *con to refer to it. - Sets *con to NULL if no fs create context has been set, i.e. using default. - If non-NULL, caller must free via freecon. */ -extern int getfscreatecon(char ** con); - -/* Set the fscreate security context for subsequent file creations. - Call with NULL if you want to reset to the default. */ -extern int setfscreatecon(const char * context); - -/* Get keycreate context, and set *con to refer to it. - Sets *con to NULL if no key create context has been set, i.e. using default. - If non-NULL, caller must free via freecon. */ -extern int getkeycreatecon(char ** con); - -/* Set the keycreate security context for subsequent key creations. - Call with NULL if you want to reset to the default. */ -extern int setkeycreatecon(const char * context); - -/* Get sockcreate context, and set *con to refer to it. - Sets *con to NULL if no socket create context has been set, i.e. using default. - If non-NULL, caller must free via freecon. */ -extern int getsockcreatecon(char ** con); - -/* Set the sockcreate security context for subsequent socket creations. - Call with NULL if you want to reset to the default. */ -extern int setsockcreatecon(const char * context); - -/* Wrappers for the xattr API. */ - -/* Get file context, and set *con to refer to it. - Caller must free via freecon. */ -extern int getfilecon(const char *path, char ** con); -extern int lgetfilecon(const char *path, char ** con); -extern int fgetfilecon(int fd, char ** con); - -/* Set file context */ -extern int setfilecon(const char *path, const char *con); -extern int lsetfilecon(const char *path, const char *con); -extern int fsetfilecon(int fd, const char *con); - -/* Wrappers for the socket API */ - -/* Get context of peer socket, and set *con to refer to it. - Caller must free via freecon. */ -extern int getpeercon(int fd, char ** con); - -/* Wrappers for the selinuxfs (policy) API. */ - -typedef unsigned int access_vector_t; -typedef unsigned short security_class_t; - -struct av_decision { - access_vector_t allowed; - access_vector_t decided; - access_vector_t auditallow; - access_vector_t auditdeny; - unsigned int seqno; - unsigned int flags; -}; - -/* Definitions of av_decision.flags */ -#define SELINUX_AVD_FLAGS_PERMISSIVE 0x0001 - -/* Structure for passing options, used by AVC and label subsystems */ -struct selinux_opt { - int type; - const char *value; -}; - -/* Callback facilities */ -union selinux_callback { - /* log the printf-style format and arguments, - with the type code indicating the type of message */ - int -#ifdef __GNUC__ -__attribute__ ((format(printf, 2, 3))) -#endif - (*func_log) (int type, const char *fmt, ...); - /* store a string representation of auditdata (corresponding - to the given security class) into msgbuf. */ - int (*func_audit) (void *auditdata, security_class_t cls, - char *msgbuf, size_t msgbufsize); - /* validate the supplied context, modifying if necessary */ - int (*func_validate) (char **ctx); - /* netlink callback for setenforce message */ - int (*func_setenforce) (int enforcing); - /* netlink callback for policyload message */ - int (*func_policyload) (int seqno); -}; - -#define SELINUX_CB_LOG 0 -#define SELINUX_CB_AUDIT 1 -#define SELINUX_CB_VALIDATE 2 -#define SELINUX_CB_SETENFORCE 3 -#define SELINUX_CB_POLICYLOAD 4 - -extern union selinux_callback selinux_get_callback(int type); -extern void selinux_set_callback(int type, union selinux_callback cb); - - /* Logging type codes, passed to the logging callback */ -#define SELINUX_ERROR 0 -#define SELINUX_WARNING 1 -#define SELINUX_INFO 2 -#define SELINUX_AVC 3 - -/* Compute an access decision. */ -extern int security_compute_av(const char * scon, - const char * tcon, - security_class_t tclass, - access_vector_t requested, - struct av_decision *avd); - -/* Compute a labeling decision and set *newcon to refer to it. - Caller must free via freecon. */ -extern int security_compute_create(const char * scon, - const char * tcon, - security_class_t tclass, - char ** newcon); - -/* Compute a relabeling decision and set *newcon to refer to it. - Caller must free via freecon. */ -extern int security_compute_relabel(const char * scon, - const char * tcon, - security_class_t tclass, - char ** newcon); - -/* Compute a polyinstantiation member decision and set *newcon to refer to it. - Caller must free via freecon. */ -extern int security_compute_member(const char * scon, - const char * tcon, - security_class_t tclass, - char ** newcon); - -/* Compute the set of reachable user contexts and set *con to refer to - the NULL-terminated array of contexts. Caller must free via freeconary. */ -extern int security_compute_user(const char * scon, - const char *username, - char *** con); - -/* Load a policy configuration. */ -extern int security_load_policy(void *data, size_t len); - -/* Get the context of an initial kernel security identifier by name. - Caller must free via freecon */ -extern int security_get_initial_context(const char *name, - char ** con); - -/* Translate boolean strict to name value pair. */ -typedef struct { - const char *name; - int value; -} SELboolean; -/* save a list of booleans in a single transaction. */ -extern int security_set_boolean_list(size_t boolcnt, - SELboolean * const boollist, int permanent); - -/* Check the validity of a security context. */ -extern int security_check_context(const char * con); - -/* Canonicalize a security context. */ -extern int security_canonicalize_context(const char * con, - char ** canoncon); - -/* Get the enforce flag value. */ -extern int security_getenforce(void); - -/* Set the enforce flag value. */ -extern int security_setenforce(int value); - -/* Get the behavior for undefined classes/permissions */ -extern int security_deny_unknown(void); - -/* Disable SELinux at runtime (must be done prior to initial policy load). */ -extern int security_disable(void); - -/* Get the policy version number. */ -extern int security_policyvers(void); - -/* Get the boolean names */ -extern int security_get_boolean_names(char ***names, int *len); - -/* Get the pending value for the boolean */ -extern int security_get_boolean_pending(const char *name); - -/* Get the active value for the boolean */ -extern int security_get_boolean_active(const char *name); - -/* Set the pending value for the boolean */ -extern int security_set_boolean(const char *name, int value); - -/* Commit the pending values for the booleans */ -extern int security_commit_booleans(void); - -/* Userspace class mapping support */ -struct security_class_mapping { - const char *name; - const char *perms[sizeof(access_vector_t) * 8 + 1]; -}; - -extern int selinux_set_mapping(struct security_class_mapping *map); - -/* Common helpers */ - -/* Convert between security class values and string names */ -extern security_class_t string_to_security_class(const char *name); -extern const char *security_class_to_string(security_class_t cls); - -/* Convert between individual access vector permissions and string names */ -extern const char *security_av_perm_to_string(security_class_t tclass, - access_vector_t perm); -extern access_vector_t string_to_av_perm(security_class_t tclass, - const char *name); - -/* Returns an access vector in a string representation. User must free the - * returned string via free(). */ -extern int security_av_string(security_class_t tclass, - access_vector_t av, char **result); - -/* Check permissions and perform appropriate auditing. */ -extern int selinux_check_access(const char * scon, - const char * tcon, - const char *tclass, - const char *perm, void *aux); - -/* Set the path to the selinuxfs mount point explicitly. - Normally, this is determined automatically during libselinux - initialization, but this is not always possible, e.g. for /sbin/init - which performs the initial mount of selinuxfs. */ -void set_selinuxmnt(const char *mnt); - -#ifdef __cplusplus -} -#endif -#endif |