2020-11-09 05:23:58 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
2015-11-28 06:04:40 +01:00
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "acl-util.h"
|
2020-09-11 22:25:25 +02:00
|
|
|
#include "errno-util.h"
|
2015-11-28 06:04:40 +01:00
|
|
|
#include "fd-util.h"
|
2020-08-07 18:54:37 +02:00
|
|
|
#include "format-util.h"
|
2015-11-28 06:04:40 +01:00
|
|
|
#include "string-util.h"
|
2020-09-11 22:25:25 +02:00
|
|
|
#include "tests.h"
|
2018-11-30 21:05:27 +01:00
|
|
|
#include "tmpfile-util.h"
|
2015-11-28 06:04:40 +01:00
|
|
|
#include "user-util.h"
|
|
|
|
|
2020-09-11 22:25:25 +02:00
|
|
|
static int test_add_acls_for_user(void) {
|
2015-11-28 06:04:40 +01:00
|
|
|
char fn[] = "/tmp/test-empty.XXXXXX";
|
|
|
|
_cleanup_close_ int fd = -1;
|
|
|
|
char *cmd;
|
|
|
|
uid_t uid;
|
|
|
|
int r;
|
|
|
|
|
2020-08-07 18:54:37 +02:00
|
|
|
log_info("/* %s */", __func__);
|
|
|
|
|
2016-09-13 08:20:38 +02:00
|
|
|
fd = mkostemp_safe(fn);
|
2015-11-28 06:04:40 +01:00
|
|
|
assert_se(fd >= 0);
|
|
|
|
|
|
|
|
/* Use the mode that user journal files use */
|
2015-11-30 21:45:39 +01:00
|
|
|
assert_se(fchmod(fd, 0640) == 0);
|
2015-11-28 06:04:40 +01:00
|
|
|
|
|
|
|
cmd = strjoina("ls -l ", fn);
|
|
|
|
assert_se(system(cmd) == 0);
|
|
|
|
|
|
|
|
cmd = strjoina("getfacl -p ", fn);
|
|
|
|
assert_se(system(cmd) == 0);
|
|
|
|
|
|
|
|
if (getuid() == 0) {
|
2017-12-07 07:48:44 +01:00
|
|
|
const char *nobody = NOBODY_USER_NAME;
|
2018-08-02 18:36:47 +02:00
|
|
|
r = get_user_creds(&nobody, &uid, NULL, NULL, NULL, 0);
|
2015-11-28 06:04:40 +01:00
|
|
|
if (r < 0)
|
|
|
|
uid = 0;
|
|
|
|
} else
|
|
|
|
uid = getuid();
|
|
|
|
|
2020-08-26 10:59:32 +02:00
|
|
|
r = fd_add_uid_acl_permission(fd, uid, ACL_READ);
|
2020-09-11 22:25:25 +02:00
|
|
|
if (ERRNO_IS_NOT_SUPPORTED(r))
|
|
|
|
return log_tests_skipped("no ACL support on /tmp");
|
|
|
|
|
2020-08-26 10:59:32 +02:00
|
|
|
log_info_errno(r, "fd_add_uid_acl_permission(%i, "UID_FMT", ACL_READ): %m", fd, uid);
|
2015-11-28 06:04:40 +01:00
|
|
|
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 */
|
|
|
|
|
2020-08-26 10:59:32 +02:00
|
|
|
r = fd_add_uid_acl_permission(fd, uid, ACL_READ);
|
2015-11-28 06:04:40 +01:00
|
|
|
assert_se(r >= 0);
|
|
|
|
|
|
|
|
cmd = strjoina("ls -l ", fn);
|
|
|
|
assert_se(system(cmd) == 0);
|
|
|
|
|
|
|
|
cmd = strjoina("getfacl -p ", fn);
|
|
|
|
assert_se(system(cmd) == 0);
|
|
|
|
|
2020-09-11 22:25:25 +02:00
|
|
|
(void) unlink(fn);
|
|
|
|
return 0;
|
2015-11-28 06:04:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2020-09-11 22:25:25 +02:00
|
|
|
return test_add_acls_for_user();
|
2015-11-28 06:04:40 +01:00
|
|
|
}
|