From: Aki Tuomi Date: Sat, 15 Jun 2013 14:51:44 +0000 (+0300) Subject: Style fixes and now does REPLACE instead of INSERT X-Git-Tag: rec-3.6.0-rc1~468^2~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f718b8c683f65da1c83c1137a83276790e486dc6;p=thirdparty%2Fpdns.git Style fixes and now does REPLACE instead of INSERT --- diff --git a/modules/oraclebackend/oraclebackend.cc b/modules/oraclebackend/oraclebackend.cc index 15bf68f025..c216cdff30 100644 --- a/modules/oraclebackend/oraclebackend.cc +++ b/modules/oraclebackend/oraclebackend.cc @@ -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; } diff --git a/modules/remotebackend/test-remotebackend.cc b/modules/remotebackend/test-remotebackend.cc index 012dc325c6..4500814b00 100644 --- a/modules/remotebackend/test-remotebackend.cc +++ b/modules/remotebackend/test-remotebackend.cc @@ -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 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) {