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 "lib/events/events.h"
27 #include "libnet/libnet.h"
28 #include "libcli/composite/composite.h"
29 #include "lib/messaging/messaging.h"
30 #include "lib/messaging/irpc.h"
33 struct composite_context *resolve_ctx;
34 struct nbt_name hostname;
39 * Sends asynchronous Lookup request
41 * @param io arguments and result of the call
44 struct composite_context *libnet_Lookup_send(struct libnet_context *ctx,
45 struct libnet_Lookup *io)
47 struct composite_context *c;
48 struct lookup_state *s;
53 /* allocate context and state structures */
54 c = talloc_zero(NULL, struct composite_context);
55 if (c == NULL) goto failed;
57 s = talloc_zero(c, struct lookup_state);
58 if (s == NULL) goto failed;
60 /* prepare event context */
61 c->event_ctx = event_context_find(c);
62 if (c->event_ctx == NULL) goto failed;
65 s->hostname.name = talloc_strdup(s, io->in.hostname);
66 s->hostname.type = io->in.type;
67 s->hostname.scope = NULL;
69 /* name resolution methods */
71 methods = io->in.methods;
73 methods = (const char**)ctx->name_res_methods;
77 c->state = COMPOSITE_STATE_IN_PROGRESS;
79 /* send resolve request */
80 s->resolve_ctx = resolve_name_send(&s->hostname, c->event_ctx, methods);
91 * Waits for and receives results of asynchronous Lookup call
93 * @param c composite context returned by asynchronous Lookup call
94 * @param mem_ctx memory context of the call
95 * @param io pointer to results (and arguments) of the call
96 * @return nt status code of execution
99 NTSTATUS libnet_Lookup_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
100 struct libnet_Lookup *io)
103 struct lookup_state *s;
106 s = talloc_get_type(c->private_data, struct lookup_state);
108 status = resolve_name_recv(s->resolve_ctx, mem_ctx, &address);
109 if (NT_STATUS_IS_OK(status)) {
110 io->out.address = str_list_make(mem_ctx, address, NULL);
111 NT_STATUS_HAVE_NO_MEMORY(io->out.address);
119 * Synchronous version of Lookup call
121 * @param mem_ctx memory context for the call
122 * @param io arguments and results of the call
123 * @return nt status code of execution
126 NTSTATUS libnet_Lookup(struct libnet_context *ctx, TALLOC_CTX *mem_ctx,
127 struct libnet_Lookup *io)
129 struct composite_context *c = libnet_Lookup_send(ctx, io);
130 return libnet_Lookup_recv(c, mem_ctx, io);
135 * Shortcut functions to find common types of name
136 * (and skip nbt name type argument)
141 * Sends asynchronous LookupHost request
143 struct composite_context* libnet_LookupHost_send(struct libnet_context *ctx,
144 struct libnet_Lookup *io)
146 io->in.type = NBT_NAME_SERVER;
147 return libnet_Lookup_send(ctx, io);
153 * Synchronous version of LookupHost call
155 NTSTATUS libnet_LookupHost(struct libnet_context *ctx, TALLOC_CTX *mem_ctx,
156 struct libnet_Lookup *io)
158 struct composite_context *c = libnet_LookupHost_send(ctx, io);
159 return libnet_Lookup_recv(c, mem_ctx, io);
164 * Sends asynchronous LookupPdc request
166 struct composite_context* libnet_LookupDCs_send(struct libnet_context *ctx,
168 struct libnet_LookupDCs *io)
170 struct messaging_context *msg_ctx = messaging_client_init(mem_ctx, ctx->event_ctx);
171 struct composite_context *c;
172 c = finddcs_send(mem_ctx,
175 NULL, ctx->name_res_methods,
176 ctx->event_ctx, msg_ctx);
181 * Waits for and receives results of asynchronous Lookup call
183 * @param c composite context returned by asynchronous Lookup call
184 * @param mem_ctx memory context of the call
185 * @param io pointer to results (and arguments) of the call
186 * @return nt status code of execution
189 NTSTATUS libnet_LookupDCs_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
190 struct libnet_LookupDCs *io)
193 status = finddcs_recv(c, mem_ctx, &io->out.num_dcs, &io->out.dcs);
194 if (!NT_STATUS_IS_OK(status)) {
201 * Synchronous version of LookupPdc
203 NTSTATUS libnet_LookupDCs(struct libnet_context *ctx, TALLOC_CTX *mem_ctx,
204 struct libnet_LookupDCs *io)
206 struct composite_context *c = libnet_LookupDCs_send(ctx, mem_ctx, io);
207 return libnet_LookupDCs_recv(c, mem_ctx, io);