22f4b1e5941e0dcbdcecf3c111a2bb58b8b3c34d
[samba.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 /* This is a public header file that is installed as part of Samba. 
24  * If you remove any functions or change their signature, update 
25  * the so version number. */
26
27 #ifndef __S4_DCERPC_H__
28 #define __S4_DCERPC_H__
29
30 #include "../lib/util/data_blob.h"
31 #include "librpc/gen_ndr/dcerpc.h"
32 #include "../librpc/ndr/libndr.h"
33 #include "../librpc/rpc/rpc_common.h"
34
35 struct tevent_context;
36 struct tevent_req;
37 struct dcerpc_binding_handle;
38 struct tstream_context;
39
40 /*
41   this defines a generic security context for signed/sealed dcerpc pipes.
42 */
43 struct dcecli_connection;
44 struct gensec_settings;
45 struct dcecli_security {
46         struct dcerpc_auth *auth_info;
47         struct gensec_security *generic_state;
48
49         /* get the session key */
50         NTSTATUS (*session_key)(struct dcecli_connection *, DATA_BLOB *);
51 };
52
53 /*
54   this holds the information that is not specific to a particular rpc context_id
55 */
56 struct rpc_request;
57 struct dcecli_connection {
58         uint32_t call_id;
59         uint32_t srv_max_xmit_frag;
60         uint32_t srv_max_recv_frag;
61         uint32_t flags;
62         struct dcecli_security security_state;
63         const char *binding_string;
64         struct tevent_context *event_ctx;
65
66         /** Directory in which to save ndrdump-parseable files */
67         const char *packet_log_dir;
68
69         bool dead;
70         bool free_skipped;
71
72         struct dcerpc_transport {
73                 enum dcerpc_transport_t transport;
74                 void *private_data;
75
76                 NTSTATUS (*shutdown_pipe)(struct dcecli_connection *, NTSTATUS status);
77
78                 const char *(*peer_name)(struct dcecli_connection *);
79
80                 const char *(*target_hostname)(struct dcecli_connection *);
81
82                 /* send a request to the server */
83                 NTSTATUS (*send_request)(struct dcecli_connection *, DATA_BLOB *, bool trigger_read);
84
85                 /* send a read request to the server */
86                 NTSTATUS (*send_read)(struct dcecli_connection *);
87
88                 /* a callback to the dcerpc code when a full fragment
89                    has been received */
90                 void (*recv_data)(struct dcecli_connection *, DATA_BLOB *, NTSTATUS status);
91         } transport;
92
93         /* Requests that have been sent, waiting for a reply */
94         struct rpc_request *pending;
95
96         /* Sync requests waiting to be shipped */
97         struct rpc_request *request_queue;
98
99         /* the next context_id to be assigned */
100         uint32_t next_context_id;
101 };
102
103 /*
104   this encapsulates a full dcerpc client side pipe 
105 */
106 struct dcerpc_pipe {
107         struct dcerpc_binding_handle *binding_handle;
108
109         uint32_t context_id;
110
111         uint32_t assoc_group_id;
112
113         struct ndr_syntax_id syntax;
114         struct ndr_syntax_id transfer_syntax;
115
116         struct dcecli_connection *conn;
117         struct dcerpc_binding *binding;
118
119         /** the last fault code from a DCERPC fault */
120         uint32_t last_fault_code;
121
122         /** timeout for individual rpc requests, in seconds */
123         uint32_t request_timeout;
124 };
125
126 /* default timeout for all rpc requests, in seconds */
127 #define DCERPC_REQUEST_TIMEOUT 60
128
129
130 /* dcerpc pipe flags */
131 #define DCERPC_DEBUG_PRINT_IN          (1<<0)
132 #define DCERPC_DEBUG_PRINT_OUT         (1<<1)
133 #define DCERPC_DEBUG_PRINT_BOTH (DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT)
134
135 #define DCERPC_DEBUG_VALIDATE_IN       (1<<2)
136 #define DCERPC_DEBUG_VALIDATE_OUT      (1<<3)
137 #define DCERPC_DEBUG_VALIDATE_BOTH (DCERPC_DEBUG_VALIDATE_IN | DCERPC_DEBUG_VALIDATE_OUT)
138
139 #define DCERPC_CONNECT                 (1<<4)
140 #define DCERPC_SIGN                    (1<<5)
141 #define DCERPC_SEAL                    (1<<6)
142
143 #define DCERPC_PUSH_BIGENDIAN          (1<<7)
144 #define DCERPC_PULL_BIGENDIAN          (1<<8)
145
146 #define DCERPC_SCHANNEL                (1<<9)
147
148 #define DCERPC_ANON_FALLBACK           (1<<10)
149
150 /* use a 128 bit session key */
151 #define DCERPC_SCHANNEL_128            (1<<12)
152
153 /* check incoming pad bytes */
154 #define DCERPC_DEBUG_PAD_CHECK         (1<<13)
155
156 /* set LIBNDR_FLAG_REF_ALLOC flag when decoding NDR */
157 #define DCERPC_NDR_REF_ALLOC           (1<<14)
158
159 #define DCERPC_AUTH_OPTIONS    (DCERPC_SEAL|DCERPC_SIGN|DCERPC_SCHANNEL|DCERPC_AUTH_SPNEGO|DCERPC_AUTH_KRB5|DCERPC_AUTH_NTLM)
160
161 /* select spnego auth */
162 #define DCERPC_AUTH_SPNEGO             (1<<15)
163
164 /* select krb5 auth */
165 #define DCERPC_AUTH_KRB5               (1<<16)
166
167 #define DCERPC_SMB2                    (1<<17)
168
169 /* select NTLM auth */
170 #define DCERPC_AUTH_NTLM               (1<<18)
171
172 /* this triggers the DCERPC_PFC_FLAG_CONC_MPX flag in the bind request */
173 #define DCERPC_CONCURRENT_MULTIPLEX     (1<<19)
174
175 /* this triggers the DCERPC_PFC_FLAG_SUPPORT_HEADER_SIGN flag in the bind request */
176 #define DCERPC_HEADER_SIGNING          (1<<20)
177
178 /* use NDR64 transport */
179 #define DCERPC_NDR64                   (1<<21)
180
181 /* specify binding interface */
182 #define DCERPC_LOCALADDRESS            (1<<22)
183
184 struct dcerpc_pipe_connect {
185         struct dcerpc_pipe *pipe;
186         struct dcerpc_binding *binding;
187         const char *pipe_name;
188         const struct ndr_interface_table *interface;
189         struct cli_credentials *creds;
190         struct resolve_context *resolve_ctx;
191 };
192
193
194 struct epm_tower;
195 struct epm_floor;
196
197 struct smbcli_tree;
198 struct smb2_tree;
199 struct socket_address;
200
201 NTSTATUS dcerpc_pipe_connect(TALLOC_CTX *parent_ctx, 
202                              struct dcerpc_pipe **pp, 
203                              const char *binding,
204                              const struct ndr_interface_table *table,
205                              struct cli_credentials *credentials,
206                              struct tevent_context *ev,
207                              struct loadparm_context *lp_ctx);
208 const char *dcerpc_server_name(struct dcerpc_pipe *p);
209 struct dcerpc_pipe *dcerpc_pipe_init(TALLOC_CTX *mem_ctx, struct tevent_context *ev);
210 NTSTATUS dcerpc_pipe_open_smb(struct dcerpc_pipe *p,
211                               struct smbcli_tree *tree,
212                               const char *pipe_name);
213 NTSTATUS dcerpc_bind_auth_none(struct dcerpc_pipe *p,
214                                const struct ndr_interface_table *table);
215 NTSTATUS dcerpc_fetch_session_key(struct dcerpc_pipe *p,
216                                   DATA_BLOB *session_key);
217 struct composite_context;
218 NTSTATUS dcerpc_secondary_connection_recv(struct composite_context *c,
219                                           struct dcerpc_pipe **p2);
220 NTSTATUS dcerpc_parse_binding(TALLOC_CTX *mem_ctx, const char *s, struct dcerpc_binding **b_out);
221
222 struct composite_context* dcerpc_pipe_connect_b_send(TALLOC_CTX *parent_ctx,
223                                                      struct dcerpc_binding *binding,
224                                                      const struct ndr_interface_table *table,
225                                                      struct cli_credentials *credentials,
226                                                      struct tevent_context *ev,
227                                                      struct loadparm_context *lp_ctx);
228
229 NTSTATUS dcerpc_pipe_connect_b_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
230                                     struct dcerpc_pipe **p);
231
232 NTSTATUS dcerpc_pipe_connect_b(TALLOC_CTX *parent_ctx,
233                                struct dcerpc_pipe **pp,
234                                struct dcerpc_binding *binding,
235                                const struct ndr_interface_table *table,
236                                struct cli_credentials *credentials,
237                                struct tevent_context *ev,
238                                struct loadparm_context *lp_ctx);
239
240 NTSTATUS dcerpc_pipe_auth(TALLOC_CTX *mem_ctx,
241                           struct dcerpc_pipe **p, 
242                           struct dcerpc_binding *binding,
243                           const struct ndr_interface_table *table,
244                           struct cli_credentials *credentials,
245                           struct loadparm_context *lp_ctx);
246 char *dcerpc_binding_string(TALLOC_CTX *mem_ctx, const struct dcerpc_binding *b);
247 NTSTATUS dcerpc_secondary_connection(struct dcerpc_pipe *p,
248                                      struct dcerpc_pipe **p2,
249                                      struct dcerpc_binding *b);
250 NTSTATUS dcerpc_bind_auth_schannel(TALLOC_CTX *tmp_ctx, 
251                                    struct dcerpc_pipe *p,
252                                    const struct ndr_interface_table *table,
253                                    struct cli_credentials *credentials,
254                                    struct loadparm_context *lp_ctx,
255                                    uint8_t auth_level);
256 struct tevent_context *dcerpc_event_context(struct dcerpc_pipe *p);
257 NTSTATUS dcerpc_init(struct loadparm_context *lp_ctx);
258 struct smbcli_tree *dcerpc_smb_tree(struct dcecli_connection *c);
259 uint16_t dcerpc_smb_fnum(struct dcecli_connection *c);
260 NTSTATUS dcerpc_secondary_context(struct dcerpc_pipe *p, 
261                                   struct dcerpc_pipe **pp2,
262                                   const struct ndr_interface_table *table);
263 NTSTATUS dcerpc_alter_context(struct dcerpc_pipe *p, 
264                               TALLOC_CTX *mem_ctx,
265                               const struct ndr_syntax_id *syntax,
266                               const struct ndr_syntax_id *transfer_syntax);
267
268 NTSTATUS dcerpc_bind_auth(struct dcerpc_pipe *p,
269                           const struct ndr_interface_table *table,
270                           struct cli_credentials *credentials,
271                           struct gensec_settings *gensec_settings,
272                           uint8_t auth_type, uint8_t auth_level,
273                           const char *service);
274 struct composite_context* dcerpc_pipe_connect_send(TALLOC_CTX *parent_ctx,
275                                                    const char *binding,
276                                                    const struct ndr_interface_table *table,
277                                                    struct cli_credentials *credentials,
278                                                    struct tevent_context *ev, struct loadparm_context *lp_ctx);
279 NTSTATUS dcerpc_pipe_connect_recv(struct composite_context *c,
280                                   TALLOC_CTX *mem_ctx,
281                                   struct dcerpc_pipe **pp);
282
283 NTSTATUS dcerpc_epm_map_binding(TALLOC_CTX *mem_ctx, struct dcerpc_binding *binding,
284                                 const struct ndr_interface_table *table, struct tevent_context *ev,
285                                 struct loadparm_context *lp_ctx);
286 struct composite_context* dcerpc_secondary_auth_connection_send(struct dcerpc_pipe *p,
287                                                                 struct dcerpc_binding *binding,
288                                                                 const struct ndr_interface_table *table,
289                                                                 struct cli_credentials *credentials,
290                                                                 struct loadparm_context *lp_ctx);
291 NTSTATUS dcerpc_secondary_auth_connection_recv(struct composite_context *c, 
292                                                TALLOC_CTX *mem_ctx,
293                                                struct dcerpc_pipe **p);
294
295 struct composite_context* dcerpc_secondary_connection_send(struct dcerpc_pipe *p,
296                                                            struct dcerpc_binding *b);
297 void dcerpc_log_packet(const char *lockdir, 
298                        const struct ndr_interface_table *ndr,
299                        uint32_t opnum, uint32_t flags,
300                        const DATA_BLOB *pkt);
301 NTSTATUS dcerpc_binding_build_tower(TALLOC_CTX *mem_ctx,
302                                     const struct dcerpc_binding *binding,
303                                     struct epm_tower *tower);
304
305 NTSTATUS dcerpc_floor_get_lhs_data(const struct epm_floor *epm_floor, struct ndr_syntax_id *syntax);
306
307 enum dcerpc_transport_t dcerpc_transport_by_tower(const struct epm_tower *tower);
308 const char *derpc_transport_string_by_transport(enum dcerpc_transport_t t);
309
310 NTSTATUS dcerpc_binding_from_tower(TALLOC_CTX *mem_ctx, 
311                                    struct epm_tower *tower, 
312                                    struct dcerpc_binding **b_out);
313
314 enum dcerpc_transport_t dcerpc_transport_by_endpoint_protocol(int prot);
315
316 const char *dcerpc_floor_get_rhs_data(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor);
317
318 #endif /* __S4_DCERPC_H__ */