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