Deleted Added
sdiff udiff text old ( 200462 ) new ( 201140 )
full compact
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Tony Nardo of the Johns Hopkins University/Applied Physics Lab.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 27 unchanged lines hidden (view full) ---

36
37#if 0
38#ifndef lint
39static char sccsid[] = "@(#)util.c 8.3 (Berkeley) 4/28/95";
40#endif
41#endif
42
43#include <sys/cdefs.h>
44__FBSDID("$FreeBSD: head/usr.bin/finger/util.c 200462 2009-12-13 03:14:06Z delphij $");
45
46#include <sys/param.h>
47#include <sys/socket.h>
48#include <sys/stat.h>
49#include <ctype.h>
50#include <db.h>
51#include <err.h>
52#include <errno.h>
53#include <fcntl.h>
54#include <paths.h>
55#include <pwd.h>
56#include <stdio.h>
57#include <stdlib.h>
58#include <string.h>
59#include <unistd.h>
60#include <utmp.h>
61#include "finger.h"
62#include "pathnames.h"
63
64static void find_idle_and_ttywrite(WHERE *);
65static void userinfo(PERSON *, struct passwd *);
66static WHERE *walloc(PERSON *);
67
68int

--- 35 unchanged lines hidden (view full) ---

104 return(1);
105 return(0);
106}
107
108void
109enter_lastlog(PERSON *pn)
110{
111 WHERE *w;
112 static int opened, fd;
113 struct lastlog ll;
114 char doit = 0;
115
116 /* some systems may not maintain lastlog, don't report errors. */
117 if (!opened) {
118 fd = open(_PATH_LASTLOG, O_RDONLY, 0);
119 opened = 1;
120 }
121 if (fd == -1 ||
122 lseek(fd, (long)pn->uid * sizeof(ll), SEEK_SET) !=
123 (long)pn->uid * sizeof(ll) ||
124 read(fd, (char *)&ll, sizeof(ll)) != sizeof(ll)) {
125 /* as if never logged in */
126 ll.ll_line[0] = ll.ll_host[0] = '\0';
127 ll.ll_time = 0;
128 }
129 if ((w = pn->whead) == NULL)
130 doit = 1;
131 else if (ll.ll_time != 0) {
132 /* if last login is earlier than some current login */
133 for (; !doit && w != NULL; w = w->next)
134 if (w->info == LOGGEDIN && w->loginat < ll.ll_time)
135 doit = 1;
136 /*
137 * and if it's not any of the current logins
138 * can't use time comparison because there may be a small
139 * discrepancy since login calls time() twice
140 */
141 for (w = pn->whead; doit && w != NULL; w = w->next)
142 if (w->info == LOGGEDIN &&
143 strncmp(w->tty, ll.ll_line, UT_LINESIZE) == 0)
144 doit = 0;
145 }
146 if (doit) {
147 w = walloc(pn);
148 w->info = LASTLOG;
149 bcopy(ll.ll_line, w->tty, UT_LINESIZE);
150 w->tty[UT_LINESIZE] = 0;
151 bcopy(ll.ll_host, w->host, UT_HOSTSIZE);
152 w->host[UT_HOSTSIZE] = 0;
153 w->loginat = ll.ll_time;
154 }
155}
156
157void
158enter_where(struct utmp *ut, PERSON *pn)
159{
160 WHERE *w;
161
162 w = walloc(pn);
163 w->info = LOGGEDIN;
164 bcopy(ut->ut_line, w->tty, UT_LINESIZE);
165 w->tty[UT_LINESIZE] = 0;
166 bcopy(ut->ut_host, w->host, UT_HOSTSIZE);
167 w->host[UT_HOSTSIZE] = 0;
168 w->loginat = (time_t)ut->ut_time;
169 find_idle_and_ttywrite(w);
170}
171
172PERSON *
173enter_person(struct passwd *pw)
174{
175 DBT data, key;
176 PERSON *pn;

--- 23 unchanged lines hidden (view full) ---

200 data.data = &pn;
201 if ((*db->put)(db, &key, &data, 0))
202 err(1, "db put");
203 return (pn);
204 }
205}
206
207PERSON *
208find_person(const char *name)
209{
210 struct passwd *pw;
211
212 int cnt;
213 DBT data, key;
214 PERSON *p;
215 char buf[UT_NAMESIZE + 1];
216
217 if (!db)
218 return(NULL);
219
220 if ((pw = getpwnam(name)) && hide(pw))
221 return(NULL);
222
223 /* Name may be only UT_NAMESIZE long and not NUL terminated. */
224 for (cnt = 0; cnt < UT_NAMESIZE && *name; ++name, ++cnt)
225 buf[cnt] = *name;
226 buf[cnt] = '\0';
227 key.data = buf;
228 key.size = cnt;
229
230 if ((*db->get)(db, &key, &data, 0))
231 return (NULL);
232 memmove(&p, data.data, sizeof p);
233 return (p);
234}
235
236PERSON *

--- 193 unchanged lines hidden ---