Code

Important update for posixAccount.
[gosa.git] / plugins / personal / posix / class_posixAccount.inc
index e3e9f2ab8ed457da4453466a61f77dc91347f513..2a59d5b86323e1051632f534a586f1367022dd07 100644 (file)
@@ -16,11 +16,6 @@ class posixAccount extends plugin
   var $plHeadline= "UNIX";
   var $plDescription= "This does something";
 
-  /* CLI vars */
-  var $cli_summary= "Manage users posix account";
-  var $cli_description= "Some longer text\nfor help";
-  var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-
   /* Plugin specific values */
   var $homeDirectory= "";
   var $loginShell= "/bin/bash";
@@ -34,7 +29,6 @@ class posixAccount extends plugin
   var $shadowInactive= "0";
   var $shadowExpire= "0";
   var $gosaDefaultPrinter= "";
-  var $gosaDefaultLanguage= "";
   var $accessTo= array();
   var $trustModel= "";
 
@@ -64,12 +58,13 @@ class posixAccount extends plugin
   var $GroupRegex       = "*";
   var $GroupUserRegex   = "*";
   var $SubSearch        = false;
+  var $memberGroup      = array();
 
   /* attribute list for save action */
   var $CopyPasteVars  = array("grouplist","groupMembership","use_shadowMin","use_shadowMax","use_shadowWarning","use_shadowInactive","use_shadowExpire","must_change_password","grouplist","savedGidNumber","savedUidNumber");
   var $attributes     = array("homeDirectory", "loginShell", "uidNumber", "gidNumber", "gecos",
       "shadowMin", "shadowMax", "shadowWarning", "shadowInactive", "shadowLastChange",
-      "shadowExpire", "gosaDefaultPrinter", "gosaDefaultLanguage", "uid","accessTo","trustModel");
+      "shadowExpire", "gosaDefaultPrinter", "uid","accessTo","trustModel");
   var $objectclasses= array("posixAccount", "shadowAccount");
 
   var $uid ="";
@@ -233,9 +228,17 @@ class posixAccount extends plugin
   }
 
   if(!$isCopyPaste){
+
+    $required = (isset($this->parent->by_object['sambaAccount']) && $this->parent->by_object['sambaAccount']->is_account) || 
+                (isset($this->parent->by_object['environment'] ) && $this->parent->by_object['environment'] ->is_account);
+
     /* Do we need to flip is_account state? */
     if (isset($_POST['modify_state'])){
-      $this->is_account= !$this->is_account;
+      if($this->is_account && $this->acl == "#all#" && !$required ){
+        $this->is_account= !$this->is_account;
+      }elseif(!$this->is_account && chkacl($this->acl,"create") == ""){
+        $this->is_account= !$this->is_account;
+      }
     }
 
     /* Do we represent a valid posixAccount? */
@@ -494,7 +497,6 @@ class posixAccount extends plugin
     } else {
       $smarty->assign("groups", "");
     }
-    $smarty->assign("languages", $this->config->data['MAIN']['LANGUAGES']);
 
        /* Avoid "Undefined index: forceMode" */
     $smarty->assign("forceMode", "");
@@ -643,6 +645,9 @@ class posixAccount extends plugin
           $this->is_modified= TRUE;
         }
         $this->primaryGroup= $_POST['primaryGroup'];
+        if ($this->primaryGroup != 0){
+          $this->gidNumber= $this->primaryGroup;
+        }
       }
 
       /* Save pwmode dependent attributes, curently hardcoded because there're
@@ -755,11 +760,11 @@ class posixAccount extends plugin
         }
 
         add_lock ("uidnumber", "gosa");
-        $this->uidNumber= $this->get_next_id("uidNumber");
+        $this->uidNumber= $this->get_next_id("uidNumber", $this->dn);
         if ($this->savedGidNumber != ""){
           $this->gidNumber= $this->savedGidNumber;
         } else {
-          $this->gidNumber= $this->get_next_id("gidNumber");
+          $this->gidNumber= $this->get_next_id("gidNumber", $this->dn);
         }
       }
 
@@ -896,8 +901,18 @@ class posixAccount extends plugin
     /* Include global link_info */
     $ldap= $this->config->get_ldap_link();
 
+    /* Append groups as memberGroup: to check hook 
+     */
+    $tmp_attributes  = $this->attributes;    
+    $this->attributes[] = "memberGroup";
+    $this->memberGroup = array();
+    foreach($this->groupMembership as $dn => $name){
+      $this->memberGroup[] = $name;
+    }
+
     /* Call common method to give check the hook */
     $message= plugin::check();
+    $this->attributes = $tmp_attributes;
 
     /* must: homeDirectory */
     if ($this->homeDirectory == ""){
@@ -1074,7 +1089,7 @@ class posixAccount extends plugin
     }
   }
 
-  function get_next_id($attrib)
+  function get_next_id($attrib, $dn)
   {
     $ids= array();
     $ldap= $this->config->get_ldap_link();
@@ -1093,10 +1108,16 @@ class posixAccount extends plugin
     }
 
     /* Add the nobody id */
-    $ids[]=  65534;
+    $ids[]= 65534;
 
     /* Find out next free id near to UID_BASE */
-    for ($id= $this->config->current['UIDBASE']; $id++; $id < pow(2,32)){
+    if (!isset($this->config->current['BASE_HOOK'])){
+      $base= $this->config->current['UIDBASE'];
+    } else {
+      /* Call base hook */
+      $base= get_base_from_hook($dn, $attrib);
+    }
+    for ($id= $base; $id++; $id < pow(2,32)){
       if (!in_array($id, $ids)){
         return ($id);
       }
@@ -1111,10 +1132,8 @@ class posixAccount extends plugin
 
  function reload()
   {
-
     /* Set base for all searches */
     $base     = $_SESSION['CurrentMainBase'];
-    $base     = $base;
     $ldap     = $this->config->get_ldap_link();    
     $attrs    =  array("cn", "description", "gidNumber");
     $Flags    = GL_SIZELIMIT;
@@ -1264,8 +1283,8 @@ class posixAccount extends plugin
     plugin::PrepareForCopyPaste($source);
     
     /* Avoid using the same gid/uid number as source user */
-    $this->savedUidNumber = $this->get_next_id("gidNumber");
-    $this->savedGidNumber = $this->get_next_id("uidNumber");
+    $this->savedUidNumber = $this->get_next_id("uidNumber", $this->dn);
+    $this->savedGidNumber = $this->get_next_id("gidNumber", $this->dn);
   }
 
   function convertToSeconds($val)