uid -- get user's uid/gid
Warren Lavallee
warren at ll-xn.ARPA
Sat Nov 30 05:48:18 AEST 1985
Here is a little program I wrote that will get the
login name/uid of people. You can specify "uid names...",
"uid uids..." or mix and match login name and uids.
Warren Lavallee
ARPA: warren at ll-xn.arpa
...!seismo
UUCP: ...!harvard!ll-xn!warren
-=-=-=-=-=-=-=-=--=-=-=-= cut here =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#! /bin/sh
# This is a shar archive. Unbundle with sh, not csh
# This includes:
# Makefile
# all.c
# main.c
# me.c
# more.h
# one.c
# uid.c
# uid.local
echo x - Makefile
sed 's/^X//' >Makefile <<'*-*-END-of-Makefile-*-*'
XOBJS= all.o main.o one.o uid.o me.o
XSRC= all.c main.c one.c uid.c me.c
XFLAGS= -O
X
X.c.o:
X ${CC} -c ${FLAGS} $*.c
X
Xall: uid
X
Xuid: ${OBJS}
X ${CC} -o uid ${OBJS}
X
Xinstall:
X cp uid /u0/warren/bin
X cp uid /usr/local/bin
X cp uid.local /usr/man/manl/uid.l
X
Xlint:
X lint $(SRC)
X
Xprint:
X imprint ${SRC}
X
X# DO NOT REMOVE THIS LINE
X
Xall.c: more.h
*-*-END-of-Makefile-*-*
echo x - all.c
sed 's/^X//' >all.c <<'*-*-END-of-all.c-*-*'
X#ifndef lint
Xstatic char *what = "@(#)all.c 11/29/85 Warren Lavallee";
X#endif
X
X/* all.c-- prints out all the entrys in the /etc/passwd file */
X
X#include <pwd.h>
X#include <stdio.h>
X#include "more.h" /* defines MORE */
X
Xstruct passwd *pw;
Xstruct passwd *getpwent ();
X
XFILE * more, *popen ();
X
Xall () { /* prints all entrys if file */
X if (!(more = popen (MORE, "w"))) {/* open pipe */
X (void) fprintf (stderr, "cannot activate %s\n", MORE);
X exit (2);
X }
X
X (void) setpwent ();
X while (pw = getpwent ())
X if (strlen (pw -> pw_passwd) >= 5){ /* see if active */
X (void) fprintf (more, "%s \tuid: %3d\tgid: %3d\n",
X pw -> pw_name,
X pw -> pw_uid, pw -> pw_gid);
X }
X (void) endpwent ();
X (void) pclose (more);
X}
*-*-END-of-all.c-*-*
echo x - main.c
sed 's/^X//' >main.c <<'*-*-END-of-main.c-*-*'
X#ifndef lint
Xstatic char *what = "@(#)main.c 11/29/85 Warren Lavallee";
X#endif
X
X#include <stdio.h>
X#include <strings.h>
X
X#define TRUE 1
X#define FALSE 0
X
X
Xmain (argc, argv)
Xint argc;
Xchar *argv[];
X{
X register int i;
X
X if (!strcmp (argv[1], "-a")) {/* see if -a set */
X (void) all ();
X exit (0);
X }
X
X if (argc == 1) { /* if not arguments print yours */
X (void) me ();
X exit (0);
X }
X
X for (i = 1; i < (argc); i++)/* loop through arguments */
X if (!one (argv[i])) { /* if login name, print */
X if (strcmp (argv[i], "0") && !atoi (argv[i])) {
X (void) fprintf (stderr, "%s not valid entry\n", argv[i]);
X (void) fflush (stderr);
X }
X else
X if (!uid (atoi (argv[i]))) {/* if uid print */
X (void) fprintf (stderr, "%s not valid entry\n", argv[i]);
X (void) fflush (stderr);
X }
X }
X}
*-*-END-of-main.c-*-*
echo x - me.c
sed 's/^X//' >me.c <<'*-*-END-of-me.c-*-*'
X#ifndef lint
Xstatic char *what = "@(#)me.c 11/29/85 Warren Lavallee";
X#endif
X
X#include <stdio.h>
X#include <pwd.h>
X
Xstruct passwd *pw;
Xstruct passwd *getpwnam ();
X
Xint myuid;
X
Xme () {
X myuid = getuid ();
X
X (void) setpwent ();
X if (pw = getpwuid (myuid)) {
X (void) printf ("%s \tuid: %3d\tgid: %3d\n",
X pw -> pw_name,
X pw -> pw_uid, pw -> pw_gid);
X return (1);
X }
X else {
X (void) fprintf (stderr, "Sorry old chap, but you don't exist\!\n");
X exit (2);
X }
X (void) endpwent ();
X return (0);
X}
*-*-END-of-me.c-*-*
echo x - more.h
sed 's/^X//' >more.h <<'*-*-END-of-more.h-*-*'
X/* more */
X#define MORE "/usr/local/bin/less -sm"
*-*-END-of-more.h-*-*
echo x - one.c
sed 's/^X//' >one.c <<'*-*-END-of-one.c-*-*'
X#ifndef lint
Xstatic char *what = "@(#)one.c 11/29/85 Warren Lavallee";
X#endif
X
X#include <pwd.h>
X#include <stdio.h>
X
Xstruct passwd *pw;
Xstruct passwd *getpwnam ();
X
Xone (name)
Xchar *name;
X{
X (void) setpwent ();
X if (pw = getpwnam (name)) {
X (void) printf ("%s \tuid: %3d\tgid: %3d\n",
X pw -> pw_name,
X pw -> pw_uid, pw -> pw_gid);
X return (1);
X }
X (void) endpwent ();
X return (0);
X}
*-*-END-of-one.c-*-*
echo x - uid.c
sed 's/^X//' >uid.c <<'*-*-END-of-uid.c-*-*'
X#ifndef lint
Xstatic char *what = "@(#)uid.c 11/29/85 Warren Lavallee";
X#endif
X
X#include <pwd.h>
X#include <stdio.h>
X
Xstruct passwd *pw;
Xstruct passwd *getpwuid ();
X
Xuid (uid) /* find a uid in /etc/passwd and prints it */
Xint uid;
X{
X (void) setpwent ();
X if (pw = getpwuid (uid)) {
X (void) printf ("%s \tuid: %3d\tgid: %3d\n",
X pw -> pw_name,
X pw -> pw_uid, pw -> pw_gid);
X return (1);
X }
X (void) endpwent ();
X return (0);
X}
*-*-END-of-uid.c-*-*
echo x - uid.local
sed 's/^X//' >uid.local <<'*-*-END-of-uid.local-*-*'
X.TH UID LOCAL "26 October 1985"
X.SH NAME
Xuid \- print User id, Group id
X
X.SH SYNOPSIS
X/usr/local/bin/uid \[-a\] \[login name(s) or uid list\]
X
X.SH DESCRIPTION
X.IR Uid
Xreturns the uid, and gid of the name(s) specified or
Xif no specification your uid. If the
X.I "\-a"
Xflag is specified, all active entry if files are shown.
X
XYou can mix login names and uids for arguments.
X
X.SH AUTHOR
XWarren Lavallee
*-*-END-of-uid.local-*-*
exit
More information about the Comp.sources.unix
mailing list