Просмотр исходного кода

add Solaris/Linux 'getent' based support for passwd/group fiddling, too.

Ralf S. Engelschall 23 лет назад
Родитель
Сommit
a12895bda7
4 измененных файлов с 49 добавлено и 36 удалено
  1. 10 10
      openpkg/aux.usrgrp.sh
  2. 2 2
      openpkg/aux.wrapsrc.sh
  3. 10 10
      openpkg/openpkg.spec
  4. 27 14
      openpkg/shtool

+ 10 - 10
openpkg/aux.usrgrp.sh

@@ -68,10 +68,10 @@ cusr=`(id -un) 2>/dev/null ||\
       (who am i | cut "-d " -f1) 2>/dev/null ||\
       echo $LOGNAME`
 cgid=`(id -g $cusr) 2>/dev/null ||\
-      ((cat /etc/passwd; ypcat passwd) 2>/dev/null |\
+      ((getent passwd; cat /etc/passwd; ypcat passwd) 2>/dev/null |\
        grep "^${cusr}:" | sed -n -e '1p' | awk -F: '{ print $4; }')`
 cgrp=`(id -gn $cusr) 2>/dev/null ||\
-      ((cat /etc/group; ypcat group) 2>/dev/null |\
+      ((getent group; cat /etc/group; ypcat group) 2>/dev/null |\
        grep ":${cgid}:" | sed -n -e '1p' | awk -F: '{ print $1; }')`
 [ ".$cgrp" = . ] && cgrp="$cusr"
 
@@ -82,10 +82,10 @@ fi
 if [ ".$sgrp" = . ]; then
     sgrp=`(id -gn $susr) 2>/dev/null`
     if [ ".$sgrp" = . ]; then
-        sgid=`(cat /etc/passwd; ypcat passwd) 2>/dev/null |\
+        sgid=`(getent passwd; cat /etc/passwd; ypcat passwd) 2>/dev/null |\
               grep "^${susr}:" | sed -n -e '1p' | awk -F: '{ print $4; }'`
         if [ ".$sgid" != . ]; then
-            sgrp=`(cat /etc/group; ypcat group) 2>/dev/null |\
+            sgrp=`(getent group; cat /etc/group; ypcat group) 2>/dev/null |\
                   grep ":${sgid}:" | sed -n -e '1p' | awk -F: '{ print $1; }'`
         fi
         if [ ".$sgrp" = . ]; then
@@ -104,10 +104,10 @@ fi
 if [ ".$mgrp" = . ]; then
     mgrp=`(id -gn $musr) 2>/dev/null`
     if [ ".$mgrp" = . ]; then
-        mgid=`(cat /etc/passwd; ypcat passwd) 2>/dev/null |\
+        mgid=`(getent passwd; cat /etc/passwd; ypcat passwd) 2>/dev/null |\
               grep "^${musr}:" | sed -n -e '1p' | awk -F: '{ print $4; }'`
         if [ ".$mgid" != . ]; then
-            mgrp=`(cat /etc/group; ypcat group) 2>/dev/null |\
+            mgrp=`(getent group; cat /etc/group; ypcat group) 2>/dev/null |\
                   grep ":${mgid}:" | sed -n -e '1p' | awk -F: '{ print $1; }'`
         fi
         if [ ".$mgrp" = . ]; then
@@ -129,10 +129,10 @@ fi
 if [ ".$rgrp" = . ]; then
     rgrp=`(id -gn $rusr) 2>/dev/null`
     if [ ".$rgrp" = . ]; then
-        rgid=`(cat /etc/passwd; ypcat passwd) 2>/dev/null |\
+        rgid=`(getent passwd; cat /etc/passwd; ypcat passwd) 2>/dev/null |\
               grep "^${rusr}:" | sed -n -e '1p' | awk -F: '{ print $4; }'`
         if [ ".$rgid" != . ]; then
-            rgrp=`(cat /etc/group; ypcat group) 2>/dev/null |\
+            rgrp=`(getent group; cat /etc/group; ypcat group) 2>/dev/null |\
                   grep ":${rgid}:" | sed -n -e '1p' | awk -F: '{ print $1; }'`
         fi
         if [ ".$rgrp" = . ]; then
@@ -154,10 +154,10 @@ fi
 if [ ".$ngrp" = . ]; then
     ngrp=`(id -gn $nusr) 2>/dev/null`
     if [ ".$ngrp" = . ]; then
-        ngid=`(cat /etc/passwd; ypcat passwd) 2>/dev/null |\
+        ngid=`(getent passwd; cat /etc/passwd; ypcat passwd) 2>/dev/null |\
               grep "^${nusr}:" | sed -n -e '1p' | awk -F: '{ print $4; }'`
         if [ ".$ngid" != . ]; then
-            ngrp=`(cat /etc/group; ypcat group) 2>/dev/null |\
+            ngrp=`(getent group; cat /etc/group; ypcat group) 2>/dev/null |\
                   grep ":${ngid}:" | sed -n -e '1p' | awk -F: '{ print $1; }'`
         fi
         if [ ".$ngrp" = . ]; then

+ 2 - 2
openpkg/aux.wrapsrc.sh

@@ -67,10 +67,10 @@ cusr=`(id -un) 2>/dev/null ||\
       (who am i | cut "-d " -f1) 2>/dev/null ||\
       echo $LOGNAME`
 cgid=`(id -g $cusr) 2>/dev/null ||\
-      ((cat /etc/passwd; ypcat passwd) 2>/dev/null |\
+      ((getent passwd; cat /etc/passwd; ypcat passwd) 2>/dev/null |\
        grep "^${cusr}:" | sed -n -e '1p' | awk -F: '{ print $4; }')`
 cgrp=`(id -gn $cusr) 2>/dev/null ||\
-      ((cat /etc/group; ypcat group) 2>/dev/null |\
+      ((getent group; cat /etc/group; ypcat group) 2>/dev/null |\
        grep ":${cgid}:" | sed -n -e '1p' | awk -F: '{ print $1; }')`
 if [ ".$cgrp" = . ]; then
     cgrp="$cusr"

+ 10 - 10
openpkg/openpkg.spec

@@ -39,8 +39,8 @@
 #   o any cc(1)
 
 #   the package version and release
-%define       V_openpkg 20030221
-%define       R_openpkg 20030221
+%define       V_openpkg 20030222
+%define       R_openpkg 20030222
 
 #   the used software versions
 %define       V_rpm     4.0.2
@@ -881,7 +881,7 @@ Provides:     OpenPKG
         eval "xuid=\"\$${class}uid\""
         eval "xgid=\"\$${class}gid\""
         if [ ".$xuid" = . ]; then
-            xuid=`(cat /etc/passwd; ypcat passwd) 2>/dev/null |\
+            xuid=`(getent passwd; cat /etc/passwd; ypcat passwd) 2>/dev/null |\
                   grep "^${xusr}:" | awk -F: '{ print $3; }'`
             if [ ".$xuid" = . ]; then
                 #   seek for a reasonably uid/gid pair
@@ -890,11 +890,11 @@ Provides:     OpenPKG
                 while [ ".$ok" = .0 ]; do
                     eval "u_exists=\$u_exists_$xuid"
                     if [ ".$u_exists" = . ]; then
-                        u_exists=`(cat /etc/passwd; ypcat passwd) 2>/dev/null | grep "^[^:]*:[^:]*:$xuid:"`
+                        u_exists=`(getent passwd; cat /etc/passwd; ypcat passwd) 2>/dev/null | grep "^[^:]*:[^:]*:$xuid:"`
                     fi
                     eval "g_exists=\$g_exists_$xuid"
                     if [ ".$g_exists" = . ]; then
-                        g_exists=`(cat /etc/group;  ypcat group)  2>/dev/null | grep "^[^:]*:[^:]*:$xuid:"`
+                        g_exists=`(getent group; cat /etc/group; ypcat group) 2>/dev/null | grep "^[^:]*:[^:]*:$xuid:"`
                     fi
                     if [ ".$u_exists" = . -a ".$g_exists" = . ]; then
                         ok=1
@@ -907,7 +907,7 @@ Provides:     OpenPKG
             fi
         fi
         if [ ".$xgid" = . ]; then
-            xgid=`(cat /etc/group; ypcat group) 2>/dev/null |\
+            xgid=`(getent group; cat /etc/group; ypcat group) 2>/dev/null |\
                   grep "^${xgrp}:" | awk -F: '{ print $3; }'`
             if [ ".$xgid" = . ]; then
                 xgid="$xuid"
@@ -944,7 +944,7 @@ Provides:     OpenPKG
         class="$1"; usr="$2"; uid="$3"; grp="$4"; gid="$5"
 
         #    check whether user already exists
-        exists=`(cat /etc/passwd; ypcat passwd) 2>/dev/null | grep "^$usr:"`
+        exists=`(getent passwd; cat /etc/passwd; ypcat passwd) 2>/dev/null | grep "^$usr:"`
         if [ ".$exists" = . ]; then
             if [ ".$cusr" != ".root" ]; then
                 echo "openpkg:WARNING: skipping creation of OpenPKG $class user $usr" 1>&2
@@ -987,7 +987,7 @@ Provides:     OpenPKG
         fi
 
         #    check whether group already exists
-        exists=`(cat /etc/group; ypcat group) 2>/dev/null | grep "^$grp:"`
+        exists=`(getent group; cat /etc/group; ypcat group) 2>/dev/null | grep "^$grp:"`
         if [ ".$exists" = . ]; then
             if [ ".$cusr" != ".root" ]; then
                 echo "openpkg:WARNING: skipping creation of OpenPKG $class group $grp" 1>&2
@@ -1312,7 +1312,7 @@ Provides:     OpenPKG
         class="$1"; usr="$2"; uid="$3"; grp="$4"; gid="$5"
 
         #    check whether user already exists
-        exists=`(cat /etc/passwd; ypcat passwd) 2>/dev/null | grep "^$usr:"`
+        exists=`(getent passwd; cat /etc/passwd; ypcat passwd) 2>/dev/null | grep "^$usr:"`
         if [ ".$exists" != . ]; then
             if [ ".$cusr" != ".root" ]; then
                 echo "openpkg:WARNING: skipping deletion of OpenPKG $class user $usr" 1>&2
@@ -1346,7 +1346,7 @@ Provides:     OpenPKG
         fi
 
         #    check whether group already exists
-        exists=`(cat /etc/group; ypcat group) 2>/dev/null | grep "^$grp:"`
+        exists=`(getent group; cat /etc/group; ypcat group) 2>/dev/null | grep "^$grp:"`
         if [ ".$exists" = . ]; then
             if [ ".$cusr" != ".root" ]; then
                 echo "openpkg:WARNING: skipping deletion of OpenPKG $class group $grp" 1>&2

+ 27 - 14
openpkg/shtool

@@ -6,7 +6,7 @@
 ##  See http://www.gnu.org/software/shtool/ for more information.
 ##  See ftp://ftp.gnu.org/gnu/shtool/ for latest version.
 ##
-##  Version:  2.0b0 (21-Feb-2003)
+##  Version:  2.0b0 (22-Feb-2003)
 ##  Contents: all available modules
 ##
 
@@ -65,7 +65,7 @@ if [ $# -eq 0 ]; then
     exit 1
 fi
 if [ ".$1" = ".-h" -o ".$1" = ".--help" ]; then
-    echo "This is GNU shtool, version 2.0b0 (21-Feb-2003)"
+    echo "This is GNU shtool, version 2.0b0 (22-Feb-2003)"
     echo "Copyright (c) 1994-2003 Ralf S. Engelschall <rse@engelschall.com>"
     echo "Report bugs to <bug-shtool@gnu.org>"
     echo ''
@@ -128,7 +128,7 @@ if [ ".$1" = ".-h" -o ".$1" = ".--help" ]; then
     exit 0
 fi
 if [ ".$1" = ".-v" -o ".$1" = ."--version" ]; then
-    echo "GNU shtool 2.0b0 (21-Feb-2003)"
+    echo "GNU shtool 2.0b0 (22-Feb-2003)"
     exit 0
 fi
 if [ ".$1" = ".-r" -o ".$1" = ."--recreate" ]; then
@@ -701,14 +701,18 @@ echo )
                     userid=`echo $str | sed -e 's/^uid[ 	]*=[ 	]*//' -e 's/(.*$//'`
                 fi
                 if [ ".$userid" = . ]; then
-                    userid=`egrep "^${username}:" /etc/passwd 2>/dev/null | \
+                    userid=`(getent passwd ${username}) 2>/dev/null | \
                             sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
                     if [ ".$userid" = . ]; then
-                        userid=`(ypcat passwd) 2>/dev/null |
-                                egrep "^${username}:" | \
+                        userid=`egrep "^${username}:" /etc/passwd 2>/dev/null | \
                                 sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
                         if [ ".$userid" = . ]; then
-                            userid='?'
+                            userid=`(ypcat passwd) 2>/dev/null |
+                                    egrep "^${username}:" | \
+                                    sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
+                            if [ ".$userid" = . ]; then
+                                userid='?'
+                            fi
                         fi
                     fi
                 fi
@@ -726,13 +730,17 @@ echo )
                 groupid=`echo $str | sed -e 's/^.*gid[ 	]*=[ 	]*//' -e 's/(.*$//'`
             fi
             if [ ".$groupid" = . ]; then
-                groupid=`egrep "^${username}:" /etc/passwd 2>/dev/null | \
+                groupid=`(getent passwd ${username}) 2>/dev/null | \
                          sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
                 if [ ".$groupid" = . ]; then
-                    groupid=`(ypcat passwd) 2>/dev/null | egrep "^${username}:" | \
+                    groupid=`egrep "^${username}:" /etc/passwd 2>/dev/null | \
                              sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
                     if [ ".$groupid" = . ]; then
-                        groupid='?'
+                        groupid=`(ypcat passwd) 2>/dev/null | egrep "^${username}:" | \
+                                 sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
+                        if [ ".$groupid" = . ]; then
+                            groupid='?'
+                        fi
                     fi
                 fi
             fi
@@ -749,14 +757,19 @@ echo )
                 groupname=`echo $str | sed -e 's/^.*gid[ 	]*=[ 	]*[0-9]*(//' -e 's/).*$//'`
             fi
             if [ ".$groupname" = . ]; then
-                groupname=`egrep "^[^:]*:[^:]*:${groupid}:" /etc/group 2>/dev/null | \
+                groupname=`(getent group) 2>/dev/null | \
+                           egrep "^[^:]*:[^:]*:${groupid}:" | \
                            sed -e 's/:.*$//'`
                 if [ ".$groupname" = . ]; then
-                    groupname=`(ypcat group) 2>/dev/null | \
-                               egrep "^[^:]*:[^:]*:${groupid}:" | \
+                    groupname=`egrep "^[^:]*:[^:]*:${groupid}:" /etc/group 2>/dev/null | \
                                sed -e 's/:.*$//'`
                     if [ ".$groupname" = . ]; then
-                        groupname='?'
+                        groupname=`(ypcat group) 2>/dev/null | \
+                                   egrep "^[^:]*:[^:]*:${groupid}:" | \
+                                   sed -e 's/:.*$//'`
+                        if [ ".$groupname" = . ]; then
+                            groupname='?'
+                        fi
                     fi
                 fi
             fi