2 Unix SMB/CIFS implementation.
4 dcerpc connect functions
6 Copyright (C) Andrew Tridgell 2003
7 Copyright (C) Jelmer Vernooij 2004
8 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2005
9 Copyright (C) Rafal Szczesniak 2005
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include "libcli/composite/composite.h"
29 #include "libcli/smb_composite/smb_composite.h"
30 #include "libcli/smb2/smb2.h"
33 struct dcerpc_pipe_connect;
35 struct pipe_np_smb_state {
36 struct smb_composite_connect conn;
37 struct smbcli_tree *tree;
38 struct dcerpc_pipe_connect io;
43 Stage 3 of ncacn_np_smb: Named pipe opened (or not)
45 void continue_pipe_open_smb(struct composite_context *ctx)
47 struct composite_context *c = talloc_get_type(ctx->async.private_data,
48 struct composite_context);
49 struct pipe_np_smb_state *s = talloc_get_type(c->private_data,
50 struct pipe_np_smb_state);
52 /* receive result of named pipe open request on smb */
53 c->status = dcerpc_pipe_open_smb_recv(ctx);
54 if (!NT_STATUS_IS_OK(c->status)) {
55 DEBUG(0,("Failed to open pipe %s - %s\n", s->io.pipe_name, nt_errstr(c->status)));
56 composite_error(c, c->status);
64 Stage 2 of ncacn_np_smb: Open a named pipe after successful smb connection
66 void continue_smb_connect(struct composite_context *ctx)
68 struct composite_context *open_ctx;
69 struct composite_context *c = talloc_get_type(ctx->async.private_data,
70 struct composite_context);
71 struct pipe_np_smb_state *s = talloc_get_type(c->private_data,
72 struct pipe_np_smb_state);
74 /* receive result of smb connect request */
75 c->status = smb_composite_connect_recv(ctx, c);
76 if (!NT_STATUS_IS_OK(c->status)) {
77 DEBUG(0,("Failed to connect to %s - %s\n", s->io.binding->host, nt_errstr(c->status)));
78 composite_error(c, c->status);
82 /* prepare named pipe open parameters */
83 s->tree = s->conn.out.tree;
84 s->io.pipe_name = s->io.binding->endpoint;
86 /* send named pipe open request */
87 open_ctx = dcerpc_pipe_open_smb_send(s->io.pipe->conn, s->tree, s->io.pipe_name);
88 if (open_ctx == NULL) {
89 composite_error(c, NT_STATUS_NO_MEMORY);
93 composite_continue(c, open_ctx, continue_pipe_open_smb, c);
98 Initiate async open of a rpc connection to a rpc pipe on SMB using
99 the binding structure to determine the endpoint and options
101 struct composite_context *dcerpc_pipe_connect_ncacn_np_smb_send(TALLOC_CTX *tmp_ctx,
102 struct dcerpc_pipe_connect *io)
104 struct composite_context *c;
105 struct pipe_np_smb_state *s;
106 struct composite_context *conn_req;
107 struct smb_composite_connect *conn;
109 /* composite context allocation and setup */
110 c = talloc_zero(tmp_ctx, struct composite_context);
111 if (c == NULL) return NULL;
113 s = talloc_zero(c, struct pipe_np_smb_state);
115 composite_error(c, NT_STATUS_NO_MEMORY);
119 c->state = COMPOSITE_STATE_IN_PROGRESS;
121 c->event_ctx = io->pipe->conn->event_ctx;
126 /* prepare smb connection parameters: we're connecting to IPC$ share on
128 conn->in.dest_host = s->io.binding->host;
130 conn->in.called_name = strupper_talloc(tmp_ctx, s->io.binding->host);
131 conn->in.service = "IPC$";
132 conn->in.service_type = NULL;
133 conn->in.fallback_to_anonymous = False;
134 conn->in.workgroup = lp_workgroup();
137 * provide proper credentials - user supplied or anonymous in case this is
138 * schannel connection
140 if (s->io.binding->flags & DCERPC_SCHANNEL) {
141 struct cli_credentials *anon_creds;
143 anon_creds = cli_credentials_init(tmp_ctx);
145 composite_error(c, NT_STATUS_NO_MEMORY);
149 cli_credentials_set_anonymous(anon_creds);
150 cli_credentials_guess(anon_creds);
152 s->conn.in.credentials = anon_creds;
155 s->conn.in.credentials = s->io.creds;
158 /* send smb connect request */
159 conn_req = smb_composite_connect_send(conn, s->io.pipe->conn, s->io.pipe->conn->event_ctx);
161 composite_error(c, NT_STATUS_NO_MEMORY);
165 composite_continue(c, conn_req, continue_smb_connect, c);
173 Receive result of a rpc connection to a rpc pipe on SMB
175 NTSTATUS dcerpc_pipe_connect_ncacn_np_smb_recv(struct composite_context *c)
177 NTSTATUS status = composite_wait(c);
185 Sync version of a rpc connection to a rpc pipe on SMB
187 NTSTATUS dcerpc_pipe_connect_ncacn_np_smb(TALLOC_CTX *tmp_ctx,
188 struct dcerpc_pipe_connect *io)
190 struct composite_context *c;
191 c = dcerpc_pipe_connect_ncacn_np_smb_send(tmp_ctx, io);
192 return dcerpc_pipe_connect_ncacn_np_smb_recv(c);
196 struct pipe_np_smb2_state {
197 struct smb2_tree *tree;
198 struct dcerpc_pipe_connect io;
203 Stage 3 of ncacn_np_smb: Named pipe opened (or not)
205 void continue_pipe_open_smb2(struct composite_context *ctx)
207 struct composite_context *c = talloc_get_type(ctx->async.private_data,
208 struct composite_context);
209 struct pipe_np_smb2_state *s = talloc_get_type(c->private_data,
210 struct pipe_np_smb2_state);
212 /* receive result of named pipe open request on smb2 */
213 c->status = dcerpc_pipe_open_smb2_recv(ctx);
214 if (!NT_STATUS_IS_OK(c->status)) {
215 DEBUG(0,("Failed to open pipe %s - %s\n", s->io.pipe_name, nt_errstr(c->status)));
216 composite_error(c, c->status);
225 Stage 2 of ncacn_np_smb2: Open a named pipe after successful smb2 connection
227 void continue_smb2_connect(struct composite_context *ctx)
229 struct composite_context *open_req;
230 struct composite_context *c = talloc_get_type(ctx->async.private_data,
231 struct composite_context);
232 struct pipe_np_smb2_state *s = talloc_get_type(c->private_data,
233 struct pipe_np_smb2_state);
235 /* receive result of smb2 connect request */
236 c->status = smb2_connect_recv(ctx, c, &s->tree);
237 if (!NT_STATUS_IS_OK(c->status)) {
238 DEBUG(0,("Failed to connect to %s - %s\n", s->io.binding->host, nt_errstr(c->status)));
239 composite_error(c, c->status);
243 /* prepare named pipe open parameters */
244 s->io.pipe_name = s->io.binding->endpoint;
246 /* send named pipe open request */
247 open_req = dcerpc_pipe_open_smb2_send(s->io.pipe->conn, s->tree, s->io.pipe_name);
248 if (open_req == NULL) {
249 composite_error(c, NT_STATUS_NO_MEMORY);
253 composite_continue(c, open_req, continue_pipe_open_smb2, c);
258 Initiate async open of a rpc connection request on SMB2 using
259 the binding structure to determine the endpoint and options
261 struct composite_context *dcerpc_pipe_connect_ncacn_np_smb2_send(TALLOC_CTX *mem_ctx,
262 struct dcerpc_pipe_connect *io)
264 struct composite_context *c;
265 struct pipe_np_smb2_state *s;
266 struct composite_context *conn_req;
268 /* composite context allocation and setup */
269 c = talloc_zero(mem_ctx, struct composite_context);
270 if (c == NULL) return NULL;
272 s = talloc_zero(c, struct pipe_np_smb2_state);
274 composite_error(c, NT_STATUS_NO_MEMORY);
278 c->state = COMPOSITE_STATE_IN_PROGRESS;
280 c->event_ctx = io->pipe->conn->event_ctx;
285 * provide proper credentials - user supplied or anonymous in case this is
286 * schannel connection
288 if (s->io.binding->flags & DCERPC_SCHANNEL) {
289 s->io.creds = cli_credentials_init(mem_ctx);
291 composite_error(c, NT_STATUS_NO_MEMORY);
295 cli_credentials_set_anonymous(s->io.creds);
296 cli_credentials_guess(s->io.creds);
299 /* send smb2 connect request */
300 conn_req = smb2_connect_send(mem_ctx, s->io.binding->host, "IPC$", s->io.creds,
302 if (conn_req == NULL) {
303 composite_error(c, NT_STATUS_NO_MEMORY);
307 composite_continue(c, conn_req, continue_smb2_connect, c);
315 Receive result of a rpc connection to a rpc pipe on SMB2
317 NTSTATUS dcerpc_pipe_connect_ncacn_np_smb2_recv(struct composite_context *c)
319 NTSTATUS status = composite_wait(c);
327 Sync version of a rpc connection to a rpc pipe on SMB2
329 NTSTATUS dcerpc_pipe_connect_ncacn_np_smb2(TALLOC_CTX *mem_ctx,
330 struct dcerpc_pipe_connect *io)
332 struct composite_context *c;
333 c = dcerpc_pipe_connect_ncacn_np_smb2_send(mem_ctx, io);
334 return dcerpc_pipe_connect_ncacn_np_smb2_recv(c);