home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume26
/
idutil
/
getgrnam.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-06-12
|
2KB
|
121 lines
#include <stdio.h>
#include <errno.h>
#include <grp.h>
#include <gnu/fileutil.h>
#include "grinf.h"
static char *RCSid="$Header: getgrnam.c,v 1.7 92/02/25 14:00:01 dtb Exp $";
int fpr_usage();
int process_it();
static int report_except = 0;
static char all_found = 1;
static char *trim_main_name;
int main ( argc, argv, envp )
int argc;
char **argv;
char **envp;
{
char *optstring = "ad:e:Igmnprv" ;
int optchar;
extern char *optarg;
extern int optind;
extern int opterr;
struct grinfrq *grinf;
trim_main_name =basename(*argv);
if ((grinf = grinfrq_set_dflt (NULL)) == NULL)
exit (ENOMEM);
opterr = 0;
while ((optchar = getopt(argc, argv, optstring)) != -1)
switch (optchar) {
case 'I':
fprintf (stderr, "%s %s\n", __FILE__, RCSid);
grinf_info_fpr (stderr);
break;
case 'a':
grinf->epw = grinf->nam = grinf->mem = grinf->gid = 1;
break;
case 'd':
grinf->dlm = *optarg;
break;
case 'e' :
grinf->mdl = *optarg;
break;
case 'g':
grinf->gid = 1;
break;
case 'm':
grinf->mem = 1;
break;
case 'n':
grinf->nam = 1;
break;
case 'p':
grinf->epw = 1;
break;
case 'r':
report_except = 1;
break;
case 'v':
grinf->vbs = 1;
break;
case '?':
fpr_usage (stderr);
exit (EINVAL);
}
if (optind == argc) {
struct group * gp;
char gnametmp[256];
gp = (struct group *)getgrgid (getegid());
strcpy (gnametmp, gp->gr_name);
/*
We need a temporary buffer for the current group name
rather than passing gp->gr_name to process_it as the
buffer pointed at by the returning getgrnam call will
overwrite the passed parameter
*/
process_it (&gnametmp[0], grinf);
}
while (optind < argc) {
process_it (*(argv+optind++), grinf);
}
exit (all_found ? 0 : 1);
}
int process_it( grpnam, grinf)
char *grpnam;
struct grinfrq *grinf;
{
struct group *grp;
int nout = 0;
grp = (struct group *) getgrnam ( grpnam );
if ( grp == NULL) {
all_found = 0;
if (report_except) {
fprintf (stderr, "%s: could not find group %s\n",
trim_main_name, grpnam);
}
} else {
nout = grinf_fpr (stdout, grp, grinf);
}
return (nout);
}
int fpr_usage (fp)
FILE *fp;
{
int nout = 0;
nout += fprintf (stderr,
"Usage: %s [-%s] [-%s] [-%s] grpname [...]\n",
trim_main_name,
"Iagmnprv", "d char", "e char" );
return (nout);
}