Skip to content

Instantly share code, notes, and snippets.

@Habbie
Created April 26, 2013 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Habbie/5466770 to your computer and use it in GitHub Desktop.
Save Habbie/5466770 to your computer and use it in GitHub Desktop.
Index: oraclebackend.cc
===================================================================
--- oraclebackend.cc (revision 2674)
+++ oraclebackend.cc (working copy)
@@ -24,27 +24,43 @@
#include <oci.h>
static const char *basicQueryKey = "PDNS_Basic_Query";
-static const char *basicQueryDefaultSQL =
+static const char *basicQueryDefaultAuthSQL =
"SELECT fqdn, ttl, type, content, zone_id, last_change, auth "
"FROM Records "
"WHERE type = :type AND fqdn = lower(:name)";
+static const char *basicQueryDefaultSQL = "SELECT fqdn, ttl, type, content, zone_id, last_change "
+ "FROM Records "
+ "WHERE type = :type AND fqdn = lower(:name)";
+
static const char *basicIdQueryKey = "PDNS_Basic_Id_Query";
-static const char *basicIdQueryDefaultSQL =
+static const char *basicIdQueryDefaultAuthSQL =
"SELECT fqdn, ttl, type, content, zone_id, last_change, auth "
"FROM Records "
"WHERE type = :type AND fqdn = lower(:name) AND zone_id = :zoneid";
+static const char *basicIdQueryDefaultSQL =
+ "SELECT fqdn, ttl, type, content, zone_id, last_change "
+ "FROM Records "
+ "WHERE type = :type AND fqdn = lower(:name) AND zone_id = :zoneid";
+
static const char *anyQueryKey = "PDNS_ANY_Query";
-static const char *anyQueryDefaultSQL =
+static const char *anyQueryDefaultAuthSQL =
"SELECT fqdn, ttl, type, content, zone_id, last_change, auth "
"FROM Records "
"WHERE fqdn = lower(:name)"
" AND type IS NOT NULL "
"ORDER BY type";
+static const char *anyQueryDefaultSQL =
+ "SELECT fqdn, ttl, type, content, zone_id, last_change "
+ "FROM Records "
+ "WHERE fqdn = lower(:name)"
+ " AND type IS NOT NULL "
+ "ORDER BY type";
+
static const char *anyIdQueryKey = "PDNS_ANY_Id_Query";
-static const char *anyIdQueryDefaultSQL =
+static const char *anyIdQueryDefaultAuthSQL =
"SELECT fqdn, ttl, type, content, zone_id, last_change, auth "
"FROM Records "
"WHERE fqdn = lower(:name)"
@@ -52,14 +68,29 @@
" AND type IS NOT NULL "
"ORDER BY type";
+static const char *anyIdQueryDefaultSQL =
+ "SELECT fqdn, ttl, type, content, zone_id, last_change "
+ "FROM Records "
+ "WHERE fqdn = lower(:name)"
+ " AND zone_id = :zoneid"
+ " AND type IS NOT NULL "
+ "ORDER BY type";
+
static const char *listQueryKey = "PDNS_List_Query";
-static const char *listQueryDefaultSQL =
+static const char *listQueryDefaultAuthSQL =
"SELECT fqdn, ttl, type, content, zone_id, last_change, auth "
"FROM Records "
"WHERE zone_id = :zoneid"
" AND type IS NOT NULL "
"ORDER BY fqdn, type";
+static const char *listQueryDefaultSQL =
+ "SELECT fqdn, ttl, type, content, zone_id, last_change "
+ "FROM Records "
+ "WHERE zone_id = :zoneid"
+ " AND type IS NOT NULL "
+ "ORDER BY fqdn, type";
+
static const char *zoneInfoQueryKey = "PDNS_Zone_Info_Query";
static const char *zoneInfoQueryDefaultSQL =
"SELECT id, name, type, last_check, serial, notified_serial "
@@ -230,13 +261,32 @@
curStmtHandle = NULL;
openTransactionZoneID = -1;
+ try
+ {
+ d_dnssecQueries = mustDo("dnssec");
+ }
+ catch (ArgException e)
+ {
+ d_dnssecQueries = false;
+ }
+
// Process configuration options
string_to_cbuf(myServerName, getArg("nameserver-name"), sizeof(myServerName));
- basicQuerySQL = getArg("basic-query");
- basicIdQuerySQL = getArg("basic-id-query");
- anyQuerySQL = getArg("any-query");
- anyIdQuerySQL = getArg("any-id-query");
- listQuerySQL = getArg("list-query");
+
+ if (d_dnssecQueries) {
+ basicQuerySQL = getArg("basic-query-auth");
+ basicIdQuerySQL = getArg("basic-id-query-auth");
+ anyQuerySQL = getArg("any-query-auth");
+ anyIdQuerySQL = getArg("any-id-query-auth");
+ listQuerySQL = getArg("list-query-auth");
+ } else {
+ basicQuerySQL = getArg("basic-query");
+ basicIdQuerySQL = getArg("basic-id-query");
+ anyQuerySQL = getArg("any-query");
+ anyIdQuerySQL = getArg("any-id-query");
+ listQuerySQL = getArg("list-query");
+ }
+
zoneInfoQuerySQL = getArg("zone-info-query");
alsoNotifyQuerySQL = getArg("also-notify-query");
zoneMastersQuerySQL = getArg("zone-masters-query");
@@ -363,7 +413,6 @@
string_to_cbuf(mQueryName, qname, sizeof(mQueryName));
string_to_cbuf(mQueryType, qtype.getName(), sizeof(mQueryType));
mQueryZoneId = zoneId;
-
rc = OCIStmtExecute(pooledSvcCtx, curStmtHandle, oraerr, 1, 0, NULL, NULL, OCI_DEFAULT);
if (rc == OCI_ERROR) {
@@ -381,6 +430,9 @@
uint32_t zoneId, const string& zone,
const string& name, string& before, string& after)
{
+ if(!d_dnssecQueries)
+ return -1;
+
sword rc;
OCIStmt *stmt;
@@ -418,6 +470,9 @@
OracleBackend::getBeforeAndAfterNamesAbsolute(uint32_t zoneId,
const string& name, string& unhashed, string& before, string& after)
{
+ if(!d_dnssecQueries)
+ return -1;
+
sword rc;
OCIStmt *stmt;
@@ -904,15 +959,20 @@
check_indicator(mResultContentInd, false);
check_indicator(mResultZoneIdInd, false);
check_indicator(mResultLastChangeInd, false);
- check_indicator(mResultIsAuthInd, false);
+ if (d_dnssecQueries)
+ check_indicator(mResultIsAuthInd, false);
rr.qname = mResultName;
rr.ttl = mResultTTL;
rr.qtype = mResultType;
rr.domain_id = mResultZoneId;
rr.last_modified = mResultLastChange;
- rr.auth = mResultIsAuth > 0;
+ if (d_dnssecQueries)
+ rr.auth = mResultIsAuth > 0;
+ else
+ rr.auth = 1;
+
if ((rr.qtype.getCode() == QType::MX) || (rr.qtype.getCode() == QType::SRV)) {
unsigned priority = 0;
int skip = 0;
@@ -1163,6 +1223,11 @@
OracleBackend::getDomainMetadata (const string& name, const string& kind,
vector<string>& meta)
{
+ if(!d_dnssecQueries)
+ return -1;
+ DomainInfo di;
+ if (getDomainInfo(name, di) == false) return false;
+
sword rc;
OCIStmt *stmt;
@@ -1198,6 +1263,11 @@
OracleBackend::setDomainMetadata(const string& name, const string& kind,
const vector<string>& meta)
{
+ if(!d_dnssecQueries)
+ return -1;
+ DomainInfo di;
+ if (getDomainInfo(name, di) == false) return false;
+
sword rc;
OCIStmt *stmt;
@@ -1256,6 +1326,11 @@
bool
OracleBackend::getTSIGKey (const string& name, string* algorithm, string* content)
{
+ if(!d_dnssecQueries)
+ return -1;
+ DomainInfo di;
+ if (getDomainInfo(name, di) == false) return false;
+
sword rc;
OCIStmt *stmt;
@@ -1287,6 +1362,11 @@
bool
OracleBackend::getDomainKeys (const string& name, unsigned int kind, vector<KeyData>& keys)
{
+ if(!d_dnssecQueries)
+ return -1;
+ DomainInfo di;
+ if (getDomainInfo(name, di) == false) return false;
+
sword rc;
OCIStmt *stmt;
@@ -1336,6 +1416,11 @@
bool
OracleBackend::removeDomainKey (const string& name, unsigned int id)
{
+ if(!d_dnssecQueries)
+ return -1;
+ DomainInfo di;
+ if (getDomainInfo(name, di) == false) return false;
+
sword rc;
OCIStmt *stmt;
@@ -1370,6 +1455,11 @@
int
OracleBackend::addDomainKey (const string& name, const KeyData& key)
{
+ if(!d_dnssecQueries)
+ return -1;
+ DomainInfo di;
+ if (getDomainInfo(name, di) == false) return false;
+
sword rc;
OCIStmt *stmt;
@@ -1416,6 +1506,11 @@
bool
OracleBackend::setDomainKeyState (const string& name, unsigned int id, int active)
{
+ if(!d_dnssecQueries)
+ return -1;
+ DomainInfo di;
+ if (getDomainInfo(name, di) == false) return false;
+
sword rc;
OCIStmt *stmt;
@@ -1625,7 +1720,9 @@
mResultContent, sizeof(mResultContent));
define_output_int(s, 5, &mResultZoneIdInd, &mResultZoneId);
define_output_int(s, 6, &mResultLastChangeInd, &mResultLastChange);
- define_output_int(s, 7, &mResultIsAuthInd, &mResultIsAuth);
+
+ if (d_dnssecQueries)
+ define_output_int(s, 7, &mResultIsAuthInd, &mResultIsAuth);
}
void
@@ -1809,6 +1906,11 @@
sword err;
try {
+ //et some envionment variables
+ setenv("ORACLE_HOME", arg()["oracle-home"].c_str(), 1);
+ setenv("ORACLE_SID", arg()["oracle-sid"].c_str(), 1);
+ setenv("NLS_LANG", arg()["oracle-nls-lang"].c_str(), 1);
+
// Initialize and create the environment
err = OCIEnvCreate(&oraenv, OCI_THREADED, NULL, NULL,
NULL, NULL, 0, NULL);
@@ -1910,6 +2012,10 @@
}
void declareArguments (const string & suffix = "") {
+ declare(suffix,"home", "Oracle home path", "");
+ declare(suffix,"sid", "Oracle sid", "XE");
+ declare(suffix,"nls-lang", "Oracle language", "AMERICAN_AMERICA.AL32UTF8");
+
declare(suffix, "pool-database", "Database to connect to for the session pool", "powerdns");
declare(suffix, "pool-username", "Username to connect as for the session pool", "powerdns");
declare(suffix, "pool-password", "Password to connect with for the session pool", "");
@@ -1919,14 +2025,19 @@
declare(suffix, "master-database", "Database to connect to for write access", "powerdns");
declare(suffix, "master-username", "Username to connect as for write access", "powerdns");
declare(suffix, "master-password", "Password to connect with for write access", "");
-
+ declare(suffix, "dnssec", "Assume DNSSEC Schema is in place", "no");
declare(suffix, "nameserver-name", "", "");
declare(suffix, "basic-query", "", basicQueryDefaultSQL);
+ declare(suffix, "basic-query-auth", "", basicQueryDefaultAuthSQL);
declare(suffix, "basic-id-query", "", basicIdQueryDefaultSQL);
+ declare(suffix, "basic-id-query-auth", "", basicIdQueryDefaultAuthSQL);
declare(suffix, "any-query", "", anyQueryDefaultSQL);
+ declare(suffix, "any-query-auth", "", anyQueryDefaultAuthSQL);
declare(suffix, "any-id-query", "", anyIdQueryDefaultSQL);
+ declare(suffix, "any-id-query-auth", "", anyIdQueryDefaultAuthSQL);
declare(suffix, "list-query", "", listQueryDefaultSQL);
+ declare(suffix, "list-query-auth", "", listQueryDefaultAuthSQL);
declare(suffix, "zone-info-query", "", zoneInfoQueryDefaultSQL);
declare(suffix, "also-notify-query", "", alsoNotifyQueryDefaultSQL);
declare(suffix, "zone-masters-query", "", zoneMastersQueryDefaultSQL);
Index: oraclebackend.hh
===================================================================
--- oraclebackend.hh (revision 2674)
+++ oraclebackend.hh (working copy)
@@ -164,6 +164,7 @@
sb2 mResultPrevNameInd;
char mResultNextName[512];
sb2 mResultNextNameInd;
+ bool d_dnssecQueries;
void Cleanup();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment