]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-acl-util.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright © 2015 Zbigniew Jędrzejewski-Szmek
14 #include "string-util.h"
15 #include "user-util.h"
17 static void test_add_acls_for_user(void) {
18 char fn
[] = "/tmp/test-empty.XXXXXX";
19 _cleanup_close_
int fd
= -1;
24 fd
= mkostemp_safe(fn
);
27 /* Use the mode that user journal files use */
28 assert_se(fchmod(fd
, 0640) == 0);
30 cmd
= strjoina("ls -l ", fn
);
31 assert_se(system(cmd
) == 0);
33 cmd
= strjoina("getfacl -p ", fn
);
34 assert_se(system(cmd
) == 0);
37 const char *nobody
= NOBODY_USER_NAME
;
38 r
= get_user_creds(&nobody
, &uid
, NULL
, NULL
, NULL
);
44 r
= add_acls_for_user(fd
, uid
);
47 cmd
= strjoina("ls -l ", fn
);
48 assert_se(system(cmd
) == 0);
50 cmd
= strjoina("getfacl -p ", fn
);
51 assert_se(system(cmd
) == 0);
53 /* set the acls again */
55 r
= add_acls_for_user(fd
, uid
);
58 cmd
= strjoina("ls -l ", fn
);
59 assert_se(system(cmd
) == 0);
61 cmd
= strjoina("getfacl -p ", fn
);
62 assert_se(system(cmd
) == 0);
67 int main(int argc
, char **argv
) {
68 test_add_acls_for_user();