Beispiel #1
0
int main(int ac, char **av)
{
	DIR *ddir, *opendir();
	int fd;
	char *filname = "chdirtest";
	char *filenames[3];

	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */

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

	setup();

	TEST_EXP_ENOS(exp_enos);

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

		Tst_count = 0;

		SAFE_CHDIR(cleanup, testdir);

		fd = SAFE_CREAT(cleanup, filname, 0000);
		SAFE_CLOSE(cleanup, fd);
		if ((ddir = opendir(".")) == NULL)
			tst_brkm(TBROK|TERRNO, cleanup, "opendir(.) failed");

		filenames[0] = ".";
		filenames[1] = "..";
		filenames[2] = filname;
		checknames(filenames, sizeof(filenames) / sizeof(filenames[0]),
		    ddir);
		closedir(ddir);

		TEST(chdir(filname));

		if (TEST_RETURN != -1)
			tst_resm(TFAIL, "call succeeded unexpectedly");
		else if (TEST_ERRNO != ENOTDIR)
			tst_resm(TFAIL|TTERRNO,
			    "failed unexpectedly; wanted ENOTDIR");
		else
			tst_resm(TPASS,
			    "failed as expected with ENOTDIR");

		if (unlink(filname) == -1)
			tst_brkm(TBROK|TERRNO, cleanup, "Couldn't remove file");

		SAFE_CHDIR(cleanup, "..");

	}
	cleanup();

	tst_exit();

}
Beispiel #2
0
static void setup(void)
{
	const char *fs_opts[3] = {"-b", "1024", NULL};

	tst_sig(FORK, DEF_HANDLER, NULL);
	tst_require_root();

	TEST_PAUSE;
	tst_tmpdir();

	TST_CHECKPOINT_INIT(tst_rmdir);

	page_size = getpagesize();

	device = tst_acquire_device(cleanup);
	if (!device)
		tst_brkm(TCONF, cleanup, "Failed to obtain block device");
	tst_mkfs(cleanup, device, fs_type, fs_opts, "10240");

	SAFE_MKDIR(cleanup, MNTPOINT, 0755);
	/*
	 * Disable ext4 delalloc feature, so block will be allocated
	 * as soon as possible
	 */
	SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, 0, "nodelalloc");
	mount_flag = 1;

	SAFE_CHDIR(cleanup, MNTPOINT);
	chdir_flag = 1;

}
Beispiel #3
0
static void cleanup(void)
{
	cleanup_fanotify_groups();

	SAFE_CHDIR("../");

	if (mount_created && tst_umount(MOUNT_NAME) < 0)
		tst_brk(TBROK | TERRNO, "umount failed");
}
Beispiel #4
0
static void setup(void)
{
	SAFE_MKDIR(MOUNT_NAME, 0755);
	SAFE_MOUNT(MOUNT_NAME, MOUNT_NAME, "none", MS_BIND, NULL);
	mount_created = 1;
	SAFE_CHDIR(MOUNT_NAME);
	SAFE_MKDIR(DIR_NAME, 0755);

	sprintf(fname, "tfile_%d", getpid());
	SAFE_FILE_PRINTF(fname, "1");
}
Beispiel #5
0
static void setup(void)
{
	char wdbuf[MAXPATHLEN];

	/*
	 * Make a directory to do this in; ignore error if already exists.
	 * Save starting directory.
	 */
	tst_tmpdir();

	if (getcwd(homedir, sizeof(homedir)) == NULL) {
		tst_brkm(TBROK | TERRNO, NULL, "getcwd() failed");
	}

	parent_pid = getpid();

	if (!fuss[0])
		sprintf(fuss, "%s/ftest03.%d", getcwd(wdbuf, sizeof(wdbuf)),
			getpid());

	mkdir(fuss, 0755);

	SAFE_CHDIR(NULL, fuss);

	/*
	 * Default values for run conditions.
	 */
	iterations = 10;
	nchild = 5;
	csize = K_2;		/* should run with 1, 2, and 4 K sizes */
	max_size = K_1 * K_1;
	misc_intvl = 10;

	if (sigset(SIGTERM, term) == SIG_ERR) {
		perror("sigset failed");
		tst_brkm(TBROK, NULL, " sigset failed: signo = 15");
	}
}
int main(int ac, char **av)
{
	DIR *ddir, *opendir();
	int fd;
	char *filname = "chdirtest";
	char *filenames[3];

	int lc;
	char *msg;

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

	setup();

	TEST_EXP_ENOS(exp_enos);

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

		tst_count = 0;

		SAFE_CHDIR(cleanup, testdir);

		fd = SAFE_CREAT(cleanup, filname, 0000);
		SAFE_CLOSE(cleanup, fd);
		if ((ddir = opendir(".")) == NULL)
			tst_brkm(TBROK | TERRNO, cleanup, "opendir(.) failed");

		filenames[0] = ".";
		filenames[1] = "..";
		filenames[2] = filname;
		checknames(filenames, sizeof(filenames) / sizeof(filenames[0]),
			   ddir);
		closedir(ddir);

		s2e_enable_forking();
		s2e_make_symbolic(filname, 20, "filename");
		TEST(chdir(filname));
		s2e_disable_forking();
		s2e_kill_state(0, "program done!");

		if (TEST_RETURN != -1)
			tst_resm(TFAIL, "call succeeded unexpectedly");
		else if (TEST_ERRNO != ENOTDIR)
			tst_resm(TFAIL | TTERRNO,
				 "failed unexpectedly; wanted ENOTDIR");
		else
			tst_resm(TPASS, "failed as expected with ENOTDIR");

		if (unlink(filname) == -1)
			tst_brkm(TBROK | TERRNO, cleanup,
				 "Couldn't remove file");

		SAFE_CHDIR(cleanup, "..");

	}
	cleanup();

	tst_exit();

}
Beispiel #7
0
Datei: test03.c Projekt: 1587/ltp
static void do_test(void)
{
	SAFE_CHDIR("nonexistent");
}
Beispiel #8
0
/*
 * setup(void) - performs all ONE TIME setup for this test.
 * 	Exit the test program on receipt of unexpected signals.
 *	Create a temporary directory used to hold test directories created
 *	and change the directory to it.
 *	Verify that pid of process executing the test is root.
 *	Create a test directory on temporary directory and set the ownership
 *	of test directory to guest user and process, change mode permissions
 *	to set group id bit on it.
 *	Set the effective uid/gid of the process to that of guest user.
 */
void setup(void)
{
	tst_require_root();

	/* Capture unexpected signals */
	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	TEST_PAUSE;

	/* Make a temp dir and cd to it */
	tst_tmpdir();

	/* fix permissions on the tmpdir */
	if (chmod(".", 0711) != 0) {
		tst_brkm(TBROK, cleanup, "chmod() failed");
	}

	/* Save the real user id of the current test process */
	save_myuid = getuid();
	/* Save the process id of the current test process */
	mypid = getpid();

	/* Get the node name to be created in the test */
	sprintf(node_name, TNODE, mypid);

	/* Get the uid/gid of ltpuser user */
	if ((user1 = getpwnam(LTPUSER)) == NULL) {
		tst_brkm(TBROK, cleanup, "%s not in /etc/passwd", LTPUSER);
	}
	user1_uid = user1->pw_uid;
	group1_gid = user1->pw_gid;

	/* Get the effective group id of the test process */
	group2_gid = getegid();

	/*
	 * Create a test directory under temporary directory with the
	 * specified mode permissions, with uid/gid set to that of guest
	 * user and the test process.
	 */
	SAFE_MKDIR(cleanup, DIR_TEMP, MODE_RWX);
	SAFE_CHOWN(cleanup, DIR_TEMP, user1_uid, group2_gid);
	SAFE_CHMOD(cleanup, DIR_TEMP, MODE_SGID);

	/*
	 * Verify that test directory created with expected permission modes
	 * and ownerships.
	 */
	SAFE_STAT(cleanup, DIR_TEMP, &buf);

	/* Verify modes of test directory */
	if (!(buf.st_mode & S_ISGID)) {
		tst_brkm(TBROK, cleanup,
			 "%s: Incorrect modes, setgid bit not set", DIR_TEMP);
	}

	/* Verify group ID of test directory */
	if (buf.st_gid != group2_gid) {
		tst_brkm(TBROK, cleanup, "%s: Incorrect group", DIR_TEMP);
	}

	/*
	 * Set the effective group id and user id of the test process
	 * to that of guest user (nobody)
	 */
	SAFE_SETGID(cleanup, group1_gid);
	if (setreuid(-1, user1_uid) < 0) {
		tst_brkm(TBROK, cleanup,
			 "Unable to set process uid to that of ltp user");
	}

	/* Save the real group ID of the current process */
	mygid = getgid();

	/* Change directory to DIR_TEMP */
	SAFE_CHDIR(cleanup, DIR_TEMP);
}
Beispiel #9
0
int main(int ac, char **av)
{
	int lc;
	int fflag;

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

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

		tst_count = 0;

		/*
		 *  Attempt to create a filesystem node with group id (sgid)
		 *  bit set on a directory with group id (sgid) bit set
		 *  such that, the node created by mknod(2) should have
		 *  group id (sgid) bit set and node's gid should be equal
		 *  to that of effective gid of the process.
		 */
		TEST(mknod(node_name, MODE_SGID, 0));

		/* Check return code from mknod(2) */
		if (TEST_RETURN == -1) {
			tst_resm(TFAIL, "mknod(%s, %#o, 0)  failed, errno=%d : "
				 "%s", node_name, MODE_SGID, TEST_ERRNO,
				 strerror(TEST_ERRNO));
			continue;
		}
		/* Set the functionality flag */
		fflag = 1;

		/* Check for node's creation */
		if (stat(node_name, &buf) < 0) {
			tst_resm(TFAIL, "stat() of %s failed, errno:%d",
				 node_name, TEST_ERRNO);
			/* unset functionality flag */
			fflag = 0;
		}

		/* Verify mode permissions of node */
		if (!(buf.st_mode & S_ISGID)) {
			tst_resm(TFAIL,
				 "%s: Incorrect modes, setgid bit not "
				 "set", node_name);
			/* unset flag as functionality fails */
			fflag = 0;
		}

		/* Verify group ID */
		if (buf.st_gid != group2_gid) {
			tst_resm(TFAIL, "%s: Incorrect group",
				 node_name);
			/* unset flag as functionality fails */
			fflag = 0;
		}
		if (fflag) {
			tst_resm(TPASS, "Functionality of mknod(%s, "
				 "%#o, 0) successful",
				 node_name, MODE_SGID);
		}

		/* Remove the node for the next go `round */
		if (unlink(node_name) == -1) {
			tst_resm(TWARN, "unlink(%s) failed, errno:%d %s",
				 node_name, errno, strerror(errno));
		}
	}

	/* Change the directory back to temporary directory */
	SAFE_CHDIR(cleanup, "..");

	/*
	 * Invoke cleanup() to delete the test directories created
	 * in the setup() and exit main().
	 */
	cleanup();

	tst_exit();
}
Beispiel #10
0
void maybe_run_child(void (*child) (), const char *fmt, ...)
{
	va_list ap;
	char *child_dir;
	char *p, *tok;
	int *iptr, i, j;
	char *s;
	char **sptr;
	char *endptr;

	/* Store the current directory for later use. */
	start_cwd = getcwd(NULL, 0);

	if (child_args) {
		char *args = strdup(child_args);

		child_dir = strtok(args, ",");
		if (strlen(child_dir) == 0) {
			tst_brkm(TBROK, NULL,
				 "Could not get directory from -C option");
			return;
		}

		va_start(ap, fmt);

		for (p = fmt; *p; p++) {
			tok = strtok(NULL, ",");
			if (!tok || strlen(tok) == 0) {
				tst_brkm(TBROK, NULL,
					 "Invalid argument to -C option");
				return;
			}

			switch (*p) {
			case 'd':
				iptr = va_arg(ap, int *);
				i = strtol(tok, &endptr, 10);
				if (*endptr != '\0') {
					tst_brkm(TBROK, NULL,
						 "Invalid argument to -C option");
					return;
				}
				*iptr = i;
				break;
			case 'n':
				j = va_arg(ap, int);
				i = strtol(tok, &endptr, 10);
				if (*endptr != '\0') {
					tst_brkm(TBROK, NULL,
						 "Invalid argument to -C option");
					return;
				}
				if (j != i) {
					va_end(ap);
					free(args);
					return;
				}
				break;
			case 's':
				s = va_arg(ap, char *);
				if (!strncpy(s, tok, strlen(tok) + 1)) {
					tst_brkm(TBROK, NULL,
						 "Could not strncpy for -C option");
					return;
				}
				break;
			case 'S':
				sptr = va_arg(ap, char **);
				*sptr = strdup(tok);
				if (!*sptr) {
					tst_brkm(TBROK, NULL,
						 "Could not strdup for -C option");
					return;
				}
				break;
			default:
				tst_brkm(TBROK, NULL,
					 "Format string option %c not implemented",
					 *p);
				return;
			}
		}

		va_end(ap);
		free(args);
		SAFE_CHDIR(NULL, child_dir);

		(*child) ();
		tst_resm(TWARN, "Child function returned unexpectedly");
		/* Exit here? or exit silently? */
	}
}