s3-kerberos: remove print_kdc_line() completely.
authorGünther Deschner <gd@samba.org>
Mon, 13 Jan 2014 14:59:26 +0000 (15:59 +0100)
committerGünther Deschner <gd@samba.org>
Fri, 7 Mar 2014 15:16:54 +0000 (16:16 +0100)
Just calling print_canonical_sockaddr() is sufficient, as it already deals with
ipv6 as well. The port handling, which was only done for IPv6 (not IPv4), is
removed as well. It was pointless because it always derived the port number from
the provided address which was either a SMB (usually port 445) or LDAP
connection. No KDC will ever run on port 389 or 445 on a Windows/Samba DC.
Finally, the kerberos libraries that we support and build with, can deal with
ipv6 addresses in krb5.conf, so we no longer put the (unnecessary) burden of
resolving the DC name on the kerberos library anymore.

Guenther

Signed-off-by: Günther Deschner <gd@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source3/libads/kerberos.c

index b026e099013506ea40e09d4b617fde452767144a..ea14350e6bc7f04d95c916118a0611d629e5f993 100644 (file)
@@ -592,70 +592,6 @@ int kerberos_kinit_password(const char *principal,
 /************************************************************************
 ************************************************************************/
 
-static char *print_kdc_line(char *mem_ctx,
-                       const char *prev_line,
-                       const struct sockaddr_storage *pss,
-                       const char *kdc_name)
-{
-       char addr[INET6_ADDRSTRLEN];
-       uint16_t port = get_sockaddr_port(pss);
-
-       if (pss->ss_family == AF_INET) {
-               return talloc_asprintf(mem_ctx, "%s\tkdc = %s\n",
-                                      prev_line,
-                                      print_canonical_sockaddr(mem_ctx, pss));
-       }
-
-       /*
-        * IPv6 starts here
-        */
-
-       DEBUG(10, ("print_kdc_line: IPv6 case for kdc_name: %s, port: %d\n",
-                  kdc_name, port));
-
-       if (port != 0 && port != DEFAULT_KRB5_PORT) {
-               /* Currently for IPv6 we can't specify a non-default
-                  krb5 port with an address, as this requires a ':'.
-                  Resolve to a name. */
-               char hostname[MAX_DNS_NAME_LENGTH];
-               int ret = sys_getnameinfo((const struct sockaddr *)pss,
-                                         sizeof(*pss),
-                                         hostname, sizeof(hostname),
-                                         NULL, 0,
-                                         NI_NAMEREQD);
-               if (ret) {
-                       DEBUG(0,("print_kdc_line: can't resolve name "
-                                "for kdc with non-default port %s. "
-                                "Error %s\n.",
-                                print_canonical_sockaddr(mem_ctx, pss),
-                                gai_strerror(ret)));
-                       return NULL;
-               }
-               /* Success, use host:port */
-               return talloc_asprintf(mem_ctx,
-                                      "%s\tkdc = %s:%u\n",
-                                      prev_line,
-                                      hostname,
-                                      (unsigned int)port);
-       }
-
-       /* no krb5 lib currently supports "kdc = ipv6 address"
-        * at all, so just fill in just the kdc_name if we have
-        * it and let the krb5 lib figure out the appropriate
-        * ipv6 address - gd */
-
-       if (kdc_name) {
-               return talloc_asprintf(mem_ctx, "%s\tkdc = %s\n",
-                                      prev_line, kdc_name);
-       }
-
-       return talloc_asprintf(mem_ctx, "%s\tkdc = %s\n",
-                              prev_line,
-                              print_sockaddr(addr,
-                                             sizeof(addr),
-                                             pss));
-}
-
 /************************************************************************
  Create a string list of available kdc's, possibly searching by sitename.
  Does DNS queries.
@@ -698,7 +634,8 @@ static char *get_kdc_ip_string(char *mem_ctx,
        char *result = NULL;
        struct netlogon_samlogon_response **responses = NULL;
        NTSTATUS status;
-       char *kdc_str = print_kdc_line(mem_ctx, "", pss, kdc_name);
+       char *kdc_str = talloc_asprintf(mem_ctx, "%s\tkdc = %s\n", "",
+                                       print_canonical_sockaddr(mem_ctx, pss));
 
        if (kdc_str == NULL) {
                TALLOC_FREE(frame);
@@ -788,9 +725,9 @@ static char *get_kdc_ip_string(char *mem_ctx,
                }
 
                /* Append to the string - inefficient but not done often. */
-               new_kdc_str = print_kdc_line(mem_ctx, kdc_str,
-                                            &dc_addrs[i],
-                                            kdc_name);
+               new_kdc_str = talloc_asprintf(mem_ctx, "%s\tkdc = %s\n",
+                                             kdc_str,
+                                             print_canonical_sockaddr(mem_ctx, &dc_addrs[i]));
                if (new_kdc_str == NULL) {
                        goto fail;
                }