From: Eric McDonald Date: Sat, 7 Mar 2026 22:29:16 +0000 (-0800) Subject: net-snmp: fix newline when RestrictOID is neither yes nor no X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=136bff9a8e85755bdb132d741a8e2f5937d3ba57;p=openwrt-packages.git net-snmp: fix newline when RestrictOID is neither yes nor no snmpd_access_default_add, snmpd_access_HostName_add, and snmpd_access_HostIP_add check if RestrictOID is `yes` or `no` but fail to write a newline for other values of RestrictOID (e.g., `true`, `false`) or if unset, corrupting the generated config. Fix by using config_get_bool and restructuring to write either a complete line or nothing. Also require RestrictedOID to be non-empty when RestrictOID is enabled. This is a breaking change for configs where RestrictOID is set to a value that the old code did not match as `yes` (e.g., `true`, `1`, `on`, `enabled`) but config_get_bool evaluates as true. In practice, this is unlikely to affect existing installs unless a user is unknowingly relying on unintended behavior or is deliberately relying on the old code's non-standard boolean evaluation; this latter case is considered unlikely by this commit's author. Configs where RestrictOID is enabled but RestrictedOID is empty are also affected; previously a directive with a trailing space was written, now no directive is written. Signed-off-by: Eric McDonald --- diff --git a/net/net-snmp/files/snmpd.init b/net/net-snmp/files/snmpd.init index 371c15071..78a62a560 100644 --- a/net/net-snmp/files/snmpd.init +++ b/net/net-snmp/files/snmpd.init @@ -133,11 +133,15 @@ snmpd_access_default_add() { [ -n "$mode" ] || return 0 config_get community "$cfg" CommunityName [ -n "$community" ] || return 0 - config_get oidrestrict "$cfg" RestrictOID + + config_get_bool oidrestrict "$cfg" RestrictOID 0 config_get oid "$cfg" RestrictedOID - echo -n "$mode $community default" >> $CONFIGFILE - [ "$oidrestrict" == "yes" ] && echo " $oid" >> $CONFIGFILE - [ "$oidrestrict" == "no" ] && echo "" >> $CONFIGFILE + if [ "$oidrestrict" -eq 1 ]; then + [ -n "$oid" ] || return 0 + echo "$mode $community default $oid" >> $CONFIGFILE + else + echo "$mode $community default" >> $CONFIGFILE + fi } snmpd_access_HostName_add() { @@ -148,11 +152,15 @@ snmpd_access_HostName_add() { [ -n "$mode" ] || return 0 config_get community "$cfg" CommunityName [ -n "$community" ] || return 0 - config_get oidrestrict "$cfg" RestrictOID + + config_get_bool oidrestrict "$cfg" RestrictOID 0 config_get oid "$cfg" RestrictedOID - echo -n "$mode $community $hostname" >> $CONFIGFILE - [ "$oidrestrict" == "yes" ] && echo " $oid" >> $CONFIGFILE - [ "$oidrestrict" == "no" ] && echo "" >> $CONFIGFILE + if [ "$oidrestrict" -eq 1 ]; then + [ -n "$oid" ] || return 0 + echo "$mode $community $hostname $oid" >> $CONFIGFILE + else + echo "$mode $community $hostname" >> $CONFIGFILE + fi } snmpd_access_HostIP_add() { @@ -165,11 +173,15 @@ snmpd_access_HostIP_add() { [ -n "$mode" ] || return 0 config_get community "$cfg" CommunityName [ -n "$community" ] || return 0 - config_get oidrestrict "$cfg" RestrictOID + + config_get_bool oidrestrict "$cfg" RestrictOID 0 config_get oid "$cfg" RestrictedOID - echo -n "$mode $community $host_ip/$ip_mask" >> $CONFIGFILE - [ "$oidrestrict" == "yes" ] && echo " $oid" >> $CONFIGFILE - [ "$oidrestrict" == "no" ] && echo "" >> $CONFIGFILE + if [ "$oidrestrict" -eq 1 ]; then + [ -n "$oid" ] || return 0 + echo "$mode $community $host_ip/$ip_mask $oid" >> $CONFIGFILE + else + echo "$mode $community $host_ip/$ip_mask" >> $CONFIGFILE + fi } snmpd_pass_add() {