2017-10-18 04:42:13 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Dmitry Timoshkov
|
2018-01-29 04:10:06 +01:00
|
|
|
* Copyright 2017 George Popoff
|
2018-01-18 16:51:24 +01:00
|
|
|
* Copyright 2008 Robert Shearman for CodeWeavers
|
|
|
|
* Copyright 2017 Hans Leidekker for CodeWeavers
|
2017-10-18 04:42:13 +02:00
|
|
|
*
|
|
|
|
* Kerberos5 Authentication Package
|
|
|
|
*
|
|
|
|
* 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-04-21 09:47:33 +02:00
|
|
|
#include <stdlib.h>
|
2017-10-18 04:42:13 +02:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2018-01-29 04:10:06 +01:00
|
|
|
#include "winnls.h"
|
2018-01-18 16:51:08 +01:00
|
|
|
#include "rpc.h"
|
2017-10-18 04:42:13 +02:00
|
|
|
#include "sspi.h"
|
|
|
|
#include "ntsecapi.h"
|
|
|
|
#include "ntsecpkg.h"
|
|
|
|
#include "winternl.h"
|
2021-04-21 09:47:33 +02:00
|
|
|
|
2017-10-18 04:42:13 +02:00
|
|
|
#include "wine/debug.h"
|
2021-04-20 15:56:48 +02:00
|
|
|
#include "unixlib.h"
|
2017-10-18 04:42:13 +02:00
|
|
|
|
2018-01-18 16:51:03 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(kerberos);
|
2017-10-18 04:42:13 +02:00
|
|
|
|
2021-04-20 15:56:48 +02:00
|
|
|
static HINSTANCE instance;
|
|
|
|
|
2021-11-04 20:50:53 +01:00
|
|
|
unixlib_handle_t krb5_handle = 0;
|
2021-04-20 15:56:48 +02:00
|
|
|
|
2018-01-18 16:51:08 +01:00
|
|
|
#define KERBEROS_CAPS \
|
|
|
|
( SECPKG_FLAG_INTEGRITY \
|
|
|
|
| SECPKG_FLAG_PRIVACY \
|
|
|
|
| SECPKG_FLAG_TOKEN_ONLY \
|
|
|
|
| SECPKG_FLAG_DATAGRAM \
|
|
|
|
| SECPKG_FLAG_CONNECTION \
|
|
|
|
| SECPKG_FLAG_MULTI_REQUIRED \
|
|
|
|
| SECPKG_FLAG_EXTENDED_ERROR \
|
|
|
|
| SECPKG_FLAG_IMPERSONATION \
|
|
|
|
| SECPKG_FLAG_ACCEPT_WIN32_NAME \
|
|
|
|
| SECPKG_FLAG_NEGOTIABLE \
|
|
|
|
| SECPKG_FLAG_GSS_COMPATIBLE \
|
|
|
|
| SECPKG_FLAG_LOGON \
|
|
|
|
| SECPKG_FLAG_MUTUAL_AUTH \
|
|
|
|
| SECPKG_FLAG_DELEGATION \
|
|
|
|
| SECPKG_FLAG_READONLY_WITH_CHECKSUM \
|
|
|
|
| SECPKG_FLAG_RESTRICTED_TOKENS \
|
|
|
|
| SECPKG_FLAG_APPCONTAINER_CHECKS)
|
|
|
|
|
2021-04-21 09:47:32 +02:00
|
|
|
static WCHAR kerberos_name_W[] = L"Kerberos";
|
|
|
|
static WCHAR kerberos_comment_W[] = L"Microsoft Kerberos V1.0";
|
2018-01-25 04:32:52 +01:00
|
|
|
static const SecPkgInfoW infoW =
|
|
|
|
{
|
|
|
|
KERBEROS_CAPS,
|
|
|
|
1,
|
|
|
|
RPC_C_AUTHN_GSS_KERBEROS,
|
|
|
|
KERBEROS_MAX_BUF,
|
|
|
|
kerberos_name_W,
|
|
|
|
kerberos_comment_W
|
|
|
|
};
|
|
|
|
|
2018-01-18 16:51:03 +01:00
|
|
|
static ULONG kerberos_package_id;
|
2017-10-18 04:42:13 +02:00
|
|
|
static LSA_DISPATCH_TABLE lsa_dispatch;
|
|
|
|
|
2018-01-18 16:51:24 +01:00
|
|
|
static const char *debugstr_us( const UNICODE_STRING *us )
|
|
|
|
{
|
|
|
|
if (!us) return "<null>";
|
|
|
|
return debugstr_wn( us->Buffer, us->Length / sizeof(WCHAR) );
|
|
|
|
}
|
|
|
|
|
2021-11-04 17:54:56 +01:00
|
|
|
static void expiry_to_timestamp( ULONG expiry, TimeStamp *timestamp )
|
|
|
|
{
|
|
|
|
LARGE_INTEGER time;
|
|
|
|
|
|
|
|
NtQuerySystemTime( &time );
|
|
|
|
RtlSystemTimeToLocalTime( &time, &time );
|
|
|
|
time.QuadPart += expiry * (ULONGLONG)10000000;
|
|
|
|
timestamp->LowPart = time.QuadPart;
|
|
|
|
timestamp->HighPart = time.QuadPart >> 32;
|
|
|
|
}
|
|
|
|
|
2018-01-18 16:51:03 +01:00
|
|
|
static NTSTATUS NTAPI kerberos_LsaApInitializePackage(ULONG package_id, PLSA_DISPATCH_TABLE dispatch,
|
2017-10-18 04:42:13 +02:00
|
|
|
PLSA_STRING database, PLSA_STRING confidentiality, PLSA_STRING *package_name)
|
|
|
|
{
|
2018-01-18 16:51:03 +01:00
|
|
|
char *kerberos_name;
|
2017-10-18 04:42:13 +02:00
|
|
|
|
2021-11-04 20:50:53 +01:00
|
|
|
if (!krb5_handle)
|
|
|
|
{
|
|
|
|
if (NtQueryVirtualMemory( GetCurrentProcess(), instance, MemoryWineUnixFuncs,
|
|
|
|
&krb5_handle, sizeof(krb5_handle), NULL ) ||
|
|
|
|
KRB5_CALL( process_attach, NULL ))
|
|
|
|
ERR( "no Kerberos support, expect problems\n" );
|
|
|
|
}
|
2017-10-18 04:42:13 +02:00
|
|
|
|
2018-01-18 16:51:03 +01:00
|
|
|
kerberos_package_id = package_id;
|
2017-10-18 04:42:13 +02:00
|
|
|
lsa_dispatch = *dispatch;
|
|
|
|
|
2018-01-18 16:51:03 +01:00
|
|
|
kerberos_name = lsa_dispatch.AllocateLsaHeap(sizeof(MICROSOFT_KERBEROS_NAME_A));
|
|
|
|
if (!kerberos_name) return STATUS_NO_MEMORY;
|
2017-10-18 04:42:13 +02:00
|
|
|
|
2018-01-18 16:51:03 +01:00
|
|
|
memcpy(kerberos_name, MICROSOFT_KERBEROS_NAME_A, sizeof(MICROSOFT_KERBEROS_NAME_A));
|
2017-10-18 04:42:13 +02:00
|
|
|
|
|
|
|
*package_name = lsa_dispatch.AllocateLsaHeap(sizeof(**package_name));
|
|
|
|
if (!*package_name)
|
|
|
|
{
|
2018-01-18 16:51:03 +01:00
|
|
|
lsa_dispatch.FreeLsaHeap(kerberos_name);
|
2017-10-18 04:42:13 +02:00
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
2018-01-18 16:51:03 +01:00
|
|
|
RtlInitString(*package_name, kerberos_name);
|
2017-10-18 04:42:13 +02:00
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-11-04 17:37:59 +01:00
|
|
|
static NTSTATUS copy_to_client( PLSA_CLIENT_REQUEST lsa_req, KERB_QUERY_TKT_CACHE_RESPONSE *resp,
|
|
|
|
void **out, ULONG size )
|
2018-01-29 04:10:06 +01:00
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
ULONG i;
|
2021-11-04 17:37:59 +01:00
|
|
|
char *client_str;
|
|
|
|
KERB_QUERY_TKT_CACHE_RESPONSE *client_resp;
|
2018-01-29 04:10:06 +01:00
|
|
|
|
2021-11-04 17:37:59 +01:00
|
|
|
status = lsa_dispatch.AllocateClientBuffer(lsa_req, size, out );
|
2018-01-29 04:10:06 +01:00
|
|
|
if (status != STATUS_SUCCESS) return status;
|
|
|
|
|
2021-11-04 17:37:59 +01:00
|
|
|
client_resp = *out;
|
|
|
|
status = lsa_dispatch.CopyToClientBuffer(lsa_req, offsetof(KERB_QUERY_TKT_CACHE_RESPONSE, Tickets),
|
|
|
|
client_resp, resp);
|
2018-01-29 04:10:06 +01:00
|
|
|
if (status != STATUS_SUCCESS) goto fail;
|
|
|
|
|
2021-11-04 17:37:59 +01:00
|
|
|
client_str = (char *)&client_resp->Tickets[resp->CountOfTickets];
|
2018-01-29 04:10:06 +01:00
|
|
|
|
2021-11-04 17:37:59 +01:00
|
|
|
for (i = 0; i < resp->CountOfTickets; i++)
|
2018-01-29 04:10:06 +01:00
|
|
|
{
|
2021-11-04 17:37:59 +01:00
|
|
|
KERB_TICKET_CACHE_INFO ticket = resp->Tickets[i];
|
2018-01-29 04:10:06 +01:00
|
|
|
|
2021-11-04 17:37:59 +01:00
|
|
|
RtlSecondsSince1970ToTime( resp->Tickets[i].StartTime.QuadPart, &ticket.StartTime );
|
|
|
|
RtlSecondsSince1970ToTime( resp->Tickets[i].EndTime.QuadPart, &ticket.EndTime );
|
|
|
|
RtlSecondsSince1970ToTime( resp->Tickets[i].RenewTime.QuadPart, &ticket.RenewTime );
|
2018-01-29 04:10:06 +01:00
|
|
|
|
2021-11-04 17:37:59 +01:00
|
|
|
status = lsa_dispatch.CopyToClientBuffer(lsa_req, ticket.RealmName.MaximumLength,
|
|
|
|
client_str, ticket.RealmName.Buffer);
|
2018-01-29 04:10:06 +01:00
|
|
|
if (status != STATUS_SUCCESS) goto fail;
|
2021-11-04 17:37:59 +01:00
|
|
|
ticket.RealmName.Buffer = (WCHAR *)client_str;
|
|
|
|
client_str += ticket.RealmName.MaximumLength;
|
2018-01-29 04:10:06 +01:00
|
|
|
|
2021-11-04 17:37:59 +01:00
|
|
|
status = lsa_dispatch.CopyToClientBuffer(lsa_req, ticket.ServerName.MaximumLength,
|
|
|
|
client_str, ticket.ServerName.Buffer);
|
2018-01-29 04:10:06 +01:00
|
|
|
if (status != STATUS_SUCCESS) goto fail;
|
2021-11-04 17:37:59 +01:00
|
|
|
ticket.ServerName.Buffer = (WCHAR *)client_str;
|
|
|
|
client_str += ticket.ServerName.MaximumLength;
|
2018-01-29 04:10:06 +01:00
|
|
|
|
2021-11-04 17:37:59 +01:00
|
|
|
status = lsa_dispatch.CopyToClientBuffer(lsa_req, sizeof(ticket), &client_resp->Tickets[i], &ticket);
|
2018-01-29 04:10:06 +01:00
|
|
|
if (status != STATUS_SUCCESS) goto fail;
|
|
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
lsa_dispatch.FreeClientBuffer(lsa_req, client_resp);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2021-04-21 09:47:30 +02:00
|
|
|
static NTSTATUS NTAPI kerberos_LsaApCallPackageUntrusted(PLSA_CLIENT_REQUEST req, void *in_buf,
|
|
|
|
void *client_buf_base, ULONG in_buf_len, void **out_buf, ULONG *out_buf_len, NTSTATUS *ret_status)
|
2018-01-29 04:10:06 +01:00
|
|
|
{
|
2021-04-21 09:47:30 +02:00
|
|
|
KERB_PROTOCOL_MESSAGE_TYPE msg;
|
2018-01-29 04:10:06 +01:00
|
|
|
|
2021-04-21 09:47:30 +02:00
|
|
|
TRACE("%p,%p,%p,%u,%p,%p,%p\n", req, in_buf, client_buf_base, in_buf_len, out_buf, out_buf_len, ret_status);
|
2018-01-29 04:10:06 +01:00
|
|
|
|
2021-04-21 09:47:30 +02:00
|
|
|
if (!in_buf || in_buf_len < sizeof(msg)) return STATUS_INVALID_PARAMETER;
|
2018-01-29 04:10:06 +01:00
|
|
|
|
2021-04-21 09:47:30 +02:00
|
|
|
msg = *(KERB_PROTOCOL_MESSAGE_TYPE *)in_buf;
|
|
|
|
switch (msg)
|
2018-01-29 04:10:06 +01:00
|
|
|
{
|
2021-04-21 09:47:30 +02:00
|
|
|
case KerbQueryTicketCacheMessage:
|
2018-01-29 04:10:06 +01:00
|
|
|
{
|
2021-04-21 09:47:30 +02:00
|
|
|
KERB_QUERY_TKT_CACHE_REQUEST *query = (KERB_QUERY_TKT_CACHE_REQUEST *)in_buf;
|
|
|
|
NTSTATUS status;
|
2018-01-29 04:10:06 +01:00
|
|
|
|
2021-04-21 09:47:30 +02:00
|
|
|
if (!in_buf || in_buf_len != sizeof(*query) || !out_buf || !out_buf_len) return STATUS_INVALID_PARAMETER;
|
|
|
|
if (query->LogonId.HighPart || query->LogonId.LowPart) return STATUS_ACCESS_DENIED;
|
|
|
|
|
2021-11-04 17:37:59 +01:00
|
|
|
*out_buf_len = 1024;
|
|
|
|
for (;;)
|
2018-01-29 04:10:06 +01:00
|
|
|
{
|
2021-11-04 17:37:59 +01:00
|
|
|
KERB_QUERY_TKT_CACHE_RESPONSE *resp = malloc( *out_buf_len );
|
2021-11-04 20:50:53 +01:00
|
|
|
struct query_ticket_cache_params params = { resp, out_buf_len };
|
|
|
|
status = KRB5_CALL( query_ticket_cache, ¶ms );
|
2021-11-04 17:37:59 +01:00
|
|
|
if (status == STATUS_SUCCESS) status = copy_to_client( req, resp, out_buf, *out_buf_len );
|
|
|
|
free( resp );
|
|
|
|
if (status != STATUS_BUFFER_TOO_SMALL) break;
|
2018-01-29 04:10:06 +01:00
|
|
|
}
|
2021-04-21 09:47:30 +02:00
|
|
|
*ret_status = status;
|
2018-01-29 04:10:06 +01:00
|
|
|
break;
|
2021-04-21 09:47:30 +02:00
|
|
|
}
|
2018-01-29 04:10:06 +01:00
|
|
|
case KerbRetrieveTicketMessage:
|
|
|
|
FIXME("KerbRetrieveTicketMessage stub\n");
|
2021-04-21 09:47:30 +02:00
|
|
|
*ret_status = STATUS_NOT_IMPLEMENTED;
|
2018-01-29 04:10:06 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KerbPurgeTicketCacheMessage:
|
|
|
|
FIXME("KerbPurgeTicketCacheMessage stub\n");
|
2021-04-21 09:47:30 +02:00
|
|
|
*ret_status = STATUS_NOT_IMPLEMENTED;
|
2018-01-29 04:10:06 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* All other requests should call LsaApCallPackage */
|
|
|
|
WARN("%u => access denied\n", msg);
|
2021-04-21 09:47:30 +02:00
|
|
|
*ret_status = STATUS_ACCESS_DENIED;
|
2018-01-29 04:10:06 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-04-21 09:47:30 +02:00
|
|
|
return *ret_status;
|
2017-10-18 04:42:13 +02:00
|
|
|
}
|
|
|
|
|
2018-01-18 16:51:08 +01:00
|
|
|
static NTSTATUS NTAPI kerberos_SpGetInfo(SecPkgInfoW *info)
|
|
|
|
{
|
|
|
|
TRACE("%p\n", info);
|
|
|
|
|
|
|
|
/* LSA will make a copy before forwarding the structure, so
|
|
|
|
* it's safe to put pointers to dynamic or constant data there.
|
|
|
|
*/
|
|
|
|
*info = infoW;
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-04-20 15:56:48 +02:00
|
|
|
static char *get_str_unixcp( const UNICODE_STRING *str )
|
|
|
|
{
|
|
|
|
char *ret;
|
|
|
|
int len = WideCharToMultiByte( CP_UNIXCP, 0, str->Buffer, str->Length / sizeof(WCHAR), NULL, 0, NULL, NULL );
|
2021-04-21 09:47:33 +02:00
|
|
|
if (!(ret = malloc( len + 1 ))) return NULL;
|
2021-04-20 15:56:48 +02:00
|
|
|
WideCharToMultiByte( CP_UNIXCP, 0, str->Buffer, str->Length / sizeof(WCHAR), ret, len, NULL, NULL );
|
|
|
|
ret[len] = 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *get_username_unixcp( const WCHAR *user, ULONG user_len, const WCHAR *domain, ULONG domain_len )
|
2018-01-18 16:51:24 +01:00
|
|
|
{
|
2018-02-21 15:22:11 +01:00
|
|
|
int len_user, len_domain;
|
|
|
|
char *ret;
|
2018-01-18 16:51:24 +01:00
|
|
|
|
2018-02-21 15:22:11 +01:00
|
|
|
len_user = WideCharToMultiByte( CP_UNIXCP, 0, user, user_len, NULL, 0, NULL, NULL );
|
|
|
|
len_domain = WideCharToMultiByte( CP_UNIXCP, 0, domain, domain_len, NULL, 0, NULL, NULL );
|
2021-04-21 09:47:33 +02:00
|
|
|
if (!(ret = malloc( len_user + len_domain + 2 ))) return NULL;
|
2018-02-21 15:22:11 +01:00
|
|
|
|
|
|
|
WideCharToMultiByte( CP_UNIXCP, 0, user, user_len, ret, len_user, NULL, NULL );
|
|
|
|
ret[len_user] = '@';
|
|
|
|
WideCharToMultiByte( CP_UNIXCP, 0, domain, domain_len, ret + len_user + 1, len_domain, NULL, NULL );
|
|
|
|
ret[len_user + len_domain + 1] = 0;
|
|
|
|
return ret;
|
|
|
|
}
|
2018-01-18 16:51:24 +01:00
|
|
|
|
2021-04-20 15:56:48 +02:00
|
|
|
static char *get_password_unixcp( const WCHAR *passwd, ULONG passwd_len )
|
2018-02-21 15:22:11 +01:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
char *ret;
|
2018-01-18 16:51:24 +01:00
|
|
|
|
2018-02-21 15:22:11 +01:00
|
|
|
len = WideCharToMultiByte( CP_UNIXCP, WC_NO_BEST_FIT_CHARS, passwd, passwd_len, NULL, 0, NULL, NULL );
|
2021-04-21 09:47:33 +02:00
|
|
|
if (!(ret = malloc( len + 1 ))) return NULL;
|
2018-02-21 15:22:11 +01:00
|
|
|
WideCharToMultiByte( CP_UNIXCP, 0, passwd, passwd_len, ret, len, NULL, NULL );
|
|
|
|
ret[len] = 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS NTAPI kerberos_SpAcquireCredentialsHandle(
|
|
|
|
UNICODE_STRING *principal_us, ULONG credential_use, LUID *logon_id, void *auth_data,
|
2021-04-20 15:56:48 +02:00
|
|
|
void *get_key_fn, void *get_key_arg, LSA_SEC_HANDLE *credential, TimeStamp *expiry )
|
2018-02-21 15:22:11 +01:00
|
|
|
{
|
2021-04-20 15:56:48 +02:00
|
|
|
char *principal = NULL, *username = NULL, *password = NULL;
|
|
|
|
SEC_WINNT_AUTH_IDENTITY_W *id = auth_data;
|
|
|
|
NTSTATUS status = SEC_E_INSUFFICIENT_MEMORY;
|
2021-11-04 17:54:56 +01:00
|
|
|
ULONG exptime;
|
2018-02-21 15:22:11 +01:00
|
|
|
|
|
|
|
TRACE( "(%s 0x%08x %p %p %p %p %p %p)\n", debugstr_us(principal_us), credential_use,
|
2021-04-20 15:56:48 +02:00
|
|
|
logon_id, auth_data, get_key_fn, get_key_arg, credential, expiry );
|
2018-02-21 15:22:11 +01:00
|
|
|
|
2021-04-20 15:56:48 +02:00
|
|
|
if (principal_us && !(principal = get_str_unixcp( principal_us ))) return SEC_E_INSUFFICIENT_MEMORY;
|
|
|
|
if (id)
|
2018-02-21 15:22:11 +01:00
|
|
|
{
|
2021-04-20 15:56:48 +02:00
|
|
|
if (id->Flags & SEC_WINNT_AUTH_IDENTITY_ANSI)
|
|
|
|
{
|
|
|
|
FIXME( "ANSI identity not supported\n" );
|
|
|
|
status = SEC_E_UNSUPPORTED_FUNCTION;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (!(username = get_username_unixcp( id->User, id->UserLength, id->Domain, id->DomainLength ))) goto done;
|
|
|
|
if (!(password = get_password_unixcp( id->Password, id->PasswordLength ))) goto done;
|
2018-02-21 15:22:11 +01:00
|
|
|
}
|
|
|
|
|
2021-11-04 20:50:53 +01:00
|
|
|
{
|
|
|
|
struct acquire_credentials_handle_params params = { principal, credential_use, username, password,
|
|
|
|
credential, &exptime };
|
|
|
|
status = KRB5_CALL( acquire_credentials_handle, ¶ms );
|
|
|
|
expiry_to_timestamp( exptime, expiry );
|
|
|
|
}
|
2021-11-04 17:54:56 +01:00
|
|
|
|
2021-04-20 15:56:48 +02:00
|
|
|
done:
|
2021-04-21 09:47:33 +02:00
|
|
|
free( principal );
|
|
|
|
free( username );
|
|
|
|
free( password );
|
2021-04-20 15:56:48 +02:00
|
|
|
return status;
|
2018-01-18 16:51:24 +01:00
|
|
|
}
|
|
|
|
|
2018-01-18 16:51:39 +01:00
|
|
|
static NTSTATUS NTAPI kerberos_SpFreeCredentialsHandle( LSA_SEC_HANDLE credential )
|
|
|
|
{
|
|
|
|
TRACE( "(%lx)\n", credential );
|
|
|
|
if (!credential) return SEC_E_INVALID_HANDLE;
|
2021-11-04 20:50:53 +01:00
|
|
|
return KRB5_CALL( free_credentials_handle, (void *)credential );
|
2018-01-18 16:51:39 +01:00
|
|
|
}
|
|
|
|
|
2018-01-18 16:51:28 +01:00
|
|
|
static NTSTATUS NTAPI kerberos_SpInitLsaModeContext( LSA_SEC_HANDLE credential, LSA_SEC_HANDLE context,
|
|
|
|
UNICODE_STRING *target_name, ULONG context_req, ULONG target_data_rep, SecBufferDesc *input,
|
2021-04-20 15:56:49 +02:00
|
|
|
LSA_SEC_HANDLE *new_context, SecBufferDesc *output, ULONG *context_attr, TimeStamp *expiry,
|
2018-01-18 16:51:28 +01:00
|
|
|
BOOLEAN *mapped_context, SecBuffer *context_data )
|
|
|
|
{
|
|
|
|
static const ULONG supported = ISC_REQ_CONFIDENTIALITY | ISC_REQ_INTEGRITY | ISC_REQ_SEQUENCE_DETECT |
|
2018-05-24 08:35:52 +02:00
|
|
|
ISC_REQ_REPLAY_DETECT | ISC_REQ_MUTUAL_AUTH | ISC_REQ_USE_DCE_STYLE |
|
2018-05-24 08:36:13 +02:00
|
|
|
ISC_REQ_IDENTIFY | ISC_REQ_CONNECTION;
|
2021-04-20 15:56:49 +02:00
|
|
|
char *target = NULL;
|
2018-04-18 12:53:55 +02:00
|
|
|
NTSTATUS status;
|
2021-11-04 17:54:56 +01:00
|
|
|
ULONG exptime;
|
2018-01-18 16:51:28 +01:00
|
|
|
|
|
|
|
TRACE( "(%lx %lx %s 0x%08x %u %p %p %p %p %p %p %p)\n", credential, context, debugstr_us(target_name),
|
2021-04-20 15:56:49 +02:00
|
|
|
context_req, target_data_rep, input, new_context, output, context_attr, expiry,
|
2018-01-18 16:51:28 +01:00
|
|
|
mapped_context, context_data );
|
2021-04-20 15:56:49 +02:00
|
|
|
if (context_req & ~supported) FIXME( "flags 0x%08x not supported\n", context_req & ~supported );
|
2018-01-18 16:51:28 +01:00
|
|
|
|
|
|
|
if (!context && !input && !credential) return SEC_E_INVALID_HANDLE;
|
2021-04-20 15:56:49 +02:00
|
|
|
if (target_name && !(target = get_str_unixcp( target_name ))) return SEC_E_INSUFFICIENT_MEMORY;
|
2021-11-04 20:50:53 +01:00
|
|
|
else
|
2021-11-04 17:54:56 +01:00
|
|
|
{
|
2021-11-04 20:50:53 +01:00
|
|
|
struct initialize_context_params params = { credential, context, target, context_req, input,
|
|
|
|
new_context, output, context_attr, &exptime };
|
|
|
|
status = KRB5_CALL( initialize_context, ¶ms );
|
|
|
|
if (!status)
|
|
|
|
{
|
|
|
|
*mapped_context = TRUE;
|
|
|
|
expiry_to_timestamp( exptime, expiry );
|
|
|
|
}
|
2021-11-04 17:54:56 +01:00
|
|
|
}
|
2018-01-18 16:51:28 +01:00
|
|
|
/* FIXME: initialize context_data */
|
2021-04-21 09:47:33 +02:00
|
|
|
free( target );
|
2021-04-20 15:56:49 +02:00
|
|
|
return status;
|
2018-01-18 16:51:28 +01:00
|
|
|
}
|
|
|
|
|
2018-01-18 16:51:31 +01:00
|
|
|
static NTSTATUS NTAPI kerberos_SpAcceptLsaModeContext( LSA_SEC_HANDLE credential, LSA_SEC_HANDLE context,
|
|
|
|
SecBufferDesc *input, ULONG context_req, ULONG target_data_rep, LSA_SEC_HANDLE *new_context,
|
2021-04-20 15:56:50 +02:00
|
|
|
SecBufferDesc *output, ULONG *context_attr, TimeStamp *expiry, BOOLEAN *mapped_context, SecBuffer *context_data )
|
2018-01-18 16:51:31 +01:00
|
|
|
{
|
2021-11-04 20:50:53 +01:00
|
|
|
NTSTATUS status = SEC_E_INVALID_HANDLE;
|
2021-11-04 17:54:56 +01:00
|
|
|
ULONG exptime;
|
2021-04-20 15:56:50 +02:00
|
|
|
|
|
|
|
TRACE( "(%lx %lx 0x%08x %u %p %p %p %p %p %p %p)\n", credential, context, context_req, target_data_rep, input,
|
|
|
|
new_context, output, context_attr, expiry, mapped_context, context_data );
|
2018-01-18 16:51:31 +01:00
|
|
|
if (context_req) FIXME( "ignoring flags 0x%08x\n", context_req );
|
|
|
|
|
2021-11-04 20:50:53 +01:00
|
|
|
if (context || input || credential)
|
2021-11-04 17:54:56 +01:00
|
|
|
{
|
2021-11-04 20:50:53 +01:00
|
|
|
struct accept_context_params params = { credential, context, input, new_context, output, context_attr, &exptime };
|
|
|
|
status = KRB5_CALL( accept_context, ¶ms );
|
|
|
|
if (!status)
|
|
|
|
{
|
|
|
|
*mapped_context = TRUE;
|
|
|
|
expiry_to_timestamp( exptime, expiry );
|
|
|
|
}
|
|
|
|
/* FIXME: initialize context_data */
|
2021-11-04 17:54:56 +01:00
|
|
|
}
|
2021-04-20 15:56:50 +02:00
|
|
|
return status;
|
2018-01-18 16:51:31 +01:00
|
|
|
}
|
|
|
|
|
2018-01-18 16:51:35 +01:00
|
|
|
static NTSTATUS NTAPI kerberos_SpDeleteContext( LSA_SEC_HANDLE context )
|
|
|
|
{
|
|
|
|
TRACE( "(%lx)\n", context );
|
|
|
|
if (!context) return SEC_E_INVALID_HANDLE;
|
2021-11-04 20:50:53 +01:00
|
|
|
return KRB5_CALL( delete_context, (void *)context );
|
2018-01-18 16:51:35 +01:00
|
|
|
}
|
|
|
|
|
2018-02-08 11:53:59 +01:00
|
|
|
static SecPkgInfoW *build_package_info( const SecPkgInfoW *info )
|
|
|
|
{
|
|
|
|
SecPkgInfoW *ret;
|
2021-04-21 09:47:31 +02:00
|
|
|
DWORD size_name = (wcslen(info->Name) + 1) * sizeof(WCHAR);
|
|
|
|
DWORD size_comment = (wcslen(info->Comment) + 1) * sizeof(WCHAR);
|
2018-02-08 11:53:59 +01:00
|
|
|
|
2021-04-21 09:47:33 +02:00
|
|
|
if (!(ret = malloc( sizeof(*ret) + size_name + size_comment ))) return NULL;
|
2018-02-08 11:53:59 +01:00
|
|
|
ret->fCapabilities = info->fCapabilities;
|
|
|
|
ret->wVersion = info->wVersion;
|
|
|
|
ret->wRPCID = info->wRPCID;
|
|
|
|
ret->cbMaxToken = info->cbMaxToken;
|
|
|
|
ret->Name = (SEC_WCHAR *)(ret + 1);
|
|
|
|
memcpy( ret->Name, info->Name, size_name );
|
|
|
|
ret->Comment = (SEC_WCHAR *)((char *)ret->Name + size_name);
|
|
|
|
memcpy( ret->Comment, info->Comment, size_comment );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-01-25 04:32:52 +01:00
|
|
|
static NTSTATUS NTAPI kerberos_SpQueryContextAttributes( LSA_SEC_HANDLE context, ULONG attribute, void *buffer )
|
|
|
|
{
|
|
|
|
TRACE( "(%lx %u %p)\n", context, attribute, buffer );
|
|
|
|
|
|
|
|
if (!context) return SEC_E_INVALID_HANDLE;
|
|
|
|
|
|
|
|
switch (attribute)
|
|
|
|
{
|
|
|
|
#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);
|
|
|
|
case SECPKG_ATTR_SIZES:
|
|
|
|
{
|
2021-11-04 20:50:53 +01:00
|
|
|
struct query_context_attributes_params params = { context, attribute, buffer };
|
|
|
|
return KRB5_CALL( query_context_attributes, ¶ms );
|
2018-01-25 04:32:52 +01:00
|
|
|
}
|
|
|
|
case SECPKG_ATTR_NEGOTIATION_INFO:
|
|
|
|
{
|
|
|
|
SecPkgContext_NegotiationInfoW *info = (SecPkgContext_NegotiationInfoW *)buffer;
|
2018-02-08 11:53:59 +01:00
|
|
|
if (!(info->PackageInfo = build_package_info( &infoW ))) return SEC_E_INSUFFICIENT_MEMORY;
|
2018-01-25 04:32:52 +01:00
|
|
|
info->NegotiationState = SECPKG_NEGOTIATION_COMPLETE;
|
|
|
|
return SEC_E_OK;
|
|
|
|
}
|
|
|
|
#undef X
|
|
|
|
default:
|
|
|
|
FIXME( "unknown attribute %u\n", attribute );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SEC_E_UNSUPPORTED_FUNCTION;
|
|
|
|
}
|
|
|
|
|
2018-01-18 16:51:24 +01:00
|
|
|
static NTSTATUS NTAPI kerberos_SpInitialize(ULONG_PTR package_id, SECPKG_PARAMETERS *params,
|
|
|
|
LSA_SECPKG_FUNCTION_TABLE *lsa_function_table)
|
|
|
|
{
|
|
|
|
TRACE("%lu,%p,%p\n", package_id, params, lsa_function_table);
|
|
|
|
|
2021-11-04 20:50:53 +01:00
|
|
|
if (!krb5_handle)
|
2021-04-20 15:56:48 +02:00
|
|
|
{
|
2021-11-04 20:50:53 +01:00
|
|
|
if (NtQueryVirtualMemory( GetCurrentProcess(), instance, MemoryWineUnixFuncs,
|
|
|
|
&krb5_handle, sizeof(krb5_handle), NULL ) ||
|
|
|
|
KRB5_CALL( process_attach, NULL ))
|
|
|
|
WARN( "no Kerberos support\n" );
|
2021-04-20 15:56:48 +02:00
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
2018-01-18 16:51:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS NTAPI kerberos_SpShutdown(void)
|
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-01-18 16:51:03 +01:00
|
|
|
static SECPKG_FUNCTION_TABLE kerberos_table =
|
2017-10-18 04:42:13 +02:00
|
|
|
{
|
2018-01-18 16:51:03 +01:00
|
|
|
kerberos_LsaApInitializePackage, /* InitializePackage */
|
2017-10-18 04:42:13 +02:00
|
|
|
NULL, /* LsaLogonUser */
|
|
|
|
NULL, /* CallPackage */
|
|
|
|
NULL, /* LogonTerminated */
|
2018-01-18 16:51:03 +01:00
|
|
|
kerberos_LsaApCallPackageUntrusted, /* CallPackageUntrusted */
|
2017-10-18 04:42:13 +02:00
|
|
|
NULL, /* CallPackagePassthrough */
|
|
|
|
NULL, /* LogonUserEx */
|
|
|
|
NULL, /* LogonUserEx2 */
|
2018-01-18 16:51:20 +01:00
|
|
|
kerberos_SpInitialize,
|
|
|
|
kerberos_SpShutdown,
|
2018-01-18 16:51:08 +01:00
|
|
|
kerberos_SpGetInfo,
|
2017-10-18 04:42:13 +02:00
|
|
|
NULL, /* AcceptCredentials */
|
2018-01-18 16:51:24 +01:00
|
|
|
kerberos_SpAcquireCredentialsHandle,
|
2017-10-18 04:42:13 +02:00
|
|
|
NULL, /* SpQueryCredentialsAttributes */
|
2018-01-18 16:51:39 +01:00
|
|
|
kerberos_SpFreeCredentialsHandle,
|
2017-10-18 04:42:13 +02:00
|
|
|
NULL, /* SaveCredentials */
|
|
|
|
NULL, /* GetCredentials */
|
|
|
|
NULL, /* DeleteCredentials */
|
2018-01-18 16:51:28 +01:00
|
|
|
kerberos_SpInitLsaModeContext,
|
2018-01-18 16:51:31 +01:00
|
|
|
kerberos_SpAcceptLsaModeContext,
|
2018-01-18 16:51:35 +01:00
|
|
|
kerberos_SpDeleteContext,
|
2017-10-18 04:42:13 +02:00
|
|
|
NULL, /* ApplyControlToken */
|
|
|
|
NULL, /* GetUserInfo */
|
|
|
|
NULL, /* GetExtendedInformation */
|
2018-01-25 04:32:52 +01:00
|
|
|
kerberos_SpQueryContextAttributes,
|
2017-10-18 04:42:13 +02:00
|
|
|
NULL, /* SpAddCredentials */
|
|
|
|
NULL, /* SetExtendedInformation */
|
|
|
|
NULL, /* SetContextAttributes */
|
|
|
|
NULL, /* SetCredentialsAttributes */
|
|
|
|
NULL, /* ChangeAccountPassword */
|
|
|
|
NULL, /* QueryMetaData */
|
|
|
|
NULL, /* ExchangeMetaData */
|
|
|
|
NULL, /* GetCredUIContext */
|
|
|
|
NULL, /* UpdateCredentials */
|
|
|
|
NULL, /* ValidateTargetInfo */
|
|
|
|
NULL, /* PostLogonUser */
|
|
|
|
};
|
|
|
|
|
|
|
|
NTSTATUS NTAPI SpLsaModeInitialize(ULONG lsa_version, PULONG package_version,
|
|
|
|
PSECPKG_FUNCTION_TABLE *table, PULONG table_count)
|
|
|
|
{
|
|
|
|
TRACE("%#x,%p,%p,%p\n", lsa_version, package_version, table, table_count);
|
|
|
|
|
|
|
|
*package_version = SECPKG_INTERFACE_VERSION;
|
2018-01-18 16:51:03 +01:00
|
|
|
*table = &kerberos_table;
|
2017-10-18 04:42:13 +02:00
|
|
|
*table_count = 1;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2018-01-25 04:33:05 +01:00
|
|
|
|
2018-01-25 04:33:11 +01:00
|
|
|
static NTSTATUS NTAPI kerberos_SpInstanceInit(ULONG version, SECPKG_DLL_FUNCTIONS *dll_function_table, void **user_functions)
|
|
|
|
{
|
2018-07-20 07:10:04 +02:00
|
|
|
TRACE("%#x,%p,%p\n", version, dll_function_table, user_functions);
|
2018-01-25 04:33:11 +01:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-01-25 04:33:26 +01:00
|
|
|
static NTSTATUS SEC_ENTRY kerberos_SpMakeSignature( LSA_SEC_HANDLE context, ULONG quality_of_protection,
|
|
|
|
SecBufferDesc *message, ULONG message_seq_no )
|
|
|
|
{
|
|
|
|
TRACE( "(%lx 0x%08x %p %u)\n", context, quality_of_protection, message, message_seq_no );
|
|
|
|
if (quality_of_protection) FIXME( "ignoring quality_of_protection 0x%08x\n", quality_of_protection );
|
2018-01-26 05:48:20 +01:00
|
|
|
if (message_seq_no) FIXME( "ignoring message_seq_no %u\n", message_seq_no );
|
2018-01-25 04:33:26 +01:00
|
|
|
|
2021-11-04 20:50:53 +01:00
|
|
|
if (context)
|
|
|
|
{
|
|
|
|
struct make_signature_params params = { context, message };
|
|
|
|
return KRB5_CALL( make_signature, ¶ms );
|
|
|
|
}
|
|
|
|
else return SEC_E_INVALID_HANDLE;
|
2018-01-25 04:33:26 +01:00
|
|
|
}
|
|
|
|
|
2018-04-18 12:53:55 +02:00
|
|
|
static NTSTATUS NTAPI kerberos_SpVerifySignature( LSA_SEC_HANDLE context, SecBufferDesc *message,
|
2018-01-25 04:33:36 +01:00
|
|
|
ULONG message_seq_no, ULONG *quality_of_protection )
|
|
|
|
{
|
|
|
|
TRACE( "(%lx %p %u %p)\n", context, message, message_seq_no, quality_of_protection );
|
2018-01-26 05:48:20 +01:00
|
|
|
if (message_seq_no) FIXME( "ignoring message_seq_no %u\n", message_seq_no );
|
2018-01-25 04:33:36 +01:00
|
|
|
|
2021-11-04 20:50:53 +01:00
|
|
|
if (context)
|
|
|
|
{
|
|
|
|
struct verify_signature_params params = { context, message, quality_of_protection };
|
|
|
|
return KRB5_CALL( verify_signature, ¶ms );
|
|
|
|
}
|
|
|
|
else return SEC_E_INVALID_HANDLE;
|
2018-01-25 04:33:36 +01:00
|
|
|
}
|
|
|
|
|
2018-02-06 09:55:00 +01:00
|
|
|
static NTSTATUS NTAPI kerberos_SpSealMessage( LSA_SEC_HANDLE context, ULONG quality_of_protection,
|
|
|
|
SecBufferDesc *message, ULONG message_seq_no )
|
|
|
|
{
|
|
|
|
TRACE( "(%lx 0x%08x %p %u)\n", context, quality_of_protection, message, message_seq_no );
|
2018-01-26 05:48:20 +01:00
|
|
|
if (message_seq_no) FIXME( "ignoring message_seq_no %u\n", message_seq_no );
|
2018-01-25 04:33:48 +01:00
|
|
|
|
2021-11-04 20:50:53 +01:00
|
|
|
if (context)
|
|
|
|
{
|
|
|
|
struct seal_message_params params = { context, message, quality_of_protection };
|
|
|
|
return KRB5_CALL( seal_message, ¶ms );
|
|
|
|
}
|
|
|
|
else return SEC_E_INVALID_HANDLE;
|
2018-02-06 09:55:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS NTAPI kerberos_SpUnsealMessage( LSA_SEC_HANDLE context, SecBufferDesc *message,
|
|
|
|
ULONG message_seq_no, ULONG *quality_of_protection )
|
|
|
|
{
|
|
|
|
TRACE( "(%lx %p %u %p)\n", context, message, message_seq_no, quality_of_protection );
|
|
|
|
if (message_seq_no) FIXME( "ignoring message_seq_no %u\n", message_seq_no );
|
|
|
|
|
2021-11-04 20:50:53 +01:00
|
|
|
if (context)
|
|
|
|
{
|
|
|
|
struct unseal_message_params params = { context, message, quality_of_protection };
|
|
|
|
return KRB5_CALL( unseal_message, ¶ms );
|
|
|
|
}
|
|
|
|
else return SEC_E_INVALID_HANDLE;
|
2018-01-25 04:33:48 +01:00
|
|
|
}
|
|
|
|
|
2018-01-25 04:33:05 +01:00
|
|
|
static SECPKG_USER_FUNCTION_TABLE kerberos_user_table =
|
|
|
|
{
|
2018-01-25 04:33:11 +01:00
|
|
|
kerberos_SpInstanceInit,
|
2018-01-25 04:33:05 +01:00
|
|
|
NULL, /* SpInitUserModeContext */
|
2018-01-25 04:33:26 +01:00
|
|
|
kerberos_SpMakeSignature,
|
2018-01-25 04:33:36 +01:00
|
|
|
kerberos_SpVerifySignature,
|
2018-01-25 04:33:44 +01:00
|
|
|
kerberos_SpSealMessage,
|
2018-01-25 04:33:48 +01:00
|
|
|
kerberos_SpUnsealMessage,
|
2018-01-25 04:33:05 +01:00
|
|
|
NULL, /* SpGetContextToken */
|
|
|
|
NULL, /* SpQueryContextAttributes */
|
|
|
|
NULL, /* SpCompleteAuthToken */
|
|
|
|
NULL, /* SpDeleteContext */
|
|
|
|
NULL, /* SpFormatCredentialsFn */
|
|
|
|
NULL, /* SpMarshallSupplementalCreds */
|
|
|
|
NULL, /* SpExportSecurityContext */
|
|
|
|
NULL /* SpImportSecurityContext */
|
|
|
|
};
|
|
|
|
|
|
|
|
NTSTATUS NTAPI SpUserModeInitialize(ULONG lsa_version, PULONG package_version,
|
|
|
|
PSECPKG_USER_FUNCTION_TABLE *table, PULONG table_count)
|
|
|
|
{
|
|
|
|
TRACE("%#x,%p,%p,%p\n", lsa_version, package_version, table, table_count);
|
|
|
|
|
|
|
|
*package_version = SECPKG_INTERFACE_VERSION;
|
|
|
|
*table = &kerberos_user_table;
|
|
|
|
*table_count = 1;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2021-04-20 15:56:48 +02:00
|
|
|
|
|
|
|
BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, void *reserved )
|
|
|
|
{
|
|
|
|
switch (reason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
instance = hinst;
|
|
|
|
DisableThreadLibraryCalls( hinst );
|
|
|
|
break;
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|