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