Move library files to lib/sspi/ for better modularity.
Add SQUID_CHECK_WIN32_SSPI autoconf test for dependency
checking by helpers.
Add missing HAVE_FOO_H wrappers around includes.
Fixes Squid coding style compliance.
Remove unnecessary __cplusplus protections.
Remove many redundant includes from helpers code.
Remove CygWin hack which is unreachable with precompiler
conditions.
Fix several structure initialization compiler errors.
--- /dev/null
+## Copyright (C) 1996-2023 The Squid Software Foundation and contributors
+##
+## Squid software is distributed under GPLv2+ license and includes
+## contributions from numerous individuals and organizations.
+## Please see the COPYING and CONTRIBUTORS files for details.
+##
+
+# Checks whether the Windows SSPI requirements are available and work.
+# Sets squid_cv_win32_sspi to "yes" or "no".
+# The argument is the commands to run on success.
+AC_DEFUN([SQUID_CHECK_WIN32_SSPI],[
+ AC_CHECK_HEADERS([w32api/windows.h windows.h],[
+ squid_cv_win32_sspi=yes
+ # optional headers
+ AC_CHECK_HEADERS([wchar.h tchar.h])
+ # required headers
+ AC_CHECK_HEADERS([ntsecapi.h security.h sspi.h],,[squid_cv_win32_sspi=no],[
+#define SECURITY_WIN32
+#if HAVE_WINDOWS_H
+#include <windows.h>
+#elif HAVE_W32API_WINDOWS_H
+#include <w32api/windows.h>
+#endif
+#if HAVE_NTSECAPI_H
+#include <ntsecapi.h>
+#endif
+#if HAVE_SECURITY_H
+#include <security.h>
+#endif
+#if HAVE_SSPI_H
+#include <sspi.h>
+#endif
+ ])
+ ])
+ AS_IF([test "x$squid_cv_win32_sspi" = "xyes"],[$1])
+])
m4_include([acinclude/tdb.m4])
m4_include([acinclude/lib-checks.m4])
m4_include([acinclude/ax_cxx_compile_stdcxx.m4])
+m4_include([acinclude/win32-sspi.m4])
PRESET_CFLAGS="$CFLAGS"
PRESET_CXXFLAGS="$CXXFLAGS"
AM_CONDITIONAL(ENABLE_AUTH, test "x$enable_auth" != "xno")
AUTH_MODULES=""
require_smblib="no"
+require_sspi="no"
AC_ARG_ENABLE(auth-basic,
AS_HELP_STRING([--enable-auth-basic="list of helpers"],
AC_SUBST(AUTH_MODULES)
AC_SUBST(AUTH_LIBS_TO_BUILD)
AM_CONDITIONAL(ENABLE_SMBLIB, test "x$require_smblib" = "xyes")
+AM_CONDITIONAL(ENABLE_SSPI, test "x$require_sspi" = "xyes")
dnl Select logging daemon helpers to build
AC_ARG_ENABLE(log-daemon-helpers,
lib/rfcnb/Makefile
lib/smblib/Makefile
lib/snmplib/Makefile
+ lib/sspi/Makefile
scripts/Makefile
src/Makefile
src/acl/Makefile
if ENABLE_SNMP
SUBDIRS += snmplib
endif
+if ENABLE_SSPI
+SUBDIRS += sspi
+endif
install: all
install-strip: all
libmisccontainers.la \
libmiscutil.la
-#
-# Some libraries are only available on Windows
-# and others are unable to be built.
-#
-if ENABLE_WIN32SPECIFIC
-noinst_LTLIBRARIES += libsspwin32.la
-libsspwin32_la_SOURCES = sspwin32.cc
-else
-EXTRA_DIST += sspwin32.cc
-endif
if ENABLE_SMBLIB
# smblib is the only user of the rfcnb library
SUBDIRS += rfcnb smblib
--- /dev/null
+## Copyright (C) 1996-2023 The Squid Software Foundation and contributors
+##
+## Squid software is distributed under GPLv2+ license and includes
+## contributions from numerous individuals and organizations.
+## Please see the COPYING and CONTRIBUTORS files for details.
+##
+
+include $(top_srcdir)/src/Common.am
+include $(top_srcdir)/src/TestHeaders.am
+
+noinst_LTLIBRARIES = libsspwin32.la
+
+libsspwin32_la_SOURCES = \
+ sspwin32.cc \
+ sspwin32.h
#include "squid.h"
#include "base64.h"
+#if HAVE_AUTH_MODULE_NTLM
#include "ntlmauth/ntlmauth.h"
-#include "sspwin32.h"
+#endif
+#include "sspi/sspwin32.h"
#include "util.h"
+// FARPROC is an exception on Windows to the -Wcast-function-type sanity check.
+// suppress the warning only when casting FARPROC
+template <typename T>
+T
+farproc_cast(FARPROC in)
+{
+#if defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-function-type"
+ return reinterpret_cast<T>(in);
+#pragma GCC diagnostic pop
+#else
+ return reinterpret_cast<T>(in);
+#endif
+}
+
typedef struct _AUTH_SEQ {
BOOL fInitialized;
BOOL fHaveCredHandle;
static uint8_t * pClientBuf = NULL;
static uint8_t * pServerBuf = NULL;
-static AUTH_SEQ NTLM_asServer = {0};
+static AUTH_SEQ NTLM_asServer = {};
BOOL Use_Unicode = FALSE;
+#if HAVE_AUTH_MODULE_NTLM
BOOL NTLM_LocalCall = FALSE;
+#endif
/* Function pointers */
ACCEPT_SECURITY_CONTEXT_FN _AcceptSecurityContext = NULL;
hModule = LoadLibrary(lpszDLL);
if (!hModule)
return hModule;
- _AcceptSecurityContext = (ACCEPT_SECURITY_CONTEXT_FN)
- GetProcAddress(hModule, "AcceptSecurityContext");
+ _AcceptSecurityContext = farproc_cast<ACCEPT_SECURITY_CONTEXT_FN>(GetProcAddress(hModule, "AcceptSecurityContext"));
if (!_AcceptSecurityContext) {
UnloadSecurityDll();
hModule = NULL;
return hModule;
}
#ifdef UNICODE
- _AcquireCredentialsHandle = (ACQUIRE_CREDENTIALS_HANDLE_FN)
- GetProcAddress(hModule, "AcquireCredentialsHandleW");
+ _AcquireCredentialsHandle = farproc_cast<ACQUIRE_CREDENTIALS_HANDLE_FN>(GetProcAddress(hModule, "AcquireCredentialsHandleW"));
#else
- _AcquireCredentialsHandle = (ACQUIRE_CREDENTIALS_HANDLE_FN)
- GetProcAddress(hModule, "AcquireCredentialsHandleA");
+ _AcquireCredentialsHandle = farproc_cast<ACQUIRE_CREDENTIALS_HANDLE_FN>(GetProcAddress(hModule, "AcquireCredentialsHandleA"));
#endif
if (!_AcquireCredentialsHandle) {
UnloadSecurityDll();
hModule = NULL;
return hModule;
}
- _CompleteAuthToken = (COMPLETE_AUTH_TOKEN_FN)
- GetProcAddress(hModule, "CompleteAuthToken");
+ _CompleteAuthToken = farproc_cast<COMPLETE_AUTH_TOKEN_FN>(GetProcAddress(hModule, "CompleteAuthToken"));
if (!_CompleteAuthToken) {
UnloadSecurityDll();
hModule = NULL;
return hModule;
}
- _DeleteSecurityContext = (DELETE_SECURITY_CONTEXT_FN)
- GetProcAddress(hModule, "DeleteSecurityContext");
+ _DeleteSecurityContext = farproc_cast<DELETE_SECURITY_CONTEXT_FN>(GetProcAddress(hModule, "DeleteSecurityContext"));
if (!_DeleteSecurityContext) {
UnloadSecurityDll();
hModule = NULL;
return hModule;
}
- _FreeContextBuffer = (FREE_CONTEXT_BUFFER_FN)
- GetProcAddress(hModule, "FreeContextBuffer");
+ _FreeContextBuffer = farproc_cast<FREE_CONTEXT_BUFFER_FN>(GetProcAddress(hModule, "FreeContextBuffer"));
if (!_FreeContextBuffer) {
UnloadSecurityDll();
hModule = NULL;
return hModule;
}
- _FreeCredentialsHandle = (FREE_CREDENTIALS_HANDLE_FN)
- GetProcAddress(hModule, "FreeCredentialsHandle");
+ _FreeCredentialsHandle = farproc_cast<FREE_CREDENTIALS_HANDLE_FN>(GetProcAddress(hModule, "FreeCredentialsHandle"));
if (!_FreeCredentialsHandle) {
UnloadSecurityDll();
hModule = NULL;
return hModule;
}
#ifdef UNICODE
- _InitializeSecurityContext = (INITIALIZE_SECURITY_CONTEXT_FN)
- GetProcAddress(hModule, "InitializeSecurityContextW");
+ _InitializeSecurityContext = farproc_cast<INITIALIZE_SECURITY_CONTEXT_FN>(GetProcAddress(hModule, "InitializeSecurityContextW"));
#else
- _InitializeSecurityContext = (INITIALIZE_SECURITY_CONTEXT_FN)
- GetProcAddress(hModule, "InitializeSecurityContextA");
+ _InitializeSecurityContext = farproc_cast<INITIALIZE_SECURITY_CONTEXT_FN>(GetProcAddress(hModule, "InitializeSecurityContextA"));
#endif
if (!_InitializeSecurityContext) {
UnloadSecurityDll();
return hModule;
}
#ifdef UNICODE
- _QuerySecurityPackageInfo = (QUERY_SECURITY_PACKAGE_INFO_FN)
- GetProcAddress(hModule, "QuerySecurityPackageInfoW");
+ _QuerySecurityPackageInfo = farproc_cast<QUERY_SECURITY_PACKAGE_INFO_FN>(GetProcAddress(hModule, "QuerySecurityPackageInfoW"));
#else
- _QuerySecurityPackageInfo = (QUERY_SECURITY_PACKAGE_INFO_FN)
- GetProcAddress(hModule, "QuerySecurityPackageInfoA");
+ _QuerySecurityPackageInfo = farproc_cast<QUERY_SECURITY_PACKAGE_INFO_FN>(GetProcAddress(hModule, "QuerySecurityPackageInfoA"));
#endif
if (!_QuerySecurityPackageInfo) {
UnloadSecurityDll();
}
#ifdef UNICODE
- _QueryContextAttributes = (QUERY_CONTEXT_ATTRIBUTES_FN_W)
- GetProcAddress(hModule, "QueryContextAttributesW");
+ _QueryContextAttributes = farproc_cast<QUERY_CONTEXT_ATTRIBUTES_FN_W>(GetProcAddress(hModule, "QueryContextAttributesW"));
#else
- _QueryContextAttributes = (QUERY_CONTEXT_ATTRIBUTES_FN_A)
- GetProcAddress(hModule, "QueryContextAttributesA");
+ _QueryContextAttributes = farproc_cast<QUERY_CONTEXT_ATTRIBUTES_FN_A>(GetProcAddress(hModule, "QueryContextAttributesA"));
#endif
if (!_QueryContextAttributes) {
UnloadSecurityDll();
BOOL WINAPI SSP_LogonUser(PTSTR szUser, PTSTR szPassword, PTSTR szDomain)
{
- AUTH_SEQ asServer = {0};
- AUTH_SEQ asClient = {0};
+ AUTH_SEQ asServer = {};
+ AUTH_SEQ asClient = {};
BOOL fDone = FALSE;
BOOL fResult = FALSE;
DWORD cbOut = 0;
return fResult;
}
+#if HAVE_AUTH_MODULE_NTLM
const char * WINAPI SSP_MakeChallenge(PVOID PNegotiateBuf, int NegotiateLen)
{
BOOL fDone = FALSE;
return fResult;
}
+#endif /* HAVE_AUTH_MODULE_NTLM */
+#if HAVE_AUTH_MODULE_NEGOTIATE
const char * WINAPI SSP_MakeNegotiateBlob(PVOID PNegotiateBuf, int NegotiateLen, PBOOL fDone, int * Status, char * credentials)
{
DWORD cbOut = 0;
}
return NULL;
}
-
+#endif /* HAVE_AUTH_MODULE_NEGOTIATE */
#ifndef _LIBSSPWIN32_H_
#define _LIBSSPWIN32_H_
-#if _SQUID_WINDOWS_
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
#define SECURITY_WIN32
#define NTLM_PACKAGE_NAME "NTLM"
#define NEGOTIATE_PACKAGE_NAME "Negotiate"
-#if _SQUID_CYGWIN_
-#include <wchar.h>
-#define _T(x) TEXT(x)
-#else
+#if HAVE_TCHAR_H
#include <tchar.h>
#endif
+#if HAVE_WINDOWS_H
#include <windows.h>
+#endif
+#if HAVE_NTSECAPI_H
#include <ntsecapi.h>
+#endif
+#if HAVE_SECURITY_H
#include <security.h>
+#endif
+#if HAVE_SSPI_H
#include <sspi.h>
+#endif
typedef char * SSP_blobP;
HMODULE LoadSecurityDll(int, const char *);
void UnloadSecurityDll(void);
+
+#if HAVE_AUTH_MODULE_BASIC
BOOL WINAPI SSP_LogonUser(PTSTR, PTSTR, PTSTR);
-BOOL WINAPI SSP_ValidateNTLMCredentials(PVOID, int, char *);
-const char * WINAPI SSP_ValidateNegotiateCredentials(PVOID, int, PBOOL, int *, char *);
-const char * WINAPI SSP_MakeChallenge(PVOID, int);
-const char * WINAPI SSP_MakeNegotiateBlob(PVOID, int, PBOOL, int *, char *);
+#endif
-extern BOOL Use_Unicode;
+#if HAVE_AUTH_MODULE_NTLM
+const char * WINAPI SSP_MakeChallenge(PVOID, int);
+BOOL WINAPI SSP_ValidateNTLMCredentials(PVOID, int, char *);
extern BOOL NTLM_LocalCall;
+#endif
-#if defined(__cplusplus)
-}
+#if HAVE_AUTH_MODULE_NEGOTIATE
+const char * WINAPI SSP_MakeNegotiateBlob(PVOID, int, PBOOL, int *, char *);
+const char * WINAPI SSP_ValidateNegotiateCredentials(PVOID, int, PBOOL, int *, char *);
#endif
-#endif /* _SQUID_WINDOWS_ */
#endif /* LIBSSPWIN32_H_ */
include $(top_srcdir)/src/Common.am
-if ENABLE_WIN32SPECIFIC
libexec_PROGRAMS = basic_sspi_auth
-endif
basic_sspi_auth_SOURCES = \
basic_sspi_auth.cc \
$(AM_CXXFLAGS) \
-Wl,--enable-auto-import
basic_sspi_auth_LDADD = \
- $(top_builddir)/lib/libsspwin32.la \
+ $(top_builddir)/lib/sspi/libsspwin32.la \
$(top_builddir)/lib/libmiscencoding.la \
$(COMPAT_LIB) \
-lnetapi32 -ladvapi32 \
## Please see the COPYING and CONTRIBUTORS files for details.
##
-# Only build this helper on Windows
-AC_CHECK_HEADERS([w32api/windows.h windows.h],[BUILD_HELPER="SSPI"])
+SQUID_CHECK_WIN32_SSPI([
+ BUILD_HELPER="SSPI"
+ require_sspi="yes"
+])
#ifndef _VALID_H_
#define _VALID_H_
-#include "sspwin32.h"
+#include "sspi/sspwin32.h"
-#if HAVE_WINDOWS_H
-#include <windows.h>
-#endif
#include <lm.h>
#include <sys/types.h>
#undef debug
negotiate_sspi_auth_SOURCES = \
negotiate_sspi_auth.cc
negotiate_sspi_auth_LDADD = \
- $(top_builddir)/lib/libsspwin32.la \
+ $(top_builddir)/lib/sspi/libsspwin32.la \
$(top_builddir)/lib/libmiscencoding.la \
$(COMPAT_LIB) \
-ladvapi32 \
#include "helper/protocol_defines.h"
#include "ntlmauth/ntlmauth.h"
#include "ntlmauth/support_bits.cci"
-#include "sspwin32.h"
+#include "sspi/sspwin32.h"
#include "util.h"
#include <cctype>
#if HAVE_GETOPT_H
#include <getopt.h>
#endif
-#include <security.h>
-#include <sspi.h>
-#include <windows.h>
int Negotiate_packet_debug_enabled = 0;
static int have_serverblob;
## Please see the COPYING and CONTRIBUTORS files for details.
##
-#
-# Only build this helper on Windows
-#
-AC_CHECK_HEADERS([w32api/windows.h windows.h],[BUILD_HELPER="SSPI"])
+SQUID_CHECK_WIN32_SSPI([
+ BUILD_HELPER="SSPI"
+ require_sspi="yes"
+])
ntlm_sspi_auth_SOURCES = ntlm_sspi_auth.cc
ntlm_sspi_auth_LDADD= \
$(top_builddir)/lib/ntlmauth/libntlmauth.la \
- $(top_builddir)/lib/libsspwin32.la \
+ $(top_builddir)/lib/sspi/libsspwin32.la \
$(top_builddir)/lib/libmiscencoding.la \
$(COMPAT_LIB) \
-lnetapi32 \
#include "helper/protocol_defines.h"
#include "ntlmauth/ntlmauth.h"
#include "ntlmauth/support_bits.cci"
-#include "sspwin32.h"
+#include "sspi/sspwin32.h"
#include "util.h"
#include <cctype>
#include <lm.h>
-#include <ntsecapi.h>
-#include <sspi.h>
-#include <security.h>
#if HAVE_GETOPT_H
#include <getopt.h>
#endif
-#include <windows.h>
int NTLM_packet_debug_enabled = 0;
static int have_challenge;
## Please see the COPYING and CONTRIBUTORS files for details.
##
-#
-# Only build this helper on Windows
-#
-AC_CHECK_HEADERS([w32api/windows.h windows.h],[BUILD_HELPER="SSPI"])
+SQUID_CHECK_WIN32_SSPI([
+ BUILD_HELPER="SSPI"
+ require_sspi="yes"
+])