Issue:
[moodle-pu.git] / auth / pam / auth.php
blob94a179eb299a1c14265a61cab951c737f9693f97
1 <?php
3 /**
4 * @author Martin Dougiamas
5 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
6 * @package moodle multiauth
8 * Authentication Plugin: PAM Authentication
10 * PAM (Pluggable Authentication Modules) for Moodle
12 * Description:
13 * Authentication by using the PHP4 PAM module:
14 * http://www.math.ohio-state.edu/~ccunning/pam_auth/
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)
20 * Contact: martinvoegeli@gmx.ch
21 * Website 1: http://elearning.zhwin.ch/
22 * Website 2: http://birdy1976.com/
24 * License: GPL License v2
26 * 2006-08-31 File created.
29 if (!defined('MOODLE_INTERNAL')) {
30 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
33 require_once($CFG->libdir.'/authlib.php');
35 /**
36 * PAM authentication plugin.
38 class auth_plugin_pam extends auth_plugin_base {
40 /**
41 * Store error messages from pam authentication attempts.
43 var $lasterror;
45 /**
46 * Constructor.
48 function auth_plugin_pam() {
49 $this->authtype = 'pam';
50 $this->config = get_config('auth/pam');
51 $this->errormessage = '';
54 /**
55 * Returns true if the username and password work and false if they are
56 * wrong or don't exist.
58 * @param string $username The username (with system magic quotes)
59 * @param string $password The password (with system magic quotes)
60 * @return bool Authentication success or failure.
62 function user_login ($username, $password) {
63 // variable to store possible errors during authentication
64 $errormessage = str_repeat(' ', 2048);
66 // just for testing and debugging
67 // error_reporting(E_ALL);
69 // call_time_pass_reference of errormessage is deprecated - throws warnings in multiauth
70 //if (pam_auth($username, $password, &$errormessage)) {
71 if (pam_auth(stripslashes($username), stripslashes($password))) {
72 return true;
74 else {
75 $this->lasterror = $errormessage;
76 return false;
80 /**
81 * Returns true if this authentication plugin is 'internal'.
83 * @return bool
85 function is_internal() {
86 return false;
89 /**
90 * Returns true if this authentication plugin can change the user's
91 * password.
93 * @return bool
95 function can_change_password() {
96 return false;
99 /**
100 * Prints a form for configuring this authentication plugin.
102 * This function is called from admin/auth.php, and outputs a full page with
103 * a form for configuring this plugin.
105 * @param array $page An object containing all the data for this page.
107 function config_form($config, $err, $user_fields) {
108 include "config.html";
112 * Processes and stores configuration data for this authentication plugin.
114 function process_config($config) {
115 return true;