]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
ntp_control.c:
authorJohannes Maximilian Kuehn <kuehn@ntp.org>
Fri, 14 Aug 2009 17:15:30 +0000 (02:15 +0900)
committerJohannes Maximilian Kuehn <kuehn@ntp.org>
Fri, 14 Aug 2009 17:15:30 +0000 (02:15 +0900)
  Handling the dumpfile argument of the dumpcfg command
ntp_config.c:
  Config dumper: Combined the server and fudge output
ntpq-subs.c:
  Added the dumpfile argument to the dumpcfg command

bk: 4a859bb2mov2_1VtSE3TrWgNFYlWlg

ntpd/ntp_config.c
ntpd/ntp_control.c
ntpq/ntpq-subs.c

index d6276e15a5d5986d92b0978a7de984c7afb8913a..7f25364a25bb19a74e8270f7881e3fe2bd79555d 100644 (file)
@@ -428,6 +428,21 @@ free_config_tree(struct config_tree *ptree)
 }
 #endif /* DEBUG */
 
+/* Dump all trees */
+int
+dump_all_config_trees (
+               FILE *df
+               ) 
+{
+       struct config_tree *cfg_ptr = cfg_tree_history;
+       int return_value = 0;
+
+       for(; cfg_ptr != NULL; cfg_ptr = cfg_ptr->prior) 
+               return_value |= dump_config_tree(cfg_ptr, df);
+
+       return return_value;
+}
+
 
 /* The config dumper */
 int
@@ -454,7 +469,7 @@ dump_config_tree(
        void *opts = NULL;
        char refid[5];
 
-       printf("dump_config_tree(%p):\n", ptree);
+       printf("dump_config_tree(%p)\n", ptree);
 
        list_ptr = queue_head(ptree->peers);
        for (;  list_ptr != NULL;
@@ -473,9 +488,14 @@ dump_config_tree(
                                fudge_ptr = next_node(fudge_ptr)) {
 
 
-                               addr_opts = (struct addr_opts_node *) list_ptr;
+                               addr_opts = (struct addr_opts_node *) fudge_ptr; 
+                               struct address_node *peer_addr = peers->addr;
+                               struct address_node *fudge_addr = addr_opts->addr;
+
+                               char *s1 = peer_addr->address;
+                               char *s2 = fudge_addr->address;
 
-                               if(!strcmp((peers->addr)->address, (addr_opts->addr)->address)) {
+                               if(!strcmp(s1, s2)) {
 
                                fprintf(df, "fudge %s", addr_opts->addr->address);
        
@@ -853,7 +873,7 @@ dump_config_tree(
 
                        atrv = (struct attr_val *) list_ptr;
 
-                       fprintf(df, "enable");
+                       fprintf(df, "enable ");
 
                        switch(atrv->attr) {
                                case T_Autokey: 
@@ -922,7 +942,7 @@ dump_config_tree(
        list_ptr = queue_head(ptree->disable_opts);
        if (list_ptr != NULL) {
 
-               fprintf(df, "disable");
+               fprintf(df, "disable ");
 
                for(;   list_ptr != NULL;
                        list_ptr = next_node(list_ptr)) {
@@ -3475,6 +3495,7 @@ config_remotely(void)
        yyparse();
        delete_keyword_scanner(key_scanner);
        key_scanner = NULL;
+       cfgt.source.attr = CONF_SOURCE_NTPQ;
 
        DPRINTF(1, ("Finished Parsing!!\n"));
 
@@ -3559,10 +3580,19 @@ getconfig(
                        msyslog(LOG_INFO, "getconfig: Couldn't open <%s>", FindConfig(alt_config_file));
                        return;
                }
+               else {
+                       cfgt.source.value.s = (char *) emalloc(strlen(alt_config_file));
+                       strcpy(cfgt.source.value.s, alt_config_file);
+               }
+
 #else  /* not SYS_WINNT */
                return;
 #endif /* not SYS_WINNT */
        }
+       else {
+               cfgt.source.value.s = (char *) emalloc(strlen(config_file));
+               strcpy(cfgt.source.value.s, config_file);
+       }
 
        /*** BULK OF THE PARSER ***/
        ip_file = fp[curr_include_level];
@@ -3575,6 +3605,9 @@ getconfig(
 
        DPRINTF(1, ("Finished Parsing!!\n"));
 
+       cfgt.source.attr = CONF_SOURCE_FILE;    
+       cfgt.timestamp = time(NULL);
+
        save_and_apply_config_tree();
 
        while (curr_include_level != -1) {
index b67034f6f6444401102ec7da66e17fcf509aa9bf..423d6f10eec90d497b3c8c1828557b4ca72e4aa8 100644 (file)
@@ -557,13 +557,24 @@ dump_config(
        char filename[80];
        char reply[80];
 
-       snprintf(filename, 80, "ntp_dump%i.conf", time(NULL));
+       FILE *fptr = NULL;
 
-       if(dump_config_dumper(filename) == -1) 
+       if((reqend - reqpt) == 0) {
+               snprintf(filename, 80, "ntp_dump%i.conf", time(NULL));
+       }
+       else {
+               strncpy(filename, reqpt, 80);
+       }
+
+       fptr = fopen(filename, "w+");
+
+       if(dump_all_config_trees(fptr) == -1) 
                snprintf(reply, 80, "Couldn't dump to file %s", filename);
        else 
                snprintf(reply, 80, "Dumped to config file %s", filename);
 
+       fclose(fptr);
+
        ctl_putdata(reply, strlen(reply), 0);
        ctl_flushpkt(0);
 }
index e78a7f2ada9902182256f24decce237fee83b205..9a95d0dfc4197dbcd4013ca1d80d28545ab5b3b8 100644 (file)
@@ -72,8 +72,8 @@ static  void    config_from_file (struct parse *, FILE *);
  * Commands we understand.     Ntpdc imports this.
  */
 struct xcmd opcmds[] = {
-       { "dumpcfg", dumpcfg, { NO, NO, NO, NO },
-               { "", "", "", ""}, 
+       { "dumpcfg", dumpcfg, { NTP_STR, NO, NO, NO },
+               { "dumpfile", "", "", ""}, 
                "dump ntp server configuration"},
        { "associations", associations, {  NO, NO, NO, NO },
          { "", "", "", "" },
@@ -1183,17 +1183,16 @@ dumpcfg(
        u_short rstatus;
        register int a = 0;
 
-       printf("%s\n", pcmd->keyword);
-
-       for(; a<pcmd->nargs; a++) 
-               printf("%s\n", pcmd->argval[a]);
-
-
-       /* For now let's just send a "signal" and have it realize the dump op */
-       res = doquery(CTL_OP_DUMPCONFIG, 0, 0, 0, (char *)0, &rstatus,
-                       &dsize, &datap);
-
-       printf("ntpq: res = %i %s\n", res, datap);
+       /* Is there a way to make an argument optional? */
+       if(pcmd->nargs > 0) {
+               res = doquery(CTL_OP_DUMPCONFIG, 0, 0, strlen(pcmd->argval[0].string), 
+                       pcmd->argval[0].string, &rstatus, &dsize, &datap);
+       }
+       else {
+               res = doquery(CTL_OP_DUMPCONFIG, 0, 0, 0, (char *) 0, 
+                       &rstatus, &dsize, &datap);
+               printf("No filename supplied\n");
+       }
 }