- 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.
+ size_t pos = user->password.find(":");
+ if (pos != std::string::npos)
+ {
+ // manpage says we must deallocate regardless of success or failure
+ // since we're about to do another query (and reset msg), first
+ // free the old one.
+ msg.dealloc();
+
+ std::string cutpassword = user->password.substr(0, pos);
+ res = ldap_search_ext_s(conn, base.c_str(), searchscope, cutpassword.c_str(), NULL, 0, NULL, NULL, NULL, 0, &msg);
+
+ if (res == LDAP_SUCCESS)
+ {
+ // Trim the user: prefix, leaving just 'pass' for later password check
+ user->password = user->password.substr(pos + 1);
+ }
+ }
+
+ // It may have found based on user:pass check above.
+ if (res != LDAP_SUCCESS)
+ {
+ if (verbose)
+ ServerInstance->SNO->WriteToSnoMask('c', "Forbidden connection from %s (LDAP search failed: %s)", user->GetFullRealHost().c_str(), ldap_err2string(res));
+ return false;
+ }