21#include <winpr/config.h>
22#include <winpr/assert.h>
23#include <winpr/windows.h>
26#include <winpr/sspi.h>
28#include <winpr/print.h>
32#include "sspi_winpr.h"
35#define TAG WINPR_TAG("sspi")
40#include "NTLM/ntlm_export.h"
41#include "CredSSP/credssp.h"
42#include "Kerberos/kerberos.h"
43#include "Negotiate/negotiate.h"
44#include "Schannel/schannel.h"
46static const SecPkgInfoA* SecPkgInfoA_LIST[] = { &NTLM_SecPkgInfoA, &KERBEROS_SecPkgInfoA,
47 &NEGOTIATE_SecPkgInfoA, &CREDSSP_SecPkgInfoA,
48 &SCHANNEL_SecPkgInfoA };
50static const SecPkgInfoW* SecPkgInfoW_LIST[] = { &NTLM_SecPkgInfoW, &KERBEROS_SecPkgInfoW,
51 &NEGOTIATE_SecPkgInfoW, &CREDSSP_SecPkgInfoW,
52 &SCHANNEL_SecPkgInfoW };
58} SecurityFunctionTableA_NAME;
62 const SEC_WCHAR* Name;
64} SecurityFunctionTableW_NAME;
66static const SecurityFunctionTableA_NAME SecurityFunctionTableA_NAME_LIST[] = {
67 {
"NTLM", &NTLM_SecurityFunctionTableA },
68 {
"Kerberos", &KERBEROS_SecurityFunctionTableA },
69 {
"Negotiate", &NEGOTIATE_SecurityFunctionTableA },
70 {
"CREDSSP", &CREDSSP_SecurityFunctionTableA },
71 {
"Schannel", &SCHANNEL_SecurityFunctionTableA }
74static WCHAR BUFFER_NAME_LIST_W[5][32] = { 0 };
76static const SecurityFunctionTableW_NAME SecurityFunctionTableW_NAME_LIST[] = {
77 { BUFFER_NAME_LIST_W[0], &NTLM_SecurityFunctionTableW },
78 { BUFFER_NAME_LIST_W[1], &KERBEROS_SecurityFunctionTableW },
79 { BUFFER_NAME_LIST_W[2], &NEGOTIATE_SecurityFunctionTableW },
80 { BUFFER_NAME_LIST_W[3], &CREDSSP_SecurityFunctionTableW },
81 { BUFFER_NAME_LIST_W[4], &SCHANNEL_SecurityFunctionTableW }
87 UINT32 allocatorIndex;
88} CONTEXT_BUFFER_ALLOC_ENTRY;
94 CONTEXT_BUFFER_ALLOC_ENTRY* entries;
95} CONTEXT_BUFFER_ALLOC_TABLE;
97static CONTEXT_BUFFER_ALLOC_TABLE ContextBufferAllocTable = { 0 };
99static int sspi_ContextBufferAllocTableNew(
void)
102 ContextBufferAllocTable.entries = NULL;
103 ContextBufferAllocTable.cEntries = 0;
104 ContextBufferAllocTable.cMaxEntries = 4;
105 size =
sizeof(CONTEXT_BUFFER_ALLOC_ENTRY) * ContextBufferAllocTable.cMaxEntries;
106 ContextBufferAllocTable.entries = (CONTEXT_BUFFER_ALLOC_ENTRY*)calloc(1, size);
108 if (!ContextBufferAllocTable.entries)
114static int sspi_ContextBufferAllocTableGrow(
void)
117 CONTEXT_BUFFER_ALLOC_ENTRY* entries = NULL;
118 ContextBufferAllocTable.cEntries = 0;
119 ContextBufferAllocTable.cMaxEntries *= 2;
120 size =
sizeof(CONTEXT_BUFFER_ALLOC_ENTRY) * ContextBufferAllocTable.cMaxEntries;
125 entries = (CONTEXT_BUFFER_ALLOC_ENTRY*)realloc(ContextBufferAllocTable.entries, size);
129 free(ContextBufferAllocTable.entries);
133 ContextBufferAllocTable.entries = entries;
134 ZeroMemory((
void*)&ContextBufferAllocTable.entries[ContextBufferAllocTable.cMaxEntries / 2],
139static void sspi_ContextBufferAllocTableFree(
void)
141 if (ContextBufferAllocTable.cEntries != 0)
142 WLog_ERR(TAG,
"ContextBufferAllocTable.entries == %" PRIu32,
143 ContextBufferAllocTable.cEntries);
145 ContextBufferAllocTable.cEntries = ContextBufferAllocTable.cMaxEntries = 0;
146 free(ContextBufferAllocTable.entries);
147 ContextBufferAllocTable.entries = NULL;
150static void* sspi_ContextBufferAlloc(UINT32 allocatorIndex,
size_t size)
152 void* contextBuffer = NULL;
154 for (UINT32 index = 0; index < ContextBufferAllocTable.cMaxEntries; index++)
156 if (!ContextBufferAllocTable.entries[index].contextBuffer)
158 contextBuffer = calloc(1, size);
163 ContextBufferAllocTable.cEntries++;
164 ContextBufferAllocTable.entries[index].contextBuffer = contextBuffer;
165 ContextBufferAllocTable.entries[index].allocatorIndex = allocatorIndex;
166 return ContextBufferAllocTable.entries[index].contextBuffer;
172 if (sspi_ContextBufferAllocTableGrow() < 0)
176 return sspi_ContextBufferAlloc(allocatorIndex, size);
188 size_t userLength = 0;
189 size_t domainLength = 0;
190 size_t passwordLength = 0;
195 if (credentials->ntlmSettings.samFile)
196 free(credentials->ntlmSettings.samFile);
198 userLength = credentials->identity.UserLength;
199 domainLength = credentials->identity.DomainLength;
200 passwordLength = credentials->identity.PasswordLength;
202 if (passwordLength > SSPI_CREDENTIALS_HASH_LENGTH_OFFSET)
203 passwordLength -= SSPI_CREDENTIALS_HASH_LENGTH_OFFSET;
205 if (credentials->identity.Flags & SEC_WINNT_AUTH_IDENTITY_UNICODE)
212 if (credentials->identity.User)
213 memset(credentials->identity.User, 0, userLength);
214 if (credentials->identity.Domain)
215 memset(credentials->identity.Domain, 0, domainLength);
216 if (credentials->identity.Password)
217 memset(credentials->identity.Password, 0, passwordLength);
218 free(credentials->identity.User);
219 free(credentials->identity.Domain);
220 free(credentials->identity.Password);
258 SecInvalidateHandle(handle);
262void* sspi_SecureHandleGetLowerPointer(
SecHandle* handle)
264 void* pointer = NULL;
266 if (!handle || !SecIsValidHandle(handle) || !handle->dwLower)
269 pointer = (
void*)~((
size_t)handle->dwLower);
273void sspi_SecureHandleInvalidate(
SecHandle* handle)
282void sspi_SecureHandleSetLowerPointer(
SecHandle* handle,
void* pointer)
287 handle->dwLower = (ULONG_PTR)(~((
size_t)pointer));
290void* sspi_SecureHandleGetUpperPointer(
SecHandle* handle)
292 void* pointer = NULL;
294 if (!handle || !SecIsValidHandle(handle) || !handle->dwUpper)
297 pointer = (
void*)~((
size_t)handle->dwUpper);
301void sspi_SecureHandleSetUpperPointer(
SecHandle* handle,
void* pointer)
306 handle->dwUpper = (ULONG_PTR)(~((
size_t)pointer));
309void sspi_SecureHandleFree(
SecHandle* handle)
314int sspi_SetAuthIdentityW(SEC_WINNT_AUTH_IDENTITY* identity,
const WCHAR* user,
const WCHAR* domain,
315 const WCHAR* password)
317 return sspi_SetAuthIdentityWithLengthW(identity, user, user ? _wcslen(user) : 0, domain,
318 domain ? _wcslen(domain) : 0, password,
319 password ? _wcslen(password) : 0);
322static BOOL copy(WCHAR** dst, ULONG* dstLen,
const WCHAR* what,
size_t len)
325 WINPR_ASSERT(dstLen);
330 if (len > UINT32_MAX)
334 if (!what && (len != 0))
336 if (!what && (len == 0))
339 *dst = calloc(
sizeof(WCHAR), len + 1);
343 memcpy(*dst, what, len *
sizeof(WCHAR));
344 *dstLen = WINPR_ASSERTING_INT_CAST(UINT32, len);
348int sspi_SetAuthIdentityWithLengthW(SEC_WINNT_AUTH_IDENTITY* identity,
const WCHAR* user,
349 size_t userLen,
const WCHAR* domain,
size_t domainLen,
350 const WCHAR* password,
size_t passwordLen)
352 WINPR_ASSERT(identity);
353 sspi_FreeAuthIdentity(identity);
354 identity->Flags &= (uint32_t)~SEC_WINNT_AUTH_IDENTITY_ANSI;
355 identity->Flags |= SEC_WINNT_AUTH_IDENTITY_UNICODE;
357 if (!copy(&identity->User, &identity->UserLength, user, userLen))
360 if (!copy(&identity->Domain, &identity->DomainLength, domain, domainLen))
363 if (!copy(&identity->Password, &identity->PasswordLength, password, passwordLen))
369static void zfree(WCHAR* str,
size_t len)
372 memset(str, 0, len *
sizeof(WCHAR));
376int sspi_SetAuthIdentityA(SEC_WINNT_AUTH_IDENTITY* identity,
const char* user,
const char* domain,
377 const char* password)
380 size_t unicodeUserLenW = 0;
381 size_t unicodeDomainLenW = 0;
382 size_t unicodePasswordLenW = 0;
383 LPWSTR unicodeUser = NULL;
384 LPWSTR unicodeDomain = NULL;
385 LPWSTR unicodePassword = NULL;
388 unicodeUser = ConvertUtf8ToWCharAlloc(user, &unicodeUserLenW);
391 unicodeDomain = ConvertUtf8ToWCharAlloc(domain, &unicodeDomainLenW);
394 unicodePassword = ConvertUtf8ToWCharAlloc(password, &unicodePasswordLenW);
396 rc = sspi_SetAuthIdentityWithLengthW(identity, unicodeUser, unicodeUserLenW, unicodeDomain,
397 unicodeDomainLenW, unicodePassword, unicodePasswordLenW);
399 zfree(unicodeUser, unicodeUserLenW);
400 zfree(unicodeDomain, unicodeDomainLenW);
401 zfree(unicodePassword, unicodePasswordLenW);
405UINT32 sspi_GetAuthIdentityVersion(
const void* identity)
412 version = *((
const UINT32*)identity);
414 if ((version == SEC_WINNT_AUTH_IDENTITY_VERSION) ||
415 (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2))
423UINT32 sspi_GetAuthIdentityFlags(
const void* identity)
431 version = sspi_GetAuthIdentityVersion(identity);
433 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
435 flags = ((
const SEC_WINNT_AUTH_IDENTITY_EX*)identity)->Flags;
437 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
443 flags = ((
const SEC_WINNT_AUTH_IDENTITY*)identity)->Flags;
449BOOL sspi_GetAuthIdentityUserDomainW(
const void* identity,
const WCHAR** pUser, UINT32* pUserLength,
450 const WCHAR** pDomain, UINT32* pDomainLength)
457 version = sspi_GetAuthIdentityVersion(identity);
459 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
462 *pUser = (
const WCHAR*)id->User;
463 *pUserLength =
id->UserLength;
464 *pDomain = (
const WCHAR*)id->Domain;
465 *pDomainLength =
id->DomainLength;
467 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
470 UINT32 UserOffset =
id->UserOffset;
471 UINT32 DomainOffset =
id->DomainOffset;
472 *pUser = (
const WCHAR*)&((
const uint8_t*)identity)[UserOffset];
473 *pUserLength =
id->UserLength / 2;
474 *pDomain = (
const WCHAR*)&((
const uint8_t*)identity)[DomainOffset];
475 *pDomainLength =
id->DomainLength / 2;
480 *pUser = (
const WCHAR*)id->User;
481 *pUserLength =
id->UserLength;
482 *pDomain = (
const WCHAR*)id->Domain;
483 *pDomainLength =
id->DomainLength;
489BOOL sspi_GetAuthIdentityUserDomainA(
const void* identity,
const char** pUser, UINT32* pUserLength,
490 const char** pDomain, UINT32* pDomainLength)
497 version = sspi_GetAuthIdentityVersion(identity);
499 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
502 *pUser = (
const char*)id->User;
503 *pUserLength =
id->UserLength;
504 *pDomain = (
const char*)id->Domain;
505 *pDomainLength =
id->DomainLength;
507 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
510 UINT32 UserOffset =
id->UserOffset;
511 UINT32 DomainOffset =
id->DomainOffset;
512 *pUser = (
const char*)&((
const uint8_t*)identity)[UserOffset];
513 *pUserLength =
id->UserLength;
514 *pDomain = (
const char*)&((
const uint8_t*)identity)[DomainOffset];
515 *pDomainLength =
id->DomainLength;
520 *pUser = (
const char*)id->User;
521 *pUserLength =
id->UserLength;
522 *pDomain = (
const char*)id->Domain;
523 *pDomainLength =
id->DomainLength;
529BOOL sspi_GetAuthIdentityPasswordW(
const void* identity,
const WCHAR** pPassword,
530 UINT32* pPasswordLength)
537 version = sspi_GetAuthIdentityVersion(identity);
539 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
542 *pPassword = (
const WCHAR*)id->Password;
543 *pPasswordLength =
id->PasswordLength;
545 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
552 *pPassword = (
const WCHAR*)id->Password;
553 *pPasswordLength =
id->PasswordLength;
559BOOL sspi_GetAuthIdentityPasswordA(
const void* identity,
const char** pPassword,
560 UINT32* pPasswordLength)
567 version = sspi_GetAuthIdentityVersion(identity);
569 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
572 *pPassword = (
const char*)id->Password;
573 *pPasswordLength =
id->PasswordLength;
575 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
582 *pPassword = (
const char*)id->Password;
583 *pPasswordLength =
id->PasswordLength;
590 char** pDomain,
char** pPassword)
592 BOOL success = FALSE;
593 const char* UserA = NULL;
594 const char* DomainA = NULL;
595 const char* PasswordA = NULL;
596 const WCHAR* UserW = NULL;
597 const WCHAR* DomainW = NULL;
598 const WCHAR* PasswordW = NULL;
599 UINT32 UserLength = 0;
600 UINT32 DomainLength = 0;
601 UINT32 PasswordLength = 0;
603 if (!identity || !pUser || !pDomain || !pPassword)
606 *pUser = *pDomain = *pPassword = NULL;
608 UINT32 identityFlags = sspi_GetAuthIdentityFlags(identity);
610 if (identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI)
612 if (!sspi_GetAuthIdentityUserDomainA(identity, &UserA, &UserLength, &DomainA,
616 if (!sspi_GetAuthIdentityPasswordA(identity, &PasswordA, &PasswordLength))
619 if (UserA && UserLength)
621 *pUser = _strdup(UserA);
627 if (DomainA && DomainLength)
629 *pDomain = _strdup(DomainA);
635 if (PasswordA && PasswordLength)
637 *pPassword = _strdup(PasswordA);
647 if (!sspi_GetAuthIdentityUserDomainW(identity, &UserW, &UserLength, &DomainW,
651 if (!sspi_GetAuthIdentityPasswordW(identity, &PasswordW, &PasswordLength))
654 if (UserW && (UserLength > 0))
656 *pUser = ConvertWCharNToUtf8Alloc(UserW, UserLength, NULL);
661 if (DomainW && (DomainLength > 0))
663 *pDomain = ConvertWCharNToUtf8Alloc(DomainW, DomainLength, NULL);
668 if (PasswordW && (PasswordLength > 0))
670 *pPassword = ConvertWCharNToUtf8Alloc(PasswordW, PasswordLength, NULL);
683 WCHAR** pDomain, WCHAR** pPassword)
685 BOOL success = FALSE;
686 const char* UserA = NULL;
687 const char* DomainA = NULL;
688 const char* PasswordA = NULL;
689 const WCHAR* UserW = NULL;
690 const WCHAR* DomainW = NULL;
691 const WCHAR* PasswordW = NULL;
692 UINT32 UserLength = 0;
693 UINT32 DomainLength = 0;
694 UINT32 PasswordLength = 0;
696 if (!identity || !pUser || !pDomain || !pPassword)
699 *pUser = *pDomain = *pPassword = NULL;
701 UINT32 identityFlags = sspi_GetAuthIdentityFlags(identity);
703 if (identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI)
705 if (!sspi_GetAuthIdentityUserDomainA(identity, &UserA, &UserLength, &DomainA,
709 if (!sspi_GetAuthIdentityPasswordA(identity, &PasswordA, &PasswordLength))
712 if (UserA && (UserLength > 0))
714 WCHAR* ptr = ConvertUtf8NToWCharAlloc(UserA, UserLength, NULL);
721 if (DomainA && (DomainLength > 0))
723 WCHAR* ptr = ConvertUtf8NToWCharAlloc(DomainA, DomainLength, NULL);
729 if (PasswordA && (PasswordLength > 0))
731 WCHAR* ptr = ConvertUtf8NToWCharAlloc(PasswordA, PasswordLength, NULL);
742 if (!sspi_GetAuthIdentityUserDomainW(identity, &UserW, &UserLength, &DomainW,
746 if (!sspi_GetAuthIdentityPasswordW(identity, &PasswordW, &PasswordLength))
749 if (UserW && UserLength)
751 *pUser = _wcsdup(UserW);
757 if (DomainW && DomainLength)
759 *pDomain = _wcsdup(DomainW);
765 if (PasswordW && PasswordLength)
767 *pPassword = _wcsdup(PasswordW);
783 UINT32 identityFlags = 0;
784 char* PackageList = NULL;
785 const char* PackageListA = NULL;
786 const WCHAR* PackageListW = NULL;
787 UINT32 PackageListLength = 0;
788 UINT32 PackageListOffset = 0;
789 const void* pAuthData = (
const void*)identity;
794 version = sspi_GetAuthIdentityVersion(pAuthData);
795 identityFlags = sspi_GetAuthIdentityFlags(pAuthData);
797 if (identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI)
799 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
802 PackageListA = (
const char*)ad->PackageList;
803 PackageListLength = ad->PackageListLength;
806 if (PackageListA && PackageListLength)
808 PackageList = _strdup(PackageListA);
813 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
816 PackageListW = (
const WCHAR*)ad->PackageList;
817 PackageListLength = ad->PackageListLength;
819 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
822 PackageListOffset = ad->PackageListOffset;
823 PackageListW = (
const WCHAR*)&((
const uint8_t*)pAuthData)[PackageListOffset];
824 PackageListLength = ad->PackageListLength / 2;
827 if (PackageListW && (PackageListLength > 0))
828 PackageList = ConvertWCharNToUtf8Alloc(PackageListW, PackageListLength, NULL);
833 *pPackageList = PackageList;
840int sspi_CopyAuthIdentity(SEC_WINNT_AUTH_IDENTITY* identity,
844 UINT32 identityFlags = 0;
845 const char* UserA = NULL;
846 const char* DomainA = NULL;
847 const char* PasswordA = NULL;
848 const WCHAR* UserW = NULL;
849 const WCHAR* DomainW = NULL;
850 const WCHAR* PasswordW = NULL;
851 UINT32 UserLength = 0;
852 UINT32 DomainLength = 0;
853 UINT32 PasswordLength = 0;
855 sspi_FreeAuthIdentity(identity);
857 identityFlags = sspi_GetAuthIdentityFlags(srcIdentity);
859 identity->Flags = identityFlags;
861 if (identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI)
863 if (!sspi_GetAuthIdentityUserDomainA(srcIdentity, &UserA, &UserLength, &DomainA,
869 if (!sspi_GetAuthIdentityPasswordA(srcIdentity, &PasswordA, &PasswordLength))
874 status = sspi_SetAuthIdentity(identity, UserA, DomainA, PasswordA);
879 identity->Flags &= (uint32_t)~SEC_WINNT_AUTH_IDENTITY_ANSI;
880 identity->Flags |= SEC_WINNT_AUTH_IDENTITY_UNICODE;
884 identity->Flags |= SEC_WINNT_AUTH_IDENTITY_UNICODE;
886 if (!sspi_GetAuthIdentityUserDomainW(srcIdentity, &UserW, &UserLength, &DomainW, &DomainLength))
891 if (!sspi_GetAuthIdentityPasswordW(srcIdentity, &PasswordW, &PasswordLength))
897 identity->UserLength = UserLength;
899 if (identity->UserLength > 0)
901 identity->User = (UINT16*)calloc((identity->UserLength + 1),
sizeof(WCHAR));
906 CopyMemory(identity->User, UserW, identity->UserLength *
sizeof(WCHAR));
907 identity->User[identity->UserLength] = 0;
910 identity->DomainLength = DomainLength;
912 if (identity->DomainLength > 0)
914 identity->Domain = (UINT16*)calloc((identity->DomainLength + 1),
sizeof(WCHAR));
916 if (!identity->Domain)
919 CopyMemory(identity->Domain, DomainW, identity->DomainLength *
sizeof(WCHAR));
920 identity->Domain[identity->DomainLength] = 0;
923 identity->PasswordLength = PasswordLength;
925 if (identity->PasswordLength > SSPI_CREDENTIALS_HASH_LENGTH_OFFSET)
926 identity->PasswordLength -= SSPI_CREDENTIALS_HASH_LENGTH_OFFSET;
930 identity->Password = (UINT16*)calloc((identity->PasswordLength + 1),
sizeof(WCHAR));
932 if (!identity->Password)
935 CopyMemory(identity->Password, PasswordW, identity->PasswordLength *
sizeof(WCHAR));
936 identity->Password[identity->PasswordLength] = 0;
939 identity->PasswordLength = PasswordLength;
948 for (UINT32 index = 0; index < pMessage->cBuffers; index++)
950 if (pMessage->pBuffers[index].BufferType == BufferType)
952 pSecBuffer = &pMessage->pBuffers[index];
960static BOOL WINPR_init(
void)
963 for (
size_t x = 0; x < ARRAYSIZE(SecurityFunctionTableA_NAME_LIST); x++)
965 const SecurityFunctionTableA_NAME* cur = &SecurityFunctionTableA_NAME_LIST[x];
966 InitializeConstWCharFromUtf8(cur->Name, BUFFER_NAME_LIST_W[x],
967 ARRAYSIZE(BUFFER_NAME_LIST_W[x]));
972static BOOL CALLBACK sspi_init(WINPR_ATTR_UNUSED
PINIT_ONCE InitOnce,
973 WINPR_ATTR_UNUSED PVOID Parameter, WINPR_ATTR_UNUSED PVOID* Context)
975 winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT);
976 sspi_ContextBufferAllocTableNew();
977 if (!SCHANNEL_init())
979 if (!KERBEROS_init())
985 if (!NEGOTIATE_init())
990void sspi_GlobalInit(
void)
992 static INIT_ONCE once = INIT_ONCE_STATIC_INIT;
994 InitOnceExecuteOnce(&once, sspi_init, &flags, NULL);
997void sspi_GlobalFinish(
void)
999 sspi_ContextBufferAllocTableFree();
1004 size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1006 for (
size_t index = 0; index < cPackages; index++)
1008 if (strcmp(Name, SecurityFunctionTableA_NAME_LIST[index].Name) == 0)
1010 return SecurityFunctionTableA_NAME_LIST[index].SecurityFunctionTable;
1019 size_t cPackages = ARRAYSIZE(SecPkgInfoW_LIST);
1021 for (
size_t index = 0; index < cPackages; index++)
1023 if (_wcscmp(Name, SecurityFunctionTableW_NAME_LIST[index].Name) == 0)
1025 return SecurityFunctionTableW_NAME_LIST[index].SecurityFunctionTable;
1034 SEC_WCHAR* NameW = NULL;
1040 NameW = ConvertUtf8ToWCharAlloc(Name, NULL);
1045 table = sspi_GetSecurityFunctionTableWByNameW(NameW);
1050static void FreeContextBuffer_EnumerateSecurityPackages(
void* contextBuffer);
1051static void FreeContextBuffer_QuerySecurityPackageInfo(
void* contextBuffer);
1053static void sspi_ContextBufferFree(
void* contextBuffer)
1055 UINT32 allocatorIndex = 0;
1057 for (
size_t index = 0; index < ContextBufferAllocTable.cMaxEntries; index++)
1059 if (contextBuffer == ContextBufferAllocTable.entries[index].contextBuffer)
1061 contextBuffer = ContextBufferAllocTable.entries[index].contextBuffer;
1062 allocatorIndex = ContextBufferAllocTable.entries[index].allocatorIndex;
1063 ContextBufferAllocTable.cEntries--;
1064 ContextBufferAllocTable.entries[index].allocatorIndex = 0;
1065 ContextBufferAllocTable.entries[index].contextBuffer = NULL;
1067 switch (allocatorIndex)
1069 case EnumerateSecurityPackagesIndex:
1070 FreeContextBuffer_EnumerateSecurityPackages(contextBuffer);
1073 case QuerySecurityPackageInfoIndex:
1074 FreeContextBuffer_QuerySecurityPackageInfo(contextBuffer);
1089static SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesW(ULONG* pcPackages,
1092 const size_t cPackages = ARRAYSIZE(SecPkgInfoW_LIST);
1093 const size_t size =
sizeof(
SecPkgInfoW) * cPackages;
1095 (
SecPkgInfoW*)sspi_ContextBufferAlloc(EnumerateSecurityPackagesIndex, size);
1097 WINPR_ASSERT(cPackages <= UINT32_MAX);
1100 return SEC_E_INSUFFICIENT_MEMORY;
1102 for (
size_t index = 0; index < cPackages; index++)
1104 pPackageInfo[index].fCapabilities = SecPkgInfoW_LIST[index]->fCapabilities;
1105 pPackageInfo[index].wVersion = SecPkgInfoW_LIST[index]->wVersion;
1106 pPackageInfo[index].wRPCID = SecPkgInfoW_LIST[index]->wRPCID;
1107 pPackageInfo[index].cbMaxToken = SecPkgInfoW_LIST[index]->cbMaxToken;
1108 pPackageInfo[index].Name = _wcsdup(SecPkgInfoW_LIST[index]->Name);
1109 pPackageInfo[index].Comment = _wcsdup(SecPkgInfoW_LIST[index]->Comment);
1112 *(pcPackages) = (UINT32)cPackages;
1113 *(ppPackageInfo) = pPackageInfo;
1117static SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesA(ULONG* pcPackages,
1120 const size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1121 const size_t size =
sizeof(
SecPkgInfoA) * cPackages;
1123 (
SecPkgInfoA*)sspi_ContextBufferAlloc(EnumerateSecurityPackagesIndex, size);
1125 WINPR_ASSERT(cPackages <= UINT32_MAX);
1128 return SEC_E_INSUFFICIENT_MEMORY;
1130 for (
size_t index = 0; index < cPackages; index++)
1132 pPackageInfo[index].fCapabilities = SecPkgInfoA_LIST[index]->fCapabilities;
1133 pPackageInfo[index].wVersion = SecPkgInfoA_LIST[index]->wVersion;
1134 pPackageInfo[index].wRPCID = SecPkgInfoA_LIST[index]->wRPCID;
1135 pPackageInfo[index].cbMaxToken = SecPkgInfoA_LIST[index]->cbMaxToken;
1136 pPackageInfo[index].Name = _strdup(SecPkgInfoA_LIST[index]->Name);
1137 pPackageInfo[index].Comment = _strdup(SecPkgInfoA_LIST[index]->Comment);
1139 if (!pPackageInfo[index].Name || !pPackageInfo[index].Comment)
1141 sspi_ContextBufferFree(pPackageInfo);
1142 return SEC_E_INSUFFICIENT_MEMORY;
1146 *(pcPackages) = (UINT32)cPackages;
1147 *(ppPackageInfo) = pPackageInfo;
1151static void FreeContextBuffer_EnumerateSecurityPackages(
void* contextBuffer)
1154 size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1159 for (
size_t index = 0; index < cPackages; index++)
1161 free(pPackageInfo[index].Name);
1162 free(pPackageInfo[index].Comment);
1168static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoW(SEC_WCHAR* pszPackageName,
1171 size_t cPackages = ARRAYSIZE(SecPkgInfoW_LIST);
1173 for (
size_t index = 0; index < cPackages; index++)
1175 if (_wcscmp(pszPackageName, SecPkgInfoW_LIST[index]->Name) == 0)
1179 (
SecPkgInfoW*)sspi_ContextBufferAlloc(QuerySecurityPackageInfoIndex, size);
1182 return SEC_E_INSUFFICIENT_MEMORY;
1184 pPackageInfo->fCapabilities = SecPkgInfoW_LIST[index]->fCapabilities;
1185 pPackageInfo->wVersion = SecPkgInfoW_LIST[index]->wVersion;
1186 pPackageInfo->wRPCID = SecPkgInfoW_LIST[index]->wRPCID;
1187 pPackageInfo->cbMaxToken = SecPkgInfoW_LIST[index]->cbMaxToken;
1188 pPackageInfo->Name = _wcsdup(SecPkgInfoW_LIST[index]->Name);
1189 pPackageInfo->Comment = _wcsdup(SecPkgInfoW_LIST[index]->Comment);
1190 *(ppPackageInfo) = pPackageInfo;
1195 *(ppPackageInfo) = NULL;
1196 return SEC_E_SECPKG_NOT_FOUND;
1199static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoA(SEC_CHAR* pszPackageName,
1202 size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1204 for (
size_t index = 0; index < cPackages; index++)
1206 if (strcmp(pszPackageName, SecPkgInfoA_LIST[index]->Name) == 0)
1210 (
SecPkgInfoA*)sspi_ContextBufferAlloc(QuerySecurityPackageInfoIndex, size);
1213 return SEC_E_INSUFFICIENT_MEMORY;
1215 pPackageInfo->fCapabilities = SecPkgInfoA_LIST[index]->fCapabilities;
1216 pPackageInfo->wVersion = SecPkgInfoA_LIST[index]->wVersion;
1217 pPackageInfo->wRPCID = SecPkgInfoA_LIST[index]->wRPCID;
1218 pPackageInfo->cbMaxToken = SecPkgInfoA_LIST[index]->cbMaxToken;
1219 pPackageInfo->Name = _strdup(SecPkgInfoA_LIST[index]->Name);
1220 pPackageInfo->Comment = _strdup(SecPkgInfoA_LIST[index]->Comment);
1222 if (!pPackageInfo->Name || !pPackageInfo->Comment)
1224 sspi_ContextBufferFree(pPackageInfo);
1225 return SEC_E_INSUFFICIENT_MEMORY;
1228 *(ppPackageInfo) = pPackageInfo;
1233 *(ppPackageInfo) = NULL;
1234 return SEC_E_SECPKG_NOT_FOUND;
1237void FreeContextBuffer_QuerySecurityPackageInfo(
void* contextBuffer)
1239 SecPkgInfo* pPackageInfo = (SecPkgInfo*)contextBuffer;
1244 free(pPackageInfo->Name);
1245 free(pPackageInfo->Comment);
1251static SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleW(
1252 SEC_WCHAR* pszPrincipal, SEC_WCHAR* pszPackage, ULONG fCredentialUse,
void* pvLogonID,
1253 void* pAuthData, SEC_GET_KEY_FN pGetKeyFn,
void* pvGetKeyArgument,
PCredHandle phCredential,
1256 SECURITY_STATUS status = 0;
1260 return SEC_E_SECPKG_NOT_FOUND;
1262 if (!table->AcquireCredentialsHandleW)
1264 WLog_WARN(TAG,
"Security module does not provide an implementation");
1265 return SEC_E_UNSUPPORTED_FUNCTION;
1268 status = table->AcquireCredentialsHandleW(pszPrincipal, pszPackage, fCredentialUse, pvLogonID,
1269 pAuthData, pGetKeyFn, pvGetKeyArgument, phCredential,
1272 if (IsSecurityStatusError(status))
1274 WLog_WARN(TAG,
"AcquireCredentialsHandleW status %s [0x%08" PRIX32
"]",
1275 GetSecurityStatusString(status), status);
1281static SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleA(
1282 SEC_CHAR* pszPrincipal, SEC_CHAR* pszPackage, ULONG fCredentialUse,
void* pvLogonID,
1283 void* pAuthData, SEC_GET_KEY_FN pGetKeyFn,
void* pvGetKeyArgument,
PCredHandle phCredential,
1286 SECURITY_STATUS status = 0;
1290 return SEC_E_SECPKG_NOT_FOUND;
1292 if (!table->AcquireCredentialsHandleA)
1294 WLog_WARN(TAG,
"Security module does not provide an implementation");
1295 return SEC_E_UNSUPPORTED_FUNCTION;
1298 status = table->AcquireCredentialsHandleA(pszPrincipal, pszPackage, fCredentialUse, pvLogonID,
1299 pAuthData, pGetKeyFn, pvGetKeyArgument, phCredential,
1302 if (IsSecurityStatusError(status))
1304 WLog_WARN(TAG,
"AcquireCredentialsHandleA status %s [0x%08" PRIX32
"]",
1305 GetSecurityStatusString(status), status);
1311static SECURITY_STATUS SEC_ENTRY winpr_ExportSecurityContext(
PCtxtHandle phContext, ULONG fFlags,
1315 SEC_CHAR* Name = NULL;
1316 SECURITY_STATUS status = 0;
1318 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1321 return SEC_E_SECPKG_NOT_FOUND;
1323 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1326 return SEC_E_SECPKG_NOT_FOUND;
1328 if (!table->ExportSecurityContext)
1330 WLog_WARN(TAG,
"Security module does not provide an implementation");
1331 return SEC_E_UNSUPPORTED_FUNCTION;
1334 status = table->ExportSecurityContext(phContext, fFlags, pPackedContext, pToken);
1336 if (IsSecurityStatusError(status))
1338 WLog_WARN(TAG,
"ExportSecurityContext status %s [0x%08" PRIX32
"]",
1339 GetSecurityStatusString(status), status);
1345static SECURITY_STATUS SEC_ENTRY winpr_FreeCredentialsHandle(
PCredHandle phCredential)
1348 SECURITY_STATUS status = 0;
1350 Name = (
char*)sspi_SecureHandleGetUpperPointer(phCredential);
1353 return SEC_E_SECPKG_NOT_FOUND;
1355 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1358 return SEC_E_SECPKG_NOT_FOUND;
1360 if (!table->FreeCredentialsHandle)
1362 WLog_WARN(TAG,
"Security module does not provide an implementation");
1363 return SEC_E_UNSUPPORTED_FUNCTION;
1366 status = table->FreeCredentialsHandle(phCredential);
1368 if (IsSecurityStatusError(status))
1370 WLog_WARN(TAG,
"FreeCredentialsHandle status %s [0x%08" PRIX32
"]",
1371 GetSecurityStatusString(status), status);
1377static SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextW(SEC_WCHAR* pszPackage,
1381 SEC_CHAR* Name = NULL;
1382 SECURITY_STATUS status = 0;
1384 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1387 return SEC_E_SECPKG_NOT_FOUND;
1389 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1392 return SEC_E_SECPKG_NOT_FOUND;
1394 if (!table->ImportSecurityContextW)
1396 WLog_WARN(TAG,
"Security module does not provide an implementation");
1397 return SEC_E_UNSUPPORTED_FUNCTION;
1400 status = table->ImportSecurityContextW(pszPackage, pPackedContext, pToken, phContext);
1402 if (IsSecurityStatusError(status))
1404 WLog_WARN(TAG,
"ImportSecurityContextW status %s [0x%08" PRIX32
"]",
1405 GetSecurityStatusString(status), status);
1411static SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextA(SEC_CHAR* pszPackage,
1416 SECURITY_STATUS status = 0;
1418 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1421 return SEC_E_SECPKG_NOT_FOUND;
1423 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1426 return SEC_E_SECPKG_NOT_FOUND;
1428 if (!table->ImportSecurityContextA)
1430 WLog_WARN(TAG,
"Security module does not provide an implementation");
1431 return SEC_E_UNSUPPORTED_FUNCTION;
1434 status = table->ImportSecurityContextA(pszPackage, pPackedContext, pToken, phContext);
1436 if (IsSecurityStatusError(status))
1438 WLog_WARN(TAG,
"ImportSecurityContextA status %s [0x%08" PRIX32
"]",
1439 GetSecurityStatusString(status), status);
1445static SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesW(
PCredHandle phCredential,
1446 ULONG ulAttribute,
void* pBuffer)
1448 SEC_WCHAR* Name = NULL;
1449 SECURITY_STATUS status = 0;
1451 Name = (SEC_WCHAR*)sspi_SecureHandleGetUpperPointer(phCredential);
1454 return SEC_E_SECPKG_NOT_FOUND;
1456 table = sspi_GetSecurityFunctionTableWByNameW(Name);
1459 return SEC_E_SECPKG_NOT_FOUND;
1461 if (!table->QueryCredentialsAttributesW)
1463 WLog_WARN(TAG,
"Security module does not provide an implementation");
1464 return SEC_E_UNSUPPORTED_FUNCTION;
1467 status = table->QueryCredentialsAttributesW(phCredential, ulAttribute, pBuffer);
1469 if (IsSecurityStatusError(status))
1471 WLog_WARN(TAG,
"QueryCredentialsAttributesW status %s [0x%08" PRIX32
"]",
1472 GetSecurityStatusString(status), status);
1478static SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesA(
PCredHandle phCredential,
1479 ULONG ulAttribute,
void* pBuffer)
1482 SECURITY_STATUS status = 0;
1484 Name = (
char*)sspi_SecureHandleGetUpperPointer(phCredential);
1487 return SEC_E_SECPKG_NOT_FOUND;
1489 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1492 return SEC_E_SECPKG_NOT_FOUND;
1494 if (!table->QueryCredentialsAttributesA)
1496 WLog_WARN(TAG,
"Security module does not provide an implementation");
1497 return SEC_E_UNSUPPORTED_FUNCTION;
1500 status = table->QueryCredentialsAttributesA(phCredential, ulAttribute, pBuffer);
1502 if (IsSecurityStatusError(status))
1504 WLog_WARN(TAG,
"QueryCredentialsAttributesA status %s [0x%08" PRIX32
"]",
1505 GetSecurityStatusString(status), status);
1511static SECURITY_STATUS SEC_ENTRY winpr_SetCredentialsAttributesW(
PCredHandle phCredential,
1512 ULONG ulAttribute,
void* pBuffer,
1515 SEC_WCHAR* Name = NULL;
1516 SECURITY_STATUS status = 0;
1518 Name = (SEC_WCHAR*)sspi_SecureHandleGetUpperPointer(phCredential);
1521 return SEC_E_SECPKG_NOT_FOUND;
1523 table = sspi_GetSecurityFunctionTableWByNameW(Name);
1526 return SEC_E_SECPKG_NOT_FOUND;
1528 if (!table->SetCredentialsAttributesW)
1530 WLog_WARN(TAG,
"Security module does not provide an implementation");
1531 return SEC_E_UNSUPPORTED_FUNCTION;
1534 status = table->SetCredentialsAttributesW(phCredential, ulAttribute, pBuffer, cbBuffer);
1536 if (IsSecurityStatusError(status))
1538 WLog_WARN(TAG,
"SetCredentialsAttributesW status %s [0x%08" PRIX32
"]",
1539 GetSecurityStatusString(status), status);
1545static SECURITY_STATUS SEC_ENTRY winpr_SetCredentialsAttributesA(
PCredHandle phCredential,
1546 ULONG ulAttribute,
void* pBuffer,
1550 SECURITY_STATUS status = 0;
1552 Name = (
char*)sspi_SecureHandleGetUpperPointer(phCredential);
1555 return SEC_E_SECPKG_NOT_FOUND;
1557 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1560 return SEC_E_SECPKG_NOT_FOUND;
1562 if (!table->SetCredentialsAttributesA)
1564 WLog_WARN(TAG,
"Security module does not provide an implementation");
1565 return SEC_E_UNSUPPORTED_FUNCTION;
1568 status = table->SetCredentialsAttributesA(phCredential, ulAttribute, pBuffer, cbBuffer);
1570 if (IsSecurityStatusError(status))
1572 WLog_WARN(TAG,
"SetCredentialsAttributesA status %s [0x%08" PRIX32
"]",
1573 GetSecurityStatusString(status), status);
1581static SECURITY_STATUS SEC_ENTRY
1583 ULONG fContextReq, ULONG TargetDataRep,
PCtxtHandle phNewContext,
1587 SECURITY_STATUS status = 0;
1589 Name = (
char*)sspi_SecureHandleGetUpperPointer(phCredential);
1592 return SEC_E_SECPKG_NOT_FOUND;
1594 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1597 return SEC_E_SECPKG_NOT_FOUND;
1599 if (!table->AcceptSecurityContext)
1601 WLog_WARN(TAG,
"Security module does not provide an implementation");
1602 return SEC_E_UNSUPPORTED_FUNCTION;
1606 table->AcceptSecurityContext(phCredential, phContext, pInput, fContextReq, TargetDataRep,
1607 phNewContext, pOutput, pfContextAttr, ptsTimeStamp);
1609 if (IsSecurityStatusError(status))
1611 WLog_WARN(TAG,
"AcceptSecurityContext status %s [0x%08" PRIX32
"]",
1612 GetSecurityStatusString(status), status);
1618static SECURITY_STATUS SEC_ENTRY winpr_ApplyControlToken(
PCtxtHandle phContext,
1622 SECURITY_STATUS status = 0;
1624 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1627 return SEC_E_SECPKG_NOT_FOUND;
1629 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1632 return SEC_E_SECPKG_NOT_FOUND;
1634 if (!table->ApplyControlToken)
1636 WLog_WARN(TAG,
"Security module does not provide an implementation");
1637 return SEC_E_UNSUPPORTED_FUNCTION;
1640 status = table->ApplyControlToken(phContext, pInput);
1642 if (IsSecurityStatusError(status))
1644 WLog_WARN(TAG,
"ApplyControlToken status %s [0x%08" PRIX32
"]",
1645 GetSecurityStatusString(status), status);
1651static SECURITY_STATUS SEC_ENTRY winpr_CompleteAuthToken(
PCtxtHandle phContext,
1655 SECURITY_STATUS status = 0;
1657 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1660 return SEC_E_SECPKG_NOT_FOUND;
1662 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1665 return SEC_E_SECPKG_NOT_FOUND;
1667 if (!table->CompleteAuthToken)
1669 WLog_WARN(TAG,
"Security module does not provide an implementation");
1670 return SEC_E_UNSUPPORTED_FUNCTION;
1673 status = table->CompleteAuthToken(phContext, pToken);
1675 if (IsSecurityStatusError(status))
1677 WLog_WARN(TAG,
"CompleteAuthToken status %s [0x%08" PRIX32
"]",
1678 GetSecurityStatusString(status), status);
1684static SECURITY_STATUS SEC_ENTRY winpr_DeleteSecurityContext(
PCtxtHandle phContext)
1686 const char* Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1689 return SEC_E_SECPKG_NOT_FOUND;
1694 return SEC_E_SECPKG_NOT_FOUND;
1696 if (!table->DeleteSecurityContext)
1698 WLog_WARN(TAG,
"Security module does not provide an implementation");
1699 return SEC_E_UNSUPPORTED_FUNCTION;
1702 const SECURITY_STATUS status = table->DeleteSecurityContext(phContext);
1704 if (IsSecurityStatusError(status))
1706 WLog_WARN(TAG,
"DeleteSecurityContext status %s [0x%08" PRIX32
"]",
1707 GetSecurityStatusString(status), status);
1713static SECURITY_STATUS SEC_ENTRY winpr_FreeContextBuffer(
void* pvContextBuffer)
1715 if (!pvContextBuffer)
1716 return SEC_E_INVALID_HANDLE;
1718 sspi_ContextBufferFree(pvContextBuffer);
1722static SECURITY_STATUS SEC_ENTRY winpr_ImpersonateSecurityContext(
PCtxtHandle phContext)
1724 SEC_CHAR* Name = NULL;
1725 SECURITY_STATUS status = 0;
1727 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1730 return SEC_E_SECPKG_NOT_FOUND;
1732 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1735 return SEC_E_SECPKG_NOT_FOUND;
1737 if (!table->ImpersonateSecurityContext)
1739 WLog_WARN(TAG,
"Security module does not provide an implementation");
1740 return SEC_E_UNSUPPORTED_FUNCTION;
1743 status = table->ImpersonateSecurityContext(phContext);
1745 if (IsSecurityStatusError(status))
1747 WLog_WARN(TAG,
"ImpersonateSecurityContext status %s [0x%08" PRIX32
"]",
1748 GetSecurityStatusString(status), status);
1754static SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextW(
1756 ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2,
1759 SEC_CHAR* Name = NULL;
1760 SECURITY_STATUS status = 0;
1762 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phCredential);
1765 return SEC_E_SECPKG_NOT_FOUND;
1767 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1770 return SEC_E_SECPKG_NOT_FOUND;
1772 if (!table->InitializeSecurityContextW)
1774 WLog_WARN(TAG,
"Security module does not provide an implementation");
1775 return SEC_E_UNSUPPORTED_FUNCTION;
1778 status = table->InitializeSecurityContextW(phCredential, phContext, pszTargetName, fContextReq,
1779 Reserved1, TargetDataRep, pInput, Reserved2,
1780 phNewContext, pOutput, pfContextAttr, ptsExpiry);
1782 if (IsSecurityStatusError(status))
1784 WLog_WARN(TAG,
"InitializeSecurityContextW status %s [0x%08" PRIX32
"]",
1785 GetSecurityStatusString(status), status);
1791static SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextA(
1793 ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2,
1796 SEC_CHAR* Name = NULL;
1797 SECURITY_STATUS status = 0;
1799 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phCredential);
1802 return SEC_E_SECPKG_NOT_FOUND;
1804 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1807 return SEC_E_SECPKG_NOT_FOUND;
1809 if (!table->InitializeSecurityContextA)
1811 WLog_WARN(TAG,
"Security module does not provide an implementation");
1812 return SEC_E_UNSUPPORTED_FUNCTION;
1815 status = table->InitializeSecurityContextA(phCredential, phContext, pszTargetName, fContextReq,
1816 Reserved1, TargetDataRep, pInput, Reserved2,
1817 phNewContext, pOutput, pfContextAttr, ptsExpiry);
1819 if (IsSecurityStatusError(status))
1821 WLog_WARN(TAG,
"InitializeSecurityContextA status %s [0x%08" PRIX32
"]",
1822 GetSecurityStatusString(status), status);
1828static SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesW(
PCtxtHandle phContext,
1829 ULONG ulAttribute,
void* pBuffer)
1831 SEC_CHAR* Name = NULL;
1832 SECURITY_STATUS status = 0;
1834 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1837 return SEC_E_SECPKG_NOT_FOUND;
1839 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1842 return SEC_E_SECPKG_NOT_FOUND;
1844 if (!table->QueryContextAttributesW)
1846 WLog_WARN(TAG,
"Security module does not provide an implementation");
1847 return SEC_E_UNSUPPORTED_FUNCTION;
1850 status = table->QueryContextAttributesW(phContext, ulAttribute, pBuffer);
1852 if (IsSecurityStatusError(status))
1854 WLog_WARN(TAG,
"QueryContextAttributesW status %s [0x%08" PRIX32
"]",
1855 GetSecurityStatusString(status), status);
1861static SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesA(
PCtxtHandle phContext,
1862 ULONG ulAttribute,
void* pBuffer)
1864 SEC_CHAR* Name = NULL;
1865 SECURITY_STATUS status = 0;
1867 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1870 return SEC_E_SECPKG_NOT_FOUND;
1872 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1875 return SEC_E_SECPKG_NOT_FOUND;
1877 if (!table->QueryContextAttributesA)
1879 WLog_WARN(TAG,
"Security module does not provide an implementation");
1880 return SEC_E_UNSUPPORTED_FUNCTION;
1883 status = table->QueryContextAttributesA(phContext, ulAttribute, pBuffer);
1885 if (IsSecurityStatusError(status))
1887 WLog_WARN(TAG,
"QueryContextAttributesA status %s [0x%08" PRIX32
"]",
1888 GetSecurityStatusString(status), status);
1894static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityContextToken(
PCtxtHandle phContext,
1897 SEC_CHAR* Name = NULL;
1898 SECURITY_STATUS status = 0;
1900 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1903 return SEC_E_SECPKG_NOT_FOUND;
1905 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1908 return SEC_E_SECPKG_NOT_FOUND;
1910 if (!table->QuerySecurityContextToken)
1912 WLog_WARN(TAG,
"Security module does not provide an implementation");
1913 return SEC_E_UNSUPPORTED_FUNCTION;
1916 status = table->QuerySecurityContextToken(phContext, phToken);
1918 if (IsSecurityStatusError(status))
1920 WLog_WARN(TAG,
"QuerySecurityContextToken status %s [0x%08" PRIX32
"]",
1921 GetSecurityStatusString(status), status);
1927static SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesW(
PCtxtHandle phContext,
1928 ULONG ulAttribute,
void* pBuffer,
1931 SEC_CHAR* Name = NULL;
1932 SECURITY_STATUS status = 0;
1934 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1937 return SEC_E_SECPKG_NOT_FOUND;
1939 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1942 return SEC_E_SECPKG_NOT_FOUND;
1944 if (!table->SetContextAttributesW)
1946 WLog_WARN(TAG,
"Security module does not provide an implementation");
1947 return SEC_E_UNSUPPORTED_FUNCTION;
1950 status = table->SetContextAttributesW(phContext, ulAttribute, pBuffer, cbBuffer);
1952 if (IsSecurityStatusError(status))
1954 WLog_WARN(TAG,
"SetContextAttributesW status %s [0x%08" PRIX32
"]",
1955 GetSecurityStatusString(status), status);
1961static SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesA(
PCtxtHandle phContext,
1962 ULONG ulAttribute,
void* pBuffer,
1966 SECURITY_STATUS status = 0;
1968 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1971 return SEC_E_SECPKG_NOT_FOUND;
1973 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1976 return SEC_E_SECPKG_NOT_FOUND;
1978 if (!table->SetContextAttributesA)
1980 WLog_WARN(TAG,
"Security module does not provide an implementation");
1981 return SEC_E_UNSUPPORTED_FUNCTION;
1984 status = table->SetContextAttributesA(phContext, ulAttribute, pBuffer, cbBuffer);
1986 if (IsSecurityStatusError(status))
1988 WLog_WARN(TAG,
"SetContextAttributesA status %s [0x%08" PRIX32
"]",
1989 GetSecurityStatusString(status), status);
1995static SECURITY_STATUS SEC_ENTRY winpr_RevertSecurityContext(
PCtxtHandle phContext)
1997 SEC_CHAR* Name = NULL;
1998 SECURITY_STATUS status = 0;
2000 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
2003 return SEC_E_SECPKG_NOT_FOUND;
2005 table = sspi_GetSecurityFunctionTableWByNameA(Name);
2008 return SEC_E_SECPKG_NOT_FOUND;
2010 if (!table->RevertSecurityContext)
2012 WLog_WARN(TAG,
"Security module does not provide an implementation");
2013 return SEC_E_UNSUPPORTED_FUNCTION;
2016 status = table->RevertSecurityContext(phContext);
2018 if (IsSecurityStatusError(status))
2020 WLog_WARN(TAG,
"RevertSecurityContext status %s [0x%08" PRIX32
"]",
2021 GetSecurityStatusString(status), status);
2029static SECURITY_STATUS SEC_ENTRY winpr_DecryptMessage(
PCtxtHandle phContext,
2034 SECURITY_STATUS status = 0;
2036 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
2039 return SEC_E_SECPKG_NOT_FOUND;
2041 table = sspi_GetSecurityFunctionTableAByNameA(Name);
2044 return SEC_E_SECPKG_NOT_FOUND;
2046 if (!table->DecryptMessage)
2048 WLog_WARN(TAG,
"Security module does not provide an implementation");
2049 return SEC_E_UNSUPPORTED_FUNCTION;
2052 status = table->DecryptMessage(phContext, pMessage, MessageSeqNo, pfQOP);
2054 if (IsSecurityStatusError(status))
2056 WLog_WARN(TAG,
"DecryptMessage status %s [0x%08" PRIX32
"]",
2057 GetSecurityStatusString(status), status);
2063static SECURITY_STATUS SEC_ENTRY winpr_EncryptMessage(
PCtxtHandle phContext, ULONG fQOP,
2067 SECURITY_STATUS status = 0;
2069 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
2072 return SEC_E_SECPKG_NOT_FOUND;
2074 table = sspi_GetSecurityFunctionTableAByNameA(Name);
2077 return SEC_E_SECPKG_NOT_FOUND;
2079 if (!table->EncryptMessage)
2081 WLog_WARN(TAG,
"Security module does not provide an implementation");
2082 return SEC_E_UNSUPPORTED_FUNCTION;
2085 status = table->EncryptMessage(phContext, fQOP, pMessage, MessageSeqNo);
2087 if (status != SEC_E_OK)
2089 WLog_ERR(TAG,
"EncryptMessage status %s [0x%08" PRIX32
"]", GetSecurityStatusString(status),
2096static SECURITY_STATUS SEC_ENTRY winpr_MakeSignature(
PCtxtHandle phContext, ULONG fQOP,
2100 SECURITY_STATUS status = 0;
2102 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
2105 return SEC_E_SECPKG_NOT_FOUND;
2107 table = sspi_GetSecurityFunctionTableAByNameA(Name);
2110 return SEC_E_SECPKG_NOT_FOUND;
2112 if (!table->MakeSignature)
2114 WLog_WARN(TAG,
"Security module does not provide an implementation");
2115 return SEC_E_UNSUPPORTED_FUNCTION;
2118 status = table->MakeSignature(phContext, fQOP, pMessage, MessageSeqNo);
2120 if (IsSecurityStatusError(status))
2122 WLog_WARN(TAG,
"MakeSignature status %s [0x%08" PRIX32
"]", GetSecurityStatusString(status),
2129static SECURITY_STATUS SEC_ENTRY winpr_VerifySignature(
PCtxtHandle phContext,
2134 SECURITY_STATUS status = 0;
2136 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
2139 return SEC_E_SECPKG_NOT_FOUND;
2141 table = sspi_GetSecurityFunctionTableAByNameA(Name);
2144 return SEC_E_SECPKG_NOT_FOUND;
2146 if (!table->VerifySignature)
2148 WLog_WARN(TAG,
"Security module does not provide an implementation");
2149 return SEC_E_UNSUPPORTED_FUNCTION;
2152 status = table->VerifySignature(phContext, pMessage, MessageSeqNo, pfQOP);
2154 if (IsSecurityStatusError(status))
2156 WLog_WARN(TAG,
"VerifySignature status %s [0x%08" PRIX32
"]",
2157 GetSecurityStatusString(status), status);
2165 winpr_EnumerateSecurityPackagesA,
2166 winpr_QueryCredentialsAttributesA,
2167 winpr_AcquireCredentialsHandleA,
2168 winpr_FreeCredentialsHandle,
2170 winpr_InitializeSecurityContextA,
2171 winpr_AcceptSecurityContext,
2172 winpr_CompleteAuthToken,
2173 winpr_DeleteSecurityContext,
2174 winpr_ApplyControlToken,
2175 winpr_QueryContextAttributesA,
2176 winpr_ImpersonateSecurityContext,
2177 winpr_RevertSecurityContext,
2178 winpr_MakeSignature,
2179 winpr_VerifySignature,
2180 winpr_FreeContextBuffer,
2181 winpr_QuerySecurityPackageInfoA,
2184 winpr_ExportSecurityContext,
2185 winpr_ImportSecurityContextA,
2188 winpr_QuerySecurityContextToken,
2189 winpr_EncryptMessage,
2190 winpr_DecryptMessage,
2191 winpr_SetContextAttributesA,
2192 winpr_SetCredentialsAttributesA,
2197 winpr_EnumerateSecurityPackagesW,
2198 winpr_QueryCredentialsAttributesW,
2199 winpr_AcquireCredentialsHandleW,
2200 winpr_FreeCredentialsHandle,
2202 winpr_InitializeSecurityContextW,
2203 winpr_AcceptSecurityContext,
2204 winpr_CompleteAuthToken,
2205 winpr_DeleteSecurityContext,
2206 winpr_ApplyControlToken,
2207 winpr_QueryContextAttributesW,
2208 winpr_ImpersonateSecurityContext,
2209 winpr_RevertSecurityContext,
2210 winpr_MakeSignature,
2211 winpr_VerifySignature,
2212 winpr_FreeContextBuffer,
2213 winpr_QuerySecurityPackageInfoW,
2216 winpr_ExportSecurityContext,
2217 winpr_ImportSecurityContextW,
2220 winpr_QuerySecurityContextToken,
2221 winpr_EncryptMessage,
2222 winpr_DecryptMessage,
2223 winpr_SetContextAttributesW,
2224 winpr_SetCredentialsAttributesW,
2229 return &winpr_SecurityFunctionTableW;
2234 return &winpr_SecurityFunctionTableA;