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 epm_tower;
|
---|
34 | struct tevent_context;
|
---|
35 | struct tstream_context;
|
---|
36 |
|
---|
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 };
|
---|
41 |
|
---|
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;
|
---|
54 | };
|
---|
55 |
|
---|
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)
|
---|
60 |
|
---|
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)
|
---|
64 |
|
---|
65 | #define DCERPC_CONNECT (1<<4)
|
---|
66 | #define DCERPC_SIGN (1<<5)
|
---|
67 | #define DCERPC_SEAL (1<<6)
|
---|
68 |
|
---|
69 | #define DCERPC_PUSH_BIGENDIAN (1<<7)
|
---|
70 | #define DCERPC_PULL_BIGENDIAN (1<<8)
|
---|
71 |
|
---|
72 | #define DCERPC_SCHANNEL (1<<9)
|
---|
73 |
|
---|
74 | #define DCERPC_ANON_FALLBACK (1<<10)
|
---|
75 |
|
---|
76 | /* use a 128 bit session key */
|
---|
77 | #define DCERPC_SCHANNEL_128 (1<<12)
|
---|
78 |
|
---|
79 | /* check incoming pad bytes */
|
---|
80 | #define DCERPC_DEBUG_PAD_CHECK (1<<13)
|
---|
81 |
|
---|
82 | /* set LIBNDR_FLAG_REF_ALLOC flag when decoding NDR */
|
---|
83 | #define DCERPC_NDR_REF_ALLOC (1<<14)
|
---|
84 |
|
---|
85 | #define DCERPC_AUTH_OPTIONS (DCERPC_SEAL|DCERPC_SIGN|DCERPC_SCHANNEL|DCERPC_AUTH_SPNEGO|DCERPC_AUTH_KRB5|DCERPC_AUTH_NTLM)
|
---|
86 |
|
---|
87 | /* select spnego auth */
|
---|
88 | #define DCERPC_AUTH_SPNEGO (1<<15)
|
---|
89 |
|
---|
90 | /* select krb5 auth */
|
---|
91 | #define DCERPC_AUTH_KRB5 (1<<16)
|
---|
92 |
|
---|
93 | #define DCERPC_SMB2 (1<<17)
|
---|
94 |
|
---|
95 | /* select NTLM auth */
|
---|
96 | #define DCERPC_AUTH_NTLM (1<<18)
|
---|
97 |
|
---|
98 | /* this triggers the DCERPC_PFC_FLAG_CONC_MPX flag in the bind request */
|
---|
99 | #define DCERPC_CONCURRENT_MULTIPLEX (1<<19)
|
---|
100 |
|
---|
101 | /* this triggers the DCERPC_PFC_FLAG_SUPPORT_HEADER_SIGN flag in the bind request */
|
---|
102 | #define DCERPC_HEADER_SIGNING (1<<20)
|
---|
103 |
|
---|
104 | /* use NDR64 transport */
|
---|
105 | #define DCERPC_NDR64 (1<<21)
|
---|
106 |
|
---|
107 | /* specify binding interface */
|
---|
108 | #define DCERPC_LOCALADDRESS (1<<22)
|
---|
109 |
|
---|
110 | /* The following definitions come from ../librpc/rpc/dcerpc_error.c */
|
---|
111 |
|
---|
112 | const char *dcerpc_errstr(TALLOC_CTX *mem_ctx, uint32_t fault_code);
|
---|
113 | NTSTATUS dcerpc_fault_to_nt_status(uint32_t fault_code);
|
---|
114 |
|
---|
115 | /* The following definitions come from ../librpc/rpc/binding.c */
|
---|
116 |
|
---|
117 | const char *epm_floor_string(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor);
|
---|
118 | const char *dcerpc_floor_get_rhs_data(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor);
|
---|
119 | enum dcerpc_transport_t dcerpc_transport_by_endpoint_protocol(int prot);
|
---|
120 | struct dcerpc_binding *dcerpc_binding_dup(TALLOC_CTX *mem_ctx,
|
---|
121 | const struct dcerpc_binding *b);
|
---|
122 | NTSTATUS dcerpc_binding_build_tower(TALLOC_CTX *mem_ctx,
|
---|
123 | const struct dcerpc_binding *binding,
|
---|
124 | struct epm_tower *tower);
|
---|
125 | NTSTATUS dcerpc_binding_from_tower(TALLOC_CTX *mem_ctx,
|
---|
126 | struct epm_tower *tower,
|
---|
127 | struct dcerpc_binding **b_out);
|
---|
128 | NTSTATUS dcerpc_parse_binding(TALLOC_CTX *mem_ctx, const char *s, struct dcerpc_binding **b_out);
|
---|
129 | char *dcerpc_binding_string(TALLOC_CTX *mem_ctx, const struct dcerpc_binding *b);
|
---|
130 | NTSTATUS dcerpc_floor_get_lhs_data(const struct epm_floor *epm_floor, struct ndr_syntax_id *syntax);
|
---|
131 | const char *derpc_transport_string_by_transport(enum dcerpc_transport_t t);
|
---|
132 | enum dcerpc_transport_t dcerpc_transport_by_tower(const struct epm_tower *tower);
|
---|
133 |
|
---|
134 | /* The following definitions come from ../librpc/rpc/dcerpc_util.c */
|
---|
135 |
|
---|
136 | void dcerpc_set_frag_length(DATA_BLOB *blob, uint16_t v);
|
---|
137 | uint16_t dcerpc_get_frag_length(const DATA_BLOB *blob);
|
---|
138 | uint32_t dcerpc_get_call_id(const DATA_BLOB *blob);
|
---|
139 | void dcerpc_set_auth_length(DATA_BLOB *blob, uint16_t v);
|
---|
140 | uint8_t dcerpc_get_endian_flag(DATA_BLOB *blob);
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * @brief Pull a dcerpc_auth structure, taking account of any auth
|
---|
144 | * padding in the blob. For request/response packets we pass
|
---|
145 | * the whole data blob, so auth_data_only must be set to false
|
---|
146 | * as the blob contains data+pad+auth and no just pad+auth.
|
---|
147 | *
|
---|
148 | * @param pkt - The ncacn_packet strcuture
|
---|
149 | * @param mem_ctx - The mem_ctx used to allocate dcerpc_auth elements
|
---|
150 | * @param pkt_trailer - The packet trailer data, usually the trailing
|
---|
151 | * auth_info blob, but in the request/response case
|
---|
152 | * this is the stub_and_verifier blob.
|
---|
153 | * @param auth - A preallocated dcerpc_auth *empty* structure
|
---|
154 | * @param auth_length - The length of the auth trail, sum of auth header
|
---|
155 | * lenght and pkt->auth_length
|
---|
156 | * @param auth_data_only - Whether the pkt_trailer includes only the auth_blob
|
---|
157 | * (+ padding) or also other data.
|
---|
158 | *
|
---|
159 | * @return - A NTSTATUS error code.
|
---|
160 | */
|
---|
161 | NTSTATUS dcerpc_pull_auth_trailer(const struct ncacn_packet *pkt,
|
---|
162 | TALLOC_CTX *mem_ctx,
|
---|
163 | const DATA_BLOB *pkt_trailer,
|
---|
164 | struct dcerpc_auth *auth,
|
---|
165 | uint32_t *auth_length,
|
---|
166 | bool auth_data_only);
|
---|
167 | NTSTATUS dcerpc_verify_ncacn_packet_header(const struct ncacn_packet *pkt,
|
---|
168 | enum dcerpc_pkt_type ptype,
|
---|
169 | size_t max_auth_info,
|
---|
170 | uint8_t required_flags,
|
---|
171 | uint8_t optional_flags);
|
---|
172 | struct tevent_req *dcerpc_read_ncacn_packet_send(TALLOC_CTX *mem_ctx,
|
---|
173 | struct tevent_context *ev,
|
---|
174 | struct tstream_context *stream);
|
---|
175 | NTSTATUS dcerpc_read_ncacn_packet_recv(struct tevent_req *req,
|
---|
176 | TALLOC_CTX *mem_ctx,
|
---|
177 | struct ncacn_packet **pkt,
|
---|
178 | DATA_BLOB *buffer);
|
---|
179 |
|
---|
180 | /* The following definitions come from ../librpc/rpc/binding_handle.c */
|
---|
181 |
|
---|
182 | struct dcerpc_binding_handle_ops {
|
---|
183 | const char *name;
|
---|
184 |
|
---|
185 | bool (*is_connected)(struct dcerpc_binding_handle *h);
|
---|
186 | uint32_t (*set_timeout)(struct dcerpc_binding_handle *h,
|
---|
187 | uint32_t timeout);
|
---|
188 |
|
---|
189 | struct tevent_req *(*raw_call_send)(TALLOC_CTX *mem_ctx,
|
---|
190 | struct tevent_context *ev,
|
---|
191 | struct dcerpc_binding_handle *h,
|
---|
192 | const struct GUID *object,
|
---|
193 | uint32_t opnum,
|
---|
194 | uint32_t in_flags,
|
---|
195 | const uint8_t *in_data,
|
---|
196 | size_t in_length);
|
---|
197 | NTSTATUS (*raw_call_recv)(struct tevent_req *req,
|
---|
198 | TALLOC_CTX *mem_ctx,
|
---|
199 | uint8_t **out_data,
|
---|
200 | size_t *out_length,
|
---|
201 | uint32_t *out_flags);
|
---|
202 |
|
---|
203 | struct tevent_req *(*disconnect_send)(TALLOC_CTX *mem_ctx,
|
---|
204 | struct tevent_context *ev,
|
---|
205 | struct dcerpc_binding_handle *h);
|
---|
206 | NTSTATUS (*disconnect_recv)(struct tevent_req *req);
|
---|
207 |
|
---|
208 | /* TODO: remove the following functions */
|
---|
209 | bool (*push_bigendian)(struct dcerpc_binding_handle *h);
|
---|
210 | bool (*ref_alloc)(struct dcerpc_binding_handle *h);
|
---|
211 | bool (*use_ndr64)(struct dcerpc_binding_handle *h);
|
---|
212 | void (*do_ndr_print)(struct dcerpc_binding_handle *h,
|
---|
213 | int ndr_flags,
|
---|
214 | const void *struct_ptr,
|
---|
215 | const struct ndr_interface_call *call);
|
---|
216 | void (*ndr_push_failed)(struct dcerpc_binding_handle *h,
|
---|
217 | NTSTATUS error,
|
---|
218 | const void *struct_ptr,
|
---|
219 | const struct ndr_interface_call *call);
|
---|
220 | void (*ndr_pull_failed)(struct dcerpc_binding_handle *h,
|
---|
221 | NTSTATUS error,
|
---|
222 | const DATA_BLOB *blob,
|
---|
223 | const struct ndr_interface_call *call);
|
---|
224 | NTSTATUS (*ndr_validate_in)(struct dcerpc_binding_handle *h,
|
---|
225 | TALLOC_CTX *mem_ctx,
|
---|
226 | const DATA_BLOB *blob,
|
---|
227 | const struct ndr_interface_call *call);
|
---|
228 | NTSTATUS (*ndr_validate_out)(struct dcerpc_binding_handle *h,
|
---|
229 | struct ndr_pull *pull_in,
|
---|
230 | const void *struct_ptr,
|
---|
231 | const struct ndr_interface_call *call);
|
---|
232 | };
|
---|
233 |
|
---|
234 | struct dcerpc_binding_handle *_dcerpc_binding_handle_create(TALLOC_CTX *mem_ctx,
|
---|
235 | const struct dcerpc_binding_handle_ops *ops,
|
---|
236 | const struct GUID *object,
|
---|
237 | const struct ndr_interface_table *table,
|
---|
238 | void *pstate,
|
---|
239 | size_t psize,
|
---|
240 | const char *type,
|
---|
241 | const char *location);
|
---|
242 | #define dcerpc_binding_handle_create(mem_ctx, ops, object, table, \
|
---|
243 | state, type, location) \
|
---|
244 | _dcerpc_binding_handle_create(mem_ctx, ops, object, table, \
|
---|
245 | state, sizeof(type), #type, location)
|
---|
246 |
|
---|
247 | void *_dcerpc_binding_handle_data(struct dcerpc_binding_handle *h);
|
---|
248 | #define dcerpc_binding_handle_data(_h, _type) \
|
---|
249 | talloc_get_type_abort(_dcerpc_binding_handle_data(_h), _type)
|
---|
250 |
|
---|
251 | _DEPRECATED_ void dcerpc_binding_handle_set_sync_ev(struct dcerpc_binding_handle *h,
|
---|
252 | struct tevent_context *ev);
|
---|
253 |
|
---|
254 | bool dcerpc_binding_handle_is_connected(struct dcerpc_binding_handle *h);
|
---|
255 |
|
---|
256 | uint32_t dcerpc_binding_handle_set_timeout(struct dcerpc_binding_handle *h,
|
---|
257 | uint32_t timeout);
|
---|
258 |
|
---|
259 | struct tevent_req *dcerpc_binding_handle_raw_call_send(TALLOC_CTX *mem_ctx,
|
---|
260 | struct tevent_context *ev,
|
---|
261 | struct dcerpc_binding_handle *h,
|
---|
262 | const struct GUID *object,
|
---|
263 | uint32_t opnum,
|
---|
264 | uint32_t in_flags,
|
---|
265 | const uint8_t *in_data,
|
---|
266 | size_t in_length);
|
---|
267 | NTSTATUS dcerpc_binding_handle_raw_call_recv(struct tevent_req *req,
|
---|
268 | TALLOC_CTX *mem_ctx,
|
---|
269 | uint8_t **out_data,
|
---|
270 | size_t *out_length,
|
---|
271 | uint32_t *out_flags);
|
---|
272 | NTSTATUS dcerpc_binding_handle_raw_call(struct dcerpc_binding_handle *h,
|
---|
273 | const struct GUID *object,
|
---|
274 | uint32_t opnum,
|
---|
275 | uint32_t in_flags,
|
---|
276 | const uint8_t *in_data,
|
---|
277 | size_t in_length,
|
---|
278 | TALLOC_CTX *mem_ctx,
|
---|
279 | uint8_t **out_data,
|
---|
280 | size_t *out_length,
|
---|
281 | uint32_t *out_flags);
|
---|
282 |
|
---|
283 | struct tevent_req *dcerpc_binding_handle_disconnect_send(TALLOC_CTX *mem_ctx,
|
---|
284 | struct tevent_context *ev,
|
---|
285 | struct dcerpc_binding_handle *h);
|
---|
286 | NTSTATUS dcerpc_binding_handle_disconnect_recv(struct tevent_req *req);
|
---|
287 |
|
---|
288 | struct tevent_req *dcerpc_binding_handle_call_send(TALLOC_CTX *mem_ctx,
|
---|
289 | struct tevent_context *ev,
|
---|
290 | struct dcerpc_binding_handle *h,
|
---|
291 | const struct GUID *object,
|
---|
292 | const struct ndr_interface_table *table,
|
---|
293 | uint32_t opnum,
|
---|
294 | TALLOC_CTX *r_mem,
|
---|
295 | void *r_ptr);
|
---|
296 | NTSTATUS dcerpc_binding_handle_call_recv(struct tevent_req *req);
|
---|
297 | NTSTATUS dcerpc_binding_handle_call(struct dcerpc_binding_handle *h,
|
---|
298 | const struct GUID *object,
|
---|
299 | const struct ndr_interface_table *table,
|
---|
300 | uint32_t opnum,
|
---|
301 | TALLOC_CTX *r_mem,
|
---|
302 | void *r_ptr);
|
---|
303 |
|
---|
304 | /**
|
---|
305 | * Extract header information from a ncacn_packet
|
---|
306 | * as a dcerpc_sec_vt_header2 as used by the security verification trailer.
|
---|
307 | *
|
---|
308 | * @param[in] pkt a packet
|
---|
309 | *
|
---|
310 | * @return a dcerpc_sec_vt_header2
|
---|
311 | */
|
---|
312 | struct dcerpc_sec_vt_header2 dcerpc_sec_vt_header2_from_ncacn_packet(const struct ncacn_packet *pkt);
|
---|
313 |
|
---|
314 |
|
---|
315 | /**
|
---|
316 | * Test if two dcerpc_sec_vt_header2 structures are equal
|
---|
317 | * without consideration of reserved fields.
|
---|
318 | *
|
---|
319 | * @param v1 a pointer to a dcerpc_sec_vt_header2 structure
|
---|
320 | * @param v2 a pointer to a dcerpc_sec_vt_header2 structure
|
---|
321 | *
|
---|
322 | * @retval true if *v1 equals *v2
|
---|
323 | */
|
---|
324 | bool dcerpc_sec_vt_header2_equal(const struct dcerpc_sec_vt_header2 *v1,
|
---|
325 | const struct dcerpc_sec_vt_header2 *v2);
|
---|
326 |
|
---|
327 | /**
|
---|
328 | * Check for consistency of the security verification trailer with the PDU header.
|
---|
329 | * See <a href="http://msdn.microsoft.com/en-us/library/cc243559.aspx">MS-RPCE 2.2.2.13</a>.
|
---|
330 | * A check with an empty trailer succeeds.
|
---|
331 | *
|
---|
332 | * @param[in] vt a pointer to the security verification trailer.
|
---|
333 | * @param[in] bitmask1 which flags were negotiated on the connection.
|
---|
334 | * @param[in] pcontext the syntaxes negotiatied for the presentation context.
|
---|
335 | * @param[in] header2 some fields from the PDU header.
|
---|
336 | *
|
---|
337 | * @retval true on success.
|
---|
338 | */
|
---|
339 | bool dcerpc_sec_verification_trailer_check(
|
---|
340 | const struct dcerpc_sec_verification_trailer *vt,
|
---|
341 | const uint32_t *bitmask1,
|
---|
342 | const struct dcerpc_sec_vt_pcontext *pcontext,
|
---|
343 | const struct dcerpc_sec_vt_header2 *header2);
|
---|
344 |
|
---|
345 | #endif /* __DEFAULT_LIBRPC_RPCCOMMON_H__ */
|
---|