X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=utils%2Fmountd%2Fauth.c;h=6b6b7d74cf4fb1afe788b5055e303dde627f54a8;hb=75cbc5abeb4b1d39abf298be217783c2b0889ae5;hp=98c3944767767744091db7954824643b6a73d1bc;hpb=08f6b0ea56f96eac00b092c7d5e1f6486eb6f457;p=nfs-utils.git diff --git a/utils/mountd/auth.c b/utils/mountd/auth.c index 98c3944..6b6b7d7 100644 --- a/utils/mountd/auth.c +++ b/utils/mountd/auth.c @@ -78,15 +78,26 @@ 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; + *hpp = get_hostent((const char *)&addr, sizeof(addr), AF_INET); + return NULL; + } else { /* must make sure the hostent is authorative. */ char **sp; struct hostent *forward = NULL; char *tmpname; + *hpp = hostent_dup (*hpp); tmpname = xstrdup((*hpp)->h_name); if (tmpname) { forward = gethostbyname(tmpname); @@ -102,23 +113,24 @@ 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; } - } + } - 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; @@ -146,7 +158,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';