WERROR dns_name_check(TALLOC_CTX *mem_ctx, size_t len, const char *name)
{
	size_t i;
	unsigned int labels    = 0;
	unsigned int label_len = 0;

	if (len == 0) {
		return WERR_DS_INVALID_DN_SYNTAX;
	}

	if (len > 1 && name[0] == '.') {
		return WERR_DS_INVALID_DN_SYNTAX;
	}

	if ((len - 1) > DNS_MAX_DOMAIN_LENGTH) {
		return WERR_DS_INVALID_DN_SYNTAX;
	}

	for (i = 0; i < len - 1; i++) {
		if (name[i] == '.' && name[i+1] == '.') {
			return WERR_DS_INVALID_DN_SYNTAX;
		}
		if (name[i] == '.') {
			labels++;
			if (labels > DNS_MAX_LABELS) {
				return WERR_DS_INVALID_DN_SYNTAX;
			}
			label_len = 0;
		} else {
			label_len++;
			if (label_len > DNS_MAX_LABEL_LENGTH) {
				return WERR_DS_INVALID_DN_SYNTAX;
			}
		}
	}

	return WERR_OK;
}
WERROR dns_name_check(TALLOC_CTX *mem_ctx, size_t len, const char *name)
{
	size_t i;
	unsigned int labels    = 0;
	unsigned int label_len = 0;

	if (len == 0) {
		return WERR_DS_INVALID_DN_SYNTAX;
	}

	if (len > 1 && name[0] == '.') {
		return WERR_DS_INVALID_DN_SYNTAX;
	}

	if ((len - 1) > DNS_MAX_DOMAIN_LENGTH) {
		return WERR_DS_INVALID_DN_SYNTAX;
	}

	for (i = 0; i < len - 1; i++) {
		if (name[i] == '.' && name[i+1] == '.') {
			return WERR_DS_INVALID_DN_SYNTAX;
		}
		if (name[i] == '.') {
			labels++;
			if (labels > DNS_MAX_LABELS) {
				return WERR_DS_INVALID_DN_SYNTAX;
			}
			label_len = 0;
		} else {
			label_len++;
			if (label_len > DNS_MAX_LABEL_LENGTH) {
				return WERR_DS_INVALID_DN_SYNTAX;
			}
		}
	}

	return WERR_OK;
}