linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] exportfs.c: escape path for function test_export
@ 2013-12-18 20:06 Tony Asleson
  2013-12-18 20:06 ` [PATCH 2/3] exportfs.c: Remove trailing whitespace Tony Asleson
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Tony Asleson @ 2013-12-18 20:06 UTC (permalink / raw)
  To: linux-nfs

Verbatim patch proposal from J. Bruce Fields except calling
snprintf instead of sprintf.

Tested and appears to work with path names that have a space.

Signed-off-by: Tony Asleson <tasleson@redhat.com>
---
 utils/exportfs/exportfs.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c
index 00667e9..3ca45c1 100644
--- a/utils/exportfs/exportfs.c
+++ b/utils/exportfs/exportfs.c
@@ -444,11 +444,15 @@ static int can_test(void)
 static int test_export(char *path, int with_fsid)
 {
 	char buf[1024];
+	char *bp = buf;
+	int len = sizeof(buf);
 	int fd, n;
 
-	sprintf(buf, "-test-client- %s 3 %d 65534 65534 0\n",
-		path,
-		with_fsid ? NFSEXP_FSID : 0);
+	n = snprintf(buf, len, "-test-client- ");
+	bp += n;
+	len -= n;
+	qword_add(&bp, &len, path);
+	snprintf(bp, len, " 3 %d 65534 65534 0\n", with_fsid ? NFSEXP_FSID : 0);
 	fd = open("/proc/net/rpc/nfsd.export/channel", O_WRONLY);
 	if (fd < 0)
 		return 0;
-- 
1.8.2.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] exportfs.c: Remove trailing whitespace
  2013-12-18 20:06 [PATCH 1/3] exportfs.c: escape path for function test_export Tony Asleson
@ 2013-12-18 20:06 ` Tony Asleson
  2013-12-18 20:06 ` [PATCH 3/3] exportfs.c: Escape path for '-s' option Tony Asleson
  2014-01-07 21:02 ` [PATCH 1/3] exportfs.c: escape path for function test_export Steve Dickson
  2 siblings, 0 replies; 4+ messages in thread
From: Tony Asleson @ 2013-12-18 20:06 UTC (permalink / raw)
  To: linux-nfs

Signed-off-by: Tony Asleson <tasleson@redhat.com>
---
 utils/exportfs/exportfs.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c
index 3ca45c1..019961b 100644
--- a/utils/exportfs/exportfs.c
+++ b/utils/exportfs/exportfs.c
@@ -65,19 +65,19 @@ static int _lockfd = -1;
  *	writes A+B		writes A+C
  *
  * The locking in support/export/xtab.c will prevent mountd from
- * seeing a partially written version of etab, and will prevent 
+ * seeing a partially written version of etab, and will prevent
  * the two writers above from writing simultaneously and
  * corrupting etab, but to prevent problems like the above we
  * need these additional lockfile() routines.
  */
-static void 
+static void
 grab_lockfile()
 {
 	_lockfd = open(lockfile, O_CREAT|O_RDWR, 0666);
-	if (_lockfd != -1) 
+	if (_lockfd != -1)
 		lockf(_lockfd, F_LOCK, 0);
 }
-static void 
+static void
 release_lockfile()
 {
 	if (_lockfd != -1)
@@ -271,7 +271,7 @@ exports_update(int verbose)
 		exports_update_one(exp, verbose);
 	}
 }
-			
+
 /*
  * export_all finds all entries and
  *    marks them xtabent and mayexport so that they get exported
@@ -286,7 +286,7 @@ export_all(int verbose)
 		for (exp = exportlist[i].p_head; exp; exp = exp->m_next) {
 			if (verbose)
 				printf("exporting %s:%s\n",
-				       exp->m_client->m_hostname, 
+				       exp->m_client->m_hostname,
 				       exp->m_export.e_path);
 			exp->m_xtabent = 1;
 			exp->m_mayexport = 1;
@@ -333,7 +333,7 @@ exportfs(char *arg, char *options, int verbose)
 		goto out;
 
 	if (verbose)
-		printf("exporting %s:%s\n", exp->m_client->m_hostname, 
+		printf("exporting %s:%s\n", exp->m_client->m_hostname,
 			exp->m_export.e_path);
 	exp->m_xtabent = 1;
 	exp->m_mayexport = 1;
@@ -391,7 +391,7 @@ unexportfs(char *arg, int verbose)
 			else
 #endif
 				printf("unexporting %s:%s\n",
-					exp->m_client->m_hostname, 
+					exp->m_client->m_hostname,
 					exp->m_export.e_path);
 		}
 #if 0
@@ -402,7 +402,7 @@ unexportfs(char *arg, int verbose)
 		exp->m_mayexport = 0;
 		success = 1;
 	}
-	if (!success) 
+	if (!success)
 		xlog(L_ERROR, "Could not find '%s:%s' to unexport.", arg, path);
 
 	freeaddrinfo(ai);
@@ -421,7 +421,7 @@ static int can_test(void)
 	/*
 	 * We introduce tolerance of 1 day to ensure that we use a
 	 * LONG_MAX for the expiry timestamp before it is actually
-	 * needed. To use LONG_MAX, the kernel code must have 
+	 * needed. To use LONG_MAX, the kernel code must have
 	 * commit 2f74f972  (sunrpc: prepare NFS for 2038).
 	 */
 	if (time(NULL) > INT_TO_LONG_THRESHOLD_SECS)
@@ -620,7 +620,7 @@ export_d_read(const char *dname)
 		int fname_len;
 
 
-		if (d->d_type != DT_UNKNOWN 
+		if (d->d_type != DT_UNKNOWN
 		    && d->d_type != DT_REG
 		    && d->d_type != DT_LNK)
 			continue;
@@ -629,7 +629,7 @@ export_d_read(const char *dname)
 
 #define _EXT_EXPORT_SIZ   (sizeof(_EXT_EXPORT) - 1)
 		namesz = strlen(d->d_name);
-		if (!namesz 
+		if (!namesz
 		    || namesz < _EXT_EXPORT_SIZ + 1
 		    || strcmp(d->d_name + (namesz - _EXT_EXPORT_SIZ),
 			      _EXT_EXPORT))
@@ -643,7 +643,7 @@ export_d_read(const char *dname)
 
 		export_read(fname);
 	}
-		
+
 	for (i = 0; i < n; i++)
 		free(namelist[i]);
 	free(namelist);
@@ -721,8 +721,8 @@ dump(int verbose, int export_format)
 			if (ep->e_uuid)
 				c = dumpopt(c, "fsid=%s", ep->e_uuid);
 			if (ep->e_mountpoint)
-				c = dumpopt(c, "mountpoint%s%s", 
-					    ep->e_mountpoint[0]?"=":"", 
+				c = dumpopt(c, "mountpoint%s%s",
+					    ep->e_mountpoint[0]?"=":"",
 					    ep->e_mountpoint);
 			if (ep->e_anonuid != 65534)
 				c = dumpopt(c, "anonuid=%d", ep->e_anonuid);
-- 
1.8.2.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] exportfs.c: Escape path for '-s' option
  2013-12-18 20:06 [PATCH 1/3] exportfs.c: escape path for function test_export Tony Asleson
  2013-12-18 20:06 ` [PATCH 2/3] exportfs.c: Remove trailing whitespace Tony Asleson
@ 2013-12-18 20:06 ` Tony Asleson
  2014-01-07 21:02 ` [PATCH 1/3] exportfs.c: escape path for function test_export Steve Dickson
  2 siblings, 0 replies; 4+ messages in thread
From: Tony Asleson @ 2013-12-18 20:06 UTC (permalink / raw)
  To: linux-nfs

When outputing the paths and the user has specified the option
-s, escape the path.

Signed-off-by: Tony Asleson <tasleson@redhat.com>
---
 utils/exportfs/exportfs.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c
index 019961b..9ea86cb 100644
--- a/utils/exportfs/exportfs.c
+++ b/utils/exportfs/exportfs.c
@@ -666,6 +666,9 @@ dumpopt(char c, char *fmt, ...)
 static void
 dump(int verbose, int export_format)
 {
+	char buf[1024];
+	char *bp;
+	int len;
 	nfs_export	*exp;
 	struct exportent *ep;
 	int		htype;
@@ -683,7 +686,15 @@ dump(int verbose, int export_format)
 			if (strlen(ep->e_path) > 14 && !export_format)
 				printf("%-14s\n\t\t%s", ep->e_path, hname);
 			else
-				printf(((export_format)? "%s %s" : "%-14s\t%s"), ep->e_path, hname);
+				if (export_format) {
+					bp = buf;
+					len = sizeof(buf) - 1;
+					qword_add(&bp, &len, ep->e_path);
+					*bp = '\0';
+					printf("%s %s", buf, hname);
+				} else {
+					printf("%-14s\t%s", ep->e_path, hname);
+				}
 
 			if (!verbose && !export_format) {
 				printf("\n");
-- 
1.8.2.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/3] exportfs.c: escape path for function test_export
  2013-12-18 20:06 [PATCH 1/3] exportfs.c: escape path for function test_export Tony Asleson
  2013-12-18 20:06 ` [PATCH 2/3] exportfs.c: Remove trailing whitespace Tony Asleson
  2013-12-18 20:06 ` [PATCH 3/3] exportfs.c: Escape path for '-s' option Tony Asleson
@ 2014-01-07 21:02 ` Steve Dickson
  2 siblings, 0 replies; 4+ messages in thread
From: Steve Dickson @ 2014-01-07 21:02 UTC (permalink / raw)
  To: Tony Asleson, linux-nfs



On 18/12/13 15:06, Tony Asleson wrote:
> Verbatim patch proposal from J. Bruce Fields except calling
> snprintf instead of sprintf.
> 
> Tested and appears to work with path names that have a space.
> 
> Signed-off-by: Tony Asleson <tasleson@redhat.com>
All three committed...

steved.

> ---
>  utils/exportfs/exportfs.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c
> index 00667e9..3ca45c1 100644
> --- a/utils/exportfs/exportfs.c
> +++ b/utils/exportfs/exportfs.c
> @@ -444,11 +444,15 @@ static int can_test(void)
>  static int test_export(char *path, int with_fsid)
>  {
>  	char buf[1024];
> +	char *bp = buf;
> +	int len = sizeof(buf);
>  	int fd, n;
>  
> -	sprintf(buf, "-test-client- %s 3 %d 65534 65534 0\n",
> -		path,
> -		with_fsid ? NFSEXP_FSID : 0);
> +	n = snprintf(buf, len, "-test-client- ");
> +	bp += n;
> +	len -= n;
> +	qword_add(&bp, &len, path);
> +	snprintf(bp, len, " 3 %d 65534 65534 0\n", with_fsid ? NFSEXP_FSID : 0);
>  	fd = open("/proc/net/rpc/nfsd.export/channel", O_WRONLY);
>  	if (fd < 0)
>  		return 0;
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-01-07 21:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-18 20:06 [PATCH 1/3] exportfs.c: escape path for function test_export Tony Asleson
2013-12-18 20:06 ` [PATCH 2/3] exportfs.c: Remove trailing whitespace Tony Asleson
2013-12-18 20:06 ` [PATCH 3/3] exportfs.c: Escape path for '-s' option Tony Asleson
2014-01-07 21:02 ` [PATCH 1/3] exportfs.c: escape path for function test_export Steve Dickson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).