Merge pull request #14031 from snipe/bug/ldap_undefined_search_base

Fixed undefined $search_base
This commit is contained in:
snipe 2023-12-15 13:33:34 +00:00 committed by GitHub
commit 130be26820
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -66,6 +66,7 @@ class LdapSync extends Command
$ldap_result_dept = Setting::getSettings()->ldap_dept; $ldap_result_dept = Setting::getSettings()->ldap_dept;
$ldap_result_manager = Setting::getSettings()->ldap_manager; $ldap_result_manager = Setting::getSettings()->ldap_manager;
$ldap_default_group = Setting::getSettings()->ldap_default_group; $ldap_default_group = Setting::getSettings()->ldap_default_group;
$search_base = Setting::getSettings()->ldap_base_dn;
try { try {
$ldapconn = Ldap::connectToLdap(); $ldapconn = Ldap::connectToLdap();
@ -83,26 +84,35 @@ class LdapSync extends Command
$summary = []; $summary = [];
try { try {
/**
* if a location ID has been specified, use that OU
*/
if ( $this->option('location_id') != '') { if ( $this->option('location_id') != '') {
foreach($this->option('location_id') as $location_id){ foreach($this->option('location_id') as $location_id){
$location_ou= Location::where('id', '=', $location_id)->value('ldap_ou'); $location_ou = Location::where('id', '=', $location_id)->value('ldap_ou');
$search_base = $location_ou; $search_base = $location_ou;
Log::debug('Importing users from specified location OU: \"'.$search_base.'\".'); Log::debug('Importing users from specified location OU: \"'.$search_base.'\".');
} }
}
else if ($this->option('base_dn') != '') { /**
* Otherwise if a manual base DN has been specified, use that
*/
} elseif ($this->option('base_dn') != '') {
$search_base = $this->option('base_dn'); $search_base = $this->option('base_dn');
Log::debug('Importing users from specified base DN: \"'.$search_base.'\".'); Log::debug('Importing users from specified base DN: \"'.$search_base.'\".');
} else {
$search_base = null;
} }
/**
* If a filter has been specified, use that
*/
if ($this->option('filter') != '') { if ($this->option('filter') != '') {
$results = Ldap::findLdapUsers($search_base, -1, $this->option('filter')); $results = Ldap::findLdapUsers($search_base, -1, $this->option('filter'));
} else { } else {
$results = Ldap::findLdapUsers($search_base); $results = Ldap::findLdapUsers($search_base);
} }
} catch (\Exception $e) { } catch (\Exception $e) {
if ($this->option('json_summary')) { if ($this->option('json_summary')) {
$json_summary = ['error' => true, 'error_message' => $e->getMessage(), 'summary' => []]; $json_summary = ['error' => true, 'error_message' => $e->getMessage(), 'summary' => []];