├── .github └── workflows │ └── ccpp.yml ├── ChangeLog ├── LICENCE ├── Makefile.am ├── README.md ├── bootstrap ├── configure.ac ├── m4 ├── openbsd-functions.m4 ├── openbsd-headers.m4 ├── openbsd-structs.m4 └── openbsd-types.m4 ├── mk └── mdoc2man.awk ├── openbsd-compat ├── Makefile.am ├── NOTES ├── clock_gettime.c ├── explicit_bzero.c ├── fgetln.c ├── include-config ├── includes │ ├── compat-resolv.h │ ├── compat-socket.h │ ├── compat-stdio.h │ ├── compat-stdlib.h │ ├── compat-string.h │ ├── compat-time.h │ ├── includes.h │ └── sys │ │ ├── queue.h │ │ └── tree.h ├── reallocarray.c ├── recallocarray.c ├── res_hnok.c ├── res_randomid.c ├── strlcat.c ├── strlcpy.c ├── strsep.c └── strtonum.c ├── src ├── Makefile.am ├── asr.c ├── asr.h ├── asr_compat.c ├── asr_compat.h ├── asr_debug.c ├── asr_private.h ├── asr_run.3 ├── asr_utils.c ├── getaddrinfo.c ├── getaddrinfo_async.c ├── gethostnamadr.c ├── gethostnamadr_async.c ├── getnameinfo.c ├── getnameinfo_async.c ├── getnetnamadr.c ├── getnetnamadr_async.c ├── getrrsetbyname.c ├── getrrsetbyname_async.c ├── res_debug.c ├── res_init.c ├── res_mkquery.c ├── res_query.c ├── res_search_async.c ├── res_send.c ├── res_send_async.c ├── sethostent.c └── thread_private.h └── tests └── asr_simple.c /.github/workflows/ccpp.yml: -------------------------------------------------------------------------------- 1 | name: C/C++ CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v1 12 | - name: boostrap 13 | run: bash bootstrap 14 | - name: configure 15 | run: ./configure 16 | - name: make 17 | run: make 18 | - name: make install 19 | run: sudo make install 20 | #- name: make distcheck 21 | # run: make distcheck 22 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | libasr 1.0.4 (2020/01/17) 2 | -------------------------- 3 | * add definition of MAXDNAME for systems that lack it 4 | * some libc require include of nameser_compat.h for rr types definition 5 | 6 | libasr 1.0.3 (2019/09/28) 7 | -------------------------- 8 | * add support for edns0 and dnssec 9 | * remove support for HOSTALIASES 10 | * remove support for non-standard [addr]:port syntax for nameserver 11 | * remove support for YP 12 | * always reload resolv.conf if pid changed 13 | * various bugfixes and improvements 14 | 15 | libasr 1.0.2 (2015/06/03) 16 | -------------------------- 17 | * Make AI_ADDRCONFIG filter on loopback address instead of loopback interface 18 | * Limit AI_ADDRCONFIG effects to DNS queries 19 | * Install manpages 20 | * Allow more aliases and addrs for gethostby*_async() and ignore extra entries 21 | 22 | libasr 1.0.1 (2015/02/02) 23 | -------------------------- 24 | * Fix potential off-by-one when parsing /etc/hosts 25 | * Fix possible NULL-deref when iterating on getifaddrs() result 26 | 27 | libasr 1.0.0 (2014/12/21) 28 | -------------------------- 29 | * First public release 30 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | This file is part of the libasr software. 2 | 3 | The licences which components of this software fall under are as 4 | follows. First, we will summarize and say that all components 5 | are under a BSD licence, or a licence more free than that. 6 | 7 | libasr is divided in 2 parts: 8 | - original asr 9 | - openbsd-compat 10 | 11 | 12 | libasr 13 | ====== 14 | 15 | 16 | 1) Almost all code is licensed under an ISC-style license, to the following 17 | copyright holders: 18 | 19 | Eric Faurot 20 | Internet Software Consortium 21 | 22 | 23 | 2) last part of getrrsetbyname_async.c is covered by 2-clause BSD license 24 | 25 | /* 26 | * Copyright (c) 2001 Jakob Schlyter. All rights reserved. 27 | * 28 | * Redistribution and use in source and binary forms, with or without 29 | * modification, are permitted provided that the following conditions 30 | * are met: 31 | * 32 | * 1. Redistributions of source code must retain the above copyright 33 | * notice, this list of conditions and the following disclaimer. 34 | * 35 | * 2. Redistributions in binary form must reproduce the above copyright 36 | * notice, this list of conditions and the following disclaimer in the 37 | * documentation and/or other materials provided with the distribution. 38 | * 39 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 40 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 41 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 42 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 43 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 44 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 45 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 46 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 47 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 48 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 49 | */ 50 | 51 | 52 | openbsd-compat 53 | ============== 54 | 55 | 56 | Most of the OpenBSD compatibility layer is based on the work by Damien Miller for 57 | Portable OpenSSH. 58 | 59 | 1) Almost all code is licensed under an ISC-style license, to the following 60 | copyright holders: 61 | 62 | Internet Software Consortium. 63 | David Mazieres 64 | Damien Miller 65 | Markus Friedl 66 | Todd C. Miller 67 | Henning Brauer 68 | Pierre-Yves Ritschard 69 | Reyk Floeter 70 | Theo de Raadt 71 | Ted Unangst 72 | Charles Longeau 73 | 74 | * Permission to use, copy, modify, and distribute this software for any 75 | * purpose with or without fee is hereby granted, provided that the above 76 | * copyright notice and this permission notice appear in all copies. 77 | * 78 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 79 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 80 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 81 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 82 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 83 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 84 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 85 | 86 | 87 | 2) Some code is under a 3-clause BSD license, from the 88 | following copyright holders: 89 | 90 | The Regents of the University of California. 91 | Ian F. Darwin 92 | Damien Miller 93 | Eric P. Allman 94 | 95 | * Redistribution and use in source and binary forms, with or without 96 | * modification, are permitted provided that the following conditions 97 | * are met: 98 | * 1. Redistributions of source code must retain the above copyright 99 | * notice, this list of conditions and the following disclaimer. 100 | * 2. Redistributions in binary form must reproduce the above copyright 101 | * notice, this list of conditions and the following disclaimer in the 102 | * documentation and/or other materials provided with the distribution. 103 | * 3. Neither the name of the University nor the names of its contributors 104 | * may be used to endorse or promote products derived from this software 105 | * without specific prior written permission. 106 | * 107 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 108 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 109 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 110 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 111 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 112 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 113 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 114 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 115 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 116 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 117 | * SUCH DAMAGE. 118 | 119 | 120 | 3) includes.h 121 | 122 | * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland 123 | * All rights reserved 124 | * 125 | * As far as I am concerned, the code I have written for this software 126 | * can be used freely for any purpose. Any derived versions of this 127 | * software must be clearly marked as such, and if the derived work is 128 | * incompatible with the protocol description in the RFC file, it must be 129 | * called by a name other than "ssh" or "Secure Shell". 130 | 131 | 132 | 4) bootstrap (only there in the git repository) 133 | 134 | # Copyright (c) 2002-2011 Sam Hocevar 135 | # 136 | # This program is free software. It comes without any warranty, to 137 | # the extent permitted by applicable law. You can redistribute it 138 | # and/or modify it under the terms of the Do What The Fuck You Want 139 | # To Public License, Version 2, as published by Sam Hocevar. See 140 | # http://sam.zoy.org/wtfpl/COPYING for more details. 141 | 142 | 143 | 144 | mk 145 | ====== 146 | 147 | 1) mdoc2man.awk 148 | 149 | # Copyright (c) 2003 Peter Stuge 150 | # 151 | # Permission to use, copy, modify, and distribute this software for any 152 | # purpose with or without fee is hereby granted, provided that the above 153 | # copyright notice and this permission notice appear in all copies. 154 | # 155 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 156 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 157 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 158 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 159 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 160 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 161 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 162 | 163 | # Dramatically overhauled by Tim Kientzle. This version almost 164 | # handles library-style pages with Fn, Ft, etc commands. Still 165 | # a lot of problems... 166 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = openbsd-compat 2 | SUBDIRS += src 3 | 4 | ACLOCAL_AMFLAGS = -I m4 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Description 2 | =========== 3 | 4 | > **Warning** 5 | > This repository is not updated and contains known issues that are 6 | > fixed in upstream OpenBSD. Please use the bundled version in 7 | > OpenSMTPD instead. 8 | 9 | libasr is a free, simple and portable asynchronous resolver library. 10 | 11 | It allows to run dns queries and perform hostname resolutions in a fully 12 | asynchronous fashion. The implementation is thread-less, fork-less, and 13 | does not make use of signals or other "tricks" that might get in the 14 | developer's way. The API was initially developed for the OpenBSD 15 | operating system, where it is natively supported. 16 | 17 | This library is intended to bring this interface to other systems. It is 18 | originally provided as a support library for the portable version of the 19 | OpenSMTPD daemon, but it can be used in any other contexts. It is known 20 | to work on the following systems: 21 | 22 | * Linux 23 | * FreeBSD 24 | * NetBSD 25 | * DragonFly 26 | * MacOSX 27 | 28 | The primary source of information about libasr is the [github repository][1]. 29 | 30 | [1]: http://github.com/OpenSMTPD/libasr 31 | 32 | 33 | Installation 34 | ============ 35 | 36 | Get the source 37 | -------------- 38 | 39 | You can get the latest sources from github: 40 | 41 | git clone git://github.com/OpenSMTPD/libasr.git 42 | 43 | Tarballs for development snapshots and official releases are available 44 | on the [OpenSMTPD website][2]. 45 | 46 | [2]: http://www.opensmtpd.org/archives/ 47 | 48 | Build 49 | ----- 50 | 51 | All you should need is working C compiler, a C library and the autotools 52 | ([autoconf],[automake],[libtool]). Build and install using the following 53 | commands: 54 | 55 | ./bootstrap # only if building from git sources 56 | ./configure 57 | make 58 | sudo make install 59 | 60 | [autoconf]: http://www.gnu.org/software/autoconf/ 61 | [automake]: http://www.gnu.org/software/automake/ 62 | [libtool]: http://www.gnu.org/software/libtool/ 63 | 64 | Documentation 65 | ============= 66 | 67 | For documentation on using the API, please refer to the [OpenBSD manpages][3]. 68 | Note that unlike the native OpenBSD implementation, this version is not currently 69 | thread-safe. 70 | 71 | [3]: http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/asr_run.3 72 | 73 | 74 | Contact 75 | ======= 76 | 77 | For now, please use the [OpenSMTPD mailing list][4] for questions related to 78 | libasr. You can also get in touch with libasr developers on the "Official" 79 | IRC channel for the OpenSMTPD project at: 80 | 81 | #OpenSMTPD @ irc.freenode.net 82 | 83 | Bug reports must be filed on the [project's issue tracker][5]. 84 | 85 | [4]: http://www.opensmtpd.org/list.html 86 | [5]: http://github.com/OpenSMTPD/libasr/issues 87 | -------------------------------------------------------------------------------- /bootstrap: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # bootstrap: generic bootstrap/autogen.sh script for autotools projects 4 | # 5 | # Copyright (c) 2002-2011 Sam Hocevar 6 | # 7 | # This program is free software. It comes without any warranty, to 8 | # the extent permitted by applicable law. You can redistribute it 9 | # and/or modify it under the terms of the Do What The Fuck You Want 10 | # To Public License, Version 2, as published by Sam Hocevar. See 11 | # http://sam.zoy.org/wtfpl/COPYING for more details. 12 | # 13 | # The latest version of this script can be found at the following place: 14 | # http://caca.zoy.org/wiki/build 15 | 16 | # Die if an error occurs 17 | set -e 18 | 19 | quiet="false" 20 | quietarg= 21 | usage() 22 | { 23 | echo 24 | echo "usage: ${progname} [-h] [-q]" 25 | echo 26 | echo "options:" 27 | echo " -h .. display this message and exit" 28 | echo " -q .. quiet, don't display directories" 29 | echo 30 | exit 1 31 | } 32 | 33 | while test $# -gt 0; do 34 | case $1 in 35 | -h|--he|--hel|--help) 36 | usage ;; 37 | -q|--qu|--qui|--quie|--quiet) 38 | quiet="true" 39 | quietarg=--quiet 40 | shift;; 41 | -*) echo "unknown option $1" 42 | usage ;; 43 | *) echo "invalid parameter $1" 44 | usage ;; 45 | esac 46 | done 47 | 48 | # Guess whether we are using configure.ac or configure.in 49 | if test -f configure.ac; then 50 | conffile="configure.ac" 51 | elif test -f configure.in; then 52 | conffile="configure.in" 53 | else 54 | echo "$0: could not find configure.ac or configure.in" 55 | exit 1 56 | fi 57 | 58 | # Check for needed features 59 | auxdir="`sed -ne 's/^[ \t]*A._CONFIG_AUX_DIR *([[ ]*\([^] )]*\).*/\1/p' $conffile`" 60 | pkgconfig="`grep '^[ \t]*PKG_PROG_PKG_CONFIG' $conffile >/dev/null 2>&1 && echo yes || echo no`" 61 | libtool="`grep '^[ \t]*A._PROG_LIBTOOL' $conffile >/dev/null 2>&1 && echo yes || echo no`" 62 | header="`grep '^[ \t]*A._CONFIG_HEADER' $conffile >/dev/null 2>&1 && echo yes || echo no`" 63 | makefile="`[ -f Makefile.am ] && echo yes || echo no`" 64 | aclocalflags="`sed -ne 's/^[ \t]*ACLOCAL_AMFLAGS[ \t]*=//p' Makefile.am 2>/dev/null || :`" 65 | 66 | # Check for automake 67 | amvers="no" 68 | for v in 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5; do 69 | if automake-1.${v} --version >/dev/null 2>&1; then 70 | amvers="-1.${v}" 71 | break 72 | elif automake1.${v} --version >/dev/null 2>&1; then 73 | amvers="1.${v}" 74 | break 75 | fi 76 | done 77 | 78 | if test "${amvers}" = "no" && automake --version > /dev/null 2>&1; then 79 | amvers="`automake --version | sed -e '1s/[^0-9]*//' -e q`" 80 | if expr "$amvers" "<" "1.5" > /dev/null 2>&1; then 81 | amvers="no" 82 | else 83 | amvers="" 84 | fi 85 | fi 86 | 87 | if test "$amvers" = "no"; then 88 | echo "$0: you need automake version 1.5 or later" 89 | exit 1 90 | fi 91 | 92 | # Check for autoconf 93 | acvers="no" 94 | for v in "" "269" "-2.69" "259" "-2.59" "253" "-2.53"; do 95 | if autoconf${v} --version >/dev/null 2>&1; then 96 | acvers="${v}" 97 | break 98 | fi 99 | done 100 | 101 | if test "$acvers" = "no"; then 102 | echo "$0: you need autoconf" 103 | exit 1 104 | fi 105 | 106 | # Check for libtool 107 | if test "$libtool" = "yes"; then 108 | libtoolize="no" 109 | if glibtoolize --version >/dev/null 2>&1; then 110 | libtoolize="glibtoolize" 111 | else 112 | for v in "16" "15" "" "14"; do 113 | if libtoolize${v} --version >/dev/null 2>&1; then 114 | libtoolize="libtoolize${v}" 115 | break 116 | fi 117 | done 118 | fi 119 | 120 | if test "$libtoolize" = "no"; then 121 | echo "$0: you need libtool" 122 | exit 1 123 | fi 124 | fi 125 | 126 | # Check for pkg-config 127 | if test "$pkgconfig" = "yes"; then 128 | if ! pkg-config --version >/dev/null 2>&1; then 129 | echo "$0: you need pkg-config" 130 | exit 1 131 | fi 132 | fi 133 | 134 | # Remove old cruft 135 | for x in aclocal.m4 configure config.guess config.log config.sub config.cache config.h.in config.h compile libtool.m4 ltoptions.m4 ltsugar.m4 ltversion.m4 ltmain.sh libtool ltconfig missing mkinstalldirs depcomp install-sh; do rm -f $x autotools/$x; if test -n "$auxdir"; then rm -f "$auxdir/$x"; fi; done 136 | rm -Rf autom4te.cache 137 | if test -n "$auxdir"; then 138 | if test ! -d "$auxdir"; then 139 | mkdir "$auxdir" 140 | fi 141 | aclocalflags="${aclocalflags} -I $auxdir -I ." 142 | fi 143 | 144 | # Honour M4PATH because sometimes M4 doesn't 145 | save_IFS=$IFS 146 | IFS=: 147 | tmp="$M4PATH" 148 | for x in $tmp; do 149 | if test -n "$x"; then 150 | aclocalflags="${aclocalflags} -I $x" 151 | fi 152 | done 153 | IFS=$save_IFS 154 | 155 | # Explain what we are doing from now 156 | test "$quiet" = "true" || set -x 157 | 158 | # Bootstrap package 159 | if test "$libtool" = "yes"; then 160 | ${libtoolize} --copy --force $quietarg 161 | if test -n "$auxdir" -a ! "$auxdir" = "." -a -f "ltmain.sh"; then 162 | test "$quiet" = "true" || echo "$0: working around a minor libtool issue" 163 | mv ltmain.sh "$auxdir/" 164 | fi 165 | fi 166 | 167 | aclocal${amvers} ${aclocalflags} 168 | autoconf${acvers} 169 | if test "$header" = "yes"; then 170 | autoheader${acvers} 171 | fi 172 | if test "$makefile" = "yes"; then 173 | #add --include-deps if you want to bootstrap with any other compiler than gcc 174 | #automake${amvers} --add-missing --copy --include-deps 175 | automake${amvers} --foreign --add-missing --copy 176 | fi 177 | 178 | # Remove cruft that we no longer want 179 | rm -Rf autom4te.cache 180 | 181 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # $Id: configure.ac,v 1.519 2013/03/22 01:49:15 dtucker Exp $ 2 | # 3 | # Copyright (c) 1999-2004 Damien Miller 4 | # 5 | # Permission to use, copy, modify, and distribute this software for any 6 | # purpose with or without fee is hereby granted, provided that the above 7 | # copyright notice and this permission notice appear in all copies. 8 | # 9 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | 17 | # 18 | # 3.1.3 Standard configure.ac Layout 19 | # 20 | # https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Autoconf-Input-Layout.html 21 | # 22 | 23 | # 24 | # AUTOCONF REQUIREMENTS 25 | # 26 | AC_PREREQ(2.69) 27 | 28 | # 29 | # AC_INIT 30 | # 31 | AC_INIT([libasr], 32 | [portable], 33 | [bugs@opensmtpd.org]) 34 | AM_INIT_AUTOMAKE([foreign subdir-objects]) 35 | LT_INIT 36 | 37 | # 38 | # PACKAGE INFORMATION 39 | # 40 | AC_LANG([C]) 41 | AC_CONFIG_MACRO_DIR([m4]) 42 | AC_CONFIG_HEADER([config.h]) 43 | AC_CANONICAL_HOST 44 | AC_C_BIGENDIAN 45 | 46 | # 47 | # CHECKS FOR PROGRAMS 48 | # 49 | AC_PROG_CC 50 | AC_PROG_CPP 51 | AC_PROG_INSTALL 52 | AC_PROG_LIBTOOL 53 | 54 | # 55 | # CHECKS FOR LIBRARIES 56 | # 57 | 58 | # 59 | # CHECKS FOR HEADERS 60 | # 61 | OPENBSD_CHECK_HEADERS 62 | AC_CHECK_HEADERS( 63 | arpa/nameser_compat.h 64 | ) 65 | 66 | # 67 | # CHECKS FOR TYPES 68 | # 69 | OPENBSD_CHECK_TYPES 70 | 71 | # 72 | # CHECKS FOR STRUCTURES 73 | # 74 | OPENBSD_CHECK_STRUCTS 75 | 76 | # 77 | # CHECKS FOR COMPILER CHARACTERISTICS 78 | # 79 | 80 | # 81 | # CHECKS FOR LIBRARY FUNCTIONS 82 | # 83 | OPENBSD_CHECK_FUNCTIONS 84 | 85 | # 86 | # CHECKS FOR SYSTEM SERVICES 87 | # 88 | 89 | # 90 | # libasr specific checks. 91 | # 92 | 93 | # This ought to be part of the generic compat library, but we don't want to force 94 | # linking against other libs (-lresolv for instance) in all cases. 95 | # It has to be improved at some point. 96 | # 97 | AC_DEFUN([LIBASR_CHECK_EXPLICIT_BZERO], [AC_LANG_PROGRAM([[ 98 | #include 99 | ]], [[ 100 | char c; 101 | explicit_bzero((void *)&c, 1); 102 | ]]) 103 | ]) 104 | AC_MSG_CHECKING([if explicit_bzero() will build]) 105 | AC_LINK_IFELSE( 106 | [ LIBASR_CHECK_EXPLICIT_BZERO ], 107 | [ AC_MSG_RESULT([yes]) 108 | AC_DEFINE([HAVE_EXPLICIT_BZERO], [1], [Have explicit_bzero()])], 109 | [ AC_MSG_RESULT([no]) 110 | ]) 111 | 112 | AC_DEFUN([LIBASR_CHECK_CLOCK_GETTIME], [AC_LANG_PROGRAM([[ 113 | #include 114 | ]], [[ 115 | clock_gettime(0, NULL); 116 | ]]) 117 | ]) 118 | AC_MSG_CHECKING([if clock_gettime() will build]) 119 | AC_LINK_IFELSE( 120 | [ LIBASR_CHECK_CLOCK_GETTIME ], 121 | [ AC_MSG_RESULT([yes]) 122 | AC_DEFINE([HAVE_CLOCK_GETTIME], [1], [Have clock_gettime()])], 123 | [ AC_MSG_RESULT([no]) 124 | saved_LIBS="$LIBS" 125 | LIBS="$LIBS -lrt" 126 | AC_MSG_CHECKING([if clock_gettime() will build with -lrt]) 127 | AC_LINK_IFELSE( 128 | [ LIBASR_CHECK_CLOCK_GETTIME ], 129 | [ AC_MSG_RESULT([yes]) 130 | AC_DEFINE([HAVE_CLOCK_GETTIME], [1], [Have clock_gettime()])], 131 | [ LIBS="$saved_LIBS" 132 | AC_MSG_RESULT([no])]) 133 | ]) 134 | 135 | AC_DEFUN([LIBASR_CHECK_RES_HNOK], [AC_LANG_PROGRAM([[ 136 | #include 137 | #include 138 | #include 139 | #include 140 | ]], [[ 141 | res_hnok(""); 142 | ]]) 143 | ]) 144 | AC_MSG_CHECKING([if res_hnok() will build]) 145 | AC_LINK_IFELSE( 146 | [ LIBASR_CHECK_RES_HNOK ], 147 | [ AC_MSG_RESULT([yes]) 148 | AC_DEFINE([HAVE_RES_HNOK], [1], [Have res_hnok()])], 149 | [ AC_MSG_RESULT([no]) 150 | saved_LIBS="$LIBS" 151 | LIBS="$LIBS -lresolv" 152 | AC_MSG_CHECKING([if res_hnok() will build with -lresolv]) 153 | AC_LINK_IFELSE( 154 | [ LIBASR_CHECK_RES_HNOK ], 155 | [ AC_MSG_RESULT([yes]) 156 | AC_DEFINE([HAVE_RES_HNOK], [1], [Have res_hnok()])], 157 | [ LIBS="$saved_LIBS" 158 | AC_MSG_RESULT([no])]) 159 | ]) 160 | 161 | # Same remark as above. 162 | # 163 | AC_DEFUN([LIBASR_CHECK_RES_RANDOMID], [AC_LANG_PROGRAM([[ 164 | #include 165 | #include 166 | #include 167 | #include 168 | ]], [[ 169 | res_randomid(); 170 | ]]) 171 | ]) 172 | AC_MSG_CHECKING([if res_randomid() will build]) 173 | AC_LINK_IFELSE( 174 | [ LIBASR_CHECK_RES_RANDOMID ], 175 | [ AC_MSG_RESULT([yes]) 176 | AC_DEFINE([HAVE_RES_RANDOMID], [1], [Have res_randomid()])], 177 | [ AC_MSG_RESULT([no]) 178 | saved_LIBS="$LIBS" 179 | LIBS="$LIBS -lresolv" 180 | AC_MSG_CHECKING([if res_randomid() will build with -lresolv]) 181 | AC_LINK_IFELSE( 182 | [ LIBASR_CHECK_RES_RANDOMID ], 183 | [ AC_MSG_RESULT([yes]) 184 | AC_DEFINE([HAVE_RES_RANDOMID], [1], [Have res_randomid()])], 185 | [ LIBS="$saved_LIBS" 186 | AC_MSG_RESULT([no])]) 187 | ]) 188 | 189 | ## 190 | AC_DEFUN([LIBASR_CHECK___P_TYPE], [AC_LANG_PROGRAM([[ 191 | #include 192 | #include 193 | #include 194 | #include 195 | ]], [[ 196 | __p_type(0); 197 | ]]) 198 | ]) 199 | AC_MSG_CHECKING([if __p_type() will build]) 200 | AC_LINK_IFELSE( 201 | [ LIBASR_CHECK___P_TYPE ], 202 | [ AC_MSG_RESULT([yes]) 203 | AC_DEFINE([HAVE___P_TYPE], [1], [Have __p_type()])], 204 | [ AC_MSG_RESULT([no]) 205 | saved_LIBS="$LIBS" 206 | LIBS="$LIBS -lresolv" 207 | AC_MSG_CHECKING([if __p_type() will build with -lresolv]) 208 | AC_LINK_IFELSE( 209 | [ LIBASR_CHECK___P_TYPE ], 210 | [ AC_MSG_RESULT([yes]) 211 | AC_DEFINE([HAVE___P_TYPE], [1], [Have __p_type()])], 212 | [ LIBS="$saved_LIBS" 213 | AC_MSG_RESULT([no])]) 214 | ]) 215 | 216 | AC_DEFUN([LIBASR_CHECK___P_CLASS], [AC_LANG_PROGRAM([[ 217 | #include 218 | #include 219 | #include 220 | #include 221 | ]], [[ 222 | __p_class(0); 223 | ]]) 224 | ]) 225 | AC_MSG_CHECKING([if __p_class() will build]) 226 | AC_LINK_IFELSE( 227 | [ LIBASR_CHECK___P_CLASS ], 228 | [ AC_MSG_RESULT([yes]) 229 | AC_DEFINE([HAVE___P_CLASS], [1], [Have __p_class()])], 230 | [ AC_MSG_RESULT([no]) 231 | saved_LIBS="$LIBS" 232 | LIBS="$LIBS -lresolv" 233 | AC_MSG_CHECKING([if __p_class() will build with -lresolv]) 234 | AC_LINK_IFELSE( 235 | [ LIBASR_CHECK___P_CLASS ], 236 | [ AC_MSG_RESULT([yes]) 237 | AC_DEFINE([HAVE___P_CLASS], [1], [Have __p_class()])], 238 | [ LIBS="$saved_LIBS" 239 | AC_MSG_RESULT([no])]) 240 | ]) 241 | 242 | # 243 | # OUTPUT 244 | # 245 | AC_CONFIG_FILES([Makefile 246 | openbsd-compat/Makefile 247 | src/Makefile 248 | ]) 249 | AC_CONFIG_COMMANDS([include-config], 250 | [sh $srcdir/openbsd-compat/include-config $srcdir], 251 | [srcdir=$srcdir]) 252 | AC_OUTPUT 253 | -------------------------------------------------------------------------------- /m4/openbsd-functions.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([OPENBSD_CHECK_FUNCTIONS], [ 2 | AC_CHECK_FUNCS( \ 3 | clock_gettime \ 4 | explicit_bzero \ 5 | fgetln \ 6 | freezero \ 7 | getline \ 8 | reallocarray \ 9 | recallocarray \ 10 | strlcat \ 11 | strlcpy \ 12 | strsep \ 13 | strtonum 14 | ) 15 | ]) 16 | -------------------------------------------------------------------------------- /m4/openbsd-headers.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([OPENBSD_CHECK_HEADERS], [ 2 | AC_CHECK_HEADERS( \ 3 | sys/queue.h \ 4 | sys/tree.h \ 5 | ) 6 | ]) 7 | -------------------------------------------------------------------------------- /m4/openbsd-structs.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([OPENBSD_CHECK_STRUCTS], [ 2 | AC_CHECK_MEMBERS([struct sockaddr.sa_len], , , 3 | [ #include 4 | #include 5 | #include ] 6 | ) 7 | AC_CHECK_MEMBERS([struct sockaddr_storage.ss_len], , , 8 | [ #include 9 | #include 10 | #include ] 11 | ) 12 | AC_CHECK_MEMBERS([struct sockaddr_in.sin_len], , , 13 | [ #include 14 | #include 15 | #include ] 16 | ) 17 | AC_CHECK_MEMBERS([struct sockaddr_in6.sin6_len], , , 18 | [ #include 19 | #include 20 | #include ] 21 | ) 22 | ]) 23 | -------------------------------------------------------------------------------- /m4/openbsd-types.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([OPENBSD_CHECK_TYPES], [ 2 | AC_CHECK_TYPES([long long, unsigned long long, long double]) 3 | AC_CHECK_SIZEOF([short int], [2]) 4 | AC_CHECK_SIZEOF([int], [4]) 5 | AC_CHECK_SIZEOF([long int], [4]) 6 | AC_CHECK_SIZEOF([long long int], [8]) 7 | AC_TYPE_INT8_T 8 | AC_TYPE_INT16_T 9 | AC_TYPE_INT32_T 10 | AC_TYPE_INT64_T 11 | AC_TYPE_UINT8_T 12 | AC_TYPE_UINT16_T 13 | AC_TYPE_UINT32_T 14 | AC_TYPE_UINT64_T 15 | AC_TYPE_INTPTR_T 16 | AC_TYPE_INTMAX_T 17 | AC_TYPE_UINTPTR_T 18 | AC_TYPE_UINTMAX_T 19 | AC_TYPE_SIZE_T 20 | AC_TYPE_SSIZE_T 21 | AC_TYPE_OFF_T 22 | AC_TYPE_MODE_T 23 | AC_TYPE_PID_T 24 | AC_TYPE_UID_T 25 | ]) 26 | -------------------------------------------------------------------------------- /mk/mdoc2man.awk: -------------------------------------------------------------------------------- 1 | #!/usr/bin/awk 2 | # 3 | # Copyright (c) 2003 Peter Stuge 4 | # 5 | # Permission to use, copy, modify, and distribute this software for any 6 | # purpose with or without fee is hereby granted, provided that the above 7 | # copyright notice and this permission notice appear in all copies. 8 | # 9 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | 17 | # Dramatically overhauled by Tim Kientzle. This version almost 18 | # handles library-style pages with Fn, Ft, etc commands. Still 19 | # a lot of problems... 20 | 21 | BEGIN { 22 | displaylines = 0 23 | trailer = "" 24 | out = "" 25 | sep = "" 26 | nextsep = " " 27 | } 28 | 29 | # Add a word with appropriate preceding whitespace 30 | # Maintain a short queue of the expected upcoming word separators. 31 | function add(str) { 32 | out=out sep str 33 | sep = nextsep 34 | nextsep = " " 35 | } 36 | 37 | # Add a word with no following whitespace 38 | # Use for opening punctuation such as '(' 39 | function addopen(str) { 40 | add(str) 41 | sep = "" 42 | } 43 | 44 | # Add a word with no preceding whitespace 45 | # Use for closing punctuation such as ')' or '.' 46 | function addclose(str) { 47 | sep = "" 48 | add(str) 49 | } 50 | 51 | # Add a word with no space before or after 52 | # Use for separating punctuation such as '=' 53 | function addpunct(str) { 54 | sep = "" 55 | add(str) 56 | sep = "" 57 | } 58 | 59 | # Emit the current line so far 60 | function endline() { 61 | addclose(trailer) 62 | trailer = "" 63 | if(length(out) > 0) { 64 | print out 65 | out="" 66 | } 67 | if(displaylines > 0) { 68 | displaylines = displaylines - 1 69 | if (displaylines == 0) 70 | dispend() 71 | } 72 | # First word on next line has no preceding whitespace 73 | sep = "" 74 | } 75 | 76 | function linecmd(cmd) { 77 | endline() 78 | add(cmd) 79 | endline() 80 | } 81 | 82 | function breakline() { 83 | linecmd(".br") 84 | } 85 | 86 | # Start an indented display 87 | function dispstart() { 88 | linecmd(".RS 4") 89 | } 90 | 91 | # End an indented display 92 | function dispend() { 93 | linecmd(".RE") 94 | } 95 | 96 | # Collect rest of input line 97 | function wtail() { 98 | retval="" 99 | while(w 0) { 111 | sub("^[ \t]*", "", l) 112 | if (match(l, "^\"")) { 113 | l = substr(l, 2) 114 | o = index(l, "\"") 115 | if (o > 0) { 116 | w = substr(l, 1, o-1) 117 | l = substr(l, o+1) 118 | dest[n++] = w 119 | } else { 120 | dest[n++] = l 121 | l = "" 122 | } 123 | } else { 124 | o = match(l, "[ \t]") 125 | if (o > 0) { 126 | w = substr(l, 1, o-1) 127 | l = substr(l, o+1) 128 | dest[n++] = w 129 | } else { 130 | dest[n++] = l 131 | l = "" 132 | } 133 | } 134 | } 135 | return n-1 136 | } 137 | 138 | ! /^\./ { 139 | out = $0 140 | endline() 141 | next 142 | } 143 | 144 | /^\.\\"/ { next } 145 | 146 | { 147 | sub("^\\.","") 148 | nwords=splitwords($0, words) 149 | # TODO: Instead of iterating 'w' over the array, have a separate 150 | # function that returns 'next word' and use that. This will allow 151 | # proper handling of double-quoted arguments as well. 152 | for(w=1;w<=nwords;w++) { 153 | if(match(words[w],"^Li$")) { # Literal; rest of line is unformatted 154 | dispstart() 155 | displaylines = 1 156 | } else if(match(words[w],"^Dl$")) { # Display literal 157 | dispstart() 158 | displaylines = 1 159 | } else if(match(words[w],"^Bd$")) { # Begin display 160 | if(match(words[w+1],"-literal")) { 161 | dispstart() 162 | linecmd(".nf") 163 | displaylines=10000 164 | w=nwords 165 | } 166 | } else if(match(words[w],"^Ed$")) { # End display 167 | displaylines = 0 168 | dispend() 169 | } else if(match(words[w],"^Ns$")) { # Suppress space after next word 170 | nextsep = "" 171 | } else if(match(words[w],"^No$")) { # Normal text 172 | add(words[++w]) 173 | } else if(match(words[w],"^Dq$")) { # Quote 174 | addopen("``") 175 | add(words[++w]) 176 | while(w") 191 | } else if(match(words[w],"^Dd$")) { 192 | date=wtail() 193 | next 194 | } else if(match(words[w],"^Dt$")) { 195 | id=wtail() 196 | next 197 | } else if(match(words[w],"^Ox$")) { 198 | add("OpenBSD") 199 | } else if(match(words[w],"^Fx$")) { 200 | add("FreeBSD") 201 | } else if(match(words[w],"^Nx$")) { 202 | add("NetBSD") 203 | } else if(match(words[w],"^St$")) { 204 | if (match(words[w+1], "^-p1003.1$")) { 205 | w++ 206 | add("IEEE Std 1003.1 (``POSIX.1'')") 207 | } else if(match(words[w+1], "^-p1003.1-96$")) { 208 | w++ 209 | add("ISO/IEC 9945-1:1996 (``POSIX.1'')") 210 | } else if(match(words[w+1], "^-p1003.1-88$")) { 211 | w++ 212 | add("IEEE Std 1003.1-1988 (``POSIX.1'')") 213 | } else if(match(words[w+1], "^-p1003.1-2001$")) { 214 | w++ 215 | add("IEEE Std 1003.1-2001 (``POSIX.1'')") 216 | } else if(match(words[w+1], "^-susv2$")) { 217 | w++ 218 | add("Version 2 of the Single UNIX Specification (``SUSv2'')") 219 | } 220 | } else if(match(words[w],"^Ex$")) { 221 | if (match(words[w+1], "^-std$")) { 222 | w++ 223 | add("The \\fB" name "\\fP utility exits 0 on success, and >0 if an error occurs.") 224 | } 225 | } else if(match(words[w],"^Os$")) { 226 | add(".TH " id " \"" date "\" \"" wtail() "\"") 227 | } else if(match(words[w],"^Sh$")) { 228 | section=wtail() 229 | add(".SH " section) 230 | linecmd(".ad l") 231 | } else if(match(words[w],"^Xr$")) { 232 | add("\\fB" words[++w] "\\fP(" words[++w] ")" words[++w]) 233 | } else if(match(words[w],"^Nm$")) { 234 | if(match(section,"SYNOPSIS")) 235 | breakline() 236 | if(w >= nwords) 237 | n=name 238 | else if (match(words[w+1], "^[A-Z][a-z]$")) 239 | n=name 240 | else if (match(words[w+1], "^[.,;:]$")) 241 | n=name 242 | else { 243 | n=words[++w] 244 | if(!length(name)) 245 | name=n 246 | } 247 | if(!length(n)) 248 | n=name 249 | add("\\fB\\%" n "\\fP") 250 | } else if(match(words[w],"^Nd$")) { 251 | add("\\- " wtail()) 252 | } else if(match(words[w],"^Fl$")) { 253 | add("\\fB\\-" words[++w] "\\fP") 254 | } else if(match(words[w],"^Ar$")) { 255 | addopen("\\fI") 256 | if(w==nwords) 257 | add("file ...\\fP") 258 | else 259 | add(words[++w] "\\fP") 260 | } else if(match(words[w],"^Cm$")) { 261 | add("\\fB" words[++w] "\\fP") 262 | } else if(match(words[w],"^Op$")) { 263 | addopen("[") 264 | option=1 265 | trailer="]" trailer 266 | } else if(match(words[w],"^Pp$")) { 267 | linecmd(".PP") 268 | } else if(match(words[w],"^An$")) { 269 | endline() 270 | } else if(match(words[w],"^Ss$")) { 271 | add(".SS") 272 | } else if(match(words[w],"^Ft$")) { 273 | if (match(section, "SYNOPSIS")) { 274 | breakline() 275 | } 276 | add("\\fI" wtail() "\\fP") 277 | if (match(section, "SYNOPSIS")) { 278 | breakline() 279 | } 280 | } else if(match(words[w],"^Fn$")) { 281 | ++w 282 | F = "\\fB\\%" words[w] "\\fP(" 283 | Fsep = "" 284 | while(w\\fP") 318 | } else if(match(words[w],"^Pa$")) { 319 | addopen("\\fI") 320 | w++ 321 | if(match(words[w],"^\\.")) 322 | add("\\&") 323 | add(words[w] "\\fP") 324 | } else if(match(words[w],"^Dv$")) { 325 | add(".BR") 326 | } else if(match(words[w],"^Em|Ev$")) { 327 | add(".IR") 328 | } else if(match(words[w],"^Pq$")) { 329 | addopen("(") 330 | trailer=")" trailer 331 | } else if(match(words[w],"^Aq$")) { 332 | addopen("\\%<") 333 | trailer=">" trailer 334 | } else if(match(words[w],"^Brq$")) { 335 | addopen("{") 336 | trailer="}" trailer 337 | } else if(match(words[w],"^S[xy]$")) { 338 | add(".B " wtail()) 339 | } else if(match(words[w],"^Ic$")) { 340 | add("\\fB") 341 | trailer="\\fP" trailer 342 | } else if(match(words[w],"^Bl$")) { 343 | oldoptlist=optlist 344 | linecmd(".RS 5") 345 | if(match(words[w+1],"-bullet")) 346 | optlist=1 347 | else if(match(words[w+1],"-enum")) { 348 | optlist=2 349 | enum=0 350 | } else if(match(words[w+1],"-tag")) 351 | optlist=3 352 | else if(match(words[w+1],"-item")) 353 | optlist=4 354 | else if(match(words[w+1],"-bullet")) 355 | optlist=1 356 | w=nwords 357 | } else if(match(words[w],"^El$")) { 358 | linecmd(".RE") 359 | optlist=oldoptlist 360 | } else if(match(words[w],"^It$")&&optlist) { 361 | if(optlist==1) 362 | add(".IP \\(bu") 363 | else if(optlist==2) 364 | add(".IP " ++enum ".") 365 | else if(optlist==3) { 366 | add(".TP") 367 | endline() 368 | if(match(words[w+1],"^Pa$|^Ev$")) { 369 | add(".B") 370 | w++ 371 | } 372 | } else if(optlist==4) 373 | add(".IP") 374 | } else if(match(words[w],"^Xo$")) { 375 | # TODO: Figure out how to handle this 376 | } else if(match(words[w],"^Xc$")) { 377 | # TODO: Figure out how to handle this 378 | } else if(match(words[w],"^[=]$")) { 379 | addpunct(words[w]) 380 | } else if(match(words[w],"^[[{(]$")) { 381 | addopen(words[w]) 382 | } else if(match(words[w],"^[\\])}.,;:]$")) { 383 | addclose(words[w]) 384 | } else { 385 | add(words[w]) 386 | } 387 | } 388 | if(match(out,"^\\.[^a-zA-Z]")) 389 | sub("^\\.","",out) 390 | endline() 391 | } 392 | -------------------------------------------------------------------------------- /openbsd-compat/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LIBRARIES = libopenbsdcompat.a 2 | 3 | libopenbsdcompat_a_SOURCES = fgetln.c 4 | libopenbsdcompat_a_SOURCES += explicit_bzero.c 5 | libopenbsdcompat_a_SOURCES += reallocarray.c 6 | libopenbsdcompat_a_SOURCES += recallocarray.c 7 | libopenbsdcompat_a_SOURCES += res_hnok.c 8 | libopenbsdcompat_a_SOURCES += res_randomid.c 9 | libopenbsdcompat_a_SOURCES += strlcat.c 10 | libopenbsdcompat_a_SOURCES += strlcpy.c 11 | #libopenbsdcompat_a_SOURCES += strsep.c 12 | libopenbsdcompat_a_SOURCES += strtonum.c 13 | 14 | libopenbsdcompat_a_CPPFLAGS = -I$(builddir)/include 15 | libopenbsdcompat_a_CFLAGS = -fPIC 16 | -------------------------------------------------------------------------------- /openbsd-compat/NOTES: -------------------------------------------------------------------------------- 1 | List of files and where they come from 2 | 3 | clock_gettime.c handmade 4 | defines.h portable openssh 5 | fgetln.c part of /usr/src/usr.bin/make/util.c 6 | includes.h portable openssh 7 | openbsd-compat.h portable openssh 8 | strlcat.c portable openssh 9 | strlcpy.c portable openssh 10 | strtonum.c portable openssh 11 | sys/queue.h portable openssh 12 | sys/tree.h portable openssh 13 | -------------------------------------------------------------------------------- /openbsd-compat/clock_gettime.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 Charles Longeau 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include "includes.h" 18 | 19 | #ifdef HAVE_MACH_MACH_TIME_H 20 | #include 21 | #endif 22 | #include 23 | #include 24 | 25 | #if !defined(HAVE_CLOCK_GETTIME) 26 | int 27 | clock_gettime(int clock_id, struct timespec *tp) 28 | { 29 | int ret = 0; 30 | uint64_t time; 31 | mach_timebase_info_data_t info; 32 | static double scaling_factor = 0; 33 | 34 | #if 0 35 | struct timeval tv; 36 | 37 | ret = gettimeofday(&tv, NULL); 38 | TIMEVAL_TO_TIMESPEC(&tv, tp); 39 | #endif 40 | 41 | /* based on http://code-factor.blogspot.fr/2009/11/monotonic-timers.html */ 42 | 43 | time = mach_absolute_time(); 44 | 45 | if (scaling_factor == 0) { 46 | ret = (int) mach_timebase_info(&info); 47 | if (ret != 0) { 48 | errno = EAGAIN; 49 | return (-1); 50 | } 51 | scaling_factor = info.numer/info.denom; 52 | } 53 | 54 | time *= scaling_factor; 55 | 56 | tp->tv_sec = time / 1000000000; 57 | tp->tv_nsec = time % 1000000000; 58 | 59 | return (ret); 60 | } 61 | #endif 62 | -------------------------------------------------------------------------------- /openbsd-compat/explicit_bzero.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: explicit_bzero.c,v 1.4 2015/08/31 02:53:57 guenther Exp $ */ 2 | /* 3 | * Public domain. 4 | * Written by Matthew Dempsky. 5 | */ 6 | 7 | #include "includes.h" 8 | #ifndef HAVE_EXPLICIT_BZERO 9 | 10 | #include 11 | 12 | void 13 | explicit_bzero(void *buf, size_t len) 14 | { 15 | memset(buf, 0, len); 16 | } 17 | #endif 18 | -------------------------------------------------------------------------------- /openbsd-compat/fgetln.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015 Joerg Jung 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | /* 18 | * portable fgetln() version, NOT reentrant 19 | */ 20 | 21 | #include "includes.h" 22 | 23 | #ifndef HAVE_FGETLN 24 | #include 25 | #include 26 | #include 27 | 28 | char * 29 | fgetln(FILE *fp, size_t *len) 30 | { 31 | static char *buf = NULL; 32 | static size_t bufsz = 0; 33 | size_t r = 0; 34 | char *p; 35 | int c, e; 36 | 37 | if (buf == NULL) { 38 | if ((buf = calloc(1, BUFSIZ)) == NULL) 39 | return NULL; 40 | bufsz = BUFSIZ; 41 | } 42 | 43 | while ((c = getc(fp)) != EOF) { 44 | buf[r++] = c; 45 | if (r == bufsz) { 46 | if (!(p = reallocarray(buf, 2, bufsz))) { 47 | e = errno; 48 | free(buf); 49 | errno = e; 50 | buf = NULL, bufsz = 0; 51 | return NULL; 52 | } 53 | buf = p, bufsz = 2 * bufsz; 54 | } 55 | if (c == '\n') 56 | break; 57 | } 58 | return (*len = r) ? buf : NULL; 59 | } 60 | #endif /* !HAVE_FGETLN */ 61 | -------------------------------------------------------------------------------- /openbsd-compat/include-config: -------------------------------------------------------------------------------- 1 | #/bin/sh 2 | 3 | set -e 4 | SRCDIR=$1 5 | shift 6 | DSTDIR=. 7 | 8 | SRC=${SRCDIR}/openbsd-compat/includes 9 | DST=${DSTDIR}/openbsd-compat/include 10 | 11 | awk '/^#define /{print $2 "=" $3, $4, $5, $6, $7}' config.h > config.rc 12 | . ./config.rc 13 | 14 | copy_header() 15 | { 16 | local F=$1; 17 | 18 | echo copying $F... 19 | mkdir -p ${DST}/$(dirname $F) 20 | cp ${SRC}/$F ${DST}/$F 21 | } 22 | 23 | copy_missing_header() 24 | { 25 | local F=$1; 26 | local V=$2; 27 | local D=$(eval echo $"$V") 28 | 29 | if [ -z ${D} ]; then 30 | copy_header $F 31 | fi; 32 | } 33 | 34 | copy_header includes.h 35 | copy_header compat-resolv.h 36 | copy_header compat-socket.h 37 | copy_header compat-stdio.h 38 | copy_header compat-stdlib.h 39 | copy_header compat-string.h 40 | copy_header compat-time.h 41 | 42 | copy_missing_header sys/queue.h HAVE_SYS_QUEUE_H 43 | copy_missing_header sys/tree.h HAVE_SYS_TREE_H 44 | -------------------------------------------------------------------------------- /openbsd-compat/includes/compat-resolv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Eric Faurot 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef HAVE_RES_HNOK 18 | int 19 | res_hnok(const char *); 20 | #endif 21 | 22 | #ifndef HAVE_RES_RANDDOMID 23 | unsigned int 24 | res_randomid(void); 25 | #endif 26 | 27 | #ifndef MAXDNAME 28 | #define MAXDNAME 1025 29 | #endif 30 | -------------------------------------------------------------------------------- /openbsd-compat/includes/compat-socket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Eric Faurot 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef SA_LEN 18 | # if defined(HAVE_STRUCT_SOCKADDR_SA_LEN) 19 | # define SA_LEN(x) ((x)->sa_len) 20 | # else 21 | # define SA_LEN(x) ((x)->sa_family == AF_INET6 ? \ 22 | sizeof(struct sockaddr_in6) : \ 23 | sizeof(struct sockaddr_in)) 24 | # endif 25 | #endif 26 | 27 | #ifndef SS_LEN 28 | # if defined(HAVE_STRUCT_SOCKADDR_SS_LEN) 29 | # define SS_LEN(x) ((x)->ss_len) 30 | # else 31 | # define SS_LEN(x) ((x)->ss_family == AF_INET6 ? \ 32 | sizeof(struct sockaddr_in6) : \ 33 | sizeof(struct sockaddr_in)) 34 | # endif 35 | #endif 36 | -------------------------------------------------------------------------------- /openbsd-compat/includes/compat-stdio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Eric Faurot 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef HAVE_FGETLN 18 | char * fgetln(FILE *stream, size_t *len); 19 | #endif 20 | -------------------------------------------------------------------------------- /openbsd-compat/includes/compat-stdlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Eric Faurot 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef HAVE_FREEZERO 18 | void freezero(void *ptr, size_t size); 19 | #endif 20 | 21 | #ifndef HAVE_REALLOCARRAY 22 | void *reallocarray(void *, size_t, size_t); 23 | #endif 24 | 25 | #ifndef HAVE_RECALLOCARRAY 26 | void *recallocarray(void *, size_t, size_t, size_t); 27 | #endif 28 | 29 | #ifndef HAVE_STRTONUM 30 | long long strtonum(const char *nptr, long long minval, long long maxval, 31 | const char **errstr); 32 | #endif 33 | -------------------------------------------------------------------------------- /openbsd-compat/includes/compat-string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Eric Faurot 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef HAVE_EXPLICIT_BZERO 18 | void explicit_bzero(void *p, size_t n); 19 | #endif 20 | 21 | #ifndef HAVE_STRLCPY 22 | size_t strlcpy(char *dst, const char *src, size_t size); 23 | #endif 24 | 25 | #ifndef HAVE_STRLCAT 26 | size_t strlcat(char *dst, const char *src, size_t size); 27 | #endif 28 | 29 | #ifndef HAVE_STRSEP 30 | char *strsep(char **stringp, const char *delim); 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /openbsd-compat/includes/compat-time.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Eric Faurot 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef timersub 18 | #define timersub(a, b, result) \ 19 | do { \ 20 | (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ 21 | (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ 22 | if ((result)->tv_usec < 0) { \ 23 | --(result)->tv_sec; \ 24 | (result)->tv_usec += 1000000; \ 25 | } \ 26 | } while (0) 27 | #endif 28 | 29 | #ifndef timespeccmp 30 | #define timespeccmp(a, b, cmp) \ 31 | (((a)->tv_sec == (b)->tv_sec) ? \ 32 | ((a)->tv_nsec cmp (b)->tv_nsec) : \ 33 | ((a)->tv_sec cmp (b)->tv_sec)) 34 | #endif 35 | 36 | #ifndef timespecsub 37 | #define timespecsub(a, b, result) \ 38 | do { \ 39 | (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ 40 | (result)->tv_nsec = (a)->tv_nsec - (b)->tv_nsec; \ 41 | if ((result)->tv_nsec < 0) { \ 42 | --(result)->tv_sec; \ 43 | (result)->tv_nsec += 1000000000L; \ 44 | } \ 45 | } while (0) 46 | #endif 47 | 48 | 49 | #ifndef HAVE_CLOCK_GETTIME 50 | int clock_gettime(clockid_t clk_id, struct timespec *tp); 51 | #endif 52 | -------------------------------------------------------------------------------- /openbsd-compat/includes/includes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Eric Faurot 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef INCLUDES_H 18 | #define INCLUDES_H 19 | 20 | #include "config.h" 21 | 22 | #define _GNU_SOURCE 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "compat-resolv.h" 30 | #include "compat-socket.h" 31 | #include "compat-stdio.h" 32 | #include "compat-stdlib.h" 33 | #include "compat-string.h" 34 | #include "compat-time.h" 35 | 36 | #endif /* INCLUDES_H */ 37 | -------------------------------------------------------------------------------- /openbsd-compat/reallocarray.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: reallocarray.c,v 1.1 2014/05/08 21:43:49 deraadt Exp $ */ 2 | /* 3 | * Copyright (c) 2008 Otto Moerbeek 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | /* OPENBSD ORIGINAL: lib/libc/stdlib/reallocarray.c */ 19 | 20 | #include "includes.h" 21 | 22 | #ifndef HAVE_REALLOCARRAY 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | /* 30 | * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX 31 | * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW 32 | */ 33 | #define MUL_NO_OVERFLOW (1UL << (sizeof(size_t) * 4)) 34 | 35 | void * 36 | reallocarray(void *optr, size_t nmemb, size_t size) 37 | { 38 | if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && 39 | nmemb > 0 && SIZE_MAX / nmemb < size) { 40 | errno = ENOMEM; 41 | return NULL; 42 | } 43 | return realloc(optr, size * nmemb); 44 | } 45 | 46 | #endif /* !HAVE_REALLOCARRAY */ 47 | -------------------------------------------------------------------------------- /openbsd-compat/recallocarray.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: recallocarray.c,v 1.1 2017/03/06 18:44:21 otto Exp $ */ 2 | /* 3 | * Copyright (c) 2008, 2017 Otto Moerbeek 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | /* OPENBSD ORIGINAL: lib/libc/stdlib/recallocarray.c */ 19 | 20 | #include "includes.h" 21 | 22 | #ifndef HAVE_RECALLOCARRAY 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | /* 31 | * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX 32 | * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW 33 | */ 34 | #define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4)) 35 | 36 | void * 37 | recallocarray(void *ptr, size_t oldnmemb, size_t newnmemb, size_t size) 38 | { 39 | size_t oldsize, newsize; 40 | void *newptr; 41 | 42 | if (ptr == NULL) 43 | return calloc(newnmemb, size); 44 | 45 | if ((newnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && 46 | newnmemb > 0 && SIZE_MAX / newnmemb < size) { 47 | errno = ENOMEM; 48 | return NULL; 49 | } 50 | newsize = newnmemb * size; 51 | 52 | if ((oldnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && 53 | oldnmemb > 0 && SIZE_MAX / oldnmemb < size) { 54 | errno = EINVAL; 55 | return NULL; 56 | } 57 | oldsize = oldnmemb * size; 58 | 59 | /* 60 | * Don't bother too much if we're shrinking just a bit, 61 | * we do not shrink for series of small steps, oh well. 62 | */ 63 | if (newsize <= oldsize) { 64 | size_t d = oldsize - newsize; 65 | 66 | if (d < oldsize / 2 && d < getpagesize()) { 67 | memset((char *)ptr + newsize, 0, d); 68 | return ptr; 69 | } 70 | } 71 | 72 | newptr = malloc(newsize); 73 | if (newptr == NULL) 74 | return NULL; 75 | 76 | if (newsize > oldsize) { 77 | memcpy(newptr, ptr, oldsize); 78 | memset((char *)newptr + oldsize, 0, newsize - oldsize); 79 | } else 80 | memcpy(newptr, ptr, newsize); 81 | 82 | explicit_bzero(ptr, oldsize); 83 | free(ptr); 84 | 85 | return newptr; 86 | } 87 | 88 | #endif /* !HAVE_RECALLOCARRAY */ 89 | -------------------------------------------------------------------------------- /openbsd-compat/res_hnok.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: res_comp.c,v 1.14 2008/04/16 22:35:23 deraadt Exp $ */ 2 | 3 | /* 4 | * ++Copyright++ 1985, 1993 5 | * - 6 | * Copyright (c) 1985, 1993 7 | * The Regents of the University of California. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 3. Neither the name of the University nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | * - 33 | * Portions Copyright (c) 1993 by Digital Equipment Corporation. 34 | * 35 | * Permission to use, copy, modify, and distribute this software for any 36 | * purpose with or without fee is hereby granted, provided that the above 37 | * copyright notice and this permission notice appear in all copies, and that 38 | * the name of Digital Equipment Corporation not be used in advertising or 39 | * publicity pertaining to distribution of the document or software without 40 | * specific, written prior permission. 41 | * 42 | * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL 43 | * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 44 | * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT 45 | * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 46 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 47 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 48 | * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 49 | * SOFTWARE. 50 | * - 51 | * --Copyright-- 52 | */ 53 | 54 | /* OPENBSD ORIGINAL: lib/libc/net/res_comp.c */ 55 | 56 | #include "includes.h" 57 | #ifndef HAVE_RES_HNOK 58 | 59 | /* 60 | * Verify that a domain name uses an acceptable character set. 61 | */ 62 | 63 | /* 64 | * Note the conspicuous absence of ctype macros in these definitions. On 65 | * non-ASCII hosts, we can't depend on string literals or ctype macros to 66 | * tell us anything about network-format data. The rest of the BIND system 67 | * is not careful about this, but for some reason, we're doing it right here. 68 | */ 69 | #define PERIOD 0x2e 70 | #define hyphenchar(c) ((c) == 0x2d) 71 | #define bslashchar(c) ((c) == 0x5c) 72 | #define underscorechar(c) ((c) == 0x5f) 73 | #define periodchar(c) ((c) == PERIOD) 74 | #define asterchar(c) ((c) == 0x2a) 75 | #define alphachar(c) (((c) >= 0x41 && (c) <= 0x5a) \ 76 | || ((c) >= 0x61 && (c) <= 0x7a)) 77 | #define digitchar(c) ((c) >= 0x30 && (c) <= 0x39) 78 | 79 | #define borderchar(c) (alphachar(c) || digitchar(c)) 80 | #define middlechar(c) (borderchar(c) || hyphenchar(c) || underscorechar(c)) 81 | #define domainchar(c) ((c) > 0x20 && (c) < 0x7f) 82 | 83 | int 84 | res_hnok(const char *dn) 85 | { 86 | int pch = PERIOD, ch = *dn++; 87 | 88 | while (ch != '\0') { 89 | int nch = *dn++; 90 | 91 | if (periodchar(ch)) { 92 | ; 93 | } else if (periodchar(pch)) { 94 | if (!borderchar(ch)) 95 | return (0); 96 | } else if (periodchar(nch) || nch == '\0') { 97 | if (!borderchar(ch)) 98 | return (0); 99 | } else { 100 | if (!middlechar(ch)) 101 | return (0); 102 | } 103 | pch = ch, ch = nch; 104 | } 105 | return (1); 106 | } 107 | 108 | #if 0 109 | 110 | /* 111 | * hostname-like (A, MX, WKS) owners can have "*" as their first label 112 | * but must otherwise be as a host name. 113 | */ 114 | int 115 | res_ownok(const char *dn) 116 | { 117 | if (asterchar(dn[0])) { 118 | if (periodchar(dn[1])) 119 | return (res_hnok(dn+2)); 120 | if (dn[1] == '\0') 121 | return (1); 122 | } 123 | return (res_hnok(dn)); 124 | } 125 | 126 | /* 127 | * SOA RNAMEs and RP RNAMEs can have any printable character in their first 128 | * label, but the rest of the name has to look like a host name. 129 | */ 130 | int 131 | res_mailok(const char *dn) 132 | { 133 | int ch, escaped = 0; 134 | 135 | /* "." is a valid missing representation */ 136 | if (*dn == '\0') 137 | return(1); 138 | 139 | /* otherwise