nsupdate.c revision 2ca0be2bb8d2ae726cebb6a45d8fd2eebd0c1033
/*
* 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.2 2000/06/16 17:10:02 mws Exp $ */
#include <config.h>
#include <stdlib.h>
#include <unistd.h>
#include <netdb.h>
#include <isc/condition.h>
#include <isc/sockaddr.h>
#include <dns/dispatch.h>
#include <dns/rdataset.h>
#include <dns/rdatalist.h>
#include <dns/rdatatype.h>
#include <dns/callbacks.h>
#include <dns/rdatastruct.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"
char domainname_store[NAMEBUF];
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
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))
}
static void
setup_system() {
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)
&sock);
&dispatchv4);
if (domain[0] != 0) {
}
else {
}
}
static void
parse_args() {
}
static void
ddebug ("check_and_add_zone()");
if (valid_zonename)
return;
}
static isc_uint16_t
ddebug ("make_rrset_prereq()");
puts ("failed to read owner name");
return STATUS_FAIL;
}
puts ("failed to read owner type");
return STATUS_FAIL;
}
return STATUS_MORE;
}
static isc_uint16_t
char *ptr;
ddebug ("make_domain_prereq()");
puts ("failed to read owner name");
return STATUS_FAIL;
}
return STATUS_MORE;
}
static isc_uint16_t
evaluate_prereq() {
char *ptr;
ddebug ("evaluate_prereq()");
puts ("failed to read operation code");
return STATUS_FAIL;
}
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_FAIL);
}
static isc_uint16_t
evaluate_server() {
char *ptr;
ddebug ("evaluate_server()");
puts ("failed to read server name");
return STATUS_FAIL;
}
return STATUS_MORE;
}
static isc_uint16_t
update_add() {
ddebug ("update_add()");
puts ("failed to read owner name");
return STATUS_FAIL;
}
puts ("failed to read owner ttl");
return STATUS_FAIL;
}
puts ("failed to read owner type");
return STATUS_FAIL;
}
puts ("failed to read owner data");
return STATUS_FAIL;
}
&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_FAIL;
}
}
}
else {
}
}
else {
#if 0
#endif
}
return STATUS_MORE;
}
static isc_uint16_t
evaluate_update() {
char *ptr;
ddebug ("evaluate_update()");
puts ("failed to read operation code");
return STATUS_FAIL;
}
return(update_delete());
return(update_add());
return(STATUS_FAIL);
}
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_SEND);
else
return(STATUS_QUIT);
}
return(STATUS_QUIT);
return(evaluate_prereq());
return(evaluate_update());
return(evaluate_server());
return(STATUS_SEND);
show_message();
return(STATUS_MORE);
}
return(STATUS_FAIL);
}
static isc_boolean_t
user_interaction() {
ddebug ("user_interaction()");
while (result == STATUS_MORE) {
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 (debug) {
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, NULL,
}
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.");
}
#if 0
#endif
0, NULL,
return;
}
if (debugging) {
(char*)isc_buffer_base(&buf));
}
/* XXXMWS Really shouldn't use firstname here */
if (result != ISC_R_SUCCESS) {
}
/* XXXMWS This can't be right. */
if (debugging) {
printf ("Found zone name: %.*s\n",
(int)isc_buffer_usedlength(&buf),
(char*)isc_buffer_base(&buf));
}
if (debugging) {
printf ("The master is: %.*s\n",
(int)isc_buffer_usedlength(&buf),
(char*)isc_buffer_base(&buf));
}
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()");
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);
}