Code

Added acls for printer glpi
[gosa.git] / plugins / admin / systems / class_printGeneric.inc
index 51b124383034e151f792c4f8f3d8ada7428008b6..9ff8c3e3b912fcce9e0a89dce492312c66096619 100644 (file)
@@ -28,7 +28,6 @@ class printgeneric extends plugin
   var $AdminMembers     =array();
   var $AdminMemberKeys  =array();
 
-  var $gotoUserPrinter ;
   var $PPDdialogToSave  = NULL;
   var $BelongsTo        = "unknown"; //  Specifies if this is a standalone printer, or belongs to a terminal / WS
 
@@ -40,15 +39,23 @@ class printgeneric extends plugin
   var $baseSelection    = false;
   var $macAddress       = "";
 
+  var $gotoUserAdminPrinter;
+  var $gotoGroupAdminPrinter ;
+  var $gotoGroupPrinter;
+  var $gotoUserPrinter ;
+
   /* attribute list for save action */
-  var $attributes     = array("cn", "description", "l", "labeledURI", "gotoPrinterPPD","gotoUserPrinter", "macAddress");
+  var $attributes     = array("cn", "description", "l", "labeledURI", "gotoPrinterPPD","gotoUserPrinter", "macAddress", 
+                              "gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter","gotoGroupPrinter");
   var $objectclasses  = array("top", "gotoPrinter");
 
-  function printgeneric ($config, $dn= NULL,$parent = NULL)
+  var $parent;
+
+  function printgeneric ($config, $dn,$parent_init,$parent)
   {
     $this->config = $config;
     $this->dn = $dn; 
-    
     /* If parent was posted(the tabs object) we can detect the printer type. */
     if($parent){
       $this->parent = $parent;
@@ -70,14 +77,14 @@ class printgeneric extends plugin
     $this->orig_dn = $this->dn;
 
     /* Get printer settings, possibly dn has changed */
-    plugin::plugin ($config, $this->dn);
+    plugin::plugin ($config, $this->dn,$parent_init);
 
     /* Get is_account initially_was_account status */
     $this->getTypeOfPrinter(true);
 
     /* set orig dn to new if object is new */
     $ldap= $this->config->get_ldap_link();
-    $ldap->cat($this->dn);
+    $ldap->cat($this->dn, array('dn'));
     if(!$ldap->count()){
       $this->orig_dn = "new";
     }
@@ -93,7 +100,12 @@ class printgeneric extends plugin
     } else {
     
       /* Set base and check if the extracted base exists */
-      $this->base= preg_replace("/ou=printers,ou=systems,/","",dn2base($this->dn));
+      if(preg_match("/ou=incoming,/",$this->dn)){
+        $this->base= preg_replace("/ou=incoming,/","",dn2base($this->dn));
+      }else{
+        $this->base= preg_replace("/ou=printers,ou=systems,/","",dn2base($this->dn));
+      }
+
       if(!isset($this->config->idepartments[$this->base])){
         print_red(_("Can't extract a valid base out of object dn, setting base to '%s'."),$_SESSION['CurrentMainBase']);
         $this->base = $_SESSION['CurrentMainBase'];
@@ -122,14 +134,14 @@ class printgeneric extends plugin
         foreach($this->attrs[$attr] as $mem){
           if(preg_match("/Group/",$type)){
             $ldap->search("(&(objectClass=posixGroup)(cn=".$mem."))",array("cn","description"));
-            $entry = $ldap->fetch();
-            if(isset($entry['description'])){
+            if($ldap->count()){
+              $entry = $ldap->fetch();
               $this->member[$type][$entry['cn'][0]]=$entry;
             }
           }else{
             $ldap->search("(&(objectClass=person)(objectClass=inetOrgPerson)(uid=".$mem."))",array("cn","uid"));
-            $entry = $ldap->fetch();
-            if(isset($entry['uid'])){
+            if($ldap->count()){
+              $entry = $ldap->fetch();
               $this->member[$type][$entry['uid'][0]]=$entry;
             }
           }
@@ -151,6 +163,8 @@ class printgeneric extends plugin
 
     /* Detect type of printer via parent tabs.
      */
+
+    $class = get_class($this->parent);
     if(isset($this->parent->by_object['workgeneric'])){
 
       /* Exclude templates 
@@ -202,8 +216,7 @@ class printgeneric extends plugin
       /* Detect if this is a valid printer account;
        */
       $ldap = $this->config->get_ldap_link();
-      $ldap->cd($this->config->current['BASE']);
-      $ldap->cat($this->dn);
+      $ldap->cat($this->dn, array('objectClass'));
 
       if($ldap->count()){
         $attrs = $ldap->fetch();
@@ -222,24 +235,24 @@ class printgeneric extends plugin
     /* Call parent execute */
     plugin::execute();
 
-    /* If type of printer couldn't be detected (because of missing parent object in construcktion) 
+    /* If type of printer couldn't be detected (because of missing parent object in construction) 
      * hide this tab.
      */
     if($this->BelongsTo == "unknown"){
-      $display= $this->show_header(_("Add printer extension"),
-          _("Could not intialize printer tab, parameter parent was missing while construcktion."),TRUE,TRUE);
+      $display= $this->show_enable_header(_("Add printer extension"),
+          _("Could not intialize printer tab, parameter parent was missing while construction."),TRUE,TRUE);
       return($display);
     }
 
     /* Templates can't have printer extensions 
      */
     if($this->BelongsTo == "WorkstationTemplate"){
-      $display= $this->show_header(_("Add printer extension"),
+      $display= $this->show_enable_header(_("Add printer extension"),
           _("This is a workstation template, printer tab is disabled."),TRUE,TRUE);
       return($display);
     }
     if($this->BelongsTo == "TerminalTemplate"){
-      $display= $this->show_header(_("Add printer extension"),
+      $display= $this->show_enable_header(_("Add printer extension"),
           _("This is a terminal template, printer tab is disabled."),TRUE,TRUE);
       return($display);
     }
@@ -253,6 +266,21 @@ class printgeneric extends plugin
     }
 
     $smarty= get_smarty();
+
+    /* Assign acls */
+    $tmp = $this->plInfo();
+    foreach($tmp['plProvidedAcls'] as $name => $translation){
+      $smarty->assign($name."ACL", $this->getacl($name));
+    }
+
+    /* Create base acls */
+    $baseACL = $this->getacl("base");
+    if(!$this->acl_is_moveable()) {
+      $baseACL = preg_replace("/w/","",$baseACL);
+    }
+    $smarty->assign("baseACL",          $baseACL);
+
+
     $display="";
 
     /* Tell smarty if this is a standalone object or a terminal / WS depending printer */
@@ -263,9 +291,12 @@ class printgeneric extends plugin
     }
 
     /* Do we need to flip is_account state? */
-    if (isset($_POST['modify_state'])){
-      $this->is_modified = true;
-      $this->is_account= !$this->is_account;
+    if(isset($_POST['modify_state'])){
+      if($this->is_account && $this->acl_is_removeable()){
+        $this->is_account= FALSE;
+      }elseif(!$this->is_account && $this->acl_is_createable()){
+        $this->is_account= TRUE;
+      }
     }
 
     /* Do we represent a valid printer? */
@@ -278,7 +309,7 @@ class printgeneric extends plugin
     /* If this is a WS / Terminal depending printer, display account state button */
     if($this->BelongsTo != "Printer"){
       if((empty($this->cn)) && ($this->dn != "new")){
-        $display= $this->show_header(_("Add printer extension"),
+        $display= $this->show_enable_header(_("Add printer extension"),
             _("This object has printer extension disabled. You can't enable it while 'cn' is not present in entry. Possibly you are currently creating a new terminal template"),TRUE,TRUE);
         $this->is_account= false;
         return $display;
@@ -286,18 +317,18 @@ class printgeneric extends plugin
 
       if (($this->is_account)){
         if($this->BelongsTo=="Workstation"){
-          $display= $this->show_header(_("Remove printer extension"),
+          $display= $this->show_disable_header(_("Remove printer extension"),
               _("This workstation has printer extension enabled.You can disable it by clicking below."));
         }elseif($this->BelongsTo=="Terminal"){
-          $display= $this->show_header(_("Remove printer extension"),
+          $display= $this->show_disable_header(_("Remove printer extension"),
               _("This terminal has printer extension enabled. You can disable it by clicking below."));
         }
       }else{
         if($this->BelongsTo=="Workstation"){
-          $display= $this->show_header(_("Add printer extension"),
+          $display= $this->show_disable_header(_("Add printer extension"),
               _("This workstation has printer extension disabled. You can enable it by clicking below."));
         }elseif($this->BelongsTo=="Terminal"){
-          $display= $this->show_header(_("Add printer extension"),
+          $display= $this->show_enable_header(_("Add printer extension"),
               _("This terminal has printer extension disabled. You can enable it by clicking below."));
         }  
         return ($display);
@@ -309,7 +340,7 @@ class printgeneric extends plugin
     foreach($_POST as $name => $value){
       if(preg_match("/^chooseBase/",$name) && $once){
         $once = false;
-        $this->dialog = new baseSelectDialog($this->config);
+        $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
         $this->dialog->setCurrentBase($this->base);
         $this->baseSelection = true;
       }
@@ -335,26 +366,25 @@ class printgeneric extends plugin
     }
 
     /* Fill templating stuff */
-    $smarty->assign("bases", $this->config->idepartments);
+    $smarty->assign("bases", $this->get_allowed_bases());
     $smarty->assign("base_select", $this->base);
 
     /* Assign attributes */
     foreach ($this->attributes as $attr){
-      $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
       $smarty->assign("$attr", $this->$attr);
     }
 
     if(isset($_POST['AddUser'])){
-      $this->dialog = new selectUserToPrinterDialog($this->config, get_userinfo(),"AddUser");
+      $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddUser");
     }
     if(isset($_POST['AddGroup'])){
-      $this->dialog = new selectUserToPrinterDialog($this->config, get_userinfo(),"AddGroup");
+      $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddGroup");
     }
     if(isset($_POST['AddAdminUser'])){
-      $this->dialog = new selectUserToPrinterDialog($this->config, get_userinfo(),"AddAdminUser");
+      $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminUser");
     }
     if(isset($_POST['AddAdminGroup'])){
-      $this->dialog = new selectUserToPrinterDialog($this->config, get_userinfo(),"AddAdminGroup");
+      $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminGroup");
     }
 
     /* Display ppd configure/select dialog      */
@@ -394,28 +424,28 @@ class printgeneric extends plugin
       }
     }
 
-    /* Member management, delete user / group / admin ..*/
+     /* Member management, delete user / group / admin ..*/
     if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
-      if(isset($this->member['AddUser'][$_POST['UserMember']])){
-        unset($this->member['AddUser'][$_POST['UserMember']]);
+      foreach($_POST['UserMember'] as $mem){
+        $this->DelMember('AddUser',$mem);
       }
     }
 
     if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
-      if(isset($this->member['AddGroup'][$_POST['UserMember']])){
-        unset($this->member['AddGroup'][$_POST['UserMember']]);
+      foreach($_POST['UserMember'] as $mem){
+        $this->DelMember('AddGroup',$mem);
       }
     }
 
     if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
-      if(isset($this->member['AddAdminUser'][$_POST['AdminMember']])){
-        unset($this->member['AddAdminUser'][$_POST['AdminMember']]);
+      foreach($_POST['AdminMember'] as $mem){
+        $this->DelMember('AddAdminUser',$mem);
       }
     }
 
     if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
-      if(isset($this->member['AddAdminGroup'][$_POST['AdminMember']])){
-        unset($this->member['AddAdminGroup'][$_POST['AdminMember']]);
+      foreach($_POST['AdminMember'] as $mem){
+        $this->DelMember('AddAdminGroup',$mem);
       }
     }
 
@@ -433,21 +463,13 @@ class printgeneric extends plugin
           print_red($msg);
         }
       }else{
-        $new = $this->dialog->save();
-        $data = $new;
+        $data= $new = $this->dialog->save();
         unset($data['type']);
-
-        if(preg_match("/User/",$new['type'])){
-          $use = "uid";
-        }else{
-          $use = "cn";
-        }
-
         foreach($data as $mem){
-          $this->member[$new['type']][$mem[$use][0]]=$mem;    
+          $this->AddMember($new['type'], $mem['dn']);
         }
         unset($this->dialog);
-        $this->dialog=NULL; 
+        $this->dialog=NULL;
       }
     }
 
@@ -470,7 +492,7 @@ class printgeneric extends plugin
       $ppdManager= new ppdManager($path);
       if(!empty($this->gotoPrinterPPD)){
         if((!file_exists($path.$this->gotoPrinterPPD))){
-          $smarty->assign("driverInfo", "<b>".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$this->gotoPrinterPPD))."</b>";
+          $smarty->assign("driverInfo", "<b>".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$path.$this->gotoPrinterPPD))."</b>";
         }else{
           $smarty->assign("driverInfo", $ppdManager->loadDescription($path.$this->gotoPrinterPPD));
         }
@@ -495,7 +517,7 @@ class printgeneric extends plugin
       }else{
         $smarty->assign("desc"    ,sprintf(_("This printer belongs to workstation %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
       }
-      $smarty->assign("cnACL"    ," disabled ");
+      $smarty->assign("cnACL"    , $this->getacl("cn",true));
     }else{
       $smarty->assign("desc"    ,"");
     }
@@ -506,7 +528,11 @@ class printgeneric extends plugin
     $smarty->assign("AdminMember"    ,$this->AdminMember);
     $smarty->assign("AdminMembers"   ,$adminlist);
     $smarty->assign("AdminMemberKeys",array_flip($adminlist));
-    $smarty->assign("netconfig", $this->netConfigDNS->execute());
+    if($this->BelongsTo == "Printer"){
+      $smarty->assign("netconfig", $this->netConfigDNS->execute());
+    } else {
+      $smarty->assign("netconfig", "");
+    }
 
     return($display.$smarty->fetch (get_template_path('printer.tpl', TRUE)));
   }
@@ -528,23 +554,23 @@ class printgeneric extends plugin
 
       /* Check if this dn points to a printer, to avoid deleting something else */
       $ldap= $this->config->get_ldap_link();
-      $ldap->cat($this->dn);
+      $ldap->cat($this->dn, array('dn',"objectClass"));
       if(!$ldap->count()){
-        print_red("Trying to remove printer obejct which isn't a printer. Aborted to avoid data loss.");
+        print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
         return;
       }
 
       /* Check if obejct is a printer */
       $CheckPrinter = $ldap->fetch();
       if(!in_array("gotoPrinter",$CheckPrinter['objectClass'])){
-        print_red("Trying to remove printer obejct which isn't a printer. Aborted to avoid data loss.");
+        print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
         return;
       }
 
       /* Remove account & dns extension */ 
       $this->netConfigDNS->remove_from_parent();
       $ldap->rmdir($this->dn);
-      show_ldap_error($ldap->get_error());
+      show_ldap_error($ldap->get_error(), sprintf(_("Removing of system print/generic with dn '%s' failed."),$this->dn));
       $this->handle_post_events("remove");
 
       /* Delete references to object groups */
@@ -563,10 +589,27 @@ class printgeneric extends plugin
   function save_object()
   {
     plugin::save_object();
-    $this->netConfigDNS->save_object();
+    
+    if(is_object($this->netConfigDNS)){
+      $this->netConfigDNS->save_object();
+    }
+
     /* Save base, since this is no LDAP attribute */
-    if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
-      $this->base= $_POST['base'];
+    if((isset($_POST['base'])) && ($this->acl_is_moveable()) ) {
+      $this->set_acl_base('dummy,'.$_POST['base']);
+      if($this->acl_is_moveable()){
+
+        if(isset($this->config->idepartments[$_POST['base']])){
+          $this->base = $_POST['base'];
+          if ($_POST['base'] != $this->base){
+            $this->is_modified= TRUE;
+          }
+        }
+      }else{
+
+        print_red(sprintf(_("You are not allowed to move this object to '%s'."),LDAP::fix($_POST['base'])));
+        $this->set_acl_base('dummy,'.$this->base);
+      }
     }
   }
 
@@ -575,7 +618,9 @@ class printgeneric extends plugin
   {
     /* Call common method to give check the hook */
     $message= plugin::check();
-    $message= array_merge($message, $this->netConfigDNS->check());
+    if ($this->BelongsTo == 'printer'){
+      $message= array_merge($message, $this->netConfigDNS->check());
+    }
 
     /* Don't display check messages if this is a template object */
     if(isset($this->parent->by_object['workgeneric'])){
@@ -594,6 +639,17 @@ class printgeneric extends plugin
     if(($this->BelongsTo == "Printer") && (empty($this->cn))){
       $message[]= "The required field 'Printer name' is not set.";
     }
+
+    if($this->BelongsTo == "Printer"){
+      if ($this->orig_dn == "new" && !$this->acl_is_createable()){
+        $message[]= _("You have no permissions to create a group on this 'Base'.");
+      }
+    }
+    
+    /* must: labeledURI */
+    if(empty($this->labeledURI)){
+      $message[]= "The required field 'Printer URL' is not set.";
+    }
     
     /* Check if there is already an entry with this cn*/
     if (($this->orig_dn != $dn)&&($this->BelongsTo == "Printer")){
@@ -672,63 +728,87 @@ class printgeneric extends plugin
     }else{
       $method="http://";
     }
-  
-    $this->attrs['gotoPrinterPPD'] = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
+
+    /* If no ppd is selected, remove this attribute */
+    if(!empty($this->gotoPrinterPPD)) {
+      $this->attrs['gotoPrinterPPD'] = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
+    }else{
+      $this->attrs['gotoPrinterPPD'] = array();
+    }
 
     /* Append printer user 
      */
-    if((isset($this->attrs['gotoUserPrinter'])) && (is_string($this->attrs['gotoUserPrinter']))){
-      $this->attrs['gotoUserPrinter']=array();
-    }
+    $this->attrs['gotoUserPrinter']=array();
     foreach($this->member['AddUser'] as $mem){
       $this->attrs['gotoUserPrinter'][]=$mem['uid'][0];
     }
 
     /* Append printer group 
      */
+    $this->attrs['gotoGroupPrinter'] = array();
     foreach($this->member['AddGroup'] as $mem){
       $this->attrs['gotoGroupPrinter'][]=$mem['cn'][0];
     }
 
     /* Append printer admin user 
      */
+    $this->attrs['gotoUserAdminPrinter'] = array();
     foreach($this->member['AddAdminUser'] as $mem){
       $this->attrs['gotoUserAdminPrinter'][]=$mem['uid'][0];
     }
 
     /* Append printer admin group 
      */
+    $this->attrs['gotoGroupAdminPrinter']= array();
     foreach($this->member['AddAdminGroup'] as $mem){
       $this->attrs['gotoGroupAdminPrinter'][]=$mem['cn'][0];
     }
 
+    if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
+      $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
+    }
+
+    if($this->orig_dn == 'new'){
+      foreach(array("gotoGroupPrinter","gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter") as $checkVar){
+        if(count($this->attrs[$checkVar])  == 0 || empty($this->attrs[$checkVar])){
+          unset($this->attrs[$checkVar]);
+        }
+      }
+    }
+
+    /* Move object in necessary*/
+    if (($this->orig_dn != $this->dn) && ($this->orig_dn != 'new')){
+      $this->move($this->orig_dn, $this->dn);
+    }
+
     /* Write back to ldap */
     $ldap= $this->config->get_ldap_link();
-    if ($this->orig_dn == 'new'){
+    $ldap->cat($this->dn);
+    if(!$ldap->count()){
       $ldap->cd($this->config->current['BASE']);
       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
       $ldap->cd($this->dn);
       $ldap->add($this->attrs);
       $this->handle_post_events("add");
     } else {
-      if ($this->orig_dn != $this->dn){
-        $this->move($this->orig_dn, $this->dn);
-      }
-
       $ldap->cd($this->dn);
       $this->cleanup();
       $ldap->modify ($this->attrs); 
-
       $this->handle_post_events("modify");
     }
-    show_ldap_error($ldap->get_error());
+    show_ldap_error($ldap->get_error(), sprintf(_("Saving of system print/generic with dn '%s' failed."),$this->dn));
 
-    $this->netConfigDNS->cn = $this->cn;
-    $this->netConfigDNS->dn = $this->dn;
-    $this->netConfigDNS->save($this->dn);
+    if($this->BelongsTo == "Printer"){
+      $this->netConfigDNS->cn = $this->cn;
+      $this->netConfigDNS->dn = $this->dn;
+      $this->netConfigDNS->save($this->dn);
+    }
 
     /* Optionally execute a command after we're done */
     $this->postcreate();
+
+    /* This is a multi object. Handle tagging here... */
+    $this->handle_object_tagging();
   }
 
   function generateList(){
@@ -749,6 +829,116 @@ class printgeneric extends plugin
     }
     return($a_return);
   }
+
+  /* Return plugin informations for acl handling
+      #FIXME FAIscript seams to ununsed within this class... */
+  function plInfo()
+  {
+    return (array(
+          "plShortName"   => _("Generic"),
+          "plDescription" => _("Print generic"),
+          "plSelfModify"  => FALSE,
+          "plDepends"     => array(),
+          "plPriority"    => 0,
+          "plSection"     => array("administration"),
+          "plCategory"    => array("printer" => array("description"  => _("Printer"),
+                                                    "objectClass"  => "gotoPrinter"),"workstation"),
+          "plProvidedAcls"=> array(
+            "cn"                => _("Name"),
+            "base"                => _("Base") ,         
+            "description"       => _("Description"), 
+            "l"                 => _("Location"), 
+            "labeledURI"        => _("LabeledURL"), 
+            "gotoPrinterPPD"    => _("Printer PPD"),
+            "gotoUserPrinter"   => _("Permissions")) 
+          ));
+  }
+
+
+  /* Delete member */
+  function DelMember($type,$id)
+  {
+    /* Check if there was a printer "dn" given, or the "cn" */
+    foreach($this->member[$type] as $key => $printer){
+      if($printer['dn'] == $id) {
+        $id = $key;
+      }
+    }
+  
+    if(!$this->acl_is_writeable("gotoUserPrinter")){
+      print_red(sprintf(_("You are not allowed to remove the given object '%s' from the list of members of printer '%s'."),$id,$this->dn));
+      return(FALSE);
+    }
+    if(isset($this->member[$type][$id])){
+      unset($this->member[$type][$id]);
+      return(TRUE);
+    }
+    return(FALSE);
+  }
+
+
+  /* Add given obejct to members */
+  function AddMember($type,$dn)
+  {
+    $types = array("AddUser","AddGroup","AddAdminUser","AddAdminGroup");
+    if(!in_array_ics($type, $types)){
+      print_red(sprintf(_("Illegal printer type while adding '%s' to the list of '%s' printers,"),$dn,$type));
+      return(FALSE);
+    }
+
+    if(!$this->acl_is_writeable("gotoUserPrinter")){
+      print_red(sprintf(_("You are not allowed to add the given object '%s' to the list of members of '%s'."),$dn,$this->dn));
+      return(FALSE);
+    }
+
+    /* Get name of index attributes */
+    if(preg_match("/user/i",$type)){
+      $var = "uid";
+    }else{
+      $var = "cn";
+    }
+
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($dn);
+    $ldap->cat($dn,array($var));
+    if($ldap->count()){
+
+      $attrs = $ldap->fetch();
+
+      if(isset($attrs[$var][0])){
+        $name = $attrs[$var][0];
+
+        /* Check if this uid/cn is already assigned to any permission */
+        foreach($types as $ctype){
+
+          /* If we want to add a user, only check user/userAdmin members */
+          if((preg_match("/user/i",$type)) && (!preg_match("/user/i",$ctype))){
+            continue;
+          }
+
+          /* If we want to add a group, only check groups/adminGroups .. */
+          if((preg_match("/group/i",$type)) && (!preg_match("/group/i",$ctype))){
+            continue;
+          }
+
+          if(isset(  $this->member[$ctype][$name])){
+            print_red(sprintf(_("Can't add '%s' to the list of members, it is already used."),$attrs[$var][0]));
+            return(FALSE);
+          }
+        }
+
+        /* Everything is fine. So add the given object to members */
+        $this->member[$type][$attrs[$var][0]] = $attrs ;
+      }else{
+        print_a($attrs);
+      }
+    }else{
+      print_red(sprintf(_("Can't add '%s' to list of members, it is not reachable."),$dn));
+      return(FALSE);
+    }
+    return(TRUE);
+  }
 }