1 /* Copyright (C) 2004 Juan Lang
3 * Implements secur32 functions that forward to (wrap) an SSP's implementation.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "secur32_priv.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(secur32
);
30 /* Tries to allocate a new SecHandle, into which it stores package (in
31 * phSec->dwUpper) and a copy of realHandle (allocated with SECUR32_ALLOC,
32 * and stored in phSec->dwLower). SecHandle is equivalent to both a
33 * CredHandle and a CtxtHandle.
35 static SECURITY_STATUS
SECUR32_makeSecHandle(PSecHandle phSec
,
36 SecurePackage
*package
, PSecHandle realHandle
)
40 if (phSec
&& package
&& realHandle
)
42 PSecHandle newSec
= (PSecHandle
)SECUR32_ALLOC(sizeof(SecHandle
));
46 memcpy(newSec
, realHandle
, sizeof(*realHandle
));
47 phSec
->dwUpper
= (ULONG_PTR
)package
;
48 phSec
->dwLower
= (ULONG_PTR
)newSec
;
52 ret
= SEC_E_INSUFFICIENT_MEMORY
;
55 ret
= SEC_E_INVALID_HANDLE
;
59 /***********************************************************************
60 * AcquireCredentialsHandleA (SECUR32.@)
62 SECURITY_STATUS WINAPI
AcquireCredentialsHandleA(
63 SEC_CHAR
*pszPrincipal
, SEC_CHAR
*pszPackage
, ULONG fCredentialsUse
,
64 PLUID pvLogonID
, PVOID pAuthData
, SEC_GET_KEY_FN pGetKeyFn
,
65 PVOID pvGetKeyArgument
, PCredHandle phCredential
, PTimeStamp ptsExpiry
)
69 TRACE("%s %s %ld %p %p %p %p %p %p\n", debugstr_a(pszPrincipal
),
70 debugstr_a(pszPackage
), fCredentialsUse
, pvLogonID
, pAuthData
, pGetKeyFn
,
71 pvGetKeyArgument
, phCredential
, ptsExpiry
);
74 SecurePackage
*package
= SECUR32_findPackageA(pszPackage
);
76 if (package
&& package
->provider
)
78 if (package
->provider
->fnTableA
.AcquireCredentialsHandleA
)
82 ret
= package
->provider
->fnTableA
.AcquireCredentialsHandleA(
83 pszPrincipal
, pszPackage
, fCredentialsUse
, pvLogonID
,
84 pAuthData
, pGetKeyFn
, pvGetKeyArgument
, &myCred
,
88 ret
= SECUR32_makeSecHandle(phCredential
, package
, &myCred
);
90 package
->provider
->fnTableW
.FreeCredentialsHandle(
95 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
98 ret
= SEC_E_SECPKG_NOT_FOUND
;
101 ret
= SEC_E_SECPKG_NOT_FOUND
;
105 /***********************************************************************
106 * AcquireCredentialsHandleW (SECUR32.@)
108 SECURITY_STATUS WINAPI
AcquireCredentialsHandleW(
109 SEC_WCHAR
*pszPrincipal
, SEC_WCHAR
*pszPackage
, ULONG fCredentialsUse
,
110 PLUID pvLogonID
, PVOID pAuthData
, SEC_GET_KEY_FN pGetKeyFn
,
111 PVOID pvGetKeyArgument
, PCredHandle phCredential
, PTimeStamp ptsExpiry
)
115 TRACE("%s %s %ld %p %p %p %p %p %p\n", debugstr_w(pszPrincipal
),
116 debugstr_w(pszPackage
), fCredentialsUse
, pvLogonID
, pAuthData
, pGetKeyFn
,
117 pvGetKeyArgument
, phCredential
, ptsExpiry
);
120 SecurePackage
*package
= SECUR32_findPackageW(pszPackage
);
122 if (package
&& package
->provider
)
124 if (package
->provider
->fnTableW
.AcquireCredentialsHandleW
)
128 ret
= package
->provider
->fnTableW
.AcquireCredentialsHandleW(
129 pszPrincipal
, pszPackage
, fCredentialsUse
, pvLogonID
,
130 pAuthData
, pGetKeyFn
, pvGetKeyArgument
, &myCred
,
134 ret
= SECUR32_makeSecHandle(phCredential
, package
, &myCred
);
136 package
->provider
->fnTableW
.FreeCredentialsHandle(
141 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
144 ret
= SEC_E_SECPKG_NOT_FOUND
;
147 ret
= SEC_E_SECPKG_NOT_FOUND
;
151 /***********************************************************************
152 * FreeCredentialsHandle (SECUR32.@)
154 SECURITY_STATUS WINAPI
FreeCredentialsHandle(
155 PCredHandle phCredential
)
159 TRACE("%p\n", phCredential
);
162 SecurePackage
*package
= (SecurePackage
*)phCredential
->dwUpper
;
163 PCredHandle cred
= (PCredHandle
)phCredential
->dwLower
;
165 if (package
&& package
->provider
&&
166 package
->provider
->fnTableW
.FreeCredentialsHandle
)
167 ret
= package
->provider
->fnTableW
.FreeCredentialsHandle(cred
);
169 ret
= SEC_E_INVALID_HANDLE
;
173 ret
= SEC_E_INVALID_HANDLE
;
177 /***********************************************************************
178 * QueryCredentialsAttributesA (SECUR32.@)
180 SECURITY_STATUS WINAPI
QueryCredentialsAttributesA(
181 PCredHandle phCredential
, unsigned long ulAttribute
, void *pBuffer
)
185 TRACE("%p %ld %p\n", phCredential
, ulAttribute
, pBuffer
);
188 SecurePackage
*package
= (SecurePackage
*)phCredential
->dwUpper
;
189 PCredHandle cred
= (PCredHandle
)phCredential
->dwLower
;
191 if (package
&& package
->provider
)
193 if (package
->provider
->fnTableA
.QueryCredentialsAttributesA
)
194 ret
= package
->provider
->fnTableA
.QueryCredentialsAttributesA(
195 cred
, ulAttribute
, pBuffer
);
197 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
200 ret
= SEC_E_INVALID_HANDLE
;
203 ret
= SEC_E_INVALID_HANDLE
;
207 /***********************************************************************
208 * QueryCredentialsAttributesW (SECUR32.@)
210 SECURITY_STATUS WINAPI
QueryCredentialsAttributesW(
211 PCredHandle phCredential
, unsigned long ulAttribute
, void *pBuffer
)
215 TRACE("%p %ld %p\n", phCredential
, ulAttribute
, pBuffer
);
218 SecurePackage
*package
= (SecurePackage
*)phCredential
->dwUpper
;
219 PCredHandle cred
= (PCredHandle
)phCredential
->dwLower
;
221 if (package
&& package
->provider
)
223 if (package
->provider
->fnTableW
.QueryCredentialsAttributesW
)
224 ret
= package
->provider
->fnTableW
.QueryCredentialsAttributesW(
225 cred
, ulAttribute
, pBuffer
);
227 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
230 ret
= SEC_E_INVALID_HANDLE
;
233 ret
= SEC_E_INVALID_HANDLE
;
237 /***********************************************************************
238 * InitializeSecurityContextA (SECUR32.@)
240 SECURITY_STATUS WINAPI
InitializeSecurityContextA(
241 PCredHandle phCredential
, PCtxtHandle phContext
,
242 SEC_CHAR
*pszTargetName
, unsigned long fContextReq
,
243 unsigned long Reserved1
, unsigned long TargetDataRep
, PSecBufferDesc pInput
,
244 unsigned long Reserved2
, PCtxtHandle phNewContext
, PSecBufferDesc pOutput
,
245 unsigned long *pfContextAttr
, PTimeStamp ptsExpiry
)
249 TRACE("%p %p %s %ld %ld %ld %p %ld %p %p %p %p\n", phCredential
, phContext
,
250 debugstr_a(pszTargetName
), fContextReq
, Reserved1
, TargetDataRep
, pInput
,
251 Reserved1
, phNewContext
, pOutput
, pfContextAttr
, ptsExpiry
);
254 SecurePackage
*package
= (SecurePackage
*)phCredential
->dwUpper
;
255 PCredHandle cred
= (PCredHandle
)phCredential
->dwLower
;
257 if (package
&& package
->provider
)
259 if (package
->provider
->fnTableA
.InitializeSecurityContextA
)
263 ret
= package
->provider
->fnTableA
.InitializeSecurityContextA(
264 cred
, phContext
? &myCtxt
: NULL
, pszTargetName
, fContextReq
,
265 Reserved1
, TargetDataRep
, pInput
, Reserved2
, &myCtxt
,
266 pOutput
, pfContextAttr
, ptsExpiry
);
269 ret
= SECUR32_makeSecHandle(phContext
, package
, &myCtxt
);
271 package
->provider
->fnTableW
.DeleteSecurityContext(
276 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
279 ret
= SEC_E_INVALID_HANDLE
;
282 ret
= SEC_E_INVALID_HANDLE
;
286 /***********************************************************************
287 * InitializeSecurityContextW (SECUR32.@)
289 SECURITY_STATUS WINAPI
InitializeSecurityContextW(
290 PCredHandle phCredential
, PCtxtHandle phContext
,
291 SEC_WCHAR
*pszTargetName
, unsigned long fContextReq
,
292 unsigned long Reserved1
, unsigned long TargetDataRep
, PSecBufferDesc pInput
,
293 unsigned long Reserved2
, PCtxtHandle phNewContext
, PSecBufferDesc pOutput
,
294 unsigned long *pfContextAttr
, PTimeStamp ptsExpiry
)
298 TRACE("%p %p %s %ld %ld %ld %p %ld %p %p %p %p\n", phCredential
, phContext
,
299 debugstr_w(pszTargetName
), fContextReq
, Reserved1
, TargetDataRep
, pInput
,
300 Reserved1
, phNewContext
, pOutput
, pfContextAttr
, ptsExpiry
);
303 SecurePackage
*package
= (SecurePackage
*)phCredential
->dwUpper
;
304 PCredHandle cred
= (PCredHandle
)phCredential
->dwLower
;
306 if (package
&& package
->provider
)
308 if (package
->provider
->fnTableW
.QueryCredentialsAttributesW
)
312 ret
= package
->provider
->fnTableW
.InitializeSecurityContextW(
313 cred
, phContext
? &myCtxt
: NULL
, pszTargetName
, fContextReq
,
314 Reserved1
, TargetDataRep
, pInput
, Reserved2
, &myCtxt
,
315 pOutput
, pfContextAttr
, ptsExpiry
);
318 ret
= SECUR32_makeSecHandle(phContext
, package
, &myCtxt
);
320 package
->provider
->fnTableW
.DeleteSecurityContext(
325 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
328 ret
= SEC_E_INVALID_HANDLE
;
331 ret
= SEC_E_INVALID_HANDLE
;
335 /***********************************************************************
336 * AcceptSecurityContext (SECUR32.@)
338 SECURITY_STATUS WINAPI
AcceptSecurityContext(
339 PCredHandle phCredential
, PCtxtHandle phContext
, PSecBufferDesc pInput
,
340 unsigned long fContextReq
, unsigned long TargetDataRep
,
341 PCtxtHandle phNewContext
, PSecBufferDesc pOutput
,
342 unsigned long *pfContextAttr
, PTimeStamp ptsExpiry
)
346 TRACE("%p %p %p %ld %ld %p %p %p %p\n", phCredential
, phContext
, pInput
,
347 fContextReq
, TargetDataRep
, phNewContext
, pOutput
, pfContextAttr
,
351 SecurePackage
*package
= (SecurePackage
*)phCredential
->dwUpper
;
352 PCredHandle cred
= (PCredHandle
)phCredential
->dwLower
;
354 if (package
&& package
->provider
)
356 if (package
->provider
->fnTableW
.AcceptSecurityContext
)
360 ret
= package
->provider
->fnTableW
.AcceptSecurityContext(
361 cred
, phContext
? &myCtxt
: NULL
, pInput
, fContextReq
,
362 TargetDataRep
, &myCtxt
, pOutput
, pfContextAttr
, ptsExpiry
);
365 ret
= SECUR32_makeSecHandle(phContext
, package
, &myCtxt
);
367 package
->provider
->fnTableW
.DeleteSecurityContext(
372 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
375 ret
= SEC_E_INVALID_HANDLE
;
378 ret
= SEC_E_INVALID_HANDLE
;
382 /***********************************************************************
383 * CompleteAuthToken (SECUR32.@)
385 SECURITY_STATUS WINAPI
CompleteAuthToken(PCtxtHandle phContext
,
386 PSecBufferDesc pToken
)
390 TRACE("%p %p\n", phContext
, pToken
);
393 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
394 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
396 if (package
&& package
->provider
)
398 if (package
->provider
->fnTableW
.CompleteAuthToken
)
399 ret
= package
->provider
->fnTableW
.CompleteAuthToken(ctxt
,
402 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
405 ret
= SEC_E_INVALID_HANDLE
;
408 ret
= SEC_E_INVALID_HANDLE
;
412 /***********************************************************************
413 * DeleteSecurityContext (SECUR32.@)
415 SECURITY_STATUS WINAPI
DeleteSecurityContext(PCtxtHandle phContext
)
419 TRACE("%p\n", phContext
);
422 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
423 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
425 if (package
&& package
->provider
&&
426 package
->provider
->fnTableW
.DeleteSecurityContext
)
427 ret
= package
->provider
->fnTableW
.DeleteSecurityContext(ctxt
);
429 ret
= SEC_E_INVALID_HANDLE
;
433 ret
= SEC_E_INVALID_HANDLE
;
437 /***********************************************************************
438 * ApplyControlToken (SECUR32.@)
440 SECURITY_STATUS WINAPI
ApplyControlToken(PCtxtHandle phContext
,
441 PSecBufferDesc pInput
)
445 TRACE("%p %p\n", phContext
, pInput
);
448 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
449 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
451 if (package
&& package
->provider
)
453 if (package
->provider
->fnTableW
.ApplyControlToken
)
454 ret
= package
->provider
->fnTableW
.ApplyControlToken(
457 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
460 ret
= SEC_E_INVALID_HANDLE
;
463 ret
= SEC_E_INVALID_HANDLE
;
467 /***********************************************************************
468 * QueryContextAttributesA (SECUR32.@)
470 SECURITY_STATUS WINAPI
QueryContextAttributesA(PCtxtHandle phContext
,
471 unsigned long ulAttribute
, void *pBuffer
)
475 TRACE("%p %ld %p\n", phContext
, ulAttribute
, pBuffer
);
478 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
479 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
481 if (package
&& package
->provider
)
483 if (package
->provider
->fnTableA
.QueryContextAttributesA
)
484 ret
= package
->provider
->fnTableA
.QueryContextAttributesA(
485 ctxt
, ulAttribute
, pBuffer
);
487 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
490 ret
= SEC_E_INVALID_HANDLE
;
493 ret
= SEC_E_INVALID_HANDLE
;
497 /***********************************************************************
498 * QueryContextAttributesW (SECUR32.@)
500 SECURITY_STATUS WINAPI
QueryContextAttributesW(PCtxtHandle phContext
,
501 unsigned long ulAttribute
, void *pBuffer
)
505 TRACE("%p %ld %p\n", phContext
, ulAttribute
, pBuffer
);
508 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
509 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
511 if (package
&& package
->provider
)
513 if (package
->provider
->fnTableW
.QueryContextAttributesW
)
514 ret
= package
->provider
->fnTableW
.QueryContextAttributesW(
515 ctxt
, ulAttribute
, pBuffer
);
517 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
520 ret
= SEC_E_INVALID_HANDLE
;
523 ret
= SEC_E_INVALID_HANDLE
;
527 /***********************************************************************
528 * ImpersonateSecurityContext (SECUR32.@)
530 SECURITY_STATUS WINAPI
ImpersonateSecurityContext(PCtxtHandle phContext
)
534 TRACE("%p\n", phContext
);
537 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
538 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
540 if (package
&& package
->provider
)
542 if (package
->provider
->fnTableW
.ImpersonateSecurityContext
)
543 ret
= package
->provider
->fnTableW
.ImpersonateSecurityContext(
546 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
549 ret
= SEC_E_INVALID_HANDLE
;
552 ret
= SEC_E_INVALID_HANDLE
;
556 /***********************************************************************
557 * RevertSecurityContext (SECUR32.@)
559 SECURITY_STATUS WINAPI
RevertSecurityContext(PCtxtHandle phContext
)
563 TRACE("%p\n", phContext
);
566 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
567 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
569 if (package
&& package
->provider
)
571 if (package
->provider
->fnTableW
.RevertSecurityContext
)
572 ret
= package
->provider
->fnTableW
.RevertSecurityContext(
575 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
578 ret
= SEC_E_INVALID_HANDLE
;
581 ret
= SEC_E_INVALID_HANDLE
;
585 /***********************************************************************
586 * MakeSignature (SECUR32.@)
588 SECURITY_STATUS WINAPI
MakeSignature(PCtxtHandle phContext
, ULONG fQOP
,
589 PSecBufferDesc pMessage
, ULONG MessageSeqNo
)
593 TRACE("%p %ld %p %ld\n", phContext
, fQOP
, pMessage
, MessageSeqNo
);
596 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
597 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
599 if (package
&& package
->provider
)
601 if (package
->provider
->fnTableW
.MakeSignature
)
602 ret
= package
->provider
->fnTableW
.MakeSignature(
603 ctxt
, fQOP
, pMessage
, MessageSeqNo
);
605 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
608 ret
= SEC_E_INVALID_HANDLE
;
611 ret
= SEC_E_INVALID_HANDLE
;
615 /***********************************************************************
616 * VerifySignature (SECUR32.@)
618 SECURITY_STATUS WINAPI
VerifySignature(PCtxtHandle phContext
,
619 PSecBufferDesc pMessage
, ULONG MessageSeqNo
, PULONG pfQOP
)
623 TRACE("%p %p %ld %p\n", phContext
, pMessage
, MessageSeqNo
, pfQOP
);
626 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
627 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
629 if (package
&& package
->provider
)
631 if (package
->provider
->fnTableW
.VerifySignature
)
632 ret
= package
->provider
->fnTableW
.VerifySignature(
633 ctxt
, pMessage
, MessageSeqNo
, pfQOP
);
635 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
638 ret
= SEC_E_INVALID_HANDLE
;
641 ret
= SEC_E_INVALID_HANDLE
;
645 /***********************************************************************
646 * QuerySecurityPackageInfoA (SECUR32.@)
648 SECURITY_STATUS WINAPI
QuerySecurityPackageInfoA(SEC_CHAR
*pszPackageName
,
649 PSecPkgInfoA
*ppPackageInfo
)
653 TRACE("%s %p\n", debugstr_a(pszPackageName
), ppPackageInfo
);
656 SecurePackage
*package
= SECUR32_findPackageA(pszPackageName
);
660 size_t bytesNeeded
= sizeof(SecPkgInfoA
);
661 int nameLen
= 0, commentLen
= 0;
663 if (package
->infoW
.Name
)
665 nameLen
= WideCharToMultiByte(CP_ACP
, 0,
666 package
->infoW
.Name
, -1, NULL
, 0, NULL
, NULL
);
667 bytesNeeded
+= nameLen
;
669 if (package
->infoW
.Comment
)
671 commentLen
= WideCharToMultiByte(CP_ACP
, 0,
672 package
->infoW
.Comment
, -1, NULL
, 0, NULL
, NULL
);
673 bytesNeeded
+= commentLen
;
675 *ppPackageInfo
= (PSecPkgInfoA
)SECUR32_ALLOC(bytesNeeded
);
678 PSTR nextString
= (PSTR
)((PBYTE
)*ppPackageInfo
+
679 sizeof(SecPkgInfoA
));
681 memcpy(*ppPackageInfo
, &package
->infoW
, sizeof(package
->infoW
));
682 if (package
->infoW
.Name
)
684 (*ppPackageInfo
)->Name
= nextString
;
685 nextString
+= WideCharToMultiByte(CP_ACP
, 0,
686 package
->infoW
.Name
, -1, nextString
, nameLen
, NULL
, NULL
);
689 (*ppPackageInfo
)->Name
= NULL
;
690 if (package
->infoW
.Comment
)
692 (*ppPackageInfo
)->Comment
= nextString
;
693 nextString
+= WideCharToMultiByte(CP_ACP
, 0,
694 package
->infoW
.Comment
, -1, nextString
, commentLen
, NULL
,
698 (*ppPackageInfo
)->Comment
= NULL
;
702 ret
= SEC_E_INSUFFICIENT_MEMORY
;
705 ret
= SEC_E_SECPKG_NOT_FOUND
;
708 ret
= SEC_E_SECPKG_NOT_FOUND
;
712 /***********************************************************************
713 * QuerySecurityPackageInfoW (SECUR32.@)
715 SECURITY_STATUS WINAPI
QuerySecurityPackageInfoW(SEC_WCHAR
*pszPackageName
,
716 PSecPkgInfoW
*ppPackageInfo
)
719 SecurePackage
*package
= SECUR32_findPackageW(pszPackageName
);
721 TRACE("%s %p\n", debugstr_w(pszPackageName
), ppPackageInfo
);
724 size_t bytesNeeded
= sizeof(SecPkgInfoW
);
725 int nameLen
= 0, commentLen
= 0;
727 if (package
->infoW
.Name
)
729 nameLen
= lstrlenW(package
->infoW
.Name
) + 1;
730 bytesNeeded
+= nameLen
* sizeof(WCHAR
);
732 if (package
->infoW
.Comment
)
734 commentLen
= lstrlenW(package
->infoW
.Comment
) + 1;
735 bytesNeeded
+= commentLen
* sizeof(WCHAR
);
737 *ppPackageInfo
= (PSecPkgInfoW
)SECUR32_ALLOC(bytesNeeded
);
740 PWSTR nextString
= (PWSTR
)((PBYTE
)*ppPackageInfo
+
741 sizeof(SecPkgInfoW
));
743 memcpy(*ppPackageInfo
, &package
->infoW
, sizeof(package
->infoW
));
744 if (package
->infoW
.Name
)
746 (*ppPackageInfo
)->Name
= nextString
;
747 lstrcpynW(nextString
, package
->infoW
.Name
, nameLen
);
748 nextString
+= nameLen
;
751 (*ppPackageInfo
)->Name
= NULL
;
752 if (package
->infoW
.Comment
)
754 (*ppPackageInfo
)->Comment
= nextString
;
755 lstrcpynW(nextString
, package
->infoW
.Comment
, commentLen
);
756 nextString
+= commentLen
;
759 (*ppPackageInfo
)->Comment
= NULL
;
763 ret
= SEC_E_INSUFFICIENT_MEMORY
;
766 ret
= SEC_E_SECPKG_NOT_FOUND
;
770 /***********************************************************************
771 * ExportSecurityContext (SECUR32.@)
773 SECURITY_STATUS WINAPI
ExportSecurityContext(PCtxtHandle phContext
,
774 ULONG fFlags
, PSecBuffer pPackedContext
, void **pToken
)
778 TRACE("%p %ld %p %p\n", phContext
, fFlags
, pPackedContext
, pToken
);
781 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
782 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
784 if (package
&& package
->provider
)
786 if (package
->provider
->fnTableW
.ExportSecurityContext
)
787 ret
= package
->provider
->fnTableW
.ExportSecurityContext(
788 ctxt
, fFlags
, pPackedContext
, pToken
);
790 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
793 ret
= SEC_E_INVALID_HANDLE
;
796 ret
= SEC_E_INVALID_HANDLE
;
800 /***********************************************************************
801 * ImportSecurityContextA (SECUR32.@)
803 SECURITY_STATUS WINAPI
ImportSecurityContextA(SEC_CHAR
*pszPackage
,
804 PSecBuffer pPackedContext
, void *Token
, PCtxtHandle phContext
)
807 SecurePackage
*package
= SECUR32_findPackageA(pszPackage
);
809 TRACE("%s %p %p %p\n", debugstr_a(pszPackage
), pPackedContext
, Token
,
811 if (package
&& package
->provider
)
813 if (package
->provider
->fnTableA
.ImportSecurityContextA
)
817 ret
= package
->provider
->fnTableA
.ImportSecurityContextA(
818 pszPackage
, pPackedContext
, Token
, &myCtxt
);
821 ret
= SECUR32_makeSecHandle(phContext
, package
, &myCtxt
);
823 package
->provider
->fnTableW
.DeleteSecurityContext(&myCtxt
);
827 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
830 ret
= SEC_E_SECPKG_NOT_FOUND
;
835 /***********************************************************************
836 * ImportSecurityContextW (SECUR32.@)
838 SECURITY_STATUS WINAPI
ImportSecurityContextW(SEC_WCHAR
*pszPackage
,
839 PSecBuffer pPackedContext
, void *Token
, PCtxtHandle phContext
)
842 SecurePackage
*package
= SECUR32_findPackageW(pszPackage
);
844 TRACE("%s %p %p %p\n", debugstr_w(pszPackage
), pPackedContext
, Token
,
846 if (package
&& package
->provider
)
848 if (package
->provider
->fnTableW
.ImportSecurityContextW
)
852 ret
= package
->provider
->fnTableW
.ImportSecurityContextW(
853 pszPackage
, pPackedContext
, Token
, &myCtxt
);
856 ret
= SECUR32_makeSecHandle(phContext
, package
, &myCtxt
);
858 package
->provider
->fnTableW
.DeleteSecurityContext(&myCtxt
);
862 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
865 ret
= SEC_E_SECPKG_NOT_FOUND
;
869 /***********************************************************************
870 * AddCredentialsA (SECUR32.@)
872 SECURITY_STATUS WINAPI
AddCredentialsA(PCredHandle hCredentials
,
873 SEC_CHAR
*pszPrincipal
, SEC_CHAR
*pszPackage
, unsigned long fCredentialUse
,
874 void *pAuthData
, SEC_GET_KEY_FN pGetKeyFn
, void *pvGetKeyArgument
,
875 PTimeStamp ptsExpiry
)
879 TRACE("%p %s %s %ld %p %p %p %p\n", hCredentials
, debugstr_a(pszPrincipal
),
880 debugstr_a(pszPackage
), fCredentialUse
, pAuthData
, pGetKeyFn
,
881 pvGetKeyArgument
, ptsExpiry
);
884 SecurePackage
*package
= (SecurePackage
*)hCredentials
->dwUpper
;
885 PCredHandle cred
= (PCtxtHandle
)hCredentials
->dwLower
;
887 if (package
&& package
->provider
)
889 if (package
->provider
->fnTableA
.AddCredentialsA
)
890 ret
= package
->provider
->fnTableA
.AddCredentialsA(
891 cred
, pszPrincipal
, pszPackage
, fCredentialUse
, pAuthData
,
892 pGetKeyFn
, pvGetKeyArgument
, ptsExpiry
);
894 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
897 ret
= SEC_E_INVALID_HANDLE
;
900 ret
= SEC_E_INVALID_HANDLE
;
904 /***********************************************************************
905 * AddCredentialsW (SECUR32.@)
907 SECURITY_STATUS WINAPI
AddCredentialsW(PCredHandle hCredentials
,
908 SEC_WCHAR
*pszPrincipal
, SEC_WCHAR
*pszPackage
, unsigned long fCredentialUse
,
909 void *pAuthData
, SEC_GET_KEY_FN pGetKeyFn
, void *pvGetKeyArgument
,
910 PTimeStamp ptsExpiry
)
914 TRACE("%p %s %s %ld %p %p %p %p\n", hCredentials
, debugstr_w(pszPrincipal
),
915 debugstr_w(pszPackage
), fCredentialUse
, pAuthData
, pGetKeyFn
,
916 pvGetKeyArgument
, ptsExpiry
);
919 SecurePackage
*package
= (SecurePackage
*)hCredentials
->dwUpper
;
920 PCredHandle cred
= (PCtxtHandle
)hCredentials
->dwLower
;
922 if (package
&& package
->provider
)
924 if (package
->provider
->fnTableW
.AddCredentialsW
)
925 ret
= package
->provider
->fnTableW
.AddCredentialsW(
926 cred
, pszPrincipal
, pszPackage
, fCredentialUse
, pAuthData
,
927 pGetKeyFn
, pvGetKeyArgument
, ptsExpiry
);
929 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
932 ret
= SEC_E_INVALID_HANDLE
;
935 ret
= SEC_E_INVALID_HANDLE
;
939 /***********************************************************************
940 * QuerySecurityContextToken (SECUR32.@)
942 SECURITY_STATUS WINAPI
QuerySecurityContextToken(PCtxtHandle phContext
,
947 TRACE("%p %p\n", phContext
, phToken
);
950 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
951 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
953 if (package
&& package
->provider
)
955 if (package
->provider
->fnTableW
.QuerySecurityContextToken
)
956 ret
= package
->provider
->fnTableW
.QuerySecurityContextToken(
959 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
962 ret
= SEC_E_INVALID_HANDLE
;
965 ret
= SEC_E_INVALID_HANDLE
;
969 /***********************************************************************
970 * EncryptMessage (SECUR32.@)
972 SECURITY_STATUS WINAPI
EncryptMessage(PCtxtHandle phContext
, ULONG fQOP
,
973 PSecBufferDesc pMessage
, ULONG MessageSeqNo
)
977 TRACE("%p %ld %p %ld\n", phContext
, fQOP
, pMessage
, MessageSeqNo
);
980 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
981 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
983 if (package
&& package
->provider
)
985 if (package
->provider
->fnTableW
.EncryptMessage
)
986 ret
= package
->provider
->fnTableW
.EncryptMessage(
987 ctxt
, fQOP
, pMessage
, MessageSeqNo
);
989 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
992 ret
= SEC_E_INVALID_HANDLE
;
995 ret
= SEC_E_INVALID_HANDLE
;
999 /***********************************************************************
1000 * DecryptMessage (SECUR32.@)
1002 SECURITY_STATUS WINAPI
DecryptMessage(PCtxtHandle phContext
,
1003 PSecBufferDesc pMessage
, ULONG MessageSeqNo
, PULONG pfQOP
)
1005 SECURITY_STATUS ret
;
1007 TRACE("%p %p %ld %p\n", phContext
, pMessage
, MessageSeqNo
, pfQOP
);
1010 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
1011 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
1013 if (package
&& package
->provider
)
1015 if (package
->provider
->fnTableW
.DecryptMessage
)
1016 ret
= package
->provider
->fnTableW
.DecryptMessage(
1017 ctxt
, pMessage
, MessageSeqNo
, pfQOP
);
1019 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
1022 ret
= SEC_E_INVALID_HANDLE
;
1025 ret
= SEC_E_INVALID_HANDLE
;
1029 /***********************************************************************
1030 * SetContextAttributesA (SECUR32.@)
1032 SECURITY_STATUS WINAPI
SetContextAttributesA(PCtxtHandle phContext
,
1033 unsigned long ulAttribute
, void *pBuffer
, unsigned long cbBuffer
)
1035 SECURITY_STATUS ret
;
1037 TRACE("%p %ld %p %ld\n", phContext
, ulAttribute
, pBuffer
, cbBuffer
);
1040 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
1041 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
1043 if (package
&& package
->provider
)
1045 if (package
->provider
->fnTableA
.SetContextAttributesA
)
1046 ret
= package
->provider
->fnTableA
.SetContextAttributesA(
1047 ctxt
, ulAttribute
, pBuffer
, cbBuffer
);
1049 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
1052 ret
= SEC_E_INVALID_HANDLE
;
1055 ret
= SEC_E_INVALID_HANDLE
;
1059 /***********************************************************************
1060 * SetContextAttributesW (SECUR32.@)
1062 SECURITY_STATUS WINAPI
SetContextAttributesW(PCtxtHandle phContext
,
1063 unsigned long ulAttribute
, void *pBuffer
, unsigned long cbBuffer
)
1065 SECURITY_STATUS ret
;
1067 TRACE("%p %ld %p %ld\n", phContext
, ulAttribute
, pBuffer
, cbBuffer
);
1070 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
1071 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
1073 if (package
&& package
->provider
)
1075 if (package
->provider
->fnTableW
.SetContextAttributesW
)
1076 ret
= package
->provider
->fnTableW
.SetContextAttributesW(
1077 ctxt
, ulAttribute
, pBuffer
, cbBuffer
);
1079 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
1082 ret
= SEC_E_INVALID_HANDLE
;
1085 ret
= SEC_E_INVALID_HANDLE
;