[SCM] Samba Shared Repository - branch master updated
Isaac Boukris
iboukris at samba.org
Tue Aug 4 10:14:07 UTC 2020
The branch, master has been updated
via 860510b196a s3: libsmb: Move all calls to convert_ss2service() to one place now all methods return a sockaddr_storage.
via 03112db1213 s3: libsmb: Now all resolution functions return a ss_list on success, we only need one local variable for this.
via ecaa4244482 s3: libsmb: Change resolve_ads() to return a talloc'ed ss_list, matching the other name resolution methods.
via d53ade5beb5 s3: libsmb: Rewrite resolve_ads() to use the previously added dns_lookup_list() function.
via d0fa32bdcda s3: libsmb: Add in (currently unused) function dns_lookup_list().
via 97781fe0aeb s3: libsmb: Pass in TALLOC_CTX * parameter to resolve_ads() instead of creating one internally.
via 2297c883b52 s3: libsmb: Cleanup - ensure ss_list variables are initialized with NULL.
via eaea3c0a62b s3: libsmb: Cleanup - put talloc parameter first in name_resolve_bcast().
via cef158a75c4 s3: libsmb: Cleanup - put talloc parameter first in resolve_wins().
via 7ad92b37020 s3/s4: Cleanup. Move TALLOC_CTX * parameter to be first in resolve_lmhosts_file_as_sockaddr() to match modern conventions.
via f12cee23611 s3: libsmb: Cleanup - put talloc parameter first in resolve_hosts().
via 53474b57e15 s3: libsmb: Cleanup - reformatting name_resolve_bcast() parameters inside internal_resolve_name().
via 1cb67bd31cc s3: libsmb: Cleanup - reformatting resolve_wins() parameters inside internal_resolve_name().
via e8db4b0909c s3: libsmb: Cleanup - reformatting resolve_lmhosts_file_as_sockaddr() parameters inside internal_resolve_name().
via d42ba0b1b68 s3: libsmb: Cleanup - reformatting 2nd use of resolve_ads() parameters inside internal_resolve_name().
via cd3cc111a42 s3: libsmb: Cleanup - reformatting resolve_ads() parameters inside internal_resolve_name().
via dd165b2c96f s3: libsmb: Cleanup - reformatting resolve_hosts() parameters inside internal_resolve_name().
via 2ad48899196 s3: libsmb: Cleanup - Remove incorrect comment in resolve_ads(). The DNS code copes fine with IPv6 addresses.
via e07fa953494 s3: libsmb: Cleanup - modernize DEBUG -> DBG_ in internal_resolve_name()
via 14433e2afad s3: libsmb: Cleanup - split allocation and NULL check in internal_resolve_name().
via 1499fd8a2e5 s3: libsmb: Cleanup - use helper 'ok' bool for internal_resolve_name().
via 4abcb3001eb s3: libsmb: Cleanup - use helper 'ok' bool for name_resolve_bcast().
via d48d60595ac s3: libsmb: Cleanup - use helper 'ok' bool for resolve_wins().
via 8e20de549fd s3: libsmb: Cleanup - use helper 'ok' bool for resolve_lmhosts_file_as_sockaddr().
via d4e430635ec s3: libsmb: Cleanup - use helper 'ok' bool for resolve_hosts().
via 75469fcfbff s3: libsmb: Cleanup - change to early continue in internal_resolve_name() for name_resolve_bcast().
via ba656a79504 s3: libsmb: Cleanup - change to early continue in internal_resolve_name() for resolve_wins().
via 02f72478e28 s3: libsmb: Cleanup - change to early continue in internal_resolve_name() for 0x1D name in resolve_wins().
via 114fe823436 s3: libsmb: Cleanup - change to early continue in internal_resolve_name() for resolve_lmhosts_file_as_sockaddr().
via 139d7a73c0e s3: libsmb: Cleanup - change to early continue in internal_resolve_name() for resolve_ads().
via e74b323a4e4 s3: libsmb: Cleanup - change to early continue in internal_resolve_name() for KDC resolve_ads().
via bfe1b6eee94 s3: libsmb: Cleanup - change to early continue in internal_resolve_name() for resolve_hosts().
via a4c85116e5c s3: libsmb: Cleanup - ensure we don't try and continue resolving names on failure of convert_ss2service().
from 12c526f1513 s3: scripts: Selfttest. samba3.blackbox.smbclient_iconv.*
https://git.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 860510b196a99cfe491996164264f1a9da44dda0
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 20:52:58 2020 -0700
s3: libsmb: Move all calls to convert_ss2service() to one place now all methods return a sockaddr_storage.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
Autobuild-User(master): Isaac Boukris <iboukris at samba.org>
Autobuild-Date(master): Tue Aug 4 10:13:53 UTC 2020 on sn-devel-184
commit 03112db121367ddbbeee38a1fd2f97159d9d3d38
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 20:40:02 2020 -0700
s3: libsmb: Now all resolution functions return a ss_list on success, we only need one local variable for this.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit ecaa424448245057018c51d71035475de1f2eeb0
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 20:17:54 2020 -0700
s3: libsmb: Change resolve_ads() to return a talloc'ed ss_list, matching the other name resolution methods.
Now we can move all the convert_ss2service() calls to one place.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit d53ade5beb5d793066c3b57b715da2e8692ecb9f
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 19:50:04 2020 -0700
s3: libsmb: Rewrite resolve_ads() to use the previously added dns_lookup_list() function.
Clean up internals - a LOT.
This one needs careful review. Ditch the (unused) port returns from
the SRV replies.
Internally uses talloc'ed arrays of struct sockaddr_storage
which it then convert to MALLOC'ed struct ip_service.
Still returns struct ip_service but this will be
fixed in the next commit.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit d0fa32bdcda523df628a7ab96e6598d5f8ea41d4
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 18:31:16 2020 -0700
s3: libsmb: Add in (currently unused) function dns_lookup_list().
This function takes a list of names returned from a DNS SRV
query which didn't have returned IP addresses and returns an
array of struct sockaddr_storage.
Currently synchronous, but this is the function that will
be changed to be asynchronous later.
Compiles but commented out for now so we don't get "unused
function" warnings.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit 97781fe0aeb8d5e000954d23543c450322962ab6
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 17:59:20 2020 -0700
s3: libsmb: Pass in TALLOC_CTX * parameter to resolve_ads() instead of creating one internally.
Pass in talloc_tos() to make it match the other resolve_XXX() functions.
No memory leaks as this is used for transient data and is cleaned up
when the calling frame in internal_resolve_name() is destroyed.
Preparing to have it return a talloc'ed struct sockaddr_storage array
rather than a malloc'ed struct ip_service array.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit 2297c883b52ddda7d8a6a143f632ffbef7fe1a10
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 20:27:38 2020 -0700
s3: libsmb: Cleanup - ensure ss_list variables are initialized with NULL.
No logic changes.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit eaea3c0a62ba6fa942d22fb7506e201de9076977
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 17:56:48 2020 -0700
s3: libsmb: Cleanup - put talloc parameter first in name_resolve_bcast().
No logic changes.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit cef158a75c4446e9a087a5f170ba3f91fdc58a1d
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 17:53:28 2020 -0700
s3: libsmb: Cleanup - put talloc parameter first in resolve_wins().
No logic changes.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit 7ad92b3702061a004b82cde88572847f77c2158f
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 17:50:21 2020 -0700
s3/s4: Cleanup. Move TALLOC_CTX * parameter to be first in resolve_lmhosts_file_as_sockaddr() to match modern conventions.
No logic changes.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit f12cee236115ed0dc10c02a874ee3aab04781fdd
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 17:45:44 2020 -0700
s3: libsmb: Cleanup - put talloc parameter first in resolve_hosts().
No logic changes.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit 53474b57e15e205711de447a246f023c750f8983
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 17:44:03 2020 -0700
s3: libsmb: Cleanup - reformatting name_resolve_bcast() parameters inside internal_resolve_name().
No logic changes.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit 1cb67bd31cc1f1effd75ac8c63973985f92ce52a
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 17:43:26 2020 -0700
s3: libsmb: Cleanup - reformatting resolve_wins() parameters inside internal_resolve_name().
No logic changes.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit e8db4b0909c8fbf99b33bf8a255880ba79f425f2
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 17:42:44 2020 -0700
s3: libsmb: Cleanup - reformatting resolve_lmhosts_file_as_sockaddr() parameters inside internal_resolve_name().
No logic changes.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit d42ba0b1b68c6566b5ecfb5a01a1a53e922c1246
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 17:40:06 2020 -0700
s3: libsmb: Cleanup - reformatting 2nd use of resolve_ads() parameters inside internal_resolve_name().
No logic change.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit cd3cc111a426f03f22754dd254423b0ab21fb493
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 17:39:33 2020 -0700
s3: libsmb: Cleanup - reformatting resolve_ads() parameters inside internal_resolve_name().
No logic changes.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit dd165b2c96fa91c6bae82ea864e28625b96db7b6
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 17:38:20 2020 -0700
s3: libsmb: Cleanup - reformatting resolve_hosts() parameters inside internal_resolve_name().
No logic changes.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit 2ad488991966ce439830e44ea8012835e14a0630
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 17:35:22 2020 -0700
s3: libsmb: Cleanup - Remove incorrect comment in resolve_ads(). The DNS code copes fine with IPv6 addresses.
No logic change.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit e07fa9534942869e6f7269a81b85628db480718f
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 17:32:47 2020 -0700
s3: libsmb: Cleanup - modernize DEBUG -> DBG_ in internal_resolve_name()
No logic change.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit 14433e2afad805a0481ca72c7108232d030919f2
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 17:28:41 2020 -0700
s3: libsmb: Cleanup - split allocation and NULL check in internal_resolve_name().
No logic change.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit 1499fd8a2e5eee8d515000e4059063215db10e3c
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 17:27:13 2020 -0700
s3: libsmb: Cleanup - use helper 'ok' bool for internal_resolve_name().
No logic change.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit 4abcb3001eb3f1a81a3e4b4ac9f999b9d1d7346a
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 17:05:27 2020 -0700
s3: libsmb: Cleanup - use helper 'ok' bool for name_resolve_bcast().
No logic change.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit d48d60595ac19a4e0bb77ac5e204ec943f2d9d51
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 17:04:57 2020 -0700
s3: libsmb: Cleanup - use helper 'ok' bool for resolve_wins().
No logic change.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit 8e20de549fdec479b31c46f5ffe38e60b50be052
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 17:03:21 2020 -0700
s3: libsmb: Cleanup - use helper 'ok' bool for resolve_lmhosts_file_as_sockaddr().
No logic change.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit d4e430635ec7bfb79dce93bded562dc8c5e17b5f
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 17:02:15 2020 -0700
s3: libsmb: Cleanup - use helper 'ok' bool for resolve_hosts().
No logic change.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit 75469fcfbffdcf2bef83f5814f562de1fed86a48
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 17:01:04 2020 -0700
s3: libsmb: Cleanup - change to early continue in internal_resolve_name() for name_resolve_bcast().
No logic change.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit ba656a79504fa71f20d82b2e82ecd7492781a26e
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 17:00:35 2020 -0700
s3: libsmb: Cleanup - change to early continue in internal_resolve_name() for resolve_wins().
No logic change.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit 02f72478e28dfab98ad1a77b0457b269978099f5
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 16:59:38 2020 -0700
s3: libsmb: Cleanup - change to early continue in internal_resolve_name() for 0x1D name in resolve_wins().
No logic change.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit 114fe82343632f13315f544c88fbd55e0235f96a
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 16:58:46 2020 -0700
s3: libsmb: Cleanup - change to early continue in internal_resolve_name() for resolve_lmhosts_file_as_sockaddr().
No logic change.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit 139d7a73c0e1975225231daf9b15d73d2b3af766
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 16:57:43 2020 -0700
s3: libsmb: Cleanup - change to early continue in internal_resolve_name() for resolve_ads().
No logic change.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit e74b323a4e4f5d9ebaf995a7a1a75baf2c33cbda
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 16:56:14 2020 -0700
s3: libsmb: Cleanup - change to early continue in internal_resolve_name() for KDC resolve_ads().
No logic change.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit bfe1b6eee9456d42f597affa901261d01a60e1e6
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 16:54:45 2020 -0700
s3: libsmb: Cleanup - change to early continue in internal_resolve_name() for resolve_hosts().
No logic change.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
commit a4c85116e5cca8b129116315d8efe02a870a7296
Author: Jeremy Allison <jra at samba.org>
Date: Mon Jul 20 20:57:44 2020 -0700
s3: libsmb: Cleanup - ensure we don't try and continue resolving names on failure of convert_ss2service().
Logic change, but correct error cleanup - jump to new 'fail:' label.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Isaac Boukris <iboukris at samba.org>
-----------------------------------------------------------------------
Summary of changes:
libcli/nbt/libnbt.h | 7 +-
libcli/nbt/lmhosts.c | 7 +-
source3/libsmb/libsmb_dir.c | 7 +-
source3/libsmb/namequery.c | 520 ++++++++++++++++++++++++++-------------
source3/libsmb/namequery.h | 8 +-
source3/utils/nmblookup.c | 8 +-
source4/libcli/resolve/lmhosts.c | 8 +-
7 files changed, 377 insertions(+), 188 deletions(-)
Changeset truncated at 500 lines:
diff --git a/libcli/nbt/libnbt.h b/libcli/nbt/libnbt.h
index f7212789897..496b2b91783 100644
--- a/libcli/nbt/libnbt.h
+++ b/libcli/nbt/libnbt.h
@@ -367,9 +367,10 @@ bool getlmhostsent(TALLOC_CTX *ctx, FILE *fp, char **pp_name, int *name_type,
struct sockaddr_storage *pss);
void endlmhosts(FILE *fp);
-NTSTATUS resolve_lmhosts_file_as_sockaddr(const char *lmhosts_file,
- const char *name, int name_type,
- TALLOC_CTX *mem_ctx,
+NTSTATUS resolve_lmhosts_file_as_sockaddr(TALLOC_CTX *mem_ctx,
+ const char *lmhosts_file,
+ const char *name,
+ int name_type,
struct sockaddr_storage **return_iplist,
int *return_count);
diff --git a/libcli/nbt/lmhosts.c b/libcli/nbt/lmhosts.c
index f47d8b9804f..0890c0407d3 100644
--- a/libcli/nbt/lmhosts.c
+++ b/libcli/nbt/lmhosts.c
@@ -159,9 +159,10 @@ void endlmhosts(FILE *fp)
Resolve via "lmhosts" method.
*********************************************************/
-NTSTATUS resolve_lmhosts_file_as_sockaddr(const char *lmhosts_file,
- const char *name, int name_type,
- TALLOC_CTX *mem_ctx,
+NTSTATUS resolve_lmhosts_file_as_sockaddr(TALLOC_CTX *mem_ctx,
+ const char *lmhosts_file,
+ const char *name,
+ int name_type,
struct sockaddr_storage **return_iplist,
int *return_count)
{
diff --git a/source3/libsmb/libsmb_dir.c b/source3/libsmb/libsmb_dir.c
index 12abb734c2d..b4ebc90bf49 100644
--- a/source3/libsmb/libsmb_dir.c
+++ b/source3/libsmb/libsmb_dir.c
@@ -606,8 +606,11 @@ SMBC_opendir_ctx(SMBCCTX *context,
*/
ip_list = NULL;
- status = name_resolve_bcast(MSBROWSE, 1, talloc_tos(),
- &ip_list, &count);
+ status = name_resolve_bcast(talloc_tos(),
+ MSBROWSE,
+ 1,
+ &ip_list,
+ &count);
if (!NT_STATUS_IS_OK(status))
{
diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c
index 642f7b91b5a..0e87df29690 100644
--- a/source3/libsmb/namequery.c
+++ b/source3/libsmb/namequery.c
@@ -1909,9 +1909,9 @@ NTSTATUS name_resolve_bcast_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
return NT_STATUS_OK;
}
-NTSTATUS name_resolve_bcast(const char *name,
+NTSTATUS name_resolve_bcast(TALLOC_CTX *mem_ctx,
+ const char *name,
int name_type,
- TALLOC_CTX *mem_ctx,
struct sockaddr_storage **return_iplist,
int *return_count)
{
@@ -2252,9 +2252,9 @@ NTSTATUS resolve_wins_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
Resolve via "wins" method.
*********************************************************/
-NTSTATUS resolve_wins(const char *name,
+NTSTATUS resolve_wins(TALLOC_CTX *mem_ctx,
+ const char *name,
int name_type,
- TALLOC_CTX *mem_ctx,
struct sockaddr_storage **return_iplist,
int *return_count)
{
@@ -2280,12 +2280,93 @@ fail:
return status;
}
+/********************************************************
+ Resolve a list of DNS names to a list of IP addresses.
+ As this is a DC / LDAP / KDC lookup any IP address will
+ do, the requested names don't have to match the returned
+ IP address list.
+*********************************************************/
+
+static NTSTATUS dns_lookup_list(TALLOC_CTX *ctx,
+ size_t num_dns_names,
+ const char **dns_lookup_names,
+ size_t *p_num_addrs,
+ struct sockaddr_storage **pp_addrs)
+{
+ size_t total_num_addrs = 0;
+ size_t i;
+ struct sockaddr_storage *ret_addrs = NULL;
+
+ /* FIXME - make this asnyc using our async DNS code. */
+
+ for (i = 0; i < num_dns_names; i++ ) {
+ struct addrinfo *res = NULL;
+ struct addrinfo *p = NULL;
+ size_t num_addrs = 0;
+ bool ok = interpret_string_addr_internal(&res,
+ dns_lookup_names[i],
+ 0);
+ if (!ok) {
+ continue;
+ }
+ /* Count the IP's returned from the lookup. */
+ for (p = res; p; p = p->ai_next) {
+ /* Wrap check. */
+ if (num_addrs + 1 < num_addrs) {
+ freeaddrinfo(res);
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+ num_addrs++;
+ }
+
+ /* Wrap check. */
+ if (total_num_addrs + num_addrs < total_num_addrs) {
+ freeaddrinfo(res);
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+ ret_addrs = talloc_realloc(ctx,
+ ret_addrs,
+ struct sockaddr_storage,
+ total_num_addrs + num_addrs);
+ if (ret_addrs == NULL) {
+ freeaddrinfo(res);
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ for (p = res; p; p = p->ai_next) {
+ char addr[INET6_ADDRSTRLEN];
+
+ memcpy(&ret_addrs[total_num_addrs],
+ p->ai_addr,
+ p->ai_addrlen);
+
+ if (is_zero_addr(&ret_addrs[total_num_addrs])) {
+ continue;
+ }
+
+ DBG_DEBUG("getaddrinfo name %s returned IP %s\n",
+ dns_lookup_names[i],
+ print_sockaddr(addr,
+ sizeof(addr),
+ &ret_addrs[total_num_addrs]));
+
+ total_num_addrs++;
+ }
+ freeaddrinfo(res);
+ }
+
+ *p_num_addrs = total_num_addrs;
+ *pp_addrs = ret_addrs;
+ return NT_STATUS_OK;
+}
+
/********************************************************
Resolve via "hosts" method.
*********************************************************/
-static NTSTATUS resolve_hosts(const char *name, int name_type,
- TALLOC_CTX *mem_ctx,
+static NTSTATUS resolve_hosts(TALLOC_CTX *mem_ctx,
+ const char *name,
+ int name_type,
struct sockaddr_storage **return_iplist,
int *return_count)
{
@@ -2374,30 +2455,31 @@ static NTSTATUS resolve_hosts(const char *name, int name_type,
/* Special name type used to cause a _kerberos DNS lookup. */
#define KDC_NAME_TYPE 0xDCDC
-static NTSTATUS resolve_ads(const char *name,
+static NTSTATUS resolve_ads(TALLOC_CTX *ctx,
+ const char *name,
int name_type,
const char *sitename,
- struct ip_service **return_iplist,
+ struct sockaddr_storage **return_addrs,
int *return_count)
{
int i;
NTSTATUS status;
- TALLOC_CTX *ctx;
struct dns_rr_srv *dcs = NULL;
int numdcs = 0;
int numaddrs = 0;
+ size_t num_srv_addrs = 0;
+ struct sockaddr_storage *srv_addrs = NULL;
+ size_t num_dns_addrs = 0;
+ struct sockaddr_storage *dns_addrs = NULL;
+ size_t num_dns_names = 0;
+ const char **dns_lookup_names = NULL;
+ struct sockaddr_storage *ret_addrs = NULL;
if ((name_type != 0x1c) && (name_type != KDC_NAME_TYPE) &&
(name_type != 0x1b)) {
return NT_STATUS_INVALID_PARAMETER;
}
- if ( (ctx = talloc_init("resolve_ads")) == NULL ) {
- DEBUG(0,("resolve_ads: talloc_init() failed!\n"));
- return NT_STATUS_NO_MEMORY;
- }
-
- /* The DNS code needs fixing to find IPv6 addresses... JRA. */
switch (name_type) {
case 0x1b:
DEBUG(5,("resolve_ads: Attempting to resolve "
@@ -2431,112 +2513,197 @@ static NTSTATUS resolve_ads(const char *name,
break;
}
- if ( !NT_STATUS_IS_OK( status ) ) {
- talloc_destroy(ctx);
+ if (!NT_STATUS_IS_OK(status)) {
+ TALLOC_FREE(dcs);
return status;
}
if (numdcs == 0) {
- *return_iplist = NULL;
+ *return_addrs = NULL;
*return_count = 0;
- talloc_destroy(ctx);
+ TALLOC_FREE(dcs);
return NT_STATUS_OK;
}
- for (i=0;i<numdcs;i++) {
- if (!dcs[i].ss_s) {
- numaddrs += 1;
+ /* Paranoia. */
+ if (numdcs < 0) {
+ TALLOC_FREE(dcs);
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ /*
+ * Split the returned values into 2 arrays. First one
+ * is a struct sockaddr_storage array that contains results
+ * from the SRV record lookup that contain both hostnames
+ * and IP addresses. We only need to copy out the IP
+ * addresses. This is srv_addrs.
+ *
+ * Second array contains the results from the SRV record
+ * lookup that only contain hostnames - no IP addresses.
+ * We must then call dns_lookup_list() to lookup
+ * hostnames -> IP address. This is dns_addrs.
+ *
+ * Finally we will merge these two arrays to create the
+ * return sockaddr_storage array.
+ */
+
+ /* First count the sizes of each array. */
+ for(i = 0; i < numdcs; i++) {
+ if (dcs[i].ss_s != NULL) {
+ /* IP address returned in SRV record. */
+ if (num_srv_addrs + dcs[i].num_ips < num_srv_addrs) {
+ /* Wrap check. */
+ TALLOC_FREE(dcs);
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+ /* Add in the number of addresses we got. */
+ num_srv_addrs += dcs[i].num_ips;
+ /*
+ * If we got any IP addresses zero out
+ * the hostname so we know we've already
+ * processed this entry and won't add it
+ * to the dns_lookup_names array we use
+ * to do DNS queries below.
+ */
+ dcs[i].hostname = NULL;
} else {
- numaddrs += dcs[i].num_ips;
+ /* Ensure we have a hostname to lookup. */
+ if (dcs[i].hostname == NULL) {
+ continue;
+ }
+ /* No IP address returned in SRV record. */
+ if (num_dns_names + 1 < num_dns_names) {
+ /* Wrap check. */
+ TALLOC_FREE(dcs);
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+ /* One more name to lookup. */
+ num_dns_names += 1;
}
- }
+ }
- if ((*return_iplist = SMB_MALLOC_ARRAY(struct ip_service, numaddrs)) ==
- NULL ) {
- DEBUG(0,("resolve_ads: malloc failed for %d entries\n",
- numaddrs ));
- talloc_destroy(ctx);
+ /* Allocate the list of IP addresses we already have. */
+ srv_addrs = talloc_zero_array(ctx,
+ struct sockaddr_storage,
+ num_srv_addrs);
+ if (srv_addrs == NULL) {
+ TALLOC_FREE(dcs);
return NT_STATUS_NO_MEMORY;
}
- /* now unroll the list of IP addresses */
-
- *return_count = 0;
+ /* Copy the addresses we already have. */
+ num_srv_addrs = 0;
+ for(i = 0; i < numdcs; i++) {
+ /* Copy all the IP addresses from the SRV response */
+ size_t j;
+ for (j = 0; j < dcs[i].num_ips; j++) {
+ char addr[INET6_ADDRSTRLEN];
- for (i = 0; i < numdcs && (*return_count<numaddrs); i++ ) {
- /* If we don't have an IP list for a name, lookup it up */
- if (!dcs[i].ss_s) {
- /* We need to get all IP addresses here. */
- struct addrinfo *res = NULL;
- struct addrinfo *p;
- int extra_addrs = 0;
-
- if (!interpret_string_addr_internal(&res,
- dcs[i].hostname,
- 0)) {
+ srv_addrs[num_srv_addrs] = dcs[i].ss_s[j];
+ if (is_zero_addr(&srv_addrs[num_srv_addrs])) {
continue;
}
- /* Add in every IP from the lookup. How
- many is that ? */
- for (p = res; p; p = p->ai_next) {
- struct sockaddr_storage ss;
- memcpy(&ss, p->ai_addr, p->ai_addrlen);
- if (is_zero_addr(&ss)) {
- continue;
- }
- extra_addrs++;
- }
- if (extra_addrs > 1) {
- /* We need to expand the return_iplist array
- as we only budgeted for one address. */
- numaddrs += (extra_addrs-1);
- *return_iplist = SMB_REALLOC_ARRAY(*return_iplist,
- struct ip_service,
- numaddrs);
- if (*return_iplist == NULL) {
- if (res) {
- freeaddrinfo(res);
- }
- talloc_destroy(ctx);
- return NT_STATUS_NO_MEMORY;
- }
- }
- for (p = res; p; p = p->ai_next) {
- (*return_iplist)[*return_count].port = dcs[i].port;
- memcpy(&(*return_iplist)[*return_count].ss,
- p->ai_addr,
- p->ai_addrlen);
- if (is_zero_addr(&(*return_iplist)[*return_count].ss)) {
- continue;
- }
- (*return_count)++;
- /* Should never happen, but still... */
- if (*return_count>=numaddrs) {
- break;
- }
- }
- if (res) {
- freeaddrinfo(res);
- }
- } else {
- /* use all the IP addresses from the SRV response */
- size_t j;
- for (j = 0; j < dcs[i].num_ips; j++) {
- (*return_iplist)[*return_count].port = dcs[i].port;
- (*return_iplist)[*return_count].ss = dcs[i].ss_s[j];
- if (is_zero_addr(&(*return_iplist)[*return_count].ss)) {
- continue;
- }
- (*return_count)++;
- /* Should never happen, but still... */
- if (*return_count>=numaddrs) {
- break;
- }
- }
+
+ DBG_DEBUG("SRV lookup %s got IP[%zu] %s\n",
+ name,
+ j,
+ print_sockaddr(addr,
+ sizeof(addr),
+ &srv_addrs[num_srv_addrs]));
+
+ num_srv_addrs++;
}
}
- talloc_destroy(ctx);
+ /* Allocate the array of hostnames we must look up. */
+ dns_lookup_names = talloc_zero_array(ctx,
+ const char *,
+ num_dns_names);
+ if (dns_lookup_names == NULL) {
+ TALLOC_FREE(dcs);
+ TALLOC_FREE(srv_addrs);
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ num_dns_names = 0;
+ for(i = 0; i < numdcs; i++) {
+ if (dcs[i].hostname == NULL) {
+ /*
+ * Must have been a SRV return with an IP address.
+ * We don't need to look up this hostname.
+ */
+ continue;
+ }
+ dns_lookup_names[num_dns_names] = dcs[i].hostname;
+ num_dns_names++;
+ }
+
+ /* Lookup the addresses on the dns_lookup_list. */
+ status = dns_lookup_list(ctx,
+ num_dns_names,
+ dns_lookup_names,
+ &num_dns_addrs,
+ &dns_addrs);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ TALLOC_FREE(dcs);
+ TALLOC_FREE(srv_addrs);
+ TALLOC_FREE(dns_lookup_names);
+ return status;
+ }
+
+ /*
+ * Combine the two sockaddr_storage arrays into a talloc'ed
+ * struct sockaddr_storage array return.
+ */
+
+ numaddrs = num_srv_addrs + num_dns_addrs;
+ /* Wrap check + bloody int conversion check :-(. */
+ if (numaddrs < num_srv_addrs ||
+ numaddrs < 0) {
+ TALLOC_FREE(dcs);
+ TALLOC_FREE(srv_addrs);
+ TALLOC_FREE(dns_addrs);
+ TALLOC_FREE(dns_lookup_names);
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ if (numaddrs == 0) {
+ /* Keep the same semantics for zero names. */
+ TALLOC_FREE(dcs);
+ TALLOC_FREE(srv_addrs);
+ TALLOC_FREE(dns_addrs);
+ TALLOC_FREE(dns_lookup_names);
+ *return_addrs = NULL;
+ *return_count = 0;
+ return NT_STATUS_OK;
+ }
+
+ ret_addrs = talloc_zero_array(ctx,
+ struct sockaddr_storage,
+ numaddrs);
+ if (ret_addrs == NULL) {
+ TALLOC_FREE(dcs);
+ TALLOC_FREE(srv_addrs);
+ TALLOC_FREE(dns_addrs);
+ TALLOC_FREE(dns_lookup_names);
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ for (i = 0; i < num_srv_addrs; i++) {
+ ret_addrs[i] = srv_addrs[i];
+ }
+ for (i = 0; i < num_dns_addrs; i++) {
+ ret_addrs[num_srv_addrs+i] = dns_addrs[i];
+ }
+
+ TALLOC_FREE(dcs);
+ TALLOC_FREE(srv_addrs);
+ TALLOC_FREE(dns_addrs);
+ TALLOC_FREE(dns_lookup_names);
+
+ *return_addrs = ret_addrs;
+ *return_count = numaddrs;
--
Samba Shared Repository
More information about the samba-cvs
mailing list