|
1 | | -{{% set file_stem = ["auth","account","password","session"] %}} |
| 1 | +{{% if product == "rhel10" %}} |
| 2 | +{{% set pam_files = ["password-auth", "system-auth"] %}} |
| 3 | +{{% else %}} |
| 4 | +{{% set pam_files = ["common"] %}} |
| 5 | +{{% endif %}} |
| 6 | +{{% set pam_sections = ["auth","account","password","session"] %}} |
2 | 7 | <def-group> |
3 | 8 | <definition class="compliance" id="{{{ rule_id }}}" version="1"> |
4 | 9 | {{{ oval_metadata("Ensure pam_unix.so is properly configured in PAM configuration files", rule_title=rule_title) }}} |
5 | | - <criteria operator="AND" comment="Check if pam_unix.so is properly defined in all PAM files"> |
6 | | - {{% for stem in file_stem %}} |
7 | | - <criterion test_ref="test_pam_unix_common_{{{ stem }}}" |
8 | | - comment="pam_unix has correctly set in common-{{{ stem }}}"/> |
| 10 | + <criteria operator="AND" comment="Check if pam_unix.so is properly defined in all PAM files"> |
| 11 | + {{% for pam_file in pam_files %}} |
| 12 | + {{% for pam_section in pam_sections %}} |
| 13 | + <criterion test_ref="test_pam_unix_{{{ pam_file }}}_{{{ pam_section }}}" comment="pam_unix is configured in {{{ pam_section }}} section in {{{ pam_file }}}" /> |
| 14 | + {{% endfor %}} |
9 | 15 | {{% endfor %}} |
10 | 16 | </criteria> |
11 | 17 | </definition> |
12 | 18 |
|
13 | 19 | <!-- Check occurrences of pam_unix.so in common-{auth,account,password} file --> |
14 | | - {{% macro test_pam_unix(stem) %}} |
15 | | - <ind:textfilecontent54_test check="all" id="test_pam_unix_common_{{{ stem }}}" version="1" |
| 20 | + {{% macro test_pam_unix(full_path, pam_file, pam_section) %}} |
| 21 | + <ind:textfilecontent54_test check="all" id="test_pam_unix_{{{ pam_file }}}_{{{ pam_section }}}" version="1" |
16 | 22 | check_existence="only_one_exists" |
17 | | - comment="No more than one pam_unix.so is expected in {{{ stem }}} section of /etc/pam.d/common-{{{ stem }}}"> |
18 | | - <ind:object object_ref="obj_pam_unix_common_{{{ stem }}}" /> |
| 23 | + comment="No more than one pam_unix.so is expected in {{{ pam_section }}} section of {{{ full_path }}}"> |
| 24 | + <ind:object object_ref="obj_pam_unix_{{{ pam_file }}}_{{{ pam_section }}}" /> |
19 | 25 | </ind:textfilecontent54_test> |
20 | 26 | {{% endmacro %}} |
21 | 27 |
|
22 | | - {{% macro object_pam_unix(stem) %}} |
23 | | - <ind:textfilecontent54_object id="obj_pam_unix_common_{{{ stem }}}" version="1" |
24 | | - comment="Get the occurrences of pam_unix.so in {{{ stem }}} section of /etc/pam.d/common-{{{ stem }}}"> |
25 | | - <ind:filepath>/etc/pam.d/common-{{{ stem }}}</ind:filepath> |
26 | | - <ind:pattern operation="pattern match">^[\s]*{{{stem}}}[\s]+(required|\[(?=.*?\bsuccess=\d+\b)?(?=.*?\bnew_authtok_reqd=ok\b)?(?=.*?\bdefault=ignore\b)?.*\])[\s]+pam_unix\.so.*$</ind:pattern> |
| 28 | + {{% macro object_pam_unix(full_path, pam_file, pam_section) %}} |
| 29 | + <ind:textfilecontent54_object id="obj_pam_unix_{{{ pam_file }}}_{{{ pam_section }}}" version="1" |
| 30 | + comment="Get the occurrences of pam_unix.so in {{{ pam_section }}} section of {{{ full_path }}}"> |
| 31 | + <ind:filepath>{{{ full_path }}}</ind:filepath> |
| 32 | +{{% if product == "rhel10" %}} |
| 33 | + <ind:pattern operation="pattern match">^[\s]*{{{ pam_section }}}[\s]+(required|sufficient)[\s]+pam_unix\.so.*$</ind:pattern> |
| 34 | +{{% else %}} |
| 35 | + <ind:pattern operation="pattern match">^[\s]*{{{ pam_section }}}[\s]+(required|\[(?=.*?\bsuccess=\d+\b)?(?=.*?\bnew_authtok_reqd=ok\b)?(?=.*?\bdefault=ignore\b)?.*\])[\s]+pam_unix\.so.*$</ind:pattern> |
| 36 | +{{% endif %}} |
27 | 37 | <ind:instance datatype="int" operation="equals">1</ind:instance> |
28 | 38 | </ind:textfilecontent54_object> |
29 | 39 | {{% endmacro %}} |
30 | 40 |
|
31 | | - {{% for file in file_stem %}} |
32 | | - {{{ test_pam_unix(stem=file) }}} |
33 | | - {{{ object_pam_unix(stem=file) }}} |
| 41 | + {{% for pam_file in pam_files %}} |
| 42 | + {{% for pam_section in pam_sections %}} |
| 43 | + {{% if product == "rhel10" %}} |
| 44 | + {{% set full_path = "/etc/pam.d/" + pam_file %}} |
| 45 | + {{% else %}} |
| 46 | + {{% set full_path = "/etc/pam.d/" + pam_file + "-" + pam_section %}} |
| 47 | + {{% endif %}} |
| 48 | + {{{ test_pam_unix(full_path, pam_file, pam_section) }}} |
| 49 | + {{{ object_pam_unix(full_path, pam_file, pam_section) }}} |
| 50 | + {{% endfor %}} |
34 | 51 | {{% endfor %}} |
35 | | - |
36 | 52 | </def-group> |
0 commit comments