r21835: fixed a rpc server bug where we failed to remove a call from one
[abartlet/samba.git/.git] / source4 / rpc_server / dcerpc_server.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    
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 2 of the License, or
12    (at your option) any later version.
13    
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.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 #ifndef SAMBA_DCERPC_SERVER_H
25 #define SAMBA_DCERPC_SERVER_H
26
27 #include "core.h"
28 #include "librpc/gen_ndr/misc.h"
29 #include "librpc/rpc/dcerpc.h"
30 #include "librpc/ndr/libndr.h"
31
32 /* modules can use the following to determine if the interface has changed
33  * please increment the version number after each interface change
34  * with a comment and maybe update struct dcesrv_critical_sizes.
35  */
36 /* version 1 - initial version - metze */
37 #define DCERPC_MODULE_VERSION 1
38
39 struct dcesrv_connection;
40 struct dcesrv_call_state;
41 struct dcesrv_auth;
42 struct dcesrv_connection_context;
43
44 struct dcesrv_interface {
45         const char *name;
46         struct dcerpc_syntax_id syntax_id;
47
48         /* this function is called when the client binds to this interface  */
49         NTSTATUS (*bind)(struct dcesrv_call_state *, const struct dcesrv_interface *);
50
51         /* this function is called when the client disconnects the endpoint */
52         void (*unbind)(struct dcesrv_connection_context *, const struct dcesrv_interface *);
53
54         /* the ndr_pull function for the chosen interface.
55          */
56         NTSTATUS (*ndr_pull)(struct dcesrv_call_state *, TALLOC_CTX *, struct ndr_pull *, void **);
57         
58         /* the dispatch function for the chosen interface.
59          */
60         NTSTATUS (*dispatch)(struct dcesrv_call_state *, TALLOC_CTX *, void *);
61
62         /* the reply function for the chosen interface.
63          */
64         NTSTATUS (*reply)(struct dcesrv_call_state *, TALLOC_CTX *, void *);
65
66         /* the ndr_push function for the chosen interface.
67          */
68         NTSTATUS (*ndr_push)(struct dcesrv_call_state *, TALLOC_CTX *, struct ndr_push *, const void *);
69
70         /* for any private use by the interface code */
71         const void *private;
72 };
73
74 enum dcesrv_call_list {
75         DCESRV_LIST_NONE,
76         DCESRV_LIST_CALL_LIST,
77         DCESRV_LIST_FRAGMENTED_CALL_LIST,
78         DCESRV_LIST_PENDING_CALL_LIST
79 };
80
81 /* the state of an ongoing dcerpc call */
82 struct dcesrv_call_state {
83         struct dcesrv_call_state *next, *prev;
84         struct dcesrv_connection *conn;
85         struct dcesrv_connection_context *context;
86         struct ncacn_packet pkt;
87
88         /*
89           which list this request is in, if any
90          */
91         enum dcesrv_call_list list;
92
93         /* the backend can mark the call
94          * with DCESRV_CALL_STATE_FLAG_ASYNC
95          * that will cause the frontend to not touch r->out
96          * and skip the reply
97          *
98          * this is only allowed to the backend when DCESRV_CALL_STATE_FLAG_MAY_ASYNC
99          * is alerady set by the frontend
100          *
101          * the backend then needs to call dcesrv_reply() when it's
102          * ready to send the reply
103          */
104 #define DCESRV_CALL_STATE_FLAG_ASYNC (1<<0)
105 #define DCESRV_CALL_STATE_FLAG_MAY_ASYNC (1<<1)
106         uint32_t state_flags;
107
108         /* the time the request arrived in the server */
109         struct timeval time;
110
111         /* the backend can use this event context for async replies */
112         struct event_context *event_ctx;
113
114         /* the message_context that will be used for async replies */
115         struct messaging_context *msg_ctx;
116
117         /* this is the pointer to the allocated function struct */
118         void *r;
119
120         /*
121          * that's the ndr pull context used in dcesrv_request()
122          * needed by dcesrv_reply() to carry over information
123          * for full pointer support.
124          */
125         struct ndr_pull *ndr_pull;
126
127         DATA_BLOB input;
128
129         struct data_blob_list_item *replies;
130
131         /* this is used by the boilerplate code to generate DCERPC faults */
132         uint32_t fault_code;
133 };
134
135 #define DCESRV_HANDLE_ANY 255
136
137 /* a dcerpc handle in internal format */
138 struct dcesrv_handle {
139         struct dcesrv_handle *next, *prev;
140         struct dcesrv_connection_context *context;
141         struct policy_handle wire_handle;
142         void *data;
143 };
144
145 /* hold the authentication state information */
146 struct dcesrv_auth {
147         struct dcerpc_auth *auth_info;
148         struct gensec_security *gensec_security;
149         struct auth_session_info *session_info;
150         NTSTATUS (*session_key)(struct dcesrv_connection *, DATA_BLOB *session_key);
151 };
152
153 struct dcesrv_connection_context {
154         struct dcesrv_connection_context *next, *prev;
155         uint32_t context_id;
156
157         /* the connection this is on */
158         struct dcesrv_connection *conn;
159
160         /* the ndr function table for the chosen interface */
161         const struct dcesrv_interface *iface;
162
163         /* private data for the interface implementation */
164         void *private;
165
166         /* current rpc handles - this is really the wrong scope for
167            them, but it will do for now */
168         struct dcesrv_handle *handles;
169 };
170
171
172 /* the state associated with a dcerpc server connection */
173 struct dcesrv_connection {
174         /* the top level context for this server */
175         struct dcesrv_context *dce_ctx;
176
177         /* the endpoint that was opened */
178         const struct dcesrv_endpoint *endpoint;
179
180         /* a list of established context_ids */
181         struct dcesrv_connection_context *contexts;
182
183         /* the state of the current incoming call fragments */
184         struct dcesrv_call_state *incoming_fragmented_call_list;
185
186         /* the state of the async pending calls */
187         struct dcesrv_call_state *pending_call_list;
188
189         /* the state of the current outgoing calls */
190         struct dcesrv_call_state *call_list;
191
192         /* the maximum size the client wants to receive */
193         uint32_t cli_max_recv_frag;
194
195         DATA_BLOB partial_input;
196
197         /* the current authentication state */
198         struct dcesrv_auth auth_state;
199
200         /* the event_context that will be used for this connection */
201         struct event_context *event_ctx;
202
203         /* the message_context that will be used for this connection */
204         struct messaging_context *msg_ctx;
205
206         /* the server_id that will be used for this connection */
207         struct server_id server_id;
208
209         /* the transport level session key */
210         DATA_BLOB transport_session_key;
211
212         BOOL processing;
213
214         /* this is the default state_flags for dcesrv_call_state structs */
215         uint32_t state_flags;
216
217         struct {
218                 void *private_data;
219                 void (*report_output_data)(struct dcesrv_connection *);
220                 struct socket_address *(*get_my_addr)(struct dcesrv_connection *, TALLOC_CTX *mem_ctx);
221                 struct socket_address *(*get_peer_addr)(struct dcesrv_connection *, TALLOC_CTX *mem_ctx);
222         } transport;
223 };
224
225
226 struct dcesrv_endpoint_server {
227         /* this is the name of the endpoint server */
228         const char *name;
229
230         /* this function should register endpoints and some other setup stuff,
231          * it is called when the dcesrv_context gets initialized.
232          */
233         NTSTATUS (*init_server)(struct dcesrv_context *, const struct dcesrv_endpoint_server *);
234
235         /* this function can be used by other endpoint servers to
236          * ask for a dcesrv_interface implementation
237          * - iface must be reference to an already existing struct !
238          */
239         BOOL (*interface_by_uuid)(struct dcesrv_interface *iface, const struct GUID *, uint32_t);
240
241         /* this function can be used by other endpoint servers to
242          * ask for a dcesrv_interface implementation
243          * - iface must be reference to an already existeng struct !
244          */
245         BOOL (*interface_by_name)(struct dcesrv_interface *iface, const char *);
246 };
247
248
249 /* server-wide context information for the dcerpc server */
250 struct dcesrv_context {
251         /* the list of endpoints that have registered 
252          * by the configured endpoint servers 
253          */
254         struct dcesrv_endpoint {
255                 struct dcesrv_endpoint *next, *prev;
256                 /* the type and location of the endpoint */
257                 struct dcerpc_binding *ep_description;
258                 /* the security descriptor for smb named pipes */
259                 struct security_descriptor *sd;
260                 /* the list of interfaces available on this endpoint */
261                 struct dcesrv_if_list {
262                         struct dcesrv_if_list *next, *prev;
263                         struct dcesrv_interface iface;
264                 } *interface_list;
265         } *endpoint_list;
266 };
267
268 /* this structure is used by modules to determine the size of some critical types */
269 struct dcesrv_critical_sizes {
270         int interface_version;
271         int sizeof_dcesrv_context;
272         int sizeof_dcesrv_endpoint;
273         int sizeof_dcesrv_endpoint_server;
274         int sizeof_dcesrv_interface;
275         int sizeof_dcesrv_if_list;
276         int sizeof_dcesrv_connection;
277         int sizeof_dcesrv_call_state;
278         int sizeof_dcesrv_auth;
279         int sizeof_dcesrv_handle;
280 };
281
282 struct model_ops;
283
284 #include "rpc_server/dcerpc_server_proto.h"
285
286 #endif /* SAMBA_DCERPC_SERVER_H */