#define _XOPEN_SOURCE
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/types.h>
#include <pwd.h>
#include <unistd.h>
int chroot(char *path);
void check(int p, char *ctx) {
if (p) {
return;
}
fprintf(stderr, "%s: %s\n", ctx, strerror(errno));
exit(1);
}
int main(int argc, char *argv[]) {
struct passwd *nobody = getpwnam("nobody");
check(nobody != NULL, "getpwnam");
int r;
r = chroot("/usr/lib/qemu-minimal-static");
check(r == 0, "chroot");
r = setgid(nobody->pw_gid);
check(r == 0, "setgid");
r = setegid(nobody->pw_gid);
check(r == 0, "setegid");
r = setuid(nobody->pw_uid);
check(r == 0, "setuid");
r = seteuid(nobody->pw_uid);
check(r == 0, "seteuid");
r = execv(argv[1], &argv[1]);
check(r == 0, "execv");
return 1;
}