diff options
Diffstat (limited to 'contrib/ntp/util')
-rw-r--r-- | contrib/ntp/util/Makefile.am | 19 | ||||
-rw-r--r-- | contrib/ntp/util/Makefile.in | 623 | ||||
-rw-r--r-- | contrib/ntp/util/README | 37 | ||||
-rw-r--r-- | contrib/ntp/util/ansi2knr.1 | 36 | ||||
-rw-r--r-- | contrib/ntp/util/ansi2knr.c | 739 | ||||
-rw-r--r-- | contrib/ntp/util/audio-pcm.c | 154 | ||||
-rw-r--r-- | contrib/ntp/util/byteorder.c | 56 | ||||
-rw-r--r-- | contrib/ntp/util/hist.c | 106 | ||||
-rw-r--r-- | contrib/ntp/util/jitter.c | 71 | ||||
-rw-r--r-- | contrib/ntp/util/kern.c | 225 | ||||
-rw-r--r-- | contrib/ntp/util/longsize.c | 11 | ||||
-rw-r--r-- | contrib/ntp/util/ntp-genkeys.c | 1048 | ||||
-rw-r--r-- | contrib/ntp/util/ntp-keygen.c | 1998 | ||||
-rw-r--r-- | contrib/ntp/util/ntptime.c | 440 | ||||
-rw-r--r-- | contrib/ntp/util/pps-api.c | 100 | ||||
-rw-r--r-- | contrib/ntp/util/precision.c | 171 | ||||
-rw-r--r-- | contrib/ntp/util/sht.c | 185 | ||||
-rw-r--r-- | contrib/ntp/util/testrs6000.c | 55 | ||||
-rw-r--r-- | contrib/ntp/util/tickadj.c | 902 | ||||
-rw-r--r-- | contrib/ntp/util/timetrim.c | 116 |
20 files changed, 0 insertions, 7092 deletions
diff --git a/contrib/ntp/util/Makefile.am b/contrib/ntp/util/Makefile.am deleted file mode 100644 index 8f1ba9e..0000000 --- a/contrib/ntp/util/Makefile.am +++ /dev/null @@ -1,19 +0,0 @@ -#AUTOMAKE_OPTIONS = ../ansi2knr no-dependencies -AUTOMAKE_OPTIONS= ansi2knr -bin_PROGRAMS= @MAKE_NTPTIME@ @MAKE_TICKADJ@ @MAKE_TIMETRIM@ @MAKE_NTP_KEYGEN@ -EXTRA_PROGRAMS= audio-pcm byteorder hist jitter kern longsize \ - ntp-keygen ntptime pps-api precision sht testrs6000 tickadj timetrim - -INCLUDES= -I$(top_srcdir)/include -# LDADD might need RESLIB and ADJLIB -LDADD= ../libntp/libntp.a -ntp_keygen_LDADD= @LCRYPTO@ -#EXTRA_DIST= README TAGS -EXTRA_DIST= -ETAGS_ARGS= Makefile.am - -../libntp/libntp.a: - cd ../libntp && $(MAKE) - -kern.o: kern.c - $(COMPILE) -DHAVE_TIMEX_H -c kern.c diff --git a/contrib/ntp/util/Makefile.in b/contrib/ntp/util/Makefile.in deleted file mode 100644 index 50b3042..0000000 --- a/contrib/ntp/util/Makefile.in +++ /dev/null @@ -1,623 +0,0 @@ -# Makefile.in generated by automake 1.7.7 from Makefile.am. -# @configure_input@ - -# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 -# Free Software Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - -@SET_MAKE@ - -srcdir = @srcdir@ -top_srcdir = @top_srcdir@ -VPATH = @srcdir@ -pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ -top_builddir = .. - -am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd -INSTALL = @INSTALL@ -install_sh_DATA = $(install_sh) -c -m 644 -install_sh_PROGRAM = $(install_sh) -c -install_sh_SCRIPT = $(install_sh) -c -INSTALL_HEADER = $(INSTALL_DATA) -transform = $(program_transform_name) -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -build_triplet = @build@ -host_triplet = @host@ -target_triplet = @target@ -ACLOCAL = @ACLOCAL@ -AMDEP_FALSE = @AMDEP_FALSE@ -AMDEP_TRUE = @AMDEP_TRUE@ -AMTAR = @AMTAR@ -ARLIB_DIR = @ARLIB_DIR@ -AUTOCONF = @AUTOCONF@ -AUTOHEADER = @AUTOHEADER@ -AUTOMAKE = @AUTOMAKE@ -AWK = @AWK@ -CC = @CC@ -CCDEPMODE = @CCDEPMODE@ -CFLAGS = @CFLAGS@ -CHUTEST = @CHUTEST@ -CLKTEST = @CLKTEST@ -CPP = @CPP@ -CPPFLAGS = @CPPFLAGS@ -CYGPATH_W = @CYGPATH_W@ -DCFD = @DCFD@ -DEFS = @DEFS@ -DEPDIR = @DEPDIR@ -ECHO_C = @ECHO_C@ -ECHO_N = @ECHO_N@ -ECHO_T = @ECHO_T@ -EF_LIBS = @EF_LIBS@ -EF_PROGS = @EF_PROGS@ -EGREP = @EGREP@ -EXEEXT = @EXEEXT@ -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ -LCRYPTO = @LCRYPTO@ -LDFLAGS = @LDFLAGS@ -LIBOBJS = @LIBOBJS@ -LIBPARSE = @LIBPARSE@ -LIBS = @LIBS@ -LN_S = @LN_S@ -LTLIBOBJS = @LTLIBOBJS@ -MAKEINFO = @MAKEINFO@ -MAKE_ADJTIMED = @MAKE_ADJTIMED@ -MAKE_CHECK_Y2K = @MAKE_CHECK_Y2K@ -MAKE_LIBNTPSIM = @MAKE_LIBNTPSIM@ -MAKE_LIBPARSE = @MAKE_LIBPARSE@ -MAKE_LIBPARSE_KERNEL = @MAKE_LIBPARSE_KERNEL@ -MAKE_NTPDSIM = @MAKE_NTPDSIM@ -MAKE_NTPTIME = @MAKE_NTPTIME@ -MAKE_NTP_KEYGEN = @MAKE_NTP_KEYGEN@ -MAKE_PARSEKMODULE = @MAKE_PARSEKMODULE@ -MAKE_SNTP = @MAKE_SNTP@ -MAKE_TICKADJ = @MAKE_TICKADJ@ -MAKE_TIMETRIM = @MAKE_TIMETRIM@ -OBJEXT = @OBJEXT@ -OPENSSL = @OPENSSL@ -OPENSSL_INC = @OPENSSL_INC@ -OPENSSL_LIB = @OPENSSL_LIB@ -PACKAGE = @PACKAGE@ -PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ -PACKAGE_NAME = @PACKAGE_NAME@ -PACKAGE_STRING = @PACKAGE_STRING@ -PACKAGE_TARNAME = @PACKAGE_TARNAME@ -PACKAGE_VERSION = @PACKAGE_VERSION@ -PATH_PERL = @PATH_PERL@ -PATH_SEPARATOR = @PATH_SEPARATOR@ -PATH_SH = @PATH_SH@ -PROPDELAY = @PROPDELAY@ -RANLIB = @RANLIB@ -READLINE_LIBS = @READLINE_LIBS@ -SET_MAKE = @SET_MAKE@ -SHELL = @SHELL@ -STRIP = @STRIP@ -TESTDCF = @TESTDCF@ -U = @U@ -VERSION = @VERSION@ -ac_ct_CC = @ac_ct_CC@ -ac_ct_RANLIB = @ac_ct_RANLIB@ -ac_ct_STRIP = @ac_ct_STRIP@ -am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ -am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ -am__include = @am__include@ -am__leading_dot = @am__leading_dot@ -am__quote = @am__quote@ -bindir = @bindir@ -build = @build@ -build_alias = @build_alias@ -build_cpu = @build_cpu@ -build_os = @build_os@ -build_vendor = @build_vendor@ -datadir = @datadir@ -exec_prefix = @exec_prefix@ -host = @host@ -host_alias = @host_alias@ -host_cpu = @host_cpu@ -host_os = @host_os@ -host_vendor = @host_vendor@ -includedir = @includedir@ -infodir = @infodir@ -install_sh = @install_sh@ -libdir = @libdir@ -libexecdir = @libexecdir@ -localstatedir = @localstatedir@ -mandir = @mandir@ -oldincludedir = @oldincludedir@ -prefix = @prefix@ -program_transform_name = @program_transform_name@ -sbindir = @sbindir@ -sharedstatedir = @sharedstatedir@ -subdirs = @subdirs@ -sysconfdir = @sysconfdir@ -target = @target@ -target_alias = @target_alias@ -target_cpu = @target_cpu@ -target_os = @target_os@ -target_vendor = @target_vendor@ - -#AUTOMAKE_OPTIONS = ../ansi2knr no-dependencies -AUTOMAKE_OPTIONS = ansi2knr -bin_PROGRAMS = @MAKE_NTPTIME@ @MAKE_TICKADJ@ @MAKE_TIMETRIM@ @MAKE_NTP_KEYGEN@ -EXTRA_PROGRAMS = audio-pcm byteorder hist jitter kern longsize \ - ntp-keygen ntptime pps-api precision sht testrs6000 tickadj timetrim - - -INCLUDES = -I$(top_srcdir)/include -# LDADD might need RESLIB and ADJLIB -LDADD = ../libntp/libntp.a -ntp_keygen_LDADD = @LCRYPTO@ -#EXTRA_DIST= README TAGS -EXTRA_DIST = -ETAGS_ARGS = Makefile.am -subdir = util -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs -CONFIG_HEADER = $(top_builddir)/config.h -CONFIG_CLEAN_FILES = -EXTRA_PROGRAMS = audio-pcm$(EXEEXT) byteorder$(EXEEXT) hist$(EXEEXT) \ - jitter$(EXEEXT) kern$(EXEEXT) longsize$(EXEEXT) \ - ntp-keygen$(EXEEXT) ntptime$(EXEEXT) pps-api$(EXEEXT) \ - precision$(EXEEXT) sht$(EXEEXT) testrs6000$(EXEEXT) \ - tickadj$(EXEEXT) timetrim$(EXEEXT) -bin_PROGRAMS = @MAKE_NTPTIME@ @MAKE_TICKADJ@ @MAKE_TIMETRIM@ \ - @MAKE_NTP_KEYGEN@ -PROGRAMS = $(bin_PROGRAMS) - -audio_pcm_SOURCES = audio-pcm.c -audio_pcm_OBJECTS = audio-pcm$U.$(OBJEXT) -audio_pcm_LDADD = $(LDADD) -audio_pcm_DEPENDENCIES = ../libntp/libntp.a -audio_pcm_LDFLAGS = -byteorder_SOURCES = byteorder.c -byteorder_OBJECTS = byteorder$U.$(OBJEXT) -byteorder_LDADD = $(LDADD) -byteorder_DEPENDENCIES = ../libntp/libntp.a -byteorder_LDFLAGS = -hist_SOURCES = hist.c -hist_OBJECTS = hist$U.$(OBJEXT) -hist_LDADD = $(LDADD) -hist_DEPENDENCIES = ../libntp/libntp.a -hist_LDFLAGS = -jitter_SOURCES = jitter.c -jitter_OBJECTS = jitter$U.$(OBJEXT) -jitter_LDADD = $(LDADD) -jitter_DEPENDENCIES = ../libntp/libntp.a -jitter_LDFLAGS = -kern_SOURCES = kern.c -kern_OBJECTS = kern$U.$(OBJEXT) -kern_LDADD = $(LDADD) -kern_DEPENDENCIES = ../libntp/libntp.a -kern_LDFLAGS = -longsize_SOURCES = longsize.c -longsize_OBJECTS = longsize$U.$(OBJEXT) -longsize_LDADD = $(LDADD) -longsize_DEPENDENCIES = ../libntp/libntp.a -longsize_LDFLAGS = -ntp_keygen_SOURCES = ntp-keygen.c -ntp_keygen_OBJECTS = ntp-keygen$U.$(OBJEXT) -ntp_keygen_DEPENDENCIES = -ntp_keygen_LDFLAGS = -ntptime_SOURCES = ntptime.c -ntptime_OBJECTS = ntptime$U.$(OBJEXT) -ntptime_LDADD = $(LDADD) -ntptime_DEPENDENCIES = ../libntp/libntp.a -ntptime_LDFLAGS = -pps_api_SOURCES = pps-api.c -pps_api_OBJECTS = pps-api$U.$(OBJEXT) -pps_api_LDADD = $(LDADD) -pps_api_DEPENDENCIES = ../libntp/libntp.a -pps_api_LDFLAGS = -precision_SOURCES = precision.c -precision_OBJECTS = precision$U.$(OBJEXT) -precision_LDADD = $(LDADD) -precision_DEPENDENCIES = ../libntp/libntp.a -precision_LDFLAGS = -sht_SOURCES = sht.c -sht_OBJECTS = sht$U.$(OBJEXT) -sht_LDADD = $(LDADD) -sht_DEPENDENCIES = ../libntp/libntp.a -sht_LDFLAGS = -testrs6000_SOURCES = testrs6000.c -testrs6000_OBJECTS = testrs6000$U.$(OBJEXT) -testrs6000_LDADD = $(LDADD) -testrs6000_DEPENDENCIES = ../libntp/libntp.a -testrs6000_LDFLAGS = -tickadj_SOURCES = tickadj.c -tickadj_OBJECTS = tickadj$U.$(OBJEXT) -tickadj_LDADD = $(LDADD) -tickadj_DEPENDENCIES = ../libntp/libntp.a -tickadj_LDFLAGS = -timetrim_SOURCES = timetrim.c -timetrim_OBJECTS = timetrim$U.$(OBJEXT) -timetrim_LDADD = $(LDADD) -timetrim_DEPENDENCIES = ../libntp/libntp.a -timetrim_LDFLAGS = - -DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) -depcomp = $(SHELL) $(top_srcdir)/depcomp -am__depfiles_maybe = depfiles -@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/audio-pcm$U.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/byteorder$U.Po ./$(DEPDIR)/hist$U.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/jitter$U.Po ./$(DEPDIR)/kern$U.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/longsize$U.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/ntp-keygen$U.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/ntptime$U.Po ./$(DEPDIR)/pps-api$U.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/precision$U.Po ./$(DEPDIR)/sht$U.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/testrs6000$U.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/tickadj$U.Po ./$(DEPDIR)/timetrim$U.Po -COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ - $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -CCLD = $(CC) -LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ -DIST_SOURCES = audio-pcm.c byteorder.c hist.c jitter.c kern.c longsize.c \ - ntp-keygen.c ntptime.c pps-api.c precision.c sht.c testrs6000.c \ - tickadj.c timetrim.c -DIST_COMMON = README $(srcdir)/Makefile.in Makefile.am ansi2knr.1 \ - ansi2knr.c -SOURCES = audio-pcm.c byteorder.c hist.c jitter.c kern.c longsize.c ntp-keygen.c ntptime.c pps-api.c precision.c sht.c testrs6000.c tickadj.c timetrim.c - -all: all-am - -.SUFFIXES: -.SUFFIXES: .c .o .obj -$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) - cd $(top_srcdir) && \ - $(AUTOMAKE) --gnu util/Makefile -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe) -binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) -install-binPROGRAMS: $(bin_PROGRAMS) - @$(NORMAL_INSTALL) - $(mkinstalldirs) $(DESTDIR)$(bindir) - @list='$(bin_PROGRAMS)'; for p in $$list; do \ - p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ - if test -f $$p \ - ; then \ - f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \ - echo " $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) $$p $(DESTDIR)$(bindir)/$$f"; \ - $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) $$p $(DESTDIR)$(bindir)/$$f || exit 1; \ - else :; fi; \ - done - -uninstall-binPROGRAMS: - @$(NORMAL_UNINSTALL) - @list='$(bin_PROGRAMS)'; for p in $$list; do \ - f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \ - echo " rm -f $(DESTDIR)$(bindir)/$$f"; \ - rm -f $(DESTDIR)$(bindir)/$$f; \ - done - -clean-binPROGRAMS: - -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) -audio-pcm$(EXEEXT): $(audio_pcm_OBJECTS) $(audio_pcm_DEPENDENCIES) - @rm -f audio-pcm$(EXEEXT) - $(LINK) $(audio_pcm_LDFLAGS) $(audio_pcm_OBJECTS) $(audio_pcm_LDADD) $(LIBS) -byteorder$(EXEEXT): $(byteorder_OBJECTS) $(byteorder_DEPENDENCIES) - @rm -f byteorder$(EXEEXT) - $(LINK) $(byteorder_LDFLAGS) $(byteorder_OBJECTS) $(byteorder_LDADD) $(LIBS) -hist$(EXEEXT): $(hist_OBJECTS) $(hist_DEPENDENCIES) - @rm -f hist$(EXEEXT) - $(LINK) $(hist_LDFLAGS) $(hist_OBJECTS) $(hist_LDADD) $(LIBS) -jitter$(EXEEXT): $(jitter_OBJECTS) $(jitter_DEPENDENCIES) - @rm -f jitter$(EXEEXT) - $(LINK) $(jitter_LDFLAGS) $(jitter_OBJECTS) $(jitter_LDADD) $(LIBS) -kern$(EXEEXT): $(kern_OBJECTS) $(kern_DEPENDENCIES) - @rm -f kern$(EXEEXT) - $(LINK) $(kern_LDFLAGS) $(kern_OBJECTS) $(kern_LDADD) $(LIBS) -longsize$(EXEEXT): $(longsize_OBJECTS) $(longsize_DEPENDENCIES) - @rm -f longsize$(EXEEXT) - $(LINK) $(longsize_LDFLAGS) $(longsize_OBJECTS) $(longsize_LDADD) $(LIBS) -ntp-keygen$(EXEEXT): $(ntp_keygen_OBJECTS) $(ntp_keygen_DEPENDENCIES) - @rm -f ntp-keygen$(EXEEXT) - $(LINK) $(ntp_keygen_LDFLAGS) $(ntp_keygen_OBJECTS) $(ntp_keygen_LDADD) $(LIBS) -ntptime$(EXEEXT): $(ntptime_OBJECTS) $(ntptime_DEPENDENCIES) - @rm -f ntptime$(EXEEXT) - $(LINK) $(ntptime_LDFLAGS) $(ntptime_OBJECTS) $(ntptime_LDADD) $(LIBS) -pps-api$(EXEEXT): $(pps_api_OBJECTS) $(pps_api_DEPENDENCIES) - @rm -f pps-api$(EXEEXT) - $(LINK) $(pps_api_LDFLAGS) $(pps_api_OBJECTS) $(pps_api_LDADD) $(LIBS) -precision$(EXEEXT): $(precision_OBJECTS) $(precision_DEPENDENCIES) - @rm -f precision$(EXEEXT) - $(LINK) $(precision_LDFLAGS) $(precision_OBJECTS) $(precision_LDADD) $(LIBS) -sht$(EXEEXT): $(sht_OBJECTS) $(sht_DEPENDENCIES) - @rm -f sht$(EXEEXT) - $(LINK) $(sht_LDFLAGS) $(sht_OBJECTS) $(sht_LDADD) $(LIBS) -testrs6000$(EXEEXT): $(testrs6000_OBJECTS) $(testrs6000_DEPENDENCIES) - @rm -f testrs6000$(EXEEXT) - $(LINK) $(testrs6000_LDFLAGS) $(testrs6000_OBJECTS) $(testrs6000_LDADD) $(LIBS) -tickadj$(EXEEXT): $(tickadj_OBJECTS) $(tickadj_DEPENDENCIES) - @rm -f tickadj$(EXEEXT) - $(LINK) $(tickadj_LDFLAGS) $(tickadj_OBJECTS) $(tickadj_LDADD) $(LIBS) -timetrim$(EXEEXT): $(timetrim_OBJECTS) $(timetrim_DEPENDENCIES) - @rm -f timetrim$(EXEEXT) - $(LINK) $(timetrim_LDFLAGS) $(timetrim_OBJECTS) $(timetrim_LDADD) $(LIBS) - -mostlyclean-compile: - -rm -f *.$(OBJEXT) core *.core - -distclean-compile: - -rm -f *.tab.c - -ANSI2KNR = @ANSI2KNR@ -ansi2knr: ansi2knr.$(OBJEXT) - $(LINK) ansi2knr.$(OBJEXT) $(LIBS) -ansi2knr.$(OBJEXT): $(CONFIG_HEADER) - -clean-krextra: - -rm -f ansi2knr - -mostlyclean-kr: - -test "$U" = "" || rm -f *_.c - -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/audio-pcm$U.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/byteorder$U.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hist$U.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/jitter$U.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/kern$U.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/longsize$U.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntp-keygen$U.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntptime$U.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pps-api$U.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/precision$U.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sht$U.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testrs6000$U.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tickadj$U.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/timetrim$U.Po@am__quote@ - -.c.o: -@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \ -@am__fastdepCC_TRUE@ -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \ -@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \ -@am__fastdepCC_TRUE@ fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(COMPILE) -c `test -f '$<' || echo '$(srcdir)/'`$< - -.c.obj: -@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \ -@am__fastdepCC_TRUE@ -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \ -@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \ -@am__fastdepCC_TRUE@ fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(COMPILE) -c `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi` -audio-pcm_.c: audio-pcm.c $(ANSI2KNR) - $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/audio-pcm.c; then echo $(srcdir)/audio-pcm.c; else echo audio-pcm.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@ -byteorder_.c: byteorder.c $(ANSI2KNR) - $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/byteorder.c; then echo $(srcdir)/byteorder.c; else echo byteorder.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@ -hist_.c: hist.c $(ANSI2KNR) - $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/hist.c; then echo $(srcdir)/hist.c; else echo hist.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@ -jitter_.c: jitter.c $(ANSI2KNR) - $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/jitter.c; then echo $(srcdir)/jitter.c; else echo jitter.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@ -kern_.c: kern.c $(ANSI2KNR) - $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/kern.c; then echo $(srcdir)/kern.c; else echo kern.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@ -longsize_.c: longsize.c $(ANSI2KNR) - $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/longsize.c; then echo $(srcdir)/longsize.c; else echo longsize.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@ -ntp-keygen_.c: ntp-keygen.c $(ANSI2KNR) - $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/ntp-keygen.c; then echo $(srcdir)/ntp-keygen.c; else echo ntp-keygen.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@ -ntptime_.c: ntptime.c $(ANSI2KNR) - $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/ntptime.c; then echo $(srcdir)/ntptime.c; else echo ntptime.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@ -pps-api_.c: pps-api.c $(ANSI2KNR) - $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/pps-api.c; then echo $(srcdir)/pps-api.c; else echo pps-api.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@ -precision_.c: precision.c $(ANSI2KNR) - $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/precision.c; then echo $(srcdir)/precision.c; else echo precision.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@ -sht_.c: sht.c $(ANSI2KNR) - $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/sht.c; then echo $(srcdir)/sht.c; else echo sht.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@ -testrs6000_.c: testrs6000.c $(ANSI2KNR) - $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/testrs6000.c; then echo $(srcdir)/testrs6000.c; else echo testrs6000.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@ -tickadj_.c: tickadj.c $(ANSI2KNR) - $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/tickadj.c; then echo $(srcdir)/tickadj.c; else echo tickadj.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@ -timetrim_.c: timetrim.c $(ANSI2KNR) - $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/timetrim.c; then echo $(srcdir)/timetrim.c; else echo timetrim.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@ -audio-pcm_.$(OBJEXT) byteorder_.$(OBJEXT) hist_.$(OBJEXT) \ -jitter_.$(OBJEXT) kern_.$(OBJEXT) longsize_.$(OBJEXT) \ -ntp-keygen_.$(OBJEXT) ntptime_.$(OBJEXT) pps-api_.$(OBJEXT) \ -precision_.$(OBJEXT) sht_.$(OBJEXT) testrs6000_.$(OBJEXT) \ -tickadj_.$(OBJEXT) timetrim_.$(OBJEXT) : $(ANSI2KNR) -uninstall-info-am: - -ETAGS = etags -ETAGSFLAGS = - -CTAGS = ctags -CTAGSFLAGS = - -tags: TAGS - -ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - mkid -fID $$unique - -TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - test -z "$(ETAGS_ARGS)$$tags$$unique" \ - || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ - $$tags $$unique - -ctags: CTAGS -CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - test -z "$(CTAGS_ARGS)$$tags$$unique" \ - || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ - $$tags $$unique - -GTAGS: - here=`$(am__cd) $(top_builddir) && pwd` \ - && cd $(top_srcdir) \ - && gtags -i $(GTAGS_ARGS) $$here - -distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags -DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) - -top_distdir = .. -distdir = $(top_distdir)/$(PACKAGE)-$(VERSION) - -distdir: $(DISTFILES) - @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ - topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ - list='$(DISTFILES)'; for file in $$list; do \ - case $$file in \ - $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ - $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ - esac; \ - if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ - dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ - if test "$$dir" != "$$file" && test "$$dir" != "."; then \ - dir="/$$dir"; \ - $(mkinstalldirs) "$(distdir)$$dir"; \ - else \ - dir=''; \ - fi; \ - if test -d $$d/$$file; then \ - if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ - cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ - fi; \ - cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ - else \ - test -f $(distdir)/$$file \ - || cp -p $$d/$$file $(distdir)/$$file \ - || exit 1; \ - fi; \ - done -check-am: all-am -check: check-am -all-am: Makefile $(ANSI2KNR) $(PROGRAMS) - -installdirs: - $(mkinstalldirs) $(DESTDIR)$(bindir) -install: install-am -install-exec: install-exec-am -install-data: install-data-am -uninstall: uninstall-am - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am - -installcheck: installcheck-am -install-strip: - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - INSTALL_STRIP_FLAG=-s \ - `test -z '$(STRIP)' || \ - echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -rm -f $(CONFIG_CLEAN_FILES) - -maintainer-clean-generic: - @echo "This command is intended for maintainers to use" - @echo "it deletes files that may require special tools to rebuild." -clean: clean-am - -clean-am: clean-binPROGRAMS clean-generic clean-krextra mostlyclean-am - -distclean: distclean-am - -rm -rf ./$(DEPDIR) - -rm -f Makefile - -distclean-am: clean-am distclean-compile distclean-generic \ - distclean-tags - -dvi: dvi-am - -dvi-am: - -info: info-am - -info-am: - -install-data-am: - -install-exec-am: install-binPROGRAMS - -install-info: install-info-am - -install-man: - -installcheck-am: - -maintainer-clean: maintainer-clean-am - -rm -rf ./$(DEPDIR) - -rm -f Makefile - -maintainer-clean-am: distclean-am maintainer-clean-generic - -mostlyclean: mostlyclean-am - -mostlyclean-am: mostlyclean-compile mostlyclean-generic mostlyclean-kr - -pdf: pdf-am - -pdf-am: - -ps: ps-am - -ps-am: - -uninstall-am: uninstall-binPROGRAMS uninstall-info-am - -.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \ - clean-generic clean-krextra ctags distclean distclean-compile \ - distclean-generic distclean-tags distdir dvi dvi-am info \ - info-am install install-am install-binPROGRAMS install-data \ - install-data-am install-exec install-exec-am install-info \ - install-info-am install-man install-strip installcheck \ - installcheck-am installdirs maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-compile \ - mostlyclean-generic mostlyclean-kr pdf pdf-am ps ps-am tags \ - uninstall uninstall-am uninstall-binPROGRAMS uninstall-info-am - - -../libntp/libntp.a: - cd ../libntp && $(MAKE) - -kern.o: kern.c - $(COMPILE) -DHAVE_TIMEX_H -c kern.c -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/contrib/ntp/util/README b/contrib/ntp/util/README deleted file mode 100644 index 297a562..0000000 --- a/contrib/ntp/util/README +++ /dev/null @@ -1,37 +0,0 @@ -README file for directory ./util of the NTP Version 4 distribution - -This directory contains the sources for the various utility programs. -See the README and RELNOTES files in the parent directory for directions -on how to make and install these programs. - -The ntptime.c program checks the kernel configuration for the NTP user -interface syscalls ntp_gettime() and ntp_adjtime(). If present, the -current timekeeping data are displayed. If not, a dissapointment is -displayed. See the kernel page file in the HTML documentation in -distribution for further details. ntptime will be built be if configure -believes your system can use it. - -The jitter.c program can be used to determine the timing jitter due to -the operating system in a gettimeofday() call. For most systems the -dominant contribution to the jitter budget is the period of the hardware -interrupt, usually in the range 10 us-1 ms. For those systems with -microsecond counters, such as recent Sun and certain HP and DEC systems, -the jitter is dominated only by the operating system. - -The timetrim.c program can be used with SGI machines to implement a -scheme to discipline the hardware clock frequency. See the source code -for further information. - -The byteorder.c and longsize.c programs are used during the configuration -process to determine the byte order (little or big endian) and longword -size (32 or 64 bits). See the configure scripts for further details. - -The testrs6000.c program is used for testing purposes with the IBM -RS/6000 AIX machines. Bill Jones <jones@chpc.utexas.edu> reports: -"I could not get a tickadj of less than 40 us to work on a RS6000. -If you set it less than 40 us do so at your own risk!" - -The tickadj.c program can be used to read and set various kernel -parameters affecting NTP operations. See the tickadj page in the HTML -documentation for further details. tickadj will be built if configure -believes your system can use it. diff --git a/contrib/ntp/util/ansi2knr.1 b/contrib/ntp/util/ansi2knr.1 deleted file mode 100644 index f9ee5a6..0000000 --- a/contrib/ntp/util/ansi2knr.1 +++ /dev/null @@ -1,36 +0,0 @@ -.TH ANSI2KNR 1 "19 Jan 1996" -.SH NAME -ansi2knr \- convert ANSI C to Kernighan & Ritchie C -.SH SYNOPSIS -.I ansi2knr -[--varargs] input_file [output_file] -.SH DESCRIPTION -If no output_file is supplied, output goes to stdout. -.br -There are no error messages. -.sp -.I ansi2knr -recognizes function definitions by seeing a non-keyword identifier at the left -margin, followed by a left parenthesis, with a right parenthesis as the last -character on the line, and with a left brace as the first token on the -following line (ignoring possible intervening comments). It will recognize a -multi-line header provided that no intervening line ends with a left or right -brace or a semicolon. These algorithms ignore whitespace and comments, except -that the function name must be the first thing on the line. -.sp -The following constructs will confuse it: -.br - - Any other construct that starts at the left margin and follows the -above syntax (such as a macro or function call). -.br - - Some macros that tinker with the syntax of the function header. -.sp -The --varargs switch is obsolete, and is recognized only for -backwards compatibility. The present version of -.I ansi2knr -will always attempt to convert a ... argument to va_alist and va_dcl. -.SH AUTHOR -L. Peter Deutsch <ghost@aladdin.com> wrote the original ansi2knr and -continues to maintain the current version; most of the code in the current -version is his work. ansi2knr also includes contributions by Francois -Pinard <pinard@iro.umontreal.ca> and Jim Avera <jima@netcom.com>. diff --git a/contrib/ntp/util/ansi2knr.c b/contrib/ntp/util/ansi2knr.c deleted file mode 100644 index 1b32b06..0000000 --- a/contrib/ntp/util/ansi2knr.c +++ /dev/null @@ -1,739 +0,0 @@ -/* Copyright (C) 1989, 2000 Aladdin Enterprises. All rights reserved. */ - -/*$Id: ansi2knr.c,v 1.3 2000/04/13 03:41:48 lpd Exp $*/ -/* Convert ANSI C function definitions to K&R ("traditional C") syntax */ - -/* -ansi2knr is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY. No author or distributor accepts responsibility to anyone for the -consequences of using it or for whether it serves any particular purpose or -works at all, unless he says so in writing. Refer to the GNU General Public -License (the "GPL") for full details. - -Everyone is granted permission to copy, modify and redistribute ansi2knr, -but only under the conditions described in the GPL. A copy of this license -is supposed to have been given to you along with ansi2knr so you can know -your rights and responsibilities. It should be in a file named COPYLEFT, -or, if there is no file named COPYLEFT, a file named COPYING. Among other -things, the copyright notice and this notice must be preserved on all -copies. - -We explicitly state here what we believe is already implied by the GPL: if -the ansi2knr program is distributed as a separate set of sources and a -separate executable file which are aggregated on a storage medium together -with another program, this in itself does not bring the other program under -the GPL, nor does the mere fact that such a program or the procedures for -constructing it invoke the ansi2knr executable bring any other part of the -program under the GPL. -*/ - -/* - * Usage: - ansi2knr [--filename FILENAME] [INPUT_FILE [OUTPUT_FILE]] - * --filename provides the file name for the #line directive in the output, - * overriding input_file (if present). - * If no input_file is supplied, input is read from stdin. - * If no output_file is supplied, output goes to stdout. - * There are no error messages. - * - * ansi2knr recognizes function definitions by seeing a non-keyword - * identifier at the left margin, followed by a left parenthesis, with a - * right parenthesis as the last character on the line, and with a left - * brace as the first token on the following line (ignoring possible - * intervening comments and/or preprocessor directives), except that a line - * consisting of only - * identifier1(identifier2) - * will not be considered a function definition unless identifier2 is - * the word "void", and a line consisting of - * identifier1(identifier2, <<arbitrary>>) - * will not be considered a function definition. - * ansi2knr will recognize a multi-line header provided that no intervening - * line ends with a left or right brace or a semicolon. These algorithms - * ignore whitespace, comments, and preprocessor directives, except that - * the function name must be the first thing on the line. The following - * constructs will confuse it: - * - Any other construct that starts at the left margin and - * follows the above syntax (such as a macro or function call). - * - Some macros that tinker with the syntax of function headers. - */ - -/* - * The original and principal author of ansi2knr is L. Peter Deutsch - * <ghost@aladdin.com>. Other authors are noted in the change history - * that follows (in reverse chronological order): - - lpd 2000-04-12 backs out Eggert's changes because of bugs: - - concatlits didn't declare the type of its bufend argument; - - concatlits didn't't recognize when it was inside a comment; - - scanstring could scan backward past the beginning of the string; when - - the check for \ + newline in scanstring was unnecessary. - - 2000-03-05 Paul Eggert <eggert@twinsun.com> - - Add support for concatenated string literals. - * ansi2knr.c (concatlits): New decl. - (main): Invoke concatlits to concatenate string literals. - (scanstring): Handle backslash-newline correctly. Work with - character constants. Fix bug when scanning backwards through - backslash-quote. Check for unterminated strings. - (convert1): Parse character constants, too. - (appendline, concatlits): New functions. - * ansi2knr.1: Document this. - - lpd 1999-08-17 added code to allow preprocessor directives - wherever comments are allowed - lpd 1999-04-12 added minor fixes from Pavel Roskin - <pavel_roskin@geocities.com> for clean compilation with - gcc -W -Wall - lpd 1999-03-22 added hack to recognize lines consisting of - identifier1(identifier2, xxx) as *not* being procedures - lpd 1999-02-03 made indentation of preprocessor commands consistent - lpd 1999-01-28 fixed two bugs: a '/' in an argument list caused an - endless loop; quoted strings within an argument list - confused the parser - lpd 1999-01-24 added a check for write errors on the output, - suggested by Jim Meyering <meyering@ascend.com> - lpd 1998-11-09 added further hack to recognize identifier(void) - as being a procedure - lpd 1998-10-23 added hack to recognize lines consisting of - identifier1(identifier2) as *not* being procedures - lpd 1997-12-08 made input_file optional; only closes input and/or - output file if not stdin or stdout respectively; prints - usage message on stderr rather than stdout; adds - --filename switch (changes suggested by - <ceder@lysator.liu.se>) - lpd 1996-01-21 added code to cope with not HAVE_CONFIG_H and with - compilers that don't understand void, as suggested by - Tom Lane - lpd 1996-01-15 changed to require that the first non-comment token - on the line following a function header be a left brace, - to reduce sensitivity to macros, as suggested by Tom Lane - <tgl@sss.pgh.pa.us> - lpd 1995-06-22 removed #ifndefs whose sole purpose was to define - undefined preprocessor symbols as 0; changed all #ifdefs - for configuration symbols to #ifs - lpd 1995-04-05 changed copyright notice to make it clear that - including ansi2knr in a program does not bring the entire - program under the GPL - lpd 1994-12-18 added conditionals for systems where ctype macros - don't handle 8-bit characters properly, suggested by - Francois Pinard <pinard@iro.umontreal.ca>; - removed --varargs switch (this is now the default) - lpd 1994-10-10 removed CONFIG_BROKETS conditional - lpd 1994-07-16 added some conditionals to help GNU `configure', - suggested by Francois Pinard <pinard@iro.umontreal.ca>; - properly erase prototype args in function parameters, - contributed by Jim Avera <jima@netcom.com>; - correct error in writeblanks (it shouldn't erase EOLs) - lpd 1989-xx-xx original version - */ - -/* Most of the conditionals here are to make ansi2knr work with */ -/* or without the GNU configure machinery. */ - -#if HAVE_CONFIG_H -# include <config.h> -#endif - -#include <stdio.h> -#include <ctype.h> - -#if HAVE_CONFIG_H - -/* - For properly autoconfiguring ansi2knr, use AC_CONFIG_HEADER(config.h). - This will define HAVE_CONFIG_H and so, activate the following lines. - */ - -# if STDC_HEADERS || HAVE_STRING_H -# include <string.h> -# else -# include <strings.h> -# endif - -#else /* not HAVE_CONFIG_H */ - -/* Otherwise do it the hard way */ - -# ifdef BSD -# include <strings.h> -# else -# ifdef VMS - extern int strlen(), strncmp(); -# else -# include <string.h> -# endif -# endif - -#endif /* not HAVE_CONFIG_H */ - -#if STDC_HEADERS -# include <stdlib.h> -#else -/* - malloc and free should be declared in stdlib.h, - but if you've got a K&R compiler, they probably aren't. - */ -# ifdef MSDOS -# include <malloc.h> -# else -# ifdef VMS - extern char *malloc(); - extern void free(); -# else - extern char *malloc(); - extern int free(); -# endif -# endif - -#endif - -/* Define NULL (for *very* old compilers). */ -#ifndef NULL -# define NULL (0) -#endif - -/* - * The ctype macros don't always handle 8-bit characters correctly. - * Compensate for this here. - */ -#ifdef isascii -# undef HAVE_ISASCII /* just in case */ -# define HAVE_ISASCII 1 -#else -#endif -#if STDC_HEADERS || !HAVE_ISASCII -# define is_ascii(c) 1 -#else -# define is_ascii(c) isascii(c) -#endif - -#define is_space(c) (is_ascii(c) && isspace(c)) -#define is_alpha(c) (is_ascii(c) && isalpha(c)) -#define is_alnum(c) (is_ascii(c) && isalnum(c)) - -/* Scanning macros */ -#define isidchar(ch) (is_alnum(ch) || (ch) == '_') -#define isidfirstchar(ch) (is_alpha(ch) || (ch) == '_') - -/* Forward references */ -char *ppdirforward(); -char *ppdirbackward(); -char *skipspace(); -char *scanstring(); -int writeblanks(); -int test1(); -int convert1(); - -/* The main program */ -int -main(argc, argv) - int argc; - char *argv[]; -{ FILE *in = stdin; - FILE *out = stdout; - char *filename = 0; - char *program_name = argv[0]; - char *output_name = 0; -#define bufsize 5000 /* arbitrary size */ - char *buf; - char *line; - char *more; - char *usage = - "Usage: ansi2knr [--filename FILENAME] [INPUT_FILE [OUTPUT_FILE]]\n"; - /* - * In previous versions, ansi2knr recognized a --varargs switch. - * If this switch was supplied, ansi2knr would attempt to convert - * a ... argument to va_alist and va_dcl; if this switch was not - * supplied, ansi2knr would simply drop any such arguments. - * Now, ansi2knr always does this conversion, and we only - * check for this switch for backward compatibility. - */ - int convert_varargs = 1; - int output_error; - - while ( argc > 1 && argv[1][0] == '-' ) { - if ( !strcmp(argv[1], "--varargs") ) { - convert_varargs = 1; - argc--; - argv++; - continue; - } - if ( !strcmp(argv[1], "--filename") && argc > 2 ) { - filename = argv[2]; - argc -= 2; - argv += 2; - continue; - } - fprintf(stderr, "%s: Unrecognized switch: %s\n", program_name, - argv[1]); - fprintf(stderr, usage); - exit(1); - } - switch ( argc ) - { - default: - fprintf(stderr, usage); - exit(0); - case 3: - output_name = argv[2]; - out = fopen(output_name, "w"); - if ( out == NULL ) { - fprintf(stderr, "%s: Cannot open output file %s\n", - program_name, output_name); - exit(1); - } - /* falls through */ - case 2: - in = fopen(argv[1], "r"); - if ( in == NULL ) { - fprintf(stderr, "%s: Cannot open input file %s\n", - program_name, argv[1]); - exit(1); - } - if ( filename == 0 ) - filename = argv[1]; - /* falls through */ - case 1: - break; - } - if ( filename ) - fprintf(out, "#line 1 \"%s\"\n", filename); - buf = malloc(bufsize); - if ( buf == NULL ) - { - fprintf(stderr, "Unable to allocate read buffer!\n"); - exit(1); - } - line = buf; - while ( fgets(line, (unsigned)(buf + bufsize - line), in) != NULL ) - { -test: line += strlen(line); - switch ( test1(buf) ) - { - case 2: /* a function header */ - convert1(buf, out, 1, convert_varargs); - break; - case 1: /* a function */ - /* Check for a { at the start of the next line. */ - more = ++line; -f: if ( line >= buf + (bufsize - 1) ) /* overflow check */ - goto wl; - if ( fgets(line, (unsigned)(buf + bufsize - line), in) == NULL ) - goto wl; - switch ( *skipspace(ppdirforward(more), 1) ) - { - case '{': - /* Definitely a function header. */ - convert1(buf, out, 0, convert_varargs); - fputs(more, out); - break; - case 0: - /* The next line was blank or a comment: */ - /* keep scanning for a non-comment. */ - line += strlen(line); - goto f; - default: - /* buf isn't a function header, but */ - /* more might be. */ - fputs(buf, out); - strcpy(buf, more); - line = buf; - goto test; - } - break; - case -1: /* maybe the start of a function */ - if ( line != buf + (bufsize - 1) ) /* overflow check */ - continue; - /* falls through */ - default: /* not a function */ -wl: fputs(buf, out); - break; - } - line = buf; - } - if ( line != buf ) - fputs(buf, out); - free(buf); - if ( output_name ) { - output_error = ferror(out); - output_error |= fclose(out); - } else { /* out == stdout */ - fflush(out); - output_error = ferror(out); - } - if ( output_error ) { - fprintf(stderr, "%s: error writing to %s\n", program_name, - (output_name ? output_name : "stdout")); - exit(1); - } - if ( in != stdin ) - fclose(in); - return 0; -} - -/* - * Skip forward or backward over one or more preprocessor directives. - */ -char * -ppdirforward(p) - char *p; -{ - for (; *p == '#'; ++p) { - for (; *p != '\r' && *p != '\n'; ++p) - if (*p == 0) - return p; - if (*p == '\r' && p[1] == '\n') - ++p; - } - return p; -} -char * -ppdirbackward(p, limit) - char *p; - char *limit; -{ - char *np = p; - - for (;; p = --np) { - if (*np == '\n' && np[-1] == '\r') - --np; - for (; np > limit && np[-1] != '\r' && np[-1] != '\n'; --np) - if (np[-1] == 0) - return np; - if (*np != '#') - return p; - } -} - -/* - * Skip over whitespace, comments, and preprocessor directives, - * in either direction. - */ -char * -skipspace(p, dir) - char *p; - int dir; /* 1 for forward, -1 for backward */ -{ - for ( ; ; ) { - while ( is_space(*p) ) - p += dir; - if ( !(*p == '/' && p[dir] == '*') ) - break; - p += dir; p += dir; - while ( !(*p == '*' && p[dir] == '/') ) { - if ( *p == 0 ) - return p; /* multi-line comment?? */ - p += dir; - } - p += dir; p += dir; - } - return p; -} - -/* Scan over a quoted string, in either direction. */ -char * -scanstring(p, dir) - char *p; - int dir; -{ - for (p += dir; ; p += dir) - if (*p == '"' && p[-dir] != '\\') - return p + dir; -} - -/* - * Write blanks over part of a string. - * Don't overwrite end-of-line characters. - */ -int -writeblanks(start, end) - char *start; - char *end; -{ char *p; - for ( p = start; p < end; p++ ) - if ( *p != '\r' && *p != '\n' ) - *p = ' '; - return 0; -} - -/* - * Test whether the string in buf is a function definition. - * The string may contain and/or end with a newline. - * Return as follows: - * 0 - definitely not a function definition; - * 1 - definitely a function definition; - * 2 - definitely a function prototype (NOT USED); - * -1 - may be the beginning of a function definition, - * append another line and look again. - * The reason we don't attempt to convert function prototypes is that - * Ghostscript's declaration-generating macros look too much like - * prototypes, and confuse the algorithms. - */ -int -test1(buf) - char *buf; -{ char *p = buf; - char *bend; - char *endfn; - int contin; - - if ( !isidfirstchar(*p) ) - return 0; /* no name at left margin */ - bend = skipspace(ppdirbackward(buf + strlen(buf) - 1, buf), -1); - switch ( *bend ) - { - case ';': contin = 0 /*2*/; break; - case ')': contin = 1; break; - case '{': return 0; /* not a function */ - case '}': return 0; /* not a function */ - default: contin = -1; - } - while ( isidchar(*p) ) - p++; - endfn = p; - p = skipspace(p, 1); - if ( *p++ != '(' ) - return 0; /* not a function */ - p = skipspace(p, 1); - if ( *p == ')' ) - return 0; /* no parameters */ - /* Check that the apparent function name isn't a keyword. */ - /* We only need to check for keywords that could be followed */ - /* by a left parenthesis (which, unfortunately, is most of them). */ - { static char *words[] = - { "asm", "auto", "case", "char", "const", "double", - "extern", "float", "for", "if", "int", "long", - "register", "return", "short", "signed", "sizeof", - "static", "switch", "typedef", "unsigned", - "void", "volatile", "while", 0 - }; - char **key = words; - char *kp; - unsigned len = endfn - buf; - - while ( (kp = *key) != 0 ) - { if ( strlen(kp) == len && !strncmp(kp, buf, len) ) - return 0; /* name is a keyword */ - key++; - } - } - { - char *id = p; - int len; - /* - * Check for identifier1(identifier2) and not - * identifier1(void), or identifier1(identifier2, xxxx). - */ - - while ( isidchar(*p) ) - p++; - len = p - id; - p = skipspace(p, 1); - if (*p == ',' || - (*p == ')' && (len != 4 || strncmp(id, "void", 4))) - ) - return 0; /* not a function */ - } - /* - * If the last significant character was a ), we need to count - * parentheses, because it might be part of a formal parameter - * that is a procedure. - */ - if (contin > 0) { - int level = 0; - - for (p = skipspace(buf, 1); *p; p = skipspace(p + 1, 1)) - level += (*p == '(' ? 1 : *p == ')' ? -1 : 0); - if (level > 0) - contin = -1; - } - return contin; -} - -/* Convert a recognized function definition or header to K&R syntax. */ -int -convert1(buf, out, header, convert_varargs) - char *buf; - FILE *out; - int header; /* Boolean */ - int convert_varargs; /* Boolean */ -{ char *endfn; - char *p; - /* - * The breaks table contains pointers to the beginning and end - * of each argument. - */ - char **breaks; - unsigned num_breaks = 2; /* for testing */ - char **btop; - char **bp; - char **ap; - char *vararg = 0; - - /* Pre-ANSI implementations don't agree on whether strchr */ - /* is called strchr or index, so we open-code it here. */ - for ( endfn = buf; *(endfn++) != '('; ) - ; -top: p = endfn; - breaks = (char **)malloc(sizeof(char *) * num_breaks * 2); - if ( breaks == NULL ) - { /* Couldn't allocate break table, give up */ - fprintf(stderr, "Unable to allocate break table!\n"); - fputs(buf, out); - return -1; - } - btop = breaks + num_breaks * 2 - 2; - bp = breaks; - /* Parse the argument list */ - do - { int level = 0; - char *lp = NULL; - char *rp = NULL; - char *end = NULL; - - if ( bp >= btop ) - { /* Filled up break table. */ - /* Allocate a bigger one and start over. */ - free((char *)breaks); - num_breaks <<= 1; - goto top; - } - *bp++ = p; - /* Find the end of the argument */ - for ( ; end == NULL; p++ ) - { switch(*p) - { - case ',': - if ( !level ) end = p; - break; - case '(': - if ( !level ) lp = p; - level++; - break; - case ')': - if ( --level < 0 ) end = p; - else rp = p; - break; - case '/': - if (p[1] == '*') - p = skipspace(p, 1) - 1; - break; - case '"': - p = scanstring(p, 1) - 1; - break; - default: - ; - } - } - /* Erase any embedded prototype parameters. */ - if ( lp && rp ) - writeblanks(lp + 1, rp); - p--; /* back up over terminator */ - /* Find the name being declared. */ - /* This is complicated because of procedure and */ - /* array modifiers. */ - for ( ; ; ) - { p = skipspace(p - 1, -1); - switch ( *p ) - { - case ']': /* skip array dimension(s) */ - case ')': /* skip procedure args OR name */ - { int level = 1; - while ( level ) - switch ( *--p ) - { - case ']': case ')': - level++; - break; - case '[': case '(': - level--; - break; - case '/': - if (p > buf && p[-1] == '*') - p = skipspace(p, -1) + 1; - break; - case '"': - p = scanstring(p, -1) + 1; - break; - default: ; - } - } - if ( *p == '(' && *skipspace(p + 1, 1) == '*' ) - { /* We found the name being declared */ - while ( !isidfirstchar(*p) ) - p = skipspace(p, 1) + 1; - goto found; - } - break; - default: - goto found; - } - } -found: if ( *p == '.' && p[-1] == '.' && p[-2] == '.' ) - { if ( convert_varargs ) - { *bp++ = "va_alist"; - vararg = p-2; - } - else - { p++; - if ( bp == breaks + 1 ) /* sole argument */ - writeblanks(breaks[0], p); - else - writeblanks(bp[-1] - 1, p); - bp--; - } - } - else - { while ( isidchar(*p) ) p--; - *bp++ = p+1; - } - p = end; - } - while ( *p++ == ',' ); - *bp = p; - /* Make a special check for 'void' arglist */ - if ( bp == breaks+2 ) - { p = skipspace(breaks[0], 1); - if ( !strncmp(p, "void", 4) ) - { p = skipspace(p+4, 1); - if ( p == breaks[2] - 1 ) - { bp = breaks; /* yup, pretend arglist is empty */ - writeblanks(breaks[0], p + 1); - } - } - } - /* Put out the function name and left parenthesis. */ - p = buf; - while ( p != endfn ) putc(*p, out), p++; - /* Put out the declaration. */ - if ( header ) - { fputs(");", out); - for ( p = breaks[0]; *p; p++ ) - if ( *p == '\r' || *p == '\n' ) - putc(*p, out); - } - else - { for ( ap = breaks+1; ap < bp; ap += 2 ) - { p = *ap; - while ( isidchar(*p) ) - putc(*p, out), p++; - if ( ap < bp - 1 ) - fputs(", ", out); - } - fputs(") ", out); - /* Put out the argument declarations */ - for ( ap = breaks+2; ap <= bp; ap += 2 ) - (*ap)[-1] = ';'; - if ( vararg != 0 ) - { *vararg = 0; - fputs(breaks[0], out); /* any prior args */ - fputs("va_dcl", out); /* the final arg */ - fputs(bp[0], out); - } - else - fputs(breaks[0], out); - } - free((char *)breaks); - return 0; -} diff --git a/contrib/ntp/util/audio-pcm.c b/contrib/ntp/util/audio-pcm.c deleted file mode 100644 index 6f2e4fa..0000000 --- a/contrib/ntp/util/audio-pcm.c +++ /dev/null @@ -1,154 +0,0 @@ -/* - * audio-pcm.c - Scope out the PCM audio stuff - */ -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#if defined(HAVE_MACHINE_SOUNDCARD_H) || defined(HAVE_SYS_SOUNDCARD_H) - -#include "audio.h" -#include "ntp_stdlib.h" -#include "ntp_syslog.h" -#ifdef HAVE_UNISTD_H -# include <unistd.h> -#endif -#include <stdio.h> -#include "ntp_string.h" - -#ifdef HAVE_SYS_IOCTL_H -#include <sys/ioctl.h> -#endif /* HAVE_SYS_IOCTL_H */ - -#include <fcntl.h> - -#ifdef HAVE_MACHINE_SOUNDCARD_H -# include <machine/soundcard.h> -# define PCM_STYLE_SOUND -#else -# ifdef HAVE_SYS_SOUNDCARD_H -# include <sys/soundcard.h> -# define PCM_STYLE_SOUND -# endif -#endif - -/* - * Global variables - */ -static int ctl_fd; /* audio control file descriptor */ - -const char *m_names[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES ; - -void -d_fmt( - unsigned int format - ) -{ - - if (format & AFMT_MU_LAW) printf("MU_LAW "); - if (format & AFMT_A_LAW) printf("A_LAW "); - if (format & AFMT_IMA_ADPCM) printf("IMA_ADPCM "); - if (format & AFMT_U8) printf("U8 "); - if (format & AFMT_S16_LE) printf("S16_LE "); - if (format & AFMT_S16_BE) printf("S16_BE "); - if (format & AFMT_S8) printf("S8 "); - if (format & AFMT_U16_LE) printf("U16_LE "); - if (format & AFMT_U16_BE) printf("U16_BE "); - if (format & AFMT_MPEG) printf("MPEG "); - if (format & AFMT_AC3) printf("AC3 "); - printf("\n"); -} - -void -d_mixer( - unsigned int mixer - ) -{ - int i; - int n = 0; - - for (i = 0; i < SOUND_MIXER_NRDEVICES; ++i) - if ((1 << i) & mixer) { - if (n) - printf(", "); - printf("%s", m_names[i]); - n = 1; - } - printf("\n"); -} - -int -main( ) -{ - int unit = 0; /* device unit (0-3) */ -# define AI_DEV "/dev/audio%d" -# define AC_DEV "/dev/mixer%d" - char ai_dev[30]; - char ac_dev[30]; - struct snd_size s_size; - snd_chan_param s_c_p; - snd_capabilities s_c; - int fd; - int rval; - char *dname = ai_dev; /* device name */ - char *actl = ac_dev; - int devmask = 0, recmask = 0, recsrc = 0; - - (void)sprintf(ai_dev, AI_DEV, unit); - (void)sprintf(ac_dev, AC_DEV, unit); - - /* - * Open audio device. Do not complain if not there. - */ - fd = open(dname, O_RDWR | O_NONBLOCK, 0777); - if (fd < 0) - return (fd); - - /* - * Open audio control device. - */ - ctl_fd = open(actl, O_RDWR); - if (ctl_fd < 0) { - fprintf(stderr, "invalid control device <%s>\n", actl); - close(fd); - return(ctl_fd); - } - - printf("input: <%s> %d\n", dname, fd); - printf("control: <%s> %d\n", actl, ctl_fd); - - if (ioctl(ctl_fd, SOUND_MIXER_READ_DEVMASK, &devmask) == -1) - printf("SOUND_MIXER_READ_DEVMASK: %s\n", strerror(errno)); - if (ioctl(ctl_fd, SOUND_MIXER_READ_RECMASK, &recmask) == -1) - printf("SOUND_MIXER_READ_RECMASK: %s\n", strerror(errno)); - if (ioctl(ctl_fd, SOUND_MIXER_READ_RECSRC, &recsrc) == -1) - printf("SOUND_MIXER_READ_RECSRC: %s\n", strerror(errno)); - - printf("devmask: %#x recmask: %#x recsrc: %#x\n", - devmask, recmask, recsrc); - printf("Devmask: "); d_mixer(devmask); - printf("Recmask: "); d_mixer(recmask); - printf("RecSrc: "); d_mixer(recsrc); - - /* - * Set audio device parameters. - */ - rval = fd; - - if (ioctl(fd, AIOGSIZE, &s_size) == -1) - printf("AIOGSIZE: %s\n", strerror(errno)); - else - printf("play_size %d, rec_size %d\n", - s_size.play_size, s_size.rec_size); - - if (ioctl(fd, AIOGFMT, &s_c_p) == -1) - printf("AIOGFMT: %s\n", strerror(errno)); - else { - printf("play_rate %lu, rec_rate %lu, play_format %#lx, rec_format %#lx\n", - s_c_p.play_rate, s_c_p.rec_rate, s_c_p.play_format, s_c_p.rec_format); - printf("Play format: "); d_fmt(s_c_p.play_format); - printf("Rec format: "); d_fmt(s_c_p.rec_format); - } - -} -#endif /* HAVE_{MACHINE_SOUNDCARD,SYS_SOUNDCARD}_H */ diff --git a/contrib/ntp/util/byteorder.c b/contrib/ntp/util/byteorder.c deleted file mode 100644 index 188536f..0000000 --- a/contrib/ntp/util/byteorder.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This works on: - * Crays - * Conven - * sparc's - * Dec mip machines - * Dec alpha machines - * RS6000 - * SGI's - */ - -#include <stdio.h> - -int -main( - int argc, - char *argv[] - ) -{ - int i; - int big; - union { - unsigned long l; - char c[sizeof(long)]; - } u; - -#if defined(LONG8) - u.l = (((long)0x08070605) << 32) | (long)0x04030201; -#else - u.l = 0x04030201; -#endif - if (sizeof(long) > 4) { - if (u.c[0] == 0x08) big = 1; - else big = 0; - } else { - if (u.c[0] == 0x04) big = 1; - else big = 0; - } - for (i=0; i< sizeof(long); i++) { - if (big == 1 && (u.c[i] == (sizeof(long) - i))) { - continue; - } else if (big == 0 && (u.c[i] == (i+1))) { - continue; - } else { - big = -1; - break; - } - } - - if (big == 1) { - printf("XNTP_BIG_ENDIAN\n"); - } else if (big == 0) { - printf("XNTP_LITTLE_ENDIAN\n"); - } - exit(0); -} diff --git a/contrib/ntp/util/hist.c b/contrib/ntp/util/hist.c deleted file mode 100644 index c9763ce..0000000 --- a/contrib/ntp/util/hist.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * This program can be used to calibrate the clock reading jitter of a - * particular CPU and operating system. It first tickles every element - * of an array, in order to force pages into memory, then repeatedly calls - * gettimeofday() and, finally, writes out the time values for later - * analysis. From this you can determine the jitter and if the clock ever - * runs backwards. - */ - -#if 0 -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#include "ntp_types.h" -#endif - -#include <stdio.h> -#include <stdlib.h> -#include <time.h> - -#define NBUF 100001 /* size of basic histogram */ -#define NSRT 20000 /* size of overflow histogram */ -#define NCNT (600 * 1000000) /* sample interval (us) */ - -extern int col(hrtime_t *, hrtime_t *); -extern hrtime_t gethrtime(void); - -int -main( - int argc, - char *argv[] - ) -{ - int i, j, n; - hrtime_t t, u, v, w, gtod[NBUF], ovfl[NSRT]; - - /* - * Force pages into memory - */ - for (i = 0; i < NBUF; i++) - gtod[i] = 0; - for (i = 0; i < NSRT; i++) - ovfl[i] = 0; - - /* - * Construct histogram - */ - n = 0; - t = gethrtime(); - v = t; - while (1) { - u = gethirestime(); - if (u - v > NCNT) - break; - w = u - t; - if (w <= 0) { -/* - printf("error <= 0 %ld %d %d, %d %d\n", w, ts.tv_sec, - ts.tv_usec, tr.tv_sec, tr.tv_usec); -*/ - } else if (w > NBUF - 1) { - ovfl[n] = w; - if (n < NSRT - 1) - n++; - } else { - gtod[w]++; - } - t = u; - } - - /* - * Write out histogram - */ - for (i = 0; i < NBUF - 1; i++) { - if (gtod[i] > 0) - printf("%ld %ld\n", i, gtod[i]); - } - if (n == 0) - return; - qsort((char *)ovfl, (size_t)n, sizeof(hrtime_t), col); - w = 0; - j = 0; - for (i = 0; i < n; i++) { - if (ovfl[i] != w) { - if (j > 0) - printf("%ld %ld\n", w, j); - w = ovfl[i]; - j = 1; - } else - j++; - } - if (j > 0) - printf("%ld %ld\n", w, j); - - exit(0); -} - -int -col( - hrtime_t *x, - hrtime_t *y - ) -{ - return (*x - *y); -} diff --git a/contrib/ntp/util/jitter.c b/contrib/ntp/util/jitter.c deleted file mode 100644 index 462fe12..0000000 --- a/contrib/ntp/util/jitter.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * This program can be used to calibrate the clock reading jitter of a - * particular CPU and operating system. It first tickles every element - * of an array, in order to force pages into memory, then repeatedly calls - * gettimeofday() and, finally, writes out the time values for later - * analysis. From this you can determine the jitter and if the clock ever - * runs backwards. - */ - -#include <stdio.h> -#include <sys/time.h> - -#define NBUF 20002 - -int -main( - int argc, - char *argv[] - ) -{ - struct timeval ts, tr; - struct timezone tzp; - long temp, j, i, gtod[NBUF]; - - gettimeofday(&ts, &tzp); - - /* - * Force pages into memory - */ - for (i = 0; i < NBUF; i ++) - gtod[i] = 0; - - /* - * Construct gtod array - */ - for (i = 0; i < NBUF; i ++) { - gettimeofday(&tr, &tzp); - gtod[i] = (tr.tv_sec - ts.tv_sec) * 1000000 + tr.tv_usec; - } - - /* - * Write out gtod array for later processing with S - */ - for (i = 0; i < NBUF - 2; i++) { - /* - printf("%lu\n", gtod[i]); - */ - gtod[i] = gtod[i + 1] - gtod[i]; - printf("%lu\n", gtod[i]); - } - - /* - * Sort the gtod array and display deciles - */ - for (i = 0; i < NBUF - 2; i++) { - for (j = 0; j <= i; j++) { - if (gtod[j] > gtod[i]) { - temp = gtod[j]; - gtod[j] = gtod[i]; - gtod[i] = temp; - } - } - } - fprintf(stderr, "First rank\n"); - for (i = 0; i < 10; i++) - fprintf(stderr, "%10ld%10ld\n", i, gtod[i]); - fprintf(stderr, "Last rank\n"); - for (i = NBUF - 12; i < NBUF - 2; i++) - fprintf(stderr, "%10ld%10ld\n", i, gtod[i]); - exit(0); -} diff --git a/contrib/ntp/util/kern.c b/contrib/ntp/util/kern.c deleted file mode 100644 index b193d6f..0000000 --- a/contrib/ntp/util/kern.c +++ /dev/null @@ -1,225 +0,0 @@ -/* - * This program simulates a first-order, type-II phase-lock loop using - * actual code segments from modified kernel distributions for SunOS, - * Ultrix and OSF/1 kernels. These segments do not use any licensed code. - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#include <stdio.h> -#include <ctype.h> -#include <math.h> -#include <sys/time.h> - -#ifdef HAVE_TIMEX_H -# include "timex.h" -#endif - -/* - * Phase-lock loop definitions - */ -#define HZ 100 /* timer interrupt frequency (Hz) */ -#define MAXPHASE 512000 /* max phase error (us) */ -#define MAXFREQ 200 /* max frequency error (ppm) */ -#define TAU 2 /* time constant (shift 0 - 6) */ -#define POLL 16 /* interval between updates (s) */ -#define MAXSEC 1200 /* max interval between updates (s) */ - -/* - * Function declarations - */ -void hardupdate(); -void hardclock(); -void second_overflow(); - -/* - * Kernel variables - */ -int tick; /* timer interrupt period (us) */ -int fixtick; /* amortization constant (ppm) */ -struct timeval timex; /* ripoff of kernel time variable */ - -/* - * Phase-lock loop variables - */ -int time_status = TIME_BAD; /* clock synchronization status */ -long time_offset = 0; /* time adjustment (us) */ -long time_constant = 0; /* pll time constant */ -long time_tolerance = MAXFREQ; /* frequency tolerance (ppm) */ -long time_precision = 1000000 / HZ; /* clock precision (us) */ -long time_maxerror = MAXPHASE; /* maximum error (us) */ -long time_esterror = MAXPHASE; /* estimated error (us) */ -long time_phase = 0; /* phase offset (scaled us) */ -long time_freq = 0; /* frequency offset (scaled ppm) */ -long time_adj = 0; /* tick adjust (scaled 1 / HZ) */ -long time_reftime = 0; /* time at last adjustment (s) */ - -/* - * Simulation variables - */ -double timey = 0; /* simulation time (us) */ -long timez = 0; /* current error (us) */ -long poll_interval = 0; /* poll counter */ - -/* - * Simulation test program - */ -int -main( - int argc, - char *argv[] - ) -{ - tick = 1000000 / HZ; - fixtick = 1000000 % HZ; - timex.tv_sec = 0; - timex.tv_usec = MAXPHASE; - time_freq = 0; - time_constant = TAU; - printf("tick %d us, fixtick %d us\n", tick, fixtick); - printf(" time offset freq _offset _freq _adj\n"); - - /* - * Grind the loop until ^C - */ - while (1) { - timey += (double)(1000000) / HZ; - if (timey >= 1000000) - timey -= 1000000; - hardclock(); - if (timex.tv_usec >= 1000000) { - timex.tv_usec -= 1000000; - timex.tv_sec++; - second_overflow(); - poll_interval++; - if (!(poll_interval % POLL)) { - timez = (long)timey - timex.tv_usec; - if (timez > 500000) - timez -= 1000000; - if (timez < -500000) - timez += 1000000; - hardupdate(timez); - printf("%10li%10li%10.2f %08lx %08lx %08lx\n", - timex.tv_sec, timez, - (double)time_freq / (1 << SHIFT_KF), - time_offset, time_freq, time_adj); - } - } - } -} - -/* - * This routine simulates the ntp_adjtime() call - * - * For default SHIFT_UPDATE = 12, offset is limited to +-512 ms, the - * maximum interval between updates is 4096 s and the maximum frequency - * offset is +-31.25 ms/s. - */ -void -hardupdate( - long offset - ) -{ - long ltemp, mtemp; - - time_offset = offset << SHIFT_UPDATE; - mtemp = timex.tv_sec - time_reftime; - time_reftime = timex.tv_sec; - if (mtemp > MAXSEC) - mtemp = 0; - - /* ugly multiply should be replaced */ - if (offset < 0) - time_freq -= (-offset * mtemp) >> - (time_constant + time_constant); - else - time_freq += (offset * mtemp) >> - (time_constant + time_constant); - ltemp = time_tolerance << SHIFT_KF; - if (time_freq > ltemp) - time_freq = ltemp; - else if (time_freq < -ltemp) - time_freq = -ltemp; - if (time_status == TIME_BAD) - time_status = TIME_OK; -} - -/* - * This routine simulates the timer interrupt - */ -void -hardclock(void) -{ - int ltemp, time_update; - - time_update = tick; /* computed by adjtime() */ - time_phase += time_adj; - if (time_phase < -FINEUSEC) { - ltemp = -time_phase >> SHIFT_SCALE; - time_phase += ltemp << SHIFT_SCALE; - time_update -= ltemp; - } - else if (time_phase > FINEUSEC) { - ltemp = time_phase >> SHIFT_SCALE; - time_phase -= ltemp << SHIFT_SCALE; - time_update += ltemp; - } - timex.tv_usec += time_update; -} - -/* - * This routine simulates the overflow of the microsecond field - * - * With SHIFT_SCALE = 23, the maximum frequency adjustment is +-256 us - * per tick, or 25.6 ms/s at a clock frequency of 100 Hz. The time - * contribution is shifted right a minimum of two bits, while the frequency - * contribution is a right shift. Thus, overflow is prevented if the - * frequency contribution is limited to half the maximum or 15.625 ms/s. - */ -void -second_overflow(void) -{ - int ltemp; - - time_maxerror += time_tolerance; - if (time_offset < 0) { - ltemp = -time_offset >> - (SHIFT_KG + time_constant); - time_offset += ltemp; - time_adj = -(ltemp << - (SHIFT_SCALE - SHIFT_HZ - SHIFT_UPDATE)); - } else { - ltemp = time_offset >> - (SHIFT_KG + time_constant); - time_offset -= ltemp; - time_adj = ltemp << - (SHIFT_SCALE - SHIFT_HZ - SHIFT_UPDATE); - } - if (time_freq < 0) - time_adj -= -time_freq >> (SHIFT_KF + SHIFT_HZ - SHIFT_SCALE); - else - time_adj += time_freq >> (SHIFT_KF + SHIFT_HZ - SHIFT_SCALE); - time_adj += fixtick << (SHIFT_SCALE - SHIFT_HZ); - - /* ugly divide should be replaced */ - if (timex.tv_sec % 86400 == 0) { - switch (time_status) { - - case TIME_INS: - timex.tv_sec--; /* !! */ - time_status = TIME_OOP; - break; - - case TIME_DEL: - timex.tv_sec++; - time_status = TIME_OK; - break; - - case TIME_OOP: - time_status = TIME_OK; - break; - } - } -} diff --git a/contrib/ntp/util/longsize.c b/contrib/ntp/util/longsize.c deleted file mode 100644 index bba1955..0000000 --- a/contrib/ntp/util/longsize.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <stdio.h> - -main() -{ - if (sizeof(long) == 8) { - printf("-DLONG8\n"); - } else if (sizeof(long) == 4) { - printf("-DLONG4\n"); - } - exit(0); -} diff --git a/contrib/ntp/util/ntp-genkeys.c b/contrib/ntp/util/ntp-genkeys.c deleted file mode 100644 index 5b70f72..0000000 --- a/contrib/ntp/util/ntp-genkeys.c +++ /dev/null @@ -1,1048 +0,0 @@ -/* - * Program to generate MD5 and RSA keys for NTP clients and servers - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#ifdef HAVE_NETINFO -#include <netinfo/ni.h> -#endif - -#include "ntp_machine.h" -#include "ntpd.h" -#include "ntp_stdlib.h" -#include "ntp_string.h" -#include "ntp_filegen.h" -#include "ntp_unixtime.h" -#include "ntp_config.h" -#include "ntp_cmdargs.h" - -#ifndef GETTIMEOFDAY -# define GETTIMEOFDAY gettimeofday -#endif - -#include <stdio.h> -#include <unistd.h> -#include <limits.h> /* PATH_MAX */ -#include <sys/stat.h> - -#ifdef PUBKEY -# include "ntp_crypto.h" -#endif - -#include "l_stdlib.h" - -#ifndef PATH_MAX -# ifdef _POSIX_PATH_MAX -# define PATH_MAX _POSIX_PATH_MAX -# else -# define PATH_MAX 255 -# endif -#endif - -/* - * Cryptodefines - */ -#define MAXKEYLEN 1024 /* maximum encoded key length */ -#define MODULUSLEN 512 /* length of RSA modulus */ -#define PRIMELEN 512 /* length of D_H prime, generator */ - -/* - * This program generates (up to) four files: - * - * ntp.keys containing the DES/MD5 private keys, - * ntpkey containing the RSA private key, - * ntpkey_HOST containing the RSA public key - * where HOST is the DNS name of the generating machine, - * ntpkey_dh containing the parameters for the Diffie-Hellman - * key-agreement algorithm. - * - * The files contain cryptographic values generated by the algorithms of - * the rsaref20 package and are in printable ASCII format. Since the - * algorythms are seeded by the system clock, each run of this program - * will produce a different outcome. There are no options or frills of - * any sort, although a number of options would seem to be appropriate. - * Waving this program in the breeze will no doubt bring a cast of - * thousands to wiggle the options this way and that for various useful - * purposes. - * - * The names of all files begin with "ntp" and end with an extension - * consisting of the seconds value of the current NTP timestamp, which - * appears in the form ".*". This provides a way to distinguish between - * key generations, since the host name and timestamp can be fetched by - * a client during operation. - * - * The ntp.keys.* file contains 16 MD5 keys. Each key consists of 16 - * characters randomized over the ASCII 95-character printing subset. - * The file is read by the daemon at the location specified by the keys - * configuration file command and made visible only to root. An - * additional key consisting of a easily remembered password should be - * added by hand for use with the ntpdc program. The file must be - * distributed by secure means to other servers and clients sharing the - * same security compartment. - * - * The key identifiers for MD5 and DES keys must be less than 65536, - * although this program uses only the identifiers from 1 to 16. The key - * identifier for each association is specified as the key argument in - * the server or peer configuration file command. - * - * The ntpkey.* file contains the RSA private key. It is read by the - * daemon at the location specified by the private argument of the - * crypto configuration file command and made visible only to root. - * This file is useful only to the machine that generated it and never - * shared with any other daemon or application program. - * - * The ntpkey_host.* file contains the RSA public key, where host is the - * DNS name of the host that generated it. The file is read by the - * daemon at the location specified by the public argument to the server - * or peer configuration file command. This file can be widely - * distributed and stored without using secure means, since the data are - * public values. - * - * The ntp_dh.* file contains two Diffie-Hellman parameters, the prime - * modulus and the generator. The file is read by the daemon at the - * location specified by the dhparams argument of the crypto - * configuration file command. This file can be widely distributed and - * stored without using secure means, since the data are public values. - * - * The file formats all begin with two lines. The first line contains - * the file name and decimal timestamp, while the second contains the - * readable datestamp. Lines beginning with # are considered comments - * and ignored by the daemon. In the ntp.keys.* file, the next 16 lines - * contain the MD5 keys in order. In the ntpkey.* and ntpkey_host.* - * files, the next line contains the modulus length in bits followed by - * the key as a PEM encoded string. In the ntpkey_dh.* file, the next - * line contains the prime length in bytes followed by the prime as a - * PEM encoded string, and the next and final line contains the - * generator length in bytes followed by the generator as a PEM encoded - * string. - * - * Note: See the file ./source/rsaref.h in the rsaref20 package for - * explanation of return values, if necessary. - */ - - -extern char *config_file; - -#ifdef HAVE_NETINFO -extern struct netinfo_config_state *config_netinfo; -extern int check_netinfo; -#endif /* HAVE_NETINFO */ - -#ifdef SYS_WINNT -char *alt_config_file; -LPTSTR temp; -char config_file_storage[PATH_MAX]; -char alt_config_file_storage[PATH_MAX]; -#endif /* SYS_WINNT */ - -int make_dh = 0; /* Make D-H parameter file? */ -int make_md5 = 0; /* Make MD5 keyfile? */ -int make_rsa = 0; /* Make RSA pair? */ -int force = 0; /* Force the installation? */ -int here = 0; /* Put the files here (curdir)? */ -int nosymlinks = 0; /* Just create the (timestamped) files? */ -int memorex = 0; /* Are we live? */ -int trash = 0; /* Trash old files? */ -int errflag = 0; - -char *f1_keysdir = NTP_KEYSDIR; - -char *f1_keys; /* Visible MD5 key file name */ -char *f2_keys; /* timestamped */ -char *f3_keys; /* previous filename */ - -char *f1_publickey; -char *f2_publickey; -char *f3_publickey; - -char *f1_privatekey; -char *f2_privatekey; -char *f3_privatekey; - -char *f1_dhparms; -char *f2_dhparms; -char *f3_dhparms; - - -/* Stubs and hacks so we can link with ntp_config.o */ -u_long sys_automax; /* maximum session key lifetime */ -int sys_bclient; /* we set our time to broadcasts */ -int sys_manycastserver; /* 1 => respond to manycast client pkts */ -char * req_file; /* name of the file with configuration info */ -keyid_t ctl_auth_keyid; /* keyid used for authenticating write requests */ -struct interface *any_interface; /* default interface */ -keyid_t info_auth_keyid; /* keyid used to authenticate requests */ -u_long current_time; /* current time (s) */ -const char *Version = ""; /* version declaration */ -keyid_t req_keyid; /* request keyid */ -u_long client_limit; -u_long client_limit_period; -l_fp sys_revoketime; -u_long sys_revoke; /* keys revoke timeout */ -volatile int debug = 0; /* debugging flag */ -u_char sys_minpoll; /* min poll interval (log2 s) */ - -void snifflink P((const char *, char **)); -int filep P((const char *)); -FILE *newfile P((const char *, const char *, mode_t, const char *)); -void cleanlinks P((const char *, const char *, const char *)); - -struct peer * -peer_config( - struct sockaddr_in *srcadr, - struct interface *dstadr, - int hmode, - int version, - int minpoll, - int maxpoll, - u_int flags, - int ttl, - keyid_t key, - u_char *keystr - ) -{ - if (debug > 1) printf("peer_config...\n"); - return 0; -} - - -void -set_sys_var( - char *data, - u_long size, - int def - ) -{ - if (debug > 1) printf("set_sys_var...\n"); - return; -} - - -void -ntp_intres (void) -{ - if (debug > 1) printf("ntp_intres...\n"); - return; -} - - -int -ctlsettrap( - struct sockaddr_in *raddr, - struct interface *linter, - int traptype, - int version - ) -{ - if (debug > 1) printf("ctlsettrap...\n"); - return 0; -} - - -#ifdef PUBKEY -void -crypto_config( - int item, /* configuration item */ - char *cp /* file name */ - ) -{ - switch (item) { - case CRYPTO_CONF_DH: - if (debug > 0) printf("crypto_config: DH/<%d> <%s>\n", item, cp); - f1_dhparms = strdup(cp); - break; - case CRYPTO_CONF_PRIV: - if (debug > 0) printf("crypto_config: PRIVATEKEY/<%d> <%s>\n", item, cp); - f1_privatekey = strdup(cp); - break; - case CRYPTO_CONF_PUBL: - if (debug > 0) printf("crypto_config: PUBLICKEY/<%d> <%s>\n", item, cp); - f1_publickey = strdup(cp); - break; - default: - if (debug > 1) printf("crypto_config: <%d> <%s>\n", item, cp); - break; - } - return; -} -#endif - - -struct interface * -findinterface( - struct sockaddr_in *addr - ) -{ - if (debug > 1) printf("findinterface...\n"); - return 0; -} - - -void -refclock_control( - struct sockaddr_in *srcadr, - struct refclockstat *in, - struct refclockstat *out - ) -{ - if (debug > 1) printf("refclock_control...\n"); - return; -} - - -void -loop_config( - int item, - double freq - ) -{ - if (debug > 1) printf("loop_config...\n"); - return; -} - - -void -filegen_config( - FILEGEN *gen, - char *basename, - u_int type, - u_int flag - ) -{ - if (debug > 1) printf("filegen_config...\n"); - return; -} - - -void -stats_config( - int item, - char *invalue /* only one type so far */ - ) -{ - if (debug > 1) printf("stats_config...\n"); - return; -} - - -void -hack_restrict( - int op, - struct sockaddr_in *resaddr, - struct sockaddr_in *resmask, - int mflags, - int flags - ) -{ - if (debug > 1) printf("hack_restrict...\n"); - return; -} - - -void -kill_asyncio (void) -{ - if (debug > 1) printf("kill_asyncio...\n"); - return; -} - - -void -proto_config( - int item, - u_long value, - double dvalue - ) -{ - if (debug > 1) printf("proto_config...\n"); - return; -} - -void -getauthkeys( - char *keyfile - ) -{ - if (debug > 0) printf("getauthkeys: got <%s>\n", keyfile); - f1_keys = strdup(keyfile); - return; -} - - -FILEGEN * -filegen_get( - char *name - ) -{ - if (debug > 1) printf("filegen_get...\n"); - return 0; -} - - -/* End of stubs and hacks */ - - -static void -usage( - void - ) -{ - printf("Usage: %s [ -c ntp.conf ] [ -g {d,m,r} ] [ -k key_file ]\n", - progname); - printf(" [ -d ] [ -f ] [ -h ] [ -l ] [ -n ] [ -t ]\n"); - printf(" where:\n"); - printf(" -c /etc/ntp.conf Location of ntp.conf file\n"); - printf(" -d enable debug messages (can be used multiple times)\n"); - printf(" -f force installation of generated keys.\n"); - printf(" -g d Generate D-H parameter file\n"); - printf(" -g m Generate MD5 key file\n"); - printf(" -g r Generate RSA keys\n"); - printf(" -g dmr (Can be combined)\n"); - printf(" -h Build keys here (current directory). Implies -l\n"); - printf(" -k key_file Location of key file\n"); - printf(" -l Don't make the symlinks\n"); - printf(" -n Don't actually do anything, just say what would be done\n"); - printf(" -t Trash the (old) files at the end of symlink\n"); - - exit(1); -} - - -void -getCmdOpts ( - int argc, - char *argv[] - ) -{ - int i; - - while ((i = ntp_getopt(argc, argv, "c:dfg:hlnt")) != EOF) - switch (i) { - case 'c': - config_file = ntp_optarg; -#ifdef HAVE_NETINFO - check_netinfo = 0; -#endif - break; - case 'd': - ++debug; - break; - case 'f': - ++force; - break; - case 'g': - while (*ntp_optarg) { - switch (*ntp_optarg) { - case 'd': - ++make_dh; - break; - case 'm': - ++make_md5; - break; - case 'r': - ++make_rsa; - break; - default: - ++errflag; - break; - } - ++ntp_optarg; - } - break; - case 'h': - ++here; - ++nosymlinks; - break; - case 'l': - ++nosymlinks; - break; - case 'n': - ++memorex; - break; - case 't': - ++trash; - break; - case '?': - ++errflag; - break; - } - - if (errflag) - usage(); - - /* If no file type was specified, make them all. */ - if (!(make_dh | make_md5 | make_rsa)) { - ++make_dh; - ++make_md5; - ++make_rsa; - } -} - - -void -snifflink( - const char *file, - char **linkdata - ) -{ -#ifdef HAVE_READLINK - char buf[PATH_MAX]; - int rc; - - if (!file) - return; - - rc = readlink(file, buf, sizeof buf); - if (-1 == rc) { - switch (errno) { - case EINVAL: /* Fall thru */ - case ENOENT: - return; - } - fprintf(stderr, "%s: readlink(%s) failed: (%d) %s\n", - progname, file, errno, strerror(errno)); - exit(1); - } - buf[rc] = '\0'; - *linkdata = strdup(buf); - /* XXX: make sure linkdata is not 0... */ -#endif /* not HAVE_READLINK */ - return; -} - - -int -filep( - const char *fn - ) -{ - struct stat sb; - - if (-1 == stat(fn, &sb)) { - if (ENOENT == errno) - return 0; - fprintf(stderr, "stat(%s) failed: %s\n", - fn, strerror(errno)); - exit(1); - } - return 1; -} - - -FILE * -newfile( - const char *f1, /* Visible file */ - const char *f2, /* New timestamped file name */ - mode_t fmask, /* umask for new timestamped file */ - const char *f3 /* Previous symlink target */ - ) -{ - FILE *fp; - char fb[PATH_MAX]; - char *cp; - - if (debug > 1) printf("newfile(%s,%s,%0o,%s)\n", f1, f2, - (unsigned)fmask, f3 ? f3 : "NULL"); - /* - If: - - no symlink support, or - - there is no old symlink (!f3) - - - file = dirname(f1) / f2 - Otherwise: - - If ('/' == *f3) - - - file = dirname(f3) / f2 - - else - - - file = dirname(f1) / dirname(f3) / f2 - fopen(file) - print any error message/bail - return FILE - */ - - if (here) - snprintf(fb, sizeof fb, "%s", f2); - else { - if ( -#ifdef HAVE_READLINK - !f3 -#else - 1 -#endif - ) { - /* file = dirname(f1) / f2 */ - snprintf(fb, sizeof fb, "%s", f1); - cp = strrchr(fb, '/'); - if (cp) { - *cp = 0; - } - snprintf(fb, sizeof fb, "%s/%s", fb, f2); - if (debug > 1) printf("case 1: file is <%s>\n", fb); - } else { - /* - - If ('/' == *f3) - - - file = dirname(f3) / f2 - - else - - - file = dirname(f1) / dirname(f3) / f2 - */ - if ('/' != *f3) { - snprintf(fb, sizeof fb, "%s", f1); - cp = strrchr(fb, '/'); - if (cp) { - ++cp; - *cp = 0; - } - if (debug > 1) - printf("case 2: file is <%s>\n", fb); - } else { - *fb = 0; - } - snprintf(fb, sizeof fb, "%s%s", fb, f3); - cp = strrchr(fb, '/'); - if (cp) { - *cp = 0; - } - snprintf(fb, sizeof fb, "%s/%s", fb, f2); - if (debug > 1) printf("case 3: file is <%s>\n", fb); - } - } - - /* - fopen(file) - print any error message/bail - return FILE - */ - if (memorex) { - printf("Would write file <%s>\n", fb); - fp = NULL; - } else { - mode_t omask; - - omask = umask(fmask); - fp = fopen(fb, "w"); - (void) umask(omask); - if (fp == NULL) { - perror(fb); - exit(1); - } - } - return fp; -} - -void -cleanlinks( - const char *f1, /* Visible file */ - const char *f2, /* New timestamped file name */ - const char *f3 /* Previous symlink target */ - ) -{ -#ifdef HAVE_READLINK - char *cp; - char fb[PATH_MAX]; - - /* - Just return if nosymlinks. - unlink f1 - file = dirname(f3) / f2 - symlink file, f1 - If trash: - - if f3 begins with a /, unlink it - - else, unlink dirname(f1) / f3 - */ -#endif /* HAVE_READLINK */ - - if (nosymlinks) - return; - - if (memorex) - printf("Would unlink(%s)\n", f1); - else if (unlink(f1)) { - if (errno != ENOENT) { - fprintf(stderr, "unlink(%s) failed: %s\n", f1, - strerror(errno)); - return; - } - } - /* file = dirname(f3) / f2 */ - if (f3) { - snprintf(fb, sizeof fb, "%s", f3); - cp = strrchr(fb, '/'); - if (cp) { - ++cp; - *cp = 0; - } else { - *fb = 0; - } - } else { - *fb = 0; - } - snprintf(fb, sizeof fb, "%s%s", fb, f2); - if (debug > 1) printf("cleanlinks 1: file is <%s>\n", fb); - - if (memorex) - printf("Would symlink <%s> -> <%s>\n", f1, fb); - else if (symlink(fb, f1)) { - fprintf(stderr, "symlink(%s,%s) failed: %s\n", fb, f1, - strerror(errno)); - return; - } - - /* - If trash: - - if f3 begins with a /, unlink it - - else, unlink dirname(f1) / f3 - */ - if (trash && f3) { - if ('/' == *f3) { - if (memorex) - printf("Would unlink(%s)\n", f3); - else if (unlink(f3)) { - if (errno != ENOENT) { - fprintf(stderr, "unlink(%s) failed: %s\n", f3, - strerror(errno)); - return; - } - } - } else { - snprintf(fb, sizeof fb, "%s", f1); - cp = strrchr(fb, '/'); - if (cp) { - *cp = 0; - } - snprintf(fb, sizeof fb, "%s/%s", fb, f3); - if (debug > 1) - printf("cleanlinks 2: file is <%s>\n", fb); - if (memorex) - printf("Would unlink(%s)\n", fb); - else if (unlink(fb)) { - if (errno != ENOENT) { - fprintf(stderr, "unlink(%s) failed: %s\n", fb, - strerror(errno)); - return; - } - } - } - } - - return; -} - - -int -main( - int argc, - char *argv[] - ) -{ -#ifdef PUBKEY - R_RSA_PRIVATE_KEY rsaref_private; /* RSA private key */ - R_RSA_PUBLIC_KEY rsaref_public; /* RSA public key */ - R_RSA_PROTO_KEY protokey; /* RSA prototype key */ - R_DH_PARAMS dh_params; /* Diffie-Hellman parameters */ - R_RANDOM_STRUCT randomstr; /* random structure */ - int rval; /* return value */ - u_char encoded_key[MAXKEYLEN]; /* encoded PEM string buffer */ - u_int modulus; /* modulus length */ - u_int len; -#endif /* PUBKEY */ - struct timeval tv; /* initialization vector */ - u_long ntptime; /* NTP timestamp */ - char hostname[256]; /* DNS host name */ - u_char md5key[17]; /* generated MD5 key */ - FILE *str; /* file handle */ - u_int temp; - int i, j; - mode_t std_mask; /* Standard mask */ - mode_t sec_mask = 077; /* Secure mask */ - char pathbuf[PATH_MAX]; - - gethostname(hostname, sizeof(hostname)); - GETTIMEOFDAY(&tv, 0); - ntptime = tv.tv_sec + JAN_1970; - - /* Initialize config_file */ - getconfig(argc, argv); /* ntpd/ntp_config.c */ - - if (!f1_keysdir) { - /* Shouldn't happen... */ - f1_keysdir = "PATH_KEYSDIR"; - } - if (*f1_keysdir != '/') { - fprintf(stderr, - "%s: keysdir path <%s> doesn't begin with a /\n", - progname, f1_keysdir); - exit(1); - } - - if (!f2_keys) { - snprintf(pathbuf, sizeof pathbuf, "ntp.keys.%lu", - ntptime); - f2_keys = strdup(pathbuf); - } - if (!f1_keys) { - snprintf(pathbuf, sizeof pathbuf, "%s/ntp.keys", - f1_keysdir); - f1_keys = strdup(pathbuf); - } - if (*f1_keys != '/') { - fprintf(stderr, - "%s: keys path <%s> doesn't begin with a /\n", - progname, f1_keys); - exit(1); - } - snifflink(f1_keys, &f3_keys); - - if (!f2_publickey) { - snprintf(pathbuf, sizeof pathbuf, "ntpkey_%s.%lu", - hostname, ntptime); - f2_publickey = strdup(pathbuf); - } - if (!f1_publickey) { - snprintf(pathbuf, sizeof pathbuf, "%s/ntpkey_%s", - f1_keysdir, hostname); - f1_publickey = strdup(pathbuf); - } - if (*f1_publickey != '/') { - fprintf(stderr, - "%s: publickey path <%s> doesn't begin with a /\n", - progname, f1_publickey); - exit(1); - } - snifflink(f1_publickey, &f3_publickey); - - if (!f2_privatekey) { - snprintf(pathbuf, sizeof pathbuf, "ntpkey.%lu", - ntptime); - f2_privatekey = strdup(pathbuf); - } - if (!f1_privatekey) { - snprintf(pathbuf, sizeof pathbuf, "%s/ntpkey", - f1_keysdir); - f1_privatekey = strdup(pathbuf); - } - if (*f1_privatekey != '/') { - fprintf(stderr, - "%s: privatekey path <%s> doesn't begin with a /\n", - progname, f1_privatekey); - exit(1); - } - snifflink(f1_privatekey, &f3_privatekey); - - if (!f2_dhparms) { - snprintf(pathbuf, sizeof pathbuf, "ntpkey_dh.%lu", - ntptime); - f2_dhparms = strdup(pathbuf); - } - if (!f1_dhparms) { - snprintf(pathbuf, sizeof pathbuf, "%s/ntpkey_dh", - f1_keysdir); - f1_dhparms = strdup(pathbuf); - } - if (*f1_dhparms != '/') { - fprintf(stderr, - "%s: dhparms path <%s> doesn't begin with a /\n", - progname, f1_dhparms); - exit(1); - } - snifflink(f1_dhparms, &f3_dhparms); - - if (debug > 1) { - printf("After config:\n"); - printf("keysdir = <%s>\n", f1_keysdir? f1_keysdir: ""); - printf("keys = <%s> -> <%s>\n" - , f1_keys? f1_keys: "" - , f2_keys? f2_keys: "" - ); - printf(" old = <%s>\n", f3_keys? f3_keys: ""); - printf("publickey = <%s> -> <%s>\n" - , f1_publickey? f1_publickey: "" - , f2_publickey? f2_publickey: "" - ); - printf(" old = <%s>\n", f3_publickey? f3_publickey: ""); - printf("privatekey = <%s> -> <%s>\n" - , f1_privatekey? f1_privatekey: "" - , f2_privatekey? f2_privatekey: "" - ); - printf(" old = <%s>\n", f3_privatekey? f3_privatekey: ""); - printf("dhparms = <%s> -> <%s>\n" - , f1_dhparms? f1_dhparms: "" - , f2_dhparms? f2_dhparms: "" - ); - printf(" old = <%s>\n", f3_dhparms? f3_dhparms: ""); - } - - /* - for each file we're going to install: - - make the new timestamped file - - if (!nosymlinks) - - - remove any old link - - - make the link - - - if (trash) - - - - remove the old file - */ - - std_mask = umask(sec_mask); /* Get the standard mask */ - (void) umask(std_mask); - - if (make_md5 && (force || !filep(f1_keys))) { - /* - * Generate 16 random MD5 keys. - */ - printf("Generating MD5 key file...\n"); - str = newfile(f1_keys, f2_keys, sec_mask, f3_keys); - if (!memorex) { - SRANDOM((u_int)tv.tv_usec); - fprintf(str, "# MD5 key file %s\n# %s", f2_keys, - ctime((const time_t *) &tv.tv_sec)); - for (i = 1; i <= 16; i++) { - for (j = 0; j < 16; j++) { - while (1) { - temp = RANDOM & 0xff; - /* - ** Harlan says Karnaugh maps - ** are not his friend, and - ** compilers can optimize - ** this most easily. - */ - if (temp == '#') - continue; - if (temp > 0x20 && temp < 0x7f) - break; - } - md5key[j] = (u_char)temp; - } - md5key[16] = 0; - fprintf(str, "%2d M %16s # MD5 key\n", - i, md5key); - } - } - if (str) fclose(str); - cleanlinks(f1_keys, f2_keys, f3_keys); - } - -#ifdef PUBKEY - if (make_rsa && (force || !filep(f1_publickey) - || !filep(f1_privatekey))) { - /* - * Roll the RSA public/private key pair. - */ - printf("Generating RSA public/private key pair (%d bits)...\n", - MODULUSLEN); - if (!memorex) { - protokey.bits = MODULUSLEN; - protokey.useFermat4 = 1; - R_RandomInit(&randomstr); - R_GetRandomBytesNeeded(&len, &randomstr); - for (i = 0; i < len; i++) { - temp = RANDOM; - R_RandomUpdate(&randomstr, (u_char *)&temp, 1); - } - rval = R_GeneratePEMKeys(&rsaref_public, - &rsaref_private, &protokey, - &randomstr); - if (rval) { - printf("R_GeneratePEMKeys error %x\n", rval); - return (-1); - } - } - - /* - * Generate the file "ntpkey.*" containing the RSA - * private key in printable ASCII format. - */ - str = newfile(f1_privatekey, f2_privatekey, sec_mask, - f3_privatekey); - if (!memorex) { - len = sizeof(rsaref_private) - - sizeof(rsaref_private.bits); - modulus = (u_int32)rsaref_private.bits; - fprintf(str, "# RSA private key file %s\n# %s", - f2_privatekey, ctime(&tv.tv_sec)); - R_EncodePEMBlock(encoded_key, &temp, - (u_char *)rsaref_private.modulus, - len); - encoded_key[temp] = '\0'; - fprintf(str, "%d %s\n", modulus, encoded_key); - } - if (str) fclose(str); - cleanlinks(f1_privatekey, f2_privatekey, f3_privatekey); - - /* - * Generate the file "ntpkey_host.*" containing the RSA - * public key in printable ASCII format. - */ - str = newfile(f1_publickey, f2_publickey, std_mask, - f3_publickey); - if (!memorex) { - len = sizeof(rsaref_public) - - sizeof(rsaref_public.bits); - modulus = (u_int32)rsaref_public.bits; - fprintf(str, "# RSA public key file %s\n# %s", - f2_publickey, ctime(&tv.tv_sec)); - R_EncodePEMBlock(encoded_key, &temp, - (u_char *)rsaref_public.modulus, len); - encoded_key[temp] = '\0'; - fprintf(str, "%d %s\n", modulus, encoded_key); - } - if (str) fclose(str); - cleanlinks(f1_publickey, f2_publickey, f3_publickey); - } -#endif /* PUBKEY */ - -#ifdef PUBKEY - if (make_dh && (force || !filep(f1_dhparms))) { - /* - * Roll the prime and generator for the Diffie-Hellman key - * agreement algorithm. - */ - printf("Generating Diffie-Hellman parameters (%d bits)...\n", - PRIMELEN); - str = newfile(f1_dhparms, f2_dhparms, std_mask, f3_dhparms); - - if (!memorex) { - R_RandomInit(&randomstr); - R_GetRandomBytesNeeded(&len, &randomstr); - for (i = 0; i < len; i++) { - temp = RANDOM; - R_RandomUpdate(&randomstr, (u_char *)&temp, 1); - } - - /* - * Generate the file "ntpkey_dh.*" containing the - * Diffie-Hellman prime and generator in printable - * ASCII format. - */ - len = DH_PRIME_LEN(PRIMELEN); - dh_params.prime = (u_char *)malloc(len); - dh_params.generator = (u_char *)malloc(len); - rval = R_GenerateDHParams(&dh_params, PRIMELEN, - PRIMELEN / 2, &randomstr); - if (rval) { - printf("R_GenerateDHParams error %x\n", rval); - return (-1); - } - - fprintf(str, - "# Diffie-Hellman parameter file %s\n# %s", - f2_dhparms, ctime(&tv.tv_sec)); - R_EncodePEMBlock(encoded_key, &temp, - (u_char *)dh_params.prime, - dh_params.primeLen); - encoded_key[temp] = '\0'; - fprintf(str, "%d %s\n", dh_params.primeLen, - encoded_key); - R_EncodePEMBlock(encoded_key, &temp, - (u_char *)dh_params.generator, - dh_params.generatorLen); - encoded_key[temp] = '\0'; - fprintf(str, "%d %s\n", dh_params.generatorLen, - encoded_key); - } - if (str) fclose(str); - cleanlinks(f1_dhparms, f2_dhparms, f3_dhparms); - } -#endif /* PUBKEY */ - - return (0); -} diff --git a/contrib/ntp/util/ntp-keygen.c b/contrib/ntp/util/ntp-keygen.c deleted file mode 100644 index 2d91652..0000000 --- a/contrib/ntp/util/ntp-keygen.c +++ /dev/null @@ -1,1998 +0,0 @@ -/* - * Program to generate cryptographic keys for NTP clients and servers - * - * This program generates files "ntpkey_<type>_<hostname>.<filestamp>", - * where <type> is the file type, <hostname> is the generating host and - * <filestamp> is the NTP seconds in decimal format. The NTP programs - * expect generic names such as "ntpkey_<type>_whimsy.udel.edu" with the - * association maintained by soft links. - * - * Files are prefixed with a header giving the name and date of creation - * followed by a type-specific descriptive label and PEM-encoded data - * string compatible with programs of the OpenSSL library. - * - * Note that private keys can be password encrypted as per OpenSSL - * conventions. - * - * The file types include - * - * ntpkey_MD5key_<hostname>.<filestamp> - * MD5 (128-bit) keys used to compute message digests in symmetric - * key cryptography - * - * ntpkey_RSAkey_<hostname>.<filestamp> - * ntpkey_host_<hostname> (RSA) link - * RSA private/public host key pair used for public key signatures - * and data encryption - * - * ntpkey_DSAkey_<hostname>.<filestamp> - * ntpkey_sign_<hostname> (RSA or DSA) link - * DSA private/public sign key pair used for public key signatures, - * but not data encryption - * - * ntpkey_IFFpar_<hostname>.<filestamp> - * ntpkey_iff_<hostname> (IFF server/client) link - * ntpkey_iffkey_<hostname> (IFF client) link - * Schnorr (IFF) server/client identity parameters - * - * ntpkey_IFFkey_<hostname>.<filestamp> - * Schnorr (IFF) client identity parameters - * - * ntpkey_GQpar_<hostname>.<filestamp>, - * ntpkey_gq_<hostname> (GQ) link - * Guillou-Quisquater (GQ) identity parameters - * - * ntpkey_MVpar_<hostname>.<filestamp>, - * Mu-Varadharajan (MV) server identity parameters - * - * ntpkey_MVkeyX_<hostname>.<filestamp>, - * ntpkey_mv_<hostname> (MV server) link - * ntpkey_mvkey_<hostname> (MV client) link - * Mu-Varadharajan (MV) client identity parameters - * - * ntpkey_XXXcert_<hostname>.<filestamp> - * ntpkey_cert_<hostname> (RSA or DSA) link - * X509v3 certificate using RSA or DSA public keys and signatures. - * XXX is a code identifying the message digest and signature - * encryption algorithm - * - * Available digest/signature schemes - * - * RSA: RSA-MD2, RSA-MD5, RSA-SHA, RSA-SHA1, RSA-MDC2, EVP-RIPEMD160 - * DSA: DSA-SHA, DSA-SHA1 - * - * Note: Once in a while because of some statistical fluke this program - * fails to generate and verify some cryptographic data, as indicated by - * exit status -1. In this case simply run the program again. If the - * program does complete with return code 0, the data are correct as - * verified. - * - * These cryptographic routines are characterized by the prime modulus - * size in bits. The default value of 512 bits is a compromise between - * cryptographic strength and computing time and is ordinarily - * considered adequate for this application. The routines have been - * tested with sizes of 256, 512, 1024 and 2048 bits. Not all message - * digest and signature encryption schemes work with sizes less than 512 - * bits. The computing time for sizes greater than 2048 bits is - * prohibitive on all but the fastest processors. An UltraSPARC Blade - * 1000 took something over nine minutes to generate and verify the - * values with size 2048. An old SPARC IPC would take a week. - * - * The OpenSSL library used by this program expects a random seed file. - * As described in the OpenSSL documentation, the file name defaults to - * first the RANDFILE environment variable in the user's home directory - * and then .rnd in the user's home directory. - */ -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif -#include <string.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/stat.h> -#include <sys/time.h> -#if HAVE_SYS_TYPES_H -# include <sys/types.h> -#endif -#include "ntp_types.h" -#include "l_stdlib.h" - -#ifdef SYS_WINNT -extern int ntp_getopt P((int, char **, const char *)); -#define getopt ntp_getopt -#define optarg ntp_optarg -#endif - -#ifdef OPENSSL -#include "openssl/bn.h" -#include "openssl/evp.h" -#include "openssl/err.h" -#include "openssl/rand.h" -#include "openssl/pem.h" -#include "openssl/x509v3.h" -#include <openssl/objects.h> -#endif /* OPENSSL */ - -/* - * Cryptodefines - */ -#define MD5KEYS 16 /* number of MD5 keys generated */ -#define JAN_1970 ULONG_CONST(2208988800) /* NTP seconds */ -#define YEAR ((long)60*60*24*365) /* one year in seconds */ -#define MAXFILENAME 256 /* max file name length */ -#define MAXHOSTNAME 256 /* max host name length */ -#ifdef OPENSSL -#define PLEN 512 /* default prime modulus size (bits) */ - -/* - * Strings used in X509v3 extension fields - */ -#define KEY_USAGE "digitalSignature,keyCertSign" -#define BASIC_CONSTRAINTS "critical,CA:TRUE" -#define EXT_KEY_PRIVATE "private" -#define EXT_KEY_TRUST "trustRoot" -#endif /* OPENSSL */ - -/* - * Prototypes - */ -FILE *fheader P((const char *, const char *)); -void fslink P((const char *, const char *)); -int gen_md5 P((char *)); -#ifdef OPENSSL -EVP_PKEY *gen_rsa P((char *)); -EVP_PKEY *gen_dsa P((char *)); -EVP_PKEY *gen_iff P((char *)); -EVP_PKEY *gen_gqpar P((char *)); -EVP_PKEY *gen_gqkey P((char *, EVP_PKEY *)); -EVP_PKEY *gen_mv P((char *)); -int x509 P((EVP_PKEY *, const EVP_MD *, char *, char *)); -void cb P((int, int, void *)); -EVP_PKEY *genkey P((char *, char *)); -u_long asn2ntp P((ASN1_TIME *)); -#endif /* OPENSSL */ - -/* - * Program variables - */ -extern char *optarg; /* command line argument */ -int debug = 0; /* debug, not de bug */ -int rval; /* return status */ -#ifdef OPENSSL -u_int modulus = PLEN; /* prime modulus size (bits) */ -#endif -int nkeys = 0; /* MV keys */ -time_t epoch; /* Unix epoch (seconds) since 1970 */ -char *hostname; /* host name (subject name) */ -char *trustname; /* trusted host name (issuer name) */ -char filename[MAXFILENAME + 1]; /* file name */ -char *passwd1 = NULL; /* input private key password */ -char *passwd2 = NULL; /* output private key password */ -#ifdef OPENSSL -long d0, d1, d2, d3; /* callback counters */ -#endif /* OPENSSL */ - -#ifdef SYS_WINNT -BOOL init_randfile(); - -/* - * Don't try to follow symbolic links - */ -int -readlink(char * link, char * file, int len) { - return (-1); -} -/* - * Don't try to create a symbolic link for now. - * Just move the file to the name you need. - */ -int -symlink(char *filename, char *linkname) { - DeleteFile(linkname); - MoveFile(filename, linkname); - return 0; -} -void -InitWin32Sockets() { - WORD wVersionRequested; - WSADATA wsaData; - wVersionRequested = MAKEWORD(2,0); - if (WSAStartup(wVersionRequested, &wsaData)) - { - fprintf(stderr, "No useable winsock.dll"); - exit(1); - } -} -#endif /* SYS_WINNT */ - -/* - * Main program - */ -int -main( - int argc, /* command line options */ - char **argv - ) -{ - struct timeval tv; /* initialization vector */ -#ifdef OPENSSL - X509 *cert = NULL; /* X509 certificate */ - EVP_PKEY *pkey_host = NULL; /* host key */ - EVP_PKEY *pkey_sign = NULL; /* sign key */ - EVP_PKEY *pkey_iff = NULL; /* IFF parameters */ - EVP_PKEY *pkey_gq = NULL; /* GQ parameters */ - EVP_PKEY *pkey_mv = NULL; /* MV parameters */ -#endif - int md5key = 0; /* generate MD5 keys */ -#ifdef OPENSSL - int hostkey = 0; /* generate RSA keys */ - int iffkey = 0; /* generate IFF parameters */ - int gqpar = 0; /* generate GQ parameters */ - int gqkey = 0; /* update GQ keys */ - int mvpar = 0; /* generate MV parameters */ - int mvkey = 0; /* update MV keys */ - char *sign = NULL; /* sign key */ - EVP_PKEY *pkey = NULL; /* temp key */ - const EVP_MD *ectx; /* EVP digest */ - char pathbuf[MAXFILENAME + 1]; - const char *scheme = NULL; /* digest/signature scheme */ - char *exten = NULL; /* private extension */ - char *grpkey = NULL; /* identity extension */ - int nid; /* X509 digest/signature scheme */ - FILE *fstr = NULL; /* file handle */ - int iffsw = 0; /* IFF key switch */ -#endif /* OPENSSL */ - char hostbuf[MAXHOSTNAME + 1]; - u_int temp; - -#ifdef SYS_WINNT - /* Initialize before OpenSSL checks */ - InitWin32Sockets(); - if(!init_randfile()) - fprintf(stderr, "Unable to initialize .rnd file\n"); -#endif - -#ifdef OPENSSL - if (SSLeay() != OPENSSL_VERSION_NUMBER) { - fprintf(stderr, - "OpenSSL version mismatch. Built against %lx, you have %lx\n", - OPENSSL_VERSION_NUMBER, SSLeay()); - return (-1); - - } else { - fprintf(stderr, - "Using OpenSSL version %lx\n", SSLeay()); - } -#endif /* OPENSSL */ - - /* - * Process options, initialize host name and timestamp. - */ - gethostname(hostbuf, MAXHOSTNAME); - hostname = hostbuf; -#ifdef OPENSSL - trustname = hostbuf; - passwd1 = hostbuf; -#endif -#ifndef SYS_WINNT - gettimeofday(&tv, 0); -#else - gettimeofday(&tv); -#endif - epoch = tv.tv_sec; - rval = 0; - while ((temp = getopt(argc, argv, -#ifdef OPENSSL - "c:deGgHIi:Mm:nPp:q:S:s:TV:v:" -#else - "dM" -#endif - )) != -1) { - switch(temp) { - -#ifdef OPENSSL - /* - * -c select public certificate type - */ - case 'c': - scheme = optarg; - continue; -#endif - - /* - * -d debug - */ - case 'd': - debug++; - continue; - -#ifdef OPENSSL - /* - * -e write identity keys - */ - case 'e': - iffsw++; - continue; -#endif - -#ifdef OPENSSL - /* - * -G generate GQ parameters and keys - */ - case 'G': - gqpar++; - continue; -#endif - -#ifdef OPENSSL - /* - * -g update GQ keys - */ - case 'g': - gqkey++; - continue; -#endif - -#ifdef OPENSSL - /* - * -H generate host key (RSA) - */ - case 'H': - hostkey++; - continue; -#endif - -#ifdef OPENSSL - /* - * -I generate IFF parameters - */ - case 'I': - iffkey++; - continue; -#endif - -#ifdef OPENSSL - /* - * -i set issuer name - */ - case 'i': - trustname = optarg; - continue; -#endif - - /* - * -M generate MD5 keys - */ - case 'M': - md5key++; - continue; - -#ifdef OPENSSL - /* - * -m select modulus (256-2048) - */ - case 'm': - if (sscanf(optarg, "%d", &modulus) != 1) - fprintf(stderr, - "invalid option -m %s\n", optarg); - continue; -#endif - -#ifdef OPENSSL - /* - * -P generate PC private certificate - */ - case 'P': - exten = EXT_KEY_PRIVATE; - continue; -#endif - -#ifdef OPENSSL - /* - * -p output private key password - */ - case 'p': - passwd2 = optarg; - continue; -#endif - -#ifdef OPENSSL - /* - * -q input private key password - */ - case 'q': - passwd1 = optarg; - continue; -#endif - -#ifdef OPENSSL - /* - * -S generate sign key (RSA or DSA) - */ - case 'S': - sign = optarg; - continue; -#endif - -#ifdef OPENSSL - /* - * -s set subject name - */ - case 's': - hostname = optarg; - continue; -#endif - -#ifdef OPENSSL - /* - * -T trusted certificate (TC scheme) - */ - case 'T': - exten = EXT_KEY_TRUST; - continue; -#endif - -#ifdef OPENSSL - /* - * -V <keys> generate MV parameters - */ - case 'V': - mvpar++; - if (sscanf(optarg, "%d", &nkeys) != 1) - fprintf(stderr, - "invalid option -V %s\n", optarg); - continue; -#endif - -#ifdef OPENSSL - /* - * -v <key> update MV keys - */ - case 'v': - mvkey++; - if (sscanf(optarg, "%d", &nkeys) != 1) - fprintf(stderr, - "invalid option -v %s\n", optarg); - continue; -#endif - - /* - * None of the above. - */ - default: - fprintf(stderr, "Option ignored\n"); - continue; - } - } - - if (passwd1 != NULL && passwd2 == NULL) - passwd2 = passwd1; -#ifdef OPENSSL - /* - * Seed random number generator and grow weeds. - */ - ERR_load_crypto_strings(); - OpenSSL_add_all_algorithms(); - if (RAND_file_name(pathbuf, MAXFILENAME) == NULL) { - fprintf(stderr, "RAND_file_name %s\n", - ERR_error_string(ERR_get_error(), NULL)); - return (-1); - } - temp = RAND_load_file(pathbuf, -1); - if (temp == 0) { - fprintf(stderr, - "RAND_load_file %s not found or empty\n", pathbuf); - return (-1); - } - fprintf(stderr, - "Random seed file %s %u bytes\n", pathbuf, temp); - RAND_add(&epoch, sizeof(epoch), 4.0); -#endif - - /* - * Generate new parameters and keys as requested. These replace - * any values already generated. - */ - if (md5key) - gen_md5("MD5"); -#ifdef OPENSSL - if (hostkey) - pkey_host = genkey("RSA", "host"); - if (sign != NULL) - pkey_sign = genkey(sign, "sign"); - if (iffkey) - pkey_iff = gen_iff("iff"); - if (gqpar) - pkey_gq = gen_gqpar("gq"); - if (mvpar) - pkey_mv = gen_mv("mv"); - - /* - * If there is no new host key, look for an existing one. If not - * found, create it. - */ - while (pkey_host == NULL && rval == 0 && !iffsw) { - sprintf(filename, "ntpkey_host_%s", hostname); - if ((fstr = fopen(filename, "r")) != NULL) { - pkey_host = PEM_read_PrivateKey(fstr, NULL, - NULL, passwd1); - fclose(fstr); - readlink(filename, filename, sizeof(filename)); - if (pkey_host == NULL) { - fprintf(stderr, "Host key\n%s\n", - ERR_error_string(ERR_get_error(), - NULL)); - rval = -1; - } else { - fprintf(stderr, - "Using host key %s\n", filename); - } - break; - - } else if ((pkey_host = genkey("RSA", "host")) == - NULL) { - rval = -1; - break; - } - } - - /* - * If there is no new sign key, look for an existing one. If not - * found, use the host key instead. - */ - pkey = pkey_sign; - while (pkey_sign == NULL && rval == 0 && !iffsw) { - sprintf(filename, "ntpkey_sign_%s", hostname); - if ((fstr = fopen(filename, "r")) != NULL) { - pkey_sign = PEM_read_PrivateKey(fstr, NULL, - NULL, passwd1); - fclose(fstr); - readlink(filename, filename, sizeof(filename)); - if (pkey_sign == NULL) { - fprintf(stderr, "Sign key\n%s\n", - ERR_error_string(ERR_get_error(), - NULL)); - rval = -1; - } else { - fprintf(stderr, "Using sign key %s\n", - filename); - } - break; - } else { - pkey = pkey_host; - fprintf(stderr, "Using host key as sign key\n"); - break; - } - } - - /* - * If there is no new IFF file, look for an existing one. - */ - if (pkey_iff == NULL && rval == 0) { - sprintf(filename, "ntpkey_iff_%s", hostname); - if ((fstr = fopen(filename, "r")) != NULL) { - pkey_iff = PEM_read_PrivateKey(fstr, NULL, - NULL, passwd1); - fclose(fstr); - readlink(filename, filename, sizeof(filename)); - if (pkey_iff == NULL) { - fprintf(stderr, "IFF parameters\n%s\n", - ERR_error_string(ERR_get_error(), - NULL)); - rval = -1; - } else { - fprintf(stderr, - "Using IFF parameters %s\n", - filename); - } - } - } - - /* - * If there is no new GQ file, look for an existing one. - */ - if (pkey_gq == NULL && rval == 0 && !iffsw) { - sprintf(filename, "ntpkey_gq_%s", hostname); - if ((fstr = fopen(filename, "r")) != NULL) { - pkey_gq = PEM_read_PrivateKey(fstr, NULL, NULL, - passwd1); - fclose(fstr); - readlink(filename, filename, sizeof(filename)); - if (pkey_gq == NULL) { - fprintf(stderr, "GQ parameters\n%s\n", - ERR_error_string(ERR_get_error(), - NULL)); - rval = -1; - } else { - fprintf(stderr, - "Using GQ parameters %s\n", - filename); - } - } - } - - /* - * If there is a GQ parameter file, create GQ private/public - * keys and extract the public key for the certificate. - */ - if (pkey_gq != NULL && rval == 0) { - gen_gqkey("gq", pkey_gq); - grpkey = BN_bn2hex(pkey_gq->pkey.rsa->q); - } - - /* - * Generate a X509v3 certificate. - */ - while (scheme == NULL && rval == 0 && !iffsw) { - sprintf(filename, "ntpkey_cert_%s", hostname); - if ((fstr = fopen(filename, "r")) != NULL) { - cert = PEM_read_X509(fstr, NULL, NULL, NULL); - fclose(fstr); - readlink(filename, filename, sizeof(filename)); - if (cert == NULL) { - fprintf(stderr, "Cert \n%s\n", - ERR_error_string(ERR_get_error(), - NULL)); - rval = -1; - } else { - nid = OBJ_obj2nid( - cert->cert_info->signature->algorithm); - scheme = OBJ_nid2sn(nid); - fprintf(stderr, - "Using scheme %s from %s\n", scheme, - filename); - break; - } - } - scheme = "RSA-MD5"; - } - if (pkey != NULL && rval == 0 && !iffsw) { - ectx = EVP_get_digestbyname(scheme); - if (ectx == NULL) { - fprintf(stderr, - "Invalid digest/signature combination %s\n", - scheme); - rval = -1; - } else { - x509(pkey, ectx, grpkey, exten); - } - } - - /* - * Write the IFF client parameters and keys as a DSA private key - * encoded in PEM. Note the private key is obscured. - */ - if (pkey_iff != NULL && rval == 0 && iffsw) { - DSA *dsa; - char *sptr; - - sptr = strrchr(filename, '.'); - sprintf(filename, "ntpkey_IFFkey_%s.%s", trustname, - ++sptr); - fprintf(stderr, "Writing new IFF key %s\n", filename); - fprintf(stdout, "# %s\n# %s", filename, ctime(&epoch)); - dsa = pkey_iff->pkey.dsa; - BN_copy(dsa->priv_key, BN_value_one()); - pkey = EVP_PKEY_new(); - EVP_PKEY_assign_DSA(pkey, dsa); - PEM_write_PrivateKey(stdout, pkey, passwd2 ? - EVP_des_cbc() : NULL, NULL, 0, NULL, passwd2); - fclose(stdout); - if (debug) - DSA_print_fp(stdout, dsa, 0); - } - - /* - * Return the marbles. - */ - if (grpkey != NULL) - OPENSSL_free(grpkey); - if (pkey_host != NULL) - EVP_PKEY_free(pkey_host); - if (pkey_sign != NULL) - EVP_PKEY_free(pkey_sign); - if (pkey_iff != NULL) - EVP_PKEY_free(pkey_iff); - if (pkey_gq != NULL) - EVP_PKEY_free(pkey_gq); - if (pkey_mv != NULL) - EVP_PKEY_free(pkey_mv); -#endif /* OPENSSL */ - return (rval); -} - - -#if 0 -/* - * Generate random MD5 key with password. - */ -int -gen_md5( - char *id /* file name id */ - ) -{ - BIGNUM *key; - BIGNUM *keyid; - FILE *str; - u_char bin[16]; - - fprintf(stderr, "Generating MD5 keys...\n"); - str = fheader("MD5key", hostname); - keyid = BN_new(); key = BN_new(); - BN_rand(keyid, 16, -1, 0); - BN_rand(key, 128, -1, 0); - BN_bn2bin(key, bin); - PEM_write_fp(str, MD5, NULL, bin); - fclose(str); - fslink(id, hostname); - return (1); -} - - -#else -/* - * Generate semi-random MD5 keys compatible with NTPv3 and NTPv4 - */ -int -gen_md5( - char *id /* file name id */ - ) -{ - u_char md5key[16]; /* MD5 key */ - FILE *str; - u_int temp = 0; /* Initialize to prevent warnings during compile */ - int i, j; - - fprintf(stderr, "Generating MD5 keys...\n"); - str = fheader("MD5key", hostname); - srandom(epoch); - for (i = 1; i <= MD5KEYS; i++) { - for (j = 0; j < 16; j++) { - while (1) { - temp = random() & 0xff; - if (temp == '#') - continue; - if (temp > 0x20 && temp < 0x7f) - break; - } - md5key[j] = (u_char)temp; - } - md5key[15] = '\0'; - fprintf(str, "%2d MD5 %16s # MD5 key\n", i, - md5key); - } - fclose(str); - fslink(id, hostname); - return (1); -} -#endif /* OPENSSL */ - - -#ifdef OPENSSL -/* - * Generate RSA public/private key pair - */ -EVP_PKEY * /* public/private key pair */ -gen_rsa( - char *id /* file name id */ - ) -{ - EVP_PKEY *pkey; /* private key */ - RSA *rsa; /* RSA parameters and key pair */ - FILE *str; - - fprintf(stderr, "Generating RSA keys (%d bits)...\n", modulus); - rsa = RSA_generate_key(modulus, 3, cb, "RSA"); - fprintf(stderr, "\n"); - if (rsa == NULL) { - fprintf(stderr, "RSA generate keys fails\n%s\n", - ERR_error_string(ERR_get_error(), NULL)); - rval = -1; - return (NULL); - } - - /* - * For signature encryption it is not necessary that the RSA - * parameters be strictly groomed and once in a while the - * modulus turns out to be non-prime. Just for grins, we check - * the primality. - */ - if (!RSA_check_key(rsa)) { - fprintf(stderr, "Invalid RSA key\n%s\n", - ERR_error_string(ERR_get_error(), NULL)); - RSA_free(rsa); - rval = -1; - return (NULL); - } - - /* - * Write the RSA parameters and keys as a RSA private key - * encoded in PEM. - */ - str = fheader("RSAkey", hostname); - pkey = EVP_PKEY_new(); - EVP_PKEY_assign_RSA(pkey, rsa); - PEM_write_PrivateKey(str, pkey, passwd2 ? EVP_des_cbc() : NULL, - NULL, 0, NULL, passwd2); - fclose(str); - if (debug) - RSA_print_fp(stdout, rsa, 0); - fslink(id, hostname); - return (pkey); -} - - -/* - * Generate DSA public/private key pair - */ -EVP_PKEY * /* public/private key pair */ -gen_dsa( - char *id /* file name id */ - ) -{ - EVP_PKEY *pkey; /* private key */ - DSA *dsa; /* DSA parameters */ - u_char seed[20]; /* seed for parameters */ - FILE *str; - - /* - * Generate DSA parameters. - */ - fprintf(stderr, - "Generating DSA parameters (%d bits)...\n", modulus); - RAND_bytes(seed, sizeof(seed)); - dsa = DSA_generate_parameters(modulus, seed, sizeof(seed), NULL, - NULL, cb, "DSA"); - fprintf(stderr, "\n"); - if (dsa == NULL) { - fprintf(stderr, "DSA generate parameters fails\n%s\n", - ERR_error_string(ERR_get_error(), NULL)); - rval = -1; - return (NULL); - } - - /* - * Generate DSA keys. - */ - fprintf(stderr, "Generating DSA keys (%d bits)...\n", modulus); - if (!DSA_generate_key(dsa)) { - fprintf(stderr, "DSA generate keys fails\n%s\n", - ERR_error_string(ERR_get_error(), NULL)); - DSA_free(dsa); - rval = -1; - return (NULL); - } - - /* - * Write the DSA parameters and keys as a DSA private key - * encoded in PEM. - */ - str = fheader("DSAkey", hostname); - pkey = EVP_PKEY_new(); - EVP_PKEY_assign_DSA(pkey, dsa); - PEM_write_PrivateKey(str, pkey, passwd2 ? EVP_des_cbc() : NULL, - NULL, 0, NULL, passwd2); - fclose(str); - if (debug) - DSA_print_fp(stdout, dsa, 0); - fslink(id, hostname); - return (pkey); -} - - -/* - * Generate Schnorr (IFF) parameters and keys - * - * The Schnorr (IFF)identity scheme is intended for use when - * certificates are generated by some other trusted certificate - * authority and the parameters cannot be conveyed in the certificate - * itself. For this purpose, new generations of IFF values must be - * securely transmitted to all members of the group before use. There - * are two kinds of files: server/client files that include private and - * public parameters and client files that include only public - * parameters. The scheme is self contained and independent of new - * generations of host keys, sign keys and certificates. - * - * The IFF values hide in a DSA cuckoo structure which uses the same - * parameters. The values are used by an identity scheme based on DSA - * cryptography and described in Stimson p. 285. The p is a 512-bit - * prime, g a generator of Zp* and q a 160-bit prime that divides p - 1 - * and is a qth root of 1 mod p; that is, g^q = 1 mod p. The TA rolls a - * private random group key b (0 < b < q), then computes public - * v = g^(q - a). All values except the group key are known to all group - * members; the group key is known to the group servers, but not the - * group clients. Alice challenges Bob to confirm identity using the - * protocol described below. - */ -EVP_PKEY * /* DSA cuckoo nest */ -gen_iff( - char *id /* file name id */ - ) -{ - EVP_PKEY *pkey; /* private key */ - DSA *dsa; /* DSA parameters */ - u_char seed[20]; /* seed for parameters */ - BN_CTX *ctx; /* BN working space */ - BIGNUM *b, *r, *k, *u, *v, *w; /* BN temp */ - FILE *str; - u_int temp; - - /* - * Generate DSA parameters for use as IFF parameters. - */ - fprintf(stderr, "Generating IFF parameters (%d bits)...\n", - modulus); - RAND_bytes(seed, sizeof(seed)); - dsa = DSA_generate_parameters(modulus, seed, sizeof(seed), NULL, - NULL, cb, "IFF"); - fprintf(stderr, "\n"); - if (dsa == NULL) { - fprintf(stderr, "DSA generate parameters fails\n%s\n", - ERR_error_string(ERR_get_error(), NULL)); - rval = -1; - return (NULL);; - } - - /* - * Generate the private and public keys. The DSA parameters and - * these keys are distributed to all members of the group. - */ - fprintf(stderr, "Generating IFF keys (%d bits)...\n", modulus); - b = BN_new(); r = BN_new(); k = BN_new(); - u = BN_new(); v = BN_new(); w = BN_new(); ctx = BN_CTX_new(); - BN_rand(b, BN_num_bits(dsa->q), -1, 0); /* a */ - BN_mod(b, b, dsa->q, ctx); - BN_sub(v, dsa->q, b); - BN_mod_exp(v, dsa->g, v, dsa->p, ctx); /* g^(q - b) mod p */ - BN_mod_exp(u, dsa->g, b, dsa->p, ctx); /* g^b mod p */ - BN_mod_mul(u, u, v, dsa->p, ctx); - temp = BN_is_one(u); - fprintf(stderr, - "Confirm g^(q - b) g^b = 1 mod p: %s\n", temp == 1 ? - "yes" : "no"); - if (!temp) { - BN_free(b); BN_free(r); BN_free(k); - BN_free(u); BN_free(v); BN_free(w); BN_CTX_free(ctx); - rval = -1; - return (NULL); - } - dsa->priv_key = BN_dup(b); /* private key */ - dsa->pub_key = BN_dup(v); /* public key */ - - /* - * Here is a trial round of the protocol. First, Alice rolls - * random r (0 < r < q) and sends it to Bob. She needs only - * modulus q. - */ - BN_rand(r, BN_num_bits(dsa->q), -1, 0); /* r */ - BN_mod(r, r, dsa->q, ctx); - - /* - * Bob rolls random k (0 < k < q), computes y = k + b r mod q - * and x = g^k mod p, then sends (y, x) to Alice. He needs - * moduli p, q and the group key b. - */ - BN_rand(k, BN_num_bits(dsa->q), -1, 0); /* k, 0 < k < q */ - BN_mod(k, k, dsa->q, ctx); - BN_mod_mul(v, dsa->priv_key, r, dsa->q, ctx); /* b r mod q */ - BN_add(v, v, k); - BN_mod(v, v, dsa->q, ctx); /* y = k + b r mod q */ - BN_mod_exp(u, dsa->g, k, dsa->p, ctx); /* x = g^k mod p */ - - /* - * Alice computes g^y v^r and verifies the result is equal to x. - * She needs modulus p, generator g, and the public key v, as - * well as her original r. - */ - BN_mod_exp(v, dsa->g, v, dsa->p, ctx); /* g^y mod p */ - BN_mod_exp(w, dsa->pub_key, r, dsa->p, ctx); /* v^r */ - BN_mod_mul(v, w, v, dsa->p, ctx); /* product mod p */ - temp = BN_cmp(u, v); - fprintf(stderr, - "Confirm g^k = g^(k + b r) g^(q - b) r: %s\n", temp == - 0 ? "yes" : "no"); - BN_free(b); BN_free(r); BN_free(k); - BN_free(u); BN_free(v); BN_free(w); BN_CTX_free(ctx); - if (temp != 0) { - DSA_free(dsa); - rval = -1; - return (NULL); - } - - /* - * Write the IFF server parameters and keys as a DSA private key - * encoded in PEM. - * - * p modulus p - * q modulus q - * g generator g - * priv_key b - * public_key v - */ - str = fheader("IFFpar", trustname); - pkey = EVP_PKEY_new(); - EVP_PKEY_assign_DSA(pkey, dsa); - PEM_write_PrivateKey(str, pkey, passwd2 ? EVP_des_cbc() : NULL, - NULL, 0, NULL, passwd2); - fclose(str); - if (debug) - DSA_print_fp(stdout, dsa, 0); - fslink(id, trustname); - return (pkey); -} - - -/* - * Generate Guillou-Quisquater (GQ) parameters and keys - * - * The Guillou-Quisquater (GQ) identity scheme is intended for use when - * the parameters, keys and certificates are generated by this program. - * The scheme uses a certificate extension field do convey the public - * key of a particular group identified by a group key known only to - * members of the group. The scheme is self contained and independent of - * new generations of host keys and sign keys. - * - * The GQ parameters hide in a RSA cuckoo structure which uses the same - * parameters. The values are used by an identity scheme based on RSA - * cryptography and described in Stimson p. 300 (with errors). The 512- - * bit public modulus is n = p q, where p and q are secret large primes. - * The TA rolls private random group key b as RSA exponent. These values - * are known to all group members. - * - * When rolling new certificates, a member recomputes the private and - * public keys. The private key u is a random roll, while the public key - * is the inverse obscured by the group key v = (u^-1)^b. These values - * replace the private and public keys normally generated by the RSA - * scheme. Alice challenges Bob to confirm identity using the protocol - * described below. - */ -EVP_PKEY * /* RSA cuckoo nest */ -gen_gqpar( - char *id /* file name id */ - ) -{ - EVP_PKEY *pkey; /* private key */ - RSA *rsa; /* GQ parameters */ - BN_CTX *ctx; /* BN working space */ - FILE *str; - - /* - * Generate RSA parameters for use as GQ parameters. - */ - fprintf(stderr, - "Generating GQ parameters (%d bits)...\n", modulus); - rsa = RSA_generate_key(modulus, 3, cb, "GQ"); - fprintf(stderr, "\n"); - if (rsa == NULL) { - fprintf(stderr, "RSA generate keys fails\n%s\n", - ERR_error_string(ERR_get_error(), NULL)); - rval = -1; - return (NULL); - } - - /* - * Generate the group key b, which is saved in the e member of - * the RSA structure. These values are distributed to all - * members of the group, but shielded from all other groups. We - * don't use all the parameters, but set the unused ones to a - * small number to minimize the file size. - */ - ctx = BN_CTX_new(); - BN_rand(rsa->e, BN_num_bits(rsa->n), -1, 0); /* b */ - BN_mod(rsa->e, rsa->e, rsa->n, ctx); - BN_copy(rsa->d, BN_value_one()); - BN_copy(rsa->p, BN_value_one()); - BN_copy(rsa->q, BN_value_one()); - BN_copy(rsa->dmp1, BN_value_one()); - BN_copy(rsa->dmq1, BN_value_one()); - BN_copy(rsa->iqmp, BN_value_one()); - - /* - * Write the GQ parameters as a RSA private key encoded in PEM. - * The public and private keys are filled in later. - * - * n modulus n - * e group key b - * (remaining values are not used) - */ - str = fheader("GQpar", trustname); - pkey = EVP_PKEY_new(); - EVP_PKEY_assign_RSA(pkey, rsa); - PEM_write_PrivateKey(str, pkey, passwd2 ? EVP_des_cbc() : NULL, - NULL, 0, NULL, passwd2); - fclose(str); - if (debug) - RSA_print_fp(stdout, rsa, 0); - fslink(id, trustname); - return (pkey); -} - - -/* - * Update Guillou-Quisquater (GQ) parameters - */ -EVP_PKEY * /* RSA cuckoo nest */ -gen_gqkey( - char *id, /* file name id */ - EVP_PKEY *gqpar /* GQ parameters */ - ) -{ - EVP_PKEY *pkey; /* private key */ - RSA *rsa; /* RSA parameters */ - BN_CTX *ctx; /* BN working space */ - BIGNUM *u, *v, *g, *k, *r, *y; /* BN temps */ - FILE *str; - u_int temp; - - /* - * Generate GQ keys. Note that the group key b is the e member - * of - * the GQ parameters. - */ - fprintf(stderr, "Updating GQ keys (%d bits)...\n", modulus); - ctx = BN_CTX_new(); u = BN_new(); v = BN_new(); - g = BN_new(); k = BN_new(); r = BN_new(); y = BN_new(); - - /* - * When generating his certificate, Bob rolls random private key - * u. - */ - rsa = gqpar->pkey.rsa; - BN_rand(u, BN_num_bits(rsa->n), -1, 0); /* u */ - BN_mod(u, u, rsa->n, ctx); - BN_mod_inverse(v, u, rsa->n, ctx); /* u^-1 mod n */ - BN_mod_mul(k, v, u, rsa->n, ctx); - - /* - * Bob computes public key v = (u^-1)^b, which is saved in an - * extension field on his certificate. We check that u^b v = - * 1 mod n. - */ - BN_mod_exp(v, v, rsa->e, rsa->n, ctx); - BN_mod_exp(g, u, rsa->e, rsa->n, ctx); /* u^b */ - BN_mod_mul(g, g, v, rsa->n, ctx); /* u^b (u^-1)^b */ - temp = BN_is_one(g); - fprintf(stderr, - "Confirm u^b (u^-1)^b = 1 mod n: %s\n", temp ? "yes" : - "no"); - if (!temp) { - BN_free(u); BN_free(v); - BN_free(g); BN_free(k); BN_free(r); BN_free(y); - BN_CTX_free(ctx); - RSA_free(rsa); - rval = -1; - return (NULL); - } - BN_copy(rsa->p, u); /* private key */ - BN_copy(rsa->q, v); /* public key */ - - /* - * Here is a trial run of the protocol. First, Alice rolls - * random r (0 < r < n) and sends it to Bob. She needs only - * modulus n from the parameters. - */ - BN_rand(r, BN_num_bits(rsa->n), -1, 0); /* r */ - BN_mod(r, r, rsa->n, ctx); - - /* - * Bob rolls random k (0 < k < n), computes y = k u^r mod n and - * g = k^b mod n, then sends (y, g) to Alice. He needs modulus n - * from the parameters and his private key u. - */ - BN_rand(k, BN_num_bits(rsa->n), -1, 0); /* k */ - BN_mod(k, k, rsa->n, ctx); - BN_mod_exp(y, rsa->p, r, rsa->n, ctx); /* u^r mod n */ - BN_mod_mul(y, k, y, rsa->n, ctx); /* y = k u^r mod n */ - BN_mod_exp(g, k, rsa->e, rsa->n, ctx); /* g = k^b mod n */ - - /* - * Alice computes v^r y^b mod n and verifies the result is equal - * to g. She needs modulus n, generator g and group key b from - * the parameters and Bob's public key v = (u^-1)^b from his - * certificate. - */ - BN_mod_exp(v, rsa->q, r, rsa->n, ctx); /* v^r mod n */ - BN_mod_exp(y, y, rsa->e, rsa->n, ctx); /* y^b mod n */ - BN_mod_mul(y, v, y, rsa->n, ctx); /* v^r y^b mod n */ - temp = BN_cmp(y, g); - fprintf(stderr, "Confirm g^k = v^r y^b mod n: %s\n", temp == 0 ? - "yes" : "no"); - BN_CTX_free(ctx); BN_free(u); BN_free(v); - BN_free(g); BN_free(k); BN_free(r); BN_free(y); - if (temp != 0) { - RSA_free(rsa); - rval = -1; - return (NULL); - } - - /* - * Write the GQ parameters and keys as a RSA private key encoded - * in PEM. - * - * n modulus n - * e group key b - * p private key u - * q public key (u^-1)^b - * (remaining values are not used) - */ - str = fheader("GQpar", trustname); - pkey = EVP_PKEY_new(); - EVP_PKEY_assign_RSA(pkey, rsa); - PEM_write_PrivateKey(str, pkey, passwd2 ? EVP_des_cbc() : NULL, - NULL, 0, NULL, passwd2); - fclose(str); - if (debug) - RSA_print_fp(stdout, rsa, 0); - fslink(id, trustname); - return (pkey); -} - - -/* - * Generate Mu-Varadharajan (MV) parameters and keys - * - * The Mu-Varadharajan (MV) cryptosystem is useful when servers - * broadcast messages to clients, but clients never send messages to - * servers. There is one encryption key for the server and a separate - * decryption key for each client. It operates something like a - * pay-per-view satellite broadcasting system where the session key is - * encrypted by the broadcaster and the decryption keys are held in a - * tamperproof set-top box. We don't use it this way, but read on. - * - * The MV parameters and private encryption key hide in a DSA cuckoo - * structure which uses the same parameters, but generated in a - * different way. The values are used in an encryption scheme similar to - * El Gamal cryptography and a polynomial formed from the expansion of - * product terms (x - x[j]), as described in Mu, Y., and V. - * Varadharajan: Robust and Secure Broadcasting, Proc. Indocrypt 2001, - * 223-231. The paper has significant errors and serious omissions. - * - * Let q be the product of n distinct primes s'[j] (j = 1...n), where - * each s'[j] has m significant bits. Let p be a prime p = 2 * q + 1, so - * that q and each s'[j] divide p - 1 and p has M = n * m + 1 - * significant bits. Let g be a generator of Zp; that is, gcd(g, p - 1) - * = 1 and g^q = 1 mod p. We do modular arithmetic over Zq and then - * project into Zp* as exponents of g. Sometimes we have to compute an - * inverse b^-1 of random b in Zq, but for that purpose we require - * gcd(b, q) = 1. We expect M to be in the 500-bit range and n - * relatively small, like 30. Associated with each s'[j] is an element - * s[j] such that s[j] s'[j] = s'[j] mod q. We find s[j] as the quotient - * (q + s'[j]) / s'[j]. These are the parameters of the scheme and they - * are expensive to compute. - * - * We set up an instance of the scheme as follows. A set of random - * values x[j] mod q (j = 1...n), are generated as the zeros of a - * polynomial of order n. The product terms (x - x[j]) are expanded to - * form coefficients a[i] mod q (i = 0...n) in powers of x. These are - * used as exponents of the generator g mod p to generate the private - * encryption key A. The pair (gbar, ghat) of public server keys and the - * pairs (xbar[j], xhat[j]) (j = 1...n) of private client keys are used - * to construct the decryption keys. The devil is in the details. - * - * This routine generates a private encryption file including the - * private encryption key E and public key (gbar, ghat). It then - * generates decryption files including the private key (xbar[j], - * xhat[j]) for each client. E is a permutation that encrypts a block - * y = E x. The jth client computes the inverse permutation E^-1 = - * gbar^xhat[j] ghat^xbar[j] and decrypts the block x = E^-1 y. - * - * The distinguishing characteristic of this scheme is the capability to - * revoke keys. Included in the calculation of E, gbar and ghat is the - * product s = prod(s'[j]) (j = 1...n) above. If the factor s'[j] is - * subsequently removed from the product and E, gbar and ghat - * recomputed, the jth client will no longer be able to compute E^-1 and - * thus unable to decrypt the block. - */ -EVP_PKEY * /* DSA cuckoo nest */ -gen_mv( - char *id /* file name id */ - ) -{ - EVP_PKEY *pkey, *pkey1; /* private key */ - DSA *dsa; /* DSA parameters */ - DSA *sdsa; /* DSA parameters */ - BN_CTX *ctx; /* BN working space */ - BIGNUM **x; /* polynomial zeros vector */ - BIGNUM **a; /* polynomial coefficient vector */ - BIGNUM **g; /* public key vector */ - BIGNUM **s, **s1; /* private enabling keys */ - BIGNUM **xbar, **xhat; /* private keys vector */ - BIGNUM *b; /* group key */ - BIGNUM *b1; /* inverse group key */ - BIGNUM *ss; /* enabling key */ - BIGNUM *biga; /* master encryption key */ - BIGNUM *bige; /* session encryption key */ - BIGNUM *gbar, *ghat; /* public key */ - BIGNUM *u, *v, *w; /* BN scratch */ - int i, j, n; - FILE *str; - u_int temp; - char ident[20]; - - /* - * Generate MV parameters. - * - * The object is to generate a multiplicative group Zp* modulo a - * prime p and a subset Zq mod q, where q is the product of n - * distinct primes s'[j] (j = 1...n) and q divides p - 1. We - * first generate n distinct primes, which may have to be - * regenerated later. As a practical matter, it is tough to find - * more than 31 distinct primes for modulus 512 or 61 primes for - * modulus 1024. The latter can take several hundred iterations - * and several minutes on a Sun Blade 1000. - */ - n = nkeys; - fprintf(stderr, - "Generating MV parameters for %d keys (%d bits)...\n", n, - modulus / n); - ctx = BN_CTX_new(); u = BN_new(); v = BN_new(); w = BN_new(); - b = BN_new(); b1 = BN_new(); - dsa = DSA_new(); - dsa->p = BN_new(); - dsa->q = BN_new(); - dsa->g = BN_new(); - s = malloc((n + 1) * sizeof(BIGNUM)); - s1 = malloc((n + 1) * sizeof(BIGNUM)); - for (j = 1; j <= n; j++) - s1[j] = BN_new(); - temp = 0; - for (j = 1; j <= n; j++) { - while (1) { - fprintf(stderr, "Birthdays %d\r", temp); - BN_generate_prime(s1[j], modulus / n, 0, NULL, - NULL, NULL, NULL); - for (i = 1; i < j; i++) { - if (BN_cmp(s1[i], s1[j]) == 0) - break; - } - if (i == j) - break; - temp++; - } - } - fprintf(stderr, "Birthday keys rejected %d\n", temp); - - /* - * Compute the modulus q as the product of the primes. Compute - * the modulus p as 2 * q + 1 and test p for primality. If p - * is composite, replace one of the primes with a new distinct - * one and try again. Note that q will hardly be a secret since - * we have to reveal p to servers and clients. However, - * factoring q to find the primes should be adequately hard, as - * this is the same problem considered hard in RSA. Question: is - * it as hard to find n small prime factors totalling n bits as - * it is to find two large prime factors totalling n bits? - * Remember, the bad guy doesn't know n. - */ - temp = 0; - while (1) { - fprintf(stderr, "Duplicate keys rejected %d\r", ++temp); - BN_one(dsa->q); - for (j = 1; j <= n; j++) - BN_mul(dsa->q, dsa->q, s1[j], ctx); - BN_copy(dsa->p, dsa->q); - BN_add(dsa->p, dsa->p, dsa->p); - BN_add_word(dsa->p, 1); - if (BN_is_prime(dsa->p, BN_prime_checks, NULL, ctx, - NULL)) - break; - - j = temp % n + 1; - while (1) { - BN_generate_prime(u, modulus / n, 0, 0, NULL, - NULL, NULL); - for (i = 1; i <= n; i++) { - if (BN_cmp(u, s1[i]) == 0) - break; - } - if (i > n) - break; - } - BN_copy(s1[j], u); - } - fprintf(stderr, "Duplicate keys rejected %d\n", temp); - - /* - * Compute the generator g using a random roll such that - * gcd(g, p - 1) = 1 and g^q = 1. This is a generator of p, not - * q. - */ - BN_copy(v, dsa->p); - BN_sub_word(v, 1); - while (1) { - BN_rand(dsa->g, BN_num_bits(dsa->p) - 1, 0, 0); - BN_mod(dsa->g, dsa->g, dsa->p, ctx); - BN_gcd(u, dsa->g, v, ctx); - if (!BN_is_one(u)) - continue; - - BN_mod_exp(u, dsa->g, dsa->q, dsa->p, ctx); - if (BN_is_one(u)) - break; - } - - /* - * Compute s[j] such that s[j] * s'[j] = s'[j] for all j. The - * easy way to do this is to compute q + s'[j] and divide the - * result by s'[j]. Exercise for the student: prove the - * remainder is always zero. - */ - for (j = 1; j <= n; j++) { - s[j] = BN_new(); - BN_add(s[j], dsa->q, s1[j]); - BN_div(s[j], u, s[j], s1[j], ctx); - } - - /* - * Setup is now complete. Roll random polynomial roots x[j] - * (0 < x[j] < q) for all j. While it may not be strictly - * necessary, Make sure each root has no factors in common with - * q. - */ - fprintf(stderr, - "Generating polynomial coefficients for %d roots (%d bits)\n", - n, BN_num_bits(dsa->q)); - x = malloc((n + 1) * sizeof(BIGNUM)); - for (j = 1; j <= n; j++) { - x[j] = BN_new(); - while (1) { - BN_rand(x[j], BN_num_bits(dsa->q), 0, 0); - BN_mod(x[j], x[j], dsa->q, ctx); - BN_gcd(u, x[j], dsa->q, ctx); - if (BN_is_one(u)) - break; - } - } - - /* - * Generate polynomial coefficients a[i] (i = 0...n) from the - * expansion of root products (x - x[j]) mod q for all j. The - * method is a present from Charlie Boncelet. - */ - a = malloc((n + 1) * sizeof(BIGNUM)); - for (i = 0; i <= n; i++) { - a[i] = BN_new(); - BN_one(a[i]); - } - for (j = 1; j <= n; j++) { - BN_zero(w); - for (i = 0; i < j; i++) { - BN_copy(u, dsa->q); - BN_mod_mul(v, a[i], x[j], dsa->q, ctx); - BN_sub(u, u, v); - BN_add(u, u, w); - BN_copy(w, a[i]); - BN_mod(a[i], u, dsa->q, ctx); - } - } - - /* - * Generate g[i] = g^a[i] mod p for all i and the generator g. - */ - fprintf(stderr, "Generating g[i] parameters\n"); - g = malloc((n + 1) * sizeof(BIGNUM)); - for (i = 0; i <= n; i++) { - g[i] = BN_new(); - BN_mod_exp(g[i], dsa->g, a[i], dsa->p, ctx); - } - - /* - * Verify prod(g[i]^(a[i] x[j]^i)) = 1 for all i, j; otherwise, - * exit. Note the a[i] x[j]^i exponent is computed mod q, but - * the g[i] is computed mod p. also note the expression given in - * the paper is incorrect. - */ - temp = 1; - for (j = 1; j <= n; j++) { - BN_one(u); - for (i = 0; i <= n; i++) { - BN_set_word(v, i); - BN_mod_exp(v, x[j], v, dsa->q, ctx); - BN_mod_mul(v, v, a[i], dsa->q, ctx); - BN_mod_exp(v, dsa->g, v, dsa->p, ctx); - BN_mod_mul(u, u, v, dsa->p, ctx); - } - if (!BN_is_one(u)) - temp = 0; - } - fprintf(stderr, - "Confirm prod(g[i]^(x[j]^i)) = 1 for all i, j: %s\n", temp ? - "yes" : "no"); - if (!temp) { - rval = -1; - return (NULL); - } - - /* - * Make private encryption key A. Keep it around for awhile, - * since it is expensive to compute. - */ - biga = BN_new(); - BN_one(biga); - for (j = 1; j <= n; j++) { - for (i = 0; i < n; i++) { - BN_set_word(v, i); - BN_mod_exp(v, x[j], v, dsa->q, ctx); - BN_mod_exp(v, g[i], v, dsa->p, ctx); - BN_mod_mul(biga, biga, v, dsa->p, ctx); - } - } - - /* - * Roll private random group key b mod q (0 < b < q), where - * gcd(b, q) = 1 to guarantee b^1 exists, then compute b^-1 - * mod q. If b is changed, the client keys must be recomputed. - */ - while (1) { - BN_rand(b, BN_num_bits(dsa->q), 0, 0); - BN_mod(b, b, dsa->q, ctx); - BN_gcd(u, b, dsa->q, ctx); - if (BN_is_one(u)) - break; - } - BN_mod_inverse(b1, b, dsa->q, ctx); - - /* - * Make private client keys (xbar[j], xhat[j]) for all j. Note - * that the keys for the jth client involve s[j], but not s'[j] - * or the product s = prod(s'[j]) mod q, which is the enabling - * key. - */ - xbar = malloc((n + 1) * sizeof(BIGNUM)); - xhat = malloc((n + 1) * sizeof(BIGNUM)); - for (j = 1; j <= n; j++) { - xbar[j] = BN_new(); xhat[j] = BN_new(); - BN_zero(xbar[j]); - BN_set_word(v, n); - for (i = 1; i <= n; i++) { - if (i == j) - continue; - BN_mod_exp(u, x[i], v, dsa->q, ctx); - BN_add(xbar[j], xbar[j], u); - } - BN_mod_mul(xbar[j], xbar[j], b1, dsa->q, ctx); - BN_mod_exp(xhat[j], x[j], v, dsa->q, ctx); - BN_mod_mul(xhat[j], xhat[j], s[j], dsa->q, ctx); - } - - /* - * The enabling key is initially q by construction. We can - * revoke client j by dividing q by s'[j]. The quotient becomes - * the enabling key s. Note we always have to revoke one key; - * otherwise, the plaintext and cryptotext would be identical. - */ - ss = BN_new(); - BN_copy(ss, dsa->q); - BN_div(ss, u, dsa->q, s1[n], ctx); - - /* - * Make private server encryption key E = A^s and public server - * keys gbar = g^s mod p and ghat = g^(s b) mod p. The (gbar, - * ghat) is the public key provided to the server, which uses it - * to compute the session encryption key and public key included - * in its messages. These values must be regenerated if the - * enabling key is changed. - */ - bige = BN_new(); gbar = BN_new(); ghat = BN_new(); - BN_mod_exp(bige, biga, ss, dsa->p, ctx); - BN_mod_exp(gbar, dsa->g, ss, dsa->p, ctx); - BN_mod_mul(v, ss, b, dsa->q, ctx); - BN_mod_exp(ghat, dsa->g, v, dsa->p, ctx); - - /* - * We produce the key media in three steps. The first step is to - * generate the private values that do not depend on the - * enabling key. These include the server values p, q, g, b, A - * and the client values s'[j], xbar[j] and xhat[j] for each j. - * The p, xbar[j] and xhat[j] values are encoded in private - * files which are distributed to respective clients. The p, q, - * g, A and s'[j] values (will be) written to a secret file to - * be read back later. - * - * The secret file (will be) read back at some later time to - * enable/disable individual keys and generate/regenerate the - * enabling key s. The p, q, E, gbar and ghat values are written - * to a secret file to be read back later by the server. - * - * The server reads the secret file and rolls the session key - * k, which is used only once, then computes E^k, gbar^k and - * ghat^k. The E^k is the session encryption key. The encrypted - * data, gbar^k and ghat^k are transmtted to clients in an - * extension field. The client receives the message and computes - * x = (gbar^k)^xbar[j] (ghat^k)^xhat[j], finds the session - * encryption key E^k as the inverse x^-1 and decrypts the data. - */ - BN_copy(dsa->g, bige); - dsa->priv_key = BN_dup(gbar); - dsa->pub_key = BN_dup(ghat); - - /* - * Write the MV server parameters and keys as a DSA private key - * encoded in PEM. - * - * p modulus p - * q modulus q (used only to generate k) - * g E mod p - * priv_key gbar mod p - * pub_key ghat mod p - */ - str = fheader("MVpar", trustname); - pkey = EVP_PKEY_new(); - EVP_PKEY_assign_DSA(pkey, dsa); - PEM_write_PrivateKey(str, pkey, passwd2 ? EVP_des_cbc() : NULL, - NULL, 0, NULL, passwd2); - fclose(str); - if (debug) - DSA_print_fp(stdout, dsa, 0); - fslink(id, trustname); - - /* - * Write the parameters and private key (xbar[j], xhat[j]) for - * all j as a DSA private key encoded in PEM. It is used only by - * the designated recipient(s) who pay a suitably outrageous fee - * for its use. - */ - sdsa = DSA_new(); - sdsa->p = BN_dup(dsa->p); - sdsa->q = BN_dup(BN_value_one()); - sdsa->g = BN_dup(BN_value_one()); - sdsa->priv_key = BN_new(); - sdsa->pub_key = BN_new(); - for (j = 1; j <= n; j++) { - BN_copy(sdsa->priv_key, xbar[j]); - BN_copy(sdsa->pub_key, xhat[j]); - BN_mod_exp(v, dsa->priv_key, sdsa->pub_key, dsa->p, - ctx); - BN_mod_exp(u, dsa->pub_key, sdsa->priv_key, dsa->p, - ctx); - BN_mod_mul(u, u, v, dsa->p, ctx); - BN_mod_mul(u, u, dsa->g, dsa->p, ctx); - BN_free(xbar[j]); BN_free(xhat[j]); - BN_free(x[j]); BN_free(s[j]); BN_free(s1[j]); - if (!BN_is_one(u)) { - fprintf(stderr, "Revoke key %d\n", j); - continue; - } - - /* - * Write the client parameters as a DSA private key - * encoded in PEM. We don't make links for these. - * - * p modulus p - * priv_key xbar[j] mod q - * pub_key xhat[j] mod q - * (remaining values are not used) - */ - sprintf(ident, "MVkey%d", j); - str = fheader(ident, trustname); - pkey1 = EVP_PKEY_new(); - EVP_PKEY_set1_DSA(pkey1, sdsa); - PEM_write_PrivateKey(str, pkey1, passwd2 ? - EVP_des_cbc() : NULL, NULL, 0, NULL, passwd2); - fclose(str); - fprintf(stderr, "ntpkey_%s_%s.%lu\n", ident, trustname, - epoch + JAN_1970); - if (debug) - DSA_print_fp(stdout, sdsa, 0); - EVP_PKEY_free(pkey1); - } - - /* - * Free the countries. - */ - for (i = 0; i <= n; i++) { - BN_free(a[i]); - BN_free(g[i]); - } - BN_free(u); BN_free(v); BN_free(w); BN_CTX_free(ctx); - BN_free(b); BN_free(b1); BN_free(biga); BN_free(bige); - BN_free(ss); BN_free(gbar); BN_free(ghat); - DSA_free(sdsa); - - /* - * Free the world. - */ - free(x); free(a); free(g); free(s); free(s1); - free(xbar); free(xhat); - return (pkey); -} - - -/* - * Generate X509v3 scertificate. - * - * The certificate consists of the version number, serial number, - * validity interval, issuer name, subject name and public key. For a - * self-signed certificate, the issuer name is the same as the subject - * name and these items are signed using the subject private key. The - * validity interval extends from the current time to the same time one - * year hence. For NTP purposes, it is convenient to use the NTP seconds - * of the current time as the serial number. - */ -int -x509 ( - EVP_PKEY *pkey, /* generic signature algorithm */ - const EVP_MD *md, /* generic digest algorithm */ - char *gqpub, /* identity extension (hex string) */ - char *exten /* private cert extension */ - ) -{ - X509 *cert; /* X509 certificate */ - X509_NAME *subj; /* distinguished (common) name */ - X509_EXTENSION *ex; /* X509v3 extension */ - FILE *str; /* file handle */ - ASN1_INTEGER *serial; /* serial number */ - const char *id; /* digest/signature scheme name */ - char pathbuf[MAXFILENAME + 1]; - - /* - * Generate X509 self-signed certificate. - * - * Set the certificate serial to the NTP seconds for grins. Set - * the version to 3. Set the subject name and issuer name to the - * subject name in the request. Set the initial validity to the - * current time and the final validity one year hence. - */ - id = OBJ_nid2sn(md->pkey_type); - fprintf(stderr, "Generating certificate %s\n", id); - cert = X509_new(); - X509_set_version(cert, 2L); - serial = ASN1_INTEGER_new(); - ASN1_INTEGER_set(serial, epoch + JAN_1970); - X509_set_serialNumber(cert, serial); - ASN1_INTEGER_free(serial); - X509_gmtime_adj(X509_get_notBefore(cert), 0L); - X509_gmtime_adj(X509_get_notAfter(cert), YEAR); - subj = X509_get_subject_name(cert); - X509_NAME_add_entry_by_txt(subj, "commonName", MBSTRING_ASC, - (unsigned char *) hostname, strlen(hostname), -1, 0); - subj = X509_get_issuer_name(cert); - X509_NAME_add_entry_by_txt(subj, "commonName", MBSTRING_ASC, - (unsigned char *) trustname, strlen(trustname), -1, 0); - if (!X509_set_pubkey(cert, pkey)) { - fprintf(stderr, "Assign key fails\n%s\n", - ERR_error_string(ERR_get_error(), NULL)); - X509_free(cert); - rval = -1; - return (0); - } - - /* - * Add X509v3 extensions if present. These represent the minimum - * set defined in RFC3280 less the certificate_policy extension, - * which is seriously obfuscated in OpenSSL. - */ - /* - * The basic_constraints extension CA:TRUE allows servers to - * sign client certficitates. - */ - fprintf(stderr, "%s: %s\n", LN_basic_constraints, - BASIC_CONSTRAINTS); - ex = X509V3_EXT_conf_nid(NULL, NULL, NID_basic_constraints, - BASIC_CONSTRAINTS); - if (!X509_add_ext(cert, ex, -1)) { - fprintf(stderr, "Add extension field fails\n%s\n", - ERR_error_string(ERR_get_error(), NULL)); - rval = -1; - return (0); - } - X509_EXTENSION_free(ex); - - /* - * The key_usage extension designates the purposes the key can - * be used for. - */ - fprintf(stderr, "%s: %s\n", LN_key_usage, KEY_USAGE); - ex = X509V3_EXT_conf_nid(NULL, NULL, NID_key_usage, KEY_USAGE); - if (!X509_add_ext(cert, ex, -1)) { - fprintf(stderr, "Add extension field fails\n%s\n", - ERR_error_string(ERR_get_error(), NULL)); - rval = -1; - return (0); - } - X509_EXTENSION_free(ex); - /* - * The subject_key_identifier is used for the GQ public key. - * This should not be controversial. - */ - if (gqpub != NULL) { - fprintf(stderr, "%s\n", LN_subject_key_identifier); - ex = X509V3_EXT_conf_nid(NULL, NULL, - NID_subject_key_identifier, gqpub); - if (!X509_add_ext(cert, ex, -1)) { - fprintf(stderr, - "Add extension field fails\n%s\n", - ERR_error_string(ERR_get_error(), NULL)); - rval = -1; - return (0); - } - X509_EXTENSION_free(ex); - } - - /* - * The extended key usage extension is used for special purpose - * here. The semantics probably do not conform to the designer's - * intent and will likely change in future. - * - * "trustRoot" designates a root authority - * "private" designates a private certificate - */ - if (exten != NULL) { - fprintf(stderr, "%s: %s\n", LN_ext_key_usage, exten); - ex = X509V3_EXT_conf_nid(NULL, NULL, - NID_ext_key_usage, exten); - if (!X509_add_ext(cert, ex, -1)) { - fprintf(stderr, - "Add extension field fails\n%s\n", - ERR_error_string(ERR_get_error(), NULL)); - rval = -1; - return (0); - } - X509_EXTENSION_free(ex); - } - - /* - * Sign and verify. - */ - X509_sign(cert, pkey, md); - if (!X509_verify(cert, pkey)) { - fprintf(stderr, "Verify %s certificate fails\n%s\n", id, - ERR_error_string(ERR_get_error(), NULL)); - X509_free(cert); - rval = -1; - return (0); - } - - /* - * Write the certificate encoded in PEM. - */ - sprintf(pathbuf, "%scert", id); - str = fheader(pathbuf, hostname); - PEM_write_X509(str, cert); - fclose(str); - if (debug) - X509_print_fp(stdout, cert); - X509_free(cert); - fslink("cert", hostname); - return (1); -} - -#if 0 /* asn2ntp is not used */ -/* - * asn2ntp - convert ASN1_TIME time structure to NTP time - */ -u_long -asn2ntp ( - ASN1_TIME *asn1time /* pointer to ASN1_TIME structure */ - ) -{ - char *v; /* pointer to ASN1_TIME string */ - struct tm tm; /* time decode structure time */ - - /* - * Extract time string YYMMDDHHMMSSZ from ASN.1 time structure. - * Note that the YY, MM, DD fields start with one, the HH, MM, - * SS fiels start with zero and the Z character should be 'Z' - * for UTC. Also note that years less than 50 map to years - * greater than 100. Dontcha love ASN.1? - */ - if (asn1time->length > 13) - return (-1); - v = (char *)asn1time->data; - tm.tm_year = (v[0] - '0') * 10 + v[1] - '0'; - if (tm.tm_year < 50) - tm.tm_year += 100; - tm.tm_mon = (v[2] - '0') * 10 + v[3] - '0' - 1; - tm.tm_mday = (v[4] - '0') * 10 + v[5] - '0'; - tm.tm_hour = (v[6] - '0') * 10 + v[7] - '0'; - tm.tm_min = (v[8] - '0') * 10 + v[9] - '0'; - tm.tm_sec = (v[10] - '0') * 10 + v[11] - '0'; - tm.tm_wday = 0; - tm.tm_yday = 0; - tm.tm_isdst = 0; - return (mktime(&tm) + JAN_1970); -} -#endif - -/* - * Callback routine - */ -void -cb ( - int n1, /* arg 1 */ - int n2, /* arg 2 */ - void *chr /* arg 3 */ - ) -{ - switch (n1) { - case 0: - d0++; - fprintf(stderr, "%s %d %d %lu\r", (char *)chr, n1, n2, - d0); - break; - case 1: - d1++; - fprintf(stderr, "%s\t\t%d %d %lu\r", (char *)chr, n1, - n2, d1); - break; - case 2: - d2++; - fprintf(stderr, "%s\t\t\t\t%d %d %lu\r", (char *)chr, - n1, n2, d2); - break; - case 3: - d3++; - fprintf(stderr, "%s\t\t\t\t\t\t%d %d %lu\r", - (char *)chr, n1, n2, d3); - break; - } -} - - -/* - * Generate key - */ -EVP_PKEY * /* public/private key pair */ -genkey( - char *type, /* key type (RSA or DSA) */ - char *id /* file name id */ - ) -{ - if (type == NULL) - return (NULL); - if (strcmp(type, "RSA") == 0) - return (gen_rsa(id)); - - else if (strcmp(type, "DSA") == 0) - return (gen_dsa(id)); - - fprintf(stderr, "Invalid %s key type %s\n", id, type); - rval = -1; - return (NULL); -} -#endif /* OPENSSL */ - - -/* - * Generate file header - */ -FILE * -fheader ( - const char *id, /* file name id */ - const char *name /* owner name */ - ) -{ - FILE *str; /* file handle */ - - sprintf(filename, "ntpkey_%s_%s.%lu", id, name, epoch + - JAN_1970); - if ((str = fopen(filename, "w")) == NULL) { - perror("Write"); - exit (-1); - } - fprintf(str, "# %s\n# %s", filename, ctime(&epoch)); - return (str); -} - - -/* - * Generate symbolic links - */ -void -fslink( - const char *id, /* file name id */ - const char *name /* owner name */ - ) -{ - char linkname[MAXFILENAME]; /* link name */ - int temp; - - sprintf(linkname, "ntpkey_%s_%s", id, name); - remove(linkname); - temp = symlink(filename, linkname); - if (temp < 0) - perror(id); - fprintf(stderr, "Generating new %s file and link\n", id); - fprintf(stderr, "%s->%s\n", linkname, filename); -} diff --git a/contrib/ntp/util/ntptime.c b/contrib/ntp/util/ntptime.c deleted file mode 100644 index 51111be..0000000 --- a/contrib/ntp/util/ntptime.c +++ /dev/null @@ -1,440 +0,0 @@ -/* - * NTP test program - * - * This program tests to see if the NTP user interface routines - * ntp_gettime() and ntp_adjtime() have been implemented in the kernel. - * If so, each of these routines is called to display current timekeeping - * data. - * - * For more information, see the README.kern file in the doc directory - * of the xntp3 distribution. - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif /* HAVE_CONFIG_H */ - -#include "ntp_fp.h" -#include "ntp_unixtime.h" -#include "ntp_syscall.h" -#include "ntp_stdlib.h" - -#include <stdio.h> -#include <ctype.h> -#include <signal.h> -#include <setjmp.h> - -#ifdef NTP_SYSCALLS_STD -# ifndef SYS_DECOSF1 -# define BADCALL -1 /* this is supposed to be a bad syscall */ -# endif /* SYS_DECOSF1 */ -#endif - -#ifdef HAVE_STRUCT_NTPTIMEVAL_TIME_TV_NSEC -#define tv_frac_sec tv_nsec -#else -#define tv_frac_sec tv_usec -#endif - - -#define TIMEX_MOD_BITS \ -"\20\1OFFSET\2FREQUENCY\3MAXERROR\4ESTERROR\5STATUS\6TIMECONST\ -\13PLL\14FLL\15MICRO\16NANO\17CLKB\20CLKA" - -#define TIMEX_STA_BITS \ -"\20\1PLL\2PPSFREQ\3PPSTIME\4FLL\5INS\6DEL\7UNSYNC\10FREQHOLD\ -\11PPSSIGNAL\12PPSJITTER\13PPSWANDER\14PPSERROR\15CLOCKERR\ -\16NANO\17MODE\20CLK" - -#define SCALE_FREQ 65536 /* frequency scale */ - - -/* - * Function prototypes - */ -char *sprintb P((u_int, const char *)); -const char *timex_state P((int)); - -#ifdef SIGSYS -void pll_trap P((int)); - -static struct sigaction newsigsys; /* new sigaction status */ -static struct sigaction sigsys; /* current sigaction status */ -static sigjmp_buf env; /* environment var. for pll_trap() */ -#endif - -static volatile int pll_control; /* (0) daemon, (1) kernel loop */ -static volatile int status; /* most recent status bits */ -static volatile int flash; /* most recent ntp_adjtime() bits */ -char* progname; -static char optargs[] = "MNT:cde:f:hm:o:rs:t:"; - -int -main( - int argc, - char *argv[] - ) -{ - extern int ntp_optind; - extern char *ntp_optarg; -#ifdef SUBST_ADJTIMEX - struct timex ntv; -#else - struct ntptimeval ntv; -#endif - struct timeval tv; - struct timex ntx, _ntx; - int times[20]; - double ftemp, gtemp, htemp; - long time_frac; /* ntv.time.tv_frac_sec (us/ns) */ - l_fp ts; - volatile unsigned ts_mask = TS_MASK; /* defaults to 20 bits (us) */ - volatile unsigned ts_roundbit = TS_ROUNDBIT; /* defaults to 20 bits (us) */ - volatile int fdigits = 6; /* fractional digits for us */ - int c; - int errflg = 0; - int cost = 0; - volatile int rawtime = 0; - - memset((char *)&ntx, 0, sizeof(ntx)); - progname = argv[0]; - while ((c = ntp_getopt(argc, argv, optargs)) != EOF) switch (c) { -#ifdef MOD_MICRO - case 'M': - ntx.modes |= MOD_MICRO; - break; -#endif -#ifdef MOD_NANO - case 'N': - ntx.modes |= MOD_NANO; - break; -#endif -#ifdef NTP_API -# if NTP_API > 3 - case 'T': - ntx.modes = MOD_TAI; - ntx.constant = atoi(ntp_optarg); - break; -# endif -#endif - case 'c': - cost++; - break; - case 'e': - ntx.modes |= MOD_ESTERROR; - ntx.esterror = atoi(ntp_optarg); - break; - case 'f': - ntx.modes |= MOD_FREQUENCY; - ntx.freq = (long)(atof(ntp_optarg) * SCALE_FREQ); - break; - case 'm': - ntx.modes |= MOD_MAXERROR; - ntx.maxerror = atoi(ntp_optarg); - break; - case 'o': - ntx.modes |= MOD_OFFSET; - ntx.offset = atoi(ntp_optarg); - break; - case 'r': - rawtime++; - break; - case 's': - ntx.modes |= MOD_STATUS; - ntx.status = atoi(ntp_optarg); - if (ntx.status < 0 || ntx.status >= 0x100) errflg++; - break; - case 't': - ntx.modes |= MOD_TIMECONST; - ntx.constant = atoi(ntp_optarg); - break; - default: - errflg++; - } - if (errflg || (ntp_optind != argc)) { - (void) fprintf(stderr, - "usage: %s [-%s]\n\n\ -%s%s%s\ --c display the time taken to call ntp_gettime (us)\n\ --e esterror estimate of the error (us)\n\ --f frequency Frequency error (-500 .. 500) (ppm)\n\ --h display this help info\n\ --m maxerror max possible error (us)\n\ --o offset current offset (ms)\n\ --r print the unix and NTP time raw\n\ --s status Set the status bits\n\ --t timeconstant log2 of PLL time constant (0 .. %d)\n", - progname, optargs, -#ifdef MOD_MICRO -"-M switch to microsecond mode\n", -#else -"", -#endif -#ifdef MOD_NANO -"-N switch to nanosecond mode\n", -#else -"", -#endif -#ifdef NTP_API -# if NTP_API > 3 -"-T tai_offset set TAI offset\n", -# else -"", -# endif -#else -"", -#endif - MAXTC); - exit(2); - } - -#ifdef SIGSYS - /* - * Test to make sure the sigaction() works in case of invalid - * syscall codes. - */ - newsigsys.sa_handler = pll_trap; - newsigsys.sa_flags = 0; - if (sigaction(SIGSYS, &newsigsys, &sigsys)) { - perror("sigaction() fails to save SIGSYS trap"); - exit(1); - } -#endif /* SIGSYS */ - -#ifdef BADCALL - /* - * Make sure the trapcatcher works. - */ - pll_control = 1; -#ifdef SIGSYS - if (sigsetjmp(env, 1) == 0) - { -#endif - status = syscall(BADCALL, &ntv); /* dummy parameter */ - if ((status < 0) && (errno == ENOSYS)) - --pll_control; -#ifdef SIGSYS - } -#endif - if (pll_control) - printf("sigaction() failed to catch an invalid syscall\n"); -#endif /* BADCALL */ - - if (cost) { -#ifdef SIGSYS - if (sigsetjmp(env, 1) == 0) { -#endif - for (c = 0; c < sizeof times / sizeof times[0]; c++) { - status = ntp_gettime(&ntv); - if ((status < 0) && (errno == ENOSYS)) - --pll_control; - if (pll_control < 0) - break; - times[c] = ntv.time.tv_frac_sec; - } -#ifdef SIGSYS - } -#endif - if (pll_control >= 0) { - printf("[ us %06d:", times[0]); - for (c = 1; c < sizeof times / sizeof times[0]; c++) - printf(" %d", times[c] - times[c - 1]); - printf(" ]\n"); - } - } -#ifdef SIGSYS - if (sigsetjmp(env, 1) == 0) { -#endif - status = ntp_gettime(&ntv); - if ((status < 0) && (errno == ENOSYS)) - --pll_control; -#ifdef SIGSYS - } -#endif - _ntx.modes = 0; /* Ensure nothing is set */ -#ifdef SIGSYS - if (sigsetjmp(env, 1) == 0) { -#endif - status = ntp_adjtime(&_ntx); - if ((status < 0) && (errno == ENOSYS)) - --pll_control; - flash = _ntx.status; -#ifdef SIGSYS - } -#endif - if (pll_control < 0) { - printf("NTP user interface routines are not configured in this kernel.\n"); - goto lexit; - } - - /* - * Fetch timekeeping data and display. - */ - status = ntp_gettime(&ntv); - if (status < 0) - perror("ntp_gettime() call fails"); - else { - printf("ntp_gettime() returns code %d (%s)\n", - status, timex_state(status)); - time_frac = ntv.time.tv_frac_sec; -#ifdef STA_NANO - if (flash & STA_NANO) { - ntv.time.tv_frac_sec /= 1000; - ts_mask = 0xfffffffc; /* 1/2^30 */ - ts_roundbit = 0x00000002; - fdigits = 9; - } -#endif - tv.tv_sec = ntv.time.tv_sec; - tv.tv_usec = ntv.time.tv_frac_sec; - TVTOTS(&tv, &ts); - ts.l_ui += JAN_1970; - ts.l_uf += ts_roundbit; - ts.l_uf &= ts_mask; - printf(" time %s, (.%0*d),\n", - prettydate(&ts), fdigits, (int) time_frac); - printf(" maximum error %lu us, estimated error %lu us", - (u_long)ntv.maxerror, (u_long)ntv.esterror); - if (rawtime) - printf(" ntptime=%x.%x unixtime=%x.%0*d %s", - (unsigned int) ts.l_ui, (unsigned int) ts.l_uf, - (int) ntv.time.tv_sec, fdigits, (int) time_frac, - ctime((const time_t *) &ntv.time.tv_sec)); -#if NTP_API > 3 - printf(", TAI offset %ld\n", (long)ntv.tai); -#else - printf("\n"); -#endif /* NTP_API */ - } - status = ntp_adjtime(&ntx); - if (status < 0) - perror((errno == EPERM) ? - "Must be root to set kernel values\nntp_adjtime() call fails" : - "ntp_adjtime() call fails"); - else { - flash = ntx.status; - printf("ntp_adjtime() returns code %d (%s)\n", - status, timex_state(status)); - printf(" modes %s,\n", sprintb(ntx.modes, TIMEX_MOD_BITS)); - ftemp = (double)ntx.offset; -#ifdef STA_NANO - if (flash & STA_NANO) - ftemp /= 1000.0; -#endif - printf(" offset %.3f", ftemp); - ftemp = (double)ntx.freq / SCALE_FREQ; - printf(" us, frequency %.3f ppm, interval %d s,\n", - ftemp, 1 << ntx.shift); - printf(" maximum error %lu us, estimated error %lu us,\n", - (u_long)ntx.maxerror, (u_long)ntx.esterror); - printf(" status %s,\n", sprintb((u_int)ntx.status, TIMEX_STA_BITS)); - ftemp = (double)ntx.tolerance / SCALE_FREQ; - gtemp = (double)ntx.precision; -#ifdef STA_NANO - if (flash & STA_NANO) - gtemp /= 1000.0; -#endif - printf( - " time constant %lu, precision %.3f us, tolerance %.0f ppm,\n", - (u_long)ntx.constant, gtemp, ftemp); - if (ntx.shift == 0) - exit (0); - ftemp = (double)ntx.ppsfreq / SCALE_FREQ; - gtemp = (double)ntx.stabil / SCALE_FREQ; - htemp = (double)ntx.jitter; -#ifdef STA_NANO - if (flash & STA_NANO) - htemp /= 1000.0; -#endif - printf( - " pps frequency %.3f ppm, stability %.3f ppm, jitter %.3f us,\n", - ftemp, gtemp, htemp); - printf(" intervals %lu, jitter exceeded %lu, stability exceeded %lu, errors %lu.\n", - (u_long)ntx.calcnt, (u_long)ntx.jitcnt, - (u_long)ntx.stbcnt, (u_long)ntx.errcnt); - return (0); - } - - /* - * Put things back together the way we found them. - */ - lexit: -#ifdef SIGSYS - if (sigaction(SIGSYS, &sigsys, (struct sigaction *)NULL)) { - perror("sigaction() fails to restore SIGSYS trap"); - exit(1); - } -#endif - exit(0); -} - -#ifdef SIGSYS -/* - * pll_trap - trap processor for undefined syscalls - */ -void -pll_trap( - int arg - ) -{ - pll_control--; - siglongjmp(env, 1); -} -#endif - -/* - * Print a value a la the %b format of the kernel's printf - */ -char * -sprintb( - register u_int v, - register const char *bits - ) -{ - register char *cp; - register int i, any = 0; - register char c; - static char buf[132]; - - if (bits && *bits == 8) - (void)sprintf(buf, "0%o", v); - else - (void)sprintf(buf, "0x%x", v); - cp = buf + strlen(buf); - bits++; - if (bits) { - *cp++ = ' '; - *cp++ = '('; - while ((i = *bits++) != 0) { - if (v & (1 << (i-1))) { - if (any) - *cp++ = ','; - any = 1; - for (; (c = *bits) > 32; bits++) - *cp++ = c; - } else - for (; *bits > 32; bits++) - continue; - } - *cp++ = ')'; - } - *cp = '\0'; - return (buf); -} - -const char *timex_states[] = { - "OK", "INS", "DEL", "OOP", "WAIT", "ERROR" -}; - -const char * -timex_state( - register int s - ) -{ - static char buf[32]; - - if (s >= 0 && s <= sizeof(timex_states) / sizeof(timex_states[0])) - return (timex_states[s]); - sprintf(buf, "TIME-#%d", s); - return (buf); -} diff --git a/contrib/ntp/util/pps-api.c b/contrib/ntp/util/pps-api.c deleted file mode 100644 index 60c98b8..0000000 --- a/contrib/ntp/util/pps-api.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - -Try to run this program to see what the PPS-API finds. You give it the -device as argument and you may have to modify the pp.mode = BLA assignment. - -Poul-Henning - -*/ - -#include <stdio.h> -#include <errno.h> -#include <fcntl.h> -#include <err.h> -#include <sys/types.h> -#include <time.h> -#include <sys/timepps.h> -#include <sys/termios.h> - -#define timespecsub(vvp, uvp) \ - do { \ - (vvp)->tv_sec -= (uvp)->tv_sec; \ - (vvp)->tv_nsec -= (uvp)->tv_nsec; \ - if ((vvp)->tv_nsec < 0) { \ - (vvp)->tv_sec--; \ - (vvp)->tv_nsec += 1000000000; \ - } \ - } while (0) - - -void -Chew(struct timespec *tsa, struct timespec *tsc, unsigned sa, unsigned sc) -{ - static int idx; - struct timespec ts; - - printf("%d.%09d ", tsa->tv_sec, tsa->tv_nsec); - printf("%d.%09d ", tsc->tv_sec, tsc->tv_nsec); - printf("%u %u ", sa, sc); - - ts = *tsc; - timespecsub(&ts,tsa); - printf("%.9f ", ts.tv_sec + ts.tv_nsec / 1e9); - printf("\n"); - fflush(stdout); -} - -int -main(int argc, char **argv) -{ - int fd; - pps_info_t pi; - pps_params_t pp; - pps_handle_t ph; - int i, mode; - u_int olda, oldc; - double d = 0; - struct timespec to; - - if (argc < 2) - argv[1] = "/dev/cuaa1"; - setbuf(stdout, 0); - fd = open(argv[1], O_RDONLY); - if (fd < 0) - err(1, argv[1]); - i = time_pps_create(fd, &ph); - if (i < 0) - err(1, "time_pps_create"); - - i = time_pps_getcap(ph, &mode); - if (i < 0) - err(1, "time_pps_getcap"); - - pp.mode = PPS_CAPTUREASSERT | PPS_ECHOASSERT; - pp.mode = PPS_CAPTUREBOTH; - /* pp.mode = PPS_CAPTUREASSERT; */ - - i = time_pps_setparams(ph, &pp); - if (i < 0) - err(1, "time_pps_setparams"); - - while (1) { - to.tv_nsec = 0; - to.tv_sec = 0; - i = time_pps_fetch(ph, PPS_TSFMT_TSPEC, &pi, &to); - if (i < 0) - err(1, "time_pps_fetch"); - if (olda == pi.assert_sequence && - oldc == pi.clear_sequence) { - usleep(10000); - continue; - } - - Chew(&pi.assert_timestamp, &pi.clear_timestamp, - pi.assert_sequence, pi.clear_sequence); - olda = pi.assert_sequence; - oldc = pi.clear_sequence; - } - - return(0); -} diff --git a/contrib/ntp/util/precision.c b/contrib/ntp/util/precision.c deleted file mode 100644 index b1516b3..0000000 --- a/contrib/ntp/util/precision.c +++ /dev/null @@ -1,171 +0,0 @@ -#include "ntp_unixtime.h" - -#include <stdio.h> - -#define DEFAULT_SYS_PRECISION -99 - -int default_get_resolution(); -int default_get_precision(); - -int -main( - int argc, - char *argv[] - ) -{ - printf("log2(resolution) = %d, log2(precision) = %d\n", - default_get_resolution(), - default_get_precision()); - return 0; -} - -/* Find the resolution of the system clock by watching how the current time - * changes as we read it repeatedly. - * - * struct timeval is only good to 1us, which may cause problems as machines - * get faster, but until then the logic goes: - * - * If a machine has resolution (i.e. accurate timing info) > 1us, then it will - * probably use the "unused" low order bits as a counter (to force time to be - * a strictly increaing variable), incrementing it each time any process - * requests the time [[ or maybe time will stand still ? ]]. - * - * SO: the logic goes: - * - * IF the difference from the last time is "small" (< MINSTEP) - * THEN this machine is "counting" with the low order bits - * ELIF this is not the first time round the loop - * THEN this machine *WAS* counting, and has now stepped - * ELSE this machine has resolution < time to read clock - * - * SO: if it exits on the first loop, assume "full accuracy" (1us) - * otherwise, take the log2(observered difference, rounded UP) - * - * MINLOOPS > 1 ensures that even if there is a STEP between the initial call - * and the first loop, it doesn't stop too early. - * Making it even greater allows MINSTEP to be reduced, assuming that the - * chance of MINSTEP-1 other processes getting in and calling gettimeofday - * between this processes's calls. - * Reducing MINSTEP may be necessary as this sets an upper bound for the time - * to actually call gettimeofday. - */ - -#define DUSECS 1000000 -#define HUSECS (1024 * 1024) -#define MINSTEP 5 /* some systems increment uS on each call */ -/* Don't use "1" as some *other* process may read too*/ -/*We assume no system actually *ANSWERS* in this time*/ -#define MAXSTEP 20000 /* maximum clock increment (us) */ -#define MINLOOPS 5 /* minimum number of step samples */ -#define MAXLOOPS HUSECS /* Assume precision < .1s ! */ - -int -default_get_resolution(void) -{ - struct timeval tp; - struct timezone tzp; - long last; - int i; - long diff; - long val; - int minsteps = MINLOOPS; /* need at least this many steps */ - - gettimeofday(&tp, &tzp); - last = tp.tv_usec; - for (i = - --minsteps; i< MAXLOOPS; i++) { - gettimeofday(&tp, &tzp); - diff = tp.tv_usec - last; - if (diff < 0) diff += DUSECS; - if (diff > MINSTEP) if (minsteps-- <= 0) break; - last = tp.tv_usec; - } - - printf("resolution = %ld usec after %d loop%s\n", - diff, i, (i==1) ? "" : "s"); - - diff = (diff *3)/2; - if (i >= MAXLOOPS) { - printf( - " (Boy this machine is fast ! %d loops without a step)\n", - MAXLOOPS); - diff = 1; /* No STEP, so FAST machine */ - } - if (i == 0) { - printf( - " (The resolution is less than the time to read the clock -- Assume 1us)\n"); - diff = 1; /* time to read clock >= resolution */ - } - for (i=0, val=HUSECS; val>0; i--, val >>= 1) if (diff >= val) return i; - printf(" (Oh dear -- that wasn't expected ! I'll guess !)\n"); - return DEFAULT_SYS_PRECISION /* Something's BUST, so lie ! */; -} - -/* ===== Rest of this code lifted straight from xntpd/ntp_proto.c ! ===== */ - -/* - * This routine calculates the differences between successive calls to - * gettimeofday(). If a difference is less than zero, the us field - * has rolled over to the next second, so we add a second in us. If - * the difference is greater than zero and less than MINSTEP, the - * clock has been advanced by a small amount to avoid standing still. - * If the clock has advanced by a greater amount, then a timer interrupt - * has occurred and this amount represents the precision of the clock. - * In order to guard against spurious values, which could occur if we - * happen to hit a fat interrupt, we do this for MINLOOPS times and - * keep the minimum value obtained. - */ -int -default_get_precision(void) -{ - struct timeval tp; - struct timezone tzp; -#ifdef HAVE_GETCLOCK - struct timespec ts; -#endif - long last; - int i; - long diff; - long val; - long usec; - - usec = 0; - val = MAXSTEP; -#ifdef HAVE_GETCLOCK - (void) getclock(TIMEOFDAY, &ts); - tp.tv_sec = ts.tv_sec; - tp.tv_usec = ts.tv_nsec / 1000; -#else /* not HAVE_GETCLOCK */ - GETTIMEOFDAY(&tp, &tzp); -#endif /* not HAVE_GETCLOCK */ - last = tp.tv_usec; - for (i = 0; i < MINLOOPS && usec < HUSECS;) { -#ifdef HAVE_GETCLOCK - (void) getclock(TIMEOFDAY, &ts); - tp.tv_sec = ts.tv_sec; - tp.tv_usec = ts.tv_nsec / 1000; -#else /* not HAVE_GETCLOCK */ - GETTIMEOFDAY(&tp, &tzp); -#endif /* not HAVE_GETCLOCK */ - diff = tp.tv_usec - last; - last = tp.tv_usec; - if (diff < 0) - diff += DUSECS; - usec += diff; - if (diff > MINSTEP) { - i++; - if (diff < val) - val = diff; - } - } - printf("precision = %ld usec after %d loop%s\n", - val, i, (i == 1) ? "" : "s"); - if (usec >= HUSECS) { - printf(" (Boy this machine is fast ! usec was %ld)\n", - usec); - val = MINSTEP; /* val <= MINSTEP; fast machine */ - } - diff = HUSECS; - for (i = 0; diff > val; i--) - diff >>= 1; - return (i); -} diff --git a/contrib/ntp/util/sht.c b/contrib/ntp/util/sht.c deleted file mode 100644 index b993de9..0000000 --- a/contrib/ntp/util/sht.c +++ /dev/null @@ -1,185 +0,0 @@ -/* - * sht.c - Testprogram for shared memory refclock - * read/write shared memory segment; see usage - */ -#ifndef SYS_WINNT -#include <sys/types.h> -#include <sys/ipc.h> -#include <sys/shm.h> -#include <stdio.h> -#include <time.h> -#include <unistd.h> -#include <stdlib.h> -#else -#include <windows.h> -#include <time.h> -#include <stdlib.h> -#include <stdio.h> -#include <iostream.h> -#define sleep(x) Sleep(x*1000) -#endif -#include <assert.h> -struct shmTime { - int mode; /* 0 - if valid set - * use values, - * clear valid - * 1 - if valid set - * if count before and after read of values is equal, - * use values - * clear valid - */ - int count; - time_t clockTimeStampSec; - int clockTimeStampUSec; - time_t receiveTimeStampSec; - int receiveTimeStampUSec; - int leap; - int precision; - int nsamples; - int valid; -}; - -struct shmTime * -getShmTime ( - int unit - ) -{ -#ifndef SYS_WINNT - int shmid=shmget (0x4e545030+unit, sizeof (struct shmTime), IPC_CREAT|0777); - if (shmid==-1) { - perror ("shmget"); - exit (1); - } - else { - struct shmTime *p=(struct shmTime *)shmat (shmid, 0, 0); - if ((int)(long)p==-1) { - perror ("shmat"); - p=0; - } - assert (p!=0); - return p; - } -#else - char buf[10]; - LPSECURITY_ATTRIBUTES psec=0; - sprintf (buf,"NTP%d",unit); - SECURITY_DESCRIPTOR sd; - SECURITY_ATTRIBUTES sa; - HANDLE shmid; - - assert (InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION)); - assert (SetSecurityDescriptorDacl(&sd,1,0,0)); - sa.nLength=sizeof (SECURITY_ATTRIBUTES); - sa.lpSecurityDescriptor=&sd; - sa.bInheritHandle=0; - shmid=CreateFileMapping ((HANDLE)0xffffffff, 0, PAGE_READWRITE, - psec, sizeof (struct shmTime),buf); - if (!shmid) { - shmid=CreateFileMapping ((HANDLE)0xffffffff, 0, PAGE_READWRITE, - 0, sizeof (struct shmTime),buf); - cout <<"CreateFileMapping with psec!=0 failed"<<endl; - } - - if (!shmid) { - char mbuf[1000]; - FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, - 0, GetLastError (), 0, mbuf, sizeof (mbuf), 0); - int x=GetLastError (); - cout <<"CreateFileMapping "<<buf<<":"<<mbuf<<endl; - exit (1); - } - else { - struct shmTime *p=(struct shmTime *) MapViewOfFile (shmid, - FILE_MAP_WRITE, 0, 0, sizeof (struct shmTime)); - if (p==0) { - char mbuf[1000]; - FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, - 0, GetLastError (), 0, mbuf, sizeof (mbuf), 0); - cout <<"MapViewOfFile "<<buf<<":"<<mbuf<<endl; - exit (1); - } - return p; - } - return 0; -#endif -} - - -int -main ( - int argc, - char *argv[] - ) -{ - volatile struct shmTime *p=getShmTime(2); - if (argc<=1) { - printf ("usage: %s r[c][l]|w|snnn\n",argv[0]); - printf (" r read shared memory\n"); - printf (" c clear valid-flag\n"); - printf (" l loop (so, rcl will read and clear in a loop\n"); - printf (" w write shared memory with current time\n"); - printf (" snnnn set nsamples to nnn\n"); - printf (" lnnnn set leap to nnn\n"); - printf (" pnnnn set precision to -nnn\n"); - exit (0); - } - switch (argv[1][0]) { - case 's': { - p->nsamples=atoi(&argv[1][1]); - } - break; - case 'l': { - p->leap=atoi(&argv[1][1]); - } - break; - case 'p': { - p->precision=-atoi(&argv[1][1]); - } - break; - case 'r': { - char *ap=&argv[1][1]; - int clear=0; - int loop=0; - printf ("reader\n"); - while (*ap) { - switch (*ap) { - case 'l' : loop=1; break; - case 'c' : clear=1; break; - } - ap++; - } - do { - printf ("mode=%d, count=%d, clock=%d.%d, rec=%d.%d,\n", - p->mode,p->count,p->clockTimeStampSec,p->clockTimeStampUSec, - p->receiveTimeStampSec,p->receiveTimeStampUSec); - printf (" leap=%d, precision=%d, nsamples=%d, valid=%d\n", - p->leap, p->precision, p->nsamples, p->valid); - if (!p->valid) - printf ("***\n"); - if (clear) { - p->valid=0; - printf ("cleared\n"); - } - if (loop) - sleep (1); - } while (loop); - } - break; - case 'w': { - printf ("writer\n"); - p->mode=0; - if (!p->valid) { - p->clockTimeStampSec=time(0)-20; - p->clockTimeStampUSec=0; - p->receiveTimeStampSec=time(0)-1; - p->receiveTimeStampUSec=0; - printf ("%d %d\n",p->clockTimeStampSec, p->receiveTimeStampSec); - p->valid=1; - } - else { - printf ("p->valid still set\n"); /* not an error! */ - } - } - break; - } -} diff --git a/contrib/ntp/util/testrs6000.c b/contrib/ntp/util/testrs6000.c deleted file mode 100644 index e4d939a..0000000 --- a/contrib/ntp/util/testrs6000.c +++ /dev/null @@ -1,55 +0,0 @@ -/* Checks for the RS/6000 AIX adjtime() bug, in which if a negative - * offset is given, the system gets messed up and never completes the - * adjustment. If the problem is fixed, this program will print the - * time, sit there for 10 seconds, and exit. If the problem isn't fixed, - * the program will print an occasional "result=nnnnnn" (the residual - * slew from adjtime()). - * - * Compile this with bsdcc and run it as root! - */ -#include <signal.h> -#include <sys/time.h> -#include <time.h> -#include <stdio.h> - -int timeout(); -struct timeval adjustment, result; - -int -main ( - int argc, - char *argv[] - ) -{ - struct itimerval value, oldvalue; - int i; - time_t curtime; - - curtime = time(0); - printf("Starting: %s", ctime(&curtime)); - value.it_interval.tv_sec = value.it_value.tv_sec = 1; - value.it_interval.tv_usec = value.it_value.tv_usec = 0; - adjustment.tv_sec = 0; - adjustment.tv_usec = -2000; - signal(SIGALRM, timeout); - setitimer(ITIMER_REAL, &value, &oldvalue); - for (i=0; i<10; i++) { - pause(); - } -} - -int -timeout( - int sig, - int code, - struct sigcontext *scp - ) -{ - signal (SIGALRM, timeout); - if (adjtime(&adjustment, &result)) - printf("adjtime call failed\n"); - if (result.tv_sec != 0 || result.tv_usec != 0) { - printf("result.u = %d.%06.6d ", (int) result.tv_sec, - (int) result.tv_usec); - } -} diff --git a/contrib/ntp/util/tickadj.c b/contrib/ntp/util/tickadj.c deleted file mode 100644 index 4a7f2c4..0000000 --- a/contrib/ntp/util/tickadj.c +++ /dev/null @@ -1,902 +0,0 @@ -/* - * tickadj - read, and possibly modify, the kernel `tick' and - * `tickadj' variables, as well as `dosynctodr'. Note that - * this operates on the running kernel only. I'd like to be - * able to read and write the binary as well, but haven't - * mastered this yet. - * - * HMS: The #includes here are different from those in xntpd/ntp_unixclock.c - * These seem "worse". - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#include "ntp_types.h" -#include "l_stdlib.h" - -#include <stdio.h> -#ifdef HAVE_UNISTD_H -# include <unistd.h> -#endif /* HAVE_UNISTD_H */ - -#ifdef HAVE___ADJTIMEX /* Linux */ - -#include <sys/timex.h> -struct timex txc; - -#if 0 -int -main( - int argc, - char *argv[] - ) -{ - int c, i; - int quiet = 0; - int errflg = 0; - char *progname; - extern int ntp_optind; - extern char *ntp_optarg; - - progname = argv[0]; - if (argc==2 && argv[1][0] != '-') { /* old Linux format, for compatability */ - if ((i = atoi(argv[1])) > 0) { - txc.time_tick = i; - txc.modes = ADJ_TIMETICK; - } else { - fprintf(stderr, "Silly value for tick: %s\n", argv[1]); - errflg++; - } - } else { - while ((c = ntp_getopt(argc, argv, "a:qt:")) != EOF) { - switch (c) { - case 'a': - if ((i=atoi(ntp_optarg)) > 0) { - txc.tickadj = i; - txc.modes |= ADJ_TICKADJ; - } else { - (void) fprintf(stderr, - "%s: unlikely value for tickadj: %s\n", - progname, ntp_optarg); - errflg++; - } - break; - - case 'q': - quiet = 1; - break; - - case 't': - if ((i=atoi(ntp_optarg)) > 0) { - txc.time_tick = i; - txc.modes |= ADJ_TIMETICK; - } else { - (void) fprintf(stderr, - "%s: unlikely value for tick: %s\n", - progname, ntp_optarg); - errflg++; - } - break; - - default: - fprintf(stderr, - "Usage: %s [tick_value]\n-or- %s [ -q ] [ -t tick ] [ -a tickadj ]\n", - progname, progname); - errflg++; - break; - } - } - } - - if (!errflg) { - if (__adjtimex(&txc) < 0) - perror("adjtimex"); - else if (!quiet) - printf("tick = %ld\ntick_adj = %d\n", - txc.time_tick, txc.tickadj); - } - - exit(errflg ? 1 : 0); -} -#else -int -main( - int argc, - char *argv[] - ) -{ - if (argc > 2) - { - fprintf(stderr, "Usage: %s [tick_value]\n", argv[0]); - exit(-1); - } - else if (argc == 2) - { -#ifdef ADJ_TIMETICK - if ( (txc.time_tick = atoi(argv[1])) < 1 ) -#else - if ( (txc.tick = atoi(argv[1])) < 1 ) -#endif - { - fprintf(stderr, "Silly value for tick: %s\n", argv[1]); - exit(-1); - } -#ifdef ADJ_TIMETICK - txc.modes = ADJ_TIMETICK; -#else -#ifdef MOD_OFFSET - txc.modes = ADJ_TICK; -#else - txc.mode = ADJ_TICK; -#endif -#endif - } - else - { -#ifdef ADJ_TIMETICK - txc.modes = 0; -#else -#ifdef MOD_OFFSET - txc.modes = 0; -#else - txc.mode = 0; -#endif -#endif - } - - if (__adjtimex(&txc) < 0) - { - perror("adjtimex"); - } - else - { -#ifdef ADJ_TIMETICK - printf("tick = %ld\ntick_adj = %ld\n", txc.time_tick, txc.tickadj); -#else - printf("tick = %ld\n", txc.tick); -#endif - } - - exit(0); -} -#endif - -#else /* not Linux... kmem tweaking: */ - -#ifdef HAVE_SYS_FILE_H -# include <sys/file.h> -#endif -#include <sys/stat.h> - -#ifdef HAVE_SYS_PARAM_H -# include <sys/param.h> -#endif - -#ifdef NLIST_STRUCT -# include <nlist.h> -#else /* not NLIST_STRUCT */ /* was defined(SYS_AUX3) || defined(SYS_AUX2) */ -# include <sys/resource.h> -# include <sys/file.h> -# include <a.out.h> -# include <sys/var.h> -#endif - -#include "ntp_io.h" -#include "ntp_stdlib.h" - -#ifdef hz /* Was: RS6000 */ -# undef hz -#endif /* hz */ - -#ifdef HAVE_KVM_OPEN -# include <kvm.h> -#endif - -#ifdef SYS_VXWORKS -/* vxWorks needs mode flag -casey*/ -#define open(name, flags) open(name, flags, 0777) -#endif - -#ifndef L_SET /* Was: defined(SYS_PTX) || defined(SYS_IX86OSF1) */ -# define L_SET SEEK_SET -#endif - -#ifndef HZ -# define HZ DEFAULT_HZ -#endif - -#define KMEM "/dev/kmem" -#define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0) - -char *progname; -volatile int debug; - -int dokmem = 1; -int writetickadj = 0; -int writeopttickadj = 0; -int unsetdosync = 0; -int writetick = 0; -int quiet = 0; -int setnoprintf = 0; - -const char *kmem = KMEM; -const char *file = NULL; -int fd = -1; - -static void getoffsets P((off_t *, off_t *, off_t *, off_t *)); -static int openfile P((const char *, int)); -static void writevar P((int, off_t, int)); -static void readvar P((int, off_t, int *)); - -/* - * main - parse arguments and handle options - */ -int -main( - int argc, - char *argv[] - ) -{ - int c; - int errflg = 0; - off_t tickadj_offset; - off_t tick_offset; - off_t dosync_offset; - off_t noprintf_offset; - int tickadj, ktickadj; /* HMS: Why isn't this u_long? */ - int tick, ktick; /* HMS: Why isn't this u_long? */ - int dosynctodr; - int noprintf; - int hz; - int hz_int, hz_hundredths; - int recommend_tickadj; - long tmp; - - progname = argv[0]; - while ((c = ntp_getopt(argc, argv, "a:Adkpqst:")) != EOF) - { - switch (c) - { - case 'a': - writetickadj = atoi(ntp_optarg); - if (writetickadj <= 0) - { - (void) fprintf(stderr, - "%s: unlikely value for tickadj: %s\n", - progname, ntp_optarg); - errflg++; - } - -#if defined SCO5_CLOCK - if (writetickadj % HZ) - { - writetickadj = (writetickadj / HZ) * HZ; - (void) fprintf(stderr, - "tickadj truncated to: %d\n", writetickadj); - } -#endif /* SCO5_CLOCK */ - - break; - case 'A': - writeopttickadj = 1; - break; - case 'd': - ++debug; - break; - case 'k': - dokmem = 1; - break; - case 'p': - setnoprintf = 1; - break; - case 'q': - quiet = 1; - break; - case 's': - unsetdosync = 1; - break; - case 't': - writetick = atoi(ntp_optarg); - if (writetick <= 0) - { - (void) fprintf(stderr, - "%s: unlikely value for tick: %s\n", - progname, ntp_optarg); - errflg++; - } - break; - default: - errflg++; - break; - } - } - if (errflg || ntp_optind != argc) - { - (void) fprintf(stderr, - "usage: %s [-Adkpqs] [-a newadj] [-t newtick]\n", progname); - exit(2); - } - - getoffsets(&tick_offset, &tickadj_offset, &dosync_offset, &noprintf_offset); - - if (debug) - { - (void) printf("tick offset = %lu\n", (unsigned long)tick_offset); - (void) printf("tickadj offset = %lu\n", (unsigned long)tickadj_offset); - (void) printf("dosynctodr offset = %lu\n", (unsigned long)dosync_offset); - (void) printf("noprintf offset = %lu\n", (unsigned long)noprintf_offset); - } - - if (writetick && (tick_offset == 0)) - { - (void) fprintf(stderr, - "No tick kernel variable\n"); - errflg++; - } - - if (writeopttickadj && (tickadj_offset == 0)) - { - (void) fprintf(stderr, - "No tickadj kernel variable\n"); - errflg++; - } - - if (unsetdosync && (dosync_offset == 0)) - { - (void) fprintf(stderr, - "No dosynctodr kernel variable\n"); - errflg++; - } - - if (setnoprintf && (noprintf_offset == 0)) - { - (void) fprintf(stderr, - "No noprintf kernel variable\n"); - errflg++; - } - - if (tick_offset != 0) - { - readvar(fd, tick_offset, &tick); -#if defined(TICK_NANO) && defined(K_TICK_NAME) - if (!quiet) - (void) printf("KERNEL %s = %d nsec\n", K_TICK_NAME, tick); -#endif /* TICK_NANO && K_TICK_NAME */ - -#ifdef TICK_NANO - tick /= 1000; -#endif - } - else - { - tick = 0; - } - - if (tickadj_offset != 0) - { - readvar(fd, tickadj_offset, &tickadj); - -#ifdef SCO5_CLOCK - /* scale from nsec/sec to usec/tick */ - tickadj /= (1000L * HZ); -#endif /*SCO5_CLOCK */ - -#if defined(TICKADJ_NANO) && defined(K_TICKADJ_NAME) - if (!quiet) - (void) printf("KERNEL %s = %d nsec\n", K_TICKADJ_NAME, tickadj); -#endif /* TICKADJ_NANO && K_TICKADJ_NAME */ - -#ifdef TICKADJ_NANO - tickadj += 999; - tickadj /= 1000; -#endif - } - else - { - tickadj = 0; - } - - if (dosync_offset != 0) - { - readvar(fd, dosync_offset, &dosynctodr); - } - - if (noprintf_offset != 0) - { - readvar(fd, noprintf_offset, &noprintf); - } - - (void) close(fd); - - if (unsetdosync && dosync_offset == 0) - { - (void) fprintf(stderr, - "%s: can't find %s in namelist\n", - progname, -#ifdef K_DOSYNCTODR_NAME - K_DOSYNCTODR_NAME -#else /* not K_DOSYNCTODR_NAME */ - "dosynctodr" -#endif /* not K_DOSYNCTODR_NAME */ - ); - exit(1); - } - - hz = HZ; -#if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK) - hz = (int) sysconf (_SC_CLK_TCK); -#endif /* not HAVE_SYSCONF && _SC_CLK_TCK */ -#ifdef OVERRIDE_HZ - hz = DEFAULT_HZ; -#endif - ktick = tick; -#ifdef PRESET_TICK - tick = PRESET_TICK; -#endif /* PRESET_TICK */ -#ifdef TICKADJ_NANO - tickadj /= 1000; - if (tickadj == 0) - tickadj = 1; -#endif - ktickadj = tickadj; -#ifdef PRESET_TICKADJ - tickadj = (PRESET_TICKADJ) ? PRESET_TICKADJ : 1; -#endif /* PRESET_TICKADJ */ - - if (!quiet) - { - if (tick_offset != 0) - { - (void) printf("KERNEL tick = %d usec (from %s kernel variable)\n", - ktick, -#ifdef K_TICK_NAME - K_TICK_NAME -#else - "<this can't happen>" -#endif - ); - } -#ifdef PRESET_TICK - (void) printf("PRESET tick = %d usec\n", tick); -#endif /* PRESET_TICK */ - if (tickadj_offset != 0) - { - (void) printf("KERNEL tickadj = %d usec (from %s kernel variable)\n", - ktickadj, -#ifdef K_TICKADJ_NAME - K_TICKADJ_NAME -#else - "<this can't happen>" -#endif - ); - } -#ifdef PRESET_TICKADJ - (void) printf("PRESET tickadj = %d usec\n", tickadj); -#endif /* PRESET_TICKADJ */ - if (dosync_offset != 0) - { - (void) printf("dosynctodr is %s\n", dosynctodr ? "on" : "off"); - } - if (noprintf_offset != 0) - { - (void) printf("kernel level printf's: %s\n", - noprintf ? "off" : "on"); - } - } - - if (tick <= 0) - { - (void) fprintf(stderr, "%s: the value of tick is silly!\n", - progname); - exit(1); - } - - hz_int = (int)(1000000L / (long)tick); - hz_hundredths = (int)((100000000L / (long)tick) - ((long)hz_int * 100L)); - if (!quiet) - { - (void) printf("KERNEL hz = %d\n", hz); - (void) printf("calculated hz = %d.%02d Hz\n", hz_int, - hz_hundredths); - } - -#if defined SCO5_CLOCK - recommend_tickadj = 100; -#else /* SCO5_CLOCK */ - tmp = (long) tick * 500L; - recommend_tickadj = (int)(tmp / 1000000L); - if (tmp % 1000000L > 0) - { - recommend_tickadj++; - } - -#ifdef MIN_REC_TICKADJ - if (recommend_tickadj < MIN_REC_TICKADJ) - { - recommend_tickadj = MIN_REC_TICKADJ; - } -#endif /* MIN_REC_TICKADJ */ -#endif /* SCO5_CLOCK */ - - - if ((!quiet) && (tickadj_offset != 0)) - { - (void) printf("recommended value of tickadj = %d us\n", - recommend_tickadj); - } - - if ( writetickadj == 0 - && !writeopttickadj - && !unsetdosync - && writetick == 0 - && !setnoprintf) - { - exit(errflg ? 1 : 0); - } - - if (writetickadj == 0 && writeopttickadj) - { - writetickadj = recommend_tickadj; - } - - fd = openfile(file, O_WRONLY); - - if (setnoprintf && (noprintf_offset != 0)) - { - if (!quiet) - { - (void) fprintf(stderr, "setting noprintf: "); - (void) fflush(stderr); - } - writevar(fd, noprintf_offset, 1); - if (!quiet) - { - (void) fprintf(stderr, "done!\n"); - } - } - - if ((writetick > 0) && (tick_offset != 0)) - { - if (!quiet) - { - (void) fprintf(stderr, "writing tick, value %d: ", - writetick); - (void) fflush(stderr); - } - writevar(fd, tick_offset, writetick); - if (!quiet) - { - (void) fprintf(stderr, "done!\n"); - } - } - - if ((writetickadj > 0) && (tickadj_offset != 0)) - { - if (!quiet) - { - (void) fprintf(stderr, "writing tickadj, value %d: ", - writetickadj); - (void) fflush(stderr); - } - -#ifdef SCO5_CLOCK - /* scale from usec/tick to nsec/sec */ - writetickadj *= (1000L * HZ); -#endif /* SCO5_CLOCK */ - - writevar(fd, tickadj_offset, writetickadj); - if (!quiet) - { - (void) fprintf(stderr, "done!\n"); - } - } - - if (unsetdosync && (dosync_offset != 0)) - { - if (!quiet) - { - (void) fprintf(stderr, "zeroing dosynctodr: "); - (void) fflush(stderr); - } - writevar(fd, dosync_offset, 0); - if (!quiet) - { - (void) fprintf(stderr, "done!\n"); - } - } - (void) close(fd); - return(errflg ? 1 : 0); -} - -/* - * getoffsets - read the magic offsets from the specified file - */ -static void -getoffsets( - off_t *tick_off, - off_t *tickadj_off, - off_t *dosync_off, - off_t *noprintf_off - ) -{ - -#ifndef NOKMEM -# ifndef HAVE_KVM_OPEN - const char **kname; -# endif -#endif - -#ifndef NOKMEM -# ifdef NLIST_NAME_UNION -# define NL_B {{ -# define NL_E }} -# else -# define NL_B { -# define NL_E } -# endif -#endif - -#define K_FILLER_NAME "DavidLetterman" - -#ifdef NLIST_EXTRA_INDIRECTION - int i; -#endif - -#ifndef NOKMEM - static struct nlist nl[] = - { - NL_B -#ifdef K_TICKADJ_NAME -#define N_TICKADJ 0 - K_TICKADJ_NAME -#else - K_FILLER_NAME -#endif - NL_E, - NL_B -#ifdef K_TICK_NAME -#define N_TICK 1 - K_TICK_NAME -#else - K_FILLER_NAME -#endif - NL_E, - NL_B -#ifdef K_DOSYNCTODR_NAME -#define N_DOSYNC 2 - K_DOSYNCTODR_NAME -#else - K_FILLER_NAME -#endif - NL_E, - NL_B -#ifdef K_NOPRINTF_NAME -#define N_NOPRINTF 3 - K_NOPRINTF_NAME -#else - K_FILLER_NAME -#endif - NL_E, - NL_B "" NL_E, - }; - -#ifndef HAVE_KVM_OPEN - static const char *kernels[] = - { -#ifdef HAVE_GETBOOTFILE - NULL, /* *** SEE BELOW! *** */ -#endif - "/kernel/unix", - "/kernel", - "/vmunix", - "/unix", - "/mach", - "/hp-ux", - "/386bsd", - "/netbsd", - "/stand/vmunix", - "/bsd", - NULL - }; -#endif /* not HAVE_KVM_OPEN */ - -#ifdef HAVE_KVM_OPEN - /* - * Solaris > 2.5 doesn't have a kernel file. Use the kvm_* interface - * to read the kernel name list. -- stolcke 3/4/96 - */ - kvm_t *kvm_handle = kvm_open(NULL, NULL, NULL, O_RDONLY, progname); - - if (kvm_handle == NULL) - { - (void) fprintf(stderr, - "%s: kvm_open failed\n", - progname); - exit(1); - } - if (kvm_nlist(kvm_handle, nl) == -1) - { - (void) fprintf(stderr, - "%s: kvm_nlist failed\n", - progname); - exit(1); - } - kvm_close(kvm_handle); -#else /* not HAVE_KVM_OPEN */ -#ifdef HAVE_GETBOOTFILE /* *** SEE HERE! *** */ - if (kernels[0] == NULL) - { - char * cp = (char *)getbootfile(); - - if (cp) - { - kernels[0] = cp; - } - else - { - kernels[0] = "/Placeholder"; - } - } -#endif /* HAVE_GETBOOTFILE */ - for (kname = kernels; *kname != NULL; kname++) - { - struct stat stbuf; - - if (stat(*kname, &stbuf) == -1) - { - continue; - } - if (nlist(*kname, nl) >= 0) - { - break; - } - else - { - (void) fprintf(stderr, - "%s: nlist didn't find needed symbols from <%s>: %s\n", - progname, *kname, strerror(errno)); - } - } - if (*kname == NULL) - { - (void) fprintf(stderr, - "%s: Couldn't find the kernel\n", - progname); - exit(1); - } -#endif /* HAVE_KVM_OPEN */ - - if (dokmem) - { - file = kmem; - - fd = openfile(file, O_RDONLY); -#ifdef NLIST_EXTRA_INDIRECTION - /* - * Go one more round of indirection. - */ - for (i = 0; i < (sizeof(nl) / sizeof(struct nlist)); i++) - { - if ((nl[i].n_value) && (nl[i].n_sclass == 0x6b)) - { - readvar(fd, nl[i].n_value, &nl[i].n_value); - } - } -#endif /* NLIST_EXTRA_INDIRECTION */ - } -#endif /* not NOKMEM */ - - *tickadj_off = 0; - *tick_off = 0; - *dosync_off = 0; - *noprintf_off = 0; - -#if defined(N_TICKADJ) - *tickadj_off = nl[N_TICKADJ].n_value; -#endif - -#if defined(N_TICK) - *tick_off = nl[N_TICK].n_value; -#endif - -#if defined(N_DOSYNC) - *dosync_off = nl[N_DOSYNC].n_value; -#endif - -#if defined(N_NOPRINTF) - *noprintf_off = nl[N_NOPRINTF].n_value; -#endif - return; -} - -#undef N_TICKADJ -#undef N_TICK -#undef N_DOSYNC -#undef N_NOPRINTF - - -/* - * openfile - open the file, check for errors - */ -static int -openfile( - const char *name, - int mode - ) -{ - int ifd; - - ifd = open(name, mode); - if (ifd < 0) - { - (void) fprintf(stderr, "%s: open %s: ", progname, name); - perror(""); - exit(1); - } - return ifd; -} - - -/* - * writevar - write a variable into the file - */ -static void -writevar( - int ofd, - off_t off, - int var - ) -{ - - if (lseek(ofd, off, L_SET) == -1) - { - (void) fprintf(stderr, "%s: lseek fails: ", progname); - perror(""); - exit(1); - } - if (write(ofd, (char *)&var, sizeof(int)) != sizeof(int)) - { - (void) fprintf(stderr, "%s: write fails: ", progname); - perror(""); - exit(1); - } - return; -} - - -/* - * readvar - read a variable from the file - */ -static void -readvar( - int ifd, - off_t off, - int *var - ) -{ - int i; - - if (lseek(ifd, off, L_SET) == -1) - { - (void) fprintf(stderr, "%s: lseek fails: ", progname); - perror(""); - exit(1); - } - i = read(ifd, (char *)var, sizeof(int)); - if (i < 0) - { - (void) fprintf(stderr, "%s: read fails: ", progname); - perror(""); - exit(1); - } - if (i != sizeof(int)) - { - (void) fprintf(stderr, "%s: read expected %d, got %d\n", - progname, (int)sizeof(int), i); - exit(1); - } - return; -} -#endif /* not Linux */ diff --git a/contrib/ntp/util/timetrim.c b/contrib/ntp/util/timetrim.c deleted file mode 100644 index 911ea28..0000000 --- a/contrib/ntp/util/timetrim.c +++ /dev/null @@ -1,116 +0,0 @@ -#if defined(sgi) || defined(_UNICOSMP) -/* - * timetrim.c - * - * "timetrim" allows setting and adjustment of the system clock frequency - * trim parameter on Silicon Graphics machines. The trim value native - * units are nanoseconds per second (10**-9), so a trim value of 1 makes - * the system clock step ahead 1 nanosecond more per second than a value - * of zero. Xntpd currently uses units of 2**-20 secs for its frequency - * offset (drift) values; to convert to a timetrim value, multiply by - * 1E9 / 2**20 (about 954). - * - * "timetrim" with no arguments just prints out the current kernel value. - * With a numeric argument, the kernel value is set to the supplied value. - * The "-i" flag causes the supplied value to be added to the kernel value. - * The "-n" option causes all input and output to be in xntpd units rather - * than timetrim native units. - * - * Note that there is a limit of +-3000000 (0.3%) on the timetrim value - * which is (silently?) enforced by the kernel. - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdio.h> -#include <ctype.h> -#include <stdlib.h> -#ifdef HAVE_SYS_SYSSGI_H -# include <sys/syssgi.h> -#endif -#ifdef HAVE_SYS_SYSTUNE_H -# include <sys/systune.h> -#endif - -#define abs(X) (((X) < 0) ? -(X) : (X)) -#define USAGE "usage: timetrim [-n] [[-i] value]\n" -#define SGITONTP(X) ((double)(X) * 1048576.0/1.0e9) -#define NTPTOSGI(X) ((long)((X) * 1.0e9/1048576.0)) - -int -main( - int argc, - char *argv[] - ) -{ - char *rem; - int incremental = 0, ntpunits = 0; - long timetrim; - double value; - - while (--argc && **++argv == '-' && isalpha((int)argv[0][1])) { - switch (argv[0][1]) { - case 'i': - incremental++; - break; - case 'n': - ntpunits++; - break; - default: - fprintf(stderr, USAGE); - exit(1); - } - } - -#ifdef HAVE_SYS_SYSSGI_H - if (syssgi(SGI_GETTIMETRIM, &timetrim) < 0) { - perror("syssgi"); - exit(2); - } -#endif -#ifdef HAVE_SYS_SYSTUNE_H - if (systune(SYSTUNE_GET, "timetrim", &timetrim) < 0) { - perror("systune"); - exit(2); - } -#endif - - if (argc == 0) { - if (ntpunits) - fprintf(stdout, "%0.5f\n", SGITONTP(timetrim)); - else - fprintf(stdout, "%ld\n", timetrim); - } else if (argc != 1) { - fprintf(stderr, USAGE); - exit(1); - } else { - value = strtod(argv[0], &rem); - if (*rem != '\0') { - fprintf(stderr, USAGE); - exit(1); - } - if (ntpunits) - value = NTPTOSGI(value); - if (incremental) - timetrim += value; - else - timetrim = value; -#ifdef HAVE_SYS_SYSSGI_H - if (syssgi(SGI_SETTIMETRIM, timetrim) < 0) { - perror("syssgi"); - exit(2); - } -#endif -#ifdef HAVE_SYS_SYSTUNE_H - if (systune(SYSTUNE_SET, "timer", "timetrim", &timetrim) < 0) { - perror("systune"); - exit(2); - } -#endif - } - return 0; -} -#endif |