mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-10 01:17:44 +03:00
test-acl-util: add new test
For now, only add_acls_for_user is tested. When run under root, it actually sets the acls. When run under non-root, it sets the acls for the user, which does nothing, but at least calls the functions.
This commit is contained in:
parent
5c3bde3fa8
commit
5bb5b236fe
1
.gitignore
vendored
1
.gitignore
vendored
@ -133,6 +133,7 @@
|
||||
/systemd-vconsole-setup
|
||||
/tags
|
||||
/test-acd
|
||||
/test-acl-util
|
||||
/test-af-list
|
||||
/test-architecture
|
||||
/test-arphrd-list
|
||||
|
11
Makefile.am
11
Makefile.am
@ -1499,6 +1499,11 @@ tests += \
|
||||
test-dns-domain \
|
||||
test-install-root
|
||||
|
||||
if HAVE_ACL
|
||||
tests += \
|
||||
test-acl-util
|
||||
endif
|
||||
|
||||
EXTRA_DIST += \
|
||||
test/a.service \
|
||||
test/basic.target \
|
||||
@ -1846,6 +1851,12 @@ test_install_root_SOURCES = \
|
||||
test_install_root_LDADD = \
|
||||
libshared.la
|
||||
|
||||
test_acl_util_SOURCES = \
|
||||
src/test/test-acl-util.c
|
||||
|
||||
test_acl_util_LDADD = \
|
||||
libshared.la
|
||||
|
||||
test_namespace_LDADD = \
|
||||
libcore.la
|
||||
|
||||
|
85
src/test/test-acl-util.c
Normal file
85
src/test/test-acl-util.c
Normal file
@ -0,0 +1,85 @@
|
||||
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2015 Zbigniew Jędrzejewski-Szmek
|
||||
|
||||
systemd is free software; you can redistribute it and/or modify it
|
||||
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 <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "acl-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "string-util.h"
|
||||
#include "user-util.h"
|
||||
|
||||
static void test_add_acls_for_user(void) {
|
||||
char fn[] = "/tmp/test-empty.XXXXXX";
|
||||
_cleanup_close_ int fd = -1;
|
||||
char *cmd;
|
||||
uid_t uid;
|
||||
int r;
|
||||
|
||||
fd = mkostemp_safe(fn, O_RDWR|O_CLOEXEC);
|
||||
assert_se(fd >= 0);
|
||||
|
||||
/* Use the mode that user journal files use */
|
||||
assert(fchmod(fd, 0640) == 0);
|
||||
|
||||
cmd = strjoina("ls -l ", fn);
|
||||
assert_se(system(cmd) == 0);
|
||||
|
||||
cmd = strjoina("getfacl -p ", fn);
|
||||
assert_se(system(cmd) == 0);
|
||||
|
||||
if (getuid() == 0) {
|
||||
const char *nobody = "nobody";
|
||||
r = get_user_creds(&nobody, &uid, NULL, NULL, NULL);
|
||||
if (r < 0)
|
||||
uid = 0;
|
||||
} else
|
||||
uid = getuid();
|
||||
|
||||
r = add_acls_for_user(fd, uid);
|
||||
assert_se(r >= 0);
|
||||
|
||||
cmd = strjoina("ls -l ", fn);
|
||||
assert_se(system(cmd) == 0);
|
||||
|
||||
cmd = strjoina("getfacl -p ", fn);
|
||||
assert_se(system(cmd) == 0);
|
||||
|
||||
/* set the acls again */
|
||||
|
||||
r = add_acls_for_user(fd, uid);
|
||||
assert_se(r >= 0);
|
||||
|
||||
cmd = strjoina("ls -l ", fn);
|
||||
assert_se(system(cmd) == 0);
|
||||
|
||||
cmd = strjoina("getfacl -p ", fn);
|
||||
assert_se(system(cmd) == 0);
|
||||
|
||||
unlink(fn);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
test_add_acls_for_user();
|
||||
}
|
Loading…
Reference in New Issue
Block a user