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;
16 void receive_argument(int control_channel_fd, char *source) {
18 received=recv(control_channel_fd, source, arg_length, 0);
19 if (received<arg_length) {
20 fprintf(logfd,"Error receiving arguments over the control buffer\n");
26 int set_magic_fd (char *data, int new_fd) {
30 data[arg_length-1]='\0';
31 ptr = strstr(data,"fd=");
35 // Found two fd= expressions
36 if (strstr(ptr+3,"fd="))
40 char *new_data = (char *) malloc(arg_length);
41 char *head = (char *) malloc(arg_length);
42 char *tail = (char *) malloc(arg_length);
43 sscanf(ptr+3,"%d",&fd);
44 strncpy(head, data, ptr - data);
45 tail = strchr(ptr+3,',');
46 sprintf(new_data,"%sfd=%d,%s",head,new_fd,tail);
47 strcpy(data,new_data);
57 void check_source(char *source) {
58 source[arg_length-1]='\0';
59 if (strchr(source,'/') || strstr(source,"..")) {
60 fprintf(logfd, "Tried mounting with source = %s\n", source);
66 void check_target(char *target) {
67 target[arg_length-1]='\0';
68 if (strstr(target,"..")) {
69 fprintf(logfd,"Tried mounting with target = %s\n", target);
75 void check_fstype(char *filesystemtype) {
76 if (strncmp(filesystemtype,"fuse",4)) {
77 fprintf(logfd,"Tried mounting filesystem type %s\n", filesystemtype);
83 int main(int argc, char *argv[]) {
84 int control_channel_fd, magic_fd, mount_fd;
85 char source[128],target[128],filesystemtype[128],data[128],slice_target[1024];
90 printf("This script is called by vsys.\n");
94 char *slice_name = argv[1];
96 logfd=fopen("/tmp/fuselog","w");
97 if (!logfd) {logfd = stderr;}
99 sscanf(argv[2],"%d", &control_channel_fd);
101 if (control_channel_fd <3 || control_channel_fd > 1023) {
102 printf ("Got control_channel_fd = %d\n", control_channel_fd);
106 receive_argument(control_channel_fd, source);
107 receive_argument(control_channel_fd, target);
108 receive_argument(control_channel_fd, filesystemtype);
109 receive_argument(control_channel_fd, data);
111 mount_fd = receive_fd (control_channel_fd);
114 printf("mount_fd = %d\n", mount_fd);
118 set_magic_fd(data, mount_fd);
121 check_source(source);
122 check_target(target);
123 check_fstype(filesystemtype);
125 sprintf(slice_target,"/vservers/%s/%s", slice_name, target);
127 fprintf(logfd, "Mount fd: %d Source: %s slice_target: %s fstype: %s mountflags: %d data: %s\n", mount_fd, source, slice_target, filesystemtype, mountflags, data);
129 if (!mount(source, slice_target, filesystemtype, mountflags, data)) {
130 send_fd(control_channel_fd, mount_fd);
133 printf ("Error executing mount\n");