From 582d8e227092a3b70bf0dd2cc65ceee3dba6526b Mon Sep 17 00:00:00 2001
From: Coty Sutherland <csutherl@redhat.com>
Date: Thu, 26 Sep 2019 16:05:30 -0400
Subject: [PATCH] Resolves: rhbz#1510522 man page uid and gid mismatch for
 service accounts

---
 tomcat.spec | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/tomcat.spec b/tomcat.spec
index d53c576..c64d9ea 100644
--- a/tomcat.spec
+++ b/tomcat.spec
@@ -35,7 +35,7 @@
 %global packdname apache-tomcat-%{version}-src
 %global servletspec 4.0
 %global elspec 3.0
-%global tcuid 91
+%global tcuid 53
 # Recommended version is specified in java/org/apache/catalina/core/AprLifecycleListener.java
 %global native_version 1.2.21
 
@@ -59,7 +59,7 @@
 Name:          tomcat
 Epoch:         1
 Version:       %{major_version}.%{minor_version}.%{micro_version}
-Release:       1%{?dist}
+Release:       2%{?dist}
 Summary:       Apache Servlet/JSP Engine, RI for Servlet %{servletspec}/JSP %{jspspec} API
 
 License:       ASL 2.0
@@ -455,9 +455,14 @@ done
 
 %pre
 # add the tomcat user and group
-%{_sbindir}/groupadd -g %{tcuid} -r tomcat 2>/dev/null || :
-%{_sbindir}/useradd -c "Apache Tomcat" -u %{tcuid} -g tomcat \
-    -s /sbin/nologin -r -d %{homedir} tomcat 2>/dev/null || :
+getent group tomcat >/dev/null || %{_sbindir}/groupadd -f -g %{tcuid} -r tomcat
+if ! getent passwd tomcat >/dev/null ; then
+    if ! getent passwd %{tcuid} >/dev/null ; then
+        %{_sbindir}/useradd -r -u %{tcuid} -g tomcat -d %{homedir} -s /sbin/nologin -c "Apache Tomcat" tomcat
+        # Tomcat uses a reserved ID, so there should never be an else
+    fi
+fi
+exit 0
 
 %post
 # install but don't activate
@@ -610,6 +615,9 @@ fi
 %attr(0660,tomcat,tomcat) %verify(not size md5 mtime) %{logdir}/catalina.out
 
 %changelog
+* Thu Sep 26 2019 Coty Sutherland <csutherl@redhat.com> - 1:9.0.26-2
+- Resolves: rhbz#1510522 man page uid and gid mismatch for service accounts
+
 * Thu Sep 26 2019 Coty Sutherland <csutherl@redhat.com> - 1:9.0.26-1
 - Update to 9.0.26
 - Resolves: rhbz#1523112 tomcat systemd does not cope with - in service names