Code

Updated in
[gosa.git] / gosa-core / plugins / admin / groups / class_group.inc
index a2519c1c3052eac498501657497decf8ad79955b..45658dd418130d36035769c57f35190bac97eceb 100644 (file)
@@ -127,7 +127,7 @@ class group extends plugin
     }
 
     /* Set mail flag */
-    if (isset($this->attrs['objectClass']) && in_array('gosaMailAccount', $this->attrs['objectClass'])){
+    if (isset($this->attrs['objectClass']) && in_array_strict('gosaMailAccount', $this->attrs['objectClass'])){
       $this->has_mailAccount= TRUE;
     }
 
@@ -291,17 +291,6 @@ class group extends plugin
       $this->dialog= FALSE;
     }
 
-    /* Base select dialog */
-    $once = true;
-    foreach($_POST as $name => $value){
-      if((preg_match("/^chooseBase/",$name) && $once) && $this->acl_is_writeable("base")){
-          
-        $once = false;
-        $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
-        $this->dialog->setCurrentBase($this->base);
-      }
-    }
-
     /* Dialog handling */
     if(is_object($this->dialog)){
       /* Must be called before save_object */
@@ -510,14 +499,14 @@ class group extends plugin
     $smarty->assign("memberUid_Some",$this->memberUid_used_by_some);
 
     foreach($this->attributes as $val){
-      if(in_array($val,$this->multi_boxes)){
+      if(in_array_strict($val,$this->multi_boxes)){
         $smarty->assign("use_".$val,TRUE);
       }else{
         $smarty->assign("use_".$val,FALSE);
       }
     }
     foreach(array("base","smbgroup","groupType","sambaDomainName","fon_group","nagios_group","trustmode") as $val){
-      if(in_array($val,$this->multi_boxes)){
+      if(in_array_strict($val,$this->multi_boxes)){
         $smarty->assign("use_".$val,TRUE);
       }else{
         $smarty->assign("use_".$val,FALSE);
@@ -661,7 +650,7 @@ class group extends plugin
 
     /* Fetch all users and skip already used users */
     foreach($res as $attrs){
-      if(in_array($attrs['uid'][0], $this->memberUid)) {
+      if(in_array_strict($attrs['uid'][0], $this->memberUid)) {
         continue;
       }
       $i ++;
@@ -748,17 +737,6 @@ class group extends plugin
   /* Save data to object */
   function save_object()
   {
-    /* Refresh base */
-    if ($this->acl_is_moveable($this->base)){
-      if (!$this->baseSelector->update()) {
-        msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
-      }
-      if ($this->base != $this->baseSelector->getBase()) {
-        $this->base= $this->baseSelector->getBase();
-        $this->is_modified= TRUE;
-      }
-    }
-
     /* Save additional values for possible next step */
     if (isset($_POST['groupedit'])){
 
@@ -769,6 +747,17 @@ class group extends plugin
       plugin::save_object();
       $this->base = $base_tmp;
 
+      /* Refresh base */
+      if ($this->acl_is_moveable($this->base)){
+        if (!$this->baseSelector->update()) {
+          msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
+        }
+        if ($this->base != $this->baseSelector->getBase()) {
+          $this->base= $this->baseSelector->getBase();
+          $this->is_modified= TRUE;
+        }
+      }
+
       $this->force_gid= 0;
 
       /* Only reset sambagroup flag if we are able to write this flag */
@@ -917,16 +906,7 @@ class group extends plugin
       if ($this->groupType == 0){
 
         if ($this->sambaSID == "" || $this->oldgroupType != $this->groupType){
-          $gidNumber= $this->gidNumber;
-          while(TRUE){
-            $sid= $this->SID."-".($gidNumber*2 + $this->ridBase+1);
-            $ldap->cd($this->config->current['BASE']);
-            $ldap->search("(sambaSID=$sid)",array("sambaSID"));
-            if ($ldap->count() == 0){
-              break;
-            }
-            $gidNumber++;
-          }
+          $sid = $this->getSambaSID();
           $this->attrs['sambaSID']= $sid;
           $this->sambaSID= $sid;
         }
@@ -1065,6 +1045,11 @@ class group extends plugin
       $message[]= msgPool::required(_("Name"));
     }
 
+    // Check if a wrong base was supplied
+    if(!$this->baseSelector->checkLastBaseUpdate()){
+      $message[]= msgPool::check_base();;
+    }
+
     /* Check for valid input */
     if (!tests::is_uid($this->cn)){
       if (strict_uid_mode()){
@@ -1074,6 +1059,11 @@ class group extends plugin
       }
     }
 
+    // Check if a wrong base was supplied
+    if(!$this->baseSelector->checkLastBaseUpdate()){
+      $message[]= msgPool::check_base();;
+    }
+
     if($this->allowGroupsWithSameNameInOtherSubtrees == true){
 
       /* Check for used 'cn' */
@@ -1286,12 +1276,12 @@ class group extends plugin
     $ret = plugin::get_multi_edit_values();
 
     foreach(array("base","smbgroup","groupType","sambaDomainName","fon_group","nagios_group") as $attr){    
-      if(in_array($attr,$this->multi_boxes)){
+      if(in_array_strict($attr,$this->multi_boxes)){
         $ret[$attr] = $this->$attr;
       }
     }
 
-    if(in_array("trustmode",$this->multi_boxes)){
+    if(in_array_strict("trustmode",$this->multi_boxes)){
       $ret['trustModel'] = $this->trustModel;
       $ret['accessTo'] = $this->accessTo;
     }
@@ -1324,7 +1314,7 @@ class group extends plugin
 
     if (isset($all['memberUid'])){
       for ($i= 0; $i<$all['memberUid']['count']; $i++){
-        if(!in_array($all['memberUid'][$i],$this->memberUid)){
+        if(!in_array_strict($all['memberUid'][$i],$this->memberUid)){
           $this->memberUid_used_by_some[$all['memberUid'][$i]]= $all['memberUid'][$i];
         }
       }
@@ -1337,6 +1327,53 @@ class group extends plugin
   {
     plugin::PrepareForCopyPaste($source);
 
+    /* Get samba Domain in case of samba 3 */
+    if ($this->sambaSID != ""){
+      $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
+      $ldap= $this->config->get_ldap_link();
+      $ldap->cd($this->config->current['BASE']);
+      $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase"));
+      if ($ldap->count() != 0){
+        $attrs= $ldap->fetch();
+        if(isset($attrs['sambaAlgorithmicRidBase'])){
+          $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
+        } else {
+          $this->ridBase= $this->config->get_cfg_value("sambaRidBase");
+        }
+
+        /* Get domain name for SID */
+        $this->sambaDomainName= "DEFAULT";
+        foreach ($this->config->data['SERVERS']['SAMBA'] as $key => $val){
+          if ($val['SID'] == $this->SID){
+            $this->sambaDomainName= $key;
+            break;
+          }
+        }
+      } else {
+        if ($this->config->get_cfg_value("sambaRidBase") != ""){
+          $this->sambaDomainName= "DEFAULT";
+          $this->ridBase= $this->config->get_cfg_value("sambaRidBase");
+          $this->SID= $this->config->get_cfg_value("sid");
+        } else {
+          msg_dialog::display(_("Configuration error"), _("Cannot find group SID in your configuration!"), ERROR_DIALOG);
+        }
+      }
+
+      /* Get group type */
+      $this->groupType= (int)substr(strrchr($this->sambaSID, "-"), 1);
+      if ($this->groupType < 500 || $this->groupType > 553){
+        $this->groupType= 0;
+      }
+      $this->oldgroupType= $this->groupType;
+    }
+
+
+    // Detect samba groups and adapt its values.
+    $this->smbgroup = in_array_strict('sambaGroupMapping', $source['objectClass']);
+    if ($this->smbgroup) { 
+      $this->sambaSID = $this->getSambaSID(); 
+    } 
+
     $this->memberUid = array();
     if(isset($source['memberUid'])){
       for($i = 0 ; $i < $source['memberUid']['count']; $i ++){
@@ -1359,7 +1396,7 @@ class group extends plugin
 
     /* Update groupMembership, keep optinal group */
     foreach($attrs['memberUid_used_by_some'] as $uid){
-      if(in_array($uid,$this->memberUid)){
+      if(in_array_strict($uid,$this->memberUid)){
         $users[$uid] = $uid;
       }
     }
@@ -1371,6 +1408,26 @@ class group extends plugin
     plugin::set_multi_edit_values($attrs);
     $this->memberUid = $users;
   }
+
+
+  /*! \brief Get a new SambaSID for a group */ 
+  function getSambaSID() 
+  { 
+    $ldap = $this->config->get_ldap_link(); 
+    $gidNumber= $this->gidNumber; 
+    while(TRUE){ 
+      $sid= $this->SID."-".($gidNumber*2 + $this->ridBase+1); 
+      $ldap->cd($this->config->current['BASE']); 
+      $ldap->search("(sambaSID=$sid)",array("sambaSID")); 
+      if ($ldap->count() == 0){ 
+        break; 
+      } 
+      $gidNumber++; 
+    } 
+  
+    return $sid; 
+  } 
+
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>