]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
build: allow NTLM tests to run on more build configurations
authorU-D5B1PQ1J\Administrador <Administrador@D5B1PQ1J.(none)>
Sat, 7 Aug 2010 12:33:14 +0000 (14:33 +0200)
committerU-D5B1PQ1J\Administrador <Administrador@D5B1PQ1J.(none)>
Sat, 7 Aug 2010 13:03:54 +0000 (15:03 +0200)
lib/curl_gethostname.c
lib/curl_gethostname.h
lib/setup.h
tests/libtest/chkhostname.c
tests/libtest/sethostname.c
tests/runtests.pl

index 5a8c6494b75d867223a6741624890660f22255ce..7f0bfed54912fcf07d0cfc90fafb474ed7a3bbb4 100644 (file)
  ***************************************************************************/
 
 #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
+
 }
index 0e393afe4edb6115c50ad0171be97a970c0c9496..b8ecf88d6ae8b630155f5817432d98c624ad8ef9 100644 (file)
  *
  ***************************************************************************/
 
-#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);
+int Curl_gethostname(char *name, GETHOSTNAME_TYPE_ARG2 namelen);
 
 #endif /* HEADER_CURL_GETHOSTNAME_H */
index 90bb898a3c3ef5a0d9630781ead3777fc4061660..e7dcba1dc5610ad78439ef77b7defcac9a0c2651 100644 (file)
 #  endif
 #endif
 
+/*
+ * Arg 2 type for gethostname in case it hasn't been defined in config file.
+ */
+
+#ifndef GETHOSTNAME_TYPE_ARG2
+#  ifdef USE_WINSOCK
+#    define GETHOSTNAME_TYPE_ARG2 int
+#  else
+#    define GETHOSTNAME_TYPE_ARG2 size_t
+#  endif
+#endif
+
 /* Below we define some functions. They should
 
    4. set the SIGALRM signal timeout
index 686eb471a62ea3a2d55d22a5382feb405a0a60e9..72c8b6a1fe5b1bf81b9bcff5ce8dba821d6f270e 100644 (file)
@@ -1,6 +1,6 @@
-#include "curl_gethostname.h"
+#include "setup.h"
 
-#include <stdio.h>
+#include "curl_gethostname.h"
 
 #define HOSTNAME_MAX 1024
 
index d050f18d65a603b712595fd96b448f38e77e8876..9d9fae00bdc13f8a63a15a6ffb5c1ed96200189b 100644 (file)
@@ -7,25 +7,20 @@
  *
  */
 
-#include <stdlib.h>
-#include <string.h>
-
-#define GETHOSTNAME_ENV_VAR "CURL_GETHOSTNAME"
+#include "setup.h"
 
 /*
  * we force our own host name, in order to make some tests machine independent
- *
- * Since some systems think this prototype doesn't match the system provided
- * function, we AVOID including unistd.h or other headers that may include the
- * original prototype! We provide our own instead (to avoid warnings).
  */
-int gethostname(char *name, size_t namelen);
 
-int gethostname(char *name, size_t namelen)
+int gethostname(char *name, GETHOSTNAME_TYPE_ARG2 namelen);
+
+int gethostname(char *name, GETHOSTNAME_TYPE_ARG2 namelen)
 {
-  const char *force_hostname = getenv(GETHOSTNAME_ENV_VAR);
+  const char *force_hostname = getenv("CURL_GETHOSTNAME");
   if(force_hostname) {
     strncpy(name, force_hostname, namelen);
+    name[namelen-1] = '\0';
     return 0;
   }
 
index 8bb5d69e977fd085a43135876d4a6b6aa0ed7c34..a97d8647e1c0aef853db94573c62109f31c66813 100755 (executable)
@@ -2376,8 +2376,9 @@ sub singletest {
                     delete $ENV{$var} if($ENV{$var});
                 }
                 else {
-                    if(($has_shared ne "yes") && ($var =~ /^LD_PRELOAD/)) {
-                        # print "Skipping LD_PRELOAD due to no shared build\n";
+                    if(($var =~ /^LD_PRELOAD/) &&
+                       ($debug_build || ($has_shared ne "yes"))) {
+                        # print "Skipping LD_PRELOAD due to no release shared build\n";
                         next;
                     }
                     $ENV{$var} = "$content";