* Copyright (c) 1989 The Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1989 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)finger.c 5.17 (Berkeley) %G%";
* Finger prints out information about users. It is not portable since
* certain fields (e.g. the full user name, office, and phone numbers) are
* extracted from the gecos field of the passwd file which other UNIXes
* may not have or may use for other things.
* There are currently two output formats; the short format is one line
* per user and displays login name, tty, login time, real name, idle time,
* and office location/phone number. The long format gives the same
* information (in a more legible format) as well as home directory, shell,
* mail info, and .plan/.project files.
int lflag
, sflag
, mflag
, pplan
;
while ((ch
= getopt(argc
, argv
, "lmps")) != EOF
)
lflag
= 1; /* long format */
mflag
= 1; /* force exact match of names */
pplan
= 1; /* don't show .plan/.project */
sflag
= 1; /* short format */
"usage: finger [-lmps] [login ...]\n");
* Assign explicit "small" format if no names given and -l
* not selected. Force the -s BEFORE we get names so proper
* screening will be done.
sflag
= 1; /* if -l not explicit, force -s */
(void)printf("No one logged on.\n");
* Assign explicit "large" format if names given and -s not
* explicitly stated. Force the -l AFTER we get names so any
* remote finger attempts specified won't be mishandled.
lflag
= 1; /* if -s not explicit, force -l */
char name
[UT_NAMESIZE
+ 1];
if ((fp
= fopen(_PATH_UTMP
, "r")) == NULL
) {
(void)fprintf(stderr
, "finger: can't read %s.\n", _PATH_UTMP
);
name
[UT_NAMESIZE
] = NULL
;
while (fread((char *)&user
, sizeof(user
), 1, fp
) == 1) {
if ((pn
= find_person(user
.ut_name
)) == NULL
) {
bcopy(user
.ut_name
, name
, UT_NAMESIZE
);
if ((pw
= getpwnam(name
)) == NULL
)
for (pn
= phead
; lflag
&& pn
!= NULL
; pn
= pn
->next
)
if (!(used
= (int *)calloc((u_int
)argc
, (u_int
)sizeof(int)))) {
(void)fprintf(stderr
, "finger: out of space.\n");
/* pull out all network requests */
for (i
= 0, dolocal
= 0, nethead
= NULL
; i
< argc
; i
++) {
if (!index(argv
[i
], '@')) {
* traverse the list of possible login names and check the login name
* and real name against the name specified by the user.
for (i
= 0; i
< argc
; i
++)
if (used
[i
] >= 0 && (pw
= getpwnam(argv
[i
]))) {
} else while (pw
= getpwent())
for (i
= 0; i
< argc
; i
++)
(!strcasecmp(pw
->pw_name
, argv
[i
]) ||
for (i
= 0; i
< argc
; i
++)
"finger: %s: no such user.\n", argv
[i
]);
/* handle network requests */
net
: for (pn
= nethead
; pn
; pn
= pn
->next
) {
* Scan thru the list of users currently logged in, saving
* appropriate data whenever a match occurs.
if ((fp
= fopen(_PATH_UTMP
, "r")) == NULL
) {
(void)fprintf( stderr
, "finger: can't read %s.\n", _PATH_UTMP
);
while (fread((char *)&user
, sizeof(user
), 1, fp
) == 1) {
if ((pn
= find_person(user
.ut_name
)) == NULL
)
for (pn
= phead
; pn
!= NULL
; pn
= pn
->next
)