version 1.1, 2002/11/19 21:32:49
|
version 1.2, 2003/08/15 22:45:40
|
|
|
// | // |
// Modified By: Mary Hinton (m.hinton@verizon.net) | // Modified By: Mary Hinton (m.hinton@verizon.net) |
// Sushma Fernandes (sushma_fernandes@hp.com) | // Sushma Fernandes (sushma_fernandes@hp.com) |
|
// Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com) |
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
|
|
#include <tchar.h> | #include <tchar.h> |
#include <direct.h> | #include <direct.h> |
| |
|
|
PEGASUS_USING_PEGASUS; | PEGASUS_USING_PEGASUS; |
PEGASUS_USING_STD; | PEGASUS_USING_STD; |
| |
|
|
int cimserver_kill( ) { return(0); } | int cimserver_kill( ) { return(0); } |
Boolean isCIMServerRunning( ) { return(false); } | Boolean isCIMServerRunning( ) { return(false); } |
| |
|
// notify parent process to terminate so user knows that cimserver |
|
// is ready to serve CIM requests. If this plateform needs to implement |
|
// this functionality, please see sample implementation in cimserver_unix.cpp |
|
void notify_parent(void) |
|
{ |
|
} |
|
|
static void __cdecl cimserver_windows_thread(void *parm) | static void __cdecl cimserver_windows_thread(void *parm) |
{ | { |
| |
|
|
// removes corresponding options and their arguments fromt he command | // removes corresponding options and their arguments fromt he command |
// line. | // line. |
| |
|
String pegasusHome; |
|
|
|
// mdh: need to get the environment for the Windows Service to run |
|
const char* tmp = getenv("PEGASUS_HOME"); |
|
if (tmp) |
|
{ |
|
pegasusHome = tmp; |
|
} |
|
|
|
ConfigManager::setPegasusHome(pegasusHome); |
|
|
ConfigManager* configManager = ConfigManager::getInstance(); | ConfigManager* configManager = ConfigManager::getInstance(); |
int dummy = 0; | int dummy = 0; |
String pegasusHome; |
//String pegasusHome; |
| |
try | try |
{ | { |
|
|
{ | { |
pegasusIOLog = true; | pegasusIOLog = true; |
} | } |
Boolean useSSL = false; |
|
| |
if (String::equal(configManager->getCurrentValue("SSL"), "true")) |
// The "SSL" property overrides the enableHttp*Connection properties and |
{ |
// enables only the HTTPS connection. |
useSSL = true; |
Boolean enableHttpConnection = String::equal( |
} |
configManager->getCurrentValue("enableHttpConnection"), "true"); |
|
|
// mdh: need to get the environment for the Windows Service to run |
Boolean enableHttpsConnection = String::equal( |
const char* tmp = getenv("PEGASUS_HOME"); |
configManager->getCurrentValue("enableHttpsConnection"), "true"); |
if (tmp) |
|
{ |
if (!enableHttpConnection && !enableHttpsConnection) |
pegasusHome = tmp; |
{ |
|
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING, |
|
"Neither HTTP nor HTTPS connection is enabled. " |
|
"CIMServer will not be started."); |
|
cerr << "Neither HTTP nor HTTPS connection is enabled. " |
|
"CIMServer will not be started." << endl; |
|
exit(1); |
} | } |
ConfigManager::setPegasusHome(pegasusHome); |
|
| |
// Grab the port otpion: |
// Get the connection port configurations |
| |
String portOption; |
Uint32 portNumberHttps; |
|
Uint32 portNumberHttp; |
| |
if (useSSL) |
if (enableHttpsConnection) |
{ | { |
portOption = configManager->getCurrentValue("httpsPort"); |
String httpsPort = configManager->getCurrentValue("httpsPort"); |
|
CString portString = httpsPort.getCString(); |
|
char* end = 0; |
|
Uint32 port = strtol(portString, &end, 10); |
|
assert(end != 0 && *end == '\0'); |
|
|
|
// |
|
// Look up the WBEM-HTTPS port number |
|
// |
|
portNumberHttps = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, port); |
} | } |
else |
|
|
if (enableHttpConnection) |
{ | { |
portOption = configManager->getCurrentValue("httpPort"); |
String httpPort = configManager->getCurrentValue("httpPort"); |
|
CString portString = httpPort.getCString(); |
|
char* end = 0; |
|
Uint32 port = strtol(portString, &end, 10); |
|
assert(end != 0 && *end == '\0'); |
|
|
|
// |
|
// Look up the WBEM-HTTP port number |
|
// |
|
portNumberHttp = System::lookupPort(WBEM_HTTP_SERVICE_NAME, port); |
} | } |
CString address = portOption.getCString(); |
|
| |
// Set up the Logger | // Set up the Logger |
Logger::setHomeDirectory("./logs"); | Logger::setHomeDirectory("./logs"); |
| |
// Put server start message to the logger | // Put server start message to the logger |
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, | Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, |
"Start $0 %1 port $2 $3 ", 88, PEGASUS_NAME, PEGASUS_VERSION, |
"Start $0 %1 $2 ", 88, PEGASUS_NAME, PEGASUS_VERSION, |
(const char*)address, (pegasusIOTrace ? " Tracing": " ")); |
(pegasusIOTrace ? " Tracing": " ")); |
|
// ATTN: Should this really be: ? |
|
//Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, |
|
// "Started $0 version $1.", PEGASUS_NAME, PEGASUS_VERSION); |
|
|
// try loop to bind the address, and run the server | // try loop to bind the address, and run the server |
try | try |
{ | { |
Monitor monitor; |
Monitor monitor(true); |
| |
CIMServer server(&monitor, useSSL); |
CIMServer server(&monitor); |
server_windows = &server; | server_windows = &server; |
| |
char* end = 0; |
if (enableHttpConnection) |
long portNumber = strtol(address, &end, 10); |
{ |
assert(end != 0 && *end == '\0'); |
server_windows->addAcceptor(false, portNumberHttp, false); |
|
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, |
|
"Listening on HTTP port $0.", portNumberHttp); |
|
} |
|
if (enableHttpsConnection) |
|
{ |
|
server_windows->addAcceptor(false, portNumberHttps, true); |
|
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, |
|
"Listening on HTTPS port $0.", portNumberHttps); |
|
} |
| |
server_windows->bind(portNumber); |
server_windows->bind(); |
| |
while(!server_windows->terminated()) | while(!server_windows->terminated()) |
{ | { |
|
|
///////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////// |
// Windows NT Service Control Code | // Windows NT Service Control Code |
///////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////// |
|
|
|
|
|
|
|
|
VOID WINAPI cimserver_windows_main(int argc, char **argv) | VOID WINAPI cimserver_windows_main(int argc, char **argv) |
{ | { |
int ccode; | int ccode; |
SERVICE_TABLE_ENTRY dispatch_table[] = | SERVICE_TABLE_ENTRY dispatch_table[] = |
{ | { |
{"cimserver", cimserver_service_start}, |
{"wmiserver", cimserver_service_start}, |
{NULL, NULL} | {NULL, NULL} |
}; | }; |
| |
|
|
Logger::put(Logger::STANDARD_LOG, "CIMServer_Windows", Logger::INFORMATION, | Logger::put(Logger::STANDARD_LOG, "CIMServer_Windows", Logger::INFORMATION, |
"Started as a Windows Service"); | "Started as a Windows Service"); |
} | } |
|
|
return; | return; |
} | } |
| |
|
|
// called by the NT service control manager to start the SLP service | // called by the NT service control manager to start the SLP service |
// | // |
///////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////// |
|
|
VOID WINAPI cimserver_service_start(DWORD argc, LPTSTR *argv) | VOID WINAPI cimserver_service_start(DWORD argc, LPTSTR *argv) |
{ | { |
| |
|
|
pegasus_status.dwServiceSpecificExitCode = 0; | pegasus_status.dwServiceSpecificExitCode = 0; |
pegasus_status.dwCheckPoint = 0; | pegasus_status.dwCheckPoint = 0; |
pegasus_status.dwWaitHint = 0; | pegasus_status.dwWaitHint = 0; |
|
pegasus_status_handle = RegisterServiceCtrlHandler("wmiserver", cimserver_service_ctrl_handler); |
| |
pegasus_status_handle = RegisterServiceCtrlHandler("cimserver", cimserver_service_ctrl_handler); |
|
if( pegasus_status_handle == (SERVICE_STATUS_HANDLE)0) | if( pegasus_status_handle == (SERVICE_STATUS_HANDLE)0) |
{ | { |
Logger::put(Logger::STANDARD_LOG, "CIMServer_Windows", Logger::INFORMATION, | Logger::put(Logger::STANDARD_LOG, "CIMServer_Windows", Logger::INFORMATION, |
|
|
if(NULL != (sc_manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS))) | if(NULL != (sc_manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS))) |
{ | { |
if(NULL != (service_handle = OpenService(sc_manager, | if(NULL != (service_handle = OpenService(sc_manager, |
"cimserver", |
"wmiserver", |
SERVICE_ALL_ACCESS))) | SERVICE_ALL_ACCESS))) |
| |
{ | { |
|
|
runPath->remove(position, len - position); | runPath->remove(position, len - position); |
} | } |
} | } |
|
|
free(svc_config); | free(svc_config); |
} | } |
} | } |
|
|
CloseServiceHandle(service_handle); | CloseServiceHandle(service_handle); |
} | } |
|
|
CloseServiceHandle(sc_manager); | CloseServiceHandle(sc_manager); |
} | } |
| |
|
|
return; | return; |
} | } |
| |
|
///////////////////////////////////////////////////////////////// |
|
// |
|
///////////////////////////////////////////////////////////////// |
VOID WINAPI cimserver_service_ctrl_handler(DWORD opcode) | VOID WINAPI cimserver_service_ctrl_handler(DWORD opcode) |
{ | { |
|
switch(opcode) |
switch(opcode) { |
{ |
case SERVICE_CONTROL_STOP: | case SERVICE_CONTROL_STOP: |
case SERVICE_CONTROL_SHUTDOWN: | case SERVICE_CONTROL_SHUTDOWN: |
if(server_windows != NULL) | if(server_windows != NULL) |
|
|
default: | default: |
break; | break; |
} | } |
|
|
SetServiceStatus(pegasus_status_handle, &pegasus_status); | SetServiceStatus(pegasus_status_handle, &pegasus_status); |
|
|
return; | return; |
} | } |
| |
|
///////////////////////////////////////////////////////////////// |
|
// |
|
///////////////////////////////////////////////////////////////// |
DWORD cimserver_initialization(DWORD argc, LPTSTR *argv, DWORD *specificError) | DWORD cimserver_initialization(DWORD argc, LPTSTR *argv, DWORD *specificError) |
{ | { |
|
|
return( _beginthread(cimserver_windows_thread, 0, NULL )); | return( _beginthread(cimserver_windows_thread, 0, NULL )); |
} | } |
| |
|
///////////////////////////////////////////////////////////////// |
|
// |
|
///////////////////////////////////////////////////////////////// |
Uint32 cimserver_install_nt_service(String &pegasusHome ) | Uint32 cimserver_install_nt_service(String &pegasusHome ) |
{ | { |
SC_HANDLE service_handle, sc_manager; | SC_HANDLE service_handle, sc_manager; |
Uint32 ccode = 0; | Uint32 ccode = 0; |
pegasusHome.append("\\bin\\cimserver.exe"); |
|
|
pegasusHome.append("\\bin\\wmiserver.exe"); |
|
|
CString pegHome = pegasusHome.getCString() ; | CString pegHome = pegasusHome.getCString() ; |
LPCSTR path_name = (const char*) pegHome; | LPCSTR path_name = (const char*) pegHome; |
|
|
if(NULL != (sc_manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS))) | if(NULL != (sc_manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS))) |
{ | { |
if(NULL != (service_handle = CreateService(sc_manager, | if(NULL != (service_handle = CreateService(sc_manager, |
"cimserver", |
"wmiserver", |
"Pegasus CIM Object Manager", |
"Pegasus WMI Mapper", |
SERVICE_ALL_ACCESS, | SERVICE_ALL_ACCESS, |
SERVICE_WIN32_OWN_PROCESS, | SERVICE_WIN32_OWN_PROCESS, |
SERVICE_DEMAND_START, | SERVICE_DEMAND_START, |
SERVICE_ERROR_NORMAL, | SERVICE_ERROR_NORMAL, |
path_name, | path_name, |
NULL, NULL, NULL, NULL, NULL))) |
NULL, |
|
NULL, |
|
NULL, |
|
NULL, |
|
NULL))) |
{ | { |
ccode = (Uint32)service_handle; | ccode = (Uint32)service_handle; |
} | } |
|
|
CloseServiceHandle(service_handle); | CloseServiceHandle(service_handle); |
} | } |
| |
return(ccode); | return(ccode); |
} | } |
| |
|
///////////////////////////////////////////////////////////////// |
|
// |
|
///////////////////////////////////////////////////////////////// |
Uint32 cimserver_remove_nt_service(void) | Uint32 cimserver_remove_nt_service(void) |
{ | { |
| |
SC_HANDLE service_handle, sc_manager; | SC_HANDLE service_handle, sc_manager; |
int ccode = 0; | int ccode = 0; |
|
|
if(NULL != (sc_manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS))) | if(NULL != (sc_manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS))) |
{ | { |
if(NULL != (service_handle = OpenService(sc_manager, "cimserver", DELETE))) |
if(NULL != (service_handle = OpenService(sc_manager, "wmiserver", DELETE))) |
{ | { |
DeleteService(service_handle); | DeleteService(service_handle); |
CloseServiceHandle(service_handle); | CloseServiceHandle(service_handle); |
ccode = 1; | ccode = 1; |
} | } |
|
|
CloseServiceHandle(sc_manager); | CloseServiceHandle(sc_manager); |
} | } |
|
|
return(ccode); | return(ccode); |
} | } |