summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2018-02-08 12:02:00 +0100
committerSimon Rettberg2018-02-08 12:02:00 +0100
commit7688ba080c0c69508847fca9aa36dc392ddbb766 (patch)
treef39315ec70374d2cca6b0929049345c7b113d8d0
parentUpdate readme (diff)
downloadslxgreeter-7688ba080c0c69508847fca9aa36dc392ddbb766.tar.gz
slxgreeter-7688ba080c0c69508847fca9aa36dc392ddbb766.tar.xz
slxgreeter-7688ba080c0c69508847fca9aa36dc392ddbb766.zip
Support regex mangling of username before passing to lightdm
-rw-r--r--src/loginform.cpp10
-rw-r--r--src/loginform.h1
-rw-r--r--src/namereplace.cpp69
-rw-r--r--src/namereplace.h13
4 files changed, 92 insertions, 1 deletions
diff --git a/src/loginform.cpp b/src/loginform.cpp
index 823958d..a43e9a8 100644
--- a/src/loginform.cpp
+++ b/src/loginform.cpp
@@ -20,6 +20,7 @@
#include "ui_loginform.h"
#include "settings.h"
#include "global.h"
+#include "namereplace.h"
LoginForm::LoginForm(QWidget *parent) :
QWidget(parent),
@@ -73,12 +74,19 @@ void LoginForm::initialize()
connect(Global::greeter(), SIGNAL(authenticationComplete()), this, SLOT(onAuthenticationComplete()));
}
+ // Load regexp for name substitution
+ NameReplace::loadSubs();
+
ui->leaveComboBox->setDisabled(ui->leaveComboBox->count() <= 1);
ui->passwordInput->clear();
}
void LoginForm::startAuthentication()
{
+ QString username(ui->userInput->text());
+ NameReplace::replace(username);
+ std::cerr << "Logging in as " << username.toStdString() << std::endl;
+
if (Global::testMode()) {
return;
}
@@ -99,7 +107,7 @@ void LoginForm::startAuthentication()
ui->userInput->setEnabled(false);
ui->passwordInput->setEnabled(false);
cancelLoginTimer.start();
- Global::greeter()->authenticate(ui->userInput->text());
+ Global::greeter()->authenticate(username);
}
void LoginForm::onPrompt(QString prompt, QLightDM::Greeter::PromptType promptType)
diff --git a/src/loginform.h b/src/loginform.h
index e414d2b..83ddd28 100644
--- a/src/loginform.h
+++ b/src/loginform.h
@@ -50,6 +50,7 @@ protected:
private:
void initialize();
+ void loadSubs();
void addLeaveEntry(bool canDo, QString iconName, QString text, QString actionName);
QString currentSession();
void setCurrentSession(QString session);
diff --git a/src/namereplace.cpp b/src/namereplace.cpp
new file mode 100644
index 0000000..36d834d
--- /dev/null
+++ b/src/namereplace.cpp
@@ -0,0 +1,69 @@
+#include "namereplace.h"
+#include <QString>
+#include <QRegularExpression>
+#include <QFile>
+#include <QTextStream>
+#include <QDebug>
+
+#define SOURCE_FILE "/opt/openslx/lightdm/login-regexp"
+
+static QList< QPair< QRegularExpression, QString > > list;
+
+static inline int find(QChar c, int start, const QString& line)
+{
+ do {
+ int next = line.indexOf(c, start);
+ if (next == -1)
+ return -1;
+ if (line.at(next - 1) != '\\')
+ return next;
+ start = next + 1;
+ } while (true);
+}
+
+void NameReplace::loadSubs()
+{
+ int idx = 0;
+ QFile inputFile(SOURCE_FILE);
+ if (!inputFile.open(QIODevice::ReadOnly))
+ return;
+ QTextStream in(&inputFile);
+ in.setCodec("UTF-8");
+ while (!in.atEnd()) {
+ QString line = in.readLine();
+ idx++;
+ if (line.isEmpty())
+ continue;
+ QChar delim = line.at(0);
+ int first = find(delim, 1, line);
+ if (first == -1)
+ continue;
+ int second = find(delim, first + 1, line);
+ if (second == -1)
+ continue;
+ QString regex = line.mid(1, first - 1).replace(QString("\\") + delim, QString(delim));
+ QString replace = line.mid(first + 1, second - first - 1).replace(QString("\\") + delim, QString(delim));
+ QString flags = line.mid(second + 1);
+ // ...
+ QRegularExpression::PatternOptions opts = 0;
+ if (flags.contains("i")) {
+ opts |= QRegularExpression::CaseInsensitiveOption;
+ }
+ QRegularExpression re(regex, opts);
+ if (!re.isValid()) {
+ qWarning() << "Invalid regex:" << regex << "on line" << idx;
+ continue;
+ }
+ list.append(QPair<QRegularExpression, QString>(re, replace));
+ }
+ inputFile.close();
+}
+
+void NameReplace::replace(QString& input)
+{
+ if (list.isEmpty())
+ return;
+ for (auto &brumm : list) {
+ input = input.replace(brumm.first, brumm.second);
+ }
+}
diff --git a/src/namereplace.h b/src/namereplace.h
new file mode 100644
index 0000000..2b8e802
--- /dev/null
+++ b/src/namereplace.h
@@ -0,0 +1,13 @@
+#ifndef NAMEREPLACE_H
+#define NAMEREPLACE_H
+
+#include <QString>
+
+class NameReplace
+{
+public:
+ static void loadSubs();
+ static void replace(QString& input);
+};
+
+#endif