]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_ldapauth.cpp
Remove references to old configure commands.
[user/henk/code/inspircd.git] / src / modules / extra / m_ldapauth.cpp
index 0b3dbb174b927919168419da33f84f6d6ce58546..4fae7a2e751209f6b3efb30324624ab799fbff0e 100644 (file)
 
 #include <ldap.h>
 
+#ifdef WINDOWS
+# pragma comment(lib, "ldap.lib")
+# pragma comment(lib, "lber.lib")
+#endif
+
 /* $ModDesc: Allow/Deny connections based upon answer from LDAP server */
 /* $LinkerFlags: -lldap */
 
@@ -137,6 +142,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 +180,27 @@ 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.
+                       size_t pos = user->password.find(":");
+                       if (pos != std::string::npos)
+                       {
+                               res = ldap_search_ext_s(conn, base.c_str(), searchscope, user->password.substr(0, pos).c_str(), 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);
+                               }
+                       }
+
+                       // 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 +216,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)