s3-rpc_server: Added helper functions to read data from a ncacn socket.
[abartlet/samba.git/.git] / source3 / librpc / rpc / dcerpc.h
1 /* 
2    Unix SMB/CIFS implementation.
3
4    DCERPC client side interface structures
5
6    Copyright (C) 2008 Jelmer Vernooij
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 /* 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. */
25
26 #ifndef __DCERPC_H__
27 #define __DCERPC_H__
28
29 #define SMB_RPC_INTERFACE_VERSION 1
30
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 };
35
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;
47 };
48
49
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)
54
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)
58
59 #define DCERPC_CONNECT                 (1<<4)
60 #define DCERPC_SIGN                    (1<<5)
61 #define DCERPC_SEAL                    (1<<6)
62
63 #define DCERPC_PUSH_BIGENDIAN          (1<<7)
64 #define DCERPC_PULL_BIGENDIAN          (1<<8)
65
66 #define DCERPC_SCHANNEL                (1<<9)
67
68 /* use a 128 bit session key */
69 #define DCERPC_SCHANNEL_128            (1<<12)
70
71 /* check incoming pad bytes */
72 #define DCERPC_DEBUG_PAD_CHECK         (1<<13)
73
74 /* set LIBNDR_FLAG_REF_ALLOC flag when decoding NDR */
75 #define DCERPC_NDR_REF_ALLOC           (1<<14)
76
77 #define DCERPC_AUTH_OPTIONS    (DCERPC_SEAL|DCERPC_SIGN|DCERPC_SCHANNEL|DCERPC_AUTH_SPNEGO|DCERPC_AUTH_KRB5|DCERPC_AUTH_NTLM)
78
79 /* select spnego auth */
80 #define DCERPC_AUTH_SPNEGO             (1<<15)
81
82 /* select krb5 auth */
83 #define DCERPC_AUTH_KRB5               (1<<16)
84
85 #define DCERPC_SMB2                    (1<<17)
86
87 /* select NTLM auth */
88 #define DCERPC_AUTH_NTLM               (1<<18)
89
90 /* this triggers the DCERPC_PFC_FLAG_CONC_MPX flag in the bind request */
91 #define DCERPC_CONCURRENT_MULTIPLEX     (1<<19)
92
93 /* this triggers the DCERPC_PFC_FLAG_SUPPORT_HEADER_SIGN flag in the bind request */
94 #define DCERPC_HEADER_SIGNING          (1<<20)
95
96 /* use NDR64 transport */
97 #define DCERPC_NDR64                   (1<<21)
98
99 /* specify binding interface */
100 #define DCERPC_LOCALADDRESS            (1<<22)
101
102 /* The following definitions come from librpc/rpc/binding.c  */
103
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);
119
120 struct NL_AUTH_MESSAGE;
121
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);
161
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;
170
171 /* from ../librpc/rpc/dcerpc_util.c */
172 void dcerpc_set_frag_length(DATA_BLOB *blob, uint16_t v);
173 uint16_t dcerpc_get_frag_length(const DATA_BLOB *blob);
174 void dcerpc_set_auth_length(DATA_BLOB *blob, uint16_t v);
175 struct tevent_req *dcerpc_read_ncacn_packet_send(TALLOC_CTX *mem_ctx,
176                                                  struct tevent_context *ev,
177                                                  struct tstream_context *stream);
178 NTSTATUS dcerpc_read_ncacn_packet_recv(struct tevent_req *req,
179                                        TALLOC_CTX *mem_ctx,
180                                        struct ncacn_packet **pkt,
181                                        DATA_BLOB *buffer);
182
183 /*
184  * This is just a hack this should never be used in code,
185  * but it's needed to build the compat stubs for now
186  */
187 struct __do_not_use_dcerpc_pipe {
188         struct dcerpc_binding_handle *binding_handle;
189 };
190 #define dcerpc_pipe __do_not_use_dcerpc_pipe
191
192
193 struct dcerpc_binding_handle_ops {
194         const char *name;
195
196         bool (*is_connected)(struct dcerpc_binding_handle *h);
197         uint32_t (*set_timeout)(struct dcerpc_binding_handle *h,
198                                 uint32_t timeout);
199
200         struct tevent_req *(*raw_call_send)(TALLOC_CTX *mem_ctx,
201                                             struct tevent_context *ev,
202                                             struct dcerpc_binding_handle *h,
203                                             const struct GUID *object,
204                                             uint32_t opnum,
205                                             uint32_t in_flags,
206                                             const uint8_t *in_data,
207                                             size_t in_length);
208         NTSTATUS (*raw_call_recv)(struct tevent_req *req,
209                                   TALLOC_CTX *mem_ctx,
210                                   uint8_t **out_data,
211                                   size_t *out_length,
212                                   uint32_t *out_flags);
213
214         struct tevent_req *(*disconnect_send)(TALLOC_CTX *mem_ctx,
215                                               struct tevent_context *ev,
216                                               struct dcerpc_binding_handle *h);
217         NTSTATUS (*disconnect_recv)(struct tevent_req *req);
218
219         /* TODO: remove the following functions */
220         bool (*push_bigendian)(struct dcerpc_binding_handle *h);
221         bool (*ref_alloc)(struct dcerpc_binding_handle *h);
222         bool (*use_ndr64)(struct dcerpc_binding_handle *h);
223         void (*do_ndr_print)(struct dcerpc_binding_handle *h,
224                              int ndr_flags,
225                              const void *struct_ptr,
226                              const struct ndr_interface_call *call);
227         void (*ndr_push_failed)(struct dcerpc_binding_handle *h,
228                                 NTSTATUS error,
229                                 const void *struct_ptr,
230                                 const struct ndr_interface_call *call);
231         void (*ndr_pull_failed)(struct dcerpc_binding_handle *h,
232                                 NTSTATUS error,
233                                 const DATA_BLOB *blob,
234                                 const struct ndr_interface_call *call);
235         NTSTATUS (*ndr_validate_in)(struct dcerpc_binding_handle *h,
236                                     TALLOC_CTX *mem_ctx,
237                                     const DATA_BLOB *blob,
238                                     const struct ndr_interface_call *call);
239         NTSTATUS (*ndr_validate_out)(struct dcerpc_binding_handle *h,
240                                      struct ndr_pull *pull_in,
241                                      const void *struct_ptr,
242                                      const struct ndr_interface_call *call);
243 };
244
245 struct dcerpc_binding_handle *_dcerpc_binding_handle_create(TALLOC_CTX *mem_ctx,
246                                         const struct dcerpc_binding_handle_ops *ops,
247                                         const struct GUID *object,
248                                         const struct ndr_interface_table *table,
249                                         void *pstate,
250                                         size_t psize,
251                                         const char *type,
252                                         const char *location);
253 #define dcerpc_binding_handle_create(mem_ctx, ops, object, table, \
254                                 state, type, location) \
255         _dcerpc_binding_handle_create(mem_ctx, ops, object, table, \
256                                 state, sizeof(type), #type, location)
257
258 void *_dcerpc_binding_handle_data(struct dcerpc_binding_handle *h);
259 #define dcerpc_binding_handle_data(_h, _type) \
260         talloc_get_type_abort(_dcerpc_binding_handle_data(_h), _type)
261
262 _DEPRECATED_ void dcerpc_binding_handle_set_ref_alloc(struct dcerpc_binding_handle *h,
263                                                       bool ref_alloc);
264
265 _DEPRECATED_ void dcerpc_binding_handle_set_sync_ev(struct dcerpc_binding_handle *h,
266                                                     struct tevent_context *ev);
267
268 bool dcerpc_binding_handle_is_connected(struct dcerpc_binding_handle *h);
269
270 uint32_t dcerpc_binding_handle_set_timeout(struct dcerpc_binding_handle *h,
271                                            uint32_t timeout);
272
273 struct tevent_req *dcerpc_binding_handle_raw_call_send(TALLOC_CTX *mem_ctx,
274                                                 struct tevent_context *ev,
275                                                 struct dcerpc_binding_handle *h,
276                                                 const struct GUID *object,
277                                                 uint32_t opnum,
278                                                 uint32_t in_flags,
279                                                 const uint8_t *in_data,
280                                                 size_t in_length);
281 NTSTATUS dcerpc_binding_handle_raw_call_recv(struct tevent_req *req,
282                                              TALLOC_CTX *mem_ctx,
283                                              uint8_t **out_data,
284                                              size_t *out_length,
285                                              uint32_t *out_flags);
286
287 struct tevent_req *dcerpc_binding_handle_disconnect_send(TALLOC_CTX *mem_ctx,
288                                                 struct tevent_context *ev,
289                                                 struct dcerpc_binding_handle *h);
290 NTSTATUS dcerpc_binding_handle_disconnect_recv(struct tevent_req *req);
291
292 struct tevent_req *dcerpc_binding_handle_call_send(TALLOC_CTX *mem_ctx,
293                                         struct tevent_context *ev,
294                                         struct dcerpc_binding_handle *h,
295                                         const struct GUID *object,
296                                         const struct ndr_interface_table *table,
297                                         uint32_t opnum,
298                                         TALLOC_CTX *r_mem,
299                                         void *r_ptr);
300 NTSTATUS dcerpc_binding_handle_call_recv(struct tevent_req *req);
301 NTSTATUS dcerpc_binding_handle_call(struct dcerpc_binding_handle *h,
302                                     const struct GUID *object,
303                                     const struct ndr_interface_table *table,
304                                     uint32_t opnum,
305                                     TALLOC_CTX *r_mem,
306                                     void *r_ptr);
307
308 #endif /* __DCERPC_H__ */