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
|
static int
|
||||||
send_via_proxy (krb5_context context,
|
send_via_proxy (krb5_context context,
|
||||||
const char *hostname,
|
const krb5_krbhst_info *hi,
|
||||||
const krb5_data *send,
|
const krb5_data *send,
|
||||||
krb5_data *receive)
|
krb5_data *receive)
|
||||||
{
|
{
|
||||||
@@ -285,7 +285,7 @@ send_via_proxy (krb5_context context,
|
|||||||
}
|
}
|
||||||
freeaddrinfo (ai);
|
freeaddrinfo (ai);
|
||||||
|
|
||||||
asprintf(&prefix, "http://%s/", hostname);
|
asprintf(&prefix, "http://%s/", hi->hostname);
|
||||||
if(prefix == NULL) {
|
if(prefix == NULL) {
|
||||||
close(s);
|
close(s);
|
||||||
return 1;
|
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'.
|
* in `receive'.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
krb5_error_code
|
krb5_error_code
|
||||||
krb5_sendto (krb5_context context,
|
krb5_sendto (krb5_context context,
|
||||||
const krb5_data *send,
|
const krb5_data *send,
|
||||||
char **hostlist,
|
krb5_krbhst_handle handle,
|
||||||
int port,
|
|
||||||
krb5_data *receive)
|
krb5_data *receive)
|
||||||
{
|
{
|
||||||
krb5_error_code ret = 0;
|
krb5_error_code ret = 0;
|
||||||
char **hp, *p;
|
|
||||||
int fd;
|
int fd;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < context->max_retries; ++i) {
|
for (i = 0; i < context->max_retries; ++i) {
|
||||||
for (hp = hostlist; (p = *hp); ++hp) {
|
krb5_krbhst_info *hi;
|
||||||
char *colon;
|
|
||||||
int http_flag = 0;
|
|
||||||
int tcp_flag = 0;
|
|
||||||
struct addrinfo *ai, *a;
|
|
||||||
struct addrinfo hints;
|
|
||||||
char portstr[NI_MAXSERV];
|
|
||||||
|
|
||||||
if(strncmp(p, "http://", 7) == 0){
|
while (krb5_krbhst_next(context, handle, &hi) == 0) {
|
||||||
p += 7;
|
int ret;
|
||||||
http_flag = 1;
|
struct addrinfo *ai, *a;
|
||||||
port = htons(80);
|
|
||||||
} else if(strncmp(p, "http/", 5) == 0) {
|
if(hi->proto == KRB5_KRBHST_HTTP && context->http_proxy) {
|
||||||
p += 5;
|
if (send_via_proxy (context, hi, send, receive))
|
||||||
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))
|
|
||||||
continue;
|
continue;
|
||||||
else
|
else
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
colon = strchr (p, ':');
|
|
||||||
if (colon)
|
|
||||||
*colon++ = '\0';
|
|
||||||
|
|
||||||
memset (&hints, 0, sizeof(hints));
|
ret = krb5_krbhst_get_addrinfo(context, hi, &ai);
|
||||||
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);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (a = ai; a != NULL; a = a->ai_next) {
|
for (a = ai; a != NULL; a = a->ai_next) {
|
||||||
fd = socket (a->ai_family, a->ai_socktype, a->ai_protocol);
|
fd = socket (a->ai_family, a->ai_socktype, a->ai_protocol);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
@@ -368,23 +340,28 @@ krb5_sendto (krb5_context context,
|
|||||||
close (fd);
|
close (fd);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(http_flag)
|
switch (hi->proto) {
|
||||||
|
case KRB5_KRBHST_HTTP :
|
||||||
ret = send_and_recv_http(fd, context->kdc_timeout,
|
ret = send_and_recv_http(fd, context->kdc_timeout,
|
||||||
"", send, receive);
|
"", send, receive);
|
||||||
else if(tcp_flag)
|
break;
|
||||||
|
case KRB5_KRBHST_TCP :
|
||||||
ret = send_and_recv_tcp (fd, context->kdc_timeout,
|
ret = send_and_recv_tcp (fd, context->kdc_timeout,
|
||||||
send, receive);
|
send, receive);
|
||||||
else
|
break;
|
||||||
|
case KRB5_KRBHST_UDP :
|
||||||
ret = send_and_recv_udp (fd, context->kdc_timeout,
|
ret = send_and_recv_udp (fd, context->kdc_timeout,
|
||||||
send, receive);
|
send, receive);
|
||||||
|
break;
|
||||||
|
}
|
||||||
close (fd);
|
close (fd);
|
||||||
if(ret == 0 && receive->length != 0) {
|
if(ret == 0 && receive->length != 0) {
|
||||||
freeaddrinfo(ai);
|
freeaddrinfo(ai);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
freeaddrinfo(ai);
|
|
||||||
}
|
}
|
||||||
|
krb5_krbhst_reset(context, handle);
|
||||||
}
|
}
|
||||||
krb5_clear_error_string (context);
|
krb5_clear_error_string (context);
|
||||||
ret = KRB5_KDC_UNREACH;
|
ret = KRB5_KDC_UNREACH;
|
||||||
@@ -400,19 +377,20 @@ krb5_sendto_kdc2(krb5_context context,
|
|||||||
krb5_boolean master)
|
krb5_boolean master)
|
||||||
{
|
{
|
||||||
krb5_error_code ret;
|
krb5_error_code ret;
|
||||||
char **hostlist;
|
krb5_krbhst_handle handle;
|
||||||
int port;
|
int type;
|
||||||
|
|
||||||
port = krb5_getportbyname (context, "kerberos", "udp", 88);
|
|
||||||
|
|
||||||
if (master || context->use_admin_kdc)
|
if (master || context->use_admin_kdc)
|
||||||
ret = krb5_get_krb_admin_hst (context, realm, &hostlist);
|
type = KRB5_KRBHST_ADMIN;
|
||||||
else
|
else
|
||||||
ret = krb5_get_krbhst (context, realm, &hostlist);
|
type = KRB5_KRBHST_KDC;
|
||||||
|
|
||||||
|
ret = krb5_krbhst_init(context, *realm, type, &handle);
|
||||||
if (ret)
|
if (ret)
|
||||||
return 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)
|
if (ret == KRB5_KDC_UNREACH)
|
||||||
krb5_set_error_string(context,
|
krb5_set_error_string(context,
|
||||||
"unable to reach any KDC in realm %s", *realm);
|
"unable to reach any KDC in realm %s", *realm);
|
||||||
|
Reference in New Issue
Block a user