dcerpc over tcp in the samba4 server now works to some extent. It
[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    
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         struct dcesrv_call_reply {
57                 struct dcesrv_call_reply *next, *prev;
58                 DATA_BLOB data;
59         } *replies;
60 };
61
62
63 /* a dcerpc handle in internal format */
64 struct dcesrv_handle {
65         struct dcesrv_handle *next, *prev;
66         struct policy_handle wire_handle;
67         TALLOC_CTX *mem_ctx;
68         void *data;
69 };
70
71 /* the state associated with a dcerpc server connection */
72 struct dcesrv_state {
73         /* the top level context for this server */
74         struct dcesrv_context *dce;
75
76         TALLOC_CTX *mem_ctx;
77
78         /* the endpoint that was opened */
79         struct dcesrv_endpoint endpoint;
80
81         /* endpoint operations provided by the endpoint server */
82         const struct dcesrv_endpoint_ops *ops;
83
84         /* the ndr function table for the chosen interface */
85         const struct dcerpc_interface_table *ndr;
86
87         /* the dispatch table for the chosen interface. Must contain
88            enough entries for all entries in the ndr table */
89         const dcesrv_dispatch_fn_t *dispatch;
90
91         /* the state of the current calls */
92         struct dcesrv_call_state *call_list;
93
94         /* the maximum size the client wants to receive */
95         uint32 cli_max_recv_frag;
96
97         /* private data for the endpoint server */
98         void *private;
99
100         /* current rpc handles - this is really the wrong scope for
101            them, but it will do for now */
102         uint32 next_handle;
103         struct dcesrv_handle *handles;
104 };
105
106
107 struct dcesrv_endpoint_ops {
108         /* this function is used to ask an endpoint server if it
109            handles a particular endpoint */
110         BOOL (*query_endpoint)(const struct dcesrv_endpoint *);
111
112         /* this function sets up the dispatch table for this
113            connection */
114         BOOL (*set_interface)(struct dcesrv_state *, const char *, uint32);
115
116         /* connect() is called when a connection is made to an endpoint */
117         NTSTATUS (*connect)(struct dcesrv_state *);
118
119         /* disconnect() is called when the endpoint is disconnected */
120         void (*disconnect)(struct dcesrv_state *);
121
122         /* this function is used to ask an endpoint server for a list
123            of endpoints/interfaces it wants to handle */
124         int (*lookup_endpoints)(TALLOC_CTX *mem_ctx, struct dcesrv_ep_iface **);
125 };
126
127
128 /* server-wide context information for the dcerpc server */
129 struct dcesrv_context {
130         
131         /* the list of endpoints servers that have registered */
132         struct dce_endpoint {
133                 struct dce_endpoint *next, *prev;
134                 const struct dcesrv_endpoint_ops *endpoint_ops;
135         } *endpoint_list;
136 };