📄 t_names.c
字号:
static voidt_dns_name_setbuffer(void) { int result; unsigned char junk[BUFLEN]; dns_name_t name; isc_buffer_t buffer; t_assert("dns_name_setbuffer", 1, T_REQUIRED, a5); isc_buffer_init(&buffer, junk, BUFLEN); dns_name_init(&name, NULL); dns_name_setbuffer(&name, &buffer); if (name.buffer == &buffer) result = T_PASS; else result = T_FAIL; t_result(result);}static const char *a6 = "dns_name_hasbuffer returns ISC_TRUE if 'name' has a " "dedicated buffer, otherwise it returns ISC_FALSE";static voidt_dns_name_hasbuffer(void) { int result; int rval; unsigned char junk[BUFLEN]; dns_name_t name; isc_buffer_t buffer; t_assert("dns_name_hasbuffer", 1, T_REQUIRED, a6); rval = 0; isc_buffer_init(&buffer, junk, BUFLEN); dns_name_init(&name, NULL); if (dns_name_hasbuffer(&name) != ISC_FALSE) ++rval; dns_name_setbuffer(&name, &buffer); if (dns_name_hasbuffer(&name) != ISC_TRUE) ++rval; if (rval == 0) result = T_PASS; else result = T_FAIL; t_result(result);}static const char *a7 = "dns_name_isabsolute returns ISC_TRUE if 'name' ends " "in the root label";static inttest_dns_name_isabsolute(char *test_name, isc_boolean_t expected) { dns_name_t name; isc_buffer_t buf; isc_buffer_t binbuf; unsigned char junk[BUFLEN]; int len; int rval; isc_boolean_t isabs_p; isc_result_t result; rval = T_UNRESOLVED; t_info("testing name %s\n", test_name); len = strlen(test_name); isc_buffer_init(&buf, test_name, len); isc_buffer_add(&buf, len); isc_buffer_init(&binbuf, &junk[0], BUFLEN); dns_name_init(&name, NULL); dns_name_setbuffer(&name, &binbuf); result = dns_name_fromtext(&name, &buf, NULL, ISC_FALSE, NULL); if (result == ISC_R_SUCCESS) { isabs_p = dns_name_isabsolute(&name); if (isabs_p == expected) rval = T_PASS; else rval = T_FAIL; } else { t_info("dns_name_fromtext %s failed, result = %s\n", test_name, dns_result_totext(result)); } return (rval);}static voidt_dns_name_isabsolute(void) { int line; int cnt; int result; char *p; FILE *fp; t_assert("dns_name_isabsolute", 1, T_REQUIRED, a7); result = T_UNRESOLVED; fp = fopen("dns_name_isabsolute_data", "r"); if (fp != NULL) { line = 0; while ((p = t_fgetbs(fp)) != NULL) { ++line; /* * Skip comment lines. */ if ((isspace((unsigned char)*p)) || (*p == '#')) continue; cnt = bustline(p, Tokens); if (cnt == 2) { /* * label, bitpos, expected value. */ result = test_dns_name_isabsolute(Tokens[0], atoi(Tokens[1]) == 0 ? ISC_FALSE : ISC_TRUE); } else { t_info("bad datafile format at line %d\n", line); } (void)free(p); t_result(result); } (void)fclose(fp); } else { t_info("Missing datafile dns_name_isabsolute_data\n"); t_result(result); }}static const char *a8 = "dns_name_hash(name, case_sensitive) returns " "a hash of 'name' which is case_sensitive if case_sensitive " "is true";/* * a9 merged with a8. */static inttest_dns_name_hash(char *test_name1, char *test_name2, isc_boolean_t csh_match, isc_boolean_t cish_match) { int rval; int failures; isc_boolean_t match; unsigned int hash1; unsigned int hash2; dns_name_t dns_name1; dns_name_t dns_name2; isc_result_t result; rval = T_UNRESOLVED; failures = 0; t_info("testing names %s and %s\n", test_name1, test_name2); result = dname_from_tname(test_name1, &dns_name1); if (result == ISC_R_SUCCESS) { result = dname_from_tname(test_name2, &dns_name2); if (result == ISC_R_SUCCESS) { hash1 = dns_name_hash(&dns_name1, ISC_TRUE); hash2 = dns_name_hash(&dns_name2, ISC_TRUE); match = ISC_FALSE; if (hash1 == hash2) match = ISC_TRUE; if (match != csh_match) { ++failures; t_info("hash mismatch when ISC_TRUE\n"); } hash1 = dns_name_hash(&dns_name1, ISC_FALSE); hash2 = dns_name_hash(&dns_name2, ISC_FALSE); match = ISC_FALSE; if (hash1 == hash2) match = ISC_TRUE; if (match != cish_match) { ++failures; t_info("hash mismatch when ISC_FALSE\n"); } if (failures == 0) rval = T_PASS; else rval = T_FAIL; } else { t_info("dns_fromtext %s failed, result = %s\n", test_name2, dns_result_totext(result)); } } else { t_info("dns_fromtext %s failed, result = %s\n", test_name1, dns_result_totext(result)); } return (rval);}static voidt_dns_name_hash(void) { int line; int cnt; int result; char *p; FILE *fp; t_assert("dns_name_hash", 1, T_REQUIRED, a8); result = T_UNRESOLVED; fp = fopen("dns_name_hash_data", "r"); if (fp != NULL) { line = 0; while ((p = t_fgetbs(fp)) != NULL) { ++line; /* * Skip comment lines. */ if ((isspace((unsigned char)*p)) || (*p == '#')) continue; cnt = bustline(p, Tokens); if (cnt == 4) { /* * name1, name2, exp match value if * case_sensitive true, * exp match value of case_sensitive false */ result = test_dns_name_hash( Tokens[0], Tokens[1], atoi(Tokens[2]) == 0 ? ISC_FALSE : ISC_TRUE, atoi(Tokens[3]) == 0 ? ISC_FALSE : ISC_TRUE); } else { t_info("bad datafile format at line %d\n", line); } (void)free(p); t_result(result); } (void)fclose(fp); } else { t_info("Missing datafile dns_name_hash_data\n"); t_result(result); }}static const char *a10 = "dns_name_fullcompare(name1, name2, orderp, nlabelsp, nbitsp) " "returns the DNSSEC ordering relationship between name1 and " "name2, sets orderp to -1 if name1 < name2, to 0 if " "name1 == name2, or to 1 if name1 > name2, sets nlabelsp " "to the number of labels name1 and name2 have in common, " "and sets nbitsp to the number of bits name1 and name2 " "have in common";/* * a11 thru a22 merged into a10. */static const char *dns_namereln_to_text(dns_namereln_t reln) { const char *p; if (reln == dns_namereln_contains) p = "contains"; else if (reln == dns_namereln_subdomain) p = "subdomain"; else if (reln == dns_namereln_equal) p = "equal"; else if (reln == dns_namereln_none) p = "none"; else if (reln == dns_namereln_commonancestor) p = "commonancestor"; else p = "unknown"; return (p);}static inttest_dns_name_fullcompare(char *name1, char *name2, dns_namereln_t exp_dns_reln, int exp_order, int exp_nlabels, int exp_nbits){ int result; int nfails; int order; unsigned int nlabels; unsigned int nbits; dns_name_t dns_name1; dns_name_t dns_name2; isc_result_t dns_result; dns_namereln_t dns_reln; nfails = 0; result = T_UNRESOLVED; t_info("testing names %s and %s for relation %s\n", name1, name2, dns_namereln_to_text(exp_dns_reln)); dns_result = dname_from_tname(name1, &dns_name1); if (dns_result == ISC_R_SUCCESS) { dns_result = dname_from_tname(name2, &dns_name2); if (dns_result == ISC_R_SUCCESS) { dns_reln = dns_name_fullcompare(&dns_name1, &dns_name2, &order, &nlabels, &nbits); if (dns_reln != exp_dns_reln) { ++nfails; t_info("expected relationship of %s, got %s\n", dns_namereln_to_text(exp_dns_reln), dns_namereln_to_text(dns_reln)); } /* * Normalize order. */ if (order < 0) order = -1; else if (order > 0) order = 1; if (order != exp_order) { ++nfails; t_info("expected ordering %d, got %d\n", exp_order, order); } if ((exp_nlabels >= 0) && (nlabels != (unsigned int)exp_nlabels)) { ++nfails; t_info("expecting %d labels, got %d\n", exp_nlabels, nlabels); } if ((exp_nbits >= 0) && (nbits != (unsigned int)exp_nbits)) { ++nfails; t_info("expecting %d bits, got %d\n", exp_nbits, nbits); } if (nfails == 0) result = T_PASS; else result = T_FAIL; } else { t_info("dname_from_tname failed, result == %s\n", dns_result_totext(result)); } } else { t_info("dname_from_tname failed, result == %s\n", dns_result_totext(result)); } return (result);}static voidt_dns_name_fullcompare(void) { int line; int cnt; int result; char *p; FILE *fp; dns_namereln_t reln; t_assert("dns_name_fullcompare", 1, T_REQUIRED, a10); result = T_UNRESOLVED; fp = fopen("dns_name_fullcompare_data", "r"); if (fp != NULL) { line = 0; while ((p = t_fgetbs(fp)) != NULL) { ++line; /* * Skip comment lines. */ if ((isspace((unsigned char)*p)) || (*p == '#')) continue; cnt = bustline(p, Tokens); if (cnt == 6) { /* * name1, name2, exp_reln, exp_order, * exp_nlabels, exp_nbits */ if (!strcmp(Tokens[2], "none")) reln = dns_namereln_none; else if (!strcmp(Tokens[2], "contains")) reln = dns_namereln_contains; else if (!strcmp(Tokens[2], "subdomain")) reln = dns_namereln_subdomain; else if (!strcmp(Tokens[2], "equal")) reln = dns_namereln_equal; else if (!strcmp(Tokens[2], "commonancestor")) reln = dns_namereln_commonancestor; else { t_info("bad format at line %d\n", line); continue; } result = test_dns_name_fullcompare( Tokens[0], Tokens[1], reln, atoi(Tokens[3]), atoi(Tokens[4]), atoi(Tokens[5])); } else { t_info("bad format at line %d\n", line); } (void)free(p); t_result(result); } (void)fclose(fp); } else { t_info("Missing datafile dns_name_fullcompare_data\n"); t_result(result); }}static const char *a23 = "dns_name_compare(name1, name2) returns information about " "the relative ordering under the DNSSEC ordering relationship " "of name1 and name2";/* * a24 thru a29 merged into a23. */static inttest_dns_name_compare(char *name1, char *name2, int exp_order) { int result; int order; isc_result_t dns_result; dns_name_t dns_name1; dns_name_t dns_name2; result = T_UNRESOLVED; t_info("testing %s %s %s\n", name1, exp_order == 0 ? "==": (exp_order == -1 ? "<" : ">"), name2); dns_result = dname_from_tname(name1, &dns_name1); if (dns_result == ISC_R_SUCCESS) { dns_result = dname_from_tname(name2, &dns_name2); if (dns_result == ISC_R_SUCCESS) { order = dns_name_compare(&dns_name1, &dns_name2); /* * Normalize order. */ if (order < 0) order = -1; else if (order > 0) order = 1; if (order != exp_order) { t_info("expected order of %d, got %d\n", exp_order, order); result = T_FAIL; } else result = T_PASS; } else { t_info("dname_from_tname failed, result == %s\n", dns_result_totext(result)); } } else { t_info("dname_from_tname failed, result == %s\n", dns_result_totext(result)); } return (result);}static voidt_dns_name_compare(void) { int line; int cnt; int result; char *p; FILE *fp; t_assert("dns_name_compare", 1, T_REQUIRED, a23); result = T_UNRESOLVED; fp = fopen("dns_name_compare_data", "r"); if (fp != NULL) { line = 0; while ((p = t_fgetbs(fp)) != NULL) { ++line; /* * Skip comment lines. */ if ((isspace((unsigned char)*p)) || (*p == '#')) continue; cnt = bustline(p, Tokens); if (cnt == 3) { /* * name1, name2, order. */ result = test_dns_name_compare( Tokens[0], Tokens[1], atoi(Tokens[2])); } else { t_info("bad datafile format at line %d\n", line); } (void)free(p); t_result(result); } (void)fclose(fp); } else { t_info("Missing datafile dns_name_compare_data\n"); t_result(result); }}static const char *a30 = "dns_name_rdatacompare(name1, name2) returns information " "about the relative ordering of name1 and name2 as if they " "are part of rdata in DNSSEC canonical form";/* * a31, a32 merged into a30. */static inttest_dns_name_rdatacompare(char *name1, char *name2, int exp_order) { int result; int order; isc_result_t dns_result; dns_name_t dns_name1; dns_name_t dns_name2; result = T_UNRESOLVED; t_info("testing %s %s %s\n", name1, exp_order == 0 ? "==": (exp_order == -1 ? "<" : ">"), name2); dns_result = dname_from_tname(name1, &dns_name1); if (dns_result == ISC_R_SUCCESS) { dns_result = dname_from_tname(name2, &dns_name2); if (dns_result == ISC_R_SUCCESS) { order = dns_name_rdatacompare(&dns_name1, &dns_name2); /* * Normalize order. */ if (order < 0) order = -1; else if (order > 0) order = 1; if (order != exp_order) { t_info("expected order of %d, got %d\n", exp_order, order); result = T_FAIL; } else result = T_PASS; } else { t_info("dname_from_tname failed, result == %s\n", dns_result_totext(result)); } } else { t_info("dname_from_tname failed, result == %s\n", dns_result_totext(result)); } return (result);}static voidt_dns_name_rdatacompare(void) { int line; int cnt; int result; char *p; FILE *fp; t_assert("dns_name_rdatacompare", 1, T_REQUIRED, a30); result = T_UNRESOLVED; fp = fopen("dns_name_rdatacompare_data", "r"); if (fp != NULL) { line = 0; while ((p = t_fgetbs(fp)) != NULL) { ++line; /* * Skip comment lines. */ if ((isspace((unsigned char)*p)) || (*p == '#')) continue; cnt = bustline(p, Tokens); if (cnt == 3) { /* * name1, name2, order. */ result = test_dns_name_rdatacompare( Tokens[0], Tokens[1], atoi(Tokens[2])); } else { t_info("bad datafile format at line %d\n", line); } (void)free(p); t_result(result); } (void)fclose(fp); } else { t_info("Missing datafile dns_name_rdatacompare_data\n"); t_result(result); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -