RAII instead of catch(...) in factories, bubble more errors in debug mode
authorScott Cantor <cantor.2@osu.edu>
Mon, 14 Mar 2005 06:44:49 +0000 (06:44 +0000)
committerScott Cantor <cantor.2@osu.edu>
Mon, 14 Mar 2005 06:44:49 +0000 (06:44 +0000)
xmlproviders/XMLAAP.cpp
xmlproviders/XMLCredentials.cpp
xmlproviders/XMLMetadata.cpp
xmlproviders/XMLRevocation.cpp
xmlproviders/XMLTrust.cpp

index 3d956e6..3db3864 100644 (file)
@@ -160,17 +160,9 @@ namespace {
 
 IPlugIn* XMLAAPFactory(const DOMElement* e)
 {
-    XMLAAP* aap=new XMLAAP(e);
-    try
-    {
-        aap->getImplementation();
-    }
-    catch (...)
-    {
-        delete aap;
-        throw;
-    }
-    return aap;
+    auto_ptr<XMLAAP> aap(new XMLAAP(e));
+    aap->getImplementation();
+    return aap.release();
 }
 
 ReloadableXMLFileImpl* XMLAAP::newImplementation(const DOMElement* e, bool first) const
@@ -185,7 +177,9 @@ ReloadableXMLFileImpl* XMLAAP::newImplementation(const char* pathname, bool firs
 
 void XMLAAPImpl::init()
 {
+#ifdef _DEBUG
     NDC ndc("XMLAAPImpl");
+#endif
     Category& log=Category::getInstance(XMLPROVIDERS_LOGCAT".XMLAAPImpl");
 
     try
@@ -232,18 +226,17 @@ void XMLAAPImpl::init()
     catch (SAMLException& e)
     {
         log.errorStream() << "Error while parsing AAP: " << e.what() << CategoryStream::ENDLINE;
-        for (attrmap_t::iterator i=m_attrMap.begin(); i!=m_attrMap.end(); i++)
-            delete i->second;
+        this->~XMLAAPImpl();
         throw;
     }
+#ifndef _DEBUG
     catch (...)
     {
         log.error("Unexpected error while parsing AAP");
-        for (attrmap_t::iterator i=m_attrMap.begin(); i!=m_attrMap.end(); i++)
-            delete i->second;
+        this->~XMLAAPImpl();
         throw;
     }
-
+#endif
 }
 
 XMLAAPImpl::~XMLAAPImpl()
@@ -629,7 +622,7 @@ bool XMLAAPImpl::AttributeRule::accept(const DOMElement* e, const IScopedRoleDes
     if (log.isWarnEnabled()) {
         auto_ptr_char temp(m_name);
         auto_ptr_char temp2(n->getNodeValue());
-        log.warn("%sattribute %svalue {%s} could not be validated by policy, rejecting it",
+        log.warn("%sattribute (%s) value {%s} could not be validated by policy, rejecting it",
                  (bSimple ? "" : "complex "),temp.get(),temp2.get());
     }
     return false;
index 7b2594b..d3b0f72 100644 (file)
@@ -98,15 +98,9 @@ namespace {
 
 IPlugIn* XMLCredentialsFactory(const DOMElement* e)
 {
-    XMLCredentials* creds=new XMLCredentials(e);
-    try {
-        creds->getImplementation();
-    }
-    catch (...) {
-        delete creds;
-        throw;
-    }
-    return creds;    
+    auto_ptr<XMLCredentials> creds(new XMLCredentials(e));
+    creds->getImplementation();
+    return creds.release();
 }
 
 ReloadableXMLFileImpl* XMLCredentials::newImplementation(const char* pathname, bool first) const
@@ -121,7 +115,9 @@ ReloadableXMLFileImpl* XMLCredentials::newImplementation(const DOMElement* e, bo
 
 void XMLCredentialsImpl::init()
 {
-    NDC ndc("XMLCredentialsImpl");
+#ifdef _DEBUG
+    saml::NDC ndc("XMLCredentialsImpl");
+#endif
     Category& log=Category::getInstance(XMLPROVIDERS_LOGCAT".XMLCredentialsImpl");
 
     try {
@@ -168,16 +164,16 @@ void XMLCredentialsImpl::init()
     }
     catch (SAMLException& e) {
         log.errorStream() << "Error while parsing creds configuration: " << e.what() << CategoryStream::ENDLINE;
-        for (resolvermap_t::iterator j=m_resolverMap.begin(); j!=m_resolverMap.end(); j++)
-            delete j->second;
+        this->~XMLCredentialsImpl();
         throw;
     }
+#ifndef _DEBUG
     catch (...) {
         log.error("Unexpected error while parsing creds configuration");
-        for (resolvermap_t::iterator j=m_resolverMap.begin(); j!=m_resolverMap.end(); j++)
-            delete j->second;
+        this->~XMLCredentialsImpl();
         throw;
     }
+#endif
 }
 
 XMLCredentialsImpl::~XMLCredentialsImpl()
index 8214911..eec97ce 100644 (file)
@@ -149,14 +149,14 @@ namespace {
             ~KeyDescriptor();
             
             KeyUse getUse() const { return m_use; }
-            DSIGKeyInfoList* getKeyInfo() const { return &m_klist; }
+            DSIGKeyInfoList* getKeyInfo() const { return m_klist; }
             saml::Iterator<const XENCEncryptionMethod*> getEncryptionMethods() const { return m_methods; }
             const DOMElement* getElement() const { return m_root; }
         
         private:
             const DOMElement* m_root;
             KeyUse m_use;
-            mutable DSIGKeyInfoList m_klist;
+            mutable DSIGKeyInfoList* m_klist;
             vector<const XENCEncryptionMethod*> m_methods;
         };
         
@@ -436,15 +436,9 @@ namespace {
 
 IPlugIn* XMLMetadataFactory(const DOMElement* e)
 {
-    XMLMetadata* m=new XMLMetadata(e);
-    try {
-        m->getImplementation();
-    }
-    catch (...) {
-        delete m;
-        throw;
-    }
-    return m;    
+    auto_ptr<XMLMetadata> m(new XMLMetadata(e));
+    m->getImplementation();
+    return m.release();
 }
 
 ReloadableXMLFileImpl* XMLMetadata::newImplementation(const DOMElement* e, bool first) const
@@ -579,6 +573,8 @@ XMLMetadataImpl::KeyDescriptor::KeyDescriptor(const DOMElement* e) : m_root(e),
     else if (!XMLString::compareString(e->getAttributeNS(NULL,SHIB_L(use)),SHIB_L(signing)))
         m_use=signing;
     
+    m_klist = new DSIGKeyInfoList(NULL);
+
     // Process ds:KeyInfo
     e=saml::XML::getFirstChildElement(e);
 
@@ -587,7 +583,7 @@ XMLMetadataImpl::KeyDescriptor::KeyDescriptor(const DOMElement* e) : m_root(e),
     DOMElement* child=saml::XML::getFirstChildElement(e);
     while (child) {
         try {
-            if (!m_klist.addXMLKeyInfo(child)) {
+            if (!m_klist->addXMLKeyInfo(child)) {
                 Category::getInstance(XMLPROVIDERS_LOGCAT".XMLMetadataImpl.KeyDescriptor").warn(
                     "skipped unsupported ds:KeyInfo child element");
             }
@@ -609,6 +605,7 @@ XMLMetadataImpl::KeyDescriptor::~KeyDescriptor()
 {
     for (vector<const XENCEncryptionMethod*>::iterator i=m_methods.begin(); i!=m_methods.end(); i++)
         delete const_cast<XENCEncryptionMethod*>(*i);
+    delete m_klist;
 }
 
 XMLMetadataImpl::Role::Role(const EntityDescriptor* provider, time_t validUntil, const DOMElement* e)
@@ -1066,7 +1063,9 @@ XMLMetadataImpl::EntitiesDescriptor::~EntitiesDescriptor()
 
 void XMLMetadataImpl::init()
 {
+#ifdef _DEBUG
     NDC ndc("XMLMetadataImpl");
+#endif
     Category& log=Category::getInstance(XMLPROVIDERS_LOGCAT".XMLMetadataImpl");
 
     try
@@ -1090,12 +1089,14 @@ void XMLMetadataImpl::init()
         this->~XMLMetadataImpl();
         throw;
     }
+#ifndef _DEBUG
     catch (...)
     {
         log.error("Unexpected error while parsing SAML metadata");
         this->~XMLMetadataImpl();
         throw;
     }
+#endif
 }
 
 XMLMetadataImpl::~XMLMetadataImpl()
index 29b3209..9523a05 100644 (file)
@@ -115,15 +115,9 @@ namespace {
 
 IPlugIn* XMLRevocationFactory(const DOMElement* e)
 {
-    XMLRevocation* r=new XMLRevocation(e);
-    try {
-        r->getImplementation();
-    }
-    catch (...) {
-        delete r;
-        throw;
-    }
-    return r;
+    auto_ptr<XMLRevocation> r(new XMLRevocation(e));
+    r->getImplementation();
+    return r.release();
 }
 
 
@@ -145,7 +139,9 @@ XMLRevocationImpl::KeyAuthority::~KeyAuthority()
 
 void XMLRevocationImpl::init()
 {
-    NDC ndc("XMLRevocationImpl");
+#ifdef _DEBUG
+    saml::NDC ndc("XMLRevocationImpl");
+#endif
     Category& log=Category::getInstance(XMLPROVIDERS_LOGCAT".XMLRevocationImpl");
 
     try {
@@ -253,16 +249,16 @@ void XMLRevocationImpl::init()
     }
     catch (SAMLException& e) {
         log.errorStream() << "Error while parsing revocation configuration: " << e.what() << CategoryStream::ENDLINE;
-        for (vector<KeyAuthority*>::iterator i=m_keyauths.begin(); i!=m_keyauths.end(); i++)
-            delete (*i);
+        this->~XMLRevocationImpl();
         throw;
     }
+#ifndef _DEBUG
     catch (...) {
         log.error("Unexpected error while parsing revocation configuration");
-        for (vector<KeyAuthority*>::iterator i=m_keyauths.begin(); i!=m_keyauths.end(); i++)
-            delete (*i);
+        this->~XMLRevocationImpl();
         throw;
     }
+#endif
 }
 
 XMLRevocationImpl::~XMLRevocationImpl()
index 9101d31..36d55ad 100644 (file)
@@ -144,15 +144,9 @@ namespace {
 
 IPlugIn* XMLTrustFactory(const DOMElement* e)
 {
-    XMLTrust* t=new XMLTrust(e);
-    try {
-        t->getImplementation();
-    }
-    catch (...) {
-        delete t;
-        throw;
-    }
-    return t;    
+    auto_ptr<XMLTrust> t(new XMLTrust(e));
+    t->getImplementation();
+    return t.release();
 }
 
 
@@ -211,7 +205,9 @@ public:
 
 void XMLTrustImpl::init()
 {
-    NDC ndc("XMLTrustImpl");
+#ifdef _DEBUG
+    saml::NDC ndc("XMLTrustImpl");
+#endif
     Category& log=Category::getInstance(XMLPROVIDERS_LOGCAT".XMLTrustImpl");
 
     try {
@@ -378,20 +374,16 @@ void XMLTrustImpl::init()
     }
     catch (SAMLException& e) {
         log.errorStream() << "Error while parsing trust configuration: " << e.what() << CategoryStream::ENDLINE;
-        for (vector<KeyAuthority*>::iterator i=m_keyauths.begin(); i!=m_keyauths.end(); i++)
-            delete (*i);
-        for (vector<DSIGKeyInfoList*>::iterator j=m_keybinds.begin(); j!=m_keybinds.end(); j++)
-            delete (*j);
+        this->~XMLTrustImpl();
         throw;
     }
+#ifndef _DEBUG
     catch (...) {
         log.error("Unexpected error while parsing trust configuration");
-        for (vector<KeyAuthority*>::iterator i=m_keyauths.begin(); i!=m_keyauths.end(); i++)
-            delete (*i);
-        for (vector<DSIGKeyInfoList*>::iterator j=m_keybinds.begin(); j!=m_keybinds.end(); j++)
-            delete (*j);
+        this->~XMLTrustImpl();
         throw;
     }
+#endif
 }
 
 XMLTrustImpl::~XMLTrustImpl()
@@ -931,6 +923,9 @@ bool XMLTrust::validate(
                 log.warn("failed to add CRL");
             }
         }
+        
+        // Install error callback.
+        X509_STORE_CTX_set_verify_cb(ctx,logging_callback);
     
         int result=X509_verify_cert(ctx);
         sk_X509_pop_free(chain,X509_free);