Deleted Added
full compact
util.c (96785) util.c (102944)
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>
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 96785 2002-05-17 05:11:07Z jmallett $");
44__FBSDID("$FreeBSD: head/usr.bin/finger/util.c 102944 2002-09-04 23:29:10Z dwmalone $");
45
46#include <sys/param.h>
45
46#include <sys/param.h>
47#include <sys/socket.h>
47#include <sys/stat.h>
48#include <ctype.h>
49#include <db.h>
50#include <err.h>
51#include <errno.h>
52#include <fcntl.h>
53#include <paths.h>
54#include <pwd.h>

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

60#include "finger.h"
61#include "pathnames.h"
62
63static void find_idle_and_ttywrite(WHERE *);
64static void userinfo(PERSON *, struct passwd *);
65static WHERE *walloc(PERSON *);
66
67int
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>

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

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
68match(pw, user)
69 struct passwd *pw;
70 char *user;
69match(struct passwd *pw, const char *user)
71{
72 char *p, *t;
73 char name[1024];
74
75 if (!strcasecmp(pw->pw_name, user))
76 return(1);
77
78 /*

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

102 *t = '\0';
103 for (t = name; (p = strtok(t, "\t ")) != NULL; t = NULL)
104 if (!strcasecmp(p, user))
105 return(1);
106 return(0);
107}
108
109void
70{
71 char *p, *t;
72 char name[1024];
73
74 if (!strcasecmp(pw->pw_name, user))
75 return(1);
76
77 /*

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

101 *t = '\0';
102 for (t = name; (p = strtok(t, "\t ")) != NULL; t = NULL)
103 if (!strcasecmp(p, user))
104 return(1);
105 return(0);
106}
107
108void
110enter_lastlog(pn)
111 PERSON *pn;
109enter_lastlog(PERSON *pn)
112{
113 WHERE *w;
114 static int opened, fd;
115 struct lastlog ll;
116 char doit = 0;
117
118 /* some systems may not maintain lastlog, don't report errors. */
119 if (!opened) {

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

152 w->tty[UT_LINESIZE] = 0;
153 bcopy(ll.ll_host, w->host, UT_HOSTSIZE);
154 w->host[UT_HOSTSIZE] = 0;
155 w->loginat = ll.ll_time;
156 }
157}
158
159void
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) {

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

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
160enter_where(ut, pn)
161 struct utmp *ut;
162 PERSON *pn;
158enter_where(struct utmp *ut, PERSON *pn)
163{
164 WHERE *w;
165
166 w = walloc(pn);
167 w->info = LOGGEDIN;
168 bcopy(ut->ut_line, w->tty, UT_LINESIZE);
169 w->tty[UT_LINESIZE] = 0;
170 bcopy(ut->ut_host, w->host, UT_HOSTSIZE);
171 w->host[UT_HOSTSIZE] = 0;
172 w->loginat = (time_t)ut->ut_time;
173 find_idle_and_ttywrite(w);
174}
175
176PERSON *
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 *
177enter_person(pw)
178 struct passwd *pw;
173enter_person(struct passwd *pw)
179{
180 DBT data, key;
181 PERSON *pn;
182
183 if (db == NULL &&
184 (db = dbopen(NULL, O_RDWR, 0, DB_BTREE, NULL)) == NULL)
185 err(1, NULL);
186

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

205 data.data = &pn;
206 if ((*db->put)(db, &key, &data, 0))
207 err(1, "db put");
208 return (pn);
209 }
210}
211
212PERSON *
174{
175 DBT data, key;
176 PERSON *pn;
177
178 if (db == NULL &&
179 (db = dbopen(NULL, O_RDWR, 0, DB_BTREE, NULL)) == NULL)
180 err(1, NULL);
181

--- 18 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 *
213find_person(name)
214 char *name;
208find_person(const char *name)
215{
216 struct passwd *pw;
217
218 int cnt;
219 DBT data, key;
220 PERSON *p;
221 char buf[UT_NAMESIZE + 1];
222

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

235
236 if ((*db->get)(db, &key, &data, 0))
237 return (NULL);
238 memmove(&p, data.data, sizeof p);
239 return (p);
240}
241
242PERSON *
209{
210 struct passwd *pw;
211
212 int cnt;
213 DBT data, key;
214 PERSON *p;
215 char buf[UT_NAMESIZE + 1];
216

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

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 *
243palloc()
237palloc(void)
244{
245 PERSON *p;
246
247 if ((p = malloc(sizeof(PERSON))) == NULL)
248 err(1, NULL);
249 return(p);
250}
251
252static WHERE *
238{
239 PERSON *p;
240
241 if ((p = malloc(sizeof(PERSON))) == NULL)
242 err(1, NULL);
243 return(p);
244}
245
246static WHERE *
253walloc(pn)
254 PERSON *pn;
247walloc(PERSON *pn)
255{
256 WHERE *w;
257
258 if ((w = malloc(sizeof(WHERE))) == NULL)
259 err(1, NULL);
260 if (pn->whead == NULL)
261 pn->whead = pn->wtail = w;
262 else {
263 pn->wtail->next = w;
264 pn->wtail = w;
265 }
266 w->next = NULL;
267 return(w);
268}
269
270char *
248{
249 WHERE *w;
250
251 if ((w = malloc(sizeof(WHERE))) == NULL)
252 err(1, NULL);
253 if (pn->whead == NULL)
254 pn->whead = pn->wtail = w;
255 else {
256 pn->wtail->next = w;
257 pn->wtail = w;
258 }
259 w->next = NULL;
260 return(w);
261}
262
263char *
271prphone(num)
272 char *num;
264prphone(char *num)
273{
274 char *p;
275 int len;
276 static char pbuf[20];
277
278 /* don't touch anything if the user has their own formatting */
279 for (p = num; *p; ++p)
280 if (!isdigit(*p))

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

313 *p++ = *num++;
314 *p++ = *num++;
315 *p++ = *num++;
316 *p = '\0';
317 return(pbuf);
318}
319
320static void
265{
266 char *p;
267 int len;
268 static char pbuf[20];
269
270 /* don't touch anything if the user has their own formatting */
271 for (p = num; *p; ++p)
272 if (!isdigit(*p))

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

305 *p++ = *num++;
306 *p++ = *num++;
307 *p++ = *num++;
308 *p = '\0';
309 return(pbuf);
310}
311
312static void
321find_idle_and_ttywrite(w)
322 WHERE *w;
313find_idle_and_ttywrite(WHERE *w)
323{
314{
324 extern time_t now;
325 struct stat sb;
326 time_t touched;
327
328 (void)snprintf(tbuf, sizeof(tbuf), "%s/%s", _PATH_DEV, w->tty);
329 if (stat(tbuf, &sb) < 0) {
330 warn("%s", tbuf);
331 return;
332 }

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

337 }
338 w->idletime = now < touched ? 0 : now - touched;
339
340#define TALKABLE 0220 /* tty is writable if 220 mode */
341 w->writable = ((sb.st_mode & TALKABLE) == TALKABLE);
342}
343
344static void
315 struct stat sb;
316 time_t touched;
317
318 (void)snprintf(tbuf, sizeof(tbuf), "%s/%s", _PATH_DEV, w->tty);
319 if (stat(tbuf, &sb) < 0) {
320 warn("%s", tbuf);
321 return;
322 }

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

327 }
328 w->idletime = now < touched ? 0 : now - touched;
329
330#define TALKABLE 0220 /* tty is writable if 220 mode */
331 w->writable = ((sb.st_mode & TALKABLE) == TALKABLE);
332}
333
334static void
345userinfo(pn, pw)
346 PERSON *pn;
347 struct passwd *pw;
335userinfo(PERSON *pn, struct passwd *pw)
348{
349 char *p, *t;
350 char *bp, name[1024];
351 struct stat sb;
352
353 pn->realname = pn->office = pn->officephone = pn->homephone = NULL;
354
355 pn->uid = pw->pw_uid;

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

405}
406
407/*
408 * Is this user hiding from finger?
409 * If ~<user>/.nofinger exists, return 1 (hide), else return 0 (nohide).
410 */
411
412int
336{
337 char *p, *t;
338 char *bp, name[1024];
339 struct stat sb;
340
341 pn->realname = pn->office = pn->officephone = pn->homephone = NULL;
342
343 pn->uid = pw->pw_uid;

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

393}
394
395/*
396 * Is this user hiding from finger?
397 * If ~<user>/.nofinger exists, return 1 (hide), else return 0 (nohide).
398 */
399
400int
413hide(pw)
414 struct passwd *pw;
401hide(struct passwd *pw)
415{
416 struct stat st;
417 char buf[MAXPATHLEN];
418
419 if (!pw->pw_dir)
420 return 0;
421
422 snprintf(buf, sizeof(buf), "%s/%s", pw->pw_dir, _PATH_NOFINGER);
423
424 if (stat(buf, &st) == 0)
425 return 1;
426
427 return 0;
428}
402{
403 struct stat st;
404 char buf[MAXPATHLEN];
405
406 if (!pw->pw_dir)
407 return 0;
408
409 snprintf(buf, sizeof(buf), "%s/%s", pw->pw_dir, _PATH_NOFINGER);
410
411 if (stat(buf, &st) == 0)
412 return 1;
413
414 return 0;
415}