Code

Backports from 2.7
[gosa.git] / gosa-core / plugins / admin / users / class_userManagement.inc
index 87c008f54862b916bc6b43a676aba3905abc665b..67f6021bca54dadf832fb7c1d0b6b85b90a954c1 100644 (file)
@@ -274,8 +274,8 @@ class userManagement extends management
             $ldap->cat($this->dn);
             $attrs = $ldap->fetch();
             $this->passwordChangeForceable = 
-                    in_array('sambaAccount', $attrs['objectClass']) || 
-                    (in_array('posixAccount', $attrs['objectClass']) && isset($attrs['shadowMax']));
+                    in_array_strict('sambaAccount', $attrs['objectClass']) || 
+                    (in_array_strict('posixAccount', $attrs['objectClass']) && isset($attrs['shadowMax']));
             $smarty->assign("passwordChangeForceable" , $this->passwordChangeForceable);
             $smarty->assign("enforcePasswordChange" , $this->enforcePasswordChange);
 
@@ -320,29 +320,38 @@ class userManagement extends management
                     }
                 }
 
+                // Call external check hook to validate the password change
+                if(!count($message)){
+                    $attrs = array();
+                    $attrs['current_password'] = '';
+                    $attrs['new_password'] = $new_password;
+                    $checkRes = password::callCheckHook($this->config,$this->dn,$attrs);
+                    if(count($checkRes)){
+                        $message[] = sprintf(_("Check-hook reported a problem: %s. Password change canceled!"), 
+                                implode($checkRes));
+                    }
+                }
+
                 // Display errors
                 if (count($message) != 0){
                     msg_dialog::displayChecks($message);
                     return($smarty->fetch(get_template_path('password.tpl', TRUE)));
                 }
 
-                // Change cassword 
+
+
+                // Change password 
                 if(isset($this->force_hash_type[$this->dn])){
-                    if(!change_password ($this->dn, $new_password,0,$this->force_hash_type[$this->dn])){
+                    if(!change_password ($this->dn, $new_password,0,$this->force_hash_type[$this->dn],'', $message)){
+                        msg_dialog::displayChecks(array($message));
                         return($smarty->fetch(get_template_path('password.tpl', TRUE)));
                     }
                 }else{
-                    if(!change_password ($this->dn, $new_password)){
+                    if(!change_password ($this->dn, $new_password,0,'','',$message)){
+                        msg_dialog::displayChecks(array($message));
                         return($smarty->fetch(get_template_path('password.tpl', TRUE)));
                     }
                 }
-                if ($this->config->get_cfg_value("core","passwordHook") != ""){
-                    $ldap = $this->config->get_ldap_link();
-                    $ldap->cd($this->config->current['BASE']);
-                    $ldap->cat($this->dn,array('uid'));
-                    $attrs = $ldap->fetch();
-                    exec($this->config->get_cfg_value("core","passwordHook")." ".$attrs['uid'][0]." ".$new_password, $resarr);
-                }
         
                 // The user has to change his password on next login
                 // - We are going to update samba and posix attributes here, to enforce
@@ -354,8 +363,8 @@ class userManagement extends management
                     $ldap->cd($this->config->current['BASE']);
                     $ldap->cat($this->dn);
                     $attrs = $ldap->fetch();
-                    $samba = in_array('sambaSamAccount', $attrs['objectClass']);
-                    $posix = in_array('posixAccount', $attrs['objectClass']);
+                    $samba = in_array_strict('sambaSamAccount', $attrs['objectClass']);
+                    $posix = in_array_strict('posixAccount', $attrs['objectClass']);
 
                     // Update the posix shadow flag...
                     if($posix){
@@ -378,10 +387,8 @@ class userManagement extends management
                     if($samba){
                         $sambaAccount = new sambaAccount($this->config, $this->dn);
                         $sambaAccount->is_modified=TRUE;
-                        $sambaAccount->enforcePasswordChange=TRUE;
-                        $sambaAccount->cannotChangePassword=FALSE;
-                        $sambaAccount->sambaPwdCanChange=0;
-                        $sambaAccount->sambaAcctFlags = preg_replace("/X/i","",$sambaAccount->sambaAcctFlags);
+                        $sambaAccount->flag_enforcePasswordChange = TRUE;
+                        $sambaAccount->flag_cannotChangePassword = FALSE;
                         $sambaAccount->save();
                     }
                 }
@@ -474,6 +481,7 @@ class userManagement extends management
             $smarty->assign("template",  array_pop($target));
             $smarty->assign("templates", $templates);
             $smarty->assign("edit_uid", "");
+            $smarty->assign("allowUidProposalModification", $this->config->get_cfg_value("core","allowUidProposalModification"));
             return($smarty->fetch(get_template_path('template.tpl', TRUE)));
 
             // -> See 'templateContinue' for further handling!
@@ -510,6 +518,7 @@ class userManagement extends management
             $smarty->assign("template", "none");
             $smarty->assign("templates", $templates);
             $smarty->assign("edit_uid", "");
+            $smarty->assign("allowUidProposalModification", $this->config->get_cfg_value("core","allowUidProposalModification"));
             return($smarty->fetch(get_template_path('template.tpl', TRUE)));
 
             // -> See 'templateContinue' for further handling!
@@ -563,6 +572,7 @@ class userManagement extends management
             $smarty->assign("templates",$templates);
             $smarty->assign("got_uid", $this->got_uid);
             $smarty->assign("edit_uid",false);
+            $smarty->assign("allowUidProposalModification", $this->config->get_cfg_value("core","allowUidProposalModification"));
             return($smarty->fetch(get_template_path('template.tpl', TRUE)));
         }
 
@@ -585,16 +595,23 @@ class userManagement extends management
 
             if ($ldap->count () != 0){
                 msg_dialog::displayChecks(array(msgPool::duplicated(_("Name"))));
+                $smarty->assign("edit_uid", "");
             }else{
 
                 // Preset uid field by using the idGenerator 
                 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
                 if ($this->config->get_cfg_value("core","idGenerator") != ""){
-                    $uids= gen_uids ($this->config->get_cfg_value("core","idGenerator"), $attributes);
-                    if (count($uids)){
-                        $smarty->assign("edit_uid", "false");
-                        $smarty->assign("uids", $uids);
-                        $this->uid= current($uids);
+                    $genStr = $this->config->get_cfg_value("core","idGenerator");
+                    $smarty->assign("edit_uid", "");
+                    if(!empty($genStr)){
+                        $uids= gen_uids($genStr, $attributes);
+                        if (count($uids)){
+                            $smarty->assign("edit_uid", "false");
+                            $smarty->assign("uids", $uids);
+                            $this->uid= current($uids);
+                        }else{
+                            msg_dialog::displayChecks(array(_("Cannot generate a unique id, please specify it manually!")));
+                        }
                     }
                 } else {
                     $smarty->assign("edit_uid", "");
@@ -611,6 +628,7 @@ class userManagement extends management
                 $smarty->assign("template", get_post('template'));
             }
             $smarty->assign("templates",$templates); 
+            $smarty->assign("allowUidProposalModification", $this->config->get_cfg_value("core","allowUidProposalModification"));
             return($smarty->fetch(get_template_path('template.tpl', TRUE)));
         }
 
@@ -886,7 +904,7 @@ class userManagement extends management
                 "apple-user" => array("image" => "plugins/netatalk/images/select_netatalk.png",
                     "plugin" => "netatalk",
                     "alt" => _("Netatalk"),
-                    "title" => _("Edit netatalk properties")),
+                    "title" => _("Edit Netatalk properties")),
                 "gotoEnvironment" => array("image" => "plugins/users/images/small_environment.png",
                     "plugin" => "environment",
                     "alt" => _("Environment"),