summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f8ee3f1)
raw | patch | inline | side by side (parent: f8ee3f1)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 5 Oct 2010 06:09:05 +0000 (06:09 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 5 Oct 2010 06:09:05 +0000 (06:09 +0000) |
-Allow to use replacement slicing by using replacements like %var{n:m}
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19912 594d385d-05f5-0310-b6e9-bd551577e9d8
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19912 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-core/include/class_plugin.inc | patch | blob | history | |
gosa-core/include/functions.inc | patch | blob | history | |
gosa-core/include/password-methods/class_password-methods.inc | patch | blob | history |
index 3c003145e39c027b85a319db97c946d1ab5605ba..d7a97a60e397d4d64aedc25553a1861a93bb543d 100644 (file)
arsort($tmp);
// Now replace the placeholder
- foreach ($tmp as $name => $len){
- $value = $addAttrs[$name];
- $command= str_replace("%$name", "$value", $command);
- }
+ $command = fillReplacements($command, $addAttrs, TRUE);
// If there are still some %.. in our command, try to fill these with some other class vars
if(preg_match("/%/",$command)){
index 6b1ad16a8a25dbde9561f6ce399a7f65531020a7..ae3624984a2c54fda029661d09cb10b6d9d5a9d0 100644 (file)
return(NULL);
}
+
+/*! \brief Replaces placeholder in a given string.
+ * For example:
+ * '%uid@gonicus.de' Replaces '%uid' with 'uid'.
+ * '%uid{0}@gonicus.de' Replaces '%uid{0}' with the first char of 'uid'.
+ * '%uid{2:4}@gonicus.de' Replaces '%uid{2:4}' with three chars from 'uid' starting from the second.
+ *
+ * @param String The string to perform the action on.
+ * @param Array An array of replacements.
+ * @return The resulting string.
+ */
+function fillReplacements($str, $attrs, $shellArg = FALSE)
+{
+ // Search for '%...{...}
+ // Get all matching parts of the given string and sort them by
+ // length, to avoid replacing strings like '%uidNumber' with 'uid'
+ // instead of 'uidNumber'; The longest tring at first.
+ preg_match_all('/(%([a-z0-9]+)(\{(([0-9]+)(:([0-9]+))?)\})?)/i', $str ,$matches, PREG_SET_ORDER);
+ $hits = array();
+ foreach($matches as $match){
+ $hits[strlen($match[2]).$match[0]] = $match;
+ }
+ krsort($hits);
+
+ // Replace the placeholder in the given string now.
+ foreach($hits as $match){
+ $name = $match[2];
+ $start = (isset($match[5])) ? $match[5] : 0;
+ $end = (isset($match[7])) ? $match[7] : strlen($attrs[$name]);
+ $value = substr($attrs[$name], $start, $end);
+ if($shellArg) $value = escapeshellarg($value);
+ $str = preg_replace("/".preg_quote($match[0],'/')."/", $value, $str);
+ }
+ return($str);
+}
+
+
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>
diff --git a/gosa-core/include/password-methods/class_password-methods.inc b/gosa-core/include/password-methods/class_password-methods.inc
index 9d1260bf2b58e8329ae26725c27baaeaa28cf44d..695f32e7171783c82c60de123268eb7b903ce822 100644 (file)
$userPassword = preg_replace("/(^[^\}]+\})(.*$)/","\\1!\\2",$userPassword);
$sambaLMPassword = preg_replace("/^[!]*(.*$)/","!\\1",$sambaLMPassword);
$sambaNTPassword = preg_replace("/^[!]*(.*$)/","!\\1",$sambaNTPassword);
- $ldap->cd($dn);
- // Lock the account by modifying the password hash.
+ // Call external lock hook
+ $res = $ldap->cat($dn);
+ $hookAttrs = array();
+ foreach($ldap->fetch() as $name => $value){
+ if(is_numeric($name)) continue;
+ if(isset($value[0])) $hookAttrs[$name] = $value[0];
+ if(isset($value) && is_string($value)) $hookAttrs[$name] = $value;
+ }
$pwdClass = new password($config, $dn);
- $pwdClass->callHook($pwdClass, 'PRELOCK',array(), $ret);
+ $pwdClass->callHook($pwdClass, 'PRELOCK',$hookAttrs, $ret);
// Update the ldap entry
+ $ldap->cd($dn);
$ldap->modify(
array(
"userPassword" => $userPassword,
if($ldap->success()){
// Call the password post-lock hook, if defined.
- $pwdClass->callHook($pwdClass, 'POSTLOCK',array(), $ret);
+ $pwdClass->callHook($pwdClass, 'POSTLOCK',$hookAttrs, $ret);
}
return($ldap->success());
$sambaLMPassword = preg_replace("/^[!]*(.*$)/","\\1",$sambaLMPassword);
$sambaNTPassword = preg_replace("/^[!]*(.*$)/","\\1",$sambaNTPassword);
- // Call a pre-lock hook if defined.
+ // Call external lock hook
+ $res = $ldap->cat($dn);
+ $hookAttrs = array();
+ foreach($ldap->fetch() as $name => $value){
+ if(is_numeric($name)) continue;
+ if(isset($value[0])) $hookAttrs[$name] = $value[0];
+ if(isset($value) && is_string($value)) $hookAttrs[$name] = $value;
+ }
$pwdClass = new password($config, $dn);
- $pwdClass->callHook($pwdClass, 'PREUNLOCK',array(), $ret);
+ $pwdClass->callHook($pwdClass, 'PREUNLOCK',$hookAttrs, $ret);
// Lock the account by modifying the password hash.
$ldap->cd($dn);
// Call the password post-lock hook, if defined.
$pwdClass = new password($config, $dn);
- $pwdClass->callHook($pwdClass, 'POSTUNLOCK',array(), $ret);
+ $pwdClass->callHook($pwdClass, 'POSTUNLOCK',$hookAttrs, $ret);
}
return($ldap->success());
}