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

📄 res_findzonecut.c

📁 bind 9.3结合mysql数据库
💻 C
📖 第 1 页 / 共 2 页
字号:
				DPRINTF(("get_soa: zname(%d) too small (%d)",					 zsize, strlen(t) + 1));				errno = EMSGSIZE;				goto cleanup;			}			strcpy(zname, t);			rdata = ns_rr_rdata(rr);			rdlen = ns_rr_rdlen(rr);			if (ns_name_uncompress(resp, ns_msg_end(msg), rdata,					       mname, msize) < 0) {				DPRINTF(("get_soa: ns_name_uncompress failed")					);				goto cleanup;			}			if (save_ns(statp, &msg, ns_s_ns,				    zname, class, opts, nsrrsp) < 0) {				DPRINTF(("get_soa: save_ns failed"));				goto cleanup;			}			free(resp);			return (0);		}		/* If we're out of labels, then not even "." has an SOA! */		if (*dname == '\0')			break;		/* Find label-terminating "."; top of loop will skip it. */		while (*dname != '.') {			if (*dname == '\\')				if (*++dname == '\0') {					errno = EMSGSIZE;					goto cleanup;				}			dname++;		}	}	DPRINTF(("get_soa: out of labels"));	errno = EDESTADDRREQ; cleanup:	if (resp != NULL)		free(resp);	return (-1);}static intget_ns(res_state statp, const char *zname, ns_class class, int opts,      rrset_ns *nsrrsp){	u_char *resp;	ns_msg msg;	int n;	resp = malloc(NS_MAXMSG);	if (resp == NULL)		return (-1);	/* Go and get the NS RRs for this zone. */	n = do_query(statp, zname, class, ns_t_ns, resp, &msg);	if (n != 0) {		DPRINTF(("get_ns: do_query('%s', %s) failed (%d)",			 zname, p_class(class), n));		free(resp);		return (-1);	}	/* Remember the NS RRs and associated A RRs that came back. */	if (save_ns(statp, &msg, ns_s_an, zname, class, opts, nsrrsp) < 0) {		DPRINTF(("get_ns save_ns('%s', %s) failed",			 zname, p_class(class)));		free(resp);		return (-1);	}	free(resp);	return (0);}static intget_glue(res_state statp, ns_class class, int opts, rrset_ns *nsrrsp) {	rr_ns *nsrr, *nsrr_n;	u_char *resp;	resp = malloc(NS_MAXMSG);	if (resp == NULL)		return(-1);	/* Go and get the A RRs for each empty NS RR on our list. */	for (nsrr = HEAD(*nsrrsp); nsrr != NULL; nsrr = nsrr_n) {		ns_msg msg;		int n;		nsrr_n = NEXT(nsrr, link);		if ((nsrr->flags & RR_NS_HAVE_V4) == 0) {			n = do_query(statp, nsrr->name, class, ns_t_a,				     resp, &msg);			if (n < 0) {				DPRINTF(				       ("get_glue: do_query('%s', %s') failed",					nsrr->name, p_class(class)));				goto cleanup;			}			if (n > 0) {				DPRINTF((			"get_glue: do_query('%s', %s') CNAME or DNAME found",					 nsrr->name, p_class(class)));			}			if (save_a(statp, &msg, ns_s_an, nsrr->name, class,				   opts, nsrr) < 0) {				DPRINTF(("get_glue: save_r('%s', %s) failed",					 nsrr->name, p_class(class)));				goto cleanup;			}		}		if ((nsrr->flags & RR_NS_HAVE_V6) == 0) {			n = do_query(statp, nsrr->name, class, ns_t_aaaa,				     resp, &msg);			if (n < 0) {				DPRINTF(				       ("get_glue: do_query('%s', %s') failed",					nsrr->name, p_class(class)));				goto cleanup;			}			if (n > 0) {				DPRINTF((			"get_glue: do_query('%s', %s') CNAME or DNAME found",					 nsrr->name, p_class(class)));			}			if (save_a(statp, &msg, ns_s_an, nsrr->name, class,				   opts, nsrr) < 0) {				DPRINTF(("get_glue: save_r('%s', %s) failed",					 nsrr->name, p_class(class)));				goto cleanup;			}		}		/* If it's still empty, it's just chaff. */		if (EMPTY(nsrr->addrs)) {			DPRINTF(("get_glue: removing empty '%s' NS",				 nsrr->name));			free_nsrr(nsrrsp, nsrr);		}	}	free(resp);	return (0); cleanup:	free(resp);	return (-1);}static intsave_ns(res_state statp, ns_msg *msg, ns_sect sect,	const char *owner, ns_class class, int opts,	rrset_ns *nsrrsp){	int i;	for (i = 0; i < ns_msg_count(*msg, sect); i++) {		char tname[MAXDNAME];		const u_char *rdata;		rr_ns *nsrr;		ns_rr rr;		int rdlen;		if (ns_parserr(msg, sect, i, &rr) < 0) {			DPRINTF(("save_ns: ns_parserr(%s, %d) failed",				 p_section(sect, ns_o_query), i));			return (-1);		}		if (ns_rr_type(rr) != ns_t_ns ||		    ns_rr_class(rr) != class ||		    ns_samename(ns_rr_name(rr), owner) != 1)			continue;		nsrr = find_ns(nsrrsp, ns_rr_name(rr));		if (nsrr == NULL) {			nsrr = malloc(sizeof *nsrr);			if (nsrr == NULL) {				DPRINTF(("save_ns: malloc failed"));				return (-1);			}			rdata = ns_rr_rdata(rr);			rdlen = ns_rr_rdlen(rr);			if (ns_name_uncompress(ns_msg_base(*msg),					       ns_msg_end(*msg), rdata,					       tname, sizeof tname) < 0) {				DPRINTF(("save_ns: ns_name_uncompress failed")					);				free(nsrr);				return (-1);			}			nsrr->name = strdup(tname);			if (nsrr->name == NULL) {				DPRINTF(("save_ns: strdup failed"));				free(nsrr);				return (-1);			}			INIT_LINK(nsrr, link);			INIT_LIST(nsrr->addrs);			nsrr->flags = 0;			APPEND(*nsrrsp, nsrr, link);		}		if (save_a(statp, msg, ns_s_ar,			   nsrr->name, class, opts, nsrr) < 0) {			DPRINTF(("save_ns: save_r('%s', %s) failed",				 nsrr->name, p_class(class)));			return (-1);		}	}	return (0);}static intsave_a(res_state statp, ns_msg *msg, ns_sect sect,       const char *owner, ns_class class, int opts,       rr_ns *nsrr){	int i;	for (i = 0; i < ns_msg_count(*msg, sect); i++) {		ns_rr rr;		rr_a *arr;		if (ns_parserr(msg, sect, i, &rr) < 0) {			DPRINTF(("save_a: ns_parserr(%s, %d) failed",				 p_section(sect, ns_o_query), i));			return (-1);		}		if ((ns_rr_type(rr) != ns_t_a &&		     ns_rr_type(rr) != ns_t_aaaa) ||		    ns_rr_class(rr) != class ||		    ns_samename(ns_rr_name(rr), owner) != 1 ||		    ns_rr_rdlen(rr) != NS_INADDRSZ)			continue;		if ((opts & RES_IPV6ONLY) != 0 && ns_rr_type(rr) != ns_t_aaaa)			continue;		if ((opts & RES_IPV4ONLY) != 0 && ns_rr_type(rr) != ns_t_a)			continue;		arr = malloc(sizeof *arr);		if (arr == NULL) {			DPRINTF(("save_a: malloc failed"));			return (-1);		}		INIT_LINK(arr, link);		memset(&arr->addr, 0, sizeof(arr->addr));		switch (ns_rr_type(rr)) {		case ns_t_a:			arr->addr.sin.sin_family = AF_INET;#ifdef HAVE_SA_LEN			arr->addr.sin.sin_len = sizeof(arr->addr.sin);#endif			memcpy(&arr->addr.sin.sin_addr, ns_rr_rdata(rr),			       NS_INADDRSZ);			arr->addr.sin.sin_port = htons(NAMESERVER_PORT);			nsrr->flags |= RR_NS_HAVE_V4;			break;		case ns_t_aaaa:			arr->addr.sin6.sin6_family = AF_INET6;#ifdef HAVE_SA_LEN			arr->addr.sin6.sin6_len = sizeof(arr->addr.sin6);#endif			memcpy(&arr->addr.sin6.sin6_addr, ns_rr_rdata(rr), 16);			arr->addr.sin.sin_port = htons(NAMESERVER_PORT);			nsrr->flags |= RR_NS_HAVE_V6;			break;		default:			abort();		}		APPEND(nsrr->addrs, arr, link);	}	return (0);}static voidfree_nsrrset(rrset_ns *nsrrsp) {	rr_ns *nsrr;	while ((nsrr = HEAD(*nsrrsp)) != NULL)		free_nsrr(nsrrsp, nsrr);}static voidfree_nsrr(rrset_ns *nsrrsp, rr_ns *nsrr) {	rr_a *arr;	char *tmp;	while ((arr = HEAD(nsrr->addrs)) != NULL) {		UNLINK(nsrr->addrs, arr, link);		free(arr);	}	DE_CONST(nsrr->name, tmp);	free(tmp);	UNLINK(*nsrrsp, nsrr, link);	free(nsrr);}static rr_ns *find_ns(rrset_ns *nsrrsp, const char *dname) {	rr_ns *nsrr;	for (nsrr = HEAD(*nsrrsp); nsrr != NULL; nsrr = NEXT(nsrr, link))		if (ns_samename(nsrr->name, dname) == 1)			return (nsrr);	return (NULL);}static intdo_query(res_state statp, const char *dname, ns_class class, ns_type qtype,	 u_char *resp, ns_msg *msg){	u_char req[NS_PACKETSZ];	int i, n;	n = res_nmkquery(statp, ns_o_query, dname, class, qtype,			 NULL, 0, NULL, req, NS_PACKETSZ);	if (n < 0) {		DPRINTF(("do_query: res_nmkquery failed"));		return (-1);	}	n = res_nsend(statp, req, n, resp, NS_MAXMSG);	if (n < 0) {		DPRINTF(("do_query: res_nsend failed"));		return (-1);	}	if (n == 0) {		DPRINTF(("do_query: res_nsend returned 0"));		errno = EMSGSIZE;		return (-1);	}	if (ns_initparse(resp, n, msg) < 0) {		DPRINTF(("do_query: ns_initparse failed"));		return (-1);	}	n = 0;	for (i = 0; i < ns_msg_count(*msg, ns_s_an); i++) {		ns_rr rr;		if (ns_parserr(msg, ns_s_an, i, &rr) < 0) {			DPRINTF(("do_query: ns_parserr failed"));			return (-1);		}		n += (ns_rr_class(rr) == class &&		      (ns_rr_type(rr) == ns_t_cname ||		       ns_rr_type(rr) == ns_t_dname));	}	return (n);}static voidres_dprintf(const char *fmt, ...) {	va_list ap;	va_start(ap, fmt);	fputs(";; res_findzonecut: ", stderr);	vfprintf(stderr, fmt, ap);	fputc('\n', stderr);	va_end(ap);}

⌨️ 快捷键说明

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