home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
beehive
/
utilitys
/
password.arc
/
PASSWORD.MAC
< prev
next >
Wrap
Text File
|
1990-07-21
|
7KB
|
254 lines
;PASSWORD.MAC - Disassembled source for P.D. "PASSWORD.COM" program.
; Ted Harper 6th February 1987
;
;This program has been disassembled using the P.D. DazzleStar disassembler
; since source code was NOT provided with the public domain release,
; despite the fact that no copyright notice or restriction of access to
; the program source was given. All credit must fall to Phil Wheeler, as
; all I have done is disassemble and comment his original work, making no
; modifications to the code. NOTE that this program REQUIRES a Z80 processor
; and will work with CP/M 2.2 or 3.x.
;
;Following is the documentation for the program extracted from
; "CP/M Utilities, Volume 2, Phil Wheeler, 16th December 1983"
; as held on the SIG/M Public Domain software library :-
;
;PASSWORD
;
;This program allows a CP/M system to be password protected. By
;including this program as either the autostart command (for CP/M V2.2),
;or as the first line in PROFILE.SUB (for CP/M V3.x), access to CP/M is
;denied without knowing the current password. Command:
;
; PASSWORD - Wait for password
; PASSWORD NONE - Set password check off
; PASSWORD password - Set new password to 'password'
;
;To change the password, the current password must be entered. The
;program stores the new password within itself on drive A:. If the
;password check is off, the program exits without waiting for a
;password. No guarantees are given for the infallibility of this
;program - its just a useful check on system access.
;
;
.Z80
aseg
org 0100h
;
BDOS EQU 0005
CPMFCB EQU 005Dh
;
Start:
LD (Stack),SP
LD SP,NewStack
;
CALL GetCurrentPassword ; Get user to enter current password
;and exit if password checking off.
;
;User has entered current password correctly.. Set new password if required
; (updating A:PASSWORD.COM) and exit to CP/M
;
LD A,(CPMFCB) ; Check if new password in CPM's FCB
CP ' ' ;Exit if setting new password not
JP Z,PgmExitPoint ; required.
;
;Set a new password by encrypting it, saving it into the program image
; & updating the file A:PASSWORD.COM on disk.
;
LD HL,CPMFCB ;Take the password entered by the
LD DE,EncryptedPW ; user after PASSWORD from CP/M
LD B,8 ; and encrypt it
EncryptNewPWLoop:
LD A,(HL)
CPL
ADD A,E
LD (DE),A
INC HL
INC DE
DJNZ EncryptNewPWLoop
;
CALL RewritePWFile ;Write the COM file back.
;
DB '!'
;This is the encrypted password, against which the
;user-entered password is checked. It MUST be somewhere
;between 100h and 180h for the "update" code to function. Note it is
;initially set to "NONE" (or the encrypted version thereof at least!)
EncryptedPW:
DB 0D7h,0D7h,0D9h,0E3h,9,0Ah,0Bh,0Ch
;
;
RewritePWFile:
;Rewrite sector 1 of A:PASSWORD.COM from first page
;of TPA (100..180h) so as to save new password.
;
POP DE
;
LD DE,ComFileFCB ;Open the (existing) file
LD C,0Fh ; A:PASSWORD.COM (for update)
CALL BDOS
CP 0FFh
JR Z,WriteError
;
LD C,1Ah ;Set DMA addr. to start of TPA (100h)
LD DE,Start
CALL BDOS
;
LD DE,ComFileFCB ;Write a record with random access
LD C,22h ; in this case rewrite the first
CALL BDOS ; sector of the file from locations
AND A ; 100h..17Fh.
JR NZ,WriteError
;
LD DE,ComFileFCB ;Have now updated password on disk,
LD C,10h ; close the file
CALL BDOS
CP 0FFh
JR Z,WriteError
;
CALL ILPrint
DB 'New Password store',0E4h
;
PgmExitPoint:
LD SP,(Stack) ;Restore entry stack
RET ; and drop back to CP/M
;
WriteError:
CALL ILPrint
DB 'Write error - check fil',0E5h
JR PgmExitPoint
;
GetCurrentPassword:
;
LD HL,NONEPassword ; Check if password checking currently
CALL CmpWithEncryptedPW ; disabled..if so, exit without doing
RET Z ; anything.
;
;Password checking is currently enabled..get password from user
;
CALL ILPrint
DB 0Dh,0Ah,'Password ?',0A0h
;
LD HL,BlankPasswordBuffer ;Blank out the buffer into which the
LD DE,PWBuffer2 ; user-entered password will be
LD BC,0008 ; saved (after encryption).
LDIR
;
;Get a password of up to 8 characters (in upper case)
;
LD B,8
LD HL,PWBuffer2
GetPWLoop:
CALL GetConsoleChar ; Get a character from CON:
CP 0Dh ; Exit loop when CR pressed
JR Z,PWGetDone
CP ' ' ; Ignore anything < ' '
JR C,GetPWLoop
CP '`' ; anything >=' ' and < '`' is upper
JR C,SavePWLetter
SUB ' ' ; convert l/case to Upper
SavePWLetter:
LD (HL),A ; Store the letter entered by user
INC HL
CALL ILPrint ; Echo a '-' to the console
DB 0ADh
DJNZ GetPWLoop ; loop until CR or 8 characters entered
;
PWGetDone:
CALL ILPrint ;Password entry done..send CR LF to CON:
DB 0Dh,8Ah
;
;Compare entered password with current (encrypted) one.
;If they don't match, loop back and try again (and again...)
;
LD HL,PWBuffer2 ; Point to password just entered
CALL CmpWithEncryptedPW ;and compare it with the real one
;
JP NZ,GetCurrentPassword ; If incorrect, back to try again
;
;return when correct password entered..then exit to
;CP/M or update with new password (as entered as
;command "tail" from CP/M).
RET
;
CmpWithEncryptedPW:
;Compares the password at HL with the current one,
;which is held in a (simply) encrypted format.
;
LD DE,EncryptedPW
LD B,8
CmpPWLoop:
LD A,(DE)
SUB E
CPL
CP (HL)
RET NZ
INC HL
INC DE
DJNZ CmpPWLoop
XOR A
RET
;
ILPrint:
;Print a string InLine (i.e. straight after the call), ending after
; a character with the high bit set (>80h) is printed.
;
EX (SP),HL
PUSH BC
PUSH DE
ILPLoop:
LD C,(HL)
RES 7,C
PUSH HL
LD DE,0009
CALL JmpBiosPlusOffset
POP HL
BIT 7,(HL)
INC HL
JR Z,ILPLoop
POP DE
POP BC
EX (SP),HL
RET
;
GetConsoleChar:
; Get a character from CON: using BIOS
PUSH BC
PUSH DE
PUSH HL
LD DE,0006
CALL JmpBiosPlusOffset
POP HL
POP DE
POP BC
AND 7Fh
RET
;
JmpBiosPlusOffset:
;Jumps straight to a BIOS service routine by adding
;the offset passed in DE to the address of the
;warmstart call & jumping there.
LD HL,(0001h)
ADD HL,DE
JP (HL)
;
NONEPassword:
DB 'NONE '
BlankPasswordBuffer:
DB ' '
;
;FCB for A:PASSWORD.COM (SYStem attribute set).
ComFileFCB:
DB 1 ; 1 means drive A: (2 = B:, etc)
DB 'PASSWORDC',0CFh,'M'
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
PWBuffer2:
DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
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
;
NewStack EQU 0299h
Stack EQU 0299h
;
END
,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,