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

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