Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #13 from vladaver/alt-name
Added SERVICE_NAME as an alternative property for specifying service name in Service_Change... calls
  • Loading branch information
dblock committed May 15, 2014
2 parents 3cfb7d6 + 4d6e03c commit 6203b66
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,6 +1,7 @@
### 1.5 (Next Release)

* **Features**:
* Added `SERVICE_NAME` as an alternative property for specifying service name in Service_Change... calls - [@vladaver](https://github.com/vladaver).
* [#8](https://github.com/dblock/msiext/pull/8) - Added `Service_GetState` immediate custom action - [@vladaver](https://github.com/vladaver).
* **Bugs**:
* **Misc**:
Expand Down
10 changes: 10 additions & 0 deletions src/CustomActions/SystemTools/ServiceImpl.cpp
Expand Up @@ -32,6 +32,10 @@ CA_API UINT __stdcall Service_ChangeBinaryPathName(MSIHANDLE hInstall)
MsiInstall msiInstall(hInstall);

std::wstring service_name = msiInstall.GetProperty(L"SERVICE_CHANGE_SERVICE_NAME");
if (service_name.empty()) {
service_name = msiInstall.GetProperty(L"SERVICE_NAME");
}

std::wstring service_binary_path = msiInstall.GetProperty(L"SERVICE_CHANGE_BINARY_PATH_NAME");

AppSecInc::Service::ServiceManager scm;
Expand All @@ -55,6 +59,9 @@ CA_API UINT __stdcall Service_ChangeDisplayName(MSIHANDLE hInstall)
MsiInstall msiInstall(hInstall);

std::wstring service_name = msiInstall.GetProperty(L"SERVICE_CHANGE_SERVICE_NAME");
if (service_name.empty()) {
service_name = msiInstall.GetProperty(L"SERVICE_NAME");
}
std::wstring service_display_name = msiInstall.GetProperty(L"SERVICE_CHANGE_DISPLAY_NAME");

AppSecInc::Service::ServiceManager scm;
Expand All @@ -78,6 +85,9 @@ CA_API UINT __stdcall Service_ChangeDescription(MSIHANDLE hInstall)
MsiInstall msiInstall(hInstall);

std::wstring service_name = msiInstall.GetProperty(L"SERVICE_CHANGE_SERVICE_NAME");
if (service_name.empty()) {
service_name = msiInstall.GetProperty(L"SERVICE_NAME");
}
std::wstring service_description = msiInstall.GetProperty(L"SERVICE_CHANGE_DESCRIPTION");

AppSecInc::Service::ServiceManager scm;
Expand Down
9 changes: 6 additions & 3 deletions src/CustomActions/SystemTools/ServiceImpl.h
Expand Up @@ -20,9 +20,10 @@ CA_API UINT __stdcall Service_RenameRegistryEntry(MSIHANDLE hInstall);
\brief Change the path to the service binary file of a service
The path to the service binary file of the service specified in
SERVICE_CHANGE_SERVICE_NAME is set to SERVICE_CHANGE_BINARY_PATH_NAME.
SERVICE_CHANGE_SERVICE_NAME or SERVICE_NAME is set to SERVICE_CHANGE_BINARY_PATH_NAME.
\param SERVICE_CHANGE_SERVICE_NAME name of the service
\param SERVICE_NAME alternative property for service name, used when SERVICE_CHANGE_SERVICE_NAME is not set
\param SERVICE_CHANGE_BINARY_PATH_NAME new fully qualified path to the service binary file.
\return check CA_ERROR on function failure
Expand All @@ -34,10 +35,11 @@ CA_API UINT __stdcall Service_ChangeBinaryPathName(MSIHANDLE hInstall);
\brief Change the display name of a service
Changes the display name of the service specified in SERVICE_CHANGE_SERVICE_NAME.
Changes the display name of the service specified in SERVICE_CHANGE_SERVICE_NAME or SERVICE_NAME.
The display name is changed to SERVICE_CHANGE_DISPLAY_NAME.
\param SERVICE_CHANGE_SERVICE_NAME name of the service
\param SERVICE_NAME alternative property for service name, used when SERVICE_CHANGE_SERVICE_NAME is not set
\param SERVICE_CHANGE_DISPLAY_NAME new display name
\return check CA_ERROR on function failure
Expand All @@ -49,10 +51,11 @@ CA_API UINT __stdcall Service_ChangeDisplayName(MSIHANDLE hInstall);
\brief Change the description of a service
Changes the description of the service specified in SERVICE_CHANGE_SERVICE_NAME.
Changes the description of the service specified in SERVICE_CHANGE_SERVICE_NAME or SERVICE_NAME.
The description is changed to SERVICE_CHANGE_DESCRIPTION.
\param SERVICE_CHANGE_SERVICE_NAME name of the service
\param SERVICE_NAME alternative property for service name, used when SERVICE_CHANGE_SERVICE_NAME is not set
\param SERVICE_CHANGE_DESCRIPTION new description
\return check CA_ERROR on function failure
Expand Down
24 changes: 24 additions & 0 deletions src/CustomActions/SystemTools/ServiceImplUnitTests.cpp
Expand Up @@ -74,6 +74,30 @@ void ServiceImplUnitTests::Test_Service_ChangeBinaryPathName()
CPPUNIT_ASSERT(testinstance.GetConfig().binary_path_name == L"C:\\test.exe");
}

void ServiceImplUnitTests::Test_Service_ChangeBinaryPathName_Accepts_SERVICE_NAME()
{
AppSecInc::Msi::MsiShim hInstall;
MsiInstall msiInstall(hInstall);

std::wstring serviceBinaryPathName = L"";
std::wstring serviceDisplayName = L"";
std::wstring serviceDescription = L"";

AppSecInc::Service::ServiceManager scm;
scm.Open();
AppSecInc::Service::ServiceInstance testinstance;
testinstance.Open(scm, service_name);

CPPUNIT_ASSERT(testinstance.GetConfig().binary_path_name != L"C:\\test.exe");

msiInstall.SetProperty(L"SERVICE_NAME", service_name);
msiInstall.SetProperty(L"SERVICE_CHANGE_BINARY_PATH_NAME", L"C:\\test.exe");

CPPUNIT_ASSERT(ERROR_SUCCESS == hInstall.ExecuteCA(L"SystemTools.dll", L"Service_ChangeBinaryPathName"));

CPPUNIT_ASSERT(testinstance.GetConfig().binary_path_name == L"C:\\test.exe");
}

void ServiceImplUnitTests::Test_Service_ChangeDisplayName()
{
AppSecInc::Msi::MsiShim hInstall;
Expand Down
2 changes: 2 additions & 0 deletions src/CustomActions/SystemTools/ServiceImplUnitTests.h
Expand Up @@ -12,6 +12,7 @@ namespace AppSecInc
CPPUNIT_TEST( Test_EntryPoints );
CPPUNIT_TEST( Test_Service_RenameRegistryEntry );
CPPUNIT_TEST( Test_Service_ChangeBinaryPathName );
CPPUNIT_TEST( Test_Service_ChangeBinaryPathName_Accepts_SERVICE_NAME );
CPPUNIT_TEST( Test_Service_ChangeDisplayName );
CPPUNIT_TEST( Test_Service_ChangeDescription );
CPPUNIT_TEST( Test_Service_Control );
Expand All @@ -29,6 +30,7 @@ namespace AppSecInc
void Test_EntryPoints();
void Test_Service_RenameRegistryEntry();
void Test_Service_ChangeBinaryPathName();
void Test_Service_ChangeBinaryPathName_Accepts_SERVICE_NAME();
void Test_Service_ChangeDisplayName();
void Test_Service_ChangeDescription();
void Test_Service_Delete();
Expand Down

0 comments on commit 6203b66

Please sign in to comment.