librpc/rpc: move enum dcerpc_transport_t 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 /* The following definitions come from ../librpc/rpc/dcerpc_error.c  */
42
43 const char *dcerpc_errstr(TALLOC_CTX *mem_ctx, uint32_t fault_code);
44 NTSTATUS dcerpc_fault_to_nt_status(uint32_t fault_code);
45
46 /* The following definitions come from ../librpc/rpc/binding.c  */
47
48 const char *epm_floor_string(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor);
49 const char *dcerpc_floor_get_rhs_data(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor);
50 enum dcerpc_transport_t dcerpc_transport_by_endpoint_protocol(int prot);
51
52 /* The following definitions come from ../librpc/rpc/dcerpc_util.c  */
53
54 void dcerpc_set_frag_length(DATA_BLOB *blob, uint16_t v);
55 uint16_t dcerpc_get_frag_length(const DATA_BLOB *blob);
56 void dcerpc_set_auth_length(DATA_BLOB *blob, uint16_t v);
57 uint8_t dcerpc_get_endian_flag(DATA_BLOB *blob);
58
59 /**
60 * @brief        Pull a dcerpc_auth structure, taking account of any auth
61 *               padding in the blob. For request/response packets we pass
62 *               the whole data blob, so auth_data_only must be set to false
63 *               as the blob contains data+pad+auth and no just pad+auth.
64 *
65 * @param pkt            - The ncacn_packet strcuture
66 * @param mem_ctx        - The mem_ctx used to allocate dcerpc_auth elements
67 * @param pkt_trailer    - The packet trailer data, usually the trailing
68 *                         auth_info blob, but in the request/response case
69 *                         this is the stub_and_verifier blob.
70 * @param auth           - A preallocated dcerpc_auth *empty* structure
71 * @param auth_length    - The length of the auth trail, sum of auth header
72 *                         lenght and pkt->auth_length
73 * @param auth_data_only - Whether the pkt_trailer includes only the auth_blob
74 *                         (+ padding) or also other data.
75 *
76 * @return               - A NTSTATUS error code.
77 */
78 NTSTATUS dcerpc_pull_auth_trailer(struct ncacn_packet *pkt,
79                                   TALLOC_CTX *mem_ctx,
80                                   DATA_BLOB *pkt_trailer,
81                                   struct dcerpc_auth *auth,
82                                   uint32_t *auth_length,
83                                   bool auth_data_only);
84 struct tevent_req *dcerpc_read_ncacn_packet_send(TALLOC_CTX *mem_ctx,
85                                                  struct tevent_context *ev,
86                                                  struct tstream_context *stream);
87 NTSTATUS dcerpc_read_ncacn_packet_recv(struct tevent_req *req,
88                                        TALLOC_CTX *mem_ctx,
89                                        struct ncacn_packet **pkt,
90                                        DATA_BLOB *buffer);
91
92 /* The following definitions come from ../librpc/rpc/binding_handle.c  */
93
94 struct dcerpc_binding_handle_ops {
95         const char *name;
96
97         bool (*is_connected)(struct dcerpc_binding_handle *h);
98         uint32_t (*set_timeout)(struct dcerpc_binding_handle *h,
99                                 uint32_t timeout);
100
101         struct tevent_req *(*raw_call_send)(TALLOC_CTX *mem_ctx,
102                                             struct tevent_context *ev,
103                                             struct dcerpc_binding_handle *h,
104                                             const struct GUID *object,
105                                             uint32_t opnum,
106                                             uint32_t in_flags,
107                                             const uint8_t *in_data,
108                                             size_t in_length);
109         NTSTATUS (*raw_call_recv)(struct tevent_req *req,
110                                   TALLOC_CTX *mem_ctx,
111                                   uint8_t **out_data,
112                                   size_t *out_length,
113                                   uint32_t *out_flags);
114
115         struct tevent_req *(*disconnect_send)(TALLOC_CTX *mem_ctx,
116                                               struct tevent_context *ev,
117                                               struct dcerpc_binding_handle *h);
118         NTSTATUS (*disconnect_recv)(struct tevent_req *req);
119
120         /* TODO: remove the following functions */
121         bool (*push_bigendian)(struct dcerpc_binding_handle *h);
122         bool (*ref_alloc)(struct dcerpc_binding_handle *h);
123         bool (*use_ndr64)(struct dcerpc_binding_handle *h);
124         void (*do_ndr_print)(struct dcerpc_binding_handle *h,
125                              int ndr_flags,
126                              const void *struct_ptr,
127                              const struct ndr_interface_call *call);
128         void (*ndr_push_failed)(struct dcerpc_binding_handle *h,
129                                 NTSTATUS error,
130                                 const void *struct_ptr,
131                                 const struct ndr_interface_call *call);
132         void (*ndr_pull_failed)(struct dcerpc_binding_handle *h,
133                                 NTSTATUS error,
134                                 const DATA_BLOB *blob,
135                                 const struct ndr_interface_call *call);
136         NTSTATUS (*ndr_validate_in)(struct dcerpc_binding_handle *h,
137                                     TALLOC_CTX *mem_ctx,
138                                     const DATA_BLOB *blob,
139                                     const struct ndr_interface_call *call);
140         NTSTATUS (*ndr_validate_out)(struct dcerpc_binding_handle *h,
141                                      struct ndr_pull *pull_in,
142                                      const void *struct_ptr,
143                                      const struct ndr_interface_call *call);
144 };
145
146 struct dcerpc_binding_handle *_dcerpc_binding_handle_create(TALLOC_CTX *mem_ctx,
147                                         const struct dcerpc_binding_handle_ops *ops,
148                                         const struct GUID *object,
149                                         const struct ndr_interface_table *table,
150                                         void *pstate,
151                                         size_t psize,
152                                         const char *type,
153                                         const char *location);
154 #define dcerpc_binding_handle_create(mem_ctx, ops, object, table, \
155                                 state, type, location) \
156         _dcerpc_binding_handle_create(mem_ctx, ops, object, table, \
157                                 state, sizeof(type), #type, location)
158
159 void *_dcerpc_binding_handle_data(struct dcerpc_binding_handle *h);
160 #define dcerpc_binding_handle_data(_h, _type) \
161         talloc_get_type_abort(_dcerpc_binding_handle_data(_h), _type)
162
163 _DEPRECATED_ void dcerpc_binding_handle_set_sync_ev(struct dcerpc_binding_handle *h,
164                                                     struct tevent_context *ev);
165
166 bool dcerpc_binding_handle_is_connected(struct dcerpc_binding_handle *h);
167
168 uint32_t dcerpc_binding_handle_set_timeout(struct dcerpc_binding_handle *h,
169                                            uint32_t timeout);
170
171 struct tevent_req *dcerpc_binding_handle_raw_call_send(TALLOC_CTX *mem_ctx,
172                                                 struct tevent_context *ev,
173                                                 struct dcerpc_binding_handle *h,
174                                                 const struct GUID *object,
175                                                 uint32_t opnum,
176                                                 uint32_t in_flags,
177                                                 const uint8_t *in_data,
178                                                 size_t in_length);
179 NTSTATUS dcerpc_binding_handle_raw_call_recv(struct tevent_req *req,
180                                              TALLOC_CTX *mem_ctx,
181                                              uint8_t **out_data,
182                                              size_t *out_length,
183                                              uint32_t *out_flags);
184
185 struct tevent_req *dcerpc_binding_handle_disconnect_send(TALLOC_CTX *mem_ctx,
186                                                 struct tevent_context *ev,
187                                                 struct dcerpc_binding_handle *h);
188 NTSTATUS dcerpc_binding_handle_disconnect_recv(struct tevent_req *req);
189
190 struct tevent_req *dcerpc_binding_handle_call_send(TALLOC_CTX *mem_ctx,
191                                         struct tevent_context *ev,
192                                         struct dcerpc_binding_handle *h,
193                                         const struct GUID *object,
194                                         const struct ndr_interface_table *table,
195                                         uint32_t opnum,
196                                         TALLOC_CTX *r_mem,
197                                         void *r_ptr);
198 NTSTATUS dcerpc_binding_handle_call_recv(struct tevent_req *req);
199 NTSTATUS dcerpc_binding_handle_call(struct dcerpc_binding_handle *h,
200                                     const struct GUID *object,
201                                     const struct ndr_interface_table *table,
202                                     uint32_t opnum,
203                                     TALLOC_CTX *r_mem,
204                                     void *r_ptr);
205
206 #endif /* __DEFAULT_LIBRPC_RPCCOMMON_H__ */