From 44dc01597a0712856c93aa765293f5079be9b9a0 Mon Sep 17 00:00:00 2001 From: Andrei Vagin Date: Fri, 13 Oct 2017 11:22:08 +0300 Subject: [PATCH] zdtm: don't use getpwnam and getgrnam For us it doesn't matter what names of users and groups are used, we want to be sure that we restore right uid-s and gid-s. If we use these functions, we can't run tests in namespaces and they use an external unix socket, what can be a problem too. sk unix: Runaway socket: ino 0x1df1ae4 peer_ino 0x1df1ae3 family 1 type 1 state 1 name /run/dbus/system_bus_socket Error (criu/sk-unix.c:712): sk unix: External socket is used. Consider using --ext-unix-sk option. Cc: Vitaly Ostrosablin Cc: Cyrill Gorcunov Signed-off-by: Andrei Vagin Acked-by: Cyrill Gorcunov Signed-off-by: Andrei Vagin --- test/zdtm/static/thread_different_uid_gid.c | 32 +++---------------- .../zdtm/static/thread_different_uid_gid.desc | 2 +- 2 files changed, 5 insertions(+), 29 deletions(-) diff --git a/test/zdtm/static/thread_different_uid_gid.c b/test/zdtm/static/thread_different_uid_gid.c index 1951668fb..2a5e4bdd8 100644 --- a/test/zdtm/static/thread_different_uid_gid.c +++ b/test/zdtm/static/thread_different_uid_gid.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include @@ -81,8 +80,6 @@ int main(int argc, char **argv) int ret; cap_t newcaps; - struct group *group; - struct passwd *user; pthread_t diff_cred_thread; test_init(argc, argv); int maingroup; @@ -115,31 +112,10 @@ int main(int argc, char **argv) } test_msg("Main thread runs as UID: %d; GID: %d\n", getuid(), getgid()); - group = getgrnam("nogroup"); - group = (group) ? group : getgrnam("nobody"); - if (!group) { - pr_perror("Failed to get nogroup/nobody GID\n"); - exit(1); - } - user = getpwnam("nobody"); - if (!user) { - pr_perror("Failed to get nobody UID\n"); - exit(1); - } - gid = group->gr_gid; - uid = user->pw_uid; - group = getgrnam("mail"); - if (!group) { - pr_perror("Failed to get mail GID\n"); - exit(1); - } - user = getpwnam("mail"); - if (!user) { - pr_perror("Failed to get mail UID\n"); - exit(1); - } - maingroup = group->gr_gid; - mainuser = user->pw_uid; + gid = 99; + uid = 99; + maingroup = 8; + mainuser = 12; test_msg("Creating thread with different UID/GID\n"); ret = pthread_create(&diff_cred_thread, NULL, &chg_uid_gid, NULL); diff --git a/test/zdtm/static/thread_different_uid_gid.desc b/test/zdtm/static/thread_different_uid_gid.desc index fa2c82d08..2eac7e654 100644 --- a/test/zdtm/static/thread_different_uid_gid.desc +++ b/test/zdtm/static/thread_different_uid_gid.desc @@ -1 +1 @@ -{'flavor': 'h', 'flags': 'suid'} +{'flags': 'suid'}