2 * SELinux services exported to the rest of the kernel.
4 * Author: James Morris <jmorris@redhat.com>
6 * Copyright (C) 2005 Red Hat, Inc., James Morris <jmorris@redhat.com>
7 * Copyright (C) 2006 Trusted Computer Solutions, Inc. <dgoeddel@trustedcs.com>
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.
13 #ifndef _LINUX_SELINUX_H
14 #define _LINUX_SELINUX_H
16 struct selinux_audit_rule;
21 #ifdef CONFIG_SECURITY_SELINUX
24 * selinux_audit_rule_init - alloc/init an selinux audit rule structure.
25 * @field: the field this rule refers to
26 * @op: the operater the rule uses
27 * @rulestr: the text "target" of the rule
28 * @rule: pointer to the new rule structure returned via this
30 * Returns 0 if successful, -errno if not. On success, the rule structure
31 * will be allocated internally. The caller must free this structure with
32 * selinux_audit_rule_free() after use.
34 int selinux_audit_rule_init(u32 field, u32 op, char *rulestr,
35 struct selinux_audit_rule **rule);
38 * selinux_audit_rule_free - free an selinux audit rule structure.
39 * @rule: pointer to the audit rule to be freed
41 * This will free all memory associated with the given rule.
42 * If @rule is NULL, no operation is performed.
44 void selinux_audit_rule_free(struct selinux_audit_rule *rule);
47 * selinux_audit_rule_match - determine if a context ID matches a rule.
48 * @ctxid: the context ID to check
49 * @field: the field this rule refers to
50 * @op: the operater the rule uses
51 * @rule: pointer to the audit rule to check against
52 * @actx: the audit context (can be NULL) associated with the check
54 * Returns 1 if the context id matches the rule, 0 if it does not, and
57 int selinux_audit_rule_match(u32 ctxid, u32 field, u32 op,
58 struct selinux_audit_rule *rule,
59 struct audit_context *actx);
62 * selinux_audit_set_callback - set the callback for policy reloads.
63 * @callback: the function to call when the policy is reloaded
65 * This sets the function callback function that will update the rules
66 * upon policy reloads. This callback should rebuild all existing rules
67 * using selinux_audit_rule_init().
69 void selinux_audit_set_callback(int (*callback)(void));
72 * selinux_task_ctxid - determine a context ID for a process.
73 * @tsk: the task object
74 * @ctxid: ID value returned via this
76 * On return, ctxid will contain an ID for the context. This value
77 * should only be used opaquely.
79 void selinux_task_ctxid(struct task_struct *tsk, u32 *ctxid);
82 * selinux_ctxid_to_string - map a security context ID to a string
83 * @ctxid: security context ID to be converted.
84 * @ctx: address of context string to be returned
85 * @ctxlen: length of returned context string.
87 * Returns 0 if successful, -errno if not. On success, the context
88 * string will be allocated internally, and the caller must call
89 * kfree() on it after use.
91 int selinux_ctxid_to_string(u32 ctxid, char **ctx, u32 *ctxlen);
94 * selinux_get_inode_sid - get the inode's security context ID
95 * @inode: inode structure to get the sid from.
96 * @sid: pointer to security context ID to be filled in.
100 void selinux_get_inode_sid(const struct inode *inode, u32 *sid);
103 * selinux_get_ipc_sid - get the ipc security context ID
104 * @ipcp: ipc structure to get the sid from.
105 * @sid: pointer to security context ID to be filled in.
109 void selinux_get_ipc_sid(const struct kern_ipc_perm *ipcp, u32 *sid);
113 static inline int selinux_audit_rule_init(u32 field, u32 op,
115 struct selinux_audit_rule **rule)
120 static inline void selinux_audit_rule_free(struct selinux_audit_rule *rule)
125 static inline int selinux_audit_rule_match(u32 ctxid, u32 field, u32 op,
126 struct selinux_audit_rule *rule,
127 struct audit_context *actx)
132 static inline void selinux_audit_set_callback(int (*callback)(void))
137 static inline void selinux_task_ctxid(struct task_struct *tsk, u32 *ctxid)
142 static inline int selinux_ctxid_to_string(u32 ctxid, char **ctx, u32 *ctxlen)
149 static inline void selinux_get_inode_sid(const struct inode *inode, u32 *sid)
154 static inline void selinux_get_ipc_sid(const struct kern_ipc_perm *ipcp, u32 *sid)
159 #endif /* CONFIG_SECURITY_SELINUX */
161 #endif /* _LINUX_SELINUX_H */