Ejemplo n.º 1
0
int main(int ac, char **av)
{
	struct stat stat_buf;
	int i, lc;
	const char *msg;
	uid_t user_id;
	gid_t group_id;

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

	setup();

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

		for (i = 0; tc[i].desc != NULL; i++) {
			user_id = tc[i].user_id;
			group_id = tc[i].group_id;

			TEST(FCHOWN(cleanup, fildes, user_id, group_id));

			if (TEST_RETURN == -1) {
				tst_resm(TFAIL | TTERRNO,
					 "fchown() Fails to %s", tc[i].desc);
				continue;
			}

			SAFE_FSTAT(cleanup, fildes, &stat_buf);

			if (user_id == (uid_t)-1)
				user_id = tc[i - 1].user_id;

			if (group_id == (gid_t)-1)
				group_id = tc[i - 1].group_id;

			if ((stat_buf.st_uid != user_id) ||
			    (stat_buf.st_gid != group_id)) {
				tst_resm(TFAIL, "%s: Incorrect owner"
					 "ship set, Expected %d %d",
					 TESTFILE, user_id, group_id);
			} else {
				tst_resm(TPASS,
					 "fchown() succeeds to %s of %s",
					 tc[i].desc, TESTFILE);
			}
		}
	}

	cleanup();
	tst_exit();
}
Ejemplo n.º 2
0
int main(int ac, char **av)
{
	struct stat stat_buf;
	int lc;
	uid_t user_id;
	gid_t group_id;

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

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

		user_id = geteuid();
		GID16_CHECK((group_id = getegid()), "fchown", cleanup)

		TEST(FCHOWN(cleanup, fildes, -1, group_id));

		if (TEST_RETURN == -1) {
			tst_resm(TFAIL, "fchown() on %s Fails, errno=%d",
				 TESTFILE, TEST_ERRNO);
			continue;
		}

		SAFE_FSTAT(cleanup, fildes, &stat_buf);

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

		if (stat_buf.st_mode != FCHOWN_PERMS) {
			tst_resm(TFAIL, "%s: Incorrect mode permissions"
				 " %#o, Expected %#o", TESTFILE,
				 stat_buf.st_mode, FCHOWN_PERMS);
		} else {
			tst_resm(TPASS, "fchown() on %s succeeds: "
				 "Setuid/gid bits cleared", TESTFILE);
		}
	}

	cleanup();
	tst_exit();
}
Ejemplo n.º 3
0
int
fchown3d(int fd, uid_t uid, gid_t gid)
{
#if FS
	Mount_t*	mp;

	if (!fscall(NiL, MSG_fchown, 0, fd, uid, gid))
		return state.ret;
	mp = monitored();
#endif
	if (FCHOWN(fd, uid, gid))
		return -1;
#if FS
	if (mp)
		fscall(mp, MSG_fchown, 0, fd, uid, gid);
	for (mp = state.global; mp; mp = mp->global)
		if (fssys(mp, MSG_fchown))
			fscall(mp, MSG_fchown, 0, fd, uid, gid);
#endif
	return 0;
}