2004-10-24 19:48:19 +04:00
/*
Unix SMB / CIFS implementation .
2007-09-03 17:13:25 +04:00
smbd - specific dcerpc server code
2004-10-24 19:48:19 +04:00
2007-09-03 17:13:25 +04:00
Copyright ( C ) Andrew Tridgell 2003 - 2005
Copyright ( C ) Stefan ( metze ) Metzmacher 2004 - 2005
Copyright ( C ) Jelmer Vernooij < jelmer @ samba . org > 2004 , 2007
2004-10-24 19:48:19 +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
2004-10-24 19:48:19 +04:00
( at your option ) any later version .
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 .
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/>.
2004-10-24 19:48:19 +04:00
*/
# include "includes.h"
2007-09-03 17:13:25 +04:00
# include "librpc/gen_ndr/ndr_dcerpc.h"
# include "auth/auth.h"
2008-10-11 23:31:42 +04:00
# include "../lib/util/dlinklist.h"
2004-11-02 10:42:47 +03:00
# include "rpc_server/dcerpc_server.h"
2008-11-23 13:24:29 +03:00
# include "rpc_server/dcerpc_server_proto.h"
2007-09-03 17:13:25 +04:00
# include "system/filesys.h"
2005-07-19 13:44:11 +04:00
# include "lib/messaging/irpc.h"
2006-03-07 14:07:23 +03:00
# include "system/network.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"
2009-04-07 20:35:30 +04:00
# include "../lib/tsocket/tsocket.h"
# include "librpc/rpc/dcerpc_proto.h"
# include "../lib/util/tevent_ntstatus.h"
# include "libcli/raw/smb.h"
# include "../libcli/named_pipe_auth/npa_tstream.h"
2009-09-22 06:57:27 +04:00
# include "smbd/process_model.h"
2004-10-24 19:48:19 +04:00
2017-04-20 22:24:43 +03:00
NTSTATUS server_service_rpc_init ( TALLOC_CTX * ) ;
2007-09-03 17:13:25 +04:00
/*
open the dcerpc server sockets
*/
2018-08-23 00:35:52 +03:00
static NTSTATUS dcesrv_task_init ( struct task_server * task )
2007-09-03 17:13:25 +04:00
{
2018-08-23 00:35:52 +03:00
NTSTATUS status = NT_STATUS_UNSUCCESSFUL ;
2007-09-03 17:13:25 +04:00
struct dcesrv_context * dce_ctx ;
struct dcesrv_endpoint * e ;
2016-10-18 00:36:51 +03:00
const struct model_ops * single_model_ops ;
2008-12-09 11:22:31 +03:00
dcerpc_server_init ( task - > lp_ctx ) ;
2007-09-03 17:13:25 +04:00
task_server_set_title ( task , " task[dcesrv] " ) ;
2016-10-18 00:36:51 +03:00
/*
* run the rpc server as a single process to allow for shard
* handles , and sharing of ldb contexts .
*
* We make an exception for NETLOGON below , and this follows
* whatever the top level is .
*/
single_model_ops = process_model_startup ( " single " ) ;
if ( ! single_model_ops ) goto failed ;
2009-09-22 06:57:27 +04:00
2007-09-03 17:13:25 +04:00
status = dcesrv_init_context ( task - > event_ctx ,
2007-12-04 22:05:00 +03:00
task - > lp_ctx ,
2010-07-16 08:32:42 +04:00
lpcfg_dcerpc_endpoint_servers ( task - > lp_ctx ) ,
2007-09-03 17:13:25 +04:00
& dce_ctx ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) goto failed ;
/* Make sure the directory for NCALRPC exists */
2010-07-16 08:32:42 +04:00
if ( ! directory_exist ( lpcfg_ncalrpc_dir ( task - > lp_ctx ) ) ) {
mkdir ( lpcfg_ncalrpc_dir ( task - > lp_ctx ) , 0755 ) ;
2007-09-03 17:13:25 +04:00
}
for ( e = dce_ctx - > endpoint_list ; e ; e = e - > next ) {
2016-10-18 00:36:51 +03:00
const struct model_ops * this_model_ops = single_model_ops ;
2014-09-21 10:38:10 +04:00
enum dcerpc_transport_t transport =
dcerpc_binding_get_transport ( e - > ep_description ) ;
2017-07-27 02:10:43 +03:00
const char * transport_str
= derpc_transport_string_by_transport ( transport ) ;
struct dcesrv_if_list * iface_list ;
2014-09-21 10:38:10 +04:00
2016-10-18 00:36:51 +03:00
/*
* Ensure that - Msingle sets e - > use_single_process for
* consistency
*/
if ( task - > model_ops = = single_model_ops ) {
e - > use_single_process = true ;
}
2014-09-21 10:38:10 +04:00
if ( transport = = NCACN_HTTP ) {
/*
* We don ' t support ncacn_http yet
*/
continue ;
2016-10-18 00:36:51 +03:00
/*
* For the next two cases , what we are trying
* to do is put the NETLOGON server into the
* standard process model , not single , as it
* has no shared handles and takes a very high
* load . We only do this for ncacn_np and
* ncacn_ip_tcp as otherwise it is too hard as
* all servers share a socket for ncalrpc and
* unix .
*/
} else if ( e - > use_single_process = = false ) {
this_model_ops = task - > model_ops ;
2014-09-21 10:38:10 +04:00
}
2016-10-18 00:36:51 +03:00
status = dcesrv_add_ep ( dce_ctx , task - > lp_ctx , e , task - > event_ctx ,
2017-09-14 22:09:23 +03:00
this_model_ops , task - > process_context ) ;
2016-12-14 01:58:48 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
goto failed ;
}
2017-07-27 02:10:43 +03:00
DEBUG ( 5 , ( " Added endpoint on %s "
" using process model %s for " ,
transport_str ,
this_model_ops - > name ) ) ;
for ( iface_list = e - > interface_list ;
iface_list ! = NULL ;
iface_list = iface_list - > next ) {
DEBUGADD ( 5 , ( " %s " , iface_list - > iface . name ) ) ;
}
DEBUGADD ( 5 , ( " \n " ) ) ;
2007-09-03 17:13:25 +04:00
}
2013-05-27 14:10:57 +04:00
irpc_add_name ( task - > msg_ctx , " rpc_server " ) ;
2018-08-23 00:35:52 +03:00
return NT_STATUS_OK ;
2007-09-03 17:13:25 +04:00
failed :
2009-09-19 05:05:55 +04:00
task_server_terminate ( task , " Failed to startup dcerpc server task " , true ) ;
2018-08-23 00:35:52 +03:00
return status ;
2007-09-03 17:13:25 +04:00
}
2017-04-20 22:24:43 +03:00
NTSTATUS server_service_rpc_init ( TALLOC_CTX * ctx )
2007-09-03 17:13:25 +04:00
{
2018-08-23 00:29:56 +03:00
static const struct service_details details = {
2017-09-14 22:09:23 +03:00
/*
* This is a SNOWFLAKE , but sadly one that we
* will have to keep for now . The RPC server
* code above overstamps the SINGLE process model
* most of the time , but we need to be in forking
* mode by defult to get a forking NETLOGON server
*/
. inhibit_fork_on_accept = false ,
2018-08-23 00:35:52 +03:00
. inhibit_pre_fork = true ,
. task_init = dcesrv_task_init ,
. post_fork = NULL
2017-09-14 22:09:23 +03:00
} ;
2018-08-23 00:35:52 +03:00
return register_server_service ( ctx , " rpc " , & details ) ;
2007-09-03 17:13:25 +04:00
}