diff --git a/repos/system_upgrade/el9toel10/actors/scanpamuserdb/actor.py b/repos/system_upgrade/el9toel10/actors/scanpamuserdb/actor.py new file mode 100644 index 0000000000..f1ad52abe2 --- /dev/null +++ b/repos/system_upgrade/el9toel10/actors/scanpamuserdb/actor.py @@ -0,0 +1,18 @@ +from leapp.actors import Actor +from leapp.tags import FactsPhaseTag, IPUWorkflowTag +from leapp.models import PamUserDbLocation +from leapp.libraries.actor import scanpamuserdb + + +class ScanPamUserDb(Actor): + """ + Scan the PAM service folder for the location of pam_userdb databases + """ + + name = 'scan_pam_user_db' + consumes = () + produces = (PamUserDbLocation,) + tags = (FactsPhaseTag, IPUWorkflowTag) + + def process(self): + self.produce(scanpamuserdb.parse_folder('/etc/pam.d/')) diff --git a/repos/system_upgrade/el9toel10/actors/scanpamuserdb/libraries/scanpamuserdb.py b/repos/system_upgrade/el9toel10/actors/scanpamuserdb/libraries/scanpamuserdb.py new file mode 100644 index 0000000000..6c42c3bcb7 --- /dev/null +++ b/repos/system_upgrade/el9toel10/actors/scanpamuserdb/libraries/scanpamuserdb.py @@ -0,0 +1,29 @@ +import os +import re + +from leapp.models import PamUserDbLocation + + +def parse_file(conf_file): + with open(conf_file, 'r') as file: + for line in file: + if 'pam_userdb' in line: + match = re.search(r'db=(\S+)', line) + if match: + return match.group(1) + + return None + + +def parse_folder(conf_folder): + locations = set() + + for file_name in os.listdir(conf_folder): + file_path = os.path.join(conf_folder, file_name) + + if os.path.isfile(file_path): + location = parse_file(file_path) + if location is not None: + locations.add(location) + + return PamUserDbLocation(locations=list(locations)) diff --git a/repos/system_upgrade/el9toel10/actors/scanpamuserdb/tests/files/pam_userdb_basic b/repos/system_upgrade/el9toel10/actors/scanpamuserdb/tests/files/pam_userdb_basic new file mode 100644 index 0000000000..fc8adf9858 --- /dev/null +++ b/repos/system_upgrade/el9toel10/actors/scanpamuserdb/tests/files/pam_userdb_basic @@ -0,0 +1 @@ +auth required pam_userdb.so db=/tmp/db1 \ No newline at end of file diff --git a/repos/system_upgrade/el9toel10/actors/scanpamuserdb/tests/files/pam_userdb_complete b/repos/system_upgrade/el9toel10/actors/scanpamuserdb/tests/files/pam_userdb_complete new file mode 100644 index 0000000000..a49c50160b --- /dev/null +++ b/repos/system_upgrade/el9toel10/actors/scanpamuserdb/tests/files/pam_userdb_complete @@ -0,0 +1,9 @@ +auth required pam_env.so +auth required pam_faildelay.so delay=2000000 +auth sufficient pam_fprintd.so +auth [default=1 ignore=ignore success=ok] pam_usertype.so isregular +auth [default=1 ignore=ignore success=ok] pam_localuser.so +auth required pam_userdb.so db=/tmp/db2 +auth [default=1 ignore=ignore success=ok] pam_usertype.so isregular +auth sufficient pam_sss.so forward_pass +auth required pam_deny.so \ No newline at end of file diff --git a/repos/system_upgrade/el9toel10/actors/scanpamuserdb/tests/files/pam_userdb_missing b/repos/system_upgrade/el9toel10/actors/scanpamuserdb/tests/files/pam_userdb_missing new file mode 100644 index 0000000000..8afceeddf8 --- /dev/null +++ b/repos/system_upgrade/el9toel10/actors/scanpamuserdb/tests/files/pam_userdb_missing @@ -0,0 +1 @@ +auth sufficient pam_unix.so nullok \ No newline at end of file diff --git a/repos/system_upgrade/el9toel10/actors/scanpamuserdb/tests/test_scanpamuserdb.py b/repos/system_upgrade/el9toel10/actors/scanpamuserdb/tests/test_scanpamuserdb.py new file mode 100644 index 0000000000..f0b0d42792 --- /dev/null +++ b/repos/system_upgrade/el9toel10/actors/scanpamuserdb/tests/test_scanpamuserdb.py @@ -0,0 +1,23 @@ +import os + +import pytest + +from leapp.libraries.actor import scanpamuserdb + +CUR_DIR = os.path.dirname(os.path.abspath(__file__)) + + +def test_parse_file(): + file = scanpamuserdb.parse_file(os.path.join(CUR_DIR, 'files/pam_userdb_missing')) + assert file is None + file = scanpamuserdb.parse_file(os.path.join(CUR_DIR, 'files/pam_userdb_basic')) + assert file == '/tmp/db1' + file = scanpamuserdb.parse_file(os.path.join(CUR_DIR, 'files/pam_userdb_complete')) + assert file == '/tmp/db2' + + +def test_parse_folder(): + msg = scanpamuserdb.parse_folder(os.path.join(CUR_DIR, 'files/')) + assert len(msg.locations) == 2 + assert '/tmp/db1' in msg.locations + assert '/tmp/db2' in msg.locations diff --git a/repos/system_upgrade/el9toel10/models/pamuserdblocation.py b/repos/system_upgrade/el9toel10/models/pamuserdblocation.py new file mode 100644 index 0000000000..124b05e994 --- /dev/null +++ b/repos/system_upgrade/el9toel10/models/pamuserdblocation.py @@ -0,0 +1,14 @@ +from leapp.models import Model, fields +from leapp.topics import SystemInfoTopic + + +class PamUserDbLocation(Model): + """ + Provides a list of all database files for pam_userdb + """ + topic = SystemInfoTopic + + locations = fields.List(fields.String(), default=[]) + """ + The list with the full path to the database files. + """