Skip to content

Commit

Permalink
Escape commas in fsname option if libfuse supports it
Browse files Browse the repository at this point in the history
  • Loading branch information
szmi committed Oct 20, 2008
1 parent c7dbdc1 commit be44229
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 16 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2008-10-20 Miklos Szeredi <miklos@szeredi.hu>

* Escape commas in fsname option if libfuse supports it

2008-10-08 Miklos Szeredi <miklos@szeredi.hu>

* Handle numerical IPv6 addresses enclosed in square brackets.
Expand Down
57 changes: 41 additions & 16 deletions sshfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3121,6 +3121,42 @@ static char *find_base_path(void)
return s;
}

/*
* Remove commas from fsname, as it confuses the fuse option parser.
*/
static void fsname_remove_commas(char *fsname)
{
if (strchr(fsname, ',') != NULL) {
char *s = fsname;
char *d = s;

for (; *s; s++) {
if (*s != ',')
*d++ = *s;
}
*d = *s;
}
}

#if FUSE_VERSION >= 27
static char *fsname_escape_commas(char *fsnameold)
{
char *fsname = g_malloc(strlen(fsnameold) * 2 + 1);
char *d = fsname;
char *s;

for (s = fsnameold; *s; s++) {
if (*s == '\\' || *s == ',')
*d++ = '\\';
*d++ = *s;
}
*d = '\0';
g_free(fsnameold);

return fsname;
}
#endif

int main(int argc, char *argv[])
{
int res;
Expand Down Expand Up @@ -3237,27 +3273,16 @@ int main(int argc, char *argv[])
tmp = g_strdup_printf("-omax_write=%u", sshfs.max_write);
fuse_opt_insert_arg(&args, 1, tmp);
g_free(tmp);
/*
* Remove commas from fsname, as it confuses the fuse option
* parser.
*
* FIXME: escape commas instead. Needs support in libfuse.
*/
if (strchr(fsname, ',') != NULL) {
char *s = fsname;
char *d = s;

for (; *s; s++) {
if (*s != ',')
*d++ = *s;
}
*d = *s;
}
#if FUSE_VERSION >= 27
libver = fuse_version();
assert(libver >= 27);
if (libver >= 28)
fsname = fsname_escape_commas(fsname);
else
fsname_remove_commas(fsname);
tmp = g_strdup_printf("-osubtype=sshfs,fsname=%s", fsname);
#else
fsname_remove_commas(fsname);
tmp = g_strdup_printf("-ofsname=sshfs#%s", fsname);
#endif
fuse_opt_insert_arg(&args, 1, tmp);
Expand Down

0 comments on commit be44229

Please sign in to comment.