From df21c8581af14b07680c17eefc7479eac510c60f Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Wed, 14 Aug 1996 21:45:21 +0000 Subject: Update. Wed Aug 14 21:36:16 1996 Ulrich Drepper * stdlib/strtod.c (STRTOD): Correct assertion about size of wint_t and wchar_t. Reported by David Mosberger-Tang. Mon Aug 12 22:40:16 1996 Andreas Schwab * elf/dl-lookup.c (_dl_lookup_symbol): Remove fifth parameter RELOC_ADDR and make NOPLT a set of flags. All callers changed. Delete condition that checks for resolving to the location being filled in. Add condition to skip the executable's symbols if requested. * elf/link.h: Change declaration of _dl_lookup_symbol accordingly. (DL_LOOKUP_NOEXEC, DL_LOOKUP_NOPLT): New definitions. * elf/dl-reloc.c (RESOLVE): Remove second parameter and rename NOPLT to FLAGS. * elf/dl-runtime.c (RESOLVE): Likewise. * elf/rtld.c (RESOLVE): Likewise. * sysdeps/m68k/dl-machine.h (elf_machine_rela): Pass DL_LOOKUP_NOEXEC as second argument to the RESOLVE macro if processing a copy reloc, DL_LOOKUP_NOPLT for a jump slot reloc, zero otherwise. * sysdeps/alpha/dl-machine.h (elf_machine_rela): Likewise. * sysdeps/i386/dl-machine.h (elf_machine_rel): Likewise. * sysdeps/mips/dl-machine.h (elf_machine_rel): Likewise. Wed Aug 14 17:57:08 1996 Ulrich Drepper * MakeTAGS: Clean up use of --omit-header and -n for xgettext. * po/header.pot: Add empty line at end. Sun Aug 11 13:45:33 1996 Andreas Schwab * MakeTAGS (all-pot): Remove $P/errlist.pot, all error messages are now in $P/stdio-common.pot. (XGETTEXTFLAGS-errlist.pot): Variable removed. Mon Aug 12 19:25:03 1996 Andreas Schwab * Makerules (do-ar, o-iterator-doit): Compute path to autolock script at run time, not configure time. * config.make.in, configure.in: Undo previous change. Wed Aug 14 13:20:02 1996 Ulrich Drepper * sysdeps/unix/sysv/linux/i386/close.S: Push return value of thread on stack as argument for `_exit'. Reported by Andreas Schwab. Mon Aug 12 19:36:25 1996 Andreas Schwab * sysdeps/unix/sysv/linux/m68k/clone.S: New file. Wed Aug 14 04:22:35 1996 Richard Henderson * elf/dl-load.c (_dl_map_object): Save name in malloced memory. (_dl_map_object_from_fd): Free name on error. Wed Aug 14 13:00:09 1996 Ulrich Drepper * string/strdup.c: Use result of memcpy to avoid reloading. Tue Aug 13 00:55:03 1996 Andreas Schwab * shadow/sgetspent_r.c (__sgetspent_r): Copy string to buffer, not the other way round. * resolv/Makefile (libresolv-routines): Add base64, inet_net_ntop, inet_net_pton, inet_net. * resolv/arpa/nameser.h (__BIND): Update version number. Mon Aug 12 19:03:22 1996 Thomas Bushnell n/BSG * sysdeps/generic/gnu/types.h: Declare __fd_mask as `unsigned long'. * mach/Makefile (mach/mach_host.uh): Depend on $(objpfx)/mach-syscalls.mk. ($(objpfx)mach-shortcuts.h): Depend on $(objpfx)mach/mach_host.h. (This fixes a make loop; thanks to Marcus Daniels for the patch.) --- ChangeLog | 84 +++++++++- INSTALL | 2 +- Makerules | 3 +- configure | 17 +- inet/arpa/inet.h | 11 +- io/getwd.c | 23 ++- manual/maint.texi | 2 +- nss/nss_dns/dns-host.c | 39 +++-- nss/nsswitch.c | 12 +- resolv/Makefile | 3 +- resolv/arpa/nameser.h | 105 ++++++++++--- resolv/base64.c | 321 +++++++++++++++++++++++++++++++++++++ resolv/gethnamaddr.c | 7 +- resolv/getnetnamadr.c | 1 + resolv/herror.c | 1 + resolv/inet_addr.c | 1 + resolv/inet_net_ntop.c | 139 ++++++++++++++++ resolv/inet_net_pton.c | 201 ++++++++++++++++++++++++ resolv/inet_neta.c | 82 ++++++++++ resolv/inet_ntop.c | 6 +- resolv/inet_pton.c | 9 +- resolv/nsap_addr.c | 18 +++ resolv/res_comp.c | 48 ++---- resolv/res_data.c | 9 +- resolv/res_debug.c | 419 ++++++++++++++++++++++++++++++++++++++++--------- resolv/res_init.c | 1 + resolv/res_mkquery.c | 9 +- resolv/res_query.c | 9 +- resolv/res_send.c | 9 +- resolv/resolv.h | 27 +++- stdlib/canonicalize.c | 6 +- stdlib/strtod.c | 2 + 32 files changed, 1431 insertions(+), 195 deletions(-) create mode 100644 resolv/base64.c create mode 100644 resolv/inet_net_ntop.c create mode 100644 resolv/inet_net_pton.c create mode 100644 resolv/inet_neta.c diff --git a/ChangeLog b/ChangeLog index a4b7271730..5159d8ca85 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,70 @@ +Wed Aug 14 21:36:16 1996 Ulrich Drepper + + * stdlib/strtod.c (STRTOD): Correct assertion about size of + wint_t and wchar_t. Reported by David Mosberger-Tang. + +Mon Aug 12 22:40:16 1996 Andreas Schwab + + * elf/dl-lookup.c (_dl_lookup_symbol): Remove fifth parameter + RELOC_ADDR and make NOPLT a set of flags. All callers + changed. Delete condition that checks for resolving to the + location being filled in. Add condition to skip the + executable's symbols if requested. + * elf/link.h: Change declaration of _dl_lookup_symbol + accordingly. + (DL_LOOKUP_NOEXEC, DL_LOOKUP_NOPLT): New definitions. + * elf/dl-reloc.c (RESOLVE): Remove second parameter and rename + NOPLT to FLAGS. + * elf/dl-runtime.c (RESOLVE): Likewise. + * elf/rtld.c (RESOLVE): Likewise. + * sysdeps/m68k/dl-machine.h (elf_machine_rela): Pass + DL_LOOKUP_NOEXEC as second argument to the RESOLVE macro if + processing a copy reloc, DL_LOOKUP_NOPLT for a jump slot + reloc, zero otherwise. + * sysdeps/alpha/dl-machine.h (elf_machine_rela): Likewise. + * sysdeps/i386/dl-machine.h (elf_machine_rel): Likewise. + * sysdeps/mips/dl-machine.h (elf_machine_rel): Likewise. + +Wed Aug 14 17:57:08 1996 Ulrich Drepper + + * MakeTAGS: Clean up use of --omit-header and -n for xgettext. + * po/header.pot: Add empty line at end. + +Sun Aug 11 13:45:33 1996 Andreas Schwab + + * MakeTAGS (all-pot): Remove $P/errlist.pot, all error messages + are now in $P/stdio-common.pot. + (XGETTEXTFLAGS-errlist.pot): Variable removed. + +Mon Aug 12 19:25:03 1996 Andreas Schwab + + * Makerules (do-ar, o-iterator-doit): Compute path to autolock + script at run time, not configure time. + * config.make.in, configure.in: Undo previous change. + +Wed Aug 14 13:20:02 1996 Ulrich Drepper + + * sysdeps/unix/sysv/linux/i386/close.S: Push return value of thread + on stack as argument for `_exit'. Reported by Andreas Schwab. + +Mon Aug 12 19:36:25 1996 Andreas Schwab + + * sysdeps/unix/sysv/linux/m68k/clone.S: New file. + +Wed Aug 14 04:22:35 1996 Richard Henderson + + * elf/dl-load.c (_dl_map_object): Save name in malloced memory. + (_dl_map_object_from_fd): Free name on error. + +Wed Aug 14 13:00:09 1996 Ulrich Drepper + + * string/strdup.c: Use result of memcpy to avoid reloading. + +Tue Aug 13 00:55:03 1996 Andreas Schwab + + * shadow/sgetspent_r.c (__sgetspent_r): Copy string to buffer, not + the other way round. + Tue Aug 13 20:51:21 1996 Ulrich Drepper * stdlib/canonicalize.c (canonicalize): Add cast to prevent @@ -11,9 +78,8 @@ Tue Aug 13 18:26:45 1996 Ulrich Drepper sorted. Update from bind-4.9.5-T1A. - * resolv/Makefile (routines): Add inet_net_ntop, inet_net_pton, - inet_net. - (libresolv-routines): Add base64. + * resolv/Makefile (libresolv-routines): Add base64, inet_net_ntop, + inet_net_pton, inet_net. * resolv/gethnamaddr.c: Include . * resolv/getnetnamadr.c: Likewise. @@ -58,7 +124,7 @@ Tue Aug 13 18:26:45 1996 Ulrich Drepper Declare sym_ntos, sym_ntop, b64_ntop, b64_pton, __p_fqnname, __p_secstodate, dn_count_labels. - * resolv/arpa/nameser.h (__BIND): Update verison number. + * resolv/arpa/nameser.h (__BIND): Update version number. Add KEYFLAG_* and ALGORITHM_* symbols. (HEADER): Add `ad' and `cd' flags. @@ -68,6 +134,16 @@ Tue Aug 13 18:26:45 1996 Ulrich Drepper * manual/maint.texi: Document that we use bind-4.9.5. * INSTALL: Ditto. +Mon Aug 12 19:03:22 1996 Thomas Bushnell n/BSG + + * sysdeps/generic/gnu/types.h: Declare __fd_mask as `unsigned long'. + + * mach/Makefile (mach/mach_host.uh): Depend on + $(objpfx)/mach-syscalls.mk. + ($(objpfx)mach-shortcuts.h): Depend on $(objpfx)mach/mach_host.h. + (This fixes a make loop; thanks to Marcus Daniels + for the patch.) + Mon Aug 12 16:41:52 1996 Thomas Bushnell n/BSG * io/getwd.c (getwd) [! PATH_MAX]: Don't assume that the user's diff --git a/INSTALL b/INSTALL index 581f3925f7..6664aadc6d 100644 --- a/INSTALL +++ b/INSTALL @@ -824,7 +824,7 @@ parts of the library were contributed or worked on by other people. changes to fit into the GNU C library and to fit the ANSI C standard, but the functional code is Berkeley's. - * The Internet resolver code is taken directly from BIND 4.9.4, + * The Internet resolver code is taken directly from BIND 4.9.5, which is under both the Berkeley copyright above and also: Portions Copyright (C) 1993 by Digital Equipment Corporation. diff --git a/Makerules b/Makerules index 4248dad91c..14f5b5b54b 100644 --- a/Makerules +++ b/Makerules @@ -474,7 +474,8 @@ define o-iterator-doit $(common-objpfx)$(patsubst %,$(libtype$o),c)($(ar-symtab-name)): \ $(common-objpfx)$(patsubst %,$(libtype$o),c)(\ $(patsubst $(objpfx)%,%,$(o-objects))) $(subdirs-stamp-o); \ - $$(RANLIB) $$(common-objpfx)$$(patsubst %,$$(libtype$o),c) + $(AUTOLOCK) $$(common-objpfx)$$(patsubst %,$$(libtype$o),c).lck \ + $$(RANLIB) $$(common-objpfx)$$(patsubst %,$$(libtype$o),c) endef ifndef subdir subdirs-stamps := $(foreach d,$(subdirs),\ diff --git a/configure b/configure index 233286832b..1882a6c6ca 100755 --- a/configure +++ b/configure @@ -1273,8 +1273,6 @@ else fi fi -AUTOLOCK="`(cd $srcdir; pwd)`/autolock.sh" - echo $ac_n "checking for signed size_t type""... $ac_c" 1>&6 if eval "test \"`echo '$''{'libc_cv_signed_size_t'+set}'`\" = set"; then @@ -1304,7 +1302,7 @@ if eval "test \"`echo '$''{'libc_cv_friendly_stddef'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1322: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* libc_cv_friendly_stddef=yes else @@ -1427,7 +1425,7 @@ if eval "test \"`echo '$''{'libc_cv_have_initfini'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1439: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* libc_cv_have_initfini=yes else @@ -1465,7 +1463,7 @@ if eval "test \"`echo '$''{'libc_cv_asm_underscores'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; }; then +if { (eval echo configure:1475: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }; then rm -rf conftest* libc_cv_asm_underscores=yes else @@ -1565,7 +1563,7 @@ _start () {} EOF if { ac_try='${CC-cc} $CFLAGS -nostdlib -nostartfiles -Wl,--no-whole-archive - -o conftest conftest.c'; { (eval echo configure:1569: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then + -o conftest conftest.c'; { (eval echo configure:1567: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then libc_cv_ld_no_whole_archive=yes else libc_cv_ld_no_whole_archive=no @@ -1839,7 +1837,6 @@ s%@BUILD_CC@%$BUILD_CC%g s%@CPP@%$CPP%g s%@AR@%$AR%g s%@RANLIB@%$RANLIB%g -s%@AUTOLOCK@%$AUTOLOCK%g s%@libc_cv_have_initfini@%$libc_cv_have_initfini%g s%@libc_cv_ld_no_whole_archive@%$libc_cv_ld_no_whole_archive%g s%@uname_sysname@%$uname_sysname%g diff --git a/inet/arpa/inet.h b/inet/arpa/inet.h index b0a91312d3..561994372f 100644 --- a/inet/arpa/inet.h +++ b/inet/arpa/inet.h @@ -46,13 +46,16 @@ u_long inet_addr __P((const char *)); int inet_aton __P((const char *, struct in_addr *)); u_int32_t inet_lnaof __P((struct in_addr)); struct in_addr inet_makeaddr __P((u_int32_t , u_int32_t)); +char * inet_neta __P((u_long, char *, size_t)); u_int32_t inet_netof __P((struct in_addr)); u_int32_t inet_network __P((const char *)); +char *inet_net_ntop __P((int, const void *, int, char *, size_t)); +int inet_net_pton __P((int, const char *, void *, size_t)); char *inet_ntoa __P((struct in_addr)); -int inet_pton __P((int af, const char *src, void *dst)); -const char *inet_ntop __P((int af, const void *src, char *dst, size_t s)); -u_int inet_nsap_addr __P((const char *, u_char *, int maxlen)); -char *inet_nsap_ntoa __P((int, const u_char *, char *ascii)); +int inet_pton __P((int, const char *, void *)); +const char *inet_ntop __P((int, const void *, char *, size_t)); +u_int inet_nsap_addr __P((const char *, u_char *, int)); +char *inet_nsap_ntoa __P((int, const u_char *, char *)); __END_DECLS #endif /* !_INET_H_ */ diff --git a/io/getwd.c b/io/getwd.c index fdda1cac22..8a8d01a28e 100644 --- a/io/getwd.c +++ b/io/getwd.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 1992 Free Software Foundation, Inc. +/* Copyright (C) 1991, 1992, 1996 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -16,7 +16,6 @@ License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include #include #include #include @@ -26,22 +25,30 @@ Cambridge, MA 02139, USA. */ If successful, return BUF. If not, put an error message in BUF and return NULL. BUF should be at least PATH_MAX bytes long. */ char * -DEFUN(getwd, (buf), char *buf) +getwd (buf) + char *buf; { +#ifndef PATH_MAX +#define PATH_MAX 1024 + char fetchbuf[PATH_MAX]; +#else +#define fetchbuf buf +#endif + if (buf == NULL) { errno = EINVAL; return NULL; } -#ifndef PATH_MAX -#define PATH_MAX 1024 /* Arbitrary; this function is unreliable. */ -#endif - if (getcwd (buf, PATH_MAX) == NULL) + if (getcwd (fetchbuf, PATH_MAX) == NULL) { - (void) strncpy (buf, strerror (errno), PATH_MAX); + strncpy (buf, strerror (errno), PATH_MAX); return NULL; } + if (fetchbuf != buf) + strcpy (buf, fetchbuf); + return buf; } diff --git a/manual/maint.texi b/manual/maint.texi index cd6c996719..975de537ae 100644 --- a/manual/maint.texi +++ b/manual/maint.texi @@ -967,7 +967,7 @@ changes to fit into the GNU C library and to fit the ANSI C standard, but the functional code is Berkeley's.@refill @item -The Internet resolver code is taken directly from BIND 4.9.4, which is +The Internet resolver code is taken directly from BIND 4.9.5, which is under both the Berkeley copyright above and also: @quotation diff --git a/nss/nss_dns/dns-host.c b/nss/nss_dns/dns-host.c index eaa9e81218..f8116fed34 100644 --- a/nss/nss_dns/dns-host.c +++ b/nss/nss_dns/dns-host.c @@ -17,19 +17,14 @@ License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* Parts of this file are plain copies of the file `getnetnamadr.c' from +/* Parts of this file are plain copies of the file `gethtnamadr.c' from the bind package and it has the following copyright. */ -/* Copyright (c) 1993 Carlos Leandro and Rui Salgueiro - * Dep. Matematica Universidade de Coimbra, Portugal, Europe - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - */ /* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. + * ++Copyright++ 1985, 1988, 1993 + * - + * Copyright (c) 1985, 1988, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -41,8 +36,8 @@ Boston, MA 02111-1307, USA. */ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. + * This product includes software developed by the University of + * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -58,6 +53,26 @@ Boston, MA 02111-1307, USA. */ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * - + * Portions Copyright (c) 1993 by Digital Equipment Corporation. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies, and that + * the name of Digital Equipment Corporation not be used in advertising or + * publicity pertaining to distribution of the document or software without + * specific, written prior permission. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT + * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * - + * --Copyright-- */ #include diff --git a/nss/nsswitch.c b/nss/nsswitch.c index 69b1be5e08..099f405c6e 100644 --- a/nss/nsswitch.c +++ b/nss/nsswitch.c @@ -189,8 +189,16 @@ __nss_configure_lookup (const char *dbname, const char *service_line) size_t cnt; for (cnt = 0; cnt < sizeof databases; ++cnt) - if (strcmp (dbname, databases[cnt].name) == 0) - break; + { + int cmp = strcmp (dbname, databases[cnt].name); + if (cmp == 0) + break; + if (cmp > 0) + { + errno = EINVAL; + return -1; + } + } if (cnt == sizeof databases) { diff --git a/resolv/Makefile b/resolv/Makefile index a09f87db60..51257a5917 100644 --- a/resolv/Makefile +++ b/resolv/Makefile @@ -28,7 +28,8 @@ routines := herror inet_addr inet_ntop inet_pton nsap_addr res_init extra-libs := libresolv libresolv-routines := gethnamaddr res_comp res_debug res_data res_mkquery \ - res_query res_send + res_query res_send inet_net_ntop inet_net_pton \ + inet_neta base64 include ../Rules diff --git a/resolv/arpa/nameser.h b/resolv/arpa/nameser.h index 0fb04a1a02..f2b251bfbf 100644 --- a/resolv/arpa/nameser.h +++ b/resolv/arpa/nameser.h @@ -50,6 +50,28 @@ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS * SOFTWARE. * - + * Portions Copyright (c) 1995 by International Business Machines, Inc. + * + * International Business Machines, Inc. (hereinafter called IBM) grants + * permission under its copyrights to use, copy, modify, and distribute this + * Software with or without fee, provided that the above copyright notice and + * all paragraphs of this notice appear in all copies, and that the name of IBM + * not be used in connection with the marketing of any product incorporating + * the Software or modifications thereof, without specific, written prior + * permission. + * + * To the extent it has a right to do so, IBM grants an immunity from suit + * under its patents, if any, for the use, sale or manufacture of products to + * the extent that such products are used for performing Domain Name System + * dynamic updates in TCP/IP networks by means of the Software. No immunity is + * granted for any product per se or for any other function of any product. + * + * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, + * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN + * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES. * --Copyright-- */ @@ -83,7 +105,7 @@ * is new enough to contain a certain feature. */ -#define __BIND 19950621 /* interface version stamp */ +#define __BIND 19960801 /* interface version stamp */ /* * Define constants based on rfc883 @@ -92,12 +114,12 @@ #define MAXDNAME 256 /* maximum domain name */ #define MAXCDNAME 255 /* maximum compressed domain name */ #define MAXLABEL 63 /* maximum length of domain label */ -#define HFIXEDSZ 12 /* #/bytes of fixed data in header */ +#define HFIXEDSZ 12 /* #/bytes of fixed data in header */ #define QFIXEDSZ 4 /* #/bytes of fixed data in query */ #define RRFIXEDSZ 10 /* #/bytes of fixed data in r record */ -#define INT32SZ 4 /* for systems without 32-bit ints */ -#define INT16SZ 2 /* for systems without 16-bit ints */ -#define INADDRSZ 4 /* IPv4 T_A */ +#define INT32SZ 4 /* for systems without 32-bit ints */ +#define INT16SZ 2 /* for systems without 16-bit ints */ +#define INADDRSZ 4 /* IPv4 T_A */ #define IN6ADDRSZ 16 /* IPv6 T_AAAA */ /* @@ -112,7 +134,7 @@ #define IQUERY 0x1 /* inverse query */ #define STATUS 0x2 /* nameserver status query */ /*#define xxx 0x3*/ /* 0x3 reserved */ -#define NS_NOTIFY_OP 0x4 /* notify secondary of SOA change */ +#define NS_NOTIFY_OP 0x4 /* notify secondary of SOA change */ #ifdef ALLOW_UPDATES /* non standard - supports ALLOW_UPDATES stuff from Mike Schwartz */ # define UPDATEA 0x9 /* add resource record */ @@ -157,19 +179,20 @@ #define T_MINFO 14 /* mailbox information */ #define T_MX 15 /* mail routing information */ #define T_TXT 16 /* text strings */ -#define T_RP 17 /* responsible person */ +#define T_RP 17 /* responsible person */ #define T_AFSDB 18 /* AFS cell database */ #define T_X25 19 /* X_25 calling address */ #define T_ISDN 20 /* ISDN calling address */ #define T_RT 21 /* router */ #define T_NSAP 22 /* NSAP address */ #define T_NSAP_PTR 23 /* reverse NSAP lookup (deprecated) */ -#define T_SIG 24 /* security signature */ -#define T_KEY 25 /* security key */ -#define T_PX 26 /* X.400 mail mapping */ -#define T_GPOS 27 /* geographical position (withdrawn) */ -#define T_AAAA 28 /* IP6 Address */ -#define T_LOC 29 /* Location Information */ +#define T_SIG 24 /* security signature */ +#define T_KEY 25 /* security key */ +#define T_PX 26 /* X.400 mail mapping */ +#define T_GPOS 27 /* geographical position (withdrawn) */ +#define T_AAAA 28 /* IP6 Address */ +#define T_LOC 29 /* Location Information */ +#define T_NXT 30 /* Next Valid Name in Zone */ /* non standard */ #define T_UINFO 100 /* user (finger) information */ #define T_UID 101 /* user ID */ @@ -191,6 +214,48 @@ /* Query class values which do not appear in resource records */ #define C_ANY 255 /* wildcard match */ +/* + * Flags field of the KEY RR rdata + */ +#define KEYFLAG_TYPEMASK 0xC000 /* Mask for "type" bits */ +#define KEYFLAG_TYPE_AUTH_CONF 0x0000 /* Key usable for both */ +#define KEYFLAG_TYPE_CONF_ONLY 0x8000 /* Key usable for confidentiality */ +#define KEYFLAG_TYPE_AUTH_ONLY 0x4000 /* Key usable for authentication */ +#define KEYFLAG_TYPE_NO_KEY 0xC000 /* No key usable for either; no key */ +/* The type bits can also be interpreted independently, as single bits: */ +#define KEYFLAG_NO_AUTH 0x8000 /* Key not usable for authentication */ +#define KEYFLAG_NO_CONF 0x4000 /* Key not usable for confidentiality */ + +#define KEYFLAG_EXPERIMENTAL 0x2000 /* Security is *mandatory* if bit=0 */ +#define KEYFLAG_RESERVED3 0x1000 /* reserved - must be zero */ +#define KEYFLAG_RESERVED4 0x0800 /* reserved - must be zero */ +#define KEYFLAG_USERACCOUNT 0x0400 /* key is assoc. with a user acct */ +#define KEYFLAG_ENTITY 0x0200 /* key is assoc. with entity eg host */ +#define KEYFLAG_ZONEKEY 0x0100 /* key is zone key for the zone named */ +#define KEYFLAG_IPSEC 0x0080 /* key is for IPSEC use (host or user)*/ +#define KEYFLAG_EMAIL 0x0040 /* key is for email (MIME security) */ +#define KEYFLAG_RESERVED10 0x0020 /* reserved - must be zero */ +#define KEYFLAG_RESERVED11 0x0010 /* reserved - must be zero */ +#define KEYFLAG_SIGNATORYMASK 0x000F /* key can sign DNS RR's of same name */ + +#define KEYFLAG_RESERVED_BITMASK ( KEYFLAG_RESERVED3 | \ + KEYFLAG_RESERVED4 | \ + KEYFLAG_RESERVED10| KEYFLAG_RESERVED11) + +/* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */ +#define ALGORITHM_MD5RSA 1 /* MD5 with RSA */ +#define ALGORITHM_EXPIRE_ONLY 253 /* No alg, no security */ +#define ALGORITHM_PRIVATE_OID 254 /* Key begins with OID indicating alg */ + +/* Signatures */ + /* Size of a mod or exp in bits */ +#define MIN_MD5RSA_KEY_PART_BITS 512 +#define MAX_MD5RSA_KEY_PART_BITS 2552 + /* Total of binary mod and exp, bytes */ +#define MAX_MD5RSA_KEY_BYTES ((MAX_MD5RSA_KEY_PART_BITS+7/8)*2+3) + /* Max length of text sig block */ +#define MAX_KEY_BASE64 (((MAX_MD5RSA_KEY_BYTES+2)/3)*4) + /* * Status return codes for T_UNSPEC conversion routines */ @@ -207,9 +272,9 @@ #ifdef linux # include #else -#define LITTLE_ENDIAN 1234 /* least-significant byte first (vax, pc) */ -#define BIG_ENDIAN 4321 /* most-significant byte first (IBM, net) */ -#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp)*/ +#define LITTLE_ENDIAN 1234 /* least-significant byte first (vax, pc) */ +#define BIG_ENDIAN 4321 /* most-significant byte first (IBM, net) */ +#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp)*/ #if defined(vax) || defined(ns32000) || defined(sun386) || defined(i386) || \ defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \ @@ -259,7 +324,9 @@ typedef struct { unsigned rd: 1; /* recursion desired */ /* fields in fourth byte */ unsigned ra: 1; /* recursion available */ - unsigned unused :3; /* unused bits (MBZ as of 4.9.3a3) */ + unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */ + unsigned ad: 1; /* authentic data from named */ + unsigned cd: 1; /* checking disabled by resolver */ unsigned rcode :4; /* response code */ #endif #if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN @@ -271,7 +338,9 @@ typedef struct { unsigned qr :1; /* response flag */ /* fields in fourth byte */ unsigned rcode :4; /* response code */ - unsigned unused :3; /* unused bits (MBZ as of 4.9.3a3) */ + unsigned cd: 1; /* checking disabled by resolver */ + unsigned ad: 1; /* authentic data from named */ + unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */ unsigned ra :1; /* recursion available */ #endif /* remaining bytes */ diff --git a/resolv/base64.c b/resolv/base64.c new file mode 100644 index 0000000000..98983e0a93 --- /dev/null +++ b/resolv/base64.c @@ -0,0 +1,321 @@ +/* + * Copyright (c) 1996 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +/* + * Portions Copyright (c) 1995 by International Business Machines, Inc. + * + * International Business Machines, Inc. (hereinafter called IBM) grants + * permission under its copyrights to use, copy, modify, and distribute this + * Software with or without fee, provided that the above copyright notice and + * all paragraphs of this notice appear in all copies, and that the name of IBM + * not be used in connection with the marketing of any product incorporating + * the Software or modifications thereof, without specific, written prior + * permission. + * + * To the extent it has a right to do so, IBM grants an immunity from suit + * under its patents, if any, for the use, sale or manufacture of products to + * the extent that such products are used for performing Domain Name System + * dynamic updates in TCP/IP networks by means of the Software. No immunity is + * granted for any product per se or for any other function of any product. + * + * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, + * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN + * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#if defined(BSD) && (BSD >= 199103) && defined(AF_INET6) +# include +# include +#else +# include "../conf/portability.h" +#endif + +#define Assert(Cond) if (!(Cond)) abort() + +static const char Base64[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +static const char Pad64 = '='; + +/* (From RFC1521 and draft-ietf-dnssec-secext-03.txt) + The following encoding technique is taken from RFC 1521 by Borenstein + and Freed. It is reproduced here in a slightly edited form for + convenience. + + A 65-character subset of US-ASCII is used, enabling 6 bits to be + represented per printable character. (The extra 65th character, "=", + is used to signify a special processing function.) + + The encoding process represents 24-bit groups of input bits as output + strings of 4 encoded characters. Proceeding from left to right, a + 24-bit input group is formed by concatenating 3 8-bit input groups. + These 24 bits are then treated as 4 concatenated 6-bit groups, each + of which is translated into a single digit in the base64 alphabet. + + Each 6-bit group is used as an index into an array of 64 printable + characters. The character referenced by the index is placed in the + output string. + + Table 1: The Base64 Alphabet + + Value Encoding Value Encoding Value Encoding Value Encoding + 0 A 17 R 34 i 51 z + 1 B 18 S 35 j 52 0 + 2 C 19 T 36 k 53 1 + 3 D 20 U 37 l 54 2 + 4 E 21 V 38 m 55 3 + 5 F 22 W 39 n 56 4 + 6 G 23 X 40 o 57 5 + 7 H 24 Y 41 p 58 6 + 8 I 25 Z 42 q 59 7 + 9 J 26 a 43 r 60 8 + 10 K 27 b 44 s 61 9 + 11 L 28 c 45 t 62 + + 12 M 29 d 46 u 63 / + 13 N 30 e 47 v + 14 O 31 f 48 w (pad) = + 15 P 32 g 49 x + 16 Q 33 h 50 y + + Special processing is performed if fewer than 24 bits are available + at the end of the data being encoded. A full encoding quantum is + always completed at the end of a quantity. When fewer than 24 input + bits are available in an input group, zero bits are added (on the + right) to form an integral number of 6-bit groups. Padding at the + end of the data is performed using the '=' character. + + Since all base64 input is an integral number of octets, only the + ------------------------------------------------- + following cases can arise: + + (1) the final quantum of encoding input is an integral + multiple of 24 bits; here, the final unit of encoded + output will be an integral multiple of 4 characters + with no "=" padding, + (2) the final quantum of encoding input is exactly 8 bits; + here, the final unit of encoded output will be two + characters followed by two "=" padding characters, or + (3) the final quantum of encoding input is exactly 16 bits; + here, the final unit of encoded output will be three + characters followed by one "=" padding character. + */ + +ssize_t +b64_ntop(src, srclength, target, targsize) + u_char const *src; + size_t srclength; + char *target; + size_t targsize; +{ + size_t datalength = 0; + u_char input[3]; + u_char output[4]; + int i; + + while (2 < srclength) { + input[0] = *src++; + input[1] = *src++; + input[2] = *src++; + srclength -= 3; + + output[0] = input[0] >> 2; + output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); + output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); + output[3] = input[2] & 0x3f; + Assert(output[0] < 64); + Assert(output[1] < 64); + Assert(output[2] < 64); + Assert(output[3] < 64); + + if (datalength + 4 > targsize) + return (-1); + target[datalength++] = Base64[output[0]]; + target[datalength++] = Base64[output[1]]; + target[datalength++] = Base64[output[2]]; + target[datalength++] = Base64[output[3]]; + } + + /* Now we worry about padding. */ + if (0 != srclength) { + /* Get what's left. */ + input[0] = input[1] = input[2] = '\0'; + for (i = 0; i < srclength; i++) + input[i] = *src++; + + output[0] = input[0] >> 2; + output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); + output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); + Assert(output[0] < 64); + Assert(output[1] < 64); + Assert(output[2] < 64); + + if (datalength + 4 > targsize) + return (-1); + target[datalength++] = Base64[output[0]]; + target[datalength++] = Base64[output[1]]; + if (srclength == 1) + target[datalength++] = Pad64; + else + target[datalength++] = Base64[output[2]]; + target[datalength++] = Pad64; + } + if (datalength >= targsize) + return (-1); + target[datalength] = '\0'; /* Returned value doesn't count \0. */ + return (datalength); +} + +/* skips all whitespace anywhere. + converts characters, four at a time, starting at (or after) + src from base - 64 numbers into three 8 bit bytes in the target area. + it returns the number of data bytes stored at the target, or -1 on error. + */ + +ssize_t +b64_pton(src, target, targsize) + char const *src; + u_char *target; + size_t targsize; +{ + int tarindex, state, ch; + char *pos; + + state = 0; + tarindex = 0; + + while ((ch = *src++) != '\0') { + if (isspace(ch)) /* Skip whitespace anywhere. */ + continue; + + if (ch == Pad64) + break; + + pos = strchr(Base64, ch); + if (pos == 0) /* A non-base64 character. */ + return (-1); + + switch (state) { + case 0: + if (target) { + if (tarindex >= targsize) + return (-1); + target[tarindex] = (pos - Base64) << 2; + } + state = 1; + break; + case 1: + if (target) { + if (tarindex + 1 >= targsize) + return (-1); + target[tarindex] |= (pos - Base64) >> 4; + target[tarindex+1] = ((pos - Base64) & 0x0f) + << 4 ; + } + tarindex++; + state = 2; + break; + case 2: + if (target) { + if (tarindex + 1 >= targsize) + return (-1); + target[tarindex] |= (pos - Base64) >> 2; + target[tarindex+1] = ((pos - Base64) & 0x03) + << 6; + } + tarindex++; + state = 3; + break; + case 3: + if (target) { + if (tarindex >= targsize) + return (-1); + target[tarindex] |= (pos - Base64); + } + tarindex++; + state = 0; + break; + default: + abort(); + } + } + + /* + * We are done decoding Base-64 chars. Let's see if we ended + * on a byte boundary, and/or with erroneous trailing characters. + */ + + if (ch == Pad64) { /* We got a pad char. */ + ch = *src++; /* Skip it, get next. */ + switch (state) { + case 0: /* Invalid = in first position */ + case 1: /* Invalid = in second position */ + return (-1); + + case 2: /* Valid, means one byte of info */ + /* Skip any number of spaces. */ + for (NULL; ch != '\0'; ch = *src++) + if (!isspace(ch)) + break; + /* Make sure there is another trailing = sign. */ + if (ch != Pad64) + return (-1); + ch = *src++; /* Skip the = */ + /* Fall through to "single trailing =" case. */ + /* FALLTHROUGH */ + + case 3: /* Valid, means two bytes of info */ + /* + * We know this char is an =. Is there anything but + * whitespace after it? + */ + for (NULL; ch != '\0'; ch = *src++) + if (!isspace(ch)) + return (-1); + + /* + * Now make sure for cases 2 and 3 that the "extra" + * bits that slopped past the last full byte were + * zeros. If we don't check them, they become a + * subliminal channel. + */ + if (target && target[tarindex] != 0) + return (-1); + } + } else { + /* + * We ended by seeing the end of the string. Make sure we + * have no partial bytes lying around. + */ + if (state != 0) + return (-1); + } + + return (tarindex); +} diff --git a/resolv/gethnamaddr.c b/resolv/gethnamaddr.c index d3c45d0446..755fc52ea8 100644 --- a/resolv/gethnamaddr.c +++ b/resolv/gethnamaddr.c @@ -58,6 +58,7 @@ static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93"; static char rcsid[] = "$Id$"; #endif /* LIBC_SCCS and not lint */ +#include #include #include #include @@ -78,10 +79,12 @@ static char rcsid[] = "$Id$"; #define MULTI_PTRS_ARE_ALIASES 1 /* XXX - experimental */ #if defined(BSD) && (BSD >= 199103) && defined(AF_INET6) +# include # include #else # include "../conf/portability.h" #endif + #if defined(USE_OPTIONS_H) # include <../conf/options.h> #endif @@ -89,7 +92,7 @@ static char rcsid[] = "$Id$"; #ifdef SPRINTF_CHAR # define SPRINTF(x) strlen(sprintf/**/x) #else -# define SPRINTF(x) sprintf x +# define SPRINTF(x) ((size_t)sprintf x) #endif #define MAXALIASES 35 @@ -99,7 +102,6 @@ static const char AskedForGot[] = "gethostby*.getanswer: asked for \"%s\", got \"%s\""; static char *h_addr_ptrs[MAXADDRS + 1]; -static struct hostent *gethostbyname_ipv4 __P((const char *)); static struct hostent host; static char *host_aliases[MAXALIASES]; @@ -369,6 +371,7 @@ getanswer(answer, anslen, qname, qtype) } bcopy(cp, *hap++ = bp, n); bp += n; + buflen -= n; cp += n; break; default: diff --git a/resolv/getnetnamadr.c b/resolv/getnetnamadr.c index 9739995e36..8e503dae12 100644 --- a/resolv/getnetnamadr.c +++ b/resolv/getnetnamadr.c @@ -44,6 +44,7 @@ static char sccsid_[] = "from getnetnamadr.c 1.4 (Coimbra) 93/06/03"; static char rcsid[] = "$Id$"; #endif /* LIBC_SCCS and not lint */ +#include #include #include #include diff --git a/resolv/herror.c b/resolv/herror.c index f36126a0bd..70f13c3ad9 100644 --- a/resolv/herror.c +++ b/resolv/herror.c @@ -58,6 +58,7 @@ static char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93"; static char rcsid[] = "$Id$"; #endif /* LIBC_SCCS and not lint */ +#include #include #include #include diff --git a/resolv/inet_addr.c b/resolv/inet_addr.c index 2caf747acf..3452672a0a 100644 --- a/resolv/inet_addr.c +++ b/resolv/inet_addr.c @@ -58,6 +58,7 @@ static char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93"; static char rcsid[] = "$Id$"; #endif /* LIBC_SCCS and not lint */ +#include #include #include #include diff --git a/resolv/inet_net_ntop.c b/resolv/inet_net_ntop.c new file mode 100644 index 0000000000..80abefcba7 --- /dev/null +++ b/resolv/inet_net_ntop.c @@ -0,0 +1,139 @@ +/* + * Copyright (c) 1996 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static const char rcsid[] = "$Id$"; +#endif + +#include +#include +#include +#include + +#include +#include +#include +#include + +#ifdef SPRINTF_CHAR +# define SPRINTF(x) strlen(sprintf/**/x) +#else +# define SPRINTF(x) ((size_t)sprintf x) +#endif + +static char * inet_net_ntop_ipv4 __P((const u_char *src, int bits, + char *dst, size_t size)); + +/* + * char * + * inet_net_ntop(af, src, bits, dst, size) + * convert network number from network to presentation format. + * generates CIDR style result always. + * return: + * pointer to dst, or NULL if an error occurred (check errno). + * author: + * Paul Vixie (ISC), July 1996 + */ +char * +inet_net_ntop(af, src, bits, dst, size) + int af; + const void *src; + int bits; + char *dst; + size_t size; +{ + switch (af) { + case AF_INET: + return (inet_net_ntop_ipv4(src, bits, dst, size)); + default: + errno = EAFNOSUPPORT; + return (NULL); + } +} + +/* + * static char * + * inet_net_ntop_ipv4(src, bits, dst, size) + * convert IPv4 network number from network to presentation format. + * generates CIDR style result always. + * return: + * pointer to dst, or NULL if an error occurred (check errno). + * note: + * network byte order assumed. this means 192.5.5.240/28 has + * 0x11110000 in its fourth octet. + * author: + * Paul Vixie (ISC), July 1996 + */ +static char * +inet_net_ntop_ipv4(src, bits, dst, size) + const u_char *src; + int bits; + char *dst; + size_t size; +{ + char *odst = dst; + char *t; + u_int m; + int b; + + if (bits < 0 || bits > 32) { + errno = EINVAL; + return (NULL); + } + if (bits == 0) { + if (size < sizeof "0") + goto emsgsize; + *dst++ = '0'; + *dst = '\0'; + } + + /* Format whole octets. */ + for (b = bits / 8; b > 0; b--) { + if (size < sizeof "255.") + goto emsgsize; + t = dst; + dst += SPRINTF((dst, "%u", *src++)); + if (b > 1) { + *dst++ = '.'; + *dst = '\0'; + } + size -= (size_t)(dst - t); + } + + /* Format partial octet. */ + b = bits % 8; + if (b > 0) { + if (size < sizeof ".255") + goto emsgsize; + t = dst; + if (dst != odst) + *dst++ = '.'; + m = ((1 << b) - 1) << (8 - b); + dst += SPRINTF((dst, "%u", *src & m)); + size -= (size_t)(dst - t); + } + + /* Format CIDR /width. */ + if (size < sizeof "/32") + goto emsgsize; + dst += SPRINTF((dst, "/%u", bits)); + return (odst); + + emsgsize: + errno = EMSGSIZE; + return (NULL); +} diff --git a/resolv/inet_net_pton.c b/resolv/inet_net_pton.c new file mode 100644 index 0000000000..ea9b2d4b55 --- /dev/null +++ b/resolv/inet_net_pton.c @@ -0,0 +1,201 @@ +/* + * Copyright (c) 1996 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static const char rcsid[] = "$Id$"; +#endif + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#ifdef SPRINTF_CHAR +# define SPRINTF(x) strlen(sprintf/**/x) +#else +# define SPRINTF(x) ((size_t)sprintf x) +#endif + +static int inet_net_pton_ipv4 __P((const char *src, u_char *dst, + size_t size)); + +/* + * static int + * inet_net_pton(af, src, dst, size) + * convert network number from presentation to network format. + * accepts hex octets, hex strings, decimal octets, and /CIDR. + * "size" is in bytes and describes "dst". + * return: + * number of bits, either imputed classfully or specified with /CIDR, + * or -1 if some failure occurred (check errno). ENOENT means it was + * not a valid network specification. + * author: + * Paul Vixie (ISC), June 1996 + */ +int +inet_net_pton(af, src, dst, size) + int af; + const char *src; + void *dst; + size_t size; +{ + switch (af) { + case AF_INET: + return (inet_net_pton_ipv4(src, dst, size)); + default: + errno = EAFNOSUPPORT; + return (-1); + } +} + +/* + * static int + * inet_net_pton_ipv4(src, dst, size) + * convert IPv4 network number from presentation to network format. + * accepts hex octets, hex strings, decimal octets, and /CIDR. + * "size" is in bytes and describes "dst". + * return: + * number of bits, either imputed classfully or specified with /CIDR, + * or -1 if some failure occurred (check errno). ENOENT means it was + * not an IPv4 network specification. + * note: + * network byte order assumed. this means 192.5.5.240/28 has + * 0x11110000 in its fourth octet. + * author: + * Paul Vixie (ISC), June 1996 + */ +static int +inet_net_pton_ipv4(src, dst, size) + const char *src; + u_char *dst; + size_t size; +{ + static const char + xdigits[] = "0123456789abcdef", + digits[] = "0123456789"; + int n, ch, tmp, dirty, bits; + const u_char *odst = dst; + + bits = -1; + ch = *src++; + + if (ch == '0' && (src[0] == 'x' || src[0] == 'X') + && isascii(src[1]) && isxdigit(src[1])) { + /* Hexadecimal: Eat nybble string. */ + if (size <= 0) + goto emsgsize; + *dst = 0, dirty = 0; + src++; /* skip x or X. */ + while ((ch = *src++) != '\0' && + isascii(ch) && isxdigit(ch)) { + if (isupper(ch)) + ch = tolower(ch); + n = strchr(xdigits, ch) - xdigits; + assert(n >= 0 && n <= 15); + *dst |= n; + if (!dirty++) + *dst <<= 4; + else if (size-- > 0) + *++dst = 0, dirty = 0; + else + goto emsgsize; + } + if (dirty) + size--; + } else if (isascii(ch) && isdigit(ch)) { + /* Decimal: eat dotted digit string. */ + for (;;) { + tmp = 0; + do { + n = strchr(digits, ch) - digits; + assert(n >= 0 && n <= 9); + tmp *= 10; + tmp += n; + if (tmp > 255) + goto enoent; + } while ((ch = *src++) != '\0' && + isascii(ch) && isdigit(ch)); + if (size-- <= 0) + goto emsgsize; + *dst++ = (u_char) tmp; + if (ch == '\0' || ch == '/') + break; + if (ch != '.') + goto enoent; + ch = *src++; + if (!isascii(ch) || !isdigit(ch)) + goto enoent; + } + } else + goto enoent; + + if (ch == '/' && isascii(src[0]) && isdigit(src[0]) && dst > odst) { + /* CIDR width specifier. Nothing can follow it. */ + ch = *src++; /* Skip over the /. */ + bits = 0; + do { + n = strchr(digits, ch) - digits; + assert(n >= 0 && n <= 9); + bits *= 10; + bits += n; + } while ((ch = *src++) != '\0' && + isascii(ch) && isdigit(ch)); + if (ch != '\0') + goto enoent; + } + + /* Firey death and destruction unless we prefetched EOS. */ + if (ch != '\0') + goto enoent; + + /* If nothing was written to the destination, we found no address. */ + if (dst == odst) + goto enoent; + /* If no CIDR spec was given, infer width from net class. */ + if (bits == -1) { + if (*odst >= 224) + bits = 4; + else if (*odst >= 192) + bits = 24; + else if (*odst >= 128) + bits = 16; + else + bits = 8; + } + /* Extend network to cover the actual mask. */ + while (bits > ((dst - odst) * 8)) { + if (size-- <= 0) + goto emsgsize; + *dst++ = '\0'; + } + return (bits); + + enoent: + errno = ENOENT; + return (-1); + + emsgsize: + errno = EMSGSIZE; + return (-1); +} diff --git a/resolv/inet_neta.c b/resolv/inet_neta.c new file mode 100644 index 0000000000..ff92d5f2dc --- /dev/null +++ b/resolv/inet_neta.c @@ -0,0 +1,82 @@ +/* + * Copyright (c) 1996 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static const char rcsid[] = "$Id$"; +#endif + +#include +#include +#include +#include + +#include +#include + +#ifdef SPRINTF_CHAR +# define SPRINTF(x) strlen(sprintf/**/x) +#else +# define SPRINTF(x) ((size_t)sprintf x) +#endif + +/* + * char * + * inet_neta(src, dst, size) + * format a u_long network number into presentation format. + * return: + * pointer to dst, or NULL if an error occurred (check errno). + * note: + * format of ``src'' is as for inet_network(). + * author: + * Paul Vixie (ISC), July 1996 + */ +char * +inet_neta(src, dst, size) + u_long src; + char *dst; + size_t size; +{ + char *odst = dst; + char *tp; + + while (src & 0xffffffff) { + u_char b = (src & 0xff000000) >> 24; + + src <<= 8; + if (b) { + if (size < sizeof "255.") + goto emsgsize; + tp = dst; + dst += SPRINTF((dst, "%u", b)); + if (src != 0L) { + *dst++ = '.'; + *dst = '\0'; + } + size -= (size_t)(dst - tp); + } + } + if (dst == odst) { + if (size < sizeof "0.0.0.0") + goto emsgsize; + strcpy(dst, "0.0.0.0"); + } + return (odst); + + emsgsize: + errno = EMSGSIZE; + return (NULL); +} diff --git a/resolv/inet_ntop.c b/resolv/inet_ntop.c index 3b5795f349..a378f3a383 100644 --- a/resolv/inet_ntop.c +++ b/resolv/inet_ntop.c @@ -32,7 +32,7 @@ static char rcsid[] = "$Id$"; #ifdef SPRINTF_CHAR # define SPRINTF(x) strlen(sprintf/**/x) #else -# define SPRINTF(x) sprintf x +# define SPRINTF(x) ((size_t)sprintf x) #endif /* @@ -127,7 +127,7 @@ inet_ntop6(src, dst, size) * Copy the input (bytewise) array into a wordwise array. * Find the longest run of 0x00's in src[] for :: shorthanding. */ - bzero(words, sizeof words); + memset(words, '\0', sizeof words); for (i = 0; i < IN6ADDRSZ; i++) words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3)); best.base = -1; @@ -186,7 +186,7 @@ inet_ntop6(src, dst, size) /* * Check for overflow, copy, and we're done. */ - if ((tp - tmp) > size) { + if ((size_t)(tp - tmp) > size) { errno = ENOSPC; return (NULL); } diff --git a/resolv/inet_pton.c b/resolv/inet_pton.c index d0d45ae3da..2315de59cd 100644 --- a/resolv/inet_pton.c +++ b/resolv/inet_pton.c @@ -67,7 +67,7 @@ inet_pton(af, src, dst) /* int * inet_pton4(src, dst) - * like inet_pton() but without all the hexadecimal and shorthand. + * like inet_aton() but without all the hexadecimal and shorthand. * return: * 1 if `src' is a valid dotted quad, else 0. * notice: @@ -111,7 +111,8 @@ inet_pton4(src, dst) } if (octets < 4) return (0); - bcopy(tmp, dst, INADDRSZ); + + memcpy(dst, tmp, INADDRSZ); return (1); } @@ -140,7 +141,7 @@ inet_pton6(src, dst) int ch, saw_xdigit; u_int val; - bzero((tp = tmp), IN6ADDRSZ); + memset((tp = tmp), '\0', IN6ADDRSZ); endp = tp + IN6ADDRSZ; colonp = NULL; /* Leading :: requires some special handling. */ @@ -209,6 +210,6 @@ inet_pton6(src, dst) } if (tp != endp) return (0); - bcopy(tmp, dst, IN6ADDRSZ); + memcpy(dst, tmp, IN6ADDRSZ); return (1); } diff --git a/resolv/nsap_addr.c b/resolv/nsap_addr.c index 6a8b75c0de..2f8ffae322 100644 --- a/resolv/nsap_addr.c +++ b/resolv/nsap_addr.c @@ -1,7 +1,25 @@ +/* + * Copyright (c) 1996 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + #if defined(LIBC_SCCS) && !defined(lint) static char rcsid[] = "$Id$"; #endif /* LIBC_SCCS and not lint */ +#include #include #include #include diff --git a/resolv/res_comp.c b/resolv/res_comp.c index 103ebd9a52..7da1c3e0f6 100644 --- a/resolv/res_comp.c +++ b/resolv/res_comp.c @@ -58,6 +58,7 @@ static char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93"; static char rcsid[] = "$Id$"; #endif /* LIBC_SCCS and not lint */ +#include #include #include #include @@ -340,34 +341,6 @@ dn_find(exp_dn, msg, dnptrs, lastdnptr) * Verify that a domain name uses an acceptable character set. */ -/**** -To: "Lawrence R. Rogers" -cc: cert@cert.org, pvm@home.net -Subject: Re: VU#14542 -In-reply-to: Your message of "Mon, 19 Feb 1996 17:16:27 PST." -Date: Tue, 20 Feb 1996 22:37:21 -0800 -From: Paul A Vixie - -in retrospect, - - hostname = firstlabel ( "." otherlabel )+ - firstchar = [a-zA-Z0-9_] - otherchar = [a-zA-Z0-9_-/] - firstlabel = firstchar otherchar* - otherlabel = otherchar+ - -should have been - - hostname = label ( "." label )+ - firstchar = [a-zA-Z0-9] - otherchar = [a-zA-Z0-9_-] - label = firstchar otherchar* - -i know of no example of a real host name that needs the looser rule i sent -earlier. since i'm only trying to bend the spec to fit actual known uses, -i should not have widened the rules as far as i did earlier. -****/ - /* * Note the conspicuous absence of ctype macros in these definitions. On * non-ASCII hosts, we can't depend on string literals or ctype macros to @@ -434,17 +407,26 @@ int res_mailok(dn) const char *dn; { - int ch, pch; + int ch, escaped = 0; - pch = '\0'; + /* "." is a valid missing representation */ + if (*dn == '\0') + return(1); + + /* otherwise