home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
cpm
/
ccp
/
logon12.lbr
/
LOGUTIL.CQ
/
LOGUTIL.C
Wrap
Text File
|
1985-02-09
|
6KB
|
267 lines
/* logutil.c
note: must link REL to newlib/s
*/
#include "printf.h"
#define TITLE "Logon Version 1.2, by David C. Oshel\n\nUser Maintenance Utility"
#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 int new;
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[]; {
init_lib();
ONinterrupt();
getable(); sort();
clr_screen();
printf("%s\n\nEnter \"?\" for user list.\n\n",TITLE);
while ( updatu() ) { sort(); putable(); }
exit();
} /* end: main */
updatu() {
struct users temp; char p[4];
zoo: printf("\nUser name (or CR to quit): ");
getu(temp.uname,15);
if (strlen(temp.uname) == 0) return (FALSE);
if (index(temp.uname,"?") >= 0) { listit(); goto zoo; }
if ( getwho(temp.uname) >= 0 ) {
if (!new ) {
printf("\nFOUND!\n"); show( log );
if (!ask("\nAny changes? ")) goto zoo;
if (ask("\nDelete this user? ")) {
if (ask("Delete user...are you sure? ")) {
printf("Deleted!\n");
strcpy(log->uname,"");
return (TRUE);
}}
else strcpy(temp.uname, log->uname);
if (ask("Change password? ")) {
printf("New password (*=hidden public): ");
getu(temp.passw,15);
printf("Change noted!\n");
}
else strcpy(temp.passw, log->passw);
}
else { /* new user */
printf("\nNEW USER: %s\n",temp.uname);
if (!ask("Add this user? ")) goto zoo;
printf("New password (*=hidden public): ");
getu(temp.passw,15);
}
printf("\nEnter Startup Info:\n\n");
printf("Startup program name, e.g., MBASIC (no .COM, please): ");
getu(temp.progr,9);
printf("Parameters ($=user will be prompted): ");
getu(temp.parms,78);
printf("Startup drive, A or B: ");
getu(p,1);
temp.usdr = strlen(p);
if (temp.usdr) {
if (toupper(p[0]) == 'B') temp.usdr = 1;
else temp.usdr = 0;
}
printf("Startup user area, 0-15 : ");
getu(p,2);
temp.uusr = atoi(p);
if (temp.uusr < 0 || temp.uusr > 15) temp.uusr = 0;
if ( verify( &temp ) ) {
strcpy(log->uname,temp.uname);
strcpy(log->passw,temp.passw);
strcpy(log->progr,temp.progr);
strcpy(log->parms,temp.parms);
log->usdr = temp.usdr;
log->uusr = temp.uusr;
return (TRUE);
}
else goto zoo;
}
else return( FALSE ); /* list full or nothing entered, quit */
} /* end: updatu */
verify( z ) struct users *z; {
printf("\n\nYou have requested: \n\n");
show( z );
return (ask("\nIs everything ok? "));
} /* end: verify */
show( z ) struct users *z; {
printf("User Name: %s\n",z->uname);
printf("Password : %s\n",z->passw);
printf("Startup Program: %s%d:",((z->usdr == 0) ? "A" : "B"),z->uusr);
printf("%s %s\n",z->progr,z->parms);
} /* end: show */
getwho(p) char *p; {
int i;
new = TRUE;
for (i = 0; i < MAXUSERS; i++) { /* check for existing user */
log = login[i];
if ( strcmp(p,log->uname) == 0 )
{ new = FALSE; break; }
}
if (new) { /* not there, is there room in the list to add it? */
for (i = 0; i < MAXUSERS; i++) {
log = login[i];
if (strlen(log->uname) == 0) break;
}
}
if (i == MAXUSERS) return (-1); else return (i);
} /* end: getwho */
getable() {
int i, j, k, file; char *glog;
k = sizeof(struct users);
bdos(BDRIV,UFD);
bdos(BUSER,UFU);
if ( rename(USERFILE,USERFILE) == -1 ) {
/* create blank table, create user file */
file = fopen(USERFILE,"wb");
for (i = 0; i < MAXUSERS; i++) {
for (j = 0; j < k; j++) putc(0,file);
}
fclose (file);
}
file = fopen(USERFILE,"rb");
for (i = 0; i < MAXUSERS; i++) {
login[i] = alloc( k );
glog = (char *) login[i];
for (j = 0; j < k; j++) *glog++ = toupper( getc(file) );
}
fclose( file );
} /* end: getable */
putable() {
int i, j, k, file; char *plog;
k = sizeof(struct users);
bdos(BDRIV,UFD);
bdos(BUSER,UFU);
file = fopen(USERFILE,"ub");
for (i = 0; i < MAXUSERS; i++) {
plog = (char *) login[i];
for (j = 0; j < k; j++ ) putc(*plog++,file);
}
fclose( file );
} /* end: putable */
listit() {
int ch, i, lst, u;
lst = ask("\n*** USER LIST: Do you want a printout? ");
if (lst) ONscript();
u = 0;
printf("\nNum User Name Password Startup Program\n\n");
for (i = 0; i < MAXUSERS; i++) {
log = login[i];
if (strlen(log->uname) > 0) {
printf("%3d. %15s%15s ",++u,log->uname,log->passw);
printf("%s%d:",((log->usdr == 0) ? "A" : "B"),log->uusr);
printf("%s %s\n",log->progr,log->parms);
if (!lst && !(u % 20)) {
printf("(more)");
while (!(ch = getc(0)))
/* wait for direct console keystroke */
;
printf("\008\008\008\008\008\008");
if (ch == 3 || ch == 27) break; /* long list */
}
}
}
OFFscript();
} /* end: listit */
getu( p,len ) char *p; int len; {
gets(p,len);
while (*p) *p = toupper(*p++);
} /* end: getu */
sort() {
static struct users *p,*q; static int i, j;
for (i = 0; i < MAXUSERS-1; i++)
for (j = i+1; j < MAXUSERS; j++) {
p = login[i];
q = login[j];
if (strcmp(p->uname,q->uname) > 0) {
login[i] = q;
login[j] = p;
}
}
} /* end: sort */