A2osX/SBIN/LOGIN.S.txt
2020-03-13 17:10:36 +01:00

359 lines
6.1 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

NEW
AUTO 3,1
.LIST OFF
.OP 65C02
.OR $2000
.TF sbin/login
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
.INB INC/KERNEL.I
.INB INC/MLI.I
*--------------------------------------
.DUMMY
.OR ZPBIN
ZS.START
ZPhBuf .BS 1
ZPBufPtr .BS 2
ZPRetryCnt .BS 1
ZPbValidUser .BS 1
ZPUID .BS 1
ZPhGetLine .BS 1
ZPGetLinePtr .BS 2
ZPbGetLineSecret .BS 1
ZPbEsc .BS 1
ZPGetLineLen .BS 1
ZPGetLineMax .BS 1
ZPNewSID .BS 1
ZPOldSID .BS 1
ZPNewSession .BS 1
ZPOldSession .BS 1
ZPhFile .BS 1
ZPStrPtr .BS 2
ZS.END
.ED
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
.DA #S.PS.F.EVENT S.PS.F
.DA #0
.DA CS.END-CS.START Code Size (without Constants)
.DA DS.END-DS.START Data Segment Size
.DA #32 Stack Size
.DA #ZS.END-ZS.START Zero Page Size
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.MSG.NOAUTH .DA MSG.NOAUTH
L.MSG.LOGIN .DA MSG.LOGIN
L.MSG.PASSWORD .DA MSG.PASSWORD
L.MSG.BAD .DA MSG.BAD
L.MSG.CRLF .DA MSG.CRLF
L.MSG.BS .DA MSG.BS
L.ETCISSUE .DA ETCISSUE
L.ETCMOTD .DA ETCMOTD
L.SHELL .DA SHELL
.DA 0
*--------------------------------------
CS.INIT clc
CS.INIT.RTS rts
*--------------------------------------
CS.RUN >LDYAI 33 Enough for HASH
>SYSCALL GetMem
bcs CS.INIT.RTS
>STYA ZPGetLinePtr
stx ZPhGetLine
>LDYA L.ETCISSUE
jsr CS.RUN.DUMPFILE
lda #0
>PUSHA ROOT user
>PUSHA
>PUSHA Dry Run, no output
>SYSCALL GetPWUID
bcc CS.RUN.AUTH
*--------------------------------------
>LDYA L.MSG.NOAUTH
jsr CS.RUN.StrOut
bcs .9
ldy #S.PS.hSession
lda (pPS),y
tax
lda S.Table.hSID-1,x
sta ZPNewSID
jmp CS.RUN.EXEC
.9 rts
*--------------------------------------
CS.RUN.AUTH lda #3
sta ZPRetryCnt
.1 >LDYA L.MSG.LOGIN
jsr CS.RUN.StrOut
bcs .9
lda #16
clc
jsr CS.RUN.GetLine
bcs .9
>LDYA L.MSG.PASSWORD
jsr CS.RUN.StrOut
bcs .9
lda #32
sec
jsr CS.RUN.GetLine
bcs .9
>LDYA L.MSG.CRLF
jsr CS.RUN.StrOut
bcs .9
bra *
jmp CS.RUN.EXEC
.8 >LDYA L.MSG.BAD
>SYSCALL PutS
bcs .9
dec ZPRetryCnt
beq .99
jmp .1
.99 lda #E.IUSR
sec
.9 rts
*--------------------------------------
CS.RUN.EXEC ldx #1
*.1 lda S.Table.hSID-1,x
* beq .2
* inx
* cpx #K.USR.MAX+1
* bne .1
* lda #E.OOH
** sec
* rts
.2
* stx ZPNewSession
* ldy #S.PS.hSession
* lda (pPS),y
* sta ZPOldSession
* txa
* sta (pPS),y
* lda ZPNewSID
* sta S.Table.hSID-1,x
* ldy #S.PS.hStdIn
* lda (pPS),y
* sta S.Table.hFILE-1,x
>LDYA L.ETCMOTD
jsr CS.RUN.DumpFile
jsr CS.CLEANUP
>PUSHW L.SHELL
>PUSHBI S.PS.F.HOLD
>SYSCALL ExecL
bcs .9
>SLEEP
* lda ZPOldSID
* beq .8
* >SYSCALL CloseSession
* stz ZPOldSID
*.8 ldx ZPNewSession
* lda S.Table.hSID-1,x
* stz S.Table.hSID-1,x
* stz S.Table.hFILE-1,x
* >SYSCALL FreeMem
* ldy #S.PS.hSession
* lda ZPOldSession
* sta (pPS),y
sec
.9 rts
*--------------------------------------
CS.RUN.GetLine sta ZPGetLineMax
ror ZPbGetLineSecret
stz ZPGetLineLen
stz ZPbEsc
.1 >SYSCALL getchar
bcs .9
bit ZPbEsc
bpl .11
* clc
ror ZPbEsc
cmp #'D'
bne .1
bra .3
.11 cmp #C.DEL
beq .3
cmp #C.SPACE
bcc .2
ldy ZPGetLineLen
cpy ZPGetLineMax
beq .1
sta (ZPGetLinePtr),y
inc ZPGetLineLen
bit ZPbGetLineSecret
bmi .1
>SYSCALL putchar
bra .1
.2 cmp #3 Ctrl-C
beq .9
cmp #C.CR
beq .8
cmp #C.ESC
bne .1
* sec
ror ZPbEsc
bra .1
.3 ldy ZPGetLineLen
beq .1
dec ZPGetLineLen
bit ZPbGetLineSecret
bmi .1
>LDYA L.MSG.BS
jsr CS.RUN.StrOut
bra .1
.8 ldy ZPGetLineLen
lda #0
sta (ZPGetLinePtr),y
clc
.9 rts
*--------------------------------------
CS.RUN.StrOut >PUSHYA
>PUSHBI 0
>SYSCALL PrintF
rts
*--------------------------------------
CS.RUN.DumpFile >PUSHYA
>PUSHBI O.RDONLY+O.TEXT
>PUSHBI S.FI.T.TXT
>PUSHWZ Aux type
>SYSCALL FOpen
bcs .9
stx ZPhFile
>LDYAI 256
>SYSCALL GetMem
bcs .99
>STYA ZPBufPtr
stx ZPhBuf
.1 >PUSHWI 256
>PUSHW ZPBufPtr
lda ZPhFile
>SYSCALL fgets
bcs .7
>PUSHW ZPBufPtr
>PUSHWI 0
>SYSCALL Expand
bcc .2
.99 php
pha
jsr .8
pla
plp
.9 rts
.2 phx
>SYSCALL PutS
pla
>SYSCALL FreeMem
bra .1
.7 lda ZPhBuf
>SYSCALL FreeMem
.8 lda ZPhFile
>SYSCALL FClose
rts
*--------------------------------------
CS.DOEVENT
sec
rts
*--------------------------------------
CS.QUIT
CS.CLEANUP lda ZPhGetLine
beq .8
stz ZPhGetLine
>SYSCALL FreeMem
.8 clc
rts
*--------------------------------------
CS.END
*--------------------------------------
MSG.NOAUTH .AS "\r\n\r\nA2osX-Login:No ETC/PASSWD file present, Logged as ROOT.\r\n"
.AS "Consider adding ROOT password with USERADD command.\r\n"
MSG.CRLF .AZ "\r\n"
MSG.LOGIN .AZ "\r\nlogin:"
MSG.PASSWORD .AZ "\r\npassword:"
MSG.BAD .AZ "Bad user or password"
MSG.BS .DA #C.BS,#C.SPACE,#C.BS,#0
ETCISSUE .AZ "${ROOT}etc/issue"
ETCMOTD .AZ "${ROOT}etc/motd"
SHELL .AZ "${SHELL}"
*--------------------------------------
.DUMMY
.OR 0
DS.START
DS.END .ED
*--------------------------------------
MAN
SAVE USR/SRC/SBIN/LOGIN.S
ASM