nsupdate.c revision a04a6cbacaac97b9ca51326ff470588e316464e7
/*
* 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.
*/
/* $Id: nsupdate.c,v 1.11 2000/06/29 02:16:44 bwelling Exp $ */
#include <config.h>
#include <netdb.h>
#include <stdlib.h>
#include <unistd.h>
#include <dns/callbacks.h>
#include <dns/dispatch.h>
#include <dns/rdatalist.h>
#include <dns/rdataset.h>
#include <dns/rdatastruct.h>
#include <dns/rdatatype.h>
#include <isc/condition.h>
#include <isc/sockaddr.h>
#define MXNAME 256
#define MAXCMD 256
#define NAMEBUF 512
#define NAMEHINT 64
#define PACKETSIZE 2048
#define MSGTEXT 4069
#define FIND_TIMEOUT 5
#define RESOLV_CONF "/etc/resolv.conf"
extern isc_boolean_t isc_mem_debugging;
char resolvstore[MXNAME];
int exitcode = 0;
int nameservers;
int ns_inuse = 0;
int ndots = 1;
#define STATUS_MORE 0
#define STATUS_SEND 1
#define STATUS_QUIT 2
#define STATUS_FAIL 3
#define STATUS_SYNTAX 4
static int
count_dots(char *string) {
char *s;
int i=0;
s = string;
while (*s != 0) {
if (*s == '.')
i++;
s++;
}
return (i);
}
static void
if (exitcode == 0)
exitcode = 8;
}
static void
if (debugging) {
}
}
static void
if (ddebugging) {
}
}
static void
if (result != ISC_R_SUCCESS) {
exitcode = 1;
}
}
static void
load_resolv_conf() {
char *ptr;
ddebug ("load_resolv_conf()");
ddebug ("Got a nameserver line");
if (nameservers < 3) {
[nameservers],
nameservers++;
}
}
6) == 0) {
ddebug ("ndots is "
"%d.",
ndots);
}
}
/* XXXMWS Searchlist not supported! */
(domain[0] == 0 )){
!= NULL) {
}
}
}
}
}
}
static void
reset_system() {
ddebug ("reset_system()");
/* If the update message is still around, destroy it */
&updatemsg);
if (VALID_NAME(&zonename))
if (VALID_NAME(&actualzone))
if (VALID_NAME(&master))
if (domain[0] != 0)
else
}
static void
setup_system(){
int secretsize;
unsigned char *secretstore;
ddebug("setup_system()");
/*
* Warning: This is not particularly good randomness. We'll
* just use random() now for getting id values, but doing so
* does NOT insure that id's can't be guessed.
*/
result = isc_app_start();
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)
&dispatchv4);
if (domain[0] != 0) {
}
else {
}
if (keysecret[0] != 0) {
debug("Creating key...");
if (result != ISC_R_SUCCESS) {
printf (";; Couldn't create key %s: %s\n",
goto SYSSETUP_FAIL;
}
debug("close");
debug("namefromtext");
if (result != ISC_R_SUCCESS) {
printf (";; Couldn't create key %s: %s\n",
goto SYSSETUP_FAIL;
}
debug("tsigkey");
if (result != ISC_R_SUCCESS) {
printf (";; Couldn't create key %s: %s\n",
}
return;
}
}
static void
char *nameptr;
char *secptr;
debug("set_key");
return;
}
return;
}
}
static void
int rc;
char **rv;
debug("parse_args");
debug ("Just turned on debugging");
debug ("In -y test");
if (rv[0][2] != 0)
else {
rc--;
rv++;
if (rc == 0) {
return;
}
}
fputs ("Virtual Circuit mode not currently "
"implemented.\n", stderr);
fputs ("TSIG not currently implemented.",
stderr);
}
}
static void
ddebug ("check_and_add_zone()");
if (valid_zonename)
return;
current_zone = &zonename;
}
static isc_uint16_t
ddebug ("make_rrset_prereq()");
puts ("failed to read owner name");
return STATUS_SYNTAX;
}
puts ("failed to read owner type");
return STATUS_SYNTAX;
}
rn = dns_rootname;
return STATUS_MORE;
}
static isc_uint16_t
char *ptr;
ddebug ("make_domain_prereq()");
puts ("failed to read owner name");
return STATUS_SYNTAX;
}
rn = dns_rootname;
return STATUS_MORE;
}
static isc_uint16_t
evaluate_prereq() {
char *ptr;
ddebug ("evaluate_prereq()");
puts ("failed to read operation code");
return STATUS_SYNTAX;
}
return(make_domain_prereq(dns_rdataclass_none));
return(make_domain_prereq(dns_rdataclass_any));
return(make_rrset_prereq(dns_rdataclass_none));
return(make_rrset_prereq(dns_rdataclass_any));
return(STATUS_SYNTAX);
}
static isc_uint16_t
evaluate_server() {
char *ptr;
ddebug ("evaluate_server()");
puts ("failed to read server name");
return STATUS_SYNTAX;
}
return STATUS_MORE;
}
static isc_uint16_t
evaluate_zone() {
char *ptr;
ddebug ("evaluate_zone()");
puts ("failed to read zone name");
return STATUS_SYNTAX;
}
return STATUS_MORE;
}
static isc_uint16_t
update_add() {
ddebug ("update_add()");
puts ("failed to read owner name");
return STATUS_SYNTAX;
}
rn = dns_rootname;
puts ("failed to read owner ttl");
return STATUS_SYNTAX;
}
puts ("failed to read owner type");
return STATUS_SYNTAX;
}
puts ("failed to read owner data");
return STATUS_SYNTAX;
}
&callbacks);
return STATUS_MORE;
}
/* XXXMWS add and delete share so much code, they should be collapsed. */
static isc_uint16_t
update_delete() {
ddebug ("update_delete()");
puts ("failed to read owner name");
return STATUS_SYNTAX;
}
rn = dns_rootname;
}
}
else {
}
}
else {
}
return STATUS_MORE;
}
static isc_uint16_t
evaluate_update() {
char *ptr;
ddebug ("evaluate_update()");
puts ("failed to read operation code");
return STATUS_SYNTAX;
}
return(update_delete());
return(update_add());
return(STATUS_SYNTAX);
}
static void
show_message() {
ddebug ("show_message()");
printf ("Outgoing update query:\n%.*s",
(int)isc_buffer_usedlength(&buf),
(char*)isc_buffer_base(&buf));
}
static isc_uint16_t
get_next_command() {
char *ptr;
ddebug ("get_next_command()");
return(STATUS_QUIT);
return(STATUS_SEND);
return(STATUS_QUIT);
return(evaluate_prereq());
return(evaluate_update());
return(evaluate_server());
return(evaluate_zone());
return(STATUS_SEND);
show_message();
return(STATUS_MORE);
}
return(STATUS_SYNTAX);
}
static isc_boolean_t
user_interaction() {
ddebug ("user_interaction()");
result = get_next_command();
}
if (result == STATUS_SEND)
return ISC_TRUE;
if (result == STATUS_FAIL)
exitcode = 1;
return ISC_FALSE;
}
static void
ddebug("get_address()");
else {
fatal("Couldn't look up your server host %s. errno=%d",
port);
}
}
static void
ddebug ("updated_completed()");
printf ("; Communication with server failed: %d-%s\n",
goto done;
}
if (debugging) {
printf ("\nReply from update query:\n%.*s\n",
(int)isc_buffer_usedlength(&buf),
(char*)isc_buffer_base(&buf));
}
done:
}
static void
send_update() {
char servername[MXNAME];
ddebug ("send_update()");
0, key,
}
static void
ddebug ("find_completed()");
printf ("; Communication with %s failed: %d-%s\n",
ns_inuse++;
if (ns_inuse >= nameservers) {
fatal ("Couldn't talk to any default nameserver.");
}
0, NULL,
return;
}
ddebug ("About to create rcvmsg");
if (debugging) {
printf ("Reply from SOA query:\n%.*s\n",
(int)isc_buffer_usedlength(&buf),
(char*)isc_buffer_base(&buf));
}
/* XXXMWS Really shouldn't use firstname here */
if (result != ISC_R_SUCCESS) {
}
/* Name is just a reference, so this is safe. */
if (debugging) {
printf ("Found zone name: %.*s\n",
(int)isc_buffer_usedlength(&buf),
(char*)isc_buffer_base(&buf));
}
ddebug("Finding name");
ddebug("tostruct");
ddebug("Duping master");
if (debugging) {
printf ("The master is: %.*s\n",
(int)isc_buffer_usedlength(&buf),
(char*)isc_buffer_base(&buf));
}
ddebug ("Out of find_completed");
send_update();
}
static void
start_update() {
ddebug ("start_update()");
&findmsg);
if (!valid_zonename) {
fatal ("don't have a valid zone yet.");
}
ns_inuse = 0;
0, NULL,
}
static void
free_lists() {
ddebug ("free_lists()");
ddebug("Freeing key");
}
if (keynamebuf != NULL) {
ddebug("Freeing keynamebuf");
}
}
if (VALID_NAME(&actualzone)) {
ddebug("Freeing actualzone");
}
if (VALID_NAME(&zonename)) {
ddebug("Freeing zonename");
}
if (is_dst_up) {
debug ("Destroy DST lib");
}
debug ("Detach from entropy");
}
ddebug("Shutting down request manager");
ddebug("Freeing the dispatcher");
ddebug("Shutting down dispatch manager");
ddebug("Ending task");
ddebug("Shutting down task manager");
ddebug("Shutting down socket manager");
ddebug("Shutting down timer manager");
ddebug("Destroying memory context");
if (isc_mem_debugging)
exit(0);
}
int
setup_system();
while (ISC_TRUE) {
reset_system();
if (!user_interaction())
break;
start_update();
while (busy) {
}
}
puts ("");
ddebug ("Fell through app_run");
free_lists(0);
return (0);
}