9
static char *xstrdup(const char *s)
13
fprintf(stderr, "%s: failed to allocate memory\n", progname);
19
static void *xrealloc(void *oldptr, size_t size)
21
void *ptr = realloc(oldptr, size);
23
fprintf(stderr, "%s: failed to allocate memory\n", progname);
29
static void add_arg(char **cmdp, const char *opt)
31
size_t optlen = strlen(opt);
32
size_t cmdlen = *cmdp ? strlen(*cmdp) : 0;
33
char *cmd = xrealloc(*cmdp, cmdlen + optlen * 4 + 4);
54
int main(int argc, char *argv[])
58
const char *mountpoint;
66
basename = strrchr(argv[0], '/');
72
if (strncmp(basename, "mount.fuse.", 11) == 0)
74
if (strncmp(basename, "mount.fuseblk.", 14) == 0)
81
fprintf(stderr, "usage: %s %s destination [-t type] [-o opt[,opts...]]\n",
82
progname, type ? "source" : "type#[source]");
92
for (i = 3; i < argc; i++) {
93
if (strcmp(argv[i], "-v") == 0) {
95
} else if (strcmp(argv[i], "-t") == 0) {
100
"%s: missing argument to option '-t'\n", progname);
104
if (strncmp(type, "fuse.", 5) == 0)
106
else if (strncmp(type, "fuseblk.", 8) == 0)
111
"%s: empty type given as argument to option '-t'\n",
115
} else if (strcmp(argv[i], "-o") == 0) {
122
opts = xstrdup(argv[i]);
123
opt = strtok(opts, ",");
127
const char *ignore_opts[] = { "", "user", "nouser", "users",
128
"auto", "noauto", "_netdev",
130
if (strncmp(opt, "setuid=", 7) == 0) {
131
setuid = xstrdup(opt + 7);
134
for (j = 0; ignore_opts[j]; j++)
135
if (strcmp(opt, ignore_opts[j]) == 0)
139
int oldlen = options ? strlen(options) : 0;
140
options = xrealloc(options, oldlen + 1 + strlen(opt) + 1);
142
strcpy(options, opt);
144
strcat(options, ",");
145
strcat(options, opt);
148
opt = strtok(NULL, ",");
154
type = xstrdup(source);
155
source = strchr(type, '#');
160
fprintf(stderr, "%s: empty filesystem type\n", progname);
165
add_arg(&command, type);
167
add_arg(&command, source);
168
add_arg(&command, mountpoint);
170
add_arg(&command, "-o");
171
add_arg(&command, options);
174
if (setuid && setuid[0]) {
175
char *sucommand = command;
177
add_arg(&command, "su");
178
add_arg(&command, "-");
179
add_arg(&command, setuid);
180
add_arg(&command, "-c");
181
add_arg(&command, sucommand);
182
} else if (!getenv("HOME")) {
183
/* Hack to make filesystems work in the boot environment */
184
setenv("HOME", "/root", 0);
187
execl("/bin/sh", "/bin/sh", "-c", command, NULL);
188
fprintf(stderr, "%s: failed to execute /bin/sh: %s\n", progname,