diff options
author | nectar <nectar@FreeBSD.org> | 2002-02-19 15:46:56 +0000 |
---|---|---|
committer | nectar <nectar@FreeBSD.org> | 2002-02-19 15:46:56 +0000 |
commit | 69a91bec14ec3ad49d1c8a82c40a796755f9e4a3 (patch) | |
tree | 85ecf91fd00875cec4b93111d3a8ed9eec9cddfe /crypto/heimdal/lib/krb5/send_to_kdc.c | |
parent | 8db4cdb3da4228a5d93635e43825e2e8a2f66db7 (diff) | |
download | FreeBSD-src-69a91bec14ec3ad49d1c8a82c40a796755f9e4a3.zip FreeBSD-src-69a91bec14ec3ad49d1c8a82c40a796755f9e4a3.tar.gz |
Import of Heimdal Kerberos from KTH repository circa 2002/02/17.
Diffstat (limited to 'crypto/heimdal/lib/krb5/send_to_kdc.c')
-rw-r--r-- | crypto/heimdal/lib/krb5/send_to_kdc.c | 96 |
1 files changed, 36 insertions, 60 deletions
diff --git a/crypto/heimdal/lib/krb5/send_to_kdc.c b/crypto/heimdal/lib/krb5/send_to_kdc.c index 5a66f02..37ba96d 100644 --- a/crypto/heimdal/lib/krb5/send_to_kdc.c +++ b/crypto/heimdal/lib/krb5/send_to_kdc.c @@ -33,7 +33,7 @@ #include "krb5_locl.h" -RCSID("$Id: send_to_kdc.c,v 1.44 2001/05/14 22:49:56 assar Exp $"); +RCSID("$Id: send_to_kdc.c,v 1.47 2001/07/03 19:35:46 assar Exp $"); /* * send the data in `req' on the socket `fd' (which is datagram iff udp) @@ -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) { @@ -248,7 +248,7 @@ send_via_proxy (krb5_context context, struct addrinfo hints; struct addrinfo *ai, *a; int ret; - int s; + int s = -1; char portstr[NI_MAXSERV]; if (proxy == NULL) @@ -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; + krb5_krbhst_info *hi; + + while (krb5_krbhst_next(context, handle, &hi) == 0) { + int ret; struct addrinfo *ai, *a; - struct addrinfo hints; - char portstr[NI_MAXSERV]; - - 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)) + + 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,26 @@ 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); + if(ret == 0 && receive->length != 0) goto out; - } } - freeaddrinfo(ai); } + krb5_krbhst_reset(context, handle); } krb5_clear_error_string (context); ret = KRB5_KDC_UNREACH; @@ -400,19 +375,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); |