aboutsummaryrefslogtreecommitdiffstats
path: root/lang/qt/src/qgpgmenewcryptoconfig.cpp
diff options
context:
space:
mode:
authorIngo Klöcker <[email protected]>2021-06-01 13:29:03 +0000
committerIngo Klöcker <[email protected]>2021-06-01 13:29:03 +0000
commit27aa7c4a0fc8f7cef6219443cee0d040c2774746 (patch)
tree5a51518cfb0abbe6e60000c6329d6ccf50fa5855 /lang/qt/src/qgpgmenewcryptoconfig.cpp
parenttests: Improve the output of the run-keylist helper. (diff)
downloadgpgme-27aa7c4a0fc8f7cef6219443cee0d040c2774746.tar.gz
gpgme-27aa7c4a0fc8f7cef6219443cee0d040c2774746.zip
qt: Add support for flags in LDAP server options
* lang/qt/src/qgpgmenewcryptoconfig.cpp (parseURL): Handle extended LDAP server option syntax. (portToString): New. (splitURL): Append flags to LDAP server option. -- This adds support for the extended syntax of LDAP server options introduced in gpg 2.2.18/2.3. The flags are stored as fragment of a QUrl. GnuPG-bug-id: 5217
Diffstat (limited to 'lang/qt/src/qgpgmenewcryptoconfig.cpp')
-rw-r--r--lang/qt/src/qgpgmenewcryptoconfig.cpp75
1 files changed, 48 insertions, 27 deletions
diff --git a/lang/qt/src/qgpgmenewcryptoconfig.cpp b/lang/qt/src/qgpgmenewcryptoconfig.cpp
index fba20fa6..f994fea8 100644
--- a/lang/qt/src/qgpgmenewcryptoconfig.cpp
+++ b/lang/qt/src/qgpgmenewcryptoconfig.cpp
@@ -468,50 +468,71 @@ static QUrl parseURL(int mRealArgType, const QString &str)
{
if (mRealArgType == 33) { // LDAP server
// The format is HOSTNAME:PORT:USERNAME:PASSWORD:BASE_DN
- QStringList items = str.split(QLatin1Char(':'));
- if (items.count() == 5) {
- QStringList::const_iterator it = items.constBegin();
- QUrl url;
- url.setScheme(QStringLiteral("ldap"));
- url.setHost(urlpart_decode(*it++));
-
- bool ok;
- const int port = (*it++).toInt(&ok);
- if (ok) {
- url.setPort(port);
- } else if (!it->isEmpty()) {
- qCWarning(QGPGME_LOG) << "parseURL: malformed LDAP server port, ignoring: \"" << *it << "\"";
- }
+ // or, since gpg 2.2.18, e.g. for dirmngr/ldapserver: [ldap:]hostname:port:username:password:base_dn:flags[:]
+ const bool isLdapUrl = str.startsWith(QLatin1String("ldap://")) || str.startsWith(QLatin1String("ldaps://"));
+ if (!isLdapUrl) {
+ const bool hasOptionalPrefix = str.startsWith(QLatin1String("ldap:"));
+ const QStringList items = hasOptionalPrefix ? str.mid(5).split(QLatin1Char(':')) : str.split(QLatin1Char(':'));
+ if (items.size() >= 5) {
+ QUrl url;
+ url.setScheme(QStringLiteral("ldap"));
+ url.setHost(urlpart_decode(items[0]), QUrl::DecodedMode);
+
+ const auto portString = items[1];
+ if (!portString.isEmpty()) {
+ bool ok;
+ const int port = portString.toInt(&ok);
+ if (ok) {
+ url.setPort(port);
+ } else {
+ qCWarning(QGPGME_LOG) << "parseURL: malformed LDAP server port, ignoring:" << portString;
+ }
+ }
- const QString userName = urlpart_decode(*it++);
- if (!userName.isEmpty()) {
- url.setUserName(userName);
- }
- const QString passWord = urlpart_decode(*it++);
- if (!passWord.isEmpty()) {
- url.setPassword(passWord);
+ const QString userName = urlpart_decode(items[2]);
+ if (!userName.isEmpty()) {
+ url.setUserName(userName, QUrl::DecodedMode);
+ }
+ const QString passWord = urlpart_decode(items[3]);
+ if (!passWord.isEmpty()) {
+ url.setPassword(passWord, QUrl::DecodedMode);
+ }
+ url.setQuery(urlpart_decode(items[4]), QUrl::DecodedMode);
+ if (items.size() >= 6) {
+ const auto flags = urlpart_decode(items[5]);
+ if (!flags.isEmpty()) {
+ url.setFragment(flags, QUrl::DecodedMode);
+ }
+ }
+ return url;
+ } else {
+ qCWarning(QGPGME_LOG) << "parseURL: malformed LDAP server:" << str;
}
- url.setQuery(urlpart_decode(*it));
- return url;
- } else {
- qCWarning(QGPGME_LOG) << "parseURL: malformed LDAP server:" << str;
}
}
// other URLs : assume wellformed URL syntax.
return QUrl(str);
}
+static QString portToString(int port)
+{
+ // -1 is used for default ports => empty string
+ return port != -1 ? QString::number(port) : QString();
+}
+
// The opposite of parseURL
static QString splitURL(int mRealArgType, const QUrl &url)
{
if (mRealArgType == 33) { // LDAP server
// The format is HOSTNAME:PORT:USERNAME:PASSWORD:BASE_DN
+ // or, since gpg 2.2.18, e.g. for dirmngr/ldapserver: [ldap:]hostname:port:username:password:base_dn:flags[:]
Q_ASSERT(url.scheme() == QLatin1String("ldap"));
return urlpart_encode(url.host()) + QLatin1Char(':') +
- (url.port() != -1 ? QString::number(url.port()) : QString()) + QLatin1Char(':') + // -1 is used for default ports, omit
+ portToString(url.port()) + QLatin1Char(':') +
urlpart_encode(url.userName()) + QLatin1Char(':') +
urlpart_encode(url.password()) + QLatin1Char(':') +
- urlpart_encode(url.query());
+ urlpart_encode(url.query()) + QLatin1Char(':') +
+ urlpart_encode(url.fragment());
}
return url.path();
}