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 dcerpc_pipe
*pipe
;
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
.pipe
->conn
);
88 if (!composite_is_ok(c
)) return;
90 /* prepare named pipe open parameters */
91 s
->io
.pipe_name
= s
->io
.binding
->endpoint
;
94 conn
= t
->session
->transport
->conn
;
95 session
= t
->session
->smbXcli
;
97 smb1cli_tcon_set_id(tcon
, t
->tid
);
98 timeout_msec
= t
->session
->transport
->options
.request_timeout
* 1000;
100 /* if we don't have a binding on this pipe yet, then create one */
101 if (s
->io
.pipe
->binding
== NULL
) {
102 const char *r
= smbXcli_conn_remote_name(conn
);
104 SMB_ASSERT(r
!= NULL
);
105 str
= talloc_asprintf(s
, "ncacn_np:%s", r
);
106 if (composite_nomem(str
, c
)) return;
107 c
->status
= dcerpc_parse_binding(s
->io
.pipe
, str
,
108 &s
->io
.pipe
->binding
);
110 if (!composite_is_ok(c
)) return;
113 /* send named pipe open request */
114 open_ctx
= dcerpc_pipe_open_smb_send(s
->io
.pipe
->conn
,
118 if (composite_nomem(open_ctx
, c
)) return;
120 composite_continue(c
, open_ctx
, continue_pipe_open_smb
, c
);
125 Initiate async open of a rpc connection to a rpc pipe on SMB using
126 the binding structure to determine the endpoint and options
128 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
)
130 struct composite_context
*c
;
131 struct pipe_np_smb_state
*s
;
132 struct composite_context
*conn_req
;
133 struct smb_composite_connect
*conn
;
135 /* composite context allocation and setup */
136 c
= composite_create(mem_ctx
, io
->pipe
->conn
->event_ctx
);
137 if (c
== NULL
) return NULL
;
139 s
= talloc_zero(c
, struct pipe_np_smb_state
);
140 if (composite_nomem(s
, c
)) return c
;
146 /* prepare smb connection parameters: we're connecting to IPC$ share on
148 conn
->in
.dest_host
= s
->io
.binding
->host
;
149 conn
->in
.dest_ports
= lpcfg_smb_ports(lp_ctx
);
150 if (s
->io
.binding
->target_hostname
== NULL
)
151 conn
->in
.called_name
= "*SMBSERVER"; /* FIXME: This is invalid */
153 conn
->in
.called_name
= s
->io
.binding
->target_hostname
;
154 conn
->in
.socket_options
= lpcfg_socket_options(lp_ctx
);
155 conn
->in
.service
= "IPC$";
156 conn
->in
.service_type
= NULL
;
157 conn
->in
.workgroup
= lpcfg_workgroup(lp_ctx
);
158 conn
->in
.gensec_settings
= lpcfg_gensec_settings(conn
, lp_ctx
);
160 lpcfg_smbcli_options(lp_ctx
, &conn
->in
.options
);
161 lpcfg_smbcli_session_options(lp_ctx
, &conn
->in
.session_options
);
164 * provide proper credentials - user supplied, but allow a
165 * fallback to anonymous if this is an schannel connection
166 * (might be NT4 not allowing machine logins at session
167 * setup) or if asked to do so by the caller (perhaps a SAMR password change?)
169 s
->conn
.in
.credentials
= s
->io
.creds
;
170 if (s
->io
.binding
->flags
& (DCERPC_SCHANNEL
|DCERPC_ANON_FALLBACK
)) {
171 conn
->in
.fallback_to_anonymous
= true;
173 conn
->in
.fallback_to_anonymous
= false;
176 /* send smb connect request */
177 conn_req
= smb_composite_connect_send(conn
, s
->io
.pipe
->conn
,
179 s
->io
.pipe
->conn
->event_ctx
);
180 if (composite_nomem(conn_req
, c
)) return c
;
182 composite_continue(c
, conn_req
, continue_smb_connect
, c
);
188 Receive result of a rpc connection to a rpc pipe on SMB
190 static NTSTATUS
dcerpc_pipe_connect_ncacn_np_smb_recv(struct composite_context
*c
)
192 NTSTATUS status
= composite_wait(c
);
199 struct pipe_np_smb2_state
{
200 struct dcerpc_pipe_connect io
;
205 Stage 3 of ncacn_np_smb: Named pipe opened (or not)
207 static void continue_pipe_open_smb2(struct composite_context
*ctx
)
209 struct composite_context
*c
= talloc_get_type(ctx
->async
.private_data
,
210 struct composite_context
);
212 /* receive result of named pipe open request on smb2 */
213 c
->status
= dcerpc_pipe_open_smb_recv(ctx
);
214 if (!composite_is_ok(c
)) return;
221 Stage 2 of ncacn_np_smb2: Open a named pipe after successful smb2 connection
223 static void continue_smb2_connect(struct tevent_req
*subreq
)
225 struct composite_context
*open_req
;
226 struct composite_context
*c
=
227 tevent_req_callback_data(subreq
,
228 struct composite_context
);
229 struct pipe_np_smb2_state
*s
= talloc_get_type(c
->private_data
,
230 struct pipe_np_smb2_state
);
232 struct smbXcli_conn
*conn
;
233 struct smbXcli_session
*session
;
234 struct smbXcli_tcon
*tcon
;
235 uint32_t timeout_msec
;
237 /* receive result of smb2 connect request */
238 c
->status
= smb2_connect_recv(subreq
, s
->io
.pipe
->conn
, &t
);
240 if (!composite_is_ok(c
)) return;
242 /* prepare named pipe open parameters */
243 s
->io
.pipe_name
= s
->io
.binding
->endpoint
;
245 conn
= t
->session
->transport
->conn
;
246 session
= t
->session
->smbXcli
;
248 timeout_msec
= t
->session
->transport
->options
.request_timeout
* 1000;
250 /* if we don't have a binding on this pipe yet, then create one */
251 if (s
->io
.pipe
->binding
== NULL
) {
252 const char *r
= smbXcli_conn_remote_name(conn
);
254 SMB_ASSERT(r
!= NULL
);
255 str
= talloc_asprintf(s
, "ncacn_np:%s", r
);
256 if (composite_nomem(str
, c
)) return;
257 c
->status
= dcerpc_parse_binding(s
->io
.pipe
, str
,
258 &s
->io
.pipe
->binding
);
260 if (!composite_is_ok(c
)) return;
263 /* send named pipe open request */
264 open_req
= dcerpc_pipe_open_smb_send(s
->io
.pipe
->conn
,
268 if (composite_nomem(open_req
, c
)) return;
270 composite_continue(c
, open_req
, continue_pipe_open_smb2
, c
);
275 Initiate async open of a rpc connection request on SMB2 using
276 the binding structure to determine the endpoint and options
278 static struct composite_context
*dcerpc_pipe_connect_ncacn_np_smb2_send(
280 struct dcerpc_pipe_connect
*io
,
281 struct loadparm_context
*lp_ctx
)
283 struct composite_context
*c
;
284 struct pipe_np_smb2_state
*s
;
285 struct tevent_req
*subreq
;
286 struct smbcli_options options
;
288 /* composite context allocation and setup */
289 c
= composite_create(mem_ctx
, io
->pipe
->conn
->event_ctx
);
290 if (c
== NULL
) return NULL
;
292 s
= talloc_zero(c
, struct pipe_np_smb2_state
);
293 if (composite_nomem(s
, c
)) return c
;
299 * provide proper credentials - user supplied or anonymous in case this is
300 * schannel connection
302 if (s
->io
.binding
->flags
& DCERPC_SCHANNEL
) {
303 s
->io
.creds
= cli_credentials_init(mem_ctx
);
304 if (composite_nomem(s
->io
.creds
, c
)) return c
;
306 cli_credentials_guess(s
->io
.creds
, lp_ctx
);
309 lpcfg_smbcli_options(lp_ctx
, &options
);
311 /* send smb2 connect request */
312 subreq
= smb2_connect_send(s
, c
->event_ctx
,
314 lpcfg_parm_string_list(mem_ctx
, lp_ctx
, NULL
, "smb2", "ports", NULL
),
318 0, /* previous_session_id */
320 lpcfg_socket_options(lp_ctx
),
321 lpcfg_gensec_settings(mem_ctx
, lp_ctx
));
322 if (composite_nomem(subreq
, c
)) return c
;
323 tevent_req_set_callback(subreq
, continue_smb2_connect
, c
);
329 Receive result of a rpc connection to a rpc pipe on SMB2
331 static NTSTATUS
dcerpc_pipe_connect_ncacn_np_smb2_recv(struct composite_context
*c
)
333 NTSTATUS status
= composite_wait(c
);
340 struct pipe_ip_tcp_state
{
341 struct dcerpc_pipe_connect io
;
342 const char *localaddr
;
344 const char *target_hostname
;
350 Stage 2 of ncacn_ip_tcp: rpc pipe opened (or not)
352 static void continue_pipe_open_ncacn_ip_tcp(struct composite_context
*ctx
)
354 struct composite_context
*c
= talloc_get_type(ctx
->async
.private_data
,
355 struct composite_context
);
357 /* receive result of named pipe open request on tcp/ip */
358 c
->status
= dcerpc_pipe_open_tcp_recv(ctx
);
359 if (!composite_is_ok(c
)) return;
366 Initiate async open of a rpc connection to a rpc pipe on TCP/IP using
367 the binding structure to determine the endpoint and options
369 static struct composite_context
* dcerpc_pipe_connect_ncacn_ip_tcp_send(TALLOC_CTX
*mem_ctx
,
370 struct dcerpc_pipe_connect
*io
)
372 struct composite_context
*c
;
373 struct pipe_ip_tcp_state
*s
;
374 struct composite_context
*pipe_req
;
376 /* composite context allocation and setup */
377 c
= composite_create(mem_ctx
, io
->pipe
->conn
->event_ctx
);
378 if (c
== NULL
) return NULL
;
380 s
= talloc_zero(c
, struct pipe_ip_tcp_state
);
381 if (composite_nomem(s
, c
)) return c
;
384 /* store input parameters in state structure */
386 s
->localaddr
= dcerpc_binding_get_string_option(io
->binding
,
388 if (io
->binding
->host
!= NULL
) {
389 s
->host
= talloc_strdup(s
, io
->binding
->host
);
390 if (composite_nomem(s
->host
, c
)) return c
;
392 if (io
->binding
->target_hostname
!= NULL
) {
393 s
->target_hostname
= talloc_strdup(s
, io
->binding
->target_hostname
);
394 if (composite_nomem(s
->target_hostname
, c
)) return c
;
396 /* port number is a binding endpoint here */
397 s
->port
= atoi(io
->binding
->endpoint
);
399 /* send pipe open request on tcp/ip */
400 pipe_req
= dcerpc_pipe_open_tcp_send(s
->io
.pipe
->conn
, s
->localaddr
, s
->host
, s
->target_hostname
,
401 s
->port
, io
->resolve_ctx
);
402 composite_continue(c
, pipe_req
, continue_pipe_open_ncacn_ip_tcp
, c
);
408 Receive result of a rpc connection to a rpc pipe on TCP/IP
410 static NTSTATUS
dcerpc_pipe_connect_ncacn_ip_tcp_recv(struct composite_context
*c
)
412 NTSTATUS status
= composite_wait(c
);
419 struct pipe_unix_state
{
420 struct dcerpc_pipe_connect io
;
426 Stage 2 of ncacn_unix: rpc pipe opened (or not)
428 static void continue_pipe_open_ncacn_unix_stream(struct composite_context
*ctx
)
430 struct composite_context
*c
= talloc_get_type(ctx
->async
.private_data
,
431 struct composite_context
);
433 /* receive result of pipe open request on unix socket */
434 c
->status
= dcerpc_pipe_open_unix_stream_recv(ctx
);
435 if (!composite_is_ok(c
)) return;
442 Initiate async open of a rpc connection to a rpc pipe on unix socket using
443 the binding structure to determine the endpoint and options
445 static struct composite_context
* dcerpc_pipe_connect_ncacn_unix_stream_send(TALLOC_CTX
*mem_ctx
,
446 struct dcerpc_pipe_connect
*io
)
448 struct composite_context
*c
;
449 struct pipe_unix_state
*s
;
450 struct composite_context
*pipe_req
;
452 /* composite context allocation and setup */
453 c
= composite_create(mem_ctx
, io
->pipe
->conn
->event_ctx
);
454 if (c
== NULL
) return NULL
;
456 s
= talloc_zero(c
, struct pipe_unix_state
);
457 if (composite_nomem(s
, c
)) return c
;
460 /* prepare pipe open parameters and store them in state structure
461 also, verify whether biding endpoint is not null */
464 if (!io
->binding
->endpoint
) {
465 DEBUG(0, ("Path to unix socket not specified\n"));
466 composite_error(c
, NT_STATUS_INVALID_PARAMETER
);
470 s
->path
= talloc_strdup(c
, io
->binding
->endpoint
); /* path is a binding endpoint here */
471 if (composite_nomem(s
->path
, c
)) return c
;
473 /* send pipe open request on unix socket */
474 pipe_req
= dcerpc_pipe_open_unix_stream_send(s
->io
.pipe
->conn
, s
->path
);
475 composite_continue(c
, pipe_req
, continue_pipe_open_ncacn_unix_stream
, c
);
481 Receive result of a rpc connection to a pipe on unix socket
483 static NTSTATUS
dcerpc_pipe_connect_ncacn_unix_stream_recv(struct composite_context
*c
)
485 NTSTATUS status
= composite_wait(c
);
492 struct pipe_ncalrpc_state
{
493 struct dcerpc_pipe_connect io
;
496 static NTSTATUS
dcerpc_pipe_connect_ncalrpc_recv(struct composite_context
*c
);
499 Stage 2 of ncalrpc: rpc pipe opened (or not)
501 static void continue_pipe_open_ncalrpc(struct composite_context
*ctx
)
503 struct composite_context
*c
= talloc_get_type(ctx
->async
.private_data
,
504 struct composite_context
);
506 /* receive result of pipe open request on ncalrpc */
507 c
->status
= dcerpc_pipe_connect_ncalrpc_recv(ctx
);
508 if (!composite_is_ok(c
)) return;
515 Initiate async open of a rpc connection request on NCALRPC using
516 the binding structure to determine the endpoint and options
518 static struct composite_context
* dcerpc_pipe_connect_ncalrpc_send(TALLOC_CTX
*mem_ctx
,
519 struct dcerpc_pipe_connect
*io
, struct loadparm_context
*lp_ctx
)
521 struct composite_context
*c
;
522 struct pipe_ncalrpc_state
*s
;
523 struct composite_context
*pipe_req
;
525 /* composite context allocation and setup */
526 c
= composite_create(mem_ctx
, io
->pipe
->conn
->event_ctx
);
527 if (c
== NULL
) return NULL
;
529 s
= talloc_zero(c
, struct pipe_ncalrpc_state
);
530 if (composite_nomem(s
, c
)) return c
;
533 /* store input parameters in state structure */
536 /* send pipe open request */
537 pipe_req
= dcerpc_pipe_open_pipe_send(s
->io
.pipe
->conn
, lpcfg_ncalrpc_dir(lp_ctx
),
538 s
->io
.binding
->endpoint
);
539 composite_continue(c
, pipe_req
, continue_pipe_open_ncalrpc
, c
);
545 Receive result of a rpc connection to a rpc pipe on NCALRPC
547 static NTSTATUS
dcerpc_pipe_connect_ncalrpc_recv(struct composite_context
*c
)
549 NTSTATUS status
= composite_wait(c
);
556 struct pipe_connect_state
{
557 struct dcerpc_pipe
*pipe
;
558 struct dcerpc_binding
*binding
;
559 const struct ndr_interface_table
*table
;
560 struct cli_credentials
*credentials
;
561 struct loadparm_context
*lp_ctx
;
565 static void continue_map_binding(struct composite_context
*ctx
);
566 static void continue_connect(struct composite_context
*c
, struct pipe_connect_state
*s
);
567 static void continue_pipe_connect_ncacn_np_smb2(struct composite_context
*ctx
);
568 static void continue_pipe_connect_ncacn_np_smb(struct composite_context
*ctx
);
569 static void continue_pipe_connect_ncacn_ip_tcp(struct composite_context
*ctx
);
570 static void continue_pipe_connect_ncacn_unix(struct composite_context
*ctx
);
571 static void continue_pipe_connect_ncalrpc(struct composite_context
*ctx
);
572 static void continue_pipe_connect(struct composite_context
*c
, struct pipe_connect_state
*s
);
573 static void continue_pipe_auth(struct composite_context
*ctx
);
577 Stage 2 of pipe_connect_b: Receive result of endpoint mapping
579 static void continue_map_binding(struct composite_context
*ctx
)
581 struct composite_context
*c
= talloc_get_type(ctx
->async
.private_data
,
582 struct composite_context
);
583 struct pipe_connect_state
*s
= talloc_get_type(c
->private_data
,
584 struct pipe_connect_state
);
586 c
->status
= dcerpc_epm_map_binding_recv(ctx
);
587 if (!composite_is_ok(c
)) return;
589 DEBUG(4,("Mapped to DCERPC endpoint %s\n", s
->binding
->endpoint
));
591 continue_connect(c
, s
);
596 Stage 2 of pipe_connect_b: Continue connection after endpoint is known
598 static void continue_connect(struct composite_context
*c
, struct pipe_connect_state
*s
)
600 struct dcerpc_pipe_connect pc
;
602 /* potential exits to another stage by sending an async request */
603 struct composite_context
*ncacn_np_smb2_req
;
604 struct composite_context
*ncacn_np_smb_req
;
605 struct composite_context
*ncacn_ip_tcp_req
;
606 struct composite_context
*ncacn_unix_req
;
607 struct composite_context
*ncalrpc_req
;
608 enum dcerpc_transport_t transport
;
611 /* dcerpc pipe connect input parameters */
613 pc
.binding
= s
->binding
;
615 pc
.interface
= s
->table
;
616 pc
.creds
= s
->credentials
;
617 pc
.resolve_ctx
= lpcfg_resolve_context(s
->lp_ctx
);
619 transport
= dcerpc_binding_get_transport(s
->binding
);
620 flags
= dcerpc_binding_get_flags(s
->binding
);
622 /* connect dcerpc pipe depending on required transport */
625 if (flags
& DCERPC_SMB2
) {
626 /* new varient of SMB a.k.a. SMB2 */
627 ncacn_np_smb2_req
= dcerpc_pipe_connect_ncacn_np_smb2_send(c
, &pc
, s
->lp_ctx
);
628 composite_continue(c
, ncacn_np_smb2_req
, continue_pipe_connect_ncacn_np_smb2
, c
);
632 /* good old ordinary SMB */
633 ncacn_np_smb_req
= dcerpc_pipe_connect_ncacn_np_smb_send(c
, &pc
, s
->lp_ctx
);
634 composite_continue(c
, ncacn_np_smb_req
, continue_pipe_connect_ncacn_np_smb
, c
);
640 ncacn_ip_tcp_req
= dcerpc_pipe_connect_ncacn_ip_tcp_send(c
, &pc
);
641 composite_continue(c
, ncacn_ip_tcp_req
, continue_pipe_connect_ncacn_ip_tcp
, c
);
644 case NCACN_UNIX_STREAM
:
645 ncacn_unix_req
= dcerpc_pipe_connect_ncacn_unix_stream_send(c
, &pc
);
646 composite_continue(c
, ncacn_unix_req
, continue_pipe_connect_ncacn_unix
, c
);
650 ncalrpc_req
= dcerpc_pipe_connect_ncalrpc_send(c
, &pc
, s
->lp_ctx
);
651 composite_continue(c
, ncalrpc_req
, continue_pipe_connect_ncalrpc
, c
);
655 /* looks like a transport we don't support now */
656 composite_error(c
, NT_STATUS_NOT_SUPPORTED
);
662 Stage 3 of pipe_connect_b: Receive result of pipe connect request on
665 static void continue_pipe_connect_ncacn_np_smb2(struct composite_context
*ctx
)
667 struct composite_context
*c
= talloc_get_type(ctx
->async
.private_data
,
668 struct composite_context
);
669 struct pipe_connect_state
*s
= talloc_get_type(c
->private_data
,
670 struct pipe_connect_state
);
672 c
->status
= dcerpc_pipe_connect_ncacn_np_smb2_recv(ctx
);
673 if (!composite_is_ok(c
)) return;
675 continue_pipe_connect(c
, s
);
680 Stage 3 of pipe_connect_b: Receive result of pipe connect request on
683 static void continue_pipe_connect_ncacn_np_smb(struct composite_context
*ctx
)
685 struct composite_context
*c
= talloc_get_type(ctx
->async
.private_data
,
686 struct composite_context
);
687 struct pipe_connect_state
*s
= talloc_get_type(c
->private_data
,
688 struct pipe_connect_state
);
690 c
->status
= dcerpc_pipe_connect_ncacn_np_smb_recv(ctx
);
691 if (!composite_is_ok(c
)) return;
693 continue_pipe_connect(c
, s
);
698 Stage 3 of pipe_connect_b: Receive result of pipe connect request on tcp/ip
700 static void continue_pipe_connect_ncacn_ip_tcp(struct composite_context
*ctx
)
702 struct composite_context
*c
= talloc_get_type(ctx
->async
.private_data
,
703 struct composite_context
);
704 struct pipe_connect_state
*s
= talloc_get_type(c
->private_data
,
705 struct pipe_connect_state
);
707 c
->status
= dcerpc_pipe_connect_ncacn_ip_tcp_recv(ctx
);
708 if (!composite_is_ok(c
)) return;
710 continue_pipe_connect(c
, s
);
715 Stage 3 of pipe_connect_b: Receive result of pipe connect request on unix socket
717 static void continue_pipe_connect_ncacn_unix(struct composite_context
*ctx
)
719 struct composite_context
*c
= talloc_get_type(ctx
->async
.private_data
,
720 struct composite_context
);
721 struct pipe_connect_state
*s
= talloc_get_type(c
->private_data
,
722 struct pipe_connect_state
);
724 c
->status
= dcerpc_pipe_connect_ncacn_unix_stream_recv(ctx
);
725 if (!composite_is_ok(c
)) return;
727 continue_pipe_connect(c
, s
);
732 Stage 3 of pipe_connect_b: Receive result of pipe connect request on local rpc
734 static void continue_pipe_connect_ncalrpc(struct composite_context
*ctx
)
736 struct composite_context
*c
= talloc_get_type(ctx
->async
.private_data
,
737 struct composite_context
);
738 struct pipe_connect_state
*s
= talloc_get_type(c
->private_data
,
739 struct pipe_connect_state
);
741 c
->status
= dcerpc_pipe_connect_ncalrpc_recv(ctx
);
742 if (!composite_is_ok(c
)) return;
744 continue_pipe_connect(c
, s
);
749 Stage 4 of pipe_connect_b: Start an authentication on connected dcerpc pipe
750 depending on credentials and binding flags passed.
752 static void continue_pipe_connect(struct composite_context
*c
, struct pipe_connect_state
*s
)
754 struct composite_context
*auth_bind_req
;
756 s
->pipe
->binding
= dcerpc_binding_dup(s
->pipe
, s
->binding
);
757 if (composite_nomem(s
->pipe
->binding
, c
)) {
761 auth_bind_req
= dcerpc_pipe_auth_send(s
->pipe
, s
->binding
, s
->table
,
762 s
->credentials
, s
->lp_ctx
);
763 composite_continue(c
, auth_bind_req
, continue_pipe_auth
, c
);
768 Stage 5 of pipe_connect_b: Receive result of pipe authentication request
769 and say if all went ok
771 static void continue_pipe_auth(struct composite_context
*ctx
)
773 struct composite_context
*c
= talloc_get_type(ctx
->async
.private_data
,
774 struct composite_context
);
775 struct pipe_connect_state
*s
= talloc_get_type(c
->private_data
, struct pipe_connect_state
);
777 c
->status
= dcerpc_pipe_auth_recv(ctx
, s
, &s
->pipe
);
778 if (!composite_is_ok(c
)) return;
785 handle timeouts of a dcerpc connect
787 static void dcerpc_connect_timeout_handler(struct tevent_context
*ev
, struct tevent_timer
*te
,
788 struct timeval t
, void *private_data
)
790 struct composite_context
*c
= talloc_get_type_abort(private_data
,
791 struct composite_context
);
792 struct pipe_connect_state
*s
= talloc_get_type_abort(c
->private_data
, struct pipe_connect_state
);
793 if (!s
->pipe
->inhibit_timeout_processing
) {
794 composite_error(c
, NT_STATUS_IO_TIMEOUT
);
796 s
->pipe
->timed_out
= true;
801 start a request to open a rpc connection to a rpc pipe, using
802 specified binding structure to determine the endpoint and options
804 _PUBLIC_
struct composite_context
* dcerpc_pipe_connect_b_send(TALLOC_CTX
*parent_ctx
,
805 const struct dcerpc_binding
*binding
,
806 const struct ndr_interface_table
*table
,
807 struct cli_credentials
*credentials
,
808 struct tevent_context
*ev
,
809 struct loadparm_context
*lp_ctx
)
811 struct composite_context
*c
;
812 struct pipe_connect_state
*s
;
813 enum dcerpc_transport_t transport
;
814 const char *endpoint
= NULL
;
816 /* composite context allocation and setup */
817 c
= composite_create(parent_ctx
, ev
);
822 s
= talloc_zero(c
, struct pipe_connect_state
);
823 if (composite_nomem(s
, c
)) return c
;
826 /* initialise dcerpc pipe structure */
827 s
->pipe
= dcerpc_pipe_init(c
, ev
);
828 if (composite_nomem(s
->pipe
, c
)) return c
;
830 if (DEBUGLEVEL
>= 10)
831 s
->pipe
->conn
->packet_log_dir
= lpcfg_lock_directory(lp_ctx
);
833 /* store parameters in state structure */
834 s
->binding
= dcerpc_binding_dup(s
, binding
);
835 if (composite_nomem(s
->binding
, c
)) return c
;
837 s
->credentials
= credentials
;
840 s
->pipe
->timed_out
= false;
841 s
->pipe
->inhibit_timeout_processing
= false;
843 tevent_add_timer(c
->event_ctx
, c
,
844 timeval_current_ofs(DCERPC_REQUEST_TIMEOUT
, 0),
845 dcerpc_connect_timeout_handler
, c
);
847 transport
= dcerpc_binding_get_transport(s
->binding
);
853 endpoint
= dcerpc_binding_get_string_option(s
->binding
, "endpoint");
859 if (endpoint
== NULL
) {
860 struct composite_context
*binding_req
;
862 binding_req
= dcerpc_epm_map_binding_send(c
, s
->binding
, s
->table
,
863 s
->pipe
->conn
->event_ctx
,
865 composite_continue(c
, binding_req
, continue_map_binding
, c
);
869 continue_connect(c
, s
);
875 receive result of a request to open a rpc connection to a rpc pipe
877 _PUBLIC_ NTSTATUS
dcerpc_pipe_connect_b_recv(struct composite_context
*c
, TALLOC_CTX
*mem_ctx
,
878 struct dcerpc_pipe
**p
)
881 struct pipe_connect_state
*s
;
883 status
= composite_wait(c
);
885 if (NT_STATUS_IS_OK(status
)) {
886 s
= talloc_get_type(c
->private_data
, struct pipe_connect_state
);
887 talloc_steal(mem_ctx
, s
->pipe
);
896 open a rpc connection to a rpc pipe, using the specified
897 binding structure to determine the endpoint and options - sync version
899 _PUBLIC_ NTSTATUS
dcerpc_pipe_connect_b(TALLOC_CTX
*parent_ctx
,
900 struct dcerpc_pipe
**pp
,
901 const struct dcerpc_binding
*binding
,
902 const struct ndr_interface_table
*table
,
903 struct cli_credentials
*credentials
,
904 struct tevent_context
*ev
,
905 struct loadparm_context
*lp_ctx
)
907 struct composite_context
*c
;
909 c
= dcerpc_pipe_connect_b_send(parent_ctx
, binding
, table
,
910 credentials
, ev
, lp_ctx
);
911 return dcerpc_pipe_connect_b_recv(c
, parent_ctx
, pp
);
915 struct pipe_conn_state
{
916 struct dcerpc_pipe
*pipe
;
920 static void continue_pipe_connect_b(struct composite_context
*ctx
);
924 Initiate rpc connection to a rpc pipe, using the specified string
925 binding to determine the endpoint and options.
926 The string is to be parsed to a binding structure first.
928 _PUBLIC_
struct composite_context
* dcerpc_pipe_connect_send(TALLOC_CTX
*parent_ctx
,
930 const struct ndr_interface_table
*table
,
931 struct cli_credentials
*credentials
,
932 struct tevent_context
*ev
, struct loadparm_context
*lp_ctx
)
934 struct composite_context
*c
;
935 struct pipe_conn_state
*s
;
936 struct dcerpc_binding
*b
;
937 struct composite_context
*pipe_conn_req
;
939 /* composite context allocation and setup */
940 c
= composite_create(parent_ctx
, ev
);
945 s
= talloc_zero(c
, struct pipe_conn_state
);
946 if (composite_nomem(s
, c
)) return c
;
949 /* parse binding string to the structure */
950 c
->status
= dcerpc_parse_binding(c
, binding
, &b
);
951 if (!NT_STATUS_IS_OK(c
->status
)) {
952 DEBUG(0, ("Failed to parse dcerpc binding '%s'\n", binding
));
953 composite_error(c
, c
->status
);
957 DEBUG(3, ("Using binding %s\n", dcerpc_binding_string(c
, b
)));
960 start connecting to a rpc pipe after binding structure
963 pipe_conn_req
= dcerpc_pipe_connect_b_send(c
, b
, table
,
964 credentials
, ev
, lp_ctx
);
965 composite_continue(c
, pipe_conn_req
, continue_pipe_connect_b
, c
);
971 Stage 2 of pipe_connect: Receive result of actual pipe connect request
972 and say if we're done ok
974 static void continue_pipe_connect_b(struct composite_context
*ctx
)
976 struct composite_context
*c
= talloc_get_type(ctx
->async
.private_data
,
977 struct composite_context
);
978 struct pipe_conn_state
*s
= talloc_get_type(c
->private_data
,
979 struct pipe_conn_state
);
981 c
->status
= dcerpc_pipe_connect_b_recv(ctx
, c
, &s
->pipe
);
982 talloc_steal(s
, s
->pipe
);
983 if (!composite_is_ok(c
)) return;
990 Receive result of pipe connect (using binding string) request
991 and return connected pipe structure.
993 NTSTATUS
dcerpc_pipe_connect_recv(struct composite_context
*c
,
995 struct dcerpc_pipe
**pp
)
998 struct pipe_conn_state
*s
;
1000 status
= composite_wait(c
);
1001 if (NT_STATUS_IS_OK(status
)) {
1002 s
= talloc_get_type(c
->private_data
, struct pipe_conn_state
);
1003 *pp
= talloc_steal(mem_ctx
, s
->pipe
);
1011 Open a rpc connection to a rpc pipe, using the specified string
1012 binding to determine the endpoint and options - sync version
1014 _PUBLIC_ NTSTATUS
dcerpc_pipe_connect(TALLOC_CTX
*parent_ctx
,
1015 struct dcerpc_pipe
**pp
,
1016 const char *binding
,
1017 const struct ndr_interface_table
*table
,
1018 struct cli_credentials
*credentials
,
1019 struct tevent_context
*ev
,
1020 struct loadparm_context
*lp_ctx
)
1022 struct composite_context
*c
;
1023 c
= dcerpc_pipe_connect_send(parent_ctx
, binding
,
1024 table
, credentials
, ev
, lp_ctx
);
1025 return dcerpc_pipe_connect_recv(c
, parent_ctx
, pp
);