From 7f49fa68121abdd160ba79267cfedee2d5577834 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Fri, 18 Mar 2011 13:36:19 +0000 Subject: [PATCH] read users full name from password file and create email address according to configured rules for automatic created accounts --- phpgwapi/inc/class.auth_pam.inc.php | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/phpgwapi/inc/class.auth_pam.inc.php b/phpgwapi/inc/class.auth_pam.inc.php index c48718b254..100c75e7b7 100644 --- a/phpgwapi/inc/class.auth_pam.inc.php +++ b/phpgwapi/inc/class.auth_pam.inc.php @@ -11,8 +11,10 @@ /** * Auth from PAM - * - * Requires php_pam extension! + * + * Requires PHP PAM extension: pecl install pam + * + * To read full name from password file PHP's posix extension is needed (sometimes in package php_process) */ class auth_pam implements auth_backend { @@ -26,8 +28,28 @@ class auth_pam implements auth_backend */ function authenticate($username, $passwd, $passwd_type='text') { - if (pam_auth($username, get_magic_quotes_gpc() ? stripslashes($passwd) : $passwd, &$error)) + if (pam_auth($username, get_magic_quotes_gpc() ? stripslashes($passwd) : $passwd, $error)) { + // for new accounts read full name from password file and pass it to EGroupware + if (!$GLOBALS['egw']->accounts->name2id($username) && + function_exists('posix_getpwnam') && ($data = posix_getpwnam($username))) + { + list($fullname) = explode(',',$data['gecos']); + $parts = explode(' ',$fullname); + if (count($parts) > 1) + { + $lastname = array_pop($parts); + $firstname = implode(' ',$parts); + $email = common::email_address($firstname, $lastname, $username); + + $GLOBALS['auto_create_acct'] = array( + 'firstname' => $firstname, + 'lastname' => $lastname, + 'email' => $email, + 'account_id' => $data['uid'], + ); + } + } return True; } return False;