summaryrefslogtreecommitdiff
diff options
authorAndrea Azzarone <azzaronea@gmail.com>2018-03-15 13:41:39 +0100
committerAndrea Azzarone <azzaronea@gmail.com>2018-03-15 13:41:39 +0100
commit44e60221070c0243e8b4adbfade57d7ee8bd4b21 (patch)
tree8f4cef285e5926a2340d6abb1abbd1404e99487f
parent68b6a77bfeb3f0ebb166548bb1af0afb230f09a3 (diff)
Fix memory leak in UserAuthenticatorPam::AuthenticateStart and add some debug messages.
(bzr r4269.1.1)
-rw-r--r--lockscreen/UserAuthenticatorPam.cpp28
1 files changed, 25 insertions, 3 deletions
diff --git a/lockscreen/UserAuthenticatorPam.cpp b/lockscreen/UserAuthenticatorPam.cpp
index f4e1952c8..463d8f949 100644
--- a/lockscreen/UserAuthenticatorPam.cpp
+++ b/lockscreen/UserAuthenticatorPam.cpp
@@ -25,6 +25,8 @@
#include "unity-shared/UnitySettings.h"
#include "UnityCore/GLibWrapper.h"
+#include <NuxCore/Logger.h>
+
#include <cstring>
#include <security/pam_appl.h>
#include <vector>
@@ -33,19 +35,31 @@ namespace unity
{
namespace lockscreen
{
+namespace
+{
+DECLARE_LOGGER(logger, "unity.lockscreen");
+}
bool UserAuthenticatorPam::AuthenticateStart(std::string const& username,
AuthenticateEndCallback const& authenticate_cb)
{
if (pam_handle_)
+ {
+ LOG_ERROR(logger) << "Unable to start authentication because another one has already been started";
return false;
+ }
first_prompt_ = true;
username_ = username;
authenticate_cb_ = authenticate_cb;
glib::Error error;
- g_thread_try_new(nullptr, AuthenticationThreadFunc, this, &error);
+ g_autoptr(GThread) thread = g_thread_try_new(nullptr, AuthenticationThreadFunc, this, &error);
+
+ if (!thread || error)
+ {
+ LOG_ERROR(logger) << "Unable to create a new thread for PAM authentication: " << error.Message();
+ }
return !error;
}
@@ -88,8 +102,16 @@ bool UserAuthenticatorPam::InitPam()
conversation.conv = ConversationFunction;
conversation.appdata_ptr = static_cast<void*>(this);
- return pam_start("unity", username_.c_str(),
- &conversation, &pam_handle_) == PAM_SUCCESS;
+ int ret = pam_start("unity", username_.c_str(),
+ &conversation, &pam_handle_);
+
+ if (ret != PAM_SUCCESS)
+ {
+ LOG_ERROR(logger) << "Unable to start pam: " << pam_strerror(pam_handle_, ret);
+ return false;
+ }
+
+ return true;
}
int UserAuthenticatorPam::ConversationFunction(int num_msg,