From nobody Tue Jun 04 18:42:44 2024 X-Original-To: dev-commits-ports-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Vtzx04vNgz5MB3q; Tue, 04 Jun 2024 18:42:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Vtzx0498bz4TWq; Tue, 4 Jun 2024 18:42:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1717526564; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=2f7vODCyFVAzOe+PanZvjA0PZDO1Y1IbEby3TPC7Ruk=; b=A6ZEPF/sRxo6NwfAQ/9My5otwPotjuWBra/PLidbxJrL4bNFb0X+rk+ZpEqq2cR01fswFP eWxF1IRrQvZyd9CPhGjikqV2e+77xR49DiyzYfVlI9uBnqhfpK6O+LoQC7vLrpWBXVp9np x1wtX6FTlO/Myx3dZq7lvoN6/ENz6+BOF9XT4xTTYHtFwSTTp9n89yqOnf2zvP4OtOqofQ xS9pEf2+g8LoUEfxKkAuXQP7+I3AyP78J6Ev5zp02OWzLLWaafGjJOBcrCa+snYyQrlWKG dbivlkrpaBJ+VrAs1fWP+iEOMAKN4V8OWYXsOcjuYUMdPBJr5YGOSQHfYwZyUg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1717526564; a=rsa-sha256; cv=none; b=a4LNxztIrpNk2FrV+09EoQa2eC/Rx5Vj8UtzXEZAzX7Eji3w5h/iQKuoIulCNobbWcTGGp eY0Rc/OlMltFb9xYm0jrvOztDa4hd0pfr3+koIm9i7YmPkkFMPjU/9We51kVmqNVaMSZLE ZrlIUqj8HjIfAPLxsILYikjlgI2VnRPJaY1o675q8pVK/sLG1CLE660kyMhqKDsCvvKW21 WYJAM/693yTM9+ZOBVFR+HeoZj72b5QvoflOwxUhc9Uid+IMrZAuU8hqcPZNSqw+fBsFoU hoQfyENlhzMlGCocHyjJqOl0T4lt8hr5WKanEw0RsL3rFysz8gihO5duuhdDxQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1717526564; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=2f7vODCyFVAzOe+PanZvjA0PZDO1Y1IbEby3TPC7Ruk=; b=e8DZ+c9OZ2KylQZW+OaEbTWItYLZiUY0tBMCP8W+iSwEugKky5fNhatIE9YAJCPMNddKp1 qpeyTvi06yYce36ggkn7uK89TCLo+yMaGJrw7AaIrOZsSycMaQq5ISx1S75LGJyqOIyBQ3 Dgytf/RvZFK0Rxc2KjN5a1+gm8LMcYGtPBYQSmzmra3yplsZONfo2q9kPEn2Lw5YtnFy88 9zsnTVUMPrTak/iK7yvteXYswQ5A9Se2phfx/WQ5KAxisDo1CrT0aY340OF39QzGTN7IXH ywmldgAhxX2Gw5hNjsr82E159csbL6QmpD6W63vrQl7Y34sNNhCtSd5pwpwNRw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Vtzx03lpgzVxW; Tue, 4 Jun 2024 18:42:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 454IgiDP039147; Tue, 4 Jun 2024 18:42:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 454IgitA039144; Tue, 4 Jun 2024 18:42:44 GMT (envelope-from git) Date: Tue, 4 Jun 2024 18:42:44 GMT Message-Id: <202406041842.454IgitA039144@gitrepo.freebsd.org> To: ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org From: Mark Johnston Subject: git: 1a7344b7ecd8 - main - net-mgmt/net-snmp: Print a warning if config files aren't readable List-Id: Commits to the main branch of the FreeBSD ports repository List-Archive: https://lists.freebsd.org/archives/dev-commits-ports-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-ports-main@freebsd.org Sender: owner-dev-commits-ports-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: ports X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1a7344b7ecd8c5073552cdd097f546e9495c11dd Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/ports/commit/?id=1a7344b7ecd8c5073552cdd097f546e9495c11dd commit 1a7344b7ecd8c5073552cdd097f546e9495c11dd Author: Mark Johnston AuthorDate: 2024-05-24 14:12:01 +0000 Commit: Mark Johnston CommitDate: 2024-06-04 18:40:37 +0000 net-mgmt/net-snmp: Print a warning if config files aren't readable Motivated by a bug report from dvl@. In his case, snmpd was able to read the configuration file initially, but failed to reload it upon receiving SIGHUP during log rotation. Approved by: zi Sponsored by: Stormshield Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D45343 --- net-mgmt/net-snmp/files/snmpd.in | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/net-mgmt/net-snmp/files/snmpd.in b/net-mgmt/net-snmp/files/snmpd.in index 7f75cacad813..6e89d9cb1c5b 100644 --- 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 @@ command=%%PREFIX%%/sbin/${name} 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 @@ net_snmpd_precmd () { 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