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] = { 0 };
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 = { 0 };
99static int sspi_ContextBufferAllocTableNew(
void)
102 ContextBufferAllocTable.entries = NULL;
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 = NULL;
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 = NULL;
150static void* sspi_ContextBufferAlloc(UINT32 allocatorIndex,
size_t size)
152 void* contextBuffer = NULL;
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 = NULL;
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 = NULL;
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 = NULL;
384 LPWSTR unicodeDomain = NULL;
385 LPWSTR unicodePassword = NULL;
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 = NULL;
594 const char* DomainA = NULL;
595 const char* PasswordA = NULL;
596 const WCHAR* UserW = NULL;
597 const WCHAR* DomainW = NULL;
598 const WCHAR* PasswordW = NULL;
599 UINT32 UserLength = 0;
600 UINT32 DomainLength = 0;
601 UINT32 PasswordLength = 0;
603 if (!identity || !pUser || !pDomain || !pPassword)
606 *pUser = *pDomain = *pPassword = NULL;
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, NULL);
661 if (DomainW && (DomainLength > 0))
663 *pDomain = ConvertWCharNToUtf8Alloc(DomainW, DomainLength, NULL);
668 if (PasswordW && (PasswordLength > 0))
670 *pPassword = ConvertWCharNToUtf8Alloc(PasswordW, PasswordLength, NULL);
683 WCHAR** pDomain, WCHAR** pPassword)
685 BOOL success = FALSE;
686 const char* UserA = NULL;
687 const char* DomainA = NULL;
688 const char* PasswordA = NULL;
689 const WCHAR* UserW = NULL;
690 const WCHAR* DomainW = NULL;
691 const WCHAR* PasswordW = NULL;
692 UINT32 UserLength = 0;
693 UINT32 DomainLength = 0;
694 UINT32 PasswordLength = 0;
696 if (!identity || !pUser || !pDomain || !pPassword)
699 *pUser = *pDomain = *pPassword = NULL;
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, NULL);
721 if (DomainA && (DomainLength > 0))
723 WCHAR* ptr = ConvertUtf8NToWCharAlloc(DomainA, DomainLength, NULL);
729 if (PasswordA && (PasswordLength > 0))
731 WCHAR* ptr = ConvertUtf8NToWCharAlloc(PasswordA, PasswordLength, NULL);
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 = NULL;
785 const char* PackageListA = NULL;
786 const WCHAR* PackageListW = NULL;
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, NULL);
833 *pPackageList = PackageList;
840int sspi_CopyAuthIdentity(SEC_WINNT_AUTH_IDENTITY* identity,
844 UINT32 identityFlags = 0;
845 const char* UserA = NULL;
846 const char* DomainA = NULL;
847 const char* PasswordA = NULL;
848 const WCHAR* UserW = NULL;
849 const WCHAR* DomainW = NULL;
850 const WCHAR* PasswordW = NULL;
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 winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT);
976 sspi_ContextBufferAllocTableNew();
977 if (!SCHANNEL_init())
979 if (!KERBEROS_init())
985 if (!NEGOTIATE_init())
990void sspi_GlobalInit(
void)
992 static INIT_ONCE once = INIT_ONCE_STATIC_INIT;
994 InitOnceExecuteOnce(&once, sspi_init, &flags, NULL);
997void sspi_GlobalFinish(
void)
999 sspi_ContextBufferAllocTableFree();
1004 size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1006 for (
size_t index = 0; index < cPackages; index++)
1008 if (strcmp(Name, SecurityFunctionTableA_NAME_LIST[index].Name) == 0)
1010 return SecurityFunctionTableA_NAME_LIST[index].SecurityFunctionTable;
1019 size_t cPackages = ARRAYSIZE(SecPkgInfoW_LIST);
1021 for (
size_t index = 0; index < cPackages; index++)
1023 if (_wcscmp(Name, SecurityFunctionTableW_NAME_LIST[index].Name) == 0)
1025 return SecurityFunctionTableW_NAME_LIST[index].SecurityFunctionTable;
1034 SEC_WCHAR* NameW = NULL;
1040 NameW = ConvertUtf8ToWCharAlloc(Name, NULL);
1045 table = sspi_GetSecurityFunctionTableWByNameW(NameW);
1050static void FreeContextBuffer_EnumerateSecurityPackages(
void* contextBuffer);
1051static void FreeContextBuffer_QuerySecurityPackageInfo(
void* contextBuffer);
1053static void sspi_ContextBufferFree(
void* contextBuffer)
1055 UINT32 allocatorIndex = 0;
1057 for (
size_t index = 0; index < ContextBufferAllocTable.cMaxEntries; index++)
1059 if (contextBuffer == ContextBufferAllocTable.entries[index].contextBuffer)
1061 contextBuffer = ContextBufferAllocTable.entries[index].contextBuffer;
1062 allocatorIndex = ContextBufferAllocTable.entries[index].allocatorIndex;
1063 ContextBufferAllocTable.cEntries--;
1064 ContextBufferAllocTable.entries[index].allocatorIndex = 0;
1065 ContextBufferAllocTable.entries[index].contextBuffer = NULL;
1067 switch (allocatorIndex)
1069 case EnumerateSecurityPackagesIndex:
1070 FreeContextBuffer_EnumerateSecurityPackages(contextBuffer);
1073 case QuerySecurityPackageInfoIndex:
1074 FreeContextBuffer_QuerySecurityPackageInfo(contextBuffer);
1089static SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesW(ULONG* pcPackages,
1092 const size_t cPackages = ARRAYSIZE(SecPkgInfoW_LIST);
1093 const size_t size =
sizeof(
SecPkgInfoW) * cPackages;
1095 (
SecPkgInfoW*)sspi_ContextBufferAlloc(EnumerateSecurityPackagesIndex, size);
1097 WINPR_ASSERT(cPackages <= UINT32_MAX);
1100 return SEC_E_INSUFFICIENT_MEMORY;
1102 for (
size_t index = 0; index < cPackages; index++)
1104 pPackageInfo[index].fCapabilities = SecPkgInfoW_LIST[index]->fCapabilities;
1105 pPackageInfo[index].wVersion = SecPkgInfoW_LIST[index]->wVersion;
1106 pPackageInfo[index].wRPCID = SecPkgInfoW_LIST[index]->wRPCID;
1107 pPackageInfo[index].cbMaxToken = SecPkgInfoW_LIST[index]->cbMaxToken;
1108 pPackageInfo[index].Name = _wcsdup(SecPkgInfoW_LIST[index]->Name);
1109 pPackageInfo[index].Comment = _wcsdup(SecPkgInfoW_LIST[index]->Comment);
1112 *(pcPackages) = (UINT32)cPackages;
1113 *(ppPackageInfo) = pPackageInfo;
1117static SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesA(ULONG* pcPackages,
1120 const size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1121 const size_t size =
sizeof(
SecPkgInfoA) * cPackages;
1123 (
SecPkgInfoA*)sspi_ContextBufferAlloc(EnumerateSecurityPackagesIndex, size);
1125 WINPR_ASSERT(cPackages <= UINT32_MAX);
1128 return SEC_E_INSUFFICIENT_MEMORY;
1130 for (
size_t index = 0; index < cPackages; index++)
1132 pPackageInfo[index].fCapabilities = SecPkgInfoA_LIST[index]->fCapabilities;
1133 pPackageInfo[index].wVersion = SecPkgInfoA_LIST[index]->wVersion;
1134 pPackageInfo[index].wRPCID = SecPkgInfoA_LIST[index]->wRPCID;
1135 pPackageInfo[index].cbMaxToken = SecPkgInfoA_LIST[index]->cbMaxToken;
1136 pPackageInfo[index].Name = _strdup(SecPkgInfoA_LIST[index]->Name);
1137 pPackageInfo[index].Comment = _strdup(SecPkgInfoA_LIST[index]->Comment);
1139 if (!pPackageInfo[index].Name || !pPackageInfo[index].Comment)
1141 sspi_ContextBufferFree(pPackageInfo);
1142 return SEC_E_INSUFFICIENT_MEMORY;
1146 *(pcPackages) = (UINT32)cPackages;
1147 *(ppPackageInfo) = pPackageInfo;
1151static void FreeContextBuffer_EnumerateSecurityPackages(
void* contextBuffer)
1154 size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1159 for (
size_t index = 0; index < cPackages; index++)
1161 free(pPackageInfo[index].Name);
1162 free(pPackageInfo[index].Comment);
1168static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoW(SEC_WCHAR* pszPackageName,
1171 size_t cPackages = ARRAYSIZE(SecPkgInfoW_LIST);
1173 for (
size_t index = 0; index < cPackages; index++)
1175 if (_wcscmp(pszPackageName, SecPkgInfoW_LIST[index]->Name) == 0)
1179 (
SecPkgInfoW*)sspi_ContextBufferAlloc(QuerySecurityPackageInfoIndex, size);
1182 return SEC_E_INSUFFICIENT_MEMORY;
1184 pPackageInfo->fCapabilities = SecPkgInfoW_LIST[index]->fCapabilities;
1185 pPackageInfo->wVersion = SecPkgInfoW_LIST[index]->wVersion;
1186 pPackageInfo->wRPCID = SecPkgInfoW_LIST[index]->wRPCID;
1187 pPackageInfo->cbMaxToken = SecPkgInfoW_LIST[index]->cbMaxToken;
1188 pPackageInfo->Name = _wcsdup(SecPkgInfoW_LIST[index]->Name);
1189 pPackageInfo->Comment = _wcsdup(SecPkgInfoW_LIST[index]->Comment);
1190 *(ppPackageInfo) = pPackageInfo;
1195 *(ppPackageInfo) = NULL;
1196 return SEC_E_SECPKG_NOT_FOUND;
1199static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoA(SEC_CHAR* pszPackageName,
1202 size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1204 for (
size_t index = 0; index < cPackages; index++)
1206 if (strcmp(pszPackageName, SecPkgInfoA_LIST[index]->Name) == 0)
1210 (
SecPkgInfoA*)sspi_ContextBufferAlloc(QuerySecurityPackageInfoIndex, size);
1213 return SEC_E_INSUFFICIENT_MEMORY;
1215 pPackageInfo->fCapabilities = SecPkgInfoA_LIST[index]->fCapabilities;
1216 pPackageInfo->wVersion = SecPkgInfoA_LIST[index]->wVersion;
1217 pPackageInfo->wRPCID = SecPkgInfoA_LIST[index]->wRPCID;
1218 pPackageInfo->cbMaxToken = SecPkgInfoA_LIST[index]->cbMaxToken;
1219 pPackageInfo->Name = _strdup(SecPkgInfoA_LIST[index]->Name);
1220 pPackageInfo->Comment = _strdup(SecPkgInfoA_LIST[index]->Comment);
1222 if (!pPackageInfo->Name || !pPackageInfo->Comment)
1224 sspi_ContextBufferFree(pPackageInfo);
1225 return SEC_E_INSUFFICIENT_MEMORY;
1228 *(ppPackageInfo) = pPackageInfo;
1233 *(ppPackageInfo) = NULL;
1234 return SEC_E_SECPKG_NOT_FOUND;
1237void FreeContextBuffer_QuerySecurityPackageInfo(
void* contextBuffer)
1239 SecPkgInfo* pPackageInfo = (SecPkgInfo*)contextBuffer;
1244 free(pPackageInfo->Name);
1245 free(pPackageInfo->Comment);
1249#define log_status(what, status) log_status_((what), (status), __FILE__, __func__, __LINE__)
1250static SECURITY_STATUS log_status_(
const char* what, SECURITY_STATUS status,
const char* file,
1251 const char* fkt,
size_t line)
1253 if (IsSecurityStatusError(status))
1255 const DWORD level = WLOG_WARN;
1256 static wLog* log = NULL;
1258 log = WLog_Get(TAG);
1260 if (WLog_IsLevelActive(log, level))
1262 WLog_PrintTextMessage(log, level, line, file, fkt,
"%s status %s [0x%08" PRIx32
"]",
1263 what, GetSecurityStatusString(status),
1264 WINPR_CXX_COMPAT_CAST(uint32_t, status));
1272static SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleW(
1273 SEC_WCHAR* pszPrincipal, SEC_WCHAR* pszPackage, ULONG fCredentialUse,
void* pvLogonID,
1274 void* pAuthData, SEC_GET_KEY_FN pGetKeyFn,
void* pvGetKeyArgument,
PCredHandle phCredential,
1277 SECURITY_STATUS status = 0;
1281 return SEC_E_SECPKG_NOT_FOUND;
1283 if (!table->AcquireCredentialsHandleW)
1285 WLog_WARN(TAG,
"Security module does not provide an implementation");
1286 return SEC_E_UNSUPPORTED_FUNCTION;
1289 status = table->AcquireCredentialsHandleW(pszPrincipal, pszPackage, fCredentialUse, pvLogonID,
1290 pAuthData, pGetKeyFn, pvGetKeyArgument, phCredential,
1292 return log_status(
"AcquireCredentialsHandleW", status);
1295static SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleA(
1296 SEC_CHAR* pszPrincipal, SEC_CHAR* pszPackage, ULONG fCredentialUse,
void* pvLogonID,
1297 void* pAuthData, SEC_GET_KEY_FN pGetKeyFn,
void* pvGetKeyArgument,
PCredHandle phCredential,
1300 SECURITY_STATUS status = 0;
1304 return SEC_E_SECPKG_NOT_FOUND;
1306 if (!table->AcquireCredentialsHandleA)
1308 WLog_WARN(TAG,
"Security module does not provide an implementation");
1309 return SEC_E_UNSUPPORTED_FUNCTION;
1312 status = table->AcquireCredentialsHandleA(pszPrincipal, pszPackage, fCredentialUse, pvLogonID,
1313 pAuthData, pGetKeyFn, pvGetKeyArgument, phCredential,
1315 return log_status(
"AcquireCredentialsHandleA", status);
1318static SECURITY_STATUS SEC_ENTRY winpr_ExportSecurityContext(
PCtxtHandle phContext, ULONG fFlags,
1322 SEC_CHAR* Name = NULL;
1323 SECURITY_STATUS status = 0;
1325 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1328 return SEC_E_SECPKG_NOT_FOUND;
1330 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1333 return SEC_E_SECPKG_NOT_FOUND;
1335 if (!table->ExportSecurityContext)
1337 WLog_WARN(TAG,
"Security module does not provide an implementation");
1338 return SEC_E_UNSUPPORTED_FUNCTION;
1341 status = table->ExportSecurityContext(phContext, fFlags, pPackedContext, pToken);
1342 return log_status(
"ExportSecurityContext", status);
1345static SECURITY_STATUS SEC_ENTRY winpr_FreeCredentialsHandle(
PCredHandle phCredential)
1348 SECURITY_STATUS status = 0;
1350 Name = (
char*)sspi_SecureHandleGetUpperPointer(phCredential);
1353 return SEC_E_SECPKG_NOT_FOUND;
1355 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1358 return SEC_E_SECPKG_NOT_FOUND;
1360 if (!table->FreeCredentialsHandle)
1362 WLog_WARN(TAG,
"Security module does not provide an implementation");
1363 return SEC_E_UNSUPPORTED_FUNCTION;
1366 status = table->FreeCredentialsHandle(phCredential);
1367 return log_status(
"FreeCredentialsHandle", status);
1370static SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextW(SEC_WCHAR* pszPackage,
1374 SEC_CHAR* Name = NULL;
1375 SECURITY_STATUS status = 0;
1377 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1380 return SEC_E_SECPKG_NOT_FOUND;
1382 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1385 return SEC_E_SECPKG_NOT_FOUND;
1387 if (!table->ImportSecurityContextW)
1389 WLog_WARN(TAG,
"Security module does not provide an implementation");
1390 return SEC_E_UNSUPPORTED_FUNCTION;
1393 status = table->ImportSecurityContextW(pszPackage, pPackedContext, pToken, phContext);
1394 return log_status(
"ImportSecurityContextW", status);
1397static SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextA(SEC_CHAR* pszPackage,
1402 SECURITY_STATUS status = 0;
1404 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1407 return SEC_E_SECPKG_NOT_FOUND;
1409 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1412 return SEC_E_SECPKG_NOT_FOUND;
1414 if (!table->ImportSecurityContextA)
1416 WLog_WARN(TAG,
"Security module does not provide an implementation");
1417 return SEC_E_UNSUPPORTED_FUNCTION;
1420 status = table->ImportSecurityContextA(pszPackage, pPackedContext, pToken, phContext);
1421 return log_status(
"ImportSecurityContextA", status);
1424static SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesW(
PCredHandle phCredential,
1425 ULONG ulAttribute,
void* pBuffer)
1427 SEC_WCHAR* Name = NULL;
1428 SECURITY_STATUS status = 0;
1430 Name = (SEC_WCHAR*)sspi_SecureHandleGetUpperPointer(phCredential);
1433 return SEC_E_SECPKG_NOT_FOUND;
1435 table = sspi_GetSecurityFunctionTableWByNameW(Name);
1438 return SEC_E_SECPKG_NOT_FOUND;
1440 if (!table->QueryCredentialsAttributesW)
1442 WLog_WARN(TAG,
"Security module does not provide an implementation");
1443 return SEC_E_UNSUPPORTED_FUNCTION;
1446 status = table->QueryCredentialsAttributesW(phCredential, ulAttribute, pBuffer);
1447 return log_status(
"QueryCredentialsAttributesW", status);
1450static SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesA(
PCredHandle phCredential,
1451 ULONG ulAttribute,
void* pBuffer)
1454 SECURITY_STATUS status = 0;
1456 Name = (
char*)sspi_SecureHandleGetUpperPointer(phCredential);
1459 return SEC_E_SECPKG_NOT_FOUND;
1461 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1464 return SEC_E_SECPKG_NOT_FOUND;
1466 if (!table->QueryCredentialsAttributesA)
1468 WLog_WARN(TAG,
"Security module does not provide an implementation");
1469 return SEC_E_UNSUPPORTED_FUNCTION;
1472 status = table->QueryCredentialsAttributesA(phCredential, ulAttribute, pBuffer);
1473 return log_status(
"QueryCredentialsAttributesA", status);
1476static SECURITY_STATUS SEC_ENTRY winpr_SetCredentialsAttributesW(
PCredHandle phCredential,
1477 ULONG ulAttribute,
void* pBuffer,
1480 SEC_WCHAR* Name = NULL;
1481 SECURITY_STATUS status = 0;
1483 Name = (SEC_WCHAR*)sspi_SecureHandleGetUpperPointer(phCredential);
1486 return SEC_E_SECPKG_NOT_FOUND;
1488 table = sspi_GetSecurityFunctionTableWByNameW(Name);
1491 return SEC_E_SECPKG_NOT_FOUND;
1493 if (!table->SetCredentialsAttributesW)
1495 WLog_WARN(TAG,
"Security module does not provide an implementation");
1496 return SEC_E_UNSUPPORTED_FUNCTION;
1499 status = table->SetCredentialsAttributesW(phCredential, ulAttribute, pBuffer, cbBuffer);
1500 return log_status(
"SetCredentialsAttributesW", status);
1503static SECURITY_STATUS SEC_ENTRY winpr_SetCredentialsAttributesA(
PCredHandle phCredential,
1504 ULONG ulAttribute,
void* pBuffer,
1508 SECURITY_STATUS status = 0;
1510 Name = (
char*)sspi_SecureHandleGetUpperPointer(phCredential);
1513 return SEC_E_SECPKG_NOT_FOUND;
1515 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1518 return SEC_E_SECPKG_NOT_FOUND;
1520 if (!table->SetCredentialsAttributesA)
1522 WLog_WARN(TAG,
"Security module does not provide an implementation");
1523 return SEC_E_UNSUPPORTED_FUNCTION;
1526 status = table->SetCredentialsAttributesA(phCredential, ulAttribute, pBuffer, cbBuffer);
1527 return log_status(
"SetCredentialsAttributesA", status);
1532static SECURITY_STATUS SEC_ENTRY
1534 ULONG fContextReq, ULONG TargetDataRep,
PCtxtHandle phNewContext,
1538 SECURITY_STATUS status = 0;
1540 Name = (
char*)sspi_SecureHandleGetUpperPointer(phCredential);
1543 return SEC_E_SECPKG_NOT_FOUND;
1545 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1548 return SEC_E_SECPKG_NOT_FOUND;
1550 if (!table->AcceptSecurityContext)
1552 WLog_WARN(TAG,
"Security module does not provide an implementation");
1553 return SEC_E_UNSUPPORTED_FUNCTION;
1557 table->AcceptSecurityContext(phCredential, phContext, pInput, fContextReq, TargetDataRep,
1558 phNewContext, pOutput, pfContextAttr, ptsTimeStamp);
1559 return log_status(
"AcceptSecurityContext", status);
1562static SECURITY_STATUS SEC_ENTRY winpr_ApplyControlToken(
PCtxtHandle phContext,
1566 SECURITY_STATUS status = 0;
1568 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1571 return SEC_E_SECPKG_NOT_FOUND;
1573 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1576 return SEC_E_SECPKG_NOT_FOUND;
1578 if (!table->ApplyControlToken)
1580 WLog_WARN(TAG,
"Security module does not provide an implementation");
1581 return SEC_E_UNSUPPORTED_FUNCTION;
1584 status = table->ApplyControlToken(phContext, pInput);
1585 return log_status(
"ApplyControlToken", status);
1588static SECURITY_STATUS SEC_ENTRY winpr_CompleteAuthToken(
PCtxtHandle phContext,
1592 SECURITY_STATUS status = 0;
1594 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1597 return SEC_E_SECPKG_NOT_FOUND;
1599 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1602 return SEC_E_SECPKG_NOT_FOUND;
1604 if (!table->CompleteAuthToken)
1606 WLog_WARN(TAG,
"Security module does not provide an implementation");
1607 return SEC_E_UNSUPPORTED_FUNCTION;
1610 status = table->CompleteAuthToken(phContext, pToken);
1611 return log_status(
"CompleteAuthToken", status);
1614static SECURITY_STATUS SEC_ENTRY winpr_DeleteSecurityContext(
PCtxtHandle phContext)
1616 const char* Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1619 return SEC_E_SECPKG_NOT_FOUND;
1624 return SEC_E_SECPKG_NOT_FOUND;
1626 if (!table->DeleteSecurityContext)
1628 WLog_WARN(TAG,
"Security module does not provide an implementation");
1629 return SEC_E_UNSUPPORTED_FUNCTION;
1632 const SECURITY_STATUS status = table->DeleteSecurityContext(phContext);
1633 return log_status(
"DeleteSecurityContext", status);
1636static SECURITY_STATUS SEC_ENTRY winpr_FreeContextBuffer(
void* pvContextBuffer)
1638 if (!pvContextBuffer)
1639 return SEC_E_INVALID_HANDLE;
1641 sspi_ContextBufferFree(pvContextBuffer);
1645static SECURITY_STATUS SEC_ENTRY winpr_ImpersonateSecurityContext(
PCtxtHandle phContext)
1647 SEC_CHAR* Name = NULL;
1648 SECURITY_STATUS status = 0;
1650 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1653 return SEC_E_SECPKG_NOT_FOUND;
1655 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1658 return SEC_E_SECPKG_NOT_FOUND;
1660 if (!table->ImpersonateSecurityContext)
1662 WLog_WARN(TAG,
"Security module does not provide an implementation");
1663 return SEC_E_UNSUPPORTED_FUNCTION;
1666 status = table->ImpersonateSecurityContext(phContext);
1667 return log_status(
"ImpersonateSecurityContext", status);
1670static SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextW(
1672 ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2,
1675 SEC_CHAR* Name = NULL;
1676 SECURITY_STATUS status = 0;
1678 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phCredential);
1681 return SEC_E_SECPKG_NOT_FOUND;
1683 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1686 return SEC_E_SECPKG_NOT_FOUND;
1688 if (!table->InitializeSecurityContextW)
1690 WLog_WARN(TAG,
"Security module does not provide an implementation");
1691 return SEC_E_UNSUPPORTED_FUNCTION;
1694 status = table->InitializeSecurityContextW(phCredential, phContext, pszTargetName, fContextReq,
1695 Reserved1, TargetDataRep, pInput, Reserved2,
1696 phNewContext, pOutput, pfContextAttr, ptsExpiry);
1697 return log_status(
"InitializeSecurityContextW", status);
1700static SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextA(
1702 ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2,
1705 SEC_CHAR* Name = NULL;
1706 SECURITY_STATUS status = 0;
1708 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phCredential);
1711 return SEC_E_SECPKG_NOT_FOUND;
1713 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1716 return SEC_E_SECPKG_NOT_FOUND;
1718 if (!table->InitializeSecurityContextA)
1720 WLog_WARN(TAG,
"Security module does not provide an implementation");
1721 return SEC_E_UNSUPPORTED_FUNCTION;
1724 status = table->InitializeSecurityContextA(phCredential, phContext, pszTargetName, fContextReq,
1725 Reserved1, TargetDataRep, pInput, Reserved2,
1726 phNewContext, pOutput, pfContextAttr, ptsExpiry);
1728 return log_status(
"InitializeSecurityContextA", status);
1731static SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesW(
PCtxtHandle phContext,
1732 ULONG ulAttribute,
void* pBuffer)
1734 SEC_CHAR* Name = NULL;
1735 SECURITY_STATUS status = 0;
1737 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1740 return SEC_E_SECPKG_NOT_FOUND;
1742 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1745 return SEC_E_SECPKG_NOT_FOUND;
1747 if (!table->QueryContextAttributesW)
1749 WLog_WARN(TAG,
"Security module does not provide an implementation");
1750 return SEC_E_UNSUPPORTED_FUNCTION;
1753 status = table->QueryContextAttributesW(phContext, ulAttribute, pBuffer);
1754 return log_status(
"QueryContextAttributesW", status);
1757static SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesA(
PCtxtHandle phContext,
1758 ULONG ulAttribute,
void* pBuffer)
1760 SEC_CHAR* Name = NULL;
1761 SECURITY_STATUS status = 0;
1763 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1766 return SEC_E_SECPKG_NOT_FOUND;
1768 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1771 return SEC_E_SECPKG_NOT_FOUND;
1773 if (!table->QueryContextAttributesA)
1775 WLog_WARN(TAG,
"Security module does not provide an implementation");
1776 return SEC_E_UNSUPPORTED_FUNCTION;
1779 status = table->QueryContextAttributesA(phContext, ulAttribute, pBuffer);
1780 return log_status(
"QueryContextAttributesA", status);
1783static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityContextToken(
PCtxtHandle phContext,
1786 SEC_CHAR* Name = NULL;
1787 SECURITY_STATUS status = 0;
1789 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1792 return SEC_E_SECPKG_NOT_FOUND;
1794 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1797 return SEC_E_SECPKG_NOT_FOUND;
1799 if (!table->QuerySecurityContextToken)
1801 WLog_WARN(TAG,
"Security module does not provide an implementation");
1802 return SEC_E_UNSUPPORTED_FUNCTION;
1805 status = table->QuerySecurityContextToken(phContext, phToken);
1806 return log_status(
"QuerySecurityContextToken", status);
1809static SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesW(
PCtxtHandle phContext,
1810 ULONG ulAttribute,
void* pBuffer,
1813 SEC_CHAR* Name = NULL;
1814 SECURITY_STATUS status = 0;
1816 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1819 return SEC_E_SECPKG_NOT_FOUND;
1821 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1824 return SEC_E_SECPKG_NOT_FOUND;
1826 if (!table->SetContextAttributesW)
1828 WLog_WARN(TAG,
"Security module does not provide an implementation");
1829 return SEC_E_UNSUPPORTED_FUNCTION;
1832 status = table->SetContextAttributesW(phContext, ulAttribute, pBuffer, cbBuffer);
1833 return log_status(
"SetContextAttributesW", status);
1836static SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesA(
PCtxtHandle phContext,
1837 ULONG ulAttribute,
void* pBuffer,
1841 SECURITY_STATUS status = 0;
1843 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1846 return SEC_E_SECPKG_NOT_FOUND;
1848 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1851 return SEC_E_SECPKG_NOT_FOUND;
1853 if (!table->SetContextAttributesA)
1855 WLog_WARN(TAG,
"Security module does not provide an implementation");
1856 return SEC_E_UNSUPPORTED_FUNCTION;
1859 status = table->SetContextAttributesA(phContext, ulAttribute, pBuffer, cbBuffer);
1860 return log_status(
"SetContextAttributesA", status);
1863static SECURITY_STATUS SEC_ENTRY winpr_RevertSecurityContext(
PCtxtHandle phContext)
1865 SEC_CHAR* Name = NULL;
1866 SECURITY_STATUS status = 0;
1868 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1871 return SEC_E_SECPKG_NOT_FOUND;
1873 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1876 return SEC_E_SECPKG_NOT_FOUND;
1878 if (!table->RevertSecurityContext)
1880 WLog_WARN(TAG,
"Security module does not provide an implementation");
1881 return SEC_E_UNSUPPORTED_FUNCTION;
1884 status = table->RevertSecurityContext(phContext);
1886 return log_status(
"RevertSecurityContext", status);
1891static SECURITY_STATUS SEC_ENTRY winpr_DecryptMessage(
PCtxtHandle phContext,
1896 SECURITY_STATUS status = 0;
1898 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1901 return SEC_E_SECPKG_NOT_FOUND;
1903 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1906 return SEC_E_SECPKG_NOT_FOUND;
1908 if (!table->DecryptMessage)
1910 WLog_WARN(TAG,
"Security module does not provide an implementation");
1911 return SEC_E_UNSUPPORTED_FUNCTION;
1914 status = table->DecryptMessage(phContext, pMessage, MessageSeqNo, pfQOP);
1916 return log_status(
"DecryptMessage", status);
1919static SECURITY_STATUS SEC_ENTRY winpr_EncryptMessage(
PCtxtHandle phContext, ULONG fQOP,
1923 SECURITY_STATUS status = 0;
1925 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1928 return SEC_E_SECPKG_NOT_FOUND;
1930 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1933 return SEC_E_SECPKG_NOT_FOUND;
1935 if (!table->EncryptMessage)
1937 WLog_WARN(TAG,
"Security module does not provide an implementation");
1938 return SEC_E_UNSUPPORTED_FUNCTION;
1941 status = table->EncryptMessage(phContext, fQOP, pMessage, MessageSeqNo);
1942 return log_status(
"EncryptMessage", status);
1945static SECURITY_STATUS SEC_ENTRY winpr_MakeSignature(
PCtxtHandle phContext, ULONG fQOP,
1948 SECURITY_STATUS status = 0;
1949 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phContext);
1952 return SEC_E_SECPKG_NOT_FOUND;
1957 return SEC_E_SECPKG_NOT_FOUND;
1959 if (!table->MakeSignature)
1961 WLog_WARN(TAG,
"Security module does not provide an implementation");
1962 return SEC_E_UNSUPPORTED_FUNCTION;
1965 status = table->MakeSignature(phContext, fQOP, pMessage, MessageSeqNo);
1966 return log_status(
"MakeSignature", status);
1969static SECURITY_STATUS SEC_ENTRY winpr_VerifySignature(
PCtxtHandle phContext,
1973 SECURITY_STATUS status = 0;
1975 const char* Name = (
const char*)sspi_SecureHandleGetUpperPointer(phContext);
1978 return SEC_E_SECPKG_NOT_FOUND;
1983 return SEC_E_SECPKG_NOT_FOUND;
1985 if (!table->VerifySignature)
1987 WLog_WARN(TAG,
"Security module does not provide an implementation");
1988 return SEC_E_UNSUPPORTED_FUNCTION;
1991 status = table->VerifySignature(phContext, pMessage, MessageSeqNo, pfQOP);
1993 return log_status(
"VerifySignature", status);
1998 winpr_EnumerateSecurityPackagesA,
1999 winpr_QueryCredentialsAttributesA,
2000 winpr_AcquireCredentialsHandleA,
2001 winpr_FreeCredentialsHandle,
2003 winpr_InitializeSecurityContextA,
2004 winpr_AcceptSecurityContext,
2005 winpr_CompleteAuthToken,
2006 winpr_DeleteSecurityContext,
2007 winpr_ApplyControlToken,
2008 winpr_QueryContextAttributesA,
2009 winpr_ImpersonateSecurityContext,
2010 winpr_RevertSecurityContext,
2011 winpr_MakeSignature,
2012 winpr_VerifySignature,
2013 winpr_FreeContextBuffer,
2014 winpr_QuerySecurityPackageInfoA,
2017 winpr_ExportSecurityContext,
2018 winpr_ImportSecurityContextA,
2021 winpr_QuerySecurityContextToken,
2022 winpr_EncryptMessage,
2023 winpr_DecryptMessage,
2024 winpr_SetContextAttributesA,
2025 winpr_SetCredentialsAttributesA,
2030 winpr_EnumerateSecurityPackagesW,
2031 winpr_QueryCredentialsAttributesW,
2032 winpr_AcquireCredentialsHandleW,
2033 winpr_FreeCredentialsHandle,
2035 winpr_InitializeSecurityContextW,
2036 winpr_AcceptSecurityContext,
2037 winpr_CompleteAuthToken,
2038 winpr_DeleteSecurityContext,
2039 winpr_ApplyControlToken,
2040 winpr_QueryContextAttributesW,
2041 winpr_ImpersonateSecurityContext,
2042 winpr_RevertSecurityContext,
2043 winpr_MakeSignature,
2044 winpr_VerifySignature,
2045 winpr_FreeContextBuffer,
2046 winpr_QuerySecurityPackageInfoW,
2049 winpr_ExportSecurityContext,
2050 winpr_ImportSecurityContextW,
2053 winpr_QuerySecurityContextToken,
2054 winpr_EncryptMessage,
2055 winpr_DecryptMessage,
2056 winpr_SetContextAttributesW,
2057 winpr_SetCredentialsAttributesW,
2062 return &winpr_SecurityFunctionTableW;
2067 return &winpr_SecurityFunctionTableA;