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 / login < prev    next >
Text File  |  1984-04-11  |  24KB  |  1,249 lines

  1.  opt nol
  2.  opt pag
  3.  ttl Login Program
  4.  lib sysdef
  5.  pag
  6.  opt lis
  7.  info UniFLEX login
  8.  info Version 1.05, Released April 11, 1984
  9.  info Copyright, (C) 1981, by
  10.  info Technical Systems Consultants, Inc.
  11.  info All rights reserved.
  12.  
  13. * constants
  14.  
  15. ECHO equ %00000010 echo bit
  16. LCASE equ %00001000 lower case bit
  17. CR equ $d carriage return
  18. st_siz equ 9 status size offset
  19.  
  20. * structures
  21.  
  22. * ulgtab
  23.  org 0
  24.  
  25. ul_tty rmb 2 tty name
  26. ul_nam rmb 10 user name
  27. ul_tim rmb 4 time
  28. USIZ equ *
  29.  
  30.  
  31. * login program
  32.  
  33.  org 0
  34.  
  35. login sys cpint,2,1 catch INTS
  36.  sys cpint,3,1 catch QUITS
  37.  ldd #0 set user id to 0
  38.  sta pwex
  39.  sys suid
  40.  ldd #2 close file 2
  41.  sys close
  42.  ldd #1 get standard out file desc
  43.  sys dup duplicate the file (error chan)
  44.  ldd #0 set priority bias
  45.  sys setpr
  46.  ldd #0 set file desc
  47.  sys ttyget,ttbuf
  48.  lda ttbuf get flag bits
  49.  anda #%10111110
  50.  sta ttbuf set back in buffer
  51.  ldd #0 set file desc
  52.  sys ttyset,ttbuf
  53.  lbsr gtinfo get tty & time info
  54.  ldd 0,s get arg count
  55.  cmpd #2 name present?
  56.  blo login1
  57.  inc noban do not display banner
  58.  ldx #buffer point to buffer
  59.  ldu 4,s point to name
  60. login0 lda 0,u+ xfr name to buffer
  61.  sta 0,x+
  62.  bne login0
  63.  bra logi25
  64. login1 ldx #lgmsg point to loggin message file name
  65.  lbsr prtmsg print the message
  66.  lbsr idlin output id line
  67. login2 clr ngflg clear out no good flag
  68.  clr pwex clear out password exists flag
  69.  ldd #1 set file desc 1
  70.  sys write,logst,LSZ output 'Login'
  71.  ldd #0 set file desc
  72.  sys read,buffer,32 read in response
  73.  cmpd #1 eof?
  74.  bls login2 if so, repeat
  75.  ldx #buffer-1 point to buffer start
  76.  clr d,x set null term
  77. logi25 lbsr fixcs fix upper/lower case
  78.  lbsr fndnam find login name in file
  79.  bec login3 error?
  80.  inc ngflg set no good ind
  81.  inc pwex set flag
  82. login3 tst pwex password exist?
  83.  beq login4 if not - no prompt
  84.  lda ttbuf get flags
  85.  anda #!ECHO turn off echo
  86.  sta ttbuf
  87.  ldd #0 set file desc
  88.  sys ttyset,ttbuf
  89.  ldd #1 set file desc
  90.  sys write,pswst,PSZ output 'Password'
  91.  ldd #0 set file desc
  92.  sys read,buffer,32 read response
  93.  pshs d save count
  94.  lda ttbuf get tty flags
  95.  ora #ECHO set echo on
  96.  sta ttbuf
  97.  ldd #0 set file desc
  98.  sys ttyset,ttbuf set status
  99.  ldd #1 set file desc
  100.  sys write,crst,1 write out cr
  101.  puls d get count
  102.  cmpd #0 end of file?
  103.  beq login2 repeat if so
  104.  ldx #buffer-1 point to buffer
  105.  clr d,x set null term
  106. login4 tst ngflg no good set?
  107.  lbne nogud if so, error
  108.  lbsr chkps check password
  109.  lbes nogud error?
  110.  lda noban check for banner message
  111.  bne logi45 if no banner to be printed
  112.  ldx #motd point to motd file name
  113.  lbsr prtmsg print the message
  114. logi45 lbsr getid get user id from file
  115.  lbes login2 error?
  116.  lbsr setdr set up user's dir
  117.  bec login5 error?
  118.  ldd #1 set file desc
  119.  sys write,ndrms,NDSZ write error message
  120.  sys term terminate task
  121. login5 sys time,ulgtab+ul_tim get system time
  122.  lbsr upduf update user file
  123.  ldd usrid get user id
  124.  std icho2 set up os call
  125.  sys ind,icho change tty owner
  126.  ldd usrid get user id
  127.  sys suid set user id
  128.  lbsr mkhom write home file
  129.  lda [nxtfld] program specified?
  130.  cmpa #$d if null - do shell
  131.  bne login6
  132.  lbsr chkml check for mail
  133.  sys exec,shell,args
  134.  sys term
  135. login6 ldx nxtfld get field pointer
  136.  stx subrg2 set up call
  137. login7 lda 0,x+ look for line end
  138.  cmpa #$d is it cr?
  139.  bne login7
  140.  clr -1,x set line end
  141.  sys exec,shell,subrg execute the program thru shell
  142.  sys term error?
  143.  
  144.  pag
  145.  
  146. * print file message
  147.  
  148. prtmsg stx iopn2 save file name in ind call
  149.  sys ind,iopn do file open for read (ind)
  150.  bes prtms8 error?
  151.  pshs d save file desc
  152. prtms2 ldd 0,s get file desc
  153.  sys read,buffer,32 read in file
  154.  bes prtms5 error?
  155.  std iwrt2 set count in ind call
  156.  beq prtms5
  157.  ldd #1 set file desc
  158.  sys ind,iwrt do write
  159.  bra prtms2 repeat
  160. prtms5 puls d get file desc
  161.  sys close close the file
  162. prtms8 rts return
  163.  
  164.  
  165. *
  166. * nogud
  167. *
  168. * Report incorrect login
  169. *
  170.  
  171. nogud lda ttbuf get ttyset flags
  172.  anda #!LCASE reset lower case bit
  173.  sta ttbuf
  174.  ldd #0 set file desc
  175.  sys ttyset,ttbuf reset data
  176.  ldd #1 set file desc
  177.  sys write,ngmsg,NGSZ write out message
  178.  sys time,ulgtab+ul_tim get current time
  179.  sys open,bdlgfl,1 open attempts file
  180.  bes nogud4 if error - skip this
  181.  pshs d save file desc
  182.  sys seek,0,0,2 seek to eof
  183.  ldd 0,s get file desc
  184.  sys write,ulgtab,16 make entry
  185.  puls d get file desc
  186.  sys close close the file
  187. nogud4 lbra login2
  188.  
  189. *
  190. * mkhom
  191. *
  192. * Create the 'home*' file which contains the name of
  193. * this guys login directory.  This is used by shell.
  194. *
  195.  
  196. mkhom sys create,homnm,$1b create file
  197.  bes mkhom6 if error - skip
  198.  pshs d save file desc
  199.  ldx ichd2 get ptr to dir name
  200.  stx ihwrt2 set up os call
  201.  ldd #0 set counter to 0
  202. mkhom2 tst 0,x+ get size of string
  203.  beq mkhom3
  204.  incb
  205.  bra mkhom2
  206. mkhom3 incb
  207.  std ihwrt3 save count in call
  208.  ldd 0,s get file desc
  209.  sys ind,ihwrt output name
  210.  puls d get file desc
  211.  sys close close the file
  212. mkhom6 rts return
  213.  
  214.  pag
  215.  
  216. *
  217. * fndnam
  218. *
  219. * Find name in password file.  Return error set
  220. * if error.
  221. *
  222.  
  223. fndnam ldx #fbuf point to file buffer
  224.  stx linpt init buf ptrs
  225.  stx linend
  226.  sys open,nfile,0 open password file
  227.  bes fndna4 error?
  228.  std namfd save file desc
  229. fndna2 bsr getlin get a line from the file
  230.  beq fndna5 eof?
  231.  ldx #buffer point to name
  232.  ldy #linbuf point to line
  233.  bsr cmpnam compare names
  234.  bne fndna2 if no compare, repeat
  235.  sty nxtfld save field pointer
  236.  lda 0,y check for null pw
  237.  cmpa #':
  238.  beq fndna3
  239.  inc pwex set pw flag
  240. fndna3 ldd namfd get file desc
  241.  sys close close the file
  242.  clc clear error
  243. fndna4 rts return
  244. fndna5 ldd namfd get file desc
  245.  sys close close the file
  246.  sec set error
  247.  rts return
  248.  
  249.  
  250. *
  251. * getlin
  252. *
  253. * Get a line from the password file.  Put it
  254. * in the linbuf.
  255. *
  256.  
  257. getlin ldx #linbuf point to line buffer
  258. getli2 bsr gtch get a character
  259.  beq getli4 eof?
  260.  sta 0,x+ save character in buffer
  261.  cmpa #CR end of line?
  262.  bne getli2
  263.  clz set ok status
  264. getli4 rts return
  265.  
  266.  pag
  267.  
  268. *
  269. * gtch
  270. *
  271. * Get a character from the password file.  Return
  272. * eq status if eof.
  273. *
  274.  
  275. gtch pshs x save x
  276. gtch2 ldx linpt get line pointer
  277.  cmpx linend end of buffer?
  278.  bne gtch4
  279.  ldd namfd get file desc
  280.  sys read,fbuf,512 read in some file
  281.  bes gtch6 error?
  282.  cmpd #0 eof?
  283.  beq gtch6
  284.  ldx #fbuf point to buffer begin
  285.  stx linpt save pointer
  286.  leax d,x mark end of buffer
  287.  stx linend
  288.  ldx linpt reset pointer
  289. gtch4 lda 0,x+ get next character
  290.  stx linpt save pointer
  291.  clz set ok status
  292.  puls x,pc return
  293. gtch6 sez set error
  294.  puls x,pc return
  295.  
  296.  
  297. *
  298. * cmpnam
  299. *
  300. * Compare name pointed at by X to name pointed
  301. * at by Y.  Return eq or ne status.
  302. *
  303.  
  304. cmpnam lda 0,x+ get a character
  305.  beq cmpna4 end of name?
  306.  cmpa 0,y+ compare chars
  307.  beq cmpnam repeat?
  308.  rts return ne
  309. cmpna4 lda 0,y+ get next
  310.  beq cmpna6 null?
  311.  cmpa #': end of field?
  312. cmpna6 rts return
  313.  
  314.  pag
  315.  
  316. *
  317. * decvt
  318. *
  319. * Decimal convert routine.  Convert ascii string
  320. * pointed at by x and null terminated.
  321. * Return number in D and ne if error.
  322. *
  323.  
  324. decvt ldd #0 set up zero
  325.  pshs d
  326. decvt2 lda 0,x+ get character
  327.  beq decvt4 end of list?
  328.  cmpa #'0 check for valid number
  329.  blo decvt3 error?
  330.  cmpa #'9
  331.  bhi decvt3
  332.  anda #$F mask character
  333.  pshs a save digit
  334.  ldd 1,s get number
  335.  aslb multiply by 8
  336.  rola
  337.  aslb
  338.  rola
  339.  aslb
  340.  rola
  341.  addd 1,s add in original twice
  342.  addd 1,s
  343.  addb 0,s+ add in new digit
  344.  adca #0
  345.  std 0,s save result
  346.  bra decvt2 repeat
  347. decvt3 clz set error
  348. decvt4 puls d,pc return
  349.  
  350.  pag
  351. *
  352. * fixcs
  353. *
  354. * Fix upper/lower case by name.
  355. *
  356.  
  357. fixcs ldx #buffer point to name
  358.  lda 0,x get 1st character
  359.  cmpa #'a is it lower case?
  360.  bhs fixcs4 if so, ok
  361. fixcs2 lda 0,x get char
  362.  beq fixcs3 is it null?
  363.  adda #$20 make lower case
  364.  sta 0,x+ save character
  365.  bra fixcs2
  366. fixcs3 lda ttbuf get tty flags
  367.  ora #LCASE set lcase bit
  368.  sta ttbuf set back in buffer
  369.  ldd #0 set file desc
  370.  sys ttyset,ttbuf set new status
  371. fixcs4 ldx #buffer
  372.  ldy #ulgtab+ul_nam copy name to table
  373.  pshs y save start
  374.  ldb #5 set count
  375.  pshs b save it
  376.  ldd #0 set null word
  377. fixcs5 std 0,y++ zero out name
  378.  dec 0,s dec count
  379.  bne fixcs5
  380.  puls b,y reset pointer
  381.  ldb #9 set count
  382.  pshs b
  383. fixcs6 dec 0,s dec the count
  384.  beq fixcs7
  385.  lda 0,x+ get name character
  386.  sta 0,y+ move to table
  387.  bne fixcs6
  388. fixcs7 puls b,pc return
  389.  
  390.  pag
  391.  
  392. *
  393. * chkps
  394. *
  395. * Check for valid password.  Return carry set on error.
  396. *
  397.  
  398. chkps pshs d save count
  399.  bsr gtnxt get next field
  400.  puls d reset count
  401.  tst pwex pw exist?
  402.  beq chkps4
  403.  cmpd #1 check for eof or cr
  404.  bls chkps3 if so, error
  405.  pshs x save buffer pointer
  406.  ldx #buffer point to name
  407.  pshs x save as arg
  408.  ldx #encpw point to encryption buffer
  409.  pshs x save as arg
  410.  lbsr crypt do encryption
  411.  leas 4,s clean stack
  412.  lbsr mkasc make ascii string
  413.  puls x
  414.  ldy #ascpw point to encrypted pswd
  415.  lbsr cmpnam compare names
  416.  beq chkps4
  417. chkps3 sec set error
  418.  rts return
  419. chkps4 clc clear error
  420.  rts return
  421.  
  422.  pag
  423.  
  424. *
  425. * gtnxt
  426. *
  427. * Get next field from linbuf
  428. *
  429.  
  430. gtnxt ldx nxtfld get field pointer
  431.  pshs x save it
  432. gtnxt2 lda 0,x+ get character
  433.  cmpa #': is it term?
  434.  bne gtnxt2
  435.  clr -1,x set null term
  436.  stx nxtfld set next ptr
  437.  puls x,pc return
  438.  
  439.  
  440. *
  441. * getid
  442. *
  443. * Get user id from password file.
  444. *
  445.  
  446. getid bsr gtnxt get next field
  447.  lbsr decvt convert number to binary
  448.  bne getid4 error?
  449.  std usrid save id
  450.  clc set ok status
  451.  rts return
  452. getid4 sec set error
  453.  rts return
  454.  
  455.  
  456. *
  457. * setdr
  458. *
  459. * Setup new user directory.
  460. *
  461.  
  462. setdr bsr gtnxt get next field
  463.  stx ichd2 set in ind call
  464.  sys ind,ichd do chdir
  465.  rts return
  466.  
  467.  
  468.  pag
  469.  
  470. *
  471. * chkml
  472. *
  473. * Check for mail file.
  474. *
  475.  
  476. chkml sys status,malnm,stb check status
  477.  bes chkml6 if error, no mail
  478.  ldd stb+st_siz+2 check size of file
  479.  bne chkml4 if != 0, then mail
  480.  ldd stb+st_siz
  481.  beq chkml6
  482. chkml4 ldd #1 set file desc
  483.  sys write,mlstr,MLSZ output message
  484. chkml6 rts return
  485.  
  486. *
  487. * mkasc
  488. *
  489. * Make encrypted password an ascii string.
  490. *
  491.  
  492. mkasc ldb #8 set count
  493.  pshs b
  494.  ldx #encpw point to password
  495.  ldy #ascpw point to buffer
  496. mkasc2 lda 0,x get a byte
  497.  anda #$f mask low 4 bits
  498.  adda #'k make a letter
  499.  sta 0,y+ save in buffer
  500.  lda 0,x+ get byte
  501.  lsra shift to get hi 4 bits
  502.  lsra
  503.  lsra
  504.  lsra
  505.  adda #'a make a letter
  506.  sta 0,y+ add to buffer
  507.  dec 0,s dec the count
  508.  bne mkasc2 repeat?
  509.  puls b,pc return
  510.  
  511.  pag
  512.  
  513. *
  514. * gtinfo
  515. *
  516. * Get current time and tty info.
  517. *
  518.  
  519. gtinfo ldd #0 set file desc 0
  520.  lbsr ttynam get tty name
  521.  bes gtinf2 error?
  522.  std ttnam2 save name
  523.  std ttchn2
  524.  std ulgtab+ul_tty save in table too
  525.  sys time,curtim get current time
  526.  rts return
  527. gtinf2 ldd #1 set file desc
  528.  sys write,bdtr,BDSZ output error msg
  529.  sys term terminate login!
  530.  
  531.  
  532. *
  533. * idlin
  534. *
  535. * Output id line during login (tty name & time)
  536. *
  537.  
  538. idlin sys time,ulgtab+ul_tim get system time
  539.  ldx #ulgtab+ul_tim point to time
  540.  lbsr tmloc convert to local time
  541.  ldx #second point to time vector
  542.  lbsr tasc convert to ascii
  543.  ldd #1 set file desc
  544.  sys write,tstr,24 print the date & time
  545.  ldd #1 set file desc
  546.  sys write,spcs,6 output 6 spaces
  547.  lda #$d set up cr
  548.  sta ttnam2+2
  549.  ldd #1 set file desc
  550.  sys write,ttnam,6 output ttyname
  551.  clr ttnam2+2
  552.  rts return
  553.  
  554.  
  555.  pag
  556.  
  557. *
  558. * ttynam
  559. *
  560. * Get the name of the tty whose file desc is in D.
  561. *
  562.  
  563. ttynam pshs d save file desc
  564.  sys ofstat,ttystb get status
  565.  bes ttyna5 error?
  566.  lda ttystb+4 get modes
  567.  bita #$04 is it character device?
  568.  beq ttyna5 if not, error
  569.  ldd ttystb+2 get fdn number
  570.  pshs d save it
  571.  sys open,ttydir,0 open device dir for read
  572.  bes ttyna4 error?
  573.  pshs d save file desc
  574. ttyna2 ldd 0,s get file desc
  575.  sys read,ttybuf,16 read in dir entry
  576.  bes ttyna3 error?
  577.  ldd 2,s get fdn number
  578.  cmpd ttybuf same fdn?
  579.  bne ttyna2 if not, repeat
  580.  puls d get file desc
  581.  sys close close the file
  582.  leas 4,s clean up stack
  583.  ldd ttybuf+5 get name
  584.  clc set ok status
  585.  rts return
  586. ttyna3 puls d get file desc
  587.  sys close close the file
  588. ttyna4 puls d clean up stack
  589. ttyna5 sec set error
  590.  puls d,pc return
  591.  
  592.  pag
  593.  
  594. *
  595. * upduf
  596. *
  597. * Update the act/utmp file with this user
  598. *
  599.  
  600. upduf sys open,utfn,1 open the file
  601.  bes upduf6 if error, skip
  602.  pshs d save file desc
  603.  ldd ulgtab+ul_tty get tty name
  604.  anda #$f mask low 4 bits
  605.  andb #$f of each char
  606.  asla hi byte times 10
  607.  pshs a
  608.  asla
  609.  asla
  610.  adda 0,s result now x10
  611.  sta 0,s save result
  612.  addb 0,s+ add in low byte
  613.  clra clear hi byte
  614.  aslb now x16
  615.  rola
  616.  aslb
  617.  rola
  618.  aslb
  619.  rola
  620.  aslb
  621.  rola
  622.  std isk2 save in seek call
  623.  ldd 0,s get file desc
  624.  sys ind,isk seek in file
  625.  ldd 0,s get file desc
  626.  sys write,ulgtab,16 write out entry
  627.  puls d get file desc
  628.  sys close close the file
  629. upduf6 sys open,hisf,1 open history file
  630.  bes upduf8 error?
  631.  pshs d save file desc
  632.  sys seek,0,0,2 seek to eof
  633.  ldd 0,s get file desc
  634.  sys write,ulgtab,16 output history data
  635.  puls d get file desc
  636.  sys close
  637. upduf8 rts return
  638.  
  639.  pag
  640.  
  641. *
  642. * tmloc
  643. *
  644. * Convert time pointed at by x to vector time (local).
  645. *
  646.  
  647. tmloc ldd 0,x get time
  648.  std ltime
  649.  ldd 2,x
  650.  std ltime+2
  651.  lda 7,x get day light savings flag
  652.  sta dlflg
  653.  clr eutc init flag
  654.  ldd 5,x get time zone
  655.  bpl tmloc2 west of GMT?
  656.  inc eutc if not - set flag
  657.  coma and make pos number
  658.  comb
  659.  addd #1
  660. tmloc2 std r0+2 save time zone
  661.  ldd #60 calculate zone seconds
  662.  std r1+2
  663.  ldd #0 set hi bytes to 0
  664.  std r0
  665.  std r1
  666.  lbsr lmul calculate time zone seconds
  667.  ldd r0 get result
  668.  std tzn save it
  669.  ldd r0+2
  670.  std tzn+2
  671.  lbsr adjtim adjust time for zone
  672.  ldx #ltime point to time
  673.  lbsr tmutc convert to vector
  674.  tst dlflg do dlst?
  675.  beq tmloc6
  676.  lbsr chkdl in dlst?
  677.  bne tmloc6
  678. tmloc5 ldd #3600 adjust for dlst
  679.  addd ltime+2
  680.  std ltime+2
  681.  ldd ltime
  682.  adcb #0
  683.  adca #0
  684.  std ltime
  685.  ldx #ltime point to time
  686.  lbsr tmutc convert to vector
  687.  inc daylit set daylit flag
  688. tmloc6 ldx #second point to vector
  689.  rts return
  690.  
  691.  pag
  692.  
  693. *
  694. * tmutc
  695. *
  696. * Convert the internal system time (4 bytes
  697. * pointed at by X on entry) to an 18 byte
  698. * vector representing the broken down time.
  699. * The time in this form is UTC (Universal
  700. * Coordinated Time).
  701. *
  702.  
  703. tmutc ldd #0 set daylight savings word
  704.  std daylit
  705.  ldd 0,x get hi word of time
  706.  std r0 save ir divide register
  707.  ldd 2,x get lo word of time
  708.  std r0+2
  709.  ldd #60*60 seconds*minutes constant
  710.  std r1 set up for divide
  711.  lbsr ldiv min*sec=time % 3600
  712.  ldd work hour*day=time / 3600
  713.  pshs d save min*sec
  714.  ldd #24 set up hours per day constant
  715.  std r1
  716.  lbsr ldiv hours= (hour*day) % 24
  717.  ldd work day= (hour*day) / 24
  718.  std hours set hours word
  719.  ldd r0+2 get day number
  720.  std day save the day
  721.  addd #2 add in day bias (Jan 1 80 => Tue)
  722.  std r0 set up for divide
  723.  ldb #7 days per week constant
  724.  stb r1
  725.  lbsr div wday=(day+2) % 7
  726.  ldb work get result
  727.  clra make into word
  728.  std wday set week day
  729.  puls d get min*sec
  730.  std r0 set up for divide
  731.  ldb #60 seconds per minute
  732.  stb r1
  733.  lbsr div seconds= (min*sec) % 60
  734.  ldb work minutes= (min*sec) / 60
  735.  clra
  736.  std second set seconds word
  737.  ldd r0 get minutes
  738.  std minute save it
  739.  
  740.  pag
  741.  
  742. * continue tutc for year and month data
  743.  
  744.  clr 0,-s clear year counter
  745. tutc2 ldx #ylen point to year length table
  746.  lda 0,s get year number
  747.  bita #$3 is it leap year?
  748.  bne tutc3
  749.  leax 2,x if so, move to long year value
  750. tutc3 ldd day get day number
  751.  cmpd 0,x day in current year?
  752.  blo tutc4 if 'lt' - we got the year!
  753.  subd 0,x subtract off years days
  754.  std day save new day count
  755.  inc 0,s bump the year count
  756.  bra tutc2 repeat
  757. tutc4 std yday set day of year word
  758.  puls b get year count
  759.  addb #80 add to '1980'
  760.  clra make 16 bits long
  761.  std year save the year
  762.  bitb #$3 is it leap year?
  763.  bne tutc5
  764.  ldd #29 if so, set Feb day count to 29
  765.  std mdays+2
  766. tutc5 ldx #mdays point to month-day table
  767.  clr 0,-s set month count to zero
  768.  ldd yday get day of the year
  769. tutc6 cmpd 0,x in the month?
  770.  blo tutc7 if 'lt' - we got the month!
  771.  inc 0,s bump the month counter
  772.  subd 0,x++ subtract of this month's days
  773.  bra tutc6
  774. tutc7 addd #1 add 1 to month day (day 1 is 1 - not 0!)
  775.  std mday save the month day
  776.  puls b get the month
  777.  std month save it
  778.  ldd #28 reset month - day table
  779.  std mdays+2
  780.  rts return
  781.  
  782.  pag
  783.  
  784. *
  785. * chkdl
  786. *
  787. * Check if in dlst - return 'eq' if so.
  788. *
  789.  
  790. chkdl ldd #119 check for last Sun in Apr
  791.  bsr fixtim
  792.  std fstdl first day of dlst
  793.  ldd #303 last Sun in Oct
  794.  bsr fixtim
  795.  std lstdl last day of dlst
  796.  ldd yday get day of year
  797.  cmpd fstdl up to 1st day yet?
  798.  blo chkdl6
  799.  bhi chkdl4
  800.  ldd hours on the 1st day - so
  801.  cmpd #2 is it 2:00 AM yet?
  802.  blo chkdl6
  803.  bra chkdl5
  804. chkdl4 ldd yday get day of year
  805.  cmpd lstdl past last day of dlst?
  806.  bhi chkdl6
  807.  blo chkdl5
  808.  ldd hours on the last day - so
  809.  cmpd #1 is it 1:00 AM yet?
  810.  bhs chkdl6
  811. chkdl5 sez we are in dlst!
  812.  rts return
  813. chkdl6 clz not in dlst
  814.  rts return
  815.  
  816.  pag
  817.  
  818. *
  819. * adjtim
  820. *
  821. * Adjust time for time zone.
  822. *
  823.  
  824. adjtim ldd ltime+2 get time
  825.  tst eutc east of UTC?
  826.  bne adjti2
  827.  subd r0+2 subtract time zone minutes
  828.  std ltime+2
  829.  ldd ltime get hi part
  830.  sbcb r0+1
  831.  sbca r0
  832.  bra adjti4
  833. adjti2 addd r0+2 add in minutes
  834.  std ltime+2
  835.  ldd ltime
  836.  adcb r0+1
  837.  adca r0
  838. adjti4 std ltime save new time
  839. adjti5 rts return
  840.  
  841. *
  842. * fixtim
  843. *
  844. * Return the closest day to the date in D
  845. * which is a Sunday.
  846. *
  847.  
  848. fixtim pshs d save day number
  849.  ldd year get year
  850.  bitb #$3 is it leap year?
  851.  puls d
  852.  bne fixti2
  853.  addd #1 if so - bump day number
  854. fixti2 pshs d save day number
  855.  addd #420 add in 420 so no negatives result
  856.  addd wday add in day of week
  857.  subd yday subtract day of year
  858.  std r0 save result
  859.  ldb #7
  860.  stb r1 set up for divide
  861.  lbsr div do: (day+420+wday-yday) % 7
  862.  puls d get day number
  863.  subb work
  864.  sbca #0
  865.  rts return day in d
  866.  
  867.  pag
  868.  
  869. *
  870. * Divide routines for time conversion use.  'Ldiv'
  871. * divides a 32 bit number (r0 -> r0+3) by a 16 bit
  872. * number (r1 -> r1+1) and produces a 32 bit result
  873. * in r0 and a 16 bit remainder in 'work'.  'Div'
  874. * divides a 16 bit number (r0 -> r0+1) by an 8 bit
  875. * number (r1) and produces a 16 bit result (r0)
  876. * and an 8 bit remainder (work).
  877. *
  878.  
  879. div lda #17 set up loop counter
  880.  clrb do initialize
  881.  stb work
  882.  bra div2
  883. div1 ldb work
  884.  subb r1 do subtraction
  885.  bcs div2 s3et new work?
  886.  stb work yes!
  887. div2 rol r0+1 do shift left
  888.  rol r0
  889.  rol work
  890.  deca dec the loop count
  891.  bne div1 repeat?
  892.  com r0 fix up result
  893.  com r0+1
  894.  lsr work fix remainder
  895.  rts
  896.  
  897.  
  898.  pag
  899.  
  900. *
  901. * Long divide
  902. *
  903.  
  904. ldiv ldb #33 set loop counter
  905.  pshs b
  906.  ldd #0 do init
  907.  std work
  908.  bra ldiv2
  909. ldiv1 ldd work do subtraction
  910.  subd r1
  911.  bcs ldiv2 work > r1 ?
  912.  std work set new work value
  913. ldiv2 rol r0+3 do shifting
  914.  rol r0+2
  915.  rol r0+1
  916.  rol r0
  917.  rol work+1
  918.  rol work
  919.  dec 0,s dec the loop count
  920.  bne ldiv1
  921.  com r0 compliment the result
  922.  com r0+1
  923.  com r0+2
  924.  com r0+3
  925.  lsr work adjust the remainder
  926.  ror work+1
  927.  puls b,pc return
  928.  
  929.  pag
  930.  
  931. *
  932. * lmul
  933. *
  934. * Long multiply - 32 bits (r0) X 32 bits (r1).
  935. * Result is in r0.
  936. *
  937.  
  938. lmul ldb #32 set loop count
  939.  pshs b
  940.  ldd #0 init variables
  941.  std work
  942.  std work+2
  943.  lsr r0 do initial shift
  944.  ror r0+1
  945.  ror r0+2
  946.  ror r0+3
  947. lmul1 bcc lmul2 need to add?
  948.  ldd work+2
  949.  addd r1+2
  950.  std work+2
  951.  ldd work
  952.  adcb r1+1
  953.  adca r1
  954.  std work save result
  955. lmul2 ror work do shifting
  956.  ror work+1
  957.  ror work+2
  958.  ror work+3
  959.  ror r0
  960.  ror r0+1
  961.  ror r0+2
  962.  ror r0+3
  963.  dec 0,s dec the loop count
  964.  bne lmul1 repeat?
  965.  puls b,pc return
  966.  
  967.  pag
  968.  
  969. *
  970. * tasc
  971. *
  972. * Convert the time vector data (18 bytes) pointed
  973. * at by x into an ascii string.  Return x pointing
  974. * to the string.
  975. *
  976.  
  977. tasc tfr x,u save vector pointer
  978.  ldx #tstr point to string
  979.  ldd 4,u get hours
  980.  lbsr cvt convert to ascii
  981.  leax 1,x skip the ':'
  982.  ldd 2,u get minutes
  983.  lbsr cvt convert to ascii
  984.  leax 1,x skip the ':'
  985.  ldd 0,u get seconds
  986.  lbsr cvt convert to ascii
  987.  leax 1,x skip space
  988.  ldd 6,u get day of week
  989.  ldy #dtab point to day table
  990.  bsr tasxfr xfr to string
  991.  ldd 10,u get month
  992.  ldy #mtab point to month table
  993.  bsr tasxfr xfr to string
  994.  ldd 8,u get month day
  995.  bsr cvt convert to ascii
  996.  leax 1,x
  997.  ldd #('1<<8)|'9 set up '19'
  998.  std 0,x save in string
  999.  ldd 12,u get year
  1000.  cmpd #100 >100 (year 2000 yet?)
  1001.  blo tasc4
  1002.  subd #100 remove bias
  1003.  pshs d save year
  1004.  ldd #('2<<8)|'0 set up '20'
  1005.  std 0,x set in string
  1006.  puls d reset year
  1007. tasc4 leax 2,x
  1008.  bsr cvt convert year to ascii
  1009.  ldx #tstr point to string
  1010.  rts return
  1011.  
  1012.  pag
  1013.  
  1014. *
  1015. * tasxfr
  1016. *
  1017. * Transfer the 3 bytes of ascii indexed by b
  1018. * at y to location pointed at by x.
  1019. *
  1020.  
  1021. tasxfr pshs b index * 3
  1022.  aslb
  1023.  addb 0,s+
  1024.  leay b,y point to indexed data
  1025.  ldd 0,y xfr the data to x
  1026.  std 0,x++
  1027.  lda 2,y
  1028.  sta 0,x
  1029.  leax 2,x bump string pointer
  1030.  rts return
  1031.  
  1032. *
  1033. * cvt
  1034. *
  1035. * Convert number in b to ascii at x.
  1036. *
  1037.  
  1038. cvt lda #'0 set ascii 0
  1039. cvt2 cmpb #10 >10?
  1040.  blo cvt4
  1041.  subb #10 subtract off 10
  1042.  inca bump ascii
  1043.  bra cvt2 repeat
  1044. cvt4 addb #'0 make 1's ascii
  1045.  std 0,x++ save ascii at x
  1046.  rts return
  1047.  
  1048.  pag
  1049.  
  1050. **   CRYPT - ENCRYPT PASSWORD.
  1051. *
  1052. *    ENTRY (2,S)=POINTER TO 8 BYTE RESPONSE AREA
  1053. *          (4,S)=POINTER TO PASSWORD, TERMINATED BY
  1054. *                A ZERO BYTE
  1055.  SPC 2
  1056. crypt LDX 2,S (X)=ADDRESS OF RESPONSE AREA
  1057.  LDY 4,S (Y)=ADDRESS OF PASSWORD
  1058.  LDA #251 SET LOOP COUNTER
  1059.  PSHS A
  1060.  LEAS -8,S RESERVE WORK SPACE
  1061.  CLRB (B)=INDEX/COUNTER
  1062.  
  1063. *   COPY PASSWORD TO RESPONSE AND WORK AREAS.
  1064.  
  1065. crypt1 LDA 0,Y+
  1066.  BNE crypt2 IF NOT END OF PASSWORD
  1067.  LEAY -1,Y BACK UP POINTER
  1068. crypt2 STA B,X STORE IN RESPONSE AREA
  1069.  STA B,S STORE IN WORK AREA
  1070.  INCB COUNT CHARACTER
  1071.  CMPB #8
  1072.  BLO crypt1 LOOP FOR 8 BYTES
  1073.  
  1074. *    TAUSWORTHE RANDOM NUMBER GENERATOR.
  1075. *    ADAPTED FROM THE ALGORITHM OF E. J. WATSON,
  1076. *    UNIVERSITY OF MANCHESTER.
  1077. *    ALGORITHM DOCUMENTED IN CACM, VOL 11, NO. 9, SEPT, 1968
  1078. *    P. 643.
  1079. *    VALUES USED: N=63, M=31
  1080. *    TO BE CONSISTENT WITH ALGORITHM, BITS NUMBERS ARE FROM
  1081. *    LEFT TO RIGHT, STARTING AT ZERO.
  1082.  
  1083. crypt4 LDA 4,S PUT BIT 32 IN CARRY
  1084.  LSLA
  1085.  LDD 2,S (D)=BITS 16-31
  1086.  ROLB
  1087.  ROLA (D)=BITS 17-32, CARRY=BIT 16
  1088.  EORB 7,S BITS 17-32 XOR BITS 48-63
  1089.  EORA 6,S
  1090.  STD 6,S REPLACE BITS 48-63
  1091.  EORB 3,S NEW 48-64 XOR BITS 16-31
  1092.  EORA 2,S
  1093.  STD 2,S REPLACE BITS 16-31
  1094.  LDD 0,S (D)=BITS 0-15
  1095.  ROLB
  1096.  ROLA (D)=BITS 1-16
  1097.  EORB 5,S BITS 1-16 XOR BITS 32-47
  1098.  EORA 4,S
  1099.  STD 4,S REPLACE BITS 32-47
  1100.  EORB 1,S NEW 32-47 XOR BITS 0-15
  1101.  EORA 0,S
  1102.  STD 0,S REPLACE BITS 0-15
  1103.  DEC 8,S COUNT ITERATION
  1104.  BNE crypt4 REPEAT 8 TIMES
  1105.  LDB #7 (B)=BYTE COUNTER
  1106.  ANDCC #$FE CLEAR CARRY
  1107. crypt5 LDA B,S ADD BACK ORIGINAL PASSWORD
  1108.  ADCA B,X
  1109.  STA B,X
  1110.  DECB
  1111.  BPL crypt5
  1112.  LEAS 9,S CLEAN UP STACK
  1113.  RTS RETURN
  1114.  
  1115.  pag
  1116.  
  1117. * indirect calls
  1118.  
  1119. iopn fcb open
  1120. iopn2 fdb 0,0
  1121.  
  1122. iwrt fcb write
  1123.  fdb buffer
  1124. iwrt2 fdb 0
  1125.  
  1126. ichd fcb chdir ind chdir call
  1127. ichd2 fdb 0
  1128.  
  1129. isk fcb seek ind seek call
  1130.  fdb 0
  1131. isk2 fdb 0,0
  1132.  
  1133. icho fcb chown change owner
  1134.  fdb ttchn
  1135. icho2 fdb 0
  1136.  
  1137. ihwrt fcb write
  1138. ihwrt2 fdb 0
  1139. ihwrt3 fdb 0
  1140.  
  1141.  
  1142. * constant strings
  1143.  
  1144. utfn fcc '/act/utmp',0
  1145. homnm fcc '.home?',0
  1146. bdlgfl fcc '/act/attempts',0
  1147. hisf fcc '/act/history',0 history file
  1148. lgmsg fcc '/etc/log/message',0
  1149. motd fcc '/etc/log/motd',0
  1150. shell fcc '/bin/shell',0
  1151. args fdb shelln,0
  1152. shelln fcc '+shell',0
  1153. nfile fcc '/etc/log/password',0
  1154. malnm fcc '.mail',0
  1155. cptst fcc '+cx',0
  1156. ttydir fcc '/dev',0
  1157. ttnam fcc 'tty'
  1158. ttnam2 fcc 'xx',0
  1159. spcs fcc '                    '
  1160. ttchn fcc '/dev/tty'
  1161. ttchn2 fcc 'xx',0
  1162.  
  1163. ngmsg fcc 'Login incorrect!',$d,$d
  1164. NGSZ equ *-ngmsg
  1165.  
  1166. logst fcc $d,$d,'Login: '
  1167. LSZ equ *-logst
  1168.  
  1169. pswst fcc 'Password: '
  1170. PSZ equ *-pswst
  1171.  
  1172. ndrms fcc 'No directory!'
  1173. NDSZ equ *-ndrms
  1174.  
  1175. mlstr fcc 'You have mail.',$d
  1176. MLSZ equ *-mlstr
  1177.  
  1178. bdtr fcc 'Bad terminal.',$d
  1179. BDSZ equ *-bdtr
  1180.  
  1181. crst fcb $d carriage string
  1182. subrg fdb shell+5,cptst
  1183. subrg2 fdb 0,0
  1184.  
  1185. ylen fdb 365 year length
  1186.  fdb 366 leap year
  1187.  
  1188. mdays fdb 31,28,31,30,31,30,31,31,30,31,30,31
  1189.  
  1190.  
  1191. tstr fcc 'xx:xx:xx xxx xxx xx xxxx',$d,0
  1192.  
  1193. dtab fcc 'SunMonTueWedThuFriSat'
  1194.  
  1195. mtab fcc 'JanFebMarAprMayJunJulAugSepOctNovDec'
  1196.  
  1197.  
  1198. * buffers
  1199.  
  1200. second fdb 0 seconds (0-59)
  1201. minute fdb 0 minutes (0-59)
  1202. hours fdb 0 hours (0-23)
  1203. wday fdb 0 week day (0-6) 0=Sunday
  1204. mday fdb 0 month day (1-31)
  1205. month fdb 0 month (0-11)
  1206. year fdb 0 year (80+)
  1207. yday fdb 0 day of year (0-355)
  1208. daylit fdb 0 daylight savings flag
  1209.  
  1210.  
  1211. r0 fdb 0,0 regs for div and mul
  1212. r1 fdb 0,0
  1213. work fdb 0,0
  1214. day fdb 0 day temp
  1215. ntime fdb 0,0 new time
  1216. eutc fcb 0 east of utc flag
  1217. fstdl fdb 0 1st day of dlst
  1218. lstdl fdb 0 last day of dlst
  1219. dlflg fcb 0 dlst flag
  1220. ltime fdb 0,0 local time
  1221. tzn fdb 0,0 time zone seconds
  1222.  
  1223. ttbuf rmb 6 ttyset buffer
  1224. buffer rmb 32
  1225. ngflg fcb 0 no good flag
  1226. nxtfld fdb 0 next field pointer
  1227. namfd fdb 0 name file descriptor
  1228. linpt fdb 0 line pointer
  1229. linend fdb 0 end of line pointer
  1230. usrid fdb 0 user id
  1231. pwex fcb 0 pw exists flag
  1232. noban fcb 0 if banner should not be displayed
  1233. stb rmb 24 status buffer
  1234. encpw rmb 8 password buffer
  1235. ascpw rmb 16 ascii pswd buffer
  1236.  fcb 0 null term for above
  1237. curtim rmb 8 current time
  1238. ulgtab rmb USIZ login table
  1239.  rmb 4 spare
  1240. ttybuf rmb 16 tty buffer
  1241. ttystb rmb 24 tty status buffer
  1242. linbuf rmb 128 line buffer
  1243.  
  1244.  org $E00
  1245.  
  1246. fbuf rmb 512 file buffer
  1247.  
  1248.  end login
  1249.