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
This commit is contained in:
parent
31eb45f016
commit
27aa7c4a0f
@ -468,50 +468,71 @@ static QUrl parseURL(int mRealArgType, const QString &str)
|
|||||||
{
|
{
|
||||||
if (mRealArgType == 33) { // LDAP server
|
if (mRealArgType == 33) { // LDAP server
|
||||||
// The format is HOSTNAME:PORT:USERNAME:PASSWORD:BASE_DN
|
// The format is HOSTNAME:PORT:USERNAME:PASSWORD:BASE_DN
|
||||||
QStringList items = str.split(QLatin1Char(':'));
|
// or, since gpg 2.2.18, e.g. for dirmngr/ldapserver: [ldap:]hostname:port:username:password:base_dn:flags[:]
|
||||||
if (items.count() == 5) {
|
const bool isLdapUrl = str.startsWith(QLatin1String("ldap://")) || str.startsWith(QLatin1String("ldaps://"));
|
||||||
QStringList::const_iterator it = items.constBegin();
|
if (!isLdapUrl) {
|
||||||
QUrl url;
|
const bool hasOptionalPrefix = str.startsWith(QLatin1String("ldap:"));
|
||||||
url.setScheme(QStringLiteral("ldap"));
|
const QStringList items = hasOptionalPrefix ? str.mid(5).split(QLatin1Char(':')) : str.split(QLatin1Char(':'));
|
||||||
url.setHost(urlpart_decode(*it++));
|
if (items.size() >= 5) {
|
||||||
|
QUrl url;
|
||||||
|
url.setScheme(QStringLiteral("ldap"));
|
||||||
|
url.setHost(urlpart_decode(items[0]), QUrl::DecodedMode);
|
||||||
|
|
||||||
bool ok;
|
const auto portString = items[1];
|
||||||
const int port = (*it++).toInt(&ok);
|
if (!portString.isEmpty()) {
|
||||||
if (ok) {
|
bool ok;
|
||||||
url.setPort(port);
|
const int port = portString.toInt(&ok);
|
||||||
} else if (!it->isEmpty()) {
|
if (ok) {
|
||||||
qCWarning(QGPGME_LOG) << "parseURL: malformed LDAP server port, ignoring: \"" << *it << "\"";
|
url.setPort(port);
|
||||||
}
|
} else {
|
||||||
|
qCWarning(QGPGME_LOG) << "parseURL: malformed LDAP server port, ignoring:" << portString;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const QString userName = urlpart_decode(*it++);
|
const QString userName = urlpart_decode(items[2]);
|
||||||
if (!userName.isEmpty()) {
|
if (!userName.isEmpty()) {
|
||||||
url.setUserName(userName);
|
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;
|
||||||
}
|
}
|
||||||
const QString passWord = urlpart_decode(*it++);
|
|
||||||
if (!passWord.isEmpty()) {
|
|
||||||
url.setPassword(passWord);
|
|
||||||
}
|
|
||||||
url.setQuery(urlpart_decode(*it));
|
|
||||||
return url;
|
|
||||||
} else {
|
|
||||||
qCWarning(QGPGME_LOG) << "parseURL: malformed LDAP server:" << str;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// other URLs : assume wellformed URL syntax.
|
// other URLs : assume wellformed URL syntax.
|
||||||
return QUrl(str);
|
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
|
// The opposite of parseURL
|
||||||
static QString splitURL(int mRealArgType, const QUrl &url)
|
static QString splitURL(int mRealArgType, const QUrl &url)
|
||||||
{
|
{
|
||||||
if (mRealArgType == 33) { // LDAP server
|
if (mRealArgType == 33) { // LDAP server
|
||||||
// The format is HOSTNAME:PORT:USERNAME:PASSWORD:BASE_DN
|
// 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"));
|
Q_ASSERT(url.scheme() == QLatin1String("ldap"));
|
||||||
return urlpart_encode(url.host()) + QLatin1Char(':') +
|
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.userName()) + QLatin1Char(':') +
|
||||||
urlpart_encode(url.password()) + QLatin1Char(':') +
|
urlpart_encode(url.password()) + QLatin1Char(':') +
|
||||||
urlpart_encode(url.query());
|
urlpart_encode(url.query()) + QLatin1Char(':') +
|
||||||
|
urlpart_encode(url.fragment());
|
||||||
}
|
}
|
||||||
return url.path();
|
return url.path();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user