+
+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;
+}
+
+