diff options
-rw-r--r-- | src/modules/extra/m_ldapauth.cpp | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/src/modules/extra/m_ldapauth.cpp b/src/modules/extra/m_ldapauth.cpp index 0b3dbb174..95882df47 100644 --- a/src/modules/extra/m_ldapauth.cpp +++ b/src/modules/extra/m_ldapauth.cpp @@ -137,6 +137,13 @@ public: if (!Connect()) return false; + if (user->password.empty()) + { + if (verbose) + ServerInstance->SNO->WriteToSnoMask('c', "Forbidden connection from %s!%s@%s (No password provided)", user->nick.c_str(), user->ident.c_str(), user->host.c_str()); + return false; + } + int res; // bind anonymously if no bind DN and authentication are given in the config struct berval cred; @@ -168,9 +175,26 @@ public: std::string what = (attribute + "=" + (useusername ? user->ident : user->nick)); if ((res = ldap_search_ext_s(conn, base.c_str(), searchscope, what.c_str(), NULL, 0, NULL, NULL, NULL, 0, &msg)) != LDAP_SUCCESS) { - if (verbose) - ServerInstance->SNO->WriteToSnoMask('c', "Forbidden connection from %s!%s@%s (LDAP search failed: %s)", user->nick.c_str(), user->ident.c_str(), user->host.c_str(), ldap_err2string(res)); - return false; + // Do a second search, based on password, if it contains a : + // That is, PASS <user>:<password> will work. + if ((size_t pos = user->password.find(":")) != std::string::npos) + { + res = ldap_search_ext_s(conn, base.c_str(), searchscope, user->password.substr(0, pos), NULL, 0, NULL, NULL, NULL, 0, &msg); + + if (res) + { + // Trim the user: prefix, leaving just 'pass' for later password check + user->password = user->password.substr(pos + 1, user->password.length()); + } + } + + // It may have found based on user:pass check above. + if (!res) + { + if (verbose) + ServerInstance->SNO->WriteToSnoMask('c', "Forbidden connection from %s!%s@%s (LDAP search failed: %s)", user->nick.c_str(), user->ident.c_str(), user->host.c_str(), ldap_err2string(res)); + return false; + } } if (ldap_count_entries(conn, msg) > 1) { @@ -186,12 +210,6 @@ public: ldap_msgfree(msg); return false; } - if (user->password.empty()) - { - if (verbose) - ServerInstance->SNO->WriteToSnoMask('c', "Forbidden connection from %s!%s@%s (No password provided)", user->nick.c_str(), user->ident.c_str(), user->host.c_str()); - return false; - } cred.bv_val = (char*)user->password.data(); cred.bv_len = user->password.length(); if ((res = ldap_sasl_bind_s(conn, ldap_get_dn(conn, entry), LDAP_SASL_SIMPLE, &cred, NULL, NULL, NULL)) == LDAP_SUCCESS) |