]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - utils/mountd/auth.c
2000-08-02 H.J. Lu <hjl@lucon.org>
[nfs-utils.git] / utils / mountd / auth.c
index afa2292888088afdd572661ce9b65d5c6e21f1c0..49567c93158b384a592ebed479a689c733dea593 100644 (file)
@@ -16,6 +16,7 @@
 #include "nfslib.h"
 #include "exportfs.h"
 #include "mountd.h"
+#include "xmalloc.h"
 
 enum auth_error
 {
@@ -77,15 +78,29 @@ auth_authenticate_internal(char *what, struct sockaddr_in *caller,
        }
        auth_fixpath(path);
 
-       if (!(*hpp = gethostbyaddr((const char *)&addr, sizeof(addr), AF_INET)))
-               *hpp = get_hostent((const char *)&addr, sizeof(addr),
-                                  AF_INET);
-       else {
+       /* First try it w/o doing a hostname lookup... */
+       *hpp = get_hostent((const char *)&addr, sizeof(addr), AF_INET);
+       exp = export_find(*hpp, path);
+
+       if (!exp) {
+           /* Ok, that didn't fly.  Try it with a reverse lookup. */
+           free (*hpp);
+           *hpp = gethostbyaddr((const char *)&addr, sizeof(addr),
+                                AF_INET);
+           if (!(*hpp)) {
+               *error = no_entry;
+               return NULL;
+           } else {
                /* must make sure the hostent is authorative. */
                char **sp;
-               struct hostent *forward;
+               struct hostent *forward = NULL;
+               char *tmpname;
 
-               forward = gethostbyname((*hpp)->h_name);
+               tmpname = xstrdup((*hpp)->h_name);
+               if (tmpname) {
+                       forward = gethostbyname(tmpname);
+                       free(tmpname);
+               }
                if (forward) {
                        /* now make sure the "addr" is in the list */
                        for (sp = forward->h_addr_list ; *sp ; sp++) {
@@ -107,12 +122,14 @@ auth_authenticate_internal(char *what, struct sockaddr_in *caller,
                        *hpp = hostent_dup (*hpp);
                        return NULL;
                }
-       }
+           }
 
-       if (!(exp = export_find(*hpp, path))) {
+           if (!(exp = export_find(*hpp, path))) {
                *error = no_entry;
                return NULL;
+           }
        }
+
        if (!exp->m_mayexport) {
                *error = not_exported;
                return NULL;