s4-selftest: fix output of opened connections in torture_holdcon
[Samba/gebeck_regimport.git] / librpc / rpc / rpc_common.h
bloba28835fa6347f216896eb04802f53530ac28d039
1 /*
2 Unix SMB/CIFS implementation.
4 Copyright (C) Stefan Metzmacher 2010-2011
5 Copyright (C) Andrew Tridgell 2010-2011
6 Copyright (C) Simo Sorce 2010
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.
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.
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/>.
22 #ifndef __DEFAULT_LIBRPC_RPCCOMMON_H__
23 #define __DEFAULT_LIBRPC_RPCCOMMON_H__
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 epm_tower;
34 struct tevent_context;
35 struct tstream_context;
37 enum dcerpc_transport_t {
38 NCA_UNKNOWN, NCACN_NP, NCACN_IP_TCP, NCACN_IP_UDP, NCACN_VNS_IPC,
39 NCACN_VNS_SPP, NCACN_AT_DSP, NCADG_AT_DDP, NCALRPC, NCACN_UNIX_STREAM,
40 NCADG_UNIX_DGRAM, NCACN_HTTP, NCADG_IPX, NCACN_SPX, NCACN_INTERNAL };
42 /** this describes a binding to a particular transport/pipe */
43 struct dcerpc_binding {
44 enum dcerpc_transport_t transport;
45 struct ndr_syntax_id object;
46 const char *host;
47 const char *target_hostname;
48 const char *target_principal;
49 const char *endpoint;
50 const char **options;
51 const char *localaddress;
52 uint32_t flags;
53 uint32_t assoc_group_id;
56 /* dcerpc pipe flags */
57 #define DCERPC_DEBUG_PRINT_IN (1<<0)
58 #define DCERPC_DEBUG_PRINT_OUT (1<<1)
59 #define DCERPC_DEBUG_PRINT_BOTH (DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT)
61 #define DCERPC_DEBUG_VALIDATE_IN (1<<2)
62 #define DCERPC_DEBUG_VALIDATE_OUT (1<<3)
63 #define DCERPC_DEBUG_VALIDATE_BOTH (DCERPC_DEBUG_VALIDATE_IN | DCERPC_DEBUG_VALIDATE_OUT)
65 #define DCERPC_CONNECT (1<<4)
66 #define DCERPC_SIGN (1<<5)
67 #define DCERPC_SEAL (1<<6)
69 #define DCERPC_PUSH_BIGENDIAN (1<<7)
70 #define DCERPC_PULL_BIGENDIAN (1<<8)
72 #define DCERPC_SCHANNEL (1<<9)
74 #define DCERPC_ANON_FALLBACK (1<<10)
76 /* use a 128 bit session key */
77 #define DCERPC_SCHANNEL_128 (1<<12)
79 /* check incoming pad bytes */
80 #define DCERPC_DEBUG_PAD_CHECK (1<<13)
82 /* set LIBNDR_FLAG_REF_ALLOC flag when decoding NDR */
83 #define DCERPC_NDR_REF_ALLOC (1<<14)
85 #define DCERPC_AUTH_OPTIONS (DCERPC_SEAL|DCERPC_SIGN|DCERPC_SCHANNEL|DCERPC_AUTH_SPNEGO|DCERPC_AUTH_KRB5|DCERPC_AUTH_NTLM)
87 /* select spnego auth */
88 #define DCERPC_AUTH_SPNEGO (1<<15)
90 /* select krb5 auth */
91 #define DCERPC_AUTH_KRB5 (1<<16)
93 #define DCERPC_SMB2 (1<<17)
95 /* select NTLM auth */
96 #define DCERPC_AUTH_NTLM (1<<18)
98 /* this triggers the DCERPC_PFC_FLAG_CONC_MPX flag in the bind request */
99 #define DCERPC_CONCURRENT_MULTIPLEX (1<<19)
101 /* this triggers the DCERPC_PFC_FLAG_SUPPORT_HEADER_SIGN flag in the bind request */
102 #define DCERPC_HEADER_SIGNING (1<<20)
104 /* use NDR64 transport */
105 #define DCERPC_NDR64 (1<<21)
107 /* specify binding interface */
108 #define DCERPC_LOCALADDRESS (1<<22)
110 /* handle upgrades or downgrades automatically */
111 #define DCERPC_SCHANNEL_AUTO (1<<23)
113 /* The following definitions come from ../librpc/rpc/dcerpc_error.c */
115 const char *dcerpc_errstr(TALLOC_CTX *mem_ctx, uint32_t fault_code);
116 NTSTATUS dcerpc_fault_to_nt_status(uint32_t fault_code);
118 /* The following definitions come from ../librpc/rpc/binding.c */
120 const char *epm_floor_string(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor);
121 const char *dcerpc_floor_get_rhs_data(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor);
122 enum dcerpc_transport_t dcerpc_transport_by_endpoint_protocol(int prot);
123 struct dcerpc_binding *dcerpc_binding_dup(TALLOC_CTX *mem_ctx,
124 const struct dcerpc_binding *b);
125 NTSTATUS dcerpc_binding_build_tower(TALLOC_CTX *mem_ctx,
126 const struct dcerpc_binding *binding,
127 struct epm_tower *tower);
128 NTSTATUS dcerpc_binding_from_tower(TALLOC_CTX *mem_ctx,
129 struct epm_tower *tower,
130 struct dcerpc_binding **b_out);
131 NTSTATUS dcerpc_parse_binding(TALLOC_CTX *mem_ctx, const char *s, struct dcerpc_binding **b_out);
132 char *dcerpc_binding_string(TALLOC_CTX *mem_ctx, const struct dcerpc_binding *b);
133 NTSTATUS dcerpc_floor_get_lhs_data(const struct epm_floor *epm_floor, struct ndr_syntax_id *syntax);
134 const char *derpc_transport_string_by_transport(enum dcerpc_transport_t t);
135 enum dcerpc_transport_t dcerpc_transport_by_tower(const struct epm_tower *tower);
137 /* The following definitions come from ../librpc/rpc/dcerpc_util.c */
139 void dcerpc_set_frag_length(DATA_BLOB *blob, uint16_t v);
140 uint16_t dcerpc_get_frag_length(const DATA_BLOB *blob);
141 void dcerpc_set_auth_length(DATA_BLOB *blob, uint16_t v);
142 uint8_t dcerpc_get_endian_flag(DATA_BLOB *blob);
145 * @brief Pull a dcerpc_auth structure, taking account of any auth
146 * padding in the blob. For request/response packets we pass
147 * the whole data blob, so auth_data_only must be set to false
148 * as the blob contains data+pad+auth and no just pad+auth.
150 * @param pkt - The ncacn_packet strcuture
151 * @param mem_ctx - The mem_ctx used to allocate dcerpc_auth elements
152 * @param pkt_trailer - The packet trailer data, usually the trailing
153 * auth_info blob, but in the request/response case
154 * this is the stub_and_verifier blob.
155 * @param auth - A preallocated dcerpc_auth *empty* structure
156 * @param auth_length - The length of the auth trail, sum of auth header
157 * lenght and pkt->auth_length
158 * @param auth_data_only - Whether the pkt_trailer includes only the auth_blob
159 * (+ padding) or also other data.
161 * @return - A NTSTATUS error code.
163 NTSTATUS dcerpc_pull_auth_trailer(struct ncacn_packet *pkt,
164 TALLOC_CTX *mem_ctx,
165 DATA_BLOB *pkt_trailer,
166 struct dcerpc_auth *auth,
167 uint32_t *auth_length,
168 bool auth_data_only);
169 struct tevent_req *dcerpc_read_ncacn_packet_send(TALLOC_CTX *mem_ctx,
170 struct tevent_context *ev,
171 struct tstream_context *stream);
172 NTSTATUS dcerpc_read_ncacn_packet_recv(struct tevent_req *req,
173 TALLOC_CTX *mem_ctx,
174 struct ncacn_packet **pkt,
175 DATA_BLOB *buffer);
177 /* The following definitions come from ../librpc/rpc/binding_handle.c */
179 struct dcerpc_binding_handle_ops {
180 const char *name;
182 bool (*is_connected)(struct dcerpc_binding_handle *h);
183 uint32_t (*set_timeout)(struct dcerpc_binding_handle *h,
184 uint32_t timeout);
186 struct tevent_req *(*raw_call_send)(TALLOC_CTX *mem_ctx,
187 struct tevent_context *ev,
188 struct dcerpc_binding_handle *h,
189 const struct GUID *object,
190 uint32_t opnum,
191 uint32_t in_flags,
192 const uint8_t *in_data,
193 size_t in_length);
194 NTSTATUS (*raw_call_recv)(struct tevent_req *req,
195 TALLOC_CTX *mem_ctx,
196 uint8_t **out_data,
197 size_t *out_length,
198 uint32_t *out_flags);
200 struct tevent_req *(*disconnect_send)(TALLOC_CTX *mem_ctx,
201 struct tevent_context *ev,
202 struct dcerpc_binding_handle *h);
203 NTSTATUS (*disconnect_recv)(struct tevent_req *req);
205 /* TODO: remove the following functions */
206 bool (*push_bigendian)(struct dcerpc_binding_handle *h);
207 bool (*ref_alloc)(struct dcerpc_binding_handle *h);
208 bool (*use_ndr64)(struct dcerpc_binding_handle *h);
209 void (*do_ndr_print)(struct dcerpc_binding_handle *h,
210 int ndr_flags,
211 const void *struct_ptr,
212 const struct ndr_interface_call *call);
213 void (*ndr_push_failed)(struct dcerpc_binding_handle *h,
214 NTSTATUS error,
215 const void *struct_ptr,
216 const struct ndr_interface_call *call);
217 void (*ndr_pull_failed)(struct dcerpc_binding_handle *h,
218 NTSTATUS error,
219 const DATA_BLOB *blob,
220 const struct ndr_interface_call *call);
221 NTSTATUS (*ndr_validate_in)(struct dcerpc_binding_handle *h,
222 TALLOC_CTX *mem_ctx,
223 const DATA_BLOB *blob,
224 const struct ndr_interface_call *call);
225 NTSTATUS (*ndr_validate_out)(struct dcerpc_binding_handle *h,
226 struct ndr_pull *pull_in,
227 const void *struct_ptr,
228 const struct ndr_interface_call *call);
231 struct dcerpc_binding_handle *_dcerpc_binding_handle_create(TALLOC_CTX *mem_ctx,
232 const struct dcerpc_binding_handle_ops *ops,
233 const struct GUID *object,
234 const struct ndr_interface_table *table,
235 void *pstate,
236 size_t psize,
237 const char *type,
238 const char *location);
239 #define dcerpc_binding_handle_create(mem_ctx, ops, object, table, \
240 state, type, location) \
241 _dcerpc_binding_handle_create(mem_ctx, ops, object, table, \
242 state, sizeof(type), #type, location)
244 void *_dcerpc_binding_handle_data(struct dcerpc_binding_handle *h);
245 #define dcerpc_binding_handle_data(_h, _type) \
246 talloc_get_type_abort(_dcerpc_binding_handle_data(_h), _type)
248 _DEPRECATED_ void dcerpc_binding_handle_set_sync_ev(struct dcerpc_binding_handle *h,
249 struct tevent_context *ev);
251 bool dcerpc_binding_handle_is_connected(struct dcerpc_binding_handle *h);
253 uint32_t dcerpc_binding_handle_set_timeout(struct dcerpc_binding_handle *h,
254 uint32_t timeout);
256 struct tevent_req *dcerpc_binding_handle_raw_call_send(TALLOC_CTX *mem_ctx,
257 struct tevent_context *ev,
258 struct dcerpc_binding_handle *h,
259 const struct GUID *object,
260 uint32_t opnum,
261 uint32_t in_flags,
262 const uint8_t *in_data,
263 size_t in_length);
264 NTSTATUS dcerpc_binding_handle_raw_call_recv(struct tevent_req *req,
265 TALLOC_CTX *mem_ctx,
266 uint8_t **out_data,
267 size_t *out_length,
268 uint32_t *out_flags);
269 NTSTATUS dcerpc_binding_handle_raw_call(struct dcerpc_binding_handle *h,
270 const struct GUID *object,
271 uint32_t opnum,
272 uint32_t in_flags,
273 const uint8_t *in_data,
274 size_t in_length,
275 TALLOC_CTX *mem_ctx,
276 uint8_t **out_data,
277 size_t *out_length,
278 uint32_t *out_flags);
280 struct tevent_req *dcerpc_binding_handle_disconnect_send(TALLOC_CTX *mem_ctx,
281 struct tevent_context *ev,
282 struct dcerpc_binding_handle *h);
283 NTSTATUS dcerpc_binding_handle_disconnect_recv(struct tevent_req *req);
285 struct tevent_req *dcerpc_binding_handle_call_send(TALLOC_CTX *mem_ctx,
286 struct tevent_context *ev,
287 struct dcerpc_binding_handle *h,
288 const struct GUID *object,
289 const struct ndr_interface_table *table,
290 uint32_t opnum,
291 TALLOC_CTX *r_mem,
292 void *r_ptr);
293 NTSTATUS dcerpc_binding_handle_call_recv(struct tevent_req *req);
294 NTSTATUS dcerpc_binding_handle_call(struct dcerpc_binding_handle *h,
295 const struct GUID *object,
296 const struct ndr_interface_table *table,
297 uint32_t opnum,
298 TALLOC_CTX *r_mem,
299 void *r_ptr);
301 #endif /* __DEFAULT_LIBRPC_RPCCOMMON_H__ */