r3114: - More work on merging the various structs that describe endpoints
[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
7    Copyright (C) Stefan (metze) Metzmacher 2004
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 /* a description of a single dcerpc endpoint. Not as flexible as a full epm tower,
35    but much easier to work with */
36 struct dcesrv_ep_description {
37         enum dcerpc_transport_t type;
38         union {
39                 const char *smb_pipe;
40                 uint16_t tcp_port;
41         } info;
42 };
43
44 struct dcesrv_connection;
45 struct dcesrv_call_state;
46 struct dcesrv_auth;
47
48 /* the dispatch functions for an interface take this form */
49 typedef NTSTATUS (*dcesrv_dispatch_fn_t)(struct dcesrv_call_state *, TALLOC_CTX *, void *);
50
51 struct dcesrv_interface {
52         /* the ndr function table for the chosen interface */
53         const struct dcerpc_interface_table *ndr;
54
55         /* this function is called when the client binds to this interface  */
56         NTSTATUS (*bind)(struct dcesrv_call_state *, const struct dcesrv_interface *);
57
58         /* this function is called when the client disconnects the endpoint */
59         void (*unbind)(struct dcesrv_connection *, const struct dcesrv_interface *);
60
61         /* the dispatch function for the chosen interface.
62          */
63         dcesrv_dispatch_fn_t dispatch;
64 }; 
65
66 /* the state of an ongoing dcerpc call */
67 struct dcesrv_call_state {
68         struct dcesrv_call_state *next, *prev;
69         struct dcesrv_connection *conn;
70         struct dcerpc_packet pkt;
71
72         DATA_BLOB input;
73
74         struct dcesrv_call_reply {
75                 struct dcesrv_call_reply *next, *prev;
76                 DATA_BLOB data;
77         } *replies;
78
79         /* this is used by the boilerplate code to generate DCERPC faults */
80         uint32_t fault_code;
81 };
82
83 #define DCESRV_HANDLE_ANY 255
84
85 /* a dcerpc handle in internal format */
86 struct dcesrv_handle {
87         struct dcesrv_handle *next, *prev;
88         struct policy_handle wire_handle;
89         void *data;
90         void (*destroy)(struct dcesrv_connection *, struct dcesrv_handle *);
91 };
92
93 /* hold the authentication state information */
94 struct dcesrv_auth {
95         struct dcerpc_auth *auth_info;
96         struct gensec_security *gensec_security;
97         struct auth_session_info *session_info;
98         NTSTATUS (*session_key)(struct dcesrv_connection *, DATA_BLOB *session_key);
99 };
100
101
102 /* the state associated with a dcerpc server connection */
103 struct dcesrv_connection {
104         /* the top level context for this server */
105         struct dcesrv_context *dce_ctx;
106
107         /* the endpoint that was opened */
108         const struct dcesrv_endpoint *endpoint;
109
110         /* the ndr function table for the chosen interface */
111         const struct dcesrv_interface *iface;
112
113         /* the state of the current calls */
114         struct dcesrv_call_state *call_list;
115
116         /* the maximum size the client wants to receive */
117         uint32_t cli_max_recv_frag;
118
119         /* private data for the interface implementation */
120         void *private;
121
122         /* current rpc handles - this is really the wrong scope for
123            them, but it will do for now */
124         struct dcesrv_handle *handles;
125
126         DATA_BLOB partial_input;
127
128         /* the current authentication state */
129         struct dcesrv_auth auth_state;
130
131         struct server_connection *srv_conn;
132
133         /* the transport level session key */
134         DATA_BLOB transport_session_key;
135 };
136
137
138 struct dcesrv_endpoint_server {
139         /* this is the name of the endpoint server */
140         const char *name;
141
142         /* this function should register endpoints and some other setup stuff,
143          * it is called when the dcesrv_context gets initialized.
144          */
145         NTSTATUS (*init_server)(struct dcesrv_context *, const struct dcesrv_endpoint_server *);
146
147         /* this function can be used by other endpoint servers to
148          * ask for a dcesrv_interface implementation
149          * - iface must be referenz to an allready existent struct !
150          */
151         BOOL (*interface_by_uuid)(struct dcesrv_interface *iface, const char *, uint32_t);
152
153         /* this function can be used by other endpoint servers to
154          * ask for a dcesrv_interface implementation
155          * - iface must be referenz to an allready existent struct !
156          */
157         BOOL (*interface_by_name)(struct dcesrv_interface *iface, const char *);
158 };
159
160
161 /* server-wide context information for the dcerpc server */
162 struct dcesrv_context {
163         /* the list of endpoints that have registered 
164          * by the configured endpoint servers 
165          */
166         struct dcesrv_endpoint {
167                 struct dcesrv_endpoint *next, *prev;
168                 /* the type and location of the endpoint */
169                 struct dcesrv_ep_description ep_description;
170                 /* the security descriptor for smb named pipes */
171                 struct security_descriptor *sd;
172                 /* the list of interfaces available on this endpoint */
173                 struct dcesrv_if_list {
174                         struct dcesrv_if_list *next, *prev;
175                         struct dcesrv_interface iface;
176                 } *interface_list;
177         } *endpoint_list;
178 };
179
180 /* this structure is used by modules to determine the size of some critical types */
181 struct dcesrv_critical_sizes {
182         int interface_version;
183         int sizeof_dcesrv_context;
184         int sizeof_dcesrv_endpoint;
185         int sizeof_dcesrv_endpoint_server;
186         int sizeof_dcesrv_ep_description;
187         int sizeof_dcesrv_interface;
188         int sizeof_dcesrv_if_list;
189         int sizeof_dcesrv_connection;
190         int sizeof_dcesrv_call_state;
191         int sizeof_dcesrv_auth;
192         int sizeof_dcesrv_handle;
193 };
194
195 #endif /* SAMBA_DCERPC_SERVER_H */