~azzar1/unity/pam-logging-xenial

« back to all changes in this revision

Viewing changes to lockscreen/UserAuthenticatorPam.cpp

  • Committer: Andrea
  • Date: 2017-09-12 09:11:32 UTC
  • mfrom: (4114.1.2 unity-xenial)
  • Revision ID: andrea@andrea-xps-15-9550-20170912091132-h2lpqc865jx97fzk
Merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include "UserAuthenticatorPam.h"
25
25
#include "unity-shared/UnitySettings.h"
26
26
 
 
27
#include <NuxCore/Logger.h>
 
28
 
27
29
#include <cstring>
28
30
#include <security/pam_appl.h>
29
31
#include <vector>
33
35
namespace lockscreen
34
36
{
35
37
 
 
38
DECLARE_LOGGER(logger, "unity.lockscreen.pam");
 
39
 
36
40
bool UserAuthenticatorPam::AuthenticateStart(std::string const& username,
37
41
                                             AuthenticateEndCallback const& authenticate_cb)
38
42
{
 
43
  LOG_WARN(logger) << "Starting the authentication procedure";
 
44
 
39
45
  first_prompt_ = true;
40
46
  username_ = username;
41
47
  authenticate_cb_ = authenticate_cb;
42
48
  pam_handle_ = nullptr;
43
49
 
44
 
  if (!InitPam() || !pam_handle_)
45
 
    return false;
 
50
  if (!InitPam() || !pam_handle_) {
 
51
      LOG_WARN(logger) << "PAM initialization failed";
 
52
      return false;
 
53
  }
 
54
 
 
55
  LOG_WARN(logger) << "PAM initialization succeded";
46
56
 
47
57
  glib::Object<GTask> task(g_task_new(nullptr, cancellable_, [] (GObject*, GAsyncResult*, gpointer data) {
48
58
    auto self = static_cast<UserAuthenticatorPam*>(data);
55
65
  g_task_run_in_thread(task, [] (GTask* task, gpointer, gpointer data, GCancellable*) {
56
66
    auto self = static_cast<UserAuthenticatorPam*>(data);
57
67
 
 
68
    LOG_WARN(logger) << "calling pam_authenticate";
58
69
    self->status_ = pam_authenticate(self->pam_handle_, 0);
 
70
    LOG_WARN(logger) << "pam_authenticate returned " << self->status_;
59
71
 
60
72
    if (self->status_ == PAM_SUCCESS)
61
73
    {
80
92
  conversation.conv = ConversationFunction;
81
93
  conversation.appdata_ptr = static_cast<void*>(this);
82
94
 
 
95
  LOG_WARN(logger) << "Initializing PAM";
 
96
 
83
97
  return pam_start("unity", username_.c_str(),
84
98
                   &conversation, &pam_handle_) == PAM_SUCCESS;
85
99
}
89
103
                                               pam_response** resp,
90
104
                                               void* appdata_ptr)
91
105
{
 
106
  LOG_WARN(logger) << "UserAuthenticatorPam::ConversationFunction " << num_msg;
 
107
 
92
108
  if (num_msg <= 0)
93
109
    return PAM_CONV_ERR;
94
110