summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Layton <jlayton@redhat.com>2009-10-14 11:06:19 -0400
committerKarolin Seeger <kseeger@samba.org>2010-01-13 14:00:50 +0100
commit6472943d242ad347ce48ec69d838606c3d759e42 (patch)
tree32a8e5b664b498cc024307c29a37aaac498d2241
parentddbd5be71987a446a24c49f68075b6c645539e4f (diff)
downloadsamba-6472943d242ad347ce48ec69d838606c3d759e42.tar.gz
samba-6472943d242ad347ce48ec69d838606c3d759e42.tar.xz
samba-6472943d242ad347ce48ec69d838606c3d759e42.zip
cifs.upcall: fix IPv6 addrs sent to upcall to have colon delimiters
Current kernels don't send IPv6 addresses with the colon delimiters, add a routine to add them when they're not present. Signed-off-by: Jeff Layton <jlayton@redhat.com> (cherry picked from commit 177e5437a75267fdfce8ba693f039a10344e5974)
-rw-r--r--source/client/cifs.upcall.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/source/client/cifs.upcall.c b/source/client/cifs.upcall.c
index 287efc4c374..f433e495c68 100644
--- a/source/client/cifs.upcall.c
+++ b/source/client/cifs.upcall.c
@@ -296,18 +296,43 @@ cifs_resolver(const key_serial_t key, const char *key_descr)
return 0;
}
+/*
+ * Older kernels sent IPv6 addresses without colons. Well, at least
+ * they're fixed-length strings. Convert these addresses to have colon
+ * delimiters to make getaddrinfo happy.
+ */
+static void
+convert_inet6_addr(const char *from, char *to)
+{
+ int i = 1;
+
+ while (*from) {
+ *to++ = *from++;
+ if (!(i++ % 4) && *from)
+ *to++ = ':';
+ }
+ *to = 0;
+}
+
static int
-ip_to_fqdn(const char *ipaddr, char *host, size_t hostlen)
+ip_to_fqdn(const char *addrstr, char *host, size_t hostlen)
{
int rc;
struct addrinfo hints = { .ai_flags = AI_NUMERICHOST };
struct addrinfo *res;
+ const char *ipaddr = addrstr;
+ char converted[INET6_ADDRSTRLEN + 1];
+
+ if ((strlen(ipaddr) > INET_ADDRSTRLEN) && !strchr(ipaddr, ':')) {
+ convert_inet6_addr(ipaddr, converted);
+ ipaddr = converted;
+ }
rc = getaddrinfo(ipaddr, NULL, &hints, &res);
if (rc) {
- syslog(LOG_DEBUG, "%s: failed to resolve %s to ipaddr: %s",
- __func__, ipaddr,
- rc == EAI_SYSTEM ? strerror(errno) : gai_strerror(rc));
+ syslog(LOG_DEBUG, "%s: failed to resolve %s to "
+ "ipaddr: %s", __func__, ipaddr,
+ rc == EAI_SYSTEM ? strerror(errno) : gai_strerror(rc));
return rc;
}