]> granicus.if.org Git - pdns/commitdiff
Style fixes and now does REPLACE instead of INSERT
authorAki Tuomi <cmouse@desteem.org>
Sat, 15 Jun 2013 14:51:44 +0000 (17:51 +0300)
committerAki Tuomi <cmouse@desteem.org>
Tue, 3 Sep 2013 15:20:21 +0000 (18:20 +0300)
modules/oraclebackend/oraclebackend.cc
modules/remotebackend/test-remotebackend.cc

index 15bf68f02582e49a969b830bbdca45a27a1f94de..c216cdff3053a546e7f42441bf8841e197091a08 100644 (file)
@@ -239,11 +239,21 @@ static const char *setZoneKeyStateQueryDefaultSQL =
   "UPDATE ZoneDNSKeys SET active = :active WHERE id = :keyid";
 
 static const char *setTSIGKeyQueryKey = "PDNS_Set_TSIG_Key";
-static const char *setTSIGKeyQueryDefaultSQL = "insert into tsigkeys (name,algorithm,secret) values(:name,:algorithm,:secret)";
+static const char *setTSIGKeyQueryDefaultSQL = 
+  "INSERT INTO TSIGKeys (name,algorithm,secret)"
+  "VALUES("
+  ":name,"
+  ":algorithm,"
+  ":secret"
+  ")";
 static const char *deleteTSIGKeyQueryKey = "PDNS_Delete_TSIG_Key";
-static const char *deleteTSIGKeyQueryDefaultSQL = "delete from tsigkeys where name=:name";
+static const char *deleteTSIGKeyQueryDefaultSQL = 
+  "DELETE FROM TSIGKeys "
+  "WHERE name = :name";
 static const char *getTSIGKeysQueryKey = "PDNS_Get_TSIG_Keys";
-static const char *getTSIGKeysQueryDefaultSQL = "select name,algorithm,secret from tsigkeys";
+static const char *getTSIGKeysQueryDefaultSQL =   
+  "SELECT name, algorithm, secret "
+  "FROM TSIGKeys";
 
 static void
 string_to_cbuf (char *buf, const string& s, size_t bufsize)
@@ -1376,7 +1386,25 @@ OracleBackend::setTSIGKey(const string& name, const string& algorithm, const str
   if(!d_dnssecQueries)
     return -1;
 
-  stmt = prepare_query(pooledSvcCtx, setTSIGKeyQuerySQL, setTSIGKeyQueryKey);
+  sword rc;
+  OCIStmt *stmt;
+
+  openMasterConnection();
+
+  rc = OCITransStart(masterSvcCtx, oraerr, 60, OCI_TRANS_NEW);
+
+  stmt = prepare_query(masterSvcCtx, deleteTSIGKeyQuerySQL, deleteTSIGKeyQueryKey);
+  string_to_cbuf(mQueryName, name, sizeof(mQueryName));
+  bind_str(stmt, ":name", mQueryName, sizeof(mQueryName));
+
+  rc = OCIStmtExecute(masterSvcCtx, stmt, oraerr, 1, 0, NULL, NULL, OCI_DEFAULT);
+  if (rc == OCI_ERROR) {
+    throw OracleException("Oracle setTSIGKey", oraerr);
+  }
+
+  release_query(stmt, setTSIGKeyQueryKey);
+
+  stmt = prepare_query(masterSvcCtx, setTSIGKeyQuerySQL, setTSIGKeyQueryKey);
   string_to_cbuf(mQueryName, name, sizeof(mQueryName));
   string_to_cbuf(mQueryType, type, sizeof(mQueryType));
   string_to_cbuf(mQueryContent, content, sizeof(mQueryContent));
@@ -1385,12 +1413,18 @@ OracleBackend::setTSIGKey(const string& name, const string& algorithm, const str
   bind_str(stmt, ":algorithm", mQueryType, sizeof(mQueryType));
   bind_str(stmt, ":secret", mQueryContent, sizeof(mQueryContent));
 
-  rc = OCIStmtExecute(pooledSvcCtx, stmt, oraerr, 1, 0, NULL, NULL, OCI_DEFAULT);
+  rc = OCIStmtExecute(masterSvcCtx, stmt, oraerr, 1, 0, NULL, NULL, OCI_DEFAULT);
   if (rc == OCI_ERROR) {
-    throw OracleException("Oracle getTSIGKey", oraerr);
+    throw OracleException("Oracle setTSIGKey", oraerr);
   }
 
   release_query(stmt, setTSIGKeyQueryKey);
+
+  rc = OCITransCommit(masterSvcCtx, oraerr, OCI_DEFAULT);
+  if (rc == OCI_ERROR) {
+    throw OracleException("Oracle setTSIGKey COMMIT", oraerr);
+  }
+
   return true;
 }
 
@@ -1400,16 +1434,27 @@ OracleBackend::deleteTSIGKey(const string& name)
   if(!d_dnssecQueries)
     return -1;
 
-  stmt = prepare_query(pooledSvcCtx, deleteTSIGKeyQuerySQL, deleteTSIGKeyQueryKey);
+  sword rc;
+  OCIStmt *stmt;
+
+  openMasterConnection();
+  rc = OCITransStart(masterSvcCtx, oraerr, 60, OCI_TRANS_NEW);
+
+  stmt = prepare_query(masterSvcCtx, deleteTSIGKeyQuerySQL, deleteTSIGKeyQueryKey);
   string_to_cbuf(mQueryName, name, sizeof(mQueryName));
   bind_str(stmt, ":name", mQueryName, sizeof(mQueryName));
-  rc = OCIStmtExecute(pooledSvcCtx, stmt, oraerr, 1, 0, NULL, NULL, OCI_DEFAULT);
+  rc = OCIStmtExecute(masterSvcCtx, stmt, oraerr, 1, 0, NULL, NULL, OCI_DEFAULT);
 
   if (rc == OCI_ERROR) {
-    throw OracleException("Oracle getTSIGKey", oraerr);
+    throw OracleException("Oracle deleteTSIGKey", oraerr);
   }
 
   release_query(stmt, setTSIGKeyQueryKey);
+
+  rc = OCITransCommit(masterSvcCtx, oraerr, OCI_DEFAULT);
+  if (rc == OCI_ERROR) {
+    throw OracleException("Oracle deleteTSIGKey COMMIT", oraerr);
+  }
   return true;
 }
 
index 012dc325c6641fc8ae5f2d38ee14c6ca6ed5aea2..4500814b0032919f945d806095919b38666ca482 100644 (file)
@@ -123,12 +123,36 @@ BOOST_AUTO_TEST_CASE(test_method_getBeforeAndAfterNamesAbsolute) {
    BOOST_CHECK_EQUAL(after, "stop");
 }
 
+BOOST_AUTO_TEST_CASE(test_method_setTSIGKey) {
+   std::string algorithm, content;
+   BOOST_TEST_MESSAGE("Testing setTSIGKey method");
+   BOOST_CHECK_MESSAGE(be->setTSIGKey("unit.test","hmac-md5","kp4/24gyYsEzbuTVJRUMoqGFmN3LYgVDzJ/3oRSP7ys="), "did not return true");
+}
+
 BOOST_AUTO_TEST_CASE(test_method_getTSIGKey) {
    std::string algorithm, content;
    BOOST_TEST_MESSAGE("Testing getTSIGKey method");
    be->getTSIGKey("unit.test",&algorithm,&content);
-   BOOST_CHECK_EQUAL(algorithm, "NULL");
-   BOOST_CHECK_EQUAL(content, "NULL");
+   BOOST_CHECK_EQUAL(algorithm, "hmac-md5");
+   BOOST_CHECK_EQUAL(content, "kp4/24gyYsEzbuTVJRUMoqGFmN3LYgVDzJ/3oRSP7ys=");
+}
+
+BOOST_AUTO_TEST_CASE(test_method_deleteTSIGKey) {
+   std::string algorithm, content;
+   BOOST_TEST_MESSAGE("Testing deleteTSIGKey method");
+   BOOST_CHECK_MESSAGE(be->deleteTSIGKey("unit.test"), "did not return true");
+}
+
+BOOST_AUTO_TEST_CASE(test_method_getTSIGKeys) {
+   std::vector<struct TSIGKey> keys;
+   BOOST_TEST_MESSAGE("Testing getTSIGKeys method");
+   be->getTSIGKeys(keys);
+   BOOST_CHECK(keys.size() > 0)
+   if (keys.size() > 0) {
+     BOOST_CHECK_EQUAL(keys[0].name, "test");
+     BOOST_CHECK_EQUAL(keys[0].algorithm, "NULL");
+     BOOST_CHECK_EQUAL(keys[0].key, "NULL");
+   }
 }
 
 BOOST_AUTO_TEST_CASE(test_method_setNotified) {