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 class passwordMethod
24 {
25 var $config = false;
26 var $attrs= array();
27 var $hash= "";
29 // Konstructor
30 function passwordMethod($config)
31 {
32 }
35 function get_hash_name()
36 {
37 }
40 // this function returns all loaded classes for password encryption
41 static function get_available_methods()
42 {
43 global $class_mapping, $config;
44 $ret =false;
45 $i =0;
47 /* Only */
48 if(!session::is_set("passwordMethod::get_available_methods")){
49 foreach($class_mapping as $class => $path) {
50 if(preg_match('/passwordMethod/i', $class) && !preg_match("/^passwordMethod$/i", $class)){
51 $name = preg_replace ("/passwordMethod/i", "", $class);
52 $test = new $class($config, "");
53 if($test->is_available()) {
54 $plugs= $test->get_hash_name();
55 if (!is_array($plugs)){
56 $plugs= array($plugs);
57 }
59 foreach ($plugs as $plugname){
61 $cfg = $test->is_configurable();
63 $ret['name'][$i]= $plugname;
64 $ret['class'][$i]=$class;
65 $ret['is_configurable'][$i]= $cfg;
66 $ret['object'][$i]= $test;
67 $ret['desc'][$i] = $test->get_description();
68 $ret[$i]['name'] = $plugname;
69 $ret[$i]['class'] = $class;
70 $ret[$i]['object']= $test;
71 $ret[$i]['is_configurable']= $cfg;
72 $ret[$i]['desc'] = $test->get_description();
73 $ret[$plugname]=$class;
74 $i++;
75 }
76 }
77 }
78 }
79 session::set("passwordMethod::get_available_methods",$ret);
80 }
81 return(session::get("passwordMethod::get_available_methods"));
82 }
85 function get_description()
86 {
87 return("");
88 }
91 // Method to let password backends remove additional information besides
92 // the userPassword attribute
93 function remove_from_parent()
94 {
95 }
98 // Method to let passwords backends manage additional information
99 // besides the userAttribute entry
100 function set_password($password)
101 {
102 return(TRUE);
103 }
106 // Return true if this password method provides a configuration dialog
107 function is_configurable()
108 {
109 return FALSE;
110 }
113 // Provide a subdialog to configure a password method
114 function configure()
115 {
116 return "";
117 }
120 // Save information to LDAP
121 function save($dn)
122 {
123 }
126 // Try to find out if it's our hash...
127 static function get_method($password_hash,$dn = "")
128 {
129 global $config;
131 $methods= passwordMethod::get_available_methods();
133 foreach ($methods['class'] as $class){
135 $test = new $class($config,$dn);
136 # All listed methods are available.
137 # if(!$test->is_available())continue;
138 $method= $test->_extract_method($password_hash);
139 if ($method != ""){
140 $test->set_hash($method);
141 return $test;
142 }
143 }
145 msg_dialog::display(_("Error"), _("Cannot find a suitable password method for the current hash!"), ERROR_DIALOG);
147 return NULL;
148 }
151 function _extract_method($password_hash)
152 {
153 $hash= $this->get_hash_name();
154 if (preg_match("/^\{$hash\}/i", $password_hash)){
155 return $hash;
156 }
158 return "";
159 }
162 static function make_hash($password, $hash)
163 {
164 global $config;
166 $methods= passwordMethod::get_available_methods();
167 $tmp= new $methods[$hash]($config);
168 $tmp->set_hash($hash);
169 return $tmp->generate_hash($password);
170 }
173 function set_hash($hash)
174 {
175 $this->hash= $hash;
176 }
179 function get_hash()
180 {
181 return $this->hash;
182 }
184 }
185 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
186 ?>