Skip to content

Commit

Permalink
Make sure grub password regex handles all cases
Browse files Browse the repository at this point in the history
The regex to match passwords in grub.conf needs to handle both
the --md5 and non-md5 cases and to apply the substitution only
to the secret part (password or password hash).

This needs to deal with the fact that python will return 'None'
for unmatched pattern groups leading to an exception in re.subn()
if not all referenced groups match for a given string (in contrast
to e.g. the perl approach of treating these groups as the empty
string).

Make this explicit by using an empty alternate in the possibly
unmatched '--md5' group:

            r"(password\s*)(--md5\s*|\s*)(.*)",
            r"\1\2********"

Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
  • Loading branch information
bmr-cymru committed Jun 2, 2014
1 parent 23182c4 commit 6501013
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sos/plugins/grub.py
Expand Up @@ -33,8 +33,8 @@ def setup(self):
def postproc(self):
self.do_path_regex_sub(
r".*\/grub.conf",
r"(password)\s(--md5)\s(.*)",
r"\1 \2 ********"
r"(password\s*)(--md5\s*|\s*)(.*)",
r"\1\2********"
)

# vim: et ts=4 sw=4

0 comments on commit 6501013

Please sign in to comment.