From a442b90ad5f98ccf182e297d20a0385f1ea28d1d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be>
Date: Wed, 10 May 2017 09:34:58 +0200
Subject: [PATCH] =?UTF-8?q?Fixes=20#5511=20Fixed=20SASL=C2=A0password=20me?=
 =?UTF-8?q?thod=20(as=20long=20as=20a=20field=20from=20main=20tab=20is=20u?=
 =?UTF-8?q?sed)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../class_password-methods-sasl.inc           | 36 +++++++++++--------
 .../class_password-methods.inc                | 14 ++++----
 plugins/personal/generic/class_user.inc       |  2 +-
 3 files changed, 29 insertions(+), 23 deletions(-)

diff --git a/include/password-methods/class_password-methods-sasl.inc b/include/password-methods/class_password-methods-sasl.inc
index ab8c6214f..a170602d1 100644
--- a/include/password-methods/class_password-methods-sasl.inc
+++ b/include/password-methods/class_password-methods-sasl.inc
@@ -1,7 +1,7 @@
 <?php
 /*
   This code is part of FusionDirectory (http://www.fusiondirectory.org/)
-  Copyright (C) 2011-2016  FusionDirectory
+  Copyright (C) 2011-2017  FusionDirectory
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -27,37 +27,43 @@
  * \brief This class contains all the functions for sasl password methods
  * \see passwordMethod
  */
-class passwordMethodsasl extends passwordMethod {
+class passwordMethodsasl extends passwordMethod
+{
   // uid, or exop specified field value
-  var $uid    = "";
-  var $realm  = "";
-  var $exop   = "";
+  var $uid    = '';
+  var $realm  = '';
+  var $exop   = '';
 
   /*!
    * \brief passwordMethodsasl Constructor
    *
    * \param string $dn The DN
+   * \param object $userTab The user main tab object
    */
-  function __construct($dn = "")
+  function __construct($dn = '', $userTab = NULL)
   {
     global $config;
     $this->realm  = trim($config->get_cfg_value('saslRealm', ''));
     $this->exop   = trim($config->get_cfg_value('saslExop', ''));
 
-    if ($dn == "" || $dn == "new") {
+    if ($dn == '' || $dn == 'new') {
       return;
     }
 
-    $attr = (empty($this->exop)?'uid':$this->exop);
+    $attr = (empty($this->exop) ? 'uid' : $this->exop);
 
-    $ldap = $config->get_ldap_link();
-    $ldap->cd($config->current['BASE']);
-    $ldap->cat($dn, array($attr));
-    if ($ldap->count() == 1) {
-      $attrs = $ldap->fetch();
-      $this->uid = $attrs[$attr][0];
+    if (($userTab !== NULL) && isset($userTab->$attr)) {
+      $this->uid = $userTab->$attr;
     } else {
-      msg_dialog::display(_("Error"), sprintf(_("Cannot change password, unknown user '%s'"), $dn), ERROR_DIALOG);
+      $ldap = $config->get_ldap_link();
+      $ldap->cd($config->current['BASE']);
+      $ldap->cat($dn, array($attr));
+      if ($ldap->count() == 1) {
+        $attrs = $ldap->fetch();
+        $this->uid = $attrs[$attr][0];
+      } else {
+        msg_dialog::display(_('Error'), sprintf(_('Cannot change password, unknown user "%s"'), $dn), ERROR_DIALOG);
+      }
     }
   }
 
diff --git a/include/password-methods/class_password-methods.inc b/include/password-methods/class_password-methods.inc
index 196dbe2b8..b8d11ebe8 100644
--- a/include/password-methods/class_password-methods.inc
+++ b/include/password-methods/class_password-methods.inc
@@ -1,9 +1,8 @@
 <?php
-
 /*
   This code is part of FusionDirectory (http://www.fusiondirectory.org/)
   Copyright (C) 2003-2010  Cajus Pollmeier
-  Copyright (C) 2011-2016  FusionDirectory
+  Copyright (C) 2011-2017  FusionDirectory
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -32,15 +31,16 @@ class passwordMethod
 {
   var $attrs    = array();
   var $display  = FALSE;
-  var $hash     = "";
+  var $hash     = '';
   var $lockable = TRUE;
 
   /*!
    * \brief Password method contructor
    *
    * \param string $dn The DN
+   * \param object $userTab The user main tab object
    */
-  function __construct($dn = "")
+  function __construct($dn = '', $userTab = NULL)
   {
   }
 
@@ -127,9 +127,9 @@ class passwordMethod
     }
 
     /* Get current password hash */
-    $attrs = $this->attrs;
-    $pwd  = "";
-    $ldap = $config->get_ldap_link();
+    $attrs  = $this->attrs;
+    $pwd    = '';
+    $ldap   = $config->get_ldap_link();
     $ldap->cd($config->current['BASE']);
     if (!empty($dn)) {
       $ldap->cat($dn);
diff --git a/plugins/personal/generic/class_user.inc b/plugins/personal/generic/class_user.inc
index fed8e9b67..bf420151d 100644
--- a/plugins/personal/generic/class_user.inc
+++ b/plugins/personal/generic/class_user.inc
@@ -200,7 +200,7 @@ class UserPasswordAttribute extends CompositeAttribute
       trigger_error('Unknown password method '.$values[0]);
       return $values[3];
     }
-    $test = new $temp[$values[0]]($this->plugin->dn);
+    $test = new $temp[$values[0]]($this->plugin->dn, $this->plugin);
     $test->set_hash($values[0]);
     if ($this->plugin->is_template) {
       return $test->generate_hash($values[1]).'|'.$values[1];
-- 
GitLab