Release 0.9.14.
[wine/multimedia.git] / dlls / secur32 / thunks.c
blobd30de7ae0d9c97cfb2f64419cab3777d6416850e
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 "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 SECUR32_FREE(principal);
81 SECUR32_FREE(package);
83 else
84 ret = SEC_E_SECPKG_NOT_FOUND;
85 return ret;
88 /* thunking is pretty dicey for these--the output type depends on ulAttribute,
89 * so we have to know about every type the caller does
91 SECURITY_STATUS SEC_ENTRY thunk_QueryCredentialsAttributesA(
92 PCredHandle phCredential, unsigned long ulAttribute, void *pBuffer)
94 SECURITY_STATUS ret;
96 TRACE("%p %ld %p\n", phCredential, ulAttribute, pBuffer);
97 if (phCredential)
99 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
100 PCredHandle cred = (PCredHandle)phCredential->dwLower;
102 if (package && package->provider)
104 if (package->provider->fnTableW.QueryCredentialsAttributesW)
106 ret = package->provider->fnTableW.QueryCredentialsAttributesW(
107 cred, ulAttribute, pBuffer);
108 if (ret == SEC_E_OK)
110 switch (ulAttribute)
112 case SECPKG_CRED_ATTR_NAMES:
114 PSecPkgCredentials_NamesW names =
115 (PSecPkgCredentials_NamesW)pBuffer;
116 SEC_WCHAR *oldUser = names->sUserName;
118 if (oldUser)
120 names->sUserName =
121 (PWSTR)SECUR32_AllocMultiByteFromWide(oldUser);
122 package->provider->fnTableW.FreeContextBuffer(
123 oldUser);
125 break;
127 default:
128 WARN("attribute type %ld unknown\n", ulAttribute);
129 ret = SEC_E_INTERNAL_ERROR;
133 else
134 ret = SEC_E_UNSUPPORTED_FUNCTION;
136 else
137 ret = SEC_E_INVALID_HANDLE;
139 else
140 ret = SEC_E_INVALID_HANDLE;
141 return ret;
144 SECURITY_STATUS SEC_ENTRY thunk_QueryCredentialsAttributesW(
145 PCredHandle phCredential, unsigned long ulAttribute, void *pBuffer)
147 SECURITY_STATUS ret;
149 TRACE("%p %ld %p\n", phCredential, ulAttribute, pBuffer);
150 if (phCredential)
152 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
153 PCredHandle cred = (PCredHandle)phCredential->dwLower;
155 if (package && package->provider)
157 if (package->provider->fnTableA.QueryCredentialsAttributesA)
159 ret = package->provider->fnTableA.QueryCredentialsAttributesA(
160 cred, ulAttribute, pBuffer);
161 if (ret == SEC_E_OK)
163 switch (ulAttribute)
165 case SECPKG_CRED_ATTR_NAMES:
167 PSecPkgCredentials_NamesA names =
168 (PSecPkgCredentials_NamesA)pBuffer;
169 SEC_CHAR *oldUser = names->sUserName;
171 if (oldUser)
173 names->sUserName =
174 (PSTR)SECUR32_AllocWideFromMultiByte(oldUser);
175 package->provider->fnTableA.FreeContextBuffer(
176 oldUser);
178 break;
180 default:
181 WARN("attribute type %ld unknown\n", ulAttribute);
182 ret = SEC_E_INTERNAL_ERROR;
186 else
187 ret = SEC_E_UNSUPPORTED_FUNCTION;
189 else
190 ret = SEC_E_INVALID_HANDLE;
192 else
193 ret = SEC_E_INVALID_HANDLE;
194 return ret;
197 SECURITY_STATUS SEC_ENTRY thunk_InitializeSecurityContextA(
198 PCredHandle phCredential, PCtxtHandle phContext,
199 SEC_CHAR *pszTargetName, unsigned long fContextReq,
200 unsigned long Reserved1, unsigned long TargetDataRep, PSecBufferDesc pInput,
201 unsigned long Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pOutput,
202 unsigned long *pfContextAttr, PTimeStamp ptsExpiry)
204 SECURITY_STATUS ret;
206 TRACE("%p %p %s %ld %ld %ld %p %ld %p %p %p %p\n", phCredential, phContext,
207 debugstr_a(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
208 Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
209 if (phCredential)
211 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
213 if (package && package->provider)
215 if (package->provider->fnTableW.InitializeSecurityContextW)
217 UNICODE_STRING target;
219 RtlCreateUnicodeStringFromAsciiz(&target, pszTargetName);
220 ret = package->provider->fnTableW.InitializeSecurityContextW(
221 phCredential, phContext, target.Buffer, fContextReq, Reserved1,
222 TargetDataRep, pInput, Reserved2, phNewContext, pOutput,
223 pfContextAttr, ptsExpiry);
224 RtlFreeUnicodeString(&target);
226 else
227 ret = SEC_E_UNSUPPORTED_FUNCTION;
229 else
230 ret = SEC_E_INVALID_HANDLE;
232 else
233 ret = SEC_E_INVALID_HANDLE;
234 return ret;
237 SECURITY_STATUS SEC_ENTRY thunk_InitializeSecurityContextW(
238 PCredHandle phCredential, PCtxtHandle phContext,
239 SEC_WCHAR *pszTargetName, unsigned long fContextReq,
240 unsigned long Reserved1, unsigned long TargetDataRep, PSecBufferDesc pInput,
241 unsigned long Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pOutput,
242 unsigned long *pfContextAttr, PTimeStamp ptsExpiry)
244 SECURITY_STATUS ret;
246 TRACE("%p %p %s %ld %ld %ld %p %ld %p %p %p %p\n", phCredential, phContext,
247 debugstr_w(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
248 Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
249 if (phCredential)
251 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
253 if (package && package->provider)
255 if (package->provider->fnTableA.InitializeSecurityContextA)
257 PSTR target = SECUR32_AllocMultiByteFromWide(pszTargetName);
259 ret = package->provider->fnTableA.InitializeSecurityContextA(
260 phCredential, phContext, target, fContextReq, Reserved1,
261 TargetDataRep, pInput, Reserved2, phNewContext, pOutput,
262 pfContextAttr, ptsExpiry);
263 SECUR32_FREE(target);
265 else
266 ret = SEC_E_UNSUPPORTED_FUNCTION;
268 else
269 ret = SEC_E_INVALID_HANDLE;
271 else
272 ret = SEC_E_INVALID_HANDLE;
273 return ret;
276 SECURITY_STATUS SEC_ENTRY thunk_AddCredentialsA(PCredHandle hCredentials,
277 SEC_CHAR *pszPrincipal, SEC_CHAR *pszPackage, unsigned long fCredentialUse,
278 void *pAuthData, SEC_GET_KEY_FN pGetKeyFn, void *pvGetKeyArgument,
279 PTimeStamp ptsExpiry)
281 SECURITY_STATUS ret;
283 TRACE("%p %s %s %ld %p %p %p %p\n", hCredentials, debugstr_a(pszPrincipal),
284 debugstr_a(pszPackage), fCredentialUse, pAuthData, pGetKeyFn,
285 pvGetKeyArgument, ptsExpiry);
286 if (hCredentials)
288 SecurePackage *package = (SecurePackage *)hCredentials->dwUpper;
289 PCredHandle cred = (PCtxtHandle)hCredentials->dwLower;
291 if (package && package->provider)
293 if (package->provider->fnTableW.AddCredentialsW)
295 UNICODE_STRING szPrincipal, szPackage;
297 RtlCreateUnicodeStringFromAsciiz(&szPrincipal, pszPrincipal);
298 RtlCreateUnicodeStringFromAsciiz(&szPackage, pszPackage);
299 ret = package->provider->fnTableW.AddCredentialsW(
300 cred, szPrincipal.Buffer, szPackage.Buffer, fCredentialUse,
301 pAuthData, pGetKeyFn, pvGetKeyArgument, ptsExpiry);
302 RtlFreeUnicodeString(&szPrincipal);
303 RtlFreeUnicodeString(&szPackage);
305 else
306 ret = SEC_E_UNSUPPORTED_FUNCTION;
308 else
309 ret = SEC_E_INVALID_HANDLE;
311 else
312 ret = SEC_E_INVALID_HANDLE;
313 return ret;
316 SECURITY_STATUS SEC_ENTRY thunk_AddCredentialsW(PCredHandle hCredentials,
317 SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, unsigned long fCredentialUse,
318 void *pAuthData, SEC_GET_KEY_FN pGetKeyFn, void *pvGetKeyArgument,
319 PTimeStamp ptsExpiry)
321 SECURITY_STATUS ret;
323 TRACE("%p %s %s %ld %p %p %p %p\n", hCredentials, debugstr_w(pszPrincipal),
324 debugstr_w(pszPackage), fCredentialUse, pAuthData, pGetKeyFn,
325 pvGetKeyArgument, ptsExpiry);
326 if (hCredentials)
328 SecurePackage *package = (SecurePackage *)hCredentials->dwUpper;
329 PCredHandle cred = (PCtxtHandle)hCredentials->dwLower;
331 if (package && package->provider)
333 if (package->provider->fnTableA.AddCredentialsA)
335 PSTR szPrincipal = SECUR32_AllocMultiByteFromWide(pszPrincipal);
336 PSTR szPackage = SECUR32_AllocMultiByteFromWide(pszPackage);
338 ret = package->provider->fnTableA.AddCredentialsA(
339 cred, szPrincipal, szPackage, fCredentialUse, pAuthData,
340 pGetKeyFn, pvGetKeyArgument, ptsExpiry);
341 SECUR32_FREE(szPrincipal);
342 SECUR32_FREE(szPackage);
344 else
345 ret = SEC_E_UNSUPPORTED_FUNCTION;
347 else
348 ret = SEC_E_INVALID_HANDLE;
350 else
351 ret = SEC_E_INVALID_HANDLE;
352 return ret;
355 static PSecPkgInfoA _copyPackageInfoFlatWToA(PSecPkgInfoW infoW)
357 PSecPkgInfoA ret;
359 if (infoW)
361 size_t bytesNeeded = sizeof(SecPkgInfoA);
362 int nameLen = 0, commentLen = 0;
364 if (infoW->Name)
366 nameLen = WideCharToMultiByte(CP_ACP, 0, infoW->Name, -1,
367 NULL, 0, NULL, NULL);
368 bytesNeeded += nameLen;
370 if (infoW->Comment)
372 commentLen = WideCharToMultiByte(CP_ACP, 0, infoW->Comment, -1,
373 NULL, 0, NULL, NULL);
374 bytesNeeded += commentLen;
376 ret = (PSecPkgInfoA)SECUR32_ALLOC(bytesNeeded);
377 if (ret)
379 PSTR nextString = (PSTR)((PBYTE)ret + sizeof(SecPkgInfoA));
381 memcpy(ret, infoW, sizeof(SecPkgInfoA));
382 if (infoW->Name)
384 ret->Name = nextString;
385 WideCharToMultiByte(CP_ACP, 0, infoW->Name, -1, nextString,
386 nameLen, NULL, NULL);
387 nextString += nameLen;
389 else
390 ret->Name = NULL;
391 if (infoW->Comment)
393 ret->Comment = nextString;
394 WideCharToMultiByte(CP_ACP, 0, infoW->Comment, -1, nextString,
395 nameLen, NULL, NULL);
397 else
398 ret->Comment = NULL;
401 else
402 ret = NULL;
403 return ret;
406 static SECURITY_STATUS thunk_ContextAttributesWToA(SecurePackage *package,
407 unsigned long ulAttribute, void *pBuffer)
409 SECURITY_STATUS ret = SEC_E_OK;
411 if (package && pBuffer)
413 switch (ulAttribute)
415 case SECPKG_ATTR_NAMES:
417 PSecPkgContext_NamesW names = (PSecPkgContext_NamesW)pBuffer;
418 SEC_WCHAR *oldUser = names->sUserName;
420 if (oldUser)
422 names->sUserName =
423 (PWSTR)SECUR32_AllocMultiByteFromWide(oldUser);
424 package->provider->fnTableW.FreeContextBuffer(oldUser);
426 break;
428 case SECPKG_ATTR_AUTHORITY:
430 PSecPkgContext_AuthorityW names =
431 (PSecPkgContext_AuthorityW)pBuffer;
432 SEC_WCHAR *oldAuth = names->sAuthorityName;
434 if (oldAuth)
436 names->sAuthorityName =
437 (PWSTR)SECUR32_AllocMultiByteFromWide(oldAuth);
438 package->provider->fnTableW.FreeContextBuffer(oldAuth);
440 break;
442 case SECPKG_ATTR_KEY_INFO:
444 PSecPkgContext_KeyInfoW info = (PSecPkgContext_KeyInfoW)pBuffer;
445 SEC_WCHAR *oldSigAlgName = info->sSignatureAlgorithmName;
446 SEC_WCHAR *oldEncAlgName = info->sEncryptAlgorithmName;
448 if (oldSigAlgName)
450 info->sSignatureAlgorithmName =
451 (PWSTR)SECUR32_AllocMultiByteFromWide(oldSigAlgName);
452 package->provider->fnTableW.FreeContextBuffer(
453 oldSigAlgName);
455 if (oldEncAlgName)
457 info->sEncryptAlgorithmName =
458 (PWSTR)SECUR32_AllocMultiByteFromWide(oldEncAlgName);
459 package->provider->fnTableW.FreeContextBuffer(
460 oldEncAlgName);
462 break;
464 case SECPKG_ATTR_PACKAGE_INFO:
466 PSecPkgContext_PackageInfoW info =
467 (PSecPkgContext_PackageInfoW)pBuffer;
468 PSecPkgInfoW oldPkgInfo = info->PackageInfo;
470 if (oldPkgInfo)
472 info->PackageInfo = (PSecPkgInfoW)
473 _copyPackageInfoFlatWToA(oldPkgInfo);
474 package->provider->fnTableW.FreeContextBuffer(oldPkgInfo);
476 break;
478 case SECPKG_ATTR_NEGOTIATION_INFO:
480 PSecPkgContext_NegotiationInfoW info =
481 (PSecPkgContext_NegotiationInfoW)pBuffer;
482 PSecPkgInfoW oldPkgInfo = info->PackageInfo;
484 if (oldPkgInfo)
486 info->PackageInfo = (PSecPkgInfoW)
487 _copyPackageInfoFlatWToA(oldPkgInfo);
488 package->provider->fnTableW.FreeContextBuffer(oldPkgInfo);
490 break;
492 case SECPKG_ATTR_NATIVE_NAMES:
494 PSecPkgContext_NativeNamesW names =
495 (PSecPkgContext_NativeNamesW)pBuffer;
496 PWSTR oldClient = names->sClientName;
497 PWSTR oldServer = names->sServerName;
499 if (oldClient)
501 names->sClientName = (PWSTR)SECUR32_AllocMultiByteFromWide(
502 oldClient);
503 package->provider->fnTableW.FreeContextBuffer(oldClient);
505 if (oldServer)
507 names->sServerName = (PWSTR)SECUR32_AllocMultiByteFromWide(
508 oldServer);
509 package->provider->fnTableW.FreeContextBuffer(oldServer);
511 break;
513 case SECPKG_ATTR_CREDENTIAL_NAME:
515 PSecPkgContext_CredentialNameW name =
516 (PSecPkgContext_CredentialNameW)pBuffer;
517 PWSTR oldCred = name->sCredentialName;
519 if (oldCred)
521 name->sCredentialName =
522 (PWSTR)SECUR32_AllocMultiByteFromWide(oldCred);
523 package->provider->fnTableW.FreeContextBuffer(oldCred);
525 break;
527 /* no thunking needed: */
528 case SECPKG_ATTR_ACCESS_TOKEN:
529 case SECPKG_ATTR_DCE_INFO:
530 case SECPKG_ATTR_FLAGS:
531 case SECPKG_ATTR_LIFESPAN:
532 case SECPKG_ATTR_PASSWORD_EXPIRY:
533 case SECPKG_ATTR_SESSION_KEY:
534 case SECPKG_ATTR_SIZES:
535 case SECPKG_ATTR_STREAM_SIZES:
536 case SECPKG_ATTR_TARGET_INFORMATION:
537 break;
538 default:
539 WARN("attribute type %ld unknown\n", ulAttribute);
540 ret = SEC_E_INTERNAL_ERROR;
543 else
544 ret = SEC_E_INVALID_TOKEN;
545 return ret;
548 SECURITY_STATUS SEC_ENTRY thunk_QueryContextAttributesA(PCtxtHandle phContext,
549 unsigned long ulAttribute, void *pBuffer)
551 SECURITY_STATUS ret;
553 TRACE("%p %ld %p\n", phContext, ulAttribute, pBuffer);
554 if (phContext)
556 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
557 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
559 if (package && package->provider)
561 if (package->provider->fnTableW.QueryContextAttributesW)
563 ret = package->provider->fnTableW.QueryContextAttributesW(
564 ctxt, ulAttribute, pBuffer);
565 if (ret == SEC_E_OK)
566 ret = thunk_ContextAttributesWToA(package, ulAttribute,
567 pBuffer);
569 else
570 ret = SEC_E_UNSUPPORTED_FUNCTION;
572 else
573 ret = SEC_E_INVALID_HANDLE;
575 else
576 ret = SEC_E_INVALID_HANDLE;
577 return ret;
580 static PSecPkgInfoW _copyPackageInfoFlatAToW(PSecPkgInfoA infoA)
582 PSecPkgInfoW ret;
584 if (infoA)
586 size_t bytesNeeded = sizeof(SecPkgInfoW);
587 int nameLen = 0, commentLen = 0;
589 if (infoA->Name)
591 nameLen = MultiByteToWideChar(CP_ACP, 0, infoA->Name, -1,
592 NULL, 0);
593 bytesNeeded += nameLen * sizeof(WCHAR);
595 if (infoA->Comment)
597 commentLen = MultiByteToWideChar(CP_ACP, 0, infoA->Comment, -1,
598 NULL, 0);
599 bytesNeeded += commentLen * sizeof(WCHAR);
601 ret = (PSecPkgInfoW)SECUR32_ALLOC(bytesNeeded);
602 if (ret)
604 PWSTR nextString = (PWSTR)((PBYTE)ret + sizeof(SecPkgInfoW));
606 memcpy(ret, infoA, sizeof(SecPkgInfoA));
607 if (infoA->Name)
609 ret->Name = nextString;
610 MultiByteToWideChar(CP_ACP, 0, infoA->Name, -1, nextString,
611 nameLen);
612 nextString += nameLen;
614 else
615 ret->Name = NULL;
616 if (infoA->Comment)
618 ret->Comment = nextString;
619 MultiByteToWideChar(CP_ACP, 0, infoA->Comment, -1, nextString,
620 commentLen);
622 else
623 ret->Comment = NULL;
626 else
627 ret = NULL;
628 return ret;
631 static SECURITY_STATUS thunk_ContextAttributesAToW(SecurePackage *package,
632 unsigned long ulAttribute, void *pBuffer)
634 SECURITY_STATUS ret = SEC_E_OK;
636 if (package && pBuffer)
638 switch (ulAttribute)
640 case SECPKG_ATTR_NAMES:
642 PSecPkgContext_NamesA names = (PSecPkgContext_NamesA)pBuffer;
643 SEC_CHAR *oldUser = names->sUserName;
645 if (oldUser)
647 names->sUserName =
648 (PSTR)SECUR32_AllocWideFromMultiByte(oldUser);
649 package->provider->fnTableW.FreeContextBuffer(oldUser);
651 break;
653 case SECPKG_ATTR_AUTHORITY:
655 PSecPkgContext_AuthorityA names =
656 (PSecPkgContext_AuthorityA)pBuffer;
657 SEC_CHAR *oldAuth = names->sAuthorityName;
659 if (oldAuth)
661 names->sAuthorityName =
662 (PSTR)SECUR32_AllocWideFromMultiByte(oldAuth);
663 package->provider->fnTableW.FreeContextBuffer(oldAuth);
665 break;
667 case SECPKG_ATTR_KEY_INFO:
669 PSecPkgContext_KeyInfoA info = (PSecPkgContext_KeyInfoA)pBuffer;
670 SEC_CHAR *oldSigAlgName = info->sSignatureAlgorithmName;
671 SEC_CHAR *oldEncAlgName = info->sEncryptAlgorithmName;
673 if (oldSigAlgName)
675 info->sSignatureAlgorithmName =
676 (PSTR)SECUR32_AllocWideFromMultiByte(oldSigAlgName);
677 package->provider->fnTableW.FreeContextBuffer(
678 oldSigAlgName);
680 if (oldEncAlgName)
682 info->sEncryptAlgorithmName =
683 (PSTR)SECUR32_AllocWideFromMultiByte(
684 oldEncAlgName);
685 package->provider->fnTableW.FreeContextBuffer(
686 oldEncAlgName);
688 break;
690 case SECPKG_ATTR_PACKAGE_INFO:
692 PSecPkgContext_PackageInfoA info =
693 (PSecPkgContext_PackageInfoA)pBuffer;
694 PSecPkgInfoA oldPkgInfo = info->PackageInfo;
696 if (oldPkgInfo)
698 info->PackageInfo = (PSecPkgInfoA)
699 _copyPackageInfoFlatAToW(oldPkgInfo);
700 package->provider->fnTableW.FreeContextBuffer(oldPkgInfo);
702 break;
704 case SECPKG_ATTR_NEGOTIATION_INFO:
706 PSecPkgContext_NegotiationInfoA info =
707 (PSecPkgContext_NegotiationInfoA)pBuffer;
708 PSecPkgInfoA oldPkgInfo = info->PackageInfo;
710 if (oldPkgInfo)
712 info->PackageInfo = (PSecPkgInfoA)
713 _copyPackageInfoFlatAToW(oldPkgInfo);
714 package->provider->fnTableW.FreeContextBuffer(oldPkgInfo);
716 break;
718 case SECPKG_ATTR_NATIVE_NAMES:
720 PSecPkgContext_NativeNamesA names =
721 (PSecPkgContext_NativeNamesA)pBuffer;
722 PSTR oldClient = names->sClientName;
723 PSTR oldServer = names->sServerName;
725 if (oldClient)
727 names->sClientName = (PSTR)SECUR32_AllocWideFromMultiByte(
728 oldClient);
729 package->provider->fnTableW.FreeContextBuffer(oldClient);
731 if (oldServer)
733 names->sServerName = (PSTR)SECUR32_AllocWideFromMultiByte(
734 oldServer);
735 package->provider->fnTableW.FreeContextBuffer(oldServer);
737 break;
739 case SECPKG_ATTR_CREDENTIAL_NAME:
741 PSecPkgContext_CredentialNameA name =
742 (PSecPkgContext_CredentialNameA)pBuffer;
743 PSTR oldCred = name->sCredentialName;
745 if (oldCred)
747 name->sCredentialName =
748 (PSTR)SECUR32_AllocWideFromMultiByte(oldCred);
749 package->provider->fnTableW.FreeContextBuffer(oldCred);
751 break;
753 /* no thunking needed: */
754 case SECPKG_ATTR_ACCESS_TOKEN:
755 case SECPKG_ATTR_DCE_INFO:
756 case SECPKG_ATTR_FLAGS:
757 case SECPKG_ATTR_LIFESPAN:
758 case SECPKG_ATTR_PASSWORD_EXPIRY:
759 case SECPKG_ATTR_SESSION_KEY:
760 case SECPKG_ATTR_SIZES:
761 case SECPKG_ATTR_STREAM_SIZES:
762 case SECPKG_ATTR_TARGET_INFORMATION:
763 break;
764 default:
765 WARN("attribute type %ld unknown\n", ulAttribute);
766 ret = SEC_E_INTERNAL_ERROR;
769 else
770 ret = SEC_E_INVALID_TOKEN;
771 return ret;
774 SECURITY_STATUS SEC_ENTRY thunk_QueryContextAttributesW(PCtxtHandle phContext,
775 unsigned long ulAttribute, void *pBuffer)
777 SECURITY_STATUS ret;
779 TRACE("%p %ld %p\n", phContext, ulAttribute, pBuffer);
780 if (phContext)
782 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
783 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
785 if (package && package->provider)
787 if (package->provider->fnTableA.QueryContextAttributesA)
789 ret = package->provider->fnTableA.QueryContextAttributesA(
790 ctxt, ulAttribute, pBuffer);
791 if (ret == SEC_E_OK)
792 ret = thunk_ContextAttributesAToW(package, ulAttribute,
793 pBuffer);
795 else
796 ret = SEC_E_UNSUPPORTED_FUNCTION;
798 else
799 ret = SEC_E_INVALID_HANDLE;
801 else
802 ret = SEC_E_INVALID_HANDLE;
803 return ret;
806 SECURITY_STATUS SEC_ENTRY thunk_SetContextAttributesA(PCtxtHandle phContext,
807 unsigned long ulAttribute, void *pBuffer, unsigned long cbBuffer)
809 SECURITY_STATUS ret;
811 TRACE("%p %ld %p %ld\n", phContext, ulAttribute, pBuffer, cbBuffer);
812 if (phContext)
814 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
815 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
817 if (package && package->provider && pBuffer && cbBuffer)
819 if (package->provider->fnTableW.SetContextAttributesW)
821 /* TODO: gotta validate size too! */
822 ret = thunk_ContextAttributesWToA(package, ulAttribute,
823 pBuffer);
824 if (ret == SEC_E_OK)
825 ret = package->provider->fnTableW.SetContextAttributesW(
826 ctxt, ulAttribute, pBuffer, cbBuffer);
828 else
829 ret = SEC_E_UNSUPPORTED_FUNCTION;
831 else
832 ret = SEC_E_INVALID_HANDLE;
834 else
835 ret = SEC_E_INVALID_HANDLE;
836 return ret;
839 SECURITY_STATUS SEC_ENTRY thunk_SetContextAttributesW(PCtxtHandle phContext,
840 unsigned long ulAttribute, void *pBuffer, unsigned long cbBuffer)
842 SECURITY_STATUS ret;
844 TRACE("%p %ld %p %ld\n", phContext, ulAttribute, pBuffer, cbBuffer);
845 if (phContext)
847 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
848 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
850 if (package && package->provider && pBuffer && cbBuffer)
852 if (package->provider->fnTableA.SetContextAttributesA)
854 /* TODO: gotta validate size too! */
855 ret = thunk_ContextAttributesAToW(package, ulAttribute,
856 pBuffer);
857 if (ret == SEC_E_OK)
858 ret = package->provider->fnTableA.SetContextAttributesA(
859 ctxt, ulAttribute, pBuffer, cbBuffer);
861 else
862 ret = SEC_E_UNSUPPORTED_FUNCTION;
864 else
865 ret = SEC_E_INVALID_HANDLE;
867 else
868 ret = SEC_E_INVALID_HANDLE;
869 return ret;
872 SECURITY_STATUS SEC_ENTRY thunk_ImportSecurityContextA(
873 SEC_CHAR *pszPackage, PSecBuffer pPackedContext, void *Token,
874 PCtxtHandle phContext)
876 SECURITY_STATUS ret;
877 UNICODE_STRING package;
879 TRACE("%s %p %p %p\n", debugstr_a(pszPackage), pPackedContext, Token,
880 phContext);
881 RtlCreateUnicodeStringFromAsciiz(&package, pszPackage);
882 ret = ImportSecurityContextW(package.Buffer, pPackedContext, Token,
883 phContext);
884 RtlFreeUnicodeString(&package);
885 return ret;
888 SECURITY_STATUS SEC_ENTRY thunk_ImportSecurityContextW(
889 SEC_WCHAR *pszPackage, PSecBuffer pPackedContext, void *Token,
890 PCtxtHandle phContext)
892 SECURITY_STATUS ret;
893 PSTR package = SECUR32_AllocMultiByteFromWide(pszPackage);
895 TRACE("%s %p %p %p\n", debugstr_w(pszPackage), pPackedContext, Token,
896 phContext);
897 ret = ImportSecurityContextA(package, pPackedContext, Token, phContext);
898 SECUR32_FREE(package);
899 return ret;