Kernel 0.93

This commit is contained in:
Rémy GIBERT 2019-04-16 16:54:56 +01:00
parent d93db0b7ce
commit 2232b123ed
8 changed files with 282 additions and 143 deletions

View File

@ -18,9 +18,7 @@ CL.Quit >LDA.G CL.hCLBuf
.9 rts .9 rts
*-------------------------------------- *--------------------------------------
CL.PrintPrompt >LDYA L.ENV.PS1 CL.PrintPrompt >LDYA L.PS1
>SYSCALL GetEnv
bcs .1
>SYSCALL ExpandStr >SYSCALL ExpandStr
bcs .9 bcs .9

View File

@ -78,13 +78,7 @@ CMD.CD lda (ZPArgVBufPtr)
CMD.CD.0 >LDYA ZPArgVBufPtr CMD.CD.0 >LDYA ZPArgVBufPtr
bra CMD.CD.YA bra CMD.CD.YA
CMD.CD.HOME >LDYA L.ENV.HOME CMD.CD.HOME >LDYA L.HOME
>SYSCALL GetEnv
bcc CMD.CD.YA
>LDYA L.ENV.ROOT
>SYSCALL GetEnv
bcs CMD.PWD
CMD.CD.YA >SYSCALL realpath CMD.CD.YA >SYSCALL realpath
bcs CMD.POPD.RTS bcs CMD.POPD.RTS

View File

@ -115,11 +115,6 @@ L.MSG.BATCHERR .DA MSG.BATCHERR
L.MSG.ERROR .DA MSG.ERROR L.MSG.ERROR .DA MSG.ERROR
L.MSG.PRINTENV .DA MSG.PRINTENV L.MSG.PRINTENV .DA MSG.PRINTENV
L.MSG.PID .DA MSG.PID L.MSG.PID .DA MSG.PID
L.ENV.ROOT .DA ENV.ROOT
L.ENV.PATH .DA ENV.PATH
L.ENV.PWD .DA ENV.PWD
L.ENV.PS1 .DA ENV.PS1
L.ENV.HOME .DA ENV.HOME
L.FMT.DATE .DA FMT.DATE L.FMT.DATE .DA FMT.DATE
L.FMT.TIME .DA FMT.TIME L.FMT.TIME .DA FMT.TIME
L.FMT.GETKEY .DA FMT.GETKEY L.FMT.GETKEY .DA FMT.GETKEY
@ -189,7 +184,9 @@ J.EXP.OP.MATH .DA M32.Add
.DA M32.Div .DA M32.Div
.DA M32.Mod .DA M32.Mod
L.EXP.OP.LOGIC .DA EXP.OP.LOGIC L.EXP.OP.LOGIC .DA EXP.OP.LOGIC
L.HOME .DA HOME
L.HOME.PROFILE .DA HOME.PROFILE L.HOME.PROFILE .DA HOME.PROFILE
L.PS1 .DA PS1
L.M32.Printf .DA M32.Printf L.M32.Printf .DA M32.Printf
L.ERR.Codes .DA ERR.Codes L.ERR.Codes .DA ERR.Codes
L.ERR.Messages .DA ERR.Messages L.ERR.Messages .DA ERR.Messages
@ -589,12 +586,9 @@ FMT.DATE .AZ "%A (%w), %B %d %Y"
FMT.TIME .AZ "%H:%M:%S (%I:%M:%S%p)" FMT.TIME .AZ "%H:%M:%S (%I:%M:%S%p)"
FMT.GETKEY .AZ "%d" FMT.GETKEY .AZ "%d"
*-------------------------------------- *--------------------------------------
ENV.ROOT .AZ "ROOT" HOME .AZ "${HOME}"
ENV.PATH .AZ "PATH"
ENV.PWD .AZ "PWD"
ENV.PS1 .AZ "PS1"
ENV.HOME .AZ "HOME"
HOME.PROFILE .AZ "${HOME}PROFILE" HOME.PROFILE .AZ "${HOME}PROFILE"
PS1 .AZ "${PS1}"
.HS 00 To Make It ArgV .HS 00 To Make It ArgV
*-------------------------------------- *--------------------------------------
CMD .AZ ".." CMD .AZ ".."

View File

@ -50,12 +50,10 @@ CS.RUN >LDYA L.MSG0
ldx #1 ldx #1
stx USRID stx USRID
>DEBUG .1 lda S.Table.hPW-1,x
.1 lda USR.Table.hPW-1,x
beq .7 beq .7
lda USR.Table.hFile-1,x lda S.Table.hFile-1,x
tax tax
jsr CS.RUN.GETIO jsr CS.RUN.GETIO
@ -63,21 +61,21 @@ CS.RUN >LDYA L.MSG0
>PUSHYA >PUSHYA
ldx USRID ldx USRID
lda USR.Table.hPW-1,x lda S.Table.hPW-1,x
>SYSCALL GetMemPtr >SYSCALL GetMemPtr
>STYA ZPPWPtr >STYA ZPPWPtr
lda ZPPWPtr lda ZPPWPtr
clc clc
adc #S.USR.NAME adc #S.SESSION.NAME
tay tay
lda ZPPWPtr+1 lda ZPPWPtr+1
adc /S.USR.NAME adc /S.SESSION.NAME
>PUSHYA >PUSHYA
>PUSHB (ZPPWPtr) >PUSHB (ZPPWPtr)
ldy #S.USR.UID ldy #S.SESSION.UID
>PUSHB (ZPPWPtr),y >PUSHB (ZPPWPtr),y
>PUSHB USRID >PUSHB USRID
@ -122,7 +120,7 @@ CS.QUIT clc
rts rts
*-------------------------------------- *--------------------------------------
CS.END CS.END
MSG0 .AZ "Usr UID Privileges Name Dev" MSG0 .AZ "SID UID Privileges Name Dev"
MSG1 .AZ "%3d %3d %b %16s %16s\r\n" MSG1 .AZ "%3d %3d %b %16s %16s\r\n"
*-------------------------------------- *--------------------------------------
.DUMMY .DUMMY

View File

@ -635,14 +635,13 @@ S.PW.SHELL .EQ 182 64+1
* *
S.PW .EQ 247 S.PW .EQ 247
*-------------------------------------- *--------------------------------------
S.USR.PRIV .EQ 0 S.SESSION.PRIV .EQ 0
S.USR.UID .EQ 1 S.SESSION.UID .EQ 1
S.USR.GID .EQ 2 S.SESSION.GID .EQ 2
S.USR.PASSWD .EQ 3 S.SESSION.NAME .EQ 3
S.USR.NAME .EQ 20 *S.SESSION.GECOS .EQ 0
*S.USR.GECOS .EQ 0 *S.SESSION.DIR .EQ 0
*S.USR.DIR .EQ 0 *S.SESSION.SHELL .EQ 0
*S.USR.SHELL .EQ 0
* *
*-------------------------------------- *--------------------------------------
MAN MAN

View File

@ -8,6 +8,7 @@ NEW
.INB INC/MACROS.I .INB INC/MACROS.I
.INB INC/A2OSX.I .INB INC/A2OSX.I
.INB INC/KERNEL.I .INB INC/KERNEL.I
.INB INC/MLI.I
.INB INC/LIBCRYPT.I .INB INC/LIBCRYPT.I
*-------------------------------------- *--------------------------------------
.DUMMY .DUMMY
@ -15,7 +16,7 @@ NEW
ZS.START ZS.START
ZPUsrID .BS 1 ZPUsrID .BS 1
ZPUsrPtr .BS 2 ZPUsrPtr .BS 2
ZPSessionPtr .BS 2
ZPShellPtr .BS 2 ZPShellPtr .BS 2
ZPRetryCnt .BS 1 ZPRetryCnt .BS 1
ZPbValidUser .BS 1 ZPbValidUser .BS 1
@ -25,11 +26,14 @@ ZPGetLinePtr .BS 2
ZPbGetLineSecret .BS 1 ZPbGetLineSecret .BS 1
ZPGetLineLen .BS 1 ZPGetLineLen .BS 1
ZPGetLineMax .BS 1 ZPGetLineMax .BS 1
ZPhSID .BS 1
ZPhFile .BS 1
ZPStrPtr .BS 2
ZS.END ZS.END
.ED .ED
*-------------------------------------- *--------------------------------------
INPUT.BUF.SIZE .EQ 16
*--------------------------------------
* File Header (16 Bytes) * File Header (16 Bytes)
*-------------------------------------- *--------------------------------------
CS.START cld CS.START cld
@ -57,34 +61,38 @@ L.MSG.PASSWORD .DA MSG.PASSWORD
L.MSG.BAD .DA MSG.BAD L.MSG.BAD .DA MSG.BAD
L.MSG.CRLF .DA MSG.CRLF L.MSG.CRLF .DA MSG.CRLF
L.MSG.BS .DA MSG.BS L.MSG.BS .DA MSG.BS
L.USR.ROOT .DA USR.ROOT L.SESSION.ROOT .DA SESSION.ROOT
L.ETCISSUE .DA ETCISSUE
L.ETCMOTD .DA ETCMOTD
L.SHELL .DA SHELL
.DA 0 .DA 0
*-------------------------------------- *--------------------------------------
CS.INIT clc CS.INIT clc
rts CS.INIT.RTS rts
*-------------------------------------- *--------------------------------------
CS.RUN >PUSHW pData PW CS.RUN >LDYAI 256
>SYSCALL getmem
bcs CS.INIT.RTS
>STYA ZPGetLinePtr
stx ZPhGetLine
>LDYA L.ETCISSUE
jsr CS.RUN.DUMPFILE
>PUSHW pData PW
lda #0 lda #0
>SYSCALL GetPWUID >SYSCALL GetPWUID
bcc CS.RUN.AUTH bcc CS.RUN.AUTH
jmp CS.RUN.NOAUTH jmp CS.RUN.NOAUTH
CS.RUN.9 rts
*-------------------------------------- *--------------------------------------
CS.RUN.AUTH >LDYA L.LIBCRYPT CS.RUN.AUTH >LDYA L.LIBCRYPT
>SYSCALL LoadLib >SYSCALL LoadLib
bcs CS.RUN.9 bcs CS.INIT.RTS
sta hLIBCRYPT sta hLIBCRYPT
>LDYAI 256
>SYSCALL getmem
bcs CS.RUN.9
>STYA ZPGetLinePtr
stx ZPhGetLine
lda #3 lda #3
sta ZPRetryCnt sta ZPRetryCnt
@ -118,7 +126,7 @@ CS.RUN.AUTH >LDYA L.LIBCRYPT
>SYSCALL printf >SYSCALL printf
bcs .9 bcs .9
jsr CS.RUN.CHECK jsr CS.RUN.CHECKPWD
bcc CS.RUN.LOGIN bcc CS.RUN.LOGIN
>PUSHBI 0 >PUSHBI 0
@ -133,7 +141,7 @@ CS.RUN.AUTH >LDYA L.LIBCRYPT
* sec * sec
.9 rts .9 rts
*-------------------------------------- *--------------------------------------
CS.RUN.CHECK rol ZPbValidUser CS.RUN.CHECKPWD rol ZPbValidUser
bcs CS.RUN.CHECK.9 bcs CS.RUN.CHECK.9
>PUSHW ZPGetlinePtr >PUSHW ZPGetlinePtr
@ -146,72 +154,37 @@ CS.RUN.CHECK rol ZPbValidUser
CS.RUN.CHECK.9 rts CS.RUN.CHECK.9 rts
*-------------------------------------- *--------------------------------------
CS.RUN.LOGIN jsr CS.RUN.SetUserSession
bcc CS.RUN.EXEC
CS.RUN.LOGIN.9 rts
*--------------------------------------
CS.RUN.NOAUTH >PUSHBI 0 CS.RUN.NOAUTH >PUSHBI 0
>LDYA L.MSG.NOAUTH >LDYA L.MSG.NOAUTH
>SYSCALL printf >SYSCALL printf
bcs CS.RUN.CHECK.9 bcs CS.RUN.CHECK.9
>LDYA L.USR.ROOT jsr CS.RUN.SetRootSession
bcs CS.RUN.LOGIN.9
CS.RUN.LOGIN jsr CS.RUN.SETUSER CS.RUN.EXEC ldx #1
bcs .9
>PUSHBI S.PS.F.HOLD
lda ZPUsrPtr
clc
adc #S.USR.NAME
sta ZPUsrPtr
lda ZPUsrPtr+1
adc /S.USR.NAME
sta ZPUsrPtr+1
ldx #3 Skip NAME,GECOS,DIR
.1 ldy #$ff
.2 iny
lda (ZPUsrPtr),y
bne .2
tya
sec
adc ZPUsrPtr
sta ZPUsrPtr
bcc .3
inc ZPUsrPtr+1
.3 dex
bne .1
>LDYA ZPUsrPtr
>SYSCALL ExecL
bcs .9
ldx ZPUsrID
lda S.Table.hPW-1,x
stz S.Table.hPW-1,x
stz S.Table.hFILE-1,x
>SYSCALL freemem
.9 rts
*--------------------------------------
CS.RUN.SETUSER >STYA ZPUsrPtr
ldx #1
.1 lda S.Table.hPW-1,x .1 lda S.Table.hPW-1,x
bne .7 beq .2
inx
cpx #K.USR.MAX+1
bne .1
stx ZPUsrID lda #E.OOH
* sec
rts
.2 stx ZPUsrID
txa txa
ldy #S.PS.hSID ldy #S.PS.hSID
sta (pPS),y sta (pPS),y
>LDYAI USR.ROOT.Size
>SYSCALL getmem
bcs .9
>STYA ZPSessionPtr
txa txa
ldx ZPUsrID ldx ZPUsrID
sta S.Table.hPW-1,x sta S.Table.hPW-1,x
@ -220,38 +193,145 @@ CS.RUN.SETUSER >STYA ZPUsrPtr
lda (pPS),y lda (pPS),y
sta S.Table.hFILE-1,x sta S.Table.hFILE-1,x
ldy #USR.ROOT.Size-1 >LDYA L.ETCMOTD
jsr CS.RUN.DumpFile
>PUSHBI S.PS.F.HOLD
>LDYA L.SHELL
>SYSCALL ExecL
bcs .9
>SLEEP
ldx ZPUsrID
lda S.Table.hPW-1,x
stz S.Table.hPW-1,x
stz S.Table.hFILE-1,x
>SYSCALL freemem
.9 rts
*--------------------------------------
CS.RUN.SetRootSession
>LDYA L.SESSION.ROOT
>STYA ZPUsrPtr
>LDYAI SESSION.ROOT.Size
>SYSCALL getmem
bcs .9
>STYA pSession
stx ZPhSID
ldy #SESSION.ROOT.Size-1
.2 lda (ZPUsrPtr),y .2 lda (ZPUsrPtr),y
sta (ZPSessionPtr),y sta (pSession),y
dey dey
bpl .2 bpl .2
clc * clc
rts
.7 inx
cpx #K.USR.MAX+1
bne .1
* sec
.9 rts .9 rts
*-------------------------------------- *--------------------------------------
CS.DOEVENT CS.RUN.SetUserSession
ldx #S.SESSION.NAME PRIV+UID+GID
ldy #S.PW.NAME-1
.1 inx
iny
lda (pData),y
bne .1 NAME len
inx
ldy #S.PW.GECOS-1
.2 inx
iny
lda (pData),y
bne .2 GECOS len
inx
ldy #S.PW.DIR-1
.3 inx
iny
lda (pData),y
bne .3 DIR len
inx
ldy #S.PW.SHELL-1
.4 inx
iny
lda (pData),y
bne .4 SHELL len
txa
tay
lda #0
>SYSCALL getmem
bcs .9
>STYA pSession
>STYA ZPStrPtr
stx ZPhSID
* clc
ldy #S.PW.GID
lda (pData),y
tax
bne .5
sec sec
.5 ldy #S.PW.UID
lda (pData),y
bne .6
sec
.6 lda #0
ror
jsr CS.RUN.AddByte PRIV
lda (pData),y
jsr CS.RUN.AddByte UID
txa
jsr CS.RUN.AddByte GID
ldy #S.PW.NAME
jsr CS.RUN.AddStr
ldy #S.PW.GECOS
jsr CS.RUN.AddStr
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
*--------------------------------------
CS.RUN.AddStr lda (pData),y
jsr CS.RUN.AddByte
iny
tax
bne CS.RUN.AddStr
rts rts
*-------------------------------------- *--------------------------------------
CS.QUIT lda ZPhGetLine CS.RUN.AddByte sta (ZPStrPtr)
beq .1 inc ZPStrPtr
bne .8
>SYSCALL freemem inc ZPStrPtr+1
.8 rts
.1 lda hLIBCRYPT
beq .8
>SYSCALL UnloadLib
.8 clc
rts
*-------------------------------------- *--------------------------------------
CS.RUN.GetLine sta ZPGetLineMax CS.RUN.GetLine sta ZPGetLineMax
ror ZPbGetLineSecret ror ZPbGetLineSecret
@ -306,6 +386,84 @@ CS.RUN.GetLine sta ZPGetLineMax
.9 rts .9 rts
*-------------------------------------- *--------------------------------------
CS.RUN.DumpFile pha
>PUSHWI 0 Aux type
>PUSHBI S.FI.T.TXT
>PUSHBI O.RDONLY+O.TEXT
pla
>SYSCALL FOpen
bcs .9
stx ZPhFile
.1 >PUSHWI 256
>PUSHW ZPGetLinePtr
lda ZPhFile
>SYSCALL fgets
bcs .8
>LDYA ZPGetLinePtr
>SYSCALL ExpandStr
bcc .2
php
pha
jsr .8
pla
plp
rts
.2 phx
>STYA ZPStrPtr
ldy #$ff
.3 iny
lda (ZPStrPtr),y
bne .3
lda #C.CR
sta (ZPStrPtr),y
iny
lda #C.LF
sta (ZPStrPtr),y
iny
lda #0
sta (ZPStrPtr),y
>PUSHBI 0
>LDYA ZPStrPtr
>SYSCALL printf
pla
>SYSCALL freemem
bra .1
.8 lda ZPhFile
>SYSCALL fclose
.9 rts
*--------------------------------------
CS.DOEVENT
sec
rts
*--------------------------------------
CS.QUIT lda ZPhGetLine
beq .1
>SYSCALL freemem
.1 lda hLIBCRYPT
beq .8
>SYSCALL UnloadLib
.8 clc
rts
*--------------------------------------
CS.END CS.END
*-------------------------------------- *--------------------------------------
LIBCRYPT .AZ "libcrypt" LIBCRYPT .AZ "libcrypt"
@ -317,17 +475,18 @@ MSG.LOGIN .AZ "\r\nlogin:"
MSG.PASSWORD .AZ "\r\npassword:" MSG.PASSWORD .AZ "\r\npassword:"
MSG.BAD .AZ "Bad user or password\r\n" MSG.BAD .AZ "Bad user or password\r\n"
MSG.BS .DA #C.BS,#C.SPACE,#C.BS,#0 MSG.BS .DA #C.BS,#C.SPACE,#C.BS,#0
.HS 00 ETCISSUE .AZ "${ROOT}ETC/ISSUE"
ETCMOTD .AZ "${ROOT}ETC/MOTD"
SHELL .AZ "${SHELL}"
*-------------------------------------- *--------------------------------------
USR.ROOT .DA #P.SYSADMIN SESSION.ROOT .DA #P.SYSADMIN
.DA #0 UID .DA #0 UID
.DA #0 GID .DA #0 GID
.BS 17 PASSWD
.AZ "ROOT" NAME .AZ "ROOT" NAME
.AZ "Root User" GECOS .AZ "Root User" GECOS
.AZ "${ROOT}ROOT/" DIR .AZ "${ROOT}ROOT/" DIR
.AZ "${ROOT}BIN/SH" SHELL .AZ "${ROOT}BIN/SH" SHELL
USR.ROOT.Size .EQ *-USR.ROOT SESSION.ROOT.Size .EQ *-SESSION.ROOT
*-------------------------------------- *--------------------------------------
.DUMMY .DUMMY
.OR 0 .OR 0

View File

@ -532,7 +532,7 @@ ENV.SysVarsJmp .DA ENV.SysVarsArgs
.DA ENV.SysVarsPID .DA ENV.SysVarsPID
.DA ENV.SysVarsCPID .DA ENV.SysVarsCPID
*-------------------------------------- *--------------------------------------
ENV.StrVars >PSTR "USERNAME" ENV.StrVars >PSTR "LOGNAME"
>PSTR "GECOS" >PSTR "GECOS"
>PSTR "HOME" >PSTR "HOME"
>PSTR "SHELL" >PSTR "SHELL"
@ -554,20 +554,18 @@ ENV.StrVarsPWD ldy #S.PS.hPREFIX
jsr K.GetMemPtr jsr K.GetMemPtr
jmp ENV.AddYAToBuf jmp ENV.AddYAToBuf
*-------------------------------------- *--------------------------------------
ENV.StrVarsUID ldy #S.USR.UID ENV.StrVarsUID ldy #S.SESSION.UID
.HS 2C .HS 2C
ENV.StrVarsGID ldy #S.USR.GID ENV.StrVarsGID ldy #S.SESSION.GID
lda (pSession),y lda (pSession),y
bra ENV.SysVarsNum bra ENV.SysVarsNum
ENV.StrVarsSession ENV.StrVarsSession
>DEBUG
lda pSession lda pSession
clc clc
adc #S.USR.NAME adc #S.SESSION.NAME
sta ZPPtr3 sta ZPPtr3
lda pSession+1 lda pSession+1
adc /S.USR.NAME adc /S.SESSION.NAME
sta ZPPtr3+1 sta ZPPtr3+1
.1 dex .1 dex

View File

@ -1107,7 +1107,6 @@ PwdMgrInit >LDYAI MSG.PWD
PwdMgr.ROOT .DA #P.SYSADMIN PwdMgr.ROOT .DA #P.SYSADMIN
.DA #0 UID .DA #0 UID
.DA #0 GID .DA #0 GID
.BS 17 PASSWD
.AZ "ROOT" NAME .AZ "ROOT" NAME
.AZ "Root User" GECOS .AZ "Root User" GECOS
.AZ "${ROOT}ROOT/" DIR .AZ "${ROOT}ROOT/" DIR