mirror of
https://github.com/curl/curl.git
synced 2026-08-24 15:53:32 +03:00
NTLM tests: boost coverage by forcing the hostname
A shared library tests/libtest/.libs/lihostname.so is preloaded in NTLM test-cases to override the system implementation of gethostname(). It makes it possible to test the NTLM authentication for exact match, and this way test the implementation of MD4 and DES. If LD_PRELOAD doesn't work, a debug build willl also workk as debug builds are now made to prefer a specific environment variable and will then return that content as host name instead of the actual one. Kamil wrote the bulk of this, Daniel Stenberg polished it.
This commit is contained in:
parent
01c309e186
commit
b5c3feda17
36 changed files with 481 additions and 176 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
52
lib/curl_gethostname.c
Normal file
52
lib/curl_gethostname.c
Normal file
|
|
@ -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
|
||||
}
|
||||
34
lib/curl_gethostname.h
Normal file
34
lib/curl_gethostname.h
Normal file
|
|
@ -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 */
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue