svn rev #24073: branches/krb5-1-8/ doc/ src/lib/kadm5/ src/lib/krb5/os/

tlyu@MIT.EDU tlyu at MIT.EDU
Thu May 20 16:41:16 EDT 2010


http://src.mit.edu/fisheye/changelog/krb5/?cs=24073
Commit By: tlyu
Log Message:
ticket:	6562
version_fixed: 1.8.2
status: resolved

pull up r24055 from trunk

 ------------------------------------------------------------------------
 r24055 | ghudson | 2010-05-18 13:19:15 -0400 (Tue, 18 May 2010) | 6 lines

 ticket:	6562

 When parsing a KDC or admin server string, allow the name or address
 to be enclosed in brackets so that IPv6 addresses can be represented.
 (IPv6 addresses contain colons, which look like port separators.)


Changed Files:
U   branches/krb5-1-8/doc/admin.texinfo
U   branches/krb5-1-8/src/lib/kadm5/alt_prof.c
U   branches/krb5-1-8/src/lib/krb5/os/locate_kdc.c
Modified: branches/krb5-1-8/doc/admin.texinfo
===================================================================
--- branches/krb5-1-8/doc/admin.texinfo	2010-05-20 15:13:06 UTC (rev 24072)
+++ branches/krb5-1-8/doc/admin.texinfo	2010-05-20 20:41:16 UTC (rev 24073)
@@ -680,12 +680,14 @@
 
 @table @b
 @itemx kdc
-The name of a host running a KDC for that realm.  An optional port
-number (separated from the hostname by a colon) may be included.  For
-your computer to be able to communicate with the KDC for each realm,
-this tag must be given a value in each realm subsection in the
-configuration file, or there must be DNS SRV records specifying the
-KDCs (see @ref{Using DNS}).
+The name or address of a host running a KDC for that realm.  An optional
+port number, separated from the hostname by a colon, may be included.
+If the name or address contains colons (for example, if it is an IPv6
+address), enclose it in square brackets to distinguish the colon from a
+port separator.  For your computer to be able to communicate with the
+KDC for each realm, this tag must be given a value in each realm
+subsection in the configuration file, or there must be DNS SRV records
+specifying the KDCs (see @ref{Using DNS}).
 
 @itemx master_kdc
 Identifies the master KDC(s).  Currently, this tag is used in only one

Modified: branches/krb5-1-8/src/lib/kadm5/alt_prof.c
===================================================================
--- branches/krb5-1-8/src/lib/kadm5/alt_prof.c	2010-05-20 15:13:06 UTC (rev 24072)
+++ branches/krb5-1-8/src/lib/kadm5/alt_prof.c	2010-05-20 20:41:16 UTC (rev 24073)
@@ -482,6 +482,36 @@
 }
 
 /*
+ * Parse out the port number from an admin_server setting.  Modify server to
+ * contain just the hostname or address.  If a port is given, set *port, and
+ * set the appropriate bit in *mask.
+ */
+static void
+parse_admin_server_port(char *server, int *port, long *mask)
+{
+    char *end, *portstr;
+
+    /* Allow the name or addr to be enclosed in brackets, for IPv6 addrs. */
+    if (*server == '[' && (end = strchr(server + 1, ']')) != NULL) {
+        portstr = (*(end + 1) == ':') ? end + 2 : NULL;
+        /* Shift the bracketed name or address back into server. */
+        memmove(server, server + 1, end - (server + 1));
+        *(end - 1) = '\0';
+    } else {
+        /* Terminate the name at the colon, if any. */
+        end = server + strcspn(server, ":");
+        portstr = (*end == ':') ? end + 1 : NULL;
+        *end = '\0';
+    }
+
+    /* If we found a port string, parse it and set the appropriate bit. */
+    if (portstr) {
+        *port = atoi(portstr);
+        *mask |= KADM5_CONFIG_KADMIND_PORT;
+    }
+}
+
+/*
  * Function: kadm5_get_config_params
  *
  * Purpose: Merge configuration parameters provided by the caller with
@@ -581,13 +611,8 @@
                      NULL);
 
     if (params.mask & KADM5_CONFIG_ADMIN_SERVER) {
-        char *p;
-        p = strchr(params.admin_server, ':');
-        if (p) {
-            params.kadmind_port = atoi(p+1);
-            params.mask |= KADM5_CONFIG_KADMIND_PORT;
-            *p = '\0';
-        }
+        parse_admin_server_port(params.admin_server, &params.kadmind_port,
+                                &params.mask);
     }
 
     /* Get the value for the database */

Modified: branches/krb5-1-8/src/lib/krb5/os/locate_kdc.c
===================================================================
--- branches/krb5-1-8/src/lib/krb5/os/locate_kdc.c	2010-05-20 15:13:06 UTC (rev 24072)
+++ branches/krb5-1-8/src/lib/krb5/os/locate_kdc.c	2010-05-20 20:41:16 UTC (rev 24073)
@@ -374,19 +374,11 @@
         if (code == 0) {
             for (i=0; masterlist[i]; i++) {
                 host = masterlist[i];
-
-                /*
-                 * Strip off excess whitespace
-                 */
-                cp = strchr(host, ' ');
-                if (cp)
-                    *cp = 0;
-                cp = strchr(host, '\t');
-                if (cp)
-                    *cp = 0;
-                cp = strchr(host, ':');
-                if (cp)
-                    *cp = 0;
+                /* Strip off excess characters. */
+                if (*host == '[' && (cp = strchr(host, ']')))
+                    *(cp + 1) = '\0';
+                else
+                    *(host + strcspn(host, " \t:")) = '\0';
             }
         }
     } else {
@@ -407,20 +399,13 @@
 
         host = hostlist[i];
         Tprintf ("entry %d is '%s'\n", i, host);
-        /*
-         * Strip off excess whitespace
-         */
-        cp = strchr(host, ' ');
-        if (cp)
-            *cp = 0;
-        cp = strchr(host, '\t');
-        if (cp)
-            *cp = 0;
-        port = strchr(host, ':');
-        if (port) {
-            *port = 0;
-            port++;
-        }
+        /* Find port number, and strip off any excess characters. */
+        if (*host == '[' && (cp = strchr(host, ']')))
+            cp = cp + 1;
+        else
+            cp = host + strcspn(host, " \t:");
+        port = (*cp == ':') ? cp + 1 : NULL;
+        *cp = '\0';
 
         ismaster = 0;
         if (masterlist) {
@@ -454,15 +439,20 @@
             p2 = sec_udpport;
         }
 
+        /* If the hostname was in brackets, strip those off now. */
+        if (*host == '[' && (cp = strchr(host, ']'))) {
+            host++;
+            *cp = '\0';
+        }
+
         if (socktype != 0)
-            code = add_host_to_list (addrlist, hostlist[i], p1, p2,
-                                     socktype, family);
+            code = add_host_to_list(addrlist, host, p1, p2, socktype, family);
         else {
-            code = add_host_to_list (addrlist, hostlist[i], p1, p2,
-                                     SOCK_DGRAM, family);
+            code = add_host_to_list(addrlist, host, p1, p2, SOCK_DGRAM,
+                                    family);
             if (code == 0)
-                code = add_host_to_list (addrlist, hostlist[i], p1, p2,
-                                         SOCK_STREAM, family);
+                code = add_host_to_list(addrlist, host, p1, p2, SOCK_STREAM,
+                                        family);
         }
         if (code) {
             Tprintf ("error %d (%s) returned from add_host_to_list\n", code,




More information about the cvs-krb5 mailing list