Code

f59768a26af91f514d5a575d1ee490be220656e2
[gosa.git] / plugins / admin / groups / class_groupGeneric.inc
1 <?php
2 class group extends plugin
3 {
4   /* CLI vars */
5   var $cli_summary= "Handling of GOsa's base group object";
6   var $cli_description= "Some longer text\nfor help";
7   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9   /* Group attributes */
10   var $cn= "";
11   var $description= "";
12   var $gidNumber= "";
13   var $memberUid= array();
15   /* Helpers */
16   var $base= "";
17   var $force_gid= FALSE;
18   var $fon_group= FALSE;
19   var $smbgroup= FALSE;
20   var $groupType= FALSE;
21   var $samba3= FALSE;
22   var $sambaSID= "";
23   var $sambaDomainName= "DEFAULT";
24   var $SID= "";
25   var $ridBase= 0;
26   var $members= array();
27   var $users= array();
28   var $allusers= array();
29   var $department= "";
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   
146     register_global('gufilter',$gufilter);
147   
148       /* Bases / Departments */
149       
150     if(isset($_SESSION['groupfilter']['depselect'])){
151       $this->base = $_SESSION['groupfilter']['depselect'];
152     }else{
153       if ($this->dn == "new"){
154         $ui= get_userinfo();
155         $this->base= dn2base($ui->dn);
156       } else {
157         $this->base= preg_replace ("/^[^,]+,[^,]+,/", "", $this->dn);
158       }
159     }
160     
162     /* This is always an account */
163     $this->is_account= TRUE;
164     $this->reload();
165   }
167   function execute()
168   {
169         /* Call parent execute */
170         plugin::execute();
172   $ui= get_userinfo();
173   $acla= get_permissions ($ui->dn, $ui->subtreeACL);
174   $this->acl= get_module_permission($acla, "group", $ui->dn);
175   /* Do we represent a valid group? */
176     if (!$this->is_account && $this->parent == NULL){
177       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
178         _("This 'dn' is no group.")."</b>";
179       return ($display);
180     }
182     /* Delete user from group */
183     if (isset($_POST['del_users']) && isset($_POST['members'])){
184       foreach ($_POST['members'] as $value){
185         unset ($this->members["$value"]);
186         $this->removeUser($value);
187       }
188       $this->reload();
189     }
191     /* Add objects? */
192     if (isset($_POST["edit_membership"])){
193       $this->group_dialog= TRUE;
194       $this->dialog= TRUE;
195     }
197     /* Add objects finished? */
198     if (isset($_POST["add_users_finish"]) || isset($_POST["add_users_cancel"])){
199       $this->group_dialog= FALSE;
200       $this->dialog= FALSE;
201     }
203     /* Add user to group */
204     if (isset($_POST['add_users_finish']) && isset($_POST['users'])){
205       foreach ($_POST['users'] as $value){
206         $this->members["$value"]= $this->allusers[$value];
207         asort($this->members);
208         $this->addUser($value);
209       }
210       $this->reload();
211     }
213     /* Base select dialog */
214     $once = true;
215     foreach($_POST as $name => $value){
216       if(preg_match("/^chooseBase/",$name) && $once){
217         $once = false;
218         $this->dialog = new baseSelectDialog($this->config);
219         $this->dialog->setCurrentBase($this->base);
220       }
221     }
223     /* Dialog handling */
224     if(is_object($this->dialog)){
225       /* Must be called before save_object */
226       $this->dialog->save_object();
228       if($this->dialog->isClosed()){
229         $this->dialog = false;
230       }elseif($this->dialog->isSelected()){
231         $this->base = $this->dialog->isSelected();
232         $this->dialog= false;
233       }else{
234         return($this->dialog->execute());
235       }
236     }
238    /* Assign templating stuff */
239     $smarty= get_smarty();
240     if ($this->samba3){
241       $smarty->assign("samba3", "true");
242     } else {
243       $smarty->assign("samba3", "");
244     }
246     if(search_config($this->config->data['MENU'], "nagiosaccount", "CLASS")){
247       $smarty->assign("nagios",true);
248     }else{
249       $smarty->assign("nagios",false);
250     }
251     
252     if(search_config($this->config->data['MENU'], "phoneAccount", "CLASS")){
253       $smarty->assign("pickupGroup",true);
254     }else{
255       $smarty->assign("pickupGroup",false);
256     }
258     /* Manage object add dialog */
259     if ($this->group_dialog){
261       /* Save data */
262       $gufilter= get_global("gufilter");
263       foreach( array("dselect", "regex") as $type){
264         if (isset($_POST[$type])){
265           $gufilter[$type]= $_POST[$type];
266         }
267       }
268       if(isset($_POST['regex'])){
269         if(isset($_POST['SubSearchGroup'])){
270           $gufilter['SubSearchGroup'] = true;
271         }else{
272           $gufilter['SubSearchGroup'] = false;
273         }
274       }
276       if (isset($_GET['search'])){
277         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
278         if ($s == "**"){
279           $s= "*";
280         }
281         $gufilter['regex']= $s;
282       }
283       $regex= preg_replace('/[*]/', ".*", $gufilter['regex']);
284       register_global("gufilter", $gufilter);
285       $this->reload();
287       /* Show dialog */
288       $smarty->assign("search_image", get_template_path('images/search.png'));
289       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
290       $smarty->assign("tree_image", get_template_path('images/tree.png'));
291       $smarty->assign("deplist", $this->config->idepartments);
292       $smarty->assign("alphabet", generate_alphabet());
293       foreach( array("dselect", "regex","SubSearchGroup") as $type){
294         $smarty->assign("$type", $gufilter[$type]);
295       }
296       $smarty->assign("hint", print_sizelimit_warning());
298       $users= array();
299       foreach ($this->allusers as $key => $value){
300         if (!array_key_exists($key, $this->members)){
301           if (preg_match("/^$regex/i", $key)){
302             $users[$key]= $value;
303           }
304         }
305       }
306       $smarty->assign("users", $users);
307       $smarty->assign("apply", apply_filter());
308       $display= $smarty->fetch (get_template_path('group_objects.tpl', TRUE, dirname(__FILE__)));
309       return ($display);
310     }
312     /* Bases / Departments */
313     if (isset($_POST['base'])){
314       $this->base= $_POST['base'];
315     }
317     $smarty->assign("bases", $this->config->idepartments);
318     $smarty->assign("base_select", $this->base);
319     $smarty->assign("department", $this->department);
321     if ($this->samba3){
322       $domains= array();
323       foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
324         $domains[$name]= $name;
325       }
326       $smarty->assign("sambaDomains", $domains);
327       $smarty->assign("sambaDomainName", $this->sambaDomainName);
328       $groupTypes= array(0 => _("Samba group"), 512 => _("Domain admins"), 513 => _("Domain users"),
329           514 => _("Domain guests"));
331       /* Don't loose special groups! If not key'ed above, add it to
332          the combo box... */    
333       if ($this->groupType >= 500 && $this->groupType <= 553 && !isset($groupTypes[$this->groupType])){
334         $groupTypes[$this->groupType]= sprintf(_("Special group (%d)"), $this->groupType);
335       }
337       $smarty->assign("groupTypes", $groupTypes);
338       $smarty->assign("groupType", $this->groupType);
339     }
341     /* Members and users */
342     $smarty->assign("members", $this->members);
344     /* Checkboxes */
345     foreach (array("force_gid", "smbgroup") as $val){
346       if ($this->$val == "1"){
347         $smarty->assign("$val", "checked");
348       } else {
349         $smarty->assign("$val", "");
350       }
351     }
352     if ($this->force_gid != "1"){
353       $smarty->assign("forceMode", "disabled");
354     }else{
355       $smarty->assign("forceMode", "");
356     }
357     $smarty->assign("force_gidACL", chkacl($this->acl, "gidNumber"));
358     $smarty->assign("sambaDomainNameACL", chkacl($this->acl, "sambaDomainName"));
359     if ($this->fon_group){
360       $smarty->assign("fon_group", "checked");
361     } else {
362       $smarty->assign("fon_group", "");
363     }
364     $smarty->assign("fon_groupACL", chkacl($this->acl, "fon_group"));
366     if ($this->nagios_group){
367       $smarty->assign("nagios_group", "checked");
368     } else {
369       $smarty->assign("nagios_group", "");
370     }
371     $smarty->assign("nagios_groupACL", chkacl($this->acl, "nagios_group"));
373     /* Fields */
374     foreach (array("cn", "description", "gidNumber") as $val){
375       $smarty->assign("$val", $this->$val);
376       $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
377     }
379     /* Missing ACL's */
380     foreach (array("base", "smbgroup", "members") as $val){
381       $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
382     }
384     /* Show main page */
385     $smarty->assign("alphabet", generate_alphabet(10));
386     $smarty->assign("search_image", get_template_path('images/search.png'));
387     $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
388     $smarty->assign("tree_image", get_template_path('images/tree.png'));
389     $smarty->assign("deplist", $this->config->idepartments);
390     return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
391   }
393   function addUser($uid)
394   {
395     $this->memberUid[]= $uid;
396     $this->memberUid= array_unique($this->memberUid);
397   }
399   function removeUser($uid)
400   {
401     $temp= array();
402     foreach ($this->memberUid as $value){
403       if ($value != $uid){
404         $temp[]= $value;
405       }
406     }
407     $this->memberUid= $temp;
408   }
411   /* Reload data */
412   function reload()
413   {
414     /* Generate userlists */
415     $this->last_sorting= "invalid";
416     $this->users= array();
417     $ldap= $this->config->get_ldap_link();
419     $MaxUser = $this->OnlyShowFirstEntries;
421     $gufilter= get_global("gufilter");
422     $ldap->cd ($this->config->current['BASE']);
423     if($gufilter['SubSearchGroup']){
424       $ldap->cd ($gufilter['dselect']);
425       $ldap->search("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$)))",array("uid", "sn","givenName"));
426     }else{
427       $ldap->cd (get_people_ou().$gufilter['dselect']);
428       $ldap->ls ("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$)))",get_people_ou().$gufilter['dselect'],array("uid", "sn", "givenName"));
429     }
430     $this->allusers= array();
431     
432     $i = 0 ;
433     while (($attrs= $ldap->fetch()) && ($i < $MaxUser)){
434       $i ++;
435       if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
436         $this->allusers[$attrs["uid"][0]]= $attrs["sn"][0].", ".
437           $attrs["givenName"][0]." [".$attrs["uid"][0]."]";
438       } else {
439         $this->allusers[$attrs["uid"][0]]= $attrs['uid'][0];
440       }
441     }
442   
443     if(($i == $MaxUser)){
444       print_red(sprintf(_("Your search method returned more than '%s' users, only '%s' users are shown.") , $MaxUser,$MaxUser));
445     }
446     
447     natcasesort ($this->allusers);
448     reset ($this->allusers);
450     /* Fill memberlist */
451     $this->members= array();
452     foreach ($this->memberUid as $value){
453       if (isset($this->allusers[$value])){
454         $this->members[$value]= $this->allusers[$value];
455       } else {
456         $ldap->cd($this->config->current['BASE']);
457         $ldap->search("(&(objectClass=gosaAccount)(uid=".$value."))",array("uid", "sn","givenName"));
458         $attrs = $ldap->fetch();
459     
460         if(!$attrs){
461           $this->members[$value] = _("! unknown id")." [".$value."]"; 
462         }else{
463     
464           if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
465             $this->allusers[$attrs["uid"][0]]= $attrs["sn"][0].", ".
466               $attrs["givenName"][0]." [".$attrs["uid"][0]."]";
467           } else {
468             $this->allusers[$attrs["uid"][0]]= $attrs['uid'][0];
469           }
470           if (isset($this->allusers[$value])){
471             $this->members[$value]= $this->allusers[$value];
472           } else {
473             $this->members[$value] = "[".$value."]";
474           }
475         }
476       }
477     }
478     asort($this->members);
479     reset($this->members);
480   }
484   function remove_from_parent()
485   {
486     plugin::remove_from_parent();
488     $ldap= $this->config->get_ldap_link();
489     $ldap->rmdir($this->dn);
490     show_ldap_error($ldap->get_error());
492     /* Delete references to object groups */
493     $ldap->cd ($this->config->current['BASE']);
494     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
495     while ($ldap->fetch()){
496       $og= new ogroup($this->config, $ldap->getDN());
497       unset($og->member[$this->dn]);
498       $og->save ();
499     }
501     /* Send signal to the world that we've done */
502     $this->handle_post_events("remove");
503   }
506   /* Save data to object */
507   function save_object()
508   {
509     /* Save additional values for possible next step */
510     if (isset($_POST['groupedit'])){
512       
513       plugin::save_object();
515       $this->force_gid= 0;
516       $this->smbgroup= 0;
517       foreach (array("force_gid", "department", "base", "smbgroup") as $val) {
518         if (chkacl ($this->acl, "$val") == "" && isset($_POST["$val"])){
519           $this->$val= $_POST["$val"];
520         }
521       }
523       /* Save sambaDomain attribute */
524       if (chkacl ($this->acl, "sambaDomainName") == "" && $this->samba3 &&
525           isset ($_POST['sambaDomainName'])){
527         $this->sambaDomainName= $_POST['sambaDomainName'];
528         $this->groupType= $_POST['groupType'];
529       }
531       /* Save fon attribute */
532       if (chkacl ($this->acl, "fon_group") == ""){
533         if (isset ($_POST['fon_group'])){
534           $this->fon_group= TRUE;
535         } else {
536           $this->fon_group= FALSE;
537         }
538       }
539          if (chkacl ($this->acl, "nagios_group") == ""){
540         if (isset ($_POST['nagios_group'])){
541           $this->nagios_group= TRUE;
542         } else {
543           $this->nagios_group= FALSE;
544         }
545       }
546     }
547   }
550   /* Save to LDAP */
551   function save()
552   {
553     /* ID handling */
554     if ($this->force_gid == 0){
555       if ($this->saved_gidNumber != ""){
556         $this->gidNumber= $this->saved_gidNumber;
557       } else {
558         /* Calculate new, lock uids */
559         $wait= 10;
560         while (get_lock("uidnumber") != ""){
561           sleep (1);
563           /* timed out? */
564           if ($wait-- == 0){
565             break;
566           }
567         }
568         add_lock ("uidnumber", "gosa");
569         $this->gidNumber= $this->get_next_id("gidNumber");
570       }
571     }
573     plugin::save(); 
575     /* Remove objectClass for samba/phone support */
576     $tmp= array();
577     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
578       if ($this->attrs['objectClass'][$i] != 'sambaGroupMapping' &&
579           $this->attrs['objectClass'][$i] != 'sambaIdmapEntry' &&
580           $this->attrs['objectClass'][$i] != 'goFonPickupGroup' &&
581          $this->attrs['objectClass'][$i] != 'nagiosContactGroup'){
582         $tmp[]= $this->attrs['objectClass'][$i];
583       }
584     }
585     $this->attrs['objectClass']= $tmp;
586     $ldap= $this->config->get_ldap_link();
588     /* Add samba group functionality */
589     if ($this->samba3 && $this->smbgroup){
590   
591       /* Fixed undefined index ... 
592        */ 
593       $this->SID = $this->ridBase = "";
594       if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
595         $this->SID    = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
596       }else{
597         print_red(sprintf(_("No configured SID found for '%s'."),$this->sambaDomainName));
598       }
599       if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'])){
600         $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE']; 
601       }else{
602         print_red(sprintf(_("No configured RIDBASE found for '%s'."),$this->sambaDomainName));
603       }
605       $this->attrs['objectClass'][]= 'sambaGroupMapping';
606       $this->attrs['sambaGroupType']= "2";
608       /* Check if we need to create a special entry */
609       if ($this->groupType == 0){
611         if ($this->sambaSID == "" || $this->oldgroupType != $this->groupType){
612           $gidNumber= $this->gidNumber;
613           while(TRUE){
614             $sid= $this->SID."-".($gidNumber*2 + $this->ridBase+1);
615             $ldap->cd($this->config->current['BASE']);
616             $ldap->search("(sambaSID=$sid)",array("sambaSID"));
617             if ($ldap->count() == 0){
618               break;
619             }
620             $gidNumber++;
621           }
622           $this->attrs['sambaSID']= $sid;
623           $this->sambaSID= $sid;
624         }
626       } else {
627         $this->attrs['sambaSID']=$this->SID."-".$this->groupType;
628       }
630       /* User wants me to fake the idMappings? This is useful for
631          making winbind resolve the group names in a reasonable amount
632          of time in combination with larger databases. */
633       if (isset($this->config->current['SAMBAIDMAPPING']) &&
634           preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
635         $this->attrs['objectClass'][]= "sambaIdmapEntry";
636       }
638     }
640     /* Add phone functionality */
641     if ($this->fon_group){
642       $this->attrs['objectClass'][]= "goFonPickupGroup";
643     }
645     /* Add nagios functionality */
646     if ($this->nagios_group){
647         $this->attrs['objectClass'][]= "nagiosContactGroup";
648     }
650     /* Take members array */
651     if (count ($this->memberUid)){
652       $this->attrs['memberUid']= array_unique($this->memberUid);
653     }
655     /* New accounts need proper 'dn', propagate it to remaining objects */
656     if ($this->dn == 'new'){
657       $this->dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
658     }
660     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
661        new entries. So do a check first... */
662     $ldap->cat ($this->dn);
663     if ($ldap->fetch()){
664       /* Modify needs array() to remove values :-( */
665       if (!count ($this->memberUid)){
666         $this->attrs['memberUid']= array();
667       }
668       if ($this->samba3){
669         if (!$this->smbgroup){
670           $this->attrs['sambaGroupType']= array();
671           $this->attrs['sambaSID']= array();
672         }
673       }
674       $mode= "modify";
675     } else {
676       $mode= "add";
677       $ldap->cd($this->config->current['BASE']);
678       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
679     }
681     /* Write back to ldap */
682     $ldap->cd($this->dn);
683     $this->cleanup();
684     $ldap->$mode($this->attrs);
686     $ret= 0;
687     if (show_ldap_error($ldap->get_error())){
688       $ret= 1;
689     }
691     /* Remove uid lock */
692     del_lock ("uidnumber");
694     /* Post that we've done*/
695     $this->handle_post_events($mode);
697     return ($ret);
698   }
700   function check()
701   {
702     $message= array();
704     /* Permissions for that base? */
705     if ($this->base != ""){
706       $new_dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
707     } else {
708       $new_dn= $this->dn;
709     }
711     $ui= get_userinfo();
712     $acl= get_permissions ($ui->dn, $ui->subtreeACL);
713     $acl= get_module_permission($acl, "group", $ui->dn);
714     if (chkacl($this->acl, "create") != ""){
715       $message[]= _("You have no permissions to create a group on this 'Base'.");
716     }
718     /* must: cn */
719     if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
720       $message[]= "The required field 'Name' is not set.";
721     }
723     /* Check for valid input */
724     if (!is_uid($this->cn)){
725       $message[]= _("The field 'Name' contains invalid characters. Lowercase, numbers and dashes are allowed.");
726     }
729     if($this->allowGroupsWithSameNameInOtherSubtrees == true){
731       /* Check for used 'cn' */
732       $ldap= $this->config->get_ldap_link();
733       if(($this->cn  != $this->orig_cn) || ($this->orig_dn == "new")){
734         $ldap->cd("ou=groups,".$this->base);
735         $ldap->ls("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))","ou=groups,".$this->base,array("cn"));
736         if ($ldap->count() != 0){
737           $message[]= _("Value specified as 'Name' is already used.");
738         }
739       }
741     }else{
743       /* Check for used 'cn' */
744       $ldap= $this->config->get_ldap_link();
745       $ldap->cd($this->config->current['BASE']);
746       $ldap->search("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",array("cn"));
747       if ($ldap->count() != 0){
749         /* New entry? */
750         if ($this->dn == 'new'){
751           $message[]= _("Value specified as 'Name' is already used.");
752         }
754         /* Moved? */
755         elseif ($new_dn != $this->orig_dn){
756           $ldap->fetch();
757           if ($ldap->getDN() != $this->orig_dn){
758             $message[]= _("Value specified as 'Name' is already used.");
759           }
760         }
761       }
762     }
763      
764     /* Check ID */
765     if ($this->force_gid == "1"){
766       if (!is_id($this->gidNumber)){
767         $message[]= _("Value specified as 'GID' is not valid.");
768       } else {
769         if ($this->gidNumber < $this->config->current['MINID']){
770           $message[]= _("Value specified as 'GID' is too small.");
771         }
773       }
774     }
776     return ($message);
777   }
779   function get_next_id($attrib)
780   {
781     $ids= array();
782     $ldap= $this->config->get_ldap_link();
784     $ldap->cd ($this->config->current['BASE']);
785     if (preg_match('/gidNumber/i', $attrib)){
786       $oc= "posixGroup";
787     } else {
788       $oc= "posixAccount";
789     }
790     $ldap->search ("(&(objectClass=$oc)($attrib=*))", array("$attrib"));
792     /* Get list of ids */
793     while ($attrs= $ldap->fetch()){
794       $ids[]= (int)$attrs["$attrib"][0];
795     }
797     /* Find out next free id near to UID_BASE */
798     for ($id= $this->config->current['UIDBASE']; $id++; $id<65000){
799       if (!in_array($id, $ids)){
800         return ($id);
801       }
802     }
804     /* Should not happen */
805     if ($id == 65000){
806       print_red(_("Too many users, can't allocate a free ID!"));
807       exit;
808     }
809   }
813 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
814 ?>