summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2021-12-14 12:29:09 +0100
committerSimon Rettberg2021-12-14 12:29:09 +0100
commitbdb6fe6168806baf22feb7fce5490dca23b07458 (patch)
tree0ff962a039acc47575d5418359bb16c92f664075
parentvsession icon: Match agains OS display name too (diff)
downloadvmchooser2-29r2.tar.gz
vmchooser2-29r2.tar.xz
vmchooser2-29r2.zip
Support wildcards * and ? in ldap filtersv29r2v29r1
Closes #3854
-rw-r--r--src/userldapdata.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/userldapdata.cpp b/src/userldapdata.cpp
index 4382800..d4f966f 100644
--- a/src/userldapdata.cpp
+++ b/src/userldapdata.cpp
@@ -4,6 +4,7 @@
#include <QFile>
#include <QDebug>
#include <QDir>
+#include <QRegularExpression>
#define INCBREAK if (++i >= len) break
@@ -39,6 +40,7 @@ bool init(QString inputFile)
keyEnd = i;
INCBREAK;
if (p[i] == ':') {
+ // Double ":", means base64 encoded data
INCBREAK;
b64 = true;
}
@@ -53,6 +55,7 @@ bool init(QString inputFile)
while (dataLen > 0 && p[dataStart + dataLen - 1] == '\n') {
dataLen--;
}
+ // Put "lowercase(key):value" into set
QString value = QString::fromUtf8(p, keyEnd).toLower() + ":";
if (b64) {
value += QString::fromUtf8(QByteArray::fromBase64(QByteArray(p + dataStart, dataLen)));
@@ -71,8 +74,18 @@ bool isEmpty()
bool isAllowed(const QString& attribute, const QString& value)
{
- const QString keyLow(attribute.toLower() + ":" + value);
- return _entries.contains(keyLow);
+ if (value.indexOf(QLatin1Char('*')) == -1 && value.indexOf(QLatin1Char('?')) == -1) {
+ const QString keyLow(attribute.toLower() + QLatin1String(":") + value);
+ return _entries.contains(keyLow);
+ }
+ // Wildcard matching
+ QRegularExpression re(QLatin1String("^") + QRegularExpression::escape(attribute.toLower()) + QLatin1String(":")
+ + QRegularExpression::wildcardToRegularExpression(value));
+ for (auto str : _entries) {
+ if (re.match(str).hasMatch())
+ return true;
+ }
+ return false;
}
}