@@ -40,7 +40,7 @@ static gid_t neg_one = -1;
static struct passwd *ltpuser;
-static struct group nobody, root, bin;
+static struct group ltpgroup, root, bin, *junk;
/*
* The following structure contains all test data. Each structure in the array
@@ -56,17 +56,17 @@ struct test_data_t {
char *test_msg;
} test_data[] = {
{
- &neg_one, &root.gr_gid, EPERM, &nobody, &nobody,
+ &neg_one, &root.gr_gid, EPERM, <pgroup, <pgroup,
"After setregid(-1, root),"}, {
- &neg_one, &bin.gr_gid, EPERM, &nobody, &nobody,
+ &neg_one, &bin.gr_gid, EPERM, <pgroup, <pgroup,
"After setregid(-1, bin)"}, {
- &root.gr_gid, &neg_one, EPERM, &nobody, &nobody,
+ &root.gr_gid, &neg_one, EPERM, <pgroup, <pgroup,
"After setregid(root,-1),"}, {
- &bin.gr_gid, &neg_one, EPERM, &nobody, &nobody,
+ &bin.gr_gid, &neg_one, EPERM, <pgroup, <pgroup,
"After setregid(bin, -1),"}, {
- &root.gr_gid, &bin.gr_gid, EPERM, &nobody, &nobody,
+ &root.gr_gid, &bin.gr_gid, EPERM, <pgroup, <pgroup,
"After setregid(root, bin)"}, {
- &bin.gr_gid, &root.gr_gid, EPERM, &nobody, &nobody,
+ &bin.gr_gid, &root.gr_gid, EPERM, <pgroup, <pgroup,
"After setregid(bin, root),"}
};
@@ -75,6 +75,8 @@ int TST_TOTAL = sizeof(test_data) / sizeof(test_data[0]);
static void setup(void);
static void cleanup(void);
static void gid_verify(struct group *ru, struct group *eu, char *when);
+static struct group get_group_by_name(const char *name);
+static struct group get_group_by_gid(gid_t gid);
int main(int ac, char **av)
{
@@ -126,8 +128,6 @@ int main(int ac, char **av)
static void setup(void)
{
- struct group *junk;
-
tst_require_root();
tst_sig(FORK, DEF_HANDLER, cleanup);
@@ -147,22 +147,33 @@ static void setup(void)
ltpuser->pw_uid);
}
-#define GET_GID(group) do { \
- junk = getgrnam(#group); \
- if (junk == NULL) { \
- tst_brkm(TBROK|TERRNO, NULL, "getgrnam(\"%s\") failed", #group); \
- } \
- GID16_CHECK(junk->gr_gid, setregid, NULL); \
- group = *(junk); \
-} while (0)
-
- GET_GID(root);
- GET_GID(nobody);
- GET_GID(bin);
+ root = get_group_by_name("root");
+ ltpgroup = get_group_by_gid(ltpuser->pw_gid);
+ bin = get_group_by_name("bin");
TEST_PAUSE;
}
+static struct group get_group_by_name(const char *name)
+{
+ junk = getgrnam(name);
+ if (junk == NULL) {
+ tst_brkm(TBROK|TERRNO, NULL, "getgrnam(\"%s\") failed", name);
+ }
+ GID16_CHECK(junk->gr_gid, setregid, NULL);
+ return *junk;
+}
+
+static struct group get_group_by_gid(gid_t gid)
+{
+ junk = getgrgid(gid);
+ if (junk == NULL) {
+ tst_brkm(TBROK|TERRNO, NULL, "getgrgid(\"%d\") failed", gid);
+ }
+ GID16_CHECK(junk->gr_gid, setregid, NULL);
+ return *junk;
+}
+
static void cleanup(void)
{
}
In setup this test sets UID and GID of the user "nobody". Then it expects that user "nobody" is in group "nobody" and tries to retrive a structure for group "nobody" using getgrnam(). However some Linux distributions use group "nogroup" for user "nobody". Thus it's necessary to retrieve a group of user "nobody" not by hardcoded name but by its GID. It's necessary because group "nobody" may not exist. I've replaced a variable "nobody" by more generic "ltpgroup". Then I've created 2 functions get_group_by_name and get_group_by_gid which are used instead of GET_GID macros. On my test system I have user "nobody" in group "nogroup". So I've got this error messages for this test: ----------->8---------- setregid02.c:160: getgrnam("nobody") failed: errno=SUCCESS(0): Success setregid02.c:160: Remaining cases broken ----------->8---------- Signed-off-by: Yuriy Kolerov <yuriy.kolerov@synopsys.com> --- testcases/kernel/syscalls/setregid/setregid02.c | 53 +++++++++++++++---------- 1 file changed, 32 insertions(+), 21 deletions(-)