Add unique IP address binding for client connections (EPM and ncacn_ip_tcp levels)
[Samba.git] / source3 / librpc / rpc / dcerpc.h
blob56d6d320fdeb7fa64a4d7544bee67ae52106e375
1 /*
2 Unix SMB/CIFS implementation.
4 DCERPC client side interface structures
6 Copyright (C) 2008 Jelmer Vernooij
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 /* This is a public header file that is installed as part of Samba.
23 * If you remove any functions or change their signature, update
24 * the so version number. */
26 #ifndef __DCERPC_H__
27 #define __DCERPC_H__
29 #define SMB_RPC_INTERFACE_VERSION 1
31 enum dcerpc_transport_t {
32 NCA_UNKNOWN, NCACN_NP, NCACN_IP_TCP, NCACN_IP_UDP, NCACN_VNS_IPC,
33 NCACN_VNS_SPP, NCACN_AT_DSP, NCADG_AT_DDP, NCALRPC, NCACN_UNIX_STREAM,
34 NCADG_UNIX_DGRAM, NCACN_HTTP, NCADG_IPX, NCACN_SPX, NCACN_INTERNAL };
36 /** this describes a binding to a particular transport/pipe */
37 struct dcerpc_binding {
38 enum dcerpc_transport_t transport;
39 struct ndr_syntax_id object;
40 const char *host;
41 const char *target_hostname;
42 const char *endpoint;
43 const char **options;
44 const char *localaddress;
45 uint32_t flags;
46 uint32_t assoc_group_id;
50 /* dcerpc pipe flags */
51 #define DCERPC_DEBUG_PRINT_IN (1<<0)
52 #define DCERPC_DEBUG_PRINT_OUT (1<<1)
53 #define DCERPC_DEBUG_PRINT_BOTH (DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT)
55 #define DCERPC_DEBUG_VALIDATE_IN (1<<2)
56 #define DCERPC_DEBUG_VALIDATE_OUT (1<<3)
57 #define DCERPC_DEBUG_VALIDATE_BOTH (DCERPC_DEBUG_VALIDATE_IN | DCERPC_DEBUG_VALIDATE_OUT)
59 #define DCERPC_CONNECT (1<<4)
60 #define DCERPC_SIGN (1<<5)
61 #define DCERPC_SEAL (1<<6)
63 #define DCERPC_PUSH_BIGENDIAN (1<<7)
64 #define DCERPC_PULL_BIGENDIAN (1<<8)
66 #define DCERPC_SCHANNEL (1<<9)
68 /* use a 128 bit session key */
69 #define DCERPC_SCHANNEL_128 (1<<12)
71 /* check incoming pad bytes */
72 #define DCERPC_DEBUG_PAD_CHECK (1<<13)
74 /* set LIBNDR_FLAG_REF_ALLOC flag when decoding NDR */
75 #define DCERPC_NDR_REF_ALLOC (1<<14)
77 #define DCERPC_AUTH_OPTIONS (DCERPC_SEAL|DCERPC_SIGN|DCERPC_SCHANNEL|DCERPC_AUTH_SPNEGO|DCERPC_AUTH_KRB5|DCERPC_AUTH_NTLM)
79 /* select spnego auth */
80 #define DCERPC_AUTH_SPNEGO (1<<15)
82 /* select krb5 auth */
83 #define DCERPC_AUTH_KRB5 (1<<16)
85 #define DCERPC_SMB2 (1<<17)
87 /* select NTLM auth */
88 #define DCERPC_AUTH_NTLM (1<<18)
90 /* this triggers the DCERPC_PFC_FLAG_CONC_MPX flag in the bind request */
91 #define DCERPC_CONCURRENT_MULTIPLEX (1<<19)
93 /* this triggers the DCERPC_PFC_FLAG_SUPPORT_HEADER_SIGN flag in the bind request */
94 #define DCERPC_HEADER_SIGNING (1<<20)
96 /* use NDR64 transport */
97 #define DCERPC_NDR64 (1<<21)
99 /* specify binding interface */
100 #define DCERPC_LOCALADDRESS (1<<22)
102 /* The following definitions come from librpc/rpc/binding.c */
104 const char *epm_floor_string(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor);
105 _PUBLIC_ char *dcerpc_binding_string(TALLOC_CTX *mem_ctx, const struct dcerpc_binding *b);
106 _PUBLIC_ NTSTATUS dcerpc_parse_binding(TALLOC_CTX *mem_ctx, const char *s, struct dcerpc_binding **b_out);
107 _PUBLIC_ NTSTATUS dcerpc_floor_get_lhs_data(const struct epm_floor *epm_floor,
108 struct ndr_syntax_id *syntax);
109 const char *dcerpc_floor_get_rhs_data(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor);
110 enum dcerpc_transport_t dcerpc_transport_by_endpoint_protocol(int prot);
111 _PUBLIC_ enum dcerpc_transport_t dcerpc_transport_by_tower(const struct epm_tower *tower);
112 _PUBLIC_ const char *derpc_transport_string_by_transport(enum dcerpc_transport_t t);
113 _PUBLIC_ NTSTATUS dcerpc_binding_from_tower(TALLOC_CTX *mem_ctx,
114 struct epm_tower *tower,
115 struct dcerpc_binding **b_out);
116 _PUBLIC_ NTSTATUS dcerpc_binding_build_tower(TALLOC_CTX *mem_ctx,
117 const struct dcerpc_binding *binding,
118 struct epm_tower *tower);
120 struct NL_AUTH_MESSAGE;
122 /* The following definitions come from librpc/rpc/dcerpc_helpers.c */
123 NTSTATUS dcerpc_push_ncacn_packet(TALLOC_CTX *mem_ctx,
124 enum dcerpc_pkt_type ptype,
125 uint8_t pfc_flags,
126 uint16_t auth_length,
127 uint32_t call_id,
128 union dcerpc_payload *u,
129 DATA_BLOB *blob);
130 NTSTATUS dcerpc_pull_ncacn_packet(TALLOC_CTX *mem_ctx,
131 const DATA_BLOB *blob,
132 struct ncacn_packet *r,
133 bool bigendian);
134 NTSTATUS dcerpc_push_schannel_bind(TALLOC_CTX *mem_ctx,
135 struct NL_AUTH_MESSAGE *r,
136 DATA_BLOB *blob);
137 NTSTATUS dcerpc_push_dcerpc_auth(TALLOC_CTX *mem_ctx,
138 enum dcerpc_AuthType auth_type,
139 enum dcerpc_AuthLevel auth_level,
140 uint8_t auth_pad_length,
141 uint32_t auth_context_id,
142 const DATA_BLOB *credentials,
143 DATA_BLOB *blob);
144 NTSTATUS dcerpc_pull_dcerpc_auth(TALLOC_CTX *mem_ctx,
145 const DATA_BLOB *blob,
146 struct dcerpc_auth *r,
147 bool bigendian);
148 NTSTATUS dcerpc_guess_sizes(struct pipe_auth_data *auth,
149 size_t header_len, size_t data_left,
150 size_t max_xmit_frag, size_t pad_alignment,
151 size_t *data_to_send, size_t *frag_len,
152 size_t *auth_len, size_t *pad_len);
153 NTSTATUS dcerpc_add_auth_footer(struct pipe_auth_data *auth,
154 size_t pad_len, DATA_BLOB *rpc_out);
155 NTSTATUS dcerpc_check_auth(struct pipe_auth_data *auth,
156 struct ncacn_packet *pkt,
157 DATA_BLOB *pkt_trailer,
158 size_t header_size,
159 DATA_BLOB *raw_pkt,
160 size_t *pad_len);
162 struct dcerpc_binding_handle;
163 struct GUID;
164 struct ndr_interface_table;
165 struct ndr_interface_call;
166 struct ndr_push;
167 struct ndr_pull;
168 struct tevent_context;
169 struct tstream_context;
171 struct tevent_req *dcerpc_read_ncacn_packet_send(TALLOC_CTX *mem_ctx,
172 struct tevent_context *ev,
173 struct tstream_context *stream);
174 NTSTATUS dcerpc_read_ncacn_packet_recv(struct tevent_req *req,
175 TALLOC_CTX *mem_ctx,
176 struct ncacn_packet **pkt,
177 DATA_BLOB *buffer);
180 * This is just a hack this should never be used in code,
181 * but it's needed to build the compat stubs for now
183 struct __do_not_use_dcerpc_pipe {
184 struct dcerpc_binding_handle *binding_handle;
186 #define dcerpc_pipe __do_not_use_dcerpc_pipe
189 struct dcerpc_binding_handle_ops {
190 const char *name;
192 bool (*is_connected)(struct dcerpc_binding_handle *h);
193 uint32_t (*set_timeout)(struct dcerpc_binding_handle *h,
194 uint32_t timeout);
196 struct tevent_req *(*raw_call_send)(TALLOC_CTX *mem_ctx,
197 struct tevent_context *ev,
198 struct dcerpc_binding_handle *h,
199 const struct GUID *object,
200 uint32_t opnum,
201 uint32_t in_flags,
202 const uint8_t *in_data,
203 size_t in_length);
204 NTSTATUS (*raw_call_recv)(struct tevent_req *req,
205 TALLOC_CTX *mem_ctx,
206 uint8_t **out_data,
207 size_t *out_length,
208 uint32_t *out_flags);
210 struct tevent_req *(*disconnect_send)(TALLOC_CTX *mem_ctx,
211 struct tevent_context *ev,
212 struct dcerpc_binding_handle *h);
213 NTSTATUS (*disconnect_recv)(struct tevent_req *req);
215 /* TODO: remove the following functions */
216 bool (*push_bigendian)(struct dcerpc_binding_handle *h);
217 bool (*ref_alloc)(struct dcerpc_binding_handle *h);
218 bool (*use_ndr64)(struct dcerpc_binding_handle *h);
219 void (*do_ndr_print)(struct dcerpc_binding_handle *h,
220 int ndr_flags,
221 const void *struct_ptr,
222 const struct ndr_interface_call *call);
223 void (*ndr_push_failed)(struct dcerpc_binding_handle *h,
224 NTSTATUS error,
225 const void *struct_ptr,
226 const struct ndr_interface_call *call);
227 void (*ndr_pull_failed)(struct dcerpc_binding_handle *h,
228 NTSTATUS error,
229 const DATA_BLOB *blob,
230 const struct ndr_interface_call *call);
231 NTSTATUS (*ndr_validate_in)(struct dcerpc_binding_handle *h,
232 TALLOC_CTX *mem_ctx,
233 const DATA_BLOB *blob,
234 const struct ndr_interface_call *call);
235 NTSTATUS (*ndr_validate_out)(struct dcerpc_binding_handle *h,
236 struct ndr_pull *pull_in,
237 const void *struct_ptr,
238 const struct ndr_interface_call *call);
241 struct dcerpc_binding_handle *_dcerpc_binding_handle_create(TALLOC_CTX *mem_ctx,
242 const struct dcerpc_binding_handle_ops *ops,
243 const struct GUID *object,
244 const struct ndr_interface_table *table,
245 void *pstate,
246 size_t psize,
247 const char *type,
248 const char *location);
249 #define dcerpc_binding_handle_create(mem_ctx, ops, object, table, \
250 state, type, location) \
251 _dcerpc_binding_handle_create(mem_ctx, ops, object, table, \
252 state, sizeof(type), #type, location)
254 void *_dcerpc_binding_handle_data(struct dcerpc_binding_handle *h);
255 #define dcerpc_binding_handle_data(_h, _type) \
256 talloc_get_type_abort(_dcerpc_binding_handle_data(_h), _type)
258 _DEPRECATED_ void dcerpc_binding_handle_set_ref_alloc(struct dcerpc_binding_handle *h,
259 bool ref_alloc);
261 _DEPRECATED_ void dcerpc_binding_handle_set_sync_ev(struct dcerpc_binding_handle *h,
262 struct tevent_context *ev);
264 bool dcerpc_binding_handle_is_connected(struct dcerpc_binding_handle *h);
266 uint32_t dcerpc_binding_handle_set_timeout(struct dcerpc_binding_handle *h,
267 uint32_t timeout);
269 struct tevent_req *dcerpc_binding_handle_raw_call_send(TALLOC_CTX *mem_ctx,
270 struct tevent_context *ev,
271 struct dcerpc_binding_handle *h,
272 const struct GUID *object,
273 uint32_t opnum,
274 uint32_t in_flags,
275 const uint8_t *in_data,
276 size_t in_length);
277 NTSTATUS dcerpc_binding_handle_raw_call_recv(struct tevent_req *req,
278 TALLOC_CTX *mem_ctx,
279 uint8_t **out_data,
280 size_t *out_length,
281 uint32_t *out_flags);
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);
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);
304 #endif /* __DCERPC_H__ */