acl-util.c revision b26fa1a2fbcfee7d03b0c8fd15ec3aa64ae70b9f
/***
This file is part of systemd.
Copyright 2011,2013 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include <stdbool.h>
#include "acl-util.h"
#include "alloc-util.h"
#include "string-util.h"
#include "strv.h"
#include "user-util.h"
#include "util.h"
acl_entry_t i;
int r;
r > 0;
uid_t *u;
bool b;
if (acl_get_tag_type(i, &tag) < 0)
return -errno;
continue;
u = acl_get_qualifier(i);
if (!u)
return -errno;
b = *u == uid;
acl_free(u);
if (b) {
*entry = i;
return 1;
}
}
if (r < 0)
return -errno;
return 0;
}
acl_entry_t i;
int r;
bool need = false;
r > 0;
if (acl_get_tag_type(i, &tag) < 0)
return -errno;
return 0;
need = true;
}
if (r < 0)
return -errno;
return -errno;
return need;
}
acl_entry_t i;
int r;
r > 0;
if (acl_get_tag_type(i, &tag) < 0)
return -errno;
if (tag == ACL_USER_OBJ)
have_user_obj = true;
else if (tag == ACL_GROUP_OBJ)
have_group_obj = true;
have_other = true;
return 0;
}
if (r < 0)
return -errno;
if (r < 0)
return -errno;
if (!basic)
return -errno;
r > 0;
if (acl_get_tag_type(i, &tag) < 0)
return -errno;
continue;
if (r < 0)
return -errno;
r = acl_copy_entry(dst, i);
if (r < 0)
return -errno;
}
if (r < 0)
return -errno;
return 0;
}
_cleanup_strv_free_ char **g = NULL;
bool ret = false;
int r;
if (!acl)
return -errno;
for (;;) {
if (r < 0)
return -errno;
if (r == 0)
break;
return -errno;
goto next;
if (!gid)
return -errno;
if (!ret_groups)
return true;
ret = true;
}
if (ret_groups) {
char *name;
if (!name)
return -ENOMEM;
r = strv_consume(&g, name);
if (r < 0)
return r;
}
next:
}
if (ret_groups) {
*ret_groups = g;
g = NULL;
}
return ret;
}
_cleanup_strv_free_ char **split;
char **entry;
int r = -EINVAL;
if (!split)
return -ENOMEM;
char *p;
if (!p)
if (p)
r = strv_push(&d, p);
else
if (r < 0)
return r;
}
if (!strv_isempty(a)) {
_cleanup_free_ char *join;
if (!join)
return -ENOMEM;
if (!a_acl)
return -errno;
if (want_mask) {
r = calc_acl_mask_if_needed(&a_acl);
if (r < 0)
return r;
}
}
if (!strv_isempty(d)) {
_cleanup_free_ char *join;
if (!join)
return -ENOMEM;
if (!d_acl)
return -errno;
if (want_mask) {
r = calc_acl_mask_if_needed(&d_acl);
if (r < 0)
return r;
}
}
*acl_access = a_acl;
*acl_default = d_acl;
return 0;
}
if (acl_get_tag_type(a, &tag_a) < 0)
return -errno;
if (acl_get_tag_type(b, &tag_b) < 0)
return -errno;
return false;
switch (tag_a) {
case ACL_USER_OBJ:
case ACL_GROUP_OBJ:
case ACL_MASK:
case ACL_OTHER:
/* can have only one of those */
return true;
case ACL_USER: {
uid_a = acl_get_qualifier(a);
if (!uid_a)
return -errno;
uid_b = acl_get_qualifier(b);
if (!uid_b)
return -errno;
}
case ACL_GROUP: {
gid_a = acl_get_qualifier(a);
if (!gid_a)
return -errno;
gid_b = acl_get_qualifier(b);
if (!gid_b)
return -errno;
}
default:
assert_not_reached("Unknown acl tag type");
}
}
acl_entry_t i;
int r;
r > 0;
r = acl_entry_equal(i, entry);
if (r < 0)
return r;
if (r > 0) {
*out = i;
return 1;
}
}
if (r < 0)
return -errno;
return 0;
}
acl_entry_t i;
int r;
if (!old)
return -errno;
r > 0;
acl_entry_t j;
r = find_acl_entry(old, i, &j);
if (r < 0)
return r;
if (r == 0)
if (acl_create_entry(&old, &j) < 0)
return -errno;
if (acl_copy_entry(j, i) < 0)
return -errno;
}
if (r < 0)
return -errno;
return 0;
}
int r;
if (!acl)
return -errno;
if (r <= 0) {
return -errno;
}
/* We do not recalculate the mask unconditionally here,
* so that the fchmod() mask above stays intact. */
return -errno;
r = calc_acl_mask_if_needed(&acl);
if (r < 0)
return r;
}