Code

Backport from trunk
[gosa.git] / gosa-plugins / sudo / admin / sudo / class_sudoGeneric.inc
index 0e139d7a6b496bb9fab35c4b7cfea02815882028..d52deed8416541e566e1044e473a3c34417d3238 100644 (file)
@@ -42,7 +42,9 @@ class sudo extends plugin
 
     public $ignore_account = TRUE;
 
+       
     public $orig_dn;
+    private $systemEnabled = FALSE;
 
     /*! \brief  Returns to the base department for sudo roles.
       This department is then used to store new roles.
@@ -63,6 +65,8 @@ class sudo extends plugin
     {
         plugin::plugin ($config, $dn);
 
+       $this->systemEnabled = class_available("systemSelect");
+
         $this->trustModeDialog = new trustModeDialog($this->config, $this->dn,NULL);
         $this->trustModeDialog->setAcl('sudo/sudo');
 
@@ -125,6 +129,12 @@ class sudo extends plugin
         /* Call parent execute */
         plugin::execute();
 
+        // Set list ACLs
+        foreach(array('sudoUser','sudoCommand','sudoHost','sudoRunAs') as $l){
+            $ll = $l."List";
+            $this->$ll->setAcl($this->getacl($l));
+        }
+
         // Handle trust mode dialog
         $trustModeDialog = $this->trustModeDialog->execute();
         if($this->trustModeDialog->trustSelect){
@@ -132,7 +142,10 @@ class sudo extends plugin
             return($trustModeDialog);
 
         }
-        $this->dialog = FALSE;
+
+        if(!is_object($this->dialog)){
+            $this->dialog = FALSE;
+        }
 
         /*********************
           Add users 
@@ -146,12 +159,12 @@ class sudo extends plugin
         if(isset($_POST['userGroupSelect_save']) && $this->dialog instanceof userGroupSelect){
             if($this->acl_is_writeable("sudoUser")){
                 foreach($this->dialog->save() as $entry){
-                    if(in_array("posixGroup",$entry['objectClass'])){
+                    if(in_array_strict("posixGroup",$entry['objectClass'])){
                         $name = trim("%".$entry['cn'][0]);
                     }elseif(isset($entry['uid'][0])){
                         $name = trim($entry['uid'][0]);
                     }
-                    if(!in_array($name,$this->sudoUser) && !in_array("!".$name,$this->sudoUser)){
+                    if(!in_array_strict($name,$this->sudoUser) && !in_array_strict("!".$name,$this->sudoUser)){
                         $this->sudoUser[] = $name;
                     }
                 }   
@@ -196,7 +209,7 @@ class sudo extends plugin
             if($this->acl_is_writeable("sudoHost")){
                 foreach($this->dialog->save() as $entry){
                     $cn = trim($entry['cn'][0]);
-                    if(!in_array($cn,$this->sudoHost) && !in_array("!".$cn,$this->sudoHost)){
+                    if(!in_array_strict($cn,$this->sudoHost) && !in_array_strict("!".$cn,$this->sudoHost)){
                         $this->sudoHost[] = $cn;
                     }
                 }   
@@ -234,6 +247,7 @@ class sudo extends plugin
           NEGATE values 
          *********************/ 
         foreach($_POST as $name => $value){
+            $value =get_post($name);
             if(preg_match("/^neg_/",$name)){
                 $attr = preg_replace("/^neg_([^_]*)_.*$/","\\1",$name);
                 $value= preg_replace("/^neg_[^_]*_([0-9]*)$/","\\1",$name);
@@ -258,6 +272,7 @@ class sudo extends plugin
           Delete values 
          *********************/ 
         foreach($_POST as $name => $value){
+            $value =get_post($name);
             if(preg_match("/^delS_/",$name)){
                 $attr = preg_replace("/^delS_([^_]*).*$/","\\1",$name);
                 $value= preg_replace("/^delS_[^_]*_([0-9]*)$/","\\1",$name);
@@ -283,12 +298,14 @@ class sudo extends plugin
                     isset($_POST["add_".$attr]) && 
                     isset($_POST['new_'.$attr]) && 
                     !empty($_POST['new_'.$attr])){
-                if(preg_match("/^[a-z\.0-9]*$/i",$_POST['new_'.$attr])){
+
+                $c = preg_quote(' *+-?_|!\'"()','/');
+                if(preg_match("/^[a-z0-9{$c}]*$/i",get_post('new_'.$attr))){
                     $attrs = $this->$attr;
-                    $attrs[] =  trim($_POST['new_'.$attr]); 
+                    $attrs[] =  trim(get_post('new_'.$attr)); 
                     $this->$attr = $attrs;
                 }else{
-                    msg_dialog::display(_("Error"),msgPool::invalid($attr,$_POST['new_'.$attr],"/[a-z0-9]/"));
+                    msg_dialog::display(_("Error"),msgPool::invalid($attr,get_post('new_'.$attr),"/[a-z0-9{$c}]/i"));
                 }
             }
         }
@@ -297,7 +314,7 @@ class sudo extends plugin
         foreach(array("sudoCommand") as $attr){
             if($this->acl_is_writeable($attr) && isset($_POST["add_".$attr]) && isset($_POST['new_'.$attr])){
                 $attrs = $this->$attr;
-                $attrs[] =  trim($_POST['new_'.$attr]); 
+                $attrs[] =  trim(get_post('new_'.$attr)); 
                 $this->$attr = $attrs;
             }
         }
@@ -308,14 +325,11 @@ class sudo extends plugin
          *********************/
 
         $smarty = get_smarty();
+        $smarty->assign("systemEnabled", $this->systemEnabled);
         $smarty->assign("trustModeDialog" , $trustModeDialog);
         $smarty->assign("is_default",$this->is_default);
         foreach($this->attributes as $attr){
-            if(is_string($this->$attr)){
-                $smarty->assign($attr,htmlentities($this->$attr));
-            }else{
-                $smarty->assign($attr,$this->$attr);
-            }
+            $smarty->assign($attr, set_post($this->$attr));
             $smarty->assign($attr."ACL",$this->getacl($attr));
         }
 
@@ -433,7 +447,7 @@ class sudo extends plugin
             $ldap->add($this->attrs);
 
             /* Send signal to the world that we've done */
-            $this->handle_post_events("create");
+            $this->handle_post_events("add");
         }else{
             $ldap->cd($this->dn);
             $ldap->modify($this->attrs);;
@@ -516,28 +530,29 @@ class sudo extends plugin
                     "plSection"     => array("administration"),
                     "plCategory"    => array("sudo" => array("objectClass" => "sudoRole", "description" => _("Sudo role"))),
 
+                    "plProperties" => 
                     array(
                         array(
                             "name"          => "sudoRDN",
                             "type"          => "rdn",
                             "default"       => "ou=sudoers,",
-                            "description"   => "The 'sudoRDN' statement defines the location where new sudo-roles will be created. The default is 'ou=sudoers,'.",
+                            "description"   => _("RDN for sudo rule storage."),
                             "check"         => "gosaProperty::isRdn",
                             "migrate"       => "migrate_sudoRDN",
                             "group"         => "plugin",
                             "mandatory"     => FALSE)),
 
 
-                    "plProvidedAcls"    => array(
-                        "accessTo"          => _("System trust"),
-                        "cn"                => _("Name"),
-                        "description"       => _("Description"),
-                        "sudoUser"          => _("Users"),
-                        "sudoHost"          => _("Host"),
-                        "sudoCommand"       => _("Command"),
-                        "sudoRunAs"         => _("Run as user"),
-                        "trustModel"        => _("Access control list"))
-                    ));
+            "plProvidedAcls"    => array(
+                    "accessTo"          => _("System trust"),
+                    "cn"                => _("Name"),
+                    "description"       => _("Description"),
+                    "sudoUser"          => _("Users"),
+                    "sudoHost"          => _("Host"),
+                    "sudoCommand"       => _("Command"),
+                    "sudoRunAs"         => _("Run as user"),
+                    "trustModel"        => _("Access control list"))
+                ));
     }
 
 
@@ -548,7 +563,7 @@ class sudo extends plugin
     function PrepareForCopyPaste($source)
     {
         plugin::PrepareForCopyPaste($source);
-        
+
         $this->trustModeDialog->PrepareForCopyPaste($source);
 
         foreach(array("sudoUser","sudoCommand","sudoHost","sudoRunAs") as $attr){
@@ -572,7 +587,7 @@ class sudo extends plugin
     {
         $vars = array("cn");
         $smarty = get_smarty();
-        $smarty->assign("cn", htmlentities($this->cn));
+        $smarty->assign("cn", set_post($this->cn));
         $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
         $ret = array();
         $ret['string'] = $str;