home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1989, 1990, John F. Haugh II
- * All rights reserved.
- *
- * Use, duplication, and disclosure prohibited without
- * the express written permission of the author.
- */
-
- #include <stdio.h>
- #include <pwd.h>
- #ifndef BSD
- #include <string.h>
- #else
- #include <strings.h>
- #define strchr index
- #define strrchr rindex
- #endif
- #include "config.h"
- #ifdef SHADOWPWD
- #include "shadow.h"
- #endif
-
- #ifndef lint
- static char _sccsid[] = "@(#)entry.c 2.3 07:47:34 8/14/90";
- #endif
-
- struct passwd *fgetpwent ();
- char *malloc ();
-
- char *strdup (s)
- char *s;
- {
- char *cp;
-
- if (s == (char *) 0)
- return ((char *) 0);
-
- if (! (cp = malloc ((unsigned) strlen (s) + 1)))
- return ((char *) 0);
-
- return (strcpy (cp, s));
- }
-
- void entry (name, pwent)
- char *name;
- struct passwd *pwent;
- {
- FILE *pwd;
- struct passwd *passwd;
- #ifdef SHADOWPWD
- struct spwd *spwd;
- char *l64a ();
- #endif
- char *cp;
-
- if ((pwd = fopen (PWDFILE, "r")) == (FILE *) 0) {
- pwent->pw_passwd = (char *) 0;
- return;
- }
- while (passwd = fgetpwent (pwd)) {
- if (strcmp (name, passwd->pw_name) == 0)
- break;
- }
- fclose (pwd);
-
- if (passwd == (struct passwd *) 0) {
- pwent->pw_name = (char *) 0;
- pwent->pw_passwd = (char *) 0;
- } else {
- pwent->pw_name = strdup (passwd->pw_name);
- pwent->pw_uid = passwd->pw_uid;
- pwent->pw_gid = passwd->pw_gid;
- pwent->pw_comment = (char *) 0;
- pwent->pw_gecos = strdup (passwd->pw_gecos);
- pwent->pw_dir = strdup (passwd->pw_dir);
- pwent->pw_shell = strdup (passwd->pw_shell);
- #ifdef SHADOWPWD
- setspent ();
- if (spwd = getspnam (name)) {
- pwent->pw_passwd = strdup (spwd->sp_pwdp);
-
- pwent->pw_age = malloc (5);
-
- if (spwd->sp_max > (63*7))
- spwd->sp_max = (63*7);
- if (spwd->sp_min > (63*7))
- spwd->sp_min = (63*7);
-
- pwent->pw_age[0] = i64c (spwd->sp_max / 7);
- pwent->pw_age[1] = i64c (spwd->sp_min / 7);
-
- cp = l64a (spwd->sp_lstchg / 7);
- pwent->pw_age[2] = cp[0];
- pwent->pw_age[3] = cp[1];
-
- pwent->pw_age[4] = '\0';
-
- endspent ();
- return;
- }
- endspent ();
- passwd->pw_age = pwent->pw_age = (char *) 0;
- #endif
- if (passwd->pw_passwd)
- pwent->pw_passwd = strdup (passwd->pw_passwd);
- else
- pwent->pw_passwd = (char *) 0;
-
- if (passwd->pw_age) {
- pwent->pw_age = malloc (5); /* longest legal time */
- (void) strncpy (pwent->pw_age, passwd->pw_age, 5);
- } else
- pwent->pw_age = (char *) 0;
- }
- }
-