2020-04-16 21:39:57

by Trond Myklebust

[permalink] [raw]
Subject: [PATCH] mountd: Preserve special characters in refer and replica path options

From: Lance Shelton <[email protected]>

Allow referral paths to contain special character by adding an
escaping mechanism.

Signed-off-by: Lance Shelton <[email protected]>
Signed-off-by: Trond Myklebust <[email protected]>
---
support/nfs/exports.c | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/support/nfs/exports.c b/support/nfs/exports.c
index 8fbb6b15c299..97eb31837816 100644
--- a/support/nfs/exports.c
+++ b/support/nfs/exports.c
@@ -247,23 +247,28 @@ void secinfo_show(FILE *fp, struct exportent *ep)
}
}

+static void
+fprintpath(FILE *fp, const char *path)
+{
+ int i;
+ for (i=0; path[i]; i++)
+ if (iscntrl(path[i]) || path[i] == '"' || path[i] == '\\' || path[i] == '#' || isspace(path[i]))
+ fprintf(fp, "\\%03o", path[i]);
+ else
+ fprintf(fp, "%c", path[i]);
+}
+
void
putexportent(struct exportent *ep)
{
FILE *fp;
int *id, i;
- char *esc=ep->e_path;

if (!efp)
return;

fp = efp->x_fp;
- for (i=0; esc[i]; i++)
- if (iscntrl(esc[i]) || esc[i] == '"' || esc[i] == '\\' || esc[i] == '#' || isspace(esc[i]))
- fprintf(fp, "\\%03o", esc[i]);
- else
- fprintf(fp, "%c", esc[i]);
-
+ fprintpath(fp, ep->e_path);
fprintf(fp, "\t%s(", ep->e_hostname);
fprintf(fp, "%s,", (ep->e_flags & NFSEXP_READONLY)? "ro" : "rw");
fprintf(fp, "%ssync,", (ep->e_flags & NFSEXP_ASYNC)? "a" : "");
@@ -302,10 +307,14 @@ putexportent(struct exportent *ep)
case FSLOC_NONE:
break;
case FSLOC_REFER:
- fprintf(fp, "refer=%s,", ep->e_fslocdata);
+ fprintf(fp, "refer=");
+ fprintpath(fp, ep->e_fslocdata);
+ fprintf(fp, ",");
break;
case FSLOC_REPLICA:
- fprintf(fp, "replicas=%s,", ep->e_fslocdata);
+ fprintf(fp, "replicas=");
+ fprintpath(fp, ep->e_fslocdata);
+ fprintf(fp, ",");
break;
#ifdef DEBUG
case FSLOC_STUB:
--
2.25.2


2020-05-08 14:13:13

by Steve Dickson

[permalink] [raw]
Subject: Re: [PATCH] mountd: Preserve special characters in refer and replica path options



On 4/16/20 5:37 PM, [email protected] wrote:
> From: Lance Shelton <[email protected]>
>
> Allow referral paths to contain special character by adding an
> escaping mechanism.
>
> Signed-off-by: Lance Shelton <[email protected]>
> Signed-off-by: Trond Myklebust <[email protected]>
> ---
> support/nfs/exports.c | 27 ++++++++++++++++++---------
> 1 file changed, 18 insertions(+), 9 deletions(-)
Committed... (tag: nfs-utils-2-4-4-rc4)

steved.

>
> diff --git a/support/nfs/exports.c b/support/nfs/exports.c
> index 8fbb6b15c299..97eb31837816 100644
> --- a/support/nfs/exports.c
> +++ b/support/nfs/exports.c
> @@ -247,23 +247,28 @@ void secinfo_show(FILE *fp, struct exportent *ep)
> }
> }
>
> +static void
> +fprintpath(FILE *fp, const char *path)
> +{
> + int i;
> + for (i=0; path[i]; i++)
> + if (iscntrl(path[i]) || path[i] == '"' || path[i] == '\\' || path[i] == '#' || isspace(path[i]))
> + fprintf(fp, "\\%03o", path[i]);
> + else
> + fprintf(fp, "%c", path[i]);
> +}
> +
> void
> putexportent(struct exportent *ep)
> {
> FILE *fp;
> int *id, i;
> - char *esc=ep->e_path;
>
> if (!efp)
> return;
>
> fp = efp->x_fp;
> - for (i=0; esc[i]; i++)
> - if (iscntrl(esc[i]) || esc[i] == '"' || esc[i] == '\\' || esc[i] == '#' || isspace(esc[i]))
> - fprintf(fp, "\\%03o", esc[i]);
> - else
> - fprintf(fp, "%c", esc[i]);
> -
> + fprintpath(fp, ep->e_path);
> fprintf(fp, "\t%s(", ep->e_hostname);
> fprintf(fp, "%s,", (ep->e_flags & NFSEXP_READONLY)? "ro" : "rw");
> fprintf(fp, "%ssync,", (ep->e_flags & NFSEXP_ASYNC)? "a" : "");
> @@ -302,10 +307,14 @@ putexportent(struct exportent *ep)
> case FSLOC_NONE:
> break;
> case FSLOC_REFER:
> - fprintf(fp, "refer=%s,", ep->e_fslocdata);
> + fprintf(fp, "refer=");
> + fprintpath(fp, ep->e_fslocdata);
> + fprintf(fp, ",");
> break;
> case FSLOC_REPLICA:
> - fprintf(fp, "replicas=%s,", ep->e_fslocdata);
> + fprintf(fp, "replicas=");
> + fprintpath(fp, ep->e_fslocdata);
> + fprintf(fp, ",");
> break;
> #ifdef DEBUG
> case FSLOC_STUB:
>