[AC_DEFINE([HAVE_LDAP_SASL_BIND], 1, [Define to 1 if you have ldap_sasl_bind])]
)
;;
- godbc )
- needunixodbc=yes
- ;;
opendbx)
AC_CHECK_HEADERS([odbx.h], , [AC_MSG_ERROR([opendbx header (odbx.h) not found])])
AC_SUBST([LIBOPENDBX])
AC_SUBST(CDB_CFLAGS)
fi
-if test "$needunixodbc"
-then
- AC_ARG_WITH(unixodbc,
- AC_HELP_STRING([--with-unixodbc=<path>],[root directory path of unixodbc installation]),
- [UNIXODBC_lib_check="$withval/lib/unixodbc $with_unixodbc/lib $withval/lib"
- UNIXODBC_inc_check="$withval/include/unixodbc"],
- [UNIXODBC_lib_check="/usr/local/unixodbc/lib/unixodbc /usr/local/lib/unixodbc /usr/lib/unixodbc /usr/local/unixodbc/lib /usr/local/lib /opt/unixodbc/lib /usr/lib"
- UNIXODBC_inc_check="/usr/local/unixodbc/include/unixodbc /usr/local/include/unixodbc/ /usr/local/include /opt/unixodbc/include/unixodbc /opt/unixodbc/include /usr/include/ /usr/include/unixodbc"])
- AC_ARG_WITH(unixodbc-lib,
- AC_HELP_STRING([--with-unixodbc-lib=<path>],[directory path of unixodbc library installation]),
- [UNIXODBC_lib_check="$withval/lib/unixodbc $withval/unixodbc $withval"])
- AC_ARG_WITH(unixodbc-includes,
- AC_HELP_STRING([--with-unixodbc-includes=<path>],[directory path of unixodbc header installation]),
- [UNIXODBC_inc_check="$withval/include $withval/include/unixodbc $withval/unixodbc $withval"])
- AC_MSG_CHECKING([for unixodbc library directory])
- UNIXODBC_libdir=
- for m in $UNIXODBC_lib_check; do
- if test -d "$m" && \
- (test -f "$m/libodbc.so" || test -f "$m/libodbc.a")
- then
- UNIXODBC_libdir=$m
- break
- fi
- done
- if test -z "$UNIXODBC_libdir"; then
- AC_MSG_ERROR([Didn't find the unixodbc library dir in '$UNIXODBC_lib_check'])
- fi
- case "$UNIXODBC_libdir" in
- /usr/lib ) UNIXODBC_lib="" ;;
- /* ) UNIXODBC_lib="-L$UNIXODBC_libdir -Wl,-rpath,$UNIXODBC_libdir"
- LDFLAGS="$UNIXODBC_lib $LDFLAGS"
- ;;
- * ) AC_MSG_ERROR([The unixodbc library directory ($UNIXODBC_libdir) must be an absolute path.]) ;;
- esac
-
- AC_SUBST(UNIXODBC_lib)
- AC_MSG_RESULT([$UNIXODBC_libdir])
- AC_MSG_CHECKING([for unixodbc include directory])
- UNIXODBC_incdir=
- for m in $UNIXODBC_inc_check; do
- if test -d "$m" && test -f "$m/sql.h"
- then
- UNIXODBC_incdir=$m
- break
- fi
- done
- if test -z "$UNIXODBC_incdir"; then
- AC_MSG_ERROR([Didn't find the unixodbc include dir in '$UNIXODBC_inc_check'])
- fi
- case "$UNIXODBC_incdir" in
- /* ) ;;
- * ) AC_MSG_ERROR([The unixodbc include directory ($UNIXODBC_incdir) must be an absolute path.]) ;;
- esac
- AC_SUBST(UNIXODBC_incdir)
- AC_MSG_RESULT([$UNIXODBC_incdir])
-
-# LIBS="$LIBS -lunixodbc"
-fi
-
for a in $modules
do
moduledirs="$moduledirs ${a}backend"
modules/gmysqlbackend/Makefile modules/db2backend/Makefile \
modules/geobackend/Makefile modules/opendbxbackend/Makefile \
modules/pipebackend/Makefile modules/oraclebackend/Makefile \
-modules/godbcbackend/Makefile \
modules/gpgsqlbackend/Makefile modules/ldapbackend/Makefile \
modules/gsqlite3backend/Makefile \
modules/goraclebackend/Makefile modules/mydnsbackend/Makefile \
SUBDIRS=@moduledirs@
-DIST_SUBDIRS=db2backend geobackend gmysqlbackend godbcbackend goraclebackend gpgsqlbackend gsqlite3backend ldapbackend luabackend mydnsbackend opendbxbackend oraclebackend pipebackend tinydnsbackend remotebackend randombackend
+DIST_SUBDIRS=db2backend geobackend gmysqlbackend goraclebackend gpgsqlbackend gsqlite3backend ldapbackend luabackend mydnsbackend opendbxbackend oraclebackend pipebackend tinydnsbackend remotebackend randombackend
+++ /dev/null
-AM_CPPFLAGS=-I@UNIXODBC_incdir@ @THREADFLAGS@
-lib_LTLIBRARIES = libgodbcbackend.la
-
-EXTRA_DIST=OBJECTFILES OBJECTLIBS
-
-libgodbcbackend_la_SOURCES=godbcbackend.cc godbcbackend.hh \
- sodbc.hh sodbc.cc
-
-
-libgodbcbackend_la_LDFLAGS=-module -avoid-version -lodbc
+++ /dev/null
-// The Generic ODBC Backend
-// By Michel Stol <michel@powerdns.com>
-
-#include "pdns/utility.hh"
-#include <map>
-#include <sstream>
-#include <string>
-
-#include "pdns/dns.hh"
-#include "pdns/dnsbackend.hh"
-#include "pdns/dnspacket.hh"
-#include "pdns/ueberbackend.hh"
-#include "pdns/pdnsexception.hh"
-#include "pdns/logger.hh"
-#include "pdns/arguments.hh"
-#include "sodbc.hh"
-#include "godbcbackend.hh"
-
-
-// Connects to the database.
-gODBCBackend::gODBCBackend (const std::string & mode, const std::string & suffix) : GSQLBackend( mode, suffix )
-{
- try
- {
- setDB( new SODBC( getArg( "datasource" ), getArg( "username" ), getArg( "password" )));
- }
- catch( SSqlException & e )
- {
- L<<Logger::Error<< mode << " Connection failed: " << e.txtReason() << std::endl;
- throw PDNSException( "Unable to launch " + mode + " connection: " + e.txtReason());
- }
-
- L << Logger::Warning << mode << " Connection successful" << std::endl;
-}
-
-
-//! Constructs a gODBCBackend
-class gODBCFactory : public BackendFactory
-{
-public:
- //! Constructor.
- gODBCFactory( const std::string & mode ) : BackendFactory( mode ), d_mode( mode )
- {
- }
-
- //! Declares all needed arguments.
- void declareArguments( const std::string & suffix = "" )
- {
- declare( suffix, "datasource", "Datasource (DSN) to use","PowerDNS");
- declare( suffix, "username", "User to connect as","powerdns");
- declare( suffix, "password", "Password to connect with","");
-
- declare( suffix, "basic-query", "Basic query","select content,ttl,prio,type,domain_id,name from records where type='%s' and name='%s'");
- declare( suffix, "id-query", "Basic with ID query","select content,ttl,prio,type,domain_id,name from records where type='%s' and name='%s' and domain_id=%d");
- declare( suffix, "wildcard-query", "Wildcard query","select content,ttl,prio,type,domain_id,name from records where type='%s' and name like '%s'");
- declare( suffix, "wildcard-id-query", "Wildcard with ID query","select content,ttl,prio,type,domain_id,name from records where type='%s' and name like '%s' and domain_id='%d'");
-
- declare( suffix, "any-query", "Any query","select content,ttl,prio,type,domain_id,name from records where name='%s'");
- declare( suffix, "any-id-query", "Any with ID query","select content,ttl,prio,type,domain_id,name from records where name='%s' and domain_id=%d");
- declare( suffix, "wildcard-any-query", "Wildcard ANY query","select content,ttl,prio,type,domain_id,name from records where name like '%s'");
- declare( suffix, "wildcard-any-id-query", "Wildcard ANY with ID query","select content,ttl,prio,type,domain_id,name from records where name like '%s' and domain_id='%d'");
-
- declare( suffix, "list-query", "AXFR query", "select content,ttl,prio,type,domain_id,name from records where domain_id='%d'");
- declare( suffix, "master-zone-query", "Data", "select master from domains where name='%s' and type='SLAVE'");
-
- declare( suffix, "info-zone-query", "","select id,name,master,last_check,notified_serial,type from domains where name='%s'");
-
- declare( suffix, "info-all-slaves-query", "","select id,name,master,last_check,type from domains where type='SLAVE'");
- declare( suffix, "supermaster-query", "", "select account from supermasters where ip='%s' and nameserver='%s'");
- declare( suffix, "insert-zone-query", "", "insert into domains (type,name) values('NATIVE','%s')");
- declare( suffix, "insert-slave-query", "", "insert into domains (type,name,master,account) values('SLAVE','%s','%s','%s')");
- declare( suffix, "insert-record-query", "", "insert into records (content,ttl,prio,type,domain_id,name) values ('%s',%d,%d,'%s',%d,'%s')");
- declare( suffix, "update-master-query", "", "update domains set master='%s' where name='%s'");
- declare( suffix, "update-kind-query", "", "update domains set type='%s' where name='%s'");
- declare( suffix, "update-serial-query", "", "update domains set notified_serial=%d where id=%d");
- declare( suffix, "update-lastcheck-query", "", "update domains set last_check=%d where id=%d");
- declare( suffix, "info-all-master-query", "", "select id,name,master,last_check,notified_serial,type from domains where type='MASTER'");
- declare( suffix, "delete-zone-query", "", "delete from records where domain_id=%d");
- }
-
- //! Constructs a new gODBCBackend object.
- DNSBackend *make(const string & suffix = "" )
- {
- return new gODBCBackend( d_mode, suffix );
- }
-
-private:
- const string d_mode;
-};
-
-
-//! Magic class that is activated when the dynamic library is loaded
-class gODBCLoader
-{
-public:
- //! This reports us to the main UeberBackend class
- gODBCLoader()
- {
- BackendMakers().report( new gODBCFactory("godbc"));
- L<<Logger::Warning << "This is module godbcbackend reporting" << std::endl;
- }
-};
-
-
-//! Reports the backendloader to the UeberBackend.
-static gODBCLoader gmysqlloader;
+++ /dev/null
-// The Generic ODBC Backend
-// By Michel Stol <michel@powerdns.com>
-
-#include <string>
-#include "pdns/backends/gsql/gsqlbackend.hh"
-
-class gODBCBackend : public GSQLBackend
-{
-private:
-public:
- //! Constructor that connects to the database, throws an exception if something went wrong.
- gODBCBackend( const std::string & mode, const std::string & suffix );
-
-};
-
+++ /dev/null
-// The Generic ODBC Backend
-// By Michel Stol <michel@powerdns.com>
-
-#include "pdns/utility.hh"
-#include <sstream>
-#include "sodbc.hh"
-#include <malloc.h>
-#include <string.h>
-
-// Constructor.
-SODBC::SODBC(
- const std::string & dsn,
- const std::string & username,
- const std::string & password
- )
-{
- SQLRETURN result;
-
- // Allocate an environment handle.
- result = SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &m_environment );
- testResult( result, "Could not allocate an environment handle." );
-
- // Set ODBC version. (IEUW!)
- result = SQLSetEnvAttr( m_environment, SQL_ATTR_ODBC_VERSION, reinterpret_cast< void * >( SQL_OV_ODBC3 ), 0 );
- testResult( result, "Could not set the ODBC version." );
-
- // Allocate connection handle.
- result = SQLAllocHandle( SQL_HANDLE_DBC, m_environment, &m_connection );
- testResult( result, "Could not allocate a connection handle." );
-
- // Connect to the database.
- char *l_dsn = strdup( dsn.c_str());
- char *l_username = strdup( username.c_str());
- char *l_password = strdup( password.c_str());
-
- result = SQLConnect( m_connection,
- reinterpret_cast< SQLTCHAR * >( l_dsn ), dsn.length(),
- reinterpret_cast< SQLTCHAR * >( l_username ), username.length(),
- reinterpret_cast< SQLTCHAR * >( l_password ), password.length());
-
- free( l_dsn );
- free( l_username );
- free( l_password );
-
- testResult( result, "Could not connect to ODBC datasource." );
-
- // Allocate statement handle.
- result = SQLAllocHandle( SQL_HANDLE_STMT, m_connection, &m_statement );
- testResult( result, "Could not allocate a statement handle." );
-
- m_busy = false;
- m_log = false;
-}
-
-
-// Destructor.
-SODBC::~SODBC( void )
-{
- // Disconnect from database and free all used resources.
- SQLFreeHandle( SQL_HANDLE_STMT, m_statement );
-
- SQLDisconnect( m_connection );
-
- SQLFreeHandle( SQL_HANDLE_DBC, m_connection );
- SQLFreeHandle( SQL_HANDLE_ENV, m_environment );
-
- // Free all allocated column memory.
- for ( int i = 0; i < m_columnInfo.size(); i++ )
- {
- if ( m_columnInfo[ i ].m_pData )
- delete m_columnInfo[ i ].m_pData;
- }
-}
-
-
-// Executes a query.
-int SODBC::doQuery( const std::string & query )
-{
- SQLRETURN result;
- char *tmp;
-
- if ( m_busy )
- throw SSqlException( "Tried to execute another query while being busy." );
-
- tmp = strdup( query.c_str());
-
- // Execute query.
- result = SQLExecDirect( m_statement, reinterpret_cast< SQLTCHAR * >( tmp ), query.length());
- free( tmp );
-
- testResult( result, "Could not execute query." );
-
- // We are now busy.
- m_busy = true;
-
- // Determine the number of columns.
- SQLSMALLINT numColumns;
- SQLNumResultCols( m_statement, &numColumns );
-
- if ( numColumns == 0 )
- throw SSqlException( "Could not determine the number of columns." );
-
- // Fill m_columnInfo.
- m_columnInfo.clear();
-
- column_t column;
- SQLSMALLINT nullable;
- SQLSMALLINT type;
-
- for ( SQLSMALLINT i = 1; i <= numColumns; i++ )
- {
- SQLDescribeCol( m_statement, i, NULL, 0, NULL, &type, &column.m_size, NULL, &nullable );
-
- if ( nullable == SQL_NULLABLE )
- column.m_canBeNull = true;
- else
- column.m_canBeNull = false;
-
- // Allocate memory.
- switch ( type )
- {
- case SQL_CHAR:
- case SQL_VARCHAR:
- case SQL_LONGVARCHAR:
- column.m_type = SQL_C_CHAR;
- column.m_pData = new SQLCHAR[ column.m_size ];
- break;
-
- case SQL_SMALLINT:
- case SQL_INTEGER:
- column.m_type = SQL_C_SLONG;
- column.m_size = sizeof( long int );
- column.m_pData = new long int;
- break;
-
- case SQL_REAL:
- case SQL_FLOAT:
- case SQL_DOUBLE:
- column.m_type = SQL_C_DOUBLE;
- column.m_size = sizeof( double );
- column.m_pData = new double;
- break;
-
- default:
- column.m_pData = NULL;
-
- }
-
- m_columnInfo.push_back( column );
- }
-
- return 0;
-}
-
-
-// Executes a query.
-int SODBC::doQuery( const std::string & query, result_t & result )
-{
- result.clear();
-
- doQuery( query );
-
- row_t row;
- while ( getRow( row ))
- result.push_back( row );
-
- return result.size();
-}
-
-
-// Executes a command.
-int SODBC::doCommand( const std::string & command )
-{
- SQLRETURN result;
- char *tmp;
-
- if ( m_busy )
- throw SSqlException( "Tried to execute another query while being busy." );
-
- tmp = strdup( command.c_str());
-
- // Execute query.
- result = SQLExecDirect( m_statement, reinterpret_cast< SQLTCHAR * >( tmp ), command.length());
- free( tmp );
-
- testResult( result, "Could not execute query." );
-
- SQLFreeStmt( m_statement, SQL_CLOSE );
-
- return 0;
-}
-
-// Escapes a SQL string.
-std::string SODBC::escape( const std::string & name )
-{
- std::string a;
-
- for( std::string::const_iterator i = name.begin(); i != name.end(); ++i )
- {
- if( *i == '\'' || *i == '\\' )
- a += '\\';
- a += *i;
- }
-
- return a;
-}
-
-
-// Returns the content of a row.
-bool SODBC::getRow( row_t & row )
-{
- SQLRETURN result;
-
- row.clear();
-
- result = SQLFetch( m_statement );
- if ( result == SQL_SUCCESS || result == SQL_SUCCESS_WITH_INFO )
- {
- // We've got a data row, now lets get the results.
- SQLLEN len;
- for ( int i = 0; i < m_columnInfo.size(); i++ )
- {
- if ( m_columnInfo[ i ].m_pData == NULL )
- continue;
-
- // Clear buffer.
- memset( m_columnInfo[ i ].m_pData, 0, m_columnInfo[ i ].m_size );
-
- SQLGetData( m_statement, i + 1, m_columnInfo[ i ].m_type, m_columnInfo[ i ].m_pData, m_columnInfo[ i ].m_size, &len );
-
- if ( len == SQL_NULL_DATA )
- {
- // Column is NULL, so we can skip the converting part.
- row.push_back( "" );
- continue;
- }
-
- // Convert the data into strings.
- std::ostringstream str;
-
- switch ( m_columnInfo[ i ].m_type )
- {
- case SQL_C_CHAR:
- row.push_back( reinterpret_cast< char * >( m_columnInfo[ i ].m_pData ));
- break;
-
- case SQL_C_SSHORT:
- case SQL_C_SLONG:
- str << *( reinterpret_cast< long * >( m_columnInfo[ i ].m_pData ));
- row.push_back( str.str());
-
- break;
-
- case SQL_C_DOUBLE:
- str << *( reinterpret_cast< double * >( m_columnInfo[ i ].m_pData ));
- row.push_back( str.str());
-
- break;
-
- default:
- // Eh?
- row.push_back( "" );
-
- }
- }
-
- // Done!
- return true;
- }
-
- // No further results, or error.
- m_busy = false;
-
- // Free all allocated column memory.
- for ( int i = 0; i < m_columnInfo.size(); i++ )
- {
- if ( m_columnInfo[ i ].m_pData )
- delete m_columnInfo[ i ].m_pData;
- }
-
- SQLFreeStmt( m_statement, SQL_CLOSE );
-
- return false;
-}
-
-
-// Sets the log state.
-void SODBC::setLog( bool state )
-{
- m_log = state;
-}
-
-
-// Returns an exception.
-SSqlException SODBC::sPerrorException( const std::string & reason )
-{
- return SSqlException( reason );
-}
-
-
-// Tests the result.
-void SODBC::testResult( SQLRETURN result, const std::string & message )
-{
- if ( result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO )
- throw SSqlException( message );
-}
+++ /dev/null
-// The Generic ODBC Backend
-// By Michel Stol <michel@powerdns.com>
-
-#ifndef SODBC_HH
-#define SODBC_HH
-
-#include <string>
-#include <vector>
-
-// The following line makes Bert puke every time he sees it.
-//#define WINDOWS_LEAN_AND_MEAN
-//#include <windows.h>
-#include <sql.h>
-#include <sqlext.h>
-
-#include "pdns/backends/gsql/ssql.hh"
-
-
-//! ODBC SSql implementation for use with the Generic ODBC Backend.
-class SODBC : public SSql
-{
-private:
- //! Column type.
- struct column_t
- {
- SQLSMALLINT m_type; //!< Type of the column.
- SQLULEN m_size; //!< Column size.
- SQLPOINTER m_pData; //!< Pointer to the memory where to store the data.
- bool m_canBeNull; //!< Can this column be null?
- };
-
- bool m_log; //!< Should we log?
- bool m_busy; //!< Are we busy executing a query?
-
- SQLHDBC m_connection; //!< Database connection handle.
- SQLHENV m_environment; //!< Database environment handle
- SQLHSTMT m_statement; //!< Database statement handle.
-
- //! Column info.
- std::vector< column_t > m_columnInfo;
-
-
- //! Throws a SQLException if the result has an error value.
- void testResult( SQLRETURN result, const std::string & message = "" );
-
-
-public:
- //! Default constructor.
- /*!
- This constructor connects to an ODBC datasource and makes sure it's ready to use.
-
- \param database The database where the data is located (not used).
- \param dsn The ODBC DSN to use.
- \param username Username to use.
- \param password Password to use.
- */
- SODBC(
- const std::string & dsn = "PowerDNS",
- const std::string & username = "",
- const std::string & password = ""
- );
-
- //! Destructor.
- virtual ~SODBC( void );
-
- //! Executes a query.
- int doQuery( const std::string & query );
-
- //! Executes a query and stores the result.
- int doQuery( const std::string & query, result_t & result );
-
- //! Executes a command.
- int doCommand( const std::string & command );
-
- //! Escapes a SQL string.
- std::string escape( const std::string & name );
-
- //! Returns a row.
- bool getRow( row_t & row );
-
- //! Sets the logging state.
- void setLog( bool state );
-
- //! Returns an exception.
- SSqlException sPerrorException( const std::string & reason );
-
-};
-
-
-#endif // SODBC_HH
Do not wrap statements in quotes as this will not work.
Besides the query related settings, the following configuration
options are available, where one should substitute 'gmysql',
- 'gpgsql', 'godbc' or 'goracle' for the prefix 'backend'. So
+ 'gpgsql', or 'goracle' for the prefix 'backend'. So
'backend-dbname' can stand for 'gpgsql-dbname' or 'gmysql-dbname'
etc.
</para>