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
27 #include "secur32_priv.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
)
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
);
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
);
57 ret
= SEC_E_SECPKG_NOT_FOUND
;
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
)
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
);
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
,
81 SECUR32_FREE(principal
);
83 SECUR32_FREE(package
);
86 ret
= SEC_E_SECPKG_NOT_FOUND
;
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
)
98 TRACE("%p %ld %p\n", phCredential
, ulAttribute
, pBuffer
);
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
);
114 case SECPKG_CRED_ATTR_NAMES
:
116 PSecPkgCredentials_NamesW names
=
117 (PSecPkgCredentials_NamesW
)pBuffer
;
118 SEC_WCHAR
*oldUser
= names
->sUserName
;
123 (PWSTR
)SECUR32_AllocMultiByteFromWide(oldUser
);
124 package
->provider
->fnTableW
.FreeContextBuffer(
130 WARN("attribute type %ld unknown\n", ulAttribute
);
131 ret
= SEC_E_INTERNAL_ERROR
;
136 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
139 ret
= SEC_E_INVALID_HANDLE
;
142 ret
= SEC_E_INVALID_HANDLE
;
146 SECURITY_STATUS SEC_ENTRY
thunk_QueryCredentialsAttributesW(
147 PCredHandle phCredential
, unsigned long ulAttribute
, void *pBuffer
)
151 TRACE("%p %ld %p\n", phCredential
, ulAttribute
, pBuffer
);
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
);
167 case SECPKG_CRED_ATTR_NAMES
:
169 PSecPkgCredentials_NamesA names
=
170 (PSecPkgCredentials_NamesA
)pBuffer
;
171 SEC_CHAR
*oldUser
= names
->sUserName
;
176 (PSTR
)SECUR32_AllocWideFromMultiByte(oldUser
);
177 package
->provider
->fnTableA
.FreeContextBuffer(
183 WARN("attribute type %ld unknown\n", ulAttribute
);
184 ret
= SEC_E_INTERNAL_ERROR
;
189 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
192 ret
= SEC_E_INVALID_HANDLE
;
195 ret
= SEC_E_INVALID_HANDLE
;
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
)
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
);
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
);
229 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
232 ret
= SEC_E_INVALID_HANDLE
;
235 ret
= SEC_E_INVALID_HANDLE
;
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
)
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
);
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
);
266 SECUR32_FREE(target
);
269 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
272 ret
= SEC_E_INVALID_HANDLE
;
275 ret
= SEC_E_INVALID_HANDLE
;
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
)
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
);
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
);
309 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
312 ret
= SEC_E_INVALID_HANDLE
;
315 ret
= SEC_E_INVALID_HANDLE
;
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
)
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
);
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
);
348 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
351 ret
= SEC_E_INVALID_HANDLE
;
354 ret
= SEC_E_INVALID_HANDLE
;
358 static PSecPkgInfoA
_copyPackageInfoFlatWToA(PSecPkgInfoW infoW
)
364 size_t bytesNeeded
= sizeof(SecPkgInfoA
);
365 int nameLen
= 0, commentLen
= 0;
369 nameLen
= WideCharToMultiByte(CP_ACP
, 0, infoW
->Name
, -1,
370 NULL
, 0, NULL
, NULL
);
371 bytesNeeded
+= nameLen
;
375 commentLen
= WideCharToMultiByte(CP_ACP
, 0, infoW
->Comment
, -1,
376 NULL
, 0, NULL
, NULL
);
377 bytesNeeded
+= commentLen
;
379 ret
= (PSecPkgInfoA
)SECUR32_ALLOC(bytesNeeded
);
382 PSTR nextString
= (PSTR
)((PBYTE
)ret
+ sizeof(SecPkgInfoA
));
384 memcpy(ret
, infoW
, sizeof(SecPkgInfoA
));
387 ret
->Name
= nextString
;
388 WideCharToMultiByte(CP_ACP
, 0, infoW
->Name
, -1, nextString
,
389 nameLen
, NULL
, NULL
);
390 nextString
+= nameLen
;
396 ret
->Comment
= nextString
;
397 WideCharToMultiByte(CP_ACP
, 0, infoW
->Comment
, -1, nextString
,
398 nameLen
, NULL
, NULL
);
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
)
418 case SECPKG_ATTR_NAMES
:
420 PSecPkgContext_NamesW names
= (PSecPkgContext_NamesW
)pBuffer
;
421 SEC_WCHAR
*oldUser
= names
->sUserName
;
426 (PWSTR
)SECUR32_AllocMultiByteFromWide(oldUser
);
427 package
->provider
->fnTableW
.FreeContextBuffer(oldUser
);
431 case SECPKG_ATTR_AUTHORITY
:
433 PSecPkgContext_AuthorityW names
=
434 (PSecPkgContext_AuthorityW
)pBuffer
;
435 SEC_WCHAR
*oldAuth
= names
->sAuthorityName
;
439 names
->sAuthorityName
=
440 (PWSTR
)SECUR32_AllocMultiByteFromWide(oldAuth
);
441 package
->provider
->fnTableW
.FreeContextBuffer(oldAuth
);
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
;
453 info
->sSignatureAlgorithmName
=
454 (PWSTR
)SECUR32_AllocMultiByteFromWide(oldSigAlgName
);
455 package
->provider
->fnTableW
.FreeContextBuffer(
460 info
->sEncryptAlgorithmName
=
461 (PWSTR
)SECUR32_AllocMultiByteFromWide(oldEncAlgName
);
462 package
->provider
->fnTableW
.FreeContextBuffer(
467 case SECPKG_ATTR_PACKAGE_INFO
:
469 PSecPkgContext_PackageInfoW info
=
470 (PSecPkgContext_PackageInfoW
)pBuffer
;
471 PSecPkgInfoW oldPkgInfo
= info
->PackageInfo
;
475 info
->PackageInfo
= (PSecPkgInfoW
)
476 _copyPackageInfoFlatWToA(oldPkgInfo
);
477 package
->provider
->fnTableW
.FreeContextBuffer(oldPkgInfo
);
481 case SECPKG_ATTR_NEGOTIATION_INFO
:
483 PSecPkgContext_NegotiationInfoW info
=
484 (PSecPkgContext_NegotiationInfoW
)pBuffer
;
485 PSecPkgInfoW oldPkgInfo
= info
->PackageInfo
;
489 info
->PackageInfo
= (PSecPkgInfoW
)
490 _copyPackageInfoFlatWToA(oldPkgInfo
);
491 package
->provider
->fnTableW
.FreeContextBuffer(oldPkgInfo
);
495 case SECPKG_ATTR_NATIVE_NAMES
:
497 PSecPkgContext_NativeNamesW names
=
498 (PSecPkgContext_NativeNamesW
)pBuffer
;
499 PWSTR oldClient
= names
->sClientName
;
500 PWSTR oldServer
= names
->sServerName
;
504 names
->sClientName
= (PWSTR
)SECUR32_AllocMultiByteFromWide(
506 package
->provider
->fnTableW
.FreeContextBuffer(oldClient
);
510 names
->sServerName
= (PWSTR
)SECUR32_AllocMultiByteFromWide(
512 package
->provider
->fnTableW
.FreeContextBuffer(oldServer
);
516 case SECPKG_ATTR_CREDENTIAL_NAME
:
518 PSecPkgContext_CredentialNameW name
=
519 (PSecPkgContext_CredentialNameW
)pBuffer
;
520 PWSTR oldCred
= name
->sCredentialName
;
524 name
->sCredentialName
=
525 (PWSTR
)SECUR32_AllocMultiByteFromWide(oldCred
);
526 package
->provider
->fnTableW
.FreeContextBuffer(oldCred
);
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
:
542 WARN("attribute type %ld unknown\n", ulAttribute
);
543 ret
= SEC_E_INTERNAL_ERROR
;
547 ret
= SEC_E_INVALID_TOKEN
;
551 SECURITY_STATUS SEC_ENTRY
thunk_QueryContextAttributesA(PCtxtHandle phContext
,
552 unsigned long ulAttribute
, void *pBuffer
)
556 TRACE("%p %ld %p\n", phContext
, ulAttribute
, pBuffer
);
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
);
569 ret
= thunk_ContextAttributesWToA(package
, ulAttribute
,
573 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
576 ret
= SEC_E_INVALID_HANDLE
;
579 ret
= SEC_E_INVALID_HANDLE
;
583 static PSecPkgInfoW
_copyPackageInfoFlatAToW(PSecPkgInfoA infoA
)
589 size_t bytesNeeded
= sizeof(SecPkgInfoW
);
590 int nameLen
= 0, commentLen
= 0;
594 nameLen
= MultiByteToWideChar(CP_ACP
, 0, infoA
->Name
, -1,
596 bytesNeeded
+= nameLen
* sizeof(WCHAR
);
600 commentLen
= MultiByteToWideChar(CP_ACP
, 0, infoA
->Comment
, -1,
602 bytesNeeded
+= commentLen
* sizeof(WCHAR
);
604 ret
= (PSecPkgInfoW
)SECUR32_ALLOC(bytesNeeded
);
607 PWSTR nextString
= (PWSTR
)((PBYTE
)ret
+ sizeof(SecPkgInfoW
));
609 memcpy(ret
, infoA
, sizeof(SecPkgInfoA
));
612 ret
->Name
= nextString
;
613 MultiByteToWideChar(CP_ACP
, 0, infoA
->Name
, -1, nextString
,
615 nextString
+= nameLen
;
621 ret
->Comment
= nextString
;
622 MultiByteToWideChar(CP_ACP
, 0, infoA
->Comment
, -1, nextString
,
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
)
643 case SECPKG_ATTR_NAMES
:
645 PSecPkgContext_NamesA names
= (PSecPkgContext_NamesA
)pBuffer
;
646 SEC_CHAR
*oldUser
= names
->sUserName
;
651 (PSTR
)SECUR32_AllocWideFromMultiByte(oldUser
);
652 package
->provider
->fnTableW
.FreeContextBuffer(oldUser
);
656 case SECPKG_ATTR_AUTHORITY
:
658 PSecPkgContext_AuthorityA names
=
659 (PSecPkgContext_AuthorityA
)pBuffer
;
660 SEC_CHAR
*oldAuth
= names
->sAuthorityName
;
664 names
->sAuthorityName
=
665 (PSTR
)SECUR32_AllocWideFromMultiByte(oldAuth
);
666 package
->provider
->fnTableW
.FreeContextBuffer(oldAuth
);
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
;
678 info
->sSignatureAlgorithmName
=
679 (PSTR
)SECUR32_AllocWideFromMultiByte(oldSigAlgName
);
680 package
->provider
->fnTableW
.FreeContextBuffer(
685 info
->sEncryptAlgorithmName
=
686 (PSTR
)SECUR32_AllocWideFromMultiByte(
688 package
->provider
->fnTableW
.FreeContextBuffer(
693 case SECPKG_ATTR_PACKAGE_INFO
:
695 PSecPkgContext_PackageInfoA info
=
696 (PSecPkgContext_PackageInfoA
)pBuffer
;
697 PSecPkgInfoA oldPkgInfo
= info
->PackageInfo
;
701 info
->PackageInfo
= (PSecPkgInfoA
)
702 _copyPackageInfoFlatAToW(oldPkgInfo
);
703 package
->provider
->fnTableW
.FreeContextBuffer(oldPkgInfo
);
707 case SECPKG_ATTR_NEGOTIATION_INFO
:
709 PSecPkgContext_NegotiationInfoA info
=
710 (PSecPkgContext_NegotiationInfoA
)pBuffer
;
711 PSecPkgInfoA oldPkgInfo
= info
->PackageInfo
;
715 info
->PackageInfo
= (PSecPkgInfoA
)
716 _copyPackageInfoFlatAToW(oldPkgInfo
);
717 package
->provider
->fnTableW
.FreeContextBuffer(oldPkgInfo
);
721 case SECPKG_ATTR_NATIVE_NAMES
:
723 PSecPkgContext_NativeNamesA names
=
724 (PSecPkgContext_NativeNamesA
)pBuffer
;
725 PSTR oldClient
= names
->sClientName
;
726 PSTR oldServer
= names
->sServerName
;
730 names
->sClientName
= (PSTR
)SECUR32_AllocWideFromMultiByte(
732 package
->provider
->fnTableW
.FreeContextBuffer(oldClient
);
736 names
->sServerName
= (PSTR
)SECUR32_AllocWideFromMultiByte(
738 package
->provider
->fnTableW
.FreeContextBuffer(oldServer
);
742 case SECPKG_ATTR_CREDENTIAL_NAME
:
744 PSecPkgContext_CredentialNameA name
=
745 (PSecPkgContext_CredentialNameA
)pBuffer
;
746 PSTR oldCred
= name
->sCredentialName
;
750 name
->sCredentialName
=
751 (PSTR
)SECUR32_AllocWideFromMultiByte(oldCred
);
752 package
->provider
->fnTableW
.FreeContextBuffer(oldCred
);
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
:
768 WARN("attribute type %ld unknown\n", ulAttribute
);
769 ret
= SEC_E_INTERNAL_ERROR
;
773 ret
= SEC_E_INVALID_TOKEN
;
777 SECURITY_STATUS SEC_ENTRY
thunk_QueryContextAttributesW(PCtxtHandle phContext
,
778 unsigned long ulAttribute
, void *pBuffer
)
782 TRACE("%p %ld %p\n", phContext
, ulAttribute
, pBuffer
);
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
);
795 ret
= thunk_ContextAttributesAToW(package
, ulAttribute
,
799 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
802 ret
= SEC_E_INVALID_HANDLE
;
805 ret
= SEC_E_INVALID_HANDLE
;
809 SECURITY_STATUS SEC_ENTRY
thunk_SetContextAttributesA(PCtxtHandle phContext
,
810 unsigned long ulAttribute
, void *pBuffer
, unsigned long cbBuffer
)
814 TRACE("%p %ld %p %ld\n", phContext
, ulAttribute
, pBuffer
, cbBuffer
);
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
,
828 ret
= package
->provider
->fnTableW
.SetContextAttributesW(
829 ctxt
, ulAttribute
, pBuffer
, cbBuffer
);
832 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
835 ret
= SEC_E_INVALID_HANDLE
;
838 ret
= SEC_E_INVALID_HANDLE
;
842 SECURITY_STATUS SEC_ENTRY
thunk_SetContextAttributesW(PCtxtHandle phContext
,
843 unsigned long ulAttribute
, void *pBuffer
, unsigned long cbBuffer
)
847 TRACE("%p %ld %p %ld\n", phContext
, ulAttribute
, pBuffer
, cbBuffer
);
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
,
861 ret
= package
->provider
->fnTableA
.SetContextAttributesA(
862 ctxt
, ulAttribute
, pBuffer
, cbBuffer
);
865 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
868 ret
= SEC_E_INVALID_HANDLE
;
871 ret
= SEC_E_INVALID_HANDLE
;
875 SECURITY_STATUS SEC_ENTRY
thunk_ImportSecurityContextA(
876 SEC_CHAR
*pszPackage
, PSecBuffer pPackedContext
, void *Token
,
877 PCtxtHandle phContext
)
880 UNICODE_STRING package
;
882 TRACE("%s %p %p %p\n", debugstr_a(pszPackage
), pPackedContext
, Token
,
884 RtlCreateUnicodeStringFromAsciiz(&package
, pszPackage
);
885 ret
= ImportSecurityContextW(package
.Buffer
, pPackedContext
, Token
,
887 RtlFreeUnicodeString(&package
);
891 SECURITY_STATUS SEC_ENTRY
thunk_ImportSecurityContextW(
892 SEC_WCHAR
*pszPackage
, PSecBuffer pPackedContext
, void *Token
,
893 PCtxtHandle phContext
)
896 PSTR package
= SECUR32_AllocMultiByteFromWide(pszPackage
);
898 TRACE("%s %p %p %p\n", debugstr_w(pszPackage
), pPackedContext
, Token
,
900 ret
= ImportSecurityContextA(package
, pPackedContext
, Token
, phContext
);
902 SECUR32_FREE(package
);