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
28 #include "wine/debug.h"
29 #include "secur32_priv.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 %d %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 static char *strdupWA( const WCHAR
*str
)
66 int len
= WideCharToMultiByte( CP_ACP
, 0, str
, -1, NULL
, 0, NULL
, NULL
);
67 if ((ret
= RtlAllocateHeap( GetProcessHeap(), 0, len
)))
68 WideCharToMultiByte( CP_ACP
, 0, str
, -1, ret
, len
, NULL
, NULL
);
73 SECURITY_STATUS SEC_ENTRY
thunk_AcquireCredentialsHandleW(
74 SEC_WCHAR
*pszPrincipal
, SEC_WCHAR
*pszPackage
, ULONG fCredentialsUse
,
75 PLUID pvLogonID
, PVOID pAuthData
, SEC_GET_KEY_FN pGetKeyFn
,
76 PVOID pvGetKeyArgument
, PCredHandle phCredential
, PTimeStamp ptsExpiry
)
80 TRACE("%s %s %d %p %p %p %p %p %p\n", debugstr_w(pszPrincipal
),
81 debugstr_w(pszPackage
), fCredentialsUse
, pvLogonID
, pAuthData
, pGetKeyFn
,
82 pvGetKeyArgument
, phCredential
, ptsExpiry
);
85 char *principal
, *package
;
87 principal
= strdupWA(pszPrincipal
);
88 package
= strdupWA(pszPackage
);
89 ret
= AcquireCredentialsHandleA(principal
, package
, fCredentialsUse
,
90 pvLogonID
, pAuthData
, pGetKeyFn
, pvGetKeyArgument
, phCredential
, ptsExpiry
);
91 RtlFreeHeap(GetProcessHeap(), 0, principal
);
92 RtlFreeHeap(GetProcessHeap(), 0, package
);
95 ret
= SEC_E_SECPKG_NOT_FOUND
;
99 /* thunking is pretty dicey for these--the output type depends on ulAttribute,
100 * so we have to know about every type the caller does
102 SECURITY_STATUS SEC_ENTRY
thunk_QueryCredentialsAttributesA(
103 PCredHandle phCredential
, ULONG ulAttribute
, void *pBuffer
)
107 TRACE("%p %d %p\n", phCredential
, ulAttribute
, pBuffer
);
110 SecurePackage
*package
= (SecurePackage
*)phCredential
->dwUpper
;
111 PCredHandle cred
= (PCredHandle
)phCredential
->dwLower
;
113 if (package
&& package
->provider
)
115 if (package
->provider
->fnTableW
.QueryCredentialsAttributesW
)
117 ret
= package
->provider
->fnTableW
.QueryCredentialsAttributesW( cred
, ulAttribute
, pBuffer
);
122 case SECPKG_CRED_ATTR_NAMES
:
124 PSecPkgCredentials_NamesW names
= (PSecPkgCredentials_NamesW
)pBuffer
;
125 SEC_WCHAR
*oldUser
= names
->sUserName
;
129 names
->sUserName
= (WCHAR
*)strdupWA(oldUser
);
130 package
->provider
->fnTableW
.FreeContextBuffer(oldUser
);
135 WARN("attribute type %d unknown\n", ulAttribute
);
136 ret
= SEC_E_INTERNAL_ERROR
;
141 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
144 ret
= SEC_E_INVALID_HANDLE
;
147 ret
= SEC_E_INVALID_HANDLE
;
151 static WCHAR
*strdupAW( const char *str
)
156 int len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
157 if ((ret
= RtlAllocateHeap( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
158 MultiByteToWideChar( CP_ACP
, 0, str
, -1, ret
, len
);
163 SECURITY_STATUS SEC_ENTRY
thunk_QueryCredentialsAttributesW(
164 PCredHandle phCredential
, ULONG ulAttribute
, void *pBuffer
)
168 TRACE("%p %d %p\n", phCredential
, ulAttribute
, pBuffer
);
171 SecurePackage
*package
= (SecurePackage
*)phCredential
->dwUpper
;
172 PCredHandle cred
= (PCredHandle
)phCredential
->dwLower
;
174 if (package
&& package
->provider
)
176 if (package
->provider
->fnTableA
.QueryCredentialsAttributesA
)
178 ret
= package
->provider
->fnTableA
.QueryCredentialsAttributesA(cred
, ulAttribute
, pBuffer
);
183 case SECPKG_CRED_ATTR_NAMES
:
185 PSecPkgCredentials_NamesA names
= (PSecPkgCredentials_NamesA
)pBuffer
;
186 SEC_CHAR
*oldUser
= names
->sUserName
;
190 names
->sUserName
= (char *)strdupAW(oldUser
);
191 package
->provider
->fnTableA
.FreeContextBuffer(oldUser
);
196 WARN("attribute type %d unknown\n", ulAttribute
);
197 ret
= SEC_E_INTERNAL_ERROR
;
202 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
205 ret
= SEC_E_INVALID_HANDLE
;
208 ret
= SEC_E_INVALID_HANDLE
;
212 SECURITY_STATUS SEC_ENTRY
thunk_InitializeSecurityContextA(
213 PCredHandle phCredential
, PCtxtHandle phContext
,
214 SEC_CHAR
*pszTargetName
, ULONG fContextReq
,
215 ULONG Reserved1
, ULONG TargetDataRep
, PSecBufferDesc pInput
,
216 ULONG Reserved2
, PCtxtHandle phNewContext
, PSecBufferDesc pOutput
,
217 ULONG
*pfContextAttr
, PTimeStamp ptsExpiry
)
221 TRACE("%p %p %s %d %d %d %p %d %p %p %p %p\n", phCredential
, phContext
,
222 debugstr_a(pszTargetName
), fContextReq
, Reserved1
, TargetDataRep
, pInput
,
223 Reserved1
, phNewContext
, pOutput
, pfContextAttr
, ptsExpiry
);
226 SecurePackage
*package
= (SecurePackage
*)phCredential
->dwUpper
;
228 if (package
&& package
->provider
)
230 if (package
->provider
->fnTableW
.InitializeSecurityContextW
)
232 UNICODE_STRING target
;
234 RtlCreateUnicodeStringFromAsciiz(&target
, pszTargetName
);
235 ret
= package
->provider
->fnTableW
.InitializeSecurityContextW(
236 phCredential
, phContext
, target
.Buffer
, fContextReq
, Reserved1
,
237 TargetDataRep
, pInput
, Reserved2
, phNewContext
, pOutput
,
238 pfContextAttr
, ptsExpiry
);
239 RtlFreeUnicodeString(&target
);
242 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
245 ret
= SEC_E_INVALID_HANDLE
;
248 ret
= SEC_E_INVALID_HANDLE
;
252 SECURITY_STATUS SEC_ENTRY
thunk_InitializeSecurityContextW(
253 PCredHandle phCredential
, PCtxtHandle phContext
,
254 SEC_WCHAR
*pszTargetName
, ULONG fContextReq
,
255 ULONG Reserved1
, ULONG TargetDataRep
, PSecBufferDesc pInput
,
256 ULONG Reserved2
, PCtxtHandle phNewContext
, PSecBufferDesc pOutput
,
257 ULONG
*pfContextAttr
, PTimeStamp ptsExpiry
)
261 TRACE("%p %p %s %d %d %d %p %d %p %p %p %p\n", phCredential
, phContext
,
262 debugstr_w(pszTargetName
), fContextReq
, Reserved1
, TargetDataRep
, pInput
,
263 Reserved1
, phNewContext
, pOutput
, pfContextAttr
, ptsExpiry
);
266 SecurePackage
*package
= (SecurePackage
*)phCredential
->dwUpper
;
268 if (package
&& package
->provider
)
270 if (package
->provider
->fnTableA
.InitializeSecurityContextA
)
272 char *target
= strdupWA(pszTargetName
);
274 ret
= package
->provider
->fnTableA
.InitializeSecurityContextA(
275 phCredential
, phContext
, target
, fContextReq
, Reserved1
,
276 TargetDataRep
, pInput
, Reserved2
, phNewContext
, pOutput
,
277 pfContextAttr
, ptsExpiry
);
278 RtlFreeHeap(GetProcessHeap(), 0, target
);
281 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
284 ret
= SEC_E_INVALID_HANDLE
;
287 ret
= SEC_E_INVALID_HANDLE
;
291 SECURITY_STATUS SEC_ENTRY
thunk_AddCredentialsA(PCredHandle hCredentials
,
292 SEC_CHAR
*pszPrincipal
, SEC_CHAR
*pszPackage
, ULONG fCredentialUse
,
293 void *pAuthData
, SEC_GET_KEY_FN pGetKeyFn
, void *pvGetKeyArgument
,
294 PTimeStamp ptsExpiry
)
298 TRACE("%p %s %s %d %p %p %p %p\n", hCredentials
, debugstr_a(pszPrincipal
),
299 debugstr_a(pszPackage
), fCredentialUse
, pAuthData
, pGetKeyFn
,
300 pvGetKeyArgument
, ptsExpiry
);
303 SecurePackage
*package
= (SecurePackage
*)hCredentials
->dwUpper
;
304 PCredHandle cred
= (PCtxtHandle
)hCredentials
->dwLower
;
306 if (package
&& package
->provider
)
308 if (package
->provider
->fnTableW
.AddCredentialsW
)
310 UNICODE_STRING szPrincipal
, szPackage
;
312 RtlCreateUnicodeStringFromAsciiz(&szPrincipal
, pszPrincipal
);
313 RtlCreateUnicodeStringFromAsciiz(&szPackage
, pszPackage
);
314 ret
= package
->provider
->fnTableW
.AddCredentialsW(
315 cred
, szPrincipal
.Buffer
, szPackage
.Buffer
, fCredentialUse
,
316 pAuthData
, pGetKeyFn
, pvGetKeyArgument
, ptsExpiry
);
317 RtlFreeUnicodeString(&szPrincipal
);
318 RtlFreeUnicodeString(&szPackage
);
321 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
324 ret
= SEC_E_INVALID_HANDLE
;
327 ret
= SEC_E_INVALID_HANDLE
;
331 SECURITY_STATUS SEC_ENTRY
thunk_AddCredentialsW(PCredHandle hCredentials
,
332 SEC_WCHAR
*pszPrincipal
, SEC_WCHAR
*pszPackage
, ULONG fCredentialUse
,
333 void *pAuthData
, SEC_GET_KEY_FN pGetKeyFn
, void *pvGetKeyArgument
,
334 PTimeStamp ptsExpiry
)
338 TRACE("%p %s %s %d %p %p %p %p\n", hCredentials
, debugstr_w(pszPrincipal
),
339 debugstr_w(pszPackage
), fCredentialUse
, pAuthData
, pGetKeyFn
,
340 pvGetKeyArgument
, ptsExpiry
);
343 SecurePackage
*package
= (SecurePackage
*)hCredentials
->dwUpper
;
344 PCredHandle cred
= (PCtxtHandle
)hCredentials
->dwLower
;
346 if (package
&& package
->provider
)
348 if (package
->provider
->fnTableA
.AddCredentialsA
)
350 char *szPrincipal
= strdupWA(pszPrincipal
);
351 char *szPackage
= strdupWA(pszPackage
);
353 ret
= package
->provider
->fnTableA
.AddCredentialsA(
354 cred
, szPrincipal
, szPackage
, fCredentialUse
, pAuthData
,
355 pGetKeyFn
, pvGetKeyArgument
, ptsExpiry
);
356 RtlFreeHeap(GetProcessHeap(), 0, szPrincipal
);
357 RtlFreeHeap(GetProcessHeap(), 0, szPackage
);
360 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
363 ret
= SEC_E_INVALID_HANDLE
;
366 ret
= SEC_E_INVALID_HANDLE
;
370 static PSecPkgInfoA
_copyPackageInfoFlatWToA(const SecPkgInfoW
*infoW
)
376 size_t bytesNeeded
= sizeof(SecPkgInfoA
);
377 int nameLen
= 0, commentLen
= 0;
381 nameLen
= WideCharToMultiByte(CP_ACP
, 0, infoW
->Name
, -1,
382 NULL
, 0, NULL
, NULL
);
383 bytesNeeded
+= nameLen
;
387 commentLen
= WideCharToMultiByte(CP_ACP
, 0, infoW
->Comment
, -1,
388 NULL
, 0, NULL
, NULL
);
389 bytesNeeded
+= commentLen
;
391 if ((ret
= RtlAllocateHeap(GetProcessHeap(), 0, bytesNeeded
)))
393 char *nextString
= (char *)ret
+ sizeof(SecPkgInfoA
);
395 memcpy(ret
, infoW
, sizeof(SecPkgInfoA
));
398 ret
->Name
= nextString
;
399 WideCharToMultiByte(CP_ACP
, 0, infoW
->Name
, -1, nextString
, nameLen
, NULL
, NULL
);
400 nextString
+= nameLen
;
406 ret
->Comment
= nextString
;
407 WideCharToMultiByte(CP_ACP
, 0, infoW
->Comment
, -1, nextString
, nameLen
, NULL
, NULL
);
418 static SECURITY_STATUS
thunk_ContextAttributesWToA(SecurePackage
*package
,
419 ULONG ulAttribute
, void *pBuffer
)
421 SECURITY_STATUS ret
= SEC_E_OK
;
423 if (package
&& pBuffer
)
427 case SECPKG_ATTR_NAMES
:
429 PSecPkgContext_NamesW names
= (PSecPkgContext_NamesW
)pBuffer
;
430 SEC_WCHAR
*oldUser
= names
->sUserName
;
434 names
->sUserName
= (WCHAR
*)strdupWA(oldUser
);
435 package
->provider
->fnTableW
.FreeContextBuffer(oldUser
);
439 case SECPKG_ATTR_AUTHORITY
:
441 PSecPkgContext_AuthorityW names
= (PSecPkgContext_AuthorityW
)pBuffer
;
442 SEC_WCHAR
*oldAuth
= names
->sAuthorityName
;
446 names
->sAuthorityName
= (WCHAR
*)strdupWA(oldAuth
);
447 package
->provider
->fnTableW
.FreeContextBuffer(oldAuth
);
451 case SECPKG_ATTR_KEY_INFO
:
453 PSecPkgContext_KeyInfoW info
= (PSecPkgContext_KeyInfoW
)pBuffer
;
454 SEC_WCHAR
*oldSigAlgName
= info
->sSignatureAlgorithmName
;
455 SEC_WCHAR
*oldEncAlgName
= info
->sEncryptAlgorithmName
;
459 info
->sSignatureAlgorithmName
= (WCHAR
*)strdupWA(oldSigAlgName
);
460 package
->provider
->fnTableW
.FreeContextBuffer(oldSigAlgName
);
464 info
->sEncryptAlgorithmName
= (WCHAR
*)strdupWA(oldEncAlgName
);
465 package
->provider
->fnTableW
.FreeContextBuffer(oldEncAlgName
);
469 case SECPKG_ATTR_PACKAGE_INFO
:
471 PSecPkgContext_PackageInfoW info
= (PSecPkgContext_PackageInfoW
)pBuffer
;
472 PSecPkgInfoW oldPkgInfo
= info
->PackageInfo
;
476 info
->PackageInfo
= (PSecPkgInfoW
)
477 _copyPackageInfoFlatWToA(oldPkgInfo
);
478 package
->provider
->fnTableW
.FreeContextBuffer(oldPkgInfo
);
482 case SECPKG_ATTR_NEGOTIATION_INFO
:
484 PSecPkgContext_NegotiationInfoW info
= (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
= (PSecPkgContext_NativeNamesW
)pBuffer
;
498 WCHAR
*oldClient
= names
->sClientName
;
499 WCHAR
*oldServer
= names
->sServerName
;
503 names
->sClientName
= (WCHAR
*)strdupWA(oldClient
);
504 package
->provider
->fnTableW
.FreeContextBuffer(oldClient
);
508 names
->sServerName
= (WCHAR
*)strdupWA(oldServer
);
509 package
->provider
->fnTableW
.FreeContextBuffer(oldServer
);
513 case SECPKG_ATTR_CREDENTIAL_NAME
:
515 PSecPkgContext_CredentialNameW name
= (PSecPkgContext_CredentialNameW
)pBuffer
;
516 WCHAR
*oldCred
= name
->sCredentialName
;
520 name
->sCredentialName
= (WCHAR
*)strdupWA(oldCred
);
521 package
->provider
->fnTableW
.FreeContextBuffer(oldCred
);
525 /* no thunking needed: */
526 case SECPKG_ATTR_ACCESS_TOKEN
:
527 case SECPKG_ATTR_DCE_INFO
:
528 case SECPKG_ATTR_FLAGS
:
529 case SECPKG_ATTR_LIFESPAN
:
530 case SECPKG_ATTR_PASSWORD_EXPIRY
:
531 case SECPKG_ATTR_SESSION_KEY
:
532 case SECPKG_ATTR_SIZES
:
533 case SECPKG_ATTR_STREAM_SIZES
:
534 case SECPKG_ATTR_TARGET_INFORMATION
:
537 WARN("attribute type %d unknown\n", ulAttribute
);
538 ret
= SEC_E_INTERNAL_ERROR
;
542 ret
= SEC_E_INVALID_TOKEN
;
546 SECURITY_STATUS SEC_ENTRY
thunk_QueryContextAttributesA(PCtxtHandle phContext
,
547 ULONG ulAttribute
, void *pBuffer
)
551 TRACE("%p %d %p\n", phContext
, ulAttribute
, pBuffer
);
554 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
555 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
557 if (package
&& package
->provider
)
559 if (package
->provider
->fnTableW
.QueryContextAttributesW
)
561 ret
= package
->provider
->fnTableW
.QueryContextAttributesW( ctxt
, ulAttribute
, pBuffer
);
563 ret
= thunk_ContextAttributesWToA(package
, ulAttribute
, pBuffer
);
566 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
569 ret
= SEC_E_INVALID_HANDLE
;
572 ret
= SEC_E_INVALID_HANDLE
;
576 static PSecPkgInfoW
_copyPackageInfoFlatAToW(const SecPkgInfoA
*infoA
)
582 size_t bytesNeeded
= sizeof(SecPkgInfoW
);
583 int nameLen
= 0, commentLen
= 0;
587 nameLen
= MultiByteToWideChar(CP_ACP
, 0, infoA
->Name
, -1, NULL
, 0);
588 bytesNeeded
+= nameLen
* sizeof(WCHAR
);
592 commentLen
= MultiByteToWideChar(CP_ACP
, 0, infoA
->Comment
, -1, NULL
, 0);
593 bytesNeeded
+= commentLen
* sizeof(WCHAR
);
595 if ((ret
= RtlAllocateHeap(GetProcessHeap(), 0, bytesNeeded
)))
597 WCHAR
*nextString
= (WCHAR
*)(char *)ret
+ sizeof(SecPkgInfoW
);
599 memcpy(ret
, infoA
, sizeof(SecPkgInfoA
));
602 ret
->Name
= nextString
;
603 MultiByteToWideChar(CP_ACP
, 0, infoA
->Name
, -1, nextString
, nameLen
);
604 nextString
+= nameLen
;
610 ret
->Comment
= nextString
;
611 MultiByteToWideChar(CP_ACP
, 0, infoA
->Comment
, -1, nextString
, commentLen
);
622 static SECURITY_STATUS
thunk_ContextAttributesAToW(SecurePackage
*package
,
623 ULONG ulAttribute
, void *pBuffer
)
625 SECURITY_STATUS ret
= SEC_E_OK
;
627 if (package
&& pBuffer
)
631 case SECPKG_ATTR_NAMES
:
633 PSecPkgContext_NamesA names
= (PSecPkgContext_NamesA
)pBuffer
;
634 SEC_CHAR
*oldUser
= names
->sUserName
;
638 names
->sUserName
= (char *)strdupAW(oldUser
);
639 package
->provider
->fnTableW
.FreeContextBuffer(oldUser
);
643 case SECPKG_ATTR_AUTHORITY
:
645 PSecPkgContext_AuthorityA names
= (PSecPkgContext_AuthorityA
)pBuffer
;
646 SEC_CHAR
*oldAuth
= names
->sAuthorityName
;
650 names
->sAuthorityName
= (char *)strdupAW(oldAuth
);
651 package
->provider
->fnTableW
.FreeContextBuffer(oldAuth
);
655 case SECPKG_ATTR_KEY_INFO
:
657 PSecPkgContext_KeyInfoA info
= (PSecPkgContext_KeyInfoA
)pBuffer
;
658 SEC_CHAR
*oldSigAlgName
= info
->sSignatureAlgorithmName
;
659 SEC_CHAR
*oldEncAlgName
= info
->sEncryptAlgorithmName
;
663 info
->sSignatureAlgorithmName
= (char *)strdupAW(oldSigAlgName
);
664 package
->provider
->fnTableW
.FreeContextBuffer(oldSigAlgName
);
668 info
->sEncryptAlgorithmName
= (char *)strdupAW(oldEncAlgName
);
669 package
->provider
->fnTableW
.FreeContextBuffer(oldEncAlgName
);
673 case SECPKG_ATTR_PACKAGE_INFO
:
675 PSecPkgContext_PackageInfoA info
= (PSecPkgContext_PackageInfoA
)pBuffer
;
676 PSecPkgInfoA oldPkgInfo
= info
->PackageInfo
;
680 info
->PackageInfo
= (PSecPkgInfoA
)
681 _copyPackageInfoFlatAToW(oldPkgInfo
);
682 package
->provider
->fnTableW
.FreeContextBuffer(oldPkgInfo
);
686 case SECPKG_ATTR_NEGOTIATION_INFO
:
688 PSecPkgContext_NegotiationInfoA info
= (PSecPkgContext_NegotiationInfoA
)pBuffer
;
689 PSecPkgInfoA oldPkgInfo
= info
->PackageInfo
;
693 info
->PackageInfo
= (PSecPkgInfoA
)
694 _copyPackageInfoFlatAToW(oldPkgInfo
);
695 package
->provider
->fnTableW
.FreeContextBuffer(oldPkgInfo
);
699 case SECPKG_ATTR_NATIVE_NAMES
:
701 PSecPkgContext_NativeNamesA names
= (PSecPkgContext_NativeNamesA
)pBuffer
;
702 char *oldClient
= names
->sClientName
;
703 char *oldServer
= names
->sServerName
;
707 names
->sClientName
= (char *)strdupAW(oldClient
);
708 package
->provider
->fnTableW
.FreeContextBuffer(oldClient
);
712 names
->sServerName
= (char *)strdupAW(oldServer
);
713 package
->provider
->fnTableW
.FreeContextBuffer(oldServer
);
717 case SECPKG_ATTR_CREDENTIAL_NAME
:
719 PSecPkgContext_CredentialNameA name
= (PSecPkgContext_CredentialNameA
)pBuffer
;
720 char *oldCred
= name
->sCredentialName
;
724 name
->sCredentialName
= (char *)strdupAW(oldCred
);
725 package
->provider
->fnTableW
.FreeContextBuffer(oldCred
);
729 /* no thunking needed: */
730 case SECPKG_ATTR_ACCESS_TOKEN
:
731 case SECPKG_ATTR_DCE_INFO
:
732 case SECPKG_ATTR_FLAGS
:
733 case SECPKG_ATTR_LIFESPAN
:
734 case SECPKG_ATTR_PASSWORD_EXPIRY
:
735 case SECPKG_ATTR_SESSION_KEY
:
736 case SECPKG_ATTR_SIZES
:
737 case SECPKG_ATTR_STREAM_SIZES
:
738 case SECPKG_ATTR_TARGET_INFORMATION
:
741 WARN("attribute type %d unknown\n", ulAttribute
);
742 ret
= SEC_E_INTERNAL_ERROR
;
746 ret
= SEC_E_INVALID_TOKEN
;
750 SECURITY_STATUS SEC_ENTRY
thunk_QueryContextAttributesW(PCtxtHandle phContext
,
751 ULONG ulAttribute
, void *pBuffer
)
755 TRACE("%p %d %p\n", phContext
, ulAttribute
, pBuffer
);
758 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
759 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
761 if (package
&& package
->provider
)
763 if (package
->provider
->fnTableA
.QueryContextAttributesA
)
765 ret
= package
->provider
->fnTableA
.QueryContextAttributesA(ctxt
, ulAttribute
, pBuffer
);
767 ret
= thunk_ContextAttributesAToW(package
, ulAttribute
, pBuffer
);
770 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
773 ret
= SEC_E_INVALID_HANDLE
;
776 ret
= SEC_E_INVALID_HANDLE
;
780 SECURITY_STATUS SEC_ENTRY
thunk_SetContextAttributesA(PCtxtHandle phContext
,
781 ULONG ulAttribute
, void *pBuffer
, ULONG cbBuffer
)
785 TRACE("%p %d %p %d\n", phContext
, ulAttribute
, pBuffer
, cbBuffer
);
788 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
789 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
791 if (package
&& package
->provider
&& pBuffer
&& cbBuffer
)
793 if (package
->provider
->fnTableW
.SetContextAttributesW
)
795 /* TODO: gotta validate size too! */
796 ret
= thunk_ContextAttributesWToA(package
, ulAttribute
, pBuffer
);
798 ret
= package
->provider
->fnTableW
.SetContextAttributesW(ctxt
, ulAttribute
, pBuffer
, cbBuffer
);
801 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
804 ret
= SEC_E_INVALID_HANDLE
;
807 ret
= SEC_E_INVALID_HANDLE
;
811 SECURITY_STATUS SEC_ENTRY
thunk_SetContextAttributesW(PCtxtHandle phContext
,
812 ULONG ulAttribute
, void *pBuffer
, ULONG cbBuffer
)
816 TRACE("%p %d %p %d\n", phContext
, ulAttribute
, pBuffer
, cbBuffer
);
819 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
820 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
822 if (package
&& package
->provider
&& pBuffer
&& cbBuffer
)
824 if (package
->provider
->fnTableA
.SetContextAttributesA
)
826 /* TODO: gotta validate size too! */
827 ret
= thunk_ContextAttributesAToW(package
, ulAttribute
, pBuffer
);
829 ret
= package
->provider
->fnTableA
.SetContextAttributesA(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_ImportSecurityContextA(
843 SEC_CHAR
*pszPackage
, PSecBuffer pPackedContext
, void *Token
,
844 PCtxtHandle phContext
)
847 UNICODE_STRING package
;
849 TRACE("%s %p %p %p\n", debugstr_a(pszPackage
), pPackedContext
, Token
, phContext
);
850 RtlCreateUnicodeStringFromAsciiz(&package
, pszPackage
);
851 ret
= ImportSecurityContextW(package
.Buffer
, pPackedContext
, Token
, phContext
);
852 RtlFreeUnicodeString(&package
);
856 SECURITY_STATUS SEC_ENTRY
thunk_ImportSecurityContextW(
857 SEC_WCHAR
*pszPackage
, PSecBuffer pPackedContext
, void *Token
,
858 PCtxtHandle phContext
)
861 char *package
= strdupWA(pszPackage
);
863 TRACE("%s %p %p %p\n", debugstr_w(pszPackage
), pPackedContext
, Token
, phContext
);
864 ret
= ImportSecurityContextA(package
, pPackedContext
, Token
, phContext
);
865 RtlFreeHeap(GetProcessHeap(), 0, package
);