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 "libcli/composite/monitor.h"
31 #include "libnet/composite.h"
32 #include "librpc/gen_ndr/ndr_nbt.h"
36 struct composite_context *resolve_ctx;
37 struct nbt_name hostname;
43 * Sends asynchronous Lookup request
45 * @param io arguments and result of the call
48 struct composite_context *libnet_Lookup_send(struct libnet_context *ctx,
49 struct libnet_Lookup *io)
51 struct composite_context *c;
52 struct lookup_state *s;
57 /* allocate context and state structures */
58 c = talloc_zero(NULL, struct composite_context);
59 if (c == NULL) goto failed;
61 s = talloc_zero(c, struct lookup_state);
62 if (s == NULL) goto failed;
64 /* prepare event context */
65 c->event_ctx = event_context_init(c);
66 if (c->event_ctx == NULL) goto failed;
69 s->hostname.name = talloc_strdup(s, io->in.hostname);
70 s->hostname.type = io->in.type;
71 s->hostname.scope = NULL;
72 s->address = io->out.address;
74 /* name resolution methods */
76 methods = io->in.methods;
78 methods = (const char**)ctx->name_res_methods;
82 c->state = SMBCLI_REQUEST_SEND;
84 /* send resolve request */
85 s->resolve_ctx = resolve_name_send(&s->hostname, c->event_ctx, methods);
96 * Waits for and receives results of asynchronous Lookup call
98 * @param c composite context returned by asynchronous Lookup call
99 * @param mem_ctx memory context of the call
100 * @param io pointer to results (and arguments) of the call
101 * @return nt status code of execution
104 NTSTATUS libnet_Lookup_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
105 struct libnet_Lookup *io)
108 struct lookup_state *s;
110 s = talloc_get_type(c->private, struct lookup_state);
112 status = resolve_name_recv(s->resolve_ctx, mem_ctx, s->address);
118 * Synchronous version of Lookup call
120 * @param mem_ctx memory context for the call
121 * @param io arguments and results of the call
122 * @return nt status code of execution
125 NTSTATUS libnet_Lookup(struct libnet_context *ctx, TALLOC_CTX *mem_ctx,
126 struct libnet_Lookup *io)
128 struct composite_context *c = libnet_Lookup_send(ctx, io);
129 return libnet_Lookup_recv(c, mem_ctx, io);
134 * Shortcut functions to find common types of name
135 * (and skip nbt name type argument)
140 * Sends asynchronous LookupHost request
142 struct composite_context* libnet_LookupHost_send(struct libnet_context *ctx,
143 struct libnet_Lookup *io)
145 io->in.type = NBT_NAME_SERVER;
146 return libnet_Lookup_send(ctx, io);
152 * Synchronous version of LookupHost call
154 NTSTATUS libnet_LookupHost(struct libnet_context *ctx, TALLOC_CTX *mem_ctx,
155 struct libnet_Lookup *io)
157 struct composite_context *c = libnet_LookupHost_send(ctx, io);
158 return libnet_Lookup_recv(c, mem_ctx, io);
163 * Sends asynchronous LookupPdc request
165 struct composite_context* libnet_LookupPdc_send(struct libnet_context *ctx,
166 struct libnet_Lookup *io)
168 io->in.type = NBT_NAME_PDC;
169 return libnet_Lookup_send(ctx, io);
174 * Synchronous version of LookupPdc
176 NTSTATUS libnet_LookupPdc(struct libnet_context *ctx, TALLOC_CTX *mem_ctx,
177 struct libnet_Lookup *io)
179 struct composite_context *c = libnet_LookupPdc_send(ctx, io);
180 return libnet_Lookup_recv(c, mem_ctx, io);