Code

0fcc62b1df9ad0fddf68fecb5d00d0e6fa78a918
[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;
38   var $OnlyShowFirstEntries =200;
40   /* attribute list for save action */
41   var $attributes= array("cn", "description", "gidNumber","memberUid","sambaGroupType","sambaSID");
42   var $objectclasses= array("top", "posixGroup");
44   function group ($config, $dn= NULL)
45   {
46     plugin::plugin ($config, $dn);
48     /* Load attributes depending on the samba version */
49     $this->samba3= ($config->current['SAMBAVERSION'] == 3);
50     $this->orig_dn= $dn;
52     /* Get member list */
53     if (isset($this->attrs['memberUid'][0])){
54       $tmp= array();
55       for ($i= 0; $i<$this->attrs['memberUid']['count']; $i++){
56         $tmp[]= $this->attrs['memberUid'][$i];
57       }
58       $this->memberUid= $tmp;
59       sort ($this->memberUid);
60     }
62     /* Save gidNumber for later use */
63     if (isset($this->attrs['gidNumber'])){
64       $this->saved_gidNumber= $this->attrs['gidNumber'][0];
65     }
67     /* Is a samba group? */
68     if (isset($this->attrs['objectClass'])){
69       if (array_search ('sambaGroupMapping', $this->attrs['objectClass']) == NULL ){
70         $this->smbgroup= FALSE;
71       } else {
72         $this->smbgroup= TRUE;
73         if (isset($this->attrs['sambaSID'])){
74           $this->sambaSID= $this->attrs['sambaSID'][0];
75         }
76       }
77       if (array_search ('goFonPickupGroup', $this->attrs['objectClass']) == NULL ){
78         $this->fon_group= FALSE;
79       } else {
80         $this->fon_group= TRUE;
81       }
82       if (array_search ('nagiosContactGroup', $this->attrs['objectClass']) == NULL ){
83         $this->nagios_group= FALSE;
84       } else {
85         $this->nagios_group= TRUE;
86       }
87     }
89     /* Set mail flag */
90     if (isset($this->attrs['objectClass']) && in_array('gosaMailAccount', $this->attrs['objectClass'])){
91       $this->has_mailAccount= TRUE;
92     }
94     /* Get samba Domain in case of samba 3 */
95     if ($this->samba3 && $this->sambaSID != ""){
96       $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
97       $ldap= $this->config->get_ldap_link();
98       $ldap->cd($this->config->current['BASE']);
99       $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase"));
100       if ($ldap->count() != 0){
101         $attrs= $ldap->fetch();
102         $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
104         /* Get domain name for SID */
105         $this->sambaDomainName= "DEFAULT";
106         foreach ($this->config->data['SERVERS']['SAMBA'] as $key => $val){
107           if ($val['SID'] == $this->SID){
108             $this->sambaDomainName= $key;
109             break;
110           }
111         }
112       } else {
113         if (isset($this->config->current['RIDBASE'])){
114           $this->sambaDomainName= "DEFAULT";
115           $this->ridBase= $this->config->current['RIDBASE'];
116           $this->SID= $this->config->current['SID'];
117         } else {
118           print_red(_("Can't find this groups SID in LDAP or in your configuration file!"));
119         }
120       }
122       /* Get group type */
123       $this->groupType= (int)substr(strrchr($this->sambaSID, "-"), 1);
124       if ($this->groupType < 500 || $this->groupType > 553){
125         $this->groupType= 0;
126       }
127       $this->oldgroupType= $this->groupType;
128     }
130     /* Get global filter config */
131     if (!is_global("gufilter")){
132       $ui= get_userinfo();
133       $base= get_base_from_people($ui->dn);
134       $gufilter= array( "dselect"       => $base,
135           "regex"           => "*");
136       register_global("gufilter", $gufilter);
137     }
138     $gufilter= get_global('gufilter');
140     $gufilter['SubSearchGroup'] = false;
141   
142     register_global('gufilter',$gufilter);
143   
144       /* Bases / Departments */
145       
146     if(isset($_SESSION['groupfilter']['depselect'])){
147       $this->base = $_SESSION['groupfilter']['depselect'];
148     }else{
149       if ($this->dn == "new"){
150         $ui= get_userinfo();
151         $this->base= dn2base($ui->dn);
152       } else {
153         $this->base= preg_replace ("/^[^,]+,[^,]+,/", "", $this->dn);
154       }
155     }
156     
158     /* This is always an account */
159     $this->is_account= TRUE;
160     $this->reload();
161   }
163   function execute()
164   {
165         /* Call parent execute */
166         plugin::execute();
168   $ui= get_userinfo();
169   $acla= get_permissions ($ui->dn, $ui->subtreeACL);
170   $this->acl= get_module_permission($acla, "group", $ui->dn);
171   /* Do we represent a valid group? */
172     if (!$this->is_account && $this->parent == NULL){
173       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
174         _("This 'dn' is no group.")."</b>";
175       return ($display);
176     }
178     /* Delete user from group */
179     if (isset($_POST['del_users']) && isset($_POST['members'])){
180       foreach ($_POST['members'] as $value){
181         unset ($this->members["$value"]);
182         $this->removeUser($value);
183       }
184       $this->reload();
185     }
187     /* Add objects? */
188     if (isset($_POST["edit_membership"])){
189       $this->group_dialog= TRUE;
190       $this->dialog= TRUE;
191     }
193     /* Add objects finished? */
194     if (isset($_POST["add_users_finish"]) || isset($_POST["add_users_cancel"])){
195       $this->group_dialog= FALSE;
196       $this->dialog= FALSE;
197     }
199     /* Add user to group */
200     if (isset($_POST['add_users_finish']) && isset($_POST['users'])){
201       foreach ($_POST['users'] as $value){
202         $this->members["$value"]= $this->allusers[$value];
203         asort($this->members);
204         $this->addUser($value);
205       }
206       $this->reload();
207     }
209     /* Base select dialog */
210     $once = true;
211     foreach($_POST as $name => $value){
212       if(preg_match("/^chooseBase/",$name) && $once){
213         $once = false;
214         $this->dialog = new baseSelectDialog($this->config);
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         $this->base = $this->dialog->isSelected();
228         $this->dialog= false;
229       }else{
230         return($this->dialog->execute());
231       }
232     }
234    /* Assign templating stuff */
235     $smarty= get_smarty();
236     if ($this->samba3){
237       $smarty->assign("samba3", "true");
238     } else {
239       $smarty->assign("samba3", "");
240     }
242     if(search_config($this->config->data['MENU'], "nagiosaccount", "CLASS")){
243       $smarty->assign("nagios",true);
244     }else{
245       $smarty->assign("nagios",false);
246     }
247     
248     if(search_config($this->config->data['MENU'], "phoneAccount", "CLASS")){
249       $smarty->assign("pickupGroup",true);
250     }else{
251       $smarty->assign("pickupGroup",false);
252     }
254     /* Manage object add dialog */
255     if ($this->group_dialog){
257       /* Save data */
258       $gufilter= get_global("gufilter");
259       foreach( array("dselect", "regex") as $type){
260         if (isset($_POST[$type])){
261           $gufilter[$type]= $_POST[$type];
262         }
263       }
264       if(isset($_POST['regex'])){
265         if(isset($_POST['SubSearchGroup'])){
266           $gufilter['SubSearchGroup'] = true;
267         }else{
268           $gufilter['SubSearchGroup'] = false;
269         }
270       }
272       if (isset($_GET['search'])){
273         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
274         if ($s == "**"){
275           $s= "*";
276         }
277         $gufilter['regex']= $s;
278       }
279       $regex= preg_replace('/[*]/', ".*", $gufilter['regex']);
280       register_global("gufilter", $gufilter);
281       $this->reload();
283       /* Show dialog */
284       $smarty->assign("search_image", get_template_path('images/search.png'));
285       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
286       $smarty->assign("tree_image", get_template_path('images/tree.png'));
287       $smarty->assign("deplist", $this->config->idepartments);
288       $smarty->assign("alphabet", generate_alphabet());
289       foreach( array("dselect", "regex","SubSearchGroup") as $type){
290         $smarty->assign("$type", $gufilter[$type]);
291       }
292       $smarty->assign("hint", print_sizelimit_warning());
294       $users= array();
295       foreach ($this->allusers as $key => $value){
296         if (!array_key_exists($key, $this->members)){
297           if (preg_match("/^$regex/i", $key)){
298             $users[$key]= $value;
299           }
300         }
301       }
302       $smarty->assign("users", $users);
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->config->idepartments);
314     $smarty->assign("base_select", $this->base);
315     $smarty->assign("department", $this->department);
317     if ($this->samba3){
318       $domains= array();
319       foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
320         $domains[$name]= $name;
321       }
322       $smarty->assign("sambaDomains", $domains);
323       $smarty->assign("sambaDomainName", $this->sambaDomainName);
324       $groupTypes= array(0 => _("Samba group"), 512 => _("Domain admins"), 513 => _("Domain users"),
325           514 => _("Domain guests"));
327       /* Don't loose special groups! If not key'ed above, add it to
328          the combo box... */    
329       if ($this->groupType >= 500 && $this->groupType <= 553 && !isset($groupTypes[$this->groupType])){
330         $groupTypes[$this->groupType]= sprintf(_("Special group (%d)"), $this->groupType);
331       }
333       $smarty->assign("groupTypes", $groupTypes);
334       $smarty->assign("groupType", $this->groupType);
335     }
337     /* Members and users */
338     $smarty->assign("members", $this->members);
340     /* Checkboxes */
341     foreach (array("force_gid", "smbgroup") as $val){
342       if ($this->$val == "1"){
343         $smarty->assign("$val", "checked");
344       } else {
345         $smarty->assign("$val", "");
346       }
347     }
348     if ($this->force_gid != "1"){
349       $smarty->assign("forceMode", "disabled");
350     }else{
351       $smarty->assign("forceMode", "");
352     }
353     $smarty->assign("force_gidACL", chkacl($this->acl, "gidNumber"));
354     $smarty->assign("sambaDomainNameACL", chkacl($this->acl, "sambaDomainName"));
355     if ($this->fon_group){
356       $smarty->assign("fon_group", "checked");
357     } else {
358       $smarty->assign("fon_group", "");
359     }
360     $smarty->assign("fon_groupACL", chkacl($this->acl, "fon_group"));
362     if ($this->nagios_group){
363       $smarty->assign("nagios_group", "checked");
364     } else {
365       $smarty->assign("nagios_group", "");
366     }
367     $smarty->assign("nagios_groupACL", chkacl($this->acl, "nagios_group"));
369     /* Fields */
370     foreach (array("cn", "description", "gidNumber") as $val){
371       $smarty->assign("$val", $this->$val);
372       $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
373     }
375     /* Missing ACL's */
376     foreach (array("base", "smbgroup", "members") as $val){
377       $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
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     /* Generate userlists */
411     $this->last_sorting= "invalid";
412     $this->users= array();
413     $ldap= $this->config->get_ldap_link();
415     $MaxUser = $this->OnlyShowFirstEntries;
417     $gufilter= get_global("gufilter");
418     $ldap->cd ($this->config->current['BASE']);
419     if($gufilter['SubSearchGroup']){
420       $ldap->cd ($gufilter['dselect']);
421       $ldap->search("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$)))",array("uid", "sn","givenName"));
422     }else{
423       $ldap->cd (get_people_ou().$gufilter['dselect']);
424       $ldap->ls ("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$)))",get_people_ou().$gufilter['dselect'],array("uid", "sn", "givenName"));
425     }
426     $this->allusers= array();
427     
428     $i = 0 ;
429     while (($attrs= $ldap->fetch()) && ($i < $MaxUser)){
430       $i ++;
431       if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
432         $this->allusers[$attrs["uid"][0]]= $attrs["sn"][0].", ".
433           $attrs["givenName"][0]." [".$attrs["uid"][0]."]";
434       } else {
435         $this->allusers[$attrs["uid"][0]]= $attrs['uid'][0];
436       }
437     }
438   
439     if(($i == $MaxUser)){
440       print_red(sprintf(_("Your search method returned more than '%s' users, only '%s' users are shown.") , $MaxUser,$MaxUser));
441     }
442     
443     natcasesort ($this->allusers);
444     reset ($this->allusers);
446     /* Fill memberlist */
447     $this->members= array();
448     foreach ($this->memberUid as $value){
449       if (isset($this->allusers[$value])){
450         $this->members[$value]= $this->allusers[$value];
451       } else {
452         $ldap->cd($this->config->current['BASE']);
453         $ldap->search("(&(objectClass=gosaAccount)(uid=".$value."))",array("uid", "sn","givenName"));
454         $attrs = $ldap->fetch();
456         if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
457           $this->allusers[$attrs["uid"][0]]= $attrs["sn"][0].", ".
458             $attrs["givenName"][0]." [".$attrs["uid"][0]."]";
459         } else {
460           $this->allusers[$attrs["uid"][0]]= $attrs['uid'][0];
461         }
462         if (isset($this->allusers[$value])){
463           $this->members[$value]= $this->allusers[$value];
464         } else {
465           $this->members[$value] = "[".$value."]";
466         }
467       }
468     }
469     asort($this->members);
470     reset($this->members);
471   }
475   function remove_from_parent()
476   {
477     plugin::remove_from_parent();
479     $ldap= $this->config->get_ldap_link();
480     $ldap->rmdir($this->dn);
481     show_ldap_error($ldap->get_error());
483     /* Delete references to object groups */
484     $ldap->cd ($this->config->current['BASE']);
485     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
486     while ($ldap->fetch()){
487       $og= new ogroup($this->config, $ldap->getDN());
488       unset($og->member[$this->dn]);
489       $og->save ();
490     }
492     /* Send signal to the world that we've done */
493     $this->handle_post_events("remove");
494   }
497   /* Save data to object */
498   function save_object()
499   {
500     /* Save additional values for possible next step */
501     if (isset($_POST['groupedit'])){
503       
504       plugin::save_object();
506       $this->force_gid= 0;
507       $this->smbgroup= 0;
508       foreach (array("force_gid", "department", "base", "smbgroup") as $val) {
509         if (chkacl ($this->acl, "$val") == "" && isset($_POST["$val"])){
510           $this->$val= $_POST["$val"];
511         }
512       }
514       /* Save sambaDomain attribute */
515       if (chkacl ($this->acl, "sambaDomainName") == "" && $this->samba3 &&
516           isset ($_POST['sambaDomainName'])){
518         $this->sambaDomainName= $_POST['sambaDomainName'];
519         $this->groupType= $_POST['groupType'];
520       }
522       /* Save fon attribute */
523       if (chkacl ($this->acl, "fon_group") == ""){
524         if (isset ($_POST['fon_group'])){
525           $this->fon_group= TRUE;
526         } else {
527           $this->fon_group= FALSE;
528         }
529       }
530          if (chkacl ($this->acl, "nagios_group") == ""){
531         if (isset ($_POST['nagios_group'])){
532           $this->nagios_group= TRUE;
533         } else {
534           $this->nagios_group= FALSE;
535         }
536       }
537     }
538   }
541   /* Save to LDAP */
542   function save()
543   {
544     /* ID handling */
545     if ($this->force_gid == 0){
546       if ($this->saved_gidNumber != ""){
547         $this->gidNumber= $this->saved_gidNumber;
548       } else {
549         /* Calculate new, lock uids */
550         $wait= 10;
551         while (get_lock("uidnumber") != ""){
552           sleep (1);
554           /* timed out? */
555           if ($wait-- == 0){
556             break;
557           }
558         }
559         add_lock ("uidnumber", "gosa");
560         $this->gidNumber= $this->get_next_id("gidNumber");
561       }
562     }
564     plugin::save(); 
566     /* Remove objectClass for samba/phone support */
567     $tmp= array();
568     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
569       if ($this->attrs['objectClass'][$i] != 'sambaGroupMapping' &&
570           $this->attrs['objectClass'][$i] != 'sambaIdmapEntry' &&
571           $this->attrs['objectClass'][$i] != 'goFonPickupGroup' &&
572          $this->attrs['objectClass'][$i] != 'nagiosContactGroup'){
573         $tmp[]= $this->attrs['objectClass'][$i];
574       }
575     }
576     $this->attrs['objectClass']= $tmp;
577     $ldap= $this->config->get_ldap_link();
579     /* Add samba group functionality */
580     if ($this->samba3 && $this->smbgroup){
581   
582       /* Fixed undefined index ... 
583        */ 
584       $this->SID = $this->ridBase = "";
585       if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
586         $this->SID    = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
587       }else{
588         print_red(sprintf(_("No configured SID found for '%s'."),$this->sambaDomainName));
589       }
590       if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'])){
591         $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE']; 
592       }else{
593         print_red(sprintf(_("No configured RIDBASE found for '%s'."),$this->sambaDomainName));
594       }
596       $this->attrs['objectClass'][]= 'sambaGroupMapping';
597       $this->attrs['sambaGroupType']= "2";
599       /* Check if we need to create a special entry */
600       if ($this->groupType == 0){
602         if ($this->sambaSID == "" || $this->oldgroupType != $this->groupType){
603           $gidNumber= $this->gidNumber;
604           while(TRUE){
605             $sid= $this->SID."-".($gidNumber*2 + $this->ridBase+1);
606             $ldap->cd($this->config->current['BASE']);
607             $ldap->search("(sambaSID=$sid)",array("sambaSID"));
608             if ($ldap->count() == 0){
609               break;
610             }
611             $gidNumber++;
612           }
613           $this->attrs['sambaSID']= $sid;
614           $this->sambaSID= $sid;
615         }
617       } else {
618         $this->attrs['sambaSID']=$this->SID."-".$this->groupType;
619       }
621       /* User wants me to fake the idMappings? This is useful for
622          making winbind resolve the group names in a reasonable amount
623          of time in combination with larger databases. */
624       if (isset($this->config->current['SAMBAIDMAPPING']) &&
625           preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
626         $this->attrs['objectClass'][]= "sambaIdmapEntry";
627       }
629     }
631     /* Add phone functionality */
632     if ($this->fon_group){
633       $this->attrs['objectClass'][]= "goFonPickupGroup";
634     }
636     /* Add nagios functionality */
637     if ($this->nagios_group){
638         $this->attrs['objectClass'][]= "nagiosContactGroup";
639     }
641     /* Take members array */
642     if (count ($this->memberUid)){
643       $this->attrs['memberUid']= array_unique($this->memberUid);
644     }
646     /* New accounts need proper 'dn', propagate it to remaining objects */
647     if ($this->dn == 'new'){
648       $this->dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
649     }
651     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
652        new entries. So do a check first... */
653     $ldap->cat ($this->dn);
654     if ($ldap->fetch()){
655       /* Modify needs array() to remove values :-( */
656       if (!count ($this->memberUid)){
657         $this->attrs['memberUid']= array();
658       }
659       if ($this->samba3){
660         if (!$this->smbgroup){
661           $this->attrs['sambaGroupType']= array();
662           $this->attrs['sambaSID']= array();
663         }
664       }
665       $mode= "modify";
666     } else {
667       $mode= "add";
668       $ldap->cd($this->config->current['BASE']);
669       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
670     }
672     /* Write back to ldap */
673     $ldap->cd($this->dn);
674     $this->cleanup();
675     $ldap->$mode($this->attrs);
677     $ret= 0;
678     if (show_ldap_error($ldap->get_error())){
679       $ret= 1;
680     }
682     /* Remove uid lock */
683     del_lock ("uidnumber");
685     /* Post that we've done*/
686     $this->handle_post_events($mode);
688     return ($ret);
689   }
691   function check()
692   {
693     $message= array();
695     /* Permissions for that base? */
696     if ($this->base != ""){
697       $new_dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
698     } else {
699       $new_dn= $this->dn;
700     }
702     $ui= get_userinfo();
703     $acl= get_permissions ($ui->dn, $ui->subtreeACL);
704     $acl= get_module_permission($acl, "group", $ui->dn);
705     if (chkacl($this->acl, "create") != ""){
706       $message[]= _("You have no permissions to create a group on this 'Base'.");
707     }
709     /* must: cn */
710     if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
711       $message[]= "The required field 'Name' is not set.";
712     }
714     /* Check for valid input */
715     if (!is_uid($this->cn)){
716       $message[]= _("The field 'Name' contains invalid characters. Lowercase, numbers and dashes are allowed.");
717     }
719     /* Check for used 'cn' */
720     $ldap= $this->config->get_ldap_link();
721     $ldap->cd($this->config->current['BASE']);
722     $ldap->search("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",array("cn"));
723     if ($ldap->count() != 0){
725       /* New entry? */
726       if ($this->dn == 'new'){
727         $message[]= _("Value specified as 'Name' is already used.");
728       }
729       
730       /* Moved? */
731       elseif ($new_dn != $this->orig_dn){
732         $ldap->fetch();
733         if ($ldap->getDN() != $this->orig_dn){
734           $message[]= _("Value specified as 'Name' is already used.");
735         }
736       }
737     }
739     /* Check ID */
740     if ($this->force_gid == "1"){
741       if (!is_id($this->gidNumber)){
742         $message[]= _("Value specified as 'GID' is not valid.");
743       } else {
744         if ($this->gidNumber < $this->config->current['MINID']){
745           $message[]= _("Value specified as 'GID' is too small.");
746         }
748       }
749     }
751     return ($message);
752   }
754   function get_next_id($attrib)
755   {
756     $ids= array();
757     $ldap= $this->config->get_ldap_link();
759     $ldap->cd ($this->config->current['BASE']);
760     if (preg_match('/gidNumber/i', $attrib)){
761       $oc= "posixGroup";
762     } else {
763       $oc= "posixAccount";
764     }
765     $ldap->search ("(&(objectClass=$oc)($attrib=*))", array("$attrib"));
767     /* Get list of ids */
768     while ($attrs= $ldap->fetch()){
769       $ids[]= (int)$attrs["$attrib"][0];
770     }
772     /* Find out next free id near to UID_BASE */
773     for ($id= $this->config->current['UIDBASE']; $id++; $id<65000){
774       if (!in_array($id, $ids)){
775         return ($id);
776       }
777     }
779     /* Should not happen */
780     if ($id == 65000){
781       print_red(_("Too many users, can't allocate a free ID!"));
782       exit;
783     }
784   }
788 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
789 ?>