2 * Unix SMB/CIFS implementation.
3 * RPC client transport over named pipes
4 * Copyright (C) Volker Lendecke 2009
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "../lib/util/tevent_ntstatus.h"
22 #include "rpc_client/rpc_transport.h"
23 #include "librpc/ndr/ndr_table.h"
24 #include "libcli/smb/smbXcli_base.h"
25 #include "libcli/smb/tstream_smbXcli_np.h"
29 #define DBGC_CLASS DBGC_RPC_CLI
31 struct rpc_transport_np_init_state
{
32 struct rpc_cli_transport
*transport
;
35 static void rpc_transport_np_init_pipe_open(struct tevent_req
*subreq
);
37 struct tevent_req
*rpc_transport_np_init_send(TALLOC_CTX
*mem_ctx
,
38 struct tevent_context
*ev
,
39 struct cli_state
*cli
,
40 const struct ndr_interface_table
*table
)
42 struct tevent_req
*req
;
43 struct rpc_transport_np_init_state
*state
;
44 const char *pipe_name
;
45 struct tevent_req
*subreq
;
46 struct smbXcli_session
*session
;
47 struct smbXcli_tcon
*tcon
;
50 req
= tevent_req_create(mem_ctx
, &state
,
51 struct rpc_transport_np_init_state
);
56 if (smbXcli_conn_protocol(cli
->conn
) >= PROTOCOL_SMB2_02
) {
57 tcon
= cli
->smb2
.tcon
;
58 session
= cli
->smb2
.session
;
60 tcon
= cli
->smb1
.tcon
;
61 session
= cli
->smb1
.session
;
65 pipe_name
= dcerpc_default_transport_endpoint(mem_ctx
, NCACN_NP
, table
);
66 if (tevent_req_nomem(pipe_name
, req
)) {
67 return tevent_req_post(req
, ev
);
70 while (pipe_name
[0] == '\\') {
74 subreq
= tstream_smbXcli_np_open_send(state
, ev
, cli
->conn
,
76 cli
->timeout
, pipe_name
);
77 if (tevent_req_nomem(subreq
, req
)) {
78 return tevent_req_post(req
, ev
);
80 tevent_req_set_callback(subreq
, rpc_transport_np_init_pipe_open
, req
);
85 static void rpc_transport_np_init_pipe_open(struct tevent_req
*subreq
)
87 struct tevent_req
*req
= tevent_req_callback_data(
88 subreq
, struct tevent_req
);
89 struct rpc_transport_np_init_state
*state
= tevent_req_data(
90 req
, struct rpc_transport_np_init_state
);
92 struct tstream_context
*stream
;
94 status
= tstream_smbXcli_np_open_recv(subreq
, state
, &stream
);
96 if (!NT_STATUS_IS_OK(status
)) {
97 tevent_req_nterror(req
, status
);
101 status
= rpc_transport_tstream_init(state
,
104 if (!NT_STATUS_IS_OK(status
)) {
105 tevent_req_nterror(req
, status
);
109 tevent_req_done(req
);
112 NTSTATUS
rpc_transport_np_init_recv(struct tevent_req
*req
,
114 struct rpc_cli_transport
**presult
)
116 struct rpc_transport_np_init_state
*state
= tevent_req_data(
117 req
, struct rpc_transport_np_init_state
);
120 if (tevent_req_is_nterror(req
, &status
)) {
124 *presult
= talloc_move(mem_ctx
, &state
->transport
);
128 NTSTATUS
rpc_transport_np_init(TALLOC_CTX
*mem_ctx
, struct cli_state
*cli
,
129 const struct ndr_interface_table
*table
,
130 struct rpc_cli_transport
**presult
)
132 TALLOC_CTX
*frame
= talloc_stackframe();
133 struct tevent_context
*ev
;
134 struct tevent_req
*req
;
135 NTSTATUS status
= NT_STATUS_OK
;
137 ev
= samba_tevent_context_init(frame
);
139 status
= NT_STATUS_NO_MEMORY
;
143 req
= rpc_transport_np_init_send(frame
, ev
, cli
, table
);
145 status
= NT_STATUS_NO_MEMORY
;
149 if (!tevent_req_poll(req
, ev
)) {
150 status
= map_nt_error_from_unix(errno
);
154 status
= rpc_transport_np_init_recv(req
, mem_ctx
, presult
);