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 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by the University of 19 * California, Berkeley and its contributors. 20 * 4. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 */ 36 37/* 38 * Luke Mewburn <lm@rmit.edu.au> added the following on 940622: 39 * - mail status ("No Mail", "Mail read:...", or "New Mail ..., 40 * Unread since ...".) 41 * - 4 digit phone extensions (3210 is printed as x3210.) 42 * - host/office toggling in short format with -h & -o. 43 * - short day names (`Tue' printed instead of `Jun 21' if the 44 * login time is < 6 days. 45 */ 46 47#ifndef lint 48static const char copyright[] = 49"@(#) Copyright (c) 1989, 1993\n\ 50 The Regents of the University of California. All rights reserved.\n"; 51#endif /* not lint */ 52 53#ifndef lint 54#if 0 55static char sccsid[] = "@(#)finger.c 8.5 (Berkeley) 5/4/95"; 56#endif 57static const char rcsid[] =
| 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 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by the University of 19 * California, Berkeley and its contributors. 20 * 4. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 */ 36 37/* 38 * Luke Mewburn <lm@rmit.edu.au> added the following on 940622: 39 * - mail status ("No Mail", "Mail read:...", or "New Mail ..., 40 * Unread since ...".) 41 * - 4 digit phone extensions (3210 is printed as x3210.) 42 * - host/office toggling in short format with -h & -o. 43 * - short day names (`Tue' printed instead of `Jun 21' if the 44 * login time is < 6 days. 45 */ 46 47#ifndef lint 48static const char copyright[] = 49"@(#) Copyright (c) 1989, 1993\n\ 50 The Regents of the University of California. All rights reserved.\n"; 51#endif /* not lint */ 52 53#ifndef lint 54#if 0 55static char sccsid[] = "@(#)finger.c 8.5 (Berkeley) 5/4/95"; 56#endif 57static const char rcsid[] =
|
59#endif /* not lint */ 60 61/* 62 * Finger prints out information about users. It is not portable since 63 * certain fields (e.g. the full user name, office, and phone numbers) are 64 * extracted from the gecos field of the passwd file which other UNIXes 65 * may not have or may use for other things. 66 * 67 * There are currently two output formats; the short format is one line 68 * per user and displays login name, tty, login time, real name, idle time, 69 * and either remote host information (default) or office location/phone 70 * number, depending on if -h or -o is used respectively. 71 * The long format gives the same information (in a more legible format) as 72 * well as home directory, shell, mail info, and .plan/.project files. 73 */ 74 75#include <db.h> 76#include <err.h> 77#include <pwd.h> 78#include <stdio.h> 79#include <stdlib.h> 80#include <string.h> 81#include <time.h> 82#include <unistd.h> 83#include <utmp.h> 84#include <locale.h> 85 86#include "finger.h" 87#include "pathnames.h" 88 89DB *db; 90time_t now; 91int entries, lflag, mflag, pplan, sflag, oflag, Tflag;
| 59#endif /* not lint */ 60 61/* 62 * Finger prints out information about users. It is not portable since 63 * certain fields (e.g. the full user name, office, and phone numbers) are 64 * extracted from the gecos field of the passwd file which other UNIXes 65 * may not have or may use for other things. 66 * 67 * There are currently two output formats; the short format is one line 68 * per user and displays login name, tty, login time, real name, idle time, 69 * and either remote host information (default) or office location/phone 70 * number, depending on if -h or -o is used respectively. 71 * The long format gives the same information (in a more legible format) as 72 * well as home directory, shell, mail info, and .plan/.project files. 73 */ 74 75#include <db.h> 76#include <err.h> 77#include <pwd.h> 78#include <stdio.h> 79#include <stdlib.h> 80#include <string.h> 81#include <time.h> 82#include <unistd.h> 83#include <utmp.h> 84#include <locale.h> 85 86#include "finger.h" 87#include "pathnames.h" 88 89DB *db; 90time_t now; 91int entries, lflag, mflag, pplan, sflag, oflag, Tflag;
|
92char tbuf[1024]; 93 94static void loginlist __P((void)); 95static void usage __P((void)); 96static void userlist __P((int, char **)); 97 98int 99option(argc, argv) 100 int argc; 101 char **argv; 102{ 103 int ch; 104 105 optind = 1; /* reset getopt */ 106 107 while ((ch = getopt(argc, argv, "lmpshoT")) != -1) 108 switch(ch) { 109 case 'l': 110 lflag = 1; /* long format */ 111 break; 112 case 'm': 113 mflag = 1; /* force exact match of names */ 114 break; 115 case 'p': 116 pplan = 1; /* don't show .plan/.project */ 117 break; 118 case 's': 119 sflag = 1; /* short format */ 120 break; 121 case 'h': 122 oflag = 0; /* remote host info */ 123 break; 124 case 'o': 125 oflag = 1; /* office info */ 126 break; 127 case 'T': 128 Tflag = 1; /* disable T/TCP */ 129 break; 130 case '?': 131 default: 132 usage(); 133 } 134 135 return optind; 136} 137 138static void 139usage() 140{ 141 (void)fprintf(stderr, "usage: finger [-lmpshoT] [login ...]\n"); 142 exit(1); 143} 144 145int 146main(argc, argv) 147 int argc; 148 char **argv; 149{ 150 int envargc, argcnt; 151 char *envargv[3]; 152 struct passwd *pw; 153 154 if (getuid() == 0 || geteuid() == 0) { 155 if ((pw = getpwnam(UNPRIV_NAME)) && pw->pw_uid > 0) { 156 setgid(pw->pw_gid); 157 setuid(pw->pw_uid); 158 } else { 159 setgid(UNPRIV_UGID); 160 setuid(UNPRIV_UGID); 161 } 162 } 163 164 (void) setlocale(LC_ALL, ""); 165 166 /* remove this line to get remote host */ 167 oflag = 1; /* default to old "office" behavior */ 168 169 /* 170 * Process environment variables followed by command line arguments. 171 */ 172 if ((envargv[1] = getenv("FINGER"))) { 173 envargc = 2; 174 envargv[0] = "finger"; 175 envargv[2] = NULL; 176 (void) option(envargc, envargv); 177 } 178 179 argcnt = option(argc, argv); 180 argc -= argcnt; 181 argv += argcnt; 182 183 (void)time(&now); 184 setpassent(1); 185 if (!*argv) { 186 /* 187 * Assign explicit "small" format if no names given and -l 188 * not selected. Force the -s BEFORE we get names so proper 189 * screening will be done. 190 */ 191 if (!lflag) 192 sflag = 1; /* if -l not explicit, force -s */ 193 loginlist(); 194 if (entries == 0) 195 (void)printf("No one logged on.\n"); 196 } else { 197 userlist(argc, argv); 198 /* 199 * Assign explicit "large" format if names given and -s not 200 * explicitly stated. Force the -l AFTER we get names so any 201 * remote finger attempts specified won't be mishandled. 202 */ 203 if (!sflag) 204 lflag = 1; /* if -s not explicit, force -l */ 205 } 206 if (entries) { 207 if (lflag) 208 lflag_print(); 209 else 210 sflag_print(); 211 } 212 return (0); 213} 214 215static void 216loginlist() 217{ 218 register PERSON *pn; 219 DBT data, key; 220 struct passwd *pw; 221 struct utmp user; 222 int r, sflag; 223 char name[UT_NAMESIZE + 1]; 224 225 if (!freopen(_PATH_UTMP, "r", stdin)) 226 err(1, "%s", _PATH_UTMP); 227 name[UT_NAMESIZE] = '\0'; 228 while (fread((char *)&user, sizeof(user), 1, stdin) == 1) { 229 if (!user.ut_name[0]) 230 continue; 231 if ((pn = find_person(user.ut_name)) == NULL) { 232 bcopy(user.ut_name, name, UT_NAMESIZE); 233 if ((pw = getpwnam(name)) == NULL) 234 continue; 235 if (hide(pw)) 236 continue; 237 pn = enter_person(pw); 238 } 239 enter_where(&user, pn); 240 } 241 if (db && lflag) 242 for (sflag = R_FIRST;; sflag = R_NEXT) { 243 PERSON *tmp; 244 245 r = (*db->seq)(db, &key, &data, sflag); 246 if (r == -1) 247 err(1, "db seq"); 248 if (r == 1) 249 break; 250 memmove(&tmp, data.data, sizeof tmp); 251 enter_lastlog(tmp); 252 } 253} 254 255static void 256userlist(argc, argv) 257 register int argc; 258 register char **argv; 259{ 260 register PERSON *pn; 261 DBT data, key; 262 struct utmp user; 263 struct passwd *pw; 264 int r, sflag, *used, *ip; 265 char **ap, **nargv, **np, **p; 266 FILE *conf_fp; 267 char conf_alias[LINE_MAX]; 268 char *conf_realname; 269 int conf_length; 270 271 if ((nargv = malloc((argc+1) * sizeof(char *))) == NULL || 272 (used = calloc(argc, sizeof(int))) == NULL) 273 err(1, NULL); 274 275 /* Pull out all network requests. */ 276 for (ap = p = argv, np = nargv; *p; ++p) 277 if (index(*p, '@')) 278 *np++ = *p; 279 else 280 *ap++ = *p; 281 282 *np++ = NULL; 283 *ap++ = NULL; 284 285 if (!*argv) 286 goto net; 287 288 /* 289 * Mark any arguments beginning with '/' as invalid so that we 290 * don't accidently confuse them with expansions from finger.conf 291 */ 292 for (p = argv, ip = used; *p; ++p, ++ip) 293 if (**p == '/') { 294 *ip = 1; 295 warnx("%s: no such user", *p); 296 } 297 298 /* 299 * Traverse the finger alias configuration file of the form 300 * alias:(user|alias), ignoring comment lines beginning '#'. 301 */ 302 if ((conf_fp = fopen(_PATH_FINGERCONF, "r")) != NULL) { 303 while(fgets(conf_alias, sizeof(conf_alias), conf_fp) != NULL) { 304 conf_length = strlen(conf_alias); 305 if (*conf_alias == '#' || conf_alias[--conf_length] != '\n') 306 continue; 307 conf_alias[conf_length] = '\0'; /* Remove trailing LF */ 308 if ((conf_realname = strchr(conf_alias, ':')) == NULL) 309 continue; 310 *conf_realname = '\0'; /* Replace : with NUL */ 311 for (p = argv; *p; ++p) { 312 if (strcmp(*p, conf_alias) == NULL) { 313 if ((*p = strdup(conf_realname+1)) == NULL) { 314 err(1, NULL); 315 } 316 } 317 } 318 } 319 (void)fclose(conf_fp); 320 } 321 322 /* 323 * Traverse the list of possible login names and check the login name 324 * and real name against the name specified by the user. If the name 325 * begins with a '/', try to read the file of that name instead of 326 * gathering the traditional finger information. 327 */ 328 if (mflag) 329 for (p = argv, ip = used; *p; ++p, ++ip) { 330 if (**p != '/' || *ip == 1 || !show_text("", *p, "")) { 331 if (((pw = getpwnam(*p)) != NULL) && !hide(pw)) 332 enter_person(pw); 333 else if (!*ip) 334 warnx("%s: no such user", *p); 335 } 336 } 337 else { 338 while ((pw = getpwent()) != NULL) { 339 for (p = argv, ip = used; *p; ++p, ++ip) 340 if (**p == '/' && *ip != 1 341 && show_text("", *p, "")) 342 *ip = 1; 343 else if (match(pw, *p) && !hide(pw)) { 344 enter_person(pw); 345 *ip = 1; 346 } 347 } 348 for (p = argv, ip = used; *p; ++p, ++ip) 349 if (!*ip) 350 warnx("%s: no such user", *p); 351 } 352 353 /* Handle network requests. */ 354net: for (p = nargv; *p;) { 355 netfinger(*p++); 356 if (*p || entries) 357 printf("\n"); 358 } 359 360 if (entries == 0) 361 return; 362 363 /* 364 * Scan thru the list of users currently logged in, saving 365 * appropriate data whenever a match occurs. 366 */ 367 if (!freopen(_PATH_UTMP, "r", stdin)) 368 err(1, "%s", _PATH_UTMP); 369 while (fread((char *)&user, sizeof(user), 1, stdin) == 1) { 370 if (!user.ut_name[0]) 371 continue; 372 if ((pn = find_person(user.ut_name)) == NULL) 373 continue; 374 enter_where(&user, pn); 375 } 376 if (db) 377 for (sflag = R_FIRST;; sflag = R_NEXT) { 378 PERSON *tmp; 379 380 r = (*db->seq)(db, &key, &data, sflag); 381 if (r == -1) 382 err(1, "db seq"); 383 if (r == 1) 384 break; 385 memmove(&tmp, data.data, sizeof tmp); 386 enter_lastlog(tmp); 387 } 388}
| 93char tbuf[1024]; 94 95static void loginlist __P((void)); 96static void usage __P((void)); 97static void userlist __P((int, char **)); 98 99int 100option(argc, argv) 101 int argc; 102 char **argv; 103{ 104 int ch; 105 106 optind = 1; /* reset getopt */ 107 108 while ((ch = getopt(argc, argv, "lmpshoT")) != -1) 109 switch(ch) { 110 case 'l': 111 lflag = 1; /* long format */ 112 break; 113 case 'm': 114 mflag = 1; /* force exact match of names */ 115 break; 116 case 'p': 117 pplan = 1; /* don't show .plan/.project */ 118 break; 119 case 's': 120 sflag = 1; /* short format */ 121 break; 122 case 'h': 123 oflag = 0; /* remote host info */ 124 break; 125 case 'o': 126 oflag = 1; /* office info */ 127 break; 128 case 'T': 129 Tflag = 1; /* disable T/TCP */ 130 break; 131 case '?': 132 default: 133 usage(); 134 } 135 136 return optind; 137} 138 139static void 140usage() 141{ 142 (void)fprintf(stderr, "usage: finger [-lmpshoT] [login ...]\n"); 143 exit(1); 144} 145 146int 147main(argc, argv) 148 int argc; 149 char **argv; 150{ 151 int envargc, argcnt; 152 char *envargv[3]; 153 struct passwd *pw; 154 155 if (getuid() == 0 || geteuid() == 0) { 156 if ((pw = getpwnam(UNPRIV_NAME)) && pw->pw_uid > 0) { 157 setgid(pw->pw_gid); 158 setuid(pw->pw_uid); 159 } else { 160 setgid(UNPRIV_UGID); 161 setuid(UNPRIV_UGID); 162 } 163 } 164 165 (void) setlocale(LC_ALL, ""); 166 167 /* remove this line to get remote host */ 168 oflag = 1; /* default to old "office" behavior */ 169 170 /* 171 * Process environment variables followed by command line arguments. 172 */ 173 if ((envargv[1] = getenv("FINGER"))) { 174 envargc = 2; 175 envargv[0] = "finger"; 176 envargv[2] = NULL; 177 (void) option(envargc, envargv); 178 } 179 180 argcnt = option(argc, argv); 181 argc -= argcnt; 182 argv += argcnt; 183 184 (void)time(&now); 185 setpassent(1); 186 if (!*argv) { 187 /* 188 * Assign explicit "small" format if no names given and -l 189 * not selected. Force the -s BEFORE we get names so proper 190 * screening will be done. 191 */ 192 if (!lflag) 193 sflag = 1; /* if -l not explicit, force -s */ 194 loginlist(); 195 if (entries == 0) 196 (void)printf("No one logged on.\n"); 197 } else { 198 userlist(argc, argv); 199 /* 200 * Assign explicit "large" format if names given and -s not 201 * explicitly stated. Force the -l AFTER we get names so any 202 * remote finger attempts specified won't be mishandled. 203 */ 204 if (!sflag) 205 lflag = 1; /* if -s not explicit, force -l */ 206 } 207 if (entries) { 208 if (lflag) 209 lflag_print(); 210 else 211 sflag_print(); 212 } 213 return (0); 214} 215 216static void 217loginlist() 218{ 219 register PERSON *pn; 220 DBT data, key; 221 struct passwd *pw; 222 struct utmp user; 223 int r, sflag; 224 char name[UT_NAMESIZE + 1]; 225 226 if (!freopen(_PATH_UTMP, "r", stdin)) 227 err(1, "%s", _PATH_UTMP); 228 name[UT_NAMESIZE] = '\0'; 229 while (fread((char *)&user, sizeof(user), 1, stdin) == 1) { 230 if (!user.ut_name[0]) 231 continue; 232 if ((pn = find_person(user.ut_name)) == NULL) { 233 bcopy(user.ut_name, name, UT_NAMESIZE); 234 if ((pw = getpwnam(name)) == NULL) 235 continue; 236 if (hide(pw)) 237 continue; 238 pn = enter_person(pw); 239 } 240 enter_where(&user, pn); 241 } 242 if (db && lflag) 243 for (sflag = R_FIRST;; sflag = R_NEXT) { 244 PERSON *tmp; 245 246 r = (*db->seq)(db, &key, &data, sflag); 247 if (r == -1) 248 err(1, "db seq"); 249 if (r == 1) 250 break; 251 memmove(&tmp, data.data, sizeof tmp); 252 enter_lastlog(tmp); 253 } 254} 255 256static void 257userlist(argc, argv) 258 register int argc; 259 register char **argv; 260{ 261 register PERSON *pn; 262 DBT data, key; 263 struct utmp user; 264 struct passwd *pw; 265 int r, sflag, *used, *ip; 266 char **ap, **nargv, **np, **p; 267 FILE *conf_fp; 268 char conf_alias[LINE_MAX]; 269 char *conf_realname; 270 int conf_length; 271 272 if ((nargv = malloc((argc+1) * sizeof(char *))) == NULL || 273 (used = calloc(argc, sizeof(int))) == NULL) 274 err(1, NULL); 275 276 /* Pull out all network requests. */ 277 for (ap = p = argv, np = nargv; *p; ++p) 278 if (index(*p, '@')) 279 *np++ = *p; 280 else 281 *ap++ = *p; 282 283 *np++ = NULL; 284 *ap++ = NULL; 285 286 if (!*argv) 287 goto net; 288 289 /* 290 * Mark any arguments beginning with '/' as invalid so that we 291 * don't accidently confuse them with expansions from finger.conf 292 */ 293 for (p = argv, ip = used; *p; ++p, ++ip) 294 if (**p == '/') { 295 *ip = 1; 296 warnx("%s: no such user", *p); 297 } 298 299 /* 300 * Traverse the finger alias configuration file of the form 301 * alias:(user|alias), ignoring comment lines beginning '#'. 302 */ 303 if ((conf_fp = fopen(_PATH_FINGERCONF, "r")) != NULL) { 304 while(fgets(conf_alias, sizeof(conf_alias), conf_fp) != NULL) { 305 conf_length = strlen(conf_alias); 306 if (*conf_alias == '#' || conf_alias[--conf_length] != '\n') 307 continue; 308 conf_alias[conf_length] = '\0'; /* Remove trailing LF */ 309 if ((conf_realname = strchr(conf_alias, ':')) == NULL) 310 continue; 311 *conf_realname = '\0'; /* Replace : with NUL */ 312 for (p = argv; *p; ++p) { 313 if (strcmp(*p, conf_alias) == NULL) { 314 if ((*p = strdup(conf_realname+1)) == NULL) { 315 err(1, NULL); 316 } 317 } 318 } 319 } 320 (void)fclose(conf_fp); 321 } 322 323 /* 324 * Traverse the list of possible login names and check the login name 325 * and real name against the name specified by the user. If the name 326 * begins with a '/', try to read the file of that name instead of 327 * gathering the traditional finger information. 328 */ 329 if (mflag) 330 for (p = argv, ip = used; *p; ++p, ++ip) { 331 if (**p != '/' || *ip == 1 || !show_text("", *p, "")) { 332 if (((pw = getpwnam(*p)) != NULL) && !hide(pw)) 333 enter_person(pw); 334 else if (!*ip) 335 warnx("%s: no such user", *p); 336 } 337 } 338 else { 339 while ((pw = getpwent()) != NULL) { 340 for (p = argv, ip = used; *p; ++p, ++ip) 341 if (**p == '/' && *ip != 1 342 && show_text("", *p, "")) 343 *ip = 1; 344 else if (match(pw, *p) && !hide(pw)) { 345 enter_person(pw); 346 *ip = 1; 347 } 348 } 349 for (p = argv, ip = used; *p; ++p, ++ip) 350 if (!*ip) 351 warnx("%s: no such user", *p); 352 } 353 354 /* Handle network requests. */ 355net: for (p = nargv; *p;) { 356 netfinger(*p++); 357 if (*p || entries) 358 printf("\n"); 359 } 360 361 if (entries == 0) 362 return; 363 364 /* 365 * Scan thru the list of users currently logged in, saving 366 * appropriate data whenever a match occurs. 367 */ 368 if (!freopen(_PATH_UTMP, "r", stdin)) 369 err(1, "%s", _PATH_UTMP); 370 while (fread((char *)&user, sizeof(user), 1, stdin) == 1) { 371 if (!user.ut_name[0]) 372 continue; 373 if ((pn = find_person(user.ut_name)) == NULL) 374 continue; 375 enter_where(&user, pn); 376 } 377 if (db) 378 for (sflag = R_FIRST;; sflag = R_NEXT) { 379 PERSON *tmp; 380 381 r = (*db->seq)(db, &key, &data, sflag); 382 if (r == -1) 383 err(1, "db seq"); 384 if (r == 1) 385 break; 386 memmove(&tmp, data.data, sizeof tmp); 387 enter_lastlog(tmp); 388 } 389}
|