home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / CCP / LOGON12.LBR / LOGON.CQ / LOGON.C
Text File  |  2000-06-30  |  6KB  |  284 lines

  1. /* logon.c
  2.  
  3. note: must link REL to newlib/s
  4.  
  5. */
  6.  
  7. #include "b:printf.h"
  8.  
  9.  
  10. #define KAYPRO /* conditional for video attribute definitions */
  11.  
  12. #define TITLE "Logon Version 1.2, by David C. Oshel"
  13.  
  14. #define BDRIV 14 /* bdos select disk   */
  15. #define BUSER 32 /* bdos set user code */
  16. #define MAXUSERS 64
  17. #define TRUE 1
  18. #define FALSE 0
  19. #define USERFILE "LOGON.USR"
  20. #define UFD 0
  21. #define UFU 15 /* selects A15: for userfile */
  22.  
  23. static struct users {
  24.     char uname[20];
  25.     char passw[20];
  26.     char progr[20];
  27.     char parms[80];
  28.     int  usdr, uusr;
  29.     }
  30.     *login[MAXUSERS],
  31.     *log;
  32.  
  33.  
  34.  
  35. main( argc, argv ) int argc; char *argv[]; {
  36.  
  37. char name[20], pw[20];
  38.  
  39.  
  40.     init_lib();
  41.     OFFinterrupt(); /* kill control-c */
  42.  
  43.     pw[0] = '\0';
  44.     name[0] = '\0';
  45.  
  46.  
  47.     getable();
  48.     clr_screen(); 
  49.     printf("%s\n\nType \"?\" and hit <Return> for assistance.\n\n",TITLE); 
  50.     lookup( name, pw );
  51.     execut();
  52.  
  53. } /* end: main */
  54.  
  55.  
  56.  
  57. assume(p,q,lim) char *p,*q; int lim; { /* copies lim bytes from q to p */
  58.  
  59. int i;
  60.     i = 0;
  61.     while (*q && (i < lim)) {
  62.         *p = *q;
  63.         p++; q++; i++;
  64.     }
  65.     *p = '\0';
  66.  
  67. } /* end: assume */
  68.  
  69.  
  70.  
  71. lookup(p,q) char *p,*q; {
  72.  
  73. int good;
  74.  
  75. zoo:    good = 0;
  76.     while (!good) { 
  77.         while (getwho(p) < 0) {
  78.             printf("\nLogon: ");
  79.             getu(p,15);
  80.             if ((index(p,"HELP") >= 0) || (index(p,"?") >= 0)) {
  81.                 help();
  82.                 p[0] = '\0';
  83.                 goto zoo;
  84.             }
  85.         }
  86.         good = passmatch(q);
  87.         p[0] = '\0';
  88.     }
  89.  
  90. } /* end: lookup */
  91.  
  92.  
  93.  
  94.  
  95. execut() {
  96.  
  97. char *p, *q, *r, *s, inbuf[80], parmbuff[128];
  98. int a, i, warmboot; 
  99. struct subrec {
  100.     char lenbyte;
  101.     char cmd[127];
  102.     }
  103.     subway;
  104.  
  105.  
  106.  
  107.  
  108. /* prompt for variable parameter(s) & expand user command line, if needed */
  109.  
  110.     p = parmbuff; q = log->parms; a = 0;
  111.  
  112.     if (index(q,"$") < 0) strcpy(p,q); /* default case */
  113.  
  114.     else {
  115.     help2();
  116.     while ( (i = index(log->parms,"$")) >= 0) {
  117.         *(log->parms + i) = '\0'; /* erase the $ */
  118.         while (*q) *p++ = *q++;
  119.  
  120.         ++a;
  121. loo:        printf("%s $%d? ",log->uname,a);
  122.         r = inbuf;
  123.         getu(r,79);
  124.         if (index(r,"?") >= 0) { help2(); goto loo; }
  125.  
  126.         while (*r && isspace(*r)) r++; /* strip leading spaces */
  127.         strcpy(p,r);
  128.         r = p;
  129.         while (*p) p++; --p; /* skip to eol and back up one */
  130.         while (isspace(*p) && (p > r)) *p-- = '\0'; /* strip trailing spaces */
  131.         ++p; /* point to the null */
  132.         *q = ' '; /* erase 0, was $, generate separating space in */
  133.                       /* case the LOGON.USR parmfield contains $$$... */
  134.     }
  135.     printf("\n"); 
  136.     }
  137.     clr_screen();
  138.     printf("One moment, please.  Loading %s %s...\n\n",log->progr,parmbuff); 
  139.  
  140.  
  141.  
  142. /* set the CP/M du byte so CCP will find the chainback SUB file on warm boot */
  143.  
  144.     bdos(BDRIV,log->usdr);
  145.     bdos(BUSER,log->uusr);
  146.     s = 0x04; /* page 0 drive/user byte, active on warm boot */
  147.     *s = (char) ( log->uusr * 16 + log->usdr );
  148.  
  149.  
  150. /* write the $$$.SUB file (chains back to logon) in the user's own area  */
  151.  
  152.     warmboot = fopen("A:$$$.SUB","wb");
  153.     strcpy(subway.cmd,"logon");
  154.     subway.lenbyte = strlen(subway.cmd);
  155.     s = (char *) &subway;
  156.     for (i = 0; i < 128; i++) putc( s[i], warmboot);
  157.     fclose(warmboot);
  158.  
  159. /* finally, do it ...! */
  160.  
  161.     exec(log->progr,parmbuff); /* does not return, restarts via SUB */
  162.  
  163. } /* end: execut */
  164.  
  165.  
  166.  
  167. passmatch(q) char *q; {
  168.  
  169.     if ( strlen(log->passw) == 0 ) return 1;   /* no password required */
  170.     if ( index(log->passw,"*") >= 0) return 1; /* hidden, no password  */
  171.     printf("\nPassword: ");
  172.     getu(q,15);
  173.     printf("\n");
  174.     if ( strcmp(q,log->passw) == 0 ) return TRUE; else return FALSE;
  175.  
  176. } /* end: passmatch */
  177.  
  178.  
  179.  
  180.  
  181. getwho(p) char *p; {
  182.  
  183. int i;
  184.  
  185.     if (strlen(p) == 0) return (-1);
  186.  
  187.     for (i = 0; i < MAXUSERS; i++) {
  188.         log = login[i];
  189.         if ( strcmp(p,log->uname) == 0  ) {
  190.             break;
  191.         }
  192.     }
  193.  
  194.     if (i == MAXUSERS) return (-1); else return (i);
  195.  
  196. } /* end: getwho */
  197.  
  198.  
  199.  
  200.  
  201. getable() {
  202.  
  203. int i, j, k, file; 
  204. char *dlog;
  205.  
  206.  
  207.     bdos(BDRIV,UFD); 
  208.     bdos(BUSER,UFU);
  209.  
  210.     if (rename(USERFILE,USERFILE) == -1) {
  211.         printf("\007*** ERROR: Users list not found!\n");
  212.         while (TRUE) ;
  213.     }
  214.  
  215.     file = fopen(USERFILE,"rb");
  216.  
  217.     k = sizeof( struct users );
  218.  
  219.     for (i = 0; i < MAXUSERS; i++) {
  220.         login[i] = alloc( k );
  221.         dlog = (char *) login[i];
  222.         for (j = 0; j < k; j++) *dlog++ = getc(file);
  223.     }
  224.     fclose( file );
  225.  
  226. } /* end: getable */
  227.  
  228.  
  229. getu(p,len) char *p; int len; {
  230.  
  231.     gets(p,len);
  232.     while (*p) *p = toupper(*p++);
  233.  
  234. } /* end: getu */
  235.  
  236.  
  237. help() {
  238.  
  239. int i, j, u; struct users *q; char *dazzle, *normal;
  240.  
  241. #ifndef KAYPRO
  242.     dazzle = "";
  243.     normal = "";
  244. #else
  245.     dazzle = "\033B0\033B1";
  246.     normal = "\033C0\033C1";
  247. #endif
  248.     clr_screen();
  249.     printf("%s\n\n",TITLE);
  250.     printf("To LOGOFF (and quit) type LOGOFF, QUIT or BYE, and hit <Return>.\n");
  251.     printf("To RUN A PROGRAM, select one of these User/Program names:\n\n");
  252.     for (u = i = 0; i < MAXUSERS; i++) {
  253.         q = login[i];
  254.         if (strlen(q->uname) > 0 && index(q->passw,"*") < 0) {
  255.             if (strlen(q->passw) == 0) {
  256.                 printf("%21s%3d. %-15s%s\n",dazzle,++u,q->uname,normal);  
  257.                 if (!(u % 16)) {
  258.                     printf("%21s","(more)");
  259.                     while (!getc(0)) 
  260.                     ;
  261.                     for (j=0; j<21; j++) putc(08,0);
  262.                 }
  263.             }
  264.         }
  265.     }
  266.     printf("\n");
  267.  
  268. } /* end: help */
  269.  
  270.  
  271. help2() {
  272.  
  273.     printf("%s accepts an optional name or expression, e.g., the name of a game\n",log->uname); 
  274.     printf("to continue playing (Adventure), or a document to edit (WordStar).\n\n");
  275.  
  276.     printf("Enter an expression that %s may use, or hit <Return> ",log->uname);
  277.     printf("to IGNORE this step.\n\n");
  278.  
  279. } /* end: help2 */
  280.  
  281.  
  282. #include "exec.c"
  283.  
  284.