zonetodb.c revision dafcb997e390efa4423883dafd100c975c4095d6
/*
* Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 2000, 2001 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 ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC 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: zonetodb.c,v 1.13 2004/03/05 05:04:33 marka Exp $ */
#include <stdlib.h>
#include <string.h>
#include <dns/dbiterator.h>
#include <dns/fixedname.h>
#include <dns/rdataset.h>
#include <dns/rdatasetiter.h>
#include <dns/rdatatype.h>
#include <pgsql/libpq-fe.h>
/*
* Generate a PostgreSQL table from a zone.
*
* This is compiled this with something like the following (assuming bind9 has
* been installed):
*
* gcc -g `isc-config.sh --cflags isc dns` -c zonetodb.c
* gcc -g -o zonetodb zonetodb.o `isc-config.sh --libs isc dns` -lpq
*/
char str[10240];
void
closeandexit(int status) {
}
void
if (result != ISC_R_SUCCESS) {
closeandexit(1);
}
}
/*
* Canonicalize a string before writing it to the database.
* "dest" must be an array of at least size 2*strlen(source) + 1.
*/
static void
while (*source != 0) {
if (*source == '\'')
*dest++ = '\'';
else if (*source == '\\')
*dest++ = '\\';
}
*dest++ = 0;
}
void
unsigned char typearray[20];
unsigned char canontypearray[40];
unsigned char dataarray[2048];
unsigned char canondataarray[4096];
isc_buffer_t b;
namearray[isc_buffer_usedlength(&b)] = 0;
typearray[isc_buffer_usedlength(&b)] = 0;
dataarray[isc_buffer_usedlength(&b)] = 0;
"INSERT INTO %s (NAME, TTL, RDTYPE, RDATA)"
" VALUES ('%s', %d, '%s', '%s')",
closeandexit(1);
}
}
int
isc_buffer_t b;
if (argc != 5) {
printf("Note that dbname must be an existing database.\n");
exit(1);
}
if (result == DNS_R_SEENINCLUDE)
closeandexit(1);
}
"DROP TABLE %s", dbtable);
closeandexit(1);
}
"CREATE TABLE %s "
"(NAME TEXT, TTL INTEGER, RDTYPE TEXT, RDATA TEXT)",
dbtable);
closeandexit(1);
}
while (result == ISC_R_SUCCESS) {
if (result == ISC_R_NOMORE)
break;
while (result == ISC_R_SUCCESS) {
while (result == ISC_R_SUCCESS) {
}
}
}
closeandexit(1);
}
dns_db_detach(&db);
closeandexit(0);
exit(0);
}