21#include <winpr/config.h>
22#include <winpr/assert.h>
23#include <winpr/windows.h>
26#include <winpr/sspi.h>
28#include <winpr/print.h>
32#include "sspi_winpr.h"
36#define TAG WINPR_TAG("sspi")
41#include "NTLM/ntlm_export.h"
42#include "CredSSP/credssp.h"
43#include "Kerberos/kerberos.h"
44#include "Negotiate/negotiate.h"
45#include "Schannel/schannel.h"
47static const SecPkgInfoA* SecPkgInfoA_LIST[] = { &NTLM_SecPkgInfoA, &KERBEROS_SecPkgInfoA,
48 &NEGOTIATE_SecPkgInfoA, &CREDSSP_SecPkgInfoA,
49 &SCHANNEL_SecPkgInfoA };
51static const SecPkgInfoW* SecPkgInfoW_LIST[] = { &NTLM_SecPkgInfoW, &KERBEROS_SecPkgInfoW,
52 &NEGOTIATE_SecPkgInfoW, &CREDSSP_SecPkgInfoW,
53 &SCHANNEL_SecPkgInfoW };
59} SecurityFunctionTableA_NAME;
63 const SEC_WCHAR* Name;
65} SecurityFunctionTableW_NAME;
67static const SecurityFunctionTableA_NAME SecurityFunctionTableA_NAME_LIST[] = {
68 {
"NTLM", &NTLM_SecurityFunctionTableA },
69 {
"Kerberos", &KERBEROS_SecurityFunctionTableA },
70 {
"Negotiate", &NEGOTIATE_SecurityFunctionTableA },
71 {
"CREDSSP", &CREDSSP_SecurityFunctionTableA },
72 {
"Schannel", &SCHANNEL_SecurityFunctionTableA }
75static WCHAR BUFFER_NAME_LIST_W[5][32] = WINPR_C_ARRAY_INIT;
77static const SecurityFunctionTableW_NAME SecurityFunctionTableW_NAME_LIST[] = {
78 { BUFFER_NAME_LIST_W[0], &NTLM_SecurityFunctionTableW },
79 { BUFFER_NAME_LIST_W[1], &KERBEROS_SecurityFunctionTableW },
80 { BUFFER_NAME_LIST_W[2], &NEGOTIATE_SecurityFunctionTableW },
81 { BUFFER_NAME_LIST_W[3], &CREDSSP_SecurityFunctionTableW },
82 { BUFFER_NAME_LIST_W[4], &SCHANNEL_SecurityFunctionTableW }
88 UINT32 allocatorIndex;
89} CONTEXT_BUFFER_ALLOC_ENTRY;
95 CONTEXT_BUFFER_ALLOC_ENTRY* entries;
96} CONTEXT_BUFFER_ALLOC_TABLE;
98static CONTEXT_BUFFER_ALLOC_TABLE ContextBufferAllocTable = WINPR_C_ARRAY_INIT;
100static int sspi_ContextBufferAllocTableNew(
void)
103 ContextBufferAllocTable.entries =
nullptr;
104 ContextBufferAllocTable.cEntries = 0;
105 ContextBufferAllocTable.cMaxEntries = 4;
106 size =
sizeof(CONTEXT_BUFFER_ALLOC_ENTRY) * ContextBufferAllocTable.cMaxEntries;
107 ContextBufferAllocTable.entries = (CONTEXT_BUFFER_ALLOC_ENTRY*)calloc(1, size);
109 if (!ContextBufferAllocTable.entries)
115static int sspi_ContextBufferAllocTableGrow(
void)
118 CONTEXT_BUFFER_ALLOC_ENTRY* entries =
nullptr;
119 ContextBufferAllocTable.cEntries = 0;
120 ContextBufferAllocTable.cMaxEntries *= 2;
121 size =
sizeof(CONTEXT_BUFFER_ALLOC_ENTRY) * ContextBufferAllocTable.cMaxEntries;
126 entries = (CONTEXT_BUFFER_ALLOC_ENTRY*)realloc(ContextBufferAllocTable.entries, size);
130 free(ContextBufferAllocTable.entries);
134 ContextBufferAllocTable.entries = entries;
135 ZeroMemory((
void*)&ContextBufferAllocTable.entries[ContextBufferAllocTable.cMaxEntries / 2],
140static void sspi_ContextBufferAllocTableFree(
void)
142 if (ContextBufferAllocTable.cEntries != 0)
143 WLog_ERR(TAG,
"ContextBufferAllocTable.entries == %" PRIu32,
144 ContextBufferAllocTable.cEntries);
146 ContextBufferAllocTable.cEntries = ContextBufferAllocTable.cMaxEntries = 0;
147 free(ContextBufferAllocTable.entries);
148 ContextBufferAllocTable.entries =
nullptr;
151void* sspi_ContextBufferAlloc(UINT32 allocatorIndex,
size_t size)
153 void* contextBuffer =
nullptr;
155 for (UINT32 index = 0; index < ContextBufferAllocTable.cMaxEntries; index++)
157 if (!ContextBufferAllocTable.entries[index].contextBuffer)
159 contextBuffer = calloc(1, size);
164 ContextBufferAllocTable.cEntries++;
165 ContextBufferAllocTable.entries[index].contextBuffer = contextBuffer;
166 ContextBufferAllocTable.entries[index].allocatorIndex = allocatorIndex;
167 return ContextBufferAllocTable.entries[index].contextBuffer;
173 if (sspi_ContextBufferAllocTableGrow() < 0)
177 return sspi_ContextBufferAlloc(allocatorIndex, size);
189 size_t userLength = 0;
190 size_t domainLength = 0;
191 size_t passwordLength = 0;
196 if (credentials->ntlmSettings.
samFile)
197 free(credentials->ntlmSettings.
samFile);
199 userLength = credentials->identity.UserLength;
200 domainLength = credentials->identity.DomainLength;
201 passwordLength = credentials->identity.PasswordLength;
203 if (credentials->identity.Flags & SEC_WINNT_AUTH_IDENTITY_UNICODE)
210 if (credentials->identity.User)
211 memset(credentials->identity.User, 0, userLength);
212 if (credentials->identity.Domain)
213 memset(credentials->identity.Domain, 0, domainLength);
214 if (credentials->identity.Password)
215 memset(credentials->identity.Password, 0, passwordLength);
216 free(credentials->identity.User);
217 free(credentials->identity.Domain);
218 free(credentials->identity.Password);
256 SecInvalidateHandle(handle);
260void* sspi_SecureHandleGetLowerPointer(
SecHandle* handle)
262 void* pointer =
nullptr;
264 if (!handle || !SecIsValidHandle(handle) || !handle->dwLower)
267 pointer = (
void*)~((
size_t)handle->dwLower);
271void sspi_SecureHandleInvalidate(
SecHandle* handle)
280void sspi_SecureHandleSetLowerPointer(
SecHandle* handle,
void* pointer)
285 handle->dwLower = (ULONG_PTR)(~((
size_t)pointer));
288void* sspi_SecureHandleGetUpperPointer(
SecHandle* handle)
290 void* pointer =
nullptr;
292 if (!handle || !SecIsValidHandle(handle) || !handle->dwUpper)
295 pointer = (
void*)~((
size_t)handle->dwUpper);
299void sspi_SecureHandleSetUpperPointer(
SecHandle* handle,
void* pointer)
304 handle->dwUpper = (ULONG_PTR)(~((
size_t)pointer));
307void sspi_SecureHandleFree(
SecHandle* handle)
312int sspi_SetAuthIdentityW(SEC_WINNT_AUTH_IDENTITY* identity,
const WCHAR* user,
const WCHAR* domain,
313 const WCHAR* password)
315 return sspi_SetAuthIdentityWithLengthW(identity, user, user ? _wcslen(user) : 0, domain,
316 domain ? _wcslen(domain) : 0, password,
317 password ? _wcslen(password) : 0);
320static BOOL copy(WCHAR** dst, ULONG* dstLen,
const WCHAR* what,
size_t len)
323 WINPR_ASSERT(dstLen);
328 if (len > UINT32_MAX)
332 if (!what && (len != 0))
334 if (!what && (len == 0))
337 *dst = calloc(
sizeof(WCHAR), len + 1);
341 memcpy(*dst, what, len *
sizeof(WCHAR));
342 *dstLen = WINPR_ASSERTING_INT_CAST(UINT32, len);
346int sspi_SetAuthIdentityWithLengthW(SEC_WINNT_AUTH_IDENTITY* identity,
const WCHAR* user,
347 size_t userLen,
const WCHAR* domain,
size_t domainLen,
348 const WCHAR* password,
size_t passwordLen)
350 WINPR_ASSERT(identity);
351 sspi_FreeAuthIdentity(identity);
352 identity->Flags &= (uint32_t)~SEC_WINNT_AUTH_IDENTITY_ANSI;
353 identity->Flags |= SEC_WINNT_AUTH_IDENTITY_UNICODE;
355 if (!copy(&identity->User, &identity->UserLength, user, userLen))
358 if (!copy(&identity->Domain, &identity->DomainLength, domain, domainLen))
361 if (!copy(&identity->Password, &identity->PasswordLength, password, passwordLen))
367static void zfree(WCHAR* str,
size_t len)
370 memset(str, 0, len *
sizeof(WCHAR));
374int sspi_SetAuthIdentityA(SEC_WINNT_AUTH_IDENTITY* identity,
const char* user,
const char* domain,
375 const char* password)
378 size_t unicodeUserLenW = 0;
379 size_t unicodeDomainLenW = 0;
380 size_t unicodePasswordLenW = 0;
381 LPWSTR unicodeUser =
nullptr;
382 LPWSTR unicodeDomain =
nullptr;
383 LPWSTR unicodePassword =
nullptr;
386 unicodeUser = ConvertUtf8ToWCharAlloc(user, &unicodeUserLenW);
389 unicodeDomain = ConvertUtf8ToWCharAlloc(domain, &unicodeDomainLenW);
392 unicodePassword = ConvertUtf8ToWCharAlloc(password, &unicodePasswordLenW);
394 rc = sspi_SetAuthIdentityWithLengthW(identity, unicodeUser, unicodeUserLenW, unicodeDomain,
395 unicodeDomainLenW, unicodePassword, unicodePasswordLenW);
397 zfree(unicodeUser, unicodeUserLenW);
398 zfree(unicodeDomain, unicodeDomainLenW);
399 zfree(unicodePassword, unicodePasswordLenW);
403UINT32 sspi_GetAuthIdentityVersion(
const void* identity)
410 version = *((
const UINT32*)identity);
412 if ((version == SEC_WINNT_AUTH_IDENTITY_VERSION) ||
413 (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2))
421UINT32 sspi_GetAuthIdentityFlags(
const void* identity)
429 version = sspi_GetAuthIdentityVersion(identity);
431 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
433 flags = ((
const SEC_WINNT_AUTH_IDENTITY_EX*)identity)->Flags;
435 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
441 flags = ((
const SEC_WINNT_AUTH_IDENTITY*)identity)->Flags;
447BOOL sspi_GetAuthIdentityUserDomainW(
const void* identity,
const WCHAR** pUser, UINT32* pUserLength,
448 const WCHAR** pDomain, UINT32* pDomainLength)
455 version = sspi_GetAuthIdentityVersion(identity);
457 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
460 *pUser = (
const WCHAR*)id->User;
461 *pUserLength =
id->UserLength;
462 *pDomain = (
const WCHAR*)id->Domain;
463 *pDomainLength =
id->DomainLength;
465 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
468 UINT32 UserOffset =
id->UserOffset;
469 UINT32 DomainOffset =
id->DomainOffset;
470 *pUser = (
const WCHAR*)&((
const uint8_t*)identity)[UserOffset];
471 *pUserLength =
id->UserLength / 2;
472 *pDomain = (
const WCHAR*)&((
const uint8_t*)identity)[DomainOffset];
473 *pDomainLength =
id->DomainLength / 2;
478 *pUser = (
const WCHAR*)id->User;
479 *pUserLength =
id->UserLength;
480 *pDomain = (
const WCHAR*)id->Domain;
481 *pDomainLength =
id->DomainLength;
487BOOL sspi_GetAuthIdentityUserDomainA(
const void* identity,
const char** pUser, UINT32* pUserLength,
488 const char** pDomain, UINT32* pDomainLength)
495 version = sspi_GetAuthIdentityVersion(identity);
497 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
500 *pUser = (
const char*)id->User;
501 *pUserLength =
id->UserLength;
502 *pDomain = (
const char*)id->Domain;
503 *pDomainLength =
id->DomainLength;
505 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
508 UINT32 UserOffset =
id->UserOffset;
509 UINT32 DomainOffset =
id->DomainOffset;
510 *pUser = (
const char*)&((
const uint8_t*)identity)[UserOffset];
511 *pUserLength =
id->UserLength;
512 *pDomain = (
const char*)&((
const uint8_t*)identity)[DomainOffset];
513 *pDomainLength =
id->DomainLength;
518 *pUser = (
const char*)id->User;
519 *pUserLength =
id->UserLength;
520 *pDomain = (
const char*)id->Domain;
521 *pDomainLength =
id->DomainLength;
527BOOL sspi_GetAuthIdentityPasswordW(
const void* identity,
const WCHAR** pPassword,
528 UINT32* pPasswordLength)
535 version = sspi_GetAuthIdentityVersion(identity);
537 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
540 *pPassword = (
const WCHAR*)id->Password;
541 *pPasswordLength =
id->PasswordLength;
543 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
550 *pPassword = (
const WCHAR*)id->Password;
551 *pPasswordLength =
id->PasswordLength;
557BOOL sspi_GetAuthIdentityPasswordA(
const void* identity,
const char** pPassword,
558 UINT32* pPasswordLength)
565 version = sspi_GetAuthIdentityVersion(identity);
567 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
570 *pPassword = (
const char*)id->Password;
571 *pPasswordLength =
id->PasswordLength;
573 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
580 *pPassword = (
const char*)id->Password;
581 *pPasswordLength =
id->PasswordLength;
588 char** pDomain,
char** pPassword)
590 BOOL success = FALSE;
591 const char* UserA =
nullptr;
592 const char* DomainA =
nullptr;
593 const char* PasswordA =
nullptr;
594 const WCHAR* UserW =
nullptr;
595 const WCHAR* DomainW =
nullptr;
596 const WCHAR* PasswordW =
nullptr;
597 UINT32 UserLength = 0;
598 UINT32 DomainLength = 0;
599 UINT32 PasswordLength = 0;
601 if (!identity || !pUser || !pDomain || !pPassword)
604 *pUser = *pDomain = *pPassword =
nullptr;
606 UINT32 identityFlags = sspi_GetAuthIdentityFlags(identity);
608 if ((identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI) != 0)
610 if (!sspi_GetAuthIdentityUserDomainA(identity, &UserA, &UserLength, &DomainA,
614 if (!sspi_GetAuthIdentityPasswordA(identity, &PasswordA, &PasswordLength))
617 if (UserA && UserLength)
619 *pUser = _strdup(UserA);
625 if (DomainA && DomainLength)
627 *pDomain = _strdup(DomainA);
633 if (PasswordA && PasswordLength)
635 *pPassword = _strdup(PasswordA);
643 else if ((identityFlags & SEC_WINNT_AUTH_IDENTITY_UNICODE) != 0)
645 if (!sspi_GetAuthIdentityUserDomainW(identity, &UserW, &UserLength, &DomainW,
649 if (!sspi_GetAuthIdentityPasswordW(identity, &PasswordW, &PasswordLength))
652 if (UserW && (UserLength > 0))
654 *pUser = ConvertWCharNToUtf8Alloc(UserW, UserLength,
nullptr);
659 if (DomainW && (DomainLength > 0))
661 *pDomain = ConvertWCharNToUtf8Alloc(DomainW, DomainLength,
nullptr);
666 if (PasswordW && (PasswordLength > 0))
668 *pPassword = ConvertWCharNToUtf8Alloc(PasswordW, PasswordLength,
nullptr);
681 WCHAR** pDomain, WCHAR** pPassword)
683 BOOL success = FALSE;
684 const char* UserA =
nullptr;
685 const char* DomainA =
nullptr;
686 const char* PasswordA =
nullptr;
687 const WCHAR* UserW =
nullptr;
688 const WCHAR* DomainW =
nullptr;
689 const WCHAR* PasswordW =
nullptr;
690 UINT32 UserLength = 0;
691 UINT32 DomainLength = 0;
692 UINT32 PasswordLength = 0;
694 if (!identity || !pUser || !pDomain || !pPassword)
697 *pUser = *pDomain = *pPassword =
nullptr;
699 UINT32 identityFlags = sspi_GetAuthIdentityFlags(identity);
701 if ((identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI) != 0)
703 if (!sspi_GetAuthIdentityUserDomainA(identity, &UserA, &UserLength, &DomainA,
707 if (!sspi_GetAuthIdentityPasswordA(identity, &PasswordA, &PasswordLength))
710 if (UserA && (UserLength > 0))
712 WCHAR* ptr = ConvertUtf8NToWCharAlloc(UserA, UserLength,
nullptr);
719 if (DomainA && (DomainLength > 0))
721 WCHAR* ptr = ConvertUtf8NToWCharAlloc(DomainA, DomainLength,
nullptr);
727 if (PasswordA && (PasswordLength > 0))
729 WCHAR* ptr = ConvertUtf8NToWCharAlloc(PasswordA, PasswordLength,
nullptr);
738 else if ((identityFlags & SEC_WINNT_AUTH_IDENTITY_UNICODE) != 0)
740 if (!sspi_GetAuthIdentityUserDomainW(identity, &UserW, &UserLength, &DomainW,
744 if (!sspi_GetAuthIdentityPasswordW(identity, &PasswordW, &PasswordLength))
747 if (UserW && UserLength)
749 *pUser = winpr_wcsndup(UserW, UserLength /
sizeof(WCHAR));
755 if (DomainW && DomainLength)
757 *pDomain = winpr_wcsndup(DomainW, DomainLength /
sizeof(WCHAR));
763 if (PasswordW && PasswordLength)
765 *pPassword = winpr_wcsndup(PasswordW, PasswordLength /
sizeof(WCHAR));
781 UINT32 identityFlags = 0;
782 char* PackageList =
nullptr;
783 const char* PackageListA =
nullptr;
784 const WCHAR* PackageListW =
nullptr;
785 UINT32 PackageListLength = 0;
786 UINT32 PackageListOffset = 0;
787 const void* pAuthData = (
const void*)identity;
792 version = sspi_GetAuthIdentityVersion(pAuthData);
793 identityFlags = sspi_GetAuthIdentityFlags(pAuthData);
795 if ((identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI) != 0)
797 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
800 PackageListA = (
const char*)ad->PackageList;
801 PackageListLength = ad->PackageListLength;
804 if (PackageListA && PackageListLength)
806 PackageList = _strdup(PackageListA);
809 else if ((identityFlags & SEC_WINNT_AUTH_IDENTITY_UNICODE) != 0)
811 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
814 PackageListW = (
const WCHAR*)ad->PackageList;
815 PackageListLength = ad->PackageListLength;
817 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
820 PackageListOffset = ad->PackageListOffset;
821 PackageListW = (
const WCHAR*)&((
const uint8_t*)pAuthData)[PackageListOffset];
822 PackageListLength = ad->PackageListLength / 2;
825 if (PackageListW && (PackageListLength > 0))
826 PackageList = ConvertWCharNToUtf8Alloc(PackageListW, PackageListLength,
nullptr);
831 *pPackageList = PackageList;
838int sspi_CopyAuthIdentity(SEC_WINNT_AUTH_IDENTITY* identity,
842 UINT32 identityFlags = 0;
843 const char* UserA =
nullptr;
844 const char* DomainA =
nullptr;
845 const char* PasswordA =
nullptr;
846 const WCHAR* UserW =
nullptr;
847 const WCHAR* DomainW =
nullptr;
848 const WCHAR* PasswordW =
nullptr;
849 UINT32 UserLength = 0;
850 UINT32 DomainLength = 0;
851 UINT32 PasswordLength = 0;
853 sspi_FreeAuthIdentity(identity);
855 identityFlags = sspi_GetAuthIdentityFlags(srcIdentity);
857 identity->Flags = identityFlags;
859 if ((identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI) != 0)
861 if (!sspi_GetAuthIdentityUserDomainA(srcIdentity, &UserA, &UserLength, &DomainA,
867 if (!sspi_GetAuthIdentityPasswordA(srcIdentity, &PasswordA, &PasswordLength))
872 status = sspi_SetAuthIdentity(identity, UserA, DomainA, PasswordA);
877 identity->Flags &= (uint32_t)~SEC_WINNT_AUTH_IDENTITY_ANSI;
878 identity->Flags |= SEC_WINNT_AUTH_IDENTITY_UNICODE;
882 identity->Flags |= SEC_WINNT_AUTH_IDENTITY_UNICODE;
884 if (!sspi_GetAuthIdentityUserDomainW(srcIdentity, &UserW, &UserLength, &DomainW, &DomainLength))
889 if (!sspi_GetAuthIdentityPasswordW(srcIdentity, &PasswordW, &PasswordLength))
895 identity->UserLength = UserLength;
897 if (identity->UserLength > 0)
899 identity->User = (UINT16*)calloc((identity->UserLength + 1),
sizeof(WCHAR));
904 CopyMemory(identity->User, UserW, identity->UserLength *
sizeof(WCHAR));
905 identity->User[identity->UserLength] = 0;
908 identity->DomainLength = DomainLength;
910 if (identity->DomainLength > 0)
912 identity->Domain = (UINT16*)calloc((identity->DomainLength + 1),
sizeof(WCHAR));
914 if (!identity->Domain)
917 CopyMemory(identity->Domain, DomainW, identity->DomainLength *
sizeof(WCHAR));
918 identity->Domain[identity->DomainLength] = 0;
921 identity->PasswordLength = PasswordLength;
925 identity->Password = (UINT16*)calloc((identity->PasswordLength + 1),
sizeof(WCHAR));
927 if (!identity->Password)
930 CopyMemory(identity->Password, PasswordW, identity->PasswordLength *
sizeof(WCHAR));
931 identity->Password[identity->PasswordLength] = 0;
942 for (UINT32 index = 0; index < pMessage->cBuffers; index++)
944 if (pMessage->pBuffers[index].BufferType == BufferType)
946 pSecBuffer = &pMessage->pBuffers[index];
954static BOOL WINPR_init(
void)
957 for (
size_t x = 0; x < ARRAYSIZE(SecurityFunctionTableA_NAME_LIST); x++)
959 const SecurityFunctionTableA_NAME* cur = &SecurityFunctionTableA_NAME_LIST[x];
960 InitializeConstWCharFromUtf8(cur->Name, BUFFER_NAME_LIST_W[x],
961 ARRAYSIZE(BUFFER_NAME_LIST_W[x]));
966static BOOL CALLBACK sspi_init(WINPR_ATTR_UNUSED
PINIT_ONCE InitOnce,
967 WINPR_ATTR_UNUSED PVOID Parameter, WINPR_ATTR_UNUSED PVOID* Context)
969 if (!winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT))
971 sspi_ContextBufferAllocTableNew();
972 if (!SCHANNEL_init())
974 if (!KERBEROS_init())
980 if (!NEGOTIATE_init())
985void sspi_GlobalInit(
void)
987 static INIT_ONCE once = INIT_ONCE_STATIC_INIT;
989 if (!InitOnceExecuteOnce(&once, sspi_init, &flags,
nullptr))
990 WLog_ERR(TAG,
"InitOnceExecuteOnce failed");
993void sspi_GlobalFinish(
void)
995 sspi_ContextBufferAllocTableFree();
1000 size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1002 for (
size_t index = 0; index < cPackages; index++)
1004 if (strcmp(Name, SecurityFunctionTableA_NAME_LIST[index].Name) == 0)
1006 return SecurityFunctionTableA_NAME_LIST[index].SecurityFunctionTable;
1015 size_t cPackages = ARRAYSIZE(SecPkgInfoW_LIST);
1017 for (
size_t index = 0; index < cPackages; index++)
1019 if (_wcscmp(Name, SecurityFunctionTableW_NAME_LIST[index].Name) == 0)
1021 return SecurityFunctionTableW_NAME_LIST[index].SecurityFunctionTable;
1033 WCHAR* NameW = ConvertUtf8ToWCharAlloc(Name,
nullptr);
1043static void FreeContextBuffer_EnumerateSecurityPackages(
void* contextBuffer);
1044static void FreeContextBuffer_QuerySecurityPackageInfo(
void* contextBuffer);
1046void sspi_ContextBufferFree(
void* contextBuffer)
1048 UINT32 allocatorIndex = 0;
1050 for (
size_t index = 0; index < ContextBufferAllocTable.cMaxEntries; index++)
1052 if (contextBuffer == ContextBufferAllocTable.entries[index].contextBuffer)
1054 contextBuffer = ContextBufferAllocTable.entries[index].contextBuffer;
1055 allocatorIndex = ContextBufferAllocTable.entries[index].allocatorIndex;
1056 ContextBufferAllocTable.cEntries--;
1057 ContextBufferAllocTable.entries[index].allocatorIndex = 0;
1058 ContextBufferAllocTable.entries[index].contextBuffer =
nullptr;
1060 switch (allocatorIndex)
1062 case EnumerateSecurityPackagesIndex:
1063 FreeContextBuffer_EnumerateSecurityPackages(contextBuffer);
1066 case QuerySecurityPackageInfoIndex:
1067 FreeContextBuffer_QuerySecurityPackageInfo(contextBuffer);
1082static SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesW(ULONG* pcPackages,
1085 const size_t cPackages = ARRAYSIZE(SecPkgInfoW_LIST);
1086 const size_t size =
sizeof(
SecPkgInfoW) * cPackages;
1088 (
SecPkgInfoW*)sspi_ContextBufferAlloc(EnumerateSecurityPackagesIndex, size);
1090 WINPR_ASSERT(cPackages <= UINT32_MAX);
1093 return SEC_E_INSUFFICIENT_MEMORY;
1095 for (
size_t index = 0; index < cPackages; index++)
1097 pPackageInfo[index].fCapabilities = SecPkgInfoW_LIST[index]->fCapabilities;
1098 pPackageInfo[index].wVersion = SecPkgInfoW_LIST[index]->wVersion;
1099 pPackageInfo[index].wRPCID = SecPkgInfoW_LIST[index]->wRPCID;
1100 pPackageInfo[index].cbMaxToken = SecPkgInfoW_LIST[index]->cbMaxToken;
1101 pPackageInfo[index].Name = _wcsdup(SecPkgInfoW_LIST[index]->Name);
1102 pPackageInfo[index].Comment = _wcsdup(SecPkgInfoW_LIST[index]->Comment);
1105 *(pcPackages) = (UINT32)cPackages;
1106 *(ppPackageInfo) = pPackageInfo;
1110static SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesA(ULONG* pcPackages,
1113 const size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1114 const size_t size =
sizeof(
SecPkgInfoA) * cPackages;
1116 (
SecPkgInfoA*)sspi_ContextBufferAlloc(EnumerateSecurityPackagesIndex, size);
1118 WINPR_ASSERT(cPackages <= UINT32_MAX);
1121 return SEC_E_INSUFFICIENT_MEMORY;
1123 for (
size_t index = 0; index < cPackages; index++)
1125 pPackageInfo[index].fCapabilities = SecPkgInfoA_LIST[index]->fCapabilities;
1126 pPackageInfo[index].wVersion = SecPkgInfoA_LIST[index]->wVersion;
1127 pPackageInfo[index].wRPCID = SecPkgInfoA_LIST[index]->wRPCID;
1128 pPackageInfo[index].cbMaxToken = SecPkgInfoA_LIST[index]->cbMaxToken;
1129 pPackageInfo[index].Name = _strdup(SecPkgInfoA_LIST[index]->Name);
1130 pPackageInfo[index].Comment = _strdup(SecPkgInfoA_LIST[index]->Comment);
1132 if (!pPackageInfo[index].Name || !pPackageInfo[index].Comment)
1134 sspi_ContextBufferFree(pPackageInfo);
1135 return SEC_E_INSUFFICIENT_MEMORY;
1139 *(pcPackages) = (UINT32)cPackages;
1140 *(ppPackageInfo) = pPackageInfo;
1144static void FreeContextBuffer_EnumerateSecurityPackages(
void* contextBuffer)
1147 size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1152 for (
size_t index = 0; index < cPackages; index++)
1154 free(pPackageInfo[index].Name);
1155 free(pPackageInfo[index].Comment);
1161static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoW(SEC_WCHAR* pszPackageName,
1164 size_t cPackages = ARRAYSIZE(SecPkgInfoW_LIST);
1166 for (
size_t index = 0; index < cPackages; index++)
1168 if (_wcscmp(pszPackageName, SecPkgInfoW_LIST[index]->Name) == 0)
1172 (
SecPkgInfoW*)sspi_ContextBufferAlloc(QuerySecurityPackageInfoIndex, size);
1175 return SEC_E_INSUFFICIENT_MEMORY;
1177 pPackageInfo->fCapabilities = SecPkgInfoW_LIST[index]->fCapabilities;
1178 pPackageInfo->wVersion = SecPkgInfoW_LIST[index]->wVersion;
1179 pPackageInfo->wRPCID = SecPkgInfoW_LIST[index]->wRPCID;
1180 pPackageInfo->cbMaxToken = SecPkgInfoW_LIST[index]->cbMaxToken;
1181 pPackageInfo->Name = _wcsdup(SecPkgInfoW_LIST[index]->Name);
1182 pPackageInfo->Comment = _wcsdup(SecPkgInfoW_LIST[index]->Comment);
1183 *(ppPackageInfo) = pPackageInfo;
1188 *(ppPackageInfo) =
nullptr;
1189 return SEC_E_SECPKG_NOT_FOUND;
1192static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoA(SEC_CHAR* pszPackageName,
1195 size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1197 for (
size_t index = 0; index < cPackages; index++)
1199 if (strcmp(pszPackageName, SecPkgInfoA_LIST[index]->Name) == 0)
1203 (
SecPkgInfoA*)sspi_ContextBufferAlloc(QuerySecurityPackageInfoIndex, size);
1206 return SEC_E_INSUFFICIENT_MEMORY;
1208 pPackageInfo->fCapabilities = SecPkgInfoA_LIST[index]->fCapabilities;
1209 pPackageInfo->wVersion = SecPkgInfoA_LIST[index]->wVersion;
1210 pPackageInfo->wRPCID = SecPkgInfoA_LIST[index]->wRPCID;
1211 pPackageInfo->cbMaxToken = SecPkgInfoA_LIST[index]->cbMaxToken;
1212 pPackageInfo->Name = _strdup(SecPkgInfoA_LIST[index]->Name);
1213 pPackageInfo->Comment = _strdup(SecPkgInfoA_LIST[index]->Comment);
1215 if (!pPackageInfo->Name || !pPackageInfo->Comment)
1217 sspi_ContextBufferFree(pPackageInfo);
1218 return SEC_E_INSUFFICIENT_MEMORY;
1221 *(ppPackageInfo) = pPackageInfo;
1226 *(ppPackageInfo) =
nullptr;
1227 return SEC_E_SECPKG_NOT_FOUND;
1230void FreeContextBuffer_QuerySecurityPackageInfo(
void* contextBuffer)
1232 SecPkgInfo* pPackageInfo = (SecPkgInfo*)contextBuffer;
1237 free(pPackageInfo->Name);
1238 free(pPackageInfo->Comment);
1242#define log_status(what, status) log_status_((what), (status), __FILE__, __func__, __LINE__)
1243static SECURITY_STATUS log_status_(
const char* what, SECURITY_STATUS status,
const char* file,
1244 const char* fkt,
size_t line)
1246 if (IsSecurityStatusError(status))
1248 const DWORD level = WLOG_WARN;
1249 static wLog* log =
nullptr;
1251 log = WLog_Get(TAG);
1253 if (WLog_IsLevelActive(log, level))
1255 WLog_PrintTextMessage(log, level, line, file, fkt,
"%s status %s [0x%08" PRIx32
"]",
1256 what, GetSecurityStatusString(status),
1257 WINPR_CXX_COMPAT_CAST(uint32_t, status));
1265static SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleW(
1266 SEC_WCHAR* pszPrincipal, SEC_WCHAR* pszPackage, ULONG fCredentialUse,
void* pvLogonID,
1267 void* pAuthData, SEC_GET_KEY_FN pGetKeyFn,
void* pvGetKeyArgument,
PCredHandle phCredential,
1273 return SEC_E_SECPKG_NOT_FOUND;
1275 if (!table->AcquireCredentialsHandleW)
1277 WLog_WARN(TAG,
"Security module does not provide an implementation");
1278 return SEC_E_UNSUPPORTED_FUNCTION;
1281 SECURITY_STATUS status = table->AcquireCredentialsHandleW(
1282 pszPrincipal, pszPackage, fCredentialUse, pvLogonID, pAuthData, pGetKeyFn, pvGetKeyArgument,
1283 phCredential, ptsExpiry);
1284 return log_status(
"AcquireCredentialsHandleW", status);
1287static SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleA(
1288 SEC_CHAR* pszPrincipal, SEC_CHAR* pszPackage, ULONG fCredentialUse,
void* pvLogonID,
1289 void* pAuthData, SEC_GET_KEY_FN pGetKeyFn,
void* pvGetKeyArgument,
PCredHandle phCredential,
1295 return SEC_E_SECPKG_NOT_FOUND;
1297 if (!table->AcquireCredentialsHandleA)
1299 WLog_WARN(TAG,
"Security module does not provide an implementation");
1300 return SEC_E_UNSUPPORTED_FUNCTION;
1303 SECURITY_STATUS status = table->AcquireCredentialsHandleA(
1304 pszPrincipal, pszPackage, fCredentialUse, pvLogonID, pAuthData, pGetKeyFn, pvGetKeyArgument,
1305 phCredential, ptsExpiry);
1306 return log_status(
"AcquireCredentialsHandleA", status);
1309static SECURITY_STATUS SEC_ENTRY winpr_ExportSecurityContext(
PCtxtHandle phContext, ULONG fFlags,
1313 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phContext);
1316 return SEC_E_SECPKG_NOT_FOUND;
1321 return SEC_E_SECPKG_NOT_FOUND;
1323 if (!table->ExportSecurityContext)
1325 WLog_WARN(TAG,
"Security module does not provide an implementation");
1326 return SEC_E_UNSUPPORTED_FUNCTION;
1329 SECURITY_STATUS status =
1330 table->ExportSecurityContext(phContext, fFlags, pPackedContext, pToken);
1331 return log_status(
"ExportSecurityContext", status);
1334static SECURITY_STATUS SEC_ENTRY winpr_FreeCredentialsHandle(
PCredHandle phCredential)
1336 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phCredential);
1339 return SEC_E_SECPKG_NOT_FOUND;
1344 return SEC_E_SECPKG_NOT_FOUND;
1346 if (!table->FreeCredentialsHandle)
1348 WLog_WARN(TAG,
"Security module does not provide an implementation");
1349 return SEC_E_UNSUPPORTED_FUNCTION;
1352 SECURITY_STATUS status = table->FreeCredentialsHandle(phCredential);
1353 return log_status(
"FreeCredentialsHandle", status);
1356static SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextW(SEC_WCHAR* pszPackage,
1360 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phContext);
1363 return SEC_E_SECPKG_NOT_FOUND;
1368 return SEC_E_SECPKG_NOT_FOUND;
1370 if (!table->ImportSecurityContextW)
1372 WLog_WARN(TAG,
"Security module does not provide an implementation");
1373 return SEC_E_UNSUPPORTED_FUNCTION;
1376 SECURITY_STATUS status =
1377 table->ImportSecurityContextW(pszPackage, pPackedContext, pToken, phContext);
1378 return log_status(
"ImportSecurityContextW", status);
1381static SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextA(SEC_CHAR* pszPackage,
1385 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phContext);
1388 return SEC_E_SECPKG_NOT_FOUND;
1393 return SEC_E_SECPKG_NOT_FOUND;
1395 if (!table->ImportSecurityContextA)
1397 WLog_WARN(TAG,
"Security module does not provide an implementation");
1398 return SEC_E_UNSUPPORTED_FUNCTION;
1401 SECURITY_STATUS status =
1402 table->ImportSecurityContextA(pszPackage, pPackedContext, pToken, phContext);
1403 return log_status(
"ImportSecurityContextA", status);
1406static SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesW(
PCredHandle phCredential,
1407 ULONG ulAttribute,
void* pBuffer)
1409 const WCHAR* Name = (
const WCHAR*)sspi_SecureHandleGetUpperPointer(phCredential);
1412 return SEC_E_SECPKG_NOT_FOUND;
1417 return SEC_E_SECPKG_NOT_FOUND;
1419 if (!table->QueryCredentialsAttributesW)
1421 WLog_WARN(TAG,
"Security module does not provide an implementation");
1422 return SEC_E_UNSUPPORTED_FUNCTION;
1425 SECURITY_STATUS status = table->QueryCredentialsAttributesW(phCredential, ulAttribute, pBuffer);
1426 return log_status(
"QueryCredentialsAttributesW", status);
1429static SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesA(
PCredHandle phCredential,
1430 ULONG ulAttribute,
void* pBuffer)
1432 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phCredential);
1435 return SEC_E_SECPKG_NOT_FOUND;
1440 return SEC_E_SECPKG_NOT_FOUND;
1442 if (!table->QueryCredentialsAttributesA)
1444 WLog_WARN(TAG,
"Security module does not provide an implementation");
1445 return SEC_E_UNSUPPORTED_FUNCTION;
1448 SECURITY_STATUS status = table->QueryCredentialsAttributesA(phCredential, ulAttribute, pBuffer);
1449 return log_status(
"QueryCredentialsAttributesA", status);
1452static SECURITY_STATUS SEC_ENTRY winpr_SetCredentialsAttributesW(
PCredHandle phCredential,
1453 ULONG ulAttribute,
void* pBuffer,
1456 const WCHAR* Name = (
const WCHAR*)sspi_SecureHandleGetUpperPointer(phCredential);
1459 return SEC_E_SECPKG_NOT_FOUND;
1464 return SEC_E_SECPKG_NOT_FOUND;
1466 if (!table->SetCredentialsAttributesW)
1468 WLog_WARN(TAG,
"Security module does not provide an implementation");
1469 return SEC_E_UNSUPPORTED_FUNCTION;
1472 SECURITY_STATUS status =
1473 table->SetCredentialsAttributesW(phCredential, ulAttribute, pBuffer, cbBuffer);
1474 return log_status(
"SetCredentialsAttributesW", status);
1477static SECURITY_STATUS SEC_ENTRY winpr_SetCredentialsAttributesA(
PCredHandle phCredential,
1478 ULONG ulAttribute,
void* pBuffer,
1481 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phCredential);
1484 return SEC_E_SECPKG_NOT_FOUND;
1489 return SEC_E_SECPKG_NOT_FOUND;
1491 if (!table->SetCredentialsAttributesA)
1493 WLog_WARN(TAG,
"Security module does not provide an implementation");
1494 return SEC_E_UNSUPPORTED_FUNCTION;
1497 SECURITY_STATUS status =
1498 table->SetCredentialsAttributesA(phCredential, ulAttribute, pBuffer, cbBuffer);
1499 return log_status(
"SetCredentialsAttributesA", status);
1504static SECURITY_STATUS SEC_ENTRY
1506 ULONG fContextReq, ULONG TargetDataRep,
PCtxtHandle phNewContext,
1509 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phCredential);
1512 return SEC_E_SECPKG_NOT_FOUND;
1517 return SEC_E_SECPKG_NOT_FOUND;
1519 if (!table->AcceptSecurityContext)
1521 WLog_WARN(TAG,
"Security module does not provide an implementation");
1522 return SEC_E_UNSUPPORTED_FUNCTION;
1525 SECURITY_STATUS status =
1526 table->AcceptSecurityContext(phCredential, phContext, pInput, fContextReq, TargetDataRep,
1527 phNewContext, pOutput, pfContextAttr, ptsTimeStamp);
1528 return log_status(
"AcceptSecurityContext", status);
1531static SECURITY_STATUS SEC_ENTRY winpr_ApplyControlToken(
PCtxtHandle phContext,
1534 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phContext);
1537 return SEC_E_SECPKG_NOT_FOUND;
1542 return SEC_E_SECPKG_NOT_FOUND;
1544 if (!table->ApplyControlToken)
1546 WLog_WARN(TAG,
"Security module does not provide an implementation");
1547 return SEC_E_UNSUPPORTED_FUNCTION;
1550 SECURITY_STATUS status = table->ApplyControlToken(phContext, pInput);
1551 return log_status(
"ApplyControlToken", status);
1554static SECURITY_STATUS SEC_ENTRY winpr_CompleteAuthToken(
PCtxtHandle phContext,
1557 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phContext);
1560 return SEC_E_SECPKG_NOT_FOUND;
1565 return SEC_E_SECPKG_NOT_FOUND;
1567 if (!table->CompleteAuthToken)
1569 WLog_WARN(TAG,
"Security module does not provide an implementation");
1570 return SEC_E_UNSUPPORTED_FUNCTION;
1573 SECURITY_STATUS status = table->CompleteAuthToken(phContext, pToken);
1574 return log_status(
"CompleteAuthToken", status);
1577static SECURITY_STATUS SEC_ENTRY winpr_DeleteSecurityContext(
PCtxtHandle phContext)
1579 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phContext);
1582 return SEC_E_SECPKG_NOT_FOUND;
1587 return SEC_E_SECPKG_NOT_FOUND;
1589 if (!table->DeleteSecurityContext)
1591 WLog_WARN(TAG,
"Security module does not provide an implementation");
1592 return SEC_E_UNSUPPORTED_FUNCTION;
1595 const SECURITY_STATUS status = table->DeleteSecurityContext(phContext);
1596 return log_status(
"DeleteSecurityContext", status);
1599static SECURITY_STATUS SEC_ENTRY winpr_FreeContextBuffer(
void* pvContextBuffer)
1601 if (!pvContextBuffer)
1602 return SEC_E_INVALID_HANDLE;
1604 sspi_ContextBufferFree(pvContextBuffer);
1608static SECURITY_STATUS SEC_ENTRY winpr_ImpersonateSecurityContext(
PCtxtHandle phContext)
1610 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phContext);
1613 return SEC_E_SECPKG_NOT_FOUND;
1618 return SEC_E_SECPKG_NOT_FOUND;
1620 if (!table->ImpersonateSecurityContext)
1622 WLog_WARN(TAG,
"Security module does not provide an implementation");
1623 return SEC_E_UNSUPPORTED_FUNCTION;
1626 SECURITY_STATUS status = table->ImpersonateSecurityContext(phContext);
1627 return log_status(
"ImpersonateSecurityContext", status);
1630static SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextW(
1632 ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2,
1635 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phCredential);
1638 return SEC_E_SECPKG_NOT_FOUND;
1643 return SEC_E_SECPKG_NOT_FOUND;
1645 if (!table->InitializeSecurityContextW)
1647 WLog_WARN(TAG,
"Security module does not provide an implementation");
1648 return SEC_E_UNSUPPORTED_FUNCTION;
1651 const SECURITY_STATUS status = table->InitializeSecurityContextW(
1652 phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput,
1653 Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry);
1654 return log_status(
"InitializeSecurityContextW", status);
1657static SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextA(
1659 ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2,
1662 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phCredential);
1665 return SEC_E_SECPKG_NOT_FOUND;
1670 return SEC_E_SECPKG_NOT_FOUND;
1672 if (!table->InitializeSecurityContextA)
1674 WLog_WARN(TAG,
"Security module does not provide an implementation");
1675 return SEC_E_UNSUPPORTED_FUNCTION;
1678 SECURITY_STATUS status = table->InitializeSecurityContextA(
1679 phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput,
1680 Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry);
1682 return log_status(
"InitializeSecurityContextA", status);
1685static SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesW(
PCtxtHandle phContext,
1686 ULONG ulAttribute,
void* pBuffer)
1688 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phContext);
1691 return SEC_E_SECPKG_NOT_FOUND;
1696 return SEC_E_SECPKG_NOT_FOUND;
1698 if (!table->QueryContextAttributesW)
1700 WLog_WARN(TAG,
"Security module does not provide an implementation");
1701 return SEC_E_UNSUPPORTED_FUNCTION;
1704 SECURITY_STATUS status = table->QueryContextAttributesW(phContext, ulAttribute, pBuffer);
1705 return log_status(
"QueryContextAttributesW", status);
1708static SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesA(
PCtxtHandle phContext,
1709 ULONG ulAttribute,
void* pBuffer)
1711 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phContext);
1714 return SEC_E_SECPKG_NOT_FOUND;
1719 return SEC_E_SECPKG_NOT_FOUND;
1721 if (!table->QueryContextAttributesA)
1723 WLog_WARN(TAG,
"Security module does not provide an implementation");
1724 return SEC_E_UNSUPPORTED_FUNCTION;
1727 SECURITY_STATUS status = table->QueryContextAttributesA(phContext, ulAttribute, pBuffer);
1728 return log_status(
"QueryContextAttributesA", status);
1731static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityContextToken(
PCtxtHandle phContext,
1734 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phContext);
1737 return SEC_E_SECPKG_NOT_FOUND;
1742 return SEC_E_SECPKG_NOT_FOUND;
1744 if (!table->QuerySecurityContextToken)
1746 WLog_WARN(TAG,
"Security module does not provide an implementation");
1747 return SEC_E_UNSUPPORTED_FUNCTION;
1750 SECURITY_STATUS status = table->QuerySecurityContextToken(phContext, phToken);
1751 return log_status(
"QuerySecurityContextToken", status);
1754static SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesW(
PCtxtHandle phContext,
1755 ULONG ulAttribute,
void* pBuffer,
1758 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phContext);
1761 return SEC_E_SECPKG_NOT_FOUND;
1766 return SEC_E_SECPKG_NOT_FOUND;
1768 if (!table->SetContextAttributesW)
1770 WLog_WARN(TAG,
"Security module does not provide an implementation");
1771 return SEC_E_UNSUPPORTED_FUNCTION;
1774 SECURITY_STATUS status =
1775 table->SetContextAttributesW(phContext, ulAttribute, pBuffer, cbBuffer);
1776 return log_status(
"SetContextAttributesW", status);
1779static SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesA(
PCtxtHandle phContext,
1780 ULONG ulAttribute,
void* pBuffer,
1783 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phContext);
1786 return SEC_E_SECPKG_NOT_FOUND;
1791 return SEC_E_SECPKG_NOT_FOUND;
1793 if (!table->SetContextAttributesA)
1795 WLog_WARN(TAG,
"Security module does not provide an implementation");
1796 return SEC_E_UNSUPPORTED_FUNCTION;
1799 SECURITY_STATUS status =
1800 table->SetContextAttributesA(phContext, ulAttribute, pBuffer, cbBuffer);
1801 return log_status(
"SetContextAttributesA", status);
1804static SECURITY_STATUS SEC_ENTRY winpr_RevertSecurityContext(
PCtxtHandle phContext)
1806 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phContext);
1809 return SEC_E_SECPKG_NOT_FOUND;
1814 return SEC_E_SECPKG_NOT_FOUND;
1816 if (!table->RevertSecurityContext)
1818 WLog_WARN(TAG,
"Security module does not provide an implementation");
1819 return SEC_E_UNSUPPORTED_FUNCTION;
1822 SECURITY_STATUS status = table->RevertSecurityContext(phContext);
1824 return log_status(
"RevertSecurityContext", status);
1829static SECURITY_STATUS SEC_ENTRY winpr_DecryptMessage(
PCtxtHandle phContext,
1833 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phContext);
1836 return SEC_E_SECPKG_NOT_FOUND;
1841 return SEC_E_SECPKG_NOT_FOUND;
1843 if (!table->DecryptMessage)
1845 WLog_WARN(TAG,
"Security module does not provide an implementation");
1846 return SEC_E_UNSUPPORTED_FUNCTION;
1849 const SECURITY_STATUS status = table->DecryptMessage(phContext, pMessage, MessageSeqNo, pfQOP);
1851 return log_status(
"DecryptMessage", status);
1854static SECURITY_STATUS SEC_ENTRY winpr_EncryptMessage(
PCtxtHandle phContext, ULONG fQOP,
1857 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phContext);
1860 return SEC_E_SECPKG_NOT_FOUND;
1865 return SEC_E_SECPKG_NOT_FOUND;
1867 if (!table->EncryptMessage)
1869 WLog_WARN(TAG,
"Security module does not provide an implementation");
1870 return SEC_E_UNSUPPORTED_FUNCTION;
1873 const SECURITY_STATUS status = table->EncryptMessage(phContext, fQOP, pMessage, MessageSeqNo);
1874 return log_status(
"EncryptMessage", status);
1877static SECURITY_STATUS SEC_ENTRY winpr_MakeSignature(
PCtxtHandle phContext, ULONG fQOP,
1880 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phContext);
1883 return SEC_E_SECPKG_NOT_FOUND;
1888 return SEC_E_SECPKG_NOT_FOUND;
1890 if (!table->MakeSignature)
1892 WLog_WARN(TAG,
"Security module does not provide an implementation");
1893 return SEC_E_UNSUPPORTED_FUNCTION;
1896 const SECURITY_STATUS status = table->MakeSignature(phContext, fQOP, pMessage, MessageSeqNo);
1897 return log_status(
"MakeSignature", status);
1900static SECURITY_STATUS SEC_ENTRY winpr_VerifySignature(
PCtxtHandle phContext,
1904 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phContext);
1907 return SEC_E_SECPKG_NOT_FOUND;
1912 return SEC_E_SECPKG_NOT_FOUND;
1914 if (!table->VerifySignature)
1916 WLog_WARN(TAG,
"Security module does not provide an implementation");
1917 return SEC_E_UNSUPPORTED_FUNCTION;
1920 SECURITY_STATUS status = table->VerifySignature(phContext, pMessage, MessageSeqNo, pfQOP);
1922 return log_status(
"VerifySignature", status);
1927 winpr_EnumerateSecurityPackagesA,
1928 winpr_QueryCredentialsAttributesA,
1929 winpr_AcquireCredentialsHandleA,
1930 winpr_FreeCredentialsHandle,
1932 winpr_InitializeSecurityContextA,
1933 winpr_AcceptSecurityContext,
1934 winpr_CompleteAuthToken,
1935 winpr_DeleteSecurityContext,
1936 winpr_ApplyControlToken,
1937 winpr_QueryContextAttributesA,
1938 winpr_ImpersonateSecurityContext,
1939 winpr_RevertSecurityContext,
1940 winpr_MakeSignature,
1941 winpr_VerifySignature,
1942 winpr_FreeContextBuffer,
1943 winpr_QuerySecurityPackageInfoA,
1946 winpr_ExportSecurityContext,
1947 winpr_ImportSecurityContextA,
1950 winpr_QuerySecurityContextToken,
1951 winpr_EncryptMessage,
1952 winpr_DecryptMessage,
1953 winpr_SetContextAttributesA,
1954 winpr_SetCredentialsAttributesA,
1959 winpr_EnumerateSecurityPackagesW,
1960 winpr_QueryCredentialsAttributesW,
1961 winpr_AcquireCredentialsHandleW,
1962 winpr_FreeCredentialsHandle,
1964 winpr_InitializeSecurityContextW,
1965 winpr_AcceptSecurityContext,
1966 winpr_CompleteAuthToken,
1967 winpr_DeleteSecurityContext,
1968 winpr_ApplyControlToken,
1969 winpr_QueryContextAttributesW,
1970 winpr_ImpersonateSecurityContext,
1971 winpr_RevertSecurityContext,
1972 winpr_MakeSignature,
1973 winpr_VerifySignature,
1974 winpr_FreeContextBuffer,
1975 winpr_QuerySecurityPackageInfoW,
1978 winpr_ExportSecurityContext,
1979 winpr_ImportSecurityContextW,
1982 winpr_QuerySecurityContextToken,
1983 winpr_EncryptMessage,
1984 winpr_DecryptMessage,
1985 winpr_SetContextAttributesW,
1986 winpr_SetCredentialsAttributesW,
1991 return &winpr_SecurityFunctionTableW;
1996 return &winpr_SecurityFunctionTableA;