wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / secur32 / wrapper.c
blob67c5b5a72154e7274d0c700c75c29f568ed14c78
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
19 #include <stdarg.h>
20 #include "windef.h"
21 #include "winbase.h"
22 #include "winnls.h"
23 #include "sspi.h"
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 (stored in phSec->dwLower).
32 * SecHandle is equivalent to both a CredHandle and a CtxtHandle.
34 static SECURITY_STATUS SECUR32_makeSecHandle(PSecHandle phSec,
35 SecurePackage *package, PSecHandle realHandle)
37 SECURITY_STATUS ret;
39 TRACE("%p %p %p\n", phSec, package, realHandle);
41 if (phSec && package && realHandle)
43 PSecHandle newSec = heap_alloc(sizeof(SecHandle));
45 if (newSec)
47 *newSec = *realHandle;
48 phSec->dwUpper = (ULONG_PTR)package;
49 phSec->dwLower = (ULONG_PTR)newSec;
50 ret = SEC_E_OK;
52 else
53 ret = SEC_E_INSUFFICIENT_MEMORY;
55 else
56 ret = SEC_E_INVALID_HANDLE;
57 return ret;
60 /***********************************************************************
61 * AcquireCredentialsHandleA (SECUR32.@)
63 SECURITY_STATUS WINAPI AcquireCredentialsHandleA(
64 SEC_CHAR *pszPrincipal, SEC_CHAR *pszPackage, ULONG fCredentialsUse,
65 PLUID pvLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn,
66 PVOID pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
68 SECURITY_STATUS ret;
70 TRACE("%s %s %d %p %p %p %p %p %p\n", debugstr_a(pszPrincipal),
71 debugstr_a(pszPackage), fCredentialsUse, pvLogonID, pAuthData, pGetKeyFn,
72 pvGetKeyArgument, phCredential, ptsExpiry);
73 if (pszPackage)
75 SecurePackage *package = SECUR32_findPackageA(pszPackage);
77 if (package && package->provider)
79 if (package->provider->fnTableA.AcquireCredentialsHandleA)
81 CredHandle myCred;
83 ret = package->provider->fnTableA.AcquireCredentialsHandleA(
84 pszPrincipal, pszPackage, fCredentialsUse, pvLogonID,
85 pAuthData, pGetKeyFn, pvGetKeyArgument, &myCred,
86 ptsExpiry);
87 if (ret == SEC_E_OK)
89 ret = SECUR32_makeSecHandle(phCredential, package, &myCred);
90 if (ret != SEC_E_OK)
91 package->provider->fnTableW.FreeCredentialsHandle(
92 &myCred);
95 else
96 ret = SEC_E_UNSUPPORTED_FUNCTION;
98 else
99 ret = SEC_E_SECPKG_NOT_FOUND;
101 else
102 ret = SEC_E_SECPKG_NOT_FOUND;
103 return ret;
106 /***********************************************************************
107 * AcquireCredentialsHandleW (SECUR32.@)
109 SECURITY_STATUS WINAPI AcquireCredentialsHandleW(
110 SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, ULONG fCredentialsUse,
111 PLUID pvLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn,
112 PVOID pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
114 SECURITY_STATUS ret;
116 TRACE("%s %s %d %p %p %p %p %p %p\n", debugstr_w(pszPrincipal),
117 debugstr_w(pszPackage), fCredentialsUse, pvLogonID, pAuthData, pGetKeyFn,
118 pvGetKeyArgument, phCredential, ptsExpiry);
119 if (pszPackage)
121 SecurePackage *package = SECUR32_findPackageW(pszPackage);
123 if (package && package->provider)
125 if (package->provider->fnTableW.AcquireCredentialsHandleW)
127 CredHandle myCred;
129 ret = package->provider->fnTableW.AcquireCredentialsHandleW(
130 pszPrincipal, pszPackage, fCredentialsUse, pvLogonID,
131 pAuthData, pGetKeyFn, pvGetKeyArgument, &myCred,
132 ptsExpiry);
133 if (ret == SEC_E_OK)
135 ret = SECUR32_makeSecHandle(phCredential, package, &myCred);
136 if (ret != SEC_E_OK)
137 package->provider->fnTableW.FreeCredentialsHandle(
138 &myCred);
141 else
142 ret = SEC_E_UNSUPPORTED_FUNCTION;
144 else
145 ret = SEC_E_SECPKG_NOT_FOUND;
147 else
148 ret = SEC_E_SECPKG_NOT_FOUND;
149 return ret;
152 /***********************************************************************
153 * FreeCredentialsHandle (SECUR32.@)
155 SECURITY_STATUS WINAPI FreeCredentialsHandle(
156 PCredHandle phCredential)
158 SECURITY_STATUS ret;
160 TRACE("%p\n", phCredential);
161 if (phCredential)
163 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
164 PCredHandle cred = (PCredHandle)phCredential->dwLower;
166 if (package && package->provider &&
167 package->provider->fnTableW.FreeCredentialsHandle)
168 ret = package->provider->fnTableW.FreeCredentialsHandle(cred);
169 else
170 ret = SEC_E_INVALID_HANDLE;
171 heap_free(cred);
173 else
174 ret = SEC_E_INVALID_HANDLE;
175 return ret;
178 /***********************************************************************
179 * QueryCredentialsAttributesA (SECUR32.@)
181 SECURITY_STATUS WINAPI QueryCredentialsAttributesA(
182 PCredHandle phCredential, ULONG ulAttribute, void *pBuffer)
184 SECURITY_STATUS ret;
186 TRACE("%p %d %p\n", phCredential, ulAttribute, pBuffer);
187 if (phCredential)
189 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
190 PCredHandle cred = (PCredHandle)phCredential->dwLower;
192 if (package && package->provider)
194 if (package->provider->fnTableA.QueryCredentialsAttributesA)
195 ret = package->provider->fnTableA.QueryCredentialsAttributesA(
196 cred, ulAttribute, pBuffer);
197 else
198 ret = SEC_E_UNSUPPORTED_FUNCTION;
200 else
201 ret = SEC_E_INVALID_HANDLE;
203 else
204 ret = SEC_E_INVALID_HANDLE;
205 return ret;
208 /***********************************************************************
209 * QueryCredentialsAttributesW (SECUR32.@)
211 SECURITY_STATUS WINAPI QueryCredentialsAttributesW(
212 PCredHandle phCredential, ULONG ulAttribute, void *pBuffer)
214 SECURITY_STATUS ret;
216 TRACE("%p %d %p\n", phCredential, ulAttribute, pBuffer);
217 if (phCredential)
219 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
220 PCredHandle cred = (PCredHandle)phCredential->dwLower;
222 if (package && package->provider)
224 if (package->provider->fnTableW.QueryCredentialsAttributesW)
225 ret = package->provider->fnTableW.QueryCredentialsAttributesW(
226 cred, ulAttribute, pBuffer);
227 else
228 ret = SEC_E_UNSUPPORTED_FUNCTION;
230 else
231 ret = SEC_E_INVALID_HANDLE;
233 else
234 ret = SEC_E_INVALID_HANDLE;
235 return ret;
238 /***********************************************************************
239 * InitializeSecurityContextA (SECUR32.@)
241 SECURITY_STATUS WINAPI InitializeSecurityContextA(
242 PCredHandle phCredential, PCtxtHandle phContext,
243 SEC_CHAR *pszTargetName, ULONG fContextReq,
244 ULONG Reserved1, ULONG TargetDataRep, PSecBufferDesc pInput,
245 ULONG Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pOutput,
246 ULONG *pfContextAttr, PTimeStamp ptsExpiry)
248 SECURITY_STATUS ret;
249 SecurePackage *package = NULL;
250 PCredHandle cred = NULL;
251 PCredHandle ctxt = NULL;
253 TRACE("%p %p %s 0x%08x %d %d %p %d %p %p %p %p\n", phCredential, phContext,
254 debugstr_a(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
255 Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
257 if (phContext)
259 package = (SecurePackage *)phContext->dwUpper;
260 ctxt = (PCtxtHandle)phContext->dwLower;
262 if (phCredential)
264 package = (SecurePackage *)phCredential->dwUpper;
265 cred = (PCredHandle)phCredential->dwLower;
268 if (package && package->provider)
270 if (package->provider->fnTableA.InitializeSecurityContextA)
272 CtxtHandle myCtxt;
274 if (phContext)
276 PCtxtHandle realCtxt = (PCtxtHandle)phContext->dwLower;
277 myCtxt.dwUpper = realCtxt->dwUpper;
278 myCtxt.dwLower = realCtxt->dwLower;
281 ret = package->provider->fnTableA.InitializeSecurityContextA(
282 cred, ctxt, pszTargetName, fContextReq,
283 Reserved1, TargetDataRep, pInput, Reserved2, phNewContext ? &myCtxt : NULL,
284 pOutput, pfContextAttr, ptsExpiry);
285 if ((ret == SEC_E_OK || ret == SEC_I_CONTINUE_NEEDED) &&
286 phNewContext && phNewContext != phContext)
288 SECURITY_STATUS ret2;
289 ret2 = SECUR32_makeSecHandle(phNewContext, package, &myCtxt);
290 if (ret2 != SEC_E_OK)
291 package->provider->fnTableA.DeleteSecurityContext(&myCtxt);
294 else
295 ret = SEC_E_UNSUPPORTED_FUNCTION;
297 else
298 ret = SEC_E_INVALID_HANDLE;
299 return ret;
302 /***********************************************************************
303 * InitializeSecurityContextW (SECUR32.@)
305 SECURITY_STATUS WINAPI InitializeSecurityContextW(
306 PCredHandle phCredential, PCtxtHandle phContext,
307 SEC_WCHAR *pszTargetName, ULONG fContextReq,
308 ULONG Reserved1, ULONG TargetDataRep, PSecBufferDesc pInput,
309 ULONG Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pOutput,
310 ULONG *pfContextAttr, PTimeStamp ptsExpiry)
312 SECURITY_STATUS ret;
313 SecurePackage *package = NULL;
314 PCredHandle cred = NULL;
315 PCredHandle ctxt = NULL;
317 TRACE("%p %p %s 0x%08x %d %d %p %d %p %p %p %p\n", phCredential, phContext,
318 debugstr_w(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
319 Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
321 if (phContext)
323 package = (SecurePackage *)phContext->dwUpper;
324 ctxt = (PCtxtHandle)phContext->dwLower;
326 if (phCredential)
328 package = (SecurePackage *)phCredential->dwUpper;
329 cred = (PCredHandle)phCredential->dwLower;
332 if (package && package->provider)
334 if (package->provider->fnTableW.InitializeSecurityContextW)
336 CtxtHandle myCtxt;
338 if (phContext)
340 PCtxtHandle realCtxt = (PCtxtHandle)phContext->dwLower;
341 myCtxt.dwUpper = realCtxt->dwUpper;
342 myCtxt.dwLower = realCtxt->dwLower;
345 ret = package->provider->fnTableW.InitializeSecurityContextW(
346 cred, ctxt, pszTargetName, fContextReq,
347 Reserved1, TargetDataRep, pInput, Reserved2, phNewContext ? &myCtxt : NULL,
348 pOutput, pfContextAttr, ptsExpiry);
349 if ((ret == SEC_E_OK || ret == SEC_I_CONTINUE_NEEDED) &&
350 phNewContext && phNewContext != phContext)
352 SECURITY_STATUS ret2;
353 ret2 = SECUR32_makeSecHandle(phNewContext, package, &myCtxt);
354 if (ret2 != SEC_E_OK)
355 package->provider->fnTableW.DeleteSecurityContext(&myCtxt);
358 else
359 ret = SEC_E_UNSUPPORTED_FUNCTION;
361 else
362 ret = SEC_E_INVALID_HANDLE;
363 return ret;
366 /***********************************************************************
367 * AcceptSecurityContext (SECUR32.@)
369 SECURITY_STATUS WINAPI AcceptSecurityContext(
370 PCredHandle phCredential, PCtxtHandle phContext, PSecBufferDesc pInput,
371 ULONG fContextReq, ULONG TargetDataRep, PCtxtHandle phNewContext,
372 PSecBufferDesc pOutput, ULONG *pfContextAttr, PTimeStamp ptsExpiry)
374 SECURITY_STATUS ret;
376 TRACE("%p %p %p %d %d %p %p %p %p\n", phCredential, phContext, pInput,
377 fContextReq, TargetDataRep, phNewContext, pOutput, pfContextAttr,
378 ptsExpiry);
379 if (phCredential)
381 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
382 PCredHandle cred = (PCredHandle)phCredential->dwLower;
384 if (package && package->provider)
386 if (package->provider->fnTableW.AcceptSecurityContext)
388 CtxtHandle myCtxt;
390 if(phContext)
392 PCtxtHandle realCtxt = (PCtxtHandle)phContext->dwLower;
393 TRACE("realCtx: %p\n", realCtxt);
394 myCtxt.dwUpper = realCtxt->dwUpper;
395 myCtxt.dwLower = realCtxt->dwLower;
398 ret = package->provider->fnTableW.AcceptSecurityContext(
399 cred, phContext ? &myCtxt : NULL, pInput, fContextReq,
400 TargetDataRep, &myCtxt, pOutput, pfContextAttr, ptsExpiry);
401 if ((ret == SEC_E_OK || ret == SEC_I_CONTINUE_NEEDED) &&
402 phNewContext && phNewContext != phContext)
404 SECURITY_STATUS ret2;
405 ret2 = SECUR32_makeSecHandle(phNewContext, package, &myCtxt);
406 if (ret2 != SEC_E_OK)
407 package->provider->fnTableW.DeleteSecurityContext(
408 &myCtxt);
411 else
412 ret = SEC_E_UNSUPPORTED_FUNCTION;
414 else
415 ret = SEC_E_INVALID_HANDLE;
417 else
418 ret = SEC_E_INVALID_HANDLE;
419 return ret;
422 /***********************************************************************
423 * CompleteAuthToken (SECUR32.@)
425 SECURITY_STATUS WINAPI CompleteAuthToken(PCtxtHandle phContext,
426 PSecBufferDesc pToken)
428 SECURITY_STATUS ret;
430 TRACE("%p %p\n", phContext, pToken);
431 if (phContext)
433 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
434 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
436 if (package && package->provider)
438 if (package->provider->fnTableW.CompleteAuthToken)
439 ret = package->provider->fnTableW.CompleteAuthToken(ctxt,
440 pToken);
441 else
442 ret = SEC_E_UNSUPPORTED_FUNCTION;
444 else
445 ret = SEC_E_INVALID_HANDLE;
447 else
448 ret = SEC_E_INVALID_HANDLE;
449 return ret;
452 /***********************************************************************
453 * DeleteSecurityContext (SECUR32.@)
455 SECURITY_STATUS WINAPI DeleteSecurityContext(PCtxtHandle phContext)
457 SECURITY_STATUS ret;
459 TRACE("%p\n", phContext);
460 if (phContext)
462 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
463 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
465 if (package && package->provider &&
466 package->provider->fnTableW.DeleteSecurityContext)
467 ret = package->provider->fnTableW.DeleteSecurityContext(ctxt);
468 else
469 ret = SEC_E_INVALID_HANDLE;
470 heap_free(ctxt);
472 else
473 ret = SEC_E_INVALID_HANDLE;
474 return ret;
477 /***********************************************************************
478 * ApplyControlToken (SECUR32.@)
480 SECURITY_STATUS WINAPI ApplyControlToken(PCtxtHandle phContext,
481 PSecBufferDesc pInput)
483 SECURITY_STATUS ret;
485 TRACE("%p %p\n", phContext, pInput);
486 if (phContext)
488 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
489 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
491 if (package && package->provider)
493 if (package->provider->fnTableW.ApplyControlToken)
494 ret = package->provider->fnTableW.ApplyControlToken(
495 ctxt, pInput);
496 else
497 ret = SEC_E_UNSUPPORTED_FUNCTION;
499 else
500 ret = SEC_E_INVALID_HANDLE;
502 else
503 ret = SEC_E_INVALID_HANDLE;
504 return ret;
507 /***********************************************************************
508 * QueryContextAttributesA (SECUR32.@)
510 SECURITY_STATUS WINAPI QueryContextAttributesA(PCtxtHandle phContext,
511 ULONG ulAttribute, void *pBuffer)
513 SECURITY_STATUS ret;
515 TRACE("%p %d %p\n", phContext, ulAttribute, pBuffer);
516 if (phContext)
518 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
519 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
521 if (package && package->provider)
523 if (package->provider->fnTableA.QueryContextAttributesA)
524 ret = package->provider->fnTableA.QueryContextAttributesA(
525 ctxt, ulAttribute, pBuffer);
526 else
527 ret = SEC_E_UNSUPPORTED_FUNCTION;
529 else
530 ret = SEC_E_INVALID_HANDLE;
532 else
533 ret = SEC_E_INVALID_HANDLE;
534 return ret;
537 /***********************************************************************
538 * QueryContextAttributesW (SECUR32.@)
540 SECURITY_STATUS WINAPI QueryContextAttributesW(PCtxtHandle phContext,
541 ULONG ulAttribute, void *pBuffer)
543 SECURITY_STATUS ret;
545 TRACE("%p %d %p\n", phContext, ulAttribute, pBuffer);
546 if (phContext)
548 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
549 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
551 if (package && package->provider)
553 if (package->provider->fnTableW.QueryContextAttributesW)
554 ret = package->provider->fnTableW.QueryContextAttributesW(
555 ctxt, ulAttribute, pBuffer);
556 else
557 ret = SEC_E_UNSUPPORTED_FUNCTION;
559 else
560 ret = SEC_E_INVALID_HANDLE;
562 else
563 ret = SEC_E_INVALID_HANDLE;
564 return ret;
567 /***********************************************************************
568 * ImpersonateSecurityContext (SECUR32.@)
570 SECURITY_STATUS WINAPI ImpersonateSecurityContext(PCtxtHandle phContext)
572 SECURITY_STATUS ret;
574 TRACE("%p\n", phContext);
575 if (phContext)
577 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
578 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
580 if (package && package->provider)
582 if (package->provider->fnTableW.ImpersonateSecurityContext)
583 ret = package->provider->fnTableW.ImpersonateSecurityContext(
584 ctxt);
585 else
586 ret = SEC_E_UNSUPPORTED_FUNCTION;
588 else
589 ret = SEC_E_INVALID_HANDLE;
591 else
592 ret = SEC_E_INVALID_HANDLE;
593 return ret;
596 /***********************************************************************
597 * RevertSecurityContext (SECUR32.@)
599 SECURITY_STATUS WINAPI RevertSecurityContext(PCtxtHandle phContext)
601 SECURITY_STATUS ret;
603 TRACE("%p\n", phContext);
604 if (phContext)
606 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
607 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
609 if (package && package->provider)
611 if (package->provider->fnTableW.RevertSecurityContext)
612 ret = package->provider->fnTableW.RevertSecurityContext(
613 ctxt);
614 else
615 ret = SEC_E_UNSUPPORTED_FUNCTION;
617 else
618 ret = SEC_E_INVALID_HANDLE;
620 else
621 ret = SEC_E_INVALID_HANDLE;
622 return ret;
625 /***********************************************************************
626 * MakeSignature (SECUR32.@)
628 SECURITY_STATUS WINAPI MakeSignature(PCtxtHandle phContext, ULONG fQOP,
629 PSecBufferDesc pMessage, ULONG MessageSeqNo)
631 SECURITY_STATUS ret;
633 TRACE("%p %d %p %d\n", phContext, fQOP, pMessage, MessageSeqNo);
634 if (phContext)
636 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
637 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
639 if (package && package->provider)
641 if (package->provider->fnTableW.MakeSignature)
642 ret = package->provider->fnTableW.MakeSignature(
643 ctxt, fQOP, pMessage, MessageSeqNo);
644 else
645 ret = SEC_E_UNSUPPORTED_FUNCTION;
647 else
648 ret = SEC_E_INVALID_HANDLE;
650 else
651 ret = SEC_E_INVALID_HANDLE;
652 return ret;
655 /***********************************************************************
656 * VerifySignature (SECUR32.@)
658 SECURITY_STATUS WINAPI VerifySignature(PCtxtHandle phContext,
659 PSecBufferDesc pMessage, ULONG MessageSeqNo, PULONG pfQOP)
661 SECURITY_STATUS ret;
663 TRACE("%p %p %d %p\n", phContext, pMessage, MessageSeqNo, pfQOP);
664 if (phContext)
666 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
667 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
669 if (package && package->provider)
671 if (package->provider->fnTableW.VerifySignature)
672 ret = package->provider->fnTableW.VerifySignature(
673 ctxt, pMessage, MessageSeqNo, pfQOP);
674 else
675 ret = SEC_E_UNSUPPORTED_FUNCTION;
677 else
678 ret = SEC_E_INVALID_HANDLE;
680 else
681 ret = SEC_E_INVALID_HANDLE;
682 return ret;
685 /***********************************************************************
686 * QuerySecurityPackageInfoA (SECUR32.@)
688 SECURITY_STATUS WINAPI QuerySecurityPackageInfoA(SEC_CHAR *pszPackageName,
689 PSecPkgInfoA *ppPackageInfo)
691 SECURITY_STATUS ret;
693 TRACE("%s %p\n", debugstr_a(pszPackageName), ppPackageInfo);
694 if (pszPackageName)
696 SecurePackage *package = SECUR32_findPackageA(pszPackageName);
698 if (package)
700 size_t bytesNeeded = sizeof(SecPkgInfoA);
701 int nameLen = 0, commentLen = 0;
703 if (package->infoW.Name)
705 nameLen = WideCharToMultiByte(CP_ACP, 0,
706 package->infoW.Name, -1, NULL, 0, NULL, NULL);
707 bytesNeeded += nameLen;
709 if (package->infoW.Comment)
711 commentLen = WideCharToMultiByte(CP_ACP, 0,
712 package->infoW.Comment, -1, NULL, 0, NULL, NULL);
713 bytesNeeded += commentLen;
715 *ppPackageInfo = heap_alloc(bytesNeeded);
716 if (*ppPackageInfo)
718 PSTR nextString = (PSTR)((PBYTE)*ppPackageInfo +
719 sizeof(SecPkgInfoA));
721 memcpy(*ppPackageInfo, &package->infoW, sizeof(package->infoW));
722 if (package->infoW.Name)
724 (*ppPackageInfo)->Name = nextString;
725 nextString += WideCharToMultiByte(CP_ACP, 0,
726 package->infoW.Name, -1, nextString, nameLen, NULL, NULL);
728 else
729 (*ppPackageInfo)->Name = NULL;
730 if (package->infoW.Comment)
732 (*ppPackageInfo)->Comment = nextString;
733 nextString += WideCharToMultiByte(CP_ACP, 0,
734 package->infoW.Comment, -1, nextString, commentLen, NULL,
735 NULL);
737 else
738 (*ppPackageInfo)->Comment = NULL;
739 ret = SEC_E_OK;
741 else
742 ret = SEC_E_INSUFFICIENT_MEMORY;
744 else
745 ret = SEC_E_SECPKG_NOT_FOUND;
747 else
748 ret = SEC_E_SECPKG_NOT_FOUND;
749 return ret;
752 /***********************************************************************
753 * QuerySecurityPackageInfoW (SECUR32.@)
755 SECURITY_STATUS WINAPI QuerySecurityPackageInfoW(SEC_WCHAR *pszPackageName,
756 PSecPkgInfoW *ppPackageInfo)
758 SECURITY_STATUS ret;
759 SecurePackage *package = SECUR32_findPackageW(pszPackageName);
761 TRACE("%s %p\n", debugstr_w(pszPackageName), ppPackageInfo);
762 if (package)
764 size_t bytesNeeded = sizeof(SecPkgInfoW);
765 int nameLen = 0, commentLen = 0;
767 if (package->infoW.Name)
769 nameLen = lstrlenW(package->infoW.Name) + 1;
770 bytesNeeded += nameLen * sizeof(WCHAR);
772 if (package->infoW.Comment)
774 commentLen = lstrlenW(package->infoW.Comment) + 1;
775 bytesNeeded += commentLen * sizeof(WCHAR);
777 *ppPackageInfo = heap_alloc(bytesNeeded);
778 if (*ppPackageInfo)
780 PWSTR nextString = (PWSTR)((PBYTE)*ppPackageInfo +
781 sizeof(SecPkgInfoW));
783 **ppPackageInfo = package->infoW;
784 if (package->infoW.Name)
786 (*ppPackageInfo)->Name = nextString;
787 lstrcpynW(nextString, package->infoW.Name, nameLen);
788 nextString += nameLen;
790 else
791 (*ppPackageInfo)->Name = NULL;
792 if (package->infoW.Comment)
794 (*ppPackageInfo)->Comment = nextString;
795 lstrcpynW(nextString, package->infoW.Comment, commentLen);
797 else
798 (*ppPackageInfo)->Comment = NULL;
799 ret = SEC_E_OK;
801 else
802 ret = SEC_E_INSUFFICIENT_MEMORY;
804 else
805 ret = SEC_E_SECPKG_NOT_FOUND;
806 return ret;
809 /***********************************************************************
810 * ExportSecurityContext (SECUR32.@)
812 SECURITY_STATUS WINAPI ExportSecurityContext(PCtxtHandle phContext,
813 ULONG fFlags, PSecBuffer pPackedContext, void **pToken)
815 SECURITY_STATUS ret;
817 TRACE("%p %d %p %p\n", phContext, fFlags, pPackedContext, pToken);
818 if (phContext)
820 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
821 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
823 if (package && package->provider)
825 if (package->provider->fnTableW.ExportSecurityContext)
826 ret = package->provider->fnTableW.ExportSecurityContext(
827 ctxt, fFlags, pPackedContext, pToken);
828 else
829 ret = SEC_E_UNSUPPORTED_FUNCTION;
831 else
832 ret = SEC_E_INVALID_HANDLE;
834 else
835 ret = SEC_E_INVALID_HANDLE;
836 return ret;
839 /***********************************************************************
840 * ImportSecurityContextA (SECUR32.@)
842 SECURITY_STATUS WINAPI ImportSecurityContextA(SEC_CHAR *pszPackage,
843 PSecBuffer pPackedContext, void *Token, PCtxtHandle phContext)
845 SECURITY_STATUS ret;
846 SecurePackage *package = SECUR32_findPackageA(pszPackage);
848 TRACE("%s %p %p %p\n", debugstr_a(pszPackage), pPackedContext, Token,
849 phContext);
850 if (package && package->provider)
852 if (package->provider->fnTableA.ImportSecurityContextA)
854 CtxtHandle myCtxt;
856 ret = package->provider->fnTableA.ImportSecurityContextA(
857 pszPackage, pPackedContext, Token, &myCtxt);
858 if (ret == SEC_E_OK)
860 ret = SECUR32_makeSecHandle(phContext, package, &myCtxt);
861 if (ret != SEC_E_OK)
862 package->provider->fnTableW.DeleteSecurityContext(&myCtxt);
865 else
866 ret = SEC_E_UNSUPPORTED_FUNCTION;
868 else
869 ret = SEC_E_SECPKG_NOT_FOUND;
870 return ret;
874 /***********************************************************************
875 * ImportSecurityContextW (SECUR32.@)
877 SECURITY_STATUS WINAPI ImportSecurityContextW(SEC_WCHAR *pszPackage,
878 PSecBuffer pPackedContext, void *Token, PCtxtHandle phContext)
880 SECURITY_STATUS ret;
881 SecurePackage *package = SECUR32_findPackageW(pszPackage);
883 TRACE("%s %p %p %p\n", debugstr_w(pszPackage), pPackedContext, Token,
884 phContext);
885 if (package && package->provider)
887 if (package->provider->fnTableW.ImportSecurityContextW)
889 CtxtHandle myCtxt;
891 ret = package->provider->fnTableW.ImportSecurityContextW(
892 pszPackage, pPackedContext, Token, &myCtxt);
893 if (ret == SEC_E_OK)
895 ret = SECUR32_makeSecHandle(phContext, package, &myCtxt);
896 if (ret != SEC_E_OK)
897 package->provider->fnTableW.DeleteSecurityContext(&myCtxt);
900 else
901 ret = SEC_E_UNSUPPORTED_FUNCTION;
903 else
904 ret = SEC_E_SECPKG_NOT_FOUND;
905 return ret;
908 /***********************************************************************
909 * AddCredentialsA (SECUR32.@)
911 SECURITY_STATUS WINAPI AddCredentialsA(PCredHandle hCredentials,
912 SEC_CHAR *pszPrincipal, SEC_CHAR *pszPackage, ULONG fCredentialUse,
913 void *pAuthData, SEC_GET_KEY_FN pGetKeyFn, void *pvGetKeyArgument,
914 PTimeStamp ptsExpiry)
916 SECURITY_STATUS ret;
918 TRACE("%p %s %s %d %p %p %p %p\n", hCredentials, debugstr_a(pszPrincipal),
919 debugstr_a(pszPackage), fCredentialUse, pAuthData, pGetKeyFn,
920 pvGetKeyArgument, ptsExpiry);
921 if (hCredentials)
923 SecurePackage *package = (SecurePackage *)hCredentials->dwUpper;
924 PCredHandle cred = (PCtxtHandle)hCredentials->dwLower;
926 if (package && package->provider)
928 if (package->provider->fnTableA.AddCredentialsA)
929 ret = package->provider->fnTableA.AddCredentialsA(
930 cred, pszPrincipal, pszPackage, fCredentialUse, pAuthData,
931 pGetKeyFn, pvGetKeyArgument, ptsExpiry);
932 else
933 ret = SEC_E_UNSUPPORTED_FUNCTION;
935 else
936 ret = SEC_E_INVALID_HANDLE;
938 else
939 ret = SEC_E_INVALID_HANDLE;
940 return ret;
943 /***********************************************************************
944 * AddCredentialsW (SECUR32.@)
946 SECURITY_STATUS WINAPI AddCredentialsW(PCredHandle hCredentials,
947 SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, ULONG fCredentialUse,
948 void *pAuthData, SEC_GET_KEY_FN pGetKeyFn, void *pvGetKeyArgument,
949 PTimeStamp ptsExpiry)
951 SECURITY_STATUS ret;
953 TRACE("%p %s %s %d %p %p %p %p\n", hCredentials, debugstr_w(pszPrincipal),
954 debugstr_w(pszPackage), fCredentialUse, pAuthData, pGetKeyFn,
955 pvGetKeyArgument, ptsExpiry);
956 if (hCredentials)
958 SecurePackage *package = (SecurePackage *)hCredentials->dwUpper;
959 PCredHandle cred = (PCtxtHandle)hCredentials->dwLower;
961 if (package && package->provider)
963 if (package->provider->fnTableW.AddCredentialsW)
964 ret = package->provider->fnTableW.AddCredentialsW(
965 cred, pszPrincipal, pszPackage, fCredentialUse, pAuthData,
966 pGetKeyFn, pvGetKeyArgument, ptsExpiry);
967 else
968 ret = SEC_E_UNSUPPORTED_FUNCTION;
970 else
971 ret = SEC_E_INVALID_HANDLE;
973 else
974 ret = SEC_E_INVALID_HANDLE;
975 return ret;
978 /***********************************************************************
979 * QuerySecurityContextToken (SECUR32.@)
981 SECURITY_STATUS WINAPI QuerySecurityContextToken(PCtxtHandle phContext,
982 HANDLE *phToken)
984 SECURITY_STATUS ret;
986 TRACE("%p %p\n", phContext, phToken);
987 if (phContext)
989 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
990 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
992 if (package && package->provider)
994 if (package->provider->fnTableW.QuerySecurityContextToken)
995 ret = package->provider->fnTableW.QuerySecurityContextToken(
996 ctxt, phToken);
997 else
998 ret = SEC_E_UNSUPPORTED_FUNCTION;
1000 else
1001 ret = SEC_E_INVALID_HANDLE;
1003 else
1004 ret = SEC_E_INVALID_HANDLE;
1005 return ret;
1008 /***********************************************************************
1009 * EncryptMessage (SECUR32.@)
1011 SECURITY_STATUS WINAPI EncryptMessage(PCtxtHandle phContext, ULONG fQOP,
1012 PSecBufferDesc pMessage, ULONG MessageSeqNo)
1014 SECURITY_STATUS ret;
1016 TRACE("%p %d %p %d\n", phContext, fQOP, pMessage, MessageSeqNo);
1017 if (phContext)
1019 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
1020 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
1022 if (package && package->provider)
1024 if (package->provider->fnTableW.EncryptMessage)
1025 ret = package->provider->fnTableW.EncryptMessage(
1026 ctxt, fQOP, pMessage, MessageSeqNo);
1027 else
1028 ret = SEC_E_UNSUPPORTED_FUNCTION;
1030 else
1031 ret = SEC_E_INVALID_HANDLE;
1033 else
1034 ret = SEC_E_INVALID_HANDLE;
1035 return ret;
1038 /***********************************************************************
1039 * DecryptMessage (SECUR32.@)
1041 SECURITY_STATUS WINAPI DecryptMessage(PCtxtHandle phContext,
1042 PSecBufferDesc pMessage, ULONG MessageSeqNo, PULONG pfQOP)
1044 SECURITY_STATUS ret;
1046 TRACE("%p %p %d %p\n", phContext, pMessage, MessageSeqNo, pfQOP);
1047 if (phContext)
1049 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
1050 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
1052 if (package && package->provider)
1054 if (package->provider->fnTableW.DecryptMessage)
1055 ret = package->provider->fnTableW.DecryptMessage(
1056 ctxt, pMessage, MessageSeqNo, pfQOP);
1057 else
1058 ret = SEC_E_UNSUPPORTED_FUNCTION;
1060 else
1061 ret = SEC_E_INVALID_HANDLE;
1063 else
1064 ret = SEC_E_INVALID_HANDLE;
1065 return ret;
1068 /***********************************************************************
1069 * SetContextAttributesA (SECUR32.@)
1071 SECURITY_STATUS WINAPI SetContextAttributesA(PCtxtHandle phContext,
1072 ULONG ulAttribute, void *pBuffer, ULONG cbBuffer)
1074 SECURITY_STATUS ret;
1076 TRACE("%p %d %p %d\n", phContext, ulAttribute, pBuffer, cbBuffer);
1077 if (phContext)
1079 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
1080 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
1082 if (package && package->provider)
1084 if (package->provider->fnTableA.SetContextAttributesA)
1085 ret = package->provider->fnTableA.SetContextAttributesA(
1086 ctxt, ulAttribute, pBuffer, cbBuffer);
1087 else
1088 ret = SEC_E_UNSUPPORTED_FUNCTION;
1090 else
1091 ret = SEC_E_INVALID_HANDLE;
1093 else
1094 ret = SEC_E_INVALID_HANDLE;
1095 return ret;
1098 /***********************************************************************
1099 * SetContextAttributesW (SECUR32.@)
1101 SECURITY_STATUS WINAPI SetContextAttributesW(PCtxtHandle phContext,
1102 ULONG ulAttribute, void *pBuffer, ULONG cbBuffer)
1104 SECURITY_STATUS ret;
1106 TRACE("%p %d %p %d\n", phContext, ulAttribute, pBuffer, cbBuffer);
1107 if (phContext)
1109 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
1110 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
1112 if (package && package->provider)
1114 if (package->provider->fnTableW.SetContextAttributesW)
1115 ret = package->provider->fnTableW.SetContextAttributesW(
1116 ctxt, ulAttribute, pBuffer, cbBuffer);
1117 else
1118 ret = SEC_E_UNSUPPORTED_FUNCTION;
1120 else
1121 ret = SEC_E_INVALID_HANDLE;
1123 else
1124 ret = SEC_E_INVALID_HANDLE;
1125 return ret;