krb5 commit: Use k5_parse_host_string() in locate_kdc.c
Greg Hudson
ghudson at mit.edu
Wed Jun 1 13:38:10 EDT 2016
https://github.com/krb5/krb5/commit/c89587b4476139f05f34aa2323bd7c7db348c44c
commit c89587b4476139f05f34aa2323bd7c7db348c44c
Author: Sarah Day <sarahday at mit.edu>
Date: Tue Jan 19 09:47:10 2016 -0500
Use k5_parse_host_string() in locate_kdc.c
[ghudson at mit.edu: made locate_srv_conf_1() error out on port string
with no hostname; split into two commits]
src/lib/krb5/os/locate_kdc.c | 48 +++++++++++++----------------------------
1 files changed, 15 insertions(+), 33 deletions(-)
diff --git a/src/lib/krb5/os/locate_kdc.c b/src/lib/krb5/os/locate_kdc.c
index 196b426..7b46765 100644
--- a/src/lib/krb5/os/locate_kdc.c
+++ b/src/lib/krb5/os/locate_kdc.c
@@ -219,9 +219,9 @@ locate_srv_conf_1(krb5_context context, const krb5_data *realm,
k5_transport transport, int udpport)
{
const char *realm_srv_names[4];
- char **hostlist, *host, *port, *cp;
+ char **hostlist, *host = NULL;
krb5_error_code code;
- int i;
+ int i, default_port;
Tprintf ("looking in krb5.conf for realm %s entry %s; ports %d,%d\n",
realm->data, name, ntohs(udpport));
@@ -259,43 +259,25 @@ locate_srv_conf_1(krb5_context context, const krb5_data *realm,
parse_uri_if_https(host, &this_transport, &host, &uri_path);
- /* 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';
-
- if (port) {
- unsigned long l;
- char *endptr;
- l = strtoul (port, &endptr, 10);
- if (endptr == NULL || *endptr != 0)
- return EINVAL;
- /* L is unsigned, don't need to check <0. */
- if (l > 65535)
- return EINVAL;
- port_num = htons(l);
- } else if (this_transport == HTTPS) {
- port_num = htons(443);
- } else {
- port_num = udpport;
- }
-
- /* If the hostname was in brackets, strip those off now. */
- if (*host == '[' && (cp = strchr(host, ']'))) {
- host++;
- *cp = '\0';
- }
+ default_port = (this_transport == HTTPS) ? htons(443) : udpport;
+ code = k5_parse_host_string(hostlist[i], default_port, &host,
+ &port_num);
+ if (code == 0 && host == NULL)
+ code = EINVAL;
+ if (code)
+ goto cleanup;
- code = add_host_to_list(serverlist, host, port_num, this_transport,
- AF_UNSPEC, uri_path);
+ code = add_host_to_list(serverlist, host, htons(port_num),
+ this_transport, AF_UNSPEC, uri_path);
if (code)
goto cleanup;
+
+ free(host);
+ host = NULL;
}
cleanup:
+ free(host);
profile_free_list(hostlist);
return code;
}
More information about the cvs-krb5
mailing list