diff --git a/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/ansible/shared.yml b/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/ansible/shared.yml index 3cc2f3b32b0..730c17f84f8 100644 --- a/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/ansible/shared.yml +++ b/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/ansible/shared.yml @@ -14,7 +14,7 @@ - name: Check if umask in {{{ etc_bash_rc }}} is already set ansible.builtin.lineinfile: path: {{{ etc_bash_rc }}} - regexp: ^[^#]*\bumask\s+ + regexp: ^[^#]*\bumask\s+\d+$ state: absent check_mode: true changed_when: false @@ -23,8 +23,8 @@ - name: Replace user umask in {{{ etc_bash_rc }}} ansible.builtin.replace: path: {{{ etc_bash_rc }}} - regexp: ^([^#]*\b)umask(\s*) - replace: \g<1>umask\g<2>{{ var_accounts_user_umask }} + regexp: ^([^#]*\b)umask\s+\d+$ + replace: \g<1>umask {{ var_accounts_user_umask }} when: - umask_replace.found > 0 diff --git a/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/oval/shared.xml b/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/oval/shared.xml index 597758a90df..bf610a8714f 100644 --- a/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/oval/shared.xml +++ b/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/oval/shared.xml @@ -16,7 +16,7 @@ {{{ etc_bash_rc }}} - ^[^#]*\bumask\s+([^#\s]*) + ^[^#]*\bumask\s+(\d{3})\s*$ 1 diff --git a/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/tests/wrong_and_mangled_and_not_at_the_begining_of_line.fail.sh b/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/tests/wrong_and_mangled_and_not_at_the_begining_of_line.fail.sh new file mode 100644 index 00000000000..e129a6ca988 --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/tests/wrong_and_mangled_and_not_at_the_begining_of_line.fail.sh @@ -0,0 +1,8 @@ +#!/bin/bash +# packages = bash + +# This TS is a regression test for https://github.com/ComplianceAsCode/content/issues/11937 + +sed -i '/umask/d' /etc/bashrc +echo " [ \`umask\` -eq 0 ] && umask 027022" >> /etc/bashrc +umask 000 diff --git a/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/tests/wrong_and_not_at_the_begining_of_line.fail.sh b/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/tests/wrong_and_not_at_the_begining_of_line.fail.sh index 7a70747b3ae..bbe2c3db1ce 100644 --- a/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/tests/wrong_and_not_at_the_begining_of_line.fail.sh +++ b/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/tests/wrong_and_not_at_the_begining_of_line.fail.sh @@ -2,5 +2,5 @@ # packages = bash sed -i '/umask/d' /etc/bashrc -echo " [ `umask` -eq 0 ] && umask 022" >> /etc/bashrc +echo " [ \`umask\` -eq 0 ] && umask 022" >> /etc/bashrc umask 000