mirror of
https://github.com/systemd/systemd
synced 2024-10-06 16:21:34 +00:00
I made more unit test to use the test macro
This commit is contained in:
parent
e71b40fd00
commit
f9d273e67a
|
@ -1 +1 @@
|
||||||
Subproject commit 857ac0d294cdb65cc139fdd3dbed69706dd4eb45
|
Subproject commit 44fe1d4553f157aea4619a3dfed49f764b44f1ab
|
|
@ -16,14 +16,14 @@ static const struct af_name* lookup_af(register const char *str, register GPERF_
|
||||||
TEST(af_list) {
|
TEST(af_list) {
|
||||||
for (unsigned i = 0; i < ELEMENTSOF(af_names); i++) {
|
for (unsigned i = 0; i < ELEMENTSOF(af_names); i++) {
|
||||||
if (af_names[i]) {
|
if (af_names[i]) {
|
||||||
assert_se(streq(af_to_name(i), af_names[i]));
|
ASSERT_STREQ(af_to_name(i), af_names[i]);
|
||||||
assert_se(af_from_name(af_names[i]) == (int) i);
|
assert_se(af_from_name(af_names[i]) == (int) i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_se(af_to_name(af_max()) == NULL);
|
ASSERT_NULL(af_to_name(af_max()));
|
||||||
assert_se(af_to_name(0) == NULL);
|
ASSERT_NULL(af_to_name(0));
|
||||||
assert_se(af_to_name(-1) == NULL);
|
ASSERT_NULL(af_to_name(-1));
|
||||||
assert_se(af_from_name("huddlduddl") == -EINVAL);
|
assert_se(af_from_name("huddlduddl") == -EINVAL);
|
||||||
assert_se(af_from_name("") == -EINVAL);
|
assert_se(af_from_name("") == -EINVAL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,18 +13,18 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
test_setup_logging(LOG_INFO);
|
test_setup_logging(LOG_INFO);
|
||||||
|
|
||||||
assert_se(architecture_from_string("") < 0);
|
ASSERT_LT(architecture_from_string(""), 0);
|
||||||
assert_se(architecture_from_string(NULL) < 0);
|
ASSERT_LT(architecture_from_string(NULL), 0);
|
||||||
assert_se(architecture_from_string("hoge") < 0);
|
ASSERT_LT(architecture_from_string("hoge"), 0);
|
||||||
assert_se(architecture_to_string(-1) == NULL);
|
ASSERT_NULL(architecture_to_string(-1));
|
||||||
assert_se(architecture_from_string(architecture_to_string(0)) == 0);
|
ASSERT_EQ(architecture_from_string(architecture_to_string(0)), 0);
|
||||||
assert_se(architecture_from_string(architecture_to_string(1)) == 1);
|
ASSERT_EQ(architecture_from_string(architecture_to_string(1)), 1);
|
||||||
|
|
||||||
v = detect_virtualization();
|
v = detect_virtualization();
|
||||||
if (ERRNO_IS_NEG_PRIVILEGE(v))
|
if (ERRNO_IS_NEG_PRIVILEGE(v))
|
||||||
return log_tests_skipped("Cannot detect virtualization");
|
return log_tests_skipped("Cannot detect virtualization");
|
||||||
|
|
||||||
assert_se(v >= 0);
|
ASSERT_OK(v);
|
||||||
|
|
||||||
log_info("virtualization=%s id=%s",
|
log_info("virtualization=%s id=%s",
|
||||||
VIRTUALIZATION_IS_CONTAINER(v) ? "container" :
|
VIRTUALIZATION_IS_CONTAINER(v) ? "container" :
|
||||||
|
@ -32,20 +32,20 @@ int main(int argc, char *argv[]) {
|
||||||
virtualization_to_string(v));
|
virtualization_to_string(v));
|
||||||
|
|
||||||
a = uname_architecture();
|
a = uname_architecture();
|
||||||
assert_se(a >= 0);
|
ASSERT_OK(a);
|
||||||
|
|
||||||
p = architecture_to_string(a);
|
p = architecture_to_string(a);
|
||||||
assert_se(p);
|
assert_se(p);
|
||||||
log_info("uname architecture=%s", p);
|
log_info("uname architecture=%s", p);
|
||||||
assert_se(architecture_from_string(p) == a);
|
ASSERT_EQ(architecture_from_string(p), a);
|
||||||
|
|
||||||
a = native_architecture();
|
a = native_architecture();
|
||||||
assert_se(a >= 0);
|
ASSERT_OK(a);
|
||||||
|
|
||||||
p = architecture_to_string(a);
|
p = architecture_to_string(a);
|
||||||
assert_se(p);
|
assert_se(p);
|
||||||
log_info("native architecture=%s", p);
|
log_info("native architecture=%s", p);
|
||||||
assert_se(architecture_from_string(p) == a);
|
ASSERT_EQ(architecture_from_string(p), a);
|
||||||
|
|
||||||
log_info("primary library architecture=" LIB_ARCH_TUPLE);
|
log_info("primary library architecture=" LIB_ARCH_TUPLE);
|
||||||
|
|
||||||
|
|
|
@ -14,11 +14,11 @@ TEST(arphrd) {
|
||||||
if (name) {
|
if (name) {
|
||||||
log_info("%i: %s", i, name);
|
log_info("%i: %s", i, name);
|
||||||
|
|
||||||
assert_se(arphrd_from_name(name) == i);
|
ASSERT_EQ(arphrd_from_name(name), i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_se(arphrd_to_name(ARPHRD_VOID + 1) == NULL);
|
ASSERT_NULL(arphrd_to_name(ARPHRD_VOID + 1));
|
||||||
assert_se(arphrd_from_name("huddlduddl") == -EINVAL);
|
assert_se(arphrd_from_name("huddlduddl") == -EINVAL);
|
||||||
assert_se(arphrd_from_name("") == -EINVAL);
|
assert_se(arphrd_from_name("") == -EINVAL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,9 +15,9 @@ TEST(ask_password) {
|
||||||
|
|
||||||
r = ask_password_tty(-EBADF, &req, /* until= */ 0, /* flags= */ ASK_PASSWORD_CONSOLE_COLOR, /* flag_file= */ NULL, &ret);
|
r = ask_password_tty(-EBADF, &req, /* until= */ 0, /* flags= */ ASK_PASSWORD_CONSOLE_COLOR, /* flag_file= */ NULL, &ret);
|
||||||
if (r == -ECANCELED)
|
if (r == -ECANCELED)
|
||||||
assert_se(ret == NULL);
|
ASSERT_NULL(ret);
|
||||||
else {
|
else {
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
assert_se(strv_length(ret) == 1);
|
assert_se(strv_length(ret) == 1);
|
||||||
log_info("Got \"%s\"", *ret);
|
log_info("Got \"%s\"", *ret);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
#include "tmpfile-util.h"
|
#include "tmpfile-util.h"
|
||||||
|
|
||||||
TEST(asynchronous_sync) {
|
TEST(asynchronous_sync) {
|
||||||
assert_se(asynchronous_sync(NULL) >= 0);
|
ASSERT_OK(asynchronous_sync(NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(asynchronous_close) {
|
TEST(asynchronous_close) {
|
||||||
|
@ -22,29 +22,29 @@ TEST(asynchronous_close) {
|
||||||
int fd, r;
|
int fd, r;
|
||||||
|
|
||||||
fd = mkostemp_safe(name);
|
fd = mkostemp_safe(name);
|
||||||
assert_se(fd >= 0);
|
ASSERT_OK(fd);
|
||||||
asynchronous_close(fd);
|
asynchronous_close(fd);
|
||||||
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
|
||||||
assert_se(fcntl(fd, F_GETFD) == -1);
|
ASSERT_EQ(fcntl(fd, F_GETFD), -1);
|
||||||
assert_se(errno == EBADF);
|
assert_se(errno == EBADF);
|
||||||
|
|
||||||
r = safe_fork("(subreaper)", FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS|FORK_DEATHSIG_SIGKILL|FORK_LOG|FORK_WAIT, NULL);
|
r = safe_fork("(subreaper)", FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS|FORK_DEATHSIG_SIGKILL|FORK_LOG|FORK_WAIT, NULL);
|
||||||
assert(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
if (r == 0) {
|
if (r == 0) {
|
||||||
/* child */
|
/* child */
|
||||||
|
|
||||||
assert(make_reaper_process(true) >= 0);
|
ASSERT_OK(make_reaper_process(true));
|
||||||
|
|
||||||
fd = open("/dev/null", O_RDONLY|O_CLOEXEC);
|
fd = open("/dev/null", O_RDONLY|O_CLOEXEC);
|
||||||
assert_se(fd >= 0);
|
ASSERT_OK(fd);
|
||||||
asynchronous_close(fd);
|
asynchronous_close(fd);
|
||||||
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
|
||||||
assert_se(fcntl(fd, F_GETFD) == -1);
|
ASSERT_EQ(fcntl(fd, F_GETFD), -1);
|
||||||
assert_se(errno == EBADF);
|
assert_se(errno == EBADF);
|
||||||
|
|
||||||
_exit(EXIT_SUCCESS);
|
_exit(EXIT_SUCCESS);
|
||||||
|
@ -55,34 +55,34 @@ TEST(asynchronous_rm_rf) {
|
||||||
_cleanup_free_ char *t = NULL, *k = NULL;
|
_cleanup_free_ char *t = NULL, *k = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert_se(mkdtemp_malloc(NULL, &t) >= 0);
|
ASSERT_OK(mkdtemp_malloc(NULL, &t));
|
||||||
assert_se(k = path_join(t, "somefile"));
|
assert_se(k = path_join(t, "somefile"));
|
||||||
assert_se(touch(k) >= 0);
|
ASSERT_OK(touch(k));
|
||||||
assert_se(asynchronous_rm_rf(t, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
|
ASSERT_OK(asynchronous_rm_rf(t, REMOVE_ROOT|REMOVE_PHYSICAL));
|
||||||
|
|
||||||
/* Do this once more, form a subreaper. Which is nice, because we can watch the async child even
|
/* Do this once more, form a subreaper. Which is nice, because we can watch the async child even
|
||||||
* though detached */
|
* though detached */
|
||||||
|
|
||||||
r = safe_fork("(subreaper)", FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS|FORK_DEATHSIG_SIGTERM|FORK_LOG|FORK_WAIT, NULL);
|
r = safe_fork("(subreaper)", FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS|FORK_DEATHSIG_SIGTERM|FORK_LOG|FORK_WAIT, NULL);
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
if (r == 0) {
|
if (r == 0) {
|
||||||
_cleanup_free_ char *tt = NULL, *kk = NULL;
|
_cleanup_free_ char *tt = NULL, *kk = NULL;
|
||||||
|
|
||||||
/* child */
|
/* child */
|
||||||
|
|
||||||
assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGCHLD) >= 0);
|
ASSERT_OK(sigprocmask_many(SIG_BLOCK, NULL, SIGCHLD));
|
||||||
assert_se(make_reaper_process(true) >= 0);
|
ASSERT_OK(make_reaper_process(true));
|
||||||
|
|
||||||
assert_se(mkdtemp_malloc(NULL, &tt) >= 0);
|
ASSERT_OK(mkdtemp_malloc(NULL, &tt));
|
||||||
assert_se(kk = path_join(tt, "somefile"));
|
assert_se(kk = path_join(tt, "somefile"));
|
||||||
assert_se(touch(kk) >= 0);
|
ASSERT_OK(touch(kk));
|
||||||
assert_se(asynchronous_rm_rf(tt, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
|
ASSERT_OK(asynchronous_rm_rf(tt, REMOVE_ROOT|REMOVE_PHYSICAL));
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
siginfo_t si = {};
|
siginfo_t si = {};
|
||||||
|
|
||||||
assert_se(waitid(P_ALL, 0, &si, WEXITED) >= 0);
|
ASSERT_OK(waitid(P_ALL, 0, &si, WEXITED));
|
||||||
|
|
||||||
if (access(tt, F_OK) < 0) {
|
if (access(tt, F_OK) < 0) {
|
||||||
assert_se(errno == ENOENT);
|
assert_se(errno == ENOENT);
|
||||||
|
|
|
@ -30,7 +30,7 @@ static void set_alarm(usec_t usecs) {
|
||||||
struct itimerval v = { };
|
struct itimerval v = { };
|
||||||
|
|
||||||
timeval_store(&v.it_value, usecs);
|
timeval_store(&v.it_value, usecs);
|
||||||
assert_se(setitimer(ITIMER_REAL, &v, NULL) >= 0);
|
ASSERT_OK(setitimer(ITIMER_REAL, &v, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TEST_BARRIER(_FUNCTION, _CHILD_CODE, _WAIT_CHILD, _PARENT_CODE, _WAIT_PARENT) \
|
#define TEST_BARRIER(_FUNCTION, _CHILD_CODE, _WAIT_CHILD, _PARENT_CODE, _WAIT_PARENT) \
|
||||||
|
@ -38,14 +38,14 @@ static void set_alarm(usec_t usecs) {
|
||||||
Barrier b = BARRIER_NULL; \
|
Barrier b = BARRIER_NULL; \
|
||||||
pid_t pid1, pid2; \
|
pid_t pid1, pid2; \
|
||||||
\
|
\
|
||||||
assert_se(barrier_create(&b) >= 0); \
|
ASSERT_OK(barrier_create(&b)); \
|
||||||
assert_se(b.me > 0); \
|
ASSERT_GT(b.me, 0); \
|
||||||
assert_se(b.them > 0); \
|
ASSERT_GT(b.them, 0); \
|
||||||
assert_se(b.pipe[0] > 0); \
|
ASSERT_GT(b.pipe[0], 0); \
|
||||||
assert_se(b.pipe[1] > 0); \
|
ASSERT_GT(b.pipe[1], 0); \
|
||||||
\
|
\
|
||||||
pid1 = fork(); \
|
pid1 = fork(); \
|
||||||
assert_se(pid1 >= 0); \
|
ASSERT_OK(pid1); \
|
||||||
if (pid1 == 0) { \
|
if (pid1 == 0) { \
|
||||||
barrier_set_role(&b, BARRIER_CHILD); \
|
barrier_set_role(&b, BARRIER_CHILD); \
|
||||||
{ _CHILD_CODE; } \
|
{ _CHILD_CODE; } \
|
||||||
|
@ -53,7 +53,7 @@ static void set_alarm(usec_t usecs) {
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
pid2 = fork(); \
|
pid2 = fork(); \
|
||||||
assert_se(pid2 >= 0); \
|
ASSERT_OK(pid2); \
|
||||||
if (pid2 == 0) { \
|
if (pid2 == 0) { \
|
||||||
barrier_set_role(&b, BARRIER_PARENT); \
|
barrier_set_role(&b, BARRIER_PARENT); \
|
||||||
{ _PARENT_CODE; } \
|
{ _PARENT_CODE; } \
|
||||||
|
@ -71,16 +71,16 @@ static void set_alarm(usec_t usecs) {
|
||||||
({ \
|
({ \
|
||||||
int pidr, status; \
|
int pidr, status; \
|
||||||
pidr = waitpid(_pid, &status, 0); \
|
pidr = waitpid(_pid, &status, 0); \
|
||||||
assert_se(pidr == _pid); \
|
ASSERT_EQ(pidr, _pid); \
|
||||||
assert_se(WIFEXITED(status)); \
|
assert_se(WIFEXITED(status)); \
|
||||||
assert_se(WEXITSTATUS(status) == 42); \
|
ASSERT_EQ(WEXITSTATUS(status), 42); \
|
||||||
})
|
})
|
||||||
|
|
||||||
#define TEST_BARRIER_WAIT_ALARM(_pid) \
|
#define TEST_BARRIER_WAIT_ALARM(_pid) \
|
||||||
({ \
|
({ \
|
||||||
int pidr, status; \
|
int pidr, status; \
|
||||||
pidr = waitpid(_pid, &status, 0); \
|
pidr = waitpid(_pid, &status, 0); \
|
||||||
assert_se(pidr == _pid); \
|
ASSERT_EQ(pidr, _pid); \
|
||||||
assert_se(WIFSIGNALED(status)); \
|
assert_se(WIFSIGNALED(status)); \
|
||||||
assert_se(WTERMSIG(status) == SIGALRM); \
|
assert_se(WTERMSIG(status) == SIGALRM); \
|
||||||
})
|
})
|
||||||
|
|
|
@ -12,50 +12,50 @@ int main(int argc, const char *argv[]) {
|
||||||
b = bitmap_new();
|
b = bitmap_new();
|
||||||
assert_se(b);
|
assert_se(b);
|
||||||
|
|
||||||
assert_se(bitmap_ensure_allocated(&b) == 0);
|
ASSERT_EQ(bitmap_ensure_allocated(&b), 0);
|
||||||
b = bitmap_free(b);
|
b = bitmap_free(b);
|
||||||
assert_se(bitmap_ensure_allocated(&b) == 0);
|
ASSERT_EQ(bitmap_ensure_allocated(&b), 0);
|
||||||
|
|
||||||
assert_se(bitmap_isset(b, 0) == false);
|
ASSERT_FALSE(bitmap_isset(b, 0));
|
||||||
assert_se(bitmap_isset(b, 1) == false);
|
ASSERT_FALSE(bitmap_isset(b, 1));
|
||||||
assert_se(bitmap_isset(b, 256) == false);
|
ASSERT_FALSE(bitmap_isset(b, 256));
|
||||||
assert_se(bitmap_isclear(b) == true);
|
ASSERT_TRUE(bitmap_isclear(b));
|
||||||
|
|
||||||
assert_se(bitmap_set(b, 0) == 0);
|
ASSERT_EQ(bitmap_set(b, 0), 0);
|
||||||
assert_se(bitmap_isset(b, 0) == true);
|
ASSERT_TRUE(bitmap_isset(b, 0));
|
||||||
assert_se(bitmap_isclear(b) == false);
|
ASSERT_FALSE(bitmap_isclear(b));
|
||||||
bitmap_unset(b, 0);
|
bitmap_unset(b, 0);
|
||||||
assert_se(bitmap_isset(b, 0) == false);
|
ASSERT_FALSE(bitmap_isset(b, 0));
|
||||||
assert_se(bitmap_isclear(b) == true);
|
ASSERT_TRUE(bitmap_isclear(b));
|
||||||
|
|
||||||
assert_se(bitmap_set(b, 1) == 0);
|
ASSERT_EQ(bitmap_set(b, 1), 0);
|
||||||
assert_se(bitmap_isset(b, 1) == true);
|
ASSERT_TRUE(bitmap_isset(b, 1));
|
||||||
assert_se(bitmap_isclear(b) == false);
|
ASSERT_FALSE(bitmap_isclear(b));
|
||||||
bitmap_unset(b, 1);
|
bitmap_unset(b, 1);
|
||||||
assert_se(bitmap_isset(b, 1) == false);
|
ASSERT_FALSE(bitmap_isset(b, 1));
|
||||||
assert_se(bitmap_isclear(b) == true);
|
ASSERT_TRUE(bitmap_isclear(b));
|
||||||
|
|
||||||
assert_se(bitmap_set(b, 256) == 0);
|
ASSERT_EQ(bitmap_set(b, 256), 0);
|
||||||
assert_se(bitmap_isset(b, 256) == true);
|
ASSERT_TRUE(bitmap_isset(b, 256));
|
||||||
assert_se(bitmap_isclear(b) == false);
|
ASSERT_FALSE(bitmap_isclear(b));
|
||||||
bitmap_unset(b, 256);
|
bitmap_unset(b, 256);
|
||||||
assert_se(bitmap_isset(b, 256) == false);
|
ASSERT_FALSE(bitmap_isset(b, 256));
|
||||||
assert_se(bitmap_isclear(b) == true);
|
ASSERT_TRUE(bitmap_isclear(b));
|
||||||
|
|
||||||
assert_se(bitmap_set(b, 32) == 0);
|
ASSERT_EQ(bitmap_set(b, 32), 0);
|
||||||
bitmap_unset(b, 0);
|
bitmap_unset(b, 0);
|
||||||
assert_se(bitmap_isset(b, 32) == true);
|
ASSERT_TRUE(bitmap_isset(b, 32));
|
||||||
bitmap_unset(b, 32);
|
bitmap_unset(b, 32);
|
||||||
|
|
||||||
BITMAP_FOREACH(n, NULL)
|
BITMAP_FOREACH(n, NULL)
|
||||||
assert_not_reached();
|
assert_not_reached();
|
||||||
|
|
||||||
assert_se(bitmap_set(b, 0) == 0);
|
ASSERT_EQ(bitmap_set(b, 0), 0);
|
||||||
assert_se(bitmap_set(b, 1) == 0);
|
ASSERT_EQ(bitmap_set(b, 1), 0);
|
||||||
assert_se(bitmap_set(b, 256) == 0);
|
ASSERT_EQ(bitmap_set(b, 256), 0);
|
||||||
|
|
||||||
BITMAP_FOREACH(n, b) {
|
BITMAP_FOREACH(n, b) {
|
||||||
assert_se(n == i);
|
ASSERT_EQ(n, i);
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
i = 1;
|
i = 1;
|
||||||
else if (i == 1)
|
else if (i == 1)
|
||||||
|
@ -64,12 +64,12 @@ int main(int argc, const char *argv[]) {
|
||||||
i = UINT_MAX;
|
i = UINT_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_se(i == UINT_MAX);
|
ASSERT_EQ(i, UINT_MAX);
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
BITMAP_FOREACH(n, b) {
|
BITMAP_FOREACH(n, b) {
|
||||||
assert_se(n == i);
|
ASSERT_EQ(n, i);
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
i = 1;
|
i = 1;
|
||||||
else if (i == 1)
|
else if (i == 1)
|
||||||
|
@ -78,38 +78,38 @@ int main(int argc, const char *argv[]) {
|
||||||
i = UINT_MAX;
|
i = UINT_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_se(i == UINT_MAX);
|
ASSERT_EQ(i, UINT_MAX);
|
||||||
|
|
||||||
b2 = bitmap_copy(b);
|
b2 = bitmap_copy(b);
|
||||||
assert_se(b2);
|
assert_se(b2);
|
||||||
assert_se(bitmap_equal(b, b2) == true);
|
ASSERT_TRUE(bitmap_equal(b, b2));
|
||||||
assert_se(bitmap_equal(b, b) == true);
|
ASSERT_TRUE(bitmap_equal(b, b));
|
||||||
assert_se(bitmap_equal(b, NULL) == false);
|
ASSERT_FALSE(bitmap_equal(b, NULL));
|
||||||
assert_se(bitmap_equal(NULL, b) == false);
|
ASSERT_FALSE(bitmap_equal(NULL, b));
|
||||||
assert_se(bitmap_equal(NULL, NULL) == true);
|
ASSERT_TRUE(bitmap_equal(NULL, NULL));
|
||||||
|
|
||||||
bitmap_clear(b);
|
bitmap_clear(b);
|
||||||
assert_se(bitmap_isclear(b) == true);
|
ASSERT_TRUE(bitmap_isclear(b));
|
||||||
assert_se(bitmap_equal(b, b2) == false);
|
ASSERT_FALSE(bitmap_equal(b, b2));
|
||||||
b2 = bitmap_free(b2);
|
b2 = bitmap_free(b2);
|
||||||
|
|
||||||
assert_se(bitmap_set(b, UINT_MAX) == -ERANGE);
|
assert_se(bitmap_set(b, UINT_MAX) == -ERANGE);
|
||||||
|
|
||||||
b = bitmap_free(b);
|
b = bitmap_free(b);
|
||||||
assert_se(bitmap_ensure_allocated(&b) == 0);
|
ASSERT_EQ(bitmap_ensure_allocated(&b), 0);
|
||||||
assert_se(bitmap_ensure_allocated(&b2) == 0);
|
ASSERT_EQ(bitmap_ensure_allocated(&b2), 0);
|
||||||
|
|
||||||
assert_se(bitmap_equal(b, b2));
|
assert_se(bitmap_equal(b, b2));
|
||||||
assert_se(bitmap_set(b, 0) == 0);
|
ASSERT_EQ(bitmap_set(b, 0), 0);
|
||||||
bitmap_unset(b, 0);
|
bitmap_unset(b, 0);
|
||||||
assert_se(bitmap_equal(b, b2));
|
assert_se(bitmap_equal(b, b2));
|
||||||
|
|
||||||
assert_se(bitmap_set(b, 1) == 0);
|
ASSERT_EQ(bitmap_set(b, 1), 0);
|
||||||
bitmap_clear(b);
|
bitmap_clear(b);
|
||||||
assert_se(bitmap_equal(b, b2));
|
assert_se(bitmap_equal(b, b2));
|
||||||
|
|
||||||
assert_se(bitmap_set(b, 0) == 0);
|
ASSERT_EQ(bitmap_set(b, 0), 0);
|
||||||
assert_se(bitmap_set(b2, 0) == 0);
|
ASSERT_EQ(bitmap_set(b2, 0), 0);
|
||||||
assert_se(bitmap_equal(b, b2));
|
assert_se(bitmap_equal(b, b2));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -76,11 +76,11 @@ int main(int argc, char* argv[]) {
|
||||||
test_setup_logging(LOG_DEBUG);
|
test_setup_logging(LOG_DEBUG);
|
||||||
|
|
||||||
p = test_acpi_fpdt();
|
p = test_acpi_fpdt();
|
||||||
assert_se(p >= 0);
|
ASSERT_OK(p);
|
||||||
q = test_efi_loader();
|
q = test_efi_loader();
|
||||||
assert_se(q >= 0);
|
ASSERT_OK(q);
|
||||||
r = test_boot_timestamps();
|
r = test_boot_timestamps();
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
if (p == 0 && q == 0 && r == 0)
|
if (p == 0 && q == 0 && r == 0)
|
||||||
return log_tests_skipped("access to firmware variables not possible");
|
return log_tests_skipped("access to firmware variables not possible");
|
||||||
|
|
|
@ -63,7 +63,7 @@ TEST_RET(bootspec_sort) {
|
||||||
_cleanup_(rm_rf_physical_and_freep) char *d = NULL;
|
_cleanup_(rm_rf_physical_and_freep) char *d = NULL;
|
||||||
_cleanup_(boot_config_free) BootConfig config = BOOT_CONFIG_NULL;
|
_cleanup_(boot_config_free) BootConfig config = BOOT_CONFIG_NULL;
|
||||||
|
|
||||||
assert_se(mkdtemp_malloc("/tmp/bootspec-testXXXXXX", &d) >= 0);
|
ASSERT_OK(mkdtemp_malloc("/tmp/bootspec-testXXXXXX", &d));
|
||||||
|
|
||||||
for (size_t i = 0; i < ELEMENTSOF(entries); i++) {
|
for (size_t i = 0; i < ELEMENTSOF(entries); i++) {
|
||||||
_cleanup_free_ char *j = NULL;
|
_cleanup_free_ char *j = NULL;
|
||||||
|
@ -71,10 +71,10 @@ TEST_RET(bootspec_sort) {
|
||||||
j = path_join(d, "/loader/entries/", entries[i].fname);
|
j = path_join(d, "/loader/entries/", entries[i].fname);
|
||||||
assert_se(j);
|
assert_se(j);
|
||||||
|
|
||||||
assert_se(write_string_file(j, entries[i].contents, WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_MKDIR_0755) >= 0);
|
ASSERT_OK(write_string_file(j, entries[i].contents, WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_MKDIR_0755));
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_se(boot_config_load(&config, d, NULL) >= 0);
|
ASSERT_OK(boot_config_load(&config, d, NULL));
|
||||||
|
|
||||||
assert_se(config.n_entries == 6);
|
assert_se(config.n_entries == 6);
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@ TEST_RET(bootspec_boot_config_find_entry) {
|
||||||
|
|
||||||
/* Test finding a non-existent entry */
|
/* Test finding a non-existent entry */
|
||||||
entry = boot_config_find_entry(&config, "nonexistent.conf");
|
entry = boot_config_find_entry(&config, "nonexistent.conf");
|
||||||
assert_se(entry == NULL);
|
ASSERT_NULL(entry);
|
||||||
|
|
||||||
/* Test case-insensitivity */
|
/* Test case-insensitivity */
|
||||||
entry = boot_config_find_entry(&config, "A-10.CONF");
|
entry = boot_config_find_entry(&config, "A-10.CONF");
|
||||||
|
|
|
@ -22,13 +22,13 @@ static void test_policy_closed(const char *cgroup_path, BPFProgram **installed_p
|
||||||
log_info("/* %s */", __func__);
|
log_info("/* %s */", __func__);
|
||||||
|
|
||||||
r = bpf_devices_cgroup_init(&prog, CGROUP_DEVICE_POLICY_CLOSED, true);
|
r = bpf_devices_cgroup_init(&prog, CGROUP_DEVICE_POLICY_CLOSED, true);
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
r = bpf_devices_allow_list_static(prog, cgroup_path);
|
r = bpf_devices_allow_list_static(prog, cgroup_path);
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
r = bpf_devices_apply_policy(&prog, CGROUP_DEVICE_POLICY_CLOSED, true, cgroup_path, installed_prog);
|
r = bpf_devices_apply_policy(&prog, CGROUP_DEVICE_POLICY_CLOSED, true, cgroup_path, installed_prog);
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
FOREACH_STRING(s, "/dev/null",
|
FOREACH_STRING(s, "/dev/null",
|
||||||
"/dev/zero",
|
"/dev/zero",
|
||||||
|
@ -59,19 +59,19 @@ static void test_policy_strict(const char *cgroup_path, BPFProgram **installed_p
|
||||||
log_info("/* %s */", __func__);
|
log_info("/* %s */", __func__);
|
||||||
|
|
||||||
r = bpf_devices_cgroup_init(&prog, CGROUP_DEVICE_POLICY_STRICT, true);
|
r = bpf_devices_cgroup_init(&prog, CGROUP_DEVICE_POLICY_STRICT, true);
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
r = bpf_devices_allow_list_device(prog, cgroup_path, "/dev/null", CGROUP_DEVICE_READ|CGROUP_DEVICE_WRITE);
|
r = bpf_devices_allow_list_device(prog, cgroup_path, "/dev/null", CGROUP_DEVICE_READ|CGROUP_DEVICE_WRITE);
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
r = bpf_devices_allow_list_device(prog, cgroup_path, "/dev/random", CGROUP_DEVICE_READ);
|
r = bpf_devices_allow_list_device(prog, cgroup_path, "/dev/random", CGROUP_DEVICE_READ);
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
r = bpf_devices_allow_list_device(prog, cgroup_path, "/dev/zero", CGROUP_DEVICE_WRITE);
|
r = bpf_devices_allow_list_device(prog, cgroup_path, "/dev/zero", CGROUP_DEVICE_WRITE);
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
r = bpf_devices_apply_policy(&prog, CGROUP_DEVICE_POLICY_STRICT, true, cgroup_path, installed_prog);
|
r = bpf_devices_apply_policy(&prog, CGROUP_DEVICE_POLICY_STRICT, true, cgroup_path, installed_prog);
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
{
|
{
|
||||||
_cleanup_close_ int fd = -EBADF, fd2 = -EBADF;
|
_cleanup_close_ int fd = -EBADF, fd2 = -EBADF;
|
||||||
|
@ -136,13 +136,13 @@ static void test_policy_allow_list_major(const char *pattern, const char *cgroup
|
||||||
log_info("/* %s(%s) */", __func__, pattern);
|
log_info("/* %s(%s) */", __func__, pattern);
|
||||||
|
|
||||||
r = bpf_devices_cgroup_init(&prog, CGROUP_DEVICE_POLICY_STRICT, true);
|
r = bpf_devices_cgroup_init(&prog, CGROUP_DEVICE_POLICY_STRICT, true);
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
r = bpf_devices_allow_list_major(prog, cgroup_path, pattern, 'c', CGROUP_DEVICE_READ|CGROUP_DEVICE_WRITE);
|
r = bpf_devices_allow_list_major(prog, cgroup_path, pattern, 'c', CGROUP_DEVICE_READ|CGROUP_DEVICE_WRITE);
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
r = bpf_devices_apply_policy(&prog, CGROUP_DEVICE_POLICY_STRICT, true, cgroup_path, installed_prog);
|
r = bpf_devices_apply_policy(&prog, CGROUP_DEVICE_POLICY_STRICT, true, cgroup_path, installed_prog);
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
/* /dev/null, /dev/full have major==1, /dev/tty has major==5 */
|
/* /dev/null, /dev/full have major==1, /dev/tty has major==5 */
|
||||||
{
|
{
|
||||||
|
@ -195,13 +195,13 @@ static void test_policy_allow_list_major_star(char type, const char *cgroup_path
|
||||||
log_info("/* %s(type=%c) */", __func__, type);
|
log_info("/* %s(type=%c) */", __func__, type);
|
||||||
|
|
||||||
r = bpf_devices_cgroup_init(&prog, CGROUP_DEVICE_POLICY_STRICT, true);
|
r = bpf_devices_cgroup_init(&prog, CGROUP_DEVICE_POLICY_STRICT, true);
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
r = bpf_devices_allow_list_major(prog, cgroup_path, "*", type, CGROUP_DEVICE_READ|CGROUP_DEVICE_WRITE);
|
r = bpf_devices_allow_list_major(prog, cgroup_path, "*", type, CGROUP_DEVICE_READ|CGROUP_DEVICE_WRITE);
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
r = bpf_devices_apply_policy(&prog, CGROUP_DEVICE_POLICY_STRICT, true, cgroup_path, installed_prog);
|
r = bpf_devices_apply_policy(&prog, CGROUP_DEVICE_POLICY_STRICT, true, cgroup_path, installed_prog);
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
{
|
{
|
||||||
_cleanup_close_ int fd = -EBADF;
|
_cleanup_close_ int fd = -EBADF;
|
||||||
|
@ -226,7 +226,7 @@ static void test_policy_empty(bool add_mismatched, const char *cgroup_path, BPFP
|
||||||
log_info("/* %s(add_mismatched=%s) */", __func__, yes_no(add_mismatched));
|
log_info("/* %s(add_mismatched=%s) */", __func__, yes_no(add_mismatched));
|
||||||
|
|
||||||
r = bpf_devices_cgroup_init(&prog, CGROUP_DEVICE_POLICY_STRICT, add_mismatched);
|
r = bpf_devices_cgroup_init(&prog, CGROUP_DEVICE_POLICY_STRICT, add_mismatched);
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
if (add_mismatched) {
|
if (add_mismatched) {
|
||||||
r = bpf_devices_allow_list_major(prog, cgroup_path, "foobarxxx", 'c', CGROUP_DEVICE_READ|CGROUP_DEVICE_WRITE);
|
r = bpf_devices_allow_list_major(prog, cgroup_path, "foobarxxx", 'c', CGROUP_DEVICE_READ|CGROUP_DEVICE_WRITE);
|
||||||
|
@ -234,7 +234,7 @@ static void test_policy_empty(bool add_mismatched, const char *cgroup_path, BPFP
|
||||||
}
|
}
|
||||||
|
|
||||||
r = bpf_devices_apply_policy(&prog, CGROUP_DEVICE_POLICY_STRICT, false, cgroup_path, installed_prog);
|
r = bpf_devices_apply_policy(&prog, CGROUP_DEVICE_POLICY_STRICT, false, cgroup_path, installed_prog);
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
{
|
{
|
||||||
_cleanup_close_ int fd = -EBADF;
|
_cleanup_close_ int fd = -EBADF;
|
||||||
|
@ -258,7 +258,7 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
test_setup_logging(LOG_DEBUG);
|
test_setup_logging(LOG_DEBUG);
|
||||||
|
|
||||||
assert_se(getrlimit(RLIMIT_MEMLOCK, &rl) >= 0);
|
ASSERT_OK(getrlimit(RLIMIT_MEMLOCK, &rl));
|
||||||
rl.rlim_cur = rl.rlim_max = MAX(rl.rlim_max, CAN_MEMLOCK_SIZE);
|
rl.rlim_cur = rl.rlim_max = MAX(rl.rlim_max, CAN_MEMLOCK_SIZE);
|
||||||
(void) setrlimit(RLIMIT_MEMLOCK, &rl);
|
(void) setrlimit(RLIMIT_MEMLOCK, &rl);
|
||||||
|
|
||||||
|
@ -278,10 +278,10 @@ int main(int argc, char *argv[]) {
|
||||||
r = bpf_devices_supported();
|
r = bpf_devices_supported();
|
||||||
if (r == 0)
|
if (r == 0)
|
||||||
return log_tests_skipped("BPF device filter not supported");
|
return log_tests_skipped("BPF device filter not supported");
|
||||||
assert_se(r == 1);
|
ASSERT_EQ(r, 1);
|
||||||
|
|
||||||
r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, cgroup, NULL, &controller_path);
|
r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, cgroup, NULL, &controller_path);
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
_cleanup_(bpf_program_freep) BPFProgram *prog = NULL;
|
_cleanup_(bpf_program_freep) BPFProgram *prog = NULL;
|
||||||
|
|
||||||
|
@ -297,11 +297,11 @@ int main(int argc, char *argv[]) {
|
||||||
test_policy_empty(false, cgroup, &prog);
|
test_policy_empty(false, cgroup, &prog);
|
||||||
test_policy_empty(true, cgroup, &prog);
|
test_policy_empty(true, cgroup, &prog);
|
||||||
|
|
||||||
assert_se(path_extract_directory(cgroup, &parent) >= 0);
|
ASSERT_OK(path_extract_directory(cgroup, &parent));
|
||||||
|
|
||||||
assert_se(cg_mask_supported(&supported) >= 0);
|
ASSERT_OK(cg_mask_supported(&supported));
|
||||||
r = cg_attach_everywhere(supported, parent, 0, NULL, NULL);
|
r = cg_attach_everywhere(supported, parent, 0, NULL, NULL);
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ int main(int argc, char *argv[]) {
|
||||||
if (detect_container() > 0)
|
if (detect_container() > 0)
|
||||||
return log_tests_skipped("test-bpf-firewall fails inside LXC and Docker containers: https://github.com/systemd/systemd/issues/9666");
|
return log_tests_skipped("test-bpf-firewall fails inside LXC and Docker containers: https://github.com/systemd/systemd/issues/9666");
|
||||||
|
|
||||||
assert_se(getrlimit(RLIMIT_MEMLOCK, &rl) >= 0);
|
ASSERT_OK(getrlimit(RLIMIT_MEMLOCK, &rl));
|
||||||
rl.rlim_cur = rl.rlim_max = MAX(rl.rlim_max, CAN_MEMLOCK_SIZE);
|
rl.rlim_cur = rl.rlim_max = MAX(rl.rlim_max, CAN_MEMLOCK_SIZE);
|
||||||
(void) setrlimit(RLIMIT_MEMLOCK, &rl);
|
(void) setrlimit(RLIMIT_MEMLOCK, &rl);
|
||||||
|
|
||||||
|
@ -51,20 +51,20 @@ int main(int argc, char *argv[]) {
|
||||||
return log_tests_skipped("cgroupfs not available");
|
return log_tests_skipped("cgroupfs not available");
|
||||||
|
|
||||||
_cleanup_free_ char *unit_dir = NULL;
|
_cleanup_free_ char *unit_dir = NULL;
|
||||||
assert_se(get_testdata_dir("units", &unit_dir) >= 0);
|
ASSERT_OK(get_testdata_dir("units", &unit_dir));
|
||||||
assert_se(set_unit_path(unit_dir) >= 0);
|
ASSERT_OK(set_unit_path(unit_dir));
|
||||||
assert_se(runtime_dir = setup_fake_runtime_dir());
|
assert_se(runtime_dir = setup_fake_runtime_dir());
|
||||||
|
|
||||||
r = bpf_program_new(BPF_PROG_TYPE_CGROUP_SKB, "sd_trivial", &p);
|
r = bpf_program_new(BPF_PROG_TYPE_CGROUP_SKB, "sd_trivial", &p);
|
||||||
assert_se(r == 0);
|
ASSERT_EQ(r, 0);
|
||||||
|
|
||||||
r = bpf_program_add_instructions(p, exit_insn, ELEMENTSOF(exit_insn));
|
r = bpf_program_add_instructions(p, exit_insn, ELEMENTSOF(exit_insn));
|
||||||
assert_se(r == 0);
|
ASSERT_EQ(r, 0);
|
||||||
|
|
||||||
r = bpf_firewall_supported();
|
r = bpf_firewall_supported();
|
||||||
if (r == BPF_FIREWALL_UNSUPPORTED)
|
if (r == BPF_FIREWALL_UNSUPPORTED)
|
||||||
return log_tests_skipped("BPF firewalling not supported");
|
return log_tests_skipped("BPF firewalling not supported");
|
||||||
assert_se(r > 0);
|
ASSERT_GT(r, 0);
|
||||||
|
|
||||||
if (r == BPF_FIREWALL_SUPPORTED_WITH_MULTI) {
|
if (r == BPF_FIREWALL_SUPPORTED_WITH_MULTI) {
|
||||||
log_notice("BPF firewalling with BPF_F_ALLOW_MULTI supported. Yay!");
|
log_notice("BPF firewalling with BPF_F_ALLOW_MULTI supported. Yay!");
|
||||||
|
@ -73,7 +73,7 @@ int main(int argc, char *argv[]) {
|
||||||
log_notice("BPF firewalling (though without BPF_F_ALLOW_MULTI) supported. Good.");
|
log_notice("BPF firewalling (though without BPF_F_ALLOW_MULTI) supported. Good.");
|
||||||
|
|
||||||
r = bpf_program_load_kernel(p, log_buf, ELEMENTSOF(log_buf));
|
r = bpf_program_load_kernel(p, log_buf, ELEMENTSOF(log_buf));
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
if (test_custom_filter) {
|
if (test_custom_filter) {
|
||||||
zero(attr);
|
zero(attr);
|
||||||
|
@ -94,29 +94,29 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
/* The simple tests succeeded. Now let's try full unit-based use-case. */
|
/* The simple tests succeeded. Now let's try full unit-based use-case. */
|
||||||
|
|
||||||
assert_se(manager_new(RUNTIME_SCOPE_USER, MANAGER_TEST_RUN_BASIC, &m) >= 0);
|
ASSERT_OK(manager_new(RUNTIME_SCOPE_USER, MANAGER_TEST_RUN_BASIC, &m));
|
||||||
assert_se(manager_startup(m, NULL, NULL, NULL) >= 0);
|
ASSERT_OK(manager_startup(m, NULL, NULL, NULL));
|
||||||
|
|
||||||
assert_se(u = unit_new(m, sizeof(Service)));
|
assert_se(u = unit_new(m, sizeof(Service)));
|
||||||
assert_se(unit_add_name(u, "foo.service") == 0);
|
ASSERT_EQ(unit_add_name(u, "foo.service"), 0);
|
||||||
assert_se(cc = unit_get_cgroup_context(u));
|
assert_se(cc = unit_get_cgroup_context(u));
|
||||||
u->perpetual = true;
|
u->perpetual = true;
|
||||||
|
|
||||||
cc->ip_accounting = true;
|
cc->ip_accounting = true;
|
||||||
|
|
||||||
assert_se(config_parse_in_addr_prefixes(u->id, "filename", 1, "Service", 1, "IPAddressAllow", 0, "10.0.1.0/24", &cc->ip_address_allow, NULL) == 0);
|
ASSERT_EQ(config_parse_in_addr_prefixes(u->id, "filename", 1, "Service", 1, "IPAddressAllow", 0, "10.0.1.0/24", &cc->ip_address_allow, NULL), 0);
|
||||||
assert_se(config_parse_in_addr_prefixes(u->id, "filename", 1, "Service", 1, "IPAddressAllow", 0, "127.0.0.2", &cc->ip_address_allow, NULL) == 0);
|
ASSERT_EQ(config_parse_in_addr_prefixes(u->id, "filename", 1, "Service", 1, "IPAddressAllow", 0, "127.0.0.2", &cc->ip_address_allow, NULL), 0);
|
||||||
assert_se(config_parse_in_addr_prefixes(u->id, "filename", 1, "Service", 1, "IPAddressDeny", 0, "127.0.0.3", &cc->ip_address_deny, NULL) == 0);
|
ASSERT_EQ(config_parse_in_addr_prefixes(u->id, "filename", 1, "Service", 1, "IPAddressDeny", 0, "127.0.0.3", &cc->ip_address_deny, NULL), 0);
|
||||||
assert_se(config_parse_in_addr_prefixes(u->id, "filename", 1, "Service", 1, "IPAddressDeny", 0, "10.0.3.2/24", &cc->ip_address_deny, NULL) == 0);
|
ASSERT_EQ(config_parse_in_addr_prefixes(u->id, "filename", 1, "Service", 1, "IPAddressDeny", 0, "10.0.3.2/24", &cc->ip_address_deny, NULL), 0);
|
||||||
assert_se(config_parse_in_addr_prefixes(u->id, "filename", 1, "Service", 1, "IPAddressDeny", 0, "127.0.0.1/25", &cc->ip_address_deny, NULL) == 0);
|
ASSERT_EQ(config_parse_in_addr_prefixes(u->id, "filename", 1, "Service", 1, "IPAddressDeny", 0, "127.0.0.1/25", &cc->ip_address_deny, NULL), 0);
|
||||||
assert_se(config_parse_in_addr_prefixes(u->id, "filename", 1, "Service", 1, "IPAddressDeny", 0, "127.0.0.4", &cc->ip_address_deny, NULL) == 0);
|
ASSERT_EQ(config_parse_in_addr_prefixes(u->id, "filename", 1, "Service", 1, "IPAddressDeny", 0, "127.0.0.4", &cc->ip_address_deny, NULL), 0);
|
||||||
|
|
||||||
assert_se(set_size(cc->ip_address_allow) == 2);
|
assert_se(set_size(cc->ip_address_allow) == 2);
|
||||||
assert_se(set_size(cc->ip_address_deny) == 4);
|
assert_se(set_size(cc->ip_address_deny) == 4);
|
||||||
|
|
||||||
/* The deny list is defined redundantly, let's ensure it will be properly reduced */
|
/* The deny list is defined redundantly, let's ensure it will be properly reduced */
|
||||||
assert_se(in_addr_prefixes_reduce(cc->ip_address_allow) >= 0);
|
ASSERT_OK(in_addr_prefixes_reduce(cc->ip_address_allow));
|
||||||
assert_se(in_addr_prefixes_reduce(cc->ip_address_deny) >= 0);
|
ASSERT_OK(in_addr_prefixes_reduce(cc->ip_address_deny));
|
||||||
|
|
||||||
assert_se(set_size(cc->ip_address_allow) == 2);
|
assert_se(set_size(cc->ip_address_allow) == 2);
|
||||||
assert_se(set_size(cc->ip_address_deny) == 2);
|
assert_se(set_size(cc->ip_address_deny) == 2);
|
||||||
|
@ -166,7 +166,7 @@ int main(int argc, char *argv[]) {
|
||||||
log_notice("%s", log_buf);
|
log_notice("%s", log_buf);
|
||||||
log_notice("-------");
|
log_notice("-------");
|
||||||
|
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
r = bpf_program_load_kernel(crt->ip_bpf_egress, log_buf, ELEMENTSOF(log_buf));
|
r = bpf_program_load_kernel(crt->ip_bpf_egress, log_buf, ELEMENTSOF(log_buf));
|
||||||
|
|
||||||
|
@ -175,9 +175,9 @@ int main(int argc, char *argv[]) {
|
||||||
log_notice("%s", log_buf);
|
log_notice("%s", log_buf);
|
||||||
log_notice("-------");
|
log_notice("-------");
|
||||||
|
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
assert_se(unit_start(u, NULL) >= 0);
|
ASSERT_OK(unit_start(u, NULL));
|
||||||
|
|
||||||
while (!IN_SET(SERVICE(u)->state, SERVICE_DEAD, SERVICE_FAILED))
|
while (!IN_SET(SERVICE(u)->state, SERVICE_DEAD, SERVICE_FAILED))
|
||||||
assert_se(sd_event_run(m->event, UINT64_MAX) >= 0);
|
assert_se(sd_event_run(m->event, UINT64_MAX) >= 0);
|
||||||
|
@ -202,7 +202,7 @@ int main(int argc, char *argv[]) {
|
||||||
SERVICE(u)->type = SERVICE_ONESHOT;
|
SERVICE(u)->type = SERVICE_ONESHOT;
|
||||||
u->load_state = UNIT_LOADED;
|
u->load_state = UNIT_LOADED;
|
||||||
|
|
||||||
assert_se(unit_start(u, NULL) >= 0);
|
ASSERT_OK(unit_start(u, NULL));
|
||||||
|
|
||||||
while (!IN_SET(SERVICE(u)->state, SERVICE_DEAD, SERVICE_FAILED))
|
while (!IN_SET(SERVICE(u)->state, SERVICE_DEAD, SERVICE_FAILED))
|
||||||
assert_se(sd_event_run(m->event, UINT64_MAX) >= 0);
|
assert_se(sd_event_run(m->event, UINT64_MAX) >= 0);
|
||||||
|
|
|
@ -282,7 +282,7 @@ int main(int argc, char *argv[]) {
|
||||||
if (getuid() != 0)
|
if (getuid() != 0)
|
||||||
return log_tests_skipped("not running as root");
|
return log_tests_skipped("not running as root");
|
||||||
|
|
||||||
assert_se(getrlimit(RLIMIT_MEMLOCK, &rl) >= 0);
|
ASSERT_OK(getrlimit(RLIMIT_MEMLOCK, &rl));
|
||||||
rl.rlim_cur = rl.rlim_max = MAX(rl.rlim_max, CAN_MEMLOCK_SIZE);
|
rl.rlim_cur = rl.rlim_max = MAX(rl.rlim_max, CAN_MEMLOCK_SIZE);
|
||||||
(void) setrlimit_closest(RLIMIT_MEMLOCK, &rl);
|
(void) setrlimit_closest(RLIMIT_MEMLOCK, &rl);
|
||||||
|
|
||||||
|
@ -297,34 +297,34 @@ int main(int argc, char *argv[]) {
|
||||||
if (r == -ENOMEDIUM)
|
if (r == -ENOMEDIUM)
|
||||||
return log_tests_skipped("cgroupfs not available");
|
return log_tests_skipped("cgroupfs not available");
|
||||||
|
|
||||||
assert_se(get_testdata_dir("units", &unit_dir) >= 0);
|
ASSERT_OK(get_testdata_dir("units", &unit_dir));
|
||||||
assert_se(set_unit_path(unit_dir) >= 0);
|
ASSERT_OK(set_unit_path(unit_dir));
|
||||||
assert_se(runtime_dir = setup_fake_runtime_dir());
|
assert_se(runtime_dir = setup_fake_runtime_dir());
|
||||||
|
|
||||||
assert_se(manager_new(RUNTIME_SCOPE_USER, MANAGER_TEST_RUN_BASIC, &m) >= 0);
|
ASSERT_OK(manager_new(RUNTIME_SCOPE_USER, MANAGER_TEST_RUN_BASIC, &m));
|
||||||
assert_se(manager_startup(m, NULL, NULL, NULL) >= 0);
|
ASSERT_OK(manager_startup(m, NULL, NULL, NULL));
|
||||||
|
|
||||||
assert_se(test_bpf_cgroup_programs(m,
|
ASSERT_OK(test_bpf_cgroup_programs(m,
|
||||||
"single_prog.service", single_prog, ELEMENTSOF(single_prog)) >= 0);
|
"single_prog.service", single_prog, ELEMENTSOF(single_prog)));
|
||||||
assert_se(test_bpf_cgroup_programs(m,
|
ASSERT_OK(test_bpf_cgroup_programs(m,
|
||||||
"multi_prog_same_hook.service",
|
"multi_prog_same_hook.service",
|
||||||
multi_prog_same_hook, ELEMENTSOF(multi_prog_same_hook)) >= 0);
|
multi_prog_same_hook, ELEMENTSOF(multi_prog_same_hook)));
|
||||||
assert_se(test_bpf_cgroup_programs(m,
|
ASSERT_OK(test_bpf_cgroup_programs(m,
|
||||||
"same_prog_multi_hook.service",
|
"same_prog_multi_hook.service",
|
||||||
same_prog_multi_hook, ELEMENTSOF(same_prog_multi_hook)) >= 0);
|
same_prog_multi_hook, ELEMENTSOF(same_prog_multi_hook)));
|
||||||
assert_se(test_bpf_cgroup_programs(m,
|
ASSERT_OK(test_bpf_cgroup_programs(m,
|
||||||
"same_prog_multi_option_0.service",
|
"same_prog_multi_option_0.service",
|
||||||
same_prog_multi_option_0, ELEMENTSOF(same_prog_multi_option_0)) >= 0);
|
same_prog_multi_option_0, ELEMENTSOF(same_prog_multi_option_0)));
|
||||||
assert_se(test_bpf_cgroup_programs(m,
|
ASSERT_OK(test_bpf_cgroup_programs(m,
|
||||||
"same_prog_multi_option_1.service",
|
"same_prog_multi_option_1.service",
|
||||||
same_prog_multi_option_1, ELEMENTSOF(same_prog_multi_option_1)) >= 0);
|
same_prog_multi_option_1, ELEMENTSOF(same_prog_multi_option_1)));
|
||||||
assert_se(test_bpf_cgroup_programs(m,
|
ASSERT_OK(test_bpf_cgroup_programs(m,
|
||||||
"same_prog_same_hook.service",
|
"same_prog_same_hook.service",
|
||||||
same_prog_same_hook,
|
same_prog_same_hook,
|
||||||
ELEMENTSOF(same_prog_same_hook)) >= 0);
|
ELEMENTSOF(same_prog_same_hook)));
|
||||||
assert_se(test_bpf_cgroup_programs(m,
|
ASSERT_OK(test_bpf_cgroup_programs(m,
|
||||||
"path_split_test.service",
|
"path_split_test.service",
|
||||||
path_split_test,
|
path_split_test,
|
||||||
ELEMENTSOF(path_split_test)) >= 0);
|
ELEMENTSOF(path_split_test)));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
test_setup_logging(LOG_DEBUG);
|
test_setup_logging(LOG_DEBUG);
|
||||||
|
|
||||||
assert_se(getrlimit(RLIMIT_MEMLOCK, &rl) >= 0);
|
ASSERT_OK(getrlimit(RLIMIT_MEMLOCK, &rl));
|
||||||
rl.rlim_cur = rl.rlim_max = MAX(rl.rlim_max, CAN_MEMLOCK_SIZE);
|
rl.rlim_cur = rl.rlim_max = MAX(rl.rlim_max, CAN_MEMLOCK_SIZE);
|
||||||
(void) setrlimit_closest(RLIMIT_MEMLOCK, &rl);
|
(void) setrlimit_closest(RLIMIT_MEMLOCK, &rl);
|
||||||
|
|
||||||
|
@ -82,21 +82,21 @@ int main(int argc, char *argv[]) {
|
||||||
if (r == -ENOMEDIUM)
|
if (r == -ENOMEDIUM)
|
||||||
return log_tests_skipped("cgroupfs not available");
|
return log_tests_skipped("cgroupfs not available");
|
||||||
|
|
||||||
assert_se(get_testdata_dir("units", &unit_dir) >= 0);
|
ASSERT_OK(get_testdata_dir("units", &unit_dir));
|
||||||
assert_se(set_unit_path(unit_dir) >= 0);
|
ASSERT_OK(set_unit_path(unit_dir));
|
||||||
assert_se(runtime_dir = setup_fake_runtime_dir());
|
assert_se(runtime_dir = setup_fake_runtime_dir());
|
||||||
|
|
||||||
assert_se(manager_new(RUNTIME_SCOPE_SYSTEM, MANAGER_TEST_RUN_BASIC, &m) >= 0);
|
ASSERT_OK(manager_new(RUNTIME_SCOPE_SYSTEM, MANAGER_TEST_RUN_BASIC, &m));
|
||||||
assert_se(manager_startup(m, NULL, NULL, NULL) >= 0);
|
ASSERT_OK(manager_startup(m, NULL, NULL, NULL));
|
||||||
|
|
||||||
/* We need to enable access to the filesystem where the binary is so we
|
/* We need to enable access to the filesystem where the binary is so we
|
||||||
* add @common-block */
|
* add @common-block */
|
||||||
assert_se(test_restrict_filesystems(m, "restrict_filesystems_test.service", "/sys/kernel/tracing/printk_formats", STRV_MAKE("@common-block")) < 0);
|
ASSERT_LT(test_restrict_filesystems(m, "restrict_filesystems_test.service", "/sys/kernel/tracing/printk_formats", STRV_MAKE("@common-block")), 0);
|
||||||
assert_se(test_restrict_filesystems(m, "restrict_filesystems_test.service", "/sys/kernel/tracing/printk_formats", STRV_MAKE("tracefs", "@common-block")) >= 0);
|
ASSERT_OK(test_restrict_filesystems(m, "restrict_filesystems_test.service", "/sys/kernel/tracing/printk_formats", STRV_MAKE("tracefs", "@common-block")));
|
||||||
assert_se(test_restrict_filesystems(m, "restrict_filesystems_test.service", "/sys/kernel/tracing/printk_formats", STRV_MAKE("tracefs", "@common-block", "~tracefs")) < 0);
|
ASSERT_LT(test_restrict_filesystems(m, "restrict_filesystems_test.service", "/sys/kernel/tracing/printk_formats", STRV_MAKE("tracefs", "@common-block", "~tracefs")), 0);
|
||||||
assert_se(test_restrict_filesystems(m, "restrict_filesystems_test.service", "/sys/kernel/debug/sleep_time", STRV_MAKE("@common-block")) < 0);
|
ASSERT_LT(test_restrict_filesystems(m, "restrict_filesystems_test.service", "/sys/kernel/debug/sleep_time", STRV_MAKE("@common-block")), 0);
|
||||||
assert_se(test_restrict_filesystems(m, "restrict_filesystems_test.service", "/sys/kernel/debug/sleep_time", STRV_MAKE("debugfs", "@common-block")) >= 0);
|
ASSERT_OK(test_restrict_filesystems(m, "restrict_filesystems_test.service", "/sys/kernel/debug/sleep_time", STRV_MAKE("debugfs", "@common-block")));
|
||||||
assert_se(test_restrict_filesystems(m, "restrict_filesystems_test.service", "/sys/kernel/debug/sleep_time", STRV_MAKE("~debugfs")) < 0);
|
ASSERT_LT(test_restrict_filesystems(m, "restrict_filesystems_test.service", "/sys/kernel/debug/sleep_time", STRV_MAKE("~debugfs")), 0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,24 +16,24 @@ static void _test_one(int line, const char *input, const char *output) {
|
||||||
r = calendar_spec_from_string(input, &c);
|
r = calendar_spec_from_string(input, &c);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
log_error_errno(r, "Failed to parse \"%s\": %m", input);
|
log_error_errno(r, "Failed to parse \"%s\": %m", input);
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
assert_se(calendar_spec_to_string(c, &p) >= 0);
|
ASSERT_OK(calendar_spec_to_string(c, &p));
|
||||||
log_info("line %d: \"%s\" → \"%s\"%s%s", line, input, p,
|
log_info("line %d: \"%s\" → \"%s\"%s%s", line, input, p,
|
||||||
!streq(p, output) ? " expected:" : "",
|
!streq(p, output) ? " expected:" : "",
|
||||||
!streq(p, output) ? output : "");
|
!streq(p, output) ? output : "");
|
||||||
|
|
||||||
assert_se(streq(p, output));
|
ASSERT_STREQ(p, output);
|
||||||
|
|
||||||
u = now(CLOCK_REALTIME);
|
u = now(CLOCK_REALTIME);
|
||||||
r = calendar_spec_next_usec(c, u, &u);
|
r = calendar_spec_next_usec(c, u, &u);
|
||||||
log_info("Next: %s", r < 0 ? STRERROR(r) : FORMAT_TIMESTAMP(u));
|
log_info("Next: %s", r < 0 ? STRERROR(r) : FORMAT_TIMESTAMP(u));
|
||||||
c = calendar_spec_free(c);
|
c = calendar_spec_free(c);
|
||||||
|
|
||||||
assert_se(calendar_spec_from_string(p, &c) >= 0);
|
ASSERT_OK(calendar_spec_from_string(p, &c));
|
||||||
assert_se(calendar_spec_to_string(c, &q) >= 0);
|
ASSERT_OK(calendar_spec_to_string(c, &q));
|
||||||
|
|
||||||
assert_se(streq(q, p));
|
ASSERT_STREQ(q, p);
|
||||||
}
|
}
|
||||||
#define test_one(input, output) _test_one(__LINE__, input, output)
|
#define test_one(input, output) _test_one(__LINE__, input, output)
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ static void _test_next(int line, const char *input, const char *new_tz, usec_t a
|
||||||
assert_se(set_unset_env("TZ", new_tz, true) == 0);
|
assert_se(set_unset_env("TZ", new_tz, true) == 0);
|
||||||
tzset();
|
tzset();
|
||||||
|
|
||||||
assert_se(calendar_spec_from_string(input, &c) >= 0);
|
ASSERT_OK(calendar_spec_from_string(input, &c));
|
||||||
|
|
||||||
log_info("line %d: \"%s\" new_tz=%s", line, input, strnull(new_tz));
|
log_info("line %d: \"%s\" new_tz=%s", line, input, strnull(new_tz));
|
||||||
|
|
||||||
|
@ -82,11 +82,11 @@ TEST(timestamp) {
|
||||||
|
|
||||||
assert_se(format_timestamp_style(buf, sizeof buf, x, TIMESTAMP_US));
|
assert_se(format_timestamp_style(buf, sizeof buf, x, TIMESTAMP_US));
|
||||||
log_info("%s", buf);
|
log_info("%s", buf);
|
||||||
assert_se(calendar_spec_from_string(buf, &c) >= 0);
|
ASSERT_OK(calendar_spec_from_string(buf, &c));
|
||||||
assert_se(calendar_spec_to_string(c, &t) >= 0);
|
ASSERT_OK(calendar_spec_to_string(c, &t));
|
||||||
log_info("%s", t);
|
log_info("%s", t);
|
||||||
|
|
||||||
assert_se(parse_timestamp(t, &y) >= 0);
|
ASSERT_OK(parse_timestamp(t, &y));
|
||||||
assert_se(y == x);
|
assert_se(y == x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,9 +95,9 @@ TEST(hourly_bug_4031) {
|
||||||
usec_t n, u, w;
|
usec_t n, u, w;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert_se(calendar_spec_from_string("hourly", &c) >= 0);
|
ASSERT_OK(calendar_spec_from_string("hourly", &c));
|
||||||
n = now(CLOCK_REALTIME);
|
n = now(CLOCK_REALTIME);
|
||||||
assert_se((r = calendar_spec_next_usec(c, n, &u)) >= 0);
|
ASSERT_OK((r = calendar_spec_next_usec(c, n, &u)));
|
||||||
|
|
||||||
log_info("Now: %s (%"PRIu64")", FORMAT_TIMESTAMP_STYLE(n, TIMESTAMP_US), n);
|
log_info("Now: %s (%"PRIu64")", FORMAT_TIMESTAMP_STYLE(n, TIMESTAMP_US), n);
|
||||||
log_info("Next hourly: %s (%"PRIu64")", r < 0 ? STRERROR(r) : FORMAT_TIMESTAMP_STYLE(u, TIMESTAMP_US), u);
|
log_info("Next hourly: %s (%"PRIu64")", r < 0 ? STRERROR(r) : FORMAT_TIMESTAMP_STYLE(u, TIMESTAMP_US), u);
|
||||||
|
@ -256,7 +256,7 @@ TEST(calendar_spec_from_string) {
|
||||||
|
|
||||||
static int intro(void) {
|
static int intro(void) {
|
||||||
/* Tests have hard-coded results that do not expect a specific timezone to be set by the caller */
|
/* Tests have hard-coded results that do not expect a specific timezone to be set by the caller */
|
||||||
assert_se(unsetenv("TZ") >= 0);
|
ASSERT_OK(unsetenv("TZ"));
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,8 +160,8 @@ TEST(capability_set_to_string_negative) {
|
||||||
uint64_t m =
|
uint64_t m =
|
||||||
random_u64() % (UINT64_C(1) << (cap_last_cap() + 1));
|
random_u64() % (UINT64_C(1) << (cap_last_cap() + 1));
|
||||||
|
|
||||||
assert_se(capability_set_to_string(m, &a) >= 0);
|
ASSERT_OK(capability_set_to_string(m, &a));
|
||||||
assert_se(capability_set_to_string_negative(m, &b) >= 0);
|
ASSERT_OK(capability_set_to_string_negative(m, &b));
|
||||||
|
|
||||||
printf("%s (%zu) → ", a, strlen(a));
|
printf("%s (%zu) → ", a, strlen(a));
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ TEST(capability_set_to_string_negative) {
|
||||||
else
|
else
|
||||||
printf("%s (%zu)\n", b, strlen(b));
|
printf("%s (%zu)\n", b, strlen(b));
|
||||||
|
|
||||||
assert_se(strlen(b) <= strlen(a));
|
ASSERT_LE(strlen(b), strlen(a));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,12 +41,12 @@ static void test_last_cap_file(void) {
|
||||||
r = read_one_line_file("/proc/sys/kernel/cap_last_cap", &content);
|
r = read_one_line_file("/proc/sys/kernel/cap_last_cap", &content);
|
||||||
if (r == -ENOENT || ERRNO_IS_NEG_PRIVILEGE(r)) /* kernel pre 3.2 or no access */
|
if (r == -ENOENT || ERRNO_IS_NEG_PRIVILEGE(r)) /* kernel pre 3.2 or no access */
|
||||||
return;
|
return;
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
r = safe_atolu(content, &val);
|
r = safe_atolu(content, &val);
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
assert_se(val != 0);
|
assert_se(val != 0);
|
||||||
assert_se(val == cap_last_cap());
|
ASSERT_EQ(val, cap_last_cap());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* verify cap_last_cap() against syscall probing */
|
/* verify cap_last_cap() against syscall probing */
|
||||||
|
@ -64,7 +64,7 @@ static void test_last_cap_probe(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_se(p != 0);
|
assert_se(p != 0);
|
||||||
assert_se(p == cap_last_cap());
|
ASSERT_EQ(p, cap_last_cap());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fork_test(void (*test_func)(void)) {
|
static void fork_test(void (*test_func)(void)) {
|
||||||
|
@ -130,7 +130,7 @@ static void test_drop_privileges_keep_net_raw(void) {
|
||||||
show_capabilities();
|
show_capabilities();
|
||||||
|
|
||||||
sock = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
|
sock = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
|
||||||
assert_se(sock >= 0);
|
ASSERT_OK(sock);
|
||||||
safe_close(sock);
|
safe_close(sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ static void test_drop_privileges_dontkeep_net_raw(void) {
|
||||||
int sock;
|
int sock;
|
||||||
|
|
||||||
sock = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
|
sock = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
|
||||||
assert_se(sock >= 0);
|
ASSERT_OK(sock);
|
||||||
safe_close(sock);
|
safe_close(sock);
|
||||||
|
|
||||||
assert_se(drop_privileges(test_uid, test_gid, test_flags) >= 0);
|
assert_se(drop_privileges(test_uid, test_gid, test_flags) >= 0);
|
||||||
|
@ -147,7 +147,7 @@ static void test_drop_privileges_dontkeep_net_raw(void) {
|
||||||
show_capabilities();
|
show_capabilities();
|
||||||
|
|
||||||
sock = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
|
sock = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
|
||||||
assert_se(sock < 0);
|
ASSERT_LT(sock, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_drop_privileges_fail(void) {
|
static void test_drop_privileges_fail(void) {
|
||||||
|
@ -155,8 +155,8 @@ static void test_drop_privileges_fail(void) {
|
||||||
assert_se(getuid() == test_uid);
|
assert_se(getuid() == test_uid);
|
||||||
assert_se(getgid() == test_gid);
|
assert_se(getgid() == test_gid);
|
||||||
|
|
||||||
assert_se(drop_privileges(test_uid, test_gid, test_flags) < 0);
|
ASSERT_LT(drop_privileges(test_uid, test_gid, test_flags), 0);
|
||||||
assert_se(drop_privileges(0, 0, test_flags) < 0);
|
ASSERT_LT(drop_privileges(0, 0, test_flags), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_drop_privileges(void) {
|
static void test_drop_privileges(void) {
|
||||||
|
@ -172,14 +172,14 @@ static void test_drop_privileges(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_have_effective_cap(void) {
|
static void test_have_effective_cap(void) {
|
||||||
assert_se(have_effective_cap(CAP_KILL) > 0);
|
ASSERT_GT(have_effective_cap(CAP_KILL), 0);
|
||||||
assert_se(have_effective_cap(CAP_CHOWN) > 0);
|
ASSERT_GT(have_effective_cap(CAP_CHOWN), 0);
|
||||||
|
|
||||||
assert_se(drop_privileges(test_uid, test_gid, test_flags | (1ULL << CAP_KILL)) >= 0);
|
ASSERT_OK(drop_privileges(test_uid, test_gid, test_flags | (1ULL << CAP_KILL)));
|
||||||
assert_se(getuid() == test_uid);
|
assert_se(getuid() == test_uid);
|
||||||
assert_se(getgid() == test_gid);
|
assert_se(getgid() == test_gid);
|
||||||
|
|
||||||
assert_se(have_effective_cap(CAP_KILL) > 0);
|
ASSERT_GT(have_effective_cap(CAP_KILL), 0);
|
||||||
assert_se(have_effective_cap(CAP_CHOWN) == 0);
|
assert_se(have_effective_cap(CAP_CHOWN) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,9 +237,9 @@ static void test_ensure_cap_64_bit(void) {
|
||||||
r = read_one_line_file("/proc/sys/kernel/cap_last_cap", &content);
|
r = read_one_line_file("/proc/sys/kernel/cap_last_cap", &content);
|
||||||
if (r == -ENOENT || ERRNO_IS_NEG_PRIVILEGE(r)) /* kernel pre 3.2 or no access */
|
if (r == -ENOENT || ERRNO_IS_NEG_PRIVILEGE(r)) /* kernel pre 3.2 or no access */
|
||||||
return;
|
return;
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
assert_se(safe_atolu(content, &p) >= 0);
|
ASSERT_OK(safe_atolu(content, &p));
|
||||||
|
|
||||||
/* If caps don't fit into 64-bit anymore, we have a problem, fail the test. */
|
/* If caps don't fit into 64-bit anymore, we have a problem, fail the test. */
|
||||||
assert_se(p <= 63);
|
assert_se(p <= 63);
|
||||||
|
@ -252,10 +252,10 @@ static void test_capability_get_ambient(void) {
|
||||||
uint64_t c;
|
uint64_t c;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert_se(capability_get_ambient(&c) >= 0);
|
ASSERT_OK(capability_get_ambient(&c));
|
||||||
|
|
||||||
r = safe_fork("(getambient)", FORK_RESET_SIGNALS|FORK_DEATHSIG_SIGTERM|FORK_WAIT|FORK_LOG, NULL);
|
r = safe_fork("(getambient)", FORK_RESET_SIGNALS|FORK_DEATHSIG_SIGTERM|FORK_WAIT|FORK_LOG, NULL);
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
|
|
||||||
if (r == 0) {
|
if (r == 0) {
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
|
@ -20,9 +20,9 @@
|
||||||
static void log_cgroup_mask(CGroupMask got, CGroupMask expected) {
|
static void log_cgroup_mask(CGroupMask got, CGroupMask expected) {
|
||||||
_cleanup_free_ char *e_store = NULL, *g_store = NULL;
|
_cleanup_free_ char *e_store = NULL, *g_store = NULL;
|
||||||
|
|
||||||
assert_se(cg_mask_to_string(expected, &e_store) >= 0);
|
ASSERT_OK(cg_mask_to_string(expected, &e_store));
|
||||||
log_info("Expected mask: %s", e_store);
|
log_info("Expected mask: %s", e_store);
|
||||||
assert_se(cg_mask_to_string(got, &g_store) >= 0);
|
ASSERT_OK(cg_mask_to_string(got, &g_store));
|
||||||
log_info("Got mask: %s", g_store);
|
log_info("Got mask: %s", g_store);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,8 +39,8 @@ TEST_RET(cgroup_mask, .sd_booted = true) {
|
||||||
|
|
||||||
/* Prepare the manager. */
|
/* Prepare the manager. */
|
||||||
_cleanup_free_ char *unit_dir = NULL;
|
_cleanup_free_ char *unit_dir = NULL;
|
||||||
assert_se(get_testdata_dir("units", &unit_dir) >= 0);
|
ASSERT_OK(get_testdata_dir("units", &unit_dir));
|
||||||
assert_se(set_unit_path(unit_dir) >= 0);
|
ASSERT_OK(set_unit_path(unit_dir));
|
||||||
assert_se(runtime_dir = setup_fake_runtime_dir());
|
assert_se(runtime_dir = setup_fake_runtime_dir());
|
||||||
r = manager_new(RUNTIME_SCOPE_USER, MANAGER_TEST_RUN_BASIC, &m);
|
r = manager_new(RUNTIME_SCOPE_USER, MANAGER_TEST_RUN_BASIC, &m);
|
||||||
if (IN_SET(r, -EPERM, -EACCES)) {
|
if (IN_SET(r, -EPERM, -EACCES)) {
|
||||||
|
@ -63,13 +63,13 @@ TEST_RET(cgroup_mask, .sd_booted = true) {
|
||||||
assert_se(manager_startup(m, NULL, NULL, NULL) >= 0);
|
assert_se(manager_startup(m, NULL, NULL, NULL) >= 0);
|
||||||
|
|
||||||
/* Load units and verify hierarchy. */
|
/* Load units and verify hierarchy. */
|
||||||
assert_se(manager_load_startable_unit_or_warn(m, "parent.slice", NULL, &parent) >= 0);
|
ASSERT_OK(manager_load_startable_unit_or_warn(m, "parent.slice", NULL, &parent));
|
||||||
assert_se(manager_load_startable_unit_or_warn(m, "son.service", NULL, &son) >= 0);
|
ASSERT_OK(manager_load_startable_unit_or_warn(m, "son.service", NULL, &son));
|
||||||
assert_se(manager_load_startable_unit_or_warn(m, "daughter.service", NULL, &daughter) >= 0);
|
ASSERT_OK(manager_load_startable_unit_or_warn(m, "daughter.service", NULL, &daughter));
|
||||||
assert_se(manager_load_startable_unit_or_warn(m, "grandchild.service", NULL, &grandchild) >= 0);
|
ASSERT_OK(manager_load_startable_unit_or_warn(m, "grandchild.service", NULL, &grandchild));
|
||||||
assert_se(manager_load_startable_unit_or_warn(m, "parent-deep.slice", NULL, &parent_deep) >= 0);
|
ASSERT_OK(manager_load_startable_unit_or_warn(m, "parent-deep.slice", NULL, &parent_deep));
|
||||||
assert_se(manager_load_startable_unit_or_warn(m, "nomem.slice", NULL, &nomem_parent) >= 0);
|
ASSERT_OK(manager_load_startable_unit_or_warn(m, "nomem.slice", NULL, &nomem_parent));
|
||||||
assert_se(manager_load_startable_unit_or_warn(m, "nomemleaf.service", NULL, &nomem_leaf) >= 0);
|
ASSERT_OK(manager_load_startable_unit_or_warn(m, "nomemleaf.service", NULL, &nomem_leaf));
|
||||||
assert_se(UNIT_GET_SLICE(son) == parent);
|
assert_se(UNIT_GET_SLICE(son) == parent);
|
||||||
assert_se(UNIT_GET_SLICE(daughter) == parent);
|
assert_se(UNIT_GET_SLICE(daughter) == parent);
|
||||||
assert_se(UNIT_GET_SLICE(parent_deep) == parent);
|
assert_se(UNIT_GET_SLICE(parent_deep) == parent);
|
||||||
|
|
|
@ -14,7 +14,7 @@ static void test_is_wanted_print_one(bool header) {
|
||||||
_cleanup_free_ char *cmdline = NULL;
|
_cleanup_free_ char *cmdline = NULL;
|
||||||
|
|
||||||
log_info("-- %s --", __func__);
|
log_info("-- %s --", __func__);
|
||||||
assert_se(proc_cmdline(&cmdline) >= 0);
|
ASSERT_OK(proc_cmdline(&cmdline));
|
||||||
log_info("cmdline: %s", cmdline);
|
log_info("cmdline: %s", cmdline);
|
||||||
if (header)
|
if (header)
|
||||||
(void) system("findmnt -n /sys/fs/cgroup");
|
(void) system("findmnt -n /sys/fs/cgroup");
|
||||||
|
@ -31,33 +31,33 @@ TEST(is_wanted_print) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(is_wanted) {
|
TEST(is_wanted) {
|
||||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
ASSERT_OK(setenv("SYSTEMD_PROC_CMDLINE",
|
||||||
"systemd.unified_cgroup_hierarchy", 1) >= 0);
|
"systemd.unified_cgroup_hierarchy", 1));
|
||||||
test_is_wanted_print_one(false);
|
test_is_wanted_print_one(false);
|
||||||
|
|
||||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
ASSERT_OK(setenv("SYSTEMD_PROC_CMDLINE",
|
||||||
"systemd.unified_cgroup_hierarchy=0", 1) >= 0);
|
"systemd.unified_cgroup_hierarchy=0", 1));
|
||||||
test_is_wanted_print_one(false);
|
test_is_wanted_print_one(false);
|
||||||
|
|
||||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
ASSERT_OK(setenv("SYSTEMD_PROC_CMDLINE",
|
||||||
"systemd.unified_cgroup_hierarchy=0 "
|
"systemd.unified_cgroup_hierarchy=0 "
|
||||||
"systemd.legacy_systemd_cgroup_controller", 1) >= 0);
|
"systemd.legacy_systemd_cgroup_controller", 1));
|
||||||
test_is_wanted_print_one(false);
|
test_is_wanted_print_one(false);
|
||||||
|
|
||||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
ASSERT_OK(setenv("SYSTEMD_PROC_CMDLINE",
|
||||||
"systemd.unified_cgroup_hierarchy=0 "
|
"systemd.unified_cgroup_hierarchy=0 "
|
||||||
"systemd.legacy_systemd_cgroup_controller=0", 1) >= 0);
|
"systemd.legacy_systemd_cgroup_controller=0", 1));
|
||||||
test_is_wanted_print_one(false);
|
test_is_wanted_print_one(false);
|
||||||
|
|
||||||
/* cgroup_no_v1=all implies unified cgroup hierarchy, unless otherwise
|
/* cgroup_no_v1=all implies unified cgroup hierarchy, unless otherwise
|
||||||
* explicitly specified. */
|
* explicitly specified. */
|
||||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
ASSERT_OK(setenv("SYSTEMD_PROC_CMDLINE",
|
||||||
"cgroup_no_v1=all", 1) >= 0);
|
"cgroup_no_v1=all", 1));
|
||||||
test_is_wanted_print_one(false);
|
test_is_wanted_print_one(false);
|
||||||
|
|
||||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
ASSERT_OK(setenv("SYSTEMD_PROC_CMDLINE",
|
||||||
"cgroup_no_v1=all "
|
"cgroup_no_v1=all "
|
||||||
"systemd.unified_cgroup_hierarchy=0", 1) >= 0);
|
"systemd.unified_cgroup_hierarchy=0", 1));
|
||||||
test_is_wanted_print_one(false);
|
test_is_wanted_print_one(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,8 @@ TEST_RET(default_memory_low, .sd_booted = true) {
|
||||||
return log_tests_skipped("cgroupfs not available");
|
return log_tests_skipped("cgroupfs not available");
|
||||||
|
|
||||||
_cleanup_free_ char *unit_dir = NULL;
|
_cleanup_free_ char *unit_dir = NULL;
|
||||||
assert_se(get_testdata_dir("units", &unit_dir) >= 0);
|
ASSERT_OK(get_testdata_dir("units", &unit_dir));
|
||||||
assert_se(set_unit_path(unit_dir) >= 0);
|
ASSERT_OK(set_unit_path(unit_dir));
|
||||||
assert_se(runtime_dir = setup_fake_runtime_dir());
|
assert_se(runtime_dir = setup_fake_runtime_dir());
|
||||||
r = manager_new(RUNTIME_SCOPE_USER, MANAGER_TEST_RUN_BASIC, &m);
|
r = manager_new(RUNTIME_SCOPE_USER, MANAGER_TEST_RUN_BASIC, &m);
|
||||||
if (IN_SET(r, -EPERM, -EACCES)) {
|
if (IN_SET(r, -EPERM, -EACCES)) {
|
||||||
|
@ -32,8 +32,8 @@ TEST_RET(default_memory_low, .sd_booted = true) {
|
||||||
return log_tests_skipped("cannot create manager");
|
return log_tests_skipped("cannot create manager");
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
assert_se(manager_startup(m, NULL, NULL, NULL) >= 0);
|
ASSERT_OK(manager_startup(m, NULL, NULL, NULL));
|
||||||
|
|
||||||
/* dml.slice has DefaultMemoryLow=50. Beyond that, individual subhierarchies look like this:
|
/* dml.slice has DefaultMemoryLow=50. Beyond that, individual subhierarchies look like this:
|
||||||
*
|
*
|
||||||
|
@ -88,27 +88,27 @@ TEST_RET(default_memory_low, .sd_booted = true) {
|
||||||
* │ dml-discard-empty.service │ │ dml-discard-set-ml.service │
|
* │ dml-discard-empty.service │ │ dml-discard-set-ml.service │
|
||||||
* └───────────────────────────┘ └────────────────────────────┘
|
* └───────────────────────────┘ └────────────────────────────┘
|
||||||
*/
|
*/
|
||||||
assert_se(manager_load_startable_unit_or_warn(m, "dml.slice", NULL, &dml) >= 0);
|
ASSERT_OK(manager_load_startable_unit_or_warn(m, "dml.slice", NULL, &dml));
|
||||||
|
|
||||||
assert_se(manager_load_startable_unit_or_warn(m, "dml-passthrough.slice", NULL, &dml_passthrough) >= 0);
|
ASSERT_OK(manager_load_startable_unit_or_warn(m, "dml-passthrough.slice", NULL, &dml_passthrough));
|
||||||
assert_se(UNIT_GET_SLICE(dml_passthrough) == dml);
|
assert_se(UNIT_GET_SLICE(dml_passthrough) == dml);
|
||||||
assert_se(manager_load_startable_unit_or_warn(m, "dml-passthrough-empty.service", NULL, &dml_passthrough_empty) >= 0);
|
ASSERT_OK(manager_load_startable_unit_or_warn(m, "dml-passthrough-empty.service", NULL, &dml_passthrough_empty));
|
||||||
assert_se(UNIT_GET_SLICE(dml_passthrough_empty) == dml_passthrough);
|
assert_se(UNIT_GET_SLICE(dml_passthrough_empty) == dml_passthrough);
|
||||||
assert_se(manager_load_startable_unit_or_warn(m, "dml-passthrough-set-dml.service", NULL, &dml_passthrough_set_dml) >= 0);
|
ASSERT_OK(manager_load_startable_unit_or_warn(m, "dml-passthrough-set-dml.service", NULL, &dml_passthrough_set_dml));
|
||||||
assert_se(UNIT_GET_SLICE(dml_passthrough_set_dml) == dml_passthrough);
|
assert_se(UNIT_GET_SLICE(dml_passthrough_set_dml) == dml_passthrough);
|
||||||
assert_se(manager_load_startable_unit_or_warn(m, "dml-passthrough-set-ml.service", NULL, &dml_passthrough_set_ml) >= 0);
|
ASSERT_OK(manager_load_startable_unit_or_warn(m, "dml-passthrough-set-ml.service", NULL, &dml_passthrough_set_ml));
|
||||||
assert_se(UNIT_GET_SLICE(dml_passthrough_set_ml) == dml_passthrough);
|
assert_se(UNIT_GET_SLICE(dml_passthrough_set_ml) == dml_passthrough);
|
||||||
|
|
||||||
assert_se(manager_load_startable_unit_or_warn(m, "dml-override.slice", NULL, &dml_override) >= 0);
|
ASSERT_OK(manager_load_startable_unit_or_warn(m, "dml-override.slice", NULL, &dml_override));
|
||||||
assert_se(UNIT_GET_SLICE(dml_override) == dml);
|
assert_se(UNIT_GET_SLICE(dml_override) == dml);
|
||||||
assert_se(manager_load_startable_unit_or_warn(m, "dml-override-empty.service", NULL, &dml_override_empty) >= 0);
|
ASSERT_OK(manager_load_startable_unit_or_warn(m, "dml-override-empty.service", NULL, &dml_override_empty));
|
||||||
assert_se(UNIT_GET_SLICE(dml_override_empty) == dml_override);
|
assert_se(UNIT_GET_SLICE(dml_override_empty) == dml_override);
|
||||||
|
|
||||||
assert_se(manager_load_startable_unit_or_warn(m, "dml-discard.slice", NULL, &dml_discard) >= 0);
|
ASSERT_OK(manager_load_startable_unit_or_warn(m, "dml-discard.slice", NULL, &dml_discard));
|
||||||
assert_se(UNIT_GET_SLICE(dml_discard) == dml);
|
assert_se(UNIT_GET_SLICE(dml_discard) == dml);
|
||||||
assert_se(manager_load_startable_unit_or_warn(m, "dml-discard-empty.service", NULL, &dml_discard_empty) >= 0);
|
ASSERT_OK(manager_load_startable_unit_or_warn(m, "dml-discard-empty.service", NULL, &dml_discard_empty));
|
||||||
assert_se(UNIT_GET_SLICE(dml_discard_empty) == dml_discard);
|
assert_se(UNIT_GET_SLICE(dml_discard_empty) == dml_discard);
|
||||||
assert_se(manager_load_startable_unit_or_warn(m, "dml-discard-set-ml.service", NULL, &dml_discard_set_ml) >= 0);
|
ASSERT_OK(manager_load_startable_unit_or_warn(m, "dml-discard-set-ml.service", NULL, &dml_discard_set_ml));
|
||||||
assert_se(UNIT_GET_SLICE(dml_discard_set_ml) == dml_discard);
|
assert_se(UNIT_GET_SLICE(dml_discard_set_ml) == dml_discard);
|
||||||
|
|
||||||
assert_se(root = UNIT_GET_SLICE(dml));
|
assert_se(root = UNIT_GET_SLICE(dml));
|
||||||
|
|
|
@ -194,7 +194,7 @@ TEST(proc) {
|
||||||
_cleanup_closedir_ DIR *d = NULL;
|
_cleanup_closedir_ DIR *d = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert_se(proc_dir_open(&d) >= 0);
|
ASSERT_OK(proc_dir_open(&d));
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
_cleanup_free_ char *path = NULL, *path_shifted = NULL, *session = NULL, *unit = NULL, *user_unit = NULL, *machine = NULL, *slice = NULL;
|
_cleanup_free_ char *path = NULL, *path_shifted = NULL, *session = NULL, *unit = NULL, *user_unit = NULL, *machine = NULL, *slice = NULL;
|
||||||
|
@ -238,7 +238,7 @@ static void test_escape_one(const char *s, const char *expected) {
|
||||||
assert_se(s);
|
assert_se(s);
|
||||||
assert_se(expected);
|
assert_se(expected);
|
||||||
|
|
||||||
assert_se(cg_escape(s, &b) >= 0);
|
ASSERT_OK(cg_escape(s, &b));
|
||||||
assert_se(streq(b, expected));
|
assert_se(streq(b, expected));
|
||||||
|
|
||||||
assert_se(streq(cg_unescape(b), s));
|
assert_se(streq(cg_unescape(b), s));
|
||||||
|
@ -315,7 +315,7 @@ TEST(slice_to_path) {
|
||||||
static void test_shift_path_one(const char *raw, const char *root, const char *shifted) {
|
static void test_shift_path_one(const char *raw, const char *root, const char *shifted) {
|
||||||
const char *s = NULL;
|
const char *s = NULL;
|
||||||
|
|
||||||
assert_se(cg_shift_path(raw, root, &s) >= 0);
|
ASSERT_OK(cg_shift_path(raw, root, &s));
|
||||||
assert_se(streq(s, shifted));
|
assert_se(streq(s, shifted));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,7 +329,7 @@ TEST(shift_path) {
|
||||||
TEST(mask_supported, .sd_booted = true) {
|
TEST(mask_supported, .sd_booted = true) {
|
||||||
CGroupMask m;
|
CGroupMask m;
|
||||||
|
|
||||||
assert_se(cg_mask_supported(&m) >= 0);
|
ASSERT_OK(cg_mask_supported(&m));
|
||||||
|
|
||||||
for (CGroupController c = 0; c < _CGROUP_CONTROLLER_MAX; c++)
|
for (CGroupController c = 0; c < _CGROUP_CONTROLLER_MAX; c++)
|
||||||
printf("'%s' is supported: %s\n",
|
printf("'%s' is supported: %s\n",
|
||||||
|
|
|
@ -26,8 +26,8 @@ static void test_chase_extract_filename_one(const char *path, const char *root,
|
||||||
assert_se(streq(ret1, expected));
|
assert_se(streq(ret1, expected));
|
||||||
|
|
||||||
assert_se(chase(path, root, 0, &ret2, NULL) > 0);
|
assert_se(chase(path, root, 0, &ret2, NULL) > 0);
|
||||||
assert_se(chase_extract_filename(ret2, root, &fname) >= 0);
|
ASSERT_OK(chase_extract_filename(ret2, root, &fname));
|
||||||
assert_se(streq(fname, expected));
|
ASSERT_STREQ(fname, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(chase) {
|
TEST(chase) {
|
||||||
|
@ -42,7 +42,7 @@ TEST(chase) {
|
||||||
assert_se(mkdtemp(temp));
|
assert_se(mkdtemp(temp));
|
||||||
|
|
||||||
top = strjoina(temp, "/top");
|
top = strjoina(temp, "/top");
|
||||||
assert_se(mkdir(top, 0700) >= 0);
|
ASSERT_OK(mkdir(top, 0700));
|
||||||
|
|
||||||
p = strjoina(top, "/dot");
|
p = strjoina(top, "/dot");
|
||||||
if (symlink(".", p) < 0) {
|
if (symlink(".", p) < 0) {
|
||||||
|
@ -52,19 +52,19 @@ TEST(chase) {
|
||||||
};
|
};
|
||||||
|
|
||||||
p = strjoina(top, "/dotdot");
|
p = strjoina(top, "/dotdot");
|
||||||
assert_se(symlink("..", p) >= 0);
|
ASSERT_OK(symlink("..", p));
|
||||||
|
|
||||||
p = strjoina(top, "/dotdota");
|
p = strjoina(top, "/dotdota");
|
||||||
assert_se(symlink("../a", p) >= 0);
|
ASSERT_OK(symlink("../a", p));
|
||||||
|
|
||||||
p = strjoina(temp, "/a");
|
p = strjoina(temp, "/a");
|
||||||
assert_se(symlink("b", p) >= 0);
|
ASSERT_OK(symlink("b", p));
|
||||||
|
|
||||||
p = strjoina(temp, "/b");
|
p = strjoina(temp, "/b");
|
||||||
assert_se(symlink("/usr", p) >= 0);
|
ASSERT_OK(symlink("/usr", p));
|
||||||
|
|
||||||
p = strjoina(temp, "/start");
|
p = strjoina(temp, "/start");
|
||||||
assert_se(symlink("top/dot/dotdota", p) >= 0);
|
ASSERT_OK(symlink("top/dot/dotdota", p));
|
||||||
|
|
||||||
/* Paths that use symlinks underneath the "root" */
|
/* Paths that use symlinks underneath the "root" */
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ TEST(chase) {
|
||||||
assert_se(path_equal(result, qslash));
|
assert_se(path_equal(result, qslash));
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
assert_se(mkdir(q, 0700) >= 0);
|
ASSERT_OK(mkdir(q, 0700));
|
||||||
|
|
||||||
r = chase(p, temp, 0, &result, NULL);
|
r = chase(p, temp, 0, &result, NULL);
|
||||||
assert_se(r > 0);
|
assert_se(r > 0);
|
||||||
|
@ -145,21 +145,21 @@ TEST(chase) {
|
||||||
/* Paths that would "escape" outside of the "root" */
|
/* Paths that would "escape" outside of the "root" */
|
||||||
|
|
||||||
p = strjoina(temp, "/6dots");
|
p = strjoina(temp, "/6dots");
|
||||||
assert_se(symlink("../../..", p) >= 0);
|
ASSERT_OK(symlink("../../..", p));
|
||||||
|
|
||||||
r = chase(p, temp, 0, &result, NULL);
|
r = chase(p, temp, 0, &result, NULL);
|
||||||
assert_se(r > 0 && path_equal(result, temp));
|
assert_se(r > 0 && path_equal(result, temp));
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
p = strjoina(temp, "/6dotsusr");
|
p = strjoina(temp, "/6dotsusr");
|
||||||
assert_se(symlink("../../../usr", p) >= 0);
|
ASSERT_OK(symlink("../../../usr", p));
|
||||||
|
|
||||||
r = chase(p, temp, 0, &result, NULL);
|
r = chase(p, temp, 0, &result, NULL);
|
||||||
assert_se(r > 0 && path_equal(result, q));
|
assert_se(r > 0 && path_equal(result, q));
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
p = strjoina(temp, "/top/8dotsusr");
|
p = strjoina(temp, "/top/8dotsusr");
|
||||||
assert_se(symlink("../../../../usr", p) >= 0);
|
ASSERT_OK(symlink("../../../../usr", p));
|
||||||
|
|
||||||
r = chase(p, temp, 0, &result, NULL);
|
r = chase(p, temp, 0, &result, NULL);
|
||||||
assert_se(r > 0 && path_equal(result, q));
|
assert_se(r > 0 && path_equal(result, q));
|
||||||
|
@ -168,7 +168,7 @@ TEST(chase) {
|
||||||
/* Paths that contain repeated slashes */
|
/* Paths that contain repeated slashes */
|
||||||
|
|
||||||
p = strjoina(temp, "/slashslash");
|
p = strjoina(temp, "/slashslash");
|
||||||
assert_se(symlink("///usr///", p) >= 0);
|
ASSERT_OK(symlink("///usr///", p));
|
||||||
|
|
||||||
r = chase(p, NULL, 0, &result, NULL);
|
r = chase(p, NULL, 0, &result, NULL);
|
||||||
assert_se(r > 0);
|
assert_se(r > 0);
|
||||||
|
@ -185,14 +185,14 @@ TEST(chase) {
|
||||||
|
|
||||||
if (geteuid() == 0) {
|
if (geteuid() == 0) {
|
||||||
p = strjoina(temp, "/user");
|
p = strjoina(temp, "/user");
|
||||||
assert_se(mkdir(p, 0755) >= 0);
|
ASSERT_OK(mkdir(p, 0755));
|
||||||
assert_se(chown(p, UID_NOBODY, GID_NOBODY) >= 0);
|
ASSERT_OK(chown(p, UID_NOBODY, GID_NOBODY));
|
||||||
|
|
||||||
q = strjoina(temp, "/user/root");
|
q = strjoina(temp, "/user/root");
|
||||||
assert_se(mkdir(q, 0755) >= 0);
|
ASSERT_OK(mkdir(q, 0755));
|
||||||
|
|
||||||
p = strjoina(q, "/link");
|
p = strjoina(q, "/link");
|
||||||
assert_se(symlink("/", p) >= 0);
|
ASSERT_OK(symlink("/", p));
|
||||||
|
|
||||||
/* Fail when user-owned directories contain root-owned subdirectories. */
|
/* Fail when user-owned directories contain root-owned subdirectories. */
|
||||||
r = chase(p, temp, CHASE_SAFE, &result, NULL);
|
r = chase(p, temp, CHASE_SAFE, &result, NULL);
|
||||||
|
@ -218,22 +218,22 @@ TEST(chase) {
|
||||||
|
|
||||||
r = chase("/../.././//../../etc", NULL, 0, &result, NULL);
|
r = chase("/../.././//../../etc", NULL, 0, &result, NULL);
|
||||||
assert_se(r > 0);
|
assert_se(r > 0);
|
||||||
assert_se(streq(result, "/etc"));
|
ASSERT_STREQ(result, "/etc");
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
r = chase("/../.././//../../test-chase.fsldajfl", NULL, CHASE_NONEXISTENT, &result, NULL);
|
r = chase("/../.././//../../test-chase.fsldajfl", NULL, CHASE_NONEXISTENT, &result, NULL);
|
||||||
assert_se(r == 0);
|
assert_se(r == 0);
|
||||||
assert_se(streq(result, "/test-chase.fsldajfl"));
|
ASSERT_STREQ(result, "/test-chase.fsldajfl");
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
r = chase("/../.././//../../etc", "/", CHASE_PREFIX_ROOT, &result, NULL);
|
r = chase("/../.././//../../etc", "/", CHASE_PREFIX_ROOT, &result, NULL);
|
||||||
assert_se(r > 0);
|
assert_se(r > 0);
|
||||||
assert_se(streq(result, "/etc"));
|
ASSERT_STREQ(result, "/etc");
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
r = chase("/../.././//../../test-chase.fsldajfl", "/", CHASE_PREFIX_ROOT|CHASE_NONEXISTENT, &result, NULL);
|
r = chase("/../.././//../../test-chase.fsldajfl", "/", CHASE_PREFIX_ROOT|CHASE_NONEXISTENT, &result, NULL);
|
||||||
assert_se(r == 0);
|
assert_se(r == 0);
|
||||||
assert_se(streq(result, "/test-chase.fsldajfl"));
|
ASSERT_STREQ(result, "/test-chase.fsldajfl");
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
r = chase("/etc/machine-id/foo", NULL, 0, &result, NULL);
|
r = chase("/etc/machine-id/foo", NULL, 0, &result, NULL);
|
||||||
|
@ -243,7 +243,7 @@ TEST(chase) {
|
||||||
/* Path that loops back to self */
|
/* Path that loops back to self */
|
||||||
|
|
||||||
p = strjoina(temp, "/recursive-symlink");
|
p = strjoina(temp, "/recursive-symlink");
|
||||||
assert_se(symlink("recursive-symlink", p) >= 0);
|
ASSERT_OK(symlink("recursive-symlink", p));
|
||||||
r = chase(p, NULL, 0, &result, NULL);
|
r = chase(p, NULL, 0, &result, NULL);
|
||||||
assert_se(r == -ELOOP);
|
assert_se(r == -ELOOP);
|
||||||
|
|
||||||
|
@ -269,9 +269,9 @@ TEST(chase) {
|
||||||
|
|
||||||
/* Relative paths */
|
/* Relative paths */
|
||||||
|
|
||||||
assert_se(safe_getcwd(&pwd) >= 0);
|
ASSERT_OK(safe_getcwd(&pwd));
|
||||||
|
|
||||||
assert_se(chdir(temp) >= 0);
|
ASSERT_OK(chdir(temp));
|
||||||
|
|
||||||
p = "this/is/a/relative/path";
|
p = "this/is/a/relative/path";
|
||||||
r = chase(p, NULL, CHASE_NONEXISTENT, &result, NULL);
|
r = chase(p, NULL, CHASE_NONEXISTENT, &result, NULL);
|
||||||
|
@ -309,46 +309,46 @@ TEST(chase) {
|
||||||
|
|
||||||
if (geteuid() == 0) {
|
if (geteuid() == 0) {
|
||||||
p = strjoina(temp, "/priv1");
|
p = strjoina(temp, "/priv1");
|
||||||
assert_se(mkdir(p, 0755) >= 0);
|
ASSERT_OK(mkdir(p, 0755));
|
||||||
|
|
||||||
q = strjoina(p, "/priv2");
|
q = strjoina(p, "/priv2");
|
||||||
assert_se(mkdir(q, 0755) >= 0);
|
ASSERT_OK(mkdir(q, 0755));
|
||||||
|
|
||||||
assert_se(chase(q, NULL, CHASE_SAFE, NULL, NULL) >= 0);
|
ASSERT_OK(chase(q, NULL, CHASE_SAFE, NULL, NULL));
|
||||||
|
|
||||||
assert_se(chown(q, UID_NOBODY, GID_NOBODY) >= 0);
|
ASSERT_OK(chown(q, UID_NOBODY, GID_NOBODY));
|
||||||
assert_se(chase(q, NULL, CHASE_SAFE, NULL, NULL) >= 0);
|
ASSERT_OK(chase(q, NULL, CHASE_SAFE, NULL, NULL));
|
||||||
|
|
||||||
assert_se(chown(p, UID_NOBODY, GID_NOBODY) >= 0);
|
ASSERT_OK(chown(p, UID_NOBODY, GID_NOBODY));
|
||||||
assert_se(chase(q, NULL, CHASE_SAFE, NULL, NULL) >= 0);
|
ASSERT_OK(chase(q, NULL, CHASE_SAFE, NULL, NULL));
|
||||||
|
|
||||||
assert_se(chown(q, 0, 0) >= 0);
|
assert_se(chown(q, 0, 0) >= 0);
|
||||||
assert_se(chase(q, NULL, CHASE_SAFE, NULL, NULL) == -ENOLINK);
|
assert_se(chase(q, NULL, CHASE_SAFE, NULL, NULL) == -ENOLINK);
|
||||||
|
|
||||||
assert_se(rmdir(q) >= 0);
|
ASSERT_OK(rmdir(q));
|
||||||
assert_se(symlink("/etc/passwd", q) >= 0);
|
ASSERT_OK(symlink("/etc/passwd", q));
|
||||||
assert_se(chase(q, NULL, CHASE_SAFE, NULL, NULL) == -ENOLINK);
|
assert_se(chase(q, NULL, CHASE_SAFE, NULL, NULL) == -ENOLINK);
|
||||||
|
|
||||||
assert_se(chown(p, 0, 0) >= 0);
|
assert_se(chown(p, 0, 0) >= 0);
|
||||||
assert_se(chase(q, NULL, CHASE_SAFE, NULL, NULL) >= 0);
|
ASSERT_OK(chase(q, NULL, CHASE_SAFE, NULL, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
p = strjoina(temp, "/machine-id-test");
|
p = strjoina(temp, "/machine-id-test");
|
||||||
assert_se(symlink("/usr/../etc/./machine-id", p) >= 0);
|
ASSERT_OK(symlink("/usr/../etc/./machine-id", p));
|
||||||
|
|
||||||
r = chase(p, NULL, 0, NULL, &pfd);
|
r = chase(p, NULL, 0, NULL, &pfd);
|
||||||
if (r != -ENOENT && sd_id128_get_machine(NULL) >= 0) {
|
if (r != -ENOENT && sd_id128_get_machine(NULL) >= 0) {
|
||||||
_cleanup_close_ int fd = -EBADF;
|
_cleanup_close_ int fd = -EBADF;
|
||||||
sd_id128_t a, b;
|
sd_id128_t a, b;
|
||||||
|
|
||||||
assert_se(pfd >= 0);
|
ASSERT_OK(pfd);
|
||||||
|
|
||||||
fd = fd_reopen(pfd, O_RDONLY|O_CLOEXEC);
|
fd = fd_reopen(pfd, O_RDONLY|O_CLOEXEC);
|
||||||
assert_se(fd >= 0);
|
ASSERT_OK(fd);
|
||||||
safe_close(pfd);
|
safe_close(pfd);
|
||||||
|
|
||||||
assert_se(id128_read_fd(fd, ID128_FORMAT_PLAIN, &a) >= 0);
|
ASSERT_OK(id128_read_fd(fd, ID128_FORMAT_PLAIN, &a));
|
||||||
assert_se(sd_id128_get_machine(&b) >= 0);
|
ASSERT_OK(sd_id128_get_machine(&b));
|
||||||
assert_se(sd_id128_equal(a, b));
|
assert_se(sd_id128_equal(a, b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -365,24 +365,24 @@ TEST(chase) {
|
||||||
q = strjoina(temp, "/symlink");
|
q = strjoina(temp, "/symlink");
|
||||||
assert_se(symlink(p, q) >= 0);
|
assert_se(symlink(p, q) >= 0);
|
||||||
r = chase(q, NULL, CHASE_NOFOLLOW, &result, &pfd);
|
r = chase(q, NULL, CHASE_NOFOLLOW, &result, &pfd);
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
assert_se(pfd >= 0);
|
ASSERT_OK(pfd);
|
||||||
assert_se(path_equal(result, q));
|
assert_se(path_equal(result, q));
|
||||||
assert_se(fstat(pfd, &st) >= 0);
|
ASSERT_OK(fstat(pfd, &st));
|
||||||
assert_se(S_ISLNK(st.st_mode));
|
assert_se(S_ISLNK(st.st_mode));
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
pfd = safe_close(pfd);
|
pfd = safe_close(pfd);
|
||||||
|
|
||||||
/* s1 -> s2 -> nonexistent */
|
/* s1 -> s2 -> nonexistent */
|
||||||
q = strjoina(temp, "/s1");
|
q = strjoina(temp, "/s1");
|
||||||
assert_se(symlink("s2", q) >= 0);
|
ASSERT_OK(symlink("s2", q));
|
||||||
p = strjoina(temp, "/s2");
|
p = strjoina(temp, "/s2");
|
||||||
assert_se(symlink("nonexistent", p) >= 0);
|
ASSERT_OK(symlink("nonexistent", p));
|
||||||
r = chase(q, NULL, CHASE_NOFOLLOW, &result, &pfd);
|
r = chase(q, NULL, CHASE_NOFOLLOW, &result, &pfd);
|
||||||
assert_se(r >= 0);
|
ASSERT_OK(r);
|
||||||
assert_se(pfd >= 0);
|
ASSERT_OK(pfd);
|
||||||
assert_se(path_equal(result, q));
|
assert_se(path_equal(result, q));
|
||||||
assert_se(fstat(pfd, &st) >= 0);
|
ASSERT_OK(fstat(pfd, &st));
|
||||||
assert_se(S_ISLNK(st.st_mode));
|
assert_se(S_ISLNK(st.st_mode));
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
pfd = safe_close(pfd);
|
pfd = safe_close(pfd);
|
||||||
|
@ -393,41 +393,41 @@ TEST(chase) {
|
||||||
r = chase(p, NULL, CHASE_STEP, &result, NULL);
|
r = chase(p, NULL, CHASE_STEP, &result, NULL);
|
||||||
assert_se(r == 0);
|
assert_se(r == 0);
|
||||||
p = strjoina(temp, "/top/dot/dotdota");
|
p = strjoina(temp, "/top/dot/dotdota");
|
||||||
assert_se(streq(p, result));
|
ASSERT_STREQ(p, result);
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
r = chase(p, NULL, CHASE_STEP, &result, NULL);
|
r = chase(p, NULL, CHASE_STEP, &result, NULL);
|
||||||
assert_se(r == 0);
|
assert_se(r == 0);
|
||||||
p = strjoina(temp, "/top/dotdota");
|
p = strjoina(temp, "/top/dotdota");
|
||||||
assert_se(streq(p, result));
|
ASSERT_STREQ(p, result);
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
r = chase(p, NULL, CHASE_STEP, &result, NULL);
|
r = chase(p, NULL, CHASE_STEP, &result, NULL);
|
||||||
assert_se(r == 0);
|
assert_se(r == 0);
|
||||||
p = strjoina(temp, "/top/../a");
|
p = strjoina(temp, "/top/../a");
|
||||||
assert_se(streq(p, result));
|
ASSERT_STREQ(p, result);
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
r = chase(p, NULL, CHASE_STEP, &result, NULL);
|
r = chase(p, NULL, CHASE_STEP, &result, NULL);
|
||||||
assert_se(r == 0);
|
assert_se(r == 0);
|
||||||
p = strjoina(temp, "/a");
|
p = strjoina(temp, "/a");
|
||||||
assert_se(streq(p, result));
|
ASSERT_STREQ(p, result);
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
r = chase(p, NULL, CHASE_STEP, &result, NULL);
|
r = chase(p, NULL, CHASE_STEP, &result, NULL);
|
||||||
assert_se(r == 0);
|
assert_se(r == 0);
|
||||||
p = strjoina(temp, "/b");
|
p = strjoina(temp, "/b");
|
||||||
assert_se(streq(p, result));
|
ASSERT_STREQ(p, result);
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
r = chase(p, NULL, CHASE_STEP, &result, NULL);
|
r = chase(p, NULL, CHASE_STEP, &result, NULL);
|
||||||
assert_se(r == 0);
|
assert_se(r == 0);
|
||||||
assert_se(streq("/usr", result));
|
ASSERT_STREQ("/usr", result);
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
r = chase("/usr", NULL, CHASE_STEP, &result, NULL);
|
r = chase("/usr", NULL, CHASE_STEP, &result, NULL);
|
||||||
assert_se(r > 0);
|
assert_se(r > 0);
|
||||||
assert_se(streq("/usr", result));
|
ASSERT_STREQ("/usr", result);
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
/* Make sure that symlinks in the "root" path are not resolved, but those below are */
|
/* Make sure that symlinks in the "root" path are not resolved, but those below are */
|
||||||
|
@ -449,7 +449,7 @@ TEST(chase) {
|
||||||
assert_se(chase("top/dot/dot", temp, CHASE_PREFIX_ROOT|CHASE_PROHIBIT_SYMLINKS|CHASE_WARN, NULL, NULL) == -EREMCHG);
|
assert_se(chase("top/dot/dot", temp, CHASE_PREFIX_ROOT|CHASE_PROHIBIT_SYMLINKS|CHASE_WARN, NULL, NULL) == -EREMCHG);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
assert_se(rm_rf(temp, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
|
ASSERT_OK(rm_rf(temp, REMOVE_ROOT|REMOVE_PHYSICAL));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(chaseat) {
|
TEST(chaseat) {
|
||||||
|
@ -461,29 +461,29 @@ TEST(chaseat) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
const char *p;
|
const char *p;
|
||||||
|
|
||||||
assert_se((tfd = mkdtemp_open(NULL, 0, &t)) >= 0);
|
ASSERT_OK((tfd = mkdtemp_open(NULL, 0, &t)));
|
||||||
|
|
||||||
/* Test that AT_FDCWD with CHASE_AT_RESOLVE_IN_ROOT resolves against / and not the current working
|
/* Test that AT_FDCWD with CHASE_AT_RESOLVE_IN_ROOT resolves against / and not the current working
|
||||||
* directory. */
|
* directory. */
|
||||||
|
|
||||||
assert_se(symlinkat("/usr", tfd, "abc") >= 0);
|
ASSERT_OK(symlinkat("/usr", tfd, "abc"));
|
||||||
|
|
||||||
p = strjoina(t, "/abc");
|
p = strjoina(t, "/abc");
|
||||||
assert_se(chaseat(AT_FDCWD, p, CHASE_AT_RESOLVE_IN_ROOT, &result, NULL) >= 0);
|
ASSERT_OK(chaseat(AT_FDCWD, p, CHASE_AT_RESOLVE_IN_ROOT, &result, NULL));
|
||||||
assert_se(streq(result, "/usr"));
|
ASSERT_STREQ(result, "/usr");
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
/* If the file descriptor points to the root directory, the result will be absolute. */
|
/* If the file descriptor points to the root directory, the result will be absolute. */
|
||||||
|
|
||||||
fd = open("/", O_CLOEXEC | O_DIRECTORY | O_PATH);
|
fd = open("/", O_CLOEXEC | O_DIRECTORY | O_PATH);
|
||||||
assert_se(fd >= 0);
|
ASSERT_OK(fd);
|
||||||
|
|
||||||
assert_se(chaseat(fd, p, 0, &result, NULL) >= 0);
|
ASSERT_OK(chaseat(fd, p, 0, &result, NULL));
|
||||||
assert_se(streq(result, "/usr"));
|
ASSERT_STREQ(result, "/usr");
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
assert_se(chaseat(fd, p, CHASE_AT_RESOLVE_IN_ROOT, &result, NULL) >= 0);
|
ASSERT_OK(chaseat(fd, p, CHASE_AT_RESOLVE_IN_ROOT, &result, NULL));
|
||||||
assert_se(streq(result, "/usr"));
|
ASSERT_STREQ(result, "/usr");
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
fd = safe_close(fd);
|
fd = safe_close(fd);
|
||||||
|
@ -491,36 +491,36 @@ TEST(chaseat) {
|
||||||
/* If the file descriptor does not point to the root directory, the result will be relative
|
/* If the file descriptor does not point to the root directory, the result will be relative
|
||||||
* unless the result is outside of the specified file descriptor. */
|
* unless the result is outside of the specified file descriptor. */
|
||||||
|
|
||||||
assert_se(chaseat(tfd, "abc", 0, &result, NULL) >= 0);
|
ASSERT_OK(chaseat(tfd, "abc", 0, &result, NULL));
|
||||||
assert_se(streq(result, "/usr"));
|
ASSERT_STREQ(result, "/usr");
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
assert_se(chaseat(tfd, "/abc", 0, &result, NULL) >= 0);
|
ASSERT_OK(chaseat(tfd, "/abc", 0, &result, NULL));
|
||||||
assert_se(streq(result, "/usr"));
|
ASSERT_STREQ(result, "/usr");
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
assert_se(chaseat(tfd, "abc", CHASE_AT_RESOLVE_IN_ROOT, NULL, NULL) == -ENOENT);
|
assert_se(chaseat(tfd, "abc", CHASE_AT_RESOLVE_IN_ROOT, NULL, NULL) == -ENOENT);
|
||||||
assert_se(chaseat(tfd, "/abc", CHASE_AT_RESOLVE_IN_ROOT, NULL, NULL) == -ENOENT);
|
assert_se(chaseat(tfd, "/abc", CHASE_AT_RESOLVE_IN_ROOT, NULL, NULL) == -ENOENT);
|
||||||
|
|
||||||
assert_se(chaseat(tfd, "abc", CHASE_AT_RESOLVE_IN_ROOT | CHASE_NONEXISTENT, &result, NULL) >= 0);
|
ASSERT_OK(chaseat(tfd, "abc", CHASE_AT_RESOLVE_IN_ROOT | CHASE_NONEXISTENT, &result, NULL));
|
||||||
assert_se(streq(result, "usr"));
|
ASSERT_STREQ(result, "usr");
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
assert_se(chaseat(tfd, "/abc", CHASE_AT_RESOLVE_IN_ROOT | CHASE_NONEXISTENT, &result, NULL) >= 0);
|
ASSERT_OK(chaseat(tfd, "/abc", CHASE_AT_RESOLVE_IN_ROOT | CHASE_NONEXISTENT, &result, NULL));
|
||||||
assert_se(streq(result, "usr"));
|
ASSERT_STREQ(result, "usr");
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
/* Test that absolute path or not are the same when resolving relative to a directory file
|
/* Test that absolute path or not are the same when resolving relative to a directory file
|
||||||
* descriptor and that we always get a relative path back. */
|
* descriptor and that we always get a relative path back. */
|
||||||
|
|
||||||
assert_se(fd = openat(tfd, "def", O_CREAT|O_CLOEXEC, 0700) >= 0);
|
ASSERT_OK(fd = openat(tfd, "def", O_CREAT|O_CLOEXEC, 0700));
|
||||||
fd = safe_close(fd);
|
fd = safe_close(fd);
|
||||||
assert_se(symlinkat("/def", tfd, "qed") >= 0);
|
ASSERT_OK(symlinkat("/def", tfd, "qed"));
|
||||||
assert_se(chaseat(tfd, "qed", CHASE_AT_RESOLVE_IN_ROOT, &result, NULL) >= 0);
|
ASSERT_OK(chaseat(tfd, "qed", CHASE_AT_RESOLVE_IN_ROOT, &result, NULL));
|
||||||
assert_se(streq(result, "def"));
|
ASSERT_STREQ(result, "def");
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
assert_se(chaseat(tfd, "/qed", CHASE_AT_RESOLVE_IN_ROOT, &result, NULL) >= 0);
|
ASSERT_OK(chaseat(tfd, "/qed", CHASE_AT_RESOLVE_IN_ROOT, &result, NULL));
|
||||||
assert_se(streq(result, "def"));
|
ASSERT_STREQ(result, "def");
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
/* Valid directory file descriptor without CHASE_AT_RESOLVE_IN_ROOT should resolve symlinks against
|
/* Valid directory file descriptor without CHASE_AT_RESOLVE_IN_ROOT should resolve symlinks against
|
||||||
|
@ -529,157 +529,157 @@ TEST(chaseat) {
|
||||||
|
|
||||||
/* Test CHASE_PARENT */
|
/* Test CHASE_PARENT */
|
||||||
|
|
||||||
assert_se((fd = open_mkdir_at(tfd, "chase", O_CLOEXEC, 0755)) >= 0);
|
ASSERT_OK((fd = open_mkdir_at(tfd, "chase", O_CLOEXEC, 0755)));
|
||||||
assert_se(symlinkat("/def", fd, "parent") >= 0);
|
ASSERT_OK(symlinkat("/def", fd, "parent"));
|
||||||
fd = safe_close(fd);
|
fd = safe_close(fd);
|
||||||
|
|
||||||
/* Make sure that when we chase a symlink parent directory, that we chase the parent directory of the
|
/* Make sure that when we chase a symlink parent directory, that we chase the parent directory of the
|
||||||
* symlink target and not the symlink itself. But if we add CHASE_NOFOLLOW, we get the parent
|
* symlink target and not the symlink itself. But if we add CHASE_NOFOLLOW, we get the parent
|
||||||
* directory of the symlink itself. */
|
* directory of the symlink itself. */
|
||||||
|
|
||||||
assert_se(chaseat(tfd, "chase/parent", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT, &result, &fd) >= 0);
|
ASSERT_OK(chaseat(tfd, "chase/parent", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT, &result, &fd));
|
||||||
assert_se(faccessat(fd, "def", F_OK, 0) >= 0);
|
ASSERT_OK(faccessat(fd, "def", F_OK, 0));
|
||||||
assert_se(streq(result, "def"));
|
ASSERT_STREQ(result, "def");
|
||||||
fd = safe_close(fd);
|
fd = safe_close(fd);
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
assert_se(chaseat(tfd, "chase/parent", CHASE_AT_RESOLVE_IN_ROOT|CHASE_PARENT|CHASE_NOFOLLOW, &result, &fd) >= 0);
|
ASSERT_OK(chaseat(tfd, "chase/parent", CHASE_AT_RESOLVE_IN_ROOT|CHASE_PARENT|CHASE_NOFOLLOW, &result, &fd));
|
||||||
assert_se(faccessat(fd, "parent", F_OK, AT_SYMLINK_NOFOLLOW) >= 0);
|
ASSERT_OK(faccessat(fd, "parent", F_OK, AT_SYMLINK_NOFOLLOW));
|
||||||
assert_se(streq(result, "chase/parent"));
|
ASSERT_STREQ(result, "chase/parent");
|
||||||
fd = safe_close(fd);
|
fd = safe_close(fd);
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
assert_se(chaseat(tfd, "chase", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT, &result, &fd) >= 0);
|
ASSERT_OK(chaseat(tfd, "chase", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT, &result, &fd));
|
||||||
assert_se(faccessat(fd, "chase", F_OK, 0) >= 0);
|
ASSERT_OK(faccessat(fd, "chase", F_OK, 0));
|
||||||
assert_se(streq(result, "chase"));
|
ASSERT_STREQ(result, "chase");
|
||||||
fd = safe_close(fd);
|
fd = safe_close(fd);
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
assert_se(chaseat(tfd, "/", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT, &result, NULL) >= 0);
|
ASSERT_OK(chaseat(tfd, "/", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT, &result, NULL));
|
||||||
assert_se(streq(result, "."));
|
ASSERT_STREQ(result, ".");
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
assert_se(chaseat(tfd, ".", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT, &result, NULL) >= 0);
|
assert_se(chaseat(tfd, ".", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT, &result, NULL));
|
||||||
assert_se(streq(result, "."));
|
ASSERT_STREQ(result, ".");
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
/* Test CHASE_MKDIR_0755 */
|
/* Test CHASE_MKDIR_0755 */
|
||||||
|
|
||||||
assert_se(chaseat(tfd, "m/k/d/i/r", CHASE_MKDIR_0755|CHASE_NONEXISTENT, &result, NULL) >= 0);
|
ASSERT_OK(chaseat(tfd, "m/k/d/i/r", CHASE_MKDIR_0755|CHASE_NONEXISTENT, &result, NULL));
|
||||||
assert_se(faccessat(tfd, "m/k/d/i", F_OK, 0) >= 0);
|
ASSERT_OK(faccessat(tfd, "m/k/d/i", F_OK, 0));
|
||||||
assert_se(RET_NERRNO(faccessat(tfd, "m/k/d/i/r", F_OK, 0)) == -ENOENT);
|
assert_se(RET_NERRNO(faccessat(tfd, "m/k/d/i/r", F_OK, 0)) == -ENOENT);
|
||||||
assert_se(streq(result, "m/k/d/i/r"));
|
ASSERT_STREQ(result, "m/k/d/i/r");
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
assert_se(chaseat(tfd, "m/../q", CHASE_MKDIR_0755|CHASE_NONEXISTENT, &result, NULL) >= 0);
|
ASSERT_OK(chaseat(tfd, "m/../q", CHASE_MKDIR_0755|CHASE_NONEXISTENT, &result, NULL));
|
||||||
assert_se(faccessat(tfd, "m", F_OK, 0) >= 0);
|
ASSERT_OK(faccessat(tfd, "m", F_OK, 0));
|
||||||
assert_se(RET_NERRNO(faccessat(tfd, "q", F_OK, 0)) == -ENOENT);
|
assert_se(RET_NERRNO(faccessat(tfd, "q", F_OK, 0)) == -ENOENT);
|
||||||
assert_se(streq(result, "q"));
|
ASSERT_STREQ(result, "q");
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
assert_se(chaseat(tfd, "i/../p", CHASE_MKDIR_0755|CHASE_NONEXISTENT, NULL, NULL) == -ENOENT);
|
assert_se(chaseat(tfd, "i/../p", CHASE_MKDIR_0755|CHASE_NONEXISTENT, NULL, NULL) == -ENOENT);
|
||||||
|
|
||||||
/* Test CHASE_EXTRACT_FILENAME */
|
/* Test CHASE_EXTRACT_FILENAME */
|
||||||
|
|
||||||
assert_se(chaseat(tfd, "chase/parent", CHASE_AT_RESOLVE_IN_ROOT|CHASE_PARENT|CHASE_NOFOLLOW|CHASE_EXTRACT_FILENAME, &result, &fd) >= 0);
|
ASSERT_OK(chaseat(tfd, "chase/parent", CHASE_AT_RESOLVE_IN_ROOT|CHASE_PARENT|CHASE_NOFOLLOW|CHASE_EXTRACT_FILENAME, &result, &fd));
|
||||||
assert_se(faccessat(fd, result, F_OK, AT_SYMLINK_NOFOLLOW) >= 0);
|
ASSERT_OK(faccessat(fd, result, F_OK, AT_SYMLINK_NOFOLLOW));
|
||||||
assert_se(streq(result, "parent"));
|
ASSERT_STREQ(result, "parent");
|
||||||
fd = safe_close(fd);
|
fd = safe_close(fd);
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
assert_se(chaseat(tfd, "chase", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT|CHASE_EXTRACT_FILENAME, &result, &fd) >= 0);
|
ASSERT_OK(chaseat(tfd, "chase", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT|CHASE_EXTRACT_FILENAME, &result, &fd));
|
||||||
assert_se(faccessat(fd, result, F_OK, 0) >= 0);
|
ASSERT_OK(faccessat(fd, result, F_OK, 0));
|
||||||
assert_se(streq(result, "chase"));
|
ASSERT_STREQ(result, "chase");
|
||||||
fd = safe_close(fd);
|
fd = safe_close(fd);
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
assert_se(chaseat(tfd, "/", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT|CHASE_EXTRACT_FILENAME, &result, NULL) >= 0);
|
ASSERT_OK(chaseat(tfd, "/", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT|CHASE_EXTRACT_FILENAME, &result, NULL));
|
||||||
assert_se(streq(result, "."));
|
ASSERT_STREQ(result, ".");
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
assert_se(chaseat(tfd, ".", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT|CHASE_EXTRACT_FILENAME, &result, NULL) >= 0);
|
ASSERT_OK(chaseat(tfd, ".", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT|CHASE_EXTRACT_FILENAME, &result, NULL));
|
||||||
assert_se(streq(result, "."));
|
ASSERT_STREQ(result, ".");
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
assert_se(chaseat(tfd, NULL, CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT|CHASE_EXTRACT_FILENAME, &result, NULL) >= 0);
|
ASSERT_OK(chaseat(tfd, NULL, CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT|CHASE_EXTRACT_FILENAME, &result, NULL));
|
||||||
assert_se(streq(result, "."));
|
ASSERT_STREQ(result, ".");
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
/* Test chase_and_openat() */
|
/* Test chase_and_openat() */
|
||||||
|
|
||||||
fd = chase_and_openat(tfd, "o/p/e/n/f/i/l/e", CHASE_MKDIR_0755, O_CREAT|O_EXCL|O_CLOEXEC, NULL);
|
fd = chase_and_openat(tfd, "o/p/e/n/f/i/l/e", CHASE_MKDIR_0755, O_CREAT|O_EXCL|O_CLOEXEC, NULL);
|
||||||
assert_se(fd >= 0);
|
ASSERT_OK(fd);
|
||||||
assert_se(fd_verify_regular(fd) >= 0);
|
ASSERT_OK(fd_verify_regular(fd));
|
||||||
fd = safe_close(fd);
|
fd = safe_close(fd);
|
||||||
|
|
||||||
fd = chase_and_openat(tfd, "o/p/e/n/d/i/r", CHASE_MKDIR_0755, O_DIRECTORY|O_CREAT|O_EXCL|O_CLOEXEC, NULL);
|
fd = chase_and_openat(tfd, "o/p/e/n/d/i/r", CHASE_MKDIR_0755, O_DIRECTORY|O_CREAT|O_EXCL|O_CLOEXEC, NULL);
|
||||||
assert_se(fd >= 0);
|
ASSERT_OK(fd);
|
||||||
assert_se(fd_verify_directory(fd) >= 0);
|
ASSERT_OK(fd_verify_directory(fd));
|
||||||
fd = safe_close(fd);
|
fd = safe_close(fd);
|
||||||
|
|
||||||
fd = chase_and_openat(tfd, NULL, CHASE_PARENT|CHASE_EXTRACT_FILENAME, O_PATH|O_DIRECTORY|O_CLOEXEC, &result);
|
fd = chase_and_openat(tfd, NULL, CHASE_PARENT|CHASE_EXTRACT_FILENAME, O_PATH|O_DIRECTORY|O_CLOEXEC, &result);
|
||||||
assert_se(fd >= 0);
|
ASSERT_OK(fd);
|
||||||
assert_se(streq(result, "."));
|
ASSERT_STREQ(result, ".");
|
||||||
fd = safe_close(fd);
|
fd = safe_close(fd);
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
/* Test chase_and_openatdir() */
|
/* Test chase_and_openatdir() */
|
||||||
|
|
||||||
assert_se(chase_and_opendirat(tfd, "o/p/e/n/d/i", 0, &result, &dir) >= 0);
|
ASSERT_OK(chase_and_opendirat(tfd, "o/p/e/n/d/i", 0, &result, &dir));
|
||||||
FOREACH_DIRENT(de, dir, assert_not_reached())
|
FOREACH_DIRENT(de, dir, assert_not_reached())
|
||||||
assert_se(streq(de->d_name, "r"));
|
ASSERT_STREQ(de->d_name, "r");
|
||||||
assert_se(streq(result, "o/p/e/n/d/i"));
|
ASSERT_STREQ(result, "o/p/e/n/d/i");
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
/* Test chase_and_statat() */
|
/* Test chase_and_statat() */
|
||||||
|
|
||||||
assert_se(chase_and_statat(tfd, "o/p", 0, &result, &st) >= 0);
|
ASSERT_OK(chase_and_statat(tfd, "o/p", 0, &result, &st));
|
||||||
assert_se(stat_verify_directory(&st) >= 0);
|
ASSERT_OK(stat_verify_directory(&st));
|
||||||
assert_se(streq(result, "o/p"));
|
ASSERT_STREQ(result, "o/p");
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
/* Test chase_and_accessat() */
|
/* Test chase_and_accessat() */
|
||||||
|
|
||||||
assert_se(chase_and_accessat(tfd, "o/p/e", 0, F_OK, &result) >= 0);
|
ASSERT_OK(chase_and_accessat(tfd, "o/p/e", 0, F_OK, &result));
|
||||||
assert_se(streq(result, "o/p/e"));
|
ASSERT_STREQ(result, "o/p/e");
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
/* Test chase_and_fopenat_unlocked() */
|
/* Test chase_and_fopenat_unlocked() */
|
||||||
|
|
||||||
assert_se(chase_and_fopenat_unlocked(tfd, "o/p/e/n/f/i/l/e", 0, "re", &result, &f) >= 0);
|
ASSERT_OK(chase_and_fopenat_unlocked(tfd, "o/p/e/n/f/i/l/e", 0, "re", &result, &f));
|
||||||
assert_se(fread(&(char[1]) {}, 1, 1, f) == 0);
|
assert_se(fread(&(char[1]) {}, 1, 1, f) == 0);
|
||||||
assert_se(feof(f));
|
assert_se(feof(f));
|
||||||
f = safe_fclose(f);
|
f = safe_fclose(f);
|
||||||
assert_se(streq(result, "o/p/e/n/f/i/l/e"));
|
ASSERT_STREQ(result, "o/p/e/n/f/i/l/e");
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
/* Test chase_and_unlinkat() */
|
/* Test chase_and_unlinkat() */
|
||||||
|
|
||||||
assert_se(chase_and_unlinkat(tfd, "o/p/e/n/f/i/l/e", 0, 0, &result) >= 0);
|
ASSERT_OK(chase_and_unlinkat(tfd, "o/p/e/n/f/i/l/e", 0, 0, &result));
|
||||||
assert_se(streq(result, "o/p/e/n/f/i/l/e"));
|
ASSERT_STREQ(result, "o/p/e/n/f/i/l/e");
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
/* Test chase_and_open_parent_at() */
|
/* Test chase_and_open_parent_at() */
|
||||||
|
|
||||||
assert_se((fd = chase_and_open_parent_at(tfd, "chase/parent", CHASE_AT_RESOLVE_IN_ROOT|CHASE_NOFOLLOW, &result)) >= 0);
|
ASSERT_OK((fd = chase_and_open_parent_at(tfd, "chase/parent", CHASE_AT_RESOLVE_IN_ROOT|CHASE_NOFOLLOW, &result)));
|
||||||
assert_se(faccessat(fd, result, F_OK, AT_SYMLINK_NOFOLLOW) >= 0);
|
ASSERT_OK(faccessat(fd, result, F_OK, AT_SYMLINK_NOFOLLOW));
|
||||||
assert_se(streq(result, "parent"));
|
ASSERT_STREQ(result, "parent");
|
||||||
fd = safe_close(fd);
|
fd = safe_close(fd);
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
assert_se((fd = chase_and_open_parent_at(tfd, "chase", CHASE_AT_RESOLVE_IN_ROOT, &result)) >= 0);
|
ASSERT_OK((fd = chase_and_open_parent_at(tfd, "chase", CHASE_AT_RESOLVE_IN_ROOT, &result)));
|
||||||
assert_se(faccessat(fd, result, F_OK, 0) >= 0);
|
ASSERT_OK(faccessat(fd, result, F_OK, 0));
|
||||||
assert_se(streq(result, "chase"));
|
ASSERT_STREQ(result, "chase");
|
||||||
fd = safe_close(fd);
|
fd = safe_close(fd);
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
assert_se((fd = chase_and_open_parent_at(tfd, "/", CHASE_AT_RESOLVE_IN_ROOT, &result)) >= 0);
|
ASSERT_OK((fd = chase_and_open_parent_at(tfd, "/", CHASE_AT_RESOLVE_IN_ROOT, &result)));
|
||||||
assert_se(streq(result, "."));
|
ASSERT_STREQ(result, ".");
|
||||||
fd = safe_close(fd);
|
fd = safe_close(fd);
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
|
|
||||||
assert_se((fd = chase_and_open_parent_at(tfd, ".", CHASE_AT_RESOLVE_IN_ROOT, &result)) >= 0);
|
ASSERT_OK((fd = chase_and_open_parent_at(tfd, ".", CHASE_AT_RESOLVE_IN_ROOT, &result)));
|
||||||
assert_se(streq(result, "."));
|
ASSERT_STREQ(result, ".");
|
||||||
fd = safe_close(fd);
|
fd = safe_close(fd);
|
||||||
result = mfree(result);
|
result = mfree(result);
|
||||||
}
|
}
|
||||||
|
@ -687,32 +687,32 @@ TEST(chaseat) {
|
||||||
TEST(chaseat_prefix_root) {
|
TEST(chaseat_prefix_root) {
|
||||||
_cleanup_free_ char *cwd = NULL, *ret = NULL, *expected = NULL;
|
_cleanup_free_ char *cwd = NULL, *ret = NULL, *expected = NULL;
|
||||||
|
|
||||||
assert_se(safe_getcwd(&cwd) >= 0);
|
ASSERT_OK(safe_getcwd(&cwd));
|
||||||
|
|
||||||
assert_se(chaseat_prefix_root("/hoge", NULL, &ret) >= 0);
|
ASSERT_OK(chaseat_prefix_root("/hoge", NULL, &ret));
|
||||||
assert_se(streq(ret, "/hoge"));
|
ASSERT_STREQ(ret, "/hoge");
|
||||||
|
|
||||||
ret = mfree(ret);
|
ret = mfree(ret);
|
||||||
|
|
||||||
assert_se(chaseat_prefix_root("/hoge", "a/b/c", &ret) >= 0);
|
ASSERT_OK(chaseat_prefix_root("/hoge", "a/b/c", &ret));
|
||||||
assert_se(streq(ret, "/hoge"));
|
ASSERT_STREQ(ret, "/hoge");
|
||||||
|
|
||||||
ret = mfree(ret);
|
ret = mfree(ret);
|
||||||
|
|
||||||
assert_se(chaseat_prefix_root("hoge", "/a/b//./c///", &ret) >= 0);
|
ASSERT_OK(chaseat_prefix_root("hoge", "/a/b//./c///", &ret));
|
||||||
assert_se(streq(ret, "/a/b/c/hoge"));
|
ASSERT_STREQ(ret, "/a/b/c/hoge");
|
||||||
|
|
||||||
ret = mfree(ret);
|
ret = mfree(ret);
|
||||||
|
|
||||||
assert_se(chaseat_prefix_root("hoge", "a/b//./c///", &ret) >= 0);
|
ASSERT_OK(chaseat_prefix_root("hoge", "a/b//./c///", &ret));
|
||||||
assert_se(expected = path_join(cwd, "a/b/c/hoge"));
|
assert_se(expected = path_join(cwd, "a/b/c/hoge"));
|
||||||
assert_se(streq(ret, expected));
|
ASSERT_STREQ(ret, expected);
|
||||||
|
|
||||||
ret = mfree(ret);
|
ret = mfree(ret);
|
||||||
expected = mfree(expected);
|
expected = mfree(expected);
|
||||||
|
|
||||||
assert_se(chaseat_prefix_root("./hoge/aaa/../././b", "/a/b//./c///", &ret) >= 0);
|
ASSERT_OK(chaseat_prefix_root("./hoge/aaa/../././b", "/a/b//./c///", &ret));
|
||||||
assert_se(streq(ret, "/a/b/c/hoge/aaa/../././b"));
|
ASSERT_STREQ(ret, "/a/b/c/hoge/aaa/../././b");
|
||||||
|
|
||||||
ret = mfree(ret);
|
ret = mfree(ret);
|
||||||
|
|
||||||
|
@ -725,9 +725,9 @@ TEST(trailing_dot_dot) {
|
||||||
_cleanup_free_ char *path = NULL, *fdpath = NULL;
|
_cleanup_free_ char *path = NULL, *fdpath = NULL;
|
||||||
_cleanup_close_ int fd = -EBADF;
|
_cleanup_close_ int fd = -EBADF;
|
||||||
|
|
||||||
assert_se(chase("/usr/..", NULL, CHASE_PARENT, &path, &fd) >= 0);
|
ASSERT_OK(chase("/usr/..", NULL, CHASE_PARENT, &path, &fd));
|
||||||
assert_se(path_equal(path, "/"));
|
assert_se(path_equal(path, "/"));
|
||||||
assert_se(fd_get_path(fd, &fdpath) >= 0);
|
ASSERT_OK(fd_get_path(fd, &fdpath));
|
||||||
assert_se(path_equal(fdpath, "/"));
|
assert_se(path_equal(fdpath, "/"));
|
||||||
|
|
||||||
path = mfree(path);
|
path = mfree(path);
|
||||||
|
@ -735,16 +735,16 @@ TEST(trailing_dot_dot) {
|
||||||
fd = safe_close(fd);
|
fd = safe_close(fd);
|
||||||
|
|
||||||
_cleanup_(rm_rf_physical_and_freep) char *t = NULL;
|
_cleanup_(rm_rf_physical_and_freep) char *t = NULL;
|
||||||
assert_se(mkdtemp_malloc(NULL, &t) >= 0);
|
ASSERT_OK(mkdtemp_malloc(NULL, &t));
|
||||||
_cleanup_free_ char *sub = ASSERT_PTR(path_join(t, "a/b/c/d"));
|
_cleanup_free_ char *sub = ASSERT_PTR(path_join(t, "a/b/c/d"));
|
||||||
assert_se(mkdir_p(sub, 0700) >= 0);
|
ASSERT_OK(mkdir_p(sub, 0700));
|
||||||
_cleanup_free_ char *suffixed = ASSERT_PTR(path_join(sub, ".."));
|
_cleanup_free_ char *suffixed = ASSERT_PTR(path_join(sub, ".."));
|
||||||
assert_se(chase(suffixed, NULL, CHASE_PARENT, &path, &fd) >= 0);
|
ASSERT_OK(chase(suffixed, NULL, CHASE_PARENT, &path, &fd));
|
||||||
_cleanup_free_ char *expected1 = ASSERT_PTR(path_join(t, "a/b/c"));
|
_cleanup_free_ char *expected1 = ASSERT_PTR(path_join(t, "a/b/c"));
|
||||||
_cleanup_free_ char *expected2 = ASSERT_PTR(path_join(t, "a/b"));
|
_cleanup_free_ char *expected2 = ASSERT_PTR(path_join(t, "a/b"));
|
||||||
|
|
||||||
assert_se(path_equal(path, expected1));
|
assert_se(path_equal(path, expected1));
|
||||||
assert_se(fd_get_path(fd, &fdpath) >= 0);
|
ASSERT_OK(fd_get_path(fd, &fdpath));
|
||||||
assert_se(path_equal(fdpath, expected2));
|
assert_se(path_equal(fdpath, expected2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue