1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at http://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
25 #ifdef USE_WINDOWS_SSPI
27 #include <curl/curl.h>
29 #include "curl_sspi.h"
31 #define _MPRINTF_REPLACE /* use our functions only */
32 #include <curl/mprintf.h>
34 #include "curl_memory.h"
35 /* The last #include file should be: */
39 /* Handle of security.dll or secur32.dll, depending on Windows version */
40 HMODULE s_hSecDll = NULL;
42 /* Pointer to SSPI dispatch table */
43 PSecurityFunctionTableA s_pSecFn = NULL;
47 * Curl_sspi_global_init()
49 * This is used to load the Security Service Provider Interface (SSPI)
50 * dynamic link library portably across all Windows versions, without
51 * the need to directly link libcurl, nor the application using it, at
54 * Once this function has been executed, Windows SSPI functions can be
55 * called through the Security Service Provider Interface dispatch table.
59 Curl_sspi_global_init(void)
62 INIT_SECURITY_INTERFACE_A pInitSecurityInterface;
64 /* If security interface is not yet initialized try to do this */
65 if(s_hSecDll == NULL) {
67 /* Find out Windows version */
68 memset(&osver, 0, sizeof(osver));
69 osver.dwOSVersionInfoSize = sizeof(osver);
70 if(! GetVersionEx(&osver))
71 return CURLE_FAILED_INIT;
73 /* Security Service Provider Interface (SSPI) functions are located in
74 * security.dll on WinNT 4.0 and in secur32.dll on Win9x. Win2K and XP
75 * have both these DLLs (security.dll forwards calls to secur32.dll) */
77 /* Load SSPI dll into the address space of the calling process */
78 if(osver.dwPlatformId == VER_PLATFORM_WIN32_NT
79 && osver.dwMajorVersion == 4)
80 s_hSecDll = LoadLibrary("security.dll");
82 s_hSecDll = LoadLibrary("secur32.dll");
84 return CURLE_FAILED_INIT;
86 /* Get address of the InitSecurityInterfaceA function from the SSPI dll */
87 pInitSecurityInterface = (INIT_SECURITY_INTERFACE_A)
88 GetProcAddress(s_hSecDll, "InitSecurityInterfaceA");
89 if(! pInitSecurityInterface)
90 return CURLE_FAILED_INIT;
92 /* Get pointer to Security Service Provider Interface dispatch table */
93 s_pSecFn = pInitSecurityInterface();
95 return CURLE_FAILED_INIT;
103 * Curl_sspi_global_cleanup()
105 * This deinitializes the Security Service Provider Interface from libcurl.
109 Curl_sspi_global_cleanup(void)
112 FreeLibrary(s_hSecDll);
118 #endif /* USE_WINDOWS_SSPI */