|
|
6cf099 |
From 194e127156332dcd29a7e2aa4a142b574e8b7eac Mon Sep 17 00:00:00 2001
|
|
|
6cf099 |
From: Pavel Reichl <preichl@redhat.com>
|
|
|
6cf099 |
Date: Fri, 24 Jul 2015 08:24:48 -0400
|
|
|
6cf099 |
Subject: [PATCH 89/90] DYNDNS: remove code duplication
|
|
|
6cf099 |
|
|
|
6cf099 |
Move copy pasted code for converting sockaddr_storage to string into
|
|
|
6cf099 |
function.
|
|
|
6cf099 |
|
|
|
6cf099 |
Resolves:
|
|
|
6cf099 |
https://fedorahosted.org/sssd/ticket/2495
|
|
|
6cf099 |
|
|
|
6cf099 |
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
6cf099 |
(cherry picked from commit b42bf6c0c01db08208fb81d8295a2909d307284a)
|
|
|
6cf099 |
---
|
|
|
6cf099 |
src/providers/dp_dyndns.c | 99 +++++++++++++++++++++--------------------------
|
|
|
6cf099 |
src/util/util_errors.c | 1 +
|
|
|
6cf099 |
src/util/util_errors.h | 1 +
|
|
|
6cf099 |
3 files changed, 46 insertions(+), 55 deletions(-)
|
|
|
6cf099 |
|
|
|
6cf099 |
diff --git a/src/providers/dp_dyndns.c b/src/providers/dp_dyndns.c
|
|
|
6cf099 |
index ae3f913ee392a6513f75aab497e7f2d784784748..0577743cb2daca9c0e86b5beb6bf059ee7b5783f 100644
|
|
|
6cf099 |
--- a/src/providers/dp_dyndns.c
|
|
|
6cf099 |
+++ b/src/providers/dp_dyndns.c
|
|
|
6cf099 |
@@ -58,6 +58,39 @@ void sss_iface_addr_concatenate(struct sss_iface_addr **list,
|
|
|
6cf099 |
DLIST_CONCATENATE((*list), list2, struct sss_iface_addr*);
|
|
|
6cf099 |
}
|
|
|
6cf099 |
|
|
|
6cf099 |
+static errno_t addr_to_str(struct sockaddr_storage *addr,
|
|
|
6cf099 |
+ char *dst, size_t size)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ const void *src;
|
|
|
6cf099 |
+ const char *res;
|
|
|
6cf099 |
+ errno_t ret;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ switch(addr->ss_family) {
|
|
|
6cf099 |
+ case AF_INET:
|
|
|
6cf099 |
+ src = &(((struct sockaddr_in *)addr)->sin_addr);
|
|
|
6cf099 |
+ break;
|
|
|
6cf099 |
+ case AF_INET6:
|
|
|
6cf099 |
+ src = &(((struct sockaddr_in6 *)addr)->sin6_addr);
|
|
|
6cf099 |
+ break;
|
|
|
6cf099 |
+ default:
|
|
|
6cf099 |
+ ret = ERR_ADDR_FAMILY_NOT_SUPPORTED;
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ res = inet_ntop(addr->ss_family, src, dst, size);
|
|
|
6cf099 |
+ if (res == NULL) {
|
|
|
6cf099 |
+ ret = errno;
|
|
|
6cf099 |
+ DEBUG(SSSDBG_OP_FAILURE, "inet_ntop failed [%d]: %s\n",
|
|
|
6cf099 |
+ ret, sss_strerror(ret));
|
|
|
6cf099 |
+ goto done;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = EOK;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+done:
|
|
|
6cf099 |
+ return ret;
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
errno_t
|
|
|
6cf099 |
sss_iface_addr_list_as_str_list(TALLOC_CTX *mem_ctx,
|
|
|
6cf099 |
struct sss_iface_addr *ifaddr_list,
|
|
|
6cf099 |
@@ -67,7 +100,6 @@ sss_iface_addr_list_as_str_list(TALLOC_CTX *mem_ctx,
|
|
|
6cf099 |
size_t count;
|
|
|
6cf099 |
int ai;
|
|
|
6cf099 |
char **straddrs;
|
|
|
6cf099 |
- const char *ip;
|
|
|
6cf099 |
char ip_addr[INET6_ADDRSTRLEN];
|
|
|
6cf099 |
errno_t ret;
|
|
|
6cf099 |
|
|
|
6cf099 |
@@ -83,35 +115,17 @@ sss_iface_addr_list_as_str_list(TALLOC_CTX *mem_ctx,
|
|
|
6cf099 |
|
|
|
6cf099 |
ai = 0;
|
|
|
6cf099 |
DLIST_FOR_EACH(ifaddr, ifaddr_list) {
|
|
|
6cf099 |
- switch(ifaddr->addr->ss_family) {
|
|
|
6cf099 |
- case AF_INET:
|
|
|
6cf099 |
- errno = 0;
|
|
|
6cf099 |
- ip = inet_ntop(ifaddr->addr->ss_family,
|
|
|
6cf099 |
- &(((struct sockaddr_in *)ifaddr->addr)->sin_addr),
|
|
|
6cf099 |
- ip_addr, INET6_ADDRSTRLEN);
|
|
|
6cf099 |
- if (ip == NULL) {
|
|
|
6cf099 |
- ret = errno;
|
|
|
6cf099 |
- goto fail;
|
|
|
6cf099 |
- }
|
|
|
6cf099 |
- break;
|
|
|
6cf099 |
|
|
|
6cf099 |
- case AF_INET6:
|
|
|
6cf099 |
- errno = 0;
|
|
|
6cf099 |
- ip = inet_ntop(ifaddr->addr->ss_family,
|
|
|
6cf099 |
- &(((struct sockaddr_in6 *)ifaddr->addr)->sin6_addr),
|
|
|
6cf099 |
- ip_addr, INET6_ADDRSTRLEN);
|
|
|
6cf099 |
- if (ip == NULL) {
|
|
|
6cf099 |
- ret = errno;
|
|
|
6cf099 |
- goto fail;
|
|
|
6cf099 |
- }
|
|
|
6cf099 |
- break;
|
|
|
6cf099 |
-
|
|
|
6cf099 |
- default:
|
|
|
6cf099 |
- DEBUG(SSSDBG_CRIT_FAILURE, "Unknown address family\n");
|
|
|
6cf099 |
+ ret = addr_to_str(ifaddr->addr, ip_addr, INET6_ADDRSTRLEN);
|
|
|
6cf099 |
+ if (ret == ERR_ADDR_FAMILY_NOT_SUPPORTED) {
|
|
|
6cf099 |
continue;
|
|
|
6cf099 |
+ } else if (ret != EOK) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_MINOR_FAILURE, "addr_to_str failed: %d:[%s],\n",
|
|
|
6cf099 |
+ ret, sss_strerror(ret));
|
|
|
6cf099 |
+ goto fail;
|
|
|
6cf099 |
}
|
|
|
6cf099 |
|
|
|
6cf099 |
- straddrs[ai] = talloc_strdup(straddrs, ip);
|
|
|
6cf099 |
+ straddrs[ai] = talloc_strdup(straddrs, ip_addr);
|
|
|
6cf099 |
if (straddrs[ai] == NULL) {
|
|
|
6cf099 |
ret = ENOMEM;
|
|
|
6cf099 |
goto fail;
|
|
|
6cf099 |
@@ -237,7 +251,6 @@ nsupdate_msg_add_fwd(char *update_msg, struct sss_iface_addr *addresses,
|
|
|
6cf099 |
{
|
|
|
6cf099 |
struct sss_iface_addr *new_record;
|
|
|
6cf099 |
char ip_addr[INET6_ADDRSTRLEN];
|
|
|
6cf099 |
- const char *ip;
|
|
|
6cf099 |
errno_t ret;
|
|
|
6cf099 |
|
|
|
6cf099 |
/* Remove existing entries as needed */
|
|
|
6cf099 |
@@ -259,33 +272,10 @@ nsupdate_msg_add_fwd(char *update_msg, struct sss_iface_addr *addresses,
|
|
|
6cf099 |
}
|
|
|
6cf099 |
|
|
|
6cf099 |
DLIST_FOR_EACH(new_record, addresses) {
|
|
|
6cf099 |
- switch(new_record->addr->ss_family) {
|
|
|
6cf099 |
- case AF_INET:
|
|
|
6cf099 |
- ip = inet_ntop(new_record->addr->ss_family,
|
|
|
6cf099 |
- &(((struct sockaddr_in *)new_record->addr)->sin_addr),
|
|
|
6cf099 |
- ip_addr, INET6_ADDRSTRLEN);
|
|
|
6cf099 |
- if (ip == NULL) {
|
|
|
6cf099 |
- ret = errno;
|
|
|
6cf099 |
- DEBUG(SSSDBG_OP_FAILURE,
|
|
|
6cf099 |
- "inet_ntop failed [%d]: %s\n", ret, strerror(ret));
|
|
|
6cf099 |
- return NULL;
|
|
|
6cf099 |
- }
|
|
|
6cf099 |
- break;
|
|
|
6cf099 |
-
|
|
|
6cf099 |
- case AF_INET6:
|
|
|
6cf099 |
- ip = inet_ntop(new_record->addr->ss_family,
|
|
|
6cf099 |
- &(((struct sockaddr_in6 *)new_record->addr)->sin6_addr),
|
|
|
6cf099 |
- ip_addr, INET6_ADDRSTRLEN);
|
|
|
6cf099 |
- if (ip == NULL) {
|
|
|
6cf099 |
- ret = errno;
|
|
|
6cf099 |
- DEBUG(SSSDBG_OP_FAILURE,
|
|
|
6cf099 |
- "inet_ntop failed [%d]: %s\n", ret, strerror(ret));
|
|
|
6cf099 |
- return NULL;
|
|
|
6cf099 |
- }
|
|
|
6cf099 |
- break;
|
|
|
6cf099 |
-
|
|
|
6cf099 |
- default:
|
|
|
6cf099 |
- DEBUG(SSSDBG_CRIT_FAILURE, "Unknown address family\n");
|
|
|
6cf099 |
+ ret = addr_to_str(new_record->addr, ip_addr, INET6_ADDRSTRLEN);
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_MINOR_FAILURE, "addr_to_str failed: %d:[%s],\n",
|
|
|
6cf099 |
+ ret, sss_strerror(ret));
|
|
|
6cf099 |
return NULL;
|
|
|
6cf099 |
}
|
|
|
6cf099 |
|
|
|
6cf099 |
@@ -298,7 +288,6 @@ nsupdate_msg_add_fwd(char *update_msg, struct sss_iface_addr *addresses,
|
|
|
6cf099 |
if (update_msg == NULL) {
|
|
|
6cf099 |
return NULL;
|
|
|
6cf099 |
}
|
|
|
6cf099 |
-
|
|
|
6cf099 |
}
|
|
|
6cf099 |
|
|
|
6cf099 |
return talloc_asprintf_append(update_msg, "send\n");
|
|
|
6cf099 |
diff --git a/src/util/util_errors.c b/src/util/util_errors.c
|
|
|
6cf099 |
index 0e288e3908bf03b4906bb449bd0f3445d22a303e..3041a1a28481aa8916bc1f5d972365e3c8007a4a 100644
|
|
|
6cf099 |
--- a/src/util/util_errors.c
|
|
|
6cf099 |
+++ b/src/util/util_errors.c
|
|
|
6cf099 |
@@ -80,6 +80,7 @@ struct err_string error_to_str[] = {
|
|
|
6cf099 |
{ "Trusted forest root unknown" }, /* ERR_TRUST_FOREST_UNKNOWN */
|
|
|
6cf099 |
{ "p11_child failed" }, /* ERR_P11_CHILD */
|
|
|
6cf099 |
{ "Subdomain is inactive" }, /* ERR_SUBDOM_INACTIVE */
|
|
|
6cf099 |
+ { "Address family not supported" }, /* ERR_ADDR_FAMILY_NOT_SUPPORTED */
|
|
|
6cf099 |
{ "ERR_LAST" } /* ERR_LAST */
|
|
|
6cf099 |
};
|
|
|
6cf099 |
|
|
|
6cf099 |
diff --git a/src/util/util_errors.h b/src/util/util_errors.h
|
|
|
6cf099 |
index da926db00121f569048ec515e95f0547ae6c4e35..660c370d600f6373d4515181cf88f62b42bcb7d7 100644
|
|
|
6cf099 |
--- a/src/util/util_errors.h
|
|
|
6cf099 |
+++ b/src/util/util_errors.h
|
|
|
6cf099 |
@@ -102,6 +102,7 @@ enum sssd_errors {
|
|
|
6cf099 |
ERR_TRUST_FOREST_UNKNOWN,
|
|
|
6cf099 |
ERR_P11_CHILD,
|
|
|
6cf099 |
ERR_SUBDOM_INACTIVE,
|
|
|
6cf099 |
+ ERR_ADDR_FAMILY_NOT_SUPPORTED,
|
|
|
6cf099 |
ERR_LAST /* ALWAYS LAST */
|
|
|
6cf099 |
};
|
|
|
6cf099 |
|
|
|
6cf099 |
--
|
|
|
6cf099 |
2.4.3
|
|
|
6cf099 |
|