1505d05c7Sgtb /*
2505d05c7Sgtb  * lib/krb5/os/dnssrv.c
3505d05c7Sgtb  *
4505d05c7Sgtb  * Copyright 1990,2000,2001,2002,2003 by the Massachusetts Institute of Technology.
5505d05c7Sgtb  * All Rights Reserved.
6505d05c7Sgtb  *
7505d05c7Sgtb  * Export of this software from the United States of America may
8505d05c7Sgtb  *   require a specific license from the United States Government.
9505d05c7Sgtb  *   It is the responsibility of any person or organization contemplating
10505d05c7Sgtb  *   export to obtain such a license before exporting.
11505d05c7Sgtb  *
12505d05c7Sgtb  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13505d05c7Sgtb  * distribute this software and its documentation for any purpose and
14505d05c7Sgtb  * without fee is hereby granted, provided that the above copyright
15505d05c7Sgtb  * notice appear in all copies and that both that copyright notice and
16505d05c7Sgtb  * this permission notice appear in supporting documentation, and that
17505d05c7Sgtb  * the name of M.I.T. not be used in advertising or publicity pertaining
18505d05c7Sgtb  * to distribution of the software without specific, written prior
19505d05c7Sgtb  * permission.  Furthermore if you modify this software you must label
20505d05c7Sgtb  * your software as modified software and not distribute it in such a
21505d05c7Sgtb  * fashion that it might be confused with the original M.I.T. software.
22505d05c7Sgtb  * M.I.T. makes no representations about the suitability of
23505d05c7Sgtb  * this software for any purpose.  It is provided "as is" without express
24505d05c7Sgtb  * or implied warranty.
25505d05c7Sgtb  *
26505d05c7Sgtb  *
27505d05c7Sgtb  * do DNS SRV RR queries
28505d05c7Sgtb  */
29505d05c7Sgtb 
30*159d09a2SMark Phalan #include "autoconf.h"
31505d05c7Sgtb #ifdef KRB5_DNS_LOOKUP
32505d05c7Sgtb 
33505d05c7Sgtb #include "dnsglue.h"
34505d05c7Sgtb 
35505d05c7Sgtb /*
36505d05c7Sgtb  * Lookup a KDC via DNS SRV records
37505d05c7Sgtb  */
38505d05c7Sgtb 
krb5int_free_srv_dns_data(struct srv_dns_entry * p)39505d05c7Sgtb void krb5int_free_srv_dns_data (struct srv_dns_entry *p)
40505d05c7Sgtb {
41505d05c7Sgtb     struct srv_dns_entry *next;
42505d05c7Sgtb     while (p) {
43505d05c7Sgtb 	next = p->next;
44505d05c7Sgtb 	free(p->host);
45505d05c7Sgtb 	free(p);
46505d05c7Sgtb 	p = next;
47505d05c7Sgtb     }
48505d05c7Sgtb }
49505d05c7Sgtb 
50505d05c7Sgtb /* Do DNS SRV query, return results in *answers.
51505d05c7Sgtb 
52505d05c7Sgtb    Make best effort to return all the data we can.  On memory or
53505d05c7Sgtb    decoding errors, just return what we've got.  Always return 0,
54505d05c7Sgtb    currently.  */
55505d05c7Sgtb 
56505d05c7Sgtb krb5_error_code
krb5int_make_srv_query_realm(const krb5_data * realm,const char * service,const char * protocol,struct srv_dns_entry ** answers)57505d05c7Sgtb krb5int_make_srv_query_realm(const krb5_data *realm,
58505d05c7Sgtb 			     const char *service,
59505d05c7Sgtb 			     const char *protocol,
60505d05c7Sgtb 			     struct srv_dns_entry **answers)
61505d05c7Sgtb {
62505d05c7Sgtb     const unsigned char *p = NULL, *base = NULL;
63505d05c7Sgtb     char host[MAXDNAME], *h;
64505d05c7Sgtb     int size, ret, rdlen, nlen;
65