Code

Fixed acls
[gosa.git] / plugins / admin / groups / class_groupGeneric.inc
1 <?php
3 class group extends plugin
4 {
5   /* CLI vars */
6   var $cli_summary= "Handling of GOsa's base group object";
7   var $cli_description= "Some longer text\nfor help";
8   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10   /* Group attributes */
11   var $cn= "";
12   var $description= "";
13   var $gidNumber= "";
14   var $memberUid= array();
16   /* Helpers */
17   var $base= "";
18   var $force_gid= FALSE;
19   var $fon_group= FALSE;
20   var $smbgroup= FALSE;
21   var $groupType= FALSE;
22   var $samba3= FALSE;
23   var $sambaSID= "";
24   var $sambaDomainName= "DEFAULT";
25   var $SID= "";
26   var $ridBase= 0;
27   var $members= array();
28   var $users= array();
29   var $allusers= array();
30   var $saved_gidNumber= "";
31   var $oldgroupType= "";
32   var $orig_dn= "";
33   var $orig_cn= "";
34   var $has_mailAccount= FALSE;
35   var $group_dialog= FALSE;
36   var $nagios_group =FALSE;
37   var $sambaGroupType;
38   var $dialog;
39   var $OnlyShowFirstEntries =200;
41   var $allowGroupsWithSameNameInOtherSubtrees = true;
43   /* attribute list for save action */
44   var $attributes= array("cn", "description", "gidNumber","memberUid","sambaGroupType","sambaSID");
45   var $objectclasses= array("top", "posixGroup");
47   function group ($config, $dn= NULL)
48   {
49     plugin::plugin ($config, $dn);
51     /* Load attributes depending on the samba version */
52     $this->samba3= ($config->current['SAMBAVERSION'] == 3);
53     $this->orig_dn= $dn;
54     $this->orig_cn= $this->cn;
56     /* Get member list */
57     if (isset($this->attrs['memberUid'][0])){
58       $tmp= array();
59       for ($i= 0; $i<$this->attrs['memberUid']['count']; $i++){
60         $tmp[]= $this->attrs['memberUid'][$i];
61       }
62       $this->memberUid= $tmp;
63       sort ($this->memberUid);
64     }
66     /* Save gidNumber for later use */
67     if (isset($this->attrs['gidNumber'])){
68       $this->saved_gidNumber= $this->attrs['gidNumber'][0];
69     }
71     /* Is a samba group? */
72     if (isset($this->attrs['objectClass'])){
73       if (array_search ('sambaGroupMapping', $this->attrs['objectClass']) == NULL ){
74         $this->smbgroup= FALSE;
75       } else {
76         $this->smbgroup= TRUE;
77         if (isset($this->attrs['sambaSID'])){
78           $this->sambaSID= $this->attrs['sambaSID'][0];
79         }
80       }
81       if (array_search ('goFonPickupGroup', $this->attrs['objectClass']) == NULL ){
82         $this->fon_group= FALSE;
83       } else {
84         $this->fon_group= TRUE;
85       }
86       if (array_search ('nagiosContactGroup', $this->attrs['objectClass']) == NULL ){
87         $this->nagios_group= FALSE;
88       } else {
89         $this->nagios_group= TRUE;
90       }
91     }
93     /* Set mail flag */
94     if (isset($this->attrs['objectClass']) && in_array('gosaMailAccount', $this->attrs['objectClass'])){
95       $this->has_mailAccount= TRUE;
96     }
98     /* Get samba Domain in case of samba 3 */
99     if ($this->samba3 && $this->sambaSID != ""){
100       $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
101       $ldap= $this->config->get_ldap_link();
102       $ldap->cd($this->config->current['BASE']);
103       $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase"));
104       if ($ldap->count() != 0){
105         $attrs= $ldap->fetch();
106         $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
108         /* Get domain name for SID */
109         $this->sambaDomainName= "DEFAULT";
110         foreach ($this->config->data['SERVERS']['SAMBA'] as $key => $val){
111           if ($val['SID'] == $this->SID){
112             $this->sambaDomainName= $key;
113             break;
114           }
115         }
116       } else {
117         if (isset($this->config->current['RIDBASE'])){
118           $this->sambaDomainName= "DEFAULT";
119           $this->ridBase= $this->config->current['RIDBASE'];
120           $this->SID= $this->config->current['SID'];
121         } else {
122           print_red(_("Can't find this groups SID in LDAP or in your configuration file!"));
123         }
124       }
126       /* Get group type */
127       $this->groupType= (int)substr(strrchr($this->sambaSID, "-"), 1);
128       if ($this->groupType < 500 || $this->groupType > 553){
129         $this->groupType= 0;
130       }
131       $this->oldgroupType= $this->groupType;
132     }
134     /* Get global filter config */
135     if (!is_global("gufilter")){
136       $ui= get_userinfo();
137       $base= get_base_from_people($ui->dn);
138       $gufilter= array( "dselect"       => $base,
139           "regex"           => "*");
140       register_global("gufilter", $gufilter);
141     }
142     $gufilter= get_global('gufilter');
144     $gufilter['SubSearchGroup'] = false;
145     $gufilter['dselect'] = $_SESSION['gufilter']['dselect'];  
147     register_global('gufilter',$gufilter);
148   
149     if ($this->dn == "new"){
150       if(isset($_SESSION['CurrentMainBase'])){
151         $this->base= $_SESSION['CurrentMainBase'];
152       }else{
153         $ui= get_userinfo();
154         $this->base= dn2base($ui->dn);
155       }
156     } else {
157       $this->base= preg_replace ("/^[^,]+,[^,]+,/", "", $this->dn);
158     }
160     /* This is always an account */
161     $this->is_account= TRUE;
162     $this->reload();
163   }
165   function execute()
166   {
167         /* Call parent execute */
168         plugin::execute();
170   /* Do we represent a valid group? */
171     if (!$this->is_account && $this->parent == NULL){
172       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
173         _("This 'dn' is no group.")."</b>";
174       return ($display);
175     }
177     /* Delete user from group */
178     if (isset($_POST['del_users']) && isset($_POST['members'])){
179       foreach ($_POST['members'] as $value){
180         unset ($this->members["$value"]);
181         $this->removeUser($value);
182       }
183       $this->reload();
184     }
186     /* Add objects? */
187     if (isset($_POST["edit_membership"])){
188       $this->group_dialog= TRUE;
189       $this->dialog= TRUE;
190     }
192     /* Add objects finished? */
193     if (isset($_POST["add_users_finish"]) || isset($_POST["add_users_cancel"])){
194       $this->group_dialog= FALSE;
195       $this->dialog= FALSE;
196     }
198     /* Add user to group */
199     if (isset($_POST['add_users_finish']) && isset($_POST['users'])){
200       foreach ($_POST['users'] as $value){
201         $this->members["$value"]= $this->allusers[$value];
202         asort($this->members);
203         $this->addUser($value);
204       }
205       $this->reload();
206     }
208     /* Base select dialog */
209     $once = true;
210     foreach($_POST as $name => $value){
211       if((preg_match("/^chooseBase/",$name) && $once) && ($this->acl_is_moveable())){
212           
213         $once = false;
214         $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
215         $this->dialog->setCurrentBase($this->base);
216       }
217     }
219     /* Dialog handling */
220     if(is_object($this->dialog)){
221       /* Must be called before save_object */
222       $this->dialog->save_object();
224       if($this->dialog->isClosed()){
225         $this->dialog = false;
226       }elseif($this->dialog->isSelected()){
227         if($this->acl_is_moveable()){
228           $this->base = $this->dialog->isSelected();
229         }
230         $this->dialog= false;
231       }else{
232         return($this->dialog->execute());
233       }
234     }
236    /* Assign templating stuff */
237     $smarty= get_smarty();
238     if ($this->samba3){
239       $smarty->assign("samba3", "true");
240     } else {
241       $smarty->assign("samba3", "");
242     }
244     if(search_config($this->config->data['MENU'], "nagiosaccount", "CLASS")){
245       $smarty->assign("nagios",true);
246     }else{
247       $smarty->assign("nagios",false);
248     }
249     
250     if(search_config($this->config->data['MENU'], "phoneAccount", "CLASS")){
251       $smarty->assign("pickupGroup",true);
252     }else{
253       $smarty->assign("pickupGroup",false);
254     }
256     /* Assign base ACL */
257     $baseACL = $this->getacl("base");
258     if(!$this->acl_is_moveable()) {
259       $baseACL = preg_replace("/w/","",$baseACL);
260     }
261     $smarty->assign("baseACL",          $baseACL);
263     /* Manage object add dialog */
264     if ($this->group_dialog){
266       /* Save data */
267       $gufilter= get_global("gufilter");
268       foreach( array("dselect", "regex") as $type){
269         if (isset($_POST[$type])){
270           $gufilter[$type]= $_POST[$type];
271         }
272       }
273       if(isset($_POST['regex'])){
274         if(isset($_POST['SubSearchGroup'])){
275           $gufilter['SubSearchGroup'] = true;
276         }else{
277           $gufilter['SubSearchGroup'] = false;
278         }
279       }
281       if (isset($_GET['search'])){
282         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
283         if ($s == "**"){
284           $s= "*";
285         }
286         $gufilter['regex']= $s;
287       }
288       register_global("gufilter", $gufilter);
289       $this->reload();
291       /* Show dialog */
292       $smarty->assign("search_image", get_template_path('images/search.png'));
293       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
294       $smarty->assign("tree_image", get_template_path('images/tree.png'));
296       $smarty->assign("deplist", $this->get_allowed_bases("users/user"));
297       $smarty->assign("alphabet", generate_alphabet());
298       foreach( array("dselect", "regex","SubSearchGroup") as $type){
299         $smarty->assign("$type", $gufilter[$type]);
300       }
301       $smarty->assign("hint", print_sizelimit_warning());
302       $smarty->assign("users", $this->displayUsers);
303       $smarty->assign("apply", apply_filter());
304       $display= $smarty->fetch (get_template_path('group_objects.tpl', TRUE, dirname(__FILE__)));
305       return ($display);
306     }
308     /* Bases / Departments */
309     if (isset($_POST['base'])){
310       $this->base= $_POST['base'];
311     }
313     $smarty->assign("bases", $this->get_allowed_bases());
314     $smarty->assign("base_select", $this->base);
316     if ($this->samba3){
317       $domains= array();
318       foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
319         $domains[$name]= $name;
320       }
321       $smarty->assign("sambaDomains", $domains);
322       $smarty->assign("sambaDomainName", $this->sambaDomainName);
323       $groupTypes= array(0 => _("Samba group"), 512 => _("Domain admins"), 513 => _("Domain users"),
324           514 => _("Domain guests"));
326       /* Don't loose special groups! If not key'ed above, add it to
327          the combo box... */    
328       if ($this->groupType >= 500 && $this->groupType <= 553 && !isset($groupTypes[$this->groupType])){
329         $groupTypes[$this->groupType]= sprintf(_("Special group (%d)"), $this->groupType);
330       }
332       $smarty->assign("groupTypes", $groupTypes);
333       $smarty->assign("groupType", $this->groupType);
334     }
336     /* Members and users */
337     $smarty->assign("members", $this->members);
339     /* Checkboxes */
340     foreach (array("force_gid", "smbgroup") as $val){
341       if ($this->$val == "1"){
342         $smarty->assign("$val", "checked");
343       } else {
344         $smarty->assign("$val", "");
345       }
346     }
347     if ($this->force_gid != "1"){
348       $smarty->assign("forceMode", "disabled");
349     }else{
350       $smarty->assign("forceMode", "");
351     }
352     if ($this->fon_group){
353       $smarty->assign("fon_group", "checked");
354     } else {
355       $smarty->assign("fon_group", "");
356     }
358     if ($this->nagios_group){
359       $smarty->assign("nagios_group", "checked");
360     } else {
361       $smarty->assign("nagios_group", "");
362     }
364     /* Fields */
365     foreach (array("cn", "description", "gidNumber") as $val){
366       $smarty->assign("$val", $this->$val);
367     }
369     $tmp = $this->plInfo();
370     foreach($tmp['plProvidedAcls'] as $name => $translation){
371       $smarty->assign($name."ACL",$this->getacl($name));
372     }
373     
374     if($this->acl_is_writeable("base")){
375       $smarty->assign("baseSelect",true);
376     }else{
377       $smarty->assign("baseSelect",false);
378     }
380     /* Show main page */
381     $smarty->assign("alphabet", generate_alphabet(10));
382     $smarty->assign("search_image", get_template_path('images/search.png'));
383     $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
384     $smarty->assign("tree_image", get_template_path('images/tree.png'));
385     $smarty->assign("deplist", $this->config->idepartments);
386     return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
387   }
389   function addUser($uid)
390   {
391     $this->memberUid[]= $uid;
392     $this->memberUid= array_unique($this->memberUid);
393   }
395   function removeUser($uid)
396   {
397     $temp= array();
398     foreach ($this->memberUid as $value){
399       if ($value != $uid){
400         $temp[]= $value;
401       }
402     }
403     $this->memberUid= $temp;
404   }
407   /* Reload data */
408   function reload()
409   {
410     /* Fix regex string */
411     $gufilter = get_global("gufilter");
412     $regex    = normalizeLdap($gufilter['regex']);
413     $MaxUser  = $this->OnlyShowFirstEntries;
415     /* Prepare ldap link */
416     $ldap= $this->config->get_ldap_link();
417     $ldap->cd($gufilter['dselect']);
420     /* Resolve still unresolved memberuids to fill the list with sn/giveName attributes 
421         (Store gathered sn/givenName informations in $this->allusers too, 
422          to be prepared when adding/deleting users)
423      */    
424     $filter = "";
425     foreach ($this->memberUid as $value){
426       if(!isset($this->members[$value])){
427         $filter .= "(uid=".normalizeLdap($value).")";
428       }
429     }
430     if(!empty($filter)){    
431       $ldap->cd($this->config->current['BASE']);
432       $ldap->search("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|".$filter."))",array("uid","sn","givenName"));
433       while($attrs = $ldap->fetch()){
434         $this->members[$attrs['uid'][0]] = $this->createResultName($attrs);
435         $this->allusers[$attrs['uid'][0]]= $this->createResultName($attrs);
436       } 
437     }
438   
439     /* check if all uids are resolved */
440     foreach ($this->memberUid as $value){
441       if(!isset($this->members[$value])){
442         $this->members[$value] =  _("! unknown id")." [".$value."]"; 
443       }
444     }  
446     /* Create display list of users matching regex & filter 
447      */
448     $this->displayUsers = array();
449     $filter = "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$))(|(uid=".$regex.")(sn=".$regex.")(givenName=".$regex.")))";
451     /* Search in current tree or within subtrees depending on the checkbox from filter section */
452     if($gufilter['SubSearchGroup']){
453       $flag = GL_SIZELIMIT | GL_SUBSEARCH;
454       $base = $gufilter['dselect'];
455     }else{
456       $flag = GL_SIZELIMIT ;
457       $base = get_people_ou().$gufilter['dselect'];
458     }
459     $i = 0;
460   
462     $res = get_list($filter,"users",$base,array("uid", "sn", "givenName"),$flag);
464     /* Fetch all users and skip already used users */
465     foreach($res as $attrs){
466       if(in_array($attrs['uid'][0], $this->memberUid)) {
467         continue;
468       }
469       $i ++;
470       if($i > $MaxUser) {
471         break;
472       }
473       $this->allusers[$attrs['uid'][0]]     = $this->createResultName($attrs);
474       $this->displayUsers[$attrs['uid'][0]] = $this->createResultName($attrs);
475     }
476   
477     /* If more than max users are found, display a message to warn the user */
478     if(($i == $MaxUser)){
479       print_red(sprintf(_("Your search method returned more than '%s' users, only '%s' users are shown.") , $MaxUser,$MaxUser));
480     }
481     
482     /* Sort lists */
483     natcasesort($this->members);
484     reset($this->members);
485     natcasesort ($this->displayUsers);
486     reset ($this->displayUsers);
487   }
490   /* Create display name, this was used so often that it is excluded into a seperate function */
491   function createResultName($attrs)
492   {
493     if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
494       $ret =  $attrs["sn"][0].", ".$attrs["givenName"][0]." [".$attrs["uid"][0]."]";
495     } else {
496       $ret= $attrs['uid'][0];
497     }
498     return($ret);
499   }
502   function remove_from_parent()
503   {
504     plugin::remove_from_parent();
506     $ldap= $this->config->get_ldap_link();
507     $ldap->rmdir($this->dn);
508     show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/generic with dn '%s' failed."),$this->dn));
510     /* Delete references to object groups */
511     $ldap->cd ($this->config->current['BASE']);
512     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
513     while ($ldap->fetch()){
514       $og= new ogroup($this->config, $ldap->getDN());
515       unset($og->member[$this->dn]);
516       $og->save ();
517     }
519     /* Send signal to the world that we've done */
520     $this->handle_post_events("remove");
521   }
524   /* Save data to object */
525   function save_object()
526   {
527     /* Save additional values for possible next step */
528     if (isset($_POST['groupedit'])){
530       plugin::save_object();
532       $this->force_gid= 0;
535       /* Only reset sambagroup flag if we are able to write this flag */
536       if($this->acl_is_writeable("sambaGroupType")){
537         $this->smbgroup = 0;
538       }
540       /* Get base selection */
541       if($this->acl_is_moveable() && isset($_POST['base'])){
542         $this->base = $_POST['base'];
543       }
545       foreach (array(
546             "force_gid"  => "gidNumber", 
547             "smbgroup"   => "sambaGroupType") as $val => $aclname) {
548         if ($this->acl_is_writeable($aclname)  && isset($_POST["$val"])){
549           $this->$val= $_POST["$val"];
550         }
551       }
553       /* Save sambaDomain attribute */
554       if ($this->acl_is_writeable("sambaDomainName") && $this->samba3 && isset ($_POST['sambaDomainName'])){
555         $this->sambaDomainName= $_POST['sambaDomainName'];
556         $this->groupType= $_POST['groupType'];
557       }
559       /* Save fon attribute */
560       if ($this->acl_is_writeable("fon_group")){
561         if (isset ($_POST['fon_group'])){
562           $this->fon_group= TRUE;
563         } else {
564           $this->fon_group= FALSE;
565         }
566       }
567       if ($this->acl_is_writeable("nagios_group")){
568         if (isset ($_POST['nagios_group'])){
569           $this->nagios_group= TRUE;
570         } else {
571           $this->nagios_group= FALSE;
572         }
573       }
574     }
575   }
578   /* Save to LDAP */
579   function save()
580   {
582     /* ID handling */
583     if ($this->force_gid == 0){
584       if ($this->saved_gidNumber != ""){
585         $this->gidNumber= $this->saved_gidNumber;
586       } else {
587         /* Calculate new, lock uids */
588         $wait= 10;
589         while (get_lock("uidnumber") != ""){
590           sleep (1);
592           /* timed out? */
593           if ($wait-- == 0){
594             break;
595           }
596         }
597         add_lock ("uidnumber", "gosa");
598         $this->gidNumber= $this->get_next_id("gidNumber");
599       }
600     }
601   
602     plugin::save(); 
604     /* Remove objectClass for samba/phone support */
605     $tmp= array();
606     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
607       if ($this->attrs['objectClass'][$i] != 'sambaGroupMapping' &&
608           $this->attrs['objectClass'][$i] != 'sambaIdmapEntry' &&
609           $this->attrs['objectClass'][$i] != 'goFonPickupGroup' &&
610          $this->attrs['objectClass'][$i] != 'nagiosContactGroup'){
611         $tmp[]= $this->attrs['objectClass'][$i];
612       }
613     }
614     $this->attrs['objectClass']= $tmp;
615     $ldap= $this->config->get_ldap_link();
617     /* Add samba group functionality */
618     if ($this->samba3 && $this->smbgroup){
619   
620       /* Fixed undefined index ... 
621        */ 
622       $this->SID = $this->ridBase = "";
623       if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
624         $this->SID    = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
625       }else{
626         print_red(sprintf(_("No configured SID found for '%s'."),$this->sambaDomainName));
627       }
628       if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'])){
629         $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE']; 
630       }else{
631         print_red(sprintf(_("No configured RIDBASE found for '%s'."),$this->sambaDomainName));
632       }
634       $this->attrs['objectClass'][]= 'sambaGroupMapping';
635       $this->attrs['sambaGroupType']= "2";
637       /* Check if we need to create a special entry */
638       if ($this->groupType == 0){
640         if ($this->sambaSID == "" || $this->oldgroupType != $this->groupType){
641           $gidNumber= $this->gidNumber;
642           while(TRUE){
643             $sid= $this->SID."-".($gidNumber*2 + $this->ridBase+1);
644             $ldap->cd($this->config->current['BASE']);
645             $ldap->search("(sambaSID=$sid)",array("sambaSID"));
646             if ($ldap->count() == 0){
647               break;
648             }
649             $gidNumber++;
650           }
651           $this->attrs['sambaSID']= $sid;
652           $this->sambaSID= $sid;
653         }
655       } else {
656         $this->attrs['sambaSID']=$this->SID."-".$this->groupType;
657       }
659       /* User wants me to fake the idMappings? This is useful for
660          making winbind resolve the group names in a reasonable amount
661          of time in combination with larger databases. */
662       if (isset($this->config->current['SAMBAIDMAPPING']) &&
663           preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
664         $this->attrs['objectClass'][]= "sambaIdmapEntry";
665       }
667     }
669     /* Add phone functionality */
670     if ($this->fon_group){
671       $this->attrs['objectClass'][]= "goFonPickupGroup";
672     }
674     /* Add nagios functionality */
675     if ($this->nagios_group){
676         $this->attrs['objectClass'][]= "nagiosContactGroup";
677     }
679     /* Take members array */
680     if (count ($this->memberUid)){
681       $this->attrs['memberUid']= array_unique($this->memberUid);
682     }
684     /* New accounts need proper 'dn', propagate it to remaining objects */
685     if ($this->dn == 'new'){
686       $this->dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
687     }
689     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
690        new entries. So do a check first... */
691     $ldap->cat ($this->dn, array('dn'));
692     if ($ldap->fetch()){
693       /* Modify needs array() to remove values :-( */
694       if (!count ($this->memberUid)){
695         $this->attrs['memberUid']= array();
696       }
697       if ($this->samba3){
698         if (!$this->smbgroup){
699           $this->attrs['sambaGroupType']= array();
700           $this->attrs['sambaSID']= array();
701         }
702       }
703       $mode= "modify";
704     } else {
705       $mode= "add";
706       $ldap->cd($this->config->current['BASE']);
707       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
708     }
710     /* Write back to ldap */
711     $ldap->cd($this->dn);
712     $this->cleanup();
713     $ldap->$mode($this->attrs);
715     $ret= 0;
716     if ( show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/generic with dn '%s' failed."),$this->dn))){
717       $ret= 1;
718     }
720     /* Remove uid lock */
721     del_lock ("uidnumber");
723     /* Post that we've done*/
724     $this->handle_post_events($mode);
726     return ($ret);
727   }
729   function check()
730   {
731     /* Call common method to give check the hook */
732     $message= plugin::check();
734     /* Permissions for that base? */
735     if ($this->base != ""){
736       $new_dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
737     } else {
738       $new_dn= $this->dn;
739     }
741     if ($this->orig_dn == "new" && !$this->acl_is_createable()){
742       $message[]= _("You have no permissions to create a group on this 'Base'.");
743     }
745     /* must: cn */
746     if ($this->cn == "" && $this->acl_is_writeable("cn")){
747       $message[]= "The required field 'Name' is not set.";
748     }
750     /* Check for valid input */
751     if (!is_uid($this->cn)){
752       $message[]= _("The field 'Name' contains invalid characters. Lowercase, numbers and dashes are allowed.");
753     }
755     if($this->allowGroupsWithSameNameInOtherSubtrees == true){
757       /* Check for used 'cn' */
758       $ldap= $this->config->get_ldap_link();
759       if(($this->cn  != $this->orig_cn) || ($this->orig_dn == "new")){
760         $ldap->cd("ou=groups,".$this->base);
761         $ldap->ls("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",get_groups_ou().$this->base,array("cn"));
762         if ($ldap->count() != 0){
763           $message[]= _("Value specified as 'Name' is already used.");
764         }
765       }
767     }else{
769       /* Check for used 'cn' */
770       $ldap= $this->config->get_ldap_link();
771       $ldap->cd($this->config->current['BASE']);
772       $ldap->search("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",array("cn"));
773       if ($ldap->count() != 0){
775         /* New entry? */
776         if ($this->dn == 'new'){
777           $message[]= _("Value specified as 'Name' is already used.");
778         }
780         /* Moved? */
781         elseif ($new_dn != $this->orig_dn){
782           $ldap->fetch();
783           if ($ldap->getDN() != $this->orig_dn){
784             $message[]= _("Value specified as 'Name' is already used.");
785           }
786         }
787       }
788     }
789      
790     /* Check ID */
791     if ($this->force_gid == "1"){
792       if (!is_id($this->gidNumber)){
793         $message[]= _("Value specified as 'GID' is not valid.");
794       } else {
795         if ($this->gidNumber < $this->config->current['MINID']){
796           $message[]= _("Value specified as 'GID' is too small.");
797         }
799       }
800     }
802     return ($message);
803   }
805   function get_next_id($attrib)
806   {
807     $ids= array();
808     $ldap= $this->config->get_ldap_link();
810     $ldap->cd ($this->config->current['BASE']);
811     if (preg_match('/gidNumber/i', $attrib)){
812       $oc= "posixGroup";
813     } else {
814       $oc= "posixAccount";
815     }
816     $ldap->search ("(&(objectClass=$oc)($attrib=*))", array("$attrib"));
818     /* Get list of ids */
819     while ($attrs= $ldap->fetch()){
820       $ids[]= (int)$attrs["$attrib"][0];
821     }
823     /* Find out next free id near to UID_BASE */
824     for ($id= $this->config->current['UIDBASE']; $id++; $id<65000){
825       if (!in_array($id, $ids)){
826         return ($id);
827       }
828     }
830     /* Should not happen */
831     if ($id == 65000){
832       print_red(_("Too many users, can't allocate a free ID!"));
833       exit;
834     }
835   }
837   function getCopyDialog()
838   {
839     $vars = array("cn");
840   
841     if($this ->force_gid){
842       $used = " checked ";
843       $dis  = "";
844     }else{
845       $used = "";
846       $dis  = " disabled ";
847     }
849     $smarty = get_smarty();
850     $smarty->assign("used",$used);
851     $smarty->assign("dis" ,$dis);
852     $smarty->assign("cn" ,$this->cn);
853     $smarty->assign("gidNumber",$this->gidNumber);
854     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
855     $ret = array();
856     $ret['string'] = $str;
857     $ret['status'] = "";
858     return($ret);
859   }
861   function saveCopyDialog()
862   {
863     if(isset($_POST['cn'])){
864       $this->cn = $_POST['cn'];
865     }
866     if(isset($_POST['force_gid'])){
867       $this->force_gid  = 1;
868       $this->gidNumber= $_POST['gidNumber'];
869     }else{
870       $this->force_gid  = 0;
871       $this->gidNumber  = false;
872     }
873   }
875   
876   /* Return plugin informations for acl handling  */ 
877   function plInfo()
878   {
879     return (array(  
880           "plShortName" => _("Generic"),
881           "plDescription" => _("Generic group settings"),
882           "plSelfModify"  => FALSE,
883           "plDepends"     => array(),
884           "plPriority"    => 0,
885           "plSection"     => array("admin"),
886           "plCategory"    => array("groups" => array("objectClass" => "posixGroup", "description" => _("Groups"))),
888           "plProvidedAcls"    => array(
889             "cn"                => _("Name"),
890             "base"              => _("Base"),
891             "description"       => _("Description"),
893             "fonGroup"          => _("Phone pickup group"),
894             "nagiosGroup"       => _("Nagios group"),
896             "gidNumber"         => _("GID"),
897             "memberUid"         => _("Group member"),
898             "sambaGroupType"    => _("Samba group type"),
899             "sambaDomainName"   => _("Samba domain name"),
900             "sambaSID"          => _("Samba SID"))
901         ));
902   }
905 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
906 ?>