Blame SOURCES/scap-security-guide-0.1.61-update_RHEL_08_010383-PR_8138.patch

62ebbd
diff --git a/linux_os/guide/system/software/sudo/sudoers_validate_passwd/ansible/shared.yml b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/ansible/shared.yml
62ebbd
index 08ffd76aed6..399ca1ea3ce 100644
62ebbd
--- a/linux_os/guide/system/software/sudo/sudoers_validate_passwd/ansible/shared.yml
62ebbd
+++ b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/ansible/shared.yml
62ebbd
@@ -4,6 +4,26 @@
62ebbd
 # complexity = low
62ebbd
 # disruption = low
62ebbd
 
62ebbd
-{{{ ansible_lineinfile(msg='Ensure that Defaults !targetpw is defined in sudoers', path='/etc/sudoers', new_line='Defaults !targetpw', create='yes', state='present') }}}
62ebbd
-{{{ ansible_lineinfile(msg='Ensure that Defaults !rootpw is defined in sudoers', path='/etc/sudoers', new_line='Defaults !rootpw', create='yes', state='present') }}}
62ebbd
-{{{ ansible_lineinfile(msg='Ensure that Defaults !runaspw is defined in sudoers', path='/etc/sudoers', new_line='Defaults !runaspw', create='yes', state='present') }}}
62ebbd
+{{%- macro delete_line_in_sudoers_d(line) %}}
62ebbd
+- name: "Find out if /etc/sudoers.d/* files contain {{{ line }}} to be deduplicated"
62ebbd
+  find:
62ebbd
+    path: "/etc/sudoers.d"
62ebbd
+    patterns: "*"
62ebbd
+    contains: '^{{{ line }}}$'
62ebbd
+  register: sudoers_d_defaults
62ebbd
+
62ebbd
+- name: "Remove found occurrences of {{{ line }}} from /etc/sudoers.d/* files"
62ebbd
+  lineinfile:
62ebbd
+    path: "{{ item.path }}"
62ebbd
+    regexp: "^{{{ line }}}$"
62ebbd
+    state: absent
62ebbd
+  with_items: "{{ sudoers_d_defaults.files }}"
62ebbd
+{{%- endmacro %}}
62ebbd
+
62ebbd
+{{{- delete_line_in_sudoers_d("Defaults !targetpw") }}}
62ebbd
+{{{- delete_line_in_sudoers_d("Defaults !rootpw") }}}
62ebbd
+{{{- delete_line_in_sudoers_d("Defaults !runaspw") }}}
62ebbd
+
62ebbd
+{{{ ansible_only_lineinfile(msg='Ensure that Defaults !targetpw is defined in sudoers', line_regex='^Defaults !targetpw$', path='/etc/sudoers', new_line='Defaults !targetpw') }}}
62ebbd
+{{{ ansible_only_lineinfile(msg='Ensure that Defaults !rootpw is defined in sudoers', line_regex='^Defaults !rootpw$', path='/etc/sudoers', new_line='Defaults !rootpw') }}}
62ebbd
+{{{ ansible_only_lineinfile(msg='Ensure that Defaults !runaspw is defined in sudoers', line_regex='^Defaults !runaspw$', path='/etc/sudoers', new_line='Defaults !runaspw') }}}
62ebbd
diff --git a/linux_os/guide/system/software/sudo/sudoers_validate_passwd/bash/shared.sh b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/bash/shared.sh
62ebbd
index ea0ac67fa1c..3b327f3fc88 100644
62ebbd
--- a/linux_os/guide/system/software/sudo/sudoers_validate_passwd/bash/shared.sh
62ebbd
+++ b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/bash/shared.sh
62ebbd
@@ -1,5 +1,17 @@
62ebbd
 # platform = multi_platform_all
62ebbd
 
62ebbd
+{{%- macro delete_line_in_sudoers_d(line) %}}
62ebbd
+if grep -x '^{{{line}}}$' /etc/sudoers.d/*; then
62ebbd
+    find /etc/sudoers.d/ -type f -exec sed -i "/{{{line}}}/d" {} \;
62ebbd
+fi
62ebbd
+{{%- endmacro %}}
62ebbd
+
62ebbd
+{{{- delete_line_in_sudoers_d("Defaults !targetpw") }}}
62ebbd
+{{{- delete_line_in_sudoers_d("Defaults !rootpw") }}}
62ebbd
+{{{- delete_line_in_sudoers_d("Defaults !runaspw") }}}
62ebbd
+
62ebbd
 {{{ set_config_file(path="/etc/sudoers", parameter="Defaults !targetpw", value="", create=true, insensitive=false, separator="", separator_regex="", prefix_regex="") }}}
62ebbd
 {{{ set_config_file(path="/etc/sudoers", parameter="Defaults !rootpw", value="", create=true, insensitive=false, separator="", separator_regex="", prefix_regex="") }}}
62ebbd
 {{{ set_config_file(path="/etc/sudoers", parameter="Defaults !runaspw", value="", create=true, insensitive=false, separator="", separator_regex="", prefix_regex="") }}}
62ebbd
+
62ebbd
+
62ebbd
diff --git a/linux_os/guide/system/software/sudo/sudoers_validate_passwd/oval/shared.xml b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/oval/shared.xml
62ebbd
index 646e6bfb7c0..b3fadd53bee 100644
62ebbd
--- a/linux_os/guide/system/software/sudo/sudoers_validate_passwd/oval/shared.xml
62ebbd
+++ b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/oval/shared.xml
62ebbd
@@ -8,17 +8,17 @@
62ebbd
       </criteria>
62ebbd
   </definition>
62ebbd
 
62ebbd
-  
62ebbd
+  
62ebbd
   id="test_sudoers_targetpw_config" version="1">
62ebbd
     <ind:object object_ref="object_test_sudoers_targetpw_config" />
62ebbd
   </ind:textfilecontent54_test>
62ebbd
 
62ebbd
-  
62ebbd
+  
62ebbd
   id="test_sudoers_rootpw_config" version="1">
62ebbd
     <ind:object object_ref="object_test_sudoers_rootpw_config" />
62ebbd
   </ind:textfilecontent54_test>
62ebbd
 
62ebbd
-  
62ebbd
+  
62ebbd
   id="test_sudoers_runaspw_config" version="1">
62ebbd
     <ind:object object_ref="object_test_sudoers_runaspw_config" />
62ebbd
   </ind:textfilecontent54_test>
62ebbd
@@ -26,19 +26,19 @@
62ebbd
   <ind:textfilecontent54_object id="object_test_sudoers_targetpw_config" version="1">
62ebbd
     <ind:filepath operation="pattern match">^/etc/sudoers(\.d/.*)?$</ind:filepath>
62ebbd
     <ind:pattern operation="pattern match">^Defaults !targetpw$\r?\n</ind:pattern>
62ebbd
-    <ind:instance datatype="int">1</ind:instance>
62ebbd
+    <ind:instance operation="greater than or equal" datatype="int">1</ind:instance>
62ebbd
   </ind:textfilecontent54_object>
62ebbd
 
62ebbd
   <ind:textfilecontent54_object id="object_test_sudoers_rootpw_config" version="1">
62ebbd
     <ind:filepath operation="pattern match">^/etc/sudoers(\.d/.*)?$</ind:filepath>
62ebbd
     <ind:pattern operation="pattern match">^Defaults !rootpw$\r?\n</ind:pattern>
62ebbd
-    <ind:instance datatype="int">1</ind:instance>
62ebbd
+    <ind:instance operation="greater than or equal" datatype="int">1</ind:instance>
62ebbd
   </ind:textfilecontent54_object>
62ebbd
 
62ebbd
   <ind:textfilecontent54_object id="object_test_sudoers_runaspw_config" version="1">
62ebbd
     <ind:filepath operation="pattern match">^/etc/sudoers(\.d/.*)?$</ind:filepath>
62ebbd
     <ind:pattern operation="pattern match">^Defaults !runaspw$\r?\n</ind:pattern>
62ebbd
-    <ind:instance datatype="int">1</ind:instance>
62ebbd
+    <ind:instance operation="greater than or equal" datatype="int">1</ind:instance>
62ebbd
   </ind:textfilecontent54_object>
62ebbd
 
62ebbd
 </def-group>
62ebbd
diff --git a/linux_os/guide/system/software/sudo/sudoers_validate_passwd/rule.yml b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/rule.yml
62ebbd
index ccc29b77d15..698021d8fd0 100644
62ebbd
--- a/linux_os/guide/system/software/sudo/sudoers_validate_passwd/rule.yml
62ebbd
+++ b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/rule.yml
62ebbd
@@ -42,7 +42,8 @@ ocil_clause: 'invoke user passwd when using sudo'
62ebbd
 ocil: |-
62ebbd
     Run the following command to Verify that the sudoers security policy is configured to use the invoking user's password for privilege escalation:
62ebbd
     
 sudo egrep -i '(!rootpw|!targetpw|!runaspw)' /etc/sudoers /etc/sudoers.d/* | grep -v '#'
62ebbd
-    If no results are returned, this is a finding
62ebbd
+    If no results are returned, this is a finding.
62ebbd
+    If results are returned from more than one file location, this is a finding.
62ebbd
     If "Defaults !targetpw" is not defined, this is a finding.
62ebbd
     If "Defaults !rootpw" is not defined, this is a finding.
62ebbd
     If "Defaults !runaspw" is not defined, this is a finding.
62ebbd
diff --git a/linux_os/guide/system/software/sudo/sudoers_validate_passwd/tests/sudoers_d_duplicate.fail.sh b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/tests/sudoers_d_duplicate.fail.sh
62ebbd
new file mode 100644
62ebbd
index 00000000000..a258d108a00
62ebbd
--- /dev/null
62ebbd
+++ b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/tests/sudoers_d_duplicate.fail.sh
62ebbd
@@ -0,0 +1,9 @@
62ebbd
+# platform = multi_platform_fedora,multi_platform_ol,multi_platform_rhel,SUSE Linux Enterprise 15
62ebbd
+# packages = sudo
62ebbd
+
62ebbd
+echo 'Defaults !targetpw' >> /etc/sudoers
62ebbd
+echo 'Defaults !rootpw' >> /etc/sudoers
62ebbd
+echo 'Defaults !runaspw' >> /etc/sudoers
62ebbd
+echo 'Defaults !targetpw' >> /etc/sudoers.d/00-complianceascode.conf
62ebbd
+echo 'Defaults !rootpw' >> /etc/sudoers.d/00-complianceascode.conf
62ebbd
+echo 'Defaults !runaspw' >> /etc/sudoers.d/00-complianceascode.conf
62ebbd
diff --git a/linux_os/guide/system/software/sudo/sudoers_validate_passwd/tests/sudoers_validate_passwd_duplicates.fail.sh b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/tests/sudoers_validate_passwd_duplicates.fail.sh
62ebbd
new file mode 100644
62ebbd
index 00000000000..6247b5230e4
62ebbd
--- /dev/null
62ebbd
+++ b/linux_os/guide/system/software/sudo/sudoers_validate_passwd/tests/sudoers_validate_passwd_duplicates.fail.sh
62ebbd
@@ -0,0 +1,7 @@
62ebbd
+# platform = multi_platform_fedora,multi_platform_ol,multi_platform_rhel,SUSE Linux Enterprise 15
62ebbd
+# packages = sudo
62ebbd
+
62ebbd
+echo 'Defaults !targetpw' >> /etc/sudoers
62ebbd
+echo 'Defaults !rootpw' >> /etc/sudoers
62ebbd
+echo 'Defaults !runaspw' >> /etc/sudoers
62ebbd
+echo 'Defaults !runaspw' >> /etc/sudoers