2017-10-18 04:42:16 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2004 Juan Lang
|
2007-08-29 22:18:24 +02:00
|
|
|
* Copyright (C) 2007 Kai Blin
|
2018-01-18 16:53:58 +01:00
|
|
|
* Copyright (C) 2017, 2018 Dmitry Timoshkov
|
2007-08-29 22:18:24 +02:00
|
|
|
*
|
|
|
|
* Local Security Authority functions, as far as secur32 has them.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2021-05-07 11:54:44 +02:00
|
|
|
#include <stdlib.h>
|
2007-08-29 22:18:24 +02:00
|
|
|
|
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2017-10-18 04:42:16 +02:00
|
|
|
#include "winreg.h"
|
|
|
|
#include "sspi.h"
|
2007-08-29 22:18:24 +02:00
|
|
|
#include "ntsecapi.h"
|
2017-10-18 04:42:16 +02:00
|
|
|
#include "ntsecpkg.h"
|
|
|
|
#include "winternl.h"
|
2018-01-18 16:53:58 +01:00
|
|
|
#include "rpc.h"
|
2007-08-29 22:18:24 +02:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
2021-05-07 11:54:44 +02:00
|
|
|
#include "secur32_priv.h"
|
2007-08-29 22:18:24 +02:00
|
|
|
|
2018-01-18 16:53:58 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(secur32);
|
2007-08-29 22:18:24 +02:00
|
|
|
|
2021-09-29 14:13:09 +02:00
|
|
|
#define LSA_MAGIC_CONNECTION ('L' << 24 | 'S' << 16 | 'A' << 8 | '0')
|
|
|
|
#define LSA_MAGIC_CREDENTIALS ('L' << 24 | 'S' << 16 | 'A' << 8 | '1')
|
|
|
|
#define LSA_MAGIC_CONTEXT ('L' << 24 | 'S' << 16 | 'A' << 8 | '2')
|
2017-10-18 04:42:16 +02:00
|
|
|
|
|
|
|
struct lsa_package
|
2007-08-29 22:18:24 +02:00
|
|
|
{
|
2017-10-18 04:42:16 +02:00
|
|
|
ULONG package_id;
|
|
|
|
HMODULE mod;
|
|
|
|
LSA_STRING *name;
|
2018-01-18 16:53:58 +01:00
|
|
|
ULONG lsa_api_version, lsa_table_count, user_api_version, user_table_count;
|
|
|
|
SECPKG_FUNCTION_TABLE *lsa_api;
|
|
|
|
SECPKG_USER_FUNCTION_TABLE *user_api;
|
2017-10-18 04:42:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct lsa_package *loaded_packages;
|
|
|
|
static ULONG loaded_packages_count;
|
|
|
|
|
2021-09-29 14:13:09 +02:00
|
|
|
struct lsa_handle
|
2017-10-18 04:42:16 +02:00
|
|
|
{
|
|
|
|
DWORD magic;
|
2021-09-29 14:13:09 +02:00
|
|
|
struct lsa_package *package;
|
|
|
|
LSA_SEC_HANDLE handle;
|
2017-10-18 04:42:16 +02:00
|
|
|
};
|
|
|
|
|
2018-02-02 11:22:29 +01:00
|
|
|
static const char *debugstr_as(const LSA_STRING *str)
|
|
|
|
{
|
|
|
|
if (!str) return "<null>";
|
|
|
|
return debugstr_an(str->Buffer, str->Length);
|
|
|
|
}
|
|
|
|
|
2017-10-18 04:42:16 +02:00
|
|
|
NTSTATUS WINAPI LsaCallAuthenticationPackage(HANDLE lsa_handle, ULONG package_id,
|
|
|
|
PVOID in_buffer, ULONG in_buffer_length,
|
|
|
|
PVOID *out_buffer, PULONG out_buffer_length, PNTSTATUS status)
|
|
|
|
{
|
|
|
|
ULONG i;
|
|
|
|
|
2022-02-17 07:12:45 +01:00
|
|
|
TRACE("%p,%lu,%p,%lu,%p,%p,%p\n", lsa_handle, package_id, in_buffer,
|
2017-10-18 04:42:16 +02:00
|
|
|
in_buffer_length, out_buffer, out_buffer_length, status);
|
|
|
|
|
|
|
|
for (i = 0; i < loaded_packages_count; i++)
|
|
|
|
{
|
|
|
|
if (loaded_packages[i].package_id == package_id)
|
|
|
|
{
|
2018-01-18 16:53:58 +01:00
|
|
|
if (loaded_packages[i].lsa_api->CallPackageUntrusted)
|
|
|
|
return loaded_packages[i].lsa_api->CallPackageUntrusted(NULL /* FIXME*/,
|
2017-10-18 04:42:16 +02:00
|
|
|
in_buffer, NULL, in_buffer_length, out_buffer, out_buffer_length, status);
|
|
|
|
|
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
2007-08-29 22:18:24 +02:00
|
|
|
}
|
|
|
|
|
2021-09-29 14:13:09 +02:00
|
|
|
static struct lsa_handle *alloc_lsa_handle(ULONG magic)
|
2018-04-18 12:53:57 +02:00
|
|
|
{
|
2021-09-29 14:13:09 +02:00
|
|
|
struct lsa_handle *ret;
|
|
|
|
if (!(ret = calloc(1, sizeof(*ret)))) return NULL;
|
|
|
|
ret->magic = magic;
|
2018-04-18 12:53:57 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-08-29 22:18:24 +02:00
|
|
|
NTSTATUS WINAPI LsaConnectUntrusted(PHANDLE LsaHandle)
|
|
|
|
{
|
2021-09-29 14:13:09 +02:00
|
|
|
struct lsa_handle *lsa_conn;
|
2017-10-18 04:42:16 +02:00
|
|
|
|
|
|
|
TRACE("%p\n", LsaHandle);
|
|
|
|
|
2021-09-29 14:13:09 +02:00
|
|
|
if (!(lsa_conn = alloc_lsa_handle(LSA_MAGIC_CONNECTION))) return STATUS_NO_MEMORY;
|
2017-10-18 04:42:16 +02:00
|
|
|
*LsaHandle = lsa_conn;
|
2018-04-18 12:53:57 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS WINAPI LsaRegisterLogonProcess(PLSA_STRING LogonProcessName,
|
|
|
|
PHANDLE LsaHandle, PLSA_OPERATIONAL_MODE SecurityMode)
|
|
|
|
{
|
2021-09-29 14:13:09 +02:00
|
|
|
struct lsa_handle *lsa_conn;
|
2018-04-18 12:53:57 +02:00
|
|
|
|
|
|
|
FIXME("%s %p %p stub\n", debugstr_as(LogonProcessName), LsaHandle, SecurityMode);
|
2017-10-18 04:42:16 +02:00
|
|
|
|
2021-09-29 14:13:09 +02:00
|
|
|
if (!(lsa_conn = alloc_lsa_handle(LSA_MAGIC_CONNECTION))) return STATUS_NO_MEMORY;
|
2018-04-18 12:53:57 +02:00
|
|
|
*LsaHandle = lsa_conn;
|
2007-08-29 22:18:24 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS WINAPI LsaDeregisterLogonProcess(HANDLE LsaHandle)
|
|
|
|
{
|
2021-09-29 14:13:09 +02:00
|
|
|
struct lsa_handle *lsa_conn = (struct lsa_handle *)LsaHandle;
|
2018-04-18 12:53:56 +02:00
|
|
|
|
|
|
|
TRACE("%p\n", LsaHandle);
|
|
|
|
|
2021-09-29 14:13:09 +02:00
|
|
|
if (!lsa_conn || lsa_conn->magic != LSA_MAGIC_CONNECTION) return STATUS_INVALID_HANDLE;
|
2018-04-18 12:53:56 +02:00
|
|
|
lsa_conn->magic = 0;
|
2021-05-07 11:54:44 +02:00
|
|
|
free(lsa_conn);
|
2018-04-18 12:53:56 +02:00
|
|
|
|
2007-08-29 22:18:24 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-08-29 22:18:36 +02:00
|
|
|
NTSTATUS WINAPI LsaEnumerateLogonSessions(PULONG LogonSessionCount,
|
|
|
|
PLUID* LogonSessionList)
|
|
|
|
{
|
|
|
|
FIXME("%p %p stub\n", LogonSessionCount, LogonSessionList);
|
|
|
|
*LogonSessionCount = 0;
|
|
|
|
*LogonSessionList = NULL;
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-02-01 07:56:15 +01:00
|
|
|
NTSTATUS WINAPI LsaFreeReturnBuffer(PVOID buffer)
|
2007-08-29 22:18:44 +02:00
|
|
|
{
|
2018-02-01 07:56:15 +01:00
|
|
|
TRACE("%p\n", buffer);
|
2021-05-07 11:54:44 +02:00
|
|
|
free(buffer);
|
2007-08-29 22:18:44 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-08-29 22:18:54 +02:00
|
|
|
NTSTATUS WINAPI LsaGetLogonSessionData(PLUID LogonId,
|
|
|
|
PSECURITY_LOGON_SESSION_DATA* ppLogonSessionData)
|
|
|
|
{
|
|
|
|
FIXME("%p %p stub\n", LogonId, ppLogonSessionData);
|
2009-06-03 13:00:36 +02:00
|
|
|
*ppLogonSessionData = NULL;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
2007-08-29 22:18:54 +02:00
|
|
|
}
|
|
|
|
|
2007-08-29 22:19:03 +02:00
|
|
|
NTSTATUS WINAPI LsaLogonUser(HANDLE LsaHandle, PLSA_STRING OriginName,
|
|
|
|
SECURITY_LOGON_TYPE LogonType, ULONG AuthenticationPackage,
|
|
|
|
PVOID AuthenticationInformation, ULONG AuthenticationInformationLength,
|
|
|
|
PTOKEN_GROUPS LocalGroups, PTOKEN_SOURCE SourceContext,
|
|
|
|
PVOID* ProfileBuffer, PULONG ProfileBufferLength, PLUID LogonId,
|
|
|
|
PHANDLE Token, PQUOTA_LIMITS Quotas, PNTSTATUS SubStatus)
|
|
|
|
{
|
2022-02-17 07:12:45 +01:00
|
|
|
FIXME("%p %s %d %ld %p %ld %p %p %p %p %p %p %p %p stub\n", LsaHandle,
|
2018-02-02 11:22:29 +01:00
|
|
|
debugstr_as(OriginName), LogonType, AuthenticationPackage,
|
2007-08-29 22:19:03 +02:00
|
|
|
AuthenticationInformation, AuthenticationInformationLength,
|
|
|
|
LocalGroups, SourceContext, ProfileBuffer, ProfileBufferLength,
|
|
|
|
LogonId, Token, Quotas, SubStatus);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2017-10-18 04:42:16 +02:00
|
|
|
static NTSTATUS NTAPI lsa_CreateLogonSession(LUID *logon_id)
|
|
|
|
{
|
|
|
|
FIXME("%p: stub\n", logon_id);
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS NTAPI lsa_DeleteLogonSession(LUID *logon_id)
|
|
|
|
{
|
|
|
|
FIXME("%p: stub\n", logon_id);
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS NTAPI lsa_AddCredential(LUID *logon_id, ULONG package_id,
|
|
|
|
LSA_STRING *primary_key, LSA_STRING *credentials)
|
|
|
|
{
|
2022-02-17 07:12:45 +01:00
|
|
|
FIXME("%p,%lu,%s,%s: stub\n", logon_id, package_id,
|
2018-02-02 11:22:29 +01:00
|
|
|
debugstr_as(primary_key), debugstr_as(credentials));
|
2017-10-18 04:42:16 +02:00
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS NTAPI lsa_GetCredentials(LUID *logon_id, ULONG package_id, ULONG *context,
|
|
|
|
BOOLEAN retrieve_all, LSA_STRING *primary_key, ULONG *primary_key_len, LSA_STRING *credentials)
|
|
|
|
{
|
2022-02-17 07:12:45 +01:00
|
|
|
FIXME("%p,%#lx,%p,%d,%p,%p,%p: stub\n", logon_id, package_id, context,
|
2017-10-18 04:42:16 +02:00
|
|
|
retrieve_all, primary_key, primary_key_len, credentials);
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS NTAPI lsa_DeleteCredential(LUID *logon_id, ULONG package_id, LSA_STRING *primary_key)
|
|
|
|
{
|
2022-02-17 07:12:45 +01:00
|
|
|
FIXME("%p,%#lx,%s: stub\n", logon_id, package_id, debugstr_as(primary_key));
|
2017-10-18 04:42:16 +02:00
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void * NTAPI lsa_AllocateLsaHeap(ULONG size)
|
|
|
|
{
|
2022-02-17 07:12:45 +01:00
|
|
|
TRACE("%lu\n", size);
|
2021-05-07 11:54:44 +02:00
|
|
|
return malloc(size);
|
2017-10-18 04:42:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void NTAPI lsa_FreeLsaHeap(void *p)
|
|
|
|
{
|
|
|
|
TRACE("%p\n", p);
|
2021-05-07 11:54:44 +02:00
|
|
|
free(p);
|
2017-10-18 04:42:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS NTAPI lsa_AllocateClientBuffer(PLSA_CLIENT_REQUEST req, ULONG size, void **p)
|
|
|
|
{
|
2022-02-17 07:12:45 +01:00
|
|
|
TRACE("%p,%lu,%p\n", req, size, p);
|
2021-05-07 11:54:44 +02:00
|
|
|
*p = malloc(size);
|
2017-10-18 04:42:16 +02:00
|
|
|
return *p ? STATUS_SUCCESS : STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS NTAPI lsa_FreeClientBuffer(PLSA_CLIENT_REQUEST req, void *p)
|
|
|
|
{
|
|
|
|
TRACE("%p,%p\n", req, p);
|
2021-05-07 11:54:44 +02:00
|
|
|
free(p);
|
2017-10-18 04:42:16 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS NTAPI lsa_CopyToClientBuffer(PLSA_CLIENT_REQUEST req, ULONG size, void *client, void *buf)
|
2007-08-29 22:18:24 +02:00
|
|
|
{
|
2022-02-17 07:12:45 +01:00
|
|
|
TRACE("%p,%lu,%p,%p\n", req, size, client, buf);
|
2017-10-18 04:42:16 +02:00
|
|
|
memcpy(client, buf, size);
|
2007-08-29 22:18:24 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2007-08-30 19:58:15 +02:00
|
|
|
|
2017-10-18 04:42:16 +02:00
|
|
|
static NTSTATUS NTAPI lsa_CopyFromClientBuffer(PLSA_CLIENT_REQUEST req, ULONG size, void *buf, void *client)
|
|
|
|
{
|
2022-02-17 07:12:45 +01:00
|
|
|
TRACE("%p,%lu,%p,%p\n", req, size, buf, client);
|
2017-10-18 04:42:16 +02:00
|
|
|
memcpy(buf, client, size);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LSA_DISPATCH_TABLE lsa_dispatch =
|
|
|
|
{
|
|
|
|
lsa_CreateLogonSession,
|
|
|
|
lsa_DeleteLogonSession,
|
|
|
|
lsa_AddCredential,
|
|
|
|
lsa_GetCredentials,
|
|
|
|
lsa_DeleteCredential,
|
|
|
|
lsa_AllocateLsaHeap,
|
|
|
|
lsa_FreeLsaHeap,
|
|
|
|
lsa_AllocateClientBuffer,
|
|
|
|
lsa_FreeClientBuffer,
|
|
|
|
lsa_CopyToClientBuffer,
|
|
|
|
lsa_CopyFromClientBuffer
|
|
|
|
};
|
|
|
|
|
2018-01-18 16:53:58 +01:00
|
|
|
static NTSTATUS NTAPI lsa_RegisterCallback(ULONG callback_id, PLSA_CALLBACK_FUNCTION callback)
|
|
|
|
{
|
2022-02-17 07:12:45 +01:00
|
|
|
FIXME("%lu,%p: stub\n", callback_id, callback);
|
2018-01-18 16:53:58 +01:00
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SECPKG_DLL_FUNCTIONS lsa_dll_dispatch =
|
|
|
|
{
|
|
|
|
lsa_AllocateLsaHeap,
|
|
|
|
lsa_FreeLsaHeap,
|
|
|
|
lsa_RegisterCallback
|
|
|
|
};
|
|
|
|
|
2018-01-18 16:54:01 +01:00
|
|
|
static SECURITY_STATUS lsa_lookup_package(SEC_WCHAR *nameW, struct lsa_package **lsa_package)
|
|
|
|
{
|
|
|
|
ULONG i;
|
|
|
|
UNICODE_STRING package_name, name;
|
|
|
|
|
|
|
|
for (i = 0; i < loaded_packages_count; i++)
|
|
|
|
{
|
|
|
|
if (RtlAnsiStringToUnicodeString(&package_name, loaded_packages[i].name, TRUE))
|
|
|
|
return SEC_E_INSUFFICIENT_MEMORY;
|
|
|
|
|
|
|
|
RtlInitUnicodeString(&name, nameW);
|
|
|
|
|
|
|
|
if (RtlEqualUnicodeString(&package_name, &name, TRUE))
|
|
|
|
{
|
|
|
|
RtlFreeUnicodeString(&package_name);
|
|
|
|
*lsa_package = &loaded_packages[i];
|
|
|
|
return SEC_E_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlFreeUnicodeString(&package_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SECURITY_STATUS WINAPI lsa_AcquireCredentialsHandleW(
|
|
|
|
SEC_WCHAR *principal, SEC_WCHAR *package, ULONG credentials_use,
|
|
|
|
LUID *logon_id, void *auth_data, SEC_GET_KEY_FN get_key_fn,
|
|
|
|
void *get_key_arg, CredHandle *credential, TimeStamp *ts_expiry)
|
|
|
|
{
|
|
|
|
SECURITY_STATUS status;
|
|
|
|
struct lsa_package *lsa_package;
|
2021-09-29 14:13:09 +02:00
|
|
|
struct lsa_handle *lsa_handle;
|
2018-01-18 16:54:01 +01:00
|
|
|
UNICODE_STRING principal_us;
|
|
|
|
LSA_SEC_HANDLE lsa_credential;
|
|
|
|
|
2022-02-17 07:12:45 +01:00
|
|
|
TRACE("%s %s %#lx %p %p %p %p %p\n", debugstr_w(principal), debugstr_w(package),
|
2018-01-18 16:54:01 +01:00
|
|
|
credentials_use, auth_data, get_key_fn, get_key_arg, credential, ts_expiry);
|
|
|
|
|
|
|
|
if (!credential) return SEC_E_INVALID_HANDLE;
|
|
|
|
if (!package) return SEC_E_SECPKG_NOT_FOUND;
|
|
|
|
|
|
|
|
status = lsa_lookup_package(package, &lsa_package);
|
|
|
|
if (status != SEC_E_OK) return status;
|
|
|
|
|
|
|
|
if (!lsa_package->lsa_api || !lsa_package->lsa_api->SpAcquireCredentialsHandle)
|
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
|
|
|
|
|
|
|
if (principal)
|
|
|
|
RtlInitUnicodeString(&principal_us, principal);
|
|
|
|
|
|
|
|
status = lsa_package->lsa_api->SpAcquireCredentialsHandle(principal ? &principal_us : NULL,
|
|
|
|
credentials_use, logon_id, auth_data, get_key_fn, get_key_arg, &lsa_credential, ts_expiry);
|
|
|
|
if (status == SEC_E_OK)
|
|
|
|
{
|
2021-09-29 14:13:09 +02:00
|
|
|
if (!(lsa_handle = alloc_lsa_handle(LSA_MAGIC_CREDENTIALS))) return STATUS_NO_MEMORY;
|
|
|
|
lsa_handle->package = lsa_package;
|
|
|
|
lsa_handle->handle = lsa_credential;
|
|
|
|
credential->dwLower = (ULONG_PTR)lsa_handle;
|
|
|
|
credential->dwUpper = 0;
|
2018-01-18 16:54:01 +01:00
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SECURITY_STATUS WINAPI lsa_AcquireCredentialsHandleA(
|
|
|
|
SEC_CHAR *principal, SEC_CHAR *package, ULONG credentials_use,
|
|
|
|
LUID *logon_id, void *auth_data, SEC_GET_KEY_FN get_key_fn,
|
|
|
|
void *get_key_arg, CredHandle *credential, TimeStamp *ts_expiry)
|
|
|
|
{
|
|
|
|
SECURITY_STATUS status = SEC_E_INSUFFICIENT_MEMORY;
|
|
|
|
int len_user = 0, len_domain = 0, len_passwd = 0;
|
|
|
|
SEC_WCHAR *principalW = NULL, *packageW = NULL, *user = NULL, *domain = NULL, *passwd = NULL;
|
|
|
|
SEC_WINNT_AUTH_IDENTITY_W *auth_dataW = NULL;
|
|
|
|
SEC_WINNT_AUTH_IDENTITY_A *id = NULL;
|
|
|
|
|
2022-02-17 07:12:45 +01:00
|
|
|
TRACE("%s %s %#lx %p %p %p %p %p\n", debugstr_a(principal), debugstr_a(package),
|
2018-01-18 16:54:01 +01:00
|
|
|
credentials_use, auth_data, get_key_fn, get_key_arg, credential, ts_expiry);
|
|
|
|
|
|
|
|
if (principal)
|
|
|
|
{
|
|
|
|
int len = MultiByteToWideChar( CP_ACP, 0, principal, -1, NULL, 0 );
|
2021-05-07 11:54:44 +02:00
|
|
|
if (!(principalW = malloc( len * sizeof(SEC_WCHAR) ))) goto done;
|
2018-01-18 16:54:01 +01:00
|
|
|
MultiByteToWideChar( CP_ACP, 0, principal, -1, principalW, len );
|
|
|
|
}
|
|
|
|
if (package)
|
|
|
|
{
|
|
|
|
int len = MultiByteToWideChar( CP_ACP, 0, package, -1, NULL, 0 );
|
2021-05-07 11:54:44 +02:00
|
|
|
if (!(packageW = malloc( len * sizeof(SEC_WCHAR) ))) goto done;
|
2018-01-18 16:54:01 +01:00
|
|
|
MultiByteToWideChar( CP_ACP, 0, package, -1, packageW, len );
|
|
|
|
}
|
|
|
|
if (auth_data)
|
|
|
|
{
|
|
|
|
id = (PSEC_WINNT_AUTH_IDENTITY_A)auth_data;
|
|
|
|
|
|
|
|
if (id->Flags == SEC_WINNT_AUTH_IDENTITY_ANSI)
|
|
|
|
{
|
2021-05-07 11:54:44 +02:00
|
|
|
if (!(auth_dataW = malloc( sizeof(SEC_WINNT_AUTH_IDENTITY_W) ))) goto done;
|
2018-01-18 16:54:01 +01:00
|
|
|
if (id->UserLength)
|
|
|
|
{
|
|
|
|
len_user = MultiByteToWideChar( CP_ACP, 0, (char *)id->User, id->UserLength, NULL, 0 );
|
2021-05-07 11:54:44 +02:00
|
|
|
if (!(user = malloc( len_user * sizeof(SEC_WCHAR) ))) goto done;
|
2018-01-18 16:54:01 +01:00
|
|
|
MultiByteToWideChar( CP_ACP, 0, (char *)id->User, id->UserLength, user, len_user );
|
|
|
|
}
|
|
|
|
if (id->DomainLength)
|
|
|
|
{
|
|
|
|
len_domain = MultiByteToWideChar( CP_ACP, 0, (char *)id->Domain, id->DomainLength, NULL, 0 );
|
2021-05-07 11:54:44 +02:00
|
|
|
if (!(domain = malloc( len_domain * sizeof(SEC_WCHAR) ))) goto done;
|
2018-01-18 16:54:01 +01:00
|
|
|
MultiByteToWideChar( CP_ACP, 0, (char *)id->Domain, id->DomainLength, domain, len_domain );
|
|
|
|
}
|
|
|
|
if (id->PasswordLength)
|
|
|
|
{
|
|
|
|
len_passwd = MultiByteToWideChar( CP_ACP, 0, (char *)id->Password, id->PasswordLength, NULL, 0 );
|
2021-05-07 11:54:44 +02:00
|
|
|
if (!(passwd = malloc( len_passwd * sizeof(SEC_WCHAR) ))) goto done;
|
2018-01-18 16:54:01 +01:00
|
|
|
MultiByteToWideChar( CP_ACP, 0, (char *)id->Password, id->PasswordLength, passwd, len_passwd );
|
|
|
|
}
|
|
|
|
auth_dataW->Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
|
|
|
|
auth_dataW->User = user;
|
|
|
|
auth_dataW->UserLength = len_user;
|
|
|
|
auth_dataW->Domain = domain;
|
|
|
|
auth_dataW->DomainLength = len_domain;
|
|
|
|
auth_dataW->Password = passwd;
|
|
|
|
auth_dataW->PasswordLength = len_passwd;
|
|
|
|
}
|
|
|
|
else auth_dataW = (PSEC_WINNT_AUTH_IDENTITY_W)auth_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = lsa_AcquireCredentialsHandleW( principalW, packageW, credentials_use, logon_id, auth_dataW, get_key_fn,
|
|
|
|
get_key_arg, credential, ts_expiry );
|
|
|
|
done:
|
2021-05-07 11:54:44 +02:00
|
|
|
if (auth_dataW != (SEC_WINNT_AUTH_IDENTITY_W *)id) free( auth_dataW );
|
|
|
|
free( packageW );
|
|
|
|
free( principalW );
|
|
|
|
free( user );
|
|
|
|
free( domain );
|
|
|
|
free( passwd );
|
2018-01-18 16:54:01 +01:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2018-01-18 16:54:05 +01:00
|
|
|
static SECURITY_STATUS WINAPI lsa_FreeCredentialsHandle(CredHandle *credential)
|
|
|
|
{
|
2021-09-29 14:13:09 +02:00
|
|
|
struct lsa_handle *lsa_cred;
|
|
|
|
SECURITY_STATUS status;
|
2018-01-18 16:54:05 +01:00
|
|
|
|
|
|
|
TRACE("%p\n", credential);
|
|
|
|
if (!credential) return SEC_E_INVALID_HANDLE;
|
|
|
|
|
2021-09-29 14:13:09 +02:00
|
|
|
lsa_cred = (struct lsa_handle *)credential->dwLower;
|
|
|
|
if (!lsa_cred || lsa_cred->magic != LSA_MAGIC_CREDENTIALS) return SEC_E_INVALID_HANDLE;
|
2018-01-18 16:54:05 +01:00
|
|
|
|
2021-09-29 14:13:09 +02:00
|
|
|
if (!lsa_cred->package->lsa_api || !lsa_cred->package->lsa_api->FreeCredentialsHandle)
|
2018-01-18 16:54:05 +01:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
|
|
|
|
2021-09-29 14:13:09 +02:00
|
|
|
status = lsa_cred->package->lsa_api->FreeCredentialsHandle(lsa_cred->handle);
|
|
|
|
|
|
|
|
lsa_cred->magic = 0;
|
|
|
|
free(lsa_cred);
|
|
|
|
return status;
|
2018-01-18 16:54:05 +01:00
|
|
|
}
|
|
|
|
|
2018-02-01 11:03:48 +01:00
|
|
|
static SECURITY_STATUS WINAPI lsa_InitializeSecurityContextW(
|
|
|
|
CredHandle *credential, CtxtHandle *context, SEC_WCHAR *target_name, ULONG context_req,
|
|
|
|
ULONG reserved1, ULONG target_data_rep, SecBufferDesc *input, ULONG reserved2,
|
|
|
|
CtxtHandle *new_context, SecBufferDesc *output, ULONG *context_attr, TimeStamp *ts_expiry)
|
|
|
|
{
|
|
|
|
SECURITY_STATUS status;
|
2021-09-29 14:13:09 +02:00
|
|
|
struct lsa_handle *lsa_cred = NULL, *lsa_ctx = NULL, *new_lsa_ctx;
|
|
|
|
struct lsa_package *package = NULL;
|
2018-02-01 11:03:48 +01:00
|
|
|
UNICODE_STRING target_name_us;
|
|
|
|
BOOLEAN mapped_context;
|
2021-09-29 14:13:09 +02:00
|
|
|
LSA_SEC_HANDLE new_handle;
|
2018-02-01 11:03:48 +01:00
|
|
|
|
2022-02-17 07:12:45 +01:00
|
|
|
TRACE("%p %p %s %#lx %ld %ld %p %ld %p %p %p %p\n", credential, context,
|
2018-02-01 11:03:48 +01:00
|
|
|
debugstr_w(target_name), context_req, reserved1, target_data_rep, input,
|
|
|
|
reserved2, new_context, output, context_attr, ts_expiry);
|
|
|
|
|
|
|
|
if (context)
|
|
|
|
{
|
2021-09-29 14:13:09 +02:00
|
|
|
lsa_ctx = (struct lsa_handle *)context->dwLower;
|
|
|
|
if (lsa_ctx->magic != LSA_MAGIC_CONTEXT) return SEC_E_INVALID_HANDLE;
|
|
|
|
package = lsa_ctx->package;
|
2018-02-01 11:03:48 +01:00
|
|
|
}
|
|
|
|
else if (credential)
|
|
|
|
{
|
2021-09-29 14:13:09 +02:00
|
|
|
lsa_cred = (struct lsa_handle *)credential->dwLower;
|
|
|
|
if (lsa_cred->magic != LSA_MAGIC_CREDENTIALS) return SEC_E_INVALID_HANDLE;
|
|
|
|
package = lsa_cred->package;
|
2018-02-01 11:03:48 +01:00
|
|
|
}
|
2021-09-29 14:13:09 +02:00
|
|
|
if (!package || !new_context) return SEC_E_INVALID_HANDLE;
|
2018-02-01 11:03:48 +01:00
|
|
|
|
2021-09-29 14:13:09 +02:00
|
|
|
if (!package->lsa_api || !package->lsa_api->InitLsaModeContext)
|
2018-02-01 11:03:48 +01:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
|
|
|
|
|
|
|
if (target_name)
|
|
|
|
RtlInitUnicodeString(&target_name_us, target_name);
|
|
|
|
|
2021-09-29 14:13:09 +02:00
|
|
|
status = package->lsa_api->InitLsaModeContext(lsa_cred ? lsa_cred->handle : 0,
|
|
|
|
lsa_ctx ? lsa_ctx->handle : 0, target_name ? &target_name_us : NULL, context_req, target_data_rep,
|
|
|
|
input, &new_handle, output, context_attr, ts_expiry, &mapped_context, NULL /* FIXME */);
|
2018-02-01 11:03:48 +01:00
|
|
|
if (status == SEC_E_OK || status == SEC_I_CONTINUE_NEEDED)
|
|
|
|
{
|
2021-09-29 14:13:09 +02:00
|
|
|
if (!(new_lsa_ctx = alloc_lsa_handle(LSA_MAGIC_CONTEXT))) return STATUS_NO_MEMORY;
|
|
|
|
new_lsa_ctx->package = package;
|
|
|
|
new_lsa_ctx->handle = new_handle;
|
|
|
|
new_context->dwLower = (ULONG_PTR)new_lsa_ctx;
|
|
|
|
new_context->dwUpper = 0;
|
2018-02-01 11:03:48 +01:00
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SECURITY_STATUS WINAPI lsa_InitializeSecurityContextA(
|
|
|
|
CredHandle *credential, CtxtHandle *context, SEC_CHAR *target_name, ULONG context_req,
|
|
|
|
ULONG reserved1, ULONG target_data_rep, SecBufferDesc *input, ULONG reserved2,
|
|
|
|
CtxtHandle *new_context, SecBufferDesc *output, ULONG *context_attr, TimeStamp *ts_expiry)
|
|
|
|
{
|
|
|
|
SECURITY_STATUS status;
|
|
|
|
SEC_WCHAR *targetW = NULL;
|
|
|
|
|
2022-02-17 07:12:45 +01:00
|
|
|
TRACE("%p %p %s %#lx %ld %ld %p %ld %p %p %p %p\n", credential, context,
|
2018-02-01 11:03:48 +01:00
|
|
|
debugstr_a(target_name), context_req, reserved1, target_data_rep, input,
|
|
|
|
reserved2, new_context, output, context_attr, ts_expiry);
|
|
|
|
|
|
|
|
if (target_name)
|
|
|
|
{
|
|
|
|
int len = MultiByteToWideChar( CP_ACP, 0, target_name, -1, NULL, 0 );
|
2021-05-07 11:54:44 +02:00
|
|
|
if (!(targetW = malloc( len * sizeof(SEC_WCHAR) ))) return SEC_E_INSUFFICIENT_MEMORY;
|
2018-02-01 11:03:48 +01:00
|
|
|
MultiByteToWideChar( CP_ACP, 0, target_name, -1, targetW, len );
|
|
|
|
}
|
|
|
|
|
|
|
|
status = lsa_InitializeSecurityContextW( credential, context, targetW, context_req, reserved1, target_data_rep,
|
|
|
|
input, reserved2, new_context, output, context_attr, ts_expiry );
|
2021-05-07 11:54:44 +02:00
|
|
|
free( targetW );
|
2018-02-01 11:03:48 +01:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2018-02-01 11:04:00 +01:00
|
|
|
static SECURITY_STATUS WINAPI lsa_AcceptSecurityContext(
|
|
|
|
CredHandle *credential, CtxtHandle *context, SecBufferDesc *input,
|
|
|
|
ULONG context_req, ULONG target_data_rep, CtxtHandle *new_context,
|
|
|
|
SecBufferDesc *output, ULONG *context_attr, TimeStamp *ts_expiry)
|
|
|
|
{
|
|
|
|
SECURITY_STATUS status;
|
2021-09-29 14:13:09 +02:00
|
|
|
struct lsa_package *package = NULL;
|
|
|
|
struct lsa_handle *lsa_cred = NULL, *lsa_ctx = NULL, *new_lsa_ctx;
|
2018-02-01 11:04:00 +01:00
|
|
|
BOOLEAN mapped_context;
|
2021-09-29 14:13:09 +02:00
|
|
|
LSA_SEC_HANDLE new_handle;
|
2018-02-01 11:04:00 +01:00
|
|
|
|
2022-02-17 07:12:45 +01:00
|
|
|
TRACE("%p %p %p %#lx %#lx %p %p %p %p\n", credential, context, input,
|
2018-02-01 11:04:00 +01:00
|
|
|
context_req, target_data_rep, new_context, output, context_attr, ts_expiry);
|
|
|
|
|
|
|
|
if (context)
|
|
|
|
{
|
2021-09-29 14:13:09 +02:00
|
|
|
lsa_ctx = (struct lsa_handle *)context->dwLower;
|
|
|
|
if (lsa_ctx->magic != LSA_MAGIC_CONTEXT) return SEC_E_INVALID_HANDLE;
|
|
|
|
package = lsa_ctx->package;
|
2018-02-01 11:04:00 +01:00
|
|
|
}
|
|
|
|
else if (credential)
|
|
|
|
{
|
2021-09-29 14:13:09 +02:00
|
|
|
lsa_cred = (struct lsa_handle *)credential->dwLower;
|
|
|
|
if (lsa_cred->magic != LSA_MAGIC_CREDENTIALS) return SEC_E_INVALID_HANDLE;
|
|
|
|
package = lsa_cred->package;
|
2018-02-01 11:04:00 +01:00
|
|
|
}
|
2021-09-29 14:13:09 +02:00
|
|
|
if (!package || !new_context) return SEC_E_INVALID_HANDLE;
|
2018-02-01 11:04:00 +01:00
|
|
|
|
2021-09-29 14:13:09 +02:00
|
|
|
if (!package->lsa_api || !package->lsa_api->AcceptLsaModeContext)
|
2018-02-01 11:04:00 +01:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
|
|
|
|
2021-09-29 14:13:09 +02:00
|
|
|
status = package->lsa_api->AcceptLsaModeContext(lsa_cred ? lsa_cred->handle : 0,
|
|
|
|
lsa_ctx ? lsa_ctx->handle : 0, input, context_req, target_data_rep, &new_handle, output,
|
|
|
|
context_attr, ts_expiry, &mapped_context, NULL /* FIXME */);
|
2018-02-01 11:04:00 +01:00
|
|
|
if (status == SEC_E_OK || status == SEC_I_CONTINUE_NEEDED)
|
|
|
|
{
|
2021-09-29 14:13:09 +02:00
|
|
|
if (!(new_lsa_ctx = alloc_lsa_handle(LSA_MAGIC_CONTEXT))) return STATUS_NO_MEMORY;
|
|
|
|
new_lsa_ctx->package = package;
|
|
|
|
new_lsa_ctx->handle = new_handle;
|
|
|
|
new_context->dwLower = (ULONG_PTR)new_lsa_ctx;
|
|
|
|
new_context->dwUpper = 0;
|
2018-02-01 11:04:00 +01:00
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2018-02-01 11:03:54 +01:00
|
|
|
static SECURITY_STATUS WINAPI lsa_DeleteSecurityContext(CtxtHandle *context)
|
|
|
|
{
|
2021-09-29 14:13:09 +02:00
|
|
|
struct lsa_handle *lsa_ctx;
|
|
|
|
SECURITY_STATUS status;
|
2018-02-01 11:03:54 +01:00
|
|
|
|
|
|
|
TRACE("%p\n", context);
|
|
|
|
|
|
|
|
if (!context) return SEC_E_INVALID_HANDLE;
|
2021-09-29 14:13:09 +02:00
|
|
|
lsa_ctx = (struct lsa_handle *)context->dwLower;
|
|
|
|
if (!lsa_ctx || lsa_ctx->magic != LSA_MAGIC_CONTEXT) return SEC_E_INVALID_HANDLE;
|
2018-02-01 11:03:54 +01:00
|
|
|
|
2021-09-29 14:13:09 +02:00
|
|
|
if (!lsa_ctx->package->lsa_api || !lsa_ctx->package->lsa_api->DeleteContext)
|
2018-02-01 11:03:54 +01:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
|
|
|
|
2021-09-29 14:13:09 +02:00
|
|
|
status = lsa_ctx->package->lsa_api->DeleteContext(lsa_ctx->handle);
|
|
|
|
free(lsa_ctx);
|
|
|
|
return status;
|
2018-02-01 11:03:54 +01:00
|
|
|
}
|
|
|
|
|
2018-02-01 11:04:07 +01:00
|
|
|
static SECURITY_STATUS WINAPI lsa_QueryContextAttributesW(CtxtHandle *context, ULONG attribute, void *buffer)
|
|
|
|
{
|
2021-09-29 14:13:09 +02:00
|
|
|
struct lsa_handle *lsa_ctx;
|
2018-02-01 11:04:07 +01:00
|
|
|
|
2022-02-17 07:12:45 +01:00
|
|
|
TRACE("%p %ld %p\n", context, attribute, buffer);
|
2018-02-01 11:04:07 +01:00
|
|
|
|
|
|
|
if (!context) return SEC_E_INVALID_HANDLE;
|
2021-09-29 14:13:09 +02:00
|
|
|
lsa_ctx = (struct lsa_handle *)context->dwLower;
|
|
|
|
if (!lsa_ctx || lsa_ctx->magic != LSA_MAGIC_CONTEXT) return SEC_E_INVALID_HANDLE;
|
2018-02-01 11:04:07 +01:00
|
|
|
|
2021-09-29 14:13:09 +02:00
|
|
|
if (!lsa_ctx->package->lsa_api || !lsa_ctx->package->lsa_api->SpQueryContextAttributes)
|
2018-02-01 11:04:07 +01:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
|
|
|
|
2021-09-29 14:13:09 +02:00
|
|
|
return lsa_ctx->package->lsa_api->SpQueryContextAttributes(lsa_ctx->handle, attribute, buffer);
|
2018-02-01 11:04:07 +01:00
|
|
|
}
|
|
|
|
|
2018-02-08 11:54:00 +01:00
|
|
|
static SecPkgInfoA *package_infoWtoA( const SecPkgInfoW *info )
|
|
|
|
{
|
|
|
|
SecPkgInfoA *ret;
|
|
|
|
int size_name = WideCharToMultiByte( CP_ACP, 0, info->Name, -1, NULL, 0, NULL, NULL );
|
|
|
|
int size_comment = WideCharToMultiByte( CP_ACP, 0, info->Comment, -1, NULL, 0, NULL, NULL );
|
|
|
|
|
2021-05-07 11:54:44 +02:00
|
|
|
/* freed with FreeContextBuffer */
|
|
|
|
if (!(ret = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*ret) + size_name + size_comment ))) return NULL;
|
2018-02-08 11:54:00 +01:00
|
|
|
ret->fCapabilities = info->fCapabilities;
|
|
|
|
ret->wVersion = info->wVersion;
|
|
|
|
ret->wRPCID = info->wRPCID;
|
|
|
|
ret->cbMaxToken = info->cbMaxToken;
|
|
|
|
ret->Name = (SEC_CHAR *)(ret + 1);
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, info->Name, -1, ret->Name, size_name, NULL, NULL );
|
|
|
|
ret->Comment = ret->Name + size_name;
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, info->Comment, -1, ret->Comment, size_comment, NULL, NULL );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SECURITY_STATUS nego_info_WtoA( const SecPkgContext_NegotiationInfoW *infoW,
|
|
|
|
SecPkgContext_NegotiationInfoA *infoA )
|
|
|
|
{
|
|
|
|
infoA->NegotiationState = infoW->NegotiationState;
|
|
|
|
if (!(infoA->PackageInfo = package_infoWtoA( infoW->PackageInfo ))) return SEC_E_INSUFFICIENT_MEMORY;
|
|
|
|
return SEC_E_OK;
|
|
|
|
}
|
|
|
|
|
2018-02-01 11:04:07 +01:00
|
|
|
static SECURITY_STATUS WINAPI lsa_QueryContextAttributesA(CtxtHandle *context, ULONG attribute, void *buffer)
|
|
|
|
{
|
2022-02-17 07:12:45 +01:00
|
|
|
TRACE("%p %ld %p\n", context, attribute, buffer);
|
2018-02-01 11:04:07 +01:00
|
|
|
|
|
|
|
if (!context) return SEC_E_INVALID_HANDLE;
|
|
|
|
|
|
|
|
switch (attribute)
|
|
|
|
{
|
|
|
|
case SECPKG_ATTR_SIZES:
|
|
|
|
return lsa_QueryContextAttributesW( context, attribute, buffer );
|
|
|
|
|
2018-02-08 11:54:00 +01:00
|
|
|
case SECPKG_ATTR_NEGOTIATION_INFO:
|
|
|
|
{
|
|
|
|
SecPkgContext_NegotiationInfoW infoW;
|
|
|
|
SecPkgContext_NegotiationInfoA *infoA = (SecPkgContext_NegotiationInfoA *)buffer;
|
|
|
|
SECURITY_STATUS status = lsa_QueryContextAttributesW( context, SECPKG_ATTR_NEGOTIATION_INFO, &infoW );
|
|
|
|
|
|
|
|
if (status != SEC_E_OK) return status;
|
|
|
|
status = nego_info_WtoA( &infoW, infoA );
|
|
|
|
FreeContextBuffer( infoW.PackageInfo );
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2018-02-01 11:04:07 +01:00
|
|
|
#define X(x) case (x) : FIXME(#x" stub\n"); break
|
|
|
|
X(SECPKG_ATTR_ACCESS_TOKEN);
|
|
|
|
X(SECPKG_ATTR_AUTHORITY);
|
|
|
|
X(SECPKG_ATTR_DCE_INFO);
|
|
|
|
X(SECPKG_ATTR_KEY_INFO);
|
|
|
|
X(SECPKG_ATTR_LIFESPAN);
|
|
|
|
X(SECPKG_ATTR_NAMES);
|
|
|
|
X(SECPKG_ATTR_NATIVE_NAMES);
|
|
|
|
X(SECPKG_ATTR_PACKAGE_INFO);
|
|
|
|
X(SECPKG_ATTR_PASSWORD_EXPIRY);
|
|
|
|
X(SECPKG_ATTR_SESSION_KEY);
|
|
|
|
X(SECPKG_ATTR_STREAM_SIZES);
|
|
|
|
X(SECPKG_ATTR_TARGET_INFORMATION);
|
|
|
|
#undef X
|
|
|
|
default:
|
2022-02-17 07:12:45 +01:00
|
|
|
FIXME( "unknown attribute %lu\n", attribute );
|
2018-02-01 11:04:07 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
|
|
|
}
|
|
|
|
|
2018-02-01 11:04:12 +01:00
|
|
|
static SECURITY_STATUS WINAPI lsa_MakeSignature(CtxtHandle *context, ULONG quality_of_protection,
|
|
|
|
SecBufferDesc *message, ULONG message_seq_no)
|
|
|
|
{
|
2021-09-29 14:13:09 +02:00
|
|
|
struct lsa_handle *lsa_ctx;
|
2018-02-01 11:04:12 +01:00
|
|
|
|
2022-02-17 07:12:45 +01:00
|
|
|
TRACE("%p %#lx %p %lu)\n", context, quality_of_protection, message, message_seq_no);
|
2018-02-01 11:04:12 +01:00
|
|
|
|
|
|
|
if (!context) return SEC_E_INVALID_HANDLE;
|
2021-09-29 14:13:09 +02:00
|
|
|
lsa_ctx = (struct lsa_handle *)context->dwLower;
|
|
|
|
if (!lsa_ctx || lsa_ctx->magic != LSA_MAGIC_CONTEXT) return SEC_E_INVALID_HANDLE;
|
2018-02-01 11:04:12 +01:00
|
|
|
|
2021-09-29 14:13:09 +02:00
|
|
|
if (!lsa_ctx->package->user_api || !lsa_ctx->package->user_api->MakeSignature)
|
2018-02-01 11:04:12 +01:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
|
|
|
|
2021-09-29 14:13:09 +02:00
|
|
|
return lsa_ctx->package->user_api->MakeSignature(lsa_ctx->handle, quality_of_protection, message, message_seq_no);
|
2018-02-01 11:04:12 +01:00
|
|
|
}
|
|
|
|
|
2018-02-01 11:04:17 +01:00
|
|
|
static SECURITY_STATUS WINAPI lsa_VerifySignature(CtxtHandle *context, SecBufferDesc *message,
|
|
|
|
ULONG message_seq_no, ULONG *quality_of_protection)
|
|
|
|
{
|
2021-09-29 14:13:09 +02:00
|
|
|
struct lsa_handle *lsa_ctx;
|
2018-02-01 11:04:17 +01:00
|
|
|
|
2022-02-17 07:12:45 +01:00
|
|
|
TRACE("%p %p %lu %p)\n", context, message, message_seq_no, quality_of_protection);
|
2018-02-01 11:04:17 +01:00
|
|
|
|
|
|
|
if (!context) return SEC_E_INVALID_HANDLE;
|
2021-09-29 14:13:09 +02:00
|
|
|
lsa_ctx = (struct lsa_handle *)context->dwLower;
|
|
|
|
if (!lsa_ctx || lsa_ctx->magic != LSA_MAGIC_CONTEXT) return SEC_E_INVALID_HANDLE;
|
2018-02-01 11:04:17 +01:00
|
|
|
|
2021-09-29 14:13:09 +02:00
|
|
|
if (!lsa_ctx->package->user_api || !lsa_ctx->package->user_api->VerifySignature)
|
2018-02-01 11:04:17 +01:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
|
|
|
|
2021-09-29 14:13:09 +02:00
|
|
|
return lsa_ctx->package->user_api->VerifySignature(lsa_ctx->handle, message, message_seq_no, quality_of_protection);
|
2018-02-01 11:04:17 +01:00
|
|
|
}
|
|
|
|
|
2018-02-01 11:04:22 +01:00
|
|
|
static SECURITY_STATUS WINAPI lsa_EncryptMessage(CtxtHandle *context, ULONG quality_of_protection,
|
|
|
|
SecBufferDesc *message, ULONG message_seq_no)
|
|
|
|
{
|
2021-09-29 14:13:09 +02:00
|
|
|
struct lsa_handle *lsa_ctx;
|
2018-02-01 11:04:22 +01:00
|
|
|
|
2022-02-17 07:12:45 +01:00
|
|
|
TRACE("%p %#lx %p %lu)\n", context, quality_of_protection, message, message_seq_no);
|
2018-02-01 11:04:22 +01:00
|
|
|
|
|
|
|
if (!context) return SEC_E_INVALID_HANDLE;
|
2021-09-29 14:13:09 +02:00
|
|
|
lsa_ctx = (struct lsa_handle *)context->dwLower;
|
|
|
|
if (!lsa_ctx || lsa_ctx->magic != LSA_MAGIC_CONTEXT) return SEC_E_INVALID_HANDLE;
|
2018-02-01 11:04:22 +01:00
|
|
|
|
2021-09-29 14:13:09 +02:00
|
|
|
if (!lsa_ctx->package->user_api || !lsa_ctx->package->user_api->SealMessage)
|
2018-02-01 11:04:22 +01:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
|
|
|
|
2021-09-29 14:13:09 +02:00
|
|
|
return lsa_ctx->package->user_api->SealMessage(lsa_ctx->handle, quality_of_protection, message, message_seq_no);
|
2018-02-01 11:04:22 +01:00
|
|
|
}
|
|
|
|
|
2018-02-01 11:04:28 +01:00
|
|
|
static SECURITY_STATUS WINAPI lsa_DecryptMessage(CtxtHandle *context, SecBufferDesc *message,
|
|
|
|
ULONG message_seq_no, ULONG *quality_of_protection)
|
|
|
|
{
|
2021-09-29 14:13:09 +02:00
|
|
|
struct lsa_handle *lsa_ctx;
|
2018-02-01 11:04:28 +01:00
|
|
|
|
2022-02-17 07:12:45 +01:00
|
|
|
TRACE("%p %p %lu %p)\n", context, message, message_seq_no, quality_of_protection);
|
2018-02-01 11:04:28 +01:00
|
|
|
|
|
|
|
if (!context) return SEC_E_INVALID_HANDLE;
|
2021-09-29 14:13:09 +02:00
|
|
|
lsa_ctx = (struct lsa_handle *)context->dwLower;
|
|
|
|
if (!lsa_ctx || lsa_ctx->magic != LSA_MAGIC_CONTEXT) return SEC_E_INVALID_HANDLE;
|
2018-02-01 11:04:28 +01:00
|
|
|
|
2021-09-29 14:13:09 +02:00
|
|
|
if (!lsa_ctx->package->user_api || !lsa_ctx->package->user_api->UnsealMessage)
|
2018-02-01 11:04:28 +01:00
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
|
|
|
|
2021-09-29 14:13:09 +02:00
|
|
|
return lsa_ctx->package->user_api->UnsealMessage(lsa_ctx->handle, message, message_seq_no, quality_of_protection);
|
2018-02-01 11:04:28 +01:00
|
|
|
}
|
|
|
|
|
2018-01-18 16:53:58 +01:00
|
|
|
static const SecurityFunctionTableW lsa_sspi_tableW =
|
|
|
|
{
|
|
|
|
1,
|
|
|
|
NULL, /* EnumerateSecurityPackagesW */
|
|
|
|
NULL, /* QueryCredentialsAttributesW */
|
2018-01-18 16:54:01 +01:00
|
|
|
lsa_AcquireCredentialsHandleW,
|
2018-01-18 16:54:05 +01:00
|
|
|
lsa_FreeCredentialsHandle,
|
2018-01-18 16:53:58 +01:00
|
|
|
NULL, /* Reserved2 */
|
2018-02-01 11:03:48 +01:00
|
|
|
lsa_InitializeSecurityContextW,
|
2018-02-01 11:04:00 +01:00
|
|
|
lsa_AcceptSecurityContext,
|
2018-01-18 16:53:58 +01:00
|
|
|
NULL, /* CompleteAuthToken */
|
2018-02-01 11:03:54 +01:00
|
|
|
lsa_DeleteSecurityContext,
|
2018-01-18 16:53:58 +01:00
|
|
|
NULL, /* ApplyControlToken */
|
2018-02-01 11:04:07 +01:00
|
|
|
lsa_QueryContextAttributesW,
|
2018-01-18 16:53:58 +01:00
|
|
|
NULL, /* ImpersonateSecurityContext */
|
|
|
|
NULL, /* RevertSecurityContext */
|
2018-02-01 11:04:12 +01:00
|
|
|
lsa_MakeSignature,
|
2018-02-01 11:04:17 +01:00
|
|
|
lsa_VerifySignature,
|
2018-01-18 16:53:58 +01:00
|
|
|
NULL, /* FreeContextBuffer */
|
|
|
|
NULL, /* QuerySecurityPackageInfoW */
|
|
|
|
NULL, /* Reserved3 */
|
|
|
|
NULL, /* Reserved4 */
|
|
|
|
NULL, /* ExportSecurityContext */
|
|
|
|
NULL, /* ImportSecurityContextW */
|
|
|
|
NULL, /* AddCredentialsW */
|
|
|
|
NULL, /* Reserved8 */
|
|
|
|
NULL, /* QuerySecurityContextToken */
|
2018-02-01 11:04:22 +01:00
|
|
|
lsa_EncryptMessage,
|
2018-02-01 11:04:28 +01:00
|
|
|
lsa_DecryptMessage,
|
2018-01-18 16:53:58 +01:00
|
|
|
NULL, /* SetContextAttributesW */
|
|
|
|
};
|
|
|
|
|
|
|
|
static const SecurityFunctionTableA lsa_sspi_tableA =
|
|
|
|
{
|
|
|
|
1,
|
|
|
|
NULL, /* EnumerateSecurityPackagesA */
|
|
|
|
NULL, /* QueryCredentialsAttributesA */
|
2018-01-18 16:54:01 +01:00
|
|
|
lsa_AcquireCredentialsHandleA,
|
2018-01-18 16:54:05 +01:00
|
|
|
lsa_FreeCredentialsHandle,
|
2018-01-18 16:53:58 +01:00
|
|
|
NULL, /* Reserved2 */
|
2018-02-01 11:03:48 +01:00
|
|
|
lsa_InitializeSecurityContextA,
|
2018-02-01 11:04:00 +01:00
|
|
|
lsa_AcceptSecurityContext,
|
2018-01-18 16:53:58 +01:00
|
|
|
NULL, /* CompleteAuthToken */
|
2018-02-01 11:03:54 +01:00
|
|
|
lsa_DeleteSecurityContext,
|
2018-01-18 16:53:58 +01:00
|
|
|
NULL, /* ApplyControlToken */
|
2018-02-01 11:04:07 +01:00
|
|
|
lsa_QueryContextAttributesA,
|
2018-01-18 16:53:58 +01:00
|
|
|
NULL, /* ImpersonateSecurityContext */
|
|
|
|
NULL, /* RevertSecurityContext */
|
2018-02-01 11:04:12 +01:00
|
|
|
lsa_MakeSignature,
|
2018-02-01 11:04:17 +01:00
|
|
|
lsa_VerifySignature,
|
2018-01-18 16:53:58 +01:00
|
|
|
NULL, /* FreeContextBuffer */
|
|
|
|
NULL, /* QuerySecurityPackageInfoA */
|
|
|
|
NULL, /* Reserved3 */
|
|
|
|
NULL, /* Reserved4 */
|
|
|
|
NULL, /* ExportSecurityContext */
|
|
|
|
NULL, /* ImportSecurityContextA */
|
|
|
|
NULL, /* AddCredentialsA */
|
|
|
|
NULL, /* Reserved8 */
|
|
|
|
NULL, /* QuerySecurityContextToken */
|
2018-02-01 11:04:22 +01:00
|
|
|
lsa_EncryptMessage,
|
2018-02-01 11:04:28 +01:00
|
|
|
lsa_DecryptMessage,
|
2018-01-18 16:53:58 +01:00
|
|
|
NULL, /* SetContextAttributesA */
|
|
|
|
};
|
|
|
|
|
2017-10-18 04:42:16 +02:00
|
|
|
static void add_package(struct lsa_package *package)
|
|
|
|
{
|
|
|
|
struct lsa_package *new_loaded_packages;
|
|
|
|
|
|
|
|
if (!loaded_packages)
|
2021-05-07 11:54:44 +02:00
|
|
|
new_loaded_packages = malloc(sizeof(*new_loaded_packages));
|
2017-10-18 04:42:16 +02:00
|
|
|
else
|
2021-05-07 11:54:44 +02:00
|
|
|
new_loaded_packages = realloc(loaded_packages, sizeof(*new_loaded_packages) * (loaded_packages_count + 1));
|
2017-10-18 04:42:16 +02:00
|
|
|
|
|
|
|
if (new_loaded_packages)
|
|
|
|
{
|
|
|
|
loaded_packages = new_loaded_packages;
|
|
|
|
loaded_packages[loaded_packages_count] = *package;
|
|
|
|
loaded_packages_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL load_package(const WCHAR *name, struct lsa_package *package, ULONG package_id)
|
|
|
|
{
|
2018-01-18 16:53:58 +01:00
|
|
|
NTSTATUS (NTAPI *pSpLsaModeInitialize)(ULONG, PULONG, PSECPKG_FUNCTION_TABLE *, PULONG);
|
|
|
|
NTSTATUS (NTAPI *pSpUserModeInitialize)(ULONG, PULONG, PSECPKG_USER_FUNCTION_TABLE *, PULONG);
|
|
|
|
|
|
|
|
memset(package, 0, sizeof(*package));
|
2017-10-18 04:42:16 +02:00
|
|
|
|
|
|
|
package->mod = LoadLibraryW(name);
|
|
|
|
if (!package->mod) return FALSE;
|
|
|
|
|
2018-01-18 16:53:58 +01:00
|
|
|
pSpLsaModeInitialize = (void *)GetProcAddress(package->mod, "SpLsaModeInitialize");
|
|
|
|
if (pSpLsaModeInitialize)
|
2017-10-18 04:42:16 +02:00
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
2018-01-18 16:53:58 +01:00
|
|
|
status = pSpLsaModeInitialize(SECPKG_INTERFACE_VERSION, &package->lsa_api_version, &package->lsa_api, &package->lsa_table_count);
|
2017-10-18 04:42:16 +02:00
|
|
|
if (status == STATUS_SUCCESS)
|
|
|
|
{
|
2018-01-18 16:53:58 +01:00
|
|
|
status = package->lsa_api->InitializePackage(package_id, &lsa_dispatch, NULL, NULL, &package->name);
|
2017-10-18 04:42:16 +02:00
|
|
|
if (status == STATUS_SUCCESS)
|
|
|
|
{
|
2022-02-17 07:12:45 +01:00
|
|
|
TRACE("%s => %p, name %s, version %#lx, api table %p, table count %lu\n",
|
2017-10-18 04:42:16 +02:00
|
|
|
debugstr_w(name), package->mod, debugstr_an(package->name->Buffer, package->name->Length),
|
2018-01-18 16:53:58 +01:00
|
|
|
package->lsa_api_version, package->lsa_api, package->lsa_table_count);
|
2017-10-18 04:42:16 +02:00
|
|
|
package->package_id = package_id;
|
2018-01-18 16:53:58 +01:00
|
|
|
|
|
|
|
status = package->lsa_api->Initialize(package_id, NULL /* FIXME: params */, NULL);
|
|
|
|
if (status == STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
pSpUserModeInitialize = (void *)GetProcAddress(package->mod, "SpUserModeInitialize");
|
|
|
|
if (pSpUserModeInitialize)
|
|
|
|
{
|
|
|
|
status = pSpUserModeInitialize(SECPKG_INTERFACE_VERSION, &package->user_api_version, &package->user_api, &package->user_table_count);
|
|
|
|
if (status == STATUS_SUCCESS)
|
|
|
|
package->user_api->InstanceInit(SECPKG_INTERFACE_VERSION, &lsa_dll_dispatch, NULL);
|
|
|
|
}
|
|
|
|
}
|
2017-10-18 04:42:16 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FreeLibrary(package->mod);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_SERVICE_NAME 260
|
|
|
|
|
2018-01-18 16:53:58 +01:00
|
|
|
void load_auth_packages(void)
|
2017-10-18 04:42:16 +02:00
|
|
|
{
|
|
|
|
DWORD err, i;
|
|
|
|
HKEY root;
|
2018-01-18 16:53:58 +01:00
|
|
|
SecureProvider *provider;
|
2017-10-18 04:42:16 +02:00
|
|
|
|
2021-05-07 11:54:43 +02:00
|
|
|
err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Control\\Lsa", 0, KEY_READ, &root);
|
2018-01-18 16:53:58 +01:00
|
|
|
if (err != ERROR_SUCCESS) return;
|
2017-10-18 04:42:16 +02:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
WCHAR name[MAX_SERVICE_NAME];
|
|
|
|
struct lsa_package package;
|
|
|
|
|
|
|
|
err = RegEnumKeyW(root, i++, name, MAX_SERVICE_NAME);
|
|
|
|
if (err == ERROR_NO_MORE_ITEMS)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (err != ERROR_SUCCESS)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!load_package(name, &package, i))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
add_package(&package);
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(root);
|
|
|
|
|
2018-01-18 16:53:58 +01:00
|
|
|
if (!loaded_packages_count) return;
|
|
|
|
|
|
|
|
provider = SECUR32_addProvider(&lsa_sspi_tableA, &lsa_sspi_tableW, NULL);
|
|
|
|
if (!provider)
|
|
|
|
{
|
|
|
|
ERR("Failed to add SSP/AP provider\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < loaded_packages_count; i++)
|
|
|
|
{
|
|
|
|
SecPkgInfoW *info;
|
|
|
|
|
2021-05-07 11:54:44 +02:00
|
|
|
info = malloc(loaded_packages[i].lsa_table_count * sizeof(*info));
|
2018-01-18 16:53:58 +01:00
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
status = loaded_packages[i].lsa_api->GetInfo(info);
|
|
|
|
if (status == STATUS_SUCCESS)
|
|
|
|
SECUR32_addPackages(provider, loaded_packages[i].lsa_table_count, NULL, info);
|
|
|
|
|
2021-05-07 11:54:44 +02:00
|
|
|
free(info);
|
2018-01-18 16:53:58 +01:00
|
|
|
}
|
|
|
|
}
|
2017-10-18 04:42:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS WINAPI LsaLookupAuthenticationPackage(HANDLE lsa_handle,
|
|
|
|
PLSA_STRING package_name, PULONG package_id)
|
|
|
|
{
|
|
|
|
ULONG i;
|
|
|
|
|
2018-02-02 11:22:29 +01:00
|
|
|
TRACE("%p %s %p\n", lsa_handle, debugstr_as(package_name), package_id);
|
2017-10-18 04:42:16 +02:00
|
|
|
|
|
|
|
for (i = 0; i < loaded_packages_count; i++)
|
|
|
|
{
|
|
|
|
if (!RtlCompareString(loaded_packages[i].name, package_name, FALSE))
|
|
|
|
{
|
|
|
|
*package_id = loaded_packages[i].package_id;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return STATUS_UNSUCCESSFUL; /* FIXME */
|
|
|
|
}
|