3 * Manages PAM repository connection with SQUID help
8 * @author Eric Seigne <eric.seigne@ryxeo.com>,
9 * Andrew McMillan <andrew@mcmillan.net.nz>
10 * @copyright Eric Seigne
11 * @license http://gnu.org/copyleft/gpl.html GNU GPL v2 or later
14 require_once("auth-functions.php");
28 * @param string $config path where /usr/lib/squid/pam_auth is
30 function __construct($config) {
32 if (! file_exists($config)){
33 $c->messages
[] = sprintf(i18n( 'drivers_squid_pam : Unable to find %s file'), $config );
42 * Check the username / password against the PAM system
44 function SQUID_PAM_check($username, $password ){
47 $script = $c->authenticate_hook
['config']['script'];
48 if ( empty($script) ) $script = $c->authenticate_hook
['config']['path'];
49 $cmd = sprintf( 'echo %s %s | %s -n common-auth', escapeshellarg($username), escapeshellarg($password),
51 $auth_result = exec($cmd);
52 if ( $auth_result == "OK") {
53 dbg_error_log('pwauth', 'User %s successfully authenticated', $username);
54 $principal = new Principal('username',$username);
55 if ( !$principal->Exists() ) {
56 dbg_error_log('pwauth', 'User %s does not exist in local db, creating', $username);
57 $pwent = posix_getpwnam($username);
58 $gecos = explode(',',$pwent['gecos']);
59 $fullname = $gecos[0];
60 $principal->Create( array(
61 'username' => $username,
63 'email' => sprintf('%s@%s', $username, $email_base),
64 'fullname' => $fullname
66 if ( ! $principal->Exists() ) {
67 dbg_error_log( "PAM", "Unable to create local principal for '%s'", $username );
70 CreateHomeCalendar($username);
75 dbg_error_log( "PAM", "User %s is not a valid username (or password was wrong)", $username );