source: trunk/src/secur32/thunks.c@ 22015

Last change on this file since 22015 was 21916, checked in by dmik, 14 years ago

Merge branch gcc-kmk to trunk.

File size: 30.5 KB
Line 
1/* Copyright (C) 2004 Juan Lang
2 *
3 * This file implements thunks between wide char and multibyte functions for
4 * SSPs that only provide one or the other.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#include <stdarg.h>
22#include <memory.h>
23
24#include "windef.h"
25#include "winbase.h"
26#include "winnls.h"
27#include "winternl.h"
28#include "sspi.h"
29#include "secur32_priv.h"
30#include "thunks.h"
31
32#include "wine/debug.h"
33#include "winerror.h"
34WINE_DEFAULT_DEBUG_CHANNEL(secur32);
35
36SECURITY_STATUS SEC_ENTRY thunk_AcquireCredentialsHandleA(
37 SEC_CHAR *pszPrincipal, SEC_CHAR *pszPackage, ULONG fCredentialsUse,
38 PLUID pvLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn,
39 PVOID pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
40{
41 SECURITY_STATUS ret;
42
43 TRACE("%s %s %d %p %p %p %p %p %p\n", debugstr_a(pszPrincipal),
44 debugstr_a(pszPackage), fCredentialsUse, pvLogonID, pAuthData, pGetKeyFn,
45 pvGetKeyArgument, phCredential, ptsExpiry);
46 if (pszPackage)
47 {
48 UNICODE_STRING principal, package;
49
50 RtlCreateUnicodeStringFromAsciiz(&principal, pszPrincipal);
51 RtlCreateUnicodeStringFromAsciiz(&package, pszPackage);
52 ret = AcquireCredentialsHandleW(principal.Buffer, package.Buffer,
53 fCredentialsUse, pvLogonID, pAuthData, pGetKeyFn, pvGetKeyArgument,
54 phCredential, ptsExpiry);
55 RtlFreeUnicodeString(&principal);
56 RtlFreeUnicodeString(&package);
57 }
58 else
59 ret = SEC_E_SECPKG_NOT_FOUND;
60 return ret;
61}
62
63SECURITY_STATUS SEC_ENTRY thunk_AcquireCredentialsHandleW(
64 SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, ULONG fCredentialsUse,
65 PLUID pvLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn,
66 PVOID pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
67{
68 SECURITY_STATUS ret;
69
70 TRACE("%s %s %d %p %p %p %p %p %p\n", debugstr_w(pszPrincipal),
71 debugstr_w(pszPackage), fCredentialsUse, pvLogonID, pAuthData, pGetKeyFn,
72 pvGetKeyArgument, phCredential, ptsExpiry);
73 if (pszPackage)
74 {
75 PSTR principal, package;
76
77 principal = SECUR32_AllocMultiByteFromWide(pszPrincipal);
78 package = SECUR32_AllocMultiByteFromWide(pszPackage);
79 ret = AcquireCredentialsHandleA(principal, package, fCredentialsUse,
80 pvLogonID, pAuthData, pGetKeyFn, pvGetKeyArgument, phCredential,
81 ptsExpiry);
82 HeapFree(GetProcessHeap(), 0, principal);
83 HeapFree(GetProcessHeap(), 0, package);
84 }
85 else
86 ret = SEC_E_SECPKG_NOT_FOUND;
87 return ret;
88}
89
90/* thunking is pretty dicey for these--the output type depends on ulAttribute,
91 * so we have to know about every type the caller does
92 */
93SECURITY_STATUS SEC_ENTRY thunk_QueryCredentialsAttributesA(
94 PCredHandle phCredential, ULONG ulAttribute, void *pBuffer)
95{
96 SECURITY_STATUS ret;
97
98 TRACE("%p %d %p\n", phCredential, ulAttribute, pBuffer);
99 if (phCredential)
100 {
101 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
102 PCredHandle cred = (PCredHandle)phCredential->dwLower;
103
104 if (package && package->provider)
105 {
106 if (package->provider->fnTableW.QueryCredentialsAttributesW)
107 {
108 ret = package->provider->fnTableW.QueryCredentialsAttributesW(
109 cred, ulAttribute, pBuffer);
110 if (ret == SEC_E_OK)
111 {
112 switch (ulAttribute)
113 {
114 case SECPKG_CRED_ATTR_NAMES:
115 {
116 PSecPkgCredentials_NamesW names =
117 (PSecPkgCredentials_NamesW)pBuffer;
118 SEC_WCHAR *oldUser = names->sUserName;
119
120 if (oldUser)
121 {
122 names->sUserName =
123 (PWSTR)SECUR32_AllocMultiByteFromWide(oldUser);
124 package->provider->fnTableW.FreeContextBuffer(
125 oldUser);
126 }
127 break;
128 }
129 default:
130 WARN("attribute type %d unknown\n", ulAttribute);
131 ret = SEC_E_INTERNAL_ERROR;
132 }
133 }
134 }
135 else
136 ret = SEC_E_UNSUPPORTED_FUNCTION;
137 }
138 else
139 ret = SEC_E_INVALID_HANDLE;
140 }
141 else
142 ret = SEC_E_INVALID_HANDLE;
143 return ret;
144}
145
146SECURITY_STATUS SEC_ENTRY thunk_QueryCredentialsAttributesW(
147 PCredHandle phCredential, ULONG ulAttribute, void *pBuffer)
148{
149 SECURITY_STATUS ret;
150
151 TRACE("%p %d %p\n", phCredential, ulAttribute, pBuffer);
152 if (phCredential)
153 {
154 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
155 PCredHandle cred = (PCredHandle)phCredential->dwLower;
156
157 if (package && package->provider)
158 {
159 if (package->provider->fnTableA.QueryCredentialsAttributesA)
160 {
161 ret = package->provider->fnTableA.QueryCredentialsAttributesA(
162 cred, ulAttribute, pBuffer);
163 if (ret == SEC_E_OK)
164 {
165 switch (ulAttribute)
166 {
167 case SECPKG_CRED_ATTR_NAMES:
168 {
169 PSecPkgCredentials_NamesA names =
170 (PSecPkgCredentials_NamesA)pBuffer;
171 SEC_CHAR *oldUser = names->sUserName;
172
173 if (oldUser)
174 {
175 names->sUserName =
176 (PSTR)SECUR32_AllocWideFromMultiByte(oldUser);
177 package->provider->fnTableA.FreeContextBuffer(
178 oldUser);
179 }
180 break;
181 }
182 default:
183 WARN("attribute type %d unknown\n", ulAttribute);
184 ret = SEC_E_INTERNAL_ERROR;
185 }
186 }
187 }
188 else
189 ret = SEC_E_UNSUPPORTED_FUNCTION;
190 }
191 else
192 ret = SEC_E_INVALID_HANDLE;
193 }
194 else
195 ret = SEC_E_INVALID_HANDLE;
196 return ret;
197}
198
199SECURITY_STATUS SEC_ENTRY thunk_InitializeSecurityContextA(
200 PCredHandle phCredential, PCtxtHandle phContext,
201 SEC_CHAR *pszTargetName, ULONG fContextReq,
202 ULONG Reserved1, ULONG TargetDataRep, PSecBufferDesc pInput,
203 ULONG Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pOutput,
204 ULONG *pfContextAttr, PTimeStamp ptsExpiry)
205{
206 SECURITY_STATUS ret;
207
208 TRACE("%p %p %s %d %d %d %p %d %p %p %p %p\n", phCredential, phContext,
209 debugstr_a(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
210 Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
211 if (phCredential)
212 {
213 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
214
215 if (package && package->provider)
216 {
217 if (package->provider->fnTableW.InitializeSecurityContextW)
218 {
219 UNICODE_STRING target;
220
221 RtlCreateUnicodeStringFromAsciiz(&target, pszTargetName);
222 ret = package->provider->fnTableW.InitializeSecurityContextW(
223 phCredential, phContext, target.Buffer, fContextReq, Reserved1,
224 TargetDataRep, pInput, Reserved2, phNewContext, pOutput,
225 pfContextAttr, ptsExpiry);
226 RtlFreeUnicodeString(&target);
227 }
228 else
229 ret = SEC_E_UNSUPPORTED_FUNCTION;
230 }
231 else
232 ret = SEC_E_INVALID_HANDLE;
233 }
234 else
235 ret = SEC_E_INVALID_HANDLE;
236 return ret;
237}
238
239SECURITY_STATUS SEC_ENTRY thunk_InitializeSecurityContextW(
240 PCredHandle phCredential, PCtxtHandle phContext,
241 SEC_WCHAR *pszTargetName, ULONG fContextReq,
242 ULONG Reserved1, ULONG TargetDataRep, PSecBufferDesc pInput,
243 ULONG Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pOutput,
244 ULONG *pfContextAttr, PTimeStamp ptsExpiry)
245{
246 SECURITY_STATUS ret;
247
248 TRACE("%p %p %s %d %d %d %p %d %p %p %p %p\n", phCredential, phContext,
249 debugstr_w(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
250 Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
251 if (phCredential)
252 {
253 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
254
255 if (package && package->provider)
256 {
257 if (package->provider->fnTableA.InitializeSecurityContextA)
258 {
259 PSTR target = SECUR32_AllocMultiByteFromWide(pszTargetName);
260
261 ret = package->provider->fnTableA.InitializeSecurityContextA(
262 phCredential, phContext, target, fContextReq, Reserved1,
263 TargetDataRep, pInput, Reserved2, phNewContext, pOutput,
264 pfContextAttr, ptsExpiry);
265 HeapFree(GetProcessHeap(), 0, target);
266 }
267 else
268 ret = SEC_E_UNSUPPORTED_FUNCTION;
269 }
270 else
271 ret = SEC_E_INVALID_HANDLE;
272 }
273 else
274 ret = SEC_E_INVALID_HANDLE;
275 return ret;
276}
277
278SECURITY_STATUS SEC_ENTRY thunk_AddCredentialsA(PCredHandle hCredentials,
279 SEC_CHAR *pszPrincipal, SEC_CHAR *pszPackage, ULONG fCredentialUse,
280 void *pAuthData, SEC_GET_KEY_FN pGetKeyFn, void *pvGetKeyArgument,
281 PTimeStamp ptsExpiry)
282{
283 SECURITY_STATUS ret;
284
285 TRACE("%p %s %s %d %p %p %p %p\n", hCredentials, debugstr_a(pszPrincipal),
286 debugstr_a(pszPackage), fCredentialUse, pAuthData, pGetKeyFn,
287 pvGetKeyArgument, ptsExpiry);
288 if (hCredentials)
289 {
290 SecurePackage *package = (SecurePackage *)hCredentials->dwUpper;
291 PCredHandle cred = (PCtxtHandle)hCredentials->dwLower;
292
293 if (package && package->provider)
294 {
295 if (package->provider->fnTableW.AddCredentialsW)
296 {
297 UNICODE_STRING szPrincipal, szPackage;
298
299 RtlCreateUnicodeStringFromAsciiz(&szPrincipal, pszPrincipal);
300 RtlCreateUnicodeStringFromAsciiz(&szPackage, pszPackage);
301 ret = package->provider->fnTableW.AddCredentialsW(
302 cred, szPrincipal.Buffer, szPackage.Buffer, fCredentialUse,
303 pAuthData, pGetKeyFn, pvGetKeyArgument, ptsExpiry);
304 RtlFreeUnicodeString(&szPrincipal);
305 RtlFreeUnicodeString(&szPackage);
306 }
307 else
308 ret = SEC_E_UNSUPPORTED_FUNCTION;
309 }
310 else
311 ret = SEC_E_INVALID_HANDLE;
312 }
313 else
314 ret = SEC_E_INVALID_HANDLE;
315 return ret;
316}
317
318SECURITY_STATUS SEC_ENTRY thunk_AddCredentialsW(PCredHandle hCredentials,
319 SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, ULONG fCredentialUse,
320 void *pAuthData, SEC_GET_KEY_FN pGetKeyFn, void *pvGetKeyArgument,
321 PTimeStamp ptsExpiry)
322{
323 SECURITY_STATUS ret;
324
325 TRACE("%p %s %s %d %p %p %p %p\n", hCredentials, debugstr_w(pszPrincipal),
326 debugstr_w(pszPackage), fCredentialUse, pAuthData, pGetKeyFn,
327 pvGetKeyArgument, ptsExpiry);
328 if (hCredentials)
329 {
330 SecurePackage *package = (SecurePackage *)hCredentials->dwUpper;
331 PCredHandle cred = (PCtxtHandle)hCredentials->dwLower;
332
333 if (package && package->provider)
334 {
335 if (package->provider->fnTableA.AddCredentialsA)
336 {
337 PSTR szPrincipal = SECUR32_AllocMultiByteFromWide(pszPrincipal);
338 PSTR szPackage = SECUR32_AllocMultiByteFromWide(pszPackage);
339
340 ret = package->provider->fnTableA.AddCredentialsA(
341 cred, szPrincipal, szPackage, fCredentialUse, pAuthData,
342 pGetKeyFn, pvGetKeyArgument, ptsExpiry);
343 HeapFree(GetProcessHeap(), 0, szPrincipal);
344 HeapFree(GetProcessHeap(), 0, szPackage);
345 }
346 else
347 ret = SEC_E_UNSUPPORTED_FUNCTION;
348 }
349 else
350 ret = SEC_E_INVALID_HANDLE;
351 }
352 else
353 ret = SEC_E_INVALID_HANDLE;
354 return ret;
355}
356
357static PSecPkgInfoA _copyPackageInfoFlatWToA(const SecPkgInfoW *infoW)
358{
359 PSecPkgInfoA ret;
360
361 if (infoW)
362 {
363 size_t bytesNeeded = sizeof(SecPkgInfoA);
364 int nameLen = 0, commentLen = 0;
365
366 if (infoW->Name)
367 {
368 nameLen = WideCharToMultiByte(CP_ACP, 0, infoW->Name, -1,
369 NULL, 0, NULL, NULL);
370 bytesNeeded += nameLen;
371 }
372 if (infoW->Comment)
373 {
374 commentLen = WideCharToMultiByte(CP_ACP, 0, infoW->Comment, -1,
375 NULL, 0, NULL, NULL);
376 bytesNeeded += commentLen;
377 }
378 ret = HeapAlloc(GetProcessHeap(), 0, bytesNeeded);
379 if (ret)
380 {
381 PSTR nextString = (PSTR)((PBYTE)ret + sizeof(SecPkgInfoA));
382
383 memcpy(ret, infoW, sizeof(SecPkgInfoA));
384 if (infoW->Name)
385 {
386 ret->Name = nextString;
387 WideCharToMultiByte(CP_ACP, 0, infoW->Name, -1, nextString,
388 nameLen, NULL, NULL);
389 nextString += nameLen;
390 }
391 else
392 ret->Name = NULL;
393 if (infoW->Comment)
394 {
395 ret->Comment = nextString;
396 WideCharToMultiByte(CP_ACP, 0, infoW->Comment, -1, nextString,
397 nameLen, NULL, NULL);
398 }
399 else
400 ret->Comment = NULL;
401 }
402 }
403 else
404 ret = NULL;
405 return ret;
406}
407
408static SECURITY_STATUS thunk_ContextAttributesWToA(SecurePackage *package,
409 ULONG ulAttribute, void *pBuffer)
410{
411 SECURITY_STATUS ret = SEC_E_OK;
412
413 if (package && pBuffer)
414 {
415 switch (ulAttribute)
416 {
417 case SECPKG_ATTR_NAMES:
418 {
419 PSecPkgContext_NamesW names = (PSecPkgContext_NamesW)pBuffer;
420 SEC_WCHAR *oldUser = names->sUserName;
421
422 if (oldUser)
423 {
424 names->sUserName =
425 (PWSTR)SECUR32_AllocMultiByteFromWide(oldUser);
426 package->provider->fnTableW.FreeContextBuffer(oldUser);
427 }
428 break;
429 }
430 case SECPKG_ATTR_AUTHORITY:
431 {
432 PSecPkgContext_AuthorityW names =
433 (PSecPkgContext_AuthorityW)pBuffer;
434 SEC_WCHAR *oldAuth = names->sAuthorityName;
435
436 if (oldAuth)
437 {
438 names->sAuthorityName =
439 (PWSTR)SECUR32_AllocMultiByteFromWide(oldAuth);
440 package->provider->fnTableW.FreeContextBuffer(oldAuth);
441 }
442 break;
443 }
444 case SECPKG_ATTR_KEY_INFO:
445 {
446 PSecPkgContext_KeyInfoW info = (PSecPkgContext_KeyInfoW)pBuffer;
447 SEC_WCHAR *oldSigAlgName = info->sSignatureAlgorithmName;
448 SEC_WCHAR *oldEncAlgName = info->sEncryptAlgorithmName;
449
450 if (oldSigAlgName)
451 {
452 info->sSignatureAlgorithmName =
453 (PWSTR)SECUR32_AllocMultiByteFromWide(oldSigAlgName);
454 package->provider->fnTableW.FreeContextBuffer(
455 oldSigAlgName);
456 }
457 if (oldEncAlgName)
458 {
459 info->sEncryptAlgorithmName =
460 (PWSTR)SECUR32_AllocMultiByteFromWide(oldEncAlgName);
461 package->provider->fnTableW.FreeContextBuffer(
462 oldEncAlgName);
463 }
464 break;
465 }
466 case SECPKG_ATTR_PACKAGE_INFO:
467 {
468 PSecPkgContext_PackageInfoW info =
469 (PSecPkgContext_PackageInfoW)pBuffer;
470 PSecPkgInfoW oldPkgInfo = info->PackageInfo;
471
472 if (oldPkgInfo)
473 {
474 info->PackageInfo = (PSecPkgInfoW)
475 _copyPackageInfoFlatWToA(oldPkgInfo);
476 package->provider->fnTableW.FreeContextBuffer(oldPkgInfo);
477 }
478 break;
479 }
480 case SECPKG_ATTR_NEGOTIATION_INFO:
481 {
482 PSecPkgContext_NegotiationInfoW info =
483 (PSecPkgContext_NegotiationInfoW)pBuffer;
484 PSecPkgInfoW oldPkgInfo = info->PackageInfo;
485
486 if (oldPkgInfo)
487 {
488 info->PackageInfo = (PSecPkgInfoW)
489 _copyPackageInfoFlatWToA(oldPkgInfo);
490 package->provider->fnTableW.FreeContextBuffer(oldPkgInfo);
491 }
492 break;
493 }
494 case SECPKG_ATTR_NATIVE_NAMES:
495 {
496 PSecPkgContext_NativeNamesW names =
497 (PSecPkgContext_NativeNamesW)pBuffer;
498 PWSTR oldClient = names->sClientName;
499 PWSTR oldServer = names->sServerName;
500
501 if (oldClient)
502 {
503 names->sClientName = (PWSTR)SECUR32_AllocMultiByteFromWide(
504 oldClient);
505 package->provider->fnTableW.FreeContextBuffer(oldClient);
506 }
507 if (oldServer)
508 {
509 names->sServerName = (PWSTR)SECUR32_AllocMultiByteFromWide(
510 oldServer);
511 package->provider->fnTableW.FreeContextBuffer(oldServer);
512 }
513 break;
514 }
515 case SECPKG_ATTR_CREDENTIAL_NAME:
516 {
517 PSecPkgContext_CredentialNameW name =
518 (PSecPkgContext_CredentialNameW)pBuffer;
519 PWSTR oldCred = name->sCredentialName;
520
521 if (oldCred)
522 {
523 name->sCredentialName =
524 (PWSTR)SECUR32_AllocMultiByteFromWide(oldCred);
525 package->provider->fnTableW.FreeContextBuffer(oldCred);
526 }
527 break;
528 }
529 /* no thunking needed: */
530 case SECPKG_ATTR_ACCESS_TOKEN:
531 case SECPKG_ATTR_DCE_INFO:
532 case SECPKG_ATTR_FLAGS:
533 case SECPKG_ATTR_LIFESPAN:
534 case SECPKG_ATTR_PASSWORD_EXPIRY:
535 case SECPKG_ATTR_SESSION_KEY:
536 case SECPKG_ATTR_SIZES:
537 case SECPKG_ATTR_STREAM_SIZES:
538 case SECPKG_ATTR_TARGET_INFORMATION:
539 break;
540 default:
541 WARN("attribute type %d unknown\n", ulAttribute);
542 ret = SEC_E_INTERNAL_ERROR;
543 }
544 }
545 else
546 ret = SEC_E_INVALID_TOKEN;
547 return ret;
548}
549
550SECURITY_STATUS SEC_ENTRY thunk_QueryContextAttributesA(PCtxtHandle phContext,
551 ULONG ulAttribute, void *pBuffer)
552{
553 SECURITY_STATUS ret;
554
555 TRACE("%p %d %p\n", phContext, ulAttribute, pBuffer);
556 if (phContext)
557 {
558 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
559 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
560
561 if (package && package->provider)
562 {
563 if (package->provider->fnTableW.QueryContextAttributesW)
564 {
565 ret = package->provider->fnTableW.QueryContextAttributesW(
566 ctxt, ulAttribute, pBuffer);
567 if (ret == SEC_E_OK)
568 ret = thunk_ContextAttributesWToA(package, ulAttribute,
569 pBuffer);
570 }
571 else
572 ret = SEC_E_UNSUPPORTED_FUNCTION;
573 }
574 else
575 ret = SEC_E_INVALID_HANDLE;
576 }
577 else
578 ret = SEC_E_INVALID_HANDLE;
579 return ret;
580}
581
582static PSecPkgInfoW _copyPackageInfoFlatAToW(const SecPkgInfoA *infoA)
583{
584 PSecPkgInfoW ret;
585
586 if (infoA)
587 {
588 size_t bytesNeeded = sizeof(SecPkgInfoW);
589 int nameLen = 0, commentLen = 0;
590
591 if (infoA->Name)
592 {
593 nameLen = MultiByteToWideChar(CP_ACP, 0, infoA->Name, -1,
594 NULL, 0);
595 bytesNeeded += nameLen * sizeof(WCHAR);
596 }
597 if (infoA->Comment)
598 {
599 commentLen = MultiByteToWideChar(CP_ACP, 0, infoA->Comment, -1,
600 NULL, 0);
601 bytesNeeded += commentLen * sizeof(WCHAR);
602 }
603 ret = HeapAlloc(GetProcessHeap(), 0, bytesNeeded);
604 if (ret)
605 {
606 PWSTR nextString = (PWSTR)((PBYTE)ret + sizeof(SecPkgInfoW));
607
608 memcpy(ret, infoA, sizeof(SecPkgInfoA));
609 if (infoA->Name)
610 {
611 ret->Name = nextString;
612 MultiByteToWideChar(CP_ACP, 0, infoA->Name, -1, nextString,
613 nameLen);
614 nextString += nameLen;
615 }
616 else
617 ret->Name = NULL;
618 if (infoA->Comment)
619 {
620 ret->Comment = nextString;
621 MultiByteToWideChar(CP_ACP, 0, infoA->Comment, -1, nextString,
622 commentLen);
623 }
624 else
625 ret->Comment = NULL;
626 }
627 }
628 else
629 ret = NULL;
630 return ret;
631}
632
633static SECURITY_STATUS thunk_ContextAttributesAToW(SecurePackage *package,
634 ULONG ulAttribute, void *pBuffer)
635{
636 SECURITY_STATUS ret = SEC_E_OK;
637
638 if (package && pBuffer)
639 {
640 switch (ulAttribute)
641 {
642 case SECPKG_ATTR_NAMES:
643 {
644 PSecPkgContext_NamesA names = (PSecPkgContext_NamesA)pBuffer;
645 SEC_CHAR *oldUser = names->sUserName;
646
647 if (oldUser)
648 {
649 names->sUserName =
650 (PSTR)SECUR32_AllocWideFromMultiByte(oldUser);
651 package->provider->fnTableW.FreeContextBuffer(oldUser);
652 }
653 break;
654 }
655 case SECPKG_ATTR_AUTHORITY:
656 {
657 PSecPkgContext_AuthorityA names =
658 (PSecPkgContext_AuthorityA)pBuffer;
659 SEC_CHAR *oldAuth = names->sAuthorityName;
660
661 if (oldAuth)
662 {
663 names->sAuthorityName =
664 (PSTR)SECUR32_AllocWideFromMultiByte(oldAuth);
665 package->provider->fnTableW.FreeContextBuffer(oldAuth);
666 }
667 break;
668 }
669 case SECPKG_ATTR_KEY_INFO:
670 {
671 PSecPkgContext_KeyInfoA info = (PSecPkgContext_KeyInfoA)pBuffer;
672 SEC_CHAR *oldSigAlgName = info->sSignatureAlgorithmName;
673 SEC_CHAR *oldEncAlgName = info->sEncryptAlgorithmName;
674
675 if (oldSigAlgName)
676 {
677 info->sSignatureAlgorithmName =
678 (PSTR)SECUR32_AllocWideFromMultiByte(oldSigAlgName);
679 package->provider->fnTableW.FreeContextBuffer(
680 oldSigAlgName);
681 }
682 if (oldEncAlgName)
683 {
684 info->sEncryptAlgorithmName =
685 (PSTR)SECUR32_AllocWideFromMultiByte(
686 oldEncAlgName);
687 package->provider->fnTableW.FreeContextBuffer(
688 oldEncAlgName);
689 }
690 break;
691 }
692 case SECPKG_ATTR_PACKAGE_INFO:
693 {
694 PSecPkgContext_PackageInfoA info =
695 (PSecPkgContext_PackageInfoA)pBuffer;
696 PSecPkgInfoA oldPkgInfo = info->PackageInfo;
697
698 if (oldPkgInfo)
699 {
700 info->PackageInfo = (PSecPkgInfoA)
701 _copyPackageInfoFlatAToW(oldPkgInfo);
702 package->provider->fnTableW.FreeContextBuffer(oldPkgInfo);
703 }
704 break;
705 }
706 case SECPKG_ATTR_NEGOTIATION_INFO:
707 {
708 PSecPkgContext_NegotiationInfoA info =
709 (PSecPkgContext_NegotiationInfoA)pBuffer;
710 PSecPkgInfoA oldPkgInfo = info->PackageInfo;
711
712 if (oldPkgInfo)
713 {
714 info->PackageInfo = (PSecPkgInfoA)
715 _copyPackageInfoFlatAToW(oldPkgInfo);
716 package->provider->fnTableW.FreeContextBuffer(oldPkgInfo);
717 }
718 break;
719 }
720 case SECPKG_ATTR_NATIVE_NAMES:
721 {
722 PSecPkgContext_NativeNamesA names =
723 (PSecPkgContext_NativeNamesA)pBuffer;
724 PSTR oldClient = names->sClientName;
725 PSTR oldServer = names->sServerName;
726
727 if (oldClient)
728 {
729 names->sClientName = (PSTR)SECUR32_AllocWideFromMultiByte(
730 oldClient);
731 package->provider->fnTableW.FreeContextBuffer(oldClient);
732 }
733 if (oldServer)
734 {
735 names->sServerName = (PSTR)SECUR32_AllocWideFromMultiByte(
736 oldServer);
737 package->provider->fnTableW.FreeContextBuffer(oldServer);
738 }
739 break;
740 }
741 case SECPKG_ATTR_CREDENTIAL_NAME:
742 {
743 PSecPkgContext_CredentialNameA name =
744 (PSecPkgContext_CredentialNameA)pBuffer;
745 PSTR oldCred = name->sCredentialName;
746
747 if (oldCred)
748 {
749 name->sCredentialName =
750 (PSTR)SECUR32_AllocWideFromMultiByte(oldCred);
751 package->provider->fnTableW.FreeContextBuffer(oldCred);
752 }
753 break;
754 }
755 /* no thunking needed: */
756 case SECPKG_ATTR_ACCESS_TOKEN:
757 case SECPKG_ATTR_DCE_INFO:
758 case SECPKG_ATTR_FLAGS:
759 case SECPKG_ATTR_LIFESPAN:
760 case SECPKG_ATTR_PASSWORD_EXPIRY:
761 case SECPKG_ATTR_SESSION_KEY:
762 case SECPKG_ATTR_SIZES:
763 case SECPKG_ATTR_STREAM_SIZES:
764 case SECPKG_ATTR_TARGET_INFORMATION:
765 break;
766 default:
767 WARN("attribute type %d unknown\n", ulAttribute);
768 ret = SEC_E_INTERNAL_ERROR;
769 }
770 }
771 else
772 ret = SEC_E_INVALID_TOKEN;
773 return ret;
774}
775
776SECURITY_STATUS SEC_ENTRY thunk_QueryContextAttributesW(PCtxtHandle phContext,
777 ULONG ulAttribute, void *pBuffer)
778{
779 SECURITY_STATUS ret;
780
781 TRACE("%p %d %p\n", phContext, ulAttribute, pBuffer);
782 if (phContext)
783 {
784 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
785 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
786
787 if (package && package->provider)
788 {
789 if (package->provider->fnTableA.QueryContextAttributesA)
790 {
791 ret = package->provider->fnTableA.QueryContextAttributesA(
792 ctxt, ulAttribute, pBuffer);
793 if (ret == SEC_E_OK)
794 ret = thunk_ContextAttributesAToW(package, ulAttribute,
795 pBuffer);
796 }
797 else
798 ret = SEC_E_UNSUPPORTED_FUNCTION;
799 }
800 else
801 ret = SEC_E_INVALID_HANDLE;
802 }
803 else
804 ret = SEC_E_INVALID_HANDLE;
805 return ret;
806}
807
808SECURITY_STATUS SEC_ENTRY thunk_SetContextAttributesA(PCtxtHandle phContext,
809 ULONG ulAttribute, void *pBuffer, ULONG cbBuffer)
810{
811 SECURITY_STATUS ret;
812
813 TRACE("%p %d %p %d\n", phContext, ulAttribute, pBuffer, cbBuffer);
814 if (phContext)
815 {
816 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
817 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
818
819 if (package && package->provider && pBuffer && cbBuffer)
820 {
821 if (package->provider->fnTableW.SetContextAttributesW)
822 {
823 /* TODO: gotta validate size too! */
824 ret = thunk_ContextAttributesWToA(package, ulAttribute,
825 pBuffer);
826 if (ret == SEC_E_OK)
827 ret = package->provider->fnTableW.SetContextAttributesW(
828 ctxt, ulAttribute, pBuffer, cbBuffer);
829 }
830 else
831 ret = SEC_E_UNSUPPORTED_FUNCTION;
832 }
833 else
834 ret = SEC_E_INVALID_HANDLE;
835 }
836 else
837 ret = SEC_E_INVALID_HANDLE;
838 return ret;
839}
840
841SECURITY_STATUS SEC_ENTRY thunk_SetContextAttributesW(PCtxtHandle phContext,
842 ULONG ulAttribute, void *pBuffer, ULONG cbBuffer)
843{
844 SECURITY_STATUS ret;
845
846 TRACE("%p %d %p %d\n", phContext, ulAttribute, pBuffer, cbBuffer);
847 if (phContext)
848 {
849 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
850 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
851
852 if (package && package->provider && pBuffer && cbBuffer)
853 {
854 if (package->provider->fnTableA.SetContextAttributesA)
855 {
856 /* TODO: gotta validate size too! */
857 ret = thunk_ContextAttributesAToW(package, ulAttribute,
858 pBuffer);
859 if (ret == SEC_E_OK)
860 ret = package->provider->fnTableA.SetContextAttributesA(
861 ctxt, ulAttribute, pBuffer, cbBuffer);
862 }
863 else
864 ret = SEC_E_UNSUPPORTED_FUNCTION;
865 }
866 else
867 ret = SEC_E_INVALID_HANDLE;
868 }
869 else
870 ret = SEC_E_INVALID_HANDLE;
871 return ret;
872}
873
874SECURITY_STATUS SEC_ENTRY thunk_ImportSecurityContextA(
875 SEC_CHAR *pszPackage, PSecBuffer pPackedContext, void *Token,
876 PCtxtHandle phContext)
877{
878 SECURITY_STATUS ret;
879 UNICODE_STRING package;
880
881 TRACE("%s %p %p %p\n", debugstr_a(pszPackage), pPackedContext, Token,
882 phContext);
883 RtlCreateUnicodeStringFromAsciiz(&package, pszPackage);
884 ret = ImportSecurityContextW(package.Buffer, pPackedContext, Token,
885 phContext);
886 RtlFreeUnicodeString(&package);
887 return ret;
888}
889
890SECURITY_STATUS SEC_ENTRY thunk_ImportSecurityContextW(
891 SEC_WCHAR *pszPackage, PSecBuffer pPackedContext, void *Token,
892 PCtxtHandle phContext)
893{
894 SECURITY_STATUS ret;
895 PSTR package = SECUR32_AllocMultiByteFromWide(pszPackage);
896
897 TRACE("%s %p %p %p\n", debugstr_w(pszPackage), pPackedContext, Token,
898 phContext);
899 ret = ImportSecurityContextA(package, pPackedContext, Token, phContext);
900 HeapFree(GetProcessHeap(), 0, package);
901 return ret;
902}
Note: See TracBrowser for help on using the repository browser.