Skip to content

Commit

Permalink
Use k5_parse_host_string() in locate_kdc.c
Browse files Browse the repository at this point in the history
[ghudson@mit.edu: made locate_srv_conf_1() error out on port string
with no hostname; split into two commits]
  • Loading branch information
SaharahSarah authored and greghudson committed Jun 1, 2016
1 parent c2d843a commit c89587b
Showing 1 changed file with 15 additions and 33 deletions.
48 changes: 15 additions & 33 deletions src/lib/krb5/os/locate_kdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit c89587b

Please sign in to comment.