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 >
Text File  |  1982-12-17  |  13KB  |  667 lines

  1.  opt pag,nol
  2.  ttl UniFLEX init task (task 1)
  3.  pag
  4.  lib sysdef
  5.  opt lis
  6.  pag
  7.  
  8.  info UniFLEX init system
  9.  info Version 1.03, Released January 15, 1983
  10.  info Copyright, (C) 1982, by
  11.  info Technical Systems Consultants, Inc.
  12.  info All rights reserved.
  13.  
  14. *
  15. * This task is executed after system initialization.
  16. * Task 0 is the scheduler, and 'init' is task 1.  Its
  17. * main purpose is to read the ttys file and start
  18. * the loggin task for each terminal listed in the file.
  19. *
  20.  
  21.  
  22. *
  23. * constants
  24. *
  25.  
  26. DFALT equ 0 default interrupt mode
  27. IGNORE equ 1 ignore interrupt for 'cpint'
  28. HANGS equ 1 hangup interrupt for 'cpint'
  29. KILLS equ 5 kill job interrupt
  30. ALRMI equ 10 alarm interrupt
  31. UTPRM equ %00001011 utmp file permissions for create
  32. READ equ 0 read mode for open
  33. RW equ 2 read/write mode for open
  34. UNFILS equ 16 number of possible task files
  35. TTYS equ 32 max number of terminals
  36. TTPRM equ %00010011 perms for tty open
  37. CR equ $d carriage return
  38. RBUFS equ 512 read line buffer size
  39.  
  40. *
  41. * structure definitions
  42. *
  43.  
  44. * struct ttab
  45.  
  46.  org 0
  47.  
  48. trmnm rmb 2 2 character terminal name
  49. tstyp rmb 1 ttyset parameter
  50. ttid rmb 2 task id started with this tty
  51.  
  52. TIBSIZ equ * structure size
  53.  
  54.  
  55. * struct linbuf
  56.  
  57.  org 0
  58.  
  59. lacpt rmb 1 accept flag (should be '1)
  60. lstyp rmb 1 ttyset parameter
  61. ltnam rmb 2 terminal name
  62. lterm rmb 1 line terminator ($D)
  63.  
  64. LINSIZ equ * structure size
  65.  
  66.  
  67.  pag
  68. *
  69. * Program entry here
  70. *
  71.  
  72.  org 0
  73. init ldx #mykey mark for key install program
  74.  sys gtid get task id
  75.  cmpd #1 if not 1 - terminate
  76.  bne init8
  77.  sys cpint,HANGS,IGNORE ignore hangup interrupt
  78.  sys cpint,ALRMI,aupdt set for auto update
  79.  ldd #30
  80.  sys alarm
  81.  ldd #('b<<8)|'t setup 'bt' for boot
  82.  lbsr uphf update history file
  83. init0 ldd #-1 kill all tasks
  84.  sys spint,KILLS
  85.  ldx #ttab point to terminal table
  86. init1 clr 0,x+ zero it out
  87.  cmpx #ttend end of table?
  88.  bne init1 loop til done
  89.  clr bdflag set bring down flag
  90.  sys sacct,0 turn off accounting
  91. init2 ldd #('s<<8)|'u setup 'su'
  92.  lbsr uphf update history file
  93.  lbsr single execute single user mode
  94.  tst bdflag bring system down?
  95.  bne down
  96.  jsr key go check key
  97.  bne init0
  98.  ldd #('m<<8)|'u setup 'mu' for multi-user mode
  99.  lbsr uphf update history file
  100.  sys fork fork a new task
  101.  bra runst new guy branch ahead
  102.  pshs d save task id
  103. init4 sys wait wait for new task
  104.  bes init4
  105.  cmpd 0,s is this the one?
  106.  bne init4 if not, wait again
  107.  puls d reset stack
  108.  bra iloop go to main loop
  109. init8 ldd #255 term init
  110.  sys term
  111.  
  112. *
  113. * runst
  114. *
  115. * Run the system startup file thru the shell.
  116. *
  117.  
  118. runst sys cpint,ALRMI,DFALT
  119.  sys open,root,READ open the root
  120.  ldd #0 set file desc 0
  121.  sys dup dup file
  122.  ldd #0
  123.  sys dup
  124.  sys exec,shell,starg exec the shell with startup file
  125.  sys term if here, error!
  126.  
  127. *
  128. * down
  129. *
  130. * Bring system down.
  131. *
  132.  
  133. down sys cpint,ALRMI,DFALT
  134.  lbsr kilal kill all jobs
  135.  ldd #('s<<8)|'t set up 'st' for stop
  136.  lbsr uphf update history file
  137.  ldd #-1 kill all tasks
  138.  sys spint,KILLS
  139.  sys sacct,0 turn off accounting
  140.  sys update update disks
  141.  bra * halt!
  142.  
  143.  pag
  144.  
  145. *
  146. * iloop
  147. *
  148. * This is the main processing loop of init.
  149. *
  150.  
  151. iloop sys cpint,HANGS,reset
  152.  ldd #0 prepare to close all files
  153.  pshs d save count
  154. iloop2 sys close close a file
  155.  ldd 0,s get count
  156.  addd #1 bump to next file
  157.  std 0,s save new
  158.  cmpd #UNFILS last file?
  159.  bne iloop2
  160.  puls d get count
  161.  sys open,ttyf,READ open ttys file
  162.  std ttfd save descriptor
  163.  ldd #rdbuf init read line ptrs
  164.  std rbfbeg
  165.  std rbfend
  166.  ldx #ttab point to tty table
  167. iloop4 pshs x save entry
  168.  lbsr rdline read a tty file line
  169.  puls x
  170.  beq iloop6 finished?
  171.  lda linbuf+lacpt an accepted line?
  172.  cmpa #'+ is it not '+'?
  173.  bne iloop4 if so, skip it
  174.  ldd linbuf+ltnam get tty name
  175.  std trmnm,x save in table
  176.  lda linbuf+lstyp get ttyset parameter
  177.  sta tstyp,x save in table
  178.  leax TIBSIZ,x bump to next entry
  179.  bra iloop4 repeat
  180. iloop6 ldd ttfd get file descriptor
  181.  sys close close the tty file
  182.  ldx #ttab point to terminal table just built
  183. iloo65 ldd trmnm,x get tty name
  184.  beq iloop7 is it null?
  185.  lbsr mkjob go create task
  186. iloop7 leax TIBSIZ,x bump to next entry
  187.  cmpx #ttend end of table?
  188.  bne iloo65 repeat?
  189. iloop8 sys wait wait for a task to terminate
  190.  bes iloop8
  191.  pshs x
  192.  ldx #ttab point to terminal table
  193. iloo85 cmpd ttid,x look for task id
  194.  beq iloop9 does it match?
  195.  leax TIBSIZ,x move to next entry
  196.  cmpx #ttend end of list?
  197.  bne iloo85 if not, repeat
  198.  puls x
  199.  bra iloop8 if so, go wait again
  200. iloop9 lbsr kiljb kill off the tasks tty
  201.  puls d
  202.  cmpd #8
  203.  beq iloop8
  204.  lbsr mkjob go make new tty task
  205.  bra iloop8 go wait again
  206.  
  207.  
  208. *
  209. * rdline
  210. *
  211. * Read a line from the 'ttylist' file and enter
  212. * the data in the tty table.
  213. *
  214.  
  215. rdline ldx #linbuf point to line buffer
  216.  ldb #LINSIZ set size count
  217. rdlin2 jsr rlgetc get a character
  218.  beq rdlin4 error?
  219.  sta 0,x+ save in buffer
  220.  decb dec the count
  221.  bne rdlin2 repeat?
  222.  cmpa #CR is it cr term?
  223.  beq rdlin3
  224.  cmpa #': is it ':' term?
  225.  bne rdlin4 if not - error
  226. rdli25 jsr rlgetc get character
  227.  beq rdlin4 error?
  228.  cmpa #CR look for cr
  229.  bne rdli25
  230. rdlin3 clz set ok status
  231.  rts return
  232. rdlin4 sez set error status
  233.  rts return
  234.  
  235. *
  236. * single
  237. *
  238. * Run a single user shell (initial system is single
  239. * usr only).
  240. *
  241.  
  242. single lbsr kilal kill all other jobs
  243.  sys fork fork a task
  244.  bra singl4 ne jump ahead
  245.  pshs d save new task id
  246. singl2 sys wait wait for job
  247.  bes singl2
  248.  cmpd 0,s right one term'd?
  249.  bne singl2
  250.  tfr x,d get status
  251.  cmpa #KILLS was it killed?
  252.  bne singl3
  253.  inc bdflag set down flag
  254. singl3 puls d,pc return
  255. singl4 sys cpint,ALRMI,DFALT
  256.  sys open,ctty,RW open console term
  257.  ldd #0 duplicate the file
  258.  sys dup
  259.  ldd #0
  260.  sys dup
  261.  sys create,utmp,UTPRM create user file
  262.  sys close close the file
  263.  sys exec,shell,sharg execute the shell
  264.  sys term term if error
  265.  
  266.  pag
  267. *
  268. * mkjob
  269. *
  270. * Make a new task for the terminal name specified
  271. * in the table entry pointed at by X.
  272. *
  273.  
  274. mkjob ldd trmnm,x get term name
  275.  std mttnm set in device name
  276.  sys fork fork a new task
  277.  bra mkjob2 if new guy, jump ahead
  278.  std ttid,x save task id
  279.  rts return
  280. mkjob2 sys cpint,HANGS,DFALT reset hangs interrupt
  281.  sys cpint,ALRMI,DFALT
  282.  sys chown,mktty,0 change owner to 0
  283.  bes mkjob8
  284.  sys chprm,mktty,TTPRM set perms for tty
  285.  bes mkjob8
  286.  sys open,mktty,RW open terminal
  287.  bes mkjob8
  288.  ldd #0 duplicate the open term
  289.  sys dup
  290.  sys exec,login,lgarg execute the login program
  291. mkjob8 sys term if error
  292.  
  293. *
  294. * kiljb
  295. *
  296. * Terminate the job whose entry is pointed at by X.
  297. *
  298.  
  299. kiljb pshs x save pointer
  300.  ldd ttid,x get task id
  301.  beq kiljb4 if null, already killed!
  302.  lbsr upduf update login file
  303.  ldx 0,s get table entry
  304.  ldd trmnm,x get terminal name
  305.  lbsr uphf update history file
  306.  ldx 0,s point to entry
  307.  ldd ttid,x get id
  308.  sys spint,KILLS kill job
  309. kiljb4 puls x reset entry pointer
  310.  ldd #0 set null word
  311.  std ttid,x zero task id
  312.  rts return
  313.  
  314. *
  315. * kilal
  316. *
  317. * Kill all active jobs.
  318. *
  319.  
  320. kilal ldx #ttab point to term table
  321. kilal2 bsr kiljb kill this job
  322.  leax TIBSIZ,x bump to next entry
  323.  cmpx #ttend end ot table?
  324.  bne kilal2 if not, repeat
  325.  rts return
  326.  pag
  327.  
  328. *
  329. * Get a character for read line
  330. *
  331.  
  332. rlgetc pshs x,b save regs
  333.  ldx rbfbeg get start ptr
  334.  cmpx rbfend empty list?
  335.  bne rlget4
  336.  ldd ttfd get file desc
  337.  sys read,rdbuf,RBUFS fill buffer
  338.  bes rlget6 error?
  339.  cmpd #0 end of file?
  340.  beq rlget6
  341.  ldx #rdbuf reset pointers
  342.  stx rbfbeg
  343.  leax d,x find end of buffer
  344.  stx rbfend mark it
  345.  ldx #rdbuf point to 1st char
  346. rlget4 lda 0,x+ get a character
  347.  stx rbfbeg set new start
  348.  puls x,b,pc return
  349. rlget6 sez set error status
  350.  puls x,b,pc return
  351.  
  352. *
  353. * upduf
  354. *
  355. * Update the act/utmp file with this user
  356. *
  357.  
  358. upduf pshs x save entry ptr
  359.  sys open,utmp,1 open the file
  360.  bes upduf6 if error, skip
  361.  pshs d save file desc
  362.  ldx 2,s get entry ptr
  363.  ldd trmnm,x get term name
  364.  anda #$f mask low 4 bits
  365.  andb #$f of each char
  366.  asla hi byte times 10
  367.  pshs a
  368.  asla
  369.  asla
  370.  asla
  371.  adda 0,s result now x10
  372.  sta 0,s save result
  373.  addb 0,s+ add in low byte
  374.  clra clear hi byte
  375.  aslb now x16
  376.  rola
  377.  aslb
  378.  rola
  379.  aslb
  380.  rola
  381.  aslb
  382.  rola
  383.  std isk2 save in seek call
  384.  ldd 0,s get file desc
  385.  sys ind,isk seek in file
  386.  ldd 0,s get file desc
  387.  sys write,nulls,16 zero out entry
  388.  puls d get file desc
  389.  sys close close the file
  390. upduf6 puls x,pc return
  391.  
  392. *
  393. * reset
  394. *
  395. * Reset system
  396. *
  397.  
  398. reset ldd #init0 reset the pc
  399.  std 10,s on stack
  400.  rti do it!
  401.  
  402. * do auto update
  403.  
  404. aupdt sys update do update
  405.  sys cpint,ALRMI,aupdt
  406.  ldd #30
  407.  sys alarm
  408.  rti return
  409.  
  410.  pag
  411.  
  412. *
  413. * uphf
  414. *
  415. * Update the history file (/act/history).
  416. *
  417.  
  418. uphf std uphbuf save name
  419.  sys open,hisf,1 open file for write
  420.  bes uphf4 if error - exit
  421.  pshs d save file desc
  422.  sys time,uphtim get time
  423.  ldd 0,s get file desc
  424.  sys seek,0,0,2 seek to eof
  425.  ldd 0,s get file desc
  426.  sys write,uphbuf,16 write out entry
  427.  puls d get file desc
  428.  sys close close the file
  429. uphf4 rts return
  430.  
  431. *
  432. * check key for multi-user use
  433. *
  434.  
  435. key ldx #hiskey point to his key
  436.  ldu #mykey point to my key
  437.  lda 0,x is his null?
  438.  beq key2
  439.  jsr tstkey is key valid?
  440.  beq key6 if so - return
  441. key2 sys open,ctty,2 open console
  442.  jsr getkey get key from user
  443.  jsr tstkey is key valid?
  444.  beq key5 if so - return
  445.  ldx #nogoms point to no go message
  446.  ldb #NOGOSZ get size of message
  447. key4 com 0,x+ fix for printing
  448.  decb
  449.  bne key4
  450.  ldd #0 set file desc
  451.  sys write,nogoms,NOGOSZ print message
  452.  jmp down take system down
  453. key5 ldd #0 close console
  454.  sys close
  455.  clz set status
  456. key6 rts return
  457.  
  458. *
  459. * test for valid key
  460. *
  461.  
  462. tstkey ldu #hiskey get his key
  463.  ldx #crpkey point to buffer
  464.  pshs x,u
  465.  jsr crypt do it
  466.  leas 4,s fix stack
  467.  ldx #crpkey fix key in place
  468.  ldb #8 set count
  469. tstke0 lda 0,x
  470.  anda #$1f mask bits
  471.  cmpa #25
  472.  bls tstke1
  473.  suba #26
  474.  asla
  475.  asla
  476. tstke1 adda #'a
  477.  sta 0,x+
  478.  decb
  479.  bne tstke0
  480.  ldx #crpkey
  481.  ldu #mykey get my key
  482.  ldb #8 set count for compare
  483. tstke2 lda 0,x+ do compare
  484.  cmpa 0,u+
  485.  bne tstke6
  486.  decb dec the count
  487.  bne tstke2
  488. tstke6 rts return
  489.  
  490. *
  491. * get key from user
  492. *
  493.  
  494. getkey ldx #keymsg fix message for printing
  495.  ldb #KEYMSZ
  496. getke2 com 0,x+
  497.  decb
  498.  bne getke2
  499.  ldd #0 set file desc
  500.  sys write,keymsg,KEYMSZ write message
  501.  ldd #0 set file desc
  502.  sys read,rdbuf,32 get response
  503.  cmpd #1 any there?
  504.  bls getke6
  505.  ldu #rdbuf-1 point to response
  506.  clr d,u set null term
  507.  leau 1,u
  508. getke3 ldx #hiskey point to his key area
  509.  ldb #8 set count
  510. getke4 lda 0,u+ move key
  511.  sta 0,x+
  512.  decb
  513.  bne getke4
  514.  clr 0,x set null term
  515.  jsr wrthis write out to file
  516.  ldx #keymsg fix up key message
  517.  ldb #KEYMSZ
  518. getke5 com 0,x+
  519.  decb
  520.  bne getke5
  521.  rts return
  522. getke6 lda #'A set up bogus key
  523.  ldb #8
  524.  ldx #rdbuf
  525. getke7 sta 0,x+
  526.  decb
  527.  bne getke7
  528.  ldu #rdbuf
  529.  bra getke3
  530.  
  531. *
  532. * write key to init file
  533. *
  534.  
  535. wrthis sys open,infil,2
  536.  bes wrthi4 error?
  537.  pshs d save file desc
  538.  sys seek,0,hiskey+28,0
  539.  bes wrthi2 error?
  540.  ldd 0,s get fd
  541.  sys write,hiskey,8 write to file
  542. wrthi2 ldd 0,s get fd
  543.  sys close close file
  544.  sys update
  545.  puls d clean stack
  546. wrthi4 rts return
  547.  
  548. **   CRYPT - ENCRYPT PASSWORD.
  549. *
  550. *    ENTRY (2,S)=POINTER TO 8 BYTE RESPONSE AREA
  551. *          (4,S)=POINTER TO PASSWORD, TERMINATED BY
  552. *                A ZERO BYTE
  553.  SPC 2
  554. crypt LDX 2,S (X)=ADDRESS OF RESPONSE AREA
  555.  LDY 4,S (Y)=ADDRESS OF PASSWORD
  556.  LDA #251 SET LOOP COUNTER
  557.  PSHS A
  558.  LEAS -8,S RESERVE WORK SPACE
  559.  CLRB (B)=INDEX/COUNTER
  560.  
  561. *   COPY PASSWORD TO RESPONSE AND WORK AREAS.
  562.  
  563. crypt1 LDA 0,Y+
  564.  BNE crypt2 IF NOT END OF PASSWORD
  565.  LEAY -1,Y BACK UP POINTER
  566. crypt2 STA B,X STORE IN RESPONSE AREA
  567.  STA B,S STORE IN WORK AREA
  568.  INCB COUNT CHARACTER
  569.  CMPB #8
  570.  BLO crypt1 LOOP FOR 8 BYTES
  571.  
  572. *    TAUSWORTHE RANDOM NUMBER GENERATOR.
  573. *    ADAPTED FROM THE ALGORITHM OF E. J. WATSON,
  574. *    UNIVERSITY OF MANCHESTER.
  575. *    ALGORITHM DOCUMENTED IN CACM, VOL 11, NO. 9, SEPT, 1968
  576. *    P. 643.
  577. *    VALUES USED: N=63, M=31
  578. *    TO BE CONSISTENT WITH ALGORITHM, BITS NUMBERS ARE FROM
  579. *    LEFT TO RIGHT, STARTING AT ZERO.
  580.  
  581. crypt4 LDA 4,S PUT BIT 32 IN CARRY
  582.  LSLA
  583.  LDD 2,S (D)=BITS 16-31
  584.  ROLB
  585.  ROLA (D)=BITS 17-32, CARRY=BIT 16
  586.  EORB 7,S BITS 17-32 XOR BITS 48-63
  587.  EORA 6,S
  588.  STD 6,S REPLACE BITS 48-63
  589.  EORB 3,S NEW 48-64 XOR BITS 16-31
  590.  EORA 2,S
  591.  STD 2,S REPLACE BITS 16-31
  592.  LDD 0,S (D)=BITS 0-15
  593.  ROLB
  594.  ROLA (D)=BITS 1-16
  595.  EORB 5,S BITS 1-16 XOR BITS 32-47
  596.  EORA 4,S
  597.  STD 4,S REPLACE BITS 32-47
  598.  EORB 1,S NEW 32-47 XOR BITS 0-15
  599.  EORA 0,S
  600.  STD 0,S REPLACE BITS 0-15
  601.  DEC 8,S COUNT ITERATION
  602.  BNE crypt4 REPEAT 8 TIMES
  603.  LDB #7 (B)=BYTE COUNTER
  604.  ANDCC #$FE CLEAR CARRY
  605. crypt5 LDA B,S ADD BACK ORIGINAL PASSWORD
  606.  ADCA B,X
  607.  STA B,X
  608.  DECB
  609.  BPL crypt5
  610.  LEAS 9,S CLEAN UP STACK
  611.  RTS RETURN
  612.  
  613.  pag
  614.  
  615. *
  616. * data constants
  617. *
  618.  
  619. mykey fcc 'tiblbtkf',0
  620. hiskey fcb 0,0,0,0,0,0,0,0,0
  621. crpkey fcc 'abcdefgh',0
  622. keymsg fcb !$d,!'I,!'n,!'v,!'a,!'l,!'i,!'d,!' ,!'k,!'e,!'y,!' ,!'-
  623.  fcb !' ,!'e,!'n,!'t,!'e,!'r,!' ,!'k,!'e,!'y,!':,!$20
  624. KEYMSZ equ *-keymsg
  625. nogoms fcb !'B,!'a,!'d,!' ,!'k,!'e,!'y,!'.,!$d
  626. NOGOSZ equ *-nogoms
  627. infil fcc '/etc/init',0
  628. root fcc '/',0
  629. utmp fcc '/act/utmp',0
  630. hisf fcc '/act/history',0
  631. shell fcc '/bin/shell',0
  632. startup fcc '/etc/startup',0
  633. ctty fcc '/dev/tty00',0
  634. sharg fdb shnm,0
  635. shnm fcc 'shell',0
  636. login fcc '/etc/login',0
  637. lgarg fdb lgnm,0
  638. lgnm fcc 'login',0
  639. mktty fcc '/dev/tty'
  640. mttnm fdb 0,0
  641. starg fdb shnm2,strnm,0
  642. shnm2 fcc 'shell',0
  643. strnm fcc '/etc/startup',0
  644. ttyf fcc '/etc/ttylist',0
  645. nulls fdb 0,0,0,0,0,0,0,0 null entry
  646. uphbuf fdb 0,0,0,0,0,0 buffer for history updates
  647. uphtim fdb 0,0,0,0 time for history
  648.  
  649. *
  650. * data section
  651. *
  652.  
  653. isk fcb seek ind seek call
  654.  fdb 0
  655. isk2 fdb 0,0
  656. bdflag fcb 0 bring down flag
  657. rbfbeg rmb 2 buffer ptr
  658. rbfend rmb 2
  659. ttfd rmb 2 open file descriptor
  660. linbuf rmb LINSIZ line buffer
  661. ttab rmb TTYS*TIBSIZ terminal table
  662. ttend equ * end of table
  663. rdbuf rmb RBUFS read line buffer
  664.  
  665.  
  666.  end
  667.