Skip to content

Commit

Permalink
Fixed installer not importing old config
Browse files Browse the repository at this point in the history
  • Loading branch information
mickem committed Jan 12, 2025
1 parent ada0986 commit ed04080
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 5 deletions.
35 changes: 35 additions & 0 deletions installer_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,41 @@ else(WIN32)
set(VERSION_ARCH Unknown)
endif(WIN32)

set(INSTALL_FILES_BASE "")

set(CONFIG_BOOT_CONF_LOCATION
"\${exe-path}/boot.ini"
CACHE
STRING
"Location of boot ini (the file which specified where to load the config)"
)
set(CONFIG_DEFAULT_CONF_LOCATION
"old"
CACHE STRING "Default configuration store")
set(CONFIG_DEFAULT_CONF_INI_BASE
"ini://\${shared-path}/"
CACHE STRING "Base location for ini files")
set(CONFIG_MODULE_FOLDER
"\${exe-path}/modules"
CACHE STRING "modules folder")
set(CONFIG_WEB_FOLDER
"\${shared-path}/web"
CACHE STRING "web folder")
set(CONFIG_SCRIPTS_FOLDER
"\${exe-path}/scripts"
CACHE STRING "script folder")
set(CONFIG_CERT_FOLDER
"\${shared-path}/security"
CACHE STRING "securoty (certificates) folder")
set(CONFIG_DEFAULT_CACHE_PATH
"\${shared-path}/cache"
CACHE STRING "Path for caching stuff")
set(CONFIG_LOG_FOLDER
"\${shared-path}/log"
CACHE STRING "Path for log files")
set(CONFIG_DEFAULT_LOG_LOCATION
"\${exe-path}/nsclient.log"
CACHE STRING "PAth for log file")

configure_file(${NSCP_INCLUDEDIR}/config.h.in
${PROJECT_BINARY_DIR}/include/config.h @ONLY)
Expand Down
1 change: 0 additions & 1 deletion installer_lib/installer_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class msi_helper {
logMessage(L"installer_lib::" + action);
}
~msi_helper() {
MsiCloseHandle(hInstall_);
hInstall_ = NULL;
}

Expand Down
15 changes: 13 additions & 2 deletions installer_lib/installer_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ class msi_logger : public nsclient::logging::logger {


void debug(const std::string& module, const char* file, const int line, const std::string& message) {
do_log("debug: " + message);
}
void trace(const std::string& module, const char* file, const int line, const std::string& message) {
}
void info(const std::string& module, const char* file, const int line, const std::string& message) {
do_log("info: " + message);
}
void warning(const std::string& module, const char* file, const int line, const std::string& message) {
do_log("warning: " + message);
Expand All @@ -106,9 +108,11 @@ class msi_logger : public nsclient::logging::logger {


void do_log(const std::string data) {

std::wstring str = utf8::cvt<std::wstring>(data);
if (str.empty())
return;
h->setProperty(L"NSCP_ERROR_LOG", L"Error: " + str);
if (boost::algorithm::starts_with(str, L"error:")) {
if (!error_.empty())
error_ += L"\n";
Expand Down Expand Up @@ -150,7 +154,7 @@ class msi_logger : public nsclient::logging::logger {


void nsclient::logging::log_message_factory::log_fatal(std::string message) {
// std::cout << message << "\n";
// std::cout << message << "\n";
}

std::string nsclient::logging::log_message_factory::create_critical(const std::string &module, const char* file, const int line, const std::string &message) {
Expand Down Expand Up @@ -318,6 +322,8 @@ std::wstring read_map_data(msi_helper &h) {
#define KEY_CONF_OLD_ERROR KEY CONF_OLD_ERROR
#define KEY_CONF_HAS_ERRORS KEY CONF_HAS_ERRORS

#define ERROR_KEY L"NSCP_ERROR"


void dump_config(msi_helper &h, std::wstring title) {
h.dumpReason(title);
Expand Down Expand Up @@ -446,6 +452,7 @@ extern "C" UINT __stdcall ImportConfig(MSIHANDLE hInstall) {

std::wstring map_data = read_map_data(h);
if (allow == L"0") {
h.setProperty(ERROR_KEY, L"Configuration is not allowed to change");
h.logMessage(L"Configuration not allowed: " + allow);
h.setProperty(KEY_CONF_CAN_CHANGE, L"0");
h.setProperty(KEY_CONF_HAS_ERRORS, L"0");
Expand All @@ -454,7 +461,8 @@ extern "C" UINT __stdcall ImportConfig(MSIHANDLE hInstall) {
}

if (!boost::filesystem::is_directory(utf8::cvt<std::string>(target))) {
h.logMessage(L"Target folder not found: " + target);
h.setProperty(ERROR_KEY, L"Configuration not found: " + target);
h.logMessage(L"Target folder not found: " + target);
h.setProperty(KEY_CONF_CAN_CHANGE, L"1");
h.setProperty(KEY_CONF_HAS_ERRORS, L"0");
dump_config(h, L"After ImportConfig");
Expand All @@ -463,6 +471,7 @@ extern "C" UINT __stdcall ImportConfig(MSIHANDLE hInstall) {

installer_settings_provider provider(&h, target, map_data);
if (!settings_manager::init_installer_settings(&provider, "")) {
h.setProperty(ERROR_KEY, L"Settings context had fatal errors");
h.logMessage(L"Settings context had fatal errors");
h.setProperty(KEY_CONF_OLD_ERROR, provider.get_error());
h.setProperty(KEY_CONF_CAN_CHANGE, L"0");
Expand Down Expand Up @@ -554,12 +563,14 @@ extern "C" UINT __stdcall ImportConfig(MSIHANDLE hInstall) {
dump_config(h, L"After ImportConfig");

} catch (installer_exception e) {
h.setProperty(ERROR_KEY, L"Installer exception");
h.logMessage(L"Failed to read old configuration file: " + e.what());
h.setProperty(KEY_CONF_OLD_ERROR, e.what());
h.setProperty(KEY_CONF_CAN_CHANGE, L"0");
h.setProperty(KEY_CONF_HAS_ERRORS, L"1");
return ERROR_SUCCESS;
} catch (...) {
h.setProperty(ERROR_KEY, L"Unknown exception");
h.logMessage(L"Failed to read old configuration file: Unknown exception");
h.setProperty(KEY_CONF_OLD_ERROR, L"Unknown exception!");
h.setProperty(KEY_CONF_CAN_CHANGE, L"0");
Expand Down
4 changes: 3 additions & 1 deletion installers/installer-NSCP/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@
<CustomAction Id='ImportConfig' BinaryKey='InstallerHelper' DllEntry='ImportConfig' Impersonate='yes' Execute="immediate" Return="check" />
<CustomAction Id='ScheduleWriteConfig' BinaryKey='InstallerHelper' DllEntry='ScheduleWriteConfig' Impersonate='yes' Execute="immediate" Return="check" />
<CustomAction Id="ApplyTool" BinaryKey="InstallerHelper" DllEntry="ApplyTool" Impersonate="yes" Execute="immediate" Return="check" />
<CustomAction Id="DetectTool" BinaryKey="InstallerHelper" DllEntry="DetectTool" Impersonate="no" Execute="immediate" Return="check" />
<CustomAction Id="DetectTool" BinaryKey="InstallerHelper" DllEntry="DetectTool" Impersonate="yes" Execute="immediate" Return="check" />
<CustomAction Id="ExecWriteConfig" BinaryKey="InstallerHelper" DllEntry="ExecWriteConfig" Impersonate="no" Execute="deferred" Return="check" />

<CustomAction Id='NeedUninstall' BinaryKey='InstallerHelper' DllEntry='NeedUninstall' Impersonate='yes' Execute="immediate" Return="check" />
Expand Down Expand Up @@ -310,6 +310,8 @@
<Custom Action="PreventDowngrading" After="FindRelatedProducts">NEWAPPFOUND</Custom>
<Custom Action="NeedUninstall" After="FindRelatedProducts">1</Custom>
<Custom Action="DetectTool" After="NeedUninstall">1</Custom>


</InstallUISequence>

<Property Id="ALLUSERS">
Expand Down
2 changes: 2 additions & 0 deletions installers/ui/WixUI_MondoNSCP.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Patch dialog sequence:
<Publish Dialog="SetupTypeDlg" Control="TypicalButton" Event="NewDialog" Value="InvalidConfigureationDlg" Order="4">KEY_CONF_HAS_ERRORS = "1"</Publish>
<Publish Dialog="SetupTypeDlg" Control="TypicalButton" Event="NewDialog" Value="ConfigureDlg" Order="2">KEY_CONF_CAN_CHANGE = "1"</Publish>
<Publish Dialog="SetupTypeDlg" Control="TypicalButton" Event="NewDialog" Value="VerifyReadyDlg" Order="1">1</Publish>
<Publish Dialog="SetupTypeDlg" Control="TypicalButton" Event="DoAction" Value="ImportConfig">1</Publish>

<Publish Dialog="SetupTypeDlg" Control="CustomButton" Event="NewDialog" Value="CustomizeDlg">1</Publish>
<Publish Dialog="SetupTypeDlg" Control="CompleteButton" Event="NewDialog" Value="InvalidConfigureationDlg" Order="4">KEY_CONF_HAS_ERRORS = "1"</Publish>
<Publish Dialog="SetupTypeDlg" Control="CompleteButton" Event="NewDialog" Value="SelectConfigurationDlg" Order="3">CONF_OLD_FOUND="0"</Publish>
Expand Down
2 changes: 1 addition & 1 deletion libs/settings_manager/settings_manager_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ namespace settings_manager {
return settings::instance_raw_ptr(new settings::INISettings(this, alias, key));
if (settings::INISettings::context_exists(this, DEFAULT_CONF_INI_BASE + key))
return settings::instance_raw_ptr(new settings::INISettings(this,alias, DEFAULT_CONF_INI_BASE + key));
throw settings::settings_exception(__FILE__, __LINE__, "Undefined settings protocol: " + url.protocol);
throw settings::settings_exception(__FILE__, __LINE__, "Undefined settings protocol: " + url.protocol + ", key=" + key);
}

bool NSCSettingsImpl::supports_edit(const std::string key) {
Expand Down

0 comments on commit ed04080

Please sign in to comment.