21 #include <winpr/config.h>
22 #include <winpr/assert.h>
23 #include <winpr/windows.h>
25 #include <winpr/crt.h>
26 #include <winpr/sspi.h>
27 #include <winpr/ssl.h>
28 #include <winpr/print.h>
32 #include "sspi_winpr.h"
35 #define TAG WINPR_TAG("sspi")
39 #include "NTLM/ntlm.h"
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"
46 static const SecPkgInfoA* SecPkgInfoA_LIST[] = { &NTLM_SecPkgInfoA, &KERBEROS_SecPkgInfoA,
47 &NEGOTIATE_SecPkgInfoA, &CREDSSP_SecPkgInfoA,
48 &SCHANNEL_SecPkgInfoA };
50 static 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;
69 static 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 }
77 static WCHAR BUFFER_NAME_LIST_W[5][32] = { 0 };
79 static 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 }
87 #define SecHandle_LOWER_MAX 0xFFFFFFFF
88 #define SecHandle_UPPER_MAX 0xFFFFFFFE
93 UINT32 allocatorIndex;
94 } CONTEXT_BUFFER_ALLOC_ENTRY;
100 CONTEXT_BUFFER_ALLOC_ENTRY* entries;
101 } CONTEXT_BUFFER_ALLOC_TABLE;
103 static CONTEXT_BUFFER_ALLOC_TABLE ContextBufferAllocTable = { 0 };
105 static int sspi_ContextBufferAllocTableNew(
void)
108 ContextBufferAllocTable.entries = NULL;
109 ContextBufferAllocTable.cEntries = 0;
110 ContextBufferAllocTable.cMaxEntries = 4;
111 size =
sizeof(CONTEXT_BUFFER_ALLOC_ENTRY) * ContextBufferAllocTable.cMaxEntries;
112 ContextBufferAllocTable.entries = (CONTEXT_BUFFER_ALLOC_ENTRY*)calloc(1, size);
114 if (!ContextBufferAllocTable.entries)
120 static int sspi_ContextBufferAllocTableGrow(
void)
123 CONTEXT_BUFFER_ALLOC_ENTRY* entries = NULL;
124 ContextBufferAllocTable.cEntries = 0;
125 ContextBufferAllocTable.cMaxEntries *= 2;
126 size =
sizeof(CONTEXT_BUFFER_ALLOC_ENTRY) * ContextBufferAllocTable.cMaxEntries;
131 entries = (CONTEXT_BUFFER_ALLOC_ENTRY*)realloc(ContextBufferAllocTable.entries, size);
135 free(ContextBufferAllocTable.entries);
139 ContextBufferAllocTable.entries = entries;
140 ZeroMemory((
void*)&ContextBufferAllocTable.entries[ContextBufferAllocTable.cMaxEntries / 2],
145 static void sspi_ContextBufferAllocTableFree(
void)
147 if (ContextBufferAllocTable.cEntries != 0)
148 WLog_ERR(TAG,
"ContextBufferAllocTable.entries == %" PRIu32,
149 ContextBufferAllocTable.cEntries);
151 ContextBufferAllocTable.cEntries = ContextBufferAllocTable.cMaxEntries = 0;
152 free(ContextBufferAllocTable.entries);
153 ContextBufferAllocTable.entries = NULL;
156 static void* sspi_ContextBufferAlloc(UINT32 allocatorIndex,
size_t size)
158 void* contextBuffer = NULL;
160 for (UINT32 index = 0; index < ContextBufferAllocTable.cMaxEntries; index++)
162 if (!ContextBufferAllocTable.entries[index].contextBuffer)
164 contextBuffer = calloc(1, size);
169 ContextBufferAllocTable.cEntries++;
170 ContextBufferAllocTable.entries[index].contextBuffer = contextBuffer;
171 ContextBufferAllocTable.entries[index].allocatorIndex = allocatorIndex;
172 return ContextBufferAllocTable.entries[index].contextBuffer;
178 if (sspi_ContextBufferAllocTableGrow() < 0)
182 return sspi_ContextBufferAlloc(allocatorIndex, size);
194 size_t userLength = 0;
195 size_t domainLength = 0;
196 size_t passwordLength = 0;
201 if (credentials->ntlmSettings.samFile)
202 free(credentials->ntlmSettings.samFile);
204 userLength = credentials->identity.UserLength;
205 domainLength = credentials->identity.DomainLength;
206 passwordLength = credentials->identity.PasswordLength;
208 if (passwordLength > SSPI_CREDENTIALS_HASH_LENGTH_OFFSET)
209 passwordLength -= SSPI_CREDENTIALS_HASH_LENGTH_OFFSET;
211 if (credentials->identity.Flags & SEC_WINNT_AUTH_IDENTITY_UNICODE)
218 if (credentials->identity.User)
219 memset(credentials->identity.User, 0, userLength);
220 if (credentials->identity.Domain)
221 memset(credentials->identity.Domain, 0, domainLength);
222 if (credentials->identity.Password)
223 memset(credentials->identity.Password, 0, passwordLength);
224 free(credentials->identity.User);
225 free(credentials->identity.Domain);
226 free(credentials->identity.Password);
264 SecInvalidateHandle(handle);
268 void* sspi_SecureHandleGetLowerPointer(
SecHandle* handle)
270 void* pointer = NULL;
272 if (!handle || !SecIsValidHandle(handle) || !handle->dwLower)
275 pointer = (
void*)~((
size_t)handle->dwLower);
279 void sspi_SecureHandleInvalidate(
SecHandle* handle)
288 void sspi_SecureHandleSetLowerPointer(
SecHandle* handle,
void* pointer)
293 handle->dwLower = (ULONG_PTR)(~((
size_t)pointer));
296 void* sspi_SecureHandleGetUpperPointer(
SecHandle* handle)
298 void* pointer = NULL;
300 if (!handle || !SecIsValidHandle(handle) || !handle->dwUpper)
303 pointer = (
void*)~((
size_t)handle->dwUpper);
307 void sspi_SecureHandleSetUpperPointer(
SecHandle* handle,
void* pointer)
312 handle->dwUpper = (ULONG_PTR)(~((
size_t)pointer));
315 void sspi_SecureHandleFree(
SecHandle* handle)
320 int sspi_SetAuthIdentityW(SEC_WINNT_AUTH_IDENTITY* identity,
const WCHAR* user,
const WCHAR* domain,
321 const WCHAR* password)
323 return sspi_SetAuthIdentityWithLengthW(identity, user, user ? _wcslen(user) : 0, domain,
324 domain ? _wcslen(domain) : 0, password,
325 password ? _wcslen(password) : 0);
328 static BOOL copy(WCHAR** dst, ULONG* dstLen,
const WCHAR* what,
size_t len)
331 WINPR_ASSERT(dstLen);
336 if (len > UINT32_MAX)
340 if (!what && (len != 0))
342 if (!what && (len == 0))
345 *dst = calloc(
sizeof(WCHAR), len + 1);
349 memcpy(*dst, what, len *
sizeof(WCHAR));
350 *dstLen = (UINT32)len;
354 int sspi_SetAuthIdentityWithLengthW(SEC_WINNT_AUTH_IDENTITY* identity,
const WCHAR* user,
355 size_t userLen,
const WCHAR* domain,
size_t domainLen,
356 const WCHAR* password,
size_t passwordLen)
358 WINPR_ASSERT(identity);
359 sspi_FreeAuthIdentity(identity);
360 identity->Flags &= ~SEC_WINNT_AUTH_IDENTITY_ANSI;
361 identity->Flags |= SEC_WINNT_AUTH_IDENTITY_UNICODE;
363 if (!copy(&identity->User, &identity->UserLength, user, userLen))
366 if (!copy(&identity->Domain, &identity->DomainLength, domain, domainLen))
369 if (!copy(&identity->Password, &identity->PasswordLength, password, passwordLen))
375 static void zfree(WCHAR* str,
size_t len)
378 memset(str, 0, len *
sizeof(WCHAR));
382 int sspi_SetAuthIdentityA(SEC_WINNT_AUTH_IDENTITY* identity,
const char* user,
const char* domain,
383 const char* password)
386 size_t unicodeUserLenW = 0;
387 size_t unicodeDomainLenW = 0;
388 size_t unicodePasswordLenW = 0;
389 LPWSTR unicodeUser = NULL;
390 LPWSTR unicodeDomain = NULL;
391 LPWSTR unicodePassword = NULL;
394 unicodeUser = ConvertUtf8ToWCharAlloc(user, &unicodeUserLenW);
397 unicodeDomain = ConvertUtf8ToWCharAlloc(domain, &unicodeDomainLenW);
400 unicodePassword = ConvertUtf8ToWCharAlloc(password, &unicodePasswordLenW);
402 rc = sspi_SetAuthIdentityWithLengthW(identity, unicodeUser, unicodeUserLenW, unicodeDomain,
403 unicodeDomainLenW, unicodePassword, unicodePasswordLenW);
405 zfree(unicodeUser, unicodeUserLenW);
406 zfree(unicodeDomain, unicodeDomainLenW);
407 zfree(unicodePassword, unicodePasswordLenW);
411 UINT32 sspi_GetAuthIdentityVersion(
const void* identity)
418 version = *((
const UINT32*)identity);
420 if ((version == SEC_WINNT_AUTH_IDENTITY_VERSION) ||
421 (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2))
429 UINT32 sspi_GetAuthIdentityFlags(
const void* identity)
437 version = sspi_GetAuthIdentityVersion(identity);
439 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
441 flags = ((
const SEC_WINNT_AUTH_IDENTITY_EX*)identity)->Flags;
443 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
449 flags = ((
const SEC_WINNT_AUTH_IDENTITY*)identity)->Flags;
455 BOOL sspi_GetAuthIdentityUserDomainW(
const void* identity,
const WCHAR** pUser, UINT32* pUserLength,
456 const WCHAR** pDomain, UINT32* pDomainLength)
463 version = sspi_GetAuthIdentityVersion(identity);
465 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
468 *pUser = (
const WCHAR*)id->User;
469 *pUserLength = id->UserLength;
470 *pDomain = (
const WCHAR*)
id->Domain;
471 *pDomainLength =
id->DomainLength;
473 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
476 UINT32 UserOffset =
id->UserOffset;
477 UINT32 DomainOffset =
id->DomainOffset;
478 *pUser = (
const WCHAR*)&((
const uint8_t*)identity)[UserOffset];
479 *pUserLength =
id->UserLength / 2;
480 *pDomain = (
const WCHAR*)&((
const uint8_t*)identity)[DomainOffset];
481 *pDomainLength =
id->DomainLength / 2;
486 *pUser = (
const WCHAR*)id->User;
487 *pUserLength = id->UserLength;
488 *pDomain = (
const WCHAR*)
id->Domain;
489 *pDomainLength =
id->DomainLength;
495 BOOL sspi_GetAuthIdentityUserDomainA(
const void* identity,
const char** pUser, UINT32* pUserLength,
496 const char** pDomain, UINT32* pDomainLength)
503 version = sspi_GetAuthIdentityVersion(identity);
505 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
508 *pUser = (
const char*)id->User;
509 *pUserLength = id->UserLength;
510 *pDomain = (
const char*)
id->Domain;
511 *pDomainLength =
id->DomainLength;
513 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
516 UINT32 UserOffset =
id->UserOffset;
517 UINT32 DomainOffset =
id->DomainOffset;
518 *pUser = (
const char*)&((
const uint8_t*)identity)[UserOffset];
519 *pUserLength =
id->UserLength;
520 *pDomain = (
const char*)&((
const uint8_t*)identity)[DomainOffset];
521 *pDomainLength =
id->DomainLength;
526 *pUser = (
const char*)id->User;
527 *pUserLength = id->UserLength;
528 *pDomain = (
const char*)
id->Domain;
529 *pDomainLength =
id->DomainLength;
535 BOOL sspi_GetAuthIdentityPasswordW(
const void* identity,
const WCHAR** pPassword,
536 UINT32* pPasswordLength)
543 version = sspi_GetAuthIdentityVersion(identity);
545 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
548 *pPassword = (
const WCHAR*)id->Password;
549 *pPasswordLength = id->PasswordLength;
551 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
558 *pPassword = (
const WCHAR*)id->Password;
559 *pPasswordLength = id->PasswordLength;
565 BOOL sspi_GetAuthIdentityPasswordA(
const void* identity,
const char** pPassword,
566 UINT32* pPasswordLength)
573 version = sspi_GetAuthIdentityVersion(identity);
575 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
578 *pPassword = (
const char*)id->Password;
579 *pPasswordLength = id->PasswordLength;
581 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
588 *pPassword = (
const char*)id->Password;
589 *pPasswordLength = id->PasswordLength;
596 char** pDomain,
char** pPassword)
598 BOOL success = FALSE;
599 const char* UserA = NULL;
600 const char* DomainA = NULL;
601 const char* PasswordA = NULL;
602 const WCHAR* UserW = NULL;
603 const WCHAR* DomainW = NULL;
604 const WCHAR* PasswordW = NULL;
605 UINT32 UserLength = 0;
606 UINT32 DomainLength = 0;
607 UINT32 PasswordLength = 0;
609 if (!identity || !pUser || !pDomain || !pPassword)
612 *pUser = *pDomain = *pPassword = NULL;
614 UINT32 identityFlags = sspi_GetAuthIdentityFlags(identity);
616 if (identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI)
618 if (!sspi_GetAuthIdentityUserDomainA(identity, &UserA, &UserLength, &DomainA,
622 if (!sspi_GetAuthIdentityPasswordA(identity, &PasswordA, &PasswordLength))
625 if (UserA && UserLength)
627 *pUser = _strdup(UserA);
633 if (DomainA && DomainLength)
635 *pDomain = _strdup(DomainA);
641 if (PasswordA && PasswordLength)
643 *pPassword = _strdup(PasswordA);
653 if (!sspi_GetAuthIdentityUserDomainW(identity, &UserW, &UserLength, &DomainW,
657 if (!sspi_GetAuthIdentityPasswordW(identity, &PasswordW, &PasswordLength))
660 if (UserW && (UserLength > 0))
662 *pUser = ConvertWCharNToUtf8Alloc(UserW, UserLength, NULL);
667 if (DomainW && (DomainLength > 0))
669 *pDomain = ConvertWCharNToUtf8Alloc(DomainW, DomainLength, NULL);
674 if (PasswordW && (PasswordLength > 0))
676 *pPassword = ConvertWCharNToUtf8Alloc(PasswordW, PasswordLength, NULL);
689 WCHAR** pDomain, WCHAR** pPassword)
691 BOOL success = FALSE;
692 const char* UserA = NULL;
693 const char* DomainA = NULL;
694 const char* PasswordA = NULL;
695 const WCHAR* UserW = NULL;
696 const WCHAR* DomainW = NULL;
697 const WCHAR* PasswordW = NULL;
698 UINT32 UserLength = 0;
699 UINT32 DomainLength = 0;
700 UINT32 PasswordLength = 0;
702 if (!identity || !pUser || !pDomain || !pPassword)
705 *pUser = *pDomain = *pPassword = NULL;
707 UINT32 identityFlags = sspi_GetAuthIdentityFlags(identity);
709 if (identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI)
711 if (!sspi_GetAuthIdentityUserDomainA(identity, &UserA, &UserLength, &DomainA,
715 if (!sspi_GetAuthIdentityPasswordA(identity, &PasswordA, &PasswordLength))
718 if (UserA && (UserLength > 0))
720 WCHAR* ptr = ConvertUtf8NToWCharAlloc(UserA, UserLength, NULL);
727 if (DomainA && (DomainLength > 0))
729 WCHAR* ptr = ConvertUtf8NToWCharAlloc(DomainA, DomainLength, NULL);
735 if (PasswordA && (PasswordLength > 0))
737 WCHAR* ptr = ConvertUtf8NToWCharAlloc(PasswordA, PasswordLength, NULL);
748 if (!sspi_GetAuthIdentityUserDomainW(identity, &UserW, &UserLength, &DomainW,
752 if (!sspi_GetAuthIdentityPasswordW(identity, &PasswordW, &PasswordLength))
755 if (UserW && UserLength)
757 *pUser = _wcsdup(UserW);
763 if (DomainW && DomainLength)
765 *pDomain = _wcsdup(DomainW);
771 if (PasswordW && PasswordLength)
773 *pPassword = _wcsdup(PasswordW);
789 UINT32 identityFlags = 0;
790 char* PackageList = NULL;
791 const char* PackageListA = NULL;
792 const WCHAR* PackageListW = NULL;
793 UINT32 PackageListLength = 0;
794 UINT32 PackageListOffset = 0;
795 const void* pAuthData = (
const void*)identity;
800 version = sspi_GetAuthIdentityVersion(pAuthData);
801 identityFlags = sspi_GetAuthIdentityFlags(pAuthData);
803 if (identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI)
805 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
808 PackageListA = (
const char*)ad->PackageList;
809 PackageListLength = ad->PackageListLength;
812 if (PackageListA && PackageListLength)
814 PackageList = _strdup(PackageListA);
819 if (version == SEC_WINNT_AUTH_IDENTITY_VERSION)
822 PackageListW = (
const WCHAR*)ad->PackageList;
823 PackageListLength = ad->PackageListLength;
825 else if (version == SEC_WINNT_AUTH_IDENTITY_VERSION_2)
828 PackageListOffset = ad->PackageListOffset;
829 PackageListW = (
const WCHAR*)&((
const uint8_t*)pAuthData)[PackageListOffset];
830 PackageListLength = ad->PackageListLength / 2;
833 if (PackageListW && (PackageListLength > 0))
834 PackageList = ConvertWCharNToUtf8Alloc(PackageListW, PackageListLength, NULL);
839 *pPackageList = PackageList;
846 int sspi_CopyAuthIdentity(SEC_WINNT_AUTH_IDENTITY* identity,
850 UINT32 identityFlags = 0;
851 const char* UserA = NULL;
852 const char* DomainA = NULL;
853 const char* PasswordA = NULL;
854 const WCHAR* UserW = NULL;
855 const WCHAR* DomainW = NULL;
856 const WCHAR* PasswordW = NULL;
857 UINT32 UserLength = 0;
858 UINT32 DomainLength = 0;
859 UINT32 PasswordLength = 0;
861 sspi_FreeAuthIdentity(identity);
863 identityFlags = sspi_GetAuthIdentityFlags(srcIdentity);
865 identity->Flags = identityFlags;
867 if (identityFlags & SEC_WINNT_AUTH_IDENTITY_ANSI)
869 if (!sspi_GetAuthIdentityUserDomainA(srcIdentity, &UserA, &UserLength, &DomainA,
875 if (!sspi_GetAuthIdentityPasswordA(srcIdentity, &PasswordA, &PasswordLength))
880 status = sspi_SetAuthIdentity(identity, UserA, DomainA, PasswordA);
885 identity->Flags &= ~SEC_WINNT_AUTH_IDENTITY_ANSI;
886 identity->Flags |= SEC_WINNT_AUTH_IDENTITY_UNICODE;
890 identity->Flags |= SEC_WINNT_AUTH_IDENTITY_UNICODE;
892 if (!sspi_GetAuthIdentityUserDomainW(srcIdentity, &UserW, &UserLength, &DomainW, &DomainLength))
897 if (!sspi_GetAuthIdentityPasswordW(srcIdentity, &PasswordW, &PasswordLength))
903 identity->UserLength = UserLength;
905 if (identity->UserLength > 0)
907 identity->User = (UINT16*)calloc((identity->UserLength + 1),
sizeof(WCHAR));
912 CopyMemory(identity->User, UserW, identity->UserLength *
sizeof(WCHAR));
913 identity->User[identity->UserLength] = 0;
916 identity->DomainLength = DomainLength;
918 if (identity->DomainLength > 0)
920 identity->Domain = (UINT16*)calloc((identity->DomainLength + 1),
sizeof(WCHAR));
922 if (!identity->Domain)
925 CopyMemory(identity->Domain, DomainW, identity->DomainLength *
sizeof(WCHAR));
926 identity->Domain[identity->DomainLength] = 0;
929 identity->PasswordLength = PasswordLength;
931 if (identity->PasswordLength > SSPI_CREDENTIALS_HASH_LENGTH_OFFSET)
932 identity->PasswordLength -= SSPI_CREDENTIALS_HASH_LENGTH_OFFSET;
936 identity->Password = (UINT16*)calloc((identity->PasswordLength + 1),
sizeof(WCHAR));
938 if (!identity->Password)
941 CopyMemory(identity->Password, PasswordW, identity->PasswordLength *
sizeof(WCHAR));
942 identity->Password[identity->PasswordLength] = 0;
945 identity->PasswordLength = PasswordLength;
954 for (UINT32 index = 0; index < pMessage->cBuffers; index++)
956 if (pMessage->pBuffers[index].BufferType == BufferType)
958 pSecBuffer = &pMessage->pBuffers[index];
966 static BOOL WINPR_init(
void)
969 for (
size_t x = 0; x < ARRAYSIZE(SecurityFunctionTableA_NAME_LIST); x++)
971 const SecurityFunctionTableA_NAME* cur = &SecurityFunctionTableA_NAME_LIST[x];
972 InitializeConstWCharFromUtf8(cur->Name, BUFFER_NAME_LIST_W[x],
973 ARRAYSIZE(BUFFER_NAME_LIST_W[x]));
978 static BOOL CALLBACK sspi_init(
PINIT_ONCE InitOnce, PVOID Parameter, PVOID* Context)
980 winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT);
981 sspi_ContextBufferAllocTableNew();
982 if (!SCHANNEL_init())
984 if (!KERBEROS_init())
990 if (!NEGOTIATE_init())
995 void sspi_GlobalInit(
void)
997 static INIT_ONCE once = INIT_ONCE_STATIC_INIT;
999 InitOnceExecuteOnce(&once, sspi_init, &flags, NULL);
1002 void sspi_GlobalFinish(
void)
1004 sspi_ContextBufferAllocTableFree();
1009 size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1011 for (
size_t index = 0; index < cPackages; index++)
1013 if (strcmp(Name, SecurityFunctionTableA_NAME_LIST[index].Name) == 0)
1015 return SecurityFunctionTableA_NAME_LIST[index].SecurityFunctionTable;
1024 size_t cPackages = ARRAYSIZE(SecPkgInfoW_LIST);
1026 for (
size_t index = 0; index < cPackages; index++)
1028 if (_wcscmp(Name, SecurityFunctionTableW_NAME_LIST[index].Name) == 0)
1030 return SecurityFunctionTableW_NAME_LIST[index].SecurityFunctionTable;
1039 SEC_WCHAR* NameW = NULL;
1045 NameW = ConvertUtf8ToWCharAlloc(Name, NULL);
1050 table = sspi_GetSecurityFunctionTableWByNameW(NameW);
1055 static void FreeContextBuffer_EnumerateSecurityPackages(
void* contextBuffer);
1056 static void FreeContextBuffer_QuerySecurityPackageInfo(
void* contextBuffer);
1058 static void sspi_ContextBufferFree(
void* contextBuffer)
1060 UINT32 allocatorIndex = 0;
1062 for (
size_t index = 0; index < ContextBufferAllocTable.cMaxEntries; index++)
1064 if (contextBuffer == ContextBufferAllocTable.entries[index].contextBuffer)
1066 contextBuffer = ContextBufferAllocTable.entries[index].contextBuffer;
1067 allocatorIndex = ContextBufferAllocTable.entries[index].allocatorIndex;
1068 ContextBufferAllocTable.cEntries--;
1069 ContextBufferAllocTable.entries[index].allocatorIndex = 0;
1070 ContextBufferAllocTable.entries[index].contextBuffer = NULL;
1072 switch (allocatorIndex)
1074 case EnumerateSecurityPackagesIndex:
1075 FreeContextBuffer_EnumerateSecurityPackages(contextBuffer);
1078 case QuerySecurityPackageInfoIndex:
1079 FreeContextBuffer_QuerySecurityPackageInfo(contextBuffer);
1094 static SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesW(ULONG* pcPackages,
1097 const size_t cPackages = ARRAYSIZE(SecPkgInfoW_LIST);
1098 const size_t size =
sizeof(
SecPkgInfoW) * cPackages;
1100 (
SecPkgInfoW*)sspi_ContextBufferAlloc(EnumerateSecurityPackagesIndex, size);
1102 WINPR_ASSERT(cPackages <= UINT32_MAX);
1105 return SEC_E_INSUFFICIENT_MEMORY;
1107 for (
size_t index = 0; index < cPackages; index++)
1109 pPackageInfo[index].fCapabilities = SecPkgInfoW_LIST[index]->fCapabilities;
1110 pPackageInfo[index].wVersion = SecPkgInfoW_LIST[index]->wVersion;
1111 pPackageInfo[index].wRPCID = SecPkgInfoW_LIST[index]->wRPCID;
1112 pPackageInfo[index].cbMaxToken = SecPkgInfoW_LIST[index]->cbMaxToken;
1113 pPackageInfo[index].Name = _wcsdup(SecPkgInfoW_LIST[index]->Name);
1114 pPackageInfo[index].Comment = _wcsdup(SecPkgInfoW_LIST[index]->Comment);
1117 *(pcPackages) = (UINT32)cPackages;
1118 *(ppPackageInfo) = pPackageInfo;
1122 static SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesA(ULONG* pcPackages,
1125 const size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1126 const size_t size =
sizeof(
SecPkgInfoA) * cPackages;
1128 (
SecPkgInfoA*)sspi_ContextBufferAlloc(EnumerateSecurityPackagesIndex, size);
1130 WINPR_ASSERT(cPackages <= UINT32_MAX);
1133 return SEC_E_INSUFFICIENT_MEMORY;
1135 for (
size_t index = 0; index < cPackages; index++)
1137 pPackageInfo[index].fCapabilities = SecPkgInfoA_LIST[index]->fCapabilities;
1138 pPackageInfo[index].wVersion = SecPkgInfoA_LIST[index]->wVersion;
1139 pPackageInfo[index].wRPCID = SecPkgInfoA_LIST[index]->wRPCID;
1140 pPackageInfo[index].cbMaxToken = SecPkgInfoA_LIST[index]->cbMaxToken;
1141 pPackageInfo[index].Name = _strdup(SecPkgInfoA_LIST[index]->Name);
1142 pPackageInfo[index].Comment = _strdup(SecPkgInfoA_LIST[index]->Comment);
1144 if (!pPackageInfo[index].Name || !pPackageInfo[index].Comment)
1146 sspi_ContextBufferFree(pPackageInfo);
1147 return SEC_E_INSUFFICIENT_MEMORY;
1151 *(pcPackages) = (UINT32)cPackages;
1152 *(ppPackageInfo) = pPackageInfo;
1156 static void FreeContextBuffer_EnumerateSecurityPackages(
void* contextBuffer)
1159 size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1164 for (
size_t index = 0; index < cPackages; index++)
1166 free(pPackageInfo[index].Name);
1167 free(pPackageInfo[index].Comment);
1175 return &winpr_SecurityFunctionTableW;
1180 return &winpr_SecurityFunctionTableA;
1183 static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoW(SEC_WCHAR* pszPackageName,
1186 size_t cPackages = ARRAYSIZE(SecPkgInfoW_LIST);
1188 for (
size_t index = 0; index < cPackages; index++)
1190 if (_wcscmp(pszPackageName, SecPkgInfoW_LIST[index]->Name) == 0)
1194 (
SecPkgInfoW*)sspi_ContextBufferAlloc(QuerySecurityPackageInfoIndex, size);
1197 return SEC_E_INSUFFICIENT_MEMORY;
1199 pPackageInfo->fCapabilities = SecPkgInfoW_LIST[index]->fCapabilities;
1200 pPackageInfo->wVersion = SecPkgInfoW_LIST[index]->wVersion;
1201 pPackageInfo->wRPCID = SecPkgInfoW_LIST[index]->wRPCID;
1202 pPackageInfo->cbMaxToken = SecPkgInfoW_LIST[index]->cbMaxToken;
1203 pPackageInfo->Name = _wcsdup(SecPkgInfoW_LIST[index]->Name);
1204 pPackageInfo->Comment = _wcsdup(SecPkgInfoW_LIST[index]->Comment);
1205 *(ppPackageInfo) = pPackageInfo;
1210 *(ppPackageInfo) = NULL;
1211 return SEC_E_SECPKG_NOT_FOUND;
1214 static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoA(SEC_CHAR* pszPackageName,
1217 size_t cPackages = ARRAYSIZE(SecPkgInfoA_LIST);
1219 for (
size_t index = 0; index < cPackages; index++)
1221 if (strcmp(pszPackageName, SecPkgInfoA_LIST[index]->Name) == 0)
1225 (
SecPkgInfoA*)sspi_ContextBufferAlloc(QuerySecurityPackageInfoIndex, size);
1228 return SEC_E_INSUFFICIENT_MEMORY;
1230 pPackageInfo->fCapabilities = SecPkgInfoA_LIST[index]->fCapabilities;
1231 pPackageInfo->wVersion = SecPkgInfoA_LIST[index]->wVersion;
1232 pPackageInfo->wRPCID = SecPkgInfoA_LIST[index]->wRPCID;
1233 pPackageInfo->cbMaxToken = SecPkgInfoA_LIST[index]->cbMaxToken;
1234 pPackageInfo->Name = _strdup(SecPkgInfoA_LIST[index]->Name);
1235 pPackageInfo->Comment = _strdup(SecPkgInfoA_LIST[index]->Comment);
1237 if (!pPackageInfo->Name || !pPackageInfo->Comment)
1239 sspi_ContextBufferFree(pPackageInfo);
1240 return SEC_E_INSUFFICIENT_MEMORY;
1243 *(ppPackageInfo) = pPackageInfo;
1248 *(ppPackageInfo) = NULL;
1249 return SEC_E_SECPKG_NOT_FOUND;
1252 void FreeContextBuffer_QuerySecurityPackageInfo(
void* contextBuffer)
1254 SecPkgInfo* pPackageInfo = (SecPkgInfo*)contextBuffer;
1259 free(pPackageInfo->Name);
1260 free(pPackageInfo->Comment);
1266 static SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleW(
1267 SEC_WCHAR* pszPrincipal, SEC_WCHAR* pszPackage, ULONG fCredentialUse,
void* pvLogonID,
1268 void* pAuthData, SEC_GET_KEY_FN pGetKeyFn,
void* pvGetKeyArgument,
PCredHandle phCredential,
1271 SECURITY_STATUS status = 0;
1275 return SEC_E_SECPKG_NOT_FOUND;
1277 if (!table->AcquireCredentialsHandleW)
1279 WLog_WARN(TAG,
"Security module does not provide an implementation");
1280 return SEC_E_UNSUPPORTED_FUNCTION;
1283 status = table->AcquireCredentialsHandleW(pszPrincipal, pszPackage, fCredentialUse, pvLogonID,
1284 pAuthData, pGetKeyFn, pvGetKeyArgument, phCredential,
1287 if (IsSecurityStatusError(status))
1289 WLog_WARN(TAG,
"AcquireCredentialsHandleW status %s [0x%08" PRIX32
"]",
1290 GetSecurityStatusString(status), status);
1296 static SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleA(
1297 SEC_CHAR* pszPrincipal, SEC_CHAR* pszPackage, ULONG fCredentialUse,
void* pvLogonID,
1298 void* pAuthData, SEC_GET_KEY_FN pGetKeyFn,
void* pvGetKeyArgument,
PCredHandle phCredential,
1301 SECURITY_STATUS status = 0;
1305 return SEC_E_SECPKG_NOT_FOUND;
1307 if (!table->AcquireCredentialsHandleA)
1309 WLog_WARN(TAG,
"Security module does not provide an implementation");
1310 return SEC_E_UNSUPPORTED_FUNCTION;
1313 status = table->AcquireCredentialsHandleA(pszPrincipal, pszPackage, fCredentialUse, pvLogonID,
1314 pAuthData, pGetKeyFn, pvGetKeyArgument, phCredential,
1317 if (IsSecurityStatusError(status))
1319 WLog_WARN(TAG,
"AcquireCredentialsHandleA status %s [0x%08" PRIX32
"]",
1320 GetSecurityStatusString(status), status);
1326 static SECURITY_STATUS SEC_ENTRY winpr_ExportSecurityContext(
PCtxtHandle phContext, ULONG fFlags,
1330 SEC_CHAR* Name = NULL;
1331 SECURITY_STATUS status = 0;
1333 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1336 return SEC_E_SECPKG_NOT_FOUND;
1338 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1341 return SEC_E_SECPKG_NOT_FOUND;
1343 if (!table->ExportSecurityContext)
1345 WLog_WARN(TAG,
"Security module does not provide an implementation");
1346 return SEC_E_UNSUPPORTED_FUNCTION;
1349 status = table->ExportSecurityContext(phContext, fFlags, pPackedContext, pToken);
1351 if (IsSecurityStatusError(status))
1353 WLog_WARN(TAG,
"ExportSecurityContext status %s [0x%08" PRIX32
"]",
1354 GetSecurityStatusString(status), status);
1360 static SECURITY_STATUS SEC_ENTRY winpr_FreeCredentialsHandle(
PCredHandle phCredential)
1363 SECURITY_STATUS status = 0;
1365 Name = (
char*)sspi_SecureHandleGetUpperPointer(phCredential);
1368 return SEC_E_SECPKG_NOT_FOUND;
1370 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1373 return SEC_E_SECPKG_NOT_FOUND;
1375 if (!table->FreeCredentialsHandle)
1377 WLog_WARN(TAG,
"Security module does not provide an implementation");
1378 return SEC_E_UNSUPPORTED_FUNCTION;
1381 status = table->FreeCredentialsHandle(phCredential);
1383 if (IsSecurityStatusError(status))
1385 WLog_WARN(TAG,
"FreeCredentialsHandle status %s [0x%08" PRIX32
"]",
1386 GetSecurityStatusString(status), status);
1392 static SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextW(SEC_WCHAR* pszPackage,
1396 SEC_CHAR* Name = NULL;
1397 SECURITY_STATUS status = 0;
1399 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1402 return SEC_E_SECPKG_NOT_FOUND;
1404 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1407 return SEC_E_SECPKG_NOT_FOUND;
1409 if (!table->ImportSecurityContextW)
1411 WLog_WARN(TAG,
"Security module does not provide an implementation");
1412 return SEC_E_UNSUPPORTED_FUNCTION;
1415 status = table->ImportSecurityContextW(pszPackage, pPackedContext, pToken, phContext);
1417 if (IsSecurityStatusError(status))
1419 WLog_WARN(TAG,
"ImportSecurityContextW status %s [0x%08" PRIX32
"]",
1420 GetSecurityStatusString(status), status);
1426 static SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextA(SEC_CHAR* pszPackage,
1431 SECURITY_STATUS status = 0;
1433 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1436 return SEC_E_SECPKG_NOT_FOUND;
1438 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1441 return SEC_E_SECPKG_NOT_FOUND;
1443 if (!table->ImportSecurityContextA)
1445 WLog_WARN(TAG,
"Security module does not provide an implementation");
1446 return SEC_E_UNSUPPORTED_FUNCTION;
1449 status = table->ImportSecurityContextA(pszPackage, pPackedContext, pToken, phContext);
1451 if (IsSecurityStatusError(status))
1453 WLog_WARN(TAG,
"ImportSecurityContextA status %s [0x%08" PRIX32
"]",
1454 GetSecurityStatusString(status), status);
1460 static SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesW(
PCredHandle phCredential,
1461 ULONG ulAttribute,
void* pBuffer)
1463 SEC_WCHAR* Name = NULL;
1464 SECURITY_STATUS status = 0;
1466 Name = (SEC_WCHAR*)sspi_SecureHandleGetUpperPointer(phCredential);
1469 return SEC_E_SECPKG_NOT_FOUND;
1471 table = sspi_GetSecurityFunctionTableWByNameW(Name);
1474 return SEC_E_SECPKG_NOT_FOUND;
1476 if (!table->QueryCredentialsAttributesW)
1478 WLog_WARN(TAG,
"Security module does not provide an implementation");
1479 return SEC_E_UNSUPPORTED_FUNCTION;
1482 status = table->QueryCredentialsAttributesW(phCredential, ulAttribute, pBuffer);
1484 if (IsSecurityStatusError(status))
1486 WLog_WARN(TAG,
"QueryCredentialsAttributesW status %s [0x%08" PRIX32
"]",
1487 GetSecurityStatusString(status), status);
1493 static SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesA(
PCredHandle phCredential,
1494 ULONG ulAttribute,
void* pBuffer)
1497 SECURITY_STATUS status = 0;
1499 Name = (
char*)sspi_SecureHandleGetUpperPointer(phCredential);
1502 return SEC_E_SECPKG_NOT_FOUND;
1504 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1507 return SEC_E_SECPKG_NOT_FOUND;
1509 if (!table->QueryCredentialsAttributesA)
1511 WLog_WARN(TAG,
"Security module does not provide an implementation");
1512 return SEC_E_UNSUPPORTED_FUNCTION;
1515 status = table->QueryCredentialsAttributesA(phCredential, ulAttribute, pBuffer);
1517 if (IsSecurityStatusError(status))
1519 WLog_WARN(TAG,
"QueryCredentialsAttributesA status %s [0x%08" PRIX32
"]",
1520 GetSecurityStatusString(status), status);
1526 static SECURITY_STATUS SEC_ENTRY winpr_SetCredentialsAttributesW(
PCredHandle phCredential,
1527 ULONG ulAttribute,
void* pBuffer,
1530 SEC_WCHAR* Name = NULL;
1531 SECURITY_STATUS status = 0;
1533 Name = (SEC_WCHAR*)sspi_SecureHandleGetUpperPointer(phCredential);
1536 return SEC_E_SECPKG_NOT_FOUND;
1538 table = sspi_GetSecurityFunctionTableWByNameW(Name);
1541 return SEC_E_SECPKG_NOT_FOUND;
1543 if (!table->SetCredentialsAttributesW)
1545 WLog_WARN(TAG,
"Security module does not provide an implementation");
1546 return SEC_E_UNSUPPORTED_FUNCTION;
1549 status = table->SetCredentialsAttributesW(phCredential, ulAttribute, pBuffer, cbBuffer);
1551 if (IsSecurityStatusError(status))
1553 WLog_WARN(TAG,
"SetCredentialsAttributesW status %s [0x%08" PRIX32
"]",
1554 GetSecurityStatusString(status), status);
1560 static SECURITY_STATUS SEC_ENTRY winpr_SetCredentialsAttributesA(
PCredHandle phCredential,
1561 ULONG ulAttribute,
void* pBuffer,
1565 SECURITY_STATUS status = 0;
1567 Name = (
char*)sspi_SecureHandleGetUpperPointer(phCredential);
1570 return SEC_E_SECPKG_NOT_FOUND;
1572 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1575 return SEC_E_SECPKG_NOT_FOUND;
1577 if (!table->SetCredentialsAttributesA)
1579 WLog_WARN(TAG,
"Security module does not provide an implementation");
1580 return SEC_E_UNSUPPORTED_FUNCTION;
1583 status = table->SetCredentialsAttributesA(phCredential, ulAttribute, pBuffer, cbBuffer);
1585 if (IsSecurityStatusError(status))
1587 WLog_WARN(TAG,
"SetCredentialsAttributesA status %s [0x%08" PRIX32
"]",
1588 GetSecurityStatusString(status), status);
1596 static SECURITY_STATUS SEC_ENTRY
1598 ULONG fContextReq, ULONG TargetDataRep,
PCtxtHandle phNewContext,
1602 SECURITY_STATUS status = 0;
1604 Name = (
char*)sspi_SecureHandleGetUpperPointer(phCredential);
1607 return SEC_E_SECPKG_NOT_FOUND;
1609 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1612 return SEC_E_SECPKG_NOT_FOUND;
1614 if (!table->AcceptSecurityContext)
1616 WLog_WARN(TAG,
"Security module does not provide an implementation");
1617 return SEC_E_UNSUPPORTED_FUNCTION;
1621 table->AcceptSecurityContext(phCredential, phContext, pInput, fContextReq, TargetDataRep,
1622 phNewContext, pOutput, pfContextAttr, ptsTimeStamp);
1624 if (IsSecurityStatusError(status))
1626 WLog_WARN(TAG,
"AcceptSecurityContext status %s [0x%08" PRIX32
"]",
1627 GetSecurityStatusString(status), status);
1633 static SECURITY_STATUS SEC_ENTRY winpr_ApplyControlToken(
PCtxtHandle phContext,
1637 SECURITY_STATUS status = 0;
1639 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1642 return SEC_E_SECPKG_NOT_FOUND;
1644 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1647 return SEC_E_SECPKG_NOT_FOUND;
1649 if (!table->ApplyControlToken)
1651 WLog_WARN(TAG,
"Security module does not provide an implementation");
1652 return SEC_E_UNSUPPORTED_FUNCTION;
1655 status = table->ApplyControlToken(phContext, pInput);
1657 if (IsSecurityStatusError(status))
1659 WLog_WARN(TAG,
"ApplyControlToken status %s [0x%08" PRIX32
"]",
1660 GetSecurityStatusString(status), status);
1666 static SECURITY_STATUS SEC_ENTRY winpr_CompleteAuthToken(
PCtxtHandle phContext,
1670 SECURITY_STATUS status = 0;
1672 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1675 return SEC_E_SECPKG_NOT_FOUND;
1677 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1680 return SEC_E_SECPKG_NOT_FOUND;
1682 if (!table->CompleteAuthToken)
1684 WLog_WARN(TAG,
"Security module does not provide an implementation");
1685 return SEC_E_UNSUPPORTED_FUNCTION;
1688 status = table->CompleteAuthToken(phContext, pToken);
1690 if (IsSecurityStatusError(status))
1692 WLog_WARN(TAG,
"CompleteAuthToken status %s [0x%08" PRIX32
"]",
1693 GetSecurityStatusString(status), status);
1699 static SECURITY_STATUS SEC_ENTRY winpr_DeleteSecurityContext(
PCtxtHandle phContext)
1701 const char* Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1704 return SEC_E_SECPKG_NOT_FOUND;
1709 return SEC_E_SECPKG_NOT_FOUND;
1711 if (!table->DeleteSecurityContext)
1713 WLog_WARN(TAG,
"Security module does not provide an implementation");
1714 return SEC_E_UNSUPPORTED_FUNCTION;
1717 const SECURITY_STATUS status = table->DeleteSecurityContext(phContext);
1719 if (IsSecurityStatusError(status))
1721 WLog_WARN(TAG,
"DeleteSecurityContext status %s [0x%08" PRIX32
"]",
1722 GetSecurityStatusString(status), status);
1728 static SECURITY_STATUS SEC_ENTRY winpr_FreeContextBuffer(
void* pvContextBuffer)
1730 if (!pvContextBuffer)
1731 return SEC_E_INVALID_HANDLE;
1733 sspi_ContextBufferFree(pvContextBuffer);
1737 static SECURITY_STATUS SEC_ENTRY winpr_ImpersonateSecurityContext(
PCtxtHandle phContext)
1739 SEC_CHAR* Name = NULL;
1740 SECURITY_STATUS status = 0;
1742 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1745 return SEC_E_SECPKG_NOT_FOUND;
1747 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1750 return SEC_E_SECPKG_NOT_FOUND;
1752 if (!table->ImpersonateSecurityContext)
1754 WLog_WARN(TAG,
"Security module does not provide an implementation");
1755 return SEC_E_UNSUPPORTED_FUNCTION;
1758 status = table->ImpersonateSecurityContext(phContext);
1760 if (IsSecurityStatusError(status))
1762 WLog_WARN(TAG,
"ImpersonateSecurityContext status %s [0x%08" PRIX32
"]",
1763 GetSecurityStatusString(status), status);
1769 static SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextW(
1771 ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2,
1774 SEC_CHAR* Name = NULL;
1775 SECURITY_STATUS status = 0;
1777 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phCredential);
1780 return SEC_E_SECPKG_NOT_FOUND;
1782 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1785 return SEC_E_SECPKG_NOT_FOUND;
1787 if (!table->InitializeSecurityContextW)
1789 WLog_WARN(TAG,
"Security module does not provide an implementation");
1790 return SEC_E_UNSUPPORTED_FUNCTION;
1793 status = table->InitializeSecurityContextW(phCredential, phContext, pszTargetName, fContextReq,
1794 Reserved1, TargetDataRep, pInput, Reserved2,
1795 phNewContext, pOutput, pfContextAttr, ptsExpiry);
1797 if (IsSecurityStatusError(status))
1799 WLog_WARN(TAG,
"InitializeSecurityContextW status %s [0x%08" PRIX32
"]",
1800 GetSecurityStatusString(status), status);
1806 static SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextA(
1808 ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pInput, ULONG Reserved2,
1811 SEC_CHAR* Name = NULL;
1812 SECURITY_STATUS status = 0;
1814 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phCredential);
1817 return SEC_E_SECPKG_NOT_FOUND;
1819 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1822 return SEC_E_SECPKG_NOT_FOUND;
1824 if (!table->InitializeSecurityContextA)
1826 WLog_WARN(TAG,
"Security module does not provide an implementation");
1827 return SEC_E_UNSUPPORTED_FUNCTION;
1830 status = table->InitializeSecurityContextA(phCredential, phContext, pszTargetName, fContextReq,
1831 Reserved1, TargetDataRep, pInput, Reserved2,
1832 phNewContext, pOutput, pfContextAttr, ptsExpiry);
1834 if (IsSecurityStatusError(status))
1836 WLog_WARN(TAG,
"InitializeSecurityContextA status %s [0x%08" PRIX32
"]",
1837 GetSecurityStatusString(status), status);
1843 static SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesW(
PCtxtHandle phContext,
1844 ULONG ulAttribute,
void* pBuffer)
1846 SEC_CHAR* Name = NULL;
1847 SECURITY_STATUS status = 0;
1849 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1852 return SEC_E_SECPKG_NOT_FOUND;
1854 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1857 return SEC_E_SECPKG_NOT_FOUND;
1859 if (!table->QueryContextAttributesW)
1861 WLog_WARN(TAG,
"Security module does not provide an implementation");
1862 return SEC_E_UNSUPPORTED_FUNCTION;
1865 status = table->QueryContextAttributesW(phContext, ulAttribute, pBuffer);
1867 if (IsSecurityStatusError(status))
1869 WLog_WARN(TAG,
"QueryContextAttributesW status %s [0x%08" PRIX32
"]",
1870 GetSecurityStatusString(status), status);
1876 static SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesA(
PCtxtHandle phContext,
1877 ULONG ulAttribute,
void* pBuffer)
1879 SEC_CHAR* Name = NULL;
1880 SECURITY_STATUS status = 0;
1882 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1885 return SEC_E_SECPKG_NOT_FOUND;
1887 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1890 return SEC_E_SECPKG_NOT_FOUND;
1892 if (!table->QueryContextAttributesA)
1894 WLog_WARN(TAG,
"Security module does not provide an implementation");
1895 return SEC_E_UNSUPPORTED_FUNCTION;
1898 status = table->QueryContextAttributesA(phContext, ulAttribute, pBuffer);
1900 if (IsSecurityStatusError(status))
1902 WLog_WARN(TAG,
"QueryContextAttributesA status %s [0x%08" PRIX32
"]",
1903 GetSecurityStatusString(status), status);
1909 static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityContextToken(
PCtxtHandle phContext,
1912 SEC_CHAR* Name = NULL;
1913 SECURITY_STATUS status = 0;
1915 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1918 return SEC_E_SECPKG_NOT_FOUND;
1920 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1923 return SEC_E_SECPKG_NOT_FOUND;
1925 if (!table->QuerySecurityContextToken)
1927 WLog_WARN(TAG,
"Security module does not provide an implementation");
1928 return SEC_E_UNSUPPORTED_FUNCTION;
1931 status = table->QuerySecurityContextToken(phContext, phToken);
1933 if (IsSecurityStatusError(status))
1935 WLog_WARN(TAG,
"QuerySecurityContextToken status %s [0x%08" PRIX32
"]",
1936 GetSecurityStatusString(status), status);
1942 static SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesW(
PCtxtHandle phContext,
1943 ULONG ulAttribute,
void* pBuffer,
1946 SEC_CHAR* Name = NULL;
1947 SECURITY_STATUS status = 0;
1949 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
1952 return SEC_E_SECPKG_NOT_FOUND;
1954 table = sspi_GetSecurityFunctionTableWByNameA(Name);
1957 return SEC_E_SECPKG_NOT_FOUND;
1959 if (!table->SetContextAttributesW)
1961 WLog_WARN(TAG,
"Security module does not provide an implementation");
1962 return SEC_E_UNSUPPORTED_FUNCTION;
1965 status = table->SetContextAttributesW(phContext, ulAttribute, pBuffer, cbBuffer);
1967 if (IsSecurityStatusError(status))
1969 WLog_WARN(TAG,
"SetContextAttributesW status %s [0x%08" PRIX32
"]",
1970 GetSecurityStatusString(status), status);
1976 static SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesA(
PCtxtHandle phContext,
1977 ULONG ulAttribute,
void* pBuffer,
1981 SECURITY_STATUS status = 0;
1983 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
1986 return SEC_E_SECPKG_NOT_FOUND;
1988 table = sspi_GetSecurityFunctionTableAByNameA(Name);
1991 return SEC_E_SECPKG_NOT_FOUND;
1993 if (!table->SetContextAttributesA)
1995 WLog_WARN(TAG,
"Security module does not provide an implementation");
1996 return SEC_E_UNSUPPORTED_FUNCTION;
1999 status = table->SetContextAttributesA(phContext, ulAttribute, pBuffer, cbBuffer);
2001 if (IsSecurityStatusError(status))
2003 WLog_WARN(TAG,
"SetContextAttributesA status %s [0x%08" PRIX32
"]",
2004 GetSecurityStatusString(status), status);
2010 static SECURITY_STATUS SEC_ENTRY winpr_RevertSecurityContext(
PCtxtHandle phContext)
2012 SEC_CHAR* Name = NULL;
2013 SECURITY_STATUS status = 0;
2015 Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
2018 return SEC_E_SECPKG_NOT_FOUND;
2020 table = sspi_GetSecurityFunctionTableWByNameA(Name);
2023 return SEC_E_SECPKG_NOT_FOUND;
2025 if (!table->RevertSecurityContext)
2027 WLog_WARN(TAG,
"Security module does not provide an implementation");
2028 return SEC_E_UNSUPPORTED_FUNCTION;
2031 status = table->RevertSecurityContext(phContext);
2033 if (IsSecurityStatusError(status))
2035 WLog_WARN(TAG,
"RevertSecurityContext status %s [0x%08" PRIX32
"]",
2036 GetSecurityStatusString(status), status);
2044 static SECURITY_STATUS SEC_ENTRY winpr_DecryptMessage(
PCtxtHandle phContext,
2049 SECURITY_STATUS status = 0;
2051 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
2054 return SEC_E_SECPKG_NOT_FOUND;
2056 table = sspi_GetSecurityFunctionTableAByNameA(Name);
2059 return SEC_E_SECPKG_NOT_FOUND;
2061 if (!table->DecryptMessage)
2063 WLog_WARN(TAG,
"Security module does not provide an implementation");
2064 return SEC_E_UNSUPPORTED_FUNCTION;
2067 status = table->DecryptMessage(phContext, pMessage, MessageSeqNo, pfQOP);
2069 if (IsSecurityStatusError(status))
2071 WLog_WARN(TAG,
"DecryptMessage status %s [0x%08" PRIX32
"]",
2072 GetSecurityStatusString(status), status);
2078 static SECURITY_STATUS SEC_ENTRY winpr_EncryptMessage(
PCtxtHandle phContext, ULONG fQOP,
2082 SECURITY_STATUS status = 0;
2084 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
2087 return SEC_E_SECPKG_NOT_FOUND;
2089 table = sspi_GetSecurityFunctionTableAByNameA(Name);
2092 return SEC_E_SECPKG_NOT_FOUND;
2094 if (!table->EncryptMessage)
2096 WLog_WARN(TAG,
"Security module does not provide an implementation");
2097 return SEC_E_UNSUPPORTED_FUNCTION;
2100 status = table->EncryptMessage(phContext, fQOP, pMessage, MessageSeqNo);
2102 if (status != SEC_E_OK)
2104 WLog_ERR(TAG,
"EncryptMessage status %s [0x%08" PRIX32
"]", GetSecurityStatusString(status),
2111 static SECURITY_STATUS SEC_ENTRY winpr_MakeSignature(
PCtxtHandle phContext, ULONG fQOP,
2115 SECURITY_STATUS status = 0;
2117 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
2120 return SEC_E_SECPKG_NOT_FOUND;
2122 table = sspi_GetSecurityFunctionTableAByNameA(Name);
2125 return SEC_E_SECPKG_NOT_FOUND;
2127 if (!table->MakeSignature)
2129 WLog_WARN(TAG,
"Security module does not provide an implementation");
2130 return SEC_E_UNSUPPORTED_FUNCTION;
2133 status = table->MakeSignature(phContext, fQOP, pMessage, MessageSeqNo);
2135 if (IsSecurityStatusError(status))
2137 WLog_WARN(TAG,
"MakeSignature status %s [0x%08" PRIX32
"]", GetSecurityStatusString(status),
2144 static SECURITY_STATUS SEC_ENTRY winpr_VerifySignature(
PCtxtHandle phContext,
2149 SECURITY_STATUS status = 0;
2151 Name = (
char*)sspi_SecureHandleGetUpperPointer(phContext);
2154 return SEC_E_SECPKG_NOT_FOUND;
2156 table = sspi_GetSecurityFunctionTableAByNameA(Name);
2159 return SEC_E_SECPKG_NOT_FOUND;
2161 if (!table->VerifySignature)
2163 WLog_WARN(TAG,
"Security module does not provide an implementation");
2164 return SEC_E_UNSUPPORTED_FUNCTION;
2167 status = table->VerifySignature(phContext, pMessage, MessageSeqNo, pfQOP);
2169 if (IsSecurityStatusError(status))
2171 WLog_WARN(TAG,
"VerifySignature status %s [0x%08" PRIX32
"]",
2172 GetSecurityStatusString(status), status);
2180 winpr_EnumerateSecurityPackagesA,
2181 winpr_QueryCredentialsAttributesA,
2182 winpr_AcquireCredentialsHandleA,
2183 winpr_FreeCredentialsHandle,
2185 winpr_InitializeSecurityContextA,
2186 winpr_AcceptSecurityContext,
2187 winpr_CompleteAuthToken,
2188 winpr_DeleteSecurityContext,
2189 winpr_ApplyControlToken,
2190 winpr_QueryContextAttributesA,
2191 winpr_ImpersonateSecurityContext,
2192 winpr_RevertSecurityContext,
2193 winpr_MakeSignature,
2194 winpr_VerifySignature,
2195 winpr_FreeContextBuffer,
2196 winpr_QuerySecurityPackageInfoA,
2199 winpr_ExportSecurityContext,
2200 winpr_ImportSecurityContextA,
2203 winpr_QuerySecurityContextToken,
2204 winpr_EncryptMessage,
2205 winpr_DecryptMessage,
2206 winpr_SetContextAttributesA,
2207 winpr_SetCredentialsAttributesA,
2212 winpr_EnumerateSecurityPackagesW,
2213 winpr_QueryCredentialsAttributesW,
2214 winpr_AcquireCredentialsHandleW,
2215 winpr_FreeCredentialsHandle,
2217 winpr_InitializeSecurityContextW,
2218 winpr_AcceptSecurityContext,
2219 winpr_CompleteAuthToken,
2220 winpr_DeleteSecurityContext,
2221 winpr_ApplyControlToken,
2222 winpr_QueryContextAttributesW,
2223 winpr_ImpersonateSecurityContext,
2224 winpr_RevertSecurityContext,
2225 winpr_MakeSignature,
2226 winpr_VerifySignature,
2227 winpr_FreeContextBuffer,
2228 winpr_QuerySecurityPackageInfoW,
2231 winpr_ExportSecurityContext,
2232 winpr_ImportSecurityContextW,
2235 winpr_QuerySecurityContextToken,
2236 winpr_EncryptMessage,
2237 winpr_DecryptMessage,
2238 winpr_SetContextAttributesW,
2239 winpr_SetCredentialsAttributesW,