--- Erik Arneson <[EMAIL PROTECTED]> wrote:

> Hmmm.  I really don't know.  What is the file's uid and gid ownership
> used for?  Are there any other commands which return this sort of
> information?  You mentioned already that 'id' doesn't work on all
> systems.  Maybe there's something else?

If you wanted to be wicked-gross, you could look for perl and do:

    perl -e 'print "uid=$> euid=$< groups=$( egroups=$)\n";'

Or write a small C program to do the same and hunt for the compiler.  This is
probably a bit too much, but you could do it.

Other things that muck with uid are:

    whoami
    /proc/self/status
    
Or you could use a bit-o-shell-script like:

#! /bin/sh -f
#
#
function error() {
    echo "$0: failed: $1" 1>&2
    exit 1
}

function getUID() {
    guess=`grep $1 /etc/passwd`
    if [ -z "$guess" ]; then
        guess=`ypcat passwd | grep $1`
        test -z "$guess" && error "Can't find user id"
    fi

    uid=`echo $guess | cut -f 3 -d :`
    gid=`echo $guess | cut -f 4 -d :`
}

function getGroup() {
    guess=`grep $1 /etc/group`
    if [ -z "$guess" ]; then
        guess=`ypcat group | grep $1`
        test -z "$guess" && error "Can't find user id"
    fi

    agroup=`echo $guess | cut -f 1 -d :`
}

function getGID() {
    guess=`grep $1 /etc/group`
    if [ -z "$guess" ]; then
        guess=`ypcat group | grep $1`
        test -z "$guess" && error "Can't find user id"
    fi

    agroup=`echo $guess | cut -f 1 -d :`
    agid=`echo $guess | cut -f 3 -d :`
}

user=`whoami`
groups=`groups`

getUID $user
getGroup $gid
echo -n "uid=$uid($user) gid=$gid($agroup) groups="
for g in $groups; do
    getGID $g
    echo -n "$agid($agroup) "
done
echo ""


which pretty much does the right thing, though needs to be changed to do
exactly the right thing.

Ian
__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com

Reply via email to