2 Unix SMB/CIFS implementation.
4 server side dcerpc defines
6 Copyright (C) Andrew Tridgell 2003-2005
7 Copyright (C) Stefan (metze) Metzmacher 2004-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 #ifndef SAMBA_DCERPC_SERVER_H
24 #define SAMBA_DCERPC_SERVER_H
26 #include "librpc/gen_ndr/server_id.h"
27 #include "librpc/rpc/dcerpc.h"
28 #include "librpc/ndr/libndr.h"
30 /* modules can use the following to determine if the interface has changed
31 * please increment the version number after each interface change
32 * with a comment and maybe update struct dcesrv_critical_sizes.
34 /* version 1 - initial version - metze */
35 #define DCERPC_MODULE_VERSION 1
37 struct dcesrv_connection
;
38 struct dcesrv_call_state
;
40 struct dcesrv_connection_context
;
42 struct dcesrv_interface
{
44 struct ndr_syntax_id syntax_id
;
46 /* this function is called when the client binds to this interface */
47 NTSTATUS (*bind
)(struct dcesrv_call_state
*, const struct dcesrv_interface
*, uint32_t if_version
);
49 /* this function is called when the client disconnects the endpoint */
50 void (*unbind
)(struct dcesrv_connection_context
*, const struct dcesrv_interface
*);
52 /* the ndr_pull function for the chosen interface.
54 NTSTATUS (*ndr_pull
)(struct dcesrv_call_state
*, TALLOC_CTX
*, struct ndr_pull
*, void **);
56 /* the dispatch function for the chosen interface.
58 NTSTATUS (*dispatch
)(struct dcesrv_call_state
*, TALLOC_CTX
*, void *);
60 /* the reply function for the chosen interface.
62 NTSTATUS (*reply
)(struct dcesrv_call_state
*, TALLOC_CTX
*, void *);
64 /* the ndr_push function for the chosen interface.
66 NTSTATUS (*ndr_push
)(struct dcesrv_call_state
*, TALLOC_CTX
*, struct ndr_push
*, const void *);
68 /* for any private use by the interface code */
69 const void *private_data
;
74 #define DCESRV_INTERFACE_FLAGS_HANDLES_NOT_USED 0x00000001
76 enum dcesrv_call_list
{
78 DCESRV_LIST_CALL_LIST
,
79 DCESRV_LIST_FRAGMENTED_CALL_LIST
,
80 DCESRV_LIST_PENDING_CALL_LIST
83 struct data_blob_list_item
{
84 struct data_blob_list_item
*prev
,*next
;
88 /* the state of an ongoing dcerpc call */
89 struct dcesrv_call_state
{
90 struct dcesrv_call_state
*next
, *prev
;
91 struct dcesrv_connection
*conn
;
92 struct dcesrv_connection_context
*context
;
93 struct ncacn_packet pkt
;
96 * Used during async bind/alter_context.
98 struct ncacn_packet ack_pkt
;
101 which list this request is in, if any
103 enum dcesrv_call_list list
;
105 /* the backend can mark the call
106 * with DCESRV_CALL_STATE_FLAG_ASYNC
107 * that will cause the frontend to not touch r->out
110 * this is only allowed to the backend when DCESRV_CALL_STATE_FLAG_MAY_ASYNC
111 * is alerady set by the frontend
113 * the backend then needs to call dcesrv_reply() when it's
114 * ready to send the reply
116 #define DCESRV_CALL_STATE_FLAG_ASYNC (1<<0)
117 #define DCESRV_CALL_STATE_FLAG_MAY_ASYNC (1<<1)
118 #define DCESRV_CALL_STATE_FLAG_MULTIPLEXED (1<<3)
119 #define DCESRV_CALL_STATE_FLAG_PROCESS_PENDING_CALL (1<<4)
120 uint32_t state_flags
;
122 /* the time the request arrived in the server */
125 /* the backend can use this event context for async replies */
126 struct tevent_context
*event_ctx
;
128 /* the message_context that will be used for async replies */
129 struct imessaging_context
*msg_ctx
;
131 /* this is the pointer to the allocated function struct */
135 * that's the ndr pull context used in dcesrv_request()
136 * needed by dcesrv_reply() to carry over information
137 * for full pointer support.
139 struct ndr_pull
*ndr_pull
;
143 struct data_blob_list_item
*replies
;
145 /* this is used by the boilerplate code to generate DCERPC faults */
148 /* the reason why we terminate the connection after sending a response */
149 const char *terminate_reason
;
151 /* temporary auth_info fields */
152 struct dcerpc_auth in_auth_info
;
153 struct dcerpc_auth _out_auth_info
;
154 struct dcerpc_auth
*out_auth_info
;
157 #define DCESRV_HANDLE_ANY 255
159 /* a dcerpc handle in internal format */
160 struct dcesrv_handle
{
161 struct dcesrv_handle
*next
, *prev
;
162 struct dcesrv_assoc_group
*assoc_group
;
163 struct policy_handle wire_handle
;
165 const struct dcesrv_interface
*iface
;
169 /* hold the authentication state information */
171 enum dcerpc_AuthType auth_type
;
172 enum dcerpc_AuthLevel auth_level
;
173 uint32_t auth_context_id
;
174 struct gensec_security
*gensec_security
;
175 struct auth_session_info
*session_info
;
176 NTSTATUS (*session_key
)(struct dcesrv_connection
*, DATA_BLOB
*session_key
);
177 bool client_hdr_signing
;
183 struct dcesrv_connection_context
{
184 struct dcesrv_connection_context
*next
, *prev
;
187 /* the connection this is on */
188 struct dcesrv_connection
*conn
;
190 /* the ndr function table for the chosen interface */
191 const struct dcesrv_interface
*iface
;
193 /* private data for the interface implementation */
197 * the minimum required auth level for this interface
199 enum dcerpc_AuthLevel min_auth_level
;
202 /* the negotiated transfer syntax */
203 struct ndr_syntax_id transfer_syntax
;
207 /* the state associated with a dcerpc server connection */
208 struct dcesrv_connection
{
209 /* for the broken_connections DLIST */
210 struct dcesrv_connection
*prev
, *next
;
212 /* the top level context for this server */
213 struct dcesrv_context
*dce_ctx
;
215 /* the endpoint that was opened */
216 const struct dcesrv_endpoint
*endpoint
;
218 /* a list of established context_ids */
219 struct dcesrv_connection_context
*contexts
;
221 /* the state of the current incoming call fragments */
222 struct dcesrv_call_state
*incoming_fragmented_call_list
;
224 /* the state of the async pending calls */
225 struct dcesrv_call_state
*pending_call_list
;
227 /* the state of the current outgoing calls */
228 struct dcesrv_call_state
*call_list
;
230 /* the maximum size the client wants to receive */
231 uint16_t max_recv_frag
;
232 uint16_t max_xmit_frag
;
234 DATA_BLOB partial_input
;
236 /* the event_context that will be used for this connection */
237 struct tevent_context
*event_ctx
;
239 /* the message_context that will be used for this connection */
240 struct imessaging_context
*msg_ctx
;
242 /* the server_id that will be used for this connection */
243 struct server_id server_id
;
245 /* the transport level session key */
246 DATA_BLOB transport_session_key
;
248 /* is this connection pending termination? If so, why? */
249 const char *terminate
;
251 const char *packet_log_dir
;
253 /* this is the default state_flags for dcesrv_call_state structs */
254 uint32_t state_flags
;
258 void (*report_output_data
)(struct dcesrv_connection
*);
261 struct tstream_context
*stream
;
262 struct tevent_queue
*send_queue
;
264 const struct tsocket_address
*local_address
;
265 const struct tsocket_address
*remote_address
;
267 /* the current authentication state */
268 struct dcesrv_auth auth_state
;
271 * remember which pdu types are allowed
278 /* the association group the connection belongs to */
279 struct dcesrv_assoc_group
*assoc_group
;
281 /* The maximum total payload of reassembled request pdus */
282 size_t max_total_request_size
;
285 * Our preferred transfer syntax.
287 const struct ndr_syntax_id
*preferred_transfer
;
289 /* the negotiated bind time features */
290 uint16_t bind_time_features
;
293 * This is used to block the connection during
294 * pending authentication.
296 struct tevent_req
*(*wait_send
)(TALLOC_CTX
*mem_ctx
,
297 struct tevent_context
*ev
,
299 NTSTATUS (*wait_recv
)(struct tevent_req
*req
);
304 struct dcesrv_endpoint_server
{
305 /* this is the name of the endpoint server */
308 /* this function should register endpoints and some other setup stuff,
309 * it is called when the dcesrv_context gets initialized.
311 NTSTATUS (*init_server
)(struct dcesrv_context
*, const struct dcesrv_endpoint_server
*);
313 /* this function can be used by other endpoint servers to
314 * ask for a dcesrv_interface implementation
315 * - iface must be reference to an already existing struct !
317 bool (*interface_by_uuid
)(struct dcesrv_interface
*iface
, const struct GUID
*, uint32_t);
319 /* this function can be used by other endpoint servers to
320 * ask for a dcesrv_interface implementation
321 * - iface must be reference to an already existeng struct !
323 bool (*interface_by_name
)(struct dcesrv_interface
*iface
, const char *);
327 /* one association groups */
328 struct dcesrv_assoc_group
{
332 /* list of handles in this association group */
333 struct dcesrv_handle
*handles
;
336 struct dcesrv_context
*dce_ctx
;
338 /* Remote association group ID (if proxied) */
342 /* server-wide context information for the dcerpc server */
343 struct dcesrv_context
{
345 * The euid at startup time.
347 * This is required for DCERPC_AUTH_TYPE_NCALRPC_AS_SYSTEM
351 /* the list of endpoints that have registered
352 * by the configured endpoint servers
354 struct dcesrv_endpoint
{
355 struct dcesrv_endpoint
*next
, *prev
;
356 /* the type and location of the endpoint */
357 struct dcerpc_binding
*ep_description
;
358 /* the security descriptor for smb named pipes */
359 struct security_descriptor
*sd
;
360 /* the list of interfaces available on this endpoint */
361 struct dcesrv_if_list
{
362 struct dcesrv_if_list
*next
, *prev
;
363 struct dcesrv_interface iface
;
367 * Should this service be run in a single process (so far only
368 * NETLOGON is not run in a single process)
370 bool use_single_process
;
373 /* loadparm context to use for this connection */
374 struct loadparm_context
*lp_ctx
;
376 struct idr_context
*assoc_groups_idr
;
378 struct dcesrv_connection
*broken_connections
;
381 /* this structure is used by modules to determine the size of some critical types */
382 struct dcesrv_critical_sizes
{
383 int interface_version
;
384 int sizeof_dcesrv_context
;
385 int sizeof_dcesrv_endpoint
;
386 int sizeof_dcesrv_endpoint_server
;
387 int sizeof_dcesrv_interface
;
388 int sizeof_dcesrv_if_list
;
389 int sizeof_dcesrv_connection
;
390 int sizeof_dcesrv_call_state
;
391 int sizeof_dcesrv_auth
;
392 int sizeof_dcesrv_handle
;
397 NTSTATUS
dcesrv_interface_register(struct dcesrv_context
*dce_ctx
,
399 const struct dcesrv_interface
*iface
,
400 const struct security_descriptor
*sd
);
401 NTSTATUS
dcerpc_register_ep_server(const struct dcesrv_endpoint_server
*ep_server
);
402 NTSTATUS
dcesrv_init_context(TALLOC_CTX
*mem_ctx
,
403 struct loadparm_context
*lp_ctx
,
404 const char **endpoint_servers
, struct dcesrv_context
**_dce_ctx
);
405 NTSTATUS
dcesrv_endpoint_connect(struct dcesrv_context
*dce_ctx
,
407 const struct dcesrv_endpoint
*ep
,
408 struct auth_session_info
*session_info
,
409 struct tevent_context
*event_ctx
,
410 struct imessaging_context
*msg_ctx
,
411 struct server_id server_id
,
412 uint32_t state_flags
,
413 struct dcesrv_connection
**_p
);
415 NTSTATUS
dcesrv_reply(struct dcesrv_call_state
*call
);
416 struct dcesrv_handle
*dcesrv_handle_new(struct dcesrv_connection_context
*context
,
417 uint8_t handle_type
);
419 struct dcesrv_handle
*dcesrv_handle_fetch(
420 struct dcesrv_connection_context
*context
,
421 struct policy_handle
*p
,
422 uint8_t handle_type
);
424 const struct tsocket_address
*dcesrv_connection_get_local_address(struct dcesrv_connection
*conn
);
425 const struct tsocket_address
*dcesrv_connection_get_remote_address(struct dcesrv_connection
*conn
);
427 NTSTATUS
dcesrv_fetch_session_key(struct dcesrv_connection
*p
, DATA_BLOB
*session_key
);
429 /* a useful macro for generating a RPC fault in the backend code */
430 #define DCESRV_FAULT(code) do { \
431 dce_call->fault_code = code; \
432 return r->out.result; \
435 /* a useful macro for generating a RPC fault in the backend code */
436 #define DCESRV_FAULT_VOID(code) do { \
437 dce_call->fault_code = code; \
441 /* a useful macro for checking the validity of a dcerpc policy handle
442 and giving the right fault code if invalid */
443 #define DCESRV_CHECK_HANDLE(h) do {if (!(h)) DCESRV_FAULT(DCERPC_FAULT_CONTEXT_MISMATCH); } while (0)
445 /* this checks for a valid policy handle, and gives a fault if an
446 invalid handle or retval if the handle is of the
448 #define DCESRV_PULL_HANDLE_RETVAL(h, inhandle, t, retval) do { \
449 (h) = dcesrv_handle_fetch(dce_call->context, (inhandle), DCESRV_HANDLE_ANY); \
450 DCESRV_CHECK_HANDLE(h); \
451 if ((t) != DCESRV_HANDLE_ANY && (h)->wire_handle.handle_type != (t)) { \
456 /* this checks for a valid policy handle and gives a dcerpc fault
457 if its the wrong type of handle */
458 #define DCESRV_PULL_HANDLE_FAULT(h, inhandle, t) do { \
459 (h) = dcesrv_handle_fetch(dce_call->context, (inhandle), t); \
460 DCESRV_CHECK_HANDLE(h); \
463 #define DCESRV_PULL_HANDLE(h, inhandle, t) DCESRV_PULL_HANDLE_RETVAL(h, inhandle, t, NT_STATUS_INVALID_HANDLE)
464 #define DCESRV_PULL_HANDLE_WERR(h, inhandle, t) DCESRV_PULL_HANDLE_RETVAL(h, inhandle, t, WERR_INVALID_HANDLE)
466 NTSTATUS
dcesrv_add_ep(struct dcesrv_context
*dce_ctx
,
467 struct loadparm_context
*lp_ctx
,
468 struct dcesrv_endpoint
*e
,
469 struct tevent_context
*event_ctx
,
470 const struct model_ops
*model_ops
);
473 * retrieve credentials from a dce_call
475 _PUBLIC_
struct cli_credentials
*dcesrv_call_credentials(struct dcesrv_call_state
*dce_call
);
478 * returns true if this is an authenticated call
480 _PUBLIC_
bool dcesrv_call_authenticated(struct dcesrv_call_state
*dce_call
);
483 * retrieve account_name for a dce_call
485 _PUBLIC_
const char *dcesrv_call_account_name(struct dcesrv_call_state
*dce_call
);
487 _PUBLIC_ NTSTATUS
dcesrv_interface_bind_require_integrity(struct dcesrv_call_state
*dce_call
,
488 const struct dcesrv_interface
*iface
);
489 _PUBLIC_ NTSTATUS
dcesrv_interface_bind_require_privacy(struct dcesrv_call_state
*dce_call
,
490 const struct dcesrv_interface
*iface
);
491 _PUBLIC_ NTSTATUS
dcesrv_interface_bind_reject_connect(struct dcesrv_call_state
*dce_call
,
492 const struct dcesrv_interface
*iface
);
493 _PUBLIC_ NTSTATUS
dcesrv_interface_bind_allow_connect(struct dcesrv_call_state
*dce_call
,
494 const struct dcesrv_interface
*iface
);
496 #endif /* SAMBA_DCERPC_SERVER_H */