librpc/rpc: move DCERPC_ flags to rpc_common.h
[samba.git] / librpc / rpc / rpc_common.h
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 tevent_context;
34 struct tstream_context;
35
36 enum dcerpc_transport_t {
37         NCA_UNKNOWN, NCACN_NP, NCACN_IP_TCP, NCACN_IP_UDP, NCACN_VNS_IPC, 
38         NCACN_VNS_SPP, NCACN_AT_DSP, NCADG_AT_DDP, NCALRPC, NCACN_UNIX_STREAM, 
39         NCADG_UNIX_DGRAM, NCACN_HTTP, NCADG_IPX, NCACN_SPX, NCACN_INTERNAL };
40
41 /** this describes a binding to a particular transport/pipe */
42 struct dcerpc_binding {
43         enum dcerpc_transport_t transport;
44         struct ndr_syntax_id object;
45         const char *host;
46         const char *target_hostname;
47         const char *target_principal;
48         const char *endpoint;
49         const char **options;
50         const char *localaddress;
51         uint32_t flags;
52         uint32_t assoc_group_id;
53 };
54
55 /* dcerpc pipe flags */
56 #define DCERPC_DEBUG_PRINT_IN          (1<<0)
57 #define DCERPC_DEBUG_PRINT_OUT         (1<<1)
58 #define DCERPC_DEBUG_PRINT_BOTH (DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT)
59
60 #define DCERPC_DEBUG_VALIDATE_IN       (1<<2)
61 #define DCERPC_DEBUG_VALIDATE_OUT      (1<<3)
62 #define DCERPC_DEBUG_VALIDATE_BOTH (DCERPC_DEBUG_VALIDATE_IN | DCERPC_DEBUG_VALIDATE_OUT)
63
64 #define DCERPC_CONNECT                 (1<<4)
65 #define DCERPC_SIGN                    (1<<5)
66 #define DCERPC_SEAL                    (1<<6)
67
68 #define DCERPC_PUSH_BIGENDIAN          (1<<7)
69 #define DCERPC_PULL_BIGENDIAN          (1<<8)
70
71 #define DCERPC_SCHANNEL                (1<<9)
72
73 #define DCERPC_ANON_FALLBACK           (1<<10)
74
75 /* use a 128 bit session key */
76 #define DCERPC_SCHANNEL_128            (1<<12)
77
78 /* check incoming pad bytes */
79 #define DCERPC_DEBUG_PAD_CHECK         (1<<13)
80
81 /* set LIBNDR_FLAG_REF_ALLOC flag when decoding NDR */
82 #define DCERPC_NDR_REF_ALLOC           (1<<14)
83
84 #define DCERPC_AUTH_OPTIONS    (DCERPC_SEAL|DCERPC_SIGN|DCERPC_SCHANNEL|DCERPC_AUTH_SPNEGO|DCERPC_AUTH_KRB5|DCERPC_AUTH_NTLM)
85
86 /* select spnego auth */
87 #define DCERPC_AUTH_SPNEGO             (1<<15)
88
89 /* select krb5 auth */
90 #define DCERPC_AUTH_KRB5               (1<<16)
91
92 #define DCERPC_SMB2                    (1<<17)
93
94 /* select NTLM auth */
95 #define DCERPC_AUTH_NTLM               (1<<18)
96
97 /* this triggers the DCERPC_PFC_FLAG_CONC_MPX flag in the bind request */
98 #define DCERPC_CONCURRENT_MULTIPLEX     (1<<19)
99
100 /* this triggers the DCERPC_PFC_FLAG_SUPPORT_HEADER_SIGN flag in the bind request */
101 #define DCERPC_HEADER_SIGNING          (1<<20)
102
103 /* use NDR64 transport */
104 #define DCERPC_NDR64                   (1<<21)
105
106 /* specify binding interface */
107 #define DCERPC_LOCALADDRESS            (1<<22)
108
109 /* The following definitions come from ../librpc/rpc/dcerpc_error.c  */
110
111 const char *dcerpc_errstr(TALLOC_CTX *mem_ctx, uint32_t fault_code);
112 NTSTATUS dcerpc_fault_to_nt_status(uint32_t fault_code);
113
114 /* The following definitions come from ../librpc/rpc/binding.c  */
115
116 const char *epm_floor_string(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor);
117 const char *dcerpc_floor_get_rhs_data(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor);
118 enum dcerpc_transport_t dcerpc_transport_by_endpoint_protocol(int prot);
119
120 /* The following definitions come from ../librpc/rpc/dcerpc_util.c  */
121
122 void dcerpc_set_frag_length(DATA_BLOB *blob, uint16_t v);
123 uint16_t dcerpc_get_frag_length(const DATA_BLOB *blob);
124 void dcerpc_set_auth_length(DATA_BLOB *blob, uint16_t v);
125 uint8_t dcerpc_get_endian_flag(DATA_BLOB *blob);
126
127 /**
128 * @brief        Pull a dcerpc_auth structure, taking account of any auth
129 *               padding in the blob. For request/response packets we pass
130 *               the whole data blob, so auth_data_only must be set to false
131 *               as the blob contains data+pad+auth and no just pad+auth.
132 *
133 * @param pkt            - The ncacn_packet strcuture
134 * @param mem_ctx        - The mem_ctx used to allocate dcerpc_auth elements
135 * @param pkt_trailer    - The packet trailer data, usually the trailing
136 *                         auth_info blob, but in the request/response case
137 *                         this is the stub_and_verifier blob.
138 * @param auth           - A preallocated dcerpc_auth *empty* structure
139 * @param auth_length    - The length of the auth trail, sum of auth header
140 *                         lenght and pkt->auth_length
141 * @param auth_data_only - Whether the pkt_trailer includes only the auth_blob
142 *                         (+ padding) or also other data.
143 *
144 * @return               - A NTSTATUS error code.
145 */
146 NTSTATUS dcerpc_pull_auth_trailer(struct ncacn_packet *pkt,
147                                   TALLOC_CTX *mem_ctx,
148                                   DATA_BLOB *pkt_trailer,
149                                   struct dcerpc_auth *auth,
150                                   uint32_t *auth_length,
151                                   bool auth_data_only);
152 struct tevent_req *dcerpc_read_ncacn_packet_send(TALLOC_CTX *mem_ctx,
153                                                  struct tevent_context *ev,
154                                                  struct tstream_context *stream);
155 NTSTATUS dcerpc_read_ncacn_packet_recv(struct tevent_req *req,
156                                        TALLOC_CTX *mem_ctx,
157                                        struct ncacn_packet **pkt,
158                                        DATA_BLOB *buffer);
159
160 /* The following definitions come from ../librpc/rpc/binding_handle.c  */
161
162 struct dcerpc_binding_handle_ops {
163         const char *name;
164
165         bool (*is_connected)(struct dcerpc_binding_handle *h);
166         uint32_t (*set_timeout)(struct dcerpc_binding_handle *h,
167                                 uint32_t timeout);
168
169         struct tevent_req *(*raw_call_send)(TALLOC_CTX *mem_ctx,
170                                             struct tevent_context *ev,
171                                             struct dcerpc_binding_handle *h,
172                                             const struct GUID *object,
173                                             uint32_t opnum,
174                                             uint32_t in_flags,
175                                             const uint8_t *in_data,
176                                             size_t in_length);
177         NTSTATUS (*raw_call_recv)(struct tevent_req *req,
178                                   TALLOC_CTX *mem_ctx,
179                                   uint8_t **out_data,
180                                   size_t *out_length,
181                                   uint32_t *out_flags);
182
183         struct tevent_req *(*disconnect_send)(TALLOC_CTX *mem_ctx,
184                                               struct tevent_context *ev,
185                                               struct dcerpc_binding_handle *h);
186         NTSTATUS (*disconnect_recv)(struct tevent_req *req);
187
188         /* TODO: remove the following functions */
189         bool (*push_bigendian)(struct dcerpc_binding_handle *h);
190         bool (*ref_alloc)(struct dcerpc_binding_handle *h);
191         bool (*use_ndr64)(struct dcerpc_binding_handle *h);
192         void (*do_ndr_print)(struct dcerpc_binding_handle *h,
193                              int ndr_flags,
194                              const void *struct_ptr,
195                              const struct ndr_interface_call *call);
196         void (*ndr_push_failed)(struct dcerpc_binding_handle *h,
197                                 NTSTATUS error,
198                                 const void *struct_ptr,
199                                 const struct ndr_interface_call *call);
200         void (*ndr_pull_failed)(struct dcerpc_binding_handle *h,
201                                 NTSTATUS error,
202                                 const DATA_BLOB *blob,
203                                 const struct ndr_interface_call *call);
204         NTSTATUS (*ndr_validate_in)(struct dcerpc_binding_handle *h,
205                                     TALLOC_CTX *mem_ctx,
206                                     const DATA_BLOB *blob,
207                                     const struct ndr_interface_call *call);
208         NTSTATUS (*ndr_validate_out)(struct dcerpc_binding_handle *h,
209                                      struct ndr_pull *pull_in,
210                                      const void *struct_ptr,
211                                      const struct ndr_interface_call *call);
212 };
213
214 struct dcerpc_binding_handle *_dcerpc_binding_handle_create(TALLOC_CTX *mem_ctx,
215                                         const struct dcerpc_binding_handle_ops *ops,
216                                         const struct GUID *object,
217                                         const struct ndr_interface_table *table,
218                                         void *pstate,
219                                         size_t psize,
220                                         const char *type,
221                                         const char *location);
222 #define dcerpc_binding_handle_create(mem_ctx, ops, object, table, \
223                                 state, type, location) \
224         _dcerpc_binding_handle_create(mem_ctx, ops, object, table, \
225                                 state, sizeof(type), #type, location)
226
227 void *_dcerpc_binding_handle_data(struct dcerpc_binding_handle *h);
228 #define dcerpc_binding_handle_data(_h, _type) \
229         talloc_get_type_abort(_dcerpc_binding_handle_data(_h), _type)
230
231 _DEPRECATED_ void dcerpc_binding_handle_set_sync_ev(struct dcerpc_binding_handle *h,
232                                                     struct tevent_context *ev);
233
234 bool dcerpc_binding_handle_is_connected(struct dcerpc_binding_handle *h);
235
236 uint32_t dcerpc_binding_handle_set_timeout(struct dcerpc_binding_handle *h,
237                                            uint32_t timeout);
238
239 struct tevent_req *dcerpc_binding_handle_raw_call_send(TALLOC_CTX *mem_ctx,
240                                                 struct tevent_context *ev,
241                                                 struct dcerpc_binding_handle *h,
242                                                 const struct GUID *object,
243                                                 uint32_t opnum,
244                                                 uint32_t in_flags,
245                                                 const uint8_t *in_data,
246                                                 size_t in_length);
247 NTSTATUS dcerpc_binding_handle_raw_call_recv(struct tevent_req *req,
248                                              TALLOC_CTX *mem_ctx,
249                                              uint8_t **out_data,
250                                              size_t *out_length,
251                                              uint32_t *out_flags);
252 NTSTATUS dcerpc_binding_handle_raw_call(struct dcerpc_binding_handle *h,
253                                         const struct GUID *object,
254                                         uint32_t opnum,
255                                         uint32_t in_flags,
256                                         const uint8_t *in_data,
257                                         size_t in_length,
258                                         TALLOC_CTX *mem_ctx,
259                                         uint8_t **out_data,
260                                         size_t *out_length,
261                                         uint32_t *out_flags);
262
263 struct tevent_req *dcerpc_binding_handle_disconnect_send(TALLOC_CTX *mem_ctx,
264                                                 struct tevent_context *ev,
265                                                 struct dcerpc_binding_handle *h);
266 NTSTATUS dcerpc_binding_handle_disconnect_recv(struct tevent_req *req);
267
268 struct tevent_req *dcerpc_binding_handle_call_send(TALLOC_CTX *mem_ctx,
269                                         struct tevent_context *ev,
270                                         struct dcerpc_binding_handle *h,
271                                         const struct GUID *object,
272                                         const struct ndr_interface_table *table,
273                                         uint32_t opnum,
274                                         TALLOC_CTX *r_mem,
275                                         void *r_ptr);
276 NTSTATUS dcerpc_binding_handle_call_recv(struct tevent_req *req);
277 NTSTATUS dcerpc_binding_handle_call(struct dcerpc_binding_handle *h,
278                                     const struct GUID *object,
279                                     const struct ndr_interface_table *table,
280                                     uint32_t opnum,
281                                     TALLOC_CTX *r_mem,
282                                     void *r_ptr);
283
284 #endif /* __DEFAULT_LIBRPC_RPCCOMMON_H__ */