Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ AC_CHECK_HEADERS([resolv.h], [], [],
# include <arpa/nameser.h>
#endif
])
AC_CHECK_HEADERS([sched.h], [AC_CHECK_FUNCS([unshare])])

AC_ARG_VAR(TAR, [Specifies tar path])
AC_PATH_PROG(TAR, [tar])
Expand Down
26 changes: 26 additions & 0 deletions daemon/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#ifdef HAVE_SCHED_H
#include <sched.h>
#endif

#include "comm.h"
#include "exitcode.h"
Expand Down Expand Up @@ -667,6 +670,29 @@ error_client(MsgChannel *client, string error)

void chdir_to_environment(MsgChannel *client, const string &dirname, uid_t user_uid, gid_t user_gid)
{
#ifdef HAVE_UNSHARE
int flags = 0;
# ifdef CLONE_NEWIPC
flags |= CLONE_NEWIPC;
# endif
# ifdef CLONE_NEWNET
flags |= CLONE_NEWNET;
# endif
# ifdef CLONE_NEWNS
flags |= CLONE_NEWNS; // mount namespace
# endif
# ifdef CLONE_NEWPID
flags |= CLONE_NEWPID;
# endif
# ifdef CLONE_NEWUSER
flags |= CLONE_NEWUSER;
# endif
# ifdef CLONE_NEWUTS
flags |= CLONE_NEWUTS;
# endif
(void) unshare(flags);
#endif

#ifdef HAVE_LIBCAP_NG

if (chdir(dirname.c_str()) < 0) {
Expand Down