]>
Commit | Line | Data |
---|---|---|
c3cf76c4 BH |
1 | |
2 | #include <string> | |
3 | #include <map> | |
917a9be8 | 4 | #include "pdns/namespaces.hh" |
c3cf76c4 BH |
5 | #include "pdns/dns.hh" |
6 | #include "pdns/dnsbackend.hh" | |
c3cf76c4 BH |
7 | #include "pdns/dnspacket.hh" |
8 | #include "pdns/ueberbackend.hh" | |
5c409fa2 | 9 | #include "pdns/pdnsexception.hh" |
c3cf76c4 BH |
10 | #include "pdns/logger.hh" |
11 | #include "pdns/arguments.hh" | |
c9245417 | 12 | #include "goraclebackend.hh" |
c3cf76c4 | 13 | #include "soracle.hh" |
c3cf76c4 BH |
14 | #include <sstream> |
15 | ||
aac4f445 | 16 | gOracleBackend::gOracleBackend(const string &mode, const string &suffix) : GSQLBackend(mode, suffix) |
c3cf76c4 BH |
17 | { |
18 | try { | |
aac4f445 | 19 | // set Oracle envionment variables |
8ac0c064 PD |
20 | setenv("ORACLE_HOME", getArg("home").c_str(), 1); |
21 | setenv("ORACLE_SID", getArg("sid").c_str(), 1); | |
22 | setenv("NLS_LANG", getArg("nls-lang").c_str(), 1); | |
6ee1e085 | 23 | |
c5020d07 | 24 | setDB(new SOracle(getArg("tnsname"), |
6ee1e085 KM |
25 | getArg("user"), |
26 | getArg("password"))); | |
27 | ||
c3cf76c4 | 28 | } |
c9245417 | 29 | |
6ee1e085 | 30 | catch (SSqlException &e) { |
aac4f445 KM |
31 | L<<Logger::Error << mode << " Connection failed: " << e.txtReason() << endl; |
32 | throw PDNSException("Unable to launch " + mode + " connection: " + e.txtReason()); | |
c3cf76c4 | 33 | } |
aac4f445 | 34 | L<<Logger::Info << mode << " Connection successful" << endl; |
c3cf76c4 BH |
35 | } |
36 | ||
aac4f445 KM |
37 | |
38 | string gOracleBackend::sqlEscape(const string &name) | |
39 | { | |
40 | return boost::replace_all_copy(name, "'", "''"); | |
41 | } | |
42 | ||
43 | ||
c3cf76c4 BH |
44 | class gOracleFactory : public BackendFactory |
45 | { | |
46 | public: | |
aac4f445 | 47 | gOracleFactory(const string &mode) : BackendFactory(mode), d_mode(mode) {} |
c9245417 | 48 | |
6ee1e085 | 49 | void declareArguments(const string &suffix="") { |
8ac0c064 PD |
50 | declare(suffix,"home", "Oracle home path", ""); |
51 | declare(suffix,"sid", "Oracle sid", "XE"); | |
52 | declare(suffix,"nls-lang", "Oracle language", "AMERICAN_AMERICA.AL32UTF8"); | |
53 | ||
c5020d07 | 54 | declare(suffix,"tnsname","Generic Oracle backend TNSNAME to connect to","powerdns"); |
c3cf76c4 | 55 | declare(suffix,"user","Database backend user to connect as","powerdns"); |
c3cf76c4 | 56 | declare(suffix,"password","Pdns backend password to connect with",""); |
c9245417 | 57 | |
fe6c17e1 | 58 | declare(suffix,"dnssec","Enable DNSSEC processing","no"); |
c3cf76c4 | 59 | |
fe6c17e1 | 60 | string record_query = "SELECT content,ttl,prio,type,domain_id,disabled,name,auth FROM records WHERE"; |
c3cf76c4 | 61 | |
cea26350 CH |
62 | declare(suffix, "basic-query", "Basic query", record_query+" disabled=0 and type='%s' and name='%s'"); |
63 | declare(suffix, "id-query", "Basic with ID query", record_query+" disabled=0 and type='%s' and name='%s' and domain_id=%d"); | |
cea26350 CH |
64 | declare(suffix, "any-query", "Any query", record_query+" disabled=0 and name='%s'"); |
65 | declare(suffix, "any-id-query", "Any with ID query", record_query+" disabled=0 and name='%s' and domain_id=%d"); | |
3d766f44 | 66 | |
fe6c17e1 | 67 | declare(suffix, "list-query", "AXFR query", record_query+" (disabled=0 OR 1=%d) and domain_id='%d' order by name, type"); |
cea26350 | 68 | declare(suffix, "list-subzone-query", "Subzone listing", record_query+" disabled=0 and (name='%s' OR name like '%s') and domain_id='%d'"); |
9118638d | 69 | |
fe6c17e1 KM |
70 | declare(suffix, "remove-empty-non-terminals-from-zone-query", "remove all empty non-terminals from zone", "delete from records where domain_id='%d' and type is null"); |
71 | declare(suffix, "insert-empty-non-terminal-query", "insert empty non-terminal in zone", "insert into records (id,domain_id,name,type,disabled,auth) values (records_id_sequence.nextval,'%d','%s',null,0,'1')"); | |
9118638d | 72 | declare(suffix,"delete-empty-non-terminal-query", "delete empty non-terminal from zone", "delete from records where domain_id='%d' and name='%s' and type is null"); |
c9245417 | 73 | |
c3cf76c4 BH |
74 | declare(suffix,"master-zone-query","Data", "select master from domains where name='%s' and type='SLAVE'"); |
75 | ||
76 | declare(suffix,"info-zone-query","","select id,name,master,last_check,notified_serial,type from domains where name='%s'"); | |
77 | ||
78 | declare(suffix,"info-all-slaves-query","","select id,name,master,last_check,type from domains where type='SLAVE'"); | |
79 | declare(suffix,"supermaster-query","", "select account from supermasters where ip='%s' and nameserver='%s'"); | |
52569c4e | 80 | declare(suffix,"supermaster-name-to-ips", "", "select ip from supermasters where nameserver='%s'"); |
d3568cf9 | 81 | |
487cf033 | 82 | declare(suffix,"insert-zone-query","", "insert into domains (id, type, name) values(domain_id_sequence.nextval, 'NATIVE','%s')"); |
c9245417 CH |
83 | declare(suffix,"insert-slave-query","", "insert into domains (id, type,name,master,account) values(domain_id_sequence.nextval, 'SLAVE','%s','%s','%s')"); |
84 | ||
fe6c17e1 KM |
85 | declare(suffix, "insert-record-query", "", "insert into records (id, content,ttl,prio,type,domain_id,disabled,name,auth) values (records_id_sequence.nextval, '%s',%d,%d,'%s',%d,%d,'%s','%d')"); |
86 | declare(suffix, "insert-record-order-query", "", "insert into records (id, content,ttl,prio,type,domain_id,disabled,name,ordername,auth) values (records_id_sequence.nextval, '%s',%d,%d,'%s',%d,%d,'%s','%s ','%d')"); | |
87 | declare(suffix, "insert-ent-query", "insert empty non-terminal in zone", "insert into records (id, type,domain_id,disabled,name,auth) values (records_id_sequence.nextval, null,'%d',0,'%s','%d')"); | |
88 | declare(suffix, "insert-ent-order-query", "insert empty non-terminal in zone", "insert into records (id, type,domain_id,disabled,name,ordername,auth) values (records_id_sequence.nextval, null,'%d',0,'%s','%s','%d')"); | |
520ecce3 | 89 | |
cea26350 CH |
90 | declare(suffix, "get-order-first-query", "DNSSEC Ordering Query, first", "select trim(ordername),name from records where disabled=0 and domain_id=%d and ordername is not null and rownum=1 order by ordername asc"); |
91 | declare(suffix, "get-order-before-query", "DNSSEC Ordering Query, before", "select trim(ordername), name from records where disabled=0 and ordername <= '%s ' and domain_id=%d and ordername is not null and rownum=1 order by ordername desc"); | |
92 | declare(suffix, "get-order-after-query", "DNSSEC Ordering Query, after", "select trim(min(ordername)) from records where disabled=0 and ordername > '%s ' and domain_id=%d and ordername is not null"); | |
93 | declare(suffix, "get-order-last-query", "DNSSEC Ordering Query, last", "select trim(ordername), name from records where disabled=0 and ordername != ' ' and domain_id=%d and ordername is not null and rownum=1 order by ordername desc"); | |
94 | declare(suffix, "set-order-and-auth-query", "DNSSEC set ordering query", "update records set ordername='%s ',auth=%d where name='%s' and domain_id='%d' and disabled=0"); | |
95 | declare(suffix, "set-auth-on-ds-record-query", "DNSSEC set auth on a DS record", "update records set auth=1 where domain_id='%d' and name='%s' and type='DS' and disabled=0"); | |
c9245417 | 96 | |
cea26350 CH |
97 | declare(suffix, "nullify-ordername-and-update-auth-query", "DNSSEC nullify ordername and update auth query", "update records set ordername=NULL,auth=%d where domain_id='%d' and name='%s' and disabled=0"); |
98 | declare(suffix, "nullify-ordername-and-auth-query", "DNSSEC nullify ordername and auth query", "update records set ordername=NULL,auth=0 where name='%s' and type='%s' and domain_id='%d' and disabled=0"); | |
9118638d | 99 | |
c02f13ef CH |
100 | declare(suffix,"update-master-query","", "update domains set master='%s' where name='%s'"); |
101 | declare(suffix,"update-kind-query","", "update domains set type='%s' where name='%s'"); | |
c3cf76c4 BH |
102 | declare(suffix,"update-serial-query","", "update domains set notified_serial=%d where id=%d"); |
103 | declare(suffix,"update-lastcheck-query","", "update domains set last_check=%d where id=%d"); | |
72d3c816 | 104 | declare(suffix,"zone-lastchange-query", "", "select max(change_date) from records where domain_id=%d"); |
c3cf76c4 | 105 | declare(suffix,"info-all-master-query","", "select id,name,master,last_check,notified_serial,type from domains where type='MASTER'"); |
09d6667a | 106 | declare(suffix,"delete-domain-query","", "delete from domains where name='%s'"); |
c3cf76c4 | 107 | declare(suffix,"delete-zone-query","", "delete from records where domain_id=%d"); |
9118638d | 108 | declare(suffix,"delete-rrset-query","","delete from records where domain_id=%d and name='%s' and type='%s'"); |
98d47e2e | 109 | declare(suffix,"delete-names-query","","delete from records where domain_id=%d and name='%s'"); |
c9245417 | 110 | |
9118638d PD |
111 | declare(suffix,"add-domain-key-query","", "insert into cryptokeys (id, domain_id, flags, active, content) select cryptokeys_id_sequence.nextval, id, %d, %d, '%s' from domains where name='%s'"); |
112 | declare(suffix,"list-domain-keys-query","", "select cryptokeys.id, flags, active, content from domains, cryptokeys where cryptokeys.domain_id=domains.id and name='%s'"); | |
b35f74f0 | 113 | declare(suffix,"get-all-domain-metadata-query","", "select kind,content from domains, domainmetadata where domainmetadata.domain_id=domains.id and name='%s'"); |
9118638d PD |
114 | declare(suffix,"get-domain-metadata-query","", "select content from domains, domainmetadata where domainmetadata.domain_id=domains.id and name='%s' and domainmetadata.kind='%s'"); |
115 | declare(suffix,"clear-domain-metadata-query","", "delete from domainmetadata where domain_id=(select id from domains where name='%s') and domainmetadata.kind='%s'"); | |
09d6667a | 116 | declare(suffix,"clear-domain-all-metadata-query","", "delete from domainmetadata where domain_id=(select id from domains where name='%s')"); |
3dcc5ccf | 117 | declare(suffix,"set-domain-metadata-query","", "insert into domainmetadata (id, domain_id, kind, content) select domainmetadata_id_sequence.nextval, id, '%s', '%s' from domains where name='%s'"); |
9118638d PD |
118 | declare(suffix,"activate-domain-key-query","", "update cryptokeys set active=1 where domain_id=(select id from domains where name='%s') and cryptokeys.id=%d"); |
119 | declare(suffix,"deactivate-domain-key-query","", "update cryptokeys set active=0 where domain_id=(select id from domains where name='%s') and cryptokeys.id=%d"); | |
c9245417 | 120 | declare(suffix,"remove-domain-key-query","", "delete from cryptokeys where domain_id=(select id from domains where name='%s') and cryptokeys.id=%d"); |
09d6667a | 121 | declare(suffix,"clear-domain-all-keys-query","", "delete from cryptokeys where domain_id=(select id from domains where name='%s')"); |
9118638d | 122 | declare(suffix,"get-tsig-key-query","", "select algorithm, secret from tsigkeys where name='%s'"); |
3dcc5ccf | 123 | declare(suffix,"set-tsig-key-query","", "insert into tsigkeys (id,name,algorithm,secret) VALUES(tsigkeys_id_sequence.nextval,'%s','%s','%s')"); |
99b63689 AT |
124 | declare(suffix,"delete-tsig-key-query","", "delete from tsigkeys where name='%s'"); |
125 | declare(suffix,"get-tsig-keys-query","", "select name,algorithm, secret from tsigkeys"); | |
9118638d | 126 | |
4de11a54 | 127 | declare(suffix, "get-all-domains-query", "Retrieve all domains", "select domains.id, domains.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check from domains LEFT JOIN records ON records.domain_id=domains.id AND records.type='SOA' AND records.name=domains.name WHERE records.disabled=0 OR 1=%d"); |
6cc98ddf | 128 | |
822fda9a KM |
129 | declare(suffix, "list-comments-query", "", "SELECT domain_id,name,type,modified_at,account,\"comment\" FROM comments WHERE domain_id=%d"); |
130 | declare(suffix, "insert-comment-query", "", "INSERT INTO comments (id, domain_id, name, type, modified_at, account, \"comment\") VALUES (comments_id_sequence.nextval, %d, '%s', '%s', %d, '%s', '%s')"); | |
6cc98ddf CH |
131 | declare(suffix, "delete-comment-rrset-query", "", "DELETE FROM comments WHERE domain_id=%d AND name='%s' AND type='%s'"); |
132 | declare(suffix, "delete-comments-query", "", "DELETE FROM comments WHERE domain_id=%d"); | |
c3cf76c4 | 133 | } |
c9245417 | 134 | |
6ee1e085 | 135 | DNSBackend* make(const string &suffix="") { |
c3cf76c4 BH |
136 | return new gOracleBackend(d_mode,suffix); |
137 | } | |
aac4f445 | 138 | |
c3cf76c4 BH |
139 | private: |
140 | const string d_mode; | |
141 | }; | |
142 | ||
143 | ||
144 | //! Magic class that is activated when the dynamic library is loaded | |
145 | class gOracleLoader | |
146 | { | |
147 | public: | |
148 | //! This reports us to the main UeberBackend class | |
6ee1e085 | 149 | gOracleLoader() { |
c3cf76c4 | 150 | BackendMakers().report(new gOracleFactory("goracle")); |
aac4f445 | 151 | L<<Logger::Warning<<"This is module goraclebackend reporting"<<endl; |
c3cf76c4 BH |
152 | } |
153 | }; | |
aac4f445 KM |
154 | |
155 | //! Reports the backendloader to the UeberBackend. | |
c3cf76c4 | 156 | static gOracleLoader goracleloader; |