Пример #1
0
/*
 * setup()
 *	performs all ONE TIME setup for this test
 */
void setup(void)
{
	tst_require_root(NULL);

	tst_sig(FORK, DEF_HANDLER, cleanup);

	if (getpwnam("nobody") == NULL) {
		tst_brkm(TBROK, NULL, "nobody must be a valid user.");
	}

	if (getpwnam("bin") == NULL) {
		tst_brkm(TBROK, NULL, "bin must be a valid user.");
	}

	root = *(getpwnam("root"));
	UID16_CHECK((root_pw_uid = root.pw_uid), "setresuid", cleanup)

	nobody = *(getpwnam("nobody"));
	UID16_CHECK((nobody_pw_uid = nobody.pw_uid), "setresuid", cleanup)

	bin = *(getpwnam("bin"));
	UID16_CHECK((bin_pw_uid = bin.pw_uid), "setresuid", cleanup)

	/* Pause if that option was specified
	 * TEST_PAUSE contains the code to fork the test with the -i option.
	 * You want to make sure you do this before you create your temporary
	 * directory.
	 */
	TEST_PAUSE;
}
Пример #2
0
static void setup(void)
{
	tst_require_root(NULL);

	tst_sig(FORK, DEF_HANDLER, cleanup);

	if (getpwnam("nobody") == NULL)
		tst_brkm(TBROK, NULL, "nobody must be a valid user.");

	if (getpwnam("daemon") == NULL)
		tst_brkm(TBROK, NULL, "daemon must be a valid user.");

	if (getpwnam("bin") == NULL)
		tst_brkm(TBROK, NULL, "bin must be a valid user.");

	nobody = *(getpwnam("nobody"));
	UID16_CHECK(nobody.pw_uid, setreuid, cleanup);

	daemonpw = *(getpwnam("daemon"));
	UID16_CHECK(daemonpw.pw_uid, setreuid, cleanup);

	root = *(getpwnam("root"));
	UID16_CHECK(root.pw_uid, setreuid, cleanup);

	bin = *(getpwnam("bin"));
	UID16_CHECK(bin.pw_uid, setreuid, cleanup);

	TEST_PAUSE;
}
Пример #3
0
int main(int argc, char *argv[])
{
	int lc;
	char *msg;
	uid_t user_id;
	gid_t group_id;
	int i;

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

	setup();
	/* set the expected errnos... */
	TEST_EXP_ENOS(exp_enos);

	user_id = geteuid();
	UID16_CHECK(user_id, lchown, cleanup);
	group_id = getegid();
	GID16_CHECK(group_id, lchown, cleanup);

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

		for (i = 0; test_cases[i].desc != NULL; i++) {
			char *file_name = test_cases[i].pathname;
			char *test_desc = test_cases[i].desc;

			/*
			 * Call lchown(2) to test different test conditions.
			 * verify that it fails with -1 return value and
			 * sets appropriate errno.
			 */
			TEST(LCHOWN(cleanup, file_name, user_id, group_id));

			/* Check return code from lchown(2) */
			if (TEST_RETURN == -1) {
				TEST_ERROR_LOG(TEST_ERRNO);
				if (TEST_ERRNO == test_cases[i].exp_errno) {
					tst_resm(TPASS,
						 "lchown(2) fails, %s, errno:%d",
						 test_desc, TEST_ERRNO);
				} else {
					tst_resm(TFAIL, "lchown(2) fails, %s, "
						 "errno:%d, expected errno:%d",
						 test_desc, TEST_ERRNO,
						 test_cases[i].exp_errno);
				}
			} else {
				tst_resm(TFAIL, "lchown(2) returned %ld, "
					 "expected -1, errno:%d", TEST_RETURN,
					 test_cases[i].exp_errno);
			}
		}
	}

	cleanup();
	tst_exit();
}
Пример #4
0
int main(int ac, char **av)
{
	struct stat stat_buf;	/* stat(2) struct contents */
	int lc;
	const char *msg;
	uid_t user_id;		/* Owner id of the test file. */
	gid_t group_id;		/* Group id of the test file. */

	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;

		UID16_CHECK((user_id = geteuid()), "chown", cleanup)
		GID16_CHECK((group_id = getegid()), "chown", cleanup)

		TEST(CHOWN(cleanup, TESTFILE, -1, group_id));

		if (TEST_RETURN == -1) {
			tst_resm(TFAIL | TTERRNO, "chown(%s, ..) failed",
				 TESTFILE);
			continue;
		}

		if (stat(TESTFILE, &stat_buf) == -1)
			tst_brkm(TFAIL | TERRNO, cleanup,
				 "stat failed");

		if (stat_buf.st_uid != user_id ||
		    stat_buf.st_gid != group_id)
			tst_resm(TFAIL, "%s: Incorrect ownership"
				 "set to %d %d, Expected %d %d",
				 TESTFILE, stat_buf.st_uid,
				 stat_buf.st_gid, user_id, group_id);

		if (stat_buf.st_mode !=
		    (NEW_PERMS & ~(S_ISUID | S_ISGID)))
			tst_resm(TFAIL, "%s: incorrect mode permissions"
				 " %#o, Expected %#o", TESTFILE,
				 stat_buf.st_mode,
				 NEW_PERMS & ~(S_ISUID | S_ISGID));
		else
			tst_resm(TPASS, "chown(%s, ..) was successful",
				 TESTFILE);
	}

	cleanup();
	tst_exit();
}
Пример #5
0
int main(int ac, char **av)
{
	int lc;
	char *msg;

	uid_t uid;

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

	setup();

	uid = 1;
	while (!getpwuid(uid))
		uid++;

	UID16_CHECK(uid, setfsuid, cleanup);

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

		tst_count = 0;

		TEST(SETFSUID(cleanup, uid));

		if (TEST_RETURN == -1) {
			tst_resm(TFAIL | TTERRNO,
				"setfsuid() failed unexpectedly");
			continue;
		}

		if (!STD_FUNCTIONAL_TEST) {
			tst_resm(TPASS, "setfsuid() succeeded");
			continue;
		}

		if (TEST_RETURN == uid) {
			tst_resm(TFAIL,
				 "setfsuid() returned %ld, expected anything but %d",
				 TEST_RETURN, uid);
		} else {
			tst_resm(TPASS, "setfsuid() returned expected value : "
				 "%ld", TEST_RETURN);
		}
	}

	cleanup();
	tst_exit();
}
Пример #6
0
Файл: chown01.c Проект: kraj/ltp
static void setup(void)
{

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;

	tst_tmpdir();

	UID16_CHECK((uid = geteuid()), "chown", cleanup)
	GID16_CHECK((gid = getegid()), "chown", cleanup)

	sprintf(fname, "t_%d", getpid());

	SAFE_FILE_PRINTF(cleanup, fname, "davef");
}
Пример #7
0
static void setup(void)
{
	struct passwd *pw;
	uid_t uid;

	pw = SAFE_GETPWNAM("nobody");
	uid = pw->pw_uid;

	UID16_CHECK(uid, setuid);
	/* Create test file */
	SAFE_TOUCH(FILENAME, 0644, NULL);

	if (SETUID(uid) == -1) {
		tst_brk(TBROK,
			"setuid() failed to set the effective uid to %d", uid);
	}
}
Пример #8
0
/*
 * setup() - performs all ONE TIME setup for this test
 */
void setup(void)
{
	tst_require_root();

	ltpuser = getpwnam(nobody_uid);

	UID16_CHECK(ltpuser->pw_uid, "setresuid", cleanup)

	tst_tmpdir();

	sprintf(testfile, "setresuid04file%d.tst", getpid());

	/* Create test file */
	fd = SAFE_OPEN(cleanup, testfile, O_CREAT | O_RDWR, 0644);

	tst_sig(FORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;
}
Пример #9
0
int main(int ac, char **av)
{
	struct passwd *pwent;
	int lc;
	char *msg;
	uid_t uid;

	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(GETEUID(cleanup));

		if (TEST_RETURN == -1)
			tst_brkm(TBROK | TTERRNO, cleanup, "geteuid* failed");

		if (STD_FUNCTIONAL_TEST) {
			uid = geteuid();
			pwent = getpwuid(uid);

			if (pwent == NULL)
				tst_resm(TFAIL | TERRNO, "getpwuid failed");

			UID16_CHECK(pwent->pw_uid, geteuid, cleanup);
			if (pwent->pw_uid != TEST_RETURN)
				tst_resm(TFAIL, "getpwuid value, %d, "
					 "does not match geteuid "
					 "value, %ld", pwent->pw_uid,
					 TEST_RETURN);
			else
				tst_resm(TPASS, "values from geteuid "
					 "and getpwuid match");
		} else
			tst_resm(TPASS, "call succeeded");
	}

	cleanup();
	tst_exit();
}
Пример #10
0
int main(int ac, char **av)
{
	int lc;

	uid_t uid;

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

	uid = 1;
	while (!getpwuid(uid))
		uid++;

	UID16_CHECK(uid, setfsuid, cleanup);

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

		tst_count = 0;

		TEST(SETFSUID(cleanup, uid));

		if (TEST_RETURN == -1) {
			tst_resm(TFAIL | TTERRNO,
				"setfsuid() failed unexpectedly");
			continue;
		}

		if (TEST_RETURN == uid) {
			tst_resm(TFAIL,
				 "setfsuid() returned %ld, expected anything but %d",
				 TEST_RETURN, uid);
		} else {
			tst_resm(TPASS, "setfsuid() returned expected value : "
				 "%ld", TEST_RETURN);
		}
	}

	cleanup();
	tst_exit();
}
Пример #11
0
static void setup(void)
{
	tst_require_root();

	ltpuser = getpwnam(nobody_uid);

	if (ltpuser == NULL)
		tst_brkm(TBROK, cleanup, "getpwnam failed for user id %s",
			nobody_uid);

	UID16_CHECK(ltpuser->pw_uid, setuid, cleanup);

	tst_tmpdir();

	/* Create test file */
	fd = SAFE_OPEN(cleanup, testfile, O_CREAT | O_RDWR, 0644);

	tst_sig(FORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;
}
Пример #12
0
int main(int ac, char **av)
{
	struct passwd *pwent;
	int lc;
	uid_t uid;

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

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

		tst_count = 0;

		TEST(GETUID(cleanup));

		if (TEST_RETURN == -1)
			tst_brkm(TBROK | TTERRNO, cleanup, "getuid failed");

		uid = getuid();
		pwent = getpwuid(uid);

		if (pwent == NULL)
			tst_resm(TFAIL | TERRNO, "getpwuid failed");

		UID16_CHECK(pwent->pw_uid, getuid, cleanup);

		if (pwent->pw_uid != TEST_RETURN)
			tst_resm(TFAIL, "getpwuid value, %d, "
				 "does not match getuid "
				 "value, %ld", pwent->pw_uid,
				 TEST_RETURN);
		else
			tst_resm(TPASS, "values from getuid "
				 "and getpwuid match");
	}
	cleanup();
	tst_exit();
}