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 201140 2009-12-28 20:54:34Z ed $"); |
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#define _ULOG_POSIX_NAMES 60#include <ulog.h> |
61#include <unistd.h> |
62#include "finger.h" 63#include "pathnames.h" 64 65static void find_idle_and_ttywrite(WHERE *); 66static void userinfo(PERSON *, struct passwd *); 67static WHERE *walloc(PERSON *); 68 69int --- 35 unchanged lines hidden (view full) --- 105 return(1); 106 return(0); 107} 108 109void 110enter_lastlog(PERSON *pn) 111{ 112 WHERE *w; |
113 struct ulog_utmpx *ut; |
114 char doit = 0; 115 |
116 ulog_setutxfile(UTXI_USER, NULL); 117 ut = ulog_getutxuser(pn->name); |
118 if ((w = pn->whead) == NULL) 119 doit = 1; |
120 else if (ut != NULL && ut->ut_type == USER_PROCESS) { |
121 /* if last login is earlier than some current login */ 122 for (; !doit && w != NULL; w = w->next) |
123 if (w->info == LOGGEDIN && 124 w->loginat < ut->ut_tv.tv_sec) |
125 doit = 1; 126 /* 127 * and if it's not any of the current logins 128 * can't use time comparison because there may be a small 129 * discrepancy since login calls time() twice 130 */ 131 for (w = pn->whead; doit && w != NULL; w = w->next) 132 if (w->info == LOGGEDIN && |
133 strcmp(w->tty, ut->ut_line) == 0) |
134 doit = 0; 135 } |
136 if (ut != NULL && doit) { |
137 w = walloc(pn); 138 w->info = LASTLOG; |
139 strcpy(w->tty, ut->ut_line); 140 strcpy(w->host, ut->ut_host); 141 w->loginat = ut->ut_tv.tv_sec; |
142 } |
143 ulog_endutxent(); |
144} 145 146void |
147enter_where(struct utmpx *ut, PERSON *pn) |
148{ 149 WHERE *w; 150 151 w = walloc(pn); 152 w->info = LOGGEDIN; |
153 strcpy(w->tty, ut->ut_line); 154 strcpy(w->host, ut->ut_host); 155 w->loginat = ut->ut_tv.tv_sec; |
156 find_idle_and_ttywrite(w); 157} 158 159PERSON * 160enter_person(struct passwd *pw) 161{ 162 DBT data, key; 163 PERSON *pn; --- 23 unchanged lines hidden (view full) --- 187 data.data = &pn; 188 if ((*db->put)(db, &key, &data, 0)) 189 err(1, "db put"); 190 return (pn); 191 } 192} 193 194PERSON * |
195find_person(char *name) |
196{ 197 struct passwd *pw; 198 |
199 DBT data, key; 200 PERSON *p; |
201 202 if (!db) 203 return(NULL); 204 205 if ((pw = getpwnam(name)) && hide(pw)) 206 return(NULL); 207 |
208 key.data = name; 209 key.size = strlen(name); |
210 211 if ((*db->get)(db, &key, &data, 0)) 212 return (NULL); 213 memmove(&p, data.data, sizeof p); 214 return (p); 215} 216 217PERSON * --- 193 unchanged lines hidden --- |