]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - utils/mountd/cache.c
mountd: add trivial helpers for client-matching
[nfs-utils.git] / utils / mountd / cache.c
index 0af640441b9b86eab0f0dd023f8ed985b4b4d410..be5198e84c830a8df418fc2e081a1a127e90af55 100644 (file)
@@ -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,18 +597,8 @@ 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);
@@ -750,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)
 {
@@ -1071,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;
        }