summaryrefslogtreecommitdiff
path: root/src/modules/extra
diff options
context:
space:
mode:
authorw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>2010-02-17 12:54:10 +0000
committerw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>2010-02-17 12:54:10 +0000
commit0cfe17a55d288770a1cb884a07345263f4816839 (patch)
treea6b16e61799fb1e03f1736ea59a3942da58f5296 /src/modules/extra
parent2d3684dee52216e539405caca85f05423e0bce43 (diff)
Check for <user>:<password> for ldap auth in /PASS password if ident/nickname method fails, this allows people with long uids/invalid uids to still auth to LDAP. Thanks to stezz.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12486 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules/extra')
-rw-r--r--src/modules/extra/m_ldapauth.cpp36
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)