Exemple #1
0
int copy_and_return_nonemptiness(int tmpfd)
{
	struct stat st;
	if (!copy_fd_all(tmpfd, 0))
		gui_fatal("receiving file from dispVM");
	if (fstat(tmpfd, &st))
		gui_fatal("fstat");
	close(tmpfd);

	return st.st_size;
}
int single_file_processor(char *filename, struct stat *st)
{
	struct file_header hdr;
	int fd;
	mode_t mode = st->st_mode;

	hdr.namelen = strlen(filename) + 1;
	hdr.mode = mode;
	hdr.atime = st->st_atim.tv_sec;
	hdr.atime_nsec = st->st_atim.tv_nsec;
	hdr.mtime = st->st_mtim.tv_sec;
	hdr.mtime_nsec = st->st_mtim.tv_nsec;

	if (S_ISREG(mode)) {
		int ret;
		fd = open(filename, O_RDONLY);
		if (fd < 0)
			gui_fatal("open %s", filename);
		hdr.filelen = st->st_size;
		write_headers(&hdr, filename);
		ret = copy_file(1, fd, hdr.filelen, &crc32_sum);
		if (ret != COPY_FILE_OK) {
			if (ret != COPY_FILE_WRITE_ERROR)
				gui_fatal("Copying file %s: %s", filename,
					  copy_file_status_to_str(ret));
			else {
				set_block(0);
				wait_for_result();
				exit(1);
			}
		}
		close(fd);
	}
	if (S_ISDIR(mode)) {
		hdr.filelen = 0;
		write_headers(&hdr, filename);
	}
	if (S_ISLNK(mode) && !ignore_symlinks) {
		char name[st->st_size + 1];
		if (readlink(filename, name, sizeof(name)) != st->st_size)
			gui_fatal("readlink %s", filename);
		hdr.filelen = st->st_size + 1;
		write_headers(&hdr, filename);
		if (!write_all_with_crc(1, name, st->st_size + 1)) {
			set_block(0);
			wait_for_result();
			exit(1);
		}
	}
	// check for possible error from qfile-unpacker
	wait_for_result();
	return 0;
}
void wait_for_result()
{
	struct result_header hdr;
	struct result_header_ext hdr_ext;
	char last_filename[MAX_PATH_LENGTH + 1];
	char last_filename_prefix[] = "; Last file: ";

	if (!read_all(0, &hdr, sizeof(hdr))) {
		if (errno == EAGAIN) {
			// no result sent and stdin still open
			return;
		} else {
			// other read error or EOF
			exit(1);	// hopefully remote has produced error message
		}
	}
	if (!read_all(0, &hdr_ext, sizeof(hdr_ext))) {
		// remote used old result_header struct
		hdr_ext.last_namelen = 0;
	}
	if (hdr_ext.last_namelen > MAX_PATH_LENGTH) {
		// read only at most MAX_PATH_LENGTH chars
		hdr_ext.last_namelen = MAX_PATH_LENGTH;
	}
	if (!read_all(0, last_filename, hdr_ext.last_namelen)) {
		fprintf(stderr, "Failed to get last filename\n");
		hdr_ext.last_namelen = 0;
	}
	last_filename[hdr_ext.last_namelen] = '\0';
	if (!hdr_ext.last_namelen)
		/* set prefix to empty string */
		last_filename_prefix[0] = '\0';

	errno = hdr.error_code;
	if (hdr.error_code != 0) {
		switch (hdr.error_code) {
			case EEXIST:
				gui_fatal("File copy: not overwriting existing file. Clean QubesIncoming dir, and retry copy%s%s", last_filename_prefix, last_filename);
				break;
			case EINVAL:
				gui_fatal("File copy: Corrupted data from packer%s%s", last_filename_prefix, last_filename);
				break;
			default:
				gui_fatal("File copy: %s%s%s",
						strerror(hdr.error_code), last_filename_prefix, last_filename);
		}
	}
	if (hdr.crc32 != crc32_sum) {
		gui_fatal("File transfer failed: checksum mismatch");
	}
}
Exemple #4
0
int main(int argc, char ** argv)
{
	signal(SIGPIPE, SIG_IGN);
	if (argc!=2) 
		gui_fatal("OpenInVM - no file given?");
	talk_to_daemon(argv[1]);
	return 0;
}	
Exemple #5
0
void actually_recv_file(char *fname, char *tempfile, int tmpfd)
{
	if (!copy_and_return_nonemptiness(tmpfd)) {
		unlink(tempfile);
		return;
	}
	if (rename(tempfile, fname))
		gui_fatal("rename");
}
Exemple #6
0
void send_file(char *fname)
{
	char *base;
	int fd = open(fname, O_RDONLY);
	if (fd < 0)
		gui_fatal("open %s", fname);
	base = rindex(fname, '/');
	if (!base)
		base = fname;
	else
		base++;
	if (strlen(base) >= DVM_FILENAME_SIZE)
		base += strlen(base) - DVM_FILENAME_SIZE + 1;
	if (!write_all(1, base, DVM_FILENAME_SIZE))
		gui_fatal("send filename to dispVM");
	if (!copy_fd_all(1, fd))
		gui_fatal("send file to dispVM");
	close(1);
}
int main(int argc, char ** argv)
{
	char *incoming_dir;
	int uid;
	char *remote_domain;

	uid = prepare_creds_return_uid("user");

	remote_domain = getenv("QREXEC_REMOTE_DOMAIN");
	if (!remote_domain) {
		gui_fatal("Cannot get remote domain name");
		exit(1);
	}
	mkdir(INCOMING_DIR_ROOT, 0700);
	asprintf(&incoming_dir, "%s/%s", INCOMING_DIR_ROOT, remote_domain);
	mkdir(incoming_dir, 0700);
	if (chdir(incoming_dir))
		gui_fatal("Error chdir to %s", incoming_dir); 
	if (chroot(incoming_dir)) //impossible
		gui_fatal("Error chroot to %s", incoming_dir);
	setuid(uid);
	return do_unpack();
}
Exemple #8
0
void recv_file_nowrite(char *fname)
{
	char *tempfile;
	char *errmsg;
	int tmpfd;

	asprintf(&tempfile, "/tmp/file_edited_in_dvm.XXXXXX");
	tmpfd = mkstemp(tempfile);
	if (tmpfd < 0)
		gui_fatal("unable to create any temporary file, aborting");
	if (!copy_and_return_nonemptiness(tmpfd)) {
		unlink(tempfile);
		return;
	}
	asprintf(&errmsg,
		 "The file %s has been edited in Disposable VM and the modified content has been received, "
		 "but this file is in nonwritable directory and thus cannot be modified safely. The edited file has been "
		 "saved to %s", fname, tempfile);
	gui_nonfatal(errmsg);
}
Exemple #9
0
void vdriver_get_colors(int first_color, int num_colors, ColorSpec *colors)
{
    gui_fatal("`!vdriver_fixed_clut_p' and `vdriver_get_colors ()' called");
}
Exemple #10
0
double
scalb (double x, int n)
{
  gui_fatal ("unimplemented");
}
Exemple #11
0
double
logb (double x)
{
  gui_fatal ("unimplemented");
}