system: Use defined constant for /etc/shadow path
The implementation of `impl::changePassword` function hardcoded path to
/etc/shadow even when we have a constant for that which is stored in
caller's class member.
Change-Id: Ibacd95211935c804d317b69860140215e1d60060
diff --git a/src/system/Authentication.cpp b/src/system/Authentication.cpp
index 2404a08..5c4c0e7 100644
--- a/src/system/Authentication.cpp
+++ b/src/system/Authentication.cpp
@@ -43,10 +43,10 @@
}
namespace impl {
-void changePassword(const std::string& name, const std::string& password)
+void changePassword(const std::string& name, const std::string& password, const std::string& etc_shadow)
{
utils::execAndWait(spdlog::get("system"), CHPASSWD_EXECUTABLE, {}, name + ":" + password);
- auto shadow = velia::utils::readFileToString("/etc/shadow");
+ auto shadow = velia::utils::readFileToString(etc_shadow);
utils::safeWriteFile(BACKUP_ETC_SHADOW_FILE, shadow);
}
}
@@ -273,7 +273,7 @@
auto password = getValueAsString(getSubtree(userNode, "change-password/password-cleartext"));
m_log->debug("Changing password for {}", name);
try {
- changePassword(name, password);
+ changePassword(name, password, m_etc_shadow);
output->new_path(session->get_context(), "result", "success", LYD_ANYDATA_CONSTSTRING, LYD_PATH_OPT_OUTPUT);
m_log->info("Changed password for {}", name);
} catch (std::runtime_error& ex) {