]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Check for <user>:<password> for ldap auth in /PASS password if ident/nickname method...
authorw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 17 Feb 2010 12:54:10 +0000 (12:54 +0000)
committerw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 17 Feb 2010 12:54:10 +0000 (12:54 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12486 e03df62e-2008-0410-955e-edbf42e46eb7

src/modules/extra/m_ldapauth.cpp

index 0b3dbb174b927919168419da33f84f6d6ce58546..95882df477bc7389a0a25dd946fc771ae8e843a5 100644 (file)
@@ -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)