aboutsummaryrefslogtreecommitdiffstats
path: root/security/tomoyo/util.c
diff options
context:
space:
mode:
authorTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>2011-06-26 10:17:10 -0400
committerJames Morris <jmorris@namei.org>2011-06-28 19:31:20 -0400
commita238cf5b89ed5285be8de56335665d023972f7d5 (patch)
treecd2594f5c80345b5f880a3ccd445d15fb6b7d6cd /security/tomoyo/util.c
parent0df7e8b8f1c25c10820bdc679555f2fbfb897ca0 (diff)
TOMOYO: Use struct for passing ACL line.
Use structure for passing ACL line, in preparation for supporting policy namespace and conditional parameters. 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/util.c')
-rw-r--r--security/tomoyo/util.c120
1 files changed, 69 insertions, 51 deletions
diff --git a/security/tomoyo/util.c b/security/tomoyo/util.c
index abb177c2d7c2..72cd2b97cae8 100644
--- a/security/tomoyo/util.c
+++ b/security/tomoyo/util.c
@@ -16,6 +16,46 @@ DEFINE_MUTEX(tomoyo_policy_lock);
16bool tomoyo_policy_loaded; 16bool tomoyo_policy_loaded;
17 17
18/** 18/**
19 * tomoyo_permstr - Find permission keywords.
20 *
21 * @string: String representation for permissions in foo/bar/buz format.
22 * @keyword: Keyword to find from @string/
23 *
24 * Returns ture if @keyword was found in @string, false otherwise.
25 *
26 * This function assumes that strncmp(w1, w2, strlen(w1)) != 0 if w1 != w2.
27 */
28bool tomoyo_permstr(const char *string, const char *keyword)
29{
30 const char *cp = strstr(string, keyword);
31 if (cp)
32 return cp == string || *(cp - 1) == '/';
33 return false;
34}
35
36/**
37 * tomoyo_read_token - Read a word from a line.
38 *
39 * @param: Pointer to "struct tomoyo_acl_param".
40 *
41 * Returns a word on success, "" otherwise.
42 *
43 * To allow the caller to skip NULL check, this function returns "" rather than
44 * NULL if there is no more words to read.
45 */
46char *tomoyo_read_token(struct tomoyo_acl_param *param)
47{
48 char *pos = param->data;
49 char *del = strchr(pos, ' ');
50 if (del)
51 *del++ = '\0';
52 else
53 del = pos + strlen(pos);
54 param->data = del;
55 return pos;
56}
57
58/**
19 * tomoyo_parse_ulong - Parse an "unsigned long" value. 59 * tomoyo_parse_ulong - Parse an "unsigned long" value.
20 * 60 *
21 * @result: Pointer to "unsigned long". 61 * @result: Pointer to "unsigned long".
@@ -81,20 +121,23 @@ void tomoyo_print_ulong(char *buffer, const int buffer_len,
81/** 121/**
82 * tomoyo_parse_name_union - Parse a tomoyo_name_union. 122 * tomoyo_parse_name_union - Parse a tomoyo_name_union.
83 * 123 *
84 * @filename: Name or name group. 124 * @param: Pointer to "struct tomoyo_acl_param".
85 * @ptr: Pointer to "struct tomoyo_name_union". 125 * @ptr: Pointer to "struct tomoyo_name_union".
86 * 126 *
87 * Returns true on success, false otherwise. 127 * Returns true on success, false otherwise.
88 */ 128 */
89bool tomoyo_parse_name_union(const char *filename, 129bool tomoyo_parse_name_union(struct tomoyo_acl_param *param,
90 struct tomoyo_name_union *ptr) 130 struct tomoyo_name_union *ptr)
91{ 131{
92 if (!tomoyo_correct_word(filename)) 132 char *filename;
93 return false; 133 if (param->data[0] == '@') {
94 if (filename[0] == '@') { 134 param->data++;
95 ptr->group = tomoyo_get_group(filename + 1, TOMOYO_PATH_GROUP); 135 ptr->group = tomoyo_get_group(param, TOMOYO_PATH_GROUP);
96 return ptr->group != NULL; 136 return ptr->group != NULL;
97 } 137 }
138 filename = tomoyo_read_token(param);
139 if (!tomoyo_correct_word(filename))
140 return false;
98 ptr->filename = tomoyo_get_name(filename); 141 ptr->filename = tomoyo_get_name(filename);
99 return ptr->filename != NULL; 142 return ptr->filename != NULL;
100} 143}
@@ -102,39 +145,41 @@ bool tomoyo_parse_name_union(const char *filename,
102/** 145/**
103 * tomoyo_parse_number_union - Parse a tomoyo_number_union. 146 * tomoyo_parse_number_union - Parse a tomoyo_number_union.
104 * 147 *
105 * @data: Number or number range or number group. 148 * @param: Pointer to "struct tomoyo_acl_param".
106 * @ptr: Pointer to "struct tomoyo_number_union". 149 * @ptr: Pointer to "struct tomoyo_number_union".
107 * 150 *
108 * Returns true on success, false otherwise. 151 * Returns true on success, false otherwise.
109 */ 152 */
110bool tomoyo_parse_number_union(char *data, struct tomoyo_number_union *num) 153bool tomoyo_parse_number_union(struct tomoyo_acl_param *param,
154 struct tomoyo_number_union *ptr)
111{ 155{
156 char *data;
112 u8 type; 157 u8 type;
113 unsigned long v; 158 unsigned long v;
114 memset(num, 0, sizeof(*num)); 159 memset(ptr, 0, sizeof(*ptr));
115 if (data[0] == '@') { 160 if (param->data[0] == '@') {
116 if (!tomoyo_correct_word(data)) 161 param->data++;
117 return false; 162 ptr->group = tomoyo_get_group(param, TOMOYO_NUMBER_GROUP);
118 num->group = tomoyo_get_group(data + 1, TOMOYO_NUMBER_GROUP); 163 return ptr->group != NULL;
119 return num->group != NULL;
120 } 164 }
165 data = tomoyo_read_token(param);
121 type = tomoyo_parse_ulong(&v, &data); 166 type = tomoyo_parse_ulong(&v, &data);
122 if (!type) 167 if (type == TOMOYO_VALUE_TYPE_INVALID)
123 return false; 168 return false;
124 num->values[0] = v; 169 ptr->values[0] = v;
125 num->value_type[0] = type; 170 ptr->value_type[0] = type;
126 if (!*data) { 171 if (!*data) {
127 num->values[1] = v; 172 ptr->values[1] = v;
128 num->value_type[1] = type; 173 ptr->value_type[1] = type;
129 return true; 174 return true;
130 } 175 }
131 if (*data++ != '-') 176 if (*data++ != '-')
132 return false; 177 return false;
133 type = tomoyo_parse_ulong(&v, &data); 178 type = tomoyo_parse_ulong(&v, &data);
134 if (!type || *data) 179 if (type == TOMOYO_VALUE_TYPE_INVALID || *data || ptr->values[0] > v)
135 return false; 180 return false;
136 num->values[1] = v; 181 ptr->values[1] = v;
137 num->value_type[1] = type; 182 ptr->value_type[1] = type;
138 return true; 183 return true;
139} 184}
140 185
@@ -259,33 +304,6 @@ void tomoyo_normalize_line(unsigned char *buffer)
259} 304}
260 305
261/** 306/**
262 * tomoyo_tokenize - Tokenize string.
263 *
264 * @buffer: The line to tokenize.
265 * @w: Pointer to "char *".
266 * @size: Sizeof @w .
267 *
268 * Returns true on success, false otherwise.
269 */
270bool tomoyo_tokenize(char *buffer, char *w[], size_t size)
271{
272 int count = size / sizeof(char *);
273 int i;
274 for (i = 0; i < count; i++)
275 w[i] = "";
276 for (i = 0; i < count; i++) {
277 char *cp = strchr(buffer, ' ');
278 if (cp)
279 *cp = '\0';
280 w[i] = buffer;
281 if (!cp)
282 break;
283 buffer = cp + 1;
284 }
285 return i < count || !*buffer;
286}
287
288/**
289 * tomoyo_correct_word2 - Validate a string. 307 * tomoyo_correct_word2 - Validate a string.
290 * 308 *
291 * @string: The string to check. May be non-'\0'-terminated. 309 * @string: The string to check. May be non-'\0'-terminated.