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 "system/network.h"
29 #include "librpc/gen_ndr/ndr_epmapper.h"
30 #include "librpc/gen_ndr/ndr_dcerpc.h"
31 #include "librpc/gen_ndr/ndr_misc.h"
32 #include "libcli/raw/libcliraw.h"
33 #include "libcli/composite/composite.h"
34 #include "libcli/smb_composite/smb_composite.h"
37 struct dcerpc_pipe_connect;
39 struct pipe_np_smb_state {
40 struct smb_composite_connect conn;
41 struct smbcli_tree *tree;
42 struct dcerpc_pipe_connect io;
47 Stage 3 of ncacn_np_smb: Named pipe opened (?)
49 void continue_pipe_open_smb(struct composite_context *ctx)
51 struct composite_context *c = talloc_get_type(ctx->async.private_data,
52 struct composite_context);
53 struct pipe_np_smb_state *s = talloc_get_type(c->private_data,
54 struct pipe_np_smb_state);
55 /* receive result of named pipe open request */
56 c->status = dcerpc_pipe_open_smb_recv(ctx);
57 if (!NT_STATUS_IS_OK(c->status)) {
58 DEBUG(0,("Failed to open pipe %s - %s\n", s->io.pipe_name, nt_errstr(c->status)));
59 composite_error(c, c->status);
67 Stage 2 of ncacn_np_smb: Open a named pipe after successful smb connection
69 void continue_smb_connect(struct composite_context *ctx)
71 struct composite_context *open_ctx;
72 struct composite_context *c = talloc_get_type(ctx->async.private_data,
73 struct composite_context);
74 struct pipe_np_smb_state *s = talloc_get_type(c->private_data,
75 struct pipe_np_smb_state);
77 /* receive result of smb connect request */
78 c->status = smb_composite_connect_recv(ctx, c);
79 if (!NT_STATUS_IS_OK(c->status)) {
80 DEBUG(0,("Failed to connect to %s - %s\n", s->io.binding->host, nt_errstr(c->status)));
81 composite_error(c, c->status);
85 /* prepare named pipe open parameters */
86 s->tree = s->conn.out.tree;
87 s->io.pipe_name = s->io.binding->endpoint;
89 /* send named pipe open request */
90 open_ctx = dcerpc_pipe_open_smb_send(s->io.pipe->conn, s->tree, s->io.pipe_name);
91 if (open_ctx == NULL) {
92 composite_error(c, NT_STATUS_NO_MEMORY);
96 composite_continue(c, open_ctx, continue_pipe_open_smb, c);
101 Initiate async open of a rpc connection to a rpc pipe on SMB using
102 the binding structure to determine the endpoint and options
104 struct composite_context *dcerpc_pipe_connect_ncacn_np_smb_send(TALLOC_CTX *tmp_ctx,
105 struct dcerpc_pipe_connect *io)
107 struct composite_context *c;
108 struct pipe_np_smb_state *s;
109 struct composite_context *conn_req;
110 struct smb_composite_connect *conn;
112 /* composite context allocation and setup */
113 c = talloc_zero(tmp_ctx, struct composite_context);
114 if (c == NULL) return NULL;
116 s = talloc_zero(c, struct pipe_np_smb_state);
118 composite_error(c, NT_STATUS_NO_MEMORY);
122 c->state = COMPOSITE_STATE_IN_PROGRESS;
124 c->event_ctx = io->pipe->conn->event_ctx;
129 /* prepare smb connection parameters: we're connecting to IPC$ share on
131 conn->in.dest_host = s->io.binding->host;
133 conn->in.called_name = strupper_talloc(tmp_ctx, s->io.binding->host);
134 conn->in.service = "IPC$";
135 conn->in.service_type = NULL;
136 conn->in.fallback_to_anonymous = False;
137 conn->in.workgroup = lp_workgroup();
140 * provide proper credentials - user supplied or anonymous in case this is
141 * schannel connection
143 if (s->io.binding->flags & DCERPC_SCHANNEL) {
144 struct cli_credentials *anon_creds;
146 anon_creds = cli_credentials_init(tmp_ctx);
148 composite_error(c, NT_STATUS_NO_MEMORY);
152 cli_credentials_set_anonymous(anon_creds);
153 cli_credentials_guess(anon_creds);
155 s->conn.in.credentials = anon_creds;
158 s->conn.in.credentials = s->io.creds;
161 /* send smb connect request */
162 conn_req = smb_composite_connect_send(conn, s->io.pipe->conn, s->io.pipe->conn->event_ctx);
164 composite_error(c, NT_STATUS_NO_MEMORY);
168 composite_continue(c, conn_req, continue_smb_connect, c);
176 Receive result of a rpc connection to a rpc pipe on SMB
178 NTSTATUS dcerpc_pipe_connect_ncacn_np_smb_recv(struct composite_context *c)
180 NTSTATUS status = composite_wait(c);
188 Sync version of a rpc connection to a rpc pipe on SMB
190 NTSTATUS dcerpc_pipe_connect_ncacn_np_smb(TALLOC_CTX *tmp_ctx,
191 struct dcerpc_pipe_connect *io)
193 struct composite_context *c;
194 c = dcerpc_pipe_connect_ncacn_np_smb_send(tmp_ctx, io);
195 return dcerpc_pipe_connect_ncacn_np_smb_recv(c);