1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
/*
* Copyright (C) 2014 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Greeter.h"
#include "GreeterPrivate.h"
namespace QLightDM
{
GreeterPrivate::GreeterPrivate(Greeter* parent)
: authenticated(false),
authenticationUser(),
twoFactorDone(false),
mockMode("single"),
q_ptr(parent)
{
char *envMockMode = getenv("LIBLIGHTDM_MOCK_MODE");
if (envMockMode) {
mockMode = envMockMode;
}
}
void GreeterPrivate::handleAuthenticate()
{
Q_Q(Greeter);
if (mockMode == "single") {
authenticated = true;
Q_EMIT q->authenticationComplete();
} else if (mockMode == "single-passphrase" || mockMode == "single-pin" || mockMode == "single-pin-clock") {
Q_EMIT q->showPrompt("Password: ", Greeter::PromptTypeSecret);
} else if (mockMode == "full") {
handleAuthenticate_full();
}
}
void GreeterPrivate::handleAuthenticate_full()
{
Q_Q(Greeter);
// Send out any messages we need to
if (authenticationUser == "info-prompt")
Q_EMIT q->showMessage("Welcome to Lomiri Greeter", Greeter::MessageTypeInfo);
else if (authenticationUser == "wide-info-prompt")
Q_EMIT q->showMessage("Welcome to Lomiri Greeter, the greeteriest greeter that ever did appear in these fine lands", Greeter::MessageTypeInfo);
else if (authenticationUser == "html-info-prompt")
Q_EMIT q->showMessage("<b>&</b>", Greeter::MessageTypeInfo);
else if (authenticationUser == "long-info-prompt")
Q_EMIT q->showMessage("Welcome to Lomiri Greeter\n\nWe like to annoy you with super ridiculously long messages.\nLike this one\n\nThis is the last line of a multiple line message.", Greeter::MessageTypeInfo);
else if (authenticationUser == "multi-info-prompt") {
Q_EMIT q->showMessage("Welcome to Lomiri Greeter", Greeter::MessageTypeInfo);
Q_EMIT q->showMessage("This is an error", Greeter::MessageTypeError);
Q_EMIT q->showMessage("You should have seen three messages", Greeter::MessageTypeInfo);
}
// OK, now actually do the prompt
if (authenticationUser == "no-password") {
authenticated = true;
Q_EMIT q->authenticationComplete();
} else if (authenticationUser == "has-pin" || authenticationUser == "has-pin-clock"){
Q_EMIT q->showPrompt("Password: ", Greeter::PromptTypeSecret);
} else if (authenticationUser == "auth-error") {
authenticated = false;
Q_EMIT q->authenticationComplete();
} else if (authenticationUser == "different-prompt") {
Q_EMIT q->showPrompt("Secret word: ", Greeter::PromptTypeSecret);
} else {
Q_EMIT q->showPrompt("Password: ", Greeter::PromptTypeSecret);
}
}
void GreeterPrivate::handleRespond(QString const &response)
{
Q_Q(Greeter);
if (mockMode == "single") {
// NOOP
} else if (mockMode == "single-passphrase") {
authenticated = (response == "password");
q->sendAuthenticationComplete();
} else if (mockMode == "single-pin" || mockMode == "single-pin-clock") {
QString expectedPincode = "";
for (int i = 1; i < response.size()+1; ++i) {
expectedPincode = expectedPincode + QString::number(i);
}
authenticated = (response == expectedPincode);
q->sendAuthenticationComplete();
} else if (mockMode == "full") {
handleRespond_full(response);
}
}
void GreeterPrivate::handleRespond_full(const QString &response)
{
Q_Q(Greeter);
if (authenticationUser == "no-response")
return;
else if (authenticationUser == "two-factor") {
if (!twoFactorDone) {
if (response == "password") {
twoFactorDone = true;
Q_EMIT q->showPrompt("otp", Greeter::PromptTypeQuestion);
} else {
authenticated = false;
q->sendAuthenticationComplete();
}
} else {
authenticated = (response == "otp");
q->sendAuthenticationComplete();
}
return;
}
if (authenticationUser == "has-pin" || authenticationUser == "has-pin-clock") {
authenticated = (response == "1234");
} else {
authenticated = (response == "password");
}
q->sendAuthenticationComplete();
}
}
|