From ecfaa61bdc6474216ad113a719fb9994a9086f69 Mon Sep 17 00:00:00 2001 From: hickert Date: Thu, 27 Nov 2008 08:56:37 +0000 Subject: [PATCH] Updated function.sinc change_password. -Added check to ensure that the selected password method is valid ($test instanceOf passowrdMethod) git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13051 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-core/include/functions.inc | 103 ++++++++++++++++---------------- 1 file changed, 53 insertions(+), 50 deletions(-) diff --git a/gosa-core/include/functions.inc b/gosa-core/include/functions.inc index ba46e840d..991f63e3e 100644 --- a/gosa-core/include/functions.inc +++ b/gosa-core/include/functions.inc @@ -2500,72 +2500,75 @@ function change_password ($dn, $password, $mode=0, $hash= "") $test = new $available['md5']($config); } - /* Feed password backends with information */ - $test->dn= $dn; - $test->attrs= $attrs; - $newpass= $test->generate_hash($password); - - // Update shadow timestamp? - if (isset($attrs["shadowLastChange"][0])){ - $shadow= (int)(date("U") / 86400); - } else { - $shadow= 0; - } - - // Write back modified entry - $ldap->cd($dn); - $attrs= array(); + if($test instanceOf passwordMethod){ - // Not for groups - if ($mode == 0){ + /* Feed password backends with information */ + $test->dn= $dn; + $test->attrs= $attrs; + $newpass= $test->generate_hash($password); - if ($shadow != 0){ - $attrs['shadowLastChange']= $shadow; + // Update shadow timestamp? + if (isset($attrs["shadowLastChange"][0])){ + $shadow= (int)(date("U") / 86400); + } else { + $shadow= 0; } - // Create SMB Password - $attrs= generate_smb_nt_hash($password); - } + // Write back modified entry + $ldap->cd($dn); + $attrs= array(); - /* Read ! if user was deactivated */ - if($deactivated){ - $newpass = preg_replace("/(^[^\}]+\})(.*$)/","\\1!\\2",$newpass); - } + // Not for groups + if ($mode == 0){ - $attrs['userPassword']= array(); - $attrs['userPassword']= $newpass; + if ($shadow != 0){ + $attrs['shadowLastChange']= $shadow; + } - $ldap->modify($attrs); + // Create SMB Password + $attrs= generate_smb_nt_hash($password); + } - new log("modify","users/passwordMethod",$dn,array_keys($attrs),$ldap->get_error()); + /* Read ! if user was deactivated */ + if($deactivated){ + $newpass = preg_replace("/(^[^\}]+\})(.*$)/","\\1!\\2",$newpass); + } - if (!$ldap->success()) { - msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, ERROR_DIALOG)); - } else { + $attrs['userPassword']= array(); + $attrs['userPassword']= $newpass; - /* Run backend method for change/create */ - if(!$test->set_password($password)){ - return(FALSE); - } + $ldap->modify($attrs); - /* Find postmodify entries for this class */ - $command= $config->search("password", "POSTMODIFY",array('menu')); + new log("modify","users/passwordMethod",$dn,array_keys($attrs),$ldap->get_error()); - if ($command != ""){ - /* Walk through attribute list */ - $command= preg_replace("/%userPassword/", $password, $command); - $command= preg_replace("/%dn/", $dn, $command); + if (!$ldap->success()) { + msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, ERROR_DIALOG)); + } else { - if (check_command($command)){ - @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute"); - exec($command); - } else { - $message= sprintf(_("Command '%s', specified as POSTMODIFY for plugin '%s' doesn't seem to exist."), $command, "password"); - msg_dialog::display(_("Configuration error"), $message, ERROR_DIALOG); + /* Run backend method for change/create */ + if(!$test->set_password($password)){ + return(FALSE); + } + + /* Find postmodify entries for this class */ + $command= $config->search("password", "POSTMODIFY",array('menu')); + + if ($command != ""){ + /* Walk through attribute list */ + $command= preg_replace("/%userPassword/", $password, $command); + $command= preg_replace("/%dn/", $dn, $command); + + if (check_command($command)){ + @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute"); + exec($command); + } else { + $message= sprintf(_("Command '%s', specified as POSTMODIFY for plugin '%s' doesn't seem to exist."), $command, "password"); + msg_dialog::display(_("Configuration error"), $message, ERROR_DIALOG); + } } } + return(TRUE); } - return(TRUE); } -- 2.30.2