From 7261a9b9f76d19e6a2179a48e903e2fee4ee64a1 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 2 May 2011 16:36:48 +1000 Subject: s4-libcli Remove resolve_name() as it conflicts with Samba3. This was just a wrapper around resolve_name_ex(), so just call that instead. Andrew Bartlett --- source4/libcli/resolve/resolve.c | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index c17e93a1f6..ef61c38f79 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -316,18 +316,6 @@ NTSTATUS resolve_name_ex(struct resolve_context *ctx, } -/* - general name resolution - sync call - */ -NTSTATUS resolve_name(struct resolve_context *ctx, - struct nbt_name *name, - TALLOC_CTX *mem_ctx, - const char **reply_addr, - struct tevent_context *ev) -{ - return resolve_name_ex(ctx, 0, 0, name, mem_ctx, reply_addr, ev); -} - /* Initialise a struct nbt_name with a NULL scope */ void make_nbt_name(struct nbt_name *nbt, const char *name, int type) -- cgit From 22cb631b4fd0647b70fbaaafaffda8712a84a999 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 2 May 2011 15:57:19 +1000 Subject: s4-interfaces Rename interfaces code so not to conflict with source3/ The iface_count, iface_n_bcast, and load_interfaces functions conflicted with functions of the same name in source3, so the source4 functions were renamed. Hopefully we can actually wrap one around the other in future. Andrew Bartlett --- source4/libcli/resolve/bcast.c | 6 +++--- source4/libcli/resolve/wins.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/bcast.c b/source4/libcli/resolve/bcast.c index 0ad3e1230b..794ef34e20 100644 --- a/source4/libcli/resolve/bcast.c +++ b/source4/libcli/resolve/bcast.c @@ -47,13 +47,13 @@ struct composite_context *resolve_name_bcast_send(TALLOC_CTX *mem_ctx, int i, count=0; struct resolve_bcast_data *data = talloc_get_type(userdata, struct resolve_bcast_data); - num_interfaces = iface_count(data->ifaces); + num_interfaces = iface_list_count(data->ifaces); address_list = talloc_array(mem_ctx, const char *, num_interfaces+1); if (address_list == NULL) return NULL; for (i=0;iifaces, i); + const char *bcast = iface_list_n_bcast(data->ifaces, i); if (bcast == NULL) continue; address_list[count] = talloc_strdup(address_list, bcast); if (address_list[count] == NULL) { @@ -101,6 +101,6 @@ bool resolve_context_add_bcast_method(struct resolve_context *ctx, struct interf bool resolve_context_add_bcast_method_lp(struct resolve_context *ctx, struct loadparm_context *lp_ctx) { struct interface *ifaces; - load_interfaces(ctx, lpcfg_interfaces(lp_ctx), &ifaces); + load_interface_list(ctx, lpcfg_interfaces(lp_ctx), &ifaces); return resolve_context_add_bcast_method(ctx, ifaces, lpcfg_nbt_port(lp_ctx), lpcfg_parm_int(lp_ctx, NULL, "nbt", "timeout", 1)); } diff --git a/source4/libcli/resolve/wins.c b/source4/libcli/resolve/wins.c index 989f40e6cd..914386ce9c 100644 --- a/source4/libcli/resolve/wins.c +++ b/source4/libcli/resolve/wins.c @@ -77,6 +77,6 @@ bool resolve_context_add_wins_method(struct resolve_context *ctx, const char **a bool resolve_context_add_wins_method_lp(struct resolve_context *ctx, struct loadparm_context *lp_ctx) { struct interface *ifaces; - load_interfaces(ctx, lpcfg_interfaces(lp_ctx), &ifaces); + load_interface_list(ctx, lpcfg_interfaces(lp_ctx), &ifaces); return resolve_context_add_wins_method(ctx, lpcfg_wins_server_list(lp_ctx), ifaces, lpcfg_nbt_port(lp_ctx), lpcfg_parm_int(lp_ctx, NULL, "nbt", "timeout", 1)); } -- cgit From c31f95f66dcf1c11646b1edd84966e8369904a8c Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Thu, 12 May 2011 20:52:52 +0200 Subject: do an explicit A record search for SRV entries Signed-off-by: Andrew Bartlett --- source4/libcli/resolve/dns_ex.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/dns_ex.c b/source4/libcli/resolve/dns_ex.c index 35e2ad74c3..1d2a8036b1 100644 --- a/source4/libcli/resolve/dns_ex.c +++ b/source4/libcli/resolve/dns_ex.c @@ -87,6 +87,7 @@ static void run_child_dns_lookup(struct dns_ex_state *state, int fd) struct rk_resource_record **srv_rr; uint32_t addrs_valid = 0; struct rk_resource_record **addrs_rr; + struct rk_dns_reply **srv_replies = NULL; char *addrs; bool first; uint32_t i; @@ -167,6 +168,13 @@ static void run_child_dns_lookup(struct dns_ex_state *state, int fd) goto done; } + srv_replies = talloc_zero_array(state, + struct rk_dns_reply *, + count); + if (!srv_replies) { + goto done; + } + /* Loop over all returned records and pick the records */ for (rr=reply->head;rr;rr=rr->next) { /* we are only interested in the IN class */ @@ -210,8 +218,12 @@ static void run_child_dns_lookup(struct dns_ex_state *state, int fd) } for (i=0; i < srv_valid; i++) { - for (rr=reply->head;rr;rr=rr->next) { + srv_replies[i] = rk_dns_lookup(srv_rr[i]->u.srv->target, "A"); + if (srv_replies[i] == NULL) + continue; + /* Add first A record to addrs_rr */ + for (rr=srv_replies[i]->head;rr;rr=rr->next) { if (rr->class != rk_ns_c_in) { continue; } @@ -221,8 +233,8 @@ static void run_child_dns_lookup(struct dns_ex_state *state, int fd) continue; } - /* verify we actually have a srv record here */ - if (strcmp(&srv_rr[i]->u.srv->target[0], rr->domain) != 0) { + /* verify we actually have a A record here */ + if (!rr->u.a) { continue; } @@ -241,7 +253,7 @@ static void run_child_dns_lookup(struct dns_ex_state *state, int fd) goto done; } first = true; - for (i=0; i < count; i++) { + for (i=0; i < addrs_valid; i++) { uint16_t port; if (!addrs_rr[i]) { continue; @@ -270,6 +282,12 @@ static void run_child_dns_lookup(struct dns_ex_state *state, int fd) } done: + if (reply != NULL) + rk_dns_free_data(reply); + for (i=0; i < srv_valid; i++) { + if (srv_replies[i] != NULL) + rk_dns_free_data(srv_replies[i]); + } close(fd); } -- cgit From 40dc94a53f4f0f5dee285daf486912b0996d5f3e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 2 Jun 2011 15:40:28 +1000 Subject: s4-ipv6: update callers to load_interface_list() --- source4/libcli/resolve/bcast.c | 2 +- source4/libcli/resolve/wins.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/bcast.c b/source4/libcli/resolve/bcast.c index 794ef34e20..150705f8d8 100644 --- a/source4/libcli/resolve/bcast.c +++ b/source4/libcli/resolve/bcast.c @@ -101,6 +101,6 @@ bool resolve_context_add_bcast_method(struct resolve_context *ctx, struct interf bool resolve_context_add_bcast_method_lp(struct resolve_context *ctx, struct loadparm_context *lp_ctx) { struct interface *ifaces; - load_interface_list(ctx, lpcfg_interfaces(lp_ctx), &ifaces); + load_interface_list(ctx, lp_ctx, &ifaces); return resolve_context_add_bcast_method(ctx, ifaces, lpcfg_nbt_port(lp_ctx), lpcfg_parm_int(lp_ctx, NULL, "nbt", "timeout", 1)); } diff --git a/source4/libcli/resolve/wins.c b/source4/libcli/resolve/wins.c index 914386ce9c..a52b99a23e 100644 --- a/source4/libcli/resolve/wins.c +++ b/source4/libcli/resolve/wins.c @@ -77,6 +77,6 @@ bool resolve_context_add_wins_method(struct resolve_context *ctx, const char **a bool resolve_context_add_wins_method_lp(struct resolve_context *ctx, struct loadparm_context *lp_ctx) { struct interface *ifaces; - load_interface_list(ctx, lpcfg_interfaces(lp_ctx), &ifaces); + load_interface_list(ctx, lp_ctx, &ifaces); return resolve_context_add_wins_method(ctx, lpcfg_wins_server_list(lp_ctx), ifaces, lpcfg_nbt_port(lp_ctx), lpcfg_parm_int(lp_ctx, NULL, "nbt", "timeout", 1)); } -- cgit From d1c90c465ee3d0bf60daf23c8eb9510071426c97 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 6 Jun 2011 08:09:02 +1000 Subject: s4-ipv6: cope with IPv6 in our async DNS client code --- source4/libcli/resolve/dns_ex.c | 56 ++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/dns_ex.c b/source4/libcli/resolve/dns_ex.c index 1d2a8036b1..069ba823c2 100644 --- a/source4/libcli/resolve/dns_ex.c +++ b/source4/libcli/resolve/dns_ex.c @@ -37,6 +37,7 @@ #include "libcli/composite/composite.h" #include "librpc/gen_ndr/ndr_nbt.h" #include "libcli/resolve/resolve.h" +#include "lib/util/util_net.h" #ifdef class #undef class @@ -136,14 +137,13 @@ static void run_child_dns_lookup(struct dns_ex_state *state, int fd) continue; } } else { - /* we are only interested in A records */ - /* TODO: add AAAA support */ - if (rr->type != rk_ns_t_a) { + /* we are only interested in A or AAAA records */ + if (rr->type != rk_ns_t_a && rr->type != rk_ns_t_aaaa) { continue; } - /* verify we actually have a A record here */ - if (!rr->u.a) { + /* verify we actually have a record here */ + if (!rr->u.data) { continue; } } @@ -201,14 +201,13 @@ static void run_child_dns_lookup(struct dns_ex_state *state, int fd) srv_rr[srv_valid] = rr; srv_valid++; } else { - /* we are only interested in A records */ - /* TODO: add AAAA support */ - if (rr->type != rk_ns_t_a) { + /* we are only interested in A or AAAA records */ + if (rr->type != rk_ns_t_a && rr->type != rk_ns_t_aaaa) { continue; } - /* verify we actually have a A record here */ - if (!rr->u.a) { + /* verify we actually have a record record here */ + if (!rr->u.data) { continue; } @@ -228,13 +227,13 @@ static void run_child_dns_lookup(struct dns_ex_state *state, int fd) continue; } - /* we are only interested in A records */ - if (rr->type != rk_ns_t_a) { + /* we are only interested in A or AAAA records */ + if (rr->type != rk_ns_t_a && rr->type != rk_ns_t_aaaa) { continue; } - /* verify we actually have a A record here */ - if (!rr->u.a) { + /* verify we actually have a record here */ + if (!rr->u.data) { continue; } @@ -255,6 +254,8 @@ static void run_child_dns_lookup(struct dns_ex_state *state, int fd) first = true; for (i=0; i < addrs_valid; i++) { uint16_t port; + char addrstr[INET6_ADDRSTRLEN]; + if (!addrs_rr[i]) { continue; } @@ -266,9 +267,13 @@ static void run_child_dns_lookup(struct dns_ex_state *state, int fd) port = state->port; } - addrs = talloc_asprintf_append_buffer(addrs, "%s%s:%u/%s", + if (!print_sockaddr_len(addrstr, sizeof(addrstr), (struct sockaddr *)addrs_rr[i]->u.data, addrs_rr[i]->size)) { + continue; + } + + addrs = talloc_asprintf_append_buffer(addrs, "%s%s@%u/%s", first?"":",", - inet_ntoa(*addrs_rr[i]->u.a), + addrstr, port, addrs_rr[i]->domain); if (!addrs) { @@ -305,7 +310,6 @@ static void run_child_getaddrinfo(struct dns_ex_state *state, int fd) ZERO_STRUCT(hints); hints.ai_socktype = SOCK_STREAM; - hints.ai_family = AF_INET;/* TODO: add AF_INET6 support */ hints.ai_flags = AI_ADDRCONFIG | AI_NUMERICSERV; ret = getaddrinfo(state->name.name, "0", &hints, &res_list); @@ -333,16 +337,13 @@ static void run_child_getaddrinfo(struct dns_ex_state *state, int fd) } first = true; for (res = res_list; res; res = res->ai_next) { - struct sockaddr_in *in; - - if (res->ai_family != AF_INET) { + char addrstr[INET6_ADDRSTRLEN]; + if (!print_sockaddr_len(addrstr, sizeof(addrstr), (struct sockaddr *)res->ai_addr, res->ai_addrlen)) { continue; } - in = (struct sockaddr_in *)res->ai_addr; - - addrs = talloc_asprintf_append_buffer(addrs, "%s%s:%u/%s", + addrs = talloc_asprintf_append_buffer(addrs, "%s%s@%u/%s", first?"":",", - inet_ntoa(in->sin_addr), + addrstr, state->port, state->name.name); if (!addrs) { @@ -424,7 +425,7 @@ static void pipe_handler(struct tevent_context *ev, struct tevent_fd *fde, for (i=0; i < num_addrs; i++) { uint32_t port = 0; - char *p = strrchr(addrs[i], ':'); + char *p = strrchr(addrs[i], '@'); char *n; if (!p) { @@ -444,8 +445,7 @@ static void pipe_handler(struct tevent_context *ev, struct tevent_fd *fde, *n = '\0'; n++; - if (strcmp(addrs[i], "0.0.0.0") == 0 || - inet_addr(addrs[i]) == INADDR_NONE) { + if (strcmp(addrs[i], "0.0.0.0") == 0) { composite_error(c, NT_STATUS_OBJECT_NAME_NOT_FOUND); return; } @@ -455,7 +455,7 @@ static void pipe_handler(struct tevent_context *ev, struct tevent_fd *fde, return; } state->addrs[i] = socket_address_from_strings(state->addrs, - "ipv4", + "ip", addrs[i], port); if (composite_nomem(state->addrs[i], c)) return; -- cgit From d8e2302330db1b4d1c5b29608823d46a03fd087a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 6 Jun 2011 10:13:20 +1000 Subject: s4-ipv6: allow for IPv6 in resolver top level calls --- source4/libcli/resolve/resolve.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index ef61c38f79..b5930aade1 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -171,12 +171,10 @@ struct composite_context *resolve_name_all_send(struct resolve_context *ctx, if (is_ipaddress(state->name.name) || strcasecmp(state->name.name, "localhost") == 0) { - struct in_addr ip = interpret_addr2(state->name.name); - state->addrs = talloc_array(state, struct socket_address *, 2); if (composite_nomem(state->addrs, c)) return c; - state->addrs[0] = socket_address_from_strings(state->addrs, "ipv4", - inet_ntoa(ip), 0); + state->addrs[0] = socket_address_from_strings(state->addrs, "ip", + state->name.name, 0); if (composite_nomem(state->addrs[0], c)) return c; state->addrs[1] = NULL; state->names = talloc_array(state, char *, 2); -- cgit From 64380ff050c77b2b67c0fac4ada8650e834c4b4a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 7 Jun 2011 12:35:10 +1000 Subject: s4-ipv6: fixed DNS handling with new IPv6 code --- source4/libcli/resolve/dns_ex.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/dns_ex.c b/source4/libcli/resolve/dns_ex.c index 069ba823c2..cb2d2c3d2c 100644 --- a/source4/libcli/resolve/dns_ex.c +++ b/source4/libcli/resolve/dns_ex.c @@ -267,7 +267,22 @@ static void run_child_dns_lookup(struct dns_ex_state *state, int fd) port = state->port; } - if (!print_sockaddr_len(addrstr, sizeof(addrstr), (struct sockaddr *)addrs_rr[i]->u.data, addrs_rr[i]->size)) { + switch (rr->type) { + case rk_ns_t_a: + if (inet_ntop(AF_INET, addrs_rr[i]->u.a, + addrstr, sizeof(addrstr)) == NULL) { + continue; + } + break; +#ifdef HAVE_IPV6 + case rk_ns_t_aaaa: + if (inet_ntop(AF_INET6, (struct in6_addr *)addrs_rr[i]->u.data, + addrstr, sizeof(addrstr)) == NULL) { + continue; + } + break; +#endif + default: continue; } -- cgit From 285293c8b5d85383aa5af9968dc73fba5beb9de0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 7 Jun 2011 14:10:38 +1000 Subject: s4-ipv6: fixed a crash in the IPv6 DNS code --- source4/libcli/resolve/dns_ex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/dns_ex.c b/source4/libcli/resolve/dns_ex.c index cb2d2c3d2c..1d56a4b4d5 100644 --- a/source4/libcli/resolve/dns_ex.c +++ b/source4/libcli/resolve/dns_ex.c @@ -267,7 +267,7 @@ static void run_child_dns_lookup(struct dns_ex_state *state, int fd) port = state->port; } - switch (rr->type) { + switch (addrs_rr[i]->type) { case rk_ns_t_a: if (inet_ntop(AF_INET, addrs_rr[i]->u.a, addrstr, sizeof(addrstr)) == NULL) { -- cgit From a1f04e8abc761ef1ba211420ff1dbda50fcf527d Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 20 Jun 2011 14:55:32 +1000 Subject: libcli/util Rename common map_nt_error_from_unix to avoid duplicate symbol The two error tables need to be combined, but for now seperate the names. (As the common parts of the tree now use the _common function, errmap_unix.c must be included in the s3 autoconf build). Andrew Bartlett Autobuild-User: Andrew Bartlett Autobuild-Date: Mon Jun 20 08:12:03 CEST 2011 on sn-devel-104 --- source4/libcli/resolve/dns_ex.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/resolve') diff --git a/source4/libcli/resolve/dns_ex.c b/source4/libcli/resolve/dns_ex.c index 1d56a4b4d5..5921212579 100644 --- a/source4/libcli/resolve/dns_ex.c +++ b/source4/libcli/resolve/dns_ex.c @@ -518,7 +518,7 @@ struct composite_context *resolve_name_dns_ex_send(TALLOC_CTX *mem_ctx, /* setup a pipe to chat to our child */ ret = pipe(fd); if (ret == -1) { - composite_error(c, map_nt_error_from_unix(errno)); + composite_error(c, map_nt_error_from_unix_common(errno)); return c; } @@ -542,7 +542,7 @@ struct composite_context *resolve_name_dns_ex_send(TALLOC_CTX *mem_ctx, state->child = fork(); if (state->child == (pid_t)-1) { - composite_error(c, map_nt_error_from_unix(errno)); + composite_error(c, map_nt_error_from_unix_common(errno)); return c; } -- cgit