/* logon.c note: must link REL to newlib/s */ #include "b:printf.h" #define KAYPRO /* conditional for video attribute definitions */ #define TITLE "Logon Version 1.2, by David C. Oshel" #define BDRIV 14 /* bdos select disk */ #define BUSER 32 /* bdos set user code */ #define MAXUSERS 64 #define TRUE 1 #define FALSE 0 #define USERFILE "LOGON.USR" #define UFD 0 #define UFU 15 /* selects A15: for userfile */ static struct users { char uname[20]; char passw[20]; char progr[20]; char parms[80]; int usdr, uusr; } *login[MAXUSERS], *log; main( argc, argv ) int argc; char *argv[]; { char name[20], pw[20]; init_lib(); OFFinterrupt(); /* kill control-c */ pw[0] = '\0'; name[0] = '\0'; getable(); clr_screen(); printf("%s\n\nType \"?\" and hit for assistance.\n\n",TITLE); lookup( name, pw ); execut(); } /* end: main */ assume(p,q,lim) char *p,*q; int lim; { /* copies lim bytes from q to p */ int i; i = 0; while (*q && (i < lim)) { *p = *q; p++; q++; i++; } *p = '\0'; } /* end: assume */ lookup(p,q) char *p,*q; { int good; zoo: good = 0; while (!good) { while (getwho(p) < 0) { printf("\nLogon: "); getu(p,15); if ((index(p,"HELP") >= 0) || (index(p,"?") >= 0)) { help(); p[0] = '\0'; goto zoo; } } good = passmatch(q); p[0] = '\0'; } } /* end: lookup */ execut() { char *p, *q, *r, *s, inbuf[80], parmbuff[128]; int a, i, warmboot; struct subrec { char lenbyte; char cmd[127]; } subway; /* prompt for variable parameter(s) & expand user command line, if needed */ p = parmbuff; q = log->parms; a = 0; if (index(q,"$") < 0) strcpy(p,q); /* default case */ else { help2(); while ( (i = index(log->parms,"$")) >= 0) { *(log->parms + i) = '\0'; /* erase the $ */ while (*q) *p++ = *q++; ++a; loo: printf("%s $%d? ",log->uname,a); r = inbuf; getu(r,79); if (index(r,"?") >= 0) { help2(); goto loo; } while (*r && isspace(*r)) r++; /* strip leading spaces */ strcpy(p,r); r = p; while (*p) p++; --p; /* skip to eol and back up one */ while (isspace(*p) && (p > r)) *p-- = '\0'; /* strip trailing spaces */ ++p; /* point to the null */ *q = ' '; /* erase 0, was $, generate separating space in */ /* case the LOGON.USR parmfield contains $$$... */ } printf("\n"); } clr_screen(); printf("One moment, please. Loading %s %s...\n\n",log->progr,parmbuff); /* set the CP/M du byte so CCP will find the chainback SUB file on warm boot */ bdos(BDRIV,log->usdr); bdos(BUSER,log->uusr); s = 0x04; /* page 0 drive/user byte, active on warm boot */ *s = (char) ( log->uusr * 16 + log->usdr ); /* write the $$$.SUB file (chains back to logon) in the user's own area */ warmboot = fopen("A:$$$.SUB","wb"); strcpy(subway.cmd,"logon"); subway.lenbyte = strlen(subway.cmd); s = (char *) &subway; for (i = 0; i < 128; i++) putc( s[i], warmboot); fclose(warmboot); /* finally, do it ...! */ exec(log->progr,parmbuff); /* does not return, restarts via SUB */ } /* end: execut */ passmatch(q) char *q; { if ( strlen(log->passw) == 0 ) return 1; /* no password required */ if ( index(log->passw,"*") >= 0) return 1; /* hidden, no password */ printf("\nPassword: "); getu(q,15); printf("\n"); if ( strcmp(q,log->passw) == 0 ) return TRUE; else return FALSE; } /* end: passmatch */ getwho(p) char *p; { int i; if (strlen(p) == 0) return (-1); for (i = 0; i < MAXUSERS; i++) { log = login[i]; if ( strcmp(p,log->uname) == 0 ) { break; } } if (i == MAXUSERS) return (-1); else return (i); } /* end: getwho */ getable() { int i, j, k, file; char *dlog; bdos(BDRIV,UFD); bdos(BUSER,UFU); if (rename(USERFILE,USERFILE) == -1) { printf("\007*** ERROR: Users list not found!\n"); while (TRUE) ; } file = fopen(USERFILE,"rb"); k = sizeof( struct users ); for (i = 0; i < MAXUSERS; i++) { login[i] = alloc( k ); dlog = (char *) login[i]; for (j = 0; j < k; j++) *dlog++ = getc(file); } fclose( file ); } /* end: getable */ getu(p,len) char *p; int len; { gets(p,len); while (*p) *p = toupper(*p++); } /* end: getu */ help() { int i, j, u; struct users *q; char *dazzle, *normal; #ifndef KAYPRO dazzle = ""; normal = ""; #else dazzle = "\033B0\033B1"; normal = "\033C0\033C1"; #endif clr_screen(); printf("%s\n\n",TITLE); printf("To LOGOFF (and quit) type LOGOFF, QUIT or BYE, and hit .\n"); printf("To RUN A PROGRAM, select one of these User/Program names:\n\n"); for (u = i = 0; i < MAXUSERS; i++) { q = login[i]; if (strlen(q->uname) > 0 && index(q->passw,"*") < 0) { if (strlen(q->passw) == 0) { printf("%21s%3d. %-15s%s\n",dazzle,++u,q->uname,normal); if (!(u % 16)) { printf("%21s","(more)"); while (!getc(0)) ; for (j=0; j<21; j++) putc(08,0); } } } } printf("\n"); } /* end: help */ help2() { printf("%s accepts an optional name or expression, e.g., the name of a game\n",log->uname); printf("to continue playing (Adventure), or a document to edit (WordStar).\n\n"); printf("Enter an expression that %s may use, or hit ",log->uname); printf("to IGNORE this step.\n\n"); } /* end: help2 */ #include "exec.c"