summaryrefslogtreecommitdiffstats
path: root/utils/mount/nfsmount.c
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2007-03-19 21:02:40 +0100
committerNeil Brown <neilb@suse.de>2007-03-20 14:30:42 +1100
commit6facb22402a0bd8cd49be2ed1a0856b24fef42f4 (patch)
treecf7cb7f96b8e36726f9506270436b25e7395b080 /utils/mount/nfsmount.c
parentb3b111b1bd5fbc678419bf1964b6093045081139 (diff)
downloadnfs-utils-6facb22402a0bd8cd49be2ed1a0856b24fef42f4.tar.gz
nfs-utils-6facb22402a0bd8cd49be2ed1a0856b24fef42f4.tar.xz
nfs-utils-6facb22402a0bd8cd49be2ed1a0856b24fef42f4.zip
Add support for quoted mount options
The patch avoid the collision between commas in security contexts and the delimiter between mount options. Try: mount.nfs foo://mnt/bar /mnt/bar -o context=\"aaa,bbb,ccc\",ro Signed-off-by: Cory Olmo <colmo@TrustedCS.com> Signed-off-by: Karel Zak <kzak@redhat.com> Signed-off-by: Neil Brown <neilb@suse.de>
Diffstat (limited to 'utils/mount/nfsmount.c')
-rw-r--r--utils/mount/nfsmount.c44
1 files changed, 35 insertions, 9 deletions
diff --git a/utils/mount/nfsmount.c b/utils/mount/nfsmount.c
index eac9590..4049e66 100644
--- a/utils/mount/nfsmount.c
+++ b/utils/mount/nfsmount.c
@@ -548,15 +548,31 @@ parse_options(char *old_opts, struct nfs_mount_data *data,
struct pmap *mnt_pmap = &mnt_server->pmap;
struct pmap *nfs_pmap = &nfs_server->pmap;
int len;
- char *opt, *opteq;
+ char *opt, *opteq, *p, *opt_b;
char *mounthost = NULL;
char cbuf[128];
+ int open_quote = 0;
data->flags = 0;
*bg = 0;
len = strlen(new_opts);
- for (opt = strtok(old_opts, ","); opt; opt = strtok(NULL, ",")) {
+ for (p=old_opts, opt_b=NULL; p && *p; p++) {
+ if (!opt_b)
+ opt_b = p; /* begin of the option item */
+ if (*p == '"')
+ open_quote ^= 1; /* reverse the status */
+ if (open_quote)
+ continue; /* still in a quoted block */
+ if (*p == ',')
+ *p = '\0'; /* terminate the option item */
+ if (*p == '\0' || *(p+1) == '\0') {
+ opt = opt_b; /* opt is useful now */
+ opt_b = NULL;
+ }
+ else
+ continue; /* still somewhere in the option item */
+
if (strlen(opt) >= sizeof(cbuf))
goto bad_parameter;
if ((opteq = strchr(opt, '=')) && isdigit(opteq[1])) {
@@ -680,14 +696,24 @@ parse_options(char *old_opts, struct nfs_mount_data *data,
mounthost=xstrndup(opteq+1,
strcspn(opteq+1," \t\n\r,"));
else if (!strcmp(opt, "context")) {
- char *context = opteq + 1;
-
- if (strlen(context) > NFS_MAX_CONTEXT_LEN) {
- printf(_("context parameter exceeds limit of %d\n"),
- NFS_MAX_CONTEXT_LEN);
+ char *context = opteq + 1;
+ int ctxlen = strlen(context);
+
+ if (ctxlen > NFS_MAX_CONTEXT_LEN) {
+ printf(_("context parameter exceeds limit of %d\n"),
+ NFS_MAX_CONTEXT_LEN);
goto bad_parameter;
- }
- strncpy(data->context, context, NFS_MAX_CONTEXT_LEN);
+ }
+ /* The context string is in the format of
+ * "system_u:object_r:...". We only want
+ * the context str between the quotes.
+ */
+ if (*context == '"')
+ strncpy(data->context, context+1,
+ ctxlen-2);
+ else
+ strncpy(data->context, context,
+ NFS_MAX_CONTEXT_LEN);
} else if (sloppy)
continue;
else