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

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