summaryrefslogtreecommitdiff
path: root/lib/curl_gethostname.c
diff options
context:
space:
mode:
authorU-D5B1PQ1J\Administrador <Administrador@D5B1PQ1J.(none)>2010-08-07 14:33:14 +0200
committerU-D5B1PQ1J\Administrador <Administrador@D5B1PQ1J.(none)>2010-08-07 15:03:54 +0200
commit7d342c723c5ae8e9312210936287810741f40bc5 (patch)
treea9870c912e8a2dbfd8bdc8aa223057b0f02822a4 /lib/curl_gethostname.c
parent5c2b6b2d3e60500bb6b47b57cfe4e65c2ba03751 (diff)
downloadcurl-7d342c723c5ae8e9312210936287810741f40bc5.tar.gz
build: allow NTLM tests to run on more build configurations
Diffstat (limited to 'lib/curl_gethostname.c')
-rw-r--r--lib/curl_gethostname.c61
1 files changed, 45 insertions, 16 deletions
diff --git a/lib/curl_gethostname.c b/lib/curl_gethostname.c
index 5a8c6494b..7f0bfed54 100644
--- a/lib/curl_gethostname.c
+++ b/lib/curl_gethostname.c
@@ -21,32 +21,61 @@
***************************************************************************/
#include "setup.h"
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
#include "curl_gethostname.h"
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
+/*
+ * Curl_gethostname() is a wrapper around gethostname() which allows
+ * overriding the host name that the function would normally return.
+ * This capability is used by the test suite to verify exact matching
+ * of NTLM authentication, which exercises libcurl's MD4 and DES code.
+ *
+ * For libcurl debug enabled builds host name overriding takes place
+ * when environment variable CURL_GETHOSTNAME is set, using the value
+ * held by the variable to override returned host name.
+ *
+ * For libcurl shared library release builds the test suite preloads
+ * another shared library named libhostname using the LD_PRELOAD
+ * mechanism which intercepts, and might override, the gethostname()
+ * function call. In this case a given platform must support the
+ * LD_PRELOAD mechanism and additionally have environment variable
+ * CURL_GETHOSTNAME set in order to override the returned host name.
+ *
+ * For libcurl static library release builds no overriding takes place.
+ */
-#define GETHOSTNAME_ENV_VAR "CURL_GETHOSTNAME"
+int Curl_gethostname(char *name, GETHOSTNAME_TYPE_ARG2 namelen) {
-int Curl_gethostname(char *name, size_t namelen) {
-#ifdef HAVE_GETHOSTNAME
+#ifndef HAVE_GETHOSTNAME
-#ifdef CURLDEBUG
- /* we check the environment variable only in case of debug build */
- const char *force_hostname = getenv(GETHOSTNAME_ENV_VAR);
+ /* Allow compilation and return failure when unavailable */
+ (void) name;
+ (void) namelen;
+ return -1;
+
+#else
+
+#ifdef DEBUGBUILD
+
+ /* Override host name when environment variable CURL_GETHOSTNAME is set */
+ const char *force_hostname = getenv("CURL_GETHOSTNAME");
if(force_hostname) {
strncpy(name, force_hostname, namelen);
+ name[namelen-1] = '\0';
return 0;
}
-#endif
- /* no override requested */
+
+#endif /* DEBUGBUILD */
+
+ /* The call to system's gethostname() might get intercepted by the
+ libhostname library when libcurl is built as a non-debug shared
+ library when running the test suite. */
return gethostname(name, namelen);
-#else
- /* no gethostname() available on system, we should always fail */
- (void) name;
- (void) namelen;
- return -1;
#endif
+
}