2 Unix SMB/CIFS implementation.
4 DCERPC client side interface structures
6 Copyright (C) Tim Potter 2003
7 Copyright (C) Andrew Tridgell 2003-2005
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.
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.
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/>.
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. */
30 #include "../lib/util/data_blob.h"
31 #include "librpc/gen_ndr/dcerpc.h"
32 #include "../librpc/ndr/libndr.h"
34 struct tevent_context;
36 struct dcerpc_binding_handle;
37 struct tstream_context;
39 enum dcerpc_transport_t {
40 NCA_UNKNOWN, NCACN_NP, NCACN_IP_TCP, NCACN_IP_UDP, NCACN_VNS_IPC,
41 NCACN_VNS_SPP, NCACN_AT_DSP, NCADG_AT_DDP, NCALRPC, NCACN_UNIX_STREAM,
42 NCADG_UNIX_DGRAM, NCACN_HTTP, NCADG_IPX, NCACN_SPX, NCACN_INTERNAL };
45 this defines a generic security context for signed/sealed dcerpc pipes.
47 struct dcerpc_connection;
48 struct gensec_settings;
49 struct dcerpc_security {
50 struct dcerpc_auth *auth_info;
51 struct gensec_security *generic_state;
53 /* get the session key */
54 NTSTATUS (*session_key)(struct dcerpc_connection *, DATA_BLOB *);
58 this holds the information that is not specific to a particular rpc context_id
60 struct dcerpc_connection {
62 uint32_t srv_max_xmit_frag;
63 uint32_t srv_max_recv_frag;
65 struct dcerpc_security security_state;
66 const char *binding_string;
67 struct tevent_context *event_ctx;
69 /** Directory in which to save ndrdump-parseable files */
70 const char *packet_log_dir;
75 struct dcerpc_transport {
76 enum dcerpc_transport_t transport;
79 NTSTATUS (*shutdown_pipe)(struct dcerpc_connection *, NTSTATUS status);
81 const char *(*peer_name)(struct dcerpc_connection *);
83 const char *(*target_hostname)(struct dcerpc_connection *);
85 /* send a request to the server */
86 NTSTATUS (*send_request)(struct dcerpc_connection *, DATA_BLOB *, bool trigger_read);
88 /* send a read request to the server */
89 NTSTATUS (*send_read)(struct dcerpc_connection *);
91 /* a callback to the dcerpc code when a full fragment
93 void (*recv_data)(struct dcerpc_connection *, DATA_BLOB *, NTSTATUS status);
96 /* Requests that have been sent, waiting for a reply */
97 struct rpc_request *pending;
99 /* Sync requests waiting to be shipped */
100 struct rpc_request *request_queue;
102 /* the next context_id to be assigned */
103 uint32_t next_context_id;
107 this encapsulates a full dcerpc client side pipe
110 struct dcerpc_binding_handle *binding_handle;
114 uint32_t assoc_group_id;
116 struct ndr_syntax_id syntax;
117 struct ndr_syntax_id transfer_syntax;
119 struct dcerpc_connection *conn;
120 struct dcerpc_binding *binding;
122 /** the last fault code from a DCERPC fault */
123 uint32_t last_fault_code;
125 /** timeout for individual rpc requests, in seconds */
126 uint32_t request_timeout;
129 /* default timeout for all rpc requests, in seconds */
130 #define DCERPC_REQUEST_TIMEOUT 60
133 /* dcerpc pipe flags */
134 #define DCERPC_DEBUG_PRINT_IN (1<<0)
135 #define DCERPC_DEBUG_PRINT_OUT (1<<1)
136 #define DCERPC_DEBUG_PRINT_BOTH (DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT)
138 #define DCERPC_DEBUG_VALIDATE_IN (1<<2)
139 #define DCERPC_DEBUG_VALIDATE_OUT (1<<3)
140 #define DCERPC_DEBUG_VALIDATE_BOTH (DCERPC_DEBUG_VALIDATE_IN | DCERPC_DEBUG_VALIDATE_OUT)
142 #define DCERPC_CONNECT (1<<4)
143 #define DCERPC_SIGN (1<<5)
144 #define DCERPC_SEAL (1<<6)
146 #define DCERPC_PUSH_BIGENDIAN (1<<7)
147 #define DCERPC_PULL_BIGENDIAN (1<<8)
149 #define DCERPC_SCHANNEL (1<<9)
151 #define DCERPC_ANON_FALLBACK (1<<10)
153 /* use a 128 bit session key */
154 #define DCERPC_SCHANNEL_128 (1<<12)
156 /* check incoming pad bytes */
157 #define DCERPC_DEBUG_PAD_CHECK (1<<13)
159 /* set LIBNDR_FLAG_REF_ALLOC flag when decoding NDR */
160 #define DCERPC_NDR_REF_ALLOC (1<<14)
162 #define DCERPC_AUTH_OPTIONS (DCERPC_SEAL|DCERPC_SIGN|DCERPC_SCHANNEL|DCERPC_AUTH_SPNEGO|DCERPC_AUTH_KRB5|DCERPC_AUTH_NTLM)
164 /* select spnego auth */
165 #define DCERPC_AUTH_SPNEGO (1<<15)
167 /* select krb5 auth */
168 #define DCERPC_AUTH_KRB5 (1<<16)
170 #define DCERPC_SMB2 (1<<17)
172 /* select NTLM auth */
173 #define DCERPC_AUTH_NTLM (1<<18)
175 /* this triggers the DCERPC_PFC_FLAG_CONC_MPX flag in the bind request */
176 #define DCERPC_CONCURRENT_MULTIPLEX (1<<19)
178 /* this triggers the DCERPC_PFC_FLAG_SUPPORT_HEADER_SIGN flag in the bind request */
179 #define DCERPC_HEADER_SIGNING (1<<20)
181 /* use NDR64 transport */
182 #define DCERPC_NDR64 (1<<21)
184 /* specify binding interface */
185 #define DCERPC_LOCALADDRESS (1<<22)
187 /* this describes a binding to a particular transport/pipe */
188 struct dcerpc_binding {
189 enum dcerpc_transport_t transport;
190 struct ndr_syntax_id object;
192 const char *target_hostname;
193 const char *target_principal;
194 const char *endpoint;
195 const char **options;
196 const char *localaddress;
198 uint32_t assoc_group_id;
202 struct dcerpc_pipe_connect {
203 struct dcerpc_pipe *pipe;
204 struct dcerpc_binding *binding;
205 const char *pipe_name;
206 const struct ndr_interface_table *interface;
207 struct cli_credentials *creds;
208 struct resolve_context *resolve_ctx;
212 enum rpc_request_state {
219 handle for an async dcerpc request
222 struct rpc_request *next, *prev;
223 struct dcerpc_pipe *p;
226 enum rpc_request_state state;
231 /* this is used to distinguish bind and alter_context requests
232 from normal requests */
233 void (*recv_handler)(struct rpc_request *conn,
234 DATA_BLOB *blob, struct ncacn_packet *pkt);
236 const struct GUID *object;
238 DATA_BLOB request_data;
241 /* use by the ndr level async recv call */
243 const struct ndr_interface_table *table;
250 void (*callback)(struct rpc_request *);
260 struct socket_address;
262 NTSTATUS dcerpc_pipe_connect(TALLOC_CTX *parent_ctx,
263 struct dcerpc_pipe **pp,
265 const struct ndr_interface_table *table,
266 struct cli_credentials *credentials,
267 struct tevent_context *ev,
268 struct loadparm_context *lp_ctx);
269 NTSTATUS dcerpc_ndr_request_recv(struct rpc_request *req);
270 struct rpc_request *dcerpc_ndr_request_send(struct dcerpc_pipe *p,
271 const struct GUID *object,
272 const struct ndr_interface_table *table,
277 const char *dcerpc_server_name(struct dcerpc_pipe *p);
278 struct dcerpc_pipe *dcerpc_pipe_init(TALLOC_CTX *mem_ctx, struct tevent_context *ev);
279 NTSTATUS dcerpc_pipe_open_smb(struct dcerpc_pipe *p,
280 struct smbcli_tree *tree,
281 const char *pipe_name);
282 NTSTATUS dcerpc_bind_auth_none(struct dcerpc_pipe *p,
283 const struct ndr_interface_table *table);
284 NTSTATUS dcerpc_fetch_session_key(struct dcerpc_pipe *p,
285 DATA_BLOB *session_key);
286 struct composite_context;
287 NTSTATUS dcerpc_secondary_connection_recv(struct composite_context *c,
288 struct dcerpc_pipe **p2);
289 NTSTATUS dcerpc_parse_binding(TALLOC_CTX *mem_ctx, const char *s, struct dcerpc_binding **b_out);
291 struct composite_context* dcerpc_pipe_connect_b_send(TALLOC_CTX *parent_ctx,
292 struct dcerpc_binding *binding,
293 const struct ndr_interface_table *table,
294 struct cli_credentials *credentials,
295 struct tevent_context *ev,
296 struct loadparm_context *lp_ctx);
298 NTSTATUS dcerpc_pipe_connect_b_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
299 struct dcerpc_pipe **p);
301 NTSTATUS dcerpc_pipe_connect_b(TALLOC_CTX *parent_ctx,
302 struct dcerpc_pipe **pp,
303 struct dcerpc_binding *binding,
304 const struct ndr_interface_table *table,
305 struct cli_credentials *credentials,
306 struct tevent_context *ev,
307 struct loadparm_context *lp_ctx);
308 const char *dcerpc_errstr(TALLOC_CTX *mem_ctx, uint32_t fault_code);
309 NTSTATUS dcerpc_fault_to_nt_status(uint32_t fault_code);
311 NTSTATUS dcerpc_pipe_auth(TALLOC_CTX *mem_ctx,
312 struct dcerpc_pipe **p,
313 struct dcerpc_binding *binding,
314 const struct ndr_interface_table *table,
315 struct cli_credentials *credentials,
316 struct loadparm_context *lp_ctx);
317 char *dcerpc_binding_string(TALLOC_CTX *mem_ctx, const struct dcerpc_binding *b);
318 NTSTATUS dcerpc_secondary_connection(struct dcerpc_pipe *p,
319 struct dcerpc_pipe **p2,
320 struct dcerpc_binding *b);
321 NTSTATUS dcerpc_bind_auth_schannel(TALLOC_CTX *tmp_ctx,
322 struct dcerpc_pipe *p,
323 const struct ndr_interface_table *table,
324 struct cli_credentials *credentials,
325 struct loadparm_context *lp_ctx,
327 struct tevent_context *dcerpc_event_context(struct dcerpc_pipe *p);
328 NTSTATUS dcerpc_init(struct loadparm_context *lp_ctx);
329 struct smbcli_tree *dcerpc_smb_tree(struct dcerpc_connection *c);
330 uint16_t dcerpc_smb_fnum(struct dcerpc_connection *c);
331 NTSTATUS dcerpc_secondary_context(struct dcerpc_pipe *p,
332 struct dcerpc_pipe **pp2,
333 const struct ndr_interface_table *table);
334 NTSTATUS dcerpc_alter_context(struct dcerpc_pipe *p,
336 const struct ndr_syntax_id *syntax,
337 const struct ndr_syntax_id *transfer_syntax);
339 NTSTATUS dcerpc_bind_auth(struct dcerpc_pipe *p,
340 const struct ndr_interface_table *table,
341 struct cli_credentials *credentials,
342 struct gensec_settings *gensec_settings,
343 uint8_t auth_type, uint8_t auth_level,
344 const char *service);
345 struct composite_context* dcerpc_pipe_connect_send(TALLOC_CTX *parent_ctx,
347 const struct ndr_interface_table *table,
348 struct cli_credentials *credentials,
349 struct tevent_context *ev, struct loadparm_context *lp_ctx);
350 NTSTATUS dcerpc_pipe_connect_recv(struct composite_context *c,
352 struct dcerpc_pipe **pp);
354 NTSTATUS dcerpc_epm_map_binding(TALLOC_CTX *mem_ctx, struct dcerpc_binding *binding,
355 const struct ndr_interface_table *table, struct tevent_context *ev,
356 struct loadparm_context *lp_ctx);
357 struct composite_context* dcerpc_secondary_auth_connection_send(struct dcerpc_pipe *p,
358 struct dcerpc_binding *binding,
359 const struct ndr_interface_table *table,
360 struct cli_credentials *credentials,
361 struct loadparm_context *lp_ctx);
362 NTSTATUS dcerpc_secondary_auth_connection_recv(struct composite_context *c,
364 struct dcerpc_pipe **p);
366 struct composite_context* dcerpc_secondary_connection_send(struct dcerpc_pipe *p,
367 struct dcerpc_binding *b);
368 void dcerpc_log_packet(const char *lockdir,
369 const struct ndr_interface_table *ndr,
370 uint32_t opnum, uint32_t flags,
371 const DATA_BLOB *pkt);
372 NTSTATUS dcerpc_binding_build_tower(TALLOC_CTX *mem_ctx,
373 const struct dcerpc_binding *binding,
374 struct epm_tower *tower);
376 NTSTATUS dcerpc_floor_get_lhs_data(const struct epm_floor *epm_floor, struct ndr_syntax_id *syntax);
378 enum dcerpc_transport_t dcerpc_transport_by_tower(const struct epm_tower *tower);
379 const char *derpc_transport_string_by_transport(enum dcerpc_transport_t t);
381 NTSTATUS dcerpc_ndr_request(struct dcerpc_pipe *p,
382 const struct GUID *object,
383 const struct ndr_interface_table *table,
388 NTSTATUS dcerpc_binding_from_tower(TALLOC_CTX *mem_ctx,
389 struct epm_tower *tower,
390 struct dcerpc_binding **b_out);
392 NTSTATUS dcerpc_request(struct dcerpc_pipe *p,
396 DATA_BLOB *stub_data_in,
397 DATA_BLOB *stub_data_out);
399 enum dcerpc_transport_t dcerpc_transport_by_endpoint_protocol(int prot);
401 const char *dcerpc_floor_get_rhs_data(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor);
403 struct tevent_req *dcerpc_read_ncacn_packet_send(TALLOC_CTX *mem_ctx,
404 struct tevent_context *ev,
405 struct tstream_context *stream);
406 NTSTATUS dcerpc_read_ncacn_packet_recv(struct tevent_req *req,
408 struct ncacn_packet **pkt,
411 struct dcerpc_binding_handle_ops {
414 bool (*is_connected)(struct dcerpc_binding_handle *h);
415 uint32_t (*set_timeout)(struct dcerpc_binding_handle *h,
418 struct tevent_req *(*raw_call_send)(TALLOC_CTX *mem_ctx,
419 struct tevent_context *ev,
420 struct dcerpc_binding_handle *h,
421 const struct GUID *object,
424 const uint8_t *in_data,
426 NTSTATUS (*raw_call_recv)(struct tevent_req *req,
430 uint32_t *out_flags);
432 struct tevent_req *(*disconnect_send)(TALLOC_CTX *mem_ctx,
433 struct tevent_context *ev,
434 struct dcerpc_binding_handle *h);
435 NTSTATUS (*disconnect_recv)(struct tevent_req *req);
437 /* TODO: remove the following functions */
438 bool (*push_bigendian)(struct dcerpc_binding_handle *h);
439 bool (*ref_alloc)(struct dcerpc_binding_handle *h);
440 bool (*use_ndr64)(struct dcerpc_binding_handle *h);
441 void (*do_ndr_print)(struct dcerpc_binding_handle *h,
443 const void *struct_ptr,
444 const struct ndr_interface_call *call);
445 void (*ndr_push_failed)(struct dcerpc_binding_handle *h,
447 const void *struct_ptr,
448 const struct ndr_interface_call *call);
449 void (*ndr_pull_failed)(struct dcerpc_binding_handle *h,
451 const DATA_BLOB *blob,
452 const struct ndr_interface_call *call);
453 NTSTATUS (*ndr_validate_in)(struct dcerpc_binding_handle *h,
455 const DATA_BLOB *blob,
456 const struct ndr_interface_call *call);
457 NTSTATUS (*ndr_validate_out)(struct dcerpc_binding_handle *h,
458 struct ndr_pull *pull_in,
459 const void *struct_ptr,
460 const struct ndr_interface_call *call);
463 struct dcerpc_binding_handle *_dcerpc_binding_handle_create(TALLOC_CTX *mem_ctx,
464 const struct dcerpc_binding_handle_ops *ops,
465 const struct GUID *object,
466 const struct ndr_interface_table *table,
470 const char *location);
471 #define dcerpc_binding_handle_create(mem_ctx, ops, object, table, \
472 state, type, location) \
473 _dcerpc_binding_handle_create(mem_ctx, ops, object, table, \
474 state, sizeof(type), #type, location)
476 void *_dcerpc_binding_handle_data(struct dcerpc_binding_handle *h);
477 #define dcerpc_binding_handle_data(_h, _type) \
478 talloc_get_type_abort(_dcerpc_binding_handle_data(_h), _type)
480 _DEPRECATED_ void dcerpc_binding_handle_set_sync_ev(struct dcerpc_binding_handle *h,
481 struct tevent_context *ev);
483 bool dcerpc_binding_handle_is_connected(struct dcerpc_binding_handle *h);
485 uint32_t dcerpc_binding_handle_set_timeout(struct dcerpc_binding_handle *h,
488 struct tevent_req *dcerpc_binding_handle_raw_call_send(TALLOC_CTX *mem_ctx,
489 struct tevent_context *ev,
490 struct dcerpc_binding_handle *h,
491 const struct GUID *object,
494 const uint8_t *in_data,
496 NTSTATUS dcerpc_binding_handle_raw_call_recv(struct tevent_req *req,
500 uint32_t *out_flags);
502 struct tevent_req *dcerpc_binding_handle_disconnect_send(TALLOC_CTX *mem_ctx,
503 struct tevent_context *ev,
504 struct dcerpc_binding_handle *h);
505 NTSTATUS dcerpc_binding_handle_disconnect_recv(struct tevent_req *req);
507 struct tevent_req *dcerpc_binding_handle_call_send(TALLOC_CTX *mem_ctx,
508 struct tevent_context *ev,
509 struct dcerpc_binding_handle *h,
510 const struct GUID *object,
511 const struct ndr_interface_table *table,
515 NTSTATUS dcerpc_binding_handle_call_recv(struct tevent_req *req);
516 NTSTATUS dcerpc_binding_handle_call(struct dcerpc_binding_handle *h,
517 const struct GUID *object,
518 const struct ndr_interface_table *table,
523 #endif /* __DCERPC_H__ */