update to use krb5_krbhst API
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@10076 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -237,7 +237,7 @@ init_port(const char *s, int fallback)
|
||||
|
||||
static int
|
||||
send_via_proxy (krb5_context context,
|
||||
const char *hostname,
|
||||
const krb5_krbhst_info *hi,
|
||||
const krb5_data *send,
|
||||
krb5_data *receive)
|
||||
{
|
||||
@@ -285,7 +285,7 @@ send_via_proxy (krb5_context context,
|
||||
}
|
||||
freeaddrinfo (ai);
|
||||
|
||||
asprintf(&prefix, "http://%s/", hostname);
|
||||
asprintf(&prefix, "http://%s/", hi->hostname);
|
||||
if(prefix == NULL) {
|
||||
close(s);
|
||||
return 1;
|
||||
@@ -300,66 +300,38 @@ send_via_proxy (krb5_context context,
|
||||
}
|
||||
|
||||
/*
|
||||
* Send the data `send' to one hots in `hostlist' and get back the reply
|
||||
* Send the data `send' to one host from `handle` and get back the reply
|
||||
* in `receive'.
|
||||
*/
|
||||
|
||||
krb5_error_code
|
||||
krb5_sendto (krb5_context context,
|
||||
const krb5_data *send,
|
||||
char **hostlist,
|
||||
int port,
|
||||
krb5_krbhst_handle handle,
|
||||
krb5_data *receive)
|
||||
{
|
||||
krb5_error_code ret = 0;
|
||||
char **hp, *p;
|
||||
int fd;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < context->max_retries; ++i) {
|
||||
for (hp = hostlist; (p = *hp); ++hp) {
|
||||
char *colon;
|
||||
int http_flag = 0;
|
||||
int tcp_flag = 0;
|
||||
struct addrinfo *ai, *a;
|
||||
struct addrinfo hints;
|
||||
char portstr[NI_MAXSERV];
|
||||
krb5_krbhst_info *hi;
|
||||
|
||||
if(strncmp(p, "http://", 7) == 0){
|
||||
p += 7;
|
||||
http_flag = 1;
|
||||
port = htons(80);
|
||||
} else if(strncmp(p, "http/", 5) == 0) {
|
||||
p += 5;
|
||||
http_flag = 1;
|
||||
port = htons(80);
|
||||
}else if(strncmp(p, "tcp/", 4) == 0){
|
||||
p += 4;
|
||||
tcp_flag = 1;
|
||||
} else if(strncmp(p, "udp/", 4) == 0) {
|
||||
p += 4;
|
||||
}
|
||||
if(http_flag && context->http_proxy) {
|
||||
if (send_via_proxy (context, p, send, receive))
|
||||
while (krb5_krbhst_next(context, handle, &hi) == 0) {
|
||||
int ret;
|
||||
struct addrinfo *ai, *a;
|
||||
|
||||
if(hi->proto == KRB5_KRBHST_HTTP && context->http_proxy) {
|
||||
if (send_via_proxy (context, hi, send, receive))
|
||||
continue;
|
||||
else
|
||||
goto out;
|
||||
}
|
||||
colon = strchr (p, ':');
|
||||
if (colon)
|
||||
*colon++ = '\0';
|
||||
|
||||
memset (&hints, 0, sizeof(hints));
|
||||
hints.ai_family = PF_UNSPEC;
|
||||
if (tcp_flag || http_flag)
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
else
|
||||
hints.ai_socktype = SOCK_DGRAM;
|
||||
snprintf (portstr, sizeof(portstr), "%d",
|
||||
ntohs(init_port (colon, port)));
|
||||
ret = getaddrinfo (p, portstr, &hints, &ai);
|
||||
ret = krb5_krbhst_get_addrinfo(context, hi, &ai);
|
||||
if (ret)
|
||||
continue;
|
||||
|
||||
for (a = ai; a != NULL; a = a->ai_next) {
|
||||
fd = socket (a->ai_family, a->ai_socktype, a->ai_protocol);
|
||||
if (fd < 0)
|
||||
@@ -368,23 +340,28 @@ krb5_sendto (krb5_context context,
|
||||
close (fd);
|
||||
continue;
|
||||
}
|
||||
if(http_flag)
|
||||
switch (hi->proto) {
|
||||
case KRB5_KRBHST_HTTP :
|
||||
ret = send_and_recv_http(fd, context->kdc_timeout,
|
||||
"", send, receive);
|
||||
else if(tcp_flag)
|
||||
break;
|
||||
case KRB5_KRBHST_TCP :
|
||||
ret = send_and_recv_tcp (fd, context->kdc_timeout,
|
||||
send, receive);
|
||||
else
|
||||
break;
|
||||
case KRB5_KRBHST_UDP :
|
||||
ret = send_and_recv_udp (fd, context->kdc_timeout,
|
||||
send, receive);
|
||||
break;
|
||||
}
|
||||
close (fd);
|
||||
if(ret == 0 && receive->length != 0) {
|
||||
freeaddrinfo(ai);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
freeaddrinfo(ai);
|
||||
}
|
||||
krb5_krbhst_reset(context, handle);
|
||||
}
|
||||
krb5_clear_error_string (context);
|
||||
ret = KRB5_KDC_UNREACH;
|
||||
@@ -400,19 +377,20 @@ krb5_sendto_kdc2(krb5_context context,
|
||||
krb5_boolean master)
|
||||
{
|
||||
krb5_error_code ret;
|
||||
char **hostlist;
|
||||
int port;
|
||||
|
||||
port = krb5_getportbyname (context, "kerberos", "udp", 88);
|
||||
|
||||
krb5_krbhst_handle handle;
|
||||
int type;
|
||||
|
||||
if (master || context->use_admin_kdc)
|
||||
ret = krb5_get_krb_admin_hst (context, realm, &hostlist);
|
||||
type = KRB5_KRBHST_ADMIN;
|
||||
else
|
||||
ret = krb5_get_krbhst (context, realm, &hostlist);
|
||||
type = KRB5_KRBHST_KDC;
|
||||
|
||||
ret = krb5_krbhst_init(context, *realm, type, &handle);
|
||||
if (ret)
|
||||
return ret;
|
||||
ret = krb5_sendto(context, send, hostlist, port, receive);
|
||||
krb5_free_krbhst (context, hostlist);
|
||||
|
||||
ret = krb5_sendto(context, send, handle, receive);
|
||||
krb5_krbhst_free(context, handle);
|
||||
if (ret == KRB5_KDC_UNREACH)
|
||||
krb5_set_error_string(context,
|
||||
"unable to reach any KDC in realm %s", *realm);
|
||||
|
Reference in New Issue
Block a user