2 * security/tomoyo/group.c
4 * Copyright (C) 2005-2011 NTT DATA CORPORATION
7 #include <linux/slab.h>
11 * tomoyo_same_path_group - Check for duplicated "struct tomoyo_path_group" entry.
13 * @a: Pointer to "struct tomoyo_acl_head".
14 * @b: Pointer to "struct tomoyo_acl_head".
16 * Returns true if @a == @b, false otherwise.
18 static bool tomoyo_same_path_group(const struct tomoyo_acl_head
*a
,
19 const struct tomoyo_acl_head
*b
)
21 return container_of(a
, struct tomoyo_path_group
, head
)->member_name
==
22 container_of(b
, struct tomoyo_path_group
, head
)->member_name
;
26 * tomoyo_same_number_group - Check for duplicated "struct tomoyo_number_group" entry.
28 * @a: Pointer to "struct tomoyo_acl_head".
29 * @b: Pointer to "struct tomoyo_acl_head".
31 * Returns true if @a == @b, false otherwise.
33 static bool tomoyo_same_number_group(const struct tomoyo_acl_head
*a
,
34 const struct tomoyo_acl_head
*b
)
36 return !memcmp(&container_of(a
, struct tomoyo_number_group
, head
)
38 &container_of(b
, struct tomoyo_number_group
, head
)
40 sizeof(container_of(a
, struct tomoyo_number_group
, head
)
45 * tomoyo_write_group - Write "struct tomoyo_path_group"/"struct tomoyo_number_group" list.
47 * @param: Pointer to "struct tomoyo_acl_param".
48 * @type: Type of this group.
50 * Returns 0 on success, negative value otherwise.
52 int tomoyo_write_group(struct tomoyo_acl_param
*param
, const u8 type
)
54 struct tomoyo_group
*group
= tomoyo_get_group(param
, type
);
58 param
->list
= &group
->member_list
;
59 if (type
== TOMOYO_PATH_GROUP
) {
60 struct tomoyo_path_group e
= { };
61 e
.member_name
= tomoyo_get_name(tomoyo_read_token(param
));
66 error
= tomoyo_update_policy(&e
.head
, sizeof(e
), param
,
67 tomoyo_same_path_group
);
68 tomoyo_put_name(e
.member_name
);
69 } else if (type
== TOMOYO_NUMBER_GROUP
) {
70 struct tomoyo_number_group e
= { };
71 if (param
->data
[0] == '@' ||
72 !tomoyo_parse_number_union(param
, &e
.number
))
74 error
= tomoyo_update_policy(&e
.head
, sizeof(e
), param
,
75 tomoyo_same_number_group
);
77 * tomoyo_put_number_union() is not needed because
78 * param->data[0] != '@'.
82 tomoyo_put_group(group
);
87 * tomoyo_path_matches_group - Check whether the given pathname matches members of the given pathname group.
89 * @pathname: The name of pathname.
90 * @group: Pointer to "struct tomoyo_path_group".
92 * Returns matched member's pathname if @pathname matches pathnames in @group,
95 * Caller holds tomoyo_read_lock().
97 const struct tomoyo_path_info
*
98 tomoyo_path_matches_group(const struct tomoyo_path_info
*pathname
,
99 const struct tomoyo_group
*group
)
101 struct tomoyo_path_group
*member
;
102 list_for_each_entry_rcu(member
, &group
->member_list
, head
.list
) {
103 if (member
->head
.is_deleted
)
105 if (!tomoyo_path_matches_pattern(pathname
, member
->member_name
))
107 return member
->member_name
;
113 * tomoyo_number_matches_group - Check whether the given number matches members of the given number group.
117 * @group: Pointer to "struct tomoyo_number_group".
119 * Returns true if @min and @max partially overlaps @group, false otherwise.
121 * Caller holds tomoyo_read_lock().
123 bool tomoyo_number_matches_group(const unsigned long min
,
124 const unsigned long max
,
125 const struct tomoyo_group
*group
)
127 struct tomoyo_number_group
*member
;
128 bool matched
= false;
129 list_for_each_entry_rcu(member
, &group
->member_list
, head
.list
) {
130 if (member
->head
.is_deleted
)
132 if (min
> member
->number
.values
[1] ||
133 max
< member
->number
.values
[0])