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);
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);
56 void check_source(char *source) {
57 source[arg_length-1]='\0';
58 if (strchr(source,'/') || strstr(source,"..")) {
59 fprintf(logfd, "Tried mounting with source = %s\n", source);
65 void check_target(char *target) {
66 target[arg_length-1]='\0';
67 if (strstr(target,"..")) {
68 fprintf(logfd,"Tried mounting with target = %s\n", target);
74 void check_fstype(char *filesystemtype) {
75 if (strncmp(filesystemtype,"fuse",4)) {
76 fprintf(logfd,"Tried mounting filesystem type %s\n", filesystemtype);
82 int main(int argc, char *argv[]) {
83 int control_channel_fd, magic_fd, mount_fd;
84 char source[128],target[128],filesystemtype[128],data[128],slice_target[1024];
89 printf("This script is called by vsys.\n");
93 char *slice_name = argv[1];
95 logfd=fopen("/tmp/fuselog","w");
96 if (!logfd) {logfd = stderr;}
98 sscanf(argv[2],"%d", &control_channel_fd);
100 if (control_channel_fd <3 || control_channel_fd > 1023) {
101 printf ("Got control_channel_fd = %d\n", control_channel_fd);
105 receive_argument(control_channel_fd, source);
106 receive_argument(control_channel_fd, target);
107 receive_argument(control_channel_fd, filesystemtype);
108 receive_argument(control_channel_fd, data);
110 mount_fd = receive_fd (control_channel_fd);
113 printf("mount_fd = %d\n", mount_fd);
117 set_magic_fd(data, mount_fd);
120 check_source(source);
121 check_target(target);
122 check_fstype(filesystemtype);
124 sprintf(slice_target,"/vservers/%s/%s", slice_name, target);
126 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);
128 if (!mount(source, slice_target, filesystemtype, mountflags, data)) {
129 send_fd(control_channel_fd, mount_fd);
132 printf ("Error executing mount\n");