diff --git a/net-mgmt/net-snmp/files/snmpd.in b/net-mgmt/net-snmp/files/snmpd.in --- a/net-mgmt/net-snmp/files/snmpd.in +++ b/net-mgmt/net-snmp/files/snmpd.in @@ -10,7 +10,8 @@ # snmpd_conffile="" # # Add the following line to make snmpd drop privileges after initialization. -# This might invalidate existing SNMPv3 users. +# This might invalidate existing SNMPv3 users. Make sure that configuration +# files are readable by the snmpd user. # # snmpd_sugid="YES" # @@ -32,8 +33,24 @@ start_precmd=net_snmpd_precmd -net_snmpd_precmd () { - local flag conffile snmpd_conffile_set +check_conffile() +{ + local conffile + + conffile=$1 + + if [ ! -f "${conffile}" ]; then + warn "snmpd configuration file $conffile not found" + return + fi + su -m snmpd -c "test -r ${conffile}" + if [ $? -ne 0 ]; then + warn "snmpd configuration file $conffile not readable by snmpd user" + fi +} + +net_snmpd_precmd() { + local flag conffile snmpd_conffile_set readable if checkyesno snmpd_flush_cache; then rm -vf /var/net-snmp/.snmp-exec-cache @@ -52,11 +69,14 @@ esac done + # -c does not override the default config file. + check_conffile %%PREFIX%%/share/snmp/snmpd.conf for conffile in ${snmpd_conffile}; do + check_conffile ${conffile} if [ -f "${conffile}" -a -s "${conffile}" ]; then - snmpd_conffile_set="${snmpd_conffile_set},${conffile}" + snmpd_conffile_set="${snmpd_conffile_set},${conffile}" else - err 1 "snmpd configuration file $conffile not found." + err 1 "snmpd configuration file $conffile not found." fi done