Importing OpenNTPD 3.9p1
This commit is contained in:
parent
70fd8dc785
commit
449c9b45bf
|
|
@ -3664,6 +3664,7 @@
|
|||
./usr/man/man5/man.conf.5 minix-sys
|
||||
./usr/man/man5 minix-sys
|
||||
./usr/man/man5/mtree.5 minix-sys
|
||||
./usr/man/man5/ntpd.conf.5 minix-sys
|
||||
./usr/man/man5/passwd.5 minix-sys
|
||||
./usr/man/man5/pkg_install.conf.5 minix-sys
|
||||
./usr/man/man5/pkg_summary.5 minix-sys
|
||||
|
|
@ -3742,6 +3743,7 @@
|
|||
./usr/man/man8/newfs_ext2fs.8 minix-sys
|
||||
./usr/man/man8/newroot.8 minix-sys
|
||||
./usr/man/man8/nonamed.8 minix-sys
|
||||
./usr/man/man8/ntpd.8 minix-sys
|
||||
./usr/man/man8/ossdevlinks.8 minix-sys
|
||||
./usr/man/man8/part.8 minix-sys
|
||||
./usr/man/man8/partition.8 minix-sys
|
||||
|
|
@ -3813,6 +3815,7 @@
|
|||
./usr/sbin/mkproto minix-sys
|
||||
./usr/sbin/mmc minix-sys
|
||||
./usr/sbin/mtree minix-sys
|
||||
./usr/sbin/ntpd minix-sys
|
||||
./usr/sbin/pfs minix-sys
|
||||
./usr/sbin/pm minix-sys
|
||||
./usr/sbin/postinstall minix-sys
|
||||
|
|
|
|||
2
external/bsd/Makefile
vendored
2
external/bsd/Makefile
vendored
|
|
@ -3,7 +3,7 @@
|
|||
.include <bsd.own.mk>
|
||||
|
||||
SUBDIR= byacc file flex mdocml \
|
||||
libarchive
|
||||
libarchive openntpd
|
||||
.if (${MKATF} != "no")
|
||||
SUBDIR+= atf
|
||||
.endif
|
||||
|
|
|
|||
3
external/bsd/openntpd/Makefile
vendored
Normal file
3
external/bsd/openntpd/Makefile
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
.include <bsd.own.mk>
|
||||
SUBDIR= lib sbin
|
||||
.include <bsd.subdir.mk>
|
||||
2
external/bsd/openntpd/Makefile.inc
vendored
Normal file
2
external/bsd/openntpd/Makefile.inc
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
OPENNTPD_DISTDIR= ${NETBSDSRCDIR}/external/bsd/openntpd/dist
|
||||
.PATH: ${OPENNTPD_DISTDIR}
|
||||
13
external/bsd/openntpd/dist/.cvsignore
vendored
Normal file
13
external/bsd/openntpd/dist/.cvsignore
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
Makefile
|
||||
configure
|
||||
config.h
|
||||
config.h.in
|
||||
config.log
|
||||
config.status
|
||||
autom4te.cache
|
||||
ntpd-vs-openbsd.diff
|
||||
ntpd
|
||||
ntpd.0
|
||||
ntpd.conf.0
|
||||
ntpd.8.out
|
||||
ntpd.conf.5.out
|
||||
8
external/bsd/openntpd/dist/CREDITS
vendored
Normal file
8
external/bsd/openntpd/dist/CREDITS
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
This is a port of OpenBSD's native ntpd, written by Henning Brauer and
|
||||
Alexander Guy. The portability layer is based heavily on Portable OpenSSH.
|
||||
|
||||
naddy at mips.inka.de: FreeBSD build fixes.
|
||||
Jason Mader (jason at ncac gwu edu): IRIX build fixes.
|
||||
Anthony O.Zabelin. (rza1 at mail ru): QNX4 support.
|
||||
|
||||
$Id: CREDITS,v 1.4 2005/05/28 05:16:34 dtucker Exp $
|
||||
1120
external/bsd/openntpd/dist/ChangeLog
vendored
Normal file
1120
external/bsd/openntpd/dist/ChangeLog
vendored
Normal file
File diff suppressed because it is too large
Load Diff
116
external/bsd/openntpd/dist/INSTALL
vendored
Normal file
116
external/bsd/openntpd/dist/INSTALL
vendored
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
1. Prerequisites
|
||||
----------------
|
||||
|
||||
You will need an entropy (randomness) source. If your OS has a /dev/random
|
||||
/dev/urandom or /dev/arandom then that is ideal.
|
||||
|
||||
If you do not have a real random device, Lutz Jaenicke's PRNGd is recommended.
|
||||
http://www.aet.tu-cottbus.de/personen/jaenicke/postfix_tls/prngd.html
|
||||
|
||||
Alternatively, EGD should also work (currently untested):
|
||||
http://www.lothar.com/tech/crypto/
|
||||
|
||||
If you are not using the builtin arc4random code (see
|
||||
--with-builtin-arc4random below) then OpenSSL 0.9.6 or greater is required:
|
||||
http://www.openssl.org/
|
||||
|
||||
|
||||
2. Building / Installation
|
||||
--------------------------
|
||||
|
||||
To install OpenNTPD with default options:
|
||||
|
||||
./configure
|
||||
make
|
||||
make install
|
||||
|
||||
This will install the OpenNTPD binary in /usr/local/sbin, configuration
|
||||
files in /usr/local/etc. To specify a different installation prefix,
|
||||
use the --prefix option to configure:
|
||||
|
||||
./configure --prefix=/opt
|
||||
make
|
||||
make install
|
||||
|
||||
Will install OpenNTPD in /opt/{etc,sbin}. You can also override
|
||||
specific paths, for example:
|
||||
|
||||
./configure --prefix=/opt --sysconfdir=/etc/ntp
|
||||
make
|
||||
make install
|
||||
|
||||
This will install the binaries in /opt/sbin, but will place the
|
||||
configuration files in /etc/ntp.
|
||||
|
||||
OpenNTPD always uses Privilege Separation (ie the majority of the
|
||||
processing is done as a chroot'ed, unprivileged user).
|
||||
|
||||
This requires that a user, group and directory to be created for it.
|
||||
The user should not be permitted to log in, and its home directory
|
||||
should be owned by root and be mode 755.
|
||||
|
||||
If you do "make install", the Makefile will create the directory with
|
||||
the correct permissions and will prompt you for the rest if required.
|
||||
If, however, you need to perform all of these tasks yourself (eg if you
|
||||
are moving the built binaries to another system) then you will need to
|
||||
do something like the following (although the exact commands required
|
||||
for creating the user and group are system dependant):
|
||||
|
||||
# groupadd _ntp
|
||||
# useradd -g _ntp -s /sbin/nologin -d /var/empty/ntp -c 'OpenNTP daemon' _ntp
|
||||
# mkdir -p /var/empty/ntp
|
||||
# chown 0 /var/empty/ntp
|
||||
# chgrp 0 /var/empty/ntp
|
||||
# chmod 0755 /var/empty/ntp
|
||||
|
||||
There are a few options to the configure script in addition to the ones
|
||||
provided by autoconf itself:
|
||||
|
||||
--with-privsep-user=[user]
|
||||
Specify unprivileged user used for privilege separation. The default
|
||||
is "_ntp".
|
||||
|
||||
--with-privsep-path=path
|
||||
Normally ntpd will always use the home directory of the privsep user
|
||||
to chroot to, however use of this option will cause ntpd to always
|
||||
use the specified directory.
|
||||
|
||||
--with-mantype=man|cat|doc
|
||||
Set man page type. The default is for configure to automatically
|
||||
detect the supported format.
|
||||
|
||||
--with-builtin-arc4random
|
||||
Use builtin arc4random rather than OpenSSL's. By default, OpenSSL
|
||||
will be used if found.
|
||||
|
||||
--with-ssl-dir=PATH
|
||||
Specify path to OpenSSL installation to use if not using the
|
||||
system's default or the builtin arc4random support.
|
||||
|
||||
|
||||
If you need to pass special options to the compiler or linker, you
|
||||
can specify these as environment variables before running ./configure.
|
||||
For example:
|
||||
|
||||
CFLAGS="-O -m486" LDFLAGS="-s" LIBS="-lrubbish" LD="/usr/foo/ld" ./configure
|
||||
|
||||
|
||||
3. Configuration
|
||||
----------------
|
||||
|
||||
The runtime configuration files are installed by in ${prefix}/etc or
|
||||
whatever you specified as your --sysconfdir (/usr/local/etc by default).
|
||||
|
||||
If no configuration file exists, the default one is used. The default
|
||||
configuration file uses a selection of publicly accessible "pool" servers
|
||||
(see http://twiki.ntp.org/bin/view/Servers/NTPPoolServers).
|
||||
|
||||
|
||||
4. Problems?
|
||||
------------
|
||||
|
||||
If you experience problems compiling, installing or running OpenNTPD,
|
||||
please report the problem to the address in the README file.
|
||||
|
||||
|
||||
$Id: INSTALL,v 1.6 2006/01/19 06:41:50 dtucker Exp $
|
||||
103
external/bsd/openntpd/dist/LICENCE
vendored
Normal file
103
external/bsd/openntpd/dist/LICENCE
vendored
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
This is a summary of the licences for the files that make up Portable
|
||||
OpenNTPD.
|
||||
|
||||
Apart from the exceptions listed below, all of the files are under an
|
||||
ISC-style licence with the following copyright holders, first for the
|
||||
files from OpenBSD's ntpd:
|
||||
|
||||
Henning Brauer
|
||||
Alexander Guy
|
||||
|
||||
and the portability layer:
|
||||
|
||||
Darren Tucker
|
||||
Damien Miller
|
||||
Internet Software Consortium
|
||||
Todd C. Miller
|
||||
Anthony O.Zabelin
|
||||
|
||||
/*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, 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.
|
||||
*/
|
||||
|
||||
Specific parts of the portability layer have the following licences.
|
||||
|
||||
bsd-snprintf.c is from OpenSSH and has the following licence:
|
||||
/*
|
||||
* Copyright Patrick Powell 1995
|
||||
* This code is based on code written by Patrick Powell
|
||||
* (papowell@astart.com) It may be used for any purpose as long as this
|
||||
* notice remains intact on all source code distributions
|
||||
*/
|
||||
|
||||
The following files are from OpenSSH or OpenBSD and are under a 2-term
|
||||
BSD license with the noted copyright holders:
|
||||
|
||||
atomicio.c: Theo de Raadt, Anil Madhavapeddy
|
||||
atomicio.h, bsd-poll.h: Theo de Raadt
|
||||
|
||||
/*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 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.
|
||||
*/
|
||||
|
||||
The following files are from OpenSSH and are under a 3-term BSD license
|
||||
with the noted copyright holders:
|
||||
|
||||
fake-rfc2553.c, fake-rfc2553.h: WIDE Project, Damien Miller.
|
||||
daemon.c, sys-queue.h: The Regents of the University of California
|
||||
|
||||
/*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* 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.
|
||||
*/
|
||||
|
||||
$Id: LICENCE,v 1.6 2005/07/03 14:02:40 dtucker Exp $
|
||||
137
external/bsd/openntpd/dist/Makefile
vendored
Normal file
137
external/bsd/openntpd/dist/Makefile
vendored
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
# $OpenBSD: Makefile,v 1.7 2004/07/04 11:01:49 alexander Exp $
|
||||
# $Id: Makefile.in,v 1.34 2006/01/19 07:16:44 dtucker Exp $
|
||||
|
||||
prefix=/usr
|
||||
exec_prefix=${prefix}
|
||||
bindir=${exec_prefix}/bin
|
||||
sbindir=${exec_prefix}/sbin
|
||||
libexecdir=${exec_prefix}/libexec
|
||||
datadir=${prefix}/share
|
||||
mandir=${prefix}/man
|
||||
mansubdir=cat
|
||||
sysconfdir=${prefix}/etc
|
||||
srcdir=.
|
||||
top_srcdir=.
|
||||
|
||||
DESTDIR=
|
||||
|
||||
CC=gcc
|
||||
CFLAGS=-g -O2 -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual -Wsign-compare
|
||||
CPPFLAGS=-I. -I$(srcdir) $(PATHS)
|
||||
LIBS=
|
||||
LDFLAGS=
|
||||
AWK= awk
|
||||
YACC= yacc
|
||||
|
||||
INSTALL=/usr/bin/install -c
|
||||
|
||||
PATHS= -DSYSCONFDIR=\"$(sysconfdir)\"
|
||||
PRIVSEP_USER=_ntp
|
||||
PRIVSEP_PATH=/var/empty
|
||||
STRIP_OPT=-s
|
||||
|
||||
PROG= ntpd
|
||||
LIBCOMPAT=openbsd-compat/libopenbsd-compat.a
|
||||
SRCS= ntpd.c buffer.c log.c imsg.c ntp.c ntp_msg.c config.c \
|
||||
server.c client.c util.c y.tab.c
|
||||
OBJS= ntpd.o buffer.o log.o imsg.o ntp.o ntp_msg.o config.o \
|
||||
server.o client.o util.o y.tab.o
|
||||
YFLAGS=
|
||||
MANPAGES_IN= ntpd.8 ntpd.conf.5
|
||||
MANPAGES= ntpd.8.out ntpd.conf.5.out
|
||||
MANTYPE= cat
|
||||
|
||||
all: ntpd $(MANPAGES)
|
||||
|
||||
$(LIBCOMPAT): config.h $(top_srcdir)/openbsd-compat/*.c \
|
||||
$(top_srcdir)/openbsd-compat/*.h
|
||||
(cd openbsd-compat && $(MAKE))
|
||||
|
||||
$(OBJS): config.h
|
||||
|
||||
PATHSUBS = -e 's|/etc/ntpd.conf|$(sysconfdir)/ntpd.conf|g'
|
||||
|
||||
ntpd.8.out: $(top_srcdir)/ntpd.8
|
||||
$(AWK) -f $(srcdir)/mdoc2man.awk $(top_srcdir)/ntpd.8 | \
|
||||
sed $(PATHSUBS) > ntpd.8.out || rm -f ntpd.8.out
|
||||
|
||||
ntpd.conf.5.out: $(top_srcdir)/ntpd.conf.5
|
||||
$(AWK) -f $(srcdir)/mdoc2man.awk $(top_srcdir)/ntpd.conf.5 | \
|
||||
sed $(PATHSUBS) > ntpd.conf.5.out || rm -f ntpd.8.out
|
||||
|
||||
catman-do: $(MANPAGES_IN)
|
||||
nroff -mandoc ntpd.8 |cat -v | sed -e 's/.\^H//g' > ntpd.0
|
||||
nroff -mandoc ntpd.conf.5 | cat -v | sed -e 's/.\^H//g' > ntpd.conf.0
|
||||
|
||||
ntpd: ntpd.o buffer.o log.o imsg.o ntp.o ntp_msg.o config.o \
|
||||
server.o client.o util.o y.tab.o $(LIBCOMPAT)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o ntpd $(OBJS) $(LIBCOMPAT) $(LIBS)
|
||||
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -c $<
|
||||
|
||||
y.tab.c: $(top_srcdir)/parse.y
|
||||
$(YACC) $(top_srcdir)/parse.y
|
||||
|
||||
install: ntpd $(MANOUT)
|
||||
@if [ ! -d $(DESTDIR)$(sbindir) ]; then \
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(sbindir); \
|
||||
fi
|
||||
@if [ ! -d $(DESTDIR)$(sysconfdir) ]; then \
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(sysconfdir); \
|
||||
fi
|
||||
@if [ ! -d $(DESTDIR)$(mandir)/$(mansubdir)5 ]; then \
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/$(mansubdir)5; \
|
||||
fi
|
||||
@if [ ! -d $(DESTDIR)$(mandir)/$(mansubdir)8 ]; then \
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/$(mansubdir)8; \
|
||||
fi
|
||||
$(INSTALL) -m 0755 $(STRIP_OPT) ntpd $(DESTDIR)$(sbindir)/ntpd
|
||||
$(INSTALL) -m 644 ntpd.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/ntpd.8
|
||||
$(INSTALL) -m 644 ntpd.conf.5.out $(DESTDIR)$(mandir)/$(mansubdir)5/ntpd.conf.5
|
||||
@if [ ! -d $(DESTDIR)$(sysconfdir) ]; then \
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(sysconfdir); \
|
||||
fi
|
||||
@if [ ! -f $(DESTDIR)$(sysconfdir)/ntpd.conf ]; then \
|
||||
$(INSTALL) -m 644 $(srcdir)/ntpd.conf $(DESTDIR)$(sysconfdir)/ntpd.conf; \
|
||||
else \
|
||||
echo "$(DESTDIR)$(sysconfdir)/ntpd.conf already exists, install will not overwrite"; \
|
||||
fi
|
||||
@if [ ! -d $(DESTDIR)$(PRIVSEP_PATH) ]; then \
|
||||
mkdir -p $(DESTDIR)$(PRIVSEP_PATH) ;\
|
||||
chown 0 $(DESTDIR)$(PRIVSEP_PATH) ; \
|
||||
chgrp 0 $(DESTDIR)$(PRIVSEP_PATH) ; \
|
||||
chmod 0755 $(DESTDIR)$(PRIVSEP_PATH) ; \
|
||||
fi
|
||||
@if egrep "^$(PRIVSEP_USER):" /etc/group >/dev/null; then \
|
||||
: ;\
|
||||
else \
|
||||
echo "Please create a dedicated group for ntpd." ;\
|
||||
echo "This is system-dependant, possibly:" ;\
|
||||
echo "# groupadd $(PRIVSEP_USER)" ;\
|
||||
fi
|
||||
@if egrep "^$(PRIVSEP_USER):" /etc/passwd >/dev/null; then \
|
||||
: ;\
|
||||
else \
|
||||
echo "Please create a dedicated user for ntpd and ensure it can" ;\
|
||||
echo "not be used to log in. This is system-dependant, possibly:" ;\
|
||||
echo "# useradd -g $(PRIVSEP_USER) -s /sbin/nologin -d $(PRIVSEP_PATH) -c 'OpenNTP daemon' $(PRIVSEP_USER)" ;\
|
||||
fi
|
||||
|
||||
diff:
|
||||
-diff -x CVS -x Makefile -ru /usr/src/usr.sbin/ntpd ./ | \
|
||||
egrep -v "^Only in" >ntpd-vs-openbsd.diff
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) ntpd openbsd-compat/*.o openbsd-compat/*.a \
|
||||
configure.lineno config.h.in~ $(MANPAGES)
|
||||
|
||||
distclean: clean
|
||||
rm -rf config.log config.status configure.lineno \
|
||||
config.h Makefile openbsd-compat/Makefile ntpd.0 ntpd.conf.0
|
||||
|
||||
distprep: distclean catman-do
|
||||
autoheader
|
||||
autoreconf
|
||||
test y.tab.c -nt parse.y || yacc parse.y
|
||||
rm -rf Makefile openbsd-compat/Makefile autom4te.cache
|
||||
137
external/bsd/openntpd/dist/Makefile.in
vendored
Normal file
137
external/bsd/openntpd/dist/Makefile.in
vendored
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
# $OpenBSD: Makefile,v 1.7 2004/07/04 11:01:49 alexander Exp $
|
||||
# $Id: Makefile.in,v 1.34 2006/01/19 07:16:44 dtucker Exp $
|
||||
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
bindir=@bindir@
|
||||
sbindir=@sbindir@
|
||||
libexecdir=@libexecdir@
|
||||
datadir=@datadir@
|
||||
mandir=@mandir@
|
||||
mansubdir=@mansubdir@
|
||||
sysconfdir=@sysconfdir@
|
||||
srcdir=@srcdir@
|
||||
top_srcdir=@top_srcdir@
|
||||
|
||||
DESTDIR=
|
||||
VPATH=@srcdir@
|
||||
CC=@CC@
|
||||
CFLAGS=@CFLAGS@
|
||||
CPPFLAGS=-I. -I$(srcdir) @CPPFLAGS@ $(PATHS)
|
||||
LIBS= @LIBS@
|
||||
LDFLAGS=@LDFLAGS@
|
||||
AWK= @AWK@
|
||||
YACC= @YACC@
|
||||
|
||||
INSTALL=@INSTALL@
|
||||
|
||||
PATHS= -DSYSCONFDIR=\"$(sysconfdir)\"
|
||||
PRIVSEP_USER=@privsep_user@
|
||||
PRIVSEP_PATH=@privsep_path@
|
||||
STRIP_OPT=@STRIP_OPT@
|
||||
|
||||
PROG= ntpd
|
||||
LIBCOMPAT=openbsd-compat/libopenbsd-compat.a
|
||||
SRCS= ntpd.c buffer.c log.c imsg.c ntp.c ntp_msg.c config.c \
|
||||
server.c client.c util.c y.tab.c
|
||||
OBJS= ntpd.o buffer.o log.o imsg.o ntp.o ntp_msg.o config.o \
|
||||
server.o client.o util.o y.tab.o
|
||||
YFLAGS=
|
||||
MANPAGES_IN= ntpd.8 ntpd.conf.5
|
||||
MANPAGES= ntpd.8.out ntpd.conf.5.out
|
||||
MANTYPE= @MANTYPE@
|
||||
|
||||
all: ntpd $(MANPAGES)
|
||||
|
||||
$(LIBCOMPAT): config.h $(top_srcdir)/openbsd-compat/*.c \
|
||||
$(top_srcdir)/openbsd-compat/*.h
|
||||
(cd openbsd-compat && $(MAKE))
|
||||
|
||||
$(OBJS): config.h
|
||||
|
||||
PATHSUBS = -e 's|/etc/ntpd.conf|$(sysconfdir)/ntpd.conf|g'
|
||||
|
||||
ntpd.8.out: $(top_srcdir)/ntpd.8
|
||||
$(AWK) -f $(srcdir)/mdoc2man.awk $(top_srcdir)/ntpd.8 | \
|
||||
sed $(PATHSUBS) > ntpd.8.out || rm -f ntpd.8.out
|
||||
|
||||
ntpd.conf.5.out: $(top_srcdir)/ntpd.conf.5
|
||||
$(AWK) -f $(srcdir)/mdoc2man.awk $(top_srcdir)/ntpd.conf.5 | \
|
||||
sed $(PATHSUBS) > ntpd.conf.5.out || rm -f ntpd.8.out
|
||||
|
||||
catman-do: $(MANPAGES_IN)
|
||||
nroff -mandoc ntpd.8 |cat -v | sed -e 's/.\^H//g' > ntpd.0
|
||||
nroff -mandoc ntpd.conf.5 | cat -v | sed -e 's/.\^H//g' > ntpd.conf.0
|
||||
|
||||
ntpd: ntpd.o buffer.o log.o imsg.o ntp.o ntp_msg.o config.o \
|
||||
server.o client.o util.o y.tab.o $(LIBCOMPAT)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o ntpd $(OBJS) $(LIBCOMPAT) $(LIBS)
|
||||
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -c $<
|
||||
|
||||
y.tab.c: $(top_srcdir)/parse.y
|
||||
$(YACC) $(top_srcdir)/parse.y
|
||||
|
||||
install: ntpd $(MANOUT)
|
||||
@if [ ! -d $(DESTDIR)$(sbindir) ]; then \
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(sbindir); \
|
||||
fi
|
||||
@if [ ! -d $(DESTDIR)$(sysconfdir) ]; then \
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(sysconfdir); \
|
||||
fi
|
||||
@if [ ! -d $(DESTDIR)$(mandir)/$(mansubdir)5 ]; then \
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/$(mansubdir)5; \
|
||||
fi
|
||||
@if [ ! -d $(DESTDIR)$(mandir)/$(mansubdir)8 ]; then \
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/$(mansubdir)8; \
|
||||
fi
|
||||
$(INSTALL) -m 0755 $(STRIP_OPT) ntpd $(DESTDIR)$(sbindir)/ntpd
|
||||
$(INSTALL) -m 644 ntpd.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/ntpd.8
|
||||
$(INSTALL) -m 644 ntpd.conf.5.out $(DESTDIR)$(mandir)/$(mansubdir)5/ntpd.conf.5
|
||||
@if [ ! -d $(DESTDIR)$(sysconfdir) ]; then \
|
||||
$(INSTALL) -m 755 -d $(DESTDIR)$(sysconfdir); \
|
||||
fi
|
||||
@if [ ! -f $(DESTDIR)$(sysconfdir)/ntpd.conf ]; then \
|
||||
$(INSTALL) -m 644 $(srcdir)/ntpd.conf $(DESTDIR)$(sysconfdir)/ntpd.conf; \
|
||||
else \
|
||||
echo "$(DESTDIR)$(sysconfdir)/ntpd.conf already exists, install will not overwrite"; \
|
||||
fi
|
||||
@if [ ! -d $(DESTDIR)$(PRIVSEP_PATH) ]; then \
|
||||
mkdir -p $(DESTDIR)$(PRIVSEP_PATH) ;\
|
||||
chown 0 $(DESTDIR)$(PRIVSEP_PATH) ; \
|
||||
chgrp 0 $(DESTDIR)$(PRIVSEP_PATH) ; \
|
||||
chmod 0755 $(DESTDIR)$(PRIVSEP_PATH) ; \
|
||||
fi
|
||||
@if egrep "^$(PRIVSEP_USER):" /etc/group >/dev/null; then \
|
||||
: ;\
|
||||
else \
|
||||
echo "Please create a dedicated group for ntpd." ;\
|
||||
echo "This is system-dependant, possibly:" ;\
|
||||
echo "# groupadd $(PRIVSEP_USER)" ;\
|
||||
fi
|
||||
@if egrep "^$(PRIVSEP_USER):" /etc/passwd >/dev/null; then \
|
||||
: ;\
|
||||
else \
|
||||
echo "Please create a dedicated user for ntpd and ensure it can" ;\
|
||||
echo "not be used to log in. This is system-dependant, possibly:" ;\
|
||||
echo "# useradd -g $(PRIVSEP_USER) -s /sbin/nologin -d $(PRIVSEP_PATH) -c 'OpenNTP daemon' $(PRIVSEP_USER)" ;\
|
||||
fi
|
||||
|
||||
diff:
|
||||
-diff -x CVS -x Makefile -ru /usr/src/usr.sbin/ntpd ./ | \
|
||||
egrep -v "^Only in" >ntpd-vs-openbsd.diff
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) ntpd openbsd-compat/*.o openbsd-compat/*.a \
|
||||
configure.lineno config.h.in~ $(MANPAGES)
|
||||
|
||||
distclean: clean
|
||||
rm -rf config.log config.status configure.lineno \
|
||||
config.h Makefile openbsd-compat/Makefile ntpd.0 ntpd.conf.0
|
||||
|
||||
distprep: distclean catman-do
|
||||
autoheader
|
||||
autoreconf
|
||||
test y.tab.c -nt parse.y || yacc parse.y
|
||||
rm -rf Makefile openbsd-compat/Makefile autom4te.cache
|
||||
41
external/bsd/openntpd/dist/README
vendored
Normal file
41
external/bsd/openntpd/dist/README
vendored
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
This is a port of OpenBSD's native ntpd to other Unix flavours adding
|
||||
autoconf support and the necessary compatibility layer. It is strongly
|
||||
influenced by, and based in part on, the OpenSSH Portable project.
|
||||
|
||||
OpenNTPD has a web site at http://www.openntpd.org/
|
||||
|
||||
I occasionally put up pre-release snapshots and various experimental
|
||||
patches at http://www.zip.com.au/~dtucker/openntpd/
|
||||
|
||||
Platform Requirements
|
||||
---------------------
|
||||
adjtime() and settimeofday() syscalls or equivalent.
|
||||
either poll() or select().
|
||||
either a self-seeding OpenSSL, a working /dev/*random device, or prngd/egd.
|
||||
|
||||
At the time of writing the Portable version is known to build and work on:
|
||||
OpenBSD (3.5, 3.7)
|
||||
Linux (Redhat 9, Fedora Core 3, Debian Woody)
|
||||
FreeBSD (4.x, 5.x)
|
||||
Solaris (2.5.1[1], 8)
|
||||
Mac OS X
|
||||
NetBSD (2.0)
|
||||
HP-UX (11.00)
|
||||
QNX4
|
||||
IRIX
|
||||
AIX (4.3.3)
|
||||
|
||||
It may work on others, but it's still a work in progress. Reports
|
||||
(success or otherwise) and/or diffs welcome.
|
||||
|
||||
[1] On Solaris 2.5.1 (and possibly other versions), socket() won't
|
||||
work in a chroot without some device special files in the chroot too.
|
||||
Solaris 8 and presumably newer don't require them. To create them:
|
||||
# tar cfh - dev/tcp dev/udp dev/zero dev/ti* | (cd /var/empty; tar xfv -)
|
||||
|
||||
Please direct any queries or bug report to me.
|
||||
|
||||
-Darren Tucker (dtucker at zip.com.au)
|
||||
2005-05-23
|
||||
|
||||
$Id: README,v 1.9 2005/06/27 05:00:40 dtucker Exp $
|
||||
152
external/bsd/openntpd/dist/buffer.c
vendored
Normal file
152
external/bsd/openntpd/dist/buffer.c
vendored
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
/* $OpenBSD: buffer.c,v 1.9 2005/08/11 16:26:29 henning Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||
*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, 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.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ntpd.h"
|
||||
|
||||
void buf_enqueue(struct msgbuf *, struct buf *);
|
||||
void buf_dequeue(struct msgbuf *, struct buf *);
|
||||
|
||||
struct buf *
|
||||
buf_open(size_t len)
|
||||
{
|
||||
struct buf *buf;
|
||||
|
||||
if ((buf = calloc(1, sizeof(struct buf))) == NULL)
|
||||
return (NULL);
|
||||
if ((buf->buf = malloc(len)) == NULL) {
|
||||
free(buf);
|
||||
return (NULL);
|
||||
}
|
||||
buf->size = len;
|
||||
|
||||
return (buf);
|
||||
}
|
||||
|
||||
int
|
||||
buf_add(struct buf *buf, void *data, size_t len)
|
||||
{
|
||||
if (buf->wpos + len > buf->size)
|
||||
return (-1);
|
||||
|
||||
memcpy(buf->buf + buf->wpos, data, len);
|
||||
buf->wpos += len;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
buf_close(struct msgbuf *msgbuf, struct buf *buf)
|
||||
{
|
||||
buf_enqueue(msgbuf, buf);
|
||||
return (1);
|
||||
}
|
||||
|
||||
void
|
||||
buf_free(struct buf *buf)
|
||||
{
|
||||
free(buf->buf);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
void
|
||||
msgbuf_init(struct msgbuf *msgbuf)
|
||||
{
|
||||
msgbuf->queued = 0;
|
||||
msgbuf->fd = -1;
|
||||
TAILQ_INIT(&msgbuf->bufs);
|
||||
}
|
||||
|
||||
void
|
||||
msgbuf_clear(struct msgbuf *msgbuf)
|
||||
{
|
||||
struct buf *buf;
|
||||
|
||||
while ((buf = TAILQ_FIRST(&msgbuf->bufs)) != NULL)
|
||||
buf_dequeue(msgbuf, buf);
|
||||
}
|
||||
|
||||
int
|
||||
msgbuf_write(struct msgbuf *msgbuf)
|
||||
{
|
||||
struct iovec iov[IOV_MAX];
|
||||
struct buf *buf, *next;
|
||||
int i = 0;
|
||||
ssize_t n;
|
||||
|
||||
bzero(&iov, sizeof(iov));
|
||||
TAILQ_FOREACH(buf, &msgbuf->bufs, entry) {
|
||||
if (i >= IOV_MAX)
|
||||
break;
|
||||
iov[i].iov_base = buf->buf + buf->rpos;
|
||||
iov[i].iov_len = buf->size - buf->rpos;
|
||||
i++;
|
||||
}
|
||||
|
||||
if ((n = writev(msgbuf->fd, iov, i)) == -1) {
|
||||
if (errno == EAGAIN || errno == EINTR ||
|
||||
errno == ENOBUFS) /* try again later */
|
||||
return (0);
|
||||
else
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (n == 0) { /* connection closed */
|
||||
errno = 0;
|
||||
return (-2);
|
||||
}
|
||||
|
||||
for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0;
|
||||
buf = next) {
|
||||
next = TAILQ_NEXT(buf, entry);
|
||||
if (buf->rpos + n >= buf->size) {
|
||||
n -= buf->size - buf->rpos;
|
||||
buf_dequeue(msgbuf, buf);
|
||||
} else {
|
||||
buf->rpos += n;
|
||||
n = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
buf_enqueue(struct msgbuf *msgbuf, struct buf *buf)
|
||||
{
|
||||
TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry);
|
||||
msgbuf->queued++;
|
||||
}
|
||||
|
||||
void
|
||||
buf_dequeue(struct msgbuf *msgbuf, struct buf *buf)
|
||||
{
|
||||
TAILQ_REMOVE(&msgbuf->bufs, buf, entry);
|
||||
msgbuf->queued--;
|
||||
buf_free(buf);
|
||||
}
|
||||
346
external/bsd/openntpd/dist/client.c
vendored
Normal file
346
external/bsd/openntpd/dist/client.c
vendored
Normal file
|
|
@ -0,0 +1,346 @@
|
|||
/* $OpenBSD: client.c,v 1.66 2005/09/24 00:32:03 dtucker Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||
* Copyright (c) 2004 Alexander Guy <alexander.guy@andern.org>
|
||||
*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, 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.
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ntpd.h"
|
||||
|
||||
int client_update(struct ntp_peer *);
|
||||
void set_deadline(struct ntp_peer *, time_t);
|
||||
|
||||
void
|
||||
set_next(struct ntp_peer *p, time_t t)
|
||||
{
|
||||
p->next = time(NULL) + t;
|
||||
p->deadline = 0;
|
||||
}
|
||||
|
||||
void
|
||||
set_deadline(struct ntp_peer *p, time_t t)
|
||||
{
|
||||
p->deadline = time(NULL) + t;
|
||||
p->next = 0;
|
||||
}
|
||||
|
||||
int
|
||||
client_peer_init(struct ntp_peer *p)
|
||||
{
|
||||
if ((p->query = calloc(1, sizeof(struct ntp_query))) == NULL)
|
||||
fatal("client_peer_init calloc");
|
||||
p->query->fd = -1;
|
||||
p->query->msg.status = MODE_CLIENT | (NTP_VERSION << 3);
|
||||
p->state = STATE_NONE;
|
||||
p->shift = 0;
|
||||
p->trustlevel = TRUSTLEVEL_PATHETIC;
|
||||
p->lasterror = 0;
|
||||
|
||||
return (client_addr_init(p));
|
||||
}
|
||||
|
||||
int
|
||||
client_addr_init(struct ntp_peer *p)
|
||||
{
|
||||
struct sockaddr_in *sa_in;
|
||||
struct sockaddr_in6 *sa_in6;
|
||||
struct ntp_addr *h;
|
||||
|
||||
for (h = p->addr; h != NULL; h = h->next) {
|
||||
switch (h->ss.ss_family) {
|
||||
case AF_INET:
|
||||
sa_in = (struct sockaddr_in *)&h->ss;
|
||||
if (ntohs(sa_in->sin_port) == 0)
|
||||
sa_in->sin_port = htons(123);
|
||||
p->state = STATE_DNS_DONE;
|
||||
break;
|
||||
case AF_INET6:
|
||||
sa_in6 = (struct sockaddr_in6 *)&h->ss;
|
||||
if (ntohs(sa_in6->sin6_port) == 0)
|
||||
sa_in6->sin6_port = htons(123);
|
||||
p->state = STATE_DNS_DONE;
|
||||
break;
|
||||
default:
|
||||
fatal("king bula sez: wrong AF in client_addr_init");
|
||||
/* not reached */
|
||||
}
|
||||
}
|
||||
|
||||
p->query->fd = -1;
|
||||
set_next(p, 0);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
client_nextaddr(struct ntp_peer *p)
|
||||
{
|
||||
close(p->query->fd);
|
||||
p->query->fd = -1;
|
||||
|
||||
if (p->addr_head.a == NULL) {
|
||||
priv_host_dns(p->addr_head.name, p->id);
|
||||
p->state = STATE_DNS_INPROGRESS;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if ((p->addr = p->addr->next) == NULL)
|
||||
p->addr = p->addr_head.a;
|
||||
|
||||
p->shift = 0;
|
||||
p->trustlevel = TRUSTLEVEL_PATHETIC;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
client_query(struct ntp_peer *p)
|
||||
{
|
||||
#ifdef IPTOS_LOWDELAY
|
||||
int tos = IPTOS_LOWDELAY;
|
||||
#endif
|
||||
|
||||
if (p->addr == NULL && client_nextaddr(p) == -1) {
|
||||
set_next(p, error_interval());
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (p->state < STATE_DNS_DONE || p->addr == NULL)
|
||||
return (-1);
|
||||
|
||||
if (p->query->fd == -1) {
|
||||
struct sockaddr *sa = (struct sockaddr *)&p->addr->ss;
|
||||
|
||||
if ((p->query->fd = socket(p->addr->ss.ss_family, SOCK_DGRAM,
|
||||
0)) == -1)
|
||||
fatal("client_query socket");
|
||||
if (connect(p->query->fd, sa, SA_LEN(sa)) == -1) {
|
||||
if (errno == ECONNREFUSED || errno == ENETUNREACH ||
|
||||
errno == EHOSTUNREACH) {
|
||||
client_nextaddr(p);
|
||||
set_next(p, error_interval());
|
||||
return (-1);
|
||||
} else
|
||||
fatal("client_query connect");
|
||||
}
|
||||
#ifdef IPTOS_LOWDELAY
|
||||
if (p->addr->ss.ss_family == AF_INET && setsockopt(p->query->fd,
|
||||
IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) == -1)
|
||||
log_warn("setsockopt IPTOS_LOWDELAY");
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Send out a random 64-bit number as our transmit time. The NTP
|
||||
* server will copy said number into the originate field on the
|
||||
* response that it sends us. This is totally legal per the SNTP spec.
|
||||
*
|
||||
* The impact of this is two fold: we no longer send out the current
|
||||
* system time for the world to see (which may aid an attacker), and
|
||||
* it gives us a (not very secure) way of knowing that we're not
|
||||
* getting spoofed by an attacker that can't capture our traffic
|
||||
* but can spoof packets from the NTP server we're communicating with.
|
||||
*
|
||||
* Save the real transmit timestamp locally.
|
||||
*/
|
||||
|
||||
p->query->msg.xmttime.int_partl = arc4random();
|
||||
p->query->msg.xmttime.fractionl = arc4random();
|
||||
p->query->xmttime = gettime();
|
||||
|
||||
if (ntp_sendmsg(p->query->fd, NULL, &p->query->msg,
|
||||
NTP_MSGSIZE_NOAUTH, 0) == -1) {
|
||||
set_next(p, INTERVAL_QUERY_PATHETIC);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
p->state = STATE_QUERY_SENT;
|
||||
set_deadline(p, QUERYTIME_MAX);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
client_dispatch(struct ntp_peer *p, u_int8_t settime)
|
||||
{
|
||||
char buf[NTP_MSGSIZE];
|
||||
ssize_t size;
|
||||
struct ntp_msg msg;
|
||||
double T1, T2, T3, T4;
|
||||
time_t interval;
|
||||
|
||||
if ((size = recvfrom(p->query->fd, &buf, sizeof(buf), 0,
|
||||
NULL, NULL)) == -1) {
|
||||
if (errno == EHOSTUNREACH || errno == EHOSTDOWN ||
|
||||
errno == ENETUNREACH || errno == ENETDOWN ||
|
||||
errno == ECONNREFUSED || errno == EADDRNOTAVAIL) {
|
||||
client_log_error(p, "recvfrom", errno);
|
||||
set_next(p, error_interval());
|
||||
return (0);
|
||||
} else
|
||||
fatal("recvfrom");
|
||||
}
|
||||
|
||||
T4 = gettime();
|
||||
|
||||
ntp_getmsg((struct sockaddr *)&p->addr->ss, buf, size, &msg);
|
||||
|
||||
if (msg.orgtime.int_partl != p->query->msg.xmttime.int_partl ||
|
||||
msg.orgtime.fractionl != p->query->msg.xmttime.fractionl)
|
||||
return (0);
|
||||
|
||||
if ((msg.status & LI_ALARM) == LI_ALARM || msg.stratum == 0 ||
|
||||
msg.stratum > NTP_MAXSTRATUM) {
|
||||
interval = error_interval();
|
||||
set_next(p, interval);
|
||||
log_info("reply from %s: not synced, next query %ds",
|
||||
log_sockaddr((struct sockaddr *)&p->addr->ss), interval);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* From RFC 2030 (with a correction to the delay math):
|
||||
*
|
||||
* Timestamp Name ID When Generated
|
||||
* ------------------------------------------------------------
|
||||
* Originate Timestamp T1 time request sent by client
|
||||
* Receive Timestamp T2 time request received by server
|
||||
* Transmit Timestamp T3 time reply sent by server
|
||||
* Destination Timestamp T4 time reply received by client
|
||||
*
|
||||
* The roundtrip delay d and local clock offset t are defined as
|
||||
*
|
||||
* d = (T4 - T1) - (T3 - T2) t = ((T2 - T1) + (T3 - T4)) / 2.
|
||||
*/
|
||||
|
||||
T1 = p->query->xmttime;
|
||||
T2 = lfp_to_d(msg.rectime);
|
||||
T3 = lfp_to_d(msg.xmttime);
|
||||
|
||||
p->reply[p->shift].offset = ((T2 - T1) + (T3 - T4)) / 2;
|
||||
p->reply[p->shift].delay = (T4 - T1) - (T3 - T2);
|
||||
if (p->reply[p->shift].delay < 0) {
|
||||
interval = error_interval();
|
||||
set_next(p, interval);
|
||||
log_info("reply from %s: negative delay %f",
|
||||
log_sockaddr((struct sockaddr *)&p->addr->ss),
|
||||
p->reply[p->shift].delay);
|
||||
return (0);
|
||||
}
|
||||
p->reply[p->shift].error = (T2 - T1) - (T3 - T4);
|
||||
p->reply[p->shift].rcvd = time(NULL);
|
||||
p->reply[p->shift].good = 1;
|
||||
|
||||
p->reply[p->shift].status.leap = (msg.status & LIMASK);
|
||||
p->reply[p->shift].status.precision = msg.precision;
|
||||
p->reply[p->shift].status.rootdelay = sfp_to_d(msg.rootdelay);
|
||||
p->reply[p->shift].status.rootdispersion = sfp_to_d(msg.dispersion);
|
||||
p->reply[p->shift].status.refid = ntohl(msg.refid);
|
||||
p->reply[p->shift].status.refid4 = msg.xmttime.fractionl;
|
||||
p->reply[p->shift].status.reftime = lfp_to_d(msg.reftime);
|
||||
p->reply[p->shift].status.poll = msg.ppoll;
|
||||
p->reply[p->shift].status.stratum = msg.stratum;
|
||||
|
||||
if (p->trustlevel < TRUSTLEVEL_PATHETIC)
|
||||
interval = scale_interval(INTERVAL_QUERY_PATHETIC);
|
||||
else if (p->trustlevel < TRUSTLEVEL_AGRESSIVE)
|
||||
interval = scale_interval(INTERVAL_QUERY_AGRESSIVE);
|
||||
else
|
||||
interval = scale_interval(INTERVAL_QUERY_NORMAL);
|
||||
|
||||
set_next(p, interval);
|
||||
p->state = STATE_REPLY_RECEIVED;
|
||||
|
||||
/* every received reply which we do not discard increases trust */
|
||||
if (p->trustlevel < TRUSTLEVEL_MAX) {
|
||||
if (p->trustlevel < TRUSTLEVEL_BADPEER &&
|
||||
p->trustlevel + 1 >= TRUSTLEVEL_BADPEER)
|
||||
log_info("peer %s now valid",
|
||||
log_sockaddr((struct sockaddr *)&p->addr->ss));
|
||||
p->trustlevel++;
|
||||
}
|
||||
|
||||
log_debug("reply from %s: offset %f delay %f, "
|
||||
"next query %ds", log_sockaddr((struct sockaddr *)&p->addr->ss),
|
||||
p->reply[p->shift].offset, p->reply[p->shift].delay, interval);
|
||||
|
||||
client_update(p);
|
||||
if (settime)
|
||||
priv_settime(p->reply[p->shift].offset);
|
||||
|
||||
if (++p->shift >= OFFSET_ARRAY_SIZE)
|
||||
p->shift = 0;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
client_update(struct ntp_peer *p)
|
||||
{
|
||||
int i, best = 0, good = 0;
|
||||
|
||||
/*
|
||||
* clock filter
|
||||
* find the offset which arrived with the lowest delay
|
||||
* use that as the peer update
|
||||
* invalidate it and all older ones
|
||||
*/
|
||||
|
||||
for (i = 0; good == 0 && i < OFFSET_ARRAY_SIZE; i++)
|
||||
if (p->reply[i].good) {
|
||||
good++;
|
||||
best = i;
|
||||
}
|
||||
|
||||
for (; i < OFFSET_ARRAY_SIZE; i++)
|
||||
if (p->reply[i].good) {
|
||||
good++;
|
||||
if (p->reply[i].delay < p->reply[best].delay)
|
||||
best = i;
|
||||
}
|
||||
|
||||
if (good < 8)
|
||||
return (-1);
|
||||
|
||||
memcpy(&p->update, &p->reply[best], sizeof(p->update));
|
||||
priv_adjtime();
|
||||
|
||||
for (i = 0; i < OFFSET_ARRAY_SIZE; i++)
|
||||
if (p->reply[i].rcvd <= p->reply[best].rcvd)
|
||||
p->reply[i].good = 0;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
client_log_error(struct ntp_peer *peer, const char *operation, int error)
|
||||
{
|
||||
const char *address;
|
||||
|
||||
address = log_sockaddr((struct sockaddr *)&peer->addr->ss);
|
||||
if (peer->lasterror == error) {
|
||||
log_debug("%s %s: %s", operation, address, strerror(error));
|
||||
return;
|
||||
}
|
||||
peer->lasterror = error;
|
||||
log_warn("%s %s", operation, address);
|
||||
}
|
||||
186
external/bsd/openntpd/dist/config.c
vendored
Normal file
186
external/bsd/openntpd/dist/config.c
vendored
Normal file
|
|
@ -0,0 +1,186 @@
|
|||
/* $OpenBSD: config.c,v 1.18 2005/05/11 15:12:35 henning Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||
*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/nameser.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <resolv.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ntpd.h"
|
||||
|
||||
struct ntp_addr *host_v4(const char *);
|
||||
struct ntp_addr *host_v6(const char *);
|
||||
|
||||
static u_int32_t maxid = 0;
|
||||
|
||||
int
|
||||
host(const char *s, struct ntp_addr **hn)
|
||||
{
|
||||
struct ntp_addr *h = NULL;
|
||||
|
||||
if (!strcmp(s, "*"))
|
||||
if ((h = calloc(1, sizeof(struct ntp_addr))) == NULL)
|
||||
fatal(NULL);
|
||||
|
||||
/* IPv4 address? */
|
||||
if (h == NULL)
|
||||
h = host_v4(s);
|
||||
|
||||
/* IPv6 address? */
|
||||
if (h == NULL)
|
||||
h = host_v6(s);
|
||||
|
||||
if (h == NULL)
|
||||
return (0);
|
||||
|
||||
*hn = h;
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
struct ntp_addr *
|
||||
host_v4(const char *s)
|
||||
{
|
||||
struct in_addr ina;
|
||||
struct sockaddr_in *sa_in;
|
||||
struct ntp_addr *h;
|
||||
|
||||
bzero(&ina, sizeof(struct in_addr));
|
||||
if (inet_pton(AF_INET, s, &ina) != 1)
|
||||
return (NULL);
|
||||
|
||||
if ((h = calloc(1, sizeof(struct ntp_addr))) == NULL)
|
||||
fatal(NULL);
|
||||
sa_in = (struct sockaddr_in *)&h->ss;
|
||||
#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
|
||||
sa_in->sin_len = sizeof(struct sockaddr_in);
|
||||
#endif
|
||||
sa_in->sin_family = AF_INET;
|
||||
sa_in->sin_addr.s_addr = ina.s_addr;
|
||||
|
||||
return (h);
|
||||
}
|
||||
|
||||
struct ntp_addr *
|
||||
host_v6(const char *s)
|
||||
{
|
||||
struct addrinfo hints, *res;
|
||||
struct sockaddr_in6 *sa_in6;
|
||||
struct ntp_addr *h = NULL;
|
||||
|
||||
bzero(&hints, sizeof(hints));
|
||||
hints.ai_family = AF_INET6;
|
||||
hints.ai_socktype = SOCK_DGRAM; /*dummy*/
|
||||
hints.ai_flags = AI_NUMERICHOST;
|
||||
if (getaddrinfo(s, "0", &hints, &res) == 0) {
|
||||
if ((h = calloc(1, sizeof(struct ntp_addr))) == NULL)
|
||||
fatal(NULL);
|
||||
sa_in6 = (struct sockaddr_in6 *)&h->ss;
|
||||
#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN
|
||||
sa_in6->sin6_len = sizeof(struct sockaddr_in6);
|
||||
#endif
|
||||
sa_in6->sin6_family = AF_INET6;
|
||||
memcpy(&sa_in6->sin6_addr,
|
||||
&((struct sockaddr_in6 *)res->ai_addr)->sin6_addr,
|
||||
sizeof(sa_in6->sin6_addr));
|
||||
#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
|
||||
sa_in6->sin6_scope_id =
|
||||
((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id;
|
||||
#endif
|
||||
|
||||
freeaddrinfo(res);
|
||||
}
|
||||
|
||||
return (h);
|
||||
}
|
||||
|
||||
int
|
||||
host_dns(const char *s, struct ntp_addr **hn)
|
||||
{
|
||||
struct addrinfo hints, *res0, *res;
|
||||
int error, cnt = 0;
|
||||
struct sockaddr_in *sa_in;
|
||||
struct sockaddr_in6 *sa_in6;
|
||||
struct ntp_addr *h, *hh = NULL;
|
||||
|
||||
bzero(&hints, sizeof(hints));
|
||||
hints.ai_family = PF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_DGRAM; /* DUMMY */
|
||||
error = getaddrinfo(s, NULL, &hints, &res0);
|
||||
if (error == EAI_AGAIN || error == EAI_NODATA || error == EAI_NONAME)
|
||||
return (0);
|
||||
if (error) {
|
||||
log_warnx("could not parse \"%s\": %s", s,
|
||||
gai_strerror(error));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
for (res = res0; res && cnt < MAX_SERVERS_DNS; res = res->ai_next) {
|
||||
if (res->ai_family != AF_INET &&
|
||||
res->ai_family != AF_INET6)
|
||||
continue;
|
||||
if ((h = calloc(1, sizeof(struct ntp_addr))) == NULL)
|
||||
fatal(NULL);
|
||||
h->ss.ss_family = res->ai_family;
|
||||
if (res->ai_family == AF_INET) {
|
||||
sa_in = (struct sockaddr_in *)&h->ss;
|
||||
#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
|
||||
sa_in->sin_len = sizeof(struct sockaddr_in);
|
||||
#endif
|
||||
sa_in->sin_addr.s_addr = ((struct sockaddr_in *)
|
||||
res->ai_addr)->sin_addr.s_addr;
|
||||
} else {
|
||||
sa_in6 = (struct sockaddr_in6 *)&h->ss;
|
||||
#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN
|
||||
sa_in6->sin6_len = sizeof(struct sockaddr_in6);
|
||||
#endif
|
||||
memcpy(&sa_in6->sin6_addr, &((struct sockaddr_in6 *)
|
||||
res->ai_addr)->sin6_addr, sizeof(struct in6_addr));
|
||||
}
|
||||
|
||||
h->next = hh;
|
||||
hh = h;
|
||||
cnt++;
|
||||
}
|
||||
freeaddrinfo(res0);
|
||||
|
||||
*hn = hh;
|
||||
return (cnt);
|
||||
}
|
||||
|
||||
struct ntp_peer *
|
||||
new_peer(void)
|
||||
{
|
||||
struct ntp_peer *p;
|
||||
|
||||
if ((p = calloc(1, sizeof(struct ntp_peer))) == NULL)
|
||||
fatal("conf_main server calloc");
|
||||
p->id = ++maxid;
|
||||
|
||||
return (p);
|
||||
}
|
||||
1410
external/bsd/openntpd/dist/config.guess
vendored
Executable file
1410
external/bsd/openntpd/dist/config.guess
vendored
Executable file
File diff suppressed because it is too large
Load Diff
345
external/bsd/openntpd/dist/config.h
vendored
Normal file
345
external/bsd/openntpd/dist/config.h
vendored
Normal file
|
|
@ -0,0 +1,345 @@
|
|||
/* config.h. Generated by configure. */
|
||||
/* config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* Broken getaddrinfo */
|
||||
/* #undef BROKEN_GETADDRINFO */
|
||||
|
||||
/* Broken setregid */
|
||||
/* #undef BROKEN_SETREGID */
|
||||
|
||||
/* ENOSYS: Not implemented */
|
||||
/* #undef BROKEN_SETRESGID */
|
||||
|
||||
/* ENOSYS: Not implemented */
|
||||
/* #undef BROKEN_SETRESUID */
|
||||
|
||||
/* Broken setreuid */
|
||||
/* #undef BROKEN_SETREUID */
|
||||
|
||||
/* statically set by configure */
|
||||
/* #undef DEF_IOV_MAX */
|
||||
|
||||
/* Define to 1 if you have the `adjtime' function. */
|
||||
#define HAVE_ADJTIME 1
|
||||
|
||||
/* Define to 1 if you have the `adjtimex' function. */
|
||||
/* #undef HAVE_ADJTIMEX */
|
||||
|
||||
/* Define to 1 if you have the `arc4random' function. */
|
||||
#define HAVE_ARC4RANDOM 1
|
||||
|
||||
/* Define to 1 if you have the <arpa/inet.h> header file. */
|
||||
#define HAVE_ARPA_INET_H 1
|
||||
|
||||
/* Define to 1 if you have the <arpa/nameser.h> header file. */
|
||||
#define HAVE_ARPA_NAMESER_H 1
|
||||
|
||||
/* Define to 1 if you have the `asprintf' function. */
|
||||
#define HAVE_ASPRINTF 1
|
||||
|
||||
/* Define to 1 if you have the `bzero' function. */
|
||||
#define HAVE_BZERO 1
|
||||
|
||||
/* Define to 1 if you have the `clock_getres' function. */
|
||||
#define HAVE_CLOCK_GETRES 1
|
||||
|
||||
/* Define if gai_strerror() returns const char * */
|
||||
#define HAVE_CONST_GAI_STRERROR_PROTO 1
|
||||
|
||||
/* Define to 1 if you have the <ctype.h> header file. */
|
||||
#define HAVE_CTYPE_H 1
|
||||
|
||||
/* Define to 1 if you have the `daemon' function. */
|
||||
#define HAVE_DAEMON 1
|
||||
|
||||
/* Define to 1 if you have the declaration of `asprintf', and to 0 if you
|
||||
don't. */
|
||||
#define HAVE_DECL_ASPRINTF 1
|
||||
|
||||
/* Define to 1 if you have the `errx' function. */
|
||||
#define HAVE_ERRX 1
|
||||
|
||||
/* Define to 1 if you have the <err.h> header file. */
|
||||
#define HAVE_ERR_H 1
|
||||
|
||||
/* Define to 1 if you have the `freeaddrinfo' function. */
|
||||
#define HAVE_FREEADDRINFO 1
|
||||
|
||||
/* Define to 1 if you have the `gai_strerror' function. */
|
||||
#define HAVE_GAI_STRERROR 1
|
||||
|
||||
/* Define to 1 if you have the `getaddrinfo' function. */
|
||||
#define HAVE_GETADDRINFO 1
|
||||
|
||||
/* Define to 1 if you have the `getifaddrs' function. */
|
||||
#define HAVE_GETIFADDRS 1
|
||||
|
||||
/* Define to 1 if you have the `getnameinfo' function. */
|
||||
#define HAVE_GETNAMEINFO 1
|
||||
|
||||
/* Define to 1 if you have the <ifaddrs.h> header file. */
|
||||
#define HAVE_IFADDRS_H 1
|
||||
|
||||
/* libc defines in6addr_any */
|
||||
/* #undef HAVE_IN6ADDR_ANY */
|
||||
|
||||
/* Define to 1 if you have the `inet_pton' function. */
|
||||
#define HAVE_INET_PTON 1
|
||||
|
||||
/* Have int64_t type */
|
||||
#define HAVE_INT64_T
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Have intXX_t */
|
||||
#define HAVE_INTXX_T
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define to 1 if you have the <netdb.h> header file. */
|
||||
#define HAVE_NETDB_H 1
|
||||
|
||||
/* Have OpenSSL */
|
||||
/* #undef HAVE_OPENSSL */
|
||||
|
||||
/* Define to 1 if you have the <paths.h> header file. */
|
||||
#define HAVE_PATHS_H 1
|
||||
|
||||
/* Define to 1 if you have the `poll' function. */
|
||||
#define HAVE_POLL 1
|
||||
|
||||
/* Define to 1 if you have the <poll.h> header file. */
|
||||
#define HAVE_POLL_H 1
|
||||
|
||||
/* Define to 1 if you have the `select' function. */
|
||||
#define HAVE_SELECT 1
|
||||
|
||||
/* Define to 1 if you have the `setegid' function. */
|
||||
#define HAVE_SETEGID 1
|
||||
|
||||
/* Define to 1 if you have the `seteuid' function. */
|
||||
#define HAVE_SETEUID 1
|
||||
|
||||
/* Define to 1 if you have the `setgid' function. */
|
||||
#define HAVE_SETGID 1
|
||||
|
||||
/* Define to 1 if you have the `setgroups' function. */
|
||||
#define HAVE_SETGROUPS 1
|
||||
|
||||
/* Define to 1 if you have the `setproctitle' function. */
|
||||
/* #undef HAVE_SETPROCTITLE */
|
||||
|
||||
/* Define to 1 if you have the `setregid' function. */
|
||||
/* #undef HAVE_SETREGID */
|
||||
|
||||
/* Define to 1 if you have the `setresgid' function. */
|
||||
/* #undef HAVE_SETRESGID */
|
||||
|
||||
/* Define to 1 if you have the `setresuid' function. */
|
||||
/* #undef HAVE_SETRESUID */
|
||||
|
||||
/* Define to 1 if you have the `setreuid' function. */
|
||||
/* #undef HAVE_SETREUID */
|
||||
|
||||
/* Define to 1 if you have the `setuid' function. */
|
||||
#define HAVE_SETUID 1
|
||||
|
||||
/* Define to 1 if the system has the type `sig_atomic_t'. */
|
||||
#define HAVE_SIG_ATOMIC_T 1
|
||||
|
||||
/* Define to 1 if you have the `snprintf' function. */
|
||||
#define HAVE_SNPRINTF 1
|
||||
|
||||
/* Have sockaddr.sa_len */
|
||||
/* #undef HAVE_SOCKADDR_SA_LEN */
|
||||
|
||||
/* Define to 1 if you have the `socketpair' function. */
|
||||
#define HAVE_SOCKETPAIR 1
|
||||
|
||||
/* Define to 1 if the system has the type `socklen_t'. */
|
||||
#define HAVE_SOCKLEN_T 1
|
||||
|
||||
/* Define to 1 if you have the <stdarg.h> header file. */
|
||||
#define HAVE_STDARG_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the `strlcpy' function. */
|
||||
#define HAVE_STRLCPY 1
|
||||
|
||||
/* Define to 1 if you have the `strsignal' function. */
|
||||
#define HAVE_STRSIGNAL 1
|
||||
|
||||
/* Have struct addrinfo */
|
||||
#define HAVE_STRUCT_ADDRINFO
|
||||
|
||||
/* Have struct in6_addr */
|
||||
#define HAVE_STRUCT_IN6_ADDR
|
||||
|
||||
/* Have struct sockaddr_in6 */
|
||||
#define HAVE_STRUCT_SOCKADDR_IN6
|
||||
|
||||
/* Define to 1 if `sin6_len' is member of `struct sockaddr_in6'. */
|
||||
/* #undef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN */
|
||||
|
||||
/* Define to 1 if `sin6_scope_id' is member of `struct sockaddr_in6'. */
|
||||
#define HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID 1
|
||||
|
||||
/* Define to 1 if `sin_len' is member of `struct sockaddr_in'. */
|
||||
/* #undef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
|
||||
|
||||
/* Define to 1 if `sa_len' is member of `struct sockaddr'. */
|
||||
/* #undef HAVE_STRUCT_SOCKADDR_SA_LEN */
|
||||
|
||||
/* Have struct sockaddr_storage */
|
||||
#define HAVE_STRUCT_SOCKADDR_STORAGE
|
||||
|
||||
/* Define to 1 if `ss_family' is member of `struct sockaddr_storage'. */
|
||||
#define HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1
|
||||
|
||||
/* Define to 1 if `__ss_family' is member of `struct sockaddr_storage'. */
|
||||
/* #undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY */
|
||||
|
||||
/* Define to 1 if you have the <syslog.h> header file. */
|
||||
#define HAVE_SYSLOG_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/bitypes.h> header file. */
|
||||
/* #undef HAVE_SYS_BITYPES_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/fcntl.h> header file. */
|
||||
#define HAVE_SYS_FCNTL_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/queue.h> header file. */
|
||||
#define HAVE_SYS_QUEUE_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/select.h> header file. */
|
||||
#define HAVE_SYS_SELECT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
#define HAVE_SYS_SOCKET_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/sockio.h> header file. */
|
||||
/* #undef HAVE_SYS_SOCKIO_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/timers.h> header file. */
|
||||
/* #undef HAVE_SYS_TIMERS_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/timex.h> header file. */
|
||||
/* #undef HAVE_SYS_TIMEX_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||
#define HAVE_SYS_TIME_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Have unitXX_t */
|
||||
#define HAVE_UINTXX_T
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Have u_char type */
|
||||
#define HAVE_U_CHAR
|
||||
|
||||
/* Have u_int */
|
||||
#define HAVE_U_INT
|
||||
|
||||
/* Have u_int64_t */
|
||||
#define HAVE_U_INT64_T
|
||||
|
||||
/* Have u_intXX_t */
|
||||
#define HAVE_U_INTXX_T
|
||||
|
||||
/* Define to 1 if you have the `verrx' function. */
|
||||
#define HAVE_VERRX 1
|
||||
|
||||
/* Define to 1 if you have the `vsnprintf' function. */
|
||||
#define HAVE_VSNPRINTF 1
|
||||
|
||||
/* Define to 1 if you have the `vsyslog' function. */
|
||||
#define HAVE_VSYSLOG 1
|
||||
|
||||
/* have __FUNCTION__ macro */
|
||||
#define HAVE___FUNCTION__ 1
|
||||
|
||||
/* libc defines __progname */
|
||||
#define HAVE___PROGNAME
|
||||
|
||||
/* have __func__ macro */
|
||||
#define HAVE___func__ 1
|
||||
|
||||
/* no "long long" support */
|
||||
/* #undef NO_LONG_LONG */
|
||||
|
||||
/* Privilege separation chroot path */
|
||||
/* #undef NTPD_CHROOT_DIR */
|
||||
|
||||
/* Unprivileged userid */
|
||||
/* #undef NTPD_USER */
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT ""
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "OpenNTPD"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "OpenNTPD Portable"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "openntpd"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "Portable"
|
||||
|
||||
/* setuid after seteuid doesn't work */
|
||||
/* #undef SETEUID_BREAKS_SETUID */
|
||||
|
||||
/* The size of a `char', as computed by sizeof. */
|
||||
#define SIZEOF_CHAR 1
|
||||
|
||||
/* The size of a `int', as computed by sizeof. */
|
||||
#define SIZEOF_INT 4
|
||||
|
||||
/* The size of a `long int', as computed by sizeof. */
|
||||
#define SIZEOF_LONG_INT 4
|
||||
|
||||
/* The size of a `long long int', as computed by sizeof. */
|
||||
#define SIZEOF_LONG_LONG_INT 8
|
||||
|
||||
/* The size of a `short int', as computed by sizeof. */
|
||||
#define SIZEOF_SHORT_INT 2
|
||||
|
||||
/* arg 3 of socket is size_t */
|
||||
/* #undef SOCKLEN_T_IS_SIZE_T */
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Use SIOCGIFCONF ioctl if we do not have getifaddrs() */
|
||||
/* #undef USE_SIOCGIFCONF */
|
||||
|
||||
/* Needed to get IOV_MAX from stdio.h on Linux */
|
||||
/* #undef __need_IOV_MAX */
|
||||
|
||||
/* Define to `__inline__' or `__inline' if that's what the C compiler
|
||||
calls it, or to nothing if 'inline' is not supported under any name. */
|
||||
#ifndef __cplusplus
|
||||
/* #undef inline */
|
||||
#endif
|
||||
344
external/bsd/openntpd/dist/config.h.in
vendored
Normal file
344
external/bsd/openntpd/dist/config.h.in
vendored
Normal file
|
|
@ -0,0 +1,344 @@
|
|||
/* config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* Broken getaddrinfo */
|
||||
#undef BROKEN_GETADDRINFO
|
||||
|
||||
/* Broken setregid */
|
||||
#undef BROKEN_SETREGID
|
||||
|
||||
/* ENOSYS: Not implemented */
|
||||
#undef BROKEN_SETRESGID
|
||||
|
||||
/* ENOSYS: Not implemented */
|
||||
#undef BROKEN_SETRESUID
|
||||
|
||||
/* Broken setreuid */
|
||||
#undef BROKEN_SETREUID
|
||||
|
||||
/* statically set by configure */
|
||||
#undef DEF_IOV_MAX
|
||||
|
||||
/* Define to 1 if you have the `adjtime' function. */
|
||||
#undef HAVE_ADJTIME
|
||||
|
||||
/* Define to 1 if you have the `adjtimex' function. */
|
||||
#undef HAVE_ADJTIMEX
|
||||
|
||||
/* Define to 1 if you have the `arc4random' function. */
|
||||
#undef HAVE_ARC4RANDOM
|
||||
|
||||
/* Define to 1 if you have the <arpa/inet.h> header file. */
|
||||
#undef HAVE_ARPA_INET_H
|
||||
|
||||
/* Define to 1 if you have the <arpa/nameser.h> header file. */
|
||||
#undef HAVE_ARPA_NAMESER_H
|
||||
|
||||
/* Define to 1 if you have the `asprintf' function. */
|
||||
#undef HAVE_ASPRINTF
|
||||
|
||||
/* Define to 1 if you have the `bzero' function. */
|
||||
#undef HAVE_BZERO
|
||||
|
||||
/* Define to 1 if you have the `clock_getres' function. */
|
||||
#undef HAVE_CLOCK_GETRES
|
||||
|
||||
/* Define if gai_strerror() returns const char * */
|
||||
#undef HAVE_CONST_GAI_STRERROR_PROTO
|
||||
|
||||
/* Define to 1 if you have the <ctype.h> header file. */
|
||||
#undef HAVE_CTYPE_H
|
||||
|
||||
/* Define to 1 if you have the `daemon' function. */
|
||||
#undef HAVE_DAEMON
|
||||
|
||||
/* Define to 1 if you have the declaration of `asprintf', and to 0 if you
|
||||
don't. */
|
||||
#undef HAVE_DECL_ASPRINTF
|
||||
|
||||
/* Define to 1 if you have the `errx' function. */
|
||||
#undef HAVE_ERRX
|
||||
|
||||
/* Define to 1 if you have the <err.h> header file. */
|
||||
#undef HAVE_ERR_H
|
||||
|
||||
/* Define to 1 if you have the `freeaddrinfo' function. */
|
||||
#undef HAVE_FREEADDRINFO
|
||||
|
||||
/* Define to 1 if you have the `gai_strerror' function. */
|
||||
#undef HAVE_GAI_STRERROR
|
||||
|
||||
/* Define to 1 if you have the `getaddrinfo' function. */
|
||||
#undef HAVE_GETADDRINFO
|
||||
|
||||
/* Define to 1 if you have the `getifaddrs' function. */
|
||||
#undef HAVE_GETIFADDRS
|
||||
|
||||
/* Define to 1 if you have the `getnameinfo' function. */
|
||||
#undef HAVE_GETNAMEINFO
|
||||
|
||||
/* Define to 1 if you have the <ifaddrs.h> header file. */
|
||||
#undef HAVE_IFADDRS_H
|
||||
|
||||
/* libc defines in6addr_any */
|
||||
#undef HAVE_IN6ADDR_ANY
|
||||
|
||||
/* Define to 1 if you have the `inet_pton' function. */
|
||||
#undef HAVE_INET_PTON
|
||||
|
||||
/* Have int64_t type */
|
||||
#undef HAVE_INT64_T
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#undef HAVE_INTTYPES_H
|
||||
|
||||
/* Have intXX_t */
|
||||
#undef HAVE_INTXX_T
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* Define to 1 if you have the <netdb.h> header file. */
|
||||
#undef HAVE_NETDB_H
|
||||
|
||||
/* Have OpenSSL */
|
||||
#undef HAVE_OPENSSL
|
||||
|
||||
/* Define to 1 if you have the <paths.h> header file. */
|
||||
#undef HAVE_PATHS_H
|
||||
|
||||
/* Define to 1 if you have the `poll' function. */
|
||||
#undef HAVE_POLL
|
||||
|
||||
/* Define to 1 if you have the <poll.h> header file. */
|
||||
#undef HAVE_POLL_H
|
||||
|
||||
/* Define to 1 if you have the `select' function. */
|
||||
#undef HAVE_SELECT
|
||||
|
||||
/* Define to 1 if you have the `setegid' function. */
|
||||
#undef HAVE_SETEGID
|
||||
|
||||
/* Define to 1 if you have the `seteuid' function. */
|
||||
#undef HAVE_SETEUID
|
||||
|
||||
/* Define to 1 if you have the `setgid' function. */
|
||||
#undef HAVE_SETGID
|
||||
|
||||
/* Define to 1 if you have the `setgroups' function. */
|
||||
#undef HAVE_SETGROUPS
|
||||
|
||||
/* Define to 1 if you have the `setproctitle' function. */
|
||||
#undef HAVE_SETPROCTITLE
|
||||
|
||||
/* Define to 1 if you have the `setregid' function. */
|
||||
#undef HAVE_SETREGID
|
||||
|
||||
/* Define to 1 if you have the `setresgid' function. */
|
||||
#undef HAVE_SETRESGID
|
||||
|
||||
/* Define to 1 if you have the `setresuid' function. */
|
||||
#undef HAVE_SETRESUID
|
||||
|
||||
/* Define to 1 if you have the `setreuid' function. */
|
||||
#undef HAVE_SETREUID
|
||||
|
||||
/* Define to 1 if you have the `setuid' function. */
|
||||
#undef HAVE_SETUID
|
||||
|
||||
/* Define to 1 if the system has the type `sig_atomic_t'. */
|
||||
#undef HAVE_SIG_ATOMIC_T
|
||||
|
||||
/* Define to 1 if you have the `snprintf' function. */
|
||||
#undef HAVE_SNPRINTF
|
||||
|
||||
/* Have sockaddr.sa_len */
|
||||
#undef HAVE_SOCKADDR_SA_LEN
|
||||
|
||||
/* Define to 1 if you have the `socketpair' function. */
|
||||
#undef HAVE_SOCKETPAIR
|
||||
|
||||
/* Define to 1 if the system has the type `socklen_t'. */
|
||||
#undef HAVE_SOCKLEN_T
|
||||
|
||||
/* Define to 1 if you have the <stdarg.h> header file. */
|
||||
#undef HAVE_STDARG_H
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#undef HAVE_STDINT_H
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#undef HAVE_STDLIB_H
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#undef HAVE_STRINGS_H
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#undef HAVE_STRING_H
|
||||
|
||||
/* Define to 1 if you have the `strlcpy' function. */
|
||||
#undef HAVE_STRLCPY
|
||||
|
||||
/* Define to 1 if you have the `strsignal' function. */
|
||||
#undef HAVE_STRSIGNAL
|
||||
|
||||
/* Have struct addrinfo */
|
||||
#undef HAVE_STRUCT_ADDRINFO
|
||||
|
||||
/* Have struct in6_addr */
|
||||
#undef HAVE_STRUCT_IN6_ADDR
|
||||
|
||||
/* Have struct sockaddr_in6 */
|
||||
#undef HAVE_STRUCT_SOCKADDR_IN6
|
||||
|
||||
/* Define to 1 if `sin6_len' is member of `struct sockaddr_in6'. */
|
||||
#undef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN
|
||||
|
||||
/* Define to 1 if `sin6_scope_id' is member of `struct sockaddr_in6'. */
|
||||
#undef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
|
||||
|
||||
/* Define to 1 if `sin_len' is member of `struct sockaddr_in'. */
|
||||
#undef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
|
||||
|
||||
/* Define to 1 if `sa_len' is member of `struct sockaddr'. */
|
||||
#undef HAVE_STRUCT_SOCKADDR_SA_LEN
|
||||
|
||||
/* Have struct sockaddr_storage */
|
||||
#undef HAVE_STRUCT_SOCKADDR_STORAGE
|
||||
|
||||
/* Define to 1 if `ss_family' is member of `struct sockaddr_storage'. */
|
||||
#undef HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY
|
||||
|
||||
/* Define to 1 if `__ss_family' is member of `struct sockaddr_storage'. */
|
||||
#undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY
|
||||
|
||||
/* Define to 1 if you have the <syslog.h> header file. */
|
||||
#undef HAVE_SYSLOG_H
|
||||
|
||||
/* Define to 1 if you have the <sys/bitypes.h> header file. */
|
||||
#undef HAVE_SYS_BITYPES_H
|
||||
|
||||
/* Define to 1 if you have the <sys/fcntl.h> header file. */
|
||||
#undef HAVE_SYS_FCNTL_H
|
||||
|
||||
/* Define to 1 if you have the <sys/queue.h> header file. */
|
||||
#undef HAVE_SYS_QUEUE_H
|
||||
|
||||
/* Define to 1 if you have the <sys/select.h> header file. */
|
||||
#undef HAVE_SYS_SELECT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
#undef HAVE_SYS_SOCKET_H
|
||||
|
||||
/* Define to 1 if you have the <sys/sockio.h> header file. */
|
||||
#undef HAVE_SYS_SOCKIO_H
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/timers.h> header file. */
|
||||
#undef HAVE_SYS_TIMERS_H
|
||||
|
||||
/* Define to 1 if you have the <sys/timex.h> header file. */
|
||||
#undef HAVE_SYS_TIMEX_H
|
||||
|
||||
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||
#undef HAVE_SYS_TIME_H
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#undef HAVE_SYS_TYPES_H
|
||||
|
||||
/* Have unitXX_t */
|
||||
#undef HAVE_UINTXX_T
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Have u_char type */
|
||||
#undef HAVE_U_CHAR
|
||||
|
||||
/* Have u_int */
|
||||
#undef HAVE_U_INT
|
||||
|
||||
/* Have u_int64_t */
|
||||
#undef HAVE_U_INT64_T
|
||||
|
||||
/* Have u_intXX_t */
|
||||
#undef HAVE_U_INTXX_T
|
||||
|
||||
/* Define to 1 if you have the `verrx' function. */
|
||||
#undef HAVE_VERRX
|
||||
|
||||
/* Define to 1 if you have the `vsnprintf' function. */
|
||||
#undef HAVE_VSNPRINTF
|
||||
|
||||
/* Define to 1 if you have the `vsyslog' function. */
|
||||
#undef HAVE_VSYSLOG
|
||||
|
||||
/* have __FUNCTION__ macro */
|
||||
#undef HAVE___FUNCTION__
|
||||
|
||||
/* libc defines __progname */
|
||||
#undef HAVE___PROGNAME
|
||||
|
||||
/* have __func__ macro */
|
||||
#undef HAVE___func__
|
||||
|
||||
/* no "long long" support */
|
||||
#undef NO_LONG_LONG
|
||||
|
||||
/* Privilege separation chroot path */
|
||||
#undef NTPD_CHROOT_DIR
|
||||
|
||||
/* Unprivileged userid */
|
||||
#undef NTPD_USER
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#undef PACKAGE_BUGREPORT
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#undef PACKAGE_NAME
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#undef PACKAGE_STRING
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#undef PACKAGE_TARNAME
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#undef PACKAGE_VERSION
|
||||
|
||||
/* setuid after seteuid doesn't work */
|
||||
#undef SETEUID_BREAKS_SETUID
|
||||
|
||||
/* The size of a `char', as computed by sizeof. */
|
||||
#undef SIZEOF_CHAR
|
||||
|
||||
/* The size of a `int', as computed by sizeof. */
|
||||
#undef SIZEOF_INT
|
||||
|
||||
/* The size of a `long int', as computed by sizeof. */
|
||||
#undef SIZEOF_LONG_INT
|
||||
|
||||
/* The size of a `long long int', as computed by sizeof. */
|
||||
#undef SIZEOF_LONG_LONG_INT
|
||||
|
||||
/* The size of a `short int', as computed by sizeof. */
|
||||
#undef SIZEOF_SHORT_INT
|
||||
|
||||
/* arg 3 of socket is size_t */
|
||||
#undef SOCKLEN_T_IS_SIZE_T
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Use SIOCGIFCONF ioctl if we do not have getifaddrs() */
|
||||
#undef USE_SIOCGIFCONF
|
||||
|
||||
/* Needed to get IOV_MAX from stdio.h on Linux */
|
||||
#undef __need_IOV_MAX
|
||||
|
||||
/* Define to `__inline__' or `__inline' if that's what the C compiler
|
||||
calls it, or to nothing if 'inline' is not supported under any name. */
|
||||
#ifndef __cplusplus
|
||||
#undef inline
|
||||
#endif
|
||||
3579
external/bsd/openntpd/dist/config.log
vendored
Normal file
3579
external/bsd/openntpd/dist/config.log
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1098
external/bsd/openntpd/dist/config.status
vendored
Executable file
1098
external/bsd/openntpd/dist/config.status
vendored
Executable file
File diff suppressed because it is too large
Load Diff
1510
external/bsd/openntpd/dist/config.sub
vendored
Executable file
1510
external/bsd/openntpd/dist/config.sub
vendored
Executable file
File diff suppressed because it is too large
Load Diff
11183
external/bsd/openntpd/dist/configure
vendored
Executable file
11183
external/bsd/openntpd/dist/configure
vendored
Executable file
File diff suppressed because it is too large
Load Diff
818
external/bsd/openntpd/dist/configure.ac
vendored
Normal file
818
external/bsd/openntpd/dist/configure.ac
vendored
Normal file
|
|
@ -0,0 +1,818 @@
|
|||
# $Id: configure.ac,v 1.77 2006/05/13 11:09:33 dtucker Exp $
|
||||
#
|
||||
# Copyright (c) 2004, 2005 Darren Tucker.
|
||||
# Parts based on configure.ac from Portable OpenSSH:
|
||||
# Copyright (c) 1999-2004 Damien Miller
|
||||
#
|
||||
# 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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.
|
||||
|
||||
AC_INIT(OpenNTPD, Portable)
|
||||
AC_CONFIG_SRCDIR([ntpd.c])
|
||||
AC_CONFIG_HEADER(config.h)
|
||||
|
||||
AC_PROG_CC
|
||||
AC_PROG_RANLIB
|
||||
AC_PROG_INSTALL
|
||||
AC_PATH_PROG(AR, ar)
|
||||
AC_PROG_AWK
|
||||
AC_PROG_YACC
|
||||
|
||||
if test -z "$LD" ; then
|
||||
LD=$CC
|
||||
fi
|
||||
AC_SUBST(LD)
|
||||
|
||||
for i in CC LD AR RANLIB INSTALL AWK
|
||||
do
|
||||
prog=`eval echo '$'$i`
|
||||
if test -z "$prog"; then
|
||||
AC_MSG_ERROR([Required program $i not found])
|
||||
fi
|
||||
done
|
||||
|
||||
AC_C_INLINE
|
||||
if test "$GCC" = "yes" || test "$GCC" = "egcs"; then
|
||||
CFLAGS="$CFLAGS -Wall"
|
||||
CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes"
|
||||
CFLAGS="$CFLAGS -Wmissing-declarations"
|
||||
CFLAGS="$CFLAGS -Wshadow -Wpointer-arith -Wcast-qual"
|
||||
CFLAGS="$CFLAGS -Wsign-compare"
|
||||
fi
|
||||
|
||||
# Check for some target-specific stuff
|
||||
AC_CANONICAL_HOST
|
||||
case "$host" in
|
||||
*-*-aix*)
|
||||
case "$host" in
|
||||
*-*-aix4*)
|
||||
AC_DEFINE(BROKEN_GETADDRINFO, [], [Broken getaddrinfo])
|
||||
;;
|
||||
esac
|
||||
AC_DEFINE(SETEUID_BREAKS_SETUID,[],[setuid after seteuid doesn't work])
|
||||
AC_DEFINE(BROKEN_SETREUID,[], [Broken setreuid])
|
||||
AC_DEFINE(BROKEN_SETREGID,[], [Broken setregid])
|
||||
# define these to pick up most of the prototypes
|
||||
CFLAGS="$CFLAGS -D_ALL_SOURCE -D_GNU_SOURCE -D_POSIX_C_SOURCE=199506L"
|
||||
;;
|
||||
*-*-darwin*)
|
||||
AC_DEFINE(SETEUID_BREAKS_SETUID,[],[setuid after seteuid doesn't work])
|
||||
AC_DEFINE(BROKEN_SETREUID,[], [Broken setreuid])
|
||||
AC_DEFINE(BROKEN_SETREGID,[], [Broken setregid])
|
||||
;;
|
||||
*-*-irix*)
|
||||
AC_DEFINE(SETEUID_BREAKS_SETUID,[],[setuid after seteuid doesn't work])
|
||||
AC_DEFINE(BROKEN_SETREUID,[], [Broken setreuid])
|
||||
AC_DEFINE(BROKEN_SETREGID,[], [Broken setregid])
|
||||
AC_CHECK_PROGS(have_sysconf, sysconf, no)
|
||||
if test "$have_sysconf" != "no"; then
|
||||
AC_MSG_CHECKING([for value of IOV_MAX])
|
||||
iov_max=`sysconf IOV_MAX`
|
||||
if test $? -eq 0; then
|
||||
AC_MSG_RESULT([$iov_max])
|
||||
AC_DEFINE_UNQUOTED(DEF_IOV_MAX, $iov_max,
|
||||
[retrived via sysconf])
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
*-*-linux*)
|
||||
AC_DEFINE(__need_IOV_MAX, [],
|
||||
[Needed to get IOV_MAX from stdio.h on Linux])
|
||||
AC_DEFINE(USE_SIOCGIFCONF, [],
|
||||
[Use SIOCGIFCONF ioctl if we do not have getifaddrs()])
|
||||
|
||||
;;
|
||||
*-*-qnx*)
|
||||
AC_DEFINE(SETEUID_BREAKS_SETUID,[],[setuid after seteuid doesn't work])
|
||||
AC_DEFINE(BROKEN_SETREUID,[], [Broken setreuid])
|
||||
AC_DEFINE(BROKEN_SETREGID,[], [Broken setregid])
|
||||
AC_DEFINE(SOCKLEN_T_IS_SIZE_T, [], [arg 3 of socket is size_t])
|
||||
AC_DEFINE_UNQUOTED(DEF_IOV_MAX, 1024, [statically set by configure])
|
||||
;;
|
||||
+*-*-*UnixWare*)
|
||||
AC_DEFINE(SETEUID_BREAKS_SETUID,[],[setuid after seteuid doesn't work])
|
||||
AC_DEFINE(BROKEN_SETREUID,[], [Broken setreuid])
|
||||
AC_DEFINE(BROKEN_SETREGID,[], [Broken setregid])
|
||||
AC_DEFINE(BROKEN_SETRESUID,[], [Broken setresuid])
|
||||
AC_DEFINE(BROKEN_SETRESGID,[], [Broken setresgid])
|
||||
AC_DEFINE_UNQUOTED(DEF_IOV_MAX, 16, [statically set by configure])
|
||||
;;
|
||||
esac
|
||||
|
||||
AC_CHECK_HEADERS( \
|
||||
arpa/inet.h \
|
||||
arpa/nameser.h \
|
||||
ctype.h \
|
||||
err.h \
|
||||
ifaddrs.h \
|
||||
netdb.h \
|
||||
netinet/in_systm.h \
|
||||
netinet/ip.h \
|
||||
paths.h \
|
||||
poll.h \
|
||||
stdarg.h \
|
||||
sys/bitypes.h \
|
||||
sys/fcntl.h \
|
||||
sys/queue.h \
|
||||
sys/select.h \
|
||||
sys/socket.h \
|
||||
sys/sockio.h \
|
||||
sys/time.h \
|
||||
sys/timers.h \
|
||||
sys/timex.h \
|
||||
sys/types.h \
|
||||
syslog.h \
|
||||
)
|
||||
|
||||
AC_CHECK_DECLS(asprintf, ,
|
||||
[saved_CFLAGS="$CFLAGS"
|
||||
CFLAGS="$CFLAGS -D_GNU_SOURCE"
|
||||
unset ac_cv_have_decl_asprintf
|
||||
AC_CHECK_DECLS(asprintf, , CFLAGS="$saved_CFLAGS")
|
||||
]
|
||||
)
|
||||
|
||||
AC_CHECK_FUNCS(socketpair, ,
|
||||
[saved_LDFLAGS="$LDFLAGS"
|
||||
LDFLAGS="$LDFLAGS -lsocket -lnsl"
|
||||
unset ac_cv_func_socketpair
|
||||
AC_CHECK_FUNCS(socketpair, , LDFLAGS="$saved_LDFLAGS")
|
||||
]
|
||||
)
|
||||
|
||||
AC_CHECK_FUNCS( \
|
||||
adjtime \
|
||||
adjtimex \
|
||||
arc4random \
|
||||
asprintf \
|
||||
bzero \
|
||||
clock_getres \
|
||||
daemon \
|
||||
errx \
|
||||
getifaddrs \
|
||||
inet_pton \
|
||||
poll select \
|
||||
setgroups \
|
||||
setproctitle \
|
||||
snprintf \
|
||||
strlcpy \
|
||||
strsignal \
|
||||
verrx \
|
||||
vsnprintf \
|
||||
)
|
||||
|
||||
dnl UnixWare vsyslog test is not accurate so we skip it
|
||||
case "$host" in
|
||||
*-*-*UnixWare*)
|
||||
;;
|
||||
*)
|
||||
AC_CHECK_FUNCS(vsyslog)
|
||||
;;
|
||||
esac
|
||||
|
||||
dnl Check for uidswap functions
|
||||
AC_CHECK_FUNCS(setuid setgid seteuid setegid setreuid setregid)
|
||||
|
||||
AC_CHECK_FUNCS(setresuid, [
|
||||
dnl Some platorms have setresuid that isn't implemented, test for this
|
||||
AC_MSG_CHECKING(if setresuid seems to work)
|
||||
AC_RUN_IFELSE(
|
||||
[AC_LANG_SOURCE([[
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
int main(){errno=0; setresuid(0,0,0); if (errno==ENOSYS) exit(1); else exit(0);}
|
||||
]])],
|
||||
[AC_MSG_RESULT(yes)],
|
||||
[AC_DEFINE(BROKEN_SETRESUID, 1, [ENOSYS: Not implemented])
|
||||
AC_MSG_RESULT(not implemented)],
|
||||
[AC_MSG_WARN([cross compiling: not checking setresuid])]
|
||||
)
|
||||
])
|
||||
|
||||
AC_CHECK_FUNCS(setresgid, [
|
||||
dnl Some platorms have setresgid that isn't implemented, test for this
|
||||
AC_MSG_CHECKING(if setresgid seems to work)
|
||||
AC_RUN_IFELSE(
|
||||
[AC_LANG_SOURCE([[
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
int main(){errno=0; setresgid(0,0,0); if (errno==ENOSYS) exit(1); else exit(0);}
|
||||
]])],
|
||||
[AC_MSG_RESULT(yes)],
|
||||
[AC_DEFINE(BROKEN_SETRESGID, 1, [ENOSYS: Not implemented])
|
||||
AC_MSG_RESULT(not implemented)],
|
||||
[AC_MSG_WARN([cross compiling: not checking setresuid])]
|
||||
)
|
||||
])
|
||||
|
||||
dnl Check for getaddrinfo and friends.
|
||||
AC_CHECK_FUNCS(getaddrinfo getnameinfo freeaddrinfo)
|
||||
|
||||
dnl IRIX has a const char return value for gai_strerror()
|
||||
AC_CHECK_FUNCS(gai_strerror,[
|
||||
AC_DEFINE(HAVE_GAI_STRERROR)
|
||||
AC_TRY_COMPILE([
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
|
||||
const char *gai_strerror(int);],[
|
||||
char *str;
|
||||
|
||||
str = gai_strerror(0);],[
|
||||
AC_DEFINE(HAVE_CONST_GAI_STRERROR_PROTO, 1,
|
||||
[Define if gai_strerror() returns const char *])])])
|
||||
|
||||
AC_CACHE_CHECK([for struct sockaddr_storage], ac_cv_have_struct_sockaddr_storage, [
|
||||
AC_TRY_COMPILE(
|
||||
[
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
],
|
||||
[ struct sockaddr_storage s; ],
|
||||
[ ac_cv_have_struct_sockaddr_storage="yes" ],
|
||||
[ ac_cv_have_struct_sockaddr_storage="no" ]
|
||||
)
|
||||
])
|
||||
if test "x$ac_cv_have_struct_sockaddr_storage" = "xyes" ; then
|
||||
AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, [], [Have struct sockaddr_storage])
|
||||
fi
|
||||
|
||||
AC_CACHE_CHECK([for struct sockaddr_in6], ac_cv_have_struct_sockaddr_in6, [
|
||||
AC_TRY_COMPILE(
|
||||
[
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
],
|
||||
[ struct sockaddr_in6 s; s.sin6_family = 0; ],
|
||||
[ ac_cv_have_struct_sockaddr_in6="yes" ],
|
||||
[ ac_cv_have_struct_sockaddr_in6="no" ]
|
||||
)
|
||||
])
|
||||
if test "x$ac_cv_have_struct_sockaddr_in6" = "xyes" ; then
|
||||
AC_DEFINE(HAVE_STRUCT_SOCKADDR_IN6, [], [Have struct sockaddr_in6])
|
||||
fi
|
||||
|
||||
AC_CACHE_CHECK([for struct in6_addr], ac_cv_have_struct_in6_addr, [
|
||||
AC_TRY_COMPILE(
|
||||
[
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
],
|
||||
[ struct in6_addr s; s.s6_addr[0] = 0; ],
|
||||
[ ac_cv_have_struct_in6_addr="yes" ],
|
||||
[ ac_cv_have_struct_in6_addr="no" ]
|
||||
)
|
||||
])
|
||||
if test "x$ac_cv_have_struct_in6_addr" = "xyes" ; then
|
||||
AC_DEFINE(HAVE_STRUCT_IN6_ADDR, [], [Have struct in6_addr])
|
||||
fi
|
||||
|
||||
AC_CACHE_CHECK([for struct addrinfo], ac_cv_have_struct_addrinfo, [
|
||||
AC_TRY_COMPILE(
|
||||
[
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
],
|
||||
[ struct addrinfo s; s.ai_flags = AI_PASSIVE; ],
|
||||
[ ac_cv_have_struct_addrinfo="yes" ],
|
||||
[ ac_cv_have_struct_addrinfo="no" ]
|
||||
)
|
||||
])
|
||||
if test "x$ac_cv_have_struct_addrinfo" = "xyes" ; then
|
||||
AC_DEFINE(HAVE_STRUCT_ADDRINFO, [], [Have struct addrinfo])
|
||||
fi
|
||||
|
||||
AC_CHECK_MEMBER(struct sockaddr.sa_len,
|
||||
AC_DEFINE(HAVE_SOCKADDR_SA_LEN, [], [Have sockaddr.sa_len]), ,
|
||||
[ #include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h> ]
|
||||
)
|
||||
|
||||
AC_SEARCH_LIBS(res_init, resolv)
|
||||
AC_SEARCH_LIBS(res_9_init, resolv)
|
||||
|
||||
AC_CHECK_MEMBERS([struct sockaddr.sa_len, struct sockaddr_in.sin_len,
|
||||
struct sockaddr_in6.sin6_len, struct sockaddr_in6.sin6_scope_id,
|
||||
struct sockaddr_storage.ss_family,
|
||||
struct sockaddr_storage.__ss_family], , ,
|
||||
[#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>]
|
||||
)
|
||||
|
||||
AC_CACHE_CHECK([if libc defines __progname], ac_cv_libc_defines___progname, [
|
||||
AC_TRY_LINK([],
|
||||
[ extern char *__progname; printf("%s", __progname); ],
|
||||
[ ac_cv_libc_defines___progname="yes" ],
|
||||
[ ac_cv_libc_defines___progname="no" ]
|
||||
)
|
||||
])
|
||||
if test "x$ac_cv_libc_defines___progname" = "xyes" ; then
|
||||
AC_DEFINE(HAVE___PROGNAME, [], [libc defines __progname])
|
||||
fi
|
||||
|
||||
AC_CACHE_CHECK([if libc defines in6addr_any], ac_cv_libc_defines_in6addr_any, [
|
||||
AC_TRY_LINK(
|
||||
[ #include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h> ]
|
||||
[ struct sockaddr_in6 = in6addr_any; ],
|
||||
[ ac_cv_libc_defines_in6addr_any="yes" ],
|
||||
[ ac_cv_libc_defines_in6addr_any="no" ]
|
||||
)
|
||||
])
|
||||
if test "x$ac_cv_libc_defines_in6addr_any" = "xyes" ; then
|
||||
AC_DEFINE(HAVE_IN6ADDR_ANY, [], [libc defines in6addr_any])
|
||||
fi
|
||||
|
||||
dnl Does not support catman yet
|
||||
mansubdir=man
|
||||
AC_SUBST(mansubdir)
|
||||
|
||||
# Checks for data types
|
||||
AC_CHECK_SIZEOF(char, 1)
|
||||
AC_CHECK_SIZEOF(short int, 2)
|
||||
AC_CHECK_SIZEOF(int, 4)
|
||||
AC_CHECK_SIZEOF(long int, 4)
|
||||
AC_CHECK_SIZEOF(long long int, 8)
|
||||
|
||||
# Sanity check long long for some platforms (AIX)
|
||||
if test "x$ac_cv_sizeof_long_long_int" = "x4" ; then
|
||||
ac_cv_sizeof_long_long_int=0
|
||||
fi
|
||||
|
||||
if test "x$ac_cv_sizeof_long_long_int" = "x0" -o -z "$ac_cv_sizeof_long_long_int"; then
|
||||
AC_DEFINE(NO_LONG_LONG, 1, [no "long long" support])
|
||||
fi
|
||||
|
||||
# More checks for data types
|
||||
AC_CACHE_CHECK([for u_int type], ac_cv_have_u_int, [
|
||||
AC_TRY_COMPILE(
|
||||
[ #include <sys/types.h> ],
|
||||
[ u_int a; a = 1;],
|
||||
[ ac_cv_have_u_int="yes" ],
|
||||
[ ac_cv_have_u_int="no" ]
|
||||
)
|
||||
])
|
||||
if test "x$ac_cv_have_u_int" = "xyes" ; then
|
||||
AC_DEFINE(HAVE_U_INT, [], [Have u_int])
|
||||
have_u_int=1
|
||||
fi
|
||||
|
||||
AC_CACHE_CHECK([for intXX_t types], ac_cv_have_intxx_t, [
|
||||
AC_TRY_COMPILE(
|
||||
[ #include <sys/types.h> ],
|
||||
[ int8_t a; int16_t b; int32_t c; a = b = c = 1;],
|
||||
[ ac_cv_have_intxx_t="yes" ],
|
||||
[ ac_cv_have_intxx_t="no" ]
|
||||
)
|
||||
])
|
||||
if test "x$ac_cv_have_intxx_t" = "xyes" ; then
|
||||
AC_DEFINE(HAVE_INTXX_T, [], [Have intXX_t types])
|
||||
have_intxx_t=1
|
||||
fi
|
||||
|
||||
if (test -z "$have_intxx_t" && \
|
||||
test "x$ac_cv_header_stdint_h" = "xyes")
|
||||
then
|
||||
AC_MSG_CHECKING([for intXX_t types in stdint.h])
|
||||
AC_TRY_COMPILE(
|
||||
[ #include <stdint.h> ],
|
||||
[ int8_t a; int16_t b; int32_t c; a = b = c = 1;],
|
||||
[
|
||||
AC_DEFINE(HAVE_INTXX_T, [], [Have intXX_t types])
|
||||
AC_MSG_RESULT(yes)
|
||||
],
|
||||
[ AC_MSG_RESULT(no) ]
|
||||
)
|
||||
fi
|
||||
|
||||
AC_CACHE_CHECK([for int64_t type], ac_cv_have_int64_t, [
|
||||
AC_TRY_COMPILE(
|
||||
[
|
||||
#include <sys/types.h>
|
||||
#ifdef HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
#include <sys/socket.h>
|
||||
#ifdef HAVE_SYS_BITYPES_H
|
||||
# include <sys/bitypes.h>
|
||||
#endif
|
||||
],
|
||||
[ int64_t a; a = 1;],
|
||||
[ ac_cv_have_int64_t="yes" ],
|
||||
[ ac_cv_have_int64_t="no" ]
|
||||
)
|
||||
])
|
||||
if test "x$ac_cv_have_int64_t" = "xyes" ; then
|
||||
AC_DEFINE(HAVE_INT64_T, [], [Have int64_t type])
|
||||
fi
|
||||
|
||||
AC_CACHE_CHECK([for u_intXX_t types], ac_cv_have_u_intxx_t, [
|
||||
AC_TRY_COMPILE(
|
||||
[ #include <sys/types.h> ],
|
||||
[ u_int8_t a; u_int16_t b; u_int32_t c; a = b = c = 1;],
|
||||
[ ac_cv_have_u_intxx_t="yes" ],
|
||||
[ ac_cv_have_u_intxx_t="no" ]
|
||||
)
|
||||
])
|
||||
if test "x$ac_cv_have_u_intxx_t" = "xyes" ; then
|
||||
AC_DEFINE(HAVE_U_INTXX_T, [], [Have u_intXX_t types])
|
||||
have_u_intxx_t=1
|
||||
fi
|
||||
|
||||
if test -z "$have_u_intxx_t" ; then
|
||||
AC_MSG_CHECKING([for u_intXX_t types in sys/socket.h])
|
||||
AC_TRY_COMPILE(
|
||||
[ #include <sys/socket.h> ],
|
||||
[ u_int8_t a; u_int16_t b; u_int32_t c; a = b = c = 1;],
|
||||
[
|
||||
AC_DEFINE(HAVE_U_INTXX_T, [], [Have u_intXX_t])
|
||||
AC_MSG_RESULT(yes)
|
||||
],
|
||||
[ AC_MSG_RESULT(no) ]
|
||||
)
|
||||
fi
|
||||
|
||||
AC_CACHE_CHECK([for u_int64_t types], ac_cv_have_u_int64_t, [
|
||||
AC_TRY_COMPILE(
|
||||
[ #include <sys/types.h> ],
|
||||
[ u_int64_t a; a = 1;],
|
||||
[ ac_cv_have_u_int64_t="yes" ],
|
||||
[ ac_cv_have_u_int64_t="no" ]
|
||||
)
|
||||
])
|
||||
if test "x$ac_cv_have_u_int64_t" = "xyes" ; then
|
||||
AC_DEFINE(HAVE_U_INT64_T, [], [Have u_int64_t])
|
||||
have_u_int64_t=1
|
||||
fi
|
||||
|
||||
if test -z "$have_u_int64_t" ; then
|
||||
AC_MSG_CHECKING([for u_int64_t type in sys/bitypes.h])
|
||||
AC_TRY_COMPILE(
|
||||
[ #include <sys/bitypes.h> ],
|
||||
[ u_int64_t a; a = 1],
|
||||
[
|
||||
AC_DEFINE(HAVE_U_INT64_T, [], [Have u_int64_t])
|
||||
AC_MSG_RESULT(yes)
|
||||
],
|
||||
[ AC_MSG_RESULT(no) ]
|
||||
)
|
||||
fi
|
||||
|
||||
if test -z "$have_u_intxx_t" ; then
|
||||
AC_CACHE_CHECK([for uintXX_t types], ac_cv_have_uintxx_t, [
|
||||
AC_TRY_COMPILE(
|
||||
[
|
||||
#include <sys/types.h>
|
||||
],
|
||||
[ uint8_t a; uint16_t b; uint32_t c; a = b = c = 1; ],
|
||||
[ ac_cv_have_uintxx_t="yes" ],
|
||||
[ ac_cv_have_uintxx_t="no" ]
|
||||
)
|
||||
])
|
||||
if test "x$ac_cv_have_uintxx_t" = "xyes" ; then
|
||||
AC_DEFINE(HAVE_UINTXX_T, [], [Have uintXX_t types])
|
||||
fi
|
||||
fi
|
||||
|
||||
if test -z "$have_uintxx_t" ; then
|
||||
AC_MSG_CHECKING([for uintXX_t types in stdint.h])
|
||||
AC_TRY_COMPILE(
|
||||
[ #include <stdint.h> ],
|
||||
[ uint8_t a; uint16_t b; uint32_t c; a = b = c = 1;],
|
||||
[
|
||||
AC_DEFINE(HAVE_UINTXX_T, [], [Have unitXX_t])
|
||||
AC_MSG_RESULT(yes)
|
||||
],
|
||||
[ AC_MSG_RESULT(no) ]
|
||||
)
|
||||
fi
|
||||
|
||||
if (test -z "$have_u_intxx_t" || test -z "$have_intxx_t" && \
|
||||
test "x$ac_cv_header_sys_bitypes_h" = "xyes")
|
||||
then
|
||||
AC_MSG_CHECKING([for intXX_t and u_intXX_t types in sys/bitypes.h])
|
||||
AC_TRY_COMPILE(
|
||||
[
|
||||
#include <sys/bitypes.h>
|
||||
],
|
||||
[
|
||||
int8_t a; int16_t b; int32_t c;
|
||||
u_int8_t e; u_int16_t f; u_int32_t g;
|
||||
a = b = c = e = f = g = 1;
|
||||
],
|
||||
[
|
||||
AC_DEFINE(HAVE_U_INTXX_T, [], [Have u_intXX_t])
|
||||
AC_DEFINE(HAVE_INTXX_T, [], [Have intXX_t])
|
||||
AC_MSG_RESULT(yes)
|
||||
],
|
||||
[AC_MSG_RESULT(no)]
|
||||
)
|
||||
fi
|
||||
|
||||
|
||||
AC_CACHE_CHECK([for u_char], ac_cv_have_u_char, [
|
||||
AC_TRY_COMPILE(
|
||||
[
|
||||
#include <sys/types.h>
|
||||
],
|
||||
[ u_char foo; foo = 125; ],
|
||||
[ ac_cv_have_u_char="yes" ],
|
||||
[ ac_cv_have_u_char="no" ]
|
||||
)
|
||||
])
|
||||
if test "x$ac_cv_have_u_char" = "xyes" ; then
|
||||
AC_DEFINE(HAVE_U_CHAR, [], [Have u_char type])
|
||||
fi
|
||||
|
||||
AC_CHECK_TYPES(sig_atomic_t,,,[#include <signal.h>])
|
||||
|
||||
AC_CHECK_TYPES(socklen_t,,,[
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_SOCKET_H
|
||||
# include <sys/socket.h>
|
||||
#endif
|
||||
])
|
||||
|
||||
AC_ARG_WITH(privsep-user,
|
||||
[ --with-privsep-user=user Specify privilege separation user],
|
||||
[ AC_DEFINE_UNQUOTED(NTPD_USER, "$withval", [Unprivileged userid])
|
||||
privsep_user=$withval ],
|
||||
[ privsep_user=_ntp ]
|
||||
)
|
||||
AC_SUBST(privsep_user)
|
||||
|
||||
AC_ARG_WITH(privsep-path,
|
||||
[ --with-privsep-path=path Specify privilege separation chroot path],
|
||||
[ AC_DEFINE_UNQUOTED(NTPD_CHROOT_DIR, "$withval",
|
||||
[Privilege separation chroot path])
|
||||
privsep_path=$withval ],
|
||||
[ privsep_path=/var/empty ]
|
||||
)
|
||||
AC_SUBST(privsep_path)
|
||||
|
||||
STRIP_OPT=-s
|
||||
AC_ARG_ENABLE(strip,
|
||||
[ --disable-strip Disable calling strip(1) on install],
|
||||
[
|
||||
if test "x$enableval" = "xno" ; then
|
||||
STRIP_OPT=
|
||||
fi
|
||||
]
|
||||
)
|
||||
AC_SUBST(STRIP_OPT)
|
||||
|
||||
AC_ARG_WITH(builtin-arc4random,
|
||||
[ --with-builtin-arc4random Use builtin arc4random rather than OpenSSL's],
|
||||
[ builtin_arc4random=$withval ]
|
||||
)
|
||||
|
||||
AC_ARG_WITH(mantype,
|
||||
[ --with-mantype=man|cat|doc Set man page type],
|
||||
[
|
||||
case "$withval" in
|
||||
man|cat|doc)
|
||||
MANTYPE=$withval
|
||||
;;
|
||||
*)
|
||||
AC_MSG_ERROR(invalid man type: $withval)
|
||||
;;
|
||||
esac
|
||||
]
|
||||
)
|
||||
if test -z "$MANTYPE"; then
|
||||
TestPath="/usr/bin${PATH_SEPARATOR}/usr/ucb"
|
||||
AC_PATH_PROGS(NROFF, nroff awf, /bin/false, $TestPath)
|
||||
AC_MSG_CHECKING(man page format)
|
||||
if ${NROFF} -mdoc ${srcdir}/ntpd.8 >/dev/null 2>&1; then
|
||||
MANTYPE=doc
|
||||
elif ${NROFF} -man ${srcdir}/ntpd.8 >/dev/null 2>&1; then
|
||||
MANTYPE=man
|
||||
else
|
||||
MANTYPE=cat
|
||||
fi
|
||||
AC_MSG_RESULT($MANTYPE)
|
||||
fi
|
||||
AC_SUBST(MANTYPE)
|
||||
if test "$MANTYPE" = "doc"; then
|
||||
mansubdir=man;
|
||||
else
|
||||
mansubdir=$MANTYPE;
|
||||
fi
|
||||
AC_SUBST(mansubdir)
|
||||
|
||||
# Search for OpenSSL if required.
|
||||
if test "$ac_cv_func_arc4random" != "yes" && test "x$builtin_arc4random" != "xyes"; then
|
||||
saved_CPPFLAGS="$CPPFLAGS"
|
||||
saved_LDFLAGS="$LDFLAGS"
|
||||
AC_ARG_WITH(ssl-dir,
|
||||
[ --with-ssl-dir=PATH Specify path to OpenSSL installation ],
|
||||
[
|
||||
if test "x$withval" != "xno" ; then
|
||||
if test -d "$withval/lib"; then
|
||||
if test -n "${need_dash_r}"; then
|
||||
LDFLAGS="-L${withval}/lib -R${withval}/lib ${LDFLAGS}"
|
||||
else
|
||||
LDFLAGS="-L${withval}/lib ${LDFLAGS}"
|
||||
fi
|
||||
else
|
||||
if test -n "${need_dash_r}"; then
|
||||
LDFLAGS="-L${withval} -R${withval} ${LDFLAGS}"
|
||||
else
|
||||
LDFLAGS="-L${withval} ${LDFLAGS}"
|
||||
fi
|
||||
fi
|
||||
if test -d "$withval/include"; then
|
||||
CPPFLAGS="-I${withval}/include ${CPPFLAGS}"
|
||||
else
|
||||
CPPFLAGS="-I${withval} ${CPPFLAGS}"
|
||||
fi
|
||||
fi
|
||||
]
|
||||
)
|
||||
saved_LIBS="$LIBS"
|
||||
LIBS="-lcrypto $LIBS"
|
||||
AC_TRY_LINK_FUNC(RAND_add, AC_DEFINE(HAVE_OPENSSL, [], [Have OpenSSL]),
|
||||
[
|
||||
dnl Check default openssl install dir
|
||||
if test -n "${need_dash_r}"; then
|
||||
LDFLAGS="-L/usr/local/ssl/lib -R/usr/local/ssl/lib ${saved_LDFLAGS}"
|
||||
else
|
||||
LDFLAGS="-L/usr/local/ssl/lib ${saved_LDFLAGS}"
|
||||
fi
|
||||
CPPFLAGS="-I/usr/local/ssl/include ${saved_CPPFLAGS}"
|
||||
AC_TRY_LINK_FUNC(RAND_add, AC_DEFINE(HAVE_OPENSSL),
|
||||
[
|
||||
AC_MSG_WARN([*** Can't find recent OpenSSL libcrypto, enabling internal arc4random ***])
|
||||
builtin_arc4random=yes
|
||||
LIBS="$saved_LIBS"
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
fi
|
||||
|
||||
if test "$ac_cv_func_arc4random" != "yes" && test "x$builtin_arc4random" != "xyes"; then
|
||||
# Determine OpenSSL header version
|
||||
AC_MSG_CHECKING([OpenSSL header version])
|
||||
AC_RUN_IFELSE(
|
||||
[
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <openssl/opensslv.h>
|
||||
#define DATA "conftest.sslincver"
|
||||
int main(void) {
|
||||
FILE *fd;
|
||||
int rc;
|
||||
|
||||
fd = fopen(DATA,"w");
|
||||
if(fd == NULL)
|
||||
exit(1);
|
||||
|
||||
if ((rc = fprintf(fd ,"%x (%s)\n", OPENSSL_VERSION_NUMBER, OPENSSL_VERSION_TEXT)) <0)
|
||||
exit(1);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
],
|
||||
[
|
||||
ssl_header_ver=`cat conftest.sslincver`
|
||||
AC_MSG_RESULT($ssl_header_ver)
|
||||
],
|
||||
[
|
||||
AC_MSG_RESULT(not found)
|
||||
AC_MSG_ERROR(OpenSSL version header not found.)
|
||||
],
|
||||
[
|
||||
AC_MSG_WARN([cross compiling: not checked])
|
||||
]
|
||||
)
|
||||
|
||||
# Determine OpenSSL library version
|
||||
AC_MSG_CHECKING([OpenSSL library version])
|
||||
AC_RUN_IFELSE(
|
||||
[
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <openssl/opensslv.h>
|
||||
#include <openssl/crypto.h>
|
||||
#define DATA "conftest.ssllibver"
|
||||
int main(void) {
|
||||
FILE *fd;
|
||||
int rc;
|
||||
|
||||
fd = fopen(DATA,"w");
|
||||
if(fd == NULL)
|
||||
exit(1);
|
||||
|
||||
if ((rc = fprintf(fd ,"%x (%s)\n", SSLeay(), SSLeay_version(SSLEAY_VERSION))) <0)
|
||||
exit(1);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
],
|
||||
[
|
||||
ssl_library_ver=`cat conftest.ssllibver`
|
||||
AC_MSG_RESULT($ssl_library_ver)
|
||||
],
|
||||
[
|
||||
AC_MSG_RESULT(not found)
|
||||
AC_MSG_ERROR(OpenSSL library not found.)
|
||||
],
|
||||
[
|
||||
AC_MSG_WARN([cross compiling: not checking])
|
||||
]
|
||||
)
|
||||
|
||||
# Sanity check OpenSSL headers
|
||||
AC_MSG_CHECKING([whether OpenSSL's headers match the library])
|
||||
AC_RUN_IFELSE(
|
||||
[
|
||||
#include <string.h>
|
||||
#include <openssl/opensslv.h>
|
||||
int main(void) { exit(SSLeay() == OPENSSL_VERSION_NUMBER ? 0 : 1); }
|
||||
],
|
||||
[
|
||||
AC_MSG_RESULT(yes)
|
||||
],
|
||||
[
|
||||
AC_MSG_RESULT(no)
|
||||
AC_MSG_ERROR([Your OpenSSL headers do not match your library.
|
||||
Check config.log for details.
|
||||
Also see contrib/findssl.sh for help identifying header/library mismatches.])
|
||||
],
|
||||
[
|
||||
AC_MSG_WARN([cross compiling: not checking])
|
||||
]
|
||||
)
|
||||
|
||||
### Configure cryptographic random number support
|
||||
|
||||
# Check wheter OpenSSL seeds itself
|
||||
AC_MSG_CHECKING([whether OpenSSL's PRNG is internally seeded])
|
||||
AC_RUN_IFELSE(
|
||||
[
|
||||
#include <string.h>
|
||||
#include <openssl/rand.h>
|
||||
int main(void) { exit(RAND_status() == 1 ? 0 : 1); }
|
||||
],
|
||||
[
|
||||
OPENSSL_SEEDS_ITSELF=yes
|
||||
AC_MSG_RESULT(yes)
|
||||
],
|
||||
[
|
||||
AC_MSG_RESULT(no)
|
||||
AC_MSG_ERROR(OpenNTPd requires a self-seeding OpenSSL)
|
||||
],
|
||||
[
|
||||
AC_MSG_WARN([cross compiling: assuming yes])
|
||||
]
|
||||
)
|
||||
fi
|
||||
|
||||
AC_CACHE_CHECK([whether $CC implements __FUNCTION__], ac_cv_cc_implements___FUNCTION__, [
|
||||
AC_TRY_LINK([
|
||||
#include <stdio.h>
|
||||
],
|
||||
[ printf("%s", __FUNCTION__); ],
|
||||
[ ac_cv_cc_implements___FUNCTION__="yes" ],
|
||||
[ ac_cv_cc_implements___FUNCTION__="no" ]
|
||||
)
|
||||
])
|
||||
if test "x$ac_cv_cc_implements___FUNCTION__" = "xyes" ; then
|
||||
AC_DEFINE(HAVE___FUNCTION__, 1, [have __FUNCTION__ macro])
|
||||
fi
|
||||
|
||||
AC_CACHE_CHECK([whether $CC implements __func__], ac_cv_cc_implements___func__, [
|
||||
AC_TRY_LINK([
|
||||
#include <stdio.h>
|
||||
],
|
||||
[ printf("%s", __func__); ],
|
||||
[ ac_cv_cc_implements___func__="yes" ],
|
||||
[ ac_cv_cc_implements___func__="no" ]
|
||||
)
|
||||
])
|
||||
if test "x$ac_cv_cc_implements___func__" = "xyes" ; then
|
||||
AC_DEFINE(HAVE___func__, 1, [have __func__ macro])
|
||||
fi
|
||||
|
||||
AC_CONFIG_FILES([Makefile openbsd-compat/Makefile])
|
||||
AC_OUTPUT
|
||||
79
external/bsd/openntpd/dist/contrib/redhat/ntpd
vendored
Normal file
79
external/bsd/openntpd/dist/contrib/redhat/ntpd
vendored
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
#! /bin/bash
|
||||
#
|
||||
# ntpd Time synchronization daemon
|
||||
#
|
||||
# chkconfig: 2345 90 60
|
||||
# description: ntpd is a time synchronization daemon
|
||||
# processname: ntpd
|
||||
# config: /etc/ntpd.conf
|
||||
# pidfile: /var/run/ntpd.pid
|
||||
|
||||
# Source function library.
|
||||
. /etc/init.d/functions
|
||||
|
||||
RETVAL=0
|
||||
|
||||
# See how we were called.
|
||||
|
||||
prog="ntpd"
|
||||
|
||||
start() {
|
||||
echo -n $"Starting $prog: "
|
||||
daemon ntpd
|
||||
RETVAL=$?
|
||||
echo
|
||||
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/ntpd
|
||||
return $RETVAL
|
||||
}
|
||||
|
||||
stop() {
|
||||
echo -n $"Stopping $prog: "
|
||||
killproc ntpd 2>/dev/null
|
||||
RETVAL=$?
|
||||
echo
|
||||
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ntpd
|
||||
return $RETVAL
|
||||
}
|
||||
|
||||
rhstatus() {
|
||||
status ntpd
|
||||
}
|
||||
|
||||
restart() {
|
||||
stop
|
||||
start
|
||||
}
|
||||
|
||||
reload() {
|
||||
echo -n $"Reloading ntpd daemon configuration: "
|
||||
killproc ntpd -HUP
|
||||
retval=$?
|
||||
echo
|
||||
return $RETVAL
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
start
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
restart)
|
||||
restart
|
||||
;;
|
||||
reload)
|
||||
reload
|
||||
;;
|
||||
status)
|
||||
rhstatus
|
||||
;;
|
||||
condrestart)
|
||||
[ -f /var/lock/subsys/ntpd ] && restart || :
|
||||
;;
|
||||
*)
|
||||
echo $"Usage: $0 {start|stop|status|reload|restart|condrestart}"
|
||||
exit 1
|
||||
esac
|
||||
|
||||
exit $?
|
||||
77
external/bsd/openntpd/dist/contrib/redhat/openntpd.spec
vendored
Normal file
77
external/bsd/openntpd/dist/contrib/redhat/openntpd.spec
vendored
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
Summary: NTP Time Synchronization Client
|
||||
Name: openntpd
|
||||
Version: 3.7p1
|
||||
Release: 1
|
||||
Copyright: BSD License
|
||||
Group: Applications/System
|
||||
Source: %{name}-%{version}.tar.gz
|
||||
BuildRoot: %{_tmppath}/%{name}-root
|
||||
BuildRequires: openssl-devel
|
||||
Requires: /usr/sbin/useradd, /usr/sbin/usermod
|
||||
Requires: /sbin/chkconfig
|
||||
|
||||
#Patch1: openntpd-3.6p1-linux-adjtimex3.patch
|
||||
|
||||
%description
|
||||
NTP Time Synchronization Client - http://www.openntpd.org
|
||||
|
||||
%prep
|
||||
%setup -q -n %{name}-%{version}
|
||||
#%patch1 -p0
|
||||
|
||||
%build
|
||||
./configure \
|
||||
--sbindir=%{_sbindir} \
|
||||
--mandir=%{_mandir} \
|
||||
--sysconfdir=%{_sysconfdir} \
|
||||
--with-privsep-user=ntp
|
||||
%{__make}
|
||||
|
||||
%clean
|
||||
%{__rm} -rf $RPM_BUILD_ROOT
|
||||
|
||||
%install
|
||||
%{__rm} -rf $RPM_BUILD_ROOT
|
||||
%{__make} install DESTDIR=$RPM_BUILD_ROOT INSTALL="%{__install} -p"
|
||||
%{__mkdir_p} $RPM_BUILD_ROOT/%{_initrddir}
|
||||
%{__cp} contrib/redhat/ntpd $RPM_BUILD_ROOT/%{_initrddir}
|
||||
|
||||
%pre
|
||||
%{__mkdir_p} /var/empty/ntpd
|
||||
%{__chown} 0 /var/empty/ntpd
|
||||
%{__chgrp} 0 /var/empty/ntpd
|
||||
%{__chmod} 0755 /var/empty/ntpd
|
||||
|
||||
if ! /usr/bin/id ntp &>/dev/null; then
|
||||
useradd -c "OpenNTPD Unprivileged User" -u 38 -r -d /var/empty/ntpd ntp &>/dev/null || \
|
||||
%logmsg "Unexpected error adding user \"ntp\". Aborting installation."
|
||||
fi
|
||||
/usr/sbin/usermod -d /var/empty/ntpd -s /sbin/nologin ntp &>/dev/null || :
|
||||
|
||||
|
||||
|
||||
%post
|
||||
/sbin/chkconfig --add ntpd
|
||||
|
||||
%preun
|
||||
if [ $1 -eq 0 ]; then
|
||||
/sbin/service ntpd stop &>/dev/null || :
|
||||
/sbin/chkconfig --del ntpd
|
||||
/usr/sbin/userdel ntp
|
||||
exit 0
|
||||
fi
|
||||
|
||||
%postun
|
||||
/sbin/service ntp condrestart &>/dev/null || :
|
||||
|
||||
|
||||
%files
|
||||
%defattr(-,root,root,-)
|
||||
%doc ChangeLog CREDITS README LICENCE
|
||||
%config(noreplace) %attr(644, root, root) %{_sysconfdir}/ntpd.conf
|
||||
%config %attr(755, root, root) %{_initrddir}/ntpd
|
||||
%attr(755, root, root) %{_sbindir}/*
|
||||
%attr(644, root, root) %{_mandir}/*
|
||||
|
||||
%changelog
|
||||
|
||||
214
external/bsd/openntpd/dist/defines.h
vendored
Normal file
214
external/bsd/openntpd/dist/defines.h
vendored
Normal file
|
|
@ -0,0 +1,214 @@
|
|||
/* $Id: defines.h,v 1.25 2006/01/19 08:00:32 dtucker Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004, 2005 Darren Tucker.
|
||||
*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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.
|
||||
*/
|
||||
|
||||
#ifndef HAVE_SETPROCTITLE
|
||||
# define setproctitle(x)
|
||||
#endif
|
||||
|
||||
#if !defined(SA_LEN)
|
||||
# if defined(HAVE_STRUCT_SOCKADDR_SA_LEN)
|
||||
# define SA_LEN(x) ((x)->sa_len)
|
||||
# else
|
||||
# define SA_LEN(x) ((x)->sa_family == AF_INET6 ? \
|
||||
sizeof(struct sockaddr_in6) : \
|
||||
sizeof(struct sockaddr_in))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef SYSCONFDIR
|
||||
# define SYSCONFDIR "/etc"
|
||||
#endif
|
||||
|
||||
#ifndef IOV_MAX
|
||||
# if defined(__FreeBSD__) || (defined(__APPLE__) && defined(__MACH__))
|
||||
# define IOV_MAX 1024 /* FreeBSD 4/Mac OS X don't define this in userspace */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef INFTIM
|
||||
# define INFTIM (-1)
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_BZERO
|
||||
# define bzero(a,b) memset((a), 0, (b))
|
||||
#endif
|
||||
|
||||
#ifdef MODEMASK
|
||||
# undef MODEMASK
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
# define MAX(a,b) (((a)>(b))?(a):(b))
|
||||
#endif
|
||||
|
||||
#ifndef _PATH_DEVNULL
|
||||
# define _PATH_DEVNULL "/dev/null"
|
||||
#endif
|
||||
|
||||
#if !defined(__GNUC__) || (__GNUC__ < 2)
|
||||
# define __attribute__(x)
|
||||
#endif /* !defined(__GNUC__) || (__GNUC__ < 2) */
|
||||
|
||||
#if !defined(HAVE___func__) && defined(HAVE___FUNCTION__)
|
||||
# define __func__ __FUNCTION__
|
||||
#elif !defined(HAVE___func__)
|
||||
# define __func__ ""
|
||||
#endif
|
||||
|
||||
/* Types */
|
||||
|
||||
/* If sys/types.h does not supply intXX_t, supply them ourselves */
|
||||
/* (or die trying) */
|
||||
|
||||
#ifndef HAVE_U_INT
|
||||
typedef unsigned int u_int;
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_INTXX_T
|
||||
# if (SIZEOF_CHAR == 1)
|
||||
typedef char int8_t;
|
||||
# else
|
||||
# error "8 bit int type not found."
|
||||
# endif
|
||||
# if (SIZEOF_SHORT_INT == 2)
|
||||
typedef short int int16_t;
|
||||
# else
|
||||
# ifdef _UNICOS
|
||||
# if (SIZEOF_SHORT_INT == 4)
|
||||
typedef short int16_t;
|
||||
# else
|
||||
typedef long int16_t;
|
||||
# endif
|
||||
# else
|
||||
# error "16 bit int type not found."
|
||||
# endif /* _UNICOS */
|
||||
# endif
|
||||
# if (SIZEOF_INT == 4)
|
||||
typedef int int32_t;
|
||||
# else
|
||||
# ifdef _UNICOS
|
||||
typedef long int32_t;
|
||||
# else
|
||||
# error "32 bit int type not found."
|
||||
# endif /* _UNICOS */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* If sys/types.h does not supply u_intXX_t, supply them ourselves */
|
||||
#ifndef HAVE_U_INTXX_T
|
||||
# ifdef HAVE_UINTXX_T
|
||||
typedef uint8_t u_int8_t;
|
||||
typedef uint16_t u_int16_t;
|
||||
typedef uint32_t u_int32_t;
|
||||
# define HAVE_U_INTXX_T 1
|
||||
# else
|
||||
# if (SIZEOF_CHAR == 1)
|
||||
typedef unsigned char u_int8_t;
|
||||
# else
|
||||
# error "8 bit int type not found."
|
||||
# endif
|
||||
# if (SIZEOF_SHORT_INT == 2)
|
||||
typedef unsigned short int u_int16_t;
|
||||
# else
|
||||
# ifdef _UNICOS
|
||||
# if (SIZEOF_SHORT_INT == 4)
|
||||
typedef unsigned short u_int16_t;
|
||||
# else
|
||||
typedef unsigned long u_int16_t;
|
||||
# endif
|
||||
# else
|
||||
# error "16 bit int type not found."
|
||||
# endif
|
||||
# endif
|
||||
# if (SIZEOF_INT == 4)
|
||||
typedef unsigned int u_int32_t;
|
||||
# else
|
||||
# ifdef _UNICOS
|
||||
typedef unsigned long u_int32_t;
|
||||
# else
|
||||
# error "32 bit int type not found."
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
#define __BIT_TYPES_DEFINED__
|
||||
#endif
|
||||
|
||||
/* 64-bit types */
|
||||
#ifndef HAVE_INT64_T
|
||||
# if (SIZEOF_LONG_INT == 8)
|
||||
typedef long int int64_t;
|
||||
# else
|
||||
# if (SIZEOF_LONG_LONG_INT == 8)
|
||||
typedef long long int int64_t;
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
#ifndef HAVE_U_INT64_T
|
||||
# if (SIZEOF_LONG_INT == 8)
|
||||
typedef unsigned long int u_int64_t;
|
||||
# else
|
||||
# if (SIZEOF_LONG_LONG_INT == 8)
|
||||
typedef unsigned long long int u_int64_t;
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SOCKLEN_T
|
||||
# ifdef SOCKLEN_T_IS_SIZE_T
|
||||
typedef size_t socklen_t;
|
||||
# else
|
||||
typedef int socklen_t;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* FSF bison 1.875 wants this to prevent conflicting definitions of YYSTYPE */
|
||||
#define YYSTYPE_IS_DECLARED 1
|
||||
|
||||
#if defined(HAVE_SETEUID) && defined(HAVE_SETREUID)
|
||||
# define seteuid(a) (setreuid(-1, a))
|
||||
#endif
|
||||
#if defined(HAVE_SETEGID) && defined(HAVE_SETREGID)
|
||||
# define setegid(a) (setregid(-1, a))
|
||||
#endif
|
||||
|
||||
#if !defined(IOV_MAX) && defined(DEF_IOV_MAX)
|
||||
# define IOV_MAX DEF_IOV_MAX
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY) && \
|
||||
defined(HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY)
|
||||
# define ss_family __ss_family
|
||||
#endif
|
||||
|
||||
#if defined(BROKEN_GETADDRINFO) && defined(HAVE_GETADDRINFO)
|
||||
# undef HAVE_GETADDRINFO
|
||||
#endif
|
||||
#if defined(BROKEN_GETADDRINFO) && defined(HAVE_FREEADDRINFO)
|
||||
# undef HAVE_FREEADDRINFO
|
||||
#endif
|
||||
#if defined(BROKEN_GETADDRINFO) && defined(HAVE_GAI_STRERROR)
|
||||
# undef HAVE_GAI_STRERROR
|
||||
#endif
|
||||
|
||||
#ifndef __dead
|
||||
# define __dead
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_GETIFADDRS) && defined(USE_SIOCGIFCONF)
|
||||
# define GETIFADDRS_VIA_SIOCGIFCONF
|
||||
#endif
|
||||
170
external/bsd/openntpd/dist/imsg.c
vendored
Normal file
170
external/bsd/openntpd/dist/imsg.c
vendored
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
/* $OpenBSD: imsg.c,v 1.11 2005/04/26 15:18:22 henning Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||
*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, 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.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ntpd.h"
|
||||
|
||||
void
|
||||
imsg_init(struct imsgbuf *ibuf, int fd)
|
||||
{
|
||||
msgbuf_init(&ibuf->w);
|
||||
bzero(&ibuf->r, sizeof(ibuf->r));
|
||||
ibuf->fd = fd;
|
||||
ibuf->w.fd = fd;
|
||||
ibuf->pid = getpid();
|
||||
}
|
||||
|
||||
int
|
||||
imsg_read(struct imsgbuf *ibuf)
|
||||
{
|
||||
ssize_t n;
|
||||
|
||||
if ((n = read(ibuf->fd, ibuf->r.buf + ibuf->r.wpos,
|
||||
sizeof(ibuf->r.buf) - ibuf->r.wpos)) == -1) {
|
||||
if (errno != EINTR && errno != EAGAIN) {
|
||||
log_warn("imsg_read: pipe read error");
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
ibuf->r.wpos += n;
|
||||
|
||||
return (n);
|
||||
}
|
||||
|
||||
int
|
||||
imsg_get(struct imsgbuf *ibuf, struct imsg *imsg)
|
||||
{
|
||||
size_t av, left, datalen;
|
||||
|
||||
av = ibuf->r.wpos;
|
||||
|
||||
if (IMSG_HEADER_SIZE > av)
|
||||
return (0);
|
||||
|
||||
memcpy(&imsg->hdr, ibuf->r.buf, sizeof(imsg->hdr));
|
||||
if (imsg->hdr.len < IMSG_HEADER_SIZE ||
|
||||
imsg->hdr.len > MAX_IMSGSIZE) {
|
||||
log_warnx("imsg_get: imsg hdr len %u out of bounds, type=%u",
|
||||
imsg->hdr.len, imsg->hdr.type);
|
||||
return (-1);
|
||||
}
|
||||
if (imsg->hdr.len > av)
|
||||
return (0);
|
||||
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
|
||||
ibuf->r.rptr = ibuf->r.buf + IMSG_HEADER_SIZE;
|
||||
if ((imsg->data = malloc(datalen)) == NULL) {
|
||||
log_warn("imsg_get");
|
||||
return (-1);
|
||||
}
|
||||
memcpy(imsg->data, ibuf->r.rptr, datalen);
|
||||
|
||||
if (imsg->hdr.len < av) {
|
||||
left = av - imsg->hdr.len;
|
||||
memmove(&ibuf->r.buf, ibuf->r.buf + imsg->hdr.len, left);
|
||||
ibuf->r.wpos = left;
|
||||
} else
|
||||
ibuf->r.wpos = 0;
|
||||
|
||||
return (datalen + IMSG_HEADER_SIZE);
|
||||
}
|
||||
|
||||
int
|
||||
imsg_compose(struct imsgbuf *ibuf, enum imsg_type type, u_int32_t peerid,
|
||||
pid_t pid, void *data, u_int16_t datalen)
|
||||
{
|
||||
struct buf *wbuf;
|
||||
int n;
|
||||
|
||||
if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL)
|
||||
return (-1);
|
||||
|
||||
if (imsg_add(wbuf, data, datalen) == -1)
|
||||
return (-1);
|
||||
|
||||
if ((n = imsg_close(ibuf, wbuf)) < 0)
|
||||
return (-1);
|
||||
|
||||
return (n);
|
||||
}
|
||||
|
||||
struct buf *
|
||||
imsg_create(struct imsgbuf *ibuf, enum imsg_type type, u_int32_t peerid,
|
||||
pid_t pid, u_int16_t datalen)
|
||||
{
|
||||
struct buf *wbuf;
|
||||
struct imsg_hdr hdr;
|
||||
|
||||
if (datalen > MAX_IMSGSIZE - IMSG_HEADER_SIZE) {
|
||||
log_warnx("imsg_create: len %u > MAX_IMSGSIZE; "
|
||||
"type %u peerid %lu", datalen + IMSG_HEADER_SIZE,
|
||||
type, peerid);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
hdr.len = datalen + IMSG_HEADER_SIZE;
|
||||
hdr.type = type;
|
||||
hdr.peerid = peerid;
|
||||
hdr.pid = pid;
|
||||
if ((wbuf = buf_open(hdr.len)) == NULL) {
|
||||
log_warn("imsg_create: buf_open");
|
||||
return (NULL);
|
||||
}
|
||||
if (imsg_add(wbuf, &hdr, sizeof(hdr)) == -1)
|
||||
return (NULL);
|
||||
|
||||
return (wbuf);
|
||||
}
|
||||
|
||||
int
|
||||
imsg_add(struct buf *msg, void *data, u_int16_t datalen)
|
||||
{
|
||||
if (datalen)
|
||||
if (buf_add(msg, data, datalen) == -1) {
|
||||
log_warnx("imsg_add: buf_add error");
|
||||
buf_free(msg);
|
||||
return (-1);
|
||||
}
|
||||
return (datalen);
|
||||
}
|
||||
|
||||
int
|
||||
imsg_close(struct imsgbuf *ibuf, struct buf *msg)
|
||||
{
|
||||
int n;
|
||||
|
||||
if ((n = buf_close(&ibuf->w, msg)) < 0) {
|
||||
log_warnx("imsg_close: buf_close error");
|
||||
buf_free(msg);
|
||||
return (-1);
|
||||
}
|
||||
return (n);
|
||||
}
|
||||
|
||||
void
|
||||
imsg_free(struct imsg *imsg)
|
||||
{
|
||||
free(imsg->data);
|
||||
}
|
||||
92
external/bsd/openntpd/dist/includes.h
vendored
Normal file
92
external/bsd/openntpd/dist/includes.h
vendored
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
/* $Id: includes.h,v 1.22 2006/05/13 11:09:33 dtucker Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004, 2005 Darren Tucker.
|
||||
*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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.
|
||||
*/
|
||||
|
||||
#ifndef OPENNTPD_INCLUDES_H
|
||||
#define OPENNTPD_INCLUDES_H
|
||||
|
||||
#define RCSID(msg) \
|
||||
static /**/const char *const rcsid[] = { (const char *)rcsid, "\100(#)" msg }
|
||||
|
||||
#include "config.h"
|
||||
#include "version.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <netinet/in.h>
|
||||
#include <grp.h>
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef HAVE_CTYPE_H
|
||||
# include <ctype.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h> /* for bzero */
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TIMERS_H
|
||||
# include <sys/timers.h>
|
||||
#endif
|
||||
#ifdef HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_BITYPES_H
|
||||
# include <sys/bitypes.h> /* For u_intXX_t */
|
||||
#endif
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
# include <sys/stat.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_SOCKET_H
|
||||
# include <sys/socket.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_FCNTL_H
|
||||
# include <sys/fcntl.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETDB_H
|
||||
# include <netdb.h>
|
||||
#endif
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
# include <arpa/inet.h>
|
||||
#endif
|
||||
#ifdef HAVE_STDARG_H
|
||||
# include <stdarg.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
# include <syslog.h>
|
||||
#endif
|
||||
#ifdef HAVE_ARPA_NAMESER_H
|
||||
# include <arpa/nameser.h>
|
||||
#endif
|
||||
|
||||
#include "defines.h"
|
||||
#ifndef HAVE_SYS_QUEUE_H
|
||||
#include "openbsd-compat/sys-queue.h"
|
||||
#endif
|
||||
#include "openbsd-compat/openbsd-compat.h"
|
||||
|
||||
#endif /* OPENNTPD_INCLUDES_H */
|
||||
251
external/bsd/openntpd/dist/install-sh
vendored
Executable file
251
external/bsd/openntpd/dist/install-sh
vendored
Executable file
|
|
@ -0,0 +1,251 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# install - install a program, script, or datafile
|
||||
# This comes from X11R5 (mit/util/scripts/install.sh).
|
||||
#
|
||||
# Copyright 1991 by the Massachusetts Institute of Technology
|
||||
#
|
||||
# Permission to use, copy, modify, distribute, and sell this software and its
|
||||
# documentation for any purpose is hereby granted without fee, provided that
|
||||
# the above copyright notice appear in all copies and that both that
|
||||
# copyright notice and this permission notice appear in supporting
|
||||
# documentation, and that the name of M.I.T. not be used in advertising or
|
||||
# publicity pertaining to distribution of the software without specific,
|
||||
# written prior permission. M.I.T. makes no representations about the
|
||||
# suitability of this software for any purpose. It is provided "as is"
|
||||
# without express or implied warranty.
|
||||
#
|
||||
# Calling this script install-sh is preferred over install.sh, to prevent
|
||||
# `make' implicit rules from creating a file called install from it
|
||||
# when there is no Makefile.
|
||||
#
|
||||
# This script is compatible with the BSD install script, but was written
|
||||
# from scratch. It can only install one file at a time, a restriction
|
||||
# shared with many OS's install programs.
|
||||
|
||||
|
||||
# set DOITPROG to echo to test this script
|
||||
|
||||
# Don't use :- since 4.3BSD and earlier shells don't like it.
|
||||
doit="${DOITPROG-}"
|
||||
|
||||
|
||||
# put in absolute paths if you don't have them in your path; or use env. vars.
|
||||
|
||||
mvprog="${MVPROG-mv}"
|
||||
cpprog="${CPPROG-cp}"
|
||||
chmodprog="${CHMODPROG-chmod}"
|
||||
chownprog="${CHOWNPROG-chown}"
|
||||
chgrpprog="${CHGRPPROG-chgrp}"
|
||||
stripprog="${STRIPPROG-strip}"
|
||||
rmprog="${RMPROG-rm}"
|
||||
mkdirprog="${MKDIRPROG-mkdir}"
|
||||
|
||||
transformbasename=""
|
||||
transform_arg=""
|
||||
instcmd="$mvprog"
|
||||
chmodcmd="$chmodprog 0755"
|
||||
chowncmd=""
|
||||
chgrpcmd=""
|
||||
stripcmd=""
|
||||
rmcmd="$rmprog -f"
|
||||
mvcmd="$mvprog"
|
||||
src=""
|
||||
dst=""
|
||||
dir_arg=""
|
||||
|
||||
while [ x"$1" != x ]; do
|
||||
case $1 in
|
||||
-c) instcmd="$cpprog"
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-d) dir_arg=true
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-m) chmodcmd="$chmodprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-o) chowncmd="$chownprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-g) chgrpcmd="$chgrpprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-s) stripcmd="$stripprog"
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
|
||||
shift
|
||||
continue;;
|
||||
|
||||
*) if [ x"$src" = x ]
|
||||
then
|
||||
src=$1
|
||||
else
|
||||
# this colon is to work around a 386BSD /bin/sh bug
|
||||
:
|
||||
dst=$1
|
||||
fi
|
||||
shift
|
||||
continue;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ x"$src" = x ]
|
||||
then
|
||||
echo "install: no input file specified"
|
||||
exit 1
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
if [ x"$dir_arg" != x ]; then
|
||||
dst=$src
|
||||
src=""
|
||||
|
||||
if [ -d $dst ]; then
|
||||
instcmd=:
|
||||
chmodcmd=""
|
||||
else
|
||||
instcmd=mkdir
|
||||
fi
|
||||
else
|
||||
|
||||
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
|
||||
# might cause directories to be created, which would be especially bad
|
||||
# if $src (and thus $dsttmp) contains '*'.
|
||||
|
||||
if [ -f $src -o -d $src ]
|
||||
then
|
||||
true
|
||||
else
|
||||
echo "install: $src does not exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ x"$dst" = x ]
|
||||
then
|
||||
echo "install: no destination specified"
|
||||
exit 1
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
# If destination is a directory, append the input filename; if your system
|
||||
# does not like double slashes in filenames, you may need to add some logic
|
||||
|
||||
if [ -d $dst ]
|
||||
then
|
||||
dst="$dst"/`basename $src`
|
||||
else
|
||||
true
|
||||
fi
|
||||
fi
|
||||
|
||||
## this sed command emulates the dirname command
|
||||
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
|
||||
|
||||
# Make sure that the destination directory exists.
|
||||
# this part is taken from Noah Friedman's mkinstalldirs script
|
||||
|
||||
# Skip lots of stat calls in the usual case.
|
||||
if [ ! -d "$dstdir" ]; then
|
||||
defaultIFS='
|
||||
'
|
||||
IFS="${IFS-${defaultIFS}}"
|
||||
|
||||
oIFS="${IFS}"
|
||||
# Some sh's can't handle IFS=/ for some reason.
|
||||
IFS='%'
|
||||
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
|
||||
IFS="${oIFS}"
|
||||
|
||||
pathcomp=''
|
||||
|
||||
while [ $# -ne 0 ] ; do
|
||||
pathcomp="${pathcomp}${1}"
|
||||
shift
|
||||
|
||||
if [ ! -d "${pathcomp}" ] ;
|
||||
then
|
||||
$mkdirprog "${pathcomp}"
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
pathcomp="${pathcomp}/"
|
||||
done
|
||||
fi
|
||||
|
||||
if [ x"$dir_arg" != x ]
|
||||
then
|
||||
$doit $instcmd $dst &&
|
||||
|
||||
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
|
||||
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
|
||||
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
|
||||
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
|
||||
else
|
||||
|
||||
# If we're going to rename the final executable, determine the name now.
|
||||
|
||||
if [ x"$transformarg" = x ]
|
||||
then
|
||||
dstfile=`basename $dst`
|
||||
else
|
||||
dstfile=`basename $dst $transformbasename |
|
||||
sed $transformarg`$transformbasename
|
||||
fi
|
||||
|
||||
# don't allow the sed command to completely eliminate the filename
|
||||
|
||||
if [ x"$dstfile" = x ]
|
||||
then
|
||||
dstfile=`basename $dst`
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
# Make a temp file name in the proper directory.
|
||||
|
||||
dsttmp=$dstdir/#inst.$$#
|
||||
|
||||
# Move or copy the file name to the temp name
|
||||
|
||||
$doit $instcmd $src $dsttmp &&
|
||||
|
||||
trap "rm -f ${dsttmp}" 0 &&
|
||||
|
||||
# and set any options; do chmod last to preserve setuid bits
|
||||
|
||||
# If any of these fail, we abort the whole thing. If we want to
|
||||
# ignore errors from any of these, just make sure not to ignore
|
||||
# errors from the above "$doit $instcmd $src $dsttmp" command.
|
||||
|
||||
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
|
||||
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
|
||||
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
|
||||
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
|
||||
|
||||
# Now rename the file to the real destination.
|
||||
|
||||
$doit $rmcmd -f $dstdir/$dstfile &&
|
||||
$doit $mvcmd $dsttmp $dstdir/$dstfile
|
||||
|
||||
fi &&
|
||||
|
||||
|
||||
exit 0
|
||||
166
external/bsd/openntpd/dist/log.c
vendored
Normal file
166
external/bsd/openntpd/dist/log.c
vendored
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
/* $OpenBSD: log.c,v 1.7 2005/03/31 12:14:01 henning Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||
*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, 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.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "ntpd.h"
|
||||
|
||||
int debug;
|
||||
|
||||
void logit(int, const char *, ...);
|
||||
|
||||
void
|
||||
log_init(int n_debug)
|
||||
{
|
||||
extern char *__progname;
|
||||
|
||||
debug = n_debug;
|
||||
|
||||
if (!debug)
|
||||
openlog(__progname, LOG_PID | LOG_NDELAY, LOG_DAEMON);
|
||||
|
||||
tzset();
|
||||
}
|
||||
|
||||
void
|
||||
logit(int pri, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vlog(pri, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
vlog(int pri, const char *fmt, va_list ap)
|
||||
{
|
||||
char *nfmt;
|
||||
|
||||
if (debug) {
|
||||
/* best effort in out of mem situations */
|
||||
if (asprintf(&nfmt, "%s\n", fmt) == -1) {
|
||||
vfprintf(stderr, fmt, ap);
|
||||
fprintf(stderr, "\n");
|
||||
} else {
|
||||
vfprintf(stderr, nfmt, ap);
|
||||
free(nfmt);
|
||||
}
|
||||
fflush(stderr);
|
||||
} else
|
||||
vsyslog(pri, fmt, ap);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
log_warn(const char *emsg, ...)
|
||||
{
|
||||
char *nfmt;
|
||||
va_list ap;
|
||||
|
||||
/* best effort to even work in out of memory situations */
|
||||
if (emsg == NULL)
|
||||
logit(LOG_CRIT, "%s", strerror(errno));
|
||||
else {
|
||||
va_start(ap, emsg);
|
||||
|
||||
if (asprintf(&nfmt, "%s: %s", emsg, strerror(errno)) == -1) {
|
||||
/* we tried it... */
|
||||
vlog(LOG_CRIT, emsg, ap);
|
||||
logit(LOG_CRIT, "%s", strerror(errno));
|
||||
} else {
|
||||
vlog(LOG_CRIT, nfmt, ap);
|
||||
free(nfmt);
|
||||
}
|
||||
va_end(ap);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
log_warnx(const char *emsg, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, emsg);
|
||||
vlog(LOG_CRIT, emsg, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
log_info(const char *emsg, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, emsg);
|
||||
vlog(LOG_INFO, emsg, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
log_debug(const char *emsg, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
if (debug) {
|
||||
va_start(ap, emsg);
|
||||
vlog(LOG_DEBUG, emsg, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
fatal(const char *emsg)
|
||||
{
|
||||
if (emsg == NULL)
|
||||
logit(LOG_CRIT, "fatal: %s", strerror(errno));
|
||||
else
|
||||
if (errno)
|
||||
logit(LOG_CRIT, "fatal: %s: %s",
|
||||
emsg, strerror(errno));
|
||||
else
|
||||
logit(LOG_CRIT, "fatal: %s", emsg);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void
|
||||
fatalx(const char *emsg)
|
||||
{
|
||||
errno = 0;
|
||||
fatal(emsg);
|
||||
}
|
||||
|
||||
const char *
|
||||
log_sockaddr(struct sockaddr *sa)
|
||||
{
|
||||
static char buf[NI_MAXHOST];
|
||||
|
||||
if (getnameinfo(sa, SA_LEN(sa), buf, sizeof(buf), NULL, 0,
|
||||
NI_NUMERICHOST))
|
||||
return ("(unknown)");
|
||||
else
|
||||
return (buf);
|
||||
}
|
||||
351
external/bsd/openntpd/dist/mdoc2man.awk
vendored
Normal file
351
external/bsd/openntpd/dist/mdoc2man.awk
vendored
Normal file
|
|
@ -0,0 +1,351 @@
|
|||
#!/usr/bin/awk
|
||||
#
|
||||
# Version history:
|
||||
# v3, I put the program under a proper license
|
||||
# Dan Nelson <dnelson@allantgroup.com> added .An, .Aq and fixed a typo
|
||||
# v2, fixed to work on GNU awk --posix and MacOS X
|
||||
# v1, first attempt, didn't work on MacOS X
|
||||
#
|
||||
# Copyright (c) 2003 Peter Stuge <stuge-mdoc2man@cdy.org>
|
||||
#
|
||||
# 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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.
|
||||
|
||||
|
||||
BEGIN {
|
||||
optlist=0
|
||||
oldoptlist=0
|
||||
nospace=0
|
||||
synopsis=0
|
||||
reference=0
|
||||
block=0
|
||||
ext=0
|
||||
extopt=0
|
||||
literal=0
|
||||
prenl=0
|
||||
breakw=0
|
||||
line=""
|
||||
}
|
||||
|
||||
function wtail() {
|
||||
retval=""
|
||||
while(w<nwords) {
|
||||
if(length(retval))
|
||||
retval=retval OFS
|
||||
retval=retval words[++w]
|
||||
}
|
||||
return retval
|
||||
}
|
||||
|
||||
function add(str) {
|
||||
for(;prenl;prenl--)
|
||||
line=line "\n"
|
||||
line=line str
|
||||
}
|
||||
|
||||
! /^\./ {
|
||||
for(;prenl;prenl--)
|
||||
print ""
|
||||
print
|
||||
if(literal)
|
||||
print ".br"
|
||||
next
|
||||
}
|
||||
|
||||
/^\.\\"/ { next }
|
||||
|
||||
{
|
||||
option=0
|
||||
parens=0
|
||||
angles=0
|
||||
sub("^\\.","")
|
||||
nwords=split($0,words)
|
||||
for(w=1;w<=nwords;w++) {
|
||||
skip=0
|
||||
if(match(words[w],"^Li|Pf$")) {
|
||||
skip=1
|
||||
} else if(match(words[w],"^Xo$")) {
|
||||
skip=1
|
||||
ext=1
|
||||
if(length(line)&&!(match(line," $")||prenl))
|
||||
add(OFS)
|
||||
} else if(match(words[w],"^Xc$")) {
|
||||
skip=1
|
||||
ext=0
|
||||
if(!extopt)
|
||||
prenl++
|
||||
w=nwords
|
||||
} else if(match(words[w],"^Bd$")) {
|
||||
skip=1
|
||||
if(match(words[w+1],"-literal")) {
|
||||
literal=1
|
||||
prenl++
|
||||
w=nwords
|
||||
}
|
||||
} else if(match(words[w],"^Ed$")) {
|
||||
skip=1
|
||||
literal=0
|
||||
} else if(match(words[w],"^Ns$")) {
|
||||
skip=1
|
||||
if(!nospace)
|
||||
nospace=1
|
||||
sub(" $","",line)
|
||||
} else if(match(words[w],"^No$")) {
|
||||
skip=1
|
||||
sub(" $","",line)
|
||||
add(words[++w])
|
||||
} else if(match(words[w],"^Dq$")) {
|
||||
skip=1
|
||||
add("``")
|
||||
add(words[++w])
|
||||
while(w<nwords&&!match(words[w+1],"^[\\.,]"))
|
||||
add(OFS words[++w])
|
||||
add("''")
|
||||
if(!nospace&&match(words[w+1],"^[\\.,]"))
|
||||
nospace=1
|
||||
} else if(match(words[w],"^Sq|Ql$")) {
|
||||
skip=1
|
||||
add("`" words[++w] "'")
|
||||
if(!nospace&&match(words[w+1],"^[\\.,]"))
|
||||
nospace=1
|
||||
} else if(match(words[w],"^Oo$")) {
|
||||
skip=1
|
||||
extopt=1
|
||||
if(!nospace)
|
||||
nospace=1
|
||||
add("[")
|
||||
} else if(match(words[w],"^Oc$")) {
|
||||
skip=1
|
||||
extopt=0
|
||||
add("]")
|
||||
}
|
||||
if(!skip) {
|
||||
if(!nospace&&length(line)&&!(match(line," $")||prenl))
|
||||
add(OFS)
|
||||
if(nospace==1)
|
||||
nospace=0
|
||||
}
|
||||
if(match(words[w],"^Dd$")) {
|
||||
date=wtail()
|
||||
next
|
||||
} else if(match(words[w],"^Dt$")) {
|
||||
id=wtail()
|
||||
next
|
||||
} else if(match(words[w],"^Ox$")) {
|
||||
add("OpenBSD")
|
||||
skip=1
|
||||
} else if(match(words[w],"^Os$")) {
|
||||
add(".TH " id " \"" date "\" \"" wtail() "\"")
|
||||
} else if(match(words[w],"^Sh$")) {
|
||||
add(".SH")
|
||||
synopsis=match(words[w+1],"SYNOPSIS")
|
||||
} else if(match(words[w],"^Xr$")) {
|
||||
add("\\fB" words[++w] "\\fP(" words[++w] ")" words[++w])
|
||||
} else if(match(words[w],"^Rs$")) {
|
||||
split("",refauthors)
|
||||
nrefauthors=0
|
||||
reftitle=""
|
||||
refissue=""
|
||||
refdate=""
|
||||
refopt=""
|
||||
reference=1
|
||||
next
|
||||
} else if(match(words[w],"^Re$")) {
|
||||
prenl++
|
||||
for(i=nrefauthors-1;i>0;i--) {
|
||||
add(refauthors[i])
|
||||
if(i>1)
|
||||
add(", ")
|
||||
}
|
||||
if(nrefauthors>1)
|
||||
add(" and ")
|
||||
add(refauthors[0] ", \\fI" reftitle "\\fP")
|
||||
if(length(refissue))
|
||||
add(", " refissue)
|
||||
if(length(refdate))
|
||||
add(", " refdate)
|
||||
if(length(refopt))
|
||||
add(", " refopt)
|
||||
add(".")
|
||||
reference=0
|
||||
} else if(reference) {
|
||||
if(match(words[w],"^%A$")) { refauthors[nrefauthors++]=wtail() }
|
||||
if(match(words[w],"^%T$")) {
|
||||
reftitle=wtail()
|
||||
sub("^\"","",reftitle)
|
||||
sub("\"$","",reftitle)
|
||||
}
|
||||
if(match(words[w],"^%N$")) { refissue=wtail() }
|
||||
if(match(words[w],"^%D$")) { refdate=wtail() }
|
||||
if(match(words[w],"^%O$")) { refopt=wtail() }
|
||||
} else if(match(words[w],"^Nm$")) {
|
||||
if(synopsis) {
|
||||
add(".br")
|
||||
prenl++
|
||||
}
|
||||
n=words[++w]
|
||||
if(!length(name))
|
||||
name=n
|
||||
if(!length(n))
|
||||
n=name
|
||||
add("\\fB" n "\\fP")
|
||||
if(!nospace&&match(words[w+1],"^[\\.,]"))
|
||||
nospace=1
|
||||
} else if(match(words[w],"^Nd$")) {
|
||||
add("\\- " wtail())
|
||||
} else if(match(words[w],"^Fl$")) {
|
||||
add("\\fB\\-" words[++w] "\\fP")
|
||||
if(!nospace&&match(words[w+1],"^[\\.,]"))
|
||||
nospace=1
|
||||
} else if(match(words[w],"^Ar$")) {
|
||||
add("\\fI")
|
||||
if(w==nwords)
|
||||
add("file ...\\fP")
|
||||
else {
|
||||
add(words[++w] "\\fP")
|
||||
while(match(words[w+1],"^\\|$"))
|
||||
add(OFS words[++w] " \\fI" words[++w] "\\fP")
|
||||
}
|
||||
if(!nospace&&match(words[w+1],"^[\\.,]"))
|
||||
nospace=1
|
||||
} else if(match(words[w],"^Cm$")) {
|
||||
add("\\fB" words[++w] "\\fP")
|
||||
while(w<nwords&&match(words[w+1],"^[\\.,:;)]"))
|
||||
add(words[++w])
|
||||
} else if(match(words[w],"^Op$")) {
|
||||
option=1
|
||||
if(!nospace)
|
||||
nospace=1
|
||||
add("[")
|
||||
} else if(match(words[w],"^Pp$")) {
|
||||
prenl++
|
||||
} else if(match(words[w],"^An$")) {
|
||||
prenl++
|
||||
} else if(match(words[w],"^Ss$")) {
|
||||
add(".SS")
|
||||
} else if(match(words[w],"^Pa$")&&!option) {
|
||||
add("\\fI")
|
||||
w++
|
||||
if(match(words[w],"^\\."))
|
||||
add("\\&")
|
||||
add(words[w] "\\fP")
|
||||
while(w<nwords&&match(words[w+1],"^[\\.,:;)]"))
|
||||
add(words[++w])
|
||||
} else if(match(words[w],"^Dv$")) {
|
||||
add(".BR")
|
||||
} else if(match(words[w],"^Em|Ev$")) {
|
||||
add(".IR")
|
||||
} else if(match(words[w],"^Pq$")) {
|
||||
add("(")
|
||||
nospace=1
|
||||
parens=1
|
||||
} else if(match(words[w],"^Aq$")) {
|
||||
add("<")
|
||||
nospace=1
|
||||
angles=1
|
||||
} else if(match(words[w],"^S[xy]$")) {
|
||||
add(".B " wtail())
|
||||
} else if(match(words[w],"^Ic$")) {
|
||||
plain=1
|
||||
add("\\fB")
|
||||
while(w<nwords) {
|
||||
w++
|
||||
if(match(words[w],"^Op$")) {
|
||||
w++
|
||||
add("[")
|
||||
words[nwords]=words[nwords] "]"
|
||||
}
|
||||
if(match(words[w],"^Ar$")) {
|
||||
add("\\fI" words[++w] "\\fP")
|
||||
} else if(match(words[w],"^[\\.,]")) {
|
||||
sub(" $","",line)
|
||||
if(plain) {
|
||||
add("\\fP")
|
||||
plain=0
|
||||
}
|
||||
add(words[w])
|
||||
} else {
|
||||
if(!plain) {
|
||||
add("\\fB")
|
||||
plain=1
|
||||
}
|
||||
add(words[w])
|
||||
}
|
||||
if(!nospace)
|
||||
add(OFS)
|
||||
}
|
||||
sub(" $","",line)
|
||||
if(plain)
|
||||
add("\\fP")
|
||||
} else if(match(words[w],"^Bl$")) {
|
||||
oldoptlist=optlist
|
||||
if(match(words[w+1],"-bullet"))
|
||||
optlist=1
|
||||
else if(match(words[w+1],"-enum")) {
|
||||
optlist=2
|
||||
enum=0
|
||||
} else if(match(words[w+1],"-tag"))
|
||||
optlist=3
|
||||
else if(match(words[w+1],"-item"))
|
||||
optlist=4
|
||||
else if(match(words[w+1],"-bullet"))
|
||||
optlist=1
|
||||
w=nwords
|
||||
} else if(match(words[w],"^El$")) {
|
||||
optlist=oldoptlist
|
||||
} else if(match(words[w],"^Bk$")) {
|
||||
if(match(words[w+1],"-words")) {
|
||||
w++
|
||||
breakw=1
|
||||
}
|
||||
} else if(match(words[w],"^Ek$")) {
|
||||
breakw=0
|
||||
} else if(match(words[w],"^It$")&&optlist) {
|
||||
if(optlist==1)
|
||||
add(".IP \\(bu")
|
||||
else if(optlist==2)
|
||||
add(".IP " ++enum ".")
|
||||
else if(optlist==3) {
|
||||
add(".TP")
|
||||
prenl++
|
||||
if(match(words[w+1],"^Pa$|^Ev$")) {
|
||||
add(".B")
|
||||
w++
|
||||
}
|
||||
} else if(optlist==4)
|
||||
add(".IP")
|
||||
} else if(match(words[w],"^Sm$")) {
|
||||
if(match(words[w+1],"off"))
|
||||
nospace=2
|
||||
else if(match(words[w+1],"on"))
|
||||
nospace=0
|
||||
w++
|
||||
} else if(!skip) {
|
||||
add(words[w])
|
||||
}
|
||||
}
|
||||
if(match(line,"^\\.[^a-zA-Z]"))
|
||||
sub("^\\.","",line)
|
||||
if(parens)
|
||||
add(")")
|
||||
if(angles)
|
||||
add(">")
|
||||
if(option)
|
||||
add("]")
|
||||
if(ext&&!extopt&&!match(line," $"))
|
||||
add(OFS)
|
||||
if(!ext&&!extopt&&length(line)) {
|
||||
print line
|
||||
prenl=0
|
||||
line=""
|
||||
}
|
||||
}
|
||||
546
external/bsd/openntpd/dist/ntp.c
vendored
Normal file
546
external/bsd/openntpd/dist/ntp.c
vendored
Normal file
|
|
@ -0,0 +1,546 @@
|
|||
/* $OpenBSD: ntp.c,v 1.67 2005/08/10 13:48:36 dtucker Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||
* Copyright (c) 2004 Alexander Guy <alexander.guy@andern.org>
|
||||
*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, 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.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef HAVE_PATHS_H
|
||||
# include <paths.h>
|
||||
#endif
|
||||
#ifdef HAVE_POLL_H
|
||||
# include <poll.h>
|
||||
#endif
|
||||
#include <pwd.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ntpd.h"
|
||||
#include "ntp.h"
|
||||
|
||||
#define PFD_PIPE_MAIN 0
|
||||
#define PFD_MAX 1
|
||||
|
||||
volatile sig_atomic_t ntp_quit = 0;
|
||||
struct imsgbuf *ibuf_main;
|
||||
struct ntpd_conf *conf;
|
||||
u_int peer_cnt;
|
||||
|
||||
void ntp_sighdlr(int);
|
||||
int ntp_dispatch_imsg(void);
|
||||
void peer_add(struct ntp_peer *);
|
||||
void peer_remove(struct ntp_peer *);
|
||||
int offset_compare(const void *, const void *);
|
||||
|
||||
void
|
||||
ntp_sighdlr(int sig)
|
||||
{
|
||||
switch (sig) {
|
||||
case SIGINT:
|
||||
case SIGTERM:
|
||||
ntp_quit = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pid_t
|
||||
ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf)
|
||||
{
|
||||
int a, b, nfds, i, j, idx_peers, timeout, nullfd;
|
||||
u_int pfd_elms = 0, idx2peer_elms = 0;
|
||||
u_int listener_cnt, new_cnt, sent_cnt, trial_cnt;
|
||||
pid_t pid;
|
||||
struct pollfd *pfd = NULL;
|
||||
struct passwd *pw;
|
||||
struct servent *se;
|
||||
struct listen_addr *la;
|
||||
struct ntp_peer *p;
|
||||
struct ntp_peer **idx2peer = NULL;
|
||||
struct timespec tp;
|
||||
struct stat stb;
|
||||
time_t nextaction;
|
||||
void *newp;
|
||||
char *chrootdir;
|
||||
|
||||
switch (pid = fork()) {
|
||||
case -1:
|
||||
fatal("cannot fork");
|
||||
break;
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
return (pid);
|
||||
}
|
||||
|
||||
if ((se = getservbyname("ntp", "udp")) == NULL)
|
||||
fatal("getservbyname");
|
||||
|
||||
if ((pw = getpwnam(NTPD_USER)) == NULL)
|
||||
fatal("getpwnam");
|
||||
|
||||
if ((nullfd = open(_PATH_DEVNULL, O_RDWR, 0)) == -1)
|
||||
fatal(NULL);
|
||||
|
||||
#ifdef NTPD_CHROOT_DIR
|
||||
chrootdir = NTPD_CHROOT_DIR;
|
||||
#else
|
||||
chrootdir = pw->pw_dir;
|
||||
#endif
|
||||
|
||||
if (stat(chrootdir, &stb) == -1)
|
||||
fatal("stat");
|
||||
if (stb.st_uid != 0 || (stb.st_mode & (S_IWGRP|S_IWOTH)) != 0)
|
||||
fatal("bad privsep dir permissions");
|
||||
/* Don't chroot on Minix -- we won't be able to hit /dev/udp */
|
||||
#ifndef __minix
|
||||
if (chroot(chrootdir) == -1)
|
||||
fatal("chroot");
|
||||
#endif
|
||||
if (chdir("/") == -1)
|
||||
fatal("chdir(\"/\")");
|
||||
|
||||
if (!nconf->debug) {
|
||||
dup2(nullfd, STDIN_FILENO);
|
||||
dup2(nullfd, STDOUT_FILENO);
|
||||
dup2(nullfd, STDERR_FILENO);
|
||||
}
|
||||
close(nullfd);
|
||||
|
||||
setproctitle("ntp engine");
|
||||
|
||||
conf = nconf;
|
||||
setup_listeners(se, conf, &listener_cnt);
|
||||
|
||||
endservent();
|
||||
|
||||
signal(SIGTERM, ntp_sighdlr);
|
||||
signal(SIGINT, ntp_sighdlr);
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
signal(SIGHUP, SIG_IGN);
|
||||
|
||||
close(pipe_prnt[0]);
|
||||
if ((ibuf_main = malloc(sizeof(struct imsgbuf))) == NULL)
|
||||
fatal(NULL);
|
||||
imsg_init(ibuf_main, pipe_prnt[1]);
|
||||
|
||||
TAILQ_FOREACH(p, &conf->ntp_peers, entry)
|
||||
client_peer_init(p);
|
||||
|
||||
bzero(&conf->status, sizeof(conf->status));
|
||||
conf->status.synced = 0;
|
||||
clock_getres(CLOCK_REALTIME, &tp);
|
||||
b = 1000000000 / tp.tv_nsec; /* convert to Hz */
|
||||
for (a = 0; b > 1; a--, b >>= 1)
|
||||
;
|
||||
conf->status.precision = a;
|
||||
conf->scale = 1;
|
||||
|
||||
log_info("ntp engine ready");
|
||||
|
||||
peer_cnt = 0;
|
||||
TAILQ_FOREACH(p, &conf->ntp_peers, entry)
|
||||
peer_cnt++;
|
||||
|
||||
while (ntp_quit == 0) {
|
||||
if (peer_cnt > idx2peer_elms) {
|
||||
if ((newp = realloc(idx2peer, sizeof(void *) *
|
||||
peer_cnt)) == NULL) {
|
||||
/* panic for now */
|
||||
log_warn("could not resize idx2peer from %u -> "
|
||||
"%u entries", idx2peer_elms, peer_cnt);
|
||||
fatalx("exiting");
|
||||
}
|
||||
idx2peer = newp;
|
||||
idx2peer_elms = peer_cnt;
|
||||
}
|
||||
|
||||
new_cnt = PFD_MAX + peer_cnt + listener_cnt;
|
||||
if (new_cnt > pfd_elms) {
|
||||
if ((newp = realloc(pfd, sizeof(struct pollfd) *
|
||||
new_cnt)) == NULL) {
|
||||
/* panic for now */
|
||||
log_warn("could not resize pfd from %u -> "
|
||||
"%u entries", pfd_elms, new_cnt);
|
||||
fatalx("exiting");
|
||||
}
|
||||
pfd = newp;
|
||||
pfd_elms = new_cnt;
|
||||
}
|
||||
|
||||
bzero(pfd, sizeof(struct pollfd) * pfd_elms);
|
||||
bzero(idx2peer, sizeof(void *) * idx2peer_elms);
|
||||
nextaction = time(NULL) + 3600;
|
||||
pfd[PFD_PIPE_MAIN].fd = ibuf_main->fd;
|
||||
pfd[PFD_PIPE_MAIN].events = POLLIN;
|
||||
|
||||
i = 1;
|
||||
TAILQ_FOREACH(la, &conf->listen_addrs, entry) {
|
||||
pfd[i].fd = la->fd;
|
||||
pfd[i].events = POLLIN;
|
||||
i++;
|
||||
}
|
||||
|
||||
idx_peers = i;
|
||||
sent_cnt = trial_cnt = 0;
|
||||
TAILQ_FOREACH(p, &conf->ntp_peers, entry) {
|
||||
if (p->next > 0 && p->next <= time(NULL)) {
|
||||
if (p->state > STATE_DNS_INPROGRESS)
|
||||
trial_cnt++;
|
||||
if (client_query(p) == 0)
|
||||
sent_cnt++;
|
||||
}
|
||||
if (p->next > 0 && p->next < nextaction)
|
||||
nextaction = p->next;
|
||||
|
||||
if (p->deadline > 0 && p->deadline < nextaction)
|
||||
nextaction = p->deadline;
|
||||
if (p->deadline > 0 && p->deadline <= time(NULL)) {
|
||||
timeout = error_interval();
|
||||
log_debug("no reply from %s received in time, "
|
||||
"next query %ds", log_sockaddr(
|
||||
(struct sockaddr *)&p->addr->ss), timeout);
|
||||
if (p->trustlevel >= TRUSTLEVEL_BADPEER &&
|
||||
(p->trustlevel /= 2) < TRUSTLEVEL_BADPEER)
|
||||
log_info("peer %s now invalid",
|
||||
log_sockaddr(
|
||||
(struct sockaddr *)&p->addr->ss));
|
||||
client_nextaddr(p);
|
||||
set_next(p, timeout);
|
||||
}
|
||||
|
||||
if (p->state == STATE_QUERY_SENT) {
|
||||
pfd[i].fd = p->query->fd;
|
||||
pfd[i].events = POLLIN;
|
||||
idx2peer[i - idx_peers] = p;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (conf->settime &&
|
||||
((trial_cnt > 0 && sent_cnt == 0) || peer_cnt == 0))
|
||||
priv_settime(0); /* no good peers, don't wait */
|
||||
|
||||
if (ibuf_main->w.queued > 0)
|
||||
pfd[PFD_PIPE_MAIN].events |= POLLOUT;
|
||||
|
||||
timeout = nextaction - time(NULL);
|
||||
if (timeout < 0)
|
||||
timeout = 0;
|
||||
|
||||
if ((nfds = poll(pfd, i, timeout * 1000)) == -1)
|
||||
if (errno != EINTR) {
|
||||
log_warn("poll error");
|
||||
ntp_quit = 1;
|
||||
}
|
||||
|
||||
if (nfds > 0 && (pfd[PFD_PIPE_MAIN].revents & POLLOUT))
|
||||
if (msgbuf_write(&ibuf_main->w) < 0) {
|
||||
log_warn("pipe write error (to parent)");
|
||||
ntp_quit = 1;
|
||||
}
|
||||
|
||||
if (nfds > 0 && pfd[PFD_PIPE_MAIN].revents & (POLLIN|POLLERR)) {
|
||||
nfds--;
|
||||
if (ntp_dispatch_imsg() == -1)
|
||||
ntp_quit = 1;
|
||||
}
|
||||
|
||||
for (j = 1; nfds > 0 && j < idx_peers; j++)
|
||||
if (pfd[j].revents & (POLLIN|POLLERR)) {
|
||||
nfds--;
|
||||
if (server_dispatch(pfd[j].fd, conf) == -1)
|
||||
ntp_quit = 1;
|
||||
}
|
||||
|
||||
for (; nfds > 0 && j < i; j++)
|
||||
if (pfd[j].revents & (POLLIN|POLLERR)) {
|
||||
nfds--;
|
||||
if (client_dispatch(idx2peer[j - idx_peers],
|
||||
conf->settime) == -1)
|
||||
ntp_quit = 1;
|
||||
}
|
||||
}
|
||||
|
||||
msgbuf_write(&ibuf_main->w);
|
||||
msgbuf_clear(&ibuf_main->w);
|
||||
free(ibuf_main);
|
||||
|
||||
log_info("ntp engine exiting");
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
int
|
||||
ntp_dispatch_imsg(void)
|
||||
{
|
||||
struct imsg imsg;
|
||||
int n;
|
||||
struct ntp_peer *peer, *npeer;
|
||||
u_int16_t dlen;
|
||||
u_char *p;
|
||||
struct ntp_addr *h;
|
||||
|
||||
if ((n = imsg_read(ibuf_main)) == -1)
|
||||
return (-1);
|
||||
|
||||
if (n == 0) { /* connection closed */
|
||||
log_warnx("ntp_dispatch_imsg in ntp engine: pipe closed");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if ((n = imsg_get(ibuf_main, &imsg)) == -1)
|
||||
return (-1);
|
||||
|
||||
if (n == 0)
|
||||
break;
|
||||
|
||||
switch (imsg.hdr.type) {
|
||||
case IMSG_ADJTIME:
|
||||
memcpy(&n, imsg.data, sizeof(n));
|
||||
if (n == 1 && !conf->status.synced) {
|
||||
log_info("clock is now synced");
|
||||
conf->status.synced = 1;
|
||||
} else if (n == 0 && conf->status.synced) {
|
||||
log_info("clock is now unsynced");
|
||||
conf->status.synced = 0;
|
||||
}
|
||||
break;
|
||||
case IMSG_HOST_DNS:
|
||||
TAILQ_FOREACH(peer, &conf->ntp_peers, entry)
|
||||
if (peer->id == imsg.hdr.peerid)
|
||||
break;
|
||||
if (peer == NULL) {
|
||||
log_warnx("IMSG_HOST_DNS with invalid peerID");
|
||||
break;
|
||||
}
|
||||
if (peer->addr != NULL) {
|
||||
log_warnx("IMSG_HOST_DNS but addr != NULL!");
|
||||
break;
|
||||
}
|
||||
|
||||
dlen = imsg.hdr.len - IMSG_HEADER_SIZE;
|
||||
if (dlen == 0) { /* no data -> temp error */
|
||||
peer->state = STATE_DNS_TEMPFAIL;
|
||||
break;
|
||||
}
|
||||
|
||||
p = (u_char *)imsg.data;
|
||||
while (dlen >= sizeof(struct sockaddr_storage)) {
|
||||
if ((h = calloc(1, sizeof(struct ntp_addr))) ==
|
||||
NULL)
|
||||
fatal(NULL);
|
||||
memcpy(&h->ss, p, sizeof(h->ss));
|
||||
p += sizeof(h->ss);
|
||||
dlen -= sizeof(h->ss);
|
||||
if (peer->addr_head.pool) {
|
||||
npeer = new_peer();
|
||||
h->next = NULL;
|
||||
npeer->addr = h;
|
||||
npeer->addr_head.a = h;
|
||||
client_peer_init(npeer);
|
||||
npeer->state = STATE_DNS_DONE;
|
||||
peer_add(npeer);
|
||||
} else {
|
||||
h->next = peer->addr;
|
||||
peer->addr = h;
|
||||
peer->addr_head.a = peer->addr;
|
||||
peer->state = STATE_DNS_DONE;
|
||||
}
|
||||
}
|
||||
if (dlen != 0)
|
||||
fatalx("IMSG_HOST_DNS: dlen != 0");
|
||||
if (peer->addr_head.pool)
|
||||
peer_remove(peer);
|
||||
else
|
||||
client_addr_init(peer);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
imsg_free(&imsg);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
peer_add(struct ntp_peer *p)
|
||||
{
|
||||
TAILQ_INSERT_TAIL(&conf->ntp_peers, p, entry);
|
||||
peer_cnt++;
|
||||
}
|
||||
|
||||
void
|
||||
peer_remove(struct ntp_peer *p)
|
||||
{
|
||||
TAILQ_REMOVE(&conf->ntp_peers, p, entry);
|
||||
free(p);
|
||||
peer_cnt--;
|
||||
}
|
||||
|
||||
void
|
||||
priv_adjtime(void)
|
||||
{
|
||||
struct ntp_peer *p;
|
||||
int offset_cnt = 0, i = 0;
|
||||
struct ntp_peer **peers;
|
||||
double offset_median;
|
||||
|
||||
TAILQ_FOREACH(p, &conf->ntp_peers, entry) {
|
||||
if (p->trustlevel < TRUSTLEVEL_BADPEER)
|
||||
continue;
|
||||
if (!p->update.good)
|
||||
return;
|
||||
offset_cnt++;
|
||||
}
|
||||
|
||||
if ((peers = calloc(offset_cnt, sizeof(struct ntp_peer *))) == NULL)
|
||||
fatal("calloc priv_adjtime");
|
||||
|
||||
TAILQ_FOREACH(p, &conf->ntp_peers, entry) {
|
||||
if (p->trustlevel < TRUSTLEVEL_BADPEER)
|
||||
continue;
|
||||
peers[i++] = p;
|
||||
}
|
||||
|
||||
qsort(peers, offset_cnt, sizeof(struct ntp_peer *), offset_compare);
|
||||
|
||||
if (offset_cnt > 0) {
|
||||
if (offset_cnt > 1 && offset_cnt % 2 == 0) {
|
||||
offset_median =
|
||||
(peers[offset_cnt / 2 - 1]->update.offset +
|
||||
peers[offset_cnt / 2]->update.offset) / 2;
|
||||
conf->status.rootdelay =
|
||||
(peers[offset_cnt / 2 - 1]->update.delay +
|
||||
peers[offset_cnt / 2]->update.delay) / 2;
|
||||
conf->status.stratum = MAX(
|
||||
peers[offset_cnt / 2 - 1]->update.status.stratum,
|
||||
peers[offset_cnt / 2]->update.status.stratum);
|
||||
} else {
|
||||
offset_median = peers[offset_cnt / 2]->update.offset;
|
||||
conf->status.rootdelay =
|
||||
peers[offset_cnt / 2]->update.delay;
|
||||
conf->status.stratum =
|
||||
peers[offset_cnt / 2]->update.status.stratum;
|
||||
}
|
||||
conf->status.leap = peers[offset_cnt / 2]->update.status.leap;
|
||||
|
||||
imsg_compose(ibuf_main, IMSG_ADJTIME, 0, 0,
|
||||
&offset_median, sizeof(offset_median));
|
||||
|
||||
conf->status.reftime = gettime();
|
||||
conf->status.stratum++; /* one more than selected peer */
|
||||
update_scale(offset_median);
|
||||
|
||||
conf->status.refid4 =
|
||||
peers[offset_cnt / 2]->update.status.refid4;
|
||||
if (peers[offset_cnt / 2]->addr->ss.ss_family == AF_INET)
|
||||
conf->status.refid = ((struct sockaddr_in *)
|
||||
&peers[offset_cnt / 2]->addr->ss)->sin_addr.s_addr;
|
||||
else
|
||||
conf->status.refid = conf->status.refid4;
|
||||
}
|
||||
|
||||
free(peers);
|
||||
|
||||
TAILQ_FOREACH(p, &conf->ntp_peers, entry)
|
||||
p->update.good = 0;
|
||||
}
|
||||
|
||||
int
|
||||
offset_compare(const void *aa, const void *bb)
|
||||
{
|
||||
const struct ntp_peer * const *a;
|
||||
const struct ntp_peer * const *b;
|
||||
|
||||
a = aa;
|
||||
b = bb;
|
||||
|
||||
if ((*a)->update.offset < (*b)->update.offset)
|
||||
return (-1);
|
||||
else if ((*a)->update.offset > (*b)->update.offset)
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
priv_settime(double offset)
|
||||
{
|
||||
struct ntp_peer *p;
|
||||
|
||||
imsg_compose(ibuf_main, IMSG_SETTIME, 0, 0, &offset, sizeof(offset));
|
||||
conf->settime = 0;
|
||||
|
||||
TAILQ_FOREACH(p, &conf->ntp_peers, entry) {
|
||||
if (p->next)
|
||||
p->next -= offset;
|
||||
if (p->deadline)
|
||||
p->deadline -= offset;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
priv_host_dns(char *name, u_int32_t peerid)
|
||||
{
|
||||
u_int16_t dlen;
|
||||
|
||||
dlen = strlen(name) + 1;
|
||||
imsg_compose(ibuf_main, IMSG_HOST_DNS, peerid, 0, name, dlen);
|
||||
}
|
||||
|
||||
void
|
||||
update_scale(double offset)
|
||||
{
|
||||
if (offset < 0)
|
||||
offset = -offset;
|
||||
|
||||
if (offset > QSCALE_OFF_MAX)
|
||||
conf->scale = 1;
|
||||
else if (offset < QSCALE_OFF_MIN)
|
||||
conf->scale = QSCALE_OFF_MAX / QSCALE_OFF_MIN;
|
||||
else
|
||||
conf->scale = QSCALE_OFF_MAX / offset;
|
||||
}
|
||||
|
||||
time_t
|
||||
scale_interval(time_t requested)
|
||||
{
|
||||
time_t interval, r;
|
||||
|
||||
interval = requested * conf->scale;
|
||||
r = arc4random() % MAX(5, interval / 10);
|
||||
return (interval + r);
|
||||
}
|
||||
|
||||
time_t
|
||||
error_interval(void)
|
||||
{
|
||||
time_t interval, r;
|
||||
|
||||
interval = INTERVAL_QUERY_PATHETIC * QSCALE_OFF_MAX / QSCALE_OFF_MIN;
|
||||
r = arc4random() % (interval / 10);
|
||||
return (interval + r);
|
||||
}
|
||||
|
||||
152
external/bsd/openntpd/dist/ntp.h
vendored
Normal file
152
external/bsd/openntpd/dist/ntp.h
vendored
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
/* $OpenBSD: ntp.h,v 1.11 2004/12/13 12:22:52 dtucker Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
|
||||
* Copyright (c) 2004 Alexander Guy <alexander.guy@andern.org>
|
||||
*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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.
|
||||
*/
|
||||
|
||||
#ifndef _NTP_H_
|
||||
#define _NTP_H_
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
/* Style borrowed from NTP ref/tcpdump and updated for SNTPv4 (RFC2030). */
|
||||
|
||||
/*
|
||||
* RFC Section 3
|
||||
*
|
||||
* 0 1 2 3
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | Integer Part |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | Fraction Part |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
*
|
||||
* 0 1 2 3
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | Integer Part | Fraction Part |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
*/
|
||||
struct l_fixedpt {
|
||||
u_int32_t int_partl;
|
||||
u_int32_t fractionl;
|
||||
};
|
||||
|
||||
struct s_fixedpt {
|
||||
u_int16_t int_parts;
|
||||
u_int16_t fractions;
|
||||
};
|
||||
|
||||
/* RFC Section 4
|
||||
*
|
||||
* 0 1 2 3
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* |LI | VN | Mode| Stratum | Poll | Precision |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | Synchronizing Distance |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | Synchronizing Dispersion |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | Reference Clock Identifier |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | |
|
||||
* | Reference Timestamp (64 bits) |
|
||||
* | |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | |
|
||||
* | Originate Timestamp (64 bits) |
|
||||
* | |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | |
|
||||
* | Receive Timestamp (64 bits) |
|
||||
* | |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | |
|
||||
* | Transmit Timestamp (64 bits) |
|
||||
* | |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | Key Identifier (optional) (32) |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | |
|
||||
* | |
|
||||
* | Message Digest (optional) (128) |
|
||||
* | |
|
||||
* | |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
*
|
||||
*/
|
||||
|
||||
#define NTP_DIGESTSIZE 16
|
||||
#define NTP_MSGSIZE_NOAUTH 48
|
||||
#define NTP_MSGSIZE (NTP_MSGSIZE_NOAUTH + 4 + NTP_DIGESTSIZE)
|
||||
|
||||
struct ntp_msg {
|
||||
u_int8_t status; /* status of local clock and leap info */
|
||||
u_int8_t stratum; /* Stratum level */
|
||||
u_int8_t ppoll; /* poll value */
|
||||
int8_t precision;
|
||||
struct s_fixedpt rootdelay;
|
||||
struct s_fixedpt dispersion;
|
||||
u_int32_t refid;
|
||||
struct l_fixedpt reftime;
|
||||
struct l_fixedpt orgtime;
|
||||
struct l_fixedpt rectime;
|
||||
struct l_fixedpt xmttime;
|
||||
u_int32_t keyid;
|
||||
u_int8_t digest[NTP_DIGESTSIZE];
|
||||
};
|
||||
|
||||
struct ntp_query {
|
||||
int fd;
|
||||
struct ntp_msg msg;
|
||||
double xmttime;
|
||||
};
|
||||
|
||||
/*
|
||||
* Leap Second Codes (high order two bits)
|
||||
*/
|
||||
#define LI_NOWARNING (0 << 6) /* no warning */
|
||||
#define LI_PLUSSEC (1 << 6) /* add a second (61 seconds) */
|
||||
#define LI_MINUSSEC (2 << 6) /* minus a second (59 seconds) */
|
||||
#define LI_ALARM (3 << 6) /* alarm condition */
|
||||
|
||||
/*
|
||||
* Status Masks
|
||||
*/
|
||||
#define MODEMASK (7 << 0)
|
||||
#define VERSIONMASK (7 << 3)
|
||||
#define LIMASK (3 << 6)
|
||||
|
||||
/*
|
||||
* Mode values
|
||||
*/
|
||||
#define MODE_RES0 0 /* reserved */
|
||||
#define MODE_SYM_ACT 1 /* symmetric active */
|
||||
#define MODE_SYM_PAS 2 /* symmetric passive */
|
||||
#define MODE_CLIENT 3 /* client */
|
||||
#define MODE_SERVER 4 /* server */
|
||||
#define MODE_BROADCAST 5 /* broadcast */
|
||||
#define MODE_RES1 6 /* reserved for NTP control message */
|
||||
#define MODE_RES2 7 /* reserved for private use */
|
||||
|
||||
#define JAN_1970 2208988800UL /* 1970 - 1900 in seconds */
|
||||
|
||||
#define NTP_VERSION 4
|
||||
#define NTP_MAXSTRATUM 15
|
||||
|
||||
#endif /* _NTP_H_ */
|
||||
105
external/bsd/openntpd/dist/ntp_msg.c
vendored
Normal file
105
external/bsd/openntpd/dist/ntp_msg.c
vendored
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
/* $OpenBSD: ntp_msg.c,v 1.15 2005/09/24 00:32:03 dtucker Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||
* Copyright (c) 2004 Alexander Guy <alexander.guy@andern.org>
|
||||
*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, 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.
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "ntpd.h"
|
||||
#include "ntp.h"
|
||||
|
||||
int
|
||||
ntp_getmsg(struct sockaddr *sa, char *p, ssize_t len, struct ntp_msg *msg)
|
||||
{
|
||||
if (len != NTP_MSGSIZE_NOAUTH && len != NTP_MSGSIZE) {
|
||||
log_warnx("malformed packet received from %s",
|
||||
log_sockaddr(sa));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
#define copyin(f,p) memcpy(&(f), (p), sizeof(f)); (p) += sizeof(f)
|
||||
|
||||
copyin(msg->status, p);
|
||||
copyin(msg->stratum, p);
|
||||
copyin(msg->ppoll, p);
|
||||
copyin(msg->precision, p);
|
||||
copyin(msg->rootdelay.int_parts, p);
|
||||
copyin(msg->rootdelay.fractions, p);
|
||||
copyin(msg->dispersion.int_parts, p);
|
||||
copyin(msg->dispersion.fractions, p);
|
||||
copyin(msg->refid, p);
|
||||
copyin(msg->reftime.int_partl, p);
|
||||
copyin(msg->reftime.fractionl, p);
|
||||
copyin(msg->orgtime.int_partl, p);
|
||||
copyin(msg->orgtime.fractionl, p);
|
||||
copyin(msg->rectime.int_partl, p);
|
||||
copyin(msg->rectime.fractionl, p);
|
||||
copyin(msg->xmttime.int_partl, p);
|
||||
copyin(msg->xmttime.fractionl, p);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
ntp_sendmsg(int fd, struct sockaddr *sa, struct ntp_msg *msg, ssize_t len,
|
||||
int auth)
|
||||
{
|
||||
char buf[NTP_MSGSIZE];
|
||||
char *p = buf;
|
||||
socklen_t salen;
|
||||
|
||||
#define copyout(p,f) memcpy((p), &(f), sizeof(f)); p += sizeof(f)
|
||||
|
||||
copyout(p, msg->status);
|
||||
copyout(p, msg->stratum);
|
||||
copyout(p, msg->ppoll);
|
||||
copyout(p, msg->precision);
|
||||
copyout(p, msg->rootdelay.int_parts);
|
||||
copyout(p, msg->rootdelay.fractions);
|
||||
copyout(p, msg->dispersion.int_parts);
|
||||
copyout(p, msg->dispersion.fractions);
|
||||
copyout(p, msg->refid);
|
||||
copyout(p, msg->reftime.int_partl);
|
||||
copyout(p, msg->reftime.fractionl);
|
||||
copyout(p, msg->orgtime.int_partl);
|
||||
copyout(p, msg->orgtime.fractionl);
|
||||
copyout(p, msg->rectime.int_partl);
|
||||
copyout(p, msg->rectime.fractionl);
|
||||
copyout(p, msg->xmttime.int_partl);
|
||||
copyout(p, msg->xmttime.fractionl);
|
||||
|
||||
if (sa != NULL)
|
||||
salen = SA_LEN(sa);
|
||||
else
|
||||
salen = 0;
|
||||
|
||||
if (sendto(fd, &buf, len, 0, sa, salen) != len) {
|
||||
if (errno == ENOBUFS || errno == EHOSTUNREACH ||
|
||||
errno == ENETDOWN || errno == EHOSTDOWN) {
|
||||
/* logging is futile */
|
||||
return (-1);
|
||||
}
|
||||
log_warn("sendto");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
54
external/bsd/openntpd/dist/ntpd.0
vendored
Normal file
54
external/bsd/openntpd/dist/ntpd.0
vendored
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
NTPD(8) OpenBSD System Manager's Manual NTPD(8)
|
||||
|
||||
NAME
|
||||
ntpd - Network Time Protocol daemon
|
||||
|
||||
SYNOPSIS
|
||||
ntpd [-dSs] [-f file]
|
||||
|
||||
DESCRIPTION
|
||||
The ntpd daemon synchronizes the local clock to one or more remote NTP
|
||||
servers, and can also act as an NTP server itself, redistributing the lo-
|
||||
cal time. It implements the Simple Network Time Protocol version 4, as
|
||||
described in RFC 2030, and the Network Time Protocol version 3, as de-
|
||||
scribed in RFC 1305.
|
||||
|
||||
ntpd uses the adjtime(2) system call to correct the local system time
|
||||
without causing time jumps. Adjustments larger than 128ms are logged us-
|
||||
ing syslog(3). The threshold value is chosen to avoid having local clock
|
||||
drift thrash the log files. Should ntpd be started with the -d option,
|
||||
all calls to adjtime(2) will be logged.
|
||||
|
||||
When ntpd starts up, it reads settings from a configuration file, typi-
|
||||
cally ntpd.conf(5).
|
||||
|
||||
The options are as follows:
|
||||
|
||||
-d Do not daemonize. If this option is specified, ntpd will run
|
||||
in the foreground and log to stderr.
|
||||
|
||||
-f file Use file as the configuration file, instead of the default
|
||||
/etc/ntpd.conf.
|
||||
|
||||
-S Do not set the time immediately at startup. This is the de-
|
||||
fault.
|
||||
|
||||
-s Set the time immediately at startup if the local clock is off
|
||||
by more than 180 seconds. Allows for a large time correc-
|
||||
tion, eliminating the need to run rdate(8) before starting
|
||||
ntpd.
|
||||
|
||||
FILES
|
||||
/etc/ntpd.conf default ntpd configuration file
|
||||
|
||||
SEE ALSO
|
||||
date(1), adjtime(2), ntpd.conf(5), rdate(8), timed(8)
|
||||
|
||||
Network Time Protocol (Version 3), RFC 1305, March 1992.
|
||||
|
||||
Simple Network Time Protocol (SNTP) Version 4, RFC 2030, October 1996.
|
||||
|
||||
HISTORY
|
||||
The ntpd program first appeared in OpenBSD 3.6.
|
||||
|
||||
OpenBSD 3.9 July 9, 2004 1
|
||||
115
external/bsd/openntpd/dist/ntpd.8
vendored
Normal file
115
external/bsd/openntpd/dist/ntpd.8
vendored
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
.\" $OpenBSD: ntpd.8,v 1.14 2005/06/21 19:55:18 deraadt Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||
.\"
|
||||
.\" 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
.\" WHATSOEVER RESULTING FROM LOSS OF MIND, 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.
|
||||
.\"
|
||||
.Dd July 9, 2004
|
||||
.Dt NTPD 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm ntpd
|
||||
.Nd "Network Time Protocol daemon"
|
||||
.Sh SYNOPSIS
|
||||
.Nm ntpd
|
||||
.Bk -words
|
||||
.Op Fl dSs
|
||||
.Op Fl f Ar file
|
||||
.Ek
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
daemon synchronizes the local clock to one or more remote NTP servers,
|
||||
and can also act as an NTP server itself,
|
||||
redistributing the local time.
|
||||
It implements the Simple Network Time Protocol version 4,
|
||||
as described in RFC 2030,
|
||||
and the Network Time Protocol version 3,
|
||||
as described in RFC 1305.
|
||||
.Pp
|
||||
.Nm
|
||||
uses the
|
||||
.Xr adjtime 2
|
||||
system call to correct the local system time without causing time jumps.
|
||||
Adjustments larger than 128ms are logged using
|
||||
.Xr syslog 3 .
|
||||
The threshold value is chosen to avoid having local clock drift
|
||||
thrash the log files.
|
||||
Should
|
||||
.Nm
|
||||
be started with the
|
||||
.Fl d
|
||||
option, all calls to
|
||||
.Xr adjtime 2
|
||||
will be logged.
|
||||
.Pp
|
||||
When
|
||||
.Nm
|
||||
starts up, it reads settings from a configuration file,
|
||||
typically
|
||||
.Xr ntpd.conf 5 .
|
||||
.Pp
|
||||
The options are as follows:
|
||||
.Bl -tag -width "-f fileXXX"
|
||||
.It Fl d
|
||||
Do not daemonize.
|
||||
If this option is specified,
|
||||
.Nm
|
||||
will run in the foreground and log to
|
||||
.Em stderr .
|
||||
.It Fl f Ar file
|
||||
Use
|
||||
.Ar file
|
||||
as the configuration file,
|
||||
instead of the default
|
||||
.Pa /etc/ntpd.conf .
|
||||
.It Fl S
|
||||
Do not set the time immediately at startup.
|
||||
This is the default.
|
||||
.It Fl s
|
||||
Set the time immediately at startup if the local clock is off by more
|
||||
than 180 seconds.
|
||||
Allows for a large time correction,
|
||||
eliminating the need to run
|
||||
.Xr rdate 8
|
||||
before starting
|
||||
.Nm .
|
||||
.El
|
||||
.Sh FILES
|
||||
.Bl -tag -width "/etc/ntpd.confXXX" -compact
|
||||
.It Pa /etc/ntpd.conf
|
||||
default
|
||||
.Nm
|
||||
configuration file
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr date 1 ,
|
||||
.Xr adjtime 2 ,
|
||||
.Xr ntpd.conf 5 ,
|
||||
.Xr rdate 8 ,
|
||||
.Xr timed 8
|
||||
.Rs
|
||||
.%R RFC 1305
|
||||
.%T "Network Time Protocol (Version 3)"
|
||||
.%D March 1992
|
||||
.Re
|
||||
.Rs
|
||||
.%R RFC 2030
|
||||
.%T "Simple Network Time Protocol (SNTP) Version 4"
|
||||
.%D October 1996
|
||||
.Re
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
program first appeared in
|
||||
.Ox 3.6 .
|
||||
377
external/bsd/openntpd/dist/ntpd.c
vendored
Normal file
377
external/bsd/openntpd/dist/ntpd.c
vendored
Normal file
|
|
@ -0,0 +1,377 @@
|
|||
/* $OpenBSD: ntpd.c,v 1.40 2005/09/06 21:27:10 wvdputte Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||
*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, 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.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
RCSID("$Release: OpenNTPD "OPENNTPD_VERSION" $");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/wait.h>
|
||||
#include <netinet/in.h>
|
||||
#include <errno.h>
|
||||
#ifdef HAVE_POLL_H
|
||||
# include <poll.h>
|
||||
#endif
|
||||
#include <pwd.h>
|
||||
#include <resolv.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ntpd.h"
|
||||
|
||||
void sighdlr(int);
|
||||
__dead void usage(void);
|
||||
int main(int, char *[]);
|
||||
int check_child(pid_t, const char *);
|
||||
int dispatch_imsg(struct ntpd_conf *);
|
||||
int ntpd_adjtime(double);
|
||||
void ntpd_settime(double);
|
||||
|
||||
volatile sig_atomic_t quit = 0;
|
||||
volatile sig_atomic_t reconfig = 0;
|
||||
volatile sig_atomic_t sigchld = 0;
|
||||
struct imsgbuf *ibuf;
|
||||
|
||||
void
|
||||
sighdlr(int sig)
|
||||
{
|
||||
switch (sig) {
|
||||
case SIGTERM:
|
||||
case SIGINT:
|
||||
quit = 1;
|
||||
break;
|
||||
case SIGCHLD:
|
||||
sigchld = 1;
|
||||
break;
|
||||
case SIGHUP:
|
||||
reconfig = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
__dead void
|
||||
usage(void)
|
||||
{
|
||||
extern char *__progname;
|
||||
|
||||
fprintf(stderr, "usage: %s [-dSs] [-f file]\n", __progname);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#define POLL_MAX 8
|
||||
#define PFD_PIPE 0
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct ntpd_conf conf;
|
||||
struct pollfd pfd[POLL_MAX];
|
||||
pid_t chld_pid = 0, pid;
|
||||
const char *conffile;
|
||||
int ch, nfds, timeout = INFTIM;
|
||||
int pipe_chld[2];
|
||||
extern char *__progname;
|
||||
|
||||
__progname = _compat_get_progname(argv[0]);
|
||||
|
||||
conffile = CONFFILE;
|
||||
|
||||
bzero(&conf, sizeof(conf));
|
||||
|
||||
log_init(1); /* log to stderr until daemonized */
|
||||
res_init(); /* XXX */
|
||||
|
||||
while ((ch = getopt(argc, argv, "df:sS")) != -1) {
|
||||
switch (ch) {
|
||||
case 'd':
|
||||
conf.debug = 1;
|
||||
break;
|
||||
case 'f':
|
||||
conffile = optarg;
|
||||
break;
|
||||
case 's':
|
||||
conf.settime = 1;
|
||||
break;
|
||||
case 'S':
|
||||
conf.settime = 0;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
/* NOTREACHED */
|
||||
}
|
||||
}
|
||||
|
||||
if (parse_config(conffile, &conf))
|
||||
exit(1);
|
||||
|
||||
if (geteuid()) {
|
||||
fprintf(stderr, "ntpd: need root privileges\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (getpwnam(NTPD_USER) == NULL) {
|
||||
fprintf(stderr, "ntpd: unknown user %s\n", NTPD_USER);
|
||||
exit(1);
|
||||
}
|
||||
endpwent();
|
||||
|
||||
#ifndef HAVE_ARC4RANDOM
|
||||
seed_rng();
|
||||
#endif
|
||||
|
||||
if (!conf.settime) {
|
||||
log_init(conf.debug);
|
||||
if (!conf.debug)
|
||||
if (daemon(1, 0))
|
||||
fatal("daemon");
|
||||
} else
|
||||
timeout = SETTIME_TIMEOUT * 1000;
|
||||
|
||||
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_chld) == -1)
|
||||
fatal("socketpair");
|
||||
|
||||
/* fork child process */
|
||||
chld_pid = ntp_main(pipe_chld, &conf);
|
||||
|
||||
setproctitle("[priv]");
|
||||
|
||||
signal(SIGTERM, sighdlr);
|
||||
signal(SIGINT, sighdlr);
|
||||
signal(SIGCHLD, sighdlr);
|
||||
signal(SIGHUP, sighdlr);
|
||||
|
||||
close(pipe_chld[1]);
|
||||
|
||||
if ((ibuf = malloc(sizeof(struct imsgbuf))) == NULL)
|
||||
fatal(NULL);
|
||||
imsg_init(ibuf, pipe_chld[0]);
|
||||
|
||||
while (quit == 0) {
|
||||
pfd[PFD_PIPE].fd = ibuf->fd;
|
||||
pfd[PFD_PIPE].events = POLLIN;
|
||||
if (ibuf->w.queued)
|
||||
pfd[PFD_PIPE].events |= POLLOUT;
|
||||
|
||||
if ((nfds = poll(pfd, 1, timeout)) == -1)
|
||||
if (errno != EINTR) {
|
||||
log_warn("poll error");
|
||||
quit = 1;
|
||||
}
|
||||
|
||||
if (nfds == 0 && conf.settime) {
|
||||
conf.settime = 0;
|
||||
timeout = INFTIM;
|
||||
log_init(conf.debug);
|
||||
log_debug("no reply received in time, skipping initial "
|
||||
"time setting");
|
||||
if (!conf.debug)
|
||||
if (daemon(1, 0))
|
||||
fatal("daemon");
|
||||
}
|
||||
|
||||
if (nfds > 0 && (pfd[PFD_PIPE].revents & POLLOUT))
|
||||
if (msgbuf_write(&ibuf->w) < 0) {
|
||||
log_warn("pipe write error (to child)");
|
||||
quit = 1;
|
||||
}
|
||||
|
||||
if (nfds > 0 && pfd[PFD_PIPE].revents & POLLIN) {
|
||||
nfds--;
|
||||
if (dispatch_imsg(&conf) == -1)
|
||||
quit = 1;
|
||||
}
|
||||
|
||||
if (sigchld) {
|
||||
if (check_child(chld_pid, "child")) {
|
||||
quit = 1;
|
||||
chld_pid = 0;
|
||||
}
|
||||
sigchld = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
signal(SIGCHLD, SIG_DFL);
|
||||
|
||||
if (chld_pid)
|
||||
kill(chld_pid, SIGTERM);
|
||||
|
||||
do {
|
||||
if ((pid = wait(NULL)) == -1 &&
|
||||
errno != EINTR && errno != ECHILD)
|
||||
fatal("wait");
|
||||
} while (pid != -1 || (pid == -1 && errno == EINTR));
|
||||
|
||||
msgbuf_clear(&ibuf->w);
|
||||
free(ibuf);
|
||||
log_info("Terminating");
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
check_child(pid_t pid, const char *pname)
|
||||
{
|
||||
int status, sig;
|
||||
char *signame;
|
||||
|
||||
if (waitpid(pid, &status, WNOHANG) > 0) {
|
||||
if (WIFEXITED(status)) {
|
||||
log_warnx("Lost child: %s exited", pname);
|
||||
return (1);
|
||||
}
|
||||
if (WIFSIGNALED(status)) {
|
||||
sig = WTERMSIG(status);
|
||||
signame = strsignal(sig) ? strsignal(sig) : "unknown";
|
||||
log_warnx("Lost child: %s terminated; signal %d (%s)",
|
||||
pname, sig, signame);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
dispatch_imsg(struct ntpd_conf *conf)
|
||||
{
|
||||
struct imsg imsg;
|
||||
int n, cnt;
|
||||
double d;
|
||||
char *name;
|
||||
struct ntp_addr *h, *hn;
|
||||
struct buf *buf;
|
||||
|
||||
if ((n = imsg_read(ibuf)) == -1)
|
||||
return (-1);
|
||||
|
||||
if (n == 0) { /* connection closed */
|
||||
log_warnx("dispatch_imsg in main: pipe closed");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if ((n = imsg_get(ibuf, &imsg)) == -1)
|
||||
return (-1);
|
||||
|
||||
if (n == 0)
|
||||
break;
|
||||
|
||||
switch (imsg.hdr.type) {
|
||||
case IMSG_ADJTIME:
|
||||
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(d))
|
||||
fatalx("invalid IMSG_ADJTIME received");
|
||||
memcpy(&d, imsg.data, sizeof(d));
|
||||
n = ntpd_adjtime(d);
|
||||
imsg_compose(ibuf, IMSG_ADJTIME, 0, 0, &n, sizeof(n));
|
||||
break;
|
||||
case IMSG_SETTIME:
|
||||
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(d))
|
||||
fatalx("invalid IMSG_SETTIME received");
|
||||
if (!conf->settime)
|
||||
break;
|
||||
log_init(conf->debug);
|
||||
memcpy(&d, imsg.data, sizeof(d));
|
||||
ntpd_settime(d);
|
||||
/* daemonize now */
|
||||
if (!conf->debug)
|
||||
if (daemon(1, 0))
|
||||
fatal("daemon");
|
||||
conf->settime = 0;
|
||||
break;
|
||||
case IMSG_HOST_DNS:
|
||||
name = imsg.data;
|
||||
if (imsg.hdr.len < 1 + IMSG_HEADER_SIZE)
|
||||
fatalx("invalid IMSG_HOST_DNS received");
|
||||
imsg.hdr.len -= 1 + IMSG_HEADER_SIZE;
|
||||
if (name[imsg.hdr.len] != '\0' ||
|
||||
strlen(name) != imsg.hdr.len)
|
||||
fatalx("invalid IMSG_HOST_DNS received");
|
||||
cnt = host_dns(name, &hn);
|
||||
buf = imsg_create(ibuf, IMSG_HOST_DNS,
|
||||
imsg.hdr.peerid, 0,
|
||||
cnt * sizeof(struct sockaddr_storage));
|
||||
if (buf == NULL)
|
||||
break;
|
||||
if (cnt > 0)
|
||||
for (h = hn; h != NULL; h = h->next)
|
||||
imsg_add(buf, &h->ss, sizeof(h->ss));
|
||||
|
||||
imsg_close(ibuf, buf);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
imsg_free(&imsg);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
ntpd_adjtime(double d)
|
||||
{
|
||||
struct timeval tv, olddelta;
|
||||
int synced = 0;
|
||||
static int firstadj = 1;
|
||||
|
||||
if (d >= (double)LOG_NEGLIGEE / 1000 ||
|
||||
d <= -1 * (double)LOG_NEGLIGEE / 1000)
|
||||
log_info("adjusting local clock by %fs", d);
|
||||
else
|
||||
log_debug("adjusting local clock by %fs", d);
|
||||
d_to_tv(d, &tv);
|
||||
if (adjtime(&tv, &olddelta) == -1)
|
||||
log_warn("adjtime failed");
|
||||
else if (!firstadj && olddelta.tv_sec == 0 && olddelta.tv_usec == 0)
|
||||
synced = 1;
|
||||
firstadj = 0;
|
||||
return (synced);
|
||||
}
|
||||
|
||||
void
|
||||
ntpd_settime(double d)
|
||||
{
|
||||
struct timeval tv, curtime;
|
||||
char buf[80];
|
||||
time_t tval;
|
||||
|
||||
/* if the offset is small, don't call settimeofday */
|
||||
if (d < SETTIME_MIN_OFFSET && d > -SETTIME_MIN_OFFSET)
|
||||
return;
|
||||
|
||||
if (gettimeofday(&curtime, NULL) == -1) {
|
||||
log_warn("gettimeofday");
|
||||
return;
|
||||
}
|
||||
d_to_tv(d, &tv);
|
||||
curtime.tv_usec += tv.tv_usec + 1000000;
|
||||
curtime.tv_sec += tv.tv_sec - 1 + (curtime.tv_usec / 1000000);
|
||||
curtime.tv_usec %= 1000000;
|
||||
|
||||
if (settimeofday(&curtime, NULL) == -1) {
|
||||
log_warn("settimeofday");
|
||||
return;
|
||||
}
|
||||
tval = curtime.tv_sec;
|
||||
strftime(buf, sizeof(buf), "%a %b %e %H:%M:%S %Z %Y",
|
||||
localtime(&tval));
|
||||
log_info("set local clock to %s (offset %fs)", buf, d);
|
||||
}
|
||||
14
external/bsd/openntpd/dist/ntpd.conf
vendored
Normal file
14
external/bsd/openntpd/dist/ntpd.conf
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# $OpenBSD: ntpd.conf,v 1.7 2004/07/20 17:38:35 henning Exp $
|
||||
# sample ntpd configuration file, see ntpd.conf(5)
|
||||
|
||||
# Addresses to listen on (ntpd does not listen by default)
|
||||
#listen on *
|
||||
#listen on 127.0.0.1
|
||||
#listen on ::1
|
||||
|
||||
# sync to a single server
|
||||
#server ntp.example.org
|
||||
|
||||
# use a random selection of 8 public stratum 2 servers
|
||||
# see http://twiki.ntp.org/bin/view/Servers/NTPPoolServers
|
||||
servers pool.ntp.org
|
||||
60
external/bsd/openntpd/dist/ntpd.conf.0
vendored
Normal file
60
external/bsd/openntpd/dist/ntpd.conf.0
vendored
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
NTPD.CONF(5) OpenBSD Programmer's Manual NTPD.CONF(5)
|
||||
|
||||
NAME
|
||||
ntpd.conf - Network Time Protocol daemon configuration file
|
||||
|
||||
DESCRIPTION
|
||||
This manual page describes the format of the ntpd(8) configuration file.
|
||||
It has the following format:
|
||||
|
||||
Empty lines and lines beginning with the `#' character are ignored.
|
||||
|
||||
Keywords may be specified multiple times within the configuration file.
|
||||
They are as follows:
|
||||
|
||||
listen on address
|
||||
Specify a local IP address or a hostname the ntpd(8) daemon
|
||||
should listen on. If it appears multiple times, ntpd(8) will
|
||||
listen on each given address. If `*' is given as an address,
|
||||
ntpd(8) will listen on all local addresses. ntpd(8) does not
|
||||
listen on any address by default. For example:
|
||||
|
||||
listen on *
|
||||
listen on 127.0.0.1
|
||||
listen on ::1
|
||||
|
||||
server address
|
||||
Specify the IP address or the hostname of an NTP server to syn-
|
||||
chronize to. If it appears multiple times, ntpd(8) will try to
|
||||
synchronize to all of the servers specified. If a hostname re-
|
||||
solves to multiple IPv4 and/or IPv6 addresses, ntpd(8) uses the
|
||||
first address. If it does not get a reply, ntpd(8) retries with
|
||||
the next address and continues to do so until a working address
|
||||
is found. For example:
|
||||
|
||||
server 10.0.0.2
|
||||
server ntp.example.org
|
||||
|
||||
To provide redundancy, it is good practice to configure multiple
|
||||
servers. In general, best accuracy is obtained by using servers
|
||||
that have a low network latency.
|
||||
|
||||
servers address
|
||||
As with server, specify the IP address or hostname of an NTP
|
||||
server to synchronize to. If it appears multiple times, ntpd(8)
|
||||
will try to synchronize to all of the servers specified. Should
|
||||
the hostname resolve to multiple IP addresses, ntpd(8) will try
|
||||
to synchronize to all of them. For example:
|
||||
|
||||
servers pool.ntp.org
|
||||
|
||||
FILES
|
||||
/etc/ntpd.conf default ntpd(8) configuration file
|
||||
|
||||
SEE ALSO
|
||||
ntpd(8)
|
||||
|
||||
HISTORY
|
||||
The ntpd.conf file format first appeared in OpenBSD 3.6.
|
||||
|
||||
OpenBSD 3.9 June 17, 2004 1
|
||||
106
external/bsd/openntpd/dist/ntpd.conf.5
vendored
Normal file
106
external/bsd/openntpd/dist/ntpd.conf.5
vendored
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
.\" $OpenBSD: ntpd.conf.5,v 1.9 2004/11/08 19:09:19 otto Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||
.\"
|
||||
.\" 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
.\" WHATSOEVER RESULTING FROM LOSS OF MIND, 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.
|
||||
.\"
|
||||
.Dd June 17, 2004
|
||||
.Dt NTPD.CONF 5
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm ntpd.conf
|
||||
.Nd Network Time Protocol daemon configuration file
|
||||
.Sh DESCRIPTION
|
||||
This manual page describes the format of the
|
||||
.Xr ntpd 8
|
||||
configuration file.
|
||||
It has the following format:
|
||||
.Pp
|
||||
Empty lines and lines beginning with the
|
||||
.Sq #
|
||||
character are ignored.
|
||||
.Pp
|
||||
Keywords may be specified multiple times within the configuration file.
|
||||
They are as follows:
|
||||
.Bl -tag -width Ds
|
||||
.It Ic listen on Ar address
|
||||
Specify a local IP address or a hostname the
|
||||
.Xr ntpd 8
|
||||
daemon should listen on.
|
||||
If it appears multiple times,
|
||||
.Xr ntpd 8
|
||||
will listen on each given address.
|
||||
If
|
||||
.Sq *
|
||||
is given as an address,
|
||||
.Xr ntpd 8
|
||||
will listen on all local addresses.
|
||||
.Xr ntpd 8
|
||||
does not listen on any address by default.
|
||||
For example:
|
||||
.Bd -literal -offset indent
|
||||
listen on *
|
||||
listen on 127.0.0.1
|
||||
listen on ::1
|
||||
.Ed
|
||||
.It Ic server Ar address
|
||||
Specify the IP address or the hostname of an NTP
|
||||
server to synchronize to.
|
||||
If it appears multiple times,
|
||||
.Xr ntpd 8
|
||||
will try to synchronize to all of the servers specified.
|
||||
If a hostname resolves to multiple IPv4 and/or IPv6 addresses,
|
||||
.Xr ntpd 8
|
||||
uses the first address.
|
||||
If it does not get a reply,
|
||||
.Xr ntpd 8
|
||||
retries with the next address and continues to do so until a working address
|
||||
is found.
|
||||
For example:
|
||||
.Bd -literal -offset indent
|
||||
server 10.0.0.2
|
||||
server ntp.example.org
|
||||
.Ed
|
||||
.Pp
|
||||
To provide redundancy, it is good practice to configure multiple servers.
|
||||
In general, best accuracy is obtained by using servers that have a low
|
||||
network latency.
|
||||
.It Ic servers Ar address
|
||||
As with
|
||||
.Cm server ,
|
||||
specify the IP address or hostname of an NTP server to synchronize to.
|
||||
If it appears multiple times,
|
||||
.Xr ntpd 8
|
||||
will try to synchronize to all of the servers specified.
|
||||
Should the hostname resolve to multiple IP addresses,
|
||||
.Xr ntpd 8
|
||||
will try to synchronize to all of them.
|
||||
For example:
|
||||
.Bd -literal -offset indent
|
||||
servers pool.ntp.org
|
||||
.Ed
|
||||
.El
|
||||
.Sh FILES
|
||||
.Bl -tag -width "/etc/ntpd.confXXX" -compact
|
||||
.It Pa /etc/ntpd.conf
|
||||
default
|
||||
.Xr ntpd 8
|
||||
configuration file
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr ntpd 8
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
file format first appeared in
|
||||
.Ox 3.6 .
|
||||
266
external/bsd/openntpd/dist/ntpd.h
vendored
Normal file
266
external/bsd/openntpd/dist/ntpd.h
vendored
Normal file
|
|
@ -0,0 +1,266 @@
|
|||
/* $OpenBSD: ntpd.h,v 1.61 2005/09/24 00:32:03 dtucker Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||
*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, 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.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/socket.h>
|
||||
#include "openbsd-compat/sys-queue.h"
|
||||
#include <sys/time.h>
|
||||
#include <netinet/in.h>
|
||||
#ifdef HAVE_NETINET_IN_SYSTM_H
|
||||
#include <netinet/in_systm.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IP_H
|
||||
#include <netinet/ip.h>
|
||||
#endif
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "ntp.h"
|
||||
|
||||
#ifndef NTPD_USER
|
||||
#define NTPD_USER "_ntp"
|
||||
#endif
|
||||
#define CONFFILE SYSCONFDIR "/ntpd.conf"
|
||||
|
||||
#define READ_BUF_SIZE 4096
|
||||
|
||||
#define NTPD_OPT_VERBOSE 0x0001
|
||||
#define NTPD_OPT_VERBOSE2 0x0002
|
||||
|
||||
#define INTERVAL_QUERY_NORMAL 30 /* sync to peers every n secs */
|
||||
#define INTERVAL_QUERY_PATHETIC 60
|
||||
#define INTERVAL_QUERY_AGRESSIVE 5
|
||||
|
||||
#define TRUSTLEVEL_BADPEER 6
|
||||
#define TRUSTLEVEL_PATHETIC 2
|
||||
#define TRUSTLEVEL_AGRESSIVE 8
|
||||
#define TRUSTLEVEL_MAX 10
|
||||
|
||||
#define MAX_SERVERS_DNS 8
|
||||
|
||||
#define QSCALE_OFF_MIN 0.05
|
||||
#define QSCALE_OFF_MAX 0.50
|
||||
|
||||
#define QUERYTIME_MAX 15 /* single query might take n secs max */
|
||||
#define OFFSET_ARRAY_SIZE 8
|
||||
#define SETTIME_MIN_OFFSET 180 /* min offset for settime at start */
|
||||
#define SETTIME_TIMEOUT 15 /* max seconds to wait with -s */
|
||||
#define LOG_NEGLIGEE 128 /* negligible drift to not log (ms) */
|
||||
|
||||
enum client_state {
|
||||
STATE_NONE,
|
||||
STATE_DNS_INPROGRESS,
|
||||
STATE_DNS_TEMPFAIL,
|
||||
STATE_DNS_DONE,
|
||||
STATE_QUERY_SENT,
|
||||
STATE_REPLY_RECEIVED
|
||||
};
|
||||
|
||||
struct listen_addr {
|
||||
TAILQ_ENTRY(listen_addr) entry;
|
||||
struct sockaddr_storage sa;
|
||||
int fd;
|
||||
};
|
||||
|
||||
struct ntp_addr {
|
||||
struct ntp_addr *next;
|
||||
struct sockaddr_storage ss;
|
||||
};
|
||||
|
||||
struct ntp_addr_wrap {
|
||||
char *name;
|
||||
struct ntp_addr *a;
|
||||
u_int8_t pool;
|
||||
};
|
||||
|
||||
struct ntp_status {
|
||||
double rootdelay;
|
||||
double rootdispersion;
|
||||
double reftime;
|
||||
u_int32_t refid;
|
||||
u_int32_t refid4;
|
||||
u_int8_t synced;
|
||||
u_int8_t leap;
|
||||
int8_t precision;
|
||||
u_int8_t poll;
|
||||
u_int8_t stratum;
|
||||
};
|
||||
|
||||
struct ntp_offset {
|
||||
struct ntp_status status;
|
||||
double offset;
|
||||
double delay;
|
||||
double error;
|
||||
time_t rcvd;
|
||||
u_int8_t good;
|
||||
};
|
||||
|
||||
struct ntp_peer {
|
||||
TAILQ_ENTRY(ntp_peer) entry;
|
||||
struct ntp_addr_wrap addr_head;
|
||||
struct ntp_addr *addr;
|
||||
struct ntp_query *query;
|
||||
struct ntp_offset reply[OFFSET_ARRAY_SIZE];
|
||||
struct ntp_offset update;
|
||||
enum client_state state;
|
||||
time_t next;
|
||||
time_t deadline;
|
||||
u_int32_t id;
|
||||
u_int8_t shift;
|
||||
u_int8_t trustlevel;
|
||||
int lasterror;
|
||||
};
|
||||
|
||||
struct ntpd_conf {
|
||||
TAILQ_HEAD(listen_addrs, listen_addr) listen_addrs;
|
||||
TAILQ_HEAD(ntp_peers, ntp_peer) ntp_peers;
|
||||
struct ntp_status status;
|
||||
u_int8_t listen_all;
|
||||
u_int8_t settime;
|
||||
u_int8_t debug;
|
||||
u_int32_t scale;
|
||||
};
|
||||
|
||||
struct buf {
|
||||
TAILQ_ENTRY(buf) entry;
|
||||
u_char *buf;
|
||||
size_t size;
|
||||
size_t wpos;
|
||||
size_t rpos;
|
||||
};
|
||||
|
||||
struct msgbuf {
|
||||
TAILQ_HEAD(, buf) bufs;
|
||||
u_int32_t queued;
|
||||
int fd;
|
||||
};
|
||||
|
||||
struct buf_read {
|
||||
size_t wpos;
|
||||
u_char buf[READ_BUF_SIZE];
|
||||
u_char *rptr;
|
||||
};
|
||||
|
||||
/* ipc messages */
|
||||
|
||||
#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
|
||||
#define MAX_IMSGSIZE 8192
|
||||
|
||||
struct imsgbuf {
|
||||
int fd;
|
||||
pid_t pid;
|
||||
struct buf_read r;
|
||||
struct msgbuf w;
|
||||
};
|
||||
|
||||
enum imsg_type {
|
||||
IMSG_NONE,
|
||||
IMSG_ADJTIME,
|
||||
IMSG_SETTIME,
|
||||
IMSG_HOST_DNS
|
||||
};
|
||||
|
||||
struct imsg_hdr {
|
||||
enum imsg_type type;
|
||||
u_int32_t peerid;
|
||||
pid_t pid;
|
||||
u_int16_t len;
|
||||
};
|
||||
|
||||
struct imsg {
|
||||
struct imsg_hdr hdr;
|
||||
void *data;
|
||||
};
|
||||
|
||||
/* prototypes */
|
||||
/* log.c */
|
||||
void log_init(int);
|
||||
void vlog(int, const char *, va_list);
|
||||
void log_warn(const char *, ...);
|
||||
void log_warnx(const char *, ...);
|
||||
void log_info(const char *, ...);
|
||||
void log_debug(const char *, ...);
|
||||
void fatal(const char *);
|
||||
void fatalx(const char *);
|
||||
const char * log_sockaddr(struct sockaddr *);
|
||||
|
||||
/* buffer.c */
|
||||
struct buf *buf_open(size_t);
|
||||
int buf_add(struct buf *, void *, size_t);
|
||||
int buf_close(struct msgbuf *, struct buf *);
|
||||
void buf_free(struct buf *);
|
||||
void msgbuf_init(struct msgbuf *);
|
||||
void msgbuf_clear(struct msgbuf *);
|
||||
int msgbuf_write(struct msgbuf *);
|
||||
|
||||
/* imsg.c */
|
||||
void imsg_init(struct imsgbuf *, int);
|
||||
int imsg_read(struct imsgbuf *);
|
||||
int imsg_get(struct imsgbuf *, struct imsg *);
|
||||
int imsg_compose(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t,
|
||||
void *, u_int16_t);
|
||||
struct buf *imsg_create(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t,
|
||||
u_int16_t);
|
||||
int imsg_add(struct buf *, void *, u_int16_t);
|
||||
int imsg_close(struct imsgbuf *, struct buf *);
|
||||
void imsg_free(struct imsg *);
|
||||
|
||||
/* ntp.c */
|
||||
pid_t ntp_main(int[2], struct ntpd_conf *);
|
||||
void priv_adjtime(void);
|
||||
void priv_settime(double);
|
||||
void priv_host_dns(char *, u_int32_t);
|
||||
|
||||
/* parse.y */
|
||||
int parse_config(const char *, struct ntpd_conf *);
|
||||
|
||||
/* config.c */
|
||||
int host(const char *, struct ntp_addr **);
|
||||
int host_dns(const char *, struct ntp_addr **);
|
||||
struct ntp_peer *new_peer(void);
|
||||
|
||||
/* ntp_msg.c */
|
||||
int ntp_getmsg(struct sockaddr *, char *, ssize_t, struct ntp_msg *);
|
||||
int ntp_sendmsg(int, struct sockaddr *, struct ntp_msg *, ssize_t, int);
|
||||
|
||||
/* server.c */
|
||||
int setup_listeners(struct servent *, struct ntpd_conf *, u_int *);
|
||||
int ntp_reply(int, struct sockaddr *, struct ntp_msg *, int);
|
||||
int server_dispatch(int, struct ntpd_conf *);
|
||||
|
||||
/* client.c */
|
||||
int client_peer_init(struct ntp_peer *);
|
||||
int client_addr_init(struct ntp_peer *);
|
||||
int client_nextaddr(struct ntp_peer *);
|
||||
int client_query(struct ntp_peer *);
|
||||
int client_dispatch(struct ntp_peer *, u_int8_t);
|
||||
void client_log_error(struct ntp_peer *, const char *, int);
|
||||
void update_scale(double);
|
||||
time_t scale_interval(time_t);
|
||||
time_t error_interval(void);
|
||||
void set_next(struct ntp_peer *, time_t);
|
||||
|
||||
/* util.c */
|
||||
double gettime(void);
|
||||
void d_to_tv(double, struct timeval *);
|
||||
double lfp_to_d(struct l_fixedpt);
|
||||
struct l_fixedpt d_to_lfp(double);
|
||||
double sfp_to_d(struct s_fixedpt);
|
||||
struct s_fixedpt d_to_sfp(double);
|
||||
2
external/bsd/openntpd/dist/openbsd-compat/.cvsignore
vendored
Normal file
2
external/bsd/openntpd/dist/openbsd-compat/.cvsignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
Makefile
|
||||
|
||||
37
external/bsd/openntpd/dist/openbsd-compat/Makefile
vendored
Normal file
37
external/bsd/openntpd/dist/openbsd-compat/Makefile
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
|
||||
sysconfdir=${prefix}/etc
|
||||
srcdir=.
|
||||
top_srcdir=..
|
||||
|
||||
all: libopenbsd-compat.a
|
||||
|
||||
OPENBSD= asprintf.o daemon.o errx.o inet_pton.o strlcpy.o verrx.o
|
||||
COMPAT= atomicio.o bsd-arc4random.o bsd-misc.o bsd-poll.o \
|
||||
bsd-snprintf.o bsd-getifaddrs.o bsd-setresuid.o \
|
||||
bsd-setresgid.o fake-rfc2553.o
|
||||
PORT= port-qnx.o
|
||||
|
||||
|
||||
CC=gcc
|
||||
LD=gcc
|
||||
CFLAGS=-g -O2 -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual -Wsign-compare
|
||||
LDFLAGS=
|
||||
CPPFLAGS=-I. -I.. -I$(srcdir) -I$(srcdir)/..
|
||||
LIBS=
|
||||
AR=/usr/pkg/bin/ar
|
||||
RANLIB=ranlib
|
||||
INSTALL=/usr/bin/install -c
|
||||
|
||||
$(COMPAT): ../config.h
|
||||
$(OPENBSD): ../config.h
|
||||
$(PORT): ../config.h
|
||||
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -c $<
|
||||
|
||||
libopenbsd-compat.a: $(COMPAT) $(OPENBSD) $(PORT)
|
||||
$(AR) rv $@ $(COMPAT) $(OPENBSD) $(PORT)
|
||||
$(RANLIB) $@
|
||||
|
||||
clean:
|
||||
rm -f $(COMPAT) $(OPENBSD) $(PORT) libopenbsd-compat.a
|
||||
37
external/bsd/openntpd/dist/openbsd-compat/Makefile.in
vendored
Normal file
37
external/bsd/openntpd/dist/openbsd-compat/Makefile.in
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
|
||||
sysconfdir=@sysconfdir@
|
||||
srcdir=@srcdir@
|
||||
top_srcdir=@top_srcdir@
|
||||
|
||||
all: libopenbsd-compat.a
|
||||
|
||||
OPENBSD= asprintf.o daemon.o errx.o inet_pton.o strlcpy.o verrx.o
|
||||
COMPAT= atomicio.o bsd-arc4random.o bsd-misc.o bsd-poll.o \
|
||||
bsd-snprintf.o bsd-getifaddrs.o bsd-setresuid.o \
|
||||
bsd-setresgid.o fake-rfc2553.o
|
||||
PORT= port-qnx.o
|
||||
|
||||
VPATH=@srcdir@
|
||||
CC=@CC@
|
||||
LD=@LD@
|
||||
CFLAGS=@CFLAGS@
|
||||
LDFLAGS=@LDFLAGS@
|
||||
CPPFLAGS=-I. -I.. -I$(srcdir) -I$(srcdir)/.. @CPPFLAGS@
|
||||
LIBS=@LIBS@
|
||||
AR=@AR@
|
||||
RANLIB=@RANLIB@
|
||||
INSTALL=@INSTALL@
|
||||
|
||||
$(COMPAT): ../config.h
|
||||
$(OPENBSD): ../config.h
|
||||
$(PORT): ../config.h
|
||||
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -c $<
|
||||
|
||||
libopenbsd-compat.a: $(COMPAT) $(OPENBSD) $(PORT)
|
||||
$(AR) rv $@ $(COMPAT) $(OPENBSD) $(PORT)
|
||||
$(RANLIB) $@
|
||||
|
||||
clean:
|
||||
rm -f $(COMPAT) $(OPENBSD) $(PORT) libopenbsd-compat.a
|
||||
71
external/bsd/openntpd/dist/openbsd-compat/asprintf.c
vendored
Normal file
71
external/bsd/openntpd/dist/openbsd-compat/asprintf.c
vendored
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2004 Darren Tucker.
|
||||
*
|
||||
* Based originally on asprintf.c from OpenBSD:
|
||||
* Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#ifndef HAVE_ASPRINTF
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#define INIT_SZ 128
|
||||
|
||||
int
|
||||
asprintf(char **str, const char *fmt, ...)
|
||||
{
|
||||
int ret = -1;
|
||||
va_list ap;
|
||||
char *string, *newstr;
|
||||
size_t len;
|
||||
|
||||
va_start(ap, fmt);
|
||||
if ((string = malloc(INIT_SZ)) == NULL)
|
||||
goto fail;
|
||||
|
||||
ret = vsnprintf(string, INIT_SZ, fmt, ap);
|
||||
if (ret >= 0 && ret < INIT_SZ) { /* succeeded with initial alloc */
|
||||
*str = string;
|
||||
} else if (ret == INT_MAX) { /* shouldn't happen */
|
||||
goto fail;
|
||||
} else { /* bigger than initial, realloc allowing for nul */
|
||||
len = (size_t)ret + 1;
|
||||
if ((newstr = realloc(string, len)) == NULL) {
|
||||
free(string);
|
||||
goto fail;
|
||||
} else {
|
||||
ret = vsnprintf(newstr, len, fmt, ap);
|
||||
if (ret >= 0 && (size_t)ret < len) {
|
||||
*str = newstr;
|
||||
} else { /* failed with realloc'ed string, give up */
|
||||
free(newstr);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
va_end(ap);
|
||||
return (ret);
|
||||
|
||||
fail:
|
||||
va_end(ap);
|
||||
*str = NULL;
|
||||
errno = ENOMEM;
|
||||
return (-1);
|
||||
}
|
||||
#endif
|
||||
65
external/bsd/openntpd/dist/openbsd-compat/atomicio.c
vendored
Normal file
65
external/bsd/openntpd/dist/openbsd-compat/atomicio.c
vendored
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2005 Anil Madhavapeddy. All rights reserved.
|
||||
* Copyright (c) 1995,1999 Theo de Raadt. All rights reserved.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 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.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
RCSID("$OpenBSD: atomicio.c,v 1.13 2005/05/24 17:32:43 avsm Exp $");
|
||||
|
||||
#include "atomicio.h"
|
||||
|
||||
/*
|
||||
* ensure all of data on socket comes through. f==read || f==vwrite
|
||||
*/
|
||||
size_t
|
||||
atomicio(f, fd, _s, n)
|
||||
ssize_t (*f) (int, void *, size_t);
|
||||
int fd;
|
||||
void *_s;
|
||||
size_t n;
|
||||
{
|
||||
char *s = _s;
|
||||
size_t pos = 0;
|
||||
ssize_t res;
|
||||
|
||||
while (n > pos) {
|
||||
res = (f) (fd, s + pos, n - pos);
|
||||
switch (res) {
|
||||
case -1:
|
||||
#ifdef EWOULDBLOCK
|
||||
if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)
|
||||
#else
|
||||
if (errno == EINTR || errno == EAGAIN)
|
||||
#endif
|
||||
continue;
|
||||
return 0;
|
||||
case 0:
|
||||
errno = EPIPE;
|
||||
return pos;
|
||||
default:
|
||||
pos += (u_int)res;
|
||||
}
|
||||
}
|
||||
return (pos);
|
||||
}
|
||||
33
external/bsd/openntpd/dist/openbsd-compat/atomicio.h
vendored
Normal file
33
external/bsd/openntpd/dist/openbsd-compat/atomicio.h
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* $OpenBSD: atomicio.h,v 1.6 2005/05/24 17:32:43 avsm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1995,1999 Theo de Raadt. All rights reserved.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Ensure all of data on socket comes through. f==read || f==vwrite
|
||||
*/
|
||||
size_t atomicio(ssize_t (*)(int, void *, size_t), int, void *, size_t);
|
||||
|
||||
#define vwrite (ssize_t (*)(int, void *, size_t))write
|
||||
233
external/bsd/openntpd/dist/openbsd-compat/bsd-arc4random.c
vendored
Normal file
233
external/bsd/openntpd/dist/openbsd-compat/bsd-arc4random.c
vendored
Normal file
|
|
@ -0,0 +1,233 @@
|
|||
/*
|
||||
* Copyright (c) 1999,2000,2004 Damien Miller <djm@mindrot.org>
|
||||
* Copyright (c) 2004 Darren Tucker <dtucker at zip.com.au>
|
||||
*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#include "ntpd.h"
|
||||
|
||||
/* RCSID("$Id: bsd-arc4random.c,v 1.14 2005/05/29 14:01:08 dtucker Exp $"); */
|
||||
|
||||
#ifndef HAVE_ARC4RANDOM
|
||||
|
||||
#ifdef HAVE_OPENSSL
|
||||
# include <openssl/rand.h>
|
||||
# include <openssl/rc4.h>
|
||||
# include <openssl/err.h>
|
||||
#else
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/un.h>
|
||||
|
||||
enum entropy_dev_type {
|
||||
none,
|
||||
dev, /* regular /dev/random type device special */
|
||||
egd /* EGD/PRNGD socket */
|
||||
};
|
||||
|
||||
struct entropy_dev_struct {
|
||||
const char *device;
|
||||
enum entropy_dev_type type;
|
||||
} entropy_dev[] = {
|
||||
{ "/dev/urandom", dev },
|
||||
{ "/dev/arandom", dev },
|
||||
{ "/dev/random", dev },
|
||||
{ "/var/run/egd-pool", egd },
|
||||
{ "/dev/egd-pool", egd },
|
||||
{ "/etc/egd-pool", egd },
|
||||
{ NULL, none }
|
||||
};
|
||||
|
||||
/*
|
||||
* arcfour routines from "nanocrypt" also by Damien Miller, included with
|
||||
* permission under the license above.
|
||||
* Converted to OpenSSL API by Darren Tucker.
|
||||
*/
|
||||
|
||||
static int randfd = -1;
|
||||
static const char *randdev = NULL;
|
||||
static enum entropy_dev_type randtype = none;
|
||||
|
||||
typedef struct {
|
||||
unsigned int s[256];
|
||||
int i;
|
||||
int j;
|
||||
} RC4_KEY;
|
||||
|
||||
static void
|
||||
RC4_set_key(RC4_KEY *r, int len, unsigned char *key)
|
||||
{
|
||||
int t;
|
||||
|
||||
for(r->i = 0; r->i < 256; r->i++)
|
||||
r->s[r->i] = r->i;
|
||||
|
||||
r->j = 0;
|
||||
for(r->i = 0; r->i < 256; r->i++)
|
||||
{
|
||||
r->j = (r->j + r->s[r->i] + key[r->i % len]) % 256;
|
||||
t = r->s[r->i];
|
||||
r->s[r->i] = r->s[r->j];
|
||||
r->s[r->j] = t;
|
||||
}
|
||||
r->i = r->j = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
RC4(RC4_KEY *r, unsigned long len, const unsigned char *plaintext,
|
||||
unsigned char *ciphertext )
|
||||
{
|
||||
int t;
|
||||
unsigned long c;
|
||||
|
||||
c = 0;
|
||||
while(c < len)
|
||||
{
|
||||
r->i = (r->i + 1) % 256;
|
||||
r->j = (r->j + r->s[r->i]) % 256;
|
||||
t = r->s[r->i];
|
||||
r->s[r->i] = r->s[r->j];
|
||||
r->s[r->j] = t;
|
||||
|
||||
t = (r->s[r->i] + r->s[r->j]) % 256;
|
||||
|
||||
ciphertext[c] = plaintext[c] ^ r->s[t];
|
||||
c++;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
RAND_status(void)
|
||||
{
|
||||
int i;
|
||||
socklen_t len;
|
||||
struct sockaddr_un sa;
|
||||
|
||||
if (randfd >= 0 && randtype != none)
|
||||
return 1;
|
||||
|
||||
/* search for an entropy source */
|
||||
for (i = 0; entropy_dev[i].device != NULL && randtype == none; i++ ) {
|
||||
randdev = entropy_dev[i].device;
|
||||
switch (entropy_dev[i].type) {
|
||||
case dev:
|
||||
randfd = open(randdev, O_RDONLY);
|
||||
if (randfd >= 0) /* success */
|
||||
randtype = entropy_dev[i].type;
|
||||
break;
|
||||
case egd:
|
||||
if ((randfd = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) {
|
||||
log_warn("socket");
|
||||
break;
|
||||
}
|
||||
memset((void *)&sa, 0, sizeof(sa));
|
||||
sa.sun_family = AF_UNIX;
|
||||
strlcpy(sa.sun_path, randdev, sizeof(sa.sun_path));
|
||||
len = sizeof(sa);
|
||||
if (connect(randfd, (struct sockaddr*)&sa, len) == -1) {
|
||||
close(randfd);
|
||||
randfd = -1;
|
||||
} else {
|
||||
randtype = entropy_dev[i].type;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
fatal("RAND_status internal error");
|
||||
}
|
||||
}
|
||||
|
||||
if (randfd >= 0 && randtype != none)
|
||||
return 1;
|
||||
return(0);
|
||||
}
|
||||
|
||||
static int
|
||||
RAND_bytes(unsigned char *buf, size_t len)
|
||||
{
|
||||
if (randtype == egd) {
|
||||
char egdcmd[2];
|
||||
|
||||
if (len > 255)
|
||||
fatal("requested more than 255 bytes from egd");
|
||||
egdcmd[0] = 0x02; /* blocking read */
|
||||
egdcmd[1] = (unsigned char)len;
|
||||
if (atomicio(vwrite, randfd, egdcmd, 2) == 0)
|
||||
fatal("write to egd socket");
|
||||
}
|
||||
if (atomicio(read, randfd, buf, len) != len)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Size of key to use */
|
||||
#define SEED_SIZE 20
|
||||
|
||||
/* Number of bytes to reseed after */
|
||||
#define REKEY_BYTES (1 << 24)
|
||||
|
||||
static int rc4_ready = 0;
|
||||
static RC4_KEY rc4;
|
||||
|
||||
void
|
||||
seed_rng(void)
|
||||
{
|
||||
if (RAND_status() != 1)
|
||||
fatal("PRNG is not seeded");
|
||||
}
|
||||
|
||||
unsigned int arc4random(void)
|
||||
{
|
||||
unsigned int r = 0;
|
||||
static int first_time = 1;
|
||||
|
||||
if (rc4_ready <= 0) {
|
||||
if (first_time)
|
||||
seed_rng();
|
||||
first_time = 0;
|
||||
arc4random_stir();
|
||||
}
|
||||
|
||||
RC4(&rc4, sizeof(r), (unsigned char *)&r, (unsigned char *)&r);
|
||||
|
||||
rc4_ready -= sizeof(r);
|
||||
|
||||
return(r);
|
||||
}
|
||||
|
||||
void arc4random_stir(void)
|
||||
{
|
||||
unsigned char rand_buf[SEED_SIZE];
|
||||
int i;
|
||||
|
||||
memset(&rc4, 0, sizeof(rc4));
|
||||
if (RAND_bytes(rand_buf, sizeof(rand_buf)) <= 0)
|
||||
fatal("Couldn't obtain random bytes");
|
||||
RC4_set_key(&rc4, sizeof(rand_buf), rand_buf);
|
||||
|
||||
/*
|
||||
* Discard early keystream, as per recommendations in:
|
||||
* http://www.wisdom.weizmann.ac.il/~itsik/RC4/Papers/Rc4_ksa.ps
|
||||
*/
|
||||
for(i = 0; i <= 256; i += sizeof(rand_buf))
|
||||
RC4(&rc4, sizeof(rand_buf), rand_buf, rand_buf);
|
||||
|
||||
RC4(&rc4, sizeof(rand_buf), rand_buf, rand_buf);
|
||||
memset(rand_buf, 0, sizeof(rand_buf));
|
||||
|
||||
rc4_ready = REKEY_BYTES;
|
||||
}
|
||||
#endif /* !HAVE_ARC4RANDOM */
|
||||
182
external/bsd/openntpd/dist/openbsd-compat/bsd-getifaddrs.c
vendored
Normal file
182
external/bsd/openntpd/dist/openbsd-compat/bsd-getifaddrs.c
vendored
Normal file
|
|
@ -0,0 +1,182 @@
|
|||
/* $Id: bsd-getifaddrs.c,v 1.1 2005/07/06 07:53:50 dtucker Exp $ */
|
||||
|
||||
/*
|
||||
* A minimal getifaddrs replacement for OpenNTPD
|
||||
* This only implements the components that ntpd uses (ie ifa_addr for
|
||||
* INET and INET6 interfaces). It is not suitable for any other purpose.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2005 Darren Tucker <dtucker at zip com au>
|
||||
*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, 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.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
#ifndef HAVE_GETIFADDRS
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef HAVE_SYS_SOCKIO_H
|
||||
#include <sys/sockio.h>
|
||||
#endif
|
||||
|
||||
#define MAX_INTERFACES 128
|
||||
#define STEPSZ 8
|
||||
|
||||
# if !defined(IF_NAMESIZE) && defined(IFNAMSIZ)
|
||||
# define IF_NAMESIZE IFNAMSIZ
|
||||
# endif
|
||||
|
||||
# ifdef GETIFADDRS_VIA_SIOCGIFCONF
|
||||
static void *
|
||||
xrealloc(void *old, size_t size) {
|
||||
if (old == NULL)
|
||||
return malloc(size);
|
||||
else
|
||||
return realloc(old, size);
|
||||
}
|
||||
|
||||
static void
|
||||
add_interface(struct ifaddrs **ifa, struct ifreq *ifr, struct sockaddr *sa)
|
||||
{
|
||||
struct ifaddrs *ifa_new = NULL;
|
||||
size_t sasize;
|
||||
int family = ifr->ifr_addr.sa_family;
|
||||
|
||||
if (family != AF_INET && family != AF_INET6)
|
||||
return;
|
||||
|
||||
sasize = SA_LEN(sa);
|
||||
|
||||
if ((ifa_new = malloc(sizeof(*ifa_new))) == NULL)
|
||||
goto fail;
|
||||
memset(ifa_new, 0, sizeof(*ifa_new));
|
||||
|
||||
if ((ifa_new->ifa_name = strdup(ifr->ifr_name)) == NULL)
|
||||
goto fail;
|
||||
if ((ifa_new->ifa_addr = malloc(sasize)) == NULL)
|
||||
goto fail;
|
||||
if (memcpy(ifa_new->ifa_addr, sa, sasize) == NULL)
|
||||
goto fail;
|
||||
ifa_new->ifa_next = *ifa;
|
||||
*ifa = ifa_new;
|
||||
return;
|
||||
|
||||
fail:
|
||||
if (ifa_new->ifa_name != NULL)
|
||||
free(ifa_new->ifa_name);
|
||||
if (ifa_new->ifa_addr != NULL)
|
||||
free(ifa_new->ifa_addr);
|
||||
if (ifa_new != NULL)
|
||||
free(ifa_new);
|
||||
}
|
||||
# endif
|
||||
|
||||
int
|
||||
getifaddrs(struct ifaddrs **ifa)
|
||||
{
|
||||
# ifdef GETIFADDRS_VIA_SIOCGIFCONF
|
||||
int fd, i, oldlen = 0;
|
||||
size_t buflen = 0;
|
||||
char *oldbuf = NULL, *buf = NULL;
|
||||
struct ifconf ifc;
|
||||
struct ifreq *ifr;
|
||||
struct sockaddr *sa;
|
||||
|
||||
if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)
|
||||
return -1;
|
||||
|
||||
*ifa = NULL;
|
||||
/*
|
||||
* We iterate until the buffer returned by the ioctl stops growing.
|
||||
* Yes, this is ugly.
|
||||
*/
|
||||
for (i = STEPSZ; i < MAX_INTERFACES; i += STEPSZ) {
|
||||
buflen = i * sizeof(struct ifreq);
|
||||
oldbuf = buf;
|
||||
if ((buf = xrealloc(buf, buflen)) == NULL)
|
||||
goto fail;
|
||||
ifc.ifc_buf = buf;
|
||||
ifc.ifc_len = buflen;
|
||||
|
||||
if (ioctl(fd, SIOCGIFCONF, &ifc) < 0)
|
||||
goto fail;
|
||||
if (oldlen == ifc.ifc_len)
|
||||
break;
|
||||
oldlen = ifc.ifc_len;
|
||||
# ifdef DEBUG_GETIFADDRS
|
||||
log_info("%s: i %d len %d oldlen %d", __func__, i, buflen,
|
||||
oldlen);
|
||||
# endif
|
||||
}
|
||||
|
||||
/* walk the device list, add the inet and inet6 ones to the list */
|
||||
for (oldbuf = buf; buf < oldbuf + ifc.ifc_len;) {
|
||||
ifr = (struct ifreq *)buf;
|
||||
sa = (struct sockaddr *)&ifr->ifr_addr;
|
||||
# if defined(HAVE_SOCKADDR_SA_LEN)
|
||||
buf += IF_NAMESIZE + SA_LEN(sa);
|
||||
# else
|
||||
buf += sizeof(struct ifreq);
|
||||
# endif
|
||||
# ifdef DEBUG_GETIFADDRS
|
||||
log_info("%s: if %s family %d", __func__, ifr->ifr_name,
|
||||
ifr->ifr_addr.sa_family);
|
||||
# endif
|
||||
add_interface(ifa, ifr, sa);
|
||||
}
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
if (oldbuf != NULL)
|
||||
free(oldbuf);
|
||||
if (*ifa != NULL) {
|
||||
freeifaddrs(*ifa);
|
||||
*ifa = NULL;
|
||||
}
|
||||
close(fd);
|
||||
return -1;
|
||||
# else
|
||||
fprintf(stderr, "\"listen on *\" not supported on this "
|
||||
"platform, interface address required\n");
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
# endif
|
||||
}
|
||||
|
||||
void
|
||||
freeifaddrs(struct ifaddrs *ifap)
|
||||
{
|
||||
# ifdef GETIFADDRS_VIA_SIOCGIFCONF
|
||||
struct ifaddrs *tmpifa = ifap;
|
||||
|
||||
while (ifap != NULL) {
|
||||
if (ifap->ifa_name != NULL)
|
||||
free(ifap->ifa_name);
|
||||
if (ifap->ifa_addr != NULL)
|
||||
free(ifap->ifa_addr);
|
||||
tmpifa = ifap->ifa_next;
|
||||
free(ifap);
|
||||
ifap = tmpifa;
|
||||
}
|
||||
return;
|
||||
# endif
|
||||
}
|
||||
#endif /* HAVE_GETIFADDRS */
|
||||
46
external/bsd/openntpd/dist/openbsd-compat/bsd-getifaddrs.h
vendored
Normal file
46
external/bsd/openntpd/dist/openbsd-compat/bsd-getifaddrs.h
vendored
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/* $Id: bsd-getifaddrs.h,v 1.1 2005/07/06 07:53:50 dtucker Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2005 Darren Tucker <dtucker at zip com au>
|
||||
*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, 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.
|
||||
*/
|
||||
|
||||
#ifndef HAVE_GETIFADDRS
|
||||
# ifndef _BSD_GETIFADDRS_H
|
||||
# define _BSD_GETIFADDRS_H
|
||||
|
||||
#ifdef ifa_broadaddr
|
||||
#undef ifa_broadaddr
|
||||
#endif
|
||||
|
||||
#ifdef ifa_dstaddr
|
||||
#undef ifa_dstaddr
|
||||
#endif
|
||||
|
||||
struct ifaddrs {
|
||||
struct ifaddrs *ifa_next; /* Pointer to next struct */
|
||||
char *ifa_name; /* Interface name */
|
||||
u_int ifa_flags; /* Interface flags */
|
||||
struct sockaddr *ifa_addr; /* Interface address */
|
||||
struct sockaddr *ifa_netmask; /* Interface netmask */
|
||||
struct sockaddr *ifa_broadaddr; /* Interface broadcast address */
|
||||
struct sockaddr *ifa_dstaddr; /* P2P interface destination */
|
||||
void *ifa_data; /* Address specific data */
|
||||
};
|
||||
|
||||
int getifaddrs(struct ifaddrs **);
|
||||
void freeifaddrs(struct ifaddrs *);
|
||||
|
||||
# endif /* _BSD_GETIFADDRS_H */
|
||||
#endif /* HAVE_GETIFADDRS */
|
||||
137
external/bsd/openntpd/dist/openbsd-compat/bsd-misc.c
vendored
Normal file
137
external/bsd/openntpd/dist/openbsd-compat/bsd-misc.c
vendored
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
* Copyright (c) 1999-2004 Damien Miller <djm@mindrot.org>
|
||||
* Copyright (c) 2004 Darren Tucker <dtucker at zip com au>
|
||||
*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
#ifdef HAVE_SYS_TIMEX_H
|
||||
/*
|
||||
* We can't put this in includes.h because of conflicting definitions of
|
||||
* ntp_adjtime.
|
||||
*/
|
||||
# include <sys/timex.h>
|
||||
#endif
|
||||
|
||||
#ifndef HAVE___PROGNAME
|
||||
char *__progname;
|
||||
#endif
|
||||
|
||||
static char *
|
||||
xstrdup(const char *s)
|
||||
{
|
||||
char *c = strdup(s);
|
||||
|
||||
if (c == NULL) {
|
||||
fprintf(stderr, "%s failed: %s", __func__, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
/*
|
||||
* NB. duplicate __progname in case it is an alias for argv[0]
|
||||
* Otherwise it may get clobbered by setproctitle()
|
||||
*/
|
||||
char *
|
||||
_compat_get_progname(char *argv0)
|
||||
{
|
||||
#ifdef HAVE___PROGNAME
|
||||
extern char *__progname;
|
||||
|
||||
return xstrdup(__progname);
|
||||
#else
|
||||
char *p;
|
||||
|
||||
if (argv0 == NULL)
|
||||
return ("unknown"); /* XXX */
|
||||
p = strrchr(argv0, '/');
|
||||
if (p == NULL)
|
||||
p = argv0;
|
||||
else
|
||||
p++;
|
||||
|
||||
return (xstrdup(p));
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID)
|
||||
int seteuid(uid_t euid)
|
||||
{
|
||||
return (setreuid(-1, euid));
|
||||
}
|
||||
#endif /* !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) */
|
||||
|
||||
#if !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID)
|
||||
int setegid(uid_t egid)
|
||||
{
|
||||
return(setresgid(-1, egid, -1));
|
||||
}
|
||||
#endif /* !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID) */
|
||||
|
||||
#ifndef HAVE_VSYSLOG
|
||||
void
|
||||
vsyslog(int priority, const char *message, va_list args)
|
||||
{
|
||||
char buf[2048];
|
||||
|
||||
vsnprintf(buf, sizeof(buf), message, args); /* possible truncation */
|
||||
syslog(priority, "%s", buf);
|
||||
}
|
||||
#endif /* HAVE_VSYSLOG */
|
||||
|
||||
#ifndef HAVE_CLOCK_GETRES
|
||||
int
|
||||
clock_getres(int clock_id, struct timespec *tp)
|
||||
{
|
||||
# ifdef HAVE_ADJTIMEX
|
||||
struct timex tmx;
|
||||
# endif
|
||||
|
||||
if (clock_id != CLOCK_REALTIME)
|
||||
return -1; /* not implemented */
|
||||
tp->tv_sec = 0;
|
||||
|
||||
# ifdef HAVE_ADJTIMEX
|
||||
tmx.modes = 0;
|
||||
if (adjtimex(&tmx) == -1)
|
||||
return -1;
|
||||
else
|
||||
tp->tv_nsec = tmx.precision * 1000; /* usec -> nsec */
|
||||
# else
|
||||
/* assume default 10ms tick */
|
||||
tp->tv_nsec = 10000000;
|
||||
# endif
|
||||
return 0;
|
||||
}
|
||||
#endif /* HAVE_CLOCK_GETRES */
|
||||
|
||||
#ifndef HAVE_SETGROUPS
|
||||
int
|
||||
setgroups(size_t size, const gid_t *list)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif /* HAVE_SETGROUPS */
|
||||
|
||||
#ifndef HAVE_STRSIGNAL
|
||||
char *
|
||||
strsignal(int sig)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
89
external/bsd/openntpd/dist/openbsd-compat/bsd-poll.c
vendored
Normal file
89
external/bsd/openntpd/dist/openbsd-compat/bsd-poll.c
vendored
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
/* $Id: bsd-poll.c,v 1.5 2005/07/03 14:29:43 dtucker Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004, 2005 Darren Tucker (dtucker at zip com au).
|
||||
*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#if !defined(HAVE_POLL) && defined(HAVE_SELECT)
|
||||
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
# include <sys/select.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include "bsd-poll.h"
|
||||
|
||||
int
|
||||
poll(struct pollfd *fds, nfds_t nfds, int timeout)
|
||||
{
|
||||
nfds_t i;
|
||||
int ret, fd, maxfd = 0;
|
||||
fd_set readfds, writefds, exceptfds;
|
||||
struct timeval tv, *tvp = NULL;
|
||||
|
||||
if (nfds > FD_SETSIZE) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
FD_ZERO(&readfds);
|
||||
FD_ZERO(&writefds);
|
||||
FD_ZERO(&exceptfds);
|
||||
|
||||
/* poll timeout is msec, select is timeval (sec + usec) */
|
||||
if (timeout >= 0) {
|
||||
tv.tv_sec = timeout / 1000;
|
||||
tv.tv_usec = (timeout % 1000) * 1000;
|
||||
tvp = &tv;
|
||||
}
|
||||
|
||||
/* populate event bit vectors for the events we're interested in */
|
||||
for (i = 0; i < nfds; i++) {
|
||||
fd = fds[i].fd;
|
||||
if (fd == -1)
|
||||
continue;
|
||||
maxfd = MAX(maxfd, fd);
|
||||
if (fds[i].events & POLLIN) {
|
||||
FD_SET(fd, &readfds);
|
||||
FD_SET(fd, &exceptfds);
|
||||
}
|
||||
if (fds[i].events & POLLOUT) {
|
||||
FD_SET(fd, &writefds);
|
||||
FD_SET(fd, &exceptfds);
|
||||
}
|
||||
}
|
||||
|
||||
ret = select(maxfd + 1, &readfds, &writefds, &exceptfds, tvp);
|
||||
|
||||
/* scan through select results and set poll() flags */
|
||||
for (i = 0; i < nfds; i++) {
|
||||
fd = fds[i].fd;
|
||||
fds[i].revents = 0;
|
||||
if (fd == -1)
|
||||
continue;
|
||||
if (FD_ISSET(fd, &readfds)) {
|
||||
fds[i].revents |= POLLIN;
|
||||
}
|
||||
if (FD_ISSET(fd, &writefds)) {
|
||||
fds[i].revents |= POLLOUT;
|
||||
}
|
||||
if (FD_ISSET(fd, &exceptfds)) {
|
||||
fds[i].revents |= POLLERR;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
56
external/bsd/openntpd/dist/openbsd-compat/bsd-poll.h
vendored
Normal file
56
external/bsd/openntpd/dist/openbsd-compat/bsd-poll.h
vendored
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/* $OpenBSD: poll.h,v 1.11 2003/12/10 23:10:08 millert Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Theo de Raadt
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 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.
|
||||
*/
|
||||
|
||||
#if !defined(HAVE_POLL) && !defined(HAVE_POLL_H)
|
||||
#ifndef _COMPAT_POLL_H_
|
||||
#define _COMPAT_POLL_H_
|
||||
|
||||
typedef struct pollfd {
|
||||
int fd;
|
||||
short events;
|
||||
short revents;
|
||||
} pollfd_t;
|
||||
|
||||
typedef unsigned int nfds_t;
|
||||
|
||||
#define POLLIN 0x0001
|
||||
#define POLLPRI 0x0002
|
||||
#define POLLOUT 0x0004
|
||||
#define POLLERR 0x0008
|
||||
#define POLLHUP 0x0010
|
||||
#define POLLNVAL 0x0020
|
||||
#define POLLRDNORM 0x0040
|
||||
#define POLLNORM POLLRDNORM
|
||||
#define POLLWRNORM POLLOUT
|
||||
#define POLLRDBAND 0x0080
|
||||
#define POLLWRBAND 0x0100
|
||||
|
||||
#define INFTIM (-1)
|
||||
|
||||
int poll(struct pollfd *, nfds_t, int);
|
||||
#endif /* !_COMPAT_POLL_H_ */
|
||||
#endif /* !HAVE_POLL_H */
|
||||
44
external/bsd/openntpd/dist/openbsd-compat/bsd-setresgid.c
vendored
Normal file
44
external/bsd/openntpd/dist/openbsd-compat/bsd-setresgid.c
vendored
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/* $Id: bsd-setresgid.c,v 1.3 2005/07/06 06:24:52 dtucker Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004, 2005 Darren Tucker (dtucker at zip com au).
|
||||
*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#if !defined(HAVE_SETRESGID) && !defined(BROKEN_SETRESGID)
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
setresgid(gid_t rgid, gid_t egid, gid_t sgid)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* this is the only configuration tested */
|
||||
if (rgid != egid || egid != sgid)
|
||||
return -1;
|
||||
# if defined(HAVE_SETREGID) && !defined(BROKEN_SETREGID)
|
||||
if ((ret = setregid(rgid, egid)) == -1)
|
||||
return -1;
|
||||
# else
|
||||
if (setegid(egid) == -1)
|
||||
return -1;
|
||||
if((ret = setgid(rgid)) == -1)
|
||||
return -1;
|
||||
# endif
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
71
external/bsd/openntpd/dist/openbsd-compat/bsd-setresuid.c
vendored
Normal file
71
external/bsd/openntpd/dist/openbsd-compat/bsd-setresuid.c
vendored
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/* $Id: bsd-setresuid.c,v 1.3 2005/07/06 06:24:52 dtucker Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004, 2005 Darren Tucker (dtucker at zip com au).
|
||||
*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#if !defined(HAVE_SETRESUID) && !defined(BROKEN_SETRESUID)
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
setresuid(uid_t ruid, uid_t euid, uid_t suid)
|
||||
{
|
||||
uid_t ouid;
|
||||
int ret = -1;
|
||||
|
||||
/* Allow only the tested configuration. */
|
||||
if (ruid != euid || euid != suid) {
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
ouid = getuid();
|
||||
|
||||
# if defined(HAVE_SETREUID) && !defined(BROKEN_SETREUID)
|
||||
if ((ret = setreuid(euid, euid)) == -1)
|
||||
return -1;
|
||||
# else
|
||||
# ifndef SETEUID_BREAKS_SETUID
|
||||
if (seteuid(euid) == -1)
|
||||
return -1;
|
||||
# endif
|
||||
if ((ret = setuid(ruid)) == -1)
|
||||
return -1;
|
||||
# endif
|
||||
|
||||
/*
|
||||
* When real, effective and saved uids are the same and we have
|
||||
* changed uids, sanity check that we cannot restore the old uid.
|
||||
*/
|
||||
if (ruid == euid && euid == suid && ouid != ruid &&
|
||||
setuid(ouid) != -1 && seteuid(ouid) != -1) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Finally, check that the real and effective uids are what we
|
||||
* expect.
|
||||
*/
|
||||
if (getuid() != ruid || geteuid() != euid) {
|
||||
errno = EACCES;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
666
external/bsd/openntpd/dist/openbsd-compat/bsd-snprintf.c
vendored
Normal file
666
external/bsd/openntpd/dist/openbsd-compat/bsd-snprintf.c
vendored
Normal file
|
|
@ -0,0 +1,666 @@
|
|||
/*
|
||||
* Copyright Patrick Powell 1995
|
||||
* This code is based on code written by Patrick Powell (papowell@astart.com)
|
||||
* It may be used for any purpose as long as this notice remains intact
|
||||
* on all source code distributions
|
||||
*/
|
||||
|
||||
/**************************************************************
|
||||
* Original:
|
||||
* Patrick Powell Tue Apr 11 09:48:21 PDT 1995
|
||||
* A bombproof version of doprnt (dopr) included.
|
||||
* Sigh. This sort of thing is always nasty do deal with. Note that
|
||||
* the version here does not include floating point...
|
||||
*
|
||||
* snprintf() is used instead of sprintf() as it does limit checks
|
||||
* for string length. This covers a nasty loophole.
|
||||
*
|
||||
* The other functions are there to prevent NULL pointers from
|
||||
* causing nast effects.
|
||||
*
|
||||
* More Recently:
|
||||
* Brandon Long <blong@fiction.net> 9/15/96 for mutt 0.43
|
||||
* This was ugly. It is still ugly. I opted out of floating point
|
||||
* numbers, but the formatter understands just about everything
|
||||
* from the normal C string format, at least as far as I can tell from
|
||||
* the Solaris 2.5 printf(3S) man page.
|
||||
*
|
||||
* Brandon Long <blong@fiction.net> 10/22/97 for mutt 0.87.1
|
||||
* Ok, added some minimal floating point support, which means this
|
||||
* probably requires libm on most operating systems. Don't yet
|
||||
* support the exponent (e,E) and sigfig (g,G). Also, fmtint()
|
||||
* was pretty badly broken, it just wasn't being exercised in ways
|
||||
* which showed it, so that's been fixed. Also, formated the code
|
||||
* to mutt conventions, and removed dead code left over from the
|
||||
* original. Also, there is now a builtin-test, just compile with:
|
||||
* gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm
|
||||
* and run snprintf for results.
|
||||
*
|
||||
* Thomas Roessler <roessler@guug.de> 01/27/98 for mutt 0.89i
|
||||
* The PGP code was using unsigned hexadecimal formats.
|
||||
* Unfortunately, unsigned formats simply didn't work.
|
||||
*
|
||||
* Michael Elkins <me@cs.hmc.edu> 03/05/98 for mutt 0.90.8
|
||||
* The original code assumed that both snprintf() and vsnprintf() were
|
||||
* missing. Some systems only have snprintf() but not vsnprintf(), so
|
||||
* the code is now broken down under HAVE_SNPRINTF and HAVE_VSNPRINTF.
|
||||
*
|
||||
* Ben Lindstrom <mouring@eviladmin.org> 09/27/00 for OpenSSH
|
||||
* Welcome to the world of %lld and %qd support. With other
|
||||
* long long support. This is needed for sftp-server to work
|
||||
* right.
|
||||
*
|
||||
* Ben Lindstrom <mouring@eviladmin.org> 02/12/01 for OpenSSH
|
||||
* Removed all hint of VARARGS stuff and banished it to the void,
|
||||
* and did a bit of KNF style work to make things a bit more
|
||||
* acceptable. Consider stealing from mutt or enlightenment.
|
||||
**************************************************************/
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
RCSID("$Id: bsd-snprintf.c,v 1.2 2004/12/18 04:28:16 dtucker Exp $");
|
||||
|
||||
#if defined(BROKEN_SNPRINTF) /* For those with broken snprintf() */
|
||||
# undef HAVE_SNPRINTF
|
||||
# undef HAVE_VSNPRINTF
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF)
|
||||
|
||||
static void
|
||||
dopr(char *buffer, size_t maxlen, const char *format, va_list args);
|
||||
|
||||
static void
|
||||
fmtstr(char *buffer, size_t *currlen, size_t maxlen, char *value, int flags,
|
||||
int min, int max);
|
||||
|
||||
static void
|
||||
fmtint(char *buffer, size_t *currlen, size_t maxlen, long value, int base,
|
||||
int min, int max, int flags);
|
||||
|
||||
static void
|
||||
fmtfp(char *buffer, size_t *currlen, size_t maxlen, long double fvalue,
|
||||
int min, int max, int flags);
|
||||
|
||||
static void
|
||||
dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c);
|
||||
|
||||
/*
|
||||
* dopr(): poor man's version of doprintf
|
||||
*/
|
||||
|
||||
/* format read states */
|
||||
#define DP_S_DEFAULT 0
|
||||
#define DP_S_FLAGS 1
|
||||
#define DP_S_MIN 2
|
||||
#define DP_S_DOT 3
|
||||
#define DP_S_MAX 4
|
||||
#define DP_S_MOD 5
|
||||
#define DP_S_CONV 6
|
||||
#define DP_S_DONE 7
|
||||
|
||||
/* format flags - Bits */
|
||||
#define DP_F_MINUS (1 << 0)
|
||||
#define DP_F_PLUS (1 << 1)
|
||||
#define DP_F_SPACE (1 << 2)
|
||||
#define DP_F_NUM (1 << 3)
|
||||
#define DP_F_ZERO (1 << 4)
|
||||
#define DP_F_UP (1 << 5)
|
||||
#define DP_F_UNSIGNED (1 << 6)
|
||||
|
||||
/* Conversion Flags */
|
||||
#define DP_C_SHORT 1
|
||||
#define DP_C_LONG 2
|
||||
#define DP_C_LDOUBLE 3
|
||||
#define DP_C_LONG_LONG 4
|
||||
|
||||
#define char_to_int(p) (p - '0')
|
||||
#define abs_val(p) (p < 0 ? -p : p)
|
||||
|
||||
|
||||
static void
|
||||
dopr(char *buffer, size_t maxlen, const char *format, va_list args)
|
||||
{
|
||||
char *strvalue, ch;
|
||||
long value;
|
||||
long double fvalue;
|
||||
int min = 0, max = -1, state = DP_S_DEFAULT, flags = 0, cflags = 0;
|
||||
size_t currlen = 0;
|
||||
|
||||
ch = *format++;
|
||||
|
||||
while (state != DP_S_DONE) {
|
||||
if ((ch == '\0') || (currlen >= maxlen))
|
||||
state = DP_S_DONE;
|
||||
|
||||
switch(state) {
|
||||
case DP_S_DEFAULT:
|
||||
if (ch == '%')
|
||||
state = DP_S_FLAGS;
|
||||
else
|
||||
dopr_outch(buffer, &currlen, maxlen, ch);
|
||||
ch = *format++;
|
||||
break;
|
||||
case DP_S_FLAGS:
|
||||
switch (ch) {
|
||||
case '-':
|
||||
flags |= DP_F_MINUS;
|
||||
ch = *format++;
|
||||
break;
|
||||
case '+':
|
||||
flags |= DP_F_PLUS;
|
||||
ch = *format++;
|
||||
break;
|
||||
case ' ':
|
||||
flags |= DP_F_SPACE;
|
||||
ch = *format++;
|
||||
break;
|
||||
case '#':
|
||||
flags |= DP_F_NUM;
|
||||
ch = *format++;
|
||||
break;
|
||||
case '0':
|
||||
flags |= DP_F_ZERO;
|
||||
ch = *format++;
|
||||
break;
|
||||
default:
|
||||
state = DP_S_MIN;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case DP_S_MIN:
|
||||
if (isdigit((unsigned char)ch)) {
|
||||
min = 10 * min + char_to_int (ch);
|
||||
ch = *format++;
|
||||
} else if (ch == '*') {
|
||||
min = va_arg (args, int);
|
||||
ch = *format++;
|
||||
state = DP_S_DOT;
|
||||
} else
|
||||
state = DP_S_DOT;
|
||||
break;
|
||||
case DP_S_DOT:
|
||||
if (ch == '.') {
|
||||
state = DP_S_MAX;
|
||||
ch = *format++;
|
||||
} else
|
||||
state = DP_S_MOD;
|
||||
break;
|
||||
case DP_S_MAX:
|
||||
if (isdigit((unsigned char)ch)) {
|
||||
if (max < 0)
|
||||
max = 0;
|
||||
max = 10 * max + char_to_int(ch);
|
||||
ch = *format++;
|
||||
} else if (ch == '*') {
|
||||
max = va_arg (args, int);
|
||||
ch = *format++;
|
||||
state = DP_S_MOD;
|
||||
} else
|
||||
state = DP_S_MOD;
|
||||
break;
|
||||
case DP_S_MOD:
|
||||
switch (ch) {
|
||||
case 'h':
|
||||
cflags = DP_C_SHORT;
|
||||
ch = *format++;
|
||||
break;
|
||||
case 'l':
|
||||
cflags = DP_C_LONG;
|
||||
ch = *format++;
|
||||
#ifndef NO_LONG_LONG
|
||||
if (ch == 'l') {
|
||||
cflags = DP_C_LONG_LONG;
|
||||
ch = *format++;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
#ifndef NO_LONG_LONG
|
||||
case 'q':
|
||||
cflags = DP_C_LONG_LONG;
|
||||
ch = *format++;
|
||||
break;
|
||||
#endif
|
||||
case 'L':
|
||||
cflags = DP_C_LDOUBLE;
|
||||
ch = *format++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
state = DP_S_CONV;
|
||||
break;
|
||||
case DP_S_CONV:
|
||||
switch (ch) {
|
||||
case 'd':
|
||||
case 'i':
|
||||
if (cflags == DP_C_SHORT)
|
||||
value = va_arg(args, int);
|
||||
else if (cflags == DP_C_LONG)
|
||||
value = va_arg(args, long int);
|
||||
#ifndef NO_LONG_LONG
|
||||
else if (cflags == DP_C_LONG_LONG)
|
||||
value = va_arg (args, long long);
|
||||
#endif
|
||||
else
|
||||
value = va_arg (args, int);
|
||||
fmtint(buffer, &currlen, maxlen, value, 10, min, max, flags);
|
||||
break;
|
||||
case 'o':
|
||||
flags |= DP_F_UNSIGNED;
|
||||
if (cflags == DP_C_SHORT)
|
||||
value = va_arg(args, unsigned int);
|
||||
else if (cflags == DP_C_LONG)
|
||||
value = va_arg(args, unsigned long int);
|
||||
#ifndef NO_LONG_LONG
|
||||
else if (cflags == DP_C_LONG_LONG)
|
||||
value = va_arg(args, unsigned long long);
|
||||
#endif
|
||||
else
|
||||
value = va_arg(args, unsigned int);
|
||||
fmtint(buffer, &currlen, maxlen, value, 8, min, max, flags);
|
||||
break;
|
||||
case 'u':
|
||||
flags |= DP_F_UNSIGNED;
|
||||
if (cflags == DP_C_SHORT)
|
||||
value = va_arg(args, unsigned int);
|
||||
else if (cflags == DP_C_LONG)
|
||||
value = va_arg(args, unsigned long int);
|
||||
#ifndef NO_LONG_LONG
|
||||
else if (cflags == DP_C_LONG_LONG)
|
||||
value = va_arg(args, unsigned long long);
|
||||
#endif
|
||||
else
|
||||
value = va_arg(args, unsigned int);
|
||||
fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
|
||||
break;
|
||||
case 'X':
|
||||
flags |= DP_F_UP;
|
||||
case 'x':
|
||||
flags |= DP_F_UNSIGNED;
|
||||
if (cflags == DP_C_SHORT)
|
||||
value = va_arg(args, unsigned int);
|
||||
else if (cflags == DP_C_LONG)
|
||||
value = va_arg(args, unsigned long int);
|
||||
#ifndef NO_LONG_LONG
|
||||
else if (cflags == DP_C_LONG_LONG)
|
||||
value = va_arg(args, unsigned long long);
|
||||
#endif
|
||||
else
|
||||
value = va_arg(args, unsigned int);
|
||||
fmtint(buffer, &currlen, maxlen, value, 16, min, max, flags);
|
||||
break;
|
||||
case 'f':
|
||||
if (cflags == DP_C_LDOUBLE)
|
||||
fvalue = va_arg(args, long double);
|
||||
else
|
||||
fvalue = va_arg(args, double);
|
||||
/* um, floating point? */
|
||||
fmtfp(buffer, &currlen, maxlen, fvalue, min, max, flags);
|
||||
break;
|
||||
case 'E':
|
||||
flags |= DP_F_UP;
|
||||
case 'e':
|
||||
if (cflags == DP_C_LDOUBLE)
|
||||
fvalue = va_arg(args, long double);
|
||||
else
|
||||
fvalue = va_arg(args, double);
|
||||
break;
|
||||
case 'G':
|
||||
flags |= DP_F_UP;
|
||||
case 'g':
|
||||
if (cflags == DP_C_LDOUBLE)
|
||||
fvalue = va_arg(args, long double);
|
||||
else
|
||||
fvalue = va_arg(args, double);
|
||||
break;
|
||||
case 'c':
|
||||
dopr_outch(buffer, &currlen, maxlen, va_arg(args, int));
|
||||
break;
|
||||
case 's':
|
||||
strvalue = va_arg(args, char *);
|
||||
if (max < 0)
|
||||
max = maxlen; /* ie, no max */
|
||||
fmtstr(buffer, &currlen, maxlen, strvalue, flags, min, max);
|
||||
break;
|
||||
case 'p':
|
||||
strvalue = va_arg(args, void *);
|
||||
fmtint(buffer, &currlen, maxlen, (long) strvalue, 16, min, max, flags);
|
||||
break;
|
||||
case 'n':
|
||||
if (cflags == DP_C_SHORT) {
|
||||
short int *num;
|
||||
num = va_arg(args, short int *);
|
||||
*num = currlen;
|
||||
} else if (cflags == DP_C_LONG) {
|
||||
long int *num;
|
||||
num = va_arg(args, long int *);
|
||||
*num = currlen;
|
||||
#ifndef NO_LONG_LONG
|
||||
} else if (cflags == DP_C_LONG_LONG) {
|
||||
long long *num;
|
||||
num = va_arg(args, long long *);
|
||||
*num = currlen;
|
||||
#endif
|
||||
} else {
|
||||
int *num;
|
||||
num = va_arg(args, int *);
|
||||
*num = currlen;
|
||||
}
|
||||
break;
|
||||
case '%':
|
||||
dopr_outch(buffer, &currlen, maxlen, ch);
|
||||
break;
|
||||
case 'w': /* not supported yet, treat as next char */
|
||||
ch = *format++;
|
||||
break;
|
||||
default: /* Unknown, skip */
|
||||
break;
|
||||
}
|
||||
ch = *format++;
|
||||
state = DP_S_DEFAULT;
|
||||
flags = cflags = min = 0;
|
||||
max = -1;
|
||||
break;
|
||||
case DP_S_DONE:
|
||||
break;
|
||||
default: /* hmm? */
|
||||
break; /* some picky compilers need this */
|
||||
}
|
||||
}
|
||||
if (currlen < maxlen - 1)
|
||||
buffer[currlen] = '\0';
|
||||
else
|
||||
buffer[maxlen - 1] = '\0';
|
||||
}
|
||||
|
||||
static void
|
||||
fmtstr(char *buffer, size_t *currlen, size_t maxlen,
|
||||
char *value, int flags, int min, int max)
|
||||
{
|
||||
int cnt = 0, padlen, strln; /* amount to pad */
|
||||
|
||||
if (value == 0)
|
||||
value = "<NULL>";
|
||||
|
||||
for (strln = 0; strln < max && value[strln]; ++strln); /* strlen */
|
||||
padlen = min - strln;
|
||||
if (padlen < 0)
|
||||
padlen = 0;
|
||||
if (flags & DP_F_MINUS)
|
||||
padlen = -padlen; /* Left Justify */
|
||||
|
||||
while ((padlen > 0) && (cnt < max)) {
|
||||
dopr_outch(buffer, currlen, maxlen, ' ');
|
||||
--padlen;
|
||||
++cnt;
|
||||
}
|
||||
while (*value && (cnt < max)) {
|
||||
dopr_outch(buffer, currlen, maxlen, *value++);
|
||||
++cnt;
|
||||
}
|
||||
while ((padlen < 0) && (cnt < max)) {
|
||||
dopr_outch(buffer, currlen, maxlen, ' ');
|
||||
++padlen;
|
||||
++cnt;
|
||||
}
|
||||
}
|
||||
|
||||
/* Have to handle DP_F_NUM (ie 0x and 0 alternates) */
|
||||
|
||||
static void
|
||||
fmtint(char *buffer, size_t *currlen, size_t maxlen,
|
||||
long value, int base, int min, int max, int flags)
|
||||
{
|
||||
unsigned long uvalue;
|
||||
char convert[20];
|
||||
int signvalue = 0, place = 0, caps = 0;
|
||||
int spadlen = 0; /* amount to space pad */
|
||||
int zpadlen = 0; /* amount to zero pad */
|
||||
|
||||
if (max < 0)
|
||||
max = 0;
|
||||
|
||||
uvalue = value;
|
||||
|
||||
if (!(flags & DP_F_UNSIGNED)) {
|
||||
if (value < 0) {
|
||||
signvalue = '-';
|
||||
uvalue = -value;
|
||||
} else if (flags & DP_F_PLUS) /* Do a sign (+/i) */
|
||||
signvalue = '+';
|
||||
else if (flags & DP_F_SPACE)
|
||||
signvalue = ' ';
|
||||
}
|
||||
|
||||
if (flags & DP_F_UP)
|
||||
caps = 1; /* Should characters be upper case? */
|
||||
do {
|
||||
convert[place++] =
|
||||
(caps ? "0123456789ABCDEF" : "0123456789abcdef")
|
||||
[uvalue % (unsigned)base];
|
||||
uvalue = (uvalue / (unsigned)base );
|
||||
} while (uvalue && (place < 20));
|
||||
if (place == 20)
|
||||
place--;
|
||||
convert[place] = 0;
|
||||
|
||||
zpadlen = max - place;
|
||||
spadlen = min - MAX (max, place) - (signvalue ? 1 : 0);
|
||||
if (zpadlen < 0)
|
||||
zpadlen = 0;
|
||||
if (spadlen < 0)
|
||||
spadlen = 0;
|
||||
if (flags & DP_F_ZERO) {
|
||||
zpadlen = MAX(zpadlen, spadlen);
|
||||
spadlen = 0;
|
||||
}
|
||||
if (flags & DP_F_MINUS)
|
||||
spadlen = -spadlen; /* Left Justifty */
|
||||
|
||||
/* Spaces */
|
||||
while (spadlen > 0) {
|
||||
dopr_outch(buffer, currlen, maxlen, ' ');
|
||||
--spadlen;
|
||||
}
|
||||
|
||||
/* Sign */
|
||||
if (signvalue)
|
||||
dopr_outch(buffer, currlen, maxlen, signvalue);
|
||||
|
||||
/* Zeros */
|
||||
if (zpadlen > 0) {
|
||||
while (zpadlen > 0) {
|
||||
dopr_outch(buffer, currlen, maxlen, '0');
|
||||
--zpadlen;
|
||||
}
|
||||
}
|
||||
|
||||
/* Digits */
|
||||
while (place > 0)
|
||||
dopr_outch(buffer, currlen, maxlen, convert[--place]);
|
||||
|
||||
/* Left Justified spaces */
|
||||
while (spadlen < 0) {
|
||||
dopr_outch (buffer, currlen, maxlen, ' ');
|
||||
++spadlen;
|
||||
}
|
||||
}
|
||||
|
||||
static long double
|
||||
pow10(int exp)
|
||||
{
|
||||
long double result = 1;
|
||||
|
||||
while (exp) {
|
||||
result *= 10;
|
||||
exp--;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static long
|
||||
round(long double value)
|
||||
{
|
||||
long intpart = value;
|
||||
|
||||
value -= intpart;
|
||||
if (value >= 0.5)
|
||||
intpart++;
|
||||
|
||||
return intpart;
|
||||
}
|
||||
|
||||
static void
|
||||
fmtfp(char *buffer, size_t *currlen, size_t maxlen, long double fvalue,
|
||||
int min, int max, int flags)
|
||||
{
|
||||
char iconvert[20], fconvert[20];
|
||||
int signvalue = 0, iplace = 0, fplace = 0;
|
||||
int padlen = 0; /* amount to pad */
|
||||
int zpadlen = 0, caps = 0;
|
||||
long intpart, fracpart;
|
||||
long double ufvalue;
|
||||
|
||||
/*
|
||||
* AIX manpage says the default is 0, but Solaris says the default
|
||||
* is 6, and sprintf on AIX defaults to 6
|
||||
*/
|
||||
if (max < 0)
|
||||
max = 6;
|
||||
|
||||
ufvalue = abs_val(fvalue);
|
||||
|
||||
if (fvalue < 0)
|
||||
signvalue = '-';
|
||||
else if (flags & DP_F_PLUS) /* Do a sign (+/i) */
|
||||
signvalue = '+';
|
||||
else if (flags & DP_F_SPACE)
|
||||
signvalue = ' ';
|
||||
|
||||
intpart = ufvalue;
|
||||
|
||||
/*
|
||||
* Sorry, we only support 9 digits past the decimal because of our
|
||||
* conversion method
|
||||
*/
|
||||
if (max > 9)
|
||||
max = 9;
|
||||
|
||||
/* We "cheat" by converting the fractional part to integer by
|
||||
* multiplying by a factor of 10
|
||||
*/
|
||||
fracpart = round((pow10 (max)) * (ufvalue - intpart));
|
||||
|
||||
if (fracpart >= pow10 (max)) {
|
||||
intpart++;
|
||||
fracpart -= pow10 (max);
|
||||
}
|
||||
|
||||
/* Convert integer part */
|
||||
do {
|
||||
iconvert[iplace++] =
|
||||
(caps ? "0123456789ABCDEF" : "0123456789abcdef")
|
||||
[intpart % 10];
|
||||
intpart = (intpart / 10);
|
||||
} while(intpart && (iplace < 20));
|
||||
if (iplace == 20)
|
||||
iplace--;
|
||||
iconvert[iplace] = 0;
|
||||
|
||||
/* Convert fractional part */
|
||||
do {
|
||||
fconvert[fplace++] =
|
||||
(caps ? "0123456789ABCDEF" : "0123456789abcdef")
|
||||
[fracpart % 10];
|
||||
fracpart = (fracpart / 10);
|
||||
} while(fracpart && (fplace < 20));
|
||||
if (fplace == 20)
|
||||
fplace--;
|
||||
fconvert[fplace] = 0;
|
||||
|
||||
/* -1 for decimal point, another -1 if we are printing a sign */
|
||||
padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0);
|
||||
zpadlen = max - fplace;
|
||||
if (zpadlen < 0)
|
||||
zpadlen = 0;
|
||||
if (padlen < 0)
|
||||
padlen = 0;
|
||||
if (flags & DP_F_MINUS)
|
||||
padlen = -padlen; /* Left Justifty */
|
||||
|
||||
if ((flags & DP_F_ZERO) && (padlen > 0)) {
|
||||
if (signvalue) {
|
||||
dopr_outch(buffer, currlen, maxlen, signvalue);
|
||||
--padlen;
|
||||
signvalue = 0;
|
||||
}
|
||||
while (padlen > 0) {
|
||||
dopr_outch(buffer, currlen, maxlen, '0');
|
||||
--padlen;
|
||||
}
|
||||
}
|
||||
while (padlen > 0) {
|
||||
dopr_outch(buffer, currlen, maxlen, ' ');
|
||||
--padlen;
|
||||
}
|
||||
if (signvalue)
|
||||
dopr_outch(buffer, currlen, maxlen, signvalue);
|
||||
|
||||
while (iplace > 0)
|
||||
dopr_outch(buffer, currlen, maxlen, iconvert[--iplace]);
|
||||
|
||||
/*
|
||||
* Decimal point. This should probably use locale to find the
|
||||
* correct char to print out.
|
||||
*/
|
||||
dopr_outch(buffer, currlen, maxlen, '.');
|
||||
|
||||
while (fplace > 0)
|
||||
dopr_outch(buffer, currlen, maxlen, fconvert[--fplace]);
|
||||
|
||||
while (zpadlen > 0) {
|
||||
dopr_outch(buffer, currlen, maxlen, '0');
|
||||
--zpadlen;
|
||||
}
|
||||
|
||||
while (padlen < 0) {
|
||||
dopr_outch(buffer, currlen, maxlen, ' ');
|
||||
++padlen;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c)
|
||||
{
|
||||
if (*currlen < maxlen)
|
||||
buffer[(*currlen)++] = c;
|
||||
}
|
||||
#endif /* !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) */
|
||||
|
||||
#ifndef HAVE_VSNPRINTF
|
||||
int
|
||||
vsnprintf(char *str, size_t count, const char *fmt, va_list args)
|
||||
{
|
||||
str[0] = 0;
|
||||
dopr(str, count, fmt, args);
|
||||
|
||||
return(strlen(str));
|
||||
}
|
||||
#endif /* !HAVE_VSNPRINTF */
|
||||
|
||||
#ifndef HAVE_SNPRINTF
|
||||
int
|
||||
snprintf(char *str,size_t count,const char *fmt,...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
(void) vsnprintf(str, count, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return(strlen(str));
|
||||
}
|
||||
|
||||
#endif /* !HAVE_SNPRINTF */
|
||||
81
external/bsd/openntpd/dist/openbsd-compat/daemon.c
vendored
Normal file
81
external/bsd/openntpd/dist/openbsd-compat/daemon.c
vendored
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/* OPENBSD ORIGINAL: lib/libc/gen/daemon.c */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990, 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
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
#ifndef HAVE_DAEMON
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char rcsid[] = "$OpenBSD: daemon.c,v 1.5 2003/07/15 17:32:41 deraadt Exp $";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
int
|
||||
daemon(int nochdir, int noclose)
|
||||
{
|
||||
int fd;
|
||||
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
return (-1);
|
||||
case 0:
|
||||
#ifdef HAVE_CYGWIN
|
||||
register_9x_service();
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
#ifdef HAVE_CYGWIN
|
||||
/*
|
||||
* This sleep avoids a race condition which kills the
|
||||
* child process if parent is started by a NT/W2K service.
|
||||
*/
|
||||
sleep(1);
|
||||
#endif
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
if (setsid() == -1)
|
||||
return (-1);
|
||||
|
||||
if (!nochdir)
|
||||
(void)chdir("/");
|
||||
|
||||
if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
|
||||
(void)dup2(fd, STDIN_FILENO);
|
||||
(void)dup2(fd, STDOUT_FILENO);
|
||||
(void)dup2(fd, STDERR_FILENO);
|
||||
if (fd > 2)
|
||||
(void)close (fd);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif /* !HAVE_DAEMON */
|
||||
|
||||
52
external/bsd/openntpd/dist/openbsd-compat/errx.c
vendored
Normal file
52
external/bsd/openntpd/dist/openbsd-compat/errx.c
vendored
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/*-
|
||||
* Copyright (c) 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
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#ifndef HAVE_ERRX
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char rcsid[] = "$OpenBSD: errx.c,v 1.7 2003/06/02 20:18:34 millert Exp $";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
/* #include <sys/cdefs.h>
|
||||
#include <err.h> */
|
||||
#include <stdarg.h>
|
||||
|
||||
__dead void
|
||||
errx(int eval, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
verrx(eval, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
/* __weak_alias(errx, _errx); */
|
||||
#endif /* HAVE_ERRX */
|
||||
228
external/bsd/openntpd/dist/openbsd-compat/fake-rfc2553.c
vendored
Normal file
228
external/bsd/openntpd/dist/openbsd-compat/fake-rfc2553.c
vendored
Normal file
|
|
@ -0,0 +1,228 @@
|
|||
/*
|
||||
* Copyright (C) 2000-2003 Damien Miller. All rights reserved.
|
||||
* Copyright (C) 1999 WIDE Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Pseudo-implementation of RFC2553 name / address resolution functions
|
||||
*
|
||||
* But these functions are not implemented correctly. The minimum subset
|
||||
* is implemented for ssh use only. For example, this routine assumes
|
||||
* that ai_family is AF_INET. Don't use it for another purpose.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
/* RCSID("$Id: fake-rfc2553.c,v 1.2.2.1 2006/05/14 05:42:51 dtucker Exp $"); */
|
||||
|
||||
#ifndef HAVE_IN6ADDR_ANY
|
||||
const struct in6_addr in6addr_any = {{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}};
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_GETNAMEINFO
|
||||
int getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
|
||||
size_t hostlen, char *serv, size_t servlen, int flags)
|
||||
{
|
||||
struct sockaddr_in *sin = (struct sockaddr_in *)sa;
|
||||
struct hostent *hp;
|
||||
char tmpserv[16];
|
||||
|
||||
if (serv != NULL) {
|
||||
snprintf(tmpserv, sizeof(tmpserv), "%d", ntohs(sin->sin_port));
|
||||
if (strlcpy(serv, tmpserv, servlen) >= servlen)
|
||||
return (EAI_MEMORY);
|
||||
}
|
||||
|
||||
if (host != NULL) {
|
||||
if (flags & NI_NUMERICHOST) {
|
||||
if (strlcpy(host, inet_ntoa(sin->sin_addr),
|
||||
hostlen) >= hostlen)
|
||||
return (EAI_MEMORY);
|
||||
else
|
||||
return (0);
|
||||
} else {
|
||||
hp = gethostbyaddr((char *)&sin->sin_addr,
|
||||
sizeof(struct in_addr), AF_INET);
|
||||
if (hp == NULL)
|
||||
return (EAI_NODATA);
|
||||
|
||||
if (strlcpy(host, hp->h_name, hostlen) >= hostlen)
|
||||
return (EAI_MEMORY);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif /* !HAVE_GETNAMEINFO */
|
||||
|
||||
#ifndef HAVE_GAI_STRERROR
|
||||
#ifdef HAVE_CONST_GAI_STRERROR_PROTO
|
||||
const char *
|
||||
#else
|
||||
char *
|
||||
#endif
|
||||
gai_strerror(int err)
|
||||
{
|
||||
switch (err) {
|
||||
case EAI_NODATA:
|
||||
return ("no address associated with name");
|
||||
case EAI_MEMORY:
|
||||
return ("memory allocation failure.");
|
||||
case EAI_NONAME:
|
||||
return ("nodename nor servname provided, or not known");
|
||||
default:
|
||||
return ("unknown/invalid error.");
|
||||
}
|
||||
}
|
||||
#endif /* !HAVE_GAI_STRERROR */
|
||||
|
||||
#ifndef HAVE_FREEADDRINFO
|
||||
void
|
||||
freeaddrinfo(struct addrinfo *ai)
|
||||
{
|
||||
struct addrinfo *next;
|
||||
|
||||
for(; ai != NULL;) {
|
||||
next = ai->ai_next;
|
||||
free(ai);
|
||||
ai = next;
|
||||
}
|
||||
}
|
||||
#endif /* !HAVE_FREEADDRINFO */
|
||||
|
||||
#ifndef HAVE_GETADDRINFO
|
||||
static struct
|
||||
addrinfo *malloc_ai(int port, u_long addr, const struct addrinfo *hints)
|
||||
{
|
||||
struct addrinfo *ai;
|
||||
|
||||
ai = malloc(sizeof(*ai) + sizeof(struct sockaddr_in));
|
||||
if (ai == NULL)
|
||||
return (NULL);
|
||||
|
||||
memset(ai, '\0', sizeof(*ai) + sizeof(struct sockaddr_in));
|
||||
|
||||
ai->ai_addr = (struct sockaddr *)(ai + 1);
|
||||
/* XXX -- ssh doesn't use sa_len */
|
||||
ai->ai_addrlen = sizeof(struct sockaddr_in);
|
||||
ai->ai_addr->sa_family = ai->ai_family = AF_INET;
|
||||
|
||||
((struct sockaddr_in *)(ai)->ai_addr)->sin_port = port;
|
||||
((struct sockaddr_in *)(ai)->ai_addr)->sin_addr.s_addr = addr;
|
||||
|
||||
/* XXX: the following is not generally correct, but does what we want */
|
||||
if (hints->ai_socktype)
|
||||
ai->ai_socktype = hints->ai_socktype;
|
||||
else
|
||||
ai->ai_socktype = SOCK_STREAM;
|
||||
|
||||
if (hints->ai_protocol)
|
||||
ai->ai_protocol = hints->ai_protocol;
|
||||
|
||||
return (ai);
|
||||
}
|
||||
|
||||
int
|
||||
getaddrinfo(const char *hostname, const char *servname,
|
||||
const struct addrinfo *hints, struct addrinfo **res)
|
||||
{
|
||||
struct hostent *hp;
|
||||
struct servent *sp;
|
||||
struct in_addr in;
|
||||
int i;
|
||||
long int port;
|
||||
u_long addr;
|
||||
|
||||
port = 0;
|
||||
if (servname != NULL) {
|
||||
char *cp;
|
||||
|
||||
port = strtol(servname, &cp, 10);
|
||||
if (port > 0 && port <= 65535 && *cp == '\0')
|
||||
port = htons(port);
|
||||
else if ((sp = getservbyname(servname, NULL)) != NULL)
|
||||
port = sp->s_port;
|
||||
else
|
||||
port = 0;
|
||||
}
|
||||
|
||||
if (hints && hints->ai_flags & AI_PASSIVE) {
|
||||
addr = htonl(0x00000000);
|
||||
if (hostname && inet_aton(hostname, &in) != 0)
|
||||
addr = in.s_addr;
|
||||
*res = malloc_ai(port, addr, hints);
|
||||
if (*res == NULL)
|
||||
return (EAI_MEMORY);
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (!hostname) {
|
||||
*res = malloc_ai(port, htonl(0x7f000001), hints);
|
||||
if (*res == NULL)
|
||||
return (EAI_MEMORY);
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (inet_aton(hostname, &in)) {
|
||||
*res = malloc_ai(port, in.s_addr, hints);
|
||||
if (*res == NULL)
|
||||
return (EAI_MEMORY);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Don't try DNS if AI_NUMERICHOST is set */
|
||||
if (hints && hints->ai_flags & AI_NUMERICHOST)
|
||||
return (EAI_NONAME);
|
||||
|
||||
hp = gethostbyname(hostname);
|
||||
if (hp && hp->h_name && hp->h_name[0] && hp->h_addr_list[0]) {
|
||||
struct addrinfo *cur, *prev;
|
||||
|
||||
cur = prev = *res = NULL;
|
||||
for (i = 0; hp->h_addr_list[i]; i++) {
|
||||
struct in_addr *in = (struct in_addr *)hp->h_addr_list[i];
|
||||
|
||||
cur = malloc_ai(port, in->s_addr, hints);
|
||||
if (cur == NULL) {
|
||||
if (*res != NULL)
|
||||
freeaddrinfo(*res);
|
||||
return (EAI_MEMORY);
|
||||
}
|
||||
if (prev)
|
||||
prev->ai_next = cur;
|
||||
else
|
||||
*res = cur;
|
||||
|
||||
prev = cur;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
return (EAI_NODATA);
|
||||
}
|
||||
#endif /* !HAVE_GETADDRINFO */
|
||||
169
external/bsd/openntpd/dist/openbsd-compat/fake-rfc2553.h
vendored
Normal file
169
external/bsd/openntpd/dist/openbsd-compat/fake-rfc2553.h
vendored
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
/* $Id: fake-rfc2553.h,v 1.3 2006/01/19 13:00:01 dtucker Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 2000-2003 Damien Miller. All rights reserved.
|
||||
* Copyright (C) 1999 WIDE Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Pseudo-implementation of RFC2553 name / address resolution functions
|
||||
*
|
||||
* But these functions are not implemented correctly. The minimum subset
|
||||
* is implemented for ssh use only. For example, this routine assumes
|
||||
* that ai_family is AF_INET. Don't use it for another purpose.
|
||||
*/
|
||||
|
||||
#ifndef _FAKE_RFC2553_H
|
||||
#define _FAKE_RFC2553_H
|
||||
|
||||
#include "includes.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
/*
|
||||
* First, socket and INET6 related definitions
|
||||
*/
|
||||
#ifndef HAVE_STRUCT_SOCKADDR_STORAGE
|
||||
# define _SS_MAXSIZE 128 /* Implementation specific max size */
|
||||
# define _SS_PADSIZE (_SS_MAXSIZE - sizeof (struct sockaddr))
|
||||
struct sockaddr_storage {
|
||||
struct sockaddr ss_sa;
|
||||
char __ss_pad2[_SS_PADSIZE];
|
||||
};
|
||||
# define ss_family ss_sa.sa_family
|
||||
#endif /* !HAVE_STRUCT_SOCKADDR_STORAGE */
|
||||
|
||||
#ifndef IN6_IS_ADDR_LOOPBACK
|
||||
# define IN6_IS_ADDR_LOOPBACK(a) \
|
||||
(((u_int32_t *)(a))[0] == 0 && ((u_int32_t *)(a))[1] == 0 && \
|
||||
((u_int32_t *)(a))[2] == 0 && ((u_int32_t *)(a))[3] == htonl(1))
|
||||
#endif /* !IN6_IS_ADDR_LOOPBACK */
|
||||
|
||||
#ifndef HAVE_STRUCT_IN6_ADDR
|
||||
struct in6_addr {
|
||||
u_int8_t s6_addr[16];
|
||||
};
|
||||
#endif /* !HAVE_STRUCT_IN6_ADDR */
|
||||
|
||||
#ifndef HAVE_STRUCT_SOCKADDR_IN6
|
||||
struct sockaddr_in6 {
|
||||
unsigned short sin6_family;
|
||||
u_int16_t sin6_port;
|
||||
u_int32_t sin6_flowinfo;
|
||||
struct in6_addr sin6_addr;
|
||||
};
|
||||
#endif /* !HAVE_STRUCT_SOCKADDR_IN6 */
|
||||
|
||||
#ifndef AF_INET6
|
||||
/* Define it to something that should never appear */
|
||||
#define AF_INET6 AF_MAX
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_IN6ADDR_ANY
|
||||
extern const struct in6_addr in6addr_any;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Next, RFC2553 name / address resolution API
|
||||
*/
|
||||
|
||||
#ifndef NI_NUMERICHOST
|
||||
# define NI_NUMERICHOST (1)
|
||||
#endif
|
||||
#ifndef NI_NAMEREQD
|
||||
# define NI_NAMEREQD (1<<1)
|
||||
#endif
|
||||
#ifndef NI_NUMERICSERV
|
||||
# define NI_NUMERICSERV (1<<2)
|
||||
#endif
|
||||
|
||||
#ifndef AI_PASSIVE
|
||||
# define AI_PASSIVE (1)
|
||||
#endif
|
||||
#ifndef AI_CANONNAME
|
||||
# define AI_CANONNAME (1<<1)
|
||||
#endif
|
||||
#ifndef AI_NUMERICHOST
|
||||
# define AI_NUMERICHOST (1<<2)
|
||||
#endif
|
||||
|
||||
#ifndef NI_MAXSERV
|
||||
# define NI_MAXSERV 32
|
||||
#endif /* !NI_MAXSERV */
|
||||
#ifndef NI_MAXHOST
|
||||
# define NI_MAXHOST 1025
|
||||
#endif /* !NI_MAXHOST */
|
||||
|
||||
#ifndef EAI_NODATA
|
||||
# define EAI_NODATA 0xff01
|
||||
#endif
|
||||
#ifndef EAI_MEMORY
|
||||
# define EAI_MEMORY 0xff02
|
||||
#endif
|
||||
#ifndef EAI_NONAME
|
||||
# define EAI_NONAME 0xff03
|
||||
#endif
|
||||
#ifndef EAI_AGAIN
|
||||
# define EAI_AGAIN 0xff04
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRUCT_ADDRINFO
|
||||
struct addrinfo {
|
||||
int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
|
||||
int ai_family; /* PF_xxx */
|
||||
int ai_socktype; /* SOCK_xxx */
|
||||
int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
|
||||
size_t ai_addrlen; /* length of ai_addr */
|
||||
char *ai_canonname; /* canonical name for hostname */
|
||||
struct sockaddr *ai_addr; /* binary address */
|
||||
struct addrinfo *ai_next; /* next structure in linked list */
|
||||
};
|
||||
#endif /* !HAVE_STRUCT_ADDRINFO */
|
||||
|
||||
#ifndef HAVE_GETADDRINFO
|
||||
#ifdef getaddrinfo
|
||||
# undef getaddrinfo
|
||||
#endif
|
||||
int getaddrinfo(const char *, const char *,
|
||||
const struct addrinfo *, struct addrinfo **);
|
||||
#endif /* !HAVE_GETADDRINFO */
|
||||
|
||||
#if !defined(HAVE_GAI_STRERROR) && !defined(HAVE_CONST_GAI_STRERROR_PROTO)
|
||||
char *gai_strerror(int);
|
||||
#endif /* !HAVE_GAI_STRERROR */
|
||||
|
||||
#ifndef HAVE_FREEADDRINFO
|
||||
void freeaddrinfo(struct addrinfo *);
|
||||
#endif /* !HAVE_FREEADDRINFO */
|
||||
|
||||
#ifndef HAVE_GETNAMEINFO
|
||||
int getnameinfo(const struct sockaddr *, size_t, char *, size_t,
|
||||
char *, size_t, int);
|
||||
#endif /* !HAVE_GETNAMEINFO */
|
||||
|
||||
#endif /* !_FAKE_RFC2553_H */
|
||||
|
||||
235
external/bsd/openntpd/dist/openbsd-compat/inet_pton.c
vendored
Normal file
235
external/bsd/openntpd/dist/openbsd-compat/inet_pton.c
vendored
Normal file
|
|
@ -0,0 +1,235 @@
|
|||
/* $OpenBSD: inet_pton.c,v 1.4 2002/02/16 21:27:23 millert Exp $ */
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
#ifndef HAVE_INET_PTON
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char rcsid[] = "$From: inet_pton.c,v 8.7 1996/08/05 08:31:35 vixie Exp $";
|
||||
#else
|
||||
static char rcsid[] = "$OpenBSD: inet_pton.c,v 1.4 2002/02/16 21:27:23 millert Exp $";
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <arpa/nameser.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
/*
|
||||
* WARNING: Don't even consider trying to compile this on a system where
|
||||
* sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
|
||||
*/
|
||||
|
||||
static int inet_pton4(const char *src, u_char *dst);
|
||||
#ifdef USE_IPV6
|
||||
static int inet_pton6(const char *src, u_char *dst);
|
||||
#endif
|
||||
|
||||
/* int
|
||||
* inet_pton(af, src, dst)
|
||||
* convert from presentation format (which usually means ASCII printable)
|
||||
* to network format (which is usually some kind of binary format).
|
||||
* return:
|
||||
* 1 if the address was valid for the specified address family
|
||||
* 0 if the address wasn't valid (`dst' is untouched in this case)
|
||||
* -1 if some other error occurred (`dst' is untouched in this case, too)
|
||||
* author:
|
||||
* Paul Vixie, 1996.
|
||||
*/
|
||||
int
|
||||
inet_pton(af, src, dst)
|
||||
int af;
|
||||
const char *src;
|
||||
void *dst;
|
||||
{
|
||||
switch (af) {
|
||||
case AF_INET:
|
||||
return (inet_pton4(src, dst));
|
||||
#ifdef USE_IPV6
|
||||
case AF_INET6:
|
||||
return (inet_pton6(src, dst));
|
||||
#endif
|
||||
default:
|
||||
errno = EAFNOSUPPORT;
|
||||
return (-1);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
/* int
|
||||
* inet_pton4(src, dst)
|
||||
* like inet_aton() but without all the hexadecimal and shorthand.
|
||||
* return:
|
||||
* 1 if `src' is a valid dotted quad, else 0.
|
||||
* notice:
|
||||
* does not touch `dst' unless it's returning 1.
|
||||
* author:
|
||||
* Paul Vixie, 1996.
|
||||
*/
|
||||
static int
|
||||
inet_pton4(src, dst)
|
||||
const char *src;
|
||||
u_char *dst;
|
||||
{
|
||||
static const char digits[] = "0123456789";
|
||||
int saw_digit, octets, ch;
|
||||
u_char tmp[INADDRSZ], *tp;
|
||||
|
||||
saw_digit = 0;
|
||||
octets = 0;
|
||||
*(tp = tmp) = 0;
|
||||
while ((ch = *src++) != '\0') {
|
||||
const char *pch;
|
||||
|
||||
if ((pch = strchr(digits, ch)) != NULL) {
|
||||
u_int new = *tp * 10 + (pch - digits);
|
||||
|
||||
if (new > 255)
|
||||
return (0);
|
||||
if (! saw_digit) {
|
||||
if (++octets > 4)
|
||||
return (0);
|
||||
saw_digit = 1;
|
||||
}
|
||||
*tp = new;
|
||||
} else if (ch == '.' && saw_digit) {
|
||||
if (octets == 4)
|
||||
return (0);
|
||||
*++tp = 0;
|
||||
saw_digit = 0;
|
||||
} else
|
||||
return (0);
|
||||
}
|
||||
if (octets < 4)
|
||||
return (0);
|
||||
|
||||
memcpy(dst, tmp, INADDRSZ);
|
||||
return (1);
|
||||
}
|
||||
|
||||
#ifdef USE_IPV6
|
||||
/* int
|
||||
* inet_pton6(src, dst)
|
||||
* convert presentation level address to network order binary form.
|
||||
* return:
|
||||
* 1 if `src' is a valid [RFC1884 2.2] address, else 0.
|
||||
* notice:
|
||||
* (1) does not touch `dst' unless it's returning 1.
|
||||
* (2) :: in a full address is silently ignored.
|
||||
* credit:
|
||||
* inspired by Mark Andrews.
|
||||
* author:
|
||||
* Paul Vixie, 1996.
|
||||
*/
|
||||
static int
|
||||
inet_pton6(src, dst)
|
||||
const char *src;
|
||||
u_char *dst;
|
||||
{
|
||||
static const char xdigits_l[] = "0123456789abcdef",
|
||||
xdigits_u[] = "0123456789ABCDEF";
|
||||
u_char tmp[IN6ADDRSZ], *tp, *endp, *colonp;
|
||||
const char *xdigits, *curtok;
|
||||
int ch, saw_xdigit;
|
||||
u_int val;
|
||||
|
||||
memset((tp = tmp), '\0', IN6ADDRSZ);
|
||||
endp = tp + IN6ADDRSZ;
|
||||
colonp = NULL;
|
||||
/* Leading :: requires some special handling. */
|
||||
if (*src == ':')
|
||||
if (*++src != ':')
|
||||
return (0);
|
||||
curtok = src;
|
||||
saw_xdigit = 0;
|
||||
val = 0;
|
||||
while ((ch = *src++) != '\0') {
|
||||
const char *pch;
|
||||
|
||||
if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
|
||||
pch = strchr((xdigits = xdigits_u), ch);
|
||||
if (pch != NULL) {
|
||||
val <<= 4;
|
||||
val |= (pch - xdigits);
|
||||
if (val > 0xffff)
|
||||
return (0);
|
||||
saw_xdigit = 1;
|
||||
continue;
|
||||
}
|
||||
if (ch == ':') {
|
||||
curtok = src;
|
||||
if (!saw_xdigit) {
|
||||
if (colonp)
|
||||
return (0);
|
||||
colonp = tp;
|
||||
continue;
|
||||
} else if (*src == '\0') {
|
||||
return (0);
|
||||
}
|
||||
if (tp + INT16SZ > endp)
|
||||
return (0);
|
||||
*tp++ = (u_char) (val >> 8) & 0xff;
|
||||
*tp++ = (u_char) val & 0xff;
|
||||
saw_xdigit = 0;
|
||||
val = 0;
|
||||
continue;
|
||||
}
|
||||
if (ch == '.' && ((tp + INADDRSZ) <= endp) &&
|
||||
inet_pton4(curtok, tp) > 0) {
|
||||
tp += INADDRSZ;
|
||||
saw_xdigit = 0;
|
||||
break; /* '\0' was seen by inet_pton4(). */
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
if (saw_xdigit) {
|
||||
if (tp + INT16SZ > endp)
|
||||
return (0);
|
||||
*tp++ = (u_char) (val >> 8) & 0xff;
|
||||
*tp++ = (u_char) val & 0xff;
|
||||
}
|
||||
if (colonp != NULL) {
|
||||
/*
|
||||
* Since some memmove()'s erroneously fail to handle
|
||||
* overlapping regions, we'll do the shift by hand.
|
||||
*/
|
||||
const int n = tp - colonp;
|
||||
int i;
|
||||
|
||||
for (i = 1; i <= n; i++) {
|
||||
endp[- i] = colonp[n - i];
|
||||
colonp[n - i] = 0;
|
||||
}
|
||||
tp = endp;
|
||||
}
|
||||
if (tp != endp)
|
||||
return (0);
|
||||
memcpy(dst, tmp, IN6ADDRSZ);
|
||||
return (1);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
101
external/bsd/openntpd/dist/openbsd-compat/openbsd-compat.h
vendored
Normal file
101
external/bsd/openntpd/dist/openbsd-compat/openbsd-compat.h
vendored
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
/* $Id: openbsd-compat.h,v 1.19 2006/01/19 13:11:27 dtucker Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004 Darren Tucker.
|
||||
*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include <pwd.h>
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "atomicio.h"
|
||||
#include "bsd-poll.h"
|
||||
#include "bsd-getifaddrs.h"
|
||||
#include "fake-rfc2553.h"
|
||||
|
||||
char *_compat_get_progname(char *);
|
||||
|
||||
#ifndef HAVE_ARC4RANDOM
|
||||
void seed_rng(void);
|
||||
unsigned int arc4random(void);
|
||||
void arc4random_stir(void);
|
||||
#endif /* !HAVE_ARC4RANDOM */
|
||||
|
||||
#ifndef HAVE_STRLCPY
|
||||
size_t strlcpy(char *dst, const char *src, size_t siz);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DAEMON
|
||||
int daemon(int nochdir, int noclose);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_ASPRINTF
|
||||
int asprintf(char **, const char *, ...)
|
||||
__attribute__((__format__ (printf, 2, 3)));
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_INET_PTON
|
||||
int inet_pton(int, const char *, void *);
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID)
|
||||
int seteuid(uid_t);
|
||||
#endif /* !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) */
|
||||
|
||||
#if !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID)
|
||||
int setegid(uid_t);
|
||||
#endif /* !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID) */
|
||||
|
||||
#ifndef HAVE_VSYSLOG
|
||||
void vsyslog(int, const char *, va_list);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SNPRINTF
|
||||
int snprintf(char *, size_t, const char *, ...);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_VSNPRINTF
|
||||
int vsnprintf(char *, size_t, const char *, va_list);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_CLOCK_GETRES
|
||||
# ifndef CLOCK_REALTIME
|
||||
# define CLOCK_REALTIME 1
|
||||
# endif
|
||||
int clock_getres(int, struct timespec *);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_ERRX
|
||||
__dead void errx(int, const char *, ...)
|
||||
__attribute__((__format__ (printf, 2, 3)));
|
||||
#endif
|
||||
#ifndef HAVE_VERRX
|
||||
__dead void verrx(int, const char *, va_list)
|
||||
__attribute__((__format__ (printf, 2, 0)));
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_SETRESUID)
|
||||
int setresuid(uid_t, uid_t, uid_t);
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_SETRESGID)
|
||||
int setresgid(gid_t, gid_t, gid_t);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRSIGNAL
|
||||
char *strsignal(int);
|
||||
#endif
|
||||
|
||||
int permanently_set_uid(struct passwd *);
|
||||
49
external/bsd/openntpd/dist/openbsd-compat/port-qnx.c
vendored
Normal file
49
external/bsd/openntpd/dist/openbsd-compat/port-qnx.c
vendored
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/* $Id: port-qnx.c,v 1.1 2004/12/19 23:41:28 dtucker Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004 Anthony O.Zabelin <rz1a at mail.ru>
|
||||
*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, 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(__QNX__) && !defined(HAVE_ADJTIME)
|
||||
|
||||
/*
|
||||
* Ajustment rate as a fraction of tick size. Speeds or slows clock by
|
||||
* 1/rate per clock tick.
|
||||
*/
|
||||
#define ADJUST_RATE 128
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
int
|
||||
adjtime(const struct timeval *delta, struct timeval *olddelta)
|
||||
{
|
||||
long c, d, usec;
|
||||
div_t sec_usec;
|
||||
|
||||
if (olddelta != NULL) {
|
||||
if (qnx_adj_time(0, 0, &c, &d) == 0) {
|
||||
sec_usec = div(((c / 1000L) * d), 1000000L);
|
||||
olddelta->tv_sec = sec_usec.quot;
|
||||
olddelta->tv_usec = sec_usec.rem;
|
||||
} else {
|
||||
olddelta->tv_sec = 0;
|
||||
olddelta->tv_usec = 0;
|
||||
}
|
||||
}
|
||||
usec = delta->tv_sec * 1000000L + delta->tv_usec;
|
||||
return(qnx_adj_time(usec, ADJUST_RATE, NULL, NULL));
|
||||
}
|
||||
#endif
|
||||
62
external/bsd/openntpd/dist/openbsd-compat/strlcpy.c
vendored
Normal file
62
external/bsd/openntpd/dist/openbsd-compat/strlcpy.c
vendored
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/* OPENBSD ORIGINAL: lib/libc/string/strlcpy.c */
|
||||
|
||||
/* $OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#ifndef HAVE_STRLCPY
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *rcsid = "$OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Copy src to string dst of size siz. At most siz-1 characters
|
||||
* will be copied. Always NUL terminates (unless siz == 0).
|
||||
* Returns strlen(src); if retval >= siz, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
strlcpy(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
register char *d = dst;
|
||||
register const char *s = src;
|
||||
register size_t n = siz;
|
||||
|
||||
/* Copy as many bytes as will fit */
|
||||
if (n != 0 && --n != 0) {
|
||||
do {
|
||||
if ((*d++ = *s++) == 0)
|
||||
break;
|
||||
} while (--n != 0);
|
||||
}
|
||||
|
||||
/* Not enough room in dst, add NUL and traverse rest of src */
|
||||
if (n == 0) {
|
||||
if (siz != 0)
|
||||
*d = '\0'; /* NUL-terminate dst */
|
||||
while (*s++)
|
||||
;
|
||||
}
|
||||
|
||||
return(s - src - 1); /* count does not include NUL */
|
||||
}
|
||||
|
||||
#endif /* !HAVE_STRLCPY */
|
||||
593
external/bsd/openntpd/dist/openbsd-compat/sys-queue.h
vendored
Normal file
593
external/bsd/openntpd/dist/openbsd-compat/sys-queue.h
vendored
Normal file
|
|
@ -0,0 +1,593 @@
|
|||
/* OPENBSD ORIGINAL: sys/sys/queue.h */
|
||||
|
||||
/* $OpenBSD: queue.h,v 1.25 2004/04/08 16:08:21 henning Exp $ */
|
||||
/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1991, 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
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* 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.
|
||||
*
|
||||
* @(#)queue.h 8.5 (Berkeley) 8/20/94
|
||||
*/
|
||||
|
||||
#ifndef _FAKE_QUEUE_H_
|
||||
#define _FAKE_QUEUE_H_
|
||||
|
||||
/*
|
||||
* Require for OS/X and other platforms that have old/broken/incomplete
|
||||
* <sys/queue.h>.
|
||||
*/
|
||||
#undef SLIST_HEAD
|
||||
#undef SLIST_HEAD_INITIALIZER
|
||||
#undef SLIST_ENTRY
|
||||
#undef SLIST_FOREACH_PREVPTR
|
||||
#undef SLIST_FIRST
|
||||
#undef SLIST_END
|
||||
#undef SLIST_EMPTY
|
||||
#undef SLIST_NEXT
|
||||
#undef SLIST_FOREACH
|
||||
#undef SLIST_INIT
|
||||
#undef SLIST_INSERT_AFTER
|
||||
#undef SLIST_INSERT_HEAD
|
||||
#undef SLIST_REMOVE_HEAD
|
||||
#undef SLIST_REMOVE
|
||||
#undef SLIST_REMOVE_NEXT
|
||||
#undef LIST_HEAD
|
||||
#undef LIST_HEAD_INITIALIZER
|
||||
#undef LIST_ENTRY
|
||||
#undef LIST_FIRST
|
||||
#undef LIST_END
|
||||
#undef LIST_EMPTY
|
||||
#undef LIST_NEXT
|
||||
#undef LIST_FOREACH
|
||||
#undef LIST_INIT
|
||||
#undef LIST_INSERT_AFTER
|
||||
#undef LIST_INSERT_BEFORE
|
||||
#undef LIST_INSERT_HEAD
|
||||
#undef LIST_REMOVE
|
||||
#undef LIST_REPLACE
|
||||
#undef SIMPLEQ_HEAD
|
||||
#undef SIMPLEQ_HEAD_INITIALIZER
|
||||
#undef SIMPLEQ_ENTRY
|
||||
#undef SIMPLEQ_FIRST
|
||||
#undef SIMPLEQ_END
|
||||
#undef SIMPLEQ_EMPTY
|
||||
#undef SIMPLEQ_NEXT
|
||||
#undef SIMPLEQ_FOREACH
|
||||
#undef SIMPLEQ_INIT
|
||||
#undef SIMPLEQ_INSERT_HEAD
|
||||
#undef SIMPLEQ_INSERT_TAIL
|
||||
#undef SIMPLEQ_INSERT_AFTER
|
||||
#undef SIMPLEQ_REMOVE_HEAD
|
||||
#undef TAILQ_HEAD
|
||||
#undef TAILQ_HEAD_INITIALIZER
|
||||
#undef TAILQ_ENTRY
|
||||
#undef TAILQ_FIRST
|
||||
#undef TAILQ_END
|
||||
#undef TAILQ_NEXT
|
||||
#undef TAILQ_LAST
|
||||
#undef TAILQ_PREV
|
||||
#undef TAILQ_EMPTY
|
||||
#undef TAILQ_FOREACH
|
||||
#undef TAILQ_FOREACH_REVERSE
|
||||
#undef TAILQ_INIT
|
||||
#undef TAILQ_INSERT_HEAD
|
||||
#undef TAILQ_INSERT_TAIL
|
||||
#undef TAILQ_INSERT_AFTER
|
||||
#undef TAILQ_INSERT_BEFORE
|
||||
#undef TAILQ_REMOVE
|
||||
#undef TAILQ_REPLACE
|
||||
#undef CIRCLEQ_HEAD
|
||||
#undef CIRCLEQ_HEAD_INITIALIZER
|
||||
#undef CIRCLEQ_ENTRY
|
||||
#undef CIRCLEQ_FIRST
|
||||
#undef CIRCLEQ_LAST
|
||||
#undef CIRCLEQ_END
|
||||
#undef CIRCLEQ_NEXT
|
||||
#undef CIRCLEQ_PREV
|
||||
#undef CIRCLEQ_EMPTY
|
||||
#undef CIRCLEQ_FOREACH
|
||||
#undef CIRCLEQ_FOREACH_REVERSE
|
||||
#undef CIRCLEQ_INIT
|
||||
#undef CIRCLEQ_INSERT_AFTER
|
||||
#undef CIRCLEQ_INSERT_BEFORE
|
||||
#undef CIRCLEQ_INSERT_HEAD
|
||||
#undef CIRCLEQ_INSERT_TAIL
|
||||
#undef CIRCLEQ_REMOVE
|
||||
#undef CIRCLEQ_REPLACE
|
||||
|
||||
/*
|
||||
* This file defines five types of data structures: singly-linked lists,
|
||||
* lists, simple queues, tail queues, and circular queues.
|
||||
*
|
||||
*
|
||||
* A singly-linked list is headed by a single forward pointer. The elements
|
||||
* are singly linked for minimum space and pointer manipulation overhead at
|
||||
* the expense of O(n) removal for arbitrary elements. New elements can be
|
||||
* added to the list after an existing element or at the head of the list.
|
||||
* Elements being removed from the head of the list should use the explicit
|
||||
* macro for this purpose for optimum efficiency. A singly-linked list may
|
||||
* only be traversed in the forward direction. Singly-linked lists are ideal
|
||||
* for applications with large datasets and few or no removals or for
|
||||
* implementing a LIFO queue.
|
||||
*
|
||||
* A list is headed by a single forward pointer (or an array of forward
|
||||
* pointers for a hash table header). The elements are doubly linked
|
||||
* so that an arbitrary element can be removed without a need to
|
||||
* traverse the list. New elements can be added to the list before
|
||||
* or after an existing element or at the head of the list. A list
|
||||
* may only be traversed in the forward direction.
|
||||
*
|
||||
* A simple queue is headed by a pair of pointers, one the head of the
|
||||
* list and the other to the tail of the list. The elements are singly
|
||||
* linked to save space, so elements can only be removed from the
|
||||
* head of the list. New elements can be added to the list before or after
|
||||
* an existing element, at the head of the list, or at the end of the
|
||||
* list. A simple queue may only be traversed in the forward direction.
|
||||
*
|
||||
* A tail queue is headed by a pair of pointers, one to the head of the
|
||||
* list and the other to the tail of the list. The elements are doubly
|
||||
* linked so that an arbitrary element can be removed without a need to
|
||||
* traverse the list. New elements can be added to the list before or
|
||||
* after an existing element, at the head of the list, or at the end of
|
||||
* the list. A tail queue may be traversed in either direction.
|
||||
*
|
||||
* A circle queue is headed by a pair of pointers, one to the head of the
|
||||
* list and the other to the tail of the list. The elements are doubly
|
||||
* linked so that an arbitrary element can be removed without a need to
|
||||
* traverse the list. New elements can be added to the list before or after
|
||||
* an existing element, at the head of the list, or at the end of the list.
|
||||
* A circle queue may be traversed in either direction, but has a more
|
||||
* complex end of list detection.
|
||||
*
|
||||
* For details on the use of these macros, see the queue(3) manual page.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Singly-linked List definitions.
|
||||
*/
|
||||
#define SLIST_HEAD(name, type) \
|
||||
struct name { \
|
||||
struct type *slh_first; /* first element */ \
|
||||
}
|
||||
|
||||
#define SLIST_HEAD_INITIALIZER(head) \
|
||||
{ NULL }
|
||||
|
||||
#define SLIST_ENTRY(type) \
|
||||
struct { \
|
||||
struct type *sle_next; /* next element */ \
|
||||
}
|
||||
|
||||
/*
|
||||
* Singly-linked List access methods.
|
||||
*/
|
||||
#define SLIST_FIRST(head) ((head)->slh_first)
|
||||
#define SLIST_END(head) NULL
|
||||
#define SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head))
|
||||
#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
|
||||
|
||||
#define SLIST_FOREACH(var, head, field) \
|
||||
for((var) = SLIST_FIRST(head); \
|
||||
(var) != SLIST_END(head); \
|
||||
(var) = SLIST_NEXT(var, field))
|
||||
|
||||
#define SLIST_FOREACH_PREVPTR(var, varp, head, field) \
|
||||
for ((varp) = &SLIST_FIRST((head)); \
|
||||
((var) = *(varp)) != SLIST_END(head); \
|
||||
(varp) = &SLIST_NEXT((var), field))
|
||||
|
||||
/*
|
||||
* Singly-linked List functions.
|
||||
*/
|
||||
#define SLIST_INIT(head) { \
|
||||
SLIST_FIRST(head) = SLIST_END(head); \
|
||||
}
|
||||
|
||||
#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
|
||||
(elm)->field.sle_next = (slistelm)->field.sle_next; \
|
||||
(slistelm)->field.sle_next = (elm); \
|
||||
} while (0)
|
||||
|
||||
#define SLIST_INSERT_HEAD(head, elm, field) do { \
|
||||
(elm)->field.sle_next = (head)->slh_first; \
|
||||
(head)->slh_first = (elm); \
|
||||
} while (0)
|
||||
|
||||
#define SLIST_REMOVE_NEXT(head, elm, field) do { \
|
||||
(elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \
|
||||
} while (0)
|
||||
|
||||
#define SLIST_REMOVE_HEAD(head, field) do { \
|
||||
(head)->slh_first = (head)->slh_first->field.sle_next; \
|
||||
} while (0)
|
||||
|
||||
#define SLIST_REMOVE(head, elm, type, field) do { \
|
||||
if ((head)->slh_first == (elm)) { \
|
||||
SLIST_REMOVE_HEAD((head), field); \
|
||||
} \
|
||||
else { \
|
||||
struct type *curelm = (head)->slh_first; \
|
||||
while( curelm->field.sle_next != (elm) ) \
|
||||
curelm = curelm->field.sle_next; \
|
||||
curelm->field.sle_next = \
|
||||
curelm->field.sle_next->field.sle_next; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* List definitions.
|
||||
*/
|
||||
#define LIST_HEAD(name, type) \
|
||||
struct name { \
|
||||
struct type *lh_first; /* first element */ \
|
||||
}
|
||||
|
||||
#define LIST_HEAD_INITIALIZER(head) \
|
||||
{ NULL }
|
||||
|
||||
#define LIST_ENTRY(type) \
|
||||
struct { \
|
||||
struct type *le_next; /* next element */ \
|
||||
struct type **le_prev; /* address of previous next element */ \
|
||||
}
|
||||
|
||||
/*
|
||||
* List access methods
|
||||
*/
|
||||
#define LIST_FIRST(head) ((head)->lh_first)
|
||||
#define LIST_END(head) NULL
|
||||
#define LIST_EMPTY(head) (LIST_FIRST(head) == LIST_END(head))
|
||||
#define LIST_NEXT(elm, field) ((elm)->field.le_next)
|
||||
|
||||
#define LIST_FOREACH(var, head, field) \
|
||||
for((var) = LIST_FIRST(head); \
|
||||
(var)!= LIST_END(head); \
|
||||
(var) = LIST_NEXT(var, field))
|
||||
|
||||
/*
|
||||
* List functions.
|
||||
*/
|
||||
#define LIST_INIT(head) do { \
|
||||
LIST_FIRST(head) = LIST_END(head); \
|
||||
} while (0)
|
||||
|
||||
#define LIST_INSERT_AFTER(listelm, elm, field) do { \
|
||||
if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
|
||||
(listelm)->field.le_next->field.le_prev = \
|
||||
&(elm)->field.le_next; \
|
||||
(listelm)->field.le_next = (elm); \
|
||||
(elm)->field.le_prev = &(listelm)->field.le_next; \
|
||||
} while (0)
|
||||
|
||||
#define LIST_INSERT_BEFORE(listelm, elm, field) do { \
|
||||
(elm)->field.le_prev = (listelm)->field.le_prev; \
|
||||
(elm)->field.le_next = (listelm); \
|
||||
*(listelm)->field.le_prev = (elm); \
|
||||
(listelm)->field.le_prev = &(elm)->field.le_next; \
|
||||
} while (0)
|
||||
|
||||
#define LIST_INSERT_HEAD(head, elm, field) do { \
|
||||
if (((elm)->field.le_next = (head)->lh_first) != NULL) \
|
||||
(head)->lh_first->field.le_prev = &(elm)->field.le_next;\
|
||||
(head)->lh_first = (elm); \
|
||||
(elm)->field.le_prev = &(head)->lh_first; \
|
||||
} while (0)
|
||||
|
||||
#define LIST_REMOVE(elm, field) do { \
|
||||
if ((elm)->field.le_next != NULL) \
|
||||
(elm)->field.le_next->field.le_prev = \
|
||||
(elm)->field.le_prev; \
|
||||
*(elm)->field.le_prev = (elm)->field.le_next; \
|
||||
} while (0)
|
||||
|
||||
#define LIST_REPLACE(elm, elm2, field) do { \
|
||||
if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \
|
||||
(elm2)->field.le_next->field.le_prev = \
|
||||
&(elm2)->field.le_next; \
|
||||
(elm2)->field.le_prev = (elm)->field.le_prev; \
|
||||
*(elm2)->field.le_prev = (elm2); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Simple queue definitions.
|
||||
*/
|
||||
#define SIMPLEQ_HEAD(name, type) \
|
||||
struct name { \
|
||||
struct type *sqh_first; /* first element */ \
|
||||
struct type **sqh_last; /* addr of last next element */ \
|
||||
}
|
||||
|
||||
#define SIMPLEQ_HEAD_INITIALIZER(head) \
|
||||
{ NULL, &(head).sqh_first }
|
||||
|
||||
#define SIMPLEQ_ENTRY(type) \
|
||||
struct { \
|
||||
struct type *sqe_next; /* next element */ \
|
||||
}
|
||||
|
||||
/*
|
||||
* Simple queue access methods.
|
||||
*/
|
||||
#define SIMPLEQ_FIRST(head) ((head)->sqh_first)
|
||||
#define SIMPLEQ_END(head) NULL
|
||||
#define SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head))
|
||||
#define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
|
||||
|
||||
#define SIMPLEQ_FOREACH(var, head, field) \
|
||||
for((var) = SIMPLEQ_FIRST(head); \
|
||||
(var) != SIMPLEQ_END(head); \
|
||||
(var) = SIMPLEQ_NEXT(var, field))
|
||||
|
||||
/*
|
||||
* Simple queue functions.
|
||||
*/
|
||||
#define SIMPLEQ_INIT(head) do { \
|
||||
(head)->sqh_first = NULL; \
|
||||
(head)->sqh_last = &(head)->sqh_first; \
|
||||
} while (0)
|
||||
|
||||
#define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
|
||||
if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
|
||||
(head)->sqh_last = &(elm)->field.sqe_next; \
|
||||
(head)->sqh_first = (elm); \
|
||||
} while (0)
|
||||
|
||||
#define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
|
||||
(elm)->field.sqe_next = NULL; \
|
||||
*(head)->sqh_last = (elm); \
|
||||
(head)->sqh_last = &(elm)->field.sqe_next; \
|
||||
} while (0)
|
||||
|
||||
#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
|
||||
if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
|
||||
(head)->sqh_last = &(elm)->field.sqe_next; \
|
||||
(listelm)->field.sqe_next = (elm); \
|
||||
} while (0)
|
||||
|
||||
#define SIMPLEQ_REMOVE_HEAD(head, elm, field) do { \
|
||||
if (((head)->sqh_first = (elm)->field.sqe_next) == NULL) \
|
||||
(head)->sqh_last = &(head)->sqh_first; \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Tail queue definitions.
|
||||
*/
|
||||
#define TAILQ_HEAD(name, type) \
|
||||
struct name { \
|
||||
struct type *tqh_first; /* first element */ \
|
||||
struct type **tqh_last; /* addr of last next element */ \
|
||||
}
|
||||
|
||||
#define TAILQ_HEAD_INITIALIZER(head) \
|
||||
{ NULL, &(head).tqh_first }
|
||||
|
||||
#define TAILQ_ENTRY(type) \
|
||||
struct { \
|
||||
struct type *tqe_next; /* next element */ \
|
||||
struct type **tqe_prev; /* address of previous next element */ \
|
||||
}
|
||||
|
||||
/*
|
||||
* tail queue access methods
|
||||
*/
|
||||
#define TAILQ_FIRST(head) ((head)->tqh_first)
|
||||
#define TAILQ_END(head) NULL
|
||||
#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
|
||||
#define TAILQ_LAST(head, headname) \
|
||||
(*(((struct headname *)((head)->tqh_last))->tqh_last))
|
||||
/* XXX */
|
||||
#define TAILQ_PREV(elm, headname, field) \
|
||||
(*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
|
||||
#define TAILQ_EMPTY(head) \
|
||||
(TAILQ_FIRST(head) == TAILQ_END(head))
|
||||
|
||||
#define TAILQ_FOREACH(var, head, field) \
|
||||
for((var) = TAILQ_FIRST(head); \
|
||||
(var) != TAILQ_END(head); \
|
||||
(var) = TAILQ_NEXT(var, field))
|
||||
|
||||
#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
|
||||
for((var) = TAILQ_LAST(head, headname); \
|
||||
(var) != TAILQ_END(head); \
|
||||
(var) = TAILQ_PREV(var, headname, field))
|
||||
|
||||
/*
|
||||
* Tail queue functions.
|
||||
*/
|
||||
#define TAILQ_INIT(head) do { \
|
||||
(head)->tqh_first = NULL; \
|
||||
(head)->tqh_last = &(head)->tqh_first; \
|
||||
} while (0)
|
||||
|
||||
#define TAILQ_INSERT_HEAD(head, elm, field) do { \
|
||||
if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
|
||||
(head)->tqh_first->field.tqe_prev = \
|
||||
&(elm)->field.tqe_next; \
|
||||
else \
|
||||
(head)->tqh_last = &(elm)->field.tqe_next; \
|
||||
(head)->tqh_first = (elm); \
|
||||
(elm)->field.tqe_prev = &(head)->tqh_first; \
|
||||
} while (0)
|
||||
|
||||
#define TAILQ_INSERT_TAIL(head, elm, field) do { \
|
||||
(elm)->field.tqe_next = NULL; \
|
||||
(elm)->field.tqe_prev = (head)->tqh_last; \
|
||||
*(head)->tqh_last = (elm); \
|
||||
(head)->tqh_last = &(elm)->field.tqe_next; \
|
||||
} while (0)
|
||||
|
||||
#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
|
||||
if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
|
||||
(elm)->field.tqe_next->field.tqe_prev = \
|
||||
&(elm)->field.tqe_next; \
|
||||
else \
|
||||
(head)->tqh_last = &(elm)->field.tqe_next; \
|
||||
(listelm)->field.tqe_next = (elm); \
|
||||
(elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
|
||||
} while (0)
|
||||
|
||||
#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
|
||||
(elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
|
||||
(elm)->field.tqe_next = (listelm); \
|
||||
*(listelm)->field.tqe_prev = (elm); \
|
||||
(listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
|
||||
} while (0)
|
||||
|
||||
#define TAILQ_REMOVE(head, elm, field) do { \
|
||||
if (((elm)->field.tqe_next) != NULL) \
|
||||
(elm)->field.tqe_next->field.tqe_prev = \
|
||||
(elm)->field.tqe_prev; \
|
||||
else \
|
||||
(head)->tqh_last = (elm)->field.tqe_prev; \
|
||||
*(elm)->field.tqe_prev = (elm)->field.tqe_next; \
|
||||
} while (0)
|
||||
|
||||
#define TAILQ_REPLACE(head, elm, elm2, field) do { \
|
||||
if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \
|
||||
(elm2)->field.tqe_next->field.tqe_prev = \
|
||||
&(elm2)->field.tqe_next; \
|
||||
else \
|
||||
(head)->tqh_last = &(elm2)->field.tqe_next; \
|
||||
(elm2)->field.tqe_prev = (elm)->field.tqe_prev; \
|
||||
*(elm2)->field.tqe_prev = (elm2); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Circular queue definitions.
|
||||
*/
|
||||
#define CIRCLEQ_HEAD(name, type) \
|
||||
struct name { \
|
||||
struct type *cqh_first; /* first element */ \
|
||||
struct type *cqh_last; /* last element */ \
|
||||
}
|
||||
|
||||
#define CIRCLEQ_HEAD_INITIALIZER(head) \
|
||||
{ CIRCLEQ_END(&head), CIRCLEQ_END(&head) }
|
||||
|
||||
#define CIRCLEQ_ENTRY(type) \
|
||||
struct { \
|
||||
struct type *cqe_next; /* next element */ \
|
||||
struct type *cqe_prev; /* previous element */ \
|
||||
}
|
||||
|
||||
/*
|
||||
* Circular queue access methods
|
||||
*/
|
||||
#define CIRCLEQ_FIRST(head) ((head)->cqh_first)
|
||||
#define CIRCLEQ_LAST(head) ((head)->cqh_last)
|
||||
#define CIRCLEQ_END(head) ((void *)(head))
|
||||
#define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
|
||||
#define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
|
||||
#define CIRCLEQ_EMPTY(head) \
|
||||
(CIRCLEQ_FIRST(head) == CIRCLEQ_END(head))
|
||||
|
||||
#define CIRCLEQ_FOREACH(var, head, field) \
|
||||
for((var) = CIRCLEQ_FIRST(head); \
|
||||
(var) != CIRCLEQ_END(head); \
|
||||
(var) = CIRCLEQ_NEXT(var, field))
|
||||
|
||||
#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \
|
||||
for((var) = CIRCLEQ_LAST(head); \
|
||||
(var) != CIRCLEQ_END(head); \
|
||||
(var) = CIRCLEQ_PREV(var, field))
|
||||
|
||||
/*
|
||||
* Circular queue functions.
|
||||
*/
|
||||
#define CIRCLEQ_INIT(head) do { \
|
||||
(head)->cqh_first = CIRCLEQ_END(head); \
|
||||
(head)->cqh_last = CIRCLEQ_END(head); \
|
||||
} while (0)
|
||||
|
||||
#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
|
||||
(elm)->field.cqe_next = (listelm)->field.cqe_next; \
|
||||
(elm)->field.cqe_prev = (listelm); \
|
||||
if ((listelm)->field.cqe_next == CIRCLEQ_END(head)) \
|
||||
(head)->cqh_last = (elm); \
|
||||
else \
|
||||
(listelm)->field.cqe_next->field.cqe_prev = (elm); \
|
||||
(listelm)->field.cqe_next = (elm); \
|
||||
} while (0)
|
||||
|
||||
#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
|
||||
(elm)->field.cqe_next = (listelm); \
|
||||
(elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
|
||||
if ((listelm)->field.cqe_prev == CIRCLEQ_END(head)) \
|
||||
(head)->cqh_first = (elm); \
|
||||
else \
|
||||
(listelm)->field.cqe_prev->field.cqe_next = (elm); \
|
||||
(listelm)->field.cqe_prev = (elm); \
|
||||
} while (0)
|
||||
|
||||
#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
|
||||
(elm)->field.cqe_next = (head)->cqh_first; \
|
||||
(elm)->field.cqe_prev = CIRCLEQ_END(head); \
|
||||
if ((head)->cqh_last == CIRCLEQ_END(head)) \
|
||||
(head)->cqh_last = (elm); \
|
||||
else \
|
||||
(head)->cqh_first->field.cqe_prev = (elm); \
|
||||
(head)->cqh_first = (elm); \
|
||||
} while (0)
|
||||
|
||||
#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
|
||||
(elm)->field.cqe_next = CIRCLEQ_END(head); \
|
||||
(elm)->field.cqe_prev = (head)->cqh_last; \
|
||||
if ((head)->cqh_first == CIRCLEQ_END(head)) \
|
||||
(head)->cqh_first = (elm); \
|
||||
else \
|
||||
(head)->cqh_last->field.cqe_next = (elm); \
|
||||
(head)->cqh_last = (elm); \
|
||||
} while (0)
|
||||
|
||||
#define CIRCLEQ_REMOVE(head, elm, field) do { \
|
||||
if ((elm)->field.cqe_next == CIRCLEQ_END(head)) \
|
||||
(head)->cqh_last = (elm)->field.cqe_prev; \
|
||||
else \
|
||||
(elm)->field.cqe_next->field.cqe_prev = \
|
||||
(elm)->field.cqe_prev; \
|
||||
if ((elm)->field.cqe_prev == CIRCLEQ_END(head)) \
|
||||
(head)->cqh_first = (elm)->field.cqe_next; \
|
||||
else \
|
||||
(elm)->field.cqe_prev->field.cqe_next = \
|
||||
(elm)->field.cqe_next; \
|
||||
} while (0)
|
||||
|
||||
#define CIRCLEQ_REPLACE(head, elm, elm2, field) do { \
|
||||
if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \
|
||||
CIRCLEQ_END(head)) \
|
||||
(head).cqh_last = (elm2); \
|
||||
else \
|
||||
(elm2)->field.cqe_next->field.cqe_prev = (elm2); \
|
||||
if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \
|
||||
CIRCLEQ_END(head)) \
|
||||
(head).cqh_first = (elm2); \
|
||||
else \
|
||||
(elm2)->field.cqe_prev->field.cqe_next = (elm2); \
|
||||
} while (0)
|
||||
|
||||
#endif /* !_FAKE_QUEUE_H_ */
|
||||
57
external/bsd/openntpd/dist/openbsd-compat/verrx.c
vendored
Normal file
57
external/bsd/openntpd/dist/openbsd-compat/verrx.c
vendored
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/*-
|
||||
* Copyright (c) 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
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#ifndef HAVE_VERRX
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char rcsid[] = "$OpenBSD: verrx.c,v 1.7 2004/05/18 02:05:52 jfb Exp $";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
/* #include <sys/cdefs.h>
|
||||
#include <err.h> */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
extern char *__progname; /* Program name, from crt0. */
|
||||
|
||||
__dead void
|
||||
verrx(int eval, const char *fmt, va_list ap)
|
||||
{
|
||||
(void)fprintf(stderr, "%s: ", __progname);
|
||||
if (fmt != NULL)
|
||||
(void)vfprintf(stderr, fmt, ap);
|
||||
(void)fprintf(stderr, "\n");
|
||||
exit(eval);
|
||||
}
|
||||
|
||||
/* __weak_alias(verrx, _verrx); */
|
||||
|
||||
#endif /* HAVE_VERRX */
|
||||
428
external/bsd/openntpd/dist/parse.y
vendored
Normal file
428
external/bsd/openntpd/dist/parse.y
vendored
Normal file
|
|
@ -0,0 +1,428 @@
|
|||
/* $OpenBSD: parse.y,v 1.25 2005/06/19 16:42:57 henning Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||
* Copyright (c) 2001 Markus Friedl. All rights reserved.
|
||||
* Copyright (c) 2001 Daniel Hartmeier. All rights reserved.
|
||||
* Copyright (c) 2001 Theo de Raadt. All rights reserved.
|
||||
*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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.
|
||||
*/
|
||||
|
||||
%{
|
||||
#include "includes.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "ntpd.h"
|
||||
|
||||
static struct ntpd_conf *conf;
|
||||
static FILE *fin = NULL;
|
||||
static int lineno = 1;
|
||||
static int errors = 0;
|
||||
const char *infile;
|
||||
|
||||
int yyerror(const char *, ...);
|
||||
int yyparse(void);
|
||||
int kw_cmp(const void *, const void *);
|
||||
int lookup(char *);
|
||||
int lgetc(FILE *);
|
||||
int lungetc(int);
|
||||
int findeol(void);
|
||||
int yylex(void);
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
u_int32_t number;
|
||||
char *string;
|
||||
struct ntp_addr_wrap *addr;
|
||||
} v;
|
||||
int lineno;
|
||||
} YYSTYPE;
|
||||
|
||||
%}
|
||||
|
||||
%token LISTEN ON
|
||||
%token SERVER SERVERS
|
||||
%token ERROR
|
||||
%token <v.string> STRING
|
||||
%type <v.addr> address
|
||||
%%
|
||||
|
||||
grammar : /* empty */
|
||||
| grammar '\n'
|
||||
| grammar conf_main '\n'
|
||||
| grammar error '\n' { errors++; }
|
||||
;
|
||||
|
||||
conf_main : LISTEN ON address {
|
||||
struct listen_addr *la;
|
||||
struct ntp_addr *h, *next;
|
||||
|
||||
if ((h = $3->a) == NULL &&
|
||||
(host_dns($3->name, &h) == -1 || !h)) {
|
||||
yyerror("could not resolve \"%s\"", $3->name);
|
||||
free($3->name);
|
||||
free($3);
|
||||
YYERROR;
|
||||
}
|
||||
|
||||
for (; h != NULL; h = next) {
|
||||
next = h->next;
|
||||
if (h->ss.ss_family == AF_UNSPEC) {
|
||||
conf->listen_all = 1;
|
||||
free(h);
|
||||
continue;
|
||||
}
|
||||
la = calloc(1, sizeof(struct listen_addr));
|
||||
if (la == NULL)
|
||||
fatal("listen on calloc");
|
||||
la->fd = -1;
|
||||
memcpy(&la->sa, &h->ss,
|
||||
sizeof(struct sockaddr_storage));
|
||||
TAILQ_INSERT_TAIL(&conf->listen_addrs, la,
|
||||
entry);
|
||||
free(h);
|
||||
}
|
||||
free($3->name);
|
||||
free($3);
|
||||
}
|
||||
| SERVERS address {
|
||||
struct ntp_peer *p;
|
||||
struct ntp_addr *h, *next;
|
||||
|
||||
h = $2->a;
|
||||
do {
|
||||
if (h != NULL) {
|
||||
next = h->next;
|
||||
if (h->ss.ss_family != AF_INET &&
|
||||
h->ss.ss_family != AF_INET6) {
|
||||
yyerror("IPv4 or IPv6 address "
|
||||
"or hostname expected");
|
||||
free(h);
|
||||
free($2->name);
|
||||
free($2);
|
||||
YYERROR;
|
||||
}
|
||||
h->next = NULL;
|
||||
} else
|
||||
next = NULL;
|
||||
|
||||
p = new_peer();
|
||||
p->addr = h;
|
||||
p->addr_head.a = h;
|
||||
p->addr_head.pool = 1;
|
||||
p->addr_head.name = strdup($2->name);
|
||||
if (p->addr_head.name == NULL)
|
||||
fatal(NULL);
|
||||
if (p->addr != NULL)
|
||||
p->state = STATE_DNS_DONE;
|
||||
TAILQ_INSERT_TAIL(&conf->ntp_peers, p, entry);
|
||||
|
||||
h = next;
|
||||
} while (h != NULL);
|
||||
|
||||
free($2->name);
|
||||
free($2);
|
||||
}
|
||||
| SERVER address {
|
||||
struct ntp_peer *p;
|
||||
struct ntp_addr *h, *next;
|
||||
|
||||
p = new_peer();
|
||||
for (h = $2->a; h != NULL; h = next) {
|
||||
next = h->next;
|
||||
if (h->ss.ss_family != AF_INET &&
|
||||
h->ss.ss_family != AF_INET6) {
|
||||
yyerror("IPv4 or IPv6 address "
|
||||
"or hostname expected");
|
||||
free(h);
|
||||
free(p);
|
||||
free($2->name);
|
||||
free($2);
|
||||
YYERROR;
|
||||
}
|
||||
h->next = p->addr;
|
||||
p->addr = h;
|
||||
}
|
||||
|
||||
p->addr_head.a = p->addr;
|
||||
p->addr_head.pool = 0;
|
||||
p->addr_head.name = strdup($2->name);
|
||||
if (p->addr_head.name == NULL)
|
||||
fatal(NULL);
|
||||
if (p->addr != NULL)
|
||||
p->state = STATE_DNS_DONE;
|
||||
TAILQ_INSERT_TAIL(&conf->ntp_peers, p, entry);
|
||||
free($2->name);
|
||||
free($2);
|
||||
}
|
||||
;
|
||||
|
||||
address : STRING {
|
||||
if (($$ = calloc(1, sizeof(struct ntp_addr_wrap))) ==
|
||||
NULL)
|
||||
fatal(NULL);
|
||||
if (host($1, &$$->a) == -1) {
|
||||
yyerror("could not parse address spec \"%s\"",
|
||||
$1);
|
||||
free($1);
|
||||
free($$);
|
||||
YYERROR;
|
||||
}
|
||||
$$->name = $1;
|
||||
}
|
||||
;
|
||||
|
||||
%%
|
||||
|
||||
struct keywords {
|
||||
const char *k_name;
|
||||
int k_val;
|
||||
};
|
||||
|
||||
int
|
||||
yyerror(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *nfmt;
|
||||
|
||||
errors = 1;
|
||||
va_start(ap, fmt);
|
||||
if (asprintf(&nfmt, "%s:%d: %s", infile, yylval.lineno, fmt) == -1)
|
||||
fatalx("yyerror asprintf");
|
||||
vlog(LOG_CRIT, nfmt, ap);
|
||||
va_end(ap);
|
||||
free(nfmt);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
kw_cmp(const void *k, const void *e)
|
||||
{
|
||||
return (strcmp(k, ((const struct keywords *)e)->k_name));
|
||||
}
|
||||
|
||||
int
|
||||
lookup(char *s)
|
||||
{
|
||||
/* this has to be sorted always */
|
||||
static const struct keywords keywords[] = {
|
||||
{ "listen", LISTEN},
|
||||
{ "on", ON},
|
||||
{ "server", SERVER},
|
||||
{ "servers", SERVERS}
|
||||
};
|
||||
const struct keywords *p;
|
||||
|
||||
p = bsearch(s, keywords, sizeof(keywords)/sizeof(keywords[0]),
|
||||
sizeof(keywords[0]), kw_cmp);
|
||||
|
||||
if (p)
|
||||
return (p->k_val);
|
||||
else
|
||||
return (STRING);
|
||||
}
|
||||
|
||||
#define MAXPUSHBACK 128
|
||||
|
||||
char *parsebuf;
|
||||
int parseindex;
|
||||
char pushback_buffer[MAXPUSHBACK];
|
||||
int pushback_index = 0;
|
||||
|
||||
int
|
||||
lgetc(FILE *f)
|
||||
{
|
||||
int c, next;
|
||||
|
||||
if (parsebuf) {
|
||||
/* Read character from the parsebuffer instead of input. */
|
||||
if (parseindex >= 0) {
|
||||
c = parsebuf[parseindex++];
|
||||
if (c != '\0')
|
||||
return (c);
|
||||
parsebuf = NULL;
|
||||
} else
|
||||
parseindex++;
|
||||
}
|
||||
|
||||
if (pushback_index)
|
||||
return (pushback_buffer[--pushback_index]);
|
||||
|
||||
while ((c = getc(f)) == '\\') {
|
||||
next = getc(f);
|
||||
if (next != '\n') {
|
||||
if (isspace(next))
|
||||
yyerror("whitespace after \\");
|
||||
ungetc(next, f);
|
||||
break;
|
||||
}
|
||||
yylval.lineno = lineno;
|
||||
lineno++;
|
||||
}
|
||||
if (c == '\t' || c == ' ') {
|
||||
/* Compress blanks to a single space. */
|
||||
do {
|
||||
c = getc(f);
|
||||
} while (c == '\t' || c == ' ');
|
||||
ungetc(c, f);
|
||||
c = ' ';
|
||||
}
|
||||
|
||||
return (c);
|
||||
}
|
||||
|
||||
int
|
||||
lungetc(int c)
|
||||
{
|
||||
if (c == EOF)
|
||||
return (EOF);
|
||||
if (parsebuf) {
|
||||
parseindex--;
|
||||
if (parseindex >= 0)
|
||||
return (c);
|
||||
}
|
||||
if (pushback_index < MAXPUSHBACK-1)
|
||||
return (pushback_buffer[pushback_index++] = c);
|
||||
else
|
||||
return (EOF);
|
||||
}
|
||||
|
||||
int
|
||||
findeol(void)
|
||||
{
|
||||
int c;
|
||||
|
||||
parsebuf = NULL;
|
||||
pushback_index = 0;
|
||||
|
||||
/* skip to either EOF or the first real EOL */
|
||||
while (1) {
|
||||
c = lgetc(fin);
|
||||
if (c == '\n') {
|
||||
lineno++;
|
||||
break;
|
||||
}
|
||||
if (c == EOF)
|
||||
break;
|
||||
}
|
||||
return (ERROR);
|
||||
}
|
||||
|
||||
int
|
||||
yylex(void)
|
||||
{
|
||||
char buf[8096];
|
||||
char *p;
|
||||
int endc, c;
|
||||
int token;
|
||||
|
||||
p = buf;
|
||||
while ((c = lgetc(fin)) == ' ')
|
||||
; /* nothing */
|
||||
|
||||
yylval.lineno = lineno;
|
||||
if (c == '#')
|
||||
while ((c = lgetc(fin)) != '\n' && c != EOF)
|
||||
; /* nothing */
|
||||
|
||||
switch (c) {
|
||||
case '\'':
|
||||
case '"':
|
||||
endc = c;
|
||||
while (1) {
|
||||
if ((c = lgetc(fin)) == EOF)
|
||||
return (0);
|
||||
if (c == endc) {
|
||||
*p = '\0';
|
||||
break;
|
||||
}
|
||||
if (c == '\n') {
|
||||
lineno++;
|
||||
continue;
|
||||
}
|
||||
if (p + 1 >= buf + sizeof(buf) - 1) {
|
||||
yyerror("string too long");
|
||||
return (findeol());
|
||||
}
|
||||
*p++ = (char)c;
|
||||
}
|
||||
yylval.v.string = strdup(buf);
|
||||
if (yylval.v.string == NULL)
|
||||
fatal("yylex: strdup");
|
||||
return (STRING);
|
||||
}
|
||||
|
||||
#define allowed_in_string(x) \
|
||||
(isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \
|
||||
x != '{' && x != '}' && x != '<' && x != '>' && \
|
||||
x != '!' && x != '=' && x != '/' && x != '#' && \
|
||||
x != ','))
|
||||
|
||||
if (isalnum(c) || c == ':' || c == '_' || c == '*') {
|
||||
do {
|
||||
*p++ = c;
|
||||
if ((unsigned)(p-buf) >= sizeof(buf)) {
|
||||
yyerror("string too long");
|
||||
return (findeol());
|
||||
}
|
||||
} while ((c = lgetc(fin)) != EOF && (allowed_in_string(c)));
|
||||
lungetc(c);
|
||||
*p = '\0';
|
||||
if ((token = lookup(buf)) == STRING)
|
||||
if ((yylval.v.string = strdup(buf)) == NULL)
|
||||
fatal("yylex: strdup");
|
||||
return (token);
|
||||
}
|
||||
if (c == '\n') {
|
||||
yylval.lineno = lineno;
|
||||
lineno++;
|
||||
}
|
||||
if (c == EOF)
|
||||
return (0);
|
||||
return (c);
|
||||
}
|
||||
|
||||
int
|
||||
parse_config(const char *filename, struct ntpd_conf *xconf)
|
||||
{
|
||||
conf = xconf;
|
||||
lineno = 1;
|
||||
errors = 0;
|
||||
TAILQ_INIT(&conf->listen_addrs);
|
||||
TAILQ_INIT(&conf->ntp_peers);
|
||||
|
||||
if ((fin = fopen(filename, "r")) == NULL) {
|
||||
log_warn("%s", filename);
|
||||
return (-1);
|
||||
}
|
||||
infile = filename;
|
||||
|
||||
yyparse();
|
||||
|
||||
fclose(fin);
|
||||
|
||||
return (errors ? -1 : 0);
|
||||
}
|
||||
183
external/bsd/openntpd/dist/server.c
vendored
Normal file
183
external/bsd/openntpd/dist/server.c
vendored
Normal file
|
|
@ -0,0 +1,183 @@
|
|||
/* $OpenBSD: server.c,v 1.28 2006/01/19 11:20:23 dtucker Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||
* Copyright (c) 2004 Alexander Guy <alexander@openbsd.org>
|
||||
*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, 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.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <errno.h>
|
||||
#include <netinet/in.h>
|
||||
#ifdef HAVE_IFADDRS_H
|
||||
# include <ifaddrs.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ntpd.h"
|
||||
#include "ntp.h"
|
||||
|
||||
int
|
||||
setup_listeners(struct servent *se, struct ntpd_conf *conf, u_int *cnt)
|
||||
{
|
||||
struct listen_addr *la;
|
||||
struct ifaddrs *ifa, *ifap;
|
||||
struct sockaddr *sa;
|
||||
u_int8_t *a6;
|
||||
size_t sa6len = sizeof(struct in6_addr);
|
||||
u_int new_cnt = 0;
|
||||
#ifdef IPTOS_LOWDELAY
|
||||
int tos = IPTOS_LOWDELAY;
|
||||
#endif
|
||||
|
||||
if (conf->listen_all) {
|
||||
if (getifaddrs(&ifa) == -1)
|
||||
fatal("getifaddrs");
|
||||
|
||||
for (ifap = ifa; ifap != NULL; ifap = ifap->ifa_next) {
|
||||
sa = ifap->ifa_addr;
|
||||
|
||||
if (sa == NULL ||
|
||||
(sa->sa_family != AF_INET &&
|
||||
sa->sa_family != AF_INET6))
|
||||
continue;
|
||||
if (SA_LEN(sa) == 0)
|
||||
continue;
|
||||
|
||||
if (sa->sa_family == AF_INET &&
|
||||
((struct sockaddr_in *)sa)->sin_addr.s_addr ==
|
||||
INADDR_ANY)
|
||||
continue;
|
||||
|
||||
if (sa->sa_family == AF_INET6) {
|
||||
a6 = ((struct sockaddr_in6 *)sa)->
|
||||
sin6_addr.s6_addr;
|
||||
if (memcmp(a6, &in6addr_any, sa6len) == 0)
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((la = calloc(1, sizeof(struct listen_addr))) ==
|
||||
NULL)
|
||||
fatal("setup_listeners calloc");
|
||||
|
||||
memcpy(&la->sa, sa, SA_LEN(sa));
|
||||
TAILQ_INSERT_TAIL(&conf->listen_addrs, la, entry);
|
||||
}
|
||||
|
||||
freeifaddrs(ifa);
|
||||
}
|
||||
|
||||
TAILQ_FOREACH(la, &conf->listen_addrs, entry) {
|
||||
new_cnt++;
|
||||
|
||||
switch (la->sa.ss_family) {
|
||||
case AF_INET:
|
||||
if (((struct sockaddr_in *)&la->sa)->sin_port == 0)
|
||||
((struct sockaddr_in *)&la->sa)->sin_port =
|
||||
se->s_port;
|
||||
break;
|
||||
case AF_INET6:
|
||||
if (((struct sockaddr_in6 *)&la->sa)->sin6_port == 0)
|
||||
((struct sockaddr_in6 *)&la->sa)->sin6_port =
|
||||
se->s_port;
|
||||
break;
|
||||
default:
|
||||
fatalx("king bula sez: af borked");
|
||||
}
|
||||
|
||||
log_info("listening on %s",
|
||||
log_sockaddr((struct sockaddr *)&la->sa));
|
||||
|
||||
if ((la->fd = socket(la->sa.ss_family, SOCK_DGRAM, 0)) == -1)
|
||||
fatal("socket");
|
||||
|
||||
#ifdef IPTOS_LOWDELAY
|
||||
if (la->sa.ss_family == AF_INET && setsockopt(la->fd,
|
||||
IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) == -1)
|
||||
log_warn("setsockopt IPTOS_LOWDELAY");
|
||||
#endif
|
||||
|
||||
if (bind(la->fd, (struct sockaddr *)&la->sa,
|
||||
SA_LEN((struct sockaddr *)&la->sa)) == -1)
|
||||
fatal("bind");
|
||||
}
|
||||
|
||||
*cnt = new_cnt;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
server_dispatch(int fd, struct ntpd_conf *conf)
|
||||
{
|
||||
ssize_t size;
|
||||
u_int8_t version;
|
||||
double rectime;
|
||||
struct sockaddr_storage fsa;
|
||||
socklen_t fsa_len;
|
||||
struct ntp_msg query, reply;
|
||||
char buf[NTP_MSGSIZE];
|
||||
|
||||
fsa_len = sizeof(fsa);
|
||||
if ((size = recvfrom(fd, &buf, sizeof(buf), 0,
|
||||
(struct sockaddr *)&fsa, &fsa_len)) == -1) {
|
||||
if (errno == EHOSTUNREACH || errno == EHOSTDOWN ||
|
||||
errno == ENETUNREACH || errno == ENETDOWN) {
|
||||
log_warn("recvfrom %s",
|
||||
log_sockaddr((struct sockaddr *)&fsa));
|
||||
return (0);
|
||||
} else
|
||||
fatal("recvfrom");
|
||||
}
|
||||
|
||||
rectime = gettime();
|
||||
|
||||
if (ntp_getmsg((struct sockaddr *)&fsa, buf, size, &query) == -1)
|
||||
return (0);
|
||||
|
||||
version = (query.status & VERSIONMASK) >> 3;
|
||||
|
||||
bzero(&reply, sizeof(reply));
|
||||
if (conf->status.synced)
|
||||
reply.status = conf->status.leap;
|
||||
else
|
||||
reply.status = LI_ALARM;
|
||||
reply.status |= (query.status & VERSIONMASK);
|
||||
if ((query.status & MODEMASK) == MODE_CLIENT)
|
||||
reply.status |= MODE_SERVER;
|
||||
else
|
||||
reply.status |= MODE_SYM_PAS;
|
||||
|
||||
reply.stratum = conf->status.stratum;
|
||||
reply.ppoll = query.ppoll;
|
||||
reply.precision = conf->status.precision;
|
||||
reply.rectime = d_to_lfp(rectime);
|
||||
reply.reftime = d_to_lfp(conf->status.reftime);
|
||||
reply.xmttime = d_to_lfp(gettime());
|
||||
reply.orgtime = query.xmttime;
|
||||
reply.rootdelay = d_to_sfp(conf->status.rootdelay);
|
||||
|
||||
if (version > 3)
|
||||
reply.refid = conf->status.refid4;
|
||||
else
|
||||
reply.refid = conf->status.refid;
|
||||
|
||||
ntp_sendmsg(fd, (struct sockaddr *)&fsa, &reply, size, 0);
|
||||
return (0);
|
||||
}
|
||||
89
external/bsd/openntpd/dist/util.c
vendored
Normal file
89
external/bsd/openntpd/dist/util.c
vendored
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
/* $OpenBSD: util.c,v 1.10 2004/12/08 15:47:38 mickey Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004 Alexander Guy <alexander.guy@andern.org>
|
||||
*
|
||||
* 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, 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.
|
||||
*/
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "ntpd.h"
|
||||
|
||||
double
|
||||
gettime(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
|
||||
if (gettimeofday(&tv, NULL) == -1)
|
||||
fatal("gettimeofday");
|
||||
|
||||
return (tv.tv_sec + JAN_1970 + 1.0e-6 * tv.tv_usec);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
d_to_tv(double d, struct timeval *tv)
|
||||
{
|
||||
tv->tv_sec = (long)d;
|
||||
tv->tv_usec = (d - tv->tv_sec) * 1000000;
|
||||
}
|
||||
|
||||
double
|
||||
lfp_to_d(struct l_fixedpt lfp)
|
||||
{
|
||||
double ret;
|
||||
|
||||
lfp.int_partl = ntohl(lfp.int_partl);
|
||||
lfp.fractionl = ntohl(lfp.fractionl);
|
||||
|
||||
ret = (double)(lfp.int_partl) + ((double)lfp.fractionl / UINT_MAX);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
struct l_fixedpt
|
||||
d_to_lfp(double d)
|
||||
{
|
||||
struct l_fixedpt lfp;
|
||||
|
||||
lfp.int_partl = htonl((u_int32_t)d);
|
||||
lfp.fractionl = htonl((u_int32_t)((d - (u_int32_t)d) * UINT_MAX));
|
||||
|
||||
return (lfp);
|
||||
}
|
||||
|
||||
double
|
||||
sfp_to_d(struct s_fixedpt sfp)
|
||||
{
|
||||
double ret;
|
||||
|
||||
sfp.int_parts = ntohs(sfp.int_parts);
|
||||
sfp.fractions = ntohs(sfp.fractions);
|
||||
|
||||
ret = (double)(sfp.int_parts) + ((double)sfp.fractions / USHRT_MAX);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
struct s_fixedpt
|
||||
d_to_sfp(double d)
|
||||
{
|
||||
struct s_fixedpt sfp;
|
||||
|
||||
sfp.int_parts = htons((u_int16_t)d);
|
||||
sfp.fractions = htons((u_int16_t)((d - (u_int16_t)d) * USHRT_MAX));
|
||||
|
||||
return (sfp);
|
||||
}
|
||||
3
external/bsd/openntpd/dist/version.h
vendored
Normal file
3
external/bsd/openntpd/dist/version.h
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
/* $Id: version.h,v 1.6 2006/05/14 05:27:48 dtucker Exp $ */
|
||||
|
||||
#define OPENNTPD_VERSION "3.9"
|
||||
878
external/bsd/openntpd/dist/y.tab.c
vendored
Normal file
878
external/bsd/openntpd/dist/y.tab.c
vendored
Normal file
|
|
@ -0,0 +1,878 @@
|
|||
#ifndef lint
|
||||
/*static char yysccsid[] = "from: @(#)yaccpar 1.9 (Berkeley) 02/21/93";*/
|
||||
static char yyrcsid[]
|
||||
#if __GNUC__ >= 2
|
||||
__attribute__ ((unused))
|
||||
#endif /* __GNUC__ >= 2 */
|
||||
= "$OpenBSD: skeleton.c,v 1.26 2006/04/20 16:51:32 deraadt Exp $";
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#define YYBYACC 1
|
||||
#define YYMAJOR 1
|
||||
#define YYMINOR 9
|
||||
#define YYLEX yylex()
|
||||
#define YYEMPTY -1
|
||||
#define yyclearin (yychar=(YYEMPTY))
|
||||
#define yyerrok (yyerrflag=0)
|
||||
#define YYRECOVERING() (yyerrflag!=0)
|
||||
#define YYPREFIX "yy"
|
||||
#line 23 "parse.y"
|
||||
#include "includes.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "ntpd.h"
|
||||
|
||||
static struct ntpd_conf *conf;
|
||||
static FILE *fin = NULL;
|
||||
static int lineno = 1;
|
||||
static int errors = 0;
|
||||
const char *infile;
|
||||
|
||||
int yyerror(const char *, ...);
|
||||
int yyparse(void);
|
||||
int kw_cmp(const void *, const void *);
|
||||
int lookup(char *);
|
||||
int lgetc(FILE *);
|
||||
int lungetc(int);
|
||||
int findeol(void);
|
||||
int yylex(void);
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
u_int32_t number;
|
||||
char *string;
|
||||
struct ntp_addr_wrap *addr;
|
||||
} v;
|
||||
int lineno;
|
||||
} YYSTYPE;
|
||||
|
||||
#line 62 "y.tab.c"
|
||||
#define LISTEN 257
|
||||
#define ON 258
|
||||
#define SERVER 259
|
||||
#define SERVERS 260
|
||||
#define ERROR 261
|
||||
#define STRING 262
|
||||
#define YYERRCODE 256
|
||||
#if defined(__cplusplus) || defined(__STDC__)
|
||||
const short yylhs[] =
|
||||
#else
|
||||
short yylhs[] =
|
||||
#endif
|
||||
{ -1,
|
||||
0, 0, 0, 0, 2, 2, 2, 1,
|
||||
};
|
||||
#if defined(__cplusplus) || defined(__STDC__)
|
||||
const short yylen[] =
|
||||
#else
|
||||
short yylen[] =
|
||||
#endif
|
||||
{ 2,
|
||||
0, 2, 3, 3, 3, 2, 2, 1,
|
||||
};
|
||||
#if defined(__cplusplus) || defined(__STDC__)
|
||||
const short yydefred[] =
|
||||
#else
|
||||
short yydefred[] =
|
||||
#endif
|
||||
{ 1,
|
||||
0, 0, 0, 0, 0, 2, 0, 4, 0, 8,
|
||||
7, 6, 3, 5,
|
||||
};
|
||||
#if defined(__cplusplus) || defined(__STDC__)
|
||||
const short yydgoto[] =
|
||||
#else
|
||||
short yydgoto[] =
|
||||
#endif
|
||||
{ 1,
|
||||
11, 7,
|
||||
};
|
||||
#if defined(__cplusplus) || defined(__STDC__)
|
||||
const short yysindex[] =
|
||||
#else
|
||||
short yysindex[] =
|
||||
#endif
|
||||
{ 0,
|
||||
-10, -8, -255, -258, -258, 0, -3, 0, -258, 0,
|
||||
0, 0, 0, 0,};
|
||||
#if defined(__cplusplus) || defined(__STDC__)
|
||||
const short yyrindex[] =
|
||||
#else
|
||||
short yyrindex[] =
|
||||
#endif
|
||||
{ 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0,};
|
||||
#if defined(__cplusplus) || defined(__STDC__)
|
||||
const short yygindex[] =
|
||||
#else
|
||||
short yygindex[] =
|
||||
#endif
|
||||
{ 0,
|
||||
-4, 0,
|
||||
};
|
||||
#define YYTABLESIZE 250
|
||||
#if defined(__cplusplus) || defined(__STDC__)
|
||||
const short yytable[] =
|
||||
#else
|
||||
short yytable[] =
|
||||
#endif
|
||||
{ 6,
|
||||
12, 8, 9, 10, 14, 0, 13, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 2, 3, 0, 4, 5,
|
||||
};
|
||||
#if defined(__cplusplus) || defined(__STDC__)
|
||||
const short yycheck[] =
|
||||
#else
|
||||
short yycheck[] =
|
||||
#endif
|
||||
{ 10,
|
||||
5, 10, 258, 262, 9, -1, 10, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, 256, 257, -1, 259, 260,
|
||||
};
|
||||
#define YYFINAL 1
|
||||
#ifndef YYDEBUG
|
||||
#define YYDEBUG 0
|
||||
#endif
|
||||
#define YYMAXTOKEN 262
|
||||
#if YYDEBUG
|
||||
#if defined(__cplusplus) || defined(__STDC__)
|
||||
const char * const yyname[] =
|
||||
#else
|
||||
char *yyname[] =
|
||||
#endif
|
||||
{
|
||||
"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"LISTEN","ON","SERVER",
|
||||
"SERVERS","ERROR","STRING",
|
||||
};
|
||||
#if defined(__cplusplus) || defined(__STDC__)
|
||||
const char * const yyrule[] =
|
||||
#else
|
||||
char *yyrule[] =
|
||||
#endif
|
||||
{"$accept : grammar",
|
||||
"grammar :",
|
||||
"grammar : grammar '\\n'",
|
||||
"grammar : grammar conf_main '\\n'",
|
||||
"grammar : grammar error '\\n'",
|
||||
"conf_main : LISTEN ON address",
|
||||
"conf_main : SERVERS address",
|
||||
"conf_main : SERVER address",
|
||||
"address : STRING",
|
||||
};
|
||||
#endif
|
||||
#ifdef YYSTACKSIZE
|
||||
#undef YYMAXDEPTH
|
||||
#define YYMAXDEPTH YYSTACKSIZE
|
||||
#else
|
||||
#ifdef YYMAXDEPTH
|
||||
#define YYSTACKSIZE YYMAXDEPTH
|
||||
#else
|
||||
#define YYSTACKSIZE 10000
|
||||
#define YYMAXDEPTH 10000
|
||||
#endif
|
||||
#endif
|
||||
#define YYINITSTACKSIZE 200
|
||||
/* LINTUSED */
|
||||
int yydebug;
|
||||
int yynerrs;
|
||||
int yyerrflag;
|
||||
int yychar;
|
||||
short *yyssp;
|
||||
YYSTYPE *yyvsp;
|
||||
YYSTYPE yyval;
|
||||
YYSTYPE yylval;
|
||||
short *yyss;
|
||||
short *yysslim;
|
||||
YYSTYPE *yyvs;
|
||||
int yystacksize;
|
||||
#line 199 "parse.y"
|
||||
|
||||
struct keywords {
|
||||
const char *k_name;
|
||||
int k_val;
|
||||
};
|
||||
|
||||
int
|
||||
yyerror(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *nfmt;
|
||||
|
||||
errors = 1;
|
||||
va_start(ap, fmt);
|
||||
if (asprintf(&nfmt, "%s:%d: %s", infile, yylval.lineno, fmt) == -1)
|
||||
fatalx("yyerror asprintf");
|
||||
vlog(LOG_CRIT, nfmt, ap);
|
||||
va_end(ap);
|
||||
free(nfmt);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
kw_cmp(const void *k, const void *e)
|
||||
{
|
||||
return (strcmp(k, ((const struct keywords *)e)->k_name));
|
||||
}
|
||||
|
||||
int
|
||||
lookup(char *s)
|
||||
{
|
||||
/* this has to be sorted always */
|
||||
static const struct keywords keywords[] = {
|
||||
{ "listen", LISTEN},
|
||||
{ "on", ON},
|
||||
{ "server", SERVER},
|
||||
{ "servers", SERVERS}
|
||||
};
|
||||
const struct keywords *p;
|
||||
|
||||
p = bsearch(s, keywords, sizeof(keywords)/sizeof(keywords[0]),
|
||||
sizeof(keywords[0]), kw_cmp);
|
||||
|
||||
if (p)
|
||||
return (p->k_val);
|
||||
else
|
||||
return (STRING);
|
||||
}
|
||||
|
||||
#define MAXPUSHBACK 128
|
||||
|
||||
char *parsebuf;
|
||||
int parseindex;
|
||||
char pushback_buffer[MAXPUSHBACK];
|
||||
int pushback_index = 0;
|
||||
|
||||
int
|
||||
lgetc(FILE *f)
|
||||
{
|
||||
int c, next;
|
||||
|
||||
if (parsebuf) {
|
||||
/* Read character from the parsebuffer instead of input. */
|
||||
if (parseindex >= 0) {
|
||||
c = parsebuf[parseindex++];
|
||||
if (c != '\0')
|
||||
return (c);
|
||||
parsebuf = NULL;
|
||||
} else
|
||||
parseindex++;
|
||||
}
|
||||
|
||||
if (pushback_index)
|
||||
return (pushback_buffer[--pushback_index]);
|
||||
|
||||
while ((c = getc(f)) == '\\') {
|
||||
next = getc(f);
|
||||
if (next != '\n') {
|
||||
if (isspace(next))
|
||||
yyerror("whitespace after \\");
|
||||
ungetc(next, f);
|
||||
break;
|
||||
}
|
||||
yylval.lineno = lineno;
|
||||
lineno++;
|
||||
}
|
||||
if (c == '\t' || c == ' ') {
|
||||
/* Compress blanks to a single space. */
|
||||
do {
|
||||
c = getc(f);
|
||||
} while (c == '\t' || c == ' ');
|
||||
ungetc(c, f);
|
||||
c = ' ';
|
||||
}
|
||||
|
||||
return (c);
|
||||
}
|
||||
|
||||
int
|
||||
lungetc(int c)
|
||||
{
|
||||
if (c == EOF)
|
||||
return (EOF);
|
||||
if (parsebuf) {
|
||||
parseindex--;
|
||||
if (parseindex >= 0)
|
||||
return (c);
|
||||
}
|
||||
if (pushback_index < MAXPUSHBACK-1)
|
||||
return (pushback_buffer[pushback_index++] = c);
|
||||
else
|
||||
return (EOF);
|
||||
}
|
||||
|
||||
int
|
||||
findeol(void)
|
||||
{
|
||||
int c;
|
||||
|
||||
parsebuf = NULL;
|
||||
pushback_index = 0;
|
||||
|
||||
/* skip to either EOF or the first real EOL */
|
||||
while (1) {
|
||||
c = lgetc(fin);
|
||||
if (c == '\n') {
|
||||
lineno++;
|
||||
break;
|
||||
}
|
||||
if (c == EOF)
|
||||
break;
|
||||
}
|
||||
return (ERROR);
|
||||
}
|
||||
|
||||
int
|
||||
yylex(void)
|
||||
{
|
||||
char buf[8096];
|
||||
char *p;
|
||||
int endc, c;
|
||||
int token;
|
||||
|
||||
p = buf;
|
||||
while ((c = lgetc(fin)) == ' ')
|
||||
; /* nothing */
|
||||
|
||||
yylval.lineno = lineno;
|
||||
if (c == '#')
|
||||
while ((c = lgetc(fin)) != '\n' && c != EOF)
|
||||
; /* nothing */
|
||||
|
||||
switch (c) {
|
||||
case '\'':
|
||||
case '"':
|
||||
endc = c;
|
||||
while (1) {
|
||||
if ((c = lgetc(fin)) == EOF)
|
||||
return (0);
|
||||
if (c == endc) {
|
||||
*p = '\0';
|
||||
break;
|
||||
}
|
||||
if (c == '\n') {
|
||||
lineno++;
|
||||
continue;
|
||||
}
|
||||
if (p + 1 >= buf + sizeof(buf) - 1) {
|
||||
yyerror("string too long");
|
||||
return (findeol());
|
||||
}
|
||||
*p++ = (char)c;
|
||||
}
|
||||
yylval.v.string = strdup(buf);
|
||||
if (yylval.v.string == NULL)
|
||||
fatal("yylex: strdup");
|
||||
return (STRING);
|
||||
}
|
||||
|
||||
#define allowed_in_string(x) \
|
||||
(isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \
|
||||
x != '{' && x != '}' && x != '<' && x != '>' && \
|
||||
x != '!' && x != '=' && x != '/' && x != '#' && \
|
||||
x != ','))
|
||||
|
||||
if (isalnum(c) || c == ':' || c == '_' || c == '*') {
|
||||
do {
|
||||
*p++ = c;
|
||||
if ((unsigned)(p-buf) >= sizeof(buf)) {
|
||||
yyerror("string too long");
|
||||
return (findeol());
|
||||
}
|
||||
} while ((c = lgetc(fin)) != EOF && (allowed_in_string(c)));
|
||||
lungetc(c);
|
||||
*p = '\0';
|
||||
if ((token = lookup(buf)) == STRING)
|
||||
if ((yylval.v.string = strdup(buf)) == NULL)
|
||||
fatal("yylex: strdup");
|
||||
return (token);
|
||||
}
|
||||
if (c == '\n') {
|
||||
yylval.lineno = lineno;
|
||||
lineno++;
|
||||
}
|
||||
if (c == EOF)
|
||||
return (0);
|
||||
return (c);
|
||||
}
|
||||
|
||||
int
|
||||
parse_config(const char *filename, struct ntpd_conf *xconf)
|
||||
{
|
||||
conf = xconf;
|
||||
lineno = 1;
|
||||
errors = 0;
|
||||
TAILQ_INIT(&conf->listen_addrs);
|
||||
TAILQ_INIT(&conf->ntp_peers);
|
||||
|
||||
if ((fin = fopen(filename, "r")) == NULL) {
|
||||
log_warn("%s", filename);
|
||||
return (-1);
|
||||
}
|
||||
infile = filename;
|
||||
|
||||
yyparse();
|
||||
|
||||
fclose(fin);
|
||||
|
||||
return (errors ? -1 : 0);
|
||||
}
|
||||
#line 433 "y.tab.c"
|
||||
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
|
||||
#if defined(__cplusplus) || defined(__STDC__)
|
||||
static int yygrowstack(void)
|
||||
#else
|
||||
static int yygrowstack()
|
||||
#endif
|
||||
{
|
||||
int newsize, i;
|
||||
short *newss;
|
||||
YYSTYPE *newvs;
|
||||
|
||||
if ((newsize = yystacksize) == 0)
|
||||
newsize = YYINITSTACKSIZE;
|
||||
else if (newsize >= YYMAXDEPTH)
|
||||
return -1;
|
||||
else if ((newsize *= 2) > YYMAXDEPTH)
|
||||
newsize = YYMAXDEPTH;
|
||||
i = yyssp - yyss;
|
||||
newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :
|
||||
(short *)malloc(newsize * sizeof *newss);
|
||||
if (newss == NULL)
|
||||
goto bail;
|
||||
yyss = newss;
|
||||
yyssp = newss + i;
|
||||
newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :
|
||||
(YYSTYPE *)malloc(newsize * sizeof *newvs);
|
||||
if (newvs == NULL)
|
||||
goto bail;
|
||||
yyvs = newvs;
|
||||
yyvsp = newvs + i;
|
||||
yystacksize = newsize;
|
||||
yysslim = yyss + newsize - 1;
|
||||
return 0;
|
||||
bail:
|
||||
if (yyss)
|
||||
free(yyss);
|
||||
if (yyvs)
|
||||
free(yyvs);
|
||||
yyss = yyssp = NULL;
|
||||
yyvs = yyvsp = NULL;
|
||||
yystacksize = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#define YYABORT goto yyabort
|
||||
#define YYREJECT goto yyabort
|
||||
#define YYACCEPT goto yyaccept
|
||||
#define YYERROR goto yyerrlab
|
||||
int
|
||||
#if defined(__cplusplus) || defined(__STDC__)
|
||||
yyparse(void)
|
||||
#else
|
||||
yyparse()
|
||||
#endif
|
||||
{
|
||||
int yym, yyn, yystate;
|
||||
#if YYDEBUG
|
||||
#if defined(__cplusplus) || defined(__STDC__)
|
||||
const char *yys;
|
||||
#else /* !(defined(__cplusplus) || defined(__STDC__)) */
|
||||
char *yys;
|
||||
#endif /* !(defined(__cplusplus) || defined(__STDC__)) */
|
||||
|
||||
if ((yys = getenv("YYDEBUG")))
|
||||
{
|
||||
yyn = *yys;
|
||||
if (yyn >= '0' && yyn <= '9')
|
||||
yydebug = yyn - '0';
|
||||
}
|
||||
#endif /* YYDEBUG */
|
||||
|
||||
yynerrs = 0;
|
||||
yyerrflag = 0;
|
||||
yychar = (-1);
|
||||
|
||||
if (yyss == NULL && yygrowstack()) goto yyoverflow;
|
||||
yyssp = yyss;
|
||||
yyvsp = yyvs;
|
||||
*yyssp = yystate = 0;
|
||||
|
||||
yyloop:
|
||||
if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
|
||||
if (yychar < 0)
|
||||
{
|
||||
if ((yychar = yylex()) < 0) yychar = 0;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, reading %d (%s)\n",
|
||||
YYPREFIX, yystate, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, shifting to state %d\n",
|
||||
YYPREFIX, yystate, yytable[yyn]);
|
||||
#endif
|
||||
if (yyssp >= yysslim && yygrowstack())
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
*++yyssp = yystate = yytable[yyn];
|
||||
*++yyvsp = yylval;
|
||||
yychar = (-1);
|
||||
if (yyerrflag > 0) --yyerrflag;
|
||||
goto yyloop;
|
||||
}
|
||||
if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
|
||||
{
|
||||
yyn = yytable[yyn];
|
||||
goto yyreduce;
|
||||
}
|
||||
if (yyerrflag) goto yyinrecovery;
|
||||
#if defined(lint) || defined(__GNUC__)
|
||||
goto yynewerror;
|
||||
#endif
|
||||
yynewerror:
|
||||
yyerror("syntax error");
|
||||
#if defined(lint) || defined(__GNUC__)
|
||||
goto yyerrlab;
|
||||
#endif
|
||||
yyerrlab:
|
||||
++yynerrs;
|
||||
yyinrecovery:
|
||||
if (yyerrflag < 3)
|
||||
{
|
||||
yyerrflag = 3;
|
||||
for (;;)
|
||||
{
|
||||
if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, error recovery shifting\
|
||||
to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
|
||||
#endif
|
||||
if (yyssp >= yysslim && yygrowstack())
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
*++yyssp = yystate = yytable[yyn];
|
||||
*++yyvsp = yylval;
|
||||
goto yyloop;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: error recovery discarding state %d\n",
|
||||
YYPREFIX, *yyssp);
|
||||
#endif
|
||||
if (yyssp <= yyss) goto yyabort;
|
||||
--yyssp;
|
||||
--yyvsp;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (yychar == 0) goto yyabort;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
|
||||
YYPREFIX, yystate, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
yychar = (-1);
|
||||
goto yyloop;
|
||||
}
|
||||
yyreduce:
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, reducing by rule %d (%s)\n",
|
||||
YYPREFIX, yystate, yyn, yyrule[yyn]);
|
||||
#endif
|
||||
yym = yylen[yyn];
|
||||
yyval = yyvsp[1-yym];
|
||||
switch (yyn)
|
||||
{
|
||||
case 4:
|
||||
#line 76 "parse.y"
|
||||
{ errors++; }
|
||||
break;
|
||||
case 5:
|
||||
#line 79 "parse.y"
|
||||
{
|
||||
struct listen_addr *la;
|
||||
struct ntp_addr *h, *next;
|
||||
|
||||
if ((h = yyvsp[0].v.addr->a) == NULL &&
|
||||
(host_dns(yyvsp[0].v.addr->name, &h) == -1 || !h)) {
|
||||
yyerror("could not resolve \"%s\"", yyvsp[0].v.addr->name);
|
||||
free(yyvsp[0].v.addr->name);
|
||||
free(yyvsp[0].v.addr);
|
||||
YYERROR;
|
||||
}
|
||||
|
||||
for (; h != NULL; h = next) {
|
||||
next = h->next;
|
||||
if (h->ss.ss_family == AF_UNSPEC) {
|
||||
conf->listen_all = 1;
|
||||
free(h);
|
||||
continue;
|
||||
}
|
||||
la = calloc(1, sizeof(struct listen_addr));
|
||||
if (la == NULL)
|
||||
fatal("listen on calloc");
|
||||
la->fd = -1;
|
||||
memcpy(&la->sa, &h->ss,
|
||||
sizeof(struct sockaddr_storage));
|
||||
TAILQ_INSERT_TAIL(&conf->listen_addrs, la,
|
||||
entry);
|
||||
free(h);
|
||||
}
|
||||
free(yyvsp[0].v.addr->name);
|
||||
free(yyvsp[0].v.addr);
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
#line 111 "parse.y"
|
||||
{
|
||||
struct ntp_peer *p;
|
||||
struct ntp_addr *h, *next;
|
||||
|
||||
h = yyvsp[0].v.addr->a;
|
||||
do {
|
||||
if (h != NULL) {
|
||||
next = h->next;
|
||||
if (h->ss.ss_family != AF_INET &&
|
||||
h->ss.ss_family != AF_INET6) {
|
||||
yyerror("IPv4 or IPv6 address "
|
||||
"or hostname expected");
|
||||
free(h);
|
||||
free(yyvsp[0].v.addr->name);
|
||||
free(yyvsp[0].v.addr);
|
||||
YYERROR;
|
||||
}
|
||||
h->next = NULL;
|
||||
} else
|
||||
next = NULL;
|
||||
|
||||
p = new_peer();
|
||||
p->addr = h;
|
||||
p->addr_head.a = h;
|
||||
p->addr_head.pool = 1;
|
||||
p->addr_head.name = strdup(yyvsp[0].v.addr->name);
|
||||
if (p->addr_head.name == NULL)
|
||||
fatal(NULL);
|
||||
if (p->addr != NULL)
|
||||
p->state = STATE_DNS_DONE;
|
||||
TAILQ_INSERT_TAIL(&conf->ntp_peers, p, entry);
|
||||
|
||||
h = next;
|
||||
} while (h != NULL);
|
||||
|
||||
free(yyvsp[0].v.addr->name);
|
||||
free(yyvsp[0].v.addr);
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
#line 149 "parse.y"
|
||||
{
|
||||
struct ntp_peer *p;
|
||||
struct ntp_addr *h, *next;
|
||||
|
||||
p = new_peer();
|
||||
for (h = yyvsp[0].v.addr->a; h != NULL; h = next) {
|
||||
next = h->next;
|
||||
if (h->ss.ss_family != AF_INET &&
|
||||
h->ss.ss_family != AF_INET6) {
|
||||
yyerror("IPv4 or IPv6 address "
|
||||
"or hostname expected");
|
||||
free(h);
|
||||
free(p);
|
||||
free(yyvsp[0].v.addr->name);
|
||||
free(yyvsp[0].v.addr);
|
||||
YYERROR;
|
||||
}
|
||||
h->next = p->addr;
|
||||
p->addr = h;
|
||||
}
|
||||
|
||||
p->addr_head.a = p->addr;
|
||||
p->addr_head.pool = 0;
|
||||
p->addr_head.name = strdup(yyvsp[0].v.addr->name);
|
||||
if (p->addr_head.name == NULL)
|
||||
fatal(NULL);
|
||||
if (p->addr != NULL)
|
||||
p->state = STATE_DNS_DONE;
|
||||
TAILQ_INSERT_TAIL(&conf->ntp_peers, p, entry);
|
||||
free(yyvsp[0].v.addr->name);
|
||||
free(yyvsp[0].v.addr);
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
#line 183 "parse.y"
|
||||
{
|
||||
if ((yyval.v.addr = calloc(1, sizeof(struct ntp_addr_wrap))) ==
|
||||
NULL)
|
||||
fatal(NULL);
|
||||
if (host(yyvsp[0].v.string, &yyval.v.addr->a) == -1) {
|
||||
yyerror("could not parse address spec \"%s\"",
|
||||
yyvsp[0].v.string);
|
||||
free(yyvsp[0].v.string);
|
||||
free(yyval.v.addr);
|
||||
YYERROR;
|
||||
}
|
||||
yyval.v.addr->name = yyvsp[0].v.string;
|
||||
}
|
||||
break;
|
||||
#line 757 "y.tab.c"
|
||||
}
|
||||
yyssp -= yym;
|
||||
yystate = *yyssp;
|
||||
yyvsp -= yym;
|
||||
yym = yylhs[yyn];
|
||||
if (yystate == 0 && yym == 0)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: after reduction, shifting from state 0 to\
|
||||
state %d\n", YYPREFIX, YYFINAL);
|
||||
#endif
|
||||
yystate = YYFINAL;
|
||||
*++yyssp = YYFINAL;
|
||||
*++yyvsp = yyval;
|
||||
if (yychar < 0)
|
||||
{
|
||||
if ((yychar = yylex()) < 0) yychar = 0;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, reading %d (%s)\n",
|
||||
YYPREFIX, YYFINAL, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (yychar == 0) goto yyaccept;
|
||||
goto yyloop;
|
||||
}
|
||||
if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
|
||||
yystate = yytable[yyn];
|
||||
else
|
||||
yystate = yydgoto[yym];
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: after reduction, shifting from state %d \
|
||||
to state %d\n", YYPREFIX, *yyssp, yystate);
|
||||
#endif
|
||||
if (yyssp >= yysslim && yygrowstack())
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
*++yyssp = yystate;
|
||||
*++yyvsp = yyval;
|
||||
goto yyloop;
|
||||
yyoverflow:
|
||||
yyerror("yacc stack overflow");
|
||||
yyabort:
|
||||
if (yyss)
|
||||
free(yyss);
|
||||
if (yyvs)
|
||||
free(yyvs);
|
||||
yyss = yyssp = NULL;
|
||||
yyvs = yyvsp = NULL;
|
||||
yystacksize = 0;
|
||||
return (1);
|
||||
yyaccept:
|
||||
if (yyss)
|
||||
free(yyss);
|
||||
if (yyvs)
|
||||
free(yyvs);
|
||||
yyss = yyssp = NULL;
|
||||
yyvs = yyvsp = NULL;
|
||||
yystacksize = 0;
|
||||
return (0);
|
||||
}
|
||||
2
external/bsd/openntpd/lib/Makefile
vendored
Normal file
2
external/bsd/openntpd/lib/Makefile
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
SUBDIR+= openbsd-compat
|
||||
.include <bsd.subdir.mk>
|
||||
1
external/bsd/openntpd/lib/Makefile.inc
vendored
Normal file
1
external/bsd/openntpd/lib/Makefile.inc
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
.include "../Makefile.inc"
|
||||
15
external/bsd/openntpd/lib/openbsd-compat/Makefile
vendored
Normal file
15
external/bsd/openntpd/lib/openbsd-compat/Makefile
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
LIBISPRIVATE=yes
|
||||
LIB= openbsd-compat
|
||||
|
||||
.include <bsd.own.mk>
|
||||
.include "${.CURDIR}/../Makefile.inc"
|
||||
|
||||
DIST= ${NETBSDSRCDIR}/external/bsd/openntpd/dist/openbsd-compat
|
||||
|
||||
.PATH.c: ${DIST}
|
||||
SRCS= asprintf.c atomicio.c bsd-arc4random.c bsd-getifaddrs.c bsd-misc.c \
|
||||
bsd-poll.c bsd-setresgid.c bsd-setresuid.c bsd-snprintf.c \
|
||||
daemon.c errx.c fake-rfc2553.c inet_pton.c port-qnx.c strlcpy.c \
|
||||
verrx.c
|
||||
CPPFLAGS+= -I${DIST} -I${DIST}/..
|
||||
.include <bsd.lib.mk>
|
||||
2
external/bsd/openntpd/sbin/Makefile
vendored
Normal file
2
external/bsd/openntpd/sbin/Makefile
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
SUBDIR= openntpd
|
||||
.include <bsd.subdir.mk>
|
||||
3
external/bsd/openntpd/sbin/Makefile.inc
vendored
Normal file
3
external/bsd/openntpd/sbin/Makefile.inc
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
.include <bsd.own.mk>
|
||||
|
||||
BINDIR= /usr/sbin
|
||||
15
external/bsd/openntpd/sbin/openntpd/Makefile
vendored
Normal file
15
external/bsd/openntpd/sbin/openntpd/Makefile
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
PROG= ntpd
|
||||
SRCS= buffer.c client.c config.c imsg.c log.c ntp.c ntp_msg.c ntpd.c \
|
||||
server.c util.c y.tab.c
|
||||
MAN= ntpd.conf.5 ntpd.8
|
||||
.include <bsd.own.mk>
|
||||
|
||||
DIST= ${NETBSDSRCDIR}/external/bsd/openntpd/dist
|
||||
CPPFLAGS+= -I${DIST}
|
||||
LIBOPENBSDCOMPAT!= cd ${.CURDIR}/../../lib/openbsd-compat && ${PRINTOBJDIR}
|
||||
LDADD+= -L${LIBOPENBSDCOMPAT} -lopenbsd-compat
|
||||
DPADD+= ${LIBOPENBSDCOMPAT}/libopenbsd-compat.a
|
||||
|
||||
.PATH: ${DIST}
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
Loading…
Reference in New Issue
Block a user