2011-01-05 19:16:46 +03:00
/*
* Unix SMB / CIFS implementation .
*
* SMBD RPC service callbacks
*
* Copyright ( c ) 2011 Andreas Schneider < asn @ samba . org >
*
* 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
* the Free Software Foundation ; either version 3 of the License , or
* ( 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
* along with this program ; if not , see < http : //www.gnu.org/licenses/>.
*/
# include "includes.h"
2011-05-02 15:21:53 +04:00
# include "ntdomain.h"
2011-01-05 19:16:46 +03:00
2011-03-10 12:17:51 +03:00
# include "../librpc/gen_ndr/ndr_epmapper_c.h"
2011-01-05 19:16:46 +03:00
# include "../librpc/gen_ndr/srv_epmapper.h"
# include "../librpc/gen_ndr/srv_srvsvc.h"
# include "../librpc/gen_ndr/srv_winreg.h"
# include "../librpc/gen_ndr/srv_dfs.h"
# include "../librpc/gen_ndr/srv_dssetup.h"
# include "../librpc/gen_ndr/srv_echo.h"
# include "../librpc/gen_ndr/srv_eventlog.h"
# include "../librpc/gen_ndr/srv_initshutdown.h"
# include "../librpc/gen_ndr/srv_lsa.h"
# include "../librpc/gen_ndr/srv_netlogon.h"
# include "../librpc/gen_ndr/srv_ntsvcs.h"
# include "../librpc/gen_ndr/srv_samr.h"
# include "../librpc/gen_ndr/srv_spoolss.h"
# include "../librpc/gen_ndr/srv_svcctl.h"
# include "../librpc/gen_ndr/srv_wkssvc.h"
2011-07-01 16:57:32 +04:00
# include "printing/nt_printing_migrate_internal.h"
2011-02-08 16:17:14 +03:00
# include "rpc_server/eventlog/srv_eventlog_reg.h"
# include "rpc_server/svcctl/srv_svcctl_reg.h"
2011-04-30 01:47:25 +04:00
# include "rpc_server/spoolss/srv_spoolss_nt.h"
2011-04-30 01:57:49 +04:00
# include "rpc_server/svcctl/srv_svcctl_nt.h"
2011-01-05 19:16:46 +03:00
2011-07-01 20:40:38 +04:00
# include "librpc/rpc/dcerpc_ep.h"
# include "rpc_server/rpc_sock_helper.h"
2011-06-06 13:13:10 +04:00
# include "rpc_server/rpc_service_setup.h"
2011-06-06 13:10:02 +04:00
# include "rpc_server/rpc_ep_register.h"
2011-02-21 11:58:26 +03:00
# include "rpc_server/rpc_server.h"
2011-03-14 19:14:19 +03:00
# include "rpc_server/epmapper/srv_epmapper.h"
2011-01-05 19:16:46 +03:00
2011-07-29 13:44:02 +04:00
enum rpc_service_mode_e rpc_epmapper_mode ( void )
{
const char * rpcsrv_type ;
enum rpc_service_mode_e state ;
rpcsrv_type = lp_parm_const_string ( GLOBAL_SECTION_SNUM ,
" rpc_server " ,
" epmapper " ,
2011-07-29 19:25:39 +04:00
" daemon " ) ;
2011-07-29 13:44:02 +04:00
if ( strcasecmp_m ( rpcsrv_type , " external " ) = = 0 ) {
state = RPC_SERVICE_MODE_EXTERNAL ;
2011-07-29 19:46:21 +04:00
} else if ( strcasecmp_m ( rpcsrv_type , " daemon " ) = = 0 ) {
state = RPC_SERVICE_MODE_DAEMON ;
} else {
state = RPC_SERVICE_MODE_DISABLED ;
}
return state ;
}
enum rpc_service_mode_e rpc_spoolss_mode ( void )
{
const char * rpcsrv_type ;
enum rpc_service_mode_e state ;
rpcsrv_type = lp_parm_const_string ( GLOBAL_SECTION_SNUM ,
" rpc_server " ,
" spoolss " ,
" embedded " ) ;
if ( strcasecmp_m ( rpcsrv_type , " embedded " ) = = 0 ) {
state = RPC_SERVICE_MODE_EMBEDDED ;
} else if ( strcasecmp_m ( rpcsrv_type , " external " ) = = 0 ) {
state = RPC_SERVICE_MODE_EXTERNAL ;
2011-07-29 13:44:02 +04:00
} else if ( strcasecmp_m ( rpcsrv_type , " daemon " ) = = 0 ) {
state = RPC_SERVICE_MODE_DAEMON ;
} else {
state = RPC_SERVICE_MODE_DISABLED ;
}
return state ;
}
2011-07-01 20:40:38 +04:00
static bool rpc_setup_epmapper ( struct tevent_context * ev_ctx ,
struct messaging_context * msg_ctx )
2011-02-21 11:58:26 +03:00
{
2011-07-14 12:40:53 +04:00
enum rpc_service_mode_e epm_mode = rpc_epmapper_mode ( ) ;
2011-07-01 20:40:38 +04:00
NTSTATUS status ;
2011-02-21 11:58:26 +03:00
2011-07-14 12:40:53 +04:00
if ( epm_mode ! = RPC_SERVICE_MODE_DISABLED ) {
2011-07-01 20:40:38 +04:00
status = rpc_epmapper_init ( NULL ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
2011-02-21 11:58:26 +03:00
}
2011-03-14 19:14:19 +03:00
return true ;
}
2011-07-01 20:40:38 +04:00
static bool rpc_setup_winreg ( struct tevent_context * ev_ctx ,
struct messaging_context * msg_ctx ,
const struct dcerpc_binding_vector * v )
2011-01-05 19:16:46 +03:00
{
2011-07-01 20:40:38 +04:00
const struct ndr_interface_table * t = & ndr_table_winreg ;
2011-03-02 17:07:27 +03:00
const char * pipe_name = " winreg " ;
2011-07-01 20:40:38 +04:00
struct dcerpc_binding_vector * v2 ;
2011-07-14 12:40:53 +04:00
enum rpc_service_mode_e epm_mode = rpc_epmapper_mode ( ) ;
2011-07-01 20:40:38 +04:00
NTSTATUS status ;
bool ok ;
status = rpc_winreg_init ( NULL ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
2011-02-22 15:06:54 +03:00
2011-07-14 12:40:53 +04:00
if ( epm_mode ! = RPC_SERVICE_MODE_DISABLED ) {
2011-07-01 20:40:38 +04:00
v2 = dcerpc_binding_vector_dup ( talloc_tos ( ) , v ) ;
if ( v2 = = NULL ) {
return false ;
}
2011-03-02 17:07:27 +03:00
2011-07-01 20:40:38 +04:00
status = dcerpc_binding_vector_replace_iface ( t , v2 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
status = dcerpc_binding_vector_add_np_default ( t , v2 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
ok = setup_dcerpc_ncalrpc_socket ( ev_ctx ,
msg_ctx ,
2011-03-14 14:29:49 +03:00
pipe_name ,
NULL ) ;
2011-03-02 17:28:25 +03:00
if ( ! ok ) {
return false ;
}
2011-07-01 20:40:38 +04:00
status = dcerpc_binding_vector_add_unix ( t , v2 , pipe_name ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-03-02 17:07:27 +03:00
return false ;
}
2011-07-01 20:40:38 +04:00
status = rpc_ep_register ( ev_ctx ,
msg_ctx ,
t ,
v2 ) ;
2011-03-02 17:28:25 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-03-02 17:07:27 +03:00
return false ;
}
2011-02-22 15:06:54 +03:00
}
2011-02-21 18:28:38 +03:00
2011-03-02 17:28:25 +03:00
return true ;
2011-01-05 19:16:46 +03:00
}
2011-07-01 20:40:38 +04:00
static bool rpc_setup_srvsvc ( struct tevent_context * ev_ctx ,
struct messaging_context * msg_ctx ,
const struct dcerpc_binding_vector * v )
2011-01-05 19:16:46 +03:00
{
2011-07-01 20:40:38 +04:00
const struct ndr_interface_table * t = & ndr_table_srvsvc ;
2011-03-02 17:07:27 +03:00
const char * pipe_name = " srvsvc " ;
2011-07-01 20:40:38 +04:00
struct dcerpc_binding_vector * v2 ;
2011-07-14 12:40:53 +04:00
enum rpc_service_mode_e epm_mode = rpc_epmapper_mode ( ) ;
2011-07-01 20:40:38 +04:00
NTSTATUS status ;
bool ok ;
status = rpc_srvsvc_init ( NULL ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
2011-02-22 15:06:54 +03:00
2011-07-14 12:40:53 +04:00
if ( epm_mode ! = RPC_SERVICE_MODE_DISABLED ) {
2011-07-01 20:40:38 +04:00
v2 = dcerpc_binding_vector_dup ( talloc_tos ( ) , v ) ;
if ( v2 = = NULL ) {
return false ;
}
2011-03-02 17:07:27 +03:00
2011-07-01 20:40:38 +04:00
status = dcerpc_binding_vector_replace_iface ( t , v2 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
status = dcerpc_binding_vector_add_np_default ( t , v2 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
ok = setup_dcerpc_ncalrpc_socket ( ev_ctx ,
msg_ctx ,
2011-03-14 14:29:49 +03:00
pipe_name ,
NULL ) ;
2011-03-02 17:28:25 +03:00
if ( ! ok ) {
return false ;
}
2011-07-01 20:40:38 +04:00
status = dcerpc_binding_vector_add_unix ( t , v2 , pipe_name ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-03-02 17:07:27 +03:00
return false ;
}
2011-07-01 20:40:38 +04:00
status = rpc_ep_register ( ev_ctx ,
msg_ctx ,
t ,
v2 ) ;
2011-03-02 17:28:25 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-03-02 17:07:27 +03:00
return false ;
}
2011-02-22 15:06:54 +03:00
}
2011-02-21 18:28:38 +03:00
2011-03-02 17:28:25 +03:00
return true ;
2011-01-05 19:16:46 +03:00
}
2011-07-01 20:40:38 +04:00
static bool rpc_setup_lsarpc ( struct tevent_context * ev_ctx ,
struct messaging_context * msg_ctx ,
const struct dcerpc_binding_vector * v )
2011-01-05 19:16:46 +03:00
{
2011-07-01 20:40:38 +04:00
const struct ndr_interface_table * t = & ndr_table_lsarpc ;
2011-03-02 17:07:27 +03:00
const char * pipe_name = " lsarpc " ;
2011-07-01 20:40:38 +04:00
struct dcerpc_binding_vector * v2 ;
2011-07-14 12:40:53 +04:00
enum rpc_service_mode_e epm_mode = rpc_epmapper_mode ( ) ;
2011-07-01 20:40:38 +04:00
NTSTATUS status ;
bool ok ;
status = rpc_lsarpc_init ( NULL ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
2011-02-22 15:06:54 +03:00
2011-07-14 12:40:53 +04:00
if ( epm_mode ! = RPC_SERVICE_MODE_DISABLED ) {
2011-07-01 20:40:38 +04:00
v2 = dcerpc_binding_vector_dup ( talloc_tos ( ) , v ) ;
if ( v2 = = NULL ) {
return false ;
}
2011-03-02 17:07:27 +03:00
2011-07-01 20:40:38 +04:00
status = dcerpc_binding_vector_replace_iface ( t , v2 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
status = dcerpc_binding_vector_add_np_default ( t , v2 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
ok = setup_dcerpc_ncalrpc_socket ( ev_ctx ,
msg_ctx ,
2011-03-14 14:29:49 +03:00
pipe_name ,
NULL ) ;
2011-03-02 17:28:25 +03:00
if ( ! ok ) {
return false ;
}
2011-07-01 20:40:38 +04:00
status = dcerpc_binding_vector_add_unix ( t , v2 , pipe_name ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-03-02 17:07:27 +03:00
return false ;
}
2011-07-01 20:40:38 +04:00
status = rpc_ep_register ( ev_ctx ,
msg_ctx ,
t ,
v2 ) ;
2011-03-02 17:28:25 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-03-02 17:07:27 +03:00
return false ;
}
2011-02-22 15:06:54 +03:00
}
2011-02-21 18:28:38 +03:00
2011-03-02 17:28:25 +03:00
return true ;
2011-01-05 19:16:46 +03:00
}
2011-07-01 20:40:38 +04:00
static bool rpc_setup_samr ( struct tevent_context * ev_ctx ,
struct messaging_context * msg_ctx ,
const struct dcerpc_binding_vector * v )
2011-01-05 19:16:46 +03:00
{
2011-07-01 20:40:38 +04:00
const struct ndr_interface_table * t = & ndr_table_samr ;
2011-03-02 17:07:27 +03:00
const char * pipe_name = " samr " ;
2011-07-01 20:40:38 +04:00
struct dcerpc_binding_vector * v2 ;
2011-07-14 12:40:53 +04:00
enum rpc_service_mode_e epm_mode = rpc_epmapper_mode ( ) ;
2011-07-01 20:40:38 +04:00
NTSTATUS status ;
bool ok ;
status = rpc_samr_init ( NULL ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
2011-02-22 15:06:54 +03:00
2011-07-14 12:40:53 +04:00
if ( epm_mode ! = RPC_SERVICE_MODE_DISABLED ) {
2011-07-01 20:40:38 +04:00
v2 = dcerpc_binding_vector_dup ( talloc_tos ( ) , v ) ;
if ( v2 = = NULL ) {
return false ;
}
2011-03-02 17:07:27 +03:00
2011-07-01 20:40:38 +04:00
status = dcerpc_binding_vector_replace_iface ( t , v2 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
status = dcerpc_binding_vector_add_np_default ( t , v2 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
ok = setup_dcerpc_ncalrpc_socket ( ev_ctx ,
msg_ctx ,
2011-03-14 14:29:49 +03:00
pipe_name ,
NULL ) ;
2011-03-02 17:28:25 +03:00
if ( ! ok ) {
return false ;
}
2011-07-01 20:40:38 +04:00
status = dcerpc_binding_vector_add_unix ( t , v2 , pipe_name ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-03-02 17:07:27 +03:00
return false ;
}
2011-07-01 20:40:38 +04:00
status = rpc_ep_register ( ev_ctx ,
msg_ctx ,
t ,
v2 ) ;
2011-03-02 17:28:25 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-03-02 17:07:27 +03:00
return false ;
}
2011-02-22 15:06:54 +03:00
}
2011-02-21 18:28:38 +03:00
2011-03-02 17:28:25 +03:00
return true ;
2011-01-05 19:16:46 +03:00
}
2011-07-01 20:40:38 +04:00
static bool rpc_setup_netlogon ( struct tevent_context * ev_ctx ,
struct messaging_context * msg_ctx ,
const struct dcerpc_binding_vector * v )
2011-01-05 19:16:46 +03:00
{
2011-07-01 20:40:38 +04:00
const struct ndr_interface_table * t = & ndr_table_netlogon ;
2011-03-02 17:07:27 +03:00
const char * pipe_name = " netlogon " ;
2011-07-01 20:40:38 +04:00
struct dcerpc_binding_vector * v2 ;
2011-07-14 12:40:53 +04:00
enum rpc_service_mode_e epm_mode = rpc_epmapper_mode ( ) ;
2011-07-01 20:40:38 +04:00
NTSTATUS status ;
bool ok ;
status = rpc_netlogon_init ( NULL ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
2011-02-22 15:06:54 +03:00
2011-07-14 12:40:53 +04:00
if ( epm_mode ! = RPC_SERVICE_MODE_DISABLED ) {
2011-07-01 20:40:38 +04:00
v2 = dcerpc_binding_vector_dup ( talloc_tos ( ) , v ) ;
if ( v2 = = NULL ) {
return false ;
}
status = dcerpc_binding_vector_replace_iface ( t , v2 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
status = dcerpc_binding_vector_add_np_default ( t , v2 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
2011-03-02 17:07:27 +03:00
2011-07-01 20:40:38 +04:00
ok = setup_dcerpc_ncalrpc_socket ( ev_ctx ,
msg_ctx ,
2011-03-14 14:29:49 +03:00
pipe_name ,
NULL ) ;
2011-03-02 17:28:25 +03:00
if ( ! ok ) {
return false ;
}
2011-07-01 20:40:38 +04:00
status = dcerpc_binding_vector_add_unix ( t , v2 , pipe_name ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-03-02 17:07:27 +03:00
return false ;
}
2011-07-01 20:40:38 +04:00
status = rpc_ep_register ( ev_ctx ,
msg_ctx ,
t ,
v2 ) ;
2011-03-02 17:28:25 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-03-02 17:07:27 +03:00
return false ;
}
2011-02-22 15:06:54 +03:00
}
2011-02-21 18:28:38 +03:00
2011-03-02 17:28:25 +03:00
return true ;
2011-01-05 19:16:46 +03:00
}
2011-07-01 20:40:38 +04:00
static bool rpc_setup_netdfs ( struct tevent_context * ev_ctx ,
struct messaging_context * msg_ctx ,
const struct dcerpc_binding_vector * v )
2011-01-05 19:16:46 +03:00
{
2011-07-01 20:40:38 +04:00
const struct ndr_interface_table * t = & ndr_table_netdfs ;
const char * pipe_name = " netdfs " ;
struct dcerpc_binding_vector * v2 ;
2011-07-14 12:40:53 +04:00
enum rpc_service_mode_e epm_mode = rpc_epmapper_mode ( ) ;
2011-07-01 20:40:38 +04:00
NTSTATUS status ;
2011-01-05 19:16:46 +03:00
bool ok ;
2011-07-01 20:40:38 +04:00
status = rpc_netdfs_init ( NULL ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
2011-07-14 12:40:53 +04:00
if ( epm_mode ! = RPC_SERVICE_MODE_DISABLED ) {
2011-07-01 20:40:38 +04:00
v2 = dcerpc_binding_vector_dup ( talloc_tos ( ) , v ) ;
if ( v2 = = NULL ) {
return false ;
}
2011-03-02 17:28:25 +03:00
2011-07-01 20:40:38 +04:00
status = dcerpc_binding_vector_replace_iface ( t , v2 ) ;
2011-03-02 17:28:25 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
2011-01-05 19:16:46 +03:00
2011-07-01 20:40:38 +04:00
status = dcerpc_binding_vector_add_np_default ( t , v2 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
2011-01-05 19:16:46 +03:00
2011-07-01 20:40:38 +04:00
ok = setup_dcerpc_ncalrpc_socket ( ev_ctx ,
msg_ctx ,
pipe_name ,
NULL ) ;
if ( ! ok ) {
return false ;
}
status = dcerpc_binding_vector_add_unix ( t , v2 , pipe_name ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
status = rpc_ep_register ( ev_ctx ,
msg_ctx ,
t ,
v2 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
}
2011-01-05 19:16:46 +03:00
2011-03-02 17:28:25 +03:00
return true ;
2011-01-05 19:16:46 +03:00
}
2011-07-01 20:40:38 +04:00
# ifdef DEVELOPER
static bool rpc_setup_rpcecho ( struct tevent_context * ev_ctx ,
struct messaging_context * msg_ctx ,
const struct dcerpc_binding_vector * v )
2011-01-05 19:16:46 +03:00
{
2011-07-01 20:40:38 +04:00
const struct ndr_interface_table * t = & ndr_table_rpcecho ;
const char * pipe_name = " rpcecho " ;
struct dcerpc_binding_vector * v2 ;
2011-07-14 12:40:53 +04:00
enum rpc_service_mode_e epm_mode = rpc_epmapper_mode ( ) ;
2011-07-01 20:40:38 +04:00
NTSTATUS status ;
2011-02-01 13:50:10 +03:00
bool ok ;
2011-07-01 20:40:38 +04:00
status = rpc_rpcecho_init ( NULL ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
2011-07-14 12:40:53 +04:00
if ( epm_mode ! = RPC_SERVICE_MODE_DISABLED ) {
2011-07-01 20:40:38 +04:00
v2 = dcerpc_binding_vector_dup ( talloc_tos ( ) , v ) ;
if ( v2 = = NULL ) {
return false ;
}
2011-03-02 17:28:25 +03:00
2011-07-01 20:40:38 +04:00
status = dcerpc_binding_vector_replace_iface ( t , v2 ) ;
2011-03-02 17:28:25 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
2011-07-01 20:40:38 +04:00
status = dcerpc_binding_vector_add_np_default ( t , v2 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
2011-01-05 19:16:46 +03:00
2011-07-01 20:40:38 +04:00
ok = setup_dcerpc_ncalrpc_socket ( ev_ctx ,
msg_ctx ,
pipe_name ,
NULL ) ;
if ( ! ok ) {
return false ;
}
status = dcerpc_binding_vector_add_unix ( t , v2 , pipe_name ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
status = rpc_ep_register ( ev_ctx ,
msg_ctx ,
t ,
v2 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
}
2011-02-01 13:50:10 +03:00
2011-03-02 17:28:25 +03:00
return true ;
2011-01-05 19:16:46 +03:00
}
2011-07-01 20:40:38 +04:00
# endif
2011-01-05 19:16:46 +03:00
2011-07-01 20:40:38 +04:00
static bool rpc_setup_dssetup ( struct tevent_context * ev_ctx ,
struct messaging_context * msg_ctx ,
const struct dcerpc_binding_vector * v )
2011-01-05 19:16:46 +03:00
{
2011-07-01 20:40:38 +04:00
const struct ndr_interface_table * t = & ndr_table_dssetup ;
const char * pipe_name = " dssetup " ;
struct dcerpc_binding_vector * v2 ;
2011-07-14 12:40:53 +04:00
enum rpc_service_mode_e epm_mode = rpc_epmapper_mode ( ) ;
2011-07-01 20:40:38 +04:00
NTSTATUS status ;
bool ok ;
status = rpc_dssetup_init ( NULL ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
2011-02-21 18:28:38 +03:00
2011-07-14 12:40:53 +04:00
if ( epm_mode ! = RPC_SERVICE_MODE_DISABLED ) {
2011-07-01 20:40:38 +04:00
v2 = dcerpc_binding_vector_dup ( talloc_tos ( ) , v ) ;
if ( v2 = = NULL ) {
return false ;
}
2011-03-02 17:28:25 +03:00
2011-07-01 20:40:38 +04:00
status = dcerpc_binding_vector_replace_iface ( t , v2 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
status = dcerpc_binding_vector_add_np_default ( t , v2 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
ok = setup_dcerpc_ncalrpc_socket ( ev_ctx ,
msg_ctx ,
pipe_name ,
NULL ) ;
if ( ! ok ) {
return false ;
}
status = dcerpc_binding_vector_add_unix ( t , v2 , pipe_name ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
status = rpc_ep_register ( ev_ctx ,
msg_ctx ,
t ,
v2 ) ;
2011-03-02 17:28:25 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
}
return true ;
2011-01-05 19:16:46 +03:00
}
2011-07-01 20:40:38 +04:00
static bool rpc_setup_wkssvc ( struct tevent_context * ev_ctx ,
struct messaging_context * msg_ctx ,
const struct dcerpc_binding_vector * v )
2011-01-05 19:16:46 +03:00
{
2011-07-01 20:40:38 +04:00
const struct ndr_interface_table * t = & ndr_table_wkssvc ;
const char * pipe_name = " wkssvc " ;
struct dcerpc_binding_vector * v2 ;
2011-07-14 12:40:53 +04:00
enum rpc_service_mode_e epm_mode = rpc_epmapper_mode ( ) ;
2011-07-01 20:40:38 +04:00
NTSTATUS status ;
2011-03-02 17:28:25 +03:00
bool ok ;
2011-01-28 14:33:20 +03:00
2011-07-01 20:40:38 +04:00
status = rpc_wkssvc_init ( NULL ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
2011-07-14 12:40:53 +04:00
if ( epm_mode ! = RPC_SERVICE_MODE_DISABLED ) {
2011-07-01 20:40:38 +04:00
v2 = dcerpc_binding_vector_dup ( talloc_tos ( ) , v ) ;
if ( v2 = = NULL ) {
return false ;
}
2011-03-02 17:28:25 +03:00
2011-07-01 20:40:38 +04:00
status = dcerpc_binding_vector_replace_iface ( t , v2 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
status = dcerpc_binding_vector_add_np_default ( t , v2 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
ok = setup_dcerpc_ncalrpc_socket ( ev_ctx ,
msg_ctx ,
pipe_name ,
NULL ) ;
if ( ! ok ) {
return false ;
}
status = dcerpc_binding_vector_add_unix ( t , v2 , pipe_name ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
status = rpc_ep_register ( ev_ctx ,
msg_ctx ,
t ,
v2 ) ;
2011-03-02 17:28:25 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
}
return true ;
2011-01-05 19:16:46 +03:00
}
2011-07-01 20:40:38 +04:00
static bool spoolss_init_cb ( void * ptr )
2011-01-05 19:16:46 +03:00
{
2011-07-01 20:40:38 +04:00
struct messaging_context * msg_ctx =
talloc_get_type_abort ( ptr , struct messaging_context ) ;
bool ok ;
2011-02-21 18:28:38 +03:00
2011-07-01 20:40:38 +04:00
/*
* Migrate the printers first .
*/
ok = nt_printing_tdb_migrate ( msg_ctx ) ;
if ( ! ok ) {
return false ;
}
2011-03-02 17:28:25 +03:00
2011-07-01 20:40:38 +04:00
return true ;
}
2011-03-02 17:28:25 +03:00
2011-07-01 20:40:38 +04:00
static bool spoolss_shutdown_cb ( void * ptr )
{
srv_spoolss_cleanup ( ) ;
2011-03-02 17:28:25 +03:00
return true ;
2011-01-05 19:16:46 +03:00
}
2011-07-01 20:40:38 +04:00
static bool rpc_setup_spoolss ( struct tevent_context * ev_ctx ,
struct messaging_context * msg_ctx )
{
const struct ndr_interface_table * t = & ndr_table_spoolss ;
struct rpc_srv_callbacks spoolss_cb ;
struct dcerpc_binding_vector * v ;
2011-07-29 19:46:37 +04:00
enum rpc_service_mode_e spoolss_mode = rpc_spoolss_mode ( ) ;
2011-07-01 20:40:38 +04:00
NTSTATUS status ;
2011-02-22 15:06:54 +03:00
2011-07-29 19:46:37 +04:00
if ( _lp_disable_spoolss ( ) | |
spoolss_mode = = RPC_SERVICE_MODE_DISABLED ) {
return true ;
}
2011-03-02 17:28:25 +03:00
2011-07-29 19:46:37 +04:00
if ( spoolss_mode = = RPC_SERVICE_MODE_EMBEDDED ) {
2011-07-01 20:40:38 +04:00
spoolss_cb . init = spoolss_init_cb ;
spoolss_cb . shutdown = spoolss_shutdown_cb ;
spoolss_cb . private_data = msg_ctx ;
2011-03-02 17:28:25 +03:00
2011-07-01 20:40:38 +04:00
status = rpc_spoolss_init ( & spoolss_cb ) ;
2011-07-29 19:46:37 +04:00
} else if ( spoolss_mode = = RPC_SERVICE_MODE_EXTERNAL | |
spoolss_mode = = RPC_SERVICE_MODE_DAEMON ) {
2011-07-01 20:40:38 +04:00
status = rpc_spoolss_init ( NULL ) ;
}
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
2011-03-02 17:28:25 +03:00
2011-07-29 19:46:37 +04:00
if ( spoolss_mode = = RPC_SERVICE_MODE_EMBEDDED ) {
2011-07-14 12:40:53 +04:00
enum rpc_service_mode_e epm_mode = rpc_epmapper_mode ( ) ;
2011-07-01 20:40:38 +04:00
2011-07-14 12:40:53 +04:00
if ( epm_mode ! = RPC_SERVICE_MODE_DISABLED ) {
2011-07-01 20:40:38 +04:00
status = dcerpc_binding_vector_new ( talloc_tos ( ) , & v ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
status = dcerpc_binding_vector_add_np_default ( t , v ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
status = rpc_ep_register ( ev_ctx ,
msg_ctx ,
t ,
v ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
2011-03-02 17:28:25 +03:00
}
2011-02-22 15:06:54 +03:00
}
2011-02-21 18:28:38 +03:00
2011-03-02 17:28:25 +03:00
return true ;
2011-01-05 19:16:46 +03:00
}
2011-07-01 20:40:38 +04:00
static bool svcctl_init_cb ( void * ptr )
{
struct messaging_context * msg_ctx =
talloc_get_type_abort ( ptr , struct messaging_context ) ;
bool ok ;
/* initialize the control hooks */
init_service_op_table ( ) ;
2011-02-22 15:06:54 +03:00
2011-07-01 20:40:38 +04:00
ok = svcctl_init_winreg ( msg_ctx ) ;
if ( ! ok ) {
return false ;
}
return true ;
}
static bool svcctl_shutdown_cb ( void * ptr )
2011-01-05 19:16:46 +03:00
{
2011-07-01 20:40:38 +04:00
shutdown_service_op_table ( ) ;
return true ;
}
static bool rpc_setup_svcctl ( struct tevent_context * ev_ctx ,
struct messaging_context * msg_ctx )
{
const struct ndr_interface_table * t = & ndr_table_svcctl ;
const char * pipe_name = " svcctl " ;
struct dcerpc_binding_vector * v ;
2011-07-14 12:40:53 +04:00
enum rpc_service_mode_e epm_mode = rpc_epmapper_mode ( ) ;
2011-07-01 20:40:38 +04:00
struct rpc_srv_callbacks svcctl_cb ;
NTSTATUS status ;
bool ok ;
svcctl_cb . init = svcctl_init_cb ;
svcctl_cb . shutdown = svcctl_shutdown_cb ;
svcctl_cb . private_data = msg_ctx ;
status = rpc_svcctl_init ( & svcctl_cb ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
2011-02-22 15:06:54 +03:00
2011-07-14 12:40:53 +04:00
if ( epm_mode ! = RPC_SERVICE_MODE_DISABLED ) {
2011-07-01 20:40:38 +04:00
status = dcerpc_binding_vector_new ( talloc_tos ( ) , & v ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
status = dcerpc_binding_vector_add_np_default ( t , v ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
2011-03-02 17:07:27 +03:00
2011-07-01 20:40:38 +04:00
ok = setup_dcerpc_ncalrpc_socket ( ev_ctx ,
msg_ctx ,
2011-03-14 14:29:49 +03:00
pipe_name ,
NULL ) ;
2011-03-02 17:28:25 +03:00
if ( ! ok ) {
return false ;
}
2011-07-01 20:40:38 +04:00
status = dcerpc_binding_vector_add_unix ( t , v , pipe_name ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-03-02 17:07:27 +03:00
return false ;
}
2011-07-01 20:40:38 +04:00
status = rpc_ep_register ( ev_ctx ,
msg_ctx ,
t ,
v ) ;
2011-03-02 17:28:25 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-03-02 17:07:27 +03:00
return false ;
}
2011-02-22 15:06:54 +03:00
}
2011-02-21 18:28:38 +03:00
2011-03-02 17:28:25 +03:00
return true ;
2011-01-05 19:16:46 +03:00
}
2011-07-01 20:40:38 +04:00
static bool rpc_setup_ntsvcs ( struct tevent_context * ev_ctx ,
struct messaging_context * msg_ctx )
2011-02-21 18:28:38 +03:00
{
2011-07-01 20:40:38 +04:00
const struct ndr_interface_table * t = & ndr_table_ntsvcs ;
struct dcerpc_binding_vector * v ;
2011-07-14 12:40:53 +04:00
enum rpc_service_mode_e epm_mode = rpc_epmapper_mode ( ) ;
2011-07-01 20:40:38 +04:00
NTSTATUS status ;
status = rpc_ntsvcs_init ( NULL ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
2011-02-22 15:06:54 +03:00
2011-07-14 12:40:53 +04:00
if ( epm_mode ! = RPC_SERVICE_MODE_DISABLED ) {
2011-07-01 20:40:38 +04:00
status = dcerpc_binding_vector_new ( talloc_tos ( ) , & v ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-03-02 17:28:25 +03:00
return false ;
}
2011-07-01 20:40:38 +04:00
status = dcerpc_binding_vector_add_np_default ( t , v ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-03-02 17:07:27 +03:00
return false ;
}
2011-07-01 20:40:38 +04:00
status = rpc_ep_register ( ev_ctx ,
msg_ctx ,
t ,
v ) ;
2011-03-02 17:28:25 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-03-02 17:07:27 +03:00
return false ;
}
2011-02-22 15:06:54 +03:00
}
2011-02-21 18:28:38 +03:00
2011-03-02 17:28:25 +03:00
return true ;
2011-01-05 19:16:46 +03:00
}
2011-07-01 20:40:38 +04:00
static bool eventlog_init_cb ( void * ptr )
2011-02-21 18:28:38 +03:00
{
2011-07-01 20:40:38 +04:00
struct messaging_context * msg_ctx =
talloc_get_type_abort ( ptr , struct messaging_context ) ;
bool ok ;
ok = eventlog_init_winreg ( msg_ctx ) ;
if ( ! ok ) {
return false ;
}
return true ;
}
static bool rpc_setup_eventlog ( struct tevent_context * ev_ctx ,
struct messaging_context * msg_ctx )
{
const struct ndr_interface_table * t = & ndr_table_eventlog ;
struct rpc_srv_callbacks eventlog_cb ;
struct dcerpc_binding_vector * v ;
2011-07-14 12:40:53 +04:00
enum rpc_service_mode_e epm_mode = rpc_epmapper_mode ( ) ;
2011-07-01 20:40:38 +04:00
NTSTATUS status ;
eventlog_cb . init = eventlog_init_cb ;
eventlog_cb . shutdown = NULL ;
eventlog_cb . private_data = msg_ctx ;
status = rpc_eventlog_init ( & eventlog_cb ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
2011-02-22 15:06:54 +03:00
2011-07-14 12:40:53 +04:00
if ( epm_mode ! = RPC_SERVICE_MODE_DISABLED ) {
2011-07-01 20:40:38 +04:00
status = dcerpc_binding_vector_new ( talloc_tos ( ) , & v ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-03-02 17:28:25 +03:00
return false ;
}
2011-07-01 20:40:38 +04:00
status = dcerpc_binding_vector_add_np_default ( t , v ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-03-02 17:07:27 +03:00
return false ;
}
2011-07-01 20:40:38 +04:00
status = rpc_ep_register ( ev_ctx ,
msg_ctx ,
t ,
v ) ;
2011-03-02 17:28:25 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-03-02 17:07:27 +03:00
return false ;
}
2011-02-22 15:06:54 +03:00
}
2011-02-21 18:28:38 +03:00
2011-03-02 17:28:25 +03:00
return true ;
2011-01-05 19:16:46 +03:00
}
2011-07-01 20:40:38 +04:00
static bool rpc_setup_initshutdown ( struct tevent_context * ev_ctx ,
struct messaging_context * msg_ctx )
2011-02-17 14:18:45 +03:00
{
2011-07-01 20:40:38 +04:00
const struct ndr_interface_table * t = & ndr_table_initshutdown ;
struct dcerpc_binding_vector * v ;
2011-07-14 12:40:53 +04:00
enum rpc_service_mode_e epm_mode = rpc_epmapper_mode ( ) ;
2011-07-01 20:40:38 +04:00
NTSTATUS status ;
2011-01-20 17:37:46 +03:00
2011-07-01 20:40:38 +04:00
status = rpc_initshutdown_init ( NULL ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-02-17 14:18:45 +03:00
return false ;
}
2011-07-14 12:40:53 +04:00
if ( epm_mode ! = RPC_SERVICE_MODE_DISABLED ) {
2011-07-01 20:40:38 +04:00
status = dcerpc_binding_vector_new ( talloc_tos ( ) , & v ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-01-20 17:37:46 +03:00
return false ;
}
2011-07-01 20:40:38 +04:00
status = dcerpc_binding_vector_add_np_default ( t , v ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2011-03-17 19:56:37 +03:00
return false ;
}
2011-01-05 19:16:46 +03:00
2011-07-01 20:40:38 +04:00
status = rpc_ep_register ( ev_ctx ,
msg_ctx ,
t ,
v ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return false ;
}
2011-01-05 19:16:46 +03:00
}
2011-07-01 20:40:38 +04:00
return true ;
}
2011-01-05 19:16:46 +03:00
2011-07-01 20:40:38 +04:00
bool dcesrv_ep_setup ( struct tevent_context * ev_ctx ,
struct messaging_context * msg_ctx )
{
struct dcerpc_binding_vector * v ;
2011-07-14 12:37:49 +04:00
const char * rpcsrv_type ;
2011-07-01 20:40:38 +04:00
TALLOC_CTX * tmp_ctx ;
NTSTATUS status ;
bool ok ;
2011-01-05 19:16:46 +03:00
2011-07-01 20:40:38 +04:00
tmp_ctx = talloc_stackframe ( ) ;
if ( tmp_ctx = = NULL ) {
2011-01-05 19:16:46 +03:00
return false ;
}
2011-07-01 20:40:38 +04:00
status = dcerpc_binding_vector_new ( tmp_ctx ,
& v ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
ok = false ;
goto done ;
2011-01-05 19:16:46 +03:00
}
2011-07-01 20:40:38 +04:00
ok = rpc_setup_epmapper ( ev_ctx , msg_ctx ) ;
if ( ! ok ) {
goto done ;
2011-01-05 19:16:46 +03:00
}
2011-07-14 12:37:49 +04:00
rpcsrv_type = lp_parm_const_string ( GLOBAL_SECTION_SNUM ,
" rpc_server " ,
" tcpip " ,
" no " ) ;
if ( strcasecmp_m ( rpcsrv_type , " yes " ) = = 0 | |
strcasecmp_m ( rpcsrv_type , " true " ) = = 0 ) {
status = rpc_setup_tcpip_sockets ( ev_ctx ,
msg_ctx ,
& ndr_table_winreg ,
v ,
0 ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
ok = false ;
goto done ;
}
2011-01-05 19:16:46 +03:00
}
2011-07-01 20:40:38 +04:00
ok = rpc_setup_winreg ( ev_ctx , msg_ctx , v ) ;
if ( ! ok ) {
goto done ;
2011-01-05 19:16:46 +03:00
}
2011-07-01 20:40:38 +04:00
ok = rpc_setup_srvsvc ( ev_ctx , msg_ctx , v ) ;
if ( ! ok ) {
goto done ;
2011-01-05 19:16:46 +03:00
}
2011-07-01 20:40:38 +04:00
ok = rpc_setup_lsarpc ( ev_ctx , msg_ctx , v ) ;
if ( ! ok ) {
goto done ;
2011-01-05 19:16:46 +03:00
}
2011-07-01 20:40:38 +04:00
ok = rpc_setup_samr ( ev_ctx , msg_ctx , v ) ;
if ( ! ok ) {
goto done ;
2011-01-05 19:16:46 +03:00
}
2011-07-01 20:40:38 +04:00
ok = rpc_setup_netlogon ( ev_ctx , msg_ctx , v ) ;
if ( ! ok ) {
goto done ;
}
ok = rpc_setup_netdfs ( ev_ctx , msg_ctx , v ) ;
if ( ! ok ) {
goto done ;
2011-01-05 19:16:46 +03:00
}
2011-03-17 18:59:10 +03:00
# ifdef DEVELOPER
2011-07-01 20:40:38 +04:00
ok = rpc_setup_rpcecho ( ev_ctx , msg_ctx , v ) ;
if ( ! ok ) {
goto done ;
2011-01-05 19:16:46 +03:00
}
# endif
2011-07-01 20:40:38 +04:00
ok = rpc_setup_dssetup ( ev_ctx , msg_ctx , v ) ;
if ( ! ok ) {
goto done ;
2011-01-05 19:16:46 +03:00
}
2011-07-01 20:40:38 +04:00
ok = rpc_setup_wkssvc ( ev_ctx , msg_ctx , v ) ;
if ( ! ok ) {
goto done ;
2011-01-05 19:16:46 +03:00
}
2011-07-01 20:40:38 +04:00
ok = rpc_setup_spoolss ( ev_ctx , msg_ctx ) ;
if ( ! ok ) {
goto done ;
}
ok = rpc_setup_svcctl ( ev_ctx , msg_ctx ) ;
if ( ! ok ) {
goto done ;
}
ok = rpc_setup_ntsvcs ( ev_ctx , msg_ctx ) ;
if ( ! ok ) {
goto done ;
}
ok = rpc_setup_eventlog ( ev_ctx , msg_ctx ) ;
if ( ! ok ) {
goto done ;
}
ok = rpc_setup_initshutdown ( ev_ctx , msg_ctx ) ;
if ( ! ok ) {
goto done ;
}
done :
talloc_free ( tmp_ctx ) ;
return ok ;
2011-01-05 19:16:46 +03:00
}
/* vim: set ts=8 sw=8 noet cindent ft=c.doxygen: */