mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-26 08:51:50 -06:00
ipa-client-install: Do not add already configured sources to nsswitch.conf entries
Makes sure that any new sources added are not already present in the entry. https://fedorahosted.org/freeipa/ticket/4508 Reviewed-By: Petr Viktorin <pviktori@redhat.com>
This commit is contained in:
parent
93346b1cf9
commit
fd26560a16
@ -399,7 +399,7 @@ def is_ipa_client_installed(on_master=False):
|
|||||||
return installed
|
return installed
|
||||||
|
|
||||||
def configure_nsswitch_database(fstore, database, services, preserve=True,
|
def configure_nsswitch_database(fstore, database, services, preserve=True,
|
||||||
append=True, default_value=None):
|
append=True, default_value=()):
|
||||||
"""
|
"""
|
||||||
Edits the specified nsswitch.conf database (e.g. passwd, group, sudoers)
|
Edits the specified nsswitch.conf database (e.g. passwd, group, sudoers)
|
||||||
to use the specified service(s).
|
to use the specified service(s).
|
||||||
@ -430,28 +430,34 @@ def configure_nsswitch_database(fstore, database, services, preserve=True,
|
|||||||
opts = conf.parse(f)
|
opts = conf.parse(f)
|
||||||
raw_database_entry = conf.findOpts(opts, 'option', database)[1]
|
raw_database_entry = conf.findOpts(opts, 'option', database)[1]
|
||||||
|
|
||||||
if not raw_database_entry:
|
# Detect the list of already configured services
|
||||||
# If there is no database entry, database is not present in
|
if not raw_database_entry:
|
||||||
# the nsswitch.conf. Set the list of services to the
|
# If there is no database entry, database is not present in
|
||||||
# default list, if passed.
|
# the nsswitch.conf. Set the list of services to the
|
||||||
configured_services = ' '.join(default_value or [])
|
# default list, if passed.
|
||||||
else:
|
configured_services = list(default_value)
|
||||||
configured_services = raw_database_entry['value'].strip()
|
|
||||||
|
|
||||||
if append:
|
|
||||||
new_services = ' ' + configured_services + ' ' + ' '.join(services)
|
|
||||||
else:
|
else:
|
||||||
new_services = ' ' + ' '.join(services) + ' ' + configured_services
|
configured_services = raw_database_entry['value'].strip().split()
|
||||||
|
|
||||||
|
# Make sure no service is added if already mentioned in the list
|
||||||
|
added_services = [s for s in services
|
||||||
|
if s not in configured_services]
|
||||||
|
|
||||||
|
# Prepend / append the list of new services
|
||||||
|
if append:
|
||||||
|
new_value = ' ' + ' '.join(configured_services + added_services)
|
||||||
|
else:
|
||||||
|
new_value = ' ' + ' '.join(added_services + configured_services)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Preserve not set, let's rewrite existing configuration
|
# Preserve not set, let's rewrite existing configuration
|
||||||
new_services = ' ' + ' '.join(services)
|
new_value = ' ' + ' '.join(services)
|
||||||
|
|
||||||
# Set new services as sources for database
|
# Set new services as sources for database
|
||||||
opts = [{'name': database,
|
opts = [{'name': database,
|
||||||
'type':'option',
|
'type':'option',
|
||||||
'action':'set',
|
'action':'set',
|
||||||
'value': new_services
|
'value': new_value
|
||||||
},
|
},
|
||||||
{'name':'empty',
|
{'name':'empty',
|
||||||
'type':'empty'
|
'type':'empty'
|
||||||
|
Loading…
Reference in New Issue
Block a user