PAM - get user name from a comma-less passwd comment field.

PAM authentication uses a regular expression to extract the user's real
name from the 'user name or comment field' passwd file when creating a
new account.

The current regular expression assumes the comment field contains the
user name followed by a comma and some other comma-delimited information
(the Linux 'adduser' command adds room number, work phone, home phone
and 'other' info given half a chance).

If the field just contains the user name, there is no trailing comma
and the RE match fails. Make the trailing comma optional.

Signed-off-by: Andrew McMillan <andrew@morphoss.com>
This commit is contained in:
Jim Hague 2010-09-16 11:37:22 +01:00 committed by Andrew McMillan
parent 685fec39e8
commit 9469eb6d58

View File

@ -68,7 +68,7 @@ function SQUID_PAM_check($username, $password ){
else {
dbg_error_log( "PAM", "user %s doesn't exist in local DB, we need to create it",$username );
$fullname = exec('getent passwd "'.$username.'"' );
$fullname = preg_replace( '{^[^:]+:[^:]+:\d+:\d+:([^:,]+)(,[^:]*):.*$}', '$1', $fullname );
$fullname = preg_replace( '{^[^:]+:[^:]+:\d+:\d+:([^:,]+)(,?[^:]*):.*$}', '$1', $fullname );
$usr = (object) array(
'user_no' => 0,
'username' => $username,