Prevent using undefined or non-existant variables

This commit is contained in:
Andrew Ruthven 2024-05-01 00:21:46 +12:00
parent a50e3eae90
commit 629789612e

View File

@ -627,16 +627,19 @@ function sync_LDAP_groups(){
foreach ( $mapping as $field => $value ) {
dbg_error_log( "LDAP", "Considering copying %s", $field );
if ( isset($validUserFields[$field]) ) {
if ( isset($validUserFields[$field]) && isset($ldap_values[$value]) ) {
$user->{$field} = $ldap_values[$value];
dbg_error_log( "LDAP", "Setting usr->%s to %s from LDAP field %s", $field, $ldap_values[$value], $value );
}
}
if ($user->fullname == "") {
// A sane default for the fullname is the group name.
if (! isset($user->fullname) || $user->fullname == "") {
$user->fullname = $group;
}
// A sane default for the displayname is the fullname (which might be
// the group name).
if (! isset($user->displayname) || $user->displayname == "") {
$user->displayname = $user->fullname;
}