diff --git a/bin/tests/system/conf.sh.common b/bin/tests/system/conf.sh.common index cf1b5e6513..ac1845860f 100644 --- a/bin/tests/system/conf.sh.common +++ b/bin/tests/system/conf.sh.common @@ -730,7 +730,6 @@ export PYTHON export RESOLVE export RNDC export RRCHECKER -export SAMPLEUPDATE export SIGNER export SUBDIRS export TMPDIR diff --git a/bin/tests/system/conf.sh.in b/bin/tests/system/conf.sh.in index 05f1a4fe71..08983b65f8 100644 --- a/bin/tests/system/conf.sh.in +++ b/bin/tests/system/conf.sh.in @@ -68,7 +68,6 @@ KEYCREATE=$TOP_BUILDDIR/bin/tests/system/tkey/keycreate KEYDELETE=$TOP_BUILDDIR/bin/tests/system/tkey/keydelete MAKEJOURNAL=$TOP_BUILDDIR/bin/tests/system/makejournal PIPEQUERIES=$TOP_BUILDDIR/bin/tests/system/pipelined/pipequeries -SAMPLEUPDATE=$TOP_BUILDDIR/lib/samples/sample-update # we don't want a KRB5_CONFIG setting breaking the tests KRB5_CONFIG=/dev/null diff --git a/bin/tests/system/conf.sh.win32 b/bin/tests/system/conf.sh.win32 index 37e4379c84..ca41063109 100644 --- a/bin/tests/system/conf.sh.win32 +++ b/bin/tests/system/conf.sh.win32 @@ -56,7 +56,6 @@ REVOKE=$TOP_BUILDDIR/Build/$VSCONF/dnssec-revoke@EXEEXT@ RNDC=$TOP_BUILDDIR/Build/$VSCONF/rndc@EXEEXT@ RNDCCONFGEN=$TOP_BUILDDIR/Build/$VSCONF/rndc-confgen@EXEEXT@ RRCHECKER=$TOP_BUILDDIR/Build/$VSCONF/named-rrchecker@EXEEXT@ -SAMPLEUPDATE=$TOP_BUILDDIR/Build/$VSCONF/update@EXEEXT@ SETTIME=$TOP_BUILDDIR/Build/$VSCONF/dnssec-settime@EXEEXT@ SIGNER=$TOP_BUILDDIR/Build/$VSCONF/dnssec-signzone@EXEEXT@ TSIGKEYGEN=$TOP_BUILDDIR/Build/$VSCONF/tsig-keygen@EXEEXT@ @@ -71,7 +70,6 @@ KEYCREATE=$TOP_BUILDDIR/Build/$VSCONF/keycreate@EXEEXT@ KEYDELETE=$TOP_BUILDDIR/Build/$VSCONF/keydelete@EXEEXT@ MAKEJOURNAL=$TOP_BUILDDIR/Build/$VSCONF/makejournal@EXEEXT@ PIPEQUERIES=$TOP_BUILDDIR/Build/$VSCONF/pipequeries@EXEEXT@ -# to port SAMPLEUPDATE=$TOP_BUILDDIR/lib/samples/sample-update # we don't want a KRB5_CONFIG setting breaking the tests KRB5_CONFIG=NUL diff --git a/bin/tests/system/nsupdate/tests.sh b/bin/tests/system/nsupdate/tests.sh index 4274f86dd3..1bbb804584 100755 --- a/bin/tests/system/nsupdate/tests.sh +++ b/bin/tests/system/nsupdate/tests.sh @@ -1428,88 +1428,6 @@ EOF [ $ret = 0 ] || { echo_i "failed"; status=1; } fi -# -# Add client library tests here -# - -if test unset != "${SAMPLEUPDATE:-unset}" -a -x "${SAMPLEUPDATE}" -then - - n=`expr $n + 1` - ret=0 - echo_i "check that dns_client_update handles prerequisite NXDOMAIN failure ($n)" - $SAMPLEUPDATE -P ${PORT} -a 10.53.0.1 -a 10.53.0.2 -p "nxdomain exists.sample" \ - add "nxdomain-exists.sample 0 in a 1.2.3.4" > update.out.test$n 2>&1 - $SAMPLEUPDATE -P ${PORT} -a 10.53.0.2 -p "nxdomain exists.sample" \ - add "check-nxdomain-exists.sample 0 in a 1.2.3.4" > update.out.check$n 2>&1 - $DIG $DIGOPTS +tcp @10.53.0.1 a nxdomain-exists.sample > dig.out.ns1.test$n - $DIG $DIGOPTS +tcp @10.53.0.2 a nxdomain-exists.sample > dig.out.ns2.test$n - $DIG $DIGOPTS +tcp @10.53.0.2 a check-nxdomain-exists.sample > check.out.ns2.test$n - grep "update failed: YXDOMAIN" update.out.test$n > /dev/null || ret=1 - grep "update succeeded" update.out.check$n > /dev/null || ret=1 - grep "status: NXDOMAIN" dig.out.ns1.test$n > /dev/null || ret=1 - grep "status: NXDOMAIN" dig.out.ns2.test$n > /dev/null || ret=1 - grep "status: NOERROR" check.out.ns2.test$n > /dev/null || ret=1 - [ $ret = 0 ] || { echo_i "failed"; status=1; } - - n=`expr $n + 1` - ret=0 - echo_i "check that dns_client_update handles prerequisite YXDOMAIN failure ($n)" - $SAMPLEUPDATE -P ${PORT} -a 10.53.0.1 -a 10.53.0.2 -p "yxdomain nxdomain.sample" \ - add "yxdomain-nxdomain.sample 0 in a 1.2.3.4" > update.out.test$n 2>&1 - $SAMPLEUPDATE -P ${PORT} -a 10.53.0.2 -p "yxdomain nxdomain.sample" \ - add "check-yxdomain-nxdomain.sample 0 in a 1.2.3.4" > update.out.check$n 2>&1 - $DIG $DIGOPTS +tcp @10.53.0.1 a nxdomain-exists.sample > dig.out.ns1.test$n - $DIG $DIGOPTS +tcp @10.53.0.2 a nxdomain-exists.sample > dig.out.ns2.test$n - $DIG $DIGOPTS +tcp @10.53.0.2 a check-nxdomain-exists.sample > check.out.ns2.test$n - grep "update failed: NXDOMAIN" update.out.test$n > /dev/null || ret=1 - grep "update succeeded" update.out.check$n > /dev/null || ret=1 - grep "status: NXDOMAIN" dig.out.ns1.test$n > /dev/null || ret=1 - grep "status: NXDOMAIN" dig.out.ns2.test$n > /dev/null || ret=1 - grep "status: NOERROR" check.out.ns2.test$n > /dev/null || ret=1 - [ $ret = 0 ] || { echo_i "failed"; status=1; } - - n=`expr $n + 1` - ret=0 - echo_i "check that dns_client_update handles prerequisite NXRRSET failure ($n)" - $SAMPLEUPDATE -P ${PORT} -a 10.53.0.1 -a 10.53.0.2 -p "nxrrset exists.sample TXT This RRset exists." \ - add "nxrrset-exists.sample 0 in a 1.2.3.4" > update.out.test$n 2>&1 - $SAMPLEUPDATE -P ${PORT} -a 10.53.0.2 -p "nxrrset exists.sample TXT This RRset exists." \ - add "check-nxrrset-exists.sample 0 in a 1.2.3.4" > update.out.check$n 2>&1 - $DIG $DIGOPTS +tcp @10.53.0.1 a nxrrset-exists.sample > dig.out.ns1.test$n - $DIG $DIGOPTS +tcp @10.53.0.2 a nxrrset-exists.sample > dig.out.ns2.test$n - $DIG $DIGOPTS +tcp @10.53.0.2 a check-nxrrset-exists.sample > check.out.ns2.test$n - grep "update failed: YXRRSET" update.out.test$n > /dev/null || ret=1 - grep "update succeeded" update.out.check$n > /dev/null || ret=1 - grep "status: NXDOMAIN" dig.out.ns1.test$n > /dev/null || ret=1 - grep "status: NXDOMAIN" dig.out.ns2.test$n > /dev/null || ret=1 - grep "status: NOERROR" check.out.ns2.test$n > /dev/null || ret=1 - [ $ret = 0 ] || { echo_i "failed"; status=1; } - - n=`expr $n + 1` - ret=0 - echo_i "check that dns_client_update handles prerequisite YXRRSET failure ($n)" - $SAMPLEUPDATE -s -P ${PORT} -a 10.53.0.1 -a 10.53.0.2 \ - -p "yxrrset no-txt.sample TXT" \ - add "yxrrset-nxrrset.sample 0 in a 1.2.3.4" > update.out.test$n 2>&1 - $SAMPLEUPDATE -P ${PORT} -a 10.53.0.2 -p "yxrrset no-txt.sample TXT" \ - add "check-yxrrset-nxrrset.sample 0 in a 1.2.3.4" > update.out.check$n 2>&1 - $DIG $DIGOPTS +tcp @10.53.0.1 a yxrrset-nxrrset.sample > dig.out.ns1.test$n - $DIG $DIGOPTS +tcp @10.53.0.2 a yxrrset-nxrrset.sample > dig.out.ns2.test$n - $DIG $DIGOPTS +tcp @10.53.0.2 a check-yxrrset-nxrrset.sample > check.out.ns2.test$n - grep "update failed: NXRRSET" update.out.test$n > /dev/null || ret=1 - grep "update succeeded" update.out.check$n > /dev/null || ret=1 - grep "status: NXDOMAIN" dig.out.ns1.test$n > /dev/null || ret=1 - grep "status: NXDOMAIN" dig.out.ns2.test$n > /dev/null || ret=1 - grep "status: NOERROR" check.out.ns2.test$n > /dev/null || ret=1 - grep "2nd update failed: NXRRSET" update.out.test$n > /dev/null || ret=1 - [ $ret = 0 ] || { echo_i "failed"; status=1; } - -fi - -# -# End client library tests here -# echo_i "exit status: $status" [ $status -eq 0 ] || exit 1 diff --git a/bin/win32/BINDInstall/BINDInstall.vcxproj.in b/bin/win32/BINDInstall/BINDInstall.vcxproj.in index 92de623ada..9e70c009b5 100644 --- a/bin/win32/BINDInstall/BINDInstall.vcxproj.in +++ b/bin/win32/BINDInstall/BINDInstall.vcxproj.in @@ -308,15 +308,9 @@ {CB2A29F6-E73B-40AB-8AC4-2C1AAE7280BD} - - {FF440E85-7450-439C-82EE-04C464512D0E} - {F66D8B7E-721D-4602-99AD-820D19AD1313} - - {05682E12-523F-4DAE-8E6D-ADFDBC308AFD} - @END SAMPLES {0D745CD9-FC3B-49DC-99BE-1E6DF85593F0} diff --git a/lib/dns/client.c b/lib/dns/client.c index c1a9b95d87..701202503b 100644 --- a/lib/dns/client.c +++ b/lib/dns/client.c @@ -95,9 +95,6 @@ struct dns_client { dns_dispatch_t *dispatchv4; dns_dispatch_t *dispatchv6; - unsigned int update_timeout; - unsigned int update_udptimeout; - unsigned int update_udpretries; unsigned int find_timeout; unsigned int find_udpretries; @@ -107,17 +104,8 @@ struct dns_client { dns_viewlist_t viewlist; ISC_LIST(struct resctx) resctxs; ISC_LIST(struct reqctx) reqctxs; - ISC_LIST(struct updatectx) updatectxs; }; -/*% - * Timeout/retry constants for dynamic update borrowed from nsupdate - */ -#define DEF_UPDATE_TIMEOUT 300 -#define MIN_UPDATE_TIMEOUT 30 -#define DEF_UPDATE_UDPTIMEOUT 3 -#define DEF_UPDATE_UDPRETRIES 3 - #define DEF_FIND_TIMEOUT 5 #define DEF_FIND_UDPRETRIES 3 @@ -202,65 +190,8 @@ typedef struct reqarg { bool canceled; } reqarg_t; -/*% - * Argument of an internal event for synchronous name resolution. - */ -typedef struct updatearg { - /* Unlocked */ - isc_appctx_t *actx; - dns_client_t *client; - isc_mutex_t lock; - - /* Locked */ - isc_result_t result; - dns_clientupdatetrans_t *trans; - bool canceled; -} updatearg_t; - -/*% - * Internal state for a single dynamic update procedure - */ -typedef struct updatectx { - /* Unlocked */ - unsigned int magic; - isc_mutex_t lock; - dns_client_t *client; - bool want_tcp; - - /* Locked */ - dns_request_t *updatereq; - dns_request_t *soareq; - dns_clientrestrans_t *restrans; - dns_clientrestrans_t *restrans2; - bool canceled; - - /* Task Locked */ - ISC_LINK(struct updatectx) link; - dns_clientupdatestate_t state; - dns_rdataclass_t rdclass; - dns_view_t *view; - dns_message_t *updatemsg; - dns_message_t *soaquery; - dns_clientupdateevent_t *event; - dns_tsigkey_t *tsigkey; - dst_key_t *sig0key; - dns_name_t *firstname; - dns_name_t soaqname; - dns_fixedname_t zonefname; - dns_name_t *zonename; - isc_sockaddrlist_t servers; - unsigned int nservers; - isc_sockaddr_t *currentserver; - struct updatectx *bp4; - struct updatectx *bp6; -} updatectx_t; - -static isc_result_t -request_soa(updatectx_t *uctx); static void client_resfind(resctx_t *rctx, dns_fetchevent_t *event); -static isc_result_t -send_update(updatectx_t *uctx); /* * Try honoring the operating system's preferred ephemeral port range. @@ -397,84 +328,6 @@ createview(isc_mem_t *mctx, dns_rdataclass_t rdclass, isc_taskmgr_t *taskmgr, return (ISC_R_SUCCESS); } -isc_result_t -dns_client_create(dns_client_t **clientp, unsigned int options) { - isc_result_t result; - isc_mem_t *mctx = NULL; - isc_appctx_t *actx = NULL; - isc_taskmgr_t *taskmgr = NULL; - isc_socketmgr_t *socketmgr = NULL; - isc_timermgr_t *timermgr = NULL; -#if 0 - /* XXXMPA add debug logging support */ - isc_log_t *lctx = NULL; - isc_logconfig_t *logconfig = NULL; - unsigned int logdebuglevel = 0; -#endif /* if 0 */ - - isc_mem_create(&mctx); - result = isc_appctx_create(mctx, &actx); - if (result != ISC_R_SUCCESS) { - goto cleanup; - } - result = isc_app_ctxstart(actx); - if (result != ISC_R_SUCCESS) { - goto cleanup; - } - result = isc_taskmgr_createinctx(mctx, 1, 0, &taskmgr); - if (result != ISC_R_SUCCESS) { - goto cleanup; - } - result = isc_socketmgr_createinctx(mctx, &socketmgr); - if (result != ISC_R_SUCCESS) { - goto cleanup; - } - result = isc_timermgr_createinctx(mctx, &timermgr); - if (result != ISC_R_SUCCESS) { - goto cleanup; - } -#if 0 - isc_log_create(mctx, &lctx, &logconfig); - isc_log_setcontext(lctx); - dns_log_init(lctx); - dns_log_setcontext(lctx); - result = isc_log_usechannel(logconfig, "default_debug", NULL, NULL); - if (result != ISC_R_SUCCESS) { - goto cleanup; - } - isc_log_setdebuglevel(lctx, logdebuglevel); -#endif /* if 0 */ - result = dns_client_createx(mctx, actx, taskmgr, socketmgr, timermgr, - options, clientp, NULL, NULL); - if (result != ISC_R_SUCCESS) { - goto cleanup; - } - - (*clientp)->attributes |= DNS_CLIENTATTR_OWNCTX; - - /* client has its own reference to mctx, so we can detach it here */ - isc_mem_detach(&mctx); - - return (ISC_R_SUCCESS); - -cleanup: - if (taskmgr != NULL) { - isc_taskmgr_destroy(&taskmgr); - } - if (timermgr != NULL) { - isc_timermgr_destroy(&timermgr); - } - if (socketmgr != NULL) { - isc_socketmgr_destroy(&socketmgr); - } - if (actx != NULL) { - isc_appctx_destroy(&actx); - } - isc_mem_detach(&mctx); - - return (result); -} - isc_result_t dns_client_createx(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr, isc_socketmgr_t *socketmgr, isc_timermgr_t *timermgr, @@ -563,14 +416,10 @@ dns_client_createx(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr, ISC_LIST_INIT(client->resctxs); ISC_LIST_INIT(client->reqctxs); - ISC_LIST_INIT(client->updatectxs); client->mctx = NULL; isc_mem_attach(mctx, &client->mctx); - client->update_timeout = DEF_UPDATE_TIMEOUT; - client->update_udptimeout = DEF_UPDATE_UDPTIMEOUT; - client->update_udpretries = DEF_UPDATE_UDPRETRIES; client->find_timeout = DEF_FIND_TIMEOUT; client->find_udpretries = DEF_FIND_UDPRETRIES; client->attributes = 0; @@ -1854,1335 +1703,3 @@ dns_client_destroyreqtrans(dns_clientreqtrans_t **transp) { dns_client_destroy(&client); } - -/*% - * Dynamic update routines - */ -static isc_result_t -rcode2result(dns_rcode_t rcode) { - /* XXX: isn't there a similar function? */ - switch (rcode) { - case dns_rcode_formerr: - return (DNS_R_FORMERR); - case dns_rcode_servfail: - return (DNS_R_SERVFAIL); - case dns_rcode_nxdomain: - return (DNS_R_NXDOMAIN); - case dns_rcode_notimp: - return (DNS_R_NOTIMP); - case dns_rcode_refused: - return (DNS_R_REFUSED); - case dns_rcode_yxdomain: - return (DNS_R_YXDOMAIN); - case dns_rcode_yxrrset: - return (DNS_R_YXRRSET); - case dns_rcode_nxrrset: - return (DNS_R_NXRRSET); - case dns_rcode_notauth: - return (DNS_R_NOTAUTH); - case dns_rcode_notzone: - return (DNS_R_NOTZONE); - case dns_rcode_badvers: - return (DNS_R_BADVERS); - } - - return (ISC_R_FAILURE); -} - -static void -update_sendevent(updatectx_t *uctx, isc_result_t result) { - isc_task_t *task; - - dns_message_detach(&uctx->updatemsg); - if (uctx->tsigkey != NULL) { - dns_tsigkey_detach(&uctx->tsigkey); - } - if (uctx->sig0key != NULL) { - dst_key_free(&uctx->sig0key); - } - - if (uctx->canceled) { - uctx->event->result = ISC_R_CANCELED; - } else { - uctx->event->result = result; - } - uctx->event->state = uctx->state; - task = uctx->event->ev_sender; - uctx->event->ev_sender = uctx; - isc_task_sendanddetach(&task, ISC_EVENT_PTR(&uctx->event)); -} - -static void -update_done(isc_task_t *task, isc_event_t *event) { - isc_result_t result; - dns_requestevent_t *reqev = NULL; - dns_request_t *request; - dns_message_t *answer = NULL; - updatectx_t *uctx = event->ev_arg; - dns_client_t *client; - unsigned int timeout, reqoptions; - - UNUSED(task); - - REQUIRE(event->ev_type == DNS_EVENT_REQUESTDONE); - reqev = (dns_requestevent_t *)event; - request = reqev->request; - REQUIRE(UCTX_VALID(uctx)); - client = uctx->client; - REQUIRE(DNS_CLIENT_VALID(client)); - - result = reqev->result; - if (result != ISC_R_SUCCESS) { - goto out; - } - - dns_message_create(client->mctx, DNS_MESSAGE_INTENTPARSE, &answer); - uctx->state = dns_clientupdatestate_done; - result = dns_request_getresponse(request, answer, - DNS_MESSAGEPARSE_PRESERVEORDER); - if (result == ISC_R_SUCCESS && answer->rcode != dns_rcode_noerror) { - result = rcode2result(answer->rcode); - } - -out: - if (answer != NULL) { - dns_message_detach(&answer); - } - isc_event_free(&event); - - LOCK(&uctx->lock); - uctx->currentserver = ISC_LIST_NEXT(uctx->currentserver, link); - dns_request_destroy(&uctx->updatereq); - /* - * Moving on to the next server shouldn't change the result - * for NXDOMAIN, YXDOMAIN, NXRRSET and YXRRSET as they - * indicate a prerequisite failure. REFUSED should also - * be consistent across all servers but often isn't as that - * is policy rather that zone content driven (slaves that - * aren't willing to forward should return NOTIMPL). NOTZONE - * indicates that we stuffed up the request construction so - * don't retry. - */ - if (result != ISC_R_SUCCESS && result != DNS_R_NXDOMAIN && - result != DNS_R_YXDOMAIN && result != DNS_R_YXRRSET && - result != DNS_R_NXRRSET && result != DNS_R_NOTZONE && - !uctx->canceled && uctx->currentserver != NULL) - { - dns_message_renderreset(uctx->updatemsg); - dns_message_settsigkey(uctx->updatemsg, NULL); - - timeout = client->update_timeout / uctx->nservers; - if (timeout < MIN_UPDATE_TIMEOUT) { - timeout = MIN_UPDATE_TIMEOUT; - } - reqoptions = 0; - if (uctx->want_tcp) { - reqoptions |= DNS_REQUESTOPT_TCP; - } - result = dns_request_createvia( - uctx->view->requestmgr, uctx->updatemsg, NULL, - uctx->currentserver, -1, reqoptions, uctx->tsigkey, - timeout, client->update_udptimeout, - client->update_udpretries, client->task, update_done, - uctx, &uctx->updatereq); - UNLOCK(&uctx->lock); - - if (result == ISC_R_SUCCESS) { - /* XXX: should we keep the 'done' state here? */ - uctx->state = dns_clientupdatestate_sent; - return; - } - } else { - UNLOCK(&uctx->lock); - } - - update_sendevent(uctx, result); -} - -static isc_result_t -send_update(updatectx_t *uctx) { - isc_result_t result; - dns_name_t *name = NULL; - dns_rdataset_t *rdataset = NULL; - dns_client_t *client = uctx->client; - unsigned int timeout, reqoptions; - - REQUIRE(uctx->zonename != NULL && uctx->currentserver != NULL); - - result = dns_message_gettempname(uctx->updatemsg, &name); - if (result != ISC_R_SUCCESS) { - return (result); - } - dns_name_init(name, NULL); - dns_name_clone(uctx->zonename, name); - result = dns_message_gettemprdataset(uctx->updatemsg, &rdataset); - if (result != ISC_R_SUCCESS) { - dns_message_puttempname(uctx->updatemsg, &name); - return (result); - } - dns_rdataset_makequestion(rdataset, uctx->rdclass, dns_rdatatype_soa); - ISC_LIST_INIT(name->list); - ISC_LIST_APPEND(name->list, rdataset, link); - dns_message_addname(uctx->updatemsg, name, DNS_SECTION_ZONE); - if (uctx->tsigkey == NULL && uctx->sig0key != NULL) { - result = dns_message_setsig0key(uctx->updatemsg, uctx->sig0key); - if (result != ISC_R_SUCCESS) { - return (result); - } - } - timeout = client->update_timeout / uctx->nservers; - if (timeout < MIN_UPDATE_TIMEOUT) { - timeout = MIN_UPDATE_TIMEOUT; - } - reqoptions = 0; - if (uctx->want_tcp) { - reqoptions |= DNS_REQUESTOPT_TCP; - } - result = dns_request_createvia( - uctx->view->requestmgr, uctx->updatemsg, NULL, - uctx->currentserver, -1, reqoptions, uctx->tsigkey, timeout, - client->update_udptimeout, client->update_udpretries, - client->task, update_done, uctx, &uctx->updatereq); - if (result == ISC_R_SUCCESS && - uctx->state == dns_clientupdatestate_prepare) { - uctx->state = dns_clientupdatestate_sent; - } - - return (result); -} - -static void -resolveaddr_done(isc_task_t *task, isc_event_t *event) { - isc_result_t result; - int family; - dns_rdatatype_t qtype; - dns_clientresevent_t *rev = (dns_clientresevent_t *)event; - dns_name_t *name; - dns_rdataset_t *rdataset; - updatectx_t *uctx; - bool completed = false; - - UNUSED(task); - - REQUIRE(event->ev_arg != NULL); - uctx = *(updatectx_t **)event->ev_arg; - REQUIRE(UCTX_VALID(uctx)); - - if (event->ev_arg == &uctx->bp4) { - family = AF_INET; - qtype = dns_rdatatype_a; - LOCK(&uctx->lock); - dns_client_destroyrestrans(&uctx->restrans); - UNLOCK(&uctx->lock); - } else { - INSIST(event->ev_arg == &uctx->bp6); - family = AF_INET6; - qtype = dns_rdatatype_aaaa; - LOCK(&uctx->lock); - dns_client_destroyrestrans(&uctx->restrans2); - UNLOCK(&uctx->lock); - } - - result = rev->result; - if (result != ISC_R_SUCCESS) { - goto done; - } - - for (name = ISC_LIST_HEAD(rev->answerlist); name != NULL; - name = ISC_LIST_NEXT(name, link)) - { - for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; - rdataset = ISC_LIST_NEXT(rdataset, link)) - { - if (!dns_rdataset_isassociated(rdataset)) { - continue; - } - if (rdataset->type != qtype) { - continue; - } - - for (result = dns_rdataset_first(rdataset); - result == ISC_R_SUCCESS; - result = dns_rdataset_next(rdataset)) - { - dns_rdata_t rdata; - dns_rdata_in_a_t rdata_a; - dns_rdata_in_aaaa_t rdata_aaaa; - isc_sockaddr_t *sa; - - sa = isc_mem_get(uctx->client->mctx, - sizeof(*sa)); - - dns_rdata_init(&rdata); - switch (family) { - case AF_INET: - dns_rdataset_current(rdataset, &rdata); - result = dns_rdata_tostruct( - &rdata, &rdata_a, NULL); - RUNTIME_CHECK(result == ISC_R_SUCCESS); - isc_sockaddr_fromin( - sa, &rdata_a.in_addr, 53); - dns_rdata_freestruct(&rdata_a); - break; - case AF_INET6: - dns_rdataset_current(rdataset, &rdata); - result = dns_rdata_tostruct( - &rdata, &rdata_aaaa, NULL); - RUNTIME_CHECK(result == ISC_R_SUCCESS); - isc_sockaddr_fromin6( - sa, &rdata_aaaa.in6_addr, 53); - dns_rdata_freestruct(&rdata_aaaa); - break; - } - - ISC_LINK_INIT(sa, link); - ISC_LIST_APPEND(uctx->servers, sa, link); - uctx->nservers++; - } - } - } - -done: - dns_client_freeresanswer(uctx->client, &rev->answerlist); - isc_event_free(&event); - - LOCK(&uctx->lock); - if (uctx->restrans == NULL && uctx->restrans2 == NULL) { - completed = true; - } - UNLOCK(&uctx->lock); - - if (completed) { - INSIST(uctx->currentserver == NULL); - uctx->currentserver = ISC_LIST_HEAD(uctx->servers); - if (uctx->currentserver != NULL && !uctx->canceled) { - send_update(uctx); - } else { - if (result == ISC_R_SUCCESS) { - result = ISC_R_NOTFOUND; - } - update_sendevent(uctx, result); - } - } -} - -static isc_result_t -process_soa(updatectx_t *uctx, dns_rdataset_t *soaset, - const dns_name_t *soaname) { - isc_result_t result; - dns_rdata_t soarr = DNS_RDATA_INIT; - dns_rdata_soa_t soa; - dns_name_t primary; - unsigned int resoptions; - - result = dns_rdataset_first(soaset); - if (result != ISC_R_SUCCESS) { - return (result); - } - dns_rdata_init(&soarr); - dns_rdataset_current(soaset, &soarr); - result = dns_rdata_tostruct(&soarr, &soa, NULL); - if (result != ISC_R_SUCCESS) { - return (result); - } - - dns_name_init(&primary, NULL); - dns_name_clone(&soa.origin, &primary); - - if (uctx->zonename == NULL) { - uctx->zonename = dns_fixedname_name(&uctx->zonefname); - dns_name_copynf(soaname, uctx->zonename); - } - - if (uctx->currentserver != NULL) { - result = send_update(uctx); - } else { - /* - * Get addresses of the primary server. We don't use the ADB - * feature so that we could avoid caching data. - */ - LOCK(&uctx->lock); - uctx->bp4 = uctx; - resoptions = 0; - if (uctx->want_tcp) { - resoptions |= DNS_CLIENTRESOPT_TCP; - } - result = dns_client_startresolve( - uctx->client, &primary, uctx->rdclass, dns_rdatatype_a, - resoptions, uctx->client->task, resolveaddr_done, - &uctx->bp4, &uctx->restrans); - if (result == ISC_R_SUCCESS) { - uctx->bp6 = uctx; - result = dns_client_startresolve( - uctx->client, &primary, uctx->rdclass, - dns_rdatatype_aaaa, resoptions, - uctx->client->task, resolveaddr_done, - &uctx->bp6, &uctx->restrans2); - } - UNLOCK(&uctx->lock); - } - - dns_rdata_freestruct(&soa); - - return (result); -} - -static void -receive_soa(isc_task_t *task, isc_event_t *event) { - dns_requestevent_t *reqev = NULL; - updatectx_t *uctx; - dns_client_t *client; - isc_result_t result, eresult; - dns_request_t *request; - dns_message_t *rcvmsg = NULL; - dns_section_t section; - dns_rdataset_t *soaset = NULL; - int pass = 0; - dns_name_t *name; - dns_message_t *soaquery = NULL; - isc_sockaddr_t *addr; - bool seencname = false; - bool droplabel = false; - dns_name_t tname; - unsigned int nlabels, reqoptions; - - UNUSED(task); - - REQUIRE(event->ev_type == DNS_EVENT_REQUESTDONE); - reqev = (dns_requestevent_t *)event; - request = reqev->request; - result = eresult = reqev->result; - POST(result); - uctx = reqev->ev_arg; - client = uctx->client; - soaquery = uctx->soaquery; - addr = uctx->currentserver; - INSIST(addr != NULL); - - isc_event_free(&event); - - if (eresult != ISC_R_SUCCESS) { - result = eresult; - goto out; - } - - dns_message_create(uctx->client->mctx, DNS_MESSAGE_INTENTPARSE, - &rcvmsg); - result = dns_request_getresponse(request, rcvmsg, - DNS_MESSAGEPARSE_PRESERVEORDER); - - if (result == DNS_R_TSIGERRORSET) { - dns_request_t *newrequest = NULL; - - /* Retry SOA request without TSIG */ - dns_message_detach(&rcvmsg); - dns_message_renderreset(uctx->soaquery); - reqoptions = 0; - if (uctx->want_tcp) { - reqoptions |= DNS_REQUESTOPT_TCP; - } - result = dns_request_createvia( - uctx->view->requestmgr, uctx->soaquery, NULL, addr, -1, - reqoptions, NULL, client->find_timeout * 20, - client->find_timeout, 3, uctx->client->task, - receive_soa, uctx, &newrequest); - if (result == ISC_R_SUCCESS) { - LOCK(&uctx->lock); - dns_request_destroy(&uctx->soareq); - uctx->soareq = newrequest; - UNLOCK(&uctx->lock); - - return; - } - goto out; - } - - section = DNS_SECTION_ANSWER; - POST(section); - - if (rcvmsg->rcode != dns_rcode_noerror && - rcvmsg->rcode != dns_rcode_nxdomain) { - result = rcode2result(rcvmsg->rcode); - goto out; - } - -lookforsoa: - if (pass == 0) { - section = DNS_SECTION_ANSWER; - } else if (pass == 1) { - section = DNS_SECTION_AUTHORITY; - } else { - droplabel = true; - goto out; - } - - result = dns_message_firstname(rcvmsg, section); - if (result != ISC_R_SUCCESS) { - pass++; - goto lookforsoa; - } - while (result == ISC_R_SUCCESS) { - name = NULL; - dns_message_currentname(rcvmsg, section, &name); - soaset = NULL; - result = dns_message_findtype(name, dns_rdatatype_soa, 0, - &soaset); - if (result == ISC_R_SUCCESS) { - break; - } - if (section == DNS_SECTION_ANSWER) { - dns_rdataset_t *tset = NULL; - if (dns_message_findtype(name, dns_rdatatype_cname, 0, - &tset) == ISC_R_SUCCESS || - dns_message_findtype(name, dns_rdatatype_dname, 0, - &tset) == ISC_R_SUCCESS) - { - seencname = true; - break; - } - } - - result = dns_message_nextname(rcvmsg, section); - } - - if (soaset == NULL && !seencname) { - pass++; - goto lookforsoa; - } - - if (seencname) { - droplabel = true; - goto out; - } - - result = process_soa(uctx, soaset, name); - -out: - if (droplabel) { - result = dns_message_firstname(soaquery, DNS_SECTION_QUESTION); - INSIST(result == ISC_R_SUCCESS); - name = NULL; - dns_message_currentname(soaquery, DNS_SECTION_QUESTION, &name); - nlabels = dns_name_countlabels(name); - if (nlabels == 1) { - result = DNS_R_SERVFAIL; /* is there a better error? */ - } else { - dns_name_init(&tname, NULL); - dns_name_getlabelsequence(name, 1, nlabels - 1, &tname); - dns_name_clone(&tname, name); - dns_request_destroy(&request); - LOCK(&uctx->lock); - uctx->soareq = NULL; - UNLOCK(&uctx->lock); - dns_message_renderreset(soaquery); - dns_message_settsigkey(soaquery, NULL); - reqoptions = 0; - if (uctx->want_tcp) { - reqoptions |= DNS_REQUESTOPT_TCP; - } - result = dns_request_createvia( - uctx->view->requestmgr, soaquery, NULL, - uctx->currentserver, -1, reqoptions, - uctx->tsigkey, client->find_timeout * 20, - client->find_timeout, 3, client->task, - receive_soa, uctx, &uctx->soareq); - } - } - - if (!droplabel || result != ISC_R_SUCCESS) { - dns_message_detach(&uctx->soaquery); - LOCK(&uctx->lock); - dns_request_destroy(&uctx->soareq); - UNLOCK(&uctx->lock); - } - - if (rcvmsg != NULL) { - dns_message_detach(&rcvmsg); - } - - if (result != ISC_R_SUCCESS) { - update_sendevent(uctx, result); - } -} - -static isc_result_t -request_soa(updatectx_t *uctx) { - isc_result_t result; - dns_message_t *soaquery = uctx->soaquery; - dns_name_t *name = NULL; - dns_rdataset_t *rdataset = NULL; - unsigned int reqoptions; - - if (soaquery == NULL) { - dns_message_create(uctx->client->mctx, DNS_MESSAGE_INTENTRENDER, - &soaquery); - } - soaquery->flags |= DNS_MESSAGEFLAG_RD; - result = dns_message_gettempname(soaquery, &name); - if (result != ISC_R_SUCCESS) { - goto fail; - } - result = dns_message_gettemprdataset(soaquery, &rdataset); - if (result != ISC_R_SUCCESS) { - goto fail; - } - dns_rdataset_makequestion(rdataset, uctx->rdclass, dns_rdatatype_soa); - dns_name_clone(uctx->firstname, name); - ISC_LIST_APPEND(name->list, rdataset, link); - dns_message_addname(soaquery, name, DNS_SECTION_QUESTION); - rdataset = NULL; - name = NULL; - reqoptions = 0; - if (uctx->want_tcp) { - reqoptions |= DNS_REQUESTOPT_TCP; - } - - result = dns_request_createvia( - uctx->view->requestmgr, soaquery, NULL, uctx->currentserver, -1, - reqoptions, uctx->tsigkey, uctx->client->find_timeout * 20, - uctx->client->find_timeout, 3, uctx->client->task, receive_soa, - uctx, &uctx->soareq); - if (result == ISC_R_SUCCESS) { - uctx->soaquery = soaquery; - return (ISC_R_SUCCESS); - } - -fail: - if (rdataset != NULL) { - ISC_LIST_UNLINK(name->list, rdataset, link); /* for safety */ - dns_message_puttemprdataset(soaquery, &rdataset); - } - if (name != NULL) { - dns_message_puttempname(soaquery, &name); - } - dns_message_detach(&soaquery); - - return (result); -} - -static void -resolvesoa_done(isc_task_t *task, isc_event_t *event) { - dns_clientresevent_t *rev = (dns_clientresevent_t *)event; - updatectx_t *uctx; - dns_name_t *name, tname; - dns_rdataset_t *rdataset = NULL; - isc_result_t result = rev->result; - unsigned int nlabels, resoptions; - - UNUSED(task); - - uctx = event->ev_arg; - REQUIRE(UCTX_VALID(uctx)); - - LOCK(&uctx->lock); - dns_client_destroyrestrans(&uctx->restrans); - UNLOCK(&uctx->lock); - - uctx = event->ev_arg; - if (result != ISC_R_SUCCESS && result != DNS_R_NCACHENXDOMAIN && - result != DNS_R_NCACHENXRRSET) - { - /* XXX: what about DNSSEC failure? */ - goto out; - } - - for (name = ISC_LIST_HEAD(rev->answerlist); name != NULL; - name = ISC_LIST_NEXT(name, link)) - { - for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; - rdataset = ISC_LIST_NEXT(rdataset, link)) - { - if (dns_rdataset_isassociated(rdataset) && - rdataset->type == dns_rdatatype_soa) { - break; - } - } - } - - if (rdataset == NULL) { - /* Drop one label and retry resolution. */ - nlabels = dns_name_countlabels(&uctx->soaqname); - if (nlabels == 1) { - result = DNS_R_SERVFAIL; /* is there a better error? */ - goto out; - } - dns_name_init(&tname, NULL); - dns_name_getlabelsequence(&uctx->soaqname, 1, nlabels - 1, - &tname); - dns_name_clone(&tname, &uctx->soaqname); - resoptions = 0; - if (uctx->want_tcp) { - resoptions |= DNS_CLIENTRESOPT_TCP; - } - - result = dns_client_startresolve( - uctx->client, &uctx->soaqname, uctx->rdclass, - dns_rdatatype_soa, resoptions, uctx->client->task, - resolvesoa_done, uctx, &uctx->restrans); - } else { - result = process_soa(uctx, rdataset, &uctx->soaqname); - } - -out: - dns_client_freeresanswer(uctx->client, &rev->answerlist); - isc_event_free(&event); - - if (result != ISC_R_SUCCESS) { - update_sendevent(uctx, result); - } -} - -static isc_result_t -copy_name(isc_mem_t *mctx, dns_message_t *msg, const dns_name_t *name, - dns_name_t **newnamep) { - isc_result_t result; - dns_name_t *newname = NULL; - isc_region_t r; - isc_buffer_t *namebuf = NULL, *rdatabuf = NULL; - dns_rdatalist_t *rdatalist; - dns_rdataset_t *rdataset, *newrdataset; - dns_rdata_t rdata = DNS_RDATA_INIT, *newrdata; - - result = dns_message_gettempname(msg, &newname); - if (result != ISC_R_SUCCESS) { - return (result); - } - isc_buffer_allocate(mctx, &namebuf, DNS_NAME_MAXWIRE); - dns_name_init(newname, NULL); - dns_name_setbuffer(newname, namebuf); - dns_message_takebuffer(msg, &namebuf); - dns_name_copynf(name, newname); - - for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; - rdataset = ISC_LIST_NEXT(rdataset, link)) - { - rdatalist = NULL; - result = dns_message_gettemprdatalist(msg, &rdatalist); - if (result != ISC_R_SUCCESS) { - goto fail; - } - dns_rdatalist_init(rdatalist); - rdatalist->type = rdataset->type; - rdatalist->rdclass = rdataset->rdclass; - rdatalist->covers = rdataset->covers; - rdatalist->ttl = rdataset->ttl; - - result = dns_rdataset_first(rdataset); - while (result == ISC_R_SUCCESS) { - dns_rdata_reset(&rdata); - dns_rdataset_current(rdataset, &rdata); - - newrdata = NULL; - result = dns_message_gettemprdata(msg, &newrdata); - if (result != ISC_R_SUCCESS) { - goto fail; - } - dns_rdata_toregion(&rdata, &r); - rdatabuf = NULL; - isc_buffer_allocate(mctx, &rdatabuf, r.length); - isc_buffer_putmem(rdatabuf, r.base, r.length); - isc_buffer_usedregion(rdatabuf, &r); - dns_rdata_init(newrdata); - dns_rdata_fromregion(newrdata, rdata.rdclass, - rdata.type, &r); - newrdata->flags = rdata.flags; - - ISC_LIST_APPEND(rdatalist->rdata, newrdata, link); - dns_message_takebuffer(msg, &rdatabuf); - - result = dns_rdataset_next(rdataset); - } - - newrdataset = NULL; - result = dns_message_gettemprdataset(msg, &newrdataset); - if (result != ISC_R_SUCCESS) { - goto fail; - } - dns_rdatalist_tordataset(rdatalist, newrdataset); - - ISC_LIST_APPEND(newname->list, newrdataset, link); - } - - *newnamep = newname; - - return (ISC_R_SUCCESS); - -fail: - dns_message_puttempname(msg, &newname); - - return (result); -} - -static void -internal_update_callback(isc_task_t *task, isc_event_t *event) { - updatearg_t *uarg = event->ev_arg; - dns_clientupdateevent_t *uev = (dns_clientupdateevent_t *)event; - - UNUSED(task); - - LOCK(&uarg->lock); - - uarg->result = uev->result; - - dns_client_destroyupdatetrans(&uarg->trans); - isc_event_free(&event); - - if (!uarg->canceled) { - UNLOCK(&uarg->lock); - - /* Exit from the internal event loop */ - isc_app_ctxsuspend(uarg->actx); - } else { - /* - * We have already exited from the loop (due to some - * unexpected event). Just clean the arg up. - */ - UNLOCK(&uarg->lock); - isc_mutex_destroy(&uarg->lock); - isc_mem_put(uarg->client->mctx, uarg, sizeof(*uarg)); - } -} - -isc_result_t -dns_client_update(dns_client_t *client, dns_rdataclass_t rdclass, - const dns_name_t *zonename, dns_namelist_t *prerequisites, - dns_namelist_t *updates, isc_sockaddrlist_t *servers, - dns_tsec_t *tsec, unsigned int options) { - isc_result_t result; - isc_appctx_t *actx; - updatearg_t *uarg; - - REQUIRE(DNS_CLIENT_VALID(client)); - - if ((client->attributes & DNS_CLIENTATTR_OWNCTX) == 0 && - (options & DNS_CLIENTUPDOPT_ALLOWRUN) == 0) - { - /* - * If the client is run under application's control, we need - * to create a new running (sub)environment for this - * particular update. - */ - return (ISC_R_NOTIMPLEMENTED); /* XXXTBD */ - } else { - actx = client->actx; - } - - uarg = isc_mem_get(client->mctx, sizeof(*uarg)); - - isc_mutex_init(&uarg->lock); - - uarg->actx = actx; - uarg->client = client; - uarg->result = ISC_R_FAILURE; - uarg->trans = NULL; - uarg->canceled = false; - - result = dns_client_startupdate( - client, rdclass, zonename, prerequisites, updates, servers, - tsec, options, client->task, internal_update_callback, uarg, - &uarg->trans); - if (result != ISC_R_SUCCESS) { - isc_mutex_destroy(&uarg->lock); - isc_mem_put(client->mctx, uarg, sizeof(*uarg)); - return (result); - } - - /* - * Start internal event loop. It blocks until the entire process - * is completed. - */ - result = isc_app_ctxrun(actx); - - LOCK(&uarg->lock); - if (result == ISC_R_SUCCESS || result == ISC_R_SUSPEND) { - result = uarg->result; - } - - if (uarg->trans != NULL) { - /* - * Unusual termination (perhaps due to signal). We need some - * tricky cleanup process. - */ - uarg->canceled = true; - dns_client_cancelupdate(uarg->trans); - - UNLOCK(&uarg->lock); - - /* uarg will be freed in the event handler. */ - } else { - UNLOCK(&uarg->lock); - - isc_mutex_destroy(&uarg->lock); - isc_mem_put(client->mctx, uarg, sizeof(*uarg)); - } - - return (result); -} - -static void -startupdate(isc_task_t *task, isc_event_t *event) { - updatectx_t *uctx; - isc_result_t result; - unsigned int resoptions; - - REQUIRE(event != NULL); - - UNUSED(task); - - uctx = event->ev_arg; - - if (uctx->zonename != NULL && uctx->currentserver != NULL) { - result = send_update(uctx); - if (result != ISC_R_SUCCESS) { - goto fail; - } - } else if (uctx->currentserver != NULL) { - result = request_soa(uctx); - if (result != ISC_R_SUCCESS) { - goto fail; - } - } else { - resoptions = 0; - if (uctx->want_tcp) { - resoptions |= DNS_CLIENTRESOPT_TCP; - } - dns_name_clone(uctx->firstname, &uctx->soaqname); - result = dns_client_startresolve( - uctx->client, &uctx->soaqname, uctx->rdclass, - dns_rdatatype_soa, resoptions, uctx->client->task, - resolvesoa_done, uctx, &uctx->restrans); - if (result != ISC_R_SUCCESS) { - goto fail; - } - } - - isc_event_free(&event); - -fail: - if (result != ISC_R_SUCCESS) { - update_sendevent(uctx, result); - } -} - -isc_result_t -dns_client_startupdate(dns_client_t *client, dns_rdataclass_t rdclass, - const dns_name_t *zonename, - dns_namelist_t *prerequisites, dns_namelist_t *updates, - isc_sockaddrlist_t *servers, dns_tsec_t *tsec, - unsigned int options, isc_task_t *task, - isc_taskaction_t action, void *arg, - dns_clientupdatetrans_t **transp) { - dns_view_t *view = NULL; - isc_result_t result; - dns_name_t *name, *newname; - updatectx_t *uctx; - isc_task_t *tclone = NULL; - dns_section_t section = DNS_SECTION_UPDATE; - isc_sockaddr_t *server, *sa = NULL; - dns_tsectype_t tsectype = dns_tsectype_none; - bool want_tcp; - - UNUSED(options); - - REQUIRE(DNS_CLIENT_VALID(client)); - REQUIRE(transp != NULL && *transp == NULL); - REQUIRE(updates != NULL); - REQUIRE(task != NULL); - - if (tsec != NULL) { - tsectype = dns_tsec_gettype(tsec); - if (tsectype != dns_tsectype_tsig) { - return (ISC_R_NOTIMPLEMENTED); /* XXX */ - } - } - - LOCK(&client->lock); - result = dns_viewlist_find(&client->viewlist, DNS_CLIENTVIEW_NAME, - rdclass, &view); - UNLOCK(&client->lock); - if (result != ISC_R_SUCCESS) { - return (result); - } - - want_tcp = ((options & DNS_CLIENTUPDOPT_TCP) != 0); - - /* - * Create a context and prepare some resources. - */ - - uctx = isc_mem_get(client->mctx, sizeof(*uctx)); - - isc_mutex_init(&uctx->lock); - - tclone = NULL; - isc_task_attach(task, &tclone); - uctx->client = client; - ISC_LINK_INIT(uctx, link); - uctx->state = dns_clientupdatestate_prepare; - uctx->view = view; - uctx->rdclass = rdclass; - uctx->canceled = false; - uctx->updatemsg = NULL; - uctx->soaquery = NULL; - uctx->updatereq = NULL; - uctx->restrans = NULL; - uctx->restrans2 = NULL; - uctx->bp4 = NULL; - uctx->bp6 = NULL; - uctx->soareq = NULL; - uctx->event = NULL; - uctx->tsigkey = NULL; - uctx->sig0key = NULL; - uctx->zonename = NULL; - uctx->want_tcp = want_tcp; - dns_name_init(&uctx->soaqname, NULL); - ISC_LIST_INIT(uctx->servers); - uctx->nservers = 0; - uctx->currentserver = NULL; - dns_fixedname_init(&uctx->zonefname); - if (tsec != NULL) { - dns_tsec_getkey(tsec, &uctx->tsigkey); - } - uctx->event = (dns_clientupdateevent_t *)isc_event_allocate( - client->mctx, tclone, DNS_EVENT_UPDATEDONE, action, arg, - sizeof(*uctx->event)); - if (zonename != NULL) { - uctx->zonename = dns_fixedname_name(&uctx->zonefname); - dns_name_copynf(zonename, uctx->zonename); - } - if (servers != NULL) { - for (server = ISC_LIST_HEAD(*servers); server != NULL; - server = ISC_LIST_NEXT(server, link)) - { - sa = isc_mem_get(client->mctx, sizeof(*sa)); - sa->type = server->type; - sa->length = server->length; - ISC_LINK_INIT(sa, link); - ISC_LIST_APPEND(uctx->servers, sa, link); - if (uctx->currentserver == NULL) { - uctx->currentserver = sa; - } - uctx->nservers++; - } - } - - /* Make update message */ - dns_message_create(client->mctx, DNS_MESSAGE_INTENTRENDER, - &uctx->updatemsg); - uctx->updatemsg->opcode = dns_opcode_update; - - if (prerequisites != NULL) { - for (name = ISC_LIST_HEAD(*prerequisites); name != NULL; - name = ISC_LIST_NEXT(name, link)) - { - newname = NULL; - result = copy_name(client->mctx, uctx->updatemsg, name, - &newname); - if (result != ISC_R_SUCCESS) { - goto fail; - } - dns_message_addname(uctx->updatemsg, newname, - DNS_SECTION_PREREQUISITE); - } - } - - for (name = ISC_LIST_HEAD(*updates); name != NULL; - name = ISC_LIST_NEXT(name, link)) - { - newname = NULL; - result = copy_name(client->mctx, uctx->updatemsg, name, - &newname); - if (result != ISC_R_SUCCESS) { - goto fail; - } - dns_message_addname(uctx->updatemsg, newname, - DNS_SECTION_UPDATE); - } - - uctx->firstname = NULL; - result = dns_message_firstname(uctx->updatemsg, section); - if (result == ISC_R_NOMORE) { - section = DNS_SECTION_PREREQUISITE; - result = dns_message_firstname(uctx->updatemsg, section); - } - if (result != ISC_R_SUCCESS) { - goto fail; - } - dns_message_currentname(uctx->updatemsg, section, &uctx->firstname); - - uctx->magic = UCTX_MAGIC; - - LOCK(&client->lock); - ISC_LIST_APPEND(client->updatectxs, uctx, link); - isc_refcount_increment(&client->references); - UNLOCK(&client->lock); - - *transp = (dns_clientupdatetrans_t *)uctx; - result = isc_app_ctxonrun(client->actx, client->mctx, client->task, - startupdate, uctx); - if (result == ISC_R_ALREADYRUNNING) { - isc_event_t *event; - event = isc_event_allocate(client->mctx, dns_client_startupdate, - DNS_EVENT_STARTUPDATE, startupdate, - uctx, sizeof(*event)); - result = ISC_R_SUCCESS; - isc_task_send(task, &event); - } - if (result == ISC_R_SUCCESS) { - return (result); - } - - isc_refcount_decrement1(&client->references); - *transp = NULL; - -fail: - if (ISC_LINK_LINKED(uctx, link)) { - LOCK(&client->lock); - ISC_LIST_UNLINK(client->updatectxs, uctx, link); - UNLOCK(&client->lock); - } - if (uctx->updatemsg != NULL) { - dns_message_detach(&uctx->updatemsg); - } - while ((sa = ISC_LIST_HEAD(uctx->servers)) != NULL) { - ISC_LIST_UNLINK(uctx->servers, sa, link); - isc_mem_put(client->mctx, sa, sizeof(*sa)); - } - if (uctx->event != NULL) { - isc_event_free(ISC_EVENT_PTR(&uctx->event)); - } - if (uctx->tsigkey != NULL) { - dns_tsigkey_detach(&uctx->tsigkey); - } - isc_task_detach(&tclone); - isc_mutex_destroy(&uctx->lock); - uctx->magic = 0; - isc_mem_put(client->mctx, uctx, sizeof(*uctx)); - dns_view_detach(&view); - - return (result); -} - -void -dns_client_cancelupdate(dns_clientupdatetrans_t *trans) { - updatectx_t *uctx; - - REQUIRE(trans != NULL); - uctx = (updatectx_t *)trans; - REQUIRE(UCTX_VALID(uctx)); - - LOCK(&uctx->lock); - - if (!uctx->canceled) { - uctx->canceled = true; - if (uctx->updatereq != NULL) { - dns_request_cancel(uctx->updatereq); - } - if (uctx->soareq != NULL) { - dns_request_cancel(uctx->soareq); - } - if (uctx->restrans != NULL) { - dns_client_cancelresolve(uctx->restrans); - } - if (uctx->restrans2 != NULL) { - dns_client_cancelresolve(uctx->restrans2); - } - } - - UNLOCK(&uctx->lock); -} - -void -dns_client_destroyupdatetrans(dns_clientupdatetrans_t **transp) { - updatectx_t *uctx; - isc_mem_t *mctx; - dns_client_t *client; - isc_sockaddr_t *sa; - - REQUIRE(transp != NULL); - uctx = (updatectx_t *)*transp; - *transp = NULL; - REQUIRE(UCTX_VALID(uctx)); - client = uctx->client; - REQUIRE(DNS_CLIENT_VALID(client)); - REQUIRE(uctx->updatereq == NULL && uctx->updatemsg == NULL && - uctx->soareq == NULL && uctx->soaquery == NULL && - uctx->event == NULL && uctx->tsigkey == NULL && - uctx->sig0key == NULL); - - mctx = client->mctx; - dns_view_detach(&uctx->view); - while ((sa = ISC_LIST_HEAD(uctx->servers)) != NULL) { - ISC_LIST_UNLINK(uctx->servers, sa, link); - isc_mem_put(mctx, sa, sizeof(*sa)); - } - - LOCK(&client->lock); - - INSIST(ISC_LINK_LINKED(uctx, link)); - ISC_LIST_UNLINK(client->updatectxs, uctx, link); - - UNLOCK(&client->lock); - - isc_mutex_destroy(&uctx->lock); - uctx->magic = 0; - - isc_mem_put(mctx, uctx, sizeof(*uctx)); - - dns_client_destroy(&client); -} - -isc_mem_t * -dns_client_mctx(dns_client_t *client) { - REQUIRE(DNS_CLIENT_VALID(client)); - return (client->mctx); -} - -typedef struct { - isc_buffer_t buffer; - dns_rdataset_t rdataset; - dns_rdatalist_t rdatalist; - dns_rdata_t rdata; - size_t size; - isc_mem_t *mctx; - unsigned char data[]; -} dns_client_updaterec_t; - -isc_result_t -dns_client_updaterec(dns_client_updateop_t op, const dns_name_t *owner, - dns_rdatatype_t type, dns_rdata_t *source, dns_ttl_t ttl, - dns_name_t *target, dns_rdataset_t *rdataset, - dns_rdatalist_t *rdatalist, dns_rdata_t *rdata, - isc_mem_t *mctx) { - dns_client_updaterec_t *updaterec = NULL; - size_t size = offsetof(dns_client_updaterec_t, data); - - REQUIRE(op < updateop_max); - REQUIRE(owner != NULL); - REQUIRE((rdataset != NULL && rdatalist != NULL && rdata != NULL) || - (rdataset == NULL && rdatalist == NULL && rdata == NULL && - mctx != NULL)); - if (op == updateop_add) { - REQUIRE(source != NULL); - } - if (source != NULL) { - REQUIRE(source->type == type); - REQUIRE(op == updateop_add || op == updateop_delete || - op == updateop_exist); - } - - size += owner->length; - if (source != NULL) { - size += source->length; - } - - if (rdataset == NULL) { - updaterec = isc_mem_get(mctx, size); - rdataset = &updaterec->rdataset; - rdatalist = &updaterec->rdatalist; - rdata = &updaterec->rdata; - dns_rdataset_init(rdataset); - dns_rdatalist_init(&updaterec->rdatalist); - dns_rdata_init(&updaterec->rdata); - isc_buffer_init( - &updaterec->buffer, updaterec->data, - (unsigned int)(size - - offsetof(dns_client_updaterec_t, data))); - dns_name_copy(owner, target, &updaterec->buffer); - if (source != NULL) { - isc_region_t r; - dns_rdata_clone(source, rdata); - dns_rdata_toregion(rdata, &r); - rdata->data = isc_buffer_used(&updaterec->buffer); - isc_buffer_copyregion(&updaterec->buffer, &r); - } - updaterec->mctx = NULL; - isc_mem_attach(mctx, &updaterec->mctx); - } else if (source != NULL) { - dns_rdata_clone(source, rdata); - } - - switch (op) { - case updateop_add: - break; - case updateop_delete: - if (source != NULL) { - ttl = 0; - dns_rdata_makedelete(rdata); - } else { - dns_rdata_deleterrset(rdata, type); - } - break; - case updateop_notexist: - dns_rdata_notexist(rdata, type); - break; - case updateop_exist: - if (source == NULL) { - ttl = 0; - dns_rdata_exists(rdata, type); - } - case updateop_none: - break; - default: - INSIST(0); - ISC_UNREACHABLE(); - } - - rdatalist->type = rdata->type; - rdatalist->rdclass = rdata->rdclass; - if (source != NULL) { - rdatalist->covers = dns_rdata_covers(rdata); - rdatalist->ttl = ttl; - } - ISC_LIST_APPEND(rdatalist->rdata, rdata, link); - dns_rdatalist_tordataset(rdatalist, rdataset); - ISC_LIST_APPEND(target->list, rdataset, link); - if (updaterec != NULL) { - target->attributes |= DNS_NAMEATTR_HASUPDATEREC; - dns_name_setbuffer(target, &updaterec->buffer); - } - if (op == updateop_add || op == updateop_delete) { - target->attributes |= DNS_NAMEATTR_UPDATE; - } else { - target->attributes |= DNS_NAMEATTR_PREREQUISITE; - } - return (ISC_R_SUCCESS); -} - -void -dns_client_freeupdate(dns_name_t **namep) { - dns_client_updaterec_t *updaterec; - dns_rdatalist_t *rdatalist; - dns_rdataset_t *rdataset; - dns_rdata_t *rdata; - dns_name_t *name; - - REQUIRE(namep != NULL && *namep != NULL); - - name = *namep; - for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; - rdataset = ISC_LIST_HEAD(name->list)) - { - ISC_LIST_UNLINK(name->list, rdataset, link); - rdatalist = NULL; - dns_rdatalist_fromrdataset(rdataset, &rdatalist); - if (rdatalist == NULL) { - dns_rdataset_disassociate(rdataset); - continue; - } - for (rdata = ISC_LIST_HEAD(rdatalist->rdata); rdata != NULL; - rdata = ISC_LIST_HEAD(rdatalist->rdata)) - { - ISC_LIST_UNLINK(rdatalist->rdata, rdata, link); - } - dns_rdataset_disassociate(rdataset); - } - - if ((name->attributes & DNS_NAMEATTR_HASUPDATEREC) != 0) { - updaterec = (dns_client_updaterec_t *)name->buffer; - INSIST(updaterec != NULL); - isc_mem_putanddetach(&updaterec->mctx, updaterec, - updaterec->size); - *namep = NULL; - } -} diff --git a/lib/dns/include/dns/client.h b/lib/dns/include/dns/client.h index 82884c67b3..f7870e412f 100644 --- a/lib/dns/include/dns/client.h +++ b/lib/dns/include/dns/client.h @@ -112,15 +112,6 @@ typedef struct dns_clientresevent { dns_namelist_t answerlist; } dns_clientresevent_t; /* too long? */ -/*% - * Status of a dynamic update procedure. - */ -typedef enum { - dns_clientupdatestate_prepare, /*%< no updates have been sent */ - dns_clientupdatestate_sent, /*%< updates were sent, no response */ - dns_clientupdatestate_done /*%< update was sent and succeeded */ -} dns_clientupdatestate_t; - /*% * A dns_clientreqevent_t is sent when a DNS request is completed by a client. * 'result' stores the result code of the entire transaction. @@ -135,24 +126,6 @@ typedef struct dns_clientreqevent { dns_message_t *rmessage; } dns_clientreqevent_t; /* too long? */ -/*% - * A dns_clientupdateevent_t is sent when dynamic update performed by a client - * completes. 'result' stores the result code of the entire update procedure. - * 'state' specifies the status of the update procedure when this event is - * sent. This can be used as a hint by the receiver to determine whether - * the update attempt was ever made. In particular, if the state is - * dns_clientupdatestate_prepare, the receiver can be sure that the requested - * update was not applied. - */ -typedef struct dns_clientupdateevent { - ISC_EVENT_COMMON(struct dns_clientupdateevent); - isc_result_t result; - dns_clientupdatestate_t state; -} dns_clientupdateevent_t; /* too long? */ - -isc_result_t -dns_client_create(dns_client_t **clientp, unsigned int options); - isc_result_t dns_client_createx(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr, isc_socketmgr_t *socketmgr, isc_timermgr_t *timermgr, @@ -160,24 +133,16 @@ dns_client_createx(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr, const isc_sockaddr_t *localaddr4, const isc_sockaddr_t *localaddr6); /*%< - * Create a DNS client. These functions create a new client object with - * minimal internal resources such as the default 'view' for the IN class and - * IPv4/IPv6 dispatches for the view. + * Create a DNS client object with minimal internal resources, such as + * a default view for the IN class and IPv4/IPv6 dispatches for the view. * - * dns_client_createx() takes 'manager' arguments so that the caller can + * dns_client_create() takes 'manager' arguments so that the caller can * control the behavior of the client through the underlying event framework. - * On the other hand, dns_client_create() simplifies the interface and creates - * the managers internally. A DNS client object created via - * dns_client_create() is expected to be used by an application that only needs - * simple synchronous services or by a thread-based application. - * - * dns_client_createx2 takes two additional parameters, 'localaddr4' and - * 'localaddr6', to specify the local address to use for each family. If - * both are set to NULL, then wildcard addresses will be used for both - * families. If only one is NULL, then the other address will be used - * as the local address, and the other protocol family will not be used. - * - * dns_client_create(x) will create a cache database with the view. + * 'localaddr4' and 'localaddr6' specify the local addresses to use for + * each address family; if both are set to NULL, then wildcard addresses + * will be used for both families. If only one is NULL, then the other + * address will be used as the local address, and the NULL protocol family + * will not be used. * * Requires: * @@ -504,146 +469,6 @@ dns_client_destroyreqtrans(dns_clientreqtrans_t **transp); *\li *transp == NULL. */ -isc_result_t -dns_client_update(dns_client_t *client, dns_rdataclass_t rdclass, - const dns_name_t *zonename, dns_namelist_t *prerequisites, - dns_namelist_t *updates, isc_sockaddrlist_t *servers, - dns_tsec_t *tsec, unsigned int options); - -isc_result_t -dns_client_startupdate(dns_client_t *client, dns_rdataclass_t rdclass, - const dns_name_t *zonename, - dns_namelist_t *prerequisites, dns_namelist_t *updates, - isc_sockaddrlist_t *servers, dns_tsec_t *tsec, - unsigned int options, isc_task_t *task, - isc_taskaction_t action, void *arg, - dns_clientupdatetrans_t **transp); -/*%< - * Perform DNS dynamic update for 'updates' of the 'rdclass' class with - * optional 'prerequisites'. - * - * 'updates' are a list of names with associated RRsets to be updated. - * - * 'prerequisites' are a list of names with associated RRsets corresponding to - * the prerequisites of the updates. This is optional and can be NULL, in - * which case the prerequisite section of the update message will be empty. - * - * Both 'updates' and 'prerequisites' must be constructed as specified in - * RFC2136. - * - * 'zonename' is the name of the zone in which the updated names exist. - * This is optional and can be NULL. In this case, these functions internally - * identify the appropriate zone through some queries for the SOA RR starting - * with the first name in prerequisites or updates. - * - * 'servers' is a list of authoritative servers to which the update message - * should be sent. This is optional and can be NULL. In this case, these - * functions internally identify the appropriate primary server name and its - * addresses through some queries for the SOA RR (like the case of zonename) - * and supplemental A/AAAA queries for the server name. - * Note: The client module generally assumes the given addresses are of the - * primary server of the corresponding zone. It will work even if a secondary - * server address is specified as long as the server allows update forwarding, - * it is generally discouraged to include secondary server addresses unless - * there's strong reason to do so. - * - * 'tsec' is a transaction security object containing, e.g. a TSIG key for - * authenticating the update transaction (and the supplemental query/response - * transactions if the server is specified). This is optional and can be - * NULL, in which case the library tries the update without any transaction - * authentication. - * - * It is typically expected that the client object passed to - * dns_client_update() was created via dns_client_create() and has its own - * managers and contexts. However, if the DNS_CLIENTUPDOPT_ALLOWRUN flag is - * set in 'options', this function performs the synchronous service even if - * it does not have its own manager and context structures. - * - * dns_client_update() provides a synchronous service. This function blocks - * until the entire update procedure completes, including the additional - * queries when necessary. - * - * dns_client_startupdate() is an asynchronous version of dns_client_update(). - * It immediately returns (typically with *transp being set to a non-NULL - * pointer), and performs the update procedure through a set of internal - * events. All transactions including the additional query exchanges are - * performed as a separate event, so none of these events cause blocking - * operation. When the update procedure completes, the specified function - * 'action' will be called with the argument of a 'dns_clientupdateevent_t' - * structure. On return, '*transp' is set to an opaque transaction ID so that - * the caller can cancel this update process. - * - * DNS_CLIENTUPDOPT_TCP switches to the TCP (vs. UDP) transport. - * - * Requires: - * - *\li 'client' is a valid client. - * - *\li 'updates' != NULL. - * - *\li 'task' is a valid task. - * - *\li 'transp' != NULL && *transp == NULL; - * - * Returns: - * - *\li #ISC_R_SUCCESS On success. - * - *\li Anything else Failure. - */ - -void -dns_client_cancelupdate(dns_clientupdatetrans_t *trans); -/*%< - * Cancel an ongoing dynamic update procedure started via - * dns_client_startupdate(). - * - * Notes: - * - *\li If the update procedure has not completed, post its UPDATEDONE - * event with a result code of #ISC_R_CANCELED. - * - * Requires: - * - *\li 'trans' is a valid transaction ID. - */ - -void -dns_client_destroyupdatetrans(dns_clientupdatetrans_t **transp); -/*%< - * Destroy dynamic update transaction identified by '*transp'. - * - * Requires: - * - *\li '*transp' is a valid transaction ID. - * - *\li The caller has received the UPDATEDONE event (either because the - * update completed or because dns_client_cancelupdate() was called). - * - * Ensures: - * - *\li *transp == NULL. - */ - -isc_result_t -dns_client_updaterec(dns_client_updateop_t op, const dns_name_t *owner, - dns_rdatatype_t type, dns_rdata_t *source, dns_ttl_t ttl, - dns_name_t *target, dns_rdataset_t *rdataset, - dns_rdatalist_t *rdatalist, dns_rdata_t *rdata, - isc_mem_t *mctx); -/*%< - * TBD - */ - -void -dns_client_freeupdate(dns_name_t **namep); -/*%< - * TBD - */ - -isc_mem_t * -dns_client_mctx(dns_client_t *client); - ISC_LANG_ENDDECLS #endif /* DNS_CLIENT_H */ diff --git a/lib/dns/win32/libdns.def.in b/lib/dns/win32/libdns.def.in index b4163d90eb..80869fae80 100644 --- a/lib/dns/win32/libdns.def.in +++ b/lib/dns/win32/libdns.def.in @@ -135,25 +135,18 @@ dns_cert_totext dns_client_addtrustedkey dns_client_cancelrequest dns_client_cancelresolve -dns_client_cancelupdate dns_client_clearservers -dns_client_create dns_client_createx dns_client_destroy dns_client_destroyreqtrans dns_client_destroyrestrans -dns_client_destroyupdatetrans dns_client_freeresanswer -dns_client_freeupdate dns_client_mctx dns_client_request dns_client_resolve dns_client_setservers dns_client_startrequest dns_client_startresolve -dns_client_startupdate -dns_client_update -dns_client_updaterec dns_clientinfo_init dns_clientinfomethods_init dns_compress_add diff --git a/lib/samples/.gitignore b/lib/samples/.gitignore index 3d14fb9600..78d0640e1e 100644 --- a/lib/samples/.gitignore +++ b/lib/samples/.gitignore @@ -3,5 +3,3 @@ process resolve sample-async sample-gai -sample-request -sample-update diff --git a/lib/samples/Makefile.am b/lib/samples/Makefile.am index 54e2b5fc5d..9eb8ad1efb 100644 --- a/lib/samples/Makefile.am +++ b/lib/samples/Makefile.am @@ -8,8 +8,6 @@ AM_CPPFLAGS += \ noinst_PROGRAMS = \ resolve \ sample-async \ - sample-update \ - sample-request \ nsprobe resolve_SOURCES = resolve.c @@ -18,11 +16,5 @@ resolve_LDADD = $(LIBISC_LIBS) $(LIBIRS_LIBS) $(LIBDNS_LIBS) sample_async_SOURCES = sample-async.c sample_async_LDADD = $(LIBISC_LIBS) $(LIBDNS_LIBS) -sample_update_SOURCES = sample-update.c -sample_update_LDADD = $(LIBISC_LIBS) $(LIBDNS_LIBS) - -sample_request_SOURCES = sample-request.c -sample_request_LDADD = $(LIBISC_LIBS) $(LIBDNS_LIBS) - nsprobe_SOURCES = nsprobe.c nsprobe_LDADD = $(LIBISC_LIBS) $(LIBDNS_LIBS) diff --git a/lib/samples/sample-request.c b/lib/samples/sample-request.c deleted file mode 100644 index 00ff2d58d3..0000000000 --- a/lib/samples/sample-request.c +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Copyright (C) Internet Systems Consortium, Inc. ("ISC") - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, you can obtain one at https://mozilla.org/MPL/2.0/. - * - * See the COPYRIGHT file distributed with this work for additional - * information regarding copyright ownership. - */ - -#ifndef WIN32 -#include -#include -#include -#include -#include -#include -#endif /* ifndef WIN32 */ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -static isc_mem_t *mctx; -static dns_fixedname_t fixedqname; - -ISC_NORETURN static void -usage(void); - -static void -usage(void) { - fprintf(stderr, "sample-request [-t RRtype] server_address hostname\n"); - - exit(1); -} - -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); - qname0 = dns_fixedname_initname(&fixedqname); - result = dns_name_fromtext(qname0, &b, dns_rootname, 0, NULL); - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "failed to convert qname: %u\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_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_detach(&message); - return (result); -} - -static void -print_section(dns_message_t *message, int section, isc_buffer_t *buf) { - isc_result_t result; - isc_region_t r; - - result = dns_message_sectiontotext(message, section, - &dns_master_style_full, 0, buf); - if (result != ISC_R_SUCCESS) { - goto fail; - } - - isc_buffer_usedregion(buf, &r); - printf("%.*s", (int)r.length, (char *)r.base); - - return; - -fail: - fprintf(stderr, "failed to convert a section\n"); -} - -int -main(int argc, char *argv[]) { - int ch, i, gaierror; - struct addrinfo hints, *res; - isc_textregion_t tr; - dns_client_t *client = NULL; - isc_result_t result; - isc_sockaddr_t sa; - dns_message_t *qmessage, *rmessage; - dns_rdatatype_t type = dns_rdatatype_a; - isc_buffer_t *outputbuf; - - while ((ch = isc_commandline_parse(argc, argv, "t:")) != -1) { - switch (ch) { - case 't': - tr.base = isc_commandline_argument; - tr.length = strlen(isc_commandline_argument); - result = dns_rdatatype_fromtext(&type, &tr); - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "invalid RRtype: %s\n", - isc_commandline_argument); - exit(1); - } - break; - default: - usage(); - } - } - - argc -= isc_commandline_index; - argv += isc_commandline_index; - if (argc < 2) { - usage(); - } - - isc_lib_register(); - result = dns_lib_init(); - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "dns_lib_init failed: %u\n", result); - exit(1); - } - - result = dns_client_create(&client, 0); - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "dns_client_create failed: %u\n", result); - exit(1); - } - - /* Prepare message structures */ - mctx = NULL; - qmessage = NULL; - rmessage = NULL; - - isc_mem_create(&mctx); - dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &qmessage); - dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &rmessage); - - /* Initialize the nameserver address */ - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_DGRAM; - hints.ai_protocol = IPPROTO_UDP; -#ifdef AI_NUMERICHOST - hints.ai_flags = AI_NUMERICHOST; -#endif /* ifdef AI_NUMERICHOST */ - gaierror = getaddrinfo(argv[0], "53", &hints, &res); - if (gaierror != 0) { - fprintf(stderr, "getaddrinfo failed: %s\n", - gai_strerror(gaierror)); - exit(1); - } - INSIST(res->ai_addrlen <= sizeof(sa.type)); - memmove(&sa.type, res->ai_addr, res->ai_addrlen); - freeaddrinfo(res); - sa.length = (unsigned int)res->ai_addrlen; - ISC_LINK_INIT(&sa, link); - - /* Construct qname */ - result = make_querymessage(qmessage, argv[1], type); - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "failed to create a query\n"); - exit(1); - } - - /* Send request and wait for a response */ - result = dns_client_request(client, qmessage, rmessage, &sa, 0, 0, NULL, - 60, 0, 3); - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "failed to get a response: %s\n", - dns_result_totext(result)); - } - - /* Dump the response */ - outputbuf = NULL; - isc_buffer_allocate(mctx, &outputbuf, 65535); - for (i = 0; i < DNS_SECTION_MAX; i++) { - print_section(rmessage, i, outputbuf); - isc_buffer_clear(outputbuf); - } - isc_buffer_free(&outputbuf); - - /* Cleanup */ - dns_message_detach(&qmessage); - dns_message_detach(&rmessage); - isc_mem_destroy(&mctx); - dns_client_destroy(&client); - dns_lib_shutdown(); - - return (0); -} diff --git a/lib/samples/sample-update.c b/lib/samples/sample-update.c deleted file mode 100644 index b3d8b73c71..0000000000 --- a/lib/samples/sample-update.c +++ /dev/null @@ -1,781 +0,0 @@ -/* - * Copyright (C) Internet Systems Consortium, Inc. ("ISC") - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, you can obtain one at https://mozilla.org/MPL/2.0/. - * - * See the COPYRIGHT file distributed with this work for additional - * information regarding copyright ownership. - */ - -#ifndef WIN32 -#include -#include -#include -#include -#include -#include -#endif /* ifndef WIN32 */ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -static dns_tsec_t *tsec = NULL; -static const dns_rdataclass_t default_rdataclass = dns_rdataclass_in; -static isc_bufferlist_t usedbuffers; -static ISC_LIST(dns_rdatalist_t) usedrdatalists; - -static const char *port = "53"; - -static void -setup_tsec(char *keyfile, isc_mem_t *mctx); -static void -update_addordelete(isc_mem_t *mctx, char *cmdline, bool isdelete, - dns_name_t *name); -static void -evaluate_prereq(isc_mem_t *mctx, char *cmdline, dns_name_t *name); - -ISC_NORETURN static void -usage(void); - -static void -usage(void) { - fprintf(stderr, "sample-update " - "-s " - "[-a auth_server] " - "[-k keyfile] " - "[-p prerequisite] " - "[-r recursive_server] " - "[-z zonename] " - "(add|delete) \"name TTL RRtype RDATA\"\n"); - exit(1); -} - -#ifdef _WIN32 -static void -InitSockets(void) { - WORD wVersionRequested; - WSADATA wsaData; - int err; - - wVersionRequested = MAKEWORD(2, 0); - - err = WSAStartup(wVersionRequested, &wsaData); - if (err != 0) { - fprintf(stderr, "WSAStartup() failed: %d\n", err); - exit(1); - } -} - -static void -DestroySockets(void) { - WSACleanup(); -} -#else /* ifdef _WIN32 */ -#define InitSockets() ((void)0) -#define DestroySockets() ((void)0) -#endif /* ifdef _WIN32 */ - -static bool -addserver(const char *server, isc_sockaddrlist_t *list, - isc_sockaddr_t *sockaddr) { - struct addrinfo hints, *res; - int gaierror; - - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_DGRAM; - hints.ai_protocol = IPPROTO_UDP; -#ifdef AI_NUMERICHOST - hints.ai_flags |= AI_NUMERICHOST; -#endif /* ifdef AI_NUMERICHOST */ -#ifdef AI_NUMERICSERV - hints.ai_flags |= AI_NUMERICSERV; -#endif /* ifdef AI_NUMERICSERV */ - InitSockets(); - gaierror = getaddrinfo(server, port, &hints, &res); - if (gaierror != 0) { - fprintf(stderr, "getaddrinfo(%s) failed: %s\n", server, - gai_strerror(gaierror)); - DestroySockets(); - return (false); - } - INSIST(res->ai_addrlen <= sizeof(sockaddr->type)); - memmove(&sockaddr->type, res->ai_addr, res->ai_addrlen); - sockaddr->length = (unsigned int)res->ai_addrlen; - ISC_LINK_INIT(sockaddr, link); - ISC_LIST_APPEND(*list, sockaddr, link); - freeaddrinfo(res); - DestroySockets(); - return (true); -} - -int -main(int argc, char *argv[]) { - int ch; - dns_client_t *client = NULL; - char *zonenamestr = NULL; - char *keyfilename = NULL; - char *prereqstr = NULL; - isc_sockaddr_t sa_auth[10], sa_recursive[10]; - unsigned int nsa_auth = 0, nsa_recursive = 0; - isc_sockaddrlist_t rec_servers; - isc_sockaddrlist_t auth_servers, *auth_serversp = &auth_servers; - isc_result_t result; - bool isdelete; - isc_buffer_t b, *buf; - dns_fixedname_t zname0, pname0, uname0; - unsigned int namelen; - dns_name_t *zname = NULL, *uname, *pname; - dns_rdataset_t *rdataset; - dns_rdatalist_t *rdatalist; - dns_rdata_t *rdata; - dns_namelist_t updatelist, prereqlist, *prereqlistp = NULL; - isc_mem_t *umctx = NULL; - bool sendtwice = false; - - ISC_LIST_INIT(auth_servers); - ISC_LIST_INIT(rec_servers); - - while ((ch = isc_commandline_parse(argc, argv, "a:k:p:P:r:sz:")) != EOF) - { - switch (ch) { - case 'k': - keyfilename = isc_commandline_argument; - break; - case 'a': - if (nsa_auth < sizeof(sa_auth) / sizeof(*sa_auth) && - addserver(isc_commandline_argument, &auth_servers, - &sa_auth[nsa_auth])) - { - nsa_auth++; - } - break; - case 'p': - prereqstr = isc_commandline_argument; - break; - case 'P': - port = isc_commandline_argument; - break; - case 'r': - if (nsa_recursive < sizeof(sa_recursive) / - sizeof(*sa_recursive) && - addserver(isc_commandline_argument, &rec_servers, - &sa_recursive[nsa_recursive])) - { - nsa_recursive++; - } - break; - case 's': - sendtwice = true; - break; - case 'z': - zonenamestr = isc_commandline_argument; - break; - default: - usage(); - } - } - - argc -= isc_commandline_index; - argv += isc_commandline_index; - if (argc < 2) { - usage(); - } - - /* command line argument validation */ - if (strcmp(argv[0], "delete") == 0) { - isdelete = true; - } else if (strcmp(argv[0], "add") == 0) { - isdelete = false; - } else { - fprintf(stderr, "invalid update command: %s\n", argv[0]); - exit(1); - } - - if (ISC_LIST_HEAD(auth_servers) == NULL && - ISC_LIST_HEAD(rec_servers) == NULL) { - fprintf(stderr, "authoritative or recursive servers " - "must be specified\n"); - usage(); - } - - /* Initialization */ - ISC_LIST_INIT(usedbuffers); - ISC_LIST_INIT(usedrdatalists); - ISC_LIST_INIT(prereqlist); - isc_lib_register(); - result = dns_lib_init(); - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "dns_lib_init failed: %u\n", result); - exit(1); - } - isc_mem_create(&umctx); - - result = dns_client_create(&client, 0); - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "dns_client_create failed: %u\n", result); - exit(1); - } - - /* Construct zone name */ - zname = NULL; - if (zonenamestr != NULL) { - namelen = strlen(zonenamestr); - isc_buffer_init(&b, zonenamestr, namelen); - isc_buffer_add(&b, namelen); - zname = dns_fixedname_initname(&zname0); - result = dns_name_fromtext(zname, &b, dns_rootname, 0, NULL); - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "failed to convert zone name: %u\n", - result); - } - } - - /* Construct prerequisite name (if given) */ - if (prereqstr != NULL) { - pname = dns_fixedname_initname(&pname0); - evaluate_prereq(umctx, prereqstr, pname); - ISC_LIST_APPEND(prereqlist, pname, link); - prereqlistp = &prereqlist; - } - - /* Construct update name */ - ISC_LIST_INIT(updatelist); - uname = dns_fixedname_initname(&uname0); - update_addordelete(umctx, argv[1], isdelete, uname); - ISC_LIST_APPEND(updatelist, uname, link); - - /* Set up TSIG/SIG(0) key (if given) */ - if (keyfilename != NULL) { - setup_tsec(keyfilename, umctx); - } - - if (ISC_LIST_HEAD(auth_servers) == NULL) { - auth_serversp = NULL; - } - - /* Perform update */ - result = dns_client_update(client, default_rdataclass, /* XXX: fixed */ - zname, prereqlistp, &updatelist, - auth_serversp, tsec, 0); - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "update failed: %s\n", - dns_result_totext(result)); - } else { - fprintf(stderr, "update succeeded\n"); - } - - if (sendtwice) { - /* Perform 2nd update */ - result = dns_client_update(client, default_rdataclass, /* XXX: - * fixed - */ - zname, prereqlistp, &updatelist, - auth_serversp, tsec, 0); - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "2nd update failed: %s\n", - dns_result_totext(result)); - } else { - fprintf(stderr, "2nd update succeeded\n"); - } - } - - /* Cleanup */ - while ((pname = ISC_LIST_HEAD(prereqlist)) != NULL) { - while ((rdataset = ISC_LIST_HEAD(pname->list)) != NULL) { - ISC_LIST_UNLINK(pname->list, rdataset, link); - dns_rdataset_disassociate(rdataset); - isc_mem_put(umctx, rdataset, sizeof(*rdataset)); - } - ISC_LIST_UNLINK(prereqlist, pname, link); - } - while ((uname = ISC_LIST_HEAD(updatelist)) != NULL) { - while ((rdataset = ISC_LIST_HEAD(uname->list)) != NULL) { - ISC_LIST_UNLINK(uname->list, rdataset, link); - dns_rdataset_disassociate(rdataset); - isc_mem_put(umctx, rdataset, sizeof(*rdataset)); - } - ISC_LIST_UNLINK(updatelist, uname, link); - } - while ((rdatalist = ISC_LIST_HEAD(usedrdatalists)) != NULL) { - while ((rdata = ISC_LIST_HEAD(rdatalist->rdata)) != NULL) { - ISC_LIST_UNLINK(rdatalist->rdata, rdata, link); - isc_mem_put(umctx, rdata, sizeof(*rdata)); - } - ISC_LIST_UNLINK(usedrdatalists, rdatalist, link); - isc_mem_put(umctx, rdatalist, sizeof(*rdatalist)); - } - while ((buf = ISC_LIST_HEAD(usedbuffers)) != NULL) { - ISC_LIST_UNLINK(usedbuffers, buf, link); - isc_buffer_free(&buf); - } - if (tsec != NULL) { - dns_tsec_destroy(&tsec); - } - isc_mem_destroy(&umctx); - dns_client_destroy(&client); - dns_lib_shutdown(); - - return (0); -} - -/* - * Subroutines borrowed from nsupdate.c - */ -#define MAXWIRE (64 * 1024) -#define TTL_MAX 2147483647U /* Maximum signed 32 bit integer. */ - -static char * -nsu_strsep(char **stringp, const char *delim) { - char *string = *stringp; - char *s; - const char *d; - char sc, dc; - - if (string == NULL) { - return (NULL); - } - - for (; *string != '\0'; string++) { - sc = *string; - for (d = delim; (dc = *d) != '\0'; d++) { - if (sc == dc) { - break; - } - } - if (dc == 0) { - break; - } - } - - for (s = string; *s != '\0'; s++) { - sc = *s; - for (d = delim; (dc = *d) != '\0'; d++) { - if (sc == dc) { - *s++ = '\0'; - *stringp = s; - return (string); - } - } - } - *stringp = NULL; - return (string); -} - -static void -fatal(const char *format, ...) { - va_list args; - - va_start(args, format); - vfprintf(stderr, format, args); - va_end(args); - fprintf(stderr, "\n"); - exit(1); -} - -static inline void -check_result(isc_result_t result, const char *msg) { - if (result != ISC_R_SUCCESS) { - fatal("%s: %s", msg, isc_result_totext(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); -} - -static void -parse_rdata(isc_mem_t *mctx, char **cmdlinep, dns_rdataclass_t rdataclass, - dns_rdatatype_t rdatatype, dns_rdata_t *rdata) { - char *cmdline = *cmdlinep; - isc_buffer_t source, *buf = NULL, *newbuf = NULL; - isc_region_t r; - isc_lex_t *lex = NULL; - dns_rdatacallbacks_t callbacks; - isc_result_t result; - - while (cmdline != NULL && *cmdline != 0 && - isspace((unsigned char)*cmdline)) { - cmdline++; - } - - if (cmdline != NULL && *cmdline != 0) { - dns_rdatacallbacks_init(&callbacks); - result = isc_lex_create(mctx, strlen(cmdline), &lex); - check_result(result, "isc_lex_create"); - isc_buffer_init(&source, cmdline, strlen(cmdline)); - isc_buffer_add(&source, strlen(cmdline)); - result = isc_lex_openbuffer(lex, &source); - check_result(result, "isc_lex_openbuffer"); - isc_buffer_allocate(mctx, &buf, MAXWIRE); - result = dns_rdata_fromtext(rdata, rdataclass, rdatatype, lex, - dns_rootname, 0, mctx, buf, - &callbacks); - isc_lex_destroy(&lex); - if (result == ISC_R_SUCCESS) { - isc_buffer_usedregion(buf, &r); - isc_buffer_allocate(mctx, &newbuf, r.length); - isc_buffer_putmem(newbuf, r.base, r.length); - isc_buffer_usedregion(newbuf, &r); - dns_rdata_reset(rdata); - dns_rdata_fromregion(rdata, rdataclass, rdatatype, &r); - isc_buffer_free(&buf); - ISC_LIST_APPEND(usedbuffers, newbuf, link); - } else { - fprintf(stderr, "invalid rdata format: %s\n", - isc_result_totext(result)); - isc_buffer_free(&buf); - exit(1); - } - } else { - rdata->flags = DNS_RDATA_UPDATE; - } - *cmdlinep = cmdline; -} - -static void -update_addordelete(isc_mem_t *mctx, char *cmdline, bool isdelete, - dns_name_t *name) { - isc_result_t result; - uint32_t ttl; - char *word; - dns_rdataclass_t rdataclass; - dns_rdatatype_t rdatatype; - dns_rdata_t *rdata = NULL; - dns_rdatalist_t *rdatalist = NULL; - dns_rdataset_t *rdataset = NULL; - isc_textregion_t region; - - /* - * Read the owner name. - */ - parse_name(&cmdline, name); - - rdata = isc_mem_get(mctx, sizeof(*rdata)); - dns_rdata_init(rdata); - - /* - * If this is an add, read the TTL and verify that it's in range. - * If it's a delete, ignore a TTL if present (for compatibility). - */ - word = nsu_strsep(&cmdline, " \t\r\n"); - if (word == NULL || *word == 0) { - if (!isdelete) { - fprintf(stderr, "could not read owner ttl\n"); - exit(1); - } else { - ttl = 0; - rdataclass = dns_rdataclass_any; - rdatatype = dns_rdatatype_any; - rdata->flags = DNS_RDATA_UPDATE; - goto doneparsing; - } - } - result = isc_parse_uint32(&ttl, word, 10); - if (result != ISC_R_SUCCESS) { - if (isdelete) { - ttl = 0; - goto parseclass; - } else { - fprintf(stderr, "ttl '%s': %s\n", word, - isc_result_totext(result)); - exit(1); - } - } - - if (isdelete) { - ttl = 0; - } else if (ttl > TTL_MAX) { - fprintf(stderr, "ttl '%s' is out of range (0 to %u)\n", word, - TTL_MAX); - exit(1); - } - - /* - * Read the class or type. - */ - word = nsu_strsep(&cmdline, " \t\r\n"); -parseclass: - if (word == NULL || *word == 0) { - if (isdelete) { - rdataclass = dns_rdataclass_any; - rdatatype = dns_rdatatype_any; - rdata->flags = DNS_RDATA_UPDATE; - goto doneparsing; - } else { - fprintf(stderr, "could not read class or type\n"); - exit(1); - } - } - region.base = word; - region.length = strlen(word); - result = dns_rdataclass_fromtext(&rdataclass, ®ion); - if (result == ISC_R_SUCCESS) { - /* - * Now read the type. - */ - word = nsu_strsep(&cmdline, " \t\r\n"); - if (word == NULL || *word == 0) { - if (isdelete) { - rdataclass = dns_rdataclass_any; - rdatatype = dns_rdatatype_any; - rdata->flags = DNS_RDATA_UPDATE; - goto doneparsing; - } else { - fprintf(stderr, "could not read type\n"); - exit(1); - } - } - region.base = word; - region.length = strlen(word); - result = dns_rdatatype_fromtext(&rdatatype, ®ion); - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "'%s' is not a valid type: %s\n", word, - isc_result_totext(result)); - exit(1); - } - } else { - rdataclass = default_rdataclass; - result = dns_rdatatype_fromtext(&rdatatype, ®ion); - if (result != ISC_R_SUCCESS) { - fprintf(stderr, - "'%s' is not a valid class or type: " - "%s\n", - word, isc_result_totext(result)); - exit(1); - } - } - - parse_rdata(mctx, &cmdline, rdataclass, rdatatype, rdata); - - if (isdelete) { - if ((rdata->flags & DNS_RDATA_UPDATE) != 0) { - rdataclass = dns_rdataclass_any; - } else { - rdataclass = dns_rdataclass_none; - } - } else { - if ((rdata->flags & DNS_RDATA_UPDATE) != 0) { - fprintf(stderr, "could not read rdata\n"); - exit(1); - } - } - -doneparsing: - - rdatalist = isc_mem_get(mctx, sizeof(*rdatalist)); - dns_rdatalist_init(rdatalist); - rdatalist->type = rdatatype; - rdatalist->rdclass = rdataclass; - rdatalist->covers = rdatatype; - rdatalist->ttl = (dns_ttl_t)ttl; - ISC_LIST_APPEND(rdatalist->rdata, rdata, link); - ISC_LIST_APPEND(usedrdatalists, rdatalist, link); - - rdataset = isc_mem_get(mctx, sizeof(*rdataset)); - dns_rdataset_init(rdataset); - dns_rdatalist_tordataset(rdatalist, rdataset); - dns_rdataset_setownercase(rdataset, name); - ISC_LIST_INIT(name->list); - ISC_LIST_APPEND(name->list, rdataset, link); -} - -static void -make_prereq(isc_mem_t *mctx, char *cmdline, bool ispositive, bool isrrset, - dns_name_t *name) { - isc_result_t result; - char *word; - isc_textregion_t region; - dns_rdataset_t *rdataset = NULL; - dns_rdatalist_t *rdatalist = NULL; - dns_rdataclass_t rdataclass; - dns_rdatatype_t rdatatype; - dns_rdata_t *rdata = NULL; - - /* - * Read the owner name - */ - parse_name(&cmdline, name); - - /* - * If this is an rrset prereq, read the class or type. - */ - if (isrrset) { - word = nsu_strsep(&cmdline, " \t\r\n"); - if (word == NULL || *word == 0) { - fprintf(stderr, "could not read class or type\n"); - exit(1); - } - region.base = word; - region.length = strlen(word); - result = dns_rdataclass_fromtext(&rdataclass, ®ion); - if (result == ISC_R_SUCCESS) { - /* - * Now read the type. - */ - word = nsu_strsep(&cmdline, " \t\r\n"); - if (word == NULL || *word == 0) { - fprintf(stderr, "could not read type\n"); - exit(1); - } - region.base = word; - region.length = strlen(word); - result = dns_rdatatype_fromtext(&rdatatype, ®ion); - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "invalid type: %s\n", word); - exit(1); - } - } else { - rdataclass = default_rdataclass; - result = dns_rdatatype_fromtext(&rdatatype, ®ion); - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "invalid type: %s\n", word); - exit(1); - } - } - } else { - rdatatype = dns_rdatatype_any; - } - - rdata = isc_mem_get(mctx, sizeof(*rdata)); - dns_rdata_init(rdata); - - if (isrrset && ispositive) { - parse_rdata(mctx, &cmdline, rdataclass, rdatatype, rdata); - } else { - rdata->flags = DNS_RDATA_UPDATE; - } - - rdatalist = isc_mem_get(mctx, sizeof(*rdatalist)); - dns_rdatalist_init(rdatalist); - rdatalist->type = rdatatype; - if (ispositive) { - if (isrrset && rdata->data != NULL) { - rdatalist->rdclass = rdataclass; - } else { - rdatalist->rdclass = dns_rdataclass_any; - } - } else { - rdatalist->rdclass = dns_rdataclass_none; - } - rdata->rdclass = rdatalist->rdclass; - rdata->type = rdatatype; - ISC_LIST_APPEND(rdatalist->rdata, rdata, link); - ISC_LIST_APPEND(usedrdatalists, rdatalist, link); - - rdataset = isc_mem_get(mctx, sizeof(*rdataset)); - dns_rdataset_init(rdataset); - dns_rdatalist_tordataset(rdatalist, rdataset); - dns_rdataset_setownercase(rdataset, name); - ISC_LIST_INIT(name->list); - ISC_LIST_APPEND(name->list, rdataset, link); -} - -static void -evaluate_prereq(isc_mem_t *mctx, char *cmdline, dns_name_t *name) { - char *word; - bool ispositive, isrrset; - - word = nsu_strsep(&cmdline, " \t\r\n"); - if (word == NULL || *word == 0) { - fprintf(stderr, "could not read operation code\n"); - exit(1); - } - if (strcasecmp(word, "nxdomain") == 0) { - ispositive = false; - isrrset = false; - } else if (strcasecmp(word, "yxdomain") == 0) { - ispositive = true; - isrrset = false; - } else if (strcasecmp(word, "nxrrset") == 0) { - ispositive = false; - isrrset = true; - } else if (strcasecmp(word, "yxrrset") == 0) { - ispositive = true; - isrrset = true; - } else { - fprintf(stderr, "incorrect operation code: %s\n", word); - exit(1); - } - - make_prereq(mctx, cmdline, ispositive, isrrset, name); -} - -static void -setup_tsec(char *keyfile, isc_mem_t *mctx) { - dst_key_t *dstkey = NULL; - isc_result_t result; - dns_tsectype_t tsectype; - - result = dst_key_fromnamedfile( - keyfile, NULL, DST_TYPE_PRIVATE | DST_TYPE_KEY, mctx, &dstkey); - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "could not read key from %s: %s\n", keyfile, - isc_result_totext(result)); - exit(1); - } - - if (dst_key_alg(dstkey) == DST_ALG_HMACMD5) { - tsectype = dns_tsectype_tsig; - } else { - tsectype = dns_tsectype_sig0; - } - - result = dns_tsec_create(mctx, tsectype, dstkey, &tsec); - dst_key_free(&dstkey); - if (result != ISC_R_SUCCESS) { - fprintf(stderr, "could not create tsec: %s\n", - isc_result_totext(result)); - exit(1); - } -} diff --git a/lib/samples/win32/request.vcxproj.filters.in b/lib/samples/win32/request.vcxproj.filters.in deleted file mode 100644 index 9edd41d41d..0000000000 --- a/lib/samples/win32/request.vcxproj.filters.in +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - \ No newline at end of file diff --git a/lib/samples/win32/request.vcxproj.in b/lib/samples/win32/request.vcxproj.in deleted file mode 100644 index 40045e3781..0000000000 --- a/lib/samples/win32/request.vcxproj.in +++ /dev/null @@ -1,127 +0,0 @@ - - - - - Debug - @PLATFORM@ - - - Release - @PLATFORM@ - - - - {FF440E85-7450-439C-82EE-04C464512D0E} - Win32Proj - request - @WINDOWS_TARGET_PLATFORM_VERSION@ - - - - Application - true - MultiByte - @PLATFORM_TOOLSET@ - - - Application - false - true - MultiByte - @PLATFORM_TOOLSET@ - - - - - - - - - - - - - true - ..\..\..\Build\$(Configuration)\ - .\$(Configuration)\ - None - - - false - ..\..\..\Build\$(Configuration)\ - .\$(Configuration)\ - None - - - - - - Level4 - false - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - .\$(Configuration)\$(TargetName).pch - .\$(Configuration)\ - .\$(Configuration)\ - $(OutDir)$(TargetName).pdb - true - ..\..\..\config.h - .\;..\..\..\;@LIBXML2_INC@@OPENSSL_INC@..\..\isc\win32;..\..\isc\win32\include;..\..\isc\include;..\..\dns\win32\include;..\..\dns\include;%(AdditionalIncludeDirectories) - CompileAsC - - - Console - true - ..\..\..\Build\$(Configuration)\$(TargetName)$(TargetExt) - ..\..\isc\win32\$(Configuration);..\..\dns\win32\$(Configuration);%(AdditionalLibraryDirectories) - @OPENSSL_LIBCRYPTO@@OPENSSL_LIBSSL@libisc.lib;libdns.lib;ws2_32.lib;%(AdditionalDependencies) - - - - - Level1 - true - - - MaxSpeed - true - @INTRINSIC@ - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - OnlyExplicitInline - false - true - .\$(Configuration)\$(TargetName).pch - .\$(Configuration)\ - .\$(Configuration)\ - $(OutDir)$(TargetName).pdb - ..\..\..\config.h - .\;..\..\..\;@LIBXML2_INC@@OPENSSL_INC@..\..\isc\win32;..\..\isc\win32\include;..\..\isc\include;..\..\dns\win32\include;..\..\dns\include;%(AdditionalIncludeDirectories) - CompileAsC - - - Console - false - true - true - ..\..\..\Build\$(Configuration)\$(TargetName)$(TargetExt) - Default - ..\..\isc\win32\$(Configuration);..\..\dns\win32\$(Configuration);%(AdditionalLibraryDirectories) - @OPENSSL_LIBCRYPTO@@OPENSSL_LIBSSL@libisc.lib;libdns.lib;ws2_32.lib;%(AdditionalDependencies) - - - - - - - - {3840E563-D180-4761-AA9C-E6155F02EAFF} - - - {5FEBFD4E-CCB0-48B9-B733-E15EEB85C16A} - - - - - - diff --git a/lib/samples/win32/request.vcxproj.user b/lib/samples/win32/request.vcxproj.user deleted file mode 100644 index ace9a86acb..0000000000 --- a/lib/samples/win32/request.vcxproj.user +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/lib/samples/win32/update.vcxproj.filters.in b/lib/samples/win32/update.vcxproj.filters.in deleted file mode 100644 index 8479fba535..0000000000 --- a/lib/samples/win32/update.vcxproj.filters.in +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - \ No newline at end of file diff --git a/lib/samples/win32/update.vcxproj.in b/lib/samples/win32/update.vcxproj.in deleted file mode 100644 index 7e125d77a4..0000000000 --- a/lib/samples/win32/update.vcxproj.in +++ /dev/null @@ -1,127 +0,0 @@ - - - - - Debug - @PLATFORM@ - - - Release - @PLATFORM@ - - - - {05682E12-523F-4DAE-8E6D-ADFDBC308AFD} - Win32Proj - update - @WINDOWS_TARGET_PLATFORM_VERSION@ - - - - Application - true - MultiByte - @PLATFORM_TOOLSET@ - - - Application - false - true - MultiByte - @PLATFORM_TOOLSET@ - - - - - - - - - - - - - true - ..\..\..\Build\$(Configuration)\ - .\$(Configuration)\ - None - - - false - ..\..\..\Build\$(Configuration)\ - .\$(Configuration)\ - None - - - - - - Level4 - false - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - .\$(Configuration)\$(TargetName).pch - .\$(Configuration)\ - .\$(Configuration)\ - $(OutDir)$(TargetName).pdb - true - ..\..\..\config.h - .\;..\..\..\;@LIBXML2_INC@@OPENSSL_INC@..\..\isc\win32;..\..\isc\win32\include;..\..\isc\include;..\..\dns\win32\include;..\..\dns\include;%(AdditionalIncludeDirectories) - CompileAsC - - - Console - true - ..\..\..\Build\$(Configuration)\$(TargetName)$(TargetExt) - ..\..\isc\win32\$(Configuration);..\..\dns\win32\$(Configuration);%(AdditionalLibraryDirectories) - @OPENSSL_LIBCRYPTO@@OPENSSL_LIBSSL@libisc.lib;libdns.lib;ws2_32.lib;%(AdditionalDependencies) - - - - - Level1 - true - - - MaxSpeed - true - @INTRINSIC@ - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - OnlyExplicitInline - false - true - .\$(Configuration)\$(TargetName).pch - .\$(Configuration)\ - .\$(Configuration)\ - $(OutDir)$(TargetName).pdb - ..\..\..\config.h - .\;..\..\..\;@LIBXML2_INC@@OPENSSL_INC@..\..\isc\win32;..\..\isc\win32\include;..\..\isc\include;..\..\dns\win32\include;..\..\dns\include;%(AdditionalIncludeDirectories) - CompileAsC - - - Console - false - true - true - ..\..\..\Build\$(Configuration)\$(TargetName)$(TargetExt) - Default - ..\..\isc\win32\$(Configuration);..\..\dns\win32\$(Configuration);%(AdditionalLibraryDirectories) - @OPENSSL_LIBCRYPTO@@OPENSSL_LIBSSL@libisc.lib;libdns.lib;ws2_32.lib;%(AdditionalDependencies) - - - - - - - - {3840E563-D180-4761-AA9C-E6155F02EAFF} - - - {5FEBFD4E-CCB0-48B9-B733-E15EEB85C16A} - - - - - - diff --git a/lib/samples/win32/update.vcxproj.user b/lib/samples/win32/update.vcxproj.user deleted file mode 100644 index ace9a86acb..0000000000 --- a/lib/samples/win32/update.vcxproj.user +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/util/copyrights b/util/copyrights index feb63b8979..e46a3c90ce 100644 --- a/util/copyrights +++ b/util/copyrights @@ -2193,23 +2193,15 @@ ./lib/samples/resolve.c C 2009,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021 ./lib/samples/rootkey.sh SH 2013,2016,2018,2019,2020,2021 ./lib/samples/sample-async.c C 2009,2013,2014,2015,2016,2018,2019,2020,2021 -./lib/samples/sample-request.c C 2009,2012,2013,2014,2015,2016,2018,2019,2020,2021 -./lib/samples/sample-update.c C 2009,2010,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021 ./lib/samples/win32/async.vcxproj.filters.in X 2014,2015,2018,2019,2020 ./lib/samples/win32/async.vcxproj.in X 2014,2015,2016,2017,2018,2019,2020 ./lib/samples/win32/async.vcxproj.user X 2014,2018,2019,2020,2021 ./lib/samples/win32/nsprobe.vcxproj.filters.in X 2014,2015,2018,2019,2020 ./lib/samples/win32/nsprobe.vcxproj.in X 2014,2015,2016,2017,2018,2019,2020 ./lib/samples/win32/nsprobe.vcxproj.user X 2014,2018,2019,2020,2021 -./lib/samples/win32/request.vcxproj.filters.in X 2014,2015,2018,2019,2020 -./lib/samples/win32/request.vcxproj.in X 2014,2015,2016,2017,2018,2019,2020 -./lib/samples/win32/request.vcxproj.user X 2014,2018,2019,2020,2021 ./lib/samples/win32/resolve.vcxproj.filters.in X 2014,2015,2018,2019,2020 ./lib/samples/win32/resolve.vcxproj.in X 2014,2015,2016,2017,2018,2019,2020 ./lib/samples/win32/resolve.vcxproj.user X 2014,2018,2019,2020,2021 -./lib/samples/win32/update.vcxproj.filters.in X 2014,2015,2018,2019,2020 -./lib/samples/win32/update.vcxproj.in X 2014,2015,2016,2017,2018,2019,2020 -./lib/samples/win32/update.vcxproj.user X 2014,2018,2019,2020,2021 ./lib/win32/bindevt/bindevt.c C 2000,2001,2004,2007,2016,2018,2019,2020,2021 ./lib/win32/bindevt/bindevt.mc X 2001,2004,2007,2016,2018,2019,2020,2021 ./lib/win32/bindevt/bindevt.vcxproj.filters.in X 2013,2015,2018,2019,2020 diff --git a/win32utils/Configure b/win32utils/Configure index 57e94d70a4..42660889d2 100644 --- a/win32utils/Configure +++ b/win32utils/Configure @@ -133,10 +133,6 @@ my @projectlist = ("../bin/check/win32/checkconf.vcxproj", "../lib/samples/win32/resolve.vcxproj.filters", "../lib/samples/win32/async.vcxproj", "../lib/samples/win32/async.vcxproj.filters", - "../lib/samples/win32/update.vcxproj", - "../lib/samples/win32/update.vcxproj.filters", - "../lib/samples/win32/request.vcxproj", - "../lib/samples/win32/request.vcxproj.filters", "../lib/samples/win32/nsprobe.vcxproj", "../lib/samples/win32/nsprobe.vcxproj.filters", "../lib/win32/bindevt/bindevt.vcxproj", diff --git a/win32utils/bind9.sln.in b/win32utils/bind9.sln.in index fe004aece3..3da2ffe9a6 100644 --- a/win32utils/bind9.sln.in +++ b/win32utils/bind9.sln.in @@ -29,10 +29,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "async", "..\lib\samples\win EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gai", "..\lib\samples\win32\gai.vcxproj", "{D42B8670-8DF6-4D90-90F7-DB5FB845AFAE}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "update", "..\lib\samples\win32\update.vcxproj", "{05682E12-523F-4DAE-8E6D-ADFDBC308AFD}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "request", "..\lib\samples\win32\request.vcxproj", "{FF440E85-7450-439C-82EE-04C464512D0E}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nsprobe", "..\lib\samples\win32\nsprobe.vcxproj", "{CB2A29F6-E73B-40AB-8AC4-2C1AAE7280BD}" EndProject @END SAMPLES