19b50d902SRodney W. Grimes /* 29b50d902SRodney W. Grimes * Copyright (c) 1989, 1993 39b50d902SRodney W. Grimes * The Regents of the University of California. All rights reserved. 49b50d902SRodney W. Grimes * 59b50d902SRodney W. Grimes * This code is derived from software contributed to Berkeley by 69b50d902SRodney W. Grimes * Tony Nardo of the Johns Hopkins University/Applied Physics Lab. 79b50d902SRodney W. Grimes * 89b50d902SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 99b50d902SRodney W. Grimes * modification, are permitted provided that the following conditions 109b50d902SRodney W. Grimes * are met: 119b50d902SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 129b50d902SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 139b50d902SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 149b50d902SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 159b50d902SRodney W. Grimes * documentation and/or other materials provided with the distribution. 169b50d902SRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 179b50d902SRodney W. Grimes * must display the following acknowledgement: 189b50d902SRodney W. Grimes * This product includes software developed by the University of 199b50d902SRodney W. Grimes * California, Berkeley and its contributors. 209b50d902SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 219b50d902SRodney W. Grimes * may be used to endorse or promote products derived from this software 229b50d902SRodney W. Grimes * without specific prior written permission. 239b50d902SRodney W. Grimes * 249b50d902SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 259b50d902SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 269b50d902SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 279b50d902SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 289b50d902SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 299b50d902SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 309b50d902SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 319b50d902SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 329b50d902SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 339b50d902SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 349b50d902SRodney W. Grimes * SUCH DAMAGE. 359b50d902SRodney W. Grimes */ 369b50d902SRodney W. Grimes 379b50d902SRodney W. Grimes #ifndef lint 38df3f5d9dSPeter Wemm static char sccsid[] = "@(#)util.c 8.3 (Berkeley) 4/28/95"; 399b50d902SRodney W. Grimes #endif /* not lint */ 409b50d902SRodney W. Grimes 419b50d902SRodney W. Grimes #include <sys/param.h> 429b50d902SRodney W. Grimes #include <sys/stat.h> 439b50d902SRodney W. Grimes #include <fcntl.h> 449b50d902SRodney W. Grimes #include <db.h> 45df3f5d9dSPeter Wemm #include <err.h> 469b50d902SRodney W. Grimes #include <pwd.h> 479b50d902SRodney W. Grimes #include <utmp.h> 489b50d902SRodney W. Grimes #include <errno.h> 499b50d902SRodney W. Grimes #include <unistd.h> 509b50d902SRodney W. Grimes #include <stdio.h> 519b50d902SRodney W. Grimes #include <ctype.h> 529b50d902SRodney W. Grimes #include <stdlib.h> 539b50d902SRodney W. Grimes #include <string.h> 549b50d902SRodney W. Grimes #include <paths.h> 5586641d8fSPaul Traina #include <errno.h> 569b50d902SRodney W. Grimes #include "finger.h" 579b50d902SRodney W. Grimes 589b50d902SRodney W. Grimes static void find_idle_and_ttywrite __P((WHERE *)); 599b50d902SRodney W. Grimes static void userinfo __P((PERSON *, struct passwd *)); 609b50d902SRodney W. Grimes static WHERE *walloc __P((PERSON *)); 619b50d902SRodney W. Grimes 629b50d902SRodney W. Grimes int 639b50d902SRodney W. Grimes match(pw, user) 649b50d902SRodney W. Grimes struct passwd *pw; 659b50d902SRodney W. Grimes char *user; 669b50d902SRodney W. Grimes { 679b50d902SRodney W. Grimes register char *p, *t; 689b50d902SRodney W. Grimes char name[1024]; 699b50d902SRodney W. Grimes 709b50d902SRodney W. Grimes if (!strcasecmp(pw->pw_name, user)) 719b50d902SRodney W. Grimes return(1); 729b50d902SRodney W. Grimes 739b50d902SRodney W. Grimes /* 749b50d902SRodney W. Grimes * XXX 759b50d902SRodney W. Grimes * Why do we skip asterisks!?!? 769b50d902SRodney W. Grimes */ 779b50d902SRodney W. Grimes (void)strcpy(p = tbuf, pw->pw_gecos); 789b50d902SRodney W. Grimes if (*p == '*') 799b50d902SRodney W. Grimes ++p; 809b50d902SRodney W. Grimes 819b50d902SRodney W. Grimes /* Ampersands get replaced by the login name. */ 829b50d902SRodney W. Grimes if ((p = strtok(p, ",")) == NULL) 839b50d902SRodney W. Grimes return(0); 849b50d902SRodney W. Grimes 85df3f5d9dSPeter Wemm for (t = name; (*t = *p) != '\0'; ++p) 869b50d902SRodney W. Grimes if (*t == '&') { 879b50d902SRodney W. Grimes (void)strcpy(t, pw->pw_name); 889b50d902SRodney W. Grimes while (*++t); 899b50d902SRodney W. Grimes } 909b50d902SRodney W. Grimes else 919b50d902SRodney W. Grimes ++t; 92df3f5d9dSPeter Wemm for (t = name; (p = strtok(t, "\t ")) != NULL; t = NULL) 939b50d902SRodney W. Grimes if (!strcasecmp(p, user)) 949b50d902SRodney W. Grimes return(1); 959b50d902SRodney W. Grimes return(0); 969b50d902SRodney W. Grimes } 979b50d902SRodney W. Grimes 989b50d902SRodney W. Grimes void 999b50d902SRodney W. Grimes enter_lastlog(pn) 1009b50d902SRodney W. Grimes register PERSON *pn; 1019b50d902SRodney W. Grimes { 1029b50d902SRodney W. Grimes register WHERE *w; 1039b50d902SRodney W. Grimes static int opened, fd; 1049b50d902SRodney W. Grimes struct lastlog ll; 1059b50d902SRodney W. Grimes char doit = 0; 1069b50d902SRodney W. Grimes 1079b50d902SRodney W. Grimes /* some systems may not maintain lastlog, don't report errors. */ 1089b50d902SRodney W. Grimes if (!opened) { 1099b50d902SRodney W. Grimes fd = open(_PATH_LASTLOG, O_RDONLY, 0); 1109b50d902SRodney W. Grimes opened = 1; 1119b50d902SRodney W. Grimes } 1129b50d902SRodney W. Grimes if (fd == -1 || 1139b50d902SRodney W. Grimes lseek(fd, (long)pn->uid * sizeof(ll), SEEK_SET) != 1149b50d902SRodney W. Grimes (long)pn->uid * sizeof(ll) || 1159b50d902SRodney W. Grimes read(fd, (char *)&ll, sizeof(ll)) != sizeof(ll)) { 1169b50d902SRodney W. Grimes /* as if never logged in */ 1179b50d902SRodney W. Grimes ll.ll_line[0] = ll.ll_host[0] = NULL; 1189b50d902SRodney W. Grimes ll.ll_time = 0; 1199b50d902SRodney W. Grimes } 1209b50d902SRodney W. Grimes if ((w = pn->whead) == NULL) 1219b50d902SRodney W. Grimes doit = 1; 1229b50d902SRodney W. Grimes else if (ll.ll_time != 0) { 1239b50d902SRodney W. Grimes /* if last login is earlier than some current login */ 1249b50d902SRodney W. Grimes for (; !doit && w != NULL; w = w->next) 1259b50d902SRodney W. Grimes if (w->info == LOGGEDIN && w->loginat < ll.ll_time) 1269b50d902SRodney W. Grimes doit = 1; 1279b50d902SRodney W. Grimes /* 1289b50d902SRodney W. Grimes * and if it's not any of the current logins 1299b50d902SRodney W. Grimes * can't use time comparison because there may be a small 1309b50d902SRodney W. Grimes * discrepency since login calls time() twice 1319b50d902SRodney W. Grimes */ 1329b50d902SRodney W. Grimes for (w = pn->whead; doit && w != NULL; w = w->next) 1339b50d902SRodney W. Grimes if (w->info == LOGGEDIN && 1349b50d902SRodney W. Grimes strncmp(w->tty, ll.ll_line, UT_LINESIZE) == 0) 1359b50d902SRodney W. Grimes doit = 0; 1369b50d902SRodney W. Grimes } 1379b50d902SRodney W. Grimes if (doit) { 1389b50d902SRodney W. Grimes w = walloc(pn); 1399b50d902SRodney W. Grimes w->info = LASTLOG; 1409b50d902SRodney W. Grimes bcopy(ll.ll_line, w->tty, UT_LINESIZE); 1419b50d902SRodney W. Grimes w->tty[UT_LINESIZE] = 0; 1429b50d902SRodney W. Grimes bcopy(ll.ll_host, w->host, UT_HOSTSIZE); 1439b50d902SRodney W. Grimes w->host[UT_HOSTSIZE] = 0; 1449b50d902SRodney W. Grimes w->loginat = ll.ll_time; 1459b50d902SRodney W. Grimes } 1469b50d902SRodney W. Grimes } 1479b50d902SRodney W. Grimes 1489b50d902SRodney W. Grimes void 1499b50d902SRodney W. Grimes enter_where(ut, pn) 1509b50d902SRodney W. Grimes struct utmp *ut; 1519b50d902SRodney W. Grimes PERSON *pn; 1529b50d902SRodney W. Grimes { 1539b50d902SRodney W. Grimes register WHERE *w; 1549b50d902SRodney W. Grimes 1559b50d902SRodney W. Grimes w = walloc(pn); 1569b50d902SRodney W. Grimes w->info = LOGGEDIN; 1579b50d902SRodney W. Grimes bcopy(ut->ut_line, w->tty, UT_LINESIZE); 1589b50d902SRodney W. Grimes w->tty[UT_LINESIZE] = 0; 1599b50d902SRodney W. Grimes bcopy(ut->ut_host, w->host, UT_HOSTSIZE); 1609b50d902SRodney W. Grimes w->host[UT_HOSTSIZE] = 0; 1619b50d902SRodney W. Grimes w->loginat = (time_t)ut->ut_time; 1629b50d902SRodney W. Grimes find_idle_and_ttywrite(w); 1639b50d902SRodney W. Grimes } 1649b50d902SRodney W. Grimes 1659b50d902SRodney W. Grimes PERSON * 1669b50d902SRodney W. Grimes enter_person(pw) 1679b50d902SRodney W. Grimes register struct passwd *pw; 1689b50d902SRodney W. Grimes { 1699b50d902SRodney W. Grimes DBT data, key; 1709b50d902SRodney W. Grimes PERSON *pn; 1719b50d902SRodney W. Grimes 1729b50d902SRodney W. Grimes if (db == NULL && 1739b50d902SRodney W. Grimes (db = dbopen(NULL, O_RDWR, 0, DB_BTREE, NULL)) == NULL) 174df3f5d9dSPeter Wemm err(1, NULL); 1759b50d902SRodney W. Grimes 1769b50d902SRodney W. Grimes key.data = pw->pw_name; 1779b50d902SRodney W. Grimes key.size = strlen(pw->pw_name); 1789b50d902SRodney W. Grimes 1799b50d902SRodney W. Grimes switch ((*db->get)(db, &key, &data, 0)) { 1809b50d902SRodney W. Grimes case 0: 181df3f5d9dSPeter Wemm memmove(&pn, data.data, sizeof pn); 182df3f5d9dSPeter Wemm return (pn); 1839b50d902SRodney W. Grimes default: 1849b50d902SRodney W. Grimes case -1: 185df3f5d9dSPeter Wemm err(1, "db get"); 1869b50d902SRodney W. Grimes /* NOTREACHED */ 1879b50d902SRodney W. Grimes case 1: 1889b50d902SRodney W. Grimes ++entries; 1899b50d902SRodney W. Grimes pn = palloc(); 1909b50d902SRodney W. Grimes userinfo(pn, pw); 1919b50d902SRodney W. Grimes pn->whead = NULL; 1929b50d902SRodney W. Grimes 1939b50d902SRodney W. Grimes data.size = sizeof(PERSON *); 1949b50d902SRodney W. Grimes data.data = &pn; 1959b50d902SRodney W. Grimes if ((*db->put)(db, &key, &data, 0)) 196df3f5d9dSPeter Wemm err(1, "db put"); 1979b50d902SRodney W. Grimes return (pn); 1989b50d902SRodney W. Grimes } 1999b50d902SRodney W. Grimes } 2009b50d902SRodney W. Grimes 2019b50d902SRodney W. Grimes PERSON * 2029b50d902SRodney W. Grimes find_person(name) 2039b50d902SRodney W. Grimes char *name; 2049b50d902SRodney W. Grimes { 2058829c73eSJordan K. Hubbard struct passwd *pw; 2068829c73eSJordan K. Hubbard 2079b50d902SRodney W. Grimes register int cnt; 2089b50d902SRodney W. Grimes DBT data, key; 209df3f5d9dSPeter Wemm PERSON *p; 2109b50d902SRodney W. Grimes char buf[UT_NAMESIZE + 1]; 2119b50d902SRodney W. Grimes 2129b50d902SRodney W. Grimes if (!db) 2139b50d902SRodney W. Grimes return(NULL); 2149b50d902SRodney W. Grimes 2158829c73eSJordan K. Hubbard if ((pw = getpwnam(name)) && hide(pw)) 2168829c73eSJordan K. Hubbard return(NULL); 2178829c73eSJordan K. Hubbard 2189b50d902SRodney W. Grimes /* Name may be only UT_NAMESIZE long and not NUL terminated. */ 2199b50d902SRodney W. Grimes for (cnt = 0; cnt < UT_NAMESIZE && *name; ++name, ++cnt) 2209b50d902SRodney W. Grimes buf[cnt] = *name; 2219b50d902SRodney W. Grimes buf[cnt] = '\0'; 2229b50d902SRodney W. Grimes key.data = buf; 2239b50d902SRodney W. Grimes key.size = cnt; 2249b50d902SRodney W. Grimes 225df3f5d9dSPeter Wemm if ((*db->get)(db, &key, &data, 0)) 226df3f5d9dSPeter Wemm return (NULL); 227df3f5d9dSPeter Wemm memmove(&p, data.data, sizeof p); 228df3f5d9dSPeter Wemm return (p); 2299b50d902SRodney W. Grimes } 2309b50d902SRodney W. Grimes 2319b50d902SRodney W. Grimes PERSON * 2329b50d902SRodney W. Grimes palloc() 2339b50d902SRodney W. Grimes { 2349b50d902SRodney W. Grimes PERSON *p; 2359b50d902SRodney W. Grimes 2369b50d902SRodney W. Grimes if ((p = malloc((u_int) sizeof(PERSON))) == NULL) 237df3f5d9dSPeter Wemm err(1, NULL); 2389b50d902SRodney W. Grimes return(p); 2399b50d902SRodney W. Grimes } 2409b50d902SRodney W. Grimes 2419b50d902SRodney W. Grimes static WHERE * 2429b50d902SRodney W. Grimes walloc(pn) 2439b50d902SRodney W. Grimes register PERSON *pn; 2449b50d902SRodney W. Grimes { 2459b50d902SRodney W. Grimes register WHERE *w; 2469b50d902SRodney W. Grimes 2479b50d902SRodney W. Grimes if ((w = malloc((u_int) sizeof(WHERE))) == NULL) 248df3f5d9dSPeter Wemm err(1, NULL); 2499b50d902SRodney W. Grimes if (pn->whead == NULL) 2509b50d902SRodney W. Grimes pn->whead = pn->wtail = w; 2519b50d902SRodney W. Grimes else { 2529b50d902SRodney W. Grimes pn->wtail->next = w; 2539b50d902SRodney W. Grimes pn->wtail = w; 2549b50d902SRodney W. Grimes } 2559b50d902SRodney W. Grimes w->next = NULL; 2569b50d902SRodney W. Grimes return(w); 2579b50d902SRodney W. Grimes } 2589b50d902SRodney W. Grimes 2599b50d902SRodney W. Grimes char * 2609b50d902SRodney W. Grimes prphone(num) 2619b50d902SRodney W. Grimes char *num; 2629b50d902SRodney W. Grimes { 2639b50d902SRodney W. Grimes register char *p; 2649b50d902SRodney W. Grimes int len; 2659b50d902SRodney W. Grimes static char pbuf[15]; 2669b50d902SRodney W. Grimes 2679b50d902SRodney W. Grimes /* don't touch anything if the user has their own formatting */ 2689b50d902SRodney W. Grimes for (p = num; *p; ++p) 2699b50d902SRodney W. Grimes if (!isdigit(*p)) 2709b50d902SRodney W. Grimes return(num); 2719b50d902SRodney W. Grimes len = p - num; 2729b50d902SRodney W. Grimes p = pbuf; 2739b50d902SRodney W. Grimes switch(len) { 2749b50d902SRodney W. Grimes case 11: /* +0-123-456-7890 */ 2759b50d902SRodney W. Grimes *p++ = '+'; 2769b50d902SRodney W. Grimes *p++ = *num++; 2779b50d902SRodney W. Grimes *p++ = '-'; 2789b50d902SRodney W. Grimes /* FALLTHROUGH */ 2799b50d902SRodney W. Grimes case 10: /* 012-345-6789 */ 2809b50d902SRodney W. Grimes *p++ = *num++; 2819b50d902SRodney W. Grimes *p++ = *num++; 2829b50d902SRodney W. Grimes *p++ = *num++; 2839b50d902SRodney W. Grimes *p++ = '-'; 2849b50d902SRodney W. Grimes /* FALLTHROUGH */ 2859b50d902SRodney W. Grimes case 7: /* 012-3456 */ 2869b50d902SRodney W. Grimes *p++ = *num++; 2879b50d902SRodney W. Grimes *p++ = *num++; 2889b50d902SRodney W. Grimes *p++ = *num++; 2899b50d902SRodney W. Grimes break; 2909b50d902SRodney W. Grimes case 5: /* x0-1234 */ 29186641d8fSPaul Traina case 4: /* x1234 */ 2929b50d902SRodney W. Grimes *p++ = 'x'; 2939b50d902SRodney W. Grimes *p++ = *num++; 2949b50d902SRodney W. Grimes break; 2959b50d902SRodney W. Grimes default: 2969b50d902SRodney W. Grimes return(num); 2979b50d902SRodney W. Grimes } 29886641d8fSPaul Traina if (len != 4) { 2999b50d902SRodney W. Grimes *p++ = '-'; 3009b50d902SRodney W. Grimes *p++ = *num++; 30186641d8fSPaul Traina } 3029b50d902SRodney W. Grimes *p++ = *num++; 3039b50d902SRodney W. Grimes *p++ = *num++; 3049b50d902SRodney W. Grimes *p++ = *num++; 3059b50d902SRodney W. Grimes *p = '\0'; 3069b50d902SRodney W. Grimes return(pbuf); 3079b50d902SRodney W. Grimes } 3089b50d902SRodney W. Grimes 3099b50d902SRodney W. Grimes static void 3109b50d902SRodney W. Grimes find_idle_and_ttywrite(w) 3119b50d902SRodney W. Grimes register WHERE *w; 3129b50d902SRodney W. Grimes { 3139b50d902SRodney W. Grimes extern time_t now; 3149b50d902SRodney W. Grimes struct stat sb; 3159b50d902SRodney W. Grimes 3169b50d902SRodney W. Grimes (void)snprintf(tbuf, sizeof(tbuf), "%s/%s", _PATH_DEV, w->tty); 3179b50d902SRodney W. Grimes if (stat(tbuf, &sb) < 0) { 318df3f5d9dSPeter Wemm warn(tbuf); 3199b50d902SRodney W. Grimes return; 3209b50d902SRodney W. Grimes } 3219b50d902SRodney W. Grimes w->idletime = now < sb.st_atime ? 0 : now - sb.st_atime; 3229b50d902SRodney W. Grimes 3239b50d902SRodney W. Grimes #define TALKABLE 0220 /* tty is writable if 220 mode */ 3249b50d902SRodney W. Grimes w->writable = ((sb.st_mode & TALKABLE) == TALKABLE); 3259b50d902SRodney W. Grimes } 3269b50d902SRodney W. Grimes 3279b50d902SRodney W. Grimes static void 3289b50d902SRodney W. Grimes userinfo(pn, pw) 3299b50d902SRodney W. Grimes register PERSON *pn; 3309b50d902SRodney W. Grimes register struct passwd *pw; 3319b50d902SRodney W. Grimes { 3329b50d902SRodney W. Grimes register char *p, *t; 3339b50d902SRodney W. Grimes char *bp, name[1024]; 33486641d8fSPaul Traina struct stat sb; 3359b50d902SRodney W. Grimes 3369b50d902SRodney W. Grimes pn->realname = pn->office = pn->officephone = pn->homephone = NULL; 3379b50d902SRodney W. Grimes 3389b50d902SRodney W. Grimes pn->uid = pw->pw_uid; 3399b50d902SRodney W. Grimes pn->name = strdup(pw->pw_name); 3409b50d902SRodney W. Grimes pn->dir = strdup(pw->pw_dir); 3419b50d902SRodney W. Grimes pn->shell = strdup(pw->pw_shell); 3429b50d902SRodney W. Grimes 3439b50d902SRodney W. Grimes /* why do we skip asterisks!?!? */ 3449b50d902SRodney W. Grimes (void)strcpy(bp = tbuf, pw->pw_gecos); 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; 351df3f5d9dSPeter Wemm for (t = name; (*t = *p) != '\0'; ++p) 3529b50d902SRodney W. Grimes if (*t == '&') { 3539b50d902SRodney W. Grimes (void)strcpy(t, pw->pw_name); 3549b50d902SRodney W. Grimes if (islower(*t)) 3559b50d902SRodney W. Grimes *t = toupper(*t); 3569b50d902SRodney W. Grimes while (*++t); 3579b50d902SRodney W. Grimes } 3589b50d902SRodney W. Grimes else 3599b50d902SRodney W. Grimes ++t; 3609b50d902SRodney W. Grimes pn->realname = strdup(name); 3619b50d902SRodney W. Grimes pn->office = ((p = strsep(&bp, ",")) && *p) ? 3629b50d902SRodney W. Grimes strdup(p) : NULL; 3639b50d902SRodney W. Grimes pn->officephone = ((p = strsep(&bp, ",")) && *p) ? 3649b50d902SRodney W. Grimes strdup(p) : NULL; 3659b50d902SRodney W. Grimes pn->homephone = ((p = strsep(&bp, ",")) && *p) ? 3669b50d902SRodney W. Grimes strdup(p) : NULL; 36786641d8fSPaul Traina (void)sprintf(tbuf,"%s/%s", _PATH_MAILDIR, pw->pw_name); 36886641d8fSPaul Traina pn->mailrecv = -1; /* -1 == not_valid */ 36986641d8fSPaul Traina if (stat(tbuf, &sb) < 0) { 37086641d8fSPaul Traina if (errno != ENOENT) { 37186641d8fSPaul Traina (void)fprintf(stderr, 37286641d8fSPaul Traina "finger: %s: %s\n", tbuf, strerror(errno)); 37386641d8fSPaul Traina return; 37486641d8fSPaul Traina } 37586641d8fSPaul Traina } else if (sb.st_size != 0) { 37686641d8fSPaul Traina pn->mailrecv = sb.st_mtime; 37786641d8fSPaul Traina pn->mailread = sb.st_atime; 37886641d8fSPaul Traina } 3799b50d902SRodney W. Grimes } 3809b50d902SRodney W. Grimes 3818829c73eSJordan K. Hubbard /* 3828829c73eSJordan K. Hubbard * Is this user hiding from finger? 3838829c73eSJordan K. Hubbard * If ~<user>/.nofinger exists, return 1 (hide), else return 0 (nohide). 3848829c73eSJordan K. Hubbard */ 3858829c73eSJordan K. Hubbard 3868829c73eSJordan K. Hubbard int 3878829c73eSJordan K. Hubbard hide(pw) 3888829c73eSJordan K. Hubbard struct passwd *pw; 3898829c73eSJordan K. Hubbard { 3908829c73eSJordan K. Hubbard int fd; 3918829c73eSJordan K. Hubbard char buf[MAXPATHLEN+1]; 3928829c73eSJordan K. Hubbard 3938829c73eSJordan K. Hubbard if (!pw->pw_dir) 3948829c73eSJordan K. Hubbard return 0; 3958829c73eSJordan K. Hubbard 3968829c73eSJordan K. Hubbard sprintf (buf, "%s/.nofinger", pw->pw_dir); 3978829c73eSJordan K. Hubbard 3988829c73eSJordan K. Hubbard if (access (buf, F_OK) == 0) 3998829c73eSJordan K. Hubbard return 1; 4008829c73eSJordan K. Hubbard 4018829c73eSJordan K. Hubbard return 0; 4028829c73eSJordan K. Hubbard } 403