11047Sgtb /* 2*7934SMark.Phalan@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 31047Sgtb * Use is subject to license terms. 41047Sgtb */ 51047Sgtb 6781Sgtb /* 7781Sgtb * lib/krb5/os/dnsglue.h 8781Sgtb * 9781Sgtb * Copyright 2004 by the Massachusetts Institute of Technology. 10781Sgtb * All Rights Reserved. 11781Sgtb * 12781Sgtb * Export of this software from the United States of America may 13781Sgtb * require a specific license from the United States Government. 14781Sgtb * It is the responsibility of any person or organization contemplating 15781Sgtb * export to obtain such a license before exporting. 16781Sgtb * 17781Sgtb * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and 18781Sgtb * distribute this software and its documentation for any purpose and 19781Sgtb * without fee is hereby granted, provided that the above copyright 20781Sgtb * notice appear in all copies and that both that copyright notice and 21781Sgtb * this permission notice appear in supporting documentation, and that 22781Sgtb * the name of M.I.T. not be used in advertising or publicity pertaining 23781Sgtb * to distribution of the software without specific, written prior 24781Sgtb * permission. Furthermore if you modify this software you must label 25781Sgtb * your software as modified software and not distribute it in such a 26781Sgtb * fashion that it might be confused with the original M.I.T. software. 27781Sgtb * M.I.T. makes no representations about the suitability of 28781Sgtb * this software for any purpose. It is provided "as is" without express 29781Sgtb * or implied warranty. 30781Sgtb * 31781Sgtb * Glue layer for DNS resolver, to make parsing of replies easier 32781Sgtb * whether we are using BIND 4, 8, or 9. 33781Sgtb */ 34781Sgtb 35781Sgtb /* 36781Sgtb * BIND 4 doesn't have the ns_initparse() API, so we need to do some 37781Sgtb * manual parsing via the HEADER struct. BIND 8 does have 38781Sgtb * ns_initparse(), but has enums for the various protocol constants 39781Sgtb * rather than the BIND 4 macros. BIND 9 (at least on Mac OS X 40781Sgtb * Panther) appears to disable res_nsearch() if BIND_8_COMPAT is 41781Sgtb * defined (which is necessary to obtain the HEADER struct). 42781Sgtb * 43781Sgtb * We use ns_initparse() if available at all, and never define 44781Sgtb * BIND_8_COMPAT. If there is no ns_initparse(), we do manual parsing 45781Sgtb * by using the HEADER struct. 46781Sgtb */ 47781Sgtb 48781Sgtb #ifndef KRB5_DNSGLUE_H 49781Sgtb #define KRB5_DNSGLUE_H 50781Sgtb 51*7934SMark.Phalan@Sun.COM #include "autoconf.h" 52781Sgtb #ifdef KRB5_DNS_LOOKUP 53781Sgtb 54781Sgtb #include "k5-int.h" 55781Sgtb #include "os-proto.h" 56781Sgtb #ifdef WSHELPER 57781Sgtb #include <wshelper.h> 58781Sgtb #else /* WSHELPER */ 59781Sgtb #include <netinet/in.h> 60781Sgtb #include <arpa/inet.h> 61781Sgtb #include <arpa/nameser.h> 62781Sgtb #include <resolv.h> 63781Sgtb #include <netdb.h> 64781Sgtb #endif /* WSHELPER */ 65781Sgtb 66781Sgtb #if HAVE_SYS_PARAM_H 67781Sgtb #include <sys/param.h> /* for MAXHOSTNAMELEN */ 68781Sgtb #endif 69781Sgtb 70781Sgtb #ifndef MAXHOSTNAMELEN 71781Sgtb #define MAXHOSTNAMELEN 64 /* if we can't find it elswhere */ 72781Sgtb #endif 73781Sgtb 74781Sgtb #ifndef MAXDNAME 75781Sgtb 76781Sgtb #ifdef NS_MAXDNAME 77781Sgtb #define MAXDNAME NS_MAXDNAME 78781Sgtb #else 79781Sgtb #ifdef MAXLABEL 80781Sgtb #define MAXDNAME (16 * MAXLABEL) 81781Sgtb #else 82781Sgtb #define MAXDNAME (16 * MAXHOSTNAMELEN) 83781Sgtb #endif 84781Sgtb #endif 85781Sgtb 86781Sgtb #endif 87781Sgtb 88*7934SMark.Phalan@Sun.COM #if HAVE_NS_INITPARSE 89*7934SMark.Phalan@Sun.COM /* 90*7934SMark.Phalan@Sun.COM * Solaris 7 has ns_rr_cl rather than ns_rr_class. 91*7934SMark.Phalan@Sun.COM */ 92*7934SMark.Phalan@Sun.COM #if !defined(ns_rr_class) && defined(ns_rr_cl) 93*7934SMark.Phalan@Sun.COM #define ns_rr_class ns_rr_cl 94*7934SMark.Phalan@Sun.COM #endif 95*7934SMark.Phalan@Sun.COM #endif 96*7934SMark.Phalan@Sun.COM 97781Sgtb #if HAVE_RES_NSEARCH 98781Sgtb /* 99781Sgtb * Some BIND 8 / BIND 9 implementations disable the BIND 4 style 100781Sgtb * constants. 101781Sgtb */ 102781Sgtb #ifndef C_IN 103781Sgtb #define C_IN ns_c_in 104781Sgtb #endif 105781Sgtb #ifndef T_SRV 106781Sgtb #define T_SRV ns_t_srv 107781Sgtb #endif 108781Sgtb #ifndef T_TXT 109781Sgtb #define T_TXT ns_t_txt 110781Sgtb #endif 111781Sgtb 112781Sgtb #else /* !HAVE_RES_NSEARCH */ 113781Sgtb 114781Sgtb /* 115781Sgtb * Some BIND implementations might be old enough to lack these. 116781Sgtb */ 117781Sgtb #ifndef T_TXT 118781Sgtb #define T_TXT 15 119781Sgtb #endif 120781Sgtb #ifndef T_SRV 121781Sgtb #define T_SRV 33 122781Sgtb #endif 123781Sgtb 124781Sgtb #endif /* HAVE_RES_NSEARCH */ 125781Sgtb 126781Sgtb /* 127781Sgtb * INCR_OK 128781Sgtb * 129781Sgtb * Given moving pointer PTR offset from BASE, return true if adding 130781Sgtb * INCR to PTR doesn't move it PTR than MAX bytes from BASE. 131781Sgtb */ 132781Sgtb #define INCR_OK(base, max, ptr, incr) \ 133781Sgtb ((incr) <= (max) - ((const unsigned char *)(ptr) \ 134781Sgtb - (const unsigned char *)(base))) 135781Sgtb 136781Sgtb /* 137781Sgtb * SAFE_GETUINT16 138781Sgtb * 139781Sgtb * Given PTR offset from BASE, if at least INCR bytes are safe to 140781Sgtb * read, get network byte order uint16 into S, and increment PTR. On 141781Sgtb * failure, goto LABEL. 142781Sgtb */ 143781Sgtb 144*7934SMark.Phalan@Sun.COM /* Solaris Kerberos */ 145781Sgtb #define SAFE_GETUINT16(base, max, ptr, incr, s, label) \ 146781Sgtb do { \ 147781Sgtb if (!INCR_OK(base, max, ptr, incr)) goto label; \ 1481047Sgtb (s) = (unsigned short)(ptr)[0] << 8 \ 1491047Sgtb | (unsigned short)(ptr)[1]; \ 1501047Sgtb (ptr) += (incr); \ 151781Sgtb } while (0) 152781Sgtb 153781Sgtb struct krb5int_dns_state; 154781Sgtb 155781Sgtb int krb5int_dns_init(struct krb5int_dns_state **, char *, int, int); 156781Sgtb int krb5int_dns_nextans(struct krb5int_dns_state *, 157781Sgtb const unsigned char **, int *); 158781Sgtb int krb5int_dns_expand(struct krb5int_dns_state *, 159781Sgtb const unsigned char *, char *, int); 160781Sgtb void krb5int_dns_fini(struct krb5int_dns_state *); 161781Sgtb 162781Sgtb #endif /* KRB5_DNS_LOOKUP */ 163781Sgtb #endif /* !defined(KRB5_DNSGLUE_H) */ 164