Code

Updated trustModes
[gosa.git] / gosa-core / include / class_acl.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 /*! \brief ACL management plugin */ 
24 class acl extends plugin
25 {
26   /* Definitions */
27   var $plHeadline= "Access control";
28   var $plDescription= "Manage access control lists";
30   /* attribute list for save action */
31   var $attributes= array('gosaAclEntry');
32   var $objectclasses= array('gosaAcl');
34   /* Helpers */
35   var $dialogState= "head";
36   var $gosaAclEntry= array();
37   var $aclType= "";
38   var $aclObject= "";
39   var $aclContents= array();
40   var $target= "group";
41   var $aclTypes= array();
42   var $aclObjects= array();
43   var $aclFilter= "";
44   var $aclMyObjects= array();
45   var $users= array();
46   var $roles= array();
47   var $groups= array();
48   var $recipients= array();
49   var $isContainer= FALSE;
50   var $currentIndex= 0;
51   var $wasNewEntry= FALSE;
52   var $ocMapping= array();
53   var $savedAclContents= array();
54   var $myAclObjects = array();
55   var $acl_category = "acl/";
57    var $list =NULL;
59   function acl (&$config, $parent, $dn= NULL)
60   {
61     /* Include config object */
62     plugin::plugin($config, $dn);
64     /* Load ACL's */
65     $this->gosaAclEntry= array();
66     if (isset($this->attrs['gosaAclEntry'])){
67       for ($i= 0; $i<$this->attrs['gosaAclEntry']['count']; $i++){
68         $acl= $this->attrs['gosaAclEntry'][$i];
69         $this->gosaAclEntry= array_merge($this->gosaAclEntry, acl::explodeACL($acl));
70       }
71     }
72     ksort($this->gosaAclEntry);
74     /* Save parent - we've to know more about it than other plugins... */
75     $this->parent= &$parent;
77     /* Container? */
78     if (preg_match('/^(o|ou|c|l|dc)=/i', $dn)){
79       $this->isContainer= TRUE;
80     }
82     /* Users */
83     $ui= get_userinfo();
84     $tag= $ui->gosaUnitTag;
85     $ldap= $config->get_ldap_link();
86     $ldap->cd($config->current['BASE']);
87     if ($tag == ""){
88       $ldap->search('(objectClass=gosaAccount)', array('uid', 'cn'));
89     } else {
90       $ldap->search('(&(objectClass=gosaAccount)(gosaUnitTag='.$tag.'))', array('uid', 'cn'));
91     }
92     while ($attrs= $ldap->fetch()){
94       // Allow objects without cn to be listed without causing an error.
95       if(!isset($attrs['cn'][0]) && isset($attrs['uid'][0])){
96         $this->users['U:'.$attrs['dn']]=  $attrs['uid'][0];
97       }elseif(!isset($attrs['uid'][0]) && isset($attrs['cn'][0])){
98         $this->users['U:'.$attrs['dn']]=  $attrs['cn'][0];
99       }elseif(!isset($attrs['uid'][0]) && !isset($attrs['cn'][0])){
100         $this->users['U:'.$attrs['dn']]= $attrs['dn'];
101       }else{
102         $this->users['U:'.$attrs['dn']]= $attrs['cn'][0].' ['.$attrs['uid'][0].']';
103       }
105     }
106     ksort($this->users);
108     /* Groups */
109     $ldap->cd($config->current['BASE']);
110 #    if ($tag == ""){
111       $ldap->search('(objectClass=posixGroup)', array('cn', 'description'));
112 #    } else {
113 #      $ldap->search('(&(objectClass=posixGroup)(gosaUnitTag='.$tag.'))', array('cn', 'description'));
114 #    }
115     while ($attrs= $ldap->fetch()){
116       $dsc= "";
117       if (isset($attrs['description'][0])){
118         $dsc= $attrs['description'][0];
119       }
120       $this->groups['G:'.$attrs['dn']]= $attrs['cn'][0].' ['.$dsc.']';
121     }
122     $this->groups['G:*']= _("All users");
123     ksort($this->groups);
125     /* Roles */
126     $ldap->cd($config->current['BASE']);
127 #    if ($tag == ""){
128       $ldap->search('(objectClass=gosaRole)', array('cn', 'description','gosaAclTemplate','dn'));
129 #    } else {
130 #     $ldap->search('(&(objectClass=gosaRole)(gosaUnitTag='.$tag.'))', array('cn', 'description','gosaAclTemplate','dn'));
131 #    }
132     while ($attrs= $ldap->fetch()){
133       $dsc= "";
134       if (isset($attrs['description'][0])){
135         $dsc= $attrs['description'][0];
136       }
138       $role_id = $attrs['dn'];
140       $this->roles[$role_id]['acls'] =array();
141       for ($i= 0; $i < $attrs['gosaAclTemplate']['count']; $i++){
142         $acl= $attrs['gosaAclTemplate'][$i];
143         $this->roles[$role_id]['acls'] = array_merge($this->roles[$role_id]['acls'],acl::explodeACL($acl));
144       }
145       $this->roles[$role_id]['description'] = $dsc;
146       $this->roles[$role_id]['cn'] = $attrs['cn'][0];
147     }
149     /* Objects */
150     $tmp= session::global_get('plist');
151     $plist= $tmp->info;
152     $cats = array();
153     if (isset($this->parent) && $this->parent !== NULL){
154       $oc= array();
155       foreach ($this->parent->by_object as $key => $obj){
156         $oc= array_merge($oc, $obj->objectclasses);
157         if(isset($obj->acl_category)){
158                                         $tmp= str_replace("/","",$obj->acl_category);
159           $cats[$tmp] = $tmp;
160         }
161       }
162       if (in_array_ics('organizationalUnit', $oc)){
163         $this->isContainer= TRUE;
164       }
165     } else {
166       $oc=  $this->attrs['objectClass'];
167     }
169     /* Extract available categories from plugin info list */
170     foreach ($plist as $class => $acls){
172       /* Only feed categories */
173       if (isset($acls['plCategory'])){
175         /* Walk through supplied list and feed only translated categories */
176         foreach($acls['plCategory'] as $idx => $data){
178           /* Non numeric index means -> base object containing more informations */
179           if (preg_match('/^[0-9]+$/', $idx)){
181             if (!isset($this->ocMapping[$data])){
182               $this->ocMapping[$data]= array();
183               $this->ocMapping[$data][]= '0';
184             }
186             if(isset($cats[$data])){
187               $this->myAclObjects[$data.'/'.$class]= $acls['plDescription'];
188             }
189             $this->ocMapping[$data][]= $class;
190           } else {
191             if (!isset($this->ocMapping[$idx])){
192               $this->ocMapping[$idx]= array();
193               $this->ocMapping[$idx][]= '0';
194             }
195             $this->ocMapping[$idx][]= $class;
196             $this->aclObjects[$idx]= $data['description'];
198             /* Additionally filter the classes we're interested in in "self edit" mode */
199             if (is_array($data['objectClass'])){
200               foreach($data['objectClass'] as $objectClass){
201                 if (in_array_ics($objectClass, $oc)){
202                   $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
203                   break;
204                 }
205               }
206             } else {
207               if (in_array_ics($data['objectClass'], $oc)){
208                 $this->myAclObjects[$idx.'/'.$class]= $acls['plDescription'];
209               }
210             }
211           }
213         }
214       }
215     }
216     $this->aclObjects['all']= '*&nbsp;'._("All categories");
217     $this->ocMapping['all']= array('0' => 'all');
219     /* Sort categories */
220     asort($this->aclObjects);
222     /* Fill acl types */
223     if ($this->isContainer){
224       $this->aclTypes= array("reset" => _("Reset ACLs"),
225                              "one" => _("One level"),
226                              "base" => _("Current object"),
227                              "sub" => _("Complete subtree"),
228                              "psub" => _("Complete subtree (permanent)"),
229                              "role" => _("Use ACL defined in role"));
230     } else {
231       $this->aclTypes= array("base" => _("Current object"),
232           "role" => _("Use ACL defined in role"));
233     }
234     asort($this->aclTypes);
235     $this->targets= array("user" => _("Users"), "group" => _("Groups"));
236     asort($this->targets);
238     /* Finally - we want to get saved... */
239     $this->is_account= TRUE;
241     $this->updateList();
242   }
244     
245   function updateList()
246   {
247       if(!$this->list){ 
248           $this->list = new sortableListing($this->gosaAclEntry,array(),TRUE);
249           $this->list->setDeleteable(true);
250           $this->list->setEditable(true);
251           $this->list->setColspecs(array('*'));
252           $this->list->setWidth("100%");
253           $this->list->setHeight("400px");
254           $this->list->setAcl("rwcdm");
255           $this->list->setHeader(array(_("Member"),_("Permissions"),_("Type")));
256       }
258  
259     // Add ACL entries to the listing 
260     $lData = array();
261     foreach($this->gosaAclEntry as $id => $entry){
262        $lData[] = $this->convertForListing($entry);
263     }    
264     $this->list->setListData($this->gosaAclEntry, $lData);
265   }
266    
267     
268   function convertForListing($entry)
269   {
270     $member = implode($entry['members'],", ");
271     $acl = implode(array_keys($entry['acl']),", ");
272     $type = implode(array_keys($entry['acl']),", ");
273     return(array('data' => array($member, $acl, $this->aclTypes[$entry['type']])));
274   }
276   
278   function execute()
279   {
280     /* Call parent execute */
281     plugin::execute();
283     $tmp= session::global_get('plist');
284     $plist= $tmp->info;
286     /* Handle posts */
287     if (isset($_POST['new_acl'])){
288       $this->dialogState= 'create';
289       $this->dialog= TRUE;
290       $this->currentIndex= count($this->gosaAclEntry);
291       $this->loadAclEntry(TRUE);
292     }
294     $new_acl= array();
295     $aclDialog= FALSE;
296     $firstedit= FALSE;
298     // Get listing actions. Delete or Edit.
299     $this->list->save_object();
300     $lAction = $this->list->getAction();
301     $this->gosaAclEntry = $this->list->getMaintainedData();
303     /* Act on HTML post and gets here.
304      */
305     if($lAction['action'] == "edit"){
306         $this->currentIndex = $this->list->getKey($lAction['targets'][0]);
307         $this->dialogState= 'create';
308         $firstedit= TRUE;
309         $this->dialog= TRUE;
310         $this->loadAclEntry();
311     }
313     foreach($_POST as $name => $post){
315       /* Actions... */
316       if (preg_match('/^acl_edit_[0-9]*$/', $name)){
317         $this->dialogState= 'create';
318         $firstedit= TRUE;
319         $this->dialog= TRUE;
320         $this->currentIndex= preg_replace('/^acl_edit_([0-9]*)$/', '\1', $name);
321         $this->loadAclEntry();
322         continue;
323       }
325       if (preg_match('/^cat_edit_.*$/', $name)){
326         $this->aclObject= preg_replace('/^cat_edit_(.*)$/', '\1', $name);
327         $this->dialogState= 'edit';
328         foreach ($this->ocMapping[$this->aclObject] as $oc){
329           if (isset($this->aclContents[$oc])){
330             $this->savedAclContents[$oc]= $this->aclContents[$oc];
331           }
332         }
333         continue;
334       }
336       /* Only handle posts, if we allowed to modify ACLs */
337       if(!$this->acl_is_writeable("")){
338         continue;
339       }
341       if (preg_match('/^acl_del_[0-9]*$/', $name)){
342         unset($this->gosaAclEntry[preg_replace('/^acl_del_([0-9]*)$/', '\1', $name)]);
343         continue;
344       }
346       if (preg_match('/^cat_del_.*$/', $name)){
347         $idx= preg_replace('/^cat_del_(.*)$/', '\1', $name);
348         foreach ($this->ocMapping[$idx] as $key){
349           if(isset($this->aclContents[$idx]))
350             unset($this->aclContents[$idx]);
351           if(isset($this->aclContents["$idx/$key"]))
352             unset($this->aclContents["$idx/$key"]);
353         }
354         continue;
355       }
357       /* ACL saving... */
358       if (preg_match('/^acl_.*_[^xy]$/', $name)){
359         list($dummy, $object, $attribute, $value)= explode('_', $name);
361         /* Skip for detection entry */
362         if ($object == 'dummy') {
363           continue;
364         }
366         /* Ordinary ACLs */
367         if (!isset($new_acl[$object])){
368           $new_acl[$object]= array();
369         }
370         if (isset($new_acl[$object][$attribute])){
371           $new_acl[$object][$attribute].= $value;
372         } else {
373           $new_acl[$object][$attribute]= $value;
374         }
375       }
377       // Remember the selected ACL role.
378       if(isset($_POST['selected_role']) && $_POST['aclType'] == 'role'){
379         $this->aclContents = "";
380         $this->aclContents = base64_decode($_POST['selected_role']);
381       }
382     }
384     if(isset($_POST['acl_dummy_0_0_0'])){
385       $aclDialog= TRUE;
386     }
388     if($this->acl_is_writeable("")){
389       
390       /* Only be interested in new acl's, if we're in the right _POST place */
391       if ($aclDialog && $this->aclObject != "" && is_array($this->ocMapping[$this->aclObject])){
393         foreach ($this->ocMapping[$this->aclObject] as $oc){
395           if(isset($this->aclContents[$oc]) && is_array($this->aclContents)){
396             unset($this->aclContents[$oc]);
397           }elseif(isset($this->aclContents[$this->aclObject.'/'.$oc]) && is_array($this->aclContents)){
398             unset($this->aclContents[$this->aclObject.'/'.$oc]);
399           }else{
400 #          trigger_error("Huhm?");
401           }
402           if (isset($new_acl[$oc]) && is_array($new_acl)){
403             $this->aclContents[$oc]= $new_acl[$oc];
404           }
405           if (isset($new_acl[$this->aclObject.'/'.$oc]) && is_array($new_acl)){
406             $this->aclContents[$this->aclObject.'/'.$oc]= $new_acl[$this->aclObject.'/'.$oc];
407           }
408         }
409       }
411       /* Save new acl in case of base edit mode */
412       if ($this->aclType == 'base' && !$firstedit){
413         $this->aclContents= $new_acl;
414       }
415     }
417     /* Cancel new acl? */
418     if (isset($_POST['cancel_new_acl'])){
419       $this->dialogState= 'head';
420       $this->dialog= FALSE;
421       if ($this->wasNewEntry){
422         unset ($this->gosaAclEntry[$this->currentIndex]);
423       }
424     }
426     /* Save common values */
427     if($this->acl_is_writeable("")){
428       foreach (array("aclType","aclFilter", "aclObject", "target") as $key){
429         if (isset($_POST[$key])){
430           $this->$key= validate($_POST[$key]);
431         }
432       }
433     }
435     /* Store ACL in main object? */
436     if (isset($_POST['submit_new_acl'])){
437       $this->gosaAclEntry[$this->currentIndex]['type']= $this->aclType;
438       $this->gosaAclEntry[$this->currentIndex]['members']= $this->recipients;
439       $this->gosaAclEntry[$this->currentIndex]['acl']= $this->aclContents;
440       $this->gosaAclEntry[$this->currentIndex]['filter']= $this->aclFilter;
441       $this->dialogState= 'head';
442       $this->dialog= FALSE;
443     }
445     /* Cancel edit acl? */
446     if (isset($_POST['cancel_edit_acl'])){
447       $this->dialogState= 'create';
448       foreach ($this->ocMapping[$this->aclObject] as $oc){
449         if (isset($this->savedAclContents[$oc])){
450           $this->aclContents[$oc]= $this->savedAclContents[$oc];
451         }
452       }
453     }
455     /* Save edit acl? */
456     if (isset($_POST['submit_edit_acl'])){
457       $this->dialogState= 'create';
458     }
460     /* Add acl? */
461     if (isset($_POST['add_acl']) && $_POST['aclObject'] != ""){
462       $this->dialogState= 'edit';
463       $this->savedAclContents= array();
464       foreach ($this->ocMapping[$this->aclObject] as $oc){
465         if (isset($this->aclContents[$oc])){
466           $this->savedAclContents[$oc]= $this->aclContents[$oc];
467         }
468       }
469     }
471     /* Add to list? */
472     if (isset($_POST['add']) && isset($_POST['source'])){
473       foreach ($_POST['source'] as $key){
474         if ($this->target == 'user'){
475           $this->recipients[$key]= $this->users[$key];
476         }
477         if ($this->target == 'group'){
478           $this->recipients[$key]= $this->groups[$key];
479         }
480       }
481       ksort($this->recipients);
482     }
484     /* Remove from list? */
485     if (isset($_POST['del']) && isset($_POST['recipient'])){
486       foreach ($_POST['recipient'] as $key){
487           unset($this->recipients[$key]);
488       }
489     }
491     /* Create templating instance */
492     $smarty= get_smarty();
493     $smarty->assign("usePrototype", "true");
494     $smarty->assign("acl_readable",$this->acl_is_readable(""));
495     if(!$this->acl_is_readable("")){
496       return ($smarty->fetch (get_template_path('acl.tpl')));
497     }
499     if ($this->dialogState == 'head'){
500       $this->updateList();
501       $smarty->assign("aclList", $this->list->render());
502     }
504     if ($this->dialogState == 'create'){
506       $aclList= new divSelectBox("aclList");
507       $aclList->SetHeight(150);
509       // Create a map of all used sections, this allows us to simply hide the remove button 
510       //  if no acl is configured for the given section 
511       // e.g. ';all;department/country;users/user;
512       $usedList = ";".implode(array_keys($this->aclContents),';').";";
514       /* Add settings for all categories to the (permanent) list */
515       foreach ($this->aclObjects as $section => $dsc){
516         $summary= "";
517         foreach($this->ocMapping[$section] as $oc){
518           if (isset($this->aclContents[$oc]) && count($this->aclContents[$oc]) && isset($this->aclContents[$oc][0]) &&
519               $this->aclContents[$oc][0] != ""){
521             $summary.= "$oc, ";
522             continue;
523           }
524           if (isset($this->aclContents["$section/$oc"]) && count($this->aclContents["$section/$oc"])){
525             $summary.= "$oc, ";
526             continue;
527           }
528           if (isset($this->aclContents[$oc]) && !isset($this->aclContents[$oc][0]) && count($this->aclContents[$oc])){
529             $summary.= "$oc, ";
530           }
531         }
533         /* Set summary... */
534         if ($summary == ""){
535           $summary= '<i>'._("No ACL settings for this category!").'</i>';
536         } else {
537           $summary= sprintf(_("Contains ACLs for these objects: %s"), preg_replace('/, $/', '', $summary));
538         }
540         $actions ="";
541         if($this->acl_is_readable("")){
542           $actions.= image('images/lists/edit.png','cat_edit_'.$section, msgPool::editButton(_("category ACL")));
543         }
544         if($this->acl_is_removeable() && preg_match("/;".$section."(;|\/)/", $usedList)){
545           $actions.= image('images/lists/trash.png','cat_del_'.$section, msgPool::delButton(_("category ACL")));
546         }   
548         $field1= array("string" => $dsc, "attach" => "style='width:100px'");
549         $field2= array("string" => $summary);
550         $field3= array("string" => $actions, "attach" => "style='border-right:0px;width:50px'");
551         $aclList->AddEntry(array($field1, $field2, $field3));
552       }
554       $smarty->assign("aclList", $aclList->DrawList());
555     
556       $smarty->assign("aclType", $this->aclType);
557       $smarty->assign("aclFilter", $this->aclFilter);
558       $smarty->assign("aclTypes", $this->aclTypes);
559       $smarty->assign("target", $this->target);
560       $smarty->assign("targets", $this->targets);
562       /* Assign possible target types */
563       $smarty->assign("targets", $this->targets);
564       foreach ($this->attributes as $attr){
565         $smarty->assign($attr, $this->$attr);
566       }
569       /* Generate list */
570       $tmp= array();
571       if ($this->target == "group" && !isset($this->recipients["G:*"])){
572         $tmp["G:*"]= _("All users");
573       }
574       foreach (array("user" => "users", "group" => "groups") as $field => $arr){
575         if ($this->target == $field){
576           foreach ($this->$arr as $key => $value){
577             if (!isset($this->recipients[$key])){
578               $tmp[$key]= $value;
579             }
580           }
581         }
582       }
583       $smarty->assign('sources', $tmp);
584       $smarty->assign('recipients', $this->recipients);
586       /* Acl selector if scope is base */
587       if ($this->aclType == 'base'){
588         $smarty->assign('aclSelector', $this->buildAclSelector($this->myAclObjects));
589       }
591       /* Role selector if scope is base */
592       if ($this->aclType == 'role'){
593         $smarty->assign('roleSelector', "Role selector");#, $this->buildRoleSelector($this->myAclObjects));
594         $smarty->assign('roleSelector', $this->buildRoleSelector($this->roles));
595       }
596     }
598     if ($this->dialogState == 'edit'){
599       $smarty->assign('headline', sprintf(_("Edit ACL for '%s' - scope is '%s'"), $this->aclObjects[$this->aclObject], $this->aclTypes[$this->aclType]));
601       /* Collect objects for selected category */
602       foreach ($this->ocMapping[$this->aclObject] as $idx => $class){
603         if ($idx == 0){
604           continue;
605         }
606         $aclObjects[$this->aclObject.'/'.$class]= $plist[$class]['plDescription'];
607       }
608       if ($this->aclObject == 'all'){
609         $aclObjects['all']= _("All objects in current subtree");
610       }
612       /* Role selector if scope is base */
613       if ($this->aclType == 'role'){
614         $smarty->assign('roleSelector', $this->buildRoleSelector($this->roles));
615       } else {
616         $smarty->assign('aclSelector', $this->buildAclSelector($aclObjects));
617       }
618     }
620     /* Show main page */
621     $smarty->assign("dialogState", $this->dialogState);
622    
623     /* Assign acls */ 
624     $smarty->assign("acl_createable",$this->acl_is_createable());
625     $smarty->assign("acl_writeable" ,$this->acl_is_writeable(""));
626     $smarty->assign("acl_readable"  ,$this->acl_is_readable(""));
627     $smarty->assign("acl_removeable",$this->acl_is_removeable());
629     return ($smarty->fetch (get_template_path('acl.tpl')));
630   }
633   function sort_by_priority($list)
634   {
635     $tmp= session::global_get('plist');
636     $plist= $tmp->info;
637     asort($plist);
638     $newSort = array();
640     foreach($list as $name => $translation){
641       $na  =  preg_replace("/^.*\//","",$name);
642       $prio = 0;
643       if(isset($plist[$na]['plPriority'])){
644         $prio=  $plist[$na]['plPriority'] ;
645       }
647       $newSort[$name] = $prio;
648     }
650     asort($newSort);
652     $ret = array();
653     foreach($newSort as $name => $prio){
654       $ret[$name] = $list[$name];
655     }
656     return($ret);
657   }
660   function buildRoleSelector($list)
661   {
662     $D_List =new divSelectBox("Acl_Roles");
663  
664     $selected = $this->aclContents;
665     if(!is_string($this->aclContents) || !isset($list[$this->aclContents])){
666       $selected = key($list);
667     }
669     $str ="";
670     foreach($list as $dn => $values){
672       if($dn == $selected){    
673         $option = "<input type='radio' name='selected_role' value='".base64_encode($dn)."' checked>";
674       }else{
675         $option = "<input type='radio' name='selected_role' value='".base64_encode($dn)."'>";
676       }
677  
678       $field1 = array("string" => $option) ;
679       $field2 = array("string" => $values['cn'], "attach" => "style='width:200px;'") ;
680       $field3 = array("string" => $values['description'],"attach" => "style='border-right:0px;'") ;
682       $D_List->AddEntry(array($field1,$field2,$field3));
683     }
684     return($D_List->DrawList());
685   } 
688   function buildAclSelector($list)
689   {
690     $display= "<input type='hidden' name='acl_dummy_0_0_0' value='1'>";
691     $cols= 3;
692     $tmp= session::global_get('plist');
693     $plist= $tmp->info;
694     asort($plist);
696     /* Add select all/none buttons */
697     $style = "style='width:100px;'";
699     if($this->acl_is_writeable("")){
700       $display .= "<button type='button' ".$style." name='toggle_all_create' onClick=\"acl_toggle_all('_0_c$');\" >Toggle C</button>";
701       $display .= "<button type='button' ".$style." name='toggle_all_move'   onClick=\"acl_toggle_all('_0_m$');\" >Toggle M</button>";
702       $display .= "<button type='button' ".$style." name='toggle_all_remove' onClick=\"acl_toggle_all('_0_d$');\" >Toggle D</button> - ";
703       $display .= "<button type='button' ".$style." name='toggle_all_read'   onClick=\"acl_toggle_all('_0_r$');\" >Toggle R</button>";
704       $display .= "<button type='button' ".$style." name='toggle_all_write'  onClick=\"acl_toggle_all('_0_w$');\" >Toggle W</button> - ";
706       $display .= "<button type='button' ".$style." name='toggle_all_sub_read'  onClick=\"acl_toggle_all('[^0]_r$');\" >R+</button>";
707       $display .= "<button type='button' ".$style." name='toggle_all_sub_write'  onClick=\"acl_toggle_all('[^0]_w$');\" >W+</button>";
709       $display .= "<br>";
711       $style = "style='width:50px;'";
712       $display .= "<button type='button' ".$style." name='set_true_all_create' onClick=\"acl_set_all('_0_c$',true);\" >C+</button>";
713       $display .= "<button type='button' ".$style." name='set_false_all_create' onClick=\"acl_set_all('_0_c$',false);\" >C-</button>";
714       $display .= "<button type='button' ".$style." name='set_true_all_move' onClick=\"acl_set_all('_0_m$',true);\" >M+</button>";
715       $display .= "<button type='button' ".$style." name='set_false_all_move' onClick=\"acl_set_all('_0_m$',false);\" >M-</button>";
716       $display .= "<button type='button' ".$style." name='set_true_all_remove' onClick=\"acl_set_all('_0_d$',true);\" >D+</button>";
717       $display .= "<button type='button' ".$style." name='set_false_all_remove' onClick=\"acl_set_all('_0_d$',false);\" >D-</button> - ";
718       $display .= "<button type='button' ".$style." name='set_true_all_read' onClick=\"acl_set_all('_0_r$',true);\" >R+</button>";
719       $display .= "<button type='button' ".$style." name='set_false_all_read' onClick=\"acl_set_all('_0_r$',false);\" >R-</button>";
720       $display .= "<button type='button' ".$style." name='set_true_all_write' onClick=\"acl_set_all('_0_w$',true);\" >W+</button>";
721       $display .= "<button type='button' ".$style." name='set_false_all_write' onClick=\"acl_set_all('_0_w$',false);\" >W-</button> - ";
723       $display .= "<button type='button' ".$style." name='set_true_all_read' onClick=\"acl_set_all('[^0]_r$',true);\" >R+</button>";
724       $display .= "<button type='button' ".$style." name='set_false_all_read' onClick=\"acl_set_all('[^0]_r$',false);\" >R-</button>";
725       $display .= "<button type='button' ".$style." name='set_true_all_write' onClick=\"acl_set_all('[^0]_w$',true);\" >W+</button>";
726       $display .= "<button type='button' ".$style." name='set_false_all_write' onClick=\"acl_set_all('[^0]_w$',false);\" >W-</button>";
727     }
729     /* Build general objects */
730     $list =$this->sort_by_priority($list);
731     foreach ($list as $key => $name){
733       /* Create sub acl if it does not exist */
734       if (!isset($this->aclContents[$key])){
735         $this->aclContents[$key]= array();
736       }
737       if(!isset($this->aclContents[$key][0])){
738         $this->aclContents[$key][0]= '';
739       }
741       $currentAcl= $this->aclContents[$key];
743       /* Get the overall plugin acls 
744        */
745       $overall_acl ="";
746       if(isset($currentAcl[0])){
747         $overall_acl = $currentAcl[0];
748       }
750       // Detect configured plugins
751       $expand = count($currentAcl) > 1 || $currentAcl[0] != "";
753       /* Object header */
754                         $tname= preg_replace("/[^a-z0-9]/i","_",$name);
756       if($expand){
757         $back_color = "#C8C8FF";
758       }else{
759         $back_color = "#C8C8C8";
760       }
762       if(isset($_SERVER['HTTP_USER_AGENT']) && 
763           (preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) || 
764           (preg_match("/presto/i",$_SERVER['HTTP_USER_AGENT']))) {
765         $display.= "\n<table summary='{$name}' style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
766           "\n  <tr>".
767           "\n    <td style='background-color:{$back_color};height:1.8em;' colspan=".($cols-1)."><b>"._("Object").": $name</b></td>".
768           "\n    <td align='right' style='background-color:{$back_color};height:1.8em;'>".
769           "\n    <button type='button' onclick=\"$('{$tname}').toggle();\">"._("Show/hide advanced settings")."</button></td>".
770           "\n  </tr>";
771       } else if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT'])) {
772         $display.= "\n<table summary='{$name}' style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
773           "\n  <tr>".
774           "\n    <td style='background-color:#C8C8C8;height:1.8em;' colspan=".($cols-1)."><b>"._("Object").": $name</b></td>".
775           "\n    <td align='right' style='background-color:#C8C8C8;height:1.8em;'>".
776           "\n    <button type='button' onclick=\"$('{$tname}').toggle();\">"._("Show/hide advanced settings")."</button></td>".
777           "\n  </tr>";
778       } else {
779         $display.= "\n<table summary='{$name}' style='width:100%;border:1px solid #A0A0A0' cellspacing=0 cellpadding=2>".
780           "\n  <tr>".
781           "\n    <td style='background-color:#C8C8C8;height:1.8em;' colspan=$cols><b>"._("Object").": $name</b></td>".
782           "\n  </tr>";
783       }
785       /* Generate options */
786       $spc= "&nbsp;&nbsp;";
787       $options= $this->mkchkbx($key."_0_c",  _("Create objects"), preg_match('/c/', $overall_acl)).$spc;
788       $options.= $this->mkchkbx($key."_0_m", _("Move objects"), preg_match('/m/', $overall_acl)).$spc;
789       $options.= $this->mkchkbx($key."_0_d", _("Remove objects"), preg_match('/d/', $overall_acl)).$spc;
790       if ($plist[preg_replace('%^.*/%', '', $key)]['plSelfModify']){
791         $options.= $this->mkchkbx($key."_0_s", _("Grant permission to owner"), preg_match('/s/', $overall_acl)).$spc;
792       }
794       /* Global options */
795       $more_options= $this->mkchkbx($key."_0_r",  _("read"), preg_match('/r/', $overall_acl)).$spc;
796       $more_options.= $this->mkchkbx($key."_0_w", _("write"), preg_match('/w/', $overall_acl));
798       $display.= "\n  <tr>".
799                  "\n    <td style='background-color:#E0E0E0' colspan=".($cols-1).">$options</td>".
800                  "\n    <td style='background-color:#D4D4D4'>&nbsp;"._("Complete object").": $more_options</td>".
801                  "\n  </tr>";
803       /* Walk through the list of attributes */
804       $cnt= 1;
805       $splist= $plist[preg_replace('%^.*/%', '', $key)]['plProvidedAcls'];
806       if(session::global_get('js')) {
807         if(isset($_SERVER['HTTP_USER_AGENT']) && 
808             (preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) || (preg_match("/presto/i",$_SERVER['HTTP_USER_AGENT']))) {
809           $display.= "\n  <tr id='tr_$tname' style='vertical-align:top;height:0px;'>".
810                      "\n    <td colspan=".$cols.">".
811                      "\n      <div id='$tname' style='overflow:hidden; display:none;vertical-align:top;width:100%;'>".
812                      "\n        <table style='width:100%;' summary='{$name}'>";
813         } else if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT'])) {
814           $display.= "\n  <tr id='tr_$tname' style='vertical-align:top;height:0px;'>".
815                      "\n    <td colspan=".$cols.">".
816                      "\n      <div id='$tname' style='position:absolute;overflow:hidden;display:none;;vertical-align:top;width:100%;'>".
817                      "\n        <table style='width:100%;' summary='{$name}'>";
818         }else{
819         }
820       }
822   
823       foreach($splist as $attr => $dsc){
825         /* Skip pl* attributes, they are internal... */
826         if (preg_match('/^pl[A-Z]+.*$/', $attr)){
827           continue;
828         }
830         /* Open table row */
831         if ($cnt == 1){
832           $display.= "\n  <tr>";
833         }
835         /* Close table row */
836         if ($cnt == $cols){
837           $cnt= 1;
838           $rb= "";
839           $end= "\n  </tr>";
840         } else {
841           $cnt++;
842           $rb= "border-right:1px solid #A0A0A0;";
843           $end= "";
844         }
846         /* Collect list of attributes */
847         $state= "";
848         if (isset($currentAcl[$attr])){
849           $state= $currentAcl[$attr];
850         }
851         $display.= "\n    <td style='border-top:1px solid #A0A0A0;${rb}width:".(int)(100/$cols)."%'>".
852                    "\n      <b>$dsc</b> ($attr)<br>".$this->mkrwbx($key."_".$attr, $state)."</td>$end";
853       }
854       
855       /* Fill missing td's if needed */
856       if (--$cnt != $cols && $cnt != 0){
857        $display.= str_repeat("\n    <td style='border-top:1px solid #A0A0A0; width:".(int)(100/$cols)."%'>&nbsp;</td>", $cols-$cnt); 
858       }
860       if(session::global_get('js')) {
861         if(isset($_SERVER['HTTP_USER_AGENT']) && 
862             (preg_match("/gecko/i",$_SERVER['HTTP_USER_AGENT'])) || 
863             (preg_match("/presto/i",$_SERVER['HTTP_USER_AGENT'])) || 
864             (preg_match("/ie/i",$_SERVER['HTTP_USER_AGENT']))) {
865           $display.= "\n        </table>".
866                      "\n      </div>".
867                      "\n    </td>".
868                      "\n  </tr>";
869         }
870       }
872       $display.= "\n</table><br />\n";
873     }
875     return ($display);
876   }
879   function mkchkbx($name, $text, $state= FALSE)
880   {
881     $state= $state?"checked":"";
882     if($this->acl_is_writeable("")){
883                         $tname= preg_replace("/[^a-z0-9]/i","_",$name);
884       return "\n      <input id='acl_$tname' type=checkbox name='acl_$name' $state>".
885         "\n      <label for='acl_$tname'>$text</label>";
886     }else{
887       return "\n <input type='checkbox' disabled name='dummy_".microtime(1)."' $state>$text";
888     }
889   }
892   function mkrwbx($name, $state= "")
893   {
894     $rstate= preg_match('/r/', $state)?'checked':'';
895     $wstate= preg_match('/w/', $state)?'checked':'';
896                 $tname= preg_replace("/[^a-z0-9]/i","_",$name);
897       
898     if($this->acl_is_writeable("")){
899       return ("\n      <input id='acl_".$tname."_r' type=checkbox name='acl_${name}_r' $rstate>".
900           "\n      <label for='acl_".$tname."_r'>"._("read")."</label>".
901           "\n      <input id='acl_".$tname."_w' type=checkbox name='acl_${name}_w' $wstate>".
902           "\n      <label for='acl_".$tname."_w'>"._("write")."</label>");
903     }else{
904       return ("\n      <input disabled type=checkbox name='dummy_".microtime(1)."' $rstate>"._("read").
905           "\n      <input disabled type=checkbox name='dummy_".microtime(1)."' $wstate>"._("write"));
906     }
907   }
910   static function explodeACL($acl)
911   {
913     $list= explode(':', $acl);
914     if(count($list) == 5){
915       list($index, $type,$member,$permission,$filter)= $list;
916       $filter = base64_decode($filter);
917     }else{
918       $filter = "";
919       list($index, $type,$member,$permission)= $list;
920     }
922     $a= array( $index => array("type" => $type,
923                                "filter"=> $filter,
924                                "members" => acl::extractMembers($acl,$type == "role")));
925    
926     /* Handle different types */
927     switch ($type){
929       case 'psub':
930       case 'sub':
931       case 'one':
932       case 'base':
933         $a[$index]['acl']= acl::extractACL($acl);
934         break;
935       
936       case 'role':
937         $a[$index]['acl']= base64_decode(preg_replace('/^[^:]+:[^:]+:([^:]+).*$/', '\1', $acl));
938         break;
940       case 'reset':
941         break;
942       
943       default:
944         msg_dialog::display(_("Internal error"), sprintf(_("Unkown ACL type '%s'!"), $type), ERROR_DIALOG);
945         $a= array();
946     }
947     return ($a);
948   }
951   static function extractMembers($acl,$role = FALSE)
952   {
953     global $config;
954     $a= array();
956     /* Rip acl off the string, seperate by ',' and place it in an array */
957     if($role){
958       $ms= preg_replace('/^[^:]+:[^:]+:[^:]+:([^:]+).*$/', '\1', $acl);
959     }else{
960       $ms= preg_replace('/^[^:]+:[^:]+:([^:]+).*$/', '\1', $acl);
961     }
962     if ($ms == $acl){
963       return $a;
964     }
965     $ma= explode(',', $ms);
967     /* Decode dn's, fill with informations from LDAP */
968     $ldap= $config->get_ldap_link();
969     foreach ($ma as $memberdn){
970       // Check for wildcard here
971       $dn= base64_decode($memberdn);
972       if ($dn != "*") {
973         $ldap->cat($dn, array('cn', 'objectClass', 'description', 'uid'));
975         /* Found entry... */
976         if ($ldap->count()){
977           $attrs= $ldap->fetch();
978           if (in_array_ics('gosaAccount', $attrs['objectClass'])){
979             $a['U:'.$dn]= $attrs['cn'][0]." [".$attrs['uid'][0]."]";
980           } else {
981             $a['G:'.$dn]= $attrs['cn'][0];
982             if (isset($attrs['description'][0])){
983               $a['G:'.$dn].= " [".$attrs['description'][0]."]";
984             }
985           }
987         /* ... or not */
988         } else {
989           $a['U:'.$dn]= sprintf(_("Unknown entry '%s'!"), $dn);
990         }
992       } else {
993         $a['G:*']= sprintf(_("All users"));
994       }
995     }
997     return ($a);
998   }
1001   static function extractACL($acl)
1002   {
1003     /* Rip acl off the string, seperate by ',' and place it in an array */
1004     $as= preg_replace('/^[^:]+:[^:]+:[^:]*:([^:]*).*$/', '\1', $acl);
1005     $aa= explode(',', $as);
1006     $a= array();
1008     /* Dis-assemble single ACLs */
1009     foreach($aa as $sacl){
1010       
1011       /* Dis-assemble field ACLs */
1012       $ao= explode('#', $sacl);
1013       $gobject= "";
1014       foreach($ao as $idx => $ssacl){
1016         /* First is department with global acl */
1017         $object= preg_replace('/^([^;]+);.*$/', '\1', $ssacl);
1018         $gacl=   preg_replace('/^[^;]+;(.*)$/', '\1', $ssacl);
1019         if ($idx == 0){
1020           /* Create hash for this object */
1021           $gobject= $object;
1022           $a[$gobject]= array();
1024           /* Append ACL if set */
1025           if ($gacl != ""){
1026             $a[$gobject]= array($gacl);
1027           }
1028         } else {
1030           /* All other entries get appended... */
1031           list($field, $facl)= explode(';', $ssacl);
1032           $a[$gobject][$field]= $facl;
1033         }
1035       }
1036     }
1038     return ($a);
1039   }
1041   
1042   function assembleAclSummary($entry)
1043   {
1044     $summary= "";
1046     /* Summarize ACL */
1047     if (isset($entry['acl'])){
1048       $acl= "";
1050       if($entry['type'] == "role"){
1052         if(isset($this->roles[$entry['acl']])){  
1053           $summary.= sprintf(_("Role: %s"), $this->roles[$entry['acl']]['cn']);
1054         }else{
1055           $summary.= sprintf(_("Role: %s"), "<i>"._("unknown role")."</i>");
1056         }
1057       }else{
1058         foreach ($entry['acl'] as $name => $object){
1059           if (count($object)){
1060             $acl.= "$name, ";
1061           }
1062         }
1063         $summary.= sprintf(_("Contains settings for these objects: %s"), preg_replace('/, $/', '', $acl));
1064       }
1065     }
1068     /* Summarize members */
1069     if(!($this instanceOf aclrole)){
1070       if ($summary != ""){
1071         $summary.= ", ";
1072       }
1073       if (count($entry['members'])){
1074         $summary.= _("Members").": ";
1075         foreach ($entry['members'] as $cn){
1076           $cn= preg_replace('/ \[.*$/', '', $cn);
1077           $summary.= $cn.", ";
1078         }
1079       } else {
1080         $summary.= "<font color='red'><i>"._("inactive")."&nbsp;-&nbsp;"._("No members")."</i></font>";
1081       }
1082     }
1083     return (preg_replace('/, $/', '', $summary));
1084   }
1087   function loadAclEntry($new= FALSE)
1088   {
1089     /* New entry gets presets... */
1090     if ($new){
1091       $this->aclType= 'base';
1092       $this->aclFilter= "";
1093       $this->recipients= array();
1094       $this->aclContents= array();
1095     } else {
1096       $acl= $this->gosaAclEntry[$this->currentIndex];
1097       $this->aclType= $acl['type'];
1098       $this->recipients= $acl['members'];
1099       $this->aclContents= $acl['acl'];
1100       $this->aclFilter= $acl['filter'];
1101     }
1103     $this->wasNewEntry= $new;
1104   }
1107   function aclPostHandler()
1108   {
1109     if (isset($_POST['save_acl'])){
1110       $this->save();
1111       return TRUE;
1112     }
1114     return FALSE;
1115   }
1117   
1118   function PrepareForCopyPaste($source)
1119   {
1120     plugin::PrepareForCopyPaste($source);
1121     
1122     $dn = $source['dn'];
1123     $acl_c = new acl($this->config, $this->parent,$dn);
1124     $this->gosaAclEntry = $acl_c->gosaAclEntry;
1125   }
1128   function save()
1129   {
1130     /* Assemble ACL's */
1131     $tmp_acl= array();
1132   
1133     foreach ($this->gosaAclEntry as $prio => $entry){
1134       $final= "";
1135       $members= "";
1136       if (isset($entry['members'])){
1137         foreach ($entry['members'] as $key => $dummy){
1138           $members.= base64_encode(preg_replace('/^.:/', '', $key)).',';
1139         }
1140       }
1142       if($entry['type'] != "role"){
1143         $final= $prio.":".$entry['type'].":".preg_replace('/,$/', '', $members);
1144       }else{
1145         $final= $prio.":".$entry['type'].":".base64_encode($entry['acl']).":".preg_replace('/,$/', '', $members);
1146       }
1148       /* ACL's if needed */
1149       if ($entry['type'] != "reset" && $entry['type'] != "role"){
1150         $acl= ":";
1151         if (isset($entry['acl'])){
1152           foreach ($entry['acl'] as $object => $contents){
1154             /* Only save, if we've some contents in there... */
1155             if (count($contents)){
1156               $acl.= $object.";";
1158               foreach($contents as $attr => $permission){
1160                 /* First entry? Its the one for global settings... */
1161                 if ($attr == '0'){
1162                   $acl.= $permission;
1163                 } else {
1164                   $acl.= '#'.$attr.';'.$permission;
1165                 }
1167               }
1168               $acl.= ',';
1169             }
1170             
1171           }
1172         }
1173         $final.= preg_replace('/,$/', '', $acl);
1174       }
1176       /* Append additional filter options 
1177        */
1178       if(!empty($entry['filter'])){
1179         $final .= ":".base64_encode($entry['filter']);
1180       }
1182       $tmp_acl[]= $final;
1183     } 
1185     /* Call main method */
1186     plugin::save();
1188     /* Finally (re-)assign it... */
1189     $this->attrs['gosaAclEntry']= $tmp_acl;
1191     /* Remove acl from this entry if it is empty... */
1192     if (!count($tmp_acl)){
1193       /* Remove attribute */
1194       if ($this->initially_was_account){
1195         $this->attrs['gosaAclEntry']= array();
1196       } else {
1197         if (isset($this->attrs['gosaAclEntry'])){
1198           unset($this->attrs['gosaAclEntry']);
1199         }
1200       }
1202       /* Remove object class */
1203       $this->attrs['objectClass']= array_remove_entries(array('gosaAcl'), $this->attrs['objectClass']);
1204     }    
1206     /* Do LDAP modifications */
1207     $ldap= $this->config->get_ldap_link();
1208     $ldap->cd($this->dn);
1209     $this->cleanup();
1210     $ldap->modify ($this->attrs);
1212     if(count($this->attrs)){
1213       new log("modify","acls/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1214     }
1216     if (!$ldap->success()){
1217       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()), ERROR_DIALOG);
1218     }
1220     /* Refresh users ACLs */
1221     $ui= get_userinfo();
1222     $ui->loadACL();
1223     session::global_set('ui',$ui);
1224   }
1227   function remove_from_parent()
1228   {
1229     plugin::remove_from_parent();
1231     /* include global link_info */
1232     $ldap= $this->config->get_ldap_link();
1234     $ldap->cd($this->dn);
1235     $this->cleanup();
1236     $ldap->modify ($this->attrs);
1238     new log("remove","acls/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1240     /* Optionally execute a command after we're done */
1241     $this->handle_post_events("remove",array("uid" => $this->uid));
1242   }
1244   
1245   /* Return plugin informations for acl handling */
1246   static function plInfo()
1247   {
1248     return (array(
1249           "plShortName"   => _("ACL"),
1250           "plDescription" => _("ACL")."&nbsp;("._("Access control list").")",
1251           "plSelfModify"  => FALSE,
1252           "plDepends"     => array(),
1253           "plPriority"    => 0,
1254           "plSection"     => array("administration"),
1255           "plCategory"    => array("acl" => array("description"  => _("ACL")."&nbsp;&amp;&nbsp;"._("ACL roles"),
1256                                                           "objectClass"  => array("gosaAcl","gosaRole"))),
1257           "plProvidedAcls"=> array(
1258             "gosaAclEntry"          => _("Acl entries")
1259 //            "description" => _("Role description")
1260             )
1262           ));
1263   }
1266   /* Remove acls defined for $src */
1267   function remove_acl()
1268   {
1269     acl::remove_acl_for($this->dn);
1270   }
1273   /* Remove acls defined for $src */
1274   static function remove_acl_for($dn)
1275   {                                  
1276     global $config;                  
1278     $ldap = $config->get_ldap_link();
1279     $ldap->cd($config->current['BASE']);
1280     $ldap->search("(&(objectClass=gosaAcl)(gosaAclEntry=*".base64_encode($dn)."*))",array("gosaAclEntry","dn"));
1281     $new_entries= array();                                                                                      
1282     while($attrs = $ldap->fetch()){                                                                             
1283       if (!isset($attrs['gosaAclEntry'])) {                                                                     
1284         continue;                                                                                               
1285       }                                                                                                         
1286       unset($attrs['gosaAclEntry']['count']);                                                                   
1288       // Remove entry directly
1289       foreach($attrs['gosaAclEntry'] as $id => $entry){
1290         $parts= explode(':',$entry);                     
1291         $members= explode(',',$parts[2]);                
1292         $new_members= array();                         
1293         foreach($members as $member) {                 
1294           if (base64_decode($member) != $dn) {         
1295             $new_members[]= $member;                   
1296           } else {                                     
1297             gosa_log("modify","users/acl",$attrs['dn'],array(),sprintf("Removed acl for %s on object %s.",$dn,$attrs['dn']));
1298           }                                                                                                                  
1299         }                                                                                                                    
1301         /* We can completely remove the entry if there are no members anymore */
1302         if (count($new_members)) {                                              
1303           $parts[2]= implode(",", $new_members);                                
1304           $new_entries[]= implode(":", $parts);                                 
1305         }                                                                       
1306       }                                                                         
1308       // There should be a modification, so write it back
1309       $ldap->cd($attrs['dn']);
1310       $new_attrs= array("gosaAclEntry" => $new_entries);
1311       $ldap->modify($new_attrs);
1312       if (!$ldap->success()){
1313         msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, get_class()), ERROR_DIALOG);
1314       }
1315     }
1316   }
1319   function update_acl_membership($src,$dst)
1320   {
1321     $ldap = $this->config->get_ldap_link();
1322     $ldap->cd($this->config->current['BASE']);
1323     $ldap->search("(&(objectClass=gosaAcl)(gosaAclEntry=*".base64_encode($src)."*))",array("gosaAclEntry","dn"));
1324     while($attrs = $ldap->fetch()){
1325       $acl = new acl($this->config,$this->parent,$attrs['dn']);
1326       foreach($acl->gosaAclEntry as $id => $entry){
1327         foreach($entry['members'] as $m_id => $member){
1328           if($m_id == "U:".$src){
1329             unset($acl->gosaAclEntry[$id]['members'][$m_id]);
1330             $new = "U:".$dst;
1331             $acl->gosaAclEntry[$id]['members'][$new] = $new;
1332             gosa_log("modify","users/acl",$attrs['dn'],array(),sprintf("Updated acl for user %s on object %s.",$src,$attrs['dn']));
1333           }
1334           if($m_id == "G:".$src){
1335             unset($acl->gosaAclEntry[$id]['members'][$m_id]);
1336             $new = "G:".$dst;
1337             $acl->gosaAclEntry[$id]['members'][$new] = $new;
1338             gosa_log("modify","groups/acl",$attrs['dn'],array(),sprintf("Updated acl for group %s on object %s.",$src,$attrs['dn']));
1339           }
1340         }
1341       }
1342       $acl -> save();
1343     }
1344   }
1346   
1347   // We are only interessted in our own acls ... 
1348   function set_acl_category($category)
1349   {
1350     plugin::set_acl_category("acl");
1351   }
1354 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1355 ?>