Code

Backports from trunk
[gosa.git] / gosa-plugins / samba / admin / systems / samba / class_winGeneric.inc
index 60a942f2a91e935c5fcc806704a16d9a96de7707..56943662cd4b9cdf341355be1f571b2c4280b606 100644 (file)
@@ -42,7 +42,7 @@ class wingeneric extends plugin
                             "shadowInactive","uid","cn","sn","givenName","homeDirectory","sambaSID",
                             "sambaPrimaryGroupSID","displayName", "sambaPwdMustChange",
                             "sambaNTPassword","sambaPwdLastSet","sambaAcctFlags");
-  var $objectclasses= array("posixAccount","person","organizationalPerson","inetOrgPerson","gosaAccount","shadowAccount","sambaSamAccount","top");
+  var $objectclasses= array("posixAccount","person","organizationalPerson","inetOrgPerson","shadowAccount","sambaSamAccount","top");
 
   var $view_logged = FALSE;
 
@@ -51,17 +51,25 @@ class wingeneric extends plugin
     plugin::plugin ($config, $dn, $parent);
     $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses,FALSE,"uid");
     $this->netConfigDNS->cn =  preg_replace("/\\\$\$/","",$this->uid);
-    $this->netConfigDNS->objectclasses=array("ipHost","ieee802Device");
     $this->netConfigDNS->MACisMust = FALSE;
     $this->netConfigDNS->IPisMust = FALSE;
 
+    // The combination of the used objectClasses may differ, remember the initial ones.
+    if(isset($this->attrs['objectClass'])){
+        $this->objectclasses = array();
+        for($i=0; $i < $this->attrs['objectClass']['count'] ;  $i++ ){
+            $this->objectclasses[] = $this->attrs['objectClass'][$i];
+        }
+    }
+
     /* Set base */
     if ($this->dn == "new"){
       $ui = get_userinfo();
       $this->base= dn2base(session::global_is_set("CurrentMainBase")?"cn=dummy,".session::global_get("CurrentMainBase"):$ui->dn);
       $this->cn= "";
-    } elseif(preg_match("/".preg_quote(get_ou("systemIncomingRDN"), '/')."/i", $this->dn)){
-      $this->base= preg_replace ("/^[^,]+,".preg_quote(get_ou("systemIncomingRDN"), '/')."/i", "", $this->dn);
+    } elseif(class_available("ArpNewDevice") &&
+                preg_match("/".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i", $this->dn)){
+      $this->base= preg_replace ("/^[^,]+,".preg_quote(get_ou("ArpNewDevice", "systemIncomingRDN"), '/')."/i", "", $this->dn);
     } else {
       $this->base= preg_replace ("/^[^,]+,".preg_quote(get_winstations_ou(), '/')."/i", "", $this->dn);
     }
@@ -115,7 +123,7 @@ class wingeneric extends plugin
 
     /* Fill templating stuff */
     $smarty= get_smarty();
-    $smarty->assign("usePrototype", "true");
+
     
     $tmp = $this->plInfo();
     foreach($tmp['plProvidedAcls'] as $name => $translated){
@@ -124,7 +132,7 @@ class wingeneric extends plugin
 
     /* Assign attributes */
     foreach ($this->attributes as $attr){
-      $smarty->assign("$attr", $this->$attr);
+      $smarty->assign("$attr", set_post($this->$attr));
     }
     
     $smarty->assign("base", $this->baseSelector->render());
@@ -192,7 +200,7 @@ class wingeneric extends plugin
     /* Call common method to give check the hook */
     $message= plugin::check();
     $message= array_merge($message, $this->netConfigDNS->check());
-    $this->dn= "cn=".$this->uid.",".get_ou('sambaMachineAccountRDN').$this->base;
+    $this->dn= "cn=".$this->uid.",".get_ou("wingeneric", "sambaMachineAccountRDN").$this->base;
 
     if(!$this->acl_is_createable()){
       $message[]= msgPool::permCreate();
@@ -253,6 +261,26 @@ class wingeneric extends plugin
       $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
     }
 
+    $curOcs = $this->attrs['objectClass'];
+    $this->cleanup();
+
+    // Prepare list of object classes
+    $ocs = array();
+    if(!empty($this->netConfigDNS->macAddress)){
+        $ocs [] = 'ieee802Device';
+    }else{
+        $curOcs = array_remove_entries(array('ieee802Device'), $curOcs);
+        $this->attrs['macAddress'] = array();
+    } 
+    if(!empty($this->netConfigDNS->ipHostNumber)){
+        $ocs [] = 'ipHost';
+    }else{
+        $curOcs = array_remove_entries(array('ipHost'), $curOcs);
+        $this->attrs['ipHostNumber'] = array();
+    } 
+
+    $this->attrs['objectClass']=$curOcs;
+
     /* Write back to ldap */
     $ldap= $this->config->get_ldap_link();
     if ($this->orig_dn == 'new'){
@@ -268,32 +296,71 @@ class wingeneric extends plugin
       }
 
       $ldap->cd($this->dn);
-      $this->cleanup();
       $ldap->modify ($this->attrs); 
       new log("modify","winworkstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
       $this->handle_post_events("modify");
     }
 
-    $this->netConfigDNS->cn =  preg_replace("/\\\$\$/","",$this->uid);
-    $this->netConfigDNS->save();
     if (!$ldap->success()){
       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
     }
+
+    // Prepare list of object classes
+    $ocs = array();
+    if(!empty($this->netConfigDNS->macAddress)){
+        $ocs [] = 'ieee802Device';
+    } 
+    if(!empty($this->netConfigDNS->ipHostNumber)){
+        $ocs [] = 'ipHost';
+    } 
+
+    $this->netConfigDNS->objectclasses=$ocs;
+    $this->netConfigDNS->cn =  preg_replace("/\\\$\$/","",$this->uid);
+    $this->netConfigDNS->save();
   }
 
   /* Return plugin informations for acl handling
   #FIXME FAIscript seams to ununsed within this class... */
   static function plInfo()
   {
-    return (array(
-          "plShortName"   => _("Win generic"),
-          "plDescription" => _("Windows workstation generic"),
-          "plSelfModify"  => FALSE,
-          "plDepends"     => array(),
-          "plPriority"    => 0,
-          "plSection"     => array("administration"),
-          "plCategory"    => array("winworkstation" => array("description"  => _("Win workstation"),
-                                                          "objectClass"  => "gotoWorkstation")),
+      return (array(
+                  "plShortName"   => _("Win generic"),
+                  "plDescription" => _("Windows workstation generic"),
+                  "plSelfModify"  => FALSE,
+                  "plDepends"     => array(),
+                  "plPriority"    => 0,
+                  "plSection"     => array("administration"),
+                  "plCategory"    => array("winworkstation" => array("description"  => _("Win workstation"),
+                          "objectClass"  => "gotoWorkstation")),
+
+                  "plRequirements"=> array(
+                      'ldapSchema' => array(
+                          'posixAccount' => '',
+                          'organizationalPerson' => '',
+                          'person' => '',
+                          'inetOrgPerson' => '',
+                          'gosaAccount' => '>=2.7',
+                          'shadowAccount' => '',
+                          'sambaSamAccount' => ''
+                          ),
+                      'onFailureDisablePlugin' => array(get_class())
+                      ),
+
+
+                  "plProperties" =>
+                  array(
+                      array(
+                          "name"          => "sambaMachineAccountRDN",
+                          "type"          => "rdn",
+                          "default"       => "ou=winstations,ou=systems,",
+                          "description"   => _("RDN for samba machine account storage."),
+                          "check"         => "gosaProperty::isRdn",
+                          "migrate"       => "migrate_sambaMachineAccountRDN",
+                          "group"         => "plugin",
+                          "mandatory"     => FALSE
+                          )
+                      ),
+
           "plProvidedAcls"=> array(
             "cn"                  => _("Name"),
             "base"                => _("Base"),