2
* @file PasswordHelper.cpp
3
* @brief Helper class for managing password entry
6
* Copyright 2015 Canonical Ltd
8
* Libertine is free software: you can redistribute it and/or modify it under
9
* the terms of the GNU General Public License, version 3, as published by the
10
* Free Software Foundation.
12
* Libertine is distributed in the hope that it will be useful, but WITHOUT ANY
13
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
#include "libertine/PasswordHelper.h"
30
struct pam_response *reply;
32
int function_conversation(int, const struct pam_message**, struct pam_response **resp, void*)
38
void set_stdin_echo(bool enable = true)
42
tcgetattr(STDIN_FILENO, &tty);
48
(void) tcsetattr(STDIN_FILENO, TCSANOW, &tty);
51
} // anonymous namespace
66
QString PasswordHelper::
71
cout << "Please enter your password:" << endl;
73
set_stdin_echo(false);
74
getline(cin, password);
77
if (cin.fail() || cin.eof())
83
return QString::fromStdString(password);
89
VerifyUserPassword(QString const& password)
91
char *username = getenv("USER");
94
const struct pam_conv local_conversation = { function_conversation, NULL };
95
pam_handle_t *local_auth_handle = NULL;
97
retval = pam_start("common_auth", username, &local_conversation, &local_auth_handle);
99
if (retval != PAM_SUCCESS)
104
reply = (struct pam_response *)malloc(sizeof(struct pam_response));
106
reply[0].resp = strdup(password.toStdString().c_str());
107
reply[0].resp_retcode = 0;
109
retval = pam_authenticate(local_auth_handle, 0);
111
if (retval != PAM_SUCCESS)
116
retval = pam_end(local_auth_handle, retval);
118
if (retval != PAM_SUCCESS)