diff options
-rw-r--r-- | src/userldapdata.cpp | 17 |
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; } } |