Code

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