home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / beehive / utilitys / password.arc / PASSWORD.MAC < prev    next >
Text File  |  1990-07-21  |  7KB  |  254 lines

  1. ;PASSWORD.MAC - Disassembled source for P.D. "PASSWORD.COM" program.
  2. ;    Ted Harper   6th February 1987
  3. ;
  4. ;This program has been disassembled using the P.D. DazzleStar disassembler
  5. ; since source code was NOT provided with the public domain release,
  6. ; despite the fact that no copyright notice or restriction of access to
  7. ; the program source was given. All credit must fall to Phil Wheeler, as
  8. ; all I have done is disassemble and comment his original work, making no
  9. ; modifications to the code. NOTE that this program REQUIRES a Z80 processor
  10. ; and will work with CP/M 2.2 or 3.x.
  11. ;
  12. ;Following is the documentation for the program extracted from
  13. ; "CP/M Utilities, Volume 2, Phil Wheeler, 16th December 1983"
  14. ; as held on the SIG/M Public Domain software library :-
  15. ;
  16. ;PASSWORD
  17. ;
  18. ;This  program  allows  a  CP/M system  to  be  password  protected.  By 
  19. ;including this program as either the autostart command (for CP/M V2.2), 
  20. ;or as the first line in PROFILE.SUB (for CP/M V3.x),  access to CP/M is 
  21. ;denied without knowing the current password. Command:
  22. ;
  23. ;    PASSWORD        - Wait for password
  24. ;    PASSWORD NONE        - Set password check off
  25. ;    PASSWORD password   - Set new password to 'password'
  26. ;
  27. ;To  change  the password,  the current password must  be  entered.  The 
  28. ;program  stores  the new password within itself on  drive  A:.  If  the 
  29. ;password  check  is  off,  the  program exits  without  waiting  for  a 
  30. ;password.  No  guarantees  are  given  for the  infallibility  of  this 
  31. ;program - its just a useful check on system access.
  32. ;
  33. ;
  34.     .Z80
  35.     aseg
  36.     org    0100h
  37. ;
  38. BDOS        EQU    0005
  39. CPMFCB        EQU    005Dh
  40. ;
  41. Start:
  42.     LD    (Stack),SP
  43.     LD    SP,NewStack
  44. ;
  45.     CALL    GetCurrentPassword    ; Get user to enter current password
  46.                     ;and exit if password checking off.
  47. ;
  48. ;User has entered current password correctly.. Set new password if required
  49. ; (updating A:PASSWORD.COM) and exit to CP/M
  50. ;
  51.     LD    A,(CPMFCB)        ; Check if new password in CPM's FCB
  52.     CP    ' '            ;Exit if setting new password not
  53.     JP    Z,PgmExitPoint        ; required.
  54. ;
  55. ;Set a new password by encrypting it, saving it into the program image
  56. ; & updating the file A:PASSWORD.COM on disk.
  57. ;
  58.     LD    HL,CPMFCB        ;Take the password entered by the
  59.     LD    DE,EncryptedPW        ; user after PASSWORD from CP/M
  60.     LD    B,8            ; and encrypt it
  61. EncryptNewPWLoop:
  62.     LD    A,(HL)
  63.     CPL
  64.     ADD    A,E
  65.     LD    (DE),A
  66.     INC    HL
  67.     INC    DE
  68.     DJNZ    EncryptNewPWLoop
  69. ;
  70.     CALL    RewritePWFile        ;Write the COM file back.
  71. ;
  72.     DB    '!'
  73. ;This is the encrypted password, against which the
  74. ;user-entered password is checked. It MUST be somewhere
  75. ;between 100h and 180h for the "update" code to function. Note it is
  76. ;initially set to "NONE" (or the encrypted version thereof at least!)
  77. EncryptedPW:
  78.     DB    0D7h,0D7h,0D9h,0E3h,9,0Ah,0Bh,0Ch
  79. ;
  80. ;
  81. RewritePWFile:
  82. ;Rewrite sector 1 of A:PASSWORD.COM from first page
  83. ;of TPA (100..180h) so as to save new password.
  84. ;
  85.     POP    DE
  86. ;
  87.     LD    DE,ComFileFCB        ;Open the (existing) file
  88.     LD    C,0Fh            ; A:PASSWORD.COM (for update)
  89.     CALL    BDOS
  90.     CP    0FFh
  91.     JR    Z,WriteError
  92. ;
  93.     LD    C,1Ah            ;Set DMA addr. to start of TPA (100h)
  94.     LD    DE,Start
  95.     CALL    BDOS
  96. ;
  97.     LD    DE,ComFileFCB        ;Write a record with random access
  98.     LD    C,22h            ; in this case rewrite the first
  99.     CALL    BDOS            ; sector of the file from locations
  100.     AND    A            ; 100h..17Fh.
  101.     JR    NZ,WriteError
  102. ;
  103.     LD    DE,ComFileFCB        ;Have now updated password on disk,
  104.     LD    C,10h            ; close the file
  105.     CALL    BDOS
  106.     CP    0FFh
  107.     JR    Z,WriteError
  108. ;
  109.     CALL    ILPrint
  110.     DB    'New Password store',0E4h
  111. ;
  112. PgmExitPoint:
  113.     LD    SP,(Stack)        ;Restore entry stack
  114.     RET                ; and drop back to CP/M
  115. ;
  116. WriteError:
  117.     CALL    ILPrint
  118.     DB    'Write error - check fil',0E5h
  119.     JR    PgmExitPoint
  120. ;
  121. GetCurrentPassword:
  122. ;
  123.     LD    HL,NONEPassword        ; Check if password checking currently
  124.     CALL    CmpWithEncryptedPW    ; disabled..if so, exit without doing
  125.     RET    Z            ; anything.
  126. ;
  127. ;Password checking is currently enabled..get password from user
  128. ;
  129.     CALL    ILPrint
  130.     DB    0Dh,0Ah,'Password ?',0A0h
  131. ;
  132.     LD    HL,BlankPasswordBuffer    ;Blank out the buffer into which the
  133.     LD    DE,PWBuffer2        ; user-entered password will be
  134.     LD    BC,0008            ; saved (after encryption).
  135.     LDIR
  136. ;
  137. ;Get a password of up to 8 characters (in upper case)
  138. ;
  139.     LD    B,8
  140.     LD    HL,PWBuffer2
  141. GetPWLoop:
  142.     CALL    GetConsoleChar        ; Get a character from CON:
  143.     CP    0Dh            ; Exit loop when CR pressed
  144.     JR    Z,PWGetDone
  145.     CP    ' '            ; Ignore anything < ' '
  146.     JR    C,GetPWLoop
  147.     CP    '`'            ; anything >=' ' and < '`' is upper
  148.     JR    C,SavePWLetter
  149.     SUB    ' '            ; convert l/case to Upper
  150. SavePWLetter:
  151.     LD    (HL),A            ; Store the letter entered by user
  152.     INC    HL
  153.     CALL    ILPrint            ; Echo a '-' to the console
  154.     DB    0ADh
  155.     DJNZ    GetPWLoop        ; loop until CR or 8 characters entered
  156. ;
  157. PWGetDone:
  158.     CALL    ILPrint        ;Password entry done..send CR LF to CON:
  159.     DB    0Dh,8Ah
  160. ;
  161. ;Compare entered password with current (encrypted) one.
  162. ;If they don't match, loop back and try again (and again...)
  163. ;
  164.     LD    HL,PWBuffer2        ; Point to password just entered
  165.     CALL    CmpWithEncryptedPW    ;and compare it with the real one
  166. ;
  167.     JP    NZ,GetCurrentPassword    ; If incorrect, back to try again
  168. ;
  169. ;return when correct password entered..then exit to
  170. ;CP/M or update with new password (as entered as
  171. ;command "tail" from CP/M).
  172.     RET
  173. ;
  174. CmpWithEncryptedPW:
  175. ;Compares the password at HL with the current one,
  176. ;which is held in a (simply) encrypted format.
  177. ;
  178.     LD    DE,EncryptedPW
  179.     LD    B,8
  180. CmpPWLoop:
  181.     LD    A,(DE)
  182.     SUB    E
  183.     CPL
  184.     CP    (HL)
  185.     RET    NZ
  186.     INC    HL
  187.     INC    DE
  188.     DJNZ    CmpPWLoop
  189.     XOR    A
  190.     RET
  191. ;
  192. ILPrint:
  193. ;Print a string InLine (i.e. straight after the call), ending after
  194. ; a character with the high bit set (>80h) is printed.
  195. ;
  196.     EX    (SP),HL
  197.     PUSH    BC
  198.     PUSH    DE
  199. ILPLoop:
  200.     LD    C,(HL)
  201.     RES    7,C
  202.     PUSH    HL
  203.     LD    DE,0009
  204.     CALL    JmpBiosPlusOffset
  205.     POP    HL
  206.     BIT    7,(HL)
  207.     INC    HL
  208.     JR    Z,ILPLoop
  209.     POP    DE
  210.     POP    BC
  211.     EX    (SP),HL
  212.     RET
  213. ;
  214. GetConsoleChar:
  215. ; Get a character from CON: using BIOS
  216.     PUSH    BC
  217.     PUSH    DE
  218.     PUSH    HL
  219.     LD    DE,0006
  220.     CALL    JmpBiosPlusOffset
  221.     POP    HL
  222.     POP    DE
  223.     POP    BC
  224.     AND    7Fh
  225.     RET
  226. ;
  227. JmpBiosPlusOffset:
  228. ;Jumps straight to a BIOS service routine by adding
  229. ;the offset passed in DE to the address of the
  230. ;warmstart call & jumping there.
  231.     LD    HL,(0001h)
  232.     ADD    HL,DE
  233.     JP    (HL)
  234. ;
  235. NONEPassword:
  236.     DB    'NONE    '
  237. BlankPasswordBuffer:
  238.     DB    '        '
  239. ;
  240. ;FCB for A:PASSWORD.COM (SYStem attribute set).
  241. ComFileFCB:
  242.     DB    1    ; 1 means drive A: (2 = B:, etc)
  243.     DB    'PASSWORDC',0CFh,'M'
  244.     DB    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  245. PWBuffer2:
  246.     DB    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  247.     db    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  248. ;
  249. NewStack    EQU    0299h
  250. Stack        EQU    0299h
  251. ;
  252.     END
  253. ,0,0,0,0,0,0,0,0,0,0
  254.     db    0,0,0,0,0,0,0,0,0,0,0,