diff options
author | Gerald (Jerry) Carter <jerry@samba.org> | 2008-03-24 14:48:29 -0500 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2008-03-24 17:25:13 -0500 |
commit | 22d7cd6605b156ca74011b4c05ed47018e7dce7a (patch) | |
tree | df68cb47cc939ad9fb2c4d790d949fa1ecf385f8 /source3 | |
parent | eeeb4aa931111b9091eaf3af8c7e709155a23ccf (diff) | |
download | samba-22d7cd6605b156ca74011b4c05ed47018e7dce7a.tar.gz samba-22d7cd6605b156ca74011b4c05ed47018e7dce7a.tar.bz2 samba-22d7cd6605b156ca74011b4c05ed47018e7dce7a.zip |
Ignore port when pulling IP addr from struct sockaddr_storage.
Linux man page states that getaddinfo() will leave the port
uninitialized when passing in NULL for the service name. So we
can't really trust that anymore. I doubt non-default KDC ports
are an issues so just drop the port from the generated krb5.conf.
AIX exhibits this bug the most.
(This used to be commit 36f8bafbd3dee66a869aa26cfc2eb4aa62019325)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/lib/util_sock.c | 44 |
1 files changed, 10 insertions, 34 deletions
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index 65625138ba..8ceabe19b2 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -108,9 +108,13 @@ static bool interpret_string_addr_internal(struct addrinfo **ppres, hints.ai_socktype = SOCK_STREAM; hints.ai_flags = flags; + /* Linux man page on getaddinfo() says port will be + uninitialized when service string in NULL */ + ret = getaddrinfo(str, NULL, &hints, ppres); + if (ret) { DEBUG(3,("interpret_string_addr_internal: getaddrinfo failed " "for name %s [%s]\n", @@ -541,50 +545,22 @@ char *print_canonical_sockaddr(TALLOC_CTX *ctx, char *dest = NULL; int ret; + /* Linux getnameinfo() man pages says port is unitialized if + service name is NULL. */ + ret = sys_getnameinfo((const struct sockaddr *)pss, sizeof(struct sockaddr_storage), addr, sizeof(addr), NULL, 0, NI_NUMERICHOST); - if (ret) { + if (ret != 0) { return NULL; } - if (pss->ss_family != AF_INET) { #if defined(HAVE_IPV6) - /* IPv6 */ - const struct sockaddr_in6 *sa6 = - (const struct sockaddr_in6 *)pss; - uint16_t port = ntohs(sa6->sin6_port); - - if (port) { - dest = talloc_asprintf(ctx, - "[%s]:%d", - addr, - (unsigned int)port); - } else { - dest = talloc_asprintf(ctx, - "[%s]", - addr); - } + dest = talloc_asprintf(ctx, "[%s]", addr); #else - return NULL; + dest = talloc_asprintf(ctx, "%s", addr); #endif - } else { - const struct sockaddr_in *sa = - (const struct sockaddr_in *)pss; - uint16_t port = ntohs(sa->sin_port); - - if (port) { - dest = talloc_asprintf(ctx, - "%s:%d", - addr, - (unsigned int)port); - } else { - dest = talloc_asprintf(ctx, - "%s", - addr); - } - } return dest; } |