Blame SOURCES/scap-security-guide-0.1.61-update_RHEL_08_020041-PR_8146.patch

ff1465
diff --git a/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/bash/shared.sh b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/bash/shared.sh
5fd106
index 737d725872d..08b62057bde 100644
ff1465
--- a/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/bash/shared.sh
ff1465
+++ b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/bash/shared.sh
ff1465
@@ -1,7 +1,11 @@
5fd106
 # platform = multi_platform_all
ff1465
+# reboot = true
ff1465
+# strategy = enable
ff1465
+# complexity = low
ff1465
+# disruption = low
ff1465
 
ff1465
 if ! grep -x '  case "$name" in sshd|login) exec tmux ;; esac' /etc/bashrc; then
ff1465
-    cat >> /etc/bashrc <<'EOF'
ff1465
+    cat >> /etc/profile.d/tmux.sh <<'EOF'
ff1465
 if [ "$PS1" ]; then
ff1465
   parent=$(ps -o ppid= -p $$)
ff1465
   name=$(ps -o comm= -p $parent)
ff1465
diff --git a/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/oval/shared.xml b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/oval/shared.xml
5fd106
index 00ac349e292..4cb2f9e0e04 100644
ff1465
--- a/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/oval/shared.xml
ff1465
+++ b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/oval/shared.xml
ff1465
@@ -4,21 +4,27 @@
ff1465
     <criteria comment="Check exec tmux configured at the end of bashrc" operator="AND">
ff1465
       
ff1465
         test_ref="test_configure_bashrc_exec_tmux" />
ff1465
+      <criterion comment="check tmux is running" test_ref="test_tmux_running"/>
ff1465
     </criteria>
ff1465
   </definition>
ff1465
-  
ff1465
+  
ff1465
     comment="check tmux is configured to exec on the last line of /etc/bashrc"
ff1465
     id="test_configure_bashrc_exec_tmux" version="1">
ff1465
     <ind:object object_ref="obj_configure_bashrc_exec_tmux" />
ff1465
-    <ind:state state_ref="state_configure_bashrc_exec_tmux" />
ff1465
   </ind:textfilecontent54_test>
ff1465
   <ind:textfilecontent54_object id="obj_configure_bashrc_exec_tmux" version="1">
ff1465
     <ind:behaviors singleline="true" multiline="false" />
ff1465
-    <ind:filepath>/etc/bashrc</ind:filepath>
ff1465
-    <ind:pattern operation="pattern match">^(.*)$</ind:pattern>
ff1465
-    <ind:instance datatype="int">1</ind:instance>
ff1465
+    <ind:filepath operation="pattern match">^/etc/bashrc$|^/etc/profile\.d/.*$</ind:filepath>
ff1465
+    <ind:pattern operation="pattern match">if \[ "\$PS1" \]; then\n\s+parent=\$\(ps -o ppid= -p \$\$\)\n\s+name=\$\(ps -o comm= -p \$parent\)\n\s+case "\$name" in sshd\|login\) exec tmux ;; esac\nfi</ind:pattern>
ff1465
+    <ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
ff1465
   </ind:textfilecontent54_object>
ff1465
-  <ind:textfilecontent54_state id="state_configure_bashrc_exec_tmux" version="1">
ff1465
-    <ind:subexpression datatype="string" operation="pattern match">if \[ "\$PS1" \]; then\n\s+parent=\$\(ps -o ppid= -p \$\$\)\n\s+name=\$\(ps -o comm= -p \$parent\)\n\s+case "\$name" in sshd\|login\) exec tmux ;; esac\nfi</ind:subexpression>
ff1465
-  </ind:textfilecontent54_state>
ff1465
+
ff1465
+  <unix:process58_test check="all" id="test_tmux_running" comment="is tmux running" version="1">
ff1465
+      <unix:object object_ref="obj_tmux_running"/>
ff1465
+  </unix:process58_test>
ff1465
+
ff1465
+  <unix:process58_object id="obj_tmux_running" version="1">
ff1465
+      <unix:command_line operation="pattern match">^tmux(?:|[\s]+.*)$</unix:command_line>
ff1465
+      <unix:pid datatype="int" operation="greater than">0</unix:pid>
ff1465
+  </unix:process58_object>
ff1465
 </def-group>
ff1465
diff --git a/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/rule.yml b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/rule.yml
5fd106
index 3ba0f4a2d8f..7afc5fc5e6b 100644
ff1465
--- a/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/rule.yml
ff1465
+++ b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/rule.yml
ff1465
@@ -7,12 +7,20 @@ title: 'Support session locking with tmux'
ff1465
 description: |-
ff1465
     The <tt>tmux</tt> terminal multiplexer is used to implement
ff1465
     automatic session locking. It should be started from
ff1465
-    <tt>/etc/bashrc</tt>.
ff1465
+    <tt>/etc/bashrc</tt> or drop-in files within <tt>/etc/profile.d/</tt>.
ff1465
+    Additionally it must be ensured that the <tt>tmux</tt> process is running
ff1465
+    and it can be verified with the following command:
ff1465
+    
ps all | grep tmux | grep -v grep
ff1465
 
ff1465
 rationale: |-
ff1465
     Unlike <tt>bash</tt> itself, the <tt>tmux</tt> terminal multiplexer
ff1465
     provides a mechanism to lock sessions after period of inactivity.
ff1465
 
ff1465
+warnings:
ff1465
+  - general: |-
ff1465
+        The remediation does not start the tmux process, so it must be
ff1465
+        manually started or have the system rebooted after applying the fix.
ff1465
+
ff1465
 severity: medium
ff1465
 
ff1465
 identifiers:
5fd106
@@ -26,17 +34,21 @@ references:
5fd106
     stigid@ol8: OL08-00-020041
ff1465
     stigid@rhel8: RHEL-08-020041
ff1465
 
ff1465
-ocil_clause: 'exec tmux is not present at the end of bashrc'
ff1465
+ocil_clause: 'exec tmux is not present at the end of bashrc or tmux process is not running'
ff1465
 
ff1465
 ocil: |-
ff1465
     To verify that tmux is configured to execute,
ff1465
     run the following command:
ff1465
-    
$ grep -A1 -B3 "case ..name. in sshd|login) exec tmux ;; esac" /etc/bashrc
ff1465
+    
$ grep -A1 -B3 "case ..name. in sshd|login) exec tmux ;; esac" /etc/bashrc /etc/profile.d/*
ff1465
     The output should return the following:
ff1465
     
if [ "$PS1" ]; then
ff1465
       parent=$(ps -o ppid= -p $$)
ff1465
       name=$(ps -o comm= -p $parent)
ff1465
       case "$name" in sshd|login) exec tmux ;; esac
ff1465
     fi
ff1465
+    To verify that the tmux process is running,
ff1465
+    run the following command:
ff1465
+    
ps all | grep tmux | grep -v grep
ff1465
+    If the command does not produce output, this is a finding.
ff1465
 
ff1465
 platform: machine
ff1465
diff --git a/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/correct_value.pass.sh b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/correct_value.pass.sh
ff1465
new file mode 100644
5fd106
index 00000000000..221c18665ef
ff1465
--- /dev/null
ff1465
+++ b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/correct_value.pass.sh
ff1465
@@ -0,0 +1,12 @@
ff1465
+#!/bin/bash
ff1465
+# packages = tmux
ff1465
+
ff1465
+cat >> /etc/bashrc <<'EOF'
ff1465
+if [ "$PS1" ]; then
ff1465
+  parent=$(ps -o ppid= -p $$)
ff1465
+  name=$(ps -o comm= -p $parent)
ff1465
+  case "$name" in sshd|login) exec tmux ;; esac
ff1465
+fi
ff1465
+EOF
ff1465
+
ff1465
+tmux new-session -s root -d
ff1465
diff --git a/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/correct_value_d_directory.pass.sh b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/correct_value_d_directory.pass.sh
ff1465
new file mode 100644
5fd106
index 00000000000..1702bb17e79
ff1465
--- /dev/null
ff1465
+++ b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/correct_value_d_directory.pass.sh
ff1465
@@ -0,0 +1,13 @@
ff1465
+#!/bin/bash
ff1465
+# packages = tmux
ff1465
+
ff1465
+
ff1465
+cat >> /etc/profile.d/00-complianceascode.conf <<'EOF'
ff1465
+if [ "$PS1" ]; then
ff1465
+  parent=$(ps -o ppid= -p $$)
ff1465
+  name=$(ps -o comm= -p $parent)
ff1465
+  case "$name" in sshd|login) exec tmux ;; esac
ff1465
+fi
ff1465
+EOF
ff1465
+
ff1465
+tmux new-session -s root -d
5fd106
diff --git a/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/duplicate_value_multiple_files.pass.sh b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/duplicate_value_multiple_files.pass.sh
ff1465
new file mode 100644
5fd106
index 00000000000..16d4acfcb5a
ff1465
--- /dev/null
5fd106
+++ b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/duplicate_value_multiple_files.pass.sh
5fd106
@@ -0,0 +1,20 @@
ff1465
+#!/bin/bash
5fd106
+# packages = tmux
ff1465
+
ff1465
+cat >> /etc/profile.d/00-complianceascode.conf <<'EOF'
ff1465
+if [ "$PS1" ]; then
ff1465
+  parent=$(ps -o ppid= -p $$)
ff1465
+  name=$(ps -o comm= -p $parent)
ff1465
+  case "$name" in sshd|login) exec tmux ;; esac
ff1465
+fi
ff1465
+EOF
ff1465
+
ff1465
+cat >> /etc/bashrc <<'EOF'
ff1465
+if [ "$PS1" ]; then
ff1465
+  parent=$(ps -o ppid= -p $$)
ff1465
+  name=$(ps -o comm= -p $parent)
ff1465
+  case "$name" in sshd|login) exec tmux ;; esac
ff1465
+fi
ff1465
+EOF
5fd106
+
5fd106
+tmux new-session -s root -d
ff1465
diff --git a/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/tmux_not_running.fail.sh b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/tmux_not_running.fail.sh
ff1465
new file mode 100644
5fd106
index 00000000000..6cb9d83efc5
ff1465
--- /dev/null
ff1465
+++ b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/tmux_not_running.fail.sh
ff1465
@@ -0,0 +1,13 @@
ff1465
+#!/bin/bash
ff1465
+# packages = tmux
ff1465
+# remediation = none
ff1465
+
ff1465
+cat >> /etc/bashrc <<'EOF'
ff1465
+if [ "$PS1" ]; then
ff1465
+  parent=$(ps -o ppid= -p $$)
ff1465
+  name=$(ps -o comm= -p $parent)
ff1465
+  case "$name" in sshd|login) exec tmux ;; esac
ff1465
+fi
ff1465
+EOF
ff1465
+
ff1465
+killall tmux || true
ff1465
diff --git a/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/wrong_value.fail.sh b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/wrong_value.fail.sh
ff1465
new file mode 100644
5fd106
index 00000000000..f13a8b038e4
ff1465
--- /dev/null
ff1465
+++ b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/wrong_value.fail.sh
ff1465
@@ -0,0 +1,105 @@
ff1465
+#!/bin/bash
ff1465
+# packages = tmux
ff1465
+
ff1465
+cat > /etc/bashrc <<'EOF'
ff1465
+# /etc/bashrc
ff1465
+
ff1465
+# System wide functions and aliases
ff1465
+# Environment stuff goes in /etc/profile
ff1465
+
ff1465
+# It's NOT a good idea to change this file unless you know what you
ff1465
+# are doing. It's much better to create a custom.sh shell script in
ff1465
+# /etc/profile.d/ to make custom changes to your environment, as this
ff1465
+# will prevent the need for merging in future updates.
ff1465
+
ff1465
+# Prevent doublesourcing
ff1465
+if [ -z "$BASHRCSOURCED" ]; then
ff1465
+  BASHRCSOURCED="Y"
ff1465
+
ff1465
+  # are we an interactive shell?
ff1465
+  if [ "$PS1" ]; then
ff1465
+    if [ -z "$PROMPT_COMMAND" ]; then
ff1465
+      case $TERM in
ff1465
+      xterm*|vte*)
ff1465
+        if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
ff1465
+            PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
ff1465
+        elif [ "${VTE_VERSION:-0}" -ge 3405 ]; then
ff1465
+            PROMPT_COMMAND="__vte_prompt_command"
ff1465
+        else
ff1465
+            PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"'
ff1465
+        fi
ff1465
+        ;;
ff1465
+      screen*)
ff1465
+        if [ -e /etc/sysconfig/bash-prompt-screen ]; then
ff1465
+            PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
ff1465
+        else
ff1465
+            PROMPT_COMMAND='printf "\033k%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"'
ff1465
+        fi
ff1465
+        ;;
ff1465
+      *)
ff1465
+        [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
ff1465
+        ;;
ff1465
+      esac
ff1465
+    fi
ff1465
+    # Turn on parallel history
ff1465
+    shopt -s histappend
ff1465
+    history -a
ff1465
+    # Turn on checkwinsize
ff1465
+    shopt -s checkwinsize
ff1465
+    [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
ff1465
+    # You might want to have e.g. tty in prompt (e.g. more virtual machines)
ff1465
+    # and console windows
ff1465
+    # If you want to do so, just add e.g.
ff1465
+    # if [ "$PS1" ]; then
ff1465
+    #   PS1="[\u@\h:\l \W]\\$ "
ff1465
+    # fi
ff1465
+    # to your custom modification shell script in /etc/profile.d/ directory
ff1465
+  fi
ff1465
+
ff1465
+  if ! shopt -q login_shell ; then # We're not a login shell
ff1465
+    # Need to redefine pathmunge, it gets undefined at the end of /etc/profile
ff1465
+    pathmunge () {
ff1465
+        case ":${PATH}:" in
ff1465
+            *:"$1":*)
ff1465
+                ;;
ff1465
+            *)
ff1465
+                if [ "$2" = "after" ] ; then
ff1465
+                    PATH=$PATH:$1
ff1465
+                else
ff1465
+                    PATH=$1:$PATH
ff1465
+                fi
ff1465
+        esac
ff1465
+    }
ff1465
+
ff1465
+    # By default, we want umask to get set. This sets it for non-login shell.
ff1465
+    # Current threshold for system reserved uid/gids is 200
ff1465
+    # You could check uidgid reservation validity in
ff1465
+    # /usr/share/doc/setup-*/uidgid file
ff1465
+    if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then
ff1465
+       umask 002
ff1465
+    else
ff1465
+       umask 022
ff1465
+    fi
ff1465
+
ff1465
+    SHELL=/bin/bash
ff1465
+    # Only display echos from profile.d scripts if we are no login shell
ff1465
+    # and interactive - otherwise just process them to set envvars
ff1465
+    for i in /etc/profile.d/*.sh; do
ff1465
+        if [ -r "$i" ]; then
ff1465
+            if [ "$PS1" ]; then
ff1465
+                . "$i"
ff1465
+            else
ff1465
+                . "$i" >/dev/null
ff1465
+            fi
ff1465
+        fi
ff1465
+    done
ff1465
+
ff1465
+    unset i
ff1465
+    unset -f pathmunge
ff1465
+  fi
ff1465
+
ff1465
+fi
ff1465
+# vim:ts=4:sw=4
ff1465
+EOF
ff1465
+
ff1465
+tmux new-session -s root -d