r24540: rename struct dcerpc_endpoint_list/struct dcerpc_authservice_list
[sfrench/samba-autobuild/.git] / source4 / librpc / rpc / dcerpc.h
1 /* 
2    Unix SMB/CIFS implementation.
3
4    DCERPC client side interface structures
5
6    Copyright (C) Tim Potter 2003
7    Copyright (C) Andrew Tridgell 2003-2005
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 3 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, see <http://www.gnu.org/licenses/>.
21 */
22
23 #ifndef __DCERPC_H__
24 #define __DCERPC_H__
25
26 #include "core.h"
27 #include "librpc/gen_ndr/dcerpc.h"
28 #include "librpc/ndr/libndr.h"
29
30 enum dcerpc_transport_t {
31         NCACN_NP, NCACN_IP_TCP, NCACN_IP_UDP, NCACN_VNS_IPC, NCACN_VNS_SPP, 
32         NCACN_AT_DSP, NCADG_AT_DDP, NCALRPC, NCACN_UNIX_STREAM, NCADG_UNIX_DGRAM,
33         NCACN_HTTP, NCADG_IPX, NCACN_SPX };
34
35 /*
36   this defines a generic security context for signed/sealed dcerpc pipes.
37 */
38 struct dcerpc_connection;
39 struct dcerpc_security {
40         struct dcerpc_auth *auth_info;
41         struct gensec_security *generic_state;
42
43         /* get the session key */
44         NTSTATUS (*session_key)(struct dcerpc_connection *, DATA_BLOB *);
45 };
46
47 /*
48   this holds the information that is not specific to a particular rpc context_id
49 */
50 struct dcerpc_connection {
51         uint32_t call_id;
52         uint32_t srv_max_xmit_frag;
53         uint32_t srv_max_recv_frag;
54         uint32_t flags;
55         struct dcerpc_security security_state;
56         const char *binding_string;
57         struct event_context *event_ctx;
58
59         bool dead;
60         bool free_skipped;
61
62         struct dcerpc_transport {
63                 enum dcerpc_transport_t transport;
64                 void *private_data;
65
66                 NTSTATUS (*shutdown_pipe)(struct dcerpc_connection *, NTSTATUS status);
67
68                 const char *(*peer_name)(struct dcerpc_connection *);
69
70                 const char *(*target_hostname)(struct dcerpc_connection *);
71
72                 /* send a request to the server */
73                 NTSTATUS (*send_request)(struct dcerpc_connection *, DATA_BLOB *, BOOL trigger_read);
74
75                 /* send a read request to the server */
76                 NTSTATUS (*send_read)(struct dcerpc_connection *);
77
78                 /* a callback to the dcerpc code when a full fragment
79                    has been received */
80                 void (*recv_data)(struct dcerpc_connection *, DATA_BLOB *, NTSTATUS status);
81         } transport;
82
83         /* Requests that have been sent, waiting for a reply */
84         struct rpc_request *pending;
85
86         /* Sync requests waiting to be shipped */
87         struct rpc_request *request_queue;
88
89         /* the next context_id to be assigned */
90         uint32_t next_context_id;
91 };
92
93 /*
94   this encapsulates a full dcerpc client side pipe 
95 */
96 struct dcerpc_pipe {
97         uint32_t context_id;
98
99         uint32_t assoc_group_id;
100
101         struct ndr_syntax_id syntax;
102         struct ndr_syntax_id transfer_syntax;
103
104         struct dcerpc_connection *conn;
105         struct dcerpc_binding *binding;
106
107         /* the last fault code from a DCERPC fault */
108         uint32_t last_fault_code;
109
110         /* timeout for individual rpc requests, in seconds */
111         uint32_t request_timeout;
112 };
113
114 /* default timeout for all rpc requests, in seconds */
115 #define DCERPC_REQUEST_TIMEOUT 60
116
117
118 /* dcerpc pipe flags */
119 #define DCERPC_DEBUG_PRINT_IN          (1<<0)
120 #define DCERPC_DEBUG_PRINT_OUT         (1<<1)
121 #define DCERPC_DEBUG_PRINT_BOTH (DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT)
122
123 #define DCERPC_DEBUG_VALIDATE_IN       (1<<2)
124 #define DCERPC_DEBUG_VALIDATE_OUT      (1<<3)
125 #define DCERPC_DEBUG_VALIDATE_BOTH (DCERPC_DEBUG_VALIDATE_IN | DCERPC_DEBUG_VALIDATE_OUT)
126
127 #define DCERPC_CONNECT                 (1<<4)
128 #define DCERPC_SIGN                    (1<<5)
129 #define DCERPC_SEAL                    (1<<6)
130
131 #define DCERPC_PUSH_BIGENDIAN          (1<<7)
132 #define DCERPC_PULL_BIGENDIAN          (1<<8)
133
134 #define DCERPC_SCHANNEL                (1<<9)
135
136 /* use a 128 bit session key */
137 #define DCERPC_SCHANNEL_128            (1<<12)
138
139 /* check incoming pad bytes */
140 #define DCERPC_DEBUG_PAD_CHECK         (1<<13)
141
142 /* set LIBNDR_FLAG_REF_ALLOC flag when decoding NDR */
143 #define DCERPC_NDR_REF_ALLOC           (1<<14)
144
145 #define DCERPC_AUTH_OPTIONS    (DCERPC_SEAL|DCERPC_SIGN|DCERPC_SCHANNEL|DCERPC_AUTH_SPNEGO|DCERPC_AUTH_KRB5|DCERPC_AUTH_NTLM)
146
147 /* select spnego auth */
148 #define DCERPC_AUTH_SPNEGO             (1<<15)
149
150 /* select krb5 auth */
151 #define DCERPC_AUTH_KRB5               (1<<16)
152
153 #define DCERPC_SMB2                    (1<<17)
154
155 /* select NTLM auth */
156 #define DCERPC_AUTH_NTLM               (1<<18)
157
158 /* this triggers the DCERPC_PFC_FLAG_CONC_MPX flag in the bind request */
159 #define DCERPC_CONCURRENT_MULTIPLEX     (1<<19)
160
161 struct dcerpc_interface_table {
162         const char *name;
163         struct ndr_syntax_id syntax_id;
164         const char *helpstring;
165         uint32_t num_calls;
166         const struct ndr_interface_call *calls;
167         const struct ndr_interface_string_array *endpoints;
168         const struct ndr_interface_string_array *authservices;
169 };
170
171 struct dcerpc_interface_list {
172         struct dcerpc_interface_list *prev, *next;
173         const struct dcerpc_interface_table *table;
174 };
175
176 /* this describes a binding to a particular transport/pipe */
177 struct dcerpc_binding {
178         enum dcerpc_transport_t transport;
179         struct ndr_syntax_id object;
180         const char *host;
181         const char *target_hostname;
182         const char *endpoint;
183         const char **options;
184         uint32_t flags;
185         uint32_t assoc_group_id;
186 };
187
188
189 struct dcerpc_pipe_connect {
190         struct dcerpc_pipe *pipe;
191         struct dcerpc_binding *binding;
192         const char *pipe_name;
193         const struct dcerpc_interface_table *interface;
194         struct cli_credentials *creds;
195 };
196
197
198 enum rpc_request_state {
199         RPC_REQUEST_QUEUED,
200         RPC_REQUEST_PENDING,
201         RPC_REQUEST_DONE
202 };
203
204 /*
205   handle for an async dcerpc request
206 */
207 struct rpc_request {
208         struct rpc_request *next, *prev;
209         struct dcerpc_pipe *p;
210         NTSTATUS status;
211         uint32_t call_id;
212         enum rpc_request_state state;
213         DATA_BLOB payload;
214         uint32_t flags;
215         uint32_t fault_code;
216
217         /* this is used to distinguish bind and alter_context requests
218            from normal requests */
219         void (*recv_handler)(struct rpc_request *conn, 
220                              DATA_BLOB *blob, struct ncacn_packet *pkt);
221
222         const struct GUID *object;
223         uint16_t opnum;
224         DATA_BLOB request_data;
225         BOOL async_call;
226         BOOL ignore_timeout;
227
228         /* use by the ndr level async recv call */
229         struct {
230                 const struct dcerpc_interface_table *table;
231                 uint32_t opnum;
232                 void *struct_ptr;
233                 TALLOC_CTX *mem_ctx;
234         } ndr;
235
236         struct {
237                 void (*callback)(struct rpc_request *);
238                 void *private_data;
239         } async;
240 };
241
242 struct epm_tower;
243 struct epm_floor;
244
245 struct smbcli_tree;
246 struct smb2_tree;
247 struct socket_address;
248
249 #include "librpc/rpc/dcerpc_proto.h"
250
251 #endif /* __DCERPC_H__ */