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
;
72 enum dcesrv_call_list
{
74 DCESRV_LIST_CALL_LIST
,
75 DCESRV_LIST_FRAGMENTED_CALL_LIST
,
76 DCESRV_LIST_PENDING_CALL_LIST
79 struct data_blob_list_item
{
80 struct data_blob_list_item
*prev
,*next
;
84 /* the state of an ongoing dcerpc call */
85 struct dcesrv_call_state
{
86 struct dcesrv_call_state
*next
, *prev
;
87 struct dcesrv_connection
*conn
;
88 struct dcesrv_connection_context
*context
;
89 struct ncacn_packet pkt
;
92 which list this request is in, if any
94 enum dcesrv_call_list list
;
96 /* the backend can mark the call
97 * with DCESRV_CALL_STATE_FLAG_ASYNC
98 * that will cause the frontend to not touch r->out
101 * this is only allowed to the backend when DCESRV_CALL_STATE_FLAG_MAY_ASYNC
102 * is alerady set by the frontend
104 * the backend then needs to call dcesrv_reply() when it's
105 * ready to send the reply
107 #define DCESRV_CALL_STATE_FLAG_ASYNC (1<<0)
108 #define DCESRV_CALL_STATE_FLAG_MAY_ASYNC (1<<1)
109 #define DCESRV_CALL_STATE_FLAG_MULTIPLEXED (1<<3)
110 #define DCESRV_CALL_STATE_FLAG_PROCESS_PENDING_CALL (1<<4)
111 uint32_t state_flags
;
113 /* the time the request arrived in the server */
116 /* the backend can use this event context for async replies */
117 struct tevent_context
*event_ctx
;
119 /* the message_context that will be used for async replies */
120 struct imessaging_context
*msg_ctx
;
122 /* this is the pointer to the allocated function struct */
126 * that's the ndr pull context used in dcesrv_request()
127 * needed by dcesrv_reply() to carry over information
128 * for full pointer support.
130 struct ndr_pull
*ndr_pull
;
134 struct data_blob_list_item
*replies
;
136 /* this is used by the boilerplate code to generate DCERPC faults */
139 /* the reason why we terminate the connection after sending a response */
140 const char *terminate_reason
;
142 /* temporary auth_info fields */
143 struct dcerpc_auth in_auth_info
;
144 struct dcerpc_auth _out_auth_info
;
145 struct dcerpc_auth
*out_auth_info
;
148 #define DCESRV_HANDLE_ANY 255
150 /* a dcerpc handle in internal format */
151 struct dcesrv_handle
{
152 struct dcesrv_handle
*next
, *prev
;
153 struct dcesrv_assoc_group
*assoc_group
;
154 struct policy_handle wire_handle
;
156 const struct dcesrv_interface
*iface
;
160 /* hold the authentication state information */
162 enum dcerpc_AuthType auth_type
;
163 enum dcerpc_AuthLevel auth_level
;
164 uint32_t auth_context_id
;
165 struct gensec_security
*gensec_security
;
166 struct auth_session_info
*session_info
;
167 NTSTATUS (*session_key
)(struct dcesrv_connection
*, DATA_BLOB
*session_key
);
168 bool client_hdr_signing
;
174 struct dcesrv_connection_context
{
175 struct dcesrv_connection_context
*next
, *prev
;
178 /* TODO: remove this legacy (for openchange) in master */
179 struct dcesrv_assoc_group
*assoc_group
;
181 /* the connection this is on */
182 struct dcesrv_connection
*conn
;
184 /* the ndr function table for the chosen interface */
185 const struct dcesrv_interface
*iface
;
187 /* private data for the interface implementation */
191 * the minimum required auth level for this interface
193 enum dcerpc_AuthLevel min_auth_level
;
198 /* the state associated with a dcerpc server connection */
199 struct dcesrv_connection
{
200 /* for the broken_connections DLIST */
201 struct dcesrv_connection
*prev
, *next
;
203 /* the top level context for this server */
204 struct dcesrv_context
*dce_ctx
;
206 /* the endpoint that was opened */
207 const struct dcesrv_endpoint
*endpoint
;
209 /* a list of established context_ids */
210 struct dcesrv_connection_context
*contexts
;
212 /* the state of the current incoming call fragments */
213 struct dcesrv_call_state
*incoming_fragmented_call_list
;
215 /* the state of the async pending calls */
216 struct dcesrv_call_state
*pending_call_list
;
218 /* the state of the current outgoing calls */
219 struct dcesrv_call_state
*call_list
;
221 /* the maximum size the client wants to receive */
222 uint16_t max_recv_frag
;
223 uint16_t max_xmit_frag
;
225 DATA_BLOB partial_input
;
227 /* the event_context that will be used for this connection */
228 struct tevent_context
*event_ctx
;
230 /* the message_context that will be used for this connection */
231 struct imessaging_context
*msg_ctx
;
233 /* the server_id that will be used for this connection */
234 struct server_id server_id
;
236 /* the transport level session key */
237 DATA_BLOB transport_session_key
;
239 /* is this connection pending termination? If so, why? */
240 const char *terminate
;
242 const char *packet_log_dir
;
244 /* this is the default state_flags for dcesrv_call_state structs */
245 uint32_t state_flags
;
249 void (*report_output_data
)(struct dcesrv_connection
*);
252 struct tstream_context
*stream
;
253 struct tevent_queue
*send_queue
;
255 const struct tsocket_address
*local_address
;
256 const struct tsocket_address
*remote_address
;
258 /* the current authentication state */
259 struct dcesrv_auth auth_state
;
262 * remember which pdu types are allowed
269 /* the association group the connection belongs to */
270 struct dcesrv_assoc_group
*assoc_group
;
272 /* The maximum total payload of reassembled request pdus */
273 size_t max_total_request_size
;
277 struct dcesrv_endpoint_server
{
278 /* this is the name of the endpoint server */
281 /* this function should register endpoints and some other setup stuff,
282 * it is called when the dcesrv_context gets initialized.
284 NTSTATUS (*init_server
)(struct dcesrv_context
*, const struct dcesrv_endpoint_server
*);
286 /* this function can be used by other endpoint servers to
287 * ask for a dcesrv_interface implementation
288 * - iface must be reference to an already existing struct !
290 bool (*interface_by_uuid
)(struct dcesrv_interface
*iface
, const struct GUID
*, uint32_t);
292 /* this function can be used by other endpoint servers to
293 * ask for a dcesrv_interface implementation
294 * - iface must be reference to an already existeng struct !
296 bool (*interface_by_name
)(struct dcesrv_interface
*iface
, const char *);
300 /* one association groups */
301 struct dcesrv_assoc_group
{
305 /* list of handles in this association group */
306 struct dcesrv_handle
*handles
;
309 struct dcesrv_context
*dce_ctx
;
311 /* Remote association group ID (if proxied) */
315 /* server-wide context information for the dcerpc server */
316 struct dcesrv_context
{
318 * The euid at startup time.
320 * This is required for DCERPC_AUTH_TYPE_NCALRPC_AS_SYSTEM
324 /* the list of endpoints that have registered
325 * by the configured endpoint servers
327 struct dcesrv_endpoint
{
328 struct dcesrv_endpoint
*next
, *prev
;
329 /* the type and location of the endpoint */
330 struct dcerpc_binding
*ep_description
;
331 /* the security descriptor for smb named pipes */
332 struct security_descriptor
*sd
;
333 /* the list of interfaces available on this endpoint */
334 struct dcesrv_if_list
{
335 struct dcesrv_if_list
*next
, *prev
;
336 struct dcesrv_interface iface
;
340 /* loadparm context to use for this connection */
341 struct loadparm_context
*lp_ctx
;
343 struct idr_context
*assoc_groups_idr
;
345 struct dcesrv_connection
*broken_connections
;
348 /* this structure is used by modules to determine the size of some critical types */
349 struct dcesrv_critical_sizes
{
350 int interface_version
;
351 int sizeof_dcesrv_context
;
352 int sizeof_dcesrv_endpoint
;
353 int sizeof_dcesrv_endpoint_server
;
354 int sizeof_dcesrv_interface
;
355 int sizeof_dcesrv_if_list
;
356 int sizeof_dcesrv_connection
;
357 int sizeof_dcesrv_call_state
;
358 int sizeof_dcesrv_auth
;
359 int sizeof_dcesrv_handle
;
364 NTSTATUS
dcesrv_interface_register(struct dcesrv_context
*dce_ctx
,
366 const struct dcesrv_interface
*iface
,
367 const struct security_descriptor
*sd
);
368 NTSTATUS
dcerpc_register_ep_server(const void *_ep_server
);
369 NTSTATUS
dcesrv_init_context(TALLOC_CTX
*mem_ctx
,
370 struct loadparm_context
*lp_ctx
,
371 const char **endpoint_servers
, struct dcesrv_context
**_dce_ctx
);
372 NTSTATUS
dcesrv_endpoint_connect(struct dcesrv_context
*dce_ctx
,
374 const struct dcesrv_endpoint
*ep
,
375 struct auth_session_info
*session_info
,
376 struct tevent_context
*event_ctx
,
377 struct imessaging_context
*msg_ctx
,
378 struct server_id server_id
,
379 uint32_t state_flags
,
380 struct dcesrv_connection
**_p
);
382 NTSTATUS
dcesrv_reply(struct dcesrv_call_state
*call
);
383 struct dcesrv_handle
*dcesrv_handle_new(struct dcesrv_connection_context
*context
,
384 uint8_t handle_type
);
386 struct dcesrv_handle
*dcesrv_handle_fetch(
387 struct dcesrv_connection_context
*context
,
388 struct policy_handle
*p
,
389 uint8_t handle_type
);
390 struct socket_address
*dcesrv_connection_get_my_addr(struct dcesrv_connection
*conn
, TALLOC_CTX
*mem_ctx
);
392 struct socket_address
*dcesrv_connection_get_peer_addr(struct dcesrv_connection
*conn
, TALLOC_CTX
*mem_ctx
);
393 const struct tsocket_address
*dcesrv_connection_get_local_address(struct dcesrv_connection
*conn
);
394 const struct tsocket_address
*dcesrv_connection_get_remote_address(struct dcesrv_connection
*conn
);
396 NTSTATUS
dcesrv_fetch_session_key(struct dcesrv_connection
*p
, DATA_BLOB
*session_key
);
398 /* a useful macro for generating a RPC fault in the backend code */
399 #define DCESRV_FAULT(code) do { \
400 dce_call->fault_code = code; \
401 return r->out.result; \
404 /* a useful macro for generating a RPC fault in the backend code */
405 #define DCESRV_FAULT_VOID(code) do { \
406 dce_call->fault_code = code; \
410 /* a useful macro for checking the validity of a dcerpc policy handle
411 and giving the right fault code if invalid */
412 #define DCESRV_CHECK_HANDLE(h) do {if (!(h)) DCESRV_FAULT(DCERPC_FAULT_CONTEXT_MISMATCH); } while (0)
414 /* this checks for a valid policy handle, and gives a fault if an
415 invalid handle or retval if the handle is of the
417 #define DCESRV_PULL_HANDLE_RETVAL(h, inhandle, t, retval) do { \
418 (h) = dcesrv_handle_fetch(dce_call->context, (inhandle), DCESRV_HANDLE_ANY); \
419 DCESRV_CHECK_HANDLE(h); \
420 if ((t) != DCESRV_HANDLE_ANY && (h)->wire_handle.handle_type != (t)) { \
425 /* this checks for a valid policy handle and gives a dcerpc fault
426 if its the wrong type of handle */
427 #define DCESRV_PULL_HANDLE_FAULT(h, inhandle, t) do { \
428 (h) = dcesrv_handle_fetch(dce_call->context, (inhandle), t); \
429 DCESRV_CHECK_HANDLE(h); \
432 #define DCESRV_PULL_HANDLE(h, inhandle, t) DCESRV_PULL_HANDLE_RETVAL(h, inhandle, t, NT_STATUS_INVALID_HANDLE)
433 #define DCESRV_PULL_HANDLE_WERR(h, inhandle, t) DCESRV_PULL_HANDLE_RETVAL(h, inhandle, t, WERR_BADFID)
435 NTSTATUS
dcesrv_add_ep(struct dcesrv_context
*dce_ctx
,
436 struct loadparm_context
*lp_ctx
,
437 struct dcesrv_endpoint
*e
,
438 struct tevent_context
*event_ctx
,
439 const struct model_ops
*model_ops
);
442 * retrieve credentials from a dce_call
444 _PUBLIC_
struct cli_credentials
*dcesrv_call_credentials(struct dcesrv_call_state
*dce_call
);
447 * returns true if this is an authenticated call
449 _PUBLIC_
bool dcesrv_call_authenticated(struct dcesrv_call_state
*dce_call
);
452 * retrieve account_name for a dce_call
454 _PUBLIC_
const char *dcesrv_call_account_name(struct dcesrv_call_state
*dce_call
);
456 _PUBLIC_ NTSTATUS
dcesrv_interface_bind_require_integrity(struct dcesrv_call_state
*dce_call
,
457 const struct dcesrv_interface
*iface
);
458 _PUBLIC_ NTSTATUS
dcesrv_interface_bind_require_privacy(struct dcesrv_call_state
*dce_call
,
459 const struct dcesrv_interface
*iface
);
460 _PUBLIC_ NTSTATUS
dcesrv_interface_bind_reject_connect(struct dcesrv_call_state
*dce_call
,
461 const struct dcesrv_interface
*iface
);
462 _PUBLIC_ NTSTATUS
dcesrv_interface_bind_allow_connect(struct dcesrv_call_state
*dce_call
,
463 const struct dcesrv_interface
*iface
);
465 #endif /* SAMBA_DCERPC_SERVER_H */