The FreeBSD Diary

The FreeBSD Diary (TM) Remember
I remember
[ HOME | TOPICS | INDEX | WEB RESOURCES | BOOKS | CONTRIBUTE | SEARCH | FEEDBACK | FAQ | FORUMS ]

Scripts / handy tips
 New Topic  |  Go to Top  |  Go to Topic  |  Search  |  Log In   Newer Topic  |  Older Topic 
 build bind9 sdb pgsql from ports
Author: ardya 
Date:   10-08-08 05:52

For those interested in running bind9 using binds sdb database interface with a postgresql database, here's how I managed to do it using the bind94 port.

All of this was done on freebsd version 7.0-RELEASE-p3, postgresql74-client, bind 9.4.2-P2

First you need to install the postgresql-client port, I used version 7.4 as my pgsql server is that version.

I had to add an entry into /etc/make.conf so the bind build would find the pgsql libs:

.if ${.CURDIR:M*/bind94*}
CFLAGS+=-L/usr/local/lib
.endif

cd /usr/ports/dns/bind94

Run make config, I chose to replace the systems bind installation. run make, then kill it when you see configure starting to run.

Now the fun begins :)
-------------------------------------------------------------------
cp work/bind-9.4.2-P2/contrib/sdb/pgsql/pgsqldb.* work/bind-9.4.2-P2/bin/named
-------------------------------------------------------------------
vi work/bind-9.4.2-P2/bin/named/pgsql.c:

/*
#include <pgsql/libpq-fe.h>
*/
#include "/usr/local/include/libpq-fe.h"

Comment out the include and add the above one.
-------------------------------------------------------------------
vi work/bind-9.4.2-P2/bin/named/Makefile.in:

DBDRIVER_OBJS = pgsqldb.@O@
DBDRIVER_SRCS = pgsqldb.c
DBDRIVER_INCLUDES =
DBDRIVER_LIBS = -lpq

Fill in the values as shown above.
-------------------------------------------------------------------
vi work/bind-9.4.2-P2/bin/named/main.c:

Three entries have to be made here, type /xx then hit enter, the first you'll see is
/* #include "xxdb.h" */
Underneath that add
#include "pgsqldb.h"
Rerun the xx search and the next line will show
/* xxdb_init(); */
Underneath that add
pgsqldb_init();
Rerun the xx search again and the next line will show
/* xxdb_clear(); */
Underneath that add
pgsqldb_clear();

Save and exit vi, run make then make install, test the installation for database connectivity. Voila. If the build itself fails due to not finding either the pgsql include or lib, double check your edits as shown above. Note I didn't run make clean in the case where you may need to review the above edited files for any troubleshooting.

Configuring zones in named.conf, and postgres server itself falls outside the scope of this document. The basic format of a zone entry that uses pgsql for zone data is:

zone "blah" in {type master;database "pgsql dbname tablename dbhost dbuser password";notify no;};

pgsql defines the sdb database interface type
dbname is the name of the database that holds the zone tables
table is the table name that holds that zones data (one table per zone)
dbhost is the hostname or IP of the pgsql server
dbuser is the database user that has, preferrably, read only access to the database in question
password is the dbusers password

Included in the bind source code in /usr/ports/dns/bind94/work/bind-9.4.2-P2/contrib/sdb/pgsql/ is the source code for aq program called zonetodb, it takes zone files and inputs them into the database for you.

Table schemas require at east these 4 columns:
name | text |
ttl | integer |
rdtype | text |
rdata | text |

name column holds the hostname, or in-addr.arpa
ttl is time to live
rdtype is the record type, SOA/A/AAAA/PTR/NS/TXT/CNAME etc
rdata is the IP if A/AAAA, fqdn if PTR/NS/MX/CNAME, text string for TXT, and SOA gets special treatment, primary ns fqdn email.address serial_num and 4 various cache and ttl values as shown in a normal bind zone file.

More documentation available in /usr/ports/dns/bind94/work/bind-9.4.2-P2/doc/misc/sdb

I read freebsd-questions listmail, and can be found on IRC on EFNets #freebsdhelp.

Reply To This Message
 
 Re: build bind9 sdb pgsql from ports
Author: ardya 
Date:   28-08-08 14:56

Well thanks to pfloyd and wxs, a port was created and committed for this:
/usr/ports/dns/bind9-sdb.postgresql

Thanks guys, its working great.

Reply To This Message
 
 Re: build bind9 sdb pgsql from ports
Author: Dan 
Date:   28-08-08 15:19

Close: dns/bind9-sdb-postgresql

Or as I prefer to say:

http://www.freshports.org/dns/bind9-sdb-postgresql/

--
Webmaster

Reply To This Message
 Forum List  |  Threaded View   Newer Topic  |  Older Topic 


 Forum List  |  Need a Login? Register Here 
 User Login
 User Name:
 Password:
 Remember my login:
   
 Forgot Your Password?
Enter your email address or user name below and a new password will be sent to the email address associated with your profile.
How to get the most out of the forum

phorum.org