From 1789242933ddbc3e4a29662f5218b5b94ee30863 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Wed, 29 Aug 2018 10:01:45 +0200 Subject: rootless: add new function to join existing namespace Signed-off-by: Giuseppe Scrivano Closes: #1371 Approved by: rhatdan --- pkg/rootless/rootless_linux.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'pkg/rootless/rootless_linux.c') diff --git a/pkg/rootless/rootless_linux.c b/pkg/rootless/rootless_linux.c index 1b98f76eb..e894328ce 100644 --- a/pkg/rootless/rootless_linux.c +++ b/pkg/rootless/rootless_linux.c @@ -83,7 +83,37 @@ get_cmd_line_args (pid_t pid) } int -reexec_in_user_namespace(int ready) +reexec_userns_join (int userns) +{ + pid_t ppid = getpid (); + char uid[16]; + char **argv; + int pid; + + sprintf (uid, "%d", geteuid ()); + + argv = get_cmd_line_args (ppid); + if (argv == NULL) + _exit (EXIT_FAILURE); + + pid = fork (); + if (pid) + return pid; + + setenv ("_LIBPOD_USERNS_CONFIGURED", "init", 1); + setenv ("_LIBPOD_ROOTLESS_UID", uid, 1); + + if (setns (userns, 0) < 0) + _exit (EXIT_FAILURE); + close (userns); + + execvp (argv[0], argv); + + _exit (EXIT_FAILURE); +} + +int +reexec_in_user_namespace (int ready) { int ret; pid_t pid; -- cgit v1.2.3-54-g00ecf