⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 server.c

📁 bind-3.2.
💻 C
📖 第 1 页 / 共 5 页
字号:
	*peerp = peer;	return (ISC_R_SUCCESS); cleanup:	dns_peer_detach(&peer);	return (result);}/* * Configure 'view' according to 'vconfig', taking defaults from 'config' * where values are missing in 'vconfig'. * * When configuring the default view, 'vconfig' will be NULL and the * global defaults in 'config' used exclusively. */static isc_result_tconfigure_view(dns_view_t *view, cfg_obj_t *config, cfg_obj_t *vconfig,	       isc_mem_t *mctx, ns_aclconfctx_t *actx){	cfg_obj_t *maps[4];	cfg_obj_t *cfgmaps[3];	cfg_obj_t *options = NULL;	cfg_obj_t *voptions = NULL;	cfg_obj_t *forwardtype;	cfg_obj_t *forwarders;	cfg_obj_t *zonelist;	cfg_obj_t *obj;	cfg_listelt_t *element;	in_port_t port;	dns_cache_t *cache = NULL;	isc_result_t result;	isc_uint32_t max_cache_size;	isc_uint32_t lame_ttl;	dns_tsig_keyring_t *ring;	dns_view_t *pview = NULL;	/* Production view */	isc_mem_t *cmctx;	dns_dispatch_t *dispatch4 = NULL;	dns_dispatch_t *dispatch6 = NULL;	isc_boolean_t reused_cache = ISC_FALSE;	int i;	char *str;	REQUIRE(DNS_VIEW_VALID(view));	cmctx = NULL;	if (config != NULL)		cfg_map_get(config, "options", &options);	i = 0;	if (vconfig != NULL) {		voptions = cfg_tuple_get(vconfig, "options");		maps[i++] = voptions;	}	if (options != NULL)		maps[i++] = options;	maps[i++] = ns_g_defaults;	maps[i] = NULL;	i = 0;	if (voptions != NULL)		cfgmaps[i++] = voptions;	if (config != NULL)		cfgmaps[i++] = config;	cfgmaps[i] = NULL;	/*	 * Set the view's port number for outgoing queries.	 */	CHECKM(ns_config_getport(config, &port), "port");	dns_view_setdstport(view, port);	/*	 * Configure the zones.	 */	zonelist = NULL;	if (voptions != NULL)		(void)cfg_map_get(voptions, "zone", &zonelist);	else		(void)cfg_map_get(config, "zone", &zonelist);	for (element = cfg_list_first(zonelist);	     element != NULL;	     element = cfg_list_next(element))	{		cfg_obj_t *zconfig = cfg_listelt_value(element);		CHECK(configure_zone(config, zconfig, vconfig, mctx, view,				     actx));	}	/*	 * Configure the view's cache.  Try to reuse an existing	 * cache if possible, otherwise create a new cache.	 * Note that the ADB is not preserved in either case.	 *	 * XXX Determining when it is safe to reuse a cache is	 * tricky.  When the view's configuration changes, the cached	 * data may become invalid because it reflects our old	 * view of the world.  As more view attributes become	 * configurable, we will have to add code here to check	 * whether they have changed in ways that could	 * invalidate the cache.	 */	result = dns_viewlist_find(&ns_g_server->viewlist,				   view->name, view->rdclass,				   &pview);	if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS)		goto cleanup;	if (pview != NULL) {		INSIST(pview->cache != NULL);		isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,			      NS_LOGMODULE_SERVER, ISC_LOG_DEBUG(3),			      "reusing existing cache");		reused_cache = ISC_TRUE;		dns_cache_attach(pview->cache, &cache);		dns_view_detach(&pview);	} else {		CHECK(isc_mem_create(0, 0, &cmctx));		CHECK(dns_cache_create(cmctx, ns_g_taskmgr, ns_g_timermgr,				       view->rdclass, "rbt", 0, NULL, &cache));	}	dns_view_setcache(view, cache);	/*	 * cache-file cannot be inherited if views are present, but this	 * should be caught by the configuration checking stage.	 */	obj = NULL;	result = ns_config_get(maps, "cache-file", &obj);	if (result == ISC_R_SUCCESS) {		dns_cache_setfilename(cache, cfg_obj_asstring(obj));		if (!reused_cache)			CHECK(dns_cache_load(cache));	}	obj = NULL;	result = ns_config_get(maps, "cleaning-interval", &obj);	INSIST(result == ISC_R_SUCCESS);	dns_cache_setcleaninginterval(cache, cfg_obj_asuint32(obj) * 60);	obj = NULL;	result = ns_config_get(maps, "max-cache-size", &obj);	INSIST(result == ISC_R_SUCCESS);	if (cfg_obj_isstring(obj)) {		str = cfg_obj_asstring(obj);		INSIST(strcasecmp(str, "unlimited") == 0);		max_cache_size = ISC_UINT32_MAX;	} else {		isc_resourcevalue_t value;		value = cfg_obj_asuint64(obj);		if (value > ISC_UINT32_MAX) {			cfg_obj_log(obj, ns_g_lctx, ISC_LOG_ERROR,				    "'max-cache-size "				    "%" ISC_PRINT_QUADFORMAT "d' is too large",				    value);			result = ISC_R_RANGE;			goto cleanup;		}		max_cache_size = (isc_uint32_t)value;	}	dns_cache_setcachesize(cache, max_cache_size);	dns_cache_detach(&cache);	/*	 * Resolver.	 *	 * XXXRTH  Hardwired number of tasks.	 */	CHECK(get_view_querysource_dispatch(maps, AF_INET, &dispatch4));	CHECK(get_view_querysource_dispatch(maps, AF_INET6, &dispatch6));	CHECK(dns_view_createresolver(view, ns_g_taskmgr, 31,				      ns_g_socketmgr, ns_g_timermgr,				      0, ns_g_dispatchmgr,				      dispatch4, dispatch6));	if (dispatch4 != NULL)		dns_dispatch_detach(&dispatch4);	if (dispatch6 != NULL)		dns_dispatch_detach(&dispatch6);	/*	 * Set resolver's lame-ttl.	 */	obj = NULL;	result = ns_config_get(maps, "lame-ttl", &obj);	INSIST(result == ISC_R_SUCCESS);	lame_ttl = cfg_obj_asuint32(obj);	if (lame_ttl > 1800)		lame_ttl = 1800;	dns_resolver_setlamettl(view->resolver, lame_ttl);		/*	 * A global or view "forwarders" option, if present,	 * creates an entry for "." in the forwarding table.	 */	forwardtype = NULL;	forwarders = NULL;	(void)ns_config_get(maps, "forward", &forwardtype);	(void)ns_config_get(maps, "forwarders", &forwarders);	if (forwarders != NULL)		CHECK(configure_forward(config, view, dns_rootname, 					forwarders, forwardtype));	/*	 * We have default hints for class IN if we need them.	 */	if (view->rdclass == dns_rdataclass_in && view->hints == NULL)		dns_view_sethints(view, ns_g_server->in_roothints);	/*	 * If we still have no hints, this is a non-IN view with no	 * "hints zone" configured.  Issue a warning, except if this	 * is a root server.  Root servers never need to consult 	 * their hints, so it's no point requireing users to configure	 * them.	 */	if (view->hints == NULL) {		dns_zone_t *rootzone = NULL;		dns_view_findzone(view, dns_rootname, &rootzone);		if (rootzone != NULL) {			dns_zone_detach(&rootzone);		} else {			isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,				      NS_LOGMODULE_SERVER, ISC_LOG_WARNING,				      "no root hints for view '%s'",				      view->name);		}	}	/*	 * Configure the view's TSIG keys.	 */	ring = NULL;	CHECK(ns_tsigkeyring_fromconfig(config, vconfig, view->mctx, &ring));	dns_view_setkeyring(view, ring);	/*	 * Configure the view's peer list.	 */	{		cfg_obj_t *peers = NULL;		cfg_listelt_t *element;		dns_peerlist_t *newpeers = NULL;		(void)ns_config_get(cfgmaps, "server", &peers);		CHECK(dns_peerlist_new(mctx, &newpeers));		for (element = cfg_list_first(peers);		     element != NULL;		     element = cfg_list_next(element))		{			cfg_obj_t *cpeer = cfg_listelt_value(element);			dns_peer_t *peer;			CHECK(configure_peer(cpeer, mctx, &peer));			dns_peerlist_addpeer(newpeers, peer);			dns_peer_detach(&peer);		}		dns_peerlist_detach(&view->peers);		view->peers = newpeers; /* Transfer ownership. */	}	/*	 * Copy the aclenv object.	 */	dns_aclenv_copy(&view->aclenv, &ns_g_server->aclenv);	/*	 * Configure the "match-clients" and "match-destinations" ACL.	 */	CHECK(configure_view_acl(vconfig, config, "match-clients", actx,				 ns_g_mctx, &view->matchclients));	CHECK(configure_view_acl(vconfig, config, "match-destinations", actx,				 ns_g_mctx, &view->matchdestinations));	/*	 * Configure the "match-recursive-only" option.	 */	obj = NULL;	(void) ns_config_get(maps, "match-recursive-only", &obj);	if (obj != NULL && cfg_obj_asboolean(obj))		view->matchrecursiveonly = ISC_TRUE;	else		view->matchrecursiveonly = ISC_FALSE;	/*	 * Configure other configurable data.	 */	obj = NULL;	result = ns_config_get(maps, "recursion", &obj);	INSIST(result == ISC_R_SUCCESS);	view->recursion = cfg_obj_asboolean(obj);	obj = NULL;	result = ns_config_get(maps, "auth-nxdomain", &obj);	INSIST(result == ISC_R_SUCCESS);	view->auth_nxdomain = cfg_obj_asboolean(obj);	obj = NULL;	result = ns_config_get(maps, "minimal-responses", &obj);	INSIST(result == ISC_R_SUCCESS);	view->minimalresponses = cfg_obj_asboolean(obj);	obj = NULL;	result = ns_config_get(maps, "transfer-format", &obj);	INSIST(result == ISC_R_SUCCESS);	str = cfg_obj_asstring(obj);	if (strcasecmp(str, "many-answers") == 0)		view->transfer_format = dns_many_answers;	else if (strcasecmp(str, "one-answer") == 0)		view->transfer_format = dns_one_answer;	else		INSIST(0);		/*	 * Set sources where additional data and CNAME/DNAME	 * targets for authoritative answers may be found.	 */	obj = NULL;	result = ns_config_get(maps, "additional-from-auth", &obj);	INSIST(result == ISC_R_SUCCESS);	view->additionalfromauth = cfg_obj_asboolean(obj);	if (view->recursion && ! view->additionalfromauth) {		cfg_obj_log(obj, ns_g_lctx, ISC_LOG_WARNING,			    "'additional-from-auth no' is only supported "			    "with 'recursion no'");		view->additionalfromauth = ISC_TRUE;	}	obj = NULL;	result = ns_config_get(maps, "additional-from-cache", &obj);	INSIST(result == ISC_R_SUCCESS);	view->additionalfromcache = cfg_obj_asboolean(obj);	if (view->recursion && ! view->additionalfromcache) {		cfg_obj_log(obj, ns_g_lctx, ISC_LOG_WARNING,			    "'additional-from-cache no' is only supported "			    "with 'recursion no'");		view->additionalfromcache = ISC_TRUE;	}	CHECK(configure_view_acl(vconfig, config, "allow-query",				 actx, ns_g_mctx, &view->queryacl));	CHECK(configure_view_acl(vconfig, config, "allow-recursion",				 actx, ns_g_mctx, &view->recursionacl));	CHECK(configure_view_acl(vconfig, config, "allow-v6-synthesis",				 actx, ns_g_mctx, &view->v6synthesisacl));	CHECK(configure_view_acl(vconfig, config, "sortlist",				 actx, ns_g_mctx, &view->sortlist));	obj = NULL;	result = ns_config_get(maps, "request-ixfr", &obj);	INSIST(result == ISC_R_SUCCESS);	view->requestixfr = cfg_obj_asboolean(obj);	obj = NULL;	result = ns_config_get(maps, "provide-ixfr", &obj);	INSIST(result == ISC_R_SUCCESS);	view->provideixfr = cfg_obj_asboolean(obj);	/*	 * For now, there is only one kind of trusted keys, the	 * "security roots".	 */	CHECK(configure_view_dnsseckeys(vconfig, config, mctx,				  &view->secroots));	obj = NULL;	result = ns_config_get(maps, "max-cache-ttl", &obj);	INSIST(result == ISC_R_SUCCESS);	view->maxcachettl = cfg_obj_asuint32(obj);	obj = NULL;	result = ns_config_get(maps, "max-ncache-ttl", &obj);	INSIST(result == ISC_R_SUCCESS);	view->maxncachettl = cfg_obj_asuint32(obj);	if (view->maxncachettl > 7 * 24 * 3600)		view->maxncachettl = 7 * 24 * 3600;	obj = NULL;	result = ns_config_get(maps, "root-delegation-only", &obj);	if (result == ISC_R_SUCCESS) {		dns_view_setrootdelonly(view, ISC_TRUE);		if (!cfg_obj_isvoid(obj)) {			dns_fixedname_t fixed;			dns_name_t *name;			isc_buffer_t b;			char *str;			cfg_obj_t *exclude;			dns_fixedname_init(&fixed);			name = dns_fixedname_name(&fixed);			for (element = cfg_list_first(obj);			     element != NULL;			     element = cfg_list_next(element)) {				exclude = cfg_listelt_value(element);				str = cfg_obj_asstring(exclude);				isc_buffer_init(&b, str, strlen(str));				isc_buffer_add(&b, strlen(str));				CHECK(dns_name_fromtext(name, &b, dns_rootname,							ISC_FALSE, NULL));				CHECK(dns_view_excludedelegationonly(view,								     name));			}		}	} else		dns_view_setrootdelonly(view, ISC_FALSE);	result = ISC_R_SUCCESS; cleanup:	if (cmctx != NULL)		isc_mem_detach(&cmctx);	if (cache != NULL)		dns_cache_detach(&cache);	return (result);}/* * Create the special view that handles queries under "bind. CH". */static isc_result_tcreate_bind_view(dns_view_t **viewp) {	isc_result_t result;	dns_view_t *view = NULL;	REQUIRE(viewp != NULL && *viewp == NULL);	CHECK(dns_view_create(ns_g_mctx, dns_rdataclass_ch, "_bind", &view));	/* Transfer ownership. */	*viewp = view;	view = NULL;	result = ISC_R_SUCCESS; cleanup:	if (view != NULL)		dns_view_detach(&view);	return (result);}/* * Create the zone that handles queries for "version.bind. CH".   The * version string is returned either from the "version" configuration * option or the global defaults. */static isc_result_tcreate_version_zone(cfg_obj_t **maps, dns_zonemgr_t *zmgr, dns_view_t *view) {	isc_result_t result;	dns_db_t *db = NULL;	dns_zone_t *zone = NULL;	dns_dbversion_t *dbver = NULL;	dns_difftuple_t *tuple = NULL;	dns_diff_t diff;	char *versiontext;	unsigned char buf[256];	isc_region_t r;	size_t len;	dns_rdata_t rdata = DNS_RDATA_INIT;	static unsigned char origindata[] = "\007version\004bind";	dns_name_t origin;	cfg_obj_t *obj = NULL;	dns_acl_t *acl = NULL;	dns_diff_init(ns_g_mctx, &diff);	dns_name_init(&origin, NULL);	r.base = origindata;	r.length = sizeof(origindata);	dns_name_fromregion(&origin, &r);	result = ns_config_get(maps, "version", &obj);	INSIST(result == ISC_R_SUCCESS);	versiontext = cfg_obj_asstring(obj);	len = strlen(versiontext);	if (len > 255U)		len = 255; /* Silently truncate. */	buf[0] = len;	memcpy(buf + 1, versiontext, len);	r.base = buf;	r.length = 1 + len;	dns_rdata_fromregion(&rdata, dns_rdataclass_ch, dns_rdatatype_txt, &r);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -