Permalink
Browse files

installer: Fixed some regression issues with related to settings fix

  • Loading branch information...
1 parent c2f6e7d commit 1f7c0a71f80087b06b0f09832d9accf6f34911b9 @mickem committed Nov 29, 2016
@@ -98,7 +98,7 @@ class msi_helper {
MsiSetFeatureState(hInstall_, feature.c_str(), INSTALLSTATE_LOCAL);
}
void setFeatureAbsent(std::wstring feature) {
- MsiSetFeatureState(hInstall_, feature.c_str(), INSTALLSTATE_REMOVED);
+ MsiSetFeatureState(hInstall_, feature.c_str(), INSTALLSTATE_ABSENT);
}
void setPropertyIfEmpty(std::wstring key, std::wstring val) {
std::wstring old = getPropery(key);
@@ -129,14 +129,14 @@ class msi_helper {
MsiSetProperty(hInstall_, key.c_str(), value.c_str());
}
void applyProperty(std::wstring key, std::wstring value_key) {
- std::wstring old_value = getPropery(key);
- std::wstring new_value = getPropery(value_key);
+ std::wstring current_value = getPropery(key);
+ std::wstring applied_value = getPropery(value_key);
logMessage(_T("Applying value from ") + value_key + _T(" to ") + key);
- if (new_value.empty()) {
- logMessage(_T(" + ") + key + _T(" goes from ") + old_value + _T(" to ") + new_value);
- setProperty(key, new_value);
+ if (!applied_value.empty()) {
+ logMessage(_T(" + ") + key + _T(" goes from ") + current_value + _T(" to ") + applied_value);
+ setProperty(key, applied_value);
} else {
- logMessage(_T(" + ") + key + _T(" unchanged as overriden value was empty: keeping ") + old_value + _T(" over ") + new_value);
+ logMessage(_T(" + ") + key + _T(" unchanged as overriden value was empty: keeping ") + current_value + _T(" over ") + applied_value);
}
}
@@ -40,9 +40,12 @@ void copy_file(msi_helper &h, std::wstring source, std::wstring target) {
class msi_logger : public nsclient::logging::logger_impl {
std::wstring error;
std::list<std::wstring> log_;
+ msi_helper *h;
public:
- msi_logger() {}
+ msi_logger(msi_helper *h) : h(h) {
+ set_log_level("trace");
+ }
void do_log(const std::string data) {
@@ -55,6 +58,7 @@ class msi_logger : public nsclient::logging::logger_impl {
error += str.substr(1);
}
log_.push_back(str.substr(1));
+ h->logMessage(str);
}
void asynch_configure() {}
void synch_configure() {}
@@ -123,9 +127,16 @@ struct installer_settings_provider : public settings_manager::provider_interface
: h(h)
, basepath(utf8::cvt<std::string>(basepath))
, old_settings_map(utf8::cvt<std::string>(old_settings_map))
- , logger(new msi_logger())
- {}
- installer_settings_provider(msi_helper *h, std::wstring basepath) : h(h), basepath(utf8::cvt<std::string>(basepath)) {}
+ , logger(new msi_logger(h))
+ {
+ }
+ installer_settings_provider(msi_helper *h, std::wstring basepath)
+ : h(h)
+ , basepath(utf8::cvt<std::string>(basepath))
+ , old_settings_map(utf8::cvt<std::string>(old_settings_map))
+ , logger(new msi_logger(h))
+ {
+ }
virtual std::string expand_path(std::string file) {
strEx::s::replace(file, "${base-path}", basepath);
@@ -243,6 +254,28 @@ std::wstring read_map_data(msi_helper &h) {
#define KEY_CONF_HAS_ERRORS KEY CONF_HAS_ERRORS
+void dump_config(msi_helper &h, std::wstring title) {
+ h.dumpReason(title);
+ h.dumpProperty(KEY_ALLOWED_HOSTS);
+ h.dumpProperty(KEY_NSCLIENT_PWD);
+ h.dumpProperty(KEY_NSCLIENT_PWD_DEFAULT);
+ h.dumpProperty(KEY_CONF_SCHEDULER);
+ h.dumpProperty(KEY_CONF_CHECKS);
+ h.dumpProperty(KEY_CONF_NRPE);
+ h.dumpProperty(KEY_CONF_NSCA);
+ h.dumpProperty(KEY_CONF_WEB);
+ h.dumpProperty(KEY_CONF_NSCLIENT);
+ h.dumpProperty(KEY_NRPEMODE);
+
+ h.dumpProperty(KEY_CONFIGURATION_TYPE);
+ h.dumpProperty(KEY_CONF_INCLUDES);
+ h.dumpProperty(KEY_INSTALL_SAMPLE_CONFIG);
+ h.dumpProperty(KEY_GENERATE_SAMPLE_CONFIG);
+
+ h.dumpProperty(KEY_CONF_CAN_CHANGE);
+}
+
+
extern "C" UINT __stdcall ApplyTool(MSIHANDLE hInstall) {
msi_helper h(hInstall, _T("ApplyTool"));
try {
@@ -299,25 +332,7 @@ extern "C" UINT __stdcall ApplyTool(MSIHANDLE hInstall) {
h.setPropertyIfEmpty(KEY_CONF_CAN_CHANGE, _T("1"));
- h.dumpReason(_T("After ApplyConfig"));
- h.dumpProperty(KEY_ALLOWED_HOSTS);
- h.dumpProperty(KEY_NSCLIENT_PWD);
- h.dumpProperty(KEY_NSCLIENT_PWD_DEFAULT);
- h.dumpProperty(KEY_CONF_SCHEDULER);
- h.dumpProperty(KEY_CONF_CHECKS);
- h.dumpProperty(KEY_CONF_NRPE);
- h.dumpProperty(KEY_CONF_NSCA);
- h.dumpProperty(KEY_CONF_WEB);
- h.dumpProperty(KEY_CONF_NSCLIENT);
- h.dumpProperty(KEY_NRPEMODE);
-
- h.dumpProperty(KEY_CONFIGURATION_TYPE);
- h.dumpProperty(KEY_CONF_INCLUDES);
- h.dumpProperty(KEY_INSTALL_SAMPLE_CONFIG);
- h.dumpProperty(KEY_GENERATE_SAMPLE_CONFIG);
-
- h.dumpProperty(KEY_CONF_CAN_CHANGE);
-
+ dump_config(h, _T("After ApplyConfig"));
} catch (installer_exception e) {
h.logMessage(_T("Failed to apply monitoring tool: ") + e.what());
@@ -347,18 +362,20 @@ extern "C" UINT __stdcall ImportConfig(MSIHANDLE hInstall) {
h.logMessage(_T("Configuration not allowed: ") + allow);
h.setProperty(KEY_CONF_CAN_CHANGE, _T("0"));
h.setProperty(KEY_CONF_HAS_ERRORS, _T("0"));
+ dump_config(h, _T("After ImportConfig"));
return ERROR_SUCCESS;
}
if (!boost::filesystem::is_directory(utf8::cvt<std::string>(target))) {
h.logMessage(_T("Target folder not found: ") + target);
h.setProperty(KEY_CONF_CAN_CHANGE, _T("1"));
h.setProperty(KEY_CONF_HAS_ERRORS, _T("0"));
+ dump_config(h, _T("After ImportConfig"));
return ERROR_SUCCESS;
}
installer_settings_provider provider(&h, target, map_data);
- if (!settings_manager::init_settings(&provider, "")) {
+ if (!settings_manager::init_installer_settings(&provider, "")) {
h.logMessage(_T("Settings context had fatal errors"));
h.setProperty(KEY_CONF_OLD_ERROR, provider.get_error());
h.setProperty(KEY_CONF_CAN_CHANGE, _T("0"));
@@ -377,18 +394,21 @@ extern "C" UINT __stdcall ImportConfig(MSIHANDLE hInstall) {
h.setProperty(KEY_CONF_OLD_ERROR, std::wstring(_T("Old configuration (")) + utf8::cvt<std::wstring>(DEFAULT_CONF_OLD_LOCATION) + _T(") was found but we got errors accessing it: ") + provider.get_error());
h.setProperty(KEY_CONF_CAN_CHANGE, _T("0"));
h.setProperty(KEY_CONF_HAS_ERRORS, _T("1"));
+ dump_config(h, _T("After ImportConfig"));
return ERROR_SUCCESS;
} else {
h.logMessage(_T("Failed to read configuration but no configuration was found (so we are assuming there is no configuration)."));
h.setProperty(KEY_CONF_CAN_CHANGE, _T("1"));
h.setProperty(KEY_CONF_HAS_ERRORS, _T("0"));
+ dump_config(h, _T("After ImportConfig"));
return ERROR_SUCCESS;
}
} else {
h.logMessage(_T("boot.conf was found but we got errors booting it..."));
h.setProperty(KEY_CONF_OLD_ERROR, provider.get_error());
h.setProperty(KEY_CONF_CAN_CHANGE, _T("0"));
h.setProperty(KEY_CONF_HAS_ERRORS, _T("1"));
+ dump_config(h, _T("After ImportConfig"));
return ERROR_SUCCESS;
}
}
@@ -427,24 +447,7 @@ extern "C" UINT __stdcall ImportConfig(MSIHANDLE hInstall) {
settings_manager::destroy_settings();
- h.dumpReason(_T("After ImportConfig"));
- h.dumpProperty(KEY_ALLOWED_HOSTS);
- h.dumpProperty(KEY_NSCLIENT_PWD);
- h.dumpProperty(KEY_NSCLIENT_PWD_DEFAULT);
- h.dumpProperty(KEY_CONF_SCHEDULER);
- h.dumpProperty(KEY_CONF_CHECKS);
- h.dumpProperty(KEY_CONF_NRPE);
- h.dumpProperty(KEY_CONF_NSCA);
- h.dumpProperty(KEY_CONF_WEB);
- h.dumpProperty(KEY_CONF_NSCLIENT);
- h.dumpProperty(KEY_NRPEMODE);
-
- h.dumpProperty(KEY_CONFIGURATION_TYPE);
- h.dumpProperty(KEY_CONF_INCLUDES);
- h.dumpProperty(KEY_INSTALL_SAMPLE_CONFIG);
- h.dumpProperty(KEY_GENERATE_SAMPLE_CONFIG);
-
- h.dumpProperty(KEY_CONF_CAN_CHANGE);
+ dump_config(h, _T("After ImportConfig"));
} catch (installer_exception e) {
h.logMessage(_T("Failed to read old configuration file: ") + e.what());
@@ -632,6 +635,7 @@ extern "C" UINT __stdcall ExecWriteConfig (MSIHANDLE hInstall) {
h.logMessage(_T("Found restore file: ") + strEx::xtos(boost::filesystem::file_size(restore_path)));
if (boost::filesystem::exists(restore_path)) {
+ h.logMessage(_T("Restore path exists: ") + restore);
if (!boost::filesystem::exists(path)) {
h.logMessage(_T("Restoring nsc.ini configuration file"));
copy_file(h, restore_path.wstring(), path.wstring());
@@ -646,9 +650,11 @@ extern "C" UINT __stdcall ExecWriteConfig (MSIHANDLE hInstall) {
h.logMessage(_T("Size (001): ") + strEx::xtos(boost::filesystem::file_size(path)));
installer_settings_provider provider(&h, target);
- if (!settings_manager::init_settings(&provider, context)) {
+ if (!settings_manager::init_installer_settings(&provider, context)) {
h.errorMessage(_T("Failed to boot settings: ") + provider.get_error());
- return ERROR_INSTALL_FAILURE;
+ h.logMessage(_T("Switching context: ") + context_w);
+ settings_manager::change_context(context);
+ return ERROR_SUCCESS;
}
if (boost::filesystem::exists(path))
h.logMessage(_T("Size (002): ") + strEx::xtos(boost::filesystem::file_size(path)));
@@ -99,6 +99,25 @@ namespace settings_manager {
throw settings::settings_exception(__FILE__, __LINE__, "Undefined settings protocol: " + url.protocol);
}
+ bool NSCSettingsImpl::supports_edit(const std::string key) {
+ if (key.empty()) {
+ return true;
+ }
+ net::url url = net::parse(expand_context(key));
+#ifdef WIN32
+ if (url.protocol == "old")
+ return false;
+ if (url.protocol == "registry")
+ return true;
+#endif
+ if (url.protocol == "ini")
+ return true;
+ if (url.protocol == "dummy")
+ return false;
+ if (url.protocol == "http" || url.protocol == "https")
+ return true;
+ return false;
+ }
bool NSCSettingsImpl::context_exists(std::string key) {
key = expand_context(key);
net::url url = net::parse(key);
@@ -232,7 +251,9 @@ namespace settings_manager {
bool init_settings(provider_interface *provider, std::string context) {
try {
+
settings_impl = new NSCSettingsImpl(provider);
+ settings_impl->get_logger()->error("settings", __FILE__, __LINE__, "++++");
get_core()->set_base(provider->expand_path("${base-path}"));
get_core()->boot(context);
get_core()->set_ready();
@@ -249,6 +270,30 @@ namespace settings_manager {
return true;
}
+ bool init_installer_settings(provider_interface *provider, std::string context) {
+ try {
+
+ settings_impl = new NSCSettingsImpl(provider);
+ settings_impl->get_logger()->error("settings", __FILE__, __LINE__, "++++");
+ get_core()->set_base(provider->expand_path("${base-path}"));
+ if (settings_impl->supports_edit(context)) {
+ get_core()->boot(context);
+ get_core()->set_ready();
+ return false;
+ }
+ } catch (const settings::settings_exception &e) {
+ get_core()->get_logger()->error("settings", __FILE__, __LINE__, "Failed to initialize settings: " + e.reason());
+ return false;
+ } catch (const std::exception &e) {
+ get_core()->get_logger()->error("settings", __FILE__, __LINE__, "Failed to initialize settings: " + utf8::utf8_from_native(e.what()));
+ return false;
+ } catch (...) {
+ get_core()->get_logger()->error("settings", __FILE__, __LINE__, "FATAL ERROR IN SETTINGS SUBSYTEM");
+ return false;
+ }
+ return true;
+ }
+
void change_context(std::string context) {
internal_get()->change_context(context);
}
@@ -32,6 +32,7 @@ namespace settings_manager {
bool create_context(std::string key);
bool has_boot_conf();
void set_primary(std::string key);
+ bool supports_edit(const std::string key);
};
// Alias to make handling "compatible" with old syntax
@@ -41,6 +42,7 @@ namespace settings_manager {
boost::shared_ptr<nscapi::settings_helper::settings_impl_interface> get_proxy();
void destroy_settings();
bool init_settings(provider_interface *provider, std::string context = "");
+ bool init_installer_settings(provider_interface *provider, std::string context = "");
void change_context(std::string context);
bool has_boot_conf();
bool context_exists(std::string key);

0 comments on commit 1f7c0a7

Please sign in to comment.