|
|
1.1 ! root 1: #include <stdio.h> ! 2: #include <signal.h> ! 3: #include <string.h> ! 4: ! 5: #include "auth.h" ! 6: ! 7: #define MAXTRYS 3 ! 8: #define DESTTRYS 8 ! 9: #define TIMEOUT (60*5) /*seconds 'til we go away*/ ! 10: ! 11: char *keyfile = "/usr/guard/keys"; ! 12: char *logfile = "/usr/guard/log/auth"; ! 13: ! 14: char line[BUFSIZE]; ! 15: char logbuf[BUFSIZE*MAXTRYS + BUFSIZE*DESTTRYS + BUFSIZE] = ""; ! 16: char caller[BUFSIZE]; ! 17: ! 18: SIG_TYP timeout(); ! 19: ! 20: main(argc, argv) ! 21: int argc; ! 22: char *argv[]; ! 23: { ! 24: char *chal; ! 25: int ok, tries; ! 26: char user[10]; ! 27: ! 28: extern int optind; ! 29: extern char *optarg; ! 30: char c; ! 31: ! 32: while ((c = getopt(argc, argv, "k:l:")) != EOF) { ! 33: switch (c) { ! 34: case 'k': keyfile = optarg; break; ! 35: case 'l': logfile = optarg; break; ! 36: default: ! 37: printf("auth argument error, get help!\n"); ! 38: exit(100); ! 39: } ! 40: } ! 41: ! 42: if (freopen(logfile, "a", stderr) == (FILE *)0) { ! 43: printf("could not open log file, get help!\n"); ! 44: exit(100); ! 45: } ! 46: ! 47: readkeyfile(); ! 48: chdir("/usr/guard"); /* in case of core dumps; I wanna find them */ ! 49: /*getcaller(caller);*/ ! 50: printf("\nAuthentication Server.\n\n"); ! 51: signal(SIGALRM, timeout); ! 52: alarm(TIMEOUT); ! 53: settty(); ! 54: ! 55: for (tries=MAXTRYS, ok=FALSE; tries > 0; tries--) { ! 56: int echo; ! 57: ! 58: printf("Id? "); ! 59: getline(TRUE); ! 60: strncpy(user, line, sizeof(user)); ! 61: user[sizeof(user) - 1] = '\0'; ! 62: log(line); log(", "); ! 63: if ((chal = getchallenge(line, "", &echo)) == NULL) ! 64: continue; ! 65: printf("%s", chal); ! 66: getline(echo); ! 67: if (responseok(line)) { ! 68: ok = TRUE; ! 69: break; ! 70: } ! 71: printf("Incorrect.\n"); ! 72: } ! 73: if (!ok) { ! 74: printf("Authentication failed.\n"); ! 75: dowarning("Failed"); ! 76: exit(1); ! 77: } ! 78: ! 79: printf("\n"); ! 80: log(", dest= "); ! 81: alarm(TIMEOUT); ! 82: for (tries=DESTTRYS; tries > 0; tries--) { ! 83: printf("\nDestination? "); ! 84: getline(TRUE); ! 85: log(line); log(", "); ! 86: if (doconnect(line, user)) ! 87: exit(0); ! 88: } ! 89: if (!ok) { ! 90: printf("Too many tries, bye bye.\n"); ! 91: dowarning("Destination"); ! 92: exit(1); ! 93: } ! 94: } ! 95: ! 96: SIG_TYP ! 97: timeout() ! 98: { ! 99: printf("\n\n** Timeout **\n\n"); ! 100: dowarning("Timeout"); ! 101: exit(2); ! 102: } ! 103: ! 104: /* ! 105: * Read a useful line into `line'. ! 106: */ ! 107: getline(echo) ! 108: int echo; ! 109: { ! 110: char *cp; ! 111: ! 112: line[0] = '\0'; ! 113: ! 114: if (!echo) ! 115: setecho(FALSE); ! 116: ! 117: fflush(stdout); ! 118: if(fgets(line, sizeof(line), stdin)==NULL) { ! 119: printf("Eof\n"); ! 120: dowarning("Eof"); ! 121: exit(10); ! 122: } ! 123: if ((cp=strpbrk(line, "\n\r")) != NULL) ! 124: *cp = '\0'; ! 125: if (!echo) ! 126: setecho(TRUE); ! 127: } ! 128: ! 129: /* ! 130: * dowarning - send a warning message to stderr (for now). ! 131: */ ! 132: dowarning(mess) ! 133: char *mess; ! 134: { ! 135: /* ! 136: * WARNING: this log is dangerous! People often get out of ! 137: * sync on logins. We only log the id, but some passwords ! 138: * will appear! ! 139: */ ! 140: fprintf(stderr, "Authentication warning: %s\n", mess); ! 141: fprintf(stderr, " Session: `%s'\n", logbuf); ! 142: } ! 143: ! 144: log(mess) ! 145: char *mess; ! 146: { ! 147: strncat(logbuf, mess, sizeof(logbuf) - strlen(mess) - 1); ! 148: logbuf[sizeof(logbuf)-1] = '\0'; ! 149: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.