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

📄 zoneconf.c

📁 bind 9.3结合mysql数据库
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1999-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: zoneconf.c,v 1.87.2.4.10.13 2004/04/20 14:12:09 marka Exp $ */#include <config.h>#include <isc/buffer.h>#include <isc/file.h>#include <isc/mem.h>#include <isc/print.h>#include <isc/string.h>		/* Required for HP/UX (and others?) */#include <isc/util.h>#include <dns/acl.h>#include <dns/fixedname.h>#include <dns/log.h>#include <dns/name.h>#include <dns/rdatatype.h>#include <dns/ssu.h>#include <dns/view.h>#include <dns/zone.h>#include <named/config.h>#include <named/globals.h>#include <named/log.h>#include <named/server.h>#include <named/zoneconf.h>/* * These are BIND9 server defaults, not necessarily identical to the * library defaults defined in zone.c. */#define RETERR(x) do { \	isc_result_t _r = (x); \	if (_r != ISC_R_SUCCESS) \		return (_r); \	} while (0)/* * Convenience function for configuring a single zone ACL. */static isc_result_tconfigure_zone_acl(cfg_obj_t *zconfig, cfg_obj_t *vconfig, cfg_obj_t *config,		   const char *aclname, ns_aclconfctx_t *actx,		   dns_zone_t *zone, 		   void (*setzacl)(dns_zone_t *, dns_acl_t *),		   void (*clearzacl)(dns_zone_t *)){	isc_result_t result;	cfg_obj_t *maps[4];	cfg_obj_t *aclobj = NULL;	int i = 0;	dns_acl_t *dacl = NULL;	if (zconfig != NULL)		maps[i++] = cfg_tuple_get(zconfig, "options");	if (vconfig != NULL)		maps[i++] = cfg_tuple_get(vconfig, "options");	if (config != NULL) {		cfg_obj_t *options = NULL;		(void)cfg_map_get(config, "options", &options);		if (options != NULL)			maps[i++] = options;	}	maps[i] = NULL;	result = ns_config_get(maps, aclname, &aclobj);	if (aclobj == NULL) {		(*clearzacl)(zone);		return (ISC_R_SUCCESS);	}	result = ns_acl_fromconfig(aclobj, config, actx,				   dns_zone_getmctx(zone), &dacl);	if (result != ISC_R_SUCCESS)		return (result);	(*setzacl)(zone, dacl);	dns_acl_detach(&dacl);	return (ISC_R_SUCCESS);}/* * Parse the zone update-policy statement. */static isc_result_tconfigure_zone_ssutable(cfg_obj_t *zconfig, dns_zone_t *zone) {	cfg_obj_t *updatepolicy = NULL;	cfg_listelt_t *element, *element2;	dns_ssutable_t *table = NULL;	isc_mem_t *mctx = dns_zone_getmctx(zone);	isc_result_t result;	(void)cfg_map_get(zconfig, "update-policy", &updatepolicy);	if (updatepolicy == NULL)		return (ISC_R_SUCCESS);	result = dns_ssutable_create(mctx, &table);	if (result != ISC_R_SUCCESS)		return (result);	for (element = cfg_list_first(updatepolicy);	     element != NULL;	     element = cfg_list_next(element))	{		cfg_obj_t *stmt = cfg_listelt_value(element);		cfg_obj_t *mode = cfg_tuple_get(stmt, "mode");		cfg_obj_t *identity = cfg_tuple_get(stmt, "identity");		cfg_obj_t *matchtype = cfg_tuple_get(stmt, "matchtype");		cfg_obj_t *dname = cfg_tuple_get(stmt, "name");		cfg_obj_t *typelist = cfg_tuple_get(stmt, "types");		char *str;		isc_boolean_t grant = ISC_FALSE;		unsigned int mtype = DNS_SSUMATCHTYPE_NAME;		dns_fixedname_t fname, fident;		isc_buffer_t b;		dns_rdatatype_t *types;		unsigned int i, n;		str = cfg_obj_asstring(mode);		if (strcasecmp(str, "grant") == 0)			grant = ISC_TRUE;		else if (strcasecmp(str, "deny") == 0)			grant = ISC_FALSE;		else			INSIST(0);		str = cfg_obj_asstring(matchtype);		if (strcasecmp(str, "name") == 0)			mtype = DNS_SSUMATCHTYPE_NAME;		else if (strcasecmp(str, "subdomain") == 0)			mtype = DNS_SSUMATCHTYPE_SUBDOMAIN;		else if (strcasecmp(str, "wildcard") == 0)			mtype = DNS_SSUMATCHTYPE_WILDCARD;		else if (strcasecmp(str, "self") == 0)			mtype = DNS_SSUMATCHTYPE_SELF;		else			INSIST(0);		dns_fixedname_init(&fident);		str = cfg_obj_asstring(identity);		isc_buffer_init(&b, str, strlen(str));		isc_buffer_add(&b, strlen(str));		result = dns_name_fromtext(dns_fixedname_name(&fident), &b,					   dns_rootname, ISC_FALSE, NULL);		if (result != ISC_R_SUCCESS) {			cfg_obj_log(identity, ns_g_lctx, ISC_LOG_ERROR,				    "'%s' is not a valid name", str);			goto cleanup;		}		dns_fixedname_init(&fname);		str = cfg_obj_asstring(dname);		isc_buffer_init(&b, str, strlen(str));		isc_buffer_add(&b, strlen(str));		result = dns_name_fromtext(dns_fixedname_name(&fname), &b,					   dns_rootname, ISC_FALSE, NULL);		if (result != ISC_R_SUCCESS) {			cfg_obj_log(identity, ns_g_lctx, ISC_LOG_ERROR,				    "'%s' is not a valid name", str);			goto cleanup;		}		n = ns_config_listcount(typelist);		if (n == 0)			types = NULL;		else {			types = isc_mem_get(mctx, n * sizeof(dns_rdatatype_t));			if (types == NULL) {				result = ISC_R_NOMEMORY;				goto cleanup;			}		}		i = 0;		for (element2 = cfg_list_first(typelist);		     element2 != NULL;		     element2 = cfg_list_next(element2))		{			cfg_obj_t *typeobj;			isc_textregion_t r;			INSIST(i < n);			typeobj = cfg_listelt_value(element2);			str = cfg_obj_asstring(typeobj);			r.base = str;			r.length = strlen(str);			result = dns_rdatatype_fromtext(&types[i++], &r);			if (result != ISC_R_SUCCESS) {				cfg_obj_log(identity, ns_g_lctx, ISC_LOG_ERROR,					    "'%s' is not a valid type", str);				isc_mem_put(mctx, types,					    n * sizeof(dns_rdatatype_t));				goto cleanup;			}		}		INSIST(i == n);		result = dns_ssutable_addrule(table, grant,					      dns_fixedname_name(&fident),					      mtype,					      dns_fixedname_name(&fname),					      n, types);		if (types != NULL)			isc_mem_put(mctx, types, n * sizeof(dns_rdatatype_t));		if (result != ISC_R_SUCCESS) {			goto cleanup;		}	}	result = ISC_R_SUCCESS;	dns_zone_setssutable(zone, table); cleanup:	dns_ssutable_detach(&table);	return (result);}/* * Convert a config file zone type into a server zone type. */static inline dns_zonetype_tzonetype_fromconfig(cfg_obj_t *map) {	cfg_obj_t *obj = NULL;	isc_result_t result;	result = cfg_map_get(map, "type", &obj);	INSIST(result == ISC_R_SUCCESS);	return (ns_config_getzonetype(obj));}/* * Helper function for strtoargv().  Pardon the gratuitous recursion. */static isc_result_tstrtoargvsub(isc_mem_t *mctx, char *s, unsigned int *argcp,	     char ***argvp, unsigned int n){	isc_result_t result;		/* Discard leading whitespace. */	while (*s == ' ' || *s == '\t')		s++;		if (*s == '\0') {		/* We have reached the end of the string. */		*argcp = n;		*argvp = isc_mem_get(mctx, n * sizeof(char *));		if (*argvp == NULL)			return (ISC_R_NOMEMORY);	} else {		char *p = s;		while (*p != ' ' && *p != '\t' && *p != '\0')			p++;		if (*p != '\0')			*p++ = '\0';		result = strtoargvsub(mctx, p, argcp, argvp, n + 1);		if (result != ISC_R_SUCCESS)			return (result);		(*argvp)[n] = s;	}	return (ISC_R_SUCCESS);}/* * Tokenize the string "s" into whitespace-separated words, * return the number of words in '*argcp' and an array * of pointers to the words in '*argvp'.  The caller * must free the array using isc_mem_put().  The string * is modified in-place. */static isc_result_tstrtoargv(isc_mem_t *mctx, char *s, unsigned int *argcp, char ***argvp) {	return (strtoargvsub(mctx, s, argcp, argvp, 0));}static voidchecknames(dns_zonetype_t ztype, cfg_obj_t **maps, cfg_obj_t **objp) {	const char *zone = NULL;	isc_result_t result;	switch (ztype) {	case dns_zone_slave: zone = "slave"; break;	case dns_zone_master: zone = "master"; break;	default:		INSIST(0);	}	result = ns_checknames_get(maps, zone, objp);	INSIST(result == ISC_R_SUCCESS);}isc_result_tns_zone_configure(cfg_obj_t *config, cfg_obj_t *vconfig, cfg_obj_t *zconfig,		  ns_aclconfctx_t *ac, dns_zone_t *zone){	isc_result_t result;	char *zname;	dns_rdataclass_t zclass;	dns_rdataclass_t vclass;	cfg_obj_t *maps[5];	cfg_obj_t *zoptions = NULL;	cfg_obj_t *options = NULL;	cfg_obj_t *obj;	const char *filename = NULL;	dns_notifytype_t notifytype = dns_notifytype_yes;	isc_sockaddr_t *addrs;	dns_name_t **keynames;	isc_uint32_t count;	char *cpval;	unsigned int dbargc;	char **dbargv;	static char default_dbtype[] = "rbt";	isc_mem_t *mctx = dns_zone_getmctx(zone);	dns_dialuptype_t dialup = dns_dialuptype_no;	dns_zonetype_t ztype;	int i;	isc_int32_t journal_size;	isc_boolean_t multi;	isc_boolean_t alt;	dns_view_t *view;	isc_boolean_t check = ISC_FALSE, fail = ISC_FALSE;	i = 0;	if (zconfig != NULL) {		zoptions = cfg_tuple_get(zconfig, "options");		maps[i++] = zoptions;	}	if (vconfig != NULL)		maps[i++] = cfg_tuple_get(vconfig, "options");	if (config != NULL) {		(void)cfg_map_get(config, "options", &options);		if (options != NULL)			maps[i++] = options;	}	maps[i++] = ns_g_defaults;	maps[i++] = NULL;	if (vconfig != NULL)		RETERR(ns_config_getclass(cfg_tuple_get(vconfig, "class"),					  dns_rdataclass_in, &vclass));	else		vclass = dns_rdataclass_in;	/*	 * Configure values common to all zone types.	 */

⌨️ 快捷键说明

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