Ver Fonte

Ticket #48285 - The dirsrv user/group should be created in rpm %pre, and ideally with fixed uid/gid

Description: Adding user dirsrv (uid 389) and group dirsrv (gid 389)
if they do not exist.  If the uid and the gid are in use, increase
one by one and find unused id for them.  If they exists, no change
is made.  The default user and group pair (nobody, nobody) is also
replaced with (dirsrv, dirsrv).

https://fedorahosted.org/389/ticket/48285

Reviewed by [email protected] (Thank you, William!)
Noriko Hosoi há 10 anos atrás
pai
commit
44d47d566a
2 ficheiros alterados com 23 adições e 2 exclusões
  1. 2 2
      configure.ac
  2. 21 0
      rpm/389-ds-base.spec.in

+ 2 - 2
configure.ac

@@ -328,8 +328,8 @@ configdir=/$PACKAGE_NAME/config
 schemadir=/$PACKAGE_NAME/schema
 
 # default user, group
-defaultuser=nobody
-defaultgroup=nobody
+defaultuser=dirsrv
+defaultgroup=dirsrv
 
 if test -z "$with_tmpfiles_d" ; then
    if test -d $sysconfdir/tmpfiles.d ; then

+ 21 - 0
rpm/389-ds-base.spec.in

@@ -274,6 +274,27 @@ if [ -n "$DEBUGPOSTTRANS" ] ; then
    output=$DEBUGPOSTTRANS
    output2=${DEBUGPOSTTRANS}.upgrade
 fi
+
+has_dirsrv=`/usr/bin/egrep -i "^dirsrv\>" /etc/passwd` || :
+if [ "$has_dirsrv" = "" ]; then
+  dirsrv_uid=389
+    while [ "`getent passwd | awk -F: '{print $3}' | grep $dirsrv_uid`" != "" ]; do
+    dirsrv_uid=`expr $dirsrv_uid + 1`
+  done
+    echo "User dirsrv does not exist, create it with uid %dirsrv_uid." >> $output 2>&1 || :
+  /usr/sbin/useradd -c "389-ds-base" -u $dirsrv_uid \
+      -s /sbin/nologin -r -d /usr/share/dirsrv dirsrv 2> /dev/null || :
+  fi
+  has_dirsrv=`/usr/bin/egrep -i "^dirsrv\>" /etc/group` || :
+  if [ "$has_dirsrv" = "" ]; then
+    dirsrv_gid=389
+  while [ "`getent group | grep $dirsrv_gid`" != "" ]; do
+      dirsrv_gid=`expr $dirsrv_gid + 1`
+    done
+  echo "Group dirsrv does not exist, create it with uid %dirsrv_gid." >> $output 2>&1 || :
+    /usr/sbin/groupadd -g $dirsrv_gid -r dirsrv 2> /dev/null || :
+fi
+
 echo looking for instances in %{_sysconfdir}/%{pkgname} > $output 2>&1 || :
 instbase="%{_sysconfdir}/%{pkgname}"
 for dir in $instbase/slapd-* ; do