Commit 6be12fa6 authored by Evan Hunt's avatar Evan Hunt

[master] contrib: sqlite3 DLZ module

3772.	[contrib]	Added sqlite3 dynamically-loadable DLZ module.
			(Based in part on a contribution from Tim Tessier.)
			[RT #20822]
parent 8da6361b
3772. [contrib] Added sqlite3 dynamically-loadable DLZ module.
(Based in part on a contribution from Tim Tessier.)
[RT #20822]
3771. [cleanup] Adjusted log level for "using built-in key"
messages. [RT #24383]
......
......@@ -291,13 +291,11 @@ build_querystring(query_list_t *querylist) {
tseg = DLZ_LIST_NEXT(tseg, link);
}
/* allocate memory for the string */
qs = malloc(length + 1);
/* couldn't allocate memory, We need more ram! */
if (qs == NULL)
return (NULL);
*qs = 0;
*qs = '\0';
/* start at the top of the list again */
tseg = DLZ_LIST_HEAD(*querylist);
while (tseg != NULL) {
......
prefix = /usr
libdir = $(prefix)/lib/bind9
CFLAGS=-fPIC -g -I../include
SQLITE3_LIBS=-lsqlite3
all: dlz_sqlite3_dynamic.so
dlz_dbi.o: ../common/dlz_dbi.c
$(CC) $(CFLAGS) -c ../common/dlz_dbi.c
dlz_sqlite3_dynamic.so: dlz_sqlite3_dynamic.c dlz_dbi.o
$(CC) $(CFLAGS) -shared -o dlz_sqlite3_dynamic.so \
dlz_sqlite3_dynamic.c dlz_dbi.o $(SQLITE3_LIBS)
clean:
rm -f dlz_sqlite3_dynamic.so *.o
install: dlz_sqlite3_dynamic.so
mkdir -p $(DESTDIR)$(libdir)
install dlz_sqlite3_dynamic.so $(DESTDIR)$(libdir)
This diff is collapsed.
These files were used for testing on Ubuntu Linux using SQLite3
- Install SQLite3: sudo apt-get install sqlite3 libsqlite3-dev
- Build sqlite3 DLZ module
- Run "sqlite3 BindDB < dlz.schema" to set up database
- Run "mysql BindDB < dlz.data" to populate it
- Run "named -gc named.conf"
- Send test queries, e.g "dig @localhost -p 5300 example.com",
"dig @localhost -p 5300 axfr example.com" (AXFR should be
allowed from 127.0.0.1 only).
INSERT INTO `records`
(`zone`, `ttl`, `type`, `host`, `mx_priority`, `data`, `primary_ns`, `resp_contact`, `serial`, `refresh`, `retry`, `expire`, `minimum`)
VALUES
('example.com', 86400, 'SOA', '@', NULL, NULL, 'ns1.example.com.', 'info.example.com.', 2011043001, 10800, 7200, 604800, 86400),
('example.com', 86400, 'NS', '@', NULL, 'ns1.example.com.', NULL, NULL, NULL, NULL, NULL, NULL, NULL),
('example.com', 86400, 'NS', '@', NULL, 'ns2.example.com.', NULL, NULL, NULL, NULL, NULL, NULL, NULL),
('example.com', 86400, 'MX', '@', 10, 'mail.example.com.', NULL, NULL, NULL, NULL, NULL, NULL, NULL),
('example.com', 86400, 'A', '@', NULL, '192.168.0.2', NULL, NULL, NULL, NULL, NULL, NULL, NULL),
('example.com', 86400, 'CNAME', 'www', NULL, '@', NULL, NULL, NULL, NULL, NULL, NULL, NULL),
('example.com', 86400, 'A', 'ns1', NULL, '192.168.0.111', NULL, NULL, NULL, NULL, NULL, NULL, NULL),
('example.com', 86400, 'A', 'ns2', NULL, '192.168.0.222', NULL, NULL, NULL, NULL, NULL, NULL, NULL),
('example.com', 86400, 'A', 'mail', NULL, '192.168.0.3', NULL, NULL, NULL, NULL, NULL, NULL, NULL),
('example.com', 86400, 'TXT', '@', NULL, 'v=spf1 ip:192.168.0.3 ~all', NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `xfr`
(`zone`, `client`)
VALUES
('example.com', '127.0.0.1');
CREATE TABLE IF NOT EXISTS `records` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`zone` CHAR(255) NOT NULL,
`ttl` INT NOT NULL DEFAULT '86400',
`type` CHAR(255) NOT NULL,
`host` CHAR(255) NOT NULL DEFAULT '@',
`mx_priority` INT DEFAULT NULL,
`data` text,
`primary_ns` CHAR(255) DEFAULT NULL,
`resp_contact` CHAR(255) DEFAULT NULL,
`serial` bigint DEFAULT NULL,
`refresh` INT DEFAULT NULL,
`retry` INT DEFAULT NULL,
`expire` INT DEFAULT NULL,
`minimum` INT DEFAULT NULL
);
CREATE INDEX IF NOT EXISTS record_type on records (type);
CREATE INDEX IF NOT EXISTS record_host on records (host);
CREATE INDEX IF NOT EXISTS record_zone on records (zone);
CREATE TABLE IF NOT EXISTS `xfr` (
`zone` CHAR(255) NOT NULL,
`client` CHAR(255) NOT NULL
);
CREATE INDEX IF NOT EXISTS xfr_zone on xfr (zone);
CREATE INDEX IF NOT EXISTS xfr_client on xfr (client);
/*
* Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
*
* Permission to use, copy, modify, and/or 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.
*/
controls { };
options {
directory ".";
port 5300;
pid-file "named.pid";
session-keyfile "session.key";
listen-on { any; };
listen-on-v6 { none; };
recursion no;
};
key rndc_key {
secret "1234abcd8765";
algorithm hmac-md5;
};
controls {
inet 127.0.0.1 port 9953 allow { any; } keys { rndc_key; };
};
dlz "test" {
database "dlopen ../dlz_sqlite3_dynamic.so
{
dbname=BindDB threads=2
}
{SELECT zone FROM records WHERE zone = '$zone$'}
{SELECT ttl, type, mx_priority, CASE WHEN type = 'TXT' THEN '\"' || data || '\"' ELSE data END AS data FROM records WHERE zone = '$zone$' AND host = '$record$' AND type <> 'SOA' AND type <> 'NS'}
{SELECT ttl, type, data, primary_ns, resp_contact, serial, refresh, retry, expire, minimum FROM records WHERE zone = '$zone$' AND (type = 'SOA' OR type='NS')}
{SELECT ttl, type, host, mx_priority, CASE WHEN type = 'TXT' THEN '\"' || data || '\"' ELSE data END AS data, resp_contact, serial, refresh, retry, expire, minimum FROM records WHERE zone = '$zone$' AND type <> 'SOA' AND type <> 'NS'}
{SELECT zone FROM xfr where zone='$zone$' AND client = '$client$'}";
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment