From 21177e5d44dfd6f4fa6de79737c1e55c4b22660a Mon Sep 17 00:00:00 2001 From: Watson Sato Date: Tue, 3 May 2022 10:49:44 +0200 Subject: [PATCH] Edited PR_8656 to apply on 0.1.60 --- .../one_sysctl_conf_one_sysctl_d.fail.sh | 11 +++ .../tests/two_sysctls_on_d.fail.sh | 11 +++ .../tests/two_sysctls_on_same_file.pass.sh | 11 +++ .../two_sysctls_on_same_file_name.fail.sh | 11 +++ shared/templates/sysctl/bash.template | 2 +- shared/templates/sysctl/oval.template | 99 +++++++++++++------ 6 files changed, 114 insertions(+), 31 deletions(-) create mode 100644 linux_os/guide/system/network/network-kernel/network_host_and_router_parameters/sysctl_net_ipv4_conf_default_accept_source_route/tests/one_sysctl_conf_one_sysctl_d.fail.sh create mode 100644 linux_os/guide/system/network/network-kernel/network_host_and_router_parameters/sysctl_net_ipv4_conf_default_accept_source_route/tests/two_sysctls_on_d.fail.sh create mode 100644 linux_os/guide/system/network/network-kernel/network_host_and_router_parameters/sysctl_net_ipv4_conf_default_accept_source_route/tests/two_sysctls_on_same_file.pass.sh create mode 100644 linux_os/guide/system/network/network-kernel/network_host_and_router_parameters/sysctl_net_ipv4_conf_default_accept_source_route/tests/two_sysctls_on_same_file_name.fail.sh diff --git a/linux_os/guide/system/network/network-kernel/network_host_and_router_parameters/sysctl_net_ipv4_conf_default_accept_source_route/tests/one_sysctl_conf_one_sysctl_d.fail.sh b/linux_os/guide/system/network/network-kernel/network_host_and_router_parameters/sysctl_net_ipv4_conf_default_accept_source_route/tests/one_sysctl_conf_one_sysctl_d.fail.sh new file mode 100644 index 0000000..b2bc2f8 --- /dev/null +++ b/linux_os/guide/system/network/network-kernel/network_host_and_router_parameters/sysctl_net_ipv4_conf_default_accept_source_route/tests/one_sysctl_conf_one_sysctl_d.fail.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Clean sysctl config directories +rm -rf /usr/lib/sysctl.d/* /run/sysctl.d/* /etc/sysctl.d/* + +sed -i "/net.ipv4.conf.default.accept_source_route/d" /etc/sysctl.conf +echo "net.ipv4.conf.default.accept_source_route = 0" >> /etc/sysctl.conf + +echo "net.ipv4.conf.default.accept_source_route = 0" >> /etc/sysctl.d/duplicate.conf + +sysctl -w net.ipv4.conf.default.accept_source_route=0 diff --git a/linux_os/guide/system/network/network-kernel/network_host_and_router_parameters/sysctl_net_ipv4_conf_default_accept_source_route/tests/two_sysctls_on_d.fail.sh b/linux_os/guide/system/network/network-kernel/network_host_and_router_parameters/sysctl_net_ipv4_conf_default_accept_source_route/tests/two_sysctls_on_d.fail.sh new file mode 100644 index 0000000..49a8f2e --- /dev/null +++ b/linux_os/guide/system/network/network-kernel/network_host_and_router_parameters/sysctl_net_ipv4_conf_default_accept_source_route/tests/two_sysctls_on_d.fail.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Clean sysctl config directories +rm -rf /usr/lib/sysctl.d/* /run/sysctl.d/* /etc/sysctl.d/* + +sed -i "/net.ipv4.conf.default.accept_source_route/d" /etc/sysctl.conf + +echo "net.ipv4.conf.default.accept_source_route = 0" >> /etc/sysctl.d/first.conf +echo "net.ipv4.conf.default.accept_source_route = 0" >> /etc/sysctl.d/duplicate.conf + +sysctl -w net.ipv4.conf.default.accept_source_route=0 diff --git a/linux_os/guide/system/network/network-kernel/network_host_and_router_parameters/sysctl_net_ipv4_conf_default_accept_source_route/tests/two_sysctls_on_same_file.pass.sh b/linux_os/guide/system/network/network-kernel/network_host_and_router_parameters/sysctl_net_ipv4_conf_default_accept_source_route/tests/two_sysctls_on_same_file.pass.sh new file mode 100644 index 0000000..548e616 --- /dev/null +++ b/linux_os/guide/system/network/network-kernel/network_host_and_router_parameters/sysctl_net_ipv4_conf_default_accept_source_route/tests/two_sysctls_on_same_file.pass.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Clean sysctl config directories +rm -rf /usr/lib/sysctl.d/* /run/sysctl.d/* /etc/sysctl.d/* + +sed -i "/net.ipv4.conf.default.accept_source_route/d" /etc/sysctl.conf + +echo "net.ipv4.conf.default.accept_source_route = 0" >> /etc/sysctl.conf +echo "net.ipv4.conf.default.accept_source_route = 0" >> /etc/sysctl.conf + +sysctl -w net.ipv4.conf.default.accept_source_route=0 diff --git a/linux_os/guide/system/network/network-kernel/network_host_and_router_parameters/sysctl_net_ipv4_conf_default_accept_source_route/tests/two_sysctls_on_same_file_name.fail.sh b/linux_os/guide/system/network/network-kernel/network_host_and_router_parameters/sysctl_net_ipv4_conf_default_accept_source_route/tests/two_sysctls_on_same_file_name.fail.sh new file mode 100644 index 0000000..487691d --- /dev/null +++ b/linux_os/guide/system/network/network-kernel/network_host_and_router_parameters/sysctl_net_ipv4_conf_default_accept_source_route/tests/two_sysctls_on_same_file_name.fail.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Clean sysctl config directories +rm -rf /usr/lib/sysctl.d/* /run/sysctl.d/* /etc/sysctl.d/* + +sed -i "/net.ipv4.conf.default.accept_source_route/d" /etc/sysctl.conf + +echo "net.ipv4.conf.default.accept_source_route = 0" >> /etc/sysctl.conf +echo "net.ipv4.conf.default.accept_source_route = 0" >> /etc/sysctl.d/sysctl.conf + +sysctl -w net.ipv4.conf.default.accept_source_route=0 diff --git a/shared/templates/sysctl/bash.template b/shared/templates/sysctl/bash.template index 6c82e6e..d68956f 100644 --- a/shared/templates/sysctl/bash.template +++ b/shared/templates/sysctl/bash.template @@ -6,7 +6,7 @@ # Comment out any occurrences of {{{ SYSCTLVAR }}} from /etc/sysctl.d/*.conf files for f in /etc/sysctl.d/*.conf ; do - matching_list=$(grep -P '^(?!#).*[\s]+{{{ SYSCTLVAR }}}.*$' $f | uniq ) + matching_list=$(grep -P '^(?!#).*[\s]*{{{ SYSCTLVAR }}}.*$' $f | uniq ) if ! test -z "$matching_list"; then while IFS= read -r entry; do # comment out "{{{ SYSCTLVAR }}}" matches to preserve user data diff --git a/shared/templates/sysctl/oval.template b/shared/templates/sysctl/oval.template index 646f5f3..fd19f8b 100644 --- a/shared/templates/sysctl/oval.template +++ b/shared/templates/sysctl/oval.template @@ -1,3 +1,9 @@ +{{%- if SYSCTLVAL == "" %}} +{{%- set COMMENT_VALUE="the appropriate value" %}} +{{%- else %}} +{{%- set COMMENT_VALUE=SYSCTLVAL %}} +{{%- endif %}} + {{% macro state_static_sysctld(prefix) -%}} {{%- if SYSCTLVAL == "" %}} @@ -6,7 +12,7 @@ {{%- endmacro -%}} {{%- macro sysctl_match() -%}} {{%- if SYSCTLVAL == "" -%}} - (?:^|.*\n)[^#]*{{{ SYSCTLVAR }}}[\s]*=[\s]*(\d+)[\s]*\n + ^[\s]*{{{ SYSCTLVAR }}}[\s]*=[\s]*(\d+)[\s]*$ 1 {{%- else -%}} {{% if OPERATION == "pattern match" %}} @@ -53,20 +59,12 @@ - {{{ oval_metadata("The kernel '" + SYSCTLVAR + "' parameter should be set to " + ("'" + SYSCTLVAL + "'") if SYSCTLVAL else " the appropriate value" + " in the system runtime.") }}} + {{{ oval_metadata("The kernel '" + SYSCTLVAR + "' parameter should be set to " + COMMENT_VALUE + " in the system runtime.") }}} -{{%- if SYSCTLVAL == "" %}} - -{{%- else %}} - -{{%- endif %}} + -{{% if SYSCTLVAL == "" %}} - -{{%- else %}} - -{{%- endif %}} + @@ -96,25 +94,21 @@ - {{{ oval_metadata("The kernel '" + SYSCTLVAR + "' parameter should be set to " + ("'" + SYSCTLVAL + "'") if SYSCTLVAL else " the appropriate value" + " in the system configuration.") }}} -{{%- if SYSCTLVAL == "" %}} - - - - - - - -{{%- else %}} - - - - - - - + {{{ oval_metadata("The kernel '" + SYSCTLVAR + "' parameter should be set to " + COMMENT_VALUE + " in the system configuration.") }}} + + + + + + + + + -{{%- endif %}} @@ -133,6 +127,51 @@ {{{ state_static_sysctld("usr_lib_sysctld") }}} + + + + + + + local_var_unique_sysctl_{{{ SYSCTLID }}}_counter + + + + 1 + + + + + + + + + + + + + + object_static_etc_sysctls_{{{ SYSCTLID }}} + object_static_run_usr_sysctls_{{{ SYSCTLID }}} + + + + + + object_static_sysctl_{{{ SYSCTLID }}} + object_static_etc_sysctld_{{{ SYSCTLID }}} + + + + + + object_static_run_sysctld_{{{ SYSCTLID }}} + object_static_usr_lib_sysctld_{{{ SYSCTLID }}} + + + /etc/sysctl.conf {{{ sysctl_match() }}} -- 2.34.1