Merge branch 'wip-mdl-37432-m24' of git://github.com/rajeshtaneja/moodle into MOODLE_...
[moodle.git] / auth / pam / auth.php
blobc0afbe0ed8153709d1af590ee1751b7b6c0704b5
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
59 * @param string $password The password
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($username, $password)) {
72 return true;
74 else {
75 $this->lasterror = $errormessage;
76 return false;
80 function prevent_local_passwords() {
81 return true;
84 /**
85 * Returns true if this authentication plugin is 'internal'.
87 * @return bool
89 function is_internal() {
90 return false;
93 /**
94 * Returns true if this authentication plugin can change the user's
95 * password.
97 * @return bool
99 function can_change_password() {
100 return false;
104 * Prints a form for configuring this authentication plugin.
106 * This function is called from admin/auth.php, and outputs a full page with
107 * a form for configuring this plugin.
109 * @param array $page An object containing all the data for this page.
111 function config_form($config, $err, $user_fields) {
112 include "config.html";
116 * Processes and stores configuration data for this authentication plugin.
118 function process_config($config) {
119 return true;