completed the linkage between the endpoint mapper and the dcerpc
[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    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23
24 enum endpoint_type {ENDPOINT_SMB, ENDPOINT_TCP};
25
26 /* a description of a single dcerpc endpoint. Not as flexible as a full epm tower,
27    but much easier to work with */
28 struct dcesrv_endpoint {
29         enum endpoint_type type;
30         union {
31                 const char *smb_pipe;
32                 uint32 tcp_port;
33         } info;
34 };
35
36 /* a endpoint combined with an interface description */
37 struct dcesrv_ep_iface {
38         const char *name;
39         struct dcesrv_endpoint endpoint;
40         const char *uuid;
41         uint32 if_version;
42 };
43
44 struct dcesrv_state;
45
46 /* the dispatch functions for an interface take this form */
47 typedef NTSTATUS (*dcesrv_dispatch_fn_t)(struct dcesrv_state *, TALLOC_CTX *, void *); 
48
49 /* the state of an ongoing dcerpc call */
50 struct dcesrv_call_state {
51         struct dcesrv_call_state *next, *prev;
52         struct dcesrv_state *dce;
53         TALLOC_CTX *mem_ctx;
54         struct dcerpc_packet pkt;
55
56         DATA_BLOB input;
57
58         struct dcesrv_call_reply {
59                 struct dcesrv_call_reply *next, *prev;
60                 DATA_BLOB data;
61         } *replies;
62 };
63
64
65 /* a dcerpc handle in internal format */
66 struct dcesrv_handle {
67         struct dcesrv_handle *next, *prev;
68         struct policy_handle wire_handle;
69         TALLOC_CTX *mem_ctx;
70         void *data;
71 };
72
73 /* the state associated with a dcerpc server connection */
74 struct dcesrv_state {
75         /* the top level context for this server */
76         struct dcesrv_context *dce;
77
78         TALLOC_CTX *mem_ctx;
79
80         /* the endpoint that was opened */
81         struct dcesrv_endpoint endpoint;
82
83         /* endpoint operations provided by the endpoint server */
84         const struct dcesrv_endpoint_ops *ops;
85
86         /* the ndr function table for the chosen interface */
87         const struct dcerpc_interface_table *ndr;
88
89         /* the dispatch table for the chosen interface. Must contain
90            enough entries for all entries in the ndr table */
91         const dcesrv_dispatch_fn_t *dispatch;
92
93         /* the state of the current calls */
94         struct dcesrv_call_state *call_list;
95
96         /* the maximum size the client wants to receive */
97         uint32 cli_max_recv_frag;
98
99         /* private data for the endpoint server */
100         void *private;
101
102         /* current rpc handles - this is really the wrong scope for
103            them, but it will do for now */
104         uint32 next_handle;
105         struct dcesrv_handle *handles;
106
107         DATA_BLOB partial_input;
108 };
109
110
111 struct dcesrv_endpoint_ops {
112         /* this function is used to ask an endpoint server if it
113            handles a particular endpoint */
114         BOOL (*query_endpoint)(const struct dcesrv_endpoint *);
115
116         /* this function sets up the dispatch table for this
117            connection */
118         BOOL (*set_interface)(struct dcesrv_state *, const char *, uint32);
119
120         /* connect() is called when a connection is made to an endpoint */
121         NTSTATUS (*connect)(struct dcesrv_state *);
122
123         /* disconnect() is called when the endpoint is disconnected */
124         void (*disconnect)(struct dcesrv_state *);
125
126         /* this function is used to ask an endpoint server for a list
127            of endpoints/interfaces it wants to handle */
128         int (*lookup_endpoints)(TALLOC_CTX *mem_ctx, struct dcesrv_ep_iface **);
129 };
130
131
132 /* server-wide context information for the dcerpc server */
133 struct dcesrv_context {
134         
135         /* the list of endpoints servers that have registered */
136         struct dce_endpoint {
137                 struct dce_endpoint *next, *prev;
138                 struct dcesrv_endpoint endpoint;
139                 const struct dcesrv_endpoint_ops *endpoint_ops;
140         } *endpoint_list;
141 };