Code

Updated function_dns.inc
[gosa.git] / include / class_password-methods.inc
index 97571da7900f3e6d51f3190319cc0ba9508d6e64..97546decf7b12b173c6ef93a5af86dfd7c527eea 100644 (file)
@@ -22,6 +22,7 @@
 class passwordMethod
 {
   var $config = false;
+  var $attrs= array();
 
   // Konstructor
   function passwordMethod($config)
@@ -102,14 +103,27 @@ function change_password ($dn, $password, $mode=0, $hash= "")
 
   // read current password entry for $dn, to detect the encryption Method
   $ldap       = $config->get_ldap_link();
-  $ldap->cat ($dn, array("shadowLastChange", "userPassword"));
+  $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 != ""){
 
@@ -121,9 +135,9 @@ function change_password ($dn, $password, $mode=0, $hash= "")
       $hash= strtolower($matches[1]);
     }
 
-
     // Crypt with the detected Method
     $test = new  $available[$hash]($config);
+    $test->attrs= $attrs;
     $newpass =  $test->generate_hash($password);
 
   } else {
@@ -154,6 +168,11 @@ 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;
 
@@ -199,7 +218,7 @@ function generate_smb_nt_hash($password)
   $hash= current($ar);
   if ($hash == "")
   {
-    print_red (_("Setting for SMBHASH in gosa.conf is incorrect! Can't change Samba password."));
+    print_red (sprintf(_("Setting for SMBHASH in %s is incorrect! Can't change Samba password."),CONFIG_FILE));
   }
   else 
   {