Commit 53cb1a70 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

Add "busy" property to Authenticator

Allows to query whether an authentication is currently ongoing,
which is independent from the enforced grace lock.
parent 51ae818d
Pipeline #209368 passed with stage
in 3 minutes and 31 seconds
......@@ -54,6 +54,7 @@ void PamTest::testLogin()
QSignalSpy promptForSecretSpy(&auth, &PamAuthenticator::promptForSecret);
QSignalSpy succeededSpy(&auth, &PamAuthenticator::succeeded);
QSignalSpy failedSpy(&auth, &PamAuthenticator::failed);
QSignalSpy busyChangedSpy(&auth, &PamAuthenticator::busyChanged);
// invalid password
auth.tryUnlock();
......@@ -64,12 +65,15 @@ void PamTest::testLogin()
QVERIFY(promptSpy.count() == 0);
QVERIFY(succeededSpy.count() == 0);
QVERIFY(busyChangedSpy.count() == 2); // changed to busy and back again.
// try again, with the right password
auth.tryUnlock();
QVERIFY(promptForSecretSpy.wait());
auth.respond("my_password");
QVERIFY(succeededSpy.wait());
QVERIFY(busyChangedSpy.count() == 4);
}
QTEST_MAIN(PamTest)
......
......@@ -36,6 +36,7 @@ public:
void authenticate();
Q_SIGNALS:
void busyChanged(bool busy);
void promptForSecret(const QString &msg);
void prompt(const QString &msg);
void infoMessage(const QString &msg);
......@@ -74,6 +75,8 @@ int PamWorker::converse(int n, const struct pam_message **msg, struct pam_respon
isSecret = true;
Q_FALLTHROUGH();
case PAM_PROMPT_ECHO_ON:
Q_EMIT c->busyChanged(false);
const QString prompt = QString::fromLocal8Bit(msg[i]->msg);
if (isSecret) {
Q_EMIT c->promptForSecret(prompt);
......@@ -96,6 +99,8 @@ int PamWorker::converse(int n, const struct pam_message **msg, struct pam_respon
return rc;
}
Q_EMIT c->busyChanged(true);
resp[i]->resp = (char *)malloc(response.length() + 1);
// on error, get rid of everything
if (!resp[i]->resp) {
......@@ -152,6 +157,8 @@ void PamWorker::authenticate()
int rc = pam_authenticate(m_handle, 0); // PAM_SILENT);
qCDebug(KSCREENLOCKER_GREET) << "Auth done RC" << rc;
Q_EMIT busyChanged(false);
if (rc == PAM_SUCCESS) {
Q_EMIT succeeded();
} else {
......@@ -196,6 +203,7 @@ PamAuthenticator::PamAuthenticator(const QString &service, const QString &user,
connect(&m_thread, &QThread::finished, d, &QObject::deleteLater);
connect(d, &PamWorker::busyChanged, this, &PamAuthenticator::setBusy);
connect(d, &PamWorker::prompt, this, &PamAuthenticator::prompt);
connect(d, &PamWorker::promptForSecret, this, &PamAuthenticator::promptForSecret);
connect(d, &PamWorker::infoMessage, this, &PamAuthenticator::infoMessage);
......@@ -225,6 +233,19 @@ void PamAuthenticator::init(const QString &service, const QString &user)
});
}
bool PamAuthenticator::isBusy() const
{
return m_busy;
}
void PamAuthenticator::setBusy(bool busy)
{
if (m_busy != busy) {
m_busy = busy;
Q_EMIT busyChanged();
}
}
bool PamAuthenticator::isUnlocked() const
{
return m_unlocked;
......
......@@ -29,13 +29,17 @@ class PamAuthenticator : public QObject
{
Q_OBJECT
Q_PROPERTY(bool busy READ isBusy NOTIFY busyChanged)
public:
PamAuthenticator(const QString &service, const QString &user, QObject *parent = nullptr);
~PamAuthenticator();
bool isBusy() const;
bool isUnlocked() const;
Q_SIGNALS:
void busyChanged();
void promptForSecret(const QString &msg);
void prompt(const QString &msg);
void infoMessage(const QString &msg);
......@@ -52,6 +56,9 @@ protected:
void init(const QString &service, const QString &user);
private:
void setBusy(bool busy);
bool m_busy = false;
bool m_unlocked = false;
QThread m_thread;
PamWorker *d;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment