contd...
[util-vserver-pl.git] / src / netns.c
1 #ifdef HAVE_CONFIG_H
2 #  include <config.h>
3 #endif
4
5 #include "vserver.h"
6 #include <string.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <stdint.h>
10 #include <sys/types.h>
11 #include <pwd.h>
12 #include <unistd.h>
13
14 #define     SPACE_FILE      "/spaces/net"
15 #define     VSERVERCONF     "/etc/vservers/"
16
17 uint32_t
18 get_space_flag(xid_t xid) {
19     char *ctx_space_file, *space_name;
20     struct passwd *slice_user;
21     uint32_t space_flag = 0;
22
23     slice_user = getpwuid(xid);
24
25     if (!slice_user)
26         return 0;
27
28     ctx_space_file=(char *) malloc(sizeof(VSERVERCONF SPACE_FILE "Z")+strlen(slice_user->pw_name));
29     if (!ctx_space_file)
30         return 0;
31
32     sprintf(ctx_space_file,VSERVERCONF SPACE_FILE "%s", slice_user->pw_name);
33
34     if (access(ctx_space_file, F_OK)==0)
35         space_flag |= CLONE_NEWNET;
36
37     free(ctx_space_dir);
38     return space_flag;
39 }