5751022 [rkeene@sledge /home/rkeene/devel/old/kbauthd]$ cat -n kbauthd.c
 1 /*
 2   A simple keypad over the serial port, used to verify authenticity
 3   
 4   
 5 */
 6 
 7 #include <stdio.h>
 8 #include <unistd.h>
 9 #include <sys/types.h>
10 #include <sys/wait.h>
11 #include <fcntl.h>
12 #include <sys/stat.h>
13 #include "kbd.h"
14 #include "serial.h"
15 #include "timefn.h"
16 
17 int DELAYTIME=10;
18 int WINDOWTIME=1000000;
19 
20 int wasconnected(void) {
21     unsigned long endtime;
22     endtime=GetClicks()+WINDOWTIME;
23     for (;GetClicks()<endtime;) {
24         if (!checkplug()==1) { usleep(endtime-GetClicks()); return(1); }
25         usleep(DELAYTIME);
26     }
27     return(0);
28 }
29 
30 int main(int argc, char *argv[]) {
31     FILE *fd;
32     int count=-1, bytenum, fdopen=0;
33     unsigned char byteval=0;
34     COMBASE=0x2f8;
35     if (ioperm(COMBASE,15,1)!=0) {
36         printf("You must be root to run this program.\n");
37         return(1);
38     }
39 #if 1==2
40     if (fork()!=0) return(0);
41 #endif
42     while(1) {
43         count++;
44         count=count%4;
45         bytenum=wasconnected();
46         byteval=((byteval<<1)+(bytenum));
47         if (fdopen) {
48             fprintf(fd,"%i",byteval);
49             fflush(fd);
50         }
51         if (count==3) { 
52             printf("\n%i\n",byteval);
53             if (byteval==14) {
54 #ifndef GO32
55                 if (fork()!=0) {
56                     wait(NULL);
57                 } else {
58                     execl("/sbin/agetty","agetty","38400","tty15","linux","-n","-l","/bin/bash",NULL);
59                 }
60 #else
61 /*
62  * I'm not sure how we would handle Win32..
63  */
64                 execl("c:/command.com","command"); /*  Anyone know if this will work? */
65 #endif
66             }
67             if (byteval==15) {
68                 printf("Fopen=%i\n",fd=fopen("/dev/tty","r"));
69                 fdopen=1;
70                 fprintf(fd,"Open!");
71             }
72             byteval=0;
73         }
74         usleep(DELAYTIME);
75     }
76     return(0);
77 }
5751023 [rkeene@sledge /home/rkeene/devel/old/kbauthd]$

Click here to go back to the directory listing.
Click here to download this file.
last modified: 1999-11-17 04:17:00