librpc/rpc: add dcerpc_binding_handle_call_params*
[metze/samba/wip.git] / librpc / rpc / rpc_common.h
1 /*
2    Unix SMB/CIFS implementation.
3
4    Copyright (C) Stefan Metzmacher 2010-2011
5    Copyright (C) Andrew Tridgell 2010-2011
6    Copyright (C) Simo Sorce 2010
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 3 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, see <http://www.gnu.org/licenses/>.
20 */
21
22 #ifndef __DEFAULT_LIBRPC_RPCCOMMON_H__
23 #define __DEFAULT_LIBRPC_RPCCOMMON_H__
24
25 #include "gen_ndr/dcerpc.h"
26 #include "lib/util/attr.h"
27
28 struct dcerpc_binding_handle;
29 struct dcerpc_pipe_handle;
30 struct dcerpc_pipe_handle_connection;
31 struct GUID;
32 struct ndr_interface_table;
33 struct ndr_interface_call;
34 struct ndr_push;
35 struct ndr_pull;
36 struct ncacn_packet;
37 struct epm_floor;
38 struct epm_tower;
39 struct tevent_context;
40 struct tstream_context;
41 struct gensec_security;
42
43 enum dcerpc_transport_t {
44         NCA_UNKNOWN, NCACN_NP, NCACN_IP_TCP, NCACN_IP_UDP, NCACN_VNS_IPC, 
45         NCACN_VNS_SPP, NCACN_AT_DSP, NCADG_AT_DDP, NCALRPC, NCACN_UNIX_STREAM, 
46         NCADG_UNIX_DGRAM, NCACN_HTTP, NCADG_IPX, NCACN_SPX, NCACN_INTERNAL };
47
48 /** this describes a binding to a particular transport/pipe */
49 struct dcerpc_binding;
50
51 /* dcerpc pipe flags */
52 #define DCERPC_DEBUG_PRINT_IN          (1<<0)
53 #define DCERPC_DEBUG_PRINT_OUT         (1<<1)
54 #define DCERPC_DEBUG_PRINT_BOTH (DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT)
55
56 #define DCERPC_DEBUG_VALIDATE_IN       (1<<2)
57 #define DCERPC_DEBUG_VALIDATE_OUT      (1<<3)
58 #define DCERPC_DEBUG_VALIDATE_BOTH (DCERPC_DEBUG_VALIDATE_IN | DCERPC_DEBUG_VALIDATE_OUT)
59
60 #define DCERPC_CONNECT                 (1<<4)
61 #define DCERPC_SIGN                    (1<<5)
62 #define DCERPC_SEAL                    (1<<6)
63
64 #define DCERPC_PUSH_BIGENDIAN          (1<<7)
65 #define DCERPC_PULL_BIGENDIAN          (1<<8)
66
67 #define DCERPC_SCHANNEL                (1<<9)
68
69 #define DCERPC_ANON_FALLBACK           (1<<10)
70
71 /* use a 128 bit session key */
72 #define DCERPC_SCHANNEL_128            (1<<12)
73
74 /* check incoming pad bytes */
75 #define DCERPC_DEBUG_PAD_CHECK         (1<<13)
76
77 /* set LIBNDR_FLAG_REF_ALLOC flag when decoding NDR */
78 #define DCERPC_NDR_REF_ALLOC           (1<<14)
79
80 #define DCERPC_AUTH_OPTIONS    (DCERPC_SEAL|DCERPC_SIGN|DCERPC_SCHANNEL|DCERPC_AUTH_SPNEGO|DCERPC_AUTH_KRB5|DCERPC_AUTH_NTLM)
81
82 /* select spnego auth */
83 #define DCERPC_AUTH_SPNEGO             (1<<15)
84
85 /* select krb5 auth */
86 #define DCERPC_AUTH_KRB5               (1<<16)
87
88 #define DCERPC_SMB2                    (1<<17)
89
90 /* select NTLM auth */
91 #define DCERPC_AUTH_NTLM               (1<<18)
92
93 /* this triggers the DCERPC_PFC_FLAG_CONC_MPX flag in the bind request */
94 #define DCERPC_CONCURRENT_MULTIPLEX     (1<<19)
95
96 /* this indicates DCERPC_PFC_FLAG_SUPPORT_HEADER_SIGN flag was negotiated */
97 #define DCERPC_HEADER_SIGNING          (1<<20)
98
99 /* use NDR64 transport */
100 #define DCERPC_NDR64                   (1<<21)
101
102 /* handle upgrades or downgrades automatically */
103 #define DCERPC_SCHANNEL_AUTO           (1<<23)
104
105 /* use aes schannel with hmac-sh256 session key */
106 #define DCERPC_SCHANNEL_AES            (1<<24)
107
108 /* this triggers the DCERPC_PFC_FLAG_SUPPORT_HEADER_SIGN flag in the bind request */
109 #define DCERPC_PROPOSE_HEADER_SIGNING          (1<<25)
110
111 #define DCERPC_PACKET                   (1<<26)
112
113 #define DCERPC_SMB1                    (1<<27)
114
115 /* The following definitions come from ../librpc/rpc/dcerpc_error.c  */
116
117 const char *dcerpc_errstr(TALLOC_CTX *mem_ctx, uint32_t fault_code);
118 NTSTATUS dcerpc_fault_to_nt_status(uint32_t fault_code);
119 uint32_t dcerpc_fault_from_nt_status(NTSTATUS nt_status);
120
121 /* The following definitions come from ../librpc/rpc/binding.c  */
122
123 const char *epm_floor_string(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor);
124 char *dcerpc_floor_get_rhs_data(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor);
125 enum dcerpc_transport_t dcerpc_transport_by_endpoint_protocol(int prot);
126 struct dcerpc_binding *dcerpc_binding_dup(TALLOC_CTX *mem_ctx,
127                                           const struct dcerpc_binding *b);
128 NTSTATUS dcerpc_binding_build_tower(TALLOC_CTX *mem_ctx,
129                                     const struct dcerpc_binding *binding,
130                                     struct epm_tower *tower);
131 NTSTATUS dcerpc_binding_from_tower(TALLOC_CTX *mem_ctx,
132                                    struct epm_tower *tower,
133                                    struct dcerpc_binding **b_out);
134 NTSTATUS dcerpc_parse_binding(TALLOC_CTX *mem_ctx, const char *s, struct dcerpc_binding **b_out);
135 char *dcerpc_binding_string(TALLOC_CTX *mem_ctx, const struct dcerpc_binding *b);
136 struct GUID dcerpc_binding_get_object(const struct dcerpc_binding *b);
137 NTSTATUS dcerpc_binding_set_object(struct dcerpc_binding *b,
138                                    struct GUID object);
139 enum dcerpc_transport_t dcerpc_binding_get_transport(const struct dcerpc_binding *b);
140 NTSTATUS dcerpc_binding_set_transport(struct dcerpc_binding *b,
141                                       enum dcerpc_transport_t transport);
142 void dcerpc_binding_get_auth_info(const struct dcerpc_binding *b,
143                                   enum dcerpc_AuthType *_auth_type,
144                                   enum dcerpc_AuthLevel *_auth_level);
145 uint32_t dcerpc_binding_get_assoc_group_id(const struct dcerpc_binding *b);
146 NTSTATUS dcerpc_binding_set_assoc_group_id(struct dcerpc_binding *b,
147                                            uint32_t assoc_group_id);
148 struct ndr_syntax_id dcerpc_binding_get_abstract_syntax(const struct dcerpc_binding *b);
149 NTSTATUS dcerpc_binding_set_abstract_syntax(struct dcerpc_binding *b,
150                                             const struct ndr_syntax_id *syntax);
151 const char *dcerpc_binding_get_string_option(const struct dcerpc_binding *b,
152                                              const char *name);
153 char *dcerpc_binding_copy_string_option(TALLOC_CTX *mem_ctx,
154                                         const struct dcerpc_binding *b,
155                                         const char *name);
156 NTSTATUS dcerpc_binding_set_string_option(struct dcerpc_binding *b,
157                                           const char *name,
158                                           const char *value);
159 void *_dcerpc_binding_get_pointer_option(const struct dcerpc_binding *b,
160                                          const char *name,
161                                          const char *type);
162 #define dcerpc_binding_get_pointer_option(b, name, type) \
163         talloc_get_type(_dcerpc_binding_get_pointer_option(b, name, #type), type)
164 NTSTATUS _dcerpc_binding_set_pointer_option(struct dcerpc_binding *b,
165                                             const char *name,
166                                             const char *type,
167                                             const void *vp);
168 #define dcerpc_binding_set_pointer_option(b, name, type, vp) \
169         _dcerpc_binding_set_pointer_option(b, name, #type, vp)
170 uint32_t dcerpc_binding_get_flags(const struct dcerpc_binding *b);
171 NTSTATUS dcerpc_binding_set_flags(struct dcerpc_binding *b,
172                                   uint32_t additional,
173                                   uint32_t clear);
174 NTSTATUS dcerpc_floor_get_lhs_data(const struct epm_floor *epm_floor, struct ndr_syntax_id *syntax);
175 const char *derpc_transport_string_by_transport(enum dcerpc_transport_t t);
176 enum dcerpc_transport_t dcerpc_transport_by_name(const char *name);
177 enum dcerpc_transport_t dcerpc_transport_by_tower(const struct epm_tower *tower);
178
179 /* The following definitions come from ../librpc/rpc/dcerpc_util.c  */
180
181 void dcerpc_set_frag_length(DATA_BLOB *blob, uint16_t v);
182 uint16_t dcerpc_get_frag_length(const DATA_BLOB *blob);
183 void dcerpc_set_auth_length(DATA_BLOB *blob, uint16_t v);
184 uint16_t dcerpc_get_auth_length(const DATA_BLOB *blob);
185 uint8_t dcerpc_get_endian_flag(DATA_BLOB *blob);
186 uint8_t dcerpc_get_auth_type(const DATA_BLOB *blob);
187 uint8_t dcerpc_get_auth_level(const DATA_BLOB *blob);
188 uint32_t dcerpc_get_auth_context_id(const DATA_BLOB *blob);
189 const char *dcerpc_default_transport_endpoint(TALLOC_CTX *mem_ctx,
190                                               enum dcerpc_transport_t transport,
191                                               const struct ndr_interface_table *table);
192
193 NTSTATUS dcerpc_pull_ncacn_packet(TALLOC_CTX *mem_ctx,
194                                   const DATA_BLOB *blob,
195                                   struct ncacn_packet *r);
196
197 /**
198 * @brief        Pull a dcerpc_auth structure, taking account of any auth
199 *               padding in the blob. For request/response packets we pass
200 *               the whole data blob, so auth_data_only must be set to false
201 *               as the blob contains data+pad+auth and no just pad+auth.
202 *
203 * @param pkt            - The ncacn_packet strcuture
204 * @param mem_ctx        - The mem_ctx used to allocate dcerpc_auth elements
205 * @param pkt_trailer    - The packet trailer data, usually the trailing
206 *                         auth_info blob, but in the request/response case
207 *                         this is the stub_and_verifier blob.
208 * @param auth           - A preallocated dcerpc_auth *empty* structure
209 * @param auth_length    - The length of the auth trail, sum of auth header
210 *                         lenght and pkt->auth_length
211 * @param auth_data_only - Whether the pkt_trailer includes only the auth_blob
212 *                         (+ padding) or also other data.
213 *
214 * @return               - A NTSTATUS error code.
215 */
216 NTSTATUS dcerpc_pull_auth_trailer(const struct ncacn_packet *pkt,
217                                   TALLOC_CTX *mem_ctx,
218                                   const DATA_BLOB *pkt_trailer,
219                                   struct dcerpc_auth *auth,
220                                   uint32_t *auth_length,
221                                   bool auth_data_only);
222 NTSTATUS dcerpc_verify_ncacn_packet_header(const struct ncacn_packet *pkt,
223                                            enum dcerpc_pkt_type ptype,
224                                            size_t max_auth_info,
225                                            uint8_t required_flags,
226                                            uint8_t optional_flags);
227 NTSTATUS dcerpc_ncacn_pull_pkt_auth(const struct dcerpc_auth *auth_state,
228                                     struct gensec_security *gensec,
229                                     TALLOC_CTX *mem_ctx,
230                                     enum dcerpc_pkt_type ptype,
231                                     uint8_t required_flags,
232                                     uint8_t optional_flags,
233                                     uint8_t payload_offset,
234                                     DATA_BLOB *payload_and_verifier,
235                                     DATA_BLOB *raw_packet,
236                                     const struct ncacn_packet *pkt);
237 NTSTATUS dcerpc_ncacn_push_pkt_auth(const struct dcerpc_auth *auth_state,
238                                     struct gensec_security *gensec,
239                                     TALLOC_CTX *mem_ctx,
240                                     DATA_BLOB *raw_packet,
241                                     size_t sig_size,
242                                     uint8_t payload_offset,
243                                     const DATA_BLOB *payload,
244                                     const struct ncacn_packet *pkt);
245 struct tevent_req *dcerpc_read_ncacn_packet_send(TALLOC_CTX *mem_ctx,
246                                                  struct tevent_context *ev,
247                                                  struct tstream_context *stream);
248 NTSTATUS dcerpc_read_ncacn_packet_recv(struct tevent_req *req,
249                                        TALLOC_CTX *mem_ctx,
250                                        struct ncacn_packet **pkt,
251                                        DATA_BLOB *buffer);
252
253 /* The following definitions come from ../librpc/rpc/binding_handle.c  */
254
255 struct dcerpc_binding_handle_ops {
256         const char *name;
257
258         bool (*is_connected)(struct dcerpc_binding_handle *h);
259         uint32_t (*set_timeout)(struct dcerpc_binding_handle *h,
260                                 uint32_t timeout);
261
262         void (*auth_info)(struct dcerpc_binding_handle *h,
263                           enum dcerpc_AuthType *auth_type,
264                           enum dcerpc_AuthLevel *auth_level);
265
266         struct tevent_req *(*raw_call_send)(TALLOC_CTX *mem_ctx,
267                                             struct tevent_context *ev,
268                                             struct dcerpc_binding_handle *h,
269                                             const struct GUID *object,
270                                             uint32_t opnum,
271                                             uint32_t in_flags,
272                                             const uint8_t *in_data,
273                                             size_t in_length);
274         NTSTATUS (*raw_call_recv)(struct tevent_req *req,
275                                   TALLOC_CTX *mem_ctx,
276                                   uint8_t **out_data,
277                                   size_t *out_length,
278                                   uint32_t *out_flags);
279
280         struct tevent_req *(*disconnect_send)(TALLOC_CTX *mem_ctx,
281                                               struct tevent_context *ev,
282                                               struct dcerpc_binding_handle *h);
283         NTSTATUS (*disconnect_recv)(struct tevent_req *req);
284
285         /* TODO: remove the following functions */
286         bool (*push_bigendian)(struct dcerpc_binding_handle *h);
287         bool (*ref_alloc)(struct dcerpc_binding_handle *h);
288         bool (*use_ndr64)(struct dcerpc_binding_handle *h);
289         void (*do_ndr_print)(struct dcerpc_binding_handle *h,
290                              int ndr_flags,
291                              const void *struct_ptr,
292                              const struct ndr_interface_call *call);
293         void (*ndr_push_failed)(struct dcerpc_binding_handle *h,
294                                 NTSTATUS error,
295                                 const void *struct_ptr,
296                                 const struct ndr_interface_call *call);
297         void (*ndr_pull_failed)(struct dcerpc_binding_handle *h,
298                                 NTSTATUS error,
299                                 const DATA_BLOB *blob,
300                                 const struct ndr_interface_call *call);
301         NTSTATUS (*ndr_validate_in)(struct dcerpc_binding_handle *h,
302                                     TALLOC_CTX *mem_ctx,
303                                     const DATA_BLOB *blob,
304                                     const struct ndr_interface_call *call);
305         NTSTATUS (*ndr_validate_out)(struct dcerpc_binding_handle *h,
306                                      struct ndr_pull *pull_in,
307                                      const void *struct_ptr,
308                                      const struct ndr_interface_call *call);
309 };
310
311 struct dcerpc_binding_handle *_dcerpc_binding_handle_create(TALLOC_CTX *mem_ctx,
312                                         const struct dcerpc_binding_handle_ops *ops,
313                                         const struct GUID *object,
314                                         const struct ndr_interface_table *table,
315                                         void *pstate,
316                                         size_t psize,
317                                         const char *type,
318                                         const char *location);
319 #define dcerpc_binding_handle_create(mem_ctx, ops, object, table, \
320                                 state, type, location) \
321         _dcerpc_binding_handle_create(mem_ctx, ops, object, table, \
322                                 state, sizeof(type), #type, location)
323
324 void *_dcerpc_binding_handle_data(struct dcerpc_binding_handle *h);
325 #define dcerpc_binding_handle_data(_h, _type) \
326         talloc_get_type_abort(_dcerpc_binding_handle_data(_h), _type)
327
328 _DEPRECATED_ void dcerpc_binding_handle_set_sync_ev(struct dcerpc_binding_handle *h,
329                                                     struct tevent_context *ev);
330
331 bool dcerpc_binding_handle_is_connected(struct dcerpc_binding_handle *h);
332
333 uint32_t dcerpc_binding_handle_set_timeout(struct dcerpc_binding_handle *h,
334                                            uint32_t timeout);
335
336 void dcerpc_binding_handle_auth_info(struct dcerpc_binding_handle *h,
337                                      enum dcerpc_AuthType *auth_type,
338                                      enum dcerpc_AuthLevel *auth_level);
339
340 struct tevent_req *dcerpc_binding_handle_raw_call_send(TALLOC_CTX *mem_ctx,
341                                                 struct tevent_context *ev,
342                                                 struct dcerpc_binding_handle *h,
343                                                 const struct GUID *object,
344                                                 uint32_t opnum,
345                                                 uint32_t in_flags,
346                                                 const uint8_t *in_data,
347                                                 size_t in_length);
348 NTSTATUS dcerpc_binding_handle_raw_call_recv(struct tevent_req *req,
349                                              TALLOC_CTX *mem_ctx,
350                                              uint8_t **out_data,
351                                              size_t *out_length,
352                                              uint32_t *out_flags);
353 NTSTATUS dcerpc_binding_handle_raw_call(struct dcerpc_binding_handle *h,
354                                         const struct GUID *object,
355                                         uint32_t opnum,
356                                         uint32_t in_flags,
357                                         const uint8_t *in_data,
358                                         size_t in_length,
359                                         TALLOC_CTX *mem_ctx,
360                                         uint8_t **out_data,
361                                         size_t *out_length,
362                                         uint32_t *out_flags);
363
364 struct tevent_req *dcerpc_binding_handle_disconnect_send(TALLOC_CTX *mem_ctx,
365                                                 struct tevent_context *ev,
366                                                 struct dcerpc_binding_handle *h);
367 NTSTATUS dcerpc_binding_handle_disconnect_recv(struct tevent_req *req);
368
369 struct dcerpc_binding_handle_call_params {
370         TALLOC_CTX *r_mem;
371         void *r_ptr;
372         struct {
373                 uint32_t num_pipes;
374                 struct dcerpc_pipe_handle_connection **pipes;
375         } in, out;
376 };
377
378 struct tevent_req *dcerpc_binding_handle_call_params_send(TALLOC_CTX *mem_ctx,
379                                 struct tevent_context *ev,
380                                 struct dcerpc_binding_handle *h,
381                                 const struct GUID *object,
382                                 const struct ndr_interface_table *table,
383                                 uint32_t opnum,
384                                 struct dcerpc_binding_handle_call_params *params);
385 NTSTATUS dcerpc_binding_handle_call_params_recv(struct tevent_req *req);
386 struct tevent_req *dcerpc_binding_handle_call_send(TALLOC_CTX *mem_ctx,
387                                         struct tevent_context *ev,
388                                         struct dcerpc_binding_handle *h,
389                                         const struct GUID *object,
390                                         const struct ndr_interface_table *table,
391                                         uint32_t opnum,
392                                         TALLOC_CTX *r_mem,
393                                         void *r_ptr);
394 NTSTATUS dcerpc_binding_handle_call_recv(struct tevent_req *req);
395 NTSTATUS dcerpc_binding_handle_call(struct dcerpc_binding_handle *h,
396                                     const struct GUID *object,
397                                     const struct ndr_interface_table *table,
398                                     uint32_t opnum,
399                                     TALLOC_CTX *r_mem,
400                                     void *r_ptr);
401
402 /**
403  * Extract header information from a ncacn_packet
404  * as a dcerpc_sec_vt_header2 as used by the security verification trailer.
405  *
406  * @param[in] pkt a packet
407  *
408  * @return a dcerpc_sec_vt_header2
409  */
410 struct dcerpc_sec_vt_header2 dcerpc_sec_vt_header2_from_ncacn_packet(const struct ncacn_packet *pkt);
411
412
413 /**
414  * Test if two dcerpc_sec_vt_header2 structures are equal
415  * without consideration of reserved fields.
416  *
417  * @param v1 a pointer to a dcerpc_sec_vt_header2 structure
418  * @param v2 a pointer to a dcerpc_sec_vt_header2 structure
419  *
420  * @retval true if *v1 equals *v2
421  */
422 bool dcerpc_sec_vt_header2_equal(const struct dcerpc_sec_vt_header2 *v1,
423                                  const struct dcerpc_sec_vt_header2 *v2);
424
425 /**
426  * Check for consistency of the security verification trailer with the PDU header.
427  * See <a href="http://msdn.microsoft.com/en-us/library/cc243559.aspx">MS-RPCE 2.2.2.13</a>.
428  * A check with an empty trailer succeeds.
429  *
430  * @param[in] vt a pointer to the security verification trailer.
431  * @param[in] bitmask1 which flags were negotiated on the connection.
432  * @param[in] pcontext the syntaxes negotiatied for the presentation context.
433  * @param[in] header2 some fields from the PDU header.
434  *
435  * @retval true on success.
436  */
437 bool dcerpc_sec_verification_trailer_check(
438                 const struct dcerpc_sec_verification_trailer *vt,
439                 const uint32_t *bitmask1,
440                 const struct dcerpc_sec_vt_pcontext *pcontext,
441                 const struct dcerpc_sec_vt_header2 *header2);
442
443 /**
444  * @brief check and optionally extract the Bind Time Features from
445  * the given ndr_syntax_id.
446  *
447  * <a href="http://msdn.microsoft.com/en-us/library/cc243715.aspx">MS-RPCE 3.3.1.5.3 Bind Time Feature Negotiation</a>.
448  *
449  * @param[in]  s the syntax that should be checked.
450  *
451  * @param[out] features This is optional, it will be filled with the extracted
452  *                      features the on success, otherwise it's filled with 0.
453  *
454  * @return true if the syntax matches the 6CB71C2C-9812-4540 prefix with version 1, false otherwise.
455  *
456  * @see dcerpc_construct_bind_time_features
457  */
458 bool dcerpc_extract_bind_time_features(struct ndr_syntax_id syntax, uint64_t *features);
459
460 /**
461  * @brief Construct a ndr_syntax_id used for Bind Time Features Negotiation.
462  *
463  * <a href="http://msdn.microsoft.com/en-us/library/cc243715.aspx">MS-RPCE 3.3.1.5.3 Bind Time Feature Negotiation</a>.
464  *
465  * @param[in] features The supported features.
466  *
467  * @return The ndr_syntax_id with the given features.
468  *
469  * @see dcerpc_extract_bind_time_features
470  */
471 struct ndr_syntax_id dcerpc_construct_bind_time_features(uint64_t features);
472
473 #define DCERPC_AUTH_PAD_LENGTH(stub_length) (\
474         (((stub_length) % DCERPC_AUTH_PAD_ALIGNMENT) > 0)?\
475         (DCERPC_AUTH_PAD_ALIGNMENT - (stub_length) % DCERPC_AUTH_PAD_ALIGNMENT):\
476         0)
477
478 struct dcerpc_pipe_handle_connection *dcerpc_pipe_handle_connection_create(
479                                         TALLOC_CTX *mem_ctx,
480                                         const char *chunk_struct_name,
481                                         size_t chunk_struct_size);
482 bool _dcerpc_pipe_handle_connection_connect(
483                                 struct dcerpc_pipe_handle_connection *pc,
484                                 const char *chunk_struct_name,
485                                 size_t chunk_struct_size,
486                                 struct dcerpc_pipe_handle *p,
487                                 bool push);
488 #define dcerpc_pipe_handle_connection_push_connect(pc, csn, css, p) \
489         _dcerpc_pipe_handle_connection_connect(pc, csn, css, p, true)
490 #define dcerpc_pipe_handle_connection_pull_connect(pc, csn, css, p) \
491         _dcerpc_pipe_handle_connection_connect(pc, csn, css, p, false)
492 void dcerpc_pipe_handle_connection_disconnect(
493                                 struct dcerpc_pipe_handle_connection *pc);
494
495 struct dcerpc_pipe_handle_ops {
496         const char *name;
497
498         struct tevent_req *(*chunk_push_send)(TALLOC_CTX *mem_ctx,
499                                             struct tevent_context *ev,
500                                             struct dcerpc_pipe_handle *p,
501                                             const void *chunk_ptr);
502         NTSTATUS (*chunk_push_recv)(struct tevent_req *req);
503
504         struct tevent_req *(*chunk_pull_send)(TALLOC_CTX *mem_ctx,
505                                             struct tevent_context *ev,
506                                             struct dcerpc_pipe_handle *p,
507                                             void *chunk_mem,
508                                             void *chunk_ptr);
509         NTSTATUS (*chunk_pull_recv)(struct tevent_req *req);
510 };
511
512 struct dcerpc_pipe_handle *_dcerpc_pipe_handle_create(
513                                         TALLOC_CTX *mem_ctx,
514                                         const struct dcerpc_pipe_handle_ops *ops,
515                                         void *pstate,
516                                         size_t psize,
517                                         const char *type,
518                                         const char *location);
519 #define dcerpc_pipe_handle_create(mem_ctx, ops, \
520                                   state, type) \
521         _dcerpc_pipe_handle_create(mem_ctx, ops, \
522                                 state, sizeof(type), #type, __location__)
523
524 void *_dcerpc_pipe_handle_data(struct dcerpc_pipe_handle *p);
525 #define dcerpc_pipe_handle_data(_p, _type) \
526         talloc_get_type_abort(_dcerpc_pipe_handle_data(_p), _type)
527
528 struct tevent_req *dcerpc_pipe_handle_push_send(TALLOC_CTX *mem_ctx,
529                                         struct tevent_context *ev,
530                                         struct dcerpc_pipe_handle_connection *pc,
531                                         const void *chunk_ptr);
532 NTSTATUS dcerpc_pipe_handle_push_recv(struct tevent_req *req);
533
534 struct tevent_req *dcerpc_pipe_handle_pull_send(TALLOC_CTX *mem_ctx,
535                                         struct tevent_context *ev,
536                                         struct dcerpc_pipe_handle_connection *pc,
537                                         void *chunk_mem,
538                                         void *chunk_ptr);
539 NTSTATUS dcerpc_pipe_handle_pull_recv(struct tevent_req *req);
540
541 #endif /* __DEFAULT_LIBRPC_RPCCOMMON_H__ */