Skip to content

Commit c7d6bc7

Browse files
committed
fixup! fixup! fixup! fixup! add detection for custom libraries registered by ld.so.conf
1 parent 82dda95 commit c7d6bc7

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

repos/system_upgrade/common/actors/checkldsoconf/libraries/checkldsoconfiguration.py

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
LD_SO_CONF_MAIN = '/etc/ld.so.conf'
1111
LD_SO_CONF_DEFAULT_INCLUDE = 'ld.so.conf.d/*.conf'
1212
LD_SO_CONF_COMMENT_PREFIX = '#'
13-
FMT_LIST_SEPARATOR = '\n - '
13+
LD_LIBRARY_PATH_VAR = 'LD_LIBRARY_PATH'
14+
FMT_LIST_SEPARATOR_1 = '\n- '
15+
FMT_LIST_SEPARATOR_2 = '\n - '
1416

1517

1618
def _read_file(file_path):
@@ -21,10 +23,10 @@ def _read_file(file_path):
2123
def _report_custom_ld_so_configuration(summary):
2224
reporting.create_report([
2325
reporting.Title(
24-
'Third party libraries linked with ld.so.conf are not supported.'
26+
'Detected customized configuration for dynamic linker.'
2527
),
2628
reporting.Summary(summary),
27-
reporting.Remediation(hint=('Remove the custom ld.so configuration and apply the changes '
29+
reporting.Remediation(hint=('Remove or revert the custom ld.so configuration and apply the changes '
2830
'using the ldconfig command.')),
2931
reporting.RelatedResource('file', '/etc/ld.so.conf'),
3032
reporting.RelatedResource('directory', '/etc/ld.so.conf.d'),
@@ -36,13 +38,11 @@ def _report_custom_ld_so_configuration(summary):
3638
def _is_modified(config_path):
3739
""" Decide if the configuration file was modified based on the package it belongs to. """
3840
result = run(['rpm', '-Vf', config_path], checked=False)
39-
if result['exit_code'] == 0:
41+
if not result['exit_code']:
4042
return False
41-
output = result['stdout']
42-
# Note that the condition is relaxed so that files different only
43-
# in the modification timestamp won't be considered as modified.
44-
modification_flags = output.split(' ', 1)[0]
45-
return modification_flags.strip('.') != 'T'
43+
modification_flags = result['stdout'].split(' ', 1)[0]
44+
# The file is considered modified only when the checksum does not match
45+
return '5' in modification_flags
4646

4747

4848
def _is_included_ld_so_config_custom(config_path):
@@ -90,34 +90,44 @@ def _parse_main_ld_so_config():
9090

9191
def check_ld_so_configuration():
9292
included_configs, other_lines = _parse_main_ld_so_config()
93-
summary = ''
93+
custom_configurations = ''
9494

9595
if other_lines:
9696
# The main ld.so config file is expected to only include additional configs that are owned by a package
97-
summary += ('The /etc/ld.so.conf file has unexpected contents:'
98-
'{}{}'.format(FMT_LIST_SEPARATOR,
99-
FMT_LIST_SEPARATOR.join(other_lines)))
97+
custom_configurations += ('{}The /etc/ld.so.conf file has unexpected contents:'
98+
'{}{}').format(FMT_LIST_SEPARATOR_1,
99+
FMT_LIST_SEPARATOR_2, FMT_LIST_SEPARATOR_2.join(other_lines))
100100

101101
is_default_include_present = '/etc/' + LD_SO_CONF_DEFAULT_INCLUDE in included_configs
102102
if not is_default_include_present:
103-
api.current_logger().debug('The default include "' + LD_SO_CONF_DEFAULT_INCLUDE +
104-
'" is not present in the ' + LD_SO_CONF_MAIN + ' file.')
103+
api.current_logger().debug('The default include "{}" is not present in '
104+
'the {} file.'.format(LD_SO_CONF_DEFAULT_INCLUDE, LD_SO_CONF_MAIN))
105105

106106
if is_default_include_present and len(included_configs) != 1:
107107
# The additional included configs will most likely be created manually by the user
108108
# and therefore will get flagged as custom in the next part of this function
109-
api.current_logger().debug('The default include "' + LD_SO_CONF_DEFAULT_INCLUDE +
110-
'" is not the only include in the ' + LD_SO_CONF_MAIN + ' file.')
109+
api.current_logger().debug('The default include "{}" is not the only include in '
110+
'the {} file.'.format(LD_SO_CONF_DEFAULT_INCLUDE, LD_SO_CONF_MAIN))
111111

112112
# Detect custom ld configs from the includes in the main ld.so.conf
113113
custom_ld_configs = set()
114114
for cfg_glob in included_configs:
115115
custom_ld_configs.update({cfg for cfg in glob.glob(cfg_glob) if _is_included_ld_so_config_custom(cfg)})
116116

117117
if custom_ld_configs:
118-
summary += ('\nThe following config files were marked as unsupported:'
119-
'{}{}'.format(FMT_LIST_SEPARATOR,
120-
FMT_LIST_SEPARATOR.join(custom_ld_configs)))
121-
122-
if summary:
118+
custom_configurations += ('{}The following drop in config files were marked as custom:'
119+
'{}{}').format(FMT_LIST_SEPARATOR_1,
120+
FMT_LIST_SEPARATOR_2, FMT_LIST_SEPARATOR_2.join(custom_ld_configs))
121+
122+
if os.environ.get(LD_LIBRARY_PATH_VAR, None):
123+
custom_configurations += ('{}The variable "{}" contains unexpected dynamic linker '
124+
'configuration.').format(FMT_LIST_SEPARATOR_1, LD_LIBRARY_PATH_VAR)
125+
126+
if custom_configurations:
127+
summary = ('Custom configurations to the dynamic linker could potentially impact the upgrade in a negative '
128+
'way. The custom configuration includes modifications to {}, custom or modified drop in config '
129+
'files in the {} directory and additional entries in the {} variable. These modifications '
130+
'configure the dynamic linker to use different libraries that might not be provided by Red Hat '
131+
'products. The following custom configurations were detected '
132+
'by leapp:{}').format(LD_SO_CONF_MAIN, LD_SO_CONF_DIR, LD_LIBRARY_PATH_VAR, custom_configurations)
123133
_report_custom_ld_so_configuration(summary)

0 commit comments

Comments
 (0)