/*
* Copyright (C) 2000-2002, 2004, 2005, 2007-2009, 2014, 2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* $Id: zonetodb.c,v 1.23 2009/09/02 23:48:01 tbox 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
*/
void
}
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
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);
}