From: Bert Hubert Date: Fri, 8 Apr 2005 18:58:52 +0000 (+0000) Subject: add initial cut at working Generic Oracle backend X-Git-Tag: pdns-2.9.18~43 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c3cf76c4656704608da0788056ac9035132652b5;p=pdns add initial cut at working Generic Oracle backend including documentation Very lightly tested git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@337 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/configure.in b/configure.in index dc3f30de1..dac21de25 100644 --- a/configure.in +++ b/configure.in @@ -410,4 +410,4 @@ modules/geobackend/Makefile \ modules/pipebackend/Makefile modules/oraclebackend/Makefile \ modules/xdbbackend/Makefile modules/odbcbackend/Makefile \ modules/gpgsqlbackend/Makefile modules/ldapbackend/Makefile -modules/gsqlitebackend/Makefile ) +modules/gsqlitebackend/Makefile modules/goraclebackend/Makefile ) diff --git a/modules/goraclebackend/Makefile.am b/modules/goraclebackend/Makefile.am index 4aab9c1d8..5fc100191 100644 --- a/modules/goraclebackend/Makefile.am +++ b/modules/goraclebackend/Makefile.am @@ -1,7 +1,7 @@ -#lib_LTLIBRARIES = libgoraclebackend.la -bin_PROGRAMS = soracle +lib_LTLIBRARIES = libgoraclebackend.la +#bin_PROGRAMS = soracle -soracle_SOURCES=soracle.cc soracle.hh +#soracle_SOURCES=soracle.cc soracle.hh EXTRA_DIST=OBJECTFILES OBJECTLIBS @@ -10,12 +10,12 @@ ORACLE_HOME ?= /opt/oracle INCLUDES= -I$(ORACLE_HOME)/rdbms/demo \ -I$(ORACLE_HOME)/rdbms/public -#libgoraclebackend_la_SOURCES=goraclebackend.cc goraclebackend.hh \ +libgoraclebackend_la_SOURCES=goraclebackend.cc goraclebackend.hh \ soracle.hh soracle.cc -#libgoraclebackend_la_LDFLAGS=-module -L$(ORACLE_HOME)/lib -lclient9 -lclntst9 -soracle_LDFLAGS=-module -L$(ORACLE_HOME)/lib -lclient9 -lclntst9 -ldl -pthread +libgoraclebackend_la_LDFLAGS=-module -L$(ORACLE_HOME)/lib -lclient9 -lclntst9 +#soracle_LDFLAGS=-module -L$(ORACLE_HOME)/lib -lclient9 -lclntst9 -ldl -pthread # -Wl,-Bstatic -lpq++ -lpq -Wl,-Bdynamic -lssl -lcrypt -lcrypto diff --git a/modules/goraclebackend/goraclebackend.cc b/modules/goraclebackend/goraclebackend.cc index e69de29bb..5d4fbeb48 100644 --- a/modules/goraclebackend/goraclebackend.cc +++ b/modules/goraclebackend/goraclebackend.cc @@ -0,0 +1,101 @@ + +#include +#include + +using namespace std; + +#include "pdns/dns.hh" +#include "pdns/dnsbackend.hh" +#include "goraclebackend.hh" +#include "pdns/dnspacket.hh" +#include "pdns/ueberbackend.hh" +#include "pdns/ahuexception.hh" +#include "pdns/logger.hh" +#include "pdns/arguments.hh" + +#include "soracle.hh" + + +#include + +gOracleBackend::gOracleBackend(const string &mode, const string &suffix) : GSQLBackend(mode,suffix) +{ + try { + setDB(new SOracle(getArg("dbname"), + getArg("host"), + getArgAsNum("port"), + getArg("socket"), + getArg("user"), + getArg("password"))); + + } + + catch(SSqlException &e) { + L< +#include + +#include "pdns/backends/gsql/gsqlbackend.hh" + +using namespace std; + +/** The gOracleBackend is a DNSBackend that can answer DNS related questions. It looks up data + in PostgreSQL */ +class gOracleBackend : public GSQLBackend +{ +public: + gOracleBackend(const string &mode, const string &suffix); //!< Makes our connection to the database. Throws an exception if it fails. + +private: +}; diff --git a/modules/goraclebackend/soracle.cc b/modules/goraclebackend/soracle.cc index 5349c99b5..2dd0f48c6 100644 --- a/modules/goraclebackend/soracle.cc +++ b/modules/goraclebackend/soracle.cc @@ -7,10 +7,37 @@ #include "pdns/misc.hh" #include "pdns/logger.hh" #include "pdns/dns.hh" +#include using namespace std; bool SOracle::s_dolog; + +string SOracle::getOracleError() +{ + string mReason = "ORA-UNKNOWN"; + + if (d_errorHandle != NULL) { + text msg[512]; + sb4 errcode = 0; + + memset((void *) msg, (int)'\0', (size_t)512); + + OCIErrorGet((dvoid *) d_errorHandle,1, NULL, &errcode, msg, sizeof(msg), OCI_HTYPE_ERROR); + if (errcode) { + char *p = (char*) msg; + while (*p++ != 0x00) { + if (*p == '\n' || *p == '\r') { + *p = ';'; + } + } + + mReason = (char*) msg; + } + } + return mReason; +} + SOracle::SOracle(const string &database, const string &host, u_int16_t port, const string &msocket, const string &user, const string &password) @@ -40,13 +67,11 @@ SOracle::SOracle(const string &database, const string &host, u_int16_t port, const char *username = user.c_str(); - - err = OCILogon(d_environmentHandle, d_errorHandle, &d_serviceContextHandle, (OraText*) username, strlen(username), (OraText*) password.c_str(), strlen(password.c_str()), (OraText*) database.c_str(), strlen(database.c_str())); if (err) { - throw sPerrorException("oops"); // mErrorHandle); + throw sPerrorException("Loging in to Oracle gave error: " + getOracleError()); } @@ -59,7 +84,29 @@ void SOracle::setLog(bool state) SOracle::~SOracle() { + if(d_handle) { + OCIHandleFree(d_handle, OCI_HTYPE_STMT); + d_handle=0; + } + int err; + if (d_serviceContextHandle != NULL) { + err=OCILogoff(d_serviceContextHandle, d_errorHandle); + if(err) { + cerr<<"Problems logging out: "+getOracleError()< + Oracle specifics + + The default setup conforms to the following schema, which you should add to a PostgreSQL database. + + +create table domains ( + id NUMBER, + name VARCHAR(255) NOT NULL, + master VARCHAR(20) DEFAULT NULL, + last_check INT DEFAULT NULL, + type VARCHAR(6) NOT NULL, + notified_serial INT DEFAULT NULL, + account VARCHAR(40) DEFAULT NULL, + primary key (id) +); +create sequence DOMAINS_ID_SEQUENCE; +create index DOMAINS$NAME on Domains (NAME); + + +CREATE TABLE records ( + id number(11) not NULL, + domain_id INT DEFAULT NULL REFERENCES Domains(ID) ON DELETE CASCADE, + name VARCHAR(255) DEFAULT NULL, + type VARCHAR(6) DEFAULT NULL, + content VARCHAR(255) DEFAULT NULL, + ttl INT DEFAULT NULL, + prio INT DEFAULT NULL, + change_date INT DEFAULT NULL, + primary key (id) +); + +create index RECORDS$NAME on RECORDS (NAME); +create sequence RECORDS_ID_SEQUENCE; + +create table supermasters ( + ip VARCHAR(25) NOT NULL, + nameserver VARCHAR(255) NOT NULL, + account VARCHAR(40) DEFAULT NULL +); + + + + + This schema contains all elements needed for master, slave and superslave operation. Depending on which features will be used, the 'GRANT' statements + can be trimmed to make sure PDNS cannot subvert the contents of your database. + + + Zone2sql with the --gpgsql flag also assumes this layout is in place. + + + + Basic functionality 4 queries are needed for regular lookups, 4 for 'fancy records' which are disabled by default and 1 is needed for zone transfers. @@ -7763,7 +7815,7 @@ GRANT ALL ON records_id_seq TO pdns; - Generic Oracle backend + Oracle backend Oracle backend capabilities