rpcrt4: Avoid casting an object to IUnknown.
[wine.git] / dlls / secur32 / wrapper.c
blob53fea29fcc5916fd8ffa7799ad07cdc60dd7de27
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
20 #include <stdarg.h>
21 #include <stdlib.h>
22 #include "windef.h"
23 #include "winbase.h"
24 #include "winternl.h"
25 #include "winnls.h"
26 #include "sspi.h"
28 #include "wine/debug.h"
29 #include "secur32_priv.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(secur32);
33 /***********************************************************************
34 * AcquireCredentialsHandleA (SECUR32.@)
36 SECURITY_STATUS WINAPI AcquireCredentialsHandleA(
37 SEC_CHAR *pszPrincipal, SEC_CHAR *pszPackage, ULONG fCredentialsUse,
38 PLUID pvLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn,
39 PVOID pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
41 SECURITY_STATUS ret;
43 TRACE("%s %s %ld %p %p %p %p %p %p\n", debugstr_a(pszPrincipal),
44 debugstr_a(pszPackage), fCredentialsUse, pvLogonID, pAuthData, pGetKeyFn,
45 pvGetKeyArgument, phCredential, ptsExpiry);
46 if (pszPackage)
48 SecurePackage *package = SECUR32_findPackageA(pszPackage);
49 if (package && package->provider)
51 if (package->provider->fnTableA.AcquireCredentialsHandleA)
53 ret = package->provider->fnTableA.AcquireCredentialsHandleA(
54 pszPrincipal, pszPackage, fCredentialsUse, pvLogonID,
55 pAuthData, pGetKeyFn, pvGetKeyArgument, phCredential,
56 ptsExpiry);
57 if (ret == SEC_E_OK)
58 phCredential->dwUpper = (ULONG_PTR)package;
60 else
61 ret = SEC_E_UNSUPPORTED_FUNCTION;
63 else
64 ret = SEC_E_SECPKG_NOT_FOUND;
66 else
67 ret = SEC_E_SECPKG_NOT_FOUND;
68 return ret;
71 /***********************************************************************
72 * AcquireCredentialsHandleW (SECUR32.@)
74 SECURITY_STATUS WINAPI AcquireCredentialsHandleW(
75 SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, ULONG fCredentialsUse,
76 PLUID pvLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn,
77 PVOID pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
79 SECURITY_STATUS ret;
81 TRACE("%s %s %ld %p %p %p %p %p %p\n", debugstr_w(pszPrincipal),
82 debugstr_w(pszPackage), fCredentialsUse, pvLogonID, pAuthData, pGetKeyFn,
83 pvGetKeyArgument, phCredential, ptsExpiry);
84 if (pszPackage)
86 SecurePackage *package = SECUR32_findPackageW(pszPackage);
87 if (package && package->provider)
89 if (package->provider->fnTableW.AcquireCredentialsHandleW)
91 ret = package->provider->fnTableW.AcquireCredentialsHandleW(
92 pszPrincipal, pszPackage, fCredentialsUse, pvLogonID,
93 pAuthData, pGetKeyFn, pvGetKeyArgument, phCredential,
94 ptsExpiry);
95 if (ret == SEC_E_OK)
96 phCredential->dwUpper = (ULONG_PTR)package;
98 else
99 ret = SEC_E_UNSUPPORTED_FUNCTION;
101 else
102 ret = SEC_E_SECPKG_NOT_FOUND;
104 else
105 ret = SEC_E_SECPKG_NOT_FOUND;
106 return ret;
109 /***********************************************************************
110 * FreeCredentialsHandle (SECUR32.@)
112 SECURITY_STATUS WINAPI FreeCredentialsHandle(
113 PCredHandle phCredential)
115 SECURITY_STATUS ret;
117 TRACE("%p\n", phCredential);
118 if (phCredential)
120 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
121 if (package && package->provider && package->provider->fnTableW.FreeCredentialsHandle)
122 ret = package->provider->fnTableW.FreeCredentialsHandle(phCredential);
123 else
124 ret = SEC_E_INVALID_HANDLE;
126 else
127 ret = SEC_E_INVALID_HANDLE;
128 return ret;
131 /***********************************************************************
132 * QueryCredentialsAttributesA (SECUR32.@)
134 SECURITY_STATUS WINAPI QueryCredentialsAttributesA(
135 PCredHandle phCredential, ULONG ulAttribute, void *pBuffer)
137 SECURITY_STATUS ret;
139 TRACE("%p %ld %p\n", phCredential, ulAttribute, pBuffer);
140 if (phCredential)
142 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
143 if (package && package->provider)
145 if (package->provider->fnTableA.QueryCredentialsAttributesA)
146 ret = package->provider->fnTableA.QueryCredentialsAttributesA(
147 phCredential, ulAttribute, pBuffer);
148 else
149 ret = SEC_E_UNSUPPORTED_FUNCTION;
151 else
152 ret = SEC_E_INVALID_HANDLE;
154 else
155 ret = SEC_E_INVALID_HANDLE;
156 return ret;
159 /***********************************************************************
160 * QueryCredentialsAttributesW (SECUR32.@)
162 SECURITY_STATUS WINAPI QueryCredentialsAttributesW(
163 PCredHandle phCredential, ULONG ulAttribute, void *pBuffer)
165 SECURITY_STATUS ret;
167 TRACE("%p %ld %p\n", phCredential, ulAttribute, pBuffer);
168 if (phCredential)
170 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
171 if (package && package->provider)
173 if (package->provider->fnTableW.QueryCredentialsAttributesW)
174 ret = package->provider->fnTableW.QueryCredentialsAttributesW(phCredential, ulAttribute, pBuffer);
175 else
176 ret = SEC_E_UNSUPPORTED_FUNCTION;
178 else
179 ret = SEC_E_INVALID_HANDLE;
181 else
182 ret = SEC_E_INVALID_HANDLE;
183 return ret;
186 /***********************************************************************
187 * InitializeSecurityContextA (SECUR32.@)
189 SECURITY_STATUS WINAPI InitializeSecurityContextA(
190 PCredHandle phCredential, PCtxtHandle phContext,
191 SEC_CHAR *pszTargetName, ULONG fContextReq,
192 ULONG Reserved1, ULONG TargetDataRep, PSecBufferDesc pInput,
193 ULONG Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pOutput,
194 ULONG *pfContextAttr, PTimeStamp ptsExpiry)
196 SECURITY_STATUS ret;
197 SecurePackage *package = NULL;
199 TRACE("%p %p %s 0x%08lx %ld %ld %p %ld %p %p %p %p\n", phCredential, phContext,
200 debugstr_a(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
201 Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
203 if (phContext) package = (SecurePackage *)phContext->dwUpper;
204 else if (phCredential) package = (SecurePackage *)phCredential->dwUpper;
206 if (package && package->provider)
208 if (package->provider->fnTableA.InitializeSecurityContextA)
210 ret = package->provider->fnTableA.InitializeSecurityContextA(
211 phCredential, phContext, pszTargetName, fContextReq,
212 Reserved1, TargetDataRep, pInput, Reserved2, phNewContext,
213 pOutput, pfContextAttr, ptsExpiry);
214 if ((ret == SEC_E_OK || ret == SEC_I_CONTINUE_NEEDED) && phNewContext)
215 phNewContext->dwUpper = (ULONG_PTR)package;
217 else
218 ret = SEC_E_UNSUPPORTED_FUNCTION;
220 else
221 ret = SEC_E_INVALID_HANDLE;
222 return ret;
225 /***********************************************************************
226 * InitializeSecurityContextW (SECUR32.@)
228 SECURITY_STATUS WINAPI InitializeSecurityContextW(
229 PCredHandle phCredential, PCtxtHandle phContext,
230 SEC_WCHAR *pszTargetName, ULONG fContextReq,
231 ULONG Reserved1, ULONG TargetDataRep, PSecBufferDesc pInput,
232 ULONG Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pOutput,
233 ULONG *pfContextAttr, PTimeStamp ptsExpiry)
235 SECURITY_STATUS ret;
236 SecurePackage *package = NULL;
238 TRACE("%p %p %s 0x%08lx %ld %ld %p %ld %p %p %p %p\n", phCredential, phContext,
239 debugstr_w(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
240 Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
242 if (phContext) package = (SecurePackage *)phContext->dwUpper;
243 else if (phCredential) package = (SecurePackage *)phCredential->dwUpper;
245 if (package && package->provider)
247 if (package->provider->fnTableW.InitializeSecurityContextW)
249 ret = package->provider->fnTableW.InitializeSecurityContextW(
250 phCredential, phContext, pszTargetName, fContextReq,
251 Reserved1, TargetDataRep, pInput, Reserved2, phNewContext,
252 pOutput, pfContextAttr, ptsExpiry);
253 if ((ret == SEC_E_OK || ret == SEC_I_CONTINUE_NEEDED) && phNewContext)
254 phNewContext->dwUpper = (ULONG_PTR)package;
256 else
257 ret = SEC_E_UNSUPPORTED_FUNCTION;
259 else
260 ret = SEC_E_INVALID_HANDLE;
261 return ret;
264 /***********************************************************************
265 * AcceptSecurityContext (SECUR32.@)
267 SECURITY_STATUS WINAPI AcceptSecurityContext(
268 PCredHandle phCredential, PCtxtHandle phContext, PSecBufferDesc pInput,
269 ULONG fContextReq, ULONG TargetDataRep, PCtxtHandle phNewContext,
270 PSecBufferDesc pOutput, ULONG *pfContextAttr, PTimeStamp ptsExpiry)
272 SECURITY_STATUS ret;
274 TRACE("%p %p %p %ld %ld %p %p %p %p\n", phCredential, phContext, pInput,
275 fContextReq, TargetDataRep, phNewContext, pOutput, pfContextAttr,
276 ptsExpiry);
277 if (phCredential)
279 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
280 if (package && package->provider)
282 if (package->provider->fnTableW.AcceptSecurityContext)
284 ret = package->provider->fnTableW.AcceptSecurityContext(
285 phCredential, phContext, pInput, fContextReq,
286 TargetDataRep, phNewContext, pOutput, pfContextAttr, ptsExpiry);
287 if ((ret == SEC_E_OK || ret == SEC_I_CONTINUE_NEEDED) && phNewContext)
288 phNewContext->dwUpper = (ULONG_PTR)package;
290 else
291 ret = SEC_E_UNSUPPORTED_FUNCTION;
293 else
294 ret = SEC_E_INVALID_HANDLE;
296 else
297 ret = SEC_E_INVALID_HANDLE;
298 return ret;
301 /***********************************************************************
302 * CompleteAuthToken (SECUR32.@)
304 SECURITY_STATUS WINAPI CompleteAuthToken(PCtxtHandle phContext,
305 PSecBufferDesc pToken)
307 SECURITY_STATUS ret;
309 TRACE("%p %p\n", phContext, pToken);
310 if (phContext)
312 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
313 if (package && package->provider)
315 if (package->provider->fnTableW.CompleteAuthToken)
316 ret = package->provider->fnTableW.CompleteAuthToken(phContext, pToken);
317 else
318 ret = SEC_E_UNSUPPORTED_FUNCTION;
320 else
321 ret = SEC_E_INVALID_HANDLE;
323 else
324 ret = SEC_E_INVALID_HANDLE;
325 return ret;
328 /***********************************************************************
329 * DeleteSecurityContext (SECUR32.@)
331 SECURITY_STATUS WINAPI DeleteSecurityContext(PCtxtHandle phContext)
333 SECURITY_STATUS ret;
335 TRACE("%p\n", phContext);
336 if (phContext)
338 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
339 if (package && package->provider && package->provider->fnTableW.DeleteSecurityContext)
340 ret = package->provider->fnTableW.DeleteSecurityContext(phContext);
341 else
342 ret = SEC_E_INVALID_HANDLE;
344 else
345 ret = SEC_E_INVALID_HANDLE;
346 return ret;
349 /***********************************************************************
350 * ApplyControlToken (SECUR32.@)
352 SECURITY_STATUS WINAPI ApplyControlToken(PCtxtHandle phContext,
353 PSecBufferDesc pInput)
355 SECURITY_STATUS ret;
357 TRACE("%p %p\n", phContext, pInput);
358 if (phContext)
360 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
361 if (package && package->provider)
363 if (package->provider->fnTableW.ApplyControlToken)
364 ret = package->provider->fnTableW.ApplyControlToken(phContext, pInput);
365 else
366 ret = SEC_E_UNSUPPORTED_FUNCTION;
368 else
369 ret = SEC_E_INVALID_HANDLE;
371 else
372 ret = SEC_E_INVALID_HANDLE;
373 return ret;
376 /***********************************************************************
377 * QueryContextAttributesA (SECUR32.@)
379 SECURITY_STATUS WINAPI QueryContextAttributesA(PCtxtHandle phContext,
380 ULONG ulAttribute, void *pBuffer)
382 SECURITY_STATUS ret;
384 TRACE("%p %ld %p\n", phContext, ulAttribute, pBuffer);
385 if (phContext)
387 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
388 if (package && package->provider)
390 if (package->provider->fnTableA.QueryContextAttributesA)
391 ret = package->provider->fnTableA.QueryContextAttributesA(phContext, ulAttribute, pBuffer);
392 else
393 ret = SEC_E_UNSUPPORTED_FUNCTION;
395 else
396 ret = SEC_E_INVALID_HANDLE;
398 else
399 ret = SEC_E_INVALID_HANDLE;
400 return ret;
403 /***********************************************************************
404 * QueryContextAttributesW (SECUR32.@)
406 SECURITY_STATUS WINAPI QueryContextAttributesW(PCtxtHandle phContext,
407 ULONG ulAttribute, void *pBuffer)
409 SECURITY_STATUS ret;
411 TRACE("%p %ld %p\n", phContext, ulAttribute, pBuffer);
412 if (phContext)
414 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
415 if (package && package->provider)
417 if (package->provider->fnTableW.QueryContextAttributesW)
418 ret = package->provider->fnTableW.QueryContextAttributesW(phContext, ulAttribute, pBuffer);
419 else
420 ret = SEC_E_UNSUPPORTED_FUNCTION;
422 else
423 ret = SEC_E_INVALID_HANDLE;
425 else
426 ret = SEC_E_INVALID_HANDLE;
427 return ret;
430 /***********************************************************************
431 * ImpersonateSecurityContext (SECUR32.@)
433 SECURITY_STATUS WINAPI ImpersonateSecurityContext(PCtxtHandle phContext)
435 SECURITY_STATUS ret;
437 TRACE("%p\n", phContext);
438 if (phContext)
440 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
441 if (package && package->provider)
443 if (package->provider->fnTableW.ImpersonateSecurityContext)
444 ret = package->provider->fnTableW.ImpersonateSecurityContext(phContext);
445 else
446 ret = SEC_E_UNSUPPORTED_FUNCTION;
448 else
449 ret = SEC_E_INVALID_HANDLE;
451 else
452 ret = SEC_E_INVALID_HANDLE;
453 return ret;
456 /***********************************************************************
457 * RevertSecurityContext (SECUR32.@)
459 SECURITY_STATUS WINAPI RevertSecurityContext(PCtxtHandle phContext)
461 SECURITY_STATUS ret;
463 TRACE("%p\n", phContext);
464 if (phContext)
466 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
467 if (package && package->provider)
469 if (package->provider->fnTableW.RevertSecurityContext)
470 ret = package->provider->fnTableW.RevertSecurityContext(phContext);
471 else
472 ret = SEC_E_UNSUPPORTED_FUNCTION;
474 else
475 ret = SEC_E_INVALID_HANDLE;
477 else
478 ret = SEC_E_INVALID_HANDLE;
479 return ret;
482 /***********************************************************************
483 * MakeSignature (SECUR32.@)
485 SECURITY_STATUS WINAPI MakeSignature(PCtxtHandle phContext, ULONG fQOP,
486 PSecBufferDesc pMessage, ULONG MessageSeqNo)
488 SECURITY_STATUS ret;
490 TRACE("%p %ld %p %ld\n", phContext, fQOP, pMessage, MessageSeqNo);
491 if (phContext)
493 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
494 if (package && package->provider)
496 if (package->provider->fnTableW.MakeSignature)
497 ret = package->provider->fnTableW.MakeSignature(phContext, fQOP, pMessage, MessageSeqNo);
498 else
499 ret = SEC_E_UNSUPPORTED_FUNCTION;
501 else
502 ret = SEC_E_INVALID_HANDLE;
504 else
505 ret = SEC_E_INVALID_HANDLE;
506 return ret;
509 /***********************************************************************
510 * VerifySignature (SECUR32.@)
512 SECURITY_STATUS WINAPI VerifySignature(PCtxtHandle phContext,
513 PSecBufferDesc pMessage, ULONG MessageSeqNo, PULONG pfQOP)
515 SECURITY_STATUS ret;
517 TRACE("%p %p %ld %p\n", phContext, pMessage, MessageSeqNo, pfQOP);
518 if (phContext)
520 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
521 if (package && package->provider)
523 if (package->provider->fnTableW.VerifySignature)
524 ret = package->provider->fnTableW.VerifySignature(phContext, pMessage, MessageSeqNo, pfQOP);
525 else
526 ret = SEC_E_UNSUPPORTED_FUNCTION;
528 else
529 ret = SEC_E_INVALID_HANDLE;
531 else
532 ret = SEC_E_INVALID_HANDLE;
533 return ret;
536 /***********************************************************************
537 * QuerySecurityPackageInfoA (SECUR32.@)
539 SECURITY_STATUS WINAPI QuerySecurityPackageInfoA(SEC_CHAR *pszPackageName,
540 PSecPkgInfoA *ppPackageInfo)
542 SECURITY_STATUS ret;
544 TRACE("%s %p\n", debugstr_a(pszPackageName), ppPackageInfo);
545 if (pszPackageName)
547 SecurePackage *package = SECUR32_findPackageA(pszPackageName);
549 if (package)
551 size_t bytesNeeded = sizeof(SecPkgInfoA);
552 int nameLen = 0, commentLen = 0;
554 if (package->infoW.Name)
556 nameLen = WideCharToMultiByte(CP_ACP, 0,
557 package->infoW.Name, -1, NULL, 0, NULL, NULL);
558 bytesNeeded += nameLen;
560 if (package->infoW.Comment)
562 commentLen = WideCharToMultiByte(CP_ACP, 0,
563 package->infoW.Comment, -1, NULL, 0, NULL, NULL);
564 bytesNeeded += commentLen;
566 /* freed with FreeContextBuffer */
567 if ((*ppPackageInfo = RtlAllocateHeap(GetProcessHeap(), 0, bytesNeeded)))
569 PSTR nextString = (PSTR)((PBYTE)*ppPackageInfo +
570 sizeof(SecPkgInfoA));
572 memcpy(*ppPackageInfo, &package->infoW, sizeof(package->infoW));
573 if (package->infoW.Name)
575 (*ppPackageInfo)->Name = nextString;
576 nextString += WideCharToMultiByte(CP_ACP, 0,
577 package->infoW.Name, -1, nextString, nameLen, NULL, NULL);
579 else
580 (*ppPackageInfo)->Name = NULL;
581 if (package->infoW.Comment)
583 (*ppPackageInfo)->Comment = nextString;
584 nextString += WideCharToMultiByte(CP_ACP, 0,
585 package->infoW.Comment, -1, nextString, commentLen, NULL,
586 NULL);
588 else
589 (*ppPackageInfo)->Comment = NULL;
590 ret = SEC_E_OK;
592 else
593 ret = SEC_E_INSUFFICIENT_MEMORY;
595 else
596 ret = SEC_E_SECPKG_NOT_FOUND;
598 else
599 ret = SEC_E_SECPKG_NOT_FOUND;
600 return ret;
603 /***********************************************************************
604 * QuerySecurityPackageInfoW (SECUR32.@)
606 SECURITY_STATUS WINAPI QuerySecurityPackageInfoW(SEC_WCHAR *pszPackageName,
607 PSecPkgInfoW *ppPackageInfo)
609 SECURITY_STATUS ret;
610 SecurePackage *package = SECUR32_findPackageW(pszPackageName);
612 TRACE("%s %p\n", debugstr_w(pszPackageName), ppPackageInfo);
613 if (package)
615 size_t bytesNeeded = sizeof(SecPkgInfoW);
616 int nameLen = 0, commentLen = 0;
618 if (package->infoW.Name)
620 nameLen = lstrlenW(package->infoW.Name) + 1;
621 bytesNeeded += nameLen * sizeof(WCHAR);
623 if (package->infoW.Comment)
625 commentLen = lstrlenW(package->infoW.Comment) + 1;
626 bytesNeeded += commentLen * sizeof(WCHAR);
628 /* freed with FreeContextBuffer */
629 if ((*ppPackageInfo = RtlAllocateHeap(GetProcessHeap(), 0, bytesNeeded)))
631 PWSTR nextString = (PWSTR)((PBYTE)*ppPackageInfo +
632 sizeof(SecPkgInfoW));
634 **ppPackageInfo = package->infoW;
635 if (package->infoW.Name)
637 (*ppPackageInfo)->Name = nextString;
638 lstrcpynW(nextString, package->infoW.Name, nameLen);
639 nextString += nameLen;
641 else
642 (*ppPackageInfo)->Name = NULL;
643 if (package->infoW.Comment)
645 (*ppPackageInfo)->Comment = nextString;
646 lstrcpynW(nextString, package->infoW.Comment, commentLen);
648 else
649 (*ppPackageInfo)->Comment = NULL;
650 ret = SEC_E_OK;
652 else
653 ret = SEC_E_INSUFFICIENT_MEMORY;
655 else
656 ret = SEC_E_SECPKG_NOT_FOUND;
657 return ret;
660 /***********************************************************************
661 * ExportSecurityContext (SECUR32.@)
663 SECURITY_STATUS WINAPI ExportSecurityContext(PCtxtHandle phContext,
664 ULONG fFlags, PSecBuffer pPackedContext, void **pToken)
666 SECURITY_STATUS ret;
668 TRACE("%p %ld %p %p\n", phContext, fFlags, pPackedContext, pToken);
669 if (phContext)
671 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
672 if (package && package->provider)
674 if (package->provider->fnTableW.ExportSecurityContext)
675 ret = package->provider->fnTableW.ExportSecurityContext(phContext, fFlags, pPackedContext, pToken);
676 else
677 ret = SEC_E_UNSUPPORTED_FUNCTION;
679 else
680 ret = SEC_E_INVALID_HANDLE;
682 else
683 ret = SEC_E_INVALID_HANDLE;
684 return ret;
687 /***********************************************************************
688 * ImportSecurityContextA (SECUR32.@)
690 SECURITY_STATUS WINAPI ImportSecurityContextA(SEC_CHAR *pszPackage,
691 PSecBuffer pPackedContext, void *Token, PCtxtHandle phContext)
693 SECURITY_STATUS ret;
694 SecurePackage *package = SECUR32_findPackageA(pszPackage);
696 TRACE("%s %p %p %p\n", debugstr_a(pszPackage), pPackedContext, Token, phContext);
697 if (package && package->provider)
699 if (package->provider->fnTableA.ImportSecurityContextA)
701 ret = package->provider->fnTableA.ImportSecurityContextA(pszPackage, pPackedContext, Token, phContext);
702 if (ret == SEC_E_OK)
703 phContext->dwUpper = (ULONG_PTR)package;
705 else
706 ret = SEC_E_UNSUPPORTED_FUNCTION;
708 else
709 ret = SEC_E_SECPKG_NOT_FOUND;
710 return ret;
714 /***********************************************************************
715 * ImportSecurityContextW (SECUR32.@)
717 SECURITY_STATUS WINAPI ImportSecurityContextW(SEC_WCHAR *pszPackage,
718 PSecBuffer pPackedContext, void *Token, PCtxtHandle phContext)
720 SECURITY_STATUS ret;
721 SecurePackage *package = SECUR32_findPackageW(pszPackage);
723 TRACE("%s %p %p %p\n", debugstr_w(pszPackage), pPackedContext, Token, phContext);
724 if (package && package->provider)
726 if (package->provider->fnTableW.ImportSecurityContextW)
728 ret = package->provider->fnTableW.ImportSecurityContextW(pszPackage, pPackedContext, Token, phContext);
729 if (ret == SEC_E_OK)
730 phContext->dwUpper = (ULONG_PTR)package;
732 else
733 ret = SEC_E_UNSUPPORTED_FUNCTION;
735 else
736 ret = SEC_E_SECPKG_NOT_FOUND;
737 return ret;
740 /***********************************************************************
741 * AddCredentialsA (SECUR32.@)
743 SECURITY_STATUS WINAPI AddCredentialsA(PCredHandle hCredentials,
744 SEC_CHAR *pszPrincipal, SEC_CHAR *pszPackage, ULONG fCredentialUse,
745 void *pAuthData, SEC_GET_KEY_FN pGetKeyFn, void *pvGetKeyArgument,
746 PTimeStamp ptsExpiry)
748 SECURITY_STATUS ret;
750 TRACE("%p %s %s %ld %p %p %p %p\n", hCredentials, debugstr_a(pszPrincipal),
751 debugstr_a(pszPackage), fCredentialUse, pAuthData, pGetKeyFn,
752 pvGetKeyArgument, ptsExpiry);
753 if (hCredentials)
755 SecurePackage *package = (SecurePackage *)hCredentials->dwUpper;
756 if (package && package->provider)
758 if (package->provider->fnTableA.AddCredentialsA)
759 ret = package->provider->fnTableA.AddCredentialsA(hCredentials, pszPrincipal, pszPackage,
760 fCredentialUse, pAuthData, pGetKeyFn,
761 pvGetKeyArgument, ptsExpiry);
762 else
763 ret = SEC_E_UNSUPPORTED_FUNCTION;
765 else
766 ret = SEC_E_INVALID_HANDLE;
768 else
769 ret = SEC_E_INVALID_HANDLE;
770 return ret;
773 /***********************************************************************
774 * AddCredentialsW (SECUR32.@)
776 SECURITY_STATUS WINAPI AddCredentialsW(PCredHandle hCredentials,
777 SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, ULONG fCredentialUse,
778 void *pAuthData, SEC_GET_KEY_FN pGetKeyFn, void *pvGetKeyArgument,
779 PTimeStamp ptsExpiry)
781 SECURITY_STATUS ret;
783 TRACE("%p %s %s %ld %p %p %p %p\n", hCredentials, debugstr_w(pszPrincipal),
784 debugstr_w(pszPackage), fCredentialUse, pAuthData, pGetKeyFn,
785 pvGetKeyArgument, ptsExpiry);
786 if (hCredentials)
788 SecurePackage *package = (SecurePackage *)hCredentials->dwUpper;
789 if (package && package->provider)
791 if (package->provider->fnTableW.AddCredentialsW)
792 ret = package->provider->fnTableW.AddCredentialsW(hCredentials, pszPrincipal, pszPackage,
793 fCredentialUse, pAuthData, pGetKeyFn,
794 pvGetKeyArgument, ptsExpiry);
795 else
796 ret = SEC_E_UNSUPPORTED_FUNCTION;
798 else
799 ret = SEC_E_INVALID_HANDLE;
801 else
802 ret = SEC_E_INVALID_HANDLE;
803 return ret;
806 /***********************************************************************
807 * QuerySecurityContextToken (SECUR32.@)
809 SECURITY_STATUS WINAPI QuerySecurityContextToken(PCtxtHandle phContext,
810 HANDLE *phToken)
812 SECURITY_STATUS ret;
814 TRACE("%p %p\n", phContext, phToken);
815 if (phContext)
817 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
818 if (package && package->provider)
820 if (package->provider->fnTableW.QuerySecurityContextToken)
821 ret = package->provider->fnTableW.QuerySecurityContextToken(phContext, phToken);
822 else
823 ret = SEC_E_UNSUPPORTED_FUNCTION;
825 else
826 ret = SEC_E_INVALID_HANDLE;
828 else
829 ret = SEC_E_INVALID_HANDLE;
830 return ret;
833 /***********************************************************************
834 * EncryptMessage (SECUR32.@)
836 SECURITY_STATUS WINAPI EncryptMessage(PCtxtHandle phContext, ULONG fQOP,
837 PSecBufferDesc pMessage, ULONG MessageSeqNo)
839 SECURITY_STATUS ret;
841 TRACE("%p %ld %p %ld\n", phContext, fQOP, pMessage, MessageSeqNo);
842 if (phContext)
844 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
845 if (package && package->provider)
847 if (package->provider->fnTableW.EncryptMessage)
848 ret = package->provider->fnTableW.EncryptMessage(phContext, fQOP, pMessage, MessageSeqNo);
849 else
850 ret = SEC_E_UNSUPPORTED_FUNCTION;
852 else
853 ret = SEC_E_INVALID_HANDLE;
855 else
856 ret = SEC_E_INVALID_HANDLE;
857 return ret;
860 /***********************************************************************
861 * DecryptMessage (SECUR32.@)
863 SECURITY_STATUS WINAPI DecryptMessage(PCtxtHandle phContext,
864 PSecBufferDesc pMessage, ULONG MessageSeqNo, PULONG pfQOP)
866 SECURITY_STATUS ret;
868 TRACE("%p %p %ld %p\n", phContext, pMessage, MessageSeqNo, pfQOP);
869 if (phContext)
871 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
872 if (package && package->provider)
874 if (package->provider->fnTableW.DecryptMessage)
875 ret = package->provider->fnTableW.DecryptMessage(phContext, pMessage, MessageSeqNo, pfQOP);
876 else
877 ret = SEC_E_UNSUPPORTED_FUNCTION;
879 else
880 ret = SEC_E_INVALID_HANDLE;
882 else
883 ret = SEC_E_INVALID_HANDLE;
884 return ret;
887 /***********************************************************************
888 * SetContextAttributesA (SECUR32.@)
890 SECURITY_STATUS WINAPI SetContextAttributesA(PCtxtHandle phContext,
891 ULONG ulAttribute, void *pBuffer, ULONG cbBuffer)
893 SECURITY_STATUS ret;
895 TRACE("%p %ld %p %ld\n", phContext, ulAttribute, pBuffer, cbBuffer);
896 if (phContext)
898 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
899 if (package && package->provider)
901 if (package->provider->fnTableA.SetContextAttributesA)
902 ret = package->provider->fnTableA.SetContextAttributesA(phContext, ulAttribute, pBuffer, cbBuffer);
903 else
904 ret = SEC_E_UNSUPPORTED_FUNCTION;
906 else
907 ret = SEC_E_INVALID_HANDLE;
909 else
910 ret = SEC_E_INVALID_HANDLE;
911 return ret;
914 /***********************************************************************
915 * SetContextAttributesW (SECUR32.@)
917 SECURITY_STATUS WINAPI SetContextAttributesW(PCtxtHandle phContext,
918 ULONG ulAttribute, void *pBuffer, ULONG cbBuffer)
920 SECURITY_STATUS ret;
922 TRACE("%p %ld %p %ld\n", phContext, ulAttribute, pBuffer, cbBuffer);
923 if (phContext)
925 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
926 if (package && package->provider)
928 if (package->provider->fnTableW.SetContextAttributesW)
929 ret = package->provider->fnTableW.SetContextAttributesW(phContext, ulAttribute, pBuffer, cbBuffer);
930 else
931 ret = SEC_E_UNSUPPORTED_FUNCTION;
933 else
934 ret = SEC_E_INVALID_HANDLE;
936 else
937 ret = SEC_E_INVALID_HANDLE;
938 return ret;