static isc_result_t convert_name(dns_fixedname_t *fn, dns_name_t **name, const char *text) { isc_result_t result; isc_buffer_t b; dns_name_t *n; unsigned int len; REQUIRE(fn != NULL && name != NULL && text != NULL); len = strlen(text); isc_buffer_constinit(&b, text, len); isc_buffer_add(&b, len); dns_fixedname_init(fn); n = dns_fixedname_name(fn); result = dns_name_fromtext(n, &b, dns_rootname, 0, NULL); if (result != ISC_R_SUCCESS) { delv_log(ISC_LOG_ERROR, "failed to convert QNAME %s: %s", text, isc_result_totext(result)); return (result); } *name = n; return (ISC_R_SUCCESS); }
static isc_result_t setup_master(void (*warn)(struct dns_rdatacallbacks *, const char *, ...), void (*error)(struct dns_rdatacallbacks *, const char *, ...)) { isc_result_t result; int len; isc_buffer_t source; isc_buffer_t target; strcpy(origin, TEST_ORIGIN); len = strlen(origin); isc_buffer_init(&source, origin, len); isc_buffer_add(&source, len); isc_buffer_setactive(&source, len); isc_buffer_init(&target, name_buf, BUFLEN); dns_name_init(&dns_origin, NULL); dns_master_initrawheader(&header); result = dns_name_fromtext(&dns_origin, &source, dns_rootname, 0, &target); if (result != ISC_R_SUCCESS) return(result); dns_rdatacallbacks_init_stdio(&callbacks); callbacks.add = add_callback; callbacks.rawdata = rawdata_callback; callbacks.zone = NULL; if (warn != NULL) callbacks.warn = warn; if (error != NULL) callbacks.error = error; headerset = ISC_FALSE; return (result); }
/* * Load test data into the RBT. */ static void add_test_data(isc_mem_t *mymctx, dns_rbt_t *rbt) { char buffer[1024]; isc_buffer_t b; isc_result_t result; dns_fixedname_t fname; dns_name_t *name; dns_compress_t cctx; rbt_testdata_t *testdatap = testdata; dns_compress_init(&cctx, -1, mymctx); while (testdatap->name != NULL && testdatap->data.data != NULL) { memmove(buffer, testdatap->name, testdatap->name_len); isc_buffer_init(&b, buffer, testdatap->name_len); isc_buffer_add(&b, testdatap->name_len); dns_fixedname_init(&fname); name = dns_fixedname_name(&fname); result = dns_name_fromtext(name, &b, dns_rootname, 0, NULL); if (result != ISC_R_SUCCESS) { testdatap++; continue; } if (name != NULL) { result = dns_rbt_addname(rbt, name, &testdatap->data); ATF_CHECK_STREQ(dns_result_totext(result), "success"); } testdatap++; } dns_compress_invalidate(&cctx); }
static dbinfo * select_db(char *origintext) { dns_fixedname_t forigin; dns_name_t *origin; isc_buffer_t source; size_t len; dbinfo *dbi; isc_result_t result; if (strcasecmp(origintext, "cache") == 0) { if (cache_dbi == NULL) printf("the cache does not exist\n"); return (cache_dbi); } len = strlen(origintext); isc_buffer_init(&source, origintext, len); isc_buffer_add(&source, len); dns_fixedname_init(&forigin); origin = dns_fixedname_name(&forigin); result = dns_name_fromtext(origin, &source, dns_rootname, 0, NULL); if (result != ISC_R_SUCCESS) { print_result("bad name", result); return (NULL); } for (dbi = ISC_LIST_HEAD(dbs); dbi != NULL; dbi = ISC_LIST_NEXT(dbi, link)) { if (dns_name_compare(dns_db_origin(dbi->db), origin) == 0) break; } return (dbi); }
static isc_result_t make_name(const char *src, dns_name_t *name) { isc_buffer_t b; isc_buffer_constinit(&b, src, strlen(src)); isc_buffer_add(&b, strlen(src)); return (dns_name_fromtext(name, &b, dns_rootname, 0, NULL)); }
static inline isc_result_t fromtext_ptr(ARGS_FROMTEXT) { isc_token_t token; dns_name_t name; isc_buffer_t buffer; REQUIRE(type == 12); UNUSED(type); UNUSED(rdclass); UNUSED(callbacks); RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_FALSE)); dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); origin = (origin != NULL) ? origin : dns_rootname; RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); if (rdclass == dns_rdataclass_in && (options & DNS_RDATA_CHECKNAMES) != 0 && (options & DNS_RDATA_CHECKREVERSE) != 0) { isc_boolean_t ok; ok = dns_name_ishostname(&name, ISC_FALSE); if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) RETTOK(DNS_R_BADNAME); if (!ok && callbacks != NULL) warn_badname(&name, lexer, callbacks); } return (ISC_R_SUCCESS); }
static inline isc_result_t fromtext_mx(ARGS_FROMTEXT) { isc_token_t token; dns_name_t name; isc_buffer_t buffer; isc_boolean_t ok; REQUIRE(type == 15); UNUSED(type); UNUSED(rdclass); UNUSED(callbacks); RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, ISC_FALSE)); if (token.value.as_ulong > 0xffffU) RETTOK(ISC_R_RANGE); RETERR(uint16_tobuffer(token.value.as_ulong, target)); RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_FALSE)); dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); origin = (origin != NULL) ? origin : dns_rootname; RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); ok = ISC_TRUE; if ((options & DNS_RDATA_CHECKNAMES) != 0) ok = dns_name_ishostname(&name, ISC_FALSE); if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) RETTOK(DNS_R_BADNAME); if (!ok && callbacks != NULL) warn_badname(&name, lexer, callbacks); return (ISC_R_SUCCESS); }
static inline isc_result_t fromtext_rp(ARGS_FROMTEXT) { isc_token_t token; dns_name_t name; isc_buffer_t buffer; int i; isc_boolean_t ok; REQUIRE(type == 17); UNUSED(type); UNUSED(rdclass); UNUSED(callbacks); origin = (origin != NULL) ? origin : dns_rootname; for (i = 0; i < 2; i++) { RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_FALSE)); dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); ok = ISC_TRUE; if ((options & DNS_RDATA_CHECKNAMES) != 0 && i == 0) ok = dns_name_ismailbox(&name); if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) RETTOK(DNS_R_BADNAME); if (!ok && callbacks != NULL) warn_badname(&name, lexer, callbacks); } return (ISC_R_SUCCESS); }
static isc_result_t set_nextqname(struct probe_trans *trans) { isc_result_t result; size_t domainlen; isc_buffer_t b; char buf[4096]; /* XXX ad-hoc constant, but should be enough */ if (*trans->qlabel == NULL) return (ISC_R_NOMORE); result = isc_string_copy(buf, sizeof(buf), *trans->qlabel); if (result != ISC_R_SUCCESS) return (result); result = isc_string_append(buf, sizeof(buf), trans->domain); if (result != ISC_R_SUCCESS) return (result); domainlen = strlen(buf); isc_buffer_init(&b, buf, domainlen); isc_buffer_add(&b, domainlen); dns_fixedname_init(&trans->fixedname); trans->qname = dns_fixedname_name(&trans->fixedname); result = dns_name_fromtext(trans->qname, &b, dns_rootname, 0, NULL); trans->qlabel++; return (result); }
/*% * Load the zone file from disk */ static void loadzone(char *file, char *origin, dns_rdataclass_t rdclass, dns_db_t **db) { isc_buffer_t b; int len; dns_fixedname_t fname; dns_name_t *name; isc_result_t result; len = strlen(origin); isc_buffer_init(&b, origin, len); isc_buffer_add(&b, len); dns_fixedname_init(&fname); name = dns_fixedname_name(&fname); result = dns_name_fromtext(name, &b, dns_rootname, 0, NULL); if (result != ISC_R_SUCCESS) fatal("failed converting name '%s' to dns format: %s", origin, isc_result_totext(result)); result = dns_db_create(mctx, "rbt", name, dns_dbtype_zone, rdclass, 0, NULL, db); check_result(result, "dns_db_create()"); result = dns_db_load2(*db, file, inputformat); if (result != ISC_R_SUCCESS && result != DNS_R_SEENINCLUDE) fatal("failed loading zone from '%s': %s", file, isc_result_totext(result)); }
static inline isc_result_t fromtext_in_kx(ARGS_FROMTEXT) { isc_token_t token; dns_name_t name; isc_buffer_t buffer; REQUIRE(type == 36); REQUIRE(rdclass == 1); UNUSED(type); UNUSED(rdclass); UNUSED(callbacks); RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, ISC_FALSE)); if (token.value.as_ulong > 0xffffU) RETTOK(ISC_R_RANGE); RETERR(uint16_tobuffer(token.value.as_ulong, target)); RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_FALSE)); dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); origin = (origin != NULL) ? origin : dns_rootname; RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); return (ISC_R_SUCCESS); }
ATF_TC_BODY(isc_dh_computesecret, tc) { dst_key_t *key = NULL; isc_buffer_t buf; unsigned char array[1024]; isc_result_t ret; dns_fixedname_t fname; dns_name_t *name; UNUSED(tc); ret = dns_test_begin(NULL, ISC_FALSE); ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS); dns_fixedname_init(&fname); name = dns_fixedname_name(&fname); isc_buffer_constinit(&buf, "dh.", 3); isc_buffer_add(&buf, 3); ret = dns_name_fromtext(name, &buf, NULL, 0, NULL); ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS); ret = dst_key_fromfile(name, 18602, DST_ALG_DH, DST_TYPE_PUBLIC | DST_TYPE_KEY, "./", mctx, &key); ATF_REQUIRE_EQ(ret, ISC_R_SUCCESS); isc_buffer_init(&buf, array, sizeof(array)); ret = dst_key_computesecret(key, key, &buf); ATF_REQUIRE_EQ(ret, DST_R_NOTPRIVATEKEY); ret = key->func->computesecret(key, key, &buf); ATF_REQUIRE_EQ(ret, DST_R_COMPUTESECRETFAILURE); dst_key_free(&key); dns_test_end(); }
isc_result_t dns_peer_setkeybycharp(dns_peer_t *peer, const char *keyval) { isc_buffer_t b; dns_fixedname_t fname; dns_name_t *name; isc_result_t result; dns_fixedname_init(&fname); isc_buffer_constinit(&b, keyval, strlen(keyval)); isc_buffer_add(&b, strlen(keyval)); result = dns_name_fromtext(dns_fixedname_name(&fname), &b, dns_rootname, 0, NULL); if (result != ISC_R_SUCCESS) return (result); name = isc_mem_get(peer->mem, sizeof(dns_name_t)); if (name == NULL) return (ISC_R_NOMEMORY); dns_name_init(name, NULL); result = dns_name_dup(dns_fixedname_name(&fname), peer->mem, name); if (result != ISC_R_SUCCESS) { isc_mem_put(peer->mem, name, sizeof(dns_name_t)); return (result); } result = dns_peer_setkey(peer, &name); if (result != ISC_R_SUCCESS) isc_mem_put(peer->mem, name, sizeof(dns_name_t)); return (result); }
static isc_result_t make_zone(const char *name, dns_zone_t **zonep) { isc_result_t result; dns_view_t *view = NULL; dns_zone_t *zone = NULL; isc_buffer_t buffer; dns_fixedname_t fixorigin; dns_name_t *origin; CHECK(dns_view_create(mctx, dns_rdataclass_in, "view", &view)); CHECK(dns_zone_create(&zone, mctx)); isc_buffer_init(&buffer, name, strlen(name)); isc_buffer_add(&buffer, strlen(name)); dns_fixedname_init(&fixorigin); origin = dns_fixedname_name(&fixorigin); CHECK(dns_name_fromtext(origin, &buffer, dns_rootname, 0, NULL)); CHECK(dns_zone_setorigin(zone, origin)); dns_zone_setview(zone, view); dns_zone_settype(zone, dns_zone_master); dns_zone_setclass(zone, view->rdclass); dns_view_detach(&view); *zonep = zone; return (ISC_R_SUCCESS); cleanup: if (zone != NULL) dns_zone_detach(&zone); if (view != NULL) dns_view_detach(&view); return (result); }
static isc_result_t sendquery(isc_task_t *task) { dns_request_t *request; dns_message_t *message; dns_name_t *qname; dns_rdataset_t *qrdataset; isc_result_t result; dns_fixedname_t queryname; isc_buffer_t buf; static char host[256]; int c; c = scanf("%255s", host); if (c == EOF) return ISC_R_NOMORE; onfly++; dns_fixedname_init(&queryname); isc_buffer_init(&buf, host, strlen(host)); isc_buffer_add(&buf, strlen(host)); result = dns_name_fromtext(dns_fixedname_name(&queryname), &buf, dns_rootname, 0, NULL); CHECK("dns_name_fromtext", result); message = NULL; result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &message); CHECK("dns_message_create", result); message->opcode = dns_opcode_query; message->flags |= DNS_MESSAGEFLAG_RD; message->rdclass = dns_rdataclass_in; message->id = (unsigned short)(random() & 0xFFFF); qname = NULL; result = dns_message_gettempname(message, &qname); CHECK("dns_message_gettempname", result); qrdataset = NULL; result = dns_message_gettemprdataset(message, &qrdataset); CHECK("dns_message_gettemprdataset", result); dns_name_init(qname, NULL); dns_name_clone(dns_fixedname_name(&queryname), qname); dns_rdataset_init(qrdataset); dns_rdataset_makequestion(qrdataset, dns_rdataclass_in, dns_rdatatype_a); ISC_LIST_APPEND(qname->list, qrdataset, link); dns_message_addname(message, qname, DNS_SECTION_QUESTION); request = NULL; result = dns_request_createvia(requestmgr, message, have_src ? &srcaddr : NULL, &dstaddr, DNS_REQUESTOPT_TCP|DNS_REQUESTOPT_SHARE, NULL, TIMEOUT, task, recvresponse, message, &request); CHECK("dns_request_create", result); return ISC_R_SUCCESS; }
/*% * Configure an apex NS with an out-of-zone NS names for a static-stub zone. * For example, for the zone named "example.com", something like the following * RRs will be added to the zone DB: * example.com. NS ns.example.net. */ static isc_result_t configure_staticstub_servernames(const cfg_obj_t *zconfig, dns_zone_t *zone, dns_rdatalist_t *rdatalist, const char *zname) { const cfg_listelt_t *element; isc_mem_t *mctx = dns_zone_getmctx(zone); dns_rdata_t *rdata; isc_region_t sregion, region; isc_result_t result = ISC_R_SUCCESS; for (element = cfg_list_first(zconfig); element != NULL; element = cfg_list_next(element)) { const cfg_obj_t *obj; const char *str; dns_fixedname_t fixed_name; dns_name_t *nsname; isc_buffer_t b; obj = cfg_listelt_value(element); str = cfg_obj_asstring(obj); dns_fixedname_init(&fixed_name); nsname = dns_fixedname_name(&fixed_name); isc_buffer_init(&b, str, strlen(str)); isc_buffer_add(&b, strlen(str)); result = dns_name_fromtext(nsname, &b, dns_rootname, 0, NULL); if (result != ISC_R_SUCCESS) { cfg_obj_log(zconfig, ns_g_lctx, ISC_LOG_ERROR, "server-name '%s' is not a valid " "name", str); return (result); } if (dns_name_issubdomain(nsname, dns_zone_getorigin(zone))) { cfg_obj_log(zconfig, ns_g_lctx, ISC_LOG_ERROR, "server-name '%s' must not be a " "subdomain of zone name '%s'", str, zname); return (ISC_R_FAILURE); } dns_name_toregion(nsname, &sregion); rdata = isc_mem_get(mctx, sizeof(*rdata) + sregion.length); if (rdata == NULL) return (ISC_R_NOMEMORY); region.length = sregion.length; region.base = (unsigned char *)(rdata + 1); memcpy(region.base, sregion.base, region.length); dns_rdata_init(rdata); dns_rdata_fromregion(rdata, dns_zone_getclass(zone), dns_rdatatype_ns, ®ion); ISC_LIST_APPEND(rdatalist->rdata, rdata, link); } return (result); }
static inline isc_result_t fromtext_soa(ARGS_FROMTEXT) { isc_token_t token; dns_name_t name; isc_buffer_t buffer; int i; isc_uint32_t n; isc_boolean_t ok; REQUIRE(type == 6); UNUSED(type); UNUSED(rdclass); UNUSED(callbacks); origin = (origin != NULL) ? origin : dns_rootname; for (i = 0; i < 2; i++) { RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_FALSE)); dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); ok = ISC_TRUE; if ((options & DNS_RDATA_CHECKNAMES) != 0) switch (i) { case 0: ok = dns_name_ishostname(&name, ISC_FALSE); break; case 1: ok = dns_name_ismailbox(&name); break; } if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) RETTOK(DNS_R_BADNAME); if (!ok && callbacks != NULL) warn_badname(&name, lexer, callbacks); } RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, ISC_FALSE)); RETERR(uint32_tobuffer(token.value.as_ulong, target)); for (i = 0; i < 4; i++) { RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_FALSE)); RETTOK(dns_counter_fromtext(&token.value.as_textregion, &n)); RETERR(uint32_tobuffer(n, target)); } return (ISC_R_SUCCESS); }
/*% load the zone */ isc_result_t load_zone(isc_mem_t *mctx, const char *zonename, const char *filename, dns_masterformat_t fileformat, const char *classname, dns_zone_t **zonep) { isc_result_t result; dns_rdataclass_t rdclass; isc_textregion_t region; isc_buffer_t buffer; dns_fixedname_t fixorigin; dns_name_t *origin; dns_zone_t *zone = NULL; REQUIRE(zonep == NULL || *zonep == NULL); if (debug) fprintf(stderr, "loading \"%s\" from \"%s\" class \"%s\"\n", zonename, filename, classname); CHECK(dns_zone_create(&zone, mctx)); dns_zone_settype(zone, dns_zone_master); isc_buffer_init(&buffer, zonename, strlen(zonename)); isc_buffer_add(&buffer, strlen(zonename)); dns_fixedname_init(&fixorigin); origin = dns_fixedname_name(&fixorigin); CHECK(dns_name_fromtext(origin, &buffer, dns_rootname, 0, NULL)); CHECK(dns_zone_setorigin(zone, origin)); CHECK(dns_zone_setdbtype(zone, 1, (const char * const *) dbtype)); CHECK(dns_zone_setfile2(zone, filename, fileformat)); DE_CONST(classname, region.base); region.length = strlen(classname); CHECK(dns_rdataclass_fromtext(&rdclass, ®ion)); dns_zone_setclass(zone, rdclass); dns_zone_setoption(zone, zone_options, ISC_TRUE); dns_zone_setoption(zone, DNS_ZONEOPT_NOMERGE, nomerge); if (docheckmx) dns_zone_setcheckmx(zone, checkmx); if (docheckns) dns_zone_setcheckns(zone, checkns); if (dochecksrv) dns_zone_setchecksrv(zone, checksrv); CHECK(dns_zone_load(zone)); if (zonep != NULL) { *zonep = zone; zone = NULL; } cleanup: if (zone != NULL) dns_zone_detach(&zone); return (result); }
int main(int argc, char **argv) { dns_fixedname_t fixed; dns_name_t *name; isc_buffer_t buffer; isc_region_t region; isc_result_t result; unsigned char hash[NSEC3_MAX_HASH_LENGTH]; unsigned char salt[DNS_NSEC3_SALTSIZE]; unsigned char text[1024]; unsigned int hash_alg; unsigned int length; unsigned int iterations; unsigned int salt_length; if (argc != 5) usage(); if (strcmp(argv[1], "-") == 0) { salt_length = 0; salt[0] = 0; } else { isc_buffer_init(&buffer, salt, sizeof(salt)); result = isc_hex_decodestring(argv[1], &buffer); check_result(result, "isc_hex_decodestring(salt)"); salt_length = isc_buffer_usedlength(&buffer); if (salt_length > DNS_NSEC3_SALTSIZE) fatal("salt too long"); } hash_alg = atoi(argv[2]); if (hash_alg > 255U) fatal("hash algorithm too large"); iterations = atoi(argv[3]); if (iterations > 0xffffU) fatal("iterations to large"); dns_fixedname_init(&fixed); name = dns_fixedname_name(&fixed); isc_buffer_init(&buffer, argv[4], strlen(argv[4])); isc_buffer_add(&buffer, strlen(argv[4])); result = dns_name_fromtext(name, &buffer, dns_rootname, 0, NULL); check_result(result, "dns_name_fromtext() failed"); dns_name_downcase(name, name, NULL); length = isc_iterated_hash(hash, hash_alg, iterations, salt, salt_length, name->ndata, name->length); if (length == 0) fatal("isc_iterated_hash failed"); region.base = hash; region.length = length; isc_buffer_init(&buffer, text, sizeof(text)); isc_base32hexnp_totext(®ion, 1, "", &buffer); fprintf(stdout, "%.*s (salt=%s, hash=%u, iterations=%u)\n", (int)isc_buffer_usedlength(&buffer), text, argv[1], hash_alg, iterations); return(0); }
static isc_result_t probe_domain (struct probe_trans *trans) { isc_result_t result; size_t domainlen; isc_buffer_t b; char buf[4096]; /* XXX ad hoc constant, but should be enough */ char *cp; REQUIRE (trans != NULL); REQUIRE (trans->inuse == ISC_FALSE); REQUIRE (outstanding_probes < MAX_PROBES); /* Construct domain */ cp = fgets (buf, sizeof (buf), fp); if (cp == NULL) return (ISC_R_NOMORE); if ((cp = strchr (buf, '\n')) != NULL) /* zap NL if any */ *cp = '\0'; trans->domain = isc_mem_strdup (mctx, buf); if (trans->domain == NULL) { fprintf (stderr, "failed to allocate memory for domain: %s", cp); return (ISC_R_NOMEMORY); } /* Start getting NS for the domain */ domainlen = strlen (buf); isc_buffer_init (&b, buf, domainlen); isc_buffer_add (&b, domainlen); dns_fixedname_init (&trans->fixedname); trans->qname = dns_fixedname_name (&trans->fixedname); result = dns_name_fromtext (trans->qname, &b, dns_rootname, 0, NULL); if (result != ISC_R_SUCCESS) goto cleanup; result = dns_client_startresolve (client, trans->qname, dns_rdataclass_in, dns_rdatatype_ns, 0, probe_task, resolve_ns, trans, &trans->resid); if (result != ISC_R_SUCCESS) goto cleanup; trans->inuse = ISC_TRUE; outstanding_probes++; return (ISC_R_SUCCESS); cleanup: isc_mem_free (mctx, trans->domain); dns_fixedname_invalidate (&trans->fixedname); return (result); }
static isc_result_t make_querymessage(dns_message_t *message, const char *namestr, dns_rdatatype_t rdtype) { dns_name_t *qname = NULL, *qname0; dns_rdataset_t *qrdataset = NULL; isc_result_t result; isc_buffer_t b; unsigned int namelen; REQUIRE(message != NULL); REQUIRE(namestr != NULL); /* Construct qname */ namelen = strlen(namestr); isc_buffer_constinit(&b, namestr, namelen); isc_buffer_add(&b, namelen); dns_fixedname_init(&fixedqname); qname0 = dns_fixedname_name(&fixedqname); result = dns_name_fromtext(qname0, &b, dns_rootname, 0, NULL); if (result != ISC_R_SUCCESS) { fprintf(stderr, "failed to convert qname: %d\n", result); return (result); } /* Construct query message */ message->opcode = dns_opcode_query; message->rdclass = dns_rdataclass_in; result = dns_message_gettempname(message, &qname); if (result != ISC_R_SUCCESS) goto cleanup; result = dns_message_gettemprdataset(message, &qrdataset); if (result != ISC_R_SUCCESS) goto cleanup; dns_name_init(qname, NULL); dns_name_clone(qname0, qname); dns_rdataset_init(qrdataset); dns_rdataset_makequestion(qrdataset, message->rdclass, rdtype); ISC_LIST_APPEND(qname->list, qrdataset, link); dns_message_addname(message, qname, DNS_SECTION_QUESTION); return (ISC_R_SUCCESS); cleanup: if (qname != NULL) dns_message_puttempname(message, &qname); if (qrdataset != NULL) dns_message_puttemprdataset(message, &qrdataset); dns_message_destroy(&message); return (result); }
static void setup(const char *zonename, const char *filename, const char *classname) { isc_result_t result; dns_rdataclass_t rdclass; isc_consttextregion_t region; isc_buffer_t buffer; dns_fixedname_t fixorigin; dns_name_t *origin; const char *rbt = "rbt"; if (debug) fprintf(stderr, "loading \"%s\" from \"%s\" class \"%s\"\n", zonename, filename, classname); result = dns_zone_create(&zone, mctx); ERRRET(result, "dns_zone_new"); dns_zone_settype(zone, zonetype); isc_buffer_init(&buffer, zonename, strlen(zonename)); isc_buffer_add(&buffer, strlen(zonename)); dns_fixedname_init(&fixorigin); result = dns_name_fromtext(dns_fixedname_name(&fixorigin), &buffer, dns_rootname, 0, NULL); ERRRET(result, "dns_name_fromtext"); origin = dns_fixedname_name(&fixorigin); result = dns_zone_setorigin(zone, origin); ERRRET(result, "dns_zone_setorigin"); result = dns_zone_setdbtype(zone, 1, &rbt); ERRRET(result, "dns_zone_setdatabase"); result = dns_zone_setfile(zone, filename); ERRRET(result, "dns_zone_setfile"); region.base = classname; region.length = strlen(classname); result = dns_rdataclass_fromtext(&rdclass, (isc_textregion_t *)(void*)®ion); ERRRET(result, "dns_rdataclass_fromtext"); dns_zone_setclass(zone, rdclass); if (zonetype == dns_zone_slave) dns_zone_setmasters(zone, &addr, 1); result = dns_zone_load(zone); ERRRET(result, "dns_zone_load"); result = dns_zonemgr_managezone(zonemgr, zone); ERRRET(result, "dns_zonemgr_managezone"); }
static isc_result_t initname(char *setname) { isc_result_t result; isc_buffer_t buf; dns_fixedname_init(&fixed); name = dns_fixedname_name(&fixed); isc_buffer_init(&buf, setname, strlen(setname)); isc_buffer_add(&buf, strlen(setname)); result = dns_name_fromtext(name, &buf, dns_rootname, 0, NULL); return (result); }
static dns_name_t *create_name (char *s) { int length; isc_result_t result; isc_buffer_t source, target; static dns_name_t *name; if (s == NULL || *s == '\0') { printf ("missing name argument\n"); return (NULL); } length = strlen (s); isc_buffer_init (&source, s, length); isc_buffer_add (&source, length); /* * It isn't really necessary in this program to create individual * memory spaces for each name structure and its associated character * string. It is done here to provide a relatively easy way to test * the callback from dns_rbt_deletename that is supposed to free the * data associated with a node. * * The buffer for the actual name will immediately follow the * name structure. */ name = isc_mem_get (mctx, sizeof (*name) + DNSNAMELEN); if (name == NULL) { printf ("out of memory!\n"); return (NULL); } dns_name_init (name, NULL); isc_buffer_init (&target, name + 1, DNSNAMELEN); result = dns_name_fromtext (name, &source, dns_rootname, 0, &target); if (result != ISC_R_SUCCESS) { printf ("dns_name_fromtext(%s) failed: %s\n", s, dns_result_totext (result)); return (NULL); } return (name); }
static void reverse_from_address(dns_name_t *tcpself, isc_netaddr_t *tcpaddr) { char buf[16 * 4 + sizeof("IP6.ARPA.")]; isc_result_t result; unsigned char *ap; isc_buffer_t b; unsigned long l; switch (tcpaddr->family) { case AF_INET: l = ntohl(tcpaddr->type.in.s_addr); result = isc_string_printf(buf, sizeof(buf), "%lu.%lu.%lu.%lu.IN-ADDR.ARPA.", (l >> 0) & 0xff, (l >> 8) & 0xff, (l >> 16) & 0xff, (l >> 24) & 0xff); RUNTIME_CHECK(result == ISC_R_SUCCESS); break; case AF_INET6: ap = tcpaddr->type.in6.s6_addr; result = isc_string_printf(buf, sizeof(buf), "%x.%x.%x.%x.%x.%x.%x.%x." "%x.%x.%x.%x.%x.%x.%x.%x." "%x.%x.%x.%x.%x.%x.%x.%x." "%x.%x.%x.%x.%x.%x.%x.%x." "IP6.ARPA.", ap[15] & 0x0f, (ap[15] >> 4) & 0x0f, ap[14] & 0x0f, (ap[14] >> 4) & 0x0f, ap[13] & 0x0f, (ap[13] >> 4) & 0x0f, ap[12] & 0x0f, (ap[12] >> 4) & 0x0f, ap[11] & 0x0f, (ap[11] >> 4) & 0x0f, ap[10] & 0x0f, (ap[10] >> 4) & 0x0f, ap[9] & 0x0f, (ap[9] >> 4) & 0x0f, ap[8] & 0x0f, (ap[8] >> 4) & 0x0f, ap[7] & 0x0f, (ap[7] >> 4) & 0x0f, ap[6] & 0x0f, (ap[6] >> 4) & 0x0f, ap[5] & 0x0f, (ap[5] >> 4) & 0x0f, ap[4] & 0x0f, (ap[4] >> 4) & 0x0f, ap[3] & 0x0f, (ap[3] >> 4) & 0x0f, ap[2] & 0x0f, (ap[2] >> 4) & 0x0f, ap[1] & 0x0f, (ap[1] >> 4) & 0x0f, ap[0] & 0x0f, (ap[0] >> 4) & 0x0f); RUNTIME_CHECK(result == ISC_R_SUCCESS); break; default: INSIST(0); } isc_buffer_init(&b, buf, strlen(buf)); isc_buffer_add(&b, strlen(buf)); result = dns_name_fromtext(tcpself, &b, dns_rootname, 0, NULL); RUNTIME_CHECK(result == ISC_R_SUCCESS); }
static int create_name(char *s, isc_mem_t *mctx, dns_name_t **dns_name) { int nfails; int length; isc_result_t result; isc_buffer_t source; isc_buffer_t target; dns_name_t *name; nfails = 0; if (s && *s) { length = strlen(s); isc_buffer_init(&source, s, length); isc_buffer_add(&source, length); /* * The buffer for the actual name will immediately follow the * name structure. */ name = isc_mem_get(mctx, sizeof(*name) + DNSNAMELEN); if (name == NULL) { t_info("isc_mem_get failed\n"); ++nfails; } else { dns_name_init(name, NULL); isc_buffer_init(&target, name + 1, DNSNAMELEN); result = dns_name_fromtext(name, &source, dns_rootname, 0, &target); if (result != ISC_R_SUCCESS) { ++nfails; t_info("dns_name_fromtext(%s) failed %s\n", s, dns_result_totext(result)); isc_mem_put(mctx, name, sizeof(*name) + DNSNAMELEN); } else *dns_name = name; } } else { ++nfails; t_info("create_name: empty name\n"); } return(nfails); }
static void lookup(const char *target) { dns_name_t name; unsigned char namedata[256]; client_t *client; isc_buffer_t t, namebuf; isc_result_t result; unsigned int options; INSIST(target != NULL); client = new_client(); isc_buffer_init(&t, target, strlen(target)); isc_buffer_add(&t, strlen(target)); isc_buffer_init(&namebuf, namedata, sizeof(namedata)); dns_name_init(&name, NULL); result = dns_name_fromtext(&name, &t, dns_rootname, ISC_FALSE, &namebuf); check_result(result, "dns_name_fromtext %s", target); result = dns_name_dup(&name, mctx, &client->name); check_result(result, "dns_name_dup %s", target); options = 0; options |= DNS_ADBFIND_INET; options |= DNS_ADBFIND_INET6; options |= DNS_ADBFIND_WANTEVENT; options |= DNS_ADBFIND_HINTOK; options |= DNS_ADBFIND_GLUEOK; result = dns_adb_createfind(adb, t2, lookup_callback, client, &client->name, dns_rootname, options, now, NULL, view->dstport, &client->find); #if 0 check_result(result, "dns_adb_createfind()"); #endif dns_adb_dumpfind(client->find, stderr); if ((client->find->options & DNS_ADBFIND_WANTEVENT) != 0) { client->target = target; ISC_LIST_APPEND(clients, client, link); } else { printf("NAME %s: err4 %s, err6 %s\n", target, isc_result_totext(client->find->result_v4), isc_result_totext(client->find->result_v6)); dns_adb_destroyfind(&client->find); free_client(&client); } }
static isc_result_t dispatch_query(struct query_trans *trans) { isc_result_t result; size_t namelen; isc_buffer_t b; char buf[4096]; /* XXX ad hoc constant, but should be enough */ char *cp; REQUIRE(trans != NULL); REQUIRE(trans->inuse == ISC_FALSE); REQUIRE(ISC_LIST_EMPTY(trans->answerlist)); REQUIRE(outstanding_queries < MAX_QUERIES); /* Construct qname */ cp = fgets(buf, sizeof(buf), fp); if (cp == NULL) return (ISC_R_NOMORE); /* zap NL if any */ if ((cp = strchr(buf, '\n')) != NULL) *cp = '\0'; namelen = strlen(buf); isc_buffer_init(&b, buf, namelen); isc_buffer_add(&b, namelen); dns_fixedname_init(&trans->fixedname); trans->qname = dns_fixedname_name(&trans->fixedname); result = dns_name_fromtext(trans->qname, &b, dns_rootname, 0, NULL); if (result != ISC_R_SUCCESS) goto cleanup; /* Start resolution */ result = dns_client_startresolve(client, trans->qname, dns_rdataclass_in, trans->type, 0, query_task, process_answer, trans, &trans->xid); if (result != ISC_R_SUCCESS) goto cleanup; trans->inuse = ISC_TRUE; outstanding_queries++; return (ISC_R_SUCCESS); cleanup: dns_fixedname_invalidate(&trans->fixedname); return (result); }
isc_result_t dhcp_isc_name(unsigned char *namestr, dns_fixedname_t *namefix, dns_name_t **name) { size_t namelen; isc_buffer_t b; isc_result_t result; namelen = strlen((char *)namestr); isc_buffer_init(&b, namestr, namelen); isc_buffer_add(&b, namelen); dns_fixedname_init(namefix); *name = dns_fixedname_name(namefix); result = dns_name_fromtext(*name, &b, dns_rootname, 0, NULL); isc_buffer_invalidate(&b); return(result); }
static void parse_name(char **cmdlinep, dns_name_t *name) { isc_result_t result; char *word; isc_buffer_t source; word = nsu_strsep(cmdlinep, " \t\r\n"); if (word == NULL || *word == 0) { fprintf(stderr, "could not read owner name\n"); exit(1); } isc_buffer_init(&source, word, strlen(word)); isc_buffer_add(&source, strlen(word)); result = dns_name_fromtext(name, &source, dns_rootname, 0, NULL); check_result(result, "dns_name_fromtext"); isc_buffer_invalidate(&source); }