2009-12-23 23:17:16 +03:00
/*
2005-06-03 15:23:15 +04:00
Unix SMB / CIFS implementation .
KDC Server startup
2008-09-05 10:45:58 +04:00
Copyright ( C ) Andrew Bartlett < abartlet @ samba . org > 2005 - 2008
2005-06-03 15:23:15 +04:00
Copyright ( C ) Andrew Tridgell 2005
2005-10-14 10:12:05 +04:00
Copyright ( C ) Stefan Metzmacher 2005
2005-06-03 15:23:15 +04:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2005-06-03 15:23:15 +04:00
( at your option ) any later version .
2009-12-23 23:17:16 +03:00
2005-06-03 15:23:15 +04:00
This program 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 General Public License for more details .
2009-12-23 23:17:16 +03:00
2005-06-03 15:23:15 +04:00
You should have received a copy of the GNU General Public License
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2005-06-03 15:23:15 +04:00
*/
# include "includes.h"
2020-11-20 17:27:17 +03:00
# include "samba/process_model.h"
2009-12-15 14:58:40 +03:00
# include "lib/tsocket/tsocket.h"
2005-07-19 13:27:20 +04:00
# include "lib/messaging/irpc.h"
2008-09-03 09:30:17 +04:00
# include "librpc/gen_ndr/ndr_irpc.h"
# include "librpc/gen_ndr/ndr_krb5pac.h"
2006-08-17 17:37:04 +04:00
# include "lib/socket/netif.h"
2007-09-08 16:42:09 +04:00
# include "param/param.h"
2016-06-10 12:10:50 +03:00
# include "kdc/kdc-server.h"
2016-06-13 12:20:44 +03:00
# include "kdc/kdc-proxy.h"
2010-11-11 06:09:41 +03:00
# include "kdc/kdc-glue.h"
2012-01-11 11:06:55 +04:00
# include "kdc/pac-glue.h"
2016-09-07 17:38:06 +03:00
# include "kdc/kpasswd-service.h"
2010-11-12 09:23:34 +03:00
# include "dsdb/samdb/samdb.h"
# include "auth/session.h"
2015-12-28 22:01:54 +03:00
# include "libds/common/roles.h"
2016-06-10 10:42:33 +03:00
# include <kdc.h>
# include <hdb.h>
2007-01-10 04:51:35 +03:00
2017-04-20 22:24:43 +03:00
NTSTATUS server_service_kdc_init ( TALLOC_CTX * ) ;
2011-03-19 02:43:50 +03:00
2022-02-22 04:39:13 +03:00
extern struct krb5plugin_kdc_ftable kdc_plugin_table ;
2006-02-04 02:19:00 +03:00
2005-10-21 05:25:55 +04:00
/**
Wrapper for krb5_kdc_process_krb5_request , converting to / from Samba
calling conventions
*/
2016-06-10 10:50:45 +03:00
static kdc_code kdc_process ( struct kdc_server * kdc ,
TALLOC_CTX * mem_ctx ,
DATA_BLOB * input ,
DATA_BLOB * reply ,
struct tsocket_address * peer_addr ,
struct tsocket_address * my_addr ,
int datagram_reply )
2005-10-21 05:25:55 +04:00
{
2009-12-15 14:58:40 +03:00
int ret ;
char * pa ;
struct sockaddr_storage ss ;
2005-10-21 05:25:55 +04:00
krb5_data k5_reply ;
2016-06-10 10:42:33 +03:00
krb5_kdc_configuration * kdc_config =
( krb5_kdc_configuration * ) kdc - > private_data ;
2006-11-07 09:59:56 +03:00
krb5_data_zero ( & k5_reply ) ;
2006-01-10 01:12:53 +03:00
2007-06-13 09:44:24 +04:00
krb5_kdc_update_time ( NULL ) ;
2009-12-15 14:58:40 +03:00
ret = tsocket_address_bsd_sockaddr ( peer_addr , ( struct sockaddr * ) & ss ,
sizeof ( struct sockaddr_storage ) ) ;
if ( ret < 0 ) {
2016-06-10 10:50:45 +03:00
return KDC_ERROR ;
2009-12-15 14:58:40 +03:00
}
pa = tsocket_address_string ( peer_addr , mem_ctx ) ;
if ( pa = = NULL ) {
2016-06-10 10:50:45 +03:00
return KDC_ERROR ;
2009-12-15 14:58:40 +03:00
}
2018-08-27 22:46:59 +03:00
DBG_DEBUG ( " Received KDC packet of length %lu from %s \n " ,
( long ) input - > length - 4 , pa ) ;
2005-10-21 05:25:55 +04:00
2009-12-23 23:17:16 +03:00
ret = krb5_kdc_process_krb5_request ( kdc - > smb_krb5_context - > krb5_context ,
2016-06-10 10:42:33 +03:00
kdc_config ,
2005-10-21 05:25:55 +04:00
input - > data , input - > length ,
& k5_reply ,
2009-12-15 14:58:40 +03:00
pa ,
( struct sockaddr * ) & ss ,
2006-11-07 09:59:56 +03:00
datagram_reply ) ;
2005-10-21 05:25:55 +04:00
if ( ret = = - 1 ) {
* reply = data_blob ( NULL , 0 ) ;
2016-06-10 10:50:45 +03:00
return KDC_ERROR ;
2005-10-21 05:25:55 +04:00
}
2010-11-12 09:23:34 +03:00
if ( ret = = HDB_ERR_NOT_FOUND_HERE ) {
* reply = data_blob ( NULL , 0 ) ;
2016-06-10 10:50:45 +03:00
return KDC_PROXY_REQUEST ;
2010-11-12 09:23:34 +03:00
}
2006-11-07 09:59:56 +03:00
if ( k5_reply . length ) {
* reply = data_blob_talloc ( mem_ctx , k5_reply . data , k5_reply . length ) ;
2009-03-25 14:21:59 +03:00
krb5_data_free ( & k5_reply ) ;
2006-11-07 09:59:56 +03:00
} else {
2009-12-23 23:17:16 +03:00
* reply = data_blob ( NULL , 0 ) ;
2006-11-07 09:59:56 +03:00
}
2016-06-10 10:50:45 +03:00
return KDC_OK ;
2005-10-21 05:25:55 +04:00
}
2005-06-03 15:23:15 +04:00
/*
setup our listening sockets on the configured network interfaces
*/
2017-09-18 04:05:24 +03:00
static NTSTATUS kdc_startup_interfaces ( struct kdc_server * kdc ,
struct loadparm_context * lp_ctx ,
struct interface * ifaces ,
const struct model_ops * model_ops )
2005-06-03 15:23:15 +04:00
{
2007-12-12 00:23:14 +03:00
int num_interfaces ;
2005-06-03 15:23:15 +04:00
TALLOC_CTX * tmp_ctx = talloc_new ( kdc ) ;
NTSTATUS status ;
2006-02-04 02:19:00 +03:00
int i ;
2010-11-15 00:41:16 +03:00
uint16_t kdc_port = lpcfg_krb5_port ( lp_ctx ) ;
uint16_t kpasswd_port = lpcfg_kpasswd_port ( lp_ctx ) ;
bool done_wildcard = false ;
2007-12-12 00:23:14 +03:00
2011-05-02 09:57:19 +04:00
num_interfaces = iface_list_count ( ifaces ) ;
2009-12-23 23:17:16 +03:00
2010-11-15 00:41:16 +03:00
/* if we are allowing incoming packets from any address, then
we need to bind to the wildcard address */
if ( ! lpcfg_bind_interfaces_only ( lp_ctx ) ) {
2019-01-18 21:09:12 +03:00
size_t num_binds = 0 ;
2014-02-27 13:28:23 +04:00
char * * wcard = iface_list_wildcard ( kdc ) ;
2011-05-12 14:35:02 +04:00
NT_STATUS_HAVE_NO_MEMORY ( wcard ) ;
for ( i = 0 ; wcard [ i ] ; i + + ) {
if ( kdc_port ) {
status = kdc_add_socket ( kdc , model_ops ,
" kdc " , wcard [ i ] , kdc_port ,
kdc_process , false ) ;
2014-06-05 23:32:30 +04:00
if ( NT_STATUS_IS_OK ( status ) ) {
num_binds + + ;
}
2011-05-12 14:35:02 +04:00
}
if ( kpasswd_port ) {
status = kdc_add_socket ( kdc , model_ops ,
" kpasswd " , wcard [ i ] , kpasswd_port ,
2016-09-07 17:38:06 +03:00
kpasswd_process , false ) ;
2014-06-05 23:32:30 +04:00
if ( NT_STATUS_IS_OK ( status ) ) {
num_binds + + ;
}
2011-05-12 14:35:02 +04:00
}
2010-11-15 00:41:16 +03:00
}
2011-05-12 14:35:02 +04:00
talloc_free ( wcard ) ;
2014-06-05 23:32:30 +04:00
if ( num_binds = = 0 ) {
return NT_STATUS_INVALID_PARAMETER_MIX ;
}
2010-11-15 00:41:16 +03:00
done_wildcard = true ;
}
2006-02-04 02:19:00 +03:00
for ( i = 0 ; i < num_interfaces ; i + + ) {
2011-05-02 09:57:19 +04:00
const char * address = talloc_strdup ( tmp_ctx , iface_list_n_ip ( ifaces , i ) ) ;
2009-11-20 17:47:40 +03:00
if ( kdc_port ) {
2009-11-24 07:28:11 +03:00
status = kdc_add_socket ( kdc , model_ops ,
2010-11-15 00:41:16 +03:00
" kdc " , address , kdc_port ,
kdc_process , done_wildcard ) ;
2009-11-20 17:47:40 +03:00
NT_STATUS_NOT_OK_RETURN ( status ) ;
}
if ( kpasswd_port ) {
2009-11-24 07:28:11 +03:00
status = kdc_add_socket ( kdc , model_ops ,
2010-11-15 00:41:16 +03:00
" kpasswd " , address , kpasswd_port ,
2016-09-07 17:38:06 +03:00
kpasswd_process , done_wildcard ) ;
2009-11-20 17:47:40 +03:00
NT_STATUS_NOT_OK_RETURN ( status ) ;
}
2006-02-04 02:19:00 +03:00
}
2005-06-03 15:23:15 +04:00
talloc_free ( tmp_ctx ) ;
return NT_STATUS_OK ;
}
2009-12-23 23:17:16 +03:00
static NTSTATUS kdc_check_generic_kerberos ( struct irpc_message * msg ,
2008-09-03 09:30:17 +04:00
struct kdc_check_generic_kerberos * r )
{
struct PAC_Validate pac_validate ;
DATA_BLOB srv_sig ;
struct PAC_SIGNATURE_DATA kdc_sig ;
2009-02-01 02:03:47 +03:00
struct kdc_server * kdc = talloc_get_type ( msg - > private_data , struct kdc_server ) ;
2016-06-10 10:42:33 +03:00
krb5_kdc_configuration * kdc_config =
( krb5_kdc_configuration * ) kdc - > private_data ;
2008-09-03 09:30:17 +04:00
enum ndr_err_code ndr_err ;
int ret ;
2022-02-22 09:41:14 +03:00
hdb_entry ent ;
2008-09-03 09:30:17 +04:00
krb5_principal principal ;
2016-06-10 10:42:33 +03:00
2008-09-03 09:30:17 +04:00
/* There is no reply to this request */
r - > out . generic_reply = data_blob ( NULL , 0 ) ;
2010-05-09 19:20:01 +04:00
ndr_err = ndr_pull_struct_blob ( & r - > in . generic_request , msg , & pac_validate ,
2008-09-03 09:30:17 +04:00
( ndr_pull_flags_fn_t ) ndr_pull_PAC_Validate ) ;
if ( ! NDR_ERR_CODE_IS_SUCCESS ( ndr_err ) ) {
return NT_STATUS_INVALID_PARAMETER ;
}
2009-12-23 23:17:16 +03:00
2012-01-11 09:13:37 +04:00
if ( pac_validate . MessageType ! = NETLOGON_GENERIC_KRB5_PAC_VALIDATE ) {
2008-09-03 09:30:17 +04:00
/* We don't implement any other message types - such as certificate validation - yet */
return NT_STATUS_INVALID_PARAMETER ;
}
2008-09-23 01:23:22 +04:00
2008-09-03 09:30:17 +04:00
if ( pac_validate . ChecksumAndSignature . length ! = ( pac_validate . ChecksumLength + pac_validate . SignatureLength )
| | pac_validate . ChecksumAndSignature . length < pac_validate . ChecksumLength
| | pac_validate . ChecksumAndSignature . length < pac_validate . SignatureLength ) {
return NT_STATUS_INVALID_PARAMETER ;
}
2009-12-23 23:17:16 +03:00
srv_sig = data_blob_const ( pac_validate . ChecksumAndSignature . data ,
2008-09-03 09:30:17 +04:00
pac_validate . ChecksumLength ) ;
2009-12-23 23:17:16 +03:00
ret = krb5_make_principal ( kdc - > smb_krb5_context - > krb5_context , & principal ,
2010-07-16 08:32:42 +04:00
lpcfg_realm ( kdc - > task - > lp_ctx ) ,
" krbtgt " , lpcfg_realm ( kdc - > task - > lp_ctx ) ,
2008-09-03 09:30:17 +04:00
NULL ) ;
if ( ret ! = 0 ) {
return NT_STATUS_NO_MEMORY ;
}
2016-06-10 10:42:33 +03:00
ret = kdc_config - > db [ 0 ] - > hdb_fetch_kvno ( kdc - > smb_krb5_context - > krb5_context ,
kdc_config - > db [ 0 ] ,
2010-11-29 03:24:08 +03:00
principal ,
HDB_F_GET_KRBTGT | HDB_F_DECRYPT ,
0 ,
& ent ) ;
2016-06-10 10:12:39 +03:00
2008-09-03 09:30:17 +04:00
if ( ret ! = 0 ) {
2022-02-22 09:41:14 +03:00
hdb_free_entry ( kdc - > smb_krb5_context - > krb5_context , kdc_config - > db [ 0 ] , & ent ) ;
2008-09-03 09:30:17 +04:00
krb5_free_principal ( kdc - > smb_krb5_context - > krb5_context , principal ) ;
2009-12-23 23:17:16 +03:00
2008-09-03 09:30:17 +04:00
return NT_STATUS_LOGON_FAILURE ;
}
2009-12-23 23:17:16 +03:00
2008-09-03 09:30:17 +04:00
kdc_sig . type = pac_validate . SignatureType ;
kdc_sig . signature = data_blob_const ( & pac_validate . ChecksumAndSignature . data [ pac_validate . ChecksumLength ] ,
pac_validate . SignatureLength ) ;
2012-01-11 11:06:55 +04:00
ret = kdc_check_pac ( kdc - > smb_krb5_context - > krb5_context , srv_sig , & kdc_sig , & ent ) ;
2008-09-03 09:30:17 +04:00
2022-02-22 09:41:14 +03:00
hdb_free_entry ( kdc - > smb_krb5_context - > krb5_context , kdc_config - > db [ 0 ] , & ent ) ;
2008-09-03 09:30:17 +04:00
krb5_free_principal ( kdc - > smb_krb5_context - > krb5_context , principal ) ;
if ( ret ! = 0 ) {
return NT_STATUS_LOGON_FAILURE ;
}
2009-12-23 23:17:16 +03:00
2008-09-03 09:30:17 +04:00
return NT_STATUS_OK ;
}
2005-06-03 15:23:15 +04:00
/*
startup the kdc task
*/
2018-08-23 00:35:52 +03:00
static NTSTATUS kdc_task_init ( struct task_server * task )
2005-06-03 15:23:15 +04:00
{
struct kdc_server * kdc ;
NTSTATUS status ;
2007-12-12 00:23:14 +03:00
struct interface * ifaces ;
2005-06-03 15:23:15 +04:00
2010-07-16 08:32:42 +04:00
switch ( lpcfg_server_role ( task - > lp_ctx ) ) {
2006-02-04 02:19:00 +03:00
case ROLE_STANDALONE :
2009-09-19 05:05:55 +04:00
task_server_terminate ( task , " kdc: no KDC required in standalone configuration " , false ) ;
2018-08-23 00:35:52 +03:00
return NT_STATUS_INVALID_DOMAIN_ROLE ;
2006-02-04 02:19:00 +03:00
case ROLE_DOMAIN_MEMBER :
2009-09-19 05:05:55 +04:00
task_server_terminate ( task , " kdc: no KDC required in member server configuration " , false ) ;
2018-08-23 00:35:52 +03:00
return NT_STATUS_INVALID_DOMAIN_ROLE ;
2012-06-10 16:08:20 +04:00
case ROLE_DOMAIN_PDC :
case ROLE_DOMAIN_BDC :
2020-11-11 19:50:45 +03:00
case ROLE_IPA_DC :
2018-09-04 03:12:49 +03:00
task_server_terminate (
task , " Cannot start KDC as a 'classic Samba' DC " , false ) ;
2018-08-23 00:35:52 +03:00
return NT_STATUS_INVALID_DOMAIN_ROLE ;
2012-06-10 16:08:20 +04:00
case ROLE_ACTIVE_DIRECTORY_DC :
2006-02-04 02:19:00 +03:00
/* Yes, we want a KDC */
break ;
}
2011-06-02 09:40:28 +04:00
load_interface_list ( task , task - > lp_ctx , & ifaces ) ;
2007-12-12 00:23:14 +03:00
2011-05-02 09:57:19 +04:00
if ( iface_list_count ( ifaces ) = = 0 ) {
2009-09-19 05:05:55 +04:00
task_server_terminate ( task , " kdc: no network interfaces configured " , false ) ;
2018-08-23 00:35:52 +03:00
return NT_STATUS_UNSUCCESSFUL ;
2005-06-03 15:23:15 +04:00
}
2006-03-09 20:48:41 +03:00
task_server_set_title ( task , " task[kdc] " ) ;
2010-11-12 09:23:34 +03:00
kdc = talloc_zero ( task , struct kdc_server ) ;
2005-06-03 15:23:15 +04:00
if ( kdc = = NULL ) {
2009-09-19 05:05:55 +04:00
task_server_terminate ( task , " kdc: out of memory " , true ) ;
2018-08-23 00:35:52 +03:00
return NT_STATUS_NO_MEMORY ;
2005-06-03 15:23:15 +04:00
}
kdc - > task = task ;
2018-08-23 02:26:40 +03:00
task - > private_data = kdc ;
2005-06-03 15:23:15 +04:00
2018-08-23 02:26:40 +03:00
/* start listening on the configured network interfaces */
status = kdc_startup_interfaces ( kdc , task - > lp_ctx , ifaces ,
task - > model_ops ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
task_server_terminate ( task , " kdc failed to setup interfaces " , true ) ;
return status ;
}
return NT_STATUS_OK ;
}
/*
initialise the kdc task after a fork
*/
2018-08-29 04:16:08 +03:00
static void kdc_post_fork ( struct task_server * task , struct process_details * pd )
2018-08-23 02:26:40 +03:00
{
struct kdc_server * kdc ;
krb5_kdc_configuration * kdc_config = NULL ;
NTSTATUS status ;
krb5_error_code ret ;
int ldb_ret ;
if ( task = = NULL ) {
task_server_terminate ( task , " kdc: Null task " , true ) ;
return ;
}
if ( task - > private_data = = NULL ) {
task_server_terminate ( task , " kdc: No kdc_server info " , true ) ;
return ;
}
kdc = talloc_get_type_abort ( task - > private_data , struct kdc_server ) ;
2010-11-12 09:23:34 +03:00
/* get a samdb connection */
2018-04-11 21:41:30 +03:00
kdc - > samdb = samdb_connect ( kdc ,
kdc - > task - > event_ctx ,
kdc - > task - > lp_ctx ,
system_session ( kdc - > task - > lp_ctx ) ,
NULL ,
0 ) ;
2010-11-12 09:23:34 +03:00
if ( ! kdc - > samdb ) {
2018-08-27 22:46:59 +03:00
DBG_WARNING ( " kdc_task_init: unable to connect to samdb \n " ) ;
2010-11-12 09:23:34 +03:00
task_server_terminate ( task , " kdc: krb5_init_context samdb connect failed " , true ) ;
2018-08-23 02:26:40 +03:00
return ;
2010-11-12 09:23:34 +03:00
}
ldb_ret = samdb_rodc ( kdc - > samdb , & kdc - > am_rodc ) ;
if ( ldb_ret ! = LDB_SUCCESS ) {
2018-08-27 22:46:59 +03:00
DBG_WARNING ( " kdc_task_init: "
" Cannot determine if we are an RODC: %s \n " ,
ldb_errstring ( kdc - > samdb ) ) ;
2010-11-12 09:23:34 +03:00
task_server_terminate ( task , " kdc: krb5_init_context samdb RODC connect failed " , true ) ;
2018-08-23 02:26:40 +03:00
return ;
2010-11-12 09:23:34 +03:00
}
kdc - > proxy_timeout = lpcfg_parm_int ( kdc - > task - > lp_ctx , NULL , " kdc " , " proxy timeout " , 5 ) ;
2005-06-03 18:32:10 +04:00
initialize_krb5_error_table ( ) ;
2014-04-17 14:35:33 +04:00
ret = smb_krb5_init_context ( kdc , task - > lp_ctx , & kdc - > smb_krb5_context ) ;
2005-06-03 18:32:10 +04:00
if ( ret ) {
2018-08-27 22:46:59 +03:00
DBG_WARNING ( " kdc_task_init: krb5_init_context failed (%s) \n " ,
error_message ( ret ) ) ;
2009-09-19 05:05:55 +04:00
task_server_terminate ( task , " kdc: krb5_init_context failed " , true ) ;
2018-08-23 02:26:40 +03:00
return ;
2005-06-03 18:32:10 +04:00
}
2005-09-28 06:22:31 +04:00
krb5_add_et_list ( kdc - > smb_krb5_context - > krb5_context , initialize_hdb_error_table_r ) ;
2009-12-23 23:17:16 +03:00
ret = krb5_kdc_get_config ( kdc - > smb_krb5_context - > krb5_context ,
2016-06-10 10:42:33 +03:00
& kdc_config ) ;
2007-01-24 05:48:40 +03:00
if ( ret ) {
2009-09-19 05:05:55 +04:00
task_server_terminate ( task , " kdc: failed to get KDC configuration " , true ) ;
2018-08-23 02:26:40 +03:00
return ;
2007-01-24 05:48:40 +03:00
}
2009-12-23 23:17:16 +03:00
2016-06-10 10:42:33 +03:00
kdc_config - > logf = ( krb5_log_facility * ) kdc - > smb_krb5_context - > pvt_log_data ;
kdc_config - > db = talloc ( kdc , struct HDB * ) ;
if ( ! kdc_config - > db ) {
2009-09-19 05:05:55 +04:00
task_server_terminate ( task , " kdc: out of memory " , true ) ;
2018-08-23 02:26:40 +03:00
return ;
2005-06-03 18:32:10 +04:00
}
2016-06-10 10:42:33 +03:00
kdc_config - > num_db = 1 ;
2009-12-23 23:17:16 +03:00
2011-07-14 23:02:20 +04:00
/*
2011-07-20 12:22:10 +04:00
* This restores the behavior before
* commit 255e3 e18e00f717d99f3bc57c8a8895ff624f3c3
* s4 : heimdal : import lorikeet - heimdal - 201107150856
* ( commit 48936803f ae4a2fb362c79365d31f420c917b85b )
2011-07-14 23:02:20 +04:00
*
2011-07-20 12:22:10 +04:00
* as_use_strongest_session_key , preauth_use_strongest_session_key
* and tgs_use_strongest_session_key are input to the
* _kdc_find_etype ( ) function . The old bahavior is in
* the use_strongest_session_key = FALSE code path .
* ( The only remaining difference in _kdc_find_etype ( )
* is the is_preauth parameter . )
*
* The old behavior in the _kdc_get_preferred_key ( )
* function is use_strongest_server_key = TRUE .
2011-07-14 23:02:20 +04:00
*/
2017-09-22 01:10:02 +03:00
kdc_config - > tgt_use_strongest_session_key = false ;
2020-04-11 00:10:28 +03:00
kdc_config - > preauth_use_strongest_session_key = true ;
2017-09-22 01:10:02 +03:00
kdc_config - > svc_use_strongest_session_key = false ;
2016-06-10 10:42:33 +03:00
kdc_config - > use_strongest_server_key = true ;
2011-07-14 23:02:20 +04:00
2021-06-17 12:27:06 +03:00
kdc_config - > force_include_pa_etype_salt = true ;
2021-12-15 02:30:28 +03:00
/*
* For Samba CVE - 2020 - 25719 Require PAC to be present
* This instructs Heimdal to match AD behaviour ,
* as seen after Microsoft ' s CVE - 2021 - 42287 when
* PacRequestorEnforcement is set to 2.
*
* Samba BUG : https : //bugzilla.samba.org/show_bug.cgi?id=14686
* REF : https : //support.microsoft.com/en-au/topic/kb5008380-authentication-updates-cve-2021-42287-9dafac11-e0d0-4cb8-959a-143bd0201041
*/
kdc_config - > require_pac = true ;
/*
* Match Windows and RFC6113 and Windows but break older
* Heimdal clients .
*/
kdc_config - > enable_armored_pa_enc_timestamp = false ;
2009-07-27 10:09:25 +04:00
/* Register hdb-samba4 hooks for use as a keytab */
2009-07-27 07:48:45 +04:00
2010-01-28 08:08:36 +03:00
kdc - > base_ctx = talloc_zero ( kdc , struct samba_kdc_base_context ) ;
if ( ! kdc - > base_ctx ) {
2009-09-19 05:05:55 +04:00
task_server_terminate ( task , " kdc: out of memory " , true ) ;
2018-08-23 02:26:40 +03:00
return ;
2009-07-27 10:09:25 +04:00
}
2010-01-28 08:08:36 +03:00
kdc - > base_ctx - > ev_ctx = task - > event_ctx ;
kdc - > base_ctx - > lp_ctx = task - > lp_ctx ;
2017-02-21 04:07:54 +03:00
kdc - > base_ctx - > msg_ctx = task - > msg_ctx ;
2010-01-28 08:08:36 +03:00
status = hdb_samba4_create_kdc ( kdc - > base_ctx ,
kdc - > smb_krb5_context - > krb5_context ,
2016-06-10 10:42:33 +03:00
& kdc_config - > db [ 0 ] ) ;
2010-01-28 08:08:36 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
task_server_terminate ( task , " kdc: hdb_samba4_create_kdc (setup KDC database) failed " , true ) ;
2018-08-23 02:26:40 +03:00
return ;
2010-01-28 08:08:36 +03:00
}
2009-07-27 07:48:45 +04:00
2009-12-23 23:17:16 +03:00
ret = krb5_plugin_register ( kdc - > smb_krb5_context - > krb5_context ,
2018-09-18 04:06:35 +03:00
PLUGIN_TYPE_DATA , " hdb_samba4_interface " ,
2011-11-30 00:45:25 +04:00
& hdb_samba4_interface ) ;
2008-09-24 23:53:10 +04:00
if ( ret ) {
2010-01-11 19:48:12 +03:00
task_server_terminate ( task , " kdc: failed to register hdb plugin " , true ) ;
2018-08-23 02:26:40 +03:00
return ;
2008-09-24 23:53:10 +04:00
}
2018-09-18 04:06:35 +03:00
kdc - > keytab_name = talloc_asprintf ( kdc , " HDB:samba4:&%p " , kdc - > base_ctx ) ;
2016-09-07 17:38:06 +03:00
if ( kdc - > keytab_name = = NULL ) {
task_server_terminate ( task ,
" kdc: Failed to set keytab name " ,
true ) ;
2018-08-23 02:26:40 +03:00
return ;
2016-09-07 17:38:06 +03:00
}
2018-09-18 04:50:55 +03:00
ret = krb5_kt_register ( kdc - > smb_krb5_context - > krb5_context , & hdb_kt_ops ) ;
if ( ret ) {
task_server_terminate ( task , " kdc: failed to register keytab plugin " , true ) ;
return ;
}
2022-02-22 04:39:13 +03:00
/* Register KDC hooks */
2009-12-23 23:17:16 +03:00
ret = krb5_plugin_register ( kdc - > smb_krb5_context - > krb5_context ,
2022-02-22 04:39:13 +03:00
PLUGIN_TYPE_DATA , " kdc " ,
& kdc_plugin_table ) ;
2007-06-13 09:44:24 +04:00
if ( ret ) {
2022-02-22 04:39:13 +03:00
task_server_terminate ( task , " kdc: failed to register kdc plugin " , true ) ;
2018-08-23 02:26:40 +03:00
return ;
2007-06-13 09:44:24 +04:00
}
2022-02-22 04:39:13 +03:00
ret = krb5_kdc_plugin_init ( kdc - > smb_krb5_context - > krb5_context ) ;
2010-11-15 01:08:43 +03:00
if ( ret ) {
2022-02-22 04:39:13 +03:00
task_server_terminate ( task , " kdc: failed to init kdc plugin " , true ) ;
2018-08-23 02:26:40 +03:00
return ;
2010-11-15 01:08:43 +03:00
}
2016-06-10 10:42:33 +03:00
ret = krb5_kdc_pkinit_config ( kdc - > smb_krb5_context - > krb5_context , kdc_config ) ;
2010-11-15 01:08:43 +03:00
if ( ret ) {
task_server_terminate ( task , " kdc: failed to init kdc pkinit subsystem " , true ) ;
2018-08-23 02:26:40 +03:00
return ;
2010-11-15 01:08:43 +03:00
}
2016-06-10 10:42:33 +03:00
kdc - > private_data = kdc_config ;
2007-01-10 04:51:35 +03:00
2009-12-23 23:17:16 +03:00
status = IRPC_REGISTER ( task - > msg_ctx , irpc , KDC_CHECK_GENERIC_KERBEROS ,
2008-09-03 09:30:17 +04:00
kdc_check_generic_kerberos , kdc ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2010-11-15 00:41:16 +03:00
task_server_terminate ( task , " kdc failed to setup monitoring " , true ) ;
2018-08-23 02:26:40 +03:00
return ;
2008-09-03 09:30:17 +04:00
}
2005-07-19 13:27:20 +04:00
irpc_add_name ( task - > msg_ctx , " kdc_server " ) ;
2005-06-03 15:23:15 +04:00
}
/* called at smbd startup - register ourselves as a server service */
2017-04-20 22:24:43 +03:00
NTSTATUS server_service_kdc_init ( TALLOC_CTX * ctx )
2005-06-03 15:23:15 +04:00
{
2018-08-23 00:29:56 +03:00
static const struct service_details details = {
2017-09-14 22:09:23 +03:00
. inhibit_fork_on_accept = true ,
2018-08-23 02:26:40 +03:00
. inhibit_pre_fork = false ,
2018-08-23 00:35:52 +03:00
. task_init = kdc_task_init ,
2018-08-23 02:26:40 +03:00
. post_fork = kdc_post_fork
2017-09-14 22:09:23 +03:00
} ;
2018-08-23 00:35:52 +03:00
return register_server_service ( ctx , " kdc " , & details ) ;
2005-06-03 15:23:15 +04:00
}