[SCM] Samba Shared Repository - branch master updated
Andrew Bartlett
abartlet at samba.org
Wed Mar 10 17:28:32 MST 2010
The branch, master has been updated
via e999472... s4:libcli Use integrated name resolution when connecting SMB
via 1af2cd2b.. s4:libcli/resovle File based lookup module for DNS name types
via 263d4b5... libcli/nbt Add parser for a 'hosts' file that takes DNS record types
via 3723e32... s4:samba_dnsupdate Add a 'file based' mode to samba_dnsupdate
via 79b4a3b... s4:lib/socket Don't go via a string when resolving addresses in connect_multi
via 9457b7e... s4:libcli/resolve Use a more robust way to return the string address
via 0201b2f... s4:lib/socket Add function to set a port on the socket address
via 4ab3e22... Move prototype to header of common code for set_sockaddr_port
via 5ed18fa... s4/rpc_server Don't segfault over replPropertyMetaData contents
from c1fb657... vfs_netatalk: Segfault if hide files or veto files has no ".AppleDouble"
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit e999472e36076e432187371b0853b887effe1067
Author: Andrew Bartlett <abartlet at samba.org>
Date: Wed Mar 10 16:01:41 2010 +1100
s4:libcli Use integrated name resolution when connecting SMB
This avoids pulling the address into a string and back again if given
a name, by letting the next async layer down do the name resolution.
If it was an IP address to start with, then the resolver library just
converts that to the struct socket_address.
Andrew Bartlett
commit 1af2cd2bd1c74c88dd00088eb37ad6286af7561f
Author: Andrew Bartlett <abartlet at samba.org>
Date: Wed Feb 24 22:57:09 2010 +1100
s4:libcli/resovle File based lookup module for DNS name types
This uses the new common code to read a file containing DNS host
names, so we don't have to use real DNS lookups in our test
environment.
Andrew Bartlett
commit 263d4b5c93a1ec8a027130800c98643f559677c5
Author: Andrew Bartlett <abartlet at samba.org>
Date: Tue Mar 9 23:29:43 2010 +1100
libcli/nbt Add parser for a 'hosts' file that takes DNS record types
commit 3723e32e8cca79b52b97d6d6f4cda8ce5ce1bd33
Author: Andrew Bartlett <abartlet at samba.org>
Date: Tue Mar 9 23:34:10 2010 +1100
s4:samba_dnsupdate Add a 'file based' mode to samba_dnsupdate
For the testsuite to use DNS like names, we need to write these names
to a file.
Also, to have this run in 'make test' the usual rules about 'no 127.*'
IP addresses in DNS must be skipped, so glue.interface_ips takes two
arguments now
commit 79b4a3b22e8a70844b9654f057f6169c553cc809
Author: Andrew Bartlett <abartlet at samba.org>
Date: Wed Mar 10 16:04:44 2010 +1100
s4:lib/socket Don't go via a string when resolving addresses in connect_multi
This also removes the special case for IP addresses, and leaves that
to the code in the resolver library.
Andrew Bartlett
commit 9457b7ea2214aaa3a466e5dbc2daa0b931975073
Author: Andrew Bartlett <abartlet at samba.org>
Date: Wed Mar 10 15:56:13 2010 +1100
s4:libcli/resolve Use a more robust way to return the string address
By going via these tevent functions, we avoid needing to dereference
the struct socket_address, which may contain a 'struct sockaddr' or
strings. The new dns_host_file resolver returns in the form of a
struct sockaddr.
Andrew Bartlett
commit 0201b2fa9f31d8c9a75f3057f91b3f720f62292c
Author: Andrew Bartlett <abartlet at samba.org>
Date: Wed Mar 10 15:55:26 2010 +1100
s4:lib/socket Add function to set a port on the socket address
commit 4ab3e220c4188b6c147e1a0fa8ce1e2965d74d43
Author: Andrew Bartlett <abartlet at samba.org>
Date: Tue Mar 9 23:30:41 2010 +1100
Move prototype to header of common code for set_sockaddr_port
commit 5ed18fad0037146bb321eb7e73c82be403a45917
Author: Andrew Bartlett <abartlet at samba.org>
Date: Thu Mar 11 10:42:18 2010 +1100
s4/rpc_server Don't segfault over replPropertyMetaData contents
The replPropertyMetaData may contain attrid values that we don't yet
have in the local schema. We need to deal with this - it is a serious
error, but we should not segfault.
Andrew Bartlett
-----------------------------------------------------------------------
Summary of changes:
lib/util/util_net.h | 2 +
libcli/nbt/config.mk | 1 +
libcli/nbt/dns_hosts_file.c | 306 +++++++++++++++++++++++++++
libcli/nbt/libnbt.h | 6 +
source3/include/proto.h | 1 -
source4/lib/socket/connect_multi.c | 48 ++---
source4/lib/socket/socket.c | 12 +
source4/lib/socket/socket.h | 2 +
source4/libcli/config.mk | 4 +-
source4/libcli/raw/clisocket.c | 4 +
source4/libcli/resolve/file.c | 150 +++++++++++++
source4/libcli/resolve/resolve.c | 13 +-
source4/libcli/resolve/resolve_lp.c | 2 +
source4/libcli/smb_composite/connect.c | 47 +----
source4/rpc_server/drsuapi/getncchanges.c | 7 +
source4/scripting/bin/samba_dnsupdate | 76 +++++--
source4/scripting/python/pyglue.c | 7 +-
source4/scripting/python/samba/provision.py | 2 +-
18 files changed, 594 insertions(+), 96 deletions(-)
create mode 100644 libcli/nbt/dns_hosts_file.c
create mode 100644 source4/libcli/resolve/file.c
Changeset truncated at 500 lines:
diff --git a/lib/util/util_net.h b/lib/util/util_net.h
index 6eacfc3..5dc4df5 100644
--- a/lib/util/util_net.h
+++ b/lib/util/util_net.h
@@ -43,4 +43,6 @@ bool interpret_string_addr_prefer_ipv4(struct sockaddr_storage *pss,
const char *str,
int flags);
+void set_sockaddr_port(struct sockaddr *psa, uint16_t port);
+
#endif /* _SAMBA_UTIL_NET_H_ */
diff --git a/libcli/nbt/config.mk b/libcli/nbt/config.mk
index c26118e..14af80e 100644
--- a/libcli/nbt/config.mk
+++ b/libcli/nbt/config.mk
@@ -10,6 +10,7 @@ PUBLIC_DEPENDENCIES = LIBNDR NDR_NBT LIBCLI_COMPOSITE LIBEVENTS \
LIBCLI_NBT_OBJ_FILES = $(addprefix $(libclinbtsrcdir)/, \
lmhosts.o \
+ dns_hosts_file.o \
nbtsocket.o \
namequery.o \
nameregister.o \
diff --git a/libcli/nbt/dns_hosts_file.c b/libcli/nbt/dns_hosts_file.c
new file mode 100644
index 0000000..6665a10
--- /dev/null
+++ b/libcli/nbt/dns_hosts_file.c
@@ -0,0 +1,306 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ read a file containing DNS names, types and IP addresses
+
+ Copyright (C) Andrew Tridgell 1994-1998
+ Copyright (C) Jeremy Allison 2007
+ Copyright (C) Andrew Bartlett 2009.
+
+ 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/>.
+*/
+
+/* The purpose of this file is to read the file generated by the samba_dnsupdate script */
+
+#include "includes.h"
+#include "lib/util/xfile.h"
+#include "lib/util/util_net.h"
+#include "system/filesys.h"
+#include "system/network.h"
+
+/********************************************************
+ Start parsing the dns_hosts_file file.
+*********************************************************/
+
+static XFILE *startdns_hosts_file(const char *fname)
+{
+ XFILE *fp = x_fopen(fname,O_RDONLY, 0);
+ if (!fp) {
+ DEBUG(4,("startdns_hosts_file: Can't open dns_hosts_file file %s. "
+ "Error was %s\n",
+ fname, strerror(errno)));
+ return NULL;
+ }
+ return fp;
+}
+
+/********************************************************
+ Parse the next line in the dns_hosts_file file.
+*********************************************************/
+
+static bool getdns_hosts_fileent(TALLOC_CTX *ctx, XFILE *fp, char **pp_name, char **pp_name_type,
+ char **pp_next_name,
+ struct sockaddr_storage *pss, uint32_t *p_port)
+{
+ char line[1024];
+
+ *pp_name = NULL;
+ *pp_name_type = NULL;
+ *pp_next_name = NULL;
+ *p_port = 0;
+
+ while(!x_feof(fp) && !x_ferror(fp)) {
+ char *name_type = NULL;
+ char *name = NULL;
+ char *next_name = NULL;
+ char *ip = NULL;
+ char *port = NULL;
+
+ const char *ptr;
+ int count = 0;
+
+ if (!fgets_slash(line,sizeof(line),fp)) {
+ continue;
+ }
+
+ if (*line == '#') {
+ continue;
+ }
+
+ ptr = line;
+
+ if (next_token_talloc(ctx, &ptr, &name_type, NULL))
+ ++count;
+ if (next_token_talloc(ctx, &ptr, &name, NULL))
+ ++count;
+ if (strcasecmp(name_type, "A") == 0) {
+ if (next_token_talloc(ctx, &ptr, &ip, NULL))
+ ++count;
+ } else if (strcasecmp(name_type, "SRV") == 0) {
+ if (next_token_talloc(ctx, &ptr, &next_name, NULL))
+ ++count;
+ if (next_token_talloc(ctx, &ptr, &port, NULL))
+ ++count;
+ } else if (strcasecmp(name_type, "CNAME") == 0) {
+ if (next_token_talloc(ctx, &ptr, &next_name, NULL))
+ ++count;
+ }
+ if (count <= 0)
+ continue;
+
+ if (strcasecmp(name_type, "A") == 0) {
+ if (count != 3) {
+ DEBUG(0,("getdns_hosts_fileent: Ill formed hosts A record [%s]\n",
+ line));
+ continue;
+ }
+ DEBUG(4, ("getdns_hosts_fileent: host entry: %s %s %s\n",
+ name_type, name, ip));
+ if (!interpret_string_addr(pss, ip, AI_NUMERICHOST)) {
+ DEBUG(0,("getdns_hosts_fileent: invalid address "
+ "%s.\n", ip));
+ }
+
+ } else if (strcasecmp(name_type, "SRV") == 0) {
+ if (count != 4) {
+ DEBUG(0,("getdns_hosts_fileent: Ill formed hosts SRV record [%s]\n",
+ line));
+ continue;
+ }
+ *p_port = strtoul(port, NULL, 10);
+ if (*p_port == ULONG_MAX) {
+ DEBUG(0, ("getdns_hosts_fileent: Ill formed hosts SRV record [%s] (invalid port: %s)\n",
+ line, port));
+ continue;
+ }
+ DEBUG(4, ("getdns_hosts_fileent: host entry: %s %s %s %u\n",
+ name_type, name, next_name, (unsigned int)*p_port));
+ *pp_next_name = talloc_strdup(ctx, next_name);
+ if (!*pp_next_name) {
+ return false;
+ }
+ } else if (strcasecmp(name_type, "CNAME") == 0) {
+ if (count != 3) {
+ DEBUG(0,("getdns_hosts_fileent: Ill formed hosts CNAME record [%s]\n",
+ line));
+ continue;
+ }
+ DEBUG(4, ("getdns_hosts_fileent: host entry: %s %s %s\n",
+ name_type, name, next_name));
+ *pp_next_name = talloc_strdup(ctx, next_name);
+ if (!*pp_next_name) {
+ return false;
+ }
+ } else {
+ DEBUG(0,("getdns_hosts_fileent: unknown type %s\n", name_type));
+ continue;
+ }
+
+ *pp_name = talloc_strdup(ctx, name);
+ if (!*pp_name) {
+ return false;
+ }
+
+ *pp_name_type = talloc_strdup(ctx, name_type);
+ if (!*pp_name_type) {
+ return false;
+ }
+ return true;
+ }
+
+ return false;
+}
+
+/********************************************************
+ Finish parsing the dns_hosts_file file.
+*********************************************************/
+
+static void enddns_hosts_file(XFILE *fp)
+{
+ x_fclose(fp);
+}
+
+/********************************************************
+ Resolve via "dns_hosts" method.
+*********************************************************/
+
+static NTSTATUS resolve_dns_hosts_file_as_sockaddr_recurse(const char *dns_hosts_file,
+ const char *name, bool srv_lookup,
+ int level, uint32_t port,
+ TALLOC_CTX *mem_ctx,
+ struct sockaddr_storage **return_iplist,
+ int *return_count)
+{
+ /*
+ * "dns_hosts" means parse the local dns_hosts file.
+ */
+
+ XFILE *fp;
+ char *host_name = NULL;
+ char *name_type = NULL;
+ char *next_name = NULL;
+ struct sockaddr_storage return_ss;
+ uint32_t srv_port;
+ NTSTATUS status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
+ TALLOC_CTX *ctx = NULL;
+ TALLOC_CTX *ip_list_ctx = NULL;
+
+ /* Don't recurse forever, even on our own flat files */
+ if (level > 11) {
+
+ }
+
+ *return_iplist = NULL;
+ *return_count = 0;
+
+ DEBUG(3,("resolve_dns_hosts: "
+ "Attempting dns_hosts lookup for name %s\n",
+ name));
+
+ fp = startdns_hosts_file(dns_hosts_file);
+
+ if ( fp == NULL )
+ return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+
+ ip_list_ctx = talloc_new(mem_ctx);
+ if (!ip_list_ctx) {
+ enddns_hosts_file(fp);
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ ctx = talloc_new(ip_list_ctx);
+ if (!ctx) {
+ talloc_free(ip_list_ctx);
+ enddns_hosts_file(fp);
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ while (getdns_hosts_fileent(ctx, fp, &host_name, &name_type, &next_name, &return_ss, &srv_port)) {
+ if (!strequal(name, host_name)) {
+ TALLOC_FREE(ctx);
+ ctx = talloc_new(mem_ctx);
+ if (!ctx) {
+ enddns_hosts_file(fp);
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ continue;
+ }
+
+ if (srv_lookup) {
+ if (strcasecmp(name_type, "SRV") == 0) {
+ /* we only accept one host name per SRV entry */
+ enddns_hosts_file(fp);
+ status = resolve_dns_hosts_file_as_sockaddr_recurse(dns_hosts_file, next_name,
+ false,
+ level + 1, srv_port,
+ mem_ctx, return_iplist,
+ return_count);
+ talloc_free(ip_list_ctx);
+ return status;
+ } else {
+ continue;
+ }
+ } else if (strcasecmp(name_type, "CNAME") == 0) {
+ /* we only accept one host name per CNAME */
+ enddns_hosts_file(fp);
+ status = resolve_dns_hosts_file_as_sockaddr_recurse(dns_hosts_file, next_name, false,
+ level + 1, port,
+ mem_ctx, return_iplist, return_count);
+ talloc_free(ip_list_ctx);
+ return status;
+ } else if (strcasecmp(name_type, "A") == 0) {
+ /* Set the specified port (possibly from a SRV lookup) into the structure we return */
+ set_sockaddr_port((struct sockaddr *)&return_ss, port);
+
+ /* We are happy to keep looking for other possible A record matches */
+ *return_iplist = talloc_realloc(ip_list_ctx, (*return_iplist),
+ struct sockaddr_storage,
+ (*return_count)+1);
+
+ if ((*return_iplist) == NULL) {
+ TALLOC_FREE(ctx);
+ enddns_hosts_file(fp);
+ DEBUG(3,("resolve_dns_hosts: talloc_realloc fail !\n"));
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ (*return_iplist)[*return_count] = return_ss;
+ *return_count += 1;
+
+ /* we found something */
+ status = NT_STATUS_OK;
+ }
+ }
+
+ talloc_steal(mem_ctx, *return_iplist);
+ TALLOC_FREE(ip_list_ctx);
+ enddns_hosts_file(fp);
+ return status;
+}
+
+/********************************************************
+ Resolve via "dns_hosts" method.
+*********************************************************/
+
+NTSTATUS resolve_dns_hosts_file_as_sockaddr(const char *dns_hosts_file,
+ const char *name, bool srv_lookup,
+ TALLOC_CTX *mem_ctx,
+ struct sockaddr_storage **return_iplist,
+ int *return_count)
+{
+ return resolve_dns_hosts_file_as_sockaddr_recurse(dns_hosts_file, name, srv_lookup,
+ 0, 0,
+ mem_ctx, return_iplist, return_count);
+}
diff --git a/libcli/nbt/libnbt.h b/libcli/nbt/libnbt.h
index 6d6a4a4..e150b35 100644
--- a/libcli/nbt/libnbt.h
+++ b/libcli/nbt/libnbt.h
@@ -366,4 +366,10 @@ NTSTATUS resolve_lmhosts_file_as_sockaddr(const char *lmhosts_file,
struct sockaddr_storage **return_iplist,
int *return_count);
+NTSTATUS resolve_dns_hosts_file_as_sockaddr(const char *dns_hosts_file,
+ const char *name, bool srv_lookup,
+ TALLOC_CTX *mem_ctx,
+ struct sockaddr_storage **return_iplist,
+ int *return_count);
+
#endif /* __LIBNBT_H__ */
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 6ecf0a5..f6a4385 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -1374,7 +1374,6 @@ char *print_sockaddr(char *dest,
const struct sockaddr_storage *psa);
char *print_canonical_sockaddr(TALLOC_CTX *ctx,
const struct sockaddr_storage *pss);
-void set_sockaddr_port(struct sockaddr *psa, uint16_t port);
const char *client_name(int fd);
int get_socket_port(int fd);
const char *client_addr(int fd, char *addr, size_t addrlen);
diff --git a/source4/lib/socket/connect_multi.c b/source4/lib/socket/connect_multi.c
index 68386ba..300e5fb 100644
--- a/source4/lib/socket/connect_multi.c
+++ b/source4/lib/socket/connect_multi.c
@@ -33,7 +33,7 @@
overall state
*/
struct connect_multi_state {
- const char *server_address;
+ struct socket_address *server_address;
int num_ports;
uint16_t *ports;
@@ -64,7 +64,7 @@ static void continue_one(struct composite_context *creq);
*/
_PUBLIC_ struct composite_context *socket_connect_multi_send(
TALLOC_CTX *mem_ctx,
- const char *server_address,
+ const char *server_name,
int num_server_ports,
uint16_t *server_ports,
struct resolve_context *resolve_ctx,
@@ -74,6 +74,9 @@ _PUBLIC_ struct composite_context *socket_connect_multi_send(
struct connect_multi_state *multi;
int i;
+ struct nbt_name name;
+ struct composite_context *creq;
+
result = talloc_zero(mem_ctx, struct composite_context);
if (result == NULL) return NULL;
result->state = COMPOSITE_STATE_IN_PROGRESS;
@@ -83,9 +86,6 @@ _PUBLIC_ struct composite_context *socket_connect_multi_send(
if (composite_nomem(multi, result)) goto failed;
result->private_data = multi;
- multi->server_address = talloc_strdup(multi, server_address);
- if (composite_nomem(multi->server_address, result)) goto failed;
-
multi->num_ports = num_server_ports;
multi->ports = talloc_array(multi, uint16_t, multi->num_ports);
if (composite_nomem(multi->ports, result)) goto failed;
@@ -94,30 +94,21 @@ _PUBLIC_ struct composite_context *socket_connect_multi_send(
multi->ports[i] = server_ports[i];
}
- if (!is_ipaddress(server_address)) {
- /*
- we don't want to do the name resolution separately
+ /*
+ we don't want to do the name resolution separately
for each port, so start it now, then only start on
the real sockets once we have an IP
- */
- struct nbt_name name;
- struct composite_context *creq;
- make_nbt_name_server(&name, server_address);
- creq = resolve_name_send(resolve_ctx, multi, &name, result->event_ctx);
- if (composite_nomem(creq, result)) goto failed;
- composite_continue(result, creq, continue_resolve_name, result);
- return result;
- }
+ */
+ make_nbt_name_server(&name, server_name);
- /* now we've setup the state we can process the first socket */
- connect_multi_next_socket(result);
+ creq = resolve_name_all_send(resolve_ctx, multi, 0, multi->ports[0], &name, result->event_ctx);
+ if (composite_nomem(creq, result)) goto failed;
- if (!NT_STATUS_IS_OK(result->status)) {
- goto failed;
- }
+ composite_continue(result, creq, continue_resolve_name, result);
return result;
+
failed:
composite_error(result, result->status);
return result;
@@ -148,11 +139,11 @@ static void connect_multi_next_socket(struct composite_context *result)
result->status = socket_create("ipv4", SOCKET_TYPE_STREAM, &state->sock, 0);
if (!composite_is_ok(result)) return;
- /* Form up the particular address we are interested in */
- state->addr = socket_address_from_strings(state, state->sock->backend_name,
- multi->server_address, multi->ports[next]);
+ state->addr = socket_address_copy(state, multi->server_address);
if (composite_nomem(state->addr, result)) return;
+ socket_address_set_port(state->addr, multi->ports[next]);
+
talloc_steal(state, state->sock);
creq = socket_connect_send(state->sock, NULL,
@@ -197,12 +188,13 @@ static void continue_resolve_name(struct composite_context *creq)
struct composite_context);
struct connect_multi_state *multi = talloc_get_type(result->private_data,
struct connect_multi_state);
- const char *addr;
+ struct socket_address **addr;
- result->status = resolve_name_recv(creq, multi, &addr);
+ result->status = resolve_name_all_recv(creq, multi, &addr, NULL);
if (!composite_is_ok(result)) return;
- multi->server_address = addr;
+ /* Let's just go for the first for now */
+ multi->server_address = addr[0];
connect_multi_next_socket(result);
}
diff --git a/source4/lib/socket/socket.c b/source4/lib/socket/socket.c
index 30db03f..4b5ceca 100644
--- a/source4/lib/socket/socket.c
+++ b/source4/lib/socket/socket.c
@@ -25,6 +25,7 @@
#include "system/network.h"
#include "param/param.h"
#include "../lib/tsocket/tsocket.h"
+#include "lib/util/util_net.h"
/*
auto-close sockets on free
@@ -371,6 +372,17 @@ _PUBLIC_ struct tsocket_address *socket_address_to_tsocket_address(TALLOC_CTX *m
return r;
}
+_PUBLIC_ void socket_address_set_port(struct socket_address *a,
+ uint16_t port)
+{
+ if (a->sockaddr) {
+ set_sockaddr_port(a->sockaddr, port);
+ } else {
+ a->port = port;
+ }
+
--
Samba Shared Repository
More information about the samba-cvs
mailing list