From 267e1e39976840e73256c8f0c5eec9a69371900e Mon Sep 17 00:00:00 2001 From: hickert Date: Thu, 10 Apr 2008 13:41:14 +0000 Subject: [PATCH] Added a new function that allows updating the accessTo attribute git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10328 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-core/include/functions.inc | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/gosa-core/include/functions.inc b/gosa-core/include/functions.inc index 6fc523247..7675ff23e 100644 --- a/gosa-core/include/functions.inc +++ b/gosa-core/include/functions.inc @@ -2684,6 +2684,42 @@ function xmlentities($str) } +/*! \brief Updates all accessTo attributes from a given value to a new one. + For example if a host is renamed. + @param String $from The source accessTo name. + @param String $to The destination accessTo name. +*/ +function update_accessTo($from,$to) +{ + global $config; + $ldap = $config->get_ldap_link(); + $ldap->cd($config->current['BASE']); + $ldap->search("(&(objectClass=trustAccount)(accessTo=".$from."))",array("objectClass","accessTo")); + while($attrs = $ldap->fetch()){ + $new_attrs = array(); + $dn = $attrs['dn']; + for($i = 0 ; $i < $attrs['objectClass']['count']; $i++){ + $new_attrs['objectClass'][] = $attrs['objectClass'][$i]; + } + for($i = 0 ; $i < $attrs['accessTo']['count']; $i++){ + if($attrs['accessTo'][$i] == $from){ + if(!empty($to)){ + $new_attrs['accessTo'][] = $to; + } + }else{ + $new_attrs['accessTo'][] = $attrs['accessTo'][$i]; + } + } + $ldap->cd($dn); + $ldap->modify($new_attrs); + if (!$ldap->success()){ + msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, "update_accessTo($from,$to)")); + } + new log("modify","update_accessTo($from,$to)",$dn,array_keys($new_attrs),$ldap->get_error()); + } +} + + function get_random_char () { $randno = rand (0, 63); if ($randno < 12) { -- 2.30.2