]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Many files:
authorHarlan Stenn <stenn@ntp.org>
Sun, 30 Jul 2000 07:05:25 +0000 (07:05 -0000)
committerHarlan Stenn <stenn@ntp.org>
Sun, 30 Jul 2000 07:05:25 +0000 (07:05 -0000)
  * configure.in: 4.0.99k4
  * util/ntp-genkeys.c: Start hacking for new functionality.
  * include/Makefile.am (noinst_HEADERS): Added ntp_cmdargs.h and
  ntp_config.h .
  * ntpd/ntp_config.c: Grab ntp_cmdargs.h.  Make some new globals
  (ugh), move ntpd-specific variables and code to cmd_args.c .
  * ntpd/cmd_args.c: Move command argument processing functions from
  ntp_config.c to this file.
  * ntpd/Makefile.am (ntpd_SOURCES): Added cmd_args.c
  * include/ntpd.h: Move getstartup() to ntp_cmdargs.h
  * include/ntp_cmdargs.h: New file
  Begin the hacking fest to make it easier for ntp-genkeys to use
  ntpd's config processing code.  I really hope this is the lesser
  of the evils...

bk: 3983d3b5jhVZWMTh3JhmCK4Rx6ZY6A

ChangeLog
configure
configure.in
include/Makefile.am
include/ntp_cmdargs.h [new file with mode: 0644]
include/ntpd.h
ntpd/Makefile.am
ntpd/Makefile.in
ntpd/cmd_args.c [new file with mode: 0644]
ntpd/ntp_config.c
util/ntp-genkeys.c

index add6cdfdaa7061475ebdc17580d48ac93c19315b..2bc4cfad84b0c11cc2a24bd1fb14e07a4d0c043b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2000-07-30  Harlan Stenn  <stenn@whimsy.udel.edu>
+
+       * configure.in: 4.0.99k4
+       * util/ntp-genkeys.c: Start hacking for new functionality.
+       * include/Makefile.am (noinst_HEADERS): Added ntp_cmdargs.h and
+       ntp_config.h .
+       * ntpd/ntp_config.c: Grab ntp_cmdargs.h.  Make some new globals
+       (ugh), move ntpd-specific variables and code to cmd_args.c .
+       * ntpd/cmd_args.c: Move command argument processing functions from
+       ntp_config.c to this file.
+       * ntpd/Makefile.am (ntpd_SOURCES): Added cmd_args.c
+       * include/ntpd.h: Move getstartup() to ntp_cmdargs.h
+       * include/ntp_cmdargs.h: New file
+       Begin the hacking fest to make it easier for ntp-genkeys to use
+       ntpd's config processing code.  I really hope this is the lesser
+       of the evils...
+       
 2000-07-28  Harlan Stenn  <stenn@whimsy.udel.edu>
 
        * util/ntp-genkeys.c (usage): Added.
index d97f9d555e06d2b3b60f80d7ab78ab19ce4ed5f1..e6e9b2efe9f9aa4ac989a0a53e41586641e27b30 100755 (executable)
--- a/configure
+++ b/configure
@@ -1091,7 +1091,7 @@ fi
 
 PACKAGE=ntp
 
-VERSION=4.0.99k3
+VERSION=4.0.99k4
 
 if test "`CDPATH=: && cd $srcdir && pwd`" != "`pwd`" &&
    test -f $srcdir/config.status; then
index cbe521614d9e3555f4424b7c87a52e763b222d98..e038e908f04ca8cc25ee848a3c58d5e9ca491c0b 100644 (file)
@@ -5,7 +5,7 @@ AC_CANONICAL_SYSTEM
 AC_DEFINE_UNQUOTED(STR_SYSTEM, "$target")
 AM_CONFIG_HEADER(config.h)
 AC_ARG_PROGRAM
-AM_INIT_AUTOMAKE(ntp, 4.0.99k3)
+AM_INIT_AUTOMAKE(ntp, 4.0.99k4)
 AC_PREREQ(2.14)
 
 ac_cv_var_oncore_ok=no
index 46c22d34bf74ba8d46294b1473f3a54571ba3f6c..c5fd8a56b0b2b0d4cefcd733375e0ba116de0dcb 100644 (file)
@@ -21,6 +21,8 @@ noinst_HEADERS = \
        ntif.h \
        ntp.h \
        ntp_calendar.h \
+       ntp_cmdargs.h \
+       ntp_config.h \
        ntp_control.h \
        ntp_crypto.h \
        ntp_datum.h \
diff --git a/include/ntp_cmdargs.h b/include/ntp_cmdargs.h
new file mode 100644 (file)
index 0000000..e9ab9b1
--- /dev/null
@@ -0,0 +1,4 @@
+#include "ntp_types.h"
+
+extern void    getstartup      P((int, char **));
+extern void    getCmdOpts      P((int, char **));
index b077c984b571035dcaa7ccc8e8cbf2ee81c98a01..653a77c390f28baa4175407759e3abed5ebc2f56 100644 (file)
@@ -26,7 +26,6 @@ void  worker_thread   (void *);
 #endif /* SYS_WINNT */
 
 /* ntp_config.c */
-extern void    getstartup      P((int, char **));
 extern void    getconfig       P((int, char **));
 
 /* ntp_config.c */
index 8ca77971d9d23cb7a6688393775dd0eecac86859..1ebf3a638c5d4511a0c77e12302fb776390fc4bb 100644 (file)
@@ -20,8 +20,8 @@ EXTRA_PROGRAMS = check_y2k
 check-local: @MAKE_CHECK_Y2K@
        [ -z "@MAKE_CHECK_Y2K@" ] || ./@MAKE_CHECK_Y2K@
 
-ntpd_SOURCES = jupiter.h map_vme.c ntp_config.c ntp_control.c ntp_crypto.c \
-       ntp_filegen.c \
+ntpd_SOURCES = cmd_args.c jupiter.h map_vme.c ntp_config.c ntp_control.c \
+       ntp_crypto.c ntp_filegen.c \
        ntp_intres.c ntp_io.c ntp_loopfilter.c ntp_monitor.c ntp_peer.c \
        ntp_proto.c ntp_refclock.c ntp_request.c ntp_resolver.c \
        ntp_restrict.c ntp_timer.c \
index 8b9c02d52e2637edbc0d51ea8b4c9588a75fd607..aa776bd77df60c507b1d0fe576f55bc82cb07d2a 100644 (file)
@@ -78,6 +78,8 @@ CXX = @CXX@
 CXXCPP = @CXXCPP@
 DCFD = @DCFD@
 DEPDIR = @DEPDIR@
+EF_LIBS = @EF_LIBS@
+EF_PROGS = @EF_PROGS@
 LDFLAGS = @LDFLAGS@
 LIBPARSE = @LIBPARSE@
 LIBRSAREF = @LIBRSAREF@
@@ -124,8 +126,8 @@ ETAGS_ARGS = Makefile.am
 check_PROGRAMS = @MAKE_CHECK_Y2K@
 EXTRA_PROGRAMS = check_y2k
 
-ntpd_SOURCES = jupiter.h map_vme.c ntp_config.c ntp_control.c ntp_crypto.c \
-       ntp_filegen.c \
+ntpd_SOURCES = cmd_args.c jupiter.h map_vme.c ntp_config.c ntp_control.c \
+       ntp_crypto.c ntp_filegen.c \
        ntp_intres.c ntp_io.c ntp_loopfilter.c ntp_monitor.c ntp_peer.c \
        ntp_proto.c ntp_refclock.c ntp_request.c ntp_resolver.c \
        ntp_restrict.c ntp_timer.c \
@@ -156,11 +158,11 @@ check_y2k_OBJECTS =  check_y2k$U.o
 check_y2k_LDADD = $(LDADD)
 check_y2k_DEPENDENCIES =  version.o ../libntp/libntp.a
 check_y2k_LDFLAGS = 
-am_ntpd_OBJECTS =  map_vme$U.o ntp_config$U.o ntp_control$U.o \
-ntp_crypto$U.o ntp_filegen$U.o ntp_intres$U.o ntp_io$U.o \
-ntp_loopfilter$U.o ntp_monitor$U.o ntp_peer$U.o ntp_proto$U.o \
-ntp_refclock$U.o ntp_request$U.o ntp_resolver$U.o ntp_restrict$U.o \
-ntp_timer$U.o ntp_util$U.o ntpd$U.o refclock_acts$U.o \
+am_ntpd_OBJECTS =  cmd_args$U.o map_vme$U.o ntp_config$U.o \
+ntp_control$U.o ntp_crypto$U.o ntp_filegen$U.o ntp_intres$U.o \
+ntp_io$U.o ntp_loopfilter$U.o ntp_monitor$U.o ntp_peer$U.o \
+ntp_proto$U.o ntp_refclock$U.o ntp_request$U.o ntp_resolver$U.o \
+ntp_restrict$U.o ntp_timer$U.o ntp_util$U.o ntpd$U.o refclock_acts$U.o \
 refclock_arbiter$U.o refclock_arc$U.o refclock_as2201$U.o \
 refclock_atom$U.o refclock_bancomm$U.o refclock_chronolog$U.o \
 refclock_chu$U.o refclock_conf$U.o refclock_datum$U.o \
@@ -186,15 +188,16 @@ DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 
 GZIP_ENV = --best
 depcomp = $(SHELL) $(top_srcdir)/depcomp
-DEP_FILES =  @AMDEP@ $(DEPDIR)/check_y2k$U.Po $(DEPDIR)/map_vme$U.Po \
-$(DEPDIR)/ntp_config$U.Po $(DEPDIR)/ntp_control$U.Po \
-$(DEPDIR)/ntp_crypto$U.Po $(DEPDIR)/ntp_filegen$U.Po \
-$(DEPDIR)/ntp_intres$U.Po $(DEPDIR)/ntp_io$U.Po \
-$(DEPDIR)/ntp_loopfilter$U.Po $(DEPDIR)/ntp_monitor$U.Po \
-$(DEPDIR)/ntp_peer$U.Po $(DEPDIR)/ntp_proto$U.Po \
-$(DEPDIR)/ntp_refclock$U.Po $(DEPDIR)/ntp_request$U.Po \
-$(DEPDIR)/ntp_resolver$U.Po $(DEPDIR)/ntp_restrict$U.Po \
-$(DEPDIR)/ntp_timer$U.Po $(DEPDIR)/ntp_util$U.Po $(DEPDIR)/ntpd$U.Po \
+DEP_FILES =  @AMDEP@ $(DEPDIR)/check_y2k$U.Po $(DEPDIR)/cmd_args$U.Po \
+$(DEPDIR)/map_vme$U.Po $(DEPDIR)/ntp_config$U.Po \
+$(DEPDIR)/ntp_control$U.Po $(DEPDIR)/ntp_crypto$U.Po \
+$(DEPDIR)/ntp_filegen$U.Po $(DEPDIR)/ntp_intres$U.Po \
+$(DEPDIR)/ntp_io$U.Po $(DEPDIR)/ntp_loopfilter$U.Po \
+$(DEPDIR)/ntp_monitor$U.Po $(DEPDIR)/ntp_peer$U.Po \
+$(DEPDIR)/ntp_proto$U.Po $(DEPDIR)/ntp_refclock$U.Po \
+$(DEPDIR)/ntp_request$U.Po $(DEPDIR)/ntp_resolver$U.Po \
+$(DEPDIR)/ntp_restrict$U.Po $(DEPDIR)/ntp_timer$U.Po \
+$(DEPDIR)/ntp_util$U.Po $(DEPDIR)/ntpd$U.Po \
 $(DEPDIR)/refclock_acts$U.Po $(DEPDIR)/refclock_arbiter$U.Po \
 $(DEPDIR)/refclock_arc$U.Po $(DEPDIR)/refclock_as2201$U.Po \
 $(DEPDIR)/refclock_atom$U.Po $(DEPDIR)/refclock_bancomm$U.Po \
@@ -298,6 +301,8 @@ ntpd: $(ntpd_OBJECTS) $(ntpd_DEPENDENCIES)
        $(LINK) $(ntpd_LDFLAGS) $(ntpd_OBJECTS) $(ntpd_LDADD) $(LIBS)
 check_y2k_.c: check_y2k.c $(ANSI2KNR)
        $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/check_y2k.c; then echo $(srcdir)/check_y2k.c; else echo check_y2k.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > check_y2k_.c
+cmd_args_.c: cmd_args.c $(ANSI2KNR)
+       $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/cmd_args.c; then echo $(srcdir)/cmd_args.c; else echo cmd_args.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > cmd_args_.c
 map_vme_.c: map_vme.c $(ANSI2KNR)
        $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/map_vme.c; then echo $(srcdir)/map_vme.c; else echo map_vme.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > map_vme_.c
 ntp_config_.c: ntp_config.c $(ANSI2KNR)
@@ -406,14 +411,15 @@ refclock_wwv_.c: refclock_wwv.c $(ANSI2KNR)
        $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/refclock_wwv.c; then echo $(srcdir)/refclock_wwv.c; else echo refclock_wwv.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > refclock_wwv_.c
 refclock_wwvb_.c: refclock_wwvb.c $(ANSI2KNR)
        $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/refclock_wwvb.c; then echo $(srcdir)/refclock_wwvb.c; else echo refclock_wwvb.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > refclock_wwvb_.c
-check_y2k_.o map_vme_.o ntp_config_.o ntp_control_.o ntp_crypto_.o \
-ntp_filegen_.o ntp_intres_.o ntp_io_.o ntp_loopfilter_.o ntp_monitor_.o \
-ntp_peer_.o ntp_proto_.o ntp_refclock_.o ntp_request_.o ntp_resolver_.o \
-ntp_restrict_.o ntp_timer_.o ntp_util_.o ntpd_.o refclock_acts_.o \
-refclock_arbiter_.o refclock_arc_.o refclock_as2201_.o refclock_atom_.o \
-refclock_bancomm_.o refclock_chronolog_.o refclock_chu_.o \
-refclock_conf_.o refclock_datum_.o refclock_dumbclock_.o refclock_fg_.o \
-refclock_gpsvme_.o refclock_heath_.o refclock_hpgps_.o refclock_irig_.o \
+check_y2k_.o cmd_args_.o map_vme_.o ntp_config_.o ntp_control_.o \
+ntp_crypto_.o ntp_filegen_.o ntp_intres_.o ntp_io_.o ntp_loopfilter_.o \
+ntp_monitor_.o ntp_peer_.o ntp_proto_.o ntp_refclock_.o ntp_request_.o \
+ntp_resolver_.o ntp_restrict_.o ntp_timer_.o ntp_util_.o ntpd_.o \
+refclock_acts_.o refclock_arbiter_.o refclock_arc_.o refclock_as2201_.o \
+refclock_atom_.o refclock_bancomm_.o refclock_chronolog_.o \
+refclock_chu_.o refclock_conf_.o refclock_datum_.o \
+refclock_dumbclock_.o refclock_fg_.o refclock_gpsvme_.o \
+refclock_heath_.o refclock_hpgps_.o refclock_irig_.o \
 refclock_jupiter_.o refclock_leitch_.o refclock_local_.o \
 refclock_msfees_.o refclock_mx4200_.o refclock_nmea_.o \
 refclock_oncore_.o refclock_palisade_.o refclock_parse_.o \
@@ -469,6 +475,7 @@ distdir: $(DISTFILES)
        done
 
 @AMDEP@include $(DEPDIR)/check_y2k$U.Po
+@AMDEP@include $(DEPDIR)/cmd_args$U.Po
 @AMDEP@include $(DEPDIR)/map_vme$U.Po
 @AMDEP@include $(DEPDIR)/ntp_config$U.Po
 @AMDEP@include $(DEPDIR)/ntp_control$U.Po
diff --git a/ntpd/cmd_args.c b/ntpd/cmd_args.c
new file mode 100644 (file)
index 0000000..538a2e0
--- /dev/null
@@ -0,0 +1,301 @@
+/*
+ * cmd_args.c = command-line argument processing
+ */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "ntpd.h"
+#include "ntp_stdlib.h"
+#include "ntp_cmdargs.h"
+
+/*
+ * Definitions of things either imported from or exported to outside
+ */
+char const *progname;
+int    listen_to_virtual_ips = 0;
+
+static const char *ntp_options = "aAbc:dD:f:gk:l:LmnN:p:P:r:s:t:v:V:x";
+
+
+/*
+ * getstartup - search through the options looking for a debugging flag
+ */
+void
+getstartup(
+       int argc,
+       char *argv[]
+       )
+{
+       int errflg;
+       int c;
+
+#ifdef DEBUG
+       debug = 0;              /* no debugging by default */
+#endif
+
+       /*
+        * This is a big hack.  We don't really want to read command line
+        * configuration until everything else is initialized, since
+        * the ability to configure the system may depend on storage
+        * and the like having been initialized.  Except that we also
+        * don't want to initialize anything until after detaching from
+        * the terminal, but we won't know to do that until we've
+        * parsed the command line.  Do that now, crudely, and do it
+        * again later.  Our ntp_getopt() is explicitly reusable, by the
+        * way.  Your own mileage may vary.
+        *
+        * This hack is even called twice (to allow complete logging to file)
+        */
+       errflg = 0;
+       progname = argv[0];
+
+       /*
+        * Decode argument list
+        */
+       while ((c = ntp_getopt(argc, argv, ntp_options)) != EOF)
+           switch (c) {
+#ifdef DEBUG
+               case 'd':
+                   ++debug;
+                   break;
+               case 'D':
+                   debug = (int)atol(ntp_optarg);
+                   printf("Debug1: %s -> %x = %d\n", ntp_optarg, debug, debug);
+                   break;
+#else
+               case 'd':
+               case 'D':
+                   msyslog(LOG_ERR, "ntpd not compiled with -DDEBUG option - no DEBUG support");
+                   fprintf(stderr, "ntpd not compiled with -DDEBUG option - no DEBUG support");
+                   ++errflg;
+                   break;
+#endif
+               case 'L':
+                   listen_to_virtual_ips = 1;
+                   break;
+               case 'l':
+                       {
+                               FILE *new_file;
+
+                               new_file = fopen(ntp_optarg, "a");
+                               if (new_file != NULL) {
+                                       NLOG(NLOG_SYSINFO)
+                                               msyslog(LOG_NOTICE, "logging to file %s", ntp_optarg);
+                                       if (syslog_file != NULL &&
+                                               fileno(syslog_file) != fileno(new_file))
+                                               (void)fclose(syslog_file);
+
+                                       syslog_file = new_file;
+                                       syslogit = 0;
+                               }
+                               else
+                                       msyslog(LOG_ERR,
+                                               "Cannot open log file %s",
+                                               ntp_optarg);
+                       }
+                       break;
+
+               case 'n':
+                   ++nofork;
+                   break;
+
+               case '?':
+                   ++errflg;
+                   break;
+
+               default:
+                       break;
+               }
+
+       if (errflg || ntp_optind != argc) {
+               (void) fprintf(stderr, "usage: %s [ -abdgmnx ] [ -c config_file ] [ -e e_delay ]\n", progname);
+               (void) fprintf(stderr, "\t\t[ -f freq_file ] [ -k key_file ] [ -l log_file ]\n");
+               (void) fprintf(stderr, "\t\t[ -p pid_file ] [ -r broad_delay ] [ -s statdir ]\n");
+               (void) fprintf(stderr, "\t\t[ -t trust_key ] [ -v sys_var ] [ -V default_sysvar ]\n");
+#if defined(HAVE_SCHED_SETSCHEDULER)
+               (void) fprintf(stderr, "\t\t[ -P fixed_process_priority ]\n");
+#endif
+               exit(2);
+       }
+       ntp_optind = 0; /* reset ntp_optind to restart ntp_getopt */
+
+#ifdef DEBUG
+       if (debug) {
+#ifdef HAVE_SETVBUF
+               static char buf[BUFSIZ];
+               setvbuf(stdout, buf, _IOLBF, BUFSIZ);
+#else
+               setlinebuf(stdout);
+#endif
+       }
+#endif
+}
+
+/*
+ * getCmdOpts - get command line options
+ */
+void
+getCmdOpts(
+       int argc,
+       char *argv[]
+       )
+{
+       extern char *config_file;
+       extern int priority_done;
+       int errflg;
+       int c;
+
+       /*
+        * Initialize, initialize
+        */
+       errflg = 0;
+#ifdef DEBUG
+       debug = 0;
+#endif /* DEBUG */
+
+       progname = argv[0];
+
+       /*
+        * Decode argument list
+        */
+       while ((c = ntp_getopt(argc, argv, ntp_options)) != EOF) {
+               switch (c) {
+                   case 'a':
+                       proto_config(PROTO_AUTHENTICATE, 1, 0.);
+                       break;
+
+                   case 'A':
+                       proto_config(PROTO_AUTHENTICATE, 0, 0.);
+                       break;
+
+                   case 'b':
+                       proto_config(PROTO_BROADCLIENT, 1, 0.);
+                       break;
+
+                   case 'c':
+                       config_file = ntp_optarg;
+#ifdef HAVE_NETINFO
+                       check_netinfo = 0;
+#endif
+                       break;
+
+                   case 'd':
+#ifdef DEBUG
+                       debug++;
+#else
+                       errflg++;
+#endif /* DEBUG */
+                       break;
+
+                   case 'D':
+#ifdef DEBUG
+                       debug = (int)atol(ntp_optarg);
+                       printf("Debug2: %s -> %x = %d\n", ntp_optarg, debug, debug);
+#else
+                       errflg++;
+#endif /* DEBUG */
+                       break;
+
+                   case 'f':
+                       stats_config(STATS_FREQ_FILE, ntp_optarg);
+                       break;
+
+                   case 'g':
+                       correct_any = TRUE;
+                       break;
+
+                   case 'k':
+                       getauthkeys(ntp_optarg);
+                       break;
+
+                   case 'L':   /* already done at pre-scan */
+                   case 'l':   /* already done at pre-scan */
+                       break;
+
+                   case 'm':
+                       proto_config(PROTO_MULTICAST_ADD, htonl(INADDR_NTP), 0.);
+                       sys_bclient = 1;
+                       break;
+
+                   case 'n':   /* already done at pre-scan */
+                       break;
+
+                   case 'N':
+                       priority_done = strcmp(ntp_optarg, "high");
+                       break;
+
+                   case 'p':
+                       stats_config(STATS_PID_FILE, ntp_optarg);
+                       break;
+
+                   case 'P':
+#if defined(HAVE_SCHED_SETSCHEDULER)
+                       config_priority = (int)atol(ntp_optarg);
+                       config_priority_override = 1;
+#else
+                       errflg++;
+#endif
+                       break;
+
+                   case 'r':
+                       do {
+                               double tmp;
+
+                               if (sscanf(ntp_optarg, "%lf", &tmp) != 1) {
+                                       msyslog(LOG_ERR,
+                                               "command line broadcast delay value %s undecodable",
+                                               ntp_optarg);
+                               } else {
+                                       proto_config(PROTO_BROADDELAY, 0, tmp);
+                               }
+                       } while (0);
+                       break;
+                       
+                   case 's':
+                       stats_config(STATS_STATSDIR, ntp_optarg);
+                       break;
+                       
+                   case 't':
+                       do {
+                               u_long tkey;
+                               
+                               tkey = (int)atol(ntp_optarg);
+                               if (tkey <= 0 || tkey > NTP_MAXKEY) {
+                                       msyslog(LOG_ERR,
+                                           "command line trusted key %s is invalid",
+                                           ntp_optarg);
+                               } else {
+                                       authtrust(tkey, 1);
+                               }
+                       } while (0);
+                       break;
+
+                   case 'v':
+                   case 'V':
+                       set_sys_var(ntp_optarg, strlen(ntp_optarg)+1,
+                           RW | ((c == 'V') ? DEF : 0));
+                       break;
+
+                   case 'x':
+                       allow_set_backward = FALSE;
+                       break;
+
+                   default:
+                       errflg++;
+                       break;
+               }
+       }
+
+       if (errflg || ntp_optind != argc) {
+               (void) fprintf(stderr, "usage: %s [ -abdgmnx ] [ -c config_file ] [ -e e_delay ]\n", progname);
+               (void) fprintf(stderr, "\t\t[ -f freq_file ] [ -k key_file ] [ -l log_file ]\n");
+               (void) fprintf(stderr, "\t\t[ -p pid_file ] [ -r broad_delay ] [ -s statdir ]\n");
+               (void) fprintf(stderr, "\t\t[ -t trust_key ] [ -v sys_var ] [ -V default_sysvar ]\n");
+#if defined(HAVE_SCHED_SETSCHEDULER)
+               (void) fprintf(stderr, "\t\t[ -P fixed_process_priority ]\n");
+#endif
+               exit(2);
+       }
+       return;
+}
index 7c2693c1e09e98c97987a7f15ac3356df487764b..f458b914428366cb8e5dcf103858e989a89db6c4 100644 (file)
@@ -31,6 +31,7 @@
 #include "ntp_filegen.h"
 #include "ntp_stdlib.h"
 #include "ntp_config.h"
+#include "ntp_cmdargs.h"
 
 #ifdef PUBKEY
 #include "ntp_crypto.h"
@@ -465,13 +466,22 @@ char      sys_phone[MAXPHONE][MAXDIAL]; /* ACTS phone numbers */
 char   pps_device[MAXPPS + 1]; /* PPS device name */
 int    pps_assert = 1;
 int    pps_hardpps;
-int    listen_to_virtual_ips = 0;
 #if defined(HAVE_SCHED_SETSCHEDULER)
 int    config_priority_override = 0;
 int    config_priority;
 #endif
 
-static const char *ntp_options = "aAbc:dD:f:gk:l:LmnN:p:P:r:s:t:v:V:x";
+const char *config_file;
+#ifdef HAVE_NETINFO
+ struct netinfo_config_state *config_netinfo = NULL;
+ int check_netinfo = 1;
+#endif /* HAVE_NETINFO */
+#ifdef SYS_WINNT
+ char *alt_config_file;
+ LPTSTR temp;
+ char config_file_storage[MAX_PATH];
+ char alt_config_file_storage[MAX_PATH];
+#endif /* SYS_WINNT */
 
 #ifdef HAVE_NETINFO
 /*
@@ -572,119 +582,6 @@ get_logmask(
        return 0;
 }
 
-/*
- * getstartup - search through the options looking for a debugging flag
- */
-void
-getstartup(
-       int argc,
-       char *argv[]
-       )
-{
-       int errflg;
-       int c;
-
-#ifdef DEBUG
-       debug = 0;              /* no debugging by default */
-#endif
-
-       /*
-        * This is a big hack.  We don't really want to read command line
-        * configuration until everything else is initialized, since
-        * the ability to configure the system may depend on storage
-        * and the like having been initialized.  Except that we also
-        * don't want to initialize anything until after detaching from
-        * the terminal, but we won't know to do that until we've
-        * parsed the command line.  Do that now, crudely, and do it
-        * again later.  Our ntp_getopt() is explicitly reusable, by the
-        * way.  Your own mileage may vary.
-        *
-        * This hack is even called twice (to allow complete logging to file)
-        */
-       errflg = 0;
-       progname = argv[0];
-
-       /*
-        * Decode argument list
-        */
-       while ((c = ntp_getopt(argc, argv, ntp_options)) != EOF)
-           switch (c) {
-#ifdef DEBUG
-               case 'd':
-                   ++debug;
-                   break;
-               case 'D':
-                   debug = (int)atol(ntp_optarg);
-                   printf("Debug1: %s -> %x = %d\n", ntp_optarg, debug, debug);
-                   break;
-#else
-               case 'd':
-               case 'D':
-                   msyslog(LOG_ERR, "ntpd not compiled with -DDEBUG option - no DEBUG support");
-                   fprintf(stderr, "ntpd not compiled with -DDEBUG option - no DEBUG support");
-                   ++errflg;
-                   break;
-#endif
-               case 'L':
-                   listen_to_virtual_ips = 1;
-                   break;
-               case 'l':
-                       {
-                               FILE *new_file;
-
-                               new_file = fopen(ntp_optarg, "a");
-                               if (new_file != NULL) {
-                                       NLOG(NLOG_SYSINFO)
-                                               msyslog(LOG_NOTICE, "logging to file %s", ntp_optarg);
-                                       if (syslog_file != NULL &&
-                                               fileno(syslog_file) != fileno(new_file))
-                                               (void)fclose(syslog_file);
-
-                                       syslog_file = new_file;
-                                       syslogit = 0;
-                               }
-                               else
-                                       msyslog(LOG_ERR,
-                                               "Cannot open log file %s",
-                                               ntp_optarg);
-                       }
-                       break;
-
-               case 'n':
-                   ++nofork;
-                   break;
-
-               case '?':
-                   ++errflg;
-                   break;
-
-               default:
-                       break;
-               }
-
-       if (errflg || ntp_optind != argc) {
-               (void) fprintf(stderr, "usage: %s [ -abdgmnx ] [ -c config_file ] [ -e e_delay ]\n", progname);
-               (void) fprintf(stderr, "\t\t[ -f freq_file ] [ -k key_file ] [ -l log_file ]\n");
-               (void) fprintf(stderr, "\t\t[ -p pid_file ] [ -r broad_delay ] [ -s statdir ]\n");
-               (void) fprintf(stderr, "\t\t[ -t trust_key ] [ -v sys_var ] [ -V default_sysvar ]\n");
-#if defined(HAVE_SCHED_SETSCHEDULER)
-               (void) fprintf(stderr, "\t\t[ -P fixed_process_priority ]\n");
-#endif
-               exit(2);
-       }
-       ntp_optind = 0; /* reset ntp_optind to restart ntp_getopt */
-
-#ifdef DEBUG
-       if (debug) {
-#ifdef HAVE_SETVBUF
-               static char buf[BUFSIZ];
-               setvbuf(stdout, buf, _IOLBF, BUFSIZ);
-#else
-               setlinebuf(stdout);
-#endif
-       }
-#endif
-}
 
 /*
  * getconfig - get command line options and read the configuration file
@@ -716,17 +613,6 @@ getconfig(
        int ntokens;
        int tok = CONFIG_UNKNOWN;
        struct interface *localaddr;
-       const char *config_file;
-#ifdef HAVE_NETINFO
-       struct netinfo_config_state *config_netinfo = NULL;
-       int check_netinfo = 1;
-#endif /* HAVE_NETINFO */
-#ifdef SYS_WINNT
-       char *alt_config_file;
-       LPTSTR temp;
-       char config_file_storage[MAX_PATH];
-       char alt_config_file_storage[MAX_PATH];
-#endif /* SYS_WINNT */
        struct refclockstat clock_stat;
        FILEGEN *filegen;
 
@@ -777,147 +663,7 @@ getconfig(
         */
        loop_config(LOOP_DRIFTINIT, 0.);
 
-       /*
-        * Decode argument list
-        */
-       while ((c = ntp_getopt(argc, argv, ntp_options)) != EOF) {
-               switch (c) {
-                   case 'a':
-                       proto_config(PROTO_AUTHENTICATE, 1, 0.);
-                       break;
-
-                   case 'A':
-                       proto_config(PROTO_AUTHENTICATE, 0, 0.);
-                       break;
-
-                   case 'b':
-                       proto_config(PROTO_BROADCLIENT, 1, 0.);
-                       break;
-
-                   case 'c':
-                       config_file = ntp_optarg;
-#ifdef HAVE_NETINFO
-                       check_netinfo = 0;
-#endif
-                       break;
-
-                   case 'd':
-#ifdef DEBUG
-                       debug++;
-#else
-                       errflg++;
-#endif /* DEBUG */
-                       break;
-
-                   case 'D':
-#ifdef DEBUG
-                       debug = (int)atol(ntp_optarg);
-                       printf("Debug2: %s -> %x = %d\n", ntp_optarg, debug, debug);
-#else
-                       errflg++;
-#endif /* DEBUG */
-                       break;
-
-                   case 'f':
-                       stats_config(STATS_FREQ_FILE, ntp_optarg);
-                       break;
-
-                   case 'g':
-                       correct_any = TRUE;
-                       break;
-
-                   case 'k':
-                       getauthkeys(ntp_optarg);
-                       break;
-
-                   case 'L':   /* already done at pre-scan */
-                   case 'l':   /* already done at pre-scan */
-                       break;
-
-                   case 'm':
-                       proto_config(PROTO_MULTICAST_ADD, htonl(INADDR_NTP), 0.);
-                       sys_bclient = 1;
-                       break;
-
-                   case 'n':   /* already done at pre-scan */
-                       break;
-
-                   case 'N':
-                       priority_done = strcmp(ntp_optarg, "high");
-                       break;
-
-                   case 'p':
-                       stats_config(STATS_PID_FILE, ntp_optarg);
-                       break;
-
-                   case 'P':
-#if defined(HAVE_SCHED_SETSCHEDULER)
-                       config_priority = (int)atol(ntp_optarg);
-                       config_priority_override = 1;
-#else
-                       errflg++;
-#endif
-                       break;
-
-                   case 'r':
-                       do {
-                               double tmp;
-
-                               if (sscanf(ntp_optarg, "%lf", &tmp) != 1) {
-                                       msyslog(LOG_ERR,
-                                               "command line broadcast delay value %s undecodable",
-                                               ntp_optarg);
-                               } else {
-                                       proto_config(PROTO_BROADDELAY, 0, tmp);
-                               }
-                       } while (0);
-                       break;
-                       
-                   case 's':
-                       stats_config(STATS_STATSDIR, ntp_optarg);
-                       break;
-                       
-                   case 't':
-                       do {
-                               u_long tkey;
-                               
-                               tkey = (int)atol(ntp_optarg);
-                               if (tkey <= 0 || tkey > NTP_MAXKEY) {
-                                       msyslog(LOG_ERR,
-                                           "command line trusted key %s is invalid",
-                                           ntp_optarg);
-                               } else {
-                                       authtrust(tkey, 1);
-                               }
-                       } while (0);
-                       break;
-
-                   case 'v':
-                   case 'V':
-                       set_sys_var(ntp_optarg, strlen(ntp_optarg)+1,
-                           RW | ((c == 'V') ? DEF : 0));
-                       break;
-
-                   case 'x':
-                       allow_set_backward = FALSE;
-                       break;
-
-                   default:
-                       errflg++;
-                       break;
-               }
-       }
-
-       if (errflg || ntp_optind != argc) {
-               (void) fprintf(stderr, "usage: %s [ -abdgmnx ] [ -c config_file ] [ -e e_delay ]\n", progname);
-               (void) fprintf(stderr, "\t\t[ -f freq_file ] [ -k key_file ] [ -l log_file ]\n");
-               (void) fprintf(stderr, "\t\t[ -p pid_file ] [ -r broad_delay ] [ -s statdir ]\n");
-               (void) fprintf(stderr, "\t\t[ -t trust_key ] [ -v sys_var ] [ -V default_sysvar ]\n");
-#if defined(HAVE_SCHED_SETSCHEDULER)
-               (void) fprintf(stderr, "\t\t[ -P fixed_process_priority ]\n");
-#endif
-               exit(2);
-       }
+       getCmdOpts(argc, argv);
 
        if (
            (fp = fopen(FindConfig(config_file), "r")) == NULL
index f9d7ee845c0552150179faa88777ca7fcf615c25..33d076a2d395c6e6542e4fab40e46d4af417b859 100644 (file)
@@ -1,15 +1,29 @@
 /*
  * Program to generate MD5 and RSA keys for NTP clients and servers
  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
 #include <stdio.h>
 #include <sys/types.h>
 #include <unistd.h>
 #include <sys/time.h>
+
+#ifdef HAVE_NETINFO
+#include <netinfo/ni.h>
+#endif
+
 #include "ntpd.h"
 #include "ntp_stdlib.h"
 #include "ntp_string.h"
-#include "ntp_crypto.h"
 #include "ntp_unixtime.h"
+#include "ntp_config.h"
+
+#ifdef PUBKEY
+# include "ntp_crypto.h"
+#endif
 
 /*
  * Cryptodefines
@@ -145,20 +159,51 @@ main(
        mode_t std_mask;        /* Standard mask */
        mode_t sec_mask = 077;  /* Secure mask */
        char *config_file;
+#ifdef HAVE_NETINFO
+       struct netinfo_config_state *config_netinfo = NULL;
+       int check_netinfo = 1;
+#endif /* HAVE_NETINFO */
+#ifdef SYS_WINNT
+       char *alt_config_file;
+       LPTSTR temp;
+       char config_file_storage[MAX_PATH];
+       char alt_config_file_storage[MAX_PATH];
+#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 nosymlinks = 0;     /* Just create the (timestamped) files? */
        int trash = 0;          /* Trash old files? */
+       int errflag = 0;
 
        /* Initialize config_file */
-       /* What abuot netinfo? */
+       /* HMS: from ntp_config.c - we should use 1 copy of this... */
+#ifndef SYS_WINNT
+       config_file = CONFIG_FILE;
+#else
+       temp = CONFIG_FILE;
+       if (!ExpandEnvironmentStrings((LPCTSTR)temp, (LPTSTR)config_file_storage, (DWORD)sizeof(config_file_storage))) {
+               msyslog(LOG_ERR, "ExpandEnvironmentStrings CONFIG_FILE failed: %m\n");
+               exit(1);
+       }
+       config_file = config_file_storage;
+
+       temp = ALT_CONFIG_FILE;
+       if (!ExpandEnvironmentStrings((LPCTSTR)temp, (LPTSTR)alt_config_file_storage, (DWORD)sizeof(alt_config_file_storage))) {
+               msyslog(LOG_ERR, "ExpandEnvironmentStrings ALT_CONFIG_FILE failed: %m\n");
+               exit(1);
+       }
+       alt_config_file = alt_config_file_storage;
+#endif /* SYS_WINNT */
 
        while ((i = ntp_getopt(argc, argv, "c:dflmrt")) != EOF)
                switch (i) {
                    case 'c':
                        config_file = ntp_optarg;
+#ifdef HAVE_NETINFO
+                       check_netinfo = 0;
+#endif
                        break;
                    case 'd':
                        ++make_dh;
@@ -179,11 +224,14 @@ main(
                        ++trash;
                        break;
                    case '?':
-                       usage();
+                       ++errflag;
                        break;
                }
 
-       /* If no type were specified, for for them all. */
+       if (errflag)
+               usage();
+
+       /* If no file type was specified, make them all. */
        if (!(make_dh | make_md5 | make_rsa)) {
                ++make_dh;
                ++make_md5;
@@ -209,6 +257,22 @@ main(
          We need 2 variables per file:
          - the specified location of the file 
          - the file it points to (if it's a symlink)
+
+         We:
+         - get each target filename
+         - if it exists, if it's a symlink get the "target"
+         - for each file we're going to install:
+         - - build the new timestamped file
+         - - install it with the timestamp suffix
+         - - If it's OK to make links:
+         - - - remove any old link
+         - - - make any needed directories?
+         - - - make the link
+         - - - remove the old file (if (trash))
+
+         We'll probably learn about how the link should be installed.
+         We will start by using fully-rooted paths, but we should use
+         whatever information we have from the old link.
        */
 
        std_mask = umask(sec_mask); /* Get the standard mask */