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

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

#ifdef UCLINUX
	maybe_run_child(&dochild, "sdd", filename, &recstart, &reclen);
#endif

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		sprintf(filename, MOUNT_DIR"%s.%d.%d\n", TCID, getpid(), lc);

		if (tst_fill_file(filename, 0, 1024, 8)) {
			tst_brkm(TBROK, cleanup,
			         "Failed to create test file '%s'", filename);
		}

		SAFE_CHMOD(cleanup, filename, 02666);

		reclen = RECLEN;
		/*
		 * want at least RECLEN bytes BEFORE AND AFTER the
		 * record lock.
		 */
		recstart = RECLEN + rand() % (len - 3 * RECLEN);

		if ((pid = FORK_OR_VFORK()) < 0)
			tst_brkm(TBROK | TERRNO, cleanup, "fork() failed");

		if (pid == 0) {
#ifdef UCLINUX
			if (self_exec(av[0], "sdd", filename, recstart,
			              reclen) < -1) {
				tst_brkm(TBROK, cleanup, "self_exec() failed");
			}
#else
			dochild();
#endif
		}

		doparent();
	}

	cleanup();
	tst_exit();
}
Esempio n. 2
0
File: link07.c Progetto: 1587/ltp
static void setup(void)
{
	struct passwd *nobody_pwd;

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	tst_require_root();

	TEST_PAUSE;

	tst_tmpdir();

	/* Modify mode permissions on test directory */
	SAFE_CHMOD(cleanup, ".", MODE_TO);

	SAFE_MKDIR(cleanup, DIR_TEMP, MODE_RWX);
	SAFE_TOUCH(cleanup, TEST_FILE2, 0666, NULL);

	/* Modify mode permissions on test directory - test conditions */
	SAFE_CHMOD(cleanup, DIR_TEMP, MODE_TE);

	nobody_pwd = SAFE_GETPWNAM(cleanup, "nobody");
	SAFE_SETEUID(cleanup, nobody_pwd->pw_uid);
}
Esempio n. 3
0
static void setup_ipc(void)
{
	size_t size = getpagesize();

	if (access("/dev/shm", F_OK) == 0) {
		snprintf(shm_path, sizeof(shm_path), "/dev/shm/ltp_%s_%d",
		         tid, getpid());
	} else {
		char *tmpdir;

		if (!tst_tmpdir_created())
			tst_tmpdir();

		tmpdir = tst_get_tmpdir();
		snprintf(shm_path, sizeof(shm_path), "%s/ltp_%s_%d",
		         tmpdir, tid, getpid());
		free(tmpdir);
	}

	ipc_fd = open(shm_path, O_CREAT | O_EXCL | O_RDWR, 0600);
	if (ipc_fd < 0)
		tst_brk(TBROK | TERRNO, "open(%s)", shm_path);
	SAFE_CHMOD(shm_path, 0666);

	SAFE_FTRUNCATE(ipc_fd, size);

	results = SAFE_MMAP(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, ipc_fd, 0);

	/* Checkpoints needs to be accessible from processes started by exec() */
	if (tst_test->needs_checkpoints) {
		sprintf(ipc_path, IPC_ENV_VAR "=%s", shm_path);
		putenv(ipc_path);
	} else {
		SAFE_UNLINK(shm_path);
	}

	SAFE_CLOSE(ipc_fd);

	if (tst_test->needs_checkpoints) {
		tst_futexes = (char*)results + sizeof(struct results);
		tst_max_futexes = (size - sizeof(struct results))/sizeof(futex_t);
	}
}
Esempio n. 4
0
File: execve02.c Progetto: 1587/ltp
static void setup(void)
{
	char path[PATH_MAX];
	struct passwd *pwd;

	tst_require_root();

	if (tst_get_path(TEST_APP, path, sizeof(path))) {
		tst_brkm(TBROK, NULL,
		         "Couldn't found "TEST_APP" binary in $PATH");
	}

	tst_tmpdir();

	SAFE_CP(tst_rmdir, path, ".");
	SAFE_CHMOD(cleanup, TEST_APP, 0700);

	pwd = SAFE_GETPWNAM(tst_rmdir, USER_NAME);
	nobody_uid = pwd->pw_uid;
}
Esempio n. 5
0
void setup(void)
{
	struct passwd *ltpuser;
	int i;

	tst_require_root(NULL);

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	ltpuser = SAFE_GETPWNAM(cleanup, "nobody");
	SAFE_SETEUID(cleanup, ltpuser->pw_uid);

	TEST_PAUSE;

	tst_tmpdir();

	SAFE_MKDIR(cleanup, DIR_TEMP, MODE_RWX);
	SAFE_TOUCH(cleanup, TEST_FILE1, 0666, NULL);
	SAFE_SYMLINK(cleanup, TEST_FILE1, SYM_FILE1);
	SAFE_CHMOD(cleanup, DIR_TEMP, FILE_MODE);

	SAFE_TOUCH(cleanup, TEST_FILE2, 0666, NULL);
	SAFE_SYMLINK(cleanup, TEST_FILE2, SYM_FILE2);

	memset(longpathname, 'a', PATH_MAX + 1);

	SAFE_TOUCH(cleanup, TEST_FILE3, 0666, NULL);

	/*
	 * NOTE: the ELOOP test is written based on that the consecutive
	 * symlinks limit in kernel is hardwired to 40.
	 */
	SAFE_MKDIR(cleanup, "test_eloop", MODE_RWX);
	SAFE_SYMLINK(cleanup, "../test_eloop", "test_eloop/test_eloop");
	for (i = 0; i < 43; i++)
		strcat(elooppathname, ELOOPFILE);
}
Esempio n. 6
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);
}