-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathsudo.c
29 lines (25 loc) · 867 Bytes
/
sudo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Setup a Linux user namespace. Then run the specified commands there. The
// default command is the default user shell.
//
// This is useful to access files written to disk by a container, when they
// where written by a non-root user (from the containers perspective). It can
// also be used as a general purpose utility to "fake" root access.
#define USAGE "usage: plash sudo [CMD1 [CMD2 ..]]\n"
#include <pwd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <plash.h>
int sudo_main(int argc, char *argv[]) {
struct passwd *pw = getpwuid(getuid());
pl_unshare_user();
pl_unshare_mount();
char *default_shell = pw ? pw->pw_shell : "/bin/sh";
if (argc <= 1) {
execlp(default_shell, default_shell, NULL);
} else {
execvp(argv[1], argv + 1);
}
pl_fatal("could not exec \"%s\"", argv[1]);
return EXIT_SUCCESS;
}