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

📄 server.c

📁 bind-3.2.
💻 C
📖 第 1 页 / 共 5 页
字号:
	{		cfg_obj_t *vconfig;		view = NULL;		vconfig = cfg_listelt_value(element);		CHECK(create_view(vconfig, &viewlist, &view));		INSIST(view != NULL);		CHECK(configure_view(view, config, vconfig,				     ns_g_mctx, &aclconfctx));		dns_view_freeze(view);		dns_view_detach(&view);	}	/*	 * Make sure we have a default view if and only if there	 * were no explicit views.	 */	if (views == NULL) {		/*		 * No explicit views; there ought to be a default view.		 * There may already be one created as a side effect		 * of zone statements, or we may have to create one.		 * In either case, we need to configure and freeze it.		 */		CHECK(create_view(NULL, &viewlist, &view));		CHECK(configure_view(view, config, NULL, ns_g_mctx,				     &aclconfctx));		dns_view_freeze(view);		dns_view_detach(&view);	}	/*	 * Create (or recreate) the internal _bind view.	 */	CHECK(create_bind_view(&view));	CHECK(configure_view_acl(NULL, config, "allow-query",				 &aclconfctx, ns_g_mctx, &view->queryacl));	ISC_LIST_APPEND(viewlist, view, link);	CHECK(create_version_zone(maps, server->zonemgr, view));	CHECK(create_authors_zone(options, server->zonemgr, view));	dns_view_freeze(view);	view = NULL;	/*	 * Swap our new view list with the production one.	 */	tmpviewlist = server->viewlist;	server->viewlist = viewlist;	viewlist = tmpviewlist;	/*	 * Load the TKEY information from the configuration.	 */	if (options != NULL) {		dns_tkeyctx_t *t = NULL;		CHECKM(ns_tkeyctx_fromconfig(options, ns_g_mctx, ns_g_entropy,					     &t),		       "configuring TKEY");		if (server->tkeyctx != NULL)			dns_tkeyctx_destroy(&server->tkeyctx);		server->tkeyctx = t;	}	/*	 * Bind the control port(s).	 */	CHECKM(ns_controls_configure(ns_g_server->controls, config,				     &aclconfctx),	       "binding control channel(s)");	/*	 * Bind the lwresd port(s).	 */	CHECKM(ns_lwresd_configure(ns_g_mctx, config),	       "binding lightweight resolver ports");	/*	 * Open the source of entropy.	 */	if (first_time) {		obj = NULL;		result = ns_config_get(maps, "random-device", &obj);		if (result != ISC_R_SUCCESS) {			isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,				      NS_LOGMODULE_SERVER, ISC_LOG_INFO,				      "no source of entropy found");		} else {			const char *randomdev = cfg_obj_asstring(obj);			result = isc_entropy_createfilesource(ns_g_entropy,							      randomdev);			if (result != ISC_R_SUCCESS)				isc_log_write(ns_g_lctx,					      NS_LOGCATEGORY_GENERAL,					      NS_LOGMODULE_SERVER,					      ISC_LOG_INFO,					      "could not open entropy source "					      "%s: %s",					      randomdev,					      isc_result_totext(result));		}	}	/*	 * Relinquish root privileges.	 */	if (first_time)		ns_os_changeuser();	/*	 * Configure the logging system.	 *	 * Do this after changing UID to make sure that any log	 * files specified in named.conf get created by the	 * unprivileged user, not root.	 */	if (ns_g_logstderr) {		isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,			      NS_LOGMODULE_SERVER, ISC_LOG_INFO,			      "ignoring config file logging "			      "statement due to -g option");	} else {		cfg_obj_t *logobj = NULL;		isc_logconfig_t *logc = NULL;		CHECKM(isc_logconfig_create(ns_g_lctx, &logc),		       "creating new logging configuration");		logobj = NULL;		(void)cfg_map_get(config, "logging", &logobj);		if (logobj != NULL) {			CHECKM(ns_log_configure(logc, logobj),			       "configuring logging");		} else {			CHECKM(ns_log_setdefaultchannels(logc),			       "setting up default logging channels");			CHECKM(ns_log_setunmatchedcategory(logc),			       "setting up default 'category unmatched'");			CHECKM(ns_log_setdefaultcategory(logc),			       "setting up default 'category default'");		}		result = isc_logconfig_use(ns_g_lctx, logc);		if (result != ISC_R_SUCCESS) {			isc_logconfig_destroy(&logc);			CHECKM(result, "installing logging configuration");		}		isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,			      NS_LOGMODULE_SERVER, ISC_LOG_DEBUG(1),			      "now using logging configuration from "			      "config file");	}	/*	 * Set the default value of the query logging flag depending	 * whether a "queries" category has been defined.  This is	 * a disgusting hack, but we need to do this for BIND 8	 * compatibility.	 */	if (first_time) {		cfg_obj_t *logobj = NULL;		cfg_obj_t *categories = NULL;		(void)cfg_map_get(config, "logging", &logobj);		if (logobj != NULL)			(void)cfg_map_get(logobj, "category", &categories);		if (categories != NULL) {			cfg_listelt_t *element;			for (element = cfg_list_first(categories);			     element != NULL;			     element = cfg_list_next(element))			{				cfg_obj_t *catobj;				char *str;				obj = cfg_listelt_value(element);				catobj = cfg_tuple_get(obj, "name");				str = cfg_obj_asstring(catobj);				if (strcasecmp(str, "queries") == 0)					server->log_queries = ISC_TRUE;			}		}	}	obj = NULL;	if (ns_config_get(maps, "pid-file", &obj) == ISC_R_SUCCESS)		ns_os_writepidfile(cfg_obj_asstring(obj), first_time);	else if (ns_g_lwresdonly)		ns_os_writepidfile(lwresd_g_defaultpidfile, first_time);	else		ns_os_writepidfile(ns_g_defaultpidfile, first_time);	obj = NULL;	result = ns_config_get(maps, "statistics-file", &obj);	INSIST(result == ISC_R_SUCCESS);	CHECKM(setstatsfile(server, cfg_obj_asstring(obj)), "strdup");	obj = NULL;	result = ns_config_get(maps, "dump-file", &obj);	INSIST(result == ISC_R_SUCCESS);	CHECKM(setdumpfile(server, cfg_obj_asstring(obj)), "strdup"); cleanup:	ns_aclconfctx_destroy(&aclconfctx);	if (parser != NULL) {		if (config != NULL)			cfg_obj_destroy(parser, &config);		cfg_parser_destroy(&parser);	}	if (view != NULL)		dns_view_detach(&view);	/*	 * This cleans up either the old production view list	 * or our temporary list depending on whether they	 * were swapped above or not.	 */	for (view = ISC_LIST_HEAD(viewlist);	     view != NULL;	     view = view_next) {		view_next = ISC_LIST_NEXT(view, link);		ISC_LIST_UNLINK(viewlist, view, link);		dns_view_detach(&view);	}	if (dispatchv4 != NULL)		dns_dispatch_detach(&dispatchv4);	if (dispatchv6 != NULL)		dns_dispatch_detach(&dispatchv6);	/* Relinquish exclusive access to configuration data. */	isc_task_endexclusive(server->task);	isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,		      ISC_LOG_DEBUG(1), "load_configuration: %s",		      isc_result_totext(result));	return (result);}static isc_result_tload_zones(ns_server_t *server, isc_boolean_t stop) {	isc_result_t result;	dns_view_t *view;	result = isc_task_beginexclusive(server->task);	RUNTIME_CHECK(result == ISC_R_SUCCESS);	/*	 * Load zone data from disk.	 */	for (view = ISC_LIST_HEAD(server->viewlist);	     view != NULL;	     view = ISC_LIST_NEXT(view, link))	{		CHECK(dns_view_load(view, stop));	}	/*	 * Force zone maintenance.  Do this after loading	 * so that we know when we need to force AXFR of	 * slave zones whose master files are missing.	 */	CHECK(dns_zonemgr_forcemaint(server->zonemgr)); cleanup:	isc_task_endexclusive(server->task);		return (result);}static isc_result_tload_new_zones(ns_server_t *server, isc_boolean_t stop) {	isc_result_t result;	dns_view_t *view;	result = isc_task_beginexclusive(server->task);	RUNTIME_CHECK(result == ISC_R_SUCCESS);	/*	 * Load zone data from disk.	 */	for (view = ISC_LIST_HEAD(server->viewlist);	     view != NULL;	     view = ISC_LIST_NEXT(view, link))	{		CHECK(dns_view_loadnew(view, stop));	}	/*	 * Force zone maintenance.  Do this after loading	 * so that we know when we need to force AXFR of	 * slave zones whose master files are missing.	 */	CHECK(dns_zonemgr_forcemaint(server->zonemgr)); cleanup:	isc_task_endexclusive(server->task);		return (result);}static voidrun_server(isc_task_t *task, isc_event_t *event) {	isc_result_t result;	ns_server_t *server = (ns_server_t *)event->ev_arg;	UNUSED(task);	isc_event_free(&event);	CHECKFATAL(dns_dispatchmgr_create(ns_g_mctx, ns_g_entropy,					  &ns_g_dispatchmgr),		   "creating dispatch manager");	CHECKFATAL(ns_interfacemgr_create(ns_g_mctx, ns_g_taskmgr,					  ns_g_socketmgr, ns_g_dispatchmgr,					  &server->interfacemgr),		   "creating interface manager");	CHECKFATAL(isc_timer_create(ns_g_timermgr, isc_timertype_inactive,				    NULL, NULL, server->task,				    interface_timer_tick,				    server, &server->interface_timer),		   "creating interface timer");	CHECKFATAL(isc_timer_create(ns_g_timermgr, isc_timertype_inactive,				    NULL, NULL, server->task,				    heartbeat_timer_tick,				    server, &server->heartbeat_timer),		   "creating heartbeat timer");	CHECKFATAL(cfg_parser_create(ns_g_mctx, NULL, &ns_g_parser),		   "creating default configuration parser");	if (ns_g_lwresdonly)		CHECKFATAL(load_configuration(lwresd_g_conffile, server,					      ISC_TRUE),			   "loading configuration");	else		CHECKFATAL(load_configuration(ns_g_conffile, server, ISC_TRUE),			   "loading configuration");	isc_hash_init();	CHECKFATAL(load_zones(server, ISC_FALSE),		   "loading zones");	isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,		      ISC_LOG_INFO, "running");}void ns_server_flushonshutdown(ns_server_t *server, isc_boolean_t flush) {	REQUIRE(NS_SERVER_VALID(server));	server->flushonshutdown = flush;}static voidshutdown_server(isc_task_t *task, isc_event_t *event) {	isc_result_t result;	dns_view_t *view, *view_next;	ns_server_t *server = (ns_server_t *)event->ev_arg;	isc_boolean_t flush = server->flushonshutdown;	UNUSED(task);	INSIST(task == server->task);	result = isc_task_beginexclusive(server->task);	RUNTIME_CHECK(result == ISC_R_SUCCESS);	isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,		      ISC_LOG_INFO, "shutting down%s",		      flush ? ": flushing changes" : "");	ns_controls_shutdown(server->controls);	cfg_obj_destroy(ns_g_parser, &ns_g_config);	cfg_parser_destroy(&ns_g_parser);	for (view = ISC_LIST_HEAD(server->viewlist);	     view != NULL;	     view = view_next) {		view_next = ISC_LIST_NEXT(view, link);		ISC_LIST_UNLINK(server->viewlist, view, link);		if (flush)			dns_view_flushanddetach(&view);		else			dns_view_detach(&view);	}	isc_timer_detach(&server->interface_timer);	isc_timer_detach(&server->heartbeat_timer);	ns_interfacemgr_shutdown(server->interfacemgr);	ns_interfacemgr_detach(&server->interfacemgr);	dns_dispatchmgr_destroy(&ns_g_dispatchmgr);	dns_zonemgr_shutdown(server->zonemgr);	if (server->blackholeacl != NULL)		dns_acl_detach(&server->blackholeacl);	isc_task_endexclusive(server->task);	isc_task_detach(&server->task);	isc_event_free(&event);}voidns_server_create(isc_mem_t *mctx, ns_server_t **serverp) {	isc_result_t result;	ns_server_t *server = isc_mem_get(mctx, sizeof(*server));	if (server == NULL)		fatal("allocating server object", ISC_R_NOMEMORY);	server->mctx = mctx;	server->task = NULL;	/* Initialize configuration data with default values. */	result = isc_quota_init(&server->xfroutquota, 10);	RUNTIME_CHECK(result == ISC_R_SUCCESS);	result = isc_quota_init(&server->tcpquota, 10);	RUNTIME_CHECK(result == ISC_R_SUCCESS);	result = isc_quota_init(&server->recursionquota, 100);	RUNTIME_CHECK(result == ISC_R_SUCCESS);	result = dns_aclenv_init(mctx, &server->aclenv);	RUNTIME_CHECK(result == ISC_R_SUCCESS);	/* Initialize server data structures. */	server->zonemgr = NULL;	server->interfacemgr = NULL;	ISC_LIST_INIT(server->viewlist);	server->in_roothints = NULL;	server->blackholeacl = NULL;	CHECKFATAL(dns_rootns_create(mctx, dns_rdataclass_in, NULL,				     &server->in_roothints),		   "setting up root hints");	CHECKFATAL(isc_mutex_init(&server->reload_event_lock),		   "initializing reload event lock");	server->reload_event =		isc_event_allocate(ns_g_mctx, server,				   NS_EVENT_RELOAD,				   ns_server_reload,				   server,				   sizeof(isc_event_t));	CHECKFATAL(server->reload_event == NULL ?		   ISC_R_NOMEMORY : ISC_R_SUCCESS,		   "allocating reload event");	CHECKFATAL(dst_lib_init(ns_g_mctx, ns_g_entropy, ISC_ENTROPY_GOODONLY),		   "initializing DST");	server->tkeyctx = NULL;	CHECKFATAL(dns_tkeyctx_create(ns_g_mctx, ns_g_entropy,				      &server->tkeyctx),		   "creating TKEY context");	/*	 * Setup the server task, which is responsible for coordinating	 * startup and shutdown of the server.	 */	CHECKFATAL(isc_task_create(ns_g_taskmgr, 0, &server->task),		   "creating server task");	isc_task_setname(server->task, "server", server);	CHECKFATAL(isc_task_onshutdown(server->task, shutdown_server, server),		   "isc_task_onshutdown");	CHECKFATAL(isc_app_onrun(ns_g_mctx, server->task, run_server, server),		   "isc_app_onrun");	server->interface_timer = NULL;	server->heartbeat_timer = NULL;		server->interface_interval = 0;	server->heartbeat_interval = 0;	CHECKFATAL(dns_zonemgr_create(ns_g_mctx, ns_g_taskmgr, ns_g_timermgr,				      ns_g_socketmgr, &server->zonemgr),		   "dns_zonemgr_create");	server->statsfile = isc_mem_strdup(server->mctx, "named.stats");	CHECKFATAL(server->statsf

⌨️ 快捷键说明

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