diff options
author | Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> | 2010-05-16 21:12:46 -0400 |
---|---|---|
committer | James Morris <jmorris@namei.org> | 2010-08-02 01:33:39 -0400 |
commit | c3ef1500ec833890275172c7d063333404b64d60 (patch) | |
tree | 2453368e521a1f7a00098eef06afbedb8404503d /security/tomoyo/securityfs_if.c | |
parent | 17fcfbd9d45b57f38d40e31f9d28db53f4af5c88 (diff) |
TOMOYO: Split files into some pieces.
security/tomoyo/common.c became too large to read.
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: James Morris <jmorris@namei.org>
Diffstat (limited to 'security/tomoyo/securityfs_if.c')
-rw-r--r-- | security/tomoyo/securityfs_if.c | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/security/tomoyo/securityfs_if.c b/security/tomoyo/securityfs_if.c new file mode 100644 index 000000000000..5eb53510c4a7 --- /dev/null +++ b/security/tomoyo/securityfs_if.c | |||
@@ -0,0 +1,140 @@ | |||
1 | /* | ||
2 | * security/tomoyo/common.c | ||
3 | * | ||
4 | * Securityfs interface for TOMOYO. | ||
5 | * | ||
6 | * Copyright (C) 2005-2010 NTT DATA CORPORATION | ||
7 | */ | ||
8 | |||
9 | #include <linux/security.h> | ||
10 | #include "common.h" | ||
11 | |||
12 | /** | ||
13 | * tomoyo_open - open() for /sys/kernel/security/tomoyo/ interface. | ||
14 | * | ||
15 | * @inode: Pointer to "struct inode". | ||
16 | * @file: Pointer to "struct file". | ||
17 | * | ||
18 | * Returns 0 on success, negative value otherwise. | ||
19 | */ | ||
20 | static int tomoyo_open(struct inode *inode, struct file *file) | ||
21 | { | ||
22 | const int key = ((u8 *) file->f_path.dentry->d_inode->i_private) | ||
23 | - ((u8 *) NULL); | ||
24 | return tomoyo_open_control(key, file); | ||
25 | } | ||
26 | |||
27 | /** | ||
28 | * tomoyo_release - close() for /sys/kernel/security/tomoyo/ interface. | ||
29 | * | ||
30 | * @inode: Pointer to "struct inode". | ||
31 | * @file: Pointer to "struct file". | ||
32 | * | ||
33 | * Returns 0 on success, negative value otherwise. | ||
34 | */ | ||
35 | static int tomoyo_release(struct inode *inode, struct file *file) | ||
36 | { | ||
37 | return tomoyo_close_control(file); | ||
38 | } | ||
39 | |||
40 | /** | ||
41 | * tomoyo_read - read() for /sys/kernel/security/tomoyo/ interface. | ||
42 | * | ||
43 | * @file: Pointer to "struct file". | ||
44 | * @buf: Pointer to buffer. | ||
45 | * @count: Size of @buf. | ||
46 | * @ppos: Unused. | ||
47 | * | ||
48 | * Returns bytes read on success, negative value otherwise. | ||
49 | */ | ||
50 | static ssize_t tomoyo_read(struct file *file, char __user *buf, size_t count, | ||
51 | loff_t *ppos) | ||
52 | { | ||
53 | return tomoyo_read_control(file, buf, count); | ||
54 | } | ||
55 | |||
56 | /** | ||
57 | * tomoyo_write - write() for /sys/kernel/security/tomoyo/ interface. | ||
58 | * | ||
59 | * @file: Pointer to "struct file". | ||
60 | * @buf: Pointer to buffer. | ||
61 | * @count: Size of @buf. | ||
62 | * @ppos: Unused. | ||
63 | * | ||
64 | * Returns @count on success, negative value otherwise. | ||
65 | */ | ||
66 | static ssize_t tomoyo_write(struct file *file, const char __user *buf, | ||
67 | size_t count, loff_t *ppos) | ||
68 | { | ||
69 | return tomoyo_write_control(file, buf, count); | ||
70 | } | ||
71 | |||
72 | /* | ||
73 | * tomoyo_operations is a "struct file_operations" which is used for handling | ||
74 | * /sys/kernel/security/tomoyo/ interface. | ||
75 | * | ||
76 | * Some files under /sys/kernel/security/tomoyo/ directory accept open(O_RDWR). | ||
77 | * See tomoyo_io_buffer for internals. | ||
78 | */ | ||
79 | static const struct file_operations tomoyo_operations = { | ||
80 | .open = tomoyo_open, | ||
81 | .release = tomoyo_release, | ||
82 | .read = tomoyo_read, | ||
83 | .write = tomoyo_write, | ||
84 | }; | ||
85 | |||
86 | /** | ||
87 | * tomoyo_create_entry - Create interface files under /sys/kernel/security/tomoyo/ directory. | ||
88 | * | ||
89 | * @name: The name of the interface file. | ||
90 | * @mode: The permission of the interface file. | ||
91 | * @parent: The parent directory. | ||
92 | * @key: Type of interface. | ||
93 | * | ||
94 | * Returns nothing. | ||
95 | */ | ||
96 | static void __init tomoyo_create_entry(const char *name, const mode_t mode, | ||
97 | struct dentry *parent, const u8 key) | ||
98 | { | ||
99 | securityfs_create_file(name, mode, parent, ((u8 *) NULL) + key, | ||
100 | &tomoyo_operations); | ||
101 | } | ||
102 | |||
103 | /** | ||
104 | * tomoyo_initerface_init - Initialize /sys/kernel/security/tomoyo/ interface. | ||
105 | * | ||
106 | * Returns 0. | ||
107 | */ | ||
108 | static int __init tomoyo_initerface_init(void) | ||
109 | { | ||
110 | struct dentry *tomoyo_dir; | ||
111 | |||
112 | /* Don't create securityfs entries unless registered. */ | ||
113 | if (current_cred()->security != &tomoyo_kernel_domain) | ||
114 | return 0; | ||
115 | |||
116 | tomoyo_dir = securityfs_create_dir("tomoyo", NULL); | ||
117 | tomoyo_create_entry("query", 0600, tomoyo_dir, | ||
118 | TOMOYO_QUERY); | ||
119 | tomoyo_create_entry("domain_policy", 0600, tomoyo_dir, | ||
120 | TOMOYO_DOMAINPOLICY); | ||
121 | tomoyo_create_entry("exception_policy", 0600, tomoyo_dir, | ||
122 | TOMOYO_EXCEPTIONPOLICY); | ||
123 | tomoyo_create_entry("self_domain", 0400, tomoyo_dir, | ||
124 | TOMOYO_SELFDOMAIN); | ||
125 | tomoyo_create_entry(".domain_status", 0600, tomoyo_dir, | ||
126 | TOMOYO_DOMAIN_STATUS); | ||
127 | tomoyo_create_entry(".process_status", 0600, tomoyo_dir, | ||
128 | TOMOYO_PROCESS_STATUS); | ||
129 | tomoyo_create_entry("meminfo", 0600, tomoyo_dir, | ||
130 | TOMOYO_MEMINFO); | ||
131 | tomoyo_create_entry("profile", 0600, tomoyo_dir, | ||
132 | TOMOYO_PROFILE); | ||
133 | tomoyo_create_entry("manager", 0600, tomoyo_dir, | ||
134 | TOMOYO_MANAGER); | ||
135 | tomoyo_create_entry("version", 0400, tomoyo_dir, | ||
136 | TOMOYO_VERSION); | ||
137 | return 0; | ||
138 | } | ||
139 | |||
140 | fs_initcall(tomoyo_initerface_init); | ||