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