OSSP CVS Repository

ossp - Check-in [3292]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 3292
Date: 2003-Feb-21 20:18:34 (local)
2003-Feb-21 19:18:34 (UTC)
User:rse
Branch:
Comment: Enhance %u, %U, %g and %G expansions of "shtool echo -e" by first trying to resolve via POSIX "id" command.

Parts submitted by: Bill Campbell <bill@celestial.com>

Tickets:
Inspections:
Files:
ossp-pkg/shtool/ChangeLog      1.181 -> 1.182     5 inserted, 0 deleted
ossp-pkg/shtool/sh.echo      1.33 -> 1.34     57 inserted, 27 deleted

ossp-pkg/shtool/ChangeLog 1.181 -> 1.182

--- ChangeLog    2003/02/11 13:00:49     1.181
+++ ChangeLog    2003/02/21 19:18:34     1.182
@@ -11,6 +11,11 @@
 
  Changes between 1.6.2 and 2.0b0 (02-Nov-2002 to xx-Feb-2003):
 
+   *) Enhance %u, %U, %g and %G expansions of "shtool echo -e"
+      by first trying to resolve via POSIX "id" command.
+      [Ralf S. Engelschall <rse@engelschall.com>,
+       Bill Campbell <bill@celestial.com>]
+
    *) Bump year in copyright messages to cover new year 2003.
       [Ralf S. Engelschall <rse@engelschall.com>]
 


ossp-pkg/shtool/sh.echo 1.33 -> 1.34

--- sh.echo      2003/02/11 13:00:50     1.33
+++ sh.echo      2003/02/21 19:18:34     1.34
@@ -103,17 +103,26 @@
 #   determine user name
 username=''
 if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%[uUgG]'`" != . ]; then
-    username="$LOGNAME"
+    username="`(id -un) 2>/dev/null`"
     if [ ".$username" = . ]; then
-        username="$USER"
+        str="`(id) 2>/dev/null`"
+        if [ ".`echo $str | grep '^uid[         ]*=[    ]*[0-9]*('`" != . ]; then
+            username=`echo $str | sed -e 's/^uid[       ]*=[    ]*[0-9]*(//' -e 's/).*$//'`
+        fi
         if [ ".$username" = . ]; then
-            username="`(whoami) 2>/dev/null |\
-                       awk '{ printf("%s", $1); }'`"
+            username="$LOGNAME"
             if [ ".$username" = . ]; then
-                username="`(who am i) 2>/dev/null |\
-                           awk '{ printf("%s", $1); }'`"
+                username="$USER"
                 if [ ".$username" = . ]; then
-                    username='unknown'
+                    username="`(whoami) 2>/dev/null |\
+                               awk '{ printf("%s", $1); }'`"
+                    if [ ".$username" = . ]; then
+                        username="`(who am i) 2>/dev/null |\
+                                   awk '{ printf("%s", $1); }'`"
+                        if [ ".$username" = . ]; then
+                            username='unknown'
+                        fi
+                    fi
                 fi
             fi
         fi
@@ -125,19 +134,22 @@
 if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%U'`" != . ]; then
     userid="`(id -u) 2>/dev/null`"
     if [ ".$userid" = . ]; then
-        str="`(id) 2>/dev/null`"
-        if [ ".`echo $str | grep '^uid[         ]*=[    ]*[0-9]*('`" != . ]; then
-            userid=`echo $str | sed -e 's/^uid[         ]*=[    ]*//' -e 's/(.*//'`
-        fi
+        userid="`(id -u ${username}) 2>/dev/null`"
         if [ ".$userid" = . ]; then
-            userid=`egrep "^${username}:" /etc/passwd 2>/dev/null | \
-                    sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
+            str="`(id) 2>/dev/null`"
+            if [ ".`echo $str | grep '^uid[     ]*=[    ]*[0-9]*('`" != . ]; then
+                userid=`echo $str | sed -e 's/^uid[     ]*=[    ]*//' -e 's/(.*$//'`
+            fi
             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
@@ -147,13 +159,22 @@
 #   determine (primary) group id
 groupid=''
 if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%[gG]'`" != . ]; then
-    groupid=`egrep "^${username}:" /etc/passwd 2>/dev/null | \
-             sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
+    groupid="`(id -g ${username}) 2>/dev/null`"
     if [ ".$groupid" = . ]; then
-        groupid=`(ypcat passwd) 2>/dev/null | egrep "^${username}:" | \
-                 sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
+        str="`(id) 2>/dev/null`"
+        if [ ".`echo $str | grep 'gid[  ]*=[    ]*[0-9]*('`" != . ]; then
+            groupid=`echo $str | sed -e 's/^.*gid[      ]*=[    ]*//' -e 's/(.*$//'`
+        fi
         if [ ".$groupid" = . ]; then
-            groupid='?'
+            groupid=`egrep "^${username}:" /etc/passwd 2>/dev/null | \
+                     sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
+            if [ ".$groupid" = . ]; then
+                groupid=`(ypcat passwd) 2>/dev/null | egrep "^${username}:" | \
+                         sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
+                if [ ".$groupid" = . ]; then
+                    groupid='?'
+                fi
+            fi
         fi
     fi
 fi
@@ -161,14 +182,23 @@
 #   determine (primary) group name
 groupname=''
 if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%g'`" != . ]; then
-    groupname=`egrep "^[^:]*:[^:]*:${groupid}:" /etc/group 2>/dev/null | \
-               sed -e 's/:.*$//'`
+    groupname="`(id -gn ${username}) 2>/dev/null`"
     if [ ".$groupname" = . ]; then
-        groupname=`(ypcat group) 2>/dev/null | \
-                   egrep "^[^:]*:[^:]*:${groupid}:" | \
-                   sed -e 's/:.*$//'`
+        str="`(id) 2>/dev/null`"
+        if [ ".`echo $str | grep 'gid[  ]*=[    ]*[0-9]*('`" != . ]; then
+            groupname=`echo $str | sed -e 's/^.*gid[    ]*=[    ]*[0-9]*(//' -e 's/).*$//'`
+        fi
         if [ ".$groupname" = . ]; then
-            groupname='?'
+            groupname=`egrep "^[^:]*:[^:]*:${groupid}:" /etc/group 2>/dev/null | \
+                       sed -e 's/:.*$//'`
+            if [ ".$groupname" = . ]; then
+                groupname=`(ypcat group) 2>/dev/null | \
+                           egrep "^[^:]*:[^:]*:${groupid}:" | \
+                           sed -e 's/:.*$//'`
+                if [ ".$groupname" = . ]; then
+                    groupname='?'
+                fi
+            fi
         fi
     fi
 fi

CVSTrac 2.0.1