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
22 #include "wine/debug.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(secur32
);
26 SECURITY_STATUS SEC_ENTRY
thunk_AcquireCredentialsHandleA(
27 SEC_CHAR
*pszPrincipal
, SEC_CHAR
*pszPackage
, ULONG fCredentialsUse
,
28 PLUID pvLogonID
, PVOID pAuthData
, SEC_GET_KEY_FN pGetKeyFn
,
29 PVOID pvGetKeyArgument
, PCredHandle phCredential
, PTimeStamp ptsExpiry
)
33 TRACE("%s %s %d %p %p %p %p %p %p\n", debugstr_a(pszPrincipal
),
34 debugstr_a(pszPackage
), fCredentialsUse
, pvLogonID
, pAuthData
, pGetKeyFn
,
35 pvGetKeyArgument
, phCredential
, ptsExpiry
);
38 UNICODE_STRING principal
, package
;
40 RtlCreateUnicodeStringFromAsciiz(&principal
, pszPrincipal
);
41 RtlCreateUnicodeStringFromAsciiz(&package
, pszPackage
);
42 ret
= AcquireCredentialsHandleW(principal
.Buffer
, package
.Buffer
,
43 fCredentialsUse
, pvLogonID
, pAuthData
, pGetKeyFn
, pvGetKeyArgument
,
44 phCredential
, ptsExpiry
);
45 RtlFreeUnicodeString(&principal
);
46 RtlFreeUnicodeString(&package
);
49 ret
= SEC_E_SECPKG_NOT_FOUND
;
53 SECURITY_STATUS SEC_ENTRY
thunk_AcquireCredentialsHandleW(
54 SEC_WCHAR
*pszPrincipal
, SEC_WCHAR
*pszPackage
, ULONG fCredentialsUse
,
55 PLUID pvLogonID
, PVOID pAuthData
, SEC_GET_KEY_FN pGetKeyFn
,
56 PVOID pvGetKeyArgument
, PCredHandle phCredential
, PTimeStamp ptsExpiry
)
60 TRACE("%s %s %d %p %p %p %p %p %p\n", debugstr_w(pszPrincipal
),
61 debugstr_w(pszPackage
), fCredentialsUse
, pvLogonID
, pAuthData
, pGetKeyFn
,
62 pvGetKeyArgument
, phCredential
, ptsExpiry
);
65 PSTR principal
, package
;
67 principal
= SECUR32_AllocMultiByteFromWide(pszPrincipal
);
68 package
= SECUR32_AllocMultiByteFromWide(pszPackage
);
69 ret
= AcquireCredentialsHandleA(principal
, package
, fCredentialsUse
,
70 pvLogonID
, pAuthData
, pGetKeyFn
, pvGetKeyArgument
, phCredential
,
72 HeapFree(GetProcessHeap(), 0, principal
);
73 HeapFree(GetProcessHeap(), 0, package
);
76 ret
= SEC_E_SECPKG_NOT_FOUND
;
80 /* thunking is pretty dicey for these--the output type depends on ulAttribute,
81 * so we have to know about every type the caller does
83 SECURITY_STATUS SEC_ENTRY
thunk_QueryCredentialsAttributesA(
84 PCredHandle phCredential
, ULONG ulAttribute
, void *pBuffer
)
88 TRACE("%p %d %p\n", phCredential
, ulAttribute
, pBuffer
);
91 SecurePackage
*package
= (SecurePackage
*)phCredential
->dwUpper
;
92 PCredHandle cred
= (PCredHandle
)phCredential
->dwLower
;
94 if (package
&& package
->provider
)
96 if (package
->provider
->fnTableW
.QueryCredentialsAttributesW
)
98 ret
= package
->provider
->fnTableW
.QueryCredentialsAttributesW(
99 cred
, ulAttribute
, pBuffer
);
104 case SECPKG_CRED_ATTR_NAMES
:
106 PSecPkgCredentials_NamesW names
=
107 (PSecPkgCredentials_NamesW
)pBuffer
;
108 SEC_WCHAR
*oldUser
= names
->sUserName
;
113 (PWSTR
)SECUR32_AllocMultiByteFromWide(oldUser
);
114 package
->provider
->fnTableW
.FreeContextBuffer(
120 WARN("attribute type %d unknown\n", ulAttribute
);
121 ret
= SEC_E_INTERNAL_ERROR
;
126 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
129 ret
= SEC_E_INVALID_HANDLE
;
132 ret
= SEC_E_INVALID_HANDLE
;
136 SECURITY_STATUS SEC_ENTRY
thunk_QueryCredentialsAttributesW(
137 PCredHandle phCredential
, ULONG ulAttribute
, void *pBuffer
)
141 TRACE("%p %d %p\n", phCredential
, ulAttribute
, pBuffer
);
144 SecurePackage
*package
= (SecurePackage
*)phCredential
->dwUpper
;
145 PCredHandle cred
= (PCredHandle
)phCredential
->dwLower
;
147 if (package
&& package
->provider
)
149 if (package
->provider
->fnTableA
.QueryCredentialsAttributesA
)
151 ret
= package
->provider
->fnTableA
.QueryCredentialsAttributesA(
152 cred
, ulAttribute
, pBuffer
);
157 case SECPKG_CRED_ATTR_NAMES
:
159 PSecPkgCredentials_NamesA names
=
160 (PSecPkgCredentials_NamesA
)pBuffer
;
161 SEC_CHAR
*oldUser
= names
->sUserName
;
166 (PSTR
)SECUR32_AllocWideFromMultiByte(oldUser
);
167 package
->provider
->fnTableA
.FreeContextBuffer(
173 WARN("attribute type %d unknown\n", ulAttribute
);
174 ret
= SEC_E_INTERNAL_ERROR
;
179 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
182 ret
= SEC_E_INVALID_HANDLE
;
185 ret
= SEC_E_INVALID_HANDLE
;
189 SECURITY_STATUS SEC_ENTRY
thunk_InitializeSecurityContextA(
190 PCredHandle phCredential
, PCtxtHandle phContext
,
191 SEC_CHAR
*pszTargetName
, ULONG fContextReq
,
192 ULONG Reserved1
, ULONG TargetDataRep
, PSecBufferDesc pInput
,
193 ULONG Reserved2
, PCtxtHandle phNewContext
, PSecBufferDesc pOutput
,
194 ULONG
*pfContextAttr
, PTimeStamp ptsExpiry
)
198 TRACE("%p %p %s %d %d %d %p %d %p %p %p %p\n", phCredential
, phContext
,
199 debugstr_a(pszTargetName
), fContextReq
, Reserved1
, TargetDataRep
, pInput
,
200 Reserved1
, phNewContext
, pOutput
, pfContextAttr
, ptsExpiry
);
203 SecurePackage
*package
= (SecurePackage
*)phCredential
->dwUpper
;
205 if (package
&& package
->provider
)
207 if (package
->provider
->fnTableW
.InitializeSecurityContextW
)
209 UNICODE_STRING target
;
211 RtlCreateUnicodeStringFromAsciiz(&target
, pszTargetName
);
212 ret
= package
->provider
->fnTableW
.InitializeSecurityContextW(
213 phCredential
, phContext
, target
.Buffer
, fContextReq
, Reserved1
,
214 TargetDataRep
, pInput
, Reserved2
, phNewContext
, pOutput
,
215 pfContextAttr
, ptsExpiry
);
216 RtlFreeUnicodeString(&target
);
219 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
222 ret
= SEC_E_INVALID_HANDLE
;
225 ret
= SEC_E_INVALID_HANDLE
;
229 SECURITY_STATUS SEC_ENTRY
thunk_InitializeSecurityContextW(
230 PCredHandle phCredential
, PCtxtHandle phContext
,
231 SEC_WCHAR
*pszTargetName
, ULONG fContextReq
,
232 ULONG Reserved1
, ULONG TargetDataRep
, PSecBufferDesc pInput
,
233 ULONG Reserved2
, PCtxtHandle phNewContext
, PSecBufferDesc pOutput
,
234 ULONG
*pfContextAttr
, PTimeStamp ptsExpiry
)
238 TRACE("%p %p %s %d %d %d %p %d %p %p %p %p\n", phCredential
, phContext
,
239 debugstr_w(pszTargetName
), fContextReq
, Reserved1
, TargetDataRep
, pInput
,
240 Reserved1
, phNewContext
, pOutput
, pfContextAttr
, ptsExpiry
);
243 SecurePackage
*package
= (SecurePackage
*)phCredential
->dwUpper
;
245 if (package
&& package
->provider
)
247 if (package
->provider
->fnTableA
.InitializeSecurityContextA
)
249 PSTR target
= SECUR32_AllocMultiByteFromWide(pszTargetName
);
251 ret
= package
->provider
->fnTableA
.InitializeSecurityContextA(
252 phCredential
, phContext
, target
, fContextReq
, Reserved1
,
253 TargetDataRep
, pInput
, Reserved2
, phNewContext
, pOutput
,
254 pfContextAttr
, ptsExpiry
);
255 HeapFree(GetProcessHeap(), 0, target
);
258 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
261 ret
= SEC_E_INVALID_HANDLE
;
264 ret
= SEC_E_INVALID_HANDLE
;
268 SECURITY_STATUS SEC_ENTRY
thunk_AddCredentialsA(PCredHandle hCredentials
,
269 SEC_CHAR
*pszPrincipal
, SEC_CHAR
*pszPackage
, ULONG fCredentialUse
,
270 void *pAuthData
, SEC_GET_KEY_FN pGetKeyFn
, void *pvGetKeyArgument
,
271 PTimeStamp ptsExpiry
)
275 TRACE("%p %s %s %d %p %p %p %p\n", hCredentials
, debugstr_a(pszPrincipal
),
276 debugstr_a(pszPackage
), fCredentialUse
, pAuthData
, pGetKeyFn
,
277 pvGetKeyArgument
, ptsExpiry
);
280 SecurePackage
*package
= (SecurePackage
*)hCredentials
->dwUpper
;
281 PCredHandle cred
= (PCtxtHandle
)hCredentials
->dwLower
;
283 if (package
&& package
->provider
)
285 if (package
->provider
->fnTableW
.AddCredentialsW
)
287 UNICODE_STRING szPrincipal
, szPackage
;
289 RtlCreateUnicodeStringFromAsciiz(&szPrincipal
, pszPrincipal
);
290 RtlCreateUnicodeStringFromAsciiz(&szPackage
, pszPackage
);
291 ret
= package
->provider
->fnTableW
.AddCredentialsW(
292 cred
, szPrincipal
.Buffer
, szPackage
.Buffer
, fCredentialUse
,
293 pAuthData
, pGetKeyFn
, pvGetKeyArgument
, ptsExpiry
);
294 RtlFreeUnicodeString(&szPrincipal
);
295 RtlFreeUnicodeString(&szPackage
);
298 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
301 ret
= SEC_E_INVALID_HANDLE
;
304 ret
= SEC_E_INVALID_HANDLE
;
308 SECURITY_STATUS SEC_ENTRY
thunk_AddCredentialsW(PCredHandle hCredentials
,
309 SEC_WCHAR
*pszPrincipal
, SEC_WCHAR
*pszPackage
, ULONG fCredentialUse
,
310 void *pAuthData
, SEC_GET_KEY_FN pGetKeyFn
, void *pvGetKeyArgument
,
311 PTimeStamp ptsExpiry
)
315 TRACE("%p %s %s %d %p %p %p %p\n", hCredentials
, debugstr_w(pszPrincipal
),
316 debugstr_w(pszPackage
), fCredentialUse
, pAuthData
, pGetKeyFn
,
317 pvGetKeyArgument
, ptsExpiry
);
320 SecurePackage
*package
= (SecurePackage
*)hCredentials
->dwUpper
;
321 PCredHandle cred
= (PCtxtHandle
)hCredentials
->dwLower
;
323 if (package
&& package
->provider
)
325 if (package
->provider
->fnTableA
.AddCredentialsA
)
327 PSTR szPrincipal
= SECUR32_AllocMultiByteFromWide(pszPrincipal
);
328 PSTR szPackage
= SECUR32_AllocMultiByteFromWide(pszPackage
);
330 ret
= package
->provider
->fnTableA
.AddCredentialsA(
331 cred
, szPrincipal
, szPackage
, fCredentialUse
, pAuthData
,
332 pGetKeyFn
, pvGetKeyArgument
, ptsExpiry
);
333 HeapFree(GetProcessHeap(), 0, szPrincipal
);
334 HeapFree(GetProcessHeap(), 0, szPackage
);
337 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
340 ret
= SEC_E_INVALID_HANDLE
;
343 ret
= SEC_E_INVALID_HANDLE
;
347 static PSecPkgInfoA
_copyPackageInfoFlatWToA(const SecPkgInfoW
*infoW
)
353 size_t bytesNeeded
= sizeof(SecPkgInfoA
);
354 int nameLen
= 0, commentLen
= 0;
358 nameLen
= WideCharToMultiByte(CP_ACP
, 0, infoW
->Name
, -1,
359 NULL
, 0, NULL
, NULL
);
360 bytesNeeded
+= nameLen
;
364 commentLen
= WideCharToMultiByte(CP_ACP
, 0, infoW
->Comment
, -1,
365 NULL
, 0, NULL
, NULL
);
366 bytesNeeded
+= commentLen
;
368 ret
= HeapAlloc(GetProcessHeap(), 0, bytesNeeded
);
371 PSTR nextString
= (PSTR
)((PBYTE
)ret
+ sizeof(SecPkgInfoA
));
373 memcpy(ret
, infoW
, sizeof(SecPkgInfoA
));
376 ret
->Name
= nextString
;
377 WideCharToMultiByte(CP_ACP
, 0, infoW
->Name
, -1, nextString
,
378 nameLen
, NULL
, NULL
);
379 nextString
+= nameLen
;
385 ret
->Comment
= nextString
;
386 WideCharToMultiByte(CP_ACP
, 0, infoW
->Comment
, -1, nextString
,
387 nameLen
, NULL
, NULL
);
398 static SECURITY_STATUS
thunk_ContextAttributesWToA(SecurePackage
*package
,
399 ULONG ulAttribute
, void *pBuffer
)
401 SECURITY_STATUS ret
= SEC_E_OK
;
403 if (package
&& pBuffer
)
407 case SECPKG_ATTR_NAMES
:
409 PSecPkgContext_NamesW names
= (PSecPkgContext_NamesW
)pBuffer
;
410 SEC_WCHAR
*oldUser
= names
->sUserName
;
415 (PWSTR
)SECUR32_AllocMultiByteFromWide(oldUser
);
416 package
->provider
->fnTableW
.FreeContextBuffer(oldUser
);
420 case SECPKG_ATTR_AUTHORITY
:
422 PSecPkgContext_AuthorityW names
=
423 (PSecPkgContext_AuthorityW
)pBuffer
;
424 SEC_WCHAR
*oldAuth
= names
->sAuthorityName
;
428 names
->sAuthorityName
=
429 (PWSTR
)SECUR32_AllocMultiByteFromWide(oldAuth
);
430 package
->provider
->fnTableW
.FreeContextBuffer(oldAuth
);
434 case SECPKG_ATTR_KEY_INFO
:
436 PSecPkgContext_KeyInfoW info
= (PSecPkgContext_KeyInfoW
)pBuffer
;
437 SEC_WCHAR
*oldSigAlgName
= info
->sSignatureAlgorithmName
;
438 SEC_WCHAR
*oldEncAlgName
= info
->sEncryptAlgorithmName
;
442 info
->sSignatureAlgorithmName
=
443 (PWSTR
)SECUR32_AllocMultiByteFromWide(oldSigAlgName
);
444 package
->provider
->fnTableW
.FreeContextBuffer(
449 info
->sEncryptAlgorithmName
=
450 (PWSTR
)SECUR32_AllocMultiByteFromWide(oldEncAlgName
);
451 package
->provider
->fnTableW
.FreeContextBuffer(
456 case SECPKG_ATTR_PACKAGE_INFO
:
458 PSecPkgContext_PackageInfoW info
=
459 (PSecPkgContext_PackageInfoW
)pBuffer
;
460 PSecPkgInfoW oldPkgInfo
= info
->PackageInfo
;
464 info
->PackageInfo
= (PSecPkgInfoW
)
465 _copyPackageInfoFlatWToA(oldPkgInfo
);
466 package
->provider
->fnTableW
.FreeContextBuffer(oldPkgInfo
);
470 case SECPKG_ATTR_NEGOTIATION_INFO
:
472 PSecPkgContext_NegotiationInfoW info
=
473 (PSecPkgContext_NegotiationInfoW
)pBuffer
;
474 PSecPkgInfoW oldPkgInfo
= info
->PackageInfo
;
478 info
->PackageInfo
= (PSecPkgInfoW
)
479 _copyPackageInfoFlatWToA(oldPkgInfo
);
480 package
->provider
->fnTableW
.FreeContextBuffer(oldPkgInfo
);
484 case SECPKG_ATTR_NATIVE_NAMES
:
486 PSecPkgContext_NativeNamesW names
=
487 (PSecPkgContext_NativeNamesW
)pBuffer
;
488 PWSTR oldClient
= names
->sClientName
;
489 PWSTR oldServer
= names
->sServerName
;
493 names
->sClientName
= (PWSTR
)SECUR32_AllocMultiByteFromWide(
495 package
->provider
->fnTableW
.FreeContextBuffer(oldClient
);
499 names
->sServerName
= (PWSTR
)SECUR32_AllocMultiByteFromWide(
501 package
->provider
->fnTableW
.FreeContextBuffer(oldServer
);
505 case SECPKG_ATTR_CREDENTIAL_NAME
:
507 PSecPkgContext_CredentialNameW name
=
508 (PSecPkgContext_CredentialNameW
)pBuffer
;
509 PWSTR oldCred
= name
->sCredentialName
;
513 name
->sCredentialName
=
514 (PWSTR
)SECUR32_AllocMultiByteFromWide(oldCred
);
515 package
->provider
->fnTableW
.FreeContextBuffer(oldCred
);
519 /* no thunking needed: */
520 case SECPKG_ATTR_ACCESS_TOKEN
:
521 case SECPKG_ATTR_DCE_INFO
:
522 case SECPKG_ATTR_FLAGS
:
523 case SECPKG_ATTR_LIFESPAN
:
524 case SECPKG_ATTR_PASSWORD_EXPIRY
:
525 case SECPKG_ATTR_SESSION_KEY
:
526 case SECPKG_ATTR_SIZES
:
527 case SECPKG_ATTR_STREAM_SIZES
:
528 case SECPKG_ATTR_TARGET_INFORMATION
:
531 WARN("attribute type %d unknown\n", ulAttribute
);
532 ret
= SEC_E_INTERNAL_ERROR
;
536 ret
= SEC_E_INVALID_TOKEN
;
540 SECURITY_STATUS SEC_ENTRY
thunk_QueryContextAttributesA(PCtxtHandle phContext
,
541 ULONG ulAttribute
, void *pBuffer
)
545 TRACE("%p %d %p\n", phContext
, ulAttribute
, pBuffer
);
548 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
549 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
551 if (package
&& package
->provider
)
553 if (package
->provider
->fnTableW
.QueryContextAttributesW
)
555 ret
= package
->provider
->fnTableW
.QueryContextAttributesW(
556 ctxt
, ulAttribute
, pBuffer
);
558 ret
= thunk_ContextAttributesWToA(package
, ulAttribute
,
562 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
565 ret
= SEC_E_INVALID_HANDLE
;
568 ret
= SEC_E_INVALID_HANDLE
;
572 static PSecPkgInfoW
_copyPackageInfoFlatAToW(const SecPkgInfoA
*infoA
)
578 size_t bytesNeeded
= sizeof(SecPkgInfoW
);
579 int nameLen
= 0, commentLen
= 0;
583 nameLen
= MultiByteToWideChar(CP_ACP
, 0, infoA
->Name
, -1,
585 bytesNeeded
+= nameLen
* sizeof(WCHAR
);
589 commentLen
= MultiByteToWideChar(CP_ACP
, 0, infoA
->Comment
, -1,
591 bytesNeeded
+= commentLen
* sizeof(WCHAR
);
593 ret
= HeapAlloc(GetProcessHeap(), 0, bytesNeeded
);
596 PWSTR nextString
= (PWSTR
)((PBYTE
)ret
+ sizeof(SecPkgInfoW
));
598 memcpy(ret
, infoA
, sizeof(SecPkgInfoA
));
601 ret
->Name
= nextString
;
602 MultiByteToWideChar(CP_ACP
, 0, infoA
->Name
, -1, nextString
,
604 nextString
+= nameLen
;
610 ret
->Comment
= nextString
;
611 MultiByteToWideChar(CP_ACP
, 0, infoA
->Comment
, -1, nextString
,
623 static SECURITY_STATUS
thunk_ContextAttributesAToW(SecurePackage
*package
,
624 ULONG ulAttribute
, void *pBuffer
)
626 SECURITY_STATUS ret
= SEC_E_OK
;
628 if (package
&& pBuffer
)
632 case SECPKG_ATTR_NAMES
:
634 PSecPkgContext_NamesA names
= (PSecPkgContext_NamesA
)pBuffer
;
635 SEC_CHAR
*oldUser
= names
->sUserName
;
640 (PSTR
)SECUR32_AllocWideFromMultiByte(oldUser
);
641 package
->provider
->fnTableW
.FreeContextBuffer(oldUser
);
645 case SECPKG_ATTR_AUTHORITY
:
647 PSecPkgContext_AuthorityA names
=
648 (PSecPkgContext_AuthorityA
)pBuffer
;
649 SEC_CHAR
*oldAuth
= names
->sAuthorityName
;
653 names
->sAuthorityName
=
654 (PSTR
)SECUR32_AllocWideFromMultiByte(oldAuth
);
655 package
->provider
->fnTableW
.FreeContextBuffer(oldAuth
);
659 case SECPKG_ATTR_KEY_INFO
:
661 PSecPkgContext_KeyInfoA info
= (PSecPkgContext_KeyInfoA
)pBuffer
;
662 SEC_CHAR
*oldSigAlgName
= info
->sSignatureAlgorithmName
;
663 SEC_CHAR
*oldEncAlgName
= info
->sEncryptAlgorithmName
;
667 info
->sSignatureAlgorithmName
=
668 (PSTR
)SECUR32_AllocWideFromMultiByte(oldSigAlgName
);
669 package
->provider
->fnTableW
.FreeContextBuffer(
674 info
->sEncryptAlgorithmName
=
675 (PSTR
)SECUR32_AllocWideFromMultiByte(
677 package
->provider
->fnTableW
.FreeContextBuffer(
682 case SECPKG_ATTR_PACKAGE_INFO
:
684 PSecPkgContext_PackageInfoA info
=
685 (PSecPkgContext_PackageInfoA
)pBuffer
;
686 PSecPkgInfoA oldPkgInfo
= info
->PackageInfo
;
690 info
->PackageInfo
= (PSecPkgInfoA
)
691 _copyPackageInfoFlatAToW(oldPkgInfo
);
692 package
->provider
->fnTableW
.FreeContextBuffer(oldPkgInfo
);
696 case SECPKG_ATTR_NEGOTIATION_INFO
:
698 PSecPkgContext_NegotiationInfoA info
=
699 (PSecPkgContext_NegotiationInfoA
)pBuffer
;
700 PSecPkgInfoA oldPkgInfo
= info
->PackageInfo
;
704 info
->PackageInfo
= (PSecPkgInfoA
)
705 _copyPackageInfoFlatAToW(oldPkgInfo
);
706 package
->provider
->fnTableW
.FreeContextBuffer(oldPkgInfo
);
710 case SECPKG_ATTR_NATIVE_NAMES
:
712 PSecPkgContext_NativeNamesA names
=
713 (PSecPkgContext_NativeNamesA
)pBuffer
;
714 PSTR oldClient
= names
->sClientName
;
715 PSTR oldServer
= names
->sServerName
;
719 names
->sClientName
= (PSTR
)SECUR32_AllocWideFromMultiByte(
721 package
->provider
->fnTableW
.FreeContextBuffer(oldClient
);
725 names
->sServerName
= (PSTR
)SECUR32_AllocWideFromMultiByte(
727 package
->provider
->fnTableW
.FreeContextBuffer(oldServer
);
731 case SECPKG_ATTR_CREDENTIAL_NAME
:
733 PSecPkgContext_CredentialNameA name
=
734 (PSecPkgContext_CredentialNameA
)pBuffer
;
735 PSTR oldCred
= name
->sCredentialName
;
739 name
->sCredentialName
=
740 (PSTR
)SECUR32_AllocWideFromMultiByte(oldCred
);
741 package
->provider
->fnTableW
.FreeContextBuffer(oldCred
);
745 /* no thunking needed: */
746 case SECPKG_ATTR_ACCESS_TOKEN
:
747 case SECPKG_ATTR_DCE_INFO
:
748 case SECPKG_ATTR_FLAGS
:
749 case SECPKG_ATTR_LIFESPAN
:
750 case SECPKG_ATTR_PASSWORD_EXPIRY
:
751 case SECPKG_ATTR_SESSION_KEY
:
752 case SECPKG_ATTR_SIZES
:
753 case SECPKG_ATTR_STREAM_SIZES
:
754 case SECPKG_ATTR_TARGET_INFORMATION
:
757 WARN("attribute type %d unknown\n", ulAttribute
);
758 ret
= SEC_E_INTERNAL_ERROR
;
762 ret
= SEC_E_INVALID_TOKEN
;
766 SECURITY_STATUS SEC_ENTRY
thunk_QueryContextAttributesW(PCtxtHandle phContext
,
767 ULONG ulAttribute
, void *pBuffer
)
771 TRACE("%p %d %p\n", phContext
, ulAttribute
, pBuffer
);
774 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
775 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
777 if (package
&& package
->provider
)
779 if (package
->provider
->fnTableA
.QueryContextAttributesA
)
781 ret
= package
->provider
->fnTableA
.QueryContextAttributesA(
782 ctxt
, ulAttribute
, pBuffer
);
784 ret
= thunk_ContextAttributesAToW(package
, ulAttribute
,
788 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
791 ret
= SEC_E_INVALID_HANDLE
;
794 ret
= SEC_E_INVALID_HANDLE
;
798 SECURITY_STATUS SEC_ENTRY
thunk_SetContextAttributesA(PCtxtHandle phContext
,
799 ULONG ulAttribute
, void *pBuffer
, ULONG cbBuffer
)
803 TRACE("%p %d %p %d\n", phContext
, ulAttribute
, pBuffer
, cbBuffer
);
806 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
807 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
809 if (package
&& package
->provider
&& pBuffer
&& cbBuffer
)
811 if (package
->provider
->fnTableW
.SetContextAttributesW
)
813 /* TODO: gotta validate size too! */
814 ret
= thunk_ContextAttributesWToA(package
, ulAttribute
,
817 ret
= package
->provider
->fnTableW
.SetContextAttributesW(
818 ctxt
, ulAttribute
, pBuffer
, cbBuffer
);
821 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
824 ret
= SEC_E_INVALID_HANDLE
;
827 ret
= SEC_E_INVALID_HANDLE
;
831 SECURITY_STATUS SEC_ENTRY
thunk_SetContextAttributesW(PCtxtHandle phContext
,
832 ULONG ulAttribute
, void *pBuffer
, ULONG cbBuffer
)
836 TRACE("%p %d %p %d\n", phContext
, ulAttribute
, pBuffer
, cbBuffer
);
839 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
840 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
842 if (package
&& package
->provider
&& pBuffer
&& cbBuffer
)
844 if (package
->provider
->fnTableA
.SetContextAttributesA
)
846 /* TODO: gotta validate size too! */
847 ret
= thunk_ContextAttributesAToW(package
, ulAttribute
,
850 ret
= package
->provider
->fnTableA
.SetContextAttributesA(
851 ctxt
, ulAttribute
, pBuffer
, cbBuffer
);
854 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
857 ret
= SEC_E_INVALID_HANDLE
;
860 ret
= SEC_E_INVALID_HANDLE
;
864 SECURITY_STATUS SEC_ENTRY
thunk_ImportSecurityContextA(
865 SEC_CHAR
*pszPackage
, PSecBuffer pPackedContext
, void *Token
,
866 PCtxtHandle phContext
)
869 UNICODE_STRING package
;
871 TRACE("%s %p %p %p\n", debugstr_a(pszPackage
), pPackedContext
, Token
,
873 RtlCreateUnicodeStringFromAsciiz(&package
, pszPackage
);
874 ret
= ImportSecurityContextW(package
.Buffer
, pPackedContext
, Token
,
876 RtlFreeUnicodeString(&package
);
880 SECURITY_STATUS SEC_ENTRY
thunk_ImportSecurityContextW(
881 SEC_WCHAR
*pszPackage
, PSecBuffer pPackedContext
, void *Token
,
882 PCtxtHandle phContext
)
885 PSTR package
= SECUR32_AllocMultiByteFromWide(pszPackage
);
887 TRACE("%s %p %p %p\n", debugstr_w(pszPackage
), pPackedContext
, Token
,
889 ret
= ImportSecurityContextA(package
, pPackedContext
, Token
, phContext
);
890 HeapFree(GetProcessHeap(), 0, package
);