]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - utils/mountd/auth.c
* utils/mountd/auth.c (auth_authenticate_internal): Reverse
[nfs-utils.git] / utils / mountd / auth.c
index afa2292888088afdd572661ce9b65d5c6e21f1c0..d88c46f31b52563827aac1aedfe5703e7fbc182f 100644 (file)
@@ -16,6 +16,7 @@
 #include "nfslib.h"
 #include "exportfs.h"
 #include "mountd.h"
+#include "xmalloc.h"
 
 enum auth_error
 {
@@ -83,9 +84,15 @@ auth_authenticate_internal(char *what, struct sockaddr_in *caller,
        else {
                /* must make sure the hostent is authorative. */
                char **sp;
-               struct hostent *forward;
-
-               forward = gethostbyname((*hpp)->h_name);
+               struct hostent *forward = NULL;
+               char *tmpname;
+
+               *hpp = hostent_dup (*hpp);
+               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++) {
@@ -96,15 +103,14 @@ auth_authenticate_internal(char *what, struct sockaddr_in *caller,
                        if (!*sp) {
                                /* it was a FAKE */
                                *error = faked_hostent;
-                               *hpp = hostent_dup (*hpp);
                                return NULL;
                        }
+                       free (*hpp);
                        *hpp = hostent_dup (forward);
                }
                else {
                        /* never heard of it. misconfigured DNS? */
                        *error = no_forward_dns;
-                       *hpp = hostent_dup (*hpp);
                        return NULL;
                }
        }
@@ -140,7 +146,11 @@ auth_authenticate(char *what, struct sockaddr_in *caller, char *path)
        struct in_addr  addr = caller->sin_addr;
        enum auth_error error;
 
-       if (path [0] != '/') return exp;
+       if (path [0] != '/') {
+               xlog(L_WARNING, "bad path in %s request from %s: \"%s\"",
+                    what, inet_ntoa(addr), path);
+               return exp;
+       }
 
        strncpy(epath, path, sizeof (epath) - 1);
        epath[sizeof (epath) - 1] = '\0';