]> granicus.if.org Git - pdns/commitdiff
hook up activate-domain-key, deactivate-domain-key, remove-domain-key
authorBert Hubert <bert.hubert@netherlabs.nl>
Sun, 2 Jan 2011 19:40:46 +0000 (19:40 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Sun, 2 Jan 2011 19:40:46 +0000 (19:40 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1791 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/backends/gsql/gsqlbackend.cc
pdns/backends/gsql/gsqlbackend.hh
pdns/dbdnsseckeeper.cc
pdns/pdnssec.cc
pdns/ueberbackend.cc
pdns/ueberbackend.hh

index 62fbaac38825cb4688a00950799e2b2f96a860b7..443525bab4a75e5d5765e3190195826ab705e5a8 100644 (file)
@@ -101,9 +101,9 @@ bool GSQLBackend::getDomainInfo(const string &domain, DomainInfo &di)
     try {
       SOAData sd;
       if(!getSOA(domain,sd)) 
-       L<<Logger::Notice<<"No serial for '"<<domain<<"' found - zone is missing?"<<endl;
+        L<<Logger::Notice<<"No serial for '"<<domain<<"' found - zone is missing?"<<endl;
       else
-       di.serial=sd.serial;
+        di.serial=sd.serial;
     }
     catch(AhuException &ae){
       L<<Logger::Error<<"Error retrieving serial for '"<<domain<<"': "<<ae.reason<<endl;
@@ -250,6 +250,10 @@ GSQLBackend::GSQLBackend(const string &mode, const string &suffix)
   d_GetDomainMetadataQuery = "select content from domains, domainmetadata where domain_id=domains.id and name='%s' and domainmetadata.kind='%s'";
   d_ClearDomainMetadataQuery = "delete from domainmetadata where domain_id=(select id from domains where name='%s') and domainmetadata.kind='%s'";
   d_SetDomainMetadataQuery = "insert into domainmetadata (domain_id, kind, content) select id, '%s', '%s' from domains where name='%s'";
+  
+  d_ActivateDomainKeyQuery = "update cryptokeys set active=1 where domain_id=(select id from domains where name='%s') and  cryptokeys.id=%d";
+  d_DeactivateDomainKeyQuery = "update cryptokeys set active=0 where domain_id=(select id from domains where name='%s') and  cryptokeys.id=%d";
+  d_RemoveDomainKeyQuery = "delete from cryptokeys where domain_id=(select id from domains where name='%s') and cryptokeys.id=%d";
 }
 
 bool GSQLBackend::updateDNSSECOrderAndAuth(uint32_t domain_id, const std::string& zonename, const std::string& qname, bool auth)
@@ -327,6 +331,50 @@ int GSQLBackend::addDomainKey(const string& name, const KeyData& key)
   return 1; // XXX FIXME, no idea how to get the id
 }
 
+bool GSQLBackend::activateDomainKey(const string& name, unsigned int id)
+{
+  char output[1024];
+  snprintf(output,sizeof(output)-1,d_ActivateDomainKeyQuery.c_str(), sqlEscape(name).c_str(), id);
+
+  try {
+    d_db->doCommand(output);
+  }
+  catch (SSqlException &e) {
+    throw AhuException("GSQLBackend unable to activate key: "+e.txtReason());
+  }
+  return true;
+}
+
+bool GSQLBackend::deactivateDomainKey(const string& name, unsigned int id)
+{
+  char output[1024];
+  snprintf(output,sizeof(output)-1,d_DeactivateDomainKeyQuery.c_str(), sqlEscape(name).c_str(), id);
+
+  try {
+    d_db->doCommand(output);
+  }
+  catch (SSqlException &e) {
+    throw AhuException("GSQLBackend unable to deactivate key: "+e.txtReason());
+  }
+  return true;
+}
+
+bool GSQLBackend::removeDomainKey(const string& name, unsigned int id)
+{
+  char output[1024];
+  snprintf(output,sizeof(output)-1,d_RemoveDomainKeyQuery.c_str(), sqlEscape(name).c_str(), id);
+
+  try {
+    d_db->doCommand(output);
+  }
+  catch (SSqlException &e) {
+    throw AhuException("GSQLBackend unable to remove key: "+e.txtReason());
+  }
+  return true;
+}
+
+
+
 bool GSQLBackend::getDomainKeys(const string& name, unsigned int kind, std::vector<KeyData>& keys)
 {
   char output[1024];  
index dde76621602392daca1080a330a0437c73d9f3b9..78ff4ae3083d4755f87feceb6dee4e4b56bc1f13 100644 (file)
@@ -47,6 +47,11 @@ public:
   bool getDomainKeys(const string& name, unsigned int kind, std::vector<KeyData>& keys);
   bool getDomainMetadata(const string& name, const std::string& kind, std::vector<std::string>& meta);
   bool setDomainMetadata(const string& name, const std::string& kind, const std::vector<std::string>& meta);
+  
+  bool removeDomainKey(const string& name, unsigned int id);
+  bool activateDomainKey(const string& name, unsigned int id);
+  bool deactivateDomainKey(const string& name, unsigned int id);
+  
 private:
   string d_qname;
   QType d_qtype;
@@ -86,6 +91,10 @@ private:
   string d_GetDomainMetadataQuery;
   string d_ClearDomainMetadataQuery;
   string d_SetDomainMetadataQuery;
+
+  string d_RemoveDomainKeyQuery;
+  string d_ActivateDomainKeyQuery;
+  string d_DeactivateDomainKeyQuery;
 protected:  
   bool d_dnssecQueries;
 };
index 944e15f49b00e647666628e4a1f0b17d5a562645..f09d8ffd6e23325680306feed4234d98e0121556 100644 (file)
@@ -88,17 +88,20 @@ DNSSECPrivateKey DNSSECKeeper::getKeyById(const std::string& zname, unsigned int
 
 void DNSSECKeeper::removeKey(const std::string& zname, unsigned int id)
 {
-  // XXX
+  UeberBackend db;
+  db.removeDomainKey(zname, id);
 }
 
 void DNSSECKeeper::deactivateKey(const std::string& zname, unsigned int id)
 {
-  // XX
+  UeberBackend db;
+  db.deactivateDomainKey(zname, id);
 }
 
 void DNSSECKeeper::activateKey(const std::string& zname, unsigned int id)
 {
-  // XXX
+  UeberBackend db;
+  db.activateDomainKey(zname, id);
 }
 
 bool DNSSECKeeper::getNSEC3PARAM(const std::string& zname, NSEC3PARAMRecordContent* ns3p)
index 381a8d7d5d1d95ef39c0260e8715c7ace95ea861..646f14584dee0e43729fe460f6ac0ea7687b7666 100644 (file)
@@ -24,7 +24,6 @@ ArgvMap &arg()
   return arg;
 }
 
-
 string humanTime(time_t t)
 {
   char ret[256];
@@ -256,8 +255,8 @@ try
   else if(cmds[0] == "add-zone-key") {
     const string& zone=cmds[1];
     // need to get algorithm & ksk or zsk from commandline
+    cerr<<"Adding a ZSK"<<endl;
     dk.addKey(zone, 1, 5, 0); 
-    cerr<<"Not implemented"<<endl;
   }
   else if(cmds[0] == "remove-zone-key") {
     const string& zone=cmds[1];
@@ -322,9 +321,12 @@ try
     unsigned int id=atoi(cmds[2].c_str());
     DNSSECPrivateKey dpk=dk.getKeyById(zone, id);
     cout << dpk.d_key.convertToISC(dpk.d_algorithm) <<endl;
-  }
+  }  
   else if(cmds[0]=="import-zone-key") {
-    cerr<<"This isn't quite right yet!"<<endl; /// XXX FIXME
+    if(cmds.size()!=3) {
+      cerr<<"Syntax: pdnssec import-zone-key zone-name filename"<<endl;
+      exit(1);
+    }
     string zone=cmds[1];
     string fname=cmds[2];
     DNSSECPrivateKey dpk;
index 46710205dfb881be3518ff247534faee9becbbfe..f324c195b6c78dc6945af2ccbb76d2f24272c3fc 100644 (file)
@@ -134,6 +134,33 @@ bool UeberBackend::setDomainMetadata(const string& name, const std::string& kind
   return false;
 }
 
+bool UeberBackend::activateDomainKey(const string& name, unsigned int id)
+{
+  BOOST_FOREACH(DNSBackend* db, backends) {
+    if(db->activateDomainKey(name, id))
+      return true;
+  }
+  return false;
+}
+
+bool UeberBackend::deactivateDomainKey(const string& name, unsigned int id)
+{
+  BOOST_FOREACH(DNSBackend* db, backends) {
+    if(db->deactivateDomainKey(name, id))
+      return true;
+  }
+  return false;
+}
+
+bool UeberBackend::removeDomainKey(const string& name, unsigned int id)
+{
+  BOOST_FOREACH(DNSBackend* db, backends) {
+    if(db->removeDomainKey(name, id))
+      return true;
+  }
+  return false;
+}
+
 
 void UeberBackend::reload()
 {
index 27f07bc57a35974e9b6fb4ac9e29b87101a1f9cf..24b1c45a8b5fc487cef8af61a34ff127d4db3184 100644 (file)
@@ -127,6 +127,10 @@ public:
   bool getDomainKeys(const string& name, unsigned int kind, std::vector<KeyData>& keys);
   bool getDomainMetadata(const string& name, const std::string& kind, std::vector<std::string>& meta);
   bool setDomainMetadata(const string& name, const std::string& kind, const std::vector<std::string>& meta);
+
+  bool removeDomainKey(const string& name, unsigned int id);
+  bool activateDomainKey(const string& name, unsigned int id);
+  bool deactivateDomainKey(const string& name, unsigned int id);
   
   void alsoNotifies(const string &domain, set<string> *ips); 
   void rediscover(string* status=0);