comctl32/tests: Flush events before testing edit control IME messages.
[wine.git] / dlls / secur32 / thunks.c
blobde0fb0a50ecdc90106784f88973d0074f27f3e7d
1 /* Copyright (C) 2004 Juan Lang
3 * This file implements thunks between wide char and multibyte functions for
4 * SSPs that only provide one or the other.
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.
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.
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
21 #include <stdarg.h>
22 #include "windef.h"
23 #include "winbase.h"
24 #include "winnls.h"
25 #include "winternl.h"
26 #include "sspi.h"
28 #include "wine/debug.h"
29 #include "secur32_priv.h"
30 #include "thunks.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(secur32);
34 SECURITY_STATUS SEC_ENTRY thunk_AcquireCredentialsHandleA(
35 SEC_CHAR *pszPrincipal, SEC_CHAR *pszPackage, ULONG fCredentialsUse,
36 PLUID pvLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn,
37 PVOID pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
39 SECURITY_STATUS ret;
41 TRACE("%s %s %ld %p %p %p %p %p %p\n", debugstr_a(pszPrincipal),
42 debugstr_a(pszPackage), fCredentialsUse, pvLogonID, pAuthData, pGetKeyFn,
43 pvGetKeyArgument, phCredential, ptsExpiry);
44 if (pszPackage)
46 UNICODE_STRING principal, package;
48 RtlCreateUnicodeStringFromAsciiz(&principal, pszPrincipal);
49 RtlCreateUnicodeStringFromAsciiz(&package, pszPackage);
50 ret = AcquireCredentialsHandleW(principal.Buffer, package.Buffer,
51 fCredentialsUse, pvLogonID, pAuthData, pGetKeyFn, pvGetKeyArgument,
52 phCredential, ptsExpiry);
53 RtlFreeUnicodeString(&principal);
54 RtlFreeUnicodeString(&package);
56 else
57 ret = SEC_E_SECPKG_NOT_FOUND;
58 return ret;
61 static char *strdupWA( const WCHAR *str )
63 char *ret = NULL;
64 if (str)
66 int len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
67 if ((ret = RtlAllocateHeap( GetProcessHeap(), 0, len )))
68 WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
70 return ret;
73 SECURITY_STATUS SEC_ENTRY thunk_AcquireCredentialsHandleW(
74 SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, ULONG fCredentialsUse,
75 PLUID pvLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn,
76 PVOID pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
78 SECURITY_STATUS ret;
80 TRACE("%s %s %ld %p %p %p %p %p %p\n", debugstr_w(pszPrincipal),
81 debugstr_w(pszPackage), fCredentialsUse, pvLogonID, pAuthData, pGetKeyFn,
82 pvGetKeyArgument, phCredential, ptsExpiry);
83 if (pszPackage)
85 char *principal, *package;
87 principal = strdupWA(pszPrincipal);
88 package = strdupWA(pszPackage);
89 ret = AcquireCredentialsHandleA(principal, package, fCredentialsUse,
90 pvLogonID, pAuthData, pGetKeyFn, pvGetKeyArgument, phCredential, ptsExpiry);
91 RtlFreeHeap(GetProcessHeap(), 0, principal);
92 RtlFreeHeap(GetProcessHeap(), 0, package);
94 else
95 ret = SEC_E_SECPKG_NOT_FOUND;
96 return ret;
99 /* thunking is pretty dicey for these--the output type depends on ulAttribute,
100 * so we have to know about every type the caller does
102 SECURITY_STATUS SEC_ENTRY thunk_QueryCredentialsAttributesA(
103 PCredHandle phCredential, ULONG ulAttribute, void *pBuffer)
105 SECURITY_STATUS ret;
107 TRACE("%p %ld %p\n", phCredential, ulAttribute, pBuffer);
108 if (phCredential)
110 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
111 PCredHandle cred = (PCredHandle)phCredential->dwLower;
113 if (package && package->provider)
115 if (package->provider->fnTableW.QueryCredentialsAttributesW)
117 ret = package->provider->fnTableW.QueryCredentialsAttributesW( cred, ulAttribute, pBuffer);
118 if (ret == SEC_E_OK)
120 switch (ulAttribute)
122 case SECPKG_CRED_ATTR_NAMES:
124 PSecPkgCredentials_NamesW names = (PSecPkgCredentials_NamesW)pBuffer;
125 SEC_WCHAR *oldUser = names->sUserName;
127 if (oldUser)
129 names->sUserName = (WCHAR *)strdupWA(oldUser);
130 package->provider->fnTableW.FreeContextBuffer(oldUser);
132 break;
134 default:
135 WARN("attribute type %ld unknown\n", ulAttribute);
136 ret = SEC_E_INTERNAL_ERROR;
140 else
141 ret = SEC_E_UNSUPPORTED_FUNCTION;
143 else
144 ret = SEC_E_INVALID_HANDLE;
146 else
147 ret = SEC_E_INVALID_HANDLE;
148 return ret;
151 static WCHAR *strdupAW( const char *str )
153 WCHAR *ret = NULL;
154 if (str)
156 int len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
157 if ((ret = RtlAllocateHeap( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
158 MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
160 return ret;
163 SECURITY_STATUS SEC_ENTRY thunk_QueryCredentialsAttributesW(
164 PCredHandle phCredential, ULONG ulAttribute, void *pBuffer)
166 SECURITY_STATUS ret;
168 TRACE("%p %ld %p\n", phCredential, ulAttribute, pBuffer);
169 if (phCredential)
171 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
172 PCredHandle cred = (PCredHandle)phCredential->dwLower;
174 if (package && package->provider)
176 if (package->provider->fnTableA.QueryCredentialsAttributesA)
178 ret = package->provider->fnTableA.QueryCredentialsAttributesA(cred, ulAttribute, pBuffer);
179 if (ret == SEC_E_OK)
181 switch (ulAttribute)
183 case SECPKG_CRED_ATTR_NAMES:
185 PSecPkgCredentials_NamesA names = (PSecPkgCredentials_NamesA)pBuffer;
186 SEC_CHAR *oldUser = names->sUserName;
188 if (oldUser)
190 names->sUserName = (char *)strdupAW(oldUser);
191 package->provider->fnTableA.FreeContextBuffer(oldUser);
193 break;
195 default:
196 WARN("attribute type %ld unknown\n", ulAttribute);
197 ret = SEC_E_INTERNAL_ERROR;
201 else
202 ret = SEC_E_UNSUPPORTED_FUNCTION;
204 else
205 ret = SEC_E_INVALID_HANDLE;
207 else
208 ret = SEC_E_INVALID_HANDLE;
209 return ret;
212 SECURITY_STATUS SEC_ENTRY thunk_InitializeSecurityContextA(
213 PCredHandle phCredential, PCtxtHandle phContext,
214 SEC_CHAR *pszTargetName, ULONG fContextReq,
215 ULONG Reserved1, ULONG TargetDataRep, PSecBufferDesc pInput,
216 ULONG Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pOutput,
217 ULONG *pfContextAttr, PTimeStamp ptsExpiry)
219 SECURITY_STATUS ret;
221 TRACE("%p %p %s %ld %ld %ld %p %ld %p %p %p %p\n", phCredential, phContext,
222 debugstr_a(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
223 Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
224 if (phCredential)
226 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
228 if (package && package->provider)
230 if (package->provider->fnTableW.InitializeSecurityContextW)
232 UNICODE_STRING target;
234 RtlCreateUnicodeStringFromAsciiz(&target, pszTargetName);
235 ret = package->provider->fnTableW.InitializeSecurityContextW(
236 phCredential, phContext, target.Buffer, fContextReq, Reserved1,
237 TargetDataRep, pInput, Reserved2, phNewContext, pOutput,
238 pfContextAttr, ptsExpiry);
239 RtlFreeUnicodeString(&target);
241 else
242 ret = SEC_E_UNSUPPORTED_FUNCTION;
244 else
245 ret = SEC_E_INVALID_HANDLE;
247 else
248 ret = SEC_E_INVALID_HANDLE;
249 return ret;
252 SECURITY_STATUS SEC_ENTRY thunk_InitializeSecurityContextW(
253 PCredHandle phCredential, PCtxtHandle phContext,
254 SEC_WCHAR *pszTargetName, ULONG fContextReq,
255 ULONG Reserved1, ULONG TargetDataRep, PSecBufferDesc pInput,
256 ULONG Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pOutput,
257 ULONG *pfContextAttr, PTimeStamp ptsExpiry)
259 SECURITY_STATUS ret;
261 TRACE("%p %p %s %ld %ld %ld %p %ld %p %p %p %p\n", phCredential, phContext,
262 debugstr_w(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
263 Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
264 if (phCredential)
266 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
268 if (package && package->provider)
270 if (package->provider->fnTableA.InitializeSecurityContextA)
272 char *target = strdupWA(pszTargetName);
274 ret = package->provider->fnTableA.InitializeSecurityContextA(
275 phCredential, phContext, target, fContextReq, Reserved1,
276 TargetDataRep, pInput, Reserved2, phNewContext, pOutput,
277 pfContextAttr, ptsExpiry);
278 RtlFreeHeap(GetProcessHeap(), 0, target);
280 else
281 ret = SEC_E_UNSUPPORTED_FUNCTION;
283 else
284 ret = SEC_E_INVALID_HANDLE;
286 else
287 ret = SEC_E_INVALID_HANDLE;
288 return ret;
291 SECURITY_STATUS SEC_ENTRY thunk_AddCredentialsA(PCredHandle hCredentials,
292 SEC_CHAR *pszPrincipal, SEC_CHAR *pszPackage, ULONG fCredentialUse,
293 void *pAuthData, SEC_GET_KEY_FN pGetKeyFn, void *pvGetKeyArgument,
294 PTimeStamp ptsExpiry)
296 SECURITY_STATUS ret;
298 TRACE("%p %s %s %ld %p %p %p %p\n", hCredentials, debugstr_a(pszPrincipal),
299 debugstr_a(pszPackage), fCredentialUse, pAuthData, pGetKeyFn,
300 pvGetKeyArgument, ptsExpiry);
301 if (hCredentials)
303 SecurePackage *package = (SecurePackage *)hCredentials->dwUpper;
304 PCredHandle cred = (PCtxtHandle)hCredentials->dwLower;
306 if (package && package->provider)
308 if (package->provider->fnTableW.AddCredentialsW)
310 UNICODE_STRING szPrincipal, szPackage;
312 RtlCreateUnicodeStringFromAsciiz(&szPrincipal, pszPrincipal);
313 RtlCreateUnicodeStringFromAsciiz(&szPackage, pszPackage);
314 ret = package->provider->fnTableW.AddCredentialsW(
315 cred, szPrincipal.Buffer, szPackage.Buffer, fCredentialUse,
316 pAuthData, pGetKeyFn, pvGetKeyArgument, ptsExpiry);
317 RtlFreeUnicodeString(&szPrincipal);
318 RtlFreeUnicodeString(&szPackage);
320 else
321 ret = SEC_E_UNSUPPORTED_FUNCTION;
323 else
324 ret = SEC_E_INVALID_HANDLE;
326 else
327 ret = SEC_E_INVALID_HANDLE;
328 return ret;
331 SECURITY_STATUS SEC_ENTRY thunk_AddCredentialsW(PCredHandle hCredentials,
332 SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, ULONG fCredentialUse,
333 void *pAuthData, SEC_GET_KEY_FN pGetKeyFn, void *pvGetKeyArgument,
334 PTimeStamp ptsExpiry)
336 SECURITY_STATUS ret;
338 TRACE("%p %s %s %ld %p %p %p %p\n", hCredentials, debugstr_w(pszPrincipal),
339 debugstr_w(pszPackage), fCredentialUse, pAuthData, pGetKeyFn,
340 pvGetKeyArgument, ptsExpiry);
341 if (hCredentials)
343 SecurePackage *package = (SecurePackage *)hCredentials->dwUpper;
344 PCredHandle cred = (PCtxtHandle)hCredentials->dwLower;
346 if (package && package->provider)
348 if (package->provider->fnTableA.AddCredentialsA)
350 char *szPrincipal = strdupWA(pszPrincipal);
351 char *szPackage = strdupWA(pszPackage);
353 ret = package->provider->fnTableA.AddCredentialsA(
354 cred, szPrincipal, szPackage, fCredentialUse, pAuthData,
355 pGetKeyFn, pvGetKeyArgument, ptsExpiry);
356 RtlFreeHeap(GetProcessHeap(), 0, szPrincipal);
357 RtlFreeHeap(GetProcessHeap(), 0, szPackage);
359 else
360 ret = SEC_E_UNSUPPORTED_FUNCTION;
362 else
363 ret = SEC_E_INVALID_HANDLE;
365 else
366 ret = SEC_E_INVALID_HANDLE;
367 return ret;
370 static PSecPkgInfoA _copyPackageInfoFlatWToA(const SecPkgInfoW *infoW)
372 PSecPkgInfoA ret;
374 if (infoW)
376 size_t bytesNeeded = sizeof(SecPkgInfoA);
377 int nameLen = 0, commentLen = 0;
379 if (infoW->Name)
381 nameLen = WideCharToMultiByte(CP_ACP, 0, infoW->Name, -1,
382 NULL, 0, NULL, NULL);
383 bytesNeeded += nameLen;
385 if (infoW->Comment)
387 commentLen = WideCharToMultiByte(CP_ACP, 0, infoW->Comment, -1,
388 NULL, 0, NULL, NULL);
389 bytesNeeded += commentLen;
391 if ((ret = RtlAllocateHeap(GetProcessHeap(), 0, bytesNeeded)))
393 char *nextString = (char *)ret + sizeof(SecPkgInfoA);
395 memcpy(ret, infoW, sizeof(SecPkgInfoA));
396 if (infoW->Name)
398 ret->Name = nextString;
399 WideCharToMultiByte(CP_ACP, 0, infoW->Name, -1, nextString, nameLen, NULL, NULL);
400 nextString += nameLen;
402 else
403 ret->Name = NULL;
404 if (infoW->Comment)
406 ret->Comment = nextString;
407 WideCharToMultiByte(CP_ACP, 0, infoW->Comment, -1, nextString, nameLen, NULL, NULL);
409 else
410 ret->Comment = NULL;
413 else
414 ret = NULL;
415 return ret;
418 static SECURITY_STATUS thunk_ContextAttributesWToA(SecurePackage *package,
419 ULONG ulAttribute, void *pBuffer)
421 SECURITY_STATUS ret = SEC_E_OK;
423 if (package && pBuffer)
425 switch (ulAttribute)
427 case SECPKG_ATTR_NAMES:
429 PSecPkgContext_NamesW names = (PSecPkgContext_NamesW)pBuffer;
430 SEC_WCHAR *oldUser = names->sUserName;
432 if (oldUser)
434 names->sUserName = (WCHAR *)strdupWA(oldUser);
435 package->provider->fnTableW.FreeContextBuffer(oldUser);
437 break;
439 case SECPKG_ATTR_AUTHORITY:
441 PSecPkgContext_AuthorityW names = (PSecPkgContext_AuthorityW)pBuffer;
442 SEC_WCHAR *oldAuth = names->sAuthorityName;
444 if (oldAuth)
446 names->sAuthorityName = (WCHAR *)strdupWA(oldAuth);
447 package->provider->fnTableW.FreeContextBuffer(oldAuth);
449 break;
451 case SECPKG_ATTR_KEY_INFO:
453 PSecPkgContext_KeyInfoW info = (PSecPkgContext_KeyInfoW)pBuffer;
454 SEC_WCHAR *oldSigAlgName = info->sSignatureAlgorithmName;
455 SEC_WCHAR *oldEncAlgName = info->sEncryptAlgorithmName;
457 if (oldSigAlgName)
459 info->sSignatureAlgorithmName = (WCHAR *)strdupWA(oldSigAlgName);
460 package->provider->fnTableW.FreeContextBuffer(oldSigAlgName);
462 if (oldEncAlgName)
464 info->sEncryptAlgorithmName = (WCHAR *)strdupWA(oldEncAlgName);
465 package->provider->fnTableW.FreeContextBuffer(oldEncAlgName);
467 break;
469 case SECPKG_ATTR_PACKAGE_INFO:
471 PSecPkgContext_PackageInfoW info = (PSecPkgContext_PackageInfoW)pBuffer;
472 PSecPkgInfoW oldPkgInfo = info->PackageInfo;
474 if (oldPkgInfo)
476 info->PackageInfo = (PSecPkgInfoW)
477 _copyPackageInfoFlatWToA(oldPkgInfo);
478 package->provider->fnTableW.FreeContextBuffer(oldPkgInfo);
480 break;
482 case SECPKG_ATTR_NEGOTIATION_INFO:
484 PSecPkgContext_NegotiationInfoW info = (PSecPkgContext_NegotiationInfoW)pBuffer;
485 PSecPkgInfoW oldPkgInfo = info->PackageInfo;
487 if (oldPkgInfo)
489 info->PackageInfo = (PSecPkgInfoW)
490 _copyPackageInfoFlatWToA(oldPkgInfo);
491 package->provider->fnTableW.FreeContextBuffer(oldPkgInfo);
493 break;
495 case SECPKG_ATTR_NATIVE_NAMES:
497 PSecPkgContext_NativeNamesW names = (PSecPkgContext_NativeNamesW)pBuffer;
498 WCHAR *oldClient = names->sClientName;
499 WCHAR *oldServer = names->sServerName;
501 if (oldClient)
503 names->sClientName = (WCHAR *)strdupWA(oldClient);
504 package->provider->fnTableW.FreeContextBuffer(oldClient);
506 if (oldServer)
508 names->sServerName = (WCHAR *)strdupWA(oldServer);
509 package->provider->fnTableW.FreeContextBuffer(oldServer);
511 break;
513 case SECPKG_ATTR_CREDENTIAL_NAME:
515 PSecPkgContext_CredentialNameW name = (PSecPkgContext_CredentialNameW)pBuffer;
516 WCHAR *oldCred = name->sCredentialName;
518 if (oldCred)
520 name->sCredentialName = (WCHAR *)strdupWA(oldCred);
521 package->provider->fnTableW.FreeContextBuffer(oldCred);
523 break;
525 /* no thunking needed: */
526 case SECPKG_ATTR_ACCESS_TOKEN:
527 case SECPKG_ATTR_DCE_INFO:
528 case SECPKG_ATTR_FLAGS:
529 case SECPKG_ATTR_LIFESPAN:
530 case SECPKG_ATTR_PASSWORD_EXPIRY:
531 case SECPKG_ATTR_SESSION_KEY:
532 case SECPKG_ATTR_SIZES:
533 case SECPKG_ATTR_STREAM_SIZES:
534 case SECPKG_ATTR_TARGET_INFORMATION:
535 break;
536 default:
537 WARN("attribute type %ld unknown\n", ulAttribute);
538 ret = SEC_E_INTERNAL_ERROR;
541 else
542 ret = SEC_E_INVALID_TOKEN;
543 return ret;
546 SECURITY_STATUS SEC_ENTRY thunk_QueryContextAttributesA(PCtxtHandle phContext,
547 ULONG ulAttribute, void *pBuffer)
549 SECURITY_STATUS ret;
551 TRACE("%p %ld %p\n", phContext, ulAttribute, pBuffer);
552 if (phContext)
554 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
555 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
557 if (package && package->provider)
559 if (package->provider->fnTableW.QueryContextAttributesW)
561 ret = package->provider->fnTableW.QueryContextAttributesW( ctxt, ulAttribute, pBuffer);
562 if (ret == SEC_E_OK)
563 ret = thunk_ContextAttributesWToA(package, ulAttribute, pBuffer);
565 else
566 ret = SEC_E_UNSUPPORTED_FUNCTION;
568 else
569 ret = SEC_E_INVALID_HANDLE;
571 else
572 ret = SEC_E_INVALID_HANDLE;
573 return ret;
576 static PSecPkgInfoW _copyPackageInfoFlatAToW(const SecPkgInfoA *infoA)
578 PSecPkgInfoW ret;
580 if (infoA)
582 size_t bytesNeeded = sizeof(SecPkgInfoW);
583 int nameLen = 0, commentLen = 0;
585 if (infoA->Name)
587 nameLen = MultiByteToWideChar(CP_ACP, 0, infoA->Name, -1, NULL, 0);
588 bytesNeeded += nameLen * sizeof(WCHAR);
590 if (infoA->Comment)
592 commentLen = MultiByteToWideChar(CP_ACP, 0, infoA->Comment, -1, NULL, 0);
593 bytesNeeded += commentLen * sizeof(WCHAR);
595 if ((ret = RtlAllocateHeap(GetProcessHeap(), 0, bytesNeeded)))
597 WCHAR *nextString = (WCHAR *)(char *)ret + sizeof(SecPkgInfoW);
599 memcpy(ret, infoA, sizeof(SecPkgInfoA));
600 if (infoA->Name)
602 ret->Name = nextString;
603 MultiByteToWideChar(CP_ACP, 0, infoA->Name, -1, nextString, nameLen);
604 nextString += nameLen;
606 else
607 ret->Name = NULL;
608 if (infoA->Comment)
610 ret->Comment = nextString;
611 MultiByteToWideChar(CP_ACP, 0, infoA->Comment, -1, nextString, commentLen);
613 else
614 ret->Comment = NULL;
617 else
618 ret = NULL;
619 return ret;
622 static SECURITY_STATUS thunk_ContextAttributesAToW(SecurePackage *package,
623 ULONG ulAttribute, void *pBuffer)
625 SECURITY_STATUS ret = SEC_E_OK;
627 if (package && pBuffer)
629 switch (ulAttribute)
631 case SECPKG_ATTR_NAMES:
633 PSecPkgContext_NamesA names = (PSecPkgContext_NamesA)pBuffer;
634 SEC_CHAR *oldUser = names->sUserName;
636 if (oldUser)
638 names->sUserName = (char *)strdupAW(oldUser);
639 package->provider->fnTableW.FreeContextBuffer(oldUser);
641 break;
643 case SECPKG_ATTR_AUTHORITY:
645 PSecPkgContext_AuthorityA names = (PSecPkgContext_AuthorityA)pBuffer;
646 SEC_CHAR *oldAuth = names->sAuthorityName;
648 if (oldAuth)
650 names->sAuthorityName = (char *)strdupAW(oldAuth);
651 package->provider->fnTableW.FreeContextBuffer(oldAuth);
653 break;
655 case SECPKG_ATTR_KEY_INFO:
657 PSecPkgContext_KeyInfoA info = (PSecPkgContext_KeyInfoA)pBuffer;
658 SEC_CHAR *oldSigAlgName = info->sSignatureAlgorithmName;
659 SEC_CHAR *oldEncAlgName = info->sEncryptAlgorithmName;
661 if (oldSigAlgName)
663 info->sSignatureAlgorithmName = (char *)strdupAW(oldSigAlgName);
664 package->provider->fnTableW.FreeContextBuffer(oldSigAlgName);
666 if (oldEncAlgName)
668 info->sEncryptAlgorithmName = (char *)strdupAW(oldEncAlgName);
669 package->provider->fnTableW.FreeContextBuffer(oldEncAlgName);
671 break;
673 case SECPKG_ATTR_PACKAGE_INFO:
675 PSecPkgContext_PackageInfoA info = (PSecPkgContext_PackageInfoA)pBuffer;
676 PSecPkgInfoA oldPkgInfo = info->PackageInfo;
678 if (oldPkgInfo)
680 info->PackageInfo = (PSecPkgInfoA)
681 _copyPackageInfoFlatAToW(oldPkgInfo);
682 package->provider->fnTableW.FreeContextBuffer(oldPkgInfo);
684 break;
686 case SECPKG_ATTR_NEGOTIATION_INFO:
688 PSecPkgContext_NegotiationInfoA info = (PSecPkgContext_NegotiationInfoA)pBuffer;
689 PSecPkgInfoA oldPkgInfo = info->PackageInfo;
691 if (oldPkgInfo)
693 info->PackageInfo = (PSecPkgInfoA)
694 _copyPackageInfoFlatAToW(oldPkgInfo);
695 package->provider->fnTableW.FreeContextBuffer(oldPkgInfo);
697 break;
699 case SECPKG_ATTR_NATIVE_NAMES:
701 PSecPkgContext_NativeNamesA names = (PSecPkgContext_NativeNamesA)pBuffer;
702 char *oldClient = names->sClientName;
703 char *oldServer = names->sServerName;
705 if (oldClient)
707 names->sClientName = (char *)strdupAW(oldClient);
708 package->provider->fnTableW.FreeContextBuffer(oldClient);
710 if (oldServer)
712 names->sServerName = (char *)strdupAW(oldServer);
713 package->provider->fnTableW.FreeContextBuffer(oldServer);
715 break;
717 case SECPKG_ATTR_CREDENTIAL_NAME:
719 PSecPkgContext_CredentialNameA name = (PSecPkgContext_CredentialNameA)pBuffer;
720 char *oldCred = name->sCredentialName;
722 if (oldCred)
724 name->sCredentialName = (char *)strdupAW(oldCred);
725 package->provider->fnTableW.FreeContextBuffer(oldCred);
727 break;
729 /* no thunking needed: */
730 case SECPKG_ATTR_ACCESS_TOKEN:
731 case SECPKG_ATTR_DCE_INFO:
732 case SECPKG_ATTR_FLAGS:
733 case SECPKG_ATTR_LIFESPAN:
734 case SECPKG_ATTR_PASSWORD_EXPIRY:
735 case SECPKG_ATTR_SESSION_KEY:
736 case SECPKG_ATTR_SIZES:
737 case SECPKG_ATTR_STREAM_SIZES:
738 case SECPKG_ATTR_TARGET_INFORMATION:
739 break;
740 default:
741 WARN("attribute type %ld unknown\n", ulAttribute);
742 ret = SEC_E_INTERNAL_ERROR;
745 else
746 ret = SEC_E_INVALID_TOKEN;
747 return ret;
750 SECURITY_STATUS SEC_ENTRY thunk_QueryContextAttributesW(PCtxtHandle phContext,
751 ULONG ulAttribute, void *pBuffer)
753 SECURITY_STATUS ret;
755 TRACE("%p %ld %p\n", phContext, ulAttribute, pBuffer);
756 if (phContext)
758 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
759 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
761 if (package && package->provider)
763 if (package->provider->fnTableA.QueryContextAttributesA)
765 ret = package->provider->fnTableA.QueryContextAttributesA(ctxt, ulAttribute, pBuffer);
766 if (ret == SEC_E_OK)
767 ret = thunk_ContextAttributesAToW(package, ulAttribute, pBuffer);
769 else
770 ret = SEC_E_UNSUPPORTED_FUNCTION;
772 else
773 ret = SEC_E_INVALID_HANDLE;
775 else
776 ret = SEC_E_INVALID_HANDLE;
777 return ret;
780 SECURITY_STATUS SEC_ENTRY thunk_SetContextAttributesA(PCtxtHandle phContext,
781 ULONG ulAttribute, void *pBuffer, ULONG cbBuffer)
783 SECURITY_STATUS ret;
785 TRACE("%p %ld %p %ld\n", phContext, ulAttribute, pBuffer, cbBuffer);
786 if (phContext)
788 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
789 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
791 if (package && package->provider && pBuffer && cbBuffer)
793 if (package->provider->fnTableW.SetContextAttributesW)
795 /* TODO: gotta validate size too! */
796 ret = thunk_ContextAttributesWToA(package, ulAttribute, pBuffer);
797 if (ret == SEC_E_OK)
798 ret = package->provider->fnTableW.SetContextAttributesW(ctxt, ulAttribute, pBuffer, cbBuffer);
800 else
801 ret = SEC_E_UNSUPPORTED_FUNCTION;
803 else
804 ret = SEC_E_INVALID_HANDLE;
806 else
807 ret = SEC_E_INVALID_HANDLE;
808 return ret;
811 SECURITY_STATUS SEC_ENTRY thunk_SetContextAttributesW(PCtxtHandle phContext,
812 ULONG ulAttribute, void *pBuffer, ULONG cbBuffer)
814 SECURITY_STATUS ret;
816 TRACE("%p %ld %p %ld\n", phContext, ulAttribute, pBuffer, cbBuffer);
817 if (phContext)
819 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
820 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
822 if (package && package->provider && pBuffer && cbBuffer)
824 if (package->provider->fnTableA.SetContextAttributesA)
826 /* TODO: gotta validate size too! */
827 ret = thunk_ContextAttributesAToW(package, ulAttribute, pBuffer);
828 if (ret == SEC_E_OK)
829 ret = package->provider->fnTableA.SetContextAttributesA(ctxt, ulAttribute, pBuffer, cbBuffer);
831 else
832 ret = SEC_E_UNSUPPORTED_FUNCTION;
834 else
835 ret = SEC_E_INVALID_HANDLE;
837 else
838 ret = SEC_E_INVALID_HANDLE;
839 return ret;
842 SECURITY_STATUS SEC_ENTRY thunk_ImportSecurityContextA(
843 SEC_CHAR *pszPackage, PSecBuffer pPackedContext, void *Token,
844 PCtxtHandle phContext)
846 SECURITY_STATUS ret;
847 UNICODE_STRING package;
849 TRACE("%s %p %p %p\n", debugstr_a(pszPackage), pPackedContext, Token, phContext);
850 RtlCreateUnicodeStringFromAsciiz(&package, pszPackage);
851 ret = ImportSecurityContextW(package.Buffer, pPackedContext, Token, phContext);
852 RtlFreeUnicodeString(&package);
853 return ret;
856 SECURITY_STATUS SEC_ENTRY thunk_ImportSecurityContextW(
857 SEC_WCHAR *pszPackage, PSecBuffer pPackedContext, void *Token,
858 PCtxtHandle phContext)
860 SECURITY_STATUS ret;
861 char *package = strdupWA(pszPackage);
863 TRACE("%s %p %p %p\n", debugstr_w(pszPackage), pPackedContext, Token, phContext);
864 ret = ImportSecurityContextA(package, pPackedContext, Token, phContext);
865 RtlFreeHeap(GetProcessHeap(), 0, package);
866 return ret;