euser - display the effective user name, SysV-ish
John F. Haugh II
jfh at rpp386.Dallas.TX.US
Mon Jul 10 12:58:54 AEST 1989
In article <37612 at sgi.SGI.COM> jmb at 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 at 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 <sys/types.h>
#include <stdio.h>
#include <grp.h>
#include <pwd.h>
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 at rpp386.cactus.org | control as a chastity belt is to
UucpNet : <backbone>!bigtex!rpp386!jfh +- birth control" -- Doug Steves --
More information about the Alt.sources
mailing list