Code

Fixed ogroup saving
[gosa.git] / plugins / personal / samba / class_sambaAccount.inc
index a8f579f58a9d699024b017e81b74a703ea93fada..8a7f5ab8808efb015f70cd881be772f1c3e003dc 100644 (file)
@@ -58,7 +58,7 @@ class sambaAccount extends plugin
   var $sambaLogonTime= "0";
   var $sambaLogoffTime= "2147483647";
   var $sambaKickoffTime= "2147483647";
-  var $sambaPwdCanChange= "0";
+  var $sambaPwdCanChange= "";
   var $sambaPwdMustChange= "0";
   var $sambaAcctFlags= "[UX        ]";
   var $sambaHomePath= "";
@@ -87,7 +87,11 @@ class sambaAccount extends plugin
   var $attributes= array();
   var $objectclasses= array();
 
-  function sambaAccount ($config, $dn= NULL)
+  var $uid = "";
+
+  var $CopyPasteVars = array("kickoff_time_set","logoff_time_set","logon_time_set","mungedObject","orig_sambaDomainName");
+
+  function sambaAccount ($config, $dn= NULL, $parent= NULL)
   {
     /* Load attributes depending on the samba version */
     $this->samba3= ($config->current['SAMBAVERSION'] == 3);
@@ -111,14 +115,19 @@ class sambaAccount extends plugin
       $this->objectclasses= array ("sambaAccount");
     }
 
-    plugin::plugin ($config, $dn);
+    plugin::plugin ($config, $dn, $parent);
+
+    /* set user id */    
+    if(isset($this->attrs['uid'])){
+      $this->uid = $this->attrs['uid'][0];
+    }
 
     /* Get samba Domain in case of samba 3 */
     if ($this->samba3 && $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))");
+      $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase","sambaDomainName"));
       if ($ldap->count() != 0){
         $attrs= $ldap->fetch();
         $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
@@ -183,6 +192,9 @@ class sambaAccount extends plugin
 
   function execute()
   {
+       /* Call parent execute */
+       plugin::execute();
+
     /* Do we need to flip is_account state? */
     if (isset($_POST['modify_state'])){
       $this->is_account= !$this->is_account;
@@ -317,7 +329,7 @@ class sambaAccount extends plugin
       $acl= array($this->config->current['BASE'] => ":all");
       $regex= $sambafilter['regex'];
       $filter= "(&(objectClass=sambaSAMAccount)$exclude(uid=*$)(|(uid=$regex)(cn=$regex)))";
-      $res= get_list($acl, "$filter", TRUE, $sambafilter['depselect'], array("uid"), TRUE);
+      $res= get_list($filter, $acl, $sambafilter['depselect'], array("uid"), GL_SUBSEARCH | GL_SIZELIMIT);
       $wslist= array();
       foreach ($res as $attrs){
         $wslist[]= preg_replace('/\$/', '', $attrs['uid'][0]);
@@ -406,7 +418,8 @@ class sambaAccount extends plugin
     $sambaKickoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
         _("May"), _("June"), _("July"), _("August"), _("September"),
         _("October"), _("November"), _("December"));
-    $smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]-1);
+    //$smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]-1);
+    $smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]); // hickert
     $smarty->assign("sambaKickoffTime_days", $sambaKickoffTime_days);
     $smarty->assign("sambaKickoffTime_months", $sambaKickoffTime_months);
     $smarty->assign("sambaKickoffTime_month", $sambaKickoffTime_date["mon"]-1);
@@ -471,6 +484,15 @@ class sambaAccount extends plugin
       $smarty->assign("reconnmode", $this->mungedObject->getReConn());
       $smarty->assign("reconnACL", chkacl($this->acl,"reconn"));
 
+      if($_SESSION['js']){
+        /* Set form elements to disabled/enable state */
+        $smarty->assign("tsloginstate", $this->mungedObject->getTsLogin()?"":"disabled");
+        $smarty->assign("inheritstate", $this->mungedObject->getInheritMode()?"disabled":"");
+      }else{
+        $smarty->assign("tsloginstate", "");
+        $smarty->assign("inheritstate", "");
+      }      
+
       /* Set checkboxes to checked or unchecked state */
       $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
       $smarty->assign("tsloginACL", chkacl($this->acl,"tslogin"));
@@ -498,8 +520,13 @@ class sambaAccount extends plugin
       /* Fill sambaUserWorkstations */
       $ws= split(",", $this->sambaUserWorkstations);
       sort($ws);
+      
+      /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
+      if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
+
+
       $smarty->assign("workstations", $ws);
-      $smarty->assign("sambaUserWorkstationACL", chkacl($this->acl,"sambauserworkstation"));
+      $smarty->assign("sambaUserWorkstationACL", chkacl($this->acl,"sambaUserWorkstation"));
     }
 
     /* Variables */
@@ -552,21 +579,21 @@ class sambaAccount extends plugin
       $smarty->assign("flagsK", "");
     }
     
-    $smarty->assign("allow_pwchangeACL", chkacl($this->acl, "allow_pwchange"));
-    $smarty->assign("password_expiresACL", chkacl($this->acl, "password_expires"));
-    $smarty->assign("no_password_requiredACL", chkacl($this->acl, "no_password_required"));
-    $smarty->assign("temporary_disableACL", chkacl($this->acl, "temporary_disable"));
-    $smarty->assign("sambaDomainNameACL", chkacl($this->acl, "sambaDomainName"));
-    $smarty->assign("logon_time_setACL", chkacl($this->acl, "logon_time_set"));
-    $smarty->assign("logoff_time_setACL", chkacl($this->acl, "logoff_time_set"));
-    $smarty->assign("kickoff_time_setACL", chkacl($this->acl, "kickoff_time_set"));
-    $smarty->assign("sambaLogonTimeACL", chkacl($this->acl, "sambaLogonTime"));
-    $smarty->assign("sambaLogoffTimeACL", chkacl($this->acl, "sambaLogoffTime"));
-    $smarty->assign("sambaKickoffTimeACL", chkacl($this->acl, "sambaKickoffTime"));
+    $smarty->assign("allow_pwchangeACL",        chkacl($this->acl, "allow_pwchange"));
+    $smarty->assign("password_expiresACL",      chkacl($this->acl, "password_expires"));
+    $smarty->assign("no_password_requiredACL",  chkacl($this->acl, "no_password_required"));
+    $smarty->assign("temporary_disableACL",     chkacl($this->acl, "temporary_disable"));
+    $smarty->assign("sambaDomainNameACL",       chkacl($this->acl, "sambaDomainName"));
+    $smarty->assign("logon_time_setACL",        chkacl($this->acl, "logon_time_set"));
+    $smarty->assign("logoff_time_setACL",       chkacl($this->acl, "logoff_time_set"));
+    $smarty->assign("kickoff_time_setACL",      chkacl($this->acl, "kickoff_time_set"));
+    $smarty->assign("sambaLogonTimeACL",        chkacl($this->acl, "sambaLogonTime"));
+    $smarty->assign("sambaLogoffTimeACL",       chkacl($this->acl, "sambaLogoffTime"));
+    $smarty->assign("sambaKickoffTimeACL",      chkacl($this->acl, "sambaKickoffTime"));
 
 
     /* In case of javascript, disable some fields on demand */
-    if ($this->samba3 && $_SESSION['js']){
+    if ($this->samba3){
       foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
         $smarty->assign("$key", "$value");
       }
@@ -601,18 +628,21 @@ class sambaAccount extends plugin
     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
         $this->attributes, "Save");
     $ldap->cd($this->dn);
-    $ldap->modify($this->attrs);
-    show_ldap_error($ldap->get_error());
+    $this->cleanup();
+    $ldap->modify ($this->attrs); 
+
+    show_ldap_error($ldap->get_error(), _("Removing Samba account failed"));
 
     /* Optionally execute a command after we're done */
-    $this->handle_post_events("remove");
+    $this->handle_post_events("remove",array("uid"=>$this->uid));
   }
 
 
   /* Check for input problems */
   function check()
   {
-    $message= array();
+    /* Call common method to give check the hook */
+    $message= plugin::check();
 
     if ($this->samba3){
 
@@ -756,10 +786,15 @@ class sambaAccount extends plugin
         /* Save checkbox states. */
         $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
                         && chkacl($this->acl, "tslogin") == "");
-        $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
-                        && chkacl($this->acl, "brokenconn") == "");
-        $this->mungedObject->setReConn($_POST['reconn'] == '1'
-                        && chkacl($this->acl, "reconn") == "");
+        // Need to do some index checking to avoid messages like "index ... not found"
+        if(isset($_POST['brokenconn'])) {
+          $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
+                          && chkacl($this->acl, "brokenconn") == "");
+        }
+        if(isset($_POST['reconn'])) {
+          $this->mungedObject->setReConn($_POST['reconn'] == '1'
+                          && chkacl($this->acl, "reconn") == "");
+        }
         $this->mungedObject->setInheritMode(isset($_POST['inherit'])
                         && chkacl($this->acl, "inherit") == "");
         $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
@@ -777,8 +812,10 @@ class sambaAccount extends plugin
                         && chkacl($this->acl, "defaultprinter") == "");
 
         /* Save combo boxes. Takes two values */
-        $this->mungedObject->setShadow((isset($_POST['shadow'])
-                        && chkacl($this->acl, "shadow") == ""), $_POST['shadow']);
+        if(isset($_POST['reconn'])) {
+          $this->mungedObject->setShadow((isset($_POST['shadow'])
+                          && chkacl($this->acl, "shadow") == ""), $_POST['shadow']);
+        }
 
         /* Check for changes */
         if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
@@ -794,7 +831,7 @@ class sambaAccount extends plugin
   {
     /* Load uid and gid of this 'dn' */
     $ldap= $this->config->get_ldap_link();
-    $ldap->cat($this->dn);
+    $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
     $tmp= $ldap->fetch();
     $this->uidNumber= $tmp['uidNumber'][0];
     $this->gidNumber= $tmp['gidNumber'][0];
@@ -835,8 +872,7 @@ class sambaAccount extends plugin
 
         /* Check for users primary group */
         $ldap->cd($this->config->current['BASE']);
-        $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))",
-                      array("cn"));
+        $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
         if ($ldap->count() != 1){
           print_red(_("Warning: Can't identify users primary group - no conversion to a samba group possible!"));
         } else {
@@ -873,28 +909,29 @@ class sambaAccount extends plugin
       } else {
         $this->attrs['sambaPwdMustChange']= array();
       }
+      /* Make sure not to save zero in sambaPwdLastset */
+      if ($this->sambaPwdLastSet != "0"){
+        $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
+      } else {
+        $this->attrs['sambaPwdLastSet']= array();
+      }
       /* Account expiery */
       if ($this->logon_time_set == "1"){
         $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
       } else {
-        # $this->attrs['sambaLogonTime']= array();
-        # Set more useful default setting
-        $this->attrs['sambaLogonTime']= 0;
+        $this->attrs['sambaLogonTime']= array();
       }
       if ($this->logoff_time_set == "1"){
         $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
       } else {
-        # $this->attrs['sambaLogoffTime']= array();
-        # Set more useful default setting
-        $this->attrs['sambaLogoffTime']= 2147483647;
+        $this->attrs['sambaLogoffTime']= array();
       }
       if ($this->kickoff_time_set == "1"){
         # Add one day in unixtime format to be compatible with usrmgr
-        $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400;
+        //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400; 
+        $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert 
       } else {
-        # $this->attrs['sambaKickoffTime']= array();
-        # Set more useful default setting
-        $this->attrs['sambaKickoffTime']= 2147483647;
+        $this->attrs['sambaKickoffTime']= array();
       }
     } else {
     /* Not samba3 */
@@ -911,37 +948,45 @@ class sambaAccount extends plugin
       } else {
         $this->attrs['pwdMustChange']= 2147483647;
       }
+      /* Make sure not to save zero in pwdLastset */
+      if ($this->pwdLastSet != "0"){
+        $this->attrs['pwdLastSet']= $this->pwdLastSet;
+      } else {
+        $this->attrs['pwdLastSet']= array();
+      }
       /* Account expiery */
       if ($this->logon_time_set == "1"){
         $this->attrs['logonTime']= $this->logonTime;
       } else {
-        $this->attrs['logonTime']= 0;
+        $this->attrs['logonTime']= array();
       }
       if ($this->logoff_time_set == "1"){
         $this->attrs['logoffTime']= $this->logoffTime;
       } else {
-        $this->attrs['logoffTime']= 2147483647;
+        $this->attrs['logoffTime']= array();
       }
       if ($this->kickoff_time_set == "1"){
         # Add one day in unixtime format to be compatible with usrmgr
         $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
       } else {
-        $this->attrs['kickoffTime']= 2147483647;
+        $this->attrs['kickoffTime']= array();
       }
     }
 
     /* Write back to ldap */
     $ldap->cd($this->dn);
-    $ldap->modify($this->attrs);
-    show_ldap_error($ldap->get_error());
+    $this->cleanup();
+    $ldap->modify ($this->attrs); 
+
+    show_ldap_error($ldap->get_error(), _("Saving Samba account failed"));
 
     /* Optionally execute a command after we're done */
     if ($this->initially_was_account == $this->is_account){
       if ($this->is_modified){
-        $this->handle_post_events("modify");
+        $this->handle_post_events("modify",array("uid" => $this->uid));
       }
     } else {
-      $this->handle_post_events("add");
+      $this->handle_post_events("add",array("uid" => $this>uid));
     }
 
   }
@@ -951,6 +996,48 @@ class sambaAccount extends plugin
     plugin::adapt_from_template($dn);
     $this->sambaSID= "";
     $this->sambaPrimaryGroupSID= "";
+
+      /* Fill mungedDial field */
+    if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
+      $this->mungedObject->load($this->sambaMungedDial);
+    }
+
+    /* Password expiery */
+    if(isset($this->attrs['sambaPwdMustChange']) &&
+        $this->attrs['sambaPwdMustChange'][0] != 0){
+      $this->password_expires= 1;
+    }
+
+    if(isset($this->attrs['sambaLogonTime']) && ! (
+        $this->attrs['sambaLogonTime'][0] == 0 ||
+        $this->attrs['sambaLogonTime'][0] == 2147483647
+      )){
+      $this->logon_time_set= 1;
+    }
+    if(isset($this->attrs['sambaLogoffTime']) && ! (
+        $this->attrs['sambaLogoffTime'][0] == 0 ||
+        $this->attrs['sambaLogoffTime'][0] == 2147483647
+      )){
+      $this->logoff_time_set= 1;
+    }
+
+    /* Account expiery */
+    if(isset($this->attrs['sambaKickoffTime']) && ! (
+        $this->attrs['sambaKickoffTime'][0] == 0 ||
+        $this->attrs['sambaKickoffTime'][0] == 2147483647
+      )){
+      $this->kickoff_time_set= 1;
+    }
+
+    /* Get global filter config */
+    if (!is_global("sambafilter")){
+      $ui= get_userinfo();
+      $base= get_base_from_people($ui->dn);
+      $sambafilter= array( "depselect" => $base, "regex" => "*");
+      register_global("sambafilter", $sambafilter);
+    }
+
+
   }
 
 }