2 #if !defined(lint) && !defined(SABER)
3 static char rcsid[] = "$Id: ns_parser.y,v 8.11 1997/12/04 07:03:05 halley Exp $";
7 * Copyright (c) 1996, 1997 by Internet Software Consortium.
9 * Permission to use, copy, modify, and distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies.
13 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
14 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
16 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
17 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
18 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
19 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
23 /* Global C stuff goes here. */
25 #include "port_before.h"
27 #include <sys/types.h>
29 #include <netinet/in.h>
30 #include <arpa/nameser.h>
31 #include <arpa/inet.h>
41 #include <isc/eventlib.h>
42 #include <isc/logging.h>
44 #include "port_after.h"
47 #include "ns_parseutil.h"
50 #define SYM_ZONE 0x010000
51 #define SYM_SERVER 0x020000
52 #define SYM_KEY 0x030000
53 #define SYM_ACL 0x040000
54 #define SYM_CHANNEL 0x050000
55 #define SYM_PORT 0x060000
57 #define SYMBOL_TABLE_SIZE 29989 /* should always be prime */
58 static symbol_table symtab;
60 #define AUTH_TABLE_SIZE 397 /* should always be prime */
61 static symbol_table authtab = NULL;
63 static zone_config current_zone;
66 static options current_options;
67 static int seen_options;
69 static topology_config current_topology;
70 static int seen_topology;
72 static server_config current_server;
73 static int seen_server;
75 static char *current_algorithm;
76 static char *current_secret;
78 static log_config current_logging;
79 static int current_category;
81 static int chan_level;
82 static u_int chan_flags;
83 static int chan_facility;
84 static char *chan_name;
85 static int chan_versions;
86 static u_long chan_max_size;
88 static log_channel lookup_channel(char *);
89 static void define_channel(char *, log_channel);
90 static char *canonical_name(char *);
102 struct in_addr ip_addr;
103 ip_match_element ime;
106 enum axfr_format axfr_fmt;
109 /* Lexical analyzer return values. */
111 %token <ip_addr> L_IPADDR
112 %token <num> L_NUMBER
114 %token <cp> L_QSTRING
117 /* Include support */
120 /* Items related to the "options" statement: */
122 %token T_DIRECTORY T_PIDFILE T_NAMED_XFER
123 %token T_DUMP_FILE T_STATS_FILE T_MEMSTATS_FILE
124 %token T_FAKE_IQUERY T_RECURSION T_FETCH_GLUE
125 %token T_QUERY_SOURCE T_LISTEN_ON T_PORT T_ADDRESS
126 %type <us_int> in_port
127 %type <us_int> maybe_port
128 %type <us_int> maybe_wild_port
129 %type <ip_addr> maybe_wild_addr
130 %token T_DATASIZE T_STACKSIZE T_CORESIZE
131 %token T_DEFAULT T_UNLIMITED
133 %token T_HOSTSTATS T_DEALLOC_ON_EXIT
134 %token T_TRANSFERS_IN T_TRANSFERS_OUT T_TRANSFERS_PER_NS
135 %token T_TRANSFER_FORMAT T_MAX_TRANSFER_TIME_IN
136 %token T_ONE_ANSWER T_MANY_ANSWERS
137 %type <axfr_fmt> transfer_format
138 %token T_NOTIFY T_AUTH_NXDOMAIN T_MULTIPLE_CNAMES
139 %token T_CLEAN_INTERVAL T_INTERFACE_INTERVAL T_STATS_INTERVAL
141 /* Items used for the "logging" statement: */
142 %token T_LOGGING T_CATEGORY T_CHANNEL T_SEVERITY T_DYNAMIC
143 %token T_FILE T_VERSIONS T_SIZE
144 %token T_SYSLOG T_DEBUG T_NULL_OUTPUT
145 %token T_PRINT_TIME T_PRINT_CATEGORY T_PRINT_SEVERITY
146 %type <s_int> category
147 %type <cp> category_name channel_name facility_name
148 %type <s_int> maybe_syslog_facility
150 /* Items used for the "topology" statement: */
154 %type <ime> address_match_simple address_match_element address_name
155 %type <iml> address_match_list
157 /* Items used for "server" statements: */
164 /* Items used for "zone" statements: */
166 %type <num> optional_class
167 %type <s_int> zone_type
168 %token T_IN T_CHAOS T_HESIOD
170 %token T_MASTER T_SLAVE T_STUB T_RESPONSE
172 %token T_MASTERS T_TRANSFER_SOURCE
175 /* Items used for access control lists and "allow" clauses: */
177 %token T_ALLOW_UPDATE T_ALLOW_QUERY T_ALLOW_TRANSFER
179 /* Items related to the "key" statement: */
180 %token T_SEC_KEY T_ALGID T_SECRET
182 %type <cp> algorithm_id secret
184 /* Items used for "size_spec" clauses: */
185 %type <ul_int> size_spec
187 /* Items used for a "check-names" clause: */
189 %type <s_int> check_names_type
190 %type <s_int> check_names_opt
191 %token T_WARN T_FAIL T_IGNORE
193 /* Items used for "forward" clauses: */
194 %token T_FORWARD T_FORWARDERS
195 %token T_ONLY T_FIRST T_IF_NO_ANSWER T_IF_NO_DOMAIN
197 /* Items used for yes/no responses: */
198 %type <num> yea_or_nay
199 %token T_YES T_TRUE T_NO T_FALSE
201 /* Miscellaneous items (used in several places): */
202 %type <cp> any_string
205 config_file: statement_list
211 statement_list: statement
212 | statement_list statement
215 statement: include_stmt
224 | error L_END_INCLUDE
227 include_stmt: T_INCLUDE L_QSTRING L_EOS { lexer_begin_file($2, NULL); }
234 options_stmt: T_OPTIONS
237 parser_error(0, "cannot redefine options");
238 current_options = new_options();
243 set_options(current_options, 0);
245 free_options(current_options);
246 current_options = NULL;
251 options: option L_EOS
252 | options option L_EOS
256 | T_DIRECTORY L_QSTRING
258 if (current_options->directory != NULL)
259 freestr(current_options->directory);
260 current_options->directory = $2;
262 | T_NAMED_XFER L_QSTRING
264 if (current_options->named_xfer != NULL)
265 freestr(current_options->named_xfer);
266 current_options->named_xfer = $2;
268 | T_PIDFILE L_QSTRING
270 if (current_options->pid_filename != NULL)
271 freestr(current_options->pid_filename);
272 current_options->pid_filename = $2;
274 | T_STATS_FILE L_QSTRING
276 if (current_options->stats_filename != NULL)
277 freestr(current_options->stats_filename);
278 current_options->stats_filename = $2;
280 | T_MEMSTATS_FILE L_QSTRING
282 if (current_options->memstats_filename != NULL)
283 freestr(current_options->memstats_filename);
284 current_options->memstats_filename = $2;
286 | T_DUMP_FILE L_QSTRING
288 if (current_options->dump_filename != NULL)
289 freestr(current_options->dump_filename);
290 current_options->dump_filename = $2;
292 | T_FAKE_IQUERY yea_or_nay
294 set_boolean_option(current_options, OPTION_FAKE_IQUERY, $2);
296 | T_RECURSION yea_or_nay
298 set_boolean_option(current_options, OPTION_NORECURSE, !$2);
300 | T_FETCH_GLUE yea_or_nay
302 set_boolean_option(current_options, OPTION_NOFETCHGLUE, !$2);
304 | T_NOTIFY yea_or_nay
306 set_boolean_option(current_options, OPTION_NONOTIFY, !$2);
308 | T_HOSTSTATS yea_or_nay
310 set_boolean_option(current_options, OPTION_HOSTSTATS, $2);
312 | T_DEALLOC_ON_EXIT yea_or_nay
314 set_boolean_option(current_options, OPTION_DEALLOC_ON_EXIT,
317 | T_AUTH_NXDOMAIN yea_or_nay
319 set_boolean_option(current_options, OPTION_NONAUTH_NXDOMAIN,
322 | T_MULTIPLE_CNAMES yea_or_nay
324 set_boolean_option(current_options, OPTION_MULTIPLE_CNAMES,
327 | T_CHECK_NAMES check_names_type check_names_opt
329 current_options->check_names[$2] = $3;
331 | T_LISTEN_ON maybe_port '{' address_match_list '}'
333 char port_string[10];
336 (void)sprintf(port_string, "%u", $2);
337 if (lookup_symbol(symtab, port_string, SYM_PORT, NULL))
339 "cannot redefine listen-on for port %u",
342 add_listen_on(current_options, $2, $4);
343 value.pointer = NULL;
344 define_symbol(symtab, savestr(port_string, 1),
345 SYM_PORT, value, SYMBOL_FREE_KEY);
349 | T_FORWARD forward_opt
352 if (current_options->fwdtab) {
353 free_forwarders(current_options->fwdtab);
354 current_options->fwdtab = NULL;
357 '{' opt_forwarders_list '}'
358 | T_QUERY_SOURCE query_source
359 | T_ALLOW_QUERY '{' address_match_list '}'
361 if (current_options->query_acl)
362 free_ip_match_list(current_options->query_acl);
363 current_options->query_acl = $3;
365 | T_ALLOW_TRANSFER '{' address_match_list '}'
367 if (current_options->transfer_acl)
368 free_ip_match_list(current_options->transfer_acl);
369 current_options->transfer_acl = $3;
371 | T_TOPOLOGY '{' address_match_list '}'
373 if (current_options->topology)
374 free_ip_match_list(current_options->topology);
375 current_options->topology = $3;
379 /* To get around the $$ = $1 default rule. */
382 | T_TRANSFER_FORMAT transfer_format
384 current_options->transfer_format = $2;
386 | T_MAX_TRANSFER_TIME_IN L_NUMBER
388 current_options->max_transfer_time_in = $2 * 60;
390 | T_CLEAN_INTERVAL L_NUMBER
392 current_options->clean_interval = $2 * 60;
394 | T_INTERFACE_INTERVAL L_NUMBER
396 current_options->interface_interval = $2 * 60;
398 | T_STATS_INTERVAL L_NUMBER
400 current_options->stats_interval = $2 * 60;
405 transfer_format: T_ONE_ANSWER
407 $$ = axfr_one_answer;
411 $$ = axfr_many_answers;
415 maybe_wild_addr: L_IPADDR { $$ = $1; }
416 | '*' { $$.s_addr = htonl(INADDR_ANY); }
419 maybe_wild_port: in_port { $$ = $1; }
420 | '*' { $$ = htons(0); }
423 query_source_address: T_ADDRESS maybe_wild_addr
425 current_options->query_source.sin_addr = $2;
429 query_source_port: T_PORT maybe_wild_port
431 current_options->query_source.sin_port = $2;
435 query_source: query_source_address
437 | query_source_address query_source_port
438 | query_source_port query_source_address
441 maybe_port: /* nothing */ { $$ = htons(NS_DEFAULTPORT); }
442 | T_PORT in_port { $$ = $2; }
463 if ($1 == 1 || $1 == 0) {
467 "number should be 0 or 1; assuming 1");
473 check_names_type: T_MASTER
479 $$ = secondary_trans;
487 check_names_opt: T_WARN
503 set_boolean_option(current_options, OPTION_FORWARD_ONLY, 1);
507 set_boolean_option(current_options, OPTION_FORWARD_ONLY, 0);
511 parser_warning(0, "forward if-no-answer is unimplemented");
515 parser_warning(0, "forward if-no-domain is unimplemented");
519 size_clause: T_DATASIZE size_spec
521 current_options->data_size = $2;
523 | T_STACKSIZE size_spec
525 current_options->stack_size = $2;
527 | T_CORESIZE size_spec
529 current_options->core_size = $2;
533 current_options->files = $2;
537 size_spec: any_string
541 if (unit_to_ulong($1, &result))
544 parser_error(0, "invalid unit string '%s'", $1);
545 /* 0 means "use default" */
564 transfer_clause: T_TRANSFERS_IN L_NUMBER
566 current_options->transfers_in = (u_long) $2;
568 | T_TRANSFERS_OUT L_NUMBER
570 current_options->transfers_out = (u_long) $2;
572 | T_TRANSFERS_PER_NS L_NUMBER
574 current_options->transfers_per_ns = (u_long) $2;
578 opt_forwarders_list: /* nothing */
579 | forwarders_in_addr_list
582 forwarders_in_addr_list: forwarders_in_addr L_EOS
586 | forwarders_in_addr_list forwarders_in_addr L_EOS
592 forwarders_in_addr: L_IPADDR
594 add_forwarder(current_options, $1);
602 logging_stmt: T_LOGGING
604 current_logging = begin_logging();
606 '{' logging_opts_list '}'
608 end_logging(current_logging, 1);
609 current_logging = NULL;
613 logging_opts_list: logging_opt L_EOS
614 | logging_opts_list logging_opt L_EOS
618 logging_opt: T_CATEGORY category
620 current_category = $2;
623 | T_CHANNEL channel_name
625 chan_type = log_null;
627 chan_level = log_info;
629 '{' channel_opt_list '}'
631 log_channel current_channel = NULL;
633 if (lookup_channel($2) != NULL) {
634 parser_error(0, "can't redefine channel '%s'", $2);
640 log_new_file_channel(chan_flags,
650 log_new_syslog_channel(chan_flags,
655 current_channel = log_new_null_channel();
658 ns_panic(ns_log_parser, 1,
659 "unknown channel type: %d",
662 if (current_channel == NULL)
663 ns_panic(ns_log_parser, 0,
664 "couldn't create channel");
665 define_channel($2, current_channel);
670 channel_severity: any_string
674 if (lookup_symbol(constants, $1, SYM_LOGGING, &value)) {
675 chan_level = value.integer;
677 parser_error(0, "unknown severity '%s'", $1);
678 chan_level = log_debug(99);
684 chan_level = log_debug(1);
693 chan_flags |= LOG_USE_CONTEXT_LEVEL|LOG_REQUIRE_DEBUG;
697 version_modifier: T_VERSIONS L_NUMBER
700 chan_flags |= LOG_TRUNCATE;
702 | T_VERSIONS T_UNLIMITED
704 chan_versions = LOG_MAX_VERSIONS;
705 chan_flags |= LOG_TRUNCATE;
709 size_modifier: T_SIZE size_spec
715 maybe_file_modifiers: /* nothing */
718 chan_max_size = ULONG_MAX;
722 chan_max_size = ULONG_MAX;
728 | version_modifier size_modifier
729 | size_modifier version_modifier
732 channel_file: T_FILE L_QSTRING maybe_file_modifiers
734 chan_flags |= LOG_CLOSE_STREAM;
735 chan_type = log_file;
741 facility_name: any_string { $$ = $1; }
742 | T_SYSLOG { $$ = savestr("syslog", 1); }
745 maybe_syslog_facility: /* nothing */ { $$ = LOG_DAEMON; }
750 if (lookup_symbol(constants, $1, SYM_SYSLOG, &value)) {
753 parser_error(0, "unknown facility '%s'", $1);
760 channel_syslog: T_SYSLOG maybe_syslog_facility
762 chan_type = log_syslog;
767 channel_opt: channel_file { /* nothing to do */ }
768 | channel_syslog { /* nothing to do */ }
771 chan_type = log_null;
773 | T_SEVERITY channel_severity { /* nothing to do */ }
774 | T_PRINT_TIME yea_or_nay
777 chan_flags |= LOG_TIMESTAMP;
779 chan_flags &= ~LOG_TIMESTAMP;
781 | T_PRINT_CATEGORY yea_or_nay
784 chan_flags |= LOG_PRINT_CATEGORY;
786 chan_flags &= ~LOG_PRINT_CATEGORY;
788 | T_PRINT_SEVERITY yea_or_nay
791 chan_flags |= LOG_PRINT_LEVEL;
793 chan_flags &= ~LOG_PRINT_LEVEL;
797 channel_opt_list: channel_opt L_EOS
798 | channel_opt_list channel_opt L_EOS
802 channel_name: any_string
803 | T_NULL_OUTPUT { $$ = savestr("null", 1); }
806 channel: channel_name
811 if (current_category >= 0) {
812 channel = lookup_channel($1);
813 if (channel != NULL) {
814 add_log_channel(current_logging,
815 current_category, channel);
817 parser_error(0, "unknown channel '%s'", $1);
823 channel_list: channel L_EOS
824 | channel_list channel L_EOS
828 category_name: any_string
829 | T_DEFAULT { $$ = savestr("default", 1); }
830 | T_NOTIFY { $$ = savestr("notify", 1); }
833 category: category_name
837 if (lookup_symbol(constants, $1, SYM_CATEGORY, &value))
840 parser_error(0, "invalid logging category '%s'",
852 server_stmt: T_SERVER L_IPADDR
857 ip_printable = inet_ntoa($2);
858 value.pointer = NULL;
859 if (lookup_symbol(symtab, ip_printable, SYM_SERVER, NULL))
864 parser_error(0, "cannot redefine server '%s'",
867 define_symbol(symtab, savestr(ip_printable, 1),
870 current_server = begin_server($2);
872 '{' server_info_list '}'
874 end_server(current_server, !seen_server);
878 server_info_list: server_info L_EOS
879 | server_info_list server_info L_EOS
882 server_info: T_BOGUS yea_or_nay
884 set_server_option(current_server, SERVER_INFO_BOGUS, $2);
886 | T_TRANSFERS L_NUMBER
888 set_server_transfers(current_server, (int)$2);
890 | T_TRANSFER_FORMAT transfer_format
892 set_server_transfer_format(current_server, $2);
894 | T_KEYS '{' key_list '}'
902 address_match_list: address_match_element L_EOS
906 iml = new_ip_match_list();
908 add_to_ip_match_list(iml, $1);
911 | address_match_list address_match_element L_EOS
914 add_to_ip_match_list($1, $2);
919 address_match_element: address_match_simple
920 | '!' address_match_simple
928 address_match_simple: L_IPADDR
930 $$ = new_ip_match_pattern($1, 32);
932 | L_IPADDR '/' L_NUMBER
934 if ($3 < 0 || $3 > 32) {
935 parser_error(0, "mask bits out of range; skipping");
938 $$ = new_ip_match_pattern($1, $3);
941 "address/mask mismatch; skipping");
944 | L_NUMBER '/' L_NUMBER
949 parser_error(0, "address out of range; skipping");
952 if ($3 < 0 || $3 > 32) {
954 "mask bits out of range; skipping");
957 ia.s_addr = htonl(($1 & 0xff) << 24);
958 $$ = new_ip_match_pattern(ia, $3);
961 "address/mask mismatch; skipping");
966 | '{' address_match_list '}'
971 * We want to be able to clean up this iml later so
972 * we give it a name and treat it like any other acl.
974 sprintf(name, "__internal_%p", $2);
975 define_acl(savestr(name, 1), $2);
976 $$ = new_ip_match_indirect($2);
980 address_name: any_string
984 iml = lookup_acl($1);
986 parser_error(0, "unknown ACL '%s'", $1);
989 $$ = new_ip_match_indirect(iml);
1002 ki = lookup_key($1);
1004 parser_error(0, "unknown key '%s'", $1);
1012 key_list_element: key_ref
1015 parser_error(0, "empty key not added to server list ");
1017 add_server_key_info(current_server, $1);
1021 key_list: key_list_element L_EOS
1022 | key_list key_list_element L_EOS
1028 current_algorithm = NULL;
1029 current_secret = NULL;
1031 any_string '{' key_definition '}'
1035 if (lookup_key($3) != NULL) {
1036 parser_error(0, "can't redefine key '%s'", $3);
1039 if (current_algorithm == NULL ||
1040 current_secret == NULL)
1041 parser_error(0, "skipping bad key '%s'", $3);
1043 ki = new_key_info($3, current_algorithm,
1051 key_definition: algorithm_id secret
1053 current_algorithm = $1;
1054 current_secret = $2;
1056 | secret algorithm_id
1058 current_algorithm = $2;
1059 current_secret = $1;
1063 current_algorithm = NULL;
1064 current_secret = NULL;
1068 algorithm_id: T_ALGID any_string L_EOS { $$ = $2; }
1071 secret: T_SECRET any_string L_EOS { $$ = $2; }
1078 acl_stmt: T_ACL any_string '{' address_match_list '}'
1080 if (lookup_acl($2) != NULL) {
1081 parser_error(0, "can't redefine ACL '%s'", $2);
1092 zone_stmt: T_ZONE L_QSTRING optional_class
1100 "no options statement before first zone; using previous/default");
1101 sym_type = SYM_ZONE | ($3 & 0xffff);
1102 value.pointer = NULL;
1103 zone_name = canonical_name($2);
1104 if (zone_name == NULL) {
1105 parser_error(0, "can't make zone name '%s' canonical",
1108 zone_name = savestr("__bad_zone__", 1);
1110 seen_zone = lookup_symbol(symtab, zone_name, sym_type,
1114 "cannot redefine zone '%s' class %d",
1117 define_symbol(symtab, zone_name, sym_type,
1121 current_zone = begin_zone(zone_name, $3);
1123 optional_zone_options_list
1124 { end_zone(current_zone, !seen_zone); }
1127 optional_zone_options_list: /* Empty */
1128 | '{' zone_option_list '}'
1131 optional_class: /* Empty */
1139 if (lookup_symbol(constants, $1, SYM_CLASS, &value))
1142 /* the zone validator will give the error */
1167 zone_option_list: zone_option L_EOS
1168 | zone_option_list zone_option L_EOS
1171 zone_option: T_TYPE zone_type
1173 if (!set_zone_type(current_zone, $2))
1174 parser_warning(0, "zone type already set; skipping");
1178 if (!set_zone_filename(current_zone, $2))
1180 "zone filename already set; skipping");
1182 | T_MASTERS '{' master_in_addr_list '}'
1183 | T_TRANSFER_SOURCE maybe_wild_addr
1185 set_zone_transfer_source(current_zone, $2);
1187 | T_CHECK_NAMES check_names_opt
1189 if (!set_zone_checknames(current_zone, $2))
1191 "zone checknames already set; skipping");
1193 | T_ALLOW_UPDATE '{' address_match_list '}'
1195 if (!set_zone_update_acl(current_zone, $3))
1197 "zone update acl already set; skipping");
1199 | T_ALLOW_QUERY '{' address_match_list '}'
1201 if (!set_zone_query_acl(current_zone, $3))
1203 "zone query acl already set; skipping");
1205 | T_ALLOW_TRANSFER '{' address_match_list '}'
1207 if (!set_zone_transfer_acl(current_zone, $3))
1209 "zone transfer acl already set; skipping");
1211 | T_MAX_TRANSFER_TIME_IN L_NUMBER
1213 if (!set_zone_transfer_time_in(current_zone, $2*60))
1215 "zone max transfer time (in) already set; skipping");
1217 | T_NOTIFY yea_or_nay
1219 set_zone_notify(current_zone, $2);
1221 | T_ALSO_NOTIFY '{' opt_notify_in_addr_list '}'
1225 master_in_addr_list: master_in_addr L_EOS
1229 | master_in_addr_list master_in_addr L_EOS
1235 master_in_addr: L_IPADDR
1237 add_zone_master(current_zone, $1);
1241 opt_notify_in_addr_list: /* nothing */
1242 | notify_in_addr_list
1245 notify_in_addr_list: notify_in_addr L_EOS
1249 | notify_in_addr_list notify_in_addr L_EOS
1255 notify_in_addr: L_IPADDR
1257 add_zone_notify(current_zone, $1);
1267 if ($1 < 0 || $1 > 65535) {
1269 "invalid IP port number '%d'; setting port to 0",
1277 any_string: L_STRING
1284 canonical_name(char *name) {
1285 char canonical[MAXDNAME];
1287 if (strlen(name) >= MAXDNAME)
1289 strcpy(canonical, name);
1290 if (makename(canonical, ".", sizeof canonical) < 0)
1292 return (savestr(canonical, 0));
1297 ip_match_element ime;
1299 struct in_addr address;
1301 /* Create the predefined ACLs */
1303 address.s_addr = 0U;
1306 ime = new_ip_match_pattern(address, 0);
1307 iml = new_ip_match_list();
1308 add_to_ip_match_list(iml, ime);
1309 define_acl(savestr("any", 1), iml);
1312 ime = new_ip_match_pattern(address, 0);
1313 ip_match_negate(ime);
1314 iml = new_ip_match_list();
1315 add_to_ip_match_list(iml, ime);
1316 define_acl(savestr("none", 1), iml);
1318 /* ACL "localhost" */
1319 ime = new_ip_match_localhost();
1320 iml = new_ip_match_list();
1321 add_to_ip_match_list(iml, ime);
1322 define_acl(savestr("localhost", 1), iml);
1324 /* ACL "localnets" */
1325 ime = new_ip_match_localnets();
1326 iml = new_ip_match_list();
1327 add_to_ip_match_list(iml, ime);
1328 define_acl(savestr("localnets", 1), iml);
1332 free_sym_value(int type, void *value) {
1333 ns_debug(ns_log_parser, 99, "free_sym_value: type %06x value %p",
1338 free_ip_match_list(value);
1341 free_key_info(value);
1344 ns_panic(ns_log_parser, 1,
1345 "unhandled case in free_sym_value()");
1352 lookup_channel(char *name) {
1355 if (lookup_symbol(symtab, name, SYM_CHANNEL, &value))
1356 return ((log_channel)(value.pointer));
1361 define_channel(char *name, log_channel channel) {
1364 value.pointer = channel;
1365 define_symbol(symtab, name, SYM_CHANNEL, value, SYMBOL_FREE_KEY);
1369 define_builtin_channels() {
1370 define_channel(savestr("default_syslog", 1), syslog_channel);
1371 define_channel(savestr("default_debug", 1), debug_channel);
1372 define_channel(savestr("default_stderr", 1), stderr_channel);
1373 define_channel(savestr("null", 1), null_channel);
1380 symtab = new_symbol_table(SYMBOL_TABLE_SIZE, NULL);
1381 if (authtab != NULL)
1382 free_symbol_table(authtab);
1383 authtab = new_symbol_table(AUTH_TABLE_SIZE, free_sym_value);
1385 define_builtin_channels();
1391 free_symbol_table(symtab);
1394 * We don't clean up authtab here because the ip_match_lists are in
1404 lookup_acl(char *name) {
1407 if (lookup_symbol(authtab, name, SYM_ACL, &value))
1408 return ((ip_match_list)(value.pointer));
1413 define_acl(char *name, ip_match_list iml) {
1416 INSIST(name != NULL);
1417 INSIST(iml != NULL);
1419 value.pointer = iml;
1420 define_symbol(authtab, name, SYM_ACL, value,
1421 SYMBOL_FREE_KEY|SYMBOL_FREE_VALUE);
1422 ns_debug(ns_log_parser, 7, "acl %s", name);
1423 dprint_ip_match_list(ns_log_parser, iml, 2, "allow ", "deny ");
1427 lookup_key(char *name) {
1430 if (lookup_symbol(authtab, name, SYM_KEY, &value))
1431 return ((key_info)(value.pointer));
1436 define_key(char *name, key_info ki) {
1439 INSIST(name != NULL);
1443 define_symbol(authtab, name, SYM_KEY, value, SYMBOL_FREE_VALUE);
1444 dprint_key_info(ki);
1448 parse_configuration(const char *filename) {
1449 FILE *config_stream;
1451 config_stream = fopen(filename, "r");
1452 if (config_stream == NULL)
1453 ns_panic(ns_log_parser, 0, "can't open '%s'", filename);
1457 lexer_begin_file(filename, config_stream);
1464 parser_initialize(void) {
1469 parser_shutdown(void) {
1470 if (authtab != NULL)
1471 free_symbol_table(authtab);