s3:utils/net_sam make use of pdb_create_builtin helper function
[Samba.git] / source4 / rpc_server / dcerpc_server.h
blob4fcb5c50a13e11892008efb671e6bf8d077701fc
1 /*
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;
39 struct dcesrv_auth;
40 struct dcesrv_connection_context;
42 struct dcesrv_interface {
43 const char *name;
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 {
73 DCESRV_LIST_NONE,
74 DCESRV_LIST_CALL_LIST,
75 DCESRV_LIST_FRAGMENTED_CALL_LIST,
76 DCESRV_LIST_PENDING_CALL_LIST
79 /* the state of an ongoing dcerpc call */
80 struct dcesrv_call_state {
81 struct dcesrv_call_state *next, *prev;
82 struct dcesrv_connection *conn;
83 struct dcesrv_connection_context *context;
84 struct ncacn_packet pkt;
87 which list this request is in, if any
89 enum dcesrv_call_list list;
91 /* the backend can mark the call
92 * with DCESRV_CALL_STATE_FLAG_ASYNC
93 * that will cause the frontend to not touch r->out
94 * and skip the reply
96 * this is only allowed to the backend when DCESRV_CALL_STATE_FLAG_MAY_ASYNC
97 * is alerady set by the frontend
99 * the backend then needs to call dcesrv_reply() when it's
100 * ready to send the reply
102 #define DCESRV_CALL_STATE_FLAG_ASYNC (1<<0)
103 #define DCESRV_CALL_STATE_FLAG_MAY_ASYNC (1<<1)
104 #define DCESRV_CALL_STATE_FLAG_HEADER_SIGNING (1<<2)
105 uint32_t state_flags;
107 /* the time the request arrived in the server */
108 struct timeval time;
110 /* the backend can use this event context for async replies */
111 struct tevent_context *event_ctx;
113 /* the message_context that will be used for async replies */
114 struct imessaging_context *msg_ctx;
116 /* this is the pointer to the allocated function struct */
117 void *r;
120 * that's the ndr pull context used in dcesrv_request()
121 * needed by dcesrv_reply() to carry over information
122 * for full pointer support.
124 struct ndr_pull *ndr_pull;
126 DATA_BLOB input;
128 struct data_blob_list_item *replies;
130 /* this is used by the boilerplate code to generate DCERPC faults */
131 uint32_t fault_code;
134 #define DCESRV_HANDLE_ANY 255
136 /* a dcerpc handle in internal format */
137 struct dcesrv_handle {
138 struct dcesrv_handle *next, *prev;
139 struct dcesrv_assoc_group *assoc_group;
140 struct policy_handle wire_handle;
141 struct dom_sid *sid;
142 const struct dcesrv_interface *iface;
143 void *data;
146 /* hold the authentication state information */
147 struct dcesrv_auth {
148 struct dcerpc_auth *auth_info;
149 struct gensec_security *gensec_security;
150 struct auth_session_info *session_info;
151 NTSTATUS (*session_key)(struct dcesrv_connection *, DATA_BLOB *session_key);
154 struct dcesrv_connection_context {
155 struct dcesrv_connection_context *next, *prev;
156 uint32_t context_id;
158 struct dcesrv_assoc_group *assoc_group;
160 /* the connection this is on */
161 struct dcesrv_connection *conn;
163 /* the ndr function table for the chosen interface */
164 const struct dcesrv_interface *iface;
166 /* private data for the interface implementation */
167 void *private_data;
171 /* the state associated with a dcerpc server connection */
172 struct dcesrv_connection {
173 /* the top level context for this server */
174 struct dcesrv_context *dce_ctx;
176 /* the endpoint that was opened */
177 const struct dcesrv_endpoint *endpoint;
179 /* a list of established context_ids */
180 struct dcesrv_connection_context *contexts;
182 /* the state of the current incoming call fragments */
183 struct dcesrv_call_state *incoming_fragmented_call_list;
185 /* the state of the async pending calls */
186 struct dcesrv_call_state *pending_call_list;
188 /* the state of the current outgoing calls */
189 struct dcesrv_call_state *call_list;
191 /* the maximum size the client wants to receive */
192 uint32_t cli_max_recv_frag;
194 DATA_BLOB partial_input;
196 /* the current authentication state */
197 struct dcesrv_auth auth_state;
199 /* the event_context that will be used for this connection */
200 struct tevent_context *event_ctx;
202 /* the message_context that will be used for this connection */
203 struct imessaging_context *msg_ctx;
205 /* the server_id that will be used for this connection */
206 struct server_id server_id;
208 /* the transport level session key */
209 DATA_BLOB transport_session_key;
211 bool processing;
213 const char *packet_log_dir;
215 /* this is the default state_flags for dcesrv_call_state structs */
216 uint32_t state_flags;
218 struct {
219 void *private_data;
220 void (*report_output_data)(struct dcesrv_connection *);
221 } transport;
223 struct tstream_context *stream;
224 struct tevent_queue *send_queue;
226 const struct tsocket_address *local_address;
227 const struct tsocket_address *remote_address;
231 struct dcesrv_endpoint_server {
232 /* this is the name of the endpoint server */
233 const char *name;
235 /* this function should register endpoints and some other setup stuff,
236 * it is called when the dcesrv_context gets initialized.
238 NTSTATUS (*init_server)(struct dcesrv_context *, const struct dcesrv_endpoint_server *);
240 /* this function can be used by other endpoint servers to
241 * ask for a dcesrv_interface implementation
242 * - iface must be reference to an already existing struct !
244 bool (*interface_by_uuid)(struct dcesrv_interface *iface, const struct GUID *, uint32_t);
246 /* this function can be used by other endpoint servers to
247 * ask for a dcesrv_interface implementation
248 * - iface must be reference to an already existeng struct !
250 bool (*interface_by_name)(struct dcesrv_interface *iface, const char *);
254 /* one association groups */
255 struct dcesrv_assoc_group {
256 /* the wire id */
257 uint32_t id;
259 /* list of handles in this association group */
260 struct dcesrv_handle *handles;
262 /* parent context */
263 struct dcesrv_context *dce_ctx;
265 /* Remote association group ID (if proxied) */
266 uint32_t proxied_id;
269 /* server-wide context information for the dcerpc server */
270 struct dcesrv_context {
271 /* the list of endpoints that have registered
272 * by the configured endpoint servers
274 struct dcesrv_endpoint {
275 struct dcesrv_endpoint *next, *prev;
276 /* the type and location of the endpoint */
277 struct dcerpc_binding *ep_description;
278 /* the security descriptor for smb named pipes */
279 struct security_descriptor *sd;
280 /* the list of interfaces available on this endpoint */
281 struct dcesrv_if_list {
282 struct dcesrv_if_list *next, *prev;
283 struct dcesrv_interface iface;
284 } *interface_list;
285 } *endpoint_list;
287 /* loadparm context to use for this connection */
288 struct loadparm_context *lp_ctx;
290 struct idr_context *assoc_groups_idr;
293 /* this structure is used by modules to determine the size of some critical types */
294 struct dcesrv_critical_sizes {
295 int interface_version;
296 int sizeof_dcesrv_context;
297 int sizeof_dcesrv_endpoint;
298 int sizeof_dcesrv_endpoint_server;
299 int sizeof_dcesrv_interface;
300 int sizeof_dcesrv_if_list;
301 int sizeof_dcesrv_connection;
302 int sizeof_dcesrv_call_state;
303 int sizeof_dcesrv_auth;
304 int sizeof_dcesrv_handle;
307 struct model_ops;
309 NTSTATUS dcesrv_interface_register(struct dcesrv_context *dce_ctx,
310 const char *ep_name,
311 const struct dcesrv_interface *iface,
312 const struct security_descriptor *sd);
313 NTSTATUS dcerpc_register_ep_server(const void *_ep_server);
314 NTSTATUS dcesrv_init_context(TALLOC_CTX *mem_ctx,
315 struct loadparm_context *lp_ctx,
316 const char **endpoint_servers, struct dcesrv_context **_dce_ctx);
317 NTSTATUS dcesrv_endpoint_connect(struct dcesrv_context *dce_ctx,
318 TALLOC_CTX *mem_ctx,
319 const struct dcesrv_endpoint *ep,
320 struct auth_session_info *session_info,
321 struct tevent_context *event_ctx,
322 struct imessaging_context *msg_ctx,
323 struct server_id server_id,
324 uint32_t state_flags,
325 struct dcesrv_connection **_p);
327 NTSTATUS dcesrv_reply(struct dcesrv_call_state *call);
328 struct dcesrv_handle *dcesrv_handle_new(struct dcesrv_connection_context *context,
329 uint8_t handle_type);
331 struct dcesrv_handle *dcesrv_handle_fetch(
332 struct dcesrv_connection_context *context,
333 struct policy_handle *p,
334 uint8_t handle_type);
335 struct socket_address *dcesrv_connection_get_my_addr(struct dcesrv_connection *conn, TALLOC_CTX *mem_ctx);
337 struct socket_address *dcesrv_connection_get_peer_addr(struct dcesrv_connection *conn, TALLOC_CTX *mem_ctx);
338 const struct tsocket_address *dcesrv_connection_get_local_address(struct dcesrv_connection *conn);
339 const struct tsocket_address *dcesrv_connection_get_remote_address(struct dcesrv_connection *conn);
341 NTSTATUS dcesrv_fetch_session_key(struct dcesrv_connection *p, DATA_BLOB *session_key);
343 /* a useful macro for generating a RPC fault in the backend code */
344 #define DCESRV_FAULT(code) do { \
345 dce_call->fault_code = code; \
346 return r->out.result; \
347 } while(0)
349 /* a useful macro for generating a RPC fault in the backend code */
350 #define DCESRV_FAULT_VOID(code) do { \
351 dce_call->fault_code = code; \
352 return; \
353 } while(0)
355 /* a useful macro for checking the validity of a dcerpc policy handle
356 and giving the right fault code if invalid */
357 #define DCESRV_CHECK_HANDLE(h) do {if (!(h)) DCESRV_FAULT(DCERPC_FAULT_CONTEXT_MISMATCH); } while (0)
359 /* this checks for a valid policy handle, and gives a fault if an
360 invalid handle or retval if the handle is of the
361 wrong type */
362 #define DCESRV_PULL_HANDLE_RETVAL(h, inhandle, t, retval) do { \
363 (h) = dcesrv_handle_fetch(dce_call->context, (inhandle), DCESRV_HANDLE_ANY); \
364 DCESRV_CHECK_HANDLE(h); \
365 if ((t) != DCESRV_HANDLE_ANY && (h)->wire_handle.handle_type != (t)) { \
366 return retval; \
368 } while (0)
370 /* this checks for a valid policy handle and gives a dcerpc fault
371 if its the wrong type of handle */
372 #define DCESRV_PULL_HANDLE_FAULT(h, inhandle, t) do { \
373 (h) = dcesrv_handle_fetch(dce_call->context, (inhandle), t); \
374 DCESRV_CHECK_HANDLE(h); \
375 } while (0)
377 #define DCESRV_PULL_HANDLE(h, inhandle, t) DCESRV_PULL_HANDLE_RETVAL(h, inhandle, t, NT_STATUS_INVALID_HANDLE)
378 #define DCESRV_PULL_HANDLE_WERR(h, inhandle, t) DCESRV_PULL_HANDLE_RETVAL(h, inhandle, t, WERR_BADFID)
380 NTSTATUS dcesrv_add_ep(struct dcesrv_context *dce_ctx,
381 struct loadparm_context *lp_ctx,
382 struct dcesrv_endpoint *e,
383 struct tevent_context *event_ctx,
384 const struct model_ops *model_ops);
387 * retrieve credentials from a dce_call
389 _PUBLIC_ struct cli_credentials *dcesrv_call_credentials(struct dcesrv_call_state *dce_call);
392 * returns true if this is an authenticated call
394 _PUBLIC_ bool dcesrv_call_authenticated(struct dcesrv_call_state *dce_call);
397 * retrieve account_name for a dce_call
399 _PUBLIC_ const char *dcesrv_call_account_name(struct dcesrv_call_state *dce_call);
402 #endif /* SAMBA_DCERPC_SERVER_H */