selinux.h 4.8 KB

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