fb1f190
From b8ab76ad19e3c284ac14bd0450662bfc41719e03 Mon Sep 17 00:00:00 2001
fb1f190
From: Jan Kara <jack@suse.cz>
fb1f190
Date: Wed, 16 Feb 2011 22:19:55 +0100
fb1f190
Subject: [PATCH 2/2] Make RPC handle properly host names with colons
fb1f190
fb1f190
NFS handles server names with colons (usually IPv6 addresses) by encapsulating
fb1f190
them in brackets. Handle this properly.
fb1f190
fb1f190
Signed-off-by: Jan Kara <jack@suse.cz>
fb1f190
---
fb1f190
 rquota_client.c |   48 +++++++++++++++++++++++++++++++++---------------
fb1f190
 1 files changed, 33 insertions(+), 15 deletions(-)
fb1f190
fb1f190
diff --git a/rquota_client.c b/rquota_client.c
fb1f190
index cc1d623..53e0579 100644
fb1f190
--- a/rquota_client.c
fb1f190
+++ b/rquota_client.c
fb1f190
@@ -104,6 +104,35 @@ int rquota_err(int stat)
fb1f190
 	}
fb1f190
 }
fb1f190
 
fb1f190
+static int split_nfs_mount(char *devname, char **host, char **path)
fb1f190
+{
fb1f190
+	char *pathname;
fb1f190
+
fb1f190
+	/* NFS server name contained in brackets? */
fb1f190
+	if (*devname == '[') {
fb1f190
+		*host = devname + 1;
fb1f190
+		pathname = strchr(devname, ']');
fb1f190
+		if (!pathname || pathname[1] != ':')
fb1f190
+			return 0;
fb1f190
+		/* Autofs? */
fb1f190
+		if (pathname[2] == '(')
fb1f190
+			return 0;
fb1f190
+		*pathname = 0;
fb1f190
+		*path = pathname + 2;
fb1f190
+		return 1;
fb1f190
+	}
fb1f190
+	*host = devname;
fb1f190
+	pathname = strchr(devname, ':');
fb1f190
+	if (!pathname)
fb1f190
+		return 0;
fb1f190
+	/* Autofs? */
fb1f190
+	if (pathname[1] == '(')
fb1f190
+		return 0;
fb1f190
+	*pathname = 0;
fb1f190
+	*path = pathname + 1;
fb1f190
+	return 1;
fb1f190
+}
fb1f190
+
fb1f190
 /*
fb1f190
  * Collect the requested quota information from a remote host.
fb1f190
  */
fb1f190
@@ -128,13 +157,7 @@ int rpc_rquota_get(struct dquot *dquot)
fb1f190
 	 */
fb1f190
 	fsname_tmp = (char *)smalloc(strlen(dquot->dq_h->qh_quotadev) + 1);
fb1f190
 	strcpy(fsname_tmp, dquot->dq_h->qh_quotadev);
fb1f190
-	host = fsname_tmp;
fb1f190
-
fb1f190
-	/*
fb1f190
-	 * Strip off pathname on nfs mounted dir. Ignore entries of any
fb1f190
-	 * automounter.
fb1f190
-	 */
fb1f190
-	if ((pathname = strchr(fsname_tmp, ':')) == (char *)0 || *(pathname + 1) == '(') {
fb1f190
+	if (!split_nfs_mount(fsname_tmp, &host, &pathname)) {
fb1f190
 		free(fsname_tmp);
fb1f190
 		return -ENOENT;
fb1f190
 	}
fb1f190
@@ -247,16 +270,11 @@ int rpc_rquota_set(int qcmd, struct dquot *dquot)
fb1f190
 	 */
fb1f190
 	fsname_tmp = (char *)smalloc(strlen(dquot->dq_h->qh_quotadev) + 1);
fb1f190
 	strcpy(fsname_tmp, dquot->dq_h->qh_quotadev);
fb1f190
-	host = fsname_tmp;
fb1f190
-
fb1f190
-	/*
fb1f190
-	 * Strip off pathname on nfs mounted dir. Ignore entries of any
fb1f190
-	 * automounter.
fb1f190
-	 */
fb1f190
-	if ((pathname = strchr(fsname_tmp, ':')) == (char *)0 || *(pathname + 1) == '(')
fb1f190
+	if (!split_nfs_mount(fsname_tmp, &host, &pathname)) {
fb1f190
+		free(fsname_tmp);
fb1f190
 		return -ENOENT;
fb1f190
+	}
fb1f190
 
fb1f190
-	*pathname++ = '\0';
fb1f190
 	/* For NFSv4, we send the filesystem path without initial /. Server prepends proper
fb1f190
 	 * NFS pseudoroot automatically and uses this for detection of NFSv4 mounts. */
fb1f190
 	if ((dquot->dq_h->qh_io_flags & IOFL_NFS_MIXED_PATHS) &&
fb1f190
-- 
fb1f190
1.7.4
fb1f190