ignatz@ihuxx.UUCP (Dave Ihnat, Chicago, IL) (08/31/84)
Apparently, my posting of the source and man page to my rewrite of 'id(1)' somehow got truncated on a number of sites, just after the lead-in notes. It's short, so I'll just repost. This is a shar archive; only use the Bourne shell. Dave Ihnat ihuxx!ignatz -----------------------CUT-------------------------- echo x - id.c cat >id.c <<'!E!O!F!' /* * id - a trivial utility * * Copyright (C) 1984 by David M. Ihnat * * Somewhere along the line, Unix(Tm) picked up this utility to * report the user and group ID's of the running shell. * This is a public domain version of that program. * * This program may be used and distributed by anyone, provided * no one sells it for profit and this notice remain intact. * I attempted to recreate the behavior of the original command * as faithfully as possible; I might suggest changes maintain * this congruence. * The user assumes liability for all losses, * direct or indirect, resulting from use of this program. * * Caveat Utilitor! */ #include <stdio.h> #include <pwd.h> #include <grp.h> #define REAL 0 #define CURRENT 1 main() { int getuid(),geteuid(),getgid(),getegid(); int uid,euid,gid,egid; /* * First, get all the appropriate numbers. * It *can't fail--ya gotta have a pid and gid! */ uid = getuid(); gid = getgid(); euid = geteuid(); egid = getegid(); uidprint(uid,REAL); if(uid != euid) uidprint(euid,CURRENT); gidprint(gid,REAL); if(gid != egid) gidprint(egid,CURRENT); fprintf(stdout,"\n"); } uidprint(id,type) int id; int type; { struct passwd *getpwuid(); struct passwd *pwdptr; if((pwdptr = getpwuid(id)) == (struct passwd *) NULL) { fprintf(stderr,"Can't find entry for %s %d in passwd file!\n", (type==REAL?"uid":"euid"),id); exit(1); } fprintf(stdout,"%s=%d(%s) ",(type==REAL?"uid":"euid"), id,pwdptr->pw_name); } gidprint(id,type) int id; int type; { struct group *getgrgid(); struct group *grpptr; if((grpptr = getgrgid(id)) == (struct group *) NULL) { fprintf(stderr,"Can't find entry for %s %d in group file!\n", (type==REAL?"gid":"egid"),id); exit(1); } fprintf(stdout,"%s=%d(%s) ",(type==REAL?"gid":"egid"), id,grpptr->gr_name); } !E!O!F! echo x - id.mp cat >id.mp <<'!E!O!F!' .TH ID 1 "" .SH NAME id \- print user and group IDs and names .SH SYNOPSIS \fBid\fP .SH DESCRIPTION \fIId\fP writes a message on the standard output giving the user and group IDs and the corresponding names of the invoking process. If the effective and real IDs do not match, both are printed. .SH SEE ALSO logname(1),getuid(2),getgid(2). .SH CAVEATS This program has been written to emulate a program of the same name on the AT&T Bell Laboratories Unix(Tm) System V. No proprietary source is involved; this program is free to the public for use and distribution, as long as this notice is retained and it is not sold for profit. .PP The program was written to recreate the behavior of the original as closely as possible; I might suggest that said congruence be maintained across any modifications. The user assumes all liability for any losses, direct or incidental, arising from use of this program. -Dave Ihnat !E!O!F!