Merge branch 'master' into debian
authorDan Breslau <dbreslau@painless-security.com>
Mon, 24 Jul 2017 22:09:08 +0000 (18:09 -0400)
committerDan Breslau <dbreslau@painless-security.com>
Mon, 24 Jul 2017 22:09:08 +0000 (18:09 -0400)
1  2 
mech_eap/util_shib.cpp

@@@ -79,14 -78,58 +79,66 @@@ using namespace opensaml
  using namespace xercesc;
  #endif
  
 +// Use unique_ptr where available; auto_ptr otherwise.
 +#if __cplusplus > 199711L
 +#define UNIQUE_OR_AUTO_PTR unique_ptr
 +#else
 +#define UNIQUE_OR_AUTO_PTR auto_ptr
 +#endif
 +
 +
+ namespace {
+     class ShibFinalizer {
+     public:
+         static bool isShibInitialized() {return shibInitialized;}
+         static void createSingleton();
+     private:
+         ShibFinalizer(): is_extra(false) {
+             if (shibInitialized) {
+                 // This should never, ever happen. Initialization is (supposed to be)
+                 // funneled through a single thread, so there should be no race
+                 // conditions here. And only this class sets this flag, and there's
+                 // only a single instance of this class.
+                 wpa_printf(MSG_ERROR, "### ShibFinalizer::ShibFinalizer(): Attempt to construct an extraneous instance!");
+                 is_extra = true;
+             }
+             else {
+                 wpa_printf(MSG_INFO, "### ShibFinalizer::ShibFinalizer(): Constructing");
+                 shibInitialized = true;
+             }
+         }
+         ~ShibFinalizer() {
+             if (!is_extra) {
+                 wpa_printf(MSG_INFO, "### ShibFinalizer::~ShibFinalizer(): Destructing");
+                 gss_eap_shib_attr_provider::finalize();
+                 shibInitialized = false;
+             }
+             else {
+                 wpa_printf(MSG_INFO, "### ShibFinalizer::~ShibFinalizer(): This was an extraneous instance; not destructing anything.");
+             }
+         }
+         bool is_extra;
+         static bool shibInitialized;
+     };
+ }
+ bool ShibFinalizer::shibInitialized = false;
+ void ShibFinalizer::createSingleton() {
+     // This object's constructor is invoked on the first call to this method.
+     // At exit, its destructor will terminate Shibboleth.
+     static ShibFinalizer finalizer;
+ }
  gss_eap_shib_attr_provider::gss_eap_shib_attr_provider(void)
  {
      m_initialized = false;