Show
Ignore:
Timestamp:
03/18/07 16:26:42 (6 years ago)
Author:
ahu
Message:

ldap, opendbx updates

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pdns/modules/opendbxbackend/odbxbackend.hh

    r681 r977  
    11/* 
    22 *  PowerDNS OpenDBX Backend 
    3  *  Copyright (C) 2005 Norbert Sendetzky <norbert@linuxnetworks.de> 
     3 *  Copyright (C) 2005-2007 Norbert Sendetzky <norbert@linuxnetworks.de> 
    44 * 
    55 *  This program is free software; you can redistribute it and/or modify 
    66 *  it under the terms of the GNU General Public License version 2 
    7  *  the Free Software Foundation 
    8  *  any later version. 
     7 *  as published by the Free Software Foundation 
    98 * 
    109 *  This program is distributed in the hope that it will be useful, 
     
    3332#include <pdns/logger.hh> 
    3433#include <odbx.h> 
    35 #include "modules/ldapbackend/utils.hh" 
    3634 
    3735 
     
    5452class OdbxBackend : public DNSBackend 
    5553{ 
     54        enum QueryType { READ, WRITE }; 
     55 
    5656        string m_myname; 
    5757        string m_qname; 
    5858        int m_default_ttl; 
    5959        bool m_qlog; 
    60         odbx_t* m_handle; 
     60        odbx_t* m_handle[2]; 
    6161        odbx_result_t* m_result; 
    6262        char m_escbuf[BUFLEN]; 
    6363        char m_buffer[2*BUFLEN]; 
     64        vector<string> m_hosts[2]; 
    6465 
    65         bool getRecord(); 
    66         void execStmt( const char* stmt, unsigned long length, bool select ); 
    67         void getDomainList( const string& query, vector<DomainInfo>* list, bool (*check_fcn)(u_int32_t,u_int32_t,SOAData*,DomainInfo*) ); 
    68         string escape( const string& str ); 
     66        string escape( const string& str, QueryType type ); 
     67        bool connectTo( const vector<string>& host, QueryType type ); 
     68        bool getDomainList( const string& query, vector<DomainInfo>* list, bool (*check_fcn)(u_int32_t,u_int32_t,SOAData*,DomainInfo*) ); 
     69        bool execStmt( const char* stmt, unsigned long length, QueryType type ); 
     70        bool getRecord( QueryType type ); 
    6971 
    7072 
     
    108110        { 
    109111                declare( suffix, "backend", "OpenDBX backend","mysql" ); 
    110                 declare( suffix, "host", "Name or address of one or more DBMS server","127.0.0.1" ); 
    111                 declare( suffix, "port", "Port the DBMS server is listening to","" ); 
     112                declare( suffix, "host-read", "Name or address of one or more DBMS server to read from","127.0.0.1" ); 
     113                declare( suffix, "host-write", "Name or address of one or more DBMS server used for updates","127.0.0.1" ); 
     114                declare( suffix, "port", "Port the DBMS server are listening to","" ); 
    112115                declare( suffix, "database", "Database name containing the DNS records","powerdns" ); 
    113116                declare( suffix, "username","User for connecting to the DBMS","powerdns"); 
    114117                declare( suffix, "password","Password for connecting to the DBMS",""); 
    115118 
    116                 declare( suffix, "sql-list", "AXFR query", "SELECT domain_id, name, type, ttl, prio, content FROM records WHERE domain_id=':id'" ); 
     119                declare( suffix, "sql-list", "AXFR query", "SELECT \"domain_id\", \"name\", \"type\", \"ttl\", \"prio\", \"content\" FROM \"records\" WHERE \"domain_id\"=:id" ); 
    117120 
    118                 declare( suffix, "sql-lookup", "Lookup query","SELECT domain_id, name, type, ttl, prio, content FROM records WHERE name=':name'" ); 
    119                 declare( suffix, "sql-lookupid", "Lookup query with id","SELECT domain_id, name, type, ttl, prio, content FROM records WHERE domain_id=':id' AND name=':name'" ); 
    120                 declare( suffix, "sql-lookuptype", "Lookup query with type","SELECT domain_id, name, type, ttl, prio, content FROM records WHERE name=':name' AND type=':type'" ); 
    121                 declare( suffix, "sql-lookuptypeid", "Lookup query with type and id","SELECT domain_id, name, type, ttl, prio, content FROM records WHERE domain_id=':id' AND name=':name' AND type=':type'" ); 
     121                declare( suffix, "sql-lookup", "Lookup query","SELECT \"domain_id\", \"name\", \"type\", \"ttl\", \"prio\", \"content\" FROM \"records\" WHERE \"name\"=':name'" ); 
     122                declare( suffix, "sql-lookupid", "Lookup query with id","SELECT \"domain_id\", \"name\", \"type\", \"ttl\", \"prio\", \"content\" FROM \"records\" WHERE \"domain_id\"=:id AND \"name\"=':name'" ); 
     123                declare( suffix, "sql-lookuptype", "Lookup query with type","SELECT \"domain_id\", \"name\", \"type\", \"ttl\", \"prio\", \"content\" FROM \"records\" WHERE \"name\"=':name' AND \"type\"=':type'" ); 
     124                declare( suffix, "sql-lookuptypeid", "Lookup query with type and id","SELECT \"domain_id\", \"name\", \"type\", \"ttl\", \"prio\", \"content\" FROM \"records\" WHERE \"domain_id\"=:id AND \"name\"=':name' AND \"type\"=':type'" ); 
    122125 
    123                 declare( suffix, "sql-zonedelete","Delete all records for this zone","DELETE FROM records WHERE domain_id=':id'" ); 
    124                 declare( suffix, "sql-zoneinfo","Get domain info","SELECT d.id, d.name, d.type, d.master, d.last_check, r.content FROM domains AS d LEFT JOIN records AS r ON d.id=r.domain_id WHERE ( d.name=':name' AND r.type='SOA' ) OR ( d.name=':name' AND r.domain_id IS NULL )" ); 
     126                declare( suffix, "sql-zonedelete","Delete all records for this zone","DELETE FROM \"records\" WHERE \"domain_id\"=:id" ); 
     127                declare( suffix, "sql-zoneinfo","Get domain info","SELECT d.\"id\", d.\"name\", d.\"type\", d.\"master\", d.\"last_check\", r.\"content\" FROM \"domains\" d LEFT JOIN \"records\" r ON ( d.\"id\"=r.\"domain_id\" AND r.\"type\"='SOA' ) WHERE d.\"name\"=':name' AND d.\"status\"='A'" ); 
    125128 
    126129                declare( suffix, "sql-transactbegin", "Start transaction", "BEGIN" ); 
     
    128131                declare( suffix, "sql-transactabort", "Abort transaction", "ROLLBACK" ); 
    129132 
    130                 declare( suffix, "sql-insert-slave","Add slave domain", "INSERT INTO domains ( name, type, master, account ) VALUES ( '%s', 'SLAVE', '%s', '%s' )" ); 
    131                 declare( suffix, "sql-insert-record","Feed record into table", "INSERT INTO records ( domain_id, name, type, ttl, prio, content ) VALUES ( '%d', '%s', '%s', '%d', '%d', '%s' )" ); 
     133                declare( suffix, "sql-insert-slave","Add slave domain", "INSERT INTO \"domains\" ( \"name\", \"type\", \"master\", \"account\" ) VALUES ( '%s', 'SLAVE', '%s', '%s' )" ); 
     134                declare( suffix, "sql-insert-record","Feed record into table", "INSERT INTO \"records\" ( \"domain_id\", \"name\", \"type\", \"ttl\", \"prio\", \"content\" ) VALUES ( %d, '%s', '%s', %d, %d, '%s' )" ); 
    132135 
    133                 declare( suffix, "sql-update-serial", "Set zone to notified", "UPDATE domains SET notified_serial='%d' WHERE id='%d'" ); 
    134                 declare( suffix, "sql-update-lastcheck", "Set time of last check", "UPDATE domains SET last_check='%d' WHERE id='%d'" ); 
     136                declare( suffix, "sql-update-serial", "Set zone to notified", "UPDATE \"domains\" SET \"notified_serial\"=%d WHERE \"id\"=%d" ); 
     137                declare( suffix, "sql-update-lastcheck", "Set time of last check", "UPDATE \"domains\" SET \"last_check\"=%d WHERE \"id\"=%d" ); 
    135138 
    136                 declare( suffix, "sql-master", "Get master record for zone", "SELECT master FROM domains WHERE name=':name' AND type='SLAVE'" ); 
    137                 declare( suffix, "sql-supermaster","Get supermaster info", "SELECT account FROM supermasters WHERE ip=':ip' AND nameserver=':ns'" ); 
     139                declare( suffix, "sql-master", "Get master record for zone", "SELECT \"master\" FROM \"domains\" WHERE \"name\"=':name' AND \"status\"='A' AND \"type\"='SLAVE'" ); 
     140                declare( suffix, "sql-supermaster","Get supermaster info", "SELECT \"account\" FROM \"supermasters\" WHERE \"ip\"=':ip' AND \"nameserver\"=':ns'" ); 
    138141 
    139                 declare( suffix, "sql-infoslaves", "Get all unfresh slaves", "SELECT d.id, d.name, d.master, d.notified_serial, d.last_check, r.change_date, r.content FROM domains AS d LEFT JOIN records AS r ON d.id=r.domain_id WHERE ( d.type='SLAVE' AND r.type='SOA' ) OR ( d.type='SLAVE' AND r.domain_id IS NULL )" ); 
    140                 declare( suffix, "sql-infomasters", "Get all updated masters", "SELECT d.id, d.name, d.master, d.notified_serial, d.last_check, r.change_date, r.content FROM domains AS d, records AS r WHERE d.type='MASTER' AND d.id=r.domain_id AND r.type='SOA'" ); 
     142                declare( suffix, "sql-infoslaves", "Get all unfresh slaves", "SELECT d.\"id\", d.\"name\", d.\"master\", d.\"notified_serial\", d.\"last_check\", r.\"change_date\", r.\"content\" FROM \"domains\" d LEFT JOIN \"records\" r ON ( d.\"id\"=r.\"domain_id\" AND r.\"type\"='SOA' ) WHERE d.\"status\"='A' AND d.\"type\"='SLAVE'" ); 
     143                declare( suffix, "sql-infomasters", "Get all updated masters", "SELECT d.\"id\", d.\"name\", d.\"master\", d.\"notified_serial\", d.\"last_check\", r.\"change_date\", r.\"content\" FROM \"domains\" d JOIN \"records\" r ON d.\"id\"=r.\"domain_id\" WHERE d.\"status\"='A' AND d.\"type\"='MASTER' AND r.\"type\"='SOA'" ); 
     144 
     145                declare( suffix, "host", "depricated, use host-read and host-write instead","" ); 
    141146        } 
    142147