services.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /* -*- linux-c -*- */
  2. /*
  3. * Author : Stephen Smalley, <sds@epoch.ncsc.mil>
  4. */
  5. #ifndef _SEPOL_POLICYDB_SERVICES_H_
  6. #define _SEPOL_POLICYDB_SERVICES_H_
  7. /*
  8. * Security server interface.
  9. */
  10. #include <sepol/policydb/flask_types.h>
  11. #include <sepol/policydb/policydb.h>
  12. #include <stddef.h>
  13. /* Set the policydb and sidtab structures to be used by
  14. the service functions. If not set, then these default
  15. to private structures within libsepol that can only be
  16. initialized and accessed via the service functions themselves.
  17. Setting the structures explicitly allows a program to directly
  18. manipulate them, e.g. checkpolicy populates the structures directly
  19. from a source policy rather than from a binary policy. */
  20. extern int sepol_set_policydb(policydb_t * p);
  21. extern int sepol_set_sidtab(sidtab_t * s);
  22. /* Modify a policydb for boolean settings. */
  23. int sepol_genbools_policydb(policydb_t * policydb, const char *booleans);
  24. /* Modify a policydb for user settings. */
  25. int sepol_genusers_policydb(policydb_t * policydb, const char *usersdir);
  26. /* Load the security policy. This initializes the policydb
  27. and sidtab based on the provided binary policy. */
  28. extern int sepol_load_policy(void *data, size_t len);
  29. /*
  30. * Compute access vectors based on a SID pair for
  31. * the permissions in a particular class.
  32. */
  33. extern int sepol_compute_av(sepol_security_id_t ssid, /* IN */
  34. sepol_security_id_t tsid, /* IN */
  35. sepol_security_class_t tclass, /* IN */
  36. sepol_access_vector_t requested, /* IN */
  37. struct sepol_av_decision *avd); /* OUT */
  38. /* Same as above, but also return the reason(s) for any
  39. denials of the requested permissions. */
  40. #define SEPOL_COMPUTEAV_TE 1
  41. #define SEPOL_COMPUTEAV_CONS 2
  42. #define SEPOL_COMPUTEAV_RBAC 4
  43. extern int sepol_compute_av_reason(sepol_security_id_t ssid,
  44. sepol_security_id_t tsid,
  45. sepol_security_class_t tclass,
  46. sepol_access_vector_t requested,
  47. struct sepol_av_decision *avd,
  48. unsigned int *reason);
  49. /*
  50. * Compute a SID to use for labeling a new object in the
  51. * class `tclass' based on a SID pair.
  52. */
  53. extern int sepol_transition_sid(sepol_security_id_t ssid, /* IN */
  54. sepol_security_id_t tsid, /* IN */
  55. sepol_security_class_t tclass, /* IN */
  56. sepol_security_id_t * out_sid); /* OUT */
  57. /*
  58. * Compute a SID to use when selecting a member of a
  59. * polyinstantiated object of class `tclass' based on
  60. * a SID pair.
  61. */
  62. extern int sepol_member_sid(sepol_security_id_t ssid, /* IN */
  63. sepol_security_id_t tsid, /* IN */
  64. sepol_security_class_t tclass, /* IN */
  65. sepol_security_id_t * out_sid); /* OUT */
  66. /*
  67. * Compute a SID to use for relabeling an object in the
  68. * class `tclass' based on a SID pair.
  69. */
  70. extern int sepol_change_sid(sepol_security_id_t ssid, /* IN */
  71. sepol_security_id_t tsid, /* IN */
  72. sepol_security_class_t tclass, /* IN */
  73. sepol_security_id_t * out_sid); /* OUT */
  74. /*
  75. * Write the security context string representation of
  76. * the context associated with `sid' into a dynamically
  77. * allocated string of the correct size. Set `*scontext'
  78. * to point to this string and set `*scontext_len' to
  79. * the length of the string.
  80. */
  81. extern int sepol_sid_to_context(sepol_security_id_t sid, /* IN */
  82. sepol_security_context_t * scontext, /* OUT */
  83. size_t * scontext_len); /* OUT */
  84. /*
  85. * Return a SID associated with the security context that
  86. * has the string representation specified by `scontext'.
  87. */
  88. extern int sepol_context_to_sid(const sepol_security_context_t scontext, /* IN */
  89. size_t scontext_len, /* IN */
  90. sepol_security_id_t * out_sid); /* OUT */
  91. /*
  92. * Generate the set of SIDs for legal security contexts
  93. * for a given user that can be reached by `fromsid'.
  94. * Set `*sids' to point to a dynamically allocated
  95. * array containing the set of SIDs. Set `*nel' to the
  96. * number of elements in the array.
  97. */
  98. extern int sepol_get_user_sids(sepol_security_id_t callsid,
  99. char *username,
  100. sepol_security_id_t ** sids, uint32_t * nel);
  101. /*
  102. * Return the SIDs to use for an unlabeled file system
  103. * that is being mounted from the device with the
  104. * the kdevname `name'. The `fs_sid' SID is returned for
  105. * the file system and the `file_sid' SID is returned
  106. * for all files within that file system.
  107. */
  108. extern int sepol_fs_sid(char *dev, /* IN */
  109. sepol_security_id_t * fs_sid, /* OUT */
  110. sepol_security_id_t * file_sid); /* OUT */
  111. /*
  112. * Return the SID of the port specified by
  113. * `domain', `type', `protocol', and `port'.
  114. */
  115. extern int sepol_port_sid(uint16_t domain,
  116. uint16_t type,
  117. uint8_t protocol,
  118. uint16_t port, sepol_security_id_t * out_sid);
  119. /*
  120. * Return the SIDs to use for a network interface
  121. * with the name `name'. The `if_sid' SID is returned for
  122. * the interface and the `msg_sid' SID is returned as
  123. * the default SID for messages received on the
  124. * interface.
  125. */
  126. extern int sepol_netif_sid(char *name,
  127. sepol_security_id_t * if_sid,
  128. sepol_security_id_t * msg_sid);
  129. /*
  130. * Return the SID of the node specified by the address
  131. * `addr' where `addrlen' is the length of the address
  132. * in bytes and `domain' is the communications domain or
  133. * address family in which the address should be interpreted.
  134. */
  135. extern int sepol_node_sid(uint16_t domain,
  136. void *addr,
  137. size_t addrlen, sepol_security_id_t * out_sid);
  138. /*
  139. * Return a value indicating how to handle labeling for the
  140. * the specified filesystem type, and optionally return a SID
  141. * for the filesystem object.
  142. */
  143. #define SECURITY_FS_USE_XATTR 1 /* use xattr */
  144. #define SECURITY_FS_USE_TRANS 2 /* use transition SIDs, e.g. devpts/tmpfs */
  145. #define SECURITY_FS_USE_TASK 3 /* use task SIDs, e.g. pipefs/sockfs */
  146. #define SECURITY_FS_USE_GENFS 4 /* use the genfs support */
  147. #define SECURITY_FS_USE_NONE 5 /* no labeling support */
  148. extern int sepol_fs_use(const char *fstype, /* IN */
  149. unsigned int *behavior, /* OUT */
  150. sepol_security_id_t * sid); /* OUT */
  151. /*
  152. * Return the SID to use for a file in a filesystem
  153. * that cannot support a persistent label mapping or use another
  154. * fixed labeling behavior like transition SIDs or task SIDs.
  155. */
  156. extern int sepol_genfs_sid(const char *fstype, /* IN */
  157. char *name, /* IN */
  158. sepol_security_class_t sclass, /* IN */
  159. sepol_security_id_t * sid); /* OUT */
  160. #endif