s4:pyrpc: add py_dcerpc_ndr_pointer_deref/wrap() infrastructure
[garming/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 /* 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 struct ndr_interface_table;
40 struct resolve_context;
41
42 /*
43   this defines a generic security context for signed/sealed dcerpc pipes.
44 */
45 struct dcecli_connection;
46 struct gensec_settings;
47 struct cli_credentials;
48 struct dcecli_security {
49         enum dcerpc_AuthType auth_type;
50         enum dcerpc_AuthLevel auth_level;
51         uint32_t auth_context_id;
52         struct {
53                 struct dcerpc_auth *out;
54                 struct dcerpc_auth *in;
55                 TALLOC_CTX *mem;
56         } tmp_auth_info;
57         struct gensec_security *generic_state;
58
59         /* get the session key */
60         NTSTATUS (*session_key)(struct dcecli_connection *, DATA_BLOB *);
61
62         bool verified_bitmask1;
63
64 };
65
66 /*
67   this holds the information that is not specific to a particular rpc context_id
68 */
69 struct rpc_request;
70 struct dcecli_connection {
71         uint32_t call_id;
72         uint32_t srv_max_xmit_frag;
73         uint32_t srv_max_recv_frag;
74         uint32_t flags;
75         struct dcecli_security security_state;
76         struct tevent_context *event_ctx;
77
78         struct tevent_immediate *io_trigger;
79         bool io_trigger_pending;
80
81         /** Directory in which to save ndrdump-parseable files */
82         const char *packet_log_dir;
83
84         bool dead;
85         bool free_skipped;
86
87         struct dcerpc_transport {
88                 enum dcerpc_transport_t transport;
89                 void *private_data;
90
91                 struct tstream_context *stream;
92                 /** to serialize write events */
93                 struct tevent_queue *write_queue;
94                 /** the current active read request if any */
95                 struct tevent_req *read_subreq;
96                 /** number of read requests other than the current active */
97                 uint32_t pending_reads;
98         } transport;
99
100         const char *server_name;
101
102         /* Requests that have been sent, waiting for a reply */
103         struct rpc_request *pending;
104
105         /* Sync requests waiting to be shipped */
106         struct rpc_request *request_queue;
107
108         /* the next context_id to be assigned */
109         uint32_t next_context_id;
110
111         /* The maximum total payload of reassembled response pdus */
112         size_t max_total_response_size;
113
114         /* the negotiated bind time features */
115         uint16_t bind_time_features;
116 };
117
118 /*
119   this encapsulates a full dcerpc client side pipe 
120 */
121 struct dcerpc_pipe {
122         struct dcerpc_binding_handle *binding_handle;
123
124         uint32_t context_id;
125
126         struct GUID object;
127         struct ndr_syntax_id syntax;
128         struct ndr_syntax_id transfer_syntax;
129
130         struct dcecli_connection *conn;
131         const struct dcerpc_binding *binding;
132
133         /** the last fault code from a DCERPC fault */
134         uint32_t last_fault_code;
135
136         /** timeout for individual rpc requests, in seconds */
137         uint32_t request_timeout;
138
139         /*
140          * Set for the timeout in dcerpc_pipe_connect_b_send(), to
141          * allow the timeout not to destory the stack during a nested
142          * event loop caused by gensec_update()
143          */
144         bool inhibit_timeout_processing;
145         bool timed_out;
146
147         bool verified_pcontext;
148 };
149
150 /* default timeout for all rpc requests, in seconds */
151 #define DCERPC_REQUEST_TIMEOUT 60
152
153 struct epm_tower;
154 struct epm_floor;
155
156 struct smbcli_tree;
157 struct smb2_tree;
158 struct smbXcli_conn;
159 struct smbXcli_session;
160 struct smbXcli_tcon;
161 struct roh_connection;
162 struct tstream_tls_params;
163 struct socket_address;
164
165 NTSTATUS dcerpc_pipe_connect(TALLOC_CTX *parent_ctx, 
166                              struct dcerpc_pipe **pp, 
167                              const char *binding,
168                              const struct ndr_interface_table *table,
169                              struct cli_credentials *credentials,
170                              struct tevent_context *ev,
171                              struct loadparm_context *lp_ctx);
172 const char *dcerpc_server_name(struct dcerpc_pipe *p);
173 struct dcerpc_pipe *dcerpc_pipe_init(TALLOC_CTX *mem_ctx, struct tevent_context *ev);
174 NTSTATUS dcerpc_pipe_open_smb(struct dcerpc_pipe *p,
175                               struct smbcli_tree *tree,
176                               const char *pipe_name);
177 NTSTATUS dcerpc_pipe_open_smb2(struct dcerpc_pipe *p,
178                                struct smb2_tree *tree,
179                                const char *pipe_name);
180 NTSTATUS dcerpc_bind_auth_none(struct dcerpc_pipe *p,
181                                const struct ndr_interface_table *table);
182 NTSTATUS dcerpc_fetch_session_key(struct dcerpc_pipe *p,
183                                   DATA_BLOB *session_key);
184 struct composite_context;
185 NTSTATUS dcerpc_secondary_connection_recv(struct composite_context *c,
186                                           struct dcerpc_pipe **p2);
187
188 struct composite_context* dcerpc_pipe_connect_b_send(TALLOC_CTX *parent_ctx,
189                                                      const struct dcerpc_binding *binding,
190                                                      const struct ndr_interface_table *table,
191                                                      struct cli_credentials *credentials,
192                                                      struct tevent_context *ev,
193                                                      struct loadparm_context *lp_ctx);
194
195 NTSTATUS dcerpc_pipe_connect_b_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
196                                     struct dcerpc_pipe **p);
197
198 NTSTATUS dcerpc_pipe_connect_b(TALLOC_CTX *parent_ctx,
199                                struct dcerpc_pipe **pp,
200                                const struct dcerpc_binding *binding,
201                                const struct ndr_interface_table *table,
202                                struct cli_credentials *credentials,
203                                struct tevent_context *ev,
204                                struct loadparm_context *lp_ctx);
205
206 NTSTATUS dcerpc_pipe_auth(TALLOC_CTX *mem_ctx,
207                           struct dcerpc_pipe **p, 
208                           const struct dcerpc_binding *binding,
209                           const struct ndr_interface_table *table,
210                           struct cli_credentials *credentials,
211                           struct loadparm_context *lp_ctx);
212 NTSTATUS dcerpc_secondary_connection(struct dcerpc_pipe *p,
213                                      struct dcerpc_pipe **p2,
214                                      const struct dcerpc_binding *b);
215 NTSTATUS dcerpc_bind_auth_schannel(TALLOC_CTX *tmp_ctx, 
216                                    struct dcerpc_pipe *p,
217                                    const struct ndr_interface_table *table,
218                                    struct cli_credentials *credentials,
219                                    struct loadparm_context *lp_ctx,
220                                    uint8_t auth_level);
221 NTSTATUS dcerpc_init(void);
222 struct composite_context *dcerpc_secondary_smb_send(struct dcecli_connection *c1,
223                                                     struct dcecli_connection *c2,
224                                                     const char *pipe_name);
225 NTSTATUS dcerpc_secondary_smb_recv(struct composite_context *c);
226 NTSTATUS dcerpc_secondary_context(struct dcerpc_pipe *p, 
227                                   struct dcerpc_pipe **pp2,
228                                   const struct ndr_interface_table *table);
229 NTSTATUS dcerpc_alter_context(struct dcerpc_pipe *p, 
230                               TALLOC_CTX *mem_ctx,
231                               const struct ndr_syntax_id *syntax,
232                               const struct ndr_syntax_id *transfer_syntax);
233
234 NTSTATUS dcerpc_bind_auth(struct dcerpc_pipe *p,
235                           const struct ndr_interface_table *table,
236                           struct cli_credentials *credentials,
237                           struct gensec_settings *gensec_settings,
238                           uint8_t auth_type, uint8_t auth_level,
239                           const char *service);
240 struct composite_context* dcerpc_pipe_connect_send(TALLOC_CTX *parent_ctx,
241                                                    const char *binding,
242                                                    const struct ndr_interface_table *table,
243                                                    struct cli_credentials *credentials,
244                                                    struct tevent_context *ev, struct loadparm_context *lp_ctx);
245 NTSTATUS dcerpc_pipe_connect_recv(struct composite_context *c,
246                                   TALLOC_CTX *mem_ctx,
247                                   struct dcerpc_pipe **pp);
248
249 NTSTATUS dcerpc_epm_map_binding(TALLOC_CTX *mem_ctx, struct dcerpc_binding *binding,
250                                 const struct ndr_interface_table *table, struct tevent_context *ev,
251                                 struct loadparm_context *lp_ctx);
252 struct composite_context* dcerpc_secondary_auth_connection_send(struct dcerpc_pipe *p,
253                                                                 const struct dcerpc_binding *binding,
254                                                                 const struct ndr_interface_table *table,
255                                                                 struct cli_credentials *credentials,
256                                                                 struct loadparm_context *lp_ctx);
257 NTSTATUS dcerpc_secondary_auth_connection_recv(struct composite_context *c, 
258                                                TALLOC_CTX *mem_ctx,
259                                                struct dcerpc_pipe **p);
260 NTSTATUS dcerpc_secondary_auth_connection(struct dcerpc_pipe *p,
261                                         const struct dcerpc_binding *binding,
262                                         const struct ndr_interface_table *table,
263                                         struct cli_credentials *credentials,
264                                         struct loadparm_context *lp_ctx,
265                                         TALLOC_CTX *mem_ctx,
266                                         struct dcerpc_pipe **p2);
267
268 struct composite_context* dcerpc_secondary_connection_send(struct dcerpc_pipe *p,
269                                                            const struct dcerpc_binding *b);
270 void dcerpc_log_packet(const char *lockdir, 
271                        const struct ndr_interface_table *ndr,
272                        uint32_t opnum, uint32_t flags,
273                        const DATA_BLOB *pkt);
274
275 #endif /* __S4_DCERPC_H__ */