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

📄 master.c

📁 bind-3.2.
💻 C
📖 第 1 页 / 共 4 页
字号:
				if (r.length == 0)					return (ISC_R_NOSPACE);				r.base[0] = *name++;				isc_textregion_consume(&r, 1);				continue;			}			strcpy(fmt, "%d");			/* Get format specifier. */			if (*name == '{' ) {				n = sscanf(name, "{%d,%u,%1[doxX]}",					   &delta, &width, mode);				switch (n) {				case 1:					break;				case 2:					n = snprintf(fmt, sizeof(fmt),						     "%%0%ud", width);					break;				case 3:					n = snprintf(fmt, sizeof(fmt),						     "%%0%u%c", width, mode[0]);					break;				default:					return (DNS_R_SYNTAX);				}				if (n >= sizeof(fmt))					return (ISC_R_NOSPACE);				/* Skip past closing brace. */				while (*name != '\0' && *name++ != '}')					continue;			}			n = snprintf(numbuf, sizeof(numbuf), fmt, it + delta);			if (n >= sizeof(numbuf))				return (ISC_R_NOSPACE);			cp = numbuf;			while (*cp != '\0') {				if (r.length == 0)					return (ISC_R_NOSPACE);				r.base[0] = *cp++;				isc_textregion_consume(&r, 1);			}		} else if (*name == '\\') {			if (r.length == 0)				return (ISC_R_NOSPACE);			r.base[0] = *name++;			isc_textregion_consume(&r, 1);			if (*name == '\0')				continue;			if (r.length == 0)				return (ISC_R_NOSPACE);			r.base[0] = *name++;			isc_textregion_consume(&r, 1);		} else {			if (r.length == 0)				return (ISC_R_NOSPACE);			r.base[0] = *name++;			isc_textregion_consume(&r, 1);		}	}	if (r.length == 0)		return (ISC_R_NOSPACE);	r.base[0] = '\0';	return (ISC_R_SUCCESS);}static isc_result_tgenerate(dns_loadctx_t *lctx, char *range, char *lhs, char *gtype, char *rhs,	 const char *source, unsigned int line){	char *target_mem = NULL;	char *lhsbuf = NULL;	char *rhsbuf = NULL;	dns_fixedname_t ownerfixed;	dns_name_t *owner;	dns_rdata_t rdata = DNS_RDATA_INIT;	dns_rdatacallbacks_t *callbacks;	dns_rdatalist_t rdatalist;	dns_rdatatype_t type;	rdatalist_head_t head;	int n;	int target_size = MINTSIZ;	/* only one rdata at a time */	isc_buffer_t buffer;	isc_buffer_t target;	isc_result_t result;	isc_textregion_t r;	unsigned int start, stop, step, i;	dns_incctx_t *ictx;	ictx = lctx->inc;	callbacks = lctx->callbacks;	dns_fixedname_init(&ownerfixed);	owner = dns_fixedname_name(&ownerfixed);	ISC_LIST_INIT(head);	target_mem = isc_mem_get(lctx->mctx, target_size);	rhsbuf = isc_mem_get(lctx->mctx, DNS_MASTER_BUFSZ);	lhsbuf = isc_mem_get(lctx->mctx, DNS_MASTER_BUFSZ);	if (target_mem == NULL || rhsbuf == NULL || lhsbuf == NULL) {		result = ISC_R_NOMEMORY;		goto error_cleanup;	}	isc_buffer_init(&target, target_mem, target_size);	n = sscanf(range, "%u-%u/%u", &start, &stop, &step);	if (n < 2 || stop < start) {	       (*callbacks->error)(callbacks,				  "%s: %s:%lu: invalid range '%s'",				  "$GENERATE", source, line, range);		result = DNS_R_SYNTAX;		goto insist_cleanup;	}	if (n == 2)		step = 1;	/*	 * Get type.	 */	r.base = gtype;	r.length = strlen(gtype);	result = dns_rdatatype_fromtext(&type, &r);	if (result != ISC_R_SUCCESS) {		(*callbacks->error)(callbacks,				   "%s: %s:%lu: unknown RR type '%s'",				   "$GENERATE", source, line, gtype);		goto insist_cleanup;	}	switch (type) {	case dns_rdatatype_ns:	case dns_rdatatype_ptr:	case dns_rdatatype_cname:	case dns_rdatatype_dname:		break;	case dns_rdatatype_a:	case dns_rdatatype_aaaa:		if (lctx->zclass == dns_rdataclass_in ||		    lctx->zclass == dns_rdataclass_hs)			break;		/* FALLTHROUGH */	default:	       (*callbacks->error)(callbacks,				  "%s: %s:%lu: unsupported type '%s'",				  "$GENERATE", source, line, gtype);		result = ISC_R_NOTIMPLEMENTED;		goto error_cleanup;	}	ISC_LIST_INIT(rdatalist.rdata);	ISC_LINK_INIT(&rdatalist, link);	for (i = start; i <= stop; i += step) {		result = genname(lhs, i, lhsbuf, DNS_MASTER_BUFSZ);		if (result != ISC_R_SUCCESS)			goto error_cleanup;		result = genname(rhs, i, rhsbuf, DNS_MASTER_BUFSZ);		if (result != ISC_R_SUCCESS)			goto error_cleanup;		isc_buffer_init(&buffer, lhsbuf, strlen(lhsbuf));		isc_buffer_add(&buffer, strlen(lhsbuf));		isc_buffer_setactive(&buffer, strlen(lhsbuf));		result = dns_name_fromtext(owner, &buffer, ictx->origin,					   ISC_FALSE, NULL);		if (result != ISC_R_SUCCESS)			goto error_cleanup;		if ((lctx->options & DNS_MASTER_ZONE) != 0 &&		    (lctx->options & DNS_MASTER_SLAVE) == 0 &&		    !dns_name_issubdomain(owner, lctx->top))		{			char namebuf[DNS_NAME_FORMATSIZE];			dns_name_format(owner, namebuf, sizeof(namebuf));			/*			 * Ignore out-of-zone data.			 */			(*callbacks->warn)(callbacks,					   "dns_master_load: %s:%lu: "					   "ignoring out-of-zone data (%s)",					   source, line, namebuf);			continue;		}		isc_buffer_init(&buffer, rhsbuf, strlen(rhsbuf));		isc_buffer_add(&buffer, strlen(rhsbuf));		isc_buffer_setactive(&buffer, strlen(rhsbuf));		result = isc_lex_openbuffer(lctx->lex, &buffer);		if (result != ISC_R_SUCCESS)			goto error_cleanup;		isc_buffer_init(&target, target_mem, target_size);		result = dns_rdata_fromtext(&rdata, lctx->zclass, type,					    lctx->lex, ictx->origin, ISC_FALSE,					    lctx->mctx, &target, callbacks);		isc_lex_close(lctx->lex);		if (result != ISC_R_SUCCESS)			goto error_cleanup;		rdatalist.type = type;		rdatalist.covers = 0;		rdatalist.rdclass = lctx->zclass;		rdatalist.ttl = lctx->ttl;		ISC_LIST_PREPEND(head, &rdatalist, link);		ISC_LIST_APPEND(rdatalist.rdata, &rdata, link);		result = commit(callbacks, lctx, &head, owner, source, line);		ISC_LIST_UNLINK(rdatalist.rdata, &rdata, link);		if (result != ISC_R_SUCCESS)			goto error_cleanup;		dns_rdata_reset(&rdata);	}	result = ISC_R_SUCCESS;	goto cleanup; error_cleanup:	if (result == ISC_R_NOMEMORY)		(*callbacks->error)(callbacks, "$GENERATE: %s",				    dns_result_totext(result));	else		(*callbacks->error)(callbacks, "$GENERATE: %s:%lu: %s",				    source, line, dns_result_totext(result)); insist_cleanup:	INSIST(result != ISC_R_SUCCESS); cleanup:	if (target_mem != NULL)		isc_mem_put(lctx->mctx, target_mem, target_size);	if (lhsbuf != NULL)		isc_mem_put(lctx->mctx, lhsbuf, DNS_MASTER_BUFSZ);	if (rhsbuf != NULL)		isc_mem_put(lctx->mctx, rhsbuf, DNS_MASTER_BUFSZ);	return (result);}static voidlimit_ttl(dns_rdatacallbacks_t *callbacks, const char *source, unsigned int line,	  isc_uint32_t *ttlp){	if (*ttlp > 0x7fffffffUL) {		(callbacks->warn)(callbacks,				  "%s: %s:%lu: "				  "$TTL %lu > MAXTTL, "				  "setting $TTL to 0",				  "dns_master_load",				  source, line,				  *ttlp);		*ttlp = 0;	}}static isc_result_tload(dns_loadctx_t *lctx) {	dns_rdataclass_t rdclass;	dns_rdatatype_t type, covers;	isc_uint32_t ttl_offset = 0;	dns_name_t *new_name;	isc_boolean_t current_has_delegation = ISC_FALSE;	isc_boolean_t done = ISC_FALSE;	isc_boolean_t finish_origin = ISC_FALSE;	isc_boolean_t finish_include = ISC_FALSE;	isc_boolean_t read_till_eol = ISC_FALSE;	isc_boolean_t initialws;	char *include_file = NULL;	isc_token_t token;	isc_result_t result = ISC_R_UNEXPECTED;	rdatalist_head_t glue_list;	rdatalist_head_t current_list;	dns_rdatalist_t *this;	dns_rdatalist_t *rdatalist = NULL;	dns_rdatalist_t *new_rdatalist;	int rdlcount = 0;	int rdlcount_save = 0;	int rdatalist_size = 0;	isc_buffer_t buffer;	isc_buffer_t target;	isc_buffer_t target_ft;	isc_buffer_t target_save;	dns_rdata_t *rdata = NULL;	dns_rdata_t *new_rdata;	int rdcount = 0;	int rdcount_save = 0;	int rdata_size = 0;	unsigned char *target_mem = NULL;	int target_size = TSIZ;	int new_in_use;	unsigned int loop_cnt = 0;	isc_mem_t *mctx;	dns_rdatacallbacks_t *callbacks;	dns_incctx_t *ictx;	char *range = NULL;	char *lhs = NULL;	char *gtype = NULL;	char *rhs = NULL;	const char *source = "";	unsigned long line = 0;	isc_boolean_t explicit_ttl;	isc_stdtime_t now;	REQUIRE(DNS_LCTX_VALID(lctx));	callbacks = lctx->callbacks;	mctx = lctx->mctx;	ictx = lctx->inc;	ISC_LIST_INIT(glue_list);	ISC_LIST_INIT(current_list);	isc_stdtime_get(&now);	/*	 * Allocate target_size of buffer space.  This is greater than twice	 * the maximum individual RR data size.	 */	target_mem = isc_mem_get(mctx, target_size);	if (target_mem == NULL) {		result = ISC_R_NOMEMORY;		goto log_and_cleanup;	}	isc_buffer_init(&target, target_mem, target_size);	target_save = target;	source = isc_lex_getsourcename(lctx->lex);	do {		initialws = ISC_FALSE;		line = isc_lex_getsourceline(lctx->lex);		GETTOKEN(lctx->lex, ISC_LEXOPT_INITIALWS, &token, ISC_TRUE);		line = isc_lex_getsourceline(lctx->lex);		if (token.type == isc_tokentype_eof) {			if (read_till_eol)				WARNUNEXPECTEDEOF(lctx->lex);			/* Pop the include stack? */			if (ictx->parent != NULL) {				COMMITALL;				lctx->inc = ictx->parent;				ictx->parent = NULL;				incctx_destroy(lctx->mctx, ictx);				isc_lex_close(lctx->lex);				line = isc_lex_getsourceline(lctx->lex);				source = isc_lex_getsourcename(lctx->lex);				ictx = lctx->inc;				EXPECTEOL;				continue;			}			done = ISC_TRUE;			continue;		}		if (token.type == isc_tokentype_eol) {			read_till_eol = ISC_FALSE;			continue;		/* blank line */		}		if (read_till_eol)			continue;		if (token.type == isc_tokentype_initialws) {			/*			 * Still working on the same name.			 */			initialws = ISC_TRUE;		} else if (token.type == isc_tokentype_string) {			/*			 * "$" Support.			 *			 * "$ORIGIN" and "$INCLUDE" can both take domain names.			 * The processing of "$ORIGIN" and "$INCLUDE" extends			 * across the normal domain name processing.			 */			if (strcasecmp(token.value.as_pointer,				       "$ORIGIN") == 0) {				GETTOKEN(lctx->lex, 0, &token, ISC_FALSE);				finish_origin = ISC_TRUE;			} else if (strcasecmp(token.value.as_pointer,					      "$TTL") == 0) {				GETTOKEN(lctx->lex, 0, &token, ISC_FALSE);				result =				   dns_ttl_fromtext(&token.value.as_textregion,						    &lctx->ttl);				if (MANYERRS(lctx, result)) {					SETRESULT(lctx, result);					lctx->ttl = 0;				} else if (result != ISC_R_SUCCESS)					goto insist_and_cleanup;				limit_ttl(callbacks, source, line, &lctx->ttl);				lctx->default_ttl = lctx->ttl;				lctx->default_ttl_known = ISC_TRUE;				EXPECTEOL;				continue;			} else if (strcasecmp(token.value.as_pointer,					      "$INCLUDE") == 0) {				COMMITALL;				if ((lctx->options & DNS_MASTER_NOINCLUDE) != 0) {					(callbacks->error)(callbacks,					   "%s: %s:%lu: $INCLUDE not allowed",					   "dns_master_load",					   source, line);					result = DNS_R_REFUSED;					goto insist_and_cleanup;				}				if (ttl_offset != 0) {					(callbacks->error)(callbacks,					   "%s: %s:%lu: $INCLUDE "					   "may not be used with $DATE",					   "dns_master_load",					   source, line);					result = DNS_R_SYNTAX;					goto insist_and_cleanup;				}				GETTOKEN(lctx->lex, ISC_LEXOPT_QSTRING, &token,					 ISC_FALSE);				if (include_file != NULL)					isc_mem_free(mctx, include_file);				include_file = isc_mem_strdup(mctx,						token.value.as_pointer);				if (include_file == NULL) {					result = ISC_R_NOMEMORY;					goto log_and_cleanup;				}				GETTOKEN(lctx->lex, 0, &token, ISC_TRUE);				if (token.type == isc_tokentype_eol ||				    token.type == isc_tokentype_eof) {					if (token.type == isc_tokentype_eof)						WARNUNEXPECTEDEOF(lctx->lex);					isc_lex_ungettoken(lctx->lex, &token);					/*					 * No origin field.					 */					result = pushfile(include_file,							  ictx->origin, lctx);					if (MANYERRS(lctx, result)) {						SETRESULT(lctx, result);						LOGITFILE(result, include_file);						continue;					} else if (result != ISC_R_SUCCESS) {						LOGITFILE(result, include_file);						goto insist_and_cleanup;					}					ictx = lctx->inc;					line = isc_lex_getsourceline(lctx->lex);					source =					       isc_lex_getsourcename(lctx->lex);					continue;				}				/*				 * There is an origin field.  Fall through				 * to domain name processing code and do				 * the actual inclusion later.				 */				finish_include = ISC_TRUE;			} else if (strcasecmp(token.value.as_pointer,					      "$DATE") == 0) {				isc_int64_t dump_time64;				isc_stdtime_t dump_time, current_time;				GETTOKEN(lctx->lex, 0, &token, ISC_FALSE);				isc_stdtime_get(&current_time);				result = dns_time64_fromtext(token.value.					     as_pointer, &dump_time64);				if (MANYERRS(lctx, result)) {					SETRESULT(lctx, result);					LOGIT(result);					dump_time64 = 0;				} else if (result != ISC_R_SUCCESS)					goto log_and_cleanup;				dump_time = (isc_stdtime_t)dump_time64;				if (dump_time != dump_time64) {					UNEXPECTED_ERROR(__FILE__, __LINE__,					 "%s: %s:%lu: $DATE outside epoch",					 "dns_master_load", source, line);					result = ISC_R_UNEXPECTED;					goto insist_and_cleanup;				}				if (dump_time > current_time) {					UNEXPECTED_ERROR(__FILE__, __LINE__,					"%s: %s:%lu: "					"$DATE in future, using current date",					"dns_master_load", source, line);					dump_time = current_time;				}				ttl_offset = current_time - dump_time;				EXPECTEOL;				continue;			} else if (strcasecmp(token.value.as_pointer,					      "$GENERATE") == 0) {				/*				 * Use default ttl if known otherwise				 * inherit or error.				 */				if (!lctx->ttl_known &&				    !lctx->default_ttl_known) {					(*callbacks->error)(callbacks,					    "%s: %s:%lu: no TTL specified",					    "dns_master_load", source, line);					result = DNS_R_NOTTL;					if (MANYERRS(lctx, result)) {						SETRESULT(lctx, result);						lctx->ttl = 0;					} else if (result != ISC_R_SUCCESS)						goto insist_and_cleanup;				} else if (lctx->default_ttl_known) {					lctx->ttl = lctx->default_ttl;				}				/*				 * Lazy cleanup.				 */				if (range != NULL)					isc_mem_free(mctx, range);				if (lhs != NULL)					isc_mem_free(mctx, lhs);				if (gtype != NULL)					isc_mem_free(mctx, gtype);				if (rhs != NULL)					isc_mem_free(mctx, rhs);				/* range */				GETTOKEN(lctx->lex, 0, &token, ISC_FALSE);				range = isc_mem_strdup(mctx,						     token.value.as_pointer);				if (range == NULL) {					result = ISC_R_NOMEMORY;					goto log_and_cleanup;				}				/* LHS */				GETTOKEN(lctx->lex, 0, &token, ISC_FALSE);				lhs = isc_mem_strdup(mctx,						    token.value.as_pointer);

⌨️ 快捷键说明

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