From: Harlan Stenn Date: Tue, 5 Jun 2007 06:28:01 +0000 (-0400) Subject: indentation cleanup X-Git-Tag: NTP_4_2_5P45~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=63599d1dab91744490c57da8b1fbc80dbb797617;p=thirdparty%2Fntp.git indentation cleanup bk: 46650271mLiDAQZTk415UeC1xyee9w --- diff --git a/ntpd/ntp_config.c b/ntpd/ntp_config.c index 57aed65ed..e89f3230f 100644 --- a/ntpd/ntp_config.c +++ b/ntpd/ntp_config.c @@ -31,7 +31,7 @@ #include #include #ifdef HAVE_SYS_PARAM_H -#include +# include #endif #include #ifndef SIGCHLD @@ -142,14 +142,14 @@ int config_priority; const char *config_file; #ifdef HAVE_NETINFO - struct netinfo_config_state *config_netinfo = NULL; - int check_netinfo = 1; +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]; +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 @@ -172,12 +172,13 @@ int input_from_file = 1; /* A boolean flag, which when set, indicates that file, instead of the remote-configuration buffer */ /* int newline_is_special = 1; */ /* A boolean flag, which when set, implies that - newlines are special characters that need to - be returned as tokens */ + newlines are special characters that need to + be returned as tokens */ -int old_config_style = 1; /* A boolean flag, which when set, indicates that the - * old configuration format with a newline at the end - * of every command is being used +int old_config_style = 1; /* A boolean flag, which when set, + * indicates that the old configuration + * format with a newline at the end of + * every command is being used */ extern int sys_maxclock; @@ -218,7 +219,7 @@ enum gnn_type { t_UNK, /* Unknown */ t_REF, /* Refclock */ t_MSK, /* Network Mask */ - }; +}; static unsigned long get_pfxmatch(char **s,struct masks *m); static unsigned long get_match(char *s,struct masks *m); @@ -234,582 +235,665 @@ static void do_resolve_internal(void); * ---------------------------- */ -static int get_flags_from_list(queue *flag_list) +static int +get_flags_from_list( + queue *flag_list + ) { - int flags = 0; - struct attr_val *curr_flag; + int flags = 0; + struct attr_val *curr_flag; - while (!empty(flag_list)) { - curr_flag = (struct attr_val *) dequeue(flag_list); - flags |= curr_flag->value.i; - free_node(curr_flag); - } - return flags; + while (!empty(flag_list)) { + curr_flag = (struct attr_val *) dequeue(flag_list); + flags |= curr_flag->value.i; + free_node(curr_flag); + } + return flags; } -static void init_auth_node() +static void +init_auth_node(void) { - my_config.auth.autokey = 0; - my_config.auth.control_key = 0; - my_config.auth.crypto_cmd_list = NULL; - my_config.auth.keys = NULL; - my_config.auth.keysdir = NULL; - my_config.auth.requested_key = 0; - my_config.auth.revoke = 0; - my_config.auth.trusted_key_list = NULL; + my_config.auth.autokey = 0; + my_config.auth.control_key = 0; + my_config.auth.crypto_cmd_list = NULL; + my_config.auth.keys = NULL; + my_config.auth.keysdir = NULL; + my_config.auth.requested_key = 0; + my_config.auth.revoke = 0; + my_config.auth.trusted_key_list = NULL; } -static void init_syntax_tree() +static void +init_syntax_tree(void) { - my_config.peers = create_queue(); - my_config.orphan_cmds = create_queue(); + my_config.peers = create_queue(); + my_config.orphan_cmds = create_queue(); - my_config.broadcastclient = 0; - my_config.manycastserver = create_queue(); - my_config.multicastclient = create_queue(); - - my_config.stats_list = create_queue(); - my_config.stats_dir = NULL; - my_config.filegen_opts = create_queue(); - - my_config.discard_opts = create_queue(); - my_config.restrict_opts = create_queue(); - - my_config.enable_opts = create_queue(); - my_config.disable_opts = create_queue(); - my_config.tinker = create_queue(); - my_config.fudge = create_queue(); - - my_config.logconfig = create_queue(); - my_config.phone = create_queue(); - my_config.setvar = create_queue(); - my_config.ttl = create_queue(); - my_config.trap = create_queue(); - my_config.vars = create_queue(); - my_config.sim_details = NULL; - init_auth_node(); + my_config.broadcastclient = 0; + my_config.manycastserver = create_queue(); + my_config.multicastclient = create_queue(); + + my_config.stats_list = create_queue(); + my_config.stats_dir = NULL; + my_config.filegen_opts = create_queue(); + + my_config.discard_opts = create_queue(); + my_config.restrict_opts = create_queue(); + + my_config.enable_opts = create_queue(); + my_config.disable_opts = create_queue(); + my_config.tinker = create_queue(); + my_config.fudge = create_queue(); + + my_config.logconfig = create_queue(); + my_config.phone = create_queue(); + my_config.setvar = create_queue(); + my_config.ttl = create_queue(); + my_config.trap = create_queue(); + my_config.vars = create_queue(); + my_config.sim_details = NULL; + init_auth_node(); } /* FUNCTIONS FOR CREATING NODES ON THE SYNTAX TREE * ----------------------------------------------- */ -queue *enqueue_in_new_queue(void *my_node) +queue * +enqueue_in_new_queue( + void *my_node + ) { - queue *my_queue = create_queue(); - enqueue(my_queue, my_node); - return my_queue; + queue *my_queue = create_queue(); + + enqueue(my_queue, my_node); + return my_queue; } -struct attr_val *create_attr_dval(int attr, double value) +struct attr_val * +create_attr_dval( + int attr, + double value + ) { - struct attr_val *my_val; - my_val = (struct attr_val *) - get_node(sizeof(struct attr_val)); - my_val->attr = attr; - my_val->value.d = value; - my_val->type = T_Double; - return my_val; + struct attr_val *my_val; + + my_val = (struct attr_val *) + get_node(sizeof(struct attr_val)); + my_val->attr = attr; + my_val->value.d = value; + my_val->type = T_Double; + return my_val; } -struct attr_val *create_attr_ival(int attr, int value) +struct attr_val * +create_attr_ival( + int attr, + int value + ) { - struct attr_val *my_val; - my_val = (struct attr_val *) - get_node(sizeof(struct attr_val)); - my_val->attr = attr; - my_val->value.i = value; - my_val->type = T_Integer; - return my_val; + struct attr_val *my_val; + + my_val = (struct attr_val *) + get_node(sizeof(struct attr_val)); + my_val->attr = attr; + my_val->value.i = value; + my_val->type = T_Integer; + return my_val; } -struct attr_val *create_attr_sval(int attr, char *s) +struct attr_val * +create_attr_sval( + int attr, + char *s + ) { - struct attr_val *my_val; - my_val = (struct attr_val *) - get_node(sizeof(struct attr_val)); - my_val->attr = attr; - my_val->value.s = strdup(s); - my_val->type = T_String; - return my_val; + struct attr_val *my_val; + + my_val = (struct attr_val *) + get_node(sizeof(struct attr_val)); + my_val->attr = attr; + my_val->value.s = strdup(s); + my_val->type = T_String; + return my_val; } -struct attr_val *create_attr_pval(int attr, void *p) +struct attr_val * +create_attr_pval( + int attr, + void *p + ) { - struct attr_val *my_val; - my_val = (struct attr_val *) - get_node(sizeof(struct attr_val)); - my_val->attr = attr; - my_val->value.p = p; - my_val->type = T_Void; - return my_val; + struct attr_val *my_val; + + my_val = (struct attr_val *) + get_node(sizeof(struct attr_val)); + my_val->attr = attr; + my_val->value.p = p; + my_val->type = T_Void; + return my_val; } -int *create_ival(int val) +int * +create_ival( + int val + ) { - int *p = (int *)get_node(sizeof(int)); - *p = val; - return p; + int *p = (int *)get_node(sizeof(int)); + + *p = val; + return p; } -double *create_dval(double val) +double * +create_dval( + double val + ) { - double *p = (double *) get_node(sizeof(int)); - *p = val; - return p; + double *p = (double *) get_node(sizeof(int)); + + *p = val; + return p; } -void **create_pval(void *val) +void ** +create_pval( + void *val + ) { - void **p = (void **) get_node(sizeof(void *)); - *p = val; - return p; + void **p = (void **) get_node(sizeof(void *)); + + *p = val; + return p; } -struct address_node *create_address_node(char *addr, int type) +struct address_node * +create_address_node( + char *addr, + int type + ) { - struct address_node *my_node = (struct address_node *) - get_node(sizeof(struct address_node)); - my_node->address = addr; - my_node->type = type; - return my_node; + struct address_node *my_node = (struct address_node *) + get_node(sizeof(struct address_node)); + + my_node->address = addr; + my_node->type = type; + return my_node; } -struct peer_node *create_peer_node(int hmode, struct address_node *addr, queue *options) +struct peer_node * +create_peer_node( + int hmode, + struct address_node *addr, + queue *options + ) { - struct peer_node* my_node; - int errflag = 0; - - my_node = (struct peer_node *) - get_node(sizeof(struct peer_node)); - - /* Initialze node values to default */ - my_node->minpoll = NTP_MINDPOLL; - my_node->maxpoll = NTP_MAXDPOLL; - my_node->ttl = 0; - my_node->peerversion = NTP_VERSION; - my_node->peerkey = 0; - my_node->peerflags = 0; - - /* Now set the node to the read values */ - my_node->host_mode = hmode; - my_node->addr = addr; + struct peer_node* my_node; + int errflag = 0; + + my_node = (struct peer_node *) + get_node(sizeof(struct peer_node)); + + /* Initialze node values to default */ + my_node->minpoll = NTP_MINDPOLL; + my_node->maxpoll = NTP_MAXDPOLL; + my_node->ttl = 0; + my_node->peerversion = NTP_VERSION; + my_node->peerkey = 0; + my_node->peerflags = 0; + + /* Now set the node to the read values */ + my_node->host_mode = hmode; + my_node->addr = addr; - while (options && !empty(options)) { - struct attr_val *my_val = dequeue(options); - - /* Check the kind of option being set */ - switch(my_val->attr) { - case T_Minpoll: - if (my_val->value.i < NTP_MINPOLL) { - msyslog(LOG_INFO, - "minpoll: provided value (%d) is below minimum (%d)", - my_val->value.i, NTP_MINPOLL); - my_node->minpoll = NTP_MINPOLL; - } - else - my_node->minpoll = my_val->value.i; - break; - case T_Maxpoll: - if (my_val->value.i > NTP_MAXPOLL) { - msyslog(LOG_INFO, - "maxpoll: provided value (%d) is above maximum (%d)", - my_val->value.i, NTP_MAXPOLL); - my_node->maxpoll = NTP_MAXPOLL; - } - else - my_node->maxpoll = my_val->value.i; - break; - case T_Ttl: - if (my_node->ttl >= MAX_TTL) { - msyslog(LOG_ERR, "ttl: invalid argument"); - errflag = 1; - } - else - my_node->ttl = my_val->value.i; - break; - case T_Mode: - my_node->ttl = my_val->value.i; - break; - case T_Key: - my_node->peerkey = my_val->value.i; - my_node->peerflags |= FLAG_AUTHENABLE; - break; - case T_Version: - my_node->peerversion = my_val->value.i; - break; - case T_Flag: - my_node->peerflags |= my_val->value.i; - break; - } - free_node(my_val); - } - if (options) - destroy_queue(options); + while (options && !empty(options)) { + struct attr_val *my_val = dequeue(options); + + /* Check the kind of option being set */ + switch(my_val->attr) { + case T_Minpoll: + if (my_val->value.i < NTP_MINPOLL) { + msyslog(LOG_INFO, + "minpoll: provided value (%d) is below minimum (%d)", + my_val->value.i, NTP_MINPOLL); + my_node->minpoll = NTP_MINPOLL; + } + else + my_node->minpoll = my_val->value.i; + break; + case T_Maxpoll: + if (my_val->value.i > NTP_MAXPOLL) { + msyslog(LOG_INFO, + "maxpoll: provided value (%d) is above maximum (%d)", + my_val->value.i, NTP_MAXPOLL); + my_node->maxpoll = NTP_MAXPOLL; + } + else + my_node->maxpoll = my_val->value.i; + break; + case T_Ttl: + if (my_node->ttl >= MAX_TTL) { + msyslog(LOG_ERR, "ttl: invalid argument"); + errflag = 1; + } + else + my_node->ttl = my_val->value.i; + break; + case T_Mode: + my_node->ttl = my_val->value.i; + break; + case T_Key: + my_node->peerkey = my_val->value.i; + my_node->peerflags |= FLAG_AUTHENABLE; + break; + case T_Version: + my_node->peerversion = my_val->value.i; + break; + case T_Flag: + my_node->peerflags |= my_val->value.i; + break; + } + free_node(my_val); + } + if (options) + destroy_queue(options); - /* Check if errors were reported. If yes, ignore the node */ - if (errflag) { - free_node(my_node); - return NULL; - } - return my_node; + /* Check if errors were reported. If yes, ignore the node */ + if (errflag) { + free_node(my_node); + return NULL; + } + return my_node; } -struct filegen_node *create_filegen_node( - void **name, - queue *options) +struct filegen_node * +create_filegen_node( + void **name, + queue *options + ) { - struct filegen_node *my_node = (struct filegen_node *) - get_node(sizeof(struct filegen_node)); + struct filegen_node *my_node = (struct filegen_node *) + get_node(sizeof(struct filegen_node)); - my_node->name = (char *) *name; - free_node(name); + my_node->name = (char *) *name; + free_node(name); - my_node->options = options; - return my_node; + my_node->options = options; + return my_node; } -struct restrict_node *create_restrict_node( - struct address_node *addr, - struct address_node *mask, - queue *flags, - int line_no) +struct restrict_node * +create_restrict_node( + struct address_node *addr, + struct address_node *mask, + queue *flags, + int line_no + ) { - struct restrict_node *my_node = (struct restrict_node *) - get_node(sizeof(struct restrict_node)); - my_node->addr = addr; - my_node->mask = mask; - my_node->flags = flags; - my_node->line_no = line_no; - return my_node; + struct restrict_node *my_node = (struct restrict_node *) + get_node(sizeof(struct restrict_node)); + + my_node->addr = addr; + my_node->mask = mask; + my_node->flags = flags; + my_node->line_no = line_no; + return my_node; } -void destroy_restrict_node(struct restrict_node *my_node) +void +destroy_restrict_node( + struct restrict_node *my_node + ) { - /* With great care, free all the memory occupied by - * the restrict node - */ - if (my_node->addr) - free_node(my_node->addr); - if (my_node->mask) - free_node(my_node->mask); - if (my_node->flags) - destroy_queue(my_node->flags); - free_node(my_node); + /* With great care, free all the memory occupied by + * the restrict node + */ + if (my_node->addr) + free_node(my_node->addr); + if (my_node->mask) + free_node(my_node->mask); + if (my_node->flags) + destroy_queue(my_node->flags); + free_node(my_node); } -struct setvar_node *create_setvar_node(char *var, char *val, u_short def) +struct setvar_node * +create_setvar_node( + char *var, + char *val, + u_short def + ) { - int len1 = strlen(var); - int len2 = strlen(val); - - char *s = (char *) emalloc(len1 + len2 + 2); - struct setvar_node *my_node; + int len1 = strlen(var); + int len2 = strlen(val); + char *s = (char *) emalloc(len1 + len2 + 2); + struct setvar_node *my_node; - /* Copy the var = val to s */ - strcpy(s, var); - s[len1] = '='; - strcpy(&s[len1 + 1], val); - s[len1+len2+1] = '\0'; + /* Copy the var = val to s */ + strcpy(s, var); + s[len1] = '='; + strcpy(&s[len1 + 1], val); + s[len1+len2+1] = '\0'; - free(var); - free(val); - - /* Now store the string and its length into a setvar_node */ - my_node = (struct setvar_node *) - get_node(sizeof(struct setvar_node)); - my_node->data = s; - my_node->len = len1 + len2 + 2; - my_node->def = def; - return my_node; + free(var); + free(val); + + /* Now store the string and its length into a setvar_node */ + my_node = (struct setvar_node *) + get_node(sizeof(struct setvar_node)); + my_node->data = s; + my_node->len = len1 + len2 + 2; + my_node->def = def; + return my_node; } -struct addr_opts_node *create_addr_opts_node( - struct address_node *addr, - queue *options) +struct addr_opts_node * +create_addr_opts_node( + struct address_node *addr, + queue *options + ) { - struct addr_opts_node *my_node = (struct addr_opts_node *) - get_node(sizeof(struct addr_opts_node)); - my_node->addr = addr; - my_node->options = options; - return my_node; + struct addr_opts_node *my_node = (struct addr_opts_node *) + get_node(sizeof(struct addr_opts_node)); + + my_node->addr = addr; + my_node->options = options; + return my_node; } -script_info *create_sim_script_info(double duration, queue *script_queue) +script_info * +create_sim_script_info( + double duration, + queue *script_queue + ) { #ifdef SIM - return NULL; + return NULL; #else - script_info *my_info; - struct attr_val *my_attr_val; - my_info = (script_info *)get_node(sizeof(script_info)); - /* XXX: check the return value... */ - - /* Initialize Script Info with default values*/ - my_info->duration = duration; - my_info->freq_offset = 0; - my_info->wander = 0; - my_info->jitter = 0; - my_info->prop_delay = NET_DLY; - my_info->proc_delay = PROC_DLY; - - /* Traverse the script_queue and fill out non-default values */ - while (!empty(script_queue)) { - my_attr_val = (struct attr_val *) dequeue(script_queue); + script_info *my_info; + struct attr_val *my_attr_val; + my_info = (script_info *)get_node(sizeof(script_info)); + /* XXX: check the return value... */ + + /* Initialize Script Info with default values*/ + my_info->duration = duration; + my_info->freq_offset = 0; + my_info->wander = 0; + my_info->jitter = 0; + my_info->prop_delay = NET_DLY; + my_info->proc_delay = PROC_DLY; + + /* Traverse the script_queue and fill out non-default values */ + while (!empty(script_queue)) { + my_attr_val = (struct attr_val *) dequeue(script_queue); - /* Set the desired value */ - switch(my_attr_val->attr) { - case T_Freq_Offset: - my_info->freq_offset = my_attr_val->value.d; - break; - case T_Wander: - my_info->wander = my_attr_val->value.d; - break; - case T_Jitter: - my_info->jitter = my_attr_val->value.d; - break; - case T_Prop_Delay: - my_info->prop_delay = my_attr_val->value.d; - break; - case T_Proc_Delay: - my_info->proc_delay = my_attr_val->value.d; - break; - default: - yyerror("ERROR!! Invalid script info in file\n"); - break; - } - free_node(my_attr_val); - } - destroy_queue(script_queue); - return (my_info); + /* Set the desired value */ + switch(my_attr_val->attr) { + case T_Freq_Offset: + my_info->freq_offset = my_attr_val->value.d; + break; + case T_Wander: + my_info->wander = my_attr_val->value.d; + break; + case T_Jitter: + my_info->jitter = my_attr_val->value.d; + break; + case T_Prop_Delay: + my_info->prop_delay = my_attr_val->value.d; + break; + case T_Proc_Delay: + my_info->proc_delay = my_attr_val->value.d; + break; + default: + yyerror("ERROR!! Invalid script info in file\n"); + break; + } + free_node(my_attr_val); + } + destroy_queue(script_queue); + return (my_info); #endif } #define ADDR_LENGTH 16 + 1 -static struct sockaddr_storage *get_next_address(struct address_node *addr) +static struct sockaddr_storage * +get_next_address( + struct address_node *addr + ) { - static char *addr_prefix = "192.168.0."; - static int curr_addr_no = 1; - char addr_string[ADDR_LENGTH]; - - struct sockaddr_storage *final_addr = (struct sockaddr_storage *) - malloc(sizeof(struct sockaddr_storage)); - struct addrinfo *ptr; - int retval; + static char *addr_prefix = "192.168.0."; + static int curr_addr_no = 1; + char addr_string[ADDR_LENGTH]; + + struct sockaddr_storage *final_addr = (struct sockaddr_storage *) + malloc(sizeof(struct sockaddr_storage)); + struct addrinfo *ptr; + int retval; - if (addr->type == T_String) { - snprintf(addr_string, ADDR_LENGTH, "%s%d", addr_prefix, curr_addr_no++); - printf("Selecting ip address %s for hostname %s\n", addr_string, addr->address); - retval = getaddrinfo(addr_string, "ntp", NULL, &ptr); - } - else { - retval = getaddrinfo(addr->address, "ntp", NULL, &ptr); - } + if (addr->type == T_String) { + snprintf(addr_string, ADDR_LENGTH, "%s%d", addr_prefix, curr_addr_no++); + printf("Selecting ip address %s for hostname %s\n", addr_string, addr->address); + retval = getaddrinfo(addr_string, "ntp", NULL, &ptr); + } + else { + retval = getaddrinfo(addr->address, "ntp", NULL, &ptr); + } - if (retval == 0) { - memcpy(final_addr, ptr->ai_addr, ptr->ai_addrlen); - fprintf(stderr, "Successful in setting ip address of simulated server to: %s\n", stoa(final_addr)); - } - else { - fprintf(stderr, "ERROR!! Could not get a new address\n"); - exit(1); - } - freeaddrinfo(ptr); - return final_addr; + if (retval == 0) { + memcpy(final_addr, ptr->ai_addr, ptr->ai_addrlen); + fprintf(stderr, "Successful in setting ip address of simulated server to: %s\n", stoa(final_addr)); + } + else { + fprintf(stderr, "ERROR!! Could not get a new address\n"); + exit(1); + } + freeaddrinfo(ptr); + return final_addr; } -server_info *create_sim_server(struct address_node *addr, double server_offset, queue *script) +server_info * +create_sim_server( + struct address_node *addr, + double server_offset, + queue *script + ) { #ifdef SIM - return NULL; + return NULL; #else - server_info *my_info; - my_info = (server_info *) get_node(sizeof(server_info)); - - my_info->server_time = server_offset; - my_info->addr = get_next_address(addr); - my_info->script = script; - my_info->curr_script = dequeue(my_info->script); - return my_info; + server_info *my_info; + my_info = (server_info *) get_node(sizeof(server_info)); + + my_info->server_time = server_offset; + my_info->addr = get_next_address(addr); + my_info->script = script; + my_info->curr_script = dequeue(my_info->script); + return my_info; #endif /* SIM */ } -struct sim_node *create_sim_node(queue *init_opts, queue *servers) +struct sim_node * +create_sim_node( + queue *init_opts, + queue *servers + ) { - struct sim_node *my_node = (struct sim_node *) - get_node(sizeof(struct sim_node)); - my_node->init_opts = init_opts; - my_node->servers = servers; - return my_node; + struct sim_node *my_node = (struct sim_node *) + get_node(sizeof(struct sim_node)); + + my_node->init_opts = init_opts; + my_node->servers = servers; + return my_node; } struct key_tok keyword_list[] = { - { "automax", T_Automax, NO_ARG }, - { "broadcast", T_Broadcast, SINGLE_ARG }, - { "broadcastclient",T_Broadcastclient, NO_ARG }, - { "broadcastdelay", T_Broadcastdelay, NO_ARG }, - { "calldelay", T_Calldelay, NO_ARG }, - { "disable", T_Disable, NO_ARG }, - { "driftfile", T_Driftfile, SINGLE_ARG }, - { "enable", T_Enable, NO_ARG }, - { "end", T_End, NO_ARG }, - { "filegen", T_Filegen, NO_ARG }, - { "fudge", T_Fudge, SINGLE_ARG }, - { "includefile", T_Includefile, SINGLE_ARG }, - { "logconfig", T_Logconfig, SINGLE_ARG }, - { "logfile", T_Logfile, SINGLE_ARG }, - { "manycastclient", T_Manycastclient, SINGLE_ARG }, - { "manycastserver", T_Manycastserver, MULTIPLE_ARG }, - { "multicastclient",T_Multicastclient, MULTIPLE_ARG }, - { "peer", T_Peer, SINGLE_ARG }, - { "phone", T_Phone, MULTIPLE_ARG }, - { "pidfile", T_Pidfile, SINGLE_ARG }, - { "pool", T_Pool, SINGLE_ARG }, - { "discard", T_Discard, NO_ARG }, - { "restrict", T_Restrict, NO_ARG }, - { "server", T_Server, SINGLE_ARG }, - { "setvar", T_Setvar, NO_ARG }, - { "statistics", T_Statistics, NO_ARG }, - { "statsdir", T_Statsdir, SINGLE_ARG }, - { "tick", T_Tick, NO_ARG }, - { "tinker", T_Tinker, NO_ARG }, - { "tos", T_Tos, NO_ARG }, - { "trap", T_Trap, SINGLE_ARG }, - { "default", T_Default, NO_ARG }, + { "automax", T_Automax, NO_ARG }, + { "broadcast", T_Broadcast, SINGLE_ARG }, + { "broadcastclient", T_Broadcastclient, NO_ARG }, + { "broadcastdelay", T_Broadcastdelay, NO_ARG }, + { "calldelay", T_Calldelay, NO_ARG }, + { "disable", T_Disable, NO_ARG }, + { "driftfile", T_Driftfile, SINGLE_ARG }, + { "enable", T_Enable, NO_ARG }, + { "end", T_End, NO_ARG }, + { "filegen", T_Filegen, NO_ARG }, + { "fudge", T_Fudge, SINGLE_ARG }, + { "includefile", T_Includefile, SINGLE_ARG }, + { "logconfig", T_Logconfig, SINGLE_ARG }, + { "logfile", T_Logfile, SINGLE_ARG }, + { "manycastclient", T_Manycastclient, SINGLE_ARG }, + { "manycastserver", T_Manycastserver, MULTIPLE_ARG }, + { "multicastclient", T_Multicastclient, MULTIPLE_ARG }, + { "peer", T_Peer, SINGLE_ARG }, + { "phone", T_Phone, MULTIPLE_ARG }, + { "pidfile", T_Pidfile, SINGLE_ARG }, + { "pool", T_Pool, SINGLE_ARG }, + { "discard", T_Discard, NO_ARG }, + { "restrict", T_Restrict, NO_ARG }, + { "server", T_Server, SINGLE_ARG }, + { "setvar", T_Setvar, NO_ARG }, + { "statistics", T_Statistics, NO_ARG }, + { "statsdir", T_Statsdir, SINGLE_ARG }, + { "tick", T_Tick, NO_ARG }, + { "tinker", T_Tinker, NO_ARG }, + { "tos", T_Tos, NO_ARG }, + { "trap", T_Trap, SINGLE_ARG }, + { "default", T_Default, NO_ARG }, /* authentication_command */ - { "controlkey", T_ControlKey, NO_ARG }, - { "crypto", T_Crypto, NO_ARG }, - { "keys", T_Keys, SINGLE_ARG }, - { "keysdir", T_Keysdir, SINGLE_ARG }, - { "requestkey", T_Requestkey, NO_ARG }, - { "revoke", T_Revoke, NO_ARG }, - { "trustedkey", T_Trustedkey, NO_ARG }, + { "controlkey", T_ControlKey, NO_ARG }, + { "crypto", T_Crypto, NO_ARG }, + { "keys", T_Keys, SINGLE_ARG }, + { "keysdir", T_Keysdir, SINGLE_ARG }, + { "requestkey", T_Requestkey, NO_ARG }, + { "revoke", T_Revoke, NO_ARG }, + { "trustedkey", T_Trustedkey, NO_ARG }, /* option */ - { "autokey", T_Autokey, NO_ARG }, - { "burst", T_Burst, NO_ARG }, - { "iburst", T_Iburst, NO_ARG }, - { "key", T_Key, NO_ARG }, - { "maxpoll", T_Maxpoll, NO_ARG }, - { "minpoll", T_Minpoll, NO_ARG }, - { "mode", T_Mode, NO_ARG }, - { "noselect", T_Noselect, NO_ARG }, - { "preempt", T_Preempt, NO_ARG }, - { "true", T_True, NO_ARG }, - { "prefer", T_Prefer, NO_ARG }, - { "ttl", T_Ttl, NO_ARG }, - { "version", T_Version, NO_ARG }, + { "autokey", T_Autokey, NO_ARG }, + { "burst", T_Burst, NO_ARG }, + { "iburst", T_Iburst, NO_ARG }, + { "key", T_Key, NO_ARG }, + { "maxpoll", T_Maxpoll, NO_ARG }, + { "minpoll", T_Minpoll, NO_ARG }, + { "mode", T_Mode, NO_ARG }, + { "noselect", T_Noselect, NO_ARG }, + { "preempt", T_Preempt, NO_ARG }, + { "true", T_True, NO_ARG }, + { "prefer", T_Prefer, NO_ARG }, + { "ttl", T_Ttl, NO_ARG }, + { "version", T_Version, NO_ARG }, /* crypto_command */ - { "cert", T_Cert, SINGLE_ARG }, - { "gqpar", T_Gqpar, SINGLE_ARG }, - { "host", T_Host, SINGLE_ARG }, - { "ident", T_Ident, SINGLE_ARG }, - { "iffpar", T_Iffpar, SINGLE_ARG }, - { "leap", T_Leap, SINGLE_ARG }, - { "mvpar", T_Mvpar, SINGLE_ARG }, - { "pw", T_Pw, SINGLE_ARG }, - { "randfile", T_RandFile, SINGLE_ARG }, - { "sign", T_Sign, SINGLE_ARG }, + { "cert", T_Cert, SINGLE_ARG }, + { "gqpar", T_Gqpar, SINGLE_ARG }, + { "host", T_Host, SINGLE_ARG }, + { "ident", T_Ident, SINGLE_ARG }, + { "iffpar", T_Iffpar, SINGLE_ARG }, + { "leap", T_Leap, SINGLE_ARG }, + { "mvpar", T_Mvpar, SINGLE_ARG }, + { "pw", T_Pw, SINGLE_ARG }, + { "randfile", T_RandFile, SINGLE_ARG }, + { "sign", T_Sign, SINGLE_ARG }, /*** MONITORING COMMANDS ***/ /* stat */ - { "clockstats", T_Clockstats, NO_ARG }, - { "cryptostats", T_Cryptostats, NO_ARG }, - { "loopstats", T_Loopstats, NO_ARG }, - { "peerstats", T_Peerstats, NO_ARG }, - { "rawstats", T_Rawstats, NO_ARG }, - { "sysstats", T_Sysstats, NO_ARG }, + { "clockstats", T_Clockstats, NO_ARG }, + { "cryptostats", T_Cryptostats, NO_ARG }, + { "loopstats", T_Loopstats, NO_ARG }, + { "peerstats", T_Peerstats, NO_ARG }, + { "rawstats", T_Rawstats, NO_ARG }, + { "sysstats", T_Sysstats, NO_ARG }, /* filegen_option */ - { "disable", T_Disable, NO_ARG }, - { "enable", T_Enable, NO_ARG }, - { "file", T_File, SINGLE_ARG }, - { "link", T_Link, NO_ARG }, - { "nolink", T_Nolink, NO_ARG }, - { "type", T_Type, NO_ARG }, + { "disable", T_Disable, NO_ARG }, + { "enable", T_Enable, NO_ARG }, + { "file", T_File, SINGLE_ARG }, + { "link", T_Link, NO_ARG }, + { "nolink", T_Nolink, NO_ARG }, + { "type", T_Type, NO_ARG }, /* filegen_type */ - { "age", T_Age, NO_ARG }, - { "day", T_Day, NO_ARG }, - { "month", T_Month, NO_ARG }, - { "none", T_None, NO_ARG }, - { "pid", T_Pid, NO_ARG }, - { "week", T_Week, NO_ARG }, - { "year", T_Year, NO_ARG }, + { "age", T_Age, NO_ARG }, + { "day", T_Day, NO_ARG }, + { "month", T_Month, NO_ARG }, + { "none", T_None, NO_ARG }, + { "pid", T_Pid, NO_ARG }, + { "week", T_Week, NO_ARG }, + { "year", T_Year, NO_ARG }, /*** ORPHAN MODE COMMANDS ***/ /* tos_option */ - { "minclock", T_Minclock, NO_ARG }, - { "maxclock", T_Maxclock, NO_ARG }, - { "minsane", T_Minsane, NO_ARG }, - { "floor", T_Floor, NO_ARG }, - { "ceiling", T_Ceiling, NO_ARG }, - { "cohort", T_Cohort, NO_ARG }, - { "mindist", T_Mindist, NO_ARG }, - { "maxdist", T_Maxdist, NO_ARG }, - { "maxhop", T_Maxhop, NO_ARG }, - { "beacon", T_Beacon, NO_ARG }, - { "orphan", T_Orphan, NO_ARG }, + { "minclock", T_Minclock, NO_ARG }, + { "maxclock", T_Maxclock, NO_ARG }, + { "minsane", T_Minsane, NO_ARG }, + { "floor", T_Floor, NO_ARG }, + { "ceiling", T_Ceiling, NO_ARG }, + { "cohort", T_Cohort, NO_ARG }, + { "mindist", T_Mindist, NO_ARG }, + { "maxdist", T_Maxdist, NO_ARG }, + { "maxhop", T_Maxhop, NO_ARG }, + { "beacon", T_Beacon, NO_ARG }, + { "orphan", T_Orphan, NO_ARG }, /* access_control_flag */ - { "ignore", T_Ignore, NO_ARG }, - { "limited", T_Limited, NO_ARG }, - { "kod", T_Kod, NO_ARG }, - { "lowpriotrap", T_Lowpriotrap, NO_ARG }, - { "mask", T_Mask, NO_ARG }, - { "nomodify", T_Nomodify, NO_ARG }, - { "nopeer", T_Nopeer, NO_ARG }, - { "noquery", T_Noquery, NO_ARG }, - { "noserve", T_Noserve, NO_ARG }, - { "notrap", T_Notrap, NO_ARG }, - { "notrust", T_Notrust, NO_ARG }, - { "ntpport", T_Ntpport, NO_ARG }, - { "version", T_Version, NO_ARG }, + { "ignore", T_Ignore, NO_ARG }, + { "limited", T_Limited, NO_ARG }, + { "kod", T_Kod, NO_ARG }, + { "lowpriotrap", T_Lowpriotrap, NO_ARG }, + { "mask", T_Mask, NO_ARG }, + { "nomodify", T_Nomodify, NO_ARG }, + { "nopeer", T_Nopeer, NO_ARG }, + { "noquery", T_Noquery, NO_ARG }, + { "noserve", T_Noserve, NO_ARG }, + { "notrap", T_Notrap, NO_ARG }, + { "notrust", T_Notrust, NO_ARG }, + { "ntpport", T_Ntpport, NO_ARG }, + { "version", T_Version, NO_ARG }, /* discard_option */ - { "average", T_Average, NO_ARG }, - { "minimum", T_Minimum, NO_ARG }, - { "monitor", T_Monitor, NO_ARG }, + { "average", T_Average, NO_ARG }, + { "minimum", T_Minimum, NO_ARG }, + { "monitor", T_Monitor, NO_ARG }, /* fudge_factor */ - { "flag1", T_Flag1, NO_ARG }, - { "flag2", T_Flag2, NO_ARG }, - { "flag3", T_Flag3, NO_ARG }, - { "flag4", T_Flag4, NO_ARG }, - { "refid", T_Refid, SINGLE_ARG }, - { "stratum", T_Stratum, NO_ARG }, - { "time1", T_Time1, NO_ARG }, - { "time2", T_Time2, NO_ARG }, + { "flag1", T_Flag1, NO_ARG }, + { "flag2", T_Flag2, NO_ARG }, + { "flag3", T_Flag3, NO_ARG }, + { "flag4", T_Flag4, NO_ARG }, + { "refid", T_Refid, SINGLE_ARG }, + { "stratum", T_Stratum, NO_ARG }, + { "time1", T_Time1, NO_ARG }, + { "time2", T_Time2, NO_ARG }, /* system_option */ - { "auth", T_Auth, NO_ARG }, - { "bclient", T_Bclient, NO_ARG }, - { "calibrate", T_Calibrate, NO_ARG }, - { "kernel", T_Kernel, NO_ARG }, - { "monitor", T_Monitor, NO_ARG }, - { "ntp", T_Ntp, NO_ARG }, - { "stats", T_Stats, NO_ARG }, + { "auth", T_Auth, NO_ARG }, + { "bclient", T_Bclient, NO_ARG }, + { "calibrate", T_Calibrate, NO_ARG }, + { "kernel", T_Kernel, NO_ARG }, + { "monitor", T_Monitor, NO_ARG }, + { "ntp", T_Ntp, NO_ARG }, + { "stats", T_Stats, NO_ARG }, /* tinker_option */ - { "step", T_Step, NO_ARG }, - { "panic", T_Panic, NO_ARG }, - { "dispersion", T_Dispersion, NO_ARG }, - { "stepout", T_Stepout, NO_ARG }, - { "allan", T_Allan, NO_ARG }, - { "huffpuff", T_Huffpuff, NO_ARG }, - { "freq", T_Freq, NO_ARG }, + { "step", T_Step, NO_ARG }, + { "panic", T_Panic, NO_ARG }, + { "dispersion", T_Dispersion, NO_ARG }, + { "stepout", T_Stepout, NO_ARG }, + { "allan", T_Allan, NO_ARG }, + { "huffpuff", T_Huffpuff, NO_ARG }, + { "freq", T_Freq, NO_ARG }, /* miscellaneous_command */ - { "port", T_Port, NO_ARG }, - { "interface", T_Interface, SINGLE_ARG }, + { "port", T_Port, NO_ARG }, + { "interface", T_Interface, SINGLE_ARG }, /* simulator commands */ - { "simulate", T_Simulate, NO_ARG }, - { "simulation_duration", T_Sim_Duration, NO_ARG }, - { "beep_delay", T_Beep_Delay, NO_ARG }, - { "duration", T_Duration, NO_ARG }, - { "server_offset", T_Server_Offset, NO_ARG }, - { "freq_offset", T_Freq_Offset, NO_ARG }, - { "wander", T_Wander, NO_ARG }, - { "jitter", T_Jitter, NO_ARG }, - { "prop_delay", T_Prop_Delay, NO_ARG }, - { "proc_delay", T_Proc_Delay, NO_ARG }, - { NULL, 0, 0} + { "simulate", T_Simulate, NO_ARG }, + { "simulation_duration",T_Sim_Duration, NO_ARG }, + { "beep_delay", T_Beep_Delay, NO_ARG }, + { "duration", T_Duration, NO_ARG }, + { "server_offset", T_Server_Offset, NO_ARG }, + { "freq_offset", T_Freq_Offset, NO_ARG }, + { "wander", T_Wander, NO_ARG }, + { "jitter", T_Jitter, NO_ARG }, + { "prop_delay", T_Prop_Delay, NO_ARG }, + { "proc_delay", T_Proc_Delay, NO_ARG }, + { NULL, 0, 0} }; @@ -817,936 +901,960 @@ struct key_tok keyword_list[] = { * ------------------------------------------ */ -static void config_other_modes(void) +static void +config_other_modes(void) { - struct sockaddr_storage addr_sock; - struct address_node *addr_node; + struct sockaddr_storage addr_sock; + struct address_node *addr_node; - if (my_config.broadcastclient) { - proto_config(PROTO_BROADCLIENT, my_config.broadcastclient, 0., NULL); - my_config.broadcastclient = 0; - } + if (my_config.broadcastclient) { + proto_config(PROTO_BROADCLIENT, my_config.broadcastclient, 0., NULL); + my_config.broadcastclient = 0; + } - /* Configure the many-cast servers */ - if (!empty(my_config.manycastserver)) { - while (!empty(my_config.manycastserver)) { - addr_node = (struct address_node *) - dequeue(my_config.manycastserver); + /* Configure the many-cast servers */ + if (!empty(my_config.manycastserver)) { + while (!empty(my_config.manycastserver)) { + addr_node = (struct address_node *) + dequeue(my_config.manycastserver); - memset((char *)&addr_sock, 0, sizeof(addr_sock)); - addr_sock.ss_family = addr_node->type; + memset((char *)&addr_sock, 0, sizeof(addr_sock)); + addr_sock.ss_family = addr_node->type; - if (getnetnum(addr_node->address, &addr_sock, 1, t_UNK) == 1) - proto_config(PROTO_MULTICAST_ADD, 0, 0., &addr_sock); + if (getnetnum(addr_node->address, &addr_sock, 1, t_UNK) == 1) + proto_config(PROTO_MULTICAST_ADD, 0, 0., &addr_sock); - free(addr_node->address); - free_node(addr_node); - } - sys_manycastserver = 1; - } + free(addr_node->address); + free_node(addr_node); + } + sys_manycastserver = 1; + } - /* Configure the multicast clients */ - if (!empty(my_config.multicastclient)) { - while (!empty(my_config.multicastclient)) { - addr_node = (struct address_node *) - dequeue(my_config.multicastclient); + /* Configure the multicast clients */ + if (!empty(my_config.multicastclient)) { + while (!empty(my_config.multicastclient)) { + addr_node = (struct address_node *) + dequeue(my_config.multicastclient); - memset((char *)&addr_sock, 0, sizeof(addr_sock)); - addr_sock.ss_family = addr_node->type; + memset((char *)&addr_sock, 0, sizeof(addr_sock)); + addr_sock.ss_family = addr_node->type; - if (getnetnum(addr_node->address, &addr_sock, 1, t_UNK) == 1) - proto_config(PROTO_MULTICAST_ADD, 0, 0., &addr_sock); + if (getnetnum(addr_node->address, &addr_sock, 1, t_UNK) == 1) + proto_config(PROTO_MULTICAST_ADD, 0, 0., &addr_sock); - free(addr_node->address); - free_node(addr_node); - } - proto_config(PROTO_MULTICAST_ADD, 1, 0., NULL); - } + free(addr_node->address); + free_node(addr_node); + } + proto_config(PROTO_MULTICAST_ADD, 1, 0., NULL); + } } -static void config_auth(void) +static void +config_auth(void) { - struct attr_val *my_val; - int *key_val; + struct attr_val *my_val; + int *key_val; - /* Crypto Command */ - if (my_config.auth.crypto_cmd_list) { - while (!empty(my_config.auth.crypto_cmd_list)) { - my_val = (struct attr_val *) - dequeue(my_config.auth.crypto_cmd_list); - #ifdef OPENSSL - crypto_config(my_val->attr, my_val->value.s); - #else - printf("Warning: Code not built with OpenSSL libraries!\n" - "Crypto commands are ignored\n"); - msyslog(LOG_ERR, "config_auth: Crypto commands are ignored\n"); - #endif + /* Crypto Command */ + if (my_config.auth.crypto_cmd_list) { + while (!empty(my_config.auth.crypto_cmd_list)) { + my_val = (struct attr_val *) + dequeue(my_config.auth.crypto_cmd_list); +#ifdef OPENSSL + crypto_config(my_val->attr, my_val->value.s); +#else + printf("Warning: Code not built with OpenSSL libraries!\n" + "Crypto commands are ignored\n"); + msyslog(LOG_ERR, "config_auth: Crypto commands are ignored\n"); +#endif - free(my_val->value.s); - free_node(my_val); - } - destroy_queue(my_config.auth.crypto_cmd_list); - my_config.auth.crypto_cmd_list = NULL; - } + free(my_val->value.s); + free_node(my_val); + } + destroy_queue(my_config.auth.crypto_cmd_list); + my_config.auth.crypto_cmd_list = NULL; + } - /* Keys Command */ - if (my_config.auth.keys) - getauthkeys(my_config.auth.keys); + /* Keys Command */ + if (my_config.auth.keys) + getauthkeys(my_config.auth.keys); - /* Keysdir Command */ - if (my_config.auth.keysdir) - keysdir = my_config.auth.keysdir; + /* Keysdir Command */ + if (my_config.auth.keysdir) + keysdir = my_config.auth.keysdir; - /* Control Key Command */ - if (my_config.auth.control_key != 0) - ctl_auth_keyid = my_config.auth.control_key; + /* Control Key Command */ + if (my_config.auth.control_key != 0) + ctl_auth_keyid = my_config.auth.control_key; - /* Requested Key Command */ - if (my_config.auth.requested_key) { + /* Requested Key Command */ + if (my_config.auth.requested_key) { #ifdef DEBUG - if (debug > 3) - printf("set info_auth_key to %08lx\n", - (long unsigned int) my_config.auth.requested_key); + if (debug > 3) + printf("set info_auth_key to %08lx\n", + (long unsigned int) my_config.auth.requested_key); #endif - info_auth_keyid = (keyid_t) my_config.auth.requested_key; - } - - /* Trusted Key Command */ - if (my_config.auth.trusted_key_list) { - while (!empty(my_config.auth.trusted_key_list)) { - key_val = (int *) dequeue(my_config.auth.trusted_key_list); - authtrust(*key_val, 1); - free_node(key_val); - } - destroy_queue(my_config.auth.trusted_key_list); - my_config.auth.trusted_key_list = NULL; - } + info_auth_keyid = (keyid_t) my_config.auth.requested_key; + } + + /* Trusted Key Command */ + if (my_config.auth.trusted_key_list) { + while (!empty(my_config.auth.trusted_key_list)) { + key_val = (int *) dequeue(my_config.auth.trusted_key_list); + authtrust(*key_val, 1); + free_node(key_val); + } + destroy_queue(my_config.auth.trusted_key_list); + my_config.auth.trusted_key_list = NULL; + } - /* Revoke Command */ + /* Revoke Command */ #ifdef OPENSSL - if (my_config.auth.revoke) - sys_revoke = (u_char) max(my_config.auth.revoke, KEY_REVOKE); + if (my_config.auth.revoke) + sys_revoke = (u_char) max(my_config.auth.revoke, KEY_REVOKE); #endif /* OPENSSL */ #if !defined(VMS) && !defined(SYS_VXWORKS) - /* find a keyid */ - if (info_auth_keyid == 0) - req_keyid = 65535; - else - req_keyid = info_auth_keyid; - - /* if doesn't exist, make up one at random */ - if (!authhavekey(req_keyid)) { - char rankey[9]; - int i, j; + /* find a keyid */ + if (info_auth_keyid == 0) + req_keyid = 65535; + else + req_keyid = info_auth_keyid; + + /* if doesn't exist, make up one at random */ + if (!authhavekey(req_keyid)) { + char rankey[9]; + int i, j; - for (i = 0; i < 8; i++) - for (j = 1; j < 100; ++j) { - rankey[i] = (char) (ntp_random() & 0xff); - if (rankey[i] != 0) break; - } - rankey[8] = 0; - - authusekey(req_keyid, KEY_TYPE_MD5, (u_char *)rankey); - authtrust(req_keyid, 1); - if (!authhavekey(req_keyid)) { - msyslog(LOG_ERR, "getconfig: Couldn't generate a valid random key!"); - /* HMS: Should this be fatal? */ - } - } - - /* save keyid so we will accept config requests with it */ - info_auth_keyid = req_keyid; + for (i = 0; i < 8; i++) + for (j = 1; j < 100; ++j) { + rankey[i] = (char) (ntp_random() & 0xff); + if (rankey[i] != 0) break; + } + rankey[8] = 0; + + authusekey(req_keyid, KEY_TYPE_MD5, (u_char *)rankey); + authtrust(req_keyid, 1); + if (!authhavekey(req_keyid)) { + msyslog(LOG_ERR, "getconfig: Couldn't generate a valid random key!"); + /* HMS: Should this be fatal? */ + } + } + + /* save keyid so we will accept config requests with it */ + info_auth_keyid = req_keyid; #endif /* !defined(VMS) && !defined(SYS_VXWORKS) */ } -static void config_tos(void) { - struct attr_val *tos; +static void +config_tos(void) +{ + struct attr_val *tos; - while (!empty(my_config.orphan_cmds)) { - tos = (struct attr_val *) dequeue(my_config.orphan_cmds); - proto_config(tos->attr, 0, tos->value.d, NULL); - free_node(tos); - } + while (!empty(my_config.orphan_cmds)) { + tos = (struct attr_val *) dequeue(my_config.orphan_cmds); + proto_config(tos->attr, 0, tos->value.d, NULL); + free_node(tos); + } } -static void config_monitor(void) +static void +config_monitor(void) { - char **filegen_string; - FILEGEN *filegen; - struct filegen_node *my_node; - struct attr_val *my_opts; - - char *filegen_file; - int filegen_type; - int filegen_flag; + char **filegen_string; + FILEGEN *filegen; + struct filegen_node *my_node; + struct attr_val *my_opts; + + char *filegen_file; + int filegen_type; + int filegen_flag; - /* Set the statistics directory */ - if (my_config.stats_dir) { - stats_config(STATS_STATSDIR,my_config.stats_dir); - free(my_config.stats_dir); - my_config.stats_dir = NULL; - } + /* Set the statistics directory */ + if (my_config.stats_dir) { + stats_config(STATS_STATSDIR,my_config.stats_dir); + free(my_config.stats_dir); + my_config.stats_dir = NULL; + } - /* NOTE: - * Calling filegen_get is brain dead. Doing a string - * comparison to find the relavant filegen structure is - * expensive. - * - * Through the parser, we already know which filegen is - * being specified. Hence, we should either store a - * pointer to the specified structure in the syntax tree - * or an index into a filegen array. - * - * Need to change the filegen code to reflect the above. - */ - - /* Turn on the specified statistics */ - while (!empty(my_config.stats_list)) { - filegen_string = (char **) dequeue(my_config.stats_list); - filegen = filegen_get(*filegen_string); + /* NOTE: + * Calling filegen_get is brain dead. Doing a string + * comparison to find the relavant filegen structure is + * expensive. + * + * Through the parser, we already know which filegen is + * being specified. Hence, we should either store a + * pointer to the specified structure in the syntax tree + * or an index into a filegen array. + * + * Need to change the filegen code to reflect the above. + */ + + /* Turn on the specified statistics */ + while (!empty(my_config.stats_list)) { + filegen_string = (char **) dequeue(my_config.stats_list); + filegen = filegen_get(*filegen_string); #ifdef DEBUG - if (debug > 3) - printf("enabling filegen for %s statistics \"%s%s\"\n", - *filegen_string, filegen->prefix, filegen->basename); + if (debug > 3) + printf("enabling filegen for %s statistics \"%s%s\"\n", + *filegen_string, filegen->prefix, filegen->basename); #endif - filegen->flag |= FGEN_FLAG_ENABLED; - free_node(filegen_string); - } + filegen->flag |= FGEN_FLAG_ENABLED; + free_node(filegen_string); + } - /* Configure the statistics with the options */ - while (!empty(my_config.filegen_opts)) { - my_node = (struct filegen_node *) dequeue(my_config.filegen_opts); - filegen = filegen_get(my_node->name); - - /* Initilize the filegen variables to their pre-configurtion states */ - filegen_flag = filegen->flag; - filegen_type = filegen->type; - filegen_file = my_node->name; - - while (!empty(my_node->options)) { - my_opts = (struct attr_val *) dequeue(my_node->options); - switch (my_opts->attr) { - case T_File: - filegen_file = (char *) my_opts->value.p; - break; - case T_Type: - filegen_type = my_opts->value.i; - break; - case T_Flag: - switch (my_opts->value.i) { - case T_Link: - filegen_flag |= FGEN_FLAG_LINK; - break; - case T_Nolink: - filegen_flag &= ~FGEN_FLAG_LINK; - break; - case T_Enable: - filegen_flag |= FGEN_FLAG_ENABLED; - break; - case T_Disable: - filegen_flag &= ~FGEN_FLAG_ENABLED; - break; - } - break; - } - filegen_config(filegen, filegen_file, filegen_type, filegen_flag); - free_node(my_opts); - } - free_node(my_node); - } + /* Configure the statistics with the options */ + while (!empty(my_config.filegen_opts)) { + my_node = (struct filegen_node *) dequeue(my_config.filegen_opts); + filegen = filegen_get(my_node->name); + + /* Initilize the filegen variables to their pre-configurtion states */ + filegen_flag = filegen->flag; + filegen_type = filegen->type; + filegen_file = my_node->name; + + while (!empty(my_node->options)) { + my_opts = (struct attr_val *) dequeue(my_node->options); + switch (my_opts->attr) { + case T_File: + filegen_file = (char *) my_opts->value.p; + break; + case T_Type: + filegen_type = my_opts->value.i; + break; + case T_Flag: + switch (my_opts->value.i) { + case T_Link: + filegen_flag |= FGEN_FLAG_LINK; + break; + case T_Nolink: + filegen_flag &= ~FGEN_FLAG_LINK; + break; + case T_Enable: + filegen_flag |= FGEN_FLAG_ENABLED; + break; + case T_Disable: + filegen_flag &= ~FGEN_FLAG_ENABLED; + break; + } + break; + } + filegen_config(filegen, filegen_file, filegen_type, filegen_flag); + free_node(my_opts); + } + free_node(my_node); + } } -static void config_access(void) +static void +config_access(void) { - struct attr_val *my_opt; - struct restrict_node *my_node; + struct attr_val *my_opt; + struct restrict_node *my_node; - struct sockaddr_storage addr_sock; - struct sockaddr_storage addr_mask; - - int flags; - int mflags; - - /* Configure the discard options */ - while (!empty(my_config.discard_opts)) { - my_opt = (struct attr_val *) - dequeue(my_config.discard_opts); - switch(my_opt->attr) { - case T_Average: - res_avg_interval = my_opt->value.i; - break; - case T_Minimum: - res_min_interval = my_opt->value.i; - break; - case T_Monitor: - mon_age = my_opt->value.i; - break; - } - free_node(my_opt); - } - - /* Configure the restrict options */ - while (!empty(my_config.restrict_opts)) { - my_node = (struct restrict_node *) - dequeue(my_config.restrict_opts); - - memset((char *)&addr_sock, 0, sizeof(addr_sock)); - /* Check if the user specified a default rule */ - if (my_node->addr) { - /* Resolve the specified address */ - addr_sock.ss_family = my_node->addr->type; + struct sockaddr_storage addr_sock; + struct sockaddr_storage addr_mask; + + int flags; + int mflags; + + /* Configure the discard options */ + while (!empty(my_config.discard_opts)) { + my_opt = (struct attr_val *) + dequeue(my_config.discard_opts); + switch(my_opt->attr) { + case T_Average: + res_avg_interval = my_opt->value.i; + break; + case T_Minimum: + res_min_interval = my_opt->value.i; + break; + case T_Monitor: + mon_age = my_opt->value.i; + break; + } + free_node(my_opt); + } + + /* Configure the restrict options */ + while (!empty(my_config.restrict_opts)) { + my_node = (struct restrict_node *) + dequeue(my_config.restrict_opts); + + memset((char *)&addr_sock, 0, sizeof(addr_sock)); + /* Check if the user specified a default rule */ + if (my_node->addr) { + /* Resolve the specified address */ + addr_sock.ss_family = my_node->addr->type; - if (getnetnum(my_node->addr->address, - &addr_sock, 1,t_UNK) != 1) { + if (getnetnum(my_node->addr->address, + &addr_sock, 1,t_UNK) != 1) { - /* Error in resolving name!!! - * Free the node memory and move onto the next - * Restrict flag - */ - msyslog(LOG_INFO, - "restrict: error in resolving name: %s on line %d. Ignoring...", - my_node->addr->address, my_node->line_no); - destroy_restrict_node(my_node); - continue; - } + /* Error in resolving name!!! + * Free the node memory and move onto the next + * Restrict flag + */ + msyslog(LOG_INFO, + "restrict: error in resolving name: %s on line %d. Ignoring...", + my_node->addr->address, my_node->line_no); + destroy_restrict_node(my_node); + continue; + } - SET_HOSTMASK(&addr_mask, addr_sock.ss_family); + SET_HOSTMASK(&addr_mask, addr_sock.ss_family); - /* Resolve the mask */ - if (my_node->mask) { - memset((char *)&addr_mask, 0, sizeof(addr_mask)); - addr_mask.ss_family = my_node->mask->type; - if (getnetnum(my_node->mask->address, &addr_mask, 1, t_MSK) != 1) { - /* Error in mask !!! - * Free the node memory and move onto the next - * Restrict flag - */ - msyslog(LOG_INFO, - "restrict: error in resolving mask: %s on line %d. Ignoring...", - my_node->mask->address, my_node->line_no); - destroy_restrict_node(my_node); - continue; - } - } - } - else { /* The user specified a default rule */ - addr_sock.ss_family = default_ai_family; - ANYSOCK(&addr_mask); - } + /* Resolve the mask */ + if (my_node->mask) { + memset((char *)&addr_mask, 0, sizeof(addr_mask)); + addr_mask.ss_family = my_node->mask->type; + if (getnetnum(my_node->mask->address, &addr_mask, 1, t_MSK) != 1) { + /* Error in mask !!! + * Free the node memory and move onto the next + * Restrict flag + */ + msyslog(LOG_INFO, + "restrict: error in resolving mask: %s on line %d. Ignoring...", + my_node->mask->address, my_node->line_no); + destroy_restrict_node(my_node); + continue; + } + } + } + else { /* The user specified a default rule */ + addr_sock.ss_family = default_ai_family; + ANYSOCK(&addr_mask); + } - /* Parse the flags */ - flags = 0; - mflags = 0; + /* Parse the flags */ + flags = 0; + mflags = 0; - while (!empty(my_node->flags)) { - int *curr_flag = (int *) dequeue(my_node->flags); - if (*curr_flag == RESM_NTPONLY) - mflags |= *curr_flag; - else - flags |= *curr_flag; - free_node(curr_flag); - } - - /* Set the flags */ - hack_restrict(RESTRICT_FLAGS, &addr_sock, &addr_mask, - mflags, flags); - destroy_restrict_node(my_node); - } + while (!empty(my_node->flags)) { + int *curr_flag = (int *) dequeue(my_node->flags); + if (*curr_flag == RESM_NTPONLY) + mflags |= *curr_flag; + else + flags |= *curr_flag; + free_node(curr_flag); + } + + /* Set the flags */ + hack_restrict(RESTRICT_FLAGS, &addr_sock, &addr_mask, + mflags, flags); + destroy_restrict_node(my_node); + } } -static void config_tinker(void) +static void +config_tinker(void) { - struct attr_val *tinker; + struct attr_val *tinker; - while (!empty(my_config.tinker)) { - tinker= (struct attr_val *) dequeue(my_config.tinker); - loop_config(tinker->attr, tinker->value.d); - free_node(tinker); - } + while (!empty(my_config.tinker)) { + tinker= (struct attr_val *) dequeue(my_config.tinker); + loop_config(tinker->attr, tinker->value.d); + free_node(tinker); + } } -static void config_system_opts(void) +static void +config_system_opts(void) { - int enable_flags; - int disable_flags; + int enable_flags; + int disable_flags; - enable_flags = get_flags_from_list(my_config.enable_opts); - disable_flags = get_flags_from_list(my_config.disable_opts); + enable_flags = get_flags_from_list(my_config.enable_opts); + disable_flags = get_flags_from_list(my_config.disable_opts); - if (enable_flags) - proto_config(enable_flags, 1, 0., NULL); - if (disable_flags) - proto_config(disable_flags, 0, 0., NULL); + if (enable_flags) + proto_config(enable_flags, 1, 0., NULL); + if (disable_flags) + proto_config(disable_flags, 0, 0., NULL); } -static void config_logconfig(void) +static void +config_logconfig(void) { - struct attr_val *my_logconfig; - - while(!empty(my_config.logconfig)) { - my_logconfig = (struct attr_val *) - dequeue(my_config.logconfig); - switch (my_logconfig->attr) { - case '+': - ntp_syslogmask |= get_logmask(my_logconfig->value.s); - break; - case '-': - ntp_syslogmask &= ~get_logmask(my_logconfig->value.s); - break; - case '=': - ntp_syslogmask = get_logmask(my_logconfig->value.s); - break; - } - free(my_logconfig->value.s); - free_node(my_logconfig); - } + struct attr_val *my_logconfig; + + while(!empty(my_config.logconfig)) { + my_logconfig = (struct attr_val *) + dequeue(my_config.logconfig); + switch (my_logconfig->attr) { + case '+': + ntp_syslogmask |= get_logmask(my_logconfig->value.s); + break; + case '-': + ntp_syslogmask &= ~get_logmask(my_logconfig->value.s); + break; + case '=': + ntp_syslogmask = get_logmask(my_logconfig->value.s); + break; + } + free(my_logconfig->value.s); + free_node(my_logconfig); + } } -static void config_phone(void) +static void +config_phone(void) { - int i = 0; - char **s; + int i = 0; + char **s; - while (!empty(my_config.phone)) { - s = (char **) dequeue(my_config.phone); - if (i < MAXPHONE) - sys_phone[i++] = *s; - else { - msyslog(LOG_INFO, - "phone: Number of phone entries exceeds %d. Ignoring phone %s...", - MAXPHONE, *s); - free(*s); - } - free_node(s); - } - sys_phone[i] = NULL; + while (!empty(my_config.phone)) { + s = (char **) dequeue(my_config.phone); + if (i < MAXPHONE) + sys_phone[i++] = *s; + else { + msyslog(LOG_INFO, + "phone: Number of phone entries exceeds %d. Ignoring phone %s...", + MAXPHONE, *s); + free(*s); + } + free_node(s); + } + sys_phone[i] = NULL; } -static void config_setvar(void) +static void +config_setvar(void) { - struct setvar_node *my_node; + struct setvar_node *my_node; - while (!empty(my_config.setvar)) { - my_node = (struct setvar_node *) dequeue(my_config.setvar); - set_sys_var(my_node->data, my_node->len, my_node->def); - free_node(my_node); - } + while (!empty(my_config.setvar)) { + my_node = (struct setvar_node *) dequeue(my_config.setvar); + set_sys_var(my_node->data, my_node->len, my_node->def); + free_node(my_node); + } } -static void config_ttl(void) +static void +config_ttl(void) { - int i = 0; - int *curr_ttl; + int i = 0; + int *curr_ttl; - while (!empty(my_config.ttl)) { - curr_ttl = (int *) dequeue(my_config.ttl); - if (i < MAX_TTL) - sys_ttl[i++] = *curr_ttl; - else - msyslog(LOG_INFO, - "ttl: Number of TTL entries exceeds %d. Ignoring TTL %d...", - MAX_TTL, *curr_ttl); + while (!empty(my_config.ttl)) { + curr_ttl = (int *) dequeue(my_config.ttl); + if (i < MAX_TTL) + sys_ttl[i++] = *curr_ttl; + else + msyslog(LOG_INFO, + "ttl: Number of TTL entries exceeds %d. Ignoring TTL %d...", + MAX_TTL, *curr_ttl); - free_node(curr_ttl); - } - sys_ttlmax = i - 1; + free_node(curr_ttl); + } + sys_ttlmax = i - 1; } -static void config_trap(void) +static void +config_trap(void) { - struct addr_opts_node *curr_trap; - struct attr_val *curr_opt; - struct sockaddr_storage addr_sock; - struct sockaddr_storage peeraddr; - struct address_node *addr_node; - struct interface *localaddr; - int port_no; - int err_flag; + struct addr_opts_node *curr_trap; + struct attr_val *curr_opt; + struct sockaddr_storage addr_sock; + struct sockaddr_storage peeraddr; + struct address_node *addr_node; + struct interface *localaddr; + int port_no; + int err_flag; - port_no = 0; - localaddr = 0; + port_no = 0; + localaddr = 0; - while (!empty(my_config.trap)) { - err_flag = 0; - curr_trap = (struct addr_opts_node *) dequeue(my_config.trap); + while (!empty(my_config.trap)) { + err_flag = 0; + curr_trap = (struct addr_opts_node *) dequeue(my_config.trap); - while (!empty(curr_trap->options)) { - curr_opt = (struct attr_val *) dequeue(curr_trap->options); - if (curr_opt->attr == T_Port) { - port_no = curr_opt->value.i; - if (port_no <= 0 || port_no > 32767) { - msyslog(LOG_ERR, "invalid port number %d, trap ignored", port_no); - err_flag = 1; - } - } - else if (curr_opt->attr == T_Interface) { - addr_node = (struct address_node *) curr_opt->value.p; - - /* Resolve the interface address */ - memset((char *)&addr_sock, 0, sizeof(addr_sock)); - addr_sock.ss_family = addr_node->type; + while (!empty(curr_trap->options)) { + curr_opt = (struct attr_val *) dequeue(curr_trap->options); + if (curr_opt->attr == T_Port) { + port_no = curr_opt->value.i; + if (port_no <= 0 || port_no > 32767) { + msyslog(LOG_ERR, "invalid port number %d, trap ignored", port_no); + err_flag = 1; + } + } + else if (curr_opt->attr == T_Interface) { + addr_node = (struct address_node *) curr_opt->value.p; + + /* Resolve the interface address */ + memset((char *)&addr_sock, 0, sizeof(addr_sock)); + addr_sock.ss_family = addr_node->type; - if (getnetnum(addr_node->address, - &addr_sock, 1, t_UNK) != 1) { - err_flag = 1; - break; - } + if (getnetnum(addr_node->address, + &addr_sock, 1, t_UNK) != 1) { + err_flag = 1; + break; + } - localaddr = findinterface(&addr_sock); + localaddr = findinterface(&addr_sock); - if (localaddr == NULL) { - msyslog(LOG_ERR, - "can't find interface with address %s", - stoa(&addr_sock)); - err_flag = 1; - } + if (localaddr == NULL) { + msyslog(LOG_ERR, + "can't find interface with address %s", + stoa(&addr_sock)); + err_flag = 1; + } - free(addr_node->address); - free_node(addr_node); - } - free_node(curr_opt); - } + free(addr_node->address); + free_node(addr_node); + } + free_node(curr_opt); + } - /* Now process the trap for the specified interface - * and port number - */ - if (!err_flag) { - memset((char *)&peeraddr, 0, sizeof(peeraddr)); - if (port_no != 0) - ((struct sockaddr_in6*)&peeraddr)->sin6_port = htons((u_short) port_no); - else - ((struct sockaddr_in6*)&peeraddr)->sin6_port = htons(TRAPPORT); - - if (localaddr == NULL) { - peeraddr.ss_family = default_ai_family; - localaddr = ANY_INTERFACE_CHOOSE(&peeraddr); - } - else - peeraddr.ss_family = addr_sock.ss_family; + /* Now process the trap for the specified interface + * and port number + */ + if (!err_flag) { + memset((char *)&peeraddr, 0, sizeof(peeraddr)); + if (port_no != 0) + ((struct sockaddr_in6*)&peeraddr)->sin6_port = htons((u_short) port_no); + else + ((struct sockaddr_in6*)&peeraddr)->sin6_port = htons(TRAPPORT); + + if (localaddr == NULL) { + peeraddr.ss_family = default_ai_family; + localaddr = ANY_INTERFACE_CHOOSE(&peeraddr); + } + else + peeraddr.ss_family = addr_sock.ss_family; - if (!ctlsettrap(&peeraddr, localaddr, 0, - NTP_VERSION)) - msyslog(LOG_ERR, - "can't set trap for %s, no resources", - stoa(&peeraddr)); - } - destroy_queue(curr_trap->options); - free_node(curr_trap); - } + if (!ctlsettrap(&peeraddr, localaddr, 0, + NTP_VERSION)) + msyslog(LOG_ERR, + "can't set trap for %s, no resources", + stoa(&peeraddr)); + } + destroy_queue(curr_trap->options); + free_node(curr_trap); + } } -static void config_fudge(void) +static void +config_fudge(void) { - struct addr_opts_node *curr_fudge; - struct attr_val *curr_opt; - struct sockaddr_storage addr_sock; - struct address_node *addr_node; - struct refclockstat clock_stat; - int err_flag; + struct addr_opts_node *curr_fudge; + struct attr_val *curr_opt; + struct sockaddr_storage addr_sock; + struct address_node *addr_node; + struct refclockstat clock_stat; + int err_flag; - while (!empty(my_config.fudge)) { - curr_fudge = (struct addr_opts_node *) dequeue(my_config.fudge); - err_flag = 0; + while (!empty(my_config.fudge)) { + curr_fudge = (struct addr_opts_node *) dequeue(my_config.fudge); + err_flag = 0; - /* Get the reference clock address and - * ensure that it is sane - */ - addr_node = curr_fudge->addr; - memset((char *)&addr_sock, 0, sizeof(addr_sock)); - if (getnetnum(addr_node->address, &addr_sock, 1, t_REF) != 1) - err_flag = 1; + /* Get the reference clock address and + * ensure that it is sane + */ + addr_node = curr_fudge->addr; + memset((char *)&addr_sock, 0, sizeof(addr_sock)); + if (getnetnum(addr_node->address, &addr_sock, 1, t_REF) != 1) + err_flag = 1; - if (!ISREFCLOCKADR(&addr_sock)) { - msyslog(LOG_ERR, - "%s is inappropriate address for the fudge command, line ignored", - stoa(&addr_sock)); - err_flag = 1; - } - - /* Parse all the options to the fudge command */ - memset((void *)&clock_stat, 0, sizeof clock_stat); - while (!empty(curr_fudge->options)) { - curr_opt = (struct attr_val *) dequeue(curr_fudge->options); + if (!ISREFCLOCKADR(&addr_sock)) { + msyslog(LOG_ERR, + "%s is inappropriate address for the fudge command, line ignored", + stoa(&addr_sock)); + err_flag = 1; + } + + /* Parse all the options to the fudge command */ + memset((void *)&clock_stat, 0, sizeof clock_stat); + while (!empty(curr_fudge->options)) { + curr_opt = (struct attr_val *) dequeue(curr_fudge->options); - /* The attribute field is used to store the flag. - * Set haveflags with it - */ - clock_stat.haveflags |= curr_opt->attr; - switch (curr_opt->attr) { - case CLK_HAVETIME1: - clock_stat.fudgetime1 = curr_opt->value.d; - break; - case CLK_HAVETIME2: - clock_stat.fudgetime2 = curr_opt->value.d; - break; - case CLK_HAVEVAL1: - clock_stat.fudgeval1 = curr_opt->value.i; - break; - case CLK_HAVEVAL2: - memcpy(&clock_stat.fudgeval2, - curr_opt->value.s, - min(strlen(curr_opt->value.s), 4)); - free(curr_opt->value.s); - break; - case CLK_HAVEFLAG1: - if (curr_opt->value.i) - clock_stat.flags |= CLK_FLAG1; - else - clock_stat.flags &= ~CLK_FLAG1; - break; - case CLK_HAVEFLAG2: - if (curr_opt->value.i) - clock_stat.flags |= CLK_FLAG2; - else - clock_stat.flags &= ~CLK_FLAG2; - break; - case CLK_HAVEFLAG3: - if (curr_opt->value.i) - clock_stat.flags |= CLK_FLAG3; - else - clock_stat.flags &= ~CLK_FLAG3; - break; - case CLK_HAVEFLAG4: - if (curr_opt->value.i) - clock_stat.flags |= CLK_FLAG4; - else - clock_stat.flags &= ~CLK_FLAG4; - break; - } + /* The attribute field is used to store the flag. + * Set haveflags with it + */ + clock_stat.haveflags |= curr_opt->attr; + switch (curr_opt->attr) { + case CLK_HAVETIME1: + clock_stat.fudgetime1 = curr_opt->value.d; + break; + case CLK_HAVETIME2: + clock_stat.fudgetime2 = curr_opt->value.d; + break; + case CLK_HAVEVAL1: + clock_stat.fudgeval1 = curr_opt->value.i; + break; + case CLK_HAVEVAL2: + memcpy(&clock_stat.fudgeval2, + curr_opt->value.s, + min(strlen(curr_opt->value.s), 4)); + free(curr_opt->value.s); + break; + case CLK_HAVEFLAG1: + if (curr_opt->value.i) + clock_stat.flags |= CLK_FLAG1; + else + clock_stat.flags &= ~CLK_FLAG1; + break; + case CLK_HAVEFLAG2: + if (curr_opt->value.i) + clock_stat.flags |= CLK_FLAG2; + else + clock_stat.flags &= ~CLK_FLAG2; + break; + case CLK_HAVEFLAG3: + if (curr_opt->value.i) + clock_stat.flags |= CLK_FLAG3; + else + clock_stat.flags &= ~CLK_FLAG3; + break; + case CLK_HAVEFLAG4: + if (curr_opt->value.i) + clock_stat.flags |= CLK_FLAG4; + else + clock_stat.flags &= ~CLK_FLAG4; + break; + } - free_node(curr_opt); - } + free_node(curr_opt); + } #ifdef REFCLOCK - if (!err_flag) - refclock_control(&addr_sock, &clock_stat, - (struct refclockstat *)0); + if (!err_flag) + refclock_control(&addr_sock, &clock_stat, + (struct refclockstat *)0); #endif - destroy_queue(curr_fudge->options); - free_node(curr_fudge); - } + destroy_queue(curr_fudge->options); + free_node(curr_fudge); + } } -static void config_vars(void) +static void +config_vars(void) { - struct attr_val *curr_var; - FILE *new_file; + struct attr_val *curr_var; + FILE *new_file; - while (!empty(my_config.vars)) { - curr_var = (struct attr_val *) dequeue(my_config.vars); - /* Determine which variable to set and set it */ - switch (curr_var->attr) { - case T_Broadcastdelay: - proto_config(PROTO_BROADDELAY, 0, curr_var->value.d, NULL); - break; - case T_Calldelay: - proto_config(PROTO_CALLDELAY, curr_var->value.i, 0, NULL); - break; - case T_Tick: - proto_config(PROTO_ADJ, 0, curr_var->value.d, NULL); - break; - case T_Driftfile: - stats_config(STATS_FREQ_FILE, curr_var->value.s); - free(curr_var->value.s); - break; - case T_Pidfile: - stats_config(STATS_PID_FILE, curr_var->value.s); - free(curr_var->value.s); - break; - case T_Logfile: - new_file = fopen(curr_var->value.s, "a"); - if (new_file != NULL) { - NLOG(NLOG_SYSINFO) /* conditional if clause for conditional syslog */ - msyslog(LOG_NOTICE, "logging to file %s", curr_var->value.s); - 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", - curr_var->value.s); - free(curr_var->value.s); - break; - case T_Automax: - #ifdef OPENSSL - sys_automax = 1 << max(curr_var->value.i, 10); - #else - printf("Warning: Automax command ignored!\n"); - #endif - break; - } - free_node(curr_var); - } + while (!empty(my_config.vars)) { + curr_var = (struct attr_val *) dequeue(my_config.vars); + /* Determine which variable to set and set it */ + switch (curr_var->attr) { + case T_Broadcastdelay: + proto_config(PROTO_BROADDELAY, 0, curr_var->value.d, NULL); + break; + case T_Calldelay: + proto_config(PROTO_CALLDELAY, curr_var->value.i, 0, NULL); + break; + case T_Tick: + proto_config(PROTO_ADJ, 0, curr_var->value.d, NULL); + break; + case T_Driftfile: + stats_config(STATS_FREQ_FILE, curr_var->value.s); + free(curr_var->value.s); + break; + case T_Pidfile: + stats_config(STATS_PID_FILE, curr_var->value.s); + free(curr_var->value.s); + break; + case T_Logfile: + new_file = fopen(curr_var->value.s, "a"); + if (new_file != NULL) { + NLOG(NLOG_SYSINFO) /* conditional if clause for conditional syslog */ + msyslog(LOG_NOTICE, "logging to file %s", curr_var->value.s); + 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", + curr_var->value.s); + free(curr_var->value.s); + break; + case T_Automax: +#ifdef OPENSSL + sys_automax = 1 << max(curr_var->value.i, 10); +#else + printf("Warning: Automax command ignored!\n"); +#endif + break; + } + free_node(curr_var); + } } /* Define a function to check if a resolved address is sane. * If yes, return 1, else return 0; */ -static int is_sane_resolved_address(struct sockaddr_storage peeraddr, int hmode) +static int +is_sane_resolved_address( + struct sockaddr_storage peeraddr, + int hmode + ) { - if ( + if ( #ifdef REFCLOCK - !ISREFCLOCKADR(&peeraddr) && + !ISREFCLOCKADR(&peeraddr) && #endif - ISBADADR(&peeraddr)) { - msyslog(LOG_ERR, - "attempt to configure invalid address %s", - stoa(&peeraddr)); - return 0; - } - /* - * Shouldn't be able to specify multicast - * address for server/peer! - * and unicast address for manycastclient! - */ - /* Check for IPv4 */ - if (peeraddr.ss_family == AF_INET) { - if (((hmode == T_Server) || (hmode == T_Peer) || (hmode == T_Pool)) && + ISBADADR(&peeraddr)) { + msyslog(LOG_ERR, + "attempt to configure invalid address %s", + stoa(&peeraddr)); + return 0; + } + /* + * Shouldn't be able to specify multicast + * address for server/peer! + * and unicast address for manycastclient! + */ + /* Check for IPv4 */ + if (peeraddr.ss_family == AF_INET) { + if (((hmode == T_Server) || (hmode == T_Peer) || (hmode == T_Pool)) && #ifdef REFCLOCK - !ISREFCLOCKADR(&peeraddr) && + !ISREFCLOCKADR(&peeraddr) && #endif - IN_CLASSD(ntohl(((struct sockaddr_in*)&peeraddr)->sin_addr.s_addr))) { - msyslog(LOG_ERR, - "attempt to configure invalid address %s", - stoa(&peeraddr)); - return 0; - } - if ((hmode == T_Manycastclient) && - !IN_CLASSD(ntohl(((struct sockaddr_in*)&peeraddr)->sin_addr.s_addr))) { - msyslog(LOG_ERR, - "attempt to configure invalid address %s", - stoa(&peeraddr)); - return 0; - } + IN_CLASSD(ntohl(((struct sockaddr_in*)&peeraddr)->sin_addr.s_addr))) { + msyslog(LOG_ERR, + "attempt to configure invalid address %s", + stoa(&peeraddr)); + return 0; + } + if ((hmode == T_Manycastclient) && + !IN_CLASSD(ntohl(((struct sockaddr_in*)&peeraddr)->sin_addr.s_addr))) { + msyslog(LOG_ERR, + "attempt to configure invalid address %s", + stoa(&peeraddr)); + return 0; + } - } - /* Check for IPv6 */ - else if(peeraddr.ss_family == AF_INET6) { - if (((hmode == T_Server) || (hmode == T_Peer) || (hmode == T_Pool)) && + } + /* Check for IPv6 */ + else if(peeraddr.ss_family == AF_INET6) { + if (((hmode == T_Server) || (hmode == T_Peer) || (hmode == T_Pool)) && #ifdef REFCLOCK - !ISREFCLOCKADR(&peeraddr) && + !ISREFCLOCKADR(&peeraddr) && #endif - IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6*)&peeraddr)->sin6_addr)) { - msyslog(LOG_ERR, - "attempt to configure in valid address %s", - stoa(&peeraddr)); - return 0; - } - if ((hmode == T_Manycastclient) && - !IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6*)&peeraddr)->sin6_addr)) { - msyslog(LOG_ERR, - "attempt to configure in valid address %s", - stoa(&peeraddr)); - return 0; - } - } + IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6*)&peeraddr)->sin6_addr)) { + msyslog(LOG_ERR, + "attempt to configure in valid address %s", + stoa(&peeraddr)); + return 0; + } + if ((hmode == T_Manycastclient) && + !IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6*)&peeraddr)->sin6_addr)) { + msyslog(LOG_ERR, + "attempt to configure in valid address %s", + stoa(&peeraddr)); + return 0; + } + } - if (peeraddr.ss_family == AF_INET6 && - isc_net_probeipv6() != ISC_R_SUCCESS) - return 0; + if (peeraddr.ss_family == AF_INET6 && + isc_net_probeipv6() != ISC_R_SUCCESS) + return 0; - /* Ok, all tests succeeded, now we can return 1 */ - return 1; + /* Ok, all tests succeeded, now we can return 1 */ + return 1; } -static int get_correct_host_mode(int hmode) +static int +get_correct_host_mode( + int hmode + ) { - switch (hmode) { - case T_Server: - case T_Pool: - case T_Manycastclient: - return MODE_CLIENT; - break; - case T_Peer: - return MODE_ACTIVE; - break; - case T_Broadcast: - return MODE_BROADCAST; - break; - default: - fprintf(stderr, "Fatal error in client_type in ntp_config.y"); - exit(1); - break; - } + switch (hmode) { + case T_Server: + case T_Pool: + case T_Manycastclient: + return MODE_CLIENT; + break; + case T_Peer: + return MODE_ACTIVE; + break; + case T_Broadcast: + return MODE_BROADCAST; + break; + default: + fprintf(stderr, "Fatal error in client_type in ntp_config.y"); + exit(1); + break; + } } -static void config_peers() +static void +config_peers(void) { - struct addrinfo *res, *res_bak; - struct sockaddr_storage peeraddr; - struct peer_node *curr_peer; - int hmode; - int status; - int no_needed; - int i; + struct addrinfo *res, *res_bak; + struct sockaddr_storage peeraddr; + struct peer_node *curr_peer; + int hmode; + int status; + int no_needed; + int i; - while (!empty(my_config.peers)) { - curr_peer = (struct peer_node *) dequeue(my_config.peers); + while (!empty(my_config.peers)) { + curr_peer = (struct peer_node *) dequeue(my_config.peers); - /* Find the number of associations needed. - * If a pool coomand is specified, then sys_maxclock needed - * else, only one is needed - */ - no_needed = (curr_peer->host_mode == T_Pool) ? sys_maxclock : 1; - - /* Find the correct host-mode */ - hmode = get_correct_host_mode(curr_peer->host_mode); + /* Find the number of associations needed. + * If a pool coomand is specified, then sys_maxclock needed + * else, only one is needed + */ + no_needed = (curr_peer->host_mode == T_Pool) ? sys_maxclock : 1; + + /* Find the correct host-mode */ + hmode = get_correct_host_mode(curr_peer->host_mode); - /* Attempt to resolve the address */ - memset((char *)&peeraddr, 0, sizeof(peeraddr)); - peeraddr.ss_family = curr_peer->addr->type; + /* Attempt to resolve the address */ + memset((char *)&peeraddr, 0, sizeof(peeraddr)); + peeraddr.ss_family = curr_peer->addr->type; - status = get_multiple_netnums(curr_peer->addr->address, &peeraddr, &res, 0, t_UNK); + status = get_multiple_netnums(curr_peer->addr->address, &peeraddr, &res, 0, t_UNK); - /* I don't know why getnetnum would return -1. - * The old code had this test, so I guess it must be - * useful - */ - if (status == -1) { - /* Do nothing, apparantly we found an IPv6 - * address and can't do anything about it */ - } - /* Check if name resolution failed. If yes, store the - * peer information in a file for asynchronous - * resolution later - */ - else if (status != 1) { - save_resolve(curr_peer->addr->address, - hmode, - curr_peer->peerversion, - curr_peer->minpoll, - curr_peer->maxpoll, - curr_peer->peerflags, - curr_peer->ttl, - curr_peer->peerkey, - (u_char *)"*"); - } - /* Yippie!! Name resolution has succeeded!!! - * Now we can proceed to some more sanity checks on - * the resolved address before we start to configure - * the peer - */ - else { - res_bak = res; - /* Loop to configure the desired number of associations - */ - for (i = 0; (i < no_needed) && res; res = res->ai_next) { - ++i; - memcpy(&peeraddr, res->ai_addr, res->ai_addrlen); + /* I don't know why getnetnum would return -1. + * The old code had this test, so I guess it must be + * useful + */ + if (status == -1) { + /* Do nothing, apparantly we found an IPv6 + * address and can't do anything about it */ + } + /* Check if name resolution failed. If yes, store the + * peer information in a file for asynchronous + * resolution later + */ + else if (status != 1) { + save_resolve(curr_peer->addr->address, + hmode, + curr_peer->peerversion, + curr_peer->minpoll, + curr_peer->maxpoll, + curr_peer->peerflags, + curr_peer->ttl, + curr_peer->peerkey, + (u_char *)"*"); + } + /* Yippie!! Name resolution has succeeded!!! + * Now we can proceed to some more sanity checks on + * the resolved address before we start to configure + * the peer + */ + else { + res_bak = res; + /* Loop to configure the desired number of associations + */ + for (i = 0; (i < no_needed) && res; res = res->ai_next) { + ++i; + memcpy(&peeraddr, res->ai_addr, res->ai_addrlen); #ifdef DEBUG - if (debug > 1) - printf("configuring host %s with address %s\n", - curr_peer->addr->address, stoa(&peeraddr)); + if (debug > 1) + printf("configuring host %s with address %s\n", + curr_peer->addr->address, stoa(&peeraddr)); #endif - if (is_sane_resolved_address(peeraddr, curr_peer->host_mode)) { - if (peer_config(&peeraddr, - ANY_INTERFACE_CHOOSE(&peeraddr), - hmode, - curr_peer->peerversion, - curr_peer->minpoll, - curr_peer->maxpoll, - curr_peer->peerflags, - curr_peer->ttl, - curr_peer->peerkey, - (u_char *)"*") == 0) { - msyslog(LOG_ERR, - "configuration of %s failed", - stoa(&peeraddr)); - } - } - } - freeaddrinfo(res_bak); - } - - /* Ok, everything done. Free up peer node memory */ - free(curr_peer->addr->address); - free_node(curr_peer->addr); - free_node(curr_peer); - } + if (is_sane_resolved_address(peeraddr, curr_peer->host_mode)) { + if (peer_config(&peeraddr, + ANY_INTERFACE_CHOOSE(&peeraddr), + hmode, + curr_peer->peerversion, + curr_peer->minpoll, + curr_peer->maxpoll, + curr_peer->peerflags, + curr_peer->ttl, + curr_peer->peerkey, + (u_char *)"*") == 0) { + msyslog(LOG_ERR, + "configuration of %s failed", + stoa(&peeraddr)); + } + } + } + freeaddrinfo(res_bak); + } + + /* Ok, everything done. Free up peer node memory */ + free(curr_peer->addr->address); + free_node(curr_peer->addr); + free_node(curr_peer); + } } #ifdef SIM -static void config_sim() +static void +config_sim(void) { - int i; - server_info *serv_info; - struct attr_val *init_stmt; + int i; + server_info *serv_info; + struct attr_val *init_stmt; - /* Check if a simulate block was found in the configuration code. - * If not, return an error and exit - */ - if (my_config.sim_details == NULL) { - fprintf(stderr, "ERROR!! I couldn't find a \"simulate\" block for configuring the simulator.\n"); - fprintf(stderr, "\tCheck your configuration file.\n"); - exit(1); - } - - /* Process the initialization statements - * ------------------------------------- - */ - while(!empty(my_config.sim_details->init_opts)) { - init_stmt = (struct attr_val *) - dequeue(my_config.sim_details->init_opts); - switch(init_stmt->attr) { - case T_Beep_Delay: - simulation.beep_delay = init_stmt->value.d; - break; - case T_Sim_Duration: - simulation.end_time = init_stmt->value.d; - break; - default: - yyerror("Internal Error in parser...\n" - "Invalid init statement in simulator block"); - break; - } - free_node(init_stmt); - } - destroy_queue(my_config.sim_details->init_opts); - - - /* Process the server list - * ----------------------- - */ - simulation.num_of_servers = get_no_of_elements(my_config.sim_details->servers); - simulation.servers = (server_info *) malloc(simulation.num_of_servers * - sizeof(server_info)); - - for (i = 0;i < simulation.num_of_servers;++i) { - serv_info = (server_info *) - dequeue(my_config.sim_details->servers); - if (!serv_info) - yyerror("Internal Error in parser...\n" - "Tried to initialize server list but no server returned\n"); - memcpy(&simulation.servers[i], serv_info, sizeof(server_info)); - free_node(serv_info); - } - destroy_queue(my_config.sim_details->servers); + /* Check if a simulate block was found in the configuration code. + * If not, return an error and exit + */ + if (my_config.sim_details == NULL) { + fprintf(stderr, "ERROR!! I couldn't find a \"simulate\" block for configuring the simulator.\n"); + fprintf(stderr, "\tCheck your configuration file.\n"); + exit(1); + } + + /* Process the initialization statements + * ------------------------------------- + */ + while(!empty(my_config.sim_details->init_opts)) { + init_stmt = (struct attr_val *) + dequeue(my_config.sim_details->init_opts); + switch(init_stmt->attr) { + case T_Beep_Delay: + simulation.beep_delay = init_stmt->value.d; + break; + case T_Sim_Duration: + simulation.end_time = init_stmt->value.d; + break; + default: + yyerror("Internal Error in parser...\n" + "Invalid init statement in simulator block"); + break; + } + free_node(init_stmt); + } + destroy_queue(my_config.sim_details->init_opts); + + + /* Process the server list + * ----------------------- + */ + simulation.num_of_servers = get_no_of_elements(my_config.sim_details->servers); + simulation.servers = (server_info *) malloc(simulation.num_of_servers * + sizeof(server_info)); + + for (i = 0;i < simulation.num_of_servers;++i) { + serv_info = (server_info *) + dequeue(my_config.sim_details->servers); + if (!serv_info) + yyerror("Internal Error in parser...\n" + "Tried to initialize server list but no server returned\n"); + memcpy(&simulation.servers[i], serv_info, sizeof(server_info)); + free_node(serv_info); + } + destroy_queue(my_config.sim_details->servers); - /* Free the sim_node memory and set the sim_details as NULL */ - free_node(my_config.sim_details); - my_config.sim_details = NULL; + /* Free the sim_node memory and set the sim_details as NULL */ + free_node(my_config.sim_details); + my_config.sim_details = NULL; - /* Create server associations */ - printf("Creating server associations\n"); - create_server_associations(); - fprintf(stderr,"\tServer associations successfully created!!\n"); + /* Create server associations */ + printf("Creating server associations\n"); + create_server_associations(); + fprintf(stderr,"\tServer associations successfully created!!\n"); } #endif /* SIM */ @@ -1755,171 +1863,178 @@ static void config_sim() * options */ -static void config_ntpd() +static void +config_ntpd(void) { - config_auth(); - config_tos(); - config_monitor(); - config_access(); - config_tinker(); - config_system_opts(); - config_logconfig(); - config_phone(); - config_setvar(); - config_ttl(); - config_trap(); - config_vars(); - config_other_modes(); - config_peers(); - config_fudge(); + config_auth(); + config_tos(); + config_monitor(); + config_access(); + config_tinker(); + config_system_opts(); + config_logconfig(); + config_phone(); + config_setvar(); + config_ttl(); + config_trap(); + config_vars(); + config_other_modes(); + config_peers(); + config_fudge(); } #ifdef SIM -static void config_ntpdsim() +static void +config_ntpdsim(void) { - printf("Configuring Simulator...\n"); - printf("Some ntpd-specific commands in the configuration file will be ignored.\n"); - - config_tos(); - config_monitor(); - config_tinker(); - config_system_opts(); - config_logconfig(); - config_vars(); - config_sim(); + printf("Configuring Simulator...\n"); + printf("Some ntpd-specific commands in the configuration file will be ignored.\n"); + + config_tos(); + config_monitor(); + config_tinker(); + config_system_opts(); + config_logconfig(); + config_vars(); + config_sim(); } #endif /* SIM */ -void config_remotely() +void +config_remotely(void) { - input_from_file = 0; -// init_syntax_tree(); - yyparse(); + input_from_file = 0; +// init_syntax_tree(); + yyparse(); #ifdef DEBUG - if (debug > 1) - printf("Finished Parsing!!\n"); + if (debug > 1) + printf("Finished Parsing!!\n"); #endif - config_ntpd(); + config_ntpd(); - input_from_file = 1; + input_from_file = 1; } /* ACTUAL getconfig code */ -void getconfig(int argc,char *argv[]) +void +getconfig( + int argc, + char *argv[] + ) { - char line[MAXLINE]; + char line[MAXLINE]; #ifndef SYS_WINNT - config_file = CONFIG_FILE; + 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 = 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; + 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 */ - res_fp = NULL; - ntp_syslogmask = NLOG_SYNCMASK; /* set more via logconfig */ - - /* - * install a non default variable with this daemon version - */ - (void) sprintf(line, "daemon_version=\"%s\"", Version); - set_sys_var(line, strlen(line)+1, RO); + res_fp = NULL; + ntp_syslogmask = NLOG_SYNCMASK; /* set more via logconfig */ + + /* + * install a non default variable with this daemon version + */ + (void) sprintf(line, "daemon_version=\"%s\"", Version); + set_sys_var(line, strlen(line)+1, RO); - /* - * Say how we're setting the time of day - */ - (void) sprintf(line, "settimeofday=\"%s\"", set_tod_using); - set_sys_var(line, strlen(line)+1, RO); - - /* - * Initialize the loop. - */ - loop_config(LOOP_DRIFTINIT, 0.); + /* + * Say how we're setting the time of day + */ + (void) sprintf(line, "settimeofday=\"%s\"", set_tod_using); + set_sys_var(line, strlen(line)+1, RO); + + /* + * Initialize the loop. + */ + loop_config(LOOP_DRIFTINIT, 0.); - getCmdOpts(argc, argv); + getCmdOpts(argc, argv); - curr_include_level = 0; - if ( - (fp[curr_include_level] = F_OPEN(FindConfig(config_file), "r")) == NULL + curr_include_level = 0; + if ( + (fp[curr_include_level] = F_OPEN(FindConfig(config_file), "r")) == NULL #ifdef HAVE_NETINFO - /* If there is no config_file, try NetInfo. */ - && check_netinfo && !(config_netinfo = get_netinfo_config()) + /* If there is no config_file, try NetInfo. */ + && check_netinfo && !(config_netinfo = get_netinfo_config()) #endif /* HAVE_NETINFO */ - ) { - fprintf(stderr, "getconfig: Couldn't open <%s>\n", FindConfig(config_file)); - msyslog(LOG_INFO, "getconfig: Couldn't open <%s>", FindConfig(config_file)); + ) { + fprintf(stderr, "getconfig: Couldn't open <%s>\n", FindConfig(config_file)); + msyslog(LOG_INFO, "getconfig: Couldn't open <%s>", FindConfig(config_file)); #ifdef SYS_WINNT - /* Under WinNT try alternate_config_file name, first NTP.CONF, then NTP.INI */ + /* Under WinNT try alternate_config_file name, first NTP.CONF, then NTP.INI */ - if ((fp[curr_include_level] = F_OPEN(FindConfig(alt_config_file), "r")) == NULL) { + if ((fp[curr_include_level] = F_OPEN(FindConfig(alt_config_file), "r")) == NULL) { - /* - * Broadcast clients can sometimes run without - * a configuration file. - */ + /* + * Broadcast clients can sometimes run without + * a configuration file. + */ - fprintf(stderr, "getconfig: Couldn't open <%s>\n", FindConfig(alt_config_file)); - msyslog(LOG_INFO, "getconfig: Couldn't open <%s>", FindConfig(alt_config_file)); - return; - } + fprintf(stderr, "getconfig: Couldn't open <%s>\n", FindConfig(alt_config_file)); + msyslog(LOG_INFO, "getconfig: Couldn't open <%s>", FindConfig(alt_config_file)); + return; + } #else /* not SYS_WINNT */ - return; + return; #endif /* not SYS_WINNT */ - } + } - /*** BULK OF THE PARSER ***/ - ip_file = fp[curr_include_level]; - key_scanner = create_keyword_scanner(keyword_list); - init_syntax_tree(); - yyparse(); + /*** BULK OF THE PARSER ***/ + ip_file = fp[curr_include_level]; + key_scanner = create_keyword_scanner(keyword_list); + init_syntax_tree(); + yyparse(); #ifdef DEBUG - if (debug > 1) - printf("Finished Parsing!!\n"); + if (debug > 1) + printf("Finished Parsing!!\n"); #endif - /* The actual configuration done depends on whether we are configuring the - * simulator or the daemon. Perform a check and call the appropriate - * function as needed. - */ + /* The actual configuration done depends on whether we are configuring the + * simulator or the daemon. Perform a check and call the appropriate + * function as needed. + */ #ifndef SIM - config_ntpd(); + config_ntpd(); #else - config_ntpdsim(); + config_ntpdsim(); #endif - while (curr_include_level != -1) { - FCLOSE(fp[curr_include_level--]); - } + while (curr_include_level != -1) { + FCLOSE(fp[curr_include_level--]); + } #ifdef HAVE_NETINFO - if (config_netinfo) - free_netinfo_config(config_netinfo); + if (config_netinfo) + free_netinfo_config(config_netinfo); #endif /* HAVE_NETINFO */ - if (res_fp != NULL) { - if (call_resolver) { - /* - * Need name resolution - */ - do_resolve_internal(); - } - } + if (res_fp != NULL) { + if (call_resolver) { + /* + * Need name resolution + */ + do_resolve_internal(); + } + } } @@ -2001,7 +2116,7 @@ get_logmask( * configuration and initialize the configuration state. */ static struct netinfo_config_state * -get_netinfo_config() +get_netinfo_config(void) { ni_status status; void *domain; @@ -2040,7 +2155,9 @@ get_netinfo_config() * free_netinfo_config - release NetInfo configuration state */ static void -free_netinfo_config(struct netinfo_config_state *config) +free_netinfo_config( + struct netinfo_config_state *config + ) { ni_free(config->domain); free(config); @@ -2065,7 +2182,7 @@ gettokens_netinfo ( /* * Iterate through each keyword and look for a property that matches it. */ - again: + again: if (!val_list) { for (; prop_index < (sizeof(keywords)/sizeof(keywords[0])); prop_index++) { @@ -2085,13 +2202,13 @@ gettokens_netinfo ( if (namelist.ni_namelist_len == 0) continue; if (! (val_list = config->val_list = (char**)malloc(sizeof(char*) * (namelist.ni_namelist_len + 1)))) - { msyslog(LOG_ERR, "out of memory while configuring"); break; } + { msyslog(LOG_ERR, "out of memory while configuring"); break; } for (index = 0; index < namelist.ni_namelist_len; index++) { char *value = namelist.ni_namelist_val[index]; if (! (val_list[index] = (char*)malloc(strlen(value)+1))) - { msyslog(LOG_ERR, "out of memory while configuring"); break; } + { msyslog(LOG_ERR, "out of memory while configuring"); break; } strcpy(val_list[index], value); } @@ -2138,8 +2255,8 @@ gettokens_netinfo ( if (ntok == MAXTOKENS) { /* HMS: chomp it to lose the EOL? */ msyslog(LOG_ERR, - "gettokens_netinfo: too many tokens. Ignoring: %s", - tokens); + "gettokens_netinfo: too many tokens. Ignoring: %s", + tokens); } else { *ntokens = ntok + 1; } @@ -2168,92 +2285,92 @@ gettokens_netinfo ( static int getnetnum( - const char *num, - struct sockaddr_storage *addr, - int complain, - enum gnn_type a_type - ) + const char *num, + struct sockaddr_storage *addr, + int complain, + enum gnn_type a_type + ) { - int retval; - struct addrinfo *res; + int retval; + struct addrinfo *res; - /* Get all the addresses that resolve to this name */ - retval = get_multiple_netnums(num, addr, &res, complain, a_type); + /* Get all the addresses that resolve to this name */ + retval = get_multiple_netnums(num, addr, &res, complain, a_type); - if (retval != 1) { - /* Name resolution failed */ - return retval; - } + if (retval != 1) { + /* Name resolution failed */ + return retval; + } - memcpy(addr, res->ai_addr, res->ai_addrlen); + memcpy(addr, res->ai_addr, res->ai_addrlen); #ifdef DEBUG - if (debug > 1) - printf("getnetnum given %s, got %s \n", - num, stoa(addr)); + if (debug > 1) + printf("getnetnum given %s, got %s \n", + num, stoa(addr)); #endif - freeaddrinfo(res); - return 1; + freeaddrinfo(res); + return 1; } static int get_multiple_netnums( - const char *num, - struct sockaddr_storage *addr, - struct addrinfo **res, - int complain, - enum gnn_type a_type - ) + const char *num, + struct sockaddr_storage *addr, + struct addrinfo **res, + int complain, + enum gnn_type a_type + ) { - struct addrinfo hints; - struct addrinfo *ptr; - - int retval; - - /* Get host address. Looking for UDP datagram connection */ - memset(&hints, 0, sizeof (hints)); - if (addr->ss_family == AF_INET || addr->ss_family == AF_INET6) - hints.ai_family = addr->ss_family; - else - hints.ai_family = AF_UNSPEC; - /* - * If we don't have an IPv6 stack, just look up IPv4 addresses - */ - if (isc_net_probeipv6() != ISC_R_SUCCESS) - hints.ai_family = AF_INET; - - hints.ai_socktype = SOCK_DGRAM; + struct addrinfo hints; + struct addrinfo *ptr; + + int retval; + + /* Get host address. Looking for UDP datagram connection */ + memset(&hints, 0, sizeof (hints)); + if (addr->ss_family == AF_INET || addr->ss_family == AF_INET6) + hints.ai_family = addr->ss_family; + else + hints.ai_family = AF_UNSPEC; + /* + * If we don't have an IPv6 stack, just look up IPv4 addresses + */ + if (isc_net_probeipv6() != ISC_R_SUCCESS) + hints.ai_family = AF_INET; + + hints.ai_socktype = SOCK_DGRAM; #ifdef DEBUG - if (debug > 3) - printf("getaddrinfo %s\n", num); + if (debug > 3) + printf("getaddrinfo %s\n", num); #endif - retval = getaddrinfo(num, "ntp", &hints, &ptr); - if (retval != 0 || - (ptr->ai_family == AF_INET6 && isc_net_probeipv6() != ISC_R_SUCCESS)) { - if (complain) - msyslog(LOG_ERR, - "getaddrinfo: \"%s\" invalid host address, ignored", - num); + retval = getaddrinfo(num, "ntp", &hints, &ptr); + if (retval != 0 || + (ptr->ai_family == AF_INET6 && isc_net_probeipv6() != ISC_R_SUCCESS)) { + if (complain) + msyslog(LOG_ERR, + "getaddrinfo: \"%s\" invalid host address, ignored", + num); #ifdef DEBUG - if (debug > 0) - printf( - "getaddrinfo: \"%s\" invalid host address%s.\n", - num, (complain) - ? ", ignored" - : ""); + if (debug > 0) + printf( + "getaddrinfo: \"%s\" invalid host address%s.\n", + num, (complain) + ? ", ignored" + : ""); #endif - if (retval == 0 && - ptr->ai_family == AF_INET6 && - isc_net_probeipv6() != ISC_R_SUCCESS) - { - return -1; - } - else { - return 0; - } - } - *res = ptr; - - return 1; + if (retval == 0 && + ptr->ai_family == AF_INET6 && + isc_net_probeipv6() != ISC_R_SUCCESS) + { + return -1; + } + else { + return 0; + } + } + *res = ptr; + + return 1; } @@ -2333,11 +2450,11 @@ save_resolve( #endif (void)fprintf(res_fp, "%s %d %d %d %d %d %d %u %s\n", name, - mode, version, minpoll, maxpoll, flags, ttl, keyid, keystr); + mode, version, minpoll, maxpoll, flags, ttl, keyid, keystr); #ifdef DEBUG if (debug > 1) printf("config: %s %d %d %d %d %x %d %u %s\n", name, mode, - version, minpoll, maxpoll, flags, ttl, keyid, keystr); + version, minpoll, maxpoll, flags, ttl, keyid, keystr); #endif #else /* SYS_VXWORKS */ @@ -2446,7 +2563,7 @@ do_resolve_internal(void) #ifdef DEBUG if (0) - debug = 2; + debug = 2; #endif # ifndef LOG_DAEMON @@ -2460,10 +2577,10 @@ do_resolve_internal(void) #ifndef SYS_CYGWIN32 # ifdef DEBUG if (debug) - setlogmask(LOG_UPTO(LOG_DEBUG)); + setlogmask(LOG_UPTO(LOG_DEBUG)); else # endif /* DEBUG */ - setlogmask(LOG_UPTO(LOG_DEBUG)); /* @@@ was INFO */ + setlogmask(LOG_UPTO(LOG_DEBUG)); /* @@@ was INFO */ # endif /* LOG_DAEMON */ #endif @@ -2478,9 +2595,9 @@ do_resolve_internal(void) exit(1); } #else - /* vxWorks spawns a thread... -casey */ - i = sp (ntp_intres); - /*i = taskSpawn("ntp_intres",100,VX_FP_TASK,20000,ntp_intres);*/ + /* vxWorks spawns a thread... -casey */ + i = sp (ntp_intres); + /*i = taskSpawn("ntp_intres",100,VX_FP_TASK,20000,ntp_intres);*/ #endif if (i == -1) { msyslog(LOG_ERR, "fork() failed, can't start ntp_intres: %m");