selinux.h 3.4 KB

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