Code

Added password check hook to userManagement
[gosa.git] / gosa-core / plugins / admin / users / class_userManagement.inc
index a8aa4369ffe73d675a2c828c9e3f55e9a5ed5c11..2d27f7c4f50c7a51662ddec92b8a73ea1d7c3e3b 100644 (file)
@@ -253,7 +253,7 @@ class userManagement extends management
         $this->enforcePasswordChange = isset($_POST['new_password']) && isset($_POST['enforcePasswordChange']);
 
         $smarty = get_smarty();
-        $smarty->assign("proposal" , $this->proposal);
+        $smarty->assign("proposal" , set_post($this->proposal));
         $smarty->assign("proposalEnabled" , $this->proposalEnabled);
         $smarty->assign("proposalSelected" , $this->proposalSelected);
 
@@ -280,7 +280,7 @@ class userManagement extends management
             $smarty->assign("enforcePasswordChange" , $this->enforcePasswordChange);
 
             // Assign proposal variables
-            $smarty->assign("proposal" , $this->proposal);
+            $smarty->assign("proposal" , set_post($this->proposal));
             $smarty->assign("proposalEnabled" , $this->proposalEnabled);
             $smarty->assign("proposalSelected" , $this->proposalSelected);
 
@@ -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 
                 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
@@ -378,8 +387,8 @@ class userManagement extends management
                     if($samba){
                         $sambaAccount = new sambaAccount($this->config, $this->dn);
                         $sambaAccount->is_modified=TRUE;
-                        $sambaAccount->kickoff_time_set  = "1";
-                        $sambaAccount->sambaKickoffTime= date('d.m.Y', time() - (1 * 24 * 60 *60));
+                        $sambaAccount->flag_enforcePasswordChange = TRUE;
+                        $sambaAccount->flag_cannotChangePassword = FALSE;
                         $sambaAccount->save();
                     }
                 }
@@ -552,7 +561,7 @@ class userManagement extends management
             $smarty = get_smarty();
             foreach(array("sn", "givenName", "uid", "template") as $attr){
                 if(isset($_POST[$attr])){
-                    $smarty->assign("$attr", get_post($attr));
+                    $smarty->assign("$attr", set_post(get_post($attr)));
                 }else{
                     $smarty->assign("$attr", "");
                 }
@@ -564,7 +573,6 @@ class userManagement extends management
             return($smarty->fetch(get_template_path('template.tpl', TRUE)));
         }
 
-
         /********************
          * 2   There was a template selected, now ask for the uid.
          ********************/
@@ -573,14 +581,15 @@ class userManagement extends management
 
             // Remember user input.
             $smarty = get_smarty();
-            $this->sn             = $_POST['sn'];
-            $this->givenName      = $_POST['givenName'];
+            $this->sn             = get_post('sn');
+            $this->givenName      = get_post('givenName');
 
             // Avoid duplicate entries, check if such a user already exists.
-            $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
+            $dn= preg_replace("/^[^,]+,/i", "", get_post('template'));
             $ldap= $this->config->get_ldap_link();
             $ldap->cd ($dn);
             $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName"));
+
             if ($ldap->count () != 0){
                 msg_dialog::displayChecks(array(msgPool::duplicated(_("Name"))));
             }else{
@@ -603,10 +612,10 @@ class userManagement extends management
 
             // Assign user input 
             foreach(array("sn", "givenName", "uid", "got_uid") as $attr){
-                $smarty->assign("$attr", $this->$attr);
+                $smarty->assign("$attr", set_post($this->$attr));
             }
             if (isset($_POST['template'])){
-                $smarty->assign("template", $_POST['template']);
+                $smarty->assign("template", get_post('template'));
             }
             $smarty->assign("templates",$templates); 
             return($smarty->fetch(get_template_path('template.tpl', TRUE)));
@@ -616,10 +625,10 @@ class userManagement extends management
         /********************
          * 3   No template - Ok. Lets fill the data into the user object and skip templating here. 
          ********************/
-        if ($_POST['template'] == 'none'){
+        if (get_post('template') == 'none'){
             foreach(array("sn", "givenName", "uid") as $attr){
                 if (isset($_POST[$attr])){
-                    $this->tabObject->by_object['user']->$attr= $_POST[$attr];
+                    $this->tabObject->by_object['user']->$attr= get_post($attr);
                 }
             }
 
@@ -636,13 +645,13 @@ class userManagement extends management
 
             // Move user supplied data to sub plugins 
             foreach(array("uid","sn","givenName") as $attr){
-                $this->$attr = $_POST[$attr];
+                $this->$attr = get_post($attr);
                 $this->tabObject->$attr       = $this->$attr;
                 $this->tabObject->by_object['user']->$attr = $this->$attr;
             }
 
             // Adapt template values.
-            $template_dn              = $_POST['template'];
+            $template_dn              = get_post('template');
             $this->tabObject->adapt_from_template($template_dn, array("uid","cn","givenName","sn"));
             $template_base            = preg_replace("/^[^,]+,".preg_quote(get_people_ou(), '/i')."/", '', $template_dn);
             $this->tabObject->by_object['user']->base= $template_base;
@@ -884,7 +893,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"),