16cd6a6acSopenharmony_ci 26cd6a6acSopenharmony_ci/* -*- linux-c -*- */ 36cd6a6acSopenharmony_ci 46cd6a6acSopenharmony_ci/* 56cd6a6acSopenharmony_ci * Author : Stephen Smalley, <sds@tycho.nsa.gov> 66cd6a6acSopenharmony_ci */ 76cd6a6acSopenharmony_ci 86cd6a6acSopenharmony_ci#ifndef _SEPOL_POLICYDB_SERVICES_H_ 96cd6a6acSopenharmony_ci#define _SEPOL_POLICYDB_SERVICES_H_ 106cd6a6acSopenharmony_ci 116cd6a6acSopenharmony_ci/* 126cd6a6acSopenharmony_ci * Security server interface. 136cd6a6acSopenharmony_ci */ 146cd6a6acSopenharmony_ci 156cd6a6acSopenharmony_ci#include <sepol/policydb/flask_types.h> 166cd6a6acSopenharmony_ci#include <sepol/policydb/policydb.h> 176cd6a6acSopenharmony_ci#include <stddef.h> 186cd6a6acSopenharmony_ci 196cd6a6acSopenharmony_ci#ifdef __cplusplus 206cd6a6acSopenharmony_ciextern "C" { 216cd6a6acSopenharmony_ci#endif 226cd6a6acSopenharmony_ci 236cd6a6acSopenharmony_ci/* Set the policydb and sidtab structures to be used by 246cd6a6acSopenharmony_ci the service functions. If not set, then these default 256cd6a6acSopenharmony_ci to private structures within libsepol that can only be 266cd6a6acSopenharmony_ci initialized and accessed via the service functions themselves. 276cd6a6acSopenharmony_ci Setting the structures explicitly allows a program to directly 286cd6a6acSopenharmony_ci manipulate them, e.g. checkpolicy populates the structures directly 296cd6a6acSopenharmony_ci from a source policy rather than from a binary policy. */ 306cd6a6acSopenharmony_ciextern int sepol_set_policydb(policydb_t * p); 316cd6a6acSopenharmony_ciextern int sepol_set_sidtab(sidtab_t * s); 326cd6a6acSopenharmony_ci 336cd6a6acSopenharmony_ci/* Load the security policy. This initializes the policydb 346cd6a6acSopenharmony_ci and sidtab based on the provided binary policy. */ 356cd6a6acSopenharmony_ciextern int sepol_load_policy(void *data, size_t len); 366cd6a6acSopenharmony_ci 376cd6a6acSopenharmony_ci/* 386cd6a6acSopenharmony_ci * Compute access vectors based on a SID pair for 396cd6a6acSopenharmony_ci * the permissions in a particular class. 406cd6a6acSopenharmony_ci */ 416cd6a6acSopenharmony_ciextern int sepol_compute_av(sepol_security_id_t ssid, /* IN */ 426cd6a6acSopenharmony_ci sepol_security_id_t tsid, /* IN */ 436cd6a6acSopenharmony_ci sepol_security_class_t tclass, /* IN */ 446cd6a6acSopenharmony_ci sepol_access_vector_t requested, /* IN */ 456cd6a6acSopenharmony_ci struct sepol_av_decision *avd); /* OUT */ 466cd6a6acSopenharmony_ci 476cd6a6acSopenharmony_ci/* Same as above, but also return the reason(s) for any 486cd6a6acSopenharmony_ci denials of the requested permissions. */ 496cd6a6acSopenharmony_ci#define SEPOL_COMPUTEAV_TE 0x1U 506cd6a6acSopenharmony_ci#define SEPOL_COMPUTEAV_CONS 0x2U 516cd6a6acSopenharmony_ci#define SEPOL_COMPUTEAV_RBAC 0x4U 526cd6a6acSopenharmony_ci#define SEPOL_COMPUTEAV_BOUNDS 0x8U 536cd6a6acSopenharmony_ciextern int sepol_compute_av_reason(sepol_security_id_t ssid, 546cd6a6acSopenharmony_ci sepol_security_id_t tsid, 556cd6a6acSopenharmony_ci sepol_security_class_t tclass, 566cd6a6acSopenharmony_ci sepol_access_vector_t requested, 576cd6a6acSopenharmony_ci struct sepol_av_decision *avd, 586cd6a6acSopenharmony_ci unsigned int *reason); 596cd6a6acSopenharmony_ci 606cd6a6acSopenharmony_ci/* 616cd6a6acSopenharmony_ci * Same as above, but also returns the constraint expression calculations 626cd6a6acSopenharmony_ci * whether allowed or denied in a buffer. This buffer is allocated by 636cd6a6acSopenharmony_ci * this call and must be free'd by the caller using free(3). The constraint 646cd6a6acSopenharmony_ci * buffer will contain any constraints in infix notation. 656cd6a6acSopenharmony_ci * If the SHOW_GRANTED flag is set it will show granted and denied 666cd6a6acSopenharmony_ci * constraints. The default is to show only denied constraints. 676cd6a6acSopenharmony_ci */ 686cd6a6acSopenharmony_ci#define SHOW_GRANTED 1 696cd6a6acSopenharmony_ciextern int sepol_compute_av_reason_buffer(sepol_security_id_t ssid, 706cd6a6acSopenharmony_ci sepol_security_id_t tsid, 716cd6a6acSopenharmony_ci sepol_security_class_t tclass, 726cd6a6acSopenharmony_ci sepol_access_vector_t requested, 736cd6a6acSopenharmony_ci struct sepol_av_decision *avd, 746cd6a6acSopenharmony_ci unsigned int *reason, 756cd6a6acSopenharmony_ci char **reason_buf, 766cd6a6acSopenharmony_ci unsigned int flags); 776cd6a6acSopenharmony_ci 786cd6a6acSopenharmony_ci/* 796cd6a6acSopenharmony_ci * Returns the mls/validatetrans constraint expression calculations in 806cd6a6acSopenharmony_ci * a buffer that must be free'd by the caller using free(3). 816cd6a6acSopenharmony_ci * If the SHOW_GRANTED flag is set it will show granted and denied 826cd6a6acSopenharmony_ci * mls/validatetrans (the default is to show only those denied). 836cd6a6acSopenharmony_ci */ 846cd6a6acSopenharmony_ciextern int sepol_validate_transition_reason_buffer(sepol_security_id_t oldsid, 856cd6a6acSopenharmony_ci sepol_security_id_t newsid, 866cd6a6acSopenharmony_ci sepol_security_id_t tasksid, 876cd6a6acSopenharmony_ci sepol_security_class_t tclass, 886cd6a6acSopenharmony_ci char **reason_buf, 896cd6a6acSopenharmony_ci unsigned int flags); 906cd6a6acSopenharmony_ci 916cd6a6acSopenharmony_ci/* 926cd6a6acSopenharmony_ci * Return a class ID associated with the class string representation 936cd6a6acSopenharmony_ci * specified by `class_name'. 946cd6a6acSopenharmony_ci */ 956cd6a6acSopenharmony_ciextern int sepol_string_to_security_class(const char *class_name, 966cd6a6acSopenharmony_ci sepol_security_class_t *tclass); 976cd6a6acSopenharmony_ci 986cd6a6acSopenharmony_ci/* 996cd6a6acSopenharmony_ci * Return a permission av bit associated with tclass and the string 1006cd6a6acSopenharmony_ci * representation of the `perm_name'. 1016cd6a6acSopenharmony_ci */ 1026cd6a6acSopenharmony_ciextern int sepol_string_to_av_perm(sepol_security_class_t tclass, 1036cd6a6acSopenharmony_ci const char *perm_name, 1046cd6a6acSopenharmony_ci sepol_access_vector_t *av); 1056cd6a6acSopenharmony_ci 1066cd6a6acSopenharmony_ci/* 1076cd6a6acSopenharmony_ci * Return a string representation of the permission av bit associated with 1086cd6a6acSopenharmony_ci * tclass. 1096cd6a6acSopenharmony_ci * Returns a pointer to an internal buffer, overridden by the next call to 1106cd6a6acSopenharmony_ci * this function or sepol_av_to_string(). 1116cd6a6acSopenharmony_ci */ 1126cd6a6acSopenharmony_ci extern const char *sepol_av_perm_to_string(sepol_security_class_t tclass, 1136cd6a6acSopenharmony_ci sepol_access_vector_t av); 1146cd6a6acSopenharmony_ci 1156cd6a6acSopenharmony_ci/* 1166cd6a6acSopenharmony_ci * Compute a SID to use for labeling a new object in the 1176cd6a6acSopenharmony_ci * class `tclass' based on a SID pair. 1186cd6a6acSopenharmony_ci */ 1196cd6a6acSopenharmony_ciextern int sepol_transition_sid(sepol_security_id_t ssid, /* IN */ 1206cd6a6acSopenharmony_ci sepol_security_id_t tsid, /* IN */ 1216cd6a6acSopenharmony_ci sepol_security_class_t tclass, /* IN */ 1226cd6a6acSopenharmony_ci sepol_security_id_t * out_sid); /* OUT */ 1236cd6a6acSopenharmony_ci 1246cd6a6acSopenharmony_ci/* 1256cd6a6acSopenharmony_ci * Compute a SID to use when selecting a member of a 1266cd6a6acSopenharmony_ci * polyinstantiated object of class `tclass' based on 1276cd6a6acSopenharmony_ci * a SID pair. 1286cd6a6acSopenharmony_ci */ 1296cd6a6acSopenharmony_ciextern int sepol_member_sid(sepol_security_id_t ssid, /* IN */ 1306cd6a6acSopenharmony_ci sepol_security_id_t tsid, /* IN */ 1316cd6a6acSopenharmony_ci sepol_security_class_t tclass, /* IN */ 1326cd6a6acSopenharmony_ci sepol_security_id_t * out_sid); /* OUT */ 1336cd6a6acSopenharmony_ci 1346cd6a6acSopenharmony_ci/* 1356cd6a6acSopenharmony_ci * Compute a SID to use for relabeling an object in the 1366cd6a6acSopenharmony_ci * class `tclass' based on a SID pair. 1376cd6a6acSopenharmony_ci */ 1386cd6a6acSopenharmony_ciextern int sepol_change_sid(sepol_security_id_t ssid, /* IN */ 1396cd6a6acSopenharmony_ci sepol_security_id_t tsid, /* IN */ 1406cd6a6acSopenharmony_ci sepol_security_class_t tclass, /* IN */ 1416cd6a6acSopenharmony_ci sepol_security_id_t * out_sid); /* OUT */ 1426cd6a6acSopenharmony_ci 1436cd6a6acSopenharmony_ci/* 1446cd6a6acSopenharmony_ci * Write the security context string representation of 1456cd6a6acSopenharmony_ci * the context associated with `sid' into a dynamically 1466cd6a6acSopenharmony_ci * allocated string of the correct size. Set `*scontext' 1476cd6a6acSopenharmony_ci * to point to this string and set `*scontext_len' to 1486cd6a6acSopenharmony_ci * the length of the string. 1496cd6a6acSopenharmony_ci */ 1506cd6a6acSopenharmony_ciextern int sepol_sid_to_context(sepol_security_id_t sid, /* IN */ 1516cd6a6acSopenharmony_ci sepol_security_context_t * scontext, /* OUT */ 1526cd6a6acSopenharmony_ci size_t * scontext_len); /* OUT */ 1536cd6a6acSopenharmony_ci 1546cd6a6acSopenharmony_ci/* 1556cd6a6acSopenharmony_ci * Return a SID associated with the security context that 1566cd6a6acSopenharmony_ci * has the string representation specified by `scontext'. 1576cd6a6acSopenharmony_ci */ 1586cd6a6acSopenharmony_ciextern int sepol_context_to_sid(sepol_const_security_context_t scontext, /* IN */ 1596cd6a6acSopenharmony_ci size_t scontext_len, /* IN */ 1606cd6a6acSopenharmony_ci sepol_security_id_t * out_sid); /* OUT */ 1616cd6a6acSopenharmony_ci 1626cd6a6acSopenharmony_ci/* 1636cd6a6acSopenharmony_ci * Generate the set of SIDs for legal security contexts 1646cd6a6acSopenharmony_ci * for a given user that can be reached by `fromsid'. 1656cd6a6acSopenharmony_ci * Set `*sids' to point to a dynamically allocated 1666cd6a6acSopenharmony_ci * array containing the set of SIDs. Set `*nel' to the 1676cd6a6acSopenharmony_ci * number of elements in the array. 1686cd6a6acSopenharmony_ci */ 1696cd6a6acSopenharmony_ciextern int sepol_get_user_sids(sepol_security_id_t callsid, 1706cd6a6acSopenharmony_ci char *username, 1716cd6a6acSopenharmony_ci sepol_security_id_t ** sids, uint32_t * nel); 1726cd6a6acSopenharmony_ci 1736cd6a6acSopenharmony_ci/* 1746cd6a6acSopenharmony_ci * Return the SIDs to use for an unlabeled file system 1756cd6a6acSopenharmony_ci * that is being mounted from the device with the 1766cd6a6acSopenharmony_ci * the kdevname `name'. The `fs_sid' SID is returned for 1776cd6a6acSopenharmony_ci * the file system and the `file_sid' SID is returned 1786cd6a6acSopenharmony_ci * for all files within that file system. 1796cd6a6acSopenharmony_ci */ 1806cd6a6acSopenharmony_ciextern int sepol_fs_sid(char *dev, /* IN */ 1816cd6a6acSopenharmony_ci sepol_security_id_t * fs_sid, /* OUT */ 1826cd6a6acSopenharmony_ci sepol_security_id_t * file_sid); /* OUT */ 1836cd6a6acSopenharmony_ci 1846cd6a6acSopenharmony_ci/* 1856cd6a6acSopenharmony_ci * Return the SID of the port specified by 1866cd6a6acSopenharmony_ci * `domain', `type', `protocol', and `port'. 1876cd6a6acSopenharmony_ci */ 1886cd6a6acSopenharmony_ciextern int sepol_port_sid(uint16_t domain, 1896cd6a6acSopenharmony_ci uint16_t type, 1906cd6a6acSopenharmony_ci uint8_t protocol, 1916cd6a6acSopenharmony_ci uint16_t port, sepol_security_id_t * out_sid); 1926cd6a6acSopenharmony_ci 1936cd6a6acSopenharmony_ci/* 1946cd6a6acSopenharmony_ci * Return the SID of the ibpkey specified by 1956cd6a6acSopenharmony_ci * `subnet prefix', and `pkey'. 1966cd6a6acSopenharmony_ci */ 1976cd6a6acSopenharmony_ciextern int sepol_ibpkey_sid(uint64_t subnet_prefix_p, 1986cd6a6acSopenharmony_ci uint16_t pkey, 1996cd6a6acSopenharmony_ci sepol_security_id_t *out_sid); 2006cd6a6acSopenharmony_ci 2016cd6a6acSopenharmony_ci/* 2026cd6a6acSopenharmony_ci * Return the SID of the ibendport specified by 2036cd6a6acSopenharmony_ci * `dev_name', and `port'. 2046cd6a6acSopenharmony_ci */ 2056cd6a6acSopenharmony_ciextern int sepol_ibendport_sid(char *dev_name, 2066cd6a6acSopenharmony_ci uint8_t port, 2076cd6a6acSopenharmony_ci sepol_security_id_t *out_sid); 2086cd6a6acSopenharmony_ci 2096cd6a6acSopenharmony_ci/* 2106cd6a6acSopenharmony_ci * Return the SIDs to use for a network interface 2116cd6a6acSopenharmony_ci * with the name `name'. The `if_sid' SID is returned for 2126cd6a6acSopenharmony_ci * the interface and the `msg_sid' SID is returned as 2136cd6a6acSopenharmony_ci * the default SID for messages received on the 2146cd6a6acSopenharmony_ci * interface. 2156cd6a6acSopenharmony_ci */ 2166cd6a6acSopenharmony_ciextern int sepol_netif_sid(char *name, 2176cd6a6acSopenharmony_ci sepol_security_id_t * if_sid, 2186cd6a6acSopenharmony_ci sepol_security_id_t * msg_sid); 2196cd6a6acSopenharmony_ci 2206cd6a6acSopenharmony_ci/* 2216cd6a6acSopenharmony_ci * Return the SID of the node specified by the address 2226cd6a6acSopenharmony_ci * `addr' where `addrlen' is the length of the address 2236cd6a6acSopenharmony_ci * in bytes and `domain' is the communications domain or 2246cd6a6acSopenharmony_ci * address family in which the address should be interpreted. 2256cd6a6acSopenharmony_ci */ 2266cd6a6acSopenharmony_ciextern int sepol_node_sid(uint16_t domain, 2276cd6a6acSopenharmony_ci void *addr, 2286cd6a6acSopenharmony_ci size_t addrlen, sepol_security_id_t * out_sid); 2296cd6a6acSopenharmony_ci 2306cd6a6acSopenharmony_ci/* 2316cd6a6acSopenharmony_ci * Return a value indicating how to handle labeling for the 2326cd6a6acSopenharmony_ci * the specified filesystem type, and optionally return a SID 2336cd6a6acSopenharmony_ci * for the filesystem object. 2346cd6a6acSopenharmony_ci */ 2356cd6a6acSopenharmony_ci#define SECURITY_FS_USE_XATTR 1 /* use xattr */ 2366cd6a6acSopenharmony_ci#define SECURITY_FS_USE_TRANS 2 /* use transition SIDs, e.g. devpts/tmpfs */ 2376cd6a6acSopenharmony_ci#define SECURITY_FS_USE_TASK 3 /* use task SIDs, e.g. pipefs/sockfs */ 2386cd6a6acSopenharmony_ci#define SECURITY_FS_USE_GENFS 4 /* use the genfs support */ 2396cd6a6acSopenharmony_ci#define SECURITY_FS_USE_NONE 5 /* no labeling support */ 2406cd6a6acSopenharmony_ciextern int sepol_fs_use(const char *fstype, /* IN */ 2416cd6a6acSopenharmony_ci unsigned int *behavior, /* OUT */ 2426cd6a6acSopenharmony_ci sepol_security_id_t * sid); /* OUT */ 2436cd6a6acSopenharmony_ci 2446cd6a6acSopenharmony_ci/* 2456cd6a6acSopenharmony_ci * Return the SID to use for a file in a filesystem 2466cd6a6acSopenharmony_ci * that cannot support a persistent label mapping or use another 2476cd6a6acSopenharmony_ci * fixed labeling behavior like transition SIDs or task SIDs. 2486cd6a6acSopenharmony_ci */ 2496cd6a6acSopenharmony_ciextern int sepol_genfs_sid(const char *fstype, /* IN */ 2506cd6a6acSopenharmony_ci const char *name, /* IN */ 2516cd6a6acSopenharmony_ci sepol_security_class_t sclass, /* IN */ 2526cd6a6acSopenharmony_ci sepol_security_id_t * sid); /* OUT */ 2536cd6a6acSopenharmony_ci 2546cd6a6acSopenharmony_ci#ifdef __cplusplus 2556cd6a6acSopenharmony_ci} 2566cd6a6acSopenharmony_ci#endif 2576cd6a6acSopenharmony_ci 2586cd6a6acSopenharmony_ci#endif 259