diff --git a/sos-bz2024893-cleaner-hostnames-improvements.patch b/sos-bz2024893-cleaner-hostnames-improvements.patch index 148adb6..5d71ffb 100644 --- a/sos-bz2024893-cleaner-hostnames-improvements.patch +++ b/sos-bz2024893-cleaner-hostnames-improvements.patch @@ -1387,3 +1387,158 @@ index 1e8d8e2dc5..7653b59de3 100644 ], cmdclass=cmdclass, command_options=command_options, +-- +2.31.1 + +From ba3528230256429a4394f155a9ca1fdb91cf3560 Mon Sep 17 00:00:00 2001 +From: Jake Hunsaker +Date: Tue, 30 Nov 2021 12:46:34 -0500 +Subject: [PATCH 1/2] [hostname] Simplify case matching for domains + +Instead of special handling all uppercase domain conventions, use our +normal flow for obfuscation and just match the casing at the end of the +sanitization routine. + +Signed-off-by: Jake Hunsaker +--- + sos/cleaner/mappings/hostname_map.py | 14 ++++++++------ + 1 file changed, 8 insertions(+), 6 deletions(-) + +diff --git a/sos/cleaner/mappings/hostname_map.py b/sos/cleaner/mappings/hostname_map.py +index 0fe78fb1..5cd8e985 100644 +--- a/sos/cleaner/mappings/hostname_map.py ++++ b/sos/cleaner/mappings/hostname_map.py +@@ -169,16 +169,15 @@ class SoSHostnameMap(SoSMap): + + def sanitize_item(self, item): + host = item.split('.') +- if len(host) > 1 and all([h.isupper() for h in host]): +- # by convention we have just a domain +- _host = [h.lower() for h in host] +- return self.sanitize_domain(_host).upper() + if len(host) == 1: + # we have a shortname for a host + return self.sanitize_short_name(host[0].lower()) + if len(host) == 2: + # we have just a domain name, e.g. example.com +- return self.sanitize_domain(host) ++ dname = self.sanitize_domain(host) ++ if all([h.isupper() for h in host]): ++ dname = dname.upper() ++ return dname + if len(host) > 2: + # we have an FQDN, e.g. foo.example.com + hostname = host[0] +@@ -194,7 +193,10 @@ class SoSHostnameMap(SoSMap): + ob_hostname = 'unknown' + ob_domain = self.sanitize_domain(domain) + self.dataset[item] = ob_domain +- return '.'.join([ob_hostname, ob_domain]) ++ _fqdn = '.'.join([ob_hostname, ob_domain]) ++ if all([h.isupper() for h in host]): ++ _fqdn = _fqdn.upper() ++ return _fqdn + + def sanitize_short_name(self, hostname): + """Obfuscate the short name of the host with an incremented counter +-- +2.31.1 + + +From 189586728de22dd55122c1f7e06b19590f9a788f Mon Sep 17 00:00:00 2001 +From: Jake Hunsaker +Date: Tue, 30 Nov 2021 12:47:58 -0500 +Subject: [PATCH 2/2] [username] Improve username sourcing and remove case + sensitivity + +First, don't skip the first line of `last` output, and instead add the +header from lastlog to the skip list. Additionally, add +`/etc/cron.allow` and `/etc/cron.deny` as sources for usernames that +might not appear in other locations in certain environments. + +Also, make matching and replacement case insensitive. + +Signed-off-by: Jake Hunsaker +--- + sos/cleaner/archives/sos.py | 4 +++- + sos/cleaner/mappings/username_map.py | 2 +- + sos/cleaner/parsers/username_parser.py | 14 +++++++++----- + 3 files changed, 13 insertions(+), 7 deletions(-) + +diff --git a/sos/cleaner/archives/sos.py b/sos/cleaner/archives/sos.py +index f8720c88..12766496 100644 +--- a/sos/cleaner/archives/sos.py ++++ b/sos/cleaner/archives/sos.py +@@ -35,7 +35,9 @@ class SoSReportArchive(SoSObfuscationArchive): + 'sos_commands/login/lastlog_-u_65537-4294967295', + # AD users will be reported here, but favor the lastlog files since + # those will include local users who have not logged in +- 'sos_commands/login/last' ++ 'sos_commands/login/last', ++ 'etc/cron.allow', ++ 'etc/cron.deny' + ] + } + +diff --git a/sos/cleaner/mappings/username_map.py b/sos/cleaner/mappings/username_map.py +index cdbf36fe..7ecccd7b 100644 +--- a/sos/cleaner/mappings/username_map.py ++++ b/sos/cleaner/mappings/username_map.py +@@ -33,5 +33,5 @@ class SoSUsernameMap(SoSMap): + ob_name = "obfuscateduser%s" % self.name_count + self.name_count += 1 + if ob_name in self.dataset.values(): +- return self.sanitize_item(username) ++ return self.sanitize_item(username.lower()) + return ob_name +diff --git a/sos/cleaner/parsers/username_parser.py b/sos/cleaner/parsers/username_parser.py +index 35377a31..229c7de4 100644 +--- a/sos/cleaner/parsers/username_parser.py ++++ b/sos/cleaner/parsers/username_parser.py +@@ -8,6 +8,7 @@ + # + # See the LICENSE file in the source distribution for further information. + ++import re + + from sos.cleaner.parsers import SoSCleanerParser + from sos.cleaner.mappings.username_map import SoSUsernameMap +@@ -34,6 +35,7 @@ class SoSUsernameParser(SoSCleanerParser): + 'reboot', + 'root', + 'ubuntu', ++ 'username', + 'wtmp' + ] + +@@ -47,12 +49,12 @@ class SoSUsernameParser(SoSCleanerParser): + this parser, we need to override the initial parser prepping here. + """ + users = set() +- for line in content.splitlines()[1:]: ++ for line in content.splitlines(): + try: + user = line.split()[0] + except Exception: + continue +- if user in self.skip_list: ++ if user.lower() in self.skip_list: + continue + users.add(user) + for each in users: +@@ -61,7 +63,9 @@ class SoSUsernameParser(SoSCleanerParser): + def parse_line(self, line): + count = 0 + for username in sorted(self.mapping.dataset.keys(), reverse=True): +- if username in line: +- count = line.count(username) +- line = line.replace(username, self.mapping.get(username)) ++ _reg = re.compile(username, re.I) ++ if _reg.search(line): ++ line, count = _reg.subn( ++ self.mapping.get(username.lower()), line ++ ) + return line, count +-- +2.31.1 + diff --git a/sos.spec b/sos.spec index 42b3c76..be7f077 100644 --- a/sos.spec +++ b/sos.spec @@ -5,7 +5,7 @@ Summary: A set of tools to gather troubleshooting information from a system Name: sos Version: 4.2 -Release: 6%{?dist} +Release: 7%{?dist} Group: Applications/System Source0: https://github.com/sosreport/sos/archive/%{version}/sos-%{version}.tar.gz Source1: sos-audit-%{auditversion}.tgz @@ -131,6 +131,10 @@ of the system. Currently storage and filesystem commands are audited. %changelog +* Wed Dec 08 2021 Pavel Moravec = 4.2-7 +- [hostname] Simplify case matching for domains + Resolves: bz2024893 + * Tue Nov 30 2021 Pavel Moravec = 4.2-6 - [redhat] Fix broken URI to upload to customer portal Resolves: bz2025611