2 Unix SMB/CIFS implementation.
4 Copyright (C) Rafal Szczesniak 2005
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 a composite function for name resolving
26 #include "libcli/raw/libcliraw.h"
27 #include "lib/events/events.h"
28 #include "libnet/libnet.h"
29 #include "libcli/composite/composite.h"
30 #include "libnet/composite.h"
31 #include "librpc/gen_ndr/ndr_nbt.h"
35 struct composite_context *resolve_ctx;
36 struct nbt_name hostname;
41 * Sends asynchronous Lookup request
43 * @param io arguments and result of the call
46 struct composite_context *libnet_Lookup_send(struct libnet_context *ctx,
47 struct libnet_Lookup *io)
49 struct composite_context *c;
50 struct lookup_state *s;
55 /* allocate context and state structures */
56 c = talloc_zero(NULL, struct composite_context);
57 if (c == NULL) goto failed;
59 s = talloc_zero(c, struct lookup_state);
60 if (s == NULL) goto failed;
62 /* prepare event context */
63 c->event_ctx = event_context_find(c);
64 if (c->event_ctx == NULL) goto failed;
67 s->hostname.name = talloc_strdup(s, io->in.hostname);
68 s->hostname.type = io->in.type;
69 s->hostname.scope = NULL;
71 /* name resolution methods */
73 methods = io->in.methods;
75 methods = (const char**)ctx->name_res_methods;
79 c->state = COMPOSITE_STATE_IN_PROGRESS;
81 /* send resolve request */
82 s->resolve_ctx = resolve_name_send(&s->hostname, c->event_ctx, methods);
93 * Waits for and receives results of asynchronous Lookup call
95 * @param c composite context returned by asynchronous Lookup call
96 * @param mem_ctx memory context of the call
97 * @param io pointer to results (and arguments) of the call
98 * @return nt status code of execution
101 NTSTATUS libnet_Lookup_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
102 struct libnet_Lookup *io)
105 struct lookup_state *s;
108 s = talloc_get_type(c->private_data, struct lookup_state);
110 status = resolve_name_recv(s->resolve_ctx, mem_ctx, &address);
111 if (NT_STATUS_IS_OK(status)) {
112 io->out.address = str_list_make(mem_ctx, address, NULL);
113 NT_STATUS_HAVE_NO_MEMORY(io->out.address);
121 * Synchronous version of Lookup call
123 * @param mem_ctx memory context for the call
124 * @param io arguments and results of the call
125 * @return nt status code of execution
128 NTSTATUS libnet_Lookup(struct libnet_context *ctx, TALLOC_CTX *mem_ctx,
129 struct libnet_Lookup *io)
131 struct composite_context *c = libnet_Lookup_send(ctx, io);
132 return libnet_Lookup_recv(c, mem_ctx, io);
137 * Shortcut functions to find common types of name
138 * (and skip nbt name type argument)
143 * Sends asynchronous LookupHost request
145 struct composite_context* libnet_LookupHost_send(struct libnet_context *ctx,
146 struct libnet_Lookup *io)
148 io->in.type = NBT_NAME_SERVER;
149 return libnet_Lookup_send(ctx, io);
155 * Synchronous version of LookupHost call
157 NTSTATUS libnet_LookupHost(struct libnet_context *ctx, TALLOC_CTX *mem_ctx,
158 struct libnet_Lookup *io)
160 struct composite_context *c = libnet_LookupHost_send(ctx, io);
161 return libnet_Lookup_recv(c, mem_ctx, io);
166 * Sends asynchronous LookupPdc request
168 struct composite_context* libnet_LookupPdc_send(struct libnet_context *ctx,
169 struct libnet_Lookup *io)
171 io->in.type = NBT_NAME_PDC;
172 return libnet_Lookup_send(ctx, io);
177 * Synchronous version of LookupPdc
179 NTSTATUS libnet_LookupPdc(struct libnet_context *ctx, TALLOC_CTX *mem_ctx,
180 struct libnet_Lookup *io)
182 struct composite_context *c = libnet_LookupPdc_send(ctx, io);
183 return libnet_Lookup_recv(c, mem_ctx, io);