LScli: fix --sub-dn autocompletion even if LDAP server not selected

This commit is contained in:
Benjamin Renard 2020-08-07 11:09:20 +02:00
parent 3dc0d7f637
commit 6eee099bd2

View file

@ -409,6 +409,8 @@ class LScli extends LSlog_staticLoggerClass {
$command = null; $command = null;
$command_arg_num = null; $command_arg_num = null;
$command_args = array(); $command_args = array();
$ldap_server_id = false;
$ldap_server_subDn = false;
for ($i=1; $i < count($comp_words); $i++) { for ($i=1; $i < count($comp_words); $i++) {
$unescaped_comp_word = $comp_words[$i]; $unescaped_comp_word = $comp_words[$i];
self :: unquote_word($unescaped_comp_word); self :: unquote_word($unescaped_comp_word);
@ -438,17 +440,6 @@ class LScli extends LSlog_staticLoggerClass {
self :: unquote_word($ldap_server_id); self :: unquote_word($ldap_server_id);
if(!LSsession :: setLdapServer($ldap_server_id)) if(!LSsession :: setLdapServer($ldap_server_id))
self :: usage("Fail to select LDAP server #$ldap_server_id."); self :: usage("Fail to select LDAP server #$ldap_server_id.");
// Check if LDAP server has subDn and select the first one if true
self :: need_ldap_con();
$subDns = LSsession :: getSubDnLdapServer();
if (is_array($subDns)) {
asort($subDns);
$subDn = key($subDns);
if(!LSsession :: setSubDn($subDn))
self :: usage("Fail to select sub DN '$subDn'.");
$opts[] = '--sub-dn';
}
} }
break; break;
case '--sub-dn': case '--sub-dn':
@ -464,13 +455,11 @@ class LScli extends LSlog_staticLoggerClass {
} }
if (!isset($comp_words[$i])) if (!isset($comp_words[$i]))
break; break;
if (isset($comp_words[$i])) { $ldap_server_subDn = $comp_words[$i];
$subDn = $comp_words[$i]; self :: unquote_word($ldap_server_subDn);
self :: unquote_word($subDn); self :: need_ldap_con();
self :: need_ldap_con(); if(!LSsession :: setSubDn($ldap_server_subDn))
if(!LSsession :: setSubDn($subDn)) self :: usage("Fail to select sub DN '$ldap_server_subDn'.");
self :: usage("Fail to select sub DN '$subDn'.");
}
break; break;
case '-L': case '-L':
case '--load-class': case '--load-class':
@ -510,6 +499,19 @@ class LScli extends LSlog_staticLoggerClass {
} }
} }
// Is no subDn selected, check if LDAP server has subDn and select the first one if true
if (!$ldap_server_subDn) {
self :: need_ldap_con();
$subDns = LSsession :: getSubDnLdapServer();
if (is_array($subDns)) {
asort($subDns);
$subDn = key($subDns);
if(!LSsession :: setSubDn($subDn))
self :: usage("Fail to select sub DN '$subDn'.");
$opts[] = '--sub-dn';
}
}
// If command set and args autocompleter defined, use it // If command set and args autocompleter defined, use it
if ($command && is_callable(self :: $commands[$command]['args_autocompleter'])) { if ($command && is_callable(self :: $commands[$command]['args_autocompleter'])) {
$command_comp_word_num = $comp_word_num-$command_arg_num-1; $command_comp_word_num = $comp_word_num-$command_arg_num-1;