2N/A/*
2N/A * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A
2N/A/*
2N/A * Copyright (c) 1985, 1993
2N/A * The Regents of the University of California. All rights reserved.
2N/A *
2N/A * Redistribution and use in source and binary forms, with or without
2N/A * modification, are permitted provided that the following conditions
2N/A * are met:
2N/A * 1. Redistributions of source code must retain the above copyright
2N/A * notice, this list of conditions and the following disclaimer.
2N/A * 2. Redistributions in binary form must reproduce the above copyright
2N/A * notice, this list of conditions and the following disclaimer in the
2N/A * documentation and/or other materials provided with the distribution.
2N/A * 3. All advertising materials mentioning features or use of this software
2N/A * must display the following acknowledgement:
2N/A * This product includes software developed by the University of
2N/A * California, Berkeley and its contributors.
2N/A * 4. Neither the name of the University nor the names of its contributors
2N/A * may be used to endorse or promote products derived from this software
2N/A * without specific prior written permission.
2N/A *
2N/A * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2N/A * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2N/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2N/A * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2N/A * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2N/A * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2N/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2N/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2N/A * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2N/A * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2N/A * SUCH DAMAGE.
2N/A */
2N/A
2N/A/*
2N/A * Portions Copyright (c) 1993 by Digital Equipment Corporation.
2N/A *
2N/A * Permission to use, copy, modify, and distribute this software for any
2N/A * purpose with or without fee is hereby granted, provided that the above
2N/A * copyright notice and this permission notice appear in all copies, and that
2N/A * the name of Digital Equipment Corporation not be used in advertising or
2N/A * publicity pertaining to distribution of the document or software without
2N/A * specific, written prior permission.
2N/A *
2N/A * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
2N/A * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
2N/A * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
2N/A * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
2N/A * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
2N/A * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
2N/A * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
2N/A * SOFTWARE.
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
2N/A * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
2N/A *
2N/A * Permission to use, copy, modify, and distribute this software for any
2N/A * purpose with or without fee is hereby granted, provided that the above
2N/A * copyright notice and this permission notice appear in all copies.
2N/A *
2N/A * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
2N/A * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
2N/A * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
2N/A * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
2N/A * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
2N/A * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
2N/A * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2N/A */
2N/A
2N/A#if defined(LIBC_SCCS) && !defined(lint)
2N/Astatic const char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93";
2N/Astatic const char rcsid[] = "$Id: res_comp.c,v 1.5 2005/07/28 06:51:50 marka Exp $";
2N/A#endif /* LIBC_SCCS and not lint */
2N/A
2N/A#include "port_before.h"
2N/A#include <sys/types.h>
2N/A#include <sys/param.h>
2N/A#include <netinet/in.h>
2N/A#include <arpa/nameser.h>
2N/A#include <ctype.h>
2N/A#include <resolv.h>
2N/A#include <stdio.h>
2N/A#include <string.h>
2N/A#include <unistd.h>
2N/A#include "port_after.h"
2N/A
2N/A#ifndef ORIGINAL_ISC_CODE
2N/A#pragma weak __dn_skipname = dn_skipname
2N/A#pragma weak __res_dnok = res_dnok
2N/A#pragma weak __res_hnok = res_hnok
2N/A#pragma weak __res_mailok = res_mailok
2N/A#pragma weak __res_ownok = res_ownok
2N/A#endif /* ORIGINAL_ISC_CODE */
2N/A
2N/A/*%
2N/A * Expand compressed domain name 'src' to full domain name.
2N/A *
2N/A * \li 'msg' is a pointer to the begining of the message,
2N/A * \li 'eom' points to the first location after the message,
2N/A * \li 'dst' is a pointer to a buffer of size 'dstsiz' for the result.
2N/A * \li Return size of compressed name or -1 if there was an error.
2N/A */
2N/Aint
2N/Adn_expand(const u_char *msg, const u_char *eom, const u_char *src,
2N/A char *dst, int dstsiz)
2N/A{
2N/A int n = ns_name_uncompress(msg, eom, src, dst, (size_t)dstsiz);
2N/A
2N/A if (n > 0 && dst[0] == '.')
2N/A dst[0] = '\0';
2N/A return (n);
2N/A}
2N/A
2N/A/*%
2N/A * Pack domain name 'exp_dn' in presentation form into 'comp_dn'.
2N/A *
2N/A * \li Return the size of the compressed name or -1.
2N/A * \li 'length' is the size of the array pointed to by 'comp_dn'.
2N/A */
2N/Aint
2N/Adn_comp(const char *src, u_char *dst, int dstsiz,
2N/A u_char **dnptrs, u_char **lastdnptr)
2N/A{
2N/A return (ns_name_compress(src, dst, (size_t)dstsiz,
2N/A (const u_char **)dnptrs,
2N/A (const u_char **)lastdnptr));
2N/A}
2N/A
2N/A
2N/A/*%
2N/A * Skip over a compressed domain name. Return the size or -1.
2N/A */
2N/Aint
2N/Adn_skipname(const u_char *ptr, const u_char *eom) {
2N/A const u_char *saveptr = ptr;
2N/A
2N/A if (ns_name_skip(&ptr, eom) == -1)
2N/A return (-1);
2N/A return (ptr - saveptr);
2N/A}
2N/A
2N/A/*%
2N/A * Verify that a domain name uses an acceptable character set.
2N/A *
2N/A * Note the conspicuous absence of ctype macros in these definitions. On
2N/A * non-ASCII hosts, we can't depend on string literals or ctype macros to
2N/A * tell us anything about network-format data. The rest of the BIND system
2N/A * is not careful about this, but for some reason, we're doing it right here.
2N/A */
2N/A#define PERIOD 0x2e
2N/A#define hyphenchar(c) ((c) == 0x2d)
2N/A#define bslashchar(c) ((c) == 0x5c)
2N/A#ifdef SUNW_HNOK_UNDERSCORE
2N/A#define underscorechar(c) ((c) == 0x5f)
2N/A#endif /* SUNW_HNOK_UNDERSCORE */
2N/A#define periodchar(c) ((c) == PERIOD)
2N/A#define asterchar(c) ((c) == 0x2a)
2N/A#define alphachar(c) (((c) >= 0x41 && (c) <= 0x5a) \
2N/A || ((c) >= 0x61 && (c) <= 0x7a))
2N/A#define digitchar(c) ((c) >= 0x30 && (c) <= 0x39)
2N/A
2N/A#define borderchar(c) (alphachar(c) || digitchar(c))
2N/A#ifdef SUNW_HNOK_UNDERSCORE
2N/A#define middlechar(c) (borderchar(c) || hyphenchar(c) || underscorechar(c))
2N/A#else
2N/A#define middlechar(c) (borderchar(c) || hyphenchar(c))
2N/A#endif /* SUNW_HNOK_UNDERSCORE */
2N/A#define domainchar(c) ((c) > 0x20 && (c) < 0x7f)
2N/A
2N/Aint
2N/Ares_hnok(const char *dn) {
2N/A int pch = PERIOD, ch = *dn++;
2N/A
2N/A while (ch != '\0') {
2N/A int nch = *dn++;
2N/A
2N/A if (periodchar(ch)) {
2N/A (void)NULL;
2N/A } else if (periodchar(pch)) {
2N/A if (!borderchar(ch))
2N/A return (0);
2N/A } else if (periodchar(nch) || nch == '\0') {
2N/A if (!borderchar(ch))
2N/A return (0);
2N/A } else {
2N/A if (!middlechar(ch))
2N/A return (0);
2N/A }
2N/A pch = ch, ch = nch;
2N/A }
2N/A return (1);
2N/A}
2N/A
2N/A/*%
2N/A * hostname-like (A, MX, WKS) owners can have "*" as their first label
2N/A * but must otherwise be as a host name.
2N/A */
2N/Aint
2N/Ares_ownok(const char *dn) {
2N/A if (asterchar(dn[0])) {
2N/A if (periodchar(dn[1]))
2N/A return (res_hnok(dn+2));
2N/A if (dn[1] == '\0')
2N/A return (1);
2N/A }
2N/A return (res_hnok(dn));
2N/A}
2N/A
2N/A/*%
2N/A * SOA RNAMEs and RP RNAMEs can have any printable character in their first
2N/A * label, but the rest of the name has to look like a host name.
2N/A */
2N/Aint
2N/Ares_mailok(const char *dn) {
2N/A int ch, escaped = 0;
2N/A
2N/A /* "." is a valid missing representation */
2N/A if (*dn == '\0')
2N/A return (1);
2N/A
2N/A /* otherwise <label>.<hostname> */
2N/A while ((ch = *dn++) != '\0') {
2N/A if (!domainchar(ch))
2N/A return (0);
2N/A if (!escaped && periodchar(ch))
2N/A break;
2N/A if (escaped)
2N/A escaped = 0;
2N/A else if (bslashchar(ch))
2N/A escaped = 1;
2N/A }
2N/A if (periodchar(ch))
2N/A return (res_hnok(dn));
2N/A return (0);
2N/A}
2N/A
2N/A/*%
2N/A * This function is quite liberal, since RFC1034's character sets are only
2N/A * recommendations.
2N/A */
2N/Aint
2N/Ares_dnok(const char *dn) {
2N/A int ch;
2N/A
2N/A while ((ch = *dn++) != '\0')
2N/A if (!domainchar(ch))
2N/A return (0);
2N/A return (1);
2N/A}
2N/A
2N/A#ifdef BIND_4_COMPAT
2N/A/*%
2N/A * This module must export the following externally-visible symbols:
2N/A * ___putlong
2N/A * ___putshort
2N/A * __getlong
2N/A * __getshort
2N/A * Note that one _ comes from C and the others come from us.
2N/A */
2N/A
2N/A#ifdef SOLARIS2
2N/A#ifdef __putlong
2N/A#undef __putlong
2N/A#endif
2N/A#ifdef __putshort
2N/A#undef __putshort
2N/A#endif
2N/A#pragma weak putlong = __putlong
2N/A#pragma weak putshort = __putshort
2N/A#endif /* SOLARIS2 */
2N/A
2N/Avoid __putlong(u_int32_t src, u_char *dst) { ns_put32(src, dst); }
2N/Avoid __putshort(u_int16_t src, u_char *dst) { ns_put16(src, dst); }
2N/A#ifndef __ultrix__
2N/Au_int32_t _getlong(const u_char *src) { return (ns_get32(src)); }
2N/Au_int16_t _getshort(const u_char *src) { return (ns_get16(src)); }
2N/A#endif /*__ultrix__*/
2N/A#endif /*BIND_4_COMPAT*/
2N/A
2N/A/*! \file */