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/*BOOL*/ remove; 117 int line_no; 118 int column; 119 short ippeerlimit; 120 short srvfuzrft; 121 }; 122 123 typedef DECL_FIFO_ANCHOR(restrict_node) restrict_fifo; 124 125 typedef struct peer_node_tag peer_node; 126 struct peer_node_tag { 127 peer_node * link; 128 int host_mode; 129 address_node * addr; 130 attr_val_fifo * peerflags; 131 u_char minpoll; 132 u_char maxpoll; 133 u_int32 ttl; 134 u_char peerversion; 135 keyid_t peerkey; 136 char * group; 137 }; 138 139 typedef DECL_FIFO_ANCHOR(peer_node) peer_fifo; 140 141 typedef struct unpeer_node_tag unpeer_node; 142 struct unpeer_node_tag { 143 unpeer_node * link; 144 associd_t assocID; 145 address_node * addr; 146 }; 147 148 typedef DECL_FIFO_ANCHOR(unpeer_node) unpeer_fifo; 149 150 typedef struct auth_node_tag auth_node; 151 struct auth_node_tag { 152 int control_key; 153 int cryptosw; 154 attr_val_fifo * crypto_cmd_list; 155 char * keys; 156 char * keysdir; 157 int request_key; 158 int revoke; 159 attr_val_fifo * trusted_key_list; 160 char * ntp_signd_socket; 161 }; 162 163 typedef struct filegen_node_tag filegen_node; 164 struct filegen_node_tag { 165 filegen_node * link; 166 int filegen_token; 167 attr_val_fifo * options; 168 }; 169 170 typedef DECL_FIFO_ANCHOR(filegen_node) filegen_fifo; 171 172 typedef struct setvar_node_tag setvar_node; 173 struct setvar_node_tag { 174 setvar_node * link; 175 char * var; 176 char * val; 177 int isdefault; 178 }; 179 180 typedef DECL_FIFO_ANCHOR(setvar_node) setvar_fifo; 181 182 typedef struct nic_rule_node_tag nic_rule_node; 183 struct nic_rule_node_tag { 184 nic_rule_node * link; 185 int match_class; 186 char * if_name; /* or numeric address */ 187 int action; 188 }; 189 190 typedef DECL_FIFO_ANCHOR(nic_rule_node) nic_rule_fifo; 191 192 typedef struct addr_opts_node_tag addr_opts_node; 193 struct addr_opts_node_tag { 194 addr_opts_node *link; 195 address_node * addr; 196 attr_val_fifo * options; 197 }; 198 199 typedef DECL_FIFO_ANCHOR(addr_opts_node) addr_opts_fifo; 200 201 typedef struct sim_node_tag sim_node; 202 struct sim_node_tag { 203 sim_node * link; 204 attr_val_fifo * init_opts; 205 server_info_fifo * servers; 206 }; 207 208 typedef DECL_FIFO_ANCHOR(sim_node) sim_fifo; 209 210 /* The syntax tree */ 211 typedef struct config_tree_tag config_tree; 212 struct config_tree_tag { 213 config_tree * link; 214 215 attr_val source; 216 time_t timestamp; 217 218 peer_fifo * peers; 219 unpeer_fifo * unpeers; 220 221 /* Other Modes */ 222 int broadcastclient; 223 address_fifo * manycastserver; 224 address_fifo * multicastclient; 225 226 attr_val_fifo * orphan_cmds; /* s/b renamed tos_options */ 227 228 /* Monitoring Configuration */ 229 int_fifo * stats_list; 230 char * stats_dir; 231 filegen_fifo * filegen_opts; 232 233 /* Access Control Configuration */ 234 attr_val_fifo * discard_opts; 235 attr_val_fifo * mru_opts; 236 restrict_fifo * restrict_opts; 237 238 addr_opts_fifo *fudge; 239 addr_opts_fifo *device; 240 attr_val_fifo * rlimit; 241 attr_val_fifo * tinker; 242 attr_val_fifo * enable_opts; 243 attr_val_fifo * disable_opts; 244 245 auth_node auth; 246 247 attr_val_fifo * logconfig; 248 string_fifo * phone; 249 setvar_fifo * setvar; 250 int_fifo * ttl; 251 addr_opts_fifo *trap; 252 attr_val_fifo * vars; 253 nic_rule_fifo * nic_rules; 254 int_fifo * reset_counters; 255 attr_val_fifo * pollskewlist; 256 257 sim_fifo * sim_details; 258 int mdnstries; 259 }; 260 261 262 /* Structure for holding a remote configuration command */ 263 struct REMOTE_CONFIG_INFO { 264 char buffer[MAXLINE]; 265 char err_msg[MAXLINE]; 266 int pos; 267 int err_pos; 268 int no_errors; 269 }; 270 271 272 /* 273 * context for trap_name_resolved() to call ctlsettrap() once the 274 * name->address resolution completes. 275 */ 276 typedef struct settrap_parms_tag { 277 sockaddr_u ifaddr; 278 int ifaddr_nonnull; 279 } settrap_parms; 280 281 282 /* 283 ** Data Minimization Items 284 */ 285 286 /* Serverresponse fuzz reftime: stored in 'restrict' fifos */ 287 288 289 /* get text from T_ tokens */ 290 const char * token_name(int token); 291 292 /* generic fifo routines for structs linked by 1st member */ 293 typedef void (*fifo_deleter)(void*); 294 void * destroy_gen_fifo(void *fifo, fifo_deleter func); 295 void * append_gen_fifo(void *fifo, void *entry); 296 void * concat_gen_fifos(void *first, void *second); 297 #define DESTROY_G_FIFO(pf, func) \ 298 ((pf) = destroy_gen_fifo((pf), (fifo_deleter)(func))) 299 #define APPEND_G_FIFO(pf, pe) \ 300 ((pf) = append_gen_fifo((pf), (pe))) 301 #define CONCAT_G_FIFOS(first, second) \ 302 ((first) = concat_gen_fifos((first), (second))) 303 #define HEAD_PFIFO(pf) \ 304 (((pf) != NULL) \ 305 ? HEAD_FIFO(*(pf)) \ 306 : NULL) 307 308 peer_node *create_peer_node(int hmode, address_node *addr, 309 attr_val_fifo *options); 310 unpeer_node *create_unpeer_node(address_node *addr); 311 address_node *create_address_node(char *addr, int type); 312 void destroy_address_node(address_node *my_node); 313 attr_val *create_attr_dval(int attr, double value); 314 attr_val *create_attr_ival(int attr, int value); 315 attr_val *create_attr_rval(int attr, int first, int last); 316 attr_val *create_attr_sval(int attr, const char *s); 317 attr_val *create_attr_uval(int attr, u_int value); 318 void destroy_attr_val(attr_val *node); 319 filegen_node *create_filegen_node(int filegen_token, 320 attr_val_fifo *options); 321 string_node *create_string_node(char *str); 322 restrict_node *create_restrict_node(address_node * addr, 323 address_node * mask, 324 short ippeerlimit, 325 attr_val_fifo * flag_tok_fifo, 326 int/*BOOL*/ remove, 327 int nline, 328 int ncol); 329 int_node *create_int_node(int val); 330 addr_opts_node *create_addr_opts_node(address_node *addr, 331 attr_val_fifo *options); 332 sim_node *create_sim_node(attr_val_fifo *init_opts, 333 server_info_fifo *servers); 334 setvar_node *create_setvar_node(char *var, char *val, int isdefault); 335 nic_rule_node *create_nic_rule_node(int match_class, char *if_name, 336 int action); 337 338 script_info *create_sim_script_info(double duration, 339 attr_val_fifo *script_queue); 340 server_info *create_sim_server(address_node *addr, double server_offset, 341 script_info_fifo *script); 342 343 extern struct REMOTE_CONFIG_INFO remote_config; 344 void config_remotely(sockaddr_u *); 345 346 #ifdef SAVECONFIG 347 int dump_config_tree(config_tree *ptree, FILE *df, int comment); 348 int dump_all_config_trees(FILE *df, int comment); 349 #endif 350 351 #if defined(HAVE_SETRLIMIT) 352 void ntp_rlimit(int, rlim_t, int, const char *); 353 #endif 354 355 #endif /* !defined(NTP_CONFIG_H) */ 356