aboutsummaryrefslogtreecommitdiffstats
path: root/security/tomoyo/memory.c
diff options
context:
space:
mode:
authorTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>2010-06-17 03:55:58 -0400
committerJames Morris <jmorris@namei.org>2010-08-02 01:34:42 -0400
commit7c2ea22e3c5463627ca98924cd65cb9e480dc29c (patch)
tree3a105a08cf75c77689bdfe890c64f9ae433748b9 /security/tomoyo/memory.c
parent31845e8c6d3f4f26702e567c667277f9fd1f73a3 (diff)
TOMOYO: Merge path_group and number_group.
Use common code for "path_group" and "number_group". 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/memory.c')
-rw-r--r--security/tomoyo/memory.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/security/tomoyo/memory.c b/security/tomoyo/memory.c
index 249835abdf4e..a1d75df93e16 100644
--- a/security/tomoyo/memory.c
+++ b/security/tomoyo/memory.c
@@ -89,6 +89,50 @@ void tomoyo_memory_free(void *ptr)
89 kfree(ptr); 89 kfree(ptr);
90} 90}
91 91
92/**
93 * tomoyo_get_group - Allocate memory for "struct tomoyo_path_group"/"struct tomoyo_number_group".
94 *
95 * @group_name: The name of address group.
96 * @idx: Index number.
97 *
98 * Returns pointer to "struct tomoyo_group" on success, NULL otherwise.
99 */
100struct tomoyo_group *tomoyo_get_group(const char *group_name, const u8 idx)
101{
102 struct tomoyo_group e = { };
103 struct tomoyo_group *group = NULL;
104 bool found = false;
105 if (!tomoyo_correct_word(group_name) || idx >= TOMOYO_MAX_GROUP)
106 return NULL;
107 e.group_name = tomoyo_get_name(group_name);
108 if (!e.group_name)
109 return NULL;
110 if (mutex_lock_interruptible(&tomoyo_policy_lock))
111 goto out;
112 list_for_each_entry(group, &tomoyo_group_list[idx], list) {
113 if (e.group_name != group->group_name)
114 continue;
115 atomic_inc(&group->users);
116 found = true;
117 break;
118 }
119 if (!found) {
120 struct tomoyo_group *entry = tomoyo_commit_ok(&e, sizeof(e));
121 if (entry) {
122 INIT_LIST_HEAD(&entry->member_list);
123 atomic_set(&entry->users, 1);
124 list_add_tail_rcu(&entry->list,
125 &tomoyo_group_list[idx]);
126 group = entry;
127 found = true;
128 }
129 }
130 mutex_unlock(&tomoyo_policy_lock);
131 out:
132 tomoyo_put_name(e.group_name);
133 return found ? group : NULL;
134}
135
92/* 136/*
93 * tomoyo_name_list is used for holding string data used by TOMOYO. 137 * tomoyo_name_list is used for holding string data used by TOMOYO.
94 * Since same string data is likely used for multiple times (e.g. 138 * Since same string data is likely used for multiple times (e.g.