summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
Diffstat (limited to 'source4')
-rw-r--r--source4/libcli/config.mk2
-rw-r--r--source4/libcli/resolve/file.c150
-rw-r--r--source4/libcli/resolve/resolve_lp.c2
3 files changed, 153 insertions, 1 deletions
diff --git a/source4/libcli/config.mk b/source4/libcli/config.mk
index 246abd414a..e8741d165a 100644
--- a/source4/libcli/config.mk
+++ b/source4/libcli/config.mk
@@ -76,7 +76,7 @@ PRIVATE_DEPENDENCIES = LIBCLI_NBT LIBSAMBA-HOSTCONFIG LIBNETIF
LP_RESOLVE_OBJ_FILES = $(addprefix $(libclisrcdir)/resolve/, \
bcast.o nbtlist.o wins.o \
- dns_ex.o \
+ dns_ex.o file.o \
host.o resolve_lp.o)
$(eval $(call proto_header_template,$(libclisrcdir)/resolve/lp_proto.h,$(LP_RESOLVE_OBJ_FILES:.o=.c)))
diff --git a/source4/libcli/resolve/file.c b/source4/libcli/resolve/file.c
new file mode 100644
index 0000000000..950815ddc4
--- /dev/null
+++ b/source4/libcli/resolve/file.c
@@ -0,0 +1,150 @@
+/*
+ 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-2010
+ 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"
+
+struct resolve_file_data {
+ const char *lookup_file;
+};
+
+struct resolve_file_state {
+ struct socket_address **addrs;
+ char **names;
+};
+
+/**
+ broadcast name resolution method - async send
+ */
+/*
+ general name resolution - async send
+ */
+struct composite_context *resolve_name_file_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_file_data *data = talloc_get_type_abort(userdata, struct resolve_file_data);
+ struct resolve_file_state *state;
+ struct sockaddr_storage *resolved_iplist;
+ int resolved_count, i;
+
+ bool srv_lookup = (flags & RESOLVE_NAME_FLAG_DNS_SRV);
+
+ if (event_ctx == NULL) {
+ return NULL;
+ }
+
+ c = composite_create(mem_ctx, event_ctx);
+ if (c == NULL) return NULL;
+
+ /* This isn't an NBT layer resolver */
+ if (flags & RESOLVE_NAME_FLAG_FORCE_NBT || name->type != NBT_NAME_SERVER) {
+ composite_error(c, NT_STATUS_OBJECT_NAME_NOT_FOUND);
+ return c;
+ }
+
+ if (composite_nomem(c->event_ctx, c)) return c;
+
+ state = talloc_zero(c, struct resolve_file_state);
+ if (composite_nomem(state, c)) return c;
+ c->private_data = state;
+
+
+ c->status = resolve_dns_hosts_file_as_sockaddr(data->lookup_file, name->name, srv_lookup, 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;
+
+ if (!(flags & RESOLVE_NAME_FLAG_OVERWRITE_PORT)) {
+ 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_file_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_file_state *state = talloc_get_type(c->private_data, struct resolve_file_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_file_method(struct resolve_context *ctx, const char *lookup_file)
+{
+ struct resolve_file_data *data = talloc(ctx, struct resolve_file_data);
+ data->lookup_file = lookup_file;
+ return resolve_context_add_method(ctx, resolve_name_file_send, resolve_name_file_recv, data);
+}
+
+bool resolve_context_add_file_method_lp(struct resolve_context *ctx, struct loadparm_context *lp_ctx)
+{
+ return resolve_context_add_file_method(ctx, lp_parm_string(lp_ctx, NULL, "resolv", "host file"));
+}
diff --git a/source4/libcli/resolve/resolve_lp.c b/source4/libcli/resolve/resolve_lp.c
index b41e2b98d8..887e0d543e 100644
--- a/source4/libcli/resolve/resolve_lp.c
+++ b/source4/libcli/resolve/resolve_lp.c
@@ -35,6 +35,8 @@ struct resolve_context *lp_resolve_context(struct loadparm_context *lp_ctx)
resolve_context_add_wins_method_lp(ret, lp_ctx);
} else if (!strcmp(methods[i], "bcast")) {
resolve_context_add_bcast_method_lp(ret, lp_ctx);
+ } else if (!strcmp(methods[i], "file")) {
+ resolve_context_add_file_method_lp(ret, lp_ctx);
} else if (!strcmp(methods[i], "host")) {
resolve_context_add_host_method(ret);
} else {