12 #include <sys/types.h>
13 #include <sys/mount.h>
16 #define ERROR(x...) fprintf(stderr, x)
21 printf("Usage: lufsmnt mount-point [options]\n");
22 printf("This is a suid wrapper called by lufsd.\n");
27 fullpath(char *path, char *full){
31 if(strlen(path) >= PATH_MAX - 1)
34 if(!realpath(path, full))
45 ERROR("cannot chdir %s\n", mp);
50 ERROR("cannot stat %s\n", mp);
54 if(!S_ISDIR(st.st_mode)){
55 ERROR("%s is not a directory\n", mp);
59 if((getuid()) && ((getuid() != st.st_uid) || ((st.st_mode & S_IRWXU) != S_IRWXU))){
60 ERROR("you don't have proper permissions to mount on %s\n", mp);
68 hide_pass(char *opts){
71 if((c = strstr(opts, "password="))){
72 for(c = c + 9; (*c != 0) && (*c != ','); c++)
78 get_fs(char *opts, char *buf, int buflen){
84 if((begin = strstr(opts, "fs="))){
87 if(!(end = strchr(begin, ','))){
88 end = begin + strlen(begin);
91 if( end - begin >= buflen)
92 end = begin + buflen - 1;
94 strncpy(buf, begin, end - begin);
99 main(int argc, char **argv){
100 char *mountpoint, *opts;
101 static char fpath[PATH_MAX];
102 static char mfs[PATH_MAX];
103 static char mopts[PATH_MAX];
114 ERROR("%s needs to be installed suid root in order to be used by unprivileged users\n", argv[0]);
118 mountpoint = argv[1];
121 fullpath(mountpoint, fpath);
127 if (mount("none", fpath, "lufs", MS_NOSUID | MS_NODEV, opts) < 0){
128 ERROR("mount failed: %s\n", strerror(errno));
131 ERROR("you don't have kernel lufs support (check whether the lufs module is available/loaded)\n");
137 sprintf(mopts, "owner=%d,", getuid());
139 if(strlen(mopts) + strlen(opts) < PATH_MAX)
141 get_fs(opts, mfs, PATH_MAX);
143 ment.mnt_fsname = mfs;
144 ment.mnt_dir = fpath;
145 ment.mnt_type = "lufs";
146 ment.mnt_opts = mopts;
150 if((fd = open(_PATH_MOUNTED"~", O_RDWR|O_CREAT|O_EXCL, 0600)) < 0){
151 ERROR("can't get "_PATH_MOUNTED"~ lock file\n");
156 if((mtab = setmntent(_PATH_MOUNTED, "a+")) == NULL){
157 ERROR("can't open "_PATH_MOUNTED"\n");
161 if(addmntent(mtab, &ment)){
162 ERROR("can't write mount entry\n");
166 if(fchmod(fileno(mtab), 0644) < 0){
167 ERROR("can't set [erms on "_PATH_MOUNTED"\n");
173 if(unlink(_PATH_MOUNTED"~") < 0){
174 ERROR("can't remove "_PATH_MOUNTED"~\n");