Merge branch 'MDL-25881' of git://git.luns.net.uk/moodle
[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
edb5da83
PS
80 function prevent_local_passwords() {
81 return true;
82 }
83
b9ddb2d5 84 /**
85 * Returns true if this authentication plugin is 'internal'.
86 *
139ebfdb 87 * @return bool
b9ddb2d5 88 */
89 function is_internal() {
90 return false;
91 }
92
93 /**
94 * Returns true if this authentication plugin can change the user's
95 * password.
96 *
139ebfdb 97 * @return bool
b9ddb2d5 98 */
99 function can_change_password() {
100 return false;
101 }
139ebfdb 102
b9ddb2d5 103 /**
104 * Prints a form for configuring this authentication plugin.
105 *
106 * This function is called from admin/auth.php, and outputs a full page with
107 * a form for configuring this plugin.
108 *
109 * @param array $page An object containing all the data for this page.
110 */
139ebfdb 111 function config_form($config, $err, $user_fields) {
b9ddb2d5 112 include "config.html";
113 }
114
115 /**
116 * Processes and stores configuration data for this authentication plugin.
117 */
118 function process_config($config) {
119 return true;
120 }
121
122}
123
5117d598 124