Code

Updated server service.
[gosa.git] / include / class_password-methods.inc
index 2755134f11c15115fe7420b9ffada04b9da1afc6..e0b96c0dbafde5719ad5fb740092ca22a1bc5867 100644 (file)
@@ -95,6 +95,9 @@ function change_password ($dn, $password, $mode=0, $hash= "")
   global $config;
   $newpass= "";
 
+  /* Convert to lower. Methods are lowercase */
+  $hash= strtolower($hash);
+
   // Get all available encryption Methods 
 
   // NON STATIC CALL :)
@@ -106,11 +109,24 @@ function change_password ($dn, $password, $mode=0, $hash= "")
   $ldap->cat ($dn, array("shadowLastChange", "userPassword", "uid"));
   $attrs      = $ldap->fetch ();
 
-  // Set encryption type to clear if required 
-  if (isset($attrs['userPassword'][0]) && preg_match('/^[^{}]+$/', $attrs['userPassword'][0]) && $hash == ""){
-    $hash= "clear";
+  // Check if user account was deactivated, indicated by ! after } ... {crypt}!###
+  if(isset($attrs['userPassword'][0]) && preg_match("/^[^\}]*+\}!/",$attrs['userPassword'][0])){
+    $deactivated = TRUE;
+  }else{
+    $deactivated = FALSE;
   }
 
+#  // Get current password hash method if available 
+#  if($hash == "" && isset($attrs['userPassword'][0]) && preg_match("/[\{\}]/",$attrs['userPassword'][0])){
+#    $hash = preg_replace("/^[^\{]*+\{([^\}]*).*$/","\\1",$attrs['userPassword'][0]);
+#    $hash = strtolower($hash);
+#  }
+
+#  // Set encryption type to clear if required 
+#  if (!isset($attrs['userPassword'][0]) || $hash == ""){
+#    $hash= "clear";
+#  }
+
   // Detect the encryption Method
   if ( (isset($attrs['userPassword'][0]) &&  preg_match ("/^{([^}]+)}(.+)/", $attrs['userPassword'][0], $matches)) ||  $hash != ""){
 
@@ -156,12 +172,17 @@ function change_password ($dn, $password, $mode=0, $hash= "")
     $attrs= generate_smb_nt_hash($password);
   }
 
+  /* Readd ! if user was deactivated */
+  if($deactivated){
+    $newpass = preg_replace("/(^[^\}]+\})(.*$)/","\\1!\\2",$newpass);
+  }
+
   $attrs['userPassword']= array();
   $attrs['userPassword']= $newpass;
 
-
   $ldap->modify($attrs);
-
+  
+  new log("modify","users/passwordMethod",$dn,array_keys($attrs),$ldap->get_error());
 
   if ($ldap->error != 'Success') {
     print_red(sprintf(_("Setting the password failed. LDAP server says '%s'."),