tests: delete libhostname.so and chkhostname

Before this patch, `libhostname.so` and `chkhostname` were a test
facility for overriding `gethostname()` in non-debug builds on
Linux and other Unix platforms supporting `LD_PRELOAD`.

`gethostname()` has a single use with SMTP.

The alternative way to override `gethostname()` is building in debug
mode, which allows to do this via the `CURL_GETHOSTNAME` env, on all
platforms.

Drop the `LD_PRELOAD` solution in favour of the above.

Also:
- delete inactive NTLM code with a `gethostname()` call made from it.
- streamline NTLM code by dropping a `printf()` and a macro.
- tests: stop setting `CURL_GETHOSTNAME` where unnecessary.

Closes #14695
This commit is contained in:
Viktor Szakats 2024-08-26 14:26:29 +02:00
parent 59b419f1a5
commit 09437d8cd4
No known key found for this signature in database
GPG Key ID: B5ABD165E2AEF201
23 changed files with 5 additions and 307 deletions

View File

@ -4064,14 +4064,6 @@ AM_CONDITIONAL(USE_MANUAL, test x"$USE_MANUAL" = x1)
CURL_CHECK_LIB_ARES
if test "x$curl_cv_native_windows" != "xyes" &&
test "x$enable_shared" = "xyes"; then
build_libhostname=yes
else
build_libhostname=no
fi
AM_CONDITIONAL(BUILD_LIBHOSTNAME, test x$build_libhostname = xyes)
if test "x$want_ares" != xyes; then
CURL_CHECK_OPTION_THREADED_RESOLVER

View File

@ -39,15 +39,6 @@
*
* Note: The function always returns the un-qualified hostname rather
* than being provider dependent.
*
* 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 hostname.
*
* For libcurl static library release builds no overriding takes place.
*/
int Curl_gethostname(char * const name, GETHOSTNAME_TYPE_ARG2 namelen)
@ -78,9 +69,6 @@ int Curl_gethostname(char * const name, GETHOSTNAME_TYPE_ARG2 namelen)
#else /* 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. */
name[0] = '\0';
err = gethostname(name, namelen);

View File

@ -59,10 +59,6 @@
/* "NTLMSSP" signature is always in ASCII regardless of the platform */
#define NTLMSSP_SIGNATURE "\x4e\x54\x4c\x4d\x53\x53\x50"
/* The fixed hostname we provide, in order to not leak our real local host
name. Copy the name used by Firefox. */
#define NTLM_HOSTNAME "WORKSTATION"
#if DEBUG_ME
# define DEBUG_OUT(x) x
static void ntlm_print_flags(FILE *handle, unsigned long flags)
@ -490,7 +486,9 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data,
unsigned char *ptr_ntresp = &ntresp[0];
unsigned char *ntlmv2resp = NULL;
bool unicode = (ntlm->flags & NTLMFLAG_NEGOTIATE_UNICODE) ? TRUE : FALSE;
char host[HOSTNAME_MAX + 1] = "";
/* The fixed hostname we provide, in order to not leak our real local host
name. Copy the name used by Firefox. */
static const char host[] = "WORKSTATION";
const char *user;
const char *domain = "";
size_t hostoff = 0;
@ -515,21 +513,7 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data,
user = userp;
userlen = strlen(user);
#ifndef NTLM_HOSTNAME
/* Get the machine's un-qualified hostname as NTLM does not like the fully
qualified domain name */
if(Curl_gethostname(host, sizeof(host))) {
infof(data, "gethostname() failed, continuing without");
hostlen = 0;
}
else {
hostlen = strlen(host);
}
#else
(void)msnprintf(host, sizeof(host), "%s", NTLM_HOSTNAME);
hostlen = sizeof(NTLM_HOSTNAME)-1;
#endif
hostlen = sizeof(host) - 1;
if(ntlm->flags & NTLMFLAG_NEGOTIATE_NTLM2_KEY) {
unsigned char ntbuffer[0x18];

View File

@ -139,13 +139,6 @@ build_all_programs()
cd libtest || exit 1
get_make_vars Makefile.inc
# Special case: redefine chkhostname compilation parameters.
# shellcheck disable=SC2034
chkhostname_SOURCES=chkhostname.c
# shellcheck disable=SC2034
chkhostname_LDADD=curl_gethostname.o
# shellcheck disable=SC2153
build_all_programs "" "${TARGETLIB}/${SRVPGM}"
)

View File

@ -73,18 +73,9 @@ http
<name>
HTTP POST with NTLM authorization and following a 302 redirect
</name>
<setenv>
# we force our own host name, in order to make the test machine independent
CURL_GETHOSTNAME=curlhost
# we try to use the LD_PRELOAD hack, if not a debug build
LD_PRELOAD=%PWD/libtest/.libs/libhostname.so
</setenv>
<command>
http://%HOSTIP:%HTTPPORT/%TESTNUMBER -u testuser:testpass --ntlm -L -d "stuff to send away"
</command>
<precheck>
chkhostname curlhost
</precheck>
</client>
# Verify data after the test has been "shot"

View File

@ -65,10 +65,6 @@ http
HTTP with NTLM delegation to winbind helper
</name>
<setenv>
# we force our own host name, in order to make the test machine independent
CURL_GETHOSTNAME=curlhost
# we try to use the LD_PRELOAD hack, if not a debug build
LD_PRELOAD=%PWD/libtest/.libs/libhostname.so
# set path to fake_auth instead of real ntlm_auth to generate NTLM type1 and type 3 messages
CURL_NTLM_WB_FILE=%PWD/server/fake_ntlm
# set source directory so fake_ntlm can find the test files
@ -81,9 +77,6 @@ CURL_NTLM_AUTH_TESTNUM=%TESTNUMBER
<command>
http://%HOSTIP:%HTTPPORT/%TESTNUMBER -u testuser:anypasswd --ntlm-wb
</command>
<precheck>
chkhostname curlhost
</precheck>
</client>
# Verify data after the test has been "shot"

View File

@ -53,18 +53,9 @@ http
<name>
HTTP with NTLM authorization when talking HTTP/1.0 (known to fail)
</name>
<setenv>
# we force our own host name, in order to make the test machine independent
CURL_GETHOSTNAME=curlhost
# we try to use the LD_PRELOAD hack, if not a debug build
LD_PRELOAD=%PWD/libtest/.libs/libhostname.so
</setenv>
<command>
http://%HOSTIP:%HTTPPORT/%TESTNUMBER -u testuser:testpass --ntlm -0
</command>
<precheck>
chkhostname curlhost
</precheck>
</client>
# Verify data after the test has been "shot"

View File

@ -112,18 +112,9 @@ libauthretry
<name>
HTTP authorization retry (Basic)
</name>
<setenv>
# we force our own host name, in order to make the test machine independent
CURL_GETHOSTNAME=curlhost
# we try to use the LD_PRELOAD hack, if not a debug build
LD_PRELOAD=%PWD/libtest/.libs/libhostname.so
</setenv>
<command>
http://%HOSTIP:%HTTPPORT/%TESTNUMBER basic basic
</command>
<precheck>
chkhostname curlhost
</precheck>
</client>
# Verify data after the test has been "shot"

View File

@ -126,18 +126,9 @@ libauthretry
<name>
HTTP authorization retry (Basic switching to Digest)
</name>
<setenv>
# we force our own host name, in order to make the test machine independent
CURL_GETHOSTNAME=curlhost
# we try to use the LD_PRELOAD hack, if not a debug build
LD_PRELOAD=%PWD/libtest/.libs/libhostname.so
</setenv>
<command>
http://%HOSTIP:%HTTPPORT/%TESTNUMBER basic digest
</command>
<precheck>
chkhostname curlhost
</precheck>
</client>
# Verify data after the test has been "shot"

View File

@ -162,18 +162,9 @@ libauthretry
<name>
HTTP authorization retry (Digest switching to Basic)
</name>
<setenv>
# we force our own host name, in order to make the test machine independent
CURL_GETHOSTNAME=curlhost
# we try to use the LD_PRELOAD hack, if not a debug build
LD_PRELOAD=%PWD/libtest/.libs/libhostname.so
</setenv>
<command>
http://%HOSTIP:%HTTPPORT/%TESTNUMBER digest basic
</command>
<precheck>
chkhostname curlhost
</precheck>
</client>
# Verify data after the test has been "shot"

View File

@ -185,18 +185,9 @@ libauthretry
<name>
HTTP authorization retry (Digest)
</name>
<setenv>
# we force our own host name, in order to make the test machine independent
CURL_GETHOSTNAME=curlhost
# we try to use the LD_PRELOAD hack, if not a debug build
LD_PRELOAD=%PWD/libtest/.libs/libhostname.so
</setenv>
<command>
http://%HOSTIP:%HTTPPORT/%TESTNUMBER digest digest
</command>
<precheck>
chkhostname curlhost
</precheck>
</client>
# Verify data after the test has been "shot"

View File

@ -34,18 +34,9 @@ SSL
<name>
IMAP NTLM graceful cancellation
</name>
<setenv>
# we force our own host name, in order to make the test machine independent
CURL_GETHOSTNAME=curlhost
# we try to use the LD_PRELOAD hack, if not a debug build
LD_PRELOAD=%PWD/libtest/.libs/libhostname.so
</setenv>
<command>
'imap://%HOSTIP:%IMAPPORT/%TESTNUMBER/;MAILINDEX=1' -u testuser:testpass
</command>
<precheck>
chkhostname curlhost
</precheck>
</client>
#

View File

@ -45,18 +45,9 @@ SSL
<name>
IMAP NTLM authentication with SASL downgrade
</name>
<setenv>
# we force our own host name, in order to make the test machine independent
CURL_GETHOSTNAME=curlhost
# we try to use the LD_PRELOAD hack, if not a debug build
LD_PRELOAD=%PWD/libtest/.libs/libhostname.so
</setenv>
<command>
'imap://%HOSTIP:%IMAPPORT/%TESTNUMBER/;MAILINDEX=1' -u user:secret
</command>
<precheck>
chkhostname curlhost
</precheck>
</client>
#

View File

@ -35,18 +35,9 @@ SSL
<name>
POP3 NTLM graceful cancellation
</name>
<setenv>
# we force our own host name, in order to make the test machine independent
CURL_GETHOSTNAME=curlhost
# we try to use the LD_PRELOAD hack, if not a debug build
LD_PRELOAD=%PWD/libtest/.libs/libhostname.so
</setenv>
<command>
pop3://%HOSTIP:%POP3PORT/%TESTNUMBER -u testuser:testpass
</command>
<precheck>
chkhostname curlhost
</precheck>
</client>
#

View File

@ -47,18 +47,9 @@ SSL
<name>
POP3 NTLM authentication with SASL downgrade
</name>
<setenv>
# we force our own host name, in order to make the test machine independent
CURL_GETHOSTNAME=curlhost
# we try to use the LD_PRELOAD hack, if not a debug build
LD_PRELOAD=%PWD/libtest/.libs/libhostname.so
</setenv>
<command>
pop3://%HOSTIP:%POP3PORT/%TESTNUMBER -u user:secret
</command>
<precheck>
chkhostname curlhost
</precheck>
</client>
#

View File

@ -34,18 +34,9 @@ SSL
<name>
SMTP NTLM graceful cancellation
</name>
<setenv>
# we force our own host name, in order to make the test machine independent
CURL_GETHOSTNAME=curlhost
# we try to use the LD_PRELOAD hack, if not a debug build
LD_PRELOAD=%PWD/libtest/.libs/libhostname.so
</setenv>
<command>
smtp://%HOSTIP:%SMTPPORT/%TESTNUMBER --mail-rcpt recipient@example.com --mail-from sender@example.com -u testuser:testpass -T -
</command>
<precheck>
chkhostname curlhost
</precheck>
</client>
#

View File

@ -40,18 +40,9 @@ SMTP NTLM authentication with SASL downgrade
<stdin>
mail body
</stdin>
<setenv>
# we force our own host name, in order to make the test machine independent
CURL_GETHOSTNAME=curlhost
# we try to use the LD_PRELOAD hack, if not a debug build
LD_PRELOAD=%PWD/libtest/.libs/libhostname.so
</setenv>
<command>
smtp://%HOSTIP:%SMTPPORT/%TESTNUMBER --mail-rcpt recipient@example.com --mail-from sender@example.com -u user:secret -T -
</command>
<precheck>
chkhostname curlhost
</precheck>
</client>
#

View File

@ -2,7 +2,6 @@
#
# SPDX-License-Identifier: curl
chkhostname
lib[1234][0-9][0-9][0-9]
lib[56][0-9][0-9]
lib1521.c

View File

@ -54,25 +54,6 @@ foreach(_target IN LISTS noinst_PROGRAMS)
PROJECT_LABEL "Test libtest ${_target}")
endforeach()
# Allows for hostname override to make tests machine independent.
# TODO: this cmake build assumes a shared build, detect static linking here!
if(NOT WIN32)
add_library(hostname MODULE EXCLUDE_FROM_ALL "sethostname.c")
add_dependencies(testdeps hostname)
target_include_directories(hostname PRIVATE
"${CURL_BINARY_DIR}/lib" # for "curl_config.h"
"${CURL_SOURCE_DIR}/lib" # for "curl_setup.h"
)
# Output to .libs for compatibility with autotools, the test data expects a
# library at (tests)/libtest/.libs/libhostname.so
set_target_properties(hostname PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/.libs")
if(CURL_HIDES_PRIVATE_SYMBOLS)
set_property(TARGET hostname APPEND PROPERTY COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS")
set_property(TARGET hostname APPEND PROPERTY COMPILE_FLAGS ${CURL_CFLAG_SYMBOLS_HIDE})
endif()
endif()
add_custom_command(
OUTPUT "lib1521.c"
COMMAND ${PERL_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/mk-lib1521.pl" < "${CURL_SOURCE_DIR}/include/curl/curl.h" > "lib1521.c"

View File

@ -63,14 +63,7 @@ LDADD = $(SUPPORTFILES_LIBS)
# noinst_PROGRAMS, lib*_SOURCES, and lib*_CFLAGS)
include Makefile.inc
# Preloading of libhostname allows host name overriding,
# this is used to make some tests machine independent.
if BUILD_LIBHOSTNAME
noinst_LTLIBRARIES = libhostname.la
else
noinst_LTLIBRARIES =
endif
if USE_CPPFLAG_CURL_STATICLIB
AM_CPPFLAGS += -DCURL_STATICLIB
@ -79,35 +72,12 @@ endif
AM_LDFLAGS =
AM_CFLAGS =
libhostname_la_CPPFLAGS_EXTRA =
libhostname_la_LDFLAGS_EXTRA = -module -avoid-version -rpath /nowhere
libhostname_la_CFLAGS_EXTRA =
libstubgss_la_LDFLAGS_EXTRA =
if CURL_LT_SHLIB_USE_NO_UNDEFINED
libhostname_la_LDFLAGS_EXTRA += -no-undefined
libstubgss_la_LDFLAGS_EXTRA += -no-undefined
endif
if CURL_LT_SHLIB_USE_MIMPURE_TEXT
libhostname_la_LDFLAGS_EXTRA += -mimpure-text
endif
if DOING_CURL_SYMBOL_HIDING
libhostname_la_CPPFLAGS_EXTRA += -DCURL_HIDDEN_SYMBOLS
libhostname_la_CFLAGS_EXTRA += $(CFLAG_CURL_SYMBOL_HIDING)
endif
libhostname_la_CPPFLAGS = $(AM_CPPFLAGS) $(libhostname_la_CPPFLAGS_EXTRA)
libhostname_la_LDFLAGS = $(AM_LDFLAGS) $(libhostname_la_LDFLAGS_EXTRA)
libhostname_la_CFLAGS = $(AM_CFLAGS) $(libhostname_la_CFLAGS_EXTRA)
libhostname_la_SOURCES = sethostname.c
libhostname_la_LIBADD =
libhostname_la_DEPENDENCIES =
# Build a stub gssapi implementation for testing
if BUILD_STUB_GSS
noinst_LTLIBRARIES += libstubgss.la

View File

@ -38,7 +38,7 @@ TIMEDIFF = ../../lib/timediff.c ../../lib/timediff.h
SUPPORTFILES = $(TIMEDIFF) first.c test.h
# These are all libcurl test programs
noinst_PROGRAMS = chkhostname libauthretry libntlmconnect libprereq \
noinst_PROGRAMS = libauthretry libntlmconnect libprereq \
lib500 lib501 lib502 lib503 lib504 lib505 lib506 lib507 lib508 lib509 \
lib510 lib511 lib512 lib513 lib514 lib515 lib516 lib517 lib518 lib519 \
lib520 lib521 lib523 lib524 lib525 lib526 lib527 lib529 lib530 lib532 \
@ -80,10 +80,6 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect libprereq \
lib3010 lib3025 lib3026 lib3027 \
lib3100 lib3101 lib3102 lib3103
chkhostname_SOURCES = chkhostname.c ../../lib/curl_gethostname.c
chkhostname_LDADD = @CURL_NETWORK_LIBS@
chkhostname_DEPENDENCIES =
libntlmconnect_SOURCES = libntlmconnect.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
libntlmconnect_LDADD = $(TESTUTIL_LIBS)

View File

@ -1,49 +0,0 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 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 https://curl.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "curl_setup.h"
#include "curl_gethostname.h"
#define HOSTNAME_MAX 1024
int main(int argc, char *argv[])
{
char buff[HOSTNAME_MAX];
if(argc != 2) {
printf("Usage: %s EXPECTED_HOSTNAME\n", argv[0]);
return 1;
}
if(Curl_gethostname(buff, HOSTNAME_MAX)) {
printf("Curl_gethostname() failed\n");
return 1;
}
/* compare the name returned by Curl_gethostname() with the expected one */
if(strncmp(buff, argv[1], HOSTNAME_MAX)) {
printf("got unexpected host name back, LD_PRELOAD failed\n");
return 1;
}
return 0;
}

View File

@ -1,41 +0,0 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 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 https://curl.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "curl_setup.h"
/*
* we force our own host name, in order to make some tests machine independent
*/
int gethostname(char *name, GETHOSTNAME_TYPE_ARG2 namelen)
{
const char *force_hostname = getenv("CURL_GETHOSTNAME");
if(force_hostname) {
strncpy(name, force_hostname, namelen);
name[namelen-1] = '\0';
return 0;
}
/* LD_PRELOAD used, but no hostname set, we'll just return a failure */
return -1;
}