]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
ChangeLog, ntp_config.h, ntp_config.c:
authorHarlan Stenn <stenn@ntp.org>
Mon, 11 Jun 2001 03:08:51 +0000 (03:08 -0000)
committerHarlan Stenn <stenn@ntp.org>
Mon, 11 Jun 2001 03:08:51 +0000 (03:08 -0000)
  * ntpd/ntp_config.c:
  * include/ntp_config.h: includefile config keyword support
  From: Dean Gibson <timekeeper@tcp-udp.net>

bk: 3b243643htryMxsAkuQz4za1UPlW0w

ChangeLog
include/ntp_config.h
ntpd/ntp_config.c

index 70741991704d5f438e2da9c15b61bf0dd1cefad1..a75399616b459e085f38086bbeaa603540ebf080 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2001-06-10  Harlan Stenn  <stenn@whimsy.udel.edu>
+
+       * ntpd/ntp_config.c:
+       * include/ntp_config.h: includefile config keyword support
+       From: Dean Gibson <timekeeper@tcp-udp.net>
+
 2001-06-08  Harlan Stenn  <stenn@whimsy.udel.edu>
 
        * configure.in: 4.0.99m-rc1b
index d14c5dc1023bdd99a7049328137caabf4ed16dab..92f5cd116c1d4c1431dbe8cdf3bd321efbc99eb9 100644 (file)
@@ -55,6 +55,7 @@
 #define CONFIG_CRYPTO          34
 #define CONFIG_KEYSDIR         35
 #endif /* PUBKEY */
+#define CONFIG_INCLUDEFILE     36
 
 /*
  * "peer", "server", "broadcast" modifier keywords
index 3f0e72db55edabe32027747c073e8cf2c8817c7a..d064403726498ae0461a694bdfa38b316087c2e5 100644 (file)
@@ -114,6 +114,7 @@ static      struct keyword keywords[] = {
        { "enable",             CONFIG_ENABLE },
        { "filegen",            CONFIG_FILEGEN },
        { "fudge",              CONFIG_FUDGE },
+       { "includefile",        CONFIG_INCLUDEFILE },
        { "keys",               CONFIG_KEYS },
 #ifdef PUBKEY
        { "keysdir",            CONFIG_KEYSDIR },
@@ -326,6 +327,7 @@ static struct masks logcfg_item[] = {
 #define MAXLINE                1024    /* maximum length of line */
 #define MAXPHONE       5       /* maximum number of phone strings */
 #define MAXPPS         20      /* maximum length of PPS device string */
+#define MAXINCLUDELEVEL        5       /* maximum include file levels */
 
 /*
  * Miscellaneous macros
@@ -499,7 +501,9 @@ getconfig(
        int hmode;
        struct sockaddr_in peeraddr;
        struct sockaddr_in maskaddr;
-       FILE *fp;
+       FILE *fp[MAXINCLUDELEVEL+1];
+       FILE *includefile;
+       int includelevel = 0;
        char line[MAXLINE];
        char *(tokens[MAXTOKENS]);
        int ntokens;
@@ -556,7 +560,7 @@ getconfig(
        getCmdOpts(argc, argv);
 
        if (
-           (fp = fopen(FindConfig(config_file), "r")) == NULL
+           (fp[0] = fopen(FindConfig(config_file), "r")) == NULL
 #ifdef HAVE_NETINFO
            /* If there is no config_file, try NetInfo. */
            && check_netinfo && !(config_netinfo = get_netinfo_config())
@@ -567,7 +571,7 @@ getconfig(
 #ifdef SYS_WINNT
                /* Under WinNT try alternate_config_file name, first NTP.CONF, then NTP.INI */
 
-               if ((fp = fopen(FindConfig(alt_config_file), "r")) == NULL) {
+               if ((fp[0] = fopen(FindConfig(alt_config_file), "r")) == NULL) {
 
                        /*
                         * Broadcast clients can sometimes run without
@@ -584,14 +588,21 @@ getconfig(
        }
 
        for (;;) {
-               if (fp)
-                       tok = gettokens(fp, line, tokens, &ntokens);
+               if (fp[includelevel])
+                       tok = gettokens(fp[includelevel], line, tokens, &ntokens);
 #ifdef HAVE_NETINFO
                else
                        tok = gettokens_netinfo(config_netinfo, tokens, &ntokens);
 #endif /* HAVE_NETINFO */
 
-               if (tok == CONFIG_UNKNOWN) break;
+               if (tok == CONFIG_UNKNOWN) {
+                   if (includelevel > 0) {
+                       fclose(fp[includelevel--]);
+                       continue;
+                   } else {
+                       break;
+                   }
+               }
 
                switch(tok) {
                    case CONFIG_PEER:
@@ -818,6 +829,25 @@ getconfig(
                            stats_config(STATS_PID_FILE, (char *)0);
                        break;
 
+                   case CONFIG_INCLUDEFILE:
+                       if (ntokens < 2) {
+                           msyslog(LOG_ERR, "includefile needs one argument");
+                           break;
+                       }
+                       if (includelevel >= MAXINCLUDELEVEL) {
+                           fprintf(stderr, "getconfig: Maximum include file level exceeded.\n");
+                           msyslog(LOG_INFO, "getconfig: Maximum include file level exceeded.");
+                           break;
+                       }
+                       includefile = fopen(FindConfig(tokens[1]), "r");
+                       if (includefile == NULL) {
+                           fprintf(stderr, "getconfig: Couldn't open <%s>\n", FindConfig(tokens[1]));
+                           msyslog(LOG_INFO, "getconfig: Couldn't open <%s>", FindConfig(tokens[1]));
+                           break;
+                       }
+                       fp[++includelevel] = includefile;
+                       break;
+
                    case CONFIG_LOGFILE:
                        if (ntokens >= 2) {
                                FILE *new_file;
@@ -1626,8 +1656,8 @@ getconfig(
                        break;
                }
        }
-       if (fp)
-               (void)fclose(fp);
+       if (fp[0])
+               (void)fclose(fp[0]);
 
 #ifdef HAVE_NETINFO
        if (config_netinfo)