diff mbox series

mountd: Preserve special characters in refer and replica path options

Message ID 20200416213722.80201-1-trondmy@kernel.org
State New, archived
Headers show
Series mountd: Preserve special characters in refer and replica path options | expand

Commit Message

trondmy@kernel.org April 16, 2020, 9:37 p.m. UTC
From: Lance Shelton <lance.shelton@hammerspace.com>

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

Signed-off-by: Lance Shelton <lance.shelton@hammerspace.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
---
 support/nfs/exports.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

Comments

Steve Dickson May 8, 2020, 2:11 p.m. UTC | #1
On 4/16/20 5:37 PM, trondmy@kernel.org wrote:
> From: Lance Shelton <lance.shelton@hammerspace.com>
> 
> Allow referral paths to contain special character by adding an
> escaping mechanism.
> 
> Signed-off-by: Lance Shelton <lance.shelton@hammerspace.com>
> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
> ---
>  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:
>
diff mbox series

Patch

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: