~ubuntu-branches/ubuntu/maverick/pdns/maverick-updates

« back to all changes in this revision

Viewing changes to modules/opendbxbackend/odbxbackend.hh

  • Committer: Bazaar Package Importer
  • Author(s): Matthijs Mohlmann, Matthijs Mohlmann, Christoph Haas
  • Date: 2007-04-15 23:23:39 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070415232339-5x3scc8gx04e50um
Tags: 2.9.21-1
[ Matthijs Mohlmann ]
* New upstream release. (Closes: #420294)
* Remove meta pdns package.
* Added new sqlite3 backend package.
* Months and minutes where mixed up. (Closes: #406462)
* Case sensitivity in bind backend caused PowerDNS to not serve a certain
  zone. (Closes: #406461)
* Bind backend forgot about zones on a notify. (Closes: #398213)

[ Christoph Haas ]
* Documented incorporated backend bind. (Closes: #415471)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *  PowerDNS OpenDBX Backend
3
 
 *  Copyright (C) 2005 Norbert Sendetzky <norbert@linuxnetworks.de>
 
3
 *  Copyright (C) 2005-2007 Norbert Sendetzky <norbert@linuxnetworks.de>
4
4
 *
5
5
 *  This program is free software; you can redistribute it and/or modify
6
 
 *  it under the terms of the GNU General Public License as published by
7
 
 *  the Free Software Foundation; either version 2 of the License, or
8
 
 *  any later version.
 
6
 *  it under the terms of the GNU General Public License version 2
 
7
 *  as published by the Free Software Foundation
9
8
 *
10
9
 *  This program is distributed in the hope that it will be useful,
11
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
13
 *
15
14
 *  You should have received a copy of the GNU General Public License
16
15
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
17
 */
19
18
 
20
19
 
32
31
#include <pdns/arguments.hh>
33
32
#include <pdns/logger.hh>
34
33
#include <odbx.h>
35
 
#include "modules/ldapbackend/utils.hh"
36
34
 
37
35
 
38
36
#ifndef ODBXBACKEND_HH
53
51
 
54
52
class OdbxBackend : public DNSBackend
55
53
{
 
54
        enum QueryType { READ, WRITE };
 
55
 
56
56
        string m_myname;
57
57
        string m_qname;
58
58
        int m_default_ttl;
59
59
        bool m_qlog;
60
 
        odbx_t* m_handle;
 
60
        odbx_t* m_handle[2];
61
61
        odbx_result_t* m_result;
62
62
        char m_escbuf[BUFLEN];
63
63
        char m_buffer[2*BUFLEN];
 
64
        vector<string> m_hosts[2];
64
65
 
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 );
69
71
 
70
72
 
71
73
public:
107
109
        void declareArguments( const string &suffix="" )
108
110
        {
109
111
                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","" );
112
115
                declare( suffix, "database", "Database name containing the DNS records","powerdns" );
113
116
                declare( suffix, "username","User for connecting to the DBMS","powerdns");
114
117
                declare( suffix, "password","Password for connecting to the DBMS","");
115
118
 
116
 
                declare( suffix, "sql-list", "AXFR query", "SELECT domain_id, name, type, ttl, prio, content FROM records WHERE domain_id=':id'" );
117
 
 
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'" );
122
 
 
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 )" );
 
119
                declare( suffix, "sql-list", "AXFR query", "SELECT \"domain_id\", \"name\", \"type\", \"ttl\", \"prio\", \"content\" FROM \"records\" WHERE \"domain_id\"=:id" );
 
120
 
 
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'" );
 
125
 
 
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'" );
125
128
 
126
129
                declare( suffix, "sql-transactbegin", "Start transaction", "BEGIN" );
127
130
                declare( suffix, "sql-transactend", "Finish transaction", "COMMIT" );
128
131
                declare( suffix, "sql-transactabort", "Abort transaction", "ROLLBACK" );
129
132
 
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' )" );
132
 
 
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'" );
135
 
 
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'" );
138
 
 
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'" );
 
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' )" );
 
135
 
 
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" );
 
138
 
 
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'" );
 
141
 
 
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","" );
141
146
        }
142
147
 
143
148