2 Unix SMB/CIFS implementation.
4 DCERPC client side interface structures
6 Copyright (C) Tim Potter 2003
7 Copyright (C) Andrew Tridgell 2003-2005
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 /* This is a public header file that is installed as part of Samba.
24 * If you remove any functions or change their signature, update
25 * the so version number. */
30 #include "../lib/util/data_blob.h"
31 #include "librpc/gen_ndr/dcerpc.h"
32 #include "../librpc/ndr/libndr.h"
34 enum dcerpc_transport_t
{
35 NCA_UNKNOWN
, NCACN_NP
, NCACN_IP_TCP
, NCACN_IP_UDP
, NCACN_VNS_IPC
,
36 NCACN_VNS_SPP
, NCACN_AT_DSP
, NCADG_AT_DDP
, NCALRPC
, NCACN_UNIX_STREAM
,
37 NCADG_UNIX_DGRAM
, NCACN_HTTP
, NCADG_IPX
, NCACN_SPX
};
40 this defines a generic security context for signed/sealed dcerpc pipes.
42 struct dcerpc_connection
;
43 struct gensec_settings
;
44 struct dcerpc_security
{
45 struct dcerpc_auth
*auth_info
;
46 struct gensec_security
*generic_state
;
48 /* get the session key */
49 NTSTATUS (*session_key
)(struct dcerpc_connection
*, DATA_BLOB
*);
53 this holds the information that is not specific to a particular rpc context_id
55 struct dcerpc_connection
{
57 uint32_t srv_max_xmit_frag
;
58 uint32_t srv_max_recv_frag
;
60 struct dcerpc_security security_state
;
61 const char *binding_string
;
62 struct tevent_context
*event_ctx
;
63 struct smb_iconv_convenience
*iconv_convenience
;
65 /** Directory in which to save ndrdump-parseable files */
66 const char *packet_log_dir
;
71 struct dcerpc_transport
{
72 enum dcerpc_transport_t transport
;
75 NTSTATUS (*shutdown_pipe
)(struct dcerpc_connection
*, NTSTATUS status
);
77 const char *(*peer_name
)(struct dcerpc_connection
*);
79 const char *(*target_hostname
)(struct dcerpc_connection
*);
81 /* send a request to the server */
82 NTSTATUS (*send_request
)(struct dcerpc_connection
*, DATA_BLOB
*, bool trigger_read
);
84 /* send a read request to the server */
85 NTSTATUS (*send_read
)(struct dcerpc_connection
*);
87 /* a callback to the dcerpc code when a full fragment
89 void (*recv_data
)(struct dcerpc_connection
*, DATA_BLOB
*, NTSTATUS status
);
92 /* Requests that have been sent, waiting for a reply */
93 struct rpc_request
*pending
;
95 /* Sync requests waiting to be shipped */
96 struct rpc_request
*request_queue
;
98 /* the next context_id to be assigned */
99 uint32_t next_context_id
;
103 this encapsulates a full dcerpc client side pipe
108 uint32_t assoc_group_id
;
110 struct ndr_syntax_id syntax
;
111 struct ndr_syntax_id transfer_syntax
;
113 struct dcerpc_connection
*conn
;
114 struct dcerpc_binding
*binding
;
116 /** the last fault code from a DCERPC fault */
117 uint32_t last_fault_code
;
119 /** timeout for individual rpc requests, in seconds */
120 uint32_t request_timeout
;
123 /* default timeout for all rpc requests, in seconds */
124 #define DCERPC_REQUEST_TIMEOUT 60
127 /* dcerpc pipe flags */
128 #define DCERPC_DEBUG_PRINT_IN (1<<0)
129 #define DCERPC_DEBUG_PRINT_OUT (1<<1)
130 #define DCERPC_DEBUG_PRINT_BOTH (DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT)
132 #define DCERPC_DEBUG_VALIDATE_IN (1<<2)
133 #define DCERPC_DEBUG_VALIDATE_OUT (1<<3)
134 #define DCERPC_DEBUG_VALIDATE_BOTH (DCERPC_DEBUG_VALIDATE_IN | DCERPC_DEBUG_VALIDATE_OUT)
136 #define DCERPC_CONNECT (1<<4)
137 #define DCERPC_SIGN (1<<5)
138 #define DCERPC_SEAL (1<<6)
140 #define DCERPC_PUSH_BIGENDIAN (1<<7)
141 #define DCERPC_PULL_BIGENDIAN (1<<8)
143 #define DCERPC_SCHANNEL (1<<9)
145 #define DCERPC_ANON_FALLBACK (1<<10)
147 /* use a 128 bit session key */
148 #define DCERPC_SCHANNEL_128 (1<<12)
150 /* check incoming pad bytes */
151 #define DCERPC_DEBUG_PAD_CHECK (1<<13)
153 /* set LIBNDR_FLAG_REF_ALLOC flag when decoding NDR */
154 #define DCERPC_NDR_REF_ALLOC (1<<14)
156 #define DCERPC_AUTH_OPTIONS (DCERPC_SEAL|DCERPC_SIGN|DCERPC_SCHANNEL|DCERPC_AUTH_SPNEGO|DCERPC_AUTH_KRB5|DCERPC_AUTH_NTLM)
158 /* select spnego auth */
159 #define DCERPC_AUTH_SPNEGO (1<<15)
161 /* select krb5 auth */
162 #define DCERPC_AUTH_KRB5 (1<<16)
164 #define DCERPC_SMB2 (1<<17)
166 /* select NTLM auth */
167 #define DCERPC_AUTH_NTLM (1<<18)
169 /* this triggers the DCERPC_PFC_FLAG_CONC_MPX flag in the bind request */
170 #define DCERPC_CONCURRENT_MULTIPLEX (1<<19)
172 /* this triggers the DCERPC_PFC_FLAG_SUPPORT_HEADER_SIGN flag in the bind request */
173 #define DCERPC_HEADER_SIGNING (1<<20)
175 /* use NDR64 transport */
176 #define DCERPC_NDR64 (1<<21)
178 /* this describes a binding to a particular transport/pipe */
179 struct dcerpc_binding
{
180 enum dcerpc_transport_t transport
;
181 struct ndr_syntax_id object
;
183 const char *target_hostname
;
184 const char *endpoint
;
185 const char **options
;
187 uint32_t assoc_group_id
;
191 struct dcerpc_pipe_connect
{
192 struct dcerpc_pipe
*pipe
;
193 struct dcerpc_binding
*binding
;
194 const char *pipe_name
;
195 const struct ndr_interface_table
*interface
;
196 struct cli_credentials
*creds
;
197 struct resolve_context
*resolve_ctx
;
201 enum rpc_request_state
{
208 handle for an async dcerpc request
211 struct rpc_request
*next
, *prev
;
212 struct dcerpc_pipe
*p
;
215 enum rpc_request_state state
;
220 /* this is used to distinguish bind and alter_context requests
221 from normal requests */
222 void (*recv_handler
)(struct rpc_request
*conn
,
223 DATA_BLOB
*blob
, struct ncacn_packet
*pkt
);
225 const struct GUID
*object
;
227 DATA_BLOB request_data
;
231 /* use by the ndr level async recv call */
233 const struct ndr_interface_table
*table
;
240 void (*callback
)(struct rpc_request
*);
250 struct socket_address
;
252 NTSTATUS
dcerpc_pipe_connect(TALLOC_CTX
*parent_ctx
,
253 struct dcerpc_pipe
**pp
,
255 const struct ndr_interface_table
*table
,
256 struct cli_credentials
*credentials
,
257 struct tevent_context
*ev
,
258 struct loadparm_context
*lp_ctx
);
259 NTSTATUS
dcerpc_ndr_request_recv(struct rpc_request
*req
);
260 struct rpc_request
*dcerpc_ndr_request_send(struct dcerpc_pipe
*p
,
261 const struct GUID
*object
,
262 const struct ndr_interface_table
*table
,
267 const char *dcerpc_server_name(struct dcerpc_pipe
*p
);
268 struct dcerpc_pipe
*dcerpc_pipe_init(TALLOC_CTX
*mem_ctx
, struct tevent_context
*ev
,
269 struct smb_iconv_convenience
*ic
);
270 NTSTATUS
dcerpc_pipe_open_smb(struct dcerpc_pipe
*p
,
271 struct smbcli_tree
*tree
,
272 const char *pipe_name
);
273 NTSTATUS
dcerpc_bind_auth_none(struct dcerpc_pipe
*p
,
274 const struct ndr_interface_table
*table
);
275 NTSTATUS
dcerpc_fetch_session_key(struct dcerpc_pipe
*p
,
276 DATA_BLOB
*session_key
);
277 struct composite_context
;
278 NTSTATUS
dcerpc_secondary_connection_recv(struct composite_context
*c
,
279 struct dcerpc_pipe
**p2
);
280 NTSTATUS
dcerpc_parse_binding(TALLOC_CTX
*mem_ctx
, const char *s
, struct dcerpc_binding
**b_out
);
282 struct composite_context
* dcerpc_pipe_connect_b_send(TALLOC_CTX
*parent_ctx
,
283 struct dcerpc_binding
*binding
,
284 const struct ndr_interface_table
*table
,
285 struct cli_credentials
*credentials
,
286 struct tevent_context
*ev
,
287 struct loadparm_context
*lp_ctx
);
289 NTSTATUS
dcerpc_pipe_connect_b_recv(struct composite_context
*c
, TALLOC_CTX
*mem_ctx
,
290 struct dcerpc_pipe
**p
);
292 NTSTATUS
dcerpc_pipe_connect_b(TALLOC_CTX
*parent_ctx
,
293 struct dcerpc_pipe
**pp
,
294 struct dcerpc_binding
*binding
,
295 const struct ndr_interface_table
*table
,
296 struct cli_credentials
*credentials
,
297 struct tevent_context
*ev
,
298 struct loadparm_context
*lp_ctx
);
299 const char *dcerpc_errstr(TALLOC_CTX
*mem_ctx
, uint32_t fault_code
);
301 NTSTATUS
dcerpc_pipe_auth(TALLOC_CTX
*mem_ctx
,
302 struct dcerpc_pipe
**p
,
303 struct dcerpc_binding
*binding
,
304 const struct ndr_interface_table
*table
,
305 struct cli_credentials
*credentials
,
306 struct loadparm_context
*lp_ctx
);
307 char *dcerpc_binding_string(TALLOC_CTX
*mem_ctx
, const struct dcerpc_binding
*b
);
308 NTSTATUS
dcerpc_secondary_connection(struct dcerpc_pipe
*p
,
309 struct dcerpc_pipe
**p2
,
310 struct dcerpc_binding
*b
);
311 NTSTATUS
dcerpc_bind_auth_schannel(TALLOC_CTX
*tmp_ctx
,
312 struct dcerpc_pipe
*p
,
313 const struct ndr_interface_table
*table
,
314 struct cli_credentials
*credentials
,
315 struct loadparm_context
*lp_ctx
,
317 struct tevent_context
*dcerpc_event_context(struct dcerpc_pipe
*p
);
318 NTSTATUS
dcerpc_init(struct loadparm_context
*lp_ctx
);
319 struct smbcli_tree
*dcerpc_smb_tree(struct dcerpc_connection
*c
);
320 uint16_t dcerpc_smb_fnum(struct dcerpc_connection
*c
);
321 NTSTATUS
dcerpc_secondary_context(struct dcerpc_pipe
*p
,
322 struct dcerpc_pipe
**pp2
,
323 const struct ndr_interface_table
*table
);
324 NTSTATUS
dcerpc_alter_context(struct dcerpc_pipe
*p
,
326 const struct ndr_syntax_id
*syntax
,
327 const struct ndr_syntax_id
*transfer_syntax
);
329 NTSTATUS
dcerpc_bind_auth(struct dcerpc_pipe
*p
,
330 const struct ndr_interface_table
*table
,
331 struct cli_credentials
*credentials
,
332 struct gensec_settings
*gensec_settings
,
333 uint8_t auth_type
, uint8_t auth_level
,
334 const char *service
);
335 struct composite_context
* dcerpc_pipe_connect_send(TALLOC_CTX
*parent_ctx
,
337 const struct ndr_interface_table
*table
,
338 struct cli_credentials
*credentials
,
339 struct tevent_context
*ev
, struct loadparm_context
*lp_ctx
);
340 NTSTATUS
dcerpc_pipe_connect_recv(struct composite_context
*c
,
342 struct dcerpc_pipe
**pp
);
344 NTSTATUS
dcerpc_epm_map_binding(TALLOC_CTX
*mem_ctx
, struct dcerpc_binding
*binding
,
345 const struct ndr_interface_table
*table
, struct tevent_context
*ev
,
346 struct loadparm_context
*lp_ctx
);
347 struct composite_context
* dcerpc_secondary_auth_connection_send(struct dcerpc_pipe
*p
,
348 struct dcerpc_binding
*binding
,
349 const struct ndr_interface_table
*table
,
350 struct cli_credentials
*credentials
,
351 struct loadparm_context
*lp_ctx
);
352 NTSTATUS
dcerpc_secondary_auth_connection_recv(struct composite_context
*c
,
354 struct dcerpc_pipe
**p
);
356 struct composite_context
* dcerpc_secondary_connection_send(struct dcerpc_pipe
*p
,
357 struct dcerpc_binding
*b
);
358 void dcerpc_log_packet(const char *lockdir
,
359 const struct ndr_interface_table
*ndr
,
360 uint32_t opnum
, uint32_t flags
,
362 NTSTATUS
dcerpc_binding_build_tower(TALLOC_CTX
*mem_ctx
,
363 const struct dcerpc_binding
*binding
,
364 struct epm_tower
*tower
);
366 NTSTATUS
dcerpc_floor_get_lhs_data(const struct epm_floor
*epm_floor
, struct ndr_syntax_id
*syntax
);
368 enum dcerpc_transport_t
dcerpc_transport_by_tower(const struct epm_tower
*tower
);
369 const char *derpc_transport_string_by_transport(enum dcerpc_transport_t t
);
371 NTSTATUS
dcerpc_ndr_request(struct dcerpc_pipe
*p
,
372 const struct GUID
*object
,
373 const struct ndr_interface_table
*table
,
378 NTSTATUS
dcerpc_binding_from_tower(TALLOC_CTX
*mem_ctx
,
379 struct epm_tower
*tower
,
380 struct dcerpc_binding
**b_out
);
382 NTSTATUS
dcerpc_request(struct dcerpc_pipe
*p
,
386 DATA_BLOB
*stub_data_in
,
387 DATA_BLOB
*stub_data_out
);
389 typedef NTSTATUS (*dcerpc_call_fn
) (struct dcerpc_pipe
*, TALLOC_CTX
*, void *);
391 enum dcerpc_transport_t
dcerpc_transport_by_endpoint_protocol(int prot
);
393 const char *dcerpc_floor_get_rhs_data(TALLOC_CTX
*mem_ctx
, struct epm_floor
*epm_floor
);
395 #endif /* __DCERPC_H__ */