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
26 #include "secur32_priv.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
)
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
);
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
);
56 ret
= SEC_E_SECPKG_NOT_FOUND
;
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
)
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
);
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
,
79 HeapFree(GetProcessHeap(), 0, principal
);
80 HeapFree(GetProcessHeap(), 0, package
);
83 ret
= SEC_E_SECPKG_NOT_FOUND
;
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
)
95 TRACE("%p %d %p\n", phCredential
, ulAttribute
, pBuffer
);
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
);
111 case SECPKG_CRED_ATTR_NAMES
:
113 PSecPkgCredentials_NamesW names
=
114 (PSecPkgCredentials_NamesW
)pBuffer
;
115 SEC_WCHAR
*oldUser
= names
->sUserName
;
120 (PWSTR
)SECUR32_AllocMultiByteFromWide(oldUser
);
121 package
->provider
->fnTableW
.FreeContextBuffer(
127 WARN("attribute type %d unknown\n", ulAttribute
);
128 ret
= SEC_E_INTERNAL_ERROR
;
133 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
136 ret
= SEC_E_INVALID_HANDLE
;
139 ret
= SEC_E_INVALID_HANDLE
;
143 SECURITY_STATUS SEC_ENTRY
thunk_QueryCredentialsAttributesW(
144 PCredHandle phCredential
, ULONG ulAttribute
, void *pBuffer
)
148 TRACE("%p %d %p\n", phCredential
, ulAttribute
, pBuffer
);
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
);
164 case SECPKG_CRED_ATTR_NAMES
:
166 PSecPkgCredentials_NamesA names
=
167 (PSecPkgCredentials_NamesA
)pBuffer
;
168 SEC_CHAR
*oldUser
= names
->sUserName
;
173 (PSTR
)SECUR32_AllocWideFromMultiByte(oldUser
);
174 package
->provider
->fnTableA
.FreeContextBuffer(
180 WARN("attribute type %d unknown\n", ulAttribute
);
181 ret
= SEC_E_INTERNAL_ERROR
;
186 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
189 ret
= SEC_E_INVALID_HANDLE
;
192 ret
= SEC_E_INVALID_HANDLE
;
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
)
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
);
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
);
226 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
229 ret
= SEC_E_INVALID_HANDLE
;
232 ret
= SEC_E_INVALID_HANDLE
;
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
)
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
);
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
);
265 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
268 ret
= SEC_E_INVALID_HANDLE
;
271 ret
= SEC_E_INVALID_HANDLE
;
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
)
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
);
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
);
305 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
308 ret
= SEC_E_INVALID_HANDLE
;
311 ret
= SEC_E_INVALID_HANDLE
;
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
)
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
);
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
);
344 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
347 ret
= SEC_E_INVALID_HANDLE
;
350 ret
= SEC_E_INVALID_HANDLE
;
354 static PSecPkgInfoA
_copyPackageInfoFlatWToA(const SecPkgInfoW
*infoW
)
360 size_t bytesNeeded
= sizeof(SecPkgInfoA
);
361 int nameLen
= 0, commentLen
= 0;
365 nameLen
= WideCharToMultiByte(CP_ACP
, 0, infoW
->Name
, -1,
366 NULL
, 0, NULL
, NULL
);
367 bytesNeeded
+= nameLen
;
371 commentLen
= WideCharToMultiByte(CP_ACP
, 0, infoW
->Comment
, -1,
372 NULL
, 0, NULL
, NULL
);
373 bytesNeeded
+= commentLen
;
375 ret
= HeapAlloc(GetProcessHeap(), 0, bytesNeeded
);
378 PSTR nextString
= (PSTR
)((PBYTE
)ret
+ sizeof(SecPkgInfoA
));
380 memcpy(ret
, infoW
, sizeof(SecPkgInfoA
));
383 ret
->Name
= nextString
;
384 WideCharToMultiByte(CP_ACP
, 0, infoW
->Name
, -1, nextString
,
385 nameLen
, NULL
, NULL
);
386 nextString
+= nameLen
;
392 ret
->Comment
= nextString
;
393 WideCharToMultiByte(CP_ACP
, 0, infoW
->Comment
, -1, nextString
,
394 nameLen
, NULL
, NULL
);
405 static SECURITY_STATUS
thunk_ContextAttributesWToA(SecurePackage
*package
,
406 ULONG ulAttribute
, void *pBuffer
)
408 SECURITY_STATUS ret
= SEC_E_OK
;
410 if (package
&& pBuffer
)
414 case SECPKG_ATTR_NAMES
:
416 PSecPkgContext_NamesW names
= (PSecPkgContext_NamesW
)pBuffer
;
417 SEC_WCHAR
*oldUser
= names
->sUserName
;
422 (PWSTR
)SECUR32_AllocMultiByteFromWide(oldUser
);
423 package
->provider
->fnTableW
.FreeContextBuffer(oldUser
);
427 case SECPKG_ATTR_AUTHORITY
:
429 PSecPkgContext_AuthorityW names
=
430 (PSecPkgContext_AuthorityW
)pBuffer
;
431 SEC_WCHAR
*oldAuth
= names
->sAuthorityName
;
435 names
->sAuthorityName
=
436 (PWSTR
)SECUR32_AllocMultiByteFromWide(oldAuth
);
437 package
->provider
->fnTableW
.FreeContextBuffer(oldAuth
);
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
;
449 info
->sSignatureAlgorithmName
=
450 (PWSTR
)SECUR32_AllocMultiByteFromWide(oldSigAlgName
);
451 package
->provider
->fnTableW
.FreeContextBuffer(
456 info
->sEncryptAlgorithmName
=
457 (PWSTR
)SECUR32_AllocMultiByteFromWide(oldEncAlgName
);
458 package
->provider
->fnTableW
.FreeContextBuffer(
463 case SECPKG_ATTR_PACKAGE_INFO
:
465 PSecPkgContext_PackageInfoW info
=
466 (PSecPkgContext_PackageInfoW
)pBuffer
;
467 PSecPkgInfoW oldPkgInfo
= info
->PackageInfo
;
471 info
->PackageInfo
= (PSecPkgInfoW
)
472 _copyPackageInfoFlatWToA(oldPkgInfo
);
473 package
->provider
->fnTableW
.FreeContextBuffer(oldPkgInfo
);
477 case SECPKG_ATTR_NEGOTIATION_INFO
:
479 PSecPkgContext_NegotiationInfoW info
=
480 (PSecPkgContext_NegotiationInfoW
)pBuffer
;
481 PSecPkgInfoW oldPkgInfo
= info
->PackageInfo
;
485 info
->PackageInfo
= (PSecPkgInfoW
)
486 _copyPackageInfoFlatWToA(oldPkgInfo
);
487 package
->provider
->fnTableW
.FreeContextBuffer(oldPkgInfo
);
491 case SECPKG_ATTR_NATIVE_NAMES
:
493 PSecPkgContext_NativeNamesW names
=
494 (PSecPkgContext_NativeNamesW
)pBuffer
;
495 PWSTR oldClient
= names
->sClientName
;
496 PWSTR oldServer
= names
->sServerName
;
500 names
->sClientName
= (PWSTR
)SECUR32_AllocMultiByteFromWide(
502 package
->provider
->fnTableW
.FreeContextBuffer(oldClient
);
506 names
->sServerName
= (PWSTR
)SECUR32_AllocMultiByteFromWide(
508 package
->provider
->fnTableW
.FreeContextBuffer(oldServer
);
512 case SECPKG_ATTR_CREDENTIAL_NAME
:
514 PSecPkgContext_CredentialNameW name
=
515 (PSecPkgContext_CredentialNameW
)pBuffer
;
516 PWSTR oldCred
= name
->sCredentialName
;
520 name
->sCredentialName
=
521 (PWSTR
)SECUR32_AllocMultiByteFromWide(oldCred
);
522 package
->provider
->fnTableW
.FreeContextBuffer(oldCred
);
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
:
538 WARN("attribute type %d unknown\n", ulAttribute
);
539 ret
= SEC_E_INTERNAL_ERROR
;
543 ret
= SEC_E_INVALID_TOKEN
;
547 SECURITY_STATUS SEC_ENTRY
thunk_QueryContextAttributesA(PCtxtHandle phContext
,
548 ULONG ulAttribute
, void *pBuffer
)
552 TRACE("%p %d %p\n", phContext
, ulAttribute
, pBuffer
);
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
);
565 ret
= thunk_ContextAttributesWToA(package
, ulAttribute
,
569 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
572 ret
= SEC_E_INVALID_HANDLE
;
575 ret
= SEC_E_INVALID_HANDLE
;
579 static PSecPkgInfoW
_copyPackageInfoFlatAToW(const SecPkgInfoA
*infoA
)
585 size_t bytesNeeded
= sizeof(SecPkgInfoW
);
586 int nameLen
= 0, commentLen
= 0;
590 nameLen
= MultiByteToWideChar(CP_ACP
, 0, infoA
->Name
, -1,
592 bytesNeeded
+= nameLen
* sizeof(WCHAR
);
596 commentLen
= MultiByteToWideChar(CP_ACP
, 0, infoA
->Comment
, -1,
598 bytesNeeded
+= commentLen
* sizeof(WCHAR
);
600 ret
= HeapAlloc(GetProcessHeap(), 0, bytesNeeded
);
603 PWSTR nextString
= (PWSTR
)((PBYTE
)ret
+ sizeof(SecPkgInfoW
));
605 memcpy(ret
, infoA
, sizeof(SecPkgInfoA
));
608 ret
->Name
= nextString
;
609 MultiByteToWideChar(CP_ACP
, 0, infoA
->Name
, -1, nextString
,
611 nextString
+= nameLen
;
617 ret
->Comment
= nextString
;
618 MultiByteToWideChar(CP_ACP
, 0, infoA
->Comment
, -1, nextString
,
630 static SECURITY_STATUS
thunk_ContextAttributesAToW(SecurePackage
*package
,
631 ULONG ulAttribute
, void *pBuffer
)
633 SECURITY_STATUS ret
= SEC_E_OK
;
635 if (package
&& pBuffer
)
639 case SECPKG_ATTR_NAMES
:
641 PSecPkgContext_NamesA names
= (PSecPkgContext_NamesA
)pBuffer
;
642 SEC_CHAR
*oldUser
= names
->sUserName
;
647 (PSTR
)SECUR32_AllocWideFromMultiByte(oldUser
);
648 package
->provider
->fnTableW
.FreeContextBuffer(oldUser
);
652 case SECPKG_ATTR_AUTHORITY
:
654 PSecPkgContext_AuthorityA names
=
655 (PSecPkgContext_AuthorityA
)pBuffer
;
656 SEC_CHAR
*oldAuth
= names
->sAuthorityName
;
660 names
->sAuthorityName
=
661 (PSTR
)SECUR32_AllocWideFromMultiByte(oldAuth
);
662 package
->provider
->fnTableW
.FreeContextBuffer(oldAuth
);
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
;
674 info
->sSignatureAlgorithmName
=
675 (PSTR
)SECUR32_AllocWideFromMultiByte(oldSigAlgName
);
676 package
->provider
->fnTableW
.FreeContextBuffer(
681 info
->sEncryptAlgorithmName
=
682 (PSTR
)SECUR32_AllocWideFromMultiByte(
684 package
->provider
->fnTableW
.FreeContextBuffer(
689 case SECPKG_ATTR_PACKAGE_INFO
:
691 PSecPkgContext_PackageInfoA info
=
692 (PSecPkgContext_PackageInfoA
)pBuffer
;
693 PSecPkgInfoA oldPkgInfo
= info
->PackageInfo
;
697 info
->PackageInfo
= (PSecPkgInfoA
)
698 _copyPackageInfoFlatAToW(oldPkgInfo
);
699 package
->provider
->fnTableW
.FreeContextBuffer(oldPkgInfo
);
703 case SECPKG_ATTR_NEGOTIATION_INFO
:
705 PSecPkgContext_NegotiationInfoA info
=
706 (PSecPkgContext_NegotiationInfoA
)pBuffer
;
707 PSecPkgInfoA oldPkgInfo
= info
->PackageInfo
;
711 info
->PackageInfo
= (PSecPkgInfoA
)
712 _copyPackageInfoFlatAToW(oldPkgInfo
);
713 package
->provider
->fnTableW
.FreeContextBuffer(oldPkgInfo
);
717 case SECPKG_ATTR_NATIVE_NAMES
:
719 PSecPkgContext_NativeNamesA names
=
720 (PSecPkgContext_NativeNamesA
)pBuffer
;
721 PSTR oldClient
= names
->sClientName
;
722 PSTR oldServer
= names
->sServerName
;
726 names
->sClientName
= (PSTR
)SECUR32_AllocWideFromMultiByte(
728 package
->provider
->fnTableW
.FreeContextBuffer(oldClient
);
732 names
->sServerName
= (PSTR
)SECUR32_AllocWideFromMultiByte(
734 package
->provider
->fnTableW
.FreeContextBuffer(oldServer
);
738 case SECPKG_ATTR_CREDENTIAL_NAME
:
740 PSecPkgContext_CredentialNameA name
=
741 (PSecPkgContext_CredentialNameA
)pBuffer
;
742 PSTR oldCred
= name
->sCredentialName
;
746 name
->sCredentialName
=
747 (PSTR
)SECUR32_AllocWideFromMultiByte(oldCred
);
748 package
->provider
->fnTableW
.FreeContextBuffer(oldCred
);
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
:
764 WARN("attribute type %d unknown\n", ulAttribute
);
765 ret
= SEC_E_INTERNAL_ERROR
;
769 ret
= SEC_E_INVALID_TOKEN
;
773 SECURITY_STATUS SEC_ENTRY
thunk_QueryContextAttributesW(PCtxtHandle phContext
,
774 ULONG ulAttribute
, void *pBuffer
)
778 TRACE("%p %d %p\n", phContext
, ulAttribute
, pBuffer
);
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
);
791 ret
= thunk_ContextAttributesAToW(package
, ulAttribute
,
795 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
798 ret
= SEC_E_INVALID_HANDLE
;
801 ret
= SEC_E_INVALID_HANDLE
;
805 SECURITY_STATUS SEC_ENTRY
thunk_SetContextAttributesA(PCtxtHandle phContext
,
806 ULONG ulAttribute
, void *pBuffer
, ULONG cbBuffer
)
810 TRACE("%p %d %p %d\n", phContext
, ulAttribute
, pBuffer
, cbBuffer
);
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
,
824 ret
= package
->provider
->fnTableW
.SetContextAttributesW(
825 ctxt
, ulAttribute
, pBuffer
, cbBuffer
);
828 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
831 ret
= SEC_E_INVALID_HANDLE
;
834 ret
= SEC_E_INVALID_HANDLE
;
838 SECURITY_STATUS SEC_ENTRY
thunk_SetContextAttributesW(PCtxtHandle phContext
,
839 ULONG ulAttribute
, void *pBuffer
, ULONG cbBuffer
)
843 TRACE("%p %d %p %d\n", phContext
, ulAttribute
, pBuffer
, cbBuffer
);
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
,
857 ret
= package
->provider
->fnTableA
.SetContextAttributesA(
858 ctxt
, ulAttribute
, pBuffer
, cbBuffer
);
861 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
864 ret
= SEC_E_INVALID_HANDLE
;
867 ret
= SEC_E_INVALID_HANDLE
;
871 SECURITY_STATUS SEC_ENTRY
thunk_ImportSecurityContextA(
872 SEC_CHAR
*pszPackage
, PSecBuffer pPackedContext
, void *Token
,
873 PCtxtHandle phContext
)
876 UNICODE_STRING package
;
878 TRACE("%s %p %p %p\n", debugstr_a(pszPackage
), pPackedContext
, Token
,
880 RtlCreateUnicodeStringFromAsciiz(&package
, pszPackage
);
881 ret
= ImportSecurityContextW(package
.Buffer
, pPackedContext
, Token
,
883 RtlFreeUnicodeString(&package
);
887 SECURITY_STATUS SEC_ENTRY
thunk_ImportSecurityContextW(
888 SEC_WCHAR
*pszPackage
, PSecBuffer pPackedContext
, void *Token
,
889 PCtxtHandle phContext
)
892 PSTR package
= SECUR32_AllocMultiByteFromWide(pszPackage
);
894 TRACE("%s %p %p %p\n", debugstr_w(pszPackage
), pPackedContext
, Token
,
896 ret
= ImportSecurityContextA(package
, pPackedContext
, Token
, phContext
);
897 HeapFree(GetProcessHeap(), 0, package
);