groups(1): Display all your groups for ISC 2.2

Darryl Wagoner darryl at lemuria.MV.COM
Sun Aug 19 23:55:13 AEST 1990


This is a quick and dirty program to display the posix groups that you
are a member of.  Enjoy

#!/bin/sh
# shar:	Shell Archiver  (v1.22)
#
#	Run the following text with /bin/sh to create:
#	  Makefile
#	  groups.c
#
sed 's/^X//' << 'SHAR_EOF' > Makefile &&
XCC = cc
XCFLAGS = -O
X
Xgroups:	groups.o
X	$(CC) -s -o groups groups.o -lcposix
X
X
SHAR_EOF
chmod 0664 Makefile || echo "restore of Makefile fails"
sed 's/^X//' << 'SHAR_EOF' > groups.c &&
X/****************************************************************/
X/*								*/
X#ifndef	lint
Xstatic char	   *sccsid = "@(#)groups.c	1.3        8/19/90\n@(#)Copyright 1990 Shecora Associates, Inc\n";
X#endif	
X/*								*/
X/*	This program may be used for any purpose the user see   */
X/*	fit, except he/she may not remove the copyright		*/
X/****************************************************************/
X
X#define _POSIX_SOURCE
X
X#include <sys/types.h>
X#include <grp.h>
X#include <stdio.h>
X
X
Xmain() {
X
X	gid_t 			groups[20];
X	struct  	group 	*gname;
X	int  			ngrp;
X	int  			i;
X
X	ngrp = getgroups(19,groups);
X
X	if (ngrp <= 0 ) {
X		perror("getgroups");
X		exit(1);
X	}
X
X	for(i=0;i<ngrp;i++) {
X		gname=getgrgid(groups[i]);
X		if (gname == NULL) 
X			printf("unknown_grp_%d ",groups[i]);
X		else
X			printf("%s ",gname->gr_name);
X	}
X	printf("\n");
X	exit(0);
X}
SHAR_EOF
chmod 0444 groups.c || echo "restore of groups.c fails"
exit 0
-- 
Darryl Wagoner		darryl at lemuria.MV.COM or uunet!virgin!lemuria!darryl
12 Oak Hill Road
Brookline, NH 03033
Office: 603.672.0736   		Home: 603.673.0578



More information about the Comp.unix.i386 mailing list