home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Source Code 1992 March
/
Source_Code_CD-ROM_Walnut_Creek_March_1992.iso
/
usenet
/
altsrcs
/
2
/
2288
/
grent.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-12-28
|
1KB
|
70 lines
/*
* Copyright 1990, John F. Haugh II
* All rights reserved.
*
* Non-commercial distribution permitted. You must provide this source
* code in any distribution. This notice must remain intact.
*/
#include <stdio.h>
#include <grp.h>
#include <string.h>
#include "config.h"
#ifdef DBM
#include <dbm.h>
#endif
#ifndef lint
static char _sccsid[] = "@(#)grent.c 1.1 08:14:07 6/20/90";
#endif
#define NFIELDS 4
#define MAXMEM 1024
static char grpbuf[4*BUFSIZ];
static char *grpfields[NFIELDS];
static char *members[MAXMEM+1];
static char **
list (s)
char *s;
{
int nmembers = 0;
while (*s) {
members[nmembers++] = s;
if (s = strchr (s, ','))
*s++ = '\0';
}
members[nmembers] = (char *) 0;
return members;
}
struct group *sgetgrent (buf)
char *buf;
{
int i;
char *cp;
static struct group grent;
strncpy (grpbuf, buf, sizeof grpbuf);
grpbuf[sizeof grpbuf - 1] = '\0';
if (cp = strrchr (grpbuf, '\n'))
*cp = '\0';
for (cp = grpbuf, i = 0;i < NFIELDS && cp;i++) {
grpfields[i] = cp;
if (cp = strchr (cp, ':'))
*cp++ = 0;
}
if (i < (NFIELDS-1) || *grpfields[2] == '\0')
return ((struct group *) 0);
grent.gr_name = grpfields[0];
grent.gr_passwd = grpfields[1];
grent.gr_gid = atoi (grpfields[2]);
grent.gr_mem = list (grpfields[3]);
return (&grent);
}