-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Service_GetStatus call - addressed issues mentioned in the previous request #8
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,3 +171,44 @@ CA_API UINT __stdcall Service_Exists(MSIHANDLE hInstall) | |
MSI_EXCEPTION_HANDLER_EPILOG; | ||
return ERROR_SUCCESS; | ||
} | ||
|
||
|
||
static std::wstring serviceStatusString(DWORD dwCurrentState) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be moved into the service implementation itself as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want it to be moved as-is (i.e. ServiceInstance static function converting int to string), or member function similar to ServiceInstance::GetServiceState, but returning string? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it should be static. Member function returning a string. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GetServiceStateString() then? |
||
{ | ||
const wchar_t* st = L"Unknown"; | ||
|
||
switch (dwCurrentState) { | ||
case SERVICE_STOPPED: st = L"Stopped"; break; | ||
case SERVICE_START_PENDING: st = L"Starting"; break; | ||
case SERVICE_STOP_PENDING: st = L"Stopping"; break; | ||
case SERVICE_RUNNING: st = L"Running"; break; | ||
case SERVICE_CONTINUE_PENDING: st = L"Resuming"; break; | ||
case SERVICE_PAUSE_PENDING: st = L"Pausing"; break; | ||
case SERVICE_PAUSED: st = L"Paused"; break; | ||
} | ||
return st; | ||
} | ||
|
||
CA_API UINT __stdcall Service_GetStatus(MSIHANDLE hInstall) | ||
{ | ||
MSI_EXCEPTION_HANDLER_PROLOG; | ||
MsiInstall msiInstall(hInstall); | ||
|
||
std::wstring service_name = msiInstall.GetProperty(L"SERVICE_STATUS_SERVICE_NAME"); | ||
if (service_name.empty()) { | ||
service_name = msiInstall.GetProperty(L"SERVICE_NAME"); | ||
} | ||
|
||
AppSecInc::Service::ServiceManager scm; | ||
scm.Open(SC_MANAGER_CONNECT|STANDARD_RIGHTS_READ); | ||
AppSecInc::Service::ServiceInstance service; | ||
service.Open( scm, service_name ); | ||
SERVICE_STATUS_PROCESS st; | ||
service.GetServiceProcessStatus( &st ); | ||
|
||
msiInstall.SetProperty(L"SERVICE_STATUS", serviceStatusString(st.dwCurrentState)); | ||
|
||
MSI_EXCEPTION_HANDLER_EPILOG; | ||
return ERROR_SUCCESS; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ void ServiceImplUnitTests::Test_EntryPoints() | |
CPPUNIT_ASSERT(NULL != GetProcAddress(h, "Service_Delete")); | ||
CPPUNIT_ASSERT(NULL != GetProcAddress(h, "Service_GetConfig")); | ||
CPPUNIT_ASSERT(NULL != GetProcAddress(h, "Service_Exists")); | ||
CPPUNIT_ASSERT(NULL != GetProcAddress(h, "Service_GetStatus")); | ||
::FreeLibrary(h); | ||
} | ||
|
||
|
@@ -218,3 +219,37 @@ void ServiceImplUnitTests::Test_Service_Exists() | |
CPPUNIT_ASSERT(ERROR_SUCCESS == hInstall.ExecuteCA(L"SystemTools.dll", L"Service_Exists")); | ||
CPPUNIT_ASSERT(L"0" == msiInstall.GetProperty(L"SERVICE_EXISTS")); | ||
} | ||
|
||
void ServiceImplUnitTests::Test_Service_GetStatus() | ||
{ | ||
AppSecInc::Msi::MsiShim hInstall; | ||
MsiInstall msiInstall(hInstall); | ||
|
||
msiInstall.SetProperty(L"SERVICE_STATUS_SERVICE_NAME", L"W32Time"); | ||
CPPUNIT_ASSERT(ERROR_SUCCESS == hInstall.ExecuteCA(L"SystemTools.dll", L"Service_GetStatus")); | ||
CPPUNIT_ASSERT(L"Running" == msiInstall.GetProperty(L"SERVICE_STATUS")); | ||
|
||
msiInstall.SetProperty(L"SERVICE_STATUS_SERVICE_NAME", L"Wecsvc"); | ||
CPPUNIT_ASSERT(ERROR_SUCCESS == hInstall.ExecuteCA(L"SystemTools.dll", L"Service_GetStatus")); | ||
CPPUNIT_ASSERT(L"Stopped" == msiInstall.GetProperty(L"SERVICE_STATUS")); | ||
|
||
msiInstall.SetProperty(L"SERVICE_STATUS_SERVICE_NAME", AppSecInc::Com::GenerateGUIDStringW()); | ||
CPPUNIT_ASSERT(ERROR_SUCCESS != hInstall.ExecuteCA(L"SystemTools.dll", L"Service_GetStatus")); | ||
// SERVICE_STATUS should remain unchainged | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo here, unchanged |
||
CPPUNIT_ASSERT(L"Stopped" == msiInstall.GetProperty(L"SERVICE_STATUS")); | ||
} | ||
|
||
void ServiceImplUnitTests::Test_Service_GetStatus_accepts_SERVICE_NAME() | ||
{ | ||
AppSecInc::Msi::MsiShim hInstall; | ||
MsiInstall msiInstall(hInstall); | ||
|
||
msiInstall.SetProperty(L"SERVICE_NAME", L"W32Time"); | ||
CPPUNIT_ASSERT(ERROR_SUCCESS == hInstall.ExecuteCA(L"SystemTools.dll", L"Service_GetStatus")); | ||
CPPUNIT_ASSERT(L"Running" == msiInstall.GetProperty(L"SERVICE_STATUS")); | ||
|
||
// more specific name should override generic one: | ||
msiInstall.SetProperty(L"SERVICE_STATUS_SERVICE_NAME", L"Wecsvc"); | ||
CPPUNIT_ASSERT(ERROR_SUCCESS == hInstall.ExecuteCA(L"SystemTools.dll", L"Service_GetStatus")); | ||
CPPUNIT_ASSERT(L"Stopped" == msiInstall.GetProperty(L"SERVICE_STATUS")); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ namespace AppSecInc | |
CPPUNIT_TEST( Test_Service_Delete ); | ||
CPPUNIT_TEST( Test_Service_GetConfig ); | ||
CPPUNIT_TEST( Test_Service_Exists ); | ||
CPPUNIT_TEST( Test_Service_GetStatus ); | ||
CPPUNIT_TEST( Test_Service_GetStatus_accepts_SERVICE_NAME ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: accepts should be Accepts, to match the rest of the code. |
||
CPPUNIT_TEST_SUITE_END(); | ||
private: | ||
std::wstring service_name; | ||
|
@@ -33,6 +35,8 @@ namespace AppSecInc | |
void Test_Service_Control(); | ||
void Test_Service_GetConfig(); | ||
void Test_Service_Exists(); | ||
void Test_Service_GetStatus(); | ||
void Test_Service_GetStatus_accepts_SERVICE_NAME(); | ||
}; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this a link to the pull request, with your name, like the other ones below.