home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
UNIFLEX
/
UNIFLEX
/
UniFLEX_Std.Utils1.tar.Z
/
UniFLEX_Std.Utils1.tar
/
utils1
/
keyinit
< prev
next >
Wrap
Text File
|
1982-12-17
|
13KB
|
667 lines
opt pag,nol
ttl UniFLEX init task (task 1)
pag
lib sysdef
opt lis
pag
info UniFLEX init system
info Version 1.03, Released January 15, 1983
info Copyright, (C) 1982, by
info Technical Systems Consultants, Inc.
info All rights reserved.
*
* This task is executed after system initialization.
* Task 0 is the scheduler, and 'init' is task 1. Its
* main purpose is to read the ttys file and start
* the loggin task for each terminal listed in the file.
*
*
* constants
*
DFALT equ 0 default interrupt mode
IGNORE equ 1 ignore interrupt for 'cpint'
HANGS equ 1 hangup interrupt for 'cpint'
KILLS equ 5 kill job interrupt
ALRMI equ 10 alarm interrupt
UTPRM equ %00001011 utmp file permissions for create
READ equ 0 read mode for open
RW equ 2 read/write mode for open
UNFILS equ 16 number of possible task files
TTYS equ 32 max number of terminals
TTPRM equ %00010011 perms for tty open
CR equ $d carriage return
RBUFS equ 512 read line buffer size
*
* structure definitions
*
* struct ttab
org 0
trmnm rmb 2 2 character terminal name
tstyp rmb 1 ttyset parameter
ttid rmb 2 task id started with this tty
TIBSIZ equ * structure size
* struct linbuf
org 0
lacpt rmb 1 accept flag (should be '1)
lstyp rmb 1 ttyset parameter
ltnam rmb 2 terminal name
lterm rmb 1 line terminator ($D)
LINSIZ equ * structure size
pag
*
* Program entry here
*
org 0
init ldx #mykey mark for key install program
sys gtid get task id
cmpd #1 if not 1 - terminate
bne init8
sys cpint,HANGS,IGNORE ignore hangup interrupt
sys cpint,ALRMI,aupdt set for auto update
ldd #30
sys alarm
ldd #('b<<8)|'t setup 'bt' for boot
lbsr uphf update history file
init0 ldd #-1 kill all tasks
sys spint,KILLS
ldx #ttab point to terminal table
init1 clr 0,x+ zero it out
cmpx #ttend end of table?
bne init1 loop til done
clr bdflag set bring down flag
sys sacct,0 turn off accounting
init2 ldd #('s<<8)|'u setup 'su'
lbsr uphf update history file
lbsr single execute single user mode
tst bdflag bring system down?
bne down
jsr key go check key
bne init0
ldd #('m<<8)|'u setup 'mu' for multi-user mode
lbsr uphf update history file
sys fork fork a new task
bra runst new guy branch ahead
pshs d save task id
init4 sys wait wait for new task
bes init4
cmpd 0,s is this the one?
bne init4 if not, wait again
puls d reset stack
bra iloop go to main loop
init8 ldd #255 term init
sys term
*
* runst
*
* Run the system startup file thru the shell.
*
runst sys cpint,ALRMI,DFALT
sys open,root,READ open the root
ldd #0 set file desc 0
sys dup dup file
ldd #0
sys dup
sys exec,shell,starg exec the shell with startup file
sys term if here, error!
*
* down
*
* Bring system down.
*
down sys cpint,ALRMI,DFALT
lbsr kilal kill all jobs
ldd #('s<<8)|'t set up 'st' for stop
lbsr uphf update history file
ldd #-1 kill all tasks
sys spint,KILLS
sys sacct,0 turn off accounting
sys update update disks
bra * halt!
pag
*
* iloop
*
* This is the main processing loop of init.
*
iloop sys cpint,HANGS,reset
ldd #0 prepare to close all files
pshs d save count
iloop2 sys close close a file
ldd 0,s get count
addd #1 bump to next file
std 0,s save new
cmpd #UNFILS last file?
bne iloop2
puls d get count
sys open,ttyf,READ open ttys file
std ttfd save descriptor
ldd #rdbuf init read line ptrs
std rbfbeg
std rbfend
ldx #ttab point to tty table
iloop4 pshs x save entry
lbsr rdline read a tty file line
puls x
beq iloop6 finished?
lda linbuf+lacpt an accepted line?
cmpa #'+ is it not '+'?
bne iloop4 if so, skip it
ldd linbuf+ltnam get tty name
std trmnm,x save in table
lda linbuf+lstyp get ttyset parameter
sta tstyp,x save in table
leax TIBSIZ,x bump to next entry
bra iloop4 repeat
iloop6 ldd ttfd get file descriptor
sys close close the tty file
ldx #ttab point to terminal table just built
iloo65 ldd trmnm,x get tty name
beq iloop7 is it null?
lbsr mkjob go create task
iloop7 leax TIBSIZ,x bump to next entry
cmpx #ttend end of table?
bne iloo65 repeat?
iloop8 sys wait wait for a task to terminate
bes iloop8
pshs x
ldx #ttab point to terminal table
iloo85 cmpd ttid,x look for task id
beq iloop9 does it match?
leax TIBSIZ,x move to next entry
cmpx #ttend end of list?
bne iloo85 if not, repeat
puls x
bra iloop8 if so, go wait again
iloop9 lbsr kiljb kill off the tasks tty
puls d
cmpd #8
beq iloop8
lbsr mkjob go make new tty task
bra iloop8 go wait again
*
* rdline
*
* Read a line from the 'ttylist' file and enter
* the data in the tty table.
*
rdline ldx #linbuf point to line buffer
ldb #LINSIZ set size count
rdlin2 jsr rlgetc get a character
beq rdlin4 error?
sta 0,x+ save in buffer
decb dec the count
bne rdlin2 repeat?
cmpa #CR is it cr term?
beq rdlin3
cmpa #': is it ':' term?
bne rdlin4 if not - error
rdli25 jsr rlgetc get character
beq rdlin4 error?
cmpa #CR look for cr
bne rdli25
rdlin3 clz set ok status
rts return
rdlin4 sez set error status
rts return
*
* single
*
* Run a single user shell (initial system is single
* usr only).
*
single lbsr kilal kill all other jobs
sys fork fork a task
bra singl4 ne jump ahead
pshs d save new task id
singl2 sys wait wait for job
bes singl2
cmpd 0,s right one term'd?
bne singl2
tfr x,d get status
cmpa #KILLS was it killed?
bne singl3
inc bdflag set down flag
singl3 puls d,pc return
singl4 sys cpint,ALRMI,DFALT
sys open,ctty,RW open console term
ldd #0 duplicate the file
sys dup
ldd #0
sys dup
sys create,utmp,UTPRM create user file
sys close close the file
sys exec,shell,sharg execute the shell
sys term term if error
pag
*
* mkjob
*
* Make a new task for the terminal name specified
* in the table entry pointed at by X.
*
mkjob ldd trmnm,x get term name
std mttnm set in device name
sys fork fork a new task
bra mkjob2 if new guy, jump ahead
std ttid,x save task id
rts return
mkjob2 sys cpint,HANGS,DFALT reset hangs interrupt
sys cpint,ALRMI,DFALT
sys chown,mktty,0 change owner to 0
bes mkjob8
sys chprm,mktty,TTPRM set perms for tty
bes mkjob8
sys open,mktty,RW open terminal
bes mkjob8
ldd #0 duplicate the open term
sys dup
sys exec,login,lgarg execute the login program
mkjob8 sys term if error
*
* kiljb
*
* Terminate the job whose entry is pointed at by X.
*
kiljb pshs x save pointer
ldd ttid,x get task id
beq kiljb4 if null, already killed!
lbsr upduf update login file
ldx 0,s get table entry
ldd trmnm,x get terminal name
lbsr uphf update history file
ldx 0,s point to entry
ldd ttid,x get id
sys spint,KILLS kill job
kiljb4 puls x reset entry pointer
ldd #0 set null word
std ttid,x zero task id
rts return
*
* kilal
*
* Kill all active jobs.
*
kilal ldx #ttab point to term table
kilal2 bsr kiljb kill this job
leax TIBSIZ,x bump to next entry
cmpx #ttend end ot table?
bne kilal2 if not, repeat
rts return
pag
*
* Get a character for read line
*
rlgetc pshs x,b save regs
ldx rbfbeg get start ptr
cmpx rbfend empty list?
bne rlget4
ldd ttfd get file desc
sys read,rdbuf,RBUFS fill buffer
bes rlget6 error?
cmpd #0 end of file?
beq rlget6
ldx #rdbuf reset pointers
stx rbfbeg
leax d,x find end of buffer
stx rbfend mark it
ldx #rdbuf point to 1st char
rlget4 lda 0,x+ get a character
stx rbfbeg set new start
puls x,b,pc return
rlget6 sez set error status
puls x,b,pc return
*
* upduf
*
* Update the act/utmp file with this user
*
upduf pshs x save entry ptr
sys open,utmp,1 open the file
bes upduf6 if error, skip
pshs d save file desc
ldx 2,s get entry ptr
ldd trmnm,x get term name
anda #$f mask low 4 bits
andb #$f of each char
asla hi byte times 10
pshs a
asla
asla
asla
adda 0,s result now x10
sta 0,s save result
addb 0,s+ add in low byte
clra clear hi byte
aslb now x16
rola
aslb
rola
aslb
rola
aslb
rola
std isk2 save in seek call
ldd 0,s get file desc
sys ind,isk seek in file
ldd 0,s get file desc
sys write,nulls,16 zero out entry
puls d get file desc
sys close close the file
upduf6 puls x,pc return
*
* reset
*
* Reset system
*
reset ldd #init0 reset the pc
std 10,s on stack
rti do it!
* do auto update
aupdt sys update do update
sys cpint,ALRMI,aupdt
ldd #30
sys alarm
rti return
pag
*
* uphf
*
* Update the history file (/act/history).
*
uphf std uphbuf save name
sys open,hisf,1 open file for write
bes uphf4 if error - exit
pshs d save file desc
sys time,uphtim get time
ldd 0,s get file desc
sys seek,0,0,2 seek to eof
ldd 0,s get file desc
sys write,uphbuf,16 write out entry
puls d get file desc
sys close close the file
uphf4 rts return
*
* check key for multi-user use
*
key ldx #hiskey point to his key
ldu #mykey point to my key
lda 0,x is his null?
beq key2
jsr tstkey is key valid?
beq key6 if so - return
key2 sys open,ctty,2 open console
jsr getkey get key from user
jsr tstkey is key valid?
beq key5 if so - return
ldx #nogoms point to no go message
ldb #NOGOSZ get size of message
key4 com 0,x+ fix for printing
decb
bne key4
ldd #0 set file desc
sys write,nogoms,NOGOSZ print message
jmp down take system down
key5 ldd #0 close console
sys close
clz set status
key6 rts return
*
* test for valid key
*
tstkey ldu #hiskey get his key
ldx #crpkey point to buffer
pshs x,u
jsr crypt do it
leas 4,s fix stack
ldx #crpkey fix key in place
ldb #8 set count
tstke0 lda 0,x
anda #$1f mask bits
cmpa #25
bls tstke1
suba #26
asla
asla
tstke1 adda #'a
sta 0,x+
decb
bne tstke0
ldx #crpkey
ldu #mykey get my key
ldb #8 set count for compare
tstke2 lda 0,x+ do compare
cmpa 0,u+
bne tstke6
decb dec the count
bne tstke2
tstke6 rts return
*
* get key from user
*
getkey ldx #keymsg fix message for printing
ldb #KEYMSZ
getke2 com 0,x+
decb
bne getke2
ldd #0 set file desc
sys write,keymsg,KEYMSZ write message
ldd #0 set file desc
sys read,rdbuf,32 get response
cmpd #1 any there?
bls getke6
ldu #rdbuf-1 point to response
clr d,u set null term
leau 1,u
getke3 ldx #hiskey point to his key area
ldb #8 set count
getke4 lda 0,u+ move key
sta 0,x+
decb
bne getke4
clr 0,x set null term
jsr wrthis write out to file
ldx #keymsg fix up key message
ldb #KEYMSZ
getke5 com 0,x+
decb
bne getke5
rts return
getke6 lda #'A set up bogus key
ldb #8
ldx #rdbuf
getke7 sta 0,x+
decb
bne getke7
ldu #rdbuf
bra getke3
*
* write key to init file
*
wrthis sys open,infil,2
bes wrthi4 error?
pshs d save file desc
sys seek,0,hiskey+28,0
bes wrthi2 error?
ldd 0,s get fd
sys write,hiskey,8 write to file
wrthi2 ldd 0,s get fd
sys close close file
sys update
puls d clean stack
wrthi4 rts return
** CRYPT - ENCRYPT PASSWORD.
*
* ENTRY (2,S)=POINTER TO 8 BYTE RESPONSE AREA
* (4,S)=POINTER TO PASSWORD, TERMINATED BY
* A ZERO BYTE
SPC 2
crypt LDX 2,S (X)=ADDRESS OF RESPONSE AREA
LDY 4,S (Y)=ADDRESS OF PASSWORD
LDA #251 SET LOOP COUNTER
PSHS A
LEAS -8,S RESERVE WORK SPACE
CLRB (B)=INDEX/COUNTER
* COPY PASSWORD TO RESPONSE AND WORK AREAS.
crypt1 LDA 0,Y+
BNE crypt2 IF NOT END OF PASSWORD
LEAY -1,Y BACK UP POINTER
crypt2 STA B,X STORE IN RESPONSE AREA
STA B,S STORE IN WORK AREA
INCB COUNT CHARACTER
CMPB #8
BLO crypt1 LOOP FOR 8 BYTES
* TAUSWORTHE RANDOM NUMBER GENERATOR.
* ADAPTED FROM THE ALGORITHM OF E. J. WATSON,
* UNIVERSITY OF MANCHESTER.
* ALGORITHM DOCUMENTED IN CACM, VOL 11, NO. 9, SEPT, 1968
* P. 643.
* VALUES USED: N=63, M=31
* TO BE CONSISTENT WITH ALGORITHM, BITS NUMBERS ARE FROM
* LEFT TO RIGHT, STARTING AT ZERO.
crypt4 LDA 4,S PUT BIT 32 IN CARRY
LSLA
LDD 2,S (D)=BITS 16-31
ROLB
ROLA (D)=BITS 17-32, CARRY=BIT 16
EORB 7,S BITS 17-32 XOR BITS 48-63
EORA 6,S
STD 6,S REPLACE BITS 48-63
EORB 3,S NEW 48-64 XOR BITS 16-31
EORA 2,S
STD 2,S REPLACE BITS 16-31
LDD 0,S (D)=BITS 0-15
ROLB
ROLA (D)=BITS 1-16
EORB 5,S BITS 1-16 XOR BITS 32-47
EORA 4,S
STD 4,S REPLACE BITS 32-47
EORB 1,S NEW 32-47 XOR BITS 0-15
EORA 0,S
STD 0,S REPLACE BITS 0-15
DEC 8,S COUNT ITERATION
BNE crypt4 REPEAT 8 TIMES
LDB #7 (B)=BYTE COUNTER
ANDCC #$FE CLEAR CARRY
crypt5 LDA B,S ADD BACK ORIGINAL PASSWORD
ADCA B,X
STA B,X
DECB
BPL crypt5
LEAS 9,S CLEAN UP STACK
RTS RETURN
pag
*
* data constants
*
mykey fcc 'tiblbtkf',0
hiskey fcb 0,0,0,0,0,0,0,0,0
crpkey fcc 'abcdefgh',0
keymsg fcb !$d,!'I,!'n,!'v,!'a,!'l,!'i,!'d,!' ,!'k,!'e,!'y,!' ,!'-
fcb !' ,!'e,!'n,!'t,!'e,!'r,!' ,!'k,!'e,!'y,!':,!$20
KEYMSZ equ *-keymsg
nogoms fcb !'B,!'a,!'d,!' ,!'k,!'e,!'y,!'.,!$d
NOGOSZ equ *-nogoms
infil fcc '/etc/init',0
root fcc '/',0
utmp fcc '/act/utmp',0
hisf fcc '/act/history',0
shell fcc '/bin/shell',0
startup fcc '/etc/startup',0
ctty fcc '/dev/tty00',0
sharg fdb shnm,0
shnm fcc 'shell',0
login fcc '/etc/login',0
lgarg fdb lgnm,0
lgnm fcc 'login',0
mktty fcc '/dev/tty'
mttnm fdb 0,0
starg fdb shnm2,strnm,0
shnm2 fcc 'shell',0
strnm fcc '/etc/startup',0
ttyf fcc '/etc/ttylist',0
nulls fdb 0,0,0,0,0,0,0,0 null entry
uphbuf fdb 0,0,0,0,0,0 buffer for history updates
uphtim fdb 0,0,0,0 time for history
*
* data section
*
isk fcb seek ind seek call
fdb 0
isk2 fdb 0,0
bdflag fcb 0 bring down flag
rbfbeg rmb 2 buffer ptr
rbfend rmb 2
ttfd rmb 2 open file descriptor
linbuf rmb LINSIZ line buffer
ttab rmb TTYS*TIBSIZ terminal table
ttend equ * end of table
rdbuf rmb RBUFS read line buffer
end