X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fldapauthenticator.cpp;h=b42044042895c644674fcdf57d38bd7a3bce9544;hp=34768faaec601d574473094beac44d78f0cae345;hb=ddfb1d2574c4bffd180361a80df9b1cd584bb040;hpb=cfbd4daee17dbb3c4052d938bf33edd08711d728 diff --git a/src/core/ldapauthenticator.cpp b/src/core/ldapauthenticator.cpp index 34768faa..b4204404 100644 --- a/src/core/ldapauthenticator.cpp +++ b/src/core/ldapauthenticator.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2016 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -28,7 +28,7 @@ #include "ldapauthenticator.h" -#include "logger.h" +#include "logmessage.h" #include "network.h" #include "quassel.h" @@ -100,15 +100,27 @@ QVariantList LdapAuthenticator::setupData() const } -void LdapAuthenticator::setAuthProperties(const QVariantMap &properties) +void LdapAuthenticator::setAuthProperties(const QVariantMap &properties, + const QProcessEnvironment &environment, + bool loadFromEnvironment) { - _hostName = properties["Hostname"].toString(); - _port = properties["Port"].toInt(); - _bindDN = properties["BindDN"].toString(); - _bindPassword = properties["BindPassword"].toString(); - _baseDN = properties["BaseDN"].toString(); - _filter = properties["Filter"].toString(); - _uidAttribute = properties["UidAttribute"].toString(); + if (loadFromEnvironment) { + _hostName = environment.value("AUTH_LDAP_HOSTNAME"); + _port = environment.value("AUTH_LDAP_PORT").toInt(); + _bindDN = environment.value("AUTH_LDAP_BIND_DN"); + _bindPassword = environment.value("AUTH_LDAP_BIND_PASSWORD"); + _baseDN = environment.value("AUTH_LDAP_BASE_DN"); + _filter = environment.value("AUTH_LDAP_FILTER"); + _uidAttribute = environment.value("AUTH_LDAP_UID_ATTRIBUTE"); + } else { + _hostName = properties["Hostname"].toString(); + _port = properties["Port"].toInt(); + _bindDN = properties["BindDN"].toString(); + _bindPassword = properties["BindPassword"].toString(); + _baseDN = properties["BaseDN"].toString(); + _filter = properties["Filter"].toString(); + _uidAttribute = properties["UidAttribute"].toString(); + } } // TODO: this code is sufficiently general that in the future, perhaps an abstract @@ -122,14 +134,18 @@ UserId LdapAuthenticator::validateUser(const QString &username, const QString &p return UserId(); } + // LDAP is case-insensitive, thus we will lowercase the username, in spite of + // a better solution :( + const QString lUsername = username.toLower(); + // If auth succeeds, but the user has not logged into quassel previously, make // a new user for them and return that ID. // Users created via LDAP have empty passwords, but authenticator column = LDAP. // On the other hand, if auth succeeds and the user already exists, do a final // cross-check to confirm we're using the right auth provider. - UserId quasselId = Core::validateUser(username, QString()); + UserId quasselId = Core::validateUser(lUsername, QString()); if (!quasselId.isValid()) { - return Core::addUser(username, QString(), backendId()); + return Core::addUser(lUsername, QString(), backendId()); } else if (!(Core::checkAuthProvider(quasselId, backendId()))) { return 0; @@ -138,17 +154,21 @@ UserId LdapAuthenticator::validateUser(const QString &username, const QString &p } -bool LdapAuthenticator::setup(const QVariantMap &settings) +bool LdapAuthenticator::setup(const QVariantMap &settings, + const QProcessEnvironment &environment, + bool loadFromEnvironment) { - setAuthProperties(settings); + setAuthProperties(settings, environment, loadFromEnvironment); bool status = ldapConnect(); return status; } -Authenticator::State LdapAuthenticator::init(const QVariantMap &settings) +Authenticator::State LdapAuthenticator::init(const QVariantMap &settings, + const QProcessEnvironment &environment, + bool loadFromEnvironment) { - setAuthProperties(settings); + setAuthProperties(settings, environment, loadFromEnvironment); bool status = ldapConnect(); if (!status) { @@ -177,6 +197,8 @@ bool LdapAuthenticator::ldapConnect() serverURIArray = serverURI.toLocal8Bit(); res = ldap_initialize(&_connection, serverURIArray); + quInfo() << "LDAP: Connecting to" << serverURI; + if (res != LDAP_SUCCESS) { qWarning() << "Could not connect to LDAP server:" << ldap_err2string(res); return false;