Blame SOURCES/scap-security-guide-0.1.61-update_accounts_password_template-PR_8164.patch

07cb6b
diff --git a/docs/templates/template_reference.md b/docs/templates/template_reference.md
07cb6b
index 65bc439225e..fef4679be39 100644
07cb6b
--- a/docs/templates/template_reference.md
07cb6b
+++ b/docs/templates/template_reference.md
07cb6b
@@ -2,17 +2,20 @@
07cb6b
 
07cb6b
 #### accounts_password
07cb6b
 -   Checks if PAM enforces password quality requirements. Checks the
07cb6b
-    configuration in `/etc/pam.d/system-auth` (for RHEL 6 systems) or
07cb6b
-    `/etc/security/pwquality.conf` (on other systems).
07cb6b
+    configuration in `/etc/security/pwquality.conf`.
07cb6b
 
07cb6b
 -   Parameters:
07cb6b
 
07cb6b
-    -   **variable** - PAM `pam_cracklib` (on RHEL 6) or `pam_pwquality`
07cb6b
-        (on other systems) module name, eg. `ucredit`, `ocredit`
07cb6b
+    -   **variable** - PAM `pam_pwquality` password quality
07cb6b
+        requirement, eg. `ucredit`, `ocredit`
07cb6b
 
07cb6b
     -   **operation** - OVAL operation, eg. `less than or equal`
07cb6b
 
07cb6b
--   Languages: OVAL
07cb6b
+    -   **zero_comparison_operation** - (optional) OVAL operation, eg. `greater than`.
07cb6b
+        When set, it will test if the **variable** value matches the OVAL operation
07cb6b
+        when compared to zero.
07cb6b
+
07cb6b
+-   Languages: Ansible, Bash, OVAL
07cb6b
 
07cb6b
 #### auditd_lineinfile
07cb6b
 -   Checks configuration options of the Audit Daemon in
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_maxclassrepeat/rule.yml b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_maxclassrepeat/rule.yml
07cb6b
index 912c783650a..9a829ac5119 100644
07cb6b
--- a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_maxclassrepeat/rule.yml
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_maxclassrepeat/rule.yml
07cb6b
@@ -47,7 +47,7 @@ ocil_clause: 'that is not the case'
07cb6b
 ocil: |-
07cb6b
     To check the value for maximum consecutive repeating characters, run the following command:
07cb6b
     
$ grep maxclassrepeat /etc/security/pwquality.conf
07cb6b
-    For DoD systems, the output should show <tt>maxclassrepeat</tt>=4.
07cb6b
+    For DoD systems, the output should show <tt>maxclassrepeat</tt>=4 or less but greater than zero.
07cb6b
 
07cb6b
 platform: pam
07cb6b
 
07cb6b
@@ -56,3 +56,4 @@ template:
07cb6b
     vars:
07cb6b
         variable: maxclassrepeat
07cb6b
         operation: less than or equal
07cb6b
+        zero_comparison_operation: greater than
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_maxclassrepeat/tests/correct_value.pass.sh b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_maxclassrepeat/tests/correct_value.pass.sh
07cb6b
new file mode 100644
07cb6b
index 00000000000..5d91559d4a2
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_maxclassrepeat/tests/correct_value.pass.sh
07cb6b
@@ -0,0 +1,8 @@
07cb6b
+#!/bin/bash
07cb6b
+
07cb6b
+if grep -q 'maxclassrepeat' /etc/security/pwquality.conf; then
07cb6b
+	sed -i 's/.*maxclassrepeat.*/maxclassrepeat = 4/' /etc/security/pwquality.conf
07cb6b
+else
07cb6b
+	echo "maxclassrepeat = 4" >> /etc/security/pwquality.conf
07cb6b
+fi
07cb6b
+
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_maxclassrepeat/tests/correct_value_less_than_variable.pass.sh b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_maxclassrepeat/tests/correct_value_less_than_variable.pass.sh
07cb6b
new file mode 100644
07cb6b
index 00000000000..4bd8070eb7e
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_maxclassrepeat/tests/correct_value_less_than_variable.pass.sh
07cb6b
@@ -0,0 +1,8 @@
07cb6b
+#!/bin/bash
07cb6b
+
07cb6b
+if grep -q 'maxclassrepeat' /etc/security/pwquality.conf; then
07cb6b
+	sed -i 's/.*maxclassrepeat.*/maxclassrepeat = 2/' /etc/security/pwquality.conf
07cb6b
+else
07cb6b
+	echo "maxclassrepeat = 2" >> /etc/security/pwquality.conf
07cb6b
+fi
07cb6b
+
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_maxclassrepeat/tests/negative_value.fail.sh b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_maxclassrepeat/tests/negative_value.fail.sh
07cb6b
new file mode 100644
07cb6b
index 00000000000..61538a4945f
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_maxclassrepeat/tests/negative_value.fail.sh
07cb6b
@@ -0,0 +1,7 @@
07cb6b
+#!/bin/bash
07cb6b
+
07cb6b
+if grep -q 'maxclassrepeat' /etc/security/pwquality.conf; then
07cb6b
+	sed -i 's/.*maxclassrepeat.*/maxclassrepeat = -1/' /etc/security/pwquality.conf
07cb6b
+else
07cb6b
+	echo "maxclassrepeat = -1" >> /etc/security/pwquality.conf
07cb6b
+fi
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_maxclassrepeat/tests/wrong_value.fail.sh b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_maxclassrepeat/tests/wrong_value.fail.sh
07cb6b
new file mode 100644
07cb6b
index 00000000000..2218250ec7b
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_maxclassrepeat/tests/wrong_value.fail.sh
07cb6b
@@ -0,0 +1,8 @@
07cb6b
+#!/bin/bash
07cb6b
+
07cb6b
+if grep -q 'maxclassrepeat' /etc/security/pwquality.conf; then
07cb6b
+	sed -i 's/.*maxclassrepeat.*/maxclassrepeat = 5/' /etc/security/pwquality.conf
07cb6b
+else
07cb6b
+	echo "maxclassrepeat = 5" >> /etc/security/pwquality.conf
07cb6b
+fi
07cb6b
+
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_maxclassrepeat/tests/wrong_value_0.fail.sh b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_maxclassrepeat/tests/wrong_value_0.fail.sh
07cb6b
new file mode 100644
07cb6b
index 00000000000..780873c6a86
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_maxclassrepeat/tests/wrong_value_0.fail.sh
07cb6b
@@ -0,0 +1,8 @@
07cb6b
+#!/bin/bash
07cb6b
+
07cb6b
+if grep -q 'maxclassrepeat' /etc/security/pwquality.conf; then
07cb6b
+	sed -i 's/.*maxclassrepeat.*/maxclassrepeat = 0/' /etc/security/pwquality.conf
07cb6b
+else
07cb6b
+	echo "maxclassrepeat = 0" >> /etc/security/pwquality.conf
07cb6b
+fi
07cb6b
+
07cb6b
diff --git a/shared/templates/accounts_password/oval.template b/shared/templates/accounts_password/oval.template
07cb6b
index 332a2800317..b995db11ea4 100644
07cb6b
--- a/shared/templates/accounts_password/oval.template
07cb6b
+++ b/shared/templates/accounts_password/oval.template
07cb6b
@@ -7,11 +7,14 @@
07cb6b
     </criteria>
07cb6b
   </definition>
07cb6b
 
07cb6b
-  
07cb6b
+  
07cb6b
   comment="check the configuration of /etc/security/pwquality.conf"
07cb6b
   id="test_password_pam_pwquality_{{{ VARIABLE }}}" version="3">
07cb6b
     <ind:object object_ref="obj_password_pam_pwquality_{{{ VARIABLE }}}" />
07cb6b
     <ind:state state_ref="state_password_pam_{{{ VARIABLE }}}" />
07cb6b
+  {{%- if ZERO_COMPARISON_OPERATION %}}
07cb6b
+    <ind:state state_ref="state_password_pam_{{{ VARIABLE }}}_zero_comparison" />
07cb6b
+  {{%- endif %}}
07cb6b
   </ind:textfilecontent54_test>
07cb6b
 
07cb6b
   <ind:textfilecontent54_object id="obj_password_pam_pwquality_{{{ VARIABLE }}}" version="3">
07cb6b
@@ -24,5 +27,11 @@
07cb6b
     <ind:subexpression datatype="int" operation="{{{ OPERATION }}}" var_ref="var_password_pam_{{{ VARIABLE }}}" />
07cb6b
   </ind:textfilecontent54_state>
07cb6b
 
07cb6b
+  {{%- if ZERO_COMPARISON_OPERATION %}}
07cb6b
+  <ind:textfilecontent54_state id="state_password_pam_{{{ VARIABLE }}}_zero_comparison" version="1">
07cb6b
+    <ind:subexpression datatype="int" operation="{{{ ZERO_COMPARISON_OPERATION }}}" >0</ind:subexpression>
07cb6b
+  </ind:textfilecontent54_state>
07cb6b
+  {{%- endif %}}
07cb6b
+
07cb6b
   <external_variable comment="External variable for pam_{{{ VARIABLE }}}" datatype="int" id="var_password_pam_{{{ VARIABLE }}}" version="3" />
07cb6b
 </def-group>
07cb6b
diff --git a/shared/templates/accounts_password/template.py b/shared/templates/accounts_password/template.py
07cb6b
index 65c25ec7991..ab849d1fa72 100644
07cb6b
--- a/shared/templates/accounts_password/template.py
07cb6b
+++ b/shared/templates/accounts_password/template.py
07cb6b
@@ -1,4 +1,7 @@
07cb6b
+from ssg.utils import parse_template_boolean_value
07cb6b
+
07cb6b
 def preprocess(data, lang):
07cb6b
     if lang == "oval":
07cb6b
         data["sign"] = "-?" if data["variable"].endswith("credit") else ""
07cb6b
+    data["zero_comparison_operation"] = data.get("zero_comparison_operation", None)
07cb6b
     return data