librpc/rpc: move struct dcerpc_binding to rpc_common.h
[samba.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 struct dcerpc_binding_handle;
26 struct GUID;
27 struct ndr_interface_table;
28 struct ndr_interface_call;
29 struct ndr_push;
30 struct ndr_pull;
31 struct ncacn_packet;
32 struct epm_floor;
33 struct tevent_context;
34 struct tstream_context;
35
36 enum dcerpc_transport_t {
37         NCA_UNKNOWN, NCACN_NP, NCACN_IP_TCP, NCACN_IP_UDP, NCACN_VNS_IPC, 
38         NCACN_VNS_SPP, NCACN_AT_DSP, NCADG_AT_DDP, NCALRPC, NCACN_UNIX_STREAM, 
39         NCADG_UNIX_DGRAM, NCACN_HTTP, NCADG_IPX, NCACN_SPX, NCACN_INTERNAL };
40
41 /** this describes a binding to a particular transport/pipe */
42 struct dcerpc_binding {
43         enum dcerpc_transport_t transport;
44         struct ndr_syntax_id object;
45         const char *host;
46         const char *target_hostname;
47         const char *target_principal;
48         const char *endpoint;
49         const char **options;
50         const char *localaddress;
51         uint32_t flags;
52         uint32_t assoc_group_id;
53 };
54
55 /* The following definitions come from ../librpc/rpc/dcerpc_error.c  */
56
57 const char *dcerpc_errstr(TALLOC_CTX *mem_ctx, uint32_t fault_code);
58 NTSTATUS dcerpc_fault_to_nt_status(uint32_t fault_code);
59
60 /* The following definitions come from ../librpc/rpc/binding.c  */
61
62 const char *epm_floor_string(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor);
63 const char *dcerpc_floor_get_rhs_data(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor);
64 enum dcerpc_transport_t dcerpc_transport_by_endpoint_protocol(int prot);
65
66 /* The following definitions come from ../librpc/rpc/dcerpc_util.c  */
67
68 void dcerpc_set_frag_length(DATA_BLOB *blob, uint16_t v);
69 uint16_t dcerpc_get_frag_length(const DATA_BLOB *blob);
70 void dcerpc_set_auth_length(DATA_BLOB *blob, uint16_t v);
71 uint8_t dcerpc_get_endian_flag(DATA_BLOB *blob);
72
73 /**
74 * @brief        Pull a dcerpc_auth structure, taking account of any auth
75 *               padding in the blob. For request/response packets we pass
76 *               the whole data blob, so auth_data_only must be set to false
77 *               as the blob contains data+pad+auth and no just pad+auth.
78 *
79 * @param pkt            - The ncacn_packet strcuture
80 * @param mem_ctx        - The mem_ctx used to allocate dcerpc_auth elements
81 * @param pkt_trailer    - The packet trailer data, usually the trailing
82 *                         auth_info blob, but in the request/response case
83 *                         this is the stub_and_verifier blob.
84 * @param auth           - A preallocated dcerpc_auth *empty* structure
85 * @param auth_length    - The length of the auth trail, sum of auth header
86 *                         lenght and pkt->auth_length
87 * @param auth_data_only - Whether the pkt_trailer includes only the auth_blob
88 *                         (+ padding) or also other data.
89 *
90 * @return               - A NTSTATUS error code.
91 */
92 NTSTATUS dcerpc_pull_auth_trailer(struct ncacn_packet *pkt,
93                                   TALLOC_CTX *mem_ctx,
94                                   DATA_BLOB *pkt_trailer,
95                                   struct dcerpc_auth *auth,
96                                   uint32_t *auth_length,
97                                   bool auth_data_only);
98 struct tevent_req *dcerpc_read_ncacn_packet_send(TALLOC_CTX *mem_ctx,
99                                                  struct tevent_context *ev,
100                                                  struct tstream_context *stream);
101 NTSTATUS dcerpc_read_ncacn_packet_recv(struct tevent_req *req,
102                                        TALLOC_CTX *mem_ctx,
103                                        struct ncacn_packet **pkt,
104                                        DATA_BLOB *buffer);
105
106 /* The following definitions come from ../librpc/rpc/binding_handle.c  */
107
108 struct dcerpc_binding_handle_ops {
109         const char *name;
110
111         bool (*is_connected)(struct dcerpc_binding_handle *h);
112         uint32_t (*set_timeout)(struct dcerpc_binding_handle *h,
113                                 uint32_t timeout);
114
115         struct tevent_req *(*raw_call_send)(TALLOC_CTX *mem_ctx,
116                                             struct tevent_context *ev,
117                                             struct dcerpc_binding_handle *h,
118                                             const struct GUID *object,
119                                             uint32_t opnum,
120                                             uint32_t in_flags,
121                                             const uint8_t *in_data,
122                                             size_t in_length);
123         NTSTATUS (*raw_call_recv)(struct tevent_req *req,
124                                   TALLOC_CTX *mem_ctx,
125                                   uint8_t **out_data,
126                                   size_t *out_length,
127                                   uint32_t *out_flags);
128
129         struct tevent_req *(*disconnect_send)(TALLOC_CTX *mem_ctx,
130                                               struct tevent_context *ev,
131                                               struct dcerpc_binding_handle *h);
132         NTSTATUS (*disconnect_recv)(struct tevent_req *req);
133
134         /* TODO: remove the following functions */
135         bool (*push_bigendian)(struct dcerpc_binding_handle *h);
136         bool (*ref_alloc)(struct dcerpc_binding_handle *h);
137         bool (*use_ndr64)(struct dcerpc_binding_handle *h);
138         void (*do_ndr_print)(struct dcerpc_binding_handle *h,
139                              int ndr_flags,
140                              const void *struct_ptr,
141                              const struct ndr_interface_call *call);
142         void (*ndr_push_failed)(struct dcerpc_binding_handle *h,
143                                 NTSTATUS error,
144                                 const void *struct_ptr,
145                                 const struct ndr_interface_call *call);
146         void (*ndr_pull_failed)(struct dcerpc_binding_handle *h,
147                                 NTSTATUS error,
148                                 const DATA_BLOB *blob,
149                                 const struct ndr_interface_call *call);
150         NTSTATUS (*ndr_validate_in)(struct dcerpc_binding_handle *h,
151                                     TALLOC_CTX *mem_ctx,
152                                     const DATA_BLOB *blob,
153                                     const struct ndr_interface_call *call);
154         NTSTATUS (*ndr_validate_out)(struct dcerpc_binding_handle *h,
155                                      struct ndr_pull *pull_in,
156                                      const void *struct_ptr,
157                                      const struct ndr_interface_call *call);
158 };
159
160 struct dcerpc_binding_handle *_dcerpc_binding_handle_create(TALLOC_CTX *mem_ctx,
161                                         const struct dcerpc_binding_handle_ops *ops,
162                                         const struct GUID *object,
163                                         const struct ndr_interface_table *table,
164                                         void *pstate,
165                                         size_t psize,
166                                         const char *type,
167                                         const char *location);
168 #define dcerpc_binding_handle_create(mem_ctx, ops, object, table, \
169                                 state, type, location) \
170         _dcerpc_binding_handle_create(mem_ctx, ops, object, table, \
171                                 state, sizeof(type), #type, location)
172
173 void *_dcerpc_binding_handle_data(struct dcerpc_binding_handle *h);
174 #define dcerpc_binding_handle_data(_h, _type) \
175         talloc_get_type_abort(_dcerpc_binding_handle_data(_h), _type)
176
177 _DEPRECATED_ void dcerpc_binding_handle_set_sync_ev(struct dcerpc_binding_handle *h,
178                                                     struct tevent_context *ev);
179
180 bool dcerpc_binding_handle_is_connected(struct dcerpc_binding_handle *h);
181
182 uint32_t dcerpc_binding_handle_set_timeout(struct dcerpc_binding_handle *h,
183                                            uint32_t timeout);
184
185 struct tevent_req *dcerpc_binding_handle_raw_call_send(TALLOC_CTX *mem_ctx,
186                                                 struct tevent_context *ev,
187                                                 struct dcerpc_binding_handle *h,
188                                                 const struct GUID *object,
189                                                 uint32_t opnum,
190                                                 uint32_t in_flags,
191                                                 const uint8_t *in_data,
192                                                 size_t in_length);
193 NTSTATUS dcerpc_binding_handle_raw_call_recv(struct tevent_req *req,
194                                              TALLOC_CTX *mem_ctx,
195                                              uint8_t **out_data,
196                                              size_t *out_length,
197                                              uint32_t *out_flags);
198
199 struct tevent_req *dcerpc_binding_handle_disconnect_send(TALLOC_CTX *mem_ctx,
200                                                 struct tevent_context *ev,
201                                                 struct dcerpc_binding_handle *h);
202 NTSTATUS dcerpc_binding_handle_disconnect_recv(struct tevent_req *req);
203
204 struct tevent_req *dcerpc_binding_handle_call_send(TALLOC_CTX *mem_ctx,
205                                         struct tevent_context *ev,
206                                         struct dcerpc_binding_handle *h,
207                                         const struct GUID *object,
208                                         const struct ndr_interface_table *table,
209                                         uint32_t opnum,
210                                         TALLOC_CTX *r_mem,
211                                         void *r_ptr);
212 NTSTATUS dcerpc_binding_handle_call_recv(struct tevent_req *req);
213 NTSTATUS dcerpc_binding_handle_call(struct dcerpc_binding_handle *h,
214                                     const struct GUID *object,
215                                     const struct ndr_interface_table *table,
216                                     uint32_t opnum,
217                                     TALLOC_CTX *r_mem,
218                                     void *r_ptr);
219
220 #endif /* __DEFAULT_LIBRPC_RPCCOMMON_H__ */