namedconf.c
来自「非常好的dns解析软件」· C语言 代码 · 共 2,050 行 · 第 1/5 页
C
2,050 行
/* * Copyright (C) 2004-2006 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 2002, 2003 Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. *//* $Id: namedconf.c,v 1.30.18.38 2006/05/03 01:46:40 marka Exp $ *//*! \file */#include <config.h>#include <string.h>#include <isc/lex.h>#include <isc/result.h>#include <isc/string.h>#include <isc/util.h>#include <isccfg/cfg.h>#include <isccfg/grammar.h>#include <isccfg/log.h>#define TOKEN_STRING(pctx) (pctx->token.value.as_textregion.base)/*% Check a return value. */#define CHECK(op) \ do { result = (op); \ if (result != ISC_R_SUCCESS) goto cleanup; \ } while (0)/*% Clean up a configuration object if non-NULL. */#define CLEANUP_OBJ(obj) \ do { if ((obj) != NULL) cfg_obj_destroy(pctx, &(obj)); } while (0)/*% * Forward declarations of static functions. */static isc_result_tparse_enum_or_other(cfg_parser_t *pctx, const cfg_type_t *enumtype, const cfg_type_t *othertype, cfg_obj_t **ret);static isc_result_tparse_keyvalue(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);static isc_result_tparse_optional_keyvalue(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret);static voidprint_keyvalue(cfg_printer_t *pctx, const cfg_obj_t *obj);static voiddoc_keyvalue(cfg_printer_t *pctx, const cfg_type_t *type);static voiddoc_optional_keyvalue(cfg_printer_t *pctx, const cfg_type_t *type);static cfg_type_t cfg_type_acl;static cfg_type_t cfg_type_addrmatchelt;static cfg_type_t cfg_type_bracketed_aml;static cfg_type_t cfg_type_bracketed_namesockaddrkeylist;static cfg_type_t cfg_type_bracketed_sockaddrlist;static cfg_type_t cfg_type_bracketed_sockaddrnameportlist;static cfg_type_t cfg_type_controls;static cfg_type_t cfg_type_controls_sockaddr;static cfg_type_t cfg_type_destinationlist;static cfg_type_t cfg_type_dialuptype;static cfg_type_t cfg_type_ixfrdifftype;static cfg_type_t cfg_type_key;static cfg_type_t cfg_type_logfile;static cfg_type_t cfg_type_logging;static cfg_type_t cfg_type_logseverity;static cfg_type_t cfg_type_lwres;static cfg_type_t cfg_type_masterselement;static cfg_type_t cfg_type_nameportiplist;static cfg_type_t cfg_type_negated;static cfg_type_t cfg_type_notifytype;static cfg_type_t cfg_type_optional_class;static cfg_type_t cfg_type_optional_facility;static cfg_type_t cfg_type_optional_facility;static cfg_type_t cfg_type_optional_keyref;static cfg_type_t cfg_type_optional_port;static cfg_type_t cfg_type_options;static cfg_type_t cfg_type_portiplist;static cfg_type_t cfg_type_querysource4;static cfg_type_t cfg_type_querysource6;static cfg_type_t cfg_type_querysource;static cfg_type_t cfg_type_server;static cfg_type_t cfg_type_server_key_kludge;static cfg_type_t cfg_type_size;static cfg_type_t cfg_type_sizenodefault;static cfg_type_t cfg_type_sockaddr4wild;static cfg_type_t cfg_type_sockaddr6wild;static cfg_type_t cfg_type_view;static cfg_type_t cfg_type_viewopts;static cfg_type_t cfg_type_zone;static cfg_type_t cfg_type_zoneopts;static cfg_type_t cfg_type_dynamically_loadable_zones;static cfg_type_t cfg_type_dynamically_loadable_zones_opts;/* * Clauses that can be found in a 'dynamically loadable zones' statement */static cfg_clausedef_tdynamically_loadable_zones_clauses[] = { { "database", &cfg_type_astring, 0 }, { NULL, NULL, 0 }};/* * A dynamically loadable zones statement. */static cfg_tuplefielddef_t dynamically_loadable_zones_fields[] = { { "name", &cfg_type_astring, 0 }, { "options", &cfg_type_dynamically_loadable_zones_opts, 0 }, { NULL, NULL, 0 }};static cfg_type_t cfg_type_dynamically_loadable_zones = { "dlz", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple, dynamically_loadable_zones_fields };/*% tkey-dhkey */static cfg_tuplefielddef_t tkey_dhkey_fields[] = { { "name", &cfg_type_qstring, 0 }, { "keyid", &cfg_type_uint32, 0 }, { NULL, NULL, 0 }};static cfg_type_t cfg_type_tkey_dhkey = { "tkey-dhkey", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple, tkey_dhkey_fields};/*% listen-on */static cfg_tuplefielddef_t listenon_fields[] = { { "port", &cfg_type_optional_port, 0 }, { "acl", &cfg_type_bracketed_aml, 0 }, { NULL, NULL, 0 }};static cfg_type_t cfg_type_listenon = { "listenon", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple, listenon_fields };/*% acl */static cfg_tuplefielddef_t acl_fields[] = { { "name", &cfg_type_astring, 0 }, { "value", &cfg_type_bracketed_aml, 0 }, { NULL, NULL, 0 }};static cfg_type_t cfg_type_acl = { "acl", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple, acl_fields };/*% masters */static cfg_tuplefielddef_t masters_fields[] = { { "name", &cfg_type_astring, 0 }, { "port", &cfg_type_optional_port, 0 }, { "addresses", &cfg_type_bracketed_namesockaddrkeylist, 0 }, { NULL, NULL, 0 }};static cfg_type_t cfg_type_masters = { "masters", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple, masters_fields };/*% * "sockaddrkeylist", a list of socket addresses with optional keys * and an optional default port, as used in the masters option. * E.g., * "port 1234 { mymasters; 10.0.0.1 key foo; 1::2 port 69; }" */static cfg_tuplefielddef_t namesockaddrkey_fields[] = { { "masterselement", &cfg_type_masterselement, 0 }, { "key", &cfg_type_optional_keyref, 0 }, { NULL, NULL, 0 },};static cfg_type_t cfg_type_namesockaddrkey = { "namesockaddrkey", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple, namesockaddrkey_fields};static cfg_type_t cfg_type_bracketed_namesockaddrkeylist = { "bracketed_namesockaddrkeylist", cfg_parse_bracketed_list, cfg_print_bracketed_list, cfg_doc_bracketed_list, &cfg_rep_list, &cfg_type_namesockaddrkey};static cfg_tuplefielddef_t namesockaddrkeylist_fields[] = { { "port", &cfg_type_optional_port, 0 }, { "addresses", &cfg_type_bracketed_namesockaddrkeylist, 0 }, { NULL, NULL, 0 }};static cfg_type_t cfg_type_namesockaddrkeylist = { "sockaddrkeylist", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple, namesockaddrkeylist_fields};/*% * A list of socket addresses with an optional default port, * as used in the also-notify option. E.g., * "port 1234 { 10.0.0.1; 1::2 port 69; }" */static cfg_tuplefielddef_t portiplist_fields[] = { { "port", &cfg_type_optional_port, 0 }, { "addresses", &cfg_type_bracketed_sockaddrlist, 0 }, { NULL, NULL, 0 }};static cfg_type_t cfg_type_portiplist = { "portiplist", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple, portiplist_fields};/*% * A public key, as in the "pubkey" statement. */static cfg_tuplefielddef_t pubkey_fields[] = { { "flags", &cfg_type_uint32, 0 }, { "protocol", &cfg_type_uint32, 0 }, { "algorithm", &cfg_type_uint32, 0 }, { "key", &cfg_type_qstring, 0 }, { NULL, NULL, 0 }};static cfg_type_t cfg_type_pubkey = { "pubkey", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple, pubkey_fields };/*% * A list of RR types, used in grant statements. * Note that the old parser allows quotes around the RR type names. */static cfg_type_t cfg_type_rrtypelist = { "rrtypelist", cfg_parse_spacelist, cfg_print_spacelist, cfg_doc_terminal, &cfg_rep_list, &cfg_type_astring};static const char *mode_enums[] = { "grant", "deny", NULL };static cfg_type_t cfg_type_mode = { "mode", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum, &cfg_rep_string, &mode_enums};static const char *matchtype_enums[] = { "name", "subdomain", "wildcard", "self", "selfsub", "selfwild", NULL };static cfg_type_t cfg_type_matchtype = { "matchtype", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum, &cfg_rep_string, &matchtype_enums};/*% * A grant statement, used in the update policy. */static cfg_tuplefielddef_t grant_fields[] = { { "mode", &cfg_type_mode, 0 }, { "identity", &cfg_type_astring, 0 }, /* domain name */ { "matchtype", &cfg_type_matchtype, 0 }, { "name", &cfg_type_astring, 0 }, /* domain name */ { "types", &cfg_type_rrtypelist, 0 }, { NULL, NULL, 0 }};static cfg_type_t cfg_type_grant = { "grant", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple, grant_fields };static cfg_type_t cfg_type_updatepolicy = { "update_policy", cfg_parse_bracketed_list, cfg_print_bracketed_list, cfg_doc_bracketed_list, &cfg_rep_list, &cfg_type_grant};/*% * A view statement. */static cfg_tuplefielddef_t view_fields[] = { { "name", &cfg_type_astring, 0 }, { "class", &cfg_type_optional_class, 0 }, { "options", &cfg_type_viewopts, 0 }, { NULL, NULL, 0 }};static cfg_type_t cfg_type_view = { "view", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple, view_fields };/*% * A zone statement. */static cfg_tuplefielddef_t zone_fields[] = { { "name", &cfg_type_astring, 0 }, { "class", &cfg_type_optional_class, 0 }, { "options", &cfg_type_zoneopts, 0 }, { NULL, NULL, 0 }};static cfg_type_t cfg_type_zone = { "zone", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple, zone_fields };/*% * A "category" clause in the "logging" statement. */static cfg_tuplefielddef_t category_fields[] = { { "name", &cfg_type_astring, 0 }, { "destinations", &cfg_type_destinationlist,0 }, { NULL, NULL, 0 }};static cfg_type_t cfg_type_category = { "category", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple, category_fields };/*% * A trusted key, as used in the "trusted-keys" statement. */static cfg_tuplefielddef_t trustedkey_fields[] = { { "name", &cfg_type_astring, 0 }, { "flags", &cfg_type_uint32, 0 }, { "protocol", &cfg_type_uint32, 0 }, { "algorithm", &cfg_type_uint32, 0 }, { "key", &cfg_type_qstring, 0 }, { NULL, NULL, 0 }};static cfg_type_t cfg_type_trustedkey = { "trustedkey", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple, trustedkey_fields};static keyword_type_t wild_class_kw = { "class", &cfg_type_ustring };static cfg_type_t cfg_type_optional_wild_class = { "optional_wild_class", parse_optional_keyvalue, print_keyvalue, doc_optional_keyvalue, &cfg_rep_string, &wild_class_kw};static keyword_type_t wild_type_kw = { "type", &cfg_type_ustring };static cfg_type_t cfg_type_optional_wild_type = { "optional_wild_type", parse_optional_keyvalue, print_keyvalue, doc_optional_keyvalue, &cfg_rep_string, &wild_type_kw};static keyword_type_t wild_name_kw = { "name", &cfg_type_qstring };static cfg_type_t cfg_type_optional_wild_name = { "optional_wild_name", parse_optional_keyvalue, print_keyvalue, doc_optional_keyvalue, &cfg_rep_string, &wild_name_kw};/*% * An rrset ordering element. */static cfg_tuplefielddef_t rrsetorderingelement_fields[] = { { "class", &cfg_type_optional_wild_class, 0 }, { "type", &cfg_type_optional_wild_type, 0 }, { "name", &cfg_type_optional_wild_name, 0 }, { "order", &cfg_type_ustring, 0 }, /* must be literal "order" */ { "ordering", &cfg_type_ustring, 0 }, { NULL, NULL, 0 }};static cfg_type_t cfg_type_rrsetorderingelement = { "rrsetorderingelement", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple, rrsetorderingelement_fields};/*% * A global or view "check-names" option. Note that the zone * "check-names" option has a different syntax. */static const char *checktype_enums[] = { "master", "slave", "response", NULL };static cfg_type_t cfg_type_checktype = { "checktype", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum, &cfg_rep_string, &checktype_enums};static const char *checkmode_enums[] = { "fail", "warn", "ignore", NULL };static cfg_type_t cfg_type_checkmode = { "checkmode", cfg_parse_enum, cfg_print_ustring, cfg_doc_enum, &cfg_rep_string, &checkmode_enums};static cfg_tuplefielddef_t checknames_fields[] = { { "type", &cfg_type_checktype, 0 }, { "mode", &cfg_type_checkmode, 0 }, { NULL, NULL, 0 }};static cfg_type_t cfg_type_checknames = { "checknames", cfg_parse_tuple, cfg_print_tuple, cfg_doc_tuple, &cfg_rep_tuple, checknames_fields};static cfg_type_t cfg_type_bracketed_sockaddrlist = { "bracketed_sockaddrlist", cfg_parse_bracketed_list, cfg_print_bracketed_list, cfg_doc_bracketed_list, &cfg_rep_list, &cfg_type_sockaddr};static cfg_type_t cfg_type_rrsetorder = { "rrsetorder", cfg_parse_bracketed_list, cfg_print_bracketed_list, cfg_doc_bracketed_list, &cfg_rep_list, &cfg_type_rrsetorderingelement};
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?