home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
TELECOM
/
stg_v4.lzh
/
grp.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-11-11
|
2KB
|
122 lines
/*
* group file routines
*
* 92/10/27 StG initial version for semi unix compatible
*/
#include "stglib.h"
/* unix already has these functions */
#ifndef _UNIX
#include "grp.h"
#include "stglib.h"
extern int errno;
#define GRPBUF 256
int hGRP=0; /* file number */
struct group _grp;
char grp_buf[GRPBUF];
setgrent()
{
int uid;
if (hGRP)
{
lseek(hGRP,0L,0);
return(0);
}
uid=getuid();
setuid(0);
hGRP=open(GRP_FILE,O_RDONLY);
if (hGRP==ERR)
{
if (errno!=216)
syslog(LOG_CRIT,"setgrent: cant access %s %m",GRP_FILE);
hGRP=0;
setuid(uid);
return(ERR);
}
setuid(uid);
return(0);
}
endgrent()
{
if (hGRP)
{
close(hGRP);
hGRP=0;
}
return(0);
}
struct group *
getgrent()
{
char *p;
int n;
if (!hGRP)
if (setgrent()==ERR)
return(0);
nextline:
n=readln(hGRP,grp_buf,GRPBUF);
if (n<=0)
return(0);
grp_buf[n-1]=0;
if (!*grp_buf || *grp_buf=='*')
goto nextline;
_grp.gr_mem=0;
_grp.gr_name=grp_buf;
p=strcut(grp_buf,',');
if (p)
{
p=strcut(p,',');
if (p)
{
p=strcut(p,',');
_grp.gr_mem=arglist(p,':');
}
}
return(&_grp);
}
struct group *
getgrnam(name)
char *name;
{
struct group *gr;
if (_grp.gr_name && !stricmp(_grp.gr_name,name))
return(&_grp);
setgrent();
do
{
gr=getgrent();
if (!gr)
{
/* endgrent(); */
return(0);
}
}
while (stricmp(gr->gr_name,name));
/* endgrent(); */
return(gr);
}
#endif