1*8a16b7a1SPedro F. Giffuni /*- 2*8a16b7a1SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 3*8a16b7a1SPedro F. Giffuni * 49b50d902SRodney W. Grimes * Copyright (c) 1989, 1993 59b50d902SRodney W. Grimes * The Regents of the University of California. All rights reserved. 69b50d902SRodney W. Grimes * 79b50d902SRodney W. Grimes * This code is derived from software contributed to Berkeley by 89b50d902SRodney W. Grimes * Tony Nardo of the Johns Hopkins University/Applied Physics Lab. 99b50d902SRodney W. Grimes * 109b50d902SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 119b50d902SRodney W. Grimes * modification, are permitted provided that the following conditions 129b50d902SRodney W. Grimes * are met: 139b50d902SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 149b50d902SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 159b50d902SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 169b50d902SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 179b50d902SRodney W. Grimes * documentation and/or other materials provided with the distribution. 18fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors 199b50d902SRodney W. Grimes * may be used to endorse or promote products derived from this software 209b50d902SRodney W. Grimes * without specific prior written permission. 219b50d902SRodney W. Grimes * 229b50d902SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 239b50d902SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 249b50d902SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 259b50d902SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 269b50d902SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 279b50d902SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 289b50d902SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 299b50d902SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 309b50d902SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 319b50d902SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 329b50d902SRodney W. Grimes * SUCH DAMAGE. 339b50d902SRodney W. Grimes */ 349b50d902SRodney W. Grimes 359f5b04e9SDavid Malone #if 0 369b50d902SRodney W. Grimes #ifndef lint 379f5b04e9SDavid Malone static char sccsid[] = "@(#)util.c 8.3 (Berkeley) 4/28/95"; 384c86f3adSPhilippe Charnier #endif 399f5b04e9SDavid Malone #endif 409f5b04e9SDavid Malone 419f5b04e9SDavid Malone #include <sys/cdefs.h> 429f5b04e9SDavid Malone __FBSDID("$FreeBSD$"); 439b50d902SRodney W. Grimes 449b50d902SRodney W. Grimes #include <sys/param.h> 45f4ac32deSDavid Malone #include <sys/socket.h> 469b50d902SRodney W. Grimes #include <sys/stat.h> 474c86f3adSPhilippe Charnier #include <ctype.h> 489b50d902SRodney W. Grimes #include <db.h> 49df3f5d9dSPeter Wemm #include <err.h> 509b50d902SRodney W. Grimes #include <errno.h> 514c86f3adSPhilippe Charnier #include <fcntl.h> 524c86f3adSPhilippe Charnier #include <paths.h> 534c86f3adSPhilippe Charnier #include <pwd.h> 549b50d902SRodney W. Grimes #include <stdio.h> 559b50d902SRodney W. Grimes #include <stdlib.h> 569b50d902SRodney W. Grimes #include <string.h> 574c86f3adSPhilippe Charnier #include <unistd.h> 58550dcc59SEd Schouten #include <utmpx.h> 599b50d902SRodney W. Grimes #include "finger.h" 60b95dbabaSYaroslav Tykhiy #include "pathnames.h" 619b50d902SRodney W. Grimes 62f1bb2cd2SWarner Losh static void find_idle_and_ttywrite(WHERE *); 63f1bb2cd2SWarner Losh static void userinfo(PERSON *, struct passwd *); 64f1bb2cd2SWarner Losh static WHERE *walloc(PERSON *); 659b50d902SRodney W. Grimes 669b50d902SRodney W. Grimes int 67f4ac32deSDavid Malone match(struct passwd *pw, const char *user) 689b50d902SRodney W. Grimes { 694e030ba6SMark Murray char *p, *t; 709b50d902SRodney W. Grimes char name[1024]; 719b50d902SRodney W. Grimes 729b50d902SRodney W. Grimes if (!strcasecmp(pw->pw_name, user)) 739b50d902SRodney W. Grimes return(1); 749b50d902SRodney W. Grimes 759b50d902SRodney W. Grimes /* 769b50d902SRodney W. Grimes * XXX 779b50d902SRodney W. Grimes * Why do we skip asterisks!?!? 789b50d902SRodney W. Grimes */ 79e0d8eea1SWarner Losh (void)strncpy(p = tbuf, pw->pw_gecos, sizeof(tbuf)); 80b59bb23bSWarner Losh tbuf[sizeof(tbuf) - 1] = '\0'; 819b50d902SRodney W. Grimes if (*p == '*') 829b50d902SRodney W. Grimes ++p; 839b50d902SRodney W. Grimes 849b50d902SRodney W. Grimes /* Ampersands get replaced by the login name. */ 859b50d902SRodney W. Grimes if ((p = strtok(p, ",")) == NULL) 869b50d902SRodney W. Grimes return(0); 879b50d902SRodney W. Grimes 88b59bb23bSWarner Losh for (t = name; t < &name[sizeof(name) - 1] && (*t = *p) != '\0'; ++p) { 899b50d902SRodney W. Grimes if (*t == '&') { 90e0d8eea1SWarner Losh (void)strncpy(t, pw->pw_name, 91e0d8eea1SWarner Losh sizeof(name) - (t - name)); 92e0d8eea1SWarner Losh name[sizeof(name) - 1] = '\0'; 93b59bb23bSWarner Losh while (t < &name[sizeof(name) - 1] && *++t) 94b59bb23bSWarner Losh continue; 95e0d8eea1SWarner Losh } else { 969b50d902SRodney W. Grimes ++t; 97e0d8eea1SWarner Losh } 98e0d8eea1SWarner Losh } 99e0d8eea1SWarner Losh *t = '\0'; 100df3f5d9dSPeter Wemm for (t = name; (p = strtok(t, "\t ")) != NULL; t = NULL) 1019b50d902SRodney W. Grimes if (!strcasecmp(p, user)) 1029b50d902SRodney W. Grimes return(1); 1039b50d902SRodney W. Grimes return(0); 1049b50d902SRodney W. Grimes } 1059b50d902SRodney W. Grimes 1069b50d902SRodney W. Grimes void 107f4ac32deSDavid Malone enter_lastlog(PERSON *pn) 1089b50d902SRodney W. Grimes { 1094e030ba6SMark Murray WHERE *w; 110550dcc59SEd Schouten struct utmpx *ut = NULL; 1119b50d902SRodney W. Grimes char doit = 0; 1129b50d902SRodney W. Grimes 113550dcc59SEd Schouten if (setutxdb(UTXDB_LASTLOGIN, NULL) == 0) 114550dcc59SEd Schouten ut = getutxuser(pn->name); 1159b50d902SRodney W. Grimes if ((w = pn->whead) == NULL) 1169b50d902SRodney W. Grimes doit = 1; 11770ad88f3SEd Schouten else if (ut != NULL && ut->ut_type == USER_PROCESS) { 1189b50d902SRodney W. Grimes /* if last login is earlier than some current login */ 1199b50d902SRodney W. Grimes for (; !doit && w != NULL; w = w->next) 12070ad88f3SEd Schouten if (w->info == LOGGEDIN && 12170ad88f3SEd Schouten w->loginat < ut->ut_tv.tv_sec) 1229b50d902SRodney W. Grimes doit = 1; 1239b50d902SRodney W. Grimes /* 1249b50d902SRodney W. Grimes * and if it's not any of the current logins 1259b50d902SRodney W. Grimes * can't use time comparison because there may be a small 1264c86f3adSPhilippe Charnier * discrepancy since login calls time() twice 1279b50d902SRodney W. Grimes */ 1289b50d902SRodney W. Grimes for (w = pn->whead; doit && w != NULL; w = w->next) 1299b50d902SRodney W. Grimes if (w->info == LOGGEDIN && 13070ad88f3SEd Schouten strcmp(w->tty, ut->ut_line) == 0) 1319b50d902SRodney W. Grimes doit = 0; 1329b50d902SRodney W. Grimes } 13370ad88f3SEd Schouten if (ut != NULL && doit) { 1349b50d902SRodney W. Grimes w = walloc(pn); 1359b50d902SRodney W. Grimes w->info = LASTLOG; 13670ad88f3SEd Schouten strcpy(w->tty, ut->ut_line); 13770ad88f3SEd Schouten strcpy(w->host, ut->ut_host); 13870ad88f3SEd Schouten w->loginat = ut->ut_tv.tv_sec; 1399b50d902SRodney W. Grimes } 140550dcc59SEd Schouten endutxent(); 1419b50d902SRodney W. Grimes } 1429b50d902SRodney W. Grimes 1439b50d902SRodney W. Grimes void 14470ad88f3SEd Schouten enter_where(struct utmpx *ut, PERSON *pn) 1459b50d902SRodney W. Grimes { 1464e030ba6SMark Murray WHERE *w; 1479b50d902SRodney W. Grimes 1489b50d902SRodney W. Grimes w = walloc(pn); 1499b50d902SRodney W. Grimes w->info = LOGGEDIN; 15070ad88f3SEd Schouten strcpy(w->tty, ut->ut_line); 15170ad88f3SEd Schouten strcpy(w->host, ut->ut_host); 15270ad88f3SEd Schouten w->loginat = ut->ut_tv.tv_sec; 1539b50d902SRodney W. Grimes find_idle_and_ttywrite(w); 1549b50d902SRodney W. Grimes } 1559b50d902SRodney W. Grimes 1569b50d902SRodney W. Grimes PERSON * 157f4ac32deSDavid Malone enter_person(struct passwd *pw) 1589b50d902SRodney W. Grimes { 1599b50d902SRodney W. Grimes DBT data, key; 1609b50d902SRodney W. Grimes PERSON *pn; 1619b50d902SRodney W. Grimes 1629b50d902SRodney W. Grimes if (db == NULL && 1639b50d902SRodney W. Grimes (db = dbopen(NULL, O_RDWR, 0, DB_BTREE, NULL)) == NULL) 164df3f5d9dSPeter Wemm err(1, NULL); 1659b50d902SRodney W. Grimes 1669b50d902SRodney W. Grimes key.data = pw->pw_name; 1679b50d902SRodney W. Grimes key.size = strlen(pw->pw_name); 1689b50d902SRodney W. Grimes 1699b50d902SRodney W. Grimes switch ((*db->get)(db, &key, &data, 0)) { 1709b50d902SRodney W. Grimes case 0: 171df3f5d9dSPeter Wemm memmove(&pn, data.data, sizeof pn); 172df3f5d9dSPeter Wemm return (pn); 1739b50d902SRodney W. Grimes default: 1749b50d902SRodney W. Grimes case -1: 175df3f5d9dSPeter Wemm err(1, "db get"); 1769b50d902SRodney W. Grimes /* NOTREACHED */ 1779b50d902SRodney W. Grimes case 1: 1789b50d902SRodney W. Grimes ++entries; 1799b50d902SRodney W. Grimes pn = palloc(); 1809b50d902SRodney W. Grimes userinfo(pn, pw); 1819b50d902SRodney W. Grimes pn->whead = NULL; 1829b50d902SRodney W. Grimes 1839b50d902SRodney W. Grimes data.size = sizeof(PERSON *); 1849b50d902SRodney W. Grimes data.data = &pn; 1859b50d902SRodney W. Grimes if ((*db->put)(db, &key, &data, 0)) 186df3f5d9dSPeter Wemm err(1, "db put"); 1879b50d902SRodney W. Grimes return (pn); 1889b50d902SRodney W. Grimes } 1899b50d902SRodney W. Grimes } 1909b50d902SRodney W. Grimes 1919b50d902SRodney W. Grimes PERSON * 19270ad88f3SEd Schouten find_person(char *name) 1939b50d902SRodney W. Grimes { 1948829c73eSJordan K. Hubbard struct passwd *pw; 1958829c73eSJordan K. Hubbard 1969b50d902SRodney W. Grimes DBT data, key; 197df3f5d9dSPeter Wemm PERSON *p; 1989b50d902SRodney W. Grimes 1999b50d902SRodney W. Grimes if (!db) 2009b50d902SRodney W. Grimes return(NULL); 2019b50d902SRodney W. Grimes 2028829c73eSJordan K. Hubbard if ((pw = getpwnam(name)) && hide(pw)) 2038829c73eSJordan K. Hubbard return(NULL); 2048829c73eSJordan K. Hubbard 20570ad88f3SEd Schouten key.data = name; 20670ad88f3SEd Schouten key.size = strlen(name); 2079b50d902SRodney W. Grimes 208df3f5d9dSPeter Wemm if ((*db->get)(db, &key, &data, 0)) 209df3f5d9dSPeter Wemm return (NULL); 210df3f5d9dSPeter Wemm memmove(&p, data.data, sizeof p); 211df3f5d9dSPeter Wemm return (p); 2129b50d902SRodney W. Grimes } 2139b50d902SRodney W. Grimes 2149b50d902SRodney W. Grimes PERSON * 215f4ac32deSDavid Malone palloc(void) 2169b50d902SRodney W. Grimes { 2179b50d902SRodney W. Grimes PERSON *p; 2189b50d902SRodney W. Grimes 21947bca8b0SJuli Mallett if ((p = malloc(sizeof(PERSON))) == NULL) 220df3f5d9dSPeter Wemm err(1, NULL); 2219b50d902SRodney W. Grimes return(p); 2229b50d902SRodney W. Grimes } 2239b50d902SRodney W. Grimes 2249b50d902SRodney W. Grimes static WHERE * 225f4ac32deSDavid Malone walloc(PERSON *pn) 2269b50d902SRodney W. Grimes { 2274e030ba6SMark Murray WHERE *w; 2289b50d902SRodney W. Grimes 22947bca8b0SJuli Mallett if ((w = malloc(sizeof(WHERE))) == NULL) 230df3f5d9dSPeter Wemm err(1, NULL); 2319b50d902SRodney W. Grimes if (pn->whead == NULL) 2329b50d902SRodney W. Grimes pn->whead = pn->wtail = w; 2339b50d902SRodney W. Grimes else { 2349b50d902SRodney W. Grimes pn->wtail->next = w; 2359b50d902SRodney W. Grimes pn->wtail = w; 2369b50d902SRodney W. Grimes } 2379b50d902SRodney W. Grimes w->next = NULL; 2389b50d902SRodney W. Grimes return(w); 2399b50d902SRodney W. Grimes } 2409b50d902SRodney W. Grimes 2419b50d902SRodney W. Grimes char * 242f4ac32deSDavid Malone prphone(char *num) 2439b50d902SRodney W. Grimes { 2444e030ba6SMark Murray char *p; 2459b50d902SRodney W. Grimes int len; 246e0d8eea1SWarner Losh static char pbuf[20]; 2479b50d902SRodney W. Grimes 2489b50d902SRodney W. Grimes /* don't touch anything if the user has their own formatting */ 2499b50d902SRodney W. Grimes for (p = num; *p; ++p) 2509b50d902SRodney W. Grimes if (!isdigit(*p)) 2519b50d902SRodney W. Grimes return(num); 2529b50d902SRodney W. Grimes len = p - num; 2539b50d902SRodney W. Grimes p = pbuf; 2549b50d902SRodney W. Grimes switch(len) { 2559b50d902SRodney W. Grimes case 11: /* +0-123-456-7890 */ 2569b50d902SRodney W. Grimes *p++ = '+'; 2579b50d902SRodney W. Grimes *p++ = *num++; 2589b50d902SRodney W. Grimes *p++ = '-'; 2599b50d902SRodney W. Grimes /* FALLTHROUGH */ 2609b50d902SRodney W. Grimes case 10: /* 012-345-6789 */ 2619b50d902SRodney W. Grimes *p++ = *num++; 2629b50d902SRodney W. Grimes *p++ = *num++; 2639b50d902SRodney W. Grimes *p++ = *num++; 2649b50d902SRodney W. Grimes *p++ = '-'; 2659b50d902SRodney W. Grimes /* FALLTHROUGH */ 2669b50d902SRodney W. Grimes case 7: /* 012-3456 */ 2679b50d902SRodney W. Grimes *p++ = *num++; 2689b50d902SRodney W. Grimes *p++ = *num++; 2699b50d902SRodney W. Grimes *p++ = *num++; 2709b50d902SRodney W. Grimes break; 2719b50d902SRodney W. Grimes case 5: /* x0-1234 */ 27286641d8fSPaul Traina case 4: /* x1234 */ 2739b50d902SRodney W. Grimes *p++ = 'x'; 2749b50d902SRodney W. Grimes *p++ = *num++; 2759b50d902SRodney W. Grimes break; 2769b50d902SRodney W. Grimes default: 2779b50d902SRodney W. Grimes return(num); 2789b50d902SRodney W. Grimes } 27986641d8fSPaul Traina if (len != 4) { 2809b50d902SRodney W. Grimes *p++ = '-'; 2819b50d902SRodney W. Grimes *p++ = *num++; 28286641d8fSPaul Traina } 2839b50d902SRodney W. Grimes *p++ = *num++; 2849b50d902SRodney W. Grimes *p++ = *num++; 2859b50d902SRodney W. Grimes *p++ = *num++; 2869b50d902SRodney W. Grimes *p = '\0'; 2879b50d902SRodney W. Grimes return(pbuf); 2889b50d902SRodney W. Grimes } 2899b50d902SRodney W. Grimes 2909b50d902SRodney W. Grimes static void 291f4ac32deSDavid Malone find_idle_and_ttywrite(WHERE *w) 2929b50d902SRodney W. Grimes { 2939b50d902SRodney W. Grimes struct stat sb; 2943bebe991SBrian Somers time_t touched; 2957d7d4297SRobert Watson int error; 2969b50d902SRodney W. Grimes 2979b50d902SRodney W. Grimes (void)snprintf(tbuf, sizeof(tbuf), "%s/%s", _PATH_DEV, w->tty); 2987d7d4297SRobert Watson 2997d7d4297SRobert Watson error = stat(tbuf, &sb); 3007d7d4297SRobert Watson if (error < 0 && errno == ENOENT) { 3017d7d4297SRobert Watson /* 3027d7d4297SRobert Watson * The terminal listed is not actually a terminal (i.e., 3037d7d4297SRobert Watson * ":0"). This is a failure, so we'll skip printing 3047d7d4297SRobert Watson * out the idle time, which is non-ideal but better 3057d7d4297SRobert Watson * than a bogus warning and idle time. 3067d7d4297SRobert Watson */ 3077d7d4297SRobert Watson w->idletime = -1; 3087d7d4297SRobert Watson return; 3097d7d4297SRobert Watson } else if (error < 0) { 310084c79f6SKris Kennaway warn("%s", tbuf); 3117d7d4297SRobert Watson w->idletime = -1; 3129b50d902SRodney W. Grimes return; 3139b50d902SRodney W. Grimes } 3143bebe991SBrian Somers touched = sb.st_atime; 3153bebe991SBrian Somers if (touched < w->loginat) { 3163bebe991SBrian Somers /* tty untouched since before login */ 3173bebe991SBrian Somers touched = w->loginat; 3183bebe991SBrian Somers } 3193bebe991SBrian Somers w->idletime = now < touched ? 0 : now - touched; 3209b50d902SRodney W. Grimes 3219b50d902SRodney W. Grimes #define TALKABLE 0220 /* tty is writable if 220 mode */ 3229b50d902SRodney W. Grimes w->writable = ((sb.st_mode & TALKABLE) == TALKABLE); 3239b50d902SRodney W. Grimes } 3249b50d902SRodney W. Grimes 3259b50d902SRodney W. Grimes static void 326f4ac32deSDavid Malone userinfo(PERSON *pn, struct passwd *pw) 3279b50d902SRodney W. Grimes { 3284e030ba6SMark Murray char *p, *t; 3299b50d902SRodney W. Grimes char *bp, name[1024]; 33086641d8fSPaul Traina struct stat sb; 3319b50d902SRodney W. Grimes 3329b50d902SRodney W. Grimes pn->realname = pn->office = pn->officephone = pn->homephone = NULL; 3339b50d902SRodney W. Grimes 3349b50d902SRodney W. Grimes pn->uid = pw->pw_uid; 3358728c621SChris D. Faulhaber if ((pn->name = strdup(pw->pw_name)) == NULL) 3368728c621SChris D. Faulhaber err(1, "strdup failed"); 3378728c621SChris D. Faulhaber if ((pn->dir = strdup(pw->pw_dir)) == NULL) 3388728c621SChris D. Faulhaber err(1, "strdup failed"); 3398728c621SChris D. Faulhaber if ((pn->shell = strdup(pw->pw_shell)) == NULL) 3408728c621SChris D. Faulhaber err(1, "strdup failed"); 3419b50d902SRodney W. Grimes 3429b50d902SRodney W. Grimes /* why do we skip asterisks!?!? */ 343e0d8eea1SWarner Losh (void)strncpy(bp = tbuf, pw->pw_gecos, sizeof(tbuf)); 344b59bb23bSWarner Losh tbuf[sizeof(tbuf) - 1] = '\0'; 3459b50d902SRodney W. Grimes if (*bp == '*') 3469b50d902SRodney W. Grimes ++bp; 3479b50d902SRodney W. Grimes 3489b50d902SRodney W. Grimes /* ampersands get replaced by the login name */ 3499b50d902SRodney W. Grimes if (!(p = strsep(&bp, ","))) 3509b50d902SRodney W. Grimes return; 351b59bb23bSWarner Losh for (t = name; t < &name[sizeof(name) - 1] && (*t = *p) != '\0'; ++p) { 3529b50d902SRodney W. Grimes if (*t == '&') { 353e0d8eea1SWarner Losh (void)strncpy(t, pw->pw_name, 354e0d8eea1SWarner Losh sizeof(name) - (t - name)); 355e0d8eea1SWarner Losh name[sizeof(name) - 1] = '\0'; 3569b50d902SRodney W. Grimes if (islower(*t)) 3579b50d902SRodney W. Grimes *t = toupper(*t); 358b59bb23bSWarner Losh while (t < &name[sizeof(name) - 1] && *++t) 359b59bb23bSWarner Losh continue; 360e0d8eea1SWarner Losh } else { 3619b50d902SRodney W. Grimes ++t; 362e0d8eea1SWarner Losh } 363e0d8eea1SWarner Losh } 364e0d8eea1SWarner Losh *t = '\0'; 3658728c621SChris D. Faulhaber if ((pn->realname = strdup(name)) == NULL) 3668728c621SChris D. Faulhaber err(1, "strdup failed"); 3679b50d902SRodney W. Grimes pn->office = ((p = strsep(&bp, ",")) && *p) ? 3689b50d902SRodney W. Grimes strdup(p) : NULL; 3699b50d902SRodney W. Grimes pn->officephone = ((p = strsep(&bp, ",")) && *p) ? 3709b50d902SRodney W. Grimes strdup(p) : NULL; 3719b50d902SRodney W. Grimes pn->homephone = ((p = strsep(&bp, ",")) && *p) ? 3729b50d902SRodney W. Grimes strdup(p) : NULL; 373e0d8eea1SWarner Losh (void)snprintf(tbuf, sizeof(tbuf), "%s/%s", _PATH_MAILDIR, pw->pw_name); 37486641d8fSPaul Traina pn->mailrecv = -1; /* -1 == not_valid */ 37586641d8fSPaul Traina if (stat(tbuf, &sb) < 0) { 37686641d8fSPaul Traina if (errno != ENOENT) { 377b14d8277SPhilippe Charnier warn("%s", tbuf); 37886641d8fSPaul Traina return; 37986641d8fSPaul Traina } 38086641d8fSPaul Traina } else if (sb.st_size != 0) { 38186641d8fSPaul Traina pn->mailrecv = sb.st_mtime; 38286641d8fSPaul Traina pn->mailread = sb.st_atime; 38386641d8fSPaul Traina } 3849b50d902SRodney W. Grimes } 3859b50d902SRodney W. Grimes 3868829c73eSJordan K. Hubbard /* 3878829c73eSJordan K. Hubbard * Is this user hiding from finger? 3888829c73eSJordan K. Hubbard * If ~<user>/.nofinger exists, return 1 (hide), else return 0 (nohide). 389d2e4ea2aSDiomidis Spinellis * Nobody can hide from root. 3908829c73eSJordan K. Hubbard */ 3918829c73eSJordan K. Hubbard 3928829c73eSJordan K. Hubbard int 393f4ac32deSDavid Malone hide(struct passwd *pw) 3948829c73eSJordan K. Hubbard { 395d691b79fSYaroslav Tykhiy struct stat st; 396167ea27bSWarner Losh char buf[MAXPATHLEN]; 3978829c73eSJordan K. Hubbard 398d2e4ea2aSDiomidis Spinellis if (invoker_root || !pw->pw_dir) 3998829c73eSJordan K. Hubbard return 0; 4008829c73eSJordan K. Hubbard 401b95dbabaSYaroslav Tykhiy snprintf(buf, sizeof(buf), "%s/%s", pw->pw_dir, _PATH_NOFINGER); 4028829c73eSJordan K. Hubbard 403d691b79fSYaroslav Tykhiy if (stat(buf, &st) == 0) 4048829c73eSJordan K. Hubbard return 1; 4058829c73eSJordan K. Hubbard 4068829c73eSJordan K. Hubbard return 0; 4078829c73eSJordan K. Hubbard } 408