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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/debug.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(secur32
);
25 /* Tries to allocate a new SecHandle, into which it stores package (in
26 * phSec->dwUpper) and a copy of realHandle (allocated with SECUR32_ALLOC,
27 * and stored in phSec->dwLower). SecHandle is equivalent to both a
28 * CredHandle and a CtxtHandle.
30 static SECURITY_STATUS
SECUR32_makeSecHandle(PSecHandle phSec
,
31 SecurePackage
*package
, PSecHandle realHandle
)
35 TRACE("%p %p %p\n", phSec
, package
, realHandle
);
37 if (phSec
&& package
&& realHandle
)
39 PSecHandle newSec
= HeapAlloc(GetProcessHeap(), 0, sizeof(SecHandle
));
43 *newSec
= *realHandle
;
44 phSec
->dwUpper
= (ULONG_PTR
)package
;
45 phSec
->dwLower
= (ULONG_PTR
)newSec
;
49 ret
= SEC_E_INSUFFICIENT_MEMORY
;
52 ret
= SEC_E_INVALID_HANDLE
;
56 /***********************************************************************
57 * AcquireCredentialsHandleA (SECUR32.@)
59 SECURITY_STATUS WINAPI
AcquireCredentialsHandleA(
60 SEC_CHAR
*pszPrincipal
, SEC_CHAR
*pszPackage
, ULONG fCredentialsUse
,
61 PLUID pvLogonID
, PVOID pAuthData
, SEC_GET_KEY_FN pGetKeyFn
,
62 PVOID pvGetKeyArgument
, PCredHandle phCredential
, PTimeStamp ptsExpiry
)
66 TRACE("%s %s %d %p %p %p %p %p %p\n", debugstr_a(pszPrincipal
),
67 debugstr_a(pszPackage
), fCredentialsUse
, pvLogonID
, pAuthData
, pGetKeyFn
,
68 pvGetKeyArgument
, phCredential
, ptsExpiry
);
71 SecurePackage
*package
= SECUR32_findPackageA(pszPackage
);
73 if (package
&& package
->provider
)
75 if (package
->provider
->fnTableA
.AcquireCredentialsHandleA
)
79 ret
= package
->provider
->fnTableA
.AcquireCredentialsHandleA(
80 pszPrincipal
, pszPackage
, fCredentialsUse
, pvLogonID
,
81 pAuthData
, pGetKeyFn
, pvGetKeyArgument
, &myCred
,
85 ret
= SECUR32_makeSecHandle(phCredential
, package
, &myCred
);
87 package
->provider
->fnTableW
.FreeCredentialsHandle(
92 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
95 ret
= SEC_E_SECPKG_NOT_FOUND
;
98 ret
= SEC_E_SECPKG_NOT_FOUND
;
102 /***********************************************************************
103 * AcquireCredentialsHandleW (SECUR32.@)
105 SECURITY_STATUS WINAPI
AcquireCredentialsHandleW(
106 SEC_WCHAR
*pszPrincipal
, SEC_WCHAR
*pszPackage
, ULONG fCredentialsUse
,
107 PLUID pvLogonID
, PVOID pAuthData
, SEC_GET_KEY_FN pGetKeyFn
,
108 PVOID pvGetKeyArgument
, PCredHandle phCredential
, PTimeStamp ptsExpiry
)
112 TRACE("%s %s %d %p %p %p %p %p %p\n", debugstr_w(pszPrincipal
),
113 debugstr_w(pszPackage
), fCredentialsUse
, pvLogonID
, pAuthData
, pGetKeyFn
,
114 pvGetKeyArgument
, phCredential
, ptsExpiry
);
117 SecurePackage
*package
= SECUR32_findPackageW(pszPackage
);
119 if (package
&& package
->provider
)
121 if (package
->provider
->fnTableW
.AcquireCredentialsHandleW
)
125 ret
= package
->provider
->fnTableW
.AcquireCredentialsHandleW(
126 pszPrincipal
, pszPackage
, fCredentialsUse
, pvLogonID
,
127 pAuthData
, pGetKeyFn
, pvGetKeyArgument
, &myCred
,
131 ret
= SECUR32_makeSecHandle(phCredential
, package
, &myCred
);
133 package
->provider
->fnTableW
.FreeCredentialsHandle(
138 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
141 ret
= SEC_E_SECPKG_NOT_FOUND
;
144 ret
= SEC_E_SECPKG_NOT_FOUND
;
148 /***********************************************************************
149 * FreeCredentialsHandle (SECUR32.@)
151 SECURITY_STATUS WINAPI
FreeCredentialsHandle(
152 PCredHandle phCredential
)
156 TRACE("%p\n", phCredential
);
159 SecurePackage
*package
= (SecurePackage
*)phCredential
->dwUpper
;
160 PCredHandle cred
= (PCredHandle
)phCredential
->dwLower
;
162 if (package
&& package
->provider
&&
163 package
->provider
->fnTableW
.FreeCredentialsHandle
)
164 ret
= package
->provider
->fnTableW
.FreeCredentialsHandle(cred
);
166 ret
= SEC_E_INVALID_HANDLE
;
167 HeapFree(GetProcessHeap(), 0, cred
);
170 ret
= SEC_E_INVALID_HANDLE
;
174 /***********************************************************************
175 * QueryCredentialsAttributesA (SECUR32.@)
177 SECURITY_STATUS WINAPI
QueryCredentialsAttributesA(
178 PCredHandle phCredential
, ULONG ulAttribute
, void *pBuffer
)
182 TRACE("%p %d %p\n", phCredential
, ulAttribute
, pBuffer
);
185 SecurePackage
*package
= (SecurePackage
*)phCredential
->dwUpper
;
186 PCredHandle cred
= (PCredHandle
)phCredential
->dwLower
;
188 if (package
&& package
->provider
)
190 if (package
->provider
->fnTableA
.QueryCredentialsAttributesA
)
191 ret
= package
->provider
->fnTableA
.QueryCredentialsAttributesA(
192 cred
, ulAttribute
, pBuffer
);
194 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
197 ret
= SEC_E_INVALID_HANDLE
;
200 ret
= SEC_E_INVALID_HANDLE
;
204 /***********************************************************************
205 * QueryCredentialsAttributesW (SECUR32.@)
207 SECURITY_STATUS WINAPI
QueryCredentialsAttributesW(
208 PCredHandle phCredential
, ULONG ulAttribute
, void *pBuffer
)
212 TRACE("%p %d %p\n", phCredential
, ulAttribute
, pBuffer
);
215 SecurePackage
*package
= (SecurePackage
*)phCredential
->dwUpper
;
216 PCredHandle cred
= (PCredHandle
)phCredential
->dwLower
;
218 if (package
&& package
->provider
)
220 if (package
->provider
->fnTableW
.QueryCredentialsAttributesW
)
221 ret
= package
->provider
->fnTableW
.QueryCredentialsAttributesW(
222 cred
, ulAttribute
, pBuffer
);
224 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
227 ret
= SEC_E_INVALID_HANDLE
;
230 ret
= SEC_E_INVALID_HANDLE
;
234 /***********************************************************************
235 * InitializeSecurityContextA (SECUR32.@)
237 SECURITY_STATUS WINAPI
InitializeSecurityContextA(
238 PCredHandle phCredential
, PCtxtHandle phContext
,
239 SEC_CHAR
*pszTargetName
, ULONG fContextReq
,
240 ULONG Reserved1
, ULONG TargetDataRep
, PSecBufferDesc pInput
,
241 ULONG Reserved2
, PCtxtHandle phNewContext
, PSecBufferDesc pOutput
,
242 ULONG
*pfContextAttr
, PTimeStamp ptsExpiry
)
245 SecurePackage
*package
= NULL
;
246 PCredHandle cred
= NULL
;
247 PCredHandle ctxt
= NULL
;
249 TRACE("%p %p %s 0x%08x %d %d %p %d %p %p %p %p\n", phCredential
, phContext
,
250 debugstr_a(pszTargetName
), fContextReq
, Reserved1
, TargetDataRep
, pInput
,
251 Reserved1
, phNewContext
, pOutput
, pfContextAttr
, ptsExpiry
);
255 package
= (SecurePackage
*)phContext
->dwUpper
;
256 ctxt
= (PCtxtHandle
)phContext
->dwLower
;
260 package
= (SecurePackage
*)phCredential
->dwUpper
;
261 cred
= (PCredHandle
)phCredential
->dwLower
;
264 if (package
&& package
->provider
)
266 if (package
->provider
->fnTableA
.InitializeSecurityContextA
)
272 PCtxtHandle realCtxt
= (PCtxtHandle
)phContext
->dwLower
;
273 myCtxt
.dwUpper
= realCtxt
->dwUpper
;
274 myCtxt
.dwLower
= realCtxt
->dwLower
;
277 ret
= package
->provider
->fnTableA
.InitializeSecurityContextA(
278 cred
, ctxt
, pszTargetName
, fContextReq
,
279 Reserved1
, TargetDataRep
, pInput
, Reserved2
, phNewContext
? &myCtxt
: NULL
,
280 pOutput
, pfContextAttr
, ptsExpiry
);
281 if ((ret
== SEC_E_OK
|| ret
== SEC_I_CONTINUE_NEEDED
) &&
282 phNewContext
&& phNewContext
!= phContext
)
284 SECURITY_STATUS ret2
;
285 ret2
= SECUR32_makeSecHandle(phNewContext
, package
, &myCtxt
);
286 if (ret2
!= SEC_E_OK
)
287 package
->provider
->fnTableA
.DeleteSecurityContext(&myCtxt
);
291 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
294 ret
= SEC_E_INVALID_HANDLE
;
298 /***********************************************************************
299 * InitializeSecurityContextW (SECUR32.@)
301 SECURITY_STATUS WINAPI
InitializeSecurityContextW(
302 PCredHandle phCredential
, PCtxtHandle phContext
,
303 SEC_WCHAR
*pszTargetName
, ULONG fContextReq
,
304 ULONG Reserved1
, ULONG TargetDataRep
, PSecBufferDesc pInput
,
305 ULONG Reserved2
, PCtxtHandle phNewContext
, PSecBufferDesc pOutput
,
306 ULONG
*pfContextAttr
, PTimeStamp ptsExpiry
)
309 SecurePackage
*package
= NULL
;
310 PCredHandle cred
= NULL
;
311 PCredHandle ctxt
= NULL
;
313 TRACE("%p %p %s %d %d %d %p %d %p %p %p %p\n", phCredential
, phContext
,
314 debugstr_w(pszTargetName
), fContextReq
, Reserved1
, TargetDataRep
, pInput
,
315 Reserved1
, phNewContext
, pOutput
, pfContextAttr
, ptsExpiry
);
319 package
= (SecurePackage
*)phContext
->dwUpper
;
320 ctxt
= (PCtxtHandle
)phContext
->dwLower
;
324 package
= (SecurePackage
*)phCredential
->dwUpper
;
325 cred
= (PCredHandle
)phCredential
->dwLower
;
328 if (package
&& package
->provider
)
330 if (package
->provider
->fnTableW
.InitializeSecurityContextW
)
336 PCtxtHandle realCtxt
= (PCtxtHandle
)phContext
->dwLower
;
337 myCtxt
.dwUpper
= realCtxt
->dwUpper
;
338 myCtxt
.dwLower
= realCtxt
->dwLower
;
341 ret
= package
->provider
->fnTableW
.InitializeSecurityContextW(
342 cred
, ctxt
, pszTargetName
, fContextReq
,
343 Reserved1
, TargetDataRep
, pInput
, Reserved2
, phNewContext
? &myCtxt
: NULL
,
344 pOutput
, pfContextAttr
, ptsExpiry
);
345 if ((ret
== SEC_E_OK
|| ret
== SEC_I_CONTINUE_NEEDED
) &&
346 phNewContext
&& phNewContext
!= phContext
)
348 SECURITY_STATUS ret2
;
349 ret2
= SECUR32_makeSecHandle(phNewContext
, package
, &myCtxt
);
350 if (ret2
!= SEC_E_OK
)
351 package
->provider
->fnTableW
.DeleteSecurityContext(&myCtxt
);
355 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
358 ret
= SEC_E_INVALID_HANDLE
;
362 /***********************************************************************
363 * AcceptSecurityContext (SECUR32.@)
365 SECURITY_STATUS WINAPI
AcceptSecurityContext(
366 PCredHandle phCredential
, PCtxtHandle phContext
, PSecBufferDesc pInput
,
367 ULONG fContextReq
, ULONG TargetDataRep
, PCtxtHandle phNewContext
,
368 PSecBufferDesc pOutput
, ULONG
*pfContextAttr
, PTimeStamp ptsExpiry
)
372 TRACE("%p %p %p %d %d %p %p %p %p\n", phCredential
, phContext
, pInput
,
373 fContextReq
, TargetDataRep
, phNewContext
, pOutput
, pfContextAttr
,
377 SecurePackage
*package
= (SecurePackage
*)phCredential
->dwUpper
;
378 PCredHandle cred
= (PCredHandle
)phCredential
->dwLower
;
380 if (package
&& package
->provider
)
382 if (package
->provider
->fnTableW
.AcceptSecurityContext
)
388 PCtxtHandle realCtxt
= (PCtxtHandle
)phContext
->dwLower
;
389 TRACE("realCtx: %p\n", realCtxt
);
390 myCtxt
.dwUpper
= realCtxt
->dwUpper
;
391 myCtxt
.dwLower
= realCtxt
->dwLower
;
394 ret
= package
->provider
->fnTableW
.AcceptSecurityContext(
395 cred
, phContext
? &myCtxt
: NULL
, pInput
, fContextReq
,
396 TargetDataRep
, &myCtxt
, pOutput
, pfContextAttr
, ptsExpiry
);
397 if (ret
== SEC_E_OK
|| ret
== SEC_I_CONTINUE_NEEDED
)
399 SECURITY_STATUS ret2
;
400 ret2
= SECUR32_makeSecHandle(phNewContext
, package
, &myCtxt
);
401 if (ret2
!= SEC_E_OK
)
402 package
->provider
->fnTableW
.DeleteSecurityContext(
407 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
410 ret
= SEC_E_INVALID_HANDLE
;
413 ret
= SEC_E_INVALID_HANDLE
;
417 /***********************************************************************
418 * CompleteAuthToken (SECUR32.@)
420 SECURITY_STATUS WINAPI
CompleteAuthToken(PCtxtHandle phContext
,
421 PSecBufferDesc pToken
)
425 TRACE("%p %p\n", phContext
, pToken
);
428 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
429 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
431 if (package
&& package
->provider
)
433 if (package
->provider
->fnTableW
.CompleteAuthToken
)
434 ret
= package
->provider
->fnTableW
.CompleteAuthToken(ctxt
,
437 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
440 ret
= SEC_E_INVALID_HANDLE
;
443 ret
= SEC_E_INVALID_HANDLE
;
447 /***********************************************************************
448 * DeleteSecurityContext (SECUR32.@)
450 SECURITY_STATUS WINAPI
DeleteSecurityContext(PCtxtHandle phContext
)
454 TRACE("%p\n", phContext
);
457 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
458 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
460 if (package
&& package
->provider
&&
461 package
->provider
->fnTableW
.DeleteSecurityContext
)
462 ret
= package
->provider
->fnTableW
.DeleteSecurityContext(ctxt
);
464 ret
= SEC_E_INVALID_HANDLE
;
465 HeapFree(GetProcessHeap(), 0, ctxt
);
468 ret
= SEC_E_INVALID_HANDLE
;
472 /***********************************************************************
473 * ApplyControlToken (SECUR32.@)
475 SECURITY_STATUS WINAPI
ApplyControlToken(PCtxtHandle phContext
,
476 PSecBufferDesc pInput
)
480 TRACE("%p %p\n", phContext
, pInput
);
483 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
484 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
486 if (package
&& package
->provider
)
488 if (package
->provider
->fnTableW
.ApplyControlToken
)
489 ret
= package
->provider
->fnTableW
.ApplyControlToken(
492 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
495 ret
= SEC_E_INVALID_HANDLE
;
498 ret
= SEC_E_INVALID_HANDLE
;
502 /***********************************************************************
503 * QueryContextAttributesA (SECUR32.@)
505 SECURITY_STATUS WINAPI
QueryContextAttributesA(PCtxtHandle phContext
,
506 ULONG ulAttribute
, void *pBuffer
)
510 TRACE("%p %d %p\n", phContext
, ulAttribute
, pBuffer
);
513 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
514 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
516 if (package
&& package
->provider
)
518 if (package
->provider
->fnTableA
.QueryContextAttributesA
)
519 ret
= package
->provider
->fnTableA
.QueryContextAttributesA(
520 ctxt
, ulAttribute
, pBuffer
);
522 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
525 ret
= SEC_E_INVALID_HANDLE
;
528 ret
= SEC_E_INVALID_HANDLE
;
532 /***********************************************************************
533 * QueryContextAttributesW (SECUR32.@)
535 SECURITY_STATUS WINAPI
QueryContextAttributesW(PCtxtHandle phContext
,
536 ULONG ulAttribute
, void *pBuffer
)
540 TRACE("%p %d %p\n", phContext
, ulAttribute
, pBuffer
);
543 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
544 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
546 if (package
&& package
->provider
)
548 if (package
->provider
->fnTableW
.QueryContextAttributesW
)
549 ret
= package
->provider
->fnTableW
.QueryContextAttributesW(
550 ctxt
, ulAttribute
, pBuffer
);
552 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
555 ret
= SEC_E_INVALID_HANDLE
;
558 ret
= SEC_E_INVALID_HANDLE
;
562 /***********************************************************************
563 * ImpersonateSecurityContext (SECUR32.@)
565 SECURITY_STATUS WINAPI
ImpersonateSecurityContext(PCtxtHandle phContext
)
569 TRACE("%p\n", phContext
);
572 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
573 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
575 if (package
&& package
->provider
)
577 if (package
->provider
->fnTableW
.ImpersonateSecurityContext
)
578 ret
= package
->provider
->fnTableW
.ImpersonateSecurityContext(
581 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
584 ret
= SEC_E_INVALID_HANDLE
;
587 ret
= SEC_E_INVALID_HANDLE
;
591 /***********************************************************************
592 * RevertSecurityContext (SECUR32.@)
594 SECURITY_STATUS WINAPI
RevertSecurityContext(PCtxtHandle phContext
)
598 TRACE("%p\n", phContext
);
601 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
602 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
604 if (package
&& package
->provider
)
606 if (package
->provider
->fnTableW
.RevertSecurityContext
)
607 ret
= package
->provider
->fnTableW
.RevertSecurityContext(
610 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
613 ret
= SEC_E_INVALID_HANDLE
;
616 ret
= SEC_E_INVALID_HANDLE
;
620 /***********************************************************************
621 * MakeSignature (SECUR32.@)
623 SECURITY_STATUS WINAPI
MakeSignature(PCtxtHandle phContext
, ULONG fQOP
,
624 PSecBufferDesc pMessage
, ULONG MessageSeqNo
)
628 TRACE("%p %d %p %d\n", phContext
, fQOP
, pMessage
, MessageSeqNo
);
631 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
632 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
634 if (package
&& package
->provider
)
636 if (package
->provider
->fnTableW
.MakeSignature
)
637 ret
= package
->provider
->fnTableW
.MakeSignature(
638 ctxt
, fQOP
, pMessage
, MessageSeqNo
);
640 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
643 ret
= SEC_E_INVALID_HANDLE
;
646 ret
= SEC_E_INVALID_HANDLE
;
650 /***********************************************************************
651 * VerifySignature (SECUR32.@)
653 SECURITY_STATUS WINAPI
VerifySignature(PCtxtHandle phContext
,
654 PSecBufferDesc pMessage
, ULONG MessageSeqNo
, PULONG pfQOP
)
658 TRACE("%p %p %d %p\n", phContext
, pMessage
, MessageSeqNo
, pfQOP
);
661 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
662 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
664 if (package
&& package
->provider
)
666 if (package
->provider
->fnTableW
.VerifySignature
)
667 ret
= package
->provider
->fnTableW
.VerifySignature(
668 ctxt
, pMessage
, MessageSeqNo
, pfQOP
);
670 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
673 ret
= SEC_E_INVALID_HANDLE
;
676 ret
= SEC_E_INVALID_HANDLE
;
680 /***********************************************************************
681 * QuerySecurityPackageInfoA (SECUR32.@)
683 SECURITY_STATUS WINAPI
QuerySecurityPackageInfoA(SEC_CHAR
*pszPackageName
,
684 PSecPkgInfoA
*ppPackageInfo
)
688 TRACE("%s %p\n", debugstr_a(pszPackageName
), ppPackageInfo
);
691 SecurePackage
*package
= SECUR32_findPackageA(pszPackageName
);
695 size_t bytesNeeded
= sizeof(SecPkgInfoA
);
696 int nameLen
= 0, commentLen
= 0;
698 if (package
->infoW
.Name
)
700 nameLen
= WideCharToMultiByte(CP_ACP
, 0,
701 package
->infoW
.Name
, -1, NULL
, 0, NULL
, NULL
);
702 bytesNeeded
+= nameLen
;
704 if (package
->infoW
.Comment
)
706 commentLen
= WideCharToMultiByte(CP_ACP
, 0,
707 package
->infoW
.Comment
, -1, NULL
, 0, NULL
, NULL
);
708 bytesNeeded
+= commentLen
;
710 *ppPackageInfo
= HeapAlloc(GetProcessHeap(), 0, bytesNeeded
);
713 PSTR nextString
= (PSTR
)((PBYTE
)*ppPackageInfo
+
714 sizeof(SecPkgInfoA
));
716 memcpy(*ppPackageInfo
, &package
->infoW
, sizeof(package
->infoW
));
717 if (package
->infoW
.Name
)
719 (*ppPackageInfo
)->Name
= nextString
;
720 nextString
+= WideCharToMultiByte(CP_ACP
, 0,
721 package
->infoW
.Name
, -1, nextString
, nameLen
, NULL
, NULL
);
724 (*ppPackageInfo
)->Name
= NULL
;
725 if (package
->infoW
.Comment
)
727 (*ppPackageInfo
)->Comment
= nextString
;
728 nextString
+= WideCharToMultiByte(CP_ACP
, 0,
729 package
->infoW
.Comment
, -1, nextString
, commentLen
, NULL
,
733 (*ppPackageInfo
)->Comment
= NULL
;
737 ret
= SEC_E_INSUFFICIENT_MEMORY
;
740 ret
= SEC_E_SECPKG_NOT_FOUND
;
743 ret
= SEC_E_SECPKG_NOT_FOUND
;
747 /***********************************************************************
748 * QuerySecurityPackageInfoW (SECUR32.@)
750 SECURITY_STATUS WINAPI
QuerySecurityPackageInfoW(SEC_WCHAR
*pszPackageName
,
751 PSecPkgInfoW
*ppPackageInfo
)
754 SecurePackage
*package
= SECUR32_findPackageW(pszPackageName
);
756 TRACE("%s %p\n", debugstr_w(pszPackageName
), ppPackageInfo
);
759 size_t bytesNeeded
= sizeof(SecPkgInfoW
);
760 int nameLen
= 0, commentLen
= 0;
762 if (package
->infoW
.Name
)
764 nameLen
= lstrlenW(package
->infoW
.Name
) + 1;
765 bytesNeeded
+= nameLen
* sizeof(WCHAR
);
767 if (package
->infoW
.Comment
)
769 commentLen
= lstrlenW(package
->infoW
.Comment
) + 1;
770 bytesNeeded
+= commentLen
* sizeof(WCHAR
);
772 *ppPackageInfo
= HeapAlloc(GetProcessHeap(), 0, bytesNeeded
);
775 PWSTR nextString
= (PWSTR
)((PBYTE
)*ppPackageInfo
+
776 sizeof(SecPkgInfoW
));
778 **ppPackageInfo
= package
->infoW
;
779 if (package
->infoW
.Name
)
781 (*ppPackageInfo
)->Name
= nextString
;
782 lstrcpynW(nextString
, package
->infoW
.Name
, nameLen
);
783 nextString
+= nameLen
;
786 (*ppPackageInfo
)->Name
= NULL
;
787 if (package
->infoW
.Comment
)
789 (*ppPackageInfo
)->Comment
= nextString
;
790 lstrcpynW(nextString
, package
->infoW
.Comment
, commentLen
);
793 (*ppPackageInfo
)->Comment
= NULL
;
797 ret
= SEC_E_INSUFFICIENT_MEMORY
;
800 ret
= SEC_E_SECPKG_NOT_FOUND
;
804 /***********************************************************************
805 * ExportSecurityContext (SECUR32.@)
807 SECURITY_STATUS WINAPI
ExportSecurityContext(PCtxtHandle phContext
,
808 ULONG fFlags
, PSecBuffer pPackedContext
, void **pToken
)
812 TRACE("%p %d %p %p\n", phContext
, fFlags
, pPackedContext
, pToken
);
815 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
816 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
818 if (package
&& package
->provider
)
820 if (package
->provider
->fnTableW
.ExportSecurityContext
)
821 ret
= package
->provider
->fnTableW
.ExportSecurityContext(
822 ctxt
, fFlags
, pPackedContext
, pToken
);
824 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
827 ret
= SEC_E_INVALID_HANDLE
;
830 ret
= SEC_E_INVALID_HANDLE
;
834 /***********************************************************************
835 * ImportSecurityContextA (SECUR32.@)
837 SECURITY_STATUS WINAPI
ImportSecurityContextA(SEC_CHAR
*pszPackage
,
838 PSecBuffer pPackedContext
, void *Token
, PCtxtHandle phContext
)
841 SecurePackage
*package
= SECUR32_findPackageA(pszPackage
);
843 TRACE("%s %p %p %p\n", debugstr_a(pszPackage
), pPackedContext
, Token
,
845 if (package
&& package
->provider
)
847 if (package
->provider
->fnTableA
.ImportSecurityContextA
)
851 ret
= package
->provider
->fnTableA
.ImportSecurityContextA(
852 pszPackage
, pPackedContext
, Token
, &myCtxt
);
855 ret
= SECUR32_makeSecHandle(phContext
, package
, &myCtxt
);
857 package
->provider
->fnTableW
.DeleteSecurityContext(&myCtxt
);
861 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
864 ret
= SEC_E_SECPKG_NOT_FOUND
;
869 /***********************************************************************
870 * ImportSecurityContextW (SECUR32.@)
872 SECURITY_STATUS WINAPI
ImportSecurityContextW(SEC_WCHAR
*pszPackage
,
873 PSecBuffer pPackedContext
, void *Token
, PCtxtHandle phContext
)
876 SecurePackage
*package
= SECUR32_findPackageW(pszPackage
);
878 TRACE("%s %p %p %p\n", debugstr_w(pszPackage
), pPackedContext
, Token
,
880 if (package
&& package
->provider
)
882 if (package
->provider
->fnTableW
.ImportSecurityContextW
)
886 ret
= package
->provider
->fnTableW
.ImportSecurityContextW(
887 pszPackage
, pPackedContext
, Token
, &myCtxt
);
890 ret
= SECUR32_makeSecHandle(phContext
, package
, &myCtxt
);
892 package
->provider
->fnTableW
.DeleteSecurityContext(&myCtxt
);
896 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
899 ret
= SEC_E_SECPKG_NOT_FOUND
;
903 /***********************************************************************
904 * AddCredentialsA (SECUR32.@)
906 SECURITY_STATUS WINAPI
AddCredentialsA(PCredHandle hCredentials
,
907 SEC_CHAR
*pszPrincipal
, SEC_CHAR
*pszPackage
, ULONG fCredentialUse
,
908 void *pAuthData
, SEC_GET_KEY_FN pGetKeyFn
, void *pvGetKeyArgument
,
909 PTimeStamp ptsExpiry
)
913 TRACE("%p %s %s %d %p %p %p %p\n", hCredentials
, debugstr_a(pszPrincipal
),
914 debugstr_a(pszPackage
), fCredentialUse
, pAuthData
, pGetKeyFn
,
915 pvGetKeyArgument
, ptsExpiry
);
918 SecurePackage
*package
= (SecurePackage
*)hCredentials
->dwUpper
;
919 PCredHandle cred
= (PCtxtHandle
)hCredentials
->dwLower
;
921 if (package
&& package
->provider
)
923 if (package
->provider
->fnTableA
.AddCredentialsA
)
924 ret
= package
->provider
->fnTableA
.AddCredentialsA(
925 cred
, pszPrincipal
, pszPackage
, fCredentialUse
, pAuthData
,
926 pGetKeyFn
, pvGetKeyArgument
, ptsExpiry
);
928 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
931 ret
= SEC_E_INVALID_HANDLE
;
934 ret
= SEC_E_INVALID_HANDLE
;
938 /***********************************************************************
939 * AddCredentialsW (SECUR32.@)
941 SECURITY_STATUS WINAPI
AddCredentialsW(PCredHandle hCredentials
,
942 SEC_WCHAR
*pszPrincipal
, SEC_WCHAR
*pszPackage
, ULONG fCredentialUse
,
943 void *pAuthData
, SEC_GET_KEY_FN pGetKeyFn
, void *pvGetKeyArgument
,
944 PTimeStamp ptsExpiry
)
948 TRACE("%p %s %s %d %p %p %p %p\n", hCredentials
, debugstr_w(pszPrincipal
),
949 debugstr_w(pszPackage
), fCredentialUse
, pAuthData
, pGetKeyFn
,
950 pvGetKeyArgument
, ptsExpiry
);
953 SecurePackage
*package
= (SecurePackage
*)hCredentials
->dwUpper
;
954 PCredHandle cred
= (PCtxtHandle
)hCredentials
->dwLower
;
956 if (package
&& package
->provider
)
958 if (package
->provider
->fnTableW
.AddCredentialsW
)
959 ret
= package
->provider
->fnTableW
.AddCredentialsW(
960 cred
, pszPrincipal
, pszPackage
, fCredentialUse
, pAuthData
,
961 pGetKeyFn
, pvGetKeyArgument
, ptsExpiry
);
963 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
966 ret
= SEC_E_INVALID_HANDLE
;
969 ret
= SEC_E_INVALID_HANDLE
;
973 /***********************************************************************
974 * QuerySecurityContextToken (SECUR32.@)
976 SECURITY_STATUS WINAPI
QuerySecurityContextToken(PCtxtHandle phContext
,
981 TRACE("%p %p\n", phContext
, phToken
);
984 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
985 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
987 if (package
&& package
->provider
)
989 if (package
->provider
->fnTableW
.QuerySecurityContextToken
)
990 ret
= package
->provider
->fnTableW
.QuerySecurityContextToken(
993 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
996 ret
= SEC_E_INVALID_HANDLE
;
999 ret
= SEC_E_INVALID_HANDLE
;
1003 /***********************************************************************
1004 * EncryptMessage (SECUR32.@)
1006 SECURITY_STATUS WINAPI
EncryptMessage(PCtxtHandle phContext
, ULONG fQOP
,
1007 PSecBufferDesc pMessage
, ULONG MessageSeqNo
)
1009 SECURITY_STATUS ret
;
1011 TRACE("%p %d %p %d\n", phContext
, fQOP
, pMessage
, MessageSeqNo
);
1014 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
1015 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
1017 if (package
&& package
->provider
)
1019 if (package
->provider
->fnTableW
.EncryptMessage
)
1020 ret
= package
->provider
->fnTableW
.EncryptMessage(
1021 ctxt
, fQOP
, pMessage
, MessageSeqNo
);
1023 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
1026 ret
= SEC_E_INVALID_HANDLE
;
1029 ret
= SEC_E_INVALID_HANDLE
;
1033 /***********************************************************************
1034 * DecryptMessage (SECUR32.@)
1036 SECURITY_STATUS WINAPI
DecryptMessage(PCtxtHandle phContext
,
1037 PSecBufferDesc pMessage
, ULONG MessageSeqNo
, PULONG pfQOP
)
1039 SECURITY_STATUS ret
;
1041 TRACE("%p %p %d %p\n", phContext
, pMessage
, MessageSeqNo
, pfQOP
);
1044 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
1045 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
1047 if (package
&& package
->provider
)
1049 if (package
->provider
->fnTableW
.DecryptMessage
)
1050 ret
= package
->provider
->fnTableW
.DecryptMessage(
1051 ctxt
, pMessage
, MessageSeqNo
, pfQOP
);
1053 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
1056 ret
= SEC_E_INVALID_HANDLE
;
1059 ret
= SEC_E_INVALID_HANDLE
;
1063 /***********************************************************************
1064 * SetContextAttributesA (SECUR32.@)
1066 SECURITY_STATUS WINAPI
SetContextAttributesA(PCtxtHandle phContext
,
1067 ULONG ulAttribute
, void *pBuffer
, ULONG cbBuffer
)
1069 SECURITY_STATUS ret
;
1071 TRACE("%p %d %p %d\n", phContext
, ulAttribute
, pBuffer
, cbBuffer
);
1074 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
1075 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
1077 if (package
&& package
->provider
)
1079 if (package
->provider
->fnTableA
.SetContextAttributesA
)
1080 ret
= package
->provider
->fnTableA
.SetContextAttributesA(
1081 ctxt
, ulAttribute
, pBuffer
, cbBuffer
);
1083 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
1086 ret
= SEC_E_INVALID_HANDLE
;
1089 ret
= SEC_E_INVALID_HANDLE
;
1093 /***********************************************************************
1094 * SetContextAttributesW (SECUR32.@)
1096 SECURITY_STATUS WINAPI
SetContextAttributesW(PCtxtHandle phContext
,
1097 ULONG ulAttribute
, void *pBuffer
, ULONG cbBuffer
)
1099 SECURITY_STATUS ret
;
1101 TRACE("%p %d %p %d\n", phContext
, ulAttribute
, pBuffer
, cbBuffer
);
1104 SecurePackage
*package
= (SecurePackage
*)phContext
->dwUpper
;
1105 PCtxtHandle ctxt
= (PCtxtHandle
)phContext
->dwLower
;
1107 if (package
&& package
->provider
)
1109 if (package
->provider
->fnTableW
.SetContextAttributesW
)
1110 ret
= package
->provider
->fnTableW
.SetContextAttributesW(
1111 ctxt
, ulAttribute
, pBuffer
, cbBuffer
);
1113 ret
= SEC_E_UNSUPPORTED_FUNCTION
;
1116 ret
= SEC_E_INVALID_HANDLE
;
1119 ret
= SEC_E_INVALID_HANDLE
;