dcesrv_core: introduce dcesrv_connection->transport_max_recv_frag
[metze/samba/wip.git] / librpc / rpc / dcesrv_core.h
1 /*
2    Unix SMB/CIFS implementation.
3
4    server side dcerpc defines
5
6    Copyright (C) Andrew Tridgell 2003-2005
7    Copyright (C) Stefan (metze) Metzmacher 2004-2005
8    Copyright (C) Samuel Cabrero <scabrero@samba.org> 2019
9
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 3 of the License, or
13    (at your option) any later version.
14
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program.  If not, see <http://www.gnu.org/licenses/>.
22 */
23
24 #ifndef _LIBRPC_RPC_DCESRV_CORE_H_
25 #define _LIBRPC_RPC_DCESRV_CORE_H_
26
27 #include "librpc/rpc/rpc_common.h"
28 #include "librpc/ndr/libndr.h"
29 #include "librpc/gen_ndr/security.h"
30
31 /* modules can use the following to determine if the interface has changed
32  * please increment the version number after each interface change
33  * with a comment and maybe update struct dcesrv_critical_sizes.
34  */
35 /* version 1 - initial version - metze */
36 #define DCERPC_MODULE_VERSION 1
37
38 struct dcesrv_connection;
39 struct dcesrv_call_state;
40 struct dcesrv_auth;
41 struct dcesrv_connection_context;
42 struct dcesrv_iface_state;
43 struct cli_credentials;
44
45 struct dcesrv_interface {
46         const char *name;
47         struct ndr_syntax_id syntax_id;
48
49         /* this function is called when the client binds to this interface  */
50         NTSTATUS (*bind)(struct dcesrv_connection_context *, const struct dcesrv_interface *);
51
52         /* this function is called when the client disconnects the endpoint */
53         void (*unbind)(struct dcesrv_connection_context *, const struct dcesrv_interface *);
54
55         /* the ndr_pull function for the chosen interface.
56          */
57         NTSTATUS (*ndr_pull)(struct dcesrv_call_state *, TALLOC_CTX *, struct ndr_pull *, void **);
58
59         /* the dispatch function for the chosen interface.
60          */
61         NTSTATUS (*dispatch)(struct dcesrv_call_state *, TALLOC_CTX *, void *);
62
63         /* the reply function for the chosen interface.
64          */
65         NTSTATUS (*reply)(struct dcesrv_call_state *, TALLOC_CTX *, void *);
66
67         /* the ndr_push function for the chosen interface.
68          */
69         NTSTATUS (*ndr_push)(struct dcesrv_call_state *, TALLOC_CTX *, struct ndr_push *, const void *);
70
71         /* the local dispatch function for the chosen interface.
72          */
73         NTSTATUS (*local)(struct dcesrv_call_state *, TALLOC_CTX *, void *);
74
75         /* for any private use by the interface code */
76         const void *private_data;
77
78         uint64_t flags;
79 };
80
81 #define DCESRV_INTERFACE_FLAGS_HANDLES_NOT_USED 0x00000001
82
83 enum dcesrv_call_list {
84         DCESRV_LIST_NONE,
85         DCESRV_LIST_CALL_LIST,
86         DCESRV_LIST_FRAGMENTED_CALL_LIST,
87         DCESRV_LIST_PENDING_CALL_LIST
88 };
89
90 struct data_blob_list_item {
91         struct data_blob_list_item *prev,*next;
92         DATA_BLOB blob;
93 };
94
95 /* the state of an ongoing dcerpc call */
96 struct dcesrv_call_state {
97         struct dcesrv_call_state *next, *prev;
98         struct dcesrv_auth *auth_state;
99         struct dcesrv_connection *conn;
100         struct dcesrv_connection_context *context;
101         struct ncacn_packet pkt;
102
103         /*
104          * Used during async bind/alter_context.
105          */
106         struct ncacn_packet ack_pkt;
107
108         /*
109           which list this request is in, if any
110          */
111         enum dcesrv_call_list list;
112
113         /* the backend can mark the call
114          * with DCESRV_CALL_STATE_FLAG_ASYNC
115          * that will cause the frontend to not touch r->out
116          * and skip the reply
117          *
118          * this is only allowed to the backend when DCESRV_CALL_STATE_FLAG_MAY_ASYNC
119          * is already set by the frontend
120          *
121          * the backend then needs to call dcesrv_reply() when it's
122          * ready to send the reply
123          */
124 #define DCESRV_CALL_STATE_FLAG_ASYNC (1<<0)
125 #define DCESRV_CALL_STATE_FLAG_MAY_ASYNC (1<<1)
126 #define DCESRV_CALL_STATE_FLAG_MULTIPLEXED (1<<3)
127 #define DCESRV_CALL_STATE_FLAG_PROCESS_PENDING_CALL (1<<4)
128 #define DCESRV_CALL_STATE_FLAG_WINBIND_OFF (1 << 5)
129         uint32_t state_flags;
130
131         /* the time the request arrived in the server */
132         struct timeval time;
133
134         /* the backend can use this event context for async replies */
135         struct tevent_context *event_ctx;
136
137         /* this is the pointer to the allocated function struct */
138         void *r;
139
140         /*
141          * that's the ndr pull context used in dcesrv_request()
142          * needed by dcesrv_reply() to carry over information
143          * for full pointer support.
144          */
145         struct ndr_pull *ndr_pull;
146
147         DATA_BLOB input;
148
149         struct data_blob_list_item *replies;
150
151         /* this is used by the boilerplate code to generate DCERPC faults */
152         uint32_t fault_code;
153
154         /* the reason why we terminate the connection after sending a response */
155         const char *terminate_reason;
156
157         /* temporary auth_info fields */
158         struct dcerpc_auth in_auth_info;
159         struct dcerpc_auth _out_auth_info;
160         struct dcerpc_auth *out_auth_info;
161
162         /*
163          * Optional subreq for pending calls,
164          * will be used to call tevent_req_cancel()
165          * if the connection terminates,
166          * we got an ORPHANED PDU
167          * or got a CO_CANCEL PDU
168          */
169         bool got_disconnect;
170         bool got_orphaned;
171         bool got_co_cancel;
172         struct tevent_req *subreq;
173 };
174
175 /*
176 * DCERPC Handles
177 * --------------
178 * The various handles that are used in the RPC servers should be
179 * created and fetch using the dcesrv_handle_* functions.
180 *
181 * Use
182 * dcesrv_handle_create(struct dcesrv_call_state \*, uint8 handle_type)
183 * to obtain a new handle of the specified type. Handle types are
184 * unique within each pipe.
185 *
186 * The handle can later be fetched again using:
187 *
188 * struct dcesrv_handle *dcesrv_handle_lookup(
189 *         struct dcesrv_call_state *dce_call,
190 *         struct policy_handle *p,
191 *         uint8 handle_type)
192 *
193 * and destroyed by:
194 *
195 *       TALLOC_FREE(struct dcesrv_handle *).
196 *
197 * User data should be stored in the 'data' member of the dcesrv_handle
198 * struct.
199 */
200
201 #define DCESRV_HANDLE_ANY 255
202
203 /* a dcerpc handle in internal format */
204 struct dcesrv_handle {
205         struct dcesrv_handle *next, *prev;
206         struct dcesrv_assoc_group *assoc_group;
207         struct policy_handle wire_handle;
208         struct dom_sid sid;
209         enum dcerpc_AuthLevel min_auth_level;
210         const struct dcesrv_interface *iface;
211         void *data;
212 };
213
214 /* hold the authentication state information */
215 struct dcesrv_auth {
216         struct dcesrv_auth *prev, *next;
217         enum dcerpc_AuthType auth_type;
218         enum dcerpc_AuthLevel auth_level;
219         uint32_t auth_context_id;
220         struct gensec_security *gensec_security;
221         struct auth_session_info *session_info;
222         NTSTATUS (*session_key_fn)(struct dcesrv_auth *, DATA_BLOB *session_key);
223         bool auth_started;
224         bool auth_finished;
225         bool auth_audited;
226         bool auth_invalid;
227 };
228
229 struct dcesrv_connection_context {
230         struct dcesrv_connection_context *next, *prev;
231         uint16_t context_id;
232
233         /* the connection this is on */
234         struct dcesrv_connection *conn;
235
236         /* the ndr function table for the chosen interface */
237         const struct dcesrv_interface *iface;
238
239         /*
240          * the minimum required auth level for this interface
241          */
242         enum dcerpc_AuthLevel min_auth_level;
243         bool allow_connect;
244
245         /* the negotiated transfer syntax */
246         struct ndr_syntax_id transfer_syntax;
247         bool ndr64;
248 };
249
250
251 /* the state associated with a dcerpc server connection */
252 struct dcesrv_connection {
253         /* for the broken_connections DLIST */
254         struct dcesrv_connection *prev, *next;
255
256         /* the top level context for this server */
257         struct dcesrv_context *dce_ctx;
258
259         /* the endpoint that was opened */
260         const struct dcesrv_endpoint *endpoint;
261
262         /* a list of established context_ids */
263         struct dcesrv_connection_context *contexts;
264
265         /* the state of the current incoming call fragments */
266         struct dcesrv_call_state *incoming_fragmented_call_list;
267
268         /* the state of the async pending calls */
269         struct dcesrv_call_state *pending_call_list;
270
271         /* the state of the current outgoing calls */
272         struct dcesrv_call_state *call_list;
273
274         /* the maximum size the client wants to receive */
275         uint16_t transport_max_recv_frag;
276         uint16_t max_recv_frag;
277         uint16_t max_xmit_frag;
278
279         DATA_BLOB partial_input;
280
281         /* the event_context that will be used for this connection */
282         struct tevent_context *event_ctx;
283
284         /* is this connection pending termination?  If so, why? */
285         const char *terminate;
286
287         const char *packet_log_dir;
288
289         /* this is the default state_flags for dcesrv_call_state structs */
290         uint32_t state_flags;
291
292         struct {
293                 void *private_data;
294                 void (*report_output_data)(struct dcesrv_connection *);
295                 void (*terminate_connection)(struct dcesrv_connection *,
296                                              const char *);
297         } transport;
298
299         struct tstream_context *stream;
300         struct tevent_queue *send_queue;
301
302         const struct tsocket_address *local_address;
303         const struct tsocket_address *remote_address;
304
305         /* the current authentication state */
306         struct dcesrv_auth *default_auth_state;
307         size_t max_auth_states;
308         struct dcesrv_auth *auth_states;
309         bool got_explicit_auth_level_connect;
310         struct dcesrv_auth *default_auth_level_connect;
311         bool client_hdr_signing;
312         bool support_hdr_signing;
313         bool negotiated_hdr_signing;
314
315         /*
316          * remember which pdu types are allowed
317          */
318         bool allow_bind;
319         bool allow_alter;
320
321         /* the association group the connection belongs to */
322         struct dcesrv_assoc_group *assoc_group;
323
324         /* The maximum total payload of reassembled request pdus */
325         size_t max_total_request_size;
326
327         /*
328          * Our preferred transfer syntax.
329          */
330         const struct ndr_syntax_id *preferred_transfer;
331
332         struct dcerpc_sec_vt_preauth preauth;
333
334         /*
335          * This is used to block the connection during
336          * pending authentication.
337          */
338         struct tevent_req *(*wait_send)(TALLOC_CTX *mem_ctx,
339                                         struct tevent_context *ev,
340                                         void *private_data);
341         NTSTATUS (*wait_recv)(struct tevent_req *req);
342         void *wait_private;
343 };
344
345
346 struct dcesrv_endpoint_server {
347         /* this is the name of the endpoint server */
348         const char *name;
349
350         /* true if the endpoint server has been initialized */
351         bool initialized;
352
353         /* this function should register endpoints and some other setup stuff,
354          * it is called when the dcesrv_context gets initialized.
355          */
356         NTSTATUS (*init_server)(struct dcesrv_context *, const struct dcesrv_endpoint_server *);
357
358         /* this function should cleanup endpoint server state and unregister
359          * the endpoint server from dcesrv_context */
360         NTSTATUS (*shutdown_server)(struct dcesrv_context *, const struct dcesrv_endpoint_server *);
361
362         /* this function can be used by other endpoint servers to
363          * ask for a dcesrv_interface implementation
364          * - iface must be reference to an already existing struct !
365          */
366         bool (*interface_by_uuid)(struct dcesrv_interface *iface, const struct GUID *, uint32_t);
367
368         /* this function can be used by other endpoint servers to
369          * ask for a dcesrv_interface implementation
370          * - iface must be reference to an already existing struct !
371          */
372         bool (*interface_by_name)(struct dcesrv_interface *iface, const char *);
373 };
374
375
376 /* one association groups */
377 struct dcesrv_assoc_group {
378         /* the wire id */
379         uint32_t id;
380
381         /* The transport this is valid on */
382         enum dcerpc_transport_t transport;
383
384         /* list of handles in this association group */
385         struct dcesrv_handle *handles;
386
387         /*
388          * list of iface states per assoc/conn
389          */
390         struct dcesrv_iface_state *iface_states;
391
392         /* parent context */
393         struct dcesrv_context *dce_ctx;
394
395         /* the negotiated bind time features */
396         uint16_t bind_time_features;
397 };
398
399 struct dcesrv_context_callbacks {
400         struct {
401                 void (*successful_authz)(
402                         struct dcesrv_call_state *call, void *private_data);
403                 void *private_data;
404         } log;
405         struct {
406                 NTSTATUS (*gensec_prepare)(
407                         TALLOC_CTX *mem_ctx,
408                         struct dcesrv_call_state *call,
409                         struct gensec_security **out,
410                         void *private_data);
411                 void *private_data;
412                 void (*become_root)(void);
413                 void (*unbecome_root)(void);
414         } auth;
415         struct {
416                 NTSTATUS (*find)(
417                         struct dcesrv_call_state *call, void *private_data);
418                 void *private_data;
419         } assoc_group;
420 };
421
422 /* server-wide context information for the dcerpc server */
423 struct dcesrv_context {
424         /*
425          * The euid at startup time.
426          *
427          * This is required for DCERPC_AUTH_TYPE_NCALRPC_AS_SYSTEM
428          */
429         uid_t initial_euid;
430
431         /* the list of endpoints that have registered
432          * by the configured endpoint servers
433          */
434         struct dcesrv_endpoint {
435                 struct dcesrv_endpoint *next, *prev;
436                 /* the type and location of the endpoint */
437                 struct dcerpc_binding *ep_description;
438                 /* the secondary endpoint description for the BIND_ACK */
439                 struct dcerpc_binding *ep_2nd_description;
440                 /* the security descriptor for smb named pipes */
441                 struct security_descriptor *sd;
442                 /* the list of interfaces available on this endpoint */
443                 struct dcesrv_if_list {
444                         struct dcesrv_if_list *next, *prev;
445                         struct dcesrv_interface *iface;
446                 } *interface_list;
447
448                 /*
449                  * Should this service be run in a single process (so far only
450                  * NETLOGON is not run in a single process)
451                  */
452                 bool use_single_process;
453         } *endpoint_list;
454
455         /*
456          * registered auth_type/principals
457          * for dcesrv_mgmt_inq_princ_name()
458          */
459         struct dcesrv_ctx_principal {
460                 struct dcesrv_ctx_principal *next, *prev;
461                 enum dcerpc_AuthType auth_type;
462                 const char *principal_name;
463         } *principal_list;
464
465         /* loadparm context to use for this connection */
466         struct loadparm_context *lp_ctx;
467
468         struct idr_context *assoc_groups_idr;
469         uint32_t assoc_groups_num;
470
471         struct dcesrv_connection *broken_connections;
472
473         /*
474          * Our preferred transfer syntax.
475          */
476         const struct ndr_syntax_id *preferred_transfer;
477
478         struct dcesrv_context_callbacks *callbacks;
479 };
480
481 /* this structure is used by modules to determine the size of some critical types */
482 struct dcesrv_critical_sizes {
483         int interface_version;
484         int sizeof_dcesrv_context;
485         int sizeof_dcesrv_endpoint;
486         int sizeof_dcesrv_endpoint_server;
487         int sizeof_dcesrv_interface;
488         int sizeof_dcesrv_if_list;
489         int sizeof_dcesrv_connection;
490         int sizeof_dcesrv_call_state;
491         int sizeof_dcesrv_auth;
492         int sizeof_dcesrv_handle;
493 };
494
495 NTSTATUS dcesrv_auth_type_principal_register(struct dcesrv_context *dce_ctx,
496                                              enum dcerpc_AuthType auth_type,
497                                              const char *principal_name);
498 const char *dcesrv_auth_type_principal_find(struct dcesrv_context *dce_ctx,
499                                             enum dcerpc_AuthType auth_type);
500 NTSTATUS dcesrv_register_default_auth_types(struct dcesrv_context *dce_ctx,
501                                             const char *principal);
502 NTSTATUS dcesrv_register_default_auth_types_machine_principal(struct dcesrv_context *dce_ctx);
503 NTSTATUS dcesrv_interface_register(struct dcesrv_context *dce_ctx,
504                                    const char *ep_name,
505                                    const char *ncacn_np_secondary_endpoint,
506                                    const struct dcesrv_interface *iface,
507                                    const struct security_descriptor *sd);
508 NTSTATUS dcesrv_interface_register_b(struct dcesrv_context *dce_ctx,
509                                    struct dcerpc_binding *binding,
510                                    struct dcerpc_binding *binding2,
511                                    const struct dcesrv_interface *iface,
512                                    const struct security_descriptor *sd);
513 NTSTATUS dcerpc_register_ep_server(const struct dcesrv_endpoint_server *ep_server);
514 NTSTATUS dcesrv_init_ep_servers(struct dcesrv_context *dce_ctx,
515                                 const char **ep_servers);
516 NTSTATUS dcesrv_init_registered_ep_servers(struct dcesrv_context *dce_ctx);
517 NTSTATUS dcesrv_shutdown_registered_ep_servers(struct dcesrv_context *dce_ctx);
518 NTSTATUS dcesrv_init_ep_server(struct dcesrv_context *dce_ctx,
519                                const char *ep_server_name);
520 NTSTATUS dcesrv_shutdown_ep_server(struct dcesrv_context *dce_ctx,
521                                    const char *name);
522 const struct dcesrv_endpoint_server *dcesrv_ep_server_byname(const char *name);
523
524 NTSTATUS dcesrv_init_context(TALLOC_CTX *mem_ctx,
525                              struct loadparm_context *lp_ctx,
526                              struct dcesrv_context_callbacks *cb,
527                              struct dcesrv_context **_dce_ctx);
528 void dcesrv_context_set_callbacks(
529         struct dcesrv_context *dce_ctx,
530         struct dcesrv_context_callbacks *cb);
531
532 /*
533  * Use dcesrv_async_reply() in async code
534  */
535 NTSTATUS dcesrv_reply(struct dcesrv_call_state *call);
536 void _dcesrv_async_reply(struct dcesrv_call_state *call,
537                          const char *func,
538                          const char *location);
539 #define dcesrv_async_reply(__call) \
540         _dcesrv_async_reply(__call, __func__, __location__)
541
542 struct dcesrv_handle *dcesrv_handle_create(struct dcesrv_call_state *call,
543                                            uint8_t handle_type);
544
545 struct dcesrv_handle *dcesrv_handle_lookup(struct dcesrv_call_state *call,
546                                            const struct policy_handle *p,
547                                            uint8_t handle_type);
548
549 const struct tsocket_address *dcesrv_connection_get_local_address(struct dcesrv_connection *conn);
550 const struct tsocket_address *dcesrv_connection_get_remote_address(struct dcesrv_connection *conn);
551
552 /*
553  * Fetch the authentication session key if available.
554  *
555  * This is the key generated by a gensec authentication.
556  */
557 NTSTATUS dcesrv_auth_session_key(struct dcesrv_call_state *call,
558                                  DATA_BLOB *session_key);
559
560 /*
561  * Fetch the transport session key if available.
562  * Typically this is the SMB session key
563  * or a fixed key for local transports.
564  *
565  * The key is always truncated to 16 bytes.
566 */
567 NTSTATUS dcesrv_transport_session_key(struct dcesrv_call_state *call,
568                                       DATA_BLOB *session_key);
569
570 /* a useful macro for generating a RPC fault in the backend code */
571 #define DCESRV_FAULT(code) do { \
572         dce_call->fault_code = code; \
573         return r->out.result; \
574 } while(0)
575
576 /* a useful macro for generating a RPC fault in the backend code */
577 #define DCESRV_FAULT_VOID(code) do { \
578         dce_call->fault_code = code; \
579         return; \
580 } while(0)
581
582 /* a useful macro for checking the validity of a dcerpc policy handle
583    and giving the right fault code if invalid */
584 #define DCESRV_CHECK_HANDLE(h) do {if (!(h)) DCESRV_FAULT(DCERPC_FAULT_CONTEXT_MISMATCH); } while (0)
585
586 /* this checks for a valid policy handle, and gives a fault if an
587    invalid handle or retval if the handle is of the
588    wrong type */
589 #define DCESRV_PULL_HANDLE_RETVAL(h, inhandle, t, retval) do { \
590         (h) = dcesrv_handle_lookup(dce_call, (inhandle), DCESRV_HANDLE_ANY); \
591         DCESRV_CHECK_HANDLE(h); \
592         if ((t) != DCESRV_HANDLE_ANY && (h)->wire_handle.handle_type != (t)) { \
593                 return retval; \
594         } \
595 } while (0)
596
597 /* this checks for a valid policy handle and gives a dcerpc fault
598    if its the wrong type of handle */
599 #define DCESRV_PULL_HANDLE_FAULT(h, inhandle, t) do { \
600         (h) = dcesrv_handle_lookup(dce_call, (inhandle), t); \
601         DCESRV_CHECK_HANDLE(h); \
602 } while (0)
603
604 #define DCESRV_PULL_HANDLE(h, inhandle, t) DCESRV_PULL_HANDLE_RETVAL(h, inhandle, t, NT_STATUS_INVALID_HANDLE)
605 #define DCESRV_PULL_HANDLE_WERR(h, inhandle, t) DCESRV_PULL_HANDLE_RETVAL(h, inhandle, t, WERR_INVALID_HANDLE)
606
607 /**
608  * retrieve credentials from a dce_call
609  */
610 _PUBLIC_ struct cli_credentials *dcesrv_call_credentials(struct dcesrv_call_state *dce_call);
611
612 /**
613  * returns true if this is an authenticated call
614  */
615 _PUBLIC_ bool dcesrv_call_authenticated(struct dcesrv_call_state *dce_call);
616
617 /**
618  * retrieve account_name for a dce_call
619  */
620 _PUBLIC_ const char *dcesrv_call_account_name(struct dcesrv_call_state *dce_call);
621
622 /**
623  * retrieve session_info from a dce_call
624  */
625 _PUBLIC_ struct auth_session_info *dcesrv_call_session_info(struct dcesrv_call_state *dce_call);
626
627 /**
628  * retrieve auth type/level from a dce_call
629  */
630 _PUBLIC_ void dcesrv_call_auth_info(struct dcesrv_call_state *dce_call,
631                                     enum dcerpc_AuthType *auth_type,
632                                     enum dcerpc_AuthLevel *auth_level);
633
634 _PUBLIC_ NTSTATUS dcesrv_interface_bind_require_integrity(struct dcesrv_connection_context *context,
635                                                           const struct dcesrv_interface *iface);
636 _PUBLIC_ NTSTATUS dcesrv_interface_bind_require_privacy(struct dcesrv_connection_context *context,
637                                                         const struct dcesrv_interface *iface);
638 _PUBLIC_ NTSTATUS dcesrv_interface_bind_reject_connect(struct dcesrv_connection_context *context,
639                                                        const struct dcesrv_interface *iface);
640 _PUBLIC_ NTSTATUS dcesrv_interface_bind_allow_connect(struct dcesrv_connection_context *context,
641                                                       const struct dcesrv_interface *iface);
642
643 _PUBLIC_ NTSTATUS _dcesrv_iface_state_store_assoc(
644                 struct dcesrv_call_state *call,
645                 uint64_t magic,
646                 void *ptr,
647                 const char *location);
648 #define dcesrv_iface_state_store_assoc(call, magic, ptr) \
649         _dcesrv_iface_state_store_assoc((call), (magic), (ptr), \
650                                         __location__)
651 _PUBLIC_ void *_dcesrv_iface_state_find_assoc(
652                 struct dcesrv_call_state *call,
653                 uint64_t magic);
654 #define dcesrv_iface_state_find_assoc(call, magic, _type) \
655         talloc_get_type( \
656                 _dcesrv_iface_state_find_assoc((call), (magic)), \
657                 _type)
658
659 _PUBLIC_ NTSTATUS _dcesrv_iface_state_store_conn(
660                 struct dcesrv_call_state *call,
661                 uint64_t magic,
662                 void *_pptr,
663                 const char *location);
664 #define dcesrv_iface_state_store_conn(call, magic, ptr) \
665         _dcesrv_iface_state_store_conn((call), (magic), (ptr), \
666                                         __location__)
667 _PUBLIC_ void *_dcesrv_iface_state_find_conn(
668                 struct dcesrv_call_state *call,
669                 uint64_t magic);
670 #define dcesrv_iface_state_find_conn(call, magic, _type) \
671         talloc_get_type( \
672                 _dcesrv_iface_state_find_conn((call), (magic)), \
673                 _type)
674
675 _PUBLIC_ void dcesrv_cleanup_broken_connections(struct dcesrv_context *dce_ctx);
676
677 _PUBLIC_ NTSTATUS dcesrv_endpoint_connect(struct dcesrv_context *dce_ctx,
678                                 TALLOC_CTX *mem_ctx,
679                                 const struct dcesrv_endpoint *ep,
680                                 struct auth_session_info *session_info,
681                                 struct tevent_context *event_ctx,
682                                 uint32_t state_flags,
683                                 struct dcesrv_connection **_p);
684 _PUBLIC_ NTSTATUS dcesrv_find_endpoint(struct dcesrv_context *dce_ctx,
685                                 const struct dcerpc_binding *ep_description,
686                                 struct dcesrv_endpoint **_out);
687
688 _PUBLIC_ void dcesrv_terminate_connection(struct dcesrv_connection *dce_conn,
689                                           const char *reason);
690 _PUBLIC_ void dcesrv_sock_report_output_data(struct dcesrv_connection *dce_conn);
691
692 _PUBLIC_ NTSTATUS dcesrv_connection_loop_start(struct dcesrv_connection *conn);
693
694 _PUBLIC_ void dcesrv_loop_next_packet(
695         struct dcesrv_connection *dce_conn,
696         struct ncacn_packet *pkt,
697         DATA_BLOB buffer);
698
699 _PUBLIC_ NTSTATUS dcesrv_call_dispatch_local(struct dcesrv_call_state *call);
700
701 _PUBLIC_ const struct dcesrv_interface *find_interface_by_syntax_id(
702         const struct dcesrv_endpoint *endpoint,
703         const struct ndr_syntax_id *interface);
704
705 void _dcesrv_save_ndr_fuzz_seed(DATA_BLOB call_blob,
706                                 struct dcesrv_call_state *call,
707                                 ndr_flags_type flags);
708
709 #if DEVELOPER
710 #define  dcesrv_save_ndr_fuzz_seed(stub, call, flags) \
711         _dcesrv_save_ndr_fuzz_seed(stub, call, flags)
712 #else
713 #define  dcesrv_save_ndr_fuzz_seed(stub, call, flags) \
714         /* */
715 #endif
716
717
718 #endif /* _LIBRPC_RPC_DCESRV_CORE_H_ */