util.c (200462) | util.c (201140) |
---|---|
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 200462 2009-12-13 03:14:06Z delphij $"); | 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> | 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> |
|
59#include <unistd.h> | 61#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; | 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; |
112 static int opened, fd; 113 struct lastlog ll; | 113 struct ulog_utmpx *ut; |
114 char doit = 0; 115 | 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 } | 116 ulog_setutxfile(UTXI_USER, NULL); 117 ut = ulog_getutxuser(pn->name); |
129 if ((w = pn->whead) == NULL) 130 doit = 1; | 118 if ((w = pn->whead) == NULL) 119 doit = 1; |
131 else if (ll.ll_time != 0) { | 120 else if (ut != NULL && ut->ut_type == USER_PROCESS) { |
132 /* if last login is earlier than some current login */ 133 for (; !doit && w != NULL; w = w->next) | 121 /* if last login is earlier than some current login */ 122 for (; !doit && w != NULL; w = w->next) |
134 if (w->info == LOGGEDIN && w->loginat < ll.ll_time) | 123 if (w->info == LOGGEDIN && 124 w->loginat < ut->ut_tv.tv_sec) |
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 && | 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 && |
143 strncmp(w->tty, ll.ll_line, UT_LINESIZE) == 0) | 133 strcmp(w->tty, ut->ut_line) == 0) |
144 doit = 0; 145 } | 134 doit = 0; 135 } |
146 if (doit) { | 136 if (ut != NULL && doit) { |
147 w = walloc(pn); 148 w->info = LASTLOG; | 137 w = walloc(pn); 138 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; | 139 strcpy(w->tty, ut->ut_line); 140 strcpy(w->host, ut->ut_host); 141 w->loginat = ut->ut_tv.tv_sec; |
154 } | 142 } |
143 ulog_endutxent(); |
|
155} 156 157void | 144} 145 146void |
158enter_where(struct utmp *ut, PERSON *pn) | 147enter_where(struct utmpx *ut, PERSON *pn) |
159{ 160 WHERE *w; 161 162 w = walloc(pn); 163 w->info = LOGGEDIN; | 148{ 149 WHERE *w; 150 151 w = walloc(pn); 152 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; | 153 strcpy(w->tty, ut->ut_line); 154 strcpy(w->host, ut->ut_host); 155 w->loginat = ut->ut_tv.tv_sec; |
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 * | 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 * |
208find_person(const char *name) | 195find_person(char *name) |
209{ 210 struct passwd *pw; 211 | 196{ 197 struct passwd *pw; 198 |
212 int cnt; | |
213 DBT data, key; 214 PERSON *p; | 199 DBT data, key; 200 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 | 201 202 if (!db) 203 return(NULL); 204 205 if ((pw = getpwnam(name)) && hide(pw)) 206 return(NULL); 207 |
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; | 208 key.data = name; 209 key.size = strlen(name); |
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 --- | 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 --- |