From 4cf5000590173f3ca3dcbbe1eebe6e479051ef36 Mon Sep 17 00:00:00 2001 From: Teemu Toivola Date: Sat, 29 Jun 2019 19:39:18 +0300 Subject: [PATCH] make test execution possible even when current user or group doesn't exist --- tests/id_tests.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/tests/id_tests.c b/tests/id_tests.c index ddb4511..9f7bc25 100644 --- a/tests/id_tests.c +++ b/tests/id_tests.c @@ -69,9 +69,17 @@ END_TEST START_TEST(setuser_with_current_user) { char temp[16]; - suppress_output(); - snprintf(temp, 16, "%d", getuser("")); - setuser(temp); + struct passwd *pw; + + pw = getpwuid(getuid()); + + if (pw != NULL) { + suppress_output(); + snprintf(temp, 16, "%d", getuser("")); + setuser(temp); + } else { + printf("Note: skipping test setuser_with_current_user due to non-existing user\n"); + } } END_TEST @@ -85,9 +93,17 @@ END_TEST START_TEST(setgroup_with_current_group) { char temp[16]; - suppress_output(); - snprintf(temp, 16, "%d", getgroup("")); - setgroup(temp); + struct group *gr; + + gr = getgrgid(getgid()); + + if (gr != NULL) { + suppress_output(); + snprintf(temp, 16, "%d", getgroup("")); + setgroup(temp); + } else { + printf("Note: skipping test setgroup_with_current_group due to non-existing group\n"); + } } END_TEST -- 2.40.0