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

📄 config.c

📁 bind 9.3结合mysql数据库
💻 C
📖 第 1 页 / 共 2 页
字号:
	}	INSIST(i == count);	*addrsp = addrs;	*countp = count;	return (ISC_R_SUCCESS);}voidns_config_putiplist(isc_mem_t *mctx, isc_sockaddr_t **addrsp,		    isc_uint32_t count){	INSIST(addrsp != NULL && *addrsp != NULL);	isc_mem_put(mctx, *addrsp, count * sizeof(isc_sockaddr_t));	*addrsp = NULL;}static isc_result_tget_masters_def(cfg_obj_t *cctx, char *name, cfg_obj_t **ret) {	isc_result_t result;	cfg_obj_t *masters = NULL;	cfg_listelt_t *elt;	result = cfg_map_get(cctx, "masters", &masters);	if (result != ISC_R_SUCCESS)		return (result);	for (elt = cfg_list_first(masters);	     elt != NULL;	     elt = cfg_list_next(elt)) {		cfg_obj_t *list;		const char *listname;		list = cfg_listelt_value(elt);		listname = cfg_obj_asstring(cfg_tuple_get(list, "name"));		if (strcasecmp(listname, name) == 0) {			*ret = list;			return (ISC_R_SUCCESS);		}	}	return (ISC_R_NOTFOUND);}isc_result_tns_config_getipandkeylist(cfg_obj_t *config, cfg_obj_t *list, isc_mem_t *mctx,			  isc_sockaddr_t **addrsp, dns_name_t ***keysp,			  isc_uint32_t *countp){	isc_uint32_t addrcount = 0, keycount = 0, i = 0;	isc_uint32_t listcount = 0, l = 0, j;	isc_uint32_t stackcount = 0, pushed = 0;	isc_result_t result;	cfg_listelt_t *element;	cfg_obj_t *addrlist;	cfg_obj_t *portobj;	in_port_t port;	dns_fixedname_t fname;	isc_sockaddr_t *addrs = NULL;	dns_name_t **keys = NULL;	char **lists = NULL;	struct {		cfg_listelt_t *element;		in_port_t port;	} *stack = NULL;	REQUIRE(addrsp != NULL && *addrsp == NULL);	REQUIRE(keysp != NULL && *keysp == NULL);	REQUIRE(countp != NULL); newlist:	addrlist = cfg_tuple_get(list, "addresses");	portobj = cfg_tuple_get(list, "port");	if (cfg_obj_isuint32(portobj)) {		isc_uint32_t val = cfg_obj_asuint32(portobj);		if (val > ISC_UINT16_MAX) {			cfg_obj_log(portobj, ns_g_lctx, ISC_LOG_ERROR,				    "port '%u' out of range", val);			return (ISC_R_RANGE);		}		port = (in_port_t) val;	} else {		result = ns_config_getport(config, &port);		if (result != ISC_R_SUCCESS)			return (result);	}	result = ISC_R_NOMEMORY;	element = cfg_list_first(addrlist); resume:	for ( ;	     element != NULL;	     element = cfg_list_next(element))	{		cfg_obj_t *addr;		cfg_obj_t *key;		char *keystr;		isc_buffer_t b;		addr = cfg_tuple_get(cfg_listelt_value(element),				     "masterselement");		key = cfg_tuple_get(cfg_listelt_value(element), "key");		if (!cfg_obj_issockaddr(addr)) {			char *listname = cfg_obj_asstring(addr);			isc_result_t tresult;			/* Grow lists? */			if (listcount == l) {				void * new;				isc_uint32_t newlen = listcount + 16;				size_t newsize, oldsize;				newsize = newlen * sizeof(*lists);				oldsize = listcount * sizeof(*lists);				new = isc_mem_get(mctx, newsize);				if (new == NULL)					goto cleanup;				if (listcount != 0) {					memcpy(new, lists, oldsize);					isc_mem_put(mctx, lists, oldsize);				}				lists = new;				listcount = newlen;			}			/* Seen? */			for (j = 0; j < l; j++)				if (strcasecmp(lists[j], listname) == 0)					break;			if (j < l)				continue;			tresult = get_masters_def(config, listname, &list);			if (tresult == ISC_R_NOTFOUND) {				cfg_obj_log(addr, ns_g_lctx, ISC_LOG_ERROR,                                    "masters \"%s\" not found", listname);				result = tresult;				goto cleanup;			}			if (tresult != ISC_R_SUCCESS)				goto cleanup;			lists[l++] = listname;			/* Grow stack? */			if (stackcount == pushed) {				void * new;				isc_uint32_t newlen = stackcount + 16;				size_t newsize, oldsize;				newsize = newlen * sizeof(*stack);				oldsize = stackcount * sizeof(*stack);				new = isc_mem_get(mctx, newsize);				if (new == NULL)					goto cleanup;				if (stackcount != 0) {					memcpy(new, stack, oldsize);					isc_mem_put(mctx, stack, oldsize);				}				stack = new;				stackcount = newlen;			}			/*			 * We want to resume processing this list on the			 * next element.			 */			stack[pushed].element = cfg_list_next(element);			stack[pushed].port = port;			pushed++;			goto newlist;		}		if (i == addrcount) {			void * new;			isc_uint32_t newlen = addrcount + 16;			size_t newsize, oldsize;			newsize = newlen * sizeof(isc_sockaddr_t);			oldsize = addrcount * sizeof(isc_sockaddr_t);			new = isc_mem_get(mctx, newsize);			if (new == NULL)				goto cleanup;			if (addrcount != 0) {				memcpy(new, addrs, oldsize);				isc_mem_put(mctx, addrs, oldsize);			}			addrs = new;			addrcount = newlen;			newsize = newlen * sizeof(dns_name_t *);			oldsize = keycount * sizeof(dns_name_t *);			new = isc_mem_get(mctx, newsize);			if (new == NULL)				goto cleanup;			if (keycount != 0) {				memcpy(new, keys, newsize);				isc_mem_put(mctx, keys, newsize);			}			keys = new;			keycount = newlen;		}		addrs[i] = *cfg_obj_assockaddr(addr);		if (isc_sockaddr_getport(&addrs[i]) == 0)			isc_sockaddr_setport(&addrs[i], port);		keys[i] = NULL;		if (!cfg_obj_isstring(key)) {			i++;			continue;		}		keys[i] = isc_mem_get(mctx, sizeof(dns_name_t));		if (keys[i] == NULL)			goto cleanup;		dns_name_init(keys[i], NULL);				keystr = cfg_obj_asstring(key);		isc_buffer_init(&b, keystr, strlen(keystr));		isc_buffer_add(&b, strlen(keystr));		dns_fixedname_init(&fname);		result = dns_name_fromtext(dns_fixedname_name(&fname), &b,					   dns_rootname, ISC_FALSE, NULL);		if (result != ISC_R_SUCCESS)			goto cleanup;		result = dns_name_dup(dns_fixedname_name(&fname), mctx,				      keys[i]);		if (result != ISC_R_SUCCESS)			goto cleanup;		i++;	}	if (pushed != 0) {		pushed--;		element = stack[pushed].element;		port = stack[pushed].port;		goto resume;	}	if (i < addrcount) {		void * new;		size_t newsize, oldsize;		newsize = i * sizeof(isc_sockaddr_t);		oldsize = addrcount * sizeof(isc_sockaddr_t);		if (i != 0) {			new = isc_mem_get(mctx, newsize);			if (new == NULL)				goto cleanup;			memcpy(new, addrs, newsize);			isc_mem_put(mctx, addrs, oldsize);		} else			new = NULL;		addrs = new;		addrcount = i;		newsize = i * sizeof(dns_name_t *);		oldsize = keycount * sizeof(dns_name_t *);		if (i != 0) {			new = isc_mem_get(mctx, newsize);			if (new == NULL)				goto cleanup;			memcpy(new, keys,  newsize);			isc_mem_put(mctx, keys, oldsize);		} else			new = NULL;		keys = new;		keycount = i;	}	if (lists != NULL)		isc_mem_put(mctx, lists, listcount * sizeof(*lists));	if (stack != NULL)		isc_mem_put(mctx, stack, stackcount * sizeof(*stack));		INSIST(keycount == addrcount);	*addrsp = addrs;	*keysp = keys;	*countp = addrcount;	return (ISC_R_SUCCESS); cleanup:	if (addrs != NULL)		isc_mem_put(mctx, addrs, addrcount * sizeof(isc_sockaddr_t));	if (keys != NULL) {		for (j = 0; j <= i; j++) {			if (keys[j] == NULL)				continue;			if (dns_name_dynamic(keys[j]))				dns_name_free(keys[j], mctx);			isc_mem_put(mctx, keys[j], sizeof(dns_name_t));		}		isc_mem_put(mctx, keys, keycount * sizeof(dns_name_t *));	}	if (lists != NULL)		isc_mem_put(mctx, lists, listcount * sizeof(*lists));	if (stack != NULL)		isc_mem_put(mctx, stack, stackcount * sizeof(*stack));	return (result);}voidns_config_putipandkeylist(isc_mem_t *mctx, isc_sockaddr_t **addrsp,			  dns_name_t ***keysp, isc_uint32_t count){	unsigned int i;	dns_name_t **keys = *keysp;	INSIST(addrsp != NULL && *addrsp != NULL);	isc_mem_put(mctx, *addrsp, count * sizeof(isc_sockaddr_t));	for (i = 0; i < count; i++) {		if (keys[i] == NULL)			continue;		if (dns_name_dynamic(keys[i]))			dns_name_free(keys[i], mctx);		isc_mem_put(mctx, keys[i], sizeof(dns_name_t));	}	isc_mem_put(mctx, *keysp, count * sizeof(dns_name_t *));	*addrsp = NULL;	*keysp = NULL;}isc_result_tns_config_getport(cfg_obj_t *config, in_port_t *portp) {	cfg_obj_t *maps[3];	cfg_obj_t *options = NULL;	cfg_obj_t *portobj = NULL;	isc_result_t result;	int i;	(void)cfg_map_get(config, "options", &options);	i = 0;	if (options != NULL)		maps[i++] = options;	maps[i++] = ns_g_defaults;	maps[i] = NULL;	result = ns_config_get(maps, "port", &portobj);	INSIST(result == ISC_R_SUCCESS);	if (cfg_obj_asuint32(portobj) >= ISC_UINT16_MAX) {		cfg_obj_log(portobj, ns_g_lctx, ISC_LOG_ERROR,			    "port '%u' out of range",			    cfg_obj_asuint32(portobj));		return (ISC_R_RANGE);	}	*portp = (in_port_t)cfg_obj_asuint32(portobj);	return (ISC_R_SUCCESS);}isc_result_tns_config_getkeyalgorithm(const char *str, dns_name_t **name){	if (strcasecmp(str, "hmac-md5") == 0 ||	    strcasecmp(str, "hmac-md5.sig-alg.reg.int") == 0 ||	    strcasecmp(str, "hmac-md5.sig-alg.reg.int.") == 0)	{		if (name != NULL)			*name = dns_tsig_hmacmd5_name;		return (ISC_R_SUCCESS);	}	return (ISC_R_NOTFOUND);}

⌨️ 快捷键说明

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