開發和下載開源軟體

Browse Subversion Repository

Contents of /trunk/1.5.x/ccs-patch/include/linux/ccs_common.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 502 - (show annotations) (download) (as text)
Tue Sep 25 13:33:45 2007 UTC (16 years, 7 months ago) by kumaneko
File MIME type: text/x-chdr
File size: 17024 byte(s)


1 /*
2 * include/linux/ccs_common.h
3 *
4 * Common functions for SAKURA and TOMOYO.
5 *
6 * Copyright (C) 2005-2007 NTT DATA CORPORATION
7 *
8 * Version: 1.5.0 2007/09/20
9 *
10 * This file is applicable to both 2.4.30 and 2.6.11 and later.
11 * See README.ccs for ChangeLog.
12 *
13 */
14
15 #ifndef _LINUX_CCS_COMMON_H
16 #define _LINUX_CCS_COMMON_H
17
18 #include <linux/string.h>
19 #include <linux/mm.h>
20 #include <linux/utime.h>
21 #include <linux/file.h>
22 #include <linux/smp_lock.h>
23 #include <linux/module.h>
24 #include <linux/init.h>
25 #include <linux/slab.h>
26 #include <linux/poll.h>
27 #include <asm/uaccess.h>
28 #include <stdarg.h>
29 #include <linux/delay.h>
30 #include <linux/version.h>
31 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
32 #include <linux/kmod.h>
33 #endif
34
35 #ifndef __user
36 #define __user
37 #endif
38
39 struct mini_stat {
40 uid_t uid;
41 gid_t gid;
42 ino_t ino;
43 };
44 struct dentry;
45 struct vfsmount;
46 struct obj_info {
47 u8 validate_done;
48 u8 path1_valid;
49 u8 path1_parent_valid;
50 u8 path2_parent_valid;
51 struct dentry *path1_dentry;
52 struct vfsmount *path1_vfsmnt;
53 struct dentry *path2_dentry;
54 struct vfsmount *path2_vfsmnt;
55 struct mini_stat path1_stat;
56 /* I don't handle path2_stat for rename operation. */
57 struct mini_stat path1_parent_stat;
58 struct mini_stat path2_parent_stat;
59 };
60
61 struct path_info {
62 const char *name;
63 u32 hash; /* = full_name_hash(name, strlen(name)) */
64 u16 total_len; /* = strlen(name) */
65 u16 const_len; /* = const_part_length(name) */
66 u8 is_dir; /* = strendswith(name, "/") */
67 u8 is_patterned; /* = PathContainsPattern(name) */
68 u16 depth; /* = PathDepth(name) */
69 };
70
71 #define CCS_MAX_PATHNAME_LEN 4000
72
73 struct group_member {
74 struct group_member *next;
75 const struct path_info *member_name;
76 int is_deleted;
77 };
78
79 struct group_entry {
80 struct group_entry *next;
81 const struct path_info *group_name;
82 struct group_member *first_member;
83 };
84
85 struct address_group_member {
86 struct address_group_member *next;
87 union {
88 u32 ipv4; /* Host byte order */
89 u16 ipv6[8]; /* Network byte order */
90 } min, max;
91 u8 is_deleted;
92 u8 is_ipv6;
93 };
94
95 struct address_group_entry {
96 struct address_group_entry *next;
97 const struct path_info *group_name;
98 struct address_group_member *first_member;
99 };
100
101 /*
102 * TOMOYO uses the following structures.
103 * Memory allocated for these structures are never kfree()ed.
104 * Since no locks are used for reading, assignment must be performed atomically.
105 */
106
107 /************************* The structure for domains. *************************/
108
109 struct condition_list;
110
111 struct acl_info {
112 struct acl_info *next;
113 const struct condition_list *cond;
114 u8 type;
115 u8 is_deleted;
116 } __attribute__((__packed__));
117
118 struct domain_info {
119 struct domain_info *next; /* Pointer to next record. NULL if none. */
120 struct acl_info *first_acl_ptr; /* Pointer to first acl. NULL if none. */
121 const struct path_info *domainname; /* Name of this domain. Never NULL. */
122 u8 profile; /* Profile to use. */
123 u8 is_deleted; /* Delete flag. */
124 u8 quota_warned; /* Quota warnning done flag. */
125 };
126
127 #define MAX_PROFILES 256
128
129 struct file_acl_record {
130 struct acl_info head; /* type = TYPE_FILE_ACL */
131 u8 perm;
132 u8 u_is_group;
133 union {
134 const struct path_info *filename; /* Pointer to single pathname. */
135 const struct group_entry *group; /* Pointer to pathname group. */
136 } u;
137 };
138
139 struct argv0_acl_record {
140 struct acl_info head; /* type = TYPE_ARGV0_ACL */
141 const struct path_info *filename; /* Pointer to single pathname. */
142 const struct path_info *argv0; /* strrchr(argv[0], '/') + 1 */
143 };
144
145 struct capability_acl_record {
146 struct acl_info head; /* type = TYPE_CAPABILITY_ACL */
147 u16 capability;
148 };
149
150 struct signal_acl_record {
151 struct acl_info head; /* type = TYPE_SIGNAL_ACL */
152 u16 sig;
153 const struct path_info *domainname; /* Pointer to destination pattern. */
154 };
155
156 struct single_acl_record {
157 struct acl_info head; /* type = TYPE_* */
158 u8 u_is_group;
159 union {
160 const struct path_info *filename; /* Pointer to single pathname. */
161 const struct group_entry *group; /* Pointer to pathname group. */
162 } u;
163 };
164
165 struct double_acl_record {
166 struct acl_info head; /* type = TYPE_RENAME_ACL or TYPE_LINK_ACL */
167 u8 u1_is_group;
168 u8 u2_is_group;
169 union {
170 const struct path_info *filename1; /* Pointer to single pathname. */
171 const struct group_entry *group1; /* Pointer to pathname group. */
172 } u1;
173 union {
174 const struct path_info *filename2; /* Pointer to single pathname. */
175 const struct group_entry *group2; /* Pointer to pathname group. */
176 } u2;
177 };
178
179 #define IP_RECORD_TYPE_ADDRESS_GROUP 0
180 #define IP_RECORD_TYPE_IPv4 1
181 #define IP_RECORD_TYPE_IPv6 2
182
183 struct ip_network_acl_record {
184 struct acl_info head; /* type = TYPE_IP_NETWORK_ACL */
185 u8 operation_type;
186 u8 record_type; /* IP_RECORD_TYPE_* */
187 union {
188 struct {
189 u32 min; /* Start of IPv4 address range. Host endian. */
190 u32 max; /* End of IPv4 address range. Host endian. */
191 } ipv4;
192 struct {
193 u16 min[8]; /* Start of IPv6 address range. Big endian. */
194 u16 max[8]; /* End of IPv6 address range. Big endian. */
195 } ipv6;
196 const struct address_group_entry *group; /* Pointer to address group. */
197 } u;
198 u16 min_port; /* Start of port number range. */
199 u16 max_port; /* End of port number range. */
200 };
201
202 /************************* Keywords for ACLs. *************************/
203
204 #define KEYWORD_ADDRESS_GROUP "address_group "
205 #define KEYWORD_ADDRESS_GROUP_LEN (sizeof(KEYWORD_ADDRESS_GROUP) - 1)
206 #define KEYWORD_AGGREGATOR "aggregator "
207 #define KEYWORD_AGGREGATOR_LEN (sizeof(KEYWORD_AGGREGATOR) - 1)
208 #define KEYWORD_ALIAS "alias "
209 #define KEYWORD_ALIAS_LEN (sizeof(KEYWORD_ALIAS) - 1)
210 #define KEYWORD_ALLOW_ARGV0 "allow_argv0 "
211 #define KEYWORD_ALLOW_ARGV0_LEN (sizeof(KEYWORD_ALLOW_ARGV0) - 1)
212 #define KEYWORD_ALLOW_CAPABILITY "allow_capability "
213 #define KEYWORD_ALLOW_CAPABILITY_LEN (sizeof(KEYWORD_ALLOW_CAPABILITY) - 1)
214 #define KEYWORD_ALLOW_CHROOT "allow_chroot "
215 #define KEYWORD_ALLOW_CHROOT_LEN (sizeof(KEYWORD_ALLOW_CHROOT) - 1)
216 #define KEYWORD_ALLOW_MOUNT "allow_mount "
217 #define KEYWORD_ALLOW_MOUNT_LEN (sizeof(KEYWORD_ALLOW_MOUNT) - 1)
218 #define KEYWORD_ALLOW_NETWORK "allow_network "
219 #define KEYWORD_ALLOW_NETWORK_LEN (sizeof(KEYWORD_ALLOW_NETWORK) - 1)
220 #define KEYWORD_ALLOW_PIVOT_ROOT "allow_pivot_root "
221 #define KEYWORD_ALLOW_PIVOT_ROOT_LEN (sizeof(KEYWORD_ALLOW_PIVOT_ROOT) - 1)
222 #define KEYWORD_ALLOW_READ "allow_read "
223 #define KEYWORD_ALLOW_READ_LEN (sizeof(KEYWORD_ALLOW_READ) - 1)
224 #define KEYWORD_ALLOW_SIGNAL "allow_signal "
225 #define KEYWORD_ALLOW_SIGNAL_LEN (sizeof(KEYWORD_ALLOW_SIGNAL) - 1)
226 #define KEYWORD_DELETE "delete "
227 #define KEYWORD_DELETE_LEN (sizeof(KEYWORD_DELETE) - 1)
228 #define KEYWORD_DENY_AUTOBIND "deny_autobind "
229 #define KEYWORD_DENY_AUTOBIND_LEN (sizeof(KEYWORD_DENY_AUTOBIND) - 1)
230 #define KEYWORD_DENY_REWRITE "deny_rewrite "
231 #define KEYWORD_DENY_REWRITE_LEN (sizeof(KEYWORD_DENY_REWRITE) - 1)
232 #define KEYWORD_DENY_UNMOUNT "deny_unmount "
233 #define KEYWORD_DENY_UNMOUNT_LEN (sizeof(KEYWORD_DENY_UNMOUNT) - 1)
234 #define KEYWORD_FILE_PATTERN "file_pattern "
235 #define KEYWORD_FILE_PATTERN_LEN (sizeof(KEYWORD_FILE_PATTERN) - 1)
236 #define KEYWORD_INITIALIZE_DOMAIN "initialize_domain "
237 #define KEYWORD_INITIALIZE_DOMAIN_LEN (sizeof(KEYWORD_INITIALIZE_DOMAIN) - 1)
238 #define KEYWORD_KEEP_DOMAIN "keep_domain "
239 #define KEYWORD_KEEP_DOMAIN_LEN (sizeof(KEYWORD_KEEP_DOMAIN) - 1)
240 #define KEYWORD_NO_INITIALIZE_DOMAIN "no_initialize_domain "
241 #define KEYWORD_NO_INITIALIZE_DOMAIN_LEN (sizeof(KEYWORD_NO_INITIALIZE_DOMAIN) - 1)
242 #define KEYWORD_NO_KEEP_DOMAIN "no_keep_domain "
243 #define KEYWORD_NO_KEEP_DOMAIN_LEN (sizeof(KEYWORD_NO_KEEP_DOMAIN) - 1)
244 #define KEYWORD_PATH_GROUP "path_group "
245 #define KEYWORD_PATH_GROUP_LEN (sizeof(KEYWORD_PATH_GROUP) - 1)
246 #define KEYWORD_SELECT "select "
247 #define KEYWORD_SELECT_LEN (sizeof(KEYWORD_SELECT) - 1)
248 #define KEYWORD_UNDELETE "undelete "
249 #define KEYWORD_UNDELETE_LEN (sizeof(KEYWORD_UNDELETE) - 1)
250
251 #define KEYWORD_USE_PROFILE "use_profile "
252
253 #define KEYWORD_MAC_FOR_CAPABILITY "MAC_FOR_CAPABILITY::"
254 #define KEYWORD_MAC_FOR_CAPABILITY_LEN (sizeof(KEYWORD_MAC_FOR_CAPABILITY) - 1)
255
256 #define ROOT_NAME "<kernel>" /* A domain definition starts with <kernel> . */
257 #define ROOT_NAME_LEN (sizeof(ROOT_NAME) - 1)
258
259 /************************* Index numbers for Access Controls. *************************/
260
261 #define CCS_PROFILE_COMMENT 0 /* profile.conf */
262 #define CCS_TOMOYO_MAC_FOR_FILE 1 /* domain_policy.conf */
263 #define CCS_TOMOYO_MAC_FOR_ARGV0 2 /* domain_policy.conf */
264 #define CCS_TOMOYO_MAC_FOR_NETWORK 3 /* domain_policy.conf */
265 #define CCS_TOMOYO_MAC_FOR_SIGNAL 4 /* domain_policy.conf */
266 #define CCS_SAKURA_DENY_CONCEAL_MOUNT 5
267 #define CCS_SAKURA_RESTRICT_CHROOT 6 /* system_policy.conf */
268 #define CCS_SAKURA_RESTRICT_MOUNT 7 /* system_policy.conf */
269 #define CCS_SAKURA_RESTRICT_UNMOUNT 8 /* system_policy.conf */
270 #define CCS_SAKURA_RESTRICT_PIVOT_ROOT 9 /* system_policy.conf */
271 #define CCS_SAKURA_RESTRICT_AUTOBIND 10 /* system_policy.conf */
272 #define CCS_TOMOYO_MAX_ACCEPT_ENTRY 11
273 #define CCS_TOMOYO_MAX_GRANT_LOG 12
274 #define CCS_TOMOYO_MAX_REJECT_LOG 13
275 #define CCS_TOMOYO_VERBOSE 14
276 #define CCS_ALLOW_ENFORCE_GRACE 15
277 #define CCS_MAX_CONTROL_INDEX 16
278
279 /************************* Index numbers for updates counter. *************************/
280
281 #define CCS_UPDATES_COUNTER_SYSTEM_POLICY 0
282 #define CCS_UPDATES_COUNTER_DOMAIN_POLICY 1
283 #define CCS_UPDATES_COUNTER_EXCEPTION_POLICY 2
284 #define CCS_UPDATES_COUNTER_PROFILE 3
285 #define CCS_UPDATES_COUNTER_QUERY 4
286 #define CCS_UPDATES_COUNTER_MANAGER 5
287 #define CCS_UPDATES_COUNTER_GRANT_LOG 6
288 #define CCS_UPDATES_COUNTER_REJECT_LOG 7
289 #define MAX_CCS_UPDATES_COUNTER 8
290
291 /************************* The structure for /proc interfaces. *************************/
292
293 struct io_buffer {
294 int (*read) (struct io_buffer *);
295 struct semaphore read_sem;
296 int (*write) (struct io_buffer *);
297 struct semaphore write_sem;
298 int (*poll) (struct file *file, poll_table *wait);
299 void *read_var1; /* The position currently reading from. */
300 void *read_var2; /* Extra variables for reading. */
301 struct domain_info *write_var1; /* The position currently writing to. */
302 int read_step; /* The step for reading. */
303 char *read_buf; /* Buffer for reading. */
304 int read_eof; /* EOF flag for reading. */
305 int read_avail; /* Bytes available for reading. */
306 int readbuf_size; /* Size of read buffer. */
307 char *write_buf; /* Buffer for writing. */
308 int write_avail; /* Bytes available for writing. */
309 int writebuf_size; /* Size of write buffer. */
310 };
311
312 /************************* PROTOTYPES *************************/
313
314 char *FindConditionPart(char *data);
315 char *InitAuditLog(int *len);
316 void *ccs_alloc(const size_t size);
317 char *print_ipv6(char *buffer, const int buffer_len, const u16 *ip);
318 const char *GetEXE(void);
319 const char *GetLastName(const struct domain_info *domain);
320 const char *GetMSG(const int is_enforce);
321 const char *acltype2keyword(const unsigned int acl_type);
322 const char *capability2keyword(const unsigned int capability);
323 const char *network2keyword(const unsigned int operation);
324 const struct condition_list *FindOrAssignNewCondition(const char *condition);
325 int AddAddressGroupPolicy(char *data, const int is_delete);
326 int AddAggregatorPolicy(char *data, const int is_delete);
327 int AddAliasPolicy(char *data, const int is_delete);
328 int AddArgv0Policy(char *data, struct domain_info *domain, const int is_delete);
329 int AddCapabilityPolicy(char *data, struct domain_info *domain, const int is_delete);
330 int AddChrootPolicy(char *data, const int is_delete);
331 int AddDomainACL(struct acl_info *ptr, struct domain_info *domain, struct acl_info *new_ptr);
332 int AddDomainInitializerPolicy(char *data, const int is_not, const int is_delete);
333 int AddDomainKeeperPolicy(char *data, const int is_not, const int is_delete);
334 int AddFilePolicy(char *data, struct domain_info *domain, const int is_delete);
335 int AddGloballyReadablePolicy(char *data, const int is_delete);
336 int AddGroupPolicy(char *data, const int is_delete);
337 int AddMountPolicy(char *data, const int is_delete);
338 int AddNetworkPolicy(char *data, struct domain_info *domain, const int is_delete);
339 int AddNoRewritePolicy(char *pattern, const int is_delete);
340 int AddNoUmountPolicy(char *data, const int is_delete);
341 int AddPatternPolicy(char *data, const int is_delete);
342 int AddPivotRootPolicy(char *data, const int is_delete);
343 int AddReservedPortPolicy(char *data, const int is_delete);
344 int AddSignalPolicy(char *data, struct domain_info *domain, const int is_delete);
345 int CCS_CloseControl(struct file *file);
346 int CCS_OpenControl(const int type, struct file *file);
347 int CCS_PollControl(struct file *file, poll_table *wait);
348 int CCS_ReadControl(struct file *file, char __user *buffer, const int buffer_len);
349 int CCS_WriteControl(struct file *file, const char __user *buffer, const int buffer_len);
350 int CanSaveAuditLog(const int is_granted);
351 int CheckCondition(const struct condition_list *condition, struct obj_info *obj_info);
352 int CheckSupervisor(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
353 int DelDomainACL(struct acl_info *ptr);
354 int DeleteDomain(char *data);
355 int DumpCondition(struct io_buffer *head, const struct condition_list *ptr);
356 int IsCorrectDomain(const unsigned char *domainname, const char *function);
357 int IsCorrectPath(const char *filename, const int start_type, const int pattern_type, const int end_type, const char *function);
358 int IsDomainDef(const unsigned char *buffer);
359 int PathMatchesToPattern(const struct path_info *pathname0, const struct path_info *pattern0);
360 int PollGrantLog(struct file *file, poll_table *wait);
361 int PollRejectLog(struct file *file, poll_table *wait);
362 int ReadAddressGroupPolicy(struct io_buffer *head);
363 int ReadAggregatorPolicy(struct io_buffer *head);
364 int ReadAliasPolicy(struct io_buffer *head);
365 int ReadCapabilityStatus(struct io_buffer *head);
366 int ReadChrootPolicy(struct io_buffer *head);
367 int ReadDomainInitializerPolicy(struct io_buffer *head);
368 int ReadDomainKeeperPolicy(struct io_buffer *head);
369 int ReadGloballyReadablePolicy(struct io_buffer *head);
370 int ReadGrantLog(struct io_buffer *head);
371 int ReadGroupPolicy(struct io_buffer *head);
372 int ReadMountPolicy(struct io_buffer *head);
373 int ReadNoRewritePolicy(struct io_buffer *head);
374 int ReadNoUmountPolicy(struct io_buffer *head);
375 int ReadPatternPolicy(struct io_buffer *head);
376 int ReadPivotRootPolicy(struct io_buffer *head);
377 int ReadRejectLog(struct io_buffer *head);
378 int ReadReservedPortPolicy(struct io_buffer *head);
379 int SetCapabilityStatus(const char *data, unsigned int value, const unsigned int profile);
380 int TooManyDomainACL(struct domain_info * const domain);
381 int WriteAuditLog(char *log, const int is_granted);
382 int acltype2paths(const unsigned int acl_type);
383 int io_printf(struct io_buffer *head, const char *fmt, ...) __attribute__ ((format(printf, 2, 3)));
384 struct domain_info *FindDomain(const char *domainname);
385 struct domain_info *FindOrAssignNewDomain(const char *domainname, const u8 profile);
386 struct domain_info *UndeleteDomain(const char *domainname0);
387 unsigned int CheckCCSAccept(const unsigned int index);
388 unsigned int CheckCCSEnforce(const unsigned int index);
389 unsigned int CheckCCSFlags(const unsigned int index);
390 unsigned int TomoyoVerboseMode(void);
391 void UpdateCounter(const unsigned char index);
392 void ccs_free(const void *p);
393 void fill_path_info(struct path_info *ptr);
394
395 static inline int pathcmp(const struct path_info *a, const struct path_info *b)
396 {
397 return a->hash != b->hash || strcmp(a->name, b->name);
398 }
399 #endif

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26