dbwrap: add a dbwrap_flags argument to db_open_tdb()
[Samba.git] / libcli / nbt / libnbt.h
blob5a29a027d8ecb1d65584f998b263160745951aa4
1 /*
2 Unix SMB/CIFS implementation.
4 a raw async NBT library
6 Copyright (C) Andrew Tridgell 2005
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 __LIBNBT_H__
23 #define __LIBNBT_H__
25 #include "librpc/gen_ndr/nbt.h"
26 #include "librpc/ndr/libndr.h"
28 possible states for pending requests
30 enum nbt_request_state {NBT_REQUEST_SEND,
31 NBT_REQUEST_WAIT,
32 NBT_REQUEST_DONE,
33 NBT_REQUEST_TIMEOUT,
34 NBT_REQUEST_ERROR};
37 a nbt name request
39 struct nbt_name_request {
40 struct nbt_name_request *next, *prev;
42 enum nbt_request_state state;
44 NTSTATUS status;
46 /* the socket this was on */
47 struct nbt_name_socket *nbtsock;
49 /* where to send the request */
50 struct socket_address *dest;
52 /* timeout between retries */
53 int timeout;
55 /* how many retries to send on timeout */
56 int num_retries;
58 /* whether we have received a WACK */
59 bool received_wack;
61 /* the timeout event */
62 struct tevent_timer *te;
64 /* the name transaction id */
65 uint16_t name_trn_id;
67 /* is it a reply? */
68 bool is_reply;
70 /* the encoded request */
71 DATA_BLOB encoded;
73 /* shall we allow multiple replies? */
74 bool allow_multiple_replies;
76 unsigned int num_replies;
77 struct nbt_name_reply {
78 struct nbt_name_packet *packet;
79 struct socket_address *dest;
80 } *replies;
82 /* information on what to do on completion */
83 struct {
84 void (*fn)(struct nbt_name_request *);
85 void *private_data;
86 } async;
92 context structure for operations on name queries
94 struct nbt_name_socket {
95 struct socket_context *sock;
96 struct tevent_context *event_ctx;
98 /* a queue of requests pending to be sent */
99 struct nbt_name_request *send_queue;
101 /* the fd event */
102 struct tevent_fd *fde;
104 /* mapping from name_trn_id to pending event */
105 struct idr_context *idr;
107 /* how many requests are waiting for a reply */
108 uint16_t num_pending;
110 /* what to do with incoming request packets */
111 struct {
112 void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *,
113 struct socket_address *);
114 void *private_data;
115 } incoming;
117 /* what to do with unexpected replies */
118 struct {
119 void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *,
120 struct socket_address *);
121 void *private_data;
122 } unexpected;
126 /* a simple name query */
127 struct nbt_name_query {
128 struct {
129 struct nbt_name name;
130 const char *dest_addr;
131 uint16_t dest_port;
132 bool broadcast;
133 bool wins_lookup;
134 int timeout; /* in seconds */
135 int retries;
136 } in;
137 struct {
138 const char *reply_from;
139 struct nbt_name name;
140 int16_t num_addrs;
141 const char **reply_addrs;
142 } out;
145 /* a simple name status query */
146 struct nbt_name_status {
147 struct {
148 struct nbt_name name;
149 const char *dest_addr;
150 uint16_t dest_port;
151 int timeout; /* in seconds */
152 int retries;
153 } in;
154 struct {
155 const char *reply_from;
156 struct nbt_name name;
157 struct nbt_rdata_status status;
158 } out;
161 /* a name registration request */
162 struct nbt_name_register {
163 struct {
164 struct nbt_name name;
165 const char *dest_addr;
166 uint16_t dest_port;
167 const char *address;
168 uint16_t nb_flags;
169 bool register_demand;
170 bool broadcast;
171 bool multi_homed;
172 uint32_t ttl;
173 int timeout; /* in seconds */
174 int retries;
175 } in;
176 struct {
177 const char *reply_from;
178 struct nbt_name name;
179 const char *reply_addr;
180 uint8_t rcode;
181 } out;
184 /* a send 3 times then demand name broadcast name registration */
185 struct nbt_name_register_bcast {
186 struct {
187 struct nbt_name name;
188 const char *dest_addr;
189 uint16_t dest_port;
190 const char *address;
191 uint16_t nb_flags;
192 uint32_t ttl;
193 } in;
197 /* wins name register with multiple wins servers to try and multiple
198 addresses to register */
199 struct nbt_name_register_wins {
200 struct {
201 struct nbt_name name;
202 const char **wins_servers;
203 uint16_t wins_port;
204 const char **addresses;
205 uint16_t nb_flags;
206 uint32_t ttl;
207 } in;
208 struct {
209 const char *wins_server;
210 uint8_t rcode;
211 } out;
216 /* a name refresh request */
217 struct nbt_name_refresh {
218 struct {
219 struct nbt_name name;
220 const char *dest_addr;
221 uint16_t dest_port;
222 const char *address;
223 uint16_t nb_flags;
224 bool broadcast;
225 uint32_t ttl;
226 int timeout; /* in seconds */
227 int retries;
228 } in;
229 struct {
230 const char *reply_from;
231 struct nbt_name name;
232 const char *reply_addr;
233 uint8_t rcode;
234 } out;
237 /* wins name refresh with multiple wins servers to try and multiple
238 addresses to register */
239 struct nbt_name_refresh_wins {
240 struct {
241 struct nbt_name name;
242 const char **wins_servers;
243 uint16_t wins_port;
244 const char **addresses;
245 uint16_t nb_flags;
246 uint32_t ttl;
247 } in;
248 struct {
249 const char *wins_server;
250 uint8_t rcode;
251 } out;
255 /* a name release request */
256 struct nbt_name_release {
257 struct {
258 struct nbt_name name;
259 const char *dest_addr;
260 uint16_t dest_port;
261 const char *address;
262 uint16_t nb_flags;
263 bool broadcast;
264 int timeout; /* in seconds */
265 int retries;
266 } in;
267 struct {
268 const char *reply_from;
269 struct nbt_name name;
270 const char *reply_addr;
271 uint8_t rcode;
272 } out;
275 struct nbt_name_socket *nbt_name_socket_init(TALLOC_CTX *mem_ctx,
276 struct tevent_context *event_ctx);
277 void nbt_name_socket_handle_response_packet(struct nbt_name_request *req,
278 struct nbt_name_packet *packet,
279 struct socket_address *src);
280 struct nbt_name_request *nbt_name_query_send(struct nbt_name_socket *nbtsock,
281 struct nbt_name_query *io);
282 NTSTATUS nbt_name_query_recv(struct nbt_name_request *req,
283 TALLOC_CTX *mem_ctx, struct nbt_name_query *io);
284 NTSTATUS nbt_name_query(struct nbt_name_socket *nbtsock,
285 TALLOC_CTX *mem_ctx, struct nbt_name_query *io);
286 struct nbt_name_request *nbt_name_status_send(struct nbt_name_socket *nbtsock,
287 struct nbt_name_status *io);
288 NTSTATUS nbt_name_status_recv(struct nbt_name_request *req,
289 TALLOC_CTX *mem_ctx, struct nbt_name_status *io);
290 NTSTATUS nbt_name_status(struct nbt_name_socket *nbtsock,
291 TALLOC_CTX *mem_ctx, struct nbt_name_status *io);
293 NTSTATUS nbt_name_dup(TALLOC_CTX *mem_ctx, struct nbt_name *name, struct nbt_name *newname);
294 NTSTATUS nbt_name_to_blob(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, struct nbt_name *name);
295 NTSTATUS nbt_name_from_blob(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob, struct nbt_name *name);
296 void nbt_choose_called_name(TALLOC_CTX *mem_ctx, struct nbt_name *n, const char *name, int type);
297 char *nbt_name_string(TALLOC_CTX *mem_ctx, const struct nbt_name *name);
298 NTSTATUS nbt_name_register(struct nbt_name_socket *nbtsock,
299 TALLOC_CTX *mem_ctx, struct nbt_name_register *io);
300 NTSTATUS nbt_name_refresh(struct nbt_name_socket *nbtsock,
301 TALLOC_CTX *mem_ctx, struct nbt_name_refresh *io);
302 NTSTATUS nbt_name_release(struct nbt_name_socket *nbtsock,
303 TALLOC_CTX *mem_ctx, struct nbt_name_release *io);
304 NTSTATUS nbt_name_register_wins(struct nbt_name_socket *nbtsock,
305 TALLOC_CTX *mem_ctx,
306 struct nbt_name_register_wins *io);
307 NTSTATUS nbt_name_refresh_wins(struct nbt_name_socket *nbtsock,
308 TALLOC_CTX *mem_ctx,
309 struct nbt_name_refresh_wins *io);
310 NTSTATUS nbt_name_register_recv(struct nbt_name_request *req,
311 TALLOC_CTX *mem_ctx, struct nbt_name_register *io);
312 struct nbt_name_request *nbt_name_register_send(struct nbt_name_socket *nbtsock,
313 struct nbt_name_register *io);
314 NTSTATUS nbt_name_release_recv(struct nbt_name_request *req,
315 TALLOC_CTX *mem_ctx, struct nbt_name_release *io);
317 struct nbt_name_request *nbt_name_release_send(struct nbt_name_socket *nbtsock,
318 struct nbt_name_release *io);
320 NTSTATUS nbt_name_refresh_recv(struct nbt_name_request *req,
321 TALLOC_CTX *mem_ctx, struct nbt_name_refresh *io);
323 NTSTATUS nbt_set_incoming_handler(struct nbt_name_socket *nbtsock,
324 void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *,
325 struct socket_address *),
326 void *private_data);
327 NTSTATUS nbt_set_unexpected_handler(struct nbt_name_socket *nbtsock,
328 void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *,
329 struct socket_address *),
330 void *private_data);
331 NTSTATUS nbt_name_reply_send(struct nbt_name_socket *nbtsock,
332 struct socket_address *dest,
333 struct nbt_name_packet *request);
336 NDR_SCALAR_PROTO(wrepl_nbt_name, const struct nbt_name *)
337 NDR_BUFFER_PROTO(nbt_name, struct nbt_name)
338 NTSTATUS nbt_rcode_to_ntstatus(uint8_t rcode);
340 struct tevent_context;
341 struct tevent_req;
342 struct tevent_req *nbt_name_register_bcast_send(TALLOC_CTX *mem_ctx,
343 struct tevent_context *ev,
344 struct nbt_name_socket *nbtsock,
345 struct nbt_name_register_bcast *io);
346 NTSTATUS nbt_name_register_bcast_recv(struct tevent_req *req);
347 struct tevent_req *nbt_name_register_wins_send(TALLOC_CTX *mem_ctx,
348 struct tevent_context *ev,
349 struct nbt_name_socket *nbtsock,
350 struct nbt_name_register_wins *io);
351 NTSTATUS nbt_name_register_wins_recv(struct tevent_req *req,
352 TALLOC_CTX *mem_ctx,
353 struct nbt_name_register_wins *io);
354 struct tevent_req *nbt_name_refresh_wins_send(TALLOC_CTX *mem_ctx,
355 struct tevent_context *ev,
356 struct nbt_name_socket *nbtsock,
357 struct nbt_name_refresh_wins *io);
358 NTSTATUS nbt_name_refresh_wins_recv(struct tevent_req *req,
359 TALLOC_CTX *mem_ctx,
360 struct nbt_name_refresh_wins *io);
362 XFILE *startlmhosts(const char *fname);
363 bool getlmhostsent(TALLOC_CTX *ctx, XFILE *fp, char **pp_name, int *name_type,
364 struct sockaddr_storage *pss);
365 void endlmhosts(XFILE *fp);
367 NTSTATUS resolve_lmhosts_file_as_sockaddr(const char *lmhosts_file,
368 const char *name, int name_type,
369 TALLOC_CTX *mem_ctx,
370 struct sockaddr_storage **return_iplist,
371 int *return_count);
373 NTSTATUS resolve_dns_hosts_file_as_sockaddr(const char *dns_hosts_file,
374 const char *name, bool srv_lookup,
375 TALLOC_CTX *mem_ctx,
376 struct sockaddr_storage **return_iplist,
377 int *return_count);
379 #endif /* __LIBNBT_H__ */