libshare: nfs: pass through ipv6 addresses in bracket notation

Recognize when the host part of a sharenfs attribute is an ipv6
Literal and pass that through without modification.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Felix Dörre <felix@dogcraft.de>
Closes: #11171
Closes #11939
Closes: #1894
This commit is contained in:
felixdoerre
2021-10-20 19:40:00 +02:00
committed by Brian Behlendorf
parent ae75a78ba3
commit 9e41d5d05c
6 changed files with 126 additions and 8 deletions
+42 -5
View File
@@ -180,8 +180,9 @@ foreach_nfs_host_cb(const char *opt, const char *value, void *pcookie)
{
int error;
const char *access;
char *host_dup, *host, *next;
char *host_dup, *host, *next, *v6Literal;
nfs_host_cookie_t *udata = (nfs_host_cookie_t *)pcookie;
int cidr_len;
#ifdef DEBUG
fprintf(stderr, "foreach_nfs_host_cb: key=%s, value=%s\n", opt, value);
@@ -204,10 +205,46 @@ foreach_nfs_host_cb(const char *opt, const char *value, void *pcookie)
host = host_dup;
do {
next = strchr(host, ':');
if (next != NULL) {
*next = '\0';
next++;
if (*host == '[') {
host++;
v6Literal = strchr(host, ']');
if (v6Literal == NULL) {
free(host_dup);
return (SA_SYNTAX_ERR);
}
if (v6Literal[1] == '\0') {
*v6Literal = '\0';
next = NULL;
} else if (v6Literal[1] == '/') {
next = strchr(v6Literal + 2, ':');
if (next == NULL) {
cidr_len =
strlen(v6Literal + 1);
memmove(v6Literal,
v6Literal + 1,
cidr_len);
v6Literal[cidr_len] = '\0';
} else {
cidr_len = next - v6Literal - 1;
memmove(v6Literal,
v6Literal + 1,
cidr_len);
v6Literal[cidr_len] = '\0';
next++;
}
} else if (v6Literal[1] == ':') {
*v6Literal = '\0';
next = v6Literal + 2;
} else {
free(host_dup);
return (SA_SYNTAX_ERR);
}
} else {
next = strchr(host, ':');
if (next != NULL) {
*next = '\0';
next++;
}
}
error = udata->callback(udata->filename,