include: Specify calling convention explicitly in idl files where needed.
[wine/hramrach.git] / dlls / secur32 / thunks.c
blob33f8bb1ce5b5bbcc5f7b560718890099513ad644
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
20 #include <stdarg.h>
21 #include "windef.h"
22 #include "winbase.h"
23 #include "winnls.h"
24 #include "winternl.h"
25 #include "sspi.h"
26 #include "secur32_priv.h"
27 #include "thunks.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(secur32);
33 SECURITY_STATUS SEC_ENTRY thunk_AcquireCredentialsHandleA(
34 SEC_CHAR *pszPrincipal, SEC_CHAR *pszPackage, ULONG fCredentialsUse,
35 PLUID pvLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn,
36 PVOID pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
38 SECURITY_STATUS ret;
40 TRACE("%s %s %d %p %p %p %p %p %p\n", debugstr_a(pszPrincipal),
41 debugstr_a(pszPackage), fCredentialsUse, pvLogonID, pAuthData, pGetKeyFn,
42 pvGetKeyArgument, phCredential, ptsExpiry);
43 if (pszPackage)
45 UNICODE_STRING principal, package;
47 RtlCreateUnicodeStringFromAsciiz(&principal, pszPrincipal);
48 RtlCreateUnicodeStringFromAsciiz(&package, pszPackage);
49 ret = AcquireCredentialsHandleW(principal.Buffer, package.Buffer,
50 fCredentialsUse, pvLogonID, pAuthData, pGetKeyFn, pvGetKeyArgument,
51 phCredential, ptsExpiry);
52 RtlFreeUnicodeString(&principal);
53 RtlFreeUnicodeString(&package);
55 else
56 ret = SEC_E_SECPKG_NOT_FOUND;
57 return ret;
60 SECURITY_STATUS SEC_ENTRY thunk_AcquireCredentialsHandleW(
61 SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, ULONG fCredentialsUse,
62 PLUID pvLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn,
63 PVOID pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
65 SECURITY_STATUS ret;
67 TRACE("%s %s %d %p %p %p %p %p %p\n", debugstr_w(pszPrincipal),
68 debugstr_w(pszPackage), fCredentialsUse, pvLogonID, pAuthData, pGetKeyFn,
69 pvGetKeyArgument, phCredential, ptsExpiry);
70 if (pszPackage)
72 PSTR principal, package;
74 principal = SECUR32_AllocMultiByteFromWide(pszPrincipal);
75 package = SECUR32_AllocMultiByteFromWide(pszPackage);
76 ret = AcquireCredentialsHandleA(principal, package, fCredentialsUse,
77 pvLogonID, pAuthData, pGetKeyFn, pvGetKeyArgument, phCredential,
78 ptsExpiry);
79 HeapFree(GetProcessHeap(), 0, principal);
80 HeapFree(GetProcessHeap(), 0, package);
82 else
83 ret = SEC_E_SECPKG_NOT_FOUND;
84 return ret;
87 /* thunking is pretty dicey for these--the output type depends on ulAttribute,
88 * so we have to know about every type the caller does
90 SECURITY_STATUS SEC_ENTRY thunk_QueryCredentialsAttributesA(
91 PCredHandle phCredential, ULONG ulAttribute, void *pBuffer)
93 SECURITY_STATUS ret;
95 TRACE("%p %d %p\n", phCredential, ulAttribute, pBuffer);
96 if (phCredential)
98 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
99 PCredHandle cred = (PCredHandle)phCredential->dwLower;
101 if (package && package->provider)
103 if (package->provider->fnTableW.QueryCredentialsAttributesW)
105 ret = package->provider->fnTableW.QueryCredentialsAttributesW(
106 cred, ulAttribute, pBuffer);
107 if (ret == SEC_E_OK)
109 switch (ulAttribute)
111 case SECPKG_CRED_ATTR_NAMES:
113 PSecPkgCredentials_NamesW names =
114 (PSecPkgCredentials_NamesW)pBuffer;
115 SEC_WCHAR *oldUser = names->sUserName;
117 if (oldUser)
119 names->sUserName =
120 (PWSTR)SECUR32_AllocMultiByteFromWide(oldUser);
121 package->provider->fnTableW.FreeContextBuffer(
122 oldUser);
124 break;
126 default:
127 WARN("attribute type %d unknown\n", ulAttribute);
128 ret = SEC_E_INTERNAL_ERROR;
132 else
133 ret = SEC_E_UNSUPPORTED_FUNCTION;
135 else
136 ret = SEC_E_INVALID_HANDLE;
138 else
139 ret = SEC_E_INVALID_HANDLE;
140 return ret;
143 SECURITY_STATUS SEC_ENTRY thunk_QueryCredentialsAttributesW(
144 PCredHandle phCredential, ULONG ulAttribute, void *pBuffer)
146 SECURITY_STATUS ret;
148 TRACE("%p %d %p\n", phCredential, ulAttribute, pBuffer);
149 if (phCredential)
151 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
152 PCredHandle cred = (PCredHandle)phCredential->dwLower;
154 if (package && package->provider)
156 if (package->provider->fnTableA.QueryCredentialsAttributesA)
158 ret = package->provider->fnTableA.QueryCredentialsAttributesA(
159 cred, ulAttribute, pBuffer);
160 if (ret == SEC_E_OK)
162 switch (ulAttribute)
164 case SECPKG_CRED_ATTR_NAMES:
166 PSecPkgCredentials_NamesA names =
167 (PSecPkgCredentials_NamesA)pBuffer;
168 SEC_CHAR *oldUser = names->sUserName;
170 if (oldUser)
172 names->sUserName =
173 (PSTR)SECUR32_AllocWideFromMultiByte(oldUser);
174 package->provider->fnTableA.FreeContextBuffer(
175 oldUser);
177 break;
179 default:
180 WARN("attribute type %d unknown\n", ulAttribute);
181 ret = SEC_E_INTERNAL_ERROR;
185 else
186 ret = SEC_E_UNSUPPORTED_FUNCTION;
188 else
189 ret = SEC_E_INVALID_HANDLE;
191 else
192 ret = SEC_E_INVALID_HANDLE;
193 return ret;
196 SECURITY_STATUS SEC_ENTRY thunk_InitializeSecurityContextA(
197 PCredHandle phCredential, PCtxtHandle phContext,
198 SEC_CHAR *pszTargetName, ULONG fContextReq,
199 ULONG Reserved1, ULONG TargetDataRep, PSecBufferDesc pInput,
200 ULONG Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pOutput,
201 ULONG *pfContextAttr, PTimeStamp ptsExpiry)
203 SECURITY_STATUS ret;
205 TRACE("%p %p %s %d %d %d %p %d %p %p %p %p\n", phCredential, phContext,
206 debugstr_a(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
207 Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
208 if (phCredential)
210 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
212 if (package && package->provider)
214 if (package->provider->fnTableW.InitializeSecurityContextW)
216 UNICODE_STRING target;
218 RtlCreateUnicodeStringFromAsciiz(&target, pszTargetName);
219 ret = package->provider->fnTableW.InitializeSecurityContextW(
220 phCredential, phContext, target.Buffer, fContextReq, Reserved1,
221 TargetDataRep, pInput, Reserved2, phNewContext, pOutput,
222 pfContextAttr, ptsExpiry);
223 RtlFreeUnicodeString(&target);
225 else
226 ret = SEC_E_UNSUPPORTED_FUNCTION;
228 else
229 ret = SEC_E_INVALID_HANDLE;
231 else
232 ret = SEC_E_INVALID_HANDLE;
233 return ret;
236 SECURITY_STATUS SEC_ENTRY thunk_InitializeSecurityContextW(
237 PCredHandle phCredential, PCtxtHandle phContext,
238 SEC_WCHAR *pszTargetName, ULONG fContextReq,
239 ULONG Reserved1, ULONG TargetDataRep, PSecBufferDesc pInput,
240 ULONG Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pOutput,
241 ULONG *pfContextAttr, PTimeStamp ptsExpiry)
243 SECURITY_STATUS ret;
245 TRACE("%p %p %s %d %d %d %p %d %p %p %p %p\n", phCredential, phContext,
246 debugstr_w(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
247 Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
248 if (phCredential)
250 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
252 if (package && package->provider)
254 if (package->provider->fnTableA.InitializeSecurityContextA)
256 PSTR target = SECUR32_AllocMultiByteFromWide(pszTargetName);
258 ret = package->provider->fnTableA.InitializeSecurityContextA(
259 phCredential, phContext, target, fContextReq, Reserved1,
260 TargetDataRep, pInput, Reserved2, phNewContext, pOutput,
261 pfContextAttr, ptsExpiry);
262 HeapFree(GetProcessHeap(), 0, target);
264 else
265 ret = SEC_E_UNSUPPORTED_FUNCTION;
267 else
268 ret = SEC_E_INVALID_HANDLE;
270 else
271 ret = SEC_E_INVALID_HANDLE;
272 return ret;
275 SECURITY_STATUS SEC_ENTRY thunk_AddCredentialsA(PCredHandle hCredentials,
276 SEC_CHAR *pszPrincipal, SEC_CHAR *pszPackage, ULONG fCredentialUse,
277 void *pAuthData, SEC_GET_KEY_FN pGetKeyFn, void *pvGetKeyArgument,
278 PTimeStamp ptsExpiry)
280 SECURITY_STATUS ret;
282 TRACE("%p %s %s %d %p %p %p %p\n", hCredentials, debugstr_a(pszPrincipal),
283 debugstr_a(pszPackage), fCredentialUse, pAuthData, pGetKeyFn,
284 pvGetKeyArgument, ptsExpiry);
285 if (hCredentials)
287 SecurePackage *package = (SecurePackage *)hCredentials->dwUpper;
288 PCredHandle cred = (PCtxtHandle)hCredentials->dwLower;
290 if (package && package->provider)
292 if (package->provider->fnTableW.AddCredentialsW)
294 UNICODE_STRING szPrincipal, szPackage;
296 RtlCreateUnicodeStringFromAsciiz(&szPrincipal, pszPrincipal);
297 RtlCreateUnicodeStringFromAsciiz(&szPackage, pszPackage);
298 ret = package->provider->fnTableW.AddCredentialsW(
299 cred, szPrincipal.Buffer, szPackage.Buffer, fCredentialUse,
300 pAuthData, pGetKeyFn, pvGetKeyArgument, ptsExpiry);
301 RtlFreeUnicodeString(&szPrincipal);
302 RtlFreeUnicodeString(&szPackage);
304 else
305 ret = SEC_E_UNSUPPORTED_FUNCTION;
307 else
308 ret = SEC_E_INVALID_HANDLE;
310 else
311 ret = SEC_E_INVALID_HANDLE;
312 return ret;
315 SECURITY_STATUS SEC_ENTRY thunk_AddCredentialsW(PCredHandle hCredentials,
316 SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, ULONG fCredentialUse,
317 void *pAuthData, SEC_GET_KEY_FN pGetKeyFn, void *pvGetKeyArgument,
318 PTimeStamp ptsExpiry)
320 SECURITY_STATUS ret;
322 TRACE("%p %s %s %d %p %p %p %p\n", hCredentials, debugstr_w(pszPrincipal),
323 debugstr_w(pszPackage), fCredentialUse, pAuthData, pGetKeyFn,
324 pvGetKeyArgument, ptsExpiry);
325 if (hCredentials)
327 SecurePackage *package = (SecurePackage *)hCredentials->dwUpper;
328 PCredHandle cred = (PCtxtHandle)hCredentials->dwLower;
330 if (package && package->provider)
332 if (package->provider->fnTableA.AddCredentialsA)
334 PSTR szPrincipal = SECUR32_AllocMultiByteFromWide(pszPrincipal);
335 PSTR szPackage = SECUR32_AllocMultiByteFromWide(pszPackage);
337 ret = package->provider->fnTableA.AddCredentialsA(
338 cred, szPrincipal, szPackage, fCredentialUse, pAuthData,
339 pGetKeyFn, pvGetKeyArgument, ptsExpiry);
340 HeapFree(GetProcessHeap(), 0, szPrincipal);
341 HeapFree(GetProcessHeap(), 0, szPackage);
343 else
344 ret = SEC_E_UNSUPPORTED_FUNCTION;
346 else
347 ret = SEC_E_INVALID_HANDLE;
349 else
350 ret = SEC_E_INVALID_HANDLE;
351 return ret;
354 static PSecPkgInfoA _copyPackageInfoFlatWToA(const SecPkgInfoW *infoW)
356 PSecPkgInfoA ret;
358 if (infoW)
360 size_t bytesNeeded = sizeof(SecPkgInfoA);
361 int nameLen = 0, commentLen = 0;
363 if (infoW->Name)
365 nameLen = WideCharToMultiByte(CP_ACP, 0, infoW->Name, -1,
366 NULL, 0, NULL, NULL);
367 bytesNeeded += nameLen;
369 if (infoW->Comment)
371 commentLen = WideCharToMultiByte(CP_ACP, 0, infoW->Comment, -1,
372 NULL, 0, NULL, NULL);
373 bytesNeeded += commentLen;
375 ret = HeapAlloc(GetProcessHeap(), 0, bytesNeeded);
376 if (ret)
378 PSTR nextString = (PSTR)((PBYTE)ret + sizeof(SecPkgInfoA));
380 memcpy(ret, infoW, sizeof(SecPkgInfoA));
381 if (infoW->Name)
383 ret->Name = nextString;
384 WideCharToMultiByte(CP_ACP, 0, infoW->Name, -1, nextString,
385 nameLen, NULL, NULL);
386 nextString += nameLen;
388 else
389 ret->Name = NULL;
390 if (infoW->Comment)
392 ret->Comment = nextString;
393 WideCharToMultiByte(CP_ACP, 0, infoW->Comment, -1, nextString,
394 nameLen, NULL, NULL);
396 else
397 ret->Comment = NULL;
400 else
401 ret = NULL;
402 return ret;
405 static SECURITY_STATUS thunk_ContextAttributesWToA(SecurePackage *package,
406 ULONG ulAttribute, void *pBuffer)
408 SECURITY_STATUS ret = SEC_E_OK;
410 if (package && pBuffer)
412 switch (ulAttribute)
414 case SECPKG_ATTR_NAMES:
416 PSecPkgContext_NamesW names = (PSecPkgContext_NamesW)pBuffer;
417 SEC_WCHAR *oldUser = names->sUserName;
419 if (oldUser)
421 names->sUserName =
422 (PWSTR)SECUR32_AllocMultiByteFromWide(oldUser);
423 package->provider->fnTableW.FreeContextBuffer(oldUser);
425 break;
427 case SECPKG_ATTR_AUTHORITY:
429 PSecPkgContext_AuthorityW names =
430 (PSecPkgContext_AuthorityW)pBuffer;
431 SEC_WCHAR *oldAuth = names->sAuthorityName;
433 if (oldAuth)
435 names->sAuthorityName =
436 (PWSTR)SECUR32_AllocMultiByteFromWide(oldAuth);
437 package->provider->fnTableW.FreeContextBuffer(oldAuth);
439 break;
441 case SECPKG_ATTR_KEY_INFO:
443 PSecPkgContext_KeyInfoW info = (PSecPkgContext_KeyInfoW)pBuffer;
444 SEC_WCHAR *oldSigAlgName = info->sSignatureAlgorithmName;
445 SEC_WCHAR *oldEncAlgName = info->sEncryptAlgorithmName;
447 if (oldSigAlgName)
449 info->sSignatureAlgorithmName =
450 (PWSTR)SECUR32_AllocMultiByteFromWide(oldSigAlgName);
451 package->provider->fnTableW.FreeContextBuffer(
452 oldSigAlgName);
454 if (oldEncAlgName)
456 info->sEncryptAlgorithmName =
457 (PWSTR)SECUR32_AllocMultiByteFromWide(oldEncAlgName);
458 package->provider->fnTableW.FreeContextBuffer(
459 oldEncAlgName);
461 break;
463 case SECPKG_ATTR_PACKAGE_INFO:
465 PSecPkgContext_PackageInfoW info =
466 (PSecPkgContext_PackageInfoW)pBuffer;
467 PSecPkgInfoW oldPkgInfo = info->PackageInfo;
469 if (oldPkgInfo)
471 info->PackageInfo = (PSecPkgInfoW)
472 _copyPackageInfoFlatWToA(oldPkgInfo);
473 package->provider->fnTableW.FreeContextBuffer(oldPkgInfo);
475 break;
477 case SECPKG_ATTR_NEGOTIATION_INFO:
479 PSecPkgContext_NegotiationInfoW info =
480 (PSecPkgContext_NegotiationInfoW)pBuffer;
481 PSecPkgInfoW oldPkgInfo = info->PackageInfo;
483 if (oldPkgInfo)
485 info->PackageInfo = (PSecPkgInfoW)
486 _copyPackageInfoFlatWToA(oldPkgInfo);
487 package->provider->fnTableW.FreeContextBuffer(oldPkgInfo);
489 break;
491 case SECPKG_ATTR_NATIVE_NAMES:
493 PSecPkgContext_NativeNamesW names =
494 (PSecPkgContext_NativeNamesW)pBuffer;
495 PWSTR oldClient = names->sClientName;
496 PWSTR oldServer = names->sServerName;
498 if (oldClient)
500 names->sClientName = (PWSTR)SECUR32_AllocMultiByteFromWide(
501 oldClient);
502 package->provider->fnTableW.FreeContextBuffer(oldClient);
504 if (oldServer)
506 names->sServerName = (PWSTR)SECUR32_AllocMultiByteFromWide(
507 oldServer);
508 package->provider->fnTableW.FreeContextBuffer(oldServer);
510 break;
512 case SECPKG_ATTR_CREDENTIAL_NAME:
514 PSecPkgContext_CredentialNameW name =
515 (PSecPkgContext_CredentialNameW)pBuffer;
516 PWSTR oldCred = name->sCredentialName;
518 if (oldCred)
520 name->sCredentialName =
521 (PWSTR)SECUR32_AllocMultiByteFromWide(oldCred);
522 package->provider->fnTableW.FreeContextBuffer(oldCred);
524 break;
526 /* no thunking needed: */
527 case SECPKG_ATTR_ACCESS_TOKEN:
528 case SECPKG_ATTR_DCE_INFO:
529 case SECPKG_ATTR_FLAGS:
530 case SECPKG_ATTR_LIFESPAN:
531 case SECPKG_ATTR_PASSWORD_EXPIRY:
532 case SECPKG_ATTR_SESSION_KEY:
533 case SECPKG_ATTR_SIZES:
534 case SECPKG_ATTR_STREAM_SIZES:
535 case SECPKG_ATTR_TARGET_INFORMATION:
536 break;
537 default:
538 WARN("attribute type %d unknown\n", ulAttribute);
539 ret = SEC_E_INTERNAL_ERROR;
542 else
543 ret = SEC_E_INVALID_TOKEN;
544 return ret;
547 SECURITY_STATUS SEC_ENTRY thunk_QueryContextAttributesA(PCtxtHandle phContext,
548 ULONG ulAttribute, void *pBuffer)
550 SECURITY_STATUS ret;
552 TRACE("%p %d %p\n", phContext, ulAttribute, pBuffer);
553 if (phContext)
555 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
556 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
558 if (package && package->provider)
560 if (package->provider->fnTableW.QueryContextAttributesW)
562 ret = package->provider->fnTableW.QueryContextAttributesW(
563 ctxt, ulAttribute, pBuffer);
564 if (ret == SEC_E_OK)
565 ret = thunk_ContextAttributesWToA(package, ulAttribute,
566 pBuffer);
568 else
569 ret = SEC_E_UNSUPPORTED_FUNCTION;
571 else
572 ret = SEC_E_INVALID_HANDLE;
574 else
575 ret = SEC_E_INVALID_HANDLE;
576 return ret;
579 static PSecPkgInfoW _copyPackageInfoFlatAToW(const SecPkgInfoA *infoA)
581 PSecPkgInfoW ret;
583 if (infoA)
585 size_t bytesNeeded = sizeof(SecPkgInfoW);
586 int nameLen = 0, commentLen = 0;
588 if (infoA->Name)
590 nameLen = MultiByteToWideChar(CP_ACP, 0, infoA->Name, -1,
591 NULL, 0);
592 bytesNeeded += nameLen * sizeof(WCHAR);
594 if (infoA->Comment)
596 commentLen = MultiByteToWideChar(CP_ACP, 0, infoA->Comment, -1,
597 NULL, 0);
598 bytesNeeded += commentLen * sizeof(WCHAR);
600 ret = HeapAlloc(GetProcessHeap(), 0, bytesNeeded);
601 if (ret)
603 PWSTR nextString = (PWSTR)((PBYTE)ret + sizeof(SecPkgInfoW));
605 memcpy(ret, infoA, sizeof(SecPkgInfoA));
606 if (infoA->Name)
608 ret->Name = nextString;
609 MultiByteToWideChar(CP_ACP, 0, infoA->Name, -1, nextString,
610 nameLen);
611 nextString += nameLen;
613 else
614 ret->Name = NULL;
615 if (infoA->Comment)
617 ret->Comment = nextString;
618 MultiByteToWideChar(CP_ACP, 0, infoA->Comment, -1, nextString,
619 commentLen);
621 else
622 ret->Comment = NULL;
625 else
626 ret = NULL;
627 return ret;
630 static SECURITY_STATUS thunk_ContextAttributesAToW(SecurePackage *package,
631 ULONG ulAttribute, void *pBuffer)
633 SECURITY_STATUS ret = SEC_E_OK;
635 if (package && pBuffer)
637 switch (ulAttribute)
639 case SECPKG_ATTR_NAMES:
641 PSecPkgContext_NamesA names = (PSecPkgContext_NamesA)pBuffer;
642 SEC_CHAR *oldUser = names->sUserName;
644 if (oldUser)
646 names->sUserName =
647 (PSTR)SECUR32_AllocWideFromMultiByte(oldUser);
648 package->provider->fnTableW.FreeContextBuffer(oldUser);
650 break;
652 case SECPKG_ATTR_AUTHORITY:
654 PSecPkgContext_AuthorityA names =
655 (PSecPkgContext_AuthorityA)pBuffer;
656 SEC_CHAR *oldAuth = names->sAuthorityName;
658 if (oldAuth)
660 names->sAuthorityName =
661 (PSTR)SECUR32_AllocWideFromMultiByte(oldAuth);
662 package->provider->fnTableW.FreeContextBuffer(oldAuth);
664 break;
666 case SECPKG_ATTR_KEY_INFO:
668 PSecPkgContext_KeyInfoA info = (PSecPkgContext_KeyInfoA)pBuffer;
669 SEC_CHAR *oldSigAlgName = info->sSignatureAlgorithmName;
670 SEC_CHAR *oldEncAlgName = info->sEncryptAlgorithmName;
672 if (oldSigAlgName)
674 info->sSignatureAlgorithmName =
675 (PSTR)SECUR32_AllocWideFromMultiByte(oldSigAlgName);
676 package->provider->fnTableW.FreeContextBuffer(
677 oldSigAlgName);
679 if (oldEncAlgName)
681 info->sEncryptAlgorithmName =
682 (PSTR)SECUR32_AllocWideFromMultiByte(
683 oldEncAlgName);
684 package->provider->fnTableW.FreeContextBuffer(
685 oldEncAlgName);
687 break;
689 case SECPKG_ATTR_PACKAGE_INFO:
691 PSecPkgContext_PackageInfoA info =
692 (PSecPkgContext_PackageInfoA)pBuffer;
693 PSecPkgInfoA oldPkgInfo = info->PackageInfo;
695 if (oldPkgInfo)
697 info->PackageInfo = (PSecPkgInfoA)
698 _copyPackageInfoFlatAToW(oldPkgInfo);
699 package->provider->fnTableW.FreeContextBuffer(oldPkgInfo);
701 break;
703 case SECPKG_ATTR_NEGOTIATION_INFO:
705 PSecPkgContext_NegotiationInfoA info =
706 (PSecPkgContext_NegotiationInfoA)pBuffer;
707 PSecPkgInfoA oldPkgInfo = info->PackageInfo;
709 if (oldPkgInfo)
711 info->PackageInfo = (PSecPkgInfoA)
712 _copyPackageInfoFlatAToW(oldPkgInfo);
713 package->provider->fnTableW.FreeContextBuffer(oldPkgInfo);
715 break;
717 case SECPKG_ATTR_NATIVE_NAMES:
719 PSecPkgContext_NativeNamesA names =
720 (PSecPkgContext_NativeNamesA)pBuffer;
721 PSTR oldClient = names->sClientName;
722 PSTR oldServer = names->sServerName;
724 if (oldClient)
726 names->sClientName = (PSTR)SECUR32_AllocWideFromMultiByte(
727 oldClient);
728 package->provider->fnTableW.FreeContextBuffer(oldClient);
730 if (oldServer)
732 names->sServerName = (PSTR)SECUR32_AllocWideFromMultiByte(
733 oldServer);
734 package->provider->fnTableW.FreeContextBuffer(oldServer);
736 break;
738 case SECPKG_ATTR_CREDENTIAL_NAME:
740 PSecPkgContext_CredentialNameA name =
741 (PSecPkgContext_CredentialNameA)pBuffer;
742 PSTR oldCred = name->sCredentialName;
744 if (oldCred)
746 name->sCredentialName =
747 (PSTR)SECUR32_AllocWideFromMultiByte(oldCred);
748 package->provider->fnTableW.FreeContextBuffer(oldCred);
750 break;
752 /* no thunking needed: */
753 case SECPKG_ATTR_ACCESS_TOKEN:
754 case SECPKG_ATTR_DCE_INFO:
755 case SECPKG_ATTR_FLAGS:
756 case SECPKG_ATTR_LIFESPAN:
757 case SECPKG_ATTR_PASSWORD_EXPIRY:
758 case SECPKG_ATTR_SESSION_KEY:
759 case SECPKG_ATTR_SIZES:
760 case SECPKG_ATTR_STREAM_SIZES:
761 case SECPKG_ATTR_TARGET_INFORMATION:
762 break;
763 default:
764 WARN("attribute type %d unknown\n", ulAttribute);
765 ret = SEC_E_INTERNAL_ERROR;
768 else
769 ret = SEC_E_INVALID_TOKEN;
770 return ret;
773 SECURITY_STATUS SEC_ENTRY thunk_QueryContextAttributesW(PCtxtHandle phContext,
774 ULONG ulAttribute, void *pBuffer)
776 SECURITY_STATUS ret;
778 TRACE("%p %d %p\n", phContext, ulAttribute, pBuffer);
779 if (phContext)
781 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
782 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
784 if (package && package->provider)
786 if (package->provider->fnTableA.QueryContextAttributesA)
788 ret = package->provider->fnTableA.QueryContextAttributesA(
789 ctxt, ulAttribute, pBuffer);
790 if (ret == SEC_E_OK)
791 ret = thunk_ContextAttributesAToW(package, ulAttribute,
792 pBuffer);
794 else
795 ret = SEC_E_UNSUPPORTED_FUNCTION;
797 else
798 ret = SEC_E_INVALID_HANDLE;
800 else
801 ret = SEC_E_INVALID_HANDLE;
802 return ret;
805 SECURITY_STATUS SEC_ENTRY thunk_SetContextAttributesA(PCtxtHandle phContext,
806 ULONG ulAttribute, void *pBuffer, ULONG cbBuffer)
808 SECURITY_STATUS ret;
810 TRACE("%p %d %p %d\n", phContext, ulAttribute, pBuffer, cbBuffer);
811 if (phContext)
813 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
814 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
816 if (package && package->provider && pBuffer && cbBuffer)
818 if (package->provider->fnTableW.SetContextAttributesW)
820 /* TODO: gotta validate size too! */
821 ret = thunk_ContextAttributesWToA(package, ulAttribute,
822 pBuffer);
823 if (ret == SEC_E_OK)
824 ret = package->provider->fnTableW.SetContextAttributesW(
825 ctxt, ulAttribute, pBuffer, cbBuffer);
827 else
828 ret = SEC_E_UNSUPPORTED_FUNCTION;
830 else
831 ret = SEC_E_INVALID_HANDLE;
833 else
834 ret = SEC_E_INVALID_HANDLE;
835 return ret;
838 SECURITY_STATUS SEC_ENTRY thunk_SetContextAttributesW(PCtxtHandle phContext,
839 ULONG ulAttribute, void *pBuffer, ULONG cbBuffer)
841 SECURITY_STATUS ret;
843 TRACE("%p %d %p %d\n", phContext, ulAttribute, pBuffer, cbBuffer);
844 if (phContext)
846 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
847 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
849 if (package && package->provider && pBuffer && cbBuffer)
851 if (package->provider->fnTableA.SetContextAttributesA)
853 /* TODO: gotta validate size too! */
854 ret = thunk_ContextAttributesAToW(package, ulAttribute,
855 pBuffer);
856 if (ret == SEC_E_OK)
857 ret = package->provider->fnTableA.SetContextAttributesA(
858 ctxt, ulAttribute, pBuffer, cbBuffer);
860 else
861 ret = SEC_E_UNSUPPORTED_FUNCTION;
863 else
864 ret = SEC_E_INVALID_HANDLE;
866 else
867 ret = SEC_E_INVALID_HANDLE;
868 return ret;
871 SECURITY_STATUS SEC_ENTRY thunk_ImportSecurityContextA(
872 SEC_CHAR *pszPackage, PSecBuffer pPackedContext, void *Token,
873 PCtxtHandle phContext)
875 SECURITY_STATUS ret;
876 UNICODE_STRING package;
878 TRACE("%s %p %p %p\n", debugstr_a(pszPackage), pPackedContext, Token,
879 phContext);
880 RtlCreateUnicodeStringFromAsciiz(&package, pszPackage);
881 ret = ImportSecurityContextW(package.Buffer, pPackedContext, Token,
882 phContext);
883 RtlFreeUnicodeString(&package);
884 return ret;
887 SECURITY_STATUS SEC_ENTRY thunk_ImportSecurityContextW(
888 SEC_WCHAR *pszPackage, PSecBuffer pPackedContext, void *Token,
889 PCtxtHandle phContext)
891 SECURITY_STATUS ret;
892 PSTR package = SECUR32_AllocMultiByteFromWide(pszPackage);
894 TRACE("%s %p %p %p\n", debugstr_w(pszPackage), pPackedContext, Token,
895 phContext);
896 ret = ImportSecurityContextA(package, pPackedContext, Token, phContext);
897 HeapFree(GetProcessHeap(), 0, package);
898 return ret;