Review and fix regular expressions of the form /^foo|bar$/.
[wine/wine-gecko.git] / dlls / secur32 / wrapper.c
blobdea3d95606e56011aa90f19bc0799c49953f8f46
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 if (phSec && package && realHandle)
42 PSecHandle newSec = (PSecHandle)SECUR32_ALLOC(sizeof(SecHandle));
44 if (newSec)
46 memcpy(newSec, realHandle, sizeof(*realHandle));
47 phSec->dwUpper = (ULONG_PTR)package;
48 phSec->dwLower = (ULONG_PTR)newSec;
49 ret = SEC_E_OK;
51 else
52 ret = SEC_E_INSUFFICIENT_MEMORY;
54 else
55 ret = SEC_E_INVALID_HANDLE;
56 return ret;
59 /***********************************************************************
60 * AcquireCredentialsHandleA (SECUR32.@)
62 SECURITY_STATUS WINAPI AcquireCredentialsHandleA(
63 SEC_CHAR *pszPrincipal, SEC_CHAR *pszPackage, ULONG fCredentialsUse,
64 PLUID pvLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn,
65 PVOID pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
67 SECURITY_STATUS ret;
69 TRACE("%s %s %ld %p %p %p %p %p %p\n", debugstr_a(pszPrincipal),
70 debugstr_a(pszPackage), fCredentialsUse, pvLogonID, pAuthData, pGetKeyFn,
71 pvGetKeyArgument, phCredential, ptsExpiry);
72 if (pszPackage)
74 SecurePackage *package = SECUR32_findPackageA(pszPackage);
76 if (package && package->provider)
78 if (package->provider->fnTableA.AcquireCredentialsHandleA)
80 CredHandle myCred;
82 ret = package->provider->fnTableA.AcquireCredentialsHandleA(
83 pszPrincipal, pszPackage, fCredentialsUse, pvLogonID,
84 pAuthData, pGetKeyFn, pvGetKeyArgument, &myCred,
85 ptsExpiry);
86 if (ret == SEC_E_OK)
88 ret = SECUR32_makeSecHandle(phCredential, package, &myCred);
89 if (ret != SEC_E_OK)
90 package->provider->fnTableW.FreeCredentialsHandle(
91 &myCred);
94 else
95 ret = SEC_E_UNSUPPORTED_FUNCTION;
97 else
98 ret = SEC_E_SECPKG_NOT_FOUND;
100 else
101 ret = SEC_E_SECPKG_NOT_FOUND;
102 return ret;
105 /***********************************************************************
106 * AcquireCredentialsHandleW (SECUR32.@)
108 SECURITY_STATUS WINAPI AcquireCredentialsHandleW(
109 SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, ULONG fCredentialsUse,
110 PLUID pvLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn,
111 PVOID pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
113 SECURITY_STATUS ret;
115 TRACE("%s %s %ld %p %p %p %p %p %p\n", debugstr_w(pszPrincipal),
116 debugstr_w(pszPackage), fCredentialsUse, pvLogonID, pAuthData, pGetKeyFn,
117 pvGetKeyArgument, phCredential, ptsExpiry);
118 if (pszPackage)
120 SecurePackage *package = SECUR32_findPackageW(pszPackage);
122 if (package && package->provider)
124 if (package->provider->fnTableW.AcquireCredentialsHandleW)
126 CredHandle myCred;
128 ret = package->provider->fnTableW.AcquireCredentialsHandleW(
129 pszPrincipal, pszPackage, fCredentialsUse, pvLogonID,
130 pAuthData, pGetKeyFn, pvGetKeyArgument, &myCred,
131 ptsExpiry);
132 if (ret == SEC_E_OK)
134 ret = SECUR32_makeSecHandle(phCredential, package, &myCred);
135 if (ret != SEC_E_OK)
136 package->provider->fnTableW.FreeCredentialsHandle(
137 &myCred);
140 else
141 ret = SEC_E_UNSUPPORTED_FUNCTION;
143 else
144 ret = SEC_E_SECPKG_NOT_FOUND;
146 else
147 ret = SEC_E_SECPKG_NOT_FOUND;
148 return ret;
151 /***********************************************************************
152 * FreeCredentialsHandle (SECUR32.@)
154 SECURITY_STATUS WINAPI FreeCredentialsHandle(
155 PCredHandle phCredential)
157 SECURITY_STATUS ret;
159 TRACE("%p\n", phCredential);
160 if (phCredential)
162 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
163 PCredHandle cred = (PCredHandle)phCredential->dwLower;
165 if (package && package->provider &&
166 package->provider->fnTableW.FreeCredentialsHandle)
167 ret = package->provider->fnTableW.FreeCredentialsHandle(cred);
168 else
169 ret = SEC_E_INVALID_HANDLE;
170 SECUR32_FREE(cred);
172 else
173 ret = SEC_E_INVALID_HANDLE;
174 return ret;
177 /***********************************************************************
178 * QueryCredentialsAttributesA (SECUR32.@)
180 SECURITY_STATUS WINAPI QueryCredentialsAttributesA(
181 PCredHandle phCredential, unsigned long ulAttribute, void *pBuffer)
183 SECURITY_STATUS ret;
185 TRACE("%p %ld %p\n", phCredential, ulAttribute, pBuffer);
186 if (phCredential)
188 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
189 PCredHandle cred = (PCredHandle)phCredential->dwLower;
191 if (package && package->provider)
193 if (package->provider->fnTableA.QueryCredentialsAttributesA)
194 ret = package->provider->fnTableA.QueryCredentialsAttributesA(
195 cred, ulAttribute, pBuffer);
196 else
197 ret = SEC_E_UNSUPPORTED_FUNCTION;
199 else
200 ret = SEC_E_INVALID_HANDLE;
202 else
203 ret = SEC_E_INVALID_HANDLE;
204 return ret;
207 /***********************************************************************
208 * QueryCredentialsAttributesW (SECUR32.@)
210 SECURITY_STATUS WINAPI QueryCredentialsAttributesW(
211 PCredHandle phCredential, unsigned long ulAttribute, void *pBuffer)
213 SECURITY_STATUS ret;
215 TRACE("%p %ld %p\n", phCredential, ulAttribute, pBuffer);
216 if (phCredential)
218 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
219 PCredHandle cred = (PCredHandle)phCredential->dwLower;
221 if (package && package->provider)
223 if (package->provider->fnTableW.QueryCredentialsAttributesW)
224 ret = package->provider->fnTableW.QueryCredentialsAttributesW(
225 cred, ulAttribute, pBuffer);
226 else
227 ret = SEC_E_UNSUPPORTED_FUNCTION;
229 else
230 ret = SEC_E_INVALID_HANDLE;
232 else
233 ret = SEC_E_INVALID_HANDLE;
234 return ret;
237 /***********************************************************************
238 * InitializeSecurityContextA (SECUR32.@)
240 SECURITY_STATUS WINAPI InitializeSecurityContextA(
241 PCredHandle phCredential, PCtxtHandle phContext,
242 SEC_CHAR *pszTargetName, unsigned long fContextReq,
243 unsigned long Reserved1, unsigned long TargetDataRep, PSecBufferDesc pInput,
244 unsigned long Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pOutput,
245 unsigned long *pfContextAttr, PTimeStamp ptsExpiry)
247 SECURITY_STATUS ret;
249 TRACE("%p %p %s %ld %ld %ld %p %ld %p %p %p %p\n", phCredential, phContext,
250 debugstr_a(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
251 Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
252 if (phCredential)
254 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
255 PCredHandle cred = (PCredHandle)phCredential->dwLower;
257 if (package && package->provider)
259 if (package->provider->fnTableA.InitializeSecurityContextA)
261 CtxtHandle myCtxt;
263 ret = package->provider->fnTableA.InitializeSecurityContextA(
264 cred, phContext ? &myCtxt : NULL, pszTargetName, fContextReq,
265 Reserved1, TargetDataRep, pInput, Reserved2, &myCtxt,
266 pOutput, pfContextAttr, ptsExpiry);
267 if (ret == SEC_E_OK)
269 ret = SECUR32_makeSecHandle(phContext, package, &myCtxt);
270 if (ret != SEC_E_OK)
271 package->provider->fnTableW.DeleteSecurityContext(
272 &myCtxt);
275 else
276 ret = SEC_E_UNSUPPORTED_FUNCTION;
278 else
279 ret = SEC_E_INVALID_HANDLE;
281 else
282 ret = SEC_E_INVALID_HANDLE;
283 return ret;
286 /***********************************************************************
287 * InitializeSecurityContextW (SECUR32.@)
289 SECURITY_STATUS WINAPI InitializeSecurityContextW(
290 PCredHandle phCredential, PCtxtHandle phContext,
291 SEC_WCHAR *pszTargetName, unsigned long fContextReq,
292 unsigned long Reserved1, unsigned long TargetDataRep, PSecBufferDesc pInput,
293 unsigned long Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pOutput,
294 unsigned long *pfContextAttr, PTimeStamp ptsExpiry)
296 SECURITY_STATUS ret;
298 TRACE("%p %p %s %ld %ld %ld %p %ld %p %p %p %p\n", phCredential, phContext,
299 debugstr_w(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput,
300 Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry);
301 if (phCredential)
303 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
304 PCredHandle cred = (PCredHandle)phCredential->dwLower;
306 if (package && package->provider)
308 if (package->provider->fnTableW.QueryCredentialsAttributesW)
310 CtxtHandle myCtxt;
312 ret = package->provider->fnTableW.InitializeSecurityContextW(
313 cred, phContext ? &myCtxt : NULL, pszTargetName, fContextReq,
314 Reserved1, TargetDataRep, pInput, Reserved2, &myCtxt,
315 pOutput, pfContextAttr, ptsExpiry);
316 if (ret == SEC_E_OK)
318 ret = SECUR32_makeSecHandle(phContext, package, &myCtxt);
319 if (ret != SEC_E_OK)
320 package->provider->fnTableW.DeleteSecurityContext(
321 &myCtxt);
324 else
325 ret = SEC_E_UNSUPPORTED_FUNCTION;
327 else
328 ret = SEC_E_INVALID_HANDLE;
330 else
331 ret = SEC_E_INVALID_HANDLE;
332 return ret;
335 /***********************************************************************
336 * AcceptSecurityContext (SECUR32.@)
338 SECURITY_STATUS WINAPI AcceptSecurityContext(
339 PCredHandle phCredential, PCtxtHandle phContext, PSecBufferDesc pInput,
340 unsigned long fContextReq, unsigned long TargetDataRep,
341 PCtxtHandle phNewContext, PSecBufferDesc pOutput,
342 unsigned long *pfContextAttr, PTimeStamp ptsExpiry)
344 SECURITY_STATUS ret;
346 TRACE("%p %p %p %ld %ld %p %p %p %p\n", phCredential, phContext, pInput,
347 fContextReq, TargetDataRep, phNewContext, pOutput, pfContextAttr,
348 ptsExpiry);
349 if (phCredential)
351 SecurePackage *package = (SecurePackage *)phCredential->dwUpper;
352 PCredHandle cred = (PCredHandle)phCredential->dwLower;
354 if (package && package->provider)
356 if (package->provider->fnTableW.AcceptSecurityContext)
358 CtxtHandle myCtxt;
360 ret = package->provider->fnTableW.AcceptSecurityContext(
361 cred, phContext ? &myCtxt : NULL, pInput, fContextReq,
362 TargetDataRep, &myCtxt, pOutput, pfContextAttr, ptsExpiry);
363 if (ret == SEC_E_OK)
365 ret = SECUR32_makeSecHandle(phContext, package, &myCtxt);
366 if (ret != SEC_E_OK)
367 package->provider->fnTableW.DeleteSecurityContext(
368 &myCtxt);
371 else
372 ret = SEC_E_UNSUPPORTED_FUNCTION;
374 else
375 ret = SEC_E_INVALID_HANDLE;
377 else
378 ret = SEC_E_INVALID_HANDLE;
379 return ret;
382 /***********************************************************************
383 * CompleteAuthToken (SECUR32.@)
385 SECURITY_STATUS WINAPI CompleteAuthToken(PCtxtHandle phContext,
386 PSecBufferDesc pToken)
388 SECURITY_STATUS ret;
390 TRACE("%p %p\n", phContext, pToken);
391 if (phContext)
393 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
394 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
396 if (package && package->provider)
398 if (package->provider->fnTableW.CompleteAuthToken)
399 ret = package->provider->fnTableW.CompleteAuthToken(ctxt,
400 pToken);
401 else
402 ret = SEC_E_UNSUPPORTED_FUNCTION;
404 else
405 ret = SEC_E_INVALID_HANDLE;
407 else
408 ret = SEC_E_INVALID_HANDLE;
409 return ret;
412 /***********************************************************************
413 * DeleteSecurityContext (SECUR32.@)
415 SECURITY_STATUS WINAPI DeleteSecurityContext(PCtxtHandle phContext)
417 SECURITY_STATUS ret;
419 TRACE("%p\n", phContext);
420 if (phContext)
422 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
423 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
425 if (package && package->provider &&
426 package->provider->fnTableW.DeleteSecurityContext)
427 ret = package->provider->fnTableW.DeleteSecurityContext(ctxt);
428 else
429 ret = SEC_E_INVALID_HANDLE;
430 SECUR32_FREE(ctxt);
432 else
433 ret = SEC_E_INVALID_HANDLE;
434 return ret;
437 /***********************************************************************
438 * ApplyControlToken (SECUR32.@)
440 SECURITY_STATUS WINAPI ApplyControlToken(PCtxtHandle phContext,
441 PSecBufferDesc pInput)
443 SECURITY_STATUS ret;
445 TRACE("%p %p\n", phContext, pInput);
446 if (phContext)
448 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
449 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
451 if (package && package->provider)
453 if (package->provider->fnTableW.ApplyControlToken)
454 ret = package->provider->fnTableW.ApplyControlToken(
455 ctxt, pInput);
456 else
457 ret = SEC_E_UNSUPPORTED_FUNCTION;
459 else
460 ret = SEC_E_INVALID_HANDLE;
462 else
463 ret = SEC_E_INVALID_HANDLE;
464 return ret;
467 /***********************************************************************
468 * QueryContextAttributesA (SECUR32.@)
470 SECURITY_STATUS WINAPI QueryContextAttributesA(PCtxtHandle phContext,
471 unsigned long ulAttribute, void *pBuffer)
473 SECURITY_STATUS ret;
475 TRACE("%p %ld %p\n", phContext, ulAttribute, pBuffer);
476 if (phContext)
478 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
479 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
481 if (package && package->provider)
483 if (package->provider->fnTableA.QueryContextAttributesA)
484 ret = package->provider->fnTableA.QueryContextAttributesA(
485 ctxt, ulAttribute, pBuffer);
486 else
487 ret = SEC_E_UNSUPPORTED_FUNCTION;
489 else
490 ret = SEC_E_INVALID_HANDLE;
492 else
493 ret = SEC_E_INVALID_HANDLE;
494 return ret;
497 /***********************************************************************
498 * QueryContextAttributesW (SECUR32.@)
500 SECURITY_STATUS WINAPI QueryContextAttributesW(PCtxtHandle phContext,
501 unsigned long ulAttribute, void *pBuffer)
503 SECURITY_STATUS ret;
505 TRACE("%p %ld %p\n", phContext, ulAttribute, pBuffer);
506 if (phContext)
508 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
509 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
511 if (package && package->provider)
513 if (package->provider->fnTableW.QueryContextAttributesW)
514 ret = package->provider->fnTableW.QueryContextAttributesW(
515 ctxt, ulAttribute, pBuffer);
516 else
517 ret = SEC_E_UNSUPPORTED_FUNCTION;
519 else
520 ret = SEC_E_INVALID_HANDLE;
522 else
523 ret = SEC_E_INVALID_HANDLE;
524 return ret;
527 /***********************************************************************
528 * ImpersonateSecurityContext (SECUR32.@)
530 SECURITY_STATUS WINAPI ImpersonateSecurityContext(PCtxtHandle phContext)
532 SECURITY_STATUS ret;
534 TRACE("%p\n", phContext);
535 if (phContext)
537 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
538 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
540 if (package && package->provider)
542 if (package->provider->fnTableW.ImpersonateSecurityContext)
543 ret = package->provider->fnTableW.ImpersonateSecurityContext(
544 ctxt);
545 else
546 ret = SEC_E_UNSUPPORTED_FUNCTION;
548 else
549 ret = SEC_E_INVALID_HANDLE;
551 else
552 ret = SEC_E_INVALID_HANDLE;
553 return ret;
556 /***********************************************************************
557 * RevertSecurityContext (SECUR32.@)
559 SECURITY_STATUS WINAPI RevertSecurityContext(PCtxtHandle phContext)
561 SECURITY_STATUS ret;
563 TRACE("%p\n", phContext);
564 if (phContext)
566 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
567 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
569 if (package && package->provider)
571 if (package->provider->fnTableW.RevertSecurityContext)
572 ret = package->provider->fnTableW.RevertSecurityContext(
573 ctxt);
574 else
575 ret = SEC_E_UNSUPPORTED_FUNCTION;
577 else
578 ret = SEC_E_INVALID_HANDLE;
580 else
581 ret = SEC_E_INVALID_HANDLE;
582 return ret;
585 /***********************************************************************
586 * MakeSignature (SECUR32.@)
588 SECURITY_STATUS WINAPI MakeSignature(PCtxtHandle phContext, ULONG fQOP,
589 PSecBufferDesc pMessage, ULONG MessageSeqNo)
591 SECURITY_STATUS ret;
593 TRACE("%p %ld %p %ld\n", phContext, fQOP, pMessage, MessageSeqNo);
594 if (phContext)
596 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
597 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
599 if (package && package->provider)
601 if (package->provider->fnTableW.MakeSignature)
602 ret = package->provider->fnTableW.MakeSignature(
603 ctxt, fQOP, pMessage, MessageSeqNo);
604 else
605 ret = SEC_E_UNSUPPORTED_FUNCTION;
607 else
608 ret = SEC_E_INVALID_HANDLE;
610 else
611 ret = SEC_E_INVALID_HANDLE;
612 return ret;
615 /***********************************************************************
616 * VerifySignature (SECUR32.@)
618 SECURITY_STATUS WINAPI VerifySignature(PCtxtHandle phContext,
619 PSecBufferDesc pMessage, ULONG MessageSeqNo, PULONG pfQOP)
621 SECURITY_STATUS ret;
623 TRACE("%p %p %ld %p\n", phContext, pMessage, MessageSeqNo, pfQOP);
624 if (phContext)
626 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
627 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
629 if (package && package->provider)
631 if (package->provider->fnTableW.VerifySignature)
632 ret = package->provider->fnTableW.VerifySignature(
633 ctxt, pMessage, MessageSeqNo, pfQOP);
634 else
635 ret = SEC_E_UNSUPPORTED_FUNCTION;
637 else
638 ret = SEC_E_INVALID_HANDLE;
640 else
641 ret = SEC_E_INVALID_HANDLE;
642 return ret;
645 /***********************************************************************
646 * QuerySecurityPackageInfoA (SECUR32.@)
648 SECURITY_STATUS WINAPI QuerySecurityPackageInfoA(SEC_CHAR *pszPackageName,
649 PSecPkgInfoA *ppPackageInfo)
651 SECURITY_STATUS ret;
653 TRACE("%s %p\n", debugstr_a(pszPackageName), ppPackageInfo);
654 if (pszPackageName)
656 SecurePackage *package = SECUR32_findPackageA(pszPackageName);
658 if (package)
660 size_t bytesNeeded = sizeof(SecPkgInfoA);
661 int nameLen = 0, commentLen = 0;
663 if (package->infoW.Name)
665 nameLen = WideCharToMultiByte(CP_ACP, 0,
666 package->infoW.Name, -1, NULL, 0, NULL, NULL);
667 bytesNeeded += nameLen;
669 if (package->infoW.Comment)
671 commentLen = WideCharToMultiByte(CP_ACP, 0,
672 package->infoW.Comment, -1, NULL, 0, NULL, NULL);
673 bytesNeeded += commentLen;
675 *ppPackageInfo = (PSecPkgInfoA)SECUR32_ALLOC(bytesNeeded);
676 if (*ppPackageInfo)
678 PSTR nextString = (PSTR)((PBYTE)*ppPackageInfo +
679 sizeof(SecPkgInfoA));
681 memcpy(*ppPackageInfo, &package->infoW, sizeof(package->infoW));
682 if (package->infoW.Name)
684 (*ppPackageInfo)->Name = nextString;
685 nextString += WideCharToMultiByte(CP_ACP, 0,
686 package->infoW.Name, -1, nextString, nameLen, NULL, NULL);
688 else
689 (*ppPackageInfo)->Name = NULL;
690 if (package->infoW.Comment)
692 (*ppPackageInfo)->Comment = nextString;
693 nextString += WideCharToMultiByte(CP_ACP, 0,
694 package->infoW.Comment, -1, nextString, commentLen, NULL,
695 NULL);
697 else
698 (*ppPackageInfo)->Comment = NULL;
699 ret = SEC_E_OK;
701 else
702 ret = SEC_E_INSUFFICIENT_MEMORY;
704 else
705 ret = SEC_E_SECPKG_NOT_FOUND;
707 else
708 ret = SEC_E_SECPKG_NOT_FOUND;
709 return ret;
712 /***********************************************************************
713 * QuerySecurityPackageInfoW (SECUR32.@)
715 SECURITY_STATUS WINAPI QuerySecurityPackageInfoW(SEC_WCHAR *pszPackageName,
716 PSecPkgInfoW *ppPackageInfo)
718 SECURITY_STATUS ret;
719 SecurePackage *package = SECUR32_findPackageW(pszPackageName);
721 TRACE("%s %p\n", debugstr_w(pszPackageName), ppPackageInfo);
722 if (package)
724 size_t bytesNeeded = sizeof(SecPkgInfoW);
725 int nameLen = 0, commentLen = 0;
727 if (package->infoW.Name)
729 nameLen = lstrlenW(package->infoW.Name) + 1;
730 bytesNeeded += nameLen * sizeof(WCHAR);
732 if (package->infoW.Comment)
734 commentLen = lstrlenW(package->infoW.Comment) + 1;
735 bytesNeeded += commentLen * sizeof(WCHAR);
737 *ppPackageInfo = (PSecPkgInfoW)SECUR32_ALLOC(bytesNeeded);
738 if (*ppPackageInfo)
740 PWSTR nextString = (PWSTR)((PBYTE)*ppPackageInfo +
741 sizeof(SecPkgInfoW));
743 memcpy(*ppPackageInfo, &package->infoW, sizeof(package->infoW));
744 if (package->infoW.Name)
746 (*ppPackageInfo)->Name = nextString;
747 lstrcpynW(nextString, package->infoW.Name, nameLen);
748 nextString += nameLen;
750 else
751 (*ppPackageInfo)->Name = NULL;
752 if (package->infoW.Comment)
754 (*ppPackageInfo)->Comment = nextString;
755 lstrcpynW(nextString, package->infoW.Comment, commentLen);
756 nextString += commentLen;
758 else
759 (*ppPackageInfo)->Comment = NULL;
760 ret = SEC_E_OK;
762 else
763 ret = SEC_E_INSUFFICIENT_MEMORY;
765 else
766 ret = SEC_E_SECPKG_NOT_FOUND;
767 return ret;
770 /***********************************************************************
771 * ExportSecurityContext (SECUR32.@)
773 SECURITY_STATUS WINAPI ExportSecurityContext(PCtxtHandle phContext,
774 ULONG fFlags, PSecBuffer pPackedContext, void **pToken)
776 SECURITY_STATUS ret;
778 TRACE("%p %ld %p %p\n", phContext, fFlags, pPackedContext, pToken);
779 if (phContext)
781 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
782 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
784 if (package && package->provider)
786 if (package->provider->fnTableW.ExportSecurityContext)
787 ret = package->provider->fnTableW.ExportSecurityContext(
788 ctxt, fFlags, pPackedContext, pToken);
789 else
790 ret = SEC_E_UNSUPPORTED_FUNCTION;
792 else
793 ret = SEC_E_INVALID_HANDLE;
795 else
796 ret = SEC_E_INVALID_HANDLE;
797 return ret;
800 /***********************************************************************
801 * ImportSecurityContextA (SECUR32.@)
803 SECURITY_STATUS WINAPI ImportSecurityContextA(SEC_CHAR *pszPackage,
804 PSecBuffer pPackedContext, void *Token, PCtxtHandle phContext)
806 SECURITY_STATUS ret;
807 SecurePackage *package = SECUR32_findPackageA(pszPackage);
809 TRACE("%s %p %p %p\n", debugstr_a(pszPackage), pPackedContext, Token,
810 phContext);
811 if (package && package->provider)
813 if (package->provider->fnTableA.ImportSecurityContextA)
815 CtxtHandle myCtxt;
817 ret = package->provider->fnTableA.ImportSecurityContextA(
818 pszPackage, pPackedContext, Token, &myCtxt);
819 if (ret == SEC_E_OK)
821 ret = SECUR32_makeSecHandle(phContext, package, &myCtxt);
822 if (ret != SEC_E_OK)
823 package->provider->fnTableW.DeleteSecurityContext(&myCtxt);
826 else
827 ret = SEC_E_UNSUPPORTED_FUNCTION;
829 else
830 ret = SEC_E_SECPKG_NOT_FOUND;
831 return ret;
835 /***********************************************************************
836 * ImportSecurityContextW (SECUR32.@)
838 SECURITY_STATUS WINAPI ImportSecurityContextW(SEC_WCHAR *pszPackage,
839 PSecBuffer pPackedContext, void *Token, PCtxtHandle phContext)
841 SECURITY_STATUS ret;
842 SecurePackage *package = SECUR32_findPackageW(pszPackage);
844 TRACE("%s %p %p %p\n", debugstr_w(pszPackage), pPackedContext, Token,
845 phContext);
846 if (package && package->provider)
848 if (package->provider->fnTableW.ImportSecurityContextW)
850 CtxtHandle myCtxt;
852 ret = package->provider->fnTableW.ImportSecurityContextW(
853 pszPackage, pPackedContext, Token, &myCtxt);
854 if (ret == SEC_E_OK)
856 ret = SECUR32_makeSecHandle(phContext, package, &myCtxt);
857 if (ret != SEC_E_OK)
858 package->provider->fnTableW.DeleteSecurityContext(&myCtxt);
861 else
862 ret = SEC_E_UNSUPPORTED_FUNCTION;
864 else
865 ret = SEC_E_SECPKG_NOT_FOUND;
866 return ret;
869 /***********************************************************************
870 * AddCredentialsA (SECUR32.@)
872 SECURITY_STATUS WINAPI AddCredentialsA(PCredHandle hCredentials,
873 SEC_CHAR *pszPrincipal, SEC_CHAR *pszPackage, unsigned long fCredentialUse,
874 void *pAuthData, SEC_GET_KEY_FN pGetKeyFn, void *pvGetKeyArgument,
875 PTimeStamp ptsExpiry)
877 SECURITY_STATUS ret;
879 TRACE("%p %s %s %ld %p %p %p %p\n", hCredentials, debugstr_a(pszPrincipal),
880 debugstr_a(pszPackage), fCredentialUse, pAuthData, pGetKeyFn,
881 pvGetKeyArgument, ptsExpiry);
882 if (hCredentials)
884 SecurePackage *package = (SecurePackage *)hCredentials->dwUpper;
885 PCredHandle cred = (PCtxtHandle)hCredentials->dwLower;
887 if (package && package->provider)
889 if (package->provider->fnTableA.AddCredentialsA)
890 ret = package->provider->fnTableA.AddCredentialsA(
891 cred, pszPrincipal, pszPackage, fCredentialUse, pAuthData,
892 pGetKeyFn, pvGetKeyArgument, ptsExpiry);
893 else
894 ret = SEC_E_UNSUPPORTED_FUNCTION;
896 else
897 ret = SEC_E_INVALID_HANDLE;
899 else
900 ret = SEC_E_INVALID_HANDLE;
901 return ret;
904 /***********************************************************************
905 * AddCredentialsW (SECUR32.@)
907 SECURITY_STATUS WINAPI AddCredentialsW(PCredHandle hCredentials,
908 SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, unsigned long fCredentialUse,
909 void *pAuthData, SEC_GET_KEY_FN pGetKeyFn, void *pvGetKeyArgument,
910 PTimeStamp ptsExpiry)
912 SECURITY_STATUS ret;
914 TRACE("%p %s %s %ld %p %p %p %p\n", hCredentials, debugstr_w(pszPrincipal),
915 debugstr_w(pszPackage), fCredentialUse, pAuthData, pGetKeyFn,
916 pvGetKeyArgument, ptsExpiry);
917 if (hCredentials)
919 SecurePackage *package = (SecurePackage *)hCredentials->dwUpper;
920 PCredHandle cred = (PCtxtHandle)hCredentials->dwLower;
922 if (package && package->provider)
924 if (package->provider->fnTableW.AddCredentialsW)
925 ret = package->provider->fnTableW.AddCredentialsW(
926 cred, pszPrincipal, pszPackage, fCredentialUse, pAuthData,
927 pGetKeyFn, pvGetKeyArgument, ptsExpiry);
928 else
929 ret = SEC_E_UNSUPPORTED_FUNCTION;
931 else
932 ret = SEC_E_INVALID_HANDLE;
934 else
935 ret = SEC_E_INVALID_HANDLE;
936 return ret;
939 /***********************************************************************
940 * QuerySecurityContextToken (SECUR32.@)
942 SECURITY_STATUS WINAPI QuerySecurityContextToken(PCtxtHandle phContext,
943 HANDLE *phToken)
945 SECURITY_STATUS ret;
947 TRACE("%p %p\n", phContext, phToken);
948 if (phContext)
950 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
951 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
953 if (package && package->provider)
955 if (package->provider->fnTableW.QuerySecurityContextToken)
956 ret = package->provider->fnTableW.QuerySecurityContextToken(
957 ctxt, phToken);
958 else
959 ret = SEC_E_UNSUPPORTED_FUNCTION;
961 else
962 ret = SEC_E_INVALID_HANDLE;
964 else
965 ret = SEC_E_INVALID_HANDLE;
966 return ret;
969 /***********************************************************************
970 * EncryptMessage (SECUR32.@)
972 SECURITY_STATUS WINAPI EncryptMessage(PCtxtHandle phContext, ULONG fQOP,
973 PSecBufferDesc pMessage, ULONG MessageSeqNo)
975 SECURITY_STATUS ret;
977 TRACE("%p %ld %p %ld\n", phContext, fQOP, pMessage, MessageSeqNo);
978 if (phContext)
980 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
981 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
983 if (package && package->provider)
985 if (package->provider->fnTableW.EncryptMessage)
986 ret = package->provider->fnTableW.EncryptMessage(
987 ctxt, fQOP, pMessage, MessageSeqNo);
988 else
989 ret = SEC_E_UNSUPPORTED_FUNCTION;
991 else
992 ret = SEC_E_INVALID_HANDLE;
994 else
995 ret = SEC_E_INVALID_HANDLE;
996 return ret;
999 /***********************************************************************
1000 * DecryptMessage (SECUR32.@)
1002 SECURITY_STATUS WINAPI DecryptMessage(PCtxtHandle phContext,
1003 PSecBufferDesc pMessage, ULONG MessageSeqNo, PULONG pfQOP)
1005 SECURITY_STATUS ret;
1007 TRACE("%p %p %ld %p\n", phContext, pMessage, MessageSeqNo, pfQOP);
1008 if (phContext)
1010 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
1011 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
1013 if (package && package->provider)
1015 if (package->provider->fnTableW.DecryptMessage)
1016 ret = package->provider->fnTableW.DecryptMessage(
1017 ctxt, pMessage, MessageSeqNo, pfQOP);
1018 else
1019 ret = SEC_E_UNSUPPORTED_FUNCTION;
1021 else
1022 ret = SEC_E_INVALID_HANDLE;
1024 else
1025 ret = SEC_E_INVALID_HANDLE;
1026 return ret;
1029 /***********************************************************************
1030 * SetContextAttributesA (SECUR32.@)
1032 SECURITY_STATUS WINAPI SetContextAttributesA(PCtxtHandle phContext,
1033 unsigned long ulAttribute, void *pBuffer, unsigned long cbBuffer)
1035 SECURITY_STATUS ret;
1037 TRACE("%p %ld %p %ld\n", phContext, ulAttribute, pBuffer, cbBuffer);
1038 if (phContext)
1040 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
1041 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
1043 if (package && package->provider)
1045 if (package->provider->fnTableA.SetContextAttributesA)
1046 ret = package->provider->fnTableA.SetContextAttributesA(
1047 ctxt, ulAttribute, pBuffer, cbBuffer);
1048 else
1049 ret = SEC_E_UNSUPPORTED_FUNCTION;
1051 else
1052 ret = SEC_E_INVALID_HANDLE;
1054 else
1055 ret = SEC_E_INVALID_HANDLE;
1056 return ret;
1059 /***********************************************************************
1060 * SetContextAttributesW (SECUR32.@)
1062 SECURITY_STATUS WINAPI SetContextAttributesW(PCtxtHandle phContext,
1063 unsigned long ulAttribute, void *pBuffer, unsigned long cbBuffer)
1065 SECURITY_STATUS ret;
1067 TRACE("%p %ld %p %ld\n", phContext, ulAttribute, pBuffer, cbBuffer);
1068 if (phContext)
1070 SecurePackage *package = (SecurePackage *)phContext->dwUpper;
1071 PCtxtHandle ctxt = (PCtxtHandle)phContext->dwLower;
1073 if (package && package->provider)
1075 if (package->provider->fnTableW.SetContextAttributesW)
1076 ret = package->provider->fnTableW.SetContextAttributesW(
1077 ctxt, ulAttribute, pBuffer, cbBuffer);
1078 else
1079 ret = SEC_E_UNSUPPORTED_FUNCTION;
1081 else
1082 ret = SEC_E_INVALID_HANDLE;
1084 else
1085 ret = SEC_E_INVALID_HANDLE;
1086 return ret;