notifyd: Add notifydd
[Samba.git] / librpc / rpc / rpc_common.h
blob28600c9da7c4af28beaf2a427be8a72af38d7344
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 #include "gen_ndr/dcerpc.h"
27 struct dcerpc_binding_handle;
28 struct GUID;
29 struct ndr_interface_table;
30 struct ndr_interface_call;
31 struct ndr_push;
32 struct ndr_pull;
33 struct ncacn_packet;
34 struct epm_floor;
35 struct epm_tower;
36 struct tevent_context;
37 struct tstream_context;
39 enum dcerpc_transport_t {
40 NCA_UNKNOWN, NCACN_NP, NCACN_IP_TCP, NCACN_IP_UDP, NCACN_VNS_IPC,
41 NCACN_VNS_SPP, NCACN_AT_DSP, NCADG_AT_DDP, NCALRPC, NCACN_UNIX_STREAM,
42 NCADG_UNIX_DGRAM, NCACN_HTTP, NCADG_IPX, NCACN_SPX, NCACN_INTERNAL };
44 /** this describes a binding to a particular transport/pipe */
45 struct dcerpc_binding;
47 /* dcerpc pipe flags */
48 #define DCERPC_DEBUG_PRINT_IN (1<<0)
49 #define DCERPC_DEBUG_PRINT_OUT (1<<1)
50 #define DCERPC_DEBUG_PRINT_BOTH (DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT)
52 #define DCERPC_DEBUG_VALIDATE_IN (1<<2)
53 #define DCERPC_DEBUG_VALIDATE_OUT (1<<3)
54 #define DCERPC_DEBUG_VALIDATE_BOTH (DCERPC_DEBUG_VALIDATE_IN | DCERPC_DEBUG_VALIDATE_OUT)
56 #define DCERPC_CONNECT (1<<4)
57 #define DCERPC_SIGN (1<<5)
58 #define DCERPC_SEAL (1<<6)
60 #define DCERPC_PUSH_BIGENDIAN (1<<7)
61 #define DCERPC_PULL_BIGENDIAN (1<<8)
63 #define DCERPC_SCHANNEL (1<<9)
65 #define DCERPC_ANON_FALLBACK (1<<10)
67 /* use a 128 bit session key */
68 #define DCERPC_SCHANNEL_128 (1<<12)
70 /* check incoming pad bytes */
71 #define DCERPC_DEBUG_PAD_CHECK (1<<13)
73 /* set LIBNDR_FLAG_REF_ALLOC flag when decoding NDR */
74 #define DCERPC_NDR_REF_ALLOC (1<<14)
76 #define DCERPC_AUTH_OPTIONS (DCERPC_SEAL|DCERPC_SIGN|DCERPC_SCHANNEL|DCERPC_AUTH_SPNEGO|DCERPC_AUTH_KRB5|DCERPC_AUTH_NTLM)
78 /* select spnego auth */
79 #define DCERPC_AUTH_SPNEGO (1<<15)
81 /* select krb5 auth */
82 #define DCERPC_AUTH_KRB5 (1<<16)
84 #define DCERPC_SMB2 (1<<17)
86 /* select NTLM auth */
87 #define DCERPC_AUTH_NTLM (1<<18)
89 /* this triggers the DCERPC_PFC_FLAG_CONC_MPX flag in the bind request */
90 #define DCERPC_CONCURRENT_MULTIPLEX (1<<19)
92 /* this indicates DCERPC_PFC_FLAG_SUPPORT_HEADER_SIGN flag was negotiated */
93 #define DCERPC_HEADER_SIGNING (1<<20)
95 /* use NDR64 transport */
96 #define DCERPC_NDR64 (1<<21)
98 /* handle upgrades or downgrades automatically */
99 #define DCERPC_SCHANNEL_AUTO (1<<23)
101 /* use aes schannel with hmac-sh256 session key */
102 #define DCERPC_SCHANNEL_AES (1<<24)
104 /* this triggers the DCERPC_PFC_FLAG_SUPPORT_HEADER_SIGN flag in the bind request */
105 #define DCERPC_PROPOSE_HEADER_SIGNING (1<<25)
107 /* The following definitions come from ../librpc/rpc/dcerpc_error.c */
109 const char *dcerpc_errstr(TALLOC_CTX *mem_ctx, uint32_t fault_code);
110 NTSTATUS dcerpc_fault_to_nt_status(uint32_t fault_code);
111 uint32_t dcerpc_fault_from_nt_status(NTSTATUS nt_status);
113 /* The following definitions come from ../librpc/rpc/binding.c */
115 const char *epm_floor_string(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor);
116 char *dcerpc_floor_get_rhs_data(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor);
117 enum dcerpc_transport_t dcerpc_transport_by_endpoint_protocol(int prot);
118 struct dcerpc_binding *dcerpc_binding_dup(TALLOC_CTX *mem_ctx,
119 const struct dcerpc_binding *b);
120 NTSTATUS dcerpc_binding_build_tower(TALLOC_CTX *mem_ctx,
121 const struct dcerpc_binding *binding,
122 struct epm_tower *tower);
123 NTSTATUS dcerpc_binding_from_tower(TALLOC_CTX *mem_ctx,
124 struct epm_tower *tower,
125 struct dcerpc_binding **b_out);
126 NTSTATUS dcerpc_parse_binding(TALLOC_CTX *mem_ctx, const char *s, struct dcerpc_binding **b_out);
127 char *dcerpc_binding_string(TALLOC_CTX *mem_ctx, const struct dcerpc_binding *b);
128 struct GUID dcerpc_binding_get_object(const struct dcerpc_binding *b);
129 NTSTATUS dcerpc_binding_set_object(struct dcerpc_binding *b,
130 struct GUID object);
131 enum dcerpc_transport_t dcerpc_binding_get_transport(const struct dcerpc_binding *b);
132 NTSTATUS dcerpc_binding_set_transport(struct dcerpc_binding *b,
133 enum dcerpc_transport_t transport);
134 void dcerpc_binding_get_auth_info(const struct dcerpc_binding *b,
135 enum dcerpc_AuthType *_auth_type,
136 enum dcerpc_AuthLevel *_auth_level);
137 uint32_t dcerpc_binding_get_assoc_group_id(const struct dcerpc_binding *b);
138 NTSTATUS dcerpc_binding_set_assoc_group_id(struct dcerpc_binding *b,
139 uint32_t assoc_group_id);
140 struct ndr_syntax_id dcerpc_binding_get_abstract_syntax(const struct dcerpc_binding *b);
141 NTSTATUS dcerpc_binding_set_abstract_syntax(struct dcerpc_binding *b,
142 const struct ndr_syntax_id *syntax);
143 const char *dcerpc_binding_get_string_option(const struct dcerpc_binding *b,
144 const char *name);
145 char *dcerpc_binding_copy_string_option(TALLOC_CTX *mem_ctx,
146 const struct dcerpc_binding *b,
147 const char *name);
148 NTSTATUS dcerpc_binding_set_string_option(struct dcerpc_binding *b,
149 const char *name,
150 const char *value);
151 uint32_t dcerpc_binding_get_flags(const struct dcerpc_binding *b);
152 NTSTATUS dcerpc_binding_set_flags(struct dcerpc_binding *b,
153 uint32_t additional,
154 uint32_t clear);
155 NTSTATUS dcerpc_floor_get_lhs_data(const struct epm_floor *epm_floor, struct ndr_syntax_id *syntax);
156 const char *derpc_transport_string_by_transport(enum dcerpc_transport_t t);
157 enum dcerpc_transport_t dcerpc_transport_by_name(const char *name);
158 enum dcerpc_transport_t dcerpc_transport_by_tower(const struct epm_tower *tower);
160 /* The following definitions come from ../librpc/rpc/dcerpc_util.c */
162 void dcerpc_set_frag_length(DATA_BLOB *blob, uint16_t v);
163 uint16_t dcerpc_get_frag_length(const DATA_BLOB *blob);
164 void dcerpc_set_auth_length(DATA_BLOB *blob, uint16_t v);
165 uint8_t dcerpc_get_endian_flag(DATA_BLOB *blob);
166 const char *dcerpc_default_transport_endpoint(TALLOC_CTX *mem_ctx,
167 enum dcerpc_transport_t transport,
168 const struct ndr_interface_table *table);
171 * @brief Pull a dcerpc_auth structure, taking account of any auth
172 * padding in the blob. For request/response packets we pass
173 * the whole data blob, so auth_data_only must be set to false
174 * as the blob contains data+pad+auth and no just pad+auth.
176 * @param pkt - The ncacn_packet strcuture
177 * @param mem_ctx - The mem_ctx used to allocate dcerpc_auth elements
178 * @param pkt_trailer - The packet trailer data, usually the trailing
179 * auth_info blob, but in the request/response case
180 * this is the stub_and_verifier blob.
181 * @param auth - A preallocated dcerpc_auth *empty* structure
182 * @param auth_length - The length of the auth trail, sum of auth header
183 * lenght and pkt->auth_length
184 * @param auth_data_only - Whether the pkt_trailer includes only the auth_blob
185 * (+ padding) or also other data.
187 * @return - A NTSTATUS error code.
189 NTSTATUS dcerpc_pull_auth_trailer(struct ncacn_packet *pkt,
190 TALLOC_CTX *mem_ctx,
191 DATA_BLOB *pkt_trailer,
192 struct dcerpc_auth *auth,
193 uint32_t *auth_length,
194 bool auth_data_only);
195 struct tevent_req *dcerpc_read_ncacn_packet_send(TALLOC_CTX *mem_ctx,
196 struct tevent_context *ev,
197 struct tstream_context *stream);
198 NTSTATUS dcerpc_read_ncacn_packet_recv(struct tevent_req *req,
199 TALLOC_CTX *mem_ctx,
200 struct ncacn_packet **pkt,
201 DATA_BLOB *buffer);
203 /* The following definitions come from ../librpc/rpc/binding_handle.c */
205 struct dcerpc_binding_handle_ops {
206 const char *name;
208 bool (*is_connected)(struct dcerpc_binding_handle *h);
209 uint32_t (*set_timeout)(struct dcerpc_binding_handle *h,
210 uint32_t timeout);
212 void (*auth_info)(struct dcerpc_binding_handle *h,
213 enum dcerpc_AuthType *auth_type,
214 enum dcerpc_AuthLevel *auth_level);
216 struct tevent_req *(*raw_call_send)(TALLOC_CTX *mem_ctx,
217 struct tevent_context *ev,
218 struct dcerpc_binding_handle *h,
219 const struct GUID *object,
220 uint32_t opnum,
221 uint32_t in_flags,
222 const uint8_t *in_data,
223 size_t in_length);
224 NTSTATUS (*raw_call_recv)(struct tevent_req *req,
225 TALLOC_CTX *mem_ctx,
226 uint8_t **out_data,
227 size_t *out_length,
228 uint32_t *out_flags);
230 struct tevent_req *(*disconnect_send)(TALLOC_CTX *mem_ctx,
231 struct tevent_context *ev,
232 struct dcerpc_binding_handle *h);
233 NTSTATUS (*disconnect_recv)(struct tevent_req *req);
235 /* TODO: remove the following functions */
236 bool (*push_bigendian)(struct dcerpc_binding_handle *h);
237 bool (*ref_alloc)(struct dcerpc_binding_handle *h);
238 bool (*use_ndr64)(struct dcerpc_binding_handle *h);
239 void (*do_ndr_print)(struct dcerpc_binding_handle *h,
240 int ndr_flags,
241 const void *struct_ptr,
242 const struct ndr_interface_call *call);
243 void (*ndr_push_failed)(struct dcerpc_binding_handle *h,
244 NTSTATUS error,
245 const void *struct_ptr,
246 const struct ndr_interface_call *call);
247 void (*ndr_pull_failed)(struct dcerpc_binding_handle *h,
248 NTSTATUS error,
249 const DATA_BLOB *blob,
250 const struct ndr_interface_call *call);
251 NTSTATUS (*ndr_validate_in)(struct dcerpc_binding_handle *h,
252 TALLOC_CTX *mem_ctx,
253 const DATA_BLOB *blob,
254 const struct ndr_interface_call *call);
255 NTSTATUS (*ndr_validate_out)(struct dcerpc_binding_handle *h,
256 struct ndr_pull *pull_in,
257 const void *struct_ptr,
258 const struct ndr_interface_call *call);
261 struct dcerpc_binding_handle *_dcerpc_binding_handle_create(TALLOC_CTX *mem_ctx,
262 const struct dcerpc_binding_handle_ops *ops,
263 const struct GUID *object,
264 const struct ndr_interface_table *table,
265 void *pstate,
266 size_t psize,
267 const char *type,
268 const char *location);
269 #define dcerpc_binding_handle_create(mem_ctx, ops, object, table, \
270 state, type, location) \
271 _dcerpc_binding_handle_create(mem_ctx, ops, object, table, \
272 state, sizeof(type), #type, location)
274 void *_dcerpc_binding_handle_data(struct dcerpc_binding_handle *h);
275 #define dcerpc_binding_handle_data(_h, _type) \
276 talloc_get_type_abort(_dcerpc_binding_handle_data(_h), _type)
278 _DEPRECATED_ void dcerpc_binding_handle_set_sync_ev(struct dcerpc_binding_handle *h,
279 struct tevent_context *ev);
281 bool dcerpc_binding_handle_is_connected(struct dcerpc_binding_handle *h);
283 uint32_t dcerpc_binding_handle_set_timeout(struct dcerpc_binding_handle *h,
284 uint32_t timeout);
286 void dcerpc_binding_handle_auth_info(struct dcerpc_binding_handle *h,
287 enum dcerpc_AuthType *auth_type,
288 enum dcerpc_AuthLevel *auth_level);
290 struct tevent_req *dcerpc_binding_handle_raw_call_send(TALLOC_CTX *mem_ctx,
291 struct tevent_context *ev,
292 struct dcerpc_binding_handle *h,
293 const struct GUID *object,
294 uint32_t opnum,
295 uint32_t in_flags,
296 const uint8_t *in_data,
297 size_t in_length);
298 NTSTATUS dcerpc_binding_handle_raw_call_recv(struct tevent_req *req,
299 TALLOC_CTX *mem_ctx,
300 uint8_t **out_data,
301 size_t *out_length,
302 uint32_t *out_flags);
303 NTSTATUS dcerpc_binding_handle_raw_call(struct dcerpc_binding_handle *h,
304 const struct GUID *object,
305 uint32_t opnum,
306 uint32_t in_flags,
307 const uint8_t *in_data,
308 size_t in_length,
309 TALLOC_CTX *mem_ctx,
310 uint8_t **out_data,
311 size_t *out_length,
312 uint32_t *out_flags);
314 struct tevent_req *dcerpc_binding_handle_disconnect_send(TALLOC_CTX *mem_ctx,
315 struct tevent_context *ev,
316 struct dcerpc_binding_handle *h);
317 NTSTATUS dcerpc_binding_handle_disconnect_recv(struct tevent_req *req);
319 struct tevent_req *dcerpc_binding_handle_call_send(TALLOC_CTX *mem_ctx,
320 struct tevent_context *ev,
321 struct dcerpc_binding_handle *h,
322 const struct GUID *object,
323 const struct ndr_interface_table *table,
324 uint32_t opnum,
325 TALLOC_CTX *r_mem,
326 void *r_ptr);
327 NTSTATUS dcerpc_binding_handle_call_recv(struct tevent_req *req);
328 NTSTATUS dcerpc_binding_handle_call(struct dcerpc_binding_handle *h,
329 const struct GUID *object,
330 const struct ndr_interface_table *table,
331 uint32_t opnum,
332 TALLOC_CTX *r_mem,
333 void *r_ptr);
336 * Extract header information from a ncacn_packet
337 * as a dcerpc_sec_vt_header2 as used by the security verification trailer.
339 * @param[in] pkt a packet
341 * @return a dcerpc_sec_vt_header2
343 struct dcerpc_sec_vt_header2 dcerpc_sec_vt_header2_from_ncacn_packet(const struct ncacn_packet *pkt);
347 * Test if two dcerpc_sec_vt_header2 structures are equal
348 * without consideration of reserved fields.
350 * @param v1 a pointer to a dcerpc_sec_vt_header2 structure
351 * @param v2 a pointer to a dcerpc_sec_vt_header2 structure
353 * @retval true if *v1 equals *v2
355 bool dcerpc_sec_vt_header2_equal(const struct dcerpc_sec_vt_header2 *v1,
356 const struct dcerpc_sec_vt_header2 *v2);
359 * Check for consistency of the security verification trailer with the PDU header.
360 * See <a href="http://msdn.microsoft.com/en-us/library/cc243559.aspx">MS-RPCE 2.2.2.13</a>.
361 * A check with an empty trailer succeeds.
363 * @param[in] vt a pointer to the security verification trailer.
364 * @param[in] bitmask1 which flags were negotiated on the connection.
365 * @param[in] pcontext the syntaxes negotiatied for the presentation context.
366 * @param[in] header2 some fields from the PDU header.
368 * @retval true on success.
370 bool dcerpc_sec_verification_trailer_check(
371 const struct dcerpc_sec_verification_trailer *vt,
372 const uint32_t *bitmask1,
373 const struct dcerpc_sec_vt_pcontext *pcontext,
374 const struct dcerpc_sec_vt_header2 *header2);
377 * @brief check and optionally extract the Bind Time Features from
378 * the given ndr_syntax_id.
380 * <a href="http://msdn.microsoft.com/en-us/library/cc243715.aspx">MS-RPCE 3.3.1.5.3 Bind Time Feature Negotiation</a>.
382 * @param[in] s the syntax that should be checked.
384 * @param[out] features This is optional, it will be filled with the extracted
385 * features the on success, otherwise it's filled with 0.
387 * @return true if the syntax matches the 6CB71C2C-9812-4540 prefix with version 1, false otherwise.
389 * @see dcerpc_construct_bind_time_features
391 bool dcerpc_extract_bind_time_features(struct ndr_syntax_id syntax, uint64_t *features);
394 * @brief Construct a ndr_syntax_id used for Bind Time Features Negotiation.
396 * <a href="http://msdn.microsoft.com/en-us/library/cc243715.aspx">MS-RPCE 3.3.1.5.3 Bind Time Feature Negotiation</a>.
398 * @param[in] features The supported features.
400 * @return The ndr_syntax_id with the given features.
402 * @see dcerpc_extract_bind_time_features
404 struct ndr_syntax_id dcerpc_construct_bind_time_features(uint64_t features);
406 #define DCERPC_AUTH_PAD_LENGTH(stub_length) (\
407 (((stub_length) % DCERPC_AUTH_PAD_ALIGNMENT) > 0)?\
408 (DCERPC_AUTH_PAD_ALIGNMENT - (stub_length) % DCERPC_AUTH_PAD_ALIGNMENT):\
411 #endif /* __DEFAULT_LIBRPC_RPCCOMMON_H__ */