Added some tests for VerFindFileA.
[wine/wine-gecko.git] / dlls / secur32 / wrapper.c
blobba848107584aa9d5a8b500e9c0cadddac5fcabdd
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
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 (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)
38 SECURITY_STATUS ret;
40 TRACE("%p %p %p\n", phSec, package, realHandle);
42 if (phSec && package && realHandle)
44 PSecHandle newSec = (PSecHandle)SECUR32_ALLOC(sizeof(SecHandle));
46 if (newSec)
48 memcpy(newSec, realHandle, sizeof(*realHandle));
49 phSec->dwUpper = (ULONG_PTR)package;
50 phSec->dwLower = (ULONG_PTR)newSec;
51 ret = SEC_E_OK;
53 else
54 ret = SEC_E_INSUFFICIENT_MEMORY;
56 else
57 ret = SEC_E_INVALID_HANDLE;
58 return ret;
61 /***********************************************************************
62 * AcquireCredentialsHandleA (SECUR32.@)
64 SECURITY_STATUS WINAPI AcquireCredentialsHandleA(
65 SEC_CHAR *pszPrincipal, SEC_CHAR *pszPackage, ULONG fCredentialsUse,
66 PLUID pvLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn,
67 PVOID pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
69 SECURITY_STATUS ret;
71 TRACE("%s %s %ld %p %p %p %p %p %p\n", debugstr_a(pszPrincipal),
72 debugstr_a(pszPackage), fCredentialsUse, pvLogonID, pAuthData, pGetKeyFn,
73 pvGetKeyArgument, phCredential, ptsExpiry);
74 if (pszPackage)
76 SecurePackage *package = SECUR32_findPackageA(pszPackage);
78 if (package && package->provider)
80 if (package->provider->fnTableA.AcquireCredentialsHandleA)
82 CredHandle myCred;
84 ret = package->provider->fnTableA.AcquireCredentialsHandleA(
85 pszPrincipal, pszPackage, fCredentialsUse, pvLogonID,
86 pAuthData, pGetKeyFn, pvGetKeyArgument, &myCred,
87 ptsExpiry);
88 if (ret == SEC_E_OK)
90 ret = SECUR32_makeSecHandle(phCredential, package, &myCred);
91 if (ret != SEC_E_OK)
92 package->provider->fnTableW.FreeCredentialsHandle(
93 &myCred);
96 else
97 ret = SEC_E_UNSUPPORTED_FUNCTION;
99 else
100 ret = SEC_E_SECPKG_NOT_FOUND;
102 else
103 ret = SEC_E_SECPKG_NOT_FOUND;
104 return ret;
107 /***********************************************************************
108 * AcquireCredentialsHandleW (SECUR32.@)
110 SECURITY_STATUS WINAPI AcquireCredentialsHandleW(
111 SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, ULONG fCredentialsUse,
112 PLUID pvLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn,
113 PVOID pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
115 SECURITY_STATUS ret;
117 TRACE("%s %s %ld %p %p %p %p %p %p\n", debugstr_w(pszPrincipal),
118 debugstr_w(pszPackage), fCredentialsUse, pvLogonID, pAuthData, pGetKeyFn,
119 pvGetKeyArgument, phCredential, ptsExpiry);
120 if (pszPackage)
122 SecurePackage *package = SECUR32_findPackageW(pszPackage);
124 if (package && package->provider)
126 if (package->provider->fnTableW.AcquireCredentialsHandleW)
128 CredHandle myCred;
130 ret = package->provider->fnTableW.AcquireCredentialsHandleW(
131 pszPrincipal, pszPackage, fCredentialsUse, pvLogonID,
132 pAuthData, pGetKeyFn, pvGetKeyArgument, &myCred,
133 ptsExpiry);
134 if (ret == SEC_E_OK)
136 ret = SECUR32_makeSecHandle(phCredential, package, &myCred);
137 if (ret != SEC_E_OK)
138 package->provider->fnTableW.FreeCredentialsHandle(
139 &myCred);
142 else
143 ret = SEC_E_UNSUPPORTED_FUNCTION;
145 else
146 ret = SEC_E_SECPKG_NOT_FOUND;
148 else
149 ret = SEC_E_SECPKG_NOT_FOUND;
150 return ret;
153 /***********************************************************************
154 * FreeCredentialsHandle (SECUR32.@)
156 SECURITY_STATUS WINAPI FreeCredentialsHandle(
157 PCredHandle phCredential)
159 SECURITY_STATUS ret;
161 TRACE("%p\n", phCredential);
162 if (phCredential)
164 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
165 PCredHandle cred = (PCredHandle)phCredential->dwLower;
167 if (package && package->provider &&
168 package->provider->fnTableW.FreeCredentialsHandle)
169 ret = package->provider->fnTableW.FreeCredentialsHandle(cred);
170 else
171 ret = SEC_E_INVALID_HANDLE;
172 SECUR32_FREE(cred);
174 else
175 ret = SEC_E_INVALID_HANDLE;
176 return ret;
179 /***********************************************************************
180 * QueryCredentialsAttributesA (SECUR32.@)
182 SECURITY_STATUS WINAPI QueryCredentialsAttributesA(
183 PCredHandle phCredential, unsigned long ulAttribute, void *pBuffer)
185 SECURITY_STATUS ret;
187 TRACE("%p %ld %p\n", phCredential, ulAttribute, pBuffer);
188 if (phCredential)
190 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
191 PCredHandle cred = (PCredHandle)phCredential->dwLower;
193 if (package && package->provider)
195 if (package->provider->fnTableA.QueryCredentialsAttributesA)
196 ret = package->provider->fnTableA.QueryCredentialsAttributesA(
197 cred, ulAttribute, pBuffer);
198 else
199 ret = SEC_E_UNSUPPORTED_FUNCTION;
201 else
202 ret = SEC_E_INVALID_HANDLE;
204 else
205 ret = SEC_E_INVALID_HANDLE;
206 return ret;
209 /***********************************************************************
210 * QueryCredentialsAttributesW (SECUR32.@)
212 SECURITY_STATUS WINAPI QueryCredentialsAttributesW(
213 PCredHandle phCredential, unsigned long ulAttribute, void *pBuffer)
215 SECURITY_STATUS ret;
217 TRACE("%p %ld %p\n", phCredential, ulAttribute, pBuffer);
218 if (phCredential)
220 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
221 PCredHandle cred = (PCredHandle)phCredential->dwLower;
223 if (package && package->provider)
225 if (package->provider->fnTableW.QueryCredentialsAttributesW)
226 ret = package->provider->fnTableW.QueryCredentialsAttributesW(
227 cred, ulAttribute, pBuffer);
228 else
229 ret = SEC_E_UNSUPPORTED_FUNCTION;
231 else
232 ret = SEC_E_INVALID_HANDLE;
234 else
235 ret = SEC_E_INVALID_HANDLE;
236 return ret;
239 /***********************************************************************
240 * InitializeSecurityContextA (SECUR32.@)
242 SECURITY_STATUS WINAPI InitializeSecurityContextA(
243 PCredHandle phCredential, PCtxtHandle phContext,
244 SEC_CHAR *pszTargetName, unsigned long fContextReq,
245 unsigned long Reserved1, unsigned long TargetDataRep, PSecBufferDesc pInput,
246 unsigned long Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pOutput,
247 unsigned long *pfContextAttr, PTimeStamp ptsExpiry)
249 SECURITY_STATUS ret;
251 TRACE("%p %p %s %ld %ld %ld %p %ld %p %p %p %p\n", phCredential, phContext,
252 debugstr_a(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
253 Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
254 if (phCredential)
256 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
257 PCredHandle cred = (PCredHandle)phCredential->dwLower;
259 if (package && package->provider)
261 if (package->provider->fnTableA.InitializeSecurityContextA)
263 CtxtHandle myCtxt;
265 if(phContext)
267 PCtxtHandle realCtxt = (PCtxtHandle)phContext->dwLower;
268 myCtxt.dwUpper = realCtxt->dwUpper;
269 myCtxt.dwLower = realCtxt->dwLower;
272 ret = package->provider->fnTableA.InitializeSecurityContextA(
273 cred, phContext ? &myCtxt : NULL, pszTargetName, fContextReq,
274 Reserved1, TargetDataRep, pInput, Reserved2, &myCtxt,
275 pOutput, pfContextAttr, ptsExpiry);
276 if (ret == SEC_E_OK || ret == SEC_I_CONTINUE_NEEDED)
278 SECURITY_STATUS ret2;
279 ret2 = SECUR32_makeSecHandle(phNewContext, package, &myCtxt);
280 if (ret2 != SEC_E_OK)
281 package->provider->fnTableW.DeleteSecurityContext(
282 &myCtxt);
285 else
286 ret = SEC_E_UNSUPPORTED_FUNCTION;
288 else
289 ret = SEC_E_INVALID_HANDLE;
291 else
292 ret = SEC_E_INVALID_HANDLE;
293 return ret;
296 /***********************************************************************
297 * InitializeSecurityContextW (SECUR32.@)
299 SECURITY_STATUS WINAPI InitializeSecurityContextW(
300 PCredHandle phCredential, PCtxtHandle phContext,
301 SEC_WCHAR *pszTargetName, unsigned long fContextReq,
302 unsigned long Reserved1, unsigned long TargetDataRep, PSecBufferDesc pInput,
303 unsigned long Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pOutput,
304 unsigned long *pfContextAttr, PTimeStamp ptsExpiry)
306 SECURITY_STATUS ret;
308 TRACE("%p %p %s %ld %ld %ld %p %ld %p %p %p %p\n", phCredential, phContext,
309 debugstr_w(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
310 Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
311 if (phCredential)
313 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
314 PCredHandle cred = (PCredHandle)phCredential->dwLower;
316 if (package && package->provider)
318 if (package->provider->fnTableW.QueryCredentialsAttributesW)
320 CtxtHandle myCtxt;
322 if(phContext)
324 PCtxtHandle realCtxt = (PCtxtHandle)phContext->dwLower;
325 myCtxt.dwUpper = realCtxt->dwUpper;
326 myCtxt.dwLower = realCtxt->dwLower;
329 ret = package->provider->fnTableW.InitializeSecurityContextW(
330 cred, phContext ? &myCtxt : NULL, pszTargetName, fContextReq,
331 Reserved1, TargetDataRep, pInput, Reserved2, &myCtxt,
332 pOutput, pfContextAttr, ptsExpiry);
333 if (ret == SEC_E_OK || ret == SEC_I_CONTINUE_NEEDED)
335 SECURITY_STATUS ret2;
336 ret2 = SECUR32_makeSecHandle(phNewContext, package, &myCtxt);
337 if (ret2 != SEC_E_OK)
338 package->provider->fnTableW.DeleteSecurityContext(
339 &myCtxt);
342 else
343 ret = SEC_E_UNSUPPORTED_FUNCTION;
345 else
346 ret = SEC_E_INVALID_HANDLE;
348 else
349 ret = SEC_E_INVALID_HANDLE;
350 return ret;
353 /***********************************************************************
354 * AcceptSecurityContext (SECUR32.@)
356 SECURITY_STATUS WINAPI AcceptSecurityContext(
357 PCredHandle phCredential, PCtxtHandle phContext, PSecBufferDesc pInput,
358 unsigned long fContextReq, unsigned long TargetDataRep,
359 PCtxtHandle phNewContext, PSecBufferDesc pOutput,
360 unsigned long *pfContextAttr, PTimeStamp ptsExpiry)
362 SECURITY_STATUS ret;
364 TRACE("%p %p %p %ld %ld %p %p %p %p\n", phCredential, phContext, pInput,
365 fContextReq, TargetDataRep, phNewContext, pOutput, pfContextAttr,
366 ptsExpiry);
367 if (phCredential)
369 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
370 PCredHandle cred = (PCredHandle)phCredential->dwLower;
372 if (package && package->provider)
374 if (package->provider->fnTableW.AcceptSecurityContext)
376 CtxtHandle myCtxt;
378 if(phContext)
380 PCtxtHandle realCtxt = (PCtxtHandle)phContext->dwLower;
381 TRACE("realCtx: %p\n", realCtxt);
382 myCtxt.dwUpper = realCtxt->dwUpper;
383 myCtxt.dwLower = realCtxt->dwLower;
386 ret = package->provider->fnTableW.AcceptSecurityContext(
387 cred, phContext ? &myCtxt : NULL, pInput, fContextReq,
388 TargetDataRep, &myCtxt, pOutput, pfContextAttr, ptsExpiry);
389 if (ret == SEC_E_OK || ret == SEC_I_CONTINUE_NEEDED)
391 SECURITY_STATUS ret2;
392 ret2 = SECUR32_makeSecHandle(phNewContext, package, &myCtxt);
393 if (ret2 != SEC_E_OK)
394 package->provider->fnTableW.DeleteSecurityContext(
395 &myCtxt);
398 else
399 ret = SEC_E_UNSUPPORTED_FUNCTION;
401 else
402 ret = SEC_E_INVALID_HANDLE;
404 else
405 ret = SEC_E_INVALID_HANDLE;
406 return ret;
409 /***********************************************************************
410 * CompleteAuthToken (SECUR32.@)
412 SECURITY_STATUS WINAPI CompleteAuthToken(PCtxtHandle phContext,
413 PSecBufferDesc pToken)
415 SECURITY_STATUS ret;
417 TRACE("%p %p\n", phContext, pToken);
418 if (phContext)
420 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
421 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
423 if (package && package->provider)
425 if (package->provider->fnTableW.CompleteAuthToken)
426 ret = package->provider->fnTableW.CompleteAuthToken(ctxt,
427 pToken);
428 else
429 ret = SEC_E_UNSUPPORTED_FUNCTION;
431 else
432 ret = SEC_E_INVALID_HANDLE;
434 else
435 ret = SEC_E_INVALID_HANDLE;
436 return ret;
439 /***********************************************************************
440 * DeleteSecurityContext (SECUR32.@)
442 SECURITY_STATUS WINAPI DeleteSecurityContext(PCtxtHandle phContext)
444 SECURITY_STATUS ret;
446 TRACE("%p\n", phContext);
447 if (phContext)
449 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
450 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
452 if (package && package->provider &&
453 package->provider->fnTableW.DeleteSecurityContext)
454 ret = package->provider->fnTableW.DeleteSecurityContext(ctxt);
455 else
456 ret = SEC_E_INVALID_HANDLE;
457 SECUR32_FREE(ctxt);
459 else
460 ret = SEC_E_INVALID_HANDLE;
461 return ret;
464 /***********************************************************************
465 * ApplyControlToken (SECUR32.@)
467 SECURITY_STATUS WINAPI ApplyControlToken(PCtxtHandle phContext,
468 PSecBufferDesc pInput)
470 SECURITY_STATUS ret;
472 TRACE("%p %p\n", phContext, pInput);
473 if (phContext)
475 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
476 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
478 if (package && package->provider)
480 if (package->provider->fnTableW.ApplyControlToken)
481 ret = package->provider->fnTableW.ApplyControlToken(
482 ctxt, pInput);
483 else
484 ret = SEC_E_UNSUPPORTED_FUNCTION;
486 else
487 ret = SEC_E_INVALID_HANDLE;
489 else
490 ret = SEC_E_INVALID_HANDLE;
491 return ret;
494 /***********************************************************************
495 * QueryContextAttributesA (SECUR32.@)
497 SECURITY_STATUS WINAPI QueryContextAttributesA(PCtxtHandle phContext,
498 unsigned long ulAttribute, void *pBuffer)
500 SECURITY_STATUS ret;
502 TRACE("%p %ld %p\n", phContext, ulAttribute, pBuffer);
503 if (phContext)
505 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
506 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
508 if (package && package->provider)
510 if (package->provider->fnTableA.QueryContextAttributesA)
511 ret = package->provider->fnTableA.QueryContextAttributesA(
512 ctxt, ulAttribute, pBuffer);
513 else
514 ret = SEC_E_UNSUPPORTED_FUNCTION;
516 else
517 ret = SEC_E_INVALID_HANDLE;
519 else
520 ret = SEC_E_INVALID_HANDLE;
521 return ret;
524 /***********************************************************************
525 * QueryContextAttributesW (SECUR32.@)
527 SECURITY_STATUS WINAPI QueryContextAttributesW(PCtxtHandle phContext,
528 unsigned long ulAttribute, void *pBuffer)
530 SECURITY_STATUS ret;
532 TRACE("%p %ld %p\n", phContext, ulAttribute, pBuffer);
533 if (phContext)
535 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
536 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
538 if (package && package->provider)
540 if (package->provider->fnTableW.QueryContextAttributesW)
541 ret = package->provider->fnTableW.QueryContextAttributesW(
542 ctxt, ulAttribute, pBuffer);
543 else
544 ret = SEC_E_UNSUPPORTED_FUNCTION;
546 else
547 ret = SEC_E_INVALID_HANDLE;
549 else
550 ret = SEC_E_INVALID_HANDLE;
551 return ret;
554 /***********************************************************************
555 * ImpersonateSecurityContext (SECUR32.@)
557 SECURITY_STATUS WINAPI ImpersonateSecurityContext(PCtxtHandle phContext)
559 SECURITY_STATUS ret;
561 TRACE("%p\n", phContext);
562 if (phContext)
564 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
565 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
567 if (package && package->provider)
569 if (package->provider->fnTableW.ImpersonateSecurityContext)
570 ret = package->provider->fnTableW.ImpersonateSecurityContext(
571 ctxt);
572 else
573 ret = SEC_E_UNSUPPORTED_FUNCTION;
575 else
576 ret = SEC_E_INVALID_HANDLE;
578 else
579 ret = SEC_E_INVALID_HANDLE;
580 return ret;
583 /***********************************************************************
584 * RevertSecurityContext (SECUR32.@)
586 SECURITY_STATUS WINAPI RevertSecurityContext(PCtxtHandle phContext)
588 SECURITY_STATUS ret;
590 TRACE("%p\n", phContext);
591 if (phContext)
593 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
594 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
596 if (package && package->provider)
598 if (package->provider->fnTableW.RevertSecurityContext)
599 ret = package->provider->fnTableW.RevertSecurityContext(
600 ctxt);
601 else
602 ret = SEC_E_UNSUPPORTED_FUNCTION;
604 else
605 ret = SEC_E_INVALID_HANDLE;
607 else
608 ret = SEC_E_INVALID_HANDLE;
609 return ret;
612 /***********************************************************************
613 * MakeSignature (SECUR32.@)
615 SECURITY_STATUS WINAPI MakeSignature(PCtxtHandle phContext, ULONG fQOP,
616 PSecBufferDesc pMessage, ULONG MessageSeqNo)
618 SECURITY_STATUS ret;
620 TRACE("%p %ld %p %ld\n", phContext, fQOP, pMessage, MessageSeqNo);
621 if (phContext)
623 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
624 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
626 if (package && package->provider)
628 if (package->provider->fnTableW.MakeSignature)
629 ret = package->provider->fnTableW.MakeSignature(
630 ctxt, fQOP, pMessage, MessageSeqNo);
631 else
632 ret = SEC_E_UNSUPPORTED_FUNCTION;
634 else
635 ret = SEC_E_INVALID_HANDLE;
637 else
638 ret = SEC_E_INVALID_HANDLE;
639 return ret;
642 /***********************************************************************
643 * VerifySignature (SECUR32.@)
645 SECURITY_STATUS WINAPI VerifySignature(PCtxtHandle phContext,
646 PSecBufferDesc pMessage, ULONG MessageSeqNo, PULONG pfQOP)
648 SECURITY_STATUS ret;
650 TRACE("%p %p %ld %p\n", phContext, pMessage, MessageSeqNo, pfQOP);
651 if (phContext)
653 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
654 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
656 if (package && package->provider)
658 if (package->provider->fnTableW.VerifySignature)
659 ret = package->provider->fnTableW.VerifySignature(
660 ctxt, pMessage, MessageSeqNo, pfQOP);
661 else
662 ret = SEC_E_UNSUPPORTED_FUNCTION;
664 else
665 ret = SEC_E_INVALID_HANDLE;
667 else
668 ret = SEC_E_INVALID_HANDLE;
669 return ret;
672 /***********************************************************************
673 * QuerySecurityPackageInfoA (SECUR32.@)
675 SECURITY_STATUS WINAPI QuerySecurityPackageInfoA(SEC_CHAR *pszPackageName,
676 PSecPkgInfoA *ppPackageInfo)
678 SECURITY_STATUS ret;
680 TRACE("%s %p\n", debugstr_a(pszPackageName), ppPackageInfo);
681 if (pszPackageName)
683 SecurePackage *package = SECUR32_findPackageA(pszPackageName);
685 if (package)
687 size_t bytesNeeded = sizeof(SecPkgInfoA);
688 int nameLen = 0, commentLen = 0;
690 if (package->infoW.Name)
692 nameLen = WideCharToMultiByte(CP_ACP, 0,
693 package->infoW.Name, -1, NULL, 0, NULL, NULL);
694 bytesNeeded += nameLen;
696 if (package->infoW.Comment)
698 commentLen = WideCharToMultiByte(CP_ACP, 0,
699 package->infoW.Comment, -1, NULL, 0, NULL, NULL);
700 bytesNeeded += commentLen;
702 *ppPackageInfo = (PSecPkgInfoA)SECUR32_ALLOC(bytesNeeded);
703 if (*ppPackageInfo)
705 PSTR nextString = (PSTR)((PBYTE)*ppPackageInfo +
706 sizeof(SecPkgInfoA));
708 memcpy(*ppPackageInfo, &package->infoW, sizeof(package->infoW));
709 if (package->infoW.Name)
711 (*ppPackageInfo)->Name = nextString;
712 nextString += WideCharToMultiByte(CP_ACP, 0,
713 package->infoW.Name, -1, nextString, nameLen, NULL, NULL);
715 else
716 (*ppPackageInfo)->Name = NULL;
717 if (package->infoW.Comment)
719 (*ppPackageInfo)->Comment = nextString;
720 nextString += WideCharToMultiByte(CP_ACP, 0,
721 package->infoW.Comment, -1, nextString, commentLen, NULL,
722 NULL);
724 else
725 (*ppPackageInfo)->Comment = NULL;
726 ret = SEC_E_OK;
728 else
729 ret = SEC_E_INSUFFICIENT_MEMORY;
731 else
732 ret = SEC_E_SECPKG_NOT_FOUND;
734 else
735 ret = SEC_E_SECPKG_NOT_FOUND;
736 return ret;
739 /***********************************************************************
740 * QuerySecurityPackageInfoW (SECUR32.@)
742 SECURITY_STATUS WINAPI QuerySecurityPackageInfoW(SEC_WCHAR *pszPackageName,
743 PSecPkgInfoW *ppPackageInfo)
745 SECURITY_STATUS ret;
746 SecurePackage *package = SECUR32_findPackageW(pszPackageName);
748 TRACE("%s %p\n", debugstr_w(pszPackageName), ppPackageInfo);
749 if (package)
751 size_t bytesNeeded = sizeof(SecPkgInfoW);
752 int nameLen = 0, commentLen = 0;
754 if (package->infoW.Name)
756 nameLen = lstrlenW(package->infoW.Name) + 1;
757 bytesNeeded += nameLen * sizeof(WCHAR);
759 if (package->infoW.Comment)
761 commentLen = lstrlenW(package->infoW.Comment) + 1;
762 bytesNeeded += commentLen * sizeof(WCHAR);
764 *ppPackageInfo = (PSecPkgInfoW)SECUR32_ALLOC(bytesNeeded);
765 if (*ppPackageInfo)
767 PWSTR nextString = (PWSTR)((PBYTE)*ppPackageInfo +
768 sizeof(SecPkgInfoW));
770 memcpy(*ppPackageInfo, &package->infoW, sizeof(package->infoW));
771 if (package->infoW.Name)
773 (*ppPackageInfo)->Name = nextString;
774 lstrcpynW(nextString, package->infoW.Name, nameLen);
775 nextString += nameLen;
777 else
778 (*ppPackageInfo)->Name = NULL;
779 if (package->infoW.Comment)
781 (*ppPackageInfo)->Comment = nextString;
782 lstrcpynW(nextString, package->infoW.Comment, commentLen);
783 nextString += commentLen;
785 else
786 (*ppPackageInfo)->Comment = NULL;
787 ret = SEC_E_OK;
789 else
790 ret = SEC_E_INSUFFICIENT_MEMORY;
792 else
793 ret = SEC_E_SECPKG_NOT_FOUND;
794 return ret;
797 /***********************************************************************
798 * ExportSecurityContext (SECUR32.@)
800 SECURITY_STATUS WINAPI ExportSecurityContext(PCtxtHandle phContext,
801 ULONG fFlags, PSecBuffer pPackedContext, void **pToken)
803 SECURITY_STATUS ret;
805 TRACE("%p %ld %p %p\n", phContext, fFlags, pPackedContext, pToken);
806 if (phContext)
808 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
809 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
811 if (package && package->provider)
813 if (package->provider->fnTableW.ExportSecurityContext)
814 ret = package->provider->fnTableW.ExportSecurityContext(
815 ctxt, fFlags, pPackedContext, pToken);
816 else
817 ret = SEC_E_UNSUPPORTED_FUNCTION;
819 else
820 ret = SEC_E_INVALID_HANDLE;
822 else
823 ret = SEC_E_INVALID_HANDLE;
824 return ret;
827 /***********************************************************************
828 * ImportSecurityContextA (SECUR32.@)
830 SECURITY_STATUS WINAPI ImportSecurityContextA(SEC_CHAR *pszPackage,
831 PSecBuffer pPackedContext, void *Token, PCtxtHandle phContext)
833 SECURITY_STATUS ret;
834 SecurePackage *package = SECUR32_findPackageA(pszPackage);
836 TRACE("%s %p %p %p\n", debugstr_a(pszPackage), pPackedContext, Token,
837 phContext);
838 if (package && package->provider)
840 if (package->provider->fnTableA.ImportSecurityContextA)
842 CtxtHandle myCtxt;
844 ret = package->provider->fnTableA.ImportSecurityContextA(
845 pszPackage, pPackedContext, Token, &myCtxt);
846 if (ret == SEC_E_OK)
848 ret = SECUR32_makeSecHandle(phContext, package, &myCtxt);
849 if (ret != SEC_E_OK)
850 package->provider->fnTableW.DeleteSecurityContext(&myCtxt);
853 else
854 ret = SEC_E_UNSUPPORTED_FUNCTION;
856 else
857 ret = SEC_E_SECPKG_NOT_FOUND;
858 return ret;
862 /***********************************************************************
863 * ImportSecurityContextW (SECUR32.@)
865 SECURITY_STATUS WINAPI ImportSecurityContextW(SEC_WCHAR *pszPackage,
866 PSecBuffer pPackedContext, void *Token, PCtxtHandle phContext)
868 SECURITY_STATUS ret;
869 SecurePackage *package = SECUR32_findPackageW(pszPackage);
871 TRACE("%s %p %p %p\n", debugstr_w(pszPackage), pPackedContext, Token,
872 phContext);
873 if (package && package->provider)
875 if (package->provider->fnTableW.ImportSecurityContextW)
877 CtxtHandle myCtxt;
879 ret = package->provider->fnTableW.ImportSecurityContextW(
880 pszPackage, pPackedContext, Token, &myCtxt);
881 if (ret == SEC_E_OK)
883 ret = SECUR32_makeSecHandle(phContext, package, &myCtxt);
884 if (ret != SEC_E_OK)
885 package->provider->fnTableW.DeleteSecurityContext(&myCtxt);
888 else
889 ret = SEC_E_UNSUPPORTED_FUNCTION;
891 else
892 ret = SEC_E_SECPKG_NOT_FOUND;
893 return ret;
896 /***********************************************************************
897 * AddCredentialsA (SECUR32.@)
899 SECURITY_STATUS WINAPI AddCredentialsA(PCredHandle hCredentials,
900 SEC_CHAR *pszPrincipal, SEC_CHAR *pszPackage, unsigned long fCredentialUse,
901 void *pAuthData, SEC_GET_KEY_FN pGetKeyFn, void *pvGetKeyArgument,
902 PTimeStamp ptsExpiry)
904 SECURITY_STATUS ret;
906 TRACE("%p %s %s %ld %p %p %p %p\n", hCredentials, debugstr_a(pszPrincipal),
907 debugstr_a(pszPackage), fCredentialUse, pAuthData, pGetKeyFn,
908 pvGetKeyArgument, ptsExpiry);
909 if (hCredentials)
911 SecurePackage *package = (SecurePackage *)hCredentials->dwUpper;
912 PCredHandle cred = (PCtxtHandle)hCredentials->dwLower;
914 if (package && package->provider)
916 if (package->provider->fnTableA.AddCredentialsA)
917 ret = package->provider->fnTableA.AddCredentialsA(
918 cred, pszPrincipal, pszPackage, fCredentialUse, pAuthData,
919 pGetKeyFn, pvGetKeyArgument, ptsExpiry);
920 else
921 ret = SEC_E_UNSUPPORTED_FUNCTION;
923 else
924 ret = SEC_E_INVALID_HANDLE;
926 else
927 ret = SEC_E_INVALID_HANDLE;
928 return ret;
931 /***********************************************************************
932 * AddCredentialsW (SECUR32.@)
934 SECURITY_STATUS WINAPI AddCredentialsW(PCredHandle hCredentials,
935 SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, unsigned long fCredentialUse,
936 void *pAuthData, SEC_GET_KEY_FN pGetKeyFn, void *pvGetKeyArgument,
937 PTimeStamp ptsExpiry)
939 SECURITY_STATUS ret;
941 TRACE("%p %s %s %ld %p %p %p %p\n", hCredentials, debugstr_w(pszPrincipal),
942 debugstr_w(pszPackage), fCredentialUse, pAuthData, pGetKeyFn,
943 pvGetKeyArgument, ptsExpiry);
944 if (hCredentials)
946 SecurePackage *package = (SecurePackage *)hCredentials->dwUpper;
947 PCredHandle cred = (PCtxtHandle)hCredentials->dwLower;
949 if (package && package->provider)
951 if (package->provider->fnTableW.AddCredentialsW)
952 ret = package->provider->fnTableW.AddCredentialsW(
953 cred, pszPrincipal, pszPackage, fCredentialUse, pAuthData,
954 pGetKeyFn, pvGetKeyArgument, ptsExpiry);
955 else
956 ret = SEC_E_UNSUPPORTED_FUNCTION;
958 else
959 ret = SEC_E_INVALID_HANDLE;
961 else
962 ret = SEC_E_INVALID_HANDLE;
963 return ret;
966 /***********************************************************************
967 * QuerySecurityContextToken (SECUR32.@)
969 SECURITY_STATUS WINAPI QuerySecurityContextToken(PCtxtHandle phContext,
970 HANDLE *phToken)
972 SECURITY_STATUS ret;
974 TRACE("%p %p\n", phContext, phToken);
975 if (phContext)
977 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
978 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
980 if (package && package->provider)
982 if (package->provider->fnTableW.QuerySecurityContextToken)
983 ret = package->provider->fnTableW.QuerySecurityContextToken(
984 ctxt, phToken);
985 else
986 ret = SEC_E_UNSUPPORTED_FUNCTION;
988 else
989 ret = SEC_E_INVALID_HANDLE;
991 else
992 ret = SEC_E_INVALID_HANDLE;
993 return ret;
996 /***********************************************************************
997 * EncryptMessage (SECUR32.@)
999 SECURITY_STATUS WINAPI EncryptMessage(PCtxtHandle phContext, ULONG fQOP,
1000 PSecBufferDesc pMessage, ULONG MessageSeqNo)
1002 SECURITY_STATUS ret;
1004 TRACE("%p %ld %p %ld\n", phContext, fQOP, pMessage, MessageSeqNo);
1005 if (phContext)
1007 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
1008 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
1010 if (package && package->provider)
1012 if (package->provider->fnTableW.EncryptMessage)
1013 ret = package->provider->fnTableW.EncryptMessage(
1014 ctxt, fQOP, pMessage, MessageSeqNo);
1015 else
1016 ret = SEC_E_UNSUPPORTED_FUNCTION;
1018 else
1019 ret = SEC_E_INVALID_HANDLE;
1021 else
1022 ret = SEC_E_INVALID_HANDLE;
1023 return ret;
1026 /***********************************************************************
1027 * DecryptMessage (SECUR32.@)
1029 SECURITY_STATUS WINAPI DecryptMessage(PCtxtHandle phContext,
1030 PSecBufferDesc pMessage, ULONG MessageSeqNo, PULONG pfQOP)
1032 SECURITY_STATUS ret;
1034 TRACE("%p %p %ld %p\n", phContext, pMessage, MessageSeqNo, pfQOP);
1035 if (phContext)
1037 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
1038 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
1040 if (package && package->provider)
1042 if (package->provider->fnTableW.DecryptMessage)
1043 ret = package->provider->fnTableW.DecryptMessage(
1044 ctxt, pMessage, MessageSeqNo, pfQOP);
1045 else
1046 ret = SEC_E_UNSUPPORTED_FUNCTION;
1048 else
1049 ret = SEC_E_INVALID_HANDLE;
1051 else
1052 ret = SEC_E_INVALID_HANDLE;
1053 return ret;
1056 /***********************************************************************
1057 * SetContextAttributesA (SECUR32.@)
1059 SECURITY_STATUS WINAPI SetContextAttributesA(PCtxtHandle phContext,
1060 unsigned long ulAttribute, void *pBuffer, unsigned long cbBuffer)
1062 SECURITY_STATUS ret;
1064 TRACE("%p %ld %p %ld\n", phContext, ulAttribute, pBuffer, cbBuffer);
1065 if (phContext)
1067 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
1068 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
1070 if (package && package->provider)
1072 if (package->provider->fnTableA.SetContextAttributesA)
1073 ret = package->provider->fnTableA.SetContextAttributesA(
1074 ctxt, ulAttribute, pBuffer, cbBuffer);
1075 else
1076 ret = SEC_E_UNSUPPORTED_FUNCTION;
1078 else
1079 ret = SEC_E_INVALID_HANDLE;
1081 else
1082 ret = SEC_E_INVALID_HANDLE;
1083 return ret;
1086 /***********************************************************************
1087 * SetContextAttributesW (SECUR32.@)
1089 SECURITY_STATUS WINAPI SetContextAttributesW(PCtxtHandle phContext,
1090 unsigned long ulAttribute, void *pBuffer, unsigned long cbBuffer)
1092 SECURITY_STATUS ret;
1094 TRACE("%p %ld %p %ld\n", phContext, ulAttribute, pBuffer, cbBuffer);
1095 if (phContext)
1097 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
1098 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
1100 if (package && package->provider)
1102 if (package->provider->fnTableW.SetContextAttributesW)
1103 ret = package->provider->fnTableW.SetContextAttributesW(
1104 ctxt, ulAttribute, pBuffer, cbBuffer);
1105 else
1106 ret = SEC_E_UNSUPPORTED_FUNCTION;
1108 else
1109 ret = SEC_E_INVALID_HANDLE;
1111 else
1112 ret = SEC_E_INVALID_HANDLE;
1113 return ret;