From e813bf31d7b4ea4b39e227a66fec068f5fcd1a50 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Thu, 29 Jan 2009 20:32:27 +0000 Subject: Introduced curl_sspi.c and curl_sspi.h for the implementation of functions Curl_sspi_global_init() and Curl_sspi_global_cleanup() which previously were named Curl_ntlm_global_init() and Curl_ntlm_global_cleanup() in http_ntlm.c Also adjusted socks_sspi.c to remove the link-time dependency on the Windows SSPI library using it now in the same way as it was done in http_ntlm.c. --- lib/curl_sspi.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 lib/curl_sspi.c (limited to 'lib/curl_sspi.c') diff --git a/lib/curl_sspi.c b/lib/curl_sspi.c new file mode 100644 index 000000000..36a498e53 --- /dev/null +++ b/lib/curl_sspi.c @@ -0,0 +1,119 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2009, Daniel Stenberg, , 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. + * + * $Id$ + ***************************************************************************/ + +#include "setup.h" + +#ifdef USE_WINDOWS_SSPI + +#include + +#include "curl_sspi.h" + +#define _MPRINTF_REPLACE /* use our functions only */ +#include + +#include "memory.h" +/* The last #include file should be: */ +#include "memdebug.h" + + +/* Handle of security.dll or secur32.dll, depending on Windows version */ +HMODULE s_hSecDll = NULL; + +/* Pointer to SSPI dispatch table */ +PSecurityFunctionTableA s_pSecFn = NULL; + + +/* + * Curl_sspi_global_init() + * + * This is used to load the Security Service Provider Interface (SSPI) + * dynamic link library portably across all Windows versions, without + * the need to directly link libcurl, nor the application using it, at + * build time. + * + * Once this function has been execured, Windows SSPI functions can be + * called through the Security Service Provider Interface dispatch table. + */ + +CURLcode +Curl_sspi_global_init(void) +{ + OSVERSIONINFO osver; + INIT_SECURITY_INTERFACE_A pInitSecurityInterface; + + /* If security interface is not yet initialized try to do this */ + if(s_hSecDll == NULL) { + + /* Find out Windows version */ + memset(&osver, 0, sizeof(osver)); + osver.dwOSVersionInfoSize = sizeof(osver); + if(! GetVersionEx(&osver)) + return CURLE_FAILED_INIT; + + /* Security Service Provider Interface (SSPI) functions are located in + * security.dll on WinNT 4.0 and in secur32.dll on Win9x. Win2K and XP + * have both these DLLs (security.dll forwards calls to secur32.dll) */ + + /* Load SSPI dll into the address space of the calling process */ + if(osver.dwPlatformId == VER_PLATFORM_WIN32_NT + && osver.dwMajorVersion == 4) + s_hSecDll = LoadLibrary("security.dll"); + else + s_hSecDll = LoadLibrary("secur32.dll"); + if(! s_hSecDll) + return CURLE_FAILED_INIT; + + /* Get address of the InitSecurityInterfaceA function from the SSPI dll */ + pInitSecurityInterface = (INIT_SECURITY_INTERFACE_A) + GetProcAddress(s_hSecDll, "InitSecurityInterfaceA"); + if(! pInitSecurityInterface) + return CURLE_FAILED_INIT; + + /* Get pointer to Security Service Provider Interface dispatch table */ + s_pSecFn = pInitSecurityInterface(); + if(! s_pSecFn) + return CURLE_FAILED_INIT; + + } + return CURLE_OK; +} + + +/* + * Curl_sspi_global_cleanup() + * + * This deinitializes the Security Service Provider Interface from libcurl. + */ + +void +Curl_sspi_global_cleanup(void) +{ + if(s_hSecDll) { + FreeLibrary(s_hSecDll); + s_hSecDll = NULL; + s_pSecFn = NULL; + } +} + +#endif /* USE_WINDOWS_SSPI */ -- cgit v1.2.1 From 0a6312d66fe7dfcc096fcc5de0e065add6941ad4 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 30 Jan 2009 01:54:22 +0000 Subject: fix typo in comment --- lib/curl_sspi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/curl_sspi.c') diff --git a/lib/curl_sspi.c b/lib/curl_sspi.c index 36a498e53..47e7d5e23 100644 --- a/lib/curl_sspi.c +++ b/lib/curl_sspi.c @@ -52,7 +52,7 @@ PSecurityFunctionTableA s_pSecFn = NULL; * the need to directly link libcurl, nor the application using it, at * build time. * - * Once this function has been execured, Windows SSPI functions can be + * Once this function has been executed, Windows SSPI functions can be * called through the Security Service Provider Interface dispatch table. */ -- cgit v1.2.1 From 33a3753c3f41d546ebf3350685eb7201d25783f4 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 21 Apr 2009 11:46:16 +0000 Subject: libcurl's memory.h renamed to curl_memory.h --- lib/curl_sspi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/curl_sspi.c') diff --git a/lib/curl_sspi.c b/lib/curl_sspi.c index 47e7d5e23..d91948557 100644 --- a/lib/curl_sspi.c +++ b/lib/curl_sspi.c @@ -32,7 +32,7 @@ #define _MPRINTF_REPLACE /* use our functions only */ #include -#include "memory.h" +#include "curl_memory.h" /* The last #include file should be: */ #include "memdebug.h" -- cgit v1.2.1 From 2309b4e330b96bc2e1f8e36b6184015e59544037 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 24 Mar 2010 11:02:54 +0100 Subject: remove the CVSish $Id$ lines --- lib/curl_sspi.c | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/curl_sspi.c') diff --git a/lib/curl_sspi.c b/lib/curl_sspi.c index d91948557..6b19b47c8 100644 --- a/lib/curl_sspi.c +++ b/lib/curl_sspi.c @@ -18,7 +18,6 @@ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * - * $Id$ ***************************************************************************/ #include "setup.h" -- cgit v1.2.1 From 413cbdce3c54be97a50e119154df99aa1e4e2810 Mon Sep 17 00:00:00 2001 From: Guenter Knauf Date: Thu, 2 Sep 2010 00:38:16 +0200 Subject: Use own typedef as workaround for broken sspi.h header (f.e. Watcom). --- lib/curl_sspi.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/curl_sspi.c') diff --git a/lib/curl_sspi.c b/lib/curl_sspi.c index 6b19b47c8..b985dbceb 100644 --- a/lib/curl_sspi.c +++ b/lib/curl_sspi.c @@ -36,6 +36,9 @@ #include "memdebug.h" +/* We use our own typedef here since some headers might lack these */ +typedef PSecurityFunctionTableA (APIENTRY *INITSECURITYINTERFACE_FN_A)(VOID); + /* Handle of security.dll or secur32.dll, depending on Windows version */ HMODULE s_hSecDll = NULL; @@ -59,7 +62,7 @@ CURLcode Curl_sspi_global_init(void) { OSVERSIONINFO osver; - INIT_SECURITY_INTERFACE_A pInitSecurityInterface; + INITSECURITYINTERFACE_FN_A pInitSecurityInterface; /* If security interface is not yet initialized try to do this */ if(s_hSecDll == NULL) { @@ -84,7 +87,7 @@ Curl_sspi_global_init(void) return CURLE_FAILED_INIT; /* Get address of the InitSecurityInterfaceA function from the SSPI dll */ - pInitSecurityInterface = (INIT_SECURITY_INTERFACE_A) + pInitSecurityInterface = (INITSECURITYINTERFACE_FN_A) GetProcAddress(s_hSecDll, "InitSecurityInterfaceA"); if(! pInitSecurityInterface) return CURLE_FAILED_INIT; -- cgit v1.2.1 From 2976de480808119dae08fc6f52c8d75ba1aedb1a Mon Sep 17 00:00:00 2001 From: Steve Holme Date: Sun, 22 Apr 2012 18:49:27 +0100 Subject: sspi: Added version information Added version information for Windows SSPI to curl's main version string and removed SSPI from the features string. --- lib/curl_sspi.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) (limited to 'lib/curl_sspi.c') diff --git a/lib/curl_sspi.c b/lib/curl_sspi.c index b985dbceb..e065f86c5 100644 --- a/lib/curl_sspi.c +++ b/lib/curl_sspi.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2009, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2012, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -101,6 +101,68 @@ Curl_sspi_global_init(void) return CURLE_OK; } +/* + * Curl_sspi_version() + * + * This function returns the SSPI library version information. + */ +CURLcode Curl_sspi_version(int *major, int *minor, int *build, int *special) +{ + CURLcode result = CURLE_OK; + VS_FIXEDFILEINFO *version_info = NULL; + LPTSTR version = NULL; + LPTSTR path = NULL; + LPVOID data = NULL; + DWORD size, handle; + + if(!s_hSecDll) + return CURLE_FAILED_INIT; + + path = malloc(MAX_PATH); + if(!path) + return CURLE_OUT_OF_MEMORY; + + if(GetModuleFileName(s_hSecDll, path, MAX_PATH)) { + size = GetFileVersionInfoSize(path, &handle); + if(size) { + data = malloc(size); + if(data) { + if(GetFileVersionInfo(path, handle, size, data)) { + if(!VerQueryValue(data, "\\", &version_info, &handle)) + result = CURLE_OUT_OF_MEMORY; + } + else + result = CURLE_OUT_OF_MEMORY; + } + else + result = CURLE_OUT_OF_MEMORY; + } + else + result = CURLE_OUT_OF_MEMORY; + } + else + result = CURLE_OUT_OF_MEMORY; + + /* Set the out parameters */ + if(!result) { + if(major) + *major = (version_info->dwProductVersionMS >> 16) & 0xffff; + + if(minor) + *minor = (version_info->dwProductVersionMS >> 0) & 0xffff; + + if(build) + *build = (version_info->dwProductVersionLS >> 16) & 0xffff; + + if(special) + *special = (version_info->dwProductVersionLS >> 0) & 0xffff; + } + + Curl_safefree(data); + Curl_safefree(path); + + return result; +} /* * Curl_sspi_global_cleanup() -- cgit v1.2.1 From 46cd5f1daddad3b3e542e6d93eee52e8bb9a8687 Mon Sep 17 00:00:00 2001 From: Steve Holme Date: Sun, 22 Apr 2012 18:59:07 +0100 Subject: sspi - Small code tidy up --- lib/curl_sspi.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'lib/curl_sspi.c') diff --git a/lib/curl_sspi.c b/lib/curl_sspi.c index e065f86c5..b9a343b6c 100644 --- a/lib/curl_sspi.c +++ b/lib/curl_sspi.c @@ -35,7 +35,6 @@ /* The last #include file should be: */ #include "memdebug.h" - /* We use our own typedef here since some headers might lack these */ typedef PSecurityFunctionTableA (APIENTRY *INITSECURITYINTERFACE_FN_A)(VOID); @@ -45,7 +44,6 @@ HMODULE s_hSecDll = NULL; /* Pointer to SSPI dispatch table */ PSecurityFunctionTableA s_pSecFn = NULL; - /* * Curl_sspi_global_init() * @@ -58,19 +56,17 @@ PSecurityFunctionTableA s_pSecFn = NULL; * called through the Security Service Provider Interface dispatch table. */ -CURLcode -Curl_sspi_global_init(void) +CURLcode Curl_sspi_global_init(void) { OSVERSIONINFO osver; INITSECURITYINTERFACE_FN_A pInitSecurityInterface; /* If security interface is not yet initialized try to do this */ - if(s_hSecDll == NULL) { - + if(!s_hSecDll) { /* Find out Windows version */ memset(&osver, 0, sizeof(osver)); osver.dwOSVersionInfoSize = sizeof(osver); - if(! GetVersionEx(&osver)) + if(!GetVersionEx(&osver)) return CURLE_FAILED_INIT; /* Security Service Provider Interface (SSPI) functions are located in @@ -83,21 +79,21 @@ Curl_sspi_global_init(void) s_hSecDll = LoadLibrary("security.dll"); else s_hSecDll = LoadLibrary("secur32.dll"); - if(! s_hSecDll) + if(!s_hSecDll) return CURLE_FAILED_INIT; /* Get address of the InitSecurityInterfaceA function from the SSPI dll */ pInitSecurityInterface = (INITSECURITYINTERFACE_FN_A) GetProcAddress(s_hSecDll, "InitSecurityInterfaceA"); - if(! pInitSecurityInterface) + if(!pInitSecurityInterface) return CURLE_FAILED_INIT; /* Get pointer to Security Service Provider Interface dispatch table */ s_pSecFn = pInitSecurityInterface(); - if(! s_pSecFn) + if(!s_pSecFn) return CURLE_FAILED_INIT; - } + return CURLE_OK; } @@ -170,8 +166,7 @@ CURLcode Curl_sspi_version(int *major, int *minor, int *build, int *special) * This deinitializes the Security Service Provider Interface from libcurl. */ -void -Curl_sspi_global_cleanup(void) +void Curl_sspi_global_cleanup(void) { if(s_hSecDll) { FreeLibrary(s_hSecDll); -- cgit v1.2.1 From 683bfa60ad0b52505947e59b03515e5f44378523 Mon Sep 17 00:00:00 2001 From: Guenter Knauf Date: Sun, 22 Apr 2012 21:19:36 +0200 Subject: Fixed 'Trailing whitespace' found by checksrc. --- lib/curl_sspi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/curl_sspi.c') diff --git a/lib/curl_sspi.c b/lib/curl_sspi.c index b9a343b6c..e266c79d1 100644 --- a/lib/curl_sspi.c +++ b/lib/curl_sspi.c @@ -117,7 +117,7 @@ CURLcode Curl_sspi_version(int *major, int *minor, int *build, int *special) path = malloc(MAX_PATH); if(!path) return CURLE_OUT_OF_MEMORY; - + if(GetModuleFileName(s_hSecDll, path, MAX_PATH)) { size = GetFileVersionInfoSize(path, &handle); if(size) { @@ -143,7 +143,7 @@ CURLcode Curl_sspi_version(int *major, int *minor, int *build, int *special) if(!result) { if(major) *major = (version_info->dwProductVersionMS >> 16) & 0xffff; - + if(minor) *minor = (version_info->dwProductVersionMS >> 0) & 0xffff; -- cgit v1.2.1 From 412510f97407d617426d93b80e6b6bf0a8ff11ac Mon Sep 17 00:00:00 2001 From: Steve Holme Date: Sun, 22 Apr 2012 21:00:32 +0100 Subject: sspi: Code tidy up to remove unused variable. --- lib/curl_sspi.c | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/curl_sspi.c') diff --git a/lib/curl_sspi.c b/lib/curl_sspi.c index e266c79d1..80f29f263 100644 --- a/lib/curl_sspi.c +++ b/lib/curl_sspi.c @@ -106,7 +106,6 @@ CURLcode Curl_sspi_version(int *major, int *minor, int *build, int *special) { CURLcode result = CURLE_OK; VS_FIXEDFILEINFO *version_info = NULL; - LPTSTR version = NULL; LPTSTR path = NULL; LPVOID data = NULL; DWORD size, handle; -- cgit v1.2.1 From 975d23480c35225b80259c4e6ad70cff3e8fae12 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Mon, 23 Apr 2012 16:27:04 +0200 Subject: Revert "sspi: Code tidy up to remove unused variable." This reverts commit 412510f97407d617426d93b80e6b6bf0a8ff11ac. --- lib/curl_sspi.c | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/curl_sspi.c') diff --git a/lib/curl_sspi.c b/lib/curl_sspi.c index 80f29f263..e266c79d1 100644 --- a/lib/curl_sspi.c +++ b/lib/curl_sspi.c @@ -106,6 +106,7 @@ CURLcode Curl_sspi_version(int *major, int *minor, int *build, int *special) { CURLcode result = CURLE_OK; VS_FIXEDFILEINFO *version_info = NULL; + LPTSTR version = NULL; LPTSTR path = NULL; LPVOID data = NULL; DWORD size, handle; -- cgit v1.2.1 From 419a50f817599600a47a374eca7506845ca6afb1 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Mon, 23 Apr 2012 16:27:20 +0200 Subject: Revert "Fixed 'Trailing whitespace' found by checksrc." This reverts commit 683bfa60ad0b52505947e59b03515e5f44378523. --- lib/curl_sspi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/curl_sspi.c') diff --git a/lib/curl_sspi.c b/lib/curl_sspi.c index e266c79d1..b9a343b6c 100644 --- a/lib/curl_sspi.c +++ b/lib/curl_sspi.c @@ -117,7 +117,7 @@ CURLcode Curl_sspi_version(int *major, int *minor, int *build, int *special) path = malloc(MAX_PATH); if(!path) return CURLE_OUT_OF_MEMORY; - + if(GetModuleFileName(s_hSecDll, path, MAX_PATH)) { size = GetFileVersionInfoSize(path, &handle); if(size) { @@ -143,7 +143,7 @@ CURLcode Curl_sspi_version(int *major, int *minor, int *build, int *special) if(!result) { if(major) *major = (version_info->dwProductVersionMS >> 16) & 0xffff; - + if(minor) *minor = (version_info->dwProductVersionMS >> 0) & 0xffff; -- cgit v1.2.1 From 071f8d4182ec86b236404e0af3dadfd0bf3270c8 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Mon, 23 Apr 2012 16:27:47 +0200 Subject: Revert "sspi - Small code tidy up" This reverts commit 46cd5f1daddad3b3e542e6d93eee52e8bb9a8687. --- lib/curl_sspi.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'lib/curl_sspi.c') diff --git a/lib/curl_sspi.c b/lib/curl_sspi.c index b9a343b6c..e065f86c5 100644 --- a/lib/curl_sspi.c +++ b/lib/curl_sspi.c @@ -35,6 +35,7 @@ /* The last #include file should be: */ #include "memdebug.h" + /* We use our own typedef here since some headers might lack these */ typedef PSecurityFunctionTableA (APIENTRY *INITSECURITYINTERFACE_FN_A)(VOID); @@ -44,6 +45,7 @@ HMODULE s_hSecDll = NULL; /* Pointer to SSPI dispatch table */ PSecurityFunctionTableA s_pSecFn = NULL; + /* * Curl_sspi_global_init() * @@ -56,17 +58,19 @@ PSecurityFunctionTableA s_pSecFn = NULL; * called through the Security Service Provider Interface dispatch table. */ -CURLcode Curl_sspi_global_init(void) +CURLcode +Curl_sspi_global_init(void) { OSVERSIONINFO osver; INITSECURITYINTERFACE_FN_A pInitSecurityInterface; /* If security interface is not yet initialized try to do this */ - if(!s_hSecDll) { + if(s_hSecDll == NULL) { + /* Find out Windows version */ memset(&osver, 0, sizeof(osver)); osver.dwOSVersionInfoSize = sizeof(osver); - if(!GetVersionEx(&osver)) + if(! GetVersionEx(&osver)) return CURLE_FAILED_INIT; /* Security Service Provider Interface (SSPI) functions are located in @@ -79,21 +83,21 @@ CURLcode Curl_sspi_global_init(void) s_hSecDll = LoadLibrary("security.dll"); else s_hSecDll = LoadLibrary("secur32.dll"); - if(!s_hSecDll) + if(! s_hSecDll) return CURLE_FAILED_INIT; /* Get address of the InitSecurityInterfaceA function from the SSPI dll */ pInitSecurityInterface = (INITSECURITYINTERFACE_FN_A) GetProcAddress(s_hSecDll, "InitSecurityInterfaceA"); - if(!pInitSecurityInterface) + if(! pInitSecurityInterface) return CURLE_FAILED_INIT; /* Get pointer to Security Service Provider Interface dispatch table */ s_pSecFn = pInitSecurityInterface(); - if(!s_pSecFn) + if(! s_pSecFn) return CURLE_FAILED_INIT; - } + } return CURLE_OK; } @@ -166,7 +170,8 @@ CURLcode Curl_sspi_version(int *major, int *minor, int *build, int *special) * This deinitializes the Security Service Provider Interface from libcurl. */ -void Curl_sspi_global_cleanup(void) +void +Curl_sspi_global_cleanup(void) { if(s_hSecDll) { FreeLibrary(s_hSecDll); -- cgit v1.2.1 From d6c449e3b4262aa29c1594d64379a8c26d9a5c38 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Mon, 23 Apr 2012 16:28:01 +0200 Subject: Revert "sspi: Added version information" This reverts commit 2976de480808119dae08fc6f52c8d75ba1aedb1a. --- lib/curl_sspi.c | 64 +-------------------------------------------------------- 1 file changed, 1 insertion(+), 63 deletions(-) (limited to 'lib/curl_sspi.c') diff --git a/lib/curl_sspi.c b/lib/curl_sspi.c index e065f86c5..b985dbceb 100644 --- a/lib/curl_sspi.c +++ b/lib/curl_sspi.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2012, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2009, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -101,68 +101,6 @@ Curl_sspi_global_init(void) return CURLE_OK; } -/* - * Curl_sspi_version() - * - * This function returns the SSPI library version information. - */ -CURLcode Curl_sspi_version(int *major, int *minor, int *build, int *special) -{ - CURLcode result = CURLE_OK; - VS_FIXEDFILEINFO *version_info = NULL; - LPTSTR version = NULL; - LPTSTR path = NULL; - LPVOID data = NULL; - DWORD size, handle; - - if(!s_hSecDll) - return CURLE_FAILED_INIT; - - path = malloc(MAX_PATH); - if(!path) - return CURLE_OUT_OF_MEMORY; - - if(GetModuleFileName(s_hSecDll, path, MAX_PATH)) { - size = GetFileVersionInfoSize(path, &handle); - if(size) { - data = malloc(size); - if(data) { - if(GetFileVersionInfo(path, handle, size, data)) { - if(!VerQueryValue(data, "\\", &version_info, &handle)) - result = CURLE_OUT_OF_MEMORY; - } - else - result = CURLE_OUT_OF_MEMORY; - } - else - result = CURLE_OUT_OF_MEMORY; - } - else - result = CURLE_OUT_OF_MEMORY; - } - else - result = CURLE_OUT_OF_MEMORY; - - /* Set the out parameters */ - if(!result) { - if(major) - *major = (version_info->dwProductVersionMS >> 16) & 0xffff; - - if(minor) - *minor = (version_info->dwProductVersionMS >> 0) & 0xffff; - - if(build) - *build = (version_info->dwProductVersionLS >> 16) & 0xffff; - - if(special) - *special = (version_info->dwProductVersionLS >> 0) & 0xffff; - } - - Curl_safefree(data); - Curl_safefree(path); - - return result; -} /* * Curl_sspi_global_cleanup() -- cgit v1.2.1 From f858bb0d1f989694d562e7fe7818ee7189c18e28 Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Wed, 11 Apr 2012 17:25:26 +0200 Subject: sspi: Refactored socks_sspi and schannel to use same error message functions Moved the error constant switch to curl_sspi.c and added two new helper functions to curl_sspi.[ch] which either return the constant or a fully translated message representing the SSPI security status. Updated socks_sspi.c and curl_schannel.c to use the new functions. --- lib/curl_sspi.c | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) (limited to 'lib/curl_sspi.c') diff --git a/lib/curl_sspi.c b/lib/curl_sspi.c index b985dbceb..d915710f8 100644 --- a/lib/curl_sspi.c +++ b/lib/curl_sspi.c @@ -118,4 +118,153 @@ Curl_sspi_global_cleanup(void) } } + +/* + * Curl_sspi_status(SECURIY_STATUS status) + * + * This function returns a string representing an SSPI status. + * It will in any case return a usable string pointer which needs to be freed. + */ +char* +Curl_sspi_status(SECURITY_STATUS status) +{ + const char* status_const; + + switch(status) { + case SEC_I_COMPLETE_AND_CONTINUE: + status_const = "SEC_I_COMPLETE_AND_CONTINUE"; + break; + case SEC_I_COMPLETE_NEEDED: + status_const = "SEC_I_COMPLETE_NEEDED"; + break; + case SEC_I_CONTINUE_NEEDED: + status_const = "SEC_I_CONTINUE_NEEDED"; + break; + case SEC_I_CONTEXT_EXPIRED: + status_const = "SEC_I_CONTEXT_EXPIRED"; + break; + case SEC_I_INCOMPLETE_CREDENTIALS: + status_const = "SEC_I_INCOMPLETE_CREDENTIALS"; + break; + case SEC_I_RENEGOTIATE: + status_const = "SEC_I_RENEGOTIATE"; + break; + case SEC_E_BUFFER_TOO_SMALL: + status_const = "SEC_E_BUFFER_TOO_SMALL"; + break; + case SEC_E_CONTEXT_EXPIRED: + status_const = "SEC_E_CONTEXT_EXPIRED"; + break; + case SEC_E_CRYPTO_SYSTEM_INVALID: + status_const = "SEC_E_CRYPTO_SYSTEM_INVALID"; + break; + case SEC_E_INCOMPLETE_MESSAGE: + status_const = "SEC_E_INCOMPLETE_MESSAGE"; + break; + case SEC_E_INSUFFICIENT_MEMORY: + status_const = "SEC_E_INSUFFICIENT_MEMORY"; + break; + case SEC_E_INTERNAL_ERROR: + status_const = "SEC_E_INTERNAL_ERROR"; + break; + case SEC_E_INVALID_HANDLE: + status_const = "SEC_E_INVALID_HANDLE"; + break; + case SEC_E_INVALID_TOKEN: + status_const = "SEC_E_INVALID_TOKEN"; + break; + case SEC_E_LOGON_DENIED: + status_const = "SEC_E_LOGON_DENIED"; + break; + case SEC_E_MESSAGE_ALTERED: + status_const = "SEC_E_MESSAGE_ALTERED"; + break; + case SEC_E_NO_AUTHENTICATING_AUTHORITY: + status_const = "SEC_E_NO_AUTHENTICATING_AUTHORITY"; + break; + case SEC_E_NO_CREDENTIALS: + status_const = "SEC_E_NO_CREDENTIALS"; + break; + case SEC_E_NOT_OWNER: + status_const = "SEC_E_NOT_OWNER"; + break; + case SEC_E_OK: + status_const = "SEC_E_OK"; + break; + case SEC_E_OUT_OF_SEQUENCE: + status_const = "SEC_E_OUT_OF_SEQUENCE"; + break; + case SEC_E_QOP_NOT_SUPPORTED: + status_const = "SEC_E_QOP_NOT_SUPPORTED"; + break; + case SEC_E_SECPKG_NOT_FOUND: + status_const = "SEC_E_SECPKG_NOT_FOUND"; + break; + case SEC_E_TARGET_UNKNOWN: + status_const = "SEC_E_TARGET_UNKNOWN"; + break; + case SEC_E_UNKNOWN_CREDENTIALS: + status_const = "SEC_E_UNKNOWN_CREDENTIALS"; + break; + case SEC_E_UNSUPPORTED_FUNCTION: + status_const = "SEC_E_UNSUPPORTED_FUNCTION"; + break; + case SEC_E_WRONG_PRINCIPAL: + status_const = "SEC_E_WRONG_PRINCIPAL"; + break; + default: + status_const = "Unknown error"; + } + + return curl_maprintf("%s (0x%08X)", status_const, status); +} + +/* + * Curl_sspi_status_msg(SECURITY_STATUS status) + * + * This function returns a message representing an SSPI status. + * It will in any case return a usable string pointer which needs to be freed. + */ + +char* +Curl_sspi_status_msg(SECURITY_STATUS status) +{ + LPSTR format_msg = NULL; + char *status_msg = NULL, *status_const = NULL; + int status_len = 0; + + status_len = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, status, 0, (LPTSTR)&format_msg, 0, NULL); + + if(status_len > 0 && format_msg) { + status_msg = strdup(format_msg); + LocalFree(format_msg); + + /* remove trailing CR+LF */ + if(status_len > 0) { + if(status_msg[status_len-1] == '\n') { + status_msg[status_len-1] = '\0'; + if(status_len > 1) { + if(status_msg[status_len-2] == '\r') { + status_msg[status_len-2] = '\0'; + } + } + } + } + } + + status_const = Curl_sspi_status(status); + if(status_msg) { + status_msg = curl_maprintf("%s [%s]", status_msg, status_const); + free(status_const); + } + else { + status_msg = status_const; + } + + return status_msg; +} + #endif /* USE_WINDOWS_SSPI */ -- cgit v1.2.1 From c1311c2b8f34c352d771f1d5810e64141aa802b1 Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Sat, 14 Apr 2012 15:00:33 +0200 Subject: curl_sspi: Added Curl_sspi_version function Added new function to get SSPI version as string. Added required library version.lib to makefiles. Changed curl_schannel.c to use Curl_sspi_version. --- lib/curl_sspi.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'lib/curl_sspi.c') diff --git a/lib/curl_sspi.c b/lib/curl_sspi.c index d915710f8..d3533a293 100644 --- a/lib/curl_sspi.c +++ b/lib/curl_sspi.c @@ -119,6 +119,55 @@ Curl_sspi_global_cleanup(void) } +/* + * Curl_sspi_version() + * + * This function returns a string representing the SSPI library version. + * It will in any case return a usable string pointer which needs to be freed. + */ +char * +Curl_sspi_version() +{ + VS_FIXEDFILEINFO *version_info = NULL; + LPTSTR version = NULL; + LPTSTR path = NULL; + LPVOID data = NULL; + DWORD size, handle; + + if(s_hSecDll) { + path = malloc(MAX_PATH); + if(path) { + if(GetModuleFileName(s_hSecDll, path, MAX_PATH)) { + size = GetFileVersionInfoSize(path, &handle); + if(size) { + data = malloc(size); + if(data) { + if(GetFileVersionInfo(path, handle, size, data)) { + if(VerQueryValue(data, "\\", &version_info, &handle)) { + version = curl_maprintf("SSPI/%d.%d.%d.%d", + (version_info->dwProductVersionMS>>16)&0xffff, + (version_info->dwProductVersionMS>>0)&0xffff, + (version_info->dwProductVersionLS>>16)&0xffff, + (version_info->dwProductVersionLS>>0)&0xffff); + } + } + free(data); + } + } + } + free(path); + } + if(!version) + version = strdup("SSPI/Unknown"); + } + + if(!version) + version = strdup(""); + + return version; +} + + /* * Curl_sspi_status(SECURIY_STATUS status) * @@ -219,6 +268,7 @@ Curl_sspi_status(SECURITY_STATUS status) return curl_maprintf("%s (0x%08X)", status_const, status); } + /* * Curl_sspi_status_msg(SECURITY_STATUS status) * -- cgit v1.2.1 From 7047e2ed725d24f7fe4ce7c566ef0a9342e3be9c Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Sun, 15 Apr 2012 04:12:26 +0200 Subject: schannel: Code cleanup and bug fixes curl_sspi.c: Fixed mingw32-gcc compiler warnings curl_sspi.c: Fixed length of error code hex output The hex value was printed as signed 64-bit value on 64-bit systems: SEC_E_WRONG_PRINCIPAL (0xFFFFFFFF80090322) It is now correctly printed as the following: SEC_E_WRONG_PRINCIPAL (0x80090322) curl_sspi.c: Fallback to security function table version number Instead of reporting an unknown version, the interface version is used. curl_sspi.c: Removed SSPI/ version prefix from Curl_sspi_version curl_schannel: Replaced static buffer sizes with defined names curl_schannel.c: First brace when declaring functions on column 0 curl_schannel.c: Put the pointer sign directly at variable name curl_schannel.c: Use structs directly instead of typedef'ed structs curl_schannel.c: Removed space before opening brace curl_schannel.c: Fixed lines being longer than 80 chars --- lib/curl_sspi.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib/curl_sspi.c') diff --git a/lib/curl_sspi.c b/lib/curl_sspi.c index d3533a293..29f8a436d 100644 --- a/lib/curl_sspi.c +++ b/lib/curl_sspi.c @@ -133,6 +133,7 @@ Curl_sspi_version() LPTSTR path = NULL; LPVOID data = NULL; DWORD size, handle; + UINT length; if(s_hSecDll) { path = malloc(MAX_PATH); @@ -143,8 +144,8 @@ Curl_sspi_version() data = malloc(size); if(data) { if(GetFileVersionInfo(path, handle, size, data)) { - if(VerQueryValue(data, "\\", &version_info, &handle)) { - version = curl_maprintf("SSPI/%d.%d.%d.%d", + if(VerQueryValue(data, "\\", (LPVOID*)&version_info, &length)) { + version = curl_maprintf("%d.%d.%d.%d", (version_info->dwProductVersionMS>>16)&0xffff, (version_info->dwProductVersionMS>>0)&0xffff, (version_info->dwProductVersionLS>>16)&0xffff, @@ -158,7 +159,7 @@ Curl_sspi_version() free(path); } if(!version) - version = strdup("SSPI/Unknown"); + version = curl_maprintf("%d", s_pSecFn ? s_pSecFn->dwVersion : 0); } if(!version) @@ -265,7 +266,8 @@ Curl_sspi_status(SECURITY_STATUS status) status_const = "Unknown error"; } - return curl_maprintf("%s (0x%08X)", status_const, status); + return curl_maprintf("%s (0x%04X%04X)", status_const, + (status>>16)&0xffff, status&0xffff); } -- cgit v1.2.1 From bd38ebc6975f5de2ed6ac33ade46e92356d77966 Mon Sep 17 00:00:00 2001 From: Steve Holme Date: Sun, 10 Jun 2012 12:07:45 +0100 Subject: sspi: Reworked Curl_sspi_version() to return version components Reworked the version function to return four version components rather than a string that has to be freed by the caller. --- lib/curl_sspi.c | 77 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 32 deletions(-) (limited to 'lib/curl_sspi.c') diff --git a/lib/curl_sspi.c b/lib/curl_sspi.c index 29f8a436d..71f087be7 100644 --- a/lib/curl_sspi.c +++ b/lib/curl_sspi.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2009, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2012, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -122,50 +122,63 @@ Curl_sspi_global_cleanup(void) /* * Curl_sspi_version() * - * This function returns a string representing the SSPI library version. - * It will in any case return a usable string pointer which needs to be freed. + * This function returns the SSPI library version information. */ -char * -Curl_sspi_version() +CURLcode Curl_sspi_version(int *major, int *minor, int *build, int *special) { + CURLcode result = CURLE_OK; VS_FIXEDFILEINFO *version_info = NULL; - LPTSTR version = NULL; LPTSTR path = NULL; LPVOID data = NULL; DWORD size, handle; - UINT length; - if(s_hSecDll) { - path = malloc(MAX_PATH); - if(path) { - if(GetModuleFileName(s_hSecDll, path, MAX_PATH)) { - size = GetFileVersionInfoSize(path, &handle); - if(size) { - data = malloc(size); - if(data) { - if(GetFileVersionInfo(path, handle, size, data)) { - if(VerQueryValue(data, "\\", (LPVOID*)&version_info, &length)) { - version = curl_maprintf("%d.%d.%d.%d", - (version_info->dwProductVersionMS>>16)&0xffff, - (version_info->dwProductVersionMS>>0)&0xffff, - (version_info->dwProductVersionLS>>16)&0xffff, - (version_info->dwProductVersionLS>>0)&0xffff); - } - } - free(data); - } + if(!s_hSecDll) + return CURLE_FAILED_INIT; + + path = (char *) malloc(MAX_PATH); + if(!path) + return CURLE_OUT_OF_MEMORY; + + if(GetModuleFileName(s_hSecDll, path, MAX_PATH)) { + size = GetFileVersionInfoSize(path, &handle); + if(size) { + data = malloc(size); + if(data) { + if(GetFileVersionInfo(path, handle, size, data)) { + if(!VerQueryValue(data, "\\", &version_info, &handle)) + result = CURLE_OUT_OF_MEMORY; } + else + result = CURLE_OUT_OF_MEMORY; } - free(path); + else + result = CURLE_OUT_OF_MEMORY; } - if(!version) - version = curl_maprintf("%d", s_pSecFn ? s_pSecFn->dwVersion : 0); + else + result = CURLE_OUT_OF_MEMORY; + } + else + result = CURLE_OUT_OF_MEMORY; + + /* Set the out parameters */ + if(!result) { + if(major) + *major = (version_info->dwProductVersionMS >> 16) & 0xffff; + + if(minor) + *minor = (version_info->dwProductVersionMS >> 0) & 0xffff; + + if(build) + *build = (version_info->dwProductVersionLS >> 16) & 0xffff; + + if(special) + *special = (version_info->dwProductVersionLS >> 0) & 0xffff; } - if(!version) - version = strdup(""); + Curl_safefree(data); + Curl_safefree(path); - return version; + return result; } -- cgit v1.2.1 From 70d56bfe3cf2ae995ca715518c78f455c45ab95b Mon Sep 17 00:00:00 2001 From: Steve Holme Date: Sun, 10 Jun 2012 12:30:02 +0100 Subject: sspi.c: Post Curl_sspi_version() rework code tidy up Removed duplicate blank lines. Removed spaces between the not and test in various if statements. Removed explicit test of NULL in an if statement. Placed function returns on same line as function declarations. Replaced the use of curl_maprintf() with aprintf() as it is the preprocessor job to do this substitution if ENABLE_CURLX_PRINTF is set. --- lib/curl_sspi.c | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) (limited to 'lib/curl_sspi.c') diff --git a/lib/curl_sspi.c b/lib/curl_sspi.c index 71f087be7..3f4176214 100644 --- a/lib/curl_sspi.c +++ b/lib/curl_sspi.c @@ -35,7 +35,6 @@ /* The last #include file should be: */ #include "memdebug.h" - /* We use our own typedef here since some headers might lack these */ typedef PSecurityFunctionTableA (APIENTRY *INITSECURITYINTERFACE_FN_A)(VOID); @@ -45,7 +44,6 @@ HMODULE s_hSecDll = NULL; /* Pointer to SSPI dispatch table */ PSecurityFunctionTableA s_pSecFn = NULL; - /* * Curl_sspi_global_init() * @@ -57,20 +55,18 @@ PSecurityFunctionTableA s_pSecFn = NULL; * Once this function has been executed, Windows SSPI functions can be * called through the Security Service Provider Interface dispatch table. */ - -CURLcode -Curl_sspi_global_init(void) +CURLcode Curl_sspi_global_init(void) { OSVERSIONINFO osver; INITSECURITYINTERFACE_FN_A pInitSecurityInterface; /* If security interface is not yet initialized try to do this */ - if(s_hSecDll == NULL) { + if(!s_hSecDll) { /* Find out Windows version */ memset(&osver, 0, sizeof(osver)); osver.dwOSVersionInfoSize = sizeof(osver); - if(! GetVersionEx(&osver)) + if(!GetVersionEx(&osver)) return CURLE_FAILED_INIT; /* Security Service Provider Interface (SSPI) functions are located in @@ -83,33 +79,31 @@ Curl_sspi_global_init(void) s_hSecDll = LoadLibrary("security.dll"); else s_hSecDll = LoadLibrary("secur32.dll"); - if(! s_hSecDll) + if(!s_hSecDll) return CURLE_FAILED_INIT; /* Get address of the InitSecurityInterfaceA function from the SSPI dll */ pInitSecurityInterface = (INITSECURITYINTERFACE_FN_A) GetProcAddress(s_hSecDll, "InitSecurityInterfaceA"); - if(! pInitSecurityInterface) + if(!pInitSecurityInterface) return CURLE_FAILED_INIT; /* Get pointer to Security Service Provider Interface dispatch table */ s_pSecFn = pInitSecurityInterface(); - if(! s_pSecFn) + if(!s_pSecFn) return CURLE_FAILED_INIT; - } + return CURLE_OK; } - /* * Curl_sspi_global_cleanup() * * This deinitializes the Security Service Provider Interface from libcurl. */ -void -Curl_sspi_global_cleanup(void) +void Curl_sspi_global_cleanup(void) { if(s_hSecDll) { FreeLibrary(s_hSecDll); @@ -118,7 +112,6 @@ Curl_sspi_global_cleanup(void) } } - /* * Curl_sspi_version() * @@ -181,15 +174,13 @@ CURLcode Curl_sspi_version(int *major, int *minor, int *build, int *special) return result; } - /* * Curl_sspi_status(SECURIY_STATUS status) * * This function returns a string representing an SSPI status. * It will in any case return a usable string pointer which needs to be freed. */ -char* -Curl_sspi_status(SECURITY_STATUS status) +char* Curl_sspi_status(SECURITY_STATUS status) { const char* status_const; @@ -279,20 +270,17 @@ Curl_sspi_status(SECURITY_STATUS status) status_const = "Unknown error"; } - return curl_maprintf("%s (0x%04X%04X)", status_const, - (status>>16)&0xffff, status&0xffff); + return aprintf("%s (0x%04X%04X)", status_const, (status >> 16) & 0xffff, + status & 0xffff); } - /* * Curl_sspi_status_msg(SECURITY_STATUS status) * * This function returns a message representing an SSPI status. * It will in any case return a usable string pointer which needs to be freed. */ - -char* -Curl_sspi_status_msg(SECURITY_STATUS status) +char* Curl_sspi_status_msg(SECURITY_STATUS status) { LPSTR format_msg = NULL; char *status_msg = NULL, *status_const = NULL; @@ -307,7 +295,7 @@ Curl_sspi_status_msg(SECURITY_STATUS status) status_msg = strdup(format_msg); LocalFree(format_msg); - /* remove trailing CR+LF */ + /* Remove trailing CR+LF */ if(status_len > 0) { if(status_msg[status_len-1] == '\n') { status_msg[status_len-1] = '\0'; @@ -322,7 +310,7 @@ Curl_sspi_status_msg(SECURITY_STATUS status) status_const = Curl_sspi_status(status); if(status_msg) { - status_msg = curl_maprintf("%s [%s]", status_msg, status_const); + status_msg = aprintf("%s [%s]", status_msg, status_const); free(status_const); } else { -- cgit v1.2.1 From 61d152384e71a152dfbcfb7c18bb5fed753c7435 Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Sun, 10 Jun 2012 23:31:59 +0200 Subject: sspi: Fixed incompatible parameter pointer type in Curl_sspi_version --- lib/curl_sspi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/curl_sspi.c') diff --git a/lib/curl_sspi.c b/lib/curl_sspi.c index 3f4176214..80b929f70 100644 --- a/lib/curl_sspi.c +++ b/lib/curl_sspi.c @@ -124,6 +124,7 @@ CURLcode Curl_sspi_version(int *major, int *minor, int *build, int *special) LPTSTR path = NULL; LPVOID data = NULL; DWORD size, handle; + UINT length; if(!s_hSecDll) return CURLE_FAILED_INIT; @@ -138,7 +139,7 @@ CURLcode Curl_sspi_version(int *major, int *minor, int *build, int *special) data = malloc(size); if(data) { if(GetFileVersionInfo(path, handle, size, data)) { - if(!VerQueryValue(data, "\\", &version_info, &handle)) + if(!VerQueryValue(data, "\\", (LPVOID*) &version_info, &length)) result = CURLE_OUT_OF_MEMORY; } else -- cgit v1.2.1 From c7cc91496176483c53cda82c5906625b46aaf213 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 11 Jun 2012 19:06:43 +0200 Subject: cleanup: remove trailing whitespace --- lib/curl_sspi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/curl_sspi.c') diff --git a/lib/curl_sspi.c b/lib/curl_sspi.c index 80b929f70..b78756740 100644 --- a/lib/curl_sspi.c +++ b/lib/curl_sspi.c @@ -158,7 +158,7 @@ CURLcode Curl_sspi_version(int *major, int *minor, int *build, int *special) if(!result) { if(major) *major = (version_info->dwProductVersionMS >> 16) & 0xffff; - + if(minor) *minor = (version_info->dwProductVersionMS >> 0) & 0xffff; -- cgit v1.2.1 From 764a5e4a50286c27b0fa0c16bc44659880a184a5 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 12 Jun 2012 01:06:48 +0200 Subject: sspi: make Curl_sspi_strerror() libcurl's sspi status code string function --- lib/curl_sspi.c | 146 -------------------------------------------------------- 1 file changed, 146 deletions(-) (limited to 'lib/curl_sspi.c') diff --git a/lib/curl_sspi.c b/lib/curl_sspi.c index b78756740..0d3feb642 100644 --- a/lib/curl_sspi.c +++ b/lib/curl_sspi.c @@ -175,150 +175,4 @@ CURLcode Curl_sspi_version(int *major, int *minor, int *build, int *special) return result; } -/* - * Curl_sspi_status(SECURIY_STATUS status) - * - * This function returns a string representing an SSPI status. - * It will in any case return a usable string pointer which needs to be freed. - */ -char* Curl_sspi_status(SECURITY_STATUS status) -{ - const char* status_const; - - switch(status) { - case SEC_I_COMPLETE_AND_CONTINUE: - status_const = "SEC_I_COMPLETE_AND_CONTINUE"; - break; - case SEC_I_COMPLETE_NEEDED: - status_const = "SEC_I_COMPLETE_NEEDED"; - break; - case SEC_I_CONTINUE_NEEDED: - status_const = "SEC_I_CONTINUE_NEEDED"; - break; - case SEC_I_CONTEXT_EXPIRED: - status_const = "SEC_I_CONTEXT_EXPIRED"; - break; - case SEC_I_INCOMPLETE_CREDENTIALS: - status_const = "SEC_I_INCOMPLETE_CREDENTIALS"; - break; - case SEC_I_RENEGOTIATE: - status_const = "SEC_I_RENEGOTIATE"; - break; - case SEC_E_BUFFER_TOO_SMALL: - status_const = "SEC_E_BUFFER_TOO_SMALL"; - break; - case SEC_E_CONTEXT_EXPIRED: - status_const = "SEC_E_CONTEXT_EXPIRED"; - break; - case SEC_E_CRYPTO_SYSTEM_INVALID: - status_const = "SEC_E_CRYPTO_SYSTEM_INVALID"; - break; - case SEC_E_INCOMPLETE_MESSAGE: - status_const = "SEC_E_INCOMPLETE_MESSAGE"; - break; - case SEC_E_INSUFFICIENT_MEMORY: - status_const = "SEC_E_INSUFFICIENT_MEMORY"; - break; - case SEC_E_INTERNAL_ERROR: - status_const = "SEC_E_INTERNAL_ERROR"; - break; - case SEC_E_INVALID_HANDLE: - status_const = "SEC_E_INVALID_HANDLE"; - break; - case SEC_E_INVALID_TOKEN: - status_const = "SEC_E_INVALID_TOKEN"; - break; - case SEC_E_LOGON_DENIED: - status_const = "SEC_E_LOGON_DENIED"; - break; - case SEC_E_MESSAGE_ALTERED: - status_const = "SEC_E_MESSAGE_ALTERED"; - break; - case SEC_E_NO_AUTHENTICATING_AUTHORITY: - status_const = "SEC_E_NO_AUTHENTICATING_AUTHORITY"; - break; - case SEC_E_NO_CREDENTIALS: - status_const = "SEC_E_NO_CREDENTIALS"; - break; - case SEC_E_NOT_OWNER: - status_const = "SEC_E_NOT_OWNER"; - break; - case SEC_E_OK: - status_const = "SEC_E_OK"; - break; - case SEC_E_OUT_OF_SEQUENCE: - status_const = "SEC_E_OUT_OF_SEQUENCE"; - break; - case SEC_E_QOP_NOT_SUPPORTED: - status_const = "SEC_E_QOP_NOT_SUPPORTED"; - break; - case SEC_E_SECPKG_NOT_FOUND: - status_const = "SEC_E_SECPKG_NOT_FOUND"; - break; - case SEC_E_TARGET_UNKNOWN: - status_const = "SEC_E_TARGET_UNKNOWN"; - break; - case SEC_E_UNKNOWN_CREDENTIALS: - status_const = "SEC_E_UNKNOWN_CREDENTIALS"; - break; - case SEC_E_UNSUPPORTED_FUNCTION: - status_const = "SEC_E_UNSUPPORTED_FUNCTION"; - break; - case SEC_E_WRONG_PRINCIPAL: - status_const = "SEC_E_WRONG_PRINCIPAL"; - break; - default: - status_const = "Unknown error"; - } - - return aprintf("%s (0x%04X%04X)", status_const, (status >> 16) & 0xffff, - status & 0xffff); -} - -/* - * Curl_sspi_status_msg(SECURITY_STATUS status) - * - * This function returns a message representing an SSPI status. - * It will in any case return a usable string pointer which needs to be freed. - */ -char* Curl_sspi_status_msg(SECURITY_STATUS status) -{ - LPSTR format_msg = NULL; - char *status_msg = NULL, *status_const = NULL; - int status_len = 0; - - status_len = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, status, 0, (LPTSTR)&format_msg, 0, NULL); - - if(status_len > 0 && format_msg) { - status_msg = strdup(format_msg); - LocalFree(format_msg); - - /* Remove trailing CR+LF */ - if(status_len > 0) { - if(status_msg[status_len-1] == '\n') { - status_msg[status_len-1] = '\0'; - if(status_len > 1) { - if(status_msg[status_len-2] == '\r') { - status_msg[status_len-2] = '\0'; - } - } - } - } - } - - status_const = Curl_sspi_status(status); - if(status_msg) { - status_msg = aprintf("%s [%s]", status_msg, status_const); - free(status_const); - } - else { - status_msg = status_const; - } - - return status_msg; -} - #endif /* USE_WINDOWS_SSPI */ -- cgit v1.2.1 From 819afe46eeab2c7fa4738e4d77fa2a79a7bb8ebe Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Wed, 13 Jun 2012 15:53:51 +0200 Subject: schannel: remove version number and identify its use with 'schannel' literal Version number is removed in order to make this info consistent with how we do it with other MS and Linux system libraries for which we don't provide this info. Identifier changed from 'WinSSPI' to 'schannel' given that this is the actual provider of the SSL/TLS support. libcurl can still be built with SSPI and without SCHANNEL support. --- lib/curl_sspi.c | 63 --------------------------------------------------------- 1 file changed, 63 deletions(-) (limited to 'lib/curl_sspi.c') diff --git a/lib/curl_sspi.c b/lib/curl_sspi.c index 0d3feb642..cb83809b3 100644 --- a/lib/curl_sspi.c +++ b/lib/curl_sspi.c @@ -112,67 +112,4 @@ void Curl_sspi_global_cleanup(void) } } -/* - * Curl_sspi_version() - * - * This function returns the SSPI library version information. - */ -CURLcode Curl_sspi_version(int *major, int *minor, int *build, int *special) -{ - CURLcode result = CURLE_OK; - VS_FIXEDFILEINFO *version_info = NULL; - LPTSTR path = NULL; - LPVOID data = NULL; - DWORD size, handle; - UINT length; - - if(!s_hSecDll) - return CURLE_FAILED_INIT; - - path = (char *) malloc(MAX_PATH); - if(!path) - return CURLE_OUT_OF_MEMORY; - - if(GetModuleFileName(s_hSecDll, path, MAX_PATH)) { - size = GetFileVersionInfoSize(path, &handle); - if(size) { - data = malloc(size); - if(data) { - if(GetFileVersionInfo(path, handle, size, data)) { - if(!VerQueryValue(data, "\\", (LPVOID*) &version_info, &length)) - result = CURLE_OUT_OF_MEMORY; - } - else - result = CURLE_OUT_OF_MEMORY; - } - else - result = CURLE_OUT_OF_MEMORY; - } - else - result = CURLE_OUT_OF_MEMORY; - } - else - result = CURLE_OUT_OF_MEMORY; - - /* Set the out parameters */ - if(!result) { - if(major) - *major = (version_info->dwProductVersionMS >> 16) & 0xffff; - - if(minor) - *minor = (version_info->dwProductVersionMS >> 0) & 0xffff; - - if(build) - *build = (version_info->dwProductVersionLS >> 16) & 0xffff; - - if(special) - *special = (version_info->dwProductVersionLS >> 0) & 0xffff; - } - - Curl_safefree(data); - Curl_safefree(path); - - return result; -} - #endif /* USE_WINDOWS_SSPI */ -- cgit v1.2.1 From 46480bb9a1569eaf156012f33e3e7e8c3de18f87 Mon Sep 17 00:00:00 2001 From: Mark Salisbury Date: Fri, 15 Jun 2012 18:05:11 +0200 Subject: SSPI related code: Unicode support for WinCE SSPI related code now compiles with ANSI and WCHAR versions of security methods (WinCE requires WCHAR versions of methods). Pulled UTF8 to WCHAR conversion methods out of idn_win32.c into their own file. curl_sasl.c - include curl_memory.h to use correct memory functions. getenv.c and telnet.c - WinCE compatibility fix With some committer adjustments --- lib/curl_sspi.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'lib/curl_sspi.c') diff --git a/lib/curl_sspi.c b/lib/curl_sspi.c index cb83809b3..c3c41ec2f 100644 --- a/lib/curl_sspi.c +++ b/lib/curl_sspi.c @@ -36,13 +36,24 @@ #include "memdebug.h" /* We use our own typedef here since some headers might lack these */ -typedef PSecurityFunctionTableA (APIENTRY *INITSECURITYINTERFACE_FN_A)(VOID); +typedef PSecurityFunctionTable (APIENTRY *INITSECURITYINTERFACE_FN)(VOID); + +/* See definition of SECURITY_ENTRYPOINT in sspi.h */ +#ifdef UNICODE +# ifdef _WIN32_WCE +# define SECURITYENTRYPOINT L"InitSecurityInterfaceW" +# else +# define SECURITYENTRYPOINT "InitSecurityInterfaceW" +# endif +#else +# define SECURITYENTRYPOINT "InitSecurityInterfaceA" +#endif /* Handle of security.dll or secur32.dll, depending on Windows version */ HMODULE s_hSecDll = NULL; /* Pointer to SSPI dispatch table */ -PSecurityFunctionTableA s_pSecFn = NULL; +PSecurityFunctionTable s_pSecFn = NULL; /* * Curl_sspi_global_init() @@ -58,7 +69,7 @@ PSecurityFunctionTableA s_pSecFn = NULL; CURLcode Curl_sspi_global_init(void) { OSVERSIONINFO osver; - INITSECURITYINTERFACE_FN_A pInitSecurityInterface; + INITSECURITYINTERFACE_FN pInitSecurityInterface; /* If security interface is not yet initialized try to do this */ if(!s_hSecDll) { @@ -76,15 +87,15 @@ CURLcode Curl_sspi_global_init(void) /* Load SSPI dll into the address space of the calling process */ if(osver.dwPlatformId == VER_PLATFORM_WIN32_NT && osver.dwMajorVersion == 4) - s_hSecDll = LoadLibrary("security.dll"); + s_hSecDll = LoadLibrary(TEXT("security.dll")); else - s_hSecDll = LoadLibrary("secur32.dll"); + s_hSecDll = LoadLibrary(TEXT("secur32.dll")); if(!s_hSecDll) return CURLE_FAILED_INIT; /* Get address of the InitSecurityInterfaceA function from the SSPI dll */ - pInitSecurityInterface = (INITSECURITYINTERFACE_FN_A) - GetProcAddress(s_hSecDll, "InitSecurityInterfaceA"); + pInitSecurityInterface = (INITSECURITYINTERFACE_FN) + GetProcAddress(s_hSecDll, SECURITYENTRYPOINT); if(!pInitSecurityInterface) return CURLE_FAILED_INIT; -- cgit v1.2.1