From e2b3f8503eedbf6cbb838861e98cb418e1557599 Mon Sep 17 00:00:00 2001 From: Kees Monshouwer Date: Fri, 26 Jun 2015 21:38:15 +0200 Subject: [PATCH] oracle backend, add DNSName_to_cbuf() --- modules/oraclebackend/oraclebackend.cc | 44 ++++++++++++++++---------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/modules/oraclebackend/oraclebackend.cc b/modules/oraclebackend/oraclebackend.cc index d2071eb83..640f70c5f 100644 --- a/modules/oraclebackend/oraclebackend.cc +++ b/modules/oraclebackend/oraclebackend.cc @@ -273,6 +273,16 @@ string_to_cbuf (char *buf, const string& s, size_t bufsize) strncpy(buf, s.c_str(), bufsize); } +static void +DNSName_to_cbuf (char *buf, const DNSName& n, size_t bufsize) +{ + string s = toLower(n.toStringNoDot()); + if (s.size() >= bufsize) { + throw std::overflow_error("OracleBackend: DNSName does not fit into char buffer"); + } + strncpy(buf, s.c_str(), bufsize); +} + OracleBackend::OracleBackend (const string &suffix, OCIEnv *envh, char *poolname) { @@ -441,7 +451,7 @@ OracleBackend::lookup (const QType &qtype, const DNSName& qname, } } - string_to_cbuf(mQueryName, qname.toStringNoDot(), sizeof(mQueryName)); + DNSName_to_cbuf(mQueryName, qname, sizeof(mQueryName)); string_to_cbuf(mQueryType, qtype.getName(), sizeof(mQueryType)); mQueryZoneId = zoneId; @@ -476,7 +486,7 @@ OracleBackend::getBeforeAndAfterNames ( bind_str_ind(stmt, ":prev", mResultPrevName, sizeof(mResultPrevName), &mResultPrevNameInd); bind_str_ind(stmt, ":next", mResultNextName, sizeof(mResultNextName), &mResultNextNameInd); bind_uint32(stmt, ":zoneid", &zoneId); - string_to_cbuf(mQueryName, name.toStringNoDot(), sizeof(mQueryName)); + DNSName_to_cbuf(mQueryName, name, sizeof(mQueryName)); mResultPrevNameInd = -1; mResultNextNameInd = -1; @@ -596,7 +606,7 @@ OracleBackend::isMaster (const DNSName& domain, const string &master) stmt = prepare_query(masterSvcCtx, isZoneMasterQuerySQL, isZoneMasterQueryKey); - string_to_cbuf(mQueryZone, domain.toStringNoDot(), sizeof(mQueryZone)); + DNSName_to_cbuf(mQueryZone, domain, sizeof(mQueryZone)); string_to_cbuf(mQueryName, master, sizeof(mQueryName)); char res_master[512]; @@ -649,7 +659,7 @@ OracleBackend::getDomainInfo (const DNSName& domain, DomainInfo &di) define_output_uint32(stmt, 5, &serial_ind, &serial); define_output_uint32(stmt, 6, ¬ified_serial_ind, ¬ified_serial); - string_to_cbuf(mQueryZone, domain.toStringNoDot(), sizeof(mQueryZone)); + DNSName_to_cbuf(mQueryZone, domain, sizeof(mQueryZone)); bind_str(stmt, ":name", mQueryZone, sizeof(mQueryZone)); rc = OCIStmtExecute(masterSvcCtx, stmt, oraerr, 1, 0, NULL, NULL, OCI_DEFAULT); @@ -710,7 +720,7 @@ void OracleBackend::alsoNotifies(const DNSName& domain, set *addrs) bind_str_failokay(stmt, ":nsname", myServerName, sizeof(myServerName)); bind_str(stmt, ":name", mQueryZone, sizeof(mQueryZone)); - string_to_cbuf(mQueryZone, domain.toStringNoDot(), sizeof(mQueryZone)); + DNSName_to_cbuf(mQueryZone, domain, sizeof(mQueryZone)); define_output_str(stmt, 1, &hostaddr_ind, hostaddr, sizeof(hostaddr)); @@ -1075,7 +1085,7 @@ OracleBackend::feedRecord (const DNSResourceRecord &rr, string *ordername) bind_str(stmt, ":content", mQueryContent, sizeof(mQueryContent)); mQueryZoneId = rr.domain_id; - string_to_cbuf(mQueryName, rr.qname.toStringNoDot(), sizeof(mQueryName)); + DNSName_to_cbuf(mQueryName, rr.qname, sizeof(mQueryName)); ttl = rr.ttl; string_to_cbuf(mQueryType, rr.qtype.getName(), sizeof(mQueryType)); string_to_cbuf(mQueryContent, rr.content, sizeof(mQueryContent)); @@ -1189,7 +1199,7 @@ OracleBackend::createSlaveDomain(const string &ip, const DNSName& domain, OCIStmt *insertSlaveQueryHandle; OCIStmt *insertMasterQueryHandle; - string_to_cbuf(mQueryZone, domain.toStringNoDot(), sizeof(mQueryZone)); + DNSName_to_cbuf(mQueryZone, domain, sizeof(mQueryZone)); openMasterConnection(); @@ -1253,7 +1263,7 @@ OracleBackend::getAllDomainMetadata (const DNSName& name, std::map