2 * security/tomoyo/group.c
4 * Copyright (C) 2005-2010 NTT DATA CORPORATION
7 #include <linux/slab.h>
10 static bool tomoyo_same_path_group(const struct tomoyo_acl_head *a,
11 const struct tomoyo_acl_head *b)
13 return container_of(a, struct tomoyo_path_group, head)->member_name ==
14 container_of(b, struct tomoyo_path_group, head)->member_name;
17 static bool tomoyo_same_number_group(const struct tomoyo_acl_head *a,
18 const struct tomoyo_acl_head *b)
20 return !memcmp(&container_of(a, struct tomoyo_number_group, head)
22 &container_of(b, struct tomoyo_number_group, head)
24 sizeof(container_of(a, struct tomoyo_number_group, head)
29 * tomoyo_write_group - Write "struct tomoyo_path_group"/"struct tomoyo_number_group" list.
31 * @param: Pointer to "struct tomoyo_acl_param".
32 * @type: Type of this group.
34 * Returns 0 on success, negative value otherwise.
36 int tomoyo_write_group(struct tomoyo_acl_param *param, const u8 type)
38 struct tomoyo_group *group = tomoyo_get_group(param, type);
42 param->list = &group->member_list;
43 if (type == TOMOYO_PATH_GROUP) {
44 struct tomoyo_path_group e = { };
45 e.member_name = tomoyo_get_name(tomoyo_read_token(param));
50 error = tomoyo_update_policy(&e.head, sizeof(e), param,
51 tomoyo_same_path_group);
52 tomoyo_put_name(e.member_name);
53 } else if (type == TOMOYO_NUMBER_GROUP) {
54 struct tomoyo_number_group e = { };
55 if (param->data[0] == '@' ||
56 !tomoyo_parse_number_union(param, &e.number))
58 error = tomoyo_update_policy(&e.head, sizeof(e), param,
59 tomoyo_same_number_group);
61 * tomoyo_put_number_union() is not needed because
62 * param->data[0] != '@'.
66 tomoyo_put_group(group);
71 * tomoyo_path_matches_group - Check whether the given pathname matches members of the given pathname group.
73 * @pathname: The name of pathname.
74 * @group: Pointer to "struct tomoyo_path_group".
76 * Returns matched member's pathname if @pathname matches pathnames in @group,
79 * Caller holds tomoyo_read_lock().
81 const struct tomoyo_path_info *
82 tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
83 const struct tomoyo_group *group)
85 struct tomoyo_path_group *member;
86 list_for_each_entry_rcu(member, &group->member_list, head.list) {
87 if (member->head.is_deleted)
89 if (!tomoyo_path_matches_pattern(pathname, member->member_name))
91 return member->member_name;
97 * tomoyo_number_matches_group - Check whether the given number matches members of the given number group.
101 * @group: Pointer to "struct tomoyo_number_group".
103 * Returns true if @min and @max partially overlaps @group, false otherwise.
105 * Caller holds tomoyo_read_lock().
107 bool tomoyo_number_matches_group(const unsigned long min,
108 const unsigned long max,
109 const struct tomoyo_group *group)
111 struct tomoyo_number_group *member;
112 bool matched = false;
113 list_for_each_entry_rcu(member, &group->member_list, head.list) {
114 if (member->head.is_deleted)
116 if (min > member->number.values[1] ||
117 max < member->number.values[0])