Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

unicode NTLM SSPI: cleanup

Reduce the number of #ifdef UNICODE directives used in source files.
  • Loading branch information...
commit e77d8670685d38d80c940877a4fdfa3382c4d6cc 1 parent 1b27bb4
yangtse yangtse authored
14 lib/config-win32ce.h
... ... @@ -1,5 +1,5 @@
1   -#ifndef __LIB_CONFIG_WIN32CE_H
2   -#define __LIB_CONFIG_WIN32CE_H
  1 +#ifndef HEADER_CURL_CONFIG_WIN32CE_H
  2 +#define HEADER_CURL_CONFIG_WIN32CE_H
3 3 /***************************************************************************
4 4 * _ _ ____ _
5 5 * Project ___| | | | _ \| |
@@ -427,6 +427,14 @@
427 427 /* WinCE */
428 428 /* ---------------------------------------------------------------- */
429 429
  430 +#ifndef UNICODE
  431 +# define UNICODE
  432 +#endif
  433 +
  434 +#ifndef _UNICODE
  435 +# define _UNICODE
  436 +#endif
  437 +
430 438 #define CURL_DISABLE_FILE 1
431 439 #define CURL_DISABLE_TELNET 1
432 440 #define CURL_DISABLE_LDAP 1
@@ -437,4 +445,4 @@
437 445
438 446 extern int stat(const char *path,struct stat *buffer );
439 447
440   -#endif /* __LIB_CONFIG_WIN32CE_H */
  448 +#endif /* HEADER_CURL_CONFIG_WIN32CE_H */
25 lib/curl_multibyte.c
@@ -22,8 +22,7 @@
22 22
23 23 #include "setup.h"
24 24
25   -#if defined(USE_WIN32_IDN) || \
26   - (defined(USE_WINDOWS_SSPI) && (defined(_WIN32_WCE) || defined(UNICODE)))
  25 +#if defined(USE_WIN32_IDN) || (defined(USE_WINDOWS_SSPI) && defined(UNICODE))
27 26
28 27 /*
29 28 * MultiByte conversions using Windows kernel32 library.
@@ -45,13 +44,12 @@ wchar_t *Curl_convert_UTF8_to_wchar(const char *str_utf8)
45 44 if(str_utf8) {
46 45 int str_w_len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS,
47 46 str_utf8, -1, NULL, 0);
48   - if(str_w_len) {
  47 + if(str_w_len > 0) {
49 48 str_w = malloc(str_w_len * sizeof(wchar_t));
50 49 if(str_w) {
51 50 if(MultiByteToWideChar(CP_UTF8, 0, str_utf8, -1, str_w,
52 51 str_w_len) == 0) {
53   - free(str_w);
54   - str_w = NULL;
  52 + Curl_safefree(str_w);
55 53 }
56 54 }
57 55 }
@@ -60,30 +58,25 @@ wchar_t *Curl_convert_UTF8_to_wchar(const char *str_utf8)
60 58 return str_w;
61 59 }
62 60
63   -const char *Curl_convert_wchar_to_UTF8(const wchar_t *str_w)
  61 +char *Curl_convert_wchar_to_UTF8(const wchar_t *str_w)
64 62 {
65 63 char *str_utf8 = NULL;
66 64
67 65 if(str_w) {
68   - size_t str_utf8_len = WideCharToMultiByte(CP_UTF8, 0, str_w, -1, NULL,
69   - 0, NULL, NULL);
70   - if(str_utf8_len) {
  66 + int str_utf8_len = WideCharToMultiByte(CP_UTF8, 0, str_w, -1, NULL,
  67 + 0, NULL, NULL);
  68 + if(str_utf8_len > 0) {
71 69 str_utf8 = malloc(str_utf8_len * sizeof(wchar_t));
72 70 if(str_utf8) {
73 71 if(WideCharToMultiByte(CP_UTF8, 0, str_w, -1, str_utf8, str_utf8_len,
74 72 NULL, FALSE) == 0) {
75   - (void) GetLastError();
76   - free((void *)str_utf8);
77   - str_utf8 = NULL;
  73 + Curl_safefree(str_utf8);
78 74 }
79 75 }
80 76 }
81   - else {
82   - (void) GetLastError();
83   - }
84 77 }
85 78
86 79 return str_utf8;
87 80 }
88 81
89   -#endif /* USE_WIN32_IDN || (USE_WINDOWS_SSPI && (_WIN32_WCE || UNICODE)) */
  82 +#endif /* USE_WIN32_IDN || (USE_WINDOWS_SSPI && UNICODE) */
62 lib/curl_multibyte.h
@@ -23,18 +23,68 @@
23 23 ***************************************************************************/
24 24 #include "setup.h"
25 25
26   -#if defined(USE_WIN32_IDN) || \
27   - (defined(USE_WINDOWS_SSPI) && (defined(_WIN32_WCE) || defined(UNICODE)))
  26 +#if defined(USE_WIN32_IDN) || (defined(USE_WINDOWS_SSPI) && defined(UNICODE))
28 27
29 28 /*
30 29 * MultiByte conversions using Windows kernel32 library.
31 30 */
32 31
33   -#include <tchar.h>
34   -
35 32 wchar_t *Curl_convert_UTF8_to_wchar(const char *str_utf8);
36   -const char *Curl_convert_wchar_to_UTF8(const wchar_t *str_w);
  33 +char *Curl_convert_wchar_to_UTF8(const wchar_t *str_w);
  34 +
  35 +#endif /* USE_WIN32_IDN || (USE_WINDOWS_SSPI && UNICODE) */
  36 +
  37 +
  38 +#if defined(USE_WIN32_IDN) || defined(USE_WINDOWS_SSPI)
  39 +
  40 +/*
  41 + * Macros Curl_convert_UTF8_to_tchar(), Curl_convert_tchar_to_UTF8()
  42 + * and Curl_unicodefree() main purpose is to minimize the number of
  43 + * preprocessor conditional directives needed by code using these
  44 + * to differentiate UNICODE from non-UNICODE builds.
  45 + *
  46 + * When building with UNICODE defined, this two macros
  47 + * Curl_convert_UTF8_to_tchar() and Curl_convert_tchar_to_UTF8()
  48 + * return a pointer to a newly allocated memory area holding result.
  49 + * When the result is no longer needed, allocated memory is intended
  50 + * to be free'ed with Curl_unicodefree().
  51 + *
  52 + * When building without UNICODE defined, this macros
  53 + * Curl_convert_UTF8_to_tchar() and Curl_convert_tchar_to_UTF8()
  54 + * return the pointer received as argument. Curl_unicodefree() does
  55 + * no actual free'ing of this pointer it is simply set to NULL.
  56 + */
  57 +
  58 +#ifdef UNICODE
  59 +
  60 +#define Curl_convert_UTF8_to_tchar(ptr) Curl_convert_UTF8_to_wchar((ptr))
  61 +#define Curl_convert_tchar_to_UTF8(ptr) Curl_convert_wchar_to_UTF8((ptr))
  62 +#define Curl_unicodefree(ptr) \
  63 + do {if((ptr)) {free((ptr)); (ptr) = NULL;}} WHILE_FALSE
  64 +
  65 +typedef union {
  66 + unsigned short *tchar_ptr;
  67 + const unsigned short *const_tchar_ptr;
  68 + unsigned short *tbyte_ptr;
  69 + const unsigned short *const_tbyte_ptr;
  70 +} xcharp_u;
  71 +
  72 +#else
  73 +
  74 +#define Curl_convert_UTF8_to_tchar(ptr) (ptr)
  75 +#define Curl_convert_tchar_to_UTF8(ptr) (ptr)
  76 +#define Curl_unicodefree(ptr) \
  77 + do {(ptr) = NULL;} WHILE_FALSE
  78 +
  79 +typedef union {
  80 + char *tchar_ptr;
  81 + const char *const_tchar_ptr;
  82 + unsigned char *tbyte_ptr;
  83 + const unsigned char *const_tbyte_ptr;
  84 +} xcharp_u;
  85 +
  86 +#endif /* UNICODE */
37 87
38   -#endif /* USE_WIN32_IDN || (USE_WINDOWS_SSPI && (_WIN32_WCE || UNICODE)) */
  88 +#endif /* USE_WIN32_IDN || USE_WINDOWS_SSPI */
39 89
40 90 #endif /* HEADER_CURL_MULTIBYTE_H */
130 lib/curl_ntlm_msgs.c
@@ -33,10 +33,6 @@
33 33
34 34 #define DEBUG_ME 0
35 35
36   -#ifdef USE_WINDOWS_SSPI
37   -# include <tchar.h>
38   -#endif
39   -
40 36 #include "urldata.h"
41 37 #include "non-ascii.h"
42 38 #include "sendf.h"
@@ -44,6 +40,7 @@
44 40 #include "curl_ntlm_core.h"
45 41 #include "curl_gethostname.h"
46 42 #include "curl_multibyte.h"
  43 +#include "warnless.h"
47 44 #include "curl_memory.h"
48 45
49 46 #ifdef USE_WINDOWS_SSPI
@@ -242,7 +239,7 @@ CURLcode Curl_ntlm_decode_type2_message(struct SessionHandle *data,
242 239 free(buffer);
243 240 return CURLE_OUT_OF_MEMORY;
244 241 }
245   - ntlm->n_type_2 = (unsigned long)size;
  242 + ntlm->n_type_2 = curlx_uztoul(size);
246 243 memcpy(ntlm->type_2, buffer, size);
247 244 #else
248 245 ntlm->flags = 0;
@@ -276,19 +273,16 @@ CURLcode Curl_ntlm_decode_type2_message(struct SessionHandle *data,
276 273 #ifdef USE_WINDOWS_SSPI
277 274 void Curl_ntlm_sspi_cleanup(struct ntlmdata *ntlm)
278 275 {
279   - if(ntlm->type_2) {
280   - free(ntlm->type_2);
281   - ntlm->type_2 = NULL;
282   - }
  276 + Curl_safefree(ntlm->type_2);
283 277 if(ntlm->has_handles) {
284 278 s_pSecFn->DeleteSecurityContext(&ntlm->c_handle);
285 279 s_pSecFn->FreeCredentialsHandle(&ntlm->handle);
286 280 ntlm->has_handles = 0;
287 281 }
288 282 if(ntlm->p_identity) {
289   - if(ntlm->identity.User) free(ntlm->identity.User);
290   - if(ntlm->identity.Password) free(ntlm->identity.Password);
291   - if(ntlm->identity.Domain) free(ntlm->identity.Domain);
  283 + Curl_safefree(ntlm->identity.User);
  284 + Curl_safefree(ntlm->identity.Password);
  285 + Curl_safefree(ntlm->identity.Domain);
292 286 ntlm->p_identity = NULL;
293 287 }
294 288 }
@@ -355,87 +349,83 @@ CURLcode Curl_ntlm_create_type1_message(const char *userp,
355 349 SecBufferDesc desc;
356 350 SECURITY_STATUS status;
357 351 unsigned long attrs;
358   - const TCHAR *useranddomain;
359   - const TCHAR *user;
360   - const TCHAR *domain = TEXT("");
  352 + xcharp_u useranddomain;
  353 + xcharp_u user, dup_user;
  354 + xcharp_u domain, dup_domain;
  355 + xcharp_u passwd, dup_passwd;
361 356 size_t domlen = 0;
362 357 TimeStamp tsDummy; /* For Windows 9x compatibility of SSPI calls */
363 358
  359 + domain.const_tchar_ptr = TEXT("");
  360 +
364 361 Curl_ntlm_sspi_cleanup(ntlm);
365 362
366 363 if(userp && *userp) {
367   -#ifdef UNICODE
368   - useranddomain = Curl_convert_UTF8_to_wchar(userp);
369   - if(useranddomain == NULL)
  364 +
  365 + /* null initialize ntlm identity's data to allow proper cleanup */
  366 + ntlm->p_identity = &ntlm->identity;
  367 + memset(ntlm->p_identity, 0, sizeof(*ntlm->p_identity));
  368 +
  369 + useranddomain.tchar_ptr = Curl_convert_UTF8_to_tchar((char *)userp);
  370 + if(!useranddomain.tchar_ptr)
370 371 return CURLE_OUT_OF_MEMORY;
371   -#else
372   - useranddomain = userp;
373   -#endif
374 372
375   - user = _tcschr(useranddomain, TEXT('\\'));
376   - if(!user)
377   - user = _tcschr(useranddomain, TEXT('/'));
  373 + user.const_tchar_ptr = _tcschr(useranddomain.const_tchar_ptr, TEXT('\\'));
  374 + if(!user.const_tchar_ptr)
  375 + user.const_tchar_ptr = _tcschr(useranddomain.const_tchar_ptr, TEXT('/'));
378 376
379   - if(user) {
380   - domain = useranddomain;
381   - domlen = user - useranddomain;
382   - user++;
  377 + if(user.tchar_ptr) {
  378 + domain.tchar_ptr = useranddomain.tchar_ptr;
  379 + domlen = user.tchar_ptr - useranddomain.tchar_ptr;
  380 + user.tchar_ptr++;
383 381 }
384 382 else {
385   - user = useranddomain;
386   - domain = TEXT("");
  383 + user.tchar_ptr = useranddomain.tchar_ptr;
  384 + domain.const_tchar_ptr = TEXT("");
387 385 domlen = 0;
388 386 }
389 387
390   - /* note: initialize all of this before doing the mallocs so that
391   - * it can be cleaned up later without leaking memory.
392   - */
393   - ntlm->p_identity = &ntlm->identity;
394   - memset(ntlm->p_identity, 0, sizeof(*ntlm->p_identity));
395   -
396   -#ifdef UNICODE
397   - if((ntlm->identity.User = (unsigned short *)_wcsdup(user)) == NULL) {
398   - free((void *)useranddomain);
  388 + /* setup ntlm identity's user and length */
  389 + dup_user.tchar_ptr = _tcsdup(user.tchar_ptr);
  390 + if(!dup_user.tchar_ptr) {
  391 + Curl_unicodefree(useranddomain.tchar_ptr);
399 392 return CURLE_OUT_OF_MEMORY;
400 393 }
401   -#else
402   - if((ntlm->identity.User = (unsigned char *)strdup(user)) == NULL)
403   - return CURLE_OUT_OF_MEMORY;
404   -#endif
405   - ntlm->identity.UserLength = (unsigned long)_tcslen(user);
406   -
407   - ntlm->identity.Domain = malloc(sizeof(TCHAR) * (domlen + 1));
408   - if(ntlm->identity.Domain == NULL) {
409   -#ifdef UNICODE
410   - free((void *)useranddomain);
411   -#endif
  394 + ntlm->identity.User = dup_user.tbyte_ptr;
  395 + ntlm->identity.UserLength = curlx_uztoul(_tcslen(dup_user.tchar_ptr));
  396 + dup_user.tchar_ptr = NULL;
  397 +
  398 + /* setup ntlm identity's domain and length */
  399 + dup_domain.tchar_ptr = malloc(sizeof(TCHAR) * (domlen + 1));
  400 + if(!dup_domain.tchar_ptr) {
  401 + Curl_unicodefree(useranddomain.tchar_ptr);
412 402 return CURLE_OUT_OF_MEMORY;
413 403 }
414   - _tcsncpy((TCHAR *)ntlm->identity.Domain, domain, domlen);
415   - ntlm->identity.Domain[domlen] = TEXT('\0');
416   - ntlm->identity.DomainLength = (unsigned long)domlen;
  404 + _tcsncpy(dup_domain.tchar_ptr, domain.tchar_ptr, domlen);
  405 + *(dup_domain.tchar_ptr + domlen) = TEXT('\0');
  406 + ntlm->identity.Domain = dup_domain.tbyte_ptr;
  407 + ntlm->identity.DomainLength = curlx_uztoul(domlen);
  408 + dup_domain.tchar_ptr = NULL;
417 409
418   -#ifdef UNICODE
419   - free((void *)useranddomain);
420   -#endif
  410 + Curl_unicodefree(useranddomain.tchar_ptr);
421 411
422   -#ifdef UNICODE
423   - ntlm->identity.Password = (unsigned short *)
424   - Curl_convert_UTF8_to_wchar(passwdp);
425   - if(ntlm->identity.Password == NULL)
  412 + /* setup ntlm identity's password and length */
  413 + passwd.tchar_ptr = Curl_convert_UTF8_to_tchar((char *)passwdp);
  414 + if(!passwd.tchar_ptr)
426 415 return CURLE_OUT_OF_MEMORY;
427   -#else
428   - if((ntlm->identity.Password = (unsigned char *)strdup(passwdp)) == NULL)
  416 + dup_passwd.tchar_ptr = _tcsdup(passwd.tchar_ptr);
  417 + if(!dup_passwd.tchar_ptr) {
  418 + Curl_unicodefree(passwd.tchar_ptr);
429 419 return CURLE_OUT_OF_MEMORY;
430   -#endif
431   - ntlm->identity.PasswordLength =
432   - (unsigned long)_tcslen((TCHAR *)ntlm->identity.Password);
  420 + }
  421 + ntlm->identity.Password = dup_passwd.tbyte_ptr;
  422 + ntlm->identity.PasswordLength = curlx_uztoul(_tcslen(dup_passwd.tchar_ptr));
  423 + dup_passwd.tchar_ptr = NULL;
433 424
434   -#ifdef UNICODE
435   - ntlm->identity.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
436   -#else
437   - ntlm->identity.Flags = SEC_WINNT_AUTH_IDENTITY_ANSI;
438   -#endif
  425 + Curl_unicodefree(passwd.tchar_ptr);
  426 +
  427 + /* setup ntlm identity's flags */
  428 + ntlm->identity.Flags = SECFLAG_WINNT_AUTH_IDENTITY;
439 429 }
440 430 else
441 431 ntlm->p_identity = NULL;
10 lib/curl_ntlm_msgs.h
@@ -7,7 +7,7 @@
7 7 * | (__| |_| | _ <| |___
8 8 * \___|\___/|_| \_\_____|
9 9 *
10   - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
  10 + * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
11 11 *
12 12 * This software is licensed as described in the file COPYING, which
13 13 * you should have received as part of this distribution. The terms
@@ -163,6 +163,14 @@ void Curl_ntlm_sspi_cleanup(struct ntlmdata *ntlm);
163 163 #define NTLMFLAG_NEGOTIATE_56 (1<<31)
164 164 /* Indicates that 56-bit encryption is supported. */
165 165
  166 +#ifdef UNICODE
  167 +# define SECFLAG_WINNT_AUTH_IDENTITY \
  168 + (unsigned long)SEC_WINNT_AUTH_IDENTITY_UNICODE
  169 +#else
  170 +# define SECFLAG_WINNT_AUTH_IDENTITY \
  171 + (unsigned long)SEC_WINNT_AUTH_IDENTITY_ANSI
  172 +#endif
  173 +
166 174 #endif /* BUILDING_CURL_NTLM_MSGS_C */
167 175
168 176 #endif /* USE_NTLM */
71 lib/curl_schannel.c
@@ -189,7 +189,7 @@ schannel_connect_step1(struct connectdata *conn, int sockindex)
189 189 memset(connssl->cred, 0, sizeof(struct curl_schannel_cred));
190 190
191 191 /* http://msdn.microsoft.com/en-us/library/windows/desktop/aa374716.aspx */
192   - sspi_status = s_pSecFn->AcquireCredentialsHandle(NULL, (void *)UNISP_NAME,
  192 + sspi_status = s_pSecFn->AcquireCredentialsHandle(NULL, (TCHAR *)UNISP_NAME,
193 193 SECPKG_CRED_OUTBOUND, NULL, &schannel_cred, NULL, NULL,
194 194 &connssl->cred->cred_handle, &connssl->cred->time_stamp);
195 195
@@ -222,13 +222,9 @@ schannel_connect_step1(struct connectdata *conn, int sockindex)
222 222 }
223 223 memset(connssl->ctxt, 0, sizeof(struct curl_schannel_ctxt));
224 224
225   -#ifdef UNICODE
226   - host_name = Curl_convert_UTF8_to_wchar(conn->host.name);
  225 + host_name = Curl_convert_UTF8_to_tchar(conn->host.name);
227 226 if(!host_name)
228 227 return CURLE_OUT_OF_MEMORY;
229   -#else
230   - host_name = conn->host.name;
231   -#endif
232 228
233 229 /* http://msdn.microsoft.com/en-us/library/windows/desktop/aa375924.aspx */
234 230
@@ -237,9 +233,7 @@ schannel_connect_step1(struct connectdata *conn, int sockindex)
237 233 connssl->req_flags, 0, 0, NULL, 0, &connssl->ctxt->ctxt_handle,
238 234 &outbuf_desc, &connssl->ret_flags, &connssl->ctxt->time_stamp);
239 235
240   -#ifdef UNICODE
241   - Curl_safefree(host_name);
242   -#endif
  236 + Curl_unicodefree(host_name);
243 237
244 238 if(sspi_status != SEC_I_CONTINUE_NEEDED) {
245 239 if(sspi_status == SEC_E_WRONG_PRINCIPAL)
@@ -372,13 +366,9 @@ schannel_connect_step2(struct connectdata *conn, int sockindex)
372 366 memcpy(inbuf[0].pvBuffer, connssl->encdata_buffer,
373 367 connssl->encdata_offset);
374 368
375   -#ifdef UNICODE
376   - host_name = Curl_convert_UTF8_to_wchar(conn->host.name);
  369 + host_name = Curl_convert_UTF8_to_tchar(conn->host.name);
377 370 if(!host_name)
378 371 return CURLE_OUT_OF_MEMORY;
379   -#else
380   - host_name = conn->host.name;
381   -#endif
382 372
383 373 /* http://msdn.microsoft.com/en-us/library/windows/desktop/aa375924.aspx */
384 374
@@ -387,9 +377,7 @@ schannel_connect_step2(struct connectdata *conn, int sockindex)
387 377 host_name, connssl->req_flags, 0, 0, &inbuf_desc, 0, NULL,
388 378 &outbuf_desc, &connssl->ret_flags, &connssl->ctxt->time_stamp);
389 379
390   -#ifdef UNICODE
391   - Curl_safefree(host_name);
392   -#endif
  380 + Curl_unicodefree(host_name);
393 381
394 382 /* free buffer for received handshake data */
395 383 Curl_safefree(inbuf[0].pvBuffer);
@@ -1095,13 +1083,9 @@ int Curl_schannel_shutdown(struct connectdata *conn, int sockindex)
1095 1083 failf(data, "schannel: ApplyControlToken failure: %s",
1096 1084 Curl_sspi_strerror(conn, sspi_status));
1097 1085
1098   -#ifdef UNICODE
1099   - host_name = Curl_convert_UTF8_to_wchar(conn->host.name);
  1086 + host_name = Curl_convert_UTF8_to_tchar(conn->host.name);
1100 1087 if(!host_name)
1101 1088 return CURLE_OUT_OF_MEMORY;
1102   -#else
1103   - host_name = conn->host.name;
1104   -#endif
1105 1089
1106 1090 /* setup output buffer */
1107 1091 InitSecBuffer(&outbuf, SECBUFFER_EMPTY, NULL, 0);
@@ -1121,9 +1105,7 @@ int Curl_schannel_shutdown(struct connectdata *conn, int sockindex)
1121 1105 &connssl->ret_flags,
1122 1106 &connssl->ctxt->time_stamp);
1123 1107
1124   -#ifdef UNICODE
1125   - Curl_safefree(host_name);
1126   -#endif
  1108 + Curl_unicodefree(host_name);
1127 1109
1128 1110 if((sspi_status == SEC_E_OK) || (sspi_status == SEC_I_CONTEXT_EXPIRED)) {
1129 1111 /* send close message which is in output buffer */
@@ -1230,7 +1212,7 @@ static CURLcode verify_certificate(struct connectdata *conn, int sockindex)
1230 1212
1231 1213 if(result == CURLE_OK) {
1232 1214 CERT_SIMPLE_CHAIN *pSimpleChain = pChainContext->rgpChain[0];
1233   - DWORD dwTrustErrorMask = ~(CERT_TRUST_IS_NOT_TIME_NESTED|
  1215 + DWORD dwTrustErrorMask = ~(DWORD)(CERT_TRUST_IS_NOT_TIME_NESTED|
1234 1216 CERT_TRUST_REVOCATION_STATUS_UNKNOWN);
1235 1217 dwTrustErrorMask &= pSimpleChain->TrustStatus.dwErrorStatus;
1236 1218 if(dwTrustErrorMask) {
@@ -1255,34 +1237,41 @@ static CURLcode verify_certificate(struct connectdata *conn, int sockindex)
1255 1237 infof(data, "warning: ignoring unsupported value (1) ssl.verifyhost\n");
1256 1238 }
1257 1239 else if(data->set.ssl.verifyhost == 2) {
1258   - WCHAR cert_hostname[128];
1259   - WCHAR *hostname = Curl_convert_UTF8_to_wchar(conn->host.name);
  1240 + TCHAR cert_hostname_buff[128];
  1241 + xcharp_u hostname;
  1242 + xcharp_u cert_hostname;
1260 1243 DWORD len;
1261 1244
1262   - len = CertGetNameStringW(pCertContextServer,
1263   - CERT_NAME_DNS_TYPE,
1264   - 0,
1265   - NULL,
1266   - cert_hostname,
1267   - 128);
1268   - if(len > 0 && cert_hostname[0] == '*') {
  1245 + cert_hostname.const_tchar_ptr = cert_hostname_buff;
  1246 + hostname.tchar_ptr = Curl_convert_UTF8_to_tchar(conn->host.name);
  1247 +
  1248 + len = CertGetNameString(pCertContextServer,
  1249 + CERT_NAME_DNS_TYPE,
  1250 + 0,
  1251 + NULL,
  1252 + cert_hostname.tchar_ptr,
  1253 + 128);
  1254 + if(len > 0 && *cert_hostname.tchar_ptr == '*') {
1269 1255 /* this is a wildcard cert. try matching the last len - 1 chars */
1270 1256 int hostname_len = strlen(conn->host.name);
1271   - if(wcsicmp(cert_hostname + 1, hostname + hostname_len - len + 2) != 0)
  1257 + cert_hostname.tchar_ptr++;
  1258 + if(_tcsicmp(cert_hostname.const_tchar_ptr,
  1259 + hostname.const_tchar_ptr + hostname_len - len + 2) != 0)
1272 1260 result = CURLE_PEER_FAILED_VERIFICATION;
1273 1261 }
1274   - else if(len == 0 || wcsicmp(hostname, cert_hostname) != 0) {
  1262 + else if(len == 0 || _tcsicmp(hostname.const_tchar_ptr,
  1263 + cert_hostname.const_tchar_ptr) != 0) {
1275 1264 result = CURLE_PEER_FAILED_VERIFICATION;
1276 1265 }
1277 1266 if(result == CURLE_PEER_FAILED_VERIFICATION) {
1278   - const char *_cert_hostname;
1279   - _cert_hostname = Curl_convert_wchar_to_UTF8(cert_hostname);
  1267 + char *_cert_hostname;
  1268 + _cert_hostname = Curl_convert_tchar_to_UTF8(cert_hostname.tchar_ptr);
1280 1269 failf(data, "schannel: CertGetNameString() certificate hostname "
1281 1270 "(%s) did not match connection (%s)",
1282 1271 _cert_hostname, conn->host.name);
1283   - Curl_safefree((void *)_cert_hostname);
  1272 + Curl_safefree(_cert_hostname);
1284 1273 }
1285   - Curl_safefree(hostname);
  1274 + Curl_unicodefree(hostname.tchar_ptr);
1286 1275 }
1287 1276 }
1288 1277
10 lib/http_negotiate_sspi.c
@@ -207,13 +207,9 @@ int Curl_input_negotiate(struct connectdata *conn, bool proxy,
207 207 in_sec_buff.pvBuffer = input_token;
208 208 }
209 209
210   -#ifdef UNICODE
211   - sname = Curl_convert_UTF8_to_wchar(neg_ctx->server_name);
  210 + sname = Curl_convert_UTF8_to_tchar(neg_ctx->server_name);
212 211 if(!sname)
213 212 return CURLE_OUT_OF_MEMORY;
214   -#else
215   - sname = neg_ctx->server_name;
216   -#endif
217 213
218 214 neg_ctx->status = s_pSecFn->InitializeSecurityContext(
219 215 neg_ctx->credentials,
@@ -229,9 +225,7 @@ int Curl_input_negotiate(struct connectdata *conn, bool proxy,
229 225 &context_attributes,
230 226 &lifetime);
231 227
232   -#ifdef UNICODE
233   - free(sname);
234   -#endif
  228 + Curl_unicodefree(sname);
235 229
236 230 if(GSS_ERROR(neg_ctx->status))
237 231 return -1;
10 lib/idn_win32.c
@@ -49,10 +49,9 @@ int curl_win32_idn_to_ascii(const char *in, char **out)
49 49 }
50 50 free(in_w);
51 51
52   - *out = (char *)Curl_convert_wchar_to_UTF8(punycode);
53   - if(!(*out)) {
  52 + *out = Curl_convert_wchar_to_UTF8(punycode);
  53 + if(!*out)
54 54 return 0;
55   - }
56 55 }
57 56 return 1;
58 57 }
@@ -67,10 +66,9 @@ int curl_win32_ascii_to_idn(const char *in, size_t in_len, char **out_utf8)
67 66 return 0;
68 67 }
69 68 else {
70   - const char *out_utf8 = Curl_convert_wchar_to_UTF8(unicode);
71   - if(!out_utf8) {
  69 + *out_utf8 = Curl_convert_wchar_to_UTF8(unicode);
  70 + if(!*out_utf8)
72 71 return 0;
73   - }
74 72 }
75 73 }
76 74 return 1;
7 lib/setup.h
@@ -223,6 +223,12 @@
223 223 */
224 224
225 225 #ifdef HAVE_WINDOWS_H
  226 +# if defined(UNICODE) && !defined(_UNICODE)
  227 +# define _UNICODE
  228 +# endif
  229 +# if defined(_UNICODE) && !defined(UNICODE)
  230 +# define UNICODE
  231 +# endif
226 232 # ifndef WIN32_LEAN_AND_MEAN
227 233 # define WIN32_LEAN_AND_MEAN
228 234 # endif
@@ -237,6 +243,7 @@
237 243 # include <winsock.h>
238 244 # endif
239 245 # endif
  246 +# include <tchar.h>
240 247 #endif
241 248
242 249 /*
12 lib/socks_sspi.c
@@ -161,13 +161,11 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
161 161 /* errors, keep sending it... */
162 162 for(;;) {
163 163 TCHAR *sname;
164   -#ifdef UNICODE
165   - sname = Curl_convert_UTF8_to_wchar(service_name);
  164 +
  165 + sname = Curl_convert_UTF8_to_tchar(service_name);
166 166 if(!sname)
167 167 return CURLE_OUT_OF_MEMORY;
168   -#else
169   - sname = service_name;
170   -#endif
  168 +
171 169 status = s_pSecFn->InitializeSecurityContext(&cred_handle,
172 170 context_handle,
173 171 sname,
@@ -184,9 +182,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
184 182 &sspi_ret_flags,
185 183 &expiry);
186 184
187   -#ifdef UNICODE
188   - Curl_safefree(sname);
189   -#endif
  185 + Curl_unicodefree(sname);
190 186
191 187 if(sspi_recv_token.pvBuffer) {
192 188 s_pSecFn->FreeContextBuffer(sspi_recv_token.pvBuffer);

0 comments on commit e77d867

Please sign in to comment.
Something went wrong with that request. Please try again.