aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.inc4
-rw-r--r--lib/curl_gethostname.c52
-rw-r--r--lib/curl_gethostname.h34
-rw-r--r--lib/http_ntlm.c3
-rw-r--r--lib/smtp.c7
5 files changed, 93 insertions, 7 deletions
diff --git a/lib/Makefile.inc b/lib/Makefile.inc
index 17e2d36e7..bfd3abedc 100644
--- a/lib/Makefile.inc
+++ b/lib/Makefile.inc
@@ -20,7 +20,7 @@ CSOURCES = file.c timeval.c base64.c hostip.c progress.c formdata.c \
strdup.c socks.c ssh.c nss.c qssl.c rawstr.c curl_addrinfo.c \
socks_gssapi.c socks_sspi.c curl_sspi.c slist.c nonblock.c \
curl_memrchr.c imap.c pop3.c smtp.c pingpong.c rtsp.c curl_threads.c \
- warnless.c hmac.c polarssl.c curl_rtmp.c openldap.c
+ warnless.c hmac.c polarssl.c curl_rtmp.c openldap.c curl_gethostname.c
HHEADERS = arpa_telnet.h netrc.h file.h timeval.h qssl.h hostip.h \
progress.h formdata.h cookie.h http.h sendf.h ftp.h url.h dict.h \
@@ -34,5 +34,5 @@ HHEADERS = arpa_telnet.h netrc.h file.h timeval.h qssl.h hostip.h \
tftp.h sockaddr.h splay.h strdup.h setup_once.h socks.h ssh.h nssg.h \
curl_base64.h rawstr.h curl_addrinfo.h curl_sspi.h slist.h nonblock.h \
curl_memrchr.h imap.h pop3.h smtp.h pingpong.h rtsp.h curl_threads.h \
- warnless.h curl_hmac.h polarssl.h curl_rtmp.h
+ warnless.h curl_hmac.h polarssl.h curl_rtmp.h curl_gethostname.h
diff --git a/lib/curl_gethostname.c b/lib/curl_gethostname.c
new file mode 100644
index 000000000..5a8c6494b
--- /dev/null
+++ b/lib/curl_gethostname.c
@@ -0,0 +1,52 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+
+#include "setup.h"
+#include "curl_gethostname.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#define GETHOSTNAME_ENV_VAR "CURL_GETHOSTNAME"
+
+int Curl_gethostname(char *name, size_t namelen) {
+#ifdef HAVE_GETHOSTNAME
+
+#ifdef CURLDEBUG
+ /* we check the environment variable only in case of debug build */
+ const char *force_hostname = getenv(GETHOSTNAME_ENV_VAR);
+ if(force_hostname) {
+ strncpy(name, force_hostname, namelen);
+ return 0;
+ }
+#endif
+ /* no override requested */
+ return gethostname(name, namelen);
+
+#else
+ /* no gethostname() available on system, we should always fail */
+ (void) name;
+ (void) namelen;
+ return -1;
+#endif
+}
diff --git a/lib/curl_gethostname.h b/lib/curl_gethostname.h
new file mode 100644
index 000000000..0e393afe4
--- /dev/null
+++ b/lib/curl_gethostname.h
@@ -0,0 +1,34 @@
+#ifndef HEADER_CURL_GETHOSTNAME_H
+#define HEADER_CURL_GETHOSTNAME_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+
+#include "setup.h"
+
+/* wrapper around gethostname(), which makes it possible to override the
+ * returned value during testing. It reads the value of CURL_GETHOSTNAME
+ * environment variable when built with --enable-curldebug. The function always
+ * returns -1, if gethostname() is not available on system.
+ */
+int Curl_gethostname(char *name, size_t namelen);
+
+#endif /* HEADER_CURL_GETHOSTNAME_H */
diff --git a/lib/http_ntlm.c b/lib/http_ntlm.c
index 0e831ca33..f5b696a69 100644
--- a/lib/http_ntlm.c
+++ b/lib/http_ntlm.c
@@ -58,6 +58,7 @@
#include "curl_base64.h"
#include "http_ntlm.h"
#include "url.h"
+#include "curl_gethostname.h"
#include "curl_memory.h"
#define _MPRINTF_REPLACE /* use our functions only */
@@ -994,7 +995,7 @@ CURLcode Curl_output_ntlm(struct connectdata *conn,
user = userp;
userlen = strlen(user);
- if(gethostname(host, HOSTNAME_MAX)) {
+ if(Curl_gethostname(host, HOSTNAME_MAX)) {
infof(conn->data, "gethostname() failed, continuing without!");
hostlen = 0;
}
diff --git a/lib/smtp.c b/lib/smtp.c
index edc3ff659..1133fe527 100644
--- a/lib/smtp.c
+++ b/lib/smtp.c
@@ -91,6 +91,7 @@
#include "curl_base64.h"
#include "curl_md5.h"
#include "curl_hmac.h"
+#include "curl_gethostname.h"
#define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h>
@@ -1110,12 +1111,10 @@ static CURLcode smtp_connect(struct connectdata *conn,
pp->conn = conn;
if(!*path) {
-#ifdef HAVE_GETHOSTNAME
- if(!gethostname(localhost, sizeof localhost))
+ if(!Curl_gethostname(localhost, sizeof localhost))
path = localhost;
else
-#endif
- path = "localhost";
+ path = "localhost";
}
/* url decode the path and use it as domain with EHLO */