param: remove unused lp_copy_service
[Samba.git] / librpc / rpc / rpc_common.h
blobce7e6ea2722badecd3c0c116e1281704f8a2b5d8
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;
45 /* dcerpc pipe flags */
46 #define DCERPC_DEBUG_PRINT_IN (1<<0)
47 #define DCERPC_DEBUG_PRINT_OUT (1<<1)
48 #define DCERPC_DEBUG_PRINT_BOTH (DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT)
50 #define DCERPC_DEBUG_VALIDATE_IN (1<<2)
51 #define DCERPC_DEBUG_VALIDATE_OUT (1<<3)
52 #define DCERPC_DEBUG_VALIDATE_BOTH (DCERPC_DEBUG_VALIDATE_IN | DCERPC_DEBUG_VALIDATE_OUT)
54 #define DCERPC_CONNECT (1<<4)
55 #define DCERPC_SIGN (1<<5)
56 #define DCERPC_SEAL (1<<6)
58 #define DCERPC_PUSH_BIGENDIAN (1<<7)
59 #define DCERPC_PULL_BIGENDIAN (1<<8)
61 #define DCERPC_SCHANNEL (1<<9)
63 #define DCERPC_ANON_FALLBACK (1<<10)
65 /* use a 128 bit session key */
66 #define DCERPC_SCHANNEL_128 (1<<12)
68 /* check incoming pad bytes */
69 #define DCERPC_DEBUG_PAD_CHECK (1<<13)
71 /* set LIBNDR_FLAG_REF_ALLOC flag when decoding NDR */
72 #define DCERPC_NDR_REF_ALLOC (1<<14)
74 #define DCERPC_AUTH_OPTIONS (DCERPC_SEAL|DCERPC_SIGN|DCERPC_SCHANNEL|DCERPC_AUTH_SPNEGO|DCERPC_AUTH_KRB5|DCERPC_AUTH_NTLM)
76 /* select spnego auth */
77 #define DCERPC_AUTH_SPNEGO (1<<15)
79 /* select krb5 auth */
80 #define DCERPC_AUTH_KRB5 (1<<16)
82 #define DCERPC_SMB2 (1<<17)
84 /* select NTLM auth */
85 #define DCERPC_AUTH_NTLM (1<<18)
87 /* this triggers the DCERPC_PFC_FLAG_CONC_MPX flag in the bind request */
88 #define DCERPC_CONCURRENT_MULTIPLEX (1<<19)
90 /* this indicates DCERPC_PFC_FLAG_SUPPORT_HEADER_SIGN flag was negotiated */
91 #define DCERPC_HEADER_SIGNING (1<<20)
93 /* use NDR64 transport */
94 #define DCERPC_NDR64 (1<<21)
96 /* handle upgrades or downgrades automatically */
97 #define DCERPC_SCHANNEL_AUTO (1<<23)
99 /* use aes schannel with hmac-sh256 session key */
100 #define DCERPC_SCHANNEL_AES (1<<24)
102 /* this triggers the DCERPC_PFC_FLAG_SUPPORT_HEADER_SIGN flag in the bind request */
103 #define DCERPC_PROPOSE_HEADER_SIGNING (1<<25)
105 /* The following definitions come from ../librpc/rpc/dcerpc_error.c */
107 const char *dcerpc_errstr(TALLOC_CTX *mem_ctx, uint32_t fault_code);
108 NTSTATUS dcerpc_fault_to_nt_status(uint32_t fault_code);
110 /* The following definitions come from ../librpc/rpc/binding.c */
112 const char *epm_floor_string(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor);
113 char *dcerpc_floor_get_rhs_data(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor);
114 enum dcerpc_transport_t dcerpc_transport_by_endpoint_protocol(int prot);
115 struct dcerpc_binding *dcerpc_binding_dup(TALLOC_CTX *mem_ctx,
116 const struct dcerpc_binding *b);
117 NTSTATUS dcerpc_binding_build_tower(TALLOC_CTX *mem_ctx,
118 const struct dcerpc_binding *binding,
119 struct epm_tower *tower);
120 NTSTATUS dcerpc_binding_from_tower(TALLOC_CTX *mem_ctx,
121 struct epm_tower *tower,
122 struct dcerpc_binding **b_out);
123 NTSTATUS dcerpc_parse_binding(TALLOC_CTX *mem_ctx, const char *s, struct dcerpc_binding **b_out);
124 char *dcerpc_binding_string(TALLOC_CTX *mem_ctx, const struct dcerpc_binding *b);
125 struct GUID dcerpc_binding_get_object(const struct dcerpc_binding *b);
126 NTSTATUS dcerpc_binding_set_object(struct dcerpc_binding *b,
127 struct GUID object);
128 enum dcerpc_transport_t dcerpc_binding_get_transport(const struct dcerpc_binding *b);
129 NTSTATUS dcerpc_binding_set_transport(struct dcerpc_binding *b,
130 enum dcerpc_transport_t transport);
131 void dcerpc_binding_get_auth_info(const struct dcerpc_binding *b,
132 enum dcerpc_AuthType *_auth_type,
133 enum dcerpc_AuthLevel *_auth_level);
134 uint32_t dcerpc_binding_get_assoc_group_id(const struct dcerpc_binding *b);
135 NTSTATUS dcerpc_binding_set_assoc_group_id(struct dcerpc_binding *b,
136 uint32_t assoc_group_id);
137 struct ndr_syntax_id dcerpc_binding_get_abstract_syntax(const struct dcerpc_binding *b);
138 NTSTATUS dcerpc_binding_set_abstract_syntax(struct dcerpc_binding *b,
139 const struct ndr_syntax_id *syntax);
140 const char *dcerpc_binding_get_string_option(const struct dcerpc_binding *b,
141 const char *name);
142 char *dcerpc_binding_copy_string_option(TALLOC_CTX *mem_ctx,
143 const struct dcerpc_binding *b,
144 const char *name);
145 NTSTATUS dcerpc_binding_set_string_option(struct dcerpc_binding *b,
146 const char *name,
147 const char *value);
148 uint32_t dcerpc_binding_get_flags(const struct dcerpc_binding *b);
149 NTSTATUS dcerpc_binding_set_flags(struct dcerpc_binding *b,
150 uint32_t additional,
151 uint32_t clear);
152 NTSTATUS dcerpc_floor_get_lhs_data(const struct epm_floor *epm_floor, struct ndr_syntax_id *syntax);
153 const char *derpc_transport_string_by_transport(enum dcerpc_transport_t t);
154 enum dcerpc_transport_t dcerpc_transport_by_name(const char *name);
155 enum dcerpc_transport_t dcerpc_transport_by_tower(const struct epm_tower *tower);
157 /* The following definitions come from ../librpc/rpc/dcerpc_util.c */
159 void dcerpc_set_frag_length(DATA_BLOB *blob, uint16_t v);
160 uint16_t dcerpc_get_frag_length(const DATA_BLOB *blob);
161 void dcerpc_set_auth_length(DATA_BLOB *blob, uint16_t v);
162 uint8_t dcerpc_get_endian_flag(DATA_BLOB *blob);
163 const char *dcerpc_default_transport_endpoint(TALLOC_CTX *mem_ctx,
164 enum dcerpc_transport_t transport,
165 const struct ndr_interface_table *table);
168 * @brief Pull a dcerpc_auth structure, taking account of any auth
169 * padding in the blob. For request/response packets we pass
170 * the whole data blob, so auth_data_only must be set to false
171 * as the blob contains data+pad+auth and no just pad+auth.
173 * @param pkt - The ncacn_packet strcuture
174 * @param mem_ctx - The mem_ctx used to allocate dcerpc_auth elements
175 * @param pkt_trailer - The packet trailer data, usually the trailing
176 * auth_info blob, but in the request/response case
177 * this is the stub_and_verifier blob.
178 * @param auth - A preallocated dcerpc_auth *empty* structure
179 * @param auth_length - The length of the auth trail, sum of auth header
180 * lenght and pkt->auth_length
181 * @param auth_data_only - Whether the pkt_trailer includes only the auth_blob
182 * (+ padding) or also other data.
184 * @return - A NTSTATUS error code.
186 NTSTATUS dcerpc_pull_auth_trailer(struct ncacn_packet *pkt,
187 TALLOC_CTX *mem_ctx,
188 DATA_BLOB *pkt_trailer,
189 struct dcerpc_auth *auth,
190 uint32_t *auth_length,
191 bool auth_data_only);
192 struct tevent_req *dcerpc_read_ncacn_packet_send(TALLOC_CTX *mem_ctx,
193 struct tevent_context *ev,
194 struct tstream_context *stream);
195 NTSTATUS dcerpc_read_ncacn_packet_recv(struct tevent_req *req,
196 TALLOC_CTX *mem_ctx,
197 struct ncacn_packet **pkt,
198 DATA_BLOB *buffer);
200 /* The following definitions come from ../librpc/rpc/binding_handle.c */
202 struct dcerpc_binding_handle_ops {
203 const char *name;
205 bool (*is_connected)(struct dcerpc_binding_handle *h);
206 uint32_t (*set_timeout)(struct dcerpc_binding_handle *h,
207 uint32_t timeout);
209 void (*auth_info)(struct dcerpc_binding_handle *h,
210 enum dcerpc_AuthType *auth_type,
211 enum dcerpc_AuthLevel *auth_level);
213 struct tevent_req *(*raw_call_send)(TALLOC_CTX *mem_ctx,
214 struct tevent_context *ev,
215 struct dcerpc_binding_handle *h,
216 const struct GUID *object,
217 uint32_t opnum,
218 uint32_t in_flags,
219 const uint8_t *in_data,
220 size_t in_length);
221 NTSTATUS (*raw_call_recv)(struct tevent_req *req,
222 TALLOC_CTX *mem_ctx,
223 uint8_t **out_data,
224 size_t *out_length,
225 uint32_t *out_flags);
227 struct tevent_req *(*disconnect_send)(TALLOC_CTX *mem_ctx,
228 struct tevent_context *ev,
229 struct dcerpc_binding_handle *h);
230 NTSTATUS (*disconnect_recv)(struct tevent_req *req);
232 /* TODO: remove the following functions */
233 bool (*push_bigendian)(struct dcerpc_binding_handle *h);
234 bool (*ref_alloc)(struct dcerpc_binding_handle *h);
235 bool (*use_ndr64)(struct dcerpc_binding_handle *h);
236 void (*do_ndr_print)(struct dcerpc_binding_handle *h,
237 int ndr_flags,
238 const void *struct_ptr,
239 const struct ndr_interface_call *call);
240 void (*ndr_push_failed)(struct dcerpc_binding_handle *h,
241 NTSTATUS error,
242 const void *struct_ptr,
243 const struct ndr_interface_call *call);
244 void (*ndr_pull_failed)(struct dcerpc_binding_handle *h,
245 NTSTATUS error,
246 const DATA_BLOB *blob,
247 const struct ndr_interface_call *call);
248 NTSTATUS (*ndr_validate_in)(struct dcerpc_binding_handle *h,
249 TALLOC_CTX *mem_ctx,
250 const DATA_BLOB *blob,
251 const struct ndr_interface_call *call);
252 NTSTATUS (*ndr_validate_out)(struct dcerpc_binding_handle *h,
253 struct ndr_pull *pull_in,
254 const void *struct_ptr,
255 const struct ndr_interface_call *call);
258 struct dcerpc_binding_handle *_dcerpc_binding_handle_create(TALLOC_CTX *mem_ctx,
259 const struct dcerpc_binding_handle_ops *ops,
260 const struct GUID *object,
261 const struct ndr_interface_table *table,
262 void *pstate,
263 size_t psize,
264 const char *type,
265 const char *location);
266 #define dcerpc_binding_handle_create(mem_ctx, ops, object, table, \
267 state, type, location) \
268 _dcerpc_binding_handle_create(mem_ctx, ops, object, table, \
269 state, sizeof(type), #type, location)
271 void *_dcerpc_binding_handle_data(struct dcerpc_binding_handle *h);
272 #define dcerpc_binding_handle_data(_h, _type) \
273 talloc_get_type_abort(_dcerpc_binding_handle_data(_h), _type)
275 _DEPRECATED_ void dcerpc_binding_handle_set_sync_ev(struct dcerpc_binding_handle *h,
276 struct tevent_context *ev);
278 bool dcerpc_binding_handle_is_connected(struct dcerpc_binding_handle *h);
280 uint32_t dcerpc_binding_handle_set_timeout(struct dcerpc_binding_handle *h,
281 uint32_t timeout);
283 void dcerpc_binding_handle_auth_info(struct dcerpc_binding_handle *h,
284 enum dcerpc_AuthType *auth_type,
285 enum dcerpc_AuthLevel *auth_level);
287 struct tevent_req *dcerpc_binding_handle_raw_call_send(TALLOC_CTX *mem_ctx,
288 struct tevent_context *ev,
289 struct dcerpc_binding_handle *h,
290 const struct GUID *object,
291 uint32_t opnum,
292 uint32_t in_flags,
293 const uint8_t *in_data,
294 size_t in_length);
295 NTSTATUS dcerpc_binding_handle_raw_call_recv(struct tevent_req *req,
296 TALLOC_CTX *mem_ctx,
297 uint8_t **out_data,
298 size_t *out_length,
299 uint32_t *out_flags);
300 NTSTATUS dcerpc_binding_handle_raw_call(struct dcerpc_binding_handle *h,
301 const struct GUID *object,
302 uint32_t opnum,
303 uint32_t in_flags,
304 const uint8_t *in_data,
305 size_t in_length,
306 TALLOC_CTX *mem_ctx,
307 uint8_t **out_data,
308 size_t *out_length,
309 uint32_t *out_flags);
311 struct tevent_req *dcerpc_binding_handle_disconnect_send(TALLOC_CTX *mem_ctx,
312 struct tevent_context *ev,
313 struct dcerpc_binding_handle *h);
314 NTSTATUS dcerpc_binding_handle_disconnect_recv(struct tevent_req *req);
316 struct tevent_req *dcerpc_binding_handle_call_send(TALLOC_CTX *mem_ctx,
317 struct tevent_context *ev,
318 struct dcerpc_binding_handle *h,
319 const struct GUID *object,
320 const struct ndr_interface_table *table,
321 uint32_t opnum,
322 TALLOC_CTX *r_mem,
323 void *r_ptr);
324 NTSTATUS dcerpc_binding_handle_call_recv(struct tevent_req *req);
325 NTSTATUS dcerpc_binding_handle_call(struct dcerpc_binding_handle *h,
326 const struct GUID *object,
327 const struct ndr_interface_table *table,
328 uint32_t opnum,
329 TALLOC_CTX *r_mem,
330 void *r_ptr);
333 * Extract header information from a ncacn_packet
334 * as a dcerpc_sec_vt_header2 as used by the security verification trailer.
336 * @param[in] pkt a packet
338 * @return a dcerpc_sec_vt_header2
340 struct dcerpc_sec_vt_header2 dcerpc_sec_vt_header2_from_ncacn_packet(const struct ncacn_packet *pkt);
344 * Test if two dcerpc_sec_vt_header2 structures are equal
345 * without consideration of reserved fields.
347 * @param v1 a pointer to a dcerpc_sec_vt_header2 structure
348 * @param v2 a pointer to a dcerpc_sec_vt_header2 structure
350 * @retval true if *v1 equals *v2
352 bool dcerpc_sec_vt_header2_equal(const struct dcerpc_sec_vt_header2 *v1,
353 const struct dcerpc_sec_vt_header2 *v2);
356 * Check for consistency of the security verification trailer with the PDU header.
357 * See <a href="http://msdn.microsoft.com/en-us/library/cc243559.aspx">MS-RPCE 2.2.2.13</a>.
358 * A check with an empty trailer succeeds.
360 * @param[in] vt a pointer to the security verification trailer.
361 * @param[in] bitmask1 which flags were negotiated on the connection.
362 * @param[in] pcontext the syntaxes negotiatied for the presentation context.
363 * @param[in] header2 some fields from the PDU header.
365 * @retval true on success.
367 bool dcerpc_sec_verification_trailer_check(
368 const struct dcerpc_sec_verification_trailer *vt,
369 const uint32_t *bitmask1,
370 const struct dcerpc_sec_vt_pcontext *pcontext,
371 const struct dcerpc_sec_vt_header2 *header2);
373 #endif /* __DEFAULT_LIBRPC_RPCCOMMON_H__ */