24b0af1c4cac51b12e187689a6f42539d09e0e41
[deliverable/linux.git] / include / linux / selinux.h
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
17 struct selinux_audit_rule;
18 struct audit_context;
19 struct kern_ipc_perm;
20
21 #ifdef CONFIG_SECURITY_SELINUX
22
23 /**
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
29 *
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.
33 */
34 int selinux_audit_rule_init(u32 field, u32 op, char *rulestr,
35 struct selinux_audit_rule **rule);
36
37 /**
38 * selinux_audit_rule_free - free an selinux audit rule structure.
39 * @rule: pointer to the audit rule to be freed
40 *
41 * This will free all memory associated with the given rule.
42 * If @rule is NULL, no operation is performed.
43 */
44 void selinux_audit_rule_free(struct selinux_audit_rule *rule);
45
46 /**
47 * selinux_audit_rule_match - determine if a context ID matches a rule.
48 * @sid: 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
53 *
54 * Returns 1 if the context id matches the rule, 0 if it does not, and
55 * -errno on failure.
56 */
57 int selinux_audit_rule_match(u32 sid, u32 field, u32 op,
58 struct selinux_audit_rule *rule,
59 struct audit_context *actx);
60
61 /**
62 * selinux_audit_set_callback - set the callback for policy reloads.
63 * @callback: the function to call when the policy is reloaded
64 *
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().
68 */
69 void selinux_audit_set_callback(int (*callback)(void));
70
71 /**
72 * selinux_string_to_sid - map a security context string to a security ID
73 * @str: the security context string to be mapped
74 * @sid: ID value returned via this.
75 *
76 * Returns 0 if successful, with the SID stored in sid. A value
77 * of zero for sid indicates no SID could be determined (but no error
78 * occurred).
79 */
80 int selinux_string_to_sid(char *str, u32 *sid);
81
82 /**
83 * selinux_secmark_relabel_packet_permission - secmark permission check
84 * @sid: SECMARK ID value to be applied to network packet
85 *
86 * Returns 0 if the current task is allowed to set the SECMARK label of
87 * packets with the supplied security ID. Note that it is implicit that
88 * the packet is always being relabeled from the default unlabeled value,
89 * and that the access control decision is made in the AVC.
90 */
91 int selinux_secmark_relabel_packet_permission(u32 sid);
92
93 /**
94 * selinux_secmark_refcount_inc - increments the secmark use counter
95 *
96 * SELinux keeps track of the current SECMARK targets in use so it knows
97 * when to apply SECMARK label access checks to network packets. This
98 * function incements this reference count to indicate that a new SECMARK
99 * target has been configured.
100 */
101 void selinux_secmark_refcount_inc(void);
102
103 /**
104 * selinux_secmark_refcount_dec - decrements the secmark use counter
105 *
106 * SELinux keeps track of the current SECMARK targets in use so it knows
107 * when to apply SECMARK label access checks to network packets. This
108 * function decements this reference count to indicate that one of the
109 * existing SECMARK targets has been removed/flushed.
110 */
111 void selinux_secmark_refcount_dec(void);
112 #else
113
114 static inline int selinux_audit_rule_init(u32 field, u32 op,
115 char *rulestr,
116 struct selinux_audit_rule **rule)
117 {
118 return -EOPNOTSUPP;
119 }
120
121 static inline void selinux_audit_rule_free(struct selinux_audit_rule *rule)
122 {
123 return;
124 }
125
126 static inline int selinux_audit_rule_match(u32 sid, u32 field, u32 op,
127 struct selinux_audit_rule *rule,
128 struct audit_context *actx)
129 {
130 return 0;
131 }
132
133 static inline void selinux_audit_set_callback(int (*callback)(void))
134 {
135 return;
136 }
137
138 static inline int selinux_string_to_sid(const char *str, u32 *sid)
139 {
140 *sid = 0;
141 return 0;
142 }
143
144 static inline int selinux_secmark_relabel_packet_permission(u32 sid)
145 {
146 return 0;
147 }
148
149 static inline void selinux_secmark_refcount_inc(void)
150 {
151 return;
152 }
153
154 static inline void selinux_secmark_refcount_dec(void)
155 {
156 return;
157 }
158
159 #endif /* CONFIG_SECURITY_SELINUX */
160
161 #endif /* _LINUX_SELINUX_H */
This page took 0.032731 seconds and 4 git commands to generate.