selinux.h 4.4 KB

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