Esempio n. 1
0
int main(int ac, char **av)
{
	int lc;
	const char *msg;

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		tst_count = 0;

		/*
		 * TEST CASE:
		 *  Dont change either real or effective gid
		 */
		gid = getgid();
		GID16_CHECK(gid, setregid, cleanup);

		egid = getegid();
		GID16_CHECK(egid, setregid, cleanup);

		TEST(SETREGID(cleanup, -1, -1));

		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
			tst_resm(TFAIL,
				 "setregid -  Dont change either real or effective gid failed, errno=%d : %s",
				 TEST_ERRNO, strerror(TEST_ERRNO));
		} else {
			if (STD_FUNCTIONAL_TEST) {
				tst_resm(TPASS,
					 "setregid -  Dont change either real or effective gid returned %ld",
					 TEST_RETURN);
			}
		}

		/*
		 * TEST CASE:
		 *  change effective to effective gid
		 */

		TEST(SETREGID(cleanup, -1, egid));

		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
			tst_resm(TFAIL,
				 "setregid -  change effective to effective gid failed, errno=%d : %s",
				 TEST_ERRNO, strerror(TEST_ERRNO));
		} else {
			if (STD_FUNCTIONAL_TEST) {
				tst_resm(TPASS,
					 "setregid -  change effective to effective gid returned %ld",
					 TEST_RETURN);
			}
		}

		/*
		 * TEST CASE:
		 *  change real to real gid
		 */

		TEST(SETREGID(cleanup, gid, -1));

		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
			tst_resm(TFAIL,
				 "setregid -  change real to real gid failed, errno=%d : %s",
				 TEST_ERRNO, strerror(TEST_ERRNO));
		} else {
			if (STD_FUNCTIONAL_TEST) {
				tst_resm(TPASS,
					 "setregid -  change real to real gid returned %ld",
					 TEST_RETURN);
			}
		}

		/*
		 * TEST CASE:
		 *  change effective to real gid
		 */

		TEST(SETREGID(cleanup, -1, gid));

		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
			tst_resm(TFAIL,
				 "setregid -  change effective to real gid failed, errno=%d : %s",
				 TEST_ERRNO, strerror(TEST_ERRNO));
		} else {
			if (STD_FUNCTIONAL_TEST) {
				tst_resm(TPASS,
					 "setregid -  change effective to real gid returned %ld",
					 TEST_RETURN);
			}
		}

		/*
		 * TEST CASE:
		 *  try to change real to current real
		 */

		TEST(SETREGID(cleanup, gid, gid));

		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
			tst_resm(TFAIL | TTERRNO, "setregid failed");
		} else {
			if (STD_FUNCTIONAL_TEST) {
				tst_resm(TPASS, "setregid return %ld",
					 TEST_RETURN);
			}
		}

	}

	cleanup();
	tst_exit();
}
Esempio n. 2
0
int main(int ac, char **av)
{
	int lc;

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		tst_count = 0;

		/*
		 * TEST CASE:
		 *  Dont change either real or effective gid
		 */
		gid = getgid();
		GID16_CHECK(gid, setregid, NULL);

		egid = getegid();
		GID16_CHECK(egid, setregid, NULL);

		TEST(SETREGID(NULL, -1, -1));

		if (TEST_RETURN == -1) {
			tst_resm(TFAIL,
				 "setregid -  Dont change either real or effective gid failed, errno=%d : %s",
				 TEST_ERRNO, strerror(TEST_ERRNO));
		} else {
			tst_resm(TPASS,
				 "setregid -  Dont change either real or effective gid returned %ld",
				 TEST_RETURN);
		}

		/*
		 * TEST CASE:
		 *  change effective to effective gid
		 */

		TEST(SETREGID(NULL, -1, egid));

		if (TEST_RETURN == -1) {
			tst_resm(TFAIL,
				 "setregid -  change effective to effective gid failed, errno=%d : %s",
				 TEST_ERRNO, strerror(TEST_ERRNO));
		} else {
			tst_resm(TPASS,
				 "setregid -  change effective to effective gid returned %ld",
				 TEST_RETURN);
		}

		/*
		 * TEST CASE:
		 *  change real to real gid
		 */

		TEST(SETREGID(NULL, gid, -1));

		if (TEST_RETURN == -1) {
			tst_resm(TFAIL,
				 "setregid -  change real to real gid failed, errno=%d : %s",
				 TEST_ERRNO, strerror(TEST_ERRNO));
		} else {
			tst_resm(TPASS,
				 "setregid -  change real to real gid returned %ld",
				 TEST_RETURN);
		}

		/*
		 * TEST CASE:
		 *  change effective to real gid
		 */

		TEST(SETREGID(NULL, -1, gid));

		if (TEST_RETURN == -1) {
			tst_resm(TFAIL,
				 "setregid -  change effective to real gid failed, errno=%d : %s",
				 TEST_ERRNO, strerror(TEST_ERRNO));
		} else {
			tst_resm(TPASS,
				 "setregid -  change effective to real gid returned %ld",
				 TEST_RETURN);
		}

		/*
		 * TEST CASE:
		 *  try to change real to current real
		 */

		TEST(SETREGID(NULL, gid, gid));

		if (TEST_RETURN == -1) {
			tst_resm(TFAIL | TTERRNO, "setregid failed");
		} else {
			tst_resm(TPASS, "setregid return %ld",
				 TEST_RETURN);
		}

	}

	tst_exit();
}
Esempio n. 3
0
int main(int ac, char **av)
{
	int lc;

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		pid_t pid;
		int status, i;

		pass = 0;
		flag = 0;

		tst_count = 0;

		/* set the appropriate ownership values */
		if (SETREGID(NULL, sys.gr_gid, bin.gr_gid) == -1)
			tst_brkm(TBROK, NULL, "Initial setregid failed");

		if (seteuid(nobody.pw_uid) == -1)
			tst_brkm(TBROK, NULL, "Initial seteuid failed");

		if ((pid = FORK_OR_VFORK()) == -1) {
			tst_brkm(TBROK, NULL, "fork failed");
		} else if (pid == 0) {	/* child */
			for (i = 0; i < TST_TOTAL; i++) {
				gid_t test_ret;
				/* Set the real or effective group id */
				TEST(SETREGID(NULL, *test_data[i].real_gid,
					      *test_data[i].eff_gid));
				test_ret = TEST_RETURN;

				if (test_ret == *test_data[i].exp_ret) {
					if (test_ret == neg_one) {
						if (TEST_ERRNO != EPERM) {
							tst_resm(TFAIL,
								 "setregid(%d, %d) "
								 "did not set errno "
								 "value as expected.",
								 *test_data
								 [i].real_gid,
								 *test_data
								 [i].eff_gid);
							fail = -1;
							continue;
						} else {
							tst_resm(TPASS,
								 "setregid(%d, %d) "
								 "failed as expected.",
								 *test_data
								 [i].real_gid,
								 *test_data
								 [i].eff_gid);
						}
					} else {
						tst_resm(TPASS,
							 "setregid(%d, %d) "
							 "succeeded as expected.",
							 *test_data[i].real_gid,
							 *test_data[i].eff_gid);
					}
				} else {
					tst_resm(TFAIL, "setregid(%d, %d) "
						 "did not return as expected.",
						 *test_data[i].real_gid,
						 *test_data[i].eff_gid);
					flag = -1;
				}
				if (test_ret == -1) {
				}

				gid_verify(test_data[i].exp_real_usr,
					   test_data[i].exp_eff_usr,
					   test_data[i].test_msg);
			}
			exit(flag);
		} else {	/* parent */
			waitpid(pid, &status, 0);
			if (WEXITSTATUS(status) != 0) {
				tst_resm(TFAIL, "test failed within "
					 "child process.");
			}
		}
	}

	tst_exit();
}