14require_once(
"auth-functions.php");
35 if (! file_exists($config)){
36 $c->messages[] = sprintf(i18n(
'drivers_squid_pam : Unable to find %s file'), $config );
47function SQUID_PAM_check($username, $password ){
50 $script = $c->authenticate_hook[
'config'][
'script'];
51 if ( empty($script) ) $script = $c->authenticate_hook[
'config'][
'path'];
52 $cmd = sprintf(
'echo %s %s | %s -n common-auth', escapeshellarg($username), escapeshellarg($password),
54 $auth_result = exec($cmd);
55 if ( $auth_result ==
"OK") {
56 dbg_error_log(
'PAM',
'User %s successfully authenticated', $username);
57 $principal =
new Principal(
'username',$username);
58 if ( !$principal->Exists() ) {
59 dbg_error_log(
'PAM',
'User %s does not exist in local db, creating', $username);
60 $pwent = posix_getpwnam($username);
61 $gecos = explode(
',',$pwent[
'gecos']);
62 $fullname = $gecos[0];
63 $principal->Create( array(
64 'username' => $username,
66 'email' => sprintf(
'%s@%s', $username, $email_base),
67 'fullname' => $fullname
69 if ( ! $principal->Exists() ) {
70 dbg_error_log(
"PAM",
"Unable to create local principal for '%s'", $username );
73 CreateHomeCollections($username);
74 CreateDefaultRelationships($username);
79 dbg_error_log(
"PAM",
"User %s is not a valid username (or password was wrong)", $username );