home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume22
/
bigb
/
part01
/
find_term.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-09-13
|
2KB
|
74 lines
/* This routine tries to find which terminal a login attempt was made on.
* I freely admit that it is a disgusting hack - there does not seem to be
* any reliable way of finding out on which terminal a failed login
* attempt was made. This routine just goes through all terminals in
* turn and compares the uid and time of the last suitable login attempt.
* As if that was not bad enough the times in general do not match exactly
* so I look for times that match to within 5 seconds. Also 60 seconds
* after a failed login the terminal times out, this updates the time flag
* so I also check for a terminal failure 60+-5 seconds after the login
* failure!
*/
#include "bigb.h"
#include <string.h>
#include <time.h>
/* Return the data is this buffer */
PRIVATE char devname[20];
/* Declare the local routine */
PRIVATE int check_term_for_match(const struct pr_term *, int, int, time_t);
PUBLIC char *find_relevant_terminal(int successful,int uid,time_t ttime)
{
struct pr_term *term;
int res = FALSE;
setprtcent();
while ((term=getprtcent()) != (struct pr_term *) NULL) {
if ((res=check_term_for_match(term,successful,uid,ttime)) == TRUE)
break;
};
endprtcent();
if (res == TRUE)
strcpy(devname,term->ufld.fd_devname); /* Found it */
else
strcpy(devname,"unknown terminal"); /* No match */
return(devname);
}
PRIVATE int check_term_for_match(const struct pr_term *term,
int successful, int uid, time_t ttime)
{
struct t_field *data;
int t_uid;
time_t t_time;
time_t time_diff;
data = (struct t_field *) &(term->ufld);
/* Get the last uid and time data from the terminal database */
if (successful == TRUE) {
t_uid = data->fd_uid;
t_time = data->fd_slogin;
} else {
t_uid = data->fd_uuid;
t_time = data->fd_ulogin;
}
/* Check if the uid matches ( or matches 0 after a timeout ) */
if (uid != t_uid && t_uid != 0)
return(FALSE);
/* Check if the time matches ( or +60 seconds after a timeout ) */
time_diff = ttime - t_time;
if ((abs(time_diff) > 5) && (abs(time_diff+60) > 5))
return(FALSE);
/* Not certain but this looks likely */
return(TRUE);
}