MDL-20941 store hashed username into user->email field for deleted users. Merged...
[moodle.git] / auth / pam / auth.php
CommitLineData
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 *
139ebfdb 10 * PAM (Pluggable Authentication Modules) for Moodle
11 *
b9ddb2d5 12 * Description:
13 * Authentication by using the PHP4 PAM module:
14 * http://www.math.ohio-state.edu/~ccunning/pam_auth/
139ebfdb 15 *
b9ddb2d5 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)
139ebfdb 19 *
b9ddb2d5 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
139ebfdb 29if (!defined('MOODLE_INTERNAL')) {
30 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
31}
b9ddb2d5 32
6bc1e5d5 33require_once($CFG->libdir.'/authlib.php');
34
b9ddb2d5 35/**
36 * PAM authentication plugin.
37 */
6bc1e5d5 38class auth_plugin_pam extends auth_plugin_base {
139ebfdb 39
b9ddb2d5 40 /**
41 * Store error messages from pam authentication attempts.
42 */
43 var $lasterror;
44
45 /**
46 * Constructor.
47 */
48 function auth_plugin_pam() {
6bc1e5d5 49 $this->authtype = 'pam';
b9ddb2d5 50 $this->config = get_config('auth/pam');
51 $this->errormessage = '';
52 }
53
54 /**
55 * Returns true if the username and password work and false if they are
56 * wrong or don't exist.
57 *
be544ec3 58 * @param string $username The username
59 * @param string $password The password
139ebfdb 60 * @return bool Authentication success or failure.
b9ddb2d5 61 */
62 function user_login ($username, $password) {
63 // variable to store possible errors during authentication
64 $errormessage = str_repeat(' ', 2048);
139ebfdb 65
b9ddb2d5 66 // just for testing and debugging
67 // error_reporting(E_ALL);
b91c36bf 68
69 // call_time_pass_reference of errormessage is deprecated - throws warnings in multiauth
70 //if (pam_auth($username, $password, &$errormessage)) {
be544ec3 71 if (pam_auth($username, $password)) {
b9ddb2d5 72 return true;
73 }
74 else {
75 $this->lasterror = $errormessage;
76 return false;
139ebfdb 77 }
b9ddb2d5 78 }
79
80 /**
81 * Returns true if this authentication plugin is 'internal'.
82 *
139ebfdb 83 * @return bool
b9ddb2d5 84 */
85 function is_internal() {
86 return false;
87 }
88
89 /**
90 * Returns true if this authentication plugin can change the user's
91 * password.
92 *
139ebfdb 93 * @return bool
b9ddb2d5 94 */
95 function can_change_password() {
96 return false;
97 }
139ebfdb 98
b9ddb2d5 99 /**
100 * Prints a form for configuring this authentication plugin.
101 *
102 * This function is called from admin/auth.php, and outputs a full page with
103 * a form for configuring this plugin.
104 *
105 * @param array $page An object containing all the data for this page.
106 */
139ebfdb 107 function config_form($config, $err, $user_fields) {
b9ddb2d5 108 include "config.html";
109 }
110
111 /**
112 * Processes and stores configuration data for this authentication plugin.
113 */
114 function process_config($config) {
115 return true;
116 }
117
118}
119
5117d598 120