From e85d986494a896bbe9e47178c9c8daa1ad8c27ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Pierre=20Andr=C3=A9?= Date: Mon, 23 Jan 2012 18:00:18 +0100 Subject: [PATCH] Put the device name as the last option On OpenIndiana the device names have commas, so put it as the last option to prevent defeating the options parsing. --- src/lowntfs-3g.c | 6 +++--- src/ntfs-3g.c | 6 +++--- src/ntfs-3g_common.c | 48 ++++++++++++++++++++++++++++++++++++++++++++ src/ntfs-3g_common.h | 1 + 4 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/lowntfs-3g.c b/src/lowntfs-3g.c index c22badb7..4aa6e86e 100644 --- a/src/lowntfs-3g.c +++ b/src/lowntfs-3g.c @@ -3908,7 +3908,7 @@ int main(int argc, char *argv[]) else { permissions_mode = "User mapping built, Posix ACLs in use"; #if KERNELACLS - if (ntfs_strappend(&parsed_options, + if (ntfs_strinsert(&parsed_options, ",default_permissions,acl")) { err = NTFS_VOLUME_SYNTAX_ERROR; goto err_out; @@ -3924,7 +3924,7 @@ int main(int argc, char *argv[]) */ #if KERNELPERMS ctx->vol->secure_flags |= (1 << SECURITY_DEFAULT); - if (ntfs_strappend(&parsed_options, ",default_permissions")) { + if (ntfs_strinsert(&parsed_options, ",default_permissions")) { err = NTFS_VOLUME_SYNTAX_ERROR; goto err_out; } @@ -3941,7 +3941,7 @@ int main(int argc, char *argv[]) if ((ctx->vol->secure_flags & (1 << SECURITY_WANTED)) && !(ctx->vol->secure_flags & (1 << SECURITY_DEFAULT))) { ctx->vol->secure_flags |= (1 << SECURITY_DEFAULT); - if (ntfs_strappend(&parsed_options, ",default_permissions")) { + if (ntfs_strinsert(&parsed_options, ",default_permissions")) { err = NTFS_VOLUME_SYNTAX_ERROR; goto err_out; } diff --git a/src/ntfs-3g.c b/src/ntfs-3g.c index 6c827180..fce4b6ae 100644 --- a/src/ntfs-3g.c +++ b/src/ntfs-3g.c @@ -3763,7 +3763,7 @@ int main(int argc, char *argv[]) else { permissions_mode = "User mapping built, Posix ACLs in use"; #if KERNELACLS - if (ntfs_strappend(&parsed_options, ",default_permissions,acl")) { + if (ntfs_strinsert(&parsed_options, ",default_permissions,acl")) { err = NTFS_VOLUME_SYNTAX_ERROR; goto err_out; } @@ -3778,7 +3778,7 @@ int main(int argc, char *argv[]) * force default security */ ctx->vol->secure_flags |= (1 << SECURITY_DEFAULT); - if (ntfs_strappend(&parsed_options, ",default_permissions")) { + if (ntfs_strinsert(&parsed_options, ",default_permissions")) { err = NTFS_VOLUME_SYNTAX_ERROR; goto err_out; } @@ -3795,7 +3795,7 @@ int main(int argc, char *argv[]) if ((ctx->vol->secure_flags & (1 << SECURITY_WANTED)) && !(ctx->vol->secure_flags & (1 << SECURITY_DEFAULT))) { ctx->vol->secure_flags |= (1 << SECURITY_DEFAULT); - if (ntfs_strappend(&parsed_options, ",default_permissions")) { + if (ntfs_strinsert(&parsed_options, ",default_permissions")) { err = NTFS_VOLUME_SYNTAX_ERROR; goto err_out; } diff --git a/src/ntfs-3g_common.c b/src/ntfs-3g_common.c index dc5fc370..7b5131f8 100644 --- a/src/ntfs-3g_common.c +++ b/src/ntfs-3g_common.c @@ -155,6 +155,54 @@ int ntfs_strappend(char **dest, const char *append) return 0; } +/* + * Insert an option before ",fsname=" + * This is for keeping "fsname" as the last option, because on + * Solaris device names may contain commas. + */ + +int ntfs_strinsert(char **dest, const char *append) +{ + char *p, *q; + size_t size_append, size_dest = 0; + + if (!dest) + return -1; + if (!append) + return 0; + + size_append = strlen(append); + if (*dest) + size_dest = strlen(*dest); + + if (strappend_is_large(size_dest) || strappend_is_large(size_append)) { + errno = EOVERFLOW; + ntfs_log_perror("%s: Too large input buffer", EXEC_NAME); + return -1; + } + + p = (char*)malloc(size_dest + size_append + 1); + if (!p) { + ntfs_log_perror("%s: Memory reallocation failed", EXEC_NAME); + return -1; + } + strcpy(p, *dest); + q = strstr(p, ",fsname="); + if (q) { + strcpy(q, append); + q = strstr(*dest, ",fsname="); + if (q) + strcat(p, q); + free(*dest); + *dest = p; + } else { + free(*dest); + *dest = p; + strcpy(*dest + size_dest, append); + } + return 0; +} + static int bogus_option_value(char *val, const char *s) { if (val) { diff --git a/src/ntfs-3g_common.h b/src/ntfs-3g_common.h index 9d269841..47586606 100644 --- a/src/ntfs-3g_common.h +++ b/src/ntfs-3g_common.h @@ -172,6 +172,7 @@ extern const char nf_ns_trusted_prefix[]; extern const int nf_ns_trusted_prefix_len; int ntfs_strappend(char **dest, const char *append); +int ntfs_strinsert(char **dest, const char *append); char *parse_mount_options(ntfs_fuse_context_t *ctx, const struct ntfs_options *popts, BOOL low_fuse); int ntfs_parse_options(struct ntfs_options *popts, void (*usage)(void),