Krenair

phpBB LDAP validate session patch

Mar 15th, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.74 KB | None | 0 0
  1. diff --git a/phpBB/includes/auth/auth_ldap.php b/phpBB/includes/auth/auth_ldap.php
  2. index eebf147..1a4fd12 100644
  3. +++ b/phpBB/includes/auth/auth_ldap.php
  4. @@ -271,6 +271,52 @@ function login_ldap(&$username, &$password)
  5.         );
  6.  }
  7.  
  8. +function validate_session_ldap($user_row)
  9. +{
  10. +       global $config;
  11. +       if (!@extension_loaded('ldap'))
  12. +       {
  13. +               return true;
  14. +       }
  15. +
  16. +       $config['ldap_port'] = (int) $config['ldap_port'];
  17. +       if ($config['ldap_port'])
  18. +       {
  19. +               $ldap = @ldap_connect($config['ldap_server'], $config['ldap_port']);
  20. +       }
  21. +       else
  22. +       {
  23. +               $ldap = @ldap_connect($config['ldap_server']);
  24. +       }
  25. +
  26. +       if (!$ldap)
  27. +       {
  28. +               return true;
  29. +       }
  30. +
  31. +       ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
  32. +       ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
  33. +
  34. +       if ($config['ldap_user'] || $config['ldap_password'])
  35. +       {
  36. +               if (!@ldap_bind($ldap, htmlspecialchars_decode($config['ldap_user']), htmlspecialchars_decode($config['ldap_password'])))
  37. +               {
  38. +                       return true;
  39. +               }
  40. +       }
  41. +
  42. +       $search = @ldap_list(
  43. +               $ldap,
  44. +               htmlspecialchars_decode($config['ldap_base_dn']),
  45. +               ldap_user_filter($user_row['username'])
  46. +       );
  47. +
  48. +       $ldap_result = @ldap_get_entries($ldap, $search);
  49. +
  50. +       @ldap_close($ldap);
  51. +       return is_array($ldap_result) && isset($ldap_result["count"]) && $ldap_result["count"] > 0;
  52. +}
  53. +
  54.  /**
  55.  * Generates a filter string for ldap_search to find a user
  56.  *
  57. @@ -350,4 +396,4 @@ function acp_ldap(&$new)
  58.         );
  59.  }
  60.  
  61. -?>
  62. \ No newline at end of file
  63. +?>
Advertisement
Add Comment
Please, Sign In to add comment