source: trunk/athena/bin/finger/hespwnam.c @ 744

Revision 744, 1.7 KB checked in by ambar, 37 years ago (diff)
Initial revision
Line 
1/*
2 * Copyright 1987 by the Massachusetts Institute of Technology.
3 * For copying and distribution information, see the file
4 * "mit-copyright.h".
5 *
6 *      $Source: /afs/dev.mit.edu/source/repository/athena/bin/finger/hespwnam.c,v $
7 *      $Author: ambar $
8 *      $Header: /afs/dev.mit.edu/source/repository/athena/bin/finger/hespwnam.c,v 1.1 1987-08-21 18:20:40 ambar Exp $
9 *      $Log: not supported by cvs2svn $
10 *
11 */
12
13#ifndef lint
14static char *rcsid_hespwnam_c = "$Header: /afs/dev.mit.edu/source/repository/athena/bin/finger/hespwnam.c,v 1.1 1987-08-21 18:20:40 ambar Exp $";
15#endif lint
16
17#include <stdio.h>
18#include <pwd.h>
19#include "mit-copyright.h"
20
21static struct passwd passwd;
22static char buf[256];
23
24char *strcpy();
25
26struct passwd *
27hesgetpwnam(nam)
28    char *nam;
29{
30    struct passwd *pwcommon();
31    char **pp, **hes_resolve();
32
33    pp = hes_resolve(nam, "passwd");
34    return pwcommon(pp);
35}
36
37static
38struct passwd *
39pwcommon(pp)
40    char **pp;
41{
42    register char *p;
43    char *pwskip();
44
45    if (pp == NULL)
46        return (NULL);
47    /* choose only the first response (only 1 expected) */
48    (void) strcpy(buf, pp[0]);
49    while (*pp)
50        free(*pp++);            /* necessary to avoid leaks */
51    p = buf;
52    passwd.pw_name = p;
53    p = pwskip(p);
54    passwd.pw_passwd = p;
55    p = pwskip(p);
56    passwd.pw_uid = atoi(p);
57    p = pwskip(p);
58    passwd.pw_gid = atoi(p);
59    passwd.pw_quota = 0;
60    passwd.pw_comment = "";
61    p = pwskip(p);
62    passwd.pw_gecos = p;
63    p = pwskip(p);
64    passwd.pw_dir = p;
65    p = pwskip(p);
66    passwd.pw_shell = p;
67    while (*p && *p != '\n')
68        p++;
69    *p = '\0';
70    return (&passwd);
71}
72
73static char *
74pwskip(p)
75    register char *p;
76{
77    while (*p && *p != ':' && *p != '\n')
78        ++p;
79    if (*p)
80        *p++ = 0;
81    return (p);
82}
Note: See TracBrowser for help on using the repository browser.