static void hal_property_modified(LibHalContext *ctx, const char *udi, const char *key, dbus_bool_t is_removed, dbus_bool_t is_added) { if (!strcmp(key, "volume.is_mounted")) { if (libhal_device_get_property_bool(ctx, udi, "volume.is_mounted", NULL)) { char *mountpoint = libhal_device_get_property_string( ctx, udi, "volume.mount_point", NULL); if (!strncmp(MEDIA_DIR, mountpoint, strlen(MEDIA_DIR))) { add_mount(udi, mountpoint); } if (mountpoint) libhal_free_string(mountpoint); } else { remove_mount(udi); } update_status(); } }
int main(int argc, char *argv[]) { int a; int fd; int res; char *origmnt; char *mnt; int unmount = 0; char **userprog; int numargs; char mypath[PATH_MAX]; char *unmount_cmd; char *commfd; char verstr[128]; int flags = 0; progname = argv[0]; for(a = 1; a < argc; a++) { if(argv[a][0] != '-') break; switch(argv[a][1]) { case 'c': flags |= FUSE_KERNEL_CACHE; break; case 'h': usage(); break; case 'u': unmount = 1; break; case 'p': flags |= FUSE_DEFAULT_PERMISSIONS; break; case 'x': if(getuid() != 0) { fprintf(stderr, "%s: option %s is allowed only for root\n", progname, argv[a]); exit(1); } flags |= FUSE_ALLOW_OTHER; break; default: fprintf(stderr, "%s: Unknown option %s\n", progname, argv[a]); exit(1); } } if(a == argc) { fprintf(stderr, "%s: Missing mountpoint argument\n", progname); exit(1); } origmnt = argv[a++]; if(getpid() != 0) drop_privs(); mnt = resolve_path(origmnt, unmount); if(mnt == NULL) exit(1); if(getpid() != 0) restore_privs(); if(unmount) { res = remove_mount(mnt); if(res == -1) exit(1); return 0; } commfd = getenv(FUSE_COMMFD_ENV); if(a == argc && commfd == NULL) { fprintf(stderr, "%s: Missing program argument\n", progname); exit(1); } userprog = argv + a; numargs = argc - a; fd = mount_fuse(mnt, flags); if(fd == -1) exit(1); if(commfd != NULL) { int cfd = atoi(commfd); res = send_fd(cfd, fd); if(res == -1) exit(1); exit(0); } /* Dup the file descriptor to stdin */ if(fd != 0) { dup2(fd, 0); close(fd); } /* Strangely this doesn't work after dropping permissions... */ res = readlink("/proc/self/exe", mypath, sizeof(mypath) - 1); if(res == -1) { fprintf(stderr, "%s: failed to determine self path: %s\n", progname, strerror(errno)); strcpy(mypath, "fusermount"); fprintf(stderr, "using %s as the default\n", mypath); } else mypath[res] = '\0'; /* Drop setuid/setgid permissions */ setuid(getuid()); setgid(getgid()); unmount_cmd = (char *) malloc(strlen(mypath) + strlen(mnt) + 64); sprintf(unmount_cmd, "%s -u %s", mypath, mnt); setenv(FUSE_UMOUNT_CMD_ENV, unmount_cmd, 1); sprintf(verstr, "%i", FUSE_KERNEL_VERSION); setenv(FUSE_KERNEL_VERSION_ENV, verstr, 1); setenv(FUSE_MOUNTED_ENV, "", 1); execvp(userprog[0], userprog); fprintf(stderr, "%s: failed to exec %s: %s\n", progname, userprog[0], strerror(errno)); close(0); system(unmount_cmd); return 1; }