Implement AccountService PATCH method
This patchset implements the AccountService PATCH method, using PAM and
dbus in combination.
Change-Id: I754590f787fc84a21a9453e7e10726c56da5c3f7
Signed-off-by: Ed Tanous <ed.tanous@intel.com>
diff --git a/include/pam_authenticate.hpp b/include/pam_authenticate.hpp
index f51f9aa..643c804 100644
--- a/include/pam_authenticate.hpp
+++ b/include/pam_authenticate.hpp
@@ -55,14 +55,6 @@
if (retval != PAM_SUCCESS)
{
- if (retval == PAM_AUTH_ERR)
- {
- // printf("Authentication failure.\n");
- }
- else
- {
- // printf("pam_authenticate returned %d\n", retval);
- }
pam_end(localAuthHandle, PAM_SUCCESS);
return false;
}
@@ -82,3 +74,31 @@
return true;
}
+
+inline bool pamUpdatePassword(const std::string& username,
+ const std::string& password)
+{
+ const struct pam_conv localConversation = {
+ pamFunctionConversation, const_cast<char*>(password.c_str())};
+ pam_handle_t* localAuthHandle = NULL; // this gets set by pam_start
+
+ if (pam_start("passwd", username.c_str(), &localConversation,
+ &localAuthHandle) != PAM_SUCCESS)
+ {
+ return false;
+ }
+ int retval = pam_chauthtok(localAuthHandle, PAM_SILENT);
+
+ if (retval != PAM_SUCCESS)
+ {
+ pam_end(localAuthHandle, PAM_SUCCESS);
+ return false;
+ }
+
+ if (pam_end(localAuthHandle, PAM_SUCCESS) != PAM_SUCCESS)
+ {
+ return false;
+ }
+
+ return true;
+}