home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume6
/
shadow-2.pt3
/
pwent.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-02-03
|
2KB
|
112 lines
#include <stdio.h>
#include <pwd.h>
#include <string.h>
#define SBUFSIZ 64
static char *tokcpy (buf, token)
char *buf;
char *token;
{
static char *cp;
char *start;
if (buf == (char *) 0)
buf = cp;
else
cp = buf;
start = cp;
if (*buf == '\0')
return ((char *) 0);
while (*buf && *buf != ':')
*token++ = *buf++;
*token = '\0';
if (*buf)
cp = buf + 1;
return (start);
}
struct passwd *sgetpwent (buf)
char *buf;
{
static struct passwd pwent;
static char name[SBUFSIZ];
static char password[SBUFSIZ];
static char gecos[SBUFSIZ];
static char home[SBUFSIZ];
static char shell[SBUFSIZ];
static char age[SBUFSIZ];
char tmp[BUFSIZ];
char *cp;
pwent.pw_name = name;
pwent.pw_passwd = password;
pwent.pw_uid = -1;
pwent.pw_gid = -1;
pwent.pw_age = age;
pwent.pw_comment = (char *) 0;
pwent.pw_gecos = gecos;
pwent.pw_dir = home;
pwent.pw_shell = shell;
(void) strcpy (tmp, buf);
if (! tokcpy (tmp, name) || ! name[0])
return ((struct passwd *) 0);
if (! tokcpy ((char *) 0, password))
return ((struct passwd *) 0);
if (tokcpy ((char *) 0, tmp) && *tmp)
pwent.pw_uid = atoi (tmp);
else
return ((struct passwd *) 0);
if (tokcpy ((char *) 0, tmp) && *tmp)
pwent.pw_gid = atoi (tmp);
else
return ((struct passwd *) 0);
if (cp = strchr (password, ',')) {
(void) strcpy (age, cp + 1);
*cp = '\0';
} else
pwent.pw_age = (char *) 0;
if (! tokcpy ((char *) 0, gecos))
return ((struct passwd *) 0);
if (! tokcpy ((char *) 0, home))
return ((struct passwd *) 0);
if (! tokcpy ((char *) 0, shell) && *shell)
pwent.pw_shell = (char *) 0;
if (pwent.pw_passwd && pwent.pw_passwd[0] == '\0')
pwent.pw_passwd = (char *) 0;
return (&pwent);
}
#ifdef FGETPWENT
struct passwd *fgetpwent (fp)
FILE *fp;
{
char buf[BUFSIZ];
while (fgets (buf, BUFSIZ, fp) != (char *) 0) {
if (buf[0] == '#')
continue;
buf[strlen (buf) - 1] = '\0';
return (sgetpwent (buf));
}
return ((struct passwd *) 0);
}
#endif