2 #include <sys/socket.h>
10 unsigned int rcvbuf = 16*1024*1024;
11 unsigned int arg_length = 128;
12 unsigned int mountflags = MS_NODEV | MS_NOSUID;
14 void receive_argument(int control_channel_fd, char *source) {
16 received=recv(control_channel_fd, source, arg_length, 0);
17 if (received<arg_length) {
18 printf("Error receiving arguments over the control buffer\n");
23 int set_magic_fd (char *data, int new_fd) {
27 data[arg_length-1]='\0';
28 ptr = strstr(data,"fd=");
32 // Found two fd= expressions
33 if (strstr(ptr+3,"fd="))
37 char *new_data = (char *) malloc(arg_length);
38 char *head = (char *) malloc(arg_length);
39 char *tail = (char *) malloc(arg_length);
40 sscanf(ptr+3,"%d",&fd);
41 strncpy(head, data, ptr - data);
42 tail = strchr(ptr+3,',');
43 sprintf(new_data,"%sfd=%d,%s",head,new_fd,tail);
44 strcpy(data,new_data);
54 void check_source(char *source) {
55 source[arg_length-1]='\0';
56 if (strchr(source,'/') || strstr(source,"..")) {
57 printf("Tried mounting with source = %s\n", source);
62 void check_target(char *target) {
63 target[arg_length-1]='\0';
64 if (strstr(target,"..")) {
65 printf("Tried mounting with target = %s\n", target);
70 void check_fstype(char *filesystemtype) {
71 if (strncmp(filesystemtype,"fuse",4)) {
72 printf("Tried mounting filesystem type %s\n", filesystemtype);
76 int main(int argc, char *argv[]) {
77 int control_channel_fd, magic_fd, mount_fd;
78 char source[128],target[128],filesystemtype[128],data[128],slice_target[256];
83 printf("This script is called by vsys.\n");
87 char *slice_name = argv[1];
89 sscanf(argv[2],"%d", &control_channel_fd);
91 if (control_channel_fd <3 || control_channel_fd > 1023) {
92 printf ("Got control_channel_fd = %d\n", control_channel_fd);
96 receive_argument(control_channel_fd, source);
97 receive_argument(control_channel_fd, target);
98 receive_argument(control_channel_fd, filesystemtype);
99 receive_argument(control_channel_fd, data);
101 mount_fd = receive_fd (control_channel_fd);
104 printf("mount_fd = %d\n", mount_fd);
108 set_magic_fd(data, mount_fd);
111 check_source(source);
112 check_target(target);
113 check_fstype(filesystemtype);
115 sprintf(slice_target,"/vservers/%s/%s", target);
117 if (!mount(source, slice_target, filesystemtype, mountflags, data)) {
118 send_fd(control_channel_fd, mount_fd);
121 printf ("Error executing mount\n");