Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/vpnns.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,8 @@ static int connect_to_watcher(const char *statedir)
return fd;
}

static uid_t muid = 0, mgid = 0;

static int create_ns(const char *statedir, const char *name)
{
char str[64];
Expand All @@ -489,9 +491,9 @@ static int create_ns(const char *statedir, const char *name)

if (access("/proc/self/setgroups", O_RDONLY) == 0)
write_file("/proc/self/setgroups", "deny");
snprintf(str, sizeof(str), "0 %d 1", uid);
snprintf(str, sizeof(str), "%d %d 1", muid, uid);
write_file("/proc/self/uid_map", str);
snprintf(str, sizeof(str), "0 %d 1", gid);
snprintf(str, sizeof(str), "%d %d 1", mgid, gid);
write_file("/proc/self/gid_map", str);

if (sethostname(name, strlen(name)) < 0)
Expand Down Expand Up @@ -803,6 +805,8 @@ static struct option longopts[] = {
{ "script", 1, NULL, 's' },
{ "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'v' },
{ "uid", 1, NULL, 'u' },
{ "gid", 1, NULL, 'g' },
{ NULL }
};

Expand All @@ -829,6 +833,12 @@ int main(int argc, char **argv)
case 's':
script = optarg;
break;
case 'u':
muid = (uid_t) strtol(optarg, (char**) NULL, 10);
break;
case 'g':
mgid = (uid_t) strtol(optarg, (char**) NULL, 10);
break;
case 'h':
case '?':
show_help();
Expand Down