DLZ error in ODBC driver

Stefan Steiger stefan.steiger at bluewin.ch
Thu Feb 6 14:07:12 UTC 2014


Hi everyone,


I just tried connecting bind9 to a MS-SQL database via ODBC (DLZ).
I'm just writing to say that there is an error (actually several) in the
bind9 DLZ driver for ODBC.
Somebody with write access to the repo should correct it, please.

The error is in this file:
bind9/bind-9.9.5/contrib/dlz/drivers/dlz_odbc_driver.c
in function odbc_getField and odbc_getManyFields.

It defines size as SQLINTEGER.
SQLINTEGER size;

It should define size as SQLLEN
SQLLEN size;

or otherwise it doesn't work on 64-Bit Linux (Segmentation fault (core
dumped)).
As it is now, it works only on 32 bit Linux, because only there this
doesn't make a difference).

Also there seems to be an error in the handling of the TEXT datatype.
If I create a Microsoft SQL-Server table with data as TEXT or
VARCHAR(MAX), then it crashes.
If I create data as varchar(1000), then it works.


Also there is an error in function dns_rdatatype_fromtext
from file
/root/sources/bind9/bind-9.9.5/lib/dns/rdata.c
which comes via function dns_sdlz_putrr in file
/root/sources/bind9/bind-9.9.5/lib/dns/sdlz.c

This is probably also the place where TEXT fails with MS-SQL.
But it definitely is the place where it fails with FireBird/InteBase.
By the way, in Firebird, changing the datatype of column data to varchar(1000) doesn't help.

Hint:
If you try to reproduce the problem with Firebird ODBC, don't change
size to SQLLEN.
There is the same bug in the Firebird ODBC driver that is in bind9.
Getting a few defines right must be so very hard indeed.

The compiler even warns, but I guess people like the person who wrote
the "very reliable" code of function dns_rdatatype_fromtext,
that does whatever it is that it should do, don't bother about such tiny
neglectable details in the first place.

Why is data even of type "text" ? It doesn't make sense.
Is that because in MySQL, varchar is limited to a maximum length of 255 ?

Also I think allocating the maximum number of bytes a text field is
capable of storing, as in
if (sqlOK(SQLColAttribute(stmnt, i, SQL_DESC_DISPLAY_SIZE,   ...
from function odbc_getManyFields
bind9/bind-9.9.5/contrib/dlz/drivers/dlz_odbc_driver.c

which must be about 4GB (give or take)  is not a very sensible thing to
do...



----- Table Create for SQL-Server.

CREATE TABLE dbo.dns_record (
      id integer IDENTITY(1,1) NOT NULL
     ,zone character varying(255) NOT NULL
     ,ttl integer NOT NULL
     ,type character varying(255) NOT NULL
     ,host character varying(255) DEFAULT '@' NOT NULL
     ,mx_priority integer
     -- ,data character text
     -- ,data character varying(MAX)
     ,data character varying(1000)
     ,primary_ns character varying(255)
     ,resp_contact character varying(255)
     ,serial bigint
     ,refresh integer
     ,retry integer
     ,expire integer
     ,minimum integer
);

ALTER TABLE dbo.dns_record
     ADD CONSTRAINT dns_record_pkey PRIMARY KEY (id);


CREATE NONCLUSTERED INDEX dns_record_zone_idx ON dbo.dns_record(zone ASC);
CREATE NONCLUSTERED INDEX dns_record_type_idx ON dbo.dns_record(type ASC);
CREATE NONCLUSTERED INDEX dns_record_host_idx ON dbo.dns_record(host ASC);




Sample named.conf for MS-SQL:



// This is the primary configuration file for the BIND DNS server named.
//
// Please read /usr/share/doc/bind9/README.Debian.gz for information on the
// structure of BIND configuration files in Debian, *BEFORE* you customize
// this configuration file.
//
// If you are just adding zones, please do that in
/etc/bind/named.conf.local
#auskommentiert !!!
#include "/etc/bind/named.conf.options";
#include "/etc/bind/named.conf.local";
#include "/etc/bind/named.conf.default-zones";


key "rndc-key" {
             // how was key encoded
             algorithm hmac-md5;
             // what is the pass-phrase for the key
             secret
"4ptlffIBhVnZgfdT0CXIcLDZeONxA5bHUVT5W2NofC9O4FOfjps8FzghoQy4myXnJ0g9jrna9Sjl6uKt6c/22A==";
};


#options {
#default-key "rndc-key";
#default-server 127.0.0.1;
#default-port 953;
#};

controls {
inet * port 953 allow { any; } keys { "rndc-key"; };
#inet * port 53 allow { any; } keys { "rndc-key"; };
};



logging {
     channel query.log {
         file "/var/log/query.log";
         // Set the severity to dynamic to see all the debug messages.
         severity dynamic;
     };

     category queries { query.log; };
};


dlz "odbc zone" {
        database "odbc 2
        {dsn=bind9_MSSQL user=SYSDBA pass=masterkey}
        {SELECT zone FROM dns_record WHERE zone = '$zone$'}
        {SELECT ttl, type, mx_priority, case when lower(type)='txt' then
'\"' + data + '\"' else data end AS data FROM dns_record 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 dns_record WHERE zone = '$zone$'
AND (type = 'SOA' OR type='NS')}
        {SELECT ttl, type, host, mx_priority, case when
lower(type)='txt' then '\"' + data + '\"' else data end AS data,
resp_contact, serial, refresh, retry, expire, minimum FROM dns_record
WHERE zone = '$zone$' AND type <> 'SOA' AND type <> 'NS'}
        {SELECT zone FROM dns_xfr where zone='$zone$' AND client =
'$client$'}";
};





Table Create for Firebird/Interbase


CREATE TABLE dns_record
(
      id integer NOT NULL
     ,zone character varying(255) NOT NULL
     ,ttl integer NOT NULL
     ,type character varying(255) NOT NULL
     ,host character varying(255) DEFAULT '@' NOT NULL
     ,mx_priority integer
     --,data BLOB SUB_TYPE TEXT --
http://www.firebirdsql.org/manual/migration-mssql-data-types.html
     ,data character varying(1000)
     ,primary_ns character varying(255)
     ,resp_contact character varying(255)
     ,serial bigint
     ,refresh integer
     ,retry integer
     ,expire integer
     ,minimum integer
);

ALTER TABLE dns_record
     ADD CONSTRAINT dns_record_pkey PRIMARY KEY (id);


CREATE INDEX dns_record_host_idx
     ON dns_record (host)
;

CREATE INDEX dns_record_type_idx
     ON dns_record (type)
;

CREATE INDEX dns_record_zone_idx
     ON dns_record (zone)
;



-----------------------------------

named.conf for Firebird/InterBase

// This is the primary configuration file for the BIND DNS server named.
//
// Please read /usr/share/doc/bind9/README.Debian.gz for information on the
// structure of BIND configuration files in Debian, *BEFORE* you customize
// this configuration file.
//
// If you are just adding zones, please do that in
/etc/bind/named.conf.local
#auskommentiert !!!
#include "/etc/bind/named.conf.options";
#include "/etc/bind/named.conf.local";
#include "/etc/bind/named.conf.default-zones";


key "rndc-key" {
             // how was key encoded
             algorithm hmac-md5;
             // what is the pass-phrase for the key
             secret
"4ptlffIBhVnZgfdT0CXIcLDZeONxA5bHUVT5W2NofC9O4FOfjps8FzghoQy4myXnJ0g9jrna9Sjl6uKt6c/22A==";
};


#options {
#default-key "rndc-key";
#default-server 127.0.0.1;
#default-port 953;
#};

controls {
inet * port 953 allow { any; } keys { "rndc-key"; };
#inet * port 53 allow { any; } keys { "rndc-key"; };
};



logging {
     channel query.log {
         file "/var/log/query.log";
         // Set the severity to dynamic to see all the debug messages.
         severity dynamic;
     };

     category queries { query.log; };
};


dlz "odbc zone" {
        database "odbc 2
        {dsn=bind9_IB user=SYSDBA pass=masterkey}
        {SELECT zone FROM dns_record WHERE zone = '$zone$'}
        {SELECT ttl, type, mx_priority, case when lower(type)='txt' then
'\"' || data || '\"' else data end AS data FROM dns_record 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 dns_record WHERE zone = '$zone$'
AND (type = 'SOA' OR type='NS')}
        {SELECT ttl, type, host, mx_priority, case when
lower(type)='txt' then '\"' || data || '\"' else data end AS data,
resp_contact, serial, refresh, retry, expire, minimum FROM dns_record
WHERE zone = '$zone$' AND type <> 'SOA' AND type <> 'NS'}
        {SELECT zone FROM dns_xfr where zone='$zone$' AND client =
'$client$'}";
};





-- odbcinst.ini

[Firebird]
Description = InterBase/Firebird ODBC Driver
Driver = /usr/lib/libOdbcFb.so
Setup = /usr/lib/libOdbcFbS.so
Threading = 1
FileUsage = 1
CPTimeout =
CPReuse =


[FreeTDS]
Description = MS SQL database access with Free TDS
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so






------- odbc.ini

[bind9_IB]
Description = "Firebird Employee sample database"
Driver = Firebird
Dbname = localhost:/var/lib/firebird/2.5/data/employee.fdb
Role =
CharacterSet =
ReadOnly = No
NoWait = No


[bind9_MSSQL]
Description = "test"
Driver = FreeTDS
Server = 192.168.119.22
Port = 1433
Database = bind9_dlz
TDS_Version = 8.0




More information about the bind-users mailing list