Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!execu!sequoia!rpp386!jfh From: jfh@rpp386.Dallas.TX.US (John F. Haugh II) Newsgroups: alt.sources Subject: Re: euser - display the effective user name, SysV-ish Message-ID: <16780@rpp386.Dallas.TX.US> Date: 10 Jul 89 02:58:54 GMT References: <14448@bfmny0.UUCP> <37612@sgi.SGI.COM> Reply-To: jfh@rpp386.cactus.org (John F. Haugh II) Organization: I am NOT the NRA Lines: 98 In article <37612@sgi.SGI.COM> jmb@patton.sgi.com (Jim Barton) writes: >Why waste time with this? The system V 'id' command does the >same thing! And, it's standard! It isn't standard under BSD, and the version on AIX doesn't support concurrent groups. This version [ the one attached below ] should resolve all of those problems. And its public domain, so you can rip it off and send it out with your BSD port. Enjoy. -- /* * id - print current process identification information * * This program was written by John F. Haugh II (jfh@rpp386.UUCP) * on 7/9/89 and hereby placed into the public domain. * * Syntax: * id * Synopsis: * Print the current process identifiers. This includes the * UID, GID, effective-UID and effective-GID. In environment * where concurrent groupsets exist, the list of groups in * the concurrent groupset is printed as well. * * Notes: * Straightforward implementation. Get the IDs and print * them out. We key on the #define NGROUPS to decide if * concurrent groups exist. This may have to be changed to * something more intelligent. */ #include #include #include #include main (argc, argv) int argc; char **argv; { #ifdef NGROUPS int groups[NGROUPS]; int ngroups; #endif int id; int i; struct passwd *pw, *getpwuid(); struct group *gr, *getgrgid(); if (pw = getpwuid (id = getuid ())) printf ("uid=%d(%s)", id, pw->pw_name); else printf ("uid=%d", id); if (gr = getgrgid (id = getgid ())) printf (" gid=%d(%s)", id, gr->gr_name); else printf (" gid=%d", id); if (getuid () != geteuid ()) { if (pw = getpwuid (id = geteuid ())) printf (" euid=%d(%s)", id, pw->pw_name); else printf (" euid=%d", id); } if (getgid () != getegid ()) { if (gr = getgrgid (id = getegid ())) printf (" egid=%d(%s)", id, gr->gr_name); else printf (" egid=%d", id); } #ifdef NGROUPS if ((ngroups = getgroups (NGROUPS, groups)) != -1) { printf (" groupset=("); for (i = 0;i < ngroups;i++) { if (i) putchar (' '); if (gr = getgrgid (groups[i])) printf ("%s", groups[i], gr->gr_name); else printf ("%d", groups[i]); } putchar (')'); } #endif putchar ('\n'); } -- John F. Haugh II +-Quote of the month club: ------------ VoiceNet: (512) 832-8832 Data: -8835 | "Computer security is to information InterNet: jfh@rpp386.cactus.org | control as a chastity belt is to UucpNet : !bigtex!rpp386!jfh +- birth control" -- Doug Steves --