euser - display the effective user name, SysV-ish
Tom Neff
tneff at bfmny0.UUCP
Sat Jul 8 09:29:21 AEST 1989
If you need a FAST way to generate the name of your current effective
user (including the effects of su(1) etc), this works. It's not fancy.
Obviously it has to read /etc/passwd. Feel free to hack and pass
around.
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
# euser.c
# This archive created: Wed Jul 5 19:58:33 1989
export PATH; PATH=/bin:/usr/bin:$PATH
if test -f 'euser.c'
then
echo shar: "will not over-write existing file 'euser.c'"
else
sed 's/^X//' << \SHAR_EOF > 'euser.c'
X/*
X euser.c rev: 05-Jul-89 Tom Neff
X
X Display the name of our effective user at the moment.
X
X System V-ish. Have a blast.
X
X Uses /etc/passwd.
X */
X
X#include <stdio.h>
X#include <string.h>
X
Xunsigned short geteuid(), euid;
X
XFILE *pass;
Xchar line[256], *name;
Xint uid = 0;
X
Xmain()
X{
X euid = geteuid();
X if ((pass = fopen("/etc/passwd","r")) == NULL)
X exit(2);
X while (fgets(line, sizeof(line), pass) != NULL)
X {
X name = strtok(line, ":");
X strtok(NULL, ":");
X uid = atoi(strtok(NULL, ":"));
X if (euid == uid)
X {
X puts(name);
X exit(0);
X }
X }
X exit(1);
X}
SHAR_EOF
fi
exit 0
# End of shell archive
--
"My God, Thiokol, when do you \\ Tom Neff
want me to launch -- next April?" \\ uunet!bfmny0!tneff
More information about the Alt.sources
mailing list