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

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