2N/A/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2N/A/*
2N/A * lib/krb5/os/dnsglue.h
2N/A *
2N/A * Copyright 2004 by the Massachusetts Institute of Technology.
2N/A * All Rights Reserved.
2N/A *
2N/A * Export of this software from the United States of America may
2N/A * require a specific license from the United States Government.
2N/A * It is the responsibility of any person or organization contemplating
2N/A * export to obtain such a license before exporting.
2N/A *
2N/A * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
2N/A * distribute this software and its documentation for any purpose and
2N/A * without fee is hereby granted, provided that the above copyright
2N/A * notice appear in all copies and that both that copyright notice and
2N/A * this permission notice appear in supporting documentation, and that
2N/A * the name of M.I.T. not be used in advertising or publicity pertaining
2N/A * to distribution of the software without specific, written prior
2N/A * permission. Furthermore if you modify this software you must label
2N/A * your software as modified software and not distribute it in such a
2N/A * fashion that it might be confused with the original M.I.T. software.
2N/A * M.I.T. makes no representations about the suitability of
2N/A * this software for any purpose. It is provided "as is" without express
2N/A * or implied warranty.
2N/A *
2N/A * Glue layer for DNS resolver, to make parsing of replies easier
2N/A * whether we are using BIND 4, 8, or 9.
2N/A */
2N/A
2N/A/*
2N/A * BIND 4 doesn't have the ns_initparse() API, so we need to do some
2N/A * manual parsing via the HEADER struct. BIND 8 does have
2N/A * ns_initparse(), but has enums for the various protocol constants
2N/A * rather than the BIND 4 macros. BIND 9 (at least on Mac OS X
2N/A * Panther) appears to disable res_nsearch() if BIND_8_COMPAT is
2N/A * defined (which is necessary to obtain the HEADER struct).
2N/A *
2N/A * We use ns_initparse() if available at all, and never define
2N/A * BIND_8_COMPAT. If there is no ns_initparse(), we do manual parsing
2N/A * by using the HEADER struct.
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#ifndef KRB5_DNSGLUE_H
2N/A#define KRB5_DNSGLUE_H
2N/A
2N/A#include "autoconf.h"
2N/A#ifdef KRB5_DNS_LOOKUP
2N/A
2N/A#include "k5-int.h"
2N/A#include "os-proto.h"
2N/A#ifdef WSHELPER
2N/A#include <wshelper.h>
2N/A#else /* WSHELPER */
2N/A#include <netinet/in.h>
2N/A#include <arpa/inet.h>
2N/A#include <arpa/nameser.h>
2N/A#include <resolv.h>
2N/A#include <netdb.h>
2N/A#endif /* WSHELPER */
2N/A
2N/A#if HAVE_SYS_PARAM_H
2N/A#include <sys/param.h> /* for MAXHOSTNAMELEN */
2N/A#endif
2N/A
2N/A#ifndef MAXHOSTNAMELEN
2N/A#define MAXHOSTNAMELEN 64 /* if we can't find it elswhere */
2N/A#endif
2N/A
2N/A#ifndef MAXDNAME
2N/A
2N/A#ifdef NS_MAXDNAME
2N/A#define MAXDNAME NS_MAXDNAME
2N/A#else
2N/A#ifdef MAXLABEL
2N/A#define MAXDNAME (16 * MAXLABEL)
2N/A#else
2N/A#define MAXDNAME (16 * MAXHOSTNAMELEN)
2N/A#endif
2N/A#endif
2N/A
2N/A#endif
2N/A
2N/A#if HAVE_NS_INITPARSE
2N/A/*
2N/A * Solaris 7 has ns_rr_cl rather than ns_rr_class.
2N/A */
2N/A#if !defined(ns_rr_class) && defined(ns_rr_cl)
2N/A#define ns_rr_class ns_rr_cl
2N/A#endif
2N/A#endif
2N/A
2N/A#if HAVE_RES_NSEARCH
2N/A/*
2N/A * Some BIND 8 / BIND 9 implementations disable the BIND 4 style
2N/A * constants.
2N/A */
2N/A#ifndef C_IN
2N/A#define C_IN ns_c_in
2N/A#endif
2N/A#ifndef T_SRV
2N/A#define T_SRV ns_t_srv
2N/A#endif
2N/A#ifndef T_TXT
2N/A#define T_TXT ns_t_txt
2N/A#endif
2N/A
2N/A#else /* !HAVE_RES_NSEARCH */
2N/A
2N/A/*
2N/A * Some BIND implementations might be old enough to lack these.
2N/A */
2N/A#ifndef T_TXT
2N/A#define T_TXT 15
2N/A#endif
2N/A#ifndef T_SRV
2N/A#define T_SRV 33
2N/A#endif
2N/A
2N/A#endif /* HAVE_RES_NSEARCH */
2N/A
2N/A/*
2N/A * INCR_OK
2N/A *
2N/A * Given moving pointer PTR offset from BASE, return true if adding
2N/A * INCR to PTR doesn't move it PTR than MAX bytes from BASE.
2N/A */
2N/A#define INCR_OK(base, max, ptr, incr) \
2N/A ((incr) <= (max) - ((const unsigned char *)(ptr) \
2N/A - (const unsigned char *)(base)))
2N/A
2N/A/*
2N/A * SAFE_GETUINT16
2N/A *
2N/A * Given PTR offset from BASE, if at least INCR bytes are safe to
2N/A * read, get network byte order uint16 into S, and increment PTR. On
2N/A * failure, goto LABEL.
2N/A */
2N/A/* Solaris Kerberos: p should be ptr */
2N/A#define SAFE_GETUINT16(base, max, ptr, incr, s, label) \
2N/A do { \
2N/A if (!INCR_OK(base, max, ptr, incr)) goto label; \
2N/A (s) = (unsigned short)(ptr)[0] << 8 \
2N/A | (unsigned short)(ptr)[1]; \
2N/A (ptr) += (incr); \
2N/A } while (0)
2N/A
2N/Astruct krb5int_dns_state;
2N/A
2N/Aint krb5int_dns_init(struct krb5int_dns_state **, char *, int, int);
2N/Aint krb5int_dns_nextans(struct krb5int_dns_state *,
2N/A const unsigned char **, int *);
2N/Aint krb5int_dns_expand(struct krb5int_dns_state *,
2N/A const unsigned char *, char *, int);
2N/Avoid krb5int_dns_fini(struct krb5int_dns_state *);
2N/A
2N/A#endif /* KRB5_DNS_LOOKUP */
2N/A#endif /* !defined(KRB5_DNSGLUE_H) */