qfile-unpacker: add option for custom user and target directory

QubesOS/qubes-issues#930
This commit is contained in:
Marek Marczykowski-Górecki 2019-09-03 19:28:23 +02:00
parent d0b699c59f
commit cee32d4f90
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -36,7 +36,7 @@ char *prepare_creds_return_dir(int uid)
return pwd->pw_dir;
}
int main(int argc __attribute((__unused__)), char ** argv __attribute__((__unused__)))
int main(int argc, char ** argv)
{
char *home_dir;
char *incoming_dir_root;
@ -46,22 +46,39 @@ int main(int argc __attribute((__unused__)), char ** argv __attribute__((__unuse
const char *remote_domain;
char *procdir_path;
int procfs_fd;
int i;
uid = getuid();
home_dir = prepare_creds_return_dir(uid);
if (argc >= 3) {
errno = 0;
uid = strtol(argv[1], NULL, 10);
if (errno)
gui_fatal("Invalid user ID argument");
home_dir = prepare_creds_return_dir(uid);
incoming_dir = argv[2];
} else {
uid = getuid();
home_dir = prepare_creds_return_dir(uid);
remote_domain = getenv("QREXEC_REMOTE_DOMAIN");
if (!remote_domain) {
gui_fatal("Cannot get remote domain name");
}
remote_domain = getenv("QREXEC_REMOTE_DOMAIN");
if (!remote_domain) {
gui_fatal("Cannot get remote domain name");
if (asprintf(&incoming_dir_root, "%s/%s", home_dir, INCOMING_DIR_NAME) < 0) {
gui_fatal("Error allocating memory");
}
mkdir(incoming_dir_root, 0700);
if (asprintf(&incoming_dir, "%s/%s", incoming_dir_root, remote_domain) < 0)
gui_fatal("Error allocating memory");
mkdir(incoming_dir, 0700);
}
if (asprintf(&incoming_dir_root, "%s/%s", home_dir, INCOMING_DIR_NAME) < 0) {
gui_fatal("Error allocating memory");
for (i = 3; i < argc; i++) {
if (strcmp(argv[i], "-v") == 0)
set_verbose(1);
else
gui_fatal("Invalid option %s", argv[i]);
}
mkdir(incoming_dir_root, 0700);
if (asprintf(&incoming_dir, "%s/%s", incoming_dir_root, remote_domain) < 0)
gui_fatal("Error allocating memory");
mkdir(incoming_dir, 0700);
if (chdir(incoming_dir))
gui_fatal("Error chdir to %s", incoming_dir);