#include <shibresolver/resolver.h>
#include <sstream>
+#include <memory>
using namespace shibsp;
using namespace shibresolver;
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;
if (!gss_eap_attr_provider::initWithGssContext(manager, gssCred, gssCtx))
return false;
- auto_ptr<ShibbolethResolver> resolver(ShibbolethResolver::create());
+ UNIQUE_OR_AUTO_PTR<ShibbolethResolver> resolver(ShibbolethResolver::create());
/*
* For now, leave ApplicationID defaulted.
{
bool ret = false;
+ if (ShibFinalizer::isShibInitialized()) {
+ wpa_printf(MSG_INFO, "### gss_eap_shib_attr_provider::init(): ShibResolver library is already initialized; ignoring.");
+ return true;
+ }
+
+ wpa_printf(MSG_INFO, "### gss_eap_shib_attr_provider::init(): Initializing ShibResolver library");
+
try {
ret = ShibbolethResolver::init();
} catch (exception &e) {
}
- if (ret)
+ if (ret) {
+ ShibFinalizer::createSingleton();
gss_eap_attr_ctx::registerProvider(ATTR_TYPE_LOCAL, createAttrContext);
+ }
return ret;
}
void
gss_eap_shib_attr_provider::finalize(void)
{
+ wpa_printf(MSG_INFO, "### gss_eap_shib_attr_provider::finalize(): calling ShibbolethResolver::term()");
gss_eap_attr_ctx::unregisterProvider(ATTR_TYPE_LOCAL);
ShibbolethResolver::term();
}
return dst;
}
+
OM_uint32
gssEapLocalAttrProviderInit(OM_uint32 *minor)
{
*minor = GSSEAP_SHIB_INIT_FAILURE;
return GSS_S_FAILURE;
}
- return GSS_S_COMPLETE;
- }
-
- OM_uint32
- gssEapLocalAttrProviderFinalize(OM_uint32 *minor)
- {
- gss_eap_shib_attr_provider::finalize();
- *minor = 0;
return GSS_S_COMPLETE;
}