1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2011,2013 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
30 int acl_find_uid(acl_t acl, uid_t uid, acl_entry_t *entry) {
37 for (found = acl_get_entry(acl, ACL_FIRST_ENTRY, &i);
39 found = acl_get_entry(acl, ACL_NEXT_ENTRY, &i)) {
45 if (acl_get_tag_type(i, &tag) < 0)
51 u = acl_get_qualifier(i);
70 int calc_acl_mask_if_needed(acl_t *acl_p) {
76 for (found = acl_get_entry(*acl_p, ACL_FIRST_ENTRY, &i);
78 found = acl_get_entry(*acl_p, ACL_NEXT_ENTRY, &i)) {
82 if (acl_get_tag_type(i, &tag) < 0)
92 if (acl_calc_mask(acl_p) < 0)
98 int search_acl_groups(char*** dst, const char* path, bool* belong) {
104 acl = acl_get_file(path, ACL_TYPE_DEFAULT);
109 r = acl_get_entry(acl, ACL_FIRST_ENTRY, &entry);
115 r = acl_get_tag_type(entry, &tag);
119 if (tag != ACL_GROUP)
122 gid = acl_get_qualifier(entry);
126 if (in_gid(*gid) > 0) {
131 name = gid_to_name(*gid);
137 r = strv_consume(dst, name);
144 r = acl_get_entry(acl, ACL_NEXT_ENTRY, &entry);
153 int parse_acl(char *text, acl_t *acl_access, acl_t *acl_default, bool want_mask) {
154 _cleanup_free_ char **a = NULL, **d = NULL; /* strings are not be freed */
155 _cleanup_strv_free_ char **split;
158 _cleanup_(acl_freep) acl_t a_acl = NULL, d_acl = NULL;
160 split = strv_split(text, ",");
164 STRV_FOREACH(entry, split) {
167 p = startswith(*entry, "default:");
169 p = startswith(*entry, "d:");
172 r = strv_push(&d, p);
174 r = strv_push(&a, *entry);
179 if (!strv_isempty(a)) {
180 _cleanup_free_ char *join;
182 join = strv_join(a, ",");
186 a_acl = acl_from_text(join);
191 r = calc_acl_mask_if_needed(&a_acl);
197 if (!strv_isempty(d)) {
198 _cleanup_free_ char *join;
200 join = strv_join(d, ",");
204 d_acl = acl_from_text(join);
209 r = calc_acl_mask_if_needed(&d_acl);
216 *acl_default = d_acl;
217 a_acl = d_acl = NULL;
221 int acls_for_file(const char *path, acl_type_t type, acl_t new, acl_t *acl) {
222 _cleanup_(acl_freep) acl_t old;
226 old = acl_get_file(path, type);
230 for (found = acl_get_entry(new, ACL_FIRST_ENTRY, &i);
232 found = acl_get_entry(new, ACL_NEXT_ENTRY, &i)) {
236 if (acl_create_entry(&old, &j) < 0)
239 if (acl_copy_entry(j, i) < 0)
243 r = calc_acl_mask_if_needed(&old);