2 * A policy database (policydb) specifies the
3 * configuration data for the security policy.
5 * Author : Stephen Smalley, <sds@epoch.ncsc.mil>
8 /* Updated: Frank Mayer <mayerf@tresys.com> and Karl MacMillan <kmacmillan@tresys.com>
10 * Added conditional policy language extensions
12 * Copyright (C) 2003 - 2004 Tresys Technology, LLC
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, version 2.
18 #ifndef _SS_POLICYDB_H_
19 #define _SS_POLICYDB_H_
25 #include "constraint.h"
28 * A datum type is defined for each kind of symbol
29 * in the configuration data: individual permissions,
30 * common prefixes for access vectors, classes,
31 * users, roles, types, sensitivities, categories, etc.
34 /* Permission attributes */
36 u32 value; /* permission bit + 1 */
37 #ifdef CONFIG_SECURITY_SELINUX_MLS
38 #define MLS_BASE_READ 1 /* MLS base permission `read' */
39 #define MLS_BASE_WRITE 2 /* MLS base permission `write' */
40 #define MLS_BASE_READBY 4 /* MLS base permission `readby' */
41 #define MLS_BASE_WRITEBY 8 /* MLS base permission `writeby' */
42 u32 base_perms; /* MLS base permission mask */
46 /* Attributes of a common prefix for access vectors */
48 u32 value; /* internal common value */
49 struct symtab permissions; /* common permissions */
52 /* Class attributes */
54 u32 value; /* class value */
55 char *comkey; /* common name */
56 struct common_datum *comdatum; /* common datum */
57 struct symtab permissions; /* class-specific permission symbol table */
58 struct constraint_node *constraints; /* constraints on class permissions */
59 #ifdef CONFIG_SECURITY_SELINUX_MLS
60 struct mls_perms mlsperms; /* MLS base permission masks */
66 u32 value; /* internal role value */
67 struct ebitmap dominates; /* set of roles dominated by this role */
68 struct ebitmap types; /* set of authorized types for role */
72 u32 role; /* current role */
73 u32 type; /* program executable type */
74 u32 new_role; /* new role */
75 struct role_trans *next;
79 u32 role; /* current role */
80 u32 new_role; /* new role */
81 struct role_allow *next;
86 u32 value; /* internal type value */
87 unsigned char primary; /* primary name? */
92 u32 value; /* internal user value */
93 struct ebitmap roles; /* set of authorized roles for user */
94 #ifdef CONFIG_SECURITY_SELINUX_MLS
95 struct mls_range_list *ranges; /* list of authorized MLS ranges for user */
100 #ifdef CONFIG_SECURITY_SELINUX_MLS
101 /* Sensitivity attributes */
103 struct mls_level *level; /* sensitivity and associated categories */
104 unsigned char isalias; /* is this sensitivity an alias for another? */
107 /* Category attributes */
109 u32 value; /* internal category bit + 1 */
110 unsigned char isalias; /* is this category an alias for another? */
114 /* Boolean data type */
115 struct cond_bool_datum {
116 __u32 value; /* internal type value */
123 * The configuration data includes security contexts for
124 * initial SIDs, unlabeled file systems, TCP and UDP port numbers,
125 * network interfaces, and nodes. This structure stores the
126 * relevant data for one such entry. Entries of the same kind
127 * (e.g. all initial SIDs) are linked together into a list.
131 char *name; /* name of initial SID, fs, netif, fstype, path */
136 } port; /* TCP or UDP port information */
140 } node; /* node information */
144 } node6; /* IPv6 node information */
147 u32 sclass; /* security class for genfs */
148 u32 behavior; /* labeling behavior for fs_use */
150 struct context context[2]; /* security context(s) */
151 u32 sid[2]; /* SID(s) */
152 struct ocontext *next;
157 struct ocontext *head;
161 /* symbol table array indices */
162 #define SYM_COMMONS 0
163 #define SYM_CLASSES 1
167 #ifdef CONFIG_SECURITY_SELINUX_MLS
177 /* object context array indices */
178 #define OCON_ISID 0 /* initial SIDs */
179 #define OCON_FS 1 /* unlabeled file systems */
180 #define OCON_PORT 2 /* TCP and UDP port numbers */
181 #define OCON_NETIF 3 /* network interfaces */
182 #define OCON_NODE 4 /* nodes */
183 #define OCON_FSUSE 5 /* fs_use */
184 #define OCON_NODE6 6 /* IPv6 nodes */
187 /* The policy database */
190 struct symtab symtab[SYM_NUM];
191 #define p_commons symtab[SYM_COMMONS]
192 #define p_classes symtab[SYM_CLASSES]
193 #define p_roles symtab[SYM_ROLES]
194 #define p_types symtab[SYM_TYPES]
195 #define p_users symtab[SYM_USERS]
196 #define p_levels symtab[SYM_LEVELS]
197 #define p_cats symtab[SYM_CATS]
198 #define p_bools symtab[SYM_BOOLS]
200 /* symbol names indexed by (value - 1) */
201 char **sym_val_to_name[SYM_NUM];
202 #define p_common_val_to_name sym_val_to_name[SYM_COMMONS]
203 #define p_class_val_to_name sym_val_to_name[SYM_CLASSES]
204 #define p_role_val_to_name sym_val_to_name[SYM_ROLES]
205 #define p_type_val_to_name sym_val_to_name[SYM_TYPES]
206 #define p_user_val_to_name sym_val_to_name[SYM_USERS]
207 #define p_sens_val_to_name sym_val_to_name[SYM_LEVELS]
208 #define p_cat_val_to_name sym_val_to_name[SYM_CATS]
209 #define p_bool_val_to_name sym_val_to_name[SYM_BOOLS]
211 /* class, role, and user attributes indexed by (value - 1) */
212 struct class_datum **class_val_to_struct;
213 struct role_datum **role_val_to_struct;
214 struct user_datum **user_val_to_struct;
216 /* type enforcement access vectors and transitions */
217 struct avtab te_avtab;
219 /* role transitions */
220 struct role_trans *role_tr;
222 /* bools indexed by (value - 1) */
223 struct cond_bool_datum **bool_val_to_struct;
224 /* type enforcement conditional access vectors and transitions */
225 struct avtab te_cond_avtab;
226 /* linked list indexing te_cond_avtab by conditional */
227 struct cond_node* cond_list;
230 struct role_allow *role_allow;
232 /* security contexts of initial SIDs, unlabeled file systems,
233 TCP or UDP port numbers, network interfaces and nodes */
234 struct ocontext *ocontexts[OCON_NUM];
236 /* security contexts for files in filesystems that cannot support
237 a persistent label mapping or use another
238 fixed labeling behavior. */
241 #ifdef CONFIG_SECURITY_SELINUX_MLS
242 /* number of legitimate MLS levels */
245 struct ebitmap trustedreaders;
246 struct ebitmap trustedwriters;
247 struct ebitmap trustedobjects;
251 extern int policydb_init(struct policydb *p);
252 extern int policydb_index_classes(struct policydb *p);
253 extern int policydb_index_others(struct policydb *p);
254 extern int constraint_expr_destroy(struct constraint_expr *expr);
255 extern void policydb_destroy(struct policydb *p);
256 extern int policydb_load_isids(struct policydb *p, struct sidtab *s);
257 extern int policydb_context_isvalid(struct policydb *p, struct context *c);
258 extern int policydb_read(struct policydb *p, void *fp);
260 #define PERM_SYMTAB_SIZE 32
262 #define POLICYDB_CONFIG_MLS 1
264 #define OBJECT_R "object_r"
265 #define OBJECT_R_VAL 1
267 #define POLICYDB_MAGIC SELINUX_MAGIC
268 #define POLICYDB_STRING "SE Linux"
275 static inline void *next_entry(struct policy_file *fp, size_t bytes)
288 #endif /* _SS_POLICYDB_H_ */