1 #ifndef NTP_CONFIG_H 2 #define NTP_CONFIG_H 3 4 #ifdef HAVE_SYS_RESOURCE_H 5 # include <sys/resource.h> 6 #endif /* HAVE_SYS_RESOURCE_H */ 7 8 #include "ntp_machine.h" 9 #include "ntp_psl.h" 10 #include "ntpsim.h" 11 12 13 /* 14 * Configuration file name 15 */ 16 #ifndef CONFIG_FILE 17 # ifndef SYS_WINNT 18 # define CONFIG_FILE "/etc/ntp.conf" 19 # else /* SYS_WINNT */ 20 # define CONFIG_FILE "%windir%\\system32\\drivers\\etc\\ntp.conf" 21 # define ALT_CONFIG_FILE "%windir%\\ntp.conf" 22 # define NTP_KEYSDIR "%windir%\\system32\\drivers\\etc" 23 # endif /* SYS_WINNT */ 24 #endif /* not CONFIG_FILE */ 25 26 27 /* 28 * We keep config trees around for possible saveconfig use. When 29 * built with configure --disable-saveconfig, and when built with 30 * debugging enabled, include the free_config_*() routines. In the 31 * DEBUG case, they are used in an atexit() cleanup routine to make 32 * postmortem leak check reports more interesting. 33 */ 34 #if !defined(FREE_CFG_T) && (!defined(SAVECONFIG) || defined(DEBUG)) 35 #define FREE_CFG_T 36 #endif 37 38 /* Limits */ 39 #define MAXLINE 1024 40 41 /* Configuration sources */ 42 43 #define CONF_SOURCE_FILE 0 44 #define CONF_SOURCE_NTPQ 1 45 46 /* list of servers from command line for config_peers() */ 47 extern int cmdline_server_count; 48 extern char ** cmdline_servers; 49 50 /* set to zero if we're not locking memory */ 51 extern int cur_memlock; 52 53 typedef struct int_range_tag { 54 int first; 55 int last; 56 } int_range; 57 58 /* generic list node */ 59 typedef struct any_node_tag any_node; 60 struct any_node_tag { 61 any_node * link; 62 }; 63 64 typedef DECL_FIFO_ANCHOR(any_node) any_node_fifo; 65 66 /* Structure for storing an attribute-value pair */ 67 typedef struct attr_val_tag attr_val; 68 struct attr_val_tag { 69 attr_val * link; 70 int attr; 71 int type; /* T_String, T_Integer, ... */ 72 int flag; /* auxiliary flags */ 73 union val { 74 double d; /* T_Double */ 75 int i; /* T_Integer */ 76 int_range r; /* T_Intrange */ 77 char * s; /* T_String */ 78 u_int u; /* T_U_int */ 79 } value; 80 }; 81 82 typedef DECL_FIFO_ANCHOR(attr_val) attr_val_fifo; 83 84 /* Structure for nodes on the syntax tree */ 85 typedef struct address_node_tag address_node; 86 struct address_node_tag { 87 address_node * link; 88 char * address; 89 u_short type; /* family, AF_UNSPEC (0), AF_INET[6] */ 90 }; 91 92 typedef DECL_FIFO_ANCHOR(address_node) address_fifo; 93 94 typedef struct int_node_tag int_node; 95 struct int_node_tag { 96 int_node * link; 97 int i; 98 }; 99 100 typedef DECL_FIFO_ANCHOR(int_node) int_fifo; 101 102 typedef struct string_node_tag string_node; 103 struct string_node_tag { 104 string_node * link; 105 char * s; 106 }; 107 108 typedef DECL_FIFO_ANCHOR(string_node) string_fifo; 109 110 typedef struct restrict_node_tag restrict_node; 111 struct restrict_node_tag { 112 restrict_node * link; 113 address_node * addr; 114 address_node * mask; 115 attr_val_fifo * flag_tok_fifo; 116 int line_no; 117 short ippeerlimit; 118 short srvfuzrft; 119 }; 120 121 typedef DECL_FIFO_ANCHOR(restrict_node) restrict_fifo; 122 123 typedef struct peer_node_tag peer_node; 124 struct peer_node_tag { 125 peer_node * link; 126 int host_mode; 127 address_node * addr; 128 attr_val_fifo * peerflags; 129 u_char minpoll; 130 u_char maxpoll; 131 u_int32 ttl; 132 u_char peerversion; 133 keyid_t peerkey; 134 char * group; 135 }; 136 137 typedef DECL_FIFO_ANCHOR(peer_node) peer_fifo; 138 139 typedef struct unpeer_node_tag unpeer_node; 140 struct unpeer_node_tag { 141 unpeer_node * link; 142 associd_t assocID; 143 address_node * addr; 144 }; 145 146 typedef DECL_FIFO_ANCHOR(unpeer_node) unpeer_fifo; 147 148 typedef struct auth_node_tag auth_node; 149 struct auth_node_tag { 150 int control_key; 151 int cryptosw; 152 attr_val_fifo * crypto_cmd_list; 153 char * keys; 154 char * keysdir; 155 int request_key; 156 int revoke; 157 attr_val_fifo * trusted_key_list; 158 char * ntp_signd_socket; 159 }; 160 161 typedef struct filegen_node_tag filegen_node; 162 struct filegen_node_tag { 163 filegen_node * link; 164 int filegen_token; 165 attr_val_fifo * options; 166 }; 167 168 typedef DECL_FIFO_ANCHOR(filegen_node) filegen_fifo; 169 170 typedef struct setvar_node_tag setvar_node; 171 struct setvar_node_tag { 172 setvar_node * link; 173 char * var; 174 char * val; 175 int isdefault; 176 }; 177 178 typedef DECL_FIFO_ANCHOR(setvar_node) setvar_fifo; 179 180 typedef struct nic_rule_node_tag nic_rule_node; 181 struct nic_rule_node_tag { 182 nic_rule_node * link; 183 int match_class; 184 char * if_name; /* or numeric address */ 185 int action; 186 }; 187 188 typedef DECL_FIFO_ANCHOR(nic_rule_node) nic_rule_fifo; 189 190 typedef struct addr_opts_node_tag addr_opts_node; 191 struct addr_opts_node_tag { 192 addr_opts_node *link; 193 address_node * addr; 194 attr_val_fifo * options; 195 }; 196 197 typedef DECL_FIFO_ANCHOR(addr_opts_node) addr_opts_fifo; 198 199 typedef struct sim_node_tag sim_node; 200 struct sim_node_tag { 201 sim_node * link; 202 attr_val_fifo * init_opts; 203 server_info_fifo * servers; 204 }; 205 206 typedef DECL_FIFO_ANCHOR(sim_node) sim_fifo; 207 208 /* The syntax tree */ 209 typedef struct config_tree_tag config_tree; 210 struct config_tree_tag { 211 config_tree * link; 212 213 attr_val source; 214 time_t timestamp; 215 216 peer_fifo * peers; 217 unpeer_fifo * unpeers; 218 219 /* Other Modes */ 220 int broadcastclient; 221 address_fifo * manycastserver; 222 address_fifo * multicastclient; 223 224 attr_val_fifo * orphan_cmds; /* s/b renamed tos_options */ 225 226 /* Monitoring Configuration */ 227 int_fifo * stats_list; 228 char * stats_dir; 229 filegen_fifo * filegen_opts; 230 231 /* Access Control Configuration */ 232 attr_val_fifo * discard_opts; 233 attr_val_fifo * mru_opts; 234 restrict_fifo * restrict_opts; 235 236 addr_opts_fifo *fudge; 237 addr_opts_fifo *device; 238 attr_val_fifo * rlimit; 239 attr_val_fifo * tinker; 240 attr_val_fifo * enable_opts; 241 attr_val_fifo * disable_opts; 242 243 auth_node auth; 244 245 attr_val_fifo * logconfig; 246 string_fifo * phone; 247 setvar_fifo * setvar; 248 int_fifo * ttl; 249 addr_opts_fifo *trap; 250 attr_val_fifo * vars; 251 nic_rule_fifo * nic_rules; 252 int_fifo * reset_counters; 253 attr_val_fifo * pollskewlist; 254 255 sim_fifo * sim_details; 256 int mdnstries; 257 }; 258 259 260 /* Structure for holding a remote configuration command */ 261 struct REMOTE_CONFIG_INFO { 262 char buffer[MAXLINE]; 263 char err_msg[MAXLINE]; 264 int pos; 265 int err_pos; 266 int no_errors; 267 }; 268 269 270 /* 271 * context for trap_name_resolved() to call ctlsettrap() once the 272 * name->address resolution completes. 273 */ 274 typedef struct settrap_parms_tag { 275 sockaddr_u ifaddr; 276 int ifaddr_nonnull; 277 } settrap_parms; 278 279 280 /* 281 ** Data Minimization Items 282 */ 283 284 /* Serverresponse fuzz reftime: stored in 'restrict' fifos */ 285 286 287 /* get text from T_ tokens */ 288 const char * token_name(int token); 289 290 /* generic fifo routines for structs linked by 1st member */ 291 typedef void (*fifo_deleter)(void*); 292 void * destroy_gen_fifo(void *fifo, fifo_deleter func); 293 void * append_gen_fifo(void *fifo, void *entry); 294 void * concat_gen_fifos(void *first, void *second); 295 #define DESTROY_G_FIFO(pf, func) \ 296 ((pf) = destroy_gen_fifo((pf), (fifo_deleter)(func))) 297 #define APPEND_G_FIFO(pf, pe) \ 298 ((pf) = append_gen_fifo((pf), (pe))) 299 #define CONCAT_G_FIFOS(first, second) \ 300 ((first) = concat_gen_fifos((first), (second))) 301 #define HEAD_PFIFO(pf) \ 302 (((pf) != NULL) \ 303 ? HEAD_FIFO(*(pf)) \ 304 : NULL) 305 306 peer_node *create_peer_node(int hmode, address_node *addr, 307 attr_val_fifo *options); 308 unpeer_node *create_unpeer_node(address_node *addr); 309 address_node *create_address_node(char *addr, int type); 310 void destroy_address_node(address_node *my_node); 311 attr_val *create_attr_dval(int attr, double value); 312 attr_val *create_attr_ival(int attr, int value); 313 attr_val *create_attr_rval(int attr, int first, int last); 314 attr_val *create_attr_sval(int attr, const char *s); 315 attr_val *create_attr_uval(int attr, u_int value); 316 void destroy_attr_val(attr_val *node); 317 filegen_node *create_filegen_node(int filegen_token, 318 attr_val_fifo *options); 319 string_node *create_string_node(char *str); 320 restrict_node *create_restrict_node(address_node *addr, 321 address_node *mask, 322 short ippeerlimit, 323 attr_val_fifo *flags, int line_no); 324 int_node *create_int_node(int val); 325 addr_opts_node *create_addr_opts_node(address_node *addr, 326 attr_val_fifo *options); 327 sim_node *create_sim_node(attr_val_fifo *init_opts, 328 server_info_fifo *servers); 329 setvar_node *create_setvar_node(char *var, char *val, int isdefault); 330 nic_rule_node *create_nic_rule_node(int match_class, char *if_name, 331 int action); 332 333 script_info *create_sim_script_info(double duration, 334 attr_val_fifo *script_queue); 335 server_info *create_sim_server(address_node *addr, double server_offset, 336 script_info_fifo *script); 337 338 extern struct REMOTE_CONFIG_INFO remote_config; 339 void config_remotely(sockaddr_u *); 340 341 #ifdef SAVECONFIG 342 int dump_config_tree(config_tree *ptree, FILE *df, int comment); 343 int dump_all_config_trees(FILE *df, int comment); 344 #endif 345 346 #if defined(HAVE_SETRLIMIT) 347 void ntp_rlimit(int, rlim_t, int, const char *); 348 #endif 349 350 #endif /* !defined(NTP_CONFIG_H) */ 351