12b15cb3dSCy Schubert #ifndef NTP_CONFIG_H 22b15cb3dSCy Schubert #define NTP_CONFIG_H 32b15cb3dSCy Schubert 42b15cb3dSCy Schubert #ifdef HAVE_SYS_RESOURCE_H 52b15cb3dSCy Schubert # include <sys/resource.h> 62b15cb3dSCy Schubert #endif /* HAVE_SYS_RESOURCE_H */ 72b15cb3dSCy Schubert 82b15cb3dSCy Schubert #include "ntp_machine.h" 92d4e511cSCy Schubert #include "ntp_psl.h" 102b15cb3dSCy Schubert #include "ntpsim.h" 112b15cb3dSCy Schubert 122b15cb3dSCy Schubert 13224ba2bdSOllivier Robert /* 14224ba2bdSOllivier Robert * Configuration file name 15224ba2bdSOllivier Robert */ 16224ba2bdSOllivier Robert #ifndef CONFIG_FILE 17224ba2bdSOllivier Robert # ifndef SYS_WINNT 18224ba2bdSOllivier Robert # define CONFIG_FILE "/etc/ntp.conf" 19224ba2bdSOllivier Robert # else /* SYS_WINNT */ 20224ba2bdSOllivier Robert # define CONFIG_FILE "%windir%\\system32\\drivers\\etc\\ntp.conf" 21224ba2bdSOllivier Robert # define ALT_CONFIG_FILE "%windir%\\ntp.conf" 229c2daa00SOllivier Robert # define NTP_KEYSDIR "%windir%\\system32\\drivers\\etc" 23224ba2bdSOllivier Robert # endif /* SYS_WINNT */ 24224ba2bdSOllivier Robert #endif /* not CONFIG_FILE */ 25224ba2bdSOllivier Robert 26224ba2bdSOllivier Robert 27224ba2bdSOllivier Robert /* 282b15cb3dSCy Schubert * We keep config trees around for possible saveconfig use. When 292b15cb3dSCy Schubert * built with configure --disable-saveconfig, and when built with 302b15cb3dSCy Schubert * debugging enabled, include the free_config_*() routines. In the 312b15cb3dSCy Schubert * DEBUG case, they are used in an atexit() cleanup routine to make 322b15cb3dSCy Schubert * postmortem leak check reports more interesting. 33224ba2bdSOllivier Robert */ 342b15cb3dSCy Schubert #if !defined(FREE_CFG_T) && (!defined(SAVECONFIG) || defined(DEBUG)) 352b15cb3dSCy Schubert #define FREE_CFG_T 362b15cb3dSCy Schubert #endif 372b15cb3dSCy Schubert 382b15cb3dSCy Schubert /* Limits */ 392b15cb3dSCy Schubert #define MAXLINE 1024 402b15cb3dSCy Schubert 412b15cb3dSCy Schubert /* Configuration sources */ 422b15cb3dSCy Schubert 432b15cb3dSCy Schubert #define CONF_SOURCE_FILE 0 442b15cb3dSCy Schubert #define CONF_SOURCE_NTPQ 1 452b15cb3dSCy Schubert 462b15cb3dSCy Schubert /* list of servers from command line for config_peers() */ 472b15cb3dSCy Schubert extern int cmdline_server_count; 482b15cb3dSCy Schubert extern char ** cmdline_servers; 492b15cb3dSCy Schubert 509034852cSGleb Smirnoff /* set to zero if we're not locking memory */ 519034852cSGleb Smirnoff extern int cur_memlock; 522b15cb3dSCy Schubert 532b15cb3dSCy Schubert typedef struct int_range_tag { 542b15cb3dSCy Schubert int first; 552b15cb3dSCy Schubert int last; 562b15cb3dSCy Schubert } int_range; 572b15cb3dSCy Schubert 5809100258SXin LI /* generic list node */ 5909100258SXin LI typedef struct any_node_tag any_node; 6009100258SXin LI struct any_node_tag { 6109100258SXin LI any_node * link; 6209100258SXin LI }; 6309100258SXin LI 6409100258SXin LI typedef DECL_FIFO_ANCHOR(any_node) any_node_fifo; 6509100258SXin LI 662b15cb3dSCy Schubert /* Structure for storing an attribute-value pair */ 672b15cb3dSCy Schubert typedef struct attr_val_tag attr_val; 682b15cb3dSCy Schubert struct attr_val_tag { 692b15cb3dSCy Schubert attr_val * link; 702b15cb3dSCy Schubert int attr; 712b15cb3dSCy Schubert int type; /* T_String, T_Integer, ... */ 722d4e511cSCy Schubert int flag; /* auxiliary flags */ 732b15cb3dSCy Schubert union val { 742d4e511cSCy Schubert double d; /* T_Double */ 752d4e511cSCy Schubert int i; /* T_Integer */ 762d4e511cSCy Schubert int_range r; /* T_Intrange */ 772d4e511cSCy Schubert char * s; /* T_String */ 782d4e511cSCy Schubert u_int u; /* T_U_int */ 792b15cb3dSCy Schubert } value; 802b15cb3dSCy Schubert }; 812b15cb3dSCy Schubert 822b15cb3dSCy Schubert typedef DECL_FIFO_ANCHOR(attr_val) attr_val_fifo; 832b15cb3dSCy Schubert 842b15cb3dSCy Schubert /* Structure for nodes on the syntax tree */ 852b15cb3dSCy Schubert typedef struct address_node_tag address_node; 862b15cb3dSCy Schubert struct address_node_tag { 872b15cb3dSCy Schubert address_node * link; 882b15cb3dSCy Schubert char * address; 892b15cb3dSCy Schubert u_short type; /* family, AF_UNSPEC (0), AF_INET[6] */ 902b15cb3dSCy Schubert }; 912b15cb3dSCy Schubert 922b15cb3dSCy Schubert typedef DECL_FIFO_ANCHOR(address_node) address_fifo; 932b15cb3dSCy Schubert 942b15cb3dSCy Schubert typedef struct int_node_tag int_node; 952b15cb3dSCy Schubert struct int_node_tag { 962b15cb3dSCy Schubert int_node * link; 972b15cb3dSCy Schubert int i; 982b15cb3dSCy Schubert }; 992b15cb3dSCy Schubert 1002b15cb3dSCy Schubert typedef DECL_FIFO_ANCHOR(int_node) int_fifo; 1012b15cb3dSCy Schubert 1022b15cb3dSCy Schubert typedef struct string_node_tag string_node; 1032b15cb3dSCy Schubert struct string_node_tag { 1042b15cb3dSCy Schubert string_node * link; 1052b15cb3dSCy Schubert char * s; 1062b15cb3dSCy Schubert }; 1072b15cb3dSCy Schubert 1082b15cb3dSCy Schubert typedef DECL_FIFO_ANCHOR(string_node) string_fifo; 1092b15cb3dSCy Schubert 1102b15cb3dSCy Schubert typedef struct restrict_node_tag restrict_node; 1112b15cb3dSCy Schubert struct restrict_node_tag { 1122b15cb3dSCy Schubert restrict_node * link; 1132b15cb3dSCy Schubert address_node * addr; 1142b15cb3dSCy Schubert address_node * mask; 1152d4e511cSCy Schubert attr_val_fifo * flag_tok_fifo; 1162b15cb3dSCy Schubert int line_no; 11709100258SXin LI short ippeerlimit; 1182d4e511cSCy Schubert short srvfuzrft; 1192b15cb3dSCy Schubert }; 1202b15cb3dSCy Schubert 1212b15cb3dSCy Schubert typedef DECL_FIFO_ANCHOR(restrict_node) restrict_fifo; 1222b15cb3dSCy Schubert 1232b15cb3dSCy Schubert typedef struct peer_node_tag peer_node; 1242b15cb3dSCy Schubert struct peer_node_tag { 1252b15cb3dSCy Schubert peer_node * link; 1262b15cb3dSCy Schubert int host_mode; 1272b15cb3dSCy Schubert address_node * addr; 1282b15cb3dSCy Schubert attr_val_fifo * peerflags; 1292b15cb3dSCy Schubert u_char minpoll; 1302b15cb3dSCy Schubert u_char maxpoll; 1312b15cb3dSCy Schubert u_int32 ttl; 1322b15cb3dSCy Schubert u_char peerversion; 1332b15cb3dSCy Schubert keyid_t peerkey; 1342b15cb3dSCy Schubert char * group; 1352b15cb3dSCy Schubert }; 1362b15cb3dSCy Schubert 1372b15cb3dSCy Schubert typedef DECL_FIFO_ANCHOR(peer_node) peer_fifo; 1382b15cb3dSCy Schubert 1392b15cb3dSCy Schubert typedef struct unpeer_node_tag unpeer_node; 1402b15cb3dSCy Schubert struct unpeer_node_tag { 1412b15cb3dSCy Schubert unpeer_node * link; 1422b15cb3dSCy Schubert associd_t assocID; 1432b15cb3dSCy Schubert address_node * addr; 1442b15cb3dSCy Schubert }; 1452b15cb3dSCy Schubert 1462b15cb3dSCy Schubert typedef DECL_FIFO_ANCHOR(unpeer_node) unpeer_fifo; 1472b15cb3dSCy Schubert 1482b15cb3dSCy Schubert typedef struct auth_node_tag auth_node; 1492b15cb3dSCy Schubert struct auth_node_tag { 1502b15cb3dSCy Schubert int control_key; 1512b15cb3dSCy Schubert int cryptosw; 1522b15cb3dSCy Schubert attr_val_fifo * crypto_cmd_list; 1532b15cb3dSCy Schubert char * keys; 1542b15cb3dSCy Schubert char * keysdir; 1552b15cb3dSCy Schubert int request_key; 1562b15cb3dSCy Schubert int revoke; 1572b15cb3dSCy Schubert attr_val_fifo * trusted_key_list; 1582b15cb3dSCy Schubert char * ntp_signd_socket; 1592b15cb3dSCy Schubert }; 1602b15cb3dSCy Schubert 1612b15cb3dSCy Schubert typedef struct filegen_node_tag filegen_node; 1622b15cb3dSCy Schubert struct filegen_node_tag { 1632b15cb3dSCy Schubert filegen_node * link; 1642b15cb3dSCy Schubert int filegen_token; 1652b15cb3dSCy Schubert attr_val_fifo * options; 1662b15cb3dSCy Schubert }; 1672b15cb3dSCy Schubert 1682b15cb3dSCy Schubert typedef DECL_FIFO_ANCHOR(filegen_node) filegen_fifo; 1692b15cb3dSCy Schubert 1702b15cb3dSCy Schubert typedef struct setvar_node_tag setvar_node; 1712b15cb3dSCy Schubert struct setvar_node_tag { 1722b15cb3dSCy Schubert setvar_node * link; 1732b15cb3dSCy Schubert char * var; 1742b15cb3dSCy Schubert char * val; 1752b15cb3dSCy Schubert int isdefault; 1762b15cb3dSCy Schubert }; 1772b15cb3dSCy Schubert 1782b15cb3dSCy Schubert typedef DECL_FIFO_ANCHOR(setvar_node) setvar_fifo; 1792b15cb3dSCy Schubert 1802b15cb3dSCy Schubert typedef struct nic_rule_node_tag nic_rule_node; 1812b15cb3dSCy Schubert struct nic_rule_node_tag { 1822b15cb3dSCy Schubert nic_rule_node * link; 1832b15cb3dSCy Schubert int match_class; 1842b15cb3dSCy Schubert char * if_name; /* or numeric address */ 1852b15cb3dSCy Schubert int action; 1862b15cb3dSCy Schubert }; 1872b15cb3dSCy Schubert 1882b15cb3dSCy Schubert typedef DECL_FIFO_ANCHOR(nic_rule_node) nic_rule_fifo; 1892b15cb3dSCy Schubert 1902b15cb3dSCy Schubert typedef struct addr_opts_node_tag addr_opts_node; 1912b15cb3dSCy Schubert struct addr_opts_node_tag { 1922b15cb3dSCy Schubert addr_opts_node *link; 1932b15cb3dSCy Schubert address_node * addr; 1942b15cb3dSCy Schubert attr_val_fifo * options; 1952b15cb3dSCy Schubert }; 1962b15cb3dSCy Schubert 1972b15cb3dSCy Schubert typedef DECL_FIFO_ANCHOR(addr_opts_node) addr_opts_fifo; 1982b15cb3dSCy Schubert 1992b15cb3dSCy Schubert typedef struct sim_node_tag sim_node; 2002b15cb3dSCy Schubert struct sim_node_tag { 2012b15cb3dSCy Schubert sim_node * link; 2022b15cb3dSCy Schubert attr_val_fifo * init_opts; 2032b15cb3dSCy Schubert server_info_fifo * servers; 2042b15cb3dSCy Schubert }; 2052b15cb3dSCy Schubert 2062b15cb3dSCy Schubert typedef DECL_FIFO_ANCHOR(sim_node) sim_fifo; 2072b15cb3dSCy Schubert 2082b15cb3dSCy Schubert /* The syntax tree */ 2092b15cb3dSCy Schubert typedef struct config_tree_tag config_tree; 2102b15cb3dSCy Schubert struct config_tree_tag { 2112b15cb3dSCy Schubert config_tree * link; 2122b15cb3dSCy Schubert 2132b15cb3dSCy Schubert attr_val source; 2142b15cb3dSCy Schubert time_t timestamp; 2152b15cb3dSCy Schubert 2162b15cb3dSCy Schubert peer_fifo * peers; 2172b15cb3dSCy Schubert unpeer_fifo * unpeers; 2182b15cb3dSCy Schubert 2192b15cb3dSCy Schubert /* Other Modes */ 2202b15cb3dSCy Schubert int broadcastclient; 2212b15cb3dSCy Schubert address_fifo * manycastserver; 2222b15cb3dSCy Schubert address_fifo * multicastclient; 2232b15cb3dSCy Schubert 2242b15cb3dSCy Schubert attr_val_fifo * orphan_cmds; /* s/b renamed tos_options */ 2252b15cb3dSCy Schubert 2262b15cb3dSCy Schubert /* Monitoring Configuration */ 2272b15cb3dSCy Schubert int_fifo * stats_list; 2282b15cb3dSCy Schubert char * stats_dir; 2292b15cb3dSCy Schubert filegen_fifo * filegen_opts; 2302b15cb3dSCy Schubert 2312b15cb3dSCy Schubert /* Access Control Configuration */ 2322b15cb3dSCy Schubert attr_val_fifo * discard_opts; 2332b15cb3dSCy Schubert attr_val_fifo * mru_opts; 2342b15cb3dSCy Schubert restrict_fifo * restrict_opts; 2352b15cb3dSCy Schubert 2362b15cb3dSCy Schubert addr_opts_fifo *fudge; 237*a466cc55SCy Schubert addr_opts_fifo *device; 2382b15cb3dSCy Schubert attr_val_fifo * rlimit; 2392b15cb3dSCy Schubert attr_val_fifo * tinker; 2402b15cb3dSCy Schubert attr_val_fifo * enable_opts; 2412b15cb3dSCy Schubert attr_val_fifo * disable_opts; 2422b15cb3dSCy Schubert 2432b15cb3dSCy Schubert auth_node auth; 2442b15cb3dSCy Schubert 2452b15cb3dSCy Schubert attr_val_fifo * logconfig; 2462b15cb3dSCy Schubert string_fifo * phone; 2472b15cb3dSCy Schubert setvar_fifo * setvar; 2482b15cb3dSCy Schubert int_fifo * ttl; 2492b15cb3dSCy Schubert addr_opts_fifo *trap; 2502b15cb3dSCy Schubert attr_val_fifo * vars; 2512b15cb3dSCy Schubert nic_rule_fifo * nic_rules; 2522b15cb3dSCy Schubert int_fifo * reset_counters; 2532d4e511cSCy Schubert attr_val_fifo * pollskewlist; 2542b15cb3dSCy Schubert 2552b15cb3dSCy Schubert sim_fifo * sim_details; 2562b15cb3dSCy Schubert int mdnstries; 2572b15cb3dSCy Schubert }; 2582b15cb3dSCy Schubert 2592b15cb3dSCy Schubert 2602b15cb3dSCy Schubert /* Structure for holding a remote configuration command */ 2612b15cb3dSCy Schubert struct REMOTE_CONFIG_INFO { 2622b15cb3dSCy Schubert char buffer[MAXLINE]; 2632b15cb3dSCy Schubert char err_msg[MAXLINE]; 2642b15cb3dSCy Schubert int pos; 2652b15cb3dSCy Schubert int err_pos; 2662b15cb3dSCy Schubert int no_errors; 2672b15cb3dSCy Schubert }; 2682b15cb3dSCy Schubert 269224ba2bdSOllivier Robert 270224ba2bdSOllivier Robert /* 2712b15cb3dSCy Schubert * context for trap_name_resolved() to call ctlsettrap() once the 2722b15cb3dSCy Schubert * name->address resolution completes. 273224ba2bdSOllivier Robert */ 2742b15cb3dSCy Schubert typedef struct settrap_parms_tag { 2752b15cb3dSCy Schubert sockaddr_u ifaddr; 2762b15cb3dSCy Schubert int ifaddr_nonnull; 2772b15cb3dSCy Schubert } settrap_parms; 278224ba2bdSOllivier Robert 279224ba2bdSOllivier Robert 2802d4e511cSCy Schubert /* 2812d4e511cSCy Schubert ** Data Minimization Items 2822d4e511cSCy Schubert */ 2832d4e511cSCy Schubert 2842d4e511cSCy Schubert /* Serverresponse fuzz reftime: stored in 'restrict' fifos */ 2852d4e511cSCy Schubert 2862d4e511cSCy Schubert 2872b15cb3dSCy Schubert /* get text from T_ tokens */ 2882b15cb3dSCy Schubert const char * token_name(int token); 289224ba2bdSOllivier Robert 2902b15cb3dSCy Schubert /* generic fifo routines for structs linked by 1st member */ 29109100258SXin LI typedef void (*fifo_deleter)(void*); 29209100258SXin LI void * destroy_gen_fifo(void *fifo, fifo_deleter func); 2932b15cb3dSCy Schubert void * append_gen_fifo(void *fifo, void *entry); 2942b15cb3dSCy Schubert void * concat_gen_fifos(void *first, void *second); 29509100258SXin LI #define DESTROY_G_FIFO(pf, func) \ 29609100258SXin LI ((pf) = destroy_gen_fifo((pf), (fifo_deleter)(func))) 2972b15cb3dSCy Schubert #define APPEND_G_FIFO(pf, pe) \ 2982b15cb3dSCy Schubert ((pf) = append_gen_fifo((pf), (pe))) 2992b15cb3dSCy Schubert #define CONCAT_G_FIFOS(first, second) \ 3002b15cb3dSCy Schubert ((first) = concat_gen_fifos((first), (second))) 3012b15cb3dSCy Schubert #define HEAD_PFIFO(pf) \ 3022b15cb3dSCy Schubert (((pf) != NULL) \ 3032b15cb3dSCy Schubert ? HEAD_FIFO(*(pf)) \ 3042b15cb3dSCy Schubert : NULL) 305224ba2bdSOllivier Robert 3062b15cb3dSCy Schubert peer_node *create_peer_node(int hmode, address_node *addr, 3072b15cb3dSCy Schubert attr_val_fifo *options); 3082b15cb3dSCy Schubert unpeer_node *create_unpeer_node(address_node *addr); 3092b15cb3dSCy Schubert address_node *create_address_node(char *addr, int type); 3102b15cb3dSCy Schubert void destroy_address_node(address_node *my_node); 3112b15cb3dSCy Schubert attr_val *create_attr_dval(int attr, double value); 3122b15cb3dSCy Schubert attr_val *create_attr_ival(int attr, int value); 3132d4e511cSCy Schubert attr_val *create_attr_rval(int attr, int first, int last); 3142b15cb3dSCy Schubert attr_val *create_attr_sval(int attr, const char *s); 3152d4e511cSCy Schubert attr_val *create_attr_uval(int attr, u_int value); 31609100258SXin LI void destroy_attr_val(attr_val *node); 3172b15cb3dSCy Schubert filegen_node *create_filegen_node(int filegen_token, 3182b15cb3dSCy Schubert attr_val_fifo *options); 3192b15cb3dSCy Schubert string_node *create_string_node(char *str); 3202b15cb3dSCy Schubert restrict_node *create_restrict_node(address_node *addr, 3212b15cb3dSCy Schubert address_node *mask, 32209100258SXin LI short ippeerlimit, 3232d4e511cSCy Schubert attr_val_fifo *flags, int line_no); 3242b15cb3dSCy Schubert int_node *create_int_node(int val); 3252b15cb3dSCy Schubert addr_opts_node *create_addr_opts_node(address_node *addr, 3262b15cb3dSCy Schubert attr_val_fifo *options); 3272b15cb3dSCy Schubert sim_node *create_sim_node(attr_val_fifo *init_opts, 3282b15cb3dSCy Schubert server_info_fifo *servers); 3292b15cb3dSCy Schubert setvar_node *create_setvar_node(char *var, char *val, int isdefault); 3302b15cb3dSCy Schubert nic_rule_node *create_nic_rule_node(int match_class, char *if_name, 3312b15cb3dSCy Schubert int action); 332224ba2bdSOllivier Robert 3332b15cb3dSCy Schubert script_info *create_sim_script_info(double duration, 3342b15cb3dSCy Schubert attr_val_fifo *script_queue); 3352b15cb3dSCy Schubert server_info *create_sim_server(address_node *addr, double server_offset, 3362b15cb3dSCy Schubert script_info_fifo *script); 3379c2daa00SOllivier Robert 3382b15cb3dSCy Schubert extern struct REMOTE_CONFIG_INFO remote_config; 3392b15cb3dSCy Schubert void config_remotely(sockaddr_u *); 340224ba2bdSOllivier Robert 3412b15cb3dSCy Schubert #ifdef SAVECONFIG 3422b15cb3dSCy Schubert int dump_config_tree(config_tree *ptree, FILE *df, int comment); 3432b15cb3dSCy Schubert int dump_all_config_trees(FILE *df, int comment); 3442b15cb3dSCy Schubert #endif 3459c2daa00SOllivier Robert 3462b15cb3dSCy Schubert #if defined(HAVE_SETRLIMIT) 3472b15cb3dSCy Schubert void ntp_rlimit(int, rlim_t, int, const char *); 3482b15cb3dSCy Schubert #endif 3499c2daa00SOllivier Robert 3502b15cb3dSCy Schubert #endif /* !defined(NTP_CONFIG_H) */ 351