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;
46 void continue_pipe_open_smb(struct composite_context *ctx)
48 struct composite_context *c = talloc_get_type(ctx->async.private_data,
49 struct composite_context);
50 struct pipe_np_smb_state *s = talloc_get_type(c->private_data,
51 struct pipe_np_smb_state);
53 c->status = dcerpc_pipe_open_smb_recv(ctx);
54 if (!NT_STATUS_IS_OK(c->status)) {
56 DEBUG(0,("Failed to open pipe %s - %s\n", s->io.pipe_name, nt_errstr(c->status)));
57 composite_error(c, c->status);
65 void continue_smb_connect(struct composite_context *ctx)
67 struct composite_context *open_ctx;
68 struct composite_context *c = talloc_get_type(ctx->async.private_data,
69 struct composite_context);
70 struct pipe_np_smb_state *s = talloc_get_type(c->private_data,
71 struct pipe_np_smb_state);
73 c->status = smb_composite_connect_recv(ctx, c);
74 if (!NT_STATUS_IS_OK(c->status)) {
76 DEBUG(0,("Failed to connect to %s - %s\n", s->io.binding->host, nt_errstr(c->status)));
77 composite_error(c, c->status);
81 s->tree = s->conn.out.tree;
82 s->io.pipe_name = s->io.binding->endpoint;
84 open_ctx = dcerpc_pipe_open_smb_send(s->io.pipe->conn, s->tree, s->io.pipe_name);
85 if (open_ctx == NULL) {
86 composite_error(c, NT_STATUS_NO_MEMORY);
90 composite_continue(c, open_ctx, continue_pipe_open_smb, c);
94 /* open a rpc connection to a rpc pipe on SMB using the binding
95 structure to determine the endpoint and options */
96 struct composite_context *dcerpc_pipe_connect_ncacn_np_smb_send(TALLOC_CTX *tmp_ctx,
97 struct dcerpc_pipe_connect *io)
99 struct composite_context *c;
100 struct pipe_np_smb_state *s;
101 struct composite_context *conn_req;
102 struct smb_composite_connect *conn;
104 c = talloc_zero(tmp_ctx, struct composite_context);
105 if (c == NULL) return NULL;
107 s = talloc_zero(c, struct pipe_np_smb_state);
109 composite_error(c, NT_STATUS_NO_MEMORY);
113 c->state = COMPOSITE_STATE_IN_PROGRESS;
115 c->event_ctx = io->pipe->conn->event_ctx;
120 conn->in.dest_host = s->io.binding->host;
122 conn->in.called_name = strupper_talloc(tmp_ctx, s->io.binding->host);
123 conn->in.service = "IPC$";
124 conn->in.service_type = NULL;
125 conn->in.fallback_to_anonymous = False;
126 conn->in.workgroup = lp_workgroup();
128 if (s->io.binding->flags & DCERPC_SCHANNEL) {
129 struct cli_credentials *anon_creds;
131 anon_creds = cli_credentials_init(tmp_ctx);
133 composite_error(c, NT_STATUS_NO_MEMORY);
137 cli_credentials_set_anonymous(anon_creds);
138 cli_credentials_guess(anon_creds);
140 s->conn.in.credentials = anon_creds;
143 s->conn.in.credentials = s->io.creds;
146 conn_req = smb_composite_connect_send(conn, s->io.pipe->conn, s->io.pipe->conn->event_ctx);
148 composite_error(c, NT_STATUS_NO_MEMORY);
152 composite_continue(c, conn_req, continue_smb_connect, c);
159 NTSTATUS dcerpc_pipe_connect_ncacn_np_smb_recv(struct composite_context *c)
161 NTSTATUS status = composite_wait(c);
168 NTSTATUS dcerpc_pipe_connect_ncacn_np_smb(TALLOC_CTX *tmp_ctx,
169 struct dcerpc_pipe_connect *io)
171 struct composite_context *c;
172 c = dcerpc_pipe_connect_ncacn_np_smb_send(tmp_ctx, io);
173 return dcerpc_pipe_connect_ncacn_np_smb_recv(c);