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; return pwd->pw_dir;
} }
int main(int argc __attribute((__unused__)), char ** argv __attribute__((__unused__))) int main(int argc, char ** argv)
{ {
char *home_dir; char *home_dir;
char *incoming_dir_root; char *incoming_dir_root;
@ -46,10 +46,18 @@ int main(int argc __attribute((__unused__)), char ** argv __attribute__((__unuse
const char *remote_domain; const char *remote_domain;
char *procdir_path; char *procdir_path;
int procfs_fd; int procfs_fd;
int i;
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(); uid = getuid();
home_dir = prepare_creds_return_dir(uid); home_dir = prepare_creds_return_dir(uid);
remote_domain = getenv("QREXEC_REMOTE_DOMAIN"); remote_domain = getenv("QREXEC_REMOTE_DOMAIN");
if (!remote_domain) { if (!remote_domain) {
gui_fatal("Cannot get remote domain name"); gui_fatal("Cannot get remote domain name");
@ -62,6 +70,15 @@ int main(int argc __attribute((__unused__)), char ** argv __attribute__((__unuse
if (asprintf(&incoming_dir, "%s/%s", incoming_dir_root, remote_domain) < 0) if (asprintf(&incoming_dir, "%s/%s", incoming_dir_root, remote_domain) < 0)
gui_fatal("Error allocating memory"); gui_fatal("Error allocating memory");
mkdir(incoming_dir, 0700); mkdir(incoming_dir, 0700);
}
for (i = 3; i < argc; i++) {
if (strcmp(argv[i], "-v") == 0)
set_verbose(1);
else
gui_fatal("Invalid option %s", argv[i]);
}
if (chdir(incoming_dir)) if (chdir(incoming_dir))
gui_fatal("Error chdir to %s", incoming_dir); gui_fatal("Error chdir to %s", incoming_dir);