fi
+AC_ARG_ENABLE(namespaces,
+[AS_HELP_STRING([--enable-namespaces],[Use Linux namespaces.])],
+[enable_namespaces=yes], [])
+
+if test "$enable_namespaces" = yes; then
+ AC_CHECK_HEADERS([sched.h], [], [AC_MSG_ERROR([sched.h not found.])], [])
+ AC_CHECK_HEADERS([sys/capability.h], [], [AC_MSG_ERROR([sys/capability.h not found.])], [])
+ AC_CHECK_LIB(cap, cap_get_proc, [LIBS+=" -lcap"], [AC_MSG_ERROR([Cannot find libcap.])])
+ AC_MSG_RESULT([Enabled Linux namespace support.])
+ AC_DEFINE(USE_NAMESPACES,1,[Use Linux namespaces])
+fi
+
+
AC_ARG_WITH(config-file,
[AS_HELP_STRING([--with-config-file=PATH],[Define the path to the default configuration file.])],
[configfile=$withval], [configfile="/etc/dgamelaunch.conf"])
# include <pty.h>
#endif
+#ifdef USE_NAMESPACES
+# include <sched.h>
+# include <sys/capability.h>
+#endif
+
#include <fcntl.h>
#include <pwd.h>
#include <grp.h>
}
}
+#ifdef USE_NAMESPACES
+void
+write_proc_maps(uid_t uid, gid_t gid)
+{
+ FILE *fp;
+
+ fp = fopen("/proc/self/setgroups", "w");
+ if (fp) {
+ fprintf(fp, "deny");
+ fclose(fp);
+ } else perror("fopen setgroups");
+
+ fp = fopen("/proc/self/uid_map", "w");
+ if (fp) {
+ fprintf(fp, "%d %d 1", globalconfig.shed_uid, uid);
+ fclose(fp);
+ } else perror("fopen uid_map");
+
+ fp = fopen("/proc/self/gid_map", "w");
+ if (fp) {
+ fprintf(fp, "%d %d 1", globalconfig.shed_gid, gid);
+ fclose(fp);
+ } else perror("fopen gid_map");
+}
+#endif
+
int
main (int argc, char** argv)
{
#endif
#endif
+#ifdef USE_NAMESPACES
+ {
+ uid_t uid = geteuid();
+ gid_t gid = getegid();
+ if (unshare(CLONE_NEWUSER | CLONE_NEWNET)) {
+ perror("unshare");
+ graceful_exit(14);
+ }
+ write_proc_maps(uid, gid);
+ }
+#endif
+
+#ifndef USE_NAMESPACES
if (geteuid () != globalconfig.shed_uid)
+#endif
{
/* chroot */
if (chroot (globalconfig.chroot))
}
/* shed privs. this is done immediately after chroot. */
+#ifdef USE_NAMESPACES
+ {
+ /* drop all capabilities */
+ cap_t cap = cap_get_proc();
+ cap_clear(cap);
+ cap_set_proc(cap);
+ cap_free(cap);
+ }
+#else
if (setgroups (1, &globalconfig.shed_gid) == -1)
{
perror ("setgroups");
perror ("setuid");
graceful_exit (6);
}
+#endif
}
if (globalconfig.locale) {