2010-06-04 00:04:08 +04:00
/*
* Unix SMB / CIFS implementation .
* RPC Pipe client / server routines
* Copyright ( C ) Andrew Tridgell 1992 - 1998 ,
* Largely re - written : 2005
* Copyright ( C ) Jeremy Allison 1998 - 2005
2010-07-07 23:24:00 +04:00
* Copyright ( C ) Simo Sorce 2010
2011-07-18 16:26:31 +04:00
* Copyright ( C ) Andrew Bartlett 2011
2010-06-04 00:04:08 +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
* 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-02-28 12:19:44 +03:00
# include "rpc_client/cli_pipe.h"
2010-08-18 20:26:17 +04:00
# include "rpc_dce.h"
2010-07-07 23:24:00 +04:00
# include "../libcli/named_pipe_auth/npa_tstream.h"
# include "rpc_server/rpc_ncacn_np.h"
# include "librpc/gen_ndr/netlogon.h"
2011-02-09 06:22:16 +03:00
# include "librpc/gen_ndr/auth.h"
# include "../auth/auth_sam_reply.h"
2018-08-30 17:33:25 +03:00
# include "../auth/auth_util.h"
2011-03-24 14:08:15 +03:00
# include "auth.h"
2011-07-21 19:02:59 +04:00
# include "rpc_server/rpc_pipes.h"
2011-04-28 19:26:40 +04:00
# include "../lib/tsocket/tsocket.h"
2011-04-28 19:38:09 +04:00
# include "../lib/util/tevent_ntstatus.h"
2011-08-10 23:34:37 +04:00
# include "rpc_server/rpc_config.h"
2013-09-18 12:59:14 +04:00
# include "librpc/ndr/ndr_table.h"
2013-09-25 13:35:41 +04:00
# include "rpc_server/rpc_server.h"
2021-04-02 13:20:38 +03:00
# include "librpc/rpc/dcerpc_util.h"
2010-06-04 00:04:08 +04:00
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_RPC_SRV
2019-02-18 23:04:00 +03:00
struct np_proxy_state {
uint16_t file_type ;
uint16_t device_state ;
uint64_t allocation_size ;
struct tstream_context * npipe ;
struct tevent_queue * read_queue ;
struct tevent_queue * write_queue ;
} ;
2021-06-18 20:56:48 +03:00
struct npa_state * npa_state_init ( TALLOC_CTX * mem_ctx )
2013-09-24 13:27:35 +04:00
{
struct npa_state * npa ;
npa = talloc_zero ( mem_ctx , struct npa_state ) ;
if ( npa = = NULL ) {
return NULL ;
}
npa - > read_queue = tevent_queue_create ( npa , " npa_cli_read " ) ;
if ( npa - > read_queue = = NULL ) {
DEBUG ( 0 , ( " tevent_queue_create failed \n " ) ) ;
goto fail ;
}
npa - > write_queue = tevent_queue_create ( npa , " npa_cli_write " ) ;
if ( npa - > write_queue = = NULL ) {
DEBUG ( 0 , ( " tevent_queue_create failed \n " ) ) ;
goto fail ;
}
return npa ;
fail :
talloc_free ( npa ) ;
return NULL ;
}
2010-09-03 21:28:00 +04:00
/**
* @ brief Create a new DCERPC Binding Handle which uses a local dispatch function .
*
* @ param [ in ] mem_ctx The memory context to use .
*
* @ param [ in ] ndr_table Normally the ndr_table_ < name > .
*
2011-06-07 19:21:28 +04:00
* @ param [ in ] remote_address The info about the connected client .
2010-09-03 21:28:00 +04:00
*
* @ param [ in ] serversupplied_info The server supplied authentication function .
*
* @ param [ in ] msg_ctx The messaging context that can be used by the server
*
* @ param [ out ] binding_handle A pointer to store the connected
* dcerpc_binding_handle
*
* @ return NT_STATUS_OK on success , a corresponding NT status if an
2017-02-17 22:46:28 +03:00
* error occurred .
2010-09-03 21:28:00 +04:00
*
* @ code
* struct dcerpc_binding_handle * winreg_binding ;
* NTSTATUS status ;
*
* status = rpcint_binding_handle ( tmp_ctx ,
* & ndr_table_winreg ,
2011-06-07 19:21:28 +04:00
* p - > remote_address ,
2011-02-21 12:25:52 +03:00
* p - > session_info ,
2010-09-03 21:28:00 +04:00
* p - > msg_ctx
* & winreg_binding ) ;
* @ endcode
*/
NTSTATUS rpcint_binding_handle ( TALLOC_CTX * mem_ctx ,
const struct ndr_interface_table * ndr_table ,
2011-06-07 19:21:28 +04:00
const struct tsocket_address * remote_address ,
2017-02-24 03:29:12 +03:00
const struct tsocket_address * local_address ,
2011-07-18 07:06:47 +04:00
const struct auth_session_info * session_info ,
2010-09-03 21:28:00 +04:00
struct messaging_context * msg_ctx ,
struct dcerpc_binding_handle * * binding_handle )
{
2021-10-07 15:52:47 +03:00
struct rpc_pipe_client * rpccli = NULL ;
NTSTATUS status ;
status = rpc_pipe_open_local_np (
mem_ctx ,
ndr_table ,
NULL ,
remote_address ,
NULL ,
local_address ,
session_info ,
& rpccli ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DBG_DEBUG ( " rpc_pipe_open_local_np failed: %s \n " ,
nt_errstr ( status ) ) ;
goto fail ;
}
* binding_handle = rpccli - > binding_handle ;
return NT_STATUS_OK ;
fail :
TALLOC_FREE ( rpccli ) ;
return status ;
2010-08-07 16:37:21 +04:00
}
2010-07-07 23:24:00 +04:00
/**
2011-05-12 00:38:46 +04:00
* @ brief Create a new RPC client context which uses a local dispatch function
* or a remote transport , depending on rpc_server configuration for the
* specific service .
*
* @ param [ in ] mem_ctx The memory context to use .
*
* @ param [ in ] abstract_syntax Normally the syntax_id of the autogenerated
* ndr_table_ < name > .
*
* @ param [ in ] serversupplied_info The server supplied authentication function .
2010-07-07 23:24:00 +04:00
*
2011-06-07 19:21:28 +04:00
* @ param [ in ] remote_address The client address information .
2011-05-12 00:38:46 +04:00
*
* @ param [ in ] msg_ctx The messaging context to use .
2010-07-07 23:24:00 +04:00
*
2011-05-12 00:38:46 +04:00
* @ param [ out ] presult A pointer to store the connected rpc client pipe .
*
* @ return NT_STATUS_OK on success , a corresponding NT status if an
2017-02-17 22:46:28 +03:00
* error occurred .
2011-05-12 00:38:46 +04:00
*
* @ code
* struct rpc_pipe_client * winreg_pipe ;
* NTSTATUS status ;
*
* status = rpc_pipe_open_interface ( tmp_ctx ,
* & ndr_table_winreg . syntax_id ,
* p - > session_info ,
2011-06-07 19:21:28 +04:00
* remote_address ,
2011-05-12 00:38:46 +04:00
* & winreg_pipe ) ;
* @ endcode
2010-07-07 23:24:00 +04:00
*/
NTSTATUS rpc_pipe_open_interface ( TALLOC_CTX * mem_ctx ,
2013-05-17 18:44:05 +04:00
const struct ndr_interface_table * table ,
2011-07-18 07:06:47 +04:00
const struct auth_session_info * session_info ,
2011-06-07 19:21:28 +04:00
const struct tsocket_address * remote_address ,
2017-02-24 03:29:12 +03:00
const struct tsocket_address * local_address ,
2010-07-07 23:24:00 +04:00
struct messaging_context * msg_ctx ,
struct rpc_pipe_client * * cli_pipe )
{
2010-09-15 13:38:53 +04:00
struct rpc_pipe_client * cli = NULL ;
2010-07-07 23:24:00 +04:00
NTSTATUS status ;
2012-12-17 20:46:34 +04:00
if ( cli_pipe ! = NULL ) {
if ( rpccli_is_connected ( * cli_pipe ) ) {
return NT_STATUS_OK ;
} else {
TALLOC_FREE ( * cli_pipe ) ;
}
2010-07-07 23:24:00 +04:00
}
2021-06-18 20:11:19 +03:00
status = rpc_pipe_open_local_np (
mem_ctx ,
table ,
NULL ,
remote_address ,
NULL ,
local_address ,
session_info ,
& cli ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DBG_ERR ( " Could not connect to %s pipe: %s \n " ,
table - > name ,
nt_errstr ( status ) ) ;
return status ;
2010-09-16 12:49:39 +04:00
}
2012-12-17 20:46:34 +04:00
if ( NT_STATUS_IS_OK ( status ) & & cli_pipe ! = NULL ) {
2021-06-18 20:11:19 +03:00
* cli_pipe = cli ;
2010-07-07 23:24:00 +04:00
}
return status ;
}