2011-03-15 16:43:43 +01:00
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <grp.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/fsuid.h>
|
|
|
|
#include <gui-fatal.h>
|
|
|
|
#include <errno.h>
|
2013-03-20 06:21:16 +01:00
|
|
|
#include <libqubes-rpc-filecopy.h>
|
2013-02-23 13:11:59 +01:00
|
|
|
#define INCOMING_DIR_ROOT "/home/user/QubesIncoming"
|
2011-03-15 16:43:43 +01:00
|
|
|
int prepare_creds_return_uid(char *username)
|
|
|
|
{
|
|
|
|
struct passwd *pwd;
|
|
|
|
pwd = getpwnam(username);
|
|
|
|
if (!pwd) {
|
|
|
|
perror("getpwnam");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
setenv("HOME", pwd->pw_dir, 1);
|
|
|
|
setenv("USER", username, 1);
|
|
|
|
setgid(pwd->pw_gid);
|
|
|
|
initgroups(username, pwd->pw_gid);
|
|
|
|
setfsuid(pwd->pw_uid);
|
|
|
|
return pwd->pw_uid;
|
|
|
|
}
|
|
|
|
|
2013-03-20 06:21:16 +01:00
|
|
|
|
|
|
|
void notify_progress(int p1, int p2)
|
|
|
|
{
|
|
|
|
}
|
2011-03-15 16:43:43 +01:00
|
|
|
|
|
|
|
int main(int argc, char ** argv)
|
|
|
|
{
|
|
|
|
char *incoming_dir;
|
|
|
|
int uid;
|
2012-07-14 22:54:23 +02:00
|
|
|
char *remote_domain;
|
2011-03-15 16:43:43 +01:00
|
|
|
|
|
|
|
uid = prepare_creds_return_uid("user");
|
|
|
|
|
2012-07-14 22:54:23 +02:00
|
|
|
remote_domain = getenv("QREXEC_REMOTE_DOMAIN");
|
|
|
|
if (!remote_domain) {
|
|
|
|
gui_fatal("Cannot get remote domain name");
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-03-15 16:43:43 +01:00
|
|
|
mkdir(INCOMING_DIR_ROOT, 0700);
|
2013-02-23 13:11:59 +01:00
|
|
|
asprintf(&incoming_dir, "%s/%s", INCOMING_DIR_ROOT, remote_domain);
|
2011-03-15 16:43:43 +01:00
|
|
|
mkdir(incoming_dir, 0700);
|
|
|
|
if (chdir(incoming_dir))
|
|
|
|
gui_fatal("Error chdir to %s", incoming_dir);
|
2012-08-25 02:09:45 +02:00
|
|
|
if (chroot(incoming_dir)) //impossible
|
|
|
|
gui_fatal("Error chroot to %s", incoming_dir);
|
2011-03-15 16:43:43 +01:00
|
|
|
setuid(uid);
|
2012-08-25 02:09:45 +02:00
|
|
|
return do_unpack();
|
2011-03-15 16:43:43 +01:00
|
|
|
}
|