Exemplo n.º 1
0
int start(struct install_options* param) {
  char *home=configdir(),*p;
  char *localprojects=cat(home,"local-projects/",NULL);
  setup_uid(1);
  ensure_directories_exist(localprojects);
  s(localprojects);
  if(installed_p(param)) {
    printf("%s/%s is already installed. Try (TBD) for the forced re-installation.\n",param->impl,param->version?param->version:"");
    return 0;
  }
  if(install_running_p(param)) {
    printf("It seems another installation process for $1/$2 is in progress somewhere in the system.\n");
    return 0;
  }
  p=cat(home,"tmp",SLASH,param->impl,param->version?"-":"",param->version?param->version:"",SLASH,NULL);
  ensure_directories_exist(p);
  s(p);

  p=cat(home,"tmp",SLASH,param->impl,param->version?"-":"",param->version?param->version:"",".lock",NULL);
  delete_at_exit(p);
  touch(p);

  s(p),s(home);
  return 1;
}
Exemplo n.º 2
0
int cmd_internal(int argc,char **argv,struct sub_command* cmd) {
  setup_uid(0);
  return proccmd(argc-1,&(argv[1]),(LVal)NULL,internal_commands);
}
Exemplo n.º 3
0
int test_rwflag(int i, int cnt)
{
	int fd, pid, status;
	char nobody_uid[] = "nobody";
	struct passwd *ltpuser;

	switch (i) {
	case 0:
		/* Validate MS_RDONLY flag of mount call */

		snprintf(file, PATH_MAX, "%stmp", Path_name);
		if ((fd = open(file, O_CREAT | O_RDWR, S_IRWXU)) == -1) {
			if (errno == EROFS) {
				return 0;
			} else {
				tst_resm(TWARN|TERRNO,
				    "open didn't fail with EROFS");
				return 1;
			}
		}
		close(fd);
		return 1;
	case 1:
		/* Validate MS_NODEV flag of mount call */

		snprintf(file, PATH_MAX, "%smynod_%d_%d", Path_name, getpid(),
			       cnt);
		if (mknod(file, S_IFBLK | 0777, 0) == 0) {
			if ((fd = open(file, O_RDWR, S_IRWXU)) == -1) {
				if (errno == EACCES) {
					return 0;
				} else {
					tst_resm(TWARN|TERRNO,
					    "open didn't fail with EACCES");
					return 1;
				}
			}
			close(fd);
		} else {
			tst_resm(TWARN|TERRNO, "mknod(2) failed to create %s",
			    file);
			return 1;
		}
		return 1;
	case 2:
		/* Validate MS_NOEXEC flag of mount call */

		snprintf(file, PATH_MAX, "%stmp1", Path_name);
		if ((fd = open(file, O_CREAT | O_RDWR, S_IRWXU)) == -1) {
			tst_resm(TWARN|TERRNO, "opening %s failed", file);
		} else {
			close(fd);
			execlp(file, basename(file), NULL);
		}
		return 1;
	case 3:
		/*
		 * Validate MS_SYNCHRONOUS flag of mount call.
		 * Copy some data into data buffer.
		 */

		strcpy(write_buffer, "abcdefghijklmnopqrstuvwxyz");

		/* Creat a temporary file under above directory */
		snprintf(file, PATH_MAX, "%s%s", Path_name, TEMP_FILE);
		if ((fildes = open(file, O_RDWR | O_CREAT, FILE_MODE))
		    == -1) {
			tst_resm(TWARN|TERRNO,
			    "open(%s, O_RDWR|O_CREAT, %#o) failed",
			    file, FILE_MODE);
			return 1;
		}

		/* Write the buffer data into file */
		if (write(fildes, write_buffer, strlen(write_buffer)) !=
		    strlen(write_buffer)) {
			tst_resm(TWARN|TERRNO, "writing to %s failed", file);
			close(fildes);
			return 1;
		}

		/* Set the file ptr to b'nning of file */
		if (lseek(fildes, 0, SEEK_SET) < 0) {
			tst_resm(TWARN, "lseek() failed on %s, error="
				 " %d", file, errno);
			close(fildes);
			return 1;
		}

		/* Read the contents of file */
		if (read(fildes, read_buffer, sizeof(read_buffer)) > 0) {
			if (strcmp(read_buffer, write_buffer)) {
				tst_resm(TWARN, "Data read from %s and written "
				    "mismatch", file);
				close(fildes);
				return 1;
			} else {
				close(fildes);
				return 0;
			}
		} else {
			tst_resm(TWARN|TERRNO, "read() Fails on %s", file);
			close(fildes);
			return 1;
		}

	case 4:
		/* Validate MS_REMOUNT flag of mount call */

		TEST(mount(device, mntpoint, Fstype, MS_REMOUNT, NULL));
		if (TEST_RETURN != 0) {
			tst_resm(TWARN|TTERRNO, "mount(2) failed to remount");
			return 1;
		} else {
			snprintf(file, PATH_MAX, "%stmp2", Path_name);
			if ((fd = open(file, O_CREAT | O_RDWR, S_IRWXU))
			    == -1) {
				tst_resm(TWARN, "open(%s) on readonly "
					 "filesystem passed", file);
				return 1;
			} else {
				close(fd);
				return 0;
			}
		}
	case 5:
		/* Validate MS_NOSUID flag of mount call */

		if (setup_uid() != 0) {
			tst_resm(TBROK|TERRNO, "setup_uid failed");
			return 1;
		}
		switch (pid = fork()) {
		case -1:
			tst_resm(TBROK|TERRNO, "fork failed");
			return 1;
		case 0:
			snprintf(file, PATH_MAX, "%ssetuid_test", Path_name);
			if (chmod(file, SUID_MODE) != 0) {
				tst_resm(TWARN, "chmod(%s, %#o) failed",
				    file, SUID_MODE);
			}

			ltpuser = getpwnam(nobody_uid);
			if (setreuid(ltpuser->pw_uid, ltpuser->pw_uid) == -1) {
				tst_resm(TWARN|TERRNO,
				    "seteuid() failed to change euid to %d",
				    ltpuser->pw_uid);
			}
			execlp(file, basename(file), NULL);
			exit(1);
		default:
			waitpid(pid, &status, 0);
			if (WIFEXITED(status)) {
				/* reset the setup_uid */
				if (status)
					return 0;
				else
					return 1;
			}
		}
	}
	return 0;
}