![]() ![]() |
![]() |
File: [Pegasus] / pegasus / src / WMIMapper / PegServer / CIMServer.cpp
(download)
Revision: 1.10, Fri Jun 18 21:00:23 2004 UTC (20 years ago) by kumpf Branch: MAIN CVS Tags: RELEASE_2_4_FC_CANDIDATE_1, MONITOR_CONSOLIDATION_2_5_BRANCH, CQL_2_5_BRANCH Changes since 1.9: +27 -11 lines BUG#: 1571 TITLE: HP[Nag] Use getHomedPath() when using the config properties passwordFilePath, sslCertificateFilePath and sslKeyFilePath DESCRIPTION: Updated the code not to prepend PegasusHome during the initialization of these config properties, instead getHomedPath() is used at places where these properties are used. |
//%2003//////////////////////////////////////////////////////////////////////// // // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development // Company, L. P., IBM Corp., The Open Group, Tivoli Systems. // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.; // IBM Corp.; EMC Corporation, The Open Group. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // //============================================================================== // // Author: Mike Brasher (mbrasher@bmc.com) // // Modified By: // Mike Day (mdday@us.ibm.com)s // Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com) // Nag Boranna, Hewlett-Packard Company (nagaraja_boranna@hp.com) // Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com) // Jenny Yu, Hewlett-Packard Company (jenny_yu@hp.com) // Sushma Fernandes, Hewlett-Packard Company (sushma_fernandes@hp.com) // Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com) // Bapu Patil, Hewlett-Packard Company (bapu_patil@hp.com) // Barbara Packard, Hewlett-Packard Company (barbara_packard@hp.com) // Jair Santos, Hewlett-Packard Company (jair.santos@hp.com) // Dan Gorey, IBM (djgorey@us.ibm.com) // Terry Martin, Hewlett-Packard Company (terry.martin@hp.com) // Amit K Arora, IBM (amita@in.ibm.com) for PEP#101 // //%///////////////////////////////////////////////////////////////////////////// #include <Pegasus/Common/Config.h> #include <iostream> #include <cstdio> #include <cctype> #include <ctime> #include <Pegasus/Common/Constants.h> #include <Pegasus/Common/FileSystem.h> #include <Pegasus/Common/HTTPAcceptor.h> #include <Pegasus/Common/Tracer.h> #include <Pegasus/Common/Cimom.h> #include <Pegasus/Common/PegasusVersion.h> #include <Pegasus/Common/Signal.h> #include <Pegasus/Repository/CIMRepository.h> /* #include "ProviderMessageFacade.h" */ #include <Pegasus/ExportServer/CIMExportRequestDispatcher.h> #include <Pegasus/ExportServer/CIMExportResponseEncoder.h> #include <Pegasus/ExportServer/CIMExportRequestDecoder.h> #include <Pegasus/Config/ConfigManager.h> #include <Pegasus/Security/UserManager/UserManager.h> /* #include <Pegasus/HandlerService/IndicationHandlerService.h> #include <Pegasus/IndicationService/IndicationService.h> #ifdef PEGASUS_USE_23PROVIDER_MANAGER #include <Pegasus/ProviderManager/ProviderManagerService.h> #include <Pegasus/ProviderManager/ProviderManager.h> #else #include <Pegasus/ProviderManager2/ProviderManagerService.h> #endif */ #include "CIMServer.h" #include "CIMOperationRequestDispatcher.h" #include "CIMOperationResponseEncoder.h" #include "CIMOperationRequestDecoder.h" #include "CIMOperationRequestAuthorizer.h" #include "HTTPAuthenticatorDelegator.h" /* #include "ShutdownProvider.h" #include "ShutdownService.h" #include "BinaryMessageHandler.h" #include <Pegasus/Common/ModuleController.h> #include <Pegasus/ControlProviders/ConfigSettingProvider/ConfigSettingProvider.h> #include <Pegasus/ControlProviders/UserAuthProvider/UserAuthProvider.h> #include <Pegasus/ControlProviders/ProviderRegistrationProvider/ProviderRegistrationProvider.h> #include <Pegasus/ControlProviders/NamespaceProvider/NamespaceProvider.h> */ // l10n #include <Pegasus/Common/MessageLoader.h> PEGASUS_USING_STD; PEGASUS_NAMESPACE_BEGIN /* // Need a static method to act as a callback for the control provider. // This doesn't belong here, but I don't have a better place to put it. static Message * controlProviderReceiveMessageCallback( Message * message, void * instance) { ProviderMessageFacade * mpf = reinterpret_cast<ProviderMessageFacade *>(instance); return mpf->handleRequestMessage(message); } void shutdownSignalHandler(int s_n, PEGASUS_SIGINFO_T * s_info, void * sig) { PEG_METHOD_ENTER(TRC_SERVER, "shutdownSignalHandler"); Tracer::trace(TRC_SERVER, Tracer::LEVEL2, "Signal %d received.", s_n); handleShutdownSignal = true; PEG_METHOD_EXIT(); } */ Boolean handleShutdownSignal = false; void CIMServer::shutdownSignal() { PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::shutdownSignal()"); handleShutdownSignal = true; PEG_METHOD_EXIT(); } CIMServer::CIMServer(Monitor* monitor) : _dieNow(false), _monitor(monitor), _monitor2(0), _type(OLD) { PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::CIMServer()"); _init(); PEG_METHOD_EXIT(); } CIMServer::CIMServer(monitor_2* m2) : _dieNow(false), _monitor(0), _monitor2(m2), _type(NEW) { PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::CIMServer()"); _init(); _monitor2->set_accept_dispatch(pegasus_acceptor::accept_dispatch); _monitor2->set_session_dispatch(HTTPConnection2::connection_dispatch); _monitor2->set_idle_dispatch(_monitor_idle_routine); _monitor2->set_idle_parm((void*)this); PEG_METHOD_EXIT(); } void CIMServer::_init(void) { String repositoryRootPath = String::EMPTY; #if defined(PEGASUS_OS_HPUX) && defined(PEGASUS_USE_RELEASE_DIRS) chdir( PEGASUS_CORE_DIR ); #endif // -- Save the monitor or create a new one: repositoryRootPath = ConfigManager::getHomedPath(ConfigManager::getInstance()->getCurrentValue("repositoryDir")); // -- Create a repository: /* #ifdef DO_NOT_CREATE_REPOSITORY_ON_STARTUP // If this code is enable, the CIMServer will fail to start // if the repository directory does not exit. If called, // the Repository will create an empty repository. // This check has been disabled to allow cimmof to call // the CIMServer to build the initial repository. if (!FileSystem::isDirectory(repositoryRootPath)) { PEG_METHOD_EXIT(); throw NoSuchDirectory(repositoryRootPath); } #endif */ _repository = new CIMRepository(repositoryRootPath); // -- Create a UserManager object: UserManager* userManager = UserManager::getInstance(_repository); // -- Create a CIMServerState object: _serverState.reset(new CIMServerState()); /* _providerRegistrationManager = new ProviderRegistrationManager(_repository); // -- Create queue inter-connections: #ifdef PEGASUS_USE_23PROVIDER_MANAGER _providerManager = new ProviderManagerService(_providerRegistrationManager); #else _providerManager = new ProviderManagerService(_providerRegistrationManager,_repository); #endif _handlerService = new IndicationHandlerService(_repository); // Create the control service _controlService = new ModuleController(PEGASUS_QUEUENAME_CONTROLSERVICE); // Create the Configuration control provider ProviderMessageFacade * configProvider = new ProviderMessageFacade(new ConfigSettingProvider()); ModuleController::register_module(PEGASUS_QUEUENAME_CONTROLSERVICE, PEGASUS_MODULENAME_CONFIGPROVIDER, configProvider, controlProviderReceiveMessageCallback, 0, 0); // Create the User/Authorization control provider ProviderMessageFacade * userAuthProvider = new ProviderMessageFacade(new UserAuthProvider(_repository)); ModuleController::register_module(PEGASUS_QUEUENAME_CONTROLSERVICE, PEGASUS_MODULENAME_USERAUTHPROVIDER, userAuthProvider, controlProviderReceiveMessageCallback, 0, 0); // Create the Provider Registration control provider ProviderMessageFacade * provRegProvider = new ProviderMessageFacade( new ProviderRegistrationProvider(_providerRegistrationManager)); ModuleController::register_module(PEGASUS_QUEUENAME_CONTROLSERVICE, PEGASUS_MODULENAME_PROVREGPROVIDER, provRegProvider, controlProviderReceiveMessageCallback, 0, 0); // Create the Shutdown control provider ProviderMessageFacade * shutdownProvider = new ProviderMessageFacade(new ShutdownProvider(this)); ModuleController::register_module(PEGASUS_QUEUENAME_CONTROLSERVICE, PEGASUS_MODULENAME_SHUTDOWNPROVIDER, shutdownProvider, controlProviderReceiveMessageCallback, 0, 0); // Create the namespace control provider ProviderMessageFacade * namespaceProvider = new ProviderMessageFacade(new NamespaceProvider(_repository)); ModuleController::register_module(PEGASUS_QUEUENAME_CONTROLSERVICE, PEGASUS_MODULENAME_NAMESPACEPROVIDER, namespaceProvider, controlProviderReceiveMessageCallback, 0, 0); _cimOperationRequestDispatcher = new CIMOperationRequestDispatcher(_repository, _providerRegistrationManager); _binaryMessageHandler = new BinaryMessageHandler(_cimOperationRequestDispatcher); */ _cimOperationResponseEncoder = new CIMOperationResponseEncoder; // // get the configured authentication and authorization flags // ConfigManager* configManager = ConfigManager::getInstance(); Boolean enableAuthentication = false; if (String::equalNoCase( configManager->getCurrentValue("enableAuthentication"), "true")) { enableAuthentication = true; } // // Create Authorization queue only if authentication is enabled // if ( enableAuthentication ) { _cimOperationRequestAuthorizer = new CIMOperationRequestAuthorizer( _cimOperationRequestDispatcher); _cimOperationRequestDecoder = new CIMOperationRequestDecoder( _cimOperationRequestAuthorizer, _cimOperationResponseEncoder->getQueueId()); } else { _cimOperationRequestAuthorizer = 0; _cimOperationRequestDecoder = new CIMOperationRequestDecoder( _cimOperationRequestDispatcher, _cimOperationResponseEncoder->getQueueId()); } _cimExportRequestDispatcher = new CIMExportRequestDispatcher(); _cimExportResponseEncoder = new CIMExportResponseEncoder; _cimExportRequestDecoder = new CIMExportRequestDecoder( _cimExportRequestDispatcher, _cimExportResponseEncoder->getQueueId()); _httpAuthenticatorDelegator = new HTTPAuthenticatorDelegator( _cimOperationRequestDecoder->getQueueId(), _cimExportRequestDecoder->getQueueId()); _sslcontext.reset(); _exportSSLContext.reset(); // IMPORTANT-NU-20020513: Indication service must start after ExportService // otherwise HandlerService started by indicationService will never // get ExportQueue to export indications for existing subscriptions /* _indicationService = 0; if (String::equal( configManager->getCurrentValue("enableIndicationService"), "true")) { _indicationService = new IndicationService (_repository, _providerRegistrationManager); } // Enable the signal handler to shutdown gracefully on SIGHUP and SIGTERM getSigHandle()->registerHandler(PEGASUS_SIGHUP, shutdownSignalHandler); getSigHandle()->activate(PEGASUS_SIGHUP); getSigHandle()->registerHandler(PEGASUS_SIGTERM, shutdownSignalHandler); getSigHandle()->activate(PEGASUS_SIGTERM); */ } CIMServer::~CIMServer() { PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::~CIMServer()"); // Note: do not delete the acceptor because it belongs to the Monitor // which takes care of disposing of it. /* if (_providerRegistrationManager) { delete _providerRegistrationManager; } */ if (_type != OLD) { pegasus_acceptor::close_all_acceptors(); } PEG_METHOD_EXIT(); } void CIMServer::addAcceptor( Boolean localConnection, Uint32 portNumber, Boolean useSSL, Boolean exportConnection) { if(_type == OLD ){ HTTPAcceptor* acceptor; if (exportConnection) { // // On export connection, create SSLContext with a indication // trust store. // acceptor = new HTTPAcceptor(_monitor, _httpAuthenticatorDelegator, localConnection, portNumber, useSSL ? _getExportSSLContext() : 0, exportConnection); } else { acceptor = new HTTPAcceptor(_monitor, _httpAuthenticatorDelegator, localConnection, portNumber, useSSL ? _getSSLContext() : 0, exportConnection); } _acceptors.append(acceptor); } else { pegasus_acceptor* acceptor = new pegasus_acceptor(_monitor2, _httpAuthenticatorDelegator, localConnection, portNumber, useSSL ? _getSSLContext() : 0); acceptor->bind(); } } void CIMServer::bind() { PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::bind()"); if(_type == OLD) { if (_acceptors.size() == 0) { // l10n // throw BindFailedException("No CIM Server connections are enabled."); MessageLoaderParms mlp = MessageLoaderParms("Server.CIMServer.BIND_FAILED","No CIM Server connections are enabled."); throw BindFailedException(mlp); } for (Uint32 i=0; i<_acceptors.size(); i++) { _acceptors[i]->bind(); } } PEG_METHOD_EXIT(); } void CIMServer::_monitor_idle_routine(void *parm) { CIMServer* myself = static_cast<CIMServer* >(parm); try { MessageQueueService::_check_idle_flag = 1; MessageQueueService::_polling_sem.signal(); /* #ifdef PEGASUS_USE_23PROVIDER_MANAGER ProviderManagerService::getProviderManager()->unload_idle_providers(); #else myself->_providerManager->unload_idle_providers(); #endif */ } catch(...) { } if (handleShutdownSignal) { Tracer::trace(TRC_SERVER, Tracer::LEVEL3, "CIMServer::runForever - signal received. Shutting down."); myself->_monitor2->stop(); /* ShutdownService::getInstance(myself)->shutdown(true, 10, false); */ // MessageQueueService::force_shutdown(true); handleShutdownSignal = false; } } monitor_2* CIMServer::get_monitor2(void) { return _monitor2; } void CIMServer::runForever() { if(_type == OLD) { // Note: Trace code in this method will be invoked frequently. static int modulator = 0; if(!_dieNow) { if(false == _monitor->run(100)) { modulator++; if( ! (modulator % 5000) ) { try { MessageQueueService::_check_idle_flag = 1; MessageQueueService::_polling_sem.signal(); /* #ifdef PEGASUS_USE_23PROVIDER_MANAGER ProviderManagerService::getProviderManager()->unload_idle_providers(); #else _providerManager->unload_idle_providers(); #endif */ } catch(...) { } } } /* if (handleShutdownSignal) { Tracer::trace(TRC_SERVER, Tracer::LEVEL3, "CIMServer::runForever - signal received. Shutting down."); ShutdownService::getInstance(this)->shutdown(true, 10, false); handleShutdownSignal = false; } */ } } else { _monitor2->run(); // MessageQueueService::force_shutdown(true); } } void CIMServer::stopClientConnection() { PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::stopClientConnection()"); if(_type == OLD) { // tell Monitor to stop listening for client connections _monitor->stopListeningForConnections(); // // Wait 150 milliseconds to allow time for the Monitor to stop // listening for client connections. // // This wait time is the timeout value for the select() call // in the Monitor's run() method (currently set to 100 // milliseconds) plus a delta of 50 milliseconds. The reason // for the wait here is to make sure that the Monitor entries // are updated before closing the connection sockets. // PEG_TRACE_STRING(TRC_SERVER, Tracer::LEVEL4, "Wait 150 milliseconds."); pegasus_sleep(150); for (Uint32 i=0; i<_acceptors.size(); i++) { _acceptors[i]->closeConnectionSocket(); } } PEG_METHOD_EXIT(); } void CIMServer::shutdown() { PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::shutdown()"); _dieNow = true; PEG_METHOD_EXIT(); } void CIMServer::resume() { PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::resume()"); for (Uint32 i=0; i<_acceptors.size(); i++) { _acceptors[i]->reopenConnectionSocket(); } PEG_METHOD_EXIT(); } void CIMServer::setState(Uint32 state) { PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::setState()"); _serverState->setState(state); // // get the configured authentication and authorization flags // ConfigManager* configManager = ConfigManager::getInstance(); Boolean enableAuthentication = false; Boolean enableNamespaceAuthorization = false; if (String::equal( configManager->getCurrentValue("enableAuthentication"), "true")) { enableAuthentication = true; } if (String::equal( configManager->getCurrentValue("enableNamespaceAuthorization"), "true")) { enableNamespaceAuthorization = true; } if (state == CIMServerState::TERMINATING) { // tell decoder that CIMServer is terminating _cimOperationRequestDecoder->setServerTerminating(true); _cimExportRequestDecoder->setServerTerminating(true); // tell authorizer that CIMServer is terminating ONLY if // authentication and authorization are enabled // if ( enableAuthentication && enableNamespaceAuthorization ) { _cimOperationRequestAuthorizer->setServerTerminating(true); } } else { // tell decoder that CIMServer is not terminating _cimOperationRequestDecoder->setServerTerminating(false); _cimExportRequestDecoder->setServerTerminating(false); // tell authorizer that CIMServer is terminating ONLY if // authentication and authorization are enabled // if ( enableAuthentication && enableNamespaceAuthorization ) { _cimOperationRequestAuthorizer->setServerTerminating(false); } } PEG_METHOD_EXIT(); } Uint32 CIMServer::getOutstandingRequestCount() { PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::getOutstandingRequestCount()"); Uint32 requestCount = 0; if(_type == OLD) { for (Uint32 i=0; i<_acceptors.size(); i++) { requestCount += _acceptors[i]->getOutstandingRequestCount(); } } PEG_METHOD_EXIT(); return requestCount; } SSLContext* CIMServer::_getSSLContext() { static String PROPERTY_NAME__SSLCERT_FILEPATH = "sslCertificateFilePath"; static String PROPERTY_NAME__SSLKEY_FILEPATH = "sslKeyFilePath"; if (!_sslcontext.get()) { // // Get the sslCertificateFilePath property from the Config Manager. // String certPath; certPath = ConfigManager::getHomedPath( ConfigManager::getInstance()->getCurrentValue( PROPERTY_NAME__SSLCERT_FILEPATH)); // // Get the sslKeyFilePath property from the Config Manager. // String keyPath; keyPath = ConfigManager::getHomedPath( ConfigManager::getInstance()->getCurrentValue( PROPERTY_NAME__SSLKEY_FILEPATH)); String randFile = String::EMPTY; #ifdef PEGASUS_SSL_RANDOMFILE // NOTE: It is technically not necessary to set up a random file on // the server side, but it is easier to use a consistent interface // on the client and server than to optimize out the random file on // the server side. randFile = ConfigManager::getHomedPath(PEGASUS_SSLSERVER_RANDOMFILE); #endif _sslcontext.reset(new SSLContext(String::EMPTY, certPath, keyPath, 0, randFile)); } return _sslcontext.get(); } SSLContext* CIMServer::_getExportSSLContext() { PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::_getExportSSLContext()"); static const String PROPERTY_NAME__EXPORT_SSLTRUST_STORE = "exportSSLTrustStore"; static const String PROPERTY_NAME__SSLCERT_FILEPATH = "sslCertificateFilePath"; static const String PROPERTY_NAME__SSLKEY_FILEPATH = "sslKeyFilePath"; if (!_exportSSLContext.get()) { // // Get the exportSSLTrustStore property from the Config Manager. // String trustStore = ConfigManager::getInstance()->getCurrentValue( PROPERTY_NAME__EXPORT_SSLTRUST_STORE); if (trustStore == String::EMPTY) { MessageLoaderParms parms("Server.CIMServer.EXPORT_TRUST_EMPTY", "The \"exportSSLTrustStore\" configuration property must be set when \"enableSSLExportClientVerification\" is true. cimserver not started."); PEG_METHOD_EXIT(); throw Exception(parms); } String trustPath = ConfigManager::getHomedPath(trustStore); PEG_TRACE_STRING(TRC_SERVER, Tracer::LEVEL2, "Using the export trust store : " + trustPath); // // Get the sslCertificateFilePath property from the Config Manager. // String certPath = String::EMPTY; certPath = ConfigManager::getHomedPath( ConfigManager::getInstance()->getCurrentValue( PROPERTY_NAME__SSLCERT_FILEPATH)); // // Get the sslKeyFilePath property from the Config Manager. // String keyPath = String::EMPTY; keyPath = ConfigManager::getHomedPath( ConfigManager::getInstance()->getCurrentValue( PROPERTY_NAME__SSLKEY_FILEPATH)); String randFile = String::EMPTY; #ifdef PEGASUS_SSL_RANDOMFILE // NOTE: It is technically not necessary to set up a random file on // the server side, but it is easier to use a consistent interface // on the client and server than to optimize out the random file on // the server side. randFile = ConfigManager::getHomedPath(PEGASUS_SSLSERVER_RANDOMFILE); #endif // // Note: Trust store is used by default on Export connections, // verification callback function is not used. // _exportSSLContext.reset(new SSLContext(trustPath, certPath, keyPath, 0, randFile)); } PEG_METHOD_EXIT(); return _exportSSLContext.get(); } PEGASUS_NAMESPACE_END
No CVS admin address has been configured |
Powered by ViewCVS 0.9.2 |