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"
35#define TAG WINPR_TAG("sspi")
40#include "NTLM/ntlm_export.h"
41#include "CredSSP/credssp.h"
42#include "Kerberos/kerberos.h"
43#include "Negotiate/negotiate.h"
44#include "Schannel/schannel.h"
46static const SecPkgInfoA* SecPkgInfoA_LIST[] = { &NTLM_SecPkgInfoA, &KERBEROS_SecPkgInfoA,
47 &NEGOTIATE_SecPkgInfoA, &CREDSSP_SecPkgInfoA,
48 &SCHANNEL_SecPkgInfoA };
50static const SecPkgInfoW* SecPkgInfoW_LIST[] = { &NTLM_SecPkgInfoW, &KERBEROS_SecPkgInfoW,
51 &NEGOTIATE_SecPkgInfoW, &CREDSSP_SecPkgInfoW,
52 &SCHANNEL_SecPkgInfoW };
58} SecurityFunctionTableA_NAME;
62 const SEC_WCHAR* Name;
64} SecurityFunctionTableW_NAME;
66static const SecurityFunctionTableA_NAME SecurityFunctionTableA_NAME_LIST[] = {
67 {
"NTLM", &NTLM_SecurityFunctionTableA },
68 {
"Kerberos", &KERBEROS_SecurityFunctionTableA },
69 {
"Negotiate", &NEGOTIATE_SecurityFunctionTableA },
70 {
"CREDSSP", &CREDSSP_SecurityFunctionTableA },
71 {
"Schannel", &SCHANNEL_SecurityFunctionTableA }
74static WCHAR BUFFER_NAME_LIST_W[5][32] = WINPR_C_ARRAY_INIT;
76static const SecurityFunctionTableW_NAME SecurityFunctionTableW_NAME_LIST[] = {
77 { BUFFER_NAME_LIST_W[0], &NTLM_SecurityFunctionTableW },
78 { BUFFER_NAME_LIST_W[1], &KERBEROS_SecurityFunctionTableW },
79 { BUFFER_NAME_LIST_W[2], &NEGOTIATE_SecurityFunctionTableW },
80 { BUFFER_NAME_LIST_W[3], &CREDSSP_SecurityFunctionTableW },
81 { BUFFER_NAME_LIST_W[4], &SCHANNEL_SecurityFunctionTableW }
87 UINT32 allocatorIndex;
88} CONTEXT_BUFFER_ALLOC_ENTRY;
94 CONTEXT_BUFFER_ALLOC_ENTRY* entries;
95} CONTEXT_BUFFER_ALLOC_TABLE;
97static CONTEXT_BUFFER_ALLOC_TABLE ContextBufferAllocTable = WINPR_C_ARRAY_INIT;
99static int sspi_ContextBufferAllocTableNew(
void)
102 ContextBufferAllocTable.entries =
nullptr;
103 ContextBufferAllocTable.cEntries = 0;
104 ContextBufferAllocTable.cMaxEntries = 4;
105 size =
sizeof(CONTEXT_BUFFER_ALLOC_ENTRY) * ContextBufferAllocTable.cMaxEntries;
106 ContextBufferAllocTable.entries = (CONTEXT_BUFFER_ALLOC_ENTRY*)calloc(1, size);
108 if (!ContextBufferAllocTable.entries)
114static int sspi_ContextBufferAllocTableGrow(
void)
117 CONTEXT_BUFFER_ALLOC_ENTRY* entries =
nullptr;
118 ContextBufferAllocTable.cEntries = 0;
119 ContextBufferAllocTable.cMaxEntries *= 2;
120 size =
sizeof(CONTEXT_BUFFER_ALLOC_ENTRY) * ContextBufferAllocTable.cMaxEntries;
125 entries = (CONTEXT_BUFFER_ALLOC_ENTRY*)realloc(ContextBufferAllocTable.entries, size);
129 free(ContextBufferAllocTable.entries);
133 ContextBufferAllocTable.entries = entries;
134 ZeroMemory((
void*)&ContextBufferAllocTable.entries[ContextBufferAllocTable.cMaxEntries / 2],
139static void sspi_ContextBufferAllocTableFree(
void)
141 if (ContextBufferAllocTable.cEntries != 0)
142 WLog_ERR(TAG,
"ContextBufferAllocTable.entries == %" PRIu32,
143 ContextBufferAllocTable.cEntries);
145 ContextBufferAllocTable.cEntries = ContextBufferAllocTable.cMaxEntries = 0;
146 free(ContextBufferAllocTable.entries);
147 ContextBufferAllocTable.entries =
nullptr;
150void* sspi_ContextBufferAlloc(UINT32 allocatorIndex,
size_t size)
152 void* contextBuffer =
nullptr;
154 for (UINT32 index = 0; index < ContextBufferAllocTable.cMaxEntries; index++)
156 if (!ContextBufferAllocTable.entries[index].contextBuffer)
158 contextBuffer = calloc(1, size);
163 ContextBufferAllocTable.cEntries++;
164 ContextBufferAllocTable.entries[index].contextBuffer = contextBuffer;
165 ContextBufferAllocTable.entries[index].allocatorIndex = allocatorIndex;
166 return ContextBufferAllocTable.entries[index].contextBuffer;
172 if (sspi_ContextBufferAllocTableGrow() < 0)
176 return sspi_ContextBufferAlloc(allocatorIndex, size);
188 size_t userLength = 0;
189 size_t domainLength = 0;
190 size_t passwordLength = 0;
195 if (credentials->ntlmSettings.samFile)
196 free(credentials->ntlmSettings.samFile);
198 userLength = credentials->identity.UserLength;
199 domainLength = credentials->identity.DomainLength;
200 passwordLength = credentials->identity.PasswordLength;
202 if (passwordLength > SSPI_CREDENTIALS_HASH_LENGTH_OFFSET)
203 passwordLength -= SSPI_CREDENTIALS_HASH_LENGTH_OFFSET;
205 if (credentials->identity.Flags & SEC_WINNT_AUTH_IDENTITY_UNICODE)
212 if (credentials->identity.User)
213 memset(credentials->identity.User, 0, userLength);
214 if (credentials->identity.Domain)
215 memset(credentials->identity.Domain, 0, domainLength);
216 if (credentials->identity.Password)
217 memset(credentials->identity.Password, 0, passwordLength);
218 free(credentials->identity.User);
219 free(credentials->identity.Domain);
220 free(credentials->identity.Password);
258 SecInvalidateHandle(handle);
262void* sspi_SecureHandleGetLowerPointer(
SecHandle* handle)
264 void* pointer =
nullptr;
266 if (!handle || !SecIsValidHandle(handle) || !handle->dwLower)
269 pointer = (
void*)~((
size_t)handle->dwLower);
273void sspi_SecureHandleInvalidate(
SecHandle* handle)
282void sspi_SecureHandleSetLowerPointer(
SecHandle* handle,
void* pointer)
287 handle->dwLower = (ULONG_PTR)(~((
size_t)pointer));
290void* sspi_SecureHandleGetUpperPointer(
SecHandle* handle)
292 void* pointer =
nullptr;
294 if (!handle || !SecIsValidHandle(handle) || !handle->dwUpper)
297 pointer = (
void*)~((
size_t)handle->dwUpper);
301void sspi_SecureHandleSetUpperPointer(
SecHandle* handle,
void* pointer)
306 handle->dwUpper = (ULONG_PTR)(~((
size_t)pointer));
309void sspi_SecureHandleFree(
SecHandle* handle)
314int sspi_SetAuthIdentityW(SEC_WINNT_AUTH_IDENTITY* identity,
const WCHAR* user,
const WCHAR* domain,
315 const WCHAR* password)
317 return sspi_SetAuthIdentityWithLengthW(identity, user, user ? _wcslen(user) : 0, domain,
318 domain ? _wcslen(domain) : 0, password,
319 password ? _wcslen(password) : 0);
322static BOOL copy(WCHAR** dst, ULONG* dstLen,
const WCHAR* what,
size_t len)
325 WINPR_ASSERT(dstLen);
330 if (len > UINT32_MAX)
334 if (!what && (len != 0))
336 if (!what && (len == 0))
339 *dst = calloc(
sizeof(WCHAR), len + 1);
343 memcpy(*dst, what, len *
sizeof(WCHAR));
344 *dstLen = WINPR_ASSERTING_INT_CAST(UINT32, len);
348int sspi_SetAuthIdentityWithLengthW(SEC_WINNT_AUTH_IDENTITY* identity,
const WCHAR* user,
349 size_t userLen,
const WCHAR* domain,
size_t domainLen,
350 const WCHAR* password,
size_t passwordLen)
352 WINPR_ASSERT(identity);
353 sspi_FreeAuthIdentity(identity);
354 identity->Flags &= (uint32_t)~SEC_WINNT_AUTH_IDENTITY_ANSI;
355 identity->Flags |= SEC_WINNT_AUTH_IDENTITY_UNICODE;
357 if (!copy(&identity->User, &identity->UserLength, user, userLen))
360 if (!copy(&identity->Domain, &identity->DomainLength, domain, domainLen))
363 if (!copy(&identity->Password, &identity->PasswordLength, password, passwordLen))
369static void zfree(WCHAR* str,
size_t len)
372 memset(str, 0, len *
sizeof(WCHAR));
376int sspi_SetAuthIdentityA(SEC_WINNT_AUTH_IDENTITY* identity,
const char* user,
const char* domain,
377 const char* password)
380 size_t unicodeUserLenW = 0;
381 size_t unicodeDomainLenW = 0;
382 size_t unicodePasswordLenW = 0;
383 LPWSTR unicodeUser =
nullptr;
384 LPWSTR unicodeDomain =
nullptr;
385 LPWSTR unicodePassword =
nullptr;
388 unicodeUser = ConvertUtf8ToWCharAlloc(user, &unicodeUserLenW);
391 unicodeDomain = ConvertUtf8ToWCharAlloc(domain, &unicodeDomainLenW);
394 unicodePassword = ConvertUtf8ToWCharAlloc(password, &unicodePasswordLenW);
396 rc = sspi_SetAuthIdentityWithLengthW(identity, unicodeUser, unicodeUserLenW, unicodeDomain,
397 unicodeDomainLenW, unicodePassword, unicodePasswordLenW);
399 zfree(unicodeUser, unicodeUserLenW);
400 zfree(unicodeDomain, unicodeDomainLenW);
401 zfree(unicodePassword, unicodePasswordLenW);
405UINT32 sspi_GetAuthIdentityVersion(
const void* identity)
412 version = *((
const UINT32*)identity);
414 if ((version == SEC_WINNT_AUTH_IDENTITY_VERSION) ||
415 (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2))
423UINT32 sspi_GetAuthIdentityFlags(
const void* identity)
431 version = sspi_GetAuthIdentityVersion(identity);
433 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
435 flags = ((
const SEC_WINNT_AUTH_IDENTITY_EX*)identity)->Flags;
437 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
443 flags = ((
const SEC_WINNT_AUTH_IDENTITY*)identity)->Flags;
449BOOL sspi_GetAuthIdentityUserDomainW(
const void* identity,
const WCHAR** pUser, UINT32* pUserLength,
450 const WCHAR** pDomain, UINT32* pDomainLength)
457 version = sspi_GetAuthIdentityVersion(identity);
459 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
462 *pUser = (
const WCHAR*)id->User;
463 *pUserLength =
id->UserLength;
464 *pDomain = (
const WCHAR*)id->Domain;
465 *pDomainLength =
id->DomainLength;
467 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
470 UINT32 UserOffset =
id->UserOffset;
471 UINT32 DomainOffset =
id->DomainOffset;
472 *pUser = (
const WCHAR*)&((
const uint8_t*)identity)[UserOffset];
473 *pUserLength =
id->UserLength / 2;
474 *pDomain = (
const WCHAR*)&((
const uint8_t*)identity)[DomainOffset];
475 *pDomainLength =
id->DomainLength / 2;
480 *pUser = (
const WCHAR*)id->User;
481 *pUserLength =
id->UserLength;
482 *pDomain = (
const WCHAR*)id->Domain;
483 *pDomainLength =
id->DomainLength;
489BOOL sspi_GetAuthIdentityUserDomainA(
const void* identity,
const char** pUser, UINT32* pUserLength,
490 const char** pDomain, UINT32* pDomainLength)
497 version = sspi_GetAuthIdentityVersion(identity);
499 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
502 *pUser = (
const char*)id->User;
503 *pUserLength =
id->UserLength;
504 *pDomain = (
const char*)id->Domain;
505 *pDomainLength =
id->DomainLength;
507 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
510 UINT32 UserOffset =
id->UserOffset;
511 UINT32 DomainOffset =
id->DomainOffset;
512 *pUser = (
const char*)&((
const uint8_t*)identity)[UserOffset];
513 *pUserLength =
id->UserLength;
514 *pDomain = (
const char*)&((
const uint8_t*)identity)[DomainOffset];
515 *pDomainLength =
id->DomainLength;
520 *pUser = (
const char*)id->User;
521 *pUserLength =
id->UserLength;
522 *pDomain = (
const char*)id->Domain;
523 *pDomainLength =
id->DomainLength;
529BOOL sspi_GetAuthIdentityPasswordW(
const void* identity,
const WCHAR** pPassword,
530 UINT32* pPasswordLength)
537 version = sspi_GetAuthIdentityVersion(identity);
539 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
542 *pPassword = (
const WCHAR*)id->Password;
543 *pPasswordLength =
id->PasswordLength;
545 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
552 *pPassword = (
const WCHAR*)id->Password;
553 *pPasswordLength =
id->PasswordLength;
559BOOL sspi_GetAuthIdentityPasswordA(
const void* identity,
const char** pPassword,
560 UINT32* pPasswordLength)
567 version = sspi_GetAuthIdentityVersion(identity);
569 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
572 *pPassword = (
const char*)id->Password;
573 *pPasswordLength =
id->PasswordLength;
575 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
582 *pPassword = (
const char*)id->Password;
583 *pPasswordLength =
id->PasswordLength;
590 char** pDomain,
char** pPassword)
592 BOOL success = FALSE;
593 const char* UserA =
nullptr;
594 const char* DomainA =
nullptr;
595 const char* PasswordA =
nullptr;
596 const WCHAR* UserW =
nullptr;
597 const WCHAR* DomainW =
nullptr;
598 const WCHAR* PasswordW =
nullptr;
599 UINT32 UserLength = 0;
600 UINT32 DomainLength = 0;
601 UINT32 PasswordLength = 0;
603 if (!identity || !pUser || !pDomain || !pPassword)
606 *pUser = *pDomain = *pPassword =
nullptr;
608 UINT32 identityFlags = sspi_GetAuthIdentityFlags(identity);
610 if (identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI)
612 if (!sspi_GetAuthIdentityUserDomainA(identity, &UserA, &UserLength, &DomainA,
616 if (!sspi_GetAuthIdentityPasswordA(identity, &PasswordA, &PasswordLength))
619 if (UserA && UserLength)
621 *pUser = _strdup(UserA);
627 if (DomainA && DomainLength)
629 *pDomain = _strdup(DomainA);
635 if (PasswordA && PasswordLength)
637 *pPassword = _strdup(PasswordA);
647 if (!sspi_GetAuthIdentityUserDomainW(identity, &UserW, &UserLength, &DomainW,
651 if (!sspi_GetAuthIdentityPasswordW(identity, &PasswordW, &PasswordLength))
654 if (UserW && (UserLength > 0))
656 *pUser = ConvertWCharNToUtf8Alloc(UserW, UserLength,
nullptr);
661 if (DomainW && (DomainLength > 0))
663 *pDomain = ConvertWCharNToUtf8Alloc(DomainW, DomainLength,
nullptr);
668 if (PasswordW && (PasswordLength > 0))
670 *pPassword = ConvertWCharNToUtf8Alloc(PasswordW, PasswordLength,
nullptr);
683 WCHAR** pDomain, WCHAR** pPassword)
685 BOOL success = FALSE;
686 const char* UserA =
nullptr;
687 const char* DomainA =
nullptr;
688 const char* PasswordA =
nullptr;
689 const WCHAR* UserW =
nullptr;
690 const WCHAR* DomainW =
nullptr;
691 const WCHAR* PasswordW =
nullptr;
692 UINT32 UserLength = 0;
693 UINT32 DomainLength = 0;
694 UINT32 PasswordLength = 0;
696 if (!identity || !pUser || !pDomain || !pPassword)
699 *pUser = *pDomain = *pPassword =
nullptr;
701 UINT32 identityFlags = sspi_GetAuthIdentityFlags(identity);
703 if (identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI)
705 if (!sspi_GetAuthIdentityUserDomainA(identity, &UserA, &UserLength, &DomainA,
709 if (!sspi_GetAuthIdentityPasswordA(identity, &PasswordA, &PasswordLength))
712 if (UserA && (UserLength > 0))
714 WCHAR* ptr = ConvertUtf8NToWCharAlloc(UserA, UserLength,
nullptr);
721 if (DomainA && (DomainLength > 0))
723 WCHAR* ptr = ConvertUtf8NToWCharAlloc(DomainA, DomainLength,
nullptr);
729 if (PasswordA && (PasswordLength > 0))
731 WCHAR* ptr = ConvertUtf8NToWCharAlloc(PasswordA, PasswordLength,
nullptr);
742 if (!sspi_GetAuthIdentityUserDomainW(identity, &UserW, &UserLength, &DomainW,
746 if (!sspi_GetAuthIdentityPasswordW(identity, &PasswordW, &PasswordLength))
749 if (UserW && UserLength)
751 *pUser = _wcsdup(UserW);
757 if (DomainW && DomainLength)
759 *pDomain = _wcsdup(DomainW);
765 if (PasswordW && PasswordLength)
767 *pPassword = _wcsdup(PasswordW);
783 UINT32 identityFlags = 0;
784 char* PackageList =
nullptr;
785 const char* PackageListA =
nullptr;
786 const WCHAR* PackageListW =
nullptr;
787 UINT32 PackageListLength = 0;
788 UINT32 PackageListOffset = 0;
789 const void* pAuthData = (
const void*)identity;
794 version = sspi_GetAuthIdentityVersion(pAuthData);
795 identityFlags = sspi_GetAuthIdentityFlags(pAuthData);
797 if (identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI)
799 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
802 PackageListA = (
const char*)ad->PackageList;
803 PackageListLength = ad->PackageListLength;
806 if (PackageListA && PackageListLength)
808 PackageList = _strdup(PackageListA);
813 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
816 PackageListW = (
const WCHAR*)ad->PackageList;
817 PackageListLength = ad->PackageListLength;
819 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
822 PackageListOffset = ad->PackageListOffset;
823 PackageListW = (
const WCHAR*)&((
const uint8_t*)pAuthData)[PackageListOffset];
824 PackageListLength = ad->PackageListLength / 2;
827 if (PackageListW && (PackageListLength > 0))
828 PackageList = ConvertWCharNToUtf8Alloc(PackageListW, PackageListLength,
nullptr);
833 *pPackageList = PackageList;
840int sspi_CopyAuthIdentity(SEC_WINNT_AUTH_IDENTITY* identity,
844 UINT32 identityFlags = 0;
845 const char* UserA =
nullptr;
846 const char* DomainA =
nullptr;
847 const char* PasswordA =
nullptr;
848 const WCHAR* UserW =
nullptr;
849 const WCHAR* DomainW =
nullptr;
850 const WCHAR* PasswordW =
nullptr;
851 UINT32 UserLength = 0;
852 UINT32 DomainLength = 0;
853 UINT32 PasswordLength = 0;
855 sspi_FreeAuthIdentity(identity);
857 identityFlags = sspi_GetAuthIdentityFlags(srcIdentity);
859 identity->Flags = identityFlags;
861 if (identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI)
863 if (!sspi_GetAuthIdentityUserDomainA(srcIdentity, &UserA, &UserLength, &DomainA,
869 if (!sspi_GetAuthIdentityPasswordA(srcIdentity, &PasswordA, &PasswordLength))
874 status = sspi_SetAuthIdentity(identity, UserA, DomainA, PasswordA);
879 identity->Flags &= (uint32_t)~SEC_WINNT_AUTH_IDENTITY_ANSI;
880 identity->Flags |= SEC_WINNT_AUTH_IDENTITY_UNICODE;
884 identity->Flags |= SEC_WINNT_AUTH_IDENTITY_UNICODE;
886 if (!sspi_GetAuthIdentityUserDomainW(srcIdentity, &UserW, &UserLength, &DomainW, &DomainLength))
891 if (!sspi_GetAuthIdentityPasswordW(srcIdentity, &PasswordW, &PasswordLength))
897 identity->UserLength = UserLength;
899 if (identity->UserLength > 0)
901 identity->User = (UINT16*)calloc((identity->UserLength + 1),
sizeof(WCHAR));
906 CopyMemory(identity->User, UserW, identity->UserLength *
sizeof(WCHAR));
907 identity->User[identity->UserLength] = 0;
910 identity->DomainLength = DomainLength;
912 if (identity->DomainLength > 0)
914 identity->Domain = (UINT16*)calloc((identity->DomainLength + 1),
sizeof(WCHAR));
916 if (!identity->Domain)
919 CopyMemory(identity->Domain, DomainW, identity->DomainLength *
sizeof(WCHAR));
920 identity->Domain[identity->DomainLength] = 0;
923 identity->PasswordLength = PasswordLength;
925 if (identity->PasswordLength > SSPI_CREDENTIALS_HASH_LENGTH_OFFSET)
926 identity->PasswordLength -= SSPI_CREDENTIALS_HASH_LENGTH_OFFSET;
930 identity->Password = (UINT16*)calloc((identity->PasswordLength + 1),
sizeof(WCHAR));
932 if (!identity->Password)
935 CopyMemory(identity->Password, PasswordW, identity->PasswordLength *
sizeof(WCHAR));
936 identity->Password[identity->PasswordLength] = 0;
939 identity->PasswordLength = PasswordLength;
948 for (UINT32 index = 0; index < pMessage->cBuffers; index++)
950 if (pMessage->pBuffers[index].BufferType == BufferType)
952 pSecBuffer = &pMessage->pBuffers[index];
960static BOOL WINPR_init(
void)
963 for (
size_t x = 0; x < ARRAYSIZE(SecurityFunctionTableA_NAME_LIST); x++)
965 const SecurityFunctionTableA_NAME* cur = &SecurityFunctionTableA_NAME_LIST[x];
966 InitializeConstWCharFromUtf8(cur->Name, BUFFER_NAME_LIST_W[x],
967 ARRAYSIZE(BUFFER_NAME_LIST_W[x]));
972static BOOL CALLBACK sspi_init(WINPR_ATTR_UNUSED
PINIT_ONCE InitOnce,
973 WINPR_ATTR_UNUSED PVOID Parameter, WINPR_ATTR_UNUSED PVOID* Context)
975 if (!winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT))
977 sspi_ContextBufferAllocTableNew();
978 if (!SCHANNEL_init())
980 if (!KERBEROS_init())
986 if (!NEGOTIATE_init())
991void sspi_GlobalInit(
void)
993 static INIT_ONCE once = INIT_ONCE_STATIC_INIT;
995 (void)InitOnceExecuteOnce(&once, sspi_init, &flags,
nullptr);
998void sspi_GlobalFinish(
void)
1000 sspi_ContextBufferAllocTableFree();
1005 size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1007 for (
size_t index = 0; index < cPackages; index++)
1009 if (strcmp(Name, SecurityFunctionTableA_NAME_LIST[index].Name) == 0)
1011 return SecurityFunctionTableA_NAME_LIST[index].SecurityFunctionTable;
1020 size_t cPackages = ARRAYSIZE(SecPkgInfoW_LIST);
1022 for (
size_t index = 0; index < cPackages; index++)
1024 if (_wcscmp(Name, SecurityFunctionTableW_NAME_LIST[index].Name) == 0)
1026 return SecurityFunctionTableW_NAME_LIST[index].SecurityFunctionTable;
1035 SEC_WCHAR* NameW =
nullptr;
1041 NameW = ConvertUtf8ToWCharAlloc(Name,
nullptr);
1046 table = sspi_GetSecurityFunctionTableWByNameW(NameW);
1051static void FreeContextBuffer_EnumerateSecurityPackages(
void* contextBuffer);
1052static void FreeContextBuffer_QuerySecurityPackageInfo(
void* contextBuffer);
1054void sspi_ContextBufferFree(
void* contextBuffer)
1056 UINT32 allocatorIndex = 0;
1058 for (
size_t index = 0; index < ContextBufferAllocTable.cMaxEntries; index++)
1060 if (contextBuffer == ContextBufferAllocTable.entries[index].contextBuffer)
1062 contextBuffer = ContextBufferAllocTable.entries[index].contextBuffer;
1063 allocatorIndex = ContextBufferAllocTable.entries[index].allocatorIndex;
1064 ContextBufferAllocTable.cEntries--;
1065 ContextBufferAllocTable.entries[index].allocatorIndex = 0;
1066 ContextBufferAllocTable.entries[index].contextBuffer =
nullptr;
1068 switch (allocatorIndex)
1070 case EnumerateSecurityPackagesIndex:
1071 FreeContextBuffer_EnumerateSecurityPackages(contextBuffer);
1074 case QuerySecurityPackageInfoIndex:
1075 FreeContextBuffer_QuerySecurityPackageInfo(contextBuffer);
1090static SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesW(ULONG* pcPackages,
1093 const size_t cPackages = ARRAYSIZE(SecPkgInfoW_LIST);
1094 const size_t size =
sizeof(
SecPkgInfoW) * cPackages;
1096 (
SecPkgInfoW*)sspi_ContextBufferAlloc(EnumerateSecurityPackagesIndex, size);
1098 WINPR_ASSERT(cPackages <= UINT32_MAX);
1101 return SEC_E_INSUFFICIENT_MEMORY;
1103 for (
size_t index = 0; index < cPackages; index++)
1105 pPackageInfo[index].fCapabilities = SecPkgInfoW_LIST[index]->fCapabilities;
1106 pPackageInfo[index].wVersion = SecPkgInfoW_LIST[index]->wVersion;
1107 pPackageInfo[index].wRPCID = SecPkgInfoW_LIST[index]->wRPCID;
1108 pPackageInfo[index].cbMaxToken = SecPkgInfoW_LIST[index]->cbMaxToken;
1109 pPackageInfo[index].Name = _wcsdup(SecPkgInfoW_LIST[index]->Name);
1110 pPackageInfo[index].Comment = _wcsdup(SecPkgInfoW_LIST[index]->Comment);
1113 *(pcPackages) = (UINT32)cPackages;
1114 *(ppPackageInfo) = pPackageInfo;
1118static SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesA(ULONG* pcPackages,
1121 const size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1122 const size_t size =
sizeof(
SecPkgInfoA) * cPackages;
1124 (
SecPkgInfoA*)sspi_ContextBufferAlloc(EnumerateSecurityPackagesIndex, size);
1126 WINPR_ASSERT(cPackages <= UINT32_MAX);
1129 return SEC_E_INSUFFICIENT_MEMORY;
1131 for (
size_t index = 0; index < cPackages; index++)
1133 pPackageInfo[index].fCapabilities = SecPkgInfoA_LIST[index]->fCapabilities;
1134 pPackageInfo[index].wVersion = SecPkgInfoA_LIST[index]->wVersion;
1135 pPackageInfo[index].wRPCID = SecPkgInfoA_LIST[index]->wRPCID;
1136 pPackageInfo[index].cbMaxToken = SecPkgInfoA_LIST[index]->cbMaxToken;
1137 pPackageInfo[index].Name = _strdup(SecPkgInfoA_LIST[index]->Name);
1138 pPackageInfo[index].Comment = _strdup(SecPkgInfoA_LIST[index]->Comment);
1140 if (!pPackageInfo[index].Name || !pPackageInfo[index].Comment)
1142 sspi_ContextBufferFree(pPackageInfo);
1143 return SEC_E_INSUFFICIENT_MEMORY;
1147 *(pcPackages) = (UINT32)cPackages;
1148 *(ppPackageInfo) = pPackageInfo;
1152static void FreeContextBuffer_EnumerateSecurityPackages(
void* contextBuffer)
1155 size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1160 for (
size_t index = 0; index < cPackages; index++)
1162 free(pPackageInfo[index].Name);
1163 free(pPackageInfo[index].Comment);
1169static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoW(SEC_WCHAR* pszPackageName,
1172 size_t cPackages = ARRAYSIZE(SecPkgInfoW_LIST);
1174 for (
size_t index = 0; index < cPackages; index++)
1176 if (_wcscmp(pszPackageName, SecPkgInfoW_LIST[index]->Name) == 0)
1180 (
SecPkgInfoW*)sspi_ContextBufferAlloc(QuerySecurityPackageInfoIndex, size);
1183 return SEC_E_INSUFFICIENT_MEMORY;
1185 pPackageInfo->fCapabilities = SecPkgInfoW_LIST[index]->fCapabilities;
1186 pPackageInfo->wVersion = SecPkgInfoW_LIST[index]->wVersion;
1187 pPackageInfo->wRPCID = SecPkgInfoW_LIST[index]->wRPCID;
1188 pPackageInfo->cbMaxToken = SecPkgInfoW_LIST[index]->cbMaxToken;
1189 pPackageInfo->Name = _wcsdup(SecPkgInfoW_LIST[index]->Name);
1190 pPackageInfo->Comment = _wcsdup(SecPkgInfoW_LIST[index]->Comment);
1191 *(ppPackageInfo) = pPackageInfo;
1196 *(ppPackageInfo) =
nullptr;
1197 return SEC_E_SECPKG_NOT_FOUND;
1200static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoA(SEC_CHAR* pszPackageName,
1203 size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1205 for (
size_t index = 0; index < cPackages; index++)
1207 if (strcmp(pszPackageName, SecPkgInfoA_LIST[index]->Name) == 0)
1211 (
SecPkgInfoA*)sspi_ContextBufferAlloc(QuerySecurityPackageInfoIndex, size);
1214 return SEC_E_INSUFFICIENT_MEMORY;
1216 pPackageInfo->fCapabilities = SecPkgInfoA_LIST[index]->fCapabilities;
1217 pPackageInfo->wVersion = SecPkgInfoA_LIST[index]->wVersion;
1218 pPackageInfo->wRPCID = SecPkgInfoA_LIST[index]->wRPCID;
1219 pPackageInfo->cbMaxToken = SecPkgInfoA_LIST[index]->cbMaxToken;
1220 pPackageInfo->Name = _strdup(SecPkgInfoA_LIST[index]->Name);
1221 pPackageInfo->Comment = _strdup(SecPkgInfoA_LIST[index]->Comment);
1223 if (!pPackageInfo->Name || !pPackageInfo->Comment)
1225 sspi_ContextBufferFree(pPackageInfo);
1226 return SEC_E_INSUFFICIENT_MEMORY;
1229 *(ppPackageInfo) = pPackageInfo;
1234 *(ppPackageInfo) =
nullptr;
1235 return SEC_E_SECPKG_NOT_FOUND;
1238void FreeContextBuffer_QuerySecurityPackageInfo(
void* contextBuffer)
1240 SecPkgInfo* pPackageInfo = (SecPkgInfo*)contextBuffer;
1245 free(pPackageInfo->Name);
1246 free(pPackageInfo->Comment);
1250#define log_status(what, status) log_status_((what), (status), __FILE__, __func__, __LINE__)
1251static SECURITY_STATUS log_status_(
const char* what, SECURITY_STATUS status,
const char* file,
1252 const char* fkt,
size_t line)
1254 if (IsSecurityStatusError(status))
1256 const DWORD level = WLOG_WARN;
1257 static wLog* log =
nullptr;
1259 log = WLog_Get(TAG);
1261 if (WLog_IsLevelActive(log, level))
1263 WLog_PrintTextMessage(log, level, line, file, fkt,
"%s status %s [0x%08" PRIx32
"]",
1264 what, GetSecurityStatusString(status),
1265 WINPR_CXX_COMPAT_CAST(uint32_t, status));
1273static SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleW(
1274 SEC_WCHAR* pszPrincipal, SEC_WCHAR* pszPackage, ULONG fCredentialUse,
void* pvLogonID,
1275 void* pAuthData, SEC_GET_KEY_FN pGetKeyFn,
void* pvGetKeyArgument,
PCredHandle phCredential,
1278 SECURITY_STATUS status = 0;
1282 return SEC_E_SECPKG_NOT_FOUND;
1284 if (!table->AcquireCredentialsHandleW)
1286 WLog_WARN(TAG,
"Security module does not provide an implementation");
1287 return SEC_E_UNSUPPORTED_FUNCTION;
1290 status = table->AcquireCredentialsHandleW(pszPrincipal, pszPackage, fCredentialUse, pvLogonID,
1291 pAuthData, pGetKeyFn, pvGetKeyArgument, phCredential,
1293 return log_status(
"AcquireCredentialsHandleW", status);
1296static SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleA(
1297 SEC_CHAR* pszPrincipal, SEC_CHAR* pszPackage, ULONG fCredentialUse,
void* pvLogonID,
1298 void* pAuthData, SEC_GET_KEY_FN pGetKeyFn,
void* pvGetKeyArgument,
PCredHandle phCredential,
1301 SECURITY_STATUS status = 0;
1305 return SEC_E_SECPKG_NOT_FOUND;
1307 if (!table->AcquireCredentialsHandleA)
1309 WLog_WARN(TAG,
"Security module does not provide an implementation");
1310 return SEC_E_UNSUPPORTED_FUNCTION;
1313 status = table->AcquireCredentialsHandleA(pszPrincipal, pszPackage, fCredentialUse, pvLogonID,
1314 pAuthData, pGetKeyFn, pvGetKeyArgument, phCredential,
1316 return log_status(
"AcquireCredentialsHandleA", status);
1319static SECURITY_STATUS SEC_ENTRY winpr_ExportSecurityContext(
PCtxtHandle phContext, ULONG fFlags,
1323 SEC_CHAR* Name =
nullptr;
1324 SECURITY_STATUS status = 0;
1326 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1329 return SEC_E_SECPKG_NOT_FOUND;
1331 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1334 return SEC_E_SECPKG_NOT_FOUND;
1336 if (!table->ExportSecurityContext)
1338 WLog_WARN(TAG,
"Security module does not provide an implementation");
1339 return SEC_E_UNSUPPORTED_FUNCTION;
1342 status = table->ExportSecurityContext(phContext, fFlags, pPackedContext, pToken);
1343 return log_status(
"ExportSecurityContext", status);
1346static SECURITY_STATUS SEC_ENTRY winpr_FreeCredentialsHandle(
PCredHandle phCredential)
1348 char* Name =
nullptr;
1349 SECURITY_STATUS status = 0;
1351 Name = (
char*)sspi_SecureHandleGetUpperPointer(phCredential);
1354 return SEC_E_SECPKG_NOT_FOUND;
1356 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1359 return SEC_E_SECPKG_NOT_FOUND;
1361 if (!table->FreeCredentialsHandle)
1363 WLog_WARN(TAG,
"Security module does not provide an implementation");
1364 return SEC_E_UNSUPPORTED_FUNCTION;
1367 status = table->FreeCredentialsHandle(phCredential);
1368 return log_status(
"FreeCredentialsHandle", status);
1371static SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextW(SEC_WCHAR* pszPackage,
1375 SEC_CHAR* Name =
nullptr;
1376 SECURITY_STATUS status = 0;
1378 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1381 return SEC_E_SECPKG_NOT_FOUND;
1383 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1386 return SEC_E_SECPKG_NOT_FOUND;
1388 if (!table->ImportSecurityContextW)
1390 WLog_WARN(TAG,
"Security module does not provide an implementation");
1391 return SEC_E_UNSUPPORTED_FUNCTION;
1394 status = table->ImportSecurityContextW(pszPackage, pPackedContext, pToken, phContext);
1395 return log_status(
"ImportSecurityContextW", status);
1398static SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextA(SEC_CHAR* pszPackage,
1402 char* Name =
nullptr;
1403 SECURITY_STATUS status = 0;
1405 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1408 return SEC_E_SECPKG_NOT_FOUND;
1410 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1413 return SEC_E_SECPKG_NOT_FOUND;
1415 if (!table->ImportSecurityContextA)
1417 WLog_WARN(TAG,
"Security module does not provide an implementation");
1418 return SEC_E_UNSUPPORTED_FUNCTION;
1421 status = table->ImportSecurityContextA(pszPackage, pPackedContext, pToken, phContext);
1422 return log_status(
"ImportSecurityContextA", status);
1425static SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesW(
PCredHandle phCredential,
1426 ULONG ulAttribute,
void* pBuffer)
1428 SEC_WCHAR* Name =
nullptr;
1429 SECURITY_STATUS status = 0;
1431 Name = (SEC_WCHAR*)sspi_SecureHandleGetUpperPointer(phCredential);
1434 return SEC_E_SECPKG_NOT_FOUND;
1436 table = sspi_GetSecurityFunctionTableWByNameW(Name);
1439 return SEC_E_SECPKG_NOT_FOUND;
1441 if (!table->QueryCredentialsAttributesW)
1443 WLog_WARN(TAG,
"Security module does not provide an implementation");
1444 return SEC_E_UNSUPPORTED_FUNCTION;
1447 status = table->QueryCredentialsAttributesW(phCredential, ulAttribute, pBuffer);
1448 return log_status(
"QueryCredentialsAttributesW", status);
1451static SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesA(
PCredHandle phCredential,
1452 ULONG ulAttribute,
void* pBuffer)
1454 char* Name =
nullptr;
1455 SECURITY_STATUS status = 0;
1457 Name = (
char*)sspi_SecureHandleGetUpperPointer(phCredential);
1460 return SEC_E_SECPKG_NOT_FOUND;
1462 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1465 return SEC_E_SECPKG_NOT_FOUND;
1467 if (!table->QueryCredentialsAttributesA)
1469 WLog_WARN(TAG,
"Security module does not provide an implementation");
1470 return SEC_E_UNSUPPORTED_FUNCTION;
1473 status = table->QueryCredentialsAttributesA(phCredential, ulAttribute, pBuffer);
1474 return log_status(
"QueryCredentialsAttributesA", status);
1477static SECURITY_STATUS SEC_ENTRY winpr_SetCredentialsAttributesW(
PCredHandle phCredential,
1478 ULONG ulAttribute,
void* pBuffer,
1481 SEC_WCHAR* Name =
nullptr;
1482 SECURITY_STATUS status = 0;
1484 Name = (SEC_WCHAR*)sspi_SecureHandleGetUpperPointer(phCredential);
1487 return SEC_E_SECPKG_NOT_FOUND;
1489 table = sspi_GetSecurityFunctionTableWByNameW(Name);
1492 return SEC_E_SECPKG_NOT_FOUND;
1494 if (!table->SetCredentialsAttributesW)
1496 WLog_WARN(TAG,
"Security module does not provide an implementation");
1497 return SEC_E_UNSUPPORTED_FUNCTION;
1500 status = table->SetCredentialsAttributesW(phCredential, ulAttribute, pBuffer, cbBuffer);
1501 return log_status(
"SetCredentialsAttributesW", status);
1504static SECURITY_STATUS SEC_ENTRY winpr_SetCredentialsAttributesA(
PCredHandle phCredential,
1505 ULONG ulAttribute,
void* pBuffer,
1508 char* Name =
nullptr;
1509 SECURITY_STATUS status = 0;
1511 Name = (
char*)sspi_SecureHandleGetUpperPointer(phCredential);
1514 return SEC_E_SECPKG_NOT_FOUND;
1516 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1519 return SEC_E_SECPKG_NOT_FOUND;
1521 if (!table->SetCredentialsAttributesA)
1523 WLog_WARN(TAG,
"Security module does not provide an implementation");
1524 return SEC_E_UNSUPPORTED_FUNCTION;
1527 status = table->SetCredentialsAttributesA(phCredential, ulAttribute, pBuffer, cbBuffer);
1528 return log_status(
"SetCredentialsAttributesA", status);
1533static SECURITY_STATUS SEC_ENTRY
1535 ULONG fContextReq, ULONG TargetDataRep,
PCtxtHandle phNewContext,
1538 char* Name =
nullptr;
1539 SECURITY_STATUS status = 0;
1541 Name = (
char*)sspi_SecureHandleGetUpperPointer(phCredential);
1544 return SEC_E_SECPKG_NOT_FOUND;
1546 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1549 return SEC_E_SECPKG_NOT_FOUND;
1551 if (!table->AcceptSecurityContext)
1553 WLog_WARN(TAG,
"Security module does not provide an implementation");
1554 return SEC_E_UNSUPPORTED_FUNCTION;
1558 table->AcceptSecurityContext(phCredential, phContext, pInput, fContextReq, TargetDataRep,
1559 phNewContext, pOutput, pfContextAttr, ptsTimeStamp);
1560 return log_status(
"AcceptSecurityContext", status);
1563static SECURITY_STATUS SEC_ENTRY winpr_ApplyControlToken(
PCtxtHandle phContext,
1566 char* Name =
nullptr;
1567 SECURITY_STATUS status = 0;
1569 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1572 return SEC_E_SECPKG_NOT_FOUND;
1574 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1577 return SEC_E_SECPKG_NOT_FOUND;
1579 if (!table->ApplyControlToken)
1581 WLog_WARN(TAG,
"Security module does not provide an implementation");
1582 return SEC_E_UNSUPPORTED_FUNCTION;
1585 status = table->ApplyControlToken(phContext, pInput);
1586 return log_status(
"ApplyControlToken", status);
1589static SECURITY_STATUS SEC_ENTRY winpr_CompleteAuthToken(
PCtxtHandle phContext,
1592 char* Name =
nullptr;
1593 SECURITY_STATUS status = 0;
1595 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1598 return SEC_E_SECPKG_NOT_FOUND;
1600 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1603 return SEC_E_SECPKG_NOT_FOUND;
1605 if (!table->CompleteAuthToken)
1607 WLog_WARN(TAG,
"Security module does not provide an implementation");
1608 return SEC_E_UNSUPPORTED_FUNCTION;
1611 status = table->CompleteAuthToken(phContext, pToken);
1612 return log_status(
"CompleteAuthToken", status);
1615static SECURITY_STATUS SEC_ENTRY winpr_DeleteSecurityContext(
PCtxtHandle phContext)
1617 const char* Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1620 return SEC_E_SECPKG_NOT_FOUND;
1625 return SEC_E_SECPKG_NOT_FOUND;
1627 if (!table->DeleteSecurityContext)
1629 WLog_WARN(TAG,
"Security module does not provide an implementation");
1630 return SEC_E_UNSUPPORTED_FUNCTION;
1633 const SECURITY_STATUS status = table->DeleteSecurityContext(phContext);
1634 return log_status(
"DeleteSecurityContext", status);
1637static SECURITY_STATUS SEC_ENTRY winpr_FreeContextBuffer(
void* pvContextBuffer)
1639 if (!pvContextBuffer)
1640 return SEC_E_INVALID_HANDLE;
1642 sspi_ContextBufferFree(pvContextBuffer);
1646static SECURITY_STATUS SEC_ENTRY winpr_ImpersonateSecurityContext(
PCtxtHandle phContext)
1648 SEC_CHAR* Name =
nullptr;
1649 SECURITY_STATUS status = 0;
1651 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1654 return SEC_E_SECPKG_NOT_FOUND;
1656 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1659 return SEC_E_SECPKG_NOT_FOUND;
1661 if (!table->ImpersonateSecurityContext)
1663 WLog_WARN(TAG,
"Security module does not provide an implementation");
1664 return SEC_E_UNSUPPORTED_FUNCTION;
1667 status = table->ImpersonateSecurityContext(phContext);
1668 return log_status(
"ImpersonateSecurityContext", status);
1671static SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextW(
1673 ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2,
1676 SEC_CHAR* Name =
nullptr;
1677 SECURITY_STATUS status = 0;
1679 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phCredential);
1682 return SEC_E_SECPKG_NOT_FOUND;
1684 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1687 return SEC_E_SECPKG_NOT_FOUND;
1689 if (!table->InitializeSecurityContextW)
1691 WLog_WARN(TAG,
"Security module does not provide an implementation");
1692 return SEC_E_UNSUPPORTED_FUNCTION;
1695 status = table->InitializeSecurityContextW(phCredential, phContext, pszTargetName, fContextReq,
1696 Reserved1, TargetDataRep, pInput, Reserved2,
1697 phNewContext, pOutput, pfContextAttr, ptsExpiry);
1698 return log_status(
"InitializeSecurityContextW", status);
1701static SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextA(
1703 ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2,
1706 SEC_CHAR* Name =
nullptr;
1707 SECURITY_STATUS status = 0;
1709 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phCredential);
1712 return SEC_E_SECPKG_NOT_FOUND;
1714 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1717 return SEC_E_SECPKG_NOT_FOUND;
1719 if (!table->InitializeSecurityContextA)
1721 WLog_WARN(TAG,
"Security module does not provide an implementation");
1722 return SEC_E_UNSUPPORTED_FUNCTION;
1725 status = table->InitializeSecurityContextA(phCredential, phContext, pszTargetName, fContextReq,
1726 Reserved1, TargetDataRep, pInput, Reserved2,
1727 phNewContext, pOutput, pfContextAttr, ptsExpiry);
1729 return log_status(
"InitializeSecurityContextA", status);
1732static SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesW(
PCtxtHandle phContext,
1733 ULONG ulAttribute,
void* pBuffer)
1735 SEC_CHAR* Name =
nullptr;
1736 SECURITY_STATUS status = 0;
1738 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1741 return SEC_E_SECPKG_NOT_FOUND;
1743 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1746 return SEC_E_SECPKG_NOT_FOUND;
1748 if (!table->QueryContextAttributesW)
1750 WLog_WARN(TAG,
"Security module does not provide an implementation");
1751 return SEC_E_UNSUPPORTED_FUNCTION;
1754 status = table->QueryContextAttributesW(phContext, ulAttribute, pBuffer);
1755 return log_status(
"QueryContextAttributesW", status);
1758static SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesA(
PCtxtHandle phContext,
1759 ULONG ulAttribute,
void* pBuffer)
1761 SEC_CHAR* Name =
nullptr;
1762 SECURITY_STATUS status = 0;
1764 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1767 return SEC_E_SECPKG_NOT_FOUND;
1769 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1772 return SEC_E_SECPKG_NOT_FOUND;
1774 if (!table->QueryContextAttributesA)
1776 WLog_WARN(TAG,
"Security module does not provide an implementation");
1777 return SEC_E_UNSUPPORTED_FUNCTION;
1780 status = table->QueryContextAttributesA(phContext, ulAttribute, pBuffer);
1781 return log_status(
"QueryContextAttributesA", status);
1784static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityContextToken(
PCtxtHandle phContext,
1787 SEC_CHAR* Name =
nullptr;
1788 SECURITY_STATUS status = 0;
1790 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1793 return SEC_E_SECPKG_NOT_FOUND;
1795 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1798 return SEC_E_SECPKG_NOT_FOUND;
1800 if (!table->QuerySecurityContextToken)
1802 WLog_WARN(TAG,
"Security module does not provide an implementation");
1803 return SEC_E_UNSUPPORTED_FUNCTION;
1806 status = table->QuerySecurityContextToken(phContext, phToken);
1807 return log_status(
"QuerySecurityContextToken", status);
1810static SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesW(
PCtxtHandle phContext,
1811 ULONG ulAttribute,
void* pBuffer,
1814 SEC_CHAR* Name =
nullptr;
1815 SECURITY_STATUS status = 0;
1817 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1820 return SEC_E_SECPKG_NOT_FOUND;
1822 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1825 return SEC_E_SECPKG_NOT_FOUND;
1827 if (!table->SetContextAttributesW)
1829 WLog_WARN(TAG,
"Security module does not provide an implementation");
1830 return SEC_E_UNSUPPORTED_FUNCTION;
1833 status = table->SetContextAttributesW(phContext, ulAttribute, pBuffer, cbBuffer);
1834 return log_status(
"SetContextAttributesW", status);
1837static SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesA(
PCtxtHandle phContext,
1838 ULONG ulAttribute,
void* pBuffer,
1841 char* Name =
nullptr;
1842 SECURITY_STATUS status = 0;
1844 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1847 return SEC_E_SECPKG_NOT_FOUND;
1849 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1852 return SEC_E_SECPKG_NOT_FOUND;
1854 if (!table->SetContextAttributesA)
1856 WLog_WARN(TAG,
"Security module does not provide an implementation");
1857 return SEC_E_UNSUPPORTED_FUNCTION;
1860 status = table->SetContextAttributesA(phContext, ulAttribute, pBuffer, cbBuffer);
1861 return log_status(
"SetContextAttributesA", status);
1864static SECURITY_STATUS SEC_ENTRY winpr_RevertSecurityContext(
PCtxtHandle phContext)
1866 SEC_CHAR* Name =
nullptr;
1867 SECURITY_STATUS status = 0;
1869 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1872 return SEC_E_SECPKG_NOT_FOUND;
1874 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1877 return SEC_E_SECPKG_NOT_FOUND;
1879 if (!table->RevertSecurityContext)
1881 WLog_WARN(TAG,
"Security module does not provide an implementation");
1882 return SEC_E_UNSUPPORTED_FUNCTION;
1885 status = table->RevertSecurityContext(phContext);
1887 return log_status(
"RevertSecurityContext", status);
1892static SECURITY_STATUS SEC_ENTRY winpr_DecryptMessage(
PCtxtHandle phContext,
1896 char* Name =
nullptr;
1897 SECURITY_STATUS status = 0;
1899 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1902 return SEC_E_SECPKG_NOT_FOUND;
1904 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1907 return SEC_E_SECPKG_NOT_FOUND;
1909 if (!table->DecryptMessage)
1911 WLog_WARN(TAG,
"Security module does not provide an implementation");
1912 return SEC_E_UNSUPPORTED_FUNCTION;
1915 status = table->DecryptMessage(phContext, pMessage, MessageSeqNo, pfQOP);
1917 return log_status(
"DecryptMessage", status);
1920static SECURITY_STATUS SEC_ENTRY winpr_EncryptMessage(
PCtxtHandle phContext, ULONG fQOP,
1923 char* Name =
nullptr;
1924 SECURITY_STATUS status = 0;
1926 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1929 return SEC_E_SECPKG_NOT_FOUND;
1931 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1934 return SEC_E_SECPKG_NOT_FOUND;
1936 if (!table->EncryptMessage)
1938 WLog_WARN(TAG,
"Security module does not provide an implementation");
1939 return SEC_E_UNSUPPORTED_FUNCTION;
1942 status = table->EncryptMessage(phContext, fQOP, pMessage, MessageSeqNo);
1943 return log_status(
"EncryptMessage", status);
1946static SECURITY_STATUS SEC_ENTRY winpr_MakeSignature(
PCtxtHandle phContext, ULONG fQOP,
1949 SECURITY_STATUS status = 0;
1950 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phContext);
1953 return SEC_E_SECPKG_NOT_FOUND;
1958 return SEC_E_SECPKG_NOT_FOUND;
1960 if (!table->MakeSignature)
1962 WLog_WARN(TAG,
"Security module does not provide an implementation");
1963 return SEC_E_UNSUPPORTED_FUNCTION;
1966 status = table->MakeSignature(phContext, fQOP, pMessage, MessageSeqNo);
1967 return log_status(
"MakeSignature", status);
1970static SECURITY_STATUS SEC_ENTRY winpr_VerifySignature(
PCtxtHandle phContext,
1974 SECURITY_STATUS status = 0;
1976 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phContext);
1979 return SEC_E_SECPKG_NOT_FOUND;
1984 return SEC_E_SECPKG_NOT_FOUND;
1986 if (!table->VerifySignature)
1988 WLog_WARN(TAG,
"Security module does not provide an implementation");
1989 return SEC_E_UNSUPPORTED_FUNCTION;
1992 status = table->VerifySignature(phContext, pMessage, MessageSeqNo, pfQOP);
1994 return log_status(
"VerifySignature", status);
1999 winpr_EnumerateSecurityPackagesA,
2000 winpr_QueryCredentialsAttributesA,
2001 winpr_AcquireCredentialsHandleA,
2002 winpr_FreeCredentialsHandle,
2004 winpr_InitializeSecurityContextA,
2005 winpr_AcceptSecurityContext,
2006 winpr_CompleteAuthToken,
2007 winpr_DeleteSecurityContext,
2008 winpr_ApplyControlToken,
2009 winpr_QueryContextAttributesA,
2010 winpr_ImpersonateSecurityContext,
2011 winpr_RevertSecurityContext,
2012 winpr_MakeSignature,
2013 winpr_VerifySignature,
2014 winpr_FreeContextBuffer,
2015 winpr_QuerySecurityPackageInfoA,
2018 winpr_ExportSecurityContext,
2019 winpr_ImportSecurityContextA,
2022 winpr_QuerySecurityContextToken,
2023 winpr_EncryptMessage,
2024 winpr_DecryptMessage,
2025 winpr_SetContextAttributesA,
2026 winpr_SetCredentialsAttributesA,
2031 winpr_EnumerateSecurityPackagesW,
2032 winpr_QueryCredentialsAttributesW,
2033 winpr_AcquireCredentialsHandleW,
2034 winpr_FreeCredentialsHandle,
2036 winpr_InitializeSecurityContextW,
2037 winpr_AcceptSecurityContext,
2038 winpr_CompleteAuthToken,
2039 winpr_DeleteSecurityContext,
2040 winpr_ApplyControlToken,
2041 winpr_QueryContextAttributesW,
2042 winpr_ImpersonateSecurityContext,
2043 winpr_RevertSecurityContext,
2044 winpr_MakeSignature,
2045 winpr_VerifySignature,
2046 winpr_FreeContextBuffer,
2047 winpr_QuerySecurityPackageInfoW,
2050 winpr_ExportSecurityContext,
2051 winpr_ImportSecurityContextW,
2054 winpr_QuerySecurityContextToken,
2055 winpr_EncryptMessage,
2056 winpr_DecryptMessage,
2057 winpr_SetContextAttributesW,
2058 winpr_SetCredentialsAttributesW,
2063 return &winpr_SecurityFunctionTableW;
2068 return &winpr_SecurityFunctionTableA;