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-29 02:16:44 +00:00
|
|
|
/* $Id: nsupdate.c,v 1.11 2000/06/29 02:16:44 bwelling Exp $ */
|
2000-06-10 00:50:36 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
2000-06-21 17:48:32 +00:00
|
|
|
#include <netdb.h>
|
2000-06-10 00:50:36 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2000-06-21 17:48:32 +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/rdatalist.h>
|
|
|
|
#include <dns/rdataset.h>
|
|
|
|
#include <dns/rdatastruct.h>
|
|
|
|
#include <dns/rdatatype.h>
|
|
|
|
#include <dns/request.h>
|
2000-06-23 20:46:25 +00:00
|
|
|
#include <dns/result.h>
|
|
|
|
#include <dns/tsig.h>
|
|
|
|
#include <dst/dst.h>
|
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-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-23 20:46:25 +00:00
|
|
|
#include <isc/stdtime.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
|
|
|
|
|
|
|
#define MXNAME 256
|
|
|
|
#define MAXCMD 256
|
|
|
|
#define NAMEBUF 512
|
|
|
|
#define NAMEHINT 64
|
|
|
|
#define PACKETSIZE 2048
|
|
|
|
#define MSGTEXT 4069
|
|
|
|
#define FIND_TIMEOUT 5
|
|
|
|
|
|
|
|
#define VALID_NAME(n) ISC_MAGIC_VALID(n, DNS_NAME_MAGIC)
|
|
|
|
|
|
|
|
#define RESOLV_CONF "/etc/resolv.conf"
|
|
|
|
|
2000-06-17 00:16:50 +00:00
|
|
|
extern isc_boolean_t isc_mem_debugging;
|
|
|
|
|
2000-06-20 22:50:13 +00:00
|
|
|
isc_boolean_t busy= ISC_FALSE, debugging = ISC_FALSE, ddebugging = ISC_FALSE,
|
|
|
|
have_ipv6 = ISC_FALSE, valid_zonename = ISC_FALSE,
|
2000-06-23 20:46:25 +00:00
|
|
|
forced_master = ISC_FALSE, is_dst_up = ISC_FALSE;
|
2000-06-10 00:50:36 +00:00
|
|
|
isc_mutex_t lock;
|
|
|
|
isc_condition_t cond;
|
|
|
|
|
|
|
|
isc_taskmgr_t *taskmgr = NULL;
|
|
|
|
isc_task_t *global_task = NULL;
|
|
|
|
isc_mem_t *mctx = NULL;
|
|
|
|
dns_dispatchmgr_t *dispatchmgr = NULL;
|
|
|
|
dns_requestmgr_t *requestmgr = NULL;
|
|
|
|
isc_socketmgr_t *socketmgr = NULL;
|
|
|
|
isc_timermgr_t *timermgr = NULL;
|
2000-06-16 17:10:02 +00:00
|
|
|
dns_dispatch_t *dispatchv4 = NULL;
|
2000-06-10 00:50:36 +00:00
|
|
|
dns_message_t *updatemsg = NULL, *findmsg = NULL;
|
2000-06-20 22:50:13 +00:00
|
|
|
dns_name_t zonename; /* From ZONE command */
|
|
|
|
dns_name_t actualzone; /* From SOA query reply */
|
|
|
|
dns_name_t resolvdomain; /* From resolv.conf's domain line, if exists */
|
|
|
|
dns_name_t *current_zone; /* Points to one of above, or dns_rootname */
|
|
|
|
isc_buffer_t resolvbuf;
|
|
|
|
char resolvstore[MXNAME];
|
|
|
|
dns_name_t master; /* Master nameserver, from SOA query */
|
2000-06-23 20:46:25 +00:00
|
|
|
dns_tsigkey_t *key = NULL;
|
|
|
|
dns_tsig_keyring_t *keyring = NULL;
|
2000-06-10 00:50:36 +00:00
|
|
|
|
|
|
|
int exitcode = 0;
|
|
|
|
char server[MXNAME];
|
2000-06-20 22:50:13 +00:00
|
|
|
char userzone[MXNAME];
|
2000-06-10 00:50:36 +00:00
|
|
|
char nameservername[3][MXNAME];
|
|
|
|
int nameservers;
|
|
|
|
int ns_inuse = 0;
|
|
|
|
int ndots = 1;
|
|
|
|
char domain[MXNAME];
|
2000-06-23 20:46:25 +00:00
|
|
|
char keynametext[MXNAME]="";
|
|
|
|
char keysecret[MXNAME]="";
|
|
|
|
dns_name_t keyname;
|
|
|
|
isc_buffer_t *keynamebuf = NULL;
|
|
|
|
isc_entropy_t *entp = NULL;
|
2000-06-10 00:50:36 +00:00
|
|
|
|
|
|
|
#define STATUS_MORE 0
|
|
|
|
#define STATUS_SEND 1
|
|
|
|
#define STATUS_QUIT 2
|
|
|
|
#define STATUS_FAIL 3
|
2000-06-17 00:16:50 +00:00
|
|
|
#define STATUS_SYNTAX 4
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-06-20 22:50:13 +00:00
|
|
|
static int
|
|
|
|
count_dots(char *string) {
|
|
|
|
char *s;
|
|
|
|
int i=0;
|
|
|
|
|
|
|
|
s = string;
|
|
|
|
while (*s != 0) {
|
|
|
|
if (*s == '.')
|
|
|
|
i++;
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
return (i);
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
if (exitcode == 0)
|
|
|
|
exitcode = 8;
|
|
|
|
exit(exitcode);
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
exitcode = 1;
|
|
|
|
fatal("%s: %s", msg, isc_result_totext(result));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
load_resolv_conf() {
|
|
|
|
FILE *fp;
|
|
|
|
char rcinput[MXNAME];
|
|
|
|
char *ptr;
|
|
|
|
|
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");
|
|
|
|
if (fp != NULL) {
|
|
|
|
while (fgets(rcinput, MXNAME, fp) != 0) {
|
|
|
|
ptr = strtok (rcinput, " \t\r\n");
|
|
|
|
if (ptr != NULL) {
|
|
|
|
if (strcasecmp(ptr, "nameserver") == 0) {
|
2000-06-16 17:10:02 +00:00
|
|
|
ddebug ("Got a nameserver line");
|
2000-06-10 00:50:36 +00:00
|
|
|
ptr = strtok (NULL, " \t\r\n");
|
|
|
|
if (ptr != NULL) {
|
|
|
|
if (nameservers < 3) {
|
|
|
|
strncpy(nameservername
|
|
|
|
[nameservers],
|
|
|
|
ptr,MXNAME);
|
|
|
|
nameservers++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (strcasecmp(ptr, "options") == 0) {
|
|
|
|
ptr = strtok(NULL, " \t\r\n");
|
|
|
|
if (ptr != NULL) {
|
|
|
|
if (strncasecmp(ptr, "ndots:",
|
|
|
|
6) == 0) {
|
|
|
|
ndots = atoi(&ptr[6]);
|
2000-06-16 17:10:02 +00:00
|
|
|
ddebug ("ndots is "
|
2000-06-10 00:50:36 +00:00
|
|
|
"%d.",
|
|
|
|
ndots);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* XXXMWS Searchlist not supported! */
|
|
|
|
} else if ((strcasecmp(ptr, "domain") == 0) &&
|
|
|
|
(domain[0] == 0 )){
|
|
|
|
while ((ptr = strtok(NULL, " \t\r\n"))
|
|
|
|
!= NULL) {
|
|
|
|
strncpy(domain, ptr, MXNAME);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose (fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
reset_system() {
|
|
|
|
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)
|
|
|
|
dns_message_destroy(&updatemsg);
|
2000-06-17 00:16:50 +00:00
|
|
|
if (findmsg != NULL)
|
|
|
|
dns_message_destroy(&findmsg);
|
2000-06-10 00:50:36 +00:00
|
|
|
result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER,
|
|
|
|
&updatemsg);
|
|
|
|
check_result (result, "dns_message_create");
|
|
|
|
updatemsg->opcode = dns_opcode_update;
|
|
|
|
|
|
|
|
valid_zonename = ISC_FALSE;
|
|
|
|
if (VALID_NAME(&zonename))
|
2000-06-17 00:16:50 +00:00
|
|
|
dns_name_free(&zonename, mctx);
|
2000-06-10 00:50:36 +00:00
|
|
|
if (VALID_NAME(&actualzone))
|
2000-06-17 00:16:50 +00:00
|
|
|
dns_name_free(&actualzone, mctx);
|
2000-06-10 00:50:36 +00:00
|
|
|
if (VALID_NAME(&master))
|
2000-06-17 00:16:50 +00:00
|
|
|
dns_name_free(&master, mctx);
|
2000-06-20 22:50:13 +00:00
|
|
|
if (domain[0] != 0)
|
|
|
|
current_zone = &resolvdomain;
|
|
|
|
else
|
|
|
|
current_zone = dns_rootname;
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-06-17 00:16:50 +00:00
|
|
|
setup_system(){
|
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-23 20:46:25 +00:00
|
|
|
int secretsize;
|
|
|
|
unsigned char *secretstore;
|
|
|
|
isc_buffer_t secretsrc;
|
|
|
|
isc_buffer_t secretbuf;
|
|
|
|
isc_lex_t *lex = NULL;
|
|
|
|
isc_stdtime_t now;
|
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-10 00:50:36 +00:00
|
|
|
*/
|
|
|
|
srandom (getpid() + (int)&setup_system);
|
|
|
|
|
2000-06-17 00:16:50 +00:00
|
|
|
isc_mem_debugging = ISC_FALSE;
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
load_resolv_conf();
|
|
|
|
|
|
|
|
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-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");
|
|
|
|
|
|
|
|
if (domain[0] != 0) {
|
2000-06-20 22:50:13 +00:00
|
|
|
dns_name_init(&resolvdomain, NULL);
|
|
|
|
isc_buffer_init(&resolvbuf, resolvstore, NAMEBUF);
|
|
|
|
dns_name_setbuffer(&resolvdomain, &resolvbuf);
|
2000-06-10 00:50:36 +00:00
|
|
|
isc_buffer_init(&buf, domain, strlen(domain));
|
|
|
|
isc_buffer_add(&buf, strlen(domain));
|
2000-06-20 22:50:13 +00:00
|
|
|
result = dns_name_fromtext(&resolvdomain, &buf, dns_rootname,
|
2000-06-10 00:50:36 +00:00
|
|
|
ISC_FALSE, NULL);
|
|
|
|
check_result(result, "dns_name_fromtext");
|
2000-06-20 22:50:13 +00:00
|
|
|
current_zone = &resolvdomain;
|
2000-06-10 00:50:36 +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-23 20:46:25 +00:00
|
|
|
if (keysecret[0] != 0) {
|
|
|
|
debug("Creating key...");
|
|
|
|
result = dns_tsigkeyring_create(mctx, &keyring);
|
|
|
|
check_result(result, "dns_tsigkeyringcreate");
|
|
|
|
result = isc_buffer_allocate(mctx, &keynamebuf, MXNAME);
|
|
|
|
check_result(result, "isc_buffer_allocate");
|
|
|
|
dns_name_init(&keyname, NULL);
|
|
|
|
check_result(result, "dns_name_init");
|
|
|
|
isc_buffer_putstr(keynamebuf, keynametext);
|
|
|
|
secretsize = strlen(keysecret) * 3 / 4;
|
|
|
|
secretstore = isc_mem_get(mctx, secretsize);
|
|
|
|
ENSURE (secretstore != NULL);
|
|
|
|
isc_buffer_init(&secretsrc, keysecret, strlen(keysecret));
|
|
|
|
isc_buffer_add(&secretsrc, strlen(keysecret));
|
|
|
|
isc_buffer_init(&secretbuf, secretstore, secretsize);
|
|
|
|
result = isc_lex_create(mctx, strlen(keysecret), &lex);
|
|
|
|
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) {
|
|
|
|
printf (";; Couldn't create key %s: %s\n",
|
|
|
|
keynametext, isc_result_totext(result));
|
|
|
|
isc_lex_close(lex);
|
|
|
|
isc_lex_destroy(&lex);
|
|
|
|
goto SYSSETUP_FAIL;
|
|
|
|
}
|
|
|
|
secretsize = isc_buffer_usedlength(&secretbuf);
|
|
|
|
debug("close");
|
|
|
|
isc_lex_close(lex);
|
|
|
|
isc_lex_destroy(&lex);
|
|
|
|
isc_stdtime_get(&now);
|
|
|
|
|
|
|
|
debug("namefromtext");
|
|
|
|
result = dns_name_fromtext(&keyname, keynamebuf,
|
|
|
|
dns_rootname, ISC_FALSE,
|
|
|
|
keynamebuf);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
printf (";; Couldn't create key %s: %s\n",
|
|
|
|
keynametext, dns_result_totext(result));
|
|
|
|
goto SYSSETUP_FAIL;
|
|
|
|
}
|
|
|
|
debug("tsigkey");
|
|
|
|
result = dns_tsigkey_create(&keyname, dns_tsig_hmacmd5_name,
|
|
|
|
secretstore, secretsize,
|
|
|
|
ISC_TRUE, NULL, now, now, mctx,
|
|
|
|
keyring, &key);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
printf (";; Couldn't create key %s: %s\n",
|
|
|
|
keynametext, dns_result_totext(result));
|
|
|
|
}
|
|
|
|
isc_mem_put(mctx, secretstore, secretsize);
|
|
|
|
dns_name_invalidate(&keyname);
|
|
|
|
isc_buffer_free(&keynamebuf);
|
|
|
|
return;
|
|
|
|
SYSSETUP_FAIL:
|
|
|
|
isc_mem_put(mctx, secretstore, secretsize);
|
|
|
|
dns_name_invalidate(&keyname);
|
|
|
|
isc_buffer_free(&keynamebuf);
|
|
|
|
dns_tsigkeyring_destroy(&keyring);
|
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
2000-06-23 20:46:25 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
set_key(char *key) {
|
|
|
|
char *nameptr;
|
|
|
|
char *secptr;
|
|
|
|
|
|
|
|
debug("set_key");
|
|
|
|
nameptr = strtok(key, ": \t\r\n");
|
|
|
|
if (nameptr == NULL) {
|
|
|
|
fputs ("Need a key entry\n", stderr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
secptr = strtok(NULL, " \t\r\n");
|
|
|
|
if (secptr == NULL) {
|
|
|
|
fputs ("Need a key entry\n", stderr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
strncpy (keynametext, nameptr, MXNAME);
|
|
|
|
strncpy (keysecret, secptr, MXNAME);
|
|
|
|
}
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
static void
|
2000-06-20 22:50:13 +00:00
|
|
|
parse_args(int argc, char **argv) {
|
|
|
|
int rc;
|
|
|
|
char **rv;
|
|
|
|
|
2000-06-23 20:46:25 +00:00
|
|
|
debug("parse_args");
|
2000-06-20 22:50:13 +00:00
|
|
|
rc = argc;
|
|
|
|
rv = argv;
|
|
|
|
for (rc--, rv++; rc > 0; rc--, rv++) {
|
|
|
|
if (strcasecmp(rv[0], "-d") == 0)
|
|
|
|
debugging = ISC_TRUE;
|
|
|
|
else if (strcasecmp(rv[0], "-dd") == 0) {
|
|
|
|
ddebugging = ISC_TRUE;
|
2000-06-23 20:46:25 +00:00
|
|
|
debug ("Just turned on debugging");
|
2000-06-20 22:50:13 +00:00
|
|
|
} else if (strcasecmp(rv[0], "-dm") == 0) {
|
|
|
|
ddebugging = ISC_TRUE;
|
|
|
|
isc_mem_debugging = ISC_TRUE;
|
2000-06-23 20:46:25 +00:00
|
|
|
} else if (strncasecmp(rv[0],"-y", 2) == 0) {
|
|
|
|
debug ("In -y test");
|
|
|
|
if (rv[0][2] != 0)
|
|
|
|
set_key(&rv[0][2]);
|
|
|
|
else {
|
|
|
|
rc--;
|
|
|
|
rv++;
|
|
|
|
if (rc == 0) {
|
|
|
|
fputs ("Need a key entry\n", stderr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
set_key(rv[0]);
|
|
|
|
}
|
2000-06-20 22:50:13 +00:00
|
|
|
} else if (strcasecmp(rv[0], "-v") == 0)
|
|
|
|
fputs ("Virtual Circuit mode not currently "
|
|
|
|
"implemented.\n", stderr);
|
|
|
|
else if (strcasecmp(rv[0], "-k") == 0)
|
|
|
|
fputs ("TSIG not currently implemented.",
|
|
|
|
stderr);
|
|
|
|
}
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
check_and_add_zone(dns_name_t *namein) {
|
2000-06-16 17:10:02 +00:00
|
|
|
|
|
|
|
ddebug ("check_and_add_zone()");
|
2000-06-20 22:50:13 +00:00
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
if (valid_zonename)
|
|
|
|
return;
|
|
|
|
dns_name_init(&zonename, NULL);
|
2000-06-17 00:16:50 +00:00
|
|
|
dns_name_dup(namein, mctx, &zonename);
|
2000-06-20 22:50:13 +00:00
|
|
|
current_zone = &zonename;
|
2000-06-10 00:50:36 +00:00
|
|
|
valid_zonename = ISC_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_uint16_t
|
|
|
|
make_rrset_prereq(dns_rdataclass_t rdclass) {
|
|
|
|
isc_result_t result;
|
|
|
|
char *nameptr, *typeptr;
|
|
|
|
dns_name_t *name = NULL;
|
|
|
|
isc_buffer_t *buf = NULL;
|
|
|
|
isc_buffer_t source;
|
|
|
|
isc_textregion_t typeregion;
|
|
|
|
dns_rdataset_t *rdataset = NULL;
|
2000-06-19 22:09:46 +00:00
|
|
|
dns_rdatalist_t *rdatalist = NULL;
|
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-16 17:10:02 +00:00
|
|
|
ddebug ("make_rrset_prereq()");
|
2000-06-10 00:50:36 +00:00
|
|
|
nameptr = strtok(NULL, " \t\r\n");
|
|
|
|
if (nameptr == NULL) {
|
|
|
|
puts ("failed to read owner name");
|
2000-06-17 00:16:50 +00:00
|
|
|
return STATUS_SYNTAX;
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typeptr = strtok(NULL, " \t\r\n");
|
|
|
|
if (typeptr == NULL) {
|
|
|
|
puts ("failed to read owner type");
|
2000-06-17 00:16:50 +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, &buf, NAMEBUF);
|
|
|
|
check_result(result, "isc_buffer_allocate");
|
|
|
|
dns_name_init(name, NULL);
|
|
|
|
dns_name_setbuffer(name, buf);
|
2000-06-17 00:16:50 +00:00
|
|
|
dns_message_takebuffer(updatemsg, &buf);
|
2000-06-10 00:50:36 +00:00
|
|
|
isc_buffer_init(&source, nameptr, strlen(nameptr));
|
|
|
|
isc_buffer_add(&source, strlen(nameptr));
|
2000-06-20 22:50:13 +00:00
|
|
|
if (count_dots(nameptr) > ndots)
|
|
|
|
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");
|
|
|
|
|
|
|
|
check_and_add_zone(name);
|
|
|
|
|
|
|
|
typeregion.base = typeptr;
|
|
|
|
typeregion.length = strlen(typeptr);
|
|
|
|
result = dns_rdatatype_fromtext(&rdatatype, &typeregion);
|
|
|
|
check_result (result, "dns_rdatatype_fromtext");
|
|
|
|
|
2000-06-19 22:09:46 +00:00
|
|
|
result = dns_message_gettemprdatalist(updatemsg, &rdatalist);
|
|
|
|
check_result(result, "dns_message_gettemprdatalist");
|
2000-06-16 17:10:02 +00:00
|
|
|
result = dns_message_gettemprdataset(updatemsg, &rdataset);
|
2000-06-19 22:09:46 +00:00
|
|
|
check_result(result, "dns_message_gettemprdataset");
|
|
|
|
dns_rdatalist_init(rdatalist);
|
|
|
|
rdatalist->type = rdatatype;
|
|
|
|
rdatalist->rdclass = rdclass;
|
|
|
|
rdatalist->covers = 0;
|
|
|
|
rdatalist->ttl = 0;
|
|
|
|
result = dns_message_gettemprdata(updatemsg, &rdata);
|
|
|
|
check_result(result, "dns_message_gettemprdata");
|
|
|
|
rdata->data = NULL;
|
|
|
|
rdata->length = 0;
|
|
|
|
rdata->rdclass = rdclass;
|
|
|
|
rdata->type = rdatatype;
|
|
|
|
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);
|
|
|
|
return STATUS_MORE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static isc_uint16_t
|
|
|
|
make_domain_prereq(dns_rdataclass_t rdclass) {
|
|
|
|
isc_result_t result;
|
|
|
|
char *ptr;
|
2000-06-20 22:50:13 +00:00
|
|
|
dns_name_t *name = NULL;
|
|
|
|
isc_buffer_t *buf = NULL;
|
2000-06-10 00:50:36 +00:00
|
|
|
isc_buffer_t source;
|
2000-06-16 17:10:02 +00:00
|
|
|
dns_rdataset_t *rdataset = NULL;
|
2000-06-19 22:09:46 +00:00
|
|
|
dns_rdatalist_t *rdatalist = NULL;
|
|
|
|
dns_rdata_t *rdata = NULL;
|
2000-06-20 22:50:13 +00:00
|
|
|
dns_name_t *rn = current_zone;
|
2000-06-19 22:09:46 +00:00
|
|
|
|
2000-06-16 17:10:02 +00:00
|
|
|
ddebug ("make_domain_prereq()");
|
2000-06-10 00:50:36 +00:00
|
|
|
ptr = strtok(NULL, " \t\r\n");
|
|
|
|
if (ptr == NULL) {
|
|
|
|
puts ("failed to read owner name");
|
2000-06-17 00:16:50 +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, &buf, NAMEBUF);
|
|
|
|
check_result(result, "isc_buffer_allocate");
|
|
|
|
dns_name_init(name, NULL);
|
|
|
|
dns_name_setbuffer(name, buf);
|
2000-06-17 00:16:50 +00:00
|
|
|
dns_message_takebuffer(updatemsg, &buf);
|
2000-06-10 00:50:36 +00:00
|
|
|
isc_buffer_init(&source, ptr, strlen(ptr));
|
|
|
|
isc_buffer_add(&source, strlen(ptr));
|
2000-06-20 22:50:13 +00:00
|
|
|
if (count_dots(ptr) > ndots)
|
|
|
|
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");
|
|
|
|
|
|
|
|
check_and_add_zone(name);
|
|
|
|
|
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);
|
|
|
|
rdatalist->type = dns_rdatatype_any;
|
|
|
|
rdatalist->rdclass = rdclass;
|
|
|
|
rdatalist->covers = 0;
|
|
|
|
rdatalist->ttl = 0;
|
|
|
|
result = dns_message_gettemprdata(updatemsg, &rdata);
|
|
|
|
check_result(result, "dns_message_gettemprdata");
|
|
|
|
rdata->data = NULL;
|
|
|
|
rdata->length = 0;
|
|
|
|
rdata->rdclass = rdclass;
|
|
|
|
rdata->type = dns_rdatatype_any;
|
|
|
|
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);
|
|
|
|
return STATUS_MORE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_uint16_t
|
|
|
|
evaluate_prereq() {
|
|
|
|
char *ptr;
|
|
|
|
|
2000-06-16 17:10:02 +00:00
|
|
|
ddebug ("evaluate_prereq()");
|
2000-06-10 00:50:36 +00:00
|
|
|
ptr = strtok(NULL, " \t\r\n");
|
|
|
|
if (ptr == NULL) {
|
|
|
|
puts ("failed to read operation code");
|
2000-06-17 00:16:50 +00:00
|
|
|
return STATUS_SYNTAX;
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
if (strcasecmp(ptr,"nxdomain") == 0)
|
|
|
|
return(make_domain_prereq(dns_rdataclass_none));
|
|
|
|
if (strcasecmp(ptr,"yxdomain") == 0)
|
|
|
|
return(make_domain_prereq(dns_rdataclass_any));
|
|
|
|
if (strcasecmp(ptr,"nxrrset") == 0)
|
|
|
|
return(make_rrset_prereq(dns_rdataclass_none));
|
|
|
|
if (strcasecmp(ptr,"yxrrset") == 0)
|
|
|
|
return(make_rrset_prereq(dns_rdataclass_any));
|
|
|
|
printf ("incorrect operation code: %s\n",ptr);
|
2000-06-17 00:16:50 +00:00
|
|
|
return(STATUS_SYNTAX);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static isc_uint16_t
|
|
|
|
evaluate_server() {
|
|
|
|
char *ptr;
|
|
|
|
|
2000-06-16 17:10:02 +00:00
|
|
|
ddebug ("evaluate_server()");
|
2000-06-10 00:50:36 +00:00
|
|
|
ptr = strtok(NULL, " \t\r\n");
|
|
|
|
if (ptr == NULL) {
|
|
|
|
puts ("failed to read server name");
|
2000-06-17 00:16:50 +00:00
|
|
|
return STATUS_SYNTAX;
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
strncpy(server, ptr, MXNAME);
|
|
|
|
return STATUS_MORE;
|
|
|
|
}
|
|
|
|
|
2000-06-20 22:50:13 +00:00
|
|
|
static isc_uint16_t
|
|
|
|
evaluate_zone() {
|
|
|
|
char *ptr;
|
|
|
|
dns_name_t name;
|
|
|
|
isc_buffer_t source, *buf = NULL;
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
ddebug ("evaluate_zone()");
|
|
|
|
ptr = strtok(NULL, " \t\r\n");
|
|
|
|
if (ptr == NULL) {
|
|
|
|
puts ("failed to read zone name");
|
|
|
|
return STATUS_SYNTAX;
|
|
|
|
}
|
|
|
|
strncpy(userzone, ptr, MXNAME);
|
|
|
|
|
|
|
|
result = isc_buffer_allocate(mctx, &buf, NAMEBUF);
|
|
|
|
check_result(result, "isc_buffer_allocate");
|
|
|
|
dns_name_init(&name, NULL);
|
|
|
|
dns_name_setbuffer(&name, buf);
|
|
|
|
isc_buffer_init(&source, ptr, strlen(ptr));
|
|
|
|
isc_buffer_add(&source, strlen(ptr));
|
|
|
|
result = dns_name_fromtext(&name, &source, dns_rootname,
|
|
|
|
ISC_FALSE, NULL);
|
|
|
|
check_result(result, "dns_name_fromtext");
|
|
|
|
|
|
|
|
check_and_add_zone(&name);
|
|
|
|
|
|
|
|
isc_buffer_free(&buf);
|
|
|
|
|
|
|
|
return STATUS_MORE;
|
|
|
|
}
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
static isc_uint16_t
|
|
|
|
update_add() {
|
|
|
|
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;
|
|
|
|
char *ptr, *type, *data;
|
|
|
|
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-10 00:50:36 +00:00
|
|
|
|
2000-06-16 17:10:02 +00:00
|
|
|
ddebug ("update_add()");
|
2000-06-10 00:50:36 +00:00
|
|
|
ptr = strtok(NULL, " \t\r\n");
|
|
|
|
if (ptr == NULL) {
|
|
|
|
puts ("failed to read owner name");
|
2000-06-17 00:16:50 +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-10 00:50:36 +00:00
|
|
|
isc_buffer_init(&source, ptr, strlen(ptr));
|
|
|
|
isc_buffer_add(&source, strlen(ptr));
|
2000-06-20 22:50:13 +00:00
|
|
|
if (count_dots(ptr) > ndots)
|
|
|
|
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");
|
|
|
|
|
|
|
|
check_and_add_zone(name);
|
|
|
|
|
|
|
|
ptr = strtok(NULL, " \t\r\n");
|
|
|
|
if (ptr == NULL) {
|
|
|
|
puts ("failed to read owner ttl");
|
2000-06-16 17:10:02 +00:00
|
|
|
dns_message_puttempname(updatemsg, &name);
|
2000-06-17 00:16:50 +00:00
|
|
|
return STATUS_SYNTAX;
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
ttl = atoi(ptr);
|
|
|
|
|
|
|
|
type = strtok(NULL, " \t\r\n");
|
|
|
|
if (type == NULL) {
|
|
|
|
puts ("failed to read owner type");
|
2000-06-16 17:10:02 +00:00
|
|
|
dns_message_puttempname(updatemsg, &name);
|
2000-06-17 00:16:50 +00:00
|
|
|
return STATUS_SYNTAX;
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
data = strtok(NULL, " \t\r\n");
|
|
|
|
if (data == NULL) {
|
|
|
|
puts ("failed to read owner data");
|
2000-06-16 17:10:02 +00:00
|
|
|
dns_message_puttempname(updatemsg, &name);
|
2000-06-17 00:16:50 +00:00
|
|
|
return STATUS_SYNTAX;
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
result = isc_lex_create(mctx, NAMEHINT, &lex);
|
|
|
|
check_result(result, "isc_lex_create");
|
|
|
|
region.base = type;
|
|
|
|
region.length = strlen(type);
|
|
|
|
result = dns_rdatatype_fromtext(&rdatatype, ®ion);
|
|
|
|
check_result(result, "dns_rdatatype_fromtext");
|
|
|
|
isc_buffer_invalidate(&source);
|
|
|
|
|
|
|
|
isc_buffer_init(&source, data, strlen(data));
|
|
|
|
isc_buffer_add(&source, strlen(data));
|
|
|
|
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");
|
|
|
|
result = dns_message_gettemprdata(updatemsg, &rdata);
|
|
|
|
check_result(result, "dns_message_gettemprdata");
|
|
|
|
dns_rdatacallbacks_init_stdio(&callbacks);
|
|
|
|
result = dns_rdata_fromtext(rdata, dns_rdataclass_in, rdatatype,
|
2000-06-20 22:50:13 +00:00
|
|
|
lex, current_zone, ISC_FALSE, buf,
|
2000-06-10 00:50:36 +00:00
|
|
|
&callbacks);
|
|
|
|
check_result(result, "dns_rdata_fromtext");
|
2000-06-17 00:16:50 +00:00
|
|
|
isc_lex_destroy(&lex);
|
2000-06-10 00:50:36 +00:00
|
|
|
|
|
|
|
check_and_add_zone(name);
|
|
|
|
|
|
|
|
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;
|
|
|
|
rdatalist->rdclass = dns_rdataclass_in;
|
|
|
|
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-19 22:09:46 +00:00
|
|
|
dns_message_takebuffer(updatemsg, &buf);
|
2000-06-10 00:50:36 +00:00
|
|
|
return STATUS_MORE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXXMWS add and delete share so much code, they should be collapsed. */
|
|
|
|
static isc_uint16_t
|
|
|
|
update_delete() {
|
|
|
|
isc_result_t result;
|
|
|
|
isc_lex_t *lex = NULL;
|
2000-06-16 17:10:02 +00:00
|
|
|
isc_buffer_t *namebuf = NULL;
|
2000-06-10 00:50:36 +00:00
|
|
|
isc_buffer_t *buf = NULL;
|
|
|
|
isc_buffer_t source;
|
2000-06-16 17:10:02 +00:00
|
|
|
dns_name_t *name = NULL;
|
2000-06-10 00:50:36 +00:00
|
|
|
char *ptr, *typeptr, *dataptr = NULL;
|
|
|
|
dns_rdatatype_t rdatatype;
|
|
|
|
dns_rdatacallbacks_t callbacks;
|
|
|
|
dns_rdata_t *rdata = NULL;
|
|
|
|
dns_rdatalist_t *rdatalist = NULL;
|
|
|
|
dns_rdataset_t *rdataset = NULL;
|
|
|
|
isc_textregion_t typeregion;
|
2000-06-20 22:50:13 +00:00
|
|
|
dns_name_t *rn = current_zone;
|
2000-06-10 00:50:36 +00:00
|
|
|
|
2000-06-16 17:10:02 +00:00
|
|
|
ddebug ("update_delete()");
|
2000-06-10 00:50:36 +00:00
|
|
|
ptr = strtok(NULL, " \t\r\n");
|
|
|
|
if (ptr == NULL) {
|
|
|
|
puts ("failed to read owner name");
|
2000-06-17 00:16:50 +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");
|
2000-06-16 17:10:02 +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-16 17:10:02 +00:00
|
|
|
dns_name_setbuffer(name, namebuf);
|
2000-06-17 00:16:50 +00:00
|
|
|
dns_message_takebuffer(updatemsg, &namebuf);
|
2000-06-10 00:50:36 +00:00
|
|
|
isc_buffer_init(&source, ptr, strlen(ptr));
|
|
|
|
isc_buffer_add(&source, strlen(ptr));
|
2000-06-20 22:50:13 +00:00
|
|
|
if (count_dots(ptr) > ndots)
|
|
|
|
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");
|
|
|
|
|
|
|
|
check_and_add_zone(name);
|
|
|
|
|
|
|
|
typeptr = strtok(NULL, " \t\r\n");
|
|
|
|
if (typeptr != NULL) {
|
|
|
|
dataptr = strtok(NULL, " \t\r\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeptr != NULL) {
|
|
|
|
typeregion.base = typeptr;
|
|
|
|
typeregion.length = strlen(typeptr);
|
|
|
|
result = dns_rdatatype_fromtext(&rdatatype, &typeregion);
|
|
|
|
check_result(result, "dns_rdatatype_fromtext");
|
|
|
|
isc_buffer_invalidate(&source);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rdatatype = dns_rdatatype_any;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dataptr != NULL) {
|
2000-06-17 00:16:50 +00:00
|
|
|
result = isc_lex_create(mctx, NAMEHINT, &lex);
|
|
|
|
check_result(result, "isc_lex_create");
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
isc_buffer_init(&source, dataptr, strlen(dataptr));
|
|
|
|
isc_buffer_add(&source, strlen(dataptr));
|
|
|
|
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");
|
|
|
|
result = dns_message_gettemprdata(updatemsg, &rdata);
|
|
|
|
check_result(result, "dns_message_gettemprdata");
|
|
|
|
dns_rdatacallbacks_init_stdio(&callbacks);
|
|
|
|
result = dns_rdata_fromtext(rdata, dns_rdataclass_in,
|
2000-06-20 22:50:13 +00:00
|
|
|
rdatatype, lex, current_zone,
|
2000-06-10 00:50:36 +00:00
|
|
|
ISC_FALSE, buf, &callbacks);
|
|
|
|
check_result(result, "dns_rdata_fromtext");
|
2000-06-17 00:16:50 +00:00
|
|
|
isc_lex_destroy(&lex);
|
|
|
|
|
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;
|
|
|
|
rdatalist->rdclass = dns_rdataclass_none;
|
2000-06-16 17:10:02 +00:00
|
|
|
rdatalist->covers = 0;
|
2000-06-10 00:50:36 +00:00
|
|
|
rdatalist->ttl = 0;
|
|
|
|
ISC_LIST_INIT(rdatalist->rdata);
|
|
|
|
ISC_LIST_APPEND(rdatalist->rdata, rdata, link);
|
|
|
|
dns_rdataset_init(rdataset);
|
|
|
|
dns_rdatalist_tordataset(rdatalist, rdataset);
|
2000-06-17 00:16:50 +00:00
|
|
|
isc_buffer_free(&buf);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
else {
|
2000-06-16 17:10:02 +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-16 18:54:33 +00:00
|
|
|
rdatalist->rdclass = dns_rdataclass_any;
|
2000-06-16 17:10:02 +00:00
|
|
|
rdatalist->covers = 0;
|
|
|
|
rdatalist->ttl = 0;
|
2000-06-16 18:54:33 +00:00
|
|
|
result = dns_message_gettemprdata(updatemsg, &rdata);
|
|
|
|
check_result(result, "dns_message_gettemprdata");
|
|
|
|
rdata->data = NULL;
|
|
|
|
rdata->length = 0;
|
|
|
|
rdata->rdclass = dns_rdataclass_any;
|
|
|
|
rdata->type = rdatatype;
|
2000-06-16 17:10:02 +00:00
|
|
|
ISC_LIST_INIT(rdatalist->rdata);
|
2000-06-16 18:54:33 +00:00
|
|
|
ISC_LIST_APPEND(rdatalist->rdata, rdata, link);
|
2000-06-16 17:10:02 +00:00
|
|
|
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_UPDATE);
|
|
|
|
return STATUS_MORE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static isc_uint16_t
|
|
|
|
evaluate_update() {
|
|
|
|
char *ptr;
|
|
|
|
|
2000-06-16 17:10:02 +00:00
|
|
|
ddebug ("evaluate_update()");
|
2000-06-10 00:50:36 +00:00
|
|
|
ptr = strtok(NULL, " \t\r\n");
|
|
|
|
if (ptr == NULL) {
|
|
|
|
puts ("failed to read operation code");
|
2000-06-17 00:16:50 +00:00
|
|
|
return STATUS_SYNTAX;
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
if (strcasecmp(ptr,"delete") == 0)
|
|
|
|
return(update_delete());
|
|
|
|
if (strcasecmp(ptr,"add") == 0)
|
|
|
|
return(update_add());
|
|
|
|
printf ("incorrect operation code: %s\n",ptr);
|
2000-06-17 00:16:50 +00:00
|
|
|
return(STATUS_SYNTAX);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
show_message() {
|
|
|
|
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);
|
|
|
|
check_result(result, "dns_message_totext");
|
2000-06-16 17:10:02 +00:00
|
|
|
printf ("Outgoing update query:\n%.*s",
|
|
|
|
(int)isc_buffer_usedlength(&buf),
|
2000-06-10 00:50:36 +00:00
|
|
|
(char*)isc_buffer_base(&buf));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static isc_uint16_t
|
|
|
|
get_next_command() {
|
|
|
|
char cmdline[MAXCMD];
|
|
|
|
char *ptr;
|
|
|
|
|
2000-06-16 17:10:02 +00:00
|
|
|
ddebug ("get_next_command()");
|
2000-06-10 00:50:36 +00:00
|
|
|
fputs ("> ", stderr);
|
|
|
|
fgets (cmdline, MAXCMD, stdin);
|
|
|
|
ptr = strtok(cmdline, " \t\r\n");
|
2000-06-20 22:50:13 +00:00
|
|
|
|
|
|
|
if (feof(stdin))
|
|
|
|
return(STATUS_QUIT);
|
|
|
|
if (ptr == NULL)
|
|
|
|
return(STATUS_SEND);
|
2000-06-10 00:50:36 +00:00
|
|
|
if (strcasecmp(ptr,"quit") == 0)
|
|
|
|
return(STATUS_QUIT);
|
|
|
|
if (strcasecmp(ptr,"prereq") == 0)
|
|
|
|
return(evaluate_prereq());
|
|
|
|
if (strcasecmp(ptr,"update") == 0)
|
|
|
|
return(evaluate_update());
|
|
|
|
if (strcasecmp(ptr,"server") == 0)
|
|
|
|
return(evaluate_server());
|
2000-06-20 22:50:13 +00:00
|
|
|
if (strcasecmp(ptr,"zone") == 0)
|
|
|
|
return(evaluate_zone());
|
2000-06-10 00:50:36 +00:00
|
|
|
if (strcasecmp(ptr,"send") == 0)
|
|
|
|
return(STATUS_SEND);
|
|
|
|
if (strcasecmp(ptr,"show") == 0) {
|
|
|
|
show_message();
|
|
|
|
return(STATUS_MORE);
|
|
|
|
}
|
|
|
|
printf ("incorrect section name: %s\n",ptr);
|
2000-06-17 00:16:50 +00:00
|
|
|
return(STATUS_SYNTAX);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static isc_boolean_t
|
|
|
|
user_interaction() {
|
|
|
|
isc_uint16_t result = STATUS_MORE;
|
|
|
|
|
2000-06-16 17:10:02 +00:00
|
|
|
ddebug ("user_interaction()");
|
2000-06-17 00:16:50 +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)
|
|
|
|
return ISC_TRUE;
|
|
|
|
if (result == STATUS_FAIL)
|
|
|
|
exitcode = 1;
|
|
|
|
return ISC_FALSE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
printf ("; Communication with server failed: %d-%s\n",
|
|
|
|
reqev->result, isc_result_totext(reqev->result));
|
|
|
|
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);
|
|
|
|
isc_mutex_lock(&lock);
|
|
|
|
busy = ISC_FALSE;
|
|
|
|
isc_condition_signal(&cond);
|
|
|
|
isc_mutex_unlock(&lock);
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
send_update() {
|
|
|
|
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");
|
|
|
|
dns_name_init(name, NULL);
|
2000-06-17 00:16:50 +00:00
|
|
|
dns_name_clone(&actualzone, 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);
|
|
|
|
result = dns_name_totext(&master, ISC_TRUE, &buf);
|
|
|
|
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;
|
|
|
|
isc_sockaddr_t sockaddr;
|
|
|
|
dns_request_t *request = NULL;
|
|
|
|
isc_result_t result;
|
|
|
|
dns_message_t *rcvmsg = NULL;
|
|
|
|
dns_section_t section;
|
|
|
|
dns_name_t *name = NULL;
|
|
|
|
dns_rdataset_t *rdataset = NULL;
|
|
|
|
dns_rdata_soa_t soa;
|
|
|
|
dns_rdata_t rdata;
|
2000-06-16 17:10:02 +00:00
|
|
|
isc_buffer_t buf;
|
|
|
|
char bufstore[MSGTEXT];
|
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;
|
|
|
|
if (reqev->result != ISC_R_SUCCESS) {
|
2000-06-16 17:10:02 +00:00
|
|
|
printf ("; Communication with %s failed: %d-%s\n",
|
|
|
|
nameservername[ns_inuse], reqev->result,
|
|
|
|
isc_result_totext(reqev->result));
|
2000-06-10 00:50:36 +00:00
|
|
|
ns_inuse++;
|
|
|
|
if (ns_inuse >= nameservers) {
|
|
|
|
fatal ("Couldn't talk to any default nameserver.");
|
|
|
|
}
|
|
|
|
get_address(nameservername[ns_inuse], 53, &sockaddr);
|
2000-06-16 17:10:02 +00:00
|
|
|
ddebug("Destroying %lx[%lx]", &reqev->request,
|
|
|
|
reqev->request);
|
2000-06-10 00:50:36 +00:00
|
|
|
dns_request_destroy(&reqev->request);
|
|
|
|
isc_event_free(&event);
|
|
|
|
result = dns_request_create(requestmgr, findmsg, &sockaddr,
|
2000-06-16 17:10:02 +00:00
|
|
|
0, NULL,
|
2000-06-10 00:50:36 +00:00
|
|
|
FIND_TIMEOUT, global_task,
|
|
|
|
find_completed, NULL, &request);
|
|
|
|
check_result(result, "dns_result_create");
|
|
|
|
return;
|
|
|
|
}
|
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");
|
|
|
|
result = dns_request_getresponse(reqev->request, rcvmsg, ISC_TRUE);
|
|
|
|
check_result(result, "dns_request_getresponse");
|
|
|
|
section = DNS_SECTION_ANSWER;
|
2000-06-16 17:10:02 +00:00
|
|
|
if (debugging) {
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXXMWS Really shouldn't use firstname here */
|
|
|
|
section = DNS_SECTION_ANSWER;
|
|
|
|
result = dns_message_firstname(rcvmsg, section);
|
2000-06-10 00:50:36 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
section = DNS_SECTION_AUTHORITY;
|
2000-06-16 17:10:02 +00:00
|
|
|
result = dns_message_firstname(rcvmsg, section);
|
|
|
|
check_result(result, "dns_message_firstname");
|
2000-06-10 00:50:36 +00:00
|
|
|
}
|
2000-06-16 17:10:02 +00:00
|
|
|
dns_message_currentname(rcvmsg, section, &name);
|
2000-06-10 00:50:36 +00:00
|
|
|
dns_name_init(&actualzone, NULL);
|
|
|
|
result = dns_name_dup(name, mctx, &actualzone);
|
|
|
|
|
2000-06-16 18:54:33 +00:00
|
|
|
/* Name is just a reference, so this is safe. */
|
2000-06-16 17:10:02 +00:00
|
|
|
name = NULL;
|
|
|
|
|
|
|
|
if (debugging) {
|
|
|
|
isc_buffer_clear(&buf);
|
|
|
|
result = dns_name_totext(&actualzone, ISC_FALSE, &buf);
|
|
|
|
check_result(result, "dns_name_totext");
|
|
|
|
printf ("Found zone name: %.*s\n",
|
|
|
|
(int)isc_buffer_usedlength(&buf),
|
|
|
|
(char*)isc_buffer_base(&buf));
|
|
|
|
}
|
|
|
|
|
2000-06-17 00:16:50 +00:00
|
|
|
ddebug("Finding name");
|
2000-06-16 17:10:02 +00:00
|
|
|
result = dns_message_findname(rcvmsg, section, &actualzone,
|
|
|
|
dns_rdatatype_soa, 0,
|
|
|
|
&name, &rdataset);
|
|
|
|
check_result(result, "Couldn't find SOA in reply");
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
result = dns_rdataset_first(rdataset);
|
|
|
|
check_result(result, "dns_rdataset_first");
|
|
|
|
dns_rdataset_current(rdataset, &rdata);
|
2000-06-17 00:16:50 +00:00
|
|
|
ddebug("tostruct");
|
2000-06-10 00:50:36 +00:00
|
|
|
result = dns_rdata_tostruct(&rdata, &soa, mctx);
|
|
|
|
check_result(result, "dns_rdata_tostruct");
|
|
|
|
dns_name_init(&master, NULL);
|
2000-06-17 00:16:50 +00:00
|
|
|
ddebug("Duping master");
|
2000-06-10 00:50:36 +00:00
|
|
|
result = dns_name_dup(&soa.origin, mctx, &master);
|
|
|
|
check_result(result, "dns_name_dup");
|
|
|
|
|
2000-06-16 17:10:02 +00:00
|
|
|
if (debugging) {
|
|
|
|
isc_buffer_clear(&buf);
|
|
|
|
result = dns_name_totext(&master, ISC_FALSE, &buf);
|
|
|
|
check_result(result, "dns_name_totext");
|
|
|
|
printf ("The master is: %.*s\n",
|
|
|
|
(int)isc_buffer_usedlength(&buf),
|
|
|
|
(char*)isc_buffer_base(&buf));
|
|
|
|
}
|
|
|
|
|
2000-06-17 00:16:50 +00:00
|
|
|
dns_rdata_freestruct(&soa);
|
2000-06-16 17:10:02 +00:00
|
|
|
dns_message_destroy(&rcvmsg);
|
2000-06-10 00:50:36 +00:00
|
|
|
dns_request_destroy(&reqev->request);
|
|
|
|
isc_event_free(&event);
|
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
|
|
|
|
start_update() {
|
|
|
|
isc_result_t result;
|
|
|
|
dns_rdataset_t *rdataset = NULL;
|
|
|
|
dns_name_t *name = NULL;
|
|
|
|
isc_sockaddr_t sockaddr;
|
|
|
|
dns_request_t *request = NULL;
|
|
|
|
|
2000-06-16 17:10:02 +00:00
|
|
|
ddebug ("start_update()");
|
2000-06-10 00:50:36 +00:00
|
|
|
result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER,
|
|
|
|
&findmsg);
|
|
|
|
check_result(result, "dns_message_create");
|
|
|
|
|
2000-06-16 17:10:02 +00:00
|
|
|
findmsg->flags |= DNS_MESSAGEFLAG_RD;
|
|
|
|
|
2000-06-10 00:50:36 +00:00
|
|
|
result = dns_message_gettempname(findmsg, &name);
|
|
|
|
check_result(result, "dns_message_gettempname");
|
|
|
|
|
|
|
|
result = dns_message_gettemprdataset(findmsg, &rdataset);
|
|
|
|
check_result(result, "dns_message_gettemprdataset");
|
|
|
|
|
|
|
|
dns_rdataset_makequestion(rdataset, dns_rdataclass_in,
|
|
|
|
dns_rdatatype_soa);
|
|
|
|
|
|
|
|
dns_name_init(name, NULL);
|
2000-06-16 17:10:02 +00:00
|
|
|
if (!valid_zonename) {
|
|
|
|
fatal ("don't have a valid zone yet.");
|
|
|
|
}
|
2000-06-17 00:16:50 +00:00
|
|
|
dns_name_clone(&zonename, name);
|
2000-06-10 00:50:36 +00:00
|
|
|
|
|
|
|
ISC_LIST_INIT(name->list);
|
|
|
|
ISC_LIST_APPEND(name->list, rdataset, link);
|
|
|
|
dns_message_addname(findmsg, name, DNS_SECTION_QUESTION);
|
|
|
|
|
|
|
|
ns_inuse = 0;
|
|
|
|
get_address(nameservername[0], 53, &sockaddr);
|
|
|
|
result = dns_request_create(requestmgr, findmsg, &sockaddr,
|
2000-06-16 17:10:02 +00:00
|
|
|
0, NULL,
|
2000-06-10 00:50:36 +00:00
|
|
|
FIND_TIMEOUT, global_task,
|
|
|
|
find_completed, NULL, &request);
|
|
|
|
check_result(result, "dns_request_create");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_lists() {
|
2000-06-16 17:10:02 +00:00
|
|
|
ddebug ("free_lists()");
|
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 (keynamebuf != NULL) {
|
|
|
|
ddebug("Freeing keynamebuf");
|
|
|
|
isc_buffer_free(&keynamebuf);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
if (findmsg != NULL)
|
|
|
|
dns_message_destroy(&findmsg);
|
|
|
|
|
|
|
|
if (VALID_NAME(&actualzone)) {
|
|
|
|
ddebug("Freeing actualzone");
|
|
|
|
dns_name_free(&actualzone, mctx);
|
|
|
|
}
|
|
|
|
if (VALID_NAME(&zonename)) {
|
|
|
|
ddebug("Freeing zonename");
|
|
|
|
dns_name_free(&zonename, mctx);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
result = isc_mutex_trylock(&lock);
|
|
|
|
check_result(result, "isc_mutex_trylock");
|
|
|
|
|
|
|
|
while (ISC_TRUE) {
|
|
|
|
reset_system();
|
|
|
|
if (!user_interaction())
|
|
|
|
break;
|
|
|
|
busy = ISC_TRUE;
|
|
|
|
start_update();
|
|
|
|
while (busy) {
|
|
|
|
result = isc_condition_wait(&cond, &lock);
|
|
|
|
check_result(result, "isc_condition_wait");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-20 22:50:13 +00:00
|
|
|
free_lists(0);
|
2000-06-10 00:50:36 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|