Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "curl_setup.h"
00024
00025 #ifdef USE_WINDOWS_SSPI
00026
00027 #include <curl/curl.h>
00028 #include "curl_sspi.h"
00029 #include "curl_multibyte.h"
00030 #include "system_win32.h"
00031 #include "warnless.h"
00032
00033
00034 #include "curl_memory.h"
00035 #include "memdebug.h"
00036
00037
00038 typedef PSecurityFunctionTable (APIENTRY *INITSECURITYINTERFACE_FN)(VOID);
00039
00040
00041 #ifdef UNICODE
00042 # ifdef _WIN32_WCE
00043 # define SECURITYENTRYPOINT L"InitSecurityInterfaceW"
00044 # else
00045 # define SECURITYENTRYPOINT "InitSecurityInterfaceW"
00046 # endif
00047 #else
00048 # define SECURITYENTRYPOINT "InitSecurityInterfaceA"
00049 #endif
00050
00051
00052 HMODULE s_hSecDll = NULL;
00053
00054
00055 PSecurityFunctionTable s_pSecFn = NULL;
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 CURLcode Curl_sspi_global_init(void)
00075 {
00076 INITSECURITYINTERFACE_FN pInitSecurityInterface;
00077
00078
00079 if(!s_hSecDll) {
00080
00081
00082
00083
00084
00085 if(Curl_verify_windows_version(4, 0, PLATFORM_WINNT, VERSION_EQUAL))
00086 s_hSecDll = Curl_load_library(TEXT("security.dll"));
00087 else
00088 s_hSecDll = Curl_load_library(TEXT("secur32.dll"));
00089 if(!s_hSecDll)
00090 return CURLE_FAILED_INIT;
00091
00092
00093 pInitSecurityInterface = (INITSECURITYINTERFACE_FN)
00094 GetProcAddress(s_hSecDll, SECURITYENTRYPOINT);
00095 if(!pInitSecurityInterface)
00096 return CURLE_FAILED_INIT;
00097
00098
00099 s_pSecFn = pInitSecurityInterface();
00100 if(!s_pSecFn)
00101 return CURLE_FAILED_INIT;
00102 }
00103
00104 return CURLE_OK;
00105 }
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 void Curl_sspi_global_cleanup(void)
00117 {
00118 if(s_hSecDll) {
00119 FreeLibrary(s_hSecDll);
00120 s_hSecDll = NULL;
00121 s_pSecFn = NULL;
00122 }
00123 }
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 CURLcode Curl_create_sspi_identity(const char *userp, const char *passwdp,
00140 SEC_WINNT_AUTH_IDENTITY *identity)
00141 {
00142 xcharp_u useranddomain;
00143 xcharp_u user, dup_user;
00144 xcharp_u domain, dup_domain;
00145 xcharp_u passwd, dup_passwd;
00146 size_t domlen = 0;
00147
00148 domain.const_tchar_ptr = TEXT("");
00149
00150
00151 memset(identity, 0, sizeof(*identity));
00152
00153 useranddomain.tchar_ptr = Curl_convert_UTF8_to_tchar((char *)userp);
00154 if(!useranddomain.tchar_ptr)
00155 return CURLE_OUT_OF_MEMORY;
00156
00157 user.const_tchar_ptr = _tcschr(useranddomain.const_tchar_ptr, TEXT('\\'));
00158 if(!user.const_tchar_ptr)
00159 user.const_tchar_ptr = _tcschr(useranddomain.const_tchar_ptr, TEXT('/'));
00160
00161 if(user.tchar_ptr) {
00162 domain.tchar_ptr = useranddomain.tchar_ptr;
00163 domlen = user.tchar_ptr - useranddomain.tchar_ptr;
00164 user.tchar_ptr++;
00165 }
00166 else {
00167 user.tchar_ptr = useranddomain.tchar_ptr;
00168 domain.const_tchar_ptr = TEXT("");
00169 domlen = 0;
00170 }
00171
00172
00173 dup_user.tchar_ptr = _tcsdup(user.tchar_ptr);
00174 if(!dup_user.tchar_ptr) {
00175 Curl_unicodefree(useranddomain.tchar_ptr);
00176 return CURLE_OUT_OF_MEMORY;
00177 }
00178 identity->User = dup_user.tbyte_ptr;
00179 identity->UserLength = curlx_uztoul(_tcslen(dup_user.tchar_ptr));
00180 dup_user.tchar_ptr = NULL;
00181
00182
00183 dup_domain.tchar_ptr = malloc(sizeof(TCHAR) * (domlen + 1));
00184 if(!dup_domain.tchar_ptr) {
00185 Curl_unicodefree(useranddomain.tchar_ptr);
00186 return CURLE_OUT_OF_MEMORY;
00187 }
00188 _tcsncpy(dup_domain.tchar_ptr, domain.tchar_ptr, domlen);
00189 *(dup_domain.tchar_ptr + domlen) = TEXT('\0');
00190 identity->Domain = dup_domain.tbyte_ptr;
00191 identity->DomainLength = curlx_uztoul(domlen);
00192 dup_domain.tchar_ptr = NULL;
00193
00194 Curl_unicodefree(useranddomain.tchar_ptr);
00195
00196
00197 passwd.tchar_ptr = Curl_convert_UTF8_to_tchar((char *)passwdp);
00198 if(!passwd.tchar_ptr)
00199 return CURLE_OUT_OF_MEMORY;
00200 dup_passwd.tchar_ptr = _tcsdup(passwd.tchar_ptr);
00201 if(!dup_passwd.tchar_ptr) {
00202 Curl_unicodefree(passwd.tchar_ptr);
00203 return CURLE_OUT_OF_MEMORY;
00204 }
00205 identity->Password = dup_passwd.tbyte_ptr;
00206 identity->PasswordLength = curlx_uztoul(_tcslen(dup_passwd.tchar_ptr));
00207 dup_passwd.tchar_ptr = NULL;
00208
00209 Curl_unicodefree(passwd.tchar_ptr);
00210
00211
00212 identity->Flags = SECFLAG_WINNT_AUTH_IDENTITY;
00213
00214 return CURLE_OK;
00215 }
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226 void Curl_sspi_free_identity(SEC_WINNT_AUTH_IDENTITY *identity)
00227 {
00228 if(identity) {
00229 Curl_safefree(identity->User);
00230 Curl_safefree(identity->Password);
00231 Curl_safefree(identity->Domain);
00232 }
00233 }
00234
00235 #endif