[6375] in Athena Bugs
finger changes
daemon@ATHENA.MIT.EDU (John Carr)
Fri Nov 9 23:59:31 1990
To: bugs@ATHENA.MIT.EDU
Date: Fri, 09 Nov 90 23:59:11 EST
From: John Carr <jfc@ATHENA.MIT.EDU>
This patch to finger allows use of common source for both versions of finger
(defining HESIOD and ZEPHYR for /usr/athena/finger but not /usr/ucb/finger),
and adds one extension:
If the terminal field in /etc/utmp begins with ':', the terminal
name is used as an X display name, and the idle time of that display
is found using the X Idle time extension.
Sample output:
Login Name TTY Idle When Office
jfc John F Carr ap 1:12 Fri 22:34 E40-342 253-4261
jfc John F Carr p3 Fri 22:35 E40-342 253-4261
jfc John F Carr :0 Fri 23:47 E40-342 253-4261
*** /source/athena/usr.athena/finger/finger.c Thu Jul 12 15:46:31 1990
--- finger.c Sun Oct 28 04:56:43 1990
***************
*** 115,124 ****
--- 115,133 ----
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
+ #ifdef HESIOD
#include <hesiod.h>
+ #endif
+ #ifdef ZEPHYR
#include <zephyr/zephyr.h>
+ #endif
#include "mit-copyright.h"
+ #ifdef XIDLE
+ #include <X11/Xlib.h>
+ #include <X11/extensions/xidle.h>
+ #endif
+
#define MAXTTYS 256
#define MAXSEARCH 750
***************
*** 137,143 ****
#define NMAX sizeof(user.ut_name)
#define LMAX sizeof(user.ut_line)
#define HMAX sizeof(user.ut_host)
- #define MIN(a,b) ((a) < (b) ? (a) : (b))
struct person { /* one for each person fingered */
char *name; /* name */
--- 146,151 ----
***************
*** 180,196 ****
int small = 0; /* -s option default */
int wide = 1; /* -w option default */
int numloc = 1; /* number of locations from zgetlocations */
ZLocations_t location; /* holds Zephyr locations */
! int znloc = NULL; /* number of locations returned via a Zephyr
* lookup */
int unshort;
int lf = -1; /* LASTLOG file descriptor */
int lw = -1; /* ACCTLOG file descriptor */
! /* !#$%!@#$! Bezerkeley non-initializations !!! */
! struct person *person1 = (struct person *) NULL; /* list of people */
! struct person *person2 = (struct person *) NULL; /* 2nd list of people */
long tloc; /* current time */
char ttnames[MAXTTYS][LMAX]; /* TTY names */
--- 188,206 ----
int small = 0; /* -s option default */
int wide = 1; /* -w option default */
+ #ifdef ZEPHYR
int numloc = 1; /* number of locations from zgetlocations */
ZLocations_t location; /* holds Zephyr locations */
! int znloc = 0; /* number of locations returned via a Zephyr
* lookup */
+ #endif
+
int unshort;
int lf = -1; /* LASTLOG file descriptor */
int lw = -1; /* ACCTLOG file descriptor */
! struct person *person1; /* list of people */
! struct person *person2; /* 2nd list of people */
long tloc; /* current time */
char ttnames[MAXTTYS][LMAX]; /* TTY names */
***************
*** 197,205 ****
long logouts[MAXTTYS]; /* Logout times */
struct passwd *pwdcopy();
! char *strcpy();
! char *strcat();
! char *strncpy();
char *malloc();
char *ctime();
--- 207,213 ----
long logouts[MAXTTYS]; /* Logout times */
struct passwd *pwdcopy();
! #include <strings.h>
char *malloc();
char *ctime();
***************
*** 264,276 ****
--- 272,288 ----
else
donames(argv);
if (person1) {
+ #ifdef ZEPHYR
printf("\nLocal:\n");
+ #endif
print(person1);
}
+ #ifdef ZEPHYR
if (person2) {
printf("\nAthena-wide:\n");
print(person2);
}
+ #endif
exit(0);
}
***************
*** 345,353 ****
--- 357,369 ----
register struct person *q; /* A second chain for athena-wide
* finger */
register struct passwd *pw;
+ #ifdef HESIOD
struct passwd *hesgetpwnam();
+ #endif
int uf, i;
+ #ifdef ZEPHYR
Code_t state;
+ #endif
/*
* get names from command line and check to see if they're logged in
***************
*** 437,446 ****
}
}
}
/* now do the hesiod chain */
for (q = person2; q != 0; q = q->link)
! if (pw = hesgetpwnam(q->name))
q->pwd = pwdcopy(pw);
endpwent();
}
/* Now get login information */
--- 453,464 ----
}
}
}
+ #ifdef HESIOD
/* now do the hesiod chain */
for (q = person2; q != 0; q = q->link)
! if (pw = hes_getpwnam(q->name))
q->pwd = pwdcopy(pw);
+ #endif
endpwent();
}
/* Now get login information */
***************
*** 485,490 ****
--- 503,509 ----
}
}
}
+ #ifdef ZEPHYR
/* Ask Zephyr if someone is logged in. */
if ((state = ZInitialize()) != ZERR_NONE) {
com_err("finger", state, "\nFailure in Zephyr \
***************
*** 524,529 ****
--- 543,549 ----
}
}
}
+ #endif
(void) close(uf);
if (unquick) {
fwopen();
***************
*** 969,979 ****
if (*gp == COMMA) { /* nickname */
gp++;
bp = buffer;
! while ((*gp != NULL) && (*gp != COMMA)) {
if (*gp == SAMENAME) {
lp = pers->pwd->pw_name;
*bp++ = CAPITALIZE(*lp++);
! while (*lp != NULL) {
*bp++ = *lp++;
}
}
--- 989,999 ----
if (*gp == COMMA) { /* nickname */
gp++;
bp = buffer;
! while ((*gp != '\0') && (*gp != COMMA)) {
if (*gp == SAMENAME) {
lp = pers->pwd->pw_name;
*bp++ = CAPITALIZE(*lp++);
! while (*lp != '\0') {
*bp++ = *lp++;
}
}
***************
*** 982,988 ****
}
gp++;
}
! *bp = NULL;
if (strlen(buffer) > 0) {
pers->nickname = malloc((unsigned) (strlen(&buffer[0])
+ 1));
--- 1002,1008 ----
}
gp++;
}
! *bp = '\0';
if (strlen(buffer) > 0) {
pers->nickname = malloc((unsigned) (strlen(&buffer[0])
+ 1));
***************
*** 1089,1095 ****
if (count++ == MAXSEARCH)
goto fudged;
if (!strncmp(bp->ut_name, pers->name,
! MIN(strlen(pers->name)+1, NMAX))) {
(void) strncpy(pers->tty,
bp->ut_line, LMAX);
(void) strncpy(pers->host,
--- 1109,1115 ----
if (count++ == MAXSEARCH)
goto fudged;
if (!strncmp(bp->ut_name, pers->name,
! min(strlen(pers->name)+1, NMAX))) {
(void) strncpy(pers->tty,
bp->ut_line, LMAX);
(void) strncpy(pers->host,
***************
*** 1178,1188 ****
#define TTYLEN 5
if (!pers->zlocation) {
(void) strcpy(buffer + TTYLEN, pers->tty);
buffer[TTYLEN + LMAX] = 0;
if (stat(buffer, &ttystatus) < 0) {
fprintf(stderr, "finger: Can't stat %s\n", buffer);
! exit(4);
}
(void) time(&t);
if (t < ttystatus.st_atime)
--- 1198,1216 ----
#define TTYLEN 5
if (!pers->zlocation) {
+ #ifdef XIDLE
+ if(pers->tty[0] == ':') {
+ GetXTime(pers);
+ return;
+ }
+ #endif
(void) strcpy(buffer + TTYLEN, pers->tty);
buffer[TTYLEN + LMAX] = 0;
if (stat(buffer, &ttystatus) < 0) {
+ if(pers->tty[0] != ':')
fprintf(stderr, "finger: Can't stat %s\n", buffer);
! pers->idletime = -1;
! return;
}
(void) time(&t);
if (t < ttystatus.st_atime)
***************
*** 1205,1210 ****
--- 1233,1243 ----
{
register struct tm *delta;
+ if(*dt == -1) {
+ printf("????");
+ return;
+ }
+
delta = gmtime(dt);
if (delta->tm_yday == 0)
if (delta->tm_hour == 0)
***************
*** 1232,1237 ****
--- 1265,1275 ----
{
register struct tm *delta;
+ if(*dt == -1) {
+ printf("Idle time unknown\n");
+ return;
+ }
+
delta = gmtime(dt);
if (delta->tm_yday == 0 && delta->tm_hour == 0 && delta->tm_min == 0 &&
delta->tm_sec <= 10)
***************
*** 1338,1344 ****
struct servent *sp;
struct sockaddr_in sin;
int s;
- char *rindex();
register FILE *f;
register int c;
register int lastc;
--- 1376,1381 ----
***************
*** 1426,1431 ****
--- 1463,1491 ----
(void) fclose(f);
return (1);
}
+
+ #ifdef XIDLE
+ GetXTime(pers)
+ struct person *pers;
+ {
+ register char *display = pers->tty;
+ register Display *dpy;
+ int d1, d2;
+ Time idle;
+
+ dpy = XOpenDisplay(display);
+ if(dpy == NULL ||
+ XidleQueryExtension(dpy, &d1, &d2) == 0 ||
+ XGetIdleTime(dpy, &idle) == 0) {
+ pers->idletime = -1;
+ if(dpy) XCloseDisplay(dpy);
+ return;
+ }
+ pers->idletime = idle / 1000;
+ pers->writable = 1;
+ XCloseDisplay(dpy);
+ }
+ #endif
/*
* Local Variables:
*** /source/athena/usr.athena/finger/Makefile Wed May 2 14:46:21 1990
--- Makefile Fri Nov 9 23:54:43 1990
***************
*** 42,67 ****
#
#
DESTDIR=
! CFLAGS = -O
CONFDIR = ${DESTDIR}/usr/athena
BINDIR = ${DESTDIR}/bin
! LIBS = -lhesiod -lzephyr -lcom_err -lkrb -ldes
! SRCS = finger.c hespwnam.c
! OBJECTS = finger.o hespwnam.o
all: finger
finger: ${OBJECTS}
! cc ${CFLAGS} -o finger ${OBJECTS} ${LIBS}
finger.o: finger.c
cc -c ${CFLAGS} finger.c
-
- hespwnam.o: hespwnam.c
- cc -c ${CFLAGS} hespwnam.c
lint:
lint -I../../include *.c
--- 42,67 ----
#
#
DESTDIR=
! OPT=-O
! DEFINES= -DXIDLE -DHESIOD -DZEPHYR
! CFLAGS = $(OPT) $(DEFINES)
! LDFLAGS=-Z
CONFDIR = ${DESTDIR}/usr/athena
BINDIR = ${DESTDIR}/bin
! LIBS = -lhesiod -lzephyr -lcom_err -lkrb -ldes -lXext -lX11
! SRCS = finger.c
! OBJECTS = finger.o
all: finger
finger: ${OBJECTS}
! $(CC) $(LDFLAGS) -o finger ${OBJECTS} ${LIBS}
finger.o: finger.c
cc -c ${CFLAGS} finger.c
lint:
lint -I../../include *.c