[alt.sources] A replacement for the Sun "id" program

bjs@.cis.ufl.edu (Brian J. Smith) (08/28/90)

	[ This is a little hack I made for some non sun     ]
	[ machines that we have here.  I use the id program ]
	[ to check and see if users have the correct group  ]
	[ group permissions to write and read in directories]
	[ I hope that it will be of some use to somebody.   ]
	[		bjs@cis.ufl.edu			    ]

-------------------------- cut here -------------------------
#!/bin/sh
# This is a shell archive (shar 3.32)
# made 08/28/1990 01:23 UTC by bjs@reef
# Source directory /net/lightning/1/bjs/src/id
#
# existing files will NOT be overwritten
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#    245 -rw-r--r-- Makefile
#    445 -rw-r--r-- README
#    457 -rw-r--r-- id.8
#   2250 -rw-r--r-- id.c
#
if touch 2>&1 | fgrep 'amc' > /dev/null
 then TOUCH=touch
 else TOUCH=true
fi
# ============= Makefile ==============
if test X"$1" != X"-c" -a -f 'Makefile'; then
	echo "File already exists: skipping 'Makefile'"
else
echo "x - extracting Makefile (Text)"
sed 's/^X//' << 'SHAR_EOF' > Makefile &&
X#
X# Last Edited: Mon Aug 27 21:28:30 1990 by bjs (Brian J. Smith) on reef
X#
X#
XCFLAGS= -O
X#CFLAGS= -O -DSYSV
XCC = cc
X#CC = gcc
XSTRIP = strip
X
Xall:	id
X
Xid:	id.o
X	$(CC) -o $@  id.c
X
Xstripped:	id
X	$(STRIP) id 
Xclean:
X	/bin/rm id *.o core *.BAK
SHAR_EOF
$TOUCH -am 0827211290 Makefile &&
chmod 0644 Makefile ||
echo "restore of Makefile failed"
set `wc -c Makefile`;Wc_c=$1
if test "$Wc_c" != "245"; then
	echo original size 245, current size $Wc_c
fi
fi
# ============= README ==============
if test X"$1" != X"-c" -a -f 'README'; then
	echo "File already exists: skipping 'README'"
else
echo "x - extracting README (Text)"
sed 's/^X//' << 'SHAR_EOF' > README &&
X
Xid a lookalike for Sun's id program that shows a processes active
Xuid's and gid's.
X
XTo compile on a standard BSD machine just type 'make'.
X
XTo compile the stripped verison just type 'make stripped'.
X
XIf you wish to port it to a SYSV machine be sure to include -DSYSV in
Xthe makefile.
X
XYou may modify, copy, and/or destroy this code as you wish, all I as
Xis you mail me a copy of the modified source.
X
XPlease send corrections to bjs@cis.ufl.edu
SHAR_EOF
$TOUCH -am 0710183090 README &&
chmod 0644 README ||
echo "restore of README failed"
set `wc -c README`;Wc_c=$1
if test "$Wc_c" != "445"; then
	echo original size 445, current size $Wc_c
fi
fi
# ============= id.8 ==============
if test X"$1" != X"-c" -a -f 'id.8'; then
	echo "File already exists: skipping 'id.8'"
else
echo "x - extracting id.8 (Text)"
sed 's/^X//' << 'SHAR_EOF' > id.8 &&
X.\" 
X.TH ID 1 "13 June 1990"
X.SH NAME
Xid \- print the user name and ID, and group name and ID
X.SH USAGE
X.B id
X.SH DESCRIPTION
X.LP
X.B id
Xdisplays your user and group id's with names.  If your real and effective 
Xdo not match, both are printed.  Along with this information all the 
Xgroups that you have access to are also printed.
X.LP
X.LP
X.SH BUGS
X.B id
Xwill not run correctly on an Ardent.
X.SH SEE ALSO
X.BR getuid (2)\t\tgetgid(2)\t\tgeteuid(2)\tgetegid(2)
SHAR_EOF
$TOUCH -am 0710183690 id.8 &&
chmod 0644 id.8 ||
echo "restore of id.8 failed"
set `wc -c id.8`;Wc_c=$1
if test "$Wc_c" != "457"; then
	echo original size 457, current size $Wc_c
fi
fi
# ============= id.c ==============
if test X"$1" != X"-c" -a -f 'id.c'; then
	echo "File already exists: skipping 'id.c'"
else
echo "x - extracting id.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > id.c &&
X/*
X * Last Edited: Tue Jul 10 18:21:59 1990 by bjs (Brian J. Smith) on lightning
X * Copyright (C) 1990 Brian J. Smith,  This code may be modified without
X * any restrictions, all I request is that you send me updated copies.
X *
X * Please send updates to bjs@cis.ufl.edu
X *
X */
X/* Jun 12, Version 0.9: Completed getting uid and all gid's */
X/*
X * Jun 13, Version 1.0: Completed getting all gid's true names as listed in
X * the /etc/groups file or ypdatabase
X */
X/*
X * Jun 13, Version 1.01: Added tests for egid and euid and included SYSV 
X * compiler directive so it won't bomb on SYSV machines (I hope)
X */
X
X#include <grp.h>
X#include <stdio.h>
X#include <pwd.h>
X
Xextern int      getuid();
Xextern int      getgid();
Xextern int      geteuid();
Xextern int      getegid();
Xextern struct group *getgrent();
Xextern struct group *getgrgid();
Xextern struct passwd *getpwent();
X
X#ifndef SYSV
X#include <sys/param.h>
Xextern int getgroups();
X#endif				/* not SYSV */
X
X#ifdef SYSV
X#define NGROUPS 2  /* Max 2 gid and egid */
X
Xint getgroups(ngr, gr)
X	int             ngr;
X	int             gr[];
X{
X	if (ngr < 1)		/* shouldn't happen */
X		return (0);
X	gr[0] = getgid();
X	gr[1] = getegid();
X	if (gr[1] != gr[0])
X	   return (2);
X	else
X	   return(1);
X}
X#endif				/* SYSV */
X
X
X
Xmain()
X{
X	int             id = 0;
X	int             uid = getuid();
X	int             gid = getgid();
X	int             euid = geteuid();
X	int             egid = getegid();
X	int             numgroups;
X	int             grouplist[NGROUPS];
X	struct group   *groupinfo;
X	struct passwd  *passinfo;
X
X	passinfo = getpwuid(uid);
X	groupinfo = getgrgid(gid);
X	numgroups = getgroups(NGROUPS, grouplist);
X	(void) fprintf(stdout, "uid=%d(%s) gid=%d(%s)", uid, passinfo->pw_name, gid, groupinfo->gr_name);
X	if (uid != euid) {
X		passinfo = getpwuid(euid);
X		(void) fprintf(stdout, " euid=%d(%s)", euid, passinfo->pw_name);
X	}
X	if (gid != egid) {
X		groupinfo = getgrgid(egid);
X		(void) fprintf(stdout, " egid=%d(%s)", egid, groupinfo->gr_name);
X	}
X	if (numgroups != 0) {
X		(void) fprintf(stdout, " groups=");
X		for (id = 0; id != numgroups; id++) {
X			groupinfo = getgrgid(grouplist[id]);
X			(void) fprintf(stdout, "%d(%s) ", grouplist[id], groupinfo->gr_name);
X		}
X	}
X	(void) fprintf(stdout, "\n");
X	exit(0);
X}
SHAR_EOF
$TOUCH -am 0710182190 id.c &&
chmod 0644 id.c ||
echo "restore of id.c failed"
set `wc -c id.c`;Wc_c=$1
if test "$Wc_c" != "2250"; then
	echo original size 2250, current size $Wc_c
fi
fi
exit 0
--
Brian J. Smith				"I have come here to chew bubble
UF Unix Consulting Staff 		 gum and kick ass, and I'm fresh
bjs@cis.ufl.edu				 out of bubble gum !"