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))
387static void zfree(WCHAR* str,
size_t len)
390 memset(str, 0, len *
sizeof(WCHAR));
394int sspi_SetAuthIdentityA(SEC_WINNT_AUTH_IDENTITY* identity,
const char* user,
const char* domain,
395 const char* password)
398 size_t unicodeUserLenW = 0;
399 size_t unicodeDomainLenW = 0;
400 size_t unicodePasswordLenW = 0;
401 LPWSTR unicodeUser =
nullptr;
402 LPWSTR unicodeDomain =
nullptr;
403 LPWSTR unicodePassword =
nullptr;
406 unicodeUser = ConvertUtf8ToWCharAlloc(user, &unicodeUserLenW);
409 unicodeDomain = ConvertUtf8ToWCharAlloc(domain, &unicodeDomainLenW);
412 unicodePassword = ConvertUtf8ToWCharAlloc(password, &unicodePasswordLenW);
414 rc = sspi_SetAuthIdentityWithLengthW(identity, unicodeUser, unicodeUserLenW, unicodeDomain,
415 unicodeDomainLenW, unicodePassword, unicodePasswordLenW);
417 zfree(unicodeUser, unicodeUserLenW);
418 zfree(unicodeDomain, unicodeDomainLenW);
419 zfree(unicodePassword, unicodePasswordLenW);
423UINT32 sspi_GetAuthIdentityVersion(
const void* identity)
430 version = *((
const UINT32*)identity);
432 if ((version == SEC_WINNT_AUTH_IDENTITY_VERSION) ||
433 (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2))
441UINT32 sspi_GetAuthIdentityFlags(
const void* identity)
449 version = sspi_GetAuthIdentityVersion(identity);
451 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
453 flags = ((
const SEC_WINNT_AUTH_IDENTITY_EX*)identity)->Flags;
455 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
461 flags = ((
const SEC_WINNT_AUTH_IDENTITY*)identity)->Flags;
467BOOL sspi_GetAuthIdentityUserDomainW(
const void* identity,
const WCHAR** pUser, UINT32* pUserLength,
468 const WCHAR** pDomain, UINT32* pDomainLength)
475 version = sspi_GetAuthIdentityVersion(identity);
477 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
480 *pUser = (
const WCHAR*)id->User;
481 *pUserLength =
id->UserLength;
482 *pDomain = (
const WCHAR*)id->Domain;
483 *pDomainLength =
id->DomainLength;
485 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
488 UINT32 UserOffset =
id->UserOffset;
489 UINT32 DomainOffset =
id->DomainOffset;
490 *pUser = (
const WCHAR*)&((
const uint8_t*)identity)[UserOffset];
491 *pUserLength =
id->UserLength / 2;
492 *pDomain = (
const WCHAR*)&((
const uint8_t*)identity)[DomainOffset];
493 *pDomainLength =
id->DomainLength / 2;
498 *pUser = (
const WCHAR*)id->User;
499 *pUserLength =
id->UserLength;
500 *pDomain = (
const WCHAR*)id->Domain;
501 *pDomainLength =
id->DomainLength;
507BOOL sspi_GetAuthIdentityUserDomainA(
const void* identity,
const char** pUser, UINT32* pUserLength,
508 const char** pDomain, UINT32* pDomainLength)
515 version = sspi_GetAuthIdentityVersion(identity);
517 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
520 *pUser = (
const char*)id->User;
521 *pUserLength =
id->UserLength;
522 *pDomain = (
const char*)id->Domain;
523 *pDomainLength =
id->DomainLength;
525 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
528 UINT32 UserOffset =
id->UserOffset;
529 UINT32 DomainOffset =
id->DomainOffset;
530 *pUser = (
const char*)&((
const uint8_t*)identity)[UserOffset];
531 *pUserLength =
id->UserLength;
532 *pDomain = (
const char*)&((
const uint8_t*)identity)[DomainOffset];
533 *pDomainLength =
id->DomainLength;
538 *pUser = (
const char*)id->User;
539 *pUserLength =
id->UserLength;
540 *pDomain = (
const char*)id->Domain;
541 *pDomainLength =
id->DomainLength;
547BOOL sspi_GetAuthIdentityPasswordW(
const void* identity,
const WCHAR** pPassword,
548 UINT32* pPasswordLength)
555 version = sspi_GetAuthIdentityVersion(identity);
557 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
560 *pPassword = (
const WCHAR*)id->Password;
561 *pPasswordLength =
id->PasswordLength;
563 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
570 *pPassword = (
const WCHAR*)id->Password;
571 *pPasswordLength =
id->PasswordLength;
577BOOL sspi_GetAuthIdentityPasswordA(
const void* identity,
const char** pPassword,
578 UINT32* pPasswordLength)
585 version = sspi_GetAuthIdentityVersion(identity);
587 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
590 *pPassword = (
const char*)id->Password;
591 *pPasswordLength =
id->PasswordLength;
593 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
600 *pPassword = (
const char*)id->Password;
601 *pPasswordLength =
id->PasswordLength;
608 char** pDomain,
char** pPassword)
610 BOOL success = FALSE;
611 const char* UserA =
nullptr;
612 const char* DomainA =
nullptr;
613 const char* PasswordA =
nullptr;
614 const WCHAR* UserW =
nullptr;
615 const WCHAR* DomainW =
nullptr;
616 const WCHAR* PasswordW =
nullptr;
617 UINT32 UserLength = 0;
618 UINT32 DomainLength = 0;
619 UINT32 PasswordLength = 0;
621 if (!identity || !pUser || !pDomain || !pPassword)
624 *pUser = *pDomain = *pPassword =
nullptr;
626 UINT32 identityFlags = sspi_GetAuthIdentityFlags(identity);
628 if ((identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI) != 0)
630 if (!sspi_GetAuthIdentityUserDomainA(identity, &UserA, &UserLength, &DomainA,
634 if (!sspi_GetAuthIdentityPasswordA(identity, &PasswordA, &PasswordLength))
637 if (UserA && UserLength)
639 *pUser = _strdup(UserA);
645 if (DomainA && DomainLength)
647 *pDomain = _strdup(DomainA);
653 if (PasswordA && PasswordLength)
655 *pPassword = _strdup(PasswordA);
663 else if ((identityFlags & SEC_WINNT_AUTH_IDENTITY_UNICODE) != 0)
665 if (!sspi_GetAuthIdentityUserDomainW(identity, &UserW, &UserLength, &DomainW,
669 if (!sspi_GetAuthIdentityPasswordW(identity, &PasswordW, &PasswordLength))
672 if (UserW && (UserLength > 0))
674 *pUser = ConvertWCharNToUtf8Alloc(UserW, UserLength,
nullptr);
679 if (DomainW && (DomainLength > 0))
681 *pDomain = ConvertWCharNToUtf8Alloc(DomainW, DomainLength,
nullptr);
686 if (PasswordW && (PasswordLength > 0))
688 *pPassword = ConvertWCharNToUtf8Alloc(PasswordW, PasswordLength,
nullptr);
701 WCHAR** pDomain, WCHAR** pPassword)
703 BOOL success = FALSE;
704 const char* UserA =
nullptr;
705 const char* DomainA =
nullptr;
706 const char* PasswordA =
nullptr;
707 const WCHAR* UserW =
nullptr;
708 const WCHAR* DomainW =
nullptr;
709 const WCHAR* PasswordW =
nullptr;
710 UINT32 UserLength = 0;
711 UINT32 DomainLength = 0;
712 UINT32 PasswordLength = 0;
714 if (!identity || !pUser || !pDomain || !pPassword)
717 *pUser = *pDomain = *pPassword =
nullptr;
719 UINT32 identityFlags = sspi_GetAuthIdentityFlags(identity);
721 if ((identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI) != 0)
723 if (!sspi_GetAuthIdentityUserDomainA(identity, &UserA, &UserLength, &DomainA,
727 if (!sspi_GetAuthIdentityPasswordA(identity, &PasswordA, &PasswordLength))
730 if (UserA && (UserLength > 0))
732 WCHAR* ptr = ConvertUtf8NToWCharAlloc(UserA, UserLength,
nullptr);
739 if (DomainA && (DomainLength > 0))
741 WCHAR* ptr = ConvertUtf8NToWCharAlloc(DomainA, DomainLength,
nullptr);
747 if (PasswordA && (PasswordLength > 0))
749 WCHAR* ptr = ConvertUtf8NToWCharAlloc(PasswordA, PasswordLength,
nullptr);
758 else if ((identityFlags & SEC_WINNT_AUTH_IDENTITY_UNICODE) != 0)
760 if (!sspi_GetAuthIdentityUserDomainW(identity, &UserW, &UserLength, &DomainW,
764 if (!sspi_GetAuthIdentityPasswordW(identity, &PasswordW, &PasswordLength))
767 if (UserW && UserLength)
769 *pUser = winpr_wcsndup(UserW, UserLength /
sizeof(WCHAR));
775 if (DomainW && DomainLength)
777 *pDomain = winpr_wcsndup(DomainW, DomainLength /
sizeof(WCHAR));
783 if (PasswordW && PasswordLength)
785 *pPassword = winpr_wcsndup(PasswordW, PasswordLength /
sizeof(WCHAR));
801 UINT32 identityFlags = 0;
802 char* PackageList =
nullptr;
803 const char* PackageListA =
nullptr;
804 const WCHAR* PackageListW =
nullptr;
805 UINT32 PackageListLength = 0;
806 UINT32 PackageListOffset = 0;
807 const void* pAuthData = (
const void*)identity;
812 version = sspi_GetAuthIdentityVersion(pAuthData);
813 identityFlags = sspi_GetAuthIdentityFlags(pAuthData);
815 if ((identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI) != 0)
817 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
820 PackageListA = (
const char*)ad->PackageList;
821 PackageListLength = ad->PackageListLength;
824 if (PackageListA && PackageListLength)
826 PackageList = _strdup(PackageListA);
829 else if ((identityFlags & SEC_WINNT_AUTH_IDENTITY_UNICODE) != 0)
831 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
834 PackageListW = (
const WCHAR*)ad->PackageList;
835 PackageListLength = ad->PackageListLength;
837 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
840 PackageListOffset = ad->PackageListOffset;
841 PackageListW = (
const WCHAR*)&((
const uint8_t*)pAuthData)[PackageListOffset];
842 PackageListLength = ad->PackageListLength / 2;
845 if (PackageListW && (PackageListLength > 0))
846 PackageList = ConvertWCharNToUtf8Alloc(PackageListW, PackageListLength,
nullptr);
851 *pPackageList = PackageList;
858int sspi_CopyAuthIdentity(SEC_WINNT_AUTH_IDENTITY* identity,
862 UINT32 identityFlags = 0;
863 const char* UserA =
nullptr;
864 const char* DomainA =
nullptr;
865 const char* PasswordA =
nullptr;
866 const WCHAR* UserW =
nullptr;
867 const WCHAR* DomainW =
nullptr;
868 const WCHAR* PasswordW =
nullptr;
869 UINT32 UserLength = 0;
870 UINT32 DomainLength = 0;
871 UINT32 PasswordLength = 0;
873 sspi_FreeAuthIdentity(identity);
875 identityFlags = sspi_GetAuthIdentityFlags(srcIdentity);
877 identity->Flags = identityFlags;
879 if ((identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI) != 0)
881 if (!sspi_GetAuthIdentityUserDomainA(srcIdentity, &UserA, &UserLength, &DomainA,
887 if (!sspi_GetAuthIdentityPasswordA(srcIdentity, &PasswordA, &PasswordLength))
892 status = sspi_SetAuthIdentity(identity, UserA, DomainA, PasswordA);
897 identity->Flags &= (uint32_t)~SEC_WINNT_AUTH_IDENTITY_ANSI;
898 identity->Flags |= SEC_WINNT_AUTH_IDENTITY_UNICODE;
902 identity->Flags |= SEC_WINNT_AUTH_IDENTITY_UNICODE;
904 if (!sspi_GetAuthIdentityUserDomainW(srcIdentity, &UserW, &UserLength, &DomainW, &DomainLength))
909 if (!sspi_GetAuthIdentityPasswordW(srcIdentity, &PasswordW, &PasswordLength))
915 identity->UserLength = UserLength;
917 if (identity->UserLength > 0)
919 identity->User = (UINT16*)calloc((identity->UserLength + 1),
sizeof(WCHAR));
924 CopyMemory(identity->User, UserW, identity->UserLength *
sizeof(WCHAR));
925 identity->User[identity->UserLength] = 0;
928 identity->DomainLength = DomainLength;
930 if (identity->DomainLength > 0)
932 identity->Domain = (UINT16*)calloc((identity->DomainLength + 1),
sizeof(WCHAR));
934 if (!identity->Domain)
937 CopyMemory(identity->Domain, DomainW, identity->DomainLength *
sizeof(WCHAR));
938 identity->Domain[identity->DomainLength] = 0;
941 identity->PasswordLength = PasswordLength;
945 identity->Password = (UINT16*)calloc((identity->PasswordLength + 1),
sizeof(WCHAR));
947 if (!identity->Password)
950 CopyMemory(identity->Password, PasswordW, identity->PasswordLength *
sizeof(WCHAR));
951 identity->Password[identity->PasswordLength] = 0;
962 for (UINT32 index = 0; index < pMessage->cBuffers; index++)
964 if (pMessage->pBuffers[index].BufferType == BufferType)
966 pSecBuffer = &pMessage->pBuffers[index];
974static BOOL WINPR_init(
void)
977 for (
size_t x = 0; x < ARRAYSIZE(SecurityFunctionTableA_NAME_LIST); x++)
979 const SecurityFunctionTableA_NAME* cur = &SecurityFunctionTableA_NAME_LIST[x];
980 InitializeConstWCharFromUtf8(cur->Name, BUFFER_NAME_LIST_W[x],
981 ARRAYSIZE(BUFFER_NAME_LIST_W[x]));
986static BOOL CALLBACK sspi_init(WINPR_ATTR_UNUSED
PINIT_ONCE InitOnce,
987 WINPR_ATTR_UNUSED PVOID Parameter, WINPR_ATTR_UNUSED PVOID* Context)
989 if (!winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT))
991 sspi_ContextBufferAllocTableNew();
992 if (!SCHANNEL_init())
994 if (!KERBEROS_init())
1000 if (!NEGOTIATE_init())
1002 return WINPR_init();
1005void sspi_GlobalInit(
void)
1007 static INIT_ONCE once = INIT_ONCE_STATIC_INIT;
1014 WINPR_STATIC_ASSERT(ARRAYSIZE(SecPkgInfoA_LIST) == SSPI_PACKAGE_COUNT - 1);
1015 WINPR_STATIC_ASSERT(ARRAYSIZE(SecPkgInfoW_LIST) == SSPI_PACKAGE_COUNT - 1);
1016 WINPR_STATIC_ASSERT(ARRAYSIZE(SecurityFunctionTableA_NAME_LIST) == SSPI_PACKAGE_COUNT - 1);
1017 WINPR_STATIC_ASSERT(ARRAYSIZE(SecurityFunctionTableW_NAME_LIST) == SSPI_PACKAGE_COUNT - 1);
1018 WINPR_STATIC_ASSERT(ARRAYSIZE(BUFFER_NAME_LIST_W) == SSPI_PACKAGE_COUNT - 1);
1020 if (!InitOnceExecuteOnce(&once, sspi_init, &flags,
nullptr))
1021 WLog_ERR(TAG,
"InitOnceExecuteOnce failed");
1024void sspi_GlobalFinish(
void)
1026 sspi_ContextBufferAllocTableFree();
1031 size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1033 for (
size_t index = 0; index < cPackages; index++)
1035 if (strcmp(Name, SecurityFunctionTableA_NAME_LIST[index].Name) == 0)
1037 return SecurityFunctionTableA_NAME_LIST[index].SecurityFunctionTable;
1046 size_t cPackages = ARRAYSIZE(SecPkgInfoW_LIST);
1048 for (
size_t index = 0; index < cPackages; index++)
1050 if (_wcscmp(Name, SecurityFunctionTableW_NAME_LIST[index].Name) == 0)
1052 return SecurityFunctionTableW_NAME_LIST[index].SecurityFunctionTable;
1063sspi_GetSecurityFunctionTableAByHandle(
SecHandle* handle)
1065 const SSPI_PACKAGE_ID
id = sspi_SecureHandleGetPackageId(handle);
1067 if ((
id < SSPI_PACKAGE_NTLM) || (
id > ARRAYSIZE(SecurityFunctionTableA_NAME_LIST)))
1070 return SecurityFunctionTableA_NAME_LIST[
id - 1].SecurityFunctionTable;
1074sspi_GetSecurityFunctionTableWByHandle(
SecHandle* handle)
1076 const SSPI_PACKAGE_ID
id = sspi_SecureHandleGetPackageId(handle);
1078 if ((
id < SSPI_PACKAGE_NTLM) || (
id > ARRAYSIZE(SecurityFunctionTableW_NAME_LIST)))
1081 return SecurityFunctionTableW_NAME_LIST[
id - 1].SecurityFunctionTable;
1084static void FreeContextBuffer_EnumerateSecurityPackages(
void* contextBuffer);
1085static void FreeContextBuffer_QuerySecurityPackageInfo(
void* contextBuffer);
1087void sspi_ContextBufferFree(
void* contextBuffer)
1089 UINT32 allocatorIndex = 0;
1091 for (
size_t index = 0; index < ContextBufferAllocTable.cMaxEntries; index++)
1093 if (contextBuffer == ContextBufferAllocTable.entries[index].contextBuffer)
1095 contextBuffer = ContextBufferAllocTable.entries[index].contextBuffer;
1096 allocatorIndex = ContextBufferAllocTable.entries[index].allocatorIndex;
1097 ContextBufferAllocTable.cEntries--;
1098 ContextBufferAllocTable.entries[index].allocatorIndex = 0;
1099 ContextBufferAllocTable.entries[index].contextBuffer =
nullptr;
1101 switch (allocatorIndex)
1103 case EnumerateSecurityPackagesIndex:
1104 FreeContextBuffer_EnumerateSecurityPackages(contextBuffer);
1107 case QuerySecurityPackageInfoIndex:
1108 FreeContextBuffer_QuerySecurityPackageInfo(contextBuffer);
1123static SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesW(ULONG* pcPackages,
1126 const size_t cPackages = ARRAYSIZE(SecPkgInfoW_LIST);
1127 const size_t size =
sizeof(
SecPkgInfoW) * cPackages;
1129 (
SecPkgInfoW*)sspi_ContextBufferAlloc(EnumerateSecurityPackagesIndex, size);
1131 WINPR_ASSERT(cPackages <= UINT32_MAX);
1134 return SEC_E_INSUFFICIENT_MEMORY;
1136 for (
size_t index = 0; index < cPackages; index++)
1138 pPackageInfo[index].fCapabilities = SecPkgInfoW_LIST[index]->fCapabilities;
1139 pPackageInfo[index].wVersion = SecPkgInfoW_LIST[index]->wVersion;
1140 pPackageInfo[index].wRPCID = SecPkgInfoW_LIST[index]->wRPCID;
1141 pPackageInfo[index].cbMaxToken = SecPkgInfoW_LIST[index]->cbMaxToken;
1142 pPackageInfo[index].Name = _wcsdup(SecPkgInfoW_LIST[index]->Name);
1143 pPackageInfo[index].Comment = _wcsdup(SecPkgInfoW_LIST[index]->Comment);
1146 *(pcPackages) = (UINT32)cPackages;
1147 *(ppPackageInfo) = pPackageInfo;
1151static SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesA(ULONG* pcPackages,
1154 const size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1155 const size_t size =
sizeof(
SecPkgInfoA) * cPackages;
1157 (
SecPkgInfoA*)sspi_ContextBufferAlloc(EnumerateSecurityPackagesIndex, size);
1159 WINPR_ASSERT(cPackages <= UINT32_MAX);
1162 return SEC_E_INSUFFICIENT_MEMORY;
1164 for (
size_t index = 0; index < cPackages; index++)
1166 pPackageInfo[index].fCapabilities = SecPkgInfoA_LIST[index]->fCapabilities;
1167 pPackageInfo[index].wVersion = SecPkgInfoA_LIST[index]->wVersion;
1168 pPackageInfo[index].wRPCID = SecPkgInfoA_LIST[index]->wRPCID;
1169 pPackageInfo[index].cbMaxToken = SecPkgInfoA_LIST[index]->cbMaxToken;
1170 pPackageInfo[index].Name = _strdup(SecPkgInfoA_LIST[index]->Name);
1171 pPackageInfo[index].Comment = _strdup(SecPkgInfoA_LIST[index]->Comment);
1173 if (!pPackageInfo[index].Name || !pPackageInfo[index].Comment)
1175 sspi_ContextBufferFree(pPackageInfo);
1176 return SEC_E_INSUFFICIENT_MEMORY;
1180 *(pcPackages) = (UINT32)cPackages;
1181 *(ppPackageInfo) = pPackageInfo;
1185static void FreeContextBuffer_EnumerateSecurityPackages(
void* contextBuffer)
1188 size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1193 for (
size_t index = 0; index < cPackages; index++)
1195 free(pPackageInfo[index].Name);
1196 free(pPackageInfo[index].Comment);
1202static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoW(SEC_WCHAR* pszPackageName,
1205 size_t cPackages = ARRAYSIZE(SecPkgInfoW_LIST);
1207 for (
size_t index = 0; index < cPackages; index++)
1209 if (_wcscmp(pszPackageName, SecPkgInfoW_LIST[index]->Name) == 0)
1213 (
SecPkgInfoW*)sspi_ContextBufferAlloc(QuerySecurityPackageInfoIndex, size);
1216 return SEC_E_INSUFFICIENT_MEMORY;
1218 pPackageInfo->fCapabilities = SecPkgInfoW_LIST[index]->fCapabilities;
1219 pPackageInfo->wVersion = SecPkgInfoW_LIST[index]->wVersion;
1220 pPackageInfo->wRPCID = SecPkgInfoW_LIST[index]->wRPCID;
1221 pPackageInfo->cbMaxToken = SecPkgInfoW_LIST[index]->cbMaxToken;
1222 pPackageInfo->Name = _wcsdup(SecPkgInfoW_LIST[index]->Name);
1223 pPackageInfo->Comment = _wcsdup(SecPkgInfoW_LIST[index]->Comment);
1224 *(ppPackageInfo) = pPackageInfo;
1229 *(ppPackageInfo) =
nullptr;
1230 return SEC_E_SECPKG_NOT_FOUND;
1233static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoA(SEC_CHAR* pszPackageName,
1236 size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1238 for (
size_t index = 0; index < cPackages; index++)
1240 if (strcmp(pszPackageName, SecPkgInfoA_LIST[index]->Name) == 0)
1244 (
SecPkgInfoA*)sspi_ContextBufferAlloc(QuerySecurityPackageInfoIndex, size);
1247 return SEC_E_INSUFFICIENT_MEMORY;
1249 pPackageInfo->fCapabilities = SecPkgInfoA_LIST[index]->fCapabilities;
1250 pPackageInfo->wVersion = SecPkgInfoA_LIST[index]->wVersion;
1251 pPackageInfo->wRPCID = SecPkgInfoA_LIST[index]->wRPCID;
1252 pPackageInfo->cbMaxToken = SecPkgInfoA_LIST[index]->cbMaxToken;
1253 pPackageInfo->Name = _strdup(SecPkgInfoA_LIST[index]->Name);
1254 pPackageInfo->Comment = _strdup(SecPkgInfoA_LIST[index]->Comment);
1256 if (!pPackageInfo->Name || !pPackageInfo->Comment)
1258 sspi_ContextBufferFree(pPackageInfo);
1259 return SEC_E_INSUFFICIENT_MEMORY;
1262 *(ppPackageInfo) = pPackageInfo;
1267 *(ppPackageInfo) =
nullptr;
1268 return SEC_E_SECPKG_NOT_FOUND;
1271void FreeContextBuffer_QuerySecurityPackageInfo(
void* contextBuffer)
1273 SecPkgInfo* pPackageInfo = (SecPkgInfo*)contextBuffer;
1278 free(pPackageInfo->Name);
1279 free(pPackageInfo->Comment);
1283#define log_status(what, status) log_status_((what), (status), __FILE__, __func__, __LINE__)
1284static SECURITY_STATUS log_status_(
const char* what, SECURITY_STATUS status,
const char* file,
1285 const char* fkt,
size_t line)
1287 if (IsSecurityStatusError(status))
1289 const DWORD level = WLOG_WARN;
1290 static wLog* log =
nullptr;
1292 log = WLog_Get(TAG);
1294 if (WLog_IsLevelActive(log, level))
1296 WLog_PrintTextMessage(log, level, line, file, fkt,
"%s status %s [0x%08" PRIx32
"]",
1297 what, GetSecurityStatusString(status),
1298 WINPR_CXX_COMPAT_CAST(uint32_t, status));
1306static SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleW(
1307 SEC_WCHAR* pszPrincipal, SEC_WCHAR* pszPackage, ULONG fCredentialUse,
void* pvLogonID,
1308 void* pAuthData, SEC_GET_KEY_FN pGetKeyFn,
void* pvGetKeyArgument,
PCredHandle phCredential,
1314 return SEC_E_SECPKG_NOT_FOUND;
1316 if (!table->AcquireCredentialsHandleW)
1318 WLog_WARN(TAG,
"Security module does not provide an implementation");
1319 return SEC_E_UNSUPPORTED_FUNCTION;
1322 SECURITY_STATUS status = table->AcquireCredentialsHandleW(
1323 pszPrincipal, pszPackage, fCredentialUse, pvLogonID, pAuthData, pGetKeyFn, pvGetKeyArgument,
1324 phCredential, ptsExpiry);
1325 return log_status(
"AcquireCredentialsHandleW", status);
1328static SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleA(
1329 SEC_CHAR* pszPrincipal, SEC_CHAR* pszPackage, ULONG fCredentialUse,
void* pvLogonID,
1330 void* pAuthData, SEC_GET_KEY_FN pGetKeyFn,
void* pvGetKeyArgument,
PCredHandle phCredential,
1336 return SEC_E_SECPKG_NOT_FOUND;
1338 if (!table->AcquireCredentialsHandleA)
1340 WLog_WARN(TAG,
"Security module does not provide an implementation");
1341 return SEC_E_UNSUPPORTED_FUNCTION;
1344 SECURITY_STATUS status = table->AcquireCredentialsHandleA(
1345 pszPrincipal, pszPackage, fCredentialUse, pvLogonID, pAuthData, pGetKeyFn, pvGetKeyArgument,
1346 phCredential, ptsExpiry);
1347 return log_status(
"AcquireCredentialsHandleA", status);
1350static SECURITY_STATUS SEC_ENTRY winpr_ExportSecurityContext(
PCtxtHandle phContext, ULONG fFlags,
1357 return SEC_E_SECPKG_NOT_FOUND;
1359 if (!table->ExportSecurityContext)
1361 WLog_WARN(TAG,
"Security module does not provide an implementation");
1362 return SEC_E_UNSUPPORTED_FUNCTION;
1365 SECURITY_STATUS status =
1366 table->ExportSecurityContext(phContext, fFlags, pPackedContext, pToken);
1367 return log_status(
"ExportSecurityContext", status);
1370static SECURITY_STATUS SEC_ENTRY winpr_FreeCredentialsHandle(
PCredHandle phCredential)
1375 return SEC_E_SECPKG_NOT_FOUND;
1377 if (!table->FreeCredentialsHandle)
1379 WLog_WARN(TAG,
"Security module does not provide an implementation");
1380 return SEC_E_UNSUPPORTED_FUNCTION;
1383 SECURITY_STATUS status = table->FreeCredentialsHandle(phCredential);
1384 return log_status(
"FreeCredentialsHandle", status);
1387static SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextW(SEC_WCHAR* pszPackage,
1394 return SEC_E_SECPKG_NOT_FOUND;
1396 if (!table->ImportSecurityContextW)
1398 WLog_WARN(TAG,
"Security module does not provide an implementation");
1399 return SEC_E_UNSUPPORTED_FUNCTION;
1402 SECURITY_STATUS status =
1403 table->ImportSecurityContextW(pszPackage, pPackedContext, pToken, phContext);
1404 return log_status(
"ImportSecurityContextW", status);
1407static SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextA(SEC_CHAR* pszPackage,
1414 return SEC_E_SECPKG_NOT_FOUND;
1416 if (!table->ImportSecurityContextA)
1418 WLog_WARN(TAG,
"Security module does not provide an implementation");
1419 return SEC_E_UNSUPPORTED_FUNCTION;
1422 SECURITY_STATUS status =
1423 table->ImportSecurityContextA(pszPackage, pPackedContext, pToken, phContext);
1424 return log_status(
"ImportSecurityContextA", status);
1427static SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesW(
PCredHandle phCredential,
1428 ULONG ulAttribute,
void* pBuffer)
1433 return SEC_E_SECPKG_NOT_FOUND;
1435 if (!table->QueryCredentialsAttributesW)
1437 WLog_WARN(TAG,
"Security module does not provide an implementation");
1438 return SEC_E_UNSUPPORTED_FUNCTION;
1441 SECURITY_STATUS status = table->QueryCredentialsAttributesW(phCredential, ulAttribute, pBuffer);
1442 return log_status(
"QueryCredentialsAttributesW", status);
1445static SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesA(
PCredHandle phCredential,
1446 ULONG ulAttribute,
void* pBuffer)
1451 return SEC_E_SECPKG_NOT_FOUND;
1453 if (!table->QueryCredentialsAttributesA)
1455 WLog_WARN(TAG,
"Security module does not provide an implementation");
1456 return SEC_E_UNSUPPORTED_FUNCTION;
1459 SECURITY_STATUS status = table->QueryCredentialsAttributesA(phCredential, ulAttribute, pBuffer);
1460 return log_status(
"QueryCredentialsAttributesA", status);
1463static SECURITY_STATUS SEC_ENTRY winpr_SetCredentialsAttributesW(
PCredHandle phCredential,
1464 ULONG ulAttribute,
void* pBuffer,
1470 return SEC_E_SECPKG_NOT_FOUND;
1472 if (!table->SetCredentialsAttributesW)
1474 WLog_WARN(TAG,
"Security module does not provide an implementation");
1475 return SEC_E_UNSUPPORTED_FUNCTION;
1478 SECURITY_STATUS status =
1479 table->SetCredentialsAttributesW(phCredential, ulAttribute, pBuffer, cbBuffer);
1480 return log_status(
"SetCredentialsAttributesW", status);
1483static SECURITY_STATUS SEC_ENTRY winpr_SetCredentialsAttributesA(
PCredHandle phCredential,
1484 ULONG ulAttribute,
void* pBuffer,
1490 return SEC_E_SECPKG_NOT_FOUND;
1492 if (!table->SetCredentialsAttributesA)
1494 WLog_WARN(TAG,
"Security module does not provide an implementation");
1495 return SEC_E_UNSUPPORTED_FUNCTION;
1498 SECURITY_STATUS status =
1499 table->SetCredentialsAttributesA(phCredential, ulAttribute, pBuffer, cbBuffer);
1500 return log_status(
"SetCredentialsAttributesA", status);
1505static SECURITY_STATUS SEC_ENTRY
1507 ULONG fContextReq, ULONG TargetDataRep,
PCtxtHandle phNewContext,
1513 return SEC_E_SECPKG_NOT_FOUND;
1515 if (!table->AcceptSecurityContext)
1517 WLog_WARN(TAG,
"Security module does not provide an implementation");
1518 return SEC_E_UNSUPPORTED_FUNCTION;
1521 SECURITY_STATUS status =
1522 table->AcceptSecurityContext(phCredential, phContext, pInput, fContextReq, TargetDataRep,
1523 phNewContext, pOutput, pfContextAttr, ptsTimeStamp);
1524 return log_status(
"AcceptSecurityContext", status);
1527static SECURITY_STATUS SEC_ENTRY winpr_ApplyControlToken(
PCtxtHandle phContext,
1533 return SEC_E_SECPKG_NOT_FOUND;
1535 if (!table->ApplyControlToken)
1537 WLog_WARN(TAG,
"Security module does not provide an implementation");
1538 return SEC_E_UNSUPPORTED_FUNCTION;
1541 SECURITY_STATUS status = table->ApplyControlToken(phContext, pInput);
1542 return log_status(
"ApplyControlToken", status);
1545static SECURITY_STATUS SEC_ENTRY winpr_CompleteAuthToken(
PCtxtHandle phContext,
1551 return SEC_E_SECPKG_NOT_FOUND;
1553 if (!table->CompleteAuthToken)
1555 WLog_WARN(TAG,
"Security module does not provide an implementation");
1556 return SEC_E_UNSUPPORTED_FUNCTION;
1559 SECURITY_STATUS status = table->CompleteAuthToken(phContext, pToken);
1560 return log_status(
"CompleteAuthToken", status);
1563static SECURITY_STATUS SEC_ENTRY winpr_DeleteSecurityContext(
PCtxtHandle phContext)
1568 return SEC_E_SECPKG_NOT_FOUND;
1570 if (!table->DeleteSecurityContext)
1572 WLog_WARN(TAG,
"Security module does not provide an implementation");
1573 return SEC_E_UNSUPPORTED_FUNCTION;
1576 const SECURITY_STATUS status = table->DeleteSecurityContext(phContext);
1577 return log_status(
"DeleteSecurityContext", status);
1580static SECURITY_STATUS SEC_ENTRY winpr_FreeContextBuffer(
void* pvContextBuffer)
1582 if (!pvContextBuffer)
1583 return SEC_E_INVALID_HANDLE;
1585 sspi_ContextBufferFree(pvContextBuffer);
1589static SECURITY_STATUS SEC_ENTRY winpr_ImpersonateSecurityContext(
PCtxtHandle phContext)
1594 return SEC_E_SECPKG_NOT_FOUND;
1596 if (!table->ImpersonateSecurityContext)
1598 WLog_WARN(TAG,
"Security module does not provide an implementation");
1599 return SEC_E_UNSUPPORTED_FUNCTION;
1602 SECURITY_STATUS status = table->ImpersonateSecurityContext(phContext);
1603 return log_status(
"ImpersonateSecurityContext", status);
1606static SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextW(
1608 ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2,
1614 return SEC_E_SECPKG_NOT_FOUND;
1616 if (!table->InitializeSecurityContextW)
1618 WLog_WARN(TAG,
"Security module does not provide an implementation");
1619 return SEC_E_UNSUPPORTED_FUNCTION;
1622 const SECURITY_STATUS status = table->InitializeSecurityContextW(
1623 phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput,
1624 Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry);
1625 return log_status(
"InitializeSecurityContextW", status);
1628static SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextA(
1630 ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2,
1636 return SEC_E_SECPKG_NOT_FOUND;
1638 if (!table->InitializeSecurityContextA)
1640 WLog_WARN(TAG,
"Security module does not provide an implementation");
1641 return SEC_E_UNSUPPORTED_FUNCTION;
1644 SECURITY_STATUS status = table->InitializeSecurityContextA(
1645 phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput,
1646 Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry);
1648 return log_status(
"InitializeSecurityContextA", status);
1651static SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesW(
PCtxtHandle phContext,
1652 ULONG ulAttribute,
void* pBuffer)
1657 return SEC_E_SECPKG_NOT_FOUND;
1659 if (!table->QueryContextAttributesW)
1661 WLog_WARN(TAG,
"Security module does not provide an implementation");
1662 return SEC_E_UNSUPPORTED_FUNCTION;
1665 SECURITY_STATUS status = table->QueryContextAttributesW(phContext, ulAttribute, pBuffer);
1666 return log_status(
"QueryContextAttributesW", status);
1669static SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesA(
PCtxtHandle phContext,
1670 ULONG ulAttribute,
void* pBuffer)
1675 return SEC_E_SECPKG_NOT_FOUND;
1677 if (!table->QueryContextAttributesA)
1679 WLog_WARN(TAG,
"Security module does not provide an implementation");
1680 return SEC_E_UNSUPPORTED_FUNCTION;
1683 SECURITY_STATUS status = table->QueryContextAttributesA(phContext, ulAttribute, pBuffer);
1684 return log_status(
"QueryContextAttributesA", status);
1687static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityContextToken(
PCtxtHandle phContext,
1693 return SEC_E_SECPKG_NOT_FOUND;
1695 if (!table->QuerySecurityContextToken)
1697 WLog_WARN(TAG,
"Security module does not provide an implementation");
1698 return SEC_E_UNSUPPORTED_FUNCTION;
1701 SECURITY_STATUS status = table->QuerySecurityContextToken(phContext, phToken);
1702 return log_status(
"QuerySecurityContextToken", status);
1705static SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesW(
PCtxtHandle phContext,
1706 ULONG ulAttribute,
void* pBuffer,
1712 return SEC_E_SECPKG_NOT_FOUND;
1714 if (!table->SetContextAttributesW)
1716 WLog_WARN(TAG,
"Security module does not provide an implementation");
1717 return SEC_E_UNSUPPORTED_FUNCTION;
1720 SECURITY_STATUS status =
1721 table->SetContextAttributesW(phContext, ulAttribute, pBuffer, cbBuffer);
1722 return log_status(
"SetContextAttributesW", status);
1725static SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesA(
PCtxtHandle phContext,
1726 ULONG ulAttribute,
void* pBuffer,
1732 return SEC_E_SECPKG_NOT_FOUND;
1734 if (!table->SetContextAttributesA)
1736 WLog_WARN(TAG,
"Security module does not provide an implementation");
1737 return SEC_E_UNSUPPORTED_FUNCTION;
1740 SECURITY_STATUS status =
1741 table->SetContextAttributesA(phContext, ulAttribute, pBuffer, cbBuffer);
1742 return log_status(
"SetContextAttributesA", status);
1745static SECURITY_STATUS SEC_ENTRY winpr_RevertSecurityContext(
PCtxtHandle phContext)
1750 return SEC_E_SECPKG_NOT_FOUND;
1752 if (!table->RevertSecurityContext)
1754 WLog_WARN(TAG,
"Security module does not provide an implementation");
1755 return SEC_E_UNSUPPORTED_FUNCTION;
1758 SECURITY_STATUS status = table->RevertSecurityContext(phContext);
1760 return log_status(
"RevertSecurityContext", status);
1765static SECURITY_STATUS SEC_ENTRY winpr_DecryptMessage(
PCtxtHandle phContext,
1772 return SEC_E_SECPKG_NOT_FOUND;
1774 if (!table->DecryptMessage)
1776 WLog_WARN(TAG,
"Security module does not provide an implementation");
1777 return SEC_E_UNSUPPORTED_FUNCTION;
1780 const SECURITY_STATUS status = table->DecryptMessage(phContext, pMessage, MessageSeqNo, pfQOP);
1782 return log_status(
"DecryptMessage", status);
1785static SECURITY_STATUS SEC_ENTRY winpr_EncryptMessage(
PCtxtHandle phContext, ULONG fQOP,
1791 return SEC_E_SECPKG_NOT_FOUND;
1793 if (!table->EncryptMessage)
1795 WLog_WARN(TAG,
"Security module does not provide an implementation");
1796 return SEC_E_UNSUPPORTED_FUNCTION;
1799 const SECURITY_STATUS status = table->EncryptMessage(phContext, fQOP, pMessage, MessageSeqNo);
1800 return log_status(
"EncryptMessage", status);
1803static SECURITY_STATUS SEC_ENTRY winpr_MakeSignature(
PCtxtHandle phContext, ULONG fQOP,
1809 return SEC_E_SECPKG_NOT_FOUND;
1811 if (!table->MakeSignature)
1813 WLog_WARN(TAG,
"Security module does not provide an implementation");
1814 return SEC_E_UNSUPPORTED_FUNCTION;
1817 const SECURITY_STATUS status = table->MakeSignature(phContext, fQOP, pMessage, MessageSeqNo);
1818 return log_status(
"MakeSignature", status);
1821static SECURITY_STATUS SEC_ENTRY winpr_VerifySignature(
PCtxtHandle phContext,
1828 return SEC_E_SECPKG_NOT_FOUND;
1830 if (!table->VerifySignature)
1832 WLog_WARN(TAG,
"Security module does not provide an implementation");
1833 return SEC_E_UNSUPPORTED_FUNCTION;
1836 SECURITY_STATUS status = table->VerifySignature(phContext, pMessage, MessageSeqNo, pfQOP);
1838 return log_status(
"VerifySignature", status);
1843 winpr_EnumerateSecurityPackagesA,
1844 winpr_QueryCredentialsAttributesA,
1845 winpr_AcquireCredentialsHandleA,
1846 winpr_FreeCredentialsHandle,
1848 winpr_InitializeSecurityContextA,
1849 winpr_AcceptSecurityContext,
1850 winpr_CompleteAuthToken,
1851 winpr_DeleteSecurityContext,
1852 winpr_ApplyControlToken,
1853 winpr_QueryContextAttributesA,
1854 winpr_ImpersonateSecurityContext,
1855 winpr_RevertSecurityContext,
1856 winpr_MakeSignature,
1857 winpr_VerifySignature,
1858 winpr_FreeContextBuffer,
1859 winpr_QuerySecurityPackageInfoA,
1862 winpr_ExportSecurityContext,
1863 winpr_ImportSecurityContextA,
1866 winpr_QuerySecurityContextToken,
1867 winpr_EncryptMessage,
1868 winpr_DecryptMessage,
1869 winpr_SetContextAttributesA,
1870 winpr_SetCredentialsAttributesA,
1875 winpr_EnumerateSecurityPackagesW,
1876 winpr_QueryCredentialsAttributesW,
1877 winpr_AcquireCredentialsHandleW,
1878 winpr_FreeCredentialsHandle,
1880 winpr_InitializeSecurityContextW,
1881 winpr_AcceptSecurityContext,
1882 winpr_CompleteAuthToken,
1883 winpr_DeleteSecurityContext,
1884 winpr_ApplyControlToken,
1885 winpr_QueryContextAttributesW,
1886 winpr_ImpersonateSecurityContext,
1887 winpr_RevertSecurityContext,
1888 winpr_MakeSignature,
1889 winpr_VerifySignature,
1890 winpr_FreeContextBuffer,
1891 winpr_QuerySecurityPackageInfoW,
1894 winpr_ExportSecurityContext,
1895 winpr_ImportSecurityContextW,
1898 winpr_QuerySecurityContextToken,
1899 winpr_EncryptMessage,
1900 winpr_DecryptMessage,
1901 winpr_SetContextAttributesW,
1902 winpr_SetCredentialsAttributesW,
1907 return &winpr_SecurityFunctionTableW;
1912 return &winpr_SecurityFunctionTableA;
1915SEC_WINPR_NTLM_SETTINGS_V2* sspi_CloneSecNtlmSettings(
const SEC_WINPR_NTLM_SETTINGS_V2* other)
1920 const size_t size =
sizeof(SEC_WINPR_NTLM_SETTINGS_V2);
1921 if (other->size < size)
1924 "Invalid SEC_WINPR_NTLM_SETTINGS_V2 parameter passed, must be of size >= "
1930 SEC_WINPR_NTLM_SETTINGS_V2* clone = sspi_AllocSecNtlmSettings();
1936 if (!sspi_CloneSecSettingsString(&clone->samFile, other->samFile))
1939 clone->hashCallback = other->hashCallback;
1940 clone->hashCallbackArg = other->hashCallbackArg;
1941 if (other->targetName)
1943 if (!sspi_CloneSecSettingsString(&clone->targetName, other->targetName))
1946 if (other->netBiosComputerName)
1948 if (!sspi_CloneSecSettingsString(&clone->netBiosComputerName, other->netBiosComputerName))
1951 if (other->netBiosDomainName)
1953 if (!sspi_CloneSecSettingsString(&clone->netBiosDomainName, other->netBiosDomainName))
1956 if (other->dnsComputerName)
1958 if (!sspi_CloneSecSettingsString(&clone->dnsComputerName, other->dnsComputerName))
1961 if (other->dnsDomainName)
1963 if (!sspi_CloneSecSettingsString(&clone->dnsDomainName, other->dnsDomainName))
1970 sspi_FreeSecNtlmSettings(clone);