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 get_magic_fd (char *data) {
27 data[arg_length-1]='\0';
28 ptr = strstr(data,"fd=");
32 // Found two fd= expressions
33 if (strstr(ptr+3,"fd="))
37 sscanf(ptr+3,"%d",&fd);
44 void check_source(char *source) {
45 source[arg_length-1]='\0';
46 if (strchr(source,'/') || strstr(source,"..")) {
47 printf("Tried mounting with source = %s\n", source);
52 void check_target(char *target) {
53 target[arg_length-1]='\0';
54 if (strstr(target,"..")) {
55 printf("Tried mounting with target = %s\n", target);
60 void check_fstype(char *filesystemtype) {
61 if (strncmp(filesystemtype,"fuse",4)) {
62 printf("Tried mounting filesystem type %s\n", filesystemtype);
66 int main(int argc, char *argv[]) {
67 int control_channel_fd, magic_fd, mount_fd;
68 char source[128],target[128],filesystemtype[128],data[128],slice_target[256];
73 printf("This script is called by vsys.\n");
77 char *slice_name = argv[1];
79 sscanf(argv[2],"%d", &control_channel_fd);
81 if (control_channel_fd <3 || control_channel_fd > 1023) {
82 printf ("Got control_channel_fd = %d\n", control_channel_fd);
86 receive_argument(control_channel_fd, source);
87 receive_argument(control_channel_fd, target);
88 receive_argument(control_channel_fd, filesystemtype);
89 receive_argument(control_channel_fd, data);
91 magic_fd = get_magic_fd (data);
94 printf("Got fd %d in fusemount\n",magic_fd);
98 mount_fd = receive_fd (control_channel_fd);
100 if (mount_fd != magic_fd) {
101 printf("mount_fd (%d) != magic_fd (%d)\n", mount_fd, magic_fd);
105 check_source(source);
106 check_target(target);
107 check_fstype(filesystemtype);
109 sprintf(slice_target,"/vservers/%s/%s", target);
111 if (!mount(source, slice_target, filesystemtype, mountflags, data)) {
112 send_fd(control_channel_fd, magic_fd);