]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/acl-util.c
relicense to LGPLv2.1 (with exceptions)
[thirdparty/systemd.git] / src / shared / acl-util.c
CommitLineData
f4b47811
LP
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2011 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
5430f7f2
LP
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
f4b47811
LP
11 (at your option) any later version.
12
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
5430f7f2 16 Lesser General Public License for more details.
f4b47811 17
5430f7f2 18 You should have received a copy of the GNU Lesser General Public License
f4b47811
LP
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
22#include <assert.h>
23#include <sys/acl.h>
24#include <acl/libacl.h>
25#include <errno.h>
26#include <stdbool.h>
27
79c07722 28#include "acl-util.h"
f4b47811
LP
29
30int acl_find_uid(acl_t acl, uid_t uid, acl_entry_t *entry) {
31 acl_entry_t i;
32 int found;
33
34 assert(acl);
35 assert(entry);
36
37 for (found = acl_get_entry(acl, ACL_FIRST_ENTRY, &i);
38 found > 0;
39 found = acl_get_entry(acl, ACL_NEXT_ENTRY, &i)) {
40
41 acl_tag_t tag;
42 uid_t *u;
43 bool b;
44
45 if (acl_get_tag_type(i, &tag) < 0)
46 return -errno;
47
48 if (tag != ACL_USER)
49 continue;
50
51 u = acl_get_qualifier(i);
52 if (!u)
53 return -errno;
54
55 b = *u == uid;
56 acl_free(u);
57
58 if (b) {
59 *entry = i;
60 return 1;
61 }
62 }
63
64 if (found < 0)
65 return -errno;
66
67 return 0;
68}