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);
186 credentials->ntlmSettingsV2 = sspi_AllocSecNtlmSettings();
187 if (!credentials->ntlmSettingsV2)
189 sspi_CredentialsFree(credentials);
201 size_t userLength = credentials->identity.UserLength;
202 size_t domainLength = credentials->identity.DomainLength;
203 size_t passwordLength = credentials->identity.PasswordLength;
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);
221 sspi_FreeSecNtlmSettings(credentials->ntlmSettingsV2);
260 SecInvalidateHandle(handle);
264void* sspi_SecureHandleGetLowerPointer(
SecHandle* handle)
266 void* pointer =
nullptr;
268 if (!handle || !SecIsValidHandle(handle) || !handle->dwLower)
271 pointer = (
void*)~((
size_t)handle->dwLower);
275void sspi_SecureHandleInvalidate(
SecHandle* handle)
284void sspi_SecureHandleSetLowerPointer(
SecHandle* handle,
void* pointer)
289 handle->dwLower = (ULONG_PTR)(~((
size_t)pointer));
292void* sspi_SecureHandleGetUpperPointer(
SecHandle* handle)
294 void* pointer =
nullptr;
296 if (!handle || !SecIsValidHandle(handle) || !handle->dwUpper)
299 pointer = (
void*)~((
size_t)handle->dwUpper);
303void sspi_SecureHandleSetUpperPointer(
SecHandle* handle,
void* pointer)
308 handle->dwUpper = (ULONG_PTR)(~((
size_t)pointer));
311SSPI_PACKAGE_ID sspi_SecureHandleGetPackageId(
SecHandle* handle)
313 if (!handle || !SecIsValidHandle(handle) || !handle->dwUpper)
314 return SSPI_PACKAGE_NONE;
316 return (SSPI_PACKAGE_ID)(~((size_t)handle->dwUpper));
319void sspi_SecureHandleSetPackageId(
SecHandle* handle, SSPI_PACKAGE_ID
id)
324 handle->dwUpper = (ULONG_PTR)(~((
size_t)
id));
327void sspi_SecureHandleFree(
SecHandle* handle)
332int sspi_SetAuthIdentityW(SEC_WINNT_AUTH_IDENTITY* identity,
const WCHAR* user,
const WCHAR* domain,
333 const WCHAR* password)
335 return sspi_SetAuthIdentityWithLengthW(identity, user, user ? _wcslen(user) : 0, domain,
336 domain ? _wcslen(domain) : 0, password,
337 password ? _wcslen(password) : 0);
340static BOOL copy(WCHAR** dst, ULONG* dstLen,
const WCHAR* what,
size_t len)
343 WINPR_ASSERT(dstLen);
348 if (len > UINT32_MAX)
352 if (!what && (len != 0))
354 if (!what && (len == 0))
357 *dst = calloc(
sizeof(WCHAR), len + 1);
361 memcpy(*dst, what, len *
sizeof(WCHAR));
362 *dstLen = WINPR_ASSERTING_INT_CAST(UINT32, len);
366int sspi_SetAuthIdentityWithLengthW(SEC_WINNT_AUTH_IDENTITY* identity,
const WCHAR* user,
367 size_t userLen,
const WCHAR* domain,
size_t domainLen,
368 const WCHAR* password,
size_t passwordLen)
370 WINPR_ASSERT(identity);
371 sspi_FreeAuthIdentity(identity);
372 identity->Flags &= (uint32_t)~SEC_WINNT_AUTH_IDENTITY_ANSI;
373 identity->Flags |= SEC_WINNT_AUTH_IDENTITY_UNICODE;
375 if (!copy(&identity->User, &identity->UserLength, user, userLen))
378 if (!copy(&identity->Domain, &identity->DomainLength, domain, domainLen))
381 if (!copy(&identity->Password, &identity->PasswordLength, password, passwordLen))
387int sspi_SetAuthIdentityA(SEC_WINNT_AUTH_IDENTITY* identity,
const char* user,
const char* domain,
388 const char* password)
391 size_t unicodeUserLenW = 0;
392 size_t unicodeDomainLenW = 0;
393 size_t unicodePasswordLenW = 0;
394 LPWSTR unicodeUser =
nullptr;
395 LPWSTR unicodeDomain =
nullptr;
396 LPWSTR unicodePassword =
nullptr;
399 unicodeUser = ConvertUtf8ToWCharAlloc(user, &unicodeUserLenW);
402 unicodeDomain = ConvertUtf8ToWCharAlloc(domain, &unicodeDomainLenW);
405 unicodePassword = ConvertUtf8ToWCharAlloc(password, &unicodePasswordLenW);
407 rc = sspi_SetAuthIdentityWithLengthW(identity, unicodeUser, unicodeUserLenW, unicodeDomain,
408 unicodeDomainLenW, unicodePassword, unicodePasswordLenW);
410 winpr_znfree(unicodeUser, unicodeUserLenW *
sizeof(WCHAR));
411 winpr_znfree(unicodeDomain, unicodeDomainLenW *
sizeof(WCHAR));
412 winpr_znfree(unicodePassword, unicodePasswordLenW *
sizeof(WCHAR));
416UINT32 sspi_GetAuthIdentityVersion(
const void* identity)
423 version = *((
const UINT32*)identity);
425 if ((version == SEC_WINNT_AUTH_IDENTITY_VERSION) ||
426 (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2))
434UINT32 sspi_GetAuthIdentityFlags(
const void* identity)
442 version = sspi_GetAuthIdentityVersion(identity);
444 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
446 flags = ((
const SEC_WINNT_AUTH_IDENTITY_EX*)identity)->Flags;
448 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
454 flags = ((
const SEC_WINNT_AUTH_IDENTITY*)identity)->Flags;
460BOOL sspi_GetAuthIdentityUserDomainW(
const void* identity,
const WCHAR** pUser, UINT32* pUserLength,
461 const WCHAR** pDomain, UINT32* pDomainLength)
468 version = sspi_GetAuthIdentityVersion(identity);
470 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
473 *pUser = (
const WCHAR*)id->User;
474 *pUserLength =
id->UserLength;
475 *pDomain = (
const WCHAR*)id->Domain;
476 *pDomainLength =
id->DomainLength;
478 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
481 UINT32 UserOffset =
id->UserOffset;
482 UINT32 DomainOffset =
id->DomainOffset;
483 *pUser = WINPR_PACKED_ALIGN_CAST(
const WCHAR*, &((
const uint8_t*)identity)[UserOffset]);
484 *pUserLength =
id->UserLength / 2;
485 *pDomain = WINPR_PACKED_ALIGN_CAST(
const WCHAR*, &((
const uint8_t*)identity)[DomainOffset]);
486 *pDomainLength =
id->DomainLength / 2;
491 *pUser = (
const WCHAR*)id->User;
492 *pUserLength =
id->UserLength;
493 *pDomain = (
const WCHAR*)id->Domain;
494 *pDomainLength =
id->DomainLength;
500BOOL sspi_GetAuthIdentityUserDomainA(
const void* identity,
const char** pUser, UINT32* pUserLength,
501 const char** pDomain, UINT32* pDomainLength)
508 version = sspi_GetAuthIdentityVersion(identity);
510 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
513 *pUser = (
const char*)id->User;
514 *pUserLength =
id->UserLength;
515 *pDomain = (
const char*)id->Domain;
516 *pDomainLength =
id->DomainLength;
518 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
521 UINT32 UserOffset =
id->UserOffset;
522 UINT32 DomainOffset =
id->DomainOffset;
523 *pUser = (
const char*)&((
const uint8_t*)identity)[UserOffset];
524 *pUserLength =
id->UserLength;
525 *pDomain = (
const char*)&((
const uint8_t*)identity)[DomainOffset];
526 *pDomainLength =
id->DomainLength;
531 *pUser = (
const char*)id->User;
532 *pUserLength =
id->UserLength;
533 *pDomain = (
const char*)id->Domain;
534 *pDomainLength =
id->DomainLength;
540BOOL sspi_GetAuthIdentityPasswordW(
const void* identity,
const WCHAR** pPassword,
541 UINT32* pPasswordLength)
548 version = sspi_GetAuthIdentityVersion(identity);
550 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
553 *pPassword = (
const WCHAR*)id->Password;
554 *pPasswordLength =
id->PasswordLength;
556 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
563 *pPassword = (
const WCHAR*)id->Password;
564 *pPasswordLength =
id->PasswordLength;
570BOOL sspi_GetAuthIdentityPasswordA(
const void* identity,
const char** pPassword,
571 UINT32* pPasswordLength)
578 version = sspi_GetAuthIdentityVersion(identity);
580 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
583 *pPassword = (
const char*)id->Password;
584 *pPasswordLength =
id->PasswordLength;
586 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
593 *pPassword = (
const char*)id->Password;
594 *pPasswordLength =
id->PasswordLength;
601 char** pDomain,
char** pPassword)
603 BOOL success = FALSE;
604 const char* UserA =
nullptr;
605 const char* DomainA =
nullptr;
606 const char* PasswordA =
nullptr;
607 const WCHAR* UserW =
nullptr;
608 const WCHAR* DomainW =
nullptr;
609 const WCHAR* PasswordW =
nullptr;
610 UINT32 UserLength = 0;
611 UINT32 DomainLength = 0;
612 UINT32 PasswordLength = 0;
614 if (!identity || !pUser || !pDomain || !pPassword)
617 *pUser = *pDomain = *pPassword =
nullptr;
619 UINT32 identityFlags = sspi_GetAuthIdentityFlags(identity);
621 if ((identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI) != 0)
623 if (!sspi_GetAuthIdentityUserDomainA(identity, &UserA, &UserLength, &DomainA,
627 if (!sspi_GetAuthIdentityPasswordA(identity, &PasswordA, &PasswordLength))
630 if (UserA && UserLength)
632 *pUser = _strdup(UserA);
638 if (DomainA && DomainLength)
640 *pDomain = _strdup(DomainA);
646 if (PasswordA && PasswordLength)
648 *pPassword = _strdup(PasswordA);
656 else if ((identityFlags & SEC_WINNT_AUTH_IDENTITY_UNICODE) != 0)
658 if (!sspi_GetAuthIdentityUserDomainW(identity, &UserW, &UserLength, &DomainW,
662 if (!sspi_GetAuthIdentityPasswordW(identity, &PasswordW, &PasswordLength))
665 if (UserW && (UserLength > 0))
667 *pUser = ConvertWCharNToUtf8Alloc(UserW, UserLength,
nullptr);
672 if (DomainW && (DomainLength > 0))
674 *pDomain = ConvertWCharNToUtf8Alloc(DomainW, DomainLength,
nullptr);
679 if (PasswordW && (PasswordLength > 0))
681 *pPassword = ConvertWCharNToUtf8Alloc(PasswordW, PasswordLength,
nullptr);
694 WCHAR** pDomain, WCHAR** pPassword)
696 BOOL success = FALSE;
697 const char* UserA =
nullptr;
698 const char* DomainA =
nullptr;
699 const char* PasswordA =
nullptr;
700 const WCHAR* UserW =
nullptr;
701 const WCHAR* DomainW =
nullptr;
702 const WCHAR* PasswordW =
nullptr;
703 UINT32 UserLength = 0;
704 UINT32 DomainLength = 0;
705 UINT32 PasswordLength = 0;
707 if (!identity || !pUser || !pDomain || !pPassword)
710 *pUser = *pDomain = *pPassword =
nullptr;
712 UINT32 identityFlags = sspi_GetAuthIdentityFlags(identity);
714 if ((identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI) != 0)
716 if (!sspi_GetAuthIdentityUserDomainA(identity, &UserA, &UserLength, &DomainA,
720 if (!sspi_GetAuthIdentityPasswordA(identity, &PasswordA, &PasswordLength))
723 if (UserA && (UserLength > 0))
725 WCHAR* ptr = ConvertUtf8NToWCharAlloc(UserA, UserLength,
nullptr);
732 if (DomainA && (DomainLength > 0))
734 WCHAR* ptr = ConvertUtf8NToWCharAlloc(DomainA, DomainLength,
nullptr);
740 if (PasswordA && (PasswordLength > 0))
742 WCHAR* ptr = ConvertUtf8NToWCharAlloc(PasswordA, PasswordLength,
nullptr);
751 else if ((identityFlags & SEC_WINNT_AUTH_IDENTITY_UNICODE) != 0)
753 if (!sspi_GetAuthIdentityUserDomainW(identity, &UserW, &UserLength, &DomainW,
757 if (!sspi_GetAuthIdentityPasswordW(identity, &PasswordW, &PasswordLength))
760 if (UserW && UserLength)
762 *pUser = winpr_wcsndup(UserW, UserLength /
sizeof(WCHAR));
768 if (DomainW && DomainLength)
770 *pDomain = winpr_wcsndup(DomainW, DomainLength /
sizeof(WCHAR));
776 if (PasswordW && PasswordLength)
778 *pPassword = winpr_wcsndup(PasswordW, PasswordLength /
sizeof(WCHAR));
794 UINT32 identityFlags = 0;
795 char* PackageList =
nullptr;
796 const char* PackageListA =
nullptr;
797 const WCHAR* PackageListW =
nullptr;
798 UINT32 PackageListLength = 0;
799 UINT32 PackageListOffset = 0;
800 const void* pAuthData = (
const void*)identity;
805 version = sspi_GetAuthIdentityVersion(pAuthData);
806 identityFlags = sspi_GetAuthIdentityFlags(pAuthData);
808 if ((identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI) != 0)
810 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
813 PackageListA = (
const char*)ad->PackageList;
814 PackageListLength = ad->PackageListLength;
817 if (PackageListA && PackageListLength)
819 PackageList = _strdup(PackageListA);
822 else if ((identityFlags & SEC_WINNT_AUTH_IDENTITY_UNICODE) != 0)
824 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
827 PackageListW = (
const WCHAR*)ad->PackageList;
828 PackageListLength = ad->PackageListLength;
830 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
833 PackageListOffset = ad->PackageListOffset;
834 PackageListW = WINPR_PACKED_ALIGN_CAST(
const WCHAR*,
835 &((
const uint8_t*)pAuthData)[PackageListOffset]);
836 PackageListLength = ad->PackageListLength / 2;
839 if (PackageListW && (PackageListLength > 0))
840 PackageList = ConvertWCharNToUtf8Alloc(PackageListW, PackageListLength,
nullptr);
845 *pPackageList = PackageList;
852int sspi_CopyAuthIdentity(SEC_WINNT_AUTH_IDENTITY* identity,
856 UINT32 identityFlags = 0;
857 const char* UserA =
nullptr;
858 const char* DomainA =
nullptr;
859 const char* PasswordA =
nullptr;
860 const WCHAR* UserW =
nullptr;
861 const WCHAR* DomainW =
nullptr;
862 const WCHAR* PasswordW =
nullptr;
863 UINT32 UserLength = 0;
864 UINT32 DomainLength = 0;
865 UINT32 PasswordLength = 0;
867 sspi_FreeAuthIdentity(identity);
869 identityFlags = sspi_GetAuthIdentityFlags(srcIdentity);
871 identity->Flags = identityFlags;
873 if ((identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI) != 0)
875 if (!sspi_GetAuthIdentityUserDomainA(srcIdentity, &UserA, &UserLength, &DomainA,
881 if (!sspi_GetAuthIdentityPasswordA(srcIdentity, &PasswordA, &PasswordLength))
886 status = sspi_SetAuthIdentity(identity, UserA, DomainA, PasswordA);
891 identity->Flags &= (uint32_t)~SEC_WINNT_AUTH_IDENTITY_ANSI;
892 identity->Flags |= SEC_WINNT_AUTH_IDENTITY_UNICODE;
896 identity->Flags |= SEC_WINNT_AUTH_IDENTITY_UNICODE;
898 if (!sspi_GetAuthIdentityUserDomainW(srcIdentity, &UserW, &UserLength, &DomainW, &DomainLength))
903 if (!sspi_GetAuthIdentityPasswordW(srcIdentity, &PasswordW, &PasswordLength))
909 identity->UserLength = UserLength;
911 if (identity->UserLength > 0)
913 identity->User = (UINT16*)calloc((identity->UserLength + 1),
sizeof(WCHAR));
918 CopyMemory(identity->User, UserW, identity->UserLength *
sizeof(WCHAR));
919 identity->User[identity->UserLength] = 0;
922 identity->DomainLength = DomainLength;
924 if (identity->DomainLength > 0)
926 identity->Domain = (UINT16*)calloc((identity->DomainLength + 1),
sizeof(WCHAR));
928 if (!identity->Domain)
931 CopyMemory(identity->Domain, DomainW, identity->DomainLength *
sizeof(WCHAR));
932 identity->Domain[identity->DomainLength] = 0;
935 identity->PasswordLength = PasswordLength;
939 identity->Password = (UINT16*)calloc((identity->PasswordLength + 1),
sizeof(WCHAR));
941 if (!identity->Password)
944 CopyMemory(identity->Password, PasswordW, identity->PasswordLength *
sizeof(WCHAR));
945 identity->Password[identity->PasswordLength] = 0;
956 for (UINT32 index = 0; index < pMessage->cBuffers; index++)
958 if (pMessage->pBuffers[index].BufferType == BufferType)
960 pSecBuffer = &pMessage->pBuffers[index];
968static BOOL WINPR_init(
void)
971 for (
size_t x = 0; x < ARRAYSIZE(SecurityFunctionTableA_NAME_LIST); x++)
973 const SecurityFunctionTableA_NAME* cur = &SecurityFunctionTableA_NAME_LIST[x];
974 InitializeConstWCharFromUtf8(cur->Name, BUFFER_NAME_LIST_W[x],
975 ARRAYSIZE(BUFFER_NAME_LIST_W[x]));
980static BOOL CALLBACK sspi_init(WINPR_ATTR_UNUSED
PINIT_ONCE InitOnce,
981 WINPR_ATTR_UNUSED PVOID Parameter, WINPR_ATTR_UNUSED PVOID* Context)
983 if (!winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT))
985 sspi_ContextBufferAllocTableNew();
986 if (!SCHANNEL_init())
988 if (!KERBEROS_init())
994 if (!NEGOTIATE_init())
999void sspi_GlobalInit(
void)
1001 static INIT_ONCE once = INIT_ONCE_STATIC_INIT;
1008 WINPR_STATIC_ASSERT(ARRAYSIZE(SecPkgInfoA_LIST) == SSPI_PACKAGE_COUNT - 1);
1009 WINPR_STATIC_ASSERT(ARRAYSIZE(SecPkgInfoW_LIST) == SSPI_PACKAGE_COUNT - 1);
1010 WINPR_STATIC_ASSERT(ARRAYSIZE(SecurityFunctionTableA_NAME_LIST) == SSPI_PACKAGE_COUNT - 1);
1011 WINPR_STATIC_ASSERT(ARRAYSIZE(SecurityFunctionTableW_NAME_LIST) == SSPI_PACKAGE_COUNT - 1);
1012 WINPR_STATIC_ASSERT(ARRAYSIZE(BUFFER_NAME_LIST_W) == SSPI_PACKAGE_COUNT - 1);
1014 if (!InitOnceExecuteOnce(&once, sspi_init, &flags,
nullptr))
1015 WLog_ERR(TAG,
"InitOnceExecuteOnce failed");
1018void sspi_GlobalFinish(
void)
1020 sspi_ContextBufferAllocTableFree();
1025 size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1027 for (
size_t index = 0; index < cPackages; index++)
1029 if (strcmp(Name, SecurityFunctionTableA_NAME_LIST[index].Name) == 0)
1031 return SecurityFunctionTableA_NAME_LIST[index].SecurityFunctionTable;
1040 size_t cPackages = ARRAYSIZE(SecPkgInfoW_LIST);
1042 for (
size_t index = 0; index < cPackages; index++)
1044 if (_wcscmp(Name, SecurityFunctionTableW_NAME_LIST[index].Name) == 0)
1046 return SecurityFunctionTableW_NAME_LIST[index].SecurityFunctionTable;
1057sspi_GetSecurityFunctionTableAByHandle(
SecHandle* handle)
1059 const SSPI_PACKAGE_ID
id = sspi_SecureHandleGetPackageId(handle);
1061 if ((
id < SSPI_PACKAGE_NTLM) || (
id > ARRAYSIZE(SecurityFunctionTableA_NAME_LIST)))
1064 return SecurityFunctionTableA_NAME_LIST[
id - 1].SecurityFunctionTable;
1068sspi_GetSecurityFunctionTableWByHandle(
SecHandle* handle)
1070 const SSPI_PACKAGE_ID
id = sspi_SecureHandleGetPackageId(handle);
1072 if ((
id < SSPI_PACKAGE_NTLM) || (
id > ARRAYSIZE(SecurityFunctionTableW_NAME_LIST)))
1075 return SecurityFunctionTableW_NAME_LIST[
id - 1].SecurityFunctionTable;
1078static void FreeContextBuffer_EnumerateSecurityPackages(
void* contextBuffer);
1079static void FreeContextBuffer_QuerySecurityPackageInfo(
void* contextBuffer);
1081void sspi_ContextBufferFree(
void* contextBuffer)
1083 UINT32 allocatorIndex = 0;
1085 for (
size_t index = 0; index < ContextBufferAllocTable.cMaxEntries; index++)
1087 if (contextBuffer == ContextBufferAllocTable.entries[index].contextBuffer)
1089 contextBuffer = ContextBufferAllocTable.entries[index].contextBuffer;
1090 allocatorIndex = ContextBufferAllocTable.entries[index].allocatorIndex;
1091 ContextBufferAllocTable.cEntries--;
1092 ContextBufferAllocTable.entries[index].allocatorIndex = 0;
1093 ContextBufferAllocTable.entries[index].contextBuffer =
nullptr;
1095 switch (allocatorIndex)
1097 case EnumerateSecurityPackagesIndex:
1098 FreeContextBuffer_EnumerateSecurityPackages(contextBuffer);
1101 case QuerySecurityPackageInfoIndex:
1102 FreeContextBuffer_QuerySecurityPackageInfo(contextBuffer);
1117static SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesW(ULONG* pcPackages,
1120 const size_t cPackages = ARRAYSIZE(SecPkgInfoW_LIST);
1121 const size_t size =
sizeof(
SecPkgInfoW) * cPackages;
1123 (
SecPkgInfoW*)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 = SecPkgInfoW_LIST[index]->fCapabilities;
1133 pPackageInfo[index].wVersion = SecPkgInfoW_LIST[index]->wVersion;
1134 pPackageInfo[index].wRPCID = SecPkgInfoW_LIST[index]->wRPCID;
1135 pPackageInfo[index].cbMaxToken = SecPkgInfoW_LIST[index]->cbMaxToken;
1136 pPackageInfo[index].Name = _wcsdup(SecPkgInfoW_LIST[index]->Name);
1137 pPackageInfo[index].Comment = _wcsdup(SecPkgInfoW_LIST[index]->Comment);
1140 *(pcPackages) = (UINT32)cPackages;
1141 *(ppPackageInfo) = pPackageInfo;
1145static SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesA(ULONG* pcPackages,
1148 const size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1149 const size_t size =
sizeof(
SecPkgInfoA) * cPackages;
1151 (
SecPkgInfoA*)sspi_ContextBufferAlloc(EnumerateSecurityPackagesIndex, size);
1153 WINPR_ASSERT(cPackages <= UINT32_MAX);
1156 return SEC_E_INSUFFICIENT_MEMORY;
1158 for (
size_t index = 0; index < cPackages; index++)
1160 pPackageInfo[index].fCapabilities = SecPkgInfoA_LIST[index]->fCapabilities;
1161 pPackageInfo[index].wVersion = SecPkgInfoA_LIST[index]->wVersion;
1162 pPackageInfo[index].wRPCID = SecPkgInfoA_LIST[index]->wRPCID;
1163 pPackageInfo[index].cbMaxToken = SecPkgInfoA_LIST[index]->cbMaxToken;
1164 pPackageInfo[index].Name = _strdup(SecPkgInfoA_LIST[index]->Name);
1165 pPackageInfo[index].Comment = _strdup(SecPkgInfoA_LIST[index]->Comment);
1167 if (!pPackageInfo[index].Name || !pPackageInfo[index].Comment)
1169 sspi_ContextBufferFree(pPackageInfo);
1170 return SEC_E_INSUFFICIENT_MEMORY;
1174 *(pcPackages) = (UINT32)cPackages;
1175 *(ppPackageInfo) = pPackageInfo;
1179static void FreeContextBuffer_EnumerateSecurityPackages(
void* contextBuffer)
1182 size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1187 for (
size_t index = 0; index < cPackages; index++)
1189 free(pPackageInfo[index].Name);
1190 free(pPackageInfo[index].Comment);
1196static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoW(SEC_WCHAR* pszPackageName,
1199 size_t cPackages = ARRAYSIZE(SecPkgInfoW_LIST);
1201 for (
size_t index = 0; index < cPackages; index++)
1203 if (_wcscmp(pszPackageName, SecPkgInfoW_LIST[index]->Name) == 0)
1207 (
SecPkgInfoW*)sspi_ContextBufferAlloc(QuerySecurityPackageInfoIndex, size);
1210 return SEC_E_INSUFFICIENT_MEMORY;
1212 pPackageInfo->fCapabilities = SecPkgInfoW_LIST[index]->fCapabilities;
1213 pPackageInfo->wVersion = SecPkgInfoW_LIST[index]->wVersion;
1214 pPackageInfo->wRPCID = SecPkgInfoW_LIST[index]->wRPCID;
1215 pPackageInfo->cbMaxToken = SecPkgInfoW_LIST[index]->cbMaxToken;
1216 pPackageInfo->Name = _wcsdup(SecPkgInfoW_LIST[index]->Name);
1217 pPackageInfo->Comment = _wcsdup(SecPkgInfoW_LIST[index]->Comment);
1218 *(ppPackageInfo) = pPackageInfo;
1223 *(ppPackageInfo) =
nullptr;
1224 return SEC_E_SECPKG_NOT_FOUND;
1227static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoA(SEC_CHAR* pszPackageName,
1230 size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1232 for (
size_t index = 0; index < cPackages; index++)
1234 if (strcmp(pszPackageName, SecPkgInfoA_LIST[index]->Name) == 0)
1238 (
SecPkgInfoA*)sspi_ContextBufferAlloc(QuerySecurityPackageInfoIndex, size);
1241 return SEC_E_INSUFFICIENT_MEMORY;
1243 pPackageInfo->fCapabilities = SecPkgInfoA_LIST[index]->fCapabilities;
1244 pPackageInfo->wVersion = SecPkgInfoA_LIST[index]->wVersion;
1245 pPackageInfo->wRPCID = SecPkgInfoA_LIST[index]->wRPCID;
1246 pPackageInfo->cbMaxToken = SecPkgInfoA_LIST[index]->cbMaxToken;
1247 pPackageInfo->Name = _strdup(SecPkgInfoA_LIST[index]->Name);
1248 pPackageInfo->Comment = _strdup(SecPkgInfoA_LIST[index]->Comment);
1250 if (!pPackageInfo->Name || !pPackageInfo->Comment)
1252 sspi_ContextBufferFree(pPackageInfo);
1253 return SEC_E_INSUFFICIENT_MEMORY;
1256 *(ppPackageInfo) = pPackageInfo;
1261 *(ppPackageInfo) =
nullptr;
1262 return SEC_E_SECPKG_NOT_FOUND;
1265void FreeContextBuffer_QuerySecurityPackageInfo(
void* contextBuffer)
1267 SecPkgInfo* pPackageInfo = (SecPkgInfo*)contextBuffer;
1272 free(pPackageInfo->Name);
1273 free(pPackageInfo->Comment);
1277#define log_status(what, status) log_status_((what), (status), __FILE__, __func__, __LINE__)
1278static SECURITY_STATUS log_status_(
const char* what, SECURITY_STATUS status,
const char* file,
1279 const char* fkt,
size_t line)
1281 if (IsSecurityStatusError(status))
1283 const DWORD level = WLOG_WARN;
1284 static wLog* log =
nullptr;
1286 log = WLog_Get(TAG);
1288 if (WLog_IsLevelActive(log, level))
1290 WLog_PrintTextMessage(log, level, line, file, fkt,
"%s status %s [0x%08" PRIx32
"]",
1291 what, GetSecurityStatusString(status),
1292 WINPR_CXX_COMPAT_CAST(uint32_t, status));
1300static SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleW(
1301 SEC_WCHAR* pszPrincipal, SEC_WCHAR* pszPackage, ULONG fCredentialUse,
void* pvLogonID,
1302 void* pAuthData, SEC_GET_KEY_FN pGetKeyFn,
void* pvGetKeyArgument,
PCredHandle phCredential,
1308 return SEC_E_SECPKG_NOT_FOUND;
1310 if (!table->AcquireCredentialsHandleW)
1312 WLog_WARN(TAG,
"Security module does not provide an implementation");
1313 return SEC_E_UNSUPPORTED_FUNCTION;
1316 SECURITY_STATUS status = table->AcquireCredentialsHandleW(
1317 pszPrincipal, pszPackage, fCredentialUse, pvLogonID, pAuthData, pGetKeyFn, pvGetKeyArgument,
1318 phCredential, ptsExpiry);
1319 return log_status(
"AcquireCredentialsHandleW", status);
1322static SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleA(
1323 SEC_CHAR* pszPrincipal, SEC_CHAR* pszPackage, ULONG fCredentialUse,
void* pvLogonID,
1324 void* pAuthData, SEC_GET_KEY_FN pGetKeyFn,
void* pvGetKeyArgument,
PCredHandle phCredential,
1330 return SEC_E_SECPKG_NOT_FOUND;
1332 if (!table->AcquireCredentialsHandleA)
1334 WLog_WARN(TAG,
"Security module does not provide an implementation");
1335 return SEC_E_UNSUPPORTED_FUNCTION;
1338 SECURITY_STATUS status = table->AcquireCredentialsHandleA(
1339 pszPrincipal, pszPackage, fCredentialUse, pvLogonID, pAuthData, pGetKeyFn, pvGetKeyArgument,
1340 phCredential, ptsExpiry);
1341 return log_status(
"AcquireCredentialsHandleA", status);
1344static SECURITY_STATUS SEC_ENTRY winpr_ExportSecurityContext(
PCtxtHandle phContext, ULONG fFlags,
1351 return SEC_E_SECPKG_NOT_FOUND;
1353 if (!table->ExportSecurityContext)
1355 WLog_WARN(TAG,
"Security module does not provide an implementation");
1356 return SEC_E_UNSUPPORTED_FUNCTION;
1359 SECURITY_STATUS status =
1360 table->ExportSecurityContext(phContext, fFlags, pPackedContext, pToken);
1361 return log_status(
"ExportSecurityContext", status);
1364static SECURITY_STATUS SEC_ENTRY winpr_FreeCredentialsHandle(
PCredHandle phCredential)
1369 return SEC_E_SECPKG_NOT_FOUND;
1371 if (!table->FreeCredentialsHandle)
1373 WLog_WARN(TAG,
"Security module does not provide an implementation");
1374 return SEC_E_UNSUPPORTED_FUNCTION;
1377 SECURITY_STATUS status = table->FreeCredentialsHandle(phCredential);
1378 return log_status(
"FreeCredentialsHandle", status);
1381static SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextW(SEC_WCHAR* pszPackage,
1388 return SEC_E_SECPKG_NOT_FOUND;
1390 if (!table->ImportSecurityContextW)
1392 WLog_WARN(TAG,
"Security module does not provide an implementation");
1393 return SEC_E_UNSUPPORTED_FUNCTION;
1396 SECURITY_STATUS status =
1397 table->ImportSecurityContextW(pszPackage, pPackedContext, pToken, phContext);
1398 return log_status(
"ImportSecurityContextW", status);
1401static SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextA(SEC_CHAR* pszPackage,
1408 return SEC_E_SECPKG_NOT_FOUND;
1410 if (!table->ImportSecurityContextA)
1412 WLog_WARN(TAG,
"Security module does not provide an implementation");
1413 return SEC_E_UNSUPPORTED_FUNCTION;
1416 SECURITY_STATUS status =
1417 table->ImportSecurityContextA(pszPackage, pPackedContext, pToken, phContext);
1418 return log_status(
"ImportSecurityContextA", status);
1421static SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesW(
PCredHandle phCredential,
1422 ULONG ulAttribute,
void* pBuffer)
1427 return SEC_E_SECPKG_NOT_FOUND;
1429 if (!table->QueryCredentialsAttributesW)
1431 WLog_WARN(TAG,
"Security module does not provide an implementation");
1432 return SEC_E_UNSUPPORTED_FUNCTION;
1435 SECURITY_STATUS status = table->QueryCredentialsAttributesW(phCredential, ulAttribute, pBuffer);
1436 return log_status(
"QueryCredentialsAttributesW", status);
1439static SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesA(
PCredHandle phCredential,
1440 ULONG ulAttribute,
void* pBuffer)
1445 return SEC_E_SECPKG_NOT_FOUND;
1447 if (!table->QueryCredentialsAttributesA)
1449 WLog_WARN(TAG,
"Security module does not provide an implementation");
1450 return SEC_E_UNSUPPORTED_FUNCTION;
1453 SECURITY_STATUS status = table->QueryCredentialsAttributesA(phCredential, ulAttribute, pBuffer);
1454 return log_status(
"QueryCredentialsAttributesA", status);
1457static SECURITY_STATUS SEC_ENTRY winpr_SetCredentialsAttributesW(
PCredHandle phCredential,
1458 ULONG ulAttribute,
void* pBuffer,
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,
1484 return SEC_E_SECPKG_NOT_FOUND;
1486 if (!table->SetCredentialsAttributesA)
1488 WLog_WARN(TAG,
"Security module does not provide an implementation");
1489 return SEC_E_UNSUPPORTED_FUNCTION;
1492 SECURITY_STATUS status =
1493 table->SetCredentialsAttributesA(phCredential, ulAttribute, pBuffer, cbBuffer);
1494 return log_status(
"SetCredentialsAttributesA", status);
1499static SECURITY_STATUS SEC_ENTRY
1501 ULONG fContextReq, ULONG TargetDataRep,
PCtxtHandle phNewContext,
1507 return SEC_E_SECPKG_NOT_FOUND;
1509 if (!table->AcceptSecurityContext)
1511 WLog_WARN(TAG,
"Security module does not provide an implementation");
1512 return SEC_E_UNSUPPORTED_FUNCTION;
1515 SECURITY_STATUS status =
1516 table->AcceptSecurityContext(phCredential, phContext, pInput, fContextReq, TargetDataRep,
1517 phNewContext, pOutput, pfContextAttr, ptsTimeStamp);
1518 return log_status(
"AcceptSecurityContext", status);
1521static SECURITY_STATUS SEC_ENTRY winpr_ApplyControlToken(
PCtxtHandle phContext,
1527 return SEC_E_SECPKG_NOT_FOUND;
1529 if (!table->ApplyControlToken)
1531 WLog_WARN(TAG,
"Security module does not provide an implementation");
1532 return SEC_E_UNSUPPORTED_FUNCTION;
1535 SECURITY_STATUS status = table->ApplyControlToken(phContext, pInput);
1536 return log_status(
"ApplyControlToken", status);
1539static SECURITY_STATUS SEC_ENTRY winpr_CompleteAuthToken(
PCtxtHandle phContext,
1545 return SEC_E_SECPKG_NOT_FOUND;
1547 if (!table->CompleteAuthToken)
1549 WLog_WARN(TAG,
"Security module does not provide an implementation");
1550 return SEC_E_UNSUPPORTED_FUNCTION;
1553 SECURITY_STATUS status = table->CompleteAuthToken(phContext, pToken);
1554 return log_status(
"CompleteAuthToken", status);
1557static SECURITY_STATUS SEC_ENTRY winpr_DeleteSecurityContext(
PCtxtHandle phContext)
1562 return SEC_E_SECPKG_NOT_FOUND;
1564 if (!table->DeleteSecurityContext)
1566 WLog_WARN(TAG,
"Security module does not provide an implementation");
1567 return SEC_E_UNSUPPORTED_FUNCTION;
1570 const SECURITY_STATUS status = table->DeleteSecurityContext(phContext);
1571 return log_status(
"DeleteSecurityContext", status);
1574static SECURITY_STATUS SEC_ENTRY winpr_FreeContextBuffer(
void* pvContextBuffer)
1576 if (!pvContextBuffer)
1577 return SEC_E_INVALID_HANDLE;
1579 sspi_ContextBufferFree(pvContextBuffer);
1583static SECURITY_STATUS SEC_ENTRY winpr_ImpersonateSecurityContext(
PCtxtHandle phContext)
1588 return SEC_E_SECPKG_NOT_FOUND;
1590 if (!table->ImpersonateSecurityContext)
1592 WLog_WARN(TAG,
"Security module does not provide an implementation");
1593 return SEC_E_UNSUPPORTED_FUNCTION;
1596 SECURITY_STATUS status = table->ImpersonateSecurityContext(phContext);
1597 return log_status(
"ImpersonateSecurityContext", status);
1600static SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextW(
1602 ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2,
1608 return SEC_E_SECPKG_NOT_FOUND;
1610 if (!table->InitializeSecurityContextW)
1612 WLog_WARN(TAG,
"Security module does not provide an implementation");
1613 return SEC_E_UNSUPPORTED_FUNCTION;
1616 const SECURITY_STATUS status = table->InitializeSecurityContextW(
1617 phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput,
1618 Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry);
1619 return log_status(
"InitializeSecurityContextW", status);
1622static SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextA(
1624 ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2,
1630 return SEC_E_SECPKG_NOT_FOUND;
1632 if (!table->InitializeSecurityContextA)
1634 WLog_WARN(TAG,
"Security module does not provide an implementation");
1635 return SEC_E_UNSUPPORTED_FUNCTION;
1638 SECURITY_STATUS status = table->InitializeSecurityContextA(
1639 phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput,
1640 Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry);
1642 return log_status(
"InitializeSecurityContextA", status);
1645static SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesW(
PCtxtHandle phContext,
1646 ULONG ulAttribute,
void* pBuffer)
1651 return SEC_E_SECPKG_NOT_FOUND;
1653 if (!table->QueryContextAttributesW)
1655 WLog_WARN(TAG,
"Security module does not provide an implementation");
1656 return SEC_E_UNSUPPORTED_FUNCTION;
1659 SECURITY_STATUS status = table->QueryContextAttributesW(phContext, ulAttribute, pBuffer);
1660 return log_status(
"QueryContextAttributesW", status);
1663static SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesA(
PCtxtHandle phContext,
1664 ULONG ulAttribute,
void* pBuffer)
1669 return SEC_E_SECPKG_NOT_FOUND;
1671 if (!table->QueryContextAttributesA)
1673 WLog_WARN(TAG,
"Security module does not provide an implementation");
1674 return SEC_E_UNSUPPORTED_FUNCTION;
1677 SECURITY_STATUS status = table->QueryContextAttributesA(phContext, ulAttribute, pBuffer);
1678 return log_status(
"QueryContextAttributesA", status);
1681static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityContextToken(
PCtxtHandle phContext,
1687 return SEC_E_SECPKG_NOT_FOUND;
1689 if (!table->QuerySecurityContextToken)
1691 WLog_WARN(TAG,
"Security module does not provide an implementation");
1692 return SEC_E_UNSUPPORTED_FUNCTION;
1695 SECURITY_STATUS status = table->QuerySecurityContextToken(phContext, phToken);
1696 return log_status(
"QuerySecurityContextToken", status);
1699static SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesW(
PCtxtHandle phContext,
1700 ULONG ulAttribute,
void* pBuffer,
1706 return SEC_E_SECPKG_NOT_FOUND;
1708 if (!table->SetContextAttributesW)
1710 WLog_WARN(TAG,
"Security module does not provide an implementation");
1711 return SEC_E_UNSUPPORTED_FUNCTION;
1714 SECURITY_STATUS status =
1715 table->SetContextAttributesW(phContext, ulAttribute, pBuffer, cbBuffer);
1716 return log_status(
"SetContextAttributesW", status);
1719static SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesA(
PCtxtHandle phContext,
1720 ULONG ulAttribute,
void* pBuffer,
1726 return SEC_E_SECPKG_NOT_FOUND;
1728 if (!table->SetContextAttributesA)
1730 WLog_WARN(TAG,
"Security module does not provide an implementation");
1731 return SEC_E_UNSUPPORTED_FUNCTION;
1734 SECURITY_STATUS status =
1735 table->SetContextAttributesA(phContext, ulAttribute, pBuffer, cbBuffer);
1736 return log_status(
"SetContextAttributesA", status);
1739static SECURITY_STATUS SEC_ENTRY winpr_RevertSecurityContext(
PCtxtHandle phContext)
1744 return SEC_E_SECPKG_NOT_FOUND;
1746 if (!table->RevertSecurityContext)
1748 WLog_WARN(TAG,
"Security module does not provide an implementation");
1749 return SEC_E_UNSUPPORTED_FUNCTION;
1752 SECURITY_STATUS status = table->RevertSecurityContext(phContext);
1754 return log_status(
"RevertSecurityContext", status);
1759static SECURITY_STATUS SEC_ENTRY winpr_DecryptMessage(
PCtxtHandle phContext,
1766 return SEC_E_SECPKG_NOT_FOUND;
1768 if (!table->DecryptMessage)
1770 WLog_WARN(TAG,
"Security module does not provide an implementation");
1771 return SEC_E_UNSUPPORTED_FUNCTION;
1774 const SECURITY_STATUS status = table->DecryptMessage(phContext, pMessage, MessageSeqNo, pfQOP);
1776 return log_status(
"DecryptMessage", status);
1779static SECURITY_STATUS SEC_ENTRY winpr_EncryptMessage(
PCtxtHandle phContext, ULONG fQOP,
1785 return SEC_E_SECPKG_NOT_FOUND;
1787 if (!table->EncryptMessage)
1789 WLog_WARN(TAG,
"Security module does not provide an implementation");
1790 return SEC_E_UNSUPPORTED_FUNCTION;
1793 const SECURITY_STATUS status = table->EncryptMessage(phContext, fQOP, pMessage, MessageSeqNo);
1794 return log_status(
"EncryptMessage", status);
1797static SECURITY_STATUS SEC_ENTRY winpr_MakeSignature(
PCtxtHandle phContext, ULONG fQOP,
1803 return SEC_E_SECPKG_NOT_FOUND;
1805 if (!table->MakeSignature)
1807 WLog_WARN(TAG,
"Security module does not provide an implementation");
1808 return SEC_E_UNSUPPORTED_FUNCTION;
1811 const SECURITY_STATUS status = table->MakeSignature(phContext, fQOP, pMessage, MessageSeqNo);
1812 return log_status(
"MakeSignature", status);
1815static SECURITY_STATUS SEC_ENTRY winpr_VerifySignature(
PCtxtHandle phContext,
1822 return SEC_E_SECPKG_NOT_FOUND;
1824 if (!table->VerifySignature)
1826 WLog_WARN(TAG,
"Security module does not provide an implementation");
1827 return SEC_E_UNSUPPORTED_FUNCTION;
1830 SECURITY_STATUS status = table->VerifySignature(phContext, pMessage, MessageSeqNo, pfQOP);
1832 return log_status(
"VerifySignature", status);
1837 winpr_EnumerateSecurityPackagesA,
1838 winpr_QueryCredentialsAttributesA,
1839 winpr_AcquireCredentialsHandleA,
1840 winpr_FreeCredentialsHandle,
1842 winpr_InitializeSecurityContextA,
1843 winpr_AcceptSecurityContext,
1844 winpr_CompleteAuthToken,
1845 winpr_DeleteSecurityContext,
1846 winpr_ApplyControlToken,
1847 winpr_QueryContextAttributesA,
1848 winpr_ImpersonateSecurityContext,
1849 winpr_RevertSecurityContext,
1850 winpr_MakeSignature,
1851 winpr_VerifySignature,
1852 winpr_FreeContextBuffer,
1853 winpr_QuerySecurityPackageInfoA,
1856 winpr_ExportSecurityContext,
1857 winpr_ImportSecurityContextA,
1860 winpr_QuerySecurityContextToken,
1861 winpr_EncryptMessage,
1862 winpr_DecryptMessage,
1863 winpr_SetContextAttributesA,
1864 winpr_SetCredentialsAttributesA,
1869 winpr_EnumerateSecurityPackagesW,
1870 winpr_QueryCredentialsAttributesW,
1871 winpr_AcquireCredentialsHandleW,
1872 winpr_FreeCredentialsHandle,
1874 winpr_InitializeSecurityContextW,
1875 winpr_AcceptSecurityContext,
1876 winpr_CompleteAuthToken,
1877 winpr_DeleteSecurityContext,
1878 winpr_ApplyControlToken,
1879 winpr_QueryContextAttributesW,
1880 winpr_ImpersonateSecurityContext,
1881 winpr_RevertSecurityContext,
1882 winpr_MakeSignature,
1883 winpr_VerifySignature,
1884 winpr_FreeContextBuffer,
1885 winpr_QuerySecurityPackageInfoW,
1888 winpr_ExportSecurityContext,
1889 winpr_ImportSecurityContextW,
1892 winpr_QuerySecurityContextToken,
1893 winpr_EncryptMessage,
1894 winpr_DecryptMessage,
1895 winpr_SetContextAttributesW,
1896 winpr_SetCredentialsAttributesW,
1901 return &winpr_SecurityFunctionTableW;
1906 return &winpr_SecurityFunctionTableA;
1909SEC_WINPR_NTLM_SETTINGS_V2* sspi_CloneSecNtlmSettings(
const SEC_WINPR_NTLM_SETTINGS_V2* other)
1914 const size_t size =
sizeof(SEC_WINPR_NTLM_SETTINGS_V2);
1915 if (other->size < size)
1918 "Invalid SEC_WINPR_NTLM_SETTINGS_V2 parameter passed, must be of size >= "
1924 SEC_WINPR_NTLM_SETTINGS_V2* clone = sspi_AllocSecNtlmSettings();
1930 if (!sspi_CloneSecSettingsString(&clone->samFile, other->samFile))
1933 clone->hashCallback = other->hashCallback;
1934 clone->hashCallbackArg = other->hashCallbackArg;
1935 if (other->targetName)
1937 if (!sspi_CloneSecSettingsString(&clone->targetName, other->targetName))
1940 if (other->netBiosComputerName)
1942 if (!sspi_CloneSecSettingsString(&clone->netBiosComputerName, other->netBiosComputerName))
1945 if (other->netBiosDomainName)
1947 if (!sspi_CloneSecSettingsString(&clone->netBiosDomainName, other->netBiosDomainName))
1950 if (other->dnsComputerName)
1952 if (!sspi_CloneSecSettingsString(&clone->dnsComputerName, other->dnsComputerName))
1955 if (other->dnsDomainName)
1957 if (!sspi_CloneSecSettingsString(&clone->dnsDomainName, other->dnsDomainName))
1964 sspi_FreeSecNtlmSettings(clone);