2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-1998,
5 * Largely re-written : 2005
6 * Copyright (C) Jeremy Allison 1998 - 2005
7 * Copyright (C) Simo Sorce 2010
8 * Copyright (C) Andrew Bartlett 2011
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <http://www.gnu.org/licenses/>.
25 #include "rpc_client/cli_pipe.h"
27 #include "../libcli/named_pipe_auth/npa_tstream.h"
28 #include "rpc_server/rpc_ncacn_np.h"
29 #include "librpc/gen_ndr/netlogon.h"
30 #include "librpc/gen_ndr/auth.h"
31 #include "../auth/auth_sam_reply.h"
32 #include "../auth/auth_util.h"
34 #include "rpc_server/rpc_pipes.h"
35 #include "../lib/tsocket/tsocket.h"
36 #include "../lib/util/tevent_ntstatus.h"
37 #include "rpc_server/rpc_config.h"
38 #include "librpc/ndr/ndr_table.h"
39 #include "rpc_server/rpc_server.h"
40 #include "librpc/rpc/dcerpc_util.h"
43 #define DBGC_CLASS DBGC_RPC_SRV
45 struct np_proxy_state
{
47 uint16_t device_state
;
48 uint64_t allocation_size
;
49 struct tstream_context
*npipe
;
50 struct tevent_queue
*read_queue
;
51 struct tevent_queue
*write_queue
;
54 struct npa_state
*npa_state_init(TALLOC_CTX
*mem_ctx
)
56 struct npa_state
*npa
;
58 npa
= talloc_zero(mem_ctx
, struct npa_state
);
63 npa
->read_queue
= tevent_queue_create(npa
, "npa_cli_read");
64 if (npa
->read_queue
== NULL
) {
65 DEBUG(0, ("tevent_queue_create failed\n"));
69 npa
->write_queue
= tevent_queue_create(npa
, "npa_cli_write");
70 if (npa
->write_queue
== NULL
) {
71 DEBUG(0, ("tevent_queue_create failed\n"));
82 * @brief Create a new DCERPC Binding Handle which uses a local dispatch function.
84 * @param[in] mem_ctx The memory context to use.
86 * @param[in] ndr_table Normally the ndr_table_<name>.
88 * @param[in] remote_address The info about the connected client.
90 * @param[in] serversupplied_info The server supplied authentication function.
92 * @param[in] msg_ctx The messaging context that can be used by the server
94 * @param[out] binding_handle A pointer to store the connected
95 * dcerpc_binding_handle
97 * @return NT_STATUS_OK on success, a corresponding NT status if an
101 * struct dcerpc_binding_handle *winreg_binding;
104 * status = rpcint_binding_handle(tmp_ctx,
112 NTSTATUS
rpcint_binding_handle(TALLOC_CTX
*mem_ctx
,
113 const struct ndr_interface_table
*ndr_table
,
114 const struct tsocket_address
*remote_address
,
115 const struct tsocket_address
*local_address
,
116 const struct auth_session_info
*session_info
,
117 struct messaging_context
*msg_ctx
,
118 struct dcerpc_binding_handle
**binding_handle
)
120 struct rpc_pipe_client
*rpccli
= NULL
;
123 status
= rpc_pipe_open_local_np(
132 if (!NT_STATUS_IS_OK(status
)) {
133 DBG_DEBUG("rpc_pipe_open_local_np failed: %s\n",
138 *binding_handle
= rpccli
->binding_handle
;
146 * @brief Create a new RPC client context which uses a local dispatch function
147 * or a remote transport, depending on rpc_server configuration for the
150 * @param[in] mem_ctx The memory context to use.
152 * @param[in] abstract_syntax Normally the syntax_id of the autogenerated
155 * @param[in] serversupplied_info The server supplied authentication function.
157 * @param[in] remote_address The client address information.
159 * @param[in] msg_ctx The messaging context to use.
161 * @param[out] presult A pointer to store the connected rpc client pipe.
163 * @return NT_STATUS_OK on success, a corresponding NT status if an
167 * struct rpc_pipe_client *winreg_pipe;
170 * status = rpc_pipe_open_interface(tmp_ctx,
171 * &ndr_table_winreg.syntax_id,
178 NTSTATUS
rpc_pipe_open_interface(TALLOC_CTX
*mem_ctx
,
179 const struct ndr_interface_table
*table
,
180 const struct auth_session_info
*session_info
,
181 const struct tsocket_address
*remote_address
,
182 const struct tsocket_address
*local_address
,
183 struct messaging_context
*msg_ctx
,
184 struct rpc_pipe_client
**cli_pipe
)
186 struct rpc_pipe_client
*cli
= NULL
;
189 if (cli_pipe
!= NULL
) {
190 if (rpccli_is_connected(*cli_pipe
)) {
193 TALLOC_FREE(*cli_pipe
);
197 status
= rpc_pipe_open_local_np(
206 if (!NT_STATUS_IS_OK(status
)) {
207 DBG_ERR("Could not connect to %s pipe: %s\n",
213 if (NT_STATUS_IS_OK(status
) && cli_pipe
!= NULL
) {