use util-vserver's style of config, not sapan's funky style.
[util-vserver-pl.git] / src / netns.c
diff --git a/src/netns.c b/src/netns.c
new file mode 100644 (file)
index 0000000..eea16f9
--- /dev/null
@@ -0,0 +1,38 @@
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include "vserver.h"
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <pwd.h>
+
+#define     SPACE_FILE      "/spaces/net"
+#define     VSERVERCONF     "/etc/vservers/"
+
+uint32_t
+get_space_flag(xid_t xid) {
+    char *ctx_space_file, *space_name;
+    struct passwd *slice_user;
+    uint32_t space_flag = 0;
+
+    slice_user = get_pwuid(xid);
+
+    if (!slice_user)
+        return 0;
+
+    ctx_space_file=(char *) malloc(sizeof(VSERVERCONF SPACE_FILE "Z")+strlen(slice_user->pw_name));
+    if (!ctx_space_file)
+        return 0;
+
+    sprintf(ctx_space_file,VSERVERCONF SPACE_FILE "%s", slice_user->pw_name);
+
+    if (access(ctx_space_file, F_OK)==0)
+        space_flag |= CLONE_NEWNET;
+
+    free(ctx_space_dir);
+    return space_flag;
+}