- call CertFreeCertificateContext from CertDeleteCertificateFromStore
[wine/multimedia.git] / dlls / secur32 / thunks.c
blob29092e8c49d6d4e5ee01b75a91a226c93eaf6f46
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <stdarg.h>
21 #include "windef.h"
22 #include "winbase.h"
23 #include "winnls.h"
24 #include "winreg.h"
25 #include "winternl.h"
26 #include "sspi.h"
27 #include "secur32_priv.h"
28 #include "thunks.h"
30 #include "wine/debug.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 SECURITY_STATUS SEC_ENTRY thunk_AcquireCredentialsHandleW(
62 SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, ULONG fCredentialsUse,
63 PLUID pvLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn,
64 PVOID pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
66 SECURITY_STATUS ret;
68 TRACE("%s %s %ld %p %p %p %p %p %p\n", debugstr_w(pszPrincipal),
69 debugstr_w(pszPackage), fCredentialsUse, pvLogonID, pAuthData, pGetKeyFn,
70 pvGetKeyArgument, phCredential, ptsExpiry);
71 if (pszPackage)
73 PSTR principal, package;
75 principal = SECUR32_AllocMultiByteFromWide(pszPrincipal);
76 package = SECUR32_AllocMultiByteFromWide(pszPackage);
77 ret = AcquireCredentialsHandleA(principal, package, fCredentialsUse,
78 pvLogonID, pAuthData, pGetKeyFn, pvGetKeyArgument, phCredential,
79 ptsExpiry);
80 if (principal)
81 SECUR32_FREE(principal);
82 if (package)
83 SECUR32_FREE(package);
85 else
86 ret = SEC_E_SECPKG_NOT_FOUND;
87 return ret;
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
93 SECURITY_STATUS SEC_ENTRY thunk_QueryCredentialsAttributesA(
94 PCredHandle phCredential, unsigned long ulAttribute, void *pBuffer)
96 SECURITY_STATUS ret;
98 TRACE("%p %ld %p\n", phCredential, ulAttribute, pBuffer);
99 if (phCredential)
101 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
102 PCredHandle cred = (PCredHandle)phCredential->dwLower;
104 if (package && package->provider)
106 if (package->provider->fnTableW.QueryCredentialsAttributesW)
108 ret = package->provider->fnTableW.QueryCredentialsAttributesW(
109 cred, ulAttribute, pBuffer);
110 if (ret == SEC_E_OK)
112 switch (ulAttribute)
114 case SECPKG_CRED_ATTR_NAMES:
116 PSecPkgCredentials_NamesW names =
117 (PSecPkgCredentials_NamesW)pBuffer;
118 SEC_WCHAR *oldUser = names->sUserName;
120 if (oldUser)
122 names->sUserName =
123 (PWSTR)SECUR32_AllocMultiByteFromWide(oldUser);
124 package->provider->fnTableW.FreeContextBuffer(
125 oldUser);
127 break;
129 default:
130 WARN("attribute type %ld unknown\n", ulAttribute);
131 ret = SEC_E_INTERNAL_ERROR;
135 else
136 ret = SEC_E_UNSUPPORTED_FUNCTION;
138 else
139 ret = SEC_E_INVALID_HANDLE;
141 else
142 ret = SEC_E_INVALID_HANDLE;
143 return ret;
146 SECURITY_STATUS SEC_ENTRY thunk_QueryCredentialsAttributesW(
147 PCredHandle phCredential, unsigned long ulAttribute, void *pBuffer)
149 SECURITY_STATUS ret;
151 TRACE("%p %ld %p\n", phCredential, ulAttribute, pBuffer);
152 if (phCredential)
154 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
155 PCredHandle cred = (PCredHandle)phCredential->dwLower;
157 if (package && package->provider)
159 if (package->provider->fnTableA.QueryCredentialsAttributesA)
161 ret = package->provider->fnTableA.QueryCredentialsAttributesA(
162 cred, ulAttribute, pBuffer);
163 if (ret == SEC_E_OK)
165 switch (ulAttribute)
167 case SECPKG_CRED_ATTR_NAMES:
169 PSecPkgCredentials_NamesA names =
170 (PSecPkgCredentials_NamesA)pBuffer;
171 SEC_CHAR *oldUser = names->sUserName;
173 if (oldUser)
175 names->sUserName =
176 (PSTR)SECUR32_AllocWideFromMultiByte(oldUser);
177 package->provider->fnTableA.FreeContextBuffer(
178 oldUser);
180 break;
182 default:
183 WARN("attribute type %ld unknown\n", ulAttribute);
184 ret = SEC_E_INTERNAL_ERROR;
188 else
189 ret = SEC_E_UNSUPPORTED_FUNCTION;
191 else
192 ret = SEC_E_INVALID_HANDLE;
194 else
195 ret = SEC_E_INVALID_HANDLE;
196 return ret;
199 SECURITY_STATUS SEC_ENTRY thunk_InitializeSecurityContextA(
200 PCredHandle phCredential, PCtxtHandle phContext,
201 SEC_CHAR *pszTargetName, unsigned long fContextReq,
202 unsigned long Reserved1, unsigned long TargetDataRep, PSecBufferDesc pInput,
203 unsigned long Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pOutput,
204 unsigned long *pfContextAttr, PTimeStamp ptsExpiry)
206 SECURITY_STATUS ret;
208 TRACE("%p %p %s %ld %ld %ld %p %ld %p %p %p %p\n", phCredential, phContext,
209 debugstr_a(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
210 Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
211 if (phCredential)
213 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
215 if (package && package->provider)
217 if (package->provider->fnTableW.InitializeSecurityContextW)
219 UNICODE_STRING target;
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);
228 else
229 ret = SEC_E_UNSUPPORTED_FUNCTION;
231 else
232 ret = SEC_E_INVALID_HANDLE;
234 else
235 ret = SEC_E_INVALID_HANDLE;
236 return ret;
239 SECURITY_STATUS SEC_ENTRY thunk_InitializeSecurityContextW(
240 PCredHandle phCredential, PCtxtHandle phContext,
241 SEC_WCHAR *pszTargetName, unsigned long fContextReq,
242 unsigned long Reserved1, unsigned long TargetDataRep, PSecBufferDesc pInput,
243 unsigned long Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pOutput,
244 unsigned long *pfContextAttr, PTimeStamp ptsExpiry)
246 SECURITY_STATUS ret;
248 TRACE("%p %p %s %ld %ld %ld %p %ld %p %p %p %p\n", phCredential, phContext,
249 debugstr_w(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
250 Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
251 if (phCredential)
253 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
255 if (package && package->provider)
257 if (package->provider->fnTableA.InitializeSecurityContextA)
259 PSTR target = SECUR32_AllocMultiByteFromWide(pszTargetName);
261 ret = package->provider->fnTableA.InitializeSecurityContextA(
262 phCredential, phContext, target, fContextReq, Reserved1,
263 TargetDataRep, pInput, Reserved2, phNewContext, pOutput,
264 pfContextAttr, ptsExpiry);
265 if (target)
266 SECUR32_FREE(target);
268 else
269 ret = SEC_E_UNSUPPORTED_FUNCTION;
271 else
272 ret = SEC_E_INVALID_HANDLE;
274 else
275 ret = SEC_E_INVALID_HANDLE;
276 return ret;
279 SECURITY_STATUS SEC_ENTRY thunk_AddCredentialsA(PCredHandle hCredentials,
280 SEC_CHAR *pszPrincipal, SEC_CHAR *pszPackage, unsigned long fCredentialUse,
281 void *pAuthData, SEC_GET_KEY_FN pGetKeyFn, void *pvGetKeyArgument,
282 PTimeStamp ptsExpiry)
284 SECURITY_STATUS ret;
286 TRACE("%p %s %s %ld %p %p %p %p\n", hCredentials, debugstr_a(pszPrincipal),
287 debugstr_a(pszPackage), fCredentialUse, pAuthData, pGetKeyFn,
288 pvGetKeyArgument, ptsExpiry);
289 if (hCredentials)
291 SecurePackage *package = (SecurePackage *)hCredentials->dwUpper;
292 PCredHandle cred = (PCtxtHandle)hCredentials->dwLower;
294 if (package && package->provider)
296 if (package->provider->fnTableW.AddCredentialsW)
298 UNICODE_STRING szPrincipal, szPackage;
300 RtlCreateUnicodeStringFromAsciiz(&szPrincipal, pszPrincipal);
301 RtlCreateUnicodeStringFromAsciiz(&szPackage, pszPackage);
302 ret = package->provider->fnTableW.AddCredentialsW(
303 cred, szPrincipal.Buffer, szPackage.Buffer, fCredentialUse,
304 pAuthData, pGetKeyFn, pvGetKeyArgument, ptsExpiry);
305 RtlFreeUnicodeString(&szPrincipal);
306 RtlFreeUnicodeString(&szPackage);
308 else
309 ret = SEC_E_UNSUPPORTED_FUNCTION;
311 else
312 ret = SEC_E_INVALID_HANDLE;
314 else
315 ret = SEC_E_INVALID_HANDLE;
316 return ret;
319 SECURITY_STATUS SEC_ENTRY thunk_AddCredentialsW(PCredHandle hCredentials,
320 SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, unsigned long fCredentialUse,
321 void *pAuthData, SEC_GET_KEY_FN pGetKeyFn, void *pvGetKeyArgument,
322 PTimeStamp ptsExpiry)
324 SECURITY_STATUS ret;
326 TRACE("%p %s %s %ld %p %p %p %p\n", hCredentials, debugstr_w(pszPrincipal),
327 debugstr_w(pszPackage), fCredentialUse, pAuthData, pGetKeyFn,
328 pvGetKeyArgument, ptsExpiry);
329 if (hCredentials)
331 SecurePackage *package = (SecurePackage *)hCredentials->dwUpper;
332 PCredHandle cred = (PCtxtHandle)hCredentials->dwLower;
334 if (package && package->provider)
336 if (package->provider->fnTableA.AddCredentialsA)
338 PSTR szPrincipal = SECUR32_AllocMultiByteFromWide(pszPrincipal);
339 PSTR szPackage = SECUR32_AllocMultiByteFromWide(pszPackage);
341 ret = package->provider->fnTableA.AddCredentialsA(
342 cred, szPrincipal, szPackage, fCredentialUse, pAuthData,
343 pGetKeyFn, pvGetKeyArgument, ptsExpiry);
344 SECUR32_FREE(szPrincipal);
345 SECUR32_FREE(szPackage);
347 else
348 ret = SEC_E_UNSUPPORTED_FUNCTION;
350 else
351 ret = SEC_E_INVALID_HANDLE;
353 else
354 ret = SEC_E_INVALID_HANDLE;
355 return ret;
358 static PSecPkgInfoA _copyPackageInfoFlatWToA(PSecPkgInfoW infoW)
360 PSecPkgInfoA ret;
362 if (infoW)
364 size_t bytesNeeded = sizeof(SecPkgInfoA);
365 int nameLen = 0, commentLen = 0;
367 if (infoW->Name)
369 nameLen = WideCharToMultiByte(CP_ACP, 0, infoW->Name, -1,
370 NULL, 0, NULL, NULL);
371 bytesNeeded += nameLen;
373 if (infoW->Comment)
375 commentLen = WideCharToMultiByte(CP_ACP, 0, infoW->Comment, -1,
376 NULL, 0, NULL, NULL);
377 bytesNeeded += commentLen;
379 ret = (PSecPkgInfoA)SECUR32_ALLOC(bytesNeeded);
380 if (ret)
382 PSTR nextString = (PSTR)((PBYTE)ret + sizeof(SecPkgInfoA));
384 memcpy(ret, infoW, sizeof(SecPkgInfoA));
385 if (infoW->Name)
387 ret->Name = nextString;
388 WideCharToMultiByte(CP_ACP, 0, infoW->Name, -1, nextString,
389 nameLen, NULL, NULL);
390 nextString += nameLen;
392 else
393 ret->Name = NULL;
394 if (infoW->Comment)
396 ret->Comment = nextString;
397 WideCharToMultiByte(CP_ACP, 0, infoW->Comment, -1, nextString,
398 nameLen, NULL, NULL);
400 else
401 ret->Comment = NULL;
404 else
405 ret = NULL;
406 return ret;
409 static SECURITY_STATUS thunk_ContextAttributesWToA(SecurePackage *package,
410 unsigned long ulAttribute, void *pBuffer)
412 SECURITY_STATUS ret = SEC_E_OK;
414 if (package && pBuffer)
416 switch (ulAttribute)
418 case SECPKG_ATTR_NAMES:
420 PSecPkgContext_NamesW names = (PSecPkgContext_NamesW)pBuffer;
421 SEC_WCHAR *oldUser = names->sUserName;
423 if (oldUser)
425 names->sUserName =
426 (PWSTR)SECUR32_AllocMultiByteFromWide(oldUser);
427 package->provider->fnTableW.FreeContextBuffer(oldUser);
429 break;
431 case SECPKG_ATTR_AUTHORITY:
433 PSecPkgContext_AuthorityW names =
434 (PSecPkgContext_AuthorityW)pBuffer;
435 SEC_WCHAR *oldAuth = names->sAuthorityName;
437 if (oldAuth)
439 names->sAuthorityName =
440 (PWSTR)SECUR32_AllocMultiByteFromWide(oldAuth);
441 package->provider->fnTableW.FreeContextBuffer(oldAuth);
443 break;
445 case SECPKG_ATTR_KEY_INFO:
447 PSecPkgContext_KeyInfoW info = (PSecPkgContext_KeyInfoW)pBuffer;
448 SEC_WCHAR *oldSigAlgName = info->sSignatureAlgorithmName;
449 SEC_WCHAR *oldEncAlgName = info->sEncryptAlgorithmName;
451 if (oldSigAlgName)
453 info->sSignatureAlgorithmName =
454 (PWSTR)SECUR32_AllocMultiByteFromWide(oldSigAlgName);
455 package->provider->fnTableW.FreeContextBuffer(
456 oldSigAlgName);
458 if (oldEncAlgName)
460 info->sEncryptAlgorithmName =
461 (PWSTR)SECUR32_AllocMultiByteFromWide(oldEncAlgName);
462 package->provider->fnTableW.FreeContextBuffer(
463 oldEncAlgName);
465 break;
467 case SECPKG_ATTR_PACKAGE_INFO:
469 PSecPkgContext_PackageInfoW info =
470 (PSecPkgContext_PackageInfoW)pBuffer;
471 PSecPkgInfoW oldPkgInfo = info->PackageInfo;
473 if (oldPkgInfo)
475 info->PackageInfo = (PSecPkgInfoW)
476 _copyPackageInfoFlatWToA(oldPkgInfo);
477 package->provider->fnTableW.FreeContextBuffer(oldPkgInfo);
479 break;
481 case SECPKG_ATTR_NEGOTIATION_INFO:
483 PSecPkgContext_NegotiationInfoW info =
484 (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 =
498 (PSecPkgContext_NativeNamesW)pBuffer;
499 PWSTR oldClient = names->sClientName;
500 PWSTR oldServer = names->sServerName;
502 if (oldClient)
504 names->sClientName = (PWSTR)SECUR32_AllocMultiByteFromWide(
505 oldClient);
506 package->provider->fnTableW.FreeContextBuffer(oldClient);
508 if (oldServer)
510 names->sServerName = (PWSTR)SECUR32_AllocMultiByteFromWide(
511 oldServer);
512 package->provider->fnTableW.FreeContextBuffer(oldServer);
514 break;
516 case SECPKG_ATTR_CREDENTIAL_NAME:
518 PSecPkgContext_CredentialNameW name =
519 (PSecPkgContext_CredentialNameW)pBuffer;
520 PWSTR oldCred = name->sCredentialName;
522 if (oldCred)
524 name->sCredentialName =
525 (PWSTR)SECUR32_AllocMultiByteFromWide(oldCred);
526 package->provider->fnTableW.FreeContextBuffer(oldCred);
528 break;
530 /* no thunking needed: */
531 case SECPKG_ATTR_ACCESS_TOKEN:
532 case SECPKG_ATTR_DCE_INFO:
533 case SECPKG_ATTR_FLAGS:
534 case SECPKG_ATTR_LIFESPAN:
535 case SECPKG_ATTR_PASSWORD_EXPIRY:
536 case SECPKG_ATTR_SESSION_KEY:
537 case SECPKG_ATTR_SIZES:
538 case SECPKG_ATTR_STREAM_SIZES:
539 case SECPKG_ATTR_TARGET_INFORMATION:
540 break;
541 default:
542 WARN("attribute type %ld unknown\n", ulAttribute);
543 ret = SEC_E_INTERNAL_ERROR;
546 else
547 ret = SEC_E_INVALID_TOKEN;
548 return ret;
551 SECURITY_STATUS SEC_ENTRY thunk_QueryContextAttributesA(PCtxtHandle phContext,
552 unsigned long ulAttribute, void *pBuffer)
554 SECURITY_STATUS ret;
556 TRACE("%p %ld %p\n", phContext, ulAttribute, pBuffer);
557 if (phContext)
559 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
560 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
562 if (package && package->provider)
564 if (package->provider->fnTableW.QueryContextAttributesW)
566 ret = package->provider->fnTableW.QueryContextAttributesW(
567 ctxt, ulAttribute, pBuffer);
568 if (ret == SEC_E_OK)
569 ret = thunk_ContextAttributesWToA(package, ulAttribute,
570 pBuffer);
572 else
573 ret = SEC_E_UNSUPPORTED_FUNCTION;
575 else
576 ret = SEC_E_INVALID_HANDLE;
578 else
579 ret = SEC_E_INVALID_HANDLE;
580 return ret;
583 static PSecPkgInfoW _copyPackageInfoFlatAToW(PSecPkgInfoA infoA)
585 PSecPkgInfoW ret;
587 if (infoA)
589 size_t bytesNeeded = sizeof(SecPkgInfoW);
590 int nameLen = 0, commentLen = 0;
592 if (infoA->Name)
594 nameLen = MultiByteToWideChar(CP_ACP, 0, infoA->Name, -1,
595 NULL, 0);
596 bytesNeeded += nameLen * sizeof(WCHAR);
598 if (infoA->Comment)
600 commentLen = MultiByteToWideChar(CP_ACP, 0, infoA->Comment, -1,
601 NULL, 0);
602 bytesNeeded += commentLen * sizeof(WCHAR);
604 ret = (PSecPkgInfoW)SECUR32_ALLOC(bytesNeeded);
605 if (ret)
607 PWSTR nextString = (PWSTR)((PBYTE)ret + sizeof(SecPkgInfoW));
609 memcpy(ret, infoA, sizeof(SecPkgInfoA));
610 if (infoA->Name)
612 ret->Name = nextString;
613 MultiByteToWideChar(CP_ACP, 0, infoA->Name, -1, nextString,
614 nameLen);
615 nextString += nameLen;
617 else
618 ret->Name = NULL;
619 if (infoA->Comment)
621 ret->Comment = nextString;
622 MultiByteToWideChar(CP_ACP, 0, infoA->Comment, -1, nextString,
623 nameLen);
625 else
626 ret->Comment = NULL;
629 else
630 ret = NULL;
631 return ret;
634 static SECURITY_STATUS thunk_ContextAttributesAToW(SecurePackage *package,
635 unsigned long ulAttribute, void *pBuffer)
637 SECURITY_STATUS ret = SEC_E_OK;
639 if (package && pBuffer)
641 switch (ulAttribute)
643 case SECPKG_ATTR_NAMES:
645 PSecPkgContext_NamesA names = (PSecPkgContext_NamesA)pBuffer;
646 SEC_CHAR *oldUser = names->sUserName;
648 if (oldUser)
650 names->sUserName =
651 (PSTR)SECUR32_AllocWideFromMultiByte(oldUser);
652 package->provider->fnTableW.FreeContextBuffer(oldUser);
654 break;
656 case SECPKG_ATTR_AUTHORITY:
658 PSecPkgContext_AuthorityA names =
659 (PSecPkgContext_AuthorityA)pBuffer;
660 SEC_CHAR *oldAuth = names->sAuthorityName;
662 if (oldAuth)
664 names->sAuthorityName =
665 (PSTR)SECUR32_AllocWideFromMultiByte(oldAuth);
666 package->provider->fnTableW.FreeContextBuffer(oldAuth);
668 break;
670 case SECPKG_ATTR_KEY_INFO:
672 PSecPkgContext_KeyInfoA info = (PSecPkgContext_KeyInfoA)pBuffer;
673 SEC_CHAR *oldSigAlgName = info->sSignatureAlgorithmName;
674 SEC_CHAR *oldEncAlgName = info->sEncryptAlgorithmName;
676 if (oldSigAlgName)
678 info->sSignatureAlgorithmName =
679 (PSTR)SECUR32_AllocWideFromMultiByte(oldSigAlgName);
680 package->provider->fnTableW.FreeContextBuffer(
681 oldSigAlgName);
683 if (oldEncAlgName)
685 info->sEncryptAlgorithmName =
686 (PSTR)SECUR32_AllocWideFromMultiByte(
687 oldEncAlgName);
688 package->provider->fnTableW.FreeContextBuffer(
689 oldEncAlgName);
691 break;
693 case SECPKG_ATTR_PACKAGE_INFO:
695 PSecPkgContext_PackageInfoA info =
696 (PSecPkgContext_PackageInfoA)pBuffer;
697 PSecPkgInfoA oldPkgInfo = info->PackageInfo;
699 if (oldPkgInfo)
701 info->PackageInfo = (PSecPkgInfoA)
702 _copyPackageInfoFlatAToW(oldPkgInfo);
703 package->provider->fnTableW.FreeContextBuffer(oldPkgInfo);
705 break;
707 case SECPKG_ATTR_NEGOTIATION_INFO:
709 PSecPkgContext_NegotiationInfoA info =
710 (PSecPkgContext_NegotiationInfoA)pBuffer;
711 PSecPkgInfoA oldPkgInfo = info->PackageInfo;
713 if (oldPkgInfo)
715 info->PackageInfo = (PSecPkgInfoA)
716 _copyPackageInfoFlatAToW(oldPkgInfo);
717 package->provider->fnTableW.FreeContextBuffer(oldPkgInfo);
719 break;
721 case SECPKG_ATTR_NATIVE_NAMES:
723 PSecPkgContext_NativeNamesA names =
724 (PSecPkgContext_NativeNamesA)pBuffer;
725 PSTR oldClient = names->sClientName;
726 PSTR oldServer = names->sServerName;
728 if (oldClient)
730 names->sClientName = (PSTR)SECUR32_AllocWideFromMultiByte(
731 oldClient);
732 package->provider->fnTableW.FreeContextBuffer(oldClient);
734 if (oldServer)
736 names->sServerName = (PSTR)SECUR32_AllocWideFromMultiByte(
737 oldServer);
738 package->provider->fnTableW.FreeContextBuffer(oldServer);
740 break;
742 case SECPKG_ATTR_CREDENTIAL_NAME:
744 PSecPkgContext_CredentialNameA name =
745 (PSecPkgContext_CredentialNameA)pBuffer;
746 PSTR oldCred = name->sCredentialName;
748 if (oldCred)
750 name->sCredentialName =
751 (PSTR)SECUR32_AllocWideFromMultiByte(oldCred);
752 package->provider->fnTableW.FreeContextBuffer(oldCred);
754 break;
756 /* no thunking needed: */
757 case SECPKG_ATTR_ACCESS_TOKEN:
758 case SECPKG_ATTR_DCE_INFO:
759 case SECPKG_ATTR_FLAGS:
760 case SECPKG_ATTR_LIFESPAN:
761 case SECPKG_ATTR_PASSWORD_EXPIRY:
762 case SECPKG_ATTR_SESSION_KEY:
763 case SECPKG_ATTR_SIZES:
764 case SECPKG_ATTR_STREAM_SIZES:
765 case SECPKG_ATTR_TARGET_INFORMATION:
766 break;
767 default:
768 WARN("attribute type %ld unknown\n", ulAttribute);
769 ret = SEC_E_INTERNAL_ERROR;
772 else
773 ret = SEC_E_INVALID_TOKEN;
774 return ret;
777 SECURITY_STATUS SEC_ENTRY thunk_QueryContextAttributesW(PCtxtHandle phContext,
778 unsigned long ulAttribute, void *pBuffer)
780 SECURITY_STATUS ret;
782 TRACE("%p %ld %p\n", phContext, ulAttribute, pBuffer);
783 if (phContext)
785 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
786 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
788 if (package && package->provider)
790 if (package->provider->fnTableA.QueryContextAttributesA)
792 ret = package->provider->fnTableA.QueryContextAttributesA(
793 ctxt, ulAttribute, pBuffer);
794 if (ret == SEC_E_OK)
795 ret = thunk_ContextAttributesAToW(package, ulAttribute,
796 pBuffer);
798 else
799 ret = SEC_E_UNSUPPORTED_FUNCTION;
801 else
802 ret = SEC_E_INVALID_HANDLE;
804 else
805 ret = SEC_E_INVALID_HANDLE;
806 return ret;
809 SECURITY_STATUS SEC_ENTRY thunk_SetContextAttributesA(PCtxtHandle phContext,
810 unsigned long ulAttribute, void *pBuffer, unsigned long cbBuffer)
812 SECURITY_STATUS ret;
814 TRACE("%p %ld %p %ld\n", phContext, ulAttribute, pBuffer, cbBuffer);
815 if (phContext)
817 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
818 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
820 if (package && package->provider && pBuffer && cbBuffer)
822 if (package->provider->fnTableW.SetContextAttributesW)
824 /* TODO: gotta validate size too! */
825 ret = thunk_ContextAttributesWToA(package, ulAttribute,
826 pBuffer);
827 if (ret == SEC_E_OK)
828 ret = package->provider->fnTableW.SetContextAttributesW(
829 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_SetContextAttributesW(PCtxtHandle phContext,
843 unsigned long ulAttribute, void *pBuffer, unsigned long cbBuffer)
845 SECURITY_STATUS ret;
847 TRACE("%p %ld %p %ld\n", phContext, ulAttribute, pBuffer, cbBuffer);
848 if (phContext)
850 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
851 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
853 if (package && package->provider && pBuffer && cbBuffer)
855 if (package->provider->fnTableA.SetContextAttributesA)
857 /* TODO: gotta validate size too! */
858 ret = thunk_ContextAttributesAToW(package, ulAttribute,
859 pBuffer);
860 if (ret == SEC_E_OK)
861 ret = package->provider->fnTableA.SetContextAttributesA(
862 ctxt, ulAttribute, pBuffer, cbBuffer);
864 else
865 ret = SEC_E_UNSUPPORTED_FUNCTION;
867 else
868 ret = SEC_E_INVALID_HANDLE;
870 else
871 ret = SEC_E_INVALID_HANDLE;
872 return ret;
875 SECURITY_STATUS SEC_ENTRY thunk_ImportSecurityContextA(
876 SEC_CHAR *pszPackage, PSecBuffer pPackedContext, void *Token,
877 PCtxtHandle phContext)
879 SECURITY_STATUS ret;
880 UNICODE_STRING package;
882 TRACE("%s %p %p %p\n", debugstr_a(pszPackage), pPackedContext, Token,
883 phContext);
884 RtlCreateUnicodeStringFromAsciiz(&package, pszPackage);
885 ret = ImportSecurityContextW(package.Buffer, pPackedContext, Token,
886 phContext);
887 RtlFreeUnicodeString(&package);
888 return ret;
891 SECURITY_STATUS SEC_ENTRY thunk_ImportSecurityContextW(
892 SEC_WCHAR *pszPackage, PSecBuffer pPackedContext, void *Token,
893 PCtxtHandle phContext)
895 SECURITY_STATUS ret;
896 PSTR package = SECUR32_AllocMultiByteFromWide(pszPackage);
898 TRACE("%s %p %p %p\n", debugstr_w(pszPackage), pPackedContext, Token,
899 phContext);
900 ret = ImportSecurityContextA(package, pPackedContext, Token, phContext);
901 if (package)
902 SECUR32_FREE(package);
903 return ret;