Code

Fixed FAIclass selection
[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 $has_mailAccount= FALSE;
34   var $group_dialog= FALSE;
35   var $nagios_group =FALSE;
36   var $sambaGroupType;
37   var $dialog;
39   /* attribute list for save action */
40   var $attributes= array("cn", "description", "gidNumber","memberUid","sambaGroupType","sambaSID");
41   var $objectclasses= array("top", "posixGroup");
43   function group ($config, $dn= NULL)
44   {
45     plugin::plugin ($config, $dn);
47     /* Load attributes depending on the samba version */
48     $this->samba3= ($config->current['SAMBAVERSION'] == 3);
49     $this->orig_dn= $dn;
51     /* Get member list */
52     if (isset($this->attrs['memberUid'][0])){
53       $tmp= array();
54       for ($i= 0; $i<$this->attrs['memberUid']['count']; $i++){
55         $tmp[]= $this->attrs['memberUid'][$i];
56       }
57       $this->memberUid= $tmp;
58       sort ($this->memberUid);
59     }
61     /* Save gidNumber for later use */
62     if (isset($this->attrs['gidNumber'])){
63       $this->saved_gidNumber= $this->attrs['gidNumber'][0];
64     }
66     /* Is a samba group? */
67     if (isset($this->attrs['objectClass'])){
68       if (array_search ('sambaGroupMapping', $this->attrs['objectClass']) == NULL ){
69         $this->smbgroup= FALSE;
70       } else {
71         $this->smbgroup= TRUE;
72         if (isset($this->attrs['sambaSID'])){
73           $this->sambaSID= $this->attrs['sambaSID'][0];
74         }
75       }
76       if (array_search ('goFonPickupGroup', $this->attrs['objectClass']) == NULL ){
77         $this->fon_group= FALSE;
78       } else {
79         $this->fon_group= TRUE;
80       }
81       if (array_search ('nagiosContactGroup', $this->attrs['objectClass']) == NULL ){
82         $this->nagios_group= FALSE;
83       } else {
84         $this->nagios_group= TRUE;
85       }
86     }
88     /* Set mail flag */
89     if (isset($this->attrs['objectClass']) && in_array('gosaMailAccount', $this->attrs['objectClass'])){
90       $this->has_mailAccount= TRUE;
91     }
93     /* Get samba Domain in case of samba 3 */
94     if ($this->samba3 && $this->sambaSID != ""){
95       $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
96       $ldap= $this->config->get_ldap_link();
97       $ldap->cd($this->config->current['BASE']);
98       $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase"));
99       if ($ldap->count() != 0){
100         $attrs= $ldap->fetch();
101         $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
103         /* Get domain name for SID */
104         $this->sambaDomainName= "DEFAULT";
105         foreach ($this->config->data['SERVERS']['SAMBA'] as $key => $val){
106           if ($val['SID'] == $this->SID){
107             $this->sambaDomainName= $key;
108             break;
109           }
110         }
111       } else {
112         if (isset($this->config->current['RIDBASE'])){
113           $this->sambaDomainName= "DEFAULT";
114           $this->ridBase= $this->config->current['RIDBASE'];
115           $this->SID= $this->config->current['SID'];
116         } else {
117           print_red(_("Can't find this groups SID in LDAP or in your configuration file!"));
118         }
119       }
121       /* Get group type */
122       $this->groupType= (int)substr(strrchr($this->sambaSID, "-"), 1);
123       if ($this->groupType < 500 || $this->groupType > 553){
124         $this->groupType= 0;
125       }
126       $this->oldgroupType= $this->groupType;
127     }
129     /* Get global filter config */
130     if (!is_global("gufilter")){
131       $ui= get_userinfo();
132       $base= get_base_from_people($ui->dn);
133       $gufilter= array( "dselect"       => $base,
134           "regex"           => "*");
135       register_global("gufilter", $gufilter);
136     }
137     $gufilter= get_global('gufilter');
139       /* Bases / Departments */
140       
141     if(isset($_SESSION['groupfilter']['depselect'])){
142       $this->base = $_SESSION['groupfilter']['depselect'];
143     }else{
144       if ($this->dn == "new"){
145         $ui= get_userinfo();
146         $this->base= dn2base($ui->dn);
147       } else {
148         $this->base= preg_replace ("/^[^,]+,[^,]+,/", "", $this->dn);
149       }
150     }
153     /* This is always an account */
154     $this->is_account= TRUE;
155     $this->reload();
156   }
158   function execute()
159   {
160         /* Call parent execute */
161         plugin::execute();
163   $ui= get_userinfo();
164   $acla= get_permissions ($ui->dn, $ui->subtreeACL);
165   $this->acl= get_module_permission($acla, "group", $ui->dn);
166   /* Do we represent a valid group? */
167     if (!$this->is_account && $this->parent == NULL){
168       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
169         _("This 'dn' is no group.")."</b>";
170       return ($display);
171     }
173     /* Delete user from group */
174     if (isset($_POST['del_users']) && isset($_POST['members'])){
175       foreach ($_POST['members'] as $value){
176         unset ($this->members["$value"]);
177         $this->removeUser($value);
178       }
179       $this->reload();
180     }
182     /* Add objects? */
183     if (isset($_POST["edit_membership"])){
184       $this->group_dialog= TRUE;
185       $this->dialog= TRUE;
186     }
188     /* Add objects finished? */
189     if (isset($_POST["add_users_finish"]) || isset($_POST["add_users_cancel"])){
190       $this->group_dialog= FALSE;
191       $this->dialog= FALSE;
192     }
194     /* Add user to group */
195     if (isset($_POST['add_users_finish']) && isset($_POST['users'])){
196       foreach ($_POST['users'] as $value){
197         $this->members["$value"]= $this->allusers[$value];
198         asort($this->members);
199         $this->addUser($value);
200       }
201       $this->reload();
202     }
204     /* Base select dialog */
205     $once = true;
206     foreach($_POST as $name => $value){
207       if(preg_match("/^chooseBase/",$name) && $once){
208         $once = false;
209         $this->dialog = new baseSelectDialog($this->config);
210         $this->dialog->setCurrentBase($this->base);
211       }
212     }
214     /* Dialog handling */
215     if(is_object($this->dialog)){
216       /* Must be called before save_object */
217       $this->dialog->save_object();
219       if($this->dialog->isClosed()){
220         $this->dialog = false;
221       }elseif($this->dialog->isSelected()){
222         $this->base = $this->dialog->isSelected();
223         $this->dialog= false;
224       }else{
225         return($this->dialog->execute());
226       }
227     }
229    /* Assign templating stuff */
230     $smarty= get_smarty();
231     if ($this->samba3){
232       $smarty->assign("samba3", "true");
233     } else {
234       $smarty->assign("samba3", "");
235     }
237     if(search_config($this->config->data['MENU'], "nagiosaccount", "CLASS")){
238       $smarty->assign("nagios",true);
239     }else{
240       $smarty->assign("nagios",false);
241     }
242     
243     if(search_config($this->config->data['MENU'], "phoneAccount", "CLASS")){
244       $smarty->assign("pickupGroup",true);
245     }else{
246       $smarty->assign("pickupGroup",false);
247     }
249     /* Manage object add dialog */
250     if ($this->group_dialog){
252       /* Save data */
253       $gufilter= get_global("gufilter");
254       foreach( array("dselect", "regex") as $type){
255         if (isset($_POST[$type])){
256           $gufilter[$type]= $_POST[$type];
257         }
258       }
259       if (isset($_GET['search'])){
260         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
261         if ($s == "**"){
262           $s= "*";
263         }
264         $gufilter['regex']= $s;
265       }
266       $regex= preg_replace('/[*]/', ".*", $gufilter['regex']);
267       register_global("gufilter", $gufilter);
268       $this->reload();
270       /* Show dialog */
271       $smarty->assign("search_image", get_template_path('images/search.png'));
272       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
273       $smarty->assign("tree_image", get_template_path('images/tree.png'));
274       $smarty->assign("deplist", $this->config->idepartments);
275       $smarty->assign("alphabet", generate_alphabet());
276       foreach( array("dselect", "regex") as $type){
277         $smarty->assign("$type", $gufilter[$type]);
278       }
279       $smarty->assign("hint", print_sizelimit_warning());
281       $users= array();
282       foreach ($this->allusers as $key => $value){
283         if (!array_key_exists($key, $this->members)){
284           if (preg_match("/^$regex/i", $key)){
285             $users[$key]= $value;
286           }
287         }
288       }
289       $smarty->assign("users", $users);
290       $smarty->assign("apply", apply_filter());
291       $display= $smarty->fetch (get_template_path('group_objects.tpl', TRUE, dirname(__FILE__)));
292       return ($display);
293     }
295     /* Bases / Departments */
296     if (isset($_POST['base'])){
297       $this->base= $_POST['base'];
298     }
300     $smarty->assign("bases", $this->config->idepartments);
301     $smarty->assign("base_select", $this->base);
302     $smarty->assign("department", $this->department);
304     if ($this->samba3){
305       $domains= array();
306       foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
307         $domains[$name]= $name;
308       }
309       $smarty->assign("sambaDomains", $domains);
310       $smarty->assign("sambaDomainName", $this->sambaDomainName);
311       $groupTypes= array(0 => _("Samba group"), 512 => _("Domain admins"), 513 => _("Domain users"),
312           514 => _("Domain guests"));
314       /* Don't loose special groups! If not key'ed above, add it to
315          the combo box... */    
316       if ($this->groupType >= 500 && $this->groupType <= 553 && !isset($groupTypes[$this->groupType])){
317         $groupTypes[$this->groupType]= sprintf(_("Special group (%d)"), $this->groupType);
318       }
320       $smarty->assign("groupTypes", $groupTypes);
321       $smarty->assign("groupType", $this->groupType);
322     }
324     /* Members and users */
325     $smarty->assign("members", $this->members);
327     /* Checkboxes */
328     foreach (array("force_gid", "smbgroup") as $val){
329       if ($this->$val == "1"){
330         $smarty->assign("$val", "checked");
331       } else {
332         $smarty->assign("$val", "");
333       }
334     }
335     if ($this->force_gid != "1"){
336       $smarty->assign("forceMode", "disabled");
337     }else{
338       $smarty->assign("forceMode", "");
339     }
340     $smarty->assign("force_gidACL", chkacl($this->acl, "gidNumber"));
341     $smarty->assign("sambaDomainNameACL", chkacl($this->acl, "sambaDomainName"));
342     if ($this->fon_group){
343       $smarty->assign("fon_group", "checked");
344     } else {
345       $smarty->assign("fon_group", "");
346     }
347     $smarty->assign("fon_groupACL", chkacl($this->acl, "fon_group"));
349     if ($this->nagios_group){
350       $smarty->assign("nagios_group", "checked");
351     } else {
352       $smarty->assign("nagios_group", "");
353     }
354     $smarty->assign("nagios_groupACL", chkacl($this->acl, "nagios_group"));
356     /* Fields */
357     foreach (array("cn", "description", "gidNumber") as $val){
358       $smarty->assign("$val", $this->$val);
359       $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
360     }
362     /* Missing ACL's */
363     foreach (array("base", "smbgroup", "members") as $val){
364       $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
365     }
367     /* Show main page */
368     $smarty->assign("alphabet", generate_alphabet(10));
369     $smarty->assign("search_image", get_template_path('images/search.png'));
370     $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
371     $smarty->assign("tree_image", get_template_path('images/tree.png'));
372     $smarty->assign("deplist", $this->config->idepartments);
373     return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
374   }
376   function addUser($uid)
377   {
378     $this->memberUid[]= $uid;
379     $this->memberUid= array_unique($this->memberUid);
380   }
382   function removeUser($uid)
383   {
384     $temp= array();
385     foreach ($this->memberUid as $value){
386       if ($value != $uid){
387         $temp[]= $value;
388       }
389     }
390     $this->memberUid= $temp;
391   }
394   /* Reload data */
395   function reload()
396   {
397     /* Generate userlists */
398     $this->last_sorting= "invalid";
399     $this->users= array();
400     $ldap= $this->config->get_ldap_link();
401     $gufilter= get_global("gufilter");
403     $ldap->cd ($this->config->current['BASE']);
404     $ldap->cd (get_people_ou().$gufilter['dselect']);
405     $ldap->ls ("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$)))",get_people_ou().$gufilter['dselect'],array("uid", "sn", "givenName"));
406     $this->allusers= array();
407     while ($attrs= $ldap->fetch()){
408       if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
409         $this->allusers[$attrs["uid"][0]]= $attrs["sn"][0].", ".
410           $attrs["givenName"][0]." [".$attrs["uid"][0]."]";
411       } else {
412         $this->allusers[$attrs["uid"][0]]= $attrs['uid'][0];
413       }
414     }
415     natcasesort ($this->allusers);
416     reset ($this->allusers);
418     /* Fill memberlist */
419     $this->members= array();
420     foreach ($this->memberUid as $value){
421       if (isset($this->allusers[$value])){
422         $this->members[$value]= $this->allusers[$value];
423       } else {
424         $ldap->cd($this->config->current['BASE']);
425         $ldap->search("(&(objectClass=gosaAccount)(uid=".$value."))",array("uid", "sn","givenName"));
426         $attrs = $ldap->fetch();
428         if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
429           $this->allusers[$attrs["uid"][0]]= $attrs["sn"][0].", ".
430             $attrs["givenName"][0]." [".$attrs["uid"][0]."]";
431         } else {
432           $this->allusers[$attrs["uid"][0]]= $attrs['uid'][0];
433         }
434         if (isset($this->allusers[$value])){
435           $this->members[$value]= $this->allusers[$value];
436         } else {
437           $this->members[$value] = "[".$value."]";
438         }
439       }
440     }
441     asort($this->members);
442     reset($this->members);
443   }
447   function remove_from_parent()
448   {
449     plugin::remove_from_parent();
451     $ldap= $this->config->get_ldap_link();
452     $ldap->rmdir($this->dn);
453     show_ldap_error($ldap->get_error());
455     /* Delete references to object groups */
456     $ldap->cd ($this->config->current['BASE']);
457     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
458     while ($ldap->fetch()){
459       $og= new ogroup($this->config, $ldap->getDN());
460       unset($og->member[$this->dn]);
461       $og->save ();
462     }
464     /* Send signal to the world that we've done */
465     $this->handle_post_events("remove");
466   }
469   /* Save data to object */
470   function save_object()
471   {
472     /* Save additional values for possible next step */
473     if (isset($_POST['groupedit'])){
474       plugin::save_object();
476       $this->force_gid= 0;
477       $this->smbgroup= 0;
478       foreach (array("force_gid", "department", "base", "smbgroup") as $val) {
479         if (chkacl ($this->acl, "$val") == "" && isset($_POST["$val"])){
480           $this->$val= $_POST["$val"];
481         }
482       }
484       /* Save sambaDomain attribute */
485       if (chkacl ($this->acl, "sambaDomainName") == "" && $this->samba3 &&
486           isset ($_POST['sambaDomainName'])){
488         $this->sambaDomainName= $_POST['sambaDomainName'];
489         $this->groupType= $_POST['groupType'];
490       }
492       /* Save fon attribute */
493       if (chkacl ($this->acl, "fon_group") == ""){
494         if (isset ($_POST['fon_group'])){
495           $this->fon_group= TRUE;
496         } else {
497           $this->fon_group= FALSE;
498         }
499       }
500          if (chkacl ($this->acl, "nagios_group") == ""){
501         if (isset ($_POST['nagios_group'])){
502           $this->nagios_group= TRUE;
503         } else {
504           $this->nagios_group= FALSE;
505         }
506       }
507     }
508   }
511   /* Save to LDAP */
512   function save()
513   {
514     /* ID handling */
515     if ($this->force_gid == 0){
516       if ($this->saved_gidNumber != ""){
517         $this->gidNumber= $this->saved_gidNumber;
518       } else {
519         /* Calculate new, lock uids */
520         $wait= 10;
521         while (get_lock("uidnumber") != ""){
522           sleep (1);
524           /* timed out? */
525           if ($wait-- == 0){
526             break;
527           }
528         }
529         add_lock ("uidnumber", "gosa");
530         $this->gidNumber= $this->get_next_id("gidNumber");
531       }
532     }
534     plugin::save(); 
536     /* Remove objectClass for samba/phone support */
537     $tmp= array();
538     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
539       if ($this->attrs['objectClass'][$i] != 'sambaGroupMapping' &&
540           $this->attrs['objectClass'][$i] != 'sambaIdmapEntry' &&
541           $this->attrs['objectClass'][$i] != 'goFonPickupGroup' &&
542          $this->attrs['objectClass'][$i] != 'nagiosContactGroup'){
543         $tmp[]= $this->attrs['objectClass'][$i];
544       }
545     }
546     $this->attrs['objectClass']= $tmp;
547     $ldap= $this->config->get_ldap_link();
549     /* Add samba group functionality */
550     if ($this->samba3 && $this->smbgroup){
551   
552       /* Fixed undefined index ... 
553        */ 
554       $this->SID = $this->ridBase = "";
555       if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
556         $this->SID    = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
557       }else{
558         print_red(sprintf(_("No configured SID found for '%s'."),$this->sambaDomainName));
559       }
560       if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'])){
561         $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE']; 
562       }else{
563         print_red(sprintf(_("No configured RIDBASE found for '%s'."),$this->sambaDomainName));
564       }
566       $this->attrs['objectClass'][]= 'sambaGroupMapping';
567       $this->attrs['sambaGroupType']= "2";
569       /* Check if we need to create a special entry */
570       if ($this->groupType == 0){
572         if ($this->sambaSID == "" || $this->oldgroupType != $this->groupType){
573           $gidNumber= $this->gidNumber;
574           while(TRUE){
575             $sid= $this->SID."-".($gidNumber*2 + $this->ridBase+1);
576             $ldap->cd($this->config->current['BASE']);
577             $ldap->search("(sambaSID=$sid)",array("sambaSID"));
578             if ($ldap->count() == 0){
579               break;
580             }
581             $gidNumber++;
582           }
583           $this->attrs['sambaSID']= $sid;
584           $this->sambaSID= $sid;
585         }
587       } else {
588         $this->attrs['sambaSID']=$this->SID."-".$this->groupType;
589       }
591       /* User wants me to fake the idMappings? This is useful for
592          making winbind resolve the group names in a reasonable amount
593          of time in combination with larger databases. */
594       if (isset($this->config->current['SAMBAIDMAPPING']) &&
595           preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
596         $this->attrs['objectClass'][]= "sambaIdmapEntry";
597       }
599     }
601     /* Add phone functionality */
602     if ($this->fon_group){
603       $this->attrs['objectClass'][]= "goFonPickupGroup";
604     }
606     /* Add nagios functionality */
607     if ($this->nagios_group){
608         $this->attrs['objectClass'][]= "nagiosContactGroup";
609     }
611     /* Take members array */
612     if (count ($this->memberUid)){
613       $this->attrs['memberUid']= array_unique($this->memberUid);
614     }
616     /* New accounts need proper 'dn', propagate it to remaining objects */
617     if ($this->dn == 'new'){
618       $this->dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
619     }
621     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
622        new entries. So do a check first... */
623     $ldap->cat ($this->dn);
624     if ($ldap->fetch()){
625       /* Modify needs array() to remove values :-( */
626       if (!count ($this->memberUid)){
627         $this->attrs['memberUid']= array();
628       }
629       if ($this->samba3){
630         if (!$this->smbgroup){
631           $this->attrs['sambaGroupType']= array();
632           $this->attrs['sambaSID']= array();
633         }
634       }
635       $mode= "modify";
636     } else {
637       $mode= "add";
638       $ldap->cd($this->config->current['BASE']);
639       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
640     }
642     /* Write back to ldap */
643     $ldap->cd($this->dn);
644     $this->cleanup();
645     $ldap->$mode($this->attrs);
647     $ret= 0;
648     if (show_ldap_error($ldap->get_error())){
649       $ret= 1;
650     }
652     /* Remove uid lock */
653     del_lock ("uidnumber");
655     /* Post that we've done*/
656     $this->handle_post_events($mode);
658     return ($ret);
659   }
661   function check()
662   {
663     $message= array();
665     /* Permissions for that base? */
666     if ($this->base != ""){
667       $new_dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
668     } else {
669       $new_dn= $this->dn;
670     }
672     $ui= get_userinfo();
673     $acl= get_permissions ($ui->dn, $ui->subtreeACL);
674     $acl= get_module_permission($acl, "group", $ui->dn);
675     if (chkacl($this->acl, "create") != ""){
676       $message[]= _("You have no permissions to create a group on this 'Base'.");
677     }
679     /* must: cn */
680     if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
681       $message[]= "The required field 'Name' is not set.";
682     }
684     /* Check for valid input */
685     if (!is_uid($this->cn)){
686       $message[]= _("The field 'Name' contains invalid characters. Lowercase, numbers and dashes are allowed.");
687     }
689     /* Check for used 'cn' */
690     $ldap= $this->config->get_ldap_link();
691     $ldap->cd($this->config->current['BASE']);
692     $ldap->search("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",array("cn"));
693     if ($ldap->count() != 0){
695       /* New entry? */
696       if ($this->dn == 'new'){
697         $message[]= _("Value specified as 'Name' is already used.");
698       }
699       
700       /* Moved? */
701       elseif ($new_dn != $this->orig_dn){
702         $ldap->fetch();
703         if ($ldap->getDN() != $this->orig_dn){
704           $message[]= _("Value specified as 'Name' is already used.");
705         }
706       }
707     }
709     /* Check ID */
710     if ($this->force_gid == "1"){
711       if (!is_id($this->gidNumber)){
712         $message[]= _("Value specified as 'GID' is not valid.");
713       } else {
714         if ($this->gidNumber < $this->config->current['MINID']){
715           $message[]= _("Value specified as 'GID' is too small.");
716         }
718       }
719     }
721     return ($message);
722   }
724   function get_next_id($attrib)
725   {
726     $ids= array();
727     $ldap= $this->config->get_ldap_link();
729     $ldap->cd ($this->config->current['BASE']);
730     if (preg_match('/gidNumber/i', $attrib)){
731       $oc= "posixGroup";
732     } else {
733       $oc= "posixAccount";
734     }
735     $ldap->search ("(&(objectClass=$oc)($attrib=*))", array("$attrib"));
737     /* Get list of ids */
738     while ($attrs= $ldap->fetch()){
739       $ids[]= (int)$attrs["$attrib"][0];
740     }
742     /* Find out next free id near to UID_BASE */
743     for ($id= $this->config->current['UIDBASE']; $id++; $id<65000){
744       if (!in_array($id, $ids)){
745         return ($id);
746       }
747     }
749     /* Should not happen */
750     if ($id == 65000){
751       print_red(_("Too many users, can't allocate a free ID!"));
752       exit;
753     }
754   }
758 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
759 ?>