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

📄 t_db.c

📁 bind-3.2.
💻 C
📖 第 1 页 / 共 5 页
字号:
	"to point to the node and returns ISC_R_SUCCESS, otherwise "	"it returns ISC_R_NOTFOUND.";static intt_dns_db_findnode_1(char **av) {	char		*filename;	char		*db_type;	char		*origin;	char		*class;	char		*model;	char		*find_name;	char		*find_type;	char		*expected_result;	int			result;	int			len;	dns_db_t		*db;	isc_result_t		dns_result;	isc_result_t		isc_result;	isc_mem_t		*mctx;	dns_dbnode_t		*nodep;	isc_buffer_t		name_buffer;	dns_rdataset_t		rdataset;	dns_rdatatype_t		rdatatype;	isc_textregion_t	textregion;	dns_fixedname_t		dns_name;	dns_dbversion_t		*cversionp;	isc_result_t		exp_result;	filename = T_ARG(0);	db_type = T_ARG(1);	origin = T_ARG(2);	class = T_ARG(3);	model = T_ARG(4);	find_name = T_ARG(5);	find_type = T_ARG(6);	expected_result = T_ARG(7);	db = NULL;	mctx = NULL;	result = T_UNRESOLVED;	t_info("testing using file %s and name %s\n", filename, find_name);	exp_result = t_dns_result_fromtext(expected_result);	textregion.base = find_type;	textregion.length = strlen(find_type);	dns_result = dns_rdatatype_fromtext(&rdatatype, &textregion);	if (dns_result != ISC_R_SUCCESS) {		t_info("dns_rdatatype_fromtext %s failed %s\n",				find_type,				dns_result_totext(dns_result));		return(T_UNRESOLVED);	}	isc_result = isc_mem_create(0, 0, &mctx);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_mem_create failed %s\n",				isc_result_totext(isc_result));		return(T_UNRESOLVED);	}	dns_result = t_create(db_type, origin, class, model, mctx, &db);	if (dns_result != ISC_R_SUCCESS) {		isc_mem_destroy(&mctx);		return(T_UNRESOLVED);	}	dns_result = dns_db_load(db, filename);	if (dns_result != ISC_R_SUCCESS) {		t_info("dns_db_load returned %s\n",				dns_result_totext(dns_result));		dns_db_detach(&db);		isc_mem_destroy(&mctx);		return(T_UNRESOLVED);	}	nodep = NULL;	dns_fixedname_init(&dns_name);	len = strlen(find_name);	isc_buffer_init(&name_buffer, find_name, len);	isc_buffer_add(&name_buffer, len);	dns_result = dns_name_fromtext(dns_fixedname_name(&dns_name),				&name_buffer, NULL, ISC_FALSE, NULL);	dns_result = dns_db_findnode(db, dns_fixedname_name(&dns_name),				ISC_FALSE, &nodep);	if (dns_result != exp_result) {		t_info("dns_db_findnode failed %s\n",				dns_result_totext(dns_result));		if (dns_result == ISC_R_SUCCESS)			dns_db_detachnode(db, &nodep);		dns_db_detach(&db);		isc_mem_destroy(&mctx);		return(T_FAIL);	}	/*	 * if we're expecting the find to succeed and it did,	 * check that the node has been initialized	 * by checking for the specified type of rdata	 * and expecting the search to succeed	 */	if (dns_result == ISC_R_SUCCESS) {		cversionp = NULL;		dns_db_currentversion(db, &cversionp);		dns_rdataset_init(&rdataset);		dns_result = dns_db_findrdataset(db, nodep, cversionp,						 rdatatype, 0,						 0, &rdataset, NULL);		if (dns_result == ISC_R_SUCCESS) {			dns_rdataset_disassociate(&rdataset);			result = T_PASS;		} else {			t_info("dns_db_findrdataset failed %s\n",					dns_result_totext(dns_result));			result = T_FAIL;		}		dns_db_closeversion(db, &cversionp, ISC_FALSE);		dns_db_detachnode(db, &nodep);	} else {		result = T_PASS;	}	dns_db_detach(&db);	isc_mem_destroy(&mctx);	return(result);}static voidt13(void) {	int	result;	t_assert("dns_db_findnode", 13, T_REQUIRED, a13);	result = t_eval("dns_db_findnode_1_data", t_dns_db_findnode_1, 8);	t_result(result);}static const char *a14 =	"If the node name does not exist and create is ISC_TRUE, "	"then a call to dns_db_findnode(db, name, create, nodep) "	"creates the node, initializes nodep to point to the node, "	"and returns ISC_R_SUCCESS.";static intt_dns_db_findnode_2(char **av) {	char			*filename;	char			*db_type;	char			*origin;	char			*class;	char			*model;	char			*newname;	int			nfails;	int			result;	int			len;	dns_db_t		*db;	isc_result_t		dns_result;	isc_result_t		isc_result;	isc_mem_t		*mctx;	dns_dbnode_t		*nodep;	dns_dbnode_t		*newnodep;	isc_buffer_t		name_buffer;	dns_rdataset_t		rdataset;	dns_fixedname_t		dns_name;	dns_fixedname_t		dns_foundname;	dns_dbversion_t		*cversionp;	filename = T_ARG(0);	db_type = T_ARG(1);	origin = T_ARG(2);	class = T_ARG(3);	model = T_ARG(4);	newname = T_ARG(5);	result = T_UNRESOLVED;	db = NULL;	mctx = NULL;	nfails = 0;	t_info("testing using file %s and name %s\n", filename, newname);	isc_result = isc_mem_create(0, 0, &mctx);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_mem_create failed %s\n",				isc_result_totext(isc_result));		return(T_UNRESOLVED);	}	dns_result = t_create(db_type, origin, class, model, mctx, &db);	if (dns_result != ISC_R_SUCCESS) {		isc_mem_destroy(&mctx);		return(T_UNRESOLVED);	}	dns_result = dns_db_load(db, filename);	if (dns_result != ISC_R_SUCCESS) {		t_info("dns_db_load returned %s\n",				dns_result_totext(dns_result));		dns_db_detach(&db);		isc_mem_destroy(&mctx);		return(T_UNRESOLVED);	}	nodep = NULL;	dns_fixedname_init(&dns_name);	/*	 * Make sure the name isn't there	 */	len = strlen(newname);	isc_buffer_init(&name_buffer, newname, len);	isc_buffer_add(&name_buffer, len);	dns_result = dns_name_fromtext(dns_fixedname_name(&dns_name),				       &name_buffer, NULL, ISC_FALSE, NULL);	dns_result = dns_db_findnode(db, dns_fixedname_name(&dns_name),				     ISC_FALSE, &nodep);	if ((dns_result != ISC_R_NOTFOUND) &&	    (dns_result != DNS_R_NXDOMAIN) &&	    (dns_result != DNS_R_NXRRSET)) {		t_info("dns_db_findnode %s\n",		       dns_result_totext(dns_result));		dns_db_detachnode(db, &nodep);		dns_db_detach(&db);		isc_mem_destroy(&mctx);		return(T_UNRESOLVED);	}	/*	 * Add it.	 */	dns_result = dns_db_findnode(db, dns_fixedname_name(&dns_name),				ISC_TRUE, &nodep);	if (dns_result != ISC_R_SUCCESS) {		t_info("dns_db_findnode %s\n",				dns_result_totext(dns_result));		dns_db_detach(&db);		isc_mem_destroy(&mctx);		return(T_FAIL);	}	/*	 * Check it.	 */	newnodep = NULL;	dns_rdataset_init(&rdataset);	dns_fixedname_init(&dns_foundname);	cversionp = NULL;	dns_db_currentversion(db, &cversionp);	/*	 * First try dns_db_find DNS_R_NXDOMAIN.	 */	dns_result = dns_db_find(db,			dns_fixedname_name(&dns_name),			cversionp,			dns_rdatatype_any,			0,			0,			&newnodep,			dns_fixedname_name(&dns_foundname),			&rdataset, NULL);	if ((dns_result != ISC_R_NOTFOUND) && (dns_result != DNS_R_NXDOMAIN)) {		dns_db_detachnode(db, &newnodep);	}	if (dns_result != DNS_R_NXDOMAIN) {		t_info("dns_db_find %s\n",				dns_result_totext(dns_result));		++nfails;	}	/*	 * Then try dns_db_findnode ISC_R_SUCCESS.	 */	dns_result = dns_db_findnode(db, dns_fixedname_name(&dns_name),				     ISC_FALSE, &newnodep);	t_info("dns_db_findnode %s\n", dns_result_totext(dns_result));	if (dns_result == ISC_R_SUCCESS) {		dns_db_detachnode(db, &newnodep);	} else {		t_info("dns_db_findnode %s failed %s\n", newname,				dns_result_totext(dns_result));		++nfails;	}	dns_db_detachnode(db, &nodep);	dns_db_closeversion(db, &cversionp, ISC_FALSE);	dns_db_detach(&db);	isc_mem_destroy(&mctx);	if (nfails == 0)		result = T_PASS;	else		result = T_FAIL;	return(result);}static voidt14(void) {	int	result;	t_assert("dns_db_findnode", 14, T_REQUIRED, a14);	result = t_eval("dns_db_findnode_2_data", t_dns_db_findnode_2, 6);	t_result(result);}static intt_dns_db_find_x(char **av) {	char			*dbfile;	char			*dbtype;	char			*dborigin;	char			*dbclass;	char			*dbmodel;	char			*findname;	char			*findtype;	char			*findopts;	char			*findtime;	char			*expected_result;	int			result;	int			len;	int			opts;	dns_db_t		*db;	isc_result_t		dns_result;	isc_result_t		isc_result;	isc_stdtime_t		ftime;	isc_stdtime_t		now;	isc_result_t		exp_result;	isc_mem_t		*mctx;	dns_dbnode_t		*nodep;	isc_textregion_t	textregion;	isc_buffer_t		findname_buffer;	dns_fixedname_t		dns_findname;	dns_fixedname_t		dns_foundname;	dns_rdataset_t		rdataset;	dns_rdatatype_t		rdatatype;	dns_dbversion_t		*cversionp;	result = T_UNRESOLVED;	dbfile = T_ARG(0);	dbtype = T_ARG(1);	dborigin = T_ARG(2);	dbclass = T_ARG(3);	dbmodel = T_ARG(4);	findname = T_ARG(5);	findtype = T_ARG(6);	findopts = T_ARG(7);	findtime = T_ARG(8);	expected_result = T_ARG(9);	db = NULL;	mctx = NULL;	opts = 0;	t_info("testing using %s, name %s, type %s\n", dbfile, findname,	       findtype);	isc_result = isc_mem_create(0, 0, &mctx);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_mem_create failed %s\n",				isc_result_totext(isc_result));		return(T_UNRESOLVED);	}	dns_result = t_create(dbtype, dborigin, dbclass, dbmodel, mctx, &db);	if (dns_result != ISC_R_SUCCESS) {		isc_mem_destroy(&mctx);		return(T_UNRESOLVED);	}	dns_result = dns_db_load(db, dbfile);	if (dns_result != ISC_R_SUCCESS) {		t_info("dns_db_load returned %s\n",				dns_result_totext(dns_result));		dns_db_detach(&db);		isc_mem_destroy(&mctx);		return(T_UNRESOLVED);	}	exp_result = t_dns_result_fromtext(expected_result);	dns_fixedname_init(&dns_findname);	len = strlen(findname);	isc_buffer_init(&findname_buffer, findname, len);	isc_buffer_add(&findname_buffer, len);	dns_result = dns_name_fromtext(dns_fixedname_name(&dns_findname),				&findname_buffer, NULL, ISC_FALSE, NULL);	if (dns_result != ISC_R_SUCCESS) {		t_info("dns_name_fromtext failed %s\n",			dns_result_totext(dns_result));		dns_db_detach(&db);		isc_mem_destroy(&mctx);		return(T_UNRESOLVED);	}	textregion.base = findtype;	textregion.length = strlen(findtype);	dns_result = dns_rdatatype_fromtext(&rdatatype, &textregion);	if (dns_result != ISC_R_SUCCESS) {		t_info("dns_rdatatype_fromtext %s failed %s\n",				findtype,				dns_result_totext(dns_result));		dns_db_detach(&db);		isc_mem_destroy(&mctx);		return(T_UNRESOLVED);	}	if (strstr(findopts, "DNS_DBFIND_GLUEOK"))		opts |= DNS_DBFIND_GLUEOK;	if (strstr(findopts, "DNS_DBFIND_VALIDATEGLUE"))		opts |= DNS_DBFIND_VALIDATEGLUE;	isc_stdtime_get(&now);	ftime = strtol(findtime, NULL, 10);	if (ftime != 0)		ftime += now;	cversionp = NULL;	dns_fixedname_init(&dns_foundname);	dns_rdataset_init(&rdataset);	if (dns_db_iszone(db))		dns_db_currentversion(db, &cversionp);	nodep = NULL;	dns_result = dns_db_find(db,			dns_fixedname_name(&dns_findname),			cversionp,			rdatatype,			opts,			ftime,			&nodep,			dns_fixedname_name(&dns_foundname),			&rdataset, NULL);	if (dns_result != exp_result) {		t_info("dns_db_find %s %s unexpectedly returned %s, "		       "expected %s\n",		       findname, findtype, dns_result_totext(dns_result),		       dns_result_totext(exp_result));		result = T_FAIL;	} else {		result = T_PASS;	}	if ((dns_result != ISC_R_NOTFOUND) && (dns_result != DNS_R_NXDOMAIN)) {		if ((dns_result != DNS_R_NXRRSET) &&		    (dns_result != DNS_R_ZONECUT))			if (dns_rdataset_isassociated(&rdataset))				dns_rdataset_disassociate(&rdataset);		dns_db_detachnode(db, &nodep);	}	if (dns_db_iszone(db))		dns_db_closeversion(db, &cversionp, ISC_FALSE);	dns_db_detach(&db);	isc_mem_destroy(&mctx);	return(result);}static const char *a15 =	"A call to dns_db_find(db, name, version, type, options, now, ...)  "	"finds the best match for 'name' and 'type' in version 'version' "	"of 'db'.";static voidt15(void) {	int	result;	t_assert("dns_db_find", 15, T_REQUIRED, a15);	result = t_eval("dns_db_find_1_data", t_dns_db_find_x, 10);	t_result(result);}static const char *a16 =	"When the desired node and type were found, but are glue, "	"and the DNS_DBFIND_GLUEOK option is set, a call to "	"dns_db_find(db, name, version, type, options, now, ...)  "	"returns DNS_R_GLUE.";static voidt16(void) {	int	result;	t_assert("dns_db_find", 16, T_REQUIRED, a16);	result = t_eval("dns_db_find_2_data", t_dns_db_find_x, 10);	t_result(result);}static const char *a17 =	"A call to dns_db_find() returns DNS_R_DELEGATION when the data "	"requested is beneath a zone cut.";static voidt17(void) {	int	result;	t_assert("dns_db_find", 17, T_REQUIRED, a17);	result = t_eval("dns_db_find_3_data", t_dns_db_find_x, 10);	t_result(result);}static const char *a18 =	"A call to dns_db_find() returns DNS_R_DELEGATION when type is "	"dns_rdatatype_any and the desired node is a zone cut.";static voidt18(void) {	int	result;	t_assert("dns_

⌨️ 快捷键说明

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