/* * setup() - performs all ONE TIME setup for this test. */ void setup() { /* test must be run as root */ if (geteuid() != 0) { tst_brkm(TBROK, NULL, "Test must be run as root"); } tst_sig(NOFORK, DEF_HANDLER, cleanup); TEST_PAUSE; if ((rootpwent = getpwnam(root)) == NULL) { tst_brkm(TBROK, cleanup, "getpwnam failed for " "user id %s", root); } mygid = getgid(); if (mygid != rootpwent->pw_gid) { tst_brkm(TBROK, cleanup, "real group id is not root"); } if ((ltpuser1pwent = getpwnam(ltpuser1)) == NULL) { tst_brkm(TBROK, cleanup, "getpwnam failed for user " "id %s", ltpuser1); } if (!(GID_SIZE_CHECK(rootpwent->pw_gid))) { tst_brkm(TBROK, cleanup, "gid for `%s' is too large for testing setgid16", root); } }
/* * setup() - performs all ONE TIME setup for this test. */ void setup() { /* Switch to nobody user for correct error code collection */ if (geteuid() != 0) { tst_brkm(TBROK, NULL, "Test must be run as root"); } ltpuser = getpwnam(nobody_uid); if (!GID_SIZE_CHECK(ltpuser->pw_gid)) { tst_brkm(TBROK, cleanup, "gid for `%s' is too large for testing setgid16", nobody_gid); } if (setgid(ltpuser->pw_gid) == -1) { tst_resm(TINFO, "setgid failed to " "to set the effective gid to %d", ltpuser->pw_gid); perror("setgid"); } if (setuid(ltpuser->pw_uid) == -1) { tst_resm(TINFO, "setuid failed to " "to set the effective uid to %d", ltpuser->pw_uid); perror("setuid"); } tst_sig(NOFORK, DEF_HANDLER, cleanup); TEST_PAUSE; }
/* * setup() - performs all ONE TIME setup for this test. * * Make sure the test process uid is root. * Get the supplimentrary group id of test user from /etc/passwd file. */ void setup() { tst_sig(NOFORK, DEF_HANDLER, cleanup); /* Make sure the calling process is super-user only */ if (geteuid() != 0) { tst_brkm(TBROK, NULL, "Must be ROOT to run this test."); } TEST_PAUSE; /* Get the group id info. of TESTUSER from /etc/passwd */ if ((user_info = getpwnam(TESTUSER)) == NULL) { tst_brkm(TFAIL, cleanup, "getpwnam(2) of %s Failed", TESTUSER); } if (!GID_SIZE_CHECK(user_info->pw_gid)) { tst_brkm(TBROK, cleanup, "gid returned from getpwnam is too large for testing setgroups16"); } groups_list[0] = user_info->pw_gid; }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ int euid; struct passwd *pwent; /* parse standard options */ if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) { tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); /*NOTREACHED*/} setup(); /* global setup */ /* The following loop checks looping state if -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping */ Tst_count = 0; TEST(GETEGID()); if (TEST_RETURN < 0) { tst_brkm(TBROK, cleanup, "This should never happen"); } if (STD_FUNCTIONAL_TEST) { euid = geteuid(); pwent = getpwuid(euid); if (pwent == NULL) { tst_brkm(TBROK, cleanup, "geteuid() returned " "unexpected value %d", euid); } else if (!GID_SIZE_CHECK(pwent->pw_gid)) { tst_brkm(TBROK, cleanup, "gid for euid %d is too large for testing getegid16", euid); } else { if (pwent->pw_gid != TEST_RETURN) { tst_resm(TFAIL, "getegid() return value" " %ld unexpected - expected %d", TEST_RETURN, pwent->pw_gid); } else { tst_resm(TPASS, "effective group id %ld " "is correct", TEST_RETURN); } } } else { tst_resm(TPASS, "call succeeded"); } } cleanup(); /*NOTREACHED*/ return 0; }
int main(int ac, char **av) { struct passwd *getpwnam(), *rootpwent; int lc; /* loop counter */ char *msg; /* message returned by parse_opts */ /* parse standard options */ if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) { tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg); /*NOTREACHED*/} setup(); TEST_EXP_ENOS(exp_enos); /* check looping state if -i option is given */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping */ Tst_count = 0; if ((rootpwent = getpwnam(root)) == NULL) { tst_brkm(TBROK, cleanup, "getpwnam failed for user id " "%s", root); } if (!GID_SIZE_CHECK(rootpwent->pw_gid)) { tst_brkm(TBROK, cleanup, "gid for `%s' is too large for testing setgid16", root); } TEST(SETGID(rootpwent->pw_gid)); if (TEST_RETURN != -1) { tst_resm(TFAIL, "call succeeded unexpectedly"); continue; } TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO != EPERM) { tst_resm(TFAIL, "setgid set invalid errno, expected: " "EPERM, got: %d\n", TEST_ERRNO); } else { tst_resm(TPASS, "setgid returned EPERM"); } } cleanup(); /*NOTREACHED*/ return 0; }
/* * setup() - performs all ONE TIME setup for this test. * * Make sure the test process uid is root. * Get the supplimentrary group id of test user from /etc/passwd file. */ void setup(void) { tst_require_root(); tst_sig(NOFORK, DEF_HANDLER, cleanup); TEST_PAUSE; /* Get the group id info. of TESTUSER from /etc/passwd */ if ((user_info = getpwnam(TESTUSER)) == NULL) { tst_brkm(TFAIL, cleanup, "getpwnam(2) of %s Failed", TESTUSER); } if (!GID_SIZE_CHECK(user_info->pw_gid)) { tst_brkm(TBROK, cleanup, "gid returned from getpwnam is too large for testing setgroups16"); } groups_list[0] = user_info->pw_gid; }
/* * setup1 - Setup function to test setgroups() which returns -1 * and sets errno to EPERM. * * Get the user info. from /etc/passwd file. * This function returns 0 on success. */ int setup1(void) { struct passwd *user_info; /* struct. to hold test user info */ /* Switch to nobody user for correct error code collection */ ltpuser = getpwnam(nobody_uid); if (seteuid(ltpuser->pw_uid) == -1) { tst_resm(TINFO, "setreuid failed to " "to set the effective uid to %d", ltpuser->pw_uid); perror("setreuid"); } if ((user_info = getpwnam(TESTUSER)) == NULL) { tst_brkm(TFAIL, cleanup, "getpwnam(2) of %s Failed", TESTUSER); } if (!GID_SIZE_CHECK(user_info->pw_gid)) { tst_brkm(TBROK, cleanup, "gid returned from getpwnam is too large for testing setgroups16"); } groups_list[0] = user_info->pw_gid; return 0; }