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