b9ddb2d5 |
1 | <?php |
2 | |
3 | /** |
4 | * @author Martin Dougiamas |
5 | * @license http://www.gnu.org/copyleft/gpl.html GNU Public License |
6 | * @package moodle multiauth |
7 | * |
8 | * Authentication Plugin: PAM Authentication |
9 | * |
10 | * PAM (Pluggable Authentication Modules) for Moodle |
11 | * |
12 | * Description: |
13 | * Authentication by using the PHP4 PAM module: |
14 | * http://www.math.ohio-state.edu/~ccunning/pam_auth/ |
15 | * |
16 | * Version 0.3 2006/09/07 by Jonathan Harker (plugin class) |
17 | * Version 0.2: 2004/09/01 by Martin V�geli (stable version) |
18 | * Version 0.1: 2004/08/30 by Martin V�geli (first draft) |
19 | * |
20 | * Contact: martinvoegeli@gmx.ch |
21 | * Website 1: http://elearning.zhwin.ch/ |
22 | * Website 2: http://birdy1976.com/ |
23 | * |
24 | * License: GPL License v2 |
25 | * |
26 | * 2006-08-31 File created. |
27 | */ |
28 | |
29 | // This page cannot be called directly |
30 | if (!isset($CFG)) exit; |
31 | |
32 | /** |
33 | * PAM authentication plugin. |
34 | */ |
35 | class auth_plugin_pam { |
36 | |
37 | /** |
38 | * The configuration details for the plugin. |
39 | */ |
40 | var $config; |
41 | |
42 | /** |
43 | * Store error messages from pam authentication attempts. |
44 | */ |
45 | var $lasterror; |
46 | |
47 | /** |
48 | * Constructor. |
49 | */ |
50 | function auth_plugin_pam() { |
51 | $this->config = get_config('auth/pam'); |
52 | $this->errormessage = ''; |
53 | } |
54 | |
55 | /** |
56 | * Returns true if the username and password work and false if they are |
57 | * wrong or don't exist. |
58 | * |
59 | * @param string $username The username |
60 | * @param string $password The password |
61 | * @returns bool Authentication success or failure. |
62 | */ |
63 | function user_login ($username, $password) { |
64 | // variable to store possible errors during authentication |
65 | $errormessage = str_repeat(' ', 2048); |
66 | |
67 | // just for testing and debugging |
68 | // error_reporting(E_ALL); |
69 | if (pam_auth($username, $password, &$errormessage)) { |
70 | return true; |
71 | } |
72 | else { |
73 | $this->lasterror = $errormessage; |
74 | return false; |
75 | } |
76 | } |
77 | |
78 | /** |
79 | * Returns true if this authentication plugin is 'internal'. |
80 | * |
81 | * @returns bool |
82 | */ |
83 | function is_internal() { |
84 | return false; |
85 | } |
86 | |
87 | /** |
88 | * Returns true if this authentication plugin can change the user's |
89 | * password. |
90 | * |
91 | * @returns bool |
92 | */ |
93 | function can_change_password() { |
94 | return false; |
95 | } |
96 | |
97 | /** |
98 | * Prints a form for configuring this authentication plugin. |
99 | * |
100 | * This function is called from admin/auth.php, and outputs a full page with |
101 | * a form for configuring this plugin. |
102 | * |
103 | * @param array $page An object containing all the data for this page. |
104 | */ |
105 | function config_form($config, $err) { |
106 | include "config.html"; |
107 | } |
108 | |
109 | /** |
110 | * Processes and stores configuration data for this authentication plugin. |
111 | */ |
112 | function process_config($config) { |
113 | return true; |
114 | } |
115 | |
116 | } |
117 | |
118 | ?> |