Skip to content

Commit

Permalink
Revert "Remove 'exec' from configure_bashrc_exec_tmux"
Browse files Browse the repository at this point in the history
This reverts commit 0acdf79.
  • Loading branch information
vojtapolasek committed Feb 8, 2024
1 parent 17ea373 commit 54b54f7
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
ansible.builtin.find:
paths: '/etc'
patterns: 'bashrc'
contains: '.*case "$name" in sshd|login\) tmux ;; esac.*'
contains: '.*case "$name" in sshd|login\) exec tmux ;; esac.*'
register: tmux_in_bashrc

- name: "{{{ rule_title }}}: Determine If the Tmux Launch Script Is Present in /etc/profile.d/*.sh"
ansible.builtin.find:
paths: '/etc/profile.d'
patterns: '*.sh'
contains: .*case "$name" in sshd|login\) tmux ;; esac.*
contains: .*case "$name" in sshd|login\) exec tmux ;; esac.*
register: tmux_in_profile_d

- name: "{{{ rule_title }}}: Insert the Correct Script into /etc/profile.d/tmux.sh"
Expand All @@ -25,7 +25,7 @@
if [ "$PS1" ]; then
parent=$(ps -o ppid= -p $$)
name=$(ps -o comm= -p $parent)
case "$name" in sshd|login) tmux ;; esac
case "$name" in sshd|login) exec tmux ;; esac
fi
create: true
when:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
# complexity = low
# disruption = low

if ! grep -x ' case "$name" in sshd|login) tmux ;; esac' /etc/bashrc; then
if ! grep -x ' case "$name" in sshd|login) exec tmux ;; esac' /etc/bashrc; then
cat >> /etc/profile.d/tmux.sh <<'EOF'
if [ "$PS1" ]; then
parent=$(ps -o ppid= -p $$)
name=$(ps -o comm= -p $parent)
case "$name" in sshd|login) tmux ;; esac
case "$name" in sshd|login) exec tmux ;; esac
fi
EOF
chmod 0644 /etc/profile.d/tmux.sh
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<def-group>
<definition class="compliance" id="configure_bashrc_exec_tmux" version="1">
{{{ oval_metadata("Check if tmux is configured to exec at the end of bashrc.") }}}
<criteria comment="Check tmux configured at the end of bashrc" operator="AND">
<criteria comment="Check exec tmux configured at the end of bashrc" operator="AND">
<criterion comment="check tmux is configured to exec on the last line of /etc/bashrc"
test_ref="test_configure_bashrc_exec_tmux" />
</criteria>
Expand All @@ -14,7 +14,7 @@
<ind:textfilecontent54_object id="obj_configure_bashrc_exec_tmux" version="1">
<ind:behaviors singleline="true" multiline="false" />
<ind:filepath operation="pattern match">^/etc/bashrc$|^/etc/profile\.d/.*$</ind:filepath>
<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\) tmux ;; esac\nfi</ind:pattern>
<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>
<ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
</ind:textfilecontent54_object>
</def-group>
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ocil: |-
<pre>$ sudo grep tmux /etc/bashrc /etc/profile.d/*
/etc/profile.d/tmux.sh: case "$name" in (sshd|login) tmux ;; esac</pre>
/etc/profile.d/tmux.sh: case "$name" in (sshd|login) exec tmux ;; esac</pre>
Review the tmux script by using the following example:
Expand All @@ -48,7 +48,7 @@ ocil: |-
if [ "$PS1" ]; then
parent=$(ps -o ppid= -p $$)
name=$(ps -o comm= -p $parent)
case "$name" in (sshd|login) tmux ;; esac
case "$name" in (sshd|login) exec tmux ;; esac
fi</pre>
If the shell file is not configured as the example above, is commented out, or is missing, this is a finding.
Expand All @@ -63,7 +63,7 @@ fixtext: |-
if [ "$PS1" ]; then
parent=$(ps -o ppid= -p $$)
name=$(ps -o comm= -p $parent)
case "$name" in sshd|login) tmux ;; esac
case "$name" in sshd|login) exec tmux ;; esac
fi
Then, ensure a correct mode of /etc/profile.d/tmux.sh using this command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cat >> /etc/bashrc <<'EOF'
if [ "$PS1" ]; then
parent=$(ps -o ppid= -p $$)
name=$(ps -o comm= -p $parent)
case "$name" in sshd|login) tmux ;; esac
case "$name" in sshd|login) exec tmux ;; esac
fi
EOF

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cat >> /etc/profile.d/00-complianceascode.conf <<'EOF'
if [ "$PS1" ]; then
parent=$(ps -o ppid= -p $$)
name=$(ps -o comm= -p $parent)
case "$name" in sshd|login) tmux ;; esac
case "$name" in sshd|login) exec tmux ;; esac
fi
EOF

Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ cat >> /etc/profile.d/00-complianceascode.conf <<'EOF'
if [ "$PS1" ]; then
parent=$(ps -o ppid= -p $$)
name=$(ps -o comm= -p $parent)
case "$name" in sshd|login) tmux ;; esac
case "$name" in sshd|login) exec tmux ;; esac
fi
EOF

cat >> /etc/bashrc <<'EOF'
if [ "$PS1" ]; then
parent=$(ps -o ppid= -p $$)
name=$(ps -o comm= -p $parent)
case "$name" in sshd|login) tmux ;; esac
case "$name" in sshd|login) exec tmux ;; esac
fi
EOF

0 comments on commit 54b54f7

Please sign in to comment.