2000-06-10 00:50:36 +00:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2016-06-27 14:56:38 +10:00
|
|
|
* 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
|
2020-09-14 16:20:40 -07:00
|
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
2000-06-10 00:50:36 +00:00
|
|
|
*/
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*! \file */
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-08-10 02:32:14 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
2018-03-28 14:19:37 +02:00
|
|
|
#include <inttypes.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <limits.h>
|
2018-04-17 08:29:14 -07:00
|
|
|
#include <stdbool.h>
|
2000-08-10 02:32:14 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2000-09-01 21:34:12 +00:00
|
|
|
#include <isc/app.h>
|
2018-08-07 16:46:53 +02:00
|
|
|
#include <isc/attributes.h>
|
2000-06-23 20:46:25 +00:00
|
|
|
#include <isc/base64.h>
|
2000-06-21 17:48:32 +00:00
|
|
|
#include <isc/buffer.h>
|
2000-06-30 01:56:14 +00:00
|
|
|
#include <isc/commandline.h>
|
2000-09-01 21:34:12 +00:00
|
|
|
#include <isc/event.h>
|
2009-06-10 00:27:22 +00:00
|
|
|
#include <isc/file.h>
|
2003-07-25 02:22:26 +00:00
|
|
|
#include <isc/hash.h>
|
2000-06-21 17:48:32 +00:00
|
|
|
#include <isc/lex.h>
|
2006-12-04 01:54:53 +00:00
|
|
|
#include <isc/log.h>
|
2021-04-27 00:07:43 +02:00
|
|
|
#include <isc/managers.h>
|
2000-06-10 00:50:36 +00:00
|
|
|
#include <isc/mem.h>
|
2021-01-14 13:02:57 -08:00
|
|
|
#include <isc/netmgr.h>
|
2018-05-28 15:22:23 +02:00
|
|
|
#include <isc/nonce.h>
|
2001-11-30 01:02:18 +00:00
|
|
|
#include <isc/parseint.h>
|
2019-03-06 14:01:24 +01:00
|
|
|
#include <isc/portset.h>
|
2009-06-10 01:44:53 +00:00
|
|
|
#include <isc/print.h>
|
2006-12-04 01:54:53 +00:00
|
|
|
#include <isc/random.h>
|
2000-06-10 00:50:36 +00:00
|
|
|
#include <isc/region.h>
|
2021-10-04 17:14:53 +02:00
|
|
|
#include <isc/result.h>
|
2000-06-21 17:48:32 +00:00
|
|
|
#include <isc/sockaddr.h>
|
2000-11-27 00:43:33 +00:00
|
|
|
#include <isc/stdio.h>
|
2000-06-10 00:50:36 +00:00
|
|
|
#include <isc/string.h>
|
2000-06-21 17:48:32 +00:00
|
|
|
#include <isc/task.h>
|
2000-06-23 20:46:25 +00:00
|
|
|
#include <isc/types.h>
|
2000-06-21 17:48:32 +00:00
|
|
|
#include <isc/util.h>
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
#include <dns/callbacks.h>
|
|
|
|
#include <dns/dispatch.h>
|
2002-01-21 07:59:15 +00:00
|
|
|
#include <dns/dnssec.h>
|
2000-06-30 01:56:14 +00:00
|
|
|
#include <dns/events.h>
|
2000-07-31 22:11:13 +00:00
|
|
|
#include <dns/fixedname.h>
|
2006-12-04 01:54:53 +00:00
|
|
|
#include <dns/log.h>
|
2001-03-28 02:42:56 +00:00
|
|
|
#include <dns/masterdump.h>
|
2000-06-30 01:56:14 +00:00
|
|
|
#include <dns/message.h>
|
|
|
|
#include <dns/name.h>
|
2021-04-23 10:03:53 +10:00
|
|
|
#include <dns/nsec3.h>
|
2004-03-04 01:21:39 +00:00
|
|
|
#include <dns/rcode.h>
|
2000-06-30 01:56:14 +00:00
|
|
|
#include <dns/rdata.h>
|
|
|
|
#include <dns/rdataclass.h>
|
|
|
|
#include <dns/rdatalist.h>
|
|
|
|
#include <dns/rdataset.h>
|
|
|
|
#include <dns/rdatastruct.h>
|
|
|
|
#include <dns/rdatatype.h>
|
|
|
|
#include <dns/request.h>
|
2006-12-04 01:54:53 +00:00
|
|
|
#include <dns/tkey.h>
|
2000-06-30 01:56:14 +00:00
|
|
|
#include <dns/tsig.h>
|
2000-07-03 23:42:48 +00:00
|
|
|
|
2020-03-09 16:17:26 +01:00
|
|
|
#include <dst/dst.h>
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <isccfg/namedconf.h>
|
2000-06-30 01:56:14 +00:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
#include <irs/resconf.h>
|
2000-06-30 21:47:35 +00:00
|
|
|
|
2018-08-07 16:46:53 +02:00
|
|
|
#if HAVE_GSSAPI
|
2006-12-04 01:54:53 +00:00
|
|
|
#include <dst/gssapi.h>
|
2018-08-07 16:46:53 +02:00
|
|
|
|
|
|
|
#if HAVE_KRB5_KRB5_H
|
2013-12-04 12:47:23 +11:00
|
|
|
#include <krb5/krb5.h>
|
2018-08-07 16:46:53 +02:00
|
|
|
#elif HAVE_KRB5_H
|
|
|
|
#include <krb5.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAVE_GSSAPI_GSSAPI_H
|
|
|
|
#include <gssapi/gssapi.h>
|
|
|
|
#elif HAVE_GSSAPI_H
|
|
|
|
#include <gssapi.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* HAVE_GSSAPI */
|
|
|
|
|
2001-11-14 22:08:38 +00:00
|
|
|
#include <bind9/getaddresses.h>
|
|
|
|
|
2021-02-11 14:13:27 +01:00
|
|
|
#include "../dig/readline.h"
|
|
|
|
|
2020-02-13 14:44:37 -08:00
|
|
|
#define MAXCMD (128 * 1024)
|
|
|
|
#define MAXWIRE (64 * 1024)
|
|
|
|
#define INITTEXT (2 * 1024)
|
|
|
|
#define MAXTEXT (128 * 1024)
|
2000-06-10 00:50:36 +00:00
|
|
|
#define FIND_TIMEOUT 5
|
2020-02-13 14:44:37 -08:00
|
|
|
#define TTL_MAX 2147483647U /* Maximum signed 32 bit integer. */
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-07-05 23:24:18 +00:00
|
|
|
#define DNSDEFAULTPORT 53
|
|
|
|
|
2014-02-11 21:29:10 -08:00
|
|
|
/* Number of addresses to request from bind9_getaddresses() */
|
|
|
|
#define MAX_SERVERADDRS 4
|
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
static uint16_t dnsport = DNSDEFAULTPORT;
|
2009-06-10 00:27:22 +00:00
|
|
|
|
2001-09-01 05:09:33 +00:00
|
|
|
#ifndef RESOLV_CONF
|
2000-06-10 00:50:36 +00:00
|
|
|
#define RESOLV_CONF "/etc/resolv.conf"
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifndef RESOLV_CONF */
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2020-02-13 14:44:37 -08:00
|
|
|
static bool debugging = false, ddebugging = false;
|
|
|
|
static bool memdebugging = false;
|
|
|
|
static bool have_ipv4 = false;
|
|
|
|
static bool have_ipv6 = false;
|
|
|
|
static bool is_dst_up = false;
|
|
|
|
static bool usevc = false;
|
|
|
|
static bool usegsstsig = false;
|
|
|
|
static bool use_win2k_gsstsig = false;
|
|
|
|
static bool tried_other_gsstsig = false;
|
|
|
|
static bool local_only = false;
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 11:31:19 +02:00
|
|
|
static isc_nm_t *netmgr = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
static isc_taskmgr_t *taskmgr = NULL;
|
|
|
|
static isc_task_t *global_task = NULL;
|
|
|
|
static isc_event_t *global_event = NULL;
|
|
|
|
static isc_log_t *glctx = NULL;
|
|
|
|
static isc_mem_t *gmctx = NULL;
|
|
|
|
static dns_dispatchmgr_t *dispatchmgr = NULL;
|
|
|
|
static dns_requestmgr_t *requestmgr = NULL;
|
|
|
|
static dns_dispatch_t *dispatchv4 = NULL;
|
|
|
|
static dns_dispatch_t *dispatchv6 = NULL;
|
|
|
|
static dns_message_t *updatemsg = NULL;
|
|
|
|
static dns_fixedname_t fuserzone;
|
|
|
|
static dns_fixedname_t fzname;
|
|
|
|
static dns_name_t *userzone = NULL;
|
|
|
|
static dns_name_t *zname = NULL;
|
|
|
|
static dns_name_t tmpzonename = DNS_NAME_INITEMPTY;
|
2021-10-05 11:28:24 +02:00
|
|
|
static dns_name_t restart_primary = DNS_NAME_INITEMPTY;
|
2020-02-13 14:44:37 -08:00
|
|
|
static dns_tsig_keyring_t *gssring = NULL;
|
|
|
|
static dns_tsigkey_t *tsigkey = NULL;
|
|
|
|
static dst_key_t *sig0key = NULL;
|
|
|
|
static isc_sockaddr_t *servers = NULL;
|
2021-10-05 11:28:24 +02:00
|
|
|
static isc_sockaddr_t *primary_servers = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
static bool default_servers = true;
|
|
|
|
static int ns_inuse = 0;
|
2021-10-05 11:28:24 +02:00
|
|
|
static int primary_inuse = 0;
|
2020-02-13 14:44:37 -08:00
|
|
|
static int ns_total = 0;
|
|
|
|
static int ns_alloc = 0;
|
2021-10-05 11:28:24 +02:00
|
|
|
static int primary_total = 0;
|
|
|
|
static int primary_alloc = 0;
|
2020-02-13 14:44:37 -08:00
|
|
|
static isc_sockaddr_t *localaddr4 = NULL;
|
|
|
|
static isc_sockaddr_t *localaddr6 = NULL;
|
|
|
|
static const char *keyfile = NULL;
|
|
|
|
static char *keystr = NULL;
|
|
|
|
static bool shuttingdown = false;
|
|
|
|
static FILE *input;
|
|
|
|
static bool interactive = true;
|
|
|
|
static bool seenerror = false;
|
2001-07-22 06:11:44 +00:00
|
|
|
static const dns_master_style_t *style;
|
2020-02-13 14:44:37 -08:00
|
|
|
static int requests = 0;
|
|
|
|
static unsigned int logdebuglevel = 0;
|
|
|
|
static unsigned int timeout = 300;
|
|
|
|
static unsigned int udp_timeout = 3;
|
|
|
|
static unsigned int udp_retries = 3;
|
|
|
|
static dns_rdataclass_t defaultclass = dns_rdataclass_in;
|
|
|
|
static dns_rdataclass_t zoneclass = dns_rdataclass_none;
|
2020-05-19 13:25:41 +10:00
|
|
|
static isc_mutex_t answer_lock;
|
2020-02-13 14:44:37 -08:00
|
|
|
static dns_message_t *answer = NULL;
|
|
|
|
static uint32_t default_ttl = 0;
|
|
|
|
static bool default_ttl_set = false;
|
|
|
|
static bool checknames = true;
|
2021-06-09 14:19:46 -07:00
|
|
|
static const char *resolvconf = RESOLV_CONF;
|
2000-06-30 01:56:14 +00:00
|
|
|
|
2000-07-05 23:24:18 +00:00
|
|
|
typedef struct nsu_requestinfo {
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_message_t *msg;
|
2000-07-05 23:24:18 +00:00
|
|
|
isc_sockaddr_t *addr;
|
|
|
|
} nsu_requestinfo_t;
|
|
|
|
|
2020-02-14 08:14:03 +01:00
|
|
|
static void
|
|
|
|
sendrequest(isc_sockaddr_t *destaddr, dns_message_t *msg,
|
|
|
|
dns_request_t **request);
|
|
|
|
static void
|
2021-10-05 11:28:24 +02:00
|
|
|
send_update(dns_name_t *zonename, isc_sockaddr_t *primary);
|
2009-09-29 15:06:07 +00:00
|
|
|
|
2018-08-07 16:46:53 +02:00
|
|
|
ISC_NORETURN static void
|
|
|
|
fatal(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
|
2001-08-08 22:54:55 +00:00
|
|
|
|
2020-02-14 08:14:03 +01:00
|
|
|
static void
|
|
|
|
debug(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
|
2001-08-08 22:54:55 +00:00
|
|
|
|
2020-02-14 08:14:03 +01:00
|
|
|
static void
|
|
|
|
ddebug(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2018-08-07 16:46:53 +02:00
|
|
|
#if HAVE_GSSAPI
|
2006-12-04 01:54:53 +00:00
|
|
|
static dns_fixedname_t fkname;
|
|
|
|
static isc_sockaddr_t *kserver = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
static char *realm = NULL;
|
|
|
|
static char servicename[DNS_NAME_FORMATSIZE];
|
|
|
|
static dns_name_t *keyname;
|
2006-12-04 01:54:53 +00:00
|
|
|
typedef struct nsu_gssinfo {
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_message_t *msg;
|
2006-12-04 01:54:53 +00:00
|
|
|
isc_sockaddr_t *addr;
|
2020-02-13 14:44:37 -08:00
|
|
|
gss_ctx_id_t context;
|
2006-12-04 01:54:53 +00:00
|
|
|
} nsu_gssinfo_t;
|
|
|
|
|
2020-02-14 08:14:03 +01:00
|
|
|
static void
|
2018-08-07 16:46:53 +02:00
|
|
|
failed_gssrequest(void);
|
2020-02-14 08:14:03 +01:00
|
|
|
static void
|
2021-10-05 11:28:24 +02:00
|
|
|
start_gssrequest(dns_name_t *primary);
|
2020-02-14 08:14:03 +01:00
|
|
|
static void
|
|
|
|
send_gssrequest(isc_sockaddr_t *destaddr, dns_message_t *msg,
|
|
|
|
dns_request_t **request, gss_ctx_id_t context);
|
|
|
|
static void
|
|
|
|
recvgss(isc_task_t *task, isc_event_t *event);
|
2018-08-07 16:46:53 +02:00
|
|
|
#endif /* HAVE_GSSAPI */
|
2006-12-04 01:54:53 +00:00
|
|
|
|
2020-02-14 08:14:03 +01:00
|
|
|
static void
|
|
|
|
error(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
|
2006-12-07 05:39:41 +00:00
|
|
|
|
2020-02-13 14:44:37 -08:00
|
|
|
#define STATUS_MORE (uint16_t)0
|
|
|
|
#define STATUS_SEND (uint16_t)1
|
|
|
|
#define STATUS_QUIT (uint16_t)2
|
2020-02-12 13:59:18 +01:00
|
|
|
#define STATUS_SYNTAX (uint16_t)3
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2014-12-05 18:26:38 +11:00
|
|
|
static void
|
2021-10-05 11:28:24 +02:00
|
|
|
primary_from_servers(void) {
|
|
|
|
if (primary_servers != NULL && primary_servers != servers) {
|
|
|
|
isc_mem_put(gmctx, primary_servers,
|
|
|
|
primary_alloc * sizeof(isc_sockaddr_t));
|
|
|
|
}
|
|
|
|
primary_servers = servers;
|
|
|
|
primary_total = ns_total;
|
|
|
|
primary_alloc = ns_alloc;
|
|
|
|
primary_inuse = ns_inuse;
|
2014-12-05 18:26:38 +11:00
|
|
|
}
|
2007-09-15 14:46:03 +00:00
|
|
|
|
2004-03-03 23:43:09 +00:00
|
|
|
static dns_rdataclass_t
|
2020-02-13 14:44:37 -08:00
|
|
|
getzoneclass(void) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (zoneclass == dns_rdataclass_none) {
|
2004-03-03 23:43:09 +00:00
|
|
|
zoneclass = defaultclass;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2004-03-03 23:43:09 +00:00
|
|
|
return (zoneclass);
|
|
|
|
}
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
static bool
|
2020-02-13 14:44:37 -08:00
|
|
|
setzoneclass(dns_rdataclass_t rdclass) {
|
|
|
|
if (zoneclass == dns_rdataclass_none || rdclass == dns_rdataclass_none)
|
|
|
|
{
|
2004-03-03 23:43:09 +00:00
|
|
|
zoneclass = rdclass;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (zoneclass != rdclass) {
|
2018-04-17 08:29:14 -07:00
|
|
|
return (false);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2004-03-03 23:43:09 +00:00
|
|
|
}
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
fatal(const char *format, ...) {
|
2000-06-10 00:50:36 +00:00
|
|
|
va_list args;
|
|
|
|
|
2000-08-01 01:33:37 +00:00
|
|
|
va_start(args, format);
|
2000-06-10 00:50:36 +00:00
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
va_end(args);
|
|
|
|
fprintf(stderr, "\n");
|
2000-06-30 01:56:14 +00:00
|
|
|
exit(1);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
2006-12-07 05:39:41 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
error(const char *format, ...) {
|
2006-12-07 05:39:41 +00:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
va_end(args);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
debug(const char *format, ...) {
|
2000-06-10 00:50:36 +00:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
if (debugging) {
|
2000-08-01 01:33:37 +00:00
|
|
|
va_start(args, format);
|
2000-06-10 00:50:36 +00:00
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
va_end(args);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-16 17:10:02 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
ddebug(const char *format, ...) {
|
2000-06-16 17:10:02 +00:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
if (ddebugging) {
|
2000-08-01 01:33:37 +00:00
|
|
|
va_start(args, format);
|
2000-06-16 17:10:02 +00:00
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
va_end(args);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-09 16:17:13 +00:00
|
|
|
static inline void
|
2020-02-13 14:44:37 -08:00
|
|
|
check_result(isc_result_t result, const char *msg) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-06-10 00:50:36 +00:00
|
|
|
fatal("%s: %s", msg, isc_result_totext(result));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
2000-06-30 03:24:27 +00:00
|
|
|
static char *
|
2020-02-13 14:44:37 -08:00
|
|
|
nsu_strsep(char **stringp, const char *delim) {
|
2000-06-30 03:24:27 +00:00
|
|
|
char *string = *stringp;
|
2020-02-08 04:37:54 -08:00
|
|
|
*stringp = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
char *s;
|
2000-06-30 03:24:27 +00:00
|
|
|
const char *d;
|
2020-02-13 14:44:37 -08:00
|
|
|
char sc, dc;
|
2000-06-30 03:24:27 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (string == NULL) {
|
2000-06-30 03:24:27 +00:00
|
|
|
return (NULL);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-06-30 03:24:27 +00:00
|
|
|
|
2000-06-30 06:35:50 +00:00
|
|
|
for (; *string != '\0'; string++) {
|
|
|
|
sc = *string;
|
|
|
|
for (d = delim; (dc = *d) != '\0'; d++) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (sc == dc) {
|
2000-06-30 06:35:50 +00:00
|
|
|
break;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-06-30 06:35:50 +00:00
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
if (dc == 0) {
|
2000-06-30 06:35:50 +00:00
|
|
|
break;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-06-30 06:35:50 +00:00
|
|
|
}
|
|
|
|
|
2000-06-30 03:24:27 +00:00
|
|
|
for (s = string; *s != '\0'; s++) {
|
|
|
|
sc = *s;
|
2000-06-30 06:35:50 +00:00
|
|
|
for (d = delim; (dc = *d) != '\0'; d++) {
|
2000-06-30 03:24:27 +00:00
|
|
|
if (sc == dc) {
|
|
|
|
*s++ = '\0';
|
|
|
|
*stringp = s;
|
|
|
|
return (string);
|
|
|
|
}
|
2000-06-30 06:35:50 +00:00
|
|
|
}
|
2000-06-30 03:24:27 +00:00
|
|
|
}
|
|
|
|
return (string);
|
|
|
|
}
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
reset_system(void) {
|
2000-07-09 16:17:13 +00:00
|
|
|
ddebug("reset_system()");
|
2000-06-10 00:50:36 +00:00
|
|
|
/* If the update message is still around, destroy it */
|
2020-02-13 21:48:23 +01:00
|
|
|
if (updatemsg != NULL) {
|
2000-06-30 01:56:14 +00:00
|
|
|
dns_message_reset(updatemsg, DNS_MESSAGE_INTENTRENDER);
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2020-09-25 11:51:36 +02:00
|
|
|
dns_message_create(gmctx, DNS_MESSAGE_INTENTRENDER, &updatemsg);
|
2000-06-30 01:56:14 +00:00
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
updatemsg->opcode = dns_opcode_update;
|
2006-12-04 01:54:53 +00:00
|
|
|
if (usegsstsig) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (tsigkey != NULL) {
|
2006-12-04 01:54:53 +00:00
|
|
|
dns_tsigkey_detach(&tsigkey);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (gssring != NULL) {
|
2011-01-10 05:32:04 +00:00
|
|
|
dns_tsigkeyring_detach(&gssring);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2018-04-17 08:29:14 -07:00
|
|
|
tried_other_gsstsig = false;
|
2006-12-04 01:54:53 +00:00
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
static bool
|
2017-06-12 11:16:18 +02:00
|
|
|
parse_hmac(const dns_name_t **hmac, const char *hmacstr, size_t len,
|
2020-02-13 14:44:37 -08:00
|
|
|
uint16_t *digestbitsp) {
|
|
|
|
uint16_t digestbits = 0;
|
2006-01-27 02:35:15 +00:00
|
|
|
isc_result_t result;
|
2020-02-13 14:44:37 -08:00
|
|
|
char buf[20];
|
2006-01-27 02:35:15 +00:00
|
|
|
|
|
|
|
REQUIRE(hmac != NULL && *hmac == NULL);
|
|
|
|
REQUIRE(hmacstr != NULL);
|
|
|
|
|
2017-06-12 11:16:18 +02:00
|
|
|
if (len >= sizeof(buf)) {
|
|
|
|
error("unknown key type '%.*s'", (int)(len), hmacstr);
|
2018-04-17 08:29:14 -07:00
|
|
|
return (false);
|
2017-06-12 11:16:18 +02:00
|
|
|
}
|
2006-01-27 02:35:15 +00:00
|
|
|
|
2017-09-14 18:11:56 +10:00
|
|
|
/* Copy len bytes and NUL terminate. */
|
|
|
|
strlcpy(buf, hmacstr, ISC_MIN(len + 1, sizeof(buf)));
|
2008-01-18 23:46:58 +00:00
|
|
|
|
2006-01-27 02:35:15 +00:00
|
|
|
if (strcasecmp(buf, "hmac-md5") == 0) {
|
|
|
|
*hmac = DNS_TSIG_HMACMD5_NAME;
|
|
|
|
} else if (strncasecmp(buf, "hmac-md5-", 9) == 0) {
|
|
|
|
*hmac = DNS_TSIG_HMACMD5_NAME;
|
|
|
|
result = isc_parse_uint16(&digestbits, &buf[9], 10);
|
2017-06-12 11:16:18 +02:00
|
|
|
if (result != ISC_R_SUCCESS || digestbits > 128) {
|
|
|
|
error("digest-bits out of range [0..128]");
|
2018-04-17 08:29:14 -07:00
|
|
|
return (false);
|
2017-06-12 11:16:18 +02:00
|
|
|
}
|
|
|
|
*digestbitsp = (digestbits + 7) & ~0x7U;
|
2018-06-12 11:26:04 +02:00
|
|
|
} else if (strcasecmp(buf, "hmac-sha1") == 0) {
|
2006-01-27 02:35:15 +00:00
|
|
|
*hmac = DNS_TSIG_HMACSHA1_NAME;
|
|
|
|
} else if (strncasecmp(buf, "hmac-sha1-", 10) == 0) {
|
|
|
|
*hmac = DNS_TSIG_HMACSHA1_NAME;
|
|
|
|
result = isc_parse_uint16(&digestbits, &buf[10], 10);
|
2017-06-12 11:16:18 +02:00
|
|
|
if (result != ISC_R_SUCCESS || digestbits > 160) {
|
|
|
|
error("digest-bits out of range [0..160]");
|
2018-04-17 08:29:14 -07:00
|
|
|
return (false);
|
2017-06-12 11:16:18 +02:00
|
|
|
}
|
|
|
|
*digestbitsp = (digestbits + 7) & ~0x7U;
|
2006-01-27 02:35:15 +00:00
|
|
|
} else if (strcasecmp(buf, "hmac-sha224") == 0) {
|
|
|
|
*hmac = DNS_TSIG_HMACSHA224_NAME;
|
|
|
|
} else if (strncasecmp(buf, "hmac-sha224-", 12) == 0) {
|
|
|
|
*hmac = DNS_TSIG_HMACSHA224_NAME;
|
|
|
|
result = isc_parse_uint16(&digestbits, &buf[12], 10);
|
2017-06-12 11:16:18 +02:00
|
|
|
if (result != ISC_R_SUCCESS || digestbits > 224) {
|
|
|
|
error("digest-bits out of range [0..224]");
|
2018-04-17 08:29:14 -07:00
|
|
|
return (false);
|
2017-06-12 11:16:18 +02:00
|
|
|
}
|
|
|
|
*digestbitsp = (digestbits + 7) & ~0x7U;
|
2006-01-27 02:35:15 +00:00
|
|
|
} else if (strcasecmp(buf, "hmac-sha256") == 0) {
|
|
|
|
*hmac = DNS_TSIG_HMACSHA256_NAME;
|
|
|
|
} else if (strncasecmp(buf, "hmac-sha256-", 12) == 0) {
|
|
|
|
*hmac = DNS_TSIG_HMACSHA256_NAME;
|
|
|
|
result = isc_parse_uint16(&digestbits, &buf[12], 10);
|
2017-06-12 11:16:18 +02:00
|
|
|
if (result != ISC_R_SUCCESS || digestbits > 256) {
|
|
|
|
error("digest-bits out of range [0..256]");
|
2018-04-17 08:29:14 -07:00
|
|
|
return (false);
|
2017-06-12 11:16:18 +02:00
|
|
|
}
|
|
|
|
*digestbitsp = (digestbits + 7) & ~0x7U;
|
2006-01-27 02:35:15 +00:00
|
|
|
} else if (strcasecmp(buf, "hmac-sha384") == 0) {
|
|
|
|
*hmac = DNS_TSIG_HMACSHA384_NAME;
|
|
|
|
} else if (strncasecmp(buf, "hmac-sha384-", 12) == 0) {
|
|
|
|
*hmac = DNS_TSIG_HMACSHA384_NAME;
|
|
|
|
result = isc_parse_uint16(&digestbits, &buf[12], 10);
|
2017-06-12 11:16:18 +02:00
|
|
|
if (result != ISC_R_SUCCESS || digestbits > 384) {
|
|
|
|
error("digest-bits out of range [0..384]");
|
2018-04-17 08:29:14 -07:00
|
|
|
return (false);
|
2017-06-12 11:16:18 +02:00
|
|
|
}
|
|
|
|
*digestbitsp = (digestbits + 7) & ~0x7U;
|
2006-01-27 02:35:15 +00:00
|
|
|
} else if (strcasecmp(buf, "hmac-sha512") == 0) {
|
|
|
|
*hmac = DNS_TSIG_HMACSHA512_NAME;
|
|
|
|
} else if (strncasecmp(buf, "hmac-sha512-", 12) == 0) {
|
|
|
|
*hmac = DNS_TSIG_HMACSHA512_NAME;
|
|
|
|
result = isc_parse_uint16(&digestbits, &buf[12], 10);
|
2017-06-12 11:16:18 +02:00
|
|
|
if (result != ISC_R_SUCCESS || digestbits > 512) {
|
|
|
|
error("digest-bits out of range [0..512]");
|
2018-04-17 08:29:14 -07:00
|
|
|
return (false);
|
2017-06-12 11:16:18 +02:00
|
|
|
}
|
|
|
|
*digestbitsp = (digestbits + 7) & ~0x7U;
|
|
|
|
} else {
|
|
|
|
error("unknown key type '%s'", buf);
|
2018-04-17 08:29:14 -07:00
|
|
|
return (false);
|
2017-06-12 11:16:18 +02:00
|
|
|
}
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2006-01-27 02:35:15 +00:00
|
|
|
}
|
|
|
|
|
2010-08-10 09:51:47 +00:00
|
|
|
static int
|
2020-02-13 14:44:37 -08:00
|
|
|
basenamelen(const char *file) {
|
2010-08-10 23:48:19 +00:00
|
|
|
int len = strlen(file);
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (len > 1 && file[len - 1] == '.') {
|
2010-08-10 23:48:19 +00:00
|
|
|
len -= 1;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else if (len > 8 && strcmp(file + len - 8, ".private") == 0) {
|
2010-08-10 23:48:19 +00:00
|
|
|
len -= 8;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else if (len > 4 && strcmp(file + len - 4, ".key") == 0) {
|
2010-08-10 23:48:19 +00:00
|
|
|
len -= 4;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2010-08-10 09:51:47 +00:00
|
|
|
return (len);
|
|
|
|
}
|
|
|
|
|
2000-07-03 23:42:48 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
setup_keystr(void) {
|
|
|
|
unsigned char *secret = NULL;
|
|
|
|
int secretlen;
|
|
|
|
isc_buffer_t secretbuf;
|
|
|
|
isc_result_t result;
|
|
|
|
isc_buffer_t keynamesrc;
|
|
|
|
char *secretstr;
|
|
|
|
char *s, *n;
|
|
|
|
dns_fixedname_t fkeyname;
|
|
|
|
dns_name_t *mykeyname;
|
|
|
|
char *name;
|
2016-12-30 15:45:08 +11:00
|
|
|
const dns_name_t *hmacname = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
uint16_t digestbits = 0;
|
2000-07-03 23:42:48 +00:00
|
|
|
|
2018-03-28 14:38:09 +02:00
|
|
|
mykeyname = dns_fixedname_initname(&fkeyname);
|
2000-08-02 02:34:40 +00:00
|
|
|
|
2001-09-27 17:53:39 +00:00
|
|
|
debug("Creating key...");
|
2000-07-03 23:42:48 +00:00
|
|
|
|
2001-09-27 17:53:39 +00:00
|
|
|
s = strchr(keystr, ':');
|
2020-02-13 21:48:23 +01:00
|
|
|
if (s == NULL || s == keystr || s[1] == 0) {
|
2006-01-27 02:35:15 +00:00
|
|
|
fatal("key option must specify [hmac:]keyname:secret");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2001-09-27 17:53:39 +00:00
|
|
|
secretstr = s + 1;
|
2006-01-27 02:35:15 +00:00
|
|
|
n = strchr(secretstr, ':');
|
|
|
|
if (n != NULL) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (n == secretstr || n[1] == 0) {
|
2006-01-27 02:35:15 +00:00
|
|
|
fatal("key option must specify [hmac:]keyname:secret");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2006-01-27 02:35:15 +00:00
|
|
|
name = secretstr;
|
|
|
|
secretstr = n + 1;
|
2017-06-12 11:16:18 +02:00
|
|
|
if (!parse_hmac(&hmacname, keystr, s - keystr, &digestbits)) {
|
|
|
|
exit(1);
|
|
|
|
}
|
2006-01-27 02:35:15 +00:00
|
|
|
} else {
|
|
|
|
hmacname = DNS_TSIG_HMACMD5_NAME;
|
|
|
|
name = keystr;
|
|
|
|
n = s;
|
|
|
|
}
|
2000-07-03 23:42:48 +00:00
|
|
|
|
2013-12-04 12:47:23 +11:00
|
|
|
isc_buffer_init(&keynamesrc, name, (unsigned int)(n - name));
|
|
|
|
isc_buffer_add(&keynamesrc, (unsigned int)(n - name));
|
2000-07-03 23:42:48 +00:00
|
|
|
|
2001-09-27 17:53:39 +00:00
|
|
|
debug("namefromtext");
|
2015-01-20 13:29:18 -08:00
|
|
|
result = dns_name_fromtext(mykeyname, &keynamesrc, dns_rootname, 0,
|
|
|
|
NULL);
|
2001-09-27 17:53:39 +00:00
|
|
|
check_result(result, "dns_name_fromtext");
|
2000-07-03 23:42:48 +00:00
|
|
|
|
2001-09-27 17:53:39 +00:00
|
|
|
secretlen = strlen(secretstr) * 3 / 4;
|
2015-01-20 13:29:18 -08:00
|
|
|
secret = isc_mem_allocate(gmctx, secretlen);
|
2000-07-17 17:42:54 +00:00
|
|
|
|
2001-09-27 17:53:39 +00:00
|
|
|
isc_buffer_init(&secretbuf, secret, secretlen);
|
|
|
|
result = isc_base64_decodestring(secretstr, &secretbuf);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr, "could not create key from %s: %s\n", keystr,
|
|
|
|
isc_result_totext(result));
|
2001-09-27 17:53:39 +00:00
|
|
|
goto failure;
|
2000-07-03 23:42:48 +00:00
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2001-09-27 17:53:39 +00:00
|
|
|
secretlen = isc_buffer_usedlength(&secretbuf);
|
|
|
|
|
2000-07-03 23:42:48 +00:00
|
|
|
debug("keycreate");
|
2015-01-20 13:29:18 -08:00
|
|
|
result = dns_tsigkey_create(mykeyname, hmacname, secret, secretlen,
|
2020-02-12 13:59:18 +01:00
|
|
|
false, NULL, 0, 0, gmctx, NULL, &tsigkey);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr, "could not create key from %s: %s\n", keystr,
|
2021-10-04 17:14:53 +02:00
|
|
|
isc_result_totext(result));
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2006-01-27 02:35:15 +00:00
|
|
|
dst_key_setbits(tsigkey->key, digestbits);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2020-02-12 13:59:18 +01:00
|
|
|
failure:
|
2020-02-13 21:48:23 +01:00
|
|
|
if (secret != NULL) {
|
2015-01-20 13:29:18 -08:00
|
|
|
isc_mem_free(gmctx, secret);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-07-03 23:42:48 +00:00
|
|
|
}
|
|
|
|
|
2009-06-10 00:27:22 +00:00
|
|
|
/*
|
|
|
|
* Get a key from a named.conf format keyfile
|
|
|
|
*/
|
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
read_sessionkey(isc_mem_t *mctx, isc_log_t *lctx) {
|
|
|
|
cfg_parser_t *pctx = NULL;
|
|
|
|
cfg_obj_t *sessionkey = NULL;
|
2009-06-10 00:27:22 +00:00
|
|
|
const cfg_obj_t *key = NULL;
|
|
|
|
const cfg_obj_t *secretobj = NULL;
|
|
|
|
const cfg_obj_t *algorithmobj = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
const char *mykeyname;
|
|
|
|
const char *secretstr;
|
|
|
|
const char *algorithm;
|
|
|
|
isc_result_t result;
|
|
|
|
int len;
|
2009-06-10 00:27:22 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (!isc_file_exists(keyfile)) {
|
2009-06-10 00:27:22 +00:00
|
|
|
return (ISC_R_FILENOTFOUND);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-06-10 00:27:22 +00:00
|
|
|
|
|
|
|
result = cfg_parser_create(mctx, lctx, &pctx);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2009-06-10 00:27:22 +00:00
|
|
|
goto cleanup;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-06-10 00:27:22 +00:00
|
|
|
|
2009-07-14 22:54:57 +00:00
|
|
|
result = cfg_parse_file(pctx, keyfile, &cfg_type_sessionkey,
|
2009-07-14 23:47:54 +00:00
|
|
|
&sessionkey);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2009-06-10 00:27:22 +00:00
|
|
|
goto cleanup;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-06-10 00:27:22 +00:00
|
|
|
|
2009-07-14 22:54:57 +00:00
|
|
|
result = cfg_map_get(sessionkey, "key", &key);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2009-06-10 00:27:22 +00:00
|
|
|
goto cleanup;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-06-10 00:27:22 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
(void)cfg_map_get(key, "secret", &secretobj);
|
|
|
|
(void)cfg_map_get(key, "algorithm", &algorithmobj);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (secretobj == NULL || algorithmobj == NULL) {
|
2009-06-10 00:27:22 +00:00
|
|
|
fatal("key must have algorithm and secret");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-06-10 00:27:22 +00:00
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
mykeyname = cfg_obj_asstring(cfg_map_getname(key));
|
2009-06-10 00:27:22 +00:00
|
|
|
secretstr = cfg_obj_asstring(secretobj);
|
|
|
|
algorithm = cfg_obj_asstring(algorithmobj);
|
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
len = strlen(algorithm) + strlen(mykeyname) + strlen(secretstr) + 3;
|
2009-06-10 00:27:22 +00:00
|
|
|
keystr = isc_mem_allocate(mctx, len);
|
2015-01-20 13:29:18 -08:00
|
|
|
snprintf(keystr, len, "%s:%s:%s", algorithm, mykeyname, secretstr);
|
2009-06-10 00:27:22 +00:00
|
|
|
setup_keystr();
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
cleanup:
|
2009-06-10 00:27:22 +00:00
|
|
|
if (pctx != NULL) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (sessionkey != NULL) {
|
2009-07-14 22:54:57 +00:00
|
|
|
cfg_obj_destroy(pctx, &sessionkey);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-06-10 00:27:22 +00:00
|
|
|
cfg_parser_destroy(&pctx);
|
|
|
|
}
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (keystr != NULL) {
|
2009-06-10 00:27:22 +00:00
|
|
|
isc_mem_free(mctx, keystr);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-06-10 00:27:22 +00:00
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2001-09-27 17:53:39 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
setup_keyfile(isc_mem_t *mctx, isc_log_t *lctx) {
|
|
|
|
dst_key_t *dstkey = NULL;
|
|
|
|
isc_result_t result;
|
2016-12-30 15:45:08 +11:00
|
|
|
const dns_name_t *hmacname = NULL;
|
2001-09-27 17:53:39 +00:00
|
|
|
|
|
|
|
debug("Creating key...");
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (sig0key != NULL) {
|
2010-12-09 00:54:34 +00:00
|
|
|
dst_key_free(&sig0key);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2010-12-09 00:54:34 +00:00
|
|
|
|
2009-06-10 00:27:22 +00:00
|
|
|
/* Try reading the key from a K* pair */
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dst_key_fromnamedfile(
|
|
|
|
keyfile, NULL, DST_TYPE_PRIVATE | DST_TYPE_KEY, mctx, &dstkey);
|
2009-06-10 00:27:22 +00:00
|
|
|
|
2009-07-14 22:54:57 +00:00
|
|
|
/* If that didn't work, try reading it as a session.key keyfile */
|
2009-06-10 00:27:22 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2009-07-14 22:54:57 +00:00
|
|
|
result = read_sessionkey(mctx, lctx);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result == ISC_R_SUCCESS) {
|
2009-06-10 00:27:22 +00:00
|
|
|
return;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-06-10 00:27:22 +00:00
|
|
|
}
|
|
|
|
|
2001-09-27 17:53:39 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr,
|
|
|
|
"could not read key from %.*s.{private,key}: "
|
|
|
|
"%s\n",
|
|
|
|
basenamelen(keyfile), keyfile,
|
|
|
|
isc_result_totext(result));
|
2001-09-27 17:53:39 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-06-10 00:27:22 +00:00
|
|
|
|
2006-01-27 02:35:15 +00:00
|
|
|
switch (dst_key_alg(dstkey)) {
|
|
|
|
case DST_ALG_HMACMD5:
|
|
|
|
hmacname = DNS_TSIG_HMACMD5_NAME;
|
|
|
|
break;
|
|
|
|
case DST_ALG_HMACSHA1:
|
|
|
|
hmacname = DNS_TSIG_HMACSHA1_NAME;
|
|
|
|
break;
|
|
|
|
case DST_ALG_HMACSHA224:
|
|
|
|
hmacname = DNS_TSIG_HMACSHA224_NAME;
|
|
|
|
break;
|
|
|
|
case DST_ALG_HMACSHA256:
|
|
|
|
hmacname = DNS_TSIG_HMACSHA256_NAME;
|
|
|
|
break;
|
|
|
|
case DST_ALG_HMACSHA384:
|
|
|
|
hmacname = DNS_TSIG_HMACSHA384_NAME;
|
|
|
|
break;
|
|
|
|
case DST_ALG_HMACSHA512:
|
|
|
|
hmacname = DNS_TSIG_HMACSHA512_NAME;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (hmacname != NULL) {
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_tsigkey_createfromkey(
|
|
|
|
dst_key_name(dstkey), hmacname, dstkey, false, NULL, 0,
|
|
|
|
0, mctx, NULL, &tsigkey);
|
2010-12-09 00:54:34 +00:00
|
|
|
dst_key_free(&dstkey);
|
2002-01-21 07:59:15 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fprintf(stderr, "could not create key from %s: %s\n",
|
|
|
|
keyfile, isc_result_totext(result));
|
|
|
|
return;
|
|
|
|
}
|
2011-05-23 22:25:32 +00:00
|
|
|
} else {
|
2010-12-09 00:54:34 +00:00
|
|
|
dst_key_attach(dstkey, &sig0key);
|
2011-05-23 22:25:32 +00:00
|
|
|
dst_key_free(&dstkey);
|
|
|
|
}
|
2001-09-27 17:53:39 +00:00
|
|
|
}
|
|
|
|
|
2000-11-22 02:54:15 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
doshutdown(void) {
|
2000-11-22 02:54:15 +00:00
|
|
|
isc_task_detach(&global_task);
|
2001-01-21 21:54:32 +00:00
|
|
|
|
2014-12-05 18:26:38 +11:00
|
|
|
/*
|
2021-10-05 11:07:44 +02:00
|
|
|
* The isc_mem_put of primary_servers must be before the
|
2014-12-09 07:41:16 +11:00
|
|
|
* isc_mem_put of servers as it sets the servers pointer
|
|
|
|
* to NULL.
|
2014-12-05 18:26:38 +11:00
|
|
|
*/
|
2021-10-05 11:28:24 +02:00
|
|
|
if (primary_servers != NULL && primary_servers != servers) {
|
|
|
|
isc_mem_put(gmctx, primary_servers,
|
|
|
|
primary_alloc * sizeof(isc_sockaddr_t));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-12-05 18:26:38 +11:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (servers != NULL) {
|
2017-07-19 15:35:41 +10:00
|
|
|
isc_mem_put(gmctx, servers, ns_alloc * sizeof(isc_sockaddr_t));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2001-01-21 21:54:32 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (localaddr4 != NULL) {
|
2015-01-20 13:29:18 -08:00
|
|
|
isc_mem_put(gmctx, localaddr4, sizeof(isc_sockaddr_t));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-12-05 18:26:38 +11:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (localaddr6 != NULL) {
|
2015-01-20 13:29:18 -08:00
|
|
|
isc_mem_put(gmctx, localaddr6, sizeof(isc_sockaddr_t));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2001-01-21 21:54:32 +00:00
|
|
|
|
2002-01-21 07:59:15 +00:00
|
|
|
if (tsigkey != NULL) {
|
|
|
|
ddebug("Freeing TSIG key");
|
|
|
|
dns_tsigkey_detach(&tsigkey);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sig0key != NULL) {
|
|
|
|
ddebug("Freeing SIG(0) key");
|
|
|
|
dst_key_free(&sig0key);
|
2001-01-21 21:54:32 +00:00
|
|
|
}
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (updatemsg != NULL) {
|
2020-09-21 16:16:15 -03:00
|
|
|
dns_message_detach(&updatemsg);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2001-01-21 21:54:32 +00:00
|
|
|
|
|
|
|
if (is_dst_up) {
|
2001-07-14 20:17:48 +00:00
|
|
|
ddebug("Destroy DST lib");
|
2001-01-21 21:54:32 +00:00
|
|
|
dst_lib_destroy();
|
2018-04-17 08:29:14 -07:00
|
|
|
is_dst_up = false;
|
2001-01-21 21:54:32 +00:00
|
|
|
}
|
|
|
|
|
2001-04-13 01:32:14 +00:00
|
|
|
ddebug("Destroying request manager");
|
2001-01-21 21:54:32 +00:00
|
|
|
dns_requestmgr_detach(&requestmgr);
|
|
|
|
|
|
|
|
ddebug("Freeing the dispatchers");
|
2020-02-13 21:48:23 +01:00
|
|
|
if (have_ipv4) {
|
2001-01-21 21:54:32 +00:00
|
|
|
dns_dispatch_detach(&dispatchv4);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (have_ipv6) {
|
2001-01-21 21:54:32 +00:00
|
|
|
dns_dispatch_detach(&dispatchv6);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2001-01-21 21:54:32 +00:00
|
|
|
|
|
|
|
ddebug("Shutting down dispatch manager");
|
2021-05-25 22:54:17 -07:00
|
|
|
dns_dispatchmgr_detach(&dispatchmgr);
|
2000-11-22 02:54:15 +00:00
|
|
|
}
|
|
|
|
|
2001-04-13 01:32:14 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
maybeshutdown(void) {
|
2020-03-27 21:03:40 +01:00
|
|
|
/* when called from getinput, doshutdown might be already finished */
|
2021-08-03 15:27:06 +02:00
|
|
|
if (requestmgr == NULL) {
|
2020-03-27 21:03:40 +01:00
|
|
|
return;
|
2021-08-03 15:27:06 +02:00
|
|
|
}
|
2020-03-27 21:03:40 +01:00
|
|
|
|
2001-04-13 01:32:14 +00:00
|
|
|
ddebug("Shutting down request manager");
|
|
|
|
dns_requestmgr_shutdown(requestmgr);
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (requests != 0) {
|
2001-04-13 01:32:14 +00:00
|
|
|
return;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2001-04-13 01:32:14 +00:00
|
|
|
|
|
|
|
doshutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
shutdown_program(isc_task_t *task, isc_event_t *event) {
|
2001-04-13 01:32:14 +00:00
|
|
|
REQUIRE(task == global_task);
|
|
|
|
UNUSED(task);
|
|
|
|
|
|
|
|
ddebug("shutdown_program()");
|
|
|
|
isc_event_free(&event);
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
shuttingdown = true;
|
2001-04-13 01:32:14 +00:00
|
|
|
maybeshutdown();
|
|
|
|
}
|
|
|
|
|
2019-03-06 14:01:24 +01:00
|
|
|
/*
|
|
|
|
* Try honoring the operating system's preferred ephemeral port range.
|
|
|
|
*/
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
set_source_ports(dns_dispatchmgr_t *manager) {
|
2019-03-06 14:01:24 +01:00
|
|
|
isc_portset_t *v4portset = NULL, *v6portset = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
in_port_t udpport_low, udpport_high;
|
|
|
|
isc_result_t result;
|
2019-03-06 14:01:24 +01:00
|
|
|
|
|
|
|
result = isc_portset_create(gmctx, &v4portset);
|
|
|
|
check_result(result, "isc_portset_create (v4)");
|
|
|
|
result = isc_net_getudpportrange(AF_INET, &udpport_low, &udpport_high);
|
|
|
|
check_result(result, "isc_net_getudpportrange (v4)");
|
|
|
|
isc_portset_addrange(v4portset, udpport_low, udpport_high);
|
|
|
|
|
|
|
|
result = isc_portset_create(gmctx, &v6portset);
|
|
|
|
check_result(result, "isc_portset_create (v6)");
|
|
|
|
result = isc_net_getudpportrange(AF_INET6, &udpport_low, &udpport_high);
|
|
|
|
check_result(result, "isc_net_getudpportrange (v6)");
|
|
|
|
isc_portset_addrange(v6portset, udpport_low, udpport_high);
|
|
|
|
|
|
|
|
result = dns_dispatchmgr_setavailports(manager, v4portset, v6portset);
|
|
|
|
check_result(result, "dns_dispatchmgr_setavailports");
|
|
|
|
|
|
|
|
isc_portset_destroy(gmctx, &v4portset);
|
|
|
|
isc_portset_destroy(gmctx, &v6portset);
|
|
|
|
}
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
setup_system(void) {
|
|
|
|
isc_result_t result;
|
|
|
|
isc_sockaddr_t bind_any, bind_any6;
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_sockaddrlist_t *nslist;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_logconfig_t *logconfig = NULL;
|
|
|
|
irs_resconf_t *resconf = NULL;
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-06-16 17:10:02 +00:00
|
|
|
ddebug("setup_system()");
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2020-03-18 14:17:55 +11:00
|
|
|
isc_log_create(gmctx, &glctx, &logconfig);
|
2015-01-20 13:29:18 -08:00
|
|
|
isc_log_setcontext(glctx);
|
|
|
|
dns_log_init(glctx);
|
|
|
|
dns_log_setcontext(glctx);
|
2006-12-04 01:54:53 +00:00
|
|
|
|
|
|
|
result = isc_log_usechannel(logconfig, "default_debug", NULL, NULL);
|
|
|
|
check_result(result, "isc_log_usechannel");
|
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
isc_log_setdebuglevel(glctx, logdebuglevel);
|
2006-12-04 01:54:53 +00:00
|
|
|
|
2021-06-09 14:19:46 -07:00
|
|
|
result = irs_resconf_load(gmctx, resolvconf, &resconf);
|
2017-09-08 13:39:09 -07:00
|
|
|
if (result != ISC_R_SUCCESS && result != ISC_R_FILENOTFOUND) {
|
2021-06-09 14:19:46 -07:00
|
|
|
fatal("parse of %s failed", resolvconf);
|
2017-08-16 16:01:39 +02:00
|
|
|
}
|
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
nslist = irs_resconf_getnameservers(resconf);
|
2000-06-30 01:56:14 +00:00
|
|
|
|
2014-12-05 18:26:38 +11:00
|
|
|
if (servers != NULL) {
|
2021-10-05 11:28:24 +02:00
|
|
|
if (primary_servers == servers) {
|
|
|
|
primary_servers = NULL;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2017-07-19 15:35:41 +10:00
|
|
|
isc_mem_put(gmctx, servers, ns_alloc * sizeof(isc_sockaddr_t));
|
2014-12-05 18:26:38 +11:00
|
|
|
}
|
|
|
|
|
2014-02-11 21:29:10 -08:00
|
|
|
ns_inuse = 0;
|
2017-09-08 13:39:09 -07:00
|
|
|
if (local_only || ISC_LIST_EMPTY(*nslist)) {
|
2020-02-13 14:44:37 -08:00
|
|
|
struct in_addr in;
|
2014-02-11 21:29:10 -08:00
|
|
|
struct in6_addr in6;
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (local_only && keyfile == NULL) {
|
2014-02-11 21:29:10 -08:00
|
|
|
keyfile = SESSION_KEYFILE;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-11 21:29:10 -08:00
|
|
|
|
2014-12-05 18:26:38 +11:00
|
|
|
default_servers = !local_only;
|
2014-02-11 21:29:10 -08:00
|
|
|
|
2017-07-19 15:35:41 +10:00
|
|
|
ns_total = ns_alloc = (have_ipv4 ? 1 : 0) + (have_ipv6 ? 1 : 0);
|
2020-02-12 13:59:18 +01:00
|
|
|
servers = isc_mem_get(gmctx, ns_alloc * sizeof(isc_sockaddr_t));
|
2014-02-11 21:29:10 -08:00
|
|
|
|
|
|
|
if (have_ipv6) {
|
|
|
|
memset(&in6, 0, sizeof(in6));
|
|
|
|
in6.s6_addr[15] = 1;
|
2017-08-16 16:01:39 +02:00
|
|
|
isc_sockaddr_fromin6(&servers[0], &in6, dnsport);
|
|
|
|
}
|
|
|
|
if (have_ipv4) {
|
|
|
|
in.s_addr = htonl(INADDR_LOOPBACK);
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_sockaddr_fromin(&servers[(have_ipv6 ? 1 : 0)], &in,
|
|
|
|
dnsport);
|
2014-02-11 21:29:10 -08:00
|
|
|
}
|
2001-10-04 23:29:41 +00:00
|
|
|
} else {
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_sockaddr_t *sa;
|
2020-02-13 14:44:37 -08:00
|
|
|
int i;
|
2017-09-08 13:39:09 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Count the nameservers (skipping any that we can't use
|
|
|
|
* because of address family restrictions) and allocate
|
|
|
|
* the servers array.
|
|
|
|
*/
|
2017-09-26 03:02:09 +05:30
|
|
|
ns_total = 0;
|
2020-02-12 13:59:18 +01:00
|
|
|
for (sa = ISC_LIST_HEAD(*nslist); sa != NULL;
|
|
|
|
sa = ISC_LIST_NEXT(sa, link)) {
|
2017-09-08 13:39:09 -07:00
|
|
|
switch (sa->type.sa.sa_family) {
|
|
|
|
case AF_INET:
|
|
|
|
if (have_ipv4) {
|
|
|
|
ns_total++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AF_INET6:
|
|
|
|
if (have_ipv6) {
|
|
|
|
ns_total++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fatal("bad family");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ns_alloc = ns_total;
|
2020-02-12 13:59:18 +01:00
|
|
|
servers = isc_mem_get(gmctx, ns_alloc * sizeof(isc_sockaddr_t));
|
2017-09-08 13:39:09 -07:00
|
|
|
|
2017-09-26 03:02:09 +05:30
|
|
|
i = 0;
|
2020-02-12 13:59:18 +01:00
|
|
|
for (sa = ISC_LIST_HEAD(*nslist); sa != NULL;
|
|
|
|
sa = ISC_LIST_NEXT(sa, link)) {
|
2017-09-08 13:39:09 -07:00
|
|
|
switch (sa->type.sa.sa_family) {
|
|
|
|
case AF_INET:
|
2017-09-26 03:02:09 +05:30
|
|
|
if (have_ipv4) {
|
|
|
|
sa->type.sin.sin_port = htons(dnsport);
|
2017-10-26 16:00:24 +11:00
|
|
|
} else {
|
|
|
|
continue;
|
2017-09-08 13:39:09 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AF_INET6:
|
2017-09-26 03:02:09 +05:30
|
|
|
if (have_ipv6) {
|
2020-02-12 13:59:18 +01:00
|
|
|
sa->type.sin6.sin6_port =
|
|
|
|
htons(dnsport);
|
2017-10-26 16:00:24 +11:00
|
|
|
} else {
|
|
|
|
continue;
|
2017-09-08 13:39:09 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fatal("bad family");
|
2001-10-04 23:29:41 +00:00
|
|
|
}
|
2017-10-26 16:00:24 +11:00
|
|
|
INSIST(i < ns_alloc);
|
2017-09-08 13:39:09 -07:00
|
|
|
servers[i++] = *sa;
|
2000-07-05 23:24:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
irs_resconf_destroy(&resconf);
|
|
|
|
|
2021-01-14 13:02:57 -08:00
|
|
|
result = isc_managers_create(gmctx, 1, 0, 0, &netmgr, &taskmgr, NULL,
|
|
|
|
NULL);
|
|
|
|
check_result(result, "isc_managers_create");
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2021-01-14 13:02:57 -08:00
|
|
|
result = dns_dispatchmgr_create(gmctx, netmgr, &dispatchmgr);
|
|
|
|
check_result(result, "dns_dispatchmgr_create");
|
2000-06-27 21:59:44 +00:00
|
|
|
|
2000-07-05 23:24:18 +00:00
|
|
|
result = isc_task_create(taskmgr, 0, &global_task);
|
2000-06-27 21:59:44 +00:00
|
|
|
check_result(result, "isc_task_create");
|
|
|
|
|
2000-11-22 02:54:15 +00:00
|
|
|
result = isc_task_onshutdown(global_task, shutdown_program, NULL);
|
|
|
|
check_result(result, "isc_task_onshutdown");
|
|
|
|
|
2018-04-22 14:56:28 +02:00
|
|
|
result = dst_lib_init(gmctx, NULL);
|
2000-06-23 20:46:25 +00:00
|
|
|
check_result(result, "dst_lib_init");
|
2018-04-17 08:29:14 -07:00
|
|
|
is_dst_up = true;
|
2000-06-23 20:46:25 +00:00
|
|
|
|
2019-03-06 14:01:24 +01:00
|
|
|
set_source_ports(dispatchmgr);
|
|
|
|
|
2000-08-09 18:44:13 +00:00
|
|
|
if (have_ipv6) {
|
|
|
|
isc_sockaddr_any6(&bind_any6);
|
2021-08-03 18:24:27 -07:00
|
|
|
result = dns_dispatch_createudp(dispatchmgr, &bind_any6,
|
2021-07-26 20:23:18 -07:00
|
|
|
&dispatchv6);
|
2020-12-16 01:32:06 -08:00
|
|
|
check_result(result, "dns_dispatch_createudp (v6)");
|
2000-08-09 18:44:13 +00:00
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-11-22 21:25:38 +00:00
|
|
|
if (have_ipv4) {
|
|
|
|
isc_sockaddr_any(&bind_any);
|
2021-08-03 18:24:27 -07:00
|
|
|
result = dns_dispatch_createudp(dispatchmgr, &bind_any,
|
2021-07-26 20:23:18 -07:00
|
|
|
&dispatchv4);
|
2020-12-16 01:32:06 -08:00
|
|
|
check_result(result, "dns_dispatch_createudp (v4)");
|
2000-11-22 21:25:38 +00:00
|
|
|
}
|
2000-06-16 17:10:02 +00:00
|
|
|
|
2021-01-14 13:02:57 -08:00
|
|
|
result = dns_requestmgr_create(gmctx, taskmgr, dispatchmgr, dispatchv4,
|
|
|
|
dispatchv6, &requestmgr);
|
2000-06-10 00:50:36 +00:00
|
|
|
check_result(result, "dns_requestmgr_create");
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (keystr != NULL) {
|
2001-09-27 17:53:39 +00:00
|
|
|
setup_keystr();
|
2020-02-13 21:48:23 +01:00
|
|
|
} else if (local_only) {
|
2015-01-20 13:29:18 -08:00
|
|
|
result = read_sessionkey(gmctx, glctx);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fatal("can't read key from %s: %s\n", keyfile,
|
|
|
|
isc_result_totext(result));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
} else if (keyfile != NULL) {
|
2015-01-20 13:29:18 -08:00
|
|
|
setup_keyfile(gmctx, glctx);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2020-05-19 13:25:41 +10:00
|
|
|
|
|
|
|
isc_mutex_init(&answer_lock);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
2000-06-23 20:46:25 +00:00
|
|
|
|
2017-07-19 15:35:41 +10:00
|
|
|
static int
|
2020-02-13 14:44:37 -08:00
|
|
|
get_addresses(char *host, in_port_t port, isc_sockaddr_t *sockaddr,
|
|
|
|
int naddrs) {
|
|
|
|
int count = 0;
|
2001-11-14 22:08:38 +00:00
|
|
|
isc_result_t result;
|
2001-02-24 21:02:38 +00:00
|
|
|
|
2001-11-14 22:08:38 +00:00
|
|
|
isc_app_block();
|
2014-02-11 21:29:10 -08:00
|
|
|
result = bind9_getaddresses(host, port, sockaddr, naddrs, &count);
|
2001-11-14 22:08:38 +00:00
|
|
|
isc_app_unblock();
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2020-02-12 13:59:18 +01:00
|
|
|
error("couldn't get address for '%s': %s", host,
|
|
|
|
isc_result_totext(result));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2017-07-19 15:35:41 +10:00
|
|
|
return (count);
|
2000-07-05 23:24:18 +00:00
|
|
|
}
|
|
|
|
|
2014-06-13 06:27:43 +05:30
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
version(void) {
|
2018-08-07 16:46:53 +02:00
|
|
|
fprintf(stderr, "nsupdate %s\n", PACKAGE_VERSION);
|
2014-06-13 06:27:43 +05:30
|
|
|
}
|
|
|
|
|
2021-06-09 14:19:46 -07:00
|
|
|
#define PARSE_ARGS_FMT "46C:dDghilL:Mok:p:Pr:R:t:Tu:vVy:"
|
2007-09-15 14:46:03 +00:00
|
|
|
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
pre_parse_args(int argc, char **argv) {
|
2012-03-05 11:38:07 +11:00
|
|
|
dns_rdatatype_t t;
|
2020-02-13 14:44:37 -08:00
|
|
|
int ch;
|
|
|
|
char buf[100];
|
|
|
|
bool doexit = false;
|
|
|
|
bool ipv4only = false, ipv6only = false;
|
2007-09-15 14:46:03 +00:00
|
|
|
|
|
|
|
while ((ch = isc_commandline_parse(argc, argv, PARSE_ARGS_FMT)) != -1) {
|
|
|
|
switch (ch) {
|
|
|
|
case 'M': /* was -dm */
|
2018-04-17 08:29:14 -07:00
|
|
|
debugging = true;
|
|
|
|
ddebugging = true;
|
|
|
|
memdebugging = true;
|
2007-09-15 14:46:03 +00:00
|
|
|
isc_mem_debugging = ISC_MEM_DEBUGTRACE |
|
|
|
|
ISC_MEM_DEBUGRECORD;
|
|
|
|
break;
|
|
|
|
|
2017-08-16 16:01:39 +02:00
|
|
|
case '4':
|
|
|
|
if (ipv6only) {
|
|
|
|
fatal("only one of -4 and -6 allowed");
|
|
|
|
}
|
2018-04-17 08:29:14 -07:00
|
|
|
ipv4only = true;
|
2017-08-16 16:01:39 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '6':
|
|
|
|
if (ipv4only) {
|
|
|
|
fatal("only one of -4 and -6 allowed");
|
|
|
|
}
|
2018-04-17 08:29:14 -07:00
|
|
|
ipv6only = true;
|
2017-08-16 16:01:39 +02:00
|
|
|
break;
|
|
|
|
|
2007-09-15 14:46:03 +00:00
|
|
|
case '?':
|
2009-06-10 00:27:22 +00:00
|
|
|
case 'h':
|
2020-02-13 21:48:23 +01:00
|
|
|
if (isc_commandline_option != '?') {
|
2007-09-15 14:46:03 +00:00
|
|
|
fprintf(stderr, "%s: invalid argument -%c\n",
|
|
|
|
argv[0], isc_commandline_option);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2021-06-09 14:19:46 -07:00
|
|
|
fprintf(stderr, "usage: nsupdate [-CdDi] [-L level] "
|
|
|
|
"[-l] [-g | -o | -y keyname:secret "
|
|
|
|
"| -k keyfile] [-p port] "
|
2020-02-12 13:59:18 +01:00
|
|
|
"[-v] [-V] [-P] [-T] [-4 | -6] "
|
|
|
|
"[filename]\n");
|
2007-09-15 14:46:03 +00:00
|
|
|
exit(1);
|
|
|
|
|
2012-03-05 11:38:07 +11:00
|
|
|
case 'P':
|
|
|
|
for (t = 0xff00; t <= 0xfffe; t++) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (dns_rdatatype_ismeta(t)) {
|
2012-03-05 11:38:07 +11:00
|
|
|
continue;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2012-03-05 11:38:07 +11:00
|
|
|
dns_rdatatype_format(t, buf, sizeof(buf));
|
2020-02-13 21:48:23 +01:00
|
|
|
if (strncmp(buf, "TYPE", 4) != 0) {
|
2012-03-05 11:38:07 +11:00
|
|
|
fprintf(stdout, "%s\n", buf);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2012-03-05 11:38:07 +11:00
|
|
|
}
|
2018-04-17 08:29:14 -07:00
|
|
|
doexit = true;
|
2012-03-05 11:38:07 +11:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'T':
|
|
|
|
for (t = 1; t <= 0xfeff; t++) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (dns_rdatatype_ismeta(t)) {
|
2012-03-05 11:38:07 +11:00
|
|
|
continue;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2012-03-05 11:38:07 +11:00
|
|
|
dns_rdatatype_format(t, buf, sizeof(buf));
|
2020-02-13 21:48:23 +01:00
|
|
|
if (strncmp(buf, "TYPE", 4) != 0) {
|
2012-03-05 11:38:07 +11:00
|
|
|
fprintf(stdout, "%s\n", buf);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2012-03-05 11:38:07 +11:00
|
|
|
}
|
2018-04-17 08:29:14 -07:00
|
|
|
doexit = true;
|
2012-03-05 11:38:07 +11:00
|
|
|
break;
|
|
|
|
|
2014-06-13 06:27:43 +05:30
|
|
|
case 'V':
|
|
|
|
version();
|
2018-04-17 08:29:14 -07:00
|
|
|
doexit = true;
|
2014-06-13 06:27:43 +05:30
|
|
|
break;
|
|
|
|
|
2007-09-15 14:46:03 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
if (doexit) {
|
2012-03-10 23:45:53 +00:00
|
|
|
exit(0);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2018-04-17 08:29:14 -07:00
|
|
|
isc_commandline_reset = true;
|
2007-09-15 14:46:03 +00:00
|
|
|
isc_commandline_index = 1;
|
|
|
|
}
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
parse_args(int argc, char **argv) {
|
|
|
|
int ch;
|
|
|
|
uint32_t i;
|
2000-11-27 00:43:33 +00:00
|
|
|
isc_result_t result;
|
2020-02-13 14:44:37 -08:00
|
|
|
bool force_interactive = false;
|
2000-06-20 22:50:13 +00:00
|
|
|
|
2000-06-23 20:46:25 +00:00
|
|
|
debug("parse_args");
|
2007-09-15 14:46:03 +00:00
|
|
|
while ((ch = isc_commandline_parse(argc, argv, PARSE_ARGS_FMT)) != -1) {
|
2000-06-30 01:56:14 +00:00
|
|
|
switch (ch) {
|
2017-08-16 16:01:39 +02:00
|
|
|
case '4':
|
|
|
|
if (have_ipv4) {
|
|
|
|
isc_net_disableipv6();
|
2018-04-17 08:29:14 -07:00
|
|
|
have_ipv6 = false;
|
2017-08-16 16:01:39 +02:00
|
|
|
} else {
|
|
|
|
fatal("can't find IPv4 networking");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '6':
|
|
|
|
if (have_ipv6) {
|
|
|
|
isc_net_disableipv4();
|
2018-04-17 08:29:14 -07:00
|
|
|
have_ipv4 = false;
|
2017-08-16 16:01:39 +02:00
|
|
|
} else {
|
|
|
|
fatal("can't find IPv6 networking");
|
|
|
|
}
|
|
|
|
break;
|
2021-06-09 14:19:46 -07:00
|
|
|
case 'C':
|
|
|
|
resolvconf = isc_commandline_argument;
|
|
|
|
break;
|
2000-06-30 01:56:14 +00:00
|
|
|
case 'd':
|
2018-04-17 08:29:14 -07:00
|
|
|
debugging = true;
|
2000-06-30 01:56:14 +00:00
|
|
|
break;
|
|
|
|
case 'D': /* was -dd */
|
2018-04-17 08:29:14 -07:00
|
|
|
debugging = true;
|
|
|
|
ddebugging = true;
|
2000-06-30 01:56:14 +00:00
|
|
|
break;
|
2007-09-15 14:46:03 +00:00
|
|
|
case 'M':
|
2000-06-30 01:56:14 +00:00
|
|
|
break;
|
2017-06-12 11:16:18 +02:00
|
|
|
case 'i':
|
2018-04-17 08:29:14 -07:00
|
|
|
force_interactive = true;
|
|
|
|
interactive = true;
|
2017-06-12 11:16:18 +02:00
|
|
|
break;
|
2006-12-04 01:54:53 +00:00
|
|
|
case 'l':
|
2018-04-17 08:29:14 -07:00
|
|
|
local_only = true;
|
2009-06-10 00:27:22 +00:00
|
|
|
break;
|
|
|
|
case 'L':
|
2006-12-04 01:54:53 +00:00
|
|
|
result = isc_parse_uint32(&i, isc_commandline_argument,
|
|
|
|
10);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr,
|
|
|
|
"bad library debug value "
|
|
|
|
"'%s'\n",
|
|
|
|
isc_commandline_argument);
|
2006-12-04 01:54:53 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
logdebuglevel = i;
|
|
|
|
break;
|
2000-06-30 01:56:14 +00:00
|
|
|
case 'y':
|
|
|
|
keystr = isc_commandline_argument;
|
|
|
|
break;
|
|
|
|
case 'v':
|
2018-04-17 08:29:14 -07:00
|
|
|
usevc = true;
|
2000-06-30 01:56:14 +00:00
|
|
|
break;
|
|
|
|
case 'k':
|
2000-07-03 23:42:48 +00:00
|
|
|
keyfile = isc_commandline_argument;
|
2000-06-30 01:56:14 +00:00
|
|
|
break;
|
2006-12-04 01:54:53 +00:00
|
|
|
case 'g':
|
2018-04-17 08:29:14 -07:00
|
|
|
usegsstsig = true;
|
|
|
|
use_win2k_gsstsig = false;
|
2006-12-04 01:54:53 +00:00
|
|
|
break;
|
|
|
|
case 'o':
|
2018-04-17 08:29:14 -07:00
|
|
|
usegsstsig = true;
|
|
|
|
use_win2k_gsstsig = true;
|
2006-12-04 01:54:53 +00:00
|
|
|
break;
|
2009-06-10 00:27:22 +00:00
|
|
|
case 'p':
|
|
|
|
result = isc_parse_uint16(&dnsport,
|
|
|
|
isc_commandline_argument, 10);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr,
|
|
|
|
"bad port number "
|
|
|
|
"'%s'\n",
|
|
|
|
isc_commandline_argument);
|
2009-06-10 00:27:22 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
2002-11-12 23:58:14 +00:00
|
|
|
case 't':
|
|
|
|
result = isc_parse_uint32(&timeout,
|
|
|
|
isc_commandline_argument, 10);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr, "bad timeout '%s'\n",
|
|
|
|
isc_commandline_argument);
|
2002-11-12 23:58:14 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
if (timeout == 0) {
|
2004-09-16 01:01:27 +00:00
|
|
|
timeout = UINT_MAX;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2002-11-12 23:58:14 +00:00
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
result = isc_parse_uint32(&udp_timeout,
|
|
|
|
isc_commandline_argument, 10);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr, "bad udp timeout '%s'\n",
|
|
|
|
isc_commandline_argument);
|
2002-11-12 23:58:14 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
if (udp_timeout == 0) {
|
2004-09-16 01:01:27 +00:00
|
|
|
udp_timeout = UINT_MAX;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2002-11-12 23:58:14 +00:00
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
result = isc_parse_uint32(&udp_retries,
|
|
|
|
isc_commandline_argument, 10);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr, "bad udp retries '%s'\n",
|
|
|
|
isc_commandline_argument);
|
2002-11-12 23:58:14 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
2007-09-15 14:46:03 +00:00
|
|
|
|
|
|
|
case 'R':
|
2021-06-09 14:19:46 -07:00
|
|
|
fatal("The -R option has been deprecated.");
|
2007-09-15 14:46:03 +00:00
|
|
|
break;
|
2007-05-21 02:47:25 +00:00
|
|
|
|
|
|
|
default:
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr, "%s: unhandled option: %c\n", argv[0],
|
|
|
|
isc_commandline_option);
|
2007-05-21 02:47:25 +00:00
|
|
|
exit(1);
|
2000-06-30 01:56:14 +00:00
|
|
|
}
|
2000-06-20 22:50:13 +00:00
|
|
|
}
|
2000-07-03 23:42:48 +00:00
|
|
|
if (keyfile != NULL && keystr != NULL) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr, "%s: cannot specify both -k and -y\n", argv[0]);
|
2000-07-03 23:42:48 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2000-11-27 00:43:33 +00:00
|
|
|
|
2018-08-07 16:46:53 +02:00
|
|
|
#if HAVE_GSSAPI
|
2006-12-04 01:54:53 +00:00
|
|
|
if (usegsstsig && (keyfile != NULL || keystr != NULL)) {
|
|
|
|
fprintf(stderr, "%s: cannot specify -g with -k or -y\n",
|
|
|
|
argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
2018-08-07 16:46:53 +02:00
|
|
|
#else /* HAVE_GSSAPI */
|
2006-12-04 01:54:53 +00:00
|
|
|
if (usegsstsig) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr,
|
|
|
|
"%s: cannot specify -g or -o, "
|
2006-12-04 01:54:53 +00:00
|
|
|
"program not linked with GSS API Library\n",
|
|
|
|
argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
2018-08-07 16:46:53 +02:00
|
|
|
#endif /* HAVE_GSSAPI */
|
2006-12-04 01:54:53 +00:00
|
|
|
|
2000-11-27 00:43:33 +00:00
|
|
|
if (argv[isc_commandline_index] != NULL) {
|
2000-12-01 20:47:15 +00:00
|
|
|
if (strcmp(argv[isc_commandline_index], "-") == 0) {
|
|
|
|
input = stdin;
|
|
|
|
} else {
|
|
|
|
result = isc_stdio_open(argv[isc_commandline_index],
|
|
|
|
"r", &input);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2001-04-16 17:09:00 +00:00
|
|
|
fprintf(stderr, "could not open '%s': %s\n",
|
2000-12-01 20:47:15 +00:00
|
|
|
argv[isc_commandline_index],
|
|
|
|
isc_result_totext(result));
|
|
|
|
exit(1);
|
|
|
|
}
|
2000-11-27 00:43:33 +00:00
|
|
|
}
|
2017-06-12 11:16:18 +02:00
|
|
|
if (!force_interactive) {
|
2018-04-17 08:29:14 -07:00
|
|
|
interactive = false;
|
2017-06-12 11:16:18 +02:00
|
|
|
}
|
2000-11-27 00:43:33 +00:00
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
static uint16_t
|
2020-02-13 14:44:37 -08:00
|
|
|
parse_name(char **cmdlinep, dns_message_t *msg, dns_name_t **namep) {
|
|
|
|
isc_result_t result;
|
|
|
|
char *word;
|
|
|
|
isc_buffer_t source;
|
2000-06-20 22:50:13 +00:00
|
|
|
|
2000-06-30 21:47:35 +00:00
|
|
|
word = nsu_strsep(cmdlinep, " \t\r\n");
|
2012-08-22 13:38:51 +10:00
|
|
|
if (word == NULL || *word == 0) {
|
2001-04-16 17:09:00 +00:00
|
|
|
fprintf(stderr, "could not read owner name\n");
|
2000-06-30 01:56:14 +00:00
|
|
|
return (STATUS_SYNTAX);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
2000-06-30 21:47:35 +00:00
|
|
|
result = dns_message_gettempname(msg, namep);
|
2000-06-10 00:50:36 +00:00
|
|
|
check_result(result, "dns_message_gettempname");
|
2000-06-30 03:24:27 +00:00
|
|
|
isc_buffer_init(&source, word, strlen(word));
|
|
|
|
isc_buffer_add(&source, strlen(word));
|
2009-09-01 00:22:28 +00:00
|
|
|
result = dns_name_fromtext(*namep, &source, dns_rootname, 0, NULL);
|
2017-06-12 11:16:18 +02:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
error("invalid owner name: %s", isc_result_totext(result));
|
|
|
|
isc_buffer_invalidate(&source);
|
|
|
|
dns_message_puttempname(msg, namep);
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
2000-06-30 21:47:35 +00:00
|
|
|
isc_buffer_invalidate(&source);
|
|
|
|
return (STATUS_MORE);
|
|
|
|
}
|
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
static uint16_t
|
2000-06-30 21:47:35 +00:00
|
|
|
parse_rdata(char **cmdlinep, dns_rdataclass_t rdataclass,
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_rdatatype_t rdatatype, dns_message_t *msg, dns_rdata_t *rdata) {
|
|
|
|
char *cmdline = *cmdlinep;
|
|
|
|
isc_buffer_t source, *buf = NULL, *newbuf = NULL;
|
|
|
|
isc_region_t r;
|
|
|
|
isc_lex_t *lex = NULL;
|
2000-06-30 21:47:35 +00:00
|
|
|
dns_rdatacallbacks_t callbacks;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_result_t result;
|
2000-06-30 21:47:35 +00:00
|
|
|
|
2011-12-16 23:01:17 +00:00
|
|
|
if (cmdline == NULL) {
|
|
|
|
rdata->flags = DNS_RDATA_UPDATE;
|
|
|
|
return (STATUS_MORE);
|
|
|
|
}
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
while (*cmdline != 0 && isspace((unsigned char)*cmdline)) {
|
2000-06-30 21:47:35 +00:00
|
|
|
cmdline++;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-06-30 21:47:35 +00:00
|
|
|
|
|
|
|
if (*cmdline != 0) {
|
2000-09-28 21:39:26 +00:00
|
|
|
dns_rdatacallbacks_init(&callbacks);
|
2015-01-20 13:29:18 -08:00
|
|
|
result = isc_lex_create(gmctx, strlen(cmdline), &lex);
|
2002-08-06 03:21:59 +00:00
|
|
|
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");
|
2020-02-02 08:35:46 +01:00
|
|
|
isc_buffer_allocate(gmctx, &buf, MAXWIRE);
|
2008-04-01 01:37:25 +00:00
|
|
|
result = dns_rdata_fromtext(NULL, rdataclass, rdatatype, lex,
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_rootname, 0, gmctx, buf,
|
2002-08-06 03:21:59 +00:00
|
|
|
&callbacks);
|
|
|
|
isc_lex_destroy(&lex);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
isc_buffer_usedregion(buf, &r);
|
2020-02-02 08:35:46 +01:00
|
|
|
isc_buffer_allocate(gmctx, &newbuf, r.length);
|
2002-08-06 03:21:59 +00:00
|
|
|
isc_buffer_putmem(newbuf, r.base, r.length);
|
|
|
|
isc_buffer_usedregion(newbuf, &r);
|
|
|
|
dns_rdata_fromregion(rdata, rdataclass, rdatatype, &r);
|
|
|
|
isc_buffer_free(&buf);
|
|
|
|
dns_message_takebuffer(msg, &newbuf);
|
|
|
|
} else {
|
2001-03-29 23:51:36 +00:00
|
|
|
fprintf(stderr, "invalid rdata format: %s\n",
|
|
|
|
isc_result_totext(result));
|
2002-08-06 03:21:59 +00:00
|
|
|
isc_buffer_free(&buf);
|
2001-03-29 23:51:36 +00:00
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
2000-10-25 04:26:57 +00:00
|
|
|
} else {
|
|
|
|
rdata->flags = DNS_RDATA_UPDATE;
|
2000-06-30 21:47:35 +00:00
|
|
|
}
|
|
|
|
*cmdlinep = cmdline;
|
|
|
|
return (STATUS_MORE);
|
|
|
|
}
|
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
static uint16_t
|
2020-02-13 14:44:37 -08:00
|
|
|
make_prereq(char *cmdline, bool ispositive, bool isrrset) {
|
|
|
|
isc_result_t result;
|
|
|
|
char *word;
|
|
|
|
dns_name_t *name = NULL;
|
2000-06-30 21:47:35 +00:00
|
|
|
isc_textregion_t region;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_rdataset_t *rdataset = NULL;
|
2000-06-30 21:47:35 +00:00
|
|
|
dns_rdatalist_t *rdatalist = NULL;
|
|
|
|
dns_rdataclass_t rdataclass;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_rdatatype_t rdatatype;
|
|
|
|
dns_rdata_t *rdata = NULL;
|
|
|
|
uint16_t retval;
|
2000-06-30 21:47:35 +00:00
|
|
|
|
2000-07-05 23:24:18 +00:00
|
|
|
ddebug("make_prereq()");
|
2000-06-30 21:47:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the owner name
|
|
|
|
*/
|
|
|
|
retval = parse_name(&cmdline, updatemsg, &name);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (retval != STATUS_MORE) {
|
2000-06-30 21:47:35 +00:00
|
|
|
return (retval);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-06-30 21:47:35 +00:00
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
/*
|
|
|
|
* If this is an rrset prereq, read the class or type.
|
|
|
|
*/
|
|
|
|
if (isrrset) {
|
2000-06-30 03:24:27 +00:00
|
|
|
word = nsu_strsep(&cmdline, " \t\r\n");
|
2012-08-22 13:38:51 +10:00
|
|
|
if (word == NULL || *word == 0) {
|
2001-04-16 17:09:00 +00:00
|
|
|
fprintf(stderr, "could not read class or type\n");
|
2001-03-29 23:51:36 +00:00
|
|
|
goto failure;
|
2000-06-30 01:56:14 +00:00
|
|
|
}
|
2000-06-30 03:24:27 +00:00
|
|
|
region.base = word;
|
|
|
|
region.length = strlen(word);
|
2000-06-30 01:56:14 +00:00
|
|
|
result = dns_rdataclass_fromtext(&rdataclass, ®ion);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
2004-03-03 23:43:09 +00:00
|
|
|
if (!setzoneclass(rdataclass)) {
|
|
|
|
fprintf(stderr, "class mismatch: %s\n", word);
|
|
|
|
goto failure;
|
|
|
|
}
|
2000-06-30 01:56:14 +00:00
|
|
|
/*
|
|
|
|
* Now read the type.
|
|
|
|
*/
|
2000-06-30 03:24:27 +00:00
|
|
|
word = nsu_strsep(&cmdline, " \t\r\n");
|
2012-08-22 13:38:51 +10:00
|
|
|
if (word == NULL || *word == 0) {
|
2001-04-16 17:09:00 +00:00
|
|
|
fprintf(stderr, "could not read type\n");
|
2001-03-29 23:51:36 +00:00
|
|
|
goto failure;
|
2000-06-30 01:56:14 +00:00
|
|
|
}
|
2000-06-30 03:24:27 +00:00
|
|
|
region.base = word;
|
|
|
|
region.length = strlen(word);
|
2000-06-30 01:56:14 +00:00
|
|
|
result = dns_rdatatype_fromtext(&rdatatype, ®ion);
|
2001-03-29 23:51:36 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2001-03-30 00:38:27 +00:00
|
|
|
fprintf(stderr, "invalid type: %s\n", word);
|
2001-03-29 23:51:36 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
2000-06-30 01:56:14 +00:00
|
|
|
} else {
|
2004-03-03 23:43:09 +00:00
|
|
|
rdataclass = getzoneclass();
|
2000-06-30 01:56:14 +00:00
|
|
|
result = dns_rdatatype_fromtext(&rdatatype, ®ion);
|
2001-03-29 23:51:36 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2001-03-30 00:38:27 +00:00
|
|
|
fprintf(stderr, "invalid type: %s\n", word);
|
2001-03-29 23:51:36 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
2000-06-30 01:56:14 +00:00
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2000-06-30 01:56:14 +00:00
|
|
|
rdatatype = dns_rdatatype_any;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-06-30 18:44:51 +00:00
|
|
|
result = dns_message_gettemprdata(updatemsg, &rdata);
|
|
|
|
check_result(result, "dns_message_gettemprdata");
|
|
|
|
|
2008-04-02 02:37:42 +00:00
|
|
|
dns_rdata_init(rdata);
|
2000-06-30 18:44:51 +00:00
|
|
|
|
|
|
|
if (isrrset && ispositive) {
|
2020-02-12 13:59:18 +01:00
|
|
|
retval = parse_rdata(&cmdline, rdataclass, rdatatype, updatemsg,
|
|
|
|
rdata);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (retval != STATUS_MORE) {
|
2001-04-20 21:10:36 +00:00
|
|
|
goto failure;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
} else {
|
2001-05-05 01:19:45 +00:00
|
|
|
rdata->flags = DNS_RDATA_UPDATE;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-06-19 22:09:46 +00:00
|
|
|
result = dns_message_gettemprdatalist(updatemsg, &rdatalist);
|
|
|
|
check_result(result, "dns_message_gettemprdatalist");
|
2000-06-10 00:50:36 +00:00
|
|
|
result = dns_message_gettemprdataset(updatemsg, &rdataset);
|
|
|
|
check_result(result, "dns_message_gettemprdataset");
|
2000-06-30 01:56:14 +00:00
|
|
|
rdatalist->type = rdatatype;
|
2000-06-30 18:44:51 +00:00
|
|
|
if (ispositive) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (isrrset && rdata->data != NULL) {
|
2000-06-30 18:44:51 +00:00
|
|
|
rdatalist->rdclass = rdataclass;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2000-06-30 18:44:51 +00:00
|
|
|
rdatalist->rdclass = dns_rdataclass_any;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
} else {
|
2000-06-30 01:56:14 +00:00
|
|
|
rdatalist->rdclass = dns_rdataclass_none;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-06-30 01:56:14 +00:00
|
|
|
rdata->rdclass = rdatalist->rdclass;
|
|
|
|
rdata->type = rdatatype;
|
2000-06-19 22:09:46 +00:00
|
|
|
ISC_LIST_APPEND(rdatalist->rdata, rdata, link);
|
2000-08-01 01:33:37 +00:00
|
|
|
dns_rdatalist_tordataset(rdatalist, rdataset);
|
2000-06-10 00:50:36 +00:00
|
|
|
ISC_LIST_INIT(name->list);
|
|
|
|
ISC_LIST_APPEND(name->list, rdataset, link);
|
|
|
|
dns_message_addname(updatemsg, name, DNS_SECTION_PREREQUISITE);
|
2000-06-30 01:56:14 +00:00
|
|
|
return (STATUS_MORE);
|
2001-03-29 23:51:36 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
failure:
|
2020-02-13 21:48:23 +01:00
|
|
|
if (name != NULL) {
|
2001-03-29 23:51:36 +00:00
|
|
|
dns_message_puttempname(updatemsg, &name);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2001-03-29 23:51:36 +00:00
|
|
|
return (STATUS_SYNTAX);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
2000-06-30 01:56:14 +00:00
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
static uint16_t
|
2020-02-13 14:44:37 -08:00
|
|
|
evaluate_prereq(char *cmdline) {
|
2000-06-30 03:24:27 +00:00
|
|
|
char *word;
|
2020-02-13 14:44:37 -08:00
|
|
|
bool ispositive, isrrset;
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-07-05 23:24:18 +00:00
|
|
|
ddebug("evaluate_prereq()");
|
2000-06-30 03:24:27 +00:00
|
|
|
word = nsu_strsep(&cmdline, " \t\r\n");
|
2012-08-22 13:38:51 +10:00
|
|
|
if (word == NULL || *word == 0) {
|
2001-04-16 17:09:00 +00:00
|
|
|
fprintf(stderr, "could not read operation code\n");
|
2000-06-30 01:56:14 +00:00
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
2000-06-30 03:24:27 +00:00
|
|
|
if (strcasecmp(word, "nxdomain") == 0) {
|
2018-04-17 08:29:14 -07:00
|
|
|
ispositive = false;
|
|
|
|
isrrset = false;
|
2000-06-30 03:24:27 +00:00
|
|
|
} else if (strcasecmp(word, "yxdomain") == 0) {
|
2018-04-17 08:29:14 -07:00
|
|
|
ispositive = true;
|
|
|
|
isrrset = false;
|
2000-06-30 03:24:27 +00:00
|
|
|
} else if (strcasecmp(word, "nxrrset") == 0) {
|
2018-04-17 08:29:14 -07:00
|
|
|
ispositive = false;
|
|
|
|
isrrset = true;
|
2000-06-30 03:24:27 +00:00
|
|
|
} else if (strcasecmp(word, "yxrrset") == 0) {
|
2018-04-17 08:29:14 -07:00
|
|
|
ispositive = true;
|
|
|
|
isrrset = true;
|
2000-06-30 01:56:14 +00:00
|
|
|
} else {
|
2000-07-09 06:25:49 +00:00
|
|
|
fprintf(stderr, "incorrect operation code: %s\n", word);
|
2000-06-30 01:56:14 +00:00
|
|
|
return (STATUS_SYNTAX);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
2000-06-30 03:24:27 +00:00
|
|
|
return (make_prereq(cmdline, ispositive, isrrset));
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
static uint16_t
|
2020-02-13 14:44:37 -08:00
|
|
|
evaluate_server(char *cmdline) {
|
2000-07-05 23:24:18 +00:00
|
|
|
char *word, *server;
|
2020-02-13 14:44:37 -08:00
|
|
|
long port;
|
2000-07-05 23:24:18 +00:00
|
|
|
|
2009-06-10 00:27:22 +00:00
|
|
|
if (local_only) {
|
|
|
|
fprintf(stderr, "cannot reset server in localhost-only mode\n");
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
|
|
|
|
2000-07-05 23:24:18 +00:00
|
|
|
word = nsu_strsep(&cmdline, " \t\r\n");
|
2012-08-22 13:38:51 +10:00
|
|
|
if (word == NULL || *word == 0) {
|
2001-04-16 17:09:00 +00:00
|
|
|
fprintf(stderr, "could not read server name\n");
|
2000-07-05 23:24:18 +00:00
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
|
|
|
server = word;
|
|
|
|
|
|
|
|
word = nsu_strsep(&cmdline, " \t\r\n");
|
2020-02-13 21:48:23 +01:00
|
|
|
if (word == NULL || *word == 0) {
|
2009-06-10 00:27:22 +00:00
|
|
|
port = dnsport;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2000-07-05 23:24:18 +00:00
|
|
|
char *endp;
|
|
|
|
port = strtol(word, &endp, 10);
|
|
|
|
if (*endp != 0) {
|
2000-07-09 06:25:49 +00:00
|
|
|
fprintf(stderr, "port '%s' is not numeric\n", word);
|
2000-07-05 23:24:18 +00:00
|
|
|
return (STATUS_SYNTAX);
|
2000-08-01 14:02:41 +00:00
|
|
|
} else if (port < 1 || port > 65535) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr,
|
|
|
|
"port '%s' is out of range "
|
|
|
|
"(1 to 65535)\n",
|
|
|
|
word);
|
2000-08-01 14:02:41 +00:00
|
|
|
return (STATUS_SYNTAX);
|
2000-07-05 23:24:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-05 18:26:38 +11:00
|
|
|
if (servers != NULL) {
|
2021-10-05 11:28:24 +02:00
|
|
|
if (primary_servers == servers) {
|
|
|
|
primary_servers = NULL;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2017-07-19 15:35:41 +10:00
|
|
|
isc_mem_put(gmctx, servers, ns_alloc * sizeof(isc_sockaddr_t));
|
2014-12-05 18:26:38 +11:00
|
|
|
}
|
2000-07-05 23:24:18 +00:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
default_servers = false;
|
2014-02-11 21:29:10 -08:00
|
|
|
|
2017-07-19 15:35:41 +10:00
|
|
|
ns_alloc = MAX_SERVERADDRS;
|
2014-12-05 18:26:38 +11:00
|
|
|
ns_inuse = 0;
|
2017-07-19 15:35:41 +10:00
|
|
|
servers = isc_mem_get(gmctx, ns_alloc * sizeof(isc_sockaddr_t));
|
2014-02-11 21:29:10 -08:00
|
|
|
|
2017-07-19 15:35:41 +10:00
|
|
|
memset(servers, 0, ns_alloc * sizeof(isc_sockaddr_t));
|
|
|
|
ns_total = get_addresses(server, (in_port_t)port, servers, ns_alloc);
|
2017-06-12 11:16:18 +02:00
|
|
|
if (ns_total == 0) {
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
2000-07-05 23:24:18 +00:00
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
return (STATUS_MORE);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
static uint16_t
|
2020-02-13 14:44:37 -08:00
|
|
|
evaluate_local(char *cmdline) {
|
|
|
|
char *word, *local;
|
|
|
|
long port;
|
|
|
|
struct in_addr in4;
|
2001-02-24 21:02:38 +00:00
|
|
|
struct in6_addr in6;
|
2000-11-16 05:40:25 +00:00
|
|
|
|
|
|
|
word = nsu_strsep(&cmdline, " \t\r\n");
|
2012-08-22 13:38:51 +10:00
|
|
|
if (word == NULL || *word == 0) {
|
2001-04-16 17:09:00 +00:00
|
|
|
fprintf(stderr, "could not read server name\n");
|
2000-11-16 05:40:25 +00:00
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
|
|
|
local = word;
|
|
|
|
|
|
|
|
word = nsu_strsep(&cmdline, " \t\r\n");
|
2020-02-13 21:48:23 +01:00
|
|
|
if (word == NULL || *word == 0) {
|
2000-11-16 05:40:25 +00:00
|
|
|
port = 0;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2000-11-16 05:40:25 +00:00
|
|
|
char *endp;
|
|
|
|
port = strtol(word, &endp, 10);
|
|
|
|
if (*endp != 0) {
|
|
|
|
fprintf(stderr, "port '%s' is not numeric\n", word);
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
} else if (port < 1 || port > 65535) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr,
|
|
|
|
"port '%s' is out of range "
|
|
|
|
"(1 to 65535)\n",
|
|
|
|
word);
|
2000-11-16 05:40:25 +00:00
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-05 18:26:38 +11:00
|
|
|
if (have_ipv6 && inet_pton(AF_INET6, local, &in6) == 1) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (localaddr6 == NULL) {
|
2020-02-12 13:59:18 +01:00
|
|
|
localaddr6 = isc_mem_get(gmctx, sizeof(isc_sockaddr_t));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-12-05 18:26:38 +11:00
|
|
|
isc_sockaddr_fromin6(localaddr6, &in6, (in_port_t)port);
|
|
|
|
} else if (have_ipv4 && inet_pton(AF_INET, local, &in4) == 1) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (localaddr4 == NULL) {
|
2020-02-12 13:59:18 +01:00
|
|
|
localaddr4 = isc_mem_get(gmctx, sizeof(isc_sockaddr_t));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-12-05 18:26:38 +11:00
|
|
|
isc_sockaddr_fromin(localaddr4, &in4, (in_port_t)port);
|
|
|
|
} else {
|
2001-02-24 21:02:38 +00:00
|
|
|
fprintf(stderr, "invalid address %s", local);
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
2000-11-16 05:40:25 +00:00
|
|
|
|
|
|
|
return (STATUS_MORE);
|
|
|
|
}
|
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
static uint16_t
|
2020-02-13 14:44:37 -08:00
|
|
|
evaluate_key(char *cmdline) {
|
|
|
|
char *namestr;
|
|
|
|
char *secretstr;
|
|
|
|
isc_buffer_t b;
|
|
|
|
isc_result_t result;
|
|
|
|
dns_fixedname_t fkeyname;
|
|
|
|
dns_name_t *mykeyname;
|
|
|
|
int secretlen;
|
|
|
|
unsigned char *secret = NULL;
|
|
|
|
isc_buffer_t secretbuf;
|
2016-12-30 15:45:08 +11:00
|
|
|
const dns_name_t *hmacname = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
uint16_t digestbits = 0;
|
|
|
|
char *n;
|
2001-07-02 06:09:28 +00:00
|
|
|
|
|
|
|
namestr = nsu_strsep(&cmdline, " \t\r\n");
|
2012-08-22 13:38:51 +10:00
|
|
|
if (namestr == NULL || *namestr == 0) {
|
2001-07-02 06:09:28 +00:00
|
|
|
fprintf(stderr, "could not read key name\n");
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
|
|
|
|
2018-03-28 14:38:09 +02:00
|
|
|
mykeyname = dns_fixedname_initname(&fkeyname);
|
2001-07-02 06:09:28 +00:00
|
|
|
|
2006-01-27 02:35:15 +00:00
|
|
|
n = strchr(namestr, ':');
|
|
|
|
if (n != NULL) {
|
2020-02-12 13:59:18 +01:00
|
|
|
if (!parse_hmac(&hmacname, namestr, n - namestr, &digestbits)) {
|
2017-06-12 11:16:18 +02:00
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
2006-01-27 02:35:15 +00:00
|
|
|
namestr = n + 1;
|
2018-06-12 11:26:04 +02:00
|
|
|
} else {
|
2006-01-27 02:35:15 +00:00
|
|
|
hmacname = DNS_TSIG_HMACMD5_NAME;
|
2018-06-12 11:26:04 +02:00
|
|
|
}
|
2006-01-27 02:35:15 +00:00
|
|
|
|
2001-07-02 06:09:28 +00:00
|
|
|
isc_buffer_init(&b, namestr, strlen(namestr));
|
|
|
|
isc_buffer_add(&b, strlen(namestr));
|
2015-01-20 13:29:18 -08:00
|
|
|
result = dns_name_fromtext(mykeyname, &b, dns_rootname, 0, NULL);
|
2001-07-02 06:09:28 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fprintf(stderr, "could not parse key name\n");
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
|
|
|
|
2002-06-17 02:30:40 +00:00
|
|
|
secretstr = nsu_strsep(&cmdline, "\r\n");
|
2012-08-22 13:38:51 +10:00
|
|
|
if (secretstr == NULL || *secretstr == 0) {
|
2001-07-02 06:09:28 +00:00
|
|
|
fprintf(stderr, "could not read key secret\n");
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
|
|
|
secretlen = strlen(secretstr) * 3 / 4;
|
2015-01-20 13:29:18 -08:00
|
|
|
secret = isc_mem_allocate(gmctx, secretlen);
|
2008-01-18 23:46:58 +00:00
|
|
|
|
2001-07-02 06:09:28 +00:00
|
|
|
isc_buffer_init(&secretbuf, secret, secretlen);
|
|
|
|
result = isc_base64_decodestring(secretstr, &secretbuf);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr, "could not create key from %s: %s\n", secretstr,
|
|
|
|
isc_result_totext(result));
|
2015-01-20 13:29:18 -08:00
|
|
|
isc_mem_free(gmctx, secret);
|
2001-07-02 06:09:28 +00:00
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
|
|
|
secretlen = isc_buffer_usedlength(&secretbuf);
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (tsigkey != NULL) {
|
2002-01-21 07:59:15 +00:00
|
|
|
dns_tsigkey_detach(&tsigkey);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-01-20 13:29:18 -08:00
|
|
|
result = dns_tsigkey_create(mykeyname, hmacname, secret, secretlen,
|
2020-02-12 13:59:18 +01:00
|
|
|
false, NULL, 0, 0, gmctx, NULL, &tsigkey);
|
2015-01-20 13:29:18 -08:00
|
|
|
isc_mem_free(gmctx, secret);
|
2001-07-02 06:09:28 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2001-07-02 18:56:58 +00:00
|
|
|
fprintf(stderr, "could not create key from %s %s: %s\n",
|
2021-10-04 17:14:53 +02:00
|
|
|
namestr, secretstr, isc_result_totext(result));
|
2001-07-02 06:09:28 +00:00
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
2006-01-27 02:35:15 +00:00
|
|
|
dst_key_setbits(tsigkey->key, digestbits);
|
2001-07-02 06:09:28 +00:00
|
|
|
return (STATUS_MORE);
|
|
|
|
}
|
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
static uint16_t
|
2020-02-13 14:44:37 -08:00
|
|
|
evaluate_zone(char *cmdline) {
|
|
|
|
char *word;
|
2000-07-05 23:24:18 +00:00
|
|
|
isc_buffer_t b;
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
word = nsu_strsep(&cmdline, " \t\r\n");
|
2012-08-22 13:38:51 +10:00
|
|
|
if (word == NULL || *word == 0) {
|
2001-04-16 17:09:00 +00:00
|
|
|
fprintf(stderr, "could not read zone name\n");
|
2000-07-05 23:24:18 +00:00
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
|
|
|
|
2018-03-28 14:38:09 +02:00
|
|
|
userzone = dns_fixedname_initname(&fuserzone);
|
2000-07-05 23:24:18 +00:00
|
|
|
isc_buffer_init(&b, word, strlen(word));
|
|
|
|
isc_buffer_add(&b, strlen(word));
|
2009-09-01 00:22:28 +00:00
|
|
|
result = dns_name_fromtext(userzone, &b, dns_rootname, 0, NULL);
|
2000-07-05 23:24:18 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2001-11-06 20:21:42 +00:00
|
|
|
userzone = NULL; /* Lest it point to an invalid name */
|
2001-04-16 17:09:00 +00:00
|
|
|
fprintf(stderr, "could not parse zone name\n");
|
2000-07-05 23:24:18 +00:00
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
return (STATUS_MORE);
|
2000-06-20 22:50:13 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
static uint16_t
|
2020-02-13 14:44:37 -08:00
|
|
|
evaluate_realm(char *cmdline) {
|
2018-08-07 16:46:53 +02:00
|
|
|
#if HAVE_GSSAPI
|
2010-07-09 05:13:15 +00:00
|
|
|
char *word;
|
2020-02-13 14:44:37 -08:00
|
|
|
char buf[1024];
|
|
|
|
int n;
|
2010-07-09 05:13:15 +00:00
|
|
|
|
2013-11-28 06:45:30 +11:00
|
|
|
if (realm != NULL) {
|
2015-01-20 13:29:18 -08:00
|
|
|
isc_mem_free(gmctx, realm);
|
2010-07-09 05:13:15 +00:00
|
|
|
realm = NULL;
|
|
|
|
}
|
|
|
|
|
2013-11-28 06:45:30 +11:00
|
|
|
word = nsu_strsep(&cmdline, " \t\r\n");
|
2020-02-13 21:48:23 +01:00
|
|
|
if (word == NULL || *word == 0) {
|
2013-11-28 06:45:30 +11:00
|
|
|
return (STATUS_MORE);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-11-28 06:45:30 +11:00
|
|
|
|
|
|
|
n = snprintf(buf, sizeof(buf), "@%s", word);
|
2017-06-12 11:16:18 +02:00
|
|
|
if (n < 0 || (size_t)n >= sizeof(buf)) {
|
|
|
|
error("realm is too long");
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
2015-01-20 13:29:18 -08:00
|
|
|
realm = isc_mem_strdup(gmctx, buf);
|
2010-07-09 05:13:15 +00:00
|
|
|
return (STATUS_MORE);
|
2018-08-07 16:46:53 +02:00
|
|
|
#else /* HAVE_GSSAPI */
|
2010-07-09 23:46:51 +00:00
|
|
|
UNUSED(cmdline);
|
2010-07-09 05:13:15 +00:00
|
|
|
return (STATUS_SYNTAX);
|
2018-08-07 16:46:53 +02:00
|
|
|
#endif /* HAVE_GSSAPI */
|
2010-07-09 05:13:15 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
static uint16_t
|
2020-02-13 14:44:37 -08:00
|
|
|
evaluate_ttl(char *cmdline) {
|
|
|
|
char *word;
|
2008-09-24 02:46:23 +00:00
|
|
|
isc_result_t result;
|
2020-02-13 14:44:37 -08:00
|
|
|
uint32_t ttl;
|
2008-09-24 02:46:23 +00:00
|
|
|
|
|
|
|
word = nsu_strsep(&cmdline, " \t\r\n");
|
2012-08-22 13:38:51 +10:00
|
|
|
if (word == NULL || *word == 0) {
|
2017-06-12 11:16:18 +02:00
|
|
|
fprintf(stderr, "could not read ttl\n");
|
2008-09-24 02:46:23 +00:00
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
|
|
|
|
2008-09-25 02:20:27 +00:00
|
|
|
if (!strcasecmp(word, "none")) {
|
|
|
|
default_ttl = 0;
|
2018-04-17 08:29:14 -07:00
|
|
|
default_ttl_set = false;
|
2008-09-25 02:20:27 +00:00
|
|
|
return (STATUS_MORE);
|
|
|
|
}
|
2008-09-25 04:02:39 +00:00
|
|
|
|
2008-09-24 02:46:23 +00:00
|
|
|
result = isc_parse_uint32(&ttl, word, 10);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2008-09-24 02:46:23 +00:00
|
|
|
return (STATUS_SYNTAX);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2008-09-24 02:46:23 +00:00
|
|
|
|
|
|
|
if (ttl > TTL_MAX) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr, "ttl '%s' is out of range (0 to %u)\n", word,
|
|
|
|
TTL_MAX);
|
2008-09-24 02:46:23 +00:00
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
|
|
|
default_ttl = ttl;
|
2018-04-17 08:29:14 -07:00
|
|
|
default_ttl_set = true;
|
2008-09-24 03:16:58 +00:00
|
|
|
|
2008-09-24 02:46:23 +00:00
|
|
|
return (STATUS_MORE);
|
|
|
|
}
|
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
static uint16_t
|
2020-02-13 14:44:37 -08:00
|
|
|
evaluate_class(char *cmdline) {
|
|
|
|
char *word;
|
2004-03-03 23:43:09 +00:00
|
|
|
isc_textregion_t r;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_result_t result;
|
2004-03-03 23:43:09 +00:00
|
|
|
dns_rdataclass_t rdclass;
|
|
|
|
|
|
|
|
word = nsu_strsep(&cmdline, " \t\r\n");
|
2012-08-22 13:38:51 +10:00
|
|
|
if (word == NULL || *word == 0) {
|
2004-03-03 23:43:09 +00:00
|
|
|
fprintf(stderr, "could not read class name\n");
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
|
|
|
|
|
|
|
r.base = word;
|
2006-12-04 01:54:53 +00:00
|
|
|
r.length = strlen(word);
|
|
|
|
result = dns_rdataclass_fromtext(&rdclass, &r);
|
2004-03-03 23:43:09 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fprintf(stderr, "could not parse class name: %s\n", word);
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
|
|
|
switch (rdclass) {
|
|
|
|
case dns_rdataclass_none:
|
|
|
|
case dns_rdataclass_any:
|
|
|
|
case dns_rdataclass_reserved0:
|
|
|
|
fprintf(stderr, "bad default class: %s\n", word);
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
default:
|
|
|
|
defaultclass = rdclass;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (STATUS_MORE);
|
|
|
|
}
|
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
static uint16_t
|
2020-02-13 14:44:37 -08:00
|
|
|
update_addordelete(char *cmdline, bool isdelete) {
|
|
|
|
isc_result_t result;
|
|
|
|
dns_name_t *name = NULL;
|
|
|
|
uint32_t ttl;
|
|
|
|
char *word;
|
2000-06-30 01:56:14 +00:00
|
|
|
dns_rdataclass_t rdataclass;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_rdatatype_t rdatatype;
|
|
|
|
dns_rdata_t *rdata = NULL;
|
2000-06-10 00:50:36 +00:00
|
|
|
dns_rdatalist_t *rdatalist = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_rdataset_t *rdataset = NULL;
|
2000-06-10 00:50:36 +00:00
|
|
|
isc_textregion_t region;
|
2020-02-13 14:44:37 -08:00
|
|
|
uint16_t retval;
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-07-09 16:17:13 +00:00
|
|
|
ddebug("update_addordelete()");
|
2000-06-30 01:56:14 +00:00
|
|
|
|
|
|
|
/*
|
2000-08-10 02:32:14 +00:00
|
|
|
* Read the owner name.
|
2000-06-30 01:56:14 +00:00
|
|
|
*/
|
2000-06-30 21:47:35 +00:00
|
|
|
retval = parse_name(&cmdline, updatemsg, &name);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (retval != STATUS_MORE) {
|
2000-06-30 21:47:35 +00:00
|
|
|
return (retval);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
result = dns_message_gettemprdata(updatemsg, &rdata);
|
|
|
|
check_result(result, "dns_message_gettemprdata");
|
|
|
|
|
2008-04-02 02:37:42 +00:00
|
|
|
dns_rdata_init(rdata);
|
2000-06-30 01:56:14 +00:00
|
|
|
|
|
|
|
/*
|
2000-08-01 14:02:41 +00:00
|
|
|
* If this is an add, read the TTL and verify that it's in range.
|
2001-01-21 19:52:06 +00:00
|
|
|
* If it's a delete, ignore a TTL if present (for compatibility).
|
2000-06-30 01:56:14 +00:00
|
|
|
*/
|
2001-01-21 19:52:06 +00:00
|
|
|
word = nsu_strsep(&cmdline, " \t\r\n");
|
2012-08-22 13:38:51 +10:00
|
|
|
if (word == NULL || *word == 0) {
|
2001-01-22 20:00:56 +00:00
|
|
|
if (!isdelete) {
|
2001-04-16 17:09:00 +00:00
|
|
|
fprintf(stderr, "could not read owner ttl\n");
|
2001-01-22 20:00:56 +00:00
|
|
|
goto failure;
|
2020-02-12 13:59:18 +01:00
|
|
|
} else {
|
2001-01-22 20:00:56 +00:00
|
|
|
ttl = 0;
|
|
|
|
rdataclass = dns_rdataclass_any;
|
|
|
|
rdatatype = dns_rdatatype_any;
|
|
|
|
rdata->flags = DNS_RDATA_UPDATE;
|
|
|
|
goto doneparsing;
|
|
|
|
}
|
2001-01-21 19:52:06 +00:00
|
|
|
}
|
2001-11-30 01:02:18 +00:00
|
|
|
result = isc_parse_uint32(&ttl, word, 10);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2001-01-22 20:00:56 +00:00
|
|
|
if (isdelete) {
|
|
|
|
ttl = 0;
|
|
|
|
goto parseclass;
|
2008-09-24 02:46:23 +00:00
|
|
|
} else if (default_ttl_set) {
|
|
|
|
ttl = default_ttl;
|
|
|
|
goto parseclass;
|
2001-01-22 20:00:56 +00:00
|
|
|
} else {
|
2001-11-30 01:02:18 +00:00
|
|
|
fprintf(stderr, "ttl '%s': %s\n", word,
|
|
|
|
isc_result_totext(result));
|
2000-06-30 21:47:35 +00:00
|
|
|
goto failure;
|
2000-06-30 01:56:14 +00:00
|
|
|
}
|
2001-01-21 19:52:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (isdelete) {
|
2000-06-30 01:56:14 +00:00
|
|
|
ttl = 0;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else if (ttl > TTL_MAX) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr, "ttl '%s' is out of range (0 to %u)\n", word,
|
|
|
|
TTL_MAX);
|
2001-01-21 19:52:06 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
/*
|
|
|
|
* Read the class or type.
|
|
|
|
*/
|
2001-01-22 20:00:56 +00:00
|
|
|
word = nsu_strsep(&cmdline, " \t\r\n");
|
2020-02-12 13:59:18 +01:00
|
|
|
parseclass:
|
2012-08-22 13:38:51 +10:00
|
|
|
if (word == NULL || *word == 0) {
|
2000-06-30 01:56:14 +00:00
|
|
|
if (isdelete) {
|
|
|
|
rdataclass = dns_rdataclass_any;
|
|
|
|
rdatatype = dns_rdatatype_any;
|
2000-10-25 04:26:57 +00:00
|
|
|
rdata->flags = DNS_RDATA_UPDATE;
|
2000-06-30 01:56:14 +00:00
|
|
|
goto doneparsing;
|
|
|
|
} else {
|
2001-04-16 17:09:00 +00:00
|
|
|
fprintf(stderr, "could not read class or type\n");
|
2000-06-30 21:47:35 +00:00
|
|
|
goto failure;
|
2000-06-30 01:56:14 +00:00
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
2000-06-30 03:24:27 +00:00
|
|
|
region.base = word;
|
|
|
|
region.length = strlen(word);
|
2009-04-30 07:10:09 +00:00
|
|
|
rdataclass = dns_rdataclass_any;
|
2000-06-30 01:56:14 +00:00
|
|
|
result = dns_rdataclass_fromtext(&rdataclass, ®ion);
|
2009-04-30 07:10:09 +00:00
|
|
|
if (result == ISC_R_SUCCESS && rdataclass != dns_rdataclass_any) {
|
2004-03-03 23:43:09 +00:00
|
|
|
if (!setzoneclass(rdataclass)) {
|
|
|
|
fprintf(stderr, "class mismatch: %s\n", word);
|
|
|
|
goto failure;
|
|
|
|
}
|
2000-06-30 01:56:14 +00:00
|
|
|
/*
|
|
|
|
* Now read the type.
|
|
|
|
*/
|
2000-06-30 03:24:27 +00:00
|
|
|
word = nsu_strsep(&cmdline, " \t\r\n");
|
2012-08-22 13:38:51 +10:00
|
|
|
if (word == NULL || *word == 0) {
|
2000-06-30 01:56:14 +00:00
|
|
|
if (isdelete) {
|
|
|
|
rdataclass = dns_rdataclass_any;
|
|
|
|
rdatatype = dns_rdatatype_any;
|
2000-10-25 04:26:57 +00:00
|
|
|
rdata->flags = DNS_RDATA_UPDATE;
|
2000-06-30 01:56:14 +00:00
|
|
|
goto doneparsing;
|
|
|
|
} else {
|
2001-04-16 17:09:00 +00:00
|
|
|
fprintf(stderr, "could not read type\n");
|
2000-06-30 21:47:35 +00:00
|
|
|
goto failure;
|
2000-06-30 01:56:14 +00:00
|
|
|
}
|
|
|
|
}
|
2000-06-30 03:24:27 +00:00
|
|
|
region.base = word;
|
|
|
|
region.length = strlen(word);
|
2000-06-30 01:56:14 +00:00
|
|
|
result = dns_rdatatype_fromtext(&rdatatype, ®ion);
|
2001-01-21 19:52:06 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr, "'%s' is not a valid type: %s\n", word,
|
|
|
|
isc_result_totext(result));
|
2001-01-21 19:52:06 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
2000-06-30 01:56:14 +00:00
|
|
|
} else {
|
2004-03-03 23:43:09 +00:00
|
|
|
rdataclass = getzoneclass();
|
2000-06-30 01:56:14 +00:00
|
|
|
result = dns_rdatatype_fromtext(&rdatatype, ®ion);
|
2001-01-21 19:52:06 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr,
|
|
|
|
"'%s' is not a valid class or type: "
|
|
|
|
"%s\n",
|
|
|
|
word, isc_result_totext(result));
|
2001-01-21 19:52:06 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
retval = parse_rdata(&cmdline, rdataclass, rdatatype, updatemsg, rdata);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (retval != STATUS_MORE) {
|
2000-06-30 21:47:35 +00:00
|
|
|
goto failure;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-06-30 03:24:27 +00:00
|
|
|
|
2000-06-30 21:47:35 +00:00
|
|
|
if (isdelete) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if ((rdata->flags & DNS_RDATA_UPDATE) != 0) {
|
2000-06-30 01:56:14 +00:00
|
|
|
rdataclass = dns_rdataclass_any;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2000-06-30 21:47:35 +00:00
|
|
|
rdataclass = dns_rdataclass_none;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-06-30 21:47:35 +00:00
|
|
|
} else {
|
2000-10-25 04:26:57 +00:00
|
|
|
if ((rdata->flags & DNS_RDATA_UPDATE) != 0) {
|
2001-04-16 17:09:00 +00:00
|
|
|
fprintf(stderr, "could not read rdata\n");
|
2000-06-30 21:47:35 +00:00
|
|
|
goto failure;
|
2000-06-30 01:56:14 +00:00
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
2014-10-02 09:35:43 +10:00
|
|
|
if (!isdelete && checknames) {
|
|
|
|
dns_fixedname_t fixed;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_name_t *bad;
|
2014-10-02 09:35:43 +10:00
|
|
|
|
|
|
|
if (!dns_rdata_checkowner(name, rdata->rdclass, rdata->type,
|
2020-02-12 13:59:18 +01:00
|
|
|
true)) {
|
2014-10-02 09:35:43 +10:00
|
|
|
char namebuf[DNS_NAME_FORMATSIZE];
|
|
|
|
|
|
|
|
dns_name_format(name, namebuf, sizeof(namebuf));
|
|
|
|
fprintf(stderr, "check-names failed: bad owner '%s'\n",
|
|
|
|
namebuf);
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2018-03-28 14:38:09 +02:00
|
|
|
bad = dns_fixedname_initname(&fixed);
|
2014-10-02 09:35:43 +10:00
|
|
|
if (!dns_rdata_checknames(rdata, name, bad)) {
|
|
|
|
char namebuf[DNS_NAME_FORMATSIZE];
|
|
|
|
|
|
|
|
dns_name_format(bad, namebuf, sizeof(namebuf));
|
|
|
|
fprintf(stderr, "check-names failed: bad name '%s'\n",
|
|
|
|
namebuf);
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-23 10:03:53 +10:00
|
|
|
if (!isdelete && rdata->type == dns_rdatatype_nsec3param) {
|
|
|
|
dns_rdata_nsec3param_t nsec3param;
|
|
|
|
|
|
|
|
result = dns_rdata_tostruct(rdata, &nsec3param, NULL);
|
|
|
|
check_result(result, "dns_rdata_tostruct");
|
|
|
|
if (nsec3param.iterations > dns_nsec3_maxiterations()) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"NSEC3PARAM has excessive iterations (> %u)\n",
|
|
|
|
dns_nsec3_maxiterations());
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
doneparsing:
|
2000-06-10 00:50:36 +00:00
|
|
|
|
|
|
|
result = dns_message_gettemprdatalist(updatemsg, &rdatalist);
|
|
|
|
check_result(result, "dns_message_gettemprdatalist");
|
|
|
|
result = dns_message_gettemprdataset(updatemsg, &rdataset);
|
|
|
|
check_result(result, "dns_message_gettemprdataset");
|
|
|
|
rdatalist->type = rdatatype;
|
2000-06-30 01:56:14 +00:00
|
|
|
rdatalist->rdclass = rdataclass;
|
2000-06-10 00:50:36 +00:00
|
|
|
rdatalist->covers = rdatatype;
|
2000-08-10 02:32:14 +00:00
|
|
|
rdatalist->ttl = (dns_ttl_t)ttl;
|
2000-06-10 00:50:36 +00:00
|
|
|
ISC_LIST_APPEND(rdatalist->rdata, rdata, link);
|
|
|
|
dns_rdatalist_tordataset(rdatalist, rdataset);
|
|
|
|
ISC_LIST_INIT(name->list);
|
|
|
|
ISC_LIST_APPEND(name->list, rdataset, link);
|
|
|
|
dns_message_addname(updatemsg, name, DNS_SECTION_UPDATE);
|
2000-06-30 01:56:14 +00:00
|
|
|
return (STATUS_MORE);
|
2000-06-30 21:47:35 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
failure:
|
2020-02-13 21:48:23 +01:00
|
|
|
if (name != NULL) {
|
2000-06-30 21:47:35 +00:00
|
|
|
dns_message_puttempname(updatemsg, &name);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2008-01-12 22:12:55 +00:00
|
|
|
dns_message_puttemprdata(updatemsg, &rdata);
|
2000-06-30 21:47:35 +00:00
|
|
|
return (STATUS_SYNTAX);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
static uint16_t
|
2020-02-13 14:44:37 -08:00
|
|
|
evaluate_update(char *cmdline) {
|
2000-06-30 03:24:27 +00:00
|
|
|
char *word;
|
2020-02-13 14:44:37 -08:00
|
|
|
bool isdelete;
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-07-05 23:24:18 +00:00
|
|
|
ddebug("evaluate_update()");
|
2000-06-30 03:24:27 +00:00
|
|
|
word = nsu_strsep(&cmdline, " \t\r\n");
|
2012-08-22 13:38:51 +10:00
|
|
|
if (word == NULL || *word == 0) {
|
2001-04-16 17:09:00 +00:00
|
|
|
fprintf(stderr, "could not read operation code\n");
|
2000-06-30 01:56:14 +00:00
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
if (strcasecmp(word, "delete") == 0) {
|
2018-04-17 08:29:14 -07:00
|
|
|
isdelete = true;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else if (strcasecmp(word, "del") == 0) {
|
2018-04-17 08:29:14 -07:00
|
|
|
isdelete = true;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else if (strcasecmp(word, "add") == 0) {
|
2018-04-17 08:29:14 -07:00
|
|
|
isdelete = false;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2000-07-09 06:25:49 +00:00
|
|
|
fprintf(stderr, "incorrect operation code: %s\n", word);
|
2000-06-30 01:56:14 +00:00
|
|
|
return (STATUS_SYNTAX);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
2000-06-30 03:24:27 +00:00
|
|
|
return (update_addordelete(cmdline, isdelete));
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
static uint16_t
|
2020-02-13 14:44:37 -08:00
|
|
|
evaluate_checknames(char *cmdline) {
|
2014-10-02 09:35:43 +10:00
|
|
|
char *word;
|
|
|
|
|
|
|
|
ddebug("evaluate_checknames()");
|
|
|
|
word = nsu_strsep(&cmdline, " \t\r\n");
|
|
|
|
if (word == NULL || *word == 0) {
|
|
|
|
fprintf(stderr, "could not read check-names directive\n");
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
2020-02-12 13:59:18 +01:00
|
|
|
if (strcasecmp(word, "yes") == 0 || strcasecmp(word, "true") == 0 ||
|
2020-02-13 14:44:37 -08:00
|
|
|
strcasecmp(word, "on") == 0)
|
|
|
|
{
|
2018-04-17 08:29:14 -07:00
|
|
|
checknames = true;
|
2014-10-02 09:35:43 +10:00
|
|
|
} else if (strcasecmp(word, "no") == 0 ||
|
2020-02-12 13:59:18 +01:00
|
|
|
strcasecmp(word, "false") == 0 ||
|
2020-02-13 14:44:37 -08:00
|
|
|
strcasecmp(word, "off") == 0)
|
|
|
|
{
|
2018-04-17 08:29:14 -07:00
|
|
|
checknames = false;
|
2014-10-02 09:35:43 +10:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "incorrect check-names directive: %s\n", word);
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
|
|
|
return (STATUS_MORE);
|
|
|
|
}
|
|
|
|
|
2006-03-02 01:57:20 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
setzone(dns_name_t *zonename) {
|
|
|
|
isc_result_t result;
|
|
|
|
dns_name_t *name = NULL;
|
2006-03-02 01:57:20 +00:00
|
|
|
dns_rdataset_t *rdataset = NULL;
|
|
|
|
|
|
|
|
result = dns_message_firstname(updatemsg, DNS_SECTION_ZONE);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
dns_message_currentname(updatemsg, DNS_SECTION_ZONE, &name);
|
|
|
|
dns_message_removename(updatemsg, name, DNS_SECTION_ZONE);
|
2020-02-12 13:59:18 +01:00
|
|
|
for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
rdataset = ISC_LIST_HEAD(name->list))
|
|
|
|
{
|
2006-03-02 01:57:20 +00:00
|
|
|
ISC_LIST_UNLINK(name->list, rdataset, link);
|
|
|
|
dns_rdataset_disassociate(rdataset);
|
|
|
|
dns_message_puttemprdataset(updatemsg, &rdataset);
|
|
|
|
}
|
|
|
|
dns_message_puttempname(updatemsg, &name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (zonename != NULL) {
|
|
|
|
result = dns_message_gettempname(updatemsg, &name);
|
|
|
|
check_result(result, "dns_message_gettempname");
|
|
|
|
dns_name_clone(zonename, name);
|
|
|
|
result = dns_message_gettemprdataset(updatemsg, &rdataset);
|
|
|
|
check_result(result, "dns_message_gettemprdataset");
|
|
|
|
dns_rdataset_makequestion(rdataset, getzoneclass(),
|
|
|
|
dns_rdatatype_soa);
|
|
|
|
ISC_LIST_INIT(name->list);
|
|
|
|
ISC_LIST_APPEND(name->list, rdataset, link);
|
|
|
|
dns_message_addname(updatemsg, name, DNS_SECTION_ZONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
show_message(FILE *stream, dns_message_t *msg, const char *description) {
|
|
|
|
isc_result_t result;
|
2000-09-28 21:39:26 +00:00
|
|
|
isc_buffer_t *buf = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
int bufsz;
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-07-09 16:17:13 +00:00
|
|
|
ddebug("show_message()");
|
2006-03-02 01:57:20 +00:00
|
|
|
|
|
|
|
setzone(userzone);
|
|
|
|
|
2000-09-28 21:39:26 +00:00
|
|
|
bufsz = INITTEXT;
|
2008-01-18 23:46:58 +00:00
|
|
|
do {
|
2000-09-28 21:39:26 +00:00
|
|
|
if (bufsz > MAXTEXT) {
|
2001-07-02 18:56:58 +00:00
|
|
|
fprintf(stderr, "could not allocate large enough "
|
2020-02-12 13:59:18 +01:00
|
|
|
"buffer to display message\n");
|
2000-09-28 21:39:26 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
if (buf != NULL) {
|
2000-09-28 21:39:26 +00:00
|
|
|
isc_buffer_free(&buf);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2020-02-02 08:35:46 +01:00
|
|
|
isc_buffer_allocate(gmctx, &buf, bufsz);
|
2001-03-28 02:42:56 +00:00
|
|
|
result = dns_message_totext(msg, style, 0, buf);
|
2000-09-28 21:39:26 +00:00
|
|
|
bufsz *= 2;
|
|
|
|
} while (result == ISC_R_NOSPACE);
|
2000-06-30 01:56:14 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2001-07-02 18:56:58 +00:00
|
|
|
fprintf(stderr, "could not convert message to text format.\n");
|
2000-09-28 21:39:26 +00:00
|
|
|
isc_buffer_free(&buf);
|
2000-06-30 01:56:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-12-04 01:54:53 +00:00
|
|
|
fprintf(stream, "%s\n%.*s", description,
|
2020-02-12 13:59:18 +01:00
|
|
|
(int)isc_buffer_usedlength(buf), (char *)isc_buffer_base(buf));
|
2018-01-22 14:26:04 +05:30
|
|
|
fflush(stream);
|
2000-09-28 21:39:26 +00:00
|
|
|
isc_buffer_free(&buf);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
static uint16_t
|
2020-02-13 14:44:37 -08:00
|
|
|
do_next_command(char *cmdline) {
|
2000-06-30 03:24:27 +00:00
|
|
|
char *word;
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2011-12-16 23:01:17 +00:00
|
|
|
ddebug("do_next_command()");
|
2000-06-30 03:24:27 +00:00
|
|
|
word = nsu_strsep(&cmdline, " \t\r\n");
|
2000-06-20 22:50:13 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (word == NULL || *word == 0) {
|
2000-06-30 03:24:27 +00:00
|
|
|
return (STATUS_SEND);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (word[0] == ';') {
|
2001-03-30 22:48:35 +00:00
|
|
|
return (STATUS_MORE);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (strcasecmp(word, "quit") == 0) {
|
2000-06-30 03:24:27 +00:00
|
|
|
return (STATUS_QUIT);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (strcasecmp(word, "prereq") == 0) {
|
2000-06-30 03:24:27 +00:00
|
|
|
return (evaluate_prereq(cmdline));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (strcasecmp(word, "nxdomain") == 0) {
|
2018-04-17 08:29:14 -07:00
|
|
|
return (make_prereq(cmdline, false, false));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (strcasecmp(word, "yxdomain") == 0) {
|
2018-04-17 08:29:14 -07:00
|
|
|
return (make_prereq(cmdline, true, false));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (strcasecmp(word, "nxrrset") == 0) {
|
2018-04-17 08:29:14 -07:00
|
|
|
return (make_prereq(cmdline, false, true));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (strcasecmp(word, "yxrrset") == 0) {
|
2018-04-17 08:29:14 -07:00
|
|
|
return (make_prereq(cmdline, true, true));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (strcasecmp(word, "update") == 0) {
|
2000-06-30 03:24:27 +00:00
|
|
|
return (evaluate_update(cmdline));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (strcasecmp(word, "delete") == 0) {
|
2018-04-17 08:29:14 -07:00
|
|
|
return (update_addordelete(cmdline, true));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (strcasecmp(word, "del") == 0) {
|
2018-04-17 08:29:14 -07:00
|
|
|
return (update_addordelete(cmdline, true));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (strcasecmp(word, "add") == 0) {
|
2018-04-17 08:29:14 -07:00
|
|
|
return (update_addordelete(cmdline, false));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (strcasecmp(word, "server") == 0) {
|
2000-06-30 03:24:27 +00:00
|
|
|
return (evaluate_server(cmdline));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (strcasecmp(word, "local") == 0) {
|
2000-11-16 05:40:25 +00:00
|
|
|
return (evaluate_local(cmdline));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (strcasecmp(word, "zone") == 0) {
|
2000-06-30 03:24:27 +00:00
|
|
|
return (evaluate_zone(cmdline));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (strcasecmp(word, "class") == 0) {
|
2004-03-03 23:43:09 +00:00
|
|
|
return (evaluate_class(cmdline));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (strcasecmp(word, "send") == 0) {
|
2000-06-30 03:24:27 +00:00
|
|
|
return (STATUS_SEND);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2008-09-24 02:46:23 +00:00
|
|
|
if (strcasecmp(word, "debug") == 0) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (debugging) {
|
2018-04-17 08:29:14 -07:00
|
|
|
ddebugging = true;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2018-04-17 08:29:14 -07:00
|
|
|
debugging = true;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2008-09-24 02:46:23 +00:00
|
|
|
return (STATUS_MORE);
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
if (strcasecmp(word, "ttl") == 0) {
|
2008-09-24 02:46:23 +00:00
|
|
|
return (evaluate_ttl(cmdline));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-06-30 03:24:27 +00:00
|
|
|
if (strcasecmp(word, "show") == 0) {
|
2006-12-04 01:54:53 +00:00
|
|
|
show_message(stdout, updatemsg, "Outgoing update query:");
|
2000-06-30 01:56:14 +00:00
|
|
|
return (STATUS_MORE);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
2004-03-04 01:21:39 +00:00
|
|
|
if (strcasecmp(word, "answer") == 0) {
|
2020-05-19 13:25:41 +10:00
|
|
|
LOCK(&answer_lock);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (answer != NULL) {
|
2006-12-04 01:54:53 +00:00
|
|
|
show_message(stdout, answer, "Answer:");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2020-05-19 13:25:41 +10:00
|
|
|
UNLOCK(&answer_lock);
|
2004-03-04 01:21:39 +00:00
|
|
|
return (STATUS_MORE);
|
|
|
|
}
|
2007-09-14 06:43:12 +00:00
|
|
|
if (strcasecmp(word, "key") == 0) {
|
2018-04-17 08:29:14 -07:00
|
|
|
usegsstsig = false;
|
2001-07-02 06:09:28 +00:00
|
|
|
return (evaluate_key(cmdline));
|
2007-09-14 06:43:12 +00:00
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
if (strcasecmp(word, "realm") == 0) {
|
2010-07-09 05:13:15 +00:00
|
|
|
return (evaluate_realm(cmdline));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2020-02-17 12:05:39 -08:00
|
|
|
if (strcasecmp(word, "check-names") == 0 ||
|
|
|
|
strcasecmp(word, "checknames") == 0) {
|
2014-10-02 09:35:43 +10:00
|
|
|
return (evaluate_checknames(cmdline));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2006-12-04 01:54:53 +00:00
|
|
|
if (strcasecmp(word, "gsstsig") == 0) {
|
2018-08-07 16:46:53 +02:00
|
|
|
#if HAVE_GSSAPI
|
2018-04-17 08:29:14 -07:00
|
|
|
usegsstsig = true;
|
|
|
|
use_win2k_gsstsig = false;
|
2018-08-07 16:46:53 +02:00
|
|
|
#else /* HAVE_GSSAPI */
|
2006-12-04 01:54:53 +00:00
|
|
|
fprintf(stderr, "gsstsig not supported\n");
|
2018-08-07 16:46:53 +02:00
|
|
|
#endif /* HAVE_GSSAPI */
|
2006-12-04 01:54:53 +00:00
|
|
|
return (STATUS_MORE);
|
|
|
|
}
|
|
|
|
if (strcasecmp(word, "oldgsstsig") == 0) {
|
2018-08-07 16:46:53 +02:00
|
|
|
#if HAVE_GSSAPI
|
2018-04-17 08:29:14 -07:00
|
|
|
usegsstsig = true;
|
|
|
|
use_win2k_gsstsig = true;
|
2018-08-07 16:46:53 +02:00
|
|
|
#else /* HAVE_GSSAPI */
|
2006-12-04 01:54:53 +00:00
|
|
|
fprintf(stderr, "gsstsig not supported\n");
|
2018-08-07 16:46:53 +02:00
|
|
|
#endif /* HAVE_GSSAPI */
|
2006-12-04 01:54:53 +00:00
|
|
|
return (STATUS_MORE);
|
|
|
|
}
|
2007-09-14 06:43:12 +00:00
|
|
|
if (strcasecmp(word, "help") == 0) {
|
2018-08-07 16:46:53 +02:00
|
|
|
fprintf(stdout, "nsupdate " PACKAGE_VERSION ":\n"
|
2020-02-12 13:59:18 +01:00
|
|
|
"local address [port] (set local "
|
|
|
|
"resolver)\n"
|
2021-10-05 11:28:24 +02:00
|
|
|
"server address [port] (set primary server "
|
2020-02-12 13:59:18 +01:00
|
|
|
"for zone)\n"
|
|
|
|
"send (send the update "
|
|
|
|
"request)\n"
|
|
|
|
"show (show the update "
|
|
|
|
"request)\n"
|
|
|
|
"answer (show the answer to "
|
|
|
|
"the last request)\n"
|
|
|
|
"quit (quit, any pending "
|
2021-09-15 17:01:00 +10:00
|
|
|
"update is not sent)\n"
|
2020-02-12 13:59:18 +01:00
|
|
|
"help (display this "
|
2021-09-15 17:01:00 +10:00
|
|
|
"message)\n"
|
2020-02-12 13:59:18 +01:00
|
|
|
"key [hmac:]keyname secret (use TSIG to sign "
|
|
|
|
"the request)\n"
|
|
|
|
"gsstsig (use GSS_TSIG to "
|
|
|
|
"sign the request)\n"
|
|
|
|
"oldgsstsig (use Microsoft's "
|
|
|
|
"GSS_TSIG to sign the request)\n"
|
|
|
|
"zone name (set the zone to be "
|
|
|
|
"updated)\n"
|
|
|
|
"class CLASS (set the zone's DNS "
|
|
|
|
"class, e.g. IN (default), CH)\n"
|
|
|
|
"check-names { on | off } (enable / disable "
|
|
|
|
"check-names)\n"
|
|
|
|
"[prereq] nxdomain name (require that this "
|
|
|
|
"name does not exist)\n"
|
|
|
|
"[prereq] yxdomain name (require that this "
|
|
|
|
"name exists)\n"
|
|
|
|
"[prereq] nxrrset .... (require that this "
|
|
|
|
"RRset does not exist)\n"
|
|
|
|
"[prereq] yxrrset .... (require that this "
|
|
|
|
"RRset exists)\n"
|
|
|
|
"[update] add .... (add the given "
|
|
|
|
"record to the zone)\n"
|
|
|
|
"[update] del[ete] .... (remove the given "
|
|
|
|
"record(s) from the zone)\n");
|
2007-09-14 06:43:12 +00:00
|
|
|
return (STATUS_MORE);
|
|
|
|
}
|
2014-03-03 08:46:50 -08:00
|
|
|
if (strcasecmp(word, "version") == 0) {
|
2018-08-07 16:46:53 +02:00
|
|
|
fprintf(stdout, "nsupdate " PACKAGE_VERSION "\n");
|
2014-03-03 08:46:50 -08:00
|
|
|
return (STATUS_MORE);
|
|
|
|
}
|
2000-07-09 16:17:13 +00:00
|
|
|
fprintf(stderr, "incorrect section name: %s\n", word);
|
2000-06-30 01:56:14 +00:00
|
|
|
return (STATUS_SYNTAX);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
static uint16_t
|
2020-02-13 14:44:37 -08:00
|
|
|
get_next_command(void) {
|
2018-03-28 14:19:37 +02:00
|
|
|
uint16_t result = STATUS_QUIT;
|
2020-02-13 14:44:37 -08:00
|
|
|
char cmdlinebuf[MAXCMD];
|
2020-08-11 16:14:36 +02:00
|
|
|
char *cmdline = NULL, *ptr = NULL;
|
2011-12-16 23:01:17 +00:00
|
|
|
|
|
|
|
isc_app_block();
|
|
|
|
if (interactive) {
|
2020-08-11 16:14:36 +02:00
|
|
|
cmdline = ptr = readline("> ");
|
|
|
|
if (ptr != NULL && *ptr != 0) {
|
|
|
|
add_history(ptr);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
} else {
|
2011-12-16 23:01:17 +00:00
|
|
|
cmdline = fgets(cmdlinebuf, MAXCMD, input);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2011-12-16 23:01:17 +00:00
|
|
|
isc_app_unblock();
|
2012-08-22 13:38:51 +10:00
|
|
|
|
|
|
|
if (cmdline != NULL) {
|
|
|
|
char *tmp = cmdline;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Normalize input by removing any eol as readline()
|
|
|
|
* removes eol but fgets doesn't.
|
|
|
|
*/
|
|
|
|
(void)nsu_strsep(&tmp, "\r\n");
|
2011-12-16 23:01:17 +00:00
|
|
|
result = do_next_command(cmdline);
|
2012-08-22 13:38:51 +10:00
|
|
|
}
|
2020-08-11 16:14:36 +02:00
|
|
|
if (ptr != NULL) {
|
|
|
|
free(ptr);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2020-08-11 16:14:36 +02:00
|
|
|
|
2011-12-16 23:01:17 +00:00
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
static bool
|
2020-02-13 14:44:37 -08:00
|
|
|
user_interaction(void) {
|
2018-03-28 14:19:37 +02:00
|
|
|
uint16_t result = STATUS_MORE;
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-07-09 16:17:13 +00:00
|
|
|
ddebug("user_interaction()");
|
2007-04-24 07:02:31 +00:00
|
|
|
while ((result == STATUS_MORE) || (result == STATUS_SYNTAX)) {
|
2000-06-10 00:50:36 +00:00
|
|
|
result = get_next_command();
|
2020-02-13 21:48:23 +01:00
|
|
|
if (!interactive && result == STATUS_SYNTAX) {
|
2007-04-24 07:02:31 +00:00
|
|
|
fatal("syntax error");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2007-04-24 07:02:31 +00:00
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result == STATUS_SEND) {
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2018-04-17 08:29:14 -07:00
|
|
|
return (false);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
done_update(void) {
|
2000-09-01 21:34:12 +00:00
|
|
|
isc_event_t *event = global_event;
|
2000-11-22 02:54:15 +00:00
|
|
|
ddebug("done_update()");
|
2000-09-01 21:34:12 +00:00
|
|
|
isc_task_send(global_task, &event);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
2004-03-04 01:21:39 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
check_tsig_error(dns_rdataset_t *rdataset, isc_buffer_t *b) {
|
|
|
|
isc_result_t result;
|
|
|
|
dns_rdata_t rdata = DNS_RDATA_INIT;
|
2004-03-04 01:21:39 +00:00
|
|
|
dns_rdata_any_tsig_t tsig;
|
|
|
|
|
|
|
|
result = dns_rdataset_first(rdataset);
|
|
|
|
check_result(result, "dns_rdataset_first");
|
|
|
|
dns_rdataset_current(rdataset, &rdata);
|
|
|
|
result = dns_rdata_tostruct(&rdata, &tsig, NULL);
|
|
|
|
check_result(result, "dns_rdata_tostruct");
|
|
|
|
if (tsig.error != 0) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (isc_buffer_remaininglength(b) < 1) {
|
2020-02-12 13:59:18 +01:00
|
|
|
check_result(ISC_R_NOSPACE, "isc_buffer_"
|
|
|
|
"remaininglength");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-03-06 17:21:19 -08:00
|
|
|
isc_buffer_putstr(b, "(" /*)*/);
|
2004-03-04 01:21:39 +00:00
|
|
|
result = dns_tsigrcode_totext(tsig.error, b);
|
|
|
|
check_result(result, "dns_tsigrcode_totext");
|
2020-02-13 21:48:23 +01:00
|
|
|
if (isc_buffer_remaininglength(b) < 1) {
|
2020-02-12 13:59:18 +01:00
|
|
|
check_result(ISC_R_NOSPACE, "isc_buffer_"
|
|
|
|
"remaininglength");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_buffer_putstr(b, /*(*/ ")");
|
2004-03-04 01:21:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
static bool
|
2021-10-05 11:28:24 +02:00
|
|
|
next_primary(const char *caller, isc_sockaddr_t *addr, isc_result_t eresult) {
|
2014-12-05 18:26:38 +11:00
|
|
|
char addrbuf[ISC_SOCKADDR_FORMATSIZE];
|
|
|
|
|
|
|
|
isc_sockaddr_format(addr, addrbuf, sizeof(addrbuf));
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr, "; Communication with %s failed: %s\n", addrbuf,
|
|
|
|
isc_result_totext(eresult));
|
2021-10-05 11:28:24 +02:00
|
|
|
if (++primary_inuse >= primary_total) {
|
2018-04-17 08:29:14 -07:00
|
|
|
return (false);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-12-05 18:26:38 +11:00
|
|
|
ddebug("%s: trying next server", caller);
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2014-12-05 18:26:38 +11:00
|
|
|
}
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
update_completed(isc_task_t *task, isc_event_t *event) {
|
2000-06-16 17:10:02 +00:00
|
|
|
dns_requestevent_t *reqev = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_result_t result;
|
|
|
|
dns_request_t *request;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-07-09 16:17:13 +00:00
|
|
|
UNUSED(task);
|
2000-06-16 17:10:02 +00:00
|
|
|
|
2000-11-22 02:54:15 +00:00
|
|
|
ddebug("update_completed()");
|
2001-01-21 21:54:32 +00:00
|
|
|
|
2001-04-13 01:32:14 +00:00
|
|
|
requests--;
|
|
|
|
|
2000-06-16 17:10:02 +00:00
|
|
|
REQUIRE(event->ev_type == DNS_EVENT_REQUESTDONE);
|
|
|
|
reqev = (dns_requestevent_t *)event;
|
2001-01-21 21:54:32 +00:00
|
|
|
request = reqev->request;
|
|
|
|
|
|
|
|
if (shuttingdown) {
|
|
|
|
dns_request_destroy(&request);
|
|
|
|
isc_event_free(&event);
|
2001-04-13 01:32:14 +00:00
|
|
|
maybeshutdown();
|
2001-01-21 21:54:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-06-16 17:10:02 +00:00
|
|
|
if (reqev->result != ISC_R_SUCCESS) {
|
2021-10-05 11:28:24 +02:00
|
|
|
if (!next_primary("update_completed",
|
|
|
|
&primary_servers[primary_inuse],
|
|
|
|
reqev->result))
|
2020-02-13 14:44:37 -08:00
|
|
|
{
|
2018-04-17 08:29:14 -07:00
|
|
|
seenerror = true;
|
2014-12-05 18:26:38 +11:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
ddebug("Destroying request [%p]", request);
|
|
|
|
dns_request_destroy(&request);
|
|
|
|
dns_message_renderreset(updatemsg);
|
|
|
|
dns_message_settsigkey(updatemsg, NULL);
|
2021-10-05 11:28:24 +02:00
|
|
|
send_update(zname, &primary_servers[primary_inuse]);
|
2014-12-05 18:26:38 +11:00
|
|
|
isc_event_free(&event);
|
|
|
|
return;
|
2000-06-16 17:10:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-19 13:25:41 +10:00
|
|
|
LOCK(&answer_lock);
|
2020-09-25 11:51:36 +02:00
|
|
|
dns_message_create(gmctx, DNS_MESSAGE_INTENTPARSE, &answer);
|
2004-03-04 01:21:39 +00:00
|
|
|
result = dns_request_getresponse(request, answer,
|
2000-10-06 18:58:30 +00:00
|
|
|
DNS_MESSAGEPARSE_PRESERVEORDER);
|
2001-07-02 06:09:28 +00:00
|
|
|
switch (result) {
|
|
|
|
case ISC_R_SUCCESS:
|
2020-02-13 21:48:23 +01:00
|
|
|
if (answer->verify_attempted) {
|
2006-12-04 01:54:53 +00:00
|
|
|
ddebug("tsig verification successful");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2001-07-02 06:09:28 +00:00
|
|
|
break;
|
|
|
|
case DNS_R_CLOCKSKEW:
|
|
|
|
case DNS_R_EXPECTEDTSIG:
|
|
|
|
case DNS_R_TSIGERRORSET:
|
|
|
|
case DNS_R_TSIGVERIFYFAILURE:
|
|
|
|
case DNS_R_UNEXPECTEDTSIG:
|
2006-12-04 01:54:53 +00:00
|
|
|
case ISC_R_FAILURE:
|
|
|
|
#if 0
|
|
|
|
if (usegsstsig && answer->rcode == dns_rcode_noerror) {
|
|
|
|
/*
|
|
|
|
* For MS DNS that violates RFC 2845, section 4.2
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if 0 */
|
2001-07-02 06:09:28 +00:00
|
|
|
fprintf(stderr, "; TSIG error with server: %s\n",
|
|
|
|
isc_result_totext(result));
|
2018-04-17 08:29:14 -07:00
|
|
|
seenerror = true;
|
2001-07-02 06:09:28 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
check_result(result, "dns_request_getresponse");
|
|
|
|
}
|
|
|
|
|
2021-06-11 16:58:15 +10:00
|
|
|
if (answer->opcode != dns_opcode_update) {
|
|
|
|
fatal("invalid OPCODE in response to UPDATE request");
|
|
|
|
}
|
|
|
|
|
2004-03-04 01:21:39 +00:00
|
|
|
if (answer->rcode != dns_rcode_noerror) {
|
2018-04-17 08:29:14 -07:00
|
|
|
seenerror = true;
|
2004-03-04 01:21:39 +00:00
|
|
|
if (!debugging) {
|
2020-02-13 14:44:37 -08:00
|
|
|
char buf[64];
|
|
|
|
isc_buffer_t b;
|
2004-03-04 01:21:39 +00:00
|
|
|
dns_rdataset_t *rds;
|
2008-01-18 23:46:58 +00:00
|
|
|
|
2004-03-04 01:21:39 +00:00
|
|
|
isc_buffer_init(&b, buf, sizeof(buf) - 1);
|
|
|
|
result = dns_rcode_totext(answer->rcode, &b);
|
|
|
|
check_result(result, "dns_rcode_totext");
|
|
|
|
rds = dns_message_gettsig(answer, NULL);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (rds != NULL) {
|
2004-03-04 01:21:39 +00:00
|
|
|
check_tsig_error(rds, &b);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2004-03-04 01:21:39 +00:00
|
|
|
fprintf(stderr, "update failed: %.*s\n",
|
|
|
|
(int)isc_buffer_usedlength(&b), buf);
|
|
|
|
}
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
if (debugging) {
|
2006-12-04 01:54:53 +00:00
|
|
|
show_message(stderr, answer, "\nReply from update query:");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2020-05-19 13:25:41 +10:00
|
|
|
UNLOCK(&answer_lock);
|
2006-12-04 01:54:53 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
done:
|
2001-01-21 21:54:32 +00:00
|
|
|
dns_request_destroy(&request);
|
2006-12-04 01:54:53 +00:00
|
|
|
if (usegsstsig) {
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_name_free(&tmpzonename, gmctx);
|
2021-10-05 11:28:24 +02:00
|
|
|
dns_name_free(&restart_primary, gmctx);
|
2018-11-14 15:17:48 +11:00
|
|
|
dns_name_init(&tmpzonename, 0);
|
2021-10-05 11:28:24 +02:00
|
|
|
dns_name_init(&restart_primary, 0);
|
2006-12-04 01:54:53 +00:00
|
|
|
}
|
2000-06-16 17:10:02 +00:00
|
|
|
isc_event_free(&event);
|
2000-09-01 21:34:12 +00:00
|
|
|
done_update();
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-10-05 11:28:24 +02:00
|
|
|
send_update(dns_name_t *zone, isc_sockaddr_t *primary) {
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_result_t result;
|
|
|
|
dns_request_t *request = NULL;
|
|
|
|
unsigned int options = DNS_REQUESTOPT_CASE;
|
2014-12-05 23:45:22 +00:00
|
|
|
isc_sockaddr_t *srcaddr;
|
2000-06-16 17:10:02 +00:00
|
|
|
|
2000-07-05 23:24:18 +00:00
|
|
|
ddebug("send_update()");
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
setzone(zone);
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (usevc) {
|
2000-06-30 18:59:21 +00:00
|
|
|
options |= DNS_REQUESTOPT_TCP;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2002-01-21 07:59:15 +00:00
|
|
|
if (tsigkey == NULL && sig0key != NULL) {
|
|
|
|
result = dns_message_setsig0key(updatemsg, sig0key);
|
|
|
|
check_result(result, "dns_message_setsig0key");
|
|
|
|
}
|
2002-04-18 00:22:17 +00:00
|
|
|
if (debugging) {
|
|
|
|
char addrbuf[ISC_SOCKADDR_FORMATSIZE];
|
|
|
|
|
2021-10-05 11:28:24 +02:00
|
|
|
isc_sockaddr_format(primary, addrbuf, sizeof(addrbuf));
|
2002-04-18 00:22:17 +00:00
|
|
|
fprintf(stderr, "Sending update to %s\n", addrbuf);
|
|
|
|
}
|
2006-12-04 01:54:53 +00:00
|
|
|
|
2021-10-05 11:28:24 +02:00
|
|
|
if (isc_sockaddr_pf(primary) == AF_INET6) {
|
2014-12-05 18:26:38 +11:00
|
|
|
srcaddr = localaddr6;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2014-12-05 18:26:38 +11:00
|
|
|
srcaddr = localaddr4;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-12-05 18:26:38 +11:00
|
|
|
|
2010-03-12 03:34:56 +00:00
|
|
|
/* Windows doesn't like the tsig name to be compressed. */
|
2020-02-13 21:48:23 +01:00
|
|
|
if (updatemsg->tsigname) {
|
2010-03-12 03:34:56 +00:00
|
|
|
updatemsg->tsigname->attributes |= DNS_NAMEATTR_NOCOMPRESS;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2010-03-12 03:34:56 +00:00
|
|
|
|
2021-10-05 11:28:24 +02:00
|
|
|
result = dns_request_createvia(requestmgr, updatemsg, srcaddr, primary,
|
2020-02-12 13:59:18 +01:00
|
|
|
-1, options, tsigkey, timeout,
|
2018-04-03 15:12:27 +02:00
|
|
|
udp_timeout, udp_retries, global_task,
|
|
|
|
update_completed, NULL, &request);
|
|
|
|
check_result(result, "dns_request_createvia");
|
2001-09-10 12:30:46 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (debugging) {
|
2006-12-04 01:54:53 +00:00
|
|
|
show_message(stdout, updatemsg, "Outgoing update query:");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2001-09-10 12:30:46 +00:00
|
|
|
|
2001-04-13 01:32:14 +00:00
|
|
|
requests++;
|
2000-07-05 23:24:18 +00:00
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2014-02-11 21:29:10 -08:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
next_server(const char *caller, isc_sockaddr_t *addr, isc_result_t eresult) {
|
2014-02-11 21:29:10 -08:00
|
|
|
char addrbuf[ISC_SOCKADDR_FORMATSIZE];
|
|
|
|
|
|
|
|
isc_sockaddr_format(addr, addrbuf, sizeof(addrbuf));
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr, "; Communication with %s failed: %s\n", addrbuf,
|
|
|
|
isc_result_totext(eresult));
|
2020-02-13 21:48:23 +01:00
|
|
|
if (++ns_inuse >= ns_total) {
|
2014-02-11 21:29:10 -08:00
|
|
|
fatal("could not reach any name server");
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2014-02-11 21:29:10 -08:00
|
|
|
ddebug("%s: trying next server", caller);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-11 21:29:10 -08:00
|
|
|
}
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
recvsoa(isc_task_t *task, isc_event_t *event) {
|
2000-06-10 00:50:36 +00:00
|
|
|
dns_requestevent_t *reqev = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_request_t *request = NULL;
|
|
|
|
isc_result_t result, eresult;
|
|
|
|
dns_message_t *rcvmsg = NULL;
|
|
|
|
dns_section_t section;
|
|
|
|
dns_name_t *name = NULL;
|
|
|
|
dns_rdataset_t *soaset = NULL;
|
|
|
|
dns_rdata_soa_t soa;
|
|
|
|
dns_rdata_t soarr = DNS_RDATA_INIT;
|
|
|
|
int pass = 0;
|
2021-10-05 11:28:24 +02:00
|
|
|
dns_name_t primary;
|
2020-02-13 14:44:37 -08:00
|
|
|
nsu_requestinfo_t *reqinfo;
|
|
|
|
dns_message_t *soaquery = NULL;
|
|
|
|
isc_sockaddr_t *addr;
|
|
|
|
isc_sockaddr_t *srcaddr;
|
|
|
|
bool seencname = false;
|
|
|
|
dns_name_t tname;
|
|
|
|
unsigned int nlabels;
|
2000-06-10 00:50:36 +00:00
|
|
|
|
|
|
|
UNUSED(task);
|
|
|
|
|
2000-07-09 16:17:13 +00:00
|
|
|
ddebug("recvsoa()");
|
2001-04-13 01:32:14 +00:00
|
|
|
|
|
|
|
requests--;
|
2008-01-18 23:46:58 +00:00
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
REQUIRE(event->ev_type == DNS_EVENT_REQUESTDONE);
|
|
|
|
reqev = (dns_requestevent_t *)event;
|
2000-06-30 01:56:14 +00:00
|
|
|
request = reqev->request;
|
|
|
|
eresult = reqev->result;
|
2000-07-05 23:24:18 +00:00
|
|
|
reqinfo = reqev->ev_arg;
|
|
|
|
soaquery = reqinfo->msg;
|
|
|
|
addr = reqinfo->addr;
|
2000-06-30 01:56:14 +00:00
|
|
|
|
2001-01-21 21:54:32 +00:00
|
|
|
if (shuttingdown) {
|
|
|
|
dns_request_destroy(&request);
|
2020-09-21 16:16:15 -03:00
|
|
|
dns_message_detach(&soaquery);
|
2015-01-20 13:29:18 -08:00
|
|
|
isc_mem_put(gmctx, reqinfo, sizeof(nsu_requestinfo_t));
|
2001-01-21 21:54:32 +00:00
|
|
|
isc_event_free(&event);
|
2001-04-13 01:32:14 +00:00
|
|
|
maybeshutdown();
|
2001-01-21 21:54:32 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-06-30 01:56:14 +00:00
|
|
|
|
|
|
|
if (eresult != ISC_R_SUCCESS) {
|
2014-02-11 21:29:10 -08:00
|
|
|
next_server("recvsoa", addr, eresult);
|
2001-08-08 22:54:55 +00:00
|
|
|
ddebug("Destroying request [%p]", request);
|
2000-06-30 01:56:14 +00:00
|
|
|
dns_request_destroy(&request);
|
2000-09-15 23:30:28 +00:00
|
|
|
dns_message_renderreset(soaquery);
|
2005-03-16 01:02:33 +00:00
|
|
|
dns_message_settsigkey(soaquery, NULL);
|
2014-12-05 18:26:38 +11:00
|
|
|
sendrequest(&servers[ns_inuse], soaquery, &request);
|
2015-01-20 13:29:18 -08:00
|
|
|
isc_mem_put(gmctx, reqinfo, sizeof(nsu_requestinfo_t));
|
2001-01-21 21:54:32 +00:00
|
|
|
isc_event_free(&event);
|
2004-03-03 23:43:09 +00:00
|
|
|
setzoneclass(dns_rdataclass_none);
|
2000-06-10 00:50:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-06-30 01:56:14 +00:00
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
isc_mem_put(gmctx, reqinfo, sizeof(nsu_requestinfo_t));
|
2006-12-07 05:39:41 +00:00
|
|
|
reqinfo = NULL;
|
2001-01-21 21:54:32 +00:00
|
|
|
isc_event_free(&event);
|
|
|
|
reqev = NULL;
|
|
|
|
|
2000-07-09 16:17:13 +00:00
|
|
|
ddebug("About to create rcvmsg");
|
2020-09-25 11:51:36 +02:00
|
|
|
dns_message_create(gmctx, DNS_MESSAGE_INTENTPARSE, &rcvmsg);
|
2000-10-06 18:58:30 +00:00
|
|
|
result = dns_request_getresponse(request, rcvmsg,
|
|
|
|
DNS_MESSAGEPARSE_PRESERVEORDER);
|
2014-02-11 21:29:10 -08:00
|
|
|
if (result == DNS_R_TSIGERRORSET && servers != NULL) {
|
2020-09-21 16:16:15 -03:00
|
|
|
dns_message_detach(&rcvmsg);
|
2004-03-04 05:33:03 +00:00
|
|
|
ddebug("Destroying request [%p]", request);
|
|
|
|
dns_request_destroy(&request);
|
2015-01-20 13:29:18 -08:00
|
|
|
reqinfo = isc_mem_get(gmctx, sizeof(nsu_requestinfo_t));
|
2004-03-04 05:33:03 +00:00
|
|
|
reqinfo->msg = soaquery;
|
|
|
|
reqinfo->addr = addr;
|
|
|
|
dns_message_renderreset(soaquery);
|
|
|
|
ddebug("retrying soa request without TSIG");
|
2014-12-05 18:26:38 +11:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (isc_sockaddr_pf(addr) == AF_INET6) {
|
2014-12-05 18:26:38 +11:00
|
|
|
srcaddr = localaddr6;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2014-12-05 18:26:38 +11:00
|
|
|
srcaddr = localaddr4;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-12-05 18:26:38 +11:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_request_createvia(
|
|
|
|
requestmgr, soaquery, srcaddr, addr, -1, 0, NULL,
|
|
|
|
FIND_TIMEOUT * 20, FIND_TIMEOUT, 3, global_task,
|
|
|
|
recvsoa, reqinfo, &request);
|
2018-04-03 15:12:27 +02:00
|
|
|
check_result(result, "dns_request_createvia");
|
2004-03-04 05:33:03 +00:00
|
|
|
requests++;
|
|
|
|
return;
|
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
check_result(result, "dns_request_getresponse");
|
2021-06-09 13:37:20 -07:00
|
|
|
|
|
|
|
if (rcvmsg->rcode == dns_rcode_refused) {
|
|
|
|
next_server("recvsoa", addr, DNS_R_REFUSED);
|
|
|
|
dns_message_detach(&rcvmsg);
|
|
|
|
dns_request_destroy(&request);
|
|
|
|
dns_message_renderreset(soaquery);
|
|
|
|
dns_message_settsigkey(soaquery, NULL);
|
|
|
|
sendrequest(&servers[ns_inuse], soaquery, &request);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
section = DNS_SECTION_ANSWER;
|
2011-03-11 06:11:27 +00:00
|
|
|
POST(section);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (debugging) {
|
2006-12-04 01:54:53 +00:00
|
|
|
show_message(stderr, rcvmsg, "Reply from SOA query:");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-06-16 17:10:02 +00:00
|
|
|
|
2021-06-11 16:58:15 +10:00
|
|
|
if (rcvmsg->opcode != dns_opcode_query) {
|
|
|
|
fatal("invalid OPCODE in response to SOA query");
|
|
|
|
}
|
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
if (rcvmsg->rcode != dns_rcode_noerror &&
|
2020-02-13 21:48:23 +01:00
|
|
|
rcvmsg->rcode != dns_rcode_nxdomain) {
|
2000-06-30 01:56:14 +00:00
|
|
|
fatal("response to SOA query was unsuccessful");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-06-30 01:56:14 +00:00
|
|
|
|
2006-12-07 05:39:41 +00:00
|
|
|
if (userzone != NULL && rcvmsg->rcode == dns_rcode_nxdomain) {
|
|
|
|
char namebuf[DNS_NAME_FORMATSIZE];
|
|
|
|
dns_name_format(userzone, namebuf, sizeof(namebuf));
|
2020-02-12 13:59:18 +01:00
|
|
|
error("specified zone '%s' does not exist (NXDOMAIN)", namebuf);
|
2020-09-21 16:16:15 -03:00
|
|
|
dns_message_detach(&rcvmsg);
|
2006-12-07 05:39:41 +00:00
|
|
|
dns_request_destroy(&request);
|
2020-09-21 16:16:15 -03:00
|
|
|
dns_message_detach(&soaquery);
|
2006-12-07 05:39:41 +00:00
|
|
|
ddebug("Out of recvsoa");
|
|
|
|
done_update();
|
2018-04-17 08:29:14 -07:00
|
|
|
seenerror = true;
|
2006-12-07 05:39:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
lookforsoa:
|
2020-02-13 21:48:23 +01:00
|
|
|
if (pass == 0) {
|
2000-06-30 01:56:14 +00:00
|
|
|
section = DNS_SECTION_ANSWER;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else if (pass == 1) {
|
2000-06-30 01:56:14 +00:00
|
|
|
section = DNS_SECTION_AUTHORITY;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2004-09-16 02:10:42 +00:00
|
|
|
goto droplabel;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-06-30 01:56:14 +00:00
|
|
|
|
2000-06-16 17:10:02 +00:00
|
|
|
result = dns_message_firstname(rcvmsg, section);
|
2000-06-10 00:50:36 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-06-30 01:56:14 +00:00
|
|
|
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);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result == ISC_R_SUCCESS) {
|
2000-06-30 01:56:14 +00:00
|
|
|
break;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-12-11 20:53:25 +00:00
|
|
|
if (section == DNS_SECTION_ANSWER) {
|
|
|
|
dns_rdataset_t *tset = NULL;
|
|
|
|
if (dns_message_findtype(name, dns_rdatatype_cname, 0,
|
2006-12-04 01:54:53 +00:00
|
|
|
&tset) == ISC_R_SUCCESS ||
|
2000-12-11 20:53:25 +00:00
|
|
|
dns_message_findtype(name, dns_rdatatype_dname, 0,
|
2020-02-13 14:44:37 -08:00
|
|
|
&tset) == ISC_R_SUCCESS)
|
|
|
|
{
|
2018-04-17 08:29:14 -07:00
|
|
|
seencname = true;
|
2000-12-11 20:53:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-01-18 23:46:58 +00:00
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
result = dns_message_nextname(rcvmsg, section);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
2000-12-11 20:53:25 +00:00
|
|
|
if (soaset == NULL && !seencname) {
|
2000-06-30 01:56:14 +00:00
|
|
|
pass++;
|
|
|
|
goto lookforsoa;
|
|
|
|
}
|
2000-06-16 17:10:02 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (seencname) {
|
2004-09-16 02:10:42 +00:00
|
|
|
goto droplabel;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-12-11 20:53:25 +00:00
|
|
|
|
2000-06-16 17:10:02 +00:00
|
|
|
if (debugging) {
|
2000-08-09 00:09:36 +00:00
|
|
|
char namestr[DNS_NAME_FORMATSIZE];
|
2000-06-30 01:56:14 +00:00
|
|
|
dns_name_format(name, namestr, sizeof(namestr));
|
2000-07-09 06:25:49 +00:00
|
|
|
fprintf(stderr, "Found zone name: %s\n", namestr);
|
2000-06-16 17:10:02 +00:00
|
|
|
}
|
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
result = dns_rdataset_first(soaset);
|
2000-06-10 00:50:36 +00:00
|
|
|
check_result(result, "dns_rdataset_first");
|
2000-06-30 01:56:14 +00:00
|
|
|
|
|
|
|
dns_rdata_init(&soarr);
|
|
|
|
dns_rdataset_current(soaset, &soarr);
|
|
|
|
result = dns_rdata_tostruct(&soarr, &soa, NULL);
|
2000-06-10 00:50:36 +00:00
|
|
|
check_result(result, "dns_rdata_tostruct");
|
2000-06-30 01:56:14 +00:00
|
|
|
|
2021-10-05 11:28:24 +02:00
|
|
|
dns_name_init(&primary, NULL);
|
|
|
|
dns_name_clone(&soa.origin, &primary);
|
2000-07-04 02:33:29 +00:00
|
|
|
|
2017-10-26 00:29:52 +11:00
|
|
|
if (userzone != NULL) {
|
2015-01-20 13:29:18 -08:00
|
|
|
zname = userzone;
|
2017-10-26 00:29:52 +11:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Save the zone name in case we need to try a second
|
|
|
|
* address.
|
|
|
|
*/
|
2018-03-28 14:38:09 +02:00
|
|
|
zname = dns_fixedname_initname(&fzname);
|
2021-05-21 17:20:44 -07:00
|
|
|
dns_name_copy(name, zname);
|
2017-10-26 00:29:52 +11:00
|
|
|
}
|
2000-06-30 01:56:14 +00:00
|
|
|
|
2000-06-16 17:10:02 +00:00
|
|
|
if (debugging) {
|
2000-08-09 00:09:36 +00:00
|
|
|
char namestr[DNS_NAME_FORMATSIZE];
|
2021-10-05 11:28:24 +02:00
|
|
|
dns_name_format(&primary, namestr, sizeof(namestr));
|
|
|
|
fprintf(stderr, "The primary is: %s\n", namestr);
|
2000-07-05 23:24:18 +00:00
|
|
|
}
|
|
|
|
|
2014-12-05 18:26:38 +11:00
|
|
|
if (default_servers) {
|
2020-02-13 14:44:37 -08:00
|
|
|
char serverstr[DNS_NAME_MAXTEXT + 1];
|
2000-07-05 23:24:18 +00:00
|
|
|
isc_buffer_t buf;
|
2020-02-13 14:44:37 -08:00
|
|
|
size_t size;
|
2000-07-05 23:24:18 +00:00
|
|
|
|
|
|
|
isc_buffer_init(&buf, serverstr, sizeof(serverstr));
|
2021-10-05 11:28:24 +02:00
|
|
|
result = dns_name_totext(&primary, true, &buf);
|
2000-07-05 23:24:18 +00:00
|
|
|
check_result(result, "dns_name_totext");
|
|
|
|
serverstr[isc_buffer_usedlength(&buf)] = 0;
|
2014-02-11 21:29:10 -08:00
|
|
|
|
2021-10-05 11:28:24 +02:00
|
|
|
if (primary_servers != NULL && primary_servers != servers) {
|
|
|
|
isc_mem_put(gmctx, primary_servers,
|
|
|
|
primary_alloc * sizeof(isc_sockaddr_t));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2021-10-05 11:28:24 +02:00
|
|
|
primary_alloc = MAX_SERVERADDRS;
|
|
|
|
size = primary_alloc * sizeof(isc_sockaddr_t);
|
|
|
|
primary_servers = isc_mem_get(gmctx, size);
|
2014-02-11 21:29:10 -08:00
|
|
|
|
2021-10-05 11:28:24 +02:00
|
|
|
memset(primary_servers, 0, size);
|
|
|
|
primary_total = get_addresses(serverstr, dnsport,
|
|
|
|
primary_servers, primary_alloc);
|
|
|
|
if (primary_total == 0) {
|
2017-06-12 11:16:18 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
2021-10-05 11:28:24 +02:00
|
|
|
primary_inuse = 0;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2021-10-05 11:28:24 +02:00
|
|
|
primary_from_servers();
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2004-09-16 02:10:42 +00:00
|
|
|
dns_rdata_freestruct(&soa);
|
2000-06-16 17:10:02 +00:00
|
|
|
|
2018-08-07 16:46:53 +02:00
|
|
|
#if HAVE_GSSAPI
|
2006-12-04 01:54:53 +00:00
|
|
|
if (usegsstsig) {
|
|
|
|
dns_name_init(&tmpzonename, NULL);
|
2015-01-20 13:29:18 -08:00
|
|
|
dns_name_dup(zname, gmctx, &tmpzonename);
|
2021-10-05 11:28:24 +02:00
|
|
|
dns_name_init(&restart_primary, NULL);
|
|
|
|
dns_name_dup(&primary, gmctx, &restart_primary);
|
|
|
|
start_gssrequest(&primary);
|
2006-12-04 01:54:53 +00:00
|
|
|
} else {
|
2021-10-05 11:28:24 +02:00
|
|
|
send_update(zname, &primary_servers[primary_inuse]);
|
2006-12-04 01:54:53 +00:00
|
|
|
setzoneclass(dns_rdataclass_none);
|
|
|
|
}
|
2018-08-07 16:46:53 +02:00
|
|
|
#else /* HAVE_GSSAPI */
|
2021-10-05 11:28:24 +02:00
|
|
|
send_update(zname, &primary_servers[primary_inuse]);
|
2004-09-16 02:10:42 +00:00
|
|
|
setzoneclass(dns_rdataclass_none);
|
2018-08-07 16:46:53 +02:00
|
|
|
#endif /* HAVE_GSSAPI */
|
2000-07-04 02:33:29 +00:00
|
|
|
|
2020-09-21 16:16:15 -03:00
|
|
|
dns_message_detach(&soaquery);
|
2000-12-11 20:53:25 +00:00
|
|
|
dns_request_destroy(&request);
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
out:
|
2020-09-21 16:16:15 -03:00
|
|
|
dns_message_detach(&rcvmsg);
|
2000-07-05 23:24:18 +00:00
|
|
|
ddebug("Out of recvsoa");
|
2004-09-16 02:10:42 +00:00
|
|
|
return;
|
2008-01-18 23:46:58 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
droplabel:
|
2004-09-16 02:10:42 +00:00
|
|
|
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);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (nlabels == 1) {
|
2004-09-16 02:10:42 +00:00
|
|
|
fatal("could not find enclosing zone");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2004-09-16 02:10:42 +00:00
|
|
|
dns_name_init(&tname, NULL);
|
|
|
|
dns_name_getlabelsequence(name, 1, nlabels - 1, &tname);
|
|
|
|
dns_name_clone(&tname, name);
|
|
|
|
dns_request_destroy(&request);
|
|
|
|
dns_message_renderreset(soaquery);
|
2005-03-16 01:02:33 +00:00
|
|
|
dns_message_settsigkey(soaquery, NULL);
|
2014-12-05 18:26:38 +11:00
|
|
|
sendrequest(&servers[ns_inuse], soaquery, &request);
|
2004-09-16 02:10:42 +00:00
|
|
|
goto out;
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-12-05 18:26:38 +11:00
|
|
|
sendrequest(isc_sockaddr_t *destaddr, dns_message_t *msg,
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_request_t **request) {
|
|
|
|
isc_result_t result;
|
2000-07-05 23:24:18 +00:00
|
|
|
nsu_requestinfo_t *reqinfo;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_sockaddr_t *srcaddr;
|
2000-07-05 23:24:18 +00:00
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
reqinfo = isc_mem_get(gmctx, sizeof(nsu_requestinfo_t));
|
2000-07-05 23:24:18 +00:00
|
|
|
reqinfo->msg = msg;
|
2000-11-16 05:40:25 +00:00
|
|
|
reqinfo->addr = destaddr;
|
2014-12-05 18:26:38 +11:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (isc_sockaddr_pf(destaddr) == AF_INET6) {
|
2014-12-05 18:26:38 +11:00
|
|
|
srcaddr = localaddr6;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2014-12-05 18:26:38 +11:00
|
|
|
srcaddr = localaddr4;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-12-05 18:26:38 +11:00
|
|
|
|
2018-04-03 15:12:27 +02:00
|
|
|
result = dns_request_createvia(requestmgr, msg, srcaddr, destaddr, -1,
|
|
|
|
0, default_servers ? NULL : tsigkey,
|
|
|
|
FIND_TIMEOUT * 20, FIND_TIMEOUT, 3,
|
|
|
|
global_task, recvsoa, reqinfo, request);
|
|
|
|
check_result(result, "dns_request_createvia");
|
2001-04-13 01:32:14 +00:00
|
|
|
requests++;
|
2000-06-30 01:56:14 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 16:46:53 +02:00
|
|
|
#if HAVE_GSSAPI
|
2010-12-24 02:20:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the realm from the users kerberos ticket if possible
|
|
|
|
*/
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
get_ticket_realm(isc_mem_t *mctx) {
|
|
|
|
krb5_context ctx;
|
2010-12-24 02:20:47 +00:00
|
|
|
krb5_error_code rc;
|
2020-02-13 14:44:37 -08:00
|
|
|
krb5_ccache ccache;
|
|
|
|
krb5_principal princ;
|
|
|
|
char *name;
|
|
|
|
const char *ticket_realm;
|
2010-12-24 23:47:05 +00:00
|
|
|
|
2010-12-24 02:20:47 +00:00
|
|
|
rc = krb5_init_context(&ctx);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (rc != 0) {
|
2010-12-24 02:20:47 +00:00
|
|
|
return;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2010-12-24 02:20:47 +00:00
|
|
|
|
|
|
|
rc = krb5_cc_default(ctx, &ccache);
|
|
|
|
if (rc != 0) {
|
|
|
|
krb5_free_context(ctx);
|
|
|
|
return;
|
|
|
|
}
|
2010-12-24 23:47:05 +00:00
|
|
|
|
2010-12-24 02:20:47 +00:00
|
|
|
rc = krb5_cc_get_principal(ctx, ccache, &princ);
|
|
|
|
if (rc != 0) {
|
|
|
|
krb5_cc_close(ctx, ccache);
|
|
|
|
krb5_free_context(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = krb5_unparse_name(ctx, princ, &name);
|
|
|
|
if (rc != 0) {
|
|
|
|
krb5_free_principal(ctx, princ);
|
|
|
|
krb5_cc_close(ctx, ccache);
|
|
|
|
krb5_free_context(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ticket_realm = strrchr(name, '@');
|
|
|
|
if (ticket_realm != NULL) {
|
|
|
|
realm = isc_mem_strdup(mctx, ticket_realm);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(name);
|
|
|
|
krb5_free_principal(ctx, princ);
|
|
|
|
krb5_cc_close(ctx, ccache);
|
|
|
|
krb5_free_context(ctx);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (realm != NULL && debugging) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr, "Found realm from ticket: %s\n", realm + 1);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2010-12-24 02:20:47 +00:00
|
|
|
}
|
|
|
|
|
2015-09-18 09:52:27 +10:00
|
|
|
static void
|
2018-08-07 16:46:53 +02:00
|
|
|
failed_gssrequest(void) {
|
2018-04-17 08:29:14 -07:00
|
|
|
seenerror = true;
|
2015-09-18 09:52:27 +10:00
|
|
|
|
|
|
|
dns_name_free(&tmpzonename, gmctx);
|
2021-10-05 11:28:24 +02:00
|
|
|
dns_name_free(&restart_primary, gmctx);
|
2018-11-14 15:17:48 +11:00
|
|
|
dns_name_init(&tmpzonename, NULL);
|
2021-10-05 11:28:24 +02:00
|
|
|
dns_name_init(&restart_primary, NULL);
|
2015-09-18 09:52:27 +10:00
|
|
|
|
|
|
|
done_update();
|
|
|
|
}
|
2010-12-24 02:20:47 +00:00
|
|
|
|
2006-12-04 01:54:53 +00:00
|
|
|
static void
|
2021-10-05 11:28:24 +02:00
|
|
|
start_gssrequest(dns_name_t *primary) {
|
2021-02-11 14:40:59 +01:00
|
|
|
dns_gss_ctx_id_t context;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_buffer_t buf;
|
|
|
|
isc_result_t result;
|
|
|
|
uint32_t val = 0;
|
|
|
|
dns_message_t *rmsg = NULL;
|
|
|
|
dns_request_t *request = NULL;
|
|
|
|
dns_name_t *servname;
|
2006-12-04 01:54:53 +00:00
|
|
|
dns_fixedname_t fname;
|
2020-02-13 14:44:37 -08:00
|
|
|
char namestr[DNS_NAME_FORMATSIZE];
|
|
|
|
char mykeystr[DNS_NAME_FORMATSIZE];
|
|
|
|
char *err_message = NULL;
|
2006-12-04 01:54:53 +00:00
|
|
|
|
|
|
|
debug("start_gssrequest");
|
2018-04-17 08:29:14 -07:00
|
|
|
usevc = true;
|
2006-12-04 01:54:53 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (gssring != NULL) {
|
2011-01-10 05:32:04 +00:00
|
|
|
dns_tsigkeyring_detach(&gssring);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2006-12-04 01:54:53 +00:00
|
|
|
gssring = NULL;
|
2015-01-20 13:29:18 -08:00
|
|
|
result = dns_tsigkeyring_create(gmctx, &gssring);
|
2008-01-18 23:46:58 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2007-09-14 06:43:12 +00:00
|
|
|
fatal("dns_tsigkeyring_create failed: %s",
|
|
|
|
isc_result_totext(result));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2006-12-04 01:54:53 +00:00
|
|
|
|
2021-10-05 11:28:24 +02:00
|
|
|
dns_name_format(primary, namestr, sizeof(namestr));
|
2006-12-04 01:54:53 +00:00
|
|
|
if (kserver == NULL) {
|
2015-01-20 13:29:18 -08:00
|
|
|
kserver = isc_mem_get(gmctx, sizeof(isc_sockaddr_t));
|
2006-12-04 01:54:53 +00:00
|
|
|
}
|
2017-04-20 09:28:37 -07:00
|
|
|
|
2021-10-05 11:28:24 +02:00
|
|
|
memmove(kserver, &primary_servers[primary_inuse],
|
|
|
|
sizeof(isc_sockaddr_t));
|
2006-12-04 01:54:53 +00:00
|
|
|
|
2018-03-28 14:38:09 +02:00
|
|
|
servname = dns_fixedname_initname(&fname);
|
2006-12-04 01:54:53 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (realm == NULL) {
|
2015-01-20 13:29:18 -08:00
|
|
|
get_ticket_realm(gmctx);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2010-12-24 02:20:47 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
result = snprintf(servicename, sizeof(servicename), "DNS/%s%s", namestr,
|
|
|
|
realm ? realm : "");
|
2018-03-21 16:38:29 +00:00
|
|
|
RUNTIME_CHECK(result < sizeof(servicename));
|
2006-12-04 01:54:53 +00:00
|
|
|
isc_buffer_init(&buf, servicename, strlen(servicename));
|
|
|
|
isc_buffer_add(&buf, strlen(servicename));
|
2009-09-01 00:22:28 +00:00
|
|
|
result = dns_name_fromtext(servname, &buf, dns_rootname, 0, NULL);
|
2018-03-21 16:38:29 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2007-09-14 06:43:12 +00:00
|
|
|
fatal("dns_name_fromtext(servname) failed: %s",
|
|
|
|
isc_result_totext(result));
|
2018-03-21 16:38:29 +00:00
|
|
|
}
|
2008-01-18 23:46:58 +00:00
|
|
|
|
2018-03-28 14:38:09 +02:00
|
|
|
keyname = dns_fixedname_initname(&fkname);
|
2006-12-04 01:54:53 +00:00
|
|
|
|
2018-05-28 15:22:23 +02:00
|
|
|
isc_nonce_buf(&val, sizeof(val));
|
2018-03-21 16:38:29 +00:00
|
|
|
|
2020-02-13 14:44:37 -08:00
|
|
|
result = snprintf(mykeystr, sizeof(mykeystr), "%u.sig-%s", val,
|
|
|
|
namestr);
|
2018-03-21 16:38:29 +00:00
|
|
|
RUNTIME_CHECK(result <= sizeof(mykeystr));
|
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
isc_buffer_init(&buf, mykeystr, strlen(mykeystr));
|
|
|
|
isc_buffer_add(&buf, strlen(mykeystr));
|
2006-12-04 01:54:53 +00:00
|
|
|
|
2009-09-01 00:22:28 +00:00
|
|
|
result = dns_name_fromtext(keyname, &buf, dns_rootname, 0, NULL);
|
2018-03-21 16:38:29 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2007-09-14 06:43:12 +00:00
|
|
|
fatal("dns_name_fromtext(keyname) failed: %s",
|
|
|
|
isc_result_totext(result));
|
2018-03-21 16:38:29 +00:00
|
|
|
}
|
2006-12-04 01:54:53 +00:00
|
|
|
|
|
|
|
/* Windows doesn't recognize name compression in the key name. */
|
|
|
|
keyname->attributes |= DNS_NAMEATTR_NOCOMPRESS;
|
|
|
|
|
|
|
|
rmsg = NULL;
|
2020-09-25 11:51:36 +02:00
|
|
|
dns_message_create(gmctx, DNS_MESSAGE_INTENTRENDER, &rmsg);
|
2006-12-04 01:54:53 +00:00
|
|
|
|
|
|
|
/* Build first request. */
|
|
|
|
context = GSS_C_NO_CONTEXT;
|
|
|
|
result = dns_tkey_buildgssquery(rmsg, keyname, servname, NULL, 0,
|
2020-02-12 13:59:18 +01:00
|
|
|
&context, use_win2k_gsstsig, gmctx,
|
|
|
|
&err_message);
|
2015-09-18 09:52:27 +10:00
|
|
|
if (result == ISC_R_FAILURE) {
|
|
|
|
fprintf(stderr, "tkey query failed: %s\n",
|
|
|
|
err_message != NULL ? err_message : "unknown error");
|
|
|
|
goto failure;
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2007-09-14 06:43:12 +00:00
|
|
|
fatal("dns_tkey_buildgssquery failed: %s",
|
|
|
|
isc_result_totext(result));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2006-12-04 01:54:53 +00:00
|
|
|
|
2014-12-05 18:26:38 +11:00
|
|
|
send_gssrequest(kserver, rmsg, &request, context);
|
2015-09-18 09:52:27 +10:00
|
|
|
return;
|
|
|
|
|
|
|
|
failure:
|
2020-02-13 21:48:23 +01:00
|
|
|
if (rmsg != NULL) {
|
2020-09-21 16:16:15 -03:00
|
|
|
dns_message_detach(&rmsg);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (err_message != NULL) {
|
2015-09-18 09:52:27 +10:00
|
|
|
isc_mem_free(gmctx, err_message);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-09-18 09:52:27 +10:00
|
|
|
failed_gssrequest();
|
2006-12-04 01:54:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-12-05 18:26:38 +11:00
|
|
|
send_gssrequest(isc_sockaddr_t *destaddr, dns_message_t *msg,
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_request_t **request, gss_ctx_id_t context) {
|
|
|
|
isc_result_t result;
|
|
|
|
nsu_gssinfo_t *reqinfo;
|
|
|
|
unsigned int options = 0;
|
2014-12-05 18:26:38 +11:00
|
|
|
isc_sockaddr_t *srcaddr;
|
2006-12-04 01:54:53 +00:00
|
|
|
|
|
|
|
debug("send_gssrequest");
|
2020-03-27 21:03:40 +01:00
|
|
|
REQUIRE(destaddr != NULL);
|
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
reqinfo = isc_mem_get(gmctx, sizeof(nsu_gssinfo_t));
|
2006-12-04 01:54:53 +00:00
|
|
|
reqinfo->msg = msg;
|
|
|
|
reqinfo->addr = destaddr;
|
|
|
|
reqinfo->context = context;
|
|
|
|
|
|
|
|
options |= DNS_REQUESTOPT_TCP;
|
2014-12-05 18:26:38 +11:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (isc_sockaddr_pf(destaddr) == AF_INET6) {
|
2014-12-05 18:26:38 +11:00
|
|
|
srcaddr = localaddr6;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2014-12-05 18:26:38 +11:00
|
|
|
srcaddr = localaddr4;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-12-05 18:26:38 +11:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_request_createvia(requestmgr, msg, srcaddr, destaddr, -1,
|
|
|
|
options, tsigkey, FIND_TIMEOUT * 20,
|
2018-04-03 15:12:27 +02:00
|
|
|
FIND_TIMEOUT, 3, global_task, recvgss,
|
|
|
|
reqinfo, request);
|
|
|
|
check_result(result, "dns_request_createvia");
|
2020-02-13 21:48:23 +01:00
|
|
|
if (debugging) {
|
2006-12-04 01:54:53 +00:00
|
|
|
show_message(stdout, msg, "Outgoing update query:");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2006-12-04 01:54:53 +00:00
|
|
|
requests++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
recvgss(isc_task_t *task, isc_event_t *event) {
|
2006-12-04 01:54:53 +00:00
|
|
|
dns_requestevent_t *reqev = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_request_t *request = NULL;
|
|
|
|
isc_result_t result, eresult;
|
|
|
|
dns_message_t *rcvmsg = NULL;
|
|
|
|
nsu_gssinfo_t *reqinfo;
|
|
|
|
dns_message_t *tsigquery = NULL;
|
|
|
|
isc_sockaddr_t *addr;
|
2021-02-11 14:40:59 +01:00
|
|
|
dns_gss_ctx_id_t context;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_buffer_t buf;
|
|
|
|
dns_name_t *servname;
|
|
|
|
dns_fixedname_t fname;
|
|
|
|
char *err_message = NULL;
|
2006-12-04 01:54:53 +00:00
|
|
|
|
|
|
|
UNUSED(task);
|
|
|
|
|
|
|
|
ddebug("recvgss()");
|
|
|
|
|
|
|
|
requests--;
|
2008-01-18 23:46:58 +00:00
|
|
|
|
2006-12-04 01:54:53 +00:00
|
|
|
REQUIRE(event->ev_type == DNS_EVENT_REQUESTDONE);
|
|
|
|
reqev = (dns_requestevent_t *)event;
|
|
|
|
request = reqev->request;
|
|
|
|
eresult = reqev->result;
|
|
|
|
reqinfo = reqev->ev_arg;
|
|
|
|
tsigquery = reqinfo->msg;
|
|
|
|
context = reqinfo->context;
|
|
|
|
addr = reqinfo->addr;
|
|
|
|
|
|
|
|
if (shuttingdown) {
|
|
|
|
dns_request_destroy(&request);
|
2020-09-21 16:16:15 -03:00
|
|
|
dns_message_detach(&tsigquery);
|
2015-01-20 13:29:18 -08:00
|
|
|
isc_mem_put(gmctx, reqinfo, sizeof(nsu_gssinfo_t));
|
2006-12-04 01:54:53 +00:00
|
|
|
isc_event_free(&event);
|
|
|
|
maybeshutdown();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eresult != ISC_R_SUCCESS) {
|
|
|
|
ddebug("Destroying request [%p]", request);
|
|
|
|
dns_request_destroy(&request);
|
2021-10-05 11:28:24 +02:00
|
|
|
if (!next_primary("recvgss", addr, eresult)) {
|
2020-09-21 16:16:15 -03:00
|
|
|
dns_message_detach(&tsigquery);
|
2017-06-14 13:09:26 +02:00
|
|
|
failed_gssrequest();
|
|
|
|
} else {
|
|
|
|
dns_message_renderreset(tsigquery);
|
2021-10-05 11:28:24 +02:00
|
|
|
memmove(kserver, &primary_servers[primary_inuse],
|
2017-06-14 13:09:26 +02:00
|
|
|
sizeof(isc_sockaddr_t));
|
|
|
|
send_gssrequest(kserver, tsigquery, &request, context);
|
|
|
|
}
|
2015-01-20 13:29:18 -08:00
|
|
|
isc_mem_put(gmctx, reqinfo, sizeof(nsu_gssinfo_t));
|
2006-12-04 01:54:53 +00:00
|
|
|
isc_event_free(&event);
|
|
|
|
return;
|
|
|
|
}
|
2015-01-20 13:29:18 -08:00
|
|
|
isc_mem_put(gmctx, reqinfo, sizeof(nsu_gssinfo_t));
|
2006-12-04 01:54:53 +00:00
|
|
|
|
|
|
|
isc_event_free(&event);
|
|
|
|
reqev = NULL;
|
|
|
|
|
|
|
|
ddebug("recvgss creating rcvmsg");
|
2020-09-25 11:51:36 +02:00
|
|
|
dns_message_create(gmctx, DNS_MESSAGE_INTENTPARSE, &rcvmsg);
|
2006-12-04 01:54:53 +00:00
|
|
|
|
|
|
|
result = dns_request_getresponse(request, rcvmsg,
|
|
|
|
DNS_MESSAGEPARSE_PRESERVEORDER);
|
|
|
|
check_result(result, "dns_request_getresponse");
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (debugging) {
|
2006-12-04 01:54:53 +00:00
|
|
|
show_message(stderr, rcvmsg,
|
|
|
|
"recvmsg reply from GSS-TSIG query");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2006-12-04 01:54:53 +00:00
|
|
|
|
2021-06-11 16:58:15 +10:00
|
|
|
if (rcvmsg->opcode != dns_opcode_query) {
|
|
|
|
fatal("invalid OPCODE in response to GSS-TSIG query");
|
|
|
|
}
|
|
|
|
|
2006-12-04 01:54:53 +00:00
|
|
|
if (rcvmsg->rcode == dns_rcode_formerr && !tried_other_gsstsig) {
|
|
|
|
ddebug("recvgss trying %s GSS-TSIG",
|
|
|
|
use_win2k_gsstsig ? "Standard" : "Win2k");
|
2020-02-13 21:48:23 +01:00
|
|
|
if (use_win2k_gsstsig) {
|
2018-04-17 08:29:14 -07:00
|
|
|
use_win2k_gsstsig = false;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2018-04-17 08:29:14 -07:00
|
|
|
use_win2k_gsstsig = true;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2018-04-17 08:29:14 -07:00
|
|
|
tried_other_gsstsig = true;
|
2021-10-05 11:28:24 +02:00
|
|
|
start_gssrequest(&restart_primary);
|
2006-12-04 01:54:53 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rcvmsg->rcode != dns_rcode_noerror &&
|
2020-02-13 21:48:23 +01:00
|
|
|
rcvmsg->rcode != dns_rcode_nxdomain) {
|
2006-12-04 01:54:53 +00:00
|
|
|
fatal("response to GSS-TSIG query was unsuccessful");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2006-12-04 01:54:53 +00:00
|
|
|
|
2018-03-28 14:38:09 +02:00
|
|
|
servname = dns_fixedname_initname(&fname);
|
2006-12-04 01:54:53 +00:00
|
|
|
isc_buffer_init(&buf, servicename, strlen(servicename));
|
|
|
|
isc_buffer_add(&buf, strlen(servicename));
|
2009-09-01 00:22:28 +00:00
|
|
|
result = dns_name_fromtext(servname, &buf, dns_rootname, 0, NULL);
|
2006-12-04 01:54:53 +00:00
|
|
|
check_result(result, "dns_name_fromtext");
|
|
|
|
|
|
|
|
tsigkey = NULL;
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_tkey_gssnegotiate(tsigquery, rcvmsg, servname, &context,
|
|
|
|
&tsigkey, gssring, use_win2k_gsstsig,
|
|
|
|
&err_message);
|
2006-12-04 01:54:53 +00:00
|
|
|
switch (result) {
|
|
|
|
case DNS_R_CONTINUE:
|
2020-09-21 16:16:15 -03:00
|
|
|
dns_message_detach(&rcvmsg);
|
2016-07-14 15:06:28 +10:00
|
|
|
dns_request_destroy(&request);
|
2014-12-05 18:26:38 +11:00
|
|
|
send_gssrequest(kserver, tsigquery, &request, context);
|
2016-07-14 15:06:28 +10:00
|
|
|
ddebug("Out of recvgss");
|
|
|
|
return;
|
2006-12-04 01:54:53 +00:00
|
|
|
|
|
|
|
case ISC_R_SUCCESS:
|
|
|
|
/*
|
|
|
|
* XXXSRA Waaay too much fun here. There's no good
|
|
|
|
* reason why we need a TSIG here (the people who put
|
|
|
|
* it into the spec admitted at the time that it was
|
|
|
|
* not a security issue), and Windows clients don't
|
|
|
|
* seem to work if named complies with the spec and
|
|
|
|
* includes the gratuitous TSIG. So we're in the
|
2009-01-17 11:04:25 +00:00
|
|
|
* bizarre situation of having to choose between
|
2006-12-04 01:54:53 +00:00
|
|
|
* complying with a useless requirement in the spec
|
|
|
|
* and interoperating. This is nuts. If we can
|
|
|
|
* confirm this behavior, we should ask the WG to
|
|
|
|
* consider removing the requirement for the
|
|
|
|
* gratuitous TSIG here. For the moment, we ignore
|
|
|
|
* the TSIG -- this too is a spec violation, but it's
|
|
|
|
* the least insane thing to do.
|
|
|
|
*/
|
|
|
|
#if 0
|
|
|
|
/*
|
2008-01-18 23:46:58 +00:00
|
|
|
* Verify the signature.
|
2006-12-04 01:54:53 +00:00
|
|
|
*/
|
|
|
|
rcvmsg->state = DNS_SECTION_ANY;
|
|
|
|
dns_message_setquerytsig(rcvmsg, NULL);
|
|
|
|
result = dns_message_settsigkey(rcvmsg, tsigkey);
|
|
|
|
check_result(result, "dns_message_settsigkey");
|
|
|
|
result = dns_message_checksig(rcvmsg, NULL);
|
2021-10-04 17:14:53 +02:00
|
|
|
ddebug("tsig verification: %s", isc_result_totext(result));
|
2006-12-04 01:54:53 +00:00
|
|
|
check_result(result, "dns_message_checksig");
|
|
|
|
#endif /* 0 */
|
|
|
|
|
2021-10-05 11:28:24 +02:00
|
|
|
send_update(&tmpzonename, &primary_servers[primary_inuse]);
|
2006-12-04 01:54:53 +00:00
|
|
|
setzoneclass(dns_rdataclass_none);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-02-12 13:59:18 +01:00
|
|
|
fatal("dns_tkey_gssnegotiate: %s %s", isc_result_totext(result),
|
2010-12-18 01:56:23 +00:00
|
|
|
err_message != NULL ? err_message : "");
|
2006-12-04 01:54:53 +00:00
|
|
|
}
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
done:
|
2006-12-04 01:54:53 +00:00
|
|
|
dns_request_destroy(&request);
|
2020-09-21 16:16:15 -03:00
|
|
|
dns_message_detach(&tsigquery);
|
2006-12-04 01:54:53 +00:00
|
|
|
|
2020-09-21 16:16:15 -03:00
|
|
|
dns_message_detach(&rcvmsg);
|
2006-12-04 01:54:53 +00:00
|
|
|
ddebug("Out of recvgss");
|
|
|
|
}
|
2018-08-07 16:46:53 +02:00
|
|
|
#endif /* HAVE_GSSAPI */
|
2006-12-04 01:54:53 +00:00
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
start_update(void) {
|
|
|
|
isc_result_t result;
|
2000-06-10 00:50:36 +00:00
|
|
|
dns_rdataset_t *rdataset = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_name_t *name = NULL;
|
|
|
|
dns_request_t *request = NULL;
|
|
|
|
dns_message_t *soaquery = NULL;
|
|
|
|
dns_name_t *firstname;
|
|
|
|
dns_section_t section = DNS_SECTION_UPDATE;
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-07-05 23:24:18 +00:00
|
|
|
ddebug("start_update()");
|
|
|
|
|
2020-05-19 13:25:41 +10:00
|
|
|
LOCK(&answer_lock);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (answer != NULL) {
|
2020-09-21 16:16:15 -03:00
|
|
|
dns_message_detach(&answer);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2020-05-19 13:25:41 +10:00
|
|
|
UNLOCK(&answer_lock);
|
2000-06-30 03:24:27 +00:00
|
|
|
|
2014-12-05 18:26:38 +11:00
|
|
|
/*
|
|
|
|
* If we have both the zone and the servers we have enough information
|
|
|
|
* to send the update straight away otherwise we need to discover
|
2021-10-05 11:07:44 +02:00
|
|
|
* the zone and / or the primary server.
|
2014-12-05 18:26:38 +11:00
|
|
|
*/
|
|
|
|
if (userzone != NULL && !default_servers && !usegsstsig) {
|
2021-10-05 11:28:24 +02:00
|
|
|
primary_from_servers();
|
|
|
|
send_update(userzone, &primary_servers[primary_inuse]);
|
2004-03-03 23:43:09 +00:00
|
|
|
setzoneclass(dns_rdataclass_none);
|
2001-07-11 06:30:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-25 11:51:36 +02:00
|
|
|
dns_message_create(gmctx, DNS_MESSAGE_INTENTRENDER, &soaquery);
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (default_servers) {
|
2006-12-07 05:39:41 +00:00
|
|
|
soaquery->flags |= DNS_MESSAGEFLAG_RD;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-06-16 17:10:02 +00:00
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
result = dns_message_gettempname(soaquery, &name);
|
2000-06-10 00:50:36 +00:00
|
|
|
check_result(result, "dns_message_gettempname");
|
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
result = dns_message_gettemprdataset(soaquery, &rdataset);
|
2000-06-10 00:50:36 +00:00
|
|
|
check_result(result, "dns_message_gettemprdataset");
|
|
|
|
|
2004-03-03 23:43:09 +00:00
|
|
|
dns_rdataset_makequestion(rdataset, getzoneclass(), dns_rdatatype_soa);
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2006-12-07 05:39:41 +00:00
|
|
|
if (userzone != NULL) {
|
|
|
|
dns_name_clone(userzone, name);
|
|
|
|
} else {
|
2010-05-18 06:18:23 +00:00
|
|
|
dns_rdataset_t *tmprdataset;
|
2006-12-07 05:39:41 +00:00
|
|
|
result = dns_message_firstname(updatemsg, section);
|
|
|
|
if (result == ISC_R_NOMORE) {
|
|
|
|
section = DNS_SECTION_PREREQUISITE;
|
|
|
|
result = dns_message_firstname(updatemsg, section);
|
|
|
|
}
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2007-02-28 23:57:39 +00:00
|
|
|
dns_message_puttempname(soaquery, &name);
|
|
|
|
dns_rdataset_disassociate(rdataset);
|
|
|
|
dns_message_puttemprdataset(soaquery, &rdataset);
|
2020-09-21 16:16:15 -03:00
|
|
|
dns_message_detach(&soaquery);
|
2006-12-07 05:39:41 +00:00
|
|
|
done_update();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
firstname = NULL;
|
|
|
|
dns_message_currentname(updatemsg, section, &firstname);
|
|
|
|
dns_name_clone(firstname, name);
|
2010-03-09 03:46:12 +00:00
|
|
|
/*
|
|
|
|
* Looks to see if the first name references a DS record
|
|
|
|
* and if that name is not the root remove a label as DS
|
|
|
|
* records live in the parent zone so we need to start our
|
|
|
|
* search one label up.
|
|
|
|
*/
|
2010-05-18 06:18:23 +00:00
|
|
|
tmprdataset = ISC_LIST_HEAD(firstname->list);
|
2010-03-09 03:46:12 +00:00
|
|
|
if (section == DNS_SECTION_UPDATE &&
|
|
|
|
!dns_name_equal(firstname, dns_rootname) &&
|
2020-02-13 14:44:37 -08:00
|
|
|
tmprdataset->type == dns_rdatatype_ds)
|
|
|
|
{
|
2020-02-12 13:59:18 +01:00
|
|
|
unsigned int labels = dns_name_countlabels(name);
|
|
|
|
dns_name_getlabelsequence(name, 1, labels - 1, name);
|
2010-03-09 03:46:12 +00:00
|
|
|
}
|
2006-12-07 05:39:41 +00:00
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
|
|
|
|
ISC_LIST_INIT(name->list);
|
|
|
|
ISC_LIST_APPEND(name->list, rdataset, link);
|
2000-06-30 01:56:14 +00:00
|
|
|
dns_message_addname(soaquery, name, DNS_SECTION_QUESTION);
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2014-02-11 21:29:10 -08:00
|
|
|
ns_inuse = 0;
|
2014-12-05 18:26:38 +11:00
|
|
|
sendrequest(&servers[ns_inuse], soaquery, &request);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
cleanup(void) {
|
2000-07-09 16:17:13 +00:00
|
|
|
ddebug("cleanup()");
|
2000-06-17 00:16:50 +00:00
|
|
|
|
2020-05-19 13:25:41 +10:00
|
|
|
LOCK(&answer_lock);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (answer != NULL) {
|
2020-09-21 16:16:15 -03:00
|
|
|
dns_message_detach(&answer);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2020-05-19 13:25:41 +10:00
|
|
|
UNLOCK(&answer_lock);
|
2006-12-04 01:54:53 +00:00
|
|
|
|
2018-08-07 16:46:53 +02:00
|
|
|
#if HAVE_GSSAPI
|
2007-09-14 06:43:12 +00:00
|
|
|
if (tsigkey != NULL) {
|
|
|
|
ddebug("detach tsigkey x%p", tsigkey);
|
|
|
|
dns_tsigkey_detach(&tsigkey);
|
|
|
|
}
|
|
|
|
if (gssring != NULL) {
|
2011-01-10 05:32:04 +00:00
|
|
|
ddebug("Detaching GSS-TSIG keyring");
|
|
|
|
dns_tsigkeyring_detach(&gssring);
|
2006-12-04 01:54:53 +00:00
|
|
|
}
|
2020-03-27 21:03:40 +01:00
|
|
|
#endif /* ifdef HAVE_GSSAPI */
|
2006-12-04 01:54:53 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (sig0key != NULL) {
|
2011-03-21 19:54:03 +00:00
|
|
|
dst_key_free(&sig0key);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2011-03-21 19:54:03 +00:00
|
|
|
|
2021-04-27 00:07:43 +02:00
|
|
|
ddebug("Shutting down managers");
|
2021-01-14 13:02:57 -08:00
|
|
|
isc_managers_destroy(&netmgr, &taskmgr, NULL, NULL);
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 11:31:19 +02:00
|
|
|
|
2000-11-22 02:54:15 +00:00
|
|
|
ddebug("Destroying event");
|
|
|
|
isc_event_free(&global_event);
|
|
|
|
|
2020-03-27 21:03:40 +01:00
|
|
|
#ifdef HAVE_GSSAPI
|
|
|
|
/*
|
|
|
|
* Cleanup GSSAPI resources after taskmgr has been destroyed.
|
|
|
|
*/
|
|
|
|
if (kserver != NULL) {
|
|
|
|
isc_mem_put(gmctx, kserver, sizeof(isc_sockaddr_t));
|
|
|
|
kserver = NULL;
|
|
|
|
}
|
|
|
|
if (realm != NULL) {
|
|
|
|
isc_mem_free(gmctx, realm);
|
|
|
|
realm = NULL;
|
|
|
|
}
|
|
|
|
if (dns_name_dynamic(&tmpzonename)) {
|
|
|
|
dns_name_free(&tmpzonename, gmctx);
|
|
|
|
}
|
2021-10-05 11:28:24 +02:00
|
|
|
if (dns_name_dynamic(&restart_primary)) {
|
|
|
|
dns_name_free(&restart_primary, gmctx);
|
2020-03-27 21:03:40 +01:00
|
|
|
}
|
|
|
|
#endif /* ifdef HAVE_GSSAPI */
|
|
|
|
|
2006-12-04 01:54:53 +00:00
|
|
|
ddebug("Removing log context");
|
2015-01-20 13:29:18 -08:00
|
|
|
isc_log_destroy(&glctx);
|
2006-12-04 01:54:53 +00:00
|
|
|
|
2000-06-17 00:16:50 +00:00
|
|
|
ddebug("Destroying memory context");
|
2020-02-13 21:48:23 +01:00
|
|
|
if (memdebugging) {
|
2015-01-20 13:29:18 -08:00
|
|
|
isc_mem_stats(gmctx, stderr);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-01-20 13:29:18 -08:00
|
|
|
isc_mem_destroy(&gmctx);
|
2020-05-19 13:25:41 +10:00
|
|
|
|
|
|
|
isc_mutex_destroy(&answer_lock);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
2000-09-01 21:34:12 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
getinput(isc_task_t *task, isc_event_t *event) {
|
2018-04-17 08:29:14 -07:00
|
|
|
bool more;
|
2000-09-01 21:34:12 +00:00
|
|
|
|
|
|
|
UNUSED(task);
|
|
|
|
|
2001-04-13 01:32:14 +00:00
|
|
|
if (shuttingdown) {
|
|
|
|
maybeshutdown();
|
2001-01-21 21:54:32 +00:00
|
|
|
return;
|
2001-04-13 01:32:14 +00:00
|
|
|
}
|
2001-01-21 21:54:32 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (global_event == NULL) {
|
2000-09-01 21:34:12 +00:00
|
|
|
global_event = event;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-09-01 21:34:12 +00:00
|
|
|
|
|
|
|
reset_system();
|
|
|
|
more = user_interaction();
|
|
|
|
if (!more) {
|
|
|
|
isc_app_shutdown();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
start_update();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
int
|
2020-02-13 14:44:37 -08:00
|
|
|
main(int argc, char **argv) {
|
2000-12-11 19:24:30 +00:00
|
|
|
isc_result_t result;
|
2001-07-22 06:11:44 +00:00
|
|
|
style = &dns_master_style_debug;
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-11-27 00:43:33 +00:00
|
|
|
input = stdin;
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
interactive = isatty(0);
|
2004-04-10 04:03:16 +00:00
|
|
|
|
2000-09-01 21:34:12 +00:00
|
|
|
isc_app_start();
|
|
|
|
|
2017-08-16 16:01:39 +02:00
|
|
|
if (isc_net_probeipv4() == ISC_R_SUCCESS) {
|
2018-04-17 08:29:14 -07:00
|
|
|
have_ipv4 = true;
|
2017-08-16 16:01:39 +02:00
|
|
|
}
|
|
|
|
if (isc_net_probeipv6() == ISC_R_SUCCESS) {
|
2018-04-17 08:29:14 -07:00
|
|
|
have_ipv6 = true;
|
2017-08-16 16:01:39 +02:00
|
|
|
}
|
|
|
|
if (!have_ipv4 && !have_ipv6) {
|
|
|
|
fatal("could not find either IPv4 or IPv6");
|
|
|
|
}
|
|
|
|
|
2007-09-15 14:46:03 +00:00
|
|
|
pre_parse_args(argc, argv);
|
|
|
|
|
2019-09-05 18:40:57 +02:00
|
|
|
isc_mem_create(&gmctx);
|
2007-09-15 14:46:03 +00:00
|
|
|
|
2018-04-22 14:56:28 +02:00
|
|
|
parse_args(argc, argv);
|
2000-06-23 20:46:25 +00:00
|
|
|
|
2000-12-11 19:24:30 +00:00
|
|
|
setup_system();
|
2000-09-01 21:34:12 +00:00
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
result = isc_app_onrun(gmctx, global_task, getinput, NULL);
|
2000-09-01 21:34:12 +00:00
|
|
|
check_result(result, "isc_app_onrun");
|
|
|
|
|
|
|
|
(void)isc_app_run();
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-12-11 19:24:30 +00:00
|
|
|
cleanup();
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-09-01 21:34:12 +00:00
|
|
|
isc_app_finish();
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (seenerror) {
|
2000-12-07 20:05:29 +00:00
|
|
|
return (2);
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2000-12-07 20:05:29 +00:00
|
|
|
return (0);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|