2000-06-10 00:50:36 +00:00
|
|
|
/*
|
2010-03-04 23:50:34 +00:00
|
|
|
* Copyright (C) 2004-2010 Internet Systems Consortium, Inc. ("ISC")
|
2004-03-05 05:14:21 +00:00
|
|
|
* Copyright (C) 2000-2003 Internet Software Consortium.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2007-06-18 23:47:57 +00:00
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
2000-06-10 00:50:36 +00:00
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2004-03-05 05:14:21 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
|
|
|
|
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
|
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
|
|
|
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
2000-06-10 00:50:36 +00:00
|
|
|
*/
|
|
|
|
|
2010-12-02 23:22:42 +00:00
|
|
|
/* $Id: nsupdate.c,v 1.183 2010/12/02 23:22:41 marka Exp $ */
|
2005-04-27 04:57:32 +00:00
|
|
|
|
|
|
|
/*! \file */
|
2000-06-10 00:50:36 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
2000-06-30 01:56:14 +00:00
|
|
|
|
2000-08-10 02:32:14 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2000-09-01 21:34:12 +00:00
|
|
|
#include <isc/app.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-06-23 20:46:25 +00:00
|
|
|
#include <isc/entropy.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>
|
2000-06-10 00:50:36 +00:00
|
|
|
#include <isc/mem.h>
|
2001-11-30 01:02:18 +00:00
|
|
|
#include <isc/parseint.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>
|
2000-06-21 17:48:32 +00:00
|
|
|
#include <isc/sockaddr.h>
|
|
|
|
#include <isc/socket.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-10 00:50:36 +00:00
|
|
|
#include <isc/timer.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
|
|
|
|
2009-06-10 00:27:22 +00:00
|
|
|
#include <isccfg/namedconf.h>
|
|
|
|
|
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>
|
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>
|
|
|
|
#include <dns/result.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
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
#include <dst/dst.h>
|
|
|
|
|
2000-06-30 21:47:35 +00:00
|
|
|
#include <lwres/lwres.h>
|
2000-07-03 20:08:13 +00:00
|
|
|
#include <lwres/net.h>
|
2000-06-30 21:47:35 +00:00
|
|
|
|
2006-12-04 01:54:53 +00:00
|
|
|
#ifdef GSSAPI
|
|
|
|
#include <dst/gssapi.h>
|
|
|
|
#endif
|
2001-11-14 22:08:38 +00:00
|
|
|
#include <bind9/getaddresses.h>
|
|
|
|
|
2006-12-04 01:54:53 +00:00
|
|
|
|
2001-01-18 22:21:31 +00:00
|
|
|
#ifdef HAVE_ADDRINFO
|
|
|
|
#ifdef HAVE_GETADDRINFO
|
|
|
|
#ifdef HAVE_GAISTRERROR
|
|
|
|
#define USE_GETADDRINFO
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2001-07-26 03:15:16 +00:00
|
|
|
#ifndef USE_GETADDRINFO
|
|
|
|
#ifndef ISC_PLATFORM_NONSTDHERRNO
|
2001-01-18 22:21:31 +00:00
|
|
|
extern int h_errno;
|
|
|
|
#endif
|
2001-07-26 03:15:16 +00:00
|
|
|
#endif
|
2001-01-18 22:21:31 +00:00
|
|
|
|
2000-09-28 16:39:49 +00:00
|
|
|
#define MAXCMD (4 * 1024)
|
2002-08-06 03:21:59 +00:00
|
|
|
#define MAXWIRE (64 * 1024)
|
2000-09-28 21:39:26 +00:00
|
|
|
#define PACKETSIZE ((64 * 1024) - 1)
|
|
|
|
#define INITTEXT (2 * 1024)
|
|
|
|
#define MAXTEXT (128 * 1024)
|
2000-06-10 00:50:36 +00:00
|
|
|
#define FIND_TIMEOUT 5
|
2003-07-25 00:01:16 +00: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
|
|
|
|
|
2009-06-10 00:27:22 +00:00
|
|
|
static isc_uint16_t dnsport = DNSDEFAULTPORT;
|
|
|
|
|
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"
|
2001-09-01 05:09:33 +00:00
|
|
|
#endif
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
static isc_boolean_t debugging = ISC_FALSE, ddebugging = ISC_FALSE;
|
2000-11-08 00:55:26 +00:00
|
|
|
static isc_boolean_t memdebugging = ISC_FALSE;
|
2000-11-22 21:25:38 +00:00
|
|
|
static isc_boolean_t have_ipv4 = ISC_FALSE;
|
2000-06-30 01:56:14 +00:00
|
|
|
static isc_boolean_t have_ipv6 = ISC_FALSE;
|
|
|
|
static isc_boolean_t is_dst_up = ISC_FALSE;
|
2000-06-30 18:59:21 +00:00
|
|
|
static isc_boolean_t usevc = ISC_FALSE;
|
2006-12-04 01:54:53 +00:00
|
|
|
static isc_boolean_t usegsstsig = ISC_FALSE;
|
|
|
|
static isc_boolean_t use_win2k_gsstsig = ISC_FALSE;
|
|
|
|
static isc_boolean_t tried_other_gsstsig = ISC_FALSE;
|
2009-06-10 00:27:22 +00:00
|
|
|
static isc_boolean_t local_only = ISC_FALSE;
|
2000-06-30 01:56:14 +00:00
|
|
|
static isc_taskmgr_t *taskmgr = NULL;
|
|
|
|
static isc_task_t *global_task = NULL;
|
2000-09-01 21:34:12 +00:00
|
|
|
static isc_event_t *global_event = NULL;
|
2006-12-04 01:54:53 +00:00
|
|
|
static isc_log_t *lctx = NULL;
|
2000-06-30 01:56:14 +00:00
|
|
|
static isc_mem_t *mctx = NULL;
|
|
|
|
static dns_dispatchmgr_t *dispatchmgr = NULL;
|
|
|
|
static dns_requestmgr_t *requestmgr = NULL;
|
|
|
|
static isc_socketmgr_t *socketmgr = NULL;
|
|
|
|
static isc_timermgr_t *timermgr = NULL;
|
|
|
|
static dns_dispatch_t *dispatchv4 = NULL;
|
2000-08-09 18:44:13 +00:00
|
|
|
static dns_dispatch_t *dispatchv6 = NULL;
|
2000-06-30 01:56:14 +00:00
|
|
|
static dns_message_t *updatemsg = NULL;
|
2000-07-05 23:24:18 +00:00
|
|
|
static dns_fixedname_t fuserzone;
|
|
|
|
static dns_name_t *userzone = NULL;
|
2006-12-04 01:54:53 +00:00
|
|
|
static dns_name_t *zonename = NULL;
|
|
|
|
static dns_name_t tmpzonename;
|
|
|
|
static dns_name_t restart_master;
|
|
|
|
static dns_tsig_keyring_t *gssring = NULL;
|
2002-01-21 07:59:15 +00:00
|
|
|
static dns_tsigkey_t *tsigkey = NULL;
|
|
|
|
static dst_key_t *sig0key;
|
2000-06-30 21:47:35 +00:00
|
|
|
static lwres_context_t *lwctx = NULL;
|
|
|
|
static lwres_conf_t *lwconf;
|
2000-07-05 23:24:18 +00:00
|
|
|
static isc_sockaddr_t *servers;
|
2000-06-30 01:56:14 +00:00
|
|
|
static int ns_inuse = 0;
|
2000-07-05 23:24:18 +00:00
|
|
|
static int ns_total = 0;
|
|
|
|
static isc_sockaddr_t *userserver = NULL;
|
2000-11-16 05:40:25 +00:00
|
|
|
static isc_sockaddr_t *localaddr = NULL;
|
2006-12-04 01:54:53 +00:00
|
|
|
static isc_sockaddr_t *serveraddr = NULL;
|
|
|
|
static isc_sockaddr_t tempaddr;
|
2009-06-10 00:27:22 +00:00
|
|
|
static const char *keyfile = NULL;
|
|
|
|
static char *keystr = NULL;
|
2007-09-15 14:46:03 +00:00
|
|
|
static isc_entropy_t *entropy = NULL;
|
2000-11-22 02:54:15 +00:00
|
|
|
static isc_boolean_t shuttingdown = ISC_FALSE;
|
2000-11-27 00:43:33 +00:00
|
|
|
static FILE *input;
|
2000-11-27 17:56:35 +00:00
|
|
|
static isc_boolean_t interactive = ISC_TRUE;
|
2000-12-07 20:05:29 +00:00
|
|
|
static isc_boolean_t seenerror = ISC_FALSE;
|
2001-07-22 06:11:44 +00:00
|
|
|
static const dns_master_style_t *style;
|
2001-04-13 01:32:14 +00:00
|
|
|
static int requests = 0;
|
2006-12-04 01:54:53 +00:00
|
|
|
static unsigned int logdebuglevel = 0;
|
2002-11-12 23:58:14 +00:00
|
|
|
static unsigned int timeout = 300;
|
|
|
|
static unsigned int udp_timeout = 3;
|
|
|
|
static unsigned int udp_retries = 3;
|
2004-03-03 23:43:09 +00:00
|
|
|
static dns_rdataclass_t defaultclass = dns_rdataclass_in;
|
|
|
|
static dns_rdataclass_t zoneclass = dns_rdataclass_none;
|
2004-03-04 01:21:39 +00:00
|
|
|
static dns_message_t *answer = NULL;
|
2008-09-24 02:46:23 +00:00
|
|
|
static isc_uint32_t default_ttl = 0;
|
|
|
|
static isc_boolean_t default_ttl_set = ISC_FALSE;
|
2000-06-30 01:56:14 +00:00
|
|
|
|
2000-07-05 23:24:18 +00:00
|
|
|
typedef struct nsu_requestinfo {
|
|
|
|
dns_message_t *msg;
|
|
|
|
isc_sockaddr_t *addr;
|
|
|
|
} nsu_requestinfo_t;
|
|
|
|
|
2000-08-01 14:02:41 +00:00
|
|
|
static void
|
2000-11-16 05:40:25 +00:00
|
|
|
sendrequest(isc_sockaddr_t *srcaddr, isc_sockaddr_t *destaddr,
|
|
|
|
dns_message_t *msg, dns_request_t **request);
|
2009-09-29 15:06:07 +00:00
|
|
|
|
|
|
|
ISC_PLATFORM_NORETURN_PRE static void
|
|
|
|
fatal(const char *format, ...)
|
|
|
|
ISC_FORMAT_PRINTF(1, 2) ISC_PLATFORM_NORETURN_POST;
|
2001-08-08 22:54:55 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
debug(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
|
|
|
|
|
|
|
|
static void
|
|
|
|
ddebug(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2006-12-04 01:54:53 +00:00
|
|
|
#ifdef GSSAPI
|
|
|
|
static dns_fixedname_t fkname;
|
|
|
|
static isc_sockaddr_t *kserver = NULL;
|
2010-07-09 05:13:15 +00:00
|
|
|
static char *realm = NULL;
|
2006-12-04 01:54:53 +00:00
|
|
|
static char servicename[DNS_NAME_FORMATSIZE];
|
|
|
|
static dns_name_t *keyname;
|
|
|
|
typedef struct nsu_gssinfo {
|
|
|
|
dns_message_t *msg;
|
|
|
|
isc_sockaddr_t *addr;
|
|
|
|
gss_ctx_id_t context;
|
|
|
|
} nsu_gssinfo_t;
|
|
|
|
|
|
|
|
static void
|
|
|
|
start_gssrequest(dns_name_t *master);
|
|
|
|
static void
|
|
|
|
send_gssrequest(isc_sockaddr_t *srcaddr, isc_sockaddr_t *destaddr,
|
2008-01-18 23:46:58 +00:00
|
|
|
dns_message_t *msg, dns_request_t **request,
|
2006-12-04 01:54:53 +00:00
|
|
|
gss_ctx_id_t context);
|
|
|
|
static void
|
|
|
|
recvgss(isc_task_t *task, isc_event_t *event);
|
|
|
|
#endif /* GSSAPI */
|
|
|
|
|
2006-12-07 05:39:41 +00:00
|
|
|
static void
|
|
|
|
error(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
|
|
|
|
|
2000-08-01 14:02:41 +00:00
|
|
|
#define STATUS_MORE (isc_uint16_t)0
|
|
|
|
#define STATUS_SEND (isc_uint16_t)1
|
|
|
|
#define STATUS_QUIT (isc_uint16_t)2
|
|
|
|
#define STATUS_SYNTAX (isc_uint16_t)3
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2007-09-15 14:46:03 +00:00
|
|
|
typedef struct entropysource entropysource_t;
|
|
|
|
|
|
|
|
struct entropysource {
|
|
|
|
isc_entropysource_t *source;
|
|
|
|
isc_mem_t *mctx;
|
|
|
|
ISC_LINK(entropysource_t) link;
|
|
|
|
};
|
|
|
|
|
|
|
|
static ISC_LIST(entropysource_t) sources;
|
|
|
|
|
|
|
|
static void
|
|
|
|
setup_entropy(isc_mem_t *mctx, const char *randomfile, isc_entropy_t **ectx)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
|
|
|
isc_entropysource_t *source = NULL;
|
|
|
|
entropysource_t *elt;
|
|
|
|
int usekeyboard = ISC_ENTROPY_KEYBOARDMAYBE;
|
|
|
|
|
|
|
|
REQUIRE(ectx != NULL);
|
|
|
|
|
|
|
|
if (*ectx == NULL) {
|
|
|
|
result = isc_entropy_create(mctx, ectx);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("could not create entropy object");
|
|
|
|
ISC_LIST_INIT(sources);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (randomfile != NULL && strcmp(randomfile, "keyboard") == 0) {
|
|
|
|
usekeyboard = ISC_ENTROPY_KEYBOARDYES;
|
|
|
|
randomfile = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = isc_entropy_usebestsource(*ectx, &source, randomfile,
|
|
|
|
usekeyboard);
|
|
|
|
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("could not initialize entropy source: %s",
|
|
|
|
isc_result_totext(result));
|
|
|
|
|
|
|
|
if (source != NULL) {
|
|
|
|
elt = isc_mem_get(mctx, sizeof(*elt));
|
|
|
|
if (elt == NULL)
|
|
|
|
fatal("out of memory");
|
|
|
|
elt->source = source;
|
|
|
|
elt->mctx = mctx;
|
|
|
|
ISC_LINK_INIT(elt, link);
|
|
|
|
ISC_LIST_APPEND(sources, elt, link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cleanup_entropy(isc_entropy_t **ectx) {
|
|
|
|
entropysource_t *source;
|
|
|
|
while (!ISC_LIST_EMPTY(sources)) {
|
|
|
|
source = ISC_LIST_HEAD(sources);
|
|
|
|
ISC_LIST_UNLINK(sources, source, link);
|
|
|
|
isc_entropy_destroysource(&source->source);
|
|
|
|
isc_mem_put(source->mctx, source, sizeof(*source));
|
|
|
|
}
|
|
|
|
isc_entropy_detach(ectx);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-03 23:43:09 +00:00
|
|
|
static dns_rdataclass_t
|
|
|
|
getzoneclass(void) {
|
|
|
|
if (zoneclass == dns_rdataclass_none)
|
|
|
|
zoneclass = defaultclass;
|
|
|
|
return (zoneclass);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_boolean_t
|
|
|
|
setzoneclass(dns_rdataclass_t rdclass) {
|
|
|
|
if (zoneclass == dns_rdataclass_none ||
|
|
|
|
rdclass == dns_rdataclass_none)
|
|
|
|
zoneclass = rdclass;
|
|
|
|
if (zoneclass != rdclass)
|
|
|
|
return (ISC_FALSE);
|
|
|
|
return (ISC_TRUE);
|
|
|
|
}
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
static void
|
|
|
|
fatal(const char *format, ...) {
|
|
|
|
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
|
|
|
|
error(const char *format, ...) {
|
|
|
|
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
|
|
|
|
debug(const char *format, ...) {
|
|
|
|
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
|
|
|
|
ddebug(const char *format, ...) {
|
|
|
|
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
|
2000-06-10 00:50:36 +00:00
|
|
|
check_result(isc_result_t result, const char *msg) {
|
2000-06-30 01:56:14 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
2000-06-10 00:50:36 +00:00
|
|
|
fatal("%s: %s", msg, isc_result_totext(result));
|
|
|
|
}
|
|
|
|
|
2000-06-30 21:47:35 +00:00
|
|
|
static void *
|
|
|
|
mem_alloc(void *arg, size_t size) {
|
|
|
|
return (isc_mem_get(arg, size));
|
2000-06-30 03:24:27 +00:00
|
|
|
}
|
|
|
|
|
2000-06-30 21:47:35 +00:00
|
|
|
static void
|
|
|
|
mem_free(void *arg, void *mem, size_t size) {
|
|
|
|
isc_mem_put(arg, mem, size);
|
2000-06-30 03:24:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
nsu_strsep(char **stringp, const char *delim) {
|
|
|
|
char *string = *stringp;
|
|
|
|
char *s;
|
|
|
|
const char *d;
|
|
|
|
char sc, dc;
|
|
|
|
|
|
|
|
if (string == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
2000-06-30 06:35:50 +00:00
|
|
|
for (; *string != '\0'; string++) {
|
|
|
|
sc = *string;
|
|
|
|
for (d = delim; (dc = *d) != '\0'; d++) {
|
|
|
|
if (sc == dc)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (dc == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
*stringp = NULL;
|
|
|
|
return (string);
|
|
|
|
}
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
static void
|
2000-06-30 01:56:14 +00:00
|
|
|
reset_system(void) {
|
2000-06-10 00:50:36 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
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 */
|
|
|
|
if (updatemsg != NULL)
|
2000-06-30 01:56:14 +00:00
|
|
|
dns_message_reset(updatemsg, DNS_MESSAGE_INTENTRENDER);
|
|
|
|
else {
|
|
|
|
result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER,
|
|
|
|
&updatemsg);
|
2000-07-09 16:17:13 +00:00
|
|
|
check_result(result, "dns_message_create");
|
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) {
|
|
|
|
if (tsigkey != NULL)
|
|
|
|
dns_tsigkey_detach(&tsigkey);
|
|
|
|
if (gssring != NULL)
|
|
|
|
dns_tsigkeyring_destroy(&gssring);
|
|
|
|
tried_other_gsstsig = ISC_FALSE;
|
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
2006-01-27 02:35:15 +00:00
|
|
|
static isc_uint16_t
|
|
|
|
parse_hmac(dns_name_t **hmac, const char *hmacstr, size_t len) {
|
|
|
|
isc_uint16_t digestbits = 0;
|
|
|
|
isc_result_t result;
|
|
|
|
char buf[20];
|
|
|
|
|
|
|
|
REQUIRE(hmac != NULL && *hmac == NULL);
|
|
|
|
REQUIRE(hmacstr != NULL);
|
|
|
|
|
|
|
|
if (len >= sizeof(buf))
|
|
|
|
fatal("unknown key type '%.*s'", (int)(len), hmacstr);
|
|
|
|
|
|
|
|
strncpy(buf, hmacstr, len);
|
|
|
|
buf[len] = 0;
|
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);
|
|
|
|
if (result != ISC_R_SUCCESS || digestbits > 128)
|
|
|
|
fatal("digest-bits out of range [0..128]");
|
|
|
|
digestbits = (digestbits +7) & ~0x7U;
|
|
|
|
} else if (strcasecmp(buf, "hmac-sha1") == 0) {
|
|
|
|
*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);
|
|
|
|
if (result != ISC_R_SUCCESS || digestbits > 160)
|
|
|
|
fatal("digest-bits out of range [0..160]");
|
|
|
|
digestbits = (digestbits +7) & ~0x7U;
|
|
|
|
} 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);
|
|
|
|
if (result != ISC_R_SUCCESS || digestbits > 224)
|
|
|
|
fatal("digest-bits out of range [0..224]");
|
|
|
|
digestbits = (digestbits +7) & ~0x7U;
|
|
|
|
} 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);
|
|
|
|
if (result != ISC_R_SUCCESS || digestbits > 256)
|
|
|
|
fatal("digest-bits out of range [0..256]");
|
|
|
|
digestbits = (digestbits +7) & ~0x7U;
|
|
|
|
} 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);
|
|
|
|
if (result != ISC_R_SUCCESS || digestbits > 384)
|
|
|
|
fatal("digest-bits out of range [0..384]");
|
|
|
|
digestbits = (digestbits +7) & ~0x7U;
|
|
|
|
} 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);
|
|
|
|
if (result != ISC_R_SUCCESS || digestbits > 512)
|
|
|
|
fatal("digest-bits out of range [0..512]");
|
|
|
|
digestbits = (digestbits +7) & ~0x7U;
|
|
|
|
} else
|
|
|
|
fatal("unknown key type '%s'", buf);
|
|
|
|
return (digestbits);
|
|
|
|
}
|
|
|
|
|
2010-08-10 09:51:47 +00:00
|
|
|
static int
|
|
|
|
basenamelen(const char *file) {
|
2010-08-10 23:48:19 +00:00
|
|
|
int len = strlen(file);
|
|
|
|
|
|
|
|
if (len > 1 && file[len - 1] == '.')
|
|
|
|
len -= 1;
|
|
|
|
else if (len > 8 && strcmp(file + len - 8, ".private") == 0)
|
|
|
|
len -= 8;
|
|
|
|
else if (len > 4 && strcmp(file + len - 4, ".key") == 0)
|
|
|
|
len -= 4;
|
2010-08-10 09:51:47 +00:00
|
|
|
return (len);
|
|
|
|
}
|
|
|
|
|
2000-07-03 23:42:48 +00:00
|
|
|
static void
|
2001-09-27 17:53:39 +00:00
|
|
|
setup_keystr(void) {
|
2000-07-03 23:42:48 +00:00
|
|
|
unsigned char *secret = NULL;
|
|
|
|
int secretlen;
|
|
|
|
isc_buffer_t secretbuf;
|
|
|
|
isc_result_t result;
|
2001-09-27 17:53:39 +00:00
|
|
|
isc_buffer_t keynamesrc;
|
|
|
|
char *secretstr;
|
2006-01-27 02:35:15 +00:00
|
|
|
char *s, *n;
|
2000-07-03 23:42:48 +00:00
|
|
|
dns_fixedname_t fkeyname;
|
|
|
|
dns_name_t *keyname;
|
2006-01-27 02:35:15 +00:00
|
|
|
char *name;
|
|
|
|
dns_name_t *hmacname = NULL;
|
|
|
|
isc_uint16_t digestbits = 0;
|
2000-07-03 23:42:48 +00:00
|
|
|
|
2000-08-02 02:34:40 +00:00
|
|
|
dns_fixedname_init(&fkeyname);
|
|
|
|
keyname = dns_fixedname_name(&fkeyname);
|
|
|
|
|
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, ':');
|
2006-01-27 02:35:15 +00:00
|
|
|
if (s == NULL || s == keystr || s[1] == 0)
|
|
|
|
fatal("key option must specify [hmac:]keyname:secret");
|
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) {
|
|
|
|
if (n == secretstr || n[1] == 0)
|
|
|
|
fatal("key option must specify [hmac:]keyname:secret");
|
|
|
|
name = secretstr;
|
|
|
|
secretstr = n + 1;
|
|
|
|
digestbits = parse_hmac(&hmacname, keystr, s - keystr);
|
|
|
|
} else {
|
|
|
|
hmacname = DNS_TSIG_HMACMD5_NAME;
|
|
|
|
name = keystr;
|
|
|
|
n = s;
|
|
|
|
}
|
2000-07-03 23:42:48 +00:00
|
|
|
|
2006-01-27 02:35:15 +00:00
|
|
|
isc_buffer_init(&keynamesrc, name, n - name);
|
|
|
|
isc_buffer_add(&keynamesrc, n - name);
|
2000-07-03 23:42:48 +00:00
|
|
|
|
2001-09-27 17:53:39 +00:00
|
|
|
debug("namefromtext");
|
2009-09-01 00:22:28 +00:00
|
|
|
result = dns_name_fromtext(keyname, &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;
|
|
|
|
secret = isc_mem_allocate(mctx, secretlen);
|
|
|
|
if (secret == NULL)
|
|
|
|
fatal("out of memory");
|
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) {
|
|
|
|
fprintf(stderr, "could not create key from %s: %s\n",
|
|
|
|
keystr, isc_result_totext(result));
|
|
|
|
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");
|
2006-01-27 02:35:15 +00:00
|
|
|
result = dns_tsigkey_create(keyname, hmacname, secret, secretlen,
|
2010-07-09 05:13:15 +00:00
|
|
|
ISC_FALSE, NULL, 0, 0, mctx, NULL,
|
|
|
|
&tsigkey);
|
2001-09-27 17:53:39 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
2001-07-02 18:56:58 +00:00
|
|
|
fprintf(stderr, "could not create key from %s: %s\n",
|
2001-09-27 17:53:39 +00:00
|
|
|
keystr, dns_result_totext(result));
|
2006-01-27 02:35:15 +00:00
|
|
|
else
|
|
|
|
dst_key_setbits(tsigkey->key, digestbits);
|
2000-07-03 23:42:48 +00:00
|
|
|
failure:
|
|
|
|
if (secret != NULL)
|
|
|
|
isc_mem_free(mctx, secret);
|
|
|
|
}
|
|
|
|
|
2009-06-10 00:27:22 +00:00
|
|
|
/*
|
|
|
|
* Get a key from a named.conf format keyfile
|
|
|
|
*/
|
|
|
|
static isc_result_t
|
2009-07-14 22:54:57 +00:00
|
|
|
read_sessionkey(isc_mem_t *mctx, isc_log_t *lctx) {
|
2009-06-10 00:27:22 +00:00
|
|
|
cfg_parser_t *pctx = NULL;
|
2009-07-14 22:54:57 +00:00
|
|
|
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;
|
|
|
|
const char *keyname;
|
|
|
|
const char *secretstr;
|
|
|
|
const char *algorithm;
|
|
|
|
isc_result_t result;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (! isc_file_exists(keyfile))
|
|
|
|
return (ISC_R_FILENOTFOUND);
|
|
|
|
|
|
|
|
result = cfg_parser_create(mctx, lctx, &pctx);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
|
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);
|
2009-06-10 00:27:22 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
|
2009-07-14 22:54:57 +00:00
|
|
|
result = cfg_map_get(sessionkey, "key", &key);
|
2009-06-10 00:27:22 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
(void) cfg_map_get(key, "secret", &secretobj);
|
|
|
|
(void) cfg_map_get(key, "algorithm", &algorithmobj);
|
|
|
|
if (secretobj == NULL || algorithmobj == NULL)
|
|
|
|
fatal("key must have algorithm and secret");
|
|
|
|
|
|
|
|
keyname = cfg_obj_asstring(cfg_map_getname(key));
|
|
|
|
secretstr = cfg_obj_asstring(secretobj);
|
|
|
|
algorithm = cfg_obj_asstring(algorithmobj);
|
|
|
|
|
|
|
|
len = strlen(algorithm) + strlen(keyname) + strlen(secretstr) + 3;
|
|
|
|
keystr = isc_mem_allocate(mctx, len);
|
|
|
|
snprintf(keystr, len, "%s:%s:%s", algorithm, keyname, secretstr);
|
|
|
|
setup_keystr();
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (pctx != NULL) {
|
2009-07-14 22:54:57 +00:00
|
|
|
if (sessionkey != NULL)
|
|
|
|
cfg_obj_destroy(pctx, &sessionkey);
|
2009-06-10 00:27:22 +00:00
|
|
|
cfg_parser_destroy(&pctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keystr != NULL)
|
|
|
|
isc_mem_free(mctx, keystr);
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2001-09-27 17:53:39 +00:00
|
|
|
static void
|
2009-06-10 00:27:22 +00:00
|
|
|
setup_keyfile(isc_mem_t *mctx, isc_log_t *lctx) {
|
2001-09-27 17:53:39 +00:00
|
|
|
dst_key_t *dstkey = NULL;
|
|
|
|
isc_result_t result;
|
2006-01-27 02:35:15 +00:00
|
|
|
dns_name_t *hmacname = NULL;
|
2001-09-27 17:53:39 +00:00
|
|
|
|
|
|
|
debug("Creating key...");
|
|
|
|
|
2009-06-10 00:27:22 +00:00
|
|
|
/* Try reading the key from a K* pair */
|
2009-07-19 04:18:05 +00:00
|
|
|
result = dst_key_fromnamedfile(keyfile, NULL,
|
2004-06-17 01:03:00 +00:00
|
|
|
DST_TYPE_PRIVATE | DST_TYPE_KEY, mctx,
|
2001-09-27 17:53:39 +00:00
|
|
|
&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);
|
2009-06-10 00:27:22 +00:00
|
|
|
if (result == ISC_R_SUCCESS)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-09-27 17:53:39 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2010-08-10 09:51:47 +00: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) {
|
2002-01-21 07:59:15 +00:00
|
|
|
result = dns_tsigkey_createfromkey(dst_key_name(dstkey),
|
2010-12-02 23:22:42 +00:00
|
|
|
hmacname, &dstkey, ISC_FALSE,
|
2006-01-27 02:35:15 +00:00
|
|
|
NULL, 0, 0, mctx, NULL,
|
|
|
|
&tsigkey);
|
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));
|
|
|
|
dst_key_free(&dstkey);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
sig0key = dstkey;
|
2001-09-27 17:53:39 +00:00
|
|
|
}
|
|
|
|
|
2000-11-22 02:54:15 +00:00
|
|
|
static void
|
2001-04-13 01:32:14 +00:00
|
|
|
doshutdown(void) {
|
2000-11-22 02:54:15 +00:00
|
|
|
isc_task_detach(&global_task);
|
2001-01-21 21:54:32 +00:00
|
|
|
|
|
|
|
if (userserver != NULL)
|
|
|
|
isc_mem_put(mctx, userserver, sizeof(isc_sockaddr_t));
|
|
|
|
|
|
|
|
if (localaddr != NULL)
|
|
|
|
isc_mem_put(mctx, localaddr, sizeof(isc_sockaddr_t));
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if (updatemsg != NULL)
|
|
|
|
dns_message_destroy(&updatemsg);
|
|
|
|
|
|
|
|
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();
|
|
|
|
is_dst_up = ISC_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-09-15 14:46:03 +00:00
|
|
|
cleanup_entropy(&entropy);
|
2001-01-21 21:54:32 +00:00
|
|
|
|
|
|
|
lwres_conf_clear(lwctx);
|
|
|
|
lwres_context_destroy(&lwctx);
|
|
|
|
|
|
|
|
isc_mem_put(mctx, servers, ns_total * sizeof(isc_sockaddr_t));
|
|
|
|
|
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");
|
|
|
|
if (have_ipv4)
|
|
|
|
dns_dispatch_detach(&dispatchv4);
|
|
|
|
if (have_ipv6)
|
|
|
|
dns_dispatch_detach(&dispatchv6);
|
|
|
|
|
|
|
|
ddebug("Shutting down dispatch manager");
|
|
|
|
dns_dispatchmgr_destroy(&dispatchmgr);
|
|
|
|
|
2000-11-22 02:54:15 +00:00
|
|
|
}
|
|
|
|
|
2001-04-13 01:32:14 +00:00
|
|
|
static void
|
|
|
|
maybeshutdown(void) {
|
|
|
|
ddebug("Shutting down request manager");
|
|
|
|
dns_requestmgr_shutdown(requestmgr);
|
|
|
|
|
|
|
|
if (requests != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
doshutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shutdown_program(isc_task_t *task, isc_event_t *event) {
|
|
|
|
REQUIRE(task == global_task);
|
|
|
|
UNUSED(task);
|
|
|
|
|
|
|
|
ddebug("shutdown_program()");
|
|
|
|
isc_event_free(&event);
|
|
|
|
|
|
|
|
shuttingdown = ISC_TRUE;
|
|
|
|
maybeshutdown();
|
|
|
|
}
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
static void
|
2000-06-30 01:56:14 +00:00
|
|
|
setup_system(void) {
|
2000-06-10 00:50:36 +00:00
|
|
|
isc_result_t result;
|
2000-08-09 18:44:13 +00:00
|
|
|
isc_sockaddr_t bind_any, bind_any6;
|
2000-06-30 21:47:35 +00:00
|
|
|
lwres_result_t lwresult;
|
2000-08-09 18:44:13 +00:00
|
|
|
unsigned int attrs, attrmask;
|
2000-07-05 23:24:18 +00:00
|
|
|
int i;
|
2006-12-04 01:54:53 +00:00
|
|
|
isc_logconfig_t *logconfig = 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
|
|
|
|
2000-10-03 17:28:58 +00:00
|
|
|
dns_result_register();
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
result = isc_net_probeipv4();
|
2000-11-22 21:25:38 +00:00
|
|
|
if (result == ISC_R_SUCCESS)
|
|
|
|
have_ipv4 = ISC_TRUE;
|
2000-06-10 00:50:36 +00:00
|
|
|
|
|
|
|
result = isc_net_probeipv6();
|
|
|
|
if (result == ISC_R_SUCCESS)
|
2000-08-09 18:44:13 +00:00
|
|
|
have_ipv6 = ISC_TRUE;
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-11-22 21:25:38 +00:00
|
|
|
if (!have_ipv4 && !have_ipv6)
|
2001-07-02 18:56:58 +00:00
|
|
|
fatal("could not find either IPv4 or IPv6");
|
2000-11-22 21:25:38 +00:00
|
|
|
|
2006-12-04 01:54:53 +00:00
|
|
|
result = isc_log_create(mctx, &lctx, &logconfig);
|
|
|
|
check_result(result, "isc_log_create");
|
|
|
|
|
|
|
|
isc_log_setcontext(lctx);
|
|
|
|
dns_log_init(lctx);
|
|
|
|
dns_log_setcontext(lctx);
|
|
|
|
|
|
|
|
result = isc_log_usechannel(logconfig, "default_debug", NULL, NULL);
|
|
|
|
check_result(result, "isc_log_usechannel");
|
|
|
|
|
|
|
|
isc_log_setdebuglevel(lctx, logdebuglevel);
|
|
|
|
|
2000-06-30 21:47:35 +00:00
|
|
|
lwresult = lwres_context_create(&lwctx, mctx, mem_alloc, mem_free, 1);
|
|
|
|
if (lwresult != LWRES_R_SUCCESS)
|
|
|
|
fatal("lwres_context_create failed");
|
|
|
|
|
2001-10-04 23:29:41 +00:00
|
|
|
(void)lwres_conf_parse(lwctx, RESOLV_CONF);
|
2000-06-30 21:47:35 +00:00
|
|
|
lwconf = lwres_conf_get(lwctx);
|
2000-06-30 01:56:14 +00:00
|
|
|
|
2000-07-05 23:24:18 +00:00
|
|
|
ns_total = lwconf->nsnext;
|
2001-10-04 23:29:41 +00:00
|
|
|
if (ns_total <= 0) {
|
|
|
|
/* No name servers in resolv.conf; default to loopback. */
|
|
|
|
struct in_addr localhost;
|
|
|
|
ns_total = 1;
|
|
|
|
servers = isc_mem_get(mctx, ns_total * sizeof(isc_sockaddr_t));
|
|
|
|
if (servers == NULL)
|
|
|
|
fatal("out of memory");
|
|
|
|
localhost.s_addr = htonl(INADDR_LOOPBACK);
|
2009-06-10 00:27:22 +00:00
|
|
|
isc_sockaddr_fromin(&servers[0], &localhost, dnsport);
|
2001-10-04 23:29:41 +00:00
|
|
|
} else {
|
|
|
|
servers = isc_mem_get(mctx, ns_total * sizeof(isc_sockaddr_t));
|
|
|
|
if (servers == NULL)
|
|
|
|
fatal("out of memory");
|
|
|
|
for (i = 0; i < ns_total; i++) {
|
|
|
|
if (lwconf->nameservers[i].family == LWRES_ADDRTYPE_V4) {
|
|
|
|
struct in_addr in4;
|
|
|
|
memcpy(&in4, lwconf->nameservers[i].address, 4);
|
2009-06-10 00:27:22 +00:00
|
|
|
isc_sockaddr_fromin(&servers[i], &in4, dnsport);
|
2001-10-04 23:29:41 +00:00
|
|
|
} else {
|
|
|
|
struct in6_addr in6;
|
|
|
|
memcpy(&in6, lwconf->nameservers[i].address, 16);
|
|
|
|
isc_sockaddr_fromin6(&servers[i], &in6,
|
2009-06-10 00:27:22 +00:00
|
|
|
dnsport);
|
2001-10-04 23:29:41 +00:00
|
|
|
}
|
2000-07-05 23:24:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-16 02:37:12 +00:00
|
|
|
setup_entropy(mctx, NULL, &entropy);
|
2001-04-10 18:45:05 +00:00
|
|
|
|
2007-09-15 14:46:03 +00:00
|
|
|
result = isc_hash_create(mctx, entropy, DNS_NAME_MAXWIRE);
|
2003-07-25 02:22:26 +00:00
|
|
|
check_result(result, "isc_hash_create");
|
|
|
|
isc_hash_init();
|
|
|
|
|
2007-09-15 14:46:03 +00:00
|
|
|
result = dns_dispatchmgr_create(mctx, entropy, &dispatchmgr);
|
2000-06-10 00:50:36 +00:00
|
|
|
check_result(result, "dns_dispatchmgr_create");
|
|
|
|
|
|
|
|
result = isc_socketmgr_create(mctx, &socketmgr);
|
|
|
|
check_result(result, "dns_socketmgr_create");
|
|
|
|
|
|
|
|
result = isc_timermgr_create(mctx, &timermgr);
|
|
|
|
check_result(result, "dns_timermgr_create");
|
|
|
|
|
2000-07-05 23:24:18 +00:00
|
|
|
result = isc_taskmgr_create(mctx, 1, 0, &taskmgr);
|
2000-06-27 21:59:44 +00:00
|
|
|
check_result(result, "isc_taskmgr_create");
|
|
|
|
|
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");
|
|
|
|
|
2007-09-15 14:46:03 +00:00
|
|
|
result = dst_lib_init(mctx, entropy, 0);
|
2000-06-23 20:46:25 +00:00
|
|
|
check_result(result, "dst_lib_init");
|
|
|
|
is_dst_up = ISC_TRUE;
|
|
|
|
|
2000-08-09 18:44:13 +00:00
|
|
|
attrmask = DNS_DISPATCHATTR_UDP | DNS_DISPATCHATTR_TCP;
|
|
|
|
attrmask |= DNS_DISPATCHATTR_IPV4 | DNS_DISPATCHATTR_IPV6;
|
|
|
|
|
|
|
|
if (have_ipv6) {
|
|
|
|
attrs = DNS_DISPATCHATTR_UDP;
|
|
|
|
attrs |= DNS_DISPATCHATTR_MAKEQUERY;
|
|
|
|
attrs |= DNS_DISPATCHATTR_IPV6;
|
|
|
|
isc_sockaddr_any6(&bind_any6);
|
|
|
|
result = dns_dispatch_getudp(dispatchmgr, socketmgr, taskmgr,
|
|
|
|
&bind_any6, PACKETSIZE,
|
|
|
|
4, 2, 3, 5,
|
|
|
|
attrs, attrmask, &dispatchv6);
|
|
|
|
check_result(result, "dns_dispatch_getudp (v6)");
|
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-11-22 21:25:38 +00:00
|
|
|
if (have_ipv4) {
|
|
|
|
attrs = DNS_DISPATCHATTR_UDP;
|
|
|
|
attrs |= DNS_DISPATCHATTR_MAKEQUERY;
|
|
|
|
attrs |= DNS_DISPATCHATTR_IPV4;
|
|
|
|
isc_sockaddr_any(&bind_any);
|
|
|
|
result = dns_dispatch_getudp(dispatchmgr, socketmgr, taskmgr,
|
|
|
|
&bind_any, PACKETSIZE,
|
|
|
|
4, 2, 3, 5,
|
|
|
|
attrs, attrmask, &dispatchv4);
|
|
|
|
check_result(result, "dns_dispatch_getudp (v4)");
|
|
|
|
}
|
2000-06-16 17:10:02 +00:00
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
result = dns_requestmgr_create(mctx, timermgr,
|
|
|
|
socketmgr, taskmgr, dispatchmgr,
|
2000-08-09 18:44:13 +00:00
|
|
|
dispatchv4, dispatchv6, &requestmgr);
|
2000-06-10 00:50:36 +00:00
|
|
|
check_result(result, "dns_requestmgr_create");
|
|
|
|
|
2001-09-27 17:53:39 +00:00
|
|
|
if (keystr != NULL)
|
|
|
|
setup_keystr();
|
2009-06-10 00:27:22 +00:00
|
|
|
else if (local_only)
|
2009-07-14 22:54:57 +00:00
|
|
|
read_sessionkey(mctx, lctx);
|
2001-09-27 17:53:39 +00:00
|
|
|
else if (keyfile != NULL)
|
2009-06-10 00:27:22 +00:00
|
|
|
setup_keyfile(mctx, lctx);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
2000-06-23 20:46:25 +00:00
|
|
|
|
2000-07-05 23:24:18 +00:00
|
|
|
static void
|
|
|
|
get_address(char *host, in_port_t port, isc_sockaddr_t *sockaddr) {
|
2001-11-14 22:08:38 +00:00
|
|
|
int count;
|
|
|
|
isc_result_t result;
|
2001-02-24 21:02:38 +00:00
|
|
|
|
2001-11-14 22:08:38 +00:00
|
|
|
isc_app_block();
|
|
|
|
result = bind9_getaddresses(host, port, sockaddr, 1, &count);
|
|
|
|
isc_app_unblock();
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("couldn't get address for '%s': %s",
|
|
|
|
host, isc_result_totext(result));
|
|
|
|
INSIST(count == 1);
|
2000-07-05 23:24:18 +00:00
|
|
|
}
|
|
|
|
|
2009-06-10 00:27:22 +00:00
|
|
|
#define PARSE_ARGS_FMT "dDML:y:ghlovk:p:rR::t:u:"
|
2007-09-15 14:46:03 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
pre_parse_args(int argc, char **argv) {
|
|
|
|
int ch;
|
|
|
|
|
|
|
|
while ((ch = isc_commandline_parse(argc, argv, PARSE_ARGS_FMT)) != -1) {
|
|
|
|
switch (ch) {
|
|
|
|
case 'M': /* was -dm */
|
|
|
|
debugging = ISC_TRUE;
|
|
|
|
ddebugging = ISC_TRUE;
|
|
|
|
memdebugging = ISC_TRUE;
|
|
|
|
isc_mem_debugging = ISC_MEM_DEBUGTRACE |
|
|
|
|
ISC_MEM_DEBUGRECORD;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '?':
|
2009-06-10 00:27:22 +00:00
|
|
|
case 'h':
|
2007-09-15 14:46:03 +00:00
|
|
|
if (isc_commandline_option != '?')
|
|
|
|
fprintf(stderr, "%s: invalid argument -%c\n",
|
|
|
|
argv[0], isc_commandline_option);
|
2009-06-10 00:27:22 +00:00
|
|
|
fprintf(stderr, "usage: nsupdate [-dD] [-L level] [-l]"
|
2007-09-15 14:46:03 +00:00
|
|
|
"[-g | -o | -y keyname:secret | -k keyfile] "
|
|
|
|
"[-v] [filename]\n");
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
isc_commandline_reset = ISC_TRUE;
|
|
|
|
isc_commandline_index = 1;
|
|
|
|
}
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
static void
|
2007-09-15 14:46:03 +00:00
|
|
|
parse_args(int argc, char **argv, isc_mem_t *mctx, isc_entropy_t **ectx) {
|
2000-06-30 01:56:14 +00:00
|
|
|
int ch;
|
2006-12-04 01:54:53 +00:00
|
|
|
isc_uint32_t i;
|
2000-11-27 00:43:33 +00:00
|
|
|
isc_result_t result;
|
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) {
|
|
|
|
case 'd':
|
|
|
|
debugging = ISC_TRUE;
|
|
|
|
break;
|
|
|
|
case 'D': /* was -dd */
|
2000-06-20 22:50:13 +00:00
|
|
|
debugging = ISC_TRUE;
|
|
|
|
ddebugging = ISC_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;
|
2006-12-04 01:54:53 +00:00
|
|
|
case 'l':
|
2009-06-10 00:27:22 +00:00
|
|
|
local_only = ISC_TRUE;
|
|
|
|
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) {
|
|
|
|
fprintf(stderr, "bad library debug value "
|
|
|
|
"'%s'\n", isc_commandline_argument);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
logdebuglevel = i;
|
|
|
|
break;
|
2000-06-30 01:56:14 +00:00
|
|
|
case 'y':
|
|
|
|
keystr = isc_commandline_argument;
|
|
|
|
break;
|
|
|
|
case 'v':
|
2000-06-30 18:59:21 +00:00
|
|
|
usevc = ISC_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':
|
|
|
|
usegsstsig = ISC_TRUE;
|
|
|
|
use_win2k_gsstsig = ISC_FALSE;
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
usegsstsig = ISC_TRUE;
|
|
|
|
use_win2k_gsstsig = ISC_TRUE;
|
|
|
|
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) {
|
|
|
|
fprintf(stderr, "bad port number "
|
|
|
|
"'%s'\n", isc_commandline_argument);
|
|
|
|
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) {
|
|
|
|
fprintf(stderr, "bad timeout '%s'\n", isc_commandline_argument);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (timeout == 0)
|
2004-09-16 01:01:27 +00:00
|
|
|
timeout = UINT_MAX;
|
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) {
|
|
|
|
fprintf(stderr, "bad udp timeout '%s'\n", isc_commandline_argument);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (udp_timeout == 0)
|
2004-09-16 01:01:27 +00:00
|
|
|
udp_timeout = UINT_MAX;
|
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) {
|
|
|
|
fprintf(stderr, "bad udp retries '%s'\n", isc_commandline_argument);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
2007-09-15 14:46:03 +00:00
|
|
|
|
|
|
|
case 'R':
|
|
|
|
setup_entropy(mctx, isc_commandline_argument, ectx);
|
|
|
|
break;
|
2007-05-21 02:47:25 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "%s: unhandled option: %c\n",
|
|
|
|
argv[0], isc_commandline_option);
|
|
|
|
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) {
|
2000-07-09 16:17:13 +00: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
|
|
|
|
2009-06-10 00:27:22 +00:00
|
|
|
if (local_only) {
|
|
|
|
struct in_addr localhost;
|
|
|
|
|
|
|
|
if (keyfile == NULL)
|
2009-07-14 22:54:57 +00:00
|
|
|
keyfile = SESSION_KEYFILE;
|
2009-06-10 00:27:22 +00:00
|
|
|
|
|
|
|
if (userserver == NULL) {
|
|
|
|
userserver = isc_mem_get(mctx, sizeof(isc_sockaddr_t));
|
|
|
|
if (userserver == NULL)
|
|
|
|
fatal("out of memory");
|
|
|
|
}
|
|
|
|
|
|
|
|
localhost.s_addr = htonl(INADDR_LOOPBACK);
|
|
|
|
isc_sockaddr_fromin(userserver, &localhost, dnsport);
|
|
|
|
}
|
|
|
|
|
2006-12-04 01:54:53 +00:00
|
|
|
#ifdef GSSAPI
|
|
|
|
if (usegsstsig && (keyfile != NULL || keystr != NULL)) {
|
|
|
|
fprintf(stderr, "%s: cannot specify -g with -k or -y\n",
|
|
|
|
argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (usegsstsig) {
|
2009-06-10 00:27:22 +00: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);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
}
|
2000-11-27 17:56:35 +00:00
|
|
|
interactive = ISC_FALSE;
|
2000-11-27 00:43:33 +00:00
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static isc_uint16_t
|
2000-06-30 21:47:35 +00:00
|
|
|
parse_name(char **cmdlinep, dns_message_t *msg, dns_name_t **namep) {
|
2000-06-10 00:50:36 +00:00
|
|
|
isc_result_t result;
|
2000-06-30 03:24:27 +00:00
|
|
|
char *word;
|
2000-06-30 01:56:14 +00:00
|
|
|
isc_buffer_t *namebuf = NULL;
|
2000-06-10 00:50:36 +00:00
|
|
|
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");
|
2000-06-30 03:45:54 +00:00
|
|
|
if (*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");
|
2002-01-21 07:59:15 +00:00
|
|
|
result = isc_buffer_allocate(mctx, &namebuf, DNS_NAME_MAXWIRE);
|
2000-06-10 00:50:36 +00:00
|
|
|
check_result(result, "isc_buffer_allocate");
|
2000-06-30 21:47:35 +00:00
|
|
|
dns_name_init(*namep, NULL);
|
|
|
|
dns_name_setbuffer(*namep, namebuf);
|
|
|
|
dns_message_takebuffer(msg, &namebuf);
|
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);
|
2000-06-10 00:50:36 +00:00
|
|
|
check_result(result, "dns_name_fromtext");
|
2000-06-30 21:47:35 +00:00
|
|
|
isc_buffer_invalidate(&source);
|
|
|
|
return (STATUS_MORE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_uint16_t
|
|
|
|
parse_rdata(char **cmdlinep, dns_rdataclass_t rdataclass,
|
2000-07-09 16:17:13 +00:00
|
|
|
dns_rdatatype_t rdatatype, dns_message_t *msg,
|
2000-10-25 04:26:57 +00:00
|
|
|
dns_rdata_t *rdata)
|
2000-06-30 21:47:35 +00:00
|
|
|
{
|
|
|
|
char *cmdline = *cmdlinep;
|
2002-08-06 03:21:59 +00:00
|
|
|
isc_buffer_t source, *buf = NULL, *newbuf = NULL;
|
|
|
|
isc_region_t r;
|
2000-06-30 21:47:35 +00:00
|
|
|
isc_lex_t *lex = NULL;
|
|
|
|
dns_rdatacallbacks_t callbacks;
|
|
|
|
isc_result_t result;
|
|
|
|
|
2000-07-01 00:22:00 +00:00
|
|
|
while (*cmdline != 0 && isspace((unsigned char)*cmdline))
|
2000-06-30 21:47:35 +00:00
|
|
|
cmdline++;
|
|
|
|
|
|
|
|
if (*cmdline != 0) {
|
2000-09-28 21:39:26 +00:00
|
|
|
dns_rdatacallbacks_init(&callbacks);
|
2002-08-06 03:21:59 +00:00
|
|
|
result = isc_lex_create(mctx, strlen(cmdline), &lex);
|
|
|
|
check_result(result, "isc_lex_create");
|
|
|
|
isc_buffer_init(&source, cmdline, strlen(cmdline));
|
|
|
|
isc_buffer_add(&source, strlen(cmdline));
|
|
|
|
result = isc_lex_openbuffer(lex, &source);
|
|
|
|
check_result(result, "isc_lex_openbuffer");
|
|
|
|
result = isc_buffer_allocate(mctx, &buf, MAXWIRE);
|
|
|
|
check_result(result, "isc_buffer_allocate");
|
2008-04-01 01:37:25 +00:00
|
|
|
result = dns_rdata_fromtext(NULL, rdataclass, rdatatype, lex,
|
2004-03-02 00:46:53 +00:00
|
|
|
dns_rootname, 0, mctx, buf,
|
2002-08-06 03:21:59 +00:00
|
|
|
&callbacks);
|
|
|
|
isc_lex_destroy(&lex);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
isc_buffer_usedregion(buf, &r);
|
|
|
|
result = isc_buffer_allocate(mctx, &newbuf, r.length);
|
2000-09-28 21:39:26 +00:00
|
|
|
check_result(result, "isc_buffer_allocate");
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_uint16_t
|
|
|
|
make_prereq(char *cmdline, isc_boolean_t ispositive, isc_boolean_t isrrset) {
|
|
|
|
isc_result_t result;
|
|
|
|
char *word;
|
|
|
|
dns_name_t *name = NULL;
|
|
|
|
isc_textregion_t region;
|
|
|
|
dns_rdataset_t *rdataset = NULL;
|
|
|
|
dns_rdatalist_t *rdatalist = NULL;
|
|
|
|
dns_rdataclass_t rdataclass;
|
|
|
|
dns_rdatatype_t rdatatype;
|
|
|
|
dns_rdata_t *rdata = NULL;
|
|
|
|
isc_uint16_t retval;
|
|
|
|
|
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);
|
|
|
|
if (retval != STATUS_MORE)
|
|
|
|
return (retval);
|
|
|
|
|
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");
|
2000-06-30 03:45:54 +00:00
|
|
|
if (*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");
|
2000-06-30 03:45:54 +00:00
|
|
|
if (*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
|
|
|
}
|
|
|
|
} else
|
|
|
|
rdatatype = dns_rdatatype_any;
|
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) {
|
2000-06-30 21:47:35 +00:00
|
|
|
retval = parse_rdata(&cmdline, rdataclass, rdatatype,
|
2000-10-25 04:26:57 +00:00
|
|
|
updatemsg, rdata);
|
2000-06-30 21:47:35 +00:00
|
|
|
if (retval != STATUS_MORE)
|
2001-04-20 21:10:36 +00:00
|
|
|
goto failure;
|
2001-05-05 01:19:45 +00:00
|
|
|
} else
|
|
|
|
rdata->flags = DNS_RDATA_UPDATE;
|
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-19 22:09:46 +00:00
|
|
|
dns_rdatalist_init(rdatalist);
|
2000-06-30 01:56:14 +00:00
|
|
|
rdatalist->type = rdatatype;
|
2000-06-30 18:44:51 +00:00
|
|
|
if (ispositive) {
|
|
|
|
if (isrrset && rdata->data != NULL)
|
|
|
|
rdatalist->rdclass = rdataclass;
|
|
|
|
else
|
|
|
|
rdatalist->rdclass = dns_rdataclass_any;
|
|
|
|
} else
|
2000-06-30 01:56:14 +00:00
|
|
|
rdatalist->rdclass = dns_rdataclass_none;
|
2000-06-19 22:09:46 +00:00
|
|
|
rdatalist->covers = 0;
|
|
|
|
rdatalist->ttl = 0;
|
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_INIT(rdatalist->rdata);
|
|
|
|
ISC_LIST_APPEND(rdatalist->rdata, rdata, link);
|
|
|
|
dns_rdataset_init(rdataset);
|
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
|
|
|
|
|
|
|
failure:
|
|
|
|
if (name != NULL)
|
|
|
|
dns_message_puttempname(updatemsg, &name);
|
|
|
|
return (STATUS_SYNTAX);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
2000-06-30 01:56:14 +00:00
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
static isc_uint16_t
|
2000-06-30 03:24:27 +00:00
|
|
|
evaluate_prereq(char *cmdline) {
|
|
|
|
char *word;
|
2000-06-30 01:56:14 +00:00
|
|
|
isc_boolean_t 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");
|
2000-06-30 03:45:54 +00:00
|
|
|
if (*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) {
|
2000-06-30 01:56:14 +00:00
|
|
|
ispositive = ISC_FALSE;
|
|
|
|
isrrset = ISC_FALSE;
|
2000-06-30 03:24:27 +00:00
|
|
|
} else if (strcasecmp(word, "yxdomain") == 0) {
|
2000-06-30 01:56:14 +00:00
|
|
|
ispositive = ISC_TRUE;
|
|
|
|
isrrset = ISC_FALSE;
|
2000-06-30 03:24:27 +00:00
|
|
|
} else if (strcasecmp(word, "nxrrset") == 0) {
|
2000-06-30 01:56:14 +00:00
|
|
|
ispositive = ISC_FALSE;
|
|
|
|
isrrset = ISC_TRUE;
|
2000-06-30 03:24:27 +00:00
|
|
|
} else if (strcasecmp(word, "yxrrset") == 0) {
|
2000-06-30 01:56:14 +00:00
|
|
|
ispositive = ISC_TRUE;
|
|
|
|
isrrset = ISC_TRUE;
|
|
|
|
} 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
|
|
|
}
|
|
|
|
|
|
|
|
static isc_uint16_t
|
2000-06-30 03:24:27 +00:00
|
|
|
evaluate_server(char *cmdline) {
|
2000-07-05 23:24:18 +00:00
|
|
|
char *word, *server;
|
2000-08-01 14:02:41 +00: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");
|
|
|
|
if (*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");
|
|
|
|
if (*word == 0)
|
2009-06-10 00:27:22 +00:00
|
|
|
port = dnsport;
|
2000-07-05 23:24:18 +00:00
|
|
|
else {
|
|
|
|
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) {
|
|
|
|
fprintf(stderr, "port '%s' is out of range "
|
|
|
|
"(1 to 65535)\n", word);
|
|
|
|
return (STATUS_SYNTAX);
|
2000-07-05 23:24:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (userserver == NULL) {
|
|
|
|
userserver = isc_mem_get(mctx, sizeof(isc_sockaddr_t));
|
|
|
|
if (userserver == NULL)
|
|
|
|
fatal("out of memory");
|
|
|
|
}
|
|
|
|
|
2000-08-01 14:02:41 +00:00
|
|
|
get_address(server, (in_port_t)port, userserver);
|
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
|
|
|
}
|
|
|
|
|
2000-11-16 05:40:25 +00:00
|
|
|
static isc_uint16_t
|
|
|
|
evaluate_local(char *cmdline) {
|
|
|
|
char *word, *local;
|
|
|
|
long port;
|
2001-02-24 21:02:38 +00:00
|
|
|
struct in_addr in4;
|
|
|
|
struct in6_addr in6;
|
2000-11-16 05:40:25 +00:00
|
|
|
|
|
|
|
word = nsu_strsep(&cmdline, " \t\r\n");
|
|
|
|
if (*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");
|
|
|
|
if (*word == 0)
|
|
|
|
port = 0;
|
|
|
|
else {
|
|
|
|
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) {
|
|
|
|
fprintf(stderr, "port '%s' is out of range "
|
|
|
|
"(1 to 65535)\n", word);
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (localaddr == NULL) {
|
|
|
|
localaddr = isc_mem_get(mctx, sizeof(isc_sockaddr_t));
|
|
|
|
if (localaddr == NULL)
|
|
|
|
fatal("out of memory");
|
|
|
|
}
|
|
|
|
|
2001-02-24 21:02:38 +00:00
|
|
|
if (have_ipv6 && inet_pton(AF_INET6, local, &in6) == 1)
|
|
|
|
isc_sockaddr_fromin6(localaddr, &in6, (in_port_t)port);
|
|
|
|
else if (have_ipv4 && inet_pton(AF_INET, local, &in4) == 1)
|
|
|
|
isc_sockaddr_fromin(localaddr, &in4, (in_port_t)port);
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "invalid address %s", local);
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
2000-11-16 05:40:25 +00:00
|
|
|
|
|
|
|
return (STATUS_MORE);
|
|
|
|
}
|
|
|
|
|
2001-07-02 06:09:28 +00:00
|
|
|
static isc_uint16_t
|
|
|
|
evaluate_key(char *cmdline) {
|
|
|
|
char *namestr;
|
|
|
|
char *secretstr;
|
|
|
|
isc_buffer_t b;
|
|
|
|
isc_result_t result;
|
|
|
|
dns_fixedname_t fkeyname;
|
|
|
|
dns_name_t *keyname;
|
|
|
|
int secretlen;
|
|
|
|
unsigned char *secret = NULL;
|
|
|
|
isc_buffer_t secretbuf;
|
2006-01-27 02:35:15 +00:00
|
|
|
dns_name_t *hmacname = NULL;
|
|
|
|
isc_uint16_t digestbits = 0;
|
|
|
|
char *n;
|
2001-07-02 06:09:28 +00:00
|
|
|
|
|
|
|
namestr = nsu_strsep(&cmdline, " \t\r\n");
|
|
|
|
if (*namestr == 0) {
|
|
|
|
fprintf(stderr, "could not read key name\n");
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
|
|
|
|
|
|
|
dns_fixedname_init(&fkeyname);
|
|
|
|
keyname = dns_fixedname_name(&fkeyname);
|
|
|
|
|
2006-01-27 02:35:15 +00:00
|
|
|
n = strchr(namestr, ':');
|
|
|
|
if (n != NULL) {
|
|
|
|
digestbits = parse_hmac(&hmacname, namestr, n - namestr);
|
|
|
|
namestr = n + 1;
|
|
|
|
} else
|
|
|
|
hmacname = DNS_TSIG_HMACMD5_NAME;
|
|
|
|
|
2001-07-02 06:09:28 +00:00
|
|
|
isc_buffer_init(&b, namestr, strlen(namestr));
|
|
|
|
isc_buffer_add(&b, strlen(namestr));
|
2009-09-01 00:22:28 +00:00
|
|
|
result = dns_name_fromtext(keyname, &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");
|
2001-07-02 06:09:28 +00:00
|
|
|
if (*secretstr == 0) {
|
|
|
|
fprintf(stderr, "could not read key secret\n");
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
|
|
|
secretlen = strlen(secretstr) * 3 / 4;
|
|
|
|
secret = isc_mem_allocate(mctx, secretlen);
|
|
|
|
if (secret == NULL)
|
|
|
|
fatal("out of memory");
|
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) {
|
2001-07-02 18:56:58 +00:00
|
|
|
fprintf(stderr, "could not create key from %s: %s\n",
|
2001-07-02 06:09:28 +00:00
|
|
|
secretstr, isc_result_totext(result));
|
|
|
|
isc_mem_free(mctx, secret);
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
|
|
|
secretlen = isc_buffer_usedlength(&secretbuf);
|
|
|
|
|
2002-01-21 07:59:15 +00:00
|
|
|
if (tsigkey != NULL)
|
|
|
|
dns_tsigkey_detach(&tsigkey);
|
2006-01-27 02:35:15 +00:00
|
|
|
result = dns_tsigkey_create(keyname, hmacname, secret, secretlen,
|
2010-07-09 05:13:15 +00:00
|
|
|
ISC_FALSE, NULL, 0, 0, mctx, NULL,
|
2006-01-27 02:35:15 +00:00
|
|
|
&tsigkey);
|
2001-07-02 06:09:28 +00:00
|
|
|
isc_mem_free(mctx, secret);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2001-07-02 18:56:58 +00:00
|
|
|
fprintf(stderr, "could not create key from %s %s: %s\n",
|
2001-07-02 06:09:28 +00:00
|
|
|
namestr, secretstr, dns_result_totext(result));
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2000-06-20 22:50:13 +00:00
|
|
|
static isc_uint16_t
|
2000-06-30 03:24:27 +00:00
|
|
|
evaluate_zone(char *cmdline) {
|
2000-07-05 23:24:18 +00:00
|
|
|
char *word;
|
|
|
|
isc_buffer_t b;
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
word = nsu_strsep(&cmdline, " \t\r\n");
|
|
|
|
if (*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);
|
|
|
|
}
|
|
|
|
|
|
|
|
dns_fixedname_init(&fuserzone);
|
|
|
|
userzone = dns_fixedname_name(&fuserzone);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-07-09 05:13:15 +00:00
|
|
|
static isc_uint16_t
|
|
|
|
evaluate_realm(char *cmdline) {
|
|
|
|
#ifdef GSSAPI
|
|
|
|
char *word;
|
|
|
|
char buf[1024];
|
|
|
|
|
|
|
|
word = nsu_strsep(&cmdline, " \t\r\n");
|
|
|
|
if (*word == 0) {
|
|
|
|
if (realm != NULL)
|
|
|
|
isc_mem_free(mctx, realm);
|
|
|
|
realm = NULL;
|
|
|
|
return (STATUS_MORE);
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "@%s", word);
|
|
|
|
realm = isc_mem_strdup(mctx, buf);
|
|
|
|
if (realm == NULL)
|
|
|
|
fatal("out of memory");
|
|
|
|
return (STATUS_MORE);
|
|
|
|
#else
|
2010-07-09 23:46:51 +00:00
|
|
|
UNUSED(cmdline);
|
2010-07-09 05:13:15 +00:00
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-09-24 02:46:23 +00:00
|
|
|
static isc_uint16_t
|
|
|
|
evaluate_ttl(char *cmdline) {
|
|
|
|
char *word;
|
|
|
|
isc_result_t result;
|
|
|
|
isc_uint32_t ttl;
|
|
|
|
|
|
|
|
word = nsu_strsep(&cmdline, " \t\r\n");
|
|
|
|
if (*word == 0) {
|
|
|
|
fprintf(stderr, "could not ttl\n");
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
|
|
|
|
2008-09-25 02:20:27 +00:00
|
|
|
if (!strcasecmp(word, "none")) {
|
|
|
|
default_ttl = 0;
|
|
|
|
default_ttl_set = ISC_FALSE;
|
|
|
|
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);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
|
|
|
|
if (ttl > TTL_MAX) {
|
|
|
|
fprintf(stderr, "ttl '%s' is out of range (0 to %u)\n",
|
|
|
|
word, TTL_MAX);
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
|
|
|
default_ttl = ttl;
|
|
|
|
default_ttl_set = ISC_TRUE;
|
2008-09-24 03:16:58 +00:00
|
|
|
|
2008-09-24 02:46:23 +00:00
|
|
|
return (STATUS_MORE);
|
|
|
|
}
|
|
|
|
|
2004-03-03 23:43:09 +00:00
|
|
|
static isc_uint16_t
|
|
|
|
evaluate_class(char *cmdline) {
|
|
|
|
char *word;
|
|
|
|
isc_textregion_t r;
|
|
|
|
isc_result_t result;
|
|
|
|
dns_rdataclass_t rdclass;
|
|
|
|
|
|
|
|
word = nsu_strsep(&cmdline, " \t\r\n");
|
|
|
|
if (*word == 0) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
static isc_uint16_t
|
2000-06-30 03:24:27 +00:00
|
|
|
update_addordelete(char *cmdline, isc_boolean_t isdelete) {
|
2000-06-10 00:50:36 +00:00
|
|
|
isc_result_t result;
|
|
|
|
dns_name_t *name = NULL;
|
2001-11-30 01:02:18 +00:00
|
|
|
isc_uint32_t ttl;
|
2000-06-30 03:24:27 +00:00
|
|
|
char *word;
|
2000-06-30 01:56:14 +00:00
|
|
|
dns_rdataclass_t rdataclass;
|
2000-06-10 00:50:36 +00:00
|
|
|
dns_rdatatype_t rdatatype;
|
2000-06-27 21:59:44 +00:00
|
|
|
dns_rdata_t *rdata = NULL;
|
2000-06-10 00:50:36 +00:00
|
|
|
dns_rdatalist_t *rdatalist = NULL;
|
|
|
|
dns_rdataset_t *rdataset = NULL;
|
|
|
|
isc_textregion_t region;
|
2000-06-30 21:47:35 +00:00
|
|
|
isc_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);
|
|
|
|
if (retval != STATUS_MORE)
|
|
|
|
return (retval);
|
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");
|
|
|
|
if (*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;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if (isdelete)
|
2000-06-30 01:56:14 +00:00
|
|
|
ttl = 0;
|
2001-11-07 04:44:09 +00:00
|
|
|
else if (ttl > TTL_MAX) {
|
2003-07-25 00:01:16 +00:00
|
|
|
fprintf(stderr, "ttl '%s' is out of range (0 to %u)\n",
|
2001-01-21 19:52:06 +00:00
|
|
|
word, TTL_MAX);
|
|
|
|
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");
|
|
|
|
parseclass:
|
2000-06-30 03:45:54 +00:00
|
|
|
if (*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");
|
2000-06-30 03:45:54 +00:00
|
|
|
if (*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) {
|
|
|
|
fprintf(stderr, "'%s' is not a valid type: %s\n",
|
|
|
|
word, isc_result_totext(result));
|
|
|
|
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) {
|
|
|
|
fprintf(stderr, "'%s' is not a valid class or type: "
|
|
|
|
"%s\n", word, isc_result_totext(result));
|
|
|
|
goto failure;
|
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
2000-06-30 21:47:35 +00:00
|
|
|
retval = parse_rdata(&cmdline, rdataclass, rdatatype, updatemsg,
|
2000-10-25 04:26:57 +00:00
|
|
|
rdata);
|
2000-06-30 21:47:35 +00:00
|
|
|
if (retval != STATUS_MORE)
|
|
|
|
goto failure;
|
2000-06-30 03:24:27 +00:00
|
|
|
|
2000-06-30 21:47:35 +00:00
|
|
|
if (isdelete) {
|
2000-10-25 04:26:57 +00:00
|
|
|
if ((rdata->flags & DNS_RDATA_UPDATE) != 0)
|
2000-06-30 01:56:14 +00:00
|
|
|
rdataclass = dns_rdataclass_any;
|
2000-06-30 21:47:35 +00:00
|
|
|
else
|
|
|
|
rdataclass = dns_rdataclass_none;
|
|
|
|
} 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
|
|
|
}
|
|
|
|
|
2000-06-30 01:56:14 +00: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");
|
|
|
|
dns_rdatalist_init(rdatalist);
|
|
|
|
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_INIT(rdatalist->rdata);
|
|
|
|
ISC_LIST_APPEND(rdatalist->rdata, rdata, link);
|
|
|
|
dns_rdataset_init(rdataset);
|
|
|
|
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
|
|
|
|
|
|
|
failure:
|
|
|
|
if (name != NULL)
|
|
|
|
dns_message_puttempname(updatemsg, &name);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static isc_uint16_t
|
2000-06-30 03:24:27 +00:00
|
|
|
evaluate_update(char *cmdline) {
|
|
|
|
char *word;
|
2000-06-30 01:56:14 +00:00
|
|
|
isc_boolean_t 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");
|
2000-06-30 03:45:54 +00:00
|
|
|
if (*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, "delete") == 0)
|
2000-06-30 01:56:14 +00:00
|
|
|
isdelete = ISC_TRUE;
|
2000-06-30 03:24:27 +00:00
|
|
|
else if (strcasecmp(word, "add") == 0)
|
2000-06-30 01:56:14 +00:00
|
|
|
isdelete = ISC_FALSE;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2006-03-02 01:57:20 +00:00
|
|
|
static void
|
|
|
|
setzone(dns_name_t *zonename) {
|
|
|
|
isc_result_t result;
|
|
|
|
dns_name_t *name = NULL;
|
|
|
|
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);
|
|
|
|
for (rdataset = ISC_LIST_HEAD(name->list);
|
|
|
|
rdataset != NULL;
|
|
|
|
rdataset = ISC_LIST_HEAD(name->list)) {
|
|
|
|
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_init(name, NULL);
|
|
|
|
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
|
2006-12-04 01:54:53 +00:00
|
|
|
show_message(FILE *stream, dns_message_t *msg, const char *description) {
|
2000-06-10 00:50:36 +00:00
|
|
|
isc_result_t result;
|
2000-09-28 21:39:26 +00:00
|
|
|
isc_buffer_t *buf = NULL;
|
|
|
|
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 "
|
2000-09-28 21:50:22 +00:00
|
|
|
"buffer to display message\n");
|
2000-09-28 21:39:26 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (buf != NULL)
|
|
|
|
isc_buffer_free(&buf);
|
|
|
|
result = isc_buffer_allocate(mctx, &buf, bufsz);
|
|
|
|
check_result(result, "isc_buffer_allocate");
|
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,
|
|
|
|
(int)isc_buffer_usedlength(buf), (char*)isc_buffer_base(buf));
|
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
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
|
|
|
|
static isc_uint16_t
|
2000-06-30 01:56:14 +00:00
|
|
|
get_next_command(void) {
|
2000-06-30 03:24:27 +00:00
|
|
|
char cmdlinebuf[MAXCMD];
|
|
|
|
char *cmdline;
|
|
|
|
char *word;
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-07-09 16:17:13 +00:00
|
|
|
ddebug("get_next_command()");
|
2006-06-09 07:26:42 +00:00
|
|
|
if (interactive) {
|
2000-11-27 17:56:35 +00:00
|
|
|
fprintf(stdout, "> ");
|
2006-06-09 07:26:42 +00:00
|
|
|
fflush(stdout);
|
|
|
|
}
|
2001-03-09 18:18:42 +00:00
|
|
|
isc_app_block();
|
2000-11-27 00:43:33 +00:00
|
|
|
cmdline = fgets(cmdlinebuf, MAXCMD, input);
|
2001-03-09 18:18:42 +00:00
|
|
|
isc_app_unblock();
|
2000-09-01 21:34:12 +00:00
|
|
|
if (cmdline == NULL)
|
|
|
|
return (STATUS_QUIT);
|
2000-06-30 03:24:27 +00:00
|
|
|
word = nsu_strsep(&cmdline, " \t\r\n");
|
2000-06-20 22:50:13 +00:00
|
|
|
|
2000-11-27 00:43:33 +00:00
|
|
|
if (feof(input))
|
2000-06-30 03:24:27 +00:00
|
|
|
return (STATUS_QUIT);
|
2000-06-30 03:45:54 +00:00
|
|
|
if (*word == 0)
|
2000-06-30 03:24:27 +00:00
|
|
|
return (STATUS_SEND);
|
2001-03-30 22:48:35 +00:00
|
|
|
if (word[0] == ';')
|
|
|
|
return (STATUS_MORE);
|
2000-06-30 03:24:27 +00:00
|
|
|
if (strcasecmp(word, "quit") == 0)
|
|
|
|
return (STATUS_QUIT);
|
|
|
|
if (strcasecmp(word, "prereq") == 0)
|
|
|
|
return (evaluate_prereq(cmdline));
|
|
|
|
if (strcasecmp(word, "update") == 0)
|
|
|
|
return (evaluate_update(cmdline));
|
|
|
|
if (strcasecmp(word, "server") == 0)
|
|
|
|
return (evaluate_server(cmdline));
|
2000-11-16 05:40:25 +00:00
|
|
|
if (strcasecmp(word, "local") == 0)
|
|
|
|
return (evaluate_local(cmdline));
|
2000-06-30 03:24:27 +00:00
|
|
|
if (strcasecmp(word, "zone") == 0)
|
|
|
|
return (evaluate_zone(cmdline));
|
2004-03-03 23:43:09 +00:00
|
|
|
if (strcasecmp(word, "class") == 0)
|
|
|
|
return (evaluate_class(cmdline));
|
2000-06-30 03:24:27 +00:00
|
|
|
if (strcasecmp(word, "send") == 0)
|
|
|
|
return (STATUS_SEND);
|
2008-09-24 02:46:23 +00:00
|
|
|
if (strcasecmp(word, "debug") == 0) {
|
|
|
|
if (debugging)
|
|
|
|
ddebugging = ISC_TRUE;
|
|
|
|
else
|
|
|
|
debugging = ISC_TRUE;
|
|
|
|
return (STATUS_MORE);
|
|
|
|
}
|
|
|
|
if (strcasecmp(word, "ttl") == 0)
|
|
|
|
return (evaluate_ttl(cmdline));
|
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) {
|
|
|
|
if (answer != NULL)
|
2006-12-04 01:54:53 +00:00
|
|
|
show_message(stdout, answer, "Answer:");
|
2004-03-04 01:21:39 +00:00
|
|
|
return (STATUS_MORE);
|
|
|
|
}
|
2007-09-14 06:43:12 +00:00
|
|
|
if (strcasecmp(word, "key") == 0) {
|
|
|
|
usegsstsig = ISC_FALSE;
|
2001-07-02 06:09:28 +00:00
|
|
|
return (evaluate_key(cmdline));
|
2007-09-14 06:43:12 +00:00
|
|
|
}
|
2010-07-09 05:13:15 +00:00
|
|
|
if (strcasecmp(word, "realm") == 0)
|
|
|
|
return (evaluate_realm(cmdline));
|
2006-12-04 01:54:53 +00:00
|
|
|
if (strcasecmp(word, "gsstsig") == 0) {
|
|
|
|
#ifdef GSSAPI
|
|
|
|
usegsstsig = ISC_TRUE;
|
|
|
|
use_win2k_gsstsig = ISC_FALSE;
|
|
|
|
#else
|
|
|
|
fprintf(stderr, "gsstsig not supported\n");
|
|
|
|
#endif
|
|
|
|
return (STATUS_MORE);
|
|
|
|
}
|
|
|
|
if (strcasecmp(word, "oldgsstsig") == 0) {
|
|
|
|
#ifdef GSSAPI
|
|
|
|
usegsstsig = ISC_TRUE;
|
|
|
|
use_win2k_gsstsig = ISC_TRUE;
|
|
|
|
#else
|
|
|
|
fprintf(stderr, "gsstsig not supported\n");
|
|
|
|
#endif
|
|
|
|
return (STATUS_MORE);
|
|
|
|
}
|
2007-09-14 06:43:12 +00:00
|
|
|
if (strcasecmp(word, "help") == 0) {
|
|
|
|
fprintf(stdout,
|
|
|
|
"local address [port] (set local resolver)\n"
|
|
|
|
"server address [port] (set master server for zone)\n"
|
|
|
|
"send (send the update request)\n"
|
|
|
|
"show (show the update request)\n"
|
2009-06-10 00:27:22 +00:00
|
|
|
"answer (show the answer to the last request)\n"
|
2007-09-14 06:43:12 +00:00
|
|
|
"quit (quit, any pending update is not sent\n"
|
2009-06-10 00:27:22 +00:00
|
|
|
"help (display this message_\n"
|
2007-09-14 06:43:12 +00: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"
|
|
|
|
"prereq nxdomain name (does this name not exist)\n"
|
|
|
|
"prereq yxdomain name (does this name exist)\n"
|
|
|
|
"prereq nxrrset .... (does this RRset exist)\n"
|
|
|
|
"prereq yxrrset .... (does this RRset not exist)\n"
|
|
|
|
"update add .... (add the given record to the zone)\n"
|
|
|
|
"update delete .... (remove the given record(s) from the zone)\n");
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static isc_boolean_t
|
2000-06-30 01:56:14 +00:00
|
|
|
user_interaction(void) {
|
2000-06-10 00:50:36 +00:00
|
|
|
isc_uint16_t result = STATUS_MORE;
|
|
|
|
|
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();
|
2007-04-24 07:02:31 +00:00
|
|
|
if (!interactive && result == STATUS_SYNTAX)
|
|
|
|
fatal("syntax error");
|
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
if (result == STATUS_SEND)
|
2000-06-30 01:56:14 +00:00
|
|
|
return (ISC_TRUE);
|
|
|
|
return (ISC_FALSE);
|
2000-06-10 00:50:36 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-09-01 21:34:12 +00:00
|
|
|
done_update(void) {
|
|
|
|
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
|
|
|
|
check_tsig_error(dns_rdataset_t *rdataset, isc_buffer_t *b) {
|
|
|
|
isc_result_t result;
|
|
|
|
dns_rdata_t rdata = DNS_RDATA_INIT;
|
|
|
|
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) {
|
|
|
|
if (isc_buffer_remaininglength(b) < 1)
|
|
|
|
check_result(ISC_R_NOSPACE, "isc_buffer_remaininglength");
|
|
|
|
isc__buffer_putstr(b, "(" /*)*/);
|
|
|
|
result = dns_tsigrcode_totext(tsig.error, b);
|
|
|
|
check_result(result, "dns_tsigrcode_totext");
|
|
|
|
if (isc_buffer_remaininglength(b) < 1)
|
|
|
|
check_result(ISC_R_NOSPACE, "isc_buffer_remaininglength");
|
|
|
|
isc__buffer_putstr(b, /*(*/ ")");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
static void
|
|
|
|
update_completed(isc_task_t *task, isc_event_t *event) {
|
2000-06-16 17:10:02 +00:00
|
|
|
dns_requestevent_t *reqev = NULL;
|
|
|
|
isc_result_t result;
|
2001-01-21 21:54:32 +00:00
|
|
|
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) {
|
2000-07-09 06:25:49 +00:00
|
|
|
fprintf(stderr, "; Communication with server failed: %s\n",
|
2000-06-30 01:56:14 +00:00
|
|
|
isc_result_totext(reqev->result));
|
2000-12-07 20:05:29 +00:00
|
|
|
seenerror = ISC_TRUE;
|
2000-06-16 17:10:02 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2004-03-04 01:21:39 +00:00
|
|
|
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &answer);
|
2000-06-16 17:10:02 +00:00
|
|
|
check_result(result, "dns_message_create");
|
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:
|
2006-12-04 01:54:53 +00:00
|
|
|
if (answer->verify_attempted)
|
|
|
|
ddebug("tsig verification successful");
|
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;
|
|
|
|
}
|
|
|
|
#endif
|
2001-07-02 06:09:28 +00:00
|
|
|
fprintf(stderr, "; TSIG error with server: %s\n",
|
|
|
|
isc_result_totext(result));
|
|
|
|
seenerror = ISC_TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
check_result(result, "dns_request_getresponse");
|
|
|
|
}
|
|
|
|
|
2004-03-04 01:21:39 +00:00
|
|
|
if (answer->rcode != dns_rcode_noerror) {
|
2000-12-07 20:05:29 +00:00
|
|
|
seenerror = ISC_TRUE;
|
2004-03-04 01:21:39 +00:00
|
|
|
if (!debugging) {
|
|
|
|
char buf[64];
|
|
|
|
isc_buffer_t b;
|
|
|
|
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);
|
|
|
|
if (rds != NULL)
|
|
|
|
check_tsig_error(rds, &b);
|
|
|
|
fprintf(stderr, "update failed: %.*s\n",
|
|
|
|
(int)isc_buffer_usedlength(&b), buf);
|
|
|
|
}
|
|
|
|
}
|
2006-12-04 01:54:53 +00:00
|
|
|
if (debugging)
|
|
|
|
show_message(stderr, answer, "\nReply from update query:");
|
|
|
|
|
2000-06-16 17:10:02 +00:00
|
|
|
done:
|
2001-01-21 21:54:32 +00:00
|
|
|
dns_request_destroy(&request);
|
2006-12-04 01:54:53 +00:00
|
|
|
if (usegsstsig) {
|
|
|
|
dns_name_free(&tmpzonename, mctx);
|
|
|
|
dns_name_free(&restart_master, mctx);
|
|
|
|
}
|
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
|
2000-11-16 05:40:25 +00:00
|
|
|
send_update(dns_name_t *zonename, isc_sockaddr_t *master,
|
|
|
|
isc_sockaddr_t *srcaddr)
|
|
|
|
{
|
2000-06-10 00:50:36 +00:00
|
|
|
isc_result_t result;
|
|
|
|
dns_request_t *request = NULL;
|
2010-03-04 05:24:56 +00:00
|
|
|
unsigned int options = DNS_REQUESTOPT_CASE;
|
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
|
|
|
|
2006-03-02 01:57:20 +00:00
|
|
|
setzone(zonename);
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-06-30 18:59:21 +00:00
|
|
|
if (usevc)
|
|
|
|
options |= DNS_REQUESTOPT_TCP;
|
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];
|
|
|
|
|
|
|
|
isc_sockaddr_format(master, addrbuf, sizeof(addrbuf));
|
|
|
|
fprintf(stderr, "Sending update to %s\n", addrbuf);
|
|
|
|
}
|
2006-12-04 01:54:53 +00:00
|
|
|
|
2010-03-12 03:34:56 +00:00
|
|
|
/* Windows doesn't like the tsig name to be compressed. */
|
|
|
|
if (updatemsg->tsigname)
|
|
|
|
updatemsg->tsigname->attributes |= DNS_NAMEATTR_NOCOMPRESS;
|
|
|
|
|
2002-11-12 23:58:14 +00:00
|
|
|
result = dns_request_createvia3(requestmgr, updatemsg, srcaddr,
|
|
|
|
master, options, tsigkey, timeout,
|
|
|
|
udp_timeout, udp_retries, global_task,
|
|
|
|
update_completed, NULL, &request);
|
|
|
|
check_result(result, "dns_request_createvia3");
|
2001-09-10 12:30:46 +00:00
|
|
|
|
|
|
|
if (debugging)
|
2006-12-04 01:54:53 +00:00
|
|
|
show_message(stdout, updatemsg, "Outgoing update query:");
|
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
|
|
|
|
|
|
|
static void
|
2000-07-05 23:24:18 +00:00
|
|
|
recvsoa(isc_task_t *task, isc_event_t *event) {
|
2000-06-10 00:50:36 +00:00
|
|
|
dns_requestevent_t *reqev = NULL;
|
|
|
|
dns_request_t *request = NULL;
|
2000-06-30 01:56:14 +00:00
|
|
|
isc_result_t result, eresult;
|
2000-06-10 00:50:36 +00:00
|
|
|
dns_message_t *rcvmsg = NULL;
|
|
|
|
dns_section_t section;
|
|
|
|
dns_name_t *name = NULL;
|
2000-06-30 01:56:14 +00:00
|
|
|
dns_rdataset_t *soaset = NULL;
|
2000-06-10 00:50:36 +00:00
|
|
|
dns_rdata_soa_t soa;
|
2000-12-11 23:09:47 +00:00
|
|
|
dns_rdata_t soarr = DNS_RDATA_INIT;
|
2000-06-30 01:56:14 +00:00
|
|
|
int pass = 0;
|
2000-07-05 23:24:18 +00:00
|
|
|
dns_name_t master;
|
|
|
|
nsu_requestinfo_t *reqinfo;
|
|
|
|
dns_message_t *soaquery = NULL;
|
|
|
|
isc_sockaddr_t *addr;
|
2000-12-11 20:53:25 +00:00
|
|
|
isc_boolean_t seencname = ISC_FALSE;
|
2004-09-16 02:10:42 +00:00
|
|
|
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);
|
|
|
|
dns_message_destroy(&soaquery);
|
|
|
|
isc_mem_put(mctx, reqinfo, sizeof(nsu_requestinfo_t));
|
|
|
|
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) {
|
2000-07-05 23:24:18 +00:00
|
|
|
char addrbuf[ISC_SOCKADDR_FORMATSIZE];
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-07-05 23:24:18 +00:00
|
|
|
isc_sockaddr_format(addr, addrbuf, sizeof(addrbuf));
|
2000-07-09 06:25:49 +00:00
|
|
|
fprintf(stderr, "; Communication with %s failed: %s\n",
|
2006-12-04 01:54:53 +00:00
|
|
|
addrbuf, isc_result_totext(eresult));
|
2000-07-05 23:24:18 +00:00
|
|
|
if (userserver != NULL)
|
2001-07-02 18:56:58 +00:00
|
|
|
fatal("could not talk to specified name server");
|
2000-09-18 19:16:45 +00:00
|
|
|
else if (++ns_inuse >= lwconf->nsnext)
|
2001-07-02 18:56:58 +00:00
|
|
|
fatal("could not talk to any default name server");
|
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);
|
2000-12-11 20:53:25 +00:00
|
|
|
sendrequest(localaddr, &servers[ns_inuse], soaquery, &request);
|
2000-07-05 23:24:18 +00:00
|
|
|
isc_mem_put(mctx, 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
|
|
|
|
2006-12-07 05:39:41 +00:00
|
|
|
isc_mem_put(mctx, reqinfo, sizeof(nsu_requestinfo_t));
|
|
|
|
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");
|
2000-06-10 00:50:36 +00:00
|
|
|
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &rcvmsg);
|
|
|
|
check_result(result, "dns_message_create");
|
2000-10-06 18:58:30 +00:00
|
|
|
result = dns_request_getresponse(request, rcvmsg,
|
|
|
|
DNS_MESSAGEPARSE_PRESERVEORDER);
|
2004-03-04 05:33:03 +00:00
|
|
|
if (result == DNS_R_TSIGERRORSET && userserver != NULL) {
|
|
|
|
dns_message_destroy(&rcvmsg);
|
|
|
|
ddebug("Destroying request [%p]", request);
|
|
|
|
dns_request_destroy(&request);
|
|
|
|
reqinfo = isc_mem_get(mctx, sizeof(nsu_requestinfo_t));
|
|
|
|
if (reqinfo == NULL)
|
|
|
|
fatal("out of memory");
|
|
|
|
reqinfo->msg = soaquery;
|
|
|
|
reqinfo->addr = addr;
|
|
|
|
dns_message_renderreset(soaquery);
|
|
|
|
ddebug("retrying soa request without TSIG");
|
|
|
|
result = dns_request_createvia3(requestmgr, soaquery,
|
|
|
|
localaddr, addr, 0, NULL,
|
|
|
|
FIND_TIMEOUT * 20,
|
2006-01-06 04:45:11 +00:00
|
|
|
FIND_TIMEOUT, 3,
|
2004-03-04 05:33:03 +00:00
|
|
|
global_task, recvsoa, reqinfo,
|
|
|
|
&request);
|
|
|
|
check_result(result, "dns_request_createvia");
|
|
|
|
requests++;
|
|
|
|
return;
|
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
check_result(result, "dns_request_getresponse");
|
|
|
|
section = DNS_SECTION_ANSWER;
|
2006-12-04 01:54:53 +00:00
|
|
|
if (debugging)
|
|
|
|
show_message(stderr, rcvmsg, "Reply from SOA query:");
|
2000-06-16 17:10:02 +00:00
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
if (rcvmsg->rcode != dns_rcode_noerror &&
|
|
|
|
rcvmsg->rcode != dns_rcode_nxdomain)
|
|
|
|
fatal("response to SOA query was unsuccessful");
|
|
|
|
|
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));
|
|
|
|
error("specified zone '%s' does not exist (NXDOMAIN)",
|
|
|
|
namebuf);
|
|
|
|
dns_message_destroy(&rcvmsg);
|
|
|
|
dns_request_destroy(&request);
|
|
|
|
dns_message_destroy(&soaquery);
|
|
|
|
ddebug("Out of recvsoa");
|
|
|
|
done_update();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
lookforsoa:
|
|
|
|
if (pass == 0)
|
|
|
|
section = DNS_SECTION_ANSWER;
|
|
|
|
else if (pass == 1)
|
|
|
|
section = DNS_SECTION_AUTHORITY;
|
2008-01-18 23:46:58 +00:00
|
|
|
else
|
2004-09-16 02:10:42 +00:00
|
|
|
goto droplabel;
|
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);
|
|
|
|
if (result == ISC_R_SUCCESS)
|
|
|
|
break;
|
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,
|
2006-12-04 01:54:53 +00:00
|
|
|
&tset) == ISC_R_SUCCESS ) {
|
2000-12-11 20:53:25 +00:00
|
|
|
seencname = ISC_TRUE;
|
|
|
|
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
|
|
|
|
2004-09-16 02:10:42 +00:00
|
|
|
if (seencname)
|
|
|
|
goto droplabel;
|
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
|
|
|
|
2000-07-04 02:33:29 +00:00
|
|
|
dns_name_init(&master, NULL);
|
|
|
|
dns_name_clone(&soa.origin, &master);
|
|
|
|
|
2000-07-05 23:24:18 +00:00
|
|
|
if (userzone != NULL)
|
|
|
|
zonename = userzone;
|
|
|
|
else
|
|
|
|
zonename = name;
|
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];
|
2000-07-04 02:33:29 +00:00
|
|
|
dns_name_format(&master, namestr, sizeof(namestr));
|
2000-07-09 06:25:49 +00:00
|
|
|
fprintf(stderr, "The master is: %s\n", namestr);
|
2000-07-05 23:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (userserver != NULL)
|
|
|
|
serveraddr = userserver;
|
|
|
|
else {
|
2000-09-28 16:39:49 +00:00
|
|
|
char serverstr[DNS_NAME_MAXTEXT+1];
|
2000-07-05 23:24:18 +00:00
|
|
|
isc_buffer_t buf;
|
|
|
|
|
|
|
|
isc_buffer_init(&buf, serverstr, sizeof(serverstr));
|
|
|
|
result = dns_name_totext(&master, ISC_TRUE, &buf);
|
|
|
|
check_result(result, "dns_name_totext");
|
|
|
|
serverstr[isc_buffer_usedlength(&buf)] = 0;
|
2009-06-10 00:27:22 +00:00
|
|
|
get_address(serverstr, dnsport, &tempaddr);
|
2000-07-05 23:24:18 +00:00
|
|
|
serveraddr = &tempaddr;
|
2000-06-16 17:10:02 +00:00
|
|
|
}
|
2004-09-16 02:10:42 +00:00
|
|
|
dns_rdata_freestruct(&soa);
|
2000-06-16 17:10:02 +00:00
|
|
|
|
2006-12-04 01:54:53 +00:00
|
|
|
#ifdef GSSAPI
|
|
|
|
if (usegsstsig) {
|
|
|
|
dns_name_init(&tmpzonename, NULL);
|
|
|
|
dns_name_dup(zonename, mctx, &tmpzonename);
|
|
|
|
dns_name_init(&restart_master, NULL);
|
|
|
|
dns_name_dup(&master, mctx, &restart_master);
|
|
|
|
start_gssrequest(&master);
|
|
|
|
} else {
|
|
|
|
send_update(zonename, serveraddr, localaddr);
|
|
|
|
setzoneclass(dns_rdataclass_none);
|
|
|
|
}
|
|
|
|
#else
|
2000-11-16 05:40:25 +00:00
|
|
|
send_update(zonename, serveraddr, localaddr);
|
2004-09-16 02:10:42 +00:00
|
|
|
setzoneclass(dns_rdataclass_none);
|
2006-12-04 01:54:53 +00:00
|
|
|
#endif
|
2000-07-04 02:33:29 +00:00
|
|
|
|
2000-12-11 20:53:25 +00:00
|
|
|
dns_message_destroy(&soaquery);
|
|
|
|
dns_request_destroy(&request);
|
|
|
|
|
|
|
|
out:
|
2000-06-16 17:10:02 +00:00
|
|
|
dns_message_destroy(&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
|
|
|
|
2004-09-16 02:10:42 +00:00
|
|
|
droplabel:
|
|
|
|
result = dns_message_firstname(soaquery, DNS_SECTION_QUESTION);
|
|
|
|
INSIST(result == ISC_R_SUCCESS);
|
|
|
|
name = NULL;
|
|
|
|
dns_message_currentname(soaquery, DNS_SECTION_QUESTION, &name);
|
|
|
|
nlabels = dns_name_countlabels(name);
|
|
|
|
if (nlabels == 1)
|
|
|
|
fatal("could not find enclosing zone");
|
|
|
|
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);
|
2004-09-16 02:10:42 +00:00
|
|
|
if (userserver != NULL)
|
|
|
|
sendrequest(localaddr, userserver, soaquery, &request);
|
|
|
|
else
|
2006-12-04 01:54:53 +00:00
|
|
|
sendrequest(localaddr, &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
|
2000-11-16 05:40:25 +00:00
|
|
|
sendrequest(isc_sockaddr_t *srcaddr, isc_sockaddr_t *destaddr,
|
|
|
|
dns_message_t *msg, dns_request_t **request)
|
2000-07-05 23:24:18 +00:00
|
|
|
{
|
2000-06-30 01:56:14 +00:00
|
|
|
isc_result_t result;
|
2000-07-05 23:24:18 +00:00
|
|
|
nsu_requestinfo_t *reqinfo;
|
|
|
|
|
|
|
|
reqinfo = isc_mem_get(mctx, sizeof(nsu_requestinfo_t));
|
|
|
|
if (reqinfo == NULL)
|
|
|
|
fatal("out of memory");
|
|
|
|
reqinfo->msg = msg;
|
2000-11-16 05:40:25 +00:00
|
|
|
reqinfo->addr = destaddr;
|
2004-03-03 22:57:33 +00:00
|
|
|
result = dns_request_createvia3(requestmgr, msg, srcaddr, destaddr, 0,
|
|
|
|
(userserver != NULL) ? tsigkey : NULL,
|
|
|
|
FIND_TIMEOUT * 20, FIND_TIMEOUT, 3,
|
|
|
|
global_task, recvsoa, reqinfo, request);
|
2000-11-16 05:40:25 +00:00
|
|
|
check_result(result, "dns_request_createvia");
|
2001-04-13 01:32:14 +00:00
|
|
|
requests++;
|
2000-06-30 01:56:14 +00:00
|
|
|
}
|
|
|
|
|
2006-12-04 01:54:53 +00:00
|
|
|
#ifdef GSSAPI
|
|
|
|
static void
|
|
|
|
start_gssrequest(dns_name_t *master)
|
|
|
|
{
|
|
|
|
gss_ctx_id_t context;
|
|
|
|
isc_buffer_t buf;
|
|
|
|
isc_result_t result;
|
|
|
|
isc_uint32_t val = 0;
|
|
|
|
dns_message_t *rmsg;
|
|
|
|
dns_request_t *request = NULL;
|
|
|
|
dns_name_t *servname;
|
|
|
|
dns_fixedname_t fname;
|
|
|
|
char namestr[DNS_NAME_FORMATSIZE];
|
|
|
|
char keystr[DNS_NAME_FORMATSIZE];
|
|
|
|
|
|
|
|
debug("start_gssrequest");
|
|
|
|
usevc = ISC_TRUE;
|
|
|
|
|
|
|
|
if (gssring != NULL)
|
|
|
|
dns_tsigkeyring_destroy(&gssring);
|
|
|
|
gssring = NULL;
|
|
|
|
result = dns_tsigkeyring_create(mctx, &gssring);
|
2008-01-18 23:46:58 +00:00
|
|
|
|
2007-09-14 06:43:12 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("dns_tsigkeyring_create failed: %s",
|
|
|
|
isc_result_totext(result));
|
2006-12-04 01:54:53 +00:00
|
|
|
|
|
|
|
dns_name_format(master, namestr, sizeof(namestr));
|
|
|
|
if (kserver == NULL) {
|
|
|
|
kserver = isc_mem_get(mctx, sizeof(isc_sockaddr_t));
|
|
|
|
if (kserver == NULL)
|
|
|
|
fatal("out of memory");
|
|
|
|
}
|
|
|
|
if (userserver == NULL)
|
2009-06-10 00:27:22 +00:00
|
|
|
get_address(namestr, dnsport, kserver);
|
2006-12-04 01:54:53 +00:00
|
|
|
else
|
|
|
|
(void)memcpy(kserver, userserver, sizeof(isc_sockaddr_t));
|
|
|
|
|
|
|
|
dns_fixedname_init(&fname);
|
|
|
|
servname = dns_fixedname_name(&fname);
|
|
|
|
|
2007-09-14 06:43:12 +00:00
|
|
|
result = isc_string_printf(servicename, sizeof(servicename),
|
2010-07-09 05:13:15 +00:00
|
|
|
"DNS/%s%s", namestr, realm ? realm : "");
|
2007-09-14 06:43:12 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("isc_string_printf(servicename) failed: %s",
|
|
|
|
isc_result_totext(result));
|
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);
|
2007-09-14 06:43:12 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("dns_name_fromtext(servname) failed: %s",
|
|
|
|
isc_result_totext(result));
|
2008-01-18 23:46:58 +00:00
|
|
|
|
2006-12-04 01:54:53 +00:00
|
|
|
dns_fixedname_init(&fkname);
|
|
|
|
keyname = dns_fixedname_name(&fkname);
|
|
|
|
|
|
|
|
isc_random_get(&val);
|
2007-09-14 06:43:12 +00:00
|
|
|
result = isc_string_printf(keystr, sizeof(keystr), "%u.sig-%s",
|
|
|
|
val, namestr);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("isc_string_printf(keystr) failed: %s",
|
|
|
|
isc_result_totext(result));
|
2006-12-04 01:54:53 +00:00
|
|
|
isc_buffer_init(&buf, keystr, strlen(keystr));
|
|
|
|
isc_buffer_add(&buf, strlen(keystr));
|
|
|
|
|
2009-09-01 00:22:28 +00:00
|
|
|
result = dns_name_fromtext(keyname, &buf, dns_rootname, 0, NULL);
|
2007-09-14 06:43:12 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("dns_name_fromtext(keyname) failed: %s",
|
|
|
|
isc_result_totext(result));
|
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;
|
|
|
|
result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &rmsg);
|
2007-09-14 06:43:12 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("dns_message_create failed: %s",
|
|
|
|
isc_result_totext(result));
|
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,
|
|
|
|
&context, use_win2k_gsstsig);
|
|
|
|
if (result == ISC_R_FAILURE)
|
|
|
|
fatal("Check your Kerberos ticket, it may have expired.");
|
2007-09-14 06:43:12 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("dns_tkey_buildgssquery failed: %s",
|
|
|
|
isc_result_totext(result));
|
2006-12-04 01:54:53 +00:00
|
|
|
|
|
|
|
send_gssrequest(localaddr, kserver, rmsg, &request, context);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
send_gssrequest(isc_sockaddr_t *srcaddr, isc_sockaddr_t *destaddr,
|
|
|
|
dns_message_t *msg, dns_request_t **request,
|
|
|
|
gss_ctx_id_t context)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
|
|
|
nsu_gssinfo_t *reqinfo;
|
|
|
|
unsigned int options = 0;
|
|
|
|
|
|
|
|
debug("send_gssrequest");
|
|
|
|
reqinfo = isc_mem_get(mctx, sizeof(nsu_gssinfo_t));
|
|
|
|
if (reqinfo == NULL)
|
|
|
|
fatal("out of memory");
|
|
|
|
reqinfo->msg = msg;
|
|
|
|
reqinfo->addr = destaddr;
|
|
|
|
reqinfo->context = context;
|
|
|
|
|
|
|
|
options |= DNS_REQUESTOPT_TCP;
|
|
|
|
result = dns_request_createvia3(requestmgr, msg, srcaddr, destaddr,
|
|
|
|
options, tsigkey, FIND_TIMEOUT * 20,
|
|
|
|
FIND_TIMEOUT, 3, global_task, recvgss,
|
|
|
|
reqinfo, request);
|
|
|
|
check_result(result, "dns_request_createvia3");
|
|
|
|
if (debugging)
|
|
|
|
show_message(stdout, msg, "Outgoing update query:");
|
|
|
|
requests++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recvgss(isc_task_t *task, isc_event_t *event) {
|
|
|
|
dns_requestevent_t *reqev = NULL;
|
|
|
|
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;
|
|
|
|
gss_ctx_id_t context;
|
|
|
|
isc_buffer_t buf;
|
|
|
|
dns_name_t *servname;
|
|
|
|
dns_fixedname_t fname;
|
|
|
|
|
|
|
|
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);
|
|
|
|
dns_message_destroy(&tsigquery);
|
|
|
|
isc_mem_put(mctx, reqinfo, sizeof(nsu_gssinfo_t));
|
|
|
|
isc_event_free(&event);
|
|
|
|
maybeshutdown();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eresult != ISC_R_SUCCESS) {
|
|
|
|
char addrbuf[ISC_SOCKADDR_FORMATSIZE];
|
|
|
|
|
|
|
|
isc_sockaddr_format(addr, addrbuf, sizeof(addrbuf));
|
|
|
|
fprintf(stderr, "; Communication with %s failed: %s\n",
|
|
|
|
addrbuf, isc_result_totext(eresult));
|
|
|
|
if (userserver != NULL)
|
|
|
|
fatal("could not talk to specified name server");
|
|
|
|
else if (++ns_inuse >= lwconf->nsnext)
|
|
|
|
fatal("could not talk to any default name server");
|
|
|
|
ddebug("Destroying request [%p]", request);
|
|
|
|
dns_request_destroy(&request);
|
|
|
|
dns_message_renderreset(tsigquery);
|
|
|
|
sendrequest(localaddr, &servers[ns_inuse], tsigquery,
|
|
|
|
&request);
|
|
|
|
isc_mem_put(mctx, reqinfo, sizeof(nsu_gssinfo_t));
|
|
|
|
isc_event_free(&event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
isc_mem_put(mctx, reqinfo, sizeof(nsu_gssinfo_t));
|
|
|
|
|
|
|
|
isc_event_free(&event);
|
|
|
|
reqev = NULL;
|
|
|
|
|
|
|
|
ddebug("recvgss creating rcvmsg");
|
|
|
|
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &rcvmsg);
|
|
|
|
check_result(result, "dns_message_create");
|
|
|
|
|
|
|
|
result = dns_request_getresponse(request, rcvmsg,
|
|
|
|
DNS_MESSAGEPARSE_PRESERVEORDER);
|
|
|
|
check_result(result, "dns_request_getresponse");
|
|
|
|
|
2008-01-18 23:46:58 +00:00
|
|
|
if (debugging)
|
2006-12-04 01:54:53 +00:00
|
|
|
show_message(stderr, rcvmsg,
|
|
|
|
"recvmsg reply from GSS-TSIG query");
|
|
|
|
|
|
|
|
if (rcvmsg->rcode == dns_rcode_formerr && !tried_other_gsstsig) {
|
|
|
|
ddebug("recvgss trying %s GSS-TSIG",
|
|
|
|
use_win2k_gsstsig ? "Standard" : "Win2k");
|
|
|
|
if (use_win2k_gsstsig)
|
|
|
|
use_win2k_gsstsig = ISC_FALSE;
|
|
|
|
else
|
|
|
|
use_win2k_gsstsig = ISC_TRUE;
|
|
|
|
tried_other_gsstsig = ISC_TRUE;
|
|
|
|
start_gssrequest(&restart_master);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rcvmsg->rcode != dns_rcode_noerror &&
|
|
|
|
rcvmsg->rcode != dns_rcode_nxdomain)
|
|
|
|
fatal("response to GSS-TSIG query was unsuccessful");
|
|
|
|
|
|
|
|
|
|
|
|
dns_fixedname_init(&fname);
|
|
|
|
servname = dns_fixedname_name(&fname);
|
|
|
|
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;
|
|
|
|
result = dns_tkey_gssnegotiate(tsigquery, rcvmsg, servname,
|
2008-01-18 23:46:58 +00:00
|
|
|
&context, &tsigkey, gssring,
|
2006-12-04 01:54:53 +00:00
|
|
|
use_win2k_gsstsig);
|
|
|
|
switch (result) {
|
|
|
|
|
|
|
|
case DNS_R_CONTINUE:
|
|
|
|
send_gssrequest(localaddr, kserver, tsigquery, &request,
|
|
|
|
context);
|
|
|
|
break;
|
|
|
|
|
|
|
|
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);
|
|
|
|
ddebug("tsig verification: %s", dns_result_totext(result));
|
|
|
|
check_result(result, "dns_message_checksig");
|
|
|
|
#endif /* 0 */
|
|
|
|
|
|
|
|
send_update(&tmpzonename, serveraddr, localaddr);
|
|
|
|
setzoneclass(dns_rdataclass_none);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
fatal("dns_tkey_negotiategss: %s", isc_result_totext(result));
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
dns_request_destroy(&request);
|
|
|
|
dns_message_destroy(&tsigquery);
|
|
|
|
|
|
|
|
dns_message_destroy(&rcvmsg);
|
|
|
|
ddebug("Out of recvgss");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
static void
|
|
|
|
start_update(void) {
|
2001-07-12 04:13:39 +00:00
|
|
|
isc_result_t result;
|
2000-06-10 00:50:36 +00:00
|
|
|
dns_rdataset_t *rdataset = NULL;
|
|
|
|
dns_name_t *name = NULL;
|
|
|
|
dns_request_t *request = NULL;
|
2000-06-30 01:56:14 +00:00
|
|
|
dns_message_t *soaquery = NULL;
|
|
|
|
dns_name_t *firstname;
|
2004-05-12 04:48:23 +00:00
|
|
|
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()");
|
|
|
|
|
2004-03-04 01:21:39 +00:00
|
|
|
if (answer != NULL)
|
|
|
|
dns_message_destroy(&answer);
|
2000-06-30 03:24:27 +00:00
|
|
|
|
2006-12-04 01:54:53 +00:00
|
|
|
if (userzone != NULL && userserver != NULL && ! usegsstsig) {
|
2001-07-11 06:30:54 +00:00
|
|
|
send_update(userzone, userserver, localaddr);
|
2004-03-03 23:43:09 +00:00
|
|
|
setzoneclass(dns_rdataclass_none);
|
2001-07-11 06:30:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER,
|
2000-06-30 01:56:14 +00:00
|
|
|
&soaquery);
|
2000-06-10 00:50:36 +00:00
|
|
|
check_result(result, "dns_message_create");
|
|
|
|
|
2006-12-07 05:39:41 +00:00
|
|
|
if (userserver == NULL)
|
|
|
|
soaquery->flags |= DNS_MESSAGEFLAG_RD;
|
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_init(name, 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);
|
|
|
|
dns_message_destroy(&soaquery);
|
2006-12-07 05:39:41 +00:00
|
|
|
done_update();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
firstname = NULL;
|
|
|
|
dns_message_currentname(updatemsg, section, &firstname);
|
|
|
|
dns_name_init(name, NULL);
|
|
|
|
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) &&
|
2010-05-18 06:18:23 +00:00
|
|
|
tmprdataset->type == dns_rdatatype_ds) {
|
2010-03-09 03:46:12 +00:00
|
|
|
unsigned int labels = dns_name_countlabels(name);
|
|
|
|
dns_name_getlabelsequence(name, 1, labels - 1, name);
|
|
|
|
}
|
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
|
|
|
|
2000-07-05 23:24:18 +00:00
|
|
|
if (userserver != NULL)
|
2000-11-16 05:40:25 +00:00
|
|
|
sendrequest(localaddr, userserver, soaquery, &request);
|
2000-07-05 23:24:18 +00:00
|
|
|
else {
|
|
|
|
ns_inuse = 0;
|
2000-11-16 05:40:25 +00:00
|
|
|
sendrequest(localaddr, &servers[ns_inuse], soaquery, &request);
|
2000-07-05 23:24:18 +00:00
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-06-30 01:56:14 +00:00
|
|
|
cleanup(void) {
|
2000-07-09 16:17:13 +00:00
|
|
|
ddebug("cleanup()");
|
2000-06-17 00:16:50 +00:00
|
|
|
|
2004-03-04 01:21:39 +00:00
|
|
|
if (answer != NULL)
|
|
|
|
dns_message_destroy(&answer);
|
2006-12-04 01:54:53 +00:00
|
|
|
|
|
|
|
#ifdef 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) {
|
2006-12-04 01:54:53 +00:00
|
|
|
ddebug("Destroying GSS-TSIG keyring");
|
2007-09-14 06:43:12 +00:00
|
|
|
dns_tsigkeyring_destroy(&gssring);
|
2006-12-04 01:54:53 +00:00
|
|
|
}
|
2007-09-14 06:43:12 +00:00
|
|
|
if (kserver != NULL) {
|
2006-12-04 01:54:53 +00:00
|
|
|
isc_mem_put(mctx, kserver, sizeof(isc_sockaddr_t));
|
2007-09-14 06:43:12 +00:00
|
|
|
kserver = NULL;
|
|
|
|
}
|
2010-07-09 05:13:15 +00:00
|
|
|
if (realm != NULL) {
|
|
|
|
isc_mem_free(mctx, realm);
|
|
|
|
realm = NULL;
|
|
|
|
}
|
2006-12-04 01:54:53 +00:00
|
|
|
#endif
|
|
|
|
|
2000-06-17 00:16:50 +00:00
|
|
|
ddebug("Shutting down task manager");
|
|
|
|
isc_taskmgr_destroy(&taskmgr);
|
|
|
|
|
2000-11-22 02:54:15 +00:00
|
|
|
ddebug("Destroying event");
|
|
|
|
isc_event_free(&global_event);
|
|
|
|
|
2000-06-27 21:59:44 +00:00
|
|
|
ddebug("Shutting down socket manager");
|
|
|
|
isc_socketmgr_destroy(&socketmgr);
|
|
|
|
|
|
|
|
ddebug("Shutting down timer manager");
|
|
|
|
isc_timermgr_destroy(&timermgr);
|
|
|
|
|
2003-07-25 02:22:26 +00:00
|
|
|
ddebug("Destroying hash context");
|
|
|
|
isc_hash_destroy();
|
|
|
|
|
2005-09-18 07:16:24 +00:00
|
|
|
ddebug("Destroying name state");
|
|
|
|
dns_name_destroy();
|
|
|
|
|
2006-12-04 01:54:53 +00:00
|
|
|
ddebug("Removing log context");
|
|
|
|
isc_log_destroy(&lctx);
|
|
|
|
|
2000-06-17 00:16:50 +00:00
|
|
|
ddebug("Destroying memory context");
|
2000-11-08 00:55:26 +00:00
|
|
|
if (memdebugging)
|
2000-06-17 00:16:50 +00:00
|
|
|
isc_mem_stats(mctx, stderr);
|
|
|
|
isc_mem_destroy(&mctx);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
2000-09-01 21:34:12 +00:00
|
|
|
static void
|
|
|
|
getinput(isc_task_t *task, isc_event_t *event) {
|
|
|
|
isc_boolean_t more;
|
|
|
|
|
|
|
|
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
|
|
|
|
2000-09-01 21:34:12 +00:00
|
|
|
if (global_event == NULL)
|
|
|
|
global_event = event;
|
|
|
|
|
|
|
|
reset_system();
|
|
|
|
more = user_interaction();
|
|
|
|
if (!more) {
|
|
|
|
isc_app_shutdown();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
start_update();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
int
|
|
|
|
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;
|
|
|
|
|
2004-04-10 04:03:16 +00:00
|
|
|
interactive = ISC_TF(isatty(0));
|
|
|
|
|
2000-09-01 21:34:12 +00:00
|
|
|
isc_app_start();
|
|
|
|
|
2007-09-15 14:46:03 +00:00
|
|
|
pre_parse_args(argc, argv);
|
|
|
|
|
|
|
|
result = isc_mem_create(0, 0, &mctx);
|
|
|
|
check_result(result, "isc_mem_create");
|
|
|
|
|
|
|
|
parse_args(argc, argv, mctx, &entropy);
|
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
|
|
|
|
|
|
|
result = isc_app_onrun(mctx, global_task, getinput, NULL);
|
|
|
|
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();
|
|
|
|
|
2000-12-11 19:24:30 +00:00
|
|
|
if (seenerror)
|
2000-12-07 20:05:29 +00:00
|
|
|
return (2);
|
|
|
|
else
|
|
|
|
return (0);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|