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