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/>.
25 #include "librpc/gen_ndr/nbt.h"
26 #include "librpc/ndr/libndr.h"
27 #include "lib/util/xfile.h"
30 possible states for pending requests
32 enum nbt_request_state {NBT_REQUEST_SEND,
41 struct nbt_name_request {
42 struct nbt_name_request *next, *prev;
44 enum nbt_request_state state;
48 /* the socket this was on */
49 struct nbt_name_socket *nbtsock;
51 /* where to send the request */
52 struct socket_address *dest;
54 /* timeout between retries */
57 /* how many retries to send on timeout */
60 /* whether we have received a WACK */
63 /* the timeout event */
64 struct tevent_timer *te;
66 /* the name transaction id */
72 /* the encoded request */
75 /* shall we allow multiple replies? */
76 bool allow_multiple_replies;
78 unsigned int num_replies;
79 struct nbt_name_reply {
80 struct nbt_name_packet *packet;
81 struct socket_address *dest;
84 /* information on what to do on completion */
86 void (*fn)(struct nbt_name_request *);
94 context structure for operations on name queries
96 struct nbt_name_socket {
97 struct socket_context *sock;
98 struct tevent_context *event_ctx;
100 /* a queue of requests pending to be sent */
101 struct nbt_name_request *send_queue;
104 struct tevent_fd *fde;
106 /* mapping from name_trn_id to pending event */
107 struct idr_context *idr;
109 /* how many requests are waiting for a reply */
110 uint16_t num_pending;
112 /* what to do with incoming request packets */
114 void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *,
115 struct socket_address *);
119 /* what to do with unexpected replies */
121 void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *,
122 struct socket_address *);
128 /* a simple name query */
129 struct nbt_name_query {
131 struct nbt_name name;
132 const char *dest_addr;
136 int timeout; /* in seconds */
140 const char *reply_from;
141 struct nbt_name name;
143 const char **reply_addrs;
147 /* a simple name status query */
148 struct nbt_name_status {
150 struct nbt_name name;
151 const char *dest_addr;
153 int timeout; /* in seconds */
157 const char *reply_from;
158 struct nbt_name name;
159 struct nbt_rdata_status status;
163 /* a name registration request */
164 struct nbt_name_register {
166 struct nbt_name name;
167 const char *dest_addr;
171 bool register_demand;
175 int timeout; /* in seconds */
179 const char *reply_from;
180 struct nbt_name name;
181 const char *reply_addr;
186 /* a send 3 times then demand name broadcast name registration */
187 struct nbt_name_register_bcast {
189 struct nbt_name name;
190 const char *dest_addr;
199 /* wins name register with multiple wins servers to try and multiple
200 addresses to register */
201 struct nbt_name_register_wins {
203 struct nbt_name name;
204 const char **wins_servers;
206 const char **addresses;
211 const char *wins_server;
218 /* a name refresh request */
219 struct nbt_name_refresh {
221 struct nbt_name name;
222 const char *dest_addr;
228 int timeout; /* in seconds */
232 const char *reply_from;
233 struct nbt_name name;
234 const char *reply_addr;
239 /* wins name refresh with multiple wins servers to try and multiple
240 addresses to register */
241 struct nbt_name_refresh_wins {
243 struct nbt_name name;
244 const char **wins_servers;
246 const char **addresses;
251 const char *wins_server;
257 /* a name release request */
258 struct nbt_name_release {
260 struct nbt_name name;
261 const char *dest_addr;
266 int timeout; /* in seconds */
270 const char *reply_from;
271 struct nbt_name name;
272 const char *reply_addr;
277 struct nbt_name_socket *nbt_name_socket_init(TALLOC_CTX *mem_ctx,
278 struct tevent_context *event_ctx);
279 void nbt_name_socket_handle_response_packet(struct nbt_name_request *req,
280 struct nbt_name_packet *packet,
281 struct socket_address *src);
282 struct nbt_name_request *nbt_name_query_send(struct nbt_name_socket *nbtsock,
283 struct nbt_name_query *io);
284 NTSTATUS nbt_name_query_recv(struct nbt_name_request *req,
285 TALLOC_CTX *mem_ctx, struct nbt_name_query *io);
286 NTSTATUS nbt_name_query(struct nbt_name_socket *nbtsock,
287 TALLOC_CTX *mem_ctx, struct nbt_name_query *io);
288 struct nbt_name_request *nbt_name_status_send(struct nbt_name_socket *nbtsock,
289 struct nbt_name_status *io);
290 NTSTATUS nbt_name_status_recv(struct nbt_name_request *req,
291 TALLOC_CTX *mem_ctx, struct nbt_name_status *io);
292 NTSTATUS nbt_name_status(struct nbt_name_socket *nbtsock,
293 TALLOC_CTX *mem_ctx, struct nbt_name_status *io);
295 NTSTATUS nbt_name_dup(TALLOC_CTX *mem_ctx, struct nbt_name *name, struct nbt_name *newname);
296 NTSTATUS nbt_name_to_blob(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, struct nbt_name *name);
297 NTSTATUS nbt_name_from_blob(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob, struct nbt_name *name);
298 void nbt_choose_called_name(TALLOC_CTX *mem_ctx, struct nbt_name *n, const char *name, int type);
299 char *nbt_name_string(TALLOC_CTX *mem_ctx, const struct nbt_name *name);
300 NTSTATUS nbt_name_register(struct nbt_name_socket *nbtsock,
301 TALLOC_CTX *mem_ctx, struct nbt_name_register *io);
302 NTSTATUS nbt_name_refresh(struct nbt_name_socket *nbtsock,
303 TALLOC_CTX *mem_ctx, struct nbt_name_refresh *io);
304 NTSTATUS nbt_name_release(struct nbt_name_socket *nbtsock,
305 TALLOC_CTX *mem_ctx, struct nbt_name_release *io);
306 NTSTATUS nbt_name_register_wins(struct nbt_name_socket *nbtsock,
308 struct nbt_name_register_wins *io);
309 NTSTATUS nbt_name_refresh_wins(struct nbt_name_socket *nbtsock,
311 struct nbt_name_refresh_wins *io);
312 NTSTATUS nbt_name_register_recv(struct nbt_name_request *req,
313 TALLOC_CTX *mem_ctx, struct nbt_name_register *io);
314 struct nbt_name_request *nbt_name_register_send(struct nbt_name_socket *nbtsock,
315 struct nbt_name_register *io);
316 NTSTATUS nbt_name_release_recv(struct nbt_name_request *req,
317 TALLOC_CTX *mem_ctx, struct nbt_name_release *io);
319 struct nbt_name_request *nbt_name_release_send(struct nbt_name_socket *nbtsock,
320 struct nbt_name_release *io);
322 NTSTATUS nbt_name_refresh_recv(struct nbt_name_request *req,
323 TALLOC_CTX *mem_ctx, struct nbt_name_refresh *io);
325 NTSTATUS nbt_set_incoming_handler(struct nbt_name_socket *nbtsock,
326 void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *,
327 struct socket_address *),
329 NTSTATUS nbt_set_unexpected_handler(struct nbt_name_socket *nbtsock,
330 void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *,
331 struct socket_address *),
333 NTSTATUS nbt_name_reply_send(struct nbt_name_socket *nbtsock,
334 struct socket_address *dest,
335 struct nbt_name_packet *request);
338 NDR_SCALAR_PTR_PROTO(wrepl_nbt_name, struct nbt_name)
339 NDR_BUFFER_PROTO(nbt_name, struct nbt_name)
340 NTSTATUS nbt_rcode_to_ntstatus(uint8_t rcode);
342 struct tevent_context;
344 struct tevent_req *nbt_name_register_bcast_send(TALLOC_CTX *mem_ctx,
345 struct tevent_context *ev,
346 struct nbt_name_socket *nbtsock,
347 struct nbt_name_register_bcast *io);
348 NTSTATUS nbt_name_register_bcast_recv(struct tevent_req *req);
349 struct tevent_req *nbt_name_register_wins_send(TALLOC_CTX *mem_ctx,
350 struct tevent_context *ev,
351 struct nbt_name_socket *nbtsock,
352 struct nbt_name_register_wins *io);
353 NTSTATUS nbt_name_register_wins_recv(struct tevent_req *req,
355 struct nbt_name_register_wins *io);
356 struct tevent_req *nbt_name_refresh_wins_send(TALLOC_CTX *mem_ctx,
357 struct tevent_context *ev,
358 struct nbt_name_socket *nbtsock,
359 struct nbt_name_refresh_wins *io);
360 NTSTATUS nbt_name_refresh_wins_recv(struct tevent_req *req,
362 struct nbt_name_refresh_wins *io);
364 XFILE *startlmhosts(const char *fname);
365 bool getlmhostsent(TALLOC_CTX *ctx, XFILE *fp, char **pp_name, int *name_type,
366 struct sockaddr_storage *pss);
367 void endlmhosts(XFILE *fp);
369 NTSTATUS resolve_lmhosts_file_as_sockaddr(const char *lmhosts_file,
370 const char *name, int name_type,
372 struct sockaddr_storage **return_iplist,
375 #endif /* __LIBNBT_H__ */