Code

Added "Select all" tooltip
[gosa.git] / gosa-plugins / sudo / admin / sudo / class_sudoGeneric.inc
index a2ba757bfa4b0cf03d8945e7b80733783445dccd..f29b615551a5424e9993caaf65f330f0d9a9c702 100644 (file)
  */
 class sudo extends plugin
 {
-  /* Group attributes */
-  var $cn= "";
-  var $description= "";
 
-  var $sudoUser   = array("ALL");
-  var $sudoCommand= array();
-  var $sudoHost   = array("ALL");
-  var $sudoRunas  = array("ALL");
+  protected $cn= "";
+  protected $description= "";
 
-  var $accessTo       = array();
-  var $trustModel     = "";
-  var $show_ws_dialog = FALSE;
+  protected $sudoUser   = array("ALL");
+  protected $sudoCommand= array();
+  protected $sudoHost   = array("ALL");
+  protected $sudoRunAs  = array("ALL");
+  protected $accessTo         = array();
+  protected $trustModel       = "";
 
-  var $objectclasses = array("top","sudoRole");
-  var $attributes    = array("cn","description","sudoUser","sudoCommand","sudoHost","sudoRunas","accessTo","trustModel");
+  private $is_default = FALSE;
+  private $show_ws_dialog   = FALSE;
+  private $was_trust_account= FALSE;
 
-  var $is_account = TRUE;
+  public $objectclasses = array("top","sudoRole");
+  public $attributes    = array("cn","description","sudoUser","sudoCommand","sudoHost","sudoRunAs","accessTo","trustModel");
 
-  var $dialog;
+  public $ignore_account = TRUE;
 
   /*! \brief  Returns to the base department for sudo roles.
               This department is then used to store new roles.
@@ -84,7 +84,7 @@ class sudo extends plugin
     plugin::plugin ($config, $dn);
 
     if($this->initially_was_account){
-      foreach(array("sudoUser","sudoCommand","sudoHost","sudoRunas") as $attr){
+      foreach(array("sudoUser","sudoCommand","sudoHost","sudoRunAs") as $attr){
         $this->$attr = array();
         if(isset($this->attrs[$attr])){
           $tmp = array();
@@ -96,7 +96,7 @@ class sudo extends plugin
       }
 
       /* Is this account a trustAccount? */
-      if ($this->is_account && isset($this->attrs['trustModel'])){
+      if (isset($this->attrs['trustModel'])){
         $this->trustModel= $this->attrs['trustModel'][0];
         $this->was_trust_account= TRUE;
       } else {
@@ -105,7 +105,7 @@ class sudo extends plugin
       }
 
       $this->accessTo = array();
-      if ($this->is_account && isset($this->attrs['accessTo'])){
+      if (isset($this->attrs['accessTo'])){
         for ($i= 0; $i<$this->attrs['accessTo']['count']; $i++){
           $tmp= $this->attrs['accessTo'][$i];
           $this->accessTo[$tmp]= $tmp;
@@ -113,6 +113,19 @@ class sudo extends plugin
       }
 
     }
+
+    if(preg_match("/^defaults$/i",$this->cn)){
+      $this->is_default = TRUE;
+    }
+
+    /* Get global filter config */
+    if (!session::is_set("sysfilter")){
+      $ui= get_userinfo();
+      $base= get_base_from_people($ui->dn);
+      $sysfilter= array( "depselect"       => $base,
+          "regex"           => "*");
+      session::set("sysfilter", $sysfilter);
+    }
   }
 
 
@@ -125,10 +138,10 @@ class sudo extends plugin
     plugin::execute();
 
     /*********************
-       Access control list 
+       Access control list / trust mode 
      *********************/ 
 
-     /* Add user workstation? */
+    /* Add user workstation? */
     if (isset($_POST["add_ws"])){
       $this->show_ws_dialog= TRUE;
       $this->dialog= TRUE;
@@ -157,62 +170,9 @@ class sudo extends plugin
       $this->dialog= FALSE;
     }
 
-  /* Show ws dialog */
+    /* Show ws dialog */
     if ($this->show_ws_dialog){
-
-      $smarty = get_smarty();
-
-
-       /* Save data */
-      $sysfilter= session::get("sysfilter");
-      foreach( array("depselect", "regex") as $type){
-        if (isset($_POST[$type])){
-          $sysfilter[$type]= $_POST[$type];
-        }
-      }
-      if (isset($_GET['search'])){
-        $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
-        if ($s == "**"){
-          $s= "*";
-        }
-        $sysfilter['regex']= $s;
-      }
-      session::set("sysfilter", $sysfilter);
-
-      /* Get workstation list */
-      $exclude= "";
-      foreach($this->accessTo as $ws){
-        $exclude.= "(cn=$ws)";
-      }
-      if ($exclude != ""){
-        $exclude= "(!(|$exclude))";
-      }
-      $regex= $sysfilter['regex'];
-      $filter= "(&(|(objectClass=goServer)(objectClass=gotoWorkstation)(objectClass=gotoTerminal))$exclude(cn=*)(cn=$regex))";
-
-      $deps_a = array(get_ou("serverou"),
-                      get_ou("terminalou"),
-                      get_ou("workstationou"));
-
-      $res= get_sub_list($filter, array("terminal","server","workstation"), $deps_a, get_ou("systemsou").$sysfilter['depselect'],          array("cn"), GL_SUBSEARCH | GL_SIZELIMIT);
-      $wslist= array();
-      foreach ($res as $attrs){
-        $wslist[]= preg_replace('/\$/', '', $attrs['cn'][0]);
-      }
-    asort($wslist);
-      $smarty->assign("search_image", get_template_path('images/search.png'));
-      $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
-      $smarty->assign("tree_image", get_template_path('images/tree.png'));
-      $smarty->assign("deplist", $this->config->idepartments);
-      $smarty->assign("alphabet", generate_alphabet());
-      foreach( array("depselect", "regex") as $type){
-        $smarty->assign("$type", $sysfilter[$type]);
-      }
-      $smarty->assign("hint", print_sizelimit_warning());
-      $smarty->assign("wslist", $wslist);
-      $smarty->assign("apply", apply_filter());
-      $display= $smarty->fetch (get_template_path('trust_machines.tpl', TRUE, dirname(__FILE__)));
-      return ($display);
+      return($this->display_trust_add_dialog());
     }
 
 
@@ -220,7 +180,7 @@ class sudo extends plugin
        Add users 
      *********************/ 
   
-    if(isset($_POST['list_sudoUser']) && !is_object($this->dialog)){
+    if(isset($_POST['list_sudoUser']) && !is_object($this->dialog) && $this->acl_is_writeable("sudoUser")){
       $used = array();
       foreach($this->sudoUser as $name){
         $used[] = preg_replace("/^!/","",$name);
@@ -230,12 +190,18 @@ class sudo extends plugin
    
     /* Add selected hosts  to the sudoUser list */ 
     if(isset($_POST['SaveMultiSelectWindow']) && $this->dialog instanceof target_list_users){
-      foreach($this->dialog->save() as $entry){
-        $cn = trim($entry['uid'][0]);
-        if(!in_array($cn,$this->sudoUser) && !in_array("!".$cn,$this->sudoUser)){
-          $this->sudoUser[] = $cn;
-        }
-      }   
+      if($this->acl_is_writeable("sudoUser")){
+        foreach($this->dialog->save() as $entry){
+          if(in_array("posixGroup",$entry['objectClass'])){
+            $name = trim("%".$entry['cn'][0]);
+          }else{
+            $name = trim($entry['uid'][0]);
+          }
+          if(!in_array($name,$this->sudoUser) && !in_array("!".$name,$this->sudoUser)){
+            $this->sudoUser[] = $name;
+          }
+        }   
+      }
       unset($this->dialog);
       $this->dialog = NULL;
     }    
@@ -245,7 +211,7 @@ class sudo extends plugin
        Add systems 
      *********************/ 
   
-    if(isset($_POST['list_sudoHost']) && !is_object($this->dialog)){
+    if(isset($_POST['list_sudoHost']) && !is_object($this->dialog) && $this->acl_is_writeable("sudoHost")){
       $used = array();
       foreach($this->sudoHost as $name){
         $used[] = preg_replace("/^!/","",$name);
@@ -255,11 +221,13 @@ class sudo extends plugin
    
     /* Add selected hosts  to the sudoHost list */ 
     if(isset($_POST['SaveMultiSelectWindow']) && $this->dialog instanceof target_list_systems){
-      foreach($this->dialog->save() as $entry){
-        $cn = trim($entry['cn'][0]);
-        if(!in_array($cn,$this->sudoHost) && !in_array("!".$cn,$this->sudoHost)){
-          $this->sudoHost[] = $cn;
-        }
+      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)){
+            $this->sudoHost[] = $cn;
+          }
+        }   
       }   
       unset($this->dialog);
       $this->dialog = NULL;
@@ -287,16 +255,18 @@ class sudo extends plugin
       if(preg_match("/^neg_/",$name)){
         $attr = preg_replace("/^neg_([^_]*)_.*$/","\\1",$name);
         $value= preg_replace("/^neg_[^_]*_([0-9]*)_.*$/","\\1",$name);
-  
-        $attrs = $this->$attr;
-        if(isset( $attrs[$value])){
-          $v =  $attrs[$value];
-          if(preg_match("/^!/",$v)){
-            $attrs[$value] = preg_replace("/^!/","",$v);
-          }else{
-            $attrs[$value] = "!".$v;
+        if($this->acl_is_writeable($attr)){
+          $attrs = $this->$attr;
+          if(isset( $attrs[$value])){
+            $v =  $attrs[$value];
+            if(preg_match("/^!/",$v)){
+              $attrs[$value] = preg_replace("/^!/","",$v);
+            }else{
+              $attrs[$value] = "!".$v;
+            }
+            $this->$attr = $attrs;  
           }
-          $this->$attr = $attrs;  
         }
         break; // Do it once, image inputs will be posted twice
       }
@@ -309,10 +279,12 @@ class sudo extends plugin
       if(preg_match("/^del_/",$name)){
         $attr = preg_replace("/^del_([^_]*)_.*$/","\\1",$name);
         $value= preg_replace("/^del_[^_]*_([0-9]*)_.*$/","\\1",$name);
-        $attrs = $this->$attr;
-        if(isset( $attrs[$value])){
-          unset($attrs[$value]);
-          $this->$attr = $attrs;  
+        if($this->acl_is_writeable($attr)){
+          $attrs = $this->$attr;
+          if(isset( $attrs[$value])){
+            unset($attrs[$value]);
+            $this->$attr = $attrs;  
+          }
         }
         break; // Do it once, image inputs will be posted twice
       }
@@ -321,9 +293,14 @@ class sudo extends plugin
 
     /*********************
        ADD values 
-     *********************/ 
-    foreach(array("sudoUser","sudoHost","sudoRunas") as $attr){
-      if(isset($_POST["add_".$attr]) && isset($_POST['new_'.$attr]) && !empty($_POST['new_'.$attr])){
+     *********************/
+
+    /* User / Host / Runas */ 
+    foreach(array("sudoUser","sudoHost","sudoRunAs") as $attr){
+      if($this->acl_is_writeable($attr) && 
+          isset($_POST["add_".$attr]) && 
+          isset($_POST['new_'.$attr]) && 
+          !empty($_POST['new_'.$attr])){
         if(preg_match("/^[a-z\.0-9]*$/i",$_POST['new_'.$attr])){
           $attrs = $this->$attr;
           $attrs[] =  trim($_POST['new_'.$attr]); 
@@ -334,80 +311,127 @@ class sudo extends plugin
       }
     }
 
+    /* Command */
     foreach(array("sudoCommand") as $attr){
-      if(isset($_POST["add_".$attr]) && isset($_POST['new_'.$attr])){
+      if($this->acl_is_writeable($attr) && isset($_POST["add_".$attr]) && isset($_POST['new_'.$attr])){
         $attrs = $this->$attr;
         $attrs[] =  trim($_POST['new_'.$attr]); 
         $this->$attr = $attrs;
       }
     }
 
+    
+    /*********************
+       SMARTY assignments 
+     *********************/
 
     $smarty = get_smarty();
+    $smarty->assign("is_default",$this->is_default);
     foreach($this->attributes as $attr){
-      $smarty->assign($attr,$this->$attr);
+      if(is_string($this->$attr)){
+        $smarty->assign($attr,htmlentities($this->$attr));
+      }else{
+        $smarty->assign($attr,$this->$attr);
+      }
+      $smarty->assign($attr."ACL",$this->getacl($attr));
     }
 
-
-/* Work on trust modes */
+    /* Work on trust modes */
     $smarty->assign("trusthide", " disabled ");
-    $smarty->assign("trustmodeACL",  $this->getacl("trustModel"));
     if ($this->trustModel == "fullaccess"){
       $trustmode= 1;
-      // pervent double disable tag in html code, this will disturb our clean w3c html
-      $smarty->assign("trustmode",  $this->getacl("trustModel"));
-
     } elseif ($this->trustModel == "byhost"){
       $trustmode= 2;
       $smarty->assign("trusthide", "");
     } else {
-      // pervent double disable tag in html code, this will disturb our clean w3c html
-      $smarty->assign("trustmode",  $this->getacl("trustModel"));
       $trustmode= 0;
     }
     $smarty->assign("trustmode", $trustmode);
-    $smarty->assign("trustmodes", array( 0 => _("disabled"), 1 => _("full access"),
+    $smarty->assign("trustmodes", array( 
+          0 => _("disabled"), 
+          1 => _("full access"),
           2 => _("allow access to these hosts")));
 
-    if((count($this->accessTo))==0)
+    if((count($this->accessTo))==0){
       $smarty->assign("emptyArrAccess",true);
-    else
+    }else{
       $smarty->assign("emptyArrAccess",false);
-
-
+    }
     $smarty->assign("workstations", $this->accessTo);
-
     
-
+    /* Create lists 
+     */
     $divlist_sudoUser = new divSelectBox("divlist_sudoUser");
     $divlist_sudoUser->SetHeight("90");
     $divlist_sudoHost = new divSelectBox("divlist_sudoHost");
     $divlist_sudoHost->Setheight("90");
-    $divlist_sudoRunas = new divSelectBox("divlist_sudoRunas");
-    $divlist_sudoRunas->Setheight("90");
+    $divlist_sudoRunAs = new divSelectBox("divlist_sudoRunAs");
+    $divlist_sudoRunAs->Setheight("90");
     $divlist_sudoCommand = new divSelectBox("divlist_sudoCommand");
     $divlist_sudoCommand->Setheight("90");
 
+    /* Fill divlists
+     */
     $neg_img= "<img src='images/negate.png' alt='!' class='center'>"; 
     $option = "<input type='image' src='images/negate.png'     name='neg_%ATTR%_%KEY%' class='center'>"; 
-    $option.= "<input type='image' src='images/edittrash.png'  name='del_%ATTR%_%KEY%' class='center'>"; 
-    foreach(array("sudoUser","sudoCommand","sudoHost","sudoRunas") as $attr){
-      foreach($this->$attr as $key => $entry){
-        $entry = preg_replace("/^!/",$neg_img,$entry);
-        $list_name = "divlist_".$attr;
-        $$list_name->AddEntry(
-          array(
-            array("string" => $entry),
-            array("string" => preg_replace(array("/%KEY%/","/%ATTR%/"),array($key,$attr),$option),
-              "attach" => "style='width:40px; border-right: 0px;'")));
+    $option.= "<input type='image' src='images/lists/trash.png'  name='del_%ATTR%_%KEY%' class='center'>"; 
+    foreach(array("sudoCommand","sudoHost","sudoRunAs") as $attr){
+      if($this->acl_is_readable($attr)){
+        foreach($this->$attr as $key => $entry){
+          $neg = "";
+          if(preg_match("/^!/",$entry)){
+            $neg = $neg_img;
+          }
+          $entry = preg_replace("/^!/","",$entry);
+          $list_name = "divlist_".$attr;
+          $$list_name->AddEntry(
+              array(
+                array("string" => $neg,"attach" => "style='width:18px;'"),
+                array("string" => $entry),
+                array("string" => preg_replace(array("/%KEY%/","/%ATTR%/"),array($key,$attr),$option),
+                  "attach" => "style='width:40px; border-right: 0px;'")));
+        }
       }
     }
 
-    $smarty->assign("divlist_sudoUser",$divlist_sudoUser->DrawList());
-    $smarty->assign("divlist_sudoHost",$divlist_sudoHost->DrawList());
-    $smarty->assign("divlist_sudoRunas",$divlist_sudoRunas->DrawList());
+    foreach(array("sudoUser") as $attr){
+      $img1 = "<img src='images/select_user.png'   alt='"._("User")."' class='center'>";
+      $img2 = "<img src='plugins/groups/images/groups.png' alt='"._("Group")."' class='center'>";
+      if($this->acl_is_readable($attr)){
+        foreach($this->$attr as $key => $entry){
+          $neg = "";
+          if(preg_match("/^!/",$entry)){
+            $neg = $neg_img;
+          }
+          $entry = preg_replace("/^!/","",$entry);
+
+          $img = $img1;
+          if(preg_match("/^%/",$entry)){
+            $img = $img2;
+          }
+          $entry = preg_replace("/^%/","",$entry);
+  
+          $list_name = "divlist_".$attr;
+          $$list_name->AddEntry(
+              array(
+                array("string" => $neg,"attach" => "style='width:18px;'"),
+                array("string" => $img,"attach" => "style='width:18px;'"),
+                array("string" => $entry),
+                array("string" => preg_replace(array("/%KEY%/","/%ATTR%/"),array($key,$attr),$option),
+                  "attach" => "style='width:40px; border-right: 0px;'")));
+        }
+      }
+    }
+
+
+
+
+    /* Tell smarty about our divlists 
+     */
+    $smarty->assign("divlist_sudoUser",   $divlist_sudoUser->DrawList());
+    $smarty->assign("divlist_sudoHost",   $divlist_sudoHost->DrawList());
+    $smarty->assign("divlist_sudoRunAs",  $divlist_sudoRunAs->DrawList());
     $smarty->assign("divlist_sudoCommand",$divlist_sudoCommand->DrawList());
-    
     return($smarty->fetch(get_template_path('generic.tpl', TRUE)));
   }
 
@@ -432,29 +456,31 @@ class sudo extends plugin
   function save_object()
   {
     plugin::save_object();
+    
+    if($this->is_default){
+      $this->cn = "defaults";
+    }  
 
     if(is_object($this->dialog)){
       $this->dialog->save_object();
     }
 
- /* Trust mode - special handling */
-      if($this->acl_is_writeable("trustModel")){
-        if (isset($_POST['trustmode'])){
-          $saved= $this->trustModel;
-          if ($_POST['trustmode'] == "1"){
-            $this->trustModel= "fullaccess";
-          } elseif ($_POST['trustmode'] == "2"){
-            $this->trustModel= "byhost";
-          } else {
-            $this->trustModel= "";
-          }
-          if ($this->trustModel != $saved){
-            $this->is_modified= TRUE;
-          }
+    /* Trust mode - special handling */
+    if($this->acl_is_writeable("trustModel")){
+      if (isset($_POST['trustmode'])){
+        $saved= $this->trustModel;
+        if ($_POST['trustmode'] == "1"){
+          $this->trustModel= "fullaccess";
+        } elseif ($_POST['trustmode'] == "2"){
+          $this->trustModel= "byhost";
+        } else {
+          $this->trustModel= "";
+        }
+        if ($this->trustModel != $saved){
+          $this->is_modified= TRUE;
         }
       }
-
-
+    }
   }
 
 
@@ -472,7 +498,7 @@ class sudo extends plugin
       $objectclasses[]= $this->attrs['objectClass'][$key];
     }
 
- $this->attrs['objectClass']= $objectclasses;
   $this->attrs['objectClass']= $objectclasses;
     if ($this->trustModel != ""){
       $this->attrs['objectClass'][]= "trustAccount";
       $this->attrs['trustModel']= $this->trustModel;
@@ -489,17 +515,19 @@ class sudo extends plugin
       }
     }
 
-   
+
     /* Ensure a correct array index 
      */ 
     $this->attrs['sudoHost']    = array_values($this->attrs['sudoHost']);
-    $this->attrs['sudoRunas']   = array_values($this->attrs['sudoRunas']);
+    $this->attrs['sudoRunAs']   = array_values($this->attrs['sudoRunAs']);
     $this->attrs['sudoUser']    = array_values($this->attrs['sudoUser']);
     $this->attrs['sudoCommand'] = array_values($this->attrs['sudoCommand']);
+
     $this->cleanup();
 
     $ldap = $this->config->get_ldap_link();
     $ldap->cd($this->config->current['BASE']);
+
     if($this->is_new){
       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
       $ldap->cd($this->dn);
@@ -527,10 +555,110 @@ class sudo extends plugin
   function check()
   {
     $message = plugin::check();
+
+    /* Is a name given? */
+    if(empty($this->cn)){
+      $message[] = msgPool::required(_("Name"));
+    }
+
+    /* Check if name is reserved */
+    if(!$this->is_default && preg_match("/^defaults$/i",$this->cn)){
+      $message[] = msgPool::reserved(_("Name"));
+    }
+
+    /* Check name */
+    if(!preg_match("/^[0-9a-z\@]*$/i",$this->cn)){
+      $message[] = msgPool::invalid(_("Name"),$this->cn,"/[0-9a-z\@]/i");
+    }
+
+    /* Check if this entry will cause duplicated ldap entries */
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($this->get_sudoers_ou($this->config));
+    $ldap->search("(&(objectClass=sudoRole)(cn=".$this->cn."))");
+    while($attrs = $ldap->fetch()){
+      if($attrs['dn'] != $this->dn){
+        $message[] = msgPool::duplicated(_("Name"));
+      }
+    }
+
     return ($message);
   }
 
 
+  /*! \brief  Display the System Trust Add Workstation dialog 
+    @return String  HTML dialog to add a system to the trust list.
+
+   */
+  private function display_trust_add_dialog()
+  {
+    $smarty = get_smarty();
+
+    /* Save data */
+    $sysfilter= session::get("sysfilter");
+    foreach( array("depselect", "regex") as $type){
+      if (isset($_POST[$type])){
+        $sysfilter[$type]= $_POST[$type];
+      }
+    }
+    if (isset($_GET['search'])){
+      $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
+      if ($s == "**"){
+        $s= "*";
+      }
+      $sysfilter['regex']= $s;
+    }
+    session::set("sysfilter", $sysfilter);
+
+    /* Get workstation list */
+    $exclude= "";
+    foreach($this->accessTo as $ws){
+      $exclude.= "(cn=$ws)";
+    }
+    if ($exclude != ""){
+      $exclude= "(!(|$exclude))";
+    }
+    $regex= $sysfilter['regex'];
+    $filter= "(&(|(objectClass=goServer)(objectClass=gotoWorkstation)(objectClass=gotoTerminal))$exclude(cn=*)(cn=$regex))";
+
+    $res = array();
+    $res= array_merge($res,get_sub_list($filter, array("terminal"), get_ou("terminalou"),
+        get_ou("systemsou").$sysfilter['depselect'],          array("cn"), GL_SUBSEARCH | GL_SIZELIMIT));
+    $res= array_merge($res,get_sub_list($filter, array("server"), get_ou("serverou"), 
+        get_ou("systemsou").$sysfilter['depselect'],          array("cn"), GL_SUBSEARCH | GL_SIZELIMIT));
+    $res= array_merge($res,get_sub_list($filter, array("workstation"), get_ou("workstationou"),
+        get_ou("systemsou").$sysfilter['depselect'],          array("cn"), GL_SUBSEARCH | GL_SIZELIMIT));
+
+    $wslist= array();
+    foreach ($res as $attrs){
+      $wslist[]= preg_replace('/\$/', '', $attrs['cn'][0]);
+    }
+    asort($wslist);
+    foreach( array("depselect","regex") as $type){
+      $smarty->assign("$type", $sysfilter[$type]);
+    }
+    $smarty->assign("search_image", get_template_path('images/lists/search.png'));
+    $smarty->assign("launchimage",  get_template_path('images/lists/action.png'));
+    $smarty->assign("tree_image",   get_template_path('images/lists/search-subtree.png'));
+    $smarty->assign("deplist",      $this->config->idepartments);
+    $smarty->assign("alphabet",     generate_alphabet());
+    $smarty->assign("hint",         print_sizelimit_warning());
+    $smarty->assign("wslist",       $wslist);
+    $smarty->assign("apply",        apply_filter());
+    $display= $smarty->fetch (get_template_path('trust_machines.tpl', TRUE, dirname(__FILE__)));
+    return ($display);
+  }
+
+
+  /*! \brief Force this entry to be handled and saved as 'default'
+      @param  BOOL  TRUE -force defaults   FALSE -normal
+   */
+  public function set_default($state)
+  {
+    $this->is_default = TRUE;
+    $this->cn = "defaults";
+  }
+
+
   /*! \brief  Add ACL object
       @return Returns the ACL object.
    */
@@ -551,9 +679,81 @@ class sudo extends plugin
             "sudoUser"          => _("Users"),
             "sudoHost"          => _("Host"),
             "sudoCommand"       => _("Command"),
-            "sudoRunas"         => _("Run as user"))
+            "sudoRunAs"         => _("Run as user"),
+            "trustModel"        => _("Access control list"))
         ));
   }
+
+
+  /*! \brief  This function will be called if an object gets copied.
+              This function adapts attributes from the source object.
+      @param  Array The source object.
+   */
+  function PrepareForCopyPaste($source)
+  {
+    plugin::PrepareForCopyPaste($source);
+    foreach(array("sudoUser","sudoCommand","sudoHost","sudoRunAs") as $attr){
+      $this->$attr = array();
+      if(isset($source[$attr])){
+        $tmp = array();
+        for($i = 0 ; $i < $source[$attr]['count']; $i++){
+          $tmp[] = $source[$attr][$i];
+        }
+        $this->$attr = $tmp;
+      }
+    }
+
+    /* Is this account a trustAccount? */
+    if (isset($source['trustModel'])){
+      $this->trustModel= $source['trustModel'][0];
+      $this->was_trust_account= TRUE;
+    } else {
+      $this->was_trust_account= FALSE;
+      $this->trustModel= "";
+    }
+
+    $this->accessTo = array();
+    if (isset($source['accessTo'])){
+      for ($i= 0; $i<$source['accessTo']['count']; $i++){
+        $tmp= $source['accessTo'][$i];
+        $this->accessTo[$tmp]= $tmp;
+      }
+    }
+  }
+
+
+  /*! \brief  Used for copy & paste.
+              Returns a HTML input mask, which allows to change the cn of this entry.
+      @param  Array   Array containing current status && a HTML template.              
+   */
+  function getCopyDialog()
+  {
+    $vars = array("cn");
+    $smarty = get_smarty();
+    $smarty->assign("cn", htmlentities($this->cn));
+    $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
+    $ret = array();
+    $ret['string'] = $str;
+    $ret['status'] = "";
+    return($ret);
+  }
+
+
+  public function get_cn()
+  {
+    return($this->cn);
+  }
+
+
+  /*! \brief  Used for copy & paste.
+              Some entries must be renamed to avaoid duplicate entries.
+   */
+  function saveCopyDialog()
+  {
+    if(isset($_POST['cn'])){
+      $this->cn = get_post('cn');
+    }
+  }
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>