A2osX/SBIN/LOGIN.S.txt

536 lines
9.1 KiB
Plaintext
Raw Normal View History

2015-06-03 18:30:57 +00:00
NEW
2019-04-15 05:40:13 +00:00
AUTO 3,1
2015-06-03 18:30:57 +00:00
.LIST OFF
.OP 65C02
.OR $2000
2018-07-20 05:43:11 +00:00
.TF SBIN/LOGIN
2015-06-03 18:30:57 +00:00
*--------------------------------------
2018-07-20 05:43:11 +00:00
.INB INC/MACROS.I
.INB INC/A2OSX.I
2019-04-15 15:29:07 +00:00
.INB INC/KERNEL.I
2019-04-16 15:54:56 +00:00
.INB INC/MLI.I
2019-04-15 05:40:13 +00:00
.INB INC/LIBCRYPT.I
*--------------------------------------
2018-12-18 14:37:07 +00:00
.DUMMY
.OR ZPBIN
ZS.START
2019-04-15 15:29:07 +00:00
ZPUsrID .BS 1
2019-04-16 15:54:56 +00:00
2019-06-06 06:37:30 +00:00
ZPhBuf .BS 1
ZPBufPtr .BS 2
2019-04-15 05:40:13 +00:00
ZPRetryCnt .BS 1
ZPbValidUser .BS 1
2019-06-06 15:45:40 +00:00
ZPUID .BS 1
2019-04-15 05:40:13 +00:00
ZPhGetLine .BS 1
ZPGetLinePtr .BS 2
ZPbGetLineSecret .BS 1
2019-04-29 15:47:17 +00:00
ZPbEsc .BS 1
2019-04-15 05:40:13 +00:00
ZPGetLineLen .BS 1
ZPGetLineMax .BS 1
2019-04-16 15:54:56 +00:00
2019-06-06 06:37:30 +00:00
ZPhPW .BS 1
ZPPWPtr .BS 2
2019-04-16 15:54:56 +00:00
ZPhSID .BS 1
ZPhFile .BS 1
ZPStrPtr .BS 2
2018-12-18 14:37:07 +00:00
ZS.END
.ED
2015-06-03 18:30:57 +00:00
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
2018-09-19 15:25:42 +00:00
.DA #S.PS.F.EVENT S.PS.F
.DA #0
2018-12-18 14:37:07 +00:00
.DA CS.END-CS.START Code Size (without Constants)
2019-05-05 17:15:37 +00:00
.DA DS.END-DS.START Data Segment Size
2019-04-15 05:40:13 +00:00
.DA #64 Stack Size
2018-12-18 14:37:07 +00:00
.DA #ZS.END-ZS.START Zero Page Size
2015-06-03 18:30:57 +00:00
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
2019-04-15 15:29:07 +00:00
L.MSG.NOAUTH .DA MSG.NOAUTH
2019-04-12 15:41:05 +00:00
L.LIBCRYPT .DA LIBCRYPT
2015-06-03 18:30:57 +00:00
L.MSG.LOGIN .DA MSG.LOGIN
L.MSG.PASSWORD .DA MSG.PASSWORD
2019-04-15 05:40:13 +00:00
L.MSG.BAD .DA MSG.BAD
L.MSG.CRLF .DA MSG.CRLF
L.MSG.BS .DA MSG.BS
2019-04-16 15:54:56 +00:00
L.SESSION.ROOT .DA SESSION.ROOT
L.ETCISSUE .DA ETCISSUE
L.ETCMOTD .DA ETCMOTD
L.SHELL .DA SHELL
2015-06-03 18:30:57 +00:00
.DA 0
*--------------------------------------
2018-09-19 15:25:42 +00:00
CS.INIT clc
2019-04-16 15:54:56 +00:00
CS.INIT.RTS rts
2015-06-03 18:30:57 +00:00
*--------------------------------------
2019-06-06 15:45:40 +00:00
CS.RUN >LDYAI 33 Enough for HASH
2019-04-16 15:54:56 +00:00
>SYSCALL getmem
bcs CS.INIT.RTS
>STYA ZPGetLinePtr
stx ZPhGetLine
2019-07-24 15:17:08 +00:00
2019-04-16 15:54:56 +00:00
>LDYA L.ETCISSUE
jsr CS.RUN.DUMPFILE
2019-06-07 15:02:51 +00:00
>PUSHWZ Dry Run, no output
2019-06-06 06:37:30 +00:00
* lda #0 ROOT user
2019-03-12 14:41:55 +00:00
>SYSCALL GetPWUID
2019-06-06 15:45:40 +00:00
bcc CS.RUN.AUTH
*--------------------------------------
CS.RUN.NOAUTH >PUSHBI 0
>LDYA L.MSG.NOAUTH
>SYSCALL printf
bcs .9
jsr CS.RUN.SetRootSession
bcs .9
2019-03-12 14:41:55 +00:00
2019-06-06 15:45:40 +00:00
jmp CS.RUN.EXEC
.9 rts
2019-04-12 15:41:05 +00:00
*--------------------------------------
CS.RUN.AUTH >LDYA L.LIBCRYPT
>SYSCALL LoadLib
2019-04-16 15:54:56 +00:00
bcs CS.INIT.RTS
2019-03-12 14:41:55 +00:00
2019-04-12 15:41:05 +00:00
sta hLIBCRYPT
2019-04-15 05:40:13 +00:00
lda #3
sta ZPRetryCnt
.1 >PUSHBI 0
2015-06-03 18:30:57 +00:00
>LDYA L.MSG.LOGIN
2018-06-21 15:12:10 +00:00
>SYSCALL printf
bcs .9
2019-04-15 05:40:13 +00:00
lda #16
clc
jsr CS.RUN.GetLine
2019-02-20 16:07:43 +00:00
bcs .9
2019-06-11 05:52:24 +00:00
2019-06-20 15:47:03 +00:00
>PUSHWZ Dry Run
2019-04-15 05:40:13 +00:00
>LDYA ZPGetLinePtr
>SYSCALL GetPWName
ror ZPbValidUser
2019-06-06 15:45:40 +00:00
sta ZPUID
2015-06-03 18:30:57 +00:00
2018-08-22 15:23:27 +00:00
>PUSHBI 0
2015-06-03 18:30:57 +00:00
>LDYA L.MSG.PASSWORD
2018-06-21 15:12:10 +00:00
>SYSCALL printf
bcs .9
2019-06-06 06:37:30 +00:00
lda #32
2019-04-15 05:40:13 +00:00
sec
jsr CS.RUN.GetLine
2019-02-20 16:07:43 +00:00
bcs .9
2019-06-11 05:52:24 +00:00
2018-12-04 13:20:35 +00:00
>PUSHBI 0
2019-04-15 05:40:13 +00:00
>LDYA L.MSG.CRLF
2018-12-04 13:20:35 +00:00
>SYSCALL printf
bcs .9
2019-04-12 15:41:05 +00:00
2019-04-16 15:54:56 +00:00
jsr CS.RUN.CHECKPWD
2019-06-06 15:45:40 +00:00
bcs .8
2019-04-15 05:40:13 +00:00
2019-06-06 15:45:40 +00:00
jsr CS.RUN.SetUserSession
bcs .9
jmp CS.RUN.EXEC
.8 >PUSHBI 0
2019-04-15 05:40:13 +00:00
>LDYA L.MSG.BAD
>SYSCALL printf
bcs .9
dec ZPRetryCnt
2019-06-06 06:37:30 +00:00
beq .99
2019-04-15 05:40:13 +00:00
2019-06-06 06:37:30 +00:00
jmp .1
.99 lda #E.IUSR
sec
2019-04-15 05:40:13 +00:00
.9 rts
*--------------------------------------
2019-04-16 15:54:56 +00:00
CS.RUN.SetRootSession
>LDYA L.SESSION.ROOT
2019-04-17 06:22:23 +00:00
>STYA ZPStrPtr
2019-04-16 15:54:56 +00:00
>LDYAI SESSION.ROOT.Size
>SYSCALL getmem
bcs .9
>STYA pSession
stx ZPhSID
ldy #SESSION.ROOT.Size-1
2019-04-17 06:22:23 +00:00
.1 lda (ZPStrPtr),y
2019-04-16 15:54:56 +00:00
sta (pSession),y
dey
2019-04-17 06:22:23 +00:00
bpl .1
2019-04-16 15:54:56 +00:00
* clc
.9 rts
*--------------------------------------
CS.RUN.SetUserSession
2019-04-23 15:47:40 +00:00
ldx #S.SESSION.NAME P+UID+GID
2019-04-16 15:54:56 +00:00
ldy #S.PW.NAME-1
2019-06-06 06:37:30 +00:00
jsr CS.RUN.AddStrLen NAME len
2019-04-16 15:54:56 +00:00
inx
ldy #S.PW.GECOS-1
2019-06-06 06:37:30 +00:00
jsr CS.RUN.AddStrLen GECOS len
2019-04-16 15:54:56 +00:00
inx
ldy #S.PW.DIR-1
2019-06-06 06:37:30 +00:00
jsr CS.RUN.AddStrLen DIR len
2019-04-16 15:54:56 +00:00
inx
2019-04-15 15:29:07 +00:00
2019-04-16 15:54:56 +00:00
ldy #S.PW.SHELL-1
2019-04-15 15:29:07 +00:00
2019-06-06 06:37:30 +00:00
jsr CS.RUN.AddStrLen SHELL len
2019-04-16 15:54:56 +00:00
2019-04-15 15:29:07 +00:00
txa
2019-04-16 15:54:56 +00:00
tay
lda #0
2019-04-15 15:29:07 +00:00
>SYSCALL getmem
2018-11-23 16:20:19 +00:00
bcs .9
2019-04-16 15:54:56 +00:00
>STYA pSession
>STYA ZPStrPtr
2019-04-26 15:07:22 +00:00
2019-04-16 15:54:56 +00:00
stx ZPhSID
* clc
2019-04-26 15:07:22 +00:00
2019-04-16 15:54:56 +00:00
ldy #S.PW.GID
2019-06-06 06:37:30 +00:00
lda (ZPPWPtr),y
2019-04-16 15:54:56 +00:00
tax
bne .5
2018-11-23 16:20:19 +00:00
2019-04-16 15:54:56 +00:00
sec
2018-11-23 16:20:19 +00:00
2019-04-16 15:54:56 +00:00
.5 ldy #S.PW.UID
2019-06-06 06:37:30 +00:00
lda (ZPPWPtr),y
2019-04-16 15:54:56 +00:00
bne .6
2019-04-15 15:29:07 +00:00
2017-01-12 17:43:45 +00:00
sec
2019-04-15 05:40:13 +00:00
2019-04-16 15:54:56 +00:00
.6 lda #0
ror
jsr CS.RUN.AddByte PRIV
2019-06-06 06:37:30 +00:00
lda (ZPPWPtr),y
2019-04-16 15:54:56 +00:00
jsr CS.RUN.AddByte UID
txa
jsr CS.RUN.AddByte GID
2019-04-15 05:40:13 +00:00
2019-04-16 15:54:56 +00:00
ldy #S.PW.NAME
jsr CS.RUN.AddStr
2019-04-12 15:41:05 +00:00
2019-04-16 15:54:56 +00:00
ldy #S.PW.GECOS
jsr CS.RUN.AddStr
2019-04-12 15:41:05 +00:00
2019-04-16 15:54:56 +00:00
ldy #S.PW.DIR
jsr CS.RUN.AddStr
ldy #S.PW.SHELL
jsr CS.RUN.AddStr
lda #0
jsr CS.RUN.AddByte
clc
.9 rts
*--------------------------------------
2019-06-06 15:45:40 +00:00
CS.RUN.CHECKPWD rol ZPbValidUser
bcs CS.RUN.CHECK.9
>LDYAI S.PW
>SYSCALL getmem
bcs CS.RUN.CHECK.9
>STYA ZPPWPtr
stx ZPhPW
>PUSHYA
lda ZPUID
>SYSCALL GetPWUID
bcs CS.RUN.CHECK.9
>PUSHW ZPGetlinePtr
>PUSHW ZPGetlinePtr
>LIBCALL hLIBCRYPT,LIBCRYPT.MD5
lda ZPPWPtr
clc
adc #S.PW.PASSWD
tay
lda ZPPWPtr+1
adc /S.PW.PASSWD
>PUSHYA
>LDYA ZPGetlinePtr
>SYSCALL strcmp
CS.RUN.CHECK.9 rts
*--------------------------------------
CS.RUN.EXEC ldx #1
.1 lda S.Table.hSession-1,x
beq .2
inx
cpx #K.USR.MAX+1
bne .1
lda #E.OOH
* sec
rts
.2 stx ZPUsrID
txa
ldy #S.PS.hSID
sta (pPS),y
lda ZPhSID
ldx ZPUsrID
sta S.Table.hSession-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
>PUSHBI S.PS.F.HOLD
>LDYA L.SHELL
>SYSCALL ExecL
bcs .9
>SLEEP
ldx ZPUsrID
lda S.Table.hSession-1,x
stz S.Table.hSession-1,x
stz S.Table.hFILE-1,x
>SYSCALL freemem
sec
.9 rts
*--------------------------------------
2019-06-06 06:37:30 +00:00
CS.RUN.AddStrLen
.1 inx
iny
lda (ZPPWPtr),y
bne .1
rts
*--------------------------------------
CS.RUN.AddStr lda (ZPPWPtr),y
2019-04-16 15:54:56 +00:00
jsr CS.RUN.AddByte
iny
tax
bne CS.RUN.AddStr
2015-06-03 18:30:57 +00:00
rts
*--------------------------------------
2019-04-16 15:54:56 +00:00
CS.RUN.AddByte sta (ZPStrPtr)
inc ZPStrPtr
bne .8
inc ZPStrPtr+1
.8 rts
*--------------------------------------
2019-04-15 05:40:13 +00:00
CS.RUN.GetLine sta ZPGetLineMax
ror ZPbGetLineSecret
stz ZPGetLineLen
2019-04-29 15:47:17 +00:00
stz ZPbEsc
2015-06-03 18:30:57 +00:00
2019-04-15 05:40:13 +00:00
.1 >SYSCALL getchar
bcs .9
2015-06-03 18:30:57 +00:00
2019-04-29 15:47:17 +00:00
bit ZPbEsc
bpl .11
2019-05-04 21:13:50 +00:00
* clc
2019-04-29 15:47:17 +00:00
ror ZPbEsc
cmp #'D'
bne .1
bra .3
.11 cmp #C.DEL
beq .3
2019-04-15 05:40:13 +00:00
cmp #C.SPACE
2015-06-03 18:30:57 +00:00
bcc .2
2019-04-15 05:40:13 +00:00
ldy ZPGetLineLen
cpy ZPGetLineMax
beq .1
2018-12-04 13:20:35 +00:00
2019-04-15 05:40:13 +00:00
sta (ZPGetLinePtr),y
2019-04-29 15:47:17 +00:00
inc ZPGetLineLen
2018-12-04 13:20:35 +00:00
2019-04-15 05:40:13 +00:00
bit ZPbGetLineSecret
bmi .1
2015-06-03 18:30:57 +00:00
2019-04-15 05:40:13 +00:00
>SYSCALL putchar
bra .1
2018-12-04 13:20:35 +00:00
2019-04-15 05:40:13 +00:00
.2 cmp #3 Ctrl-C
beq .9
cmp #C.CR
beq .8
2019-04-29 15:47:17 +00:00
cmp #C.ESC
2019-04-15 05:40:13 +00:00
bne .1
2018-12-04 13:20:35 +00:00
2019-04-29 15:47:17 +00:00
* sec
ror ZPbEsc
bra .1
.3 ldy ZPGetLineLen
2018-12-04 13:20:35 +00:00
beq .1
2019-04-15 05:40:13 +00:00
dec ZPGetLineLen
2018-12-04 13:20:35 +00:00
2019-04-15 05:40:13 +00:00
bit ZPbGetLineSecret
bmi .1
2018-12-04 13:20:35 +00:00
>PUSHBI 0
2019-04-15 05:40:13 +00:00
>LDYA L.MSG.BS
2018-12-04 13:20:35 +00:00
>SYSCALL printf
2019-04-15 05:40:13 +00:00
bra .1
2018-12-04 13:20:35 +00:00
2019-04-15 05:40:13 +00:00
.8 ldy ZPGetLineLen
lda #0
sta (ZPGetLinePtr),y
clc
.9 rts
2015-06-03 18:30:57 +00:00
*--------------------------------------
2019-04-16 15:54:56 +00:00
CS.RUN.DumpFile pha
2019-06-07 15:02:51 +00:00
>PUSHWZ Aux type
2019-04-16 15:54:56 +00:00
>PUSHBI S.FI.T.TXT
>PUSHBI O.RDONLY+O.TEXT
pla
>SYSCALL FOpen
bcs .9
stx ZPhFile
2019-06-06 06:37:30 +00:00
>LDYAI 256
>SYSCALL getmem
bcs .99
>STYA ZPBufPtr
stx ZPhBuf
2019-04-16 15:54:56 +00:00
.1 >PUSHWI 256
2019-06-06 06:37:30 +00:00
>PUSHW ZPBufPtr
2019-04-16 15:54:56 +00:00
lda ZPhFile
>SYSCALL fgets
2019-06-06 06:37:30 +00:00
bcs .7
2019-04-16 15:54:56 +00:00
2019-06-06 06:37:30 +00:00
>LDYA ZPBufPtr
2019-04-16 15:54:56 +00:00
>SYSCALL ExpandStr
bcc .2
2019-06-06 06:37:30 +00:00
.99 php
2019-04-16 15:54:56 +00:00
pha
jsr .8
pla
plp
2019-06-06 06:37:30 +00:00
.9 rts
2019-04-16 15:54:56 +00:00
.2 phx
2019-06-06 06:37:30 +00:00
>SYSCALL puts
2019-04-16 15:54:56 +00:00
pla
>SYSCALL freemem
bra .1
2019-06-06 06:37:30 +00:00
.7 lda ZPhBuf
>SYSCALL freemem
2019-04-16 15:54:56 +00:00
.8 lda ZPhFile
>SYSCALL fclose
2019-06-06 06:37:30 +00:00
rts
2019-04-16 15:54:56 +00:00
*--------------------------------------
CS.DOEVENT
sec
rts
*--------------------------------------
2019-06-06 06:37:30 +00:00
CS.QUIT lda hLIBCRYPT
beq CS.CLEANUP
2019-04-16 15:54:56 +00:00
2019-06-06 06:37:30 +00:00
>SYSCALL UnloadLib
CS.CLEANUP lda ZPhGetLine
beq .1
stz ZPhGetLine
2019-04-16 15:54:56 +00:00
>SYSCALL freemem
2019-06-06 06:37:30 +00:00
.1 lda ZPhPW
2019-04-16 15:54:56 +00:00
beq .8
2019-06-06 06:37:30 +00:00
stz ZPhPW
>SYSCALL freemem
2019-04-16 15:54:56 +00:00
.8 clc
rts
*--------------------------------------
2015-06-03 18:30:57 +00:00
CS.END
2019-04-12 15:41:05 +00:00
*--------------------------------------
LIBCRYPT .AZ "libcrypt"
hLIBCRYPT .BS 1
2019-04-15 15:29:07 +00:00
MSG.NOAUTH .AS "\r\n\r\nA2osX-Login:No ETC/PASSWD file present, Logged as ROOT.\r\n"
2019-04-15 05:40:13 +00:00
.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:"
2019-04-15 05:40:13 +00:00
MSG.BAD .AZ "Bad user or password\r\n"
MSG.BS .DA #C.BS,#C.SPACE,#C.BS,#0
2019-04-16 15:54:56 +00:00
ETCISSUE .AZ "${ROOT}ETC/ISSUE"
ETCMOTD .AZ "${ROOT}ETC/MOTD"
SHELL .AZ "${SHELL}"
2019-04-15 15:29:07 +00:00
*--------------------------------------
2019-04-19 05:42:43 +00:00
SESSION.ROOT .DA #S.SESSION.P.ROOT
2019-04-15 15:29:07 +00:00
.DA #0 UID
.DA #0 GID
.AZ "ROOT" NAME
.AZ "Root User" GECOS
.AZ "${ROOT}ROOT/" DIR
.AZ "${ROOT}BIN/SH" SHELL
2019-04-16 15:54:56 +00:00
SESSION.ROOT.Size .EQ *-SESSION.ROOT
*--------------------------------------
2015-06-03 18:30:57 +00:00
.DUMMY
.OR 0
DS.START
DS.END
.ED
*--------------------------------------
MAN
2018-11-17 17:17:13 +00:00
SAVE USR/SRC/SBIN/LOGIN.S
2015-06-03 18:30:57 +00:00
ASM