X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=utils%2Fmountd%2Fcache.c;h=be5198e84c830a8df418fc2e081a1a127e90af55;hp=ac9cdbd2e0ed30fedcd03a368e1f79797cda3f35;hb=236025253c6ec534cd816390464435ec18c499f7;hpb=ab74900ff59ef54e2ef7e2523b2f6f1ea8e695c8 diff --git a/utils/mountd/cache.c b/utils/mountd/cache.c index ac9cdbd..be5198e 100644 --- a/utils/mountd/cache.c +++ b/utils/mountd/cache.c @@ -495,6 +495,19 @@ static bool match_fsid(struct parsed_fsid *parsed, nfs_export *exp, char *path) return false; } +struct addrinfo *lookup_client_addr(char *dom) +{ + struct addrinfo *ret; + struct addrinfo *tmp; + + tmp = host_pton(dom); + if (tmp == NULL) + return NULL; + ret = client_resolve(tmp->ai_addr); + freeaddrinfo(tmp); + return ret; +} + static void nfsd_fh(FILE *f) { /* request are: @@ -538,6 +551,12 @@ static void nfsd_fh(FILE *f) auth_reload(); + if (use_ipaddr) { + ai = lookup_client_addr(dom); + if (!ai) + goto out; + } + /* Now determine export point for this fsid/domain */ for (i=0 ; i < MCL_MAXTYPES; i++) { nfs_export *next_exp; @@ -568,7 +587,7 @@ static void nfsd_fh(FILE *f) next_exp = exp->m_next; } - if (!use_ipaddr && !client_member(dom, exp->m_client->m_hostname)) + if (!use_ipaddr && !namelist_client_matches(exp, dom)) continue; if (exp->m_export.e_mountpoint && !is_mountpoint(exp->m_export.e_mountpoint[0]? @@ -578,29 +597,28 @@ static void nfsd_fh(FILE *f) if (!match_fsid(&parsed, exp, path)) continue; - if (use_ipaddr) { - if (ai == NULL) { - struct addrinfo *tmp; - tmp = host_pton(dom); - if (tmp == NULL) - goto out; - ai = client_resolve(tmp->ai_addr); - freeaddrinfo(tmp); - } - if (!client_check(exp->m_client, ai)) - continue; - } + if (use_ipaddr && !ipaddr_client_matches(exp, ai)) + continue; if (!found || subexport(&exp->m_export, found)) { found = &exp->m_export; free(found_path); found_path = strdup(path); if (found_path == NULL) goto out; - } else if (strcmp(found->e_path, exp->m_export.e_path) + } else if (strcmp(found->e_path, exp->m_export.e_path) != 0 && !subexport(found, &exp->m_export)) { xlog(L_WARNING, "%s and %s have same filehandle for %s, using first", found_path, path, dom); + } else { + /* same path, if one is V4ROOT, choose the other */ + if (found->e_flags & NFSEXP_V4ROOT) { + found = &exp->m_export; + free(found_path); + found_path = strdup(path); + if (found_path == NULL) + goto out; + } } } } @@ -741,14 +759,6 @@ static int path_matches(nfs_export *exp, char *path) return strcmp(path, exp->m_export.e_path) == 0; } -static int -client_matches(nfs_export *exp, char *dom, struct addrinfo *ai) -{ - if (use_ipaddr) - return client_check(exp->m_client, ai); - return client_member(dom, exp->m_client->m_hostname); -} - static int export_matches(nfs_export *exp, char *dom, char *path, struct addrinfo *ai) { @@ -772,10 +782,14 @@ lookup_export(char *dom, char *path, struct addrinfo *ai) found_type = i; continue; } - - /* Always prefer non-V4ROOT mounts */ - if (found->m_export.e_flags & NFSEXP_V4ROOT) + /* Always prefer non-V4ROOT exports */ + if (exp->m_export.e_flags & NFSEXP_V4ROOT) + continue; + if (found->m_export.e_flags & NFSEXP_V4ROOT) { + found = exp; + found_type = i; continue; + } /* If one is a CROSSMOUNT, then prefer the longest path */ if (((found->m_export.e_flags & NFSEXP_CROSSMOUNT) || @@ -1058,12 +1072,8 @@ static void nfsd_export(FILE *f) auth_reload(); if (use_ipaddr) { - struct addrinfo *tmp; - tmp = host_pton(dom); - if (tmp == NULL) - goto out; - ai = client_resolve(tmp->ai_addr); - freeaddrinfo(tmp); + ai = lookup_client_addr(dom); + if (!ai) goto out; }