OSSP CVS Repository

ossp - Difference in ossp-pkg/shtool/sh.echo versions 1.33 and 1.34
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

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