1285612Sdelphij#ifndef NTP_CONFIG_H 2285612Sdelphij#define NTP_CONFIG_H 3285612Sdelphij 4285612Sdelphij#ifdef HAVE_SYS_RESOURCE_H 5285612Sdelphij# include <sys/resource.h> 6285612Sdelphij#endif /* HAVE_SYS_RESOURCE_H */ 7285612Sdelphij 8285612Sdelphij#include "ntp_machine.h" 9285612Sdelphij#include "ntpsim.h" 10285612Sdelphij 11285612Sdelphij 1282498Sroberto/* 1382498Sroberto * Configuration file name 1482498Sroberto */ 1582498Sroberto#ifndef CONFIG_FILE 1682498Sroberto# ifndef SYS_WINNT 1782498Sroberto# define CONFIG_FILE "/etc/ntp.conf" 1882498Sroberto# else /* SYS_WINNT */ 1982498Sroberto# define CONFIG_FILE "%windir%\\system32\\drivers\\etc\\ntp.conf" 2082498Sroberto# define ALT_CONFIG_FILE "%windir%\\ntp.conf" 21132451Sroberto# define NTP_KEYSDIR "%windir%\\system32\\drivers\\etc" 2282498Sroberto# endif /* SYS_WINNT */ 2382498Sroberto#endif /* not CONFIG_FILE */ 2482498Sroberto 2582498Sroberto 2682498Sroberto/* 27285612Sdelphij * We keep config trees around for possible saveconfig use. When 28285612Sdelphij * built with configure --disable-saveconfig, and when built with 29285612Sdelphij * debugging enabled, include the free_config_*() routines. In the 30285612Sdelphij * DEBUG case, they are used in an atexit() cleanup routine to make 31285612Sdelphij * postmortem leak check reports more interesting. 3282498Sroberto */ 33285612Sdelphij#if !defined(FREE_CFG_T) && (!defined(SAVECONFIG) || defined(DEBUG)) 34285612Sdelphij#define FREE_CFG_T 35285612Sdelphij#endif 3682498Sroberto 37285612Sdelphij/* Limits */ 38285612Sdelphij#define MAXLINE 1024 3982498Sroberto 40285612Sdelphij/* Configuration sources */ 4182498Sroberto 42285612Sdelphij#define CONF_SOURCE_FILE 0 43285612Sdelphij#define CONF_SOURCE_NTPQ 1 4482498Sroberto 45285612Sdelphij/* list of servers from command line for config_peers() */ 46285612Sdelphijextern int cmdline_server_count; 47285612Sdelphijextern char ** cmdline_servers; 4882498Sroberto 49289997Sglebius/* set to zero if we're not locking memory */ 50289997Sglebiusextern int cur_memlock; 5182498Sroberto 52285612Sdelphijtypedef struct int_range_tag { 53285612Sdelphij int first; 54285612Sdelphij int last; 55285612Sdelphij} int_range; 56132451Sroberto 57330141Sdelphij/* generic list node */ 58330141Sdelphijtypedef struct any_node_tag any_node; 59330141Sdelphijstruct any_node_tag { 60330141Sdelphij any_node * link; 61330141Sdelphij}; 62330141Sdelphij 63330141Sdelphijtypedef DECL_FIFO_ANCHOR(any_node) any_node_fifo; 64330141Sdelphij 65330141Sdelphij/* Structure for storing an attribute-value pair */ 66285612Sdelphijtypedef struct attr_val_tag attr_val; 67285612Sdelphijstruct attr_val_tag { 68285612Sdelphij attr_val * link; 69285612Sdelphij int attr; 70285612Sdelphij int type; /* T_String, T_Integer, ... */ 71285612Sdelphij union val { 72285612Sdelphij int i; 73285612Sdelphij u_int u; 74285612Sdelphij int_range r; 75285612Sdelphij double d; 76285612Sdelphij char * s; 77285612Sdelphij } value; 78285612Sdelphij}; 7982498Sroberto 80285612Sdelphijtypedef DECL_FIFO_ANCHOR(attr_val) attr_val_fifo; 81132451Sroberto 82285612Sdelphij/* Structure for nodes on the syntax tree */ 83285612Sdelphijtypedef struct address_node_tag address_node; 84285612Sdelphijstruct address_node_tag { 85285612Sdelphij address_node * link; 86285612Sdelphij char * address; 87285612Sdelphij u_short type; /* family, AF_UNSPEC (0), AF_INET[6] */ 88285612Sdelphij}; 89285612Sdelphij 90285612Sdelphijtypedef DECL_FIFO_ANCHOR(address_node) address_fifo; 91285612Sdelphij 92285612Sdelphijtypedef struct int_node_tag int_node; 93285612Sdelphijstruct int_node_tag { 94285612Sdelphij int_node * link; 95285612Sdelphij int i; 96285612Sdelphij}; 97285612Sdelphij 98285612Sdelphijtypedef DECL_FIFO_ANCHOR(int_node) int_fifo; 99285612Sdelphij 100285612Sdelphijtypedef struct string_node_tag string_node; 101285612Sdelphijstruct string_node_tag { 102285612Sdelphij string_node * link; 103285612Sdelphij char * s; 104285612Sdelphij}; 105285612Sdelphij 106285612Sdelphijtypedef DECL_FIFO_ANCHOR(string_node) string_fifo; 107285612Sdelphij 108285612Sdelphijtypedef struct restrict_node_tag restrict_node; 109285612Sdelphijstruct restrict_node_tag { 110285612Sdelphij restrict_node * link; 111285612Sdelphij address_node * addr; 112285612Sdelphij address_node * mask; 113330141Sdelphij int_fifo * flag_tok_fifo; 114285612Sdelphij int line_no; 115330141Sdelphij short ippeerlimit; 116285612Sdelphij}; 117285612Sdelphij 118285612Sdelphijtypedef DECL_FIFO_ANCHOR(restrict_node) restrict_fifo; 119285612Sdelphij 120285612Sdelphijtypedef struct peer_node_tag peer_node; 121285612Sdelphijstruct peer_node_tag { 122285612Sdelphij peer_node * link; 123285612Sdelphij int host_mode; 124285612Sdelphij address_node * addr; 125285612Sdelphij attr_val_fifo * peerflags; 126285612Sdelphij u_char minpoll; 127285612Sdelphij u_char maxpoll; 128285612Sdelphij u_int32 ttl; 129285612Sdelphij u_char peerversion; 130285612Sdelphij keyid_t peerkey; 131285612Sdelphij char * group; 132285612Sdelphij}; 133285612Sdelphij 134285612Sdelphijtypedef DECL_FIFO_ANCHOR(peer_node) peer_fifo; 135285612Sdelphij 136285612Sdelphijtypedef struct unpeer_node_tag unpeer_node; 137285612Sdelphijstruct unpeer_node_tag { 138285612Sdelphij unpeer_node * link; 139285612Sdelphij associd_t assocID; 140285612Sdelphij address_node * addr; 141285612Sdelphij}; 142285612Sdelphij 143285612Sdelphijtypedef DECL_FIFO_ANCHOR(unpeer_node) unpeer_fifo; 144285612Sdelphij 145285612Sdelphijtypedef struct auth_node_tag auth_node; 146285612Sdelphijstruct auth_node_tag { 147285612Sdelphij int control_key; 148285612Sdelphij int cryptosw; 149285612Sdelphij attr_val_fifo * crypto_cmd_list; 150285612Sdelphij char * keys; 151285612Sdelphij char * keysdir; 152285612Sdelphij int request_key; 153285612Sdelphij int revoke; 154285612Sdelphij attr_val_fifo * trusted_key_list; 155285612Sdelphij char * ntp_signd_socket; 156285612Sdelphij}; 157285612Sdelphij 158285612Sdelphijtypedef struct filegen_node_tag filegen_node; 159285612Sdelphijstruct filegen_node_tag { 160285612Sdelphij filegen_node * link; 161285612Sdelphij int filegen_token; 162285612Sdelphij attr_val_fifo * options; 163285612Sdelphij}; 164285612Sdelphij 165285612Sdelphijtypedef DECL_FIFO_ANCHOR(filegen_node) filegen_fifo; 166285612Sdelphij 167285612Sdelphijtypedef struct setvar_node_tag setvar_node; 168285612Sdelphijstruct setvar_node_tag { 169285612Sdelphij setvar_node * link; 170285612Sdelphij char * var; 171285612Sdelphij char * val; 172285612Sdelphij int isdefault; 173285612Sdelphij}; 174285612Sdelphij 175285612Sdelphijtypedef DECL_FIFO_ANCHOR(setvar_node) setvar_fifo; 176285612Sdelphij 177285612Sdelphijtypedef struct nic_rule_node_tag nic_rule_node; 178285612Sdelphijstruct nic_rule_node_tag { 179285612Sdelphij nic_rule_node * link; 180285612Sdelphij int match_class; 181285612Sdelphij char * if_name; /* or numeric address */ 182285612Sdelphij int action; 183285612Sdelphij}; 184285612Sdelphij 185285612Sdelphijtypedef DECL_FIFO_ANCHOR(nic_rule_node) nic_rule_fifo; 186285612Sdelphij 187285612Sdelphijtypedef struct addr_opts_node_tag addr_opts_node; 188285612Sdelphijstruct addr_opts_node_tag { 189285612Sdelphij addr_opts_node *link; 190285612Sdelphij address_node * addr; 191285612Sdelphij attr_val_fifo * options; 192285612Sdelphij}; 193285612Sdelphij 194285612Sdelphijtypedef DECL_FIFO_ANCHOR(addr_opts_node) addr_opts_fifo; 195285612Sdelphij 196285612Sdelphijtypedef struct sim_node_tag sim_node; 197285612Sdelphijstruct sim_node_tag { 198285612Sdelphij sim_node * link; 199285612Sdelphij attr_val_fifo * init_opts; 200285612Sdelphij server_info_fifo * servers; 201285612Sdelphij}; 202285612Sdelphij 203285612Sdelphijtypedef DECL_FIFO_ANCHOR(sim_node) sim_fifo; 204285612Sdelphij 205285612Sdelphij/* The syntax tree */ 206285612Sdelphijtypedef struct config_tree_tag config_tree; 207285612Sdelphijstruct config_tree_tag { 208285612Sdelphij config_tree * link; 209285612Sdelphij 210285612Sdelphij attr_val source; 211285612Sdelphij time_t timestamp; 212285612Sdelphij 213285612Sdelphij peer_fifo * peers; 214285612Sdelphij unpeer_fifo * unpeers; 215285612Sdelphij 216285612Sdelphij /* Other Modes */ 217285612Sdelphij int broadcastclient; 218285612Sdelphij address_fifo * manycastserver; 219285612Sdelphij address_fifo * multicastclient; 220285612Sdelphij 221285612Sdelphij attr_val_fifo * orphan_cmds; /* s/b renamed tos_options */ 222285612Sdelphij 223285612Sdelphij /* Monitoring Configuration */ 224285612Sdelphij int_fifo * stats_list; 225285612Sdelphij char * stats_dir; 226285612Sdelphij filegen_fifo * filegen_opts; 227285612Sdelphij 228285612Sdelphij /* Access Control Configuration */ 229285612Sdelphij attr_val_fifo * discard_opts; 230285612Sdelphij attr_val_fifo * mru_opts; 231285612Sdelphij restrict_fifo * restrict_opts; 232285612Sdelphij 233285612Sdelphij addr_opts_fifo *fudge; 234285612Sdelphij attr_val_fifo * rlimit; 235285612Sdelphij attr_val_fifo * tinker; 236285612Sdelphij attr_val_fifo * enable_opts; 237285612Sdelphij attr_val_fifo * disable_opts; 238285612Sdelphij 239285612Sdelphij auth_node auth; 240285612Sdelphij 241285612Sdelphij attr_val_fifo * logconfig; 242285612Sdelphij string_fifo * phone; 243285612Sdelphij setvar_fifo * setvar; 244285612Sdelphij int_fifo * ttl; 245285612Sdelphij addr_opts_fifo *trap; 246285612Sdelphij attr_val_fifo * vars; 247285612Sdelphij nic_rule_fifo * nic_rules; 248285612Sdelphij int_fifo * reset_counters; 249285612Sdelphij 250285612Sdelphij sim_fifo * sim_details; 251285612Sdelphij int mdnstries; 252285612Sdelphij}; 253285612Sdelphij 254285612Sdelphij 255285612Sdelphij/* Structure for holding a remote configuration command */ 256285612Sdelphijstruct REMOTE_CONFIG_INFO { 257285612Sdelphij char buffer[MAXLINE]; 258285612Sdelphij char err_msg[MAXLINE]; 259285612Sdelphij int pos; 260285612Sdelphij int err_pos; 261285612Sdelphij int no_errors; 262285612Sdelphij}; 263285612Sdelphij 264285612Sdelphij 265132451Sroberto/* 266285612Sdelphij * context for trap_name_resolved() to call ctlsettrap() once the 267285612Sdelphij * name->address resolution completes. 26882498Sroberto */ 269285612Sdelphijtypedef struct settrap_parms_tag { 270285612Sdelphij sockaddr_u ifaddr; 271285612Sdelphij int ifaddr_nonnull; 272285612Sdelphij} settrap_parms; 273132451Sroberto 274285612Sdelphij 275285612Sdelphij/* get text from T_ tokens */ 276285612Sdelphijconst char * token_name(int token); 277285612Sdelphij 278285612Sdelphij/* generic fifo routines for structs linked by 1st member */ 279330141Sdelphijtypedef void (*fifo_deleter)(void*); 280330141Sdelphijvoid * destroy_gen_fifo(void *fifo, fifo_deleter func); 281330141Sdelphijvoid * append_gen_fifo(void *fifo, void *entry); 282285612Sdelphijvoid * concat_gen_fifos(void *first, void *second); 283330141Sdelphij#define DESTROY_G_FIFO(pf, func) \ 284330141Sdelphij ((pf) = destroy_gen_fifo((pf), (fifo_deleter)(func))) 285285612Sdelphij#define APPEND_G_FIFO(pf, pe) \ 286285612Sdelphij ((pf) = append_gen_fifo((pf), (pe))) 287285612Sdelphij#define CONCAT_G_FIFOS(first, second) \ 288285612Sdelphij ((first) = concat_gen_fifos((first), (second))) 289285612Sdelphij#define HEAD_PFIFO(pf) \ 290285612Sdelphij (((pf) != NULL) \ 291285612Sdelphij ? HEAD_FIFO(*(pf)) \ 292285612Sdelphij : NULL) 293285612Sdelphij 294285612Sdelphijpeer_node *create_peer_node(int hmode, address_node *addr, 295285612Sdelphij attr_val_fifo *options); 296285612Sdelphijunpeer_node *create_unpeer_node(address_node *addr); 297285612Sdelphijaddress_node *create_address_node(char *addr, int type); 298285612Sdelphijvoid destroy_address_node(address_node *my_node); 299285612Sdelphijattr_val *create_attr_dval(int attr, double value); 300285612Sdelphijattr_val *create_attr_ival(int attr, int value); 301285612Sdelphijattr_val *create_attr_uval(int attr, u_int value); 302285612Sdelphijattr_val *create_attr_rangeval(int attr, int first, int last); 303285612Sdelphijattr_val *create_attr_sval(int attr, const char *s); 304330141Sdelphijvoid destroy_attr_val(attr_val *node); 305285612Sdelphijfilegen_node *create_filegen_node(int filegen_token, 306285612Sdelphij attr_val_fifo *options); 307285612Sdelphijstring_node *create_string_node(char *str); 308285612Sdelphijrestrict_node *create_restrict_node(address_node *addr, 309285612Sdelphij address_node *mask, 310330141Sdelphij short ippeerlimit, 311285612Sdelphij int_fifo *flags, int line_no); 312285612Sdelphijint_node *create_int_node(int val); 313285612Sdelphijaddr_opts_node *create_addr_opts_node(address_node *addr, 314285612Sdelphij attr_val_fifo *options); 315285612Sdelphijsim_node *create_sim_node(attr_val_fifo *init_opts, 316285612Sdelphij server_info_fifo *servers); 317285612Sdelphijsetvar_node *create_setvar_node(char *var, char *val, int isdefault); 318285612Sdelphijnic_rule_node *create_nic_rule_node(int match_class, char *if_name, 319285612Sdelphij int action); 320285612Sdelphij 321285612Sdelphijscript_info *create_sim_script_info(double duration, 322285612Sdelphij attr_val_fifo *script_queue); 323285612Sdelphijserver_info *create_sim_server(address_node *addr, double server_offset, 324285612Sdelphij script_info_fifo *script); 325285612Sdelphij 326285612Sdelphijextern struct REMOTE_CONFIG_INFO remote_config; 327285612Sdelphijvoid config_remotely(sockaddr_u *); 328285612Sdelphij 329285612Sdelphij#ifdef SAVECONFIG 330285612Sdelphijint dump_config_tree(config_tree *ptree, FILE *df, int comment); 331285612Sdelphijint dump_all_config_trees(FILE *df, int comment); 332285612Sdelphij#endif 333285612Sdelphij 334285612Sdelphij#if defined(HAVE_SETRLIMIT) 335285612Sdelphijvoid ntp_rlimit(int, rlim_t, int, const char *); 336285612Sdelphij#endif 337285612Sdelphij 338285612Sdelphij#endif /* !defined(NTP_CONFIG_H) */ 339