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-2007
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 3 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, see <http://www.gnu.org/licenses/>.
27 #include "libcli/composite/composite.h"
28 #include "libcli/smb_composite/smb_composite.h"
29 #include "lib/events/events.h"
30 #include "libcli/smb2/smb2.h"
31 #include "libcli/smb2/smb2_calls.h"
32 #include "libcli/smb/smbXcli_base.h"
33 #include "librpc/rpc/dcerpc.h"
34 #include "librpc/rpc/dcerpc_proto.h"
35 #include "auth/credentials/credentials.h"
36 #include "param/param.h"
37 #include "libcli/resolve/resolve.h"
39 struct dcerpc_pipe_connect {
40 struct dcecli_connection *conn;
41 struct dcerpc_binding *binding;
42 const char *pipe_name;
43 const struct ndr_interface_table *interface;
44 struct cli_credentials *creds;
45 struct resolve_context *resolve_ctx;
48 struct pipe_np_smb_state {
49 struct smb_composite_connect conn;
50 struct dcerpc_pipe_connect io;
55 Stage 3 of ncacn_np_smb: Named pipe opened (or not)
57 static void continue_pipe_open_smb(struct composite_context *ctx)
59 struct composite_context *c = talloc_get_type(ctx->async.private_data,
60 struct composite_context);
62 /* receive result of named pipe open request on smb */
63 c->status = dcerpc_pipe_open_smb_recv(ctx);
64 if (!composite_is_ok(c)) return;
71 Stage 2 of ncacn_np_smb: Open a named pipe after successful smb connection
73 static void continue_smb_connect(struct composite_context *ctx)
75 struct composite_context *open_ctx;
76 struct composite_context *c = talloc_get_type(ctx->async.private_data,
77 struct composite_context);
78 struct pipe_np_smb_state *s = talloc_get_type(c->private_data,
79 struct pipe_np_smb_state);
80 struct smbcli_tree *t;
81 struct smbXcli_conn *conn;
82 struct smbXcli_session *session;
83 struct smbXcli_tcon *tcon;
84 uint32_t timeout_msec;
86 /* receive result of smb connect request */
87 c->status = smb_composite_connect_recv(ctx, s->io.conn);
88 if (!composite_is_ok(c)) return;
90 /* prepare named pipe open parameters */
91 s->io.pipe_name = dcerpc_binding_get_string_option(s->io.binding, "endpoint");
92 if (s->io.pipe_name == NULL) {
93 composite_error(c, NT_STATUS_INVALID_PARAMETER_MIX);
98 conn = t->session->transport->conn;
99 session = t->session->smbXcli;
101 smb1cli_tcon_set_id(tcon, t->tid);
102 timeout_msec = t->session->transport->options.request_timeout * 1000;
104 /* send named pipe open request */
105 open_ctx = dcerpc_pipe_open_smb_send(s->io.conn,
109 if (composite_nomem(open_ctx, c)) return;
111 composite_continue(c, open_ctx, continue_pipe_open_smb, c);
116 Initiate async open of a rpc connection to a rpc pipe on SMB using
117 the binding structure to determine the endpoint and options
119 static struct composite_context *dcerpc_pipe_connect_ncacn_np_smb_send(TALLOC_CTX *mem_ctx, struct dcerpc_pipe_connect *io, struct loadparm_context *lp_ctx)
121 struct composite_context *c;
122 struct pipe_np_smb_state *s;
123 struct composite_context *conn_req;
124 struct smb_composite_connect *conn;
127 /* composite context allocation and setup */
128 c = composite_create(mem_ctx, io->conn->event_ctx);
129 if (c == NULL) return NULL;
131 s = talloc_zero(c, struct pipe_np_smb_state);
132 if (composite_nomem(s, c)) return c;
138 /* prepare smb connection parameters: we're connecting to IPC$ share on
140 conn->in.dest_host = dcerpc_binding_get_string_option(s->io.binding, "host");
141 conn->in.dest_ports = lpcfg_smb_ports(lp_ctx);
142 conn->in.called_name =
143 dcerpc_binding_get_string_option(s->io.binding, "target_hostname");
144 if (conn->in.called_name == NULL) {
145 conn->in.called_name = "*SMBSERVER";
147 conn->in.socket_options = lpcfg_socket_options(lp_ctx);
148 conn->in.service = "IPC$";
149 conn->in.service_type = NULL;
150 conn->in.workgroup = lpcfg_workgroup(lp_ctx);
151 conn->in.gensec_settings = lpcfg_gensec_settings(conn, lp_ctx);
153 lpcfg_smbcli_options(lp_ctx, &conn->in.options);
154 lpcfg_smbcli_session_options(lp_ctx, &conn->in.session_options);
157 * provide proper credentials - user supplied, but allow a
158 * fallback to anonymous if this is an schannel connection
159 * (might be NT4 not allowing machine logins at session
160 * setup) or if asked to do so by the caller (perhaps a SAMR password change?)
162 s->conn.in.credentials = s->io.creds;
163 flags = dcerpc_binding_get_flags(s->io.binding);
164 if (flags & (DCERPC_SCHANNEL|DCERPC_ANON_FALLBACK)) {
165 conn->in.fallback_to_anonymous = true;
167 conn->in.fallback_to_anonymous = false;
170 /* send smb connect request */
171 conn_req = smb_composite_connect_send(conn, s->io.conn,
174 if (composite_nomem(conn_req, c)) return c;
176 composite_continue(c, conn_req, continue_smb_connect, c);
182 Receive result of a rpc connection to a rpc pipe on SMB
184 static NTSTATUS dcerpc_pipe_connect_ncacn_np_smb_recv(struct composite_context *c)
186 NTSTATUS status = composite_wait(c);
193 struct pipe_np_smb2_state {
194 struct dcerpc_pipe_connect io;
199 Stage 3 of ncacn_np_smb: Named pipe opened (or not)
201 static void continue_pipe_open_smb2(struct composite_context *ctx)
203 struct composite_context *c = talloc_get_type(ctx->async.private_data,
204 struct composite_context);
206 /* receive result of named pipe open request on smb2 */
207 c->status = dcerpc_pipe_open_smb_recv(ctx);
208 if (!composite_is_ok(c)) return;
215 Stage 2 of ncacn_np_smb2: Open a named pipe after successful smb2 connection
217 static void continue_smb2_connect(struct tevent_req *subreq)
219 struct composite_context *open_req;
220 struct composite_context *c =
221 tevent_req_callback_data(subreq,
222 struct composite_context);
223 struct pipe_np_smb2_state *s = talloc_get_type(c->private_data,
224 struct pipe_np_smb2_state);
226 struct smbXcli_conn *conn;
227 struct smbXcli_session *session;
228 struct smbXcli_tcon *tcon;
229 uint32_t timeout_msec;
231 /* receive result of smb2 connect request */
232 c->status = smb2_connect_recv(subreq, s->io.conn, &t);
234 if (!composite_is_ok(c)) return;
236 /* prepare named pipe open parameters */
237 s->io.pipe_name = dcerpc_binding_get_string_option(s->io.binding, "endpoint");
238 if (s->io.pipe_name == NULL) {
239 composite_error(c, NT_STATUS_INVALID_PARAMETER_MIX);
243 conn = t->session->transport->conn;
244 session = t->session->smbXcli;
246 timeout_msec = t->session->transport->options.request_timeout * 1000;
248 /* send named pipe open request */
249 open_req = dcerpc_pipe_open_smb_send(s->io.conn,
253 if (composite_nomem(open_req, c)) return;
255 composite_continue(c, open_req, continue_pipe_open_smb2, c);
260 Initiate async open of a rpc connection request on SMB2 using
261 the binding structure to determine the endpoint and options
263 static struct composite_context *dcerpc_pipe_connect_ncacn_np_smb2_send(
265 struct dcerpc_pipe_connect *io,
266 struct loadparm_context *lp_ctx)
268 struct composite_context *c;
269 struct pipe_np_smb2_state *s;
270 struct tevent_req *subreq;
271 struct smbcli_options options;
275 /* composite context allocation and setup */
276 c = composite_create(mem_ctx, io->conn->event_ctx);
277 if (c == NULL) return NULL;
279 s = talloc_zero(c, struct pipe_np_smb2_state);
280 if (composite_nomem(s, c)) return c;
285 host = dcerpc_binding_get_string_option(s->io.binding, "host");
286 flags = dcerpc_binding_get_flags(s->io.binding);
289 * provide proper credentials - user supplied or anonymous in case this is
290 * schannel connection
292 if (flags & DCERPC_SCHANNEL) {
293 s->io.creds = cli_credentials_init_anon(mem_ctx);
294 if (composite_nomem(s->io.creds, c)) return c;
297 lpcfg_smbcli_options(lp_ctx, &options);
299 /* send smb2 connect request */
300 subreq = smb2_connect_send(s, c->event_ctx,
302 lpcfg_parm_string_list(mem_ctx, lp_ctx, NULL, "smb2", "ports", NULL),
306 0, /* previous_session_id */
308 lpcfg_socket_options(lp_ctx),
309 lpcfg_gensec_settings(mem_ctx, lp_ctx));
310 if (composite_nomem(subreq, c)) return c;
311 tevent_req_set_callback(subreq, continue_smb2_connect, c);
317 Receive result of a rpc connection to a rpc pipe on SMB2
319 static NTSTATUS dcerpc_pipe_connect_ncacn_np_smb2_recv(struct composite_context *c)
321 NTSTATUS status = composite_wait(c);
328 struct pipe_ip_tcp_state {
329 struct dcerpc_pipe_connect io;
330 const char *localaddr;
332 const char *target_hostname;
338 Stage 2 of ncacn_ip_tcp: rpc pipe opened (or not)
340 static void continue_pipe_open_ncacn_ip_tcp(struct composite_context *ctx)
342 struct composite_context *c = talloc_get_type(ctx->async.private_data,
343 struct composite_context);
345 /* receive result of named pipe open request on tcp/ip */
346 c->status = dcerpc_pipe_open_tcp_recv(ctx);
347 if (!composite_is_ok(c)) return;
354 Initiate async open of a rpc connection to a rpc pipe on TCP/IP using
355 the binding structure to determine the endpoint and options
357 static struct composite_context* dcerpc_pipe_connect_ncacn_ip_tcp_send(TALLOC_CTX *mem_ctx,
358 struct dcerpc_pipe_connect *io)
360 struct composite_context *c;
361 struct pipe_ip_tcp_state *s;
362 struct composite_context *pipe_req;
363 const char *endpoint;
365 /* composite context allocation and setup */
366 c = composite_create(mem_ctx, io->conn->event_ctx);
367 if (c == NULL) return NULL;
369 s = talloc_zero(c, struct pipe_ip_tcp_state);
370 if (composite_nomem(s, c)) return c;
373 /* store input parameters in state structure */
375 s->localaddr = dcerpc_binding_get_string_option(io->binding,
377 s->host = dcerpc_binding_get_string_option(io->binding, "host");
378 s->target_hostname = dcerpc_binding_get_string_option(io->binding,
380 endpoint = dcerpc_binding_get_string_option(io->binding, "endpoint");
381 /* port number is a binding endpoint here */
382 if (endpoint != NULL) {
383 s->port = atoi(endpoint);
387 composite_error(c, NT_STATUS_INVALID_PARAMETER_MIX);
391 /* send pipe open request on tcp/ip */
392 pipe_req = dcerpc_pipe_open_tcp_send(s->io.conn, s->localaddr, s->host, s->target_hostname,
393 s->port, io->resolve_ctx);
394 composite_continue(c, pipe_req, continue_pipe_open_ncacn_ip_tcp, c);
400 Receive result of a rpc connection to a rpc pipe on TCP/IP
402 static NTSTATUS dcerpc_pipe_connect_ncacn_ip_tcp_recv(struct composite_context *c)
404 NTSTATUS status = composite_wait(c);
411 struct pipe_unix_state {
412 struct dcerpc_pipe_connect io;
418 Stage 2 of ncacn_unix: rpc pipe opened (or not)
420 static void continue_pipe_open_ncacn_unix_stream(struct composite_context *ctx)
422 struct composite_context *c = talloc_get_type(ctx->async.private_data,
423 struct composite_context);
425 /* receive result of pipe open request on unix socket */
426 c->status = dcerpc_pipe_open_unix_stream_recv(ctx);
427 if (!composite_is_ok(c)) return;
434 Initiate async open of a rpc connection to a rpc pipe on unix socket using
435 the binding structure to determine the endpoint and options
437 static struct composite_context* dcerpc_pipe_connect_ncacn_unix_stream_send(TALLOC_CTX *mem_ctx,
438 struct dcerpc_pipe_connect *io)
440 struct composite_context *c;
441 struct pipe_unix_state *s;
442 struct composite_context *pipe_req;
444 /* composite context allocation and setup */
445 c = composite_create(mem_ctx, io->conn->event_ctx);
446 if (c == NULL) return NULL;
448 s = talloc_zero(c, struct pipe_unix_state);
449 if (composite_nomem(s, c)) return c;
452 /* prepare pipe open parameters and store them in state structure
453 also, verify whether biding endpoint is not null */
456 s->path = dcerpc_binding_get_string_option(io->binding, "endpoint");
457 if (s->path == NULL) {
458 composite_error(c, NT_STATUS_INVALID_PARAMETER_MIX);
462 /* send pipe open request on unix socket */
463 pipe_req = dcerpc_pipe_open_unix_stream_send(s->io.conn, s->path);
464 composite_continue(c, pipe_req, continue_pipe_open_ncacn_unix_stream, c);
470 Receive result of a rpc connection to a pipe on unix socket
472 static NTSTATUS dcerpc_pipe_connect_ncacn_unix_stream_recv(struct composite_context *c)
474 NTSTATUS status = composite_wait(c);
481 struct pipe_ncalrpc_state {
482 struct dcerpc_pipe_connect io;
485 static NTSTATUS dcerpc_pipe_connect_ncalrpc_recv(struct composite_context *c);
488 Stage 2 of ncalrpc: rpc pipe opened (or not)
490 static void continue_pipe_open_ncalrpc(struct composite_context *ctx)
492 struct composite_context *c = talloc_get_type(ctx->async.private_data,
493 struct composite_context);
495 /* receive result of pipe open request on ncalrpc */
496 c->status = dcerpc_pipe_connect_ncalrpc_recv(ctx);
497 if (!composite_is_ok(c)) return;
504 Initiate async open of a rpc connection request on NCALRPC using
505 the binding structure to determine the endpoint and options
507 static struct composite_context* dcerpc_pipe_connect_ncalrpc_send(TALLOC_CTX *mem_ctx,
508 struct dcerpc_pipe_connect *io, struct loadparm_context *lp_ctx)
510 struct composite_context *c;
511 struct pipe_ncalrpc_state *s;
512 struct composite_context *pipe_req;
513 const char *endpoint;
515 /* composite context allocation and setup */
516 c = composite_create(mem_ctx, io->conn->event_ctx);
517 if (c == NULL) return NULL;
519 s = talloc_zero(c, struct pipe_ncalrpc_state);
520 if (composite_nomem(s, c)) return c;
523 /* store input parameters in state structure */
526 endpoint = dcerpc_binding_get_string_option(io->binding, "endpoint");
527 if (endpoint == NULL) {
528 composite_error(c, NT_STATUS_INVALID_PARAMETER_MIX);
532 /* send pipe open request */
533 pipe_req = dcerpc_pipe_open_pipe_send(s->io.conn,
534 lpcfg_ncalrpc_dir(lp_ctx),
536 composite_continue(c, pipe_req, continue_pipe_open_ncalrpc, c);
542 Receive result of a rpc connection to a rpc pipe on NCALRPC
544 static NTSTATUS dcerpc_pipe_connect_ncalrpc_recv(struct composite_context *c)
546 NTSTATUS status = composite_wait(c);
553 struct pipe_connect_state {
554 struct dcerpc_pipe *pipe;
555 struct dcerpc_binding *binding;
556 const struct ndr_interface_table *table;
557 struct cli_credentials *credentials;
558 struct loadparm_context *lp_ctx;
562 static void continue_map_binding(struct composite_context *ctx);
563 static void continue_connect(struct composite_context *c, struct pipe_connect_state *s);
564 static void continue_pipe_connect_ncacn_np_smb2(struct composite_context *ctx);
565 static void continue_pipe_connect_ncacn_np_smb(struct composite_context *ctx);
566 static void continue_pipe_connect_ncacn_ip_tcp(struct composite_context *ctx);
567 static void continue_pipe_connect_ncacn_unix(struct composite_context *ctx);
568 static void continue_pipe_connect_ncalrpc(struct composite_context *ctx);
569 static void continue_pipe_connect(struct composite_context *c, struct pipe_connect_state *s);
570 static void continue_pipe_auth(struct composite_context *ctx);
574 Stage 2 of pipe_connect_b: Receive result of endpoint mapping
576 static void continue_map_binding(struct composite_context *ctx)
578 struct composite_context *c = talloc_get_type(ctx->async.private_data,
579 struct composite_context);
580 struct pipe_connect_state *s = talloc_get_type(c->private_data,
581 struct pipe_connect_state);
582 const char *endpoint;
584 c->status = dcerpc_epm_map_binding_recv(ctx);
585 if (!composite_is_ok(c)) return;
587 endpoint = dcerpc_binding_get_string_option(s->binding, "endpoint");
588 DEBUG(4,("Mapped to DCERPC endpoint %s\n", endpoint));
590 continue_connect(c, s);
595 Stage 2 of pipe_connect_b: Continue connection after endpoint is known
597 static void continue_connect(struct composite_context *c, struct pipe_connect_state *s)
599 struct dcerpc_pipe_connect pc;
601 /* potential exits to another stage by sending an async request */
602 struct composite_context *ncacn_np_smb2_req;
603 struct composite_context *ncacn_np_smb_req;
604 struct composite_context *ncacn_ip_tcp_req;
605 struct composite_context *ncacn_unix_req;
606 struct composite_context *ncalrpc_req;
607 enum dcerpc_transport_t transport;
610 /* dcerpc pipe connect input parameters */
611 pc.conn = s->pipe->conn;
612 pc.binding = s->binding;
614 pc.interface = s->table;
615 pc.creds = s->credentials;
616 pc.resolve_ctx = lpcfg_resolve_context(s->lp_ctx);
618 transport = dcerpc_binding_get_transport(s->binding);
619 flags = dcerpc_binding_get_flags(s->binding);
621 /* connect dcerpc pipe depending on required transport */
624 if (flags & DCERPC_SMB2) {
625 /* new varient of SMB a.k.a. SMB2 */
626 ncacn_np_smb2_req = dcerpc_pipe_connect_ncacn_np_smb2_send(c, &pc, s->lp_ctx);
627 composite_continue(c, ncacn_np_smb2_req, continue_pipe_connect_ncacn_np_smb2, c);
631 /* good old ordinary SMB */
632 ncacn_np_smb_req = dcerpc_pipe_connect_ncacn_np_smb_send(c, &pc, s->lp_ctx);
633 composite_continue(c, ncacn_np_smb_req, continue_pipe_connect_ncacn_np_smb, c);
639 ncacn_ip_tcp_req = dcerpc_pipe_connect_ncacn_ip_tcp_send(c, &pc);
640 composite_continue(c, ncacn_ip_tcp_req, continue_pipe_connect_ncacn_ip_tcp, c);
643 case NCACN_UNIX_STREAM:
644 ncacn_unix_req = dcerpc_pipe_connect_ncacn_unix_stream_send(c, &pc);
645 composite_continue(c, ncacn_unix_req, continue_pipe_connect_ncacn_unix, c);
649 ncalrpc_req = dcerpc_pipe_connect_ncalrpc_send(c, &pc, s->lp_ctx);
650 composite_continue(c, ncalrpc_req, continue_pipe_connect_ncalrpc, c);
654 /* looks like a transport we don't support now */
655 composite_error(c, NT_STATUS_NOT_SUPPORTED);
661 Stage 3 of pipe_connect_b: Receive result of pipe connect request on
664 static void continue_pipe_connect_ncacn_np_smb2(struct composite_context *ctx)
666 struct composite_context *c = talloc_get_type(ctx->async.private_data,
667 struct composite_context);
668 struct pipe_connect_state *s = talloc_get_type(c->private_data,
669 struct pipe_connect_state);
671 c->status = dcerpc_pipe_connect_ncacn_np_smb2_recv(ctx);
672 if (!composite_is_ok(c)) return;
674 continue_pipe_connect(c, s);
679 Stage 3 of pipe_connect_b: Receive result of pipe connect request on
682 static void continue_pipe_connect_ncacn_np_smb(struct composite_context *ctx)
684 struct composite_context *c = talloc_get_type(ctx->async.private_data,
685 struct composite_context);
686 struct pipe_connect_state *s = talloc_get_type(c->private_data,
687 struct pipe_connect_state);
689 c->status = dcerpc_pipe_connect_ncacn_np_smb_recv(ctx);
690 if (!composite_is_ok(c)) return;
692 continue_pipe_connect(c, s);
697 Stage 3 of pipe_connect_b: Receive result of pipe connect request on tcp/ip
699 static void continue_pipe_connect_ncacn_ip_tcp(struct composite_context *ctx)
701 struct composite_context *c = talloc_get_type(ctx->async.private_data,
702 struct composite_context);
703 struct pipe_connect_state *s = talloc_get_type(c->private_data,
704 struct pipe_connect_state);
706 c->status = dcerpc_pipe_connect_ncacn_ip_tcp_recv(ctx);
707 if (!composite_is_ok(c)) return;
709 continue_pipe_connect(c, s);
714 Stage 3 of pipe_connect_b: Receive result of pipe connect request on unix socket
716 static void continue_pipe_connect_ncacn_unix(struct composite_context *ctx)
718 struct composite_context *c = talloc_get_type(ctx->async.private_data,
719 struct composite_context);
720 struct pipe_connect_state *s = talloc_get_type(c->private_data,
721 struct pipe_connect_state);
723 c->status = dcerpc_pipe_connect_ncacn_unix_stream_recv(ctx);
724 if (!composite_is_ok(c)) return;
726 continue_pipe_connect(c, s);
731 Stage 3 of pipe_connect_b: Receive result of pipe connect request on local rpc
733 static void continue_pipe_connect_ncalrpc(struct composite_context *ctx)
735 struct composite_context *c = talloc_get_type(ctx->async.private_data,
736 struct composite_context);
737 struct pipe_connect_state *s = talloc_get_type(c->private_data,
738 struct pipe_connect_state);
740 c->status = dcerpc_pipe_connect_ncalrpc_recv(ctx);
741 if (!composite_is_ok(c)) return;
743 continue_pipe_connect(c, s);
748 Stage 4 of pipe_connect_b: Start an authentication on connected dcerpc pipe
749 depending on credentials and binding flags passed.
751 static void continue_pipe_connect(struct composite_context *c, struct pipe_connect_state *s)
753 struct composite_context *auth_bind_req;
755 s->pipe->binding = dcerpc_binding_dup(s->pipe, s->binding);
756 if (composite_nomem(s->pipe->binding, c)) {
760 auth_bind_req = dcerpc_pipe_auth_send(s->pipe, s->binding, s->table,
761 s->credentials, s->lp_ctx);
762 composite_continue(c, auth_bind_req, continue_pipe_auth, c);
767 Stage 5 of pipe_connect_b: Receive result of pipe authentication request
768 and say if all went ok
770 static void continue_pipe_auth(struct composite_context *ctx)
772 struct composite_context *c = talloc_get_type(ctx->async.private_data,
773 struct composite_context);
774 struct pipe_connect_state *s = talloc_get_type(c->private_data, struct pipe_connect_state);
776 c->status = dcerpc_pipe_auth_recv(ctx, s, &s->pipe);
777 if (!composite_is_ok(c)) return;
784 handle timeouts of a dcerpc connect
786 static void dcerpc_connect_timeout_handler(struct tevent_context *ev, struct tevent_timer *te,
787 struct timeval t, void *private_data)
789 struct composite_context *c = talloc_get_type_abort(private_data,
790 struct composite_context);
791 struct pipe_connect_state *s = talloc_get_type_abort(c->private_data, struct pipe_connect_state);
792 if (!s->pipe->inhibit_timeout_processing) {
793 composite_error(c, NT_STATUS_IO_TIMEOUT);
795 s->pipe->timed_out = true;
800 start a request to open a rpc connection to a rpc pipe, using
801 specified binding structure to determine the endpoint and options
803 _PUBLIC_ struct composite_context* dcerpc_pipe_connect_b_send(TALLOC_CTX *parent_ctx,
804 const struct dcerpc_binding *binding,
805 const struct ndr_interface_table *table,
806 struct cli_credentials *credentials,
807 struct tevent_context *ev,
808 struct loadparm_context *lp_ctx)
810 struct composite_context *c;
811 struct pipe_connect_state *s;
812 enum dcerpc_transport_t transport;
813 const char *endpoint = NULL;
815 /* composite context allocation and setup */
816 c = composite_create(parent_ctx, ev);
821 s = talloc_zero(c, struct pipe_connect_state);
822 if (composite_nomem(s, c)) return c;
825 /* initialise dcerpc pipe structure */
826 s->pipe = dcerpc_pipe_init(c, ev);
827 if (composite_nomem(s->pipe, c)) return c;
829 if (DEBUGLEVEL >= 10)
830 s->pipe->conn->packet_log_dir = lpcfg_lock_directory(lp_ctx);
832 /* store parameters in state structure */
833 s->binding = dcerpc_binding_dup(s, binding);
834 if (composite_nomem(s->binding, c)) return c;
836 s->credentials = credentials;
839 s->pipe->timed_out = false;
840 s->pipe->inhibit_timeout_processing = false;
842 tevent_add_timer(c->event_ctx, c,
843 timeval_current_ofs(DCERPC_REQUEST_TIMEOUT, 0),
844 dcerpc_connect_timeout_handler, c);
846 transport = dcerpc_binding_get_transport(s->binding);
852 endpoint = dcerpc_binding_get_string_option(s->binding, "endpoint");
858 if (endpoint == NULL) {
859 struct composite_context *binding_req;
861 binding_req = dcerpc_epm_map_binding_send(c, s->binding, s->table,
862 s->pipe->conn->event_ctx,
864 composite_continue(c, binding_req, continue_map_binding, c);
868 continue_connect(c, s);
874 receive result of a request to open a rpc connection to a rpc pipe
876 _PUBLIC_ NTSTATUS dcerpc_pipe_connect_b_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
877 struct dcerpc_pipe **p)
880 struct pipe_connect_state *s;
882 status = composite_wait(c);
884 if (NT_STATUS_IS_OK(status)) {
885 s = talloc_get_type(c->private_data, struct pipe_connect_state);
886 talloc_steal(mem_ctx, s->pipe);
895 open a rpc connection to a rpc pipe, using the specified
896 binding structure to determine the endpoint and options - sync version
898 _PUBLIC_ NTSTATUS dcerpc_pipe_connect_b(TALLOC_CTX *parent_ctx,
899 struct dcerpc_pipe **pp,
900 const struct dcerpc_binding *binding,
901 const struct ndr_interface_table *table,
902 struct cli_credentials *credentials,
903 struct tevent_context *ev,
904 struct loadparm_context *lp_ctx)
906 struct composite_context *c;
908 c = dcerpc_pipe_connect_b_send(parent_ctx, binding, table,
909 credentials, ev, lp_ctx);
910 return dcerpc_pipe_connect_b_recv(c, parent_ctx, pp);
914 struct pipe_conn_state {
915 struct dcerpc_pipe *pipe;
919 static void continue_pipe_connect_b(struct composite_context *ctx);
923 Initiate rpc connection to a rpc pipe, using the specified string
924 binding to determine the endpoint and options.
925 The string is to be parsed to a binding structure first.
927 _PUBLIC_ struct composite_context* dcerpc_pipe_connect_send(TALLOC_CTX *parent_ctx,
929 const struct ndr_interface_table *table,
930 struct cli_credentials *credentials,
931 struct tevent_context *ev, struct loadparm_context *lp_ctx)
933 struct composite_context *c;
934 struct pipe_conn_state *s;
935 struct dcerpc_binding *b;
936 struct composite_context *pipe_conn_req;
938 /* composite context allocation and setup */
939 c = composite_create(parent_ctx, ev);
944 s = talloc_zero(c, struct pipe_conn_state);
945 if (composite_nomem(s, c)) return c;
948 /* parse binding string to the structure */
949 c->status = dcerpc_parse_binding(c, binding, &b);
950 if (!NT_STATUS_IS_OK(c->status)) {
951 DEBUG(0, ("Failed to parse dcerpc binding '%s'\n", binding));
952 composite_error(c, c->status);
956 DEBUG(3, ("Using binding %s\n", dcerpc_binding_string(c, b)));
959 start connecting to a rpc pipe after binding structure
962 pipe_conn_req = dcerpc_pipe_connect_b_send(c, b, table,
963 credentials, ev, lp_ctx);
964 composite_continue(c, pipe_conn_req, continue_pipe_connect_b, c);
970 Stage 2 of pipe_connect: Receive result of actual pipe connect request
971 and say if we're done ok
973 static void continue_pipe_connect_b(struct composite_context *ctx)
975 struct composite_context *c = talloc_get_type(ctx->async.private_data,
976 struct composite_context);
977 struct pipe_conn_state *s = talloc_get_type(c->private_data,
978 struct pipe_conn_state);
980 c->status = dcerpc_pipe_connect_b_recv(ctx, c, &s->pipe);
981 talloc_steal(s, s->pipe);
982 if (!composite_is_ok(c)) return;
989 Receive result of pipe connect (using binding string) request
990 and return connected pipe structure.
992 NTSTATUS dcerpc_pipe_connect_recv(struct composite_context *c,
994 struct dcerpc_pipe **pp)
997 struct pipe_conn_state *s;
999 status = composite_wait(c);
1000 if (NT_STATUS_IS_OK(status)) {
1001 s = talloc_get_type(c->private_data, struct pipe_conn_state);
1002 *pp = talloc_steal(mem_ctx, s->pipe);
1010 Open a rpc connection to a rpc pipe, using the specified string
1011 binding to determine the endpoint and options - sync version
1013 _PUBLIC_ NTSTATUS dcerpc_pipe_connect(TALLOC_CTX *parent_ctx,
1014 struct dcerpc_pipe **pp,
1015 const char *binding,
1016 const struct ndr_interface_table *table,
1017 struct cli_credentials *credentials,
1018 struct tevent_context *ev,
1019 struct loadparm_context *lp_ctx)
1021 struct composite_context *c;
1022 c = dcerpc_pipe_connect_send(parent_ctx, binding,
1023 table, credentials, ev, lp_ctx);
1024 return dcerpc_pipe_connect_recv(c, parent_ctx, pp);