2000-06-10 00:50:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2000 Internet Software Consortium.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2000-06-10 00:50:36 +00:00
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* 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
|
|
|
*
|
2000-07-27 09:55:03 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
|
|
|
|
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
|
|
|
* INTERNET SOFTWARE CONSORTIUM 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
|
|
|
*/
|
|
|
|
|
2000-10-19 16:31:05 +00:00
|
|
|
/* $Id: nsupdate.c,v 1.56 2000/10/19 16:31:05 bwelling Exp $ */
|
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 <netdb.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2000-09-18 23:23:12 +00:00
|
|
|
#if (!(defined(HAVE_ADDRINFO) && defined(HAVE_GETADDRINFO)))
|
|
|
|
extern int h_errno;
|
|
|
|
#endif
|
|
|
|
|
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>
|
2000-06-21 17:48:32 +00:00
|
|
|
#include <isc/lex.h>
|
2000-06-10 00:50:36 +00:00
|
|
|
#include <isc/mem.h>
|
|
|
|
#include <isc/region.h>
|
2000-06-21 17:48:32 +00:00
|
|
|
#include <isc/sockaddr.h>
|
|
|
|
#include <isc/socket.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
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
#include <dns/callbacks.h>
|
|
|
|
#include <dns/dispatch.h>
|
|
|
|
#include <dns/events.h>
|
2000-07-31 22:11:13 +00:00
|
|
|
#include <dns/fixedname.h>
|
2000-06-30 01:56:14 +00:00
|
|
|
#include <dns/message.h>
|
|
|
|
#include <dns/name.h>
|
|
|
|
#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>
|
|
|
|
#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
|
|
|
|
2000-09-28 16:39:49 +00:00
|
|
|
#define MAXCMD (4 * 1024)
|
2000-09-28 21:50:22 +00:00
|
|
|
#define INITDATA (32 * 1024)
|
2000-09-28 21:39:26 +00:00
|
|
|
#define MAXDATA (64 * 1024)
|
2000-06-10 00:50:36 +00:00
|
|
|
#define NAMEBUF 512
|
2000-06-30 03:24:27 +00:00
|
|
|
#define WORDLEN 512
|
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
|
2000-08-10 02:32:14 +00:00
|
|
|
#define TTL_MAX 2147483647 /* Maximum signed 32 bit integer. */
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-07-05 23:24:18 +00:00
|
|
|
#define DNSDEFAULTPORT 53
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
#define RESOLV_CONF "/etc/resolv.conf"
|
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
static isc_boolean_t debugging = ISC_FALSE, ddebugging = ISC_FALSE;
|
|
|
|
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;
|
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;
|
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;
|
|
|
|
static dns_fixedname_t resolvdomain; /* from resolv.conf's domain line */
|
2000-07-05 23:24:18 +00:00
|
|
|
static dns_name_t *origin; /* Points to one of above, or dns_rootname */
|
|
|
|
static dns_fixedname_t fuserzone;
|
|
|
|
static dns_name_t *userzone = NULL;
|
2000-06-30 01:56:14 +00:00
|
|
|
static dns_tsigkey_t *key = NULL;
|
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-07-03 23:42:48 +00:00
|
|
|
static char *keystr = NULL, *keyfile = NULL;
|
2000-06-30 01:56:14 +00:00
|
|
|
static isc_entropy_t *entp = NULL;
|
|
|
|
|
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
|
|
|
|
sendrequest(isc_sockaddr_t *address, dns_message_t *msg,
|
|
|
|
dns_request_t **request);
|
2000-06-10 00:50:36 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
count_dots(char *s, isc_boolean_t *last_was_dot) {
|
|
|
|
int i = 0;
|
|
|
|
*last_was_dot = ISC_FALSE;
|
|
|
|
while (*s != 0) {
|
|
|
|
if (*s++ == '.') {
|
|
|
|
i++;
|
|
|
|
*last_was_dot = ISC_TRUE;
|
|
|
|
} else
|
|
|
|
*last_was_dot = ISC_FALSE;
|
|
|
|
}
|
|
|
|
return (i);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2000-07-03 23:42:48 +00:00
|
|
|
static void
|
2000-08-01 14:02:41 +00:00
|
|
|
setup_key(void) {
|
2000-07-03 23:42:48 +00:00
|
|
|
unsigned char *secret = NULL;
|
|
|
|
int secretlen;
|
|
|
|
isc_buffer_t secretbuf;
|
|
|
|
isc_result_t result;
|
|
|
|
dns_fixedname_t fkeyname;
|
|
|
|
dns_name_t *keyname;
|
|
|
|
|
2000-08-02 02:34:40 +00:00
|
|
|
dns_fixedname_init(&fkeyname);
|
|
|
|
keyname = dns_fixedname_name(&fkeyname);
|
|
|
|
|
2000-07-03 23:42:48 +00:00
|
|
|
if (keystr != NULL) {
|
|
|
|
isc_buffer_t keynamesrc;
|
|
|
|
char *secretstr;
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
debug("Creating key...");
|
|
|
|
|
|
|
|
s = strchr(keystr, ':');
|
|
|
|
if (s == NULL || s == keystr || *s == 0)
|
|
|
|
fatal("key option must specify keyname:secret\n");
|
|
|
|
secretstr = s + 1;
|
|
|
|
|
|
|
|
isc_buffer_init(&keynamesrc, keystr, s - keystr);
|
|
|
|
isc_buffer_add(&keynamesrc, s - keystr);
|
|
|
|
|
|
|
|
debug("namefromtext");
|
|
|
|
result = dns_name_fromtext(keyname, &keynamesrc, dns_rootname,
|
|
|
|
ISC_FALSE, NULL);
|
|
|
|
check_result(result, "dns_name_fromtext");
|
|
|
|
|
|
|
|
secretlen = strlen(secretstr) * 3 / 4;
|
|
|
|
secret = isc_mem_allocate(mctx, secretlen);
|
|
|
|
if (secret == NULL)
|
|
|
|
fatal("out of memory");
|
|
|
|
|
|
|
|
isc_buffer_init(&secretbuf, secret, secretlen);
|
2000-07-17 17:42:54 +00:00
|
|
|
result = isc_base64_decodestring(mctx, secretstr, &secretbuf);
|
2000-07-03 23:42:48 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-07-09 06:25:49 +00:00
|
|
|
fprintf(stderr, "Couldn't create key from %s: %s\n",
|
2000-07-03 23:42:48 +00:00
|
|
|
keystr, isc_result_totext(result));
|
|
|
|
goto failure;
|
|
|
|
}
|
2000-07-17 17:42:54 +00:00
|
|
|
|
2000-07-03 23:42:48 +00:00
|
|
|
secretlen = isc_buffer_usedlength(&secretbuf);
|
|
|
|
debug("close");
|
|
|
|
} else {
|
|
|
|
dst_key_t *dstkey = NULL;
|
|
|
|
|
|
|
|
result = dst_key_fromnamedfile(keyfile, DST_TYPE_PRIVATE,
|
|
|
|
mctx, &dstkey);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-07-09 06:25:49 +00:00
|
|
|
fprintf(stderr, "Couldn't read key from %s: %s\n",
|
2000-07-03 23:42:48 +00:00
|
|
|
keyfile, isc_result_totext(result));
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
secretlen = (dst_key_size(dstkey) + 7) >> 3;
|
|
|
|
secret = isc_mem_allocate(mctx, secretlen);
|
|
|
|
if (secret == NULL)
|
|
|
|
fatal("out of memory");
|
|
|
|
isc_buffer_init(&secretbuf, secret, secretlen);
|
|
|
|
result = dst_key_tobuffer(dstkey, &secretbuf);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-07-09 06:25:49 +00:00
|
|
|
fprintf(stderr, "Couldn't read key from %s: %s\n",
|
2000-07-03 23:42:48 +00:00
|
|
|
keyfile, isc_result_totext(result));
|
|
|
|
goto failure;
|
|
|
|
}
|
2000-08-02 02:34:40 +00:00
|
|
|
result = dns_name_concatenate(dst_key_name(dstkey), NULL,
|
|
|
|
keyname, NULL);
|
|
|
|
check_result(result, "dns_name_concatenate");
|
|
|
|
dst_key_free(&dstkey);
|
|
|
|
|
2000-07-03 23:42:48 +00:00
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-07-03 23:42:48 +00:00
|
|
|
debug("keycreate");
|
|
|
|
result = dns_tsigkey_create(keyname, dns_tsig_hmacmd5_name,
|
|
|
|
secret, secretlen, ISC_TRUE, NULL, 0, 0,
|
2000-07-18 00:47:00 +00:00
|
|
|
mctx, NULL, &key);
|
2000-07-03 23:42:48 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
char *str;
|
|
|
|
if (keystr != NULL)
|
|
|
|
str = keystr;
|
|
|
|
else
|
|
|
|
str = keyfile;
|
2000-07-09 06:25:49 +00:00
|
|
|
fprintf(stderr, "Couldn't create key from %s: %s\n",
|
2000-07-03 23:42:48 +00:00
|
|
|
str, dns_result_totext(result));
|
|
|
|
}
|
|
|
|
isc_mem_free(mctx, secret);
|
|
|
|
return;
|
|
|
|
|
|
|
|
failure:
|
|
|
|
|
|
|
|
if (secret != NULL)
|
|
|
|
isc_mem_free(mctx, secret);
|
|
|
|
}
|
|
|
|
|
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-20 22:50:13 +00:00
|
|
|
isc_buffer_t buf;
|
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;
|
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();
|
|
|
|
check_result(result, "isc_net_probeipv4");
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
result = isc_mem_create(0, 0, &mctx);
|
|
|
|
check_result(result, "isc_mem_create");
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
lwresult = lwres_conf_parse(lwctx, RESOLV_CONF);
|
|
|
|
if (lwresult != LWRES_R_SUCCESS)
|
2000-07-07 19:19:09 +00:00
|
|
|
fprintf(stderr,
|
2000-08-09 18:44:13 +00:00
|
|
|
"An error was encountered in %s\n", 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;
|
|
|
|
if (ns_total <= 0)
|
|
|
|
fatal("no valid servers found");
|
|
|
|
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);
|
|
|
|
isc_sockaddr_fromin(&servers[i], &in4, DNSDEFAULTPORT);
|
|
|
|
} else {
|
|
|
|
struct in6_addr in6;
|
|
|
|
memcpy(&in6, lwconf->nameservers[i].address, 16);
|
2000-07-09 16:17:13 +00:00
|
|
|
isc_sockaddr_fromin6(&servers[i], &in6,
|
|
|
|
DNSDEFAULTPORT);
|
2000-07-05 23:24:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-23 20:46:25 +00:00
|
|
|
result = dns_dispatchmgr_create(mctx, NULL, &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-07-05 23:24:18 +00:00
|
|
|
result = isc_entropy_create(mctx, &entp);
|
2000-06-23 20:46:25 +00:00
|
|
|
check_result(result, "isc_entropy_create");
|
|
|
|
|
2000-07-05 23:24:18 +00:00
|
|
|
result = dst_lib_init(mctx, entp, 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-08-09 18:44:13 +00:00
|
|
|
attrs = DNS_DISPATCHATTR_UDP;
|
|
|
|
attrs |= DNS_DISPATCHATTR_MAKEQUERY;
|
|
|
|
attrs |= DNS_DISPATCHATTR_IPV4;
|
|
|
|
isc_sockaddr_any(&bind_any);
|
2000-06-16 17:10:02 +00:00
|
|
|
result = dns_dispatch_getudp(dispatchmgr, socketmgr, taskmgr,
|
|
|
|
&bind_any, PACKETSIZE, 4, 2, 3, 5,
|
2000-08-09 18:44:13 +00:00
|
|
|
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");
|
|
|
|
|
2000-06-30 21:47:35 +00:00
|
|
|
if (lwconf->domainname != NULL) {
|
2000-06-30 01:56:14 +00:00
|
|
|
dns_fixedname_init(&resolvdomain);
|
2000-06-30 21:47:35 +00:00
|
|
|
isc_buffer_init(&buf, lwconf->domainname,
|
|
|
|
strlen(lwconf->domainname));
|
|
|
|
isc_buffer_add(&buf, strlen(lwconf->domainname));
|
2000-06-30 01:56:14 +00:00
|
|
|
result = dns_name_fromtext(dns_fixedname_name(&resolvdomain),
|
2000-07-09 16:17:13 +00:00
|
|
|
&buf, dns_rootname, ISC_FALSE,
|
|
|
|
NULL);
|
2000-06-10 00:50:36 +00:00
|
|
|
check_result(result, "dns_name_fromtext");
|
2000-07-05 23:24:18 +00:00
|
|
|
origin = dns_fixedname_name(&resolvdomain);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
2000-06-30 01:56:14 +00:00
|
|
|
else
|
2000-07-05 23:24:18 +00:00
|
|
|
origin = dns_rootname;
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-07-03 23:42:48 +00:00
|
|
|
if (keystr != NULL || keyfile != NULL)
|
|
|
|
setup_key();
|
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) {
|
|
|
|
struct in_addr in4;
|
|
|
|
struct in6_addr in6;
|
2000-08-09 18:44:13 +00:00
|
|
|
#if defined(HAVE_ADDRINFO) && defined(HAVE_GETADDRINFO)
|
|
|
|
struct addrinfo *res = NULL;
|
|
|
|
int result;
|
|
|
|
#else
|
2000-07-05 23:24:18 +00:00
|
|
|
struct hostent *he;
|
2000-08-09 18:44:13 +00:00
|
|
|
#endif
|
2000-07-05 23:24:18 +00:00
|
|
|
|
|
|
|
ddebug("get_address()");
|
|
|
|
if (have_ipv6 && inet_pton(AF_INET6, host, &in6) == 1)
|
|
|
|
isc_sockaddr_fromin6(sockaddr, &in6, port);
|
|
|
|
else if (inet_pton(AF_INET, host, &in4) == 1)
|
|
|
|
isc_sockaddr_fromin(sockaddr, &in4, port);
|
|
|
|
else {
|
2000-08-09 18:44:13 +00:00
|
|
|
#if defined(HAVE_ADDRINFO) && defined(HAVE_GETADDRINFO)
|
|
|
|
result = getaddrinfo(host, NULL, NULL, &res);
|
|
|
|
if (result != 0) {
|
|
|
|
fatal("Couldn't find server '%s': %s",
|
|
|
|
host, gai_strerror(result));
|
|
|
|
}
|
|
|
|
memcpy(&sockaddr->type.sa,res->ai_addr, res->ai_addrlen);
|
|
|
|
sockaddr->length = res->ai_addrlen;
|
|
|
|
isc_sockaddr_setport(sockaddr, port);
|
|
|
|
freeaddrinfo(res);
|
|
|
|
#else
|
2000-07-05 23:24:18 +00:00
|
|
|
he = gethostbyname(host);
|
|
|
|
if (he == NULL)
|
|
|
|
fatal("Couldn't look up your server host %s. errno=%d",
|
|
|
|
host, h_errno);
|
|
|
|
INSIST(he->h_addrtype == AF_INET);
|
|
|
|
isc_sockaddr_fromin(sockaddr,
|
|
|
|
(struct in_addr *)(he->h_addr_list[0]),
|
|
|
|
port);
|
2000-08-09 18:44:13 +00:00
|
|
|
#endif
|
2000-07-05 23:24:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
static void
|
2000-06-20 22:50:13 +00:00
|
|
|
parse_args(int argc, char **argv) {
|
2000-06-30 01:56:14 +00:00
|
|
|
int ch;
|
2000-06-20 22:50:13 +00:00
|
|
|
|
2000-06-23 20:46:25 +00:00
|
|
|
debug("parse_args");
|
2000-06-30 01:56:14 +00:00
|
|
|
while ((ch = isc_commandline_parse(argc, argv, "dDMy:vk:")) != -1) {
|
|
|
|
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;
|
|
|
|
case 'M': /* was -dm */
|
|
|
|
debugging = ISC_TRUE;
|
2000-06-20 22:50:13 +00:00
|
|
|
ddebugging = ISC_TRUE;
|
2000-07-27 23:27:37 +00:00
|
|
|
isc_mem_debugging = 1;
|
2000-06-30 01:56:14 +00:00
|
|
|
break;
|
|
|
|
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;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "%s: invalid argument -%c\n",
|
|
|
|
argv[0], ch);
|
2000-07-05 23:24:18 +00:00
|
|
|
fprintf(stderr, "usage: nsupdate [-d] "
|
|
|
|
"[-y keyname:secret | -k keyfile] [-v]\n");
|
2000-06-30 01:56:14 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
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-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-30 01:56:14 +00:00
|
|
|
unsigned int dots;
|
|
|
|
isc_boolean_t last;
|
2000-07-06 19:29:40 +00:00
|
|
|
dns_name_t *rn;
|
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) {
|
2000-07-09 06:25:49 +00:00
|
|
|
fprintf(stderr, "failed to read owner name\n");
|
2000-06-30 01:56:14 +00:00
|
|
|
return (STATUS_SYNTAX);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
2000-06-30 21:47:35 +00:00
|
|
|
result = dns_message_gettempname(msg, namep);
|
2000-06-10 00:50:36 +00:00
|
|
|
check_result(result, "dns_message_gettempname");
|
2000-06-30 01:56:14 +00:00
|
|
|
result = isc_buffer_allocate(mctx, &namebuf, NAMEBUF);
|
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));
|
|
|
|
dots = count_dots(word, &last);
|
2000-06-30 21:47:35 +00:00
|
|
|
if (dots > lwconf->ndots || last)
|
2000-06-20 22:50:13 +00:00
|
|
|
rn = dns_rootname;
|
2000-07-06 19:29:40 +00:00
|
|
|
else if (userzone != NULL)
|
|
|
|
rn = userzone;
|
|
|
|
else
|
|
|
|
rn = origin;
|
2000-06-30 21:47:35 +00:00
|
|
|
result = dns_name_fromtext(*namep, &source, rn,
|
2000-06-10 00:50:36 +00:00
|
|
|
ISC_FALSE, NULL);
|
|
|
|
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,
|
|
|
|
dns_rdata_t **rdatap)
|
2000-06-30 21:47:35 +00:00
|
|
|
{
|
|
|
|
char *cmdline = *cmdlinep;
|
|
|
|
isc_buffer_t source, *buf = NULL;
|
|
|
|
isc_lex_t *lex = NULL;
|
|
|
|
dns_rdatacallbacks_t callbacks;
|
|
|
|
isc_result_t result;
|
2000-07-06 19:29:40 +00:00
|
|
|
dns_name_t *rn;
|
2000-09-28 21:39:26 +00:00
|
|
|
int bufsz = INITDATA;
|
2000-06-30 21:47:35 +00:00
|
|
|
|
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);
|
2000-07-06 19:29:40 +00:00
|
|
|
if (userzone != NULL)
|
|
|
|
rn = userzone;
|
|
|
|
else
|
|
|
|
rn = origin;
|
2000-09-28 21:39:26 +00:00
|
|
|
do {
|
|
|
|
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");
|
|
|
|
if (buf != NULL)
|
|
|
|
isc_buffer_free(&buf);
|
|
|
|
if (bufsz > MAXDATA) {
|
2000-09-28 21:50:22 +00:00
|
|
|
fprintf(stderr, "couldn't allocate enough "
|
|
|
|
"space for the rdata\n");
|
|
|
|
exit(1);
|
2000-09-28 21:39:26 +00:00
|
|
|
}
|
|
|
|
result = isc_buffer_allocate(mctx, &buf, bufsz);
|
|
|
|
check_result(result, "isc_buffer_allocate");
|
|
|
|
result = dns_rdata_fromtext(*rdatap, rdataclass,
|
|
|
|
rdatatype,
|
|
|
|
lex, rn, ISC_FALSE, buf,
|
|
|
|
&callbacks);
|
|
|
|
bufsz *= 2;
|
|
|
|
isc_lex_destroy(&lex);
|
|
|
|
} while (result == ISC_R_NOSPACE);
|
|
|
|
check_result(result, "dns_rdata_fromtext");
|
2000-06-30 21:47:35 +00:00
|
|
|
dns_message_takebuffer(msg, &buf);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (STATUS_MORE);
|
|
|
|
}
|
|
|
|
*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) {
|
2000-07-09 06:25:49 +00:00
|
|
|
fprintf(stderr, "failed to read class or type\n");
|
2000-06-30 01:56:14 +00:00
|
|
|
dns_message_puttempname(updatemsg, &name);
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
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) {
|
|
|
|
/*
|
|
|
|
* 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-07-09 06:25:49 +00:00
|
|
|
fprintf(stderr, "failed to read type\n");
|
2000-06-30 01:56:14 +00:00
|
|
|
dns_message_puttempname(updatemsg, &name);
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
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);
|
|
|
|
check_result(result, "dns_rdatatype_fromtext");
|
|
|
|
} else {
|
|
|
|
rdataclass = dns_rdataclass_in;
|
|
|
|
result = dns_rdatatype_fromtext(&rdatatype, ®ion);
|
|
|
|
check_result(result, "dns_rdatatype_fromtext");
|
|
|
|
}
|
|
|
|
} 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");
|
|
|
|
|
|
|
|
rdata->data = NULL;
|
|
|
|
rdata->length = 0;
|
|
|
|
|
|
|
|
if (isrrset && ispositive) {
|
2000-06-30 21:47:35 +00:00
|
|
|
retval = parse_rdata(&cmdline, rdataclass, rdatatype,
|
|
|
|
updatemsg, &rdata);
|
|
|
|
if (retval != STATUS_MORE)
|
|
|
|
return (retval);
|
2000-06-30 18:44:51 +00:00
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-06-19 22:09:46 +00:00
|
|
|
result = dns_message_gettemprdatalist(updatemsg, &rdatalist);
|
|
|
|
check_result(result, "dns_message_gettemprdatalist");
|
2000-06-10 00:50:36 +00:00
|
|
|
result = dns_message_gettemprdataset(updatemsg, &rdataset);
|
|
|
|
check_result(result, "dns_message_gettemprdataset");
|
2000-06-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);
|
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) {
|
2000-07-09 06:25:49 +00:00
|
|
|
fprintf(stderr, "failed to 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
|
|
|
|
|
|
|
word = nsu_strsep(&cmdline, " \t\r\n");
|
|
|
|
if (*word == 0) {
|
2000-07-09 06:25:49 +00:00
|
|
|
fprintf(stderr, "failed to 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)
|
|
|
|
port = DNSDEFAULTPORT;
|
|
|
|
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-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) {
|
2000-07-09 06:25:49 +00:00
|
|
|
fprintf(stderr, "failed to 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));
|
2000-07-09 16:17:13 +00:00
|
|
|
result = dns_name_fromtext(userzone, &b, dns_rootname, ISC_FALSE,
|
|
|
|
NULL);
|
2000-07-05 23:24:18 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-07-09 06:25:49 +00:00
|
|
|
fprintf(stderr, "failed to 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
|
|
|
}
|
|
|
|
|
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;
|
2000-08-01 14:02:41 +00:00
|
|
|
long 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 01:56:14 +00:00
|
|
|
char *endp;
|
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");
|
|
|
|
|
|
|
|
rdata->rdclass = 0;
|
|
|
|
rdata->type = 0;
|
|
|
|
rdata->data = NULL;
|
|
|
|
rdata->length = 0;
|
|
|
|
|
|
|
|
/*
|
2000-08-01 14:02:41 +00:00
|
|
|
* If this is an add, read the TTL and verify that it's in range.
|
2000-06-30 01:56:14 +00:00
|
|
|
*/
|
|
|
|
if (!isdelete) {
|
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-07-09 06:25:49 +00:00
|
|
|
fprintf(stderr, "failed to read owner ttl\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
|
|
|
ttl = strtol(word, &endp, 0);
|
2000-08-10 02:32:14 +00:00
|
|
|
if (*endp != '\0') {
|
2000-07-09 06:25:49 +00:00
|
|
|
fprintf(stderr, "ttl '%s' is not numeric\n", word);
|
2000-06-30 21:47:35 +00:00
|
|
|
goto failure;
|
2000-10-19 16:31:05 +00:00
|
|
|
} else if (ttl < 0 || ttl > TTL_MAX || errno == ERANGE) {
|
2000-08-10 02:32:14 +00:00
|
|
|
/*
|
|
|
|
* The errno test is needed to catch when strtol()
|
|
|
|
* overflows on a platform where sizeof(int) ==
|
|
|
|
* sizeof(long), because ttl will be set to LONG_MAX,
|
|
|
|
* which will be equal to TTL_MAX.
|
|
|
|
*/
|
2000-08-01 14:02:41 +00:00
|
|
|
fprintf(stderr, "ttl '%s' is out of range "
|
2000-08-10 02:32:14 +00:00
|
|
|
"(1 to %d)\n", word, TTL_MAX);
|
2000-08-01 14:02:41 +00:00
|
|
|
goto failure;
|
2000-06-30 01:56:14 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
ttl = 0;
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
/*
|
|
|
|
* Read the class or 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;
|
|
|
|
goto doneparsing;
|
|
|
|
} else {
|
2000-07-09 06:25:49 +00:00
|
|
|
fprintf(stderr, "failed to 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);
|
2000-06-30 01:56:14 +00:00
|
|
|
result = dns_rdataclass_fromtext(&rdataclass, ®ion);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
goto doneparsing;
|
|
|
|
} else {
|
2000-07-09 06:25:49 +00:00
|
|
|
fprintf(stderr, "failed to 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);
|
|
|
|
check_result(result, "dns_rdatatype_fromtext");
|
|
|
|
} else {
|
|
|
|
rdataclass = dns_rdataclass_in;
|
|
|
|
result = dns_rdatatype_fromtext(&rdatatype, ®ion);
|
|
|
|
check_result(result, "dns_rdatatype_fromtext");
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
2000-06-30 21:47:35 +00:00
|
|
|
retval = parse_rdata(&cmdline, rdataclass, rdatatype, updatemsg,
|
|
|
|
&rdata);
|
|
|
|
if (retval != STATUS_MORE)
|
|
|
|
goto failure;
|
2000-06-30 03:24:27 +00:00
|
|
|
|
2000-06-30 21:47:35 +00:00
|
|
|
if (isdelete) {
|
|
|
|
if (rdata->length == 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 {
|
|
|
|
if (rdata->length == 0) {
|
2000-07-09 06:25:49 +00:00
|
|
|
fprintf(stderr, "failed to 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);
|
|
|
|
if (rdata != NULL)
|
|
|
|
dns_message_puttemprdata(updatemsg, &rdata);
|
|
|
|
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) {
|
2000-07-09 06:25:49 +00:00
|
|
|
fprintf(stderr, "failed to 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
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-09-15 23:30:28 +00:00
|
|
|
show_message(dns_message_t *msg) {
|
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()");
|
2000-09-28 21:39:26 +00:00
|
|
|
bufsz = INITTEXT;
|
|
|
|
do {
|
|
|
|
if (bufsz > MAXTEXT) {
|
2000-09-28 21:50:22 +00:00
|
|
|
fprintf(stderr, "couldn't allocate large enough"
|
|
|
|
"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");
|
|
|
|
result = dns_message_totext(msg, 0, buf);
|
|
|
|
bufsz *= 2;
|
|
|
|
} while (result == ISC_R_NOSPACE);
|
2000-06-30 01:56:14 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-09-28 21:39:26 +00:00
|
|
|
fprintf(stderr, "Failed to convert message to text format.\n");
|
|
|
|
isc_buffer_free(&buf);
|
2000-06-30 01:56:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("Outgoing update query:\n%.*s",
|
2000-09-28 21:39:26 +00:00
|
|
|
(int)isc_buffer_usedlength(buf),
|
|
|
|
(char*)isc_buffer_base(buf));
|
|
|
|
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()");
|
2000-07-09 06:25:49 +00:00
|
|
|
fprintf(stdout, "> ");
|
2000-09-01 21:34:12 +00:00
|
|
|
cmdline = fgets(cmdlinebuf, MAXCMD, stdin);
|
|
|
|
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
|
|
|
|
|
|
|
if (feof(stdin))
|
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);
|
|
|
|
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));
|
|
|
|
if (strcasecmp(word, "zone") == 0)
|
|
|
|
return (evaluate_zone(cmdline));
|
|
|
|
if (strcasecmp(word, "send") == 0)
|
|
|
|
return (STATUS_SEND);
|
|
|
|
if (strcasecmp(word, "show") == 0) {
|
2000-09-15 23:30:28 +00:00
|
|
|
show_message(updatemsg);
|
2000-06-30 01:56:14 +00:00
|
|
|
return (STATUS_MORE);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
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()");
|
2000-06-30 03:24:27 +00:00
|
|
|
while ((result == STATUS_MORE) || (result == STATUS_SYNTAX))
|
2000-06-10 00:50:36 +00:00
|
|
|
result = get_next_command();
|
|
|
|
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;
|
|
|
|
isc_task_send(global_task, &event);
|
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;
|
|
|
|
dns_message_t *rcvmsg = NULL;
|
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-07-09 16:17:13 +00:00
|
|
|
ddebug("updated_completed()");
|
2000-06-16 17:10:02 +00:00
|
|
|
REQUIRE(event->ev_type == DNS_EVENT_REQUESTDONE);
|
|
|
|
reqev = (dns_requestevent_t *)event;
|
|
|
|
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-06-16 17:10:02 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
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(reqev->request, rcvmsg,
|
|
|
|
DNS_MESSAGEPARSE_PRESERVEORDER);
|
2000-06-16 17:10:02 +00:00
|
|
|
check_result(result, "dns_request_getresponse");
|
2000-06-29 02:16:44 +00:00
|
|
|
if (debugging) {
|
2000-09-28 21:39:26 +00:00
|
|
|
isc_buffer_t *buf = NULL;
|
|
|
|
int bufsz;
|
|
|
|
|
|
|
|
bufsz = INITTEXT;
|
|
|
|
do {
|
|
|
|
if (bufsz > MAXTEXT) {
|
|
|
|
fprintf (stderr, "couldn't allocate large "
|
|
|
|
"enough buffer to display message\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (buf != NULL)
|
|
|
|
isc_buffer_free(&buf);
|
|
|
|
result = isc_buffer_allocate(mctx, &buf, bufsz);
|
|
|
|
check_result(result, "isc_buffer_allocate");
|
|
|
|
result = dns_message_totext(rcvmsg, 0, buf);
|
|
|
|
bufsz *= 2;
|
|
|
|
} while (result == ISC_R_NOSPACE);
|
2000-06-16 17:10:02 +00:00
|
|
|
check_result(result, "dns_message_totext");
|
2000-07-09 06:25:49 +00:00
|
|
|
fprintf(stderr, "\nReply from update query:\n%.*s\n",
|
2000-09-28 21:39:26 +00:00
|
|
|
(int)isc_buffer_usedlength(buf),
|
|
|
|
(char*)isc_buffer_base(buf));
|
|
|
|
isc_buffer_free(&buf);
|
2000-06-16 17:10:02 +00:00
|
|
|
}
|
2000-06-17 00:16:50 +00:00
|
|
|
dns_message_destroy(&rcvmsg);
|
2000-06-16 17:10:02 +00:00
|
|
|
done:
|
2000-06-17 00:16:50 +00:00
|
|
|
dns_request_destroy(&reqev->request);
|
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-07-05 23:24:18 +00:00
|
|
|
send_update(dns_name_t *zonename, isc_sockaddr_t *master) {
|
2000-06-10 00:50:36 +00:00
|
|
|
isc_result_t result;
|
|
|
|
dns_request_t *request = NULL;
|
|
|
|
dns_name_t *name = NULL;
|
2000-06-16 17:10:02 +00:00
|
|
|
dns_rdataset_t *rdataset = NULL;
|
2000-06-30 18:59:21 +00:00
|
|
|
unsigned int options = 0;
|
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
|
|
|
|
|
|
|
result = dns_message_gettempname(updatemsg, &name);
|
|
|
|
check_result(result, "dns_message_gettempname");
|
|
|
|
dns_name_init(name, NULL);
|
2000-06-30 01:56:14 +00:00
|
|
|
dns_name_clone(zonename, name);
|
2000-06-16 17:10:02 +00:00
|
|
|
result = dns_message_gettemprdataset(updatemsg, &rdataset);
|
2000-06-10 00:50:36 +00:00
|
|
|
check_result(result, "dns_message_gettemprdataset");
|
|
|
|
dns_rdataset_makequestion(rdataset, dns_rdataclass_in,
|
|
|
|
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-30 18:59:21 +00:00
|
|
|
if (usevc)
|
|
|
|
options |= DNS_REQUESTOPT_TCP;
|
2000-07-05 23:24:18 +00:00
|
|
|
result = dns_request_create(requestmgr, updatemsg, master,
|
2000-06-30 18:59:21 +00:00
|
|
|
options, key,
|
2000-06-10 00:50:36 +00:00
|
|
|
FIND_TIMEOUT, global_task,
|
|
|
|
update_completed, NULL, &request);
|
|
|
|
check_result(result, "dns_request_create");
|
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-06-30 01:56:14 +00:00
|
|
|
dns_rdata_t soarr;
|
|
|
|
int pass = 0;
|
2000-07-05 23:24:18 +00:00
|
|
|
dns_name_t master;
|
|
|
|
isc_sockaddr_t *serveraddr, tempaddr;
|
|
|
|
dns_name_t *zonename;
|
|
|
|
nsu_requestinfo_t *reqinfo;
|
|
|
|
dns_message_t *soaquery = NULL;
|
|
|
|
isc_sockaddr_t *addr;
|
2000-06-10 00:50:36 +00:00
|
|
|
|
|
|
|
UNUSED(task);
|
|
|
|
|
2000-07-09 16:17:13 +00:00
|
|
|
ddebug("recvsoa()");
|
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
|
|
|
|
|
|
|
isc_event_free(&event);
|
|
|
|
reqev = NULL;
|
|
|
|
|
|
|
|
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",
|
2000-07-05 23:24:18 +00:00
|
|
|
addrbuf, isc_result_totext(eresult));
|
|
|
|
if (userserver != NULL)
|
|
|
|
fatal("Couldn't talk to specified nameserver.");
|
2000-09-18 19:16:45 +00:00
|
|
|
else if (++ns_inuse >= lwconf->nsnext)
|
2000-07-05 23:24:18 +00:00
|
|
|
fatal("Couldn't talk to any default nameserver.");
|
2000-06-30 01:56:14 +00:00
|
|
|
ddebug("Destroying request [%lx]", request);
|
|
|
|
dns_request_destroy(&request);
|
2000-09-15 23:30:28 +00:00
|
|
|
dns_message_renderreset(soaquery);
|
2000-07-05 23:24:18 +00:00
|
|
|
sendrequest(&servers[ns_inuse], soaquery, &request);
|
|
|
|
isc_mem_put(mctx, reqinfo, sizeof(nsu_requestinfo_t));
|
2000-06-10 00:50:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-06-30 01:56:14 +00:00
|
|
|
dns_message_destroy(&soaquery);
|
2000-07-05 23:24:18 +00:00
|
|
|
isc_mem_put(mctx, reqinfo, sizeof(nsu_requestinfo_t));
|
2000-06-30 01:56:14 +00:00
|
|
|
|
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);
|
2000-06-10 00:50:36 +00:00
|
|
|
check_result(result, "dns_request_getresponse");
|
|
|
|
section = DNS_SECTION_ANSWER;
|
2000-06-16 17:10:02 +00:00
|
|
|
if (debugging) {
|
2000-09-28 21:39:26 +00:00
|
|
|
isc_buffer_t *buf = NULL;
|
|
|
|
int bufsz;
|
|
|
|
bufsz = INITTEXT;
|
|
|
|
do {
|
|
|
|
if (buf != NULL)
|
|
|
|
isc_buffer_free(&buf);
|
|
|
|
if (bufsz > MAXTEXT) {
|
2000-09-28 21:50:22 +00:00
|
|
|
fprintf(stderr, "couldn't allocate enough "
|
2000-09-28 21:39:26 +00:00
|
|
|
"space for debugging message\n");
|
2000-09-28 21:50:22 +00:00
|
|
|
exit(1);
|
2000-09-28 21:39:26 +00:00
|
|
|
}
|
|
|
|
result = isc_buffer_allocate(mctx, &buf, bufsz);
|
|
|
|
check_result(result, "isc_buffer_allocate");
|
|
|
|
result = dns_message_totext(rcvmsg, 0, buf);
|
|
|
|
} while (result == ISC_R_NOSPACE);
|
2000-06-16 17:10:02 +00:00
|
|
|
check_result(result, "dns_message_totext");
|
2000-07-09 06:25:49 +00:00
|
|
|
fprintf(stderr, "Reply from SOA query:\n%.*s\n",
|
2000-09-28 21:39:26 +00:00
|
|
|
(int)isc_buffer_usedlength(buf),
|
|
|
|
(char*)isc_buffer_base(buf));
|
|
|
|
isc_buffer_free(&buf);
|
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");
|
|
|
|
|
|
|
|
lookforsoa:
|
|
|
|
if (pass == 0)
|
|
|
|
section = DNS_SECTION_ANSWER;
|
|
|
|
else if (pass == 1)
|
|
|
|
section = DNS_SECTION_AUTHORITY;
|
|
|
|
else
|
|
|
|
fatal("response to SOA query didn't contain an SOA");
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
result = dns_message_nextname(rcvmsg, section);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
if (soaset == NULL) {
|
|
|
|
pass++;
|
|
|
|
goto lookforsoa;
|
|
|
|
}
|
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;
|
|
|
|
get_address(serverstr, DNSDEFAULTPORT, &tempaddr);
|
|
|
|
serveraddr = &tempaddr;
|
2000-06-16 17:10:02 +00:00
|
|
|
}
|
|
|
|
|
2000-07-05 23:24:18 +00:00
|
|
|
send_update(zonename, serveraddr);
|
2000-07-04 02:33:29 +00:00
|
|
|
|
|
|
|
dns_rdata_freestruct(&soa);
|
2000-06-16 17:10:02 +00:00
|
|
|
dns_message_destroy(&rcvmsg);
|
2000-06-30 01:56:14 +00:00
|
|
|
dns_request_destroy(&request);
|
2000-07-05 23:24:18 +00:00
|
|
|
ddebug("Out of recvsoa");
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-07-05 23:24:18 +00:00
|
|
|
sendrequest(isc_sockaddr_t *address, dns_message_t *msg,
|
|
|
|
dns_request_t **request)
|
|
|
|
{
|
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;
|
|
|
|
reqinfo->addr = address;
|
|
|
|
result = dns_request_create(requestmgr, msg, address,
|
2000-06-30 01:56:14 +00:00
|
|
|
0, NULL, FIND_TIMEOUT, global_task,
|
2000-07-05 23:24:18 +00:00
|
|
|
recvsoa, reqinfo, request);
|
2000-06-30 01:56:14 +00:00
|
|
|
check_result(result, "dns_request_create");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
start_update(void) {
|
2000-06-10 00:50:36 +00:00
|
|
|
isc_result_t result;
|
|
|
|
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;
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-07-05 23:24:18 +00:00
|
|
|
ddebug("start_update()");
|
|
|
|
|
|
|
|
if (userzone != NULL && userserver != NULL) {
|
|
|
|
send_update(userzone, userserver);
|
|
|
|
return;
|
|
|
|
}
|
2000-06-30 03:24:27 +00:00
|
|
|
|
|
|
|
result = dns_message_firstname(updatemsg, DNS_SECTION_UPDATE);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-09-01 21:34:12 +00:00
|
|
|
done_update();
|
2000-06-30 03:24:27 +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");
|
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
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");
|
|
|
|
|
|
|
|
dns_rdataset_makequestion(rdataset, dns_rdataclass_in,
|
|
|
|
dns_rdatatype_soa);
|
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
firstname = NULL;
|
|
|
|
dns_message_currentname(updatemsg, DNS_SECTION_UPDATE, &firstname);
|
|
|
|
dns_name_init(name, NULL);
|
|
|
|
dns_name_clone(firstname, name);
|
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)
|
|
|
|
sendrequest(userserver, soaquery, &request);
|
|
|
|
else {
|
|
|
|
ns_inuse = 0;
|
|
|
|
sendrequest(&servers[ns_inuse], soaquery, &request);
|
|
|
|
}
|
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
|
|
|
|
2000-07-05 23:24:18 +00:00
|
|
|
if (userserver != NULL)
|
|
|
|
isc_mem_put(mctx, userserver, sizeof(isc_sockaddr_t));
|
|
|
|
|
2000-06-23 20:46:25 +00:00
|
|
|
if (key != NULL) {
|
2000-07-05 23:24:18 +00:00
|
|
|
debug("Freeing key");
|
2000-06-23 20:46:25 +00:00
|
|
|
dns_tsigkey_detach(&key);
|
|
|
|
}
|
|
|
|
|
2000-06-17 00:16:50 +00:00
|
|
|
if (updatemsg != NULL)
|
|
|
|
dns_message_destroy(&updatemsg);
|
|
|
|
|
2000-06-23 20:46:25 +00:00
|
|
|
if (is_dst_up) {
|
2000-07-05 23:24:18 +00:00
|
|
|
debug("Destroy DST lib");
|
2000-06-23 20:46:25 +00:00
|
|
|
dst_lib_destroy();
|
|
|
|
is_dst_up = ISC_FALSE;
|
|
|
|
}
|
2000-07-05 23:24:18 +00:00
|
|
|
|
2000-06-23 20:46:25 +00:00
|
|
|
if (entp != NULL) {
|
2000-07-05 23:24:18 +00:00
|
|
|
debug("Detach from entropy");
|
2000-06-23 20:46:25 +00:00
|
|
|
isc_entropy_detach(&entp);
|
|
|
|
}
|
2000-07-05 23:24:18 +00:00
|
|
|
|
2000-06-30 21:47:35 +00:00
|
|
|
lwres_conf_clear(lwctx);
|
|
|
|
lwres_context_destroy(&lwctx);
|
2000-07-05 23:42:08 +00:00
|
|
|
|
|
|
|
isc_mem_put(mctx, servers, ns_total * sizeof(isc_sockaddr_t));
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-06-17 00:16:50 +00:00
|
|
|
ddebug("Shutting down request manager");
|
|
|
|
dns_requestmgr_shutdown(requestmgr);
|
|
|
|
dns_requestmgr_detach(&requestmgr);
|
|
|
|
|
2000-08-09 18:44:13 +00:00
|
|
|
ddebug("Freeing the dispatchers");
|
2000-06-17 00:16:50 +00:00
|
|
|
dns_dispatch_detach(&dispatchv4);
|
2000-08-09 18:44:13 +00:00
|
|
|
if (have_ipv6)
|
|
|
|
dns_dispatch_detach(&dispatchv6);
|
2000-06-17 00:16:50 +00:00
|
|
|
|
|
|
|
ddebug("Shutting down dispatch manager");
|
|
|
|
dns_dispatchmgr_destroy(&dispatchmgr);
|
|
|
|
|
|
|
|
ddebug("Ending task");
|
|
|
|
isc_task_detach(&global_task);
|
|
|
|
|
2000-09-01 21:34:12 +00:00
|
|
|
ddebug("Destroying event task");
|
|
|
|
if (global_event != NULL)
|
|
|
|
isc_event_free(&global_event);
|
|
|
|
|
2000-06-17 00:16:50 +00:00
|
|
|
ddebug("Shutting down task manager");
|
|
|
|
isc_taskmgr_destroy(&taskmgr);
|
|
|
|
|
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);
|
|
|
|
|
2000-06-17 00:16:50 +00:00
|
|
|
ddebug("Destroying memory context");
|
|
|
|
if (isc_mem_debugging)
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (global_event == NULL)
|
|
|
|
global_event = event;
|
|
|
|
|
|
|
|
reset_system();
|
|
|
|
isc_app_block();
|
|
|
|
more = user_interaction();
|
|
|
|
isc_app_unblock();
|
|
|
|
if (!more) {
|
|
|
|
isc_app_shutdown();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
start_update();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
int
|
|
|
|
main(int argc, char **argv) {
|
|
|
|
isc_result_t result;
|
|
|
|
|
2000-09-01 21:34:12 +00:00
|
|
|
isc_app_start();
|
|
|
|
|
2000-06-23 20:46:25 +00:00
|
|
|
parse_args(argc, argv);
|
|
|
|
|
2000-06-10 00:50:36 +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-07-09 16:17:13 +00:00
|
|
|
fprintf(stdout, "\n");
|
2000-06-30 01:56:14 +00:00
|
|
|
cleanup();
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-09-01 21:34:12 +00:00
|
|
|
isc_app_finish();
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
return (0);
|
|
|
|
}
|