mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 00:14:32 +09:00
test: add tests for DynamicUser= with static User= whose UID and GID are different
This commit is contained in:
@@ -105,6 +105,25 @@ invalid:
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool check_user_has_group_with_same_name(const char *name) {
|
||||
struct passwd *p;
|
||||
struct group *g;
|
||||
|
||||
assert(name);
|
||||
|
||||
p = getpwnam(name);
|
||||
if (!p ||
|
||||
!streq(p->pw_name, name))
|
||||
return false;
|
||||
|
||||
g = getgrgid(p->pw_gid);
|
||||
if (!g ||
|
||||
!streq(g->gr_name, name))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool is_inaccessible_available(void) {
|
||||
char *p;
|
||||
|
||||
@@ -427,6 +446,10 @@ static void test_exec_supplementarygroups(Manager *m) {
|
||||
|
||||
static void test_exec_dynamicuser(Manager *m) {
|
||||
test(m, "exec-dynamicuser-fixeduser.service", 0, CLD_EXITED);
|
||||
if (check_user_has_group_with_same_name("adm"))
|
||||
test(m, "exec-dynamicuser-fixeduser-adm.service", 0, CLD_EXITED);
|
||||
if (check_user_has_group_with_same_name("games"))
|
||||
test(m, "exec-dynamicuser-fixeduser-games.service", 0, CLD_EXITED);
|
||||
test(m, "exec-dynamicuser-fixeduser-one-supplementarygroup.service", 0, CLD_EXITED);
|
||||
test(m, "exec-dynamicuser-supplementarygroups.service", 0, CLD_EXITED);
|
||||
test(m, "exec-dynamicuser-statedir.service", 0, CLD_EXITED);
|
||||
|
||||
@@ -45,6 +45,8 @@ test_data_files = '''
|
||||
test-execute/exec-cpuaffinity1.service
|
||||
test-execute/exec-cpuaffinity2.service
|
||||
test-execute/exec-cpuaffinity3.service
|
||||
test-execute/exec-dynamicuser-fixeduser-adm.service
|
||||
test-execute/exec-dynamicuser-fixeduser-games.service
|
||||
test-execute/exec-dynamicuser-fixeduser-one-supplementarygroup.service
|
||||
test-execute/exec-dynamicuser-fixeduser.service
|
||||
test-execute/exec-dynamicuser-statedir-migrate-step1.service
|
||||
|
||||
11
test/test-execute/exec-dynamicuser-fixeduser-adm.service
Normal file
11
test/test-execute/exec-dynamicuser-fixeduser-adm.service
Normal file
@@ -0,0 +1,11 @@
|
||||
[Unit]
|
||||
Description=Test DynamicUser with static User= whose uid and gid are different
|
||||
# On Fedora, user adm has uid==3 and gid==4.
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/bin/sh -x -c 'test "$$(id -nG)" = "adm" && test "$$(id -ng)" = "adm" && test "$$(id -nu)" = "adm"'
|
||||
# Multiple ExecStart= lines causes the issue #9702.
|
||||
ExecStart=/bin/sh -x -c 'test "$$(id -nG)" = "adm" && test "$$(id -ng)" = "adm" && test "$$(id -nu)" = "adm"'
|
||||
DynamicUser=yes
|
||||
User=adm
|
||||
11
test/test-execute/exec-dynamicuser-fixeduser-games.service
Normal file
11
test/test-execute/exec-dynamicuser-fixeduser-games.service
Normal file
@@ -0,0 +1,11 @@
|
||||
[Unit]
|
||||
Description=Test DynamicUser with static User= whose uid and gid are different
|
||||
# On Ubuntu or Debian, user games has uid==5 and gid==60.
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/bin/sh -x -c 'test "$$(id -nG)" = "games" && test "$$(id -ng)" = "games" && test "$$(id -nu)" = "games"'
|
||||
# Multiple ExecStart= lines causes the issue #9702.
|
||||
ExecStart=/bin/sh -x -c 'test "$$(id -nG)" = "games" && test "$$(id -ng)" = "games" && test "$$(id -nu)" = "games"'
|
||||
DynamicUser=yes
|
||||
User=games
|
||||
Reference in New Issue
Block a user