summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/providers/ipa/ipa_common.c10
-rw-r--r--src/providers/krb5/krb5_common.c11
-rw-r--r--src/resolv/async_resolv.c24
-rw-r--r--src/resolv/async_resolv.h3
4 files changed, 31 insertions, 17 deletions
diff --git a/src/providers/ipa/ipa_common.c b/src/providers/ipa/ipa_common.c
index da3fcd6f..eadbda35 100644
--- a/src/providers/ipa/ipa_common.c
+++ b/src/providers/ipa/ipa_common.c
@@ -609,15 +609,9 @@ static void ipa_resolve_callback(void *private_data, struct fo_server *server)
return;
}
- address = talloc_zero_size(service, 128);
+ address = resolv_get_string_address(service, srvaddr);
if (address == NULL) {
- DEBUG(1, ("talloc_zero failed.\n"));
- return;
- }
-
- if (inet_ntop(srvaddr->h_addrtype, srvaddr->h_addr_list[0],
- address, 128) == NULL) {
- DEBUG(1, ("inet_ntop failed [%d][%s].\n", errno, strerror(errno)));
+ DEBUG(1, ("resolv_get_string_address failed.\n"));
return;
}
diff --git a/src/providers/krb5/krb5_common.c b/src/providers/krb5/krb5_common.c
index ca37ba7d..c0ed6ce3 100644
--- a/src/providers/krb5/krb5_common.c
+++ b/src/providers/krb5/krb5_common.c
@@ -394,16 +394,9 @@ static void krb5_resolve_callback(void *private_data, struct fo_server *server)
return;
}
- address = talloc_zero_size(krb5_service, 128);
+ address = resolv_get_string_address(krb5_service, srvaddr);
if (address == NULL) {
- DEBUG(1, ("talloc_zero failed.\n"));
- return;
- }
-
- if (inet_ntop(srvaddr->h_addrtype, srvaddr->h_addr_list[0],
- address, 128) == NULL) {
- ret = errno;
- DEBUG(1, ("inet_ntop failed [%d][%s].\n", ret, strerror(ret)));
+ DEBUG(1, ("resolv_get_string_address failed.\n"));
return;
}
diff --git a/src/resolv/async_resolv.c b/src/resolv/async_resolv.c
index ff53aa44..13232097 100644
--- a/src/resolv/async_resolv.c
+++ b/src/resolv/async_resolv.c
@@ -648,6 +648,30 @@ resolv_gethostbyname_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
return EOK;
}
+char *
+resolv_get_string_address(TALLOC_CTX *mem_ctx, struct hostent *hostent)
+{
+ char *address;
+
+ if (!hostent) return NULL;
+
+ address = talloc_zero_size(mem_ctx, 128);
+ if (address == NULL) {
+ DEBUG(1, ("talloc_zero failed.\n"));
+ return NULL;
+ }
+
+ errno = 0;
+ if (inet_ntop(hostent->h_addrtype, hostent->h_addr_list[0],
+ address, 128) == NULL) {
+ DEBUG(1, ("inet_ntop failed [%d][%s].\n", errno, strerror(errno)));
+ talloc_free(address);
+ return NULL;
+ }
+
+ return address;
+}
+
static void
ares_gethostbyname_wakeup(struct tevent_req *subreq)
{
diff --git a/src/resolv/async_resolv.h b/src/resolv/async_resolv.h
index b6a13d7f..d6cbe149 100644
--- a/src/resolv/async_resolv.h
+++ b/src/resolv/async_resolv.h
@@ -76,6 +76,9 @@ int resolv_gethostbyname_recv(struct tevent_req *req,
int *timeouts,
struct hostent **hostent);
+char *
+resolv_get_string_address(TALLOC_CTX *mem_ctx, struct hostent *hostent);
+
/** Get SRV record **/
struct tevent_req *resolv_getsrv_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,