git: a4cc1509a9b6 - main - sysutils/nut*: Fix nut file access

From: Cy Schubert <cy_at_FreeBSD.org>
Date: Fri, 10 Feb 2023 18:26:48 UTC
The branch main has been updated by cy:

URL: https://cgit.FreeBSD.org/ports/commit/?id=a4cc1509a9b65367f76bbdf6b684035d0c3bfbc3

commit a4cc1509a9b65367f76bbdf6b684035d0c3bfbc3
Author:     Cy Schubert <cy@FreeBSD.org>
AuthorDate: 2023-02-09 16:03:07 +0000
Commit:     Cy Schubert <cy@FreeBSD.org>
CommitDate: 2023-02-10 18:26:33 +0000

    sysutils/nut*: Fix nut file access
    
    Preexisting nut files will have uucp group permissions, which will no
    longer be available to nut because it runs under its own GID. For the
    time being add code to nut_prestart() adjusting the ownership of the
    files to UID nut and GID nut.
    
    This code should be removed approximately a year from now as it is
    expected that most if not all nut installations will have correct file
    ownership by then.
    
    While here, also fix nut.newsyslog to refer to the new nut UID/GID.
    
    Reported by:    avg, Mathieu <sigsys@gmail.com>
    Fixes:          02c038c8cc15
---
 sysutils/nut-devel/Makefile            |  2 +-
 sysutils/nut-devel/files/nut.in        | 11 +++++++++++
 sysutils/nut-devel/files/nut.newsyslog |  2 +-
 sysutils/nut/Makefile                  |  2 +-
 sysutils/nut/files/nut.in              | 11 +++++++++++
 sysutils/nut/files/nut.newsyslog       |  2 +-
 6 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/sysutils/nut-devel/Makefile b/sysutils/nut-devel/Makefile
index 1f94319584fe..bff162740c92 100644
--- a/sysutils/nut-devel/Makefile
+++ b/sysutils/nut-devel/Makefile
@@ -1,6 +1,6 @@
 PORTNAME=	nut
 PORTVERSION=	${NUT_COMMIT_DATE}
-PORTREVISION=	1
+PORTREVISION=	2
 CATEGORIES=	sysutils
 PKGNAMESUFFIX=	-devel
 # MASTER_SITES=	http://www.networkupstools.org/source/${PORTVERSION:R}/
diff --git a/sysutils/nut-devel/files/nut.in b/sysutils/nut-devel/files/nut.in
index 0e4cb9e8a618..ae9ee30f03f5 100644
--- a/sysutils/nut-devel/files/nut.in
+++ b/sysutils/nut-devel/files/nut.in
@@ -32,6 +32,17 @@ start_precmd="nut_prestart"
 stop_postcmd="nut_poststop"
 
 nut_prestart() {
+	#
+	# As of PR/268960 UID/GID uucp is no longer used by nut.
+	# Instead UID/GID nut is used. Make sure preexisting nut files
+	# and directories are owned by nut instead of uucp.
+	#
+	if [ -f ${nut_prefix}/etc/nut/upsd.users ]; then
+		chgrp %%NUT_GROUP%% ${nut_prefix}/etc/nut/upsd.users
+	fi
+	find %%STATEDIR%% -user uucp -exec chown nut {} \;
+	find %%STATEDIR%% -group uucp -exec chgrp nut {} \;
+
 	${nut_prefix}/sbin/upsdrvctl start
 }
 
diff --git a/sysutils/nut-devel/files/nut.newsyslog b/sysutils/nut-devel/files/nut.newsyslog
index fc50b6c1be32..4a3a4350cee5 100644
--- a/sysutils/nut-devel/files/nut.newsyslog
+++ b/sysutils/nut-devel/files/nut.newsyslog
@@ -3,5 +3,5 @@
 # see newsyslog.conf(5) for details
 #
 # logfilename          [owner:group]    mode    count   size    when    flags   [/pid_file]     	[sig_num]
-/var/log/nut/upsd.log   uucp:uucp       644     7       100     *       J       /var/db/nut/upslog.pid
+/var/log/nut/upsd.log   nut:nut       644     7       100     *       J       /var/db/nut/upslog.pid
 
diff --git a/sysutils/nut/Makefile b/sysutils/nut/Makefile
index 81b4ebea94a9..3635e4d550fd 100644
--- a/sysutils/nut/Makefile
+++ b/sysutils/nut/Makefile
@@ -1,6 +1,6 @@
 PORTNAME=	nut
 PORTVERSION=	2.8.0
-PORTREVISION=	16
+PORTREVISION=	17
 CATEGORIES=	sysutils
 MASTER_SITES=	http://www.networkupstools.org/source/${PORTVERSION:R}/
 
diff --git a/sysutils/nut/files/nut.in b/sysutils/nut/files/nut.in
index 0e4cb9e8a618..ae9ee30f03f5 100644
--- a/sysutils/nut/files/nut.in
+++ b/sysutils/nut/files/nut.in
@@ -32,6 +32,17 @@ start_precmd="nut_prestart"
 stop_postcmd="nut_poststop"
 
 nut_prestart() {
+	#
+	# As of PR/268960 UID/GID uucp is no longer used by nut.
+	# Instead UID/GID nut is used. Make sure preexisting nut files
+	# and directories are owned by nut instead of uucp.
+	#
+	if [ -f ${nut_prefix}/etc/nut/upsd.users ]; then
+		chgrp %%NUT_GROUP%% ${nut_prefix}/etc/nut/upsd.users
+	fi
+	find %%STATEDIR%% -user uucp -exec chown nut {} \;
+	find %%STATEDIR%% -group uucp -exec chgrp nut {} \;
+
 	${nut_prefix}/sbin/upsdrvctl start
 }
 
diff --git a/sysutils/nut/files/nut.newsyslog b/sysutils/nut/files/nut.newsyslog
index fc50b6c1be32..4a3a4350cee5 100644
--- a/sysutils/nut/files/nut.newsyslog
+++ b/sysutils/nut/files/nut.newsyslog
@@ -3,5 +3,5 @@
 # see newsyslog.conf(5) for details
 #
 # logfilename          [owner:group]    mode    count   size    when    flags   [/pid_file]     	[sig_num]
-/var/log/nut/upsd.log   uucp:uucp       644     7       100     *       J       /var/db/nut/upslog.pid
+/var/log/nut/upsd.log   nut:nut       644     7       100     *       J       /var/db/nut/upslog.pid