]> git.ipfire.org Git - thirdparty/pdns.git/blob - modules/oraclebackend/oraclebackend.hh
use DNSName for before and afternames in the other backends
[thirdparty/pdns.git] / modules / oraclebackend / oraclebackend.hh
1 /*
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
4 * originally authored by Maik Zumstrull
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
9 *
10 * In addition, for the avoidance of any doubt, permission is granted to
11 * link this program with OpenSSL and to (re)distribute the binaries
12 * produced as the result of such linking.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 */
23 #ifndef PDNS_ORACLEBACKEND_HH
24 #define PDNS_ORACLEBACKEND_HH
25
26 #include <string>
27 #include <map>
28 #include <fstream>
29
30 #include <oci.h>
31
32 #include "pdns/namespaces.hh"
33
34 class OracleException : public DBException
35 {
36 public:
37
38 OracleException (string r) : DBException(r) {}
39
40 OracleException (string context, OCIError *theErrorHandle)
41 : DBException(context + ": ORA-UNKNOWN")
42 {
43 if (theErrorHandle != NULL) {
44 char msg[2048];
45 sb4 errcode = 0;
46
47 msg[0] = '\0';
48
49 OCIErrorGet((void *) theErrorHandle, 1, NULL, &errcode, (OraText*) msg,
50 sizeof(msg), OCI_HTYPE_ERROR);
51
52 reason = context + ": " + msg;
53 }
54 }
55
56 };
57
58 class OracleBackend : public DNSBackend
59 {
60 public:
61
62 OracleBackend(const string &suffix = "", OCIEnv *envh =
63 NULL, char *poolname = NULL);
64 virtual ~OracleBackend();
65
66 void lookup(const QType &qtype, const DNSName& qname, DNSPacket *p = 0,
67 int zoneId = -1);
68
69 bool getBeforeAndAfterNames(uint32_t zoneId, const DNSName& zone,
70 const DNSName& name,
71 DNSName& before, DNSName& after);
72 bool getBeforeAndAfterNamesAbsolute(uint32_t zoneId,
73 const DNSName& name,
74 DNSName& unhashed,
75 DNSName& before,
76 DNSName& after);
77 bool get(DNSResourceRecord &rr);
78 vector<string> getDomainMasters(const DNSName& domain, int zoneId);
79 bool isMaster(const DNSName& domain, const string &master);
80 bool getDomainInfo(const DNSName& domain, DomainInfo &di);
81 void alsoNotifies(const DNSName& domain, set<string> *addrs);
82 void getUnfreshSlaveInfos(vector<DomainInfo>* domains);
83 void getUpdatedMasters(vector<DomainInfo>* domains);
84 void setFresh(uint32_t zoneId);
85 void setNotified(uint32_t zoneId, uint32_t serial);
86 bool list(const DNSName& domain, int zoneId, bool include_disabled=false);
87 bool startTransaction(const DNSName& domain, int zoneId);
88 bool feedRecord(const DNSResourceRecord &rr, string* ordername);
89 bool commitTransaction();
90 bool abortTransaction();
91 bool superMasterBackend(const string &ip, const DNSName& domain,
92 const vector<DNSResourceRecord> &nsset,
93 string *account, string *nameserver,
94 DNSBackend **backend);
95 bool createSlaveDomain(const string &ip, const DNSName& domain,
96 const string &nameserver, const string &account);
97
98 bool getAllDomainMetadata(const DNSName& name, std::map<std::string, std::vector<std::string> >& meta);
99 bool getDomainMetadata(const DNSName& name, const std::string& kind, std::vector<std::string>& meta);
100 bool setDomainMetadata(const DNSName& name, const std::string& kind, const std::vector<std::string>& meta);
101
102 bool getTSIGKey(const DNSName& name, DNSName* algorithm, string* content);
103 bool delTSIGKey(const DNSName& name);
104 bool setTSIGKey(const DNSName& name, const DNSName& algorithm, const string& content);
105 bool getTSIGKeys(std::vector< struct TSIGKey > &keys);
106
107 bool getDomainKeys(const DNSName& name, unsigned int kind, vector<KeyData>& keys);
108 bool removeDomainKey(const DNSName& name, unsigned int id);
109 bool addDomainKey(const DNSName& name, const KeyData& key, int64_t& id);
110 bool activateDomainKey(const DNSName& name, unsigned int id);
111 bool deactivateDomainKey(const DNSName& name, unsigned int id);
112
113 private:
114
115 OCIEnv *oraenv;
116 OCIError *oraerr;
117 OCISvcCtx *pooledSvcCtx;
118 OCIAuthInfo *masterAuthHandle;
119 OCISvcCtx *masterSvcCtx;
120
121 string basicQuerySQL;
122 string basicIdQuerySQL;
123 string anyQuerySQL;
124 string anyIdQuerySQL;
125 string listQuerySQL;
126
127 string zoneInfoQuerySQL;
128 string alsoNotifyQuerySQL;
129 string zoneMastersQuerySQL;
130 string isZoneMasterQuerySQL;
131 string deleteZoneQuerySQL;
132 string zoneSetLastCheckQuerySQL;
133
134 string insertRecordQuerySQL;
135 string finalizeAXFRQuerySQL;
136
137 string unfreshZonesQuerySQL;
138 string updatedMastersQuerySQL;
139 string acceptSupernotificationQuerySQL;
140 string insertSlaveQuerySQL;
141 string insertMasterQuerySQL;
142 string zoneSetNotifiedSerialQuerySQL;
143
144 string prevNextNameQuerySQL;
145 string prevNextHashQuerySQL;
146
147 string getAllZoneMetadataQuerySQL;
148 string getZoneMetadataQuerySQL;
149 string delZoneMetadataQuerySQL;
150 string setZoneMetadataQuerySQL;
151
152 string getTSIGKeyQuerySQL;
153 string delTSIGKeyQuerySQL;
154 string setTSIGKeyQuerySQL;
155 string getTSIGKeysQuerySQL;
156
157 string getZoneKeysQuerySQL;
158 string delZoneKeyQuerySQL;
159 string addZoneKeyQuerySQL;
160 string setZoneKeyStateQuerySQL;
161
162 OCIStmt *curStmtHandle;
163 const char *curStmtKey;
164 int openTransactionZoneID;
165
166 char myServerName[512];
167
168 char mQueryName[512];
169 char mQueryType[64];
170 char mQueryContent[4001];
171 char mQueryZone[512];
172 char mQueryAddr[64];
173 int mQueryZoneId;
174 int mQueryTimestamp;
175
176 char mResultName[512];
177 sb2 mResultNameInd;
178 uint32_t mResultTTL;
179 sb2 mResultTTLInd;
180 char mResultType[64];
181 sb2 mResultTypeInd;
182 char mResultContent[4001];
183 sb2 mResultContentInd;
184 int mResultZoneId;
185 sb2 mResultZoneIdInd;
186 int mResultLastChange;
187 sb2 mResultLastChangeInd;
188 int mResultIsAuth;
189 sb2 mResultIsAuthInd;
190 char mResultPrevName[512];
191 sb2 mResultPrevNameInd;
192 char mResultNextName[512];
193 sb2 mResultNextNameInd;
194 bool d_dnssecQueries;
195
196 void Cleanup();
197
198 void openMasterConnection();
199 bool setDomainKeyState(const DNSName& name, unsigned int id, int active);
200
201 OCIStmt* prepare_query (OCISvcCtx* orasvc, string& code, const char *key);
202 void release_query (OCIStmt *stmt, const char *key);
203 void define_output_str (OCIStmt *s, ub4 pos, sb2 *ind, char *buf, sb4 buflen);
204 void define_output_int (OCIStmt *s, ub4 pos, sb2 *ind, int *buf);
205 void define_output_uint (OCIStmt *s, ub4 pos, sb2 *ind, unsigned int *buf);
206 void define_output_uint16 (OCIStmt *s, ub4 pos, sb2 *ind, uint16_t *buf);
207 void define_output_uint32 (OCIStmt *s, ub4 pos, sb2 *ind, uint32_t *buf);
208 void check_indicator (sb2 ind, bool null_okay);
209 void define_fwd_query (OCIStmt *s);
210 void bind_str (OCIStmt *s, const char *name, char *buf, sb4 buflen);
211 void bind_str_failokay (OCIStmt *s, const char *name, char *buf, sb4 buflen);
212 void bind_str_ind (OCIStmt *s, const char *name, char *buf, sb4 buflen, sb2 *ind);
213 void bind_int (OCIStmt *s, const char *name, int *buf);
214 void bind_uint (OCIStmt *s, const char *name, unsigned int *buf);
215 void bind_uint16 (OCIStmt *s, const char *name, uint16_t *buf);
216 void bind_uint16_ind (OCIStmt *s, const char *name, uint16_t *buf, sb2 *ind);
217 void bind_uint32 (OCIStmt *s, const char *name, uint32_t *buf);
218
219 };
220
221 #endif /* PDNS_ORACLEBACKEND_HH */