summaryrefslogtreecommitdiffstats
path: root/source4/libcli
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2014-01-14 13:48:32 +1300
committerMichael Adam <obnox@samba.org>2014-01-31 08:05:52 +0100
commitfc77a69461be8b31a6e5bdf92f82a9af8e67457c (patch)
treef93e7f096aad010c860da7e58f8b04bd142ae635 /source4/libcli
parent8427c797cecc88d70bdee4f310351ca3d4c310db (diff)
downloadsamba-fc77a69461be8b31a6e5bdf92f82a9af8e67457c.tar.gz
samba-fc77a69461be8b31a6e5bdf92f82a9af8e67457c.tar.xz
samba-fc77a69461be8b31a6e5bdf92f82a9af8e67457c.zip
s4-resolve: Add lmhosts support into the source4 name resolve code
Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'source4/libcli')
-rw-r--r--source4/libcli/resolve/lmhosts.c129
-rw-r--r--source4/libcli/resolve/resolve_lp.c2
-rwxr-xr-xsource4/libcli/wscript_build2
3 files changed, 132 insertions, 1 deletions
diff --git a/source4/libcli/resolve/lmhosts.c b/source4/libcli/resolve/lmhosts.c
new file mode 100644
index 0000000000..21cc3e4f00
--- /dev/null
+++ b/source4/libcli/resolve/lmhosts.c
@@ -0,0 +1,129 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ broadcast name resolution module
+
+ Copyright (C) Andrew Tridgell 1994-1998,2005
+ Copyright (C) Jeremy Allison 2007
+ Copyright (C) Jelmer Vernooij 2007
+ Copyright (C) Andrew Bartlett <abartlet@samba.org> 2009-2014
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "libcli/composite/composite.h"
+#include "libcli/resolve/resolve.h"
+#include "lib/socket/socket.h"
+#include "system/network.h"
+#include "lib/socket/netif.h"
+#include "param/param.h"
+#include "lib/util/util_net.h"
+#include "libcli/nbt/libnbt.h"
+#include "dynconfig.h"
+
+struct resolve_lmhosts_state {
+ struct socket_address **addrs;
+ char **names;
+};
+
+/**
+ broadcast name resolution method - async send
+ */
+/*
+ general name resolution - async send
+ */
+struct composite_context *resolve_name_lmhosts_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *event_ctx,
+ void *userdata, uint32_t flags,
+ uint16_t port,
+ struct nbt_name *name)
+{
+ struct composite_context *c;
+ struct resolve_lmhosts_state *state;
+ struct sockaddr_storage *resolved_iplist;
+ int resolved_count, i;
+
+ if (event_ctx == NULL) {
+ return NULL;
+ }
+
+ c = composite_create(mem_ctx, event_ctx);
+ if (c == NULL) return NULL;
+
+ if (composite_nomem(c->event_ctx, c)) return c;
+
+ state = talloc_zero(c, struct resolve_lmhosts_state);
+ if (composite_nomem(state, c)) return c;
+ c->private_data = state;
+
+ c->status = resolve_lmhosts_file_as_sockaddr(dyn_LMHOSTSFILE, name->name, name->type,
+ state, &resolved_iplist, &resolved_count);
+ if (!composite_is_ok(c)) return c;
+
+ for (i=0; i < resolved_count; i++) {
+ state->addrs = talloc_realloc(state, state->addrs, struct socket_address *, i+2);
+ if (composite_nomem(state->addrs, c)) return c;
+
+ set_sockaddr_port((struct sockaddr *)&resolved_iplist[i], port);
+
+ state->addrs[i] = socket_address_from_sockaddr(state->addrs, (struct sockaddr *)&resolved_iplist[i], sizeof(resolved_iplist[i]));
+ if (composite_nomem(state->addrs[i], c)) return c;
+
+ state->addrs[i+1] = NULL;
+
+
+ state->names = talloc_realloc(state, state->names, char *, i+2);
+ if (composite_nomem(state->addrs, c)) return c;
+
+ state->names[i] = talloc_strdup(state->names, name->name);
+ if (composite_nomem(state->names[i], c)) return c;
+
+ state->names[i+1] = NULL;
+
+ i++;
+ }
+
+ composite_done(c);
+ return c;
+}
+
+/*
+ general name resolution method - recv side
+ */
+NTSTATUS resolve_name_lmhosts_recv(struct composite_context *c,
+ TALLOC_CTX *mem_ctx,
+ struct socket_address ***addrs,
+ char ***names)
+{
+ NTSTATUS status;
+
+ status = composite_wait(c);
+
+ if (NT_STATUS_IS_OK(status)) {
+ struct resolve_lmhosts_state *state = talloc_get_type(c->private_data, struct resolve_lmhosts_state);
+ *addrs = talloc_steal(mem_ctx, state->addrs);
+ if (names) {
+ *names = talloc_steal(mem_ctx, state->names);
+ }
+ }
+
+ talloc_free(c);
+ return status;
+}
+
+
+bool resolve_context_add_lmhosts_method(struct resolve_context *ctx)
+{
+ return resolve_context_add_method(ctx, resolve_name_lmhosts_send, resolve_name_lmhosts_recv, NULL);
+}
diff --git a/source4/libcli/resolve/resolve_lp.c b/source4/libcli/resolve/resolve_lp.c
index 92e11f0fcb..dac92493fb 100644
--- a/source4/libcli/resolve/resolve_lp.c
+++ b/source4/libcli/resolve/resolve_lp.c
@@ -41,6 +41,8 @@ struct resolve_context *lpcfg_resolve_context(struct loadparm_context *lp_ctx)
}
} else if (!strcmp(methods[i], "file")) {
resolve_context_add_file_method_lp(ret, lp_ctx);
+ } else if (!strcmp(methods[i], "lmhosts")) {
+ resolve_context_add_lmhosts_method(ret);
} else if (!strcmp(methods[i], "host")) {
resolve_context_add_host_method(ret);
} else {
diff --git a/source4/libcli/wscript_build b/source4/libcli/wscript_build
index 600b1f87d0..13e1adb471 100755
--- a/source4/libcli/wscript_build
+++ b/source4/libcli/wscript_build
@@ -60,7 +60,7 @@ bld.SAMBA_SUBSYSTEM('LIBCLI_RESOLVE',
bld.SAMBA_SUBSYSTEM('LP_RESOLVE',
- source='resolve/bcast.c resolve/nbtlist.c resolve/wins.c resolve/dns_ex.c resolve/file.c resolve/host.c resolve/resolve_lp.c',
+ source='resolve/bcast.c resolve/nbtlist.c resolve/wins.c resolve/dns_ex.c resolve/file.c resolve/host.c resolve/lmhosts.c resolve/resolve_lp.c',
autoproto='resolve/lp_proto.h',
deps='cli-nbt samba-hostconfig netif addns'
)