2014-06-06 06:54:31 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* Security Support Provider Interface (SSPI)
|
|
|
|
*
|
|
|
|
* Copyright 2012-2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2017-05-11 19:51:45 +03:00
|
|
|
* Copyright 2017 Dorian Ducournau <dorian.ducournau@gmail.com>
|
2014-06-06 06:54:31 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 12:08:00 +03:00
|
|
|
#include <winpr/config.h>
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
#include <winpr/windows.h>
|
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/sspi.h>
|
2014-07-28 23:55:57 +04:00
|
|
|
#include <winpr/ssl.h>
|
2014-06-06 06:54:31 +04:00
|
|
|
#include <winpr/print.h>
|
|
|
|
|
|
|
|
#include "sspi.h"
|
|
|
|
|
|
|
|
#include "sspi_winpr.h"
|
|
|
|
|
2015-07-07 18:17:29 +03:00
|
|
|
#include "../log.h"
|
|
|
|
#define TAG WINPR_TAG("sspi")
|
|
|
|
|
2014-06-06 06:54:31 +04:00
|
|
|
/* Authentication Functions: http://msdn.microsoft.com/en-us/library/windows/desktop/aa374731/ */
|
|
|
|
|
2021-06-17 12:25:58 +03:00
|
|
|
#include "NTLM/ntlm_export.h"
|
2021-07-28 16:18:03 +03:00
|
|
|
#include "CredSSP/credssp.h"
|
|
|
|
#include "Kerberos/kerberos.h"
|
|
|
|
#include "Negotiate/negotiate.h"
|
|
|
|
#include "Schannel/schannel.h"
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static const SecPkgInfoA* SecPkgInfoA_LIST[] = { &NTLM_SecPkgInfoA, &KERBEROS_SecPkgInfoA,
|
|
|
|
&NEGOTIATE_SecPkgInfoA, &CREDSSP_SecPkgInfoA,
|
|
|
|
&SCHANNEL_SecPkgInfoA };
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static const SecPkgInfoW* SecPkgInfoW_LIST[] = { &NTLM_SecPkgInfoW, &KERBEROS_SecPkgInfoW,
|
|
|
|
&NEGOTIATE_SecPkgInfoW, &CREDSSP_SecPkgInfoW,
|
|
|
|
&SCHANNEL_SecPkgInfoW };
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static SecurityFunctionTableA winpr_SecurityFunctionTableA;
|
|
|
|
static SecurityFunctionTableW winpr_SecurityFunctionTableW;
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2017-11-15 11:11:12 +03:00
|
|
|
const SEC_CHAR* Name;
|
2014-06-06 06:54:31 +04:00
|
|
|
const SecurityFunctionTableA* SecurityFunctionTable;
|
2022-02-14 16:59:22 +03:00
|
|
|
} SecurityFunctionTableA_NAME;
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2017-11-15 11:11:12 +03:00
|
|
|
const SEC_WCHAR* Name;
|
2014-06-06 06:54:31 +04:00
|
|
|
const SecurityFunctionTableW* SecurityFunctionTable;
|
2022-02-14 16:59:22 +03:00
|
|
|
} SecurityFunctionTableW_NAME;
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static const SecurityFunctionTableA_NAME SecurityFunctionTableA_NAME_LIST[] = {
|
2017-12-21 13:30:21 +03:00
|
|
|
{ "NTLM", &NTLM_SecurityFunctionTableA },
|
|
|
|
{ "Kerberos", &KERBEROS_SecurityFunctionTableA },
|
|
|
|
{ "Negotiate", &NEGOTIATE_SecurityFunctionTableA },
|
|
|
|
{ "CREDSSP", &CREDSSP_SecurityFunctionTableA },
|
|
|
|
{ "Schannel", &SCHANNEL_SecurityFunctionTableA }
|
2014-06-06 06:54:31 +04:00
|
|
|
};
|
|
|
|
|
2021-07-28 16:18:03 +03:00
|
|
|
static const WCHAR _NTLM_NAME_W[] = { 'N', 'T', 'L', 'M', '\0' };
|
|
|
|
static const WCHAR _KERBEROS_NAME_W[] = { 'K', 'e', 'r', 'b', 'e', 'r', 'o', 's', '\0' };
|
|
|
|
static const WCHAR _NEGOTIATE_NAME_W[] = { 'N', 'e', 'g', 'o', 't', 'i', 'a', 't', 'e', '\0' };
|
|
|
|
static const WCHAR _CREDSSP_NAME_W[] = { 'C', 'r', 'e', 'd', 'S', 'S', 'P', '\0' };
|
|
|
|
static const WCHAR _SCHANNEL_NAME_W[] = { 'S', 'c', 'h', 'a', 'n', 'n', 'e', 'l', '\0' };
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static const SecurityFunctionTableW_NAME SecurityFunctionTableW_NAME_LIST[] = {
|
2021-07-28 16:18:03 +03:00
|
|
|
{ _NTLM_NAME_W, &NTLM_SecurityFunctionTableW },
|
|
|
|
{ _KERBEROS_NAME_W, &KERBEROS_SecurityFunctionTableW },
|
|
|
|
{ _NEGOTIATE_NAME_W, &NEGOTIATE_SecurityFunctionTableW },
|
|
|
|
{ _CREDSSP_NAME_W, &CREDSSP_SecurityFunctionTableW },
|
|
|
|
{ _SCHANNEL_NAME_W, &SCHANNEL_SecurityFunctionTableW }
|
2014-06-06 06:54:31 +04:00
|
|
|
};
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
#define SecHandle_LOWER_MAX 0xFFFFFFFF
|
|
|
|
#define SecHandle_UPPER_MAX 0xFFFFFFFE
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
void* contextBuffer;
|
|
|
|
UINT32 allocatorIndex;
|
2022-02-14 16:59:22 +03:00
|
|
|
} CONTEXT_BUFFER_ALLOC_ENTRY;
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
UINT32 cEntries;
|
|
|
|
UINT32 cMaxEntries;
|
|
|
|
CONTEXT_BUFFER_ALLOC_ENTRY* entries;
|
2022-02-14 16:59:22 +03:00
|
|
|
} CONTEXT_BUFFER_ALLOC_TABLE;
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static CONTEXT_BUFFER_ALLOC_TABLE ContextBufferAllocTable = { 0 };
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static int sspi_ContextBufferAllocTableNew(void)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
size_t size;
|
|
|
|
ContextBufferAllocTable.entries = NULL;
|
|
|
|
ContextBufferAllocTable.cEntries = 0;
|
|
|
|
ContextBufferAllocTable.cMaxEntries = 4;
|
|
|
|
size = sizeof(CONTEXT_BUFFER_ALLOC_ENTRY) * ContextBufferAllocTable.cMaxEntries;
|
2019-11-06 17:24:51 +03:00
|
|
|
ContextBufferAllocTable.entries = (CONTEXT_BUFFER_ALLOC_ENTRY*)calloc(1, size);
|
2014-06-07 01:20:34 +04:00
|
|
|
|
|
|
|
if (!ContextBufferAllocTable.entries)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 1;
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static int sspi_ContextBufferAllocTableGrow(void)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
size_t size;
|
2014-06-07 01:20:34 +04:00
|
|
|
CONTEXT_BUFFER_ALLOC_ENTRY* entries;
|
2014-06-06 06:54:31 +04:00
|
|
|
ContextBufferAllocTable.cEntries = 0;
|
|
|
|
ContextBufferAllocTable.cMaxEntries *= 2;
|
|
|
|
size = sizeof(CONTEXT_BUFFER_ALLOC_ENTRY) * ContextBufferAllocTable.cMaxEntries;
|
2014-06-07 01:20:34 +04:00
|
|
|
|
2014-06-06 06:54:31 +04:00
|
|
|
if (!size)
|
2014-06-07 01:20:34 +04:00
|
|
|
return -1;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
entries = (CONTEXT_BUFFER_ALLOC_ENTRY*)realloc(ContextBufferAllocTable.entries, size);
|
2014-06-07 01:20:34 +04:00
|
|
|
|
|
|
|
if (!entries)
|
|
|
|
{
|
|
|
|
free(ContextBufferAllocTable.entries);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ContextBufferAllocTable.entries = entries;
|
2019-11-06 17:24:51 +03:00
|
|
|
ZeroMemory((void*)&ContextBufferAllocTable.entries[ContextBufferAllocTable.cMaxEntries / 2],
|
2017-05-11 19:51:45 +03:00
|
|
|
size / 2);
|
2014-06-07 01:20:34 +04:00
|
|
|
return 1;
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static void sspi_ContextBufferAllocTableFree(void)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2017-12-12 12:47:17 +03:00
|
|
|
if (ContextBufferAllocTable.cEntries != 0)
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "ContextBufferAllocTable.entries == %" PRIu32,
|
|
|
|
ContextBufferAllocTable.cEntries);
|
2017-12-12 12:47:17 +03:00
|
|
|
|
|
|
|
ContextBufferAllocTable.cEntries = ContextBufferAllocTable.cMaxEntries = 0;
|
|
|
|
free(ContextBufferAllocTable.entries);
|
|
|
|
ContextBufferAllocTable.entries = NULL;
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static void* sspi_ContextBufferAlloc(UINT32 allocatorIndex, size_t size)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2017-11-15 11:11:12 +03:00
|
|
|
UINT32 index;
|
2014-06-06 06:54:31 +04:00
|
|
|
void* contextBuffer;
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
for (index = 0; index < ContextBufferAllocTable.cMaxEntries; index++)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2014-06-07 01:20:34 +04:00
|
|
|
if (!ContextBufferAllocTable.entries[index].contextBuffer)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2014-06-07 01:20:34 +04:00
|
|
|
contextBuffer = calloc(1, size);
|
2015-07-07 18:17:29 +03:00
|
|
|
|
2014-06-07 01:20:34 +04:00
|
|
|
if (!contextBuffer)
|
|
|
|
return NULL;
|
|
|
|
|
2014-06-06 06:54:31 +04:00
|
|
|
ContextBufferAllocTable.cEntries++;
|
|
|
|
ContextBufferAllocTable.entries[index].contextBuffer = contextBuffer;
|
|
|
|
ContextBufferAllocTable.entries[index].allocatorIndex = allocatorIndex;
|
|
|
|
return ContextBufferAllocTable.entries[index].contextBuffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no available entry was found, the table needs to be grown */
|
|
|
|
|
2014-06-07 01:20:34 +04:00
|
|
|
if (sspi_ContextBufferAllocTableGrow() < 0)
|
|
|
|
return NULL;
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
/* the next call to sspi_ContextBufferAlloc() should now succeed */
|
|
|
|
return sspi_ContextBufferAlloc(allocatorIndex, size);
|
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
SSPI_CREDENTIALS* sspi_CredentialsNew(void)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2014-06-09 23:25:00 +04:00
|
|
|
SSPI_CREDENTIALS* credentials;
|
2019-11-06 17:24:51 +03:00
|
|
|
credentials = (SSPI_CREDENTIALS*)calloc(1, sizeof(SSPI_CREDENTIALS));
|
2014-06-06 06:54:31 +04:00
|
|
|
return credentials;
|
|
|
|
}
|
|
|
|
|
2014-06-09 23:25:00 +04:00
|
|
|
void sspi_CredentialsFree(SSPI_CREDENTIALS* credentials)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2017-05-11 19:51:45 +03:00
|
|
|
size_t userLength = 0;
|
|
|
|
size_t domainLength = 0;
|
|
|
|
size_t passwordLength = 0;
|
2015-07-07 14:08:39 +03:00
|
|
|
|
2014-06-06 06:54:31 +04:00
|
|
|
if (!credentials)
|
|
|
|
return;
|
|
|
|
|
2015-07-07 14:08:39 +03:00
|
|
|
userLength = credentials->identity.UserLength;
|
|
|
|
domainLength = credentials->identity.DomainLength;
|
|
|
|
passwordLength = credentials->identity.PasswordLength;
|
|
|
|
|
2018-05-03 18:49:14 +03:00
|
|
|
if (passwordLength > SSPI_CREDENTIALS_HASH_LENGTH_OFFSET) /* [pth] */
|
|
|
|
passwordLength -= SSPI_CREDENTIALS_HASH_LENGTH_OFFSET;
|
|
|
|
|
2015-07-07 14:08:39 +03:00
|
|
|
if (credentials->identity.Flags & SEC_WINNT_AUTH_IDENTITY_UNICODE)
|
|
|
|
{
|
|
|
|
userLength *= 2;
|
|
|
|
domainLength *= 2;
|
|
|
|
passwordLength *= 2;
|
|
|
|
}
|
|
|
|
|
2020-05-15 12:16:50 +03:00
|
|
|
if (credentials->identity.User)
|
|
|
|
memset(credentials->identity.User, 0, userLength);
|
|
|
|
if (credentials->identity.Domain)
|
|
|
|
memset(credentials->identity.Domain, 0, domainLength);
|
|
|
|
if (credentials->identity.Password)
|
|
|
|
memset(credentials->identity.Password, 0, passwordLength);
|
2014-06-10 16:40:04 +04:00
|
|
|
free(credentials->identity.User);
|
|
|
|
free(credentials->identity.Domain);
|
|
|
|
free(credentials->identity.Password);
|
2014-06-06 06:54:31 +04:00
|
|
|
free(credentials);
|
|
|
|
}
|
|
|
|
|
2014-06-07 08:17:11 +04:00
|
|
|
void* sspi_SecBufferAlloc(PSecBuffer SecBuffer, ULONG size)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2014-06-07 08:17:11 +04:00
|
|
|
if (!SecBuffer)
|
|
|
|
return NULL;
|
|
|
|
|
2014-06-07 01:20:34 +04:00
|
|
|
SecBuffer->pvBuffer = calloc(1, size);
|
2017-05-11 19:51:45 +03:00
|
|
|
|
2015-04-03 17:21:01 +03:00
|
|
|
if (!SecBuffer->pvBuffer)
|
|
|
|
return NULL;
|
2014-06-07 08:17:11 +04:00
|
|
|
|
2015-04-03 17:21:01 +03:00
|
|
|
SecBuffer->cbBuffer = size;
|
2014-06-07 08:17:11 +04:00
|
|
|
return SecBuffer->pvBuffer;
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void sspi_SecBufferFree(PSecBuffer SecBuffer)
|
|
|
|
{
|
2015-05-11 10:07:39 +03:00
|
|
|
if (!SecBuffer)
|
|
|
|
return;
|
|
|
|
|
2017-05-15 19:52:39 +03:00
|
|
|
if (SecBuffer->pvBuffer)
|
|
|
|
memset(SecBuffer->pvBuffer, 0, SecBuffer->cbBuffer);
|
2017-07-03 13:47:56 +03:00
|
|
|
|
2014-06-06 06:54:31 +04:00
|
|
|
free(SecBuffer->pvBuffer);
|
|
|
|
SecBuffer->pvBuffer = NULL;
|
|
|
|
SecBuffer->cbBuffer = 0;
|
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
SecHandle* sspi_SecureHandleAlloc(void)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
SecHandle* handle = (SecHandle*)calloc(1, sizeof(SecHandle));
|
2014-06-07 01:20:34 +04:00
|
|
|
|
|
|
|
if (!handle)
|
|
|
|
return NULL;
|
|
|
|
|
2014-06-08 02:28:02 +04:00
|
|
|
SecInvalidateHandle(handle);
|
2014-06-06 06:54:31 +04:00
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* sspi_SecureHandleGetLowerPointer(SecHandle* handle)
|
|
|
|
{
|
|
|
|
void* pointer;
|
|
|
|
|
2014-06-08 02:28:02 +04:00
|
|
|
if (!handle || !SecIsValidHandle(handle) || !handle->dwLower)
|
2014-06-06 06:54:31 +04:00
|
|
|
return NULL;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
pointer = (void*)~((size_t)handle->dwLower);
|
2014-06-06 06:54:31 +04:00
|
|
|
return pointer;
|
|
|
|
}
|
|
|
|
|
2017-07-18 14:23:22 +03:00
|
|
|
void sspi_SecureHandleInvalidate(SecHandle* handle)
|
|
|
|
{
|
|
|
|
if (!handle)
|
|
|
|
return;
|
|
|
|
|
|
|
|
handle->dwLower = 0;
|
|
|
|
handle->dwUpper = 0;
|
|
|
|
}
|
|
|
|
|
2014-06-06 06:54:31 +04:00
|
|
|
void sspi_SecureHandleSetLowerPointer(SecHandle* handle, void* pointer)
|
|
|
|
{
|
|
|
|
if (!handle)
|
|
|
|
return;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
handle->dwLower = (ULONG_PTR)(~((size_t)pointer));
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void* sspi_SecureHandleGetUpperPointer(SecHandle* handle)
|
|
|
|
{
|
|
|
|
void* pointer;
|
|
|
|
|
2014-06-08 02:28:02 +04:00
|
|
|
if (!handle || !SecIsValidHandle(handle) || !handle->dwUpper)
|
2014-06-06 06:54:31 +04:00
|
|
|
return NULL;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
pointer = (void*)~((size_t)handle->dwUpper);
|
2014-06-06 06:54:31 +04:00
|
|
|
return pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sspi_SecureHandleSetUpperPointer(SecHandle* handle, void* pointer)
|
|
|
|
{
|
|
|
|
if (!handle)
|
|
|
|
return;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
handle->dwUpper = (ULONG_PTR)(~((size_t)pointer));
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void sspi_SecureHandleFree(SecHandle* handle)
|
|
|
|
{
|
|
|
|
free(handle);
|
|
|
|
}
|
|
|
|
|
2017-05-11 19:51:45 +03:00
|
|
|
int sspi_SetAuthIdentity(SEC_WINNT_AUTH_IDENTITY* identity, const char* user, const char* domain,
|
|
|
|
const char* password)
|
2017-12-06 18:30:57 +03:00
|
|
|
{
|
2018-01-24 16:11:33 +03:00
|
|
|
int rc;
|
2017-12-06 18:30:57 +03:00
|
|
|
int unicodePasswordLenW;
|
|
|
|
LPWSTR unicodePassword = NULL;
|
|
|
|
unicodePasswordLenW = ConvertToUnicode(CP_UTF8, 0, password, -1, &unicodePassword, 0);
|
|
|
|
|
|
|
|
if (unicodePasswordLenW <= 0)
|
|
|
|
return -1;
|
|
|
|
|
2018-01-24 16:11:33 +03:00
|
|
|
rc = sspi_SetAuthIdentityWithUnicodePassword(identity, user, domain, unicodePassword,
|
2019-11-06 17:24:51 +03:00
|
|
|
(ULONG)(unicodePasswordLenW - 1));
|
2018-01-24 16:11:33 +03:00
|
|
|
free(unicodePassword);
|
|
|
|
return rc;
|
2017-12-06 18:30:57 +03:00
|
|
|
}
|
|
|
|
|
2017-12-21 13:30:21 +03:00
|
|
|
int sspi_SetAuthIdentityWithUnicodePassword(SEC_WINNT_AUTH_IDENTITY* identity, const char* user,
|
2019-11-06 17:24:51 +03:00
|
|
|
const char* domain, LPWSTR password,
|
|
|
|
ULONG passwordLength)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2014-06-07 01:20:34 +04:00
|
|
|
int status;
|
2014-06-06 06:54:31 +04:00
|
|
|
identity->Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
|
2015-05-11 10:07:39 +03:00
|
|
|
free(identity->User);
|
2019-11-06 17:24:51 +03:00
|
|
|
identity->User = (UINT16*)NULL;
|
2014-06-07 01:20:34 +04:00
|
|
|
identity->UserLength = 0;
|
|
|
|
|
2014-06-06 06:54:31 +04:00
|
|
|
if (user)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
status = ConvertToUnicode(CP_UTF8, 0, user, -1, (LPWSTR*)&(identity->User), 0);
|
2014-06-07 01:20:34 +04:00
|
|
|
|
|
|
|
if (status <= 0)
|
|
|
|
return -1;
|
|
|
|
|
2017-05-11 19:51:45 +03:00
|
|
|
identity->UserLength = (ULONG)(status - 1);
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
|
2015-05-11 10:07:39 +03:00
|
|
|
free(identity->Domain);
|
2019-11-06 17:24:51 +03:00
|
|
|
identity->Domain = (UINT16*)NULL;
|
2014-06-07 01:20:34 +04:00
|
|
|
identity->DomainLength = 0;
|
|
|
|
|
2014-06-06 06:54:31 +04:00
|
|
|
if (domain)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
status = ConvertToUnicode(CP_UTF8, 0, domain, -1, (LPWSTR*)&(identity->Domain), 0);
|
2014-06-07 01:20:34 +04:00
|
|
|
|
|
|
|
if (status <= 0)
|
|
|
|
return -1;
|
|
|
|
|
2017-05-11 19:51:45 +03:00
|
|
|
identity->DomainLength = (ULONG)(status - 1);
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
|
2015-05-11 10:07:39 +03:00
|
|
|
free(identity->Password);
|
2019-11-06 17:24:51 +03:00
|
|
|
identity->Password = (UINT16*)calloc(1, (passwordLength + 1) * sizeof(WCHAR));
|
2017-12-21 13:30:21 +03:00
|
|
|
|
2017-12-06 18:30:57 +03:00
|
|
|
if (!identity->Password)
|
|
|
|
return -1;
|
2014-06-07 01:20:34 +04:00
|
|
|
|
2017-12-06 18:30:57 +03:00
|
|
|
CopyMemory(identity->Password, password, passwordLength * sizeof(WCHAR));
|
|
|
|
identity->PasswordLength = passwordLength;
|
2014-06-07 01:20:34 +04:00
|
|
|
return 1;
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
|
2022-02-24 15:17:28 +03:00
|
|
|
int sspi_CopyAuthIdentity(SEC_WINNT_AUTH_IDENTITY* identity,
|
|
|
|
const SEC_WINNT_AUTH_IDENTITY* srcIdentity)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2014-06-07 01:20:34 +04:00
|
|
|
int status;
|
|
|
|
|
2018-05-03 18:49:14 +03:00
|
|
|
if (srcIdentity->Flags & SEC_WINNT_AUTH_IDENTITY_ANSI)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
status = sspi_SetAuthIdentity(identity, (char*)srcIdentity->User,
|
|
|
|
(char*)srcIdentity->Domain, (char*)srcIdentity->Password);
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2014-06-07 01:20:34 +04:00
|
|
|
if (status <= 0)
|
|
|
|
return -1;
|
|
|
|
|
2018-05-03 18:49:14 +03:00
|
|
|
identity->Flags &= ~SEC_WINNT_AUTH_IDENTITY_ANSI;
|
|
|
|
identity->Flags |= SEC_WINNT_AUTH_IDENTITY_UNICODE;
|
2014-06-07 01:20:34 +04:00
|
|
|
return 1;
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
|
2018-05-03 18:49:14 +03:00
|
|
|
identity->Flags |= SEC_WINNT_AUTH_IDENTITY_UNICODE;
|
2017-05-11 19:51:45 +03:00
|
|
|
/* login/password authentication */
|
2014-06-06 06:54:31 +04:00
|
|
|
identity->User = identity->Domain = identity->Password = NULL;
|
|
|
|
identity->UserLength = srcIdentity->UserLength;
|
|
|
|
|
|
|
|
if (identity->UserLength > 0)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
identity->User = (UINT16*)calloc((identity->UserLength + 1), sizeof(WCHAR));
|
2014-06-07 01:20:34 +04:00
|
|
|
|
|
|
|
if (!identity->User)
|
|
|
|
return -1;
|
|
|
|
|
2014-06-06 06:54:31 +04:00
|
|
|
CopyMemory(identity->User, srcIdentity->User, identity->UserLength * sizeof(WCHAR));
|
|
|
|
identity->User[identity->UserLength] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
identity->DomainLength = srcIdentity->DomainLength;
|
|
|
|
|
|
|
|
if (identity->DomainLength > 0)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
identity->Domain = (UINT16*)calloc((identity->DomainLength + 1), sizeof(WCHAR));
|
2014-06-07 01:20:34 +04:00
|
|
|
|
|
|
|
if (!identity->Domain)
|
|
|
|
return -1;
|
|
|
|
|
2014-06-06 06:54:31 +04:00
|
|
|
CopyMemory(identity->Domain, srcIdentity->Domain, identity->DomainLength * sizeof(WCHAR));
|
|
|
|
identity->Domain[identity->DomainLength] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
identity->PasswordLength = srcIdentity->PasswordLength;
|
|
|
|
|
2018-05-03 18:49:14 +03:00
|
|
|
if (identity->PasswordLength > SSPI_CREDENTIALS_HASH_LENGTH_OFFSET)
|
|
|
|
identity->PasswordLength -= SSPI_CREDENTIALS_HASH_LENGTH_OFFSET;
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2015-10-09 20:48:41 +03:00
|
|
|
if (srcIdentity->Password)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
identity->Password = (UINT16*)calloc((identity->PasswordLength + 1), sizeof(WCHAR));
|
2014-06-07 01:20:34 +04:00
|
|
|
|
|
|
|
if (!identity->Password)
|
|
|
|
return -1;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
CopyMemory(identity->Password, srcIdentity->Password,
|
|
|
|
identity->PasswordLength * sizeof(WCHAR));
|
2014-06-06 06:54:31 +04:00
|
|
|
identity->Password[identity->PasswordLength] = 0;
|
|
|
|
}
|
|
|
|
|
2018-05-03 18:49:14 +03:00
|
|
|
identity->PasswordLength = srcIdentity->PasswordLength;
|
2017-05-11 19:51:45 +03:00
|
|
|
/* End of login/password authentication */
|
2014-06-07 01:20:34 +04:00
|
|
|
return 1;
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PSecBuffer sspi_FindSecBuffer(PSecBufferDesc pMessage, ULONG BufferType)
|
|
|
|
{
|
|
|
|
ULONG index;
|
|
|
|
PSecBuffer pSecBuffer = NULL;
|
|
|
|
|
|
|
|
for (index = 0; index < pMessage->cBuffers; index++)
|
|
|
|
{
|
|
|
|
if (pMessage->pBuffers[index].BufferType == BufferType)
|
|
|
|
{
|
|
|
|
pSecBuffer = &pMessage->pBuffers[index];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pSecBuffer;
|
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static BOOL CALLBACK sspi_init(PINIT_ONCE InitOnce, PVOID Parameter, PVOID* Context)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2017-11-15 11:11:12 +03:00
|
|
|
winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT);
|
|
|
|
sspi_ContextBufferAllocTableNew();
|
|
|
|
return TRUE;
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
void sspi_GlobalInit(void)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2017-11-15 11:11:12 +03:00
|
|
|
static INIT_ONCE once = INIT_ONCE_STATIC_INIT;
|
|
|
|
DWORD flags = 0;
|
|
|
|
InitOnceExecuteOnce(&once, sspi_init, &flags, NULL);
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
void sspi_GlobalFinish(void)
|
|
|
|
{
|
|
|
|
sspi_ContextBufferAllocTableFree();
|
|
|
|
}
|
|
|
|
|
2021-08-02 13:13:34 +03:00
|
|
|
static const SecurityFunctionTableA* sspi_GetSecurityFunctionTableAByNameA(const SEC_CHAR* Name)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
UINT32 cPackages;
|
|
|
|
cPackages = sizeof(SecPkgInfoA_LIST) / sizeof(*(SecPkgInfoA_LIST));
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
for (index = 0; index < (int)cPackages; index++)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
if (strcmp(Name, SecurityFunctionTableA_NAME_LIST[index].Name) == 0)
|
|
|
|
{
|
2021-08-02 13:13:34 +03:00
|
|
|
return (const SecurityFunctionTableA*)SecurityFunctionTableA_NAME_LIST[index]
|
2019-11-06 17:24:51 +03:00
|
|
|
.SecurityFunctionTable;
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-08-02 13:13:34 +03:00
|
|
|
static const SecurityFunctionTableW* sspi_GetSecurityFunctionTableWByNameW(const SEC_WCHAR* Name)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
UINT32 cPackages;
|
|
|
|
cPackages = sizeof(SecPkgInfoW_LIST) / sizeof(*(SecPkgInfoW_LIST));
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
for (index = 0; index < (int)cPackages; index++)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
if (lstrcmpW(Name, SecurityFunctionTableW_NAME_LIST[index].Name) == 0)
|
|
|
|
{
|
2021-08-02 13:13:34 +03:00
|
|
|
return (const SecurityFunctionTableW*)SecurityFunctionTableW_NAME_LIST[index]
|
2019-11-06 17:24:51 +03:00
|
|
|
.SecurityFunctionTable;
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-08-26 12:23:32 +03:00
|
|
|
static const SecurityFunctionTableW* sspi_GetSecurityFunctionTableWByNameA(const SEC_CHAR* Name)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2014-06-07 01:20:34 +04:00
|
|
|
int status;
|
2014-06-06 06:54:31 +04:00
|
|
|
SEC_WCHAR* NameW = NULL;
|
2021-08-02 13:13:34 +03:00
|
|
|
const SecurityFunctionTableW* table;
|
2014-06-07 01:20:34 +04:00
|
|
|
status = ConvertToUnicode(CP_UTF8, 0, Name, -1, &NameW, 0);
|
|
|
|
|
|
|
|
if (status <= 0)
|
|
|
|
return NULL;
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
table = sspi_GetSecurityFunctionTableWByNameW(NameW);
|
|
|
|
free(NameW);
|
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static void FreeContextBuffer_EnumerateSecurityPackages(void* contextBuffer);
|
|
|
|
static void FreeContextBuffer_QuerySecurityPackageInfo(void* contextBuffer);
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static void sspi_ContextBufferFree(void* contextBuffer)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2017-11-15 11:11:12 +03:00
|
|
|
UINT32 index;
|
2014-06-06 06:54:31 +04:00
|
|
|
UINT32 allocatorIndex;
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
for (index = 0; index < ContextBufferAllocTable.cMaxEntries; index++)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
if (contextBuffer == ContextBufferAllocTable.entries[index].contextBuffer)
|
|
|
|
{
|
|
|
|
contextBuffer = ContextBufferAllocTable.entries[index].contextBuffer;
|
|
|
|
allocatorIndex = ContextBufferAllocTable.entries[index].allocatorIndex;
|
|
|
|
ContextBufferAllocTable.cEntries--;
|
|
|
|
ContextBufferAllocTable.entries[index].allocatorIndex = 0;
|
|
|
|
ContextBufferAllocTable.entries[index].contextBuffer = NULL;
|
|
|
|
|
|
|
|
switch (allocatorIndex)
|
|
|
|
{
|
2017-12-21 13:30:21 +03:00
|
|
|
case EnumerateSecurityPackagesIndex:
|
|
|
|
FreeContextBuffer_EnumerateSecurityPackages(contextBuffer);
|
|
|
|
break;
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2017-12-21 13:30:21 +03:00
|
|
|
case QuerySecurityPackageInfoIndex:
|
|
|
|
FreeContextBuffer_QuerySecurityPackageInfo(contextBuffer);
|
|
|
|
break;
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-06 23:34:12 +04:00
|
|
|
/**
|
|
|
|
* Standard SSPI API
|
|
|
|
*/
|
|
|
|
|
2014-06-06 06:54:31 +04:00
|
|
|
/* Package Management */
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesW(ULONG* pcPackages,
|
2019-11-06 17:24:51 +03:00
|
|
|
PSecPkgInfoW* ppPackageInfo)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
size_t size;
|
|
|
|
UINT32 cPackages;
|
|
|
|
SecPkgInfoW* pPackageInfo;
|
|
|
|
cPackages = sizeof(SecPkgInfoW_LIST) / sizeof(*(SecPkgInfoW_LIST));
|
|
|
|
size = sizeof(SecPkgInfoW) * cPackages;
|
2019-11-06 17:24:51 +03:00
|
|
|
pPackageInfo = (SecPkgInfoW*)sspi_ContextBufferAlloc(EnumerateSecurityPackagesIndex, size);
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2014-06-07 01:20:34 +04:00
|
|
|
if (!pPackageInfo)
|
|
|
|
return SEC_E_INSUFFICIENT_MEMORY;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
for (index = 0; index < (int)cPackages; index++)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
pPackageInfo[index].fCapabilities = SecPkgInfoW_LIST[index]->fCapabilities;
|
|
|
|
pPackageInfo[index].wVersion = SecPkgInfoW_LIST[index]->wVersion;
|
|
|
|
pPackageInfo[index].wRPCID = SecPkgInfoW_LIST[index]->wRPCID;
|
|
|
|
pPackageInfo[index].cbMaxToken = SecPkgInfoW_LIST[index]->cbMaxToken;
|
|
|
|
pPackageInfo[index].Name = _wcsdup(SecPkgInfoW_LIST[index]->Name);
|
|
|
|
pPackageInfo[index].Comment = _wcsdup(SecPkgInfoW_LIST[index]->Comment);
|
|
|
|
}
|
|
|
|
|
|
|
|
*(pcPackages) = cPackages;
|
|
|
|
*(ppPackageInfo) = pPackageInfo;
|
|
|
|
return SEC_E_OK;
|
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_EnumerateSecurityPackagesA(ULONG* pcPackages,
|
2019-11-06 17:24:51 +03:00
|
|
|
PSecPkgInfoA* ppPackageInfo)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
size_t size;
|
|
|
|
UINT32 cPackages;
|
|
|
|
SecPkgInfoA* pPackageInfo;
|
|
|
|
cPackages = sizeof(SecPkgInfoA_LIST) / sizeof(*(SecPkgInfoA_LIST));
|
|
|
|
size = sizeof(SecPkgInfoA) * cPackages;
|
2019-11-06 17:24:51 +03:00
|
|
|
pPackageInfo = (SecPkgInfoA*)sspi_ContextBufferAlloc(EnumerateSecurityPackagesIndex, size);
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2014-06-07 01:20:34 +04:00
|
|
|
if (!pPackageInfo)
|
|
|
|
return SEC_E_INSUFFICIENT_MEMORY;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
for (index = 0; index < (int)cPackages; index++)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
pPackageInfo[index].fCapabilities = SecPkgInfoA_LIST[index]->fCapabilities;
|
|
|
|
pPackageInfo[index].wVersion = SecPkgInfoA_LIST[index]->wVersion;
|
|
|
|
pPackageInfo[index].wRPCID = SecPkgInfoA_LIST[index]->wRPCID;
|
|
|
|
pPackageInfo[index].cbMaxToken = SecPkgInfoA_LIST[index]->cbMaxToken;
|
|
|
|
pPackageInfo[index].Name = _strdup(SecPkgInfoA_LIST[index]->Name);
|
|
|
|
pPackageInfo[index].Comment = _strdup(SecPkgInfoA_LIST[index]->Comment);
|
2017-05-11 19:51:45 +03:00
|
|
|
|
2015-06-17 23:08:02 +03:00
|
|
|
if (!pPackageInfo[index].Name || !pPackageInfo[index].Comment)
|
|
|
|
{
|
|
|
|
sspi_ContextBufferFree(pPackageInfo);
|
|
|
|
return SEC_E_INSUFFICIENT_MEMORY;
|
|
|
|
}
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
*(pcPackages) = cPackages;
|
|
|
|
*(ppPackageInfo) = pPackageInfo;
|
|
|
|
return SEC_E_OK;
|
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static void FreeContextBuffer_EnumerateSecurityPackages(void* contextBuffer)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
UINT32 cPackages;
|
2019-11-06 17:24:51 +03:00
|
|
|
SecPkgInfoA* pPackageInfo = (SecPkgInfoA*)contextBuffer;
|
2014-06-06 06:54:31 +04:00
|
|
|
cPackages = sizeof(SecPkgInfoA_LIST) / sizeof(*(SecPkgInfoA_LIST));
|
|
|
|
|
2019-01-28 12:55:24 +03:00
|
|
|
if (!pPackageInfo)
|
|
|
|
return;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
for (index = 0; index < (int)cPackages; index++)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2015-05-11 10:07:39 +03:00
|
|
|
free(pPackageInfo[index].Name);
|
|
|
|
free(pPackageInfo[index].Comment);
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
free(pPackageInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
SecurityFunctionTableW* SEC_ENTRY winpr_InitSecurityInterfaceW(void)
|
|
|
|
{
|
|
|
|
return &winpr_SecurityFunctionTableW;
|
|
|
|
}
|
|
|
|
|
|
|
|
SecurityFunctionTableA* SEC_ENTRY winpr_InitSecurityInterfaceA(void)
|
|
|
|
{
|
|
|
|
return &winpr_SecurityFunctionTableA;
|
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoW(SEC_WCHAR* pszPackageName,
|
2019-11-06 17:24:51 +03:00
|
|
|
PSecPkgInfoW* ppPackageInfo)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
size_t size;
|
|
|
|
UINT32 cPackages;
|
|
|
|
SecPkgInfoW* pPackageInfo;
|
|
|
|
cPackages = sizeof(SecPkgInfoW_LIST) / sizeof(*(SecPkgInfoW_LIST));
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
for (index = 0; index < (int)cPackages; index++)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
if (lstrcmpW(pszPackageName, SecPkgInfoW_LIST[index]->Name) == 0)
|
|
|
|
{
|
|
|
|
size = sizeof(SecPkgInfoW);
|
2019-11-06 17:24:51 +03:00
|
|
|
pPackageInfo =
|
|
|
|
(SecPkgInfoW*)sspi_ContextBufferAlloc(QuerySecurityPackageInfoIndex, size);
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2014-06-07 01:20:34 +04:00
|
|
|
if (!pPackageInfo)
|
|
|
|
return SEC_E_INSUFFICIENT_MEMORY;
|
|
|
|
|
2014-06-06 06:54:31 +04:00
|
|
|
pPackageInfo->fCapabilities = SecPkgInfoW_LIST[index]->fCapabilities;
|
|
|
|
pPackageInfo->wVersion = SecPkgInfoW_LIST[index]->wVersion;
|
|
|
|
pPackageInfo->wRPCID = SecPkgInfoW_LIST[index]->wRPCID;
|
|
|
|
pPackageInfo->cbMaxToken = SecPkgInfoW_LIST[index]->cbMaxToken;
|
|
|
|
pPackageInfo->Name = _wcsdup(SecPkgInfoW_LIST[index]->Name);
|
|
|
|
pPackageInfo->Comment = _wcsdup(SecPkgInfoW_LIST[index]->Comment);
|
|
|
|
*(ppPackageInfo) = pPackageInfo;
|
|
|
|
return SEC_E_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*(ppPackageInfo) = NULL;
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityPackageInfoA(SEC_CHAR* pszPackageName,
|
2019-11-06 17:24:51 +03:00
|
|
|
PSecPkgInfoA* ppPackageInfo)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
size_t size;
|
|
|
|
UINT32 cPackages;
|
|
|
|
SecPkgInfoA* pPackageInfo;
|
|
|
|
cPackages = sizeof(SecPkgInfoA_LIST) / sizeof(*(SecPkgInfoA_LIST));
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
for (index = 0; index < (int)cPackages; index++)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
if (strcmp(pszPackageName, SecPkgInfoA_LIST[index]->Name) == 0)
|
|
|
|
{
|
|
|
|
size = sizeof(SecPkgInfoA);
|
2019-11-06 17:24:51 +03:00
|
|
|
pPackageInfo =
|
|
|
|
(SecPkgInfoA*)sspi_ContextBufferAlloc(QuerySecurityPackageInfoIndex, size);
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2014-06-07 01:20:34 +04:00
|
|
|
if (!pPackageInfo)
|
|
|
|
return SEC_E_INSUFFICIENT_MEMORY;
|
|
|
|
|
2014-06-06 06:54:31 +04:00
|
|
|
pPackageInfo->fCapabilities = SecPkgInfoA_LIST[index]->fCapabilities;
|
|
|
|
pPackageInfo->wVersion = SecPkgInfoA_LIST[index]->wVersion;
|
|
|
|
pPackageInfo->wRPCID = SecPkgInfoA_LIST[index]->wRPCID;
|
|
|
|
pPackageInfo->cbMaxToken = SecPkgInfoA_LIST[index]->cbMaxToken;
|
|
|
|
pPackageInfo->Name = _strdup(SecPkgInfoA_LIST[index]->Name);
|
|
|
|
pPackageInfo->Comment = _strdup(SecPkgInfoA_LIST[index]->Comment);
|
2017-05-11 19:51:45 +03:00
|
|
|
|
2015-06-17 23:08:02 +03:00
|
|
|
if (!pPackageInfo->Name || !pPackageInfo->Comment)
|
|
|
|
{
|
|
|
|
sspi_ContextBufferFree(pPackageInfo);
|
|
|
|
return SEC_E_INSUFFICIENT_MEMORY;
|
|
|
|
}
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
*(ppPackageInfo) = pPackageInfo;
|
|
|
|
return SEC_E_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*(ppPackageInfo) = NULL;
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FreeContextBuffer_QuerySecurityPackageInfo(void* contextBuffer)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
SecPkgInfo* pPackageInfo = (SecPkgInfo*)contextBuffer;
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2015-05-11 10:07:39 +03:00
|
|
|
if (!pPackageInfo)
|
|
|
|
return;
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2015-05-11 10:07:39 +03:00
|
|
|
free(pPackageInfo->Name);
|
|
|
|
free(pPackageInfo->Comment);
|
2014-06-06 06:54:31 +04:00
|
|
|
free(pPackageInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Credential Management */
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleW(
|
|
|
|
SEC_WCHAR* pszPrincipal, SEC_WCHAR* pszPackage, ULONG fCredentialUse, void* pvLogonID,
|
|
|
|
void* pAuthData, SEC_GET_KEY_FN pGetKeyFn, void* pvGetKeyArgument, PCredHandle phCredential,
|
|
|
|
PTimeStamp ptsExpiry)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
SECURITY_STATUS status;
|
2021-08-02 13:13:34 +03:00
|
|
|
const SecurityFunctionTableW* table = sspi_GetSecurityFunctionTableWByNameW(pszPackage);
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
2014-06-07 01:20:34 +04:00
|
|
|
if (!table->AcquireCredentialsHandleW)
|
2020-08-10 15:59:07 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "[%s]: Security module does not provide an implementation", __FUNCTION__);
|
2014-06-06 06:54:31 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
2020-08-10 15:59:07 +03:00
|
|
|
}
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
status = table->AcquireCredentialsHandleW(pszPrincipal, pszPackage, fCredentialUse, pvLogonID,
|
|
|
|
pAuthData, pGetKeyFn, pvGetKeyArgument, phCredential,
|
|
|
|
ptsExpiry);
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2015-09-17 18:16:20 +03:00
|
|
|
if (IsSecurityStatusError(status))
|
2015-07-07 18:17:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "AcquireCredentialsHandleW status %s [0x%08" PRIX32 "]",
|
2017-05-11 19:51:45 +03:00
|
|
|
GetSecurityStatusString(status), status);
|
2015-07-07 18:17:29 +03:00
|
|
|
}
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_AcquireCredentialsHandleA(
|
|
|
|
SEC_CHAR* pszPrincipal, SEC_CHAR* pszPackage, ULONG fCredentialUse, void* pvLogonID,
|
|
|
|
void* pAuthData, SEC_GET_KEY_FN pGetKeyFn, void* pvGetKeyArgument, PCredHandle phCredential,
|
|
|
|
PTimeStamp ptsExpiry)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
SECURITY_STATUS status;
|
2021-08-02 13:13:34 +03:00
|
|
|
const SecurityFunctionTableA* table = sspi_GetSecurityFunctionTableAByNameA(pszPackage);
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
2014-06-07 01:20:34 +04:00
|
|
|
if (!table->AcquireCredentialsHandleA)
|
2020-08-10 15:59:07 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "[%s]: Security module does not provide an implementation", __FUNCTION__);
|
2014-06-06 06:54:31 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
2020-08-10 15:59:07 +03:00
|
|
|
}
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
status = table->AcquireCredentialsHandleA(pszPrincipal, pszPackage, fCredentialUse, pvLogonID,
|
|
|
|
pAuthData, pGetKeyFn, pvGetKeyArgument, phCredential,
|
|
|
|
ptsExpiry);
|
2015-07-07 18:17:29 +03:00
|
|
|
|
2015-09-17 18:16:20 +03:00
|
|
|
if (IsSecurityStatusError(status))
|
2015-07-07 18:17:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "AcquireCredentialsHandleA status %s [0x%08" PRIX32 "]",
|
2017-05-11 19:51:45 +03:00
|
|
|
GetSecurityStatusString(status), status);
|
2015-07-07 18:17:29 +03:00
|
|
|
}
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_ExportSecurityContext(PCtxtHandle phContext, ULONG fFlags,
|
2019-11-06 17:24:51 +03:00
|
|
|
PSecBuffer pPackedContext,
|
|
|
|
HANDLE* pToken)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2014-06-08 01:08:07 +04:00
|
|
|
SEC_CHAR* Name;
|
|
|
|
SECURITY_STATUS status;
|
2021-08-26 12:23:32 +03:00
|
|
|
const SecurityFunctionTableW* table;
|
2019-11-06 17:24:51 +03:00
|
|
|
Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
|
2014-06-08 01:08:07 +04:00
|
|
|
|
|
|
|
if (!Name)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
table = sspi_GetSecurityFunctionTableWByNameA(Name);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
if (!table->ExportSecurityContext)
|
2020-08-10 15:59:07 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "[%s]: Security module does not provide an implementation", __FUNCTION__);
|
2014-06-08 01:08:07 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
2020-08-10 15:59:07 +03:00
|
|
|
}
|
2014-06-08 01:08:07 +04:00
|
|
|
|
|
|
|
status = table->ExportSecurityContext(phContext, fFlags, pPackedContext, pToken);
|
|
|
|
|
2015-09-17 18:16:20 +03:00
|
|
|
if (IsSecurityStatusError(status))
|
2015-07-07 18:17:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "ExportSecurityContext status %s [0x%08" PRIX32 "]",
|
2017-05-11 19:51:45 +03:00
|
|
|
GetSecurityStatusString(status), status);
|
2015-07-07 18:17:29 +03:00
|
|
|
}
|
|
|
|
|
2014-06-08 01:08:07 +04:00
|
|
|
return status;
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_FreeCredentialsHandle(PCredHandle phCredential)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
char* Name;
|
|
|
|
SECURITY_STATUS status;
|
2021-08-02 13:13:34 +03:00
|
|
|
const SecurityFunctionTableA* table;
|
2019-11-06 17:24:51 +03:00
|
|
|
Name = (char*)sspi_SecureHandleGetUpperPointer(phCredential);
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
if (!Name)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
table = sspi_GetSecurityFunctionTableAByNameA(Name);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
2014-06-07 01:20:34 +04:00
|
|
|
if (!table->FreeCredentialsHandle)
|
2020-08-10 15:59:07 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "[%s]: Security module does not provide an implementation", __FUNCTION__);
|
2014-06-06 06:54:31 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
2020-08-10 15:59:07 +03:00
|
|
|
}
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
status = table->FreeCredentialsHandle(phCredential);
|
|
|
|
|
2015-09-17 18:16:20 +03:00
|
|
|
if (IsSecurityStatusError(status))
|
2015-07-07 18:17:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "FreeCredentialsHandle status %s [0x%08" PRIX32 "]",
|
2017-05-11 19:51:45 +03:00
|
|
|
GetSecurityStatusString(status), status);
|
2015-07-07 18:17:29 +03:00
|
|
|
}
|
2015-09-17 18:16:20 +03:00
|
|
|
|
2014-06-06 06:54:31 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextW(SEC_WCHAR* pszPackage,
|
2019-11-06 17:24:51 +03:00
|
|
|
PSecBuffer pPackedContext,
|
|
|
|
HANDLE pToken, PCtxtHandle phContext)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2014-06-08 01:08:07 +04:00
|
|
|
SEC_CHAR* Name;
|
|
|
|
SECURITY_STATUS status;
|
2021-08-26 12:23:32 +03:00
|
|
|
const SecurityFunctionTableW* table;
|
2019-11-06 17:24:51 +03:00
|
|
|
Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
|
2014-06-08 01:08:07 +04:00
|
|
|
|
|
|
|
if (!Name)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
table = sspi_GetSecurityFunctionTableWByNameA(Name);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
if (!table->ImportSecurityContextW)
|
2020-08-10 15:59:07 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "[%s]: Security module does not provide an implementation", __FUNCTION__);
|
2014-06-08 01:08:07 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
2020-08-10 15:59:07 +03:00
|
|
|
}
|
2014-06-08 01:08:07 +04:00
|
|
|
|
|
|
|
status = table->ImportSecurityContextW(pszPackage, pPackedContext, pToken, phContext);
|
|
|
|
|
2015-09-17 18:16:20 +03:00
|
|
|
if (IsSecurityStatusError(status))
|
2015-07-07 18:17:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "ImportSecurityContextW status %s [0x%08" PRIX32 "]",
|
2017-05-11 19:51:45 +03:00
|
|
|
GetSecurityStatusString(status), status);
|
2015-07-07 18:17:29 +03:00
|
|
|
}
|
|
|
|
|
2014-06-08 01:08:07 +04:00
|
|
|
return status;
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_ImportSecurityContextA(SEC_CHAR* pszPackage,
|
2019-11-06 17:24:51 +03:00
|
|
|
PSecBuffer pPackedContext,
|
|
|
|
HANDLE pToken, PCtxtHandle phContext)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2014-06-08 00:26:57 +04:00
|
|
|
char* Name = NULL;
|
|
|
|
SECURITY_STATUS status;
|
2021-08-02 13:13:34 +03:00
|
|
|
const SecurityFunctionTableA* table;
|
2019-11-06 17:24:51 +03:00
|
|
|
Name = (char*)sspi_SecureHandleGetUpperPointer(phContext);
|
2014-06-08 00:26:57 +04:00
|
|
|
|
|
|
|
if (!Name)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
table = sspi_GetSecurityFunctionTableAByNameA(Name);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
if (!table->ImportSecurityContextA)
|
2020-08-10 15:59:07 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "[%s]: Security module does not provide an implementation", __FUNCTION__);
|
2014-06-08 00:26:57 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
2020-08-10 15:59:07 +03:00
|
|
|
}
|
2014-06-08 00:26:57 +04:00
|
|
|
|
|
|
|
status = table->ImportSecurityContextA(pszPackage, pPackedContext, pToken, phContext);
|
|
|
|
|
2015-09-17 18:16:20 +03:00
|
|
|
if (IsSecurityStatusError(status))
|
2015-07-07 18:17:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "ImportSecurityContextA status %s [0x%08" PRIX32 "]",
|
2017-05-11 19:51:45 +03:00
|
|
|
GetSecurityStatusString(status), status);
|
2015-07-07 18:17:29 +03:00
|
|
|
}
|
|
|
|
|
2014-06-08 00:26:57 +04:00
|
|
|
return status;
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesW(PCredHandle phCredential,
|
2019-11-06 17:24:51 +03:00
|
|
|
ULONG ulAttribute, void* pBuffer)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
SEC_WCHAR* Name;
|
|
|
|
SECURITY_STATUS status;
|
2021-08-02 13:13:34 +03:00
|
|
|
const SecurityFunctionTableW* table;
|
2019-11-06 17:24:51 +03:00
|
|
|
Name = (SEC_WCHAR*)sspi_SecureHandleGetUpperPointer(phCredential);
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
if (!Name)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
table = sspi_GetSecurityFunctionTableWByNameW(Name);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
2014-06-07 01:20:34 +04:00
|
|
|
if (!table->QueryCredentialsAttributesW)
|
2020-08-10 15:59:07 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "[%s]: Security module does not provide an implementation", __FUNCTION__);
|
2014-06-06 06:54:31 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
2020-08-10 15:59:07 +03:00
|
|
|
}
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
status = table->QueryCredentialsAttributesW(phCredential, ulAttribute, pBuffer);
|
|
|
|
|
2015-09-17 18:16:20 +03:00
|
|
|
if (IsSecurityStatusError(status))
|
2015-07-07 18:17:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "QueryCredentialsAttributesW status %s [0x%08" PRIX32 "]",
|
2017-05-11 19:51:45 +03:00
|
|
|
GetSecurityStatusString(status), status);
|
2015-07-07 18:17:29 +03:00
|
|
|
}
|
|
|
|
|
2014-06-06 06:54:31 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_QueryCredentialsAttributesA(PCredHandle phCredential,
|
2019-11-06 17:24:51 +03:00
|
|
|
ULONG ulAttribute, void* pBuffer)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
char* Name;
|
|
|
|
SECURITY_STATUS status;
|
2021-08-02 13:13:34 +03:00
|
|
|
const SecurityFunctionTableA* table;
|
2019-11-06 17:24:51 +03:00
|
|
|
Name = (char*)sspi_SecureHandleGetUpperPointer(phCredential);
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
if (!Name)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
table = sspi_GetSecurityFunctionTableAByNameA(Name);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
2014-06-07 01:20:34 +04:00
|
|
|
if (!table->QueryCredentialsAttributesA)
|
2020-08-10 15:59:07 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "[%s]: Security module does not provide an implementation", __FUNCTION__);
|
2014-06-06 06:54:31 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
2020-08-10 15:59:07 +03:00
|
|
|
}
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
status = table->QueryCredentialsAttributesA(phCredential, ulAttribute, pBuffer);
|
|
|
|
|
2015-09-17 18:16:20 +03:00
|
|
|
if (IsSecurityStatusError(status))
|
2015-07-07 18:17:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "QueryCredentialsAttributesA status %s [0x%08" PRIX32 "]",
|
2017-05-11 19:51:45 +03:00
|
|
|
GetSecurityStatusString(status), status);
|
2015-07-07 18:17:29 +03:00
|
|
|
}
|
|
|
|
|
2014-06-06 06:54:31 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Context Management */
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY
|
|
|
|
winpr_AcceptSecurityContext(PCredHandle phCredential, PCtxtHandle phContext, PSecBufferDesc pInput,
|
|
|
|
ULONG fContextReq, ULONG TargetDataRep, PCtxtHandle phNewContext,
|
|
|
|
PSecBufferDesc pOutput, PULONG pfContextAttr, PTimeStamp ptsTimeStamp)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
char* Name;
|
|
|
|
SECURITY_STATUS status;
|
2021-08-02 13:13:34 +03:00
|
|
|
const SecurityFunctionTableA* table;
|
2019-11-06 17:24:51 +03:00
|
|
|
Name = (char*)sspi_SecureHandleGetUpperPointer(phCredential);
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
if (!Name)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
table = sspi_GetSecurityFunctionTableAByNameA(Name);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
2014-06-07 01:20:34 +04:00
|
|
|
if (!table->AcceptSecurityContext)
|
2020-08-10 15:59:07 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "[%s]: Security module does not provide an implementation", __FUNCTION__);
|
2014-06-06 06:54:31 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
2020-08-10 15:59:07 +03:00
|
|
|
}
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
status =
|
|
|
|
table->AcceptSecurityContext(phCredential, phContext, pInput, fContextReq, TargetDataRep,
|
|
|
|
phNewContext, pOutput, pfContextAttr, ptsTimeStamp);
|
2015-07-07 18:17:29 +03:00
|
|
|
|
2015-09-17 18:16:20 +03:00
|
|
|
if (IsSecurityStatusError(status))
|
2015-07-07 18:17:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "AcceptSecurityContext status %s [0x%08" PRIX32 "]",
|
2017-05-11 19:51:45 +03:00
|
|
|
GetSecurityStatusString(status), status);
|
2015-07-07 18:17:29 +03:00
|
|
|
}
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_ApplyControlToken(PCtxtHandle phContext,
|
2019-11-06 17:24:51 +03:00
|
|
|
PSecBufferDesc pInput)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2014-06-08 00:26:57 +04:00
|
|
|
char* Name = NULL;
|
|
|
|
SECURITY_STATUS status;
|
2021-08-02 13:13:34 +03:00
|
|
|
const SecurityFunctionTableA* table;
|
2019-11-06 17:24:51 +03:00
|
|
|
Name = (char*)sspi_SecureHandleGetUpperPointer(phContext);
|
2014-06-08 00:26:57 +04:00
|
|
|
|
|
|
|
if (!Name)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
table = sspi_GetSecurityFunctionTableAByNameA(Name);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
if (!table->ApplyControlToken)
|
2020-08-10 15:59:07 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "[%s]: Security module does not provide an implementation", __FUNCTION__);
|
2014-06-08 00:26:57 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
2020-08-10 15:59:07 +03:00
|
|
|
}
|
2014-06-08 00:26:57 +04:00
|
|
|
|
|
|
|
status = table->ApplyControlToken(phContext, pInput);
|
|
|
|
|
2015-09-17 18:16:20 +03:00
|
|
|
if (IsSecurityStatusError(status))
|
2015-07-07 18:17:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "ApplyControlToken status %s [0x%08" PRIX32 "]",
|
2017-05-11 19:51:45 +03:00
|
|
|
GetSecurityStatusString(status), status);
|
2015-07-07 18:17:29 +03:00
|
|
|
}
|
|
|
|
|
2014-06-08 00:26:57 +04:00
|
|
|
return status;
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_CompleteAuthToken(PCtxtHandle phContext,
|
2019-11-06 17:24:51 +03:00
|
|
|
PSecBufferDesc pToken)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2014-06-08 00:26:57 +04:00
|
|
|
char* Name = NULL;
|
|
|
|
SECURITY_STATUS status;
|
2021-08-02 13:13:34 +03:00
|
|
|
const SecurityFunctionTableA* table;
|
2019-11-06 17:24:51 +03:00
|
|
|
Name = (char*)sspi_SecureHandleGetUpperPointer(phContext);
|
2014-06-08 00:26:57 +04:00
|
|
|
|
|
|
|
if (!Name)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
table = sspi_GetSecurityFunctionTableAByNameA(Name);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
if (!table->CompleteAuthToken)
|
2020-08-10 15:59:07 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "[%s]: Security module does not provide an implementation", __FUNCTION__);
|
2014-06-08 00:26:57 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
2020-08-10 15:59:07 +03:00
|
|
|
}
|
2014-06-08 00:26:57 +04:00
|
|
|
|
|
|
|
status = table->CompleteAuthToken(phContext, pToken);
|
|
|
|
|
2015-09-17 18:16:20 +03:00
|
|
|
if (IsSecurityStatusError(status))
|
2015-07-07 18:17:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "CompleteAuthToken status %s [0x%08" PRIX32 "]",
|
2017-05-11 19:51:45 +03:00
|
|
|
GetSecurityStatusString(status), status);
|
2015-07-07 18:17:29 +03:00
|
|
|
}
|
|
|
|
|
2014-06-08 00:26:57 +04:00
|
|
|
return status;
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_DeleteSecurityContext(PCtxtHandle phContext)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
char* Name = NULL;
|
|
|
|
SECURITY_STATUS status;
|
2021-08-02 13:13:34 +03:00
|
|
|
const SecurityFunctionTableA* table;
|
2019-11-06 17:24:51 +03:00
|
|
|
Name = (char*)sspi_SecureHandleGetUpperPointer(phContext);
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
if (!Name)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
table = sspi_GetSecurityFunctionTableAByNameA(Name);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
2014-06-07 01:20:34 +04:00
|
|
|
if (!table->DeleteSecurityContext)
|
2020-08-10 15:59:07 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "[%s]: Security module does not provide an implementation", __FUNCTION__);
|
2014-06-06 06:54:31 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
2020-08-10 15:59:07 +03:00
|
|
|
}
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
status = table->DeleteSecurityContext(phContext);
|
|
|
|
|
2015-09-17 18:16:20 +03:00
|
|
|
if (IsSecurityStatusError(status))
|
2015-07-07 18:17:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "DeleteSecurityContext status %s [0x%08" PRIX32 "]",
|
2017-05-11 19:51:45 +03:00
|
|
|
GetSecurityStatusString(status), status);
|
2015-07-07 18:17:29 +03:00
|
|
|
}
|
|
|
|
|
2014-06-06 06:54:31 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_FreeContextBuffer(void* pvContextBuffer)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
if (!pvContextBuffer)
|
|
|
|
return SEC_E_INVALID_HANDLE;
|
|
|
|
|
|
|
|
sspi_ContextBufferFree(pvContextBuffer);
|
|
|
|
return SEC_E_OK;
|
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_ImpersonateSecurityContext(PCtxtHandle phContext)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2014-06-08 00:26:57 +04:00
|
|
|
SEC_CHAR* Name;
|
|
|
|
SECURITY_STATUS status;
|
2021-08-26 12:23:32 +03:00
|
|
|
const SecurityFunctionTableW* table;
|
2019-11-06 17:24:51 +03:00
|
|
|
Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
|
2014-06-08 00:26:57 +04:00
|
|
|
|
|
|
|
if (!Name)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
table = sspi_GetSecurityFunctionTableWByNameA(Name);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
2014-06-08 01:08:07 +04:00
|
|
|
if (!table->ImpersonateSecurityContext)
|
2020-08-10 15:59:07 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "[%s]: Security module does not provide an implementation", __FUNCTION__);
|
2014-06-08 00:26:57 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
2020-08-10 15:59:07 +03:00
|
|
|
}
|
2014-06-08 00:26:57 +04:00
|
|
|
|
|
|
|
status = table->ImpersonateSecurityContext(phContext);
|
|
|
|
|
2015-09-17 18:16:20 +03:00
|
|
|
if (IsSecurityStatusError(status))
|
2015-07-07 18:17:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "ImpersonateSecurityContext status %s [0x%08" PRIX32 "]",
|
2017-05-11 19:51:45 +03:00
|
|
|
GetSecurityStatusString(status), status);
|
2015-07-07 18:17:29 +03:00
|
|
|
}
|
|
|
|
|
2014-06-08 00:26:57 +04:00
|
|
|
return status;
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextW(
|
|
|
|
PCredHandle phCredential, PCtxtHandle phContext, SEC_WCHAR* pszTargetName, ULONG fContextReq,
|
|
|
|
ULONG Reserved1, ULONG TargetDataRep, PSecBufferDesc pInput, ULONG Reserved2,
|
|
|
|
PCtxtHandle phNewContext, PSecBufferDesc pOutput, PULONG pfContextAttr, PTimeStamp ptsExpiry)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
SEC_CHAR* Name;
|
|
|
|
SECURITY_STATUS status;
|
2021-08-26 12:23:32 +03:00
|
|
|
const SecurityFunctionTableW* table;
|
2019-11-06 17:24:51 +03:00
|
|
|
Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phCredential);
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
if (!Name)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
table = sspi_GetSecurityFunctionTableWByNameA(Name);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
2014-06-07 01:20:34 +04:00
|
|
|
if (!table->InitializeSecurityContextW)
|
2020-08-10 15:59:07 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "[%s]: Security module does not provide an implementation", __FUNCTION__);
|
2014-06-06 06:54:31 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
2020-08-10 15:59:07 +03:00
|
|
|
}
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
status = table->InitializeSecurityContextW(phCredential, phContext, pszTargetName, fContextReq,
|
|
|
|
Reserved1, TargetDataRep, pInput, Reserved2,
|
|
|
|
phNewContext, pOutput, pfContextAttr, ptsExpiry);
|
2015-07-07 18:17:29 +03:00
|
|
|
|
2015-09-17 18:16:20 +03:00
|
|
|
if (IsSecurityStatusError(status))
|
2015-07-07 18:17:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "InitializeSecurityContextW status %s [0x%08" PRIX32 "]",
|
2017-05-11 19:51:45 +03:00
|
|
|
GetSecurityStatusString(status), status);
|
2015-07-07 18:17:29 +03:00
|
|
|
}
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_InitializeSecurityContextA(
|
|
|
|
PCredHandle phCredential, PCtxtHandle phContext, SEC_CHAR* pszTargetName, ULONG fContextReq,
|
|
|
|
ULONG Reserved1, ULONG TargetDataRep, PSecBufferDesc pInput, ULONG Reserved2,
|
|
|
|
PCtxtHandle phNewContext, PSecBufferDesc pOutput, PULONG pfContextAttr, PTimeStamp ptsExpiry)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
SEC_CHAR* Name;
|
|
|
|
SECURITY_STATUS status;
|
2021-08-02 13:13:34 +03:00
|
|
|
const SecurityFunctionTableA* table;
|
2019-11-06 17:24:51 +03:00
|
|
|
Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phCredential);
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
if (!Name)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
table = sspi_GetSecurityFunctionTableAByNameA(Name);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
2014-06-07 01:20:34 +04:00
|
|
|
if (!table->InitializeSecurityContextA)
|
2020-08-10 15:59:07 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "[%s]: Security module does not provide an implementation", __FUNCTION__);
|
2014-06-06 06:54:31 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
2020-08-10 15:59:07 +03:00
|
|
|
}
|
2014-06-06 06:54:31 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
status = table->InitializeSecurityContextA(phCredential, phContext, pszTargetName, fContextReq,
|
|
|
|
Reserved1, TargetDataRep, pInput, Reserved2,
|
|
|
|
phNewContext, pOutput, pfContextAttr, ptsExpiry);
|
2015-07-07 18:17:29 +03:00
|
|
|
|
2015-09-17 18:16:20 +03:00
|
|
|
if (IsSecurityStatusError(status))
|
2015-07-07 18:17:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "InitializeSecurityContextA status %s [0x%08" PRIX32 "]",
|
2017-05-11 19:51:45 +03:00
|
|
|
GetSecurityStatusString(status), status);
|
2015-07-07 18:17:29 +03:00
|
|
|
}
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesW(PCtxtHandle phContext,
|
2019-11-06 17:24:51 +03:00
|
|
|
ULONG ulAttribute, void* pBuffer)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
SEC_CHAR* Name;
|
|
|
|
SECURITY_STATUS status;
|
2021-08-26 12:23:32 +03:00
|
|
|
const SecurityFunctionTableW* table;
|
2019-11-06 17:24:51 +03:00
|
|
|
Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
if (!Name)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
table = sspi_GetSecurityFunctionTableWByNameA(Name);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
2014-06-07 01:20:34 +04:00
|
|
|
if (!table->QueryContextAttributesW)
|
2020-08-10 15:59:07 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "[%s]: Security module does not provide an implementation", __FUNCTION__);
|
2014-06-06 06:54:31 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
2020-08-10 15:59:07 +03:00
|
|
|
}
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
status = table->QueryContextAttributesW(phContext, ulAttribute, pBuffer);
|
|
|
|
|
2015-09-17 18:16:20 +03:00
|
|
|
if (IsSecurityStatusError(status))
|
2015-07-07 18:17:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "QueryContextAttributesW status %s [0x%08" PRIX32 "]",
|
2017-05-11 19:51:45 +03:00
|
|
|
GetSecurityStatusString(status), status);
|
2015-07-07 18:17:29 +03:00
|
|
|
}
|
|
|
|
|
2014-06-06 06:54:31 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_QueryContextAttributesA(PCtxtHandle phContext,
|
2019-11-06 17:24:51 +03:00
|
|
|
ULONG ulAttribute, void* pBuffer)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
SEC_CHAR* Name;
|
|
|
|
SECURITY_STATUS status;
|
2021-08-02 13:13:34 +03:00
|
|
|
const SecurityFunctionTableA* table;
|
2019-11-06 17:24:51 +03:00
|
|
|
Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
if (!Name)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
table = sspi_GetSecurityFunctionTableAByNameA(Name);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
2014-06-07 01:20:34 +04:00
|
|
|
if (!table->QueryContextAttributesA)
|
2020-08-10 15:59:07 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "[%s]: Security module does not provide an implementation", __FUNCTION__);
|
2014-06-06 06:54:31 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
2020-08-10 15:59:07 +03:00
|
|
|
}
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
status = table->QueryContextAttributesA(phContext, ulAttribute, pBuffer);
|
|
|
|
|
2015-09-17 18:16:20 +03:00
|
|
|
if (IsSecurityStatusError(status))
|
2015-07-07 18:17:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "QueryContextAttributesA status %s [0x%08" PRIX32 "]",
|
2017-05-11 19:51:45 +03:00
|
|
|
GetSecurityStatusString(status), status);
|
2015-07-07 18:17:29 +03:00
|
|
|
}
|
|
|
|
|
2014-06-06 06:54:31 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_QuerySecurityContextToken(PCtxtHandle phContext,
|
2019-11-06 17:24:51 +03:00
|
|
|
HANDLE* phToken)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2014-06-10 22:38:17 +04:00
|
|
|
SEC_CHAR* Name;
|
|
|
|
SECURITY_STATUS status;
|
2021-08-26 12:23:32 +03:00
|
|
|
const SecurityFunctionTableW* table;
|
2019-11-06 17:24:51 +03:00
|
|
|
Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
|
2014-06-10 22:38:17 +04:00
|
|
|
|
|
|
|
if (!Name)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
table = sspi_GetSecurityFunctionTableWByNameA(Name);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
if (!table->QuerySecurityContextToken)
|
2020-08-10 15:59:07 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "[%s]: Security module does not provide an implementation", __FUNCTION__);
|
2014-06-10 22:38:17 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
2020-08-10 15:59:07 +03:00
|
|
|
}
|
2014-06-10 22:38:17 +04:00
|
|
|
|
|
|
|
status = table->QuerySecurityContextToken(phContext, phToken);
|
|
|
|
|
2015-09-17 18:16:20 +03:00
|
|
|
if (IsSecurityStatusError(status))
|
2015-07-07 18:17:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "QuerySecurityContextToken status %s [0x%08" PRIX32 "]",
|
2017-05-11 19:51:45 +03:00
|
|
|
GetSecurityStatusString(status), status);
|
2015-07-07 18:17:29 +03:00
|
|
|
}
|
|
|
|
|
2014-06-10 22:38:17 +04:00
|
|
|
return status;
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesW(PCtxtHandle phContext,
|
2019-11-06 17:24:51 +03:00
|
|
|
ULONG ulAttribute, void* pBuffer,
|
|
|
|
ULONG cbBuffer)
|
2014-06-06 23:34:12 +04:00
|
|
|
{
|
2014-06-10 22:38:17 +04:00
|
|
|
SEC_CHAR* Name;
|
|
|
|
SECURITY_STATUS status;
|
2021-08-26 12:23:32 +03:00
|
|
|
const SecurityFunctionTableW* table;
|
2019-11-06 17:24:51 +03:00
|
|
|
Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
|
2014-06-10 22:38:17 +04:00
|
|
|
|
|
|
|
if (!Name)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
table = sspi_GetSecurityFunctionTableWByNameA(Name);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
if (!table->SetContextAttributesW)
|
2020-08-10 15:59:07 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "[%s]: Security module does not provide an implementation", __FUNCTION__);
|
2014-06-10 22:38:17 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
2020-08-10 15:59:07 +03:00
|
|
|
}
|
2014-06-10 22:38:17 +04:00
|
|
|
|
|
|
|
status = table->SetContextAttributesW(phContext, ulAttribute, pBuffer, cbBuffer);
|
|
|
|
|
2015-09-17 18:16:20 +03:00
|
|
|
if (IsSecurityStatusError(status))
|
2015-07-07 18:17:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "SetContextAttributesW status %s [0x%08" PRIX32 "]",
|
2017-05-11 19:51:45 +03:00
|
|
|
GetSecurityStatusString(status), status);
|
2015-07-07 18:17:29 +03:00
|
|
|
}
|
|
|
|
|
2014-06-10 22:38:17 +04:00
|
|
|
return status;
|
2014-06-06 23:34:12 +04:00
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_SetContextAttributesA(PCtxtHandle phContext,
|
2019-11-06 17:24:51 +03:00
|
|
|
ULONG ulAttribute, void* pBuffer,
|
|
|
|
ULONG cbBuffer)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2014-06-10 22:38:17 +04:00
|
|
|
char* Name;
|
|
|
|
SECURITY_STATUS status;
|
2021-08-02 13:13:34 +03:00
|
|
|
const SecurityFunctionTableA* table;
|
2019-11-06 17:24:51 +03:00
|
|
|
Name = (char*)sspi_SecureHandleGetUpperPointer(phContext);
|
2014-06-10 22:38:17 +04:00
|
|
|
|
|
|
|
if (!Name)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
table = sspi_GetSecurityFunctionTableAByNameA(Name);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
if (!table->SetContextAttributesA)
|
2020-08-10 15:59:07 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "[%s]: Security module does not provide an implementation", __FUNCTION__);
|
2014-06-10 22:38:17 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
2020-08-10 15:59:07 +03:00
|
|
|
}
|
2014-06-10 22:38:17 +04:00
|
|
|
|
|
|
|
status = table->SetContextAttributesA(phContext, ulAttribute, pBuffer, cbBuffer);
|
|
|
|
|
2015-09-17 18:16:20 +03:00
|
|
|
if (IsSecurityStatusError(status))
|
2015-07-07 18:17:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "SetContextAttributesA status %s [0x%08" PRIX32 "]",
|
2017-05-11 19:51:45 +03:00
|
|
|
GetSecurityStatusString(status), status);
|
2015-07-07 18:17:29 +03:00
|
|
|
}
|
|
|
|
|
2014-06-10 22:38:17 +04:00
|
|
|
return status;
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_RevertSecurityContext(PCtxtHandle phContext)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
2014-06-10 22:38:17 +04:00
|
|
|
SEC_CHAR* Name;
|
|
|
|
SECURITY_STATUS status;
|
2021-08-26 12:23:32 +03:00
|
|
|
const SecurityFunctionTableW* table;
|
2019-11-06 17:24:51 +03:00
|
|
|
Name = (SEC_CHAR*)sspi_SecureHandleGetUpperPointer(phContext);
|
2014-06-10 22:38:17 +04:00
|
|
|
|
|
|
|
if (!Name)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
table = sspi_GetSecurityFunctionTableWByNameA(Name);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
if (!table->RevertSecurityContext)
|
2020-08-10 15:59:07 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "[%s]: Security module does not provide an implementation", __FUNCTION__);
|
2014-06-10 22:38:17 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
2020-08-10 15:59:07 +03:00
|
|
|
}
|
2014-06-10 22:38:17 +04:00
|
|
|
|
|
|
|
status = table->RevertSecurityContext(phContext);
|
|
|
|
|
2015-09-17 18:16:20 +03:00
|
|
|
if (IsSecurityStatusError(status))
|
2015-07-07 18:17:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "RevertSecurityContext status %s [0x%08" PRIX32 "]",
|
2017-05-11 19:51:45 +03:00
|
|
|
GetSecurityStatusString(status), status);
|
2015-07-07 18:17:29 +03:00
|
|
|
}
|
|
|
|
|
2014-06-10 22:38:17 +04:00
|
|
|
return status;
|
2014-06-06 06:54:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Message Support */
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_DecryptMessage(PCtxtHandle phContext,
|
2019-11-06 17:24:51 +03:00
|
|
|
PSecBufferDesc pMessage, ULONG MessageSeqNo,
|
|
|
|
PULONG pfQOP)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
char* Name;
|
|
|
|
SECURITY_STATUS status;
|
2021-08-02 13:13:34 +03:00
|
|
|
const SecurityFunctionTableA* table;
|
2019-11-06 17:24:51 +03:00
|
|
|
Name = (char*)sspi_SecureHandleGetUpperPointer(phContext);
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
if (!Name)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
table = sspi_GetSecurityFunctionTableAByNameA(Name);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
2014-06-07 01:20:34 +04:00
|
|
|
if (!table->DecryptMessage)
|
2020-08-10 15:59:07 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "[%s]: Security module does not provide an implementation", __FUNCTION__);
|
2014-06-06 06:54:31 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
2020-08-10 15:59:07 +03:00
|
|
|
}
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
status = table->DecryptMessage(phContext, pMessage, MessageSeqNo, pfQOP);
|
|
|
|
|
2015-09-17 18:16:20 +03:00
|
|
|
if (IsSecurityStatusError(status))
|
2015-07-07 18:17:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "DecryptMessage status %s [0x%08" PRIX32 "]",
|
2017-05-11 19:51:45 +03:00
|
|
|
GetSecurityStatusString(status), status);
|
2015-07-07 18:17:29 +03:00
|
|
|
}
|
|
|
|
|
2014-06-06 06:54:31 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_EncryptMessage(PCtxtHandle phContext, ULONG fQOP,
|
2019-11-06 17:24:51 +03:00
|
|
|
PSecBufferDesc pMessage, ULONG MessageSeqNo)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
char* Name;
|
|
|
|
SECURITY_STATUS status;
|
2021-08-02 13:13:34 +03:00
|
|
|
const SecurityFunctionTableA* table;
|
2019-11-06 17:24:51 +03:00
|
|
|
Name = (char*)sspi_SecureHandleGetUpperPointer(phContext);
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
if (!Name)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
table = sspi_GetSecurityFunctionTableAByNameA(Name);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
2014-06-07 01:20:34 +04:00
|
|
|
if (!table->EncryptMessage)
|
2020-08-10 15:59:07 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "[%s]: Security module does not provide an implementation", __FUNCTION__);
|
2014-06-06 06:54:31 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
2020-08-10 15:59:07 +03:00
|
|
|
}
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
status = table->EncryptMessage(phContext, fQOP, pMessage, MessageSeqNo);
|
|
|
|
|
2015-07-07 18:17:29 +03:00
|
|
|
if (status != SEC_E_OK)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "EncryptMessage status %s [0x%08" PRIX32 "]", GetSecurityStatusString(status),
|
|
|
|
status);
|
2015-07-07 18:17:29 +03:00
|
|
|
}
|
|
|
|
|
2014-06-06 06:54:31 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_MakeSignature(PCtxtHandle phContext, ULONG fQOP,
|
2019-11-06 17:24:51 +03:00
|
|
|
PSecBufferDesc pMessage, ULONG MessageSeqNo)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
char* Name;
|
|
|
|
SECURITY_STATUS status;
|
2021-08-02 13:13:34 +03:00
|
|
|
const SecurityFunctionTableA* table;
|
2019-11-06 17:24:51 +03:00
|
|
|
Name = (char*)sspi_SecureHandleGetUpperPointer(phContext);
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
if (!Name)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
table = sspi_GetSecurityFunctionTableAByNameA(Name);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
2014-06-07 01:20:34 +04:00
|
|
|
if (!table->MakeSignature)
|
2020-08-10 15:59:07 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "[%s]: Security module does not provide an implementation", __FUNCTION__);
|
2014-06-06 06:54:31 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
2020-08-10 15:59:07 +03:00
|
|
|
}
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
status = table->MakeSignature(phContext, fQOP, pMessage, MessageSeqNo);
|
|
|
|
|
2015-09-17 18:16:20 +03:00
|
|
|
if (IsSecurityStatusError(status))
|
2015-07-07 18:17:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "MakeSignature status %s [0x%08" PRIX32 "]", GetSecurityStatusString(status),
|
|
|
|
status);
|
2015-07-07 18:17:29 +03:00
|
|
|
}
|
|
|
|
|
2014-06-06 06:54:31 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2017-11-15 11:11:12 +03:00
|
|
|
static SECURITY_STATUS SEC_ENTRY winpr_VerifySignature(PCtxtHandle phContext,
|
2019-11-06 17:24:51 +03:00
|
|
|
PSecBufferDesc pMessage, ULONG MessageSeqNo,
|
|
|
|
PULONG pfQOP)
|
2014-06-06 06:54:31 +04:00
|
|
|
{
|
|
|
|
char* Name;
|
|
|
|
SECURITY_STATUS status;
|
2021-08-02 13:13:34 +03:00
|
|
|
const SecurityFunctionTableA* table;
|
2019-11-06 17:24:51 +03:00
|
|
|
Name = (char*)sspi_SecureHandleGetUpperPointer(phContext);
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
if (!Name)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
table = sspi_GetSecurityFunctionTableAByNameA(Name);
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
2014-06-07 01:20:34 +04:00
|
|
|
if (!table->VerifySignature)
|
2020-08-10 15:59:07 +03:00
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "[%s]: Security module does not provide an implementation", __FUNCTION__);
|
2014-06-06 06:54:31 +04:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
2020-08-10 15:59:07 +03:00
|
|
|
}
|
2014-06-06 06:54:31 +04:00
|
|
|
|
|
|
|
status = table->VerifySignature(phContext, pMessage, MessageSeqNo, pfQOP);
|
|
|
|
|
2015-09-17 18:16:20 +03:00
|
|
|
if (IsSecurityStatusError(status))
|
2015-07-07 18:17:29 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "VerifySignature status %s [0x%08" PRIX32 "]",
|
2017-05-11 19:51:45 +03:00
|
|
|
GetSecurityStatusString(status), status);
|
2015-07-07 18:17:29 +03:00
|
|
|
}
|
|
|
|
|
2014-06-06 06:54:31 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static SecurityFunctionTableA winpr_SecurityFunctionTableA = {
|
|
|
|
1, /* dwVersion */
|
|
|
|
winpr_EnumerateSecurityPackagesA, /* EnumerateSecurityPackages */
|
2017-12-21 13:30:21 +03:00
|
|
|
winpr_QueryCredentialsAttributesA, /* QueryCredentialsAttributes */
|
2019-11-06 17:24:51 +03:00
|
|
|
winpr_AcquireCredentialsHandleA, /* AcquireCredentialsHandle */
|
|
|
|
winpr_FreeCredentialsHandle, /* FreeCredentialsHandle */
|
|
|
|
NULL, /* Reserved2 */
|
|
|
|
winpr_InitializeSecurityContextA, /* InitializeSecurityContext */
|
|
|
|
winpr_AcceptSecurityContext, /* AcceptSecurityContext */
|
|
|
|
winpr_CompleteAuthToken, /* CompleteAuthToken */
|
|
|
|
winpr_DeleteSecurityContext, /* DeleteSecurityContext */
|
|
|
|
winpr_ApplyControlToken, /* ApplyControlToken */
|
|
|
|
winpr_QueryContextAttributesA, /* QueryContextAttributes */
|
|
|
|
winpr_ImpersonateSecurityContext, /* ImpersonateSecurityContext */
|
|
|
|
winpr_RevertSecurityContext, /* RevertSecurityContext */
|
|
|
|
winpr_MakeSignature, /* MakeSignature */
|
|
|
|
winpr_VerifySignature, /* VerifySignature */
|
|
|
|
winpr_FreeContextBuffer, /* FreeContextBuffer */
|
|
|
|
winpr_QuerySecurityPackageInfoA, /* QuerySecurityPackageInfo */
|
|
|
|
NULL, /* Reserved3 */
|
|
|
|
NULL, /* Reserved4 */
|
|
|
|
winpr_ExportSecurityContext, /* ExportSecurityContext */
|
|
|
|
winpr_ImportSecurityContextA, /* ImportSecurityContext */
|
|
|
|
NULL, /* AddCredentials */
|
|
|
|
NULL, /* Reserved8 */
|
|
|
|
winpr_QuerySecurityContextToken, /* QuerySecurityContextToken */
|
|
|
|
winpr_EncryptMessage, /* EncryptMessage */
|
|
|
|
winpr_DecryptMessage, /* DecryptMessage */
|
|
|
|
winpr_SetContextAttributesA, /* SetContextAttributes */
|
2014-06-06 06:54:31 +04:00
|
|
|
};
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static SecurityFunctionTableW winpr_SecurityFunctionTableW = {
|
|
|
|
1, /* dwVersion */
|
|
|
|
winpr_EnumerateSecurityPackagesW, /* EnumerateSecurityPackages */
|
2017-12-21 13:30:21 +03:00
|
|
|
winpr_QueryCredentialsAttributesW, /* QueryCredentialsAttributes */
|
2019-11-06 17:24:51 +03:00
|
|
|
winpr_AcquireCredentialsHandleW, /* AcquireCredentialsHandle */
|
|
|
|
winpr_FreeCredentialsHandle, /* FreeCredentialsHandle */
|
|
|
|
NULL, /* Reserved2 */
|
|
|
|
winpr_InitializeSecurityContextW, /* InitializeSecurityContext */
|
|
|
|
winpr_AcceptSecurityContext, /* AcceptSecurityContext */
|
|
|
|
winpr_CompleteAuthToken, /* CompleteAuthToken */
|
|
|
|
winpr_DeleteSecurityContext, /* DeleteSecurityContext */
|
|
|
|
winpr_ApplyControlToken, /* ApplyControlToken */
|
|
|
|
winpr_QueryContextAttributesW, /* QueryContextAttributes */
|
|
|
|
winpr_ImpersonateSecurityContext, /* ImpersonateSecurityContext */
|
|
|
|
winpr_RevertSecurityContext, /* RevertSecurityContext */
|
|
|
|
winpr_MakeSignature, /* MakeSignature */
|
|
|
|
winpr_VerifySignature, /* VerifySignature */
|
|
|
|
winpr_FreeContextBuffer, /* FreeContextBuffer */
|
|
|
|
winpr_QuerySecurityPackageInfoW, /* QuerySecurityPackageInfo */
|
|
|
|
NULL, /* Reserved3 */
|
|
|
|
NULL, /* Reserved4 */
|
|
|
|
winpr_ExportSecurityContext, /* ExportSecurityContext */
|
|
|
|
winpr_ImportSecurityContextW, /* ImportSecurityContext */
|
|
|
|
NULL, /* AddCredentials */
|
|
|
|
NULL, /* Reserved8 */
|
|
|
|
winpr_QuerySecurityContextToken, /* QuerySecurityContextToken */
|
|
|
|
winpr_EncryptMessage, /* EncryptMessage */
|
|
|
|
winpr_DecryptMessage, /* DecryptMessage */
|
|
|
|
winpr_SetContextAttributesW, /* SetContextAttributes */
|
2014-06-06 06:54:31 +04:00
|
|
|
};
|