1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 |
|
---|
4 | DCERPC client side interface structures
|
---|
5 |
|
---|
6 | Copyright (C) Tim Potter 2003
|
---|
7 | Copyright (C) Andrew Tridgell 2003-2005
|
---|
8 |
|
---|
9 | This program is free software; you can redistribute it and/or modify
|
---|
10 | it under the terms of the GNU General Public License as published by
|
---|
11 | the Free Software Foundation; either version 3 of the License, or
|
---|
12 | (at your option) any later version.
|
---|
13 |
|
---|
14 | This program is distributed in the hope that it will be useful,
|
---|
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
17 | GNU General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU General Public License
|
---|
20 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
21 | */
|
---|
22 |
|
---|
23 | /* This is a public header file that is installed as part of Samba.
|
---|
24 | * If you remove any functions or change their signature, update
|
---|
25 | * the so version number. */
|
---|
26 |
|
---|
27 | #ifndef __DCERPC_H__
|
---|
28 | #define __DCERPC_H__
|
---|
29 |
|
---|
30 | #include "../lib/util/data_blob.h"
|
---|
31 | #include "librpc/gen_ndr/dcerpc.h"
|
---|
32 | #include "../librpc/ndr/libndr.h"
|
---|
33 |
|
---|
34 | enum dcerpc_transport_t {
|
---|
35 | NCA_UNKNOWN, NCACN_NP, NCACN_IP_TCP, NCACN_IP_UDP, NCACN_VNS_IPC,
|
---|
36 | NCACN_VNS_SPP, NCACN_AT_DSP, NCADG_AT_DDP, NCALRPC, NCACN_UNIX_STREAM,
|
---|
37 | NCADG_UNIX_DGRAM, NCACN_HTTP, NCADG_IPX, NCACN_SPX };
|
---|
38 |
|
---|
39 | /*
|
---|
40 | this defines a generic security context for signed/sealed dcerpc pipes.
|
---|
41 | */
|
---|
42 | struct dcerpc_connection;
|
---|
43 | struct gensec_settings;
|
---|
44 | struct dcerpc_security {
|
---|
45 | struct dcerpc_auth *auth_info;
|
---|
46 | struct gensec_security *generic_state;
|
---|
47 |
|
---|
48 | /* get the session key */
|
---|
49 | NTSTATUS (*session_key)(struct dcerpc_connection *, DATA_BLOB *);
|
---|
50 | };
|
---|
51 |
|
---|
52 | /*
|
---|
53 | this holds the information that is not specific to a particular rpc context_id
|
---|
54 | */
|
---|
55 | struct dcerpc_connection {
|
---|
56 | uint32_t call_id;
|
---|
57 | uint32_t srv_max_xmit_frag;
|
---|
58 | uint32_t srv_max_recv_frag;
|
---|
59 | uint32_t flags;
|
---|
60 | struct dcerpc_security security_state;
|
---|
61 | const char *binding_string;
|
---|
62 | struct tevent_context *event_ctx;
|
---|
63 | struct smb_iconv_convenience *iconv_convenience;
|
---|
64 |
|
---|
65 | /** Directory in which to save ndrdump-parseable files */
|
---|
66 | const char *packet_log_dir;
|
---|
67 |
|
---|
68 | bool dead;
|
---|
69 | bool free_skipped;
|
---|
70 |
|
---|
71 | struct dcerpc_transport {
|
---|
72 | enum dcerpc_transport_t transport;
|
---|
73 | void *private_data;
|
---|
74 |
|
---|
75 | NTSTATUS (*shutdown_pipe)(struct dcerpc_connection *, NTSTATUS status);
|
---|
76 |
|
---|
77 | const char *(*peer_name)(struct dcerpc_connection *);
|
---|
78 |
|
---|
79 | const char *(*target_hostname)(struct dcerpc_connection *);
|
---|
80 |
|
---|
81 | /* send a request to the server */
|
---|
82 | NTSTATUS (*send_request)(struct dcerpc_connection *, DATA_BLOB *, bool trigger_read);
|
---|
83 |
|
---|
84 | /* send a read request to the server */
|
---|
85 | NTSTATUS (*send_read)(struct dcerpc_connection *);
|
---|
86 |
|
---|
87 | /* a callback to the dcerpc code when a full fragment
|
---|
88 | has been received */
|
---|
89 | void (*recv_data)(struct dcerpc_connection *, DATA_BLOB *, NTSTATUS status);
|
---|
90 | } transport;
|
---|
91 |
|
---|
92 | /* Requests that have been sent, waiting for a reply */
|
---|
93 | struct rpc_request *pending;
|
---|
94 |
|
---|
95 | /* Sync requests waiting to be shipped */
|
---|
96 | struct rpc_request *request_queue;
|
---|
97 |
|
---|
98 | /* the next context_id to be assigned */
|
---|
99 | uint32_t next_context_id;
|
---|
100 | };
|
---|
101 |
|
---|
102 | /*
|
---|
103 | this encapsulates a full dcerpc client side pipe
|
---|
104 | */
|
---|
105 | struct dcerpc_pipe {
|
---|
106 | uint32_t context_id;
|
---|
107 |
|
---|
108 | uint32_t assoc_group_id;
|
---|
109 |
|
---|
110 | struct ndr_syntax_id syntax;
|
---|
111 | struct ndr_syntax_id transfer_syntax;
|
---|
112 |
|
---|
113 | struct dcerpc_connection *conn;
|
---|
114 | struct dcerpc_binding *binding;
|
---|
115 |
|
---|
116 | /** the last fault code from a DCERPC fault */
|
---|
117 | uint32_t last_fault_code;
|
---|
118 |
|
---|
119 | /** timeout for individual rpc requests, in seconds */
|
---|
120 | uint32_t request_timeout;
|
---|
121 | };
|
---|
122 |
|
---|
123 | /* default timeout for all rpc requests, in seconds */
|
---|
124 | #define DCERPC_REQUEST_TIMEOUT 60
|
---|
125 |
|
---|
126 |
|
---|
127 | /* dcerpc pipe flags */
|
---|
128 | #define DCERPC_DEBUG_PRINT_IN (1<<0)
|
---|
129 | #define DCERPC_DEBUG_PRINT_OUT (1<<1)
|
---|
130 | #define DCERPC_DEBUG_PRINT_BOTH (DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT)
|
---|
131 |
|
---|
132 | #define DCERPC_DEBUG_VALIDATE_IN (1<<2)
|
---|
133 | #define DCERPC_DEBUG_VALIDATE_OUT (1<<3)
|
---|
134 | #define DCERPC_DEBUG_VALIDATE_BOTH (DCERPC_DEBUG_VALIDATE_IN | DCERPC_DEBUG_VALIDATE_OUT)
|
---|
135 |
|
---|
136 | #define DCERPC_CONNECT (1<<4)
|
---|
137 | #define DCERPC_SIGN (1<<5)
|
---|
138 | #define DCERPC_SEAL (1<<6)
|
---|
139 |
|
---|
140 | #define DCERPC_PUSH_BIGENDIAN (1<<7)
|
---|
141 | #define DCERPC_PULL_BIGENDIAN (1<<8)
|
---|
142 |
|
---|
143 | #define DCERPC_SCHANNEL (1<<9)
|
---|
144 |
|
---|
145 | #define DCERPC_ANON_FALLBACK (1<<10)
|
---|
146 |
|
---|
147 | /* use a 128 bit session key */
|
---|
148 | #define DCERPC_SCHANNEL_128 (1<<12)
|
---|
149 |
|
---|
150 | /* check incoming pad bytes */
|
---|
151 | #define DCERPC_DEBUG_PAD_CHECK (1<<13)
|
---|
152 |
|
---|
153 | /* set LIBNDR_FLAG_REF_ALLOC flag when decoding NDR */
|
---|
154 | #define DCERPC_NDR_REF_ALLOC (1<<14)
|
---|
155 |
|
---|
156 | #define DCERPC_AUTH_OPTIONS (DCERPC_SEAL|DCERPC_SIGN|DCERPC_SCHANNEL|DCERPC_AUTH_SPNEGO|DCERPC_AUTH_KRB5|DCERPC_AUTH_NTLM)
|
---|
157 |
|
---|
158 | /* select spnego auth */
|
---|
159 | #define DCERPC_AUTH_SPNEGO (1<<15)
|
---|
160 |
|
---|
161 | /* select krb5 auth */
|
---|
162 | #define DCERPC_AUTH_KRB5 (1<<16)
|
---|
163 |
|
---|
164 | #define DCERPC_SMB2 (1<<17)
|
---|
165 |
|
---|
166 | /* select NTLM auth */
|
---|
167 | #define DCERPC_AUTH_NTLM (1<<18)
|
---|
168 |
|
---|
169 | /* this triggers the DCERPC_PFC_FLAG_CONC_MPX flag in the bind request */
|
---|
170 | #define DCERPC_CONCURRENT_MULTIPLEX (1<<19)
|
---|
171 |
|
---|
172 | /* this triggers the DCERPC_PFC_FLAG_SUPPORT_HEADER_SIGN flag in the bind request */
|
---|
173 | #define DCERPC_HEADER_SIGNING (1<<20)
|
---|
174 |
|
---|
175 | /* use NDR64 transport */
|
---|
176 | #define DCERPC_NDR64 (1<<21)
|
---|
177 |
|
---|
178 | /* this describes a binding to a particular transport/pipe */
|
---|
179 | struct dcerpc_binding {
|
---|
180 | enum dcerpc_transport_t transport;
|
---|
181 | struct ndr_syntax_id object;
|
---|
182 | const char *host;
|
---|
183 | const char *target_hostname;
|
---|
184 | const char *endpoint;
|
---|
185 | const char **options;
|
---|
186 | uint32_t flags;
|
---|
187 | uint32_t assoc_group_id;
|
---|
188 | };
|
---|
189 |
|
---|
190 |
|
---|
191 | struct dcerpc_pipe_connect {
|
---|
192 | struct dcerpc_pipe *pipe;
|
---|
193 | struct dcerpc_binding *binding;
|
---|
194 | const char *pipe_name;
|
---|
195 | const struct ndr_interface_table *interface;
|
---|
196 | struct cli_credentials *creds;
|
---|
197 | struct resolve_context *resolve_ctx;
|
---|
198 | };
|
---|
199 |
|
---|
200 |
|
---|
201 | enum rpc_request_state {
|
---|
202 | RPC_REQUEST_QUEUED,
|
---|
203 | RPC_REQUEST_PENDING,
|
---|
204 | RPC_REQUEST_DONE
|
---|
205 | };
|
---|
206 |
|
---|
207 | /*
|
---|
208 | handle for an async dcerpc request
|
---|
209 | */
|
---|
210 | struct rpc_request {
|
---|
211 | struct rpc_request *next, *prev;
|
---|
212 | struct dcerpc_pipe *p;
|
---|
213 | NTSTATUS status;
|
---|
214 | uint32_t call_id;
|
---|
215 | enum rpc_request_state state;
|
---|
216 | DATA_BLOB payload;
|
---|
217 | uint32_t flags;
|
---|
218 | uint32_t fault_code;
|
---|
219 |
|
---|
220 | /* this is used to distinguish bind and alter_context requests
|
---|
221 | from normal requests */
|
---|
222 | void (*recv_handler)(struct rpc_request *conn,
|
---|
223 | DATA_BLOB *blob, struct ncacn_packet *pkt);
|
---|
224 |
|
---|
225 | const struct GUID *object;
|
---|
226 | uint16_t opnum;
|
---|
227 | DATA_BLOB request_data;
|
---|
228 | bool async_call;
|
---|
229 | bool ignore_timeout;
|
---|
230 |
|
---|
231 | /* use by the ndr level async recv call */
|
---|
232 | struct {
|
---|
233 | const struct ndr_interface_table *table;
|
---|
234 | uint32_t opnum;
|
---|
235 | void *struct_ptr;
|
---|
236 | TALLOC_CTX *mem_ctx;
|
---|
237 | } ndr;
|
---|
238 |
|
---|
239 | struct {
|
---|
240 | void (*callback)(struct rpc_request *);
|
---|
241 | void *private_data;
|
---|
242 | } async;
|
---|
243 | };
|
---|
244 |
|
---|
245 | struct epm_tower;
|
---|
246 | struct epm_floor;
|
---|
247 |
|
---|
248 | struct smbcli_tree;
|
---|
249 | struct smb2_tree;
|
---|
250 | struct socket_address;
|
---|
251 |
|
---|
252 | NTSTATUS dcerpc_pipe_connect(TALLOC_CTX *parent_ctx,
|
---|
253 | struct dcerpc_pipe **pp,
|
---|
254 | const char *binding,
|
---|
255 | const struct ndr_interface_table *table,
|
---|
256 | struct cli_credentials *credentials,
|
---|
257 | struct tevent_context *ev,
|
---|
258 | struct loadparm_context *lp_ctx);
|
---|
259 | NTSTATUS dcerpc_ndr_request_recv(struct rpc_request *req);
|
---|
260 | struct rpc_request *dcerpc_ndr_request_send(struct dcerpc_pipe *p,
|
---|
261 | const struct GUID *object,
|
---|
262 | const struct ndr_interface_table *table,
|
---|
263 | uint32_t opnum,
|
---|
264 | bool async,
|
---|
265 | TALLOC_CTX *mem_ctx,
|
---|
266 | void *r);
|
---|
267 | const char *dcerpc_server_name(struct dcerpc_pipe *p);
|
---|
268 | struct dcerpc_pipe *dcerpc_pipe_init(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
|
---|
269 | struct smb_iconv_convenience *ic);
|
---|
270 | NTSTATUS dcerpc_pipe_open_smb(struct dcerpc_pipe *p,
|
---|
271 | struct smbcli_tree *tree,
|
---|
272 | const char *pipe_name);
|
---|
273 | NTSTATUS dcerpc_bind_auth_none(struct dcerpc_pipe *p,
|
---|
274 | const struct ndr_interface_table *table);
|
---|
275 | NTSTATUS dcerpc_fetch_session_key(struct dcerpc_pipe *p,
|
---|
276 | DATA_BLOB *session_key);
|
---|
277 | struct composite_context;
|
---|
278 | NTSTATUS dcerpc_secondary_connection_recv(struct composite_context *c,
|
---|
279 | struct dcerpc_pipe **p2);
|
---|
280 | NTSTATUS dcerpc_parse_binding(TALLOC_CTX *mem_ctx, const char *s, struct dcerpc_binding **b_out);
|
---|
281 |
|
---|
282 | struct composite_context* dcerpc_pipe_connect_b_send(TALLOC_CTX *parent_ctx,
|
---|
283 | struct dcerpc_binding *binding,
|
---|
284 | const struct ndr_interface_table *table,
|
---|
285 | struct cli_credentials *credentials,
|
---|
286 | struct tevent_context *ev,
|
---|
287 | struct loadparm_context *lp_ctx);
|
---|
288 |
|
---|
289 | NTSTATUS dcerpc_pipe_connect_b_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
|
---|
290 | struct dcerpc_pipe **p);
|
---|
291 |
|
---|
292 | NTSTATUS dcerpc_pipe_connect_b(TALLOC_CTX *parent_ctx,
|
---|
293 | struct dcerpc_pipe **pp,
|
---|
294 | struct dcerpc_binding *binding,
|
---|
295 | const struct ndr_interface_table *table,
|
---|
296 | struct cli_credentials *credentials,
|
---|
297 | struct tevent_context *ev,
|
---|
298 | struct loadparm_context *lp_ctx);
|
---|
299 | const char *dcerpc_errstr(TALLOC_CTX *mem_ctx, uint32_t fault_code);
|
---|
300 |
|
---|
301 | NTSTATUS dcerpc_pipe_auth(TALLOC_CTX *mem_ctx,
|
---|
302 | struct dcerpc_pipe **p,
|
---|
303 | struct dcerpc_binding *binding,
|
---|
304 | const struct ndr_interface_table *table,
|
---|
305 | struct cli_credentials *credentials,
|
---|
306 | struct loadparm_context *lp_ctx);
|
---|
307 | char *dcerpc_binding_string(TALLOC_CTX *mem_ctx, const struct dcerpc_binding *b);
|
---|
308 | NTSTATUS dcerpc_secondary_connection(struct dcerpc_pipe *p,
|
---|
309 | struct dcerpc_pipe **p2,
|
---|
310 | struct dcerpc_binding *b);
|
---|
311 | NTSTATUS dcerpc_bind_auth_schannel(TALLOC_CTX *tmp_ctx,
|
---|
312 | struct dcerpc_pipe *p,
|
---|
313 | const struct ndr_interface_table *table,
|
---|
314 | struct cli_credentials *credentials,
|
---|
315 | struct loadparm_context *lp_ctx,
|
---|
316 | uint8_t auth_level);
|
---|
317 | struct tevent_context *dcerpc_event_context(struct dcerpc_pipe *p);
|
---|
318 | NTSTATUS dcerpc_init(struct loadparm_context *lp_ctx);
|
---|
319 | struct smbcli_tree *dcerpc_smb_tree(struct dcerpc_connection *c);
|
---|
320 | uint16_t dcerpc_smb_fnum(struct dcerpc_connection *c);
|
---|
321 | NTSTATUS dcerpc_secondary_context(struct dcerpc_pipe *p,
|
---|
322 | struct dcerpc_pipe **pp2,
|
---|
323 | const struct ndr_interface_table *table);
|
---|
324 | NTSTATUS dcerpc_alter_context(struct dcerpc_pipe *p,
|
---|
325 | TALLOC_CTX *mem_ctx,
|
---|
326 | const struct ndr_syntax_id *syntax,
|
---|
327 | const struct ndr_syntax_id *transfer_syntax);
|
---|
328 |
|
---|
329 | NTSTATUS dcerpc_bind_auth(struct dcerpc_pipe *p,
|
---|
330 | const struct ndr_interface_table *table,
|
---|
331 | struct cli_credentials *credentials,
|
---|
332 | struct gensec_settings *gensec_settings,
|
---|
333 | uint8_t auth_type, uint8_t auth_level,
|
---|
334 | const char *service);
|
---|
335 | struct composite_context* dcerpc_pipe_connect_send(TALLOC_CTX *parent_ctx,
|
---|
336 | const char *binding,
|
---|
337 | const struct ndr_interface_table *table,
|
---|
338 | struct cli_credentials *credentials,
|
---|
339 | struct tevent_context *ev, struct loadparm_context *lp_ctx);
|
---|
340 | NTSTATUS dcerpc_pipe_connect_recv(struct composite_context *c,
|
---|
341 | TALLOC_CTX *mem_ctx,
|
---|
342 | struct dcerpc_pipe **pp);
|
---|
343 |
|
---|
344 | NTSTATUS dcerpc_epm_map_binding(TALLOC_CTX *mem_ctx, struct dcerpc_binding *binding,
|
---|
345 | const struct ndr_interface_table *table, struct tevent_context *ev,
|
---|
346 | struct loadparm_context *lp_ctx);
|
---|
347 | struct composite_context* dcerpc_secondary_auth_connection_send(struct dcerpc_pipe *p,
|
---|
348 | struct dcerpc_binding *binding,
|
---|
349 | const struct ndr_interface_table *table,
|
---|
350 | struct cli_credentials *credentials,
|
---|
351 | struct loadparm_context *lp_ctx);
|
---|
352 | NTSTATUS dcerpc_secondary_auth_connection_recv(struct composite_context *c,
|
---|
353 | TALLOC_CTX *mem_ctx,
|
---|
354 | struct dcerpc_pipe **p);
|
---|
355 |
|
---|
356 | struct composite_context* dcerpc_secondary_connection_send(struct dcerpc_pipe *p,
|
---|
357 | struct dcerpc_binding *b);
|
---|
358 | void dcerpc_log_packet(const char *lockdir,
|
---|
359 | const struct ndr_interface_table *ndr,
|
---|
360 | uint32_t opnum, uint32_t flags,
|
---|
361 | DATA_BLOB *pkt);
|
---|
362 | NTSTATUS dcerpc_binding_build_tower(TALLOC_CTX *mem_ctx,
|
---|
363 | const struct dcerpc_binding *binding,
|
---|
364 | struct epm_tower *tower);
|
---|
365 |
|
---|
366 | NTSTATUS dcerpc_floor_get_lhs_data(const struct epm_floor *epm_floor, struct ndr_syntax_id *syntax);
|
---|
367 |
|
---|
368 | enum dcerpc_transport_t dcerpc_transport_by_tower(const struct epm_tower *tower);
|
---|
369 | const char *derpc_transport_string_by_transport(enum dcerpc_transport_t t);
|
---|
370 |
|
---|
371 | NTSTATUS dcerpc_ndr_request(struct dcerpc_pipe *p,
|
---|
372 | const struct GUID *object,
|
---|
373 | const struct ndr_interface_table *table,
|
---|
374 | uint32_t opnum,
|
---|
375 | TALLOC_CTX *mem_ctx,
|
---|
376 | void *r);
|
---|
377 |
|
---|
378 | NTSTATUS dcerpc_binding_from_tower(TALLOC_CTX *mem_ctx,
|
---|
379 | struct epm_tower *tower,
|
---|
380 | struct dcerpc_binding **b_out);
|
---|
381 |
|
---|
382 | NTSTATUS dcerpc_request(struct dcerpc_pipe *p,
|
---|
383 | struct GUID *object,
|
---|
384 | uint16_t opnum,
|
---|
385 | TALLOC_CTX *mem_ctx,
|
---|
386 | DATA_BLOB *stub_data_in,
|
---|
387 | DATA_BLOB *stub_data_out);
|
---|
388 |
|
---|
389 | typedef NTSTATUS (*dcerpc_call_fn) (struct dcerpc_pipe *, TALLOC_CTX *, void *);
|
---|
390 |
|
---|
391 | enum dcerpc_transport_t dcerpc_transport_by_endpoint_protocol(int prot);
|
---|
392 |
|
---|
393 | const char *dcerpc_floor_get_rhs_data(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor);
|
---|
394 |
|
---|
395 | #endif /* __DCERPC_H__ */
|
---|