2000-06-10 00:50:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2000 Internet Software Consortium.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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-30 03:45:54 +00:00
|
|
|
/* $Id: nsupdate.c,v 1.15 2000/06/30 03:45:54 bwelling Exp $ */
|
2000-06-10 00:50:36 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
2000-06-30 01:56:14 +00:00
|
|
|
|
2000-06-10 00:50:36 +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-10 00:50:36 +00:00
|
|
|
#include <isc/condition.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-06-21 17:48:32 +00:00
|
|
|
#include <isc/lex.h>
|
2000-06-10 00:50:36 +00:00
|
|
|
#include <isc/mem.h>
|
2000-06-21 17:48:32 +00:00
|
|
|
#include <isc/mutex.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-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>
|
|
|
|
#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>
|
|
|
|
#include <dst/dst.h>
|
|
|
|
|
2000-06-30 03:24:27 +00:00
|
|
|
#include <ctype.h>
|
2000-06-30 01:56:14 +00:00
|
|
|
#include <netdb.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
#define MXNAME 256
|
2000-06-30 03:24:27 +00:00
|
|
|
#define MAXCMD 1024
|
2000-06-10 00:50:36 +00:00
|
|
|
#define NAMEBUF 512
|
2000-06-30 03:24:27 +00:00
|
|
|
#define WORDLEN 512
|
2000-06-10 00:50:36 +00:00
|
|
|
#define PACKETSIZE 2048
|
2000-06-30 03:24:27 +00:00
|
|
|
#define MSGTEXT 4096
|
2000-06-10 00:50:36 +00:00
|
|
|
#define FIND_TIMEOUT 5
|
|
|
|
|
|
|
|
#define RESOLV_CONF "/etc/resolv.conf"
|
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
static isc_boolean_t busy = ISC_FALSE;
|
|
|
|
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;
|
|
|
|
static isc_mutex_t lock;
|
|
|
|
static isc_condition_t cond;
|
|
|
|
|
|
|
|
static isc_taskmgr_t *taskmgr = NULL;
|
|
|
|
static isc_task_t *global_task = NULL;
|
|
|
|
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;
|
|
|
|
static dns_message_t *updatemsg = NULL;
|
|
|
|
static dns_name_t *zonename = NULL;
|
|
|
|
static dns_fixedname_t resolvdomain; /* from resolv.conf's domain line */
|
|
|
|
static dns_name_t *current_zone; /* Points to one of above, or dns_rootname */
|
|
|
|
static dns_name_t *master = NULL; /* Master nameserver, from SOA query */
|
|
|
|
static dns_tsigkey_t *key = NULL;
|
|
|
|
static dns_tsig_keyring_t *keyring = NULL;
|
|
|
|
|
|
|
|
static char nameservername[3][MXNAME];
|
|
|
|
static int nameservers;
|
|
|
|
static int ns_inuse = 0;
|
|
|
|
static unsigned int ndots = 1;
|
|
|
|
static char *domain = NULL;
|
|
|
|
static char *keystr = NULL;
|
|
|
|
static isc_entropy_t *entp = NULL;
|
|
|
|
|
|
|
|
static void sendrequest(int whichns, dns_message_t *msg,
|
|
|
|
dns_request_t **request);
|
2000-06-10 00:50:36 +00:00
|
|
|
|
|
|
|
#define STATUS_MORE 0
|
|
|
|
#define STATUS_SEND 1
|
|
|
|
#define STATUS_QUIT 2
|
2000-06-30 01:56:14 +00:00
|
|
|
#define STATUS_SYNTAX 3
|
2000-06-10 00:50:36 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
fatal(const char *format, ...) {
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
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) {
|
|
|
|
va_start(args, format);
|
|
|
|
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) {
|
|
|
|
va_start(args, format);
|
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
va_end(args);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
static void
|
|
|
|
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 03:24:27 +00:00
|
|
|
/*
|
|
|
|
* Eat characters from FP until EOL or EOF. Returns EOF or '\n'
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
eatline(FILE *fp) {
|
|
|
|
int ch;
|
|
|
|
|
|
|
|
ch = fgetc(fp);
|
|
|
|
while (ch != '\n' && ch != EOF)
|
|
|
|
ch = fgetc(fp);
|
|
|
|
return (ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Eats white space up to next newline or non-whitespace character (of
|
|
|
|
* EOF). Returns the last character read. Comments are considered white
|
|
|
|
* space.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
eatwhite(FILE *fp) {
|
|
|
|
int ch;
|
|
|
|
|
|
|
|
ch = fgetc(fp);
|
|
|
|
while (ch != '\n' && ch != EOF && isspace((unsigned char)ch))
|
|
|
|
ch = fgetc(fp);
|
|
|
|
|
|
|
|
if (ch == ';' || ch == '#')
|
|
|
|
ch = eatline(fp);
|
|
|
|
|
|
|
|
return (ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip over any leading whitespace and then read in the next sequence of
|
|
|
|
* non-whitespace characters. In this context newline is not considered
|
|
|
|
* whitespace. Returns EOF on end-of-file, or the character
|
|
|
|
* that caused the reading to stop.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
getword(FILE *fp, char *buffer, size_t size) {
|
|
|
|
int ch;
|
|
|
|
char *p = buffer;
|
|
|
|
|
|
|
|
REQUIRE(buffer != NULL);
|
|
|
|
REQUIRE(size > 0);
|
|
|
|
|
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
ch = eatwhite(fp);
|
|
|
|
|
|
|
|
if (ch == EOF)
|
|
|
|
return (EOF);
|
|
|
|
|
|
|
|
do {
|
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
if (ch == EOF || isspace((unsigned char)ch))
|
|
|
|
break;
|
|
|
|
else if ((size_t) (p - buffer) == size - 1)
|
|
|
|
return (EOF); /* Not enough space. */
|
|
|
|
|
|
|
|
*p++ = (char)ch;
|
|
|
|
ch = fgetc(fp);
|
|
|
|
} while (1);
|
|
|
|
|
|
|
|
return (ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
nsu_strsep(char **stringp, const char *delim) {
|
|
|
|
char *string = *stringp;
|
|
|
|
char *s;
|
|
|
|
const char *d;
|
|
|
|
char sc, dc;
|
|
|
|
|
|
|
|
if (string == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
for (s = string; *s != '\0'; s++) {
|
|
|
|
sc = *s;
|
|
|
|
for (d = delim; (dc = *d) != '\0'; d++)
|
|
|
|
if (sc == dc) {
|
|
|
|
*s++ = '\0';
|
|
|
|
*stringp = s;
|
|
|
|
return (string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*stringp = NULL;
|
|
|
|
return (string);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static 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
|
|
|
load_resolv_conf(void) {
|
2000-06-10 00:50:36 +00:00
|
|
|
FILE *fp;
|
2000-06-30 03:24:27 +00:00
|
|
|
char word[256];
|
|
|
|
int stopchar, delim;
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-06-16 17:10:02 +00:00
|
|
|
ddebug ("load_resolv_conf()");
|
2000-06-10 00:50:36 +00:00
|
|
|
fp = fopen (RESOLV_CONF, "r");
|
2000-06-30 01:56:14 +00:00
|
|
|
if (fp == NULL)
|
|
|
|
return;
|
2000-06-30 03:24:27 +00:00
|
|
|
do {
|
|
|
|
stopchar = getword(fp, word, sizeof(word));
|
|
|
|
if (stopchar == EOF)
|
|
|
|
break;
|
|
|
|
if (strcmp(word, "nameserver") == 0) {
|
2000-06-30 01:56:14 +00:00
|
|
|
ddebug ("Got a nameserver line");
|
2000-06-30 03:24:27 +00:00
|
|
|
if (nameservers >= 3) {
|
|
|
|
stopchar = eatline(fp);
|
|
|
|
if (stopchar == EOF)
|
|
|
|
break;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
delim = getword(fp, word, sizeof(word));
|
|
|
|
if (strlen(word) == 0) {
|
|
|
|
stopchar = eatline(fp);
|
|
|
|
if (stopchar == EOF)
|
|
|
|
break;
|
|
|
|
continue;
|
2000-06-30 01:56:14 +00:00
|
|
|
}
|
2000-06-30 03:24:27 +00:00
|
|
|
strncpy(nameservername[nameservers], word, MXNAME);
|
|
|
|
nameservers++;
|
|
|
|
} else if (strcasecmp(word, "options") == 0) {
|
|
|
|
delim = getword(fp, word, sizeof(word));
|
|
|
|
if (strlen(word) == 0)
|
2000-06-30 01:56:14 +00:00
|
|
|
continue;
|
2000-06-30 03:24:27 +00:00
|
|
|
while (strlen(word) > 0) {
|
|
|
|
char *endp;
|
|
|
|
if (strncmp("ndots:", word, 6) == 0) {
|
|
|
|
ndots = strtol(word + 6, &endp, 10);
|
|
|
|
if (*endp != 0)
|
|
|
|
fatal("ndots is not numeric\n");
|
|
|
|
ddebug ("ndots is %d.", ndots);
|
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
2000-06-30 03:24:27 +00:00
|
|
|
if (delim == EOF || delim == '\n')
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
delim = getword(fp, word, sizeof(word));
|
2000-06-30 01:56:14 +00:00
|
|
|
/* XXXMWS Searchlist not supported! */
|
2000-06-30 03:24:27 +00:00
|
|
|
} else if (strcasecmp(word, "domain") == 0 && domain == NULL) {
|
|
|
|
delim = getword(fp, word, sizeof(word));
|
|
|
|
if (strlen(word) == 0) {
|
|
|
|
stopchar = eatline(fp);
|
|
|
|
if (stopchar == EOF)
|
|
|
|
break;
|
2000-06-30 01:56:14 +00:00
|
|
|
continue;
|
2000-06-30 03:24:27 +00:00
|
|
|
}
|
|
|
|
domain = isc_mem_strdup(mctx, word);
|
2000-06-30 01:56:14 +00:00
|
|
|
if (domain == NULL)
|
|
|
|
fatal("out of memory");
|
2000-06-30 03:24:27 +00:00
|
|
|
strncpy(nameservername[nameservers], word, MXNAME);
|
|
|
|
nameservers++;
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
2000-06-30 03:24:27 +00:00
|
|
|
stopchar = eatline(fp);
|
|
|
|
if (stopchar == EOF)
|
|
|
|
break;
|
|
|
|
} while (ISC_TRUE);
|
2000-06-30 01:56:14 +00:00
|
|
|
fclose (fp);
|
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-06-16 17:10:02 +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);
|
|
|
|
check_result (result, "dns_message_create");
|
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
updatemsg->opcode = dns_opcode_update;
|
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
if (zonename != NULL) {
|
|
|
|
dns_name_free(zonename, mctx);
|
|
|
|
isc_mem_put(mctx, zonename, sizeof(dns_name_t));
|
|
|
|
zonename = NULL;
|
|
|
|
}
|
|
|
|
if (master != NULL) {
|
|
|
|
dns_name_free(master, mctx);
|
|
|
|
isc_mem_put(mctx, master, sizeof(dns_name_t));
|
|
|
|
master = NULL;
|
|
|
|
}
|
|
|
|
if (domain != NULL)
|
|
|
|
current_zone = dns_fixedname_name(&resolvdomain);
|
2000-06-20 22:50:13 +00:00
|
|
|
else
|
|
|
|
current_zone = dns_rootname;
|
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;
|
|
|
|
isc_sockaddr_t bind_any;
|
2000-06-20 22:50:13 +00:00
|
|
|
isc_buffer_t buf;
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
* Warning: This is not particularly good randomness. We'll
|
|
|
|
* just use random() now for getting id values, but doing so
|
2000-06-16 17:10:02 +00:00
|
|
|
* does NOT insure that id's can't be guessed.
|
2000-06-30 01:56:14 +00:00
|
|
|
*
|
|
|
|
* XXX Shouldn't random() be called somewhere if this is here?
|
2000-06-10 00:50:36 +00:00
|
|
|
*/
|
|
|
|
srandom (getpid() + (int)&setup_system);
|
|
|
|
|
|
|
|
result = isc_app_start();
|
|
|
|
check_result(result, "isc_app_start");
|
|
|
|
|
|
|
|
result = isc_net_probeipv4();
|
|
|
|
check_result(result, "isc_net_probeipv4");
|
|
|
|
|
|
|
|
/* XXXMWS There isn't any actual V6 support in the code yet */
|
|
|
|
result = isc_net_probeipv6();
|
|
|
|
if (result == ISC_R_SUCCESS)
|
|
|
|
have_ipv6=ISC_TRUE;
|
|
|
|
|
|
|
|
result = isc_mem_create(0, 0, &mctx);
|
|
|
|
check_result(result, "isc_mem_create");
|
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
load_resolv_conf();
|
|
|
|
|
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-06-27 21:59:44 +00:00
|
|
|
result = isc_taskmgr_create (mctx, 1, 0, &taskmgr);
|
|
|
|
check_result(result, "isc_taskmgr_create");
|
|
|
|
|
|
|
|
result = isc_task_create (taskmgr, 0, &global_task);
|
|
|
|
check_result(result, "isc_task_create");
|
|
|
|
|
2000-06-23 20:46:25 +00:00
|
|
|
result = isc_entropy_create (mctx, &entp);
|
|
|
|
check_result(result, "isc_entropy_create");
|
|
|
|
|
|
|
|
result = dst_lib_init (mctx, entp, 0);
|
|
|
|
check_result(result, "dst_lib_init");
|
|
|
|
is_dst_up = ISC_TRUE;
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
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,
|
|
|
|
DNS_DISPATCHATTR_UDP |
|
|
|
|
DNS_DISPATCHATTR_IPV4 |
|
|
|
|
DNS_DISPATCHATTR_MAKEQUERY, 0,
|
|
|
|
&dispatchv4);
|
|
|
|
check_result(result, "dns_dispatch_getudp");
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
result = dns_requestmgr_create(mctx, timermgr,
|
|
|
|
socketmgr, taskmgr, dispatchmgr,
|
2000-06-16 17:10:02 +00:00
|
|
|
dispatchv4, NULL, &requestmgr);
|
2000-06-10 00:50:36 +00:00
|
|
|
check_result(result, "dns_requestmgr_create");
|
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
if (domain != NULL) {
|
|
|
|
dns_fixedname_init(&resolvdomain);
|
2000-06-10 00:50:36 +00:00
|
|
|
isc_buffer_init(&buf, domain, strlen(domain));
|
|
|
|
isc_buffer_add(&buf, strlen(domain));
|
2000-06-30 01:56:14 +00:00
|
|
|
result = dns_name_fromtext(dns_fixedname_name(&resolvdomain),
|
|
|
|
&buf, dns_rootname, ISC_FALSE, NULL);
|
2000-06-10 00:50:36 +00:00
|
|
|
check_result(result, "dns_name_fromtext");
|
2000-06-30 01:56:14 +00:00
|
|
|
current_zone = dns_fixedname_name(&resolvdomain);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
2000-06-30 01:56:14 +00:00
|
|
|
else
|
2000-06-20 22:50:13 +00:00
|
|
|
current_zone = dns_rootname;
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
if (keystr != NULL) {
|
|
|
|
dns_fixedname_t fkeyname;
|
|
|
|
dns_name_t *keyname;
|
|
|
|
isc_buffer_t keynamesrc;
|
|
|
|
char *secretstr;
|
|
|
|
unsigned char *secret;
|
|
|
|
int secretlen;
|
|
|
|
isc_buffer_t secretsrc, secretbuf;
|
|
|
|
isc_lex_t *lex = NULL;
|
|
|
|
char *s;
|
|
|
|
|
2000-06-23 20:46:25 +00:00
|
|
|
debug("Creating key...");
|
2000-06-30 01:56:14 +00:00
|
|
|
|
|
|
|
s = strchr(keystr, ':');
|
|
|
|
if (s == NULL || s == keystr || *s++ == 0)
|
|
|
|
fatal("key option must specify keyname:secret\n");
|
|
|
|
secretstr = s + 1;
|
|
|
|
|
2000-06-23 20:46:25 +00:00
|
|
|
result = dns_tsigkeyring_create(mctx, &keyring);
|
|
|
|
check_result(result, "dns_tsigkeyringcreate");
|
2000-06-30 01:56:14 +00:00
|
|
|
|
|
|
|
dns_fixedname_init(&fkeyname);
|
|
|
|
keyname = dns_fixedname_name(&fkeyname);
|
|
|
|
|
|
|
|
isc_buffer_init(&keynamesrc, keystr, 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(&secretsrc, secretstr, strlen(secretstr));
|
|
|
|
isc_buffer_add(&secretsrc, strlen(secretstr));
|
|
|
|
|
|
|
|
isc_buffer_init(&secretbuf, secret, secretlen);
|
|
|
|
|
|
|
|
result = isc_lex_create(mctx, strlen(secretstr), &lex);
|
2000-06-23 20:46:25 +00:00
|
|
|
check_result(result, "isc_lex_create");
|
|
|
|
result = isc_lex_openbuffer(lex, &secretsrc);
|
|
|
|
check_result(result, "isc_lex_openbuffer");
|
|
|
|
result = isc_base64_tobuffer(lex, &secretbuf, -1);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-06-30 01:56:14 +00:00
|
|
|
printf (";; Couldn't create key from %s: %s\n",
|
|
|
|
keystr, isc_result_totext(result));
|
2000-06-23 20:46:25 +00:00
|
|
|
isc_lex_close(lex);
|
|
|
|
isc_lex_destroy(&lex);
|
|
|
|
goto SYSSETUP_FAIL;
|
|
|
|
}
|
2000-06-30 01:56:14 +00:00
|
|
|
secretlen = isc_buffer_usedlength(&secretbuf);
|
2000-06-23 20:46:25 +00:00
|
|
|
debug("close");
|
|
|
|
isc_lex_close(lex);
|
|
|
|
isc_lex_destroy(&lex);
|
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
debug("keycreate");
|
|
|
|
result = dns_tsigkey_create(keyname, dns_tsig_hmacmd5_name,
|
|
|
|
secret, secretlen,
|
|
|
|
ISC_TRUE, NULL, 0, 0, mctx,
|
2000-06-23 20:46:25 +00:00
|
|
|
keyring, &key);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-06-30 01:56:14 +00:00
|
|
|
printf (";; Couldn't create key from %s: %s\n",
|
|
|
|
keystr, dns_result_totext(result));
|
2000-06-23 20:46:25 +00:00
|
|
|
}
|
2000-06-30 01:56:14 +00:00
|
|
|
isc_mem_free(mctx, secret);
|
2000-06-23 20:46:25 +00:00
|
|
|
return;
|
|
|
|
SYSSETUP_FAIL:
|
2000-06-30 01:56:14 +00:00
|
|
|
isc_mem_free(mctx, secret);
|
2000-06-23 20:46:25 +00:00
|
|
|
dns_tsigkeyring_destroy(&keyring);
|
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
2000-06-23 20:46:25 +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;
|
|
|
|
isc_mem_debugging = ISC_TRUE;
|
2000-06-30 01:56:14 +00:00
|
|
|
break;
|
|
|
|
case 'y':
|
|
|
|
keystr = isc_commandline_argument;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
fprintf(stderr, "Virtual Circuit mode not "
|
|
|
|
"currently implemented.\n");
|
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
fprintf(stderr, "TSIG not currently implemented.");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "%s: invalid argument -%c\n",
|
|
|
|
argv[0], ch);
|
|
|
|
exit(1);
|
|
|
|
}
|
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
|
|
|
make_prereq(char *cmdline, isc_boolean_t ispositive, isc_boolean_t isrrset) {
|
2000-06-10 00:50:36 +00:00
|
|
|
isc_result_t result;
|
2000-06-30 03:24:27 +00:00
|
|
|
char *word;
|
2000-06-10 00:50:36 +00:00
|
|
|
dns_name_t *name = NULL;
|
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
|
|
|
isc_textregion_t region;
|
2000-06-10 00:50:36 +00:00
|
|
|
dns_rdataset_t *rdataset = NULL;
|
2000-06-19 22:09:46 +00:00
|
|
|
dns_rdatalist_t *rdatalist = NULL;
|
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-19 22:09:46 +00:00
|
|
|
dns_rdata_t *rdata = NULL;
|
2000-06-20 22:50:13 +00:00
|
|
|
dns_name_t *rn = current_zone;
|
2000-06-30 01:56:14 +00:00
|
|
|
unsigned int dots;
|
|
|
|
isc_boolean_t last;
|
2000-06-20 22:50:13 +00:00
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
ddebug ("make_prereq()");
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
/*
|
|
|
|
* Read the owner name
|
|
|
|
*/
|
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
|
|
|
puts("failed to read owner name");
|
|
|
|
return (STATUS_SYNTAX);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
result = dns_message_gettempname(updatemsg, &name);
|
|
|
|
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");
|
|
|
|
dns_name_init(name, NULL);
|
2000-06-30 01:56:14 +00:00
|
|
|
dns_name_setbuffer(name, namebuf);
|
|
|
|
dns_message_takebuffer(updatemsg, &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 01:56:14 +00:00
|
|
|
if (dots > ndots || last)
|
2000-06-20 22:50:13 +00:00
|
|
|
rn = dns_rootname;
|
|
|
|
result = dns_name_fromtext(name, &source, rn,
|
2000-06-10 00:50:36 +00:00
|
|
|
ISC_FALSE, NULL);
|
|
|
|
check_result(result, "dns_name_fromtext");
|
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-06-30 01:56:14 +00:00
|
|
|
puts("failed to read class or type");
|
|
|
|
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-06-30 01:56:14 +00:00
|
|
|
puts("failed to read type");
|
|
|
|
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-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;
|
|
|
|
if (ispositive)
|
|
|
|
rdatalist->rdclass = dns_rdataclass_any;
|
|
|
|
else
|
|
|
|
rdatalist->rdclass = dns_rdataclass_none;
|
2000-06-19 22:09:46 +00:00
|
|
|
rdatalist->covers = 0;
|
|
|
|
rdatalist->ttl = 0;
|
|
|
|
result = dns_message_gettemprdata(updatemsg, &rdata);
|
|
|
|
check_result(result, "dns_message_gettemprdata");
|
|
|
|
rdata->data = NULL;
|
|
|
|
rdata->length = 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);
|
|
|
|
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-06-16 17:10:02 +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-06-10 00:50:36 +00:00
|
|
|
puts ("failed to read operation code");
|
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-06-30 03:24:27 +00:00
|
|
|
printf("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) {
|
|
|
|
UNUSED(cmdline);
|
2000-06-30 01:56:14 +00:00
|
|
|
printf("The server statement is not currently implemented.\n");
|
|
|
|
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) {
|
|
|
|
UNUSED(cmdline);
|
2000-06-30 01:56:14 +00:00
|
|
|
printf("The zone statement is not currently implemented.\n");
|
|
|
|
return (STATUS_MORE);
|
|
|
|
#if 0
|
2000-06-30 03:24:27 +00:00
|
|
|
char *word;
|
2000-06-30 01:56:14 +00:00
|
|
|
dns_name_t *name;
|
|
|
|
isc_buffer_t src;
|
2000-06-20 22:50:13 +00:00
|
|
|
isc_result_t result;
|
2000-06-30 01:56:14 +00:00
|
|
|
dns_fixedname_t fname;
|
2000-06-20 22:50:13 +00:00
|
|
|
|
|
|
|
ddebug ("evaluate_zone()");
|
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
|
|
|
printf("failed to read zone name");
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
} else if (zonename != NULL)
|
|
|
|
dns_name_free(zonename, mctx);
|
2000-06-20 22:50:13 +00:00
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
dns_fixedname_init(&fname);
|
|
|
|
name = dns_fixedname_name(&fname);
|
2000-06-20 22:50:13 +00:00
|
|
|
|
2000-06-30 03:24:27 +00:00
|
|
|
isc_buffer_init(&src, word, strlen(word));
|
|
|
|
isc_buffer_add(&src, strlen(word));
|
2000-06-20 22:50:13 +00:00
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
result = dns_name_fromtext(name, &src, dns_rootname, ISC_FALSE, NULL);
|
|
|
|
check_result(result, "dns_name_fromtext");
|
|
|
|
|
|
|
|
if (zonename == NULL) {
|
|
|
|
zonename = isc_mem_get(mctx, sizeof(dns_name_t));
|
|
|
|
if (zonename == NULL)
|
|
|
|
fatal("out of memory");
|
|
|
|
}
|
|
|
|
dns_name_init(zonename, NULL);
|
|
|
|
dns_name_dup(name, mctx, zonename);
|
|
|
|
current_zone = zonename;
|
2000-06-20 22:50:13 +00:00
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
return (STATUS_MORE);
|
|
|
|
#endif
|
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;
|
|
|
|
isc_lex_t *lex = NULL;
|
|
|
|
isc_buffer_t *buf = NULL;
|
|
|
|
isc_buffer_t *namebuf = NULL;
|
|
|
|
isc_buffer_t source;
|
|
|
|
dns_name_t *name = NULL;
|
|
|
|
isc_uint16_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;
|
|
|
|
dns_rdatacallbacks_t callbacks;
|
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-20 22:50:13 +00:00
|
|
|
dns_name_t *rn = current_zone;
|
2000-06-30 01:56:14 +00:00
|
|
|
char *endp;
|
|
|
|
unsigned int dots;
|
|
|
|
isc_boolean_t last;
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
ddebug ("update_addordelete()");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the owner name
|
|
|
|
*/
|
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-10 00:50:36 +00:00
|
|
|
puts ("failed to read owner name");
|
2000-06-30 01:56:14 +00:00
|
|
|
return (STATUS_SYNTAX);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
result = dns_message_gettempname(updatemsg, &name);
|
|
|
|
check_result(result, "dns_message_gettempname");
|
|
|
|
result = isc_buffer_allocate(mctx, &namebuf, NAMEBUF);
|
|
|
|
check_result(result, "isc_buffer_allocate");
|
|
|
|
dns_name_init(name, NULL);
|
|
|
|
dns_name_setbuffer(name, namebuf);
|
2000-06-17 00:16:50 +00:00
|
|
|
dns_message_takebuffer(updatemsg, &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 01:56:14 +00:00
|
|
|
if (dots > ndots || last)
|
2000-06-20 22:50:13 +00:00
|
|
|
rn = dns_rootname;
|
|
|
|
result = dns_name_fromtext(name, &source, rn,
|
2000-06-10 00:50:36 +00:00
|
|
|
ISC_FALSE, NULL);
|
|
|
|
check_result(result, "dns_name_fromtext");
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is an add, read the TTL and verify that it's numeric.
|
|
|
|
*/
|
|
|
|
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-06-30 01:56:14 +00:00
|
|
|
puts ("failed to read owner ttl");
|
|
|
|
dns_message_puttempname(updatemsg, &name);
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
2000-06-30 03:24:27 +00:00
|
|
|
ttl = strtol(word, &endp, 0);
|
2000-06-30 01:56:14 +00:00
|
|
|
if (*endp != 0) {
|
2000-06-30 03:24:27 +00:00
|
|
|
printf("ttl '%s' is not numeric\n", word);
|
2000-06-30 01:56:14 +00:00
|
|
|
dns_message_puttempname(updatemsg, &name);
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
|
|
|
} 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 {
|
|
|
|
puts ("failed to read class or type");
|
|
|
|
dns_message_puttempname(updatemsg, &name);
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
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 {
|
|
|
|
puts ("failed to read type");
|
|
|
|
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");
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
2000-06-30 03:24:27 +00:00
|
|
|
while (*cmdline != 0 && isspace(*cmdline))
|
|
|
|
cmdline++;
|
|
|
|
|
|
|
|
if (*cmdline == 0) {
|
2000-06-30 01:56:14 +00:00
|
|
|
if (isdelete) {
|
|
|
|
rdataclass = dns_rdataclass_any;
|
|
|
|
goto doneparsing;
|
|
|
|
} else {
|
|
|
|
puts ("failed to read owner data");
|
|
|
|
dns_message_puttempname(updatemsg, &name);
|
|
|
|
return (STATUS_SYNTAX);
|
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
2000-06-30 03:24:27 +00:00
|
|
|
result = isc_lex_create(mctx, WORDLEN, &lex);
|
2000-06-10 00:50:36 +00:00
|
|
|
check_result(result, "isc_lex_create");
|
|
|
|
isc_buffer_invalidate(&source);
|
|
|
|
|
2000-06-30 03:24:27 +00:00
|
|
|
isc_buffer_init(&source, cmdline, strlen(cmdline));
|
|
|
|
isc_buffer_add(&source, strlen(cmdline));
|
2000-06-10 00:50:36 +00:00
|
|
|
result = isc_lex_openbuffer(lex, &source);
|
|
|
|
check_result(result, "isc_lex_openbuffer");
|
|
|
|
|
|
|
|
result = isc_buffer_allocate(mctx, &buf, MXNAME);
|
|
|
|
check_result(result, "isc_buffer_allocate");
|
|
|
|
dns_rdatacallbacks_init_stdio(&callbacks);
|
2000-06-30 01:56:14 +00:00
|
|
|
result = dns_rdata_fromtext(rdata, rdataclass, rdatatype,
|
2000-06-20 22:50:13 +00:00
|
|
|
lex, current_zone, ISC_FALSE, buf,
|
2000-06-10 00:50:36 +00:00
|
|
|
&callbacks);
|
2000-06-30 01:56:14 +00:00
|
|
|
dns_message_takebuffer(updatemsg, &buf);
|
2000-06-17 00:16:50 +00:00
|
|
|
isc_lex_destroy(&lex);
|
2000-06-30 03:45:54 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
dns_message_puttempname(updatemsg, &name);
|
|
|
|
dns_message_puttemprdata(updatemsg, &rdata);
|
|
|
|
return (STATUS_MORE);
|
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
if (isdelete)
|
|
|
|
rdataclass = dns_rdataclass_none;
|
|
|
|
|
|
|
|
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;
|
|
|
|
rdatalist->ttl = ttl;
|
|
|
|
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-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-06-16 17:10:02 +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-06-10 00:50:36 +00:00
|
|
|
puts ("failed to read operation code");
|
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-06-30 03:24:27 +00:00
|
|
|
printf ("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-06-30 01:56:14 +00:00
|
|
|
show_message(void) {
|
2000-06-10 00:50:36 +00:00
|
|
|
isc_result_t result;
|
|
|
|
char store[MSGTEXT];
|
|
|
|
isc_buffer_t buf;
|
|
|
|
|
2000-06-16 17:10:02 +00:00
|
|
|
ddebug ("show_message()");
|
2000-06-10 00:50:36 +00:00
|
|
|
isc_buffer_init(&buf, store, MSGTEXT);
|
|
|
|
result = dns_message_totext(updatemsg, 0, &buf);
|
2000-06-30 01:56:14 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
printf("Failed to concert message to text format.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("Outgoing update query:\n%.*s",
|
|
|
|
(int)isc_buffer_usedlength(&buf),
|
|
|
|
(char*)isc_buffer_base(&buf));
|
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-06-16 17:10:02 +00:00
|
|
|
ddebug ("get_next_command()");
|
2000-06-10 00:50:36 +00:00
|
|
|
fputs ("> ", stderr);
|
2000-06-30 03:24:27 +00:00
|
|
|
fgets (cmdlinebuf, MAXCMD, stdin);
|
|
|
|
cmdline = cmdlinebuf;
|
|
|
|
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-06-10 00:50:36 +00:00
|
|
|
show_message();
|
2000-06-30 01:56:14 +00:00
|
|
|
return (STATUS_MORE);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
2000-06-30 03:24:27 +00:00
|
|
|
printf ("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-06-16 17:10:02 +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
|
|
|
|
get_address(char *host, in_port_t port, isc_sockaddr_t *sockaddr) {
|
|
|
|
struct in_addr in4;
|
|
|
|
struct in6_addr in6;
|
|
|
|
struct hostent *he;
|
|
|
|
|
2000-06-16 17:10:02 +00:00
|
|
|
ddebug("get_address()");
|
2000-06-10 00:50:36 +00:00
|
|
|
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 {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
isc_buffer_t buf;
|
|
|
|
dns_message_t *rcvmsg = NULL;
|
|
|
|
char bufstore[MSGTEXT];
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
UNUSED (task);
|
2000-06-16 17:10:02 +00:00
|
|
|
|
|
|
|
ddebug ("updated_completed()");
|
|
|
|
REQUIRE(event->ev_type == DNS_EVENT_REQUESTDONE);
|
|
|
|
reqev = (dns_requestevent_t *)event;
|
|
|
|
if (reqev->result != ISC_R_SUCCESS) {
|
2000-06-30 01:56:14 +00:00
|
|
|
printf ("; Communication with server failed: %s\n",
|
|
|
|
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");
|
|
|
|
result = dns_request_getresponse(reqev->request, rcvmsg, ISC_TRUE);
|
|
|
|
check_result(result, "dns_request_getresponse");
|
2000-06-29 02:16:44 +00:00
|
|
|
if (debugging) {
|
2000-06-16 17:10:02 +00:00
|
|
|
isc_buffer_init(&buf, bufstore, MSGTEXT);
|
|
|
|
result = dns_message_totext(rcvmsg, 0, &buf);
|
|
|
|
check_result(result, "dns_message_totext");
|
|
|
|
printf ("\nReply from update query:\n%.*s\n",
|
|
|
|
(int)isc_buffer_usedlength(&buf),
|
|
|
|
(char*)isc_buffer_base(&buf));
|
|
|
|
}
|
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-06-30 01:56:14 +00:00
|
|
|
LOCK(&lock);
|
2000-06-16 17:10:02 +00:00
|
|
|
busy = ISC_FALSE;
|
2000-06-30 01:56:14 +00:00
|
|
|
SIGNAL(&cond);
|
|
|
|
UNLOCK(&lock);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-06-30 01:56:14 +00:00
|
|
|
send_update(void) {
|
2000-06-10 00:50:36 +00:00
|
|
|
isc_result_t result;
|
|
|
|
isc_sockaddr_t sockaddr;
|
|
|
|
dns_request_t *request = NULL;
|
|
|
|
char servername[MXNAME];
|
|
|
|
isc_buffer_t buf;
|
|
|
|
dns_name_t *name = NULL;
|
2000-06-16 17:10:02 +00:00
|
|
|
dns_rdataset_t *rdataset = NULL;
|
|
|
|
|
|
|
|
ddebug ("send_update()");
|
2000-06-10 00:50:36 +00:00
|
|
|
|
|
|
|
result = dns_message_gettempname(updatemsg, &name);
|
|
|
|
check_result(result, "dns_message_gettempname");
|
2000-06-30 01:56:14 +00:00
|
|
|
if (zonename == NULL)
|
|
|
|
fatal("don't have a valid zone yet.");
|
2000-06-10 00:50:36 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
isc_buffer_init(&buf, servername, MXNAME);
|
2000-06-30 01:56:14 +00:00
|
|
|
result = dns_name_totext(master, ISC_TRUE, &buf);
|
2000-06-10 00:50:36 +00:00
|
|
|
check_result(result, "dns_name_totext");
|
2000-06-23 20:46:25 +00:00
|
|
|
|
2000-06-16 17:10:02 +00:00
|
|
|
servername[isc_buffer_usedlength(&buf)] = 0;
|
2000-06-10 00:50:36 +00:00
|
|
|
get_address(servername, 53, &sockaddr);
|
|
|
|
result = dns_request_create(requestmgr, updatemsg, &sockaddr,
|
2000-06-23 20:46:25 +00:00
|
|
|
0, key,
|
2000-06-10 00:50:36 +00:00
|
|
|
FIND_TIMEOUT, global_task,
|
|
|
|
update_completed, NULL, &request);
|
|
|
|
check_result(result, "dns_request_create");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
find_completed(isc_task_t *task, isc_event_t *event) {
|
|
|
|
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;
|
2000-06-30 01:56:14 +00:00
|
|
|
dns_message_t *soaquery = NULL;
|
2000-06-10 00:50:36 +00:00
|
|
|
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-06-10 00:50:36 +00:00
|
|
|
|
|
|
|
UNUSED(task);
|
|
|
|
|
2000-06-16 17:10:02 +00:00
|
|
|
ddebug ("find_completed()");
|
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;
|
|
|
|
soaquery = reqev->ev_arg;
|
|
|
|
|
|
|
|
isc_event_free(&event);
|
|
|
|
reqev = NULL;
|
|
|
|
|
|
|
|
if (eresult != ISC_R_SUCCESS) {
|
|
|
|
printf ("; Communication with %s failed: %s\n",
|
|
|
|
nameservername[ns_inuse], isc_result_totext(eresult));
|
2000-06-10 00:50:36 +00:00
|
|
|
ns_inuse++;
|
2000-06-30 01:56:14 +00:00
|
|
|
if (ns_inuse >= nameservers)
|
2000-06-10 00:50:36 +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);
|
|
|
|
sendrequest(ns_inuse, soaquery, &request);
|
2000-06-10 00:50:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-06-30 01:56:14 +00:00
|
|
|
dns_message_destroy(&soaquery);
|
|
|
|
|
2000-06-17 00:16:50 +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-06-30 01:56:14 +00:00
|
|
|
result = dns_request_getresponse(request, rcvmsg, ISC_TRUE);
|
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-06-30 01:56:14 +00:00
|
|
|
isc_buffer_t buf;
|
|
|
|
char bufstore[MSGTEXT];
|
|
|
|
|
2000-06-16 17:10:02 +00:00
|
|
|
isc_buffer_init(&buf, bufstore, MSGTEXT);
|
|
|
|
result = dns_message_totext(rcvmsg, 0, &buf);
|
|
|
|
check_result(result, "dns_message_totext");
|
2000-06-20 22:50:13 +00:00
|
|
|
printf ("Reply from SOA query:\n%.*s\n",
|
|
|
|
(int)isc_buffer_usedlength(&buf),
|
2000-06-16 17:10:02 +00:00
|
|
|
(char*)isc_buffer_base(&buf));
|
|
|
|
}
|
|
|
|
|
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-06-30 01:56:14 +00:00
|
|
|
char namestr[1025];
|
|
|
|
dns_name_format(name, namestr, sizeof(namestr));
|
|
|
|
printf ("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-06-17 00:16:50 +00:00
|
|
|
ddebug("Duping master");
|
2000-06-30 01:56:14 +00:00
|
|
|
INSIST(master == NULL);
|
|
|
|
master = isc_mem_get(mctx, sizeof(dns_name_t));
|
|
|
|
dns_name_init(master, NULL);
|
|
|
|
result = dns_name_dup(&soa.origin, mctx, master);
|
2000-06-10 00:50:36 +00:00
|
|
|
check_result(result, "dns_name_dup");
|
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
ddebug("Duping zonename");
|
|
|
|
INSIST(zonename == NULL);
|
|
|
|
zonename = isc_mem_get(mctx, sizeof(dns_name_t));
|
|
|
|
dns_name_init(zonename, NULL);
|
|
|
|
result = dns_name_dup(name, mctx, zonename);
|
|
|
|
check_result(result, "dns_name_dup");
|
|
|
|
|
|
|
|
dns_rdata_freestruct(&soa);
|
|
|
|
|
2000-06-16 17:10:02 +00:00
|
|
|
if (debugging) {
|
2000-06-30 01:56:14 +00:00
|
|
|
char namestr[1025];
|
|
|
|
dns_name_format(master, namestr, sizeof(namestr));
|
|
|
|
printf ("The master is: %s\n", namestr);
|
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-06-17 00:16:50 +00:00
|
|
|
ddebug ("Out of find_completed");
|
2000-06-10 00:50:36 +00:00
|
|
|
send_update();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-06-30 01:56:14 +00:00
|
|
|
sendrequest(int whichns, dns_message_t *msg, dns_request_t **request) {
|
|
|
|
isc_sockaddr_t sockaddr;
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
get_address(nameservername[whichns], 53, &sockaddr);
|
|
|
|
result = dns_request_create(requestmgr, msg, &sockaddr,
|
|
|
|
0, NULL, FIND_TIMEOUT, global_task,
|
|
|
|
find_completed, msg, request);
|
|
|
|
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-06-16 17:10:02 +00:00
|
|
|
ddebug ("start_update()");
|
2000-06-30 03:24:27 +00:00
|
|
|
|
|
|
|
result = dns_message_firstname(updatemsg, DNS_SECTION_UPDATE);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
busy = ISC_FALSE;
|
|
|
|
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
|
|
|
|
|
|
|
ns_inuse = 0;
|
2000-06-30 01:56:14 +00:00
|
|
|
sendrequest(ns_inuse, soaquery, &request);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2000-06-30 01:56:14 +00:00
|
|
|
cleanup(void) {
|
|
|
|
ddebug ("cleanup()");
|
2000-06-17 00:16:50 +00:00
|
|
|
|
2000-06-23 20:46:25 +00:00
|
|
|
if (key != NULL) {
|
|
|
|
ddebug("Freeing key");
|
|
|
|
dns_tsigkey_setdeleted(key);
|
|
|
|
dns_tsigkey_detach(&key);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keyring != NULL) {
|
|
|
|
debug ("Freeing keyring %lx", keyring);
|
|
|
|
dns_tsigkeyring_destroy(&keyring);
|
|
|
|
}
|
|
|
|
|
2000-06-17 00:16:50 +00:00
|
|
|
if (updatemsg != NULL)
|
|
|
|
dns_message_destroy(&updatemsg);
|
|
|
|
|
2000-06-30 01:56:14 +00:00
|
|
|
if (zonename != NULL) {
|
|
|
|
dns_name_free(zonename, mctx);
|
|
|
|
isc_mem_put(mctx, zonename, sizeof(dns_name_t));
|
|
|
|
zonename = NULL;
|
2000-06-17 00:16:50 +00:00
|
|
|
}
|
2000-06-30 01:56:14 +00:00
|
|
|
if (master != NULL) {
|
|
|
|
dns_name_free(master, mctx);
|
|
|
|
isc_mem_put(mctx, master, sizeof(dns_name_t));
|
|
|
|
master = NULL;
|
|
|
|
}
|
|
|
|
if (domain != NULL) {
|
|
|
|
isc_mem_free(mctx, domain);
|
|
|
|
domain = NULL;
|
2000-06-17 00:16:50 +00:00
|
|
|
}
|
2000-06-23 20:46:25 +00:00
|
|
|
if (is_dst_up) {
|
|
|
|
debug ("Destroy DST lib");
|
|
|
|
dst_lib_destroy();
|
|
|
|
is_dst_up = ISC_FALSE;
|
|
|
|
}
|
|
|
|
if (entp != NULL) {
|
|
|
|
debug ("Detach from entropy");
|
|
|
|
isc_entropy_detach(&entp);
|
|
|
|
}
|
|
|
|
|
2000-06-17 00:16:50 +00:00
|
|
|
ddebug("Shutting down request manager");
|
|
|
|
dns_requestmgr_shutdown(requestmgr);
|
|
|
|
dns_requestmgr_detach(&requestmgr);
|
|
|
|
|
|
|
|
ddebug("Freeing the dispatcher");
|
|
|
|
dns_dispatch_detach(&dispatchv4);
|
|
|
|
|
|
|
|
ddebug("Shutting down dispatch manager");
|
|
|
|
dns_dispatchmgr_destroy(&dispatchmgr);
|
|
|
|
|
|
|
|
ddebug("Ending task");
|
|
|
|
isc_task_detach(&global_task);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv) {
|
|
|
|
isc_result_t result;
|
|
|
|
|
2000-06-23 20:46:25 +00:00
|
|
|
parse_args(argc, argv);
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
setup_system();
|
|
|
|
result = isc_mutex_init(&lock);
|
|
|
|
check_result(result, "isc_mutex_init");
|
|
|
|
result = isc_condition_init(&cond);
|
|
|
|
check_result(result, "isc_condition_init");
|
2000-06-30 01:56:14 +00:00
|
|
|
LOCK(&lock);
|
2000-06-10 00:50:36 +00:00
|
|
|
|
|
|
|
while (ISC_TRUE) {
|
|
|
|
reset_system();
|
|
|
|
if (!user_interaction())
|
|
|
|
break;
|
|
|
|
busy = ISC_TRUE;
|
|
|
|
start_update();
|
2000-06-30 01:56:14 +00:00
|
|
|
while (busy)
|
|
|
|
WAIT(&cond, &lock);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
puts ("");
|
2000-06-16 17:10:02 +00:00
|
|
|
ddebug ("Fell through app_run");
|
2000-06-10 00:50:36 +00:00
|
|
|
isc_mutex_destroy(&lock);
|
|
|
|
isc_condition_destroy(&cond);
|
2000-06-30 01:56:14 +00:00
|
|
|
cleanup();
|
2000-06-10 00:50:36 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|