r14380: Reduce the size of structs.h
[kamenim/samba.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 /* modules can use the following to determine if the interface has changed
28  * please increment the version number after each interface change
29  * with a comment and maybe update struct dcesrv_critical_sizes.
30  */
31 /* version 1 - initial version - metze */
32 #define DCERPC_MODULE_VERSION 1
33
34 struct dcesrv_connection;
35 struct dcesrv_call_state;
36 struct dcesrv_auth;
37 struct dcesrv_connection_context;
38
39 struct dcesrv_interface {
40         const char *name;
41         struct GUID uuid;
42         uint32_t if_version;
43
44         /* this function is called when the client binds to this interface  */
45         NTSTATUS (*bind)(struct dcesrv_call_state *, const struct dcesrv_interface *);
46
47         /* this function is called when the client disconnects the endpoint */
48         void (*unbind)(struct dcesrv_connection_context *, const struct dcesrv_interface *);
49
50         /* the ndr_pull function for the chosen interface.
51          */
52         NTSTATUS (*ndr_pull)(struct dcesrv_call_state *, TALLOC_CTX *, struct ndr_pull *, void **);
53         
54         /* the dispatch function for the chosen interface.
55          */
56         NTSTATUS (*dispatch)(struct dcesrv_call_state *, TALLOC_CTX *, void *);
57
58         /* the reply function for the chosen interface.
59          */
60         NTSTATUS (*reply)(struct dcesrv_call_state *, TALLOC_CTX *, void *);
61
62         /* the ndr_push function for the chosen interface.
63          */
64         NTSTATUS (*ndr_push)(struct dcesrv_call_state *, TALLOC_CTX *, struct ndr_push *, const void *);
65
66         /* for any private use by the interface code */
67         const void *private;
68 };
69
70 /* the state of an ongoing dcerpc call */
71 struct dcesrv_call_state {
72         struct dcesrv_call_state *next, *prev;
73         struct dcesrv_connection *conn;
74         struct dcesrv_connection_context *context;
75         struct ncacn_packet pkt;
76
77         /* the backend can mark the call
78          * with DCESRV_CALL_STATE_FLAG_ASYNC
79          * that will cause the frontend to not touch r->out
80          * and skip the reply
81          *
82          * this is only allowed to the backend when DCESRV_CALL_STATE_FLAG_MAY_ASYNC
83          * is alerady set by the frontend
84          *
85          * the backend then needs to call dcesrv_reply() when it's
86          * ready to send the reply
87          */
88 #define DCESRV_CALL_STATE_FLAG_ASYNC (1<<0)
89 #define DCESRV_CALL_STATE_FLAG_MAY_ASYNC (1<<1)
90         uint32_t state_flags;
91
92         /* the time the request arrived in the server */
93         struct timeval time;
94
95         /* the backend can use this event context for async replies */
96         struct event_context *event_ctx;
97
98         /* this is the pointer to the allocated function struct */
99         void *r;
100
101         /* that's the ndr push context used in dcesrv_request */
102         struct ndr_pull *ndr_pull;
103
104         DATA_BLOB input;
105
106         struct data_blob_list_item *replies;
107
108         /* this is used by the boilerplate code to generate DCERPC faults */
109         uint32_t fault_code;
110 };
111
112 #define DCESRV_HANDLE_ANY 255
113
114 /* a dcerpc handle in internal format */
115 struct dcesrv_handle {
116         struct dcesrv_handle *next, *prev;
117         struct dcesrv_connection_context *context;
118         struct policy_handle wire_handle;
119         void *data;
120 };
121
122 /* hold the authentication state information */
123 struct dcesrv_auth {
124         struct dcerpc_auth *auth_info;
125         struct gensec_security *gensec_security;
126         struct auth_session_info *session_info;
127         NTSTATUS (*session_key)(struct dcesrv_connection *, DATA_BLOB *session_key);
128 };
129
130 struct dcesrv_connection_context {
131         struct dcesrv_connection_context *next, *prev;
132         uint32_t context_id;
133
134         /* the connection this is on */
135         struct dcesrv_connection *conn;
136
137         /* the ndr function table for the chosen interface */
138         const struct dcesrv_interface *iface;
139
140         /* private data for the interface implementation */
141         void *private;
142
143         /* current rpc handles - this is really the wrong scope for
144            them, but it will do for now */
145         struct dcesrv_handle *handles;
146 };
147
148
149 /* the state associated with a dcerpc server connection */
150 struct dcesrv_connection {
151         /* the top level context for this server */
152         struct dcesrv_context *dce_ctx;
153
154         /* the endpoint that was opened */
155         const struct dcesrv_endpoint *endpoint;
156
157         /* a list of established context_ids */
158         struct dcesrv_connection_context *contexts;
159
160         /* the state of the current calls */
161         struct dcesrv_call_state *call_list;
162
163         /* the state of the async pending calls */
164         struct dcesrv_call_state *pending_call_list;
165
166         /* the maximum size the client wants to receive */
167         uint32_t cli_max_recv_frag;
168
169         DATA_BLOB partial_input;
170
171         /* the current authentication state */
172         struct dcesrv_auth auth_state;
173
174         struct stream_connection *srv_conn;
175
176         /* the transport level session key */
177         DATA_BLOB transport_session_key;
178
179         BOOL processing;
180
181         /* this is the default state_flags for dcesrv_call_state structs */
182         uint32_t state_flags;
183
184 };
185
186
187 struct dcesrv_endpoint_server {
188         /* this is the name of the endpoint server */
189         const char *name;
190
191         /* this function should register endpoints and some other setup stuff,
192          * it is called when the dcesrv_context gets initialized.
193          */
194         NTSTATUS (*init_server)(struct dcesrv_context *, const struct dcesrv_endpoint_server *);
195
196         /* this function can be used by other endpoint servers to
197          * ask for a dcesrv_interface implementation
198          * - iface must be reference to an already existing struct !
199          */
200         BOOL (*interface_by_uuid)(struct dcesrv_interface *iface, const struct GUID *, uint32_t);
201
202         /* this function can be used by other endpoint servers to
203          * ask for a dcesrv_interface implementation
204          * - iface must be reference to an already existeng struct !
205          */
206         BOOL (*interface_by_name)(struct dcesrv_interface *iface, const char *);
207 };
208
209
210 /* server-wide context information for the dcerpc server */
211 struct dcesrv_context {
212         /* the list of endpoints that have registered 
213          * by the configured endpoint servers 
214          */
215         struct dcesrv_endpoint {
216                 struct dcesrv_endpoint *next, *prev;
217                 /* the type and location of the endpoint */
218                 struct dcerpc_binding *ep_description;
219                 /* the security descriptor for smb named pipes */
220                 struct security_descriptor *sd;
221                 /* the list of interfaces available on this endpoint */
222                 struct dcesrv_if_list {
223                         struct dcesrv_if_list *next, *prev;
224                         struct dcesrv_interface iface;
225                 } *interface_list;
226         } *endpoint_list;
227 };
228
229 /* this structure is used by modules to determine the size of some critical types */
230 struct dcesrv_critical_sizes {
231         int interface_version;
232         int sizeof_dcesrv_context;
233         int sizeof_dcesrv_endpoint;
234         int sizeof_dcesrv_endpoint_server;
235         int sizeof_dcesrv_interface;
236         int sizeof_dcesrv_if_list;
237         int sizeof_dcesrv_connection;
238         int sizeof_dcesrv_call_state;
239         int sizeof_dcesrv_auth;
240         int sizeof_dcesrv_handle;
241 };
242
243 struct model_ops;
244
245 #include "rpc_server/dcerpc_server_proto.h"
246
247 #endif /* SAMBA_DCERPC_SERVER_H */