diff --git a/gosa-core/include/password-methods/class_password-methods.inc b/gosa-core/include/password-methods/class_password-methods.inc
index 5f3e683ef50dd042a15414dff15306519bfbb0e6..039886d5679257b9e2468b9903811fab6ecafe3d 100644 (file)
{
var $config = false;
var $attrs= array();
+ var $hash= "";
// Konstructor
function passwordMethod($config)
}
- // Loads Methods in annother way as get_available_methods do, (For setup ..)
- // and loads them,.
- #FIXME: This stopped working after moving around pw-methods
- function get_available_methods_if_not_loaded($path_to_load="../include")
- {
- $oh = opendir($path_to_load);
- $i = 0;
- $ret = false;
- while ($file = readdir($oh)) {
- $one = strtolower($file);
- if((strstr($one,"class_password-methods-" ))&&($one[0]!=".")){
- require_once($file);
- }
- }
- return(passwordMethod::get_available_methods());
- }
-
-
- // Crypts a single string, with given Method
- function crypt_single_str($string,$method)
- {
- $available = passwordMethod::get_available_methods();
- if(!is_array($available))
- {
- $available = passwordMethod::get_available_methods_if_not_loaded();
- }
-
- $test = new $available[$method](false);
- $newpass = $test->generate_hash($string);
- return( $newpass);
- }
-
-
// this function returns all loaded classes for password encryption
static function get_available_methods()
{
global $class_mapping, $config;
$ret =false;
$i =0;
- foreach($class_mapping as $class => $path) {
- if(preg_match('/passwordMethod/i', $class) && !preg_match("/^passwordMethod$/i", $class)){
- $name = preg_replace ("/passwordMethod/i", "", $class);
- $test = new $class($config);
- if($test->is_available()) {
- $plugname= $test->get_hash_name();
- $ret['name'][$i]= $plugname;
- $ret['class'][$i]=$class;
- $ret[$i]['name']= $plugname;
- $ret[$i]['class']= $class;
- $ret[$plugname]=$class;
- $i++;
+
+ /* Only */
+ if(!session::is_set("passwordMethod::get_available_methods")){
+ foreach($class_mapping as $class => $path) {
+ if(preg_match('/passwordMethod/i', $class) && !preg_match("/^passwordMethod$/i", $class)){
+ $name = preg_replace ("/passwordMethod/i", "", $class);
+ $test = new $class($config, "");
+ if($test->is_available()) {
+ $plugs= $test->get_hash_name();
+ if (!is_array($plugs)){
+ $plugs= array($plugs);
+ }
+
+ foreach ($plugs as $plugname){
+
+ $cfg = $test->is_configurable();
+
+ $ret['name'][$i]= $plugname;
+ $ret['class'][$i]=$class;
+ $ret['is_configurable'][$i]= $cfg;
+ $ret['object'][$i]= $test;
+ $ret['desc'][$i] = $test->get_description();
+ $ret[$i]['name'] = $plugname;
+ $ret[$i]['class'] = $class;
+ $ret[$i]['object']= $test;
+ $ret[$i]['is_configurable']= $cfg;
+ $ret[$i]['desc'] = $test->get_description();
+ $ret[$plugname]=$class;
+ $i++;
+ }
+ }
}
}
+ session::set("passwordMethod::get_available_methods",$ret);
}
- return($ret);
+ return(session::get("passwordMethod::get_available_methods"));
}
+ function get_description()
+ {
+ return("");
+ }
+
+
// Method to let password backends remove additional information besides
// the userPassword attribute
function remove_from_parent()
// besides the userAttribute entry
function set_password($password)
{
+ return(TRUE);
}
}
+ // Try to find out if it's our hash...
+ static function get_method($password_hash,$dn = "")
+ {
+ global $config;
+
+ $methods= passwordMethod::get_available_methods();
+
+ foreach ($methods['class'] as $class){
+
+ $test = new $class($config,$dn);
+# All listed methods are available.
+# if(!$test->is_available())continue;
+ $method= $test->_extract_method($password_hash);
+ if ($method != ""){
+ $test->set_hash($method);
+ return $test;
+ }
+ }
+
+ msg_dialog::display(_("Error"), _("Cannot find a suitable password method for the current hash!"), ERROR_DIALOG);
+
+ return NULL;
+ }
+
+
+ function _extract_method($password_hash)
+ {
+ $hash= $this->get_hash_name();
+ if (preg_match("/^\{$hash\}/i", $password_hash)){
+ return $hash;
+ }
+
+ return "";
+ }
+
+
+ static function make_hash($password, $hash)
+ {
+ global $config;
+
+ $methods= passwordMethod::get_available_methods();
+ $tmp= new $methods[$hash]($config);
+ $tmp->set_hash($hash);
+ return $tmp->generate_hash($password);
+ }
+
+
+ function set_hash($hash)
+ {
+ $this->hash= $hash;
+ }
+
+
+ function get_hash()
+ {
+ return $this->hash;
+ }
+
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>