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 };
61} SecurityFunctionTableA_NAME;
65 const SEC_WCHAR* Name;
67} SecurityFunctionTableW_NAME;
69static const SecurityFunctionTableA_NAME SecurityFunctionTableA_NAME_LIST[] = {
70 {
"NTLM", &NTLM_SecurityFunctionTableA },
71 {
"Kerberos", &KERBEROS_SecurityFunctionTableA },
72 {
"Negotiate", &NEGOTIATE_SecurityFunctionTableA },
73 {
"CREDSSP", &CREDSSP_SecurityFunctionTableA },
74 {
"Schannel", &SCHANNEL_SecurityFunctionTableA }
77static WCHAR BUFFER_NAME_LIST_W[5][32] = { 0 };
79static const SecurityFunctionTableW_NAME SecurityFunctionTableW_NAME_LIST[] = {
80 { BUFFER_NAME_LIST_W[0], &NTLM_SecurityFunctionTableW },
81 { BUFFER_NAME_LIST_W[1], &KERBEROS_SecurityFunctionTableW },
82 { BUFFER_NAME_LIST_W[2], &NEGOTIATE_SecurityFunctionTableW },
83 { BUFFER_NAME_LIST_W[3], &CREDSSP_SecurityFunctionTableW },
84 { BUFFER_NAME_LIST_W[4], &SCHANNEL_SecurityFunctionTableW }
90 UINT32 allocatorIndex;
91} CONTEXT_BUFFER_ALLOC_ENTRY;
97 CONTEXT_BUFFER_ALLOC_ENTRY* entries;
98} CONTEXT_BUFFER_ALLOC_TABLE;
100static CONTEXT_BUFFER_ALLOC_TABLE ContextBufferAllocTable = { 0 };
102static int sspi_ContextBufferAllocTableNew(
void)
105 ContextBufferAllocTable.entries = NULL;
106 ContextBufferAllocTable.cEntries = 0;
107 ContextBufferAllocTable.cMaxEntries = 4;
108 size =
sizeof(CONTEXT_BUFFER_ALLOC_ENTRY) * ContextBufferAllocTable.cMaxEntries;
109 ContextBufferAllocTable.entries = (CONTEXT_BUFFER_ALLOC_ENTRY*)calloc(1, size);
111 if (!ContextBufferAllocTable.entries)
117static int sspi_ContextBufferAllocTableGrow(
void)
120 CONTEXT_BUFFER_ALLOC_ENTRY* entries = NULL;
121 ContextBufferAllocTable.cEntries = 0;
122 ContextBufferAllocTable.cMaxEntries *= 2;
123 size =
sizeof(CONTEXT_BUFFER_ALLOC_ENTRY) * ContextBufferAllocTable.cMaxEntries;
128 entries = (CONTEXT_BUFFER_ALLOC_ENTRY*)realloc(ContextBufferAllocTable.entries, size);
132 free(ContextBufferAllocTable.entries);
136 ContextBufferAllocTable.entries = entries;
137 ZeroMemory((
void*)&ContextBufferAllocTable.entries[ContextBufferAllocTable.cMaxEntries / 2],
142static void sspi_ContextBufferAllocTableFree(
void)
144 if (ContextBufferAllocTable.cEntries != 0)
145 WLog_ERR(TAG,
"ContextBufferAllocTable.entries == %" PRIu32,
146 ContextBufferAllocTable.cEntries);
148 ContextBufferAllocTable.cEntries = ContextBufferAllocTable.cMaxEntries = 0;
149 free(ContextBufferAllocTable.entries);
150 ContextBufferAllocTable.entries = NULL;
153static void* sspi_ContextBufferAlloc(UINT32 allocatorIndex,
size_t size)
155 void* contextBuffer = NULL;
157 for (UINT32 index = 0; index < ContextBufferAllocTable.cMaxEntries; index++)
159 if (!ContextBufferAllocTable.entries[index].contextBuffer)
161 contextBuffer = calloc(1, size);
166 ContextBufferAllocTable.cEntries++;
167 ContextBufferAllocTable.entries[index].contextBuffer = contextBuffer;
168 ContextBufferAllocTable.entries[index].allocatorIndex = allocatorIndex;
169 return ContextBufferAllocTable.entries[index].contextBuffer;
175 if (sspi_ContextBufferAllocTableGrow() < 0)
179 return sspi_ContextBufferAlloc(allocatorIndex, size);
191 size_t userLength = 0;
192 size_t domainLength = 0;
193 size_t passwordLength = 0;
198 if (credentials->ntlmSettings.samFile)
199 free(credentials->ntlmSettings.samFile);
201 userLength = credentials->identity.UserLength;
202 domainLength = credentials->identity.DomainLength;
203 passwordLength = credentials->identity.PasswordLength;
205 if (passwordLength > SSPI_CREDENTIALS_HASH_LENGTH_OFFSET)
206 passwordLength -= SSPI_CREDENTIALS_HASH_LENGTH_OFFSET;
208 if (credentials->identity.Flags & SEC_WINNT_AUTH_IDENTITY_UNICODE)
215 if (credentials->identity.User)
216 memset(credentials->identity.User, 0, userLength);
217 if (credentials->identity.Domain)
218 memset(credentials->identity.Domain, 0, domainLength);
219 if (credentials->identity.Password)
220 memset(credentials->identity.Password, 0, passwordLength);
221 free(credentials->identity.User);
222 free(credentials->identity.Domain);
223 free(credentials->identity.Password);
261 SecInvalidateHandle(handle);
265void* sspi_SecureHandleGetLowerPointer(
SecHandle* handle)
267 void* pointer = NULL;
269 if (!handle || !SecIsValidHandle(handle) || !handle->dwLower)
272 pointer = (
void*)~((
size_t)handle->dwLower);
276void sspi_SecureHandleInvalidate(
SecHandle* handle)
285void sspi_SecureHandleSetLowerPointer(
SecHandle* handle,
void* pointer)
290 handle->dwLower = (ULONG_PTR)(~((
size_t)pointer));
293void* sspi_SecureHandleGetUpperPointer(
SecHandle* handle)
295 void* pointer = NULL;
297 if (!handle || !SecIsValidHandle(handle) || !handle->dwUpper)
300 pointer = (
void*)~((
size_t)handle->dwUpper);
304void sspi_SecureHandleSetUpperPointer(
SecHandle* handle,
void* pointer)
309 handle->dwUpper = (ULONG_PTR)(~((
size_t)pointer));
312void sspi_SecureHandleFree(
SecHandle* handle)
317int sspi_SetAuthIdentityW(SEC_WINNT_AUTH_IDENTITY* identity,
const WCHAR* user,
const WCHAR* domain,
318 const WCHAR* password)
320 return sspi_SetAuthIdentityWithLengthW(identity, user, user ? _wcslen(user) : 0, domain,
321 domain ? _wcslen(domain) : 0, password,
322 password ? _wcslen(password) : 0);
325static BOOL copy(WCHAR** dst, ULONG* dstLen,
const WCHAR* what,
size_t len)
328 WINPR_ASSERT(dstLen);
333 if (len > UINT32_MAX)
337 if (!what && (len != 0))
339 if (!what && (len == 0))
342 *dst = calloc(
sizeof(WCHAR), len + 1);
346 memcpy(*dst, what, len *
sizeof(WCHAR));
347 *dstLen = WINPR_ASSERTING_INT_CAST(UINT32, len);
351int sspi_SetAuthIdentityWithLengthW(SEC_WINNT_AUTH_IDENTITY* identity,
const WCHAR* user,
352 size_t userLen,
const WCHAR* domain,
size_t domainLen,
353 const WCHAR* password,
size_t passwordLen)
355 WINPR_ASSERT(identity);
356 sspi_FreeAuthIdentity(identity);
357 identity->Flags &= (uint32_t)~SEC_WINNT_AUTH_IDENTITY_ANSI;
358 identity->Flags |= SEC_WINNT_AUTH_IDENTITY_UNICODE;
360 if (!copy(&identity->User, &identity->UserLength, user, userLen))
363 if (!copy(&identity->Domain, &identity->DomainLength, domain, domainLen))
366 if (!copy(&identity->Password, &identity->PasswordLength, password, passwordLen))
372static void zfree(WCHAR* str,
size_t len)
375 memset(str, 0, len *
sizeof(WCHAR));
379int sspi_SetAuthIdentityA(SEC_WINNT_AUTH_IDENTITY* identity,
const char* user,
const char* domain,
380 const char* password)
383 size_t unicodeUserLenW = 0;
384 size_t unicodeDomainLenW = 0;
385 size_t unicodePasswordLenW = 0;
386 LPWSTR unicodeUser = NULL;
387 LPWSTR unicodeDomain = NULL;
388 LPWSTR unicodePassword = NULL;
391 unicodeUser = ConvertUtf8ToWCharAlloc(user, &unicodeUserLenW);
394 unicodeDomain = ConvertUtf8ToWCharAlloc(domain, &unicodeDomainLenW);
397 unicodePassword = ConvertUtf8ToWCharAlloc(password, &unicodePasswordLenW);
399 rc = sspi_SetAuthIdentityWithLengthW(identity, unicodeUser, unicodeUserLenW, unicodeDomain,
400 unicodeDomainLenW, unicodePassword, unicodePasswordLenW);
402 zfree(unicodeUser, unicodeUserLenW);
403 zfree(unicodeDomain, unicodeDomainLenW);
404 zfree(unicodePassword, unicodePasswordLenW);
408UINT32 sspi_GetAuthIdentityVersion(
const void* identity)
415 version = *((
const UINT32*)identity);
417 if ((version == SEC_WINNT_AUTH_IDENTITY_VERSION) ||
418 (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2))
426UINT32 sspi_GetAuthIdentityFlags(
const void* identity)
434 version = sspi_GetAuthIdentityVersion(identity);
436 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
438 flags = ((
const SEC_WINNT_AUTH_IDENTITY_EX*)identity)->Flags;
440 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
446 flags = ((
const SEC_WINNT_AUTH_IDENTITY*)identity)->Flags;
452BOOL sspi_GetAuthIdentityUserDomainW(
const void* identity,
const WCHAR** pUser, UINT32* pUserLength,
453 const WCHAR** pDomain, UINT32* pDomainLength)
460 version = sspi_GetAuthIdentityVersion(identity);
462 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
465 *pUser = (
const WCHAR*)id->User;
466 *pUserLength =
id->UserLength;
467 *pDomain = (
const WCHAR*)id->Domain;
468 *pDomainLength =
id->DomainLength;
470 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
473 UINT32 UserOffset =
id->UserOffset;
474 UINT32 DomainOffset =
id->DomainOffset;
475 *pUser = (
const WCHAR*)&((
const uint8_t*)identity)[UserOffset];
476 *pUserLength =
id->UserLength / 2;
477 *pDomain = (
const WCHAR*)&((
const uint8_t*)identity)[DomainOffset];
478 *pDomainLength =
id->DomainLength / 2;
483 *pUser = (
const WCHAR*)id->User;
484 *pUserLength =
id->UserLength;
485 *pDomain = (
const WCHAR*)id->Domain;
486 *pDomainLength =
id->DomainLength;
492BOOL sspi_GetAuthIdentityUserDomainA(
const void* identity,
const char** pUser, UINT32* pUserLength,
493 const char** pDomain, UINT32* pDomainLength)
500 version = sspi_GetAuthIdentityVersion(identity);
502 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
505 *pUser = (
const char*)id->User;
506 *pUserLength =
id->UserLength;
507 *pDomain = (
const char*)id->Domain;
508 *pDomainLength =
id->DomainLength;
510 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
513 UINT32 UserOffset =
id->UserOffset;
514 UINT32 DomainOffset =
id->DomainOffset;
515 *pUser = (
const char*)&((
const uint8_t*)identity)[UserOffset];
516 *pUserLength =
id->UserLength;
517 *pDomain = (
const char*)&((
const uint8_t*)identity)[DomainOffset];
518 *pDomainLength =
id->DomainLength;
523 *pUser = (
const char*)id->User;
524 *pUserLength =
id->UserLength;
525 *pDomain = (
const char*)id->Domain;
526 *pDomainLength =
id->DomainLength;
532BOOL sspi_GetAuthIdentityPasswordW(
const void* identity,
const WCHAR** pPassword,
533 UINT32* pPasswordLength)
540 version = sspi_GetAuthIdentityVersion(identity);
542 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
545 *pPassword = (
const WCHAR*)id->Password;
546 *pPasswordLength =
id->PasswordLength;
548 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
555 *pPassword = (
const WCHAR*)id->Password;
556 *pPasswordLength =
id->PasswordLength;
562BOOL sspi_GetAuthIdentityPasswordA(
const void* identity,
const char** pPassword,
563 UINT32* pPasswordLength)
570 version = sspi_GetAuthIdentityVersion(identity);
572 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
575 *pPassword = (
const char*)id->Password;
576 *pPasswordLength =
id->PasswordLength;
578 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
585 *pPassword = (
const char*)id->Password;
586 *pPasswordLength =
id->PasswordLength;
593 char** pDomain,
char** pPassword)
595 BOOL success = FALSE;
596 const char* UserA = NULL;
597 const char* DomainA = NULL;
598 const char* PasswordA = NULL;
599 const WCHAR* UserW = NULL;
600 const WCHAR* DomainW = NULL;
601 const WCHAR* PasswordW = NULL;
602 UINT32 UserLength = 0;
603 UINT32 DomainLength = 0;
604 UINT32 PasswordLength = 0;
606 if (!identity || !pUser || !pDomain || !pPassword)
609 *pUser = *pDomain = *pPassword = NULL;
611 UINT32 identityFlags = sspi_GetAuthIdentityFlags(identity);
613 if (identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI)
615 if (!sspi_GetAuthIdentityUserDomainA(identity, &UserA, &UserLength, &DomainA,
619 if (!sspi_GetAuthIdentityPasswordA(identity, &PasswordA, &PasswordLength))
622 if (UserA && UserLength)
624 *pUser = _strdup(UserA);
630 if (DomainA && DomainLength)
632 *pDomain = _strdup(DomainA);
638 if (PasswordA && PasswordLength)
640 *pPassword = _strdup(PasswordA);
650 if (!sspi_GetAuthIdentityUserDomainW(identity, &UserW, &UserLength, &DomainW,
654 if (!sspi_GetAuthIdentityPasswordW(identity, &PasswordW, &PasswordLength))
657 if (UserW && (UserLength > 0))
659 *pUser = ConvertWCharNToUtf8Alloc(UserW, UserLength, NULL);
664 if (DomainW && (DomainLength > 0))
666 *pDomain = ConvertWCharNToUtf8Alloc(DomainW, DomainLength, NULL);
671 if (PasswordW && (PasswordLength > 0))
673 *pPassword = ConvertWCharNToUtf8Alloc(PasswordW, PasswordLength, NULL);
686 WCHAR** pDomain, WCHAR** pPassword)
688 BOOL success = FALSE;
689 const char* UserA = NULL;
690 const char* DomainA = NULL;
691 const char* PasswordA = NULL;
692 const WCHAR* UserW = NULL;
693 const WCHAR* DomainW = NULL;
694 const WCHAR* PasswordW = NULL;
695 UINT32 UserLength = 0;
696 UINT32 DomainLength = 0;
697 UINT32 PasswordLength = 0;
699 if (!identity || !pUser || !pDomain || !pPassword)
702 *pUser = *pDomain = *pPassword = NULL;
704 UINT32 identityFlags = sspi_GetAuthIdentityFlags(identity);
706 if (identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI)
708 if (!sspi_GetAuthIdentityUserDomainA(identity, &UserA, &UserLength, &DomainA,
712 if (!sspi_GetAuthIdentityPasswordA(identity, &PasswordA, &PasswordLength))
715 if (UserA && (UserLength > 0))
717 WCHAR* ptr = ConvertUtf8NToWCharAlloc(UserA, UserLength, NULL);
724 if (DomainA && (DomainLength > 0))
726 WCHAR* ptr = ConvertUtf8NToWCharAlloc(DomainA, DomainLength, NULL);
732 if (PasswordA && (PasswordLength > 0))
734 WCHAR* ptr = ConvertUtf8NToWCharAlloc(PasswordA, PasswordLength, NULL);
745 if (!sspi_GetAuthIdentityUserDomainW(identity, &UserW, &UserLength, &DomainW,
749 if (!sspi_GetAuthIdentityPasswordW(identity, &PasswordW, &PasswordLength))
752 if (UserW && UserLength)
754 *pUser = _wcsdup(UserW);
760 if (DomainW && DomainLength)
762 *pDomain = _wcsdup(DomainW);
768 if (PasswordW && PasswordLength)
770 *pPassword = _wcsdup(PasswordW);
786 UINT32 identityFlags = 0;
787 char* PackageList = NULL;
788 const char* PackageListA = NULL;
789 const WCHAR* PackageListW = NULL;
790 UINT32 PackageListLength = 0;
791 UINT32 PackageListOffset = 0;
792 const void* pAuthData = (
const void*)identity;
797 version = sspi_GetAuthIdentityVersion(pAuthData);
798 identityFlags = sspi_GetAuthIdentityFlags(pAuthData);
800 if (identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI)
802 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
805 PackageListA = (
const char*)ad->PackageList;
806 PackageListLength = ad->PackageListLength;
809 if (PackageListA && PackageListLength)
811 PackageList = _strdup(PackageListA);
816 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
819 PackageListW = (
const WCHAR*)ad->PackageList;
820 PackageListLength = ad->PackageListLength;
822 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
825 PackageListOffset = ad->PackageListOffset;
826 PackageListW = (
const WCHAR*)&((
const uint8_t*)pAuthData)[PackageListOffset];
827 PackageListLength = ad->PackageListLength / 2;
830 if (PackageListW && (PackageListLength > 0))
831 PackageList = ConvertWCharNToUtf8Alloc(PackageListW, PackageListLength, NULL);
836 *pPackageList = PackageList;
843int sspi_CopyAuthIdentity(SEC_WINNT_AUTH_IDENTITY* identity,
847 UINT32 identityFlags = 0;
848 const char* UserA = NULL;
849 const char* DomainA = NULL;
850 const char* PasswordA = NULL;
851 const WCHAR* UserW = NULL;
852 const WCHAR* DomainW = NULL;
853 const WCHAR* PasswordW = NULL;
854 UINT32 UserLength = 0;
855 UINT32 DomainLength = 0;
856 UINT32 PasswordLength = 0;
858 sspi_FreeAuthIdentity(identity);
860 identityFlags = sspi_GetAuthIdentityFlags(srcIdentity);
862 identity->Flags = identityFlags;
864 if (identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI)
866 if (!sspi_GetAuthIdentityUserDomainA(srcIdentity, &UserA, &UserLength, &DomainA,
872 if (!sspi_GetAuthIdentityPasswordA(srcIdentity, &PasswordA, &PasswordLength))
877 status = sspi_SetAuthIdentity(identity, UserA, DomainA, PasswordA);
882 identity->Flags &= (uint32_t)~SEC_WINNT_AUTH_IDENTITY_ANSI;
883 identity->Flags |= SEC_WINNT_AUTH_IDENTITY_UNICODE;
887 identity->Flags |= SEC_WINNT_AUTH_IDENTITY_UNICODE;
889 if (!sspi_GetAuthIdentityUserDomainW(srcIdentity, &UserW, &UserLength, &DomainW, &DomainLength))
894 if (!sspi_GetAuthIdentityPasswordW(srcIdentity, &PasswordW, &PasswordLength))
900 identity->UserLength = UserLength;
902 if (identity->UserLength > 0)
904 identity->User = (UINT16*)calloc((identity->UserLength + 1),
sizeof(WCHAR));
909 CopyMemory(identity->User, UserW, identity->UserLength *
sizeof(WCHAR));
910 identity->User[identity->UserLength] = 0;
913 identity->DomainLength = DomainLength;
915 if (identity->DomainLength > 0)
917 identity->Domain = (UINT16*)calloc((identity->DomainLength + 1),
sizeof(WCHAR));
919 if (!identity->Domain)
922 CopyMemory(identity->Domain, DomainW, identity->DomainLength *
sizeof(WCHAR));
923 identity->Domain[identity->DomainLength] = 0;
926 identity->PasswordLength = PasswordLength;
928 if (identity->PasswordLength > SSPI_CREDENTIALS_HASH_LENGTH_OFFSET)
929 identity->PasswordLength -= SSPI_CREDENTIALS_HASH_LENGTH_OFFSET;
933 identity->Password = (UINT16*)calloc((identity->PasswordLength + 1),
sizeof(WCHAR));
935 if (!identity->Password)
938 CopyMemory(identity->Password, PasswordW, identity->PasswordLength *
sizeof(WCHAR));
939 identity->Password[identity->PasswordLength] = 0;
942 identity->PasswordLength = PasswordLength;
951 for (UINT32 index = 0; index < pMessage->cBuffers; index++)
953 if (pMessage->pBuffers[index].BufferType == BufferType)
955 pSecBuffer = &pMessage->pBuffers[index];
963static BOOL WINPR_init(
void)
966 for (
size_t x = 0; x < ARRAYSIZE(SecurityFunctionTableA_NAME_LIST); x++)
968 const SecurityFunctionTableA_NAME* cur = &SecurityFunctionTableA_NAME_LIST[x];
969 InitializeConstWCharFromUtf8(cur->Name, BUFFER_NAME_LIST_W[x],
970 ARRAYSIZE(BUFFER_NAME_LIST_W[x]));
975static BOOL CALLBACK sspi_init(WINPR_ATTR_UNUSED
PINIT_ONCE InitOnce,
976 WINPR_ATTR_UNUSED PVOID Parameter, WINPR_ATTR_UNUSED PVOID* Context)
978 winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT);
979 sspi_ContextBufferAllocTableNew();
980 if (!SCHANNEL_init())
982 if (!KERBEROS_init())
988 if (!NEGOTIATE_init())
993void sspi_GlobalInit(
void)
995 static INIT_ONCE once = INIT_ONCE_STATIC_INIT;
997 InitOnceExecuteOnce(&once, sspi_init, &flags, NULL);
1000void sspi_GlobalFinish(
void)
1002 sspi_ContextBufferAllocTableFree();
1007 size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1009 for (
size_t index = 0; index < cPackages; index++)
1011 if (strcmp(Name, SecurityFunctionTableA_NAME_LIST[index].Name) == 0)
1013 return SecurityFunctionTableA_NAME_LIST[index].SecurityFunctionTable;
1022 size_t cPackages = ARRAYSIZE(SecPkgInfoW_LIST);
1024 for (
size_t index = 0; index < cPackages; index++)
1026 if (_wcscmp(Name, SecurityFunctionTableW_NAME_LIST[index].Name) == 0)
1028 return SecurityFunctionTableW_NAME_LIST[index].SecurityFunctionTable;
1037 SEC_WCHAR* NameW = NULL;
1043 NameW = ConvertUtf8ToWCharAlloc(Name, NULL);
1048 table = sspi_GetSecurityFunctionTableWByNameW(NameW);
1053static void FreeContextBuffer_EnumerateSecurityPackages(
void* contextBuffer);
1054static void FreeContextBuffer_QuerySecurityPackageInfo(
void* contextBuffer);
1056static void sspi_ContextBufferFree(
void* contextBuffer)
1058 UINT32 allocatorIndex = 0;
1060 for (
size_t index = 0; index < ContextBufferAllocTable.cMaxEntries; index++)
1062 if (contextBuffer == ContextBufferAllocTable.entries[index].contextBuffer)
1064 contextBuffer = ContextBufferAllocTable.entries[index].contextBuffer;
1065 allocatorIndex = ContextBufferAllocTable.entries[index].allocatorIndex;
1066 ContextBufferAllocTable.cEntries--;
1067 ContextBufferAllocTable.entries[index].allocatorIndex = 0;
1068 ContextBufferAllocTable.entries[index].contextBuffer = NULL;
1070 switch (allocatorIndex)
1072 case EnumerateSecurityPackagesIndex:
1073 FreeContextBuffer_EnumerateSecurityPackages(contextBuffer);
1076 case QuerySecurityPackageInfoIndex:
1077 FreeContextBuffer_QuerySecurityPackageInfo(contextBuffer);
1092static SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesW(ULONG* pcPackages,
1095 const size_t cPackages = ARRAYSIZE(SecPkgInfoW_LIST);
1096 const size_t size =
sizeof(
SecPkgInfoW) * cPackages;
1098 (
SecPkgInfoW*)sspi_ContextBufferAlloc(EnumerateSecurityPackagesIndex, size);
1100 WINPR_ASSERT(cPackages <= UINT32_MAX);
1103 return SEC_E_INSUFFICIENT_MEMORY;
1105 for (
size_t index = 0; index < cPackages; index++)
1107 pPackageInfo[index].fCapabilities = SecPkgInfoW_LIST[index]->fCapabilities;
1108 pPackageInfo[index].wVersion = SecPkgInfoW_LIST[index]->wVersion;
1109 pPackageInfo[index].wRPCID = SecPkgInfoW_LIST[index]->wRPCID;
1110 pPackageInfo[index].cbMaxToken = SecPkgInfoW_LIST[index]->cbMaxToken;
1111 pPackageInfo[index].Name = _wcsdup(SecPkgInfoW_LIST[index]->Name);
1112 pPackageInfo[index].Comment = _wcsdup(SecPkgInfoW_LIST[index]->Comment);
1115 *(pcPackages) = (UINT32)cPackages;
1116 *(ppPackageInfo) = pPackageInfo;
1120static SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesA(ULONG* pcPackages,
1123 const size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1124 const size_t size =
sizeof(
SecPkgInfoA) * cPackages;
1126 (
SecPkgInfoA*)sspi_ContextBufferAlloc(EnumerateSecurityPackagesIndex, size);
1128 WINPR_ASSERT(cPackages <= UINT32_MAX);
1131 return SEC_E_INSUFFICIENT_MEMORY;
1133 for (
size_t index = 0; index < cPackages; index++)
1135 pPackageInfo[index].fCapabilities = SecPkgInfoA_LIST[index]->fCapabilities;
1136 pPackageInfo[index].wVersion = SecPkgInfoA_LIST[index]->wVersion;
1137 pPackageInfo[index].wRPCID = SecPkgInfoA_LIST[index]->wRPCID;
1138 pPackageInfo[index].cbMaxToken = SecPkgInfoA_LIST[index]->cbMaxToken;
1139 pPackageInfo[index].Name = _strdup(SecPkgInfoA_LIST[index]->Name);
1140 pPackageInfo[index].Comment = _strdup(SecPkgInfoA_LIST[index]->Comment);
1142 if (!pPackageInfo[index].Name || !pPackageInfo[index].Comment)
1144 sspi_ContextBufferFree(pPackageInfo);
1145 return SEC_E_INSUFFICIENT_MEMORY;
1149 *(pcPackages) = (UINT32)cPackages;
1150 *(ppPackageInfo) = pPackageInfo;
1154static void FreeContextBuffer_EnumerateSecurityPackages(
void* contextBuffer)
1157 size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1162 for (
size_t index = 0; index < cPackages; index++)
1164 free(pPackageInfo[index].Name);
1165 free(pPackageInfo[index].Comment);
1173 return &winpr_SecurityFunctionTableW;
1178 return &winpr_SecurityFunctionTableA;
1181static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoW(SEC_WCHAR* pszPackageName,
1184 size_t cPackages = ARRAYSIZE(SecPkgInfoW_LIST);
1186 for (
size_t index = 0; index < cPackages; index++)
1188 if (_wcscmp(pszPackageName, SecPkgInfoW_LIST[index]->Name) == 0)
1192 (
SecPkgInfoW*)sspi_ContextBufferAlloc(QuerySecurityPackageInfoIndex, size);
1195 return SEC_E_INSUFFICIENT_MEMORY;
1197 pPackageInfo->fCapabilities = SecPkgInfoW_LIST[index]->fCapabilities;
1198 pPackageInfo->wVersion = SecPkgInfoW_LIST[index]->wVersion;
1199 pPackageInfo->wRPCID = SecPkgInfoW_LIST[index]->wRPCID;
1200 pPackageInfo->cbMaxToken = SecPkgInfoW_LIST[index]->cbMaxToken;
1201 pPackageInfo->Name = _wcsdup(SecPkgInfoW_LIST[index]->Name);
1202 pPackageInfo->Comment = _wcsdup(SecPkgInfoW_LIST[index]->Comment);
1203 *(ppPackageInfo) = pPackageInfo;
1208 *(ppPackageInfo) = NULL;
1209 return SEC_E_SECPKG_NOT_FOUND;
1212static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoA(SEC_CHAR* pszPackageName,
1215 size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1217 for (
size_t index = 0; index < cPackages; index++)
1219 if (strcmp(pszPackageName, SecPkgInfoA_LIST[index]->Name) == 0)
1223 (
SecPkgInfoA*)sspi_ContextBufferAlloc(QuerySecurityPackageInfoIndex, size);
1226 return SEC_E_INSUFFICIENT_MEMORY;
1228 pPackageInfo->fCapabilities = SecPkgInfoA_LIST[index]->fCapabilities;
1229 pPackageInfo->wVersion = SecPkgInfoA_LIST[index]->wVersion;
1230 pPackageInfo->wRPCID = SecPkgInfoA_LIST[index]->wRPCID;
1231 pPackageInfo->cbMaxToken = SecPkgInfoA_LIST[index]->cbMaxToken;
1232 pPackageInfo->Name = _strdup(SecPkgInfoA_LIST[index]->Name);
1233 pPackageInfo->Comment = _strdup(SecPkgInfoA_LIST[index]->Comment);
1235 if (!pPackageInfo->Name || !pPackageInfo->Comment)
1237 sspi_ContextBufferFree(pPackageInfo);
1238 return SEC_E_INSUFFICIENT_MEMORY;
1241 *(ppPackageInfo) = pPackageInfo;
1246 *(ppPackageInfo) = NULL;
1247 return SEC_E_SECPKG_NOT_FOUND;
1250void FreeContextBuffer_QuerySecurityPackageInfo(
void* contextBuffer)
1252 SecPkgInfo* pPackageInfo = (SecPkgInfo*)contextBuffer;
1257 free(pPackageInfo->Name);
1258 free(pPackageInfo->Comment);
1264static SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleW(
1265 SEC_WCHAR* pszPrincipal, SEC_WCHAR* pszPackage, ULONG fCredentialUse,
void* pvLogonID,
1266 void* pAuthData, SEC_GET_KEY_FN pGetKeyFn,
void* pvGetKeyArgument,
PCredHandle phCredential,
1269 SECURITY_STATUS status = 0;
1273 return SEC_E_SECPKG_NOT_FOUND;
1275 if (!table->AcquireCredentialsHandleW)
1277 WLog_WARN(TAG,
"Security module does not provide an implementation");
1278 return SEC_E_UNSUPPORTED_FUNCTION;
1281 status = table->AcquireCredentialsHandleW(pszPrincipal, pszPackage, fCredentialUse, pvLogonID,
1282 pAuthData, pGetKeyFn, pvGetKeyArgument, phCredential,
1285 if (IsSecurityStatusError(status))
1287 WLog_WARN(TAG,
"AcquireCredentialsHandleW status %s [0x%08" PRIX32
"]",
1288 GetSecurityStatusString(status), status);
1294static SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleA(
1295 SEC_CHAR* pszPrincipal, SEC_CHAR* pszPackage, ULONG fCredentialUse,
void* pvLogonID,
1296 void* pAuthData, SEC_GET_KEY_FN pGetKeyFn,
void* pvGetKeyArgument,
PCredHandle phCredential,
1299 SECURITY_STATUS status = 0;
1303 return SEC_E_SECPKG_NOT_FOUND;
1305 if (!table->AcquireCredentialsHandleA)
1307 WLog_WARN(TAG,
"Security module does not provide an implementation");
1308 return SEC_E_UNSUPPORTED_FUNCTION;
1311 status = table->AcquireCredentialsHandleA(pszPrincipal, pszPackage, fCredentialUse, pvLogonID,
1312 pAuthData, pGetKeyFn, pvGetKeyArgument, phCredential,
1315 if (IsSecurityStatusError(status))
1317 WLog_WARN(TAG,
"AcquireCredentialsHandleA status %s [0x%08" PRIX32
"]",
1318 GetSecurityStatusString(status), status);
1324static SECURITY_STATUS SEC_ENTRY winpr_ExportSecurityContext(
PCtxtHandle phContext, ULONG fFlags,
1328 SEC_CHAR* Name = NULL;
1329 SECURITY_STATUS status = 0;
1331 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1334 return SEC_E_SECPKG_NOT_FOUND;
1336 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1339 return SEC_E_SECPKG_NOT_FOUND;
1341 if (!table->ExportSecurityContext)
1343 WLog_WARN(TAG,
"Security module does not provide an implementation");
1344 return SEC_E_UNSUPPORTED_FUNCTION;
1347 status = table->ExportSecurityContext(phContext, fFlags, pPackedContext, pToken);
1349 if (IsSecurityStatusError(status))
1351 WLog_WARN(TAG,
"ExportSecurityContext status %s [0x%08" PRIX32
"]",
1352 GetSecurityStatusString(status), status);
1358static SECURITY_STATUS SEC_ENTRY winpr_FreeCredentialsHandle(
PCredHandle phCredential)
1361 SECURITY_STATUS status = 0;
1363 Name = (
char*)sspi_SecureHandleGetUpperPointer(phCredential);
1366 return SEC_E_SECPKG_NOT_FOUND;
1368 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1371 return SEC_E_SECPKG_NOT_FOUND;
1373 if (!table->FreeCredentialsHandle)
1375 WLog_WARN(TAG,
"Security module does not provide an implementation");
1376 return SEC_E_UNSUPPORTED_FUNCTION;
1379 status = table->FreeCredentialsHandle(phCredential);
1381 if (IsSecurityStatusError(status))
1383 WLog_WARN(TAG,
"FreeCredentialsHandle status %s [0x%08" PRIX32
"]",
1384 GetSecurityStatusString(status), status);
1390static SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextW(SEC_WCHAR* pszPackage,
1394 SEC_CHAR* Name = NULL;
1395 SECURITY_STATUS status = 0;
1397 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1400 return SEC_E_SECPKG_NOT_FOUND;
1402 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1405 return SEC_E_SECPKG_NOT_FOUND;
1407 if (!table->ImportSecurityContextW)
1409 WLog_WARN(TAG,
"Security module does not provide an implementation");
1410 return SEC_E_UNSUPPORTED_FUNCTION;
1413 status = table->ImportSecurityContextW(pszPackage, pPackedContext, pToken, phContext);
1415 if (IsSecurityStatusError(status))
1417 WLog_WARN(TAG,
"ImportSecurityContextW status %s [0x%08" PRIX32
"]",
1418 GetSecurityStatusString(status), status);
1424static SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextA(SEC_CHAR* pszPackage,
1429 SECURITY_STATUS status = 0;
1431 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1434 return SEC_E_SECPKG_NOT_FOUND;
1436 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1439 return SEC_E_SECPKG_NOT_FOUND;
1441 if (!table->ImportSecurityContextA)
1443 WLog_WARN(TAG,
"Security module does not provide an implementation");
1444 return SEC_E_UNSUPPORTED_FUNCTION;
1447 status = table->ImportSecurityContextA(pszPackage, pPackedContext, pToken, phContext);
1449 if (IsSecurityStatusError(status))
1451 WLog_WARN(TAG,
"ImportSecurityContextA status %s [0x%08" PRIX32
"]",
1452 GetSecurityStatusString(status), status);
1458static SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesW(
PCredHandle phCredential,
1459 ULONG ulAttribute,
void* pBuffer)
1461 SEC_WCHAR* Name = NULL;
1462 SECURITY_STATUS status = 0;
1464 Name = (SEC_WCHAR*)sspi_SecureHandleGetUpperPointer(phCredential);
1467 return SEC_E_SECPKG_NOT_FOUND;
1469 table = sspi_GetSecurityFunctionTableWByNameW(Name);
1472 return SEC_E_SECPKG_NOT_FOUND;
1474 if (!table->QueryCredentialsAttributesW)
1476 WLog_WARN(TAG,
"Security module does not provide an implementation");
1477 return SEC_E_UNSUPPORTED_FUNCTION;
1480 status = table->QueryCredentialsAttributesW(phCredential, ulAttribute, pBuffer);
1482 if (IsSecurityStatusError(status))
1484 WLog_WARN(TAG,
"QueryCredentialsAttributesW status %s [0x%08" PRIX32
"]",
1485 GetSecurityStatusString(status), status);
1491static SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesA(
PCredHandle phCredential,
1492 ULONG ulAttribute,
void* pBuffer)
1495 SECURITY_STATUS status = 0;
1497 Name = (
char*)sspi_SecureHandleGetUpperPointer(phCredential);
1500 return SEC_E_SECPKG_NOT_FOUND;
1502 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1505 return SEC_E_SECPKG_NOT_FOUND;
1507 if (!table->QueryCredentialsAttributesA)
1509 WLog_WARN(TAG,
"Security module does not provide an implementation");
1510 return SEC_E_UNSUPPORTED_FUNCTION;
1513 status = table->QueryCredentialsAttributesA(phCredential, ulAttribute, pBuffer);
1515 if (IsSecurityStatusError(status))
1517 WLog_WARN(TAG,
"QueryCredentialsAttributesA status %s [0x%08" PRIX32
"]",
1518 GetSecurityStatusString(status), status);
1524static SECURITY_STATUS SEC_ENTRY winpr_SetCredentialsAttributesW(
PCredHandle phCredential,
1525 ULONG ulAttribute,
void* pBuffer,
1528 SEC_WCHAR* Name = NULL;
1529 SECURITY_STATUS status = 0;
1531 Name = (SEC_WCHAR*)sspi_SecureHandleGetUpperPointer(phCredential);
1534 return SEC_E_SECPKG_NOT_FOUND;
1536 table = sspi_GetSecurityFunctionTableWByNameW(Name);
1539 return SEC_E_SECPKG_NOT_FOUND;
1541 if (!table->SetCredentialsAttributesW)
1543 WLog_WARN(TAG,
"Security module does not provide an implementation");
1544 return SEC_E_UNSUPPORTED_FUNCTION;
1547 status = table->SetCredentialsAttributesW(phCredential, ulAttribute, pBuffer, cbBuffer);
1549 if (IsSecurityStatusError(status))
1551 WLog_WARN(TAG,
"SetCredentialsAttributesW status %s [0x%08" PRIX32
"]",
1552 GetSecurityStatusString(status), status);
1558static SECURITY_STATUS SEC_ENTRY winpr_SetCredentialsAttributesA(
PCredHandle phCredential,
1559 ULONG ulAttribute,
void* pBuffer,
1563 SECURITY_STATUS status = 0;
1565 Name = (
char*)sspi_SecureHandleGetUpperPointer(phCredential);
1568 return SEC_E_SECPKG_NOT_FOUND;
1570 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1573 return SEC_E_SECPKG_NOT_FOUND;
1575 if (!table->SetCredentialsAttributesA)
1577 WLog_WARN(TAG,
"Security module does not provide an implementation");
1578 return SEC_E_UNSUPPORTED_FUNCTION;
1581 status = table->SetCredentialsAttributesA(phCredential, ulAttribute, pBuffer, cbBuffer);
1583 if (IsSecurityStatusError(status))
1585 WLog_WARN(TAG,
"SetCredentialsAttributesA status %s [0x%08" PRIX32
"]",
1586 GetSecurityStatusString(status), status);
1594static SECURITY_STATUS SEC_ENTRY
1596 ULONG fContextReq, ULONG TargetDataRep,
PCtxtHandle phNewContext,
1600 SECURITY_STATUS status = 0;
1602 Name = (
char*)sspi_SecureHandleGetUpperPointer(phCredential);
1605 return SEC_E_SECPKG_NOT_FOUND;
1607 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1610 return SEC_E_SECPKG_NOT_FOUND;
1612 if (!table->AcceptSecurityContext)
1614 WLog_WARN(TAG,
"Security module does not provide an implementation");
1615 return SEC_E_UNSUPPORTED_FUNCTION;
1619 table->AcceptSecurityContext(phCredential, phContext, pInput, fContextReq, TargetDataRep,
1620 phNewContext, pOutput, pfContextAttr, ptsTimeStamp);
1622 if (IsSecurityStatusError(status))
1624 WLog_WARN(TAG,
"AcceptSecurityContext status %s [0x%08" PRIX32
"]",
1625 GetSecurityStatusString(status), status);
1631static SECURITY_STATUS SEC_ENTRY winpr_ApplyControlToken(
PCtxtHandle phContext,
1635 SECURITY_STATUS status = 0;
1637 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1640 return SEC_E_SECPKG_NOT_FOUND;
1642 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1645 return SEC_E_SECPKG_NOT_FOUND;
1647 if (!table->ApplyControlToken)
1649 WLog_WARN(TAG,
"Security module does not provide an implementation");
1650 return SEC_E_UNSUPPORTED_FUNCTION;
1653 status = table->ApplyControlToken(phContext, pInput);
1655 if (IsSecurityStatusError(status))
1657 WLog_WARN(TAG,
"ApplyControlToken status %s [0x%08" PRIX32
"]",
1658 GetSecurityStatusString(status), status);
1664static SECURITY_STATUS SEC_ENTRY winpr_CompleteAuthToken(
PCtxtHandle phContext,
1668 SECURITY_STATUS status = 0;
1670 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1673 return SEC_E_SECPKG_NOT_FOUND;
1675 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1678 return SEC_E_SECPKG_NOT_FOUND;
1680 if (!table->CompleteAuthToken)
1682 WLog_WARN(TAG,
"Security module does not provide an implementation");
1683 return SEC_E_UNSUPPORTED_FUNCTION;
1686 status = table->CompleteAuthToken(phContext, pToken);
1688 if (IsSecurityStatusError(status))
1690 WLog_WARN(TAG,
"CompleteAuthToken status %s [0x%08" PRIX32
"]",
1691 GetSecurityStatusString(status), status);
1697static SECURITY_STATUS SEC_ENTRY winpr_DeleteSecurityContext(
PCtxtHandle phContext)
1699 const char* Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1702 return SEC_E_SECPKG_NOT_FOUND;
1707 return SEC_E_SECPKG_NOT_FOUND;
1709 if (!table->DeleteSecurityContext)
1711 WLog_WARN(TAG,
"Security module does not provide an implementation");
1712 return SEC_E_UNSUPPORTED_FUNCTION;
1715 const SECURITY_STATUS status = table->DeleteSecurityContext(phContext);
1717 if (IsSecurityStatusError(status))
1719 WLog_WARN(TAG,
"DeleteSecurityContext status %s [0x%08" PRIX32
"]",
1720 GetSecurityStatusString(status), status);
1726static SECURITY_STATUS SEC_ENTRY winpr_FreeContextBuffer(
void* pvContextBuffer)
1728 if (!pvContextBuffer)
1729 return SEC_E_INVALID_HANDLE;
1731 sspi_ContextBufferFree(pvContextBuffer);
1735static SECURITY_STATUS SEC_ENTRY winpr_ImpersonateSecurityContext(
PCtxtHandle phContext)
1737 SEC_CHAR* Name = NULL;
1738 SECURITY_STATUS status = 0;
1740 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1743 return SEC_E_SECPKG_NOT_FOUND;
1745 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1748 return SEC_E_SECPKG_NOT_FOUND;
1750 if (!table->ImpersonateSecurityContext)
1752 WLog_WARN(TAG,
"Security module does not provide an implementation");
1753 return SEC_E_UNSUPPORTED_FUNCTION;
1756 status = table->ImpersonateSecurityContext(phContext);
1758 if (IsSecurityStatusError(status))
1760 WLog_WARN(TAG,
"ImpersonateSecurityContext status %s [0x%08" PRIX32
"]",
1761 GetSecurityStatusString(status), status);
1767static SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextW(
1769 ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2,
1772 SEC_CHAR* Name = NULL;
1773 SECURITY_STATUS status = 0;
1775 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phCredential);
1778 return SEC_E_SECPKG_NOT_FOUND;
1780 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1783 return SEC_E_SECPKG_NOT_FOUND;
1785 if (!table->InitializeSecurityContextW)
1787 WLog_WARN(TAG,
"Security module does not provide an implementation");
1788 return SEC_E_UNSUPPORTED_FUNCTION;
1791 status = table->InitializeSecurityContextW(phCredential, phContext, pszTargetName, fContextReq,
1792 Reserved1, TargetDataRep, pInput, Reserved2,
1793 phNewContext, pOutput, pfContextAttr, ptsExpiry);
1795 if (IsSecurityStatusError(status))
1797 WLog_WARN(TAG,
"InitializeSecurityContextW status %s [0x%08" PRIX32
"]",
1798 GetSecurityStatusString(status), status);
1804static SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextA(
1806 ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2,
1809 SEC_CHAR* Name = NULL;
1810 SECURITY_STATUS status = 0;
1812 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phCredential);
1815 return SEC_E_SECPKG_NOT_FOUND;
1817 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1820 return SEC_E_SECPKG_NOT_FOUND;
1822 if (!table->InitializeSecurityContextA)
1824 WLog_WARN(TAG,
"Security module does not provide an implementation");
1825 return SEC_E_UNSUPPORTED_FUNCTION;
1828 status = table->InitializeSecurityContextA(phCredential, phContext, pszTargetName, fContextReq,
1829 Reserved1, TargetDataRep, pInput, Reserved2,
1830 phNewContext, pOutput, pfContextAttr, ptsExpiry);
1832 if (IsSecurityStatusError(status))
1834 WLog_WARN(TAG,
"InitializeSecurityContextA status %s [0x%08" PRIX32
"]",
1835 GetSecurityStatusString(status), status);
1841static SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesW(
PCtxtHandle phContext,
1842 ULONG ulAttribute,
void* pBuffer)
1844 SEC_CHAR* Name = NULL;
1845 SECURITY_STATUS status = 0;
1847 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1850 return SEC_E_SECPKG_NOT_FOUND;
1852 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1855 return SEC_E_SECPKG_NOT_FOUND;
1857 if (!table->QueryContextAttributesW)
1859 WLog_WARN(TAG,
"Security module does not provide an implementation");
1860 return SEC_E_UNSUPPORTED_FUNCTION;
1863 status = table->QueryContextAttributesW(phContext, ulAttribute, pBuffer);
1865 if (IsSecurityStatusError(status))
1867 WLog_WARN(TAG,
"QueryContextAttributesW status %s [0x%08" PRIX32
"]",
1868 GetSecurityStatusString(status), status);
1874static SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesA(
PCtxtHandle phContext,
1875 ULONG ulAttribute,
void* pBuffer)
1877 SEC_CHAR* Name = NULL;
1878 SECURITY_STATUS status = 0;
1880 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1883 return SEC_E_SECPKG_NOT_FOUND;
1885 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1888 return SEC_E_SECPKG_NOT_FOUND;
1890 if (!table->QueryContextAttributesA)
1892 WLog_WARN(TAG,
"Security module does not provide an implementation");
1893 return SEC_E_UNSUPPORTED_FUNCTION;
1896 status = table->QueryContextAttributesA(phContext, ulAttribute, pBuffer);
1898 if (IsSecurityStatusError(status))
1900 WLog_WARN(TAG,
"QueryContextAttributesA status %s [0x%08" PRIX32
"]",
1901 GetSecurityStatusString(status), status);
1907static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityContextToken(
PCtxtHandle phContext,
1910 SEC_CHAR* Name = NULL;
1911 SECURITY_STATUS status = 0;
1913 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1916 return SEC_E_SECPKG_NOT_FOUND;
1918 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1921 return SEC_E_SECPKG_NOT_FOUND;
1923 if (!table->QuerySecurityContextToken)
1925 WLog_WARN(TAG,
"Security module does not provide an implementation");
1926 return SEC_E_UNSUPPORTED_FUNCTION;
1929 status = table->QuerySecurityContextToken(phContext, phToken);
1931 if (IsSecurityStatusError(status))
1933 WLog_WARN(TAG,
"QuerySecurityContextToken status %s [0x%08" PRIX32
"]",
1934 GetSecurityStatusString(status), status);
1940static SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesW(
PCtxtHandle phContext,
1941 ULONG ulAttribute,
void* pBuffer,
1944 SEC_CHAR* Name = NULL;
1945 SECURITY_STATUS status = 0;
1947 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1950 return SEC_E_SECPKG_NOT_FOUND;
1952 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1955 return SEC_E_SECPKG_NOT_FOUND;
1957 if (!table->SetContextAttributesW)
1959 WLog_WARN(TAG,
"Security module does not provide an implementation");
1960 return SEC_E_UNSUPPORTED_FUNCTION;
1963 status = table->SetContextAttributesW(phContext, ulAttribute, pBuffer, cbBuffer);
1965 if (IsSecurityStatusError(status))
1967 WLog_WARN(TAG,
"SetContextAttributesW status %s [0x%08" PRIX32
"]",
1968 GetSecurityStatusString(status), status);
1974static SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesA(
PCtxtHandle phContext,
1975 ULONG ulAttribute,
void* pBuffer,
1979 SECURITY_STATUS status = 0;
1981 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1984 return SEC_E_SECPKG_NOT_FOUND;
1986 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1989 return SEC_E_SECPKG_NOT_FOUND;
1991 if (!table->SetContextAttributesA)
1993 WLog_WARN(TAG,
"Security module does not provide an implementation");
1994 return SEC_E_UNSUPPORTED_FUNCTION;
1997 status = table->SetContextAttributesA(phContext, ulAttribute, pBuffer, cbBuffer);
1999 if (IsSecurityStatusError(status))
2001 WLog_WARN(TAG,
"SetContextAttributesA status %s [0x%08" PRIX32
"]",
2002 GetSecurityStatusString(status), status);
2008static SECURITY_STATUS SEC_ENTRY winpr_RevertSecurityContext(
PCtxtHandle phContext)
2010 SEC_CHAR* Name = NULL;
2011 SECURITY_STATUS status = 0;
2013 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
2016 return SEC_E_SECPKG_NOT_FOUND;
2018 table = sspi_GetSecurityFunctionTableWByNameA(Name);
2021 return SEC_E_SECPKG_NOT_FOUND;
2023 if (!table->RevertSecurityContext)
2025 WLog_WARN(TAG,
"Security module does not provide an implementation");
2026 return SEC_E_UNSUPPORTED_FUNCTION;
2029 status = table->RevertSecurityContext(phContext);
2031 if (IsSecurityStatusError(status))
2033 WLog_WARN(TAG,
"RevertSecurityContext status %s [0x%08" PRIX32
"]",
2034 GetSecurityStatusString(status), status);
2042static SECURITY_STATUS SEC_ENTRY winpr_DecryptMessage(
PCtxtHandle phContext,
2047 SECURITY_STATUS status = 0;
2049 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
2052 return SEC_E_SECPKG_NOT_FOUND;
2054 table = sspi_GetSecurityFunctionTableAByNameA(Name);
2057 return SEC_E_SECPKG_NOT_FOUND;
2059 if (!table->DecryptMessage)
2061 WLog_WARN(TAG,
"Security module does not provide an implementation");
2062 return SEC_E_UNSUPPORTED_FUNCTION;
2065 status = table->DecryptMessage(phContext, pMessage, MessageSeqNo, pfQOP);
2067 if (IsSecurityStatusError(status))
2069 WLog_WARN(TAG,
"DecryptMessage status %s [0x%08" PRIX32
"]",
2070 GetSecurityStatusString(status), status);
2076static SECURITY_STATUS SEC_ENTRY winpr_EncryptMessage(
PCtxtHandle phContext, ULONG fQOP,
2080 SECURITY_STATUS status = 0;
2082 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
2085 return SEC_E_SECPKG_NOT_FOUND;
2087 table = sspi_GetSecurityFunctionTableAByNameA(Name);
2090 return SEC_E_SECPKG_NOT_FOUND;
2092 if (!table->EncryptMessage)
2094 WLog_WARN(TAG,
"Security module does not provide an implementation");
2095 return SEC_E_UNSUPPORTED_FUNCTION;
2098 status = table->EncryptMessage(phContext, fQOP, pMessage, MessageSeqNo);
2100 if (status != SEC_E_OK)
2102 WLog_ERR(TAG,
"EncryptMessage status %s [0x%08" PRIX32
"]", GetSecurityStatusString(status),
2109static SECURITY_STATUS SEC_ENTRY winpr_MakeSignature(
PCtxtHandle phContext, ULONG fQOP,
2113 SECURITY_STATUS status = 0;
2115 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
2118 return SEC_E_SECPKG_NOT_FOUND;
2120 table = sspi_GetSecurityFunctionTableAByNameA(Name);
2123 return SEC_E_SECPKG_NOT_FOUND;
2125 if (!table->MakeSignature)
2127 WLog_WARN(TAG,
"Security module does not provide an implementation");
2128 return SEC_E_UNSUPPORTED_FUNCTION;
2131 status = table->MakeSignature(phContext, fQOP, pMessage, MessageSeqNo);
2133 if (IsSecurityStatusError(status))
2135 WLog_WARN(TAG,
"MakeSignature status %s [0x%08" PRIX32
"]", GetSecurityStatusString(status),
2142static SECURITY_STATUS SEC_ENTRY winpr_VerifySignature(
PCtxtHandle phContext,
2147 SECURITY_STATUS status = 0;
2149 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
2152 return SEC_E_SECPKG_NOT_FOUND;
2154 table = sspi_GetSecurityFunctionTableAByNameA(Name);
2157 return SEC_E_SECPKG_NOT_FOUND;
2159 if (!table->VerifySignature)
2161 WLog_WARN(TAG,
"Security module does not provide an implementation");
2162 return SEC_E_UNSUPPORTED_FUNCTION;
2165 status = table->VerifySignature(phContext, pMessage, MessageSeqNo, pfQOP);
2167 if (IsSecurityStatusError(status))
2169 WLog_WARN(TAG,
"VerifySignature status %s [0x%08" PRIX32
"]",
2170 GetSecurityStatusString(status), status);
2178 winpr_EnumerateSecurityPackagesA,
2179 winpr_QueryCredentialsAttributesA,
2180 winpr_AcquireCredentialsHandleA,
2181 winpr_FreeCredentialsHandle,
2183 winpr_InitializeSecurityContextA,
2184 winpr_AcceptSecurityContext,
2185 winpr_CompleteAuthToken,
2186 winpr_DeleteSecurityContext,
2187 winpr_ApplyControlToken,
2188 winpr_QueryContextAttributesA,
2189 winpr_ImpersonateSecurityContext,
2190 winpr_RevertSecurityContext,
2191 winpr_MakeSignature,
2192 winpr_VerifySignature,
2193 winpr_FreeContextBuffer,
2194 winpr_QuerySecurityPackageInfoA,
2197 winpr_ExportSecurityContext,
2198 winpr_ImportSecurityContextA,
2201 winpr_QuerySecurityContextToken,
2202 winpr_EncryptMessage,
2203 winpr_DecryptMessage,
2204 winpr_SetContextAttributesA,
2205 winpr_SetCredentialsAttributesA,
2210 winpr_EnumerateSecurityPackagesW,
2211 winpr_QueryCredentialsAttributesW,
2212 winpr_AcquireCredentialsHandleW,
2213 winpr_FreeCredentialsHandle,
2215 winpr_InitializeSecurityContextW,
2216 winpr_AcceptSecurityContext,
2217 winpr_CompleteAuthToken,
2218 winpr_DeleteSecurityContext,
2219 winpr_ApplyControlToken,
2220 winpr_QueryContextAttributesW,
2221 winpr_ImpersonateSecurityContext,
2222 winpr_RevertSecurityContext,
2223 winpr_MakeSignature,
2224 winpr_VerifySignature,
2225 winpr_FreeContextBuffer,
2226 winpr_QuerySecurityPackageInfoW,
2229 winpr_ExportSecurityContext,
2230 winpr_ImportSecurityContextW,
2233 winpr_QuerySecurityContextToken,
2234 winpr_EncryptMessage,
2235 winpr_DecryptMessage,
2236 winpr_SetContextAttributesW,
2237 winpr_SetCredentialsAttributesW,