selinux.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * SELinux services exported to the rest of the kernel.
  3. *
  4. * Author: James Morris <jmorris@redhat.com>
  5. *
  6. * Copyright (C) 2005 Red Hat, Inc., James Morris <jmorris@redhat.com>
  7. * Copyright (C) 2006 Trusted Computer Solutions, Inc. <dgoeddel@trustedcs.com>
  8. * Copyright (C) 2006 IBM Corporation, Timothy R. Chavez <tinytim@us.ibm.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2,
  12. * as published by the Free Software Foundation.
  13. */
  14. #ifndef _LINUX_SELINUX_H
  15. #define _LINUX_SELINUX_H
  16. struct selinux_audit_rule;
  17. struct audit_context;
  18. struct inode;
  19. struct kern_ipc_perm;
  20. #ifdef CONFIG_SECURITY_SELINUX
  21. /**
  22. * selinux_audit_rule_init - alloc/init an selinux audit rule structure.
  23. * @field: the field this rule refers to
  24. * @op: the operater the rule uses
  25. * @rulestr: the text "target" of the rule
  26. * @rule: pointer to the new rule structure returned via this
  27. *
  28. * Returns 0 if successful, -errno if not. On success, the rule structure
  29. * will be allocated internally. The caller must free this structure with
  30. * selinux_audit_rule_free() after use.
  31. */
  32. int selinux_audit_rule_init(u32 field, u32 op, char *rulestr,
  33. struct selinux_audit_rule **rule);
  34. /**
  35. * selinux_audit_rule_free - free an selinux audit rule structure.
  36. * @rule: pointer to the audit rule to be freed
  37. *
  38. * This will free all memory associated with the given rule.
  39. * If @rule is NULL, no operation is performed.
  40. */
  41. void selinux_audit_rule_free(struct selinux_audit_rule *rule);
  42. /**
  43. * selinux_audit_rule_match - determine if a context ID matches a rule.
  44. * @ctxid: the context ID to check
  45. * @field: the field this rule refers to
  46. * @op: the operater the rule uses
  47. * @rule: pointer to the audit rule to check against
  48. * @actx: the audit context (can be NULL) associated with the check
  49. *
  50. * Returns 1 if the context id matches the rule, 0 if it does not, and
  51. * -errno on failure.
  52. */
  53. int selinux_audit_rule_match(u32 ctxid, u32 field, u32 op,
  54. struct selinux_audit_rule *rule,
  55. struct audit_context *actx);
  56. /**
  57. * selinux_audit_set_callback - set the callback for policy reloads.
  58. * @callback: the function to call when the policy is reloaded
  59. *
  60. * This sets the function callback function that will update the rules
  61. * upon policy reloads. This callback should rebuild all existing rules
  62. * using selinux_audit_rule_init().
  63. */
  64. void selinux_audit_set_callback(int (*callback)(void));
  65. /**
  66. * selinux_task_ctxid - determine a context ID for a process.
  67. * @tsk: the task object
  68. * @ctxid: ID value returned via this
  69. *
  70. * On return, ctxid will contain an ID for the context. This value
  71. * should only be used opaquely.
  72. */
  73. void selinux_task_ctxid(struct task_struct *tsk, u32 *ctxid);
  74. /**
  75. * selinux_ctxid_to_string - map a security context ID to a string
  76. * @ctxid: security context ID to be converted.
  77. * @ctx: address of context string to be returned
  78. * @ctxlen: length of returned context string.
  79. *
  80. * Returns 0 if successful, -errno if not. On success, the context
  81. * string will be allocated internally, and the caller must call
  82. * kfree() on it after use.
  83. */
  84. int selinux_ctxid_to_string(u32 ctxid, char **ctx, u32 *ctxlen);
  85. /**
  86. * selinux_get_inode_sid - get the inode's security context ID
  87. * @inode: inode structure to get the sid from.
  88. * @sid: pointer to security context ID to be filled in.
  89. *
  90. * Returns nothing
  91. */
  92. void selinux_get_inode_sid(const struct inode *inode, u32 *sid);
  93. /**
  94. * selinux_get_ipc_sid - get the ipc security context ID
  95. * @ipcp: ipc structure to get the sid from.
  96. * @sid: pointer to security context ID to be filled in.
  97. *
  98. * Returns nothing
  99. */
  100. void selinux_get_ipc_sid(const struct kern_ipc_perm *ipcp, u32 *sid);
  101. /**
  102. * selinux_get_task_sid - return the SID of task
  103. * @tsk: the task whose SID will be returned
  104. * @sid: pointer to security context ID to be filled in.
  105. *
  106. * Returns nothing
  107. */
  108. void selinux_get_task_sid(struct task_struct *tsk, u32 *sid);
  109. #else
  110. static inline int selinux_audit_rule_init(u32 field, u32 op,
  111. char *rulestr,
  112. struct selinux_audit_rule **rule)
  113. {
  114. return -ENOTSUPP;
  115. }
  116. static inline void selinux_audit_rule_free(struct selinux_audit_rule *rule)
  117. {
  118. return;
  119. }
  120. static inline int selinux_audit_rule_match(u32 ctxid, u32 field, u32 op,
  121. struct selinux_audit_rule *rule,
  122. struct audit_context *actx)
  123. {
  124. return 0;
  125. }
  126. static inline void selinux_audit_set_callback(int (*callback)(void))
  127. {
  128. return;
  129. }
  130. static inline void selinux_task_ctxid(struct task_struct *tsk, u32 *ctxid)
  131. {
  132. *ctxid = 0;
  133. }
  134. static inline int selinux_ctxid_to_string(u32 ctxid, char **ctx, u32 *ctxlen)
  135. {
  136. *ctx = NULL;
  137. *ctxlen = 0;
  138. return 0;
  139. }
  140. static inline void selinux_get_inode_sid(const struct inode *inode, u32 *sid)
  141. {
  142. *sid = 0;
  143. }
  144. static inline void selinux_get_ipc_sid(const struct kern_ipc_perm *ipcp, u32 *sid)
  145. {
  146. *sid = 0;
  147. }
  148. static inline void selinux_get_task_sid(struct task_struct *tsk, u32 *sid)
  149. {
  150. *sid = 0;
  151. }
  152. #endif /* CONFIG_SECURITY_SELINUX */
  153. #endif /* _LINUX_SELINUX_H */