[PATCH] Curl_gethostname() may or may not return the hostname as a FQDN
Date: Wed, 10 Aug 2011 17:32:56 +0100
During my work of adding AUTH NTLM to the SMTP module I noticed that the
FQDN of the local machine is not necessarily being sent in the HELO and EHLO
commands as it should. After debugging I realised that Curl_gethostname()
was simply returning the local machine's name and not it's FQDN.
As you are probably aware Curl_gethostname() is a simple wrapper for
gethostname() to allow it to be overridden by the test harnesses, but
according to the MSDN documentation:
"The gethostname function returns the name of the local host into the buffer
specified by the name parameter. The host name is returned as a
null-terminated string. The form of the host name is dependent on the
Windows Sockets provider-it can be a simple host name, or it can be a fully
qualified domain name."
It would seem that the returned value is Socket provider dependent, and as
such, we are not guaranteed to receive the FQDN. Unfortunately, some email
servers will return the following error if this is the case:
504 5.5.2 <hostname>: Helo command rejected: need fully-qualified hostname
In addition to this, I also noticed that whilst reworking the NTLM code, in
http_ntlm.c, it will strip off the domain name if that has been returned
from Curl_gethostname() - this also tells me that this function should be
returning the FQDN.
Given the above, I would like to propose a fix to Curl_gethostname():
After calling gethostname(), check to see if the returned string contains a
"." separator and if it doesn't then perform an additional query to
getaddrinfo(). I would have suggested a call to gethostbyname() but this is
deprecated in Windows and, from what I have read online, from the current
version of the POSIX specification due to problems with IPV6.
Should this be a satisfactory solution, then I have attached the necessary
Received on 2011-08-10