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 struct ndr_interface_table
*interface
;
43 struct cli_credentials
*creds
;
44 struct resolve_context
*resolve_ctx
;
49 struct smbXcli_conn
*conn
;
50 struct smbXcli_session
*session
;
51 struct smbXcli_tcon
*tcon
;
52 const char *pipe_name
;
56 struct pipe_np_smb_state
{
57 struct smb_composite_connect conn
;
58 struct dcerpc_pipe_connect io
;
63 Stage 3 of ncacn_np_smb: Named pipe opened (or not)
65 static void continue_pipe_open_smb(struct composite_context
*ctx
)
67 struct composite_context
*c
= talloc_get_type(ctx
->async
.private_data
,
68 struct composite_context
);
70 /* receive result of named pipe open request on smb */
71 c
->status
= dcerpc_pipe_open_smb_recv(ctx
);
72 if (!composite_is_ok(c
)) return;
77 static void continue_smb_open(struct composite_context
*c
);
80 Stage 2 of ncacn_np_smb: Open a named pipe after successful smb connection
82 static void continue_smb_connect(struct composite_context
*ctx
)
84 struct composite_context
*c
= talloc_get_type(ctx
->async
.private_data
,
85 struct composite_context
);
86 struct pipe_np_smb_state
*s
= talloc_get_type(c
->private_data
,
87 struct pipe_np_smb_state
);
88 struct smbcli_tree
*t
;
90 /* receive result of smb connect request */
91 c
->status
= smb_composite_connect_recv(ctx
, s
->io
.conn
);
92 if (!composite_is_ok(c
)) return;
96 /* prepare named pipe open parameters */
97 s
->io
.smb
.conn
= t
->session
->transport
->conn
;
98 s
->io
.smb
.session
= t
->session
->smbXcli
;
99 s
->io
.smb
.tcon
= t
->smbXcli
;
100 smb1cli_tcon_set_id(s
->io
.smb
.tcon
, t
->tid
);
101 s
->io
.smb
.pipe_name
= dcerpc_binding_get_string_option(s
->io
.binding
,
104 continue_smb_open(c
);
107 static void continue_smb_open(struct composite_context
*c
)
109 struct pipe_np_smb_state
*s
= talloc_get_type(c
->private_data
,
110 struct pipe_np_smb_state
);
111 struct composite_context
*open_ctx
;
113 /* send named pipe open request */
114 open_ctx
= dcerpc_pipe_open_smb_send(s
->io
.conn
,
118 DCERPC_REQUEST_TIMEOUT
* 1000,
119 s
->io
.smb
.pipe_name
);
120 if (composite_nomem(open_ctx
, c
)) return;
122 composite_continue(c
, open_ctx
, continue_pipe_open_smb
, c
);
127 Initiate async open of a rpc connection to a rpc pipe on SMB using
128 the binding structure to determine the endpoint and options
130 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
)
132 struct composite_context
*c
;
133 struct pipe_np_smb_state
*s
;
134 struct composite_context
*conn_req
;
135 struct smb_composite_connect
*conn
;
138 /* composite context allocation and setup */
139 c
= composite_create(mem_ctx
, io
->conn
->event_ctx
);
140 if (c
== NULL
) return NULL
;
142 s
= talloc_zero(c
, struct pipe_np_smb_state
);
143 if (composite_nomem(s
, c
)) return c
;
149 if (smbXcli_conn_is_connected(s
->io
.smb
.conn
)) {
150 continue_smb_open(c
);
154 /* prepare smb connection parameters: we're connecting to IPC$ share on
156 conn
->in
.dest_host
= dcerpc_binding_get_string_option(s
->io
.binding
, "host");
157 conn
->in
.dest_ports
= lpcfg_smb_ports(lp_ctx
);
158 conn
->in
.called_name
=
159 dcerpc_binding_get_string_option(s
->io
.binding
, "target_hostname");
160 if (conn
->in
.called_name
== NULL
) {
161 conn
->in
.called_name
= "*SMBSERVER";
163 conn
->in
.socket_options
= lpcfg_socket_options(lp_ctx
);
164 conn
->in
.service
= "IPC$";
165 conn
->in
.service_type
= NULL
;
166 conn
->in
.workgroup
= lpcfg_workgroup(lp_ctx
);
167 conn
->in
.gensec_settings
= lpcfg_gensec_settings(conn
, lp_ctx
);
169 lpcfg_smbcli_options(lp_ctx
, &conn
->in
.options
);
170 lpcfg_smbcli_session_options(lp_ctx
, &conn
->in
.session_options
);
173 * provide proper credentials - user supplied, but allow a
174 * fallback to anonymous if this is an schannel connection
175 * (might be NT4 not allowing machine logins at session
176 * setup) or if asked to do so by the caller (perhaps a SAMR password change?)
178 s
->conn
.in
.credentials
= s
->io
.creds
;
179 flags
= dcerpc_binding_get_flags(s
->io
.binding
);
180 if (flags
& (DCERPC_SCHANNEL
|DCERPC_ANON_FALLBACK
)) {
181 conn
->in
.fallback_to_anonymous
= true;
183 conn
->in
.fallback_to_anonymous
= false;
186 /* send smb connect request */
187 conn_req
= smb_composite_connect_send(conn
, s
->io
.conn
,
190 if (composite_nomem(conn_req
, c
)) return c
;
192 composite_continue(c
, conn_req
, continue_smb_connect
, c
);
198 Receive result of a rpc connection to a rpc pipe on SMB
200 static NTSTATUS
dcerpc_pipe_connect_ncacn_np_smb_recv(struct composite_context
*c
)
202 NTSTATUS status
= composite_wait(c
);
209 Stage 2 of ncacn_np_smb2: Open a named pipe after successful smb2 connection
211 static void continue_smb2_connect(struct tevent_req
*subreq
)
213 struct composite_context
*c
=
214 tevent_req_callback_data(subreq
,
215 struct composite_context
);
216 struct pipe_np_smb_state
*s
= talloc_get_type(c
->private_data
,
217 struct pipe_np_smb_state
);
220 /* receive result of smb2 connect request */
221 c
->status
= smb2_connect_recv(subreq
, s
->io
.conn
, &t
);
223 if (!composite_is_ok(c
)) return;
225 s
->io
.smb
.conn
= t
->session
->transport
->conn
;
226 s
->io
.smb
.session
= t
->session
->smbXcli
;
227 s
->io
.smb
.tcon
= t
->smbXcli
;
228 s
->io
.smb
.pipe_name
= dcerpc_binding_get_string_option(s
->io
.binding
,
231 continue_smb_open(c
);
236 Initiate async open of a rpc connection request on SMB2 using
237 the binding structure to determine the endpoint and options
239 static struct composite_context
*dcerpc_pipe_connect_ncacn_np_smb2_send(
241 struct dcerpc_pipe_connect
*io
,
242 struct loadparm_context
*lp_ctx
)
244 struct composite_context
*c
;
245 struct pipe_np_smb_state
*s
;
246 struct tevent_req
*subreq
;
247 struct smbcli_options options
;
251 /* composite context allocation and setup */
252 c
= composite_create(mem_ctx
, io
->conn
->event_ctx
);
253 if (c
== NULL
) return NULL
;
255 s
= talloc_zero(c
, struct pipe_np_smb_state
);
256 if (composite_nomem(s
, c
)) return c
;
261 if (smbXcli_conn_is_connected(s
->io
.smb
.conn
)) {
262 continue_smb_open(c
);
266 host
= dcerpc_binding_get_string_option(s
->io
.binding
, "host");
267 flags
= dcerpc_binding_get_flags(s
->io
.binding
);
270 * provide proper credentials - user supplied or anonymous in case this is
271 * schannel connection
273 if (flags
& DCERPC_SCHANNEL
) {
274 s
->io
.creds
= cli_credentials_init_anon(mem_ctx
);
275 if (composite_nomem(s
->io
.creds
, c
)) return c
;
278 lpcfg_smbcli_options(lp_ctx
, &options
);
280 /* send smb2 connect request */
281 subreq
= smb2_connect_send(s
, c
->event_ctx
,
283 lpcfg_parm_string_list(mem_ctx
, lp_ctx
, NULL
, "smb2", "ports", NULL
),
287 0, /* previous_session_id */
289 lpcfg_socket_options(lp_ctx
),
290 lpcfg_gensec_settings(mem_ctx
, lp_ctx
));
291 if (composite_nomem(subreq
, c
)) return c
;
292 tevent_req_set_callback(subreq
, continue_smb2_connect
, c
);
298 Receive result of a rpc connection to a rpc pipe on SMB2
300 static NTSTATUS
dcerpc_pipe_connect_ncacn_np_smb2_recv(struct composite_context
*c
)
302 NTSTATUS status
= composite_wait(c
);
309 struct pipe_ip_tcp_state
{
310 struct dcerpc_pipe_connect io
;
311 const char *localaddr
;
313 const char *target_hostname
;
319 Stage 2 of ncacn_ip_tcp: rpc pipe opened (or not)
321 static void continue_pipe_open_ncacn_ip_tcp(struct composite_context
*ctx
)
323 struct composite_context
*c
= talloc_get_type(ctx
->async
.private_data
,
324 struct composite_context
);
325 struct pipe_ip_tcp_state
*s
= talloc_get_type(c
->private_data
,
326 struct pipe_ip_tcp_state
);
327 char *localaddr
= NULL
;
328 char *remoteaddr
= NULL
;
330 /* receive result of named pipe open request on tcp/ip */
331 c
->status
= dcerpc_pipe_open_tcp_recv(ctx
, s
, &localaddr
, &remoteaddr
);
332 if (!composite_is_ok(c
)) return;
334 c
->status
= dcerpc_binding_set_string_option(s
->io
.binding
,
337 if (!composite_is_ok(c
)) return;
339 c
->status
= dcerpc_binding_set_string_option(s
->io
.binding
,
342 if (!composite_is_ok(c
)) return;
349 Initiate async open of a rpc connection to a rpc pipe on TCP/IP using
350 the binding structure to determine the endpoint and options
352 static struct composite_context
* dcerpc_pipe_connect_ncacn_ip_tcp_send(TALLOC_CTX
*mem_ctx
,
353 struct dcerpc_pipe_connect
*io
)
355 struct composite_context
*c
;
356 struct pipe_ip_tcp_state
*s
;
357 struct composite_context
*pipe_req
;
358 const char *endpoint
;
360 /* composite context allocation and setup */
361 c
= composite_create(mem_ctx
, io
->conn
->event_ctx
);
362 if (c
== NULL
) return NULL
;
364 s
= talloc_zero(c
, struct pipe_ip_tcp_state
);
365 if (composite_nomem(s
, c
)) return c
;
368 /* store input parameters in state structure */
370 s
->localaddr
= dcerpc_binding_get_string_option(io
->binding
,
372 s
->host
= dcerpc_binding_get_string_option(io
->binding
, "host");
373 s
->target_hostname
= dcerpc_binding_get_string_option(io
->binding
,
375 endpoint
= dcerpc_binding_get_string_option(io
->binding
, "endpoint");
376 /* port number is a binding endpoint here */
377 if (endpoint
!= NULL
) {
378 s
->port
= atoi(endpoint
);
382 composite_error(c
, NT_STATUS_INVALID_PARAMETER_MIX
);
386 /* send pipe open request on tcp/ip */
387 pipe_req
= dcerpc_pipe_open_tcp_send(s
->io
.conn
, s
->localaddr
, s
->host
, s
->target_hostname
,
388 s
->port
, io
->resolve_ctx
);
389 composite_continue(c
, pipe_req
, continue_pipe_open_ncacn_ip_tcp
, c
);
395 Receive result of a rpc connection to a rpc pipe on TCP/IP
397 static NTSTATUS
dcerpc_pipe_connect_ncacn_ip_tcp_recv(struct composite_context
*c
)
399 NTSTATUS status
= composite_wait(c
);
406 struct pipe_unix_state
{
407 struct dcerpc_pipe_connect io
;
413 Stage 2 of ncacn_unix: rpc pipe opened (or not)
415 static void continue_pipe_open_ncacn_unix_stream(struct composite_context
*ctx
)
417 struct composite_context
*c
= talloc_get_type(ctx
->async
.private_data
,
418 struct composite_context
);
420 /* receive result of pipe open request on unix socket */
421 c
->status
= dcerpc_pipe_open_unix_stream_recv(ctx
);
422 if (!composite_is_ok(c
)) return;
429 Initiate async open of a rpc connection to a rpc pipe on unix socket using
430 the binding structure to determine the endpoint and options
432 static struct composite_context
* dcerpc_pipe_connect_ncacn_unix_stream_send(TALLOC_CTX
*mem_ctx
,
433 struct dcerpc_pipe_connect
*io
)
435 struct composite_context
*c
;
436 struct pipe_unix_state
*s
;
437 struct composite_context
*pipe_req
;
439 /* composite context allocation and setup */
440 c
= composite_create(mem_ctx
, io
->conn
->event_ctx
);
441 if (c
== NULL
) return NULL
;
443 s
= talloc_zero(c
, struct pipe_unix_state
);
444 if (composite_nomem(s
, c
)) return c
;
447 /* prepare pipe open parameters and store them in state structure
448 also, verify whether biding endpoint is not null */
451 s
->path
= dcerpc_binding_get_string_option(io
->binding
, "endpoint");
452 if (s
->path
== NULL
) {
453 composite_error(c
, NT_STATUS_INVALID_PARAMETER_MIX
);
457 /* send pipe open request on unix socket */
458 pipe_req
= dcerpc_pipe_open_unix_stream_send(s
->io
.conn
, s
->path
);
459 composite_continue(c
, pipe_req
, continue_pipe_open_ncacn_unix_stream
, c
);
465 Receive result of a rpc connection to a pipe on unix socket
467 static NTSTATUS
dcerpc_pipe_connect_ncacn_unix_stream_recv(struct composite_context
*c
)
469 NTSTATUS status
= composite_wait(c
);
476 struct pipe_ncalrpc_state
{
477 struct dcerpc_pipe_connect io
;
480 static NTSTATUS
dcerpc_pipe_connect_ncalrpc_recv(struct composite_context
*c
);
483 Stage 2 of ncalrpc: rpc pipe opened (or not)
485 static void continue_pipe_open_ncalrpc(struct composite_context
*ctx
)
487 struct composite_context
*c
= talloc_get_type(ctx
->async
.private_data
,
488 struct composite_context
);
490 /* receive result of pipe open request on ncalrpc */
491 c
->status
= dcerpc_pipe_connect_ncalrpc_recv(ctx
);
492 if (!composite_is_ok(c
)) return;
499 Initiate async open of a rpc connection request on NCALRPC using
500 the binding structure to determine the endpoint and options
502 static struct composite_context
* dcerpc_pipe_connect_ncalrpc_send(TALLOC_CTX
*mem_ctx
,
503 struct dcerpc_pipe_connect
*io
)
505 struct composite_context
*c
;
506 struct pipe_ncalrpc_state
*s
;
507 struct composite_context
*pipe_req
;
508 const char *endpoint
;
510 /* composite context allocation and setup */
511 c
= composite_create(mem_ctx
, io
->conn
->event_ctx
);
512 if (c
== NULL
) return NULL
;
514 s
= talloc_zero(c
, struct pipe_ncalrpc_state
);
515 if (composite_nomem(s
, c
)) return c
;
518 /* store input parameters in state structure */
521 endpoint
= dcerpc_binding_get_string_option(io
->binding
, "endpoint");
522 if (endpoint
== NULL
) {
523 composite_error(c
, NT_STATUS_INVALID_PARAMETER_MIX
);
527 /* send pipe open request */
528 pipe_req
= dcerpc_pipe_open_pipe_send(s
->io
.conn
,
531 composite_continue(c
, pipe_req
, continue_pipe_open_ncalrpc
, c
);
537 Receive result of a rpc connection to a rpc pipe on NCALRPC
539 static NTSTATUS
dcerpc_pipe_connect_ncalrpc_recv(struct composite_context
*c
)
541 NTSTATUS status
= composite_wait(c
);
548 struct pipe_connect_state
{
549 struct dcerpc_pipe
*pipe
;
550 struct dcerpc_binding
*binding
;
551 const struct ndr_interface_table
*table
;
552 struct cli_credentials
*credentials
;
553 struct loadparm_context
*lp_ctx
;
557 static void continue_map_binding(struct composite_context
*ctx
);
558 static void continue_connect(struct composite_context
*c
, struct pipe_connect_state
*s
);
559 static void continue_pipe_connect_ncacn_np_smb2(struct composite_context
*ctx
);
560 static void continue_pipe_connect_ncacn_np_smb(struct composite_context
*ctx
);
561 static void continue_pipe_connect_ncacn_ip_tcp(struct composite_context
*ctx
);
562 static void continue_pipe_connect_ncacn_unix(struct composite_context
*ctx
);
563 static void continue_pipe_connect_ncalrpc(struct composite_context
*ctx
);
564 static void continue_pipe_connect(struct composite_context
*c
, struct pipe_connect_state
*s
);
565 static void continue_pipe_auth(struct composite_context
*ctx
);
569 Stage 2 of pipe_connect_b: Receive result of endpoint mapping
571 static void continue_map_binding(struct composite_context
*ctx
)
573 struct composite_context
*c
= talloc_get_type(ctx
->async
.private_data
,
574 struct composite_context
);
575 struct pipe_connect_state
*s
= talloc_get_type(c
->private_data
,
576 struct pipe_connect_state
);
577 const char *endpoint
;
579 c
->status
= dcerpc_epm_map_binding_recv(ctx
);
580 if (!composite_is_ok(c
)) return;
582 endpoint
= dcerpc_binding_get_string_option(s
->binding
, "endpoint");
583 DEBUG(4,("Mapped to DCERPC endpoint %s\n", endpoint
));
585 continue_connect(c
, s
);
590 Stage 2 of pipe_connect_b: Continue connection after endpoint is known
592 static void continue_connect(struct composite_context
*c
, struct pipe_connect_state
*s
)
594 struct dcerpc_pipe_connect pc
;
596 /* potential exits to another stage by sending an async request */
597 struct composite_context
*ncacn_np_smb2_req
;
598 struct composite_context
*ncacn_np_smb_req
;
599 struct composite_context
*ncacn_ip_tcp_req
;
600 struct composite_context
*ncacn_unix_req
;
601 struct composite_context
*ncalrpc_req
;
602 enum dcerpc_transport_t transport
;
605 /* dcerpc pipe connect input parameters */
607 pc
.conn
= s
->pipe
->conn
;
608 pc
.binding
= s
->binding
;
609 pc
.interface
= s
->table
;
610 pc
.creds
= s
->credentials
;
611 pc
.resolve_ctx
= lpcfg_resolve_context(s
->lp_ctx
);
613 transport
= dcerpc_binding_get_transport(s
->binding
);
614 flags
= dcerpc_binding_get_flags(s
->binding
);
616 /* connect dcerpc pipe depending on required transport */
619 if (flags
& DCERPC_SMB2
) {
620 /* new varient of SMB a.k.a. SMB2 */
621 ncacn_np_smb2_req
= dcerpc_pipe_connect_ncacn_np_smb2_send(c
, &pc
, s
->lp_ctx
);
622 composite_continue(c
, ncacn_np_smb2_req
, continue_pipe_connect_ncacn_np_smb2
, c
);
626 /* good old ordinary SMB */
627 ncacn_np_smb_req
= dcerpc_pipe_connect_ncacn_np_smb_send(c
, &pc
, s
->lp_ctx
);
628 composite_continue(c
, ncacn_np_smb_req
, continue_pipe_connect_ncacn_np_smb
, c
);
634 ncacn_ip_tcp_req
= dcerpc_pipe_connect_ncacn_ip_tcp_send(c
, &pc
);
635 composite_continue(c
, ncacn_ip_tcp_req
, continue_pipe_connect_ncacn_ip_tcp
, c
);
638 case NCACN_UNIX_STREAM
:
639 ncacn_unix_req
= dcerpc_pipe_connect_ncacn_unix_stream_send(c
, &pc
);
640 composite_continue(c
, ncacn_unix_req
, continue_pipe_connect_ncacn_unix
, c
);
644 pc
.ncalrpc
.dir
= lpcfg_ncalrpc_dir(s
->lp_ctx
);
645 c
->status
= dcerpc_binding_set_string_option(s
->binding
, "ncalrpc_dir",
647 if (!composite_is_ok(c
)) return;
648 ncalrpc_req
= dcerpc_pipe_connect_ncalrpc_send(c
, &pc
);
649 composite_continue(c
, ncalrpc_req
, continue_pipe_connect_ncalrpc
, c
);
653 /* looks like a transport we don't support now */
654 composite_error(c
, NT_STATUS_NOT_SUPPORTED
);
660 Stage 3 of pipe_connect_b: Receive result of pipe connect request on
663 static void continue_pipe_connect_ncacn_np_smb2(struct composite_context
*ctx
)
665 struct composite_context
*c
= talloc_get_type(ctx
->async
.private_data
,
666 struct composite_context
);
667 struct pipe_connect_state
*s
= talloc_get_type(c
->private_data
,
668 struct pipe_connect_state
);
670 c
->status
= dcerpc_pipe_connect_ncacn_np_smb2_recv(ctx
);
671 if (!composite_is_ok(c
)) return;
673 continue_pipe_connect(c
, s
);
678 Stage 3 of pipe_connect_b: Receive result of pipe connect request on
681 static void continue_pipe_connect_ncacn_np_smb(struct composite_context
*ctx
)
683 struct composite_context
*c
= talloc_get_type(ctx
->async
.private_data
,
684 struct composite_context
);
685 struct pipe_connect_state
*s
= talloc_get_type(c
->private_data
,
686 struct pipe_connect_state
);
688 c
->status
= dcerpc_pipe_connect_ncacn_np_smb_recv(ctx
);
689 if (!composite_is_ok(c
)) return;
691 continue_pipe_connect(c
, s
);
696 Stage 3 of pipe_connect_b: Receive result of pipe connect request on tcp/ip
698 static void continue_pipe_connect_ncacn_ip_tcp(struct composite_context
*ctx
)
700 struct composite_context
*c
= talloc_get_type(ctx
->async
.private_data
,
701 struct composite_context
);
702 struct pipe_connect_state
*s
= talloc_get_type(c
->private_data
,
703 struct pipe_connect_state
);
705 c
->status
= dcerpc_pipe_connect_ncacn_ip_tcp_recv(ctx
);
706 if (!composite_is_ok(c
)) return;
708 continue_pipe_connect(c
, s
);
713 Stage 3 of pipe_connect_b: Receive result of pipe connect request on unix socket
715 static void continue_pipe_connect_ncacn_unix(struct composite_context
*ctx
)
717 struct composite_context
*c
= talloc_get_type(ctx
->async
.private_data
,
718 struct composite_context
);
719 struct pipe_connect_state
*s
= talloc_get_type(c
->private_data
,
720 struct pipe_connect_state
);
722 c
->status
= dcerpc_pipe_connect_ncacn_unix_stream_recv(ctx
);
723 if (!composite_is_ok(c
)) return;
725 continue_pipe_connect(c
, s
);
730 Stage 3 of pipe_connect_b: Receive result of pipe connect request on local rpc
732 static void continue_pipe_connect_ncalrpc(struct composite_context
*ctx
)
734 struct composite_context
*c
= talloc_get_type(ctx
->async
.private_data
,
735 struct composite_context
);
736 struct pipe_connect_state
*s
= talloc_get_type(c
->private_data
,
737 struct pipe_connect_state
);
739 c
->status
= dcerpc_pipe_connect_ncalrpc_recv(ctx
);
740 if (!composite_is_ok(c
)) return;
742 continue_pipe_connect(c
, s
);
747 Stage 4 of pipe_connect_b: Start an authentication on connected dcerpc pipe
748 depending on credentials and binding flags passed.
750 static void continue_pipe_connect(struct composite_context
*c
, struct pipe_connect_state
*s
)
752 struct composite_context
*auth_bind_req
;
754 s
->pipe
->binding
= dcerpc_binding_dup(s
->pipe
, s
->binding
);
755 if (composite_nomem(s
->pipe
->binding
, c
)) {
759 auth_bind_req
= dcerpc_pipe_auth_send(s
->pipe
, s
->binding
, s
->table
,
760 s
->credentials
, s
->lp_ctx
);
761 composite_continue(c
, auth_bind_req
, continue_pipe_auth
, c
);
766 Stage 5 of pipe_connect_b: Receive result of pipe authentication request
767 and say if all went ok
769 static void continue_pipe_auth(struct composite_context
*ctx
)
771 struct composite_context
*c
= talloc_get_type(ctx
->async
.private_data
,
772 struct composite_context
);
773 struct pipe_connect_state
*s
= talloc_get_type(c
->private_data
, struct pipe_connect_state
);
775 c
->status
= dcerpc_pipe_auth_recv(ctx
, s
, &s
->pipe
);
776 if (!composite_is_ok(c
)) return;
783 handle timeouts of a dcerpc connect
785 static void dcerpc_connect_timeout_handler(struct tevent_context
*ev
, struct tevent_timer
*te
,
786 struct timeval t
, void *private_data
)
788 struct composite_context
*c
= talloc_get_type_abort(private_data
,
789 struct composite_context
);
790 struct pipe_connect_state
*s
= talloc_get_type_abort(c
->private_data
, struct pipe_connect_state
);
791 if (!s
->pipe
->inhibit_timeout_processing
) {
792 composite_error(c
, NT_STATUS_IO_TIMEOUT
);
794 s
->pipe
->timed_out
= true;
799 start a request to open a rpc connection to a rpc pipe, using
800 specified binding structure to determine the endpoint and options
802 _PUBLIC_
struct composite_context
* dcerpc_pipe_connect_b_send(TALLOC_CTX
*parent_ctx
,
803 const struct dcerpc_binding
*binding
,
804 const struct ndr_interface_table
*table
,
805 struct cli_credentials
*credentials
,
806 struct tevent_context
*ev
,
807 struct loadparm_context
*lp_ctx
)
809 struct composite_context
*c
;
810 struct pipe_connect_state
*s
;
811 enum dcerpc_transport_t transport
;
812 const char *endpoint
= NULL
;
814 /* composite context allocation and setup */
815 c
= composite_create(parent_ctx
, ev
);
820 s
= talloc_zero(c
, struct pipe_connect_state
);
821 if (composite_nomem(s
, c
)) return c
;
824 /* initialise dcerpc pipe structure */
825 s
->pipe
= dcerpc_pipe_init(c
, ev
);
826 if (composite_nomem(s
->pipe
, c
)) return c
;
828 if (DEBUGLEVEL
>= 10)
829 s
->pipe
->conn
->packet_log_dir
= lpcfg_lock_directory(lp_ctx
);
831 /* store parameters in state structure */
832 s
->binding
= dcerpc_binding_dup(s
, binding
);
833 if (composite_nomem(s
->binding
, c
)) return c
;
835 s
->credentials
= credentials
;
838 s
->pipe
->timed_out
= false;
839 s
->pipe
->inhibit_timeout_processing
= false;
841 tevent_add_timer(c
->event_ctx
, c
,
842 timeval_current_ofs(DCERPC_REQUEST_TIMEOUT
, 0),
843 dcerpc_connect_timeout_handler
, c
);
845 transport
= dcerpc_binding_get_transport(s
->binding
);
851 endpoint
= dcerpc_binding_get_string_option(s
->binding
, "endpoint");
857 if (endpoint
== NULL
) {
858 struct composite_context
*binding_req
;
860 binding_req
= dcerpc_epm_map_binding_send(c
, s
->binding
, s
->table
,
861 s
->pipe
->conn
->event_ctx
,
863 composite_continue(c
, binding_req
, continue_map_binding
, c
);
867 continue_connect(c
, s
);
873 receive result of a request to open a rpc connection to a rpc pipe
875 _PUBLIC_ NTSTATUS
dcerpc_pipe_connect_b_recv(struct composite_context
*c
, TALLOC_CTX
*mem_ctx
,
876 struct dcerpc_pipe
**p
)
879 struct pipe_connect_state
*s
;
881 status
= composite_wait(c
);
883 if (NT_STATUS_IS_OK(status
)) {
884 s
= talloc_get_type(c
->private_data
, struct pipe_connect_state
);
885 talloc_steal(mem_ctx
, s
->pipe
);
894 open a rpc connection to a rpc pipe, using the specified
895 binding structure to determine the endpoint and options - sync version
897 _PUBLIC_ NTSTATUS
dcerpc_pipe_connect_b(TALLOC_CTX
*parent_ctx
,
898 struct dcerpc_pipe
**pp
,
899 const struct dcerpc_binding
*binding
,
900 const struct ndr_interface_table
*table
,
901 struct cli_credentials
*credentials
,
902 struct tevent_context
*ev
,
903 struct loadparm_context
*lp_ctx
)
905 struct composite_context
*c
;
907 c
= dcerpc_pipe_connect_b_send(parent_ctx
, binding
, table
,
908 credentials
, ev
, lp_ctx
);
909 return dcerpc_pipe_connect_b_recv(c
, parent_ctx
, pp
);
913 struct pipe_conn_state
{
914 struct dcerpc_pipe
*pipe
;
918 static void continue_pipe_connect_b(struct composite_context
*ctx
);
922 Initiate rpc connection to a rpc pipe, using the specified string
923 binding to determine the endpoint and options.
924 The string is to be parsed to a binding structure first.
926 _PUBLIC_
struct composite_context
* dcerpc_pipe_connect_send(TALLOC_CTX
*parent_ctx
,
928 const struct ndr_interface_table
*table
,
929 struct cli_credentials
*credentials
,
930 struct tevent_context
*ev
, struct loadparm_context
*lp_ctx
)
932 struct composite_context
*c
;
933 struct pipe_conn_state
*s
;
934 struct dcerpc_binding
*b
;
935 struct composite_context
*pipe_conn_req
;
937 /* composite context allocation and setup */
938 c
= composite_create(parent_ctx
, ev
);
943 s
= talloc_zero(c
, struct pipe_conn_state
);
944 if (composite_nomem(s
, c
)) return c
;
947 /* parse binding string to the structure */
948 c
->status
= dcerpc_parse_binding(c
, binding
, &b
);
949 if (!NT_STATUS_IS_OK(c
->status
)) {
950 DEBUG(0, ("Failed to parse dcerpc binding '%s'\n", binding
));
951 composite_error(c
, c
->status
);
955 DEBUG(3, ("Using binding %s\n", dcerpc_binding_string(c
, b
)));
958 start connecting to a rpc pipe after binding structure
961 pipe_conn_req
= dcerpc_pipe_connect_b_send(c
, b
, table
,
962 credentials
, ev
, lp_ctx
);
963 composite_continue(c
, pipe_conn_req
, continue_pipe_connect_b
, c
);
969 Stage 2 of pipe_connect: Receive result of actual pipe connect request
970 and say if we're done ok
972 static void continue_pipe_connect_b(struct composite_context
*ctx
)
974 struct composite_context
*c
= talloc_get_type(ctx
->async
.private_data
,
975 struct composite_context
);
976 struct pipe_conn_state
*s
= talloc_get_type(c
->private_data
,
977 struct pipe_conn_state
);
979 c
->status
= dcerpc_pipe_connect_b_recv(ctx
, c
, &s
->pipe
);
980 talloc_steal(s
, s
->pipe
);
981 if (!composite_is_ok(c
)) return;
988 Receive result of pipe connect (using binding string) request
989 and return connected pipe structure.
991 NTSTATUS
dcerpc_pipe_connect_recv(struct composite_context
*c
,
993 struct dcerpc_pipe
**pp
)
996 struct pipe_conn_state
*s
;
998 status
= composite_wait(c
);
999 if (NT_STATUS_IS_OK(status
)) {
1000 s
= talloc_get_type(c
->private_data
, struct pipe_conn_state
);
1001 *pp
= talloc_steal(mem_ctx
, s
->pipe
);
1009 Open a rpc connection to a rpc pipe, using the specified string
1010 binding to determine the endpoint and options - sync version
1012 _PUBLIC_ NTSTATUS
dcerpc_pipe_connect(TALLOC_CTX
*parent_ctx
,
1013 struct dcerpc_pipe
**pp
,
1014 const char *binding
,
1015 const struct ndr_interface_table
*table
,
1016 struct cli_credentials
*credentials
,
1017 struct tevent_context
*ev
,
1018 struct loadparm_context
*lp_ctx
)
1020 struct composite_context
*c
;
1021 c
= dcerpc_pipe_connect_send(parent_ctx
, binding
,
1022 table
, credentials
, ev
, lp_ctx
);
1023 return dcerpc_pipe_connect_recv(c
, parent_ctx
, pp
);