A2osX/BIN/USERADD.S.txt

436 lines
8.2 KiB
Plaintext
Raw Normal View History

2019-04-09 15:47:33 +00:00
NEW
AUTO 3,1
.LIST OFF
.OP 65C02
.OR $2000
2019-12-05 15:09:38 +00:00
.TF bin/useradd
2019-04-10 15:51:47 +00:00
*--------------------------------------
USER.MAX .EQ 16
PASS.MAX .EQ 64
2019-04-09 15:47:33 +00:00
*--------------------------------------
2020-05-21 12:55:49 +00:00
.INB inc/macros.i
.INB inc/a2osx.i
2019-04-09 15:47:33 +00:00
*--------------------------------------
* Zero Page Segment, up to 32 bytes
*--------------------------------------
.DUMMY
.OR ZPBIN
ZS.START
ZPPWPtr .BS 2
ZPhPW .BS 1
ZPhStr .BS 1
ZPbStrSecret .BS 1
ZPStrLen .BS 1
ZPStrMax .BS 1
2019-04-24 15:34:11 +00:00
ArgIndex .BS 1
2019-04-17 06:22:23 +00:00
ArgUsername .BS 1
ZPStrPtr .BS 2
2019-04-25 15:33:56 +00:00
ZPTmpPtr .BS 2
2019-04-09 15:47:33 +00:00
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 #0 S.PS.F.EVENT
.DA #0
.DA CS.END-CS.START Code Size (without Constants)
2019-04-12 06:24:30 +00:00
.DA DS.END-DS.START Data Segment Size
2019-04-10 15:51:47 +00:00
.DA #64 Stack Size
2019-04-09 15:47:33 +00:00
.DA #ZS.END-ZS.START Zero Page Size
.DA 0
*--------------------------------------
* Relocation Table
2019-10-03 06:25:27 +00:00
*--------------------------------------
2019-04-09 15:47:33 +00:00
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.MSG.USAGE .DA MSG.USAGE
L.MSG.ROOTPWD1 .DA MSG.ROOTPWD1
L.MSG.ROOTPWD2 .DA MSG.ROOTPWD2
2019-04-11 15:59:57 +00:00
L.MSG.MISMATCH .DA MSG.MISMATCH
2019-04-09 15:47:33 +00:00
L.MSG.BS .DA MSG.BS
2019-04-17 06:22:23 +00:00
L.MSG.CRLF .DA MSG.CRLF
2019-04-17 15:31:18 +00:00
J.CS.RUN.CheckArg
.DA CS.RUN.CheckArg.C
.DA CS.RUN.CheckArg.D
.DA CS.RUN.CheckArg.P
.DA CS.RUN.CheckArg.S
2019-04-09 15:47:33 +00:00
.DA 0
*--------------------------------------
* Called once at process creation
* Put code for loading LIB here
*--------------------------------------
2020-01-24 21:53:03 +00:00
CS.INIT clc
rts
2019-04-09 15:47:33 +00:00
*--------------------------------------
* Called until exit with CS
* if RUN exits with CC, RN entered again
*--------------------------------------
CS.RUN >LDYAI S.PW
2020-02-28 07:21:46 +00:00
>SYSCALL GetMem
2019-04-09 15:47:33 +00:00
bcs .99
2020-02-14 07:21:56 +00:00
2019-04-09 15:47:33 +00:00
>STYA ZPPWPtr
stx ZPhPW
2020-02-14 07:21:56 +00:00
2019-04-09 15:47:33 +00:00
>LDYAI 256
2020-02-28 07:21:46 +00:00
>SYSCALL GetMem
2019-04-09 15:47:33 +00:00
bcs .99
2020-02-14 07:21:56 +00:00
2019-04-09 15:47:33 +00:00
>STYA ZPStrPtr
stx ZPhStr
2020-02-14 07:21:56 +00:00
2019-04-09 15:47:33 +00:00
lda #0
2020-02-17 16:55:02 +00:00
>PUSHA
>PUSHW ZPPWPtr
2019-04-09 15:47:33 +00:00
>SYSCALL GetPWUID
bcc .1
2020-02-14 07:21:56 +00:00
2019-04-09 15:47:33 +00:00
jmp CS.RUN.ROOT
2020-02-11 16:32:33 +00:00
2019-04-23 15:47:40 +00:00
.1 ldy #S.PW
2020-02-11 16:32:33 +00:00
2019-04-23 15:47:40 +00:00
.2 dey
lda PW.DEFAULT,y
2019-04-17 15:31:18 +00:00
sta (pData),y
2019-04-23 15:47:40 +00:00
tya
bne .2
2020-02-11 16:32:33 +00:00
2019-04-17 15:31:18 +00:00
jsr CS.RUN.CheckArg
bcs .9
2019-04-17 06:22:23 +00:00
2019-04-24 15:34:11 +00:00
jsr CS.RUN.MkDir
2019-04-25 15:33:56 +00:00
* bcs .99
2020-07-09 11:34:07 +00:00
2020-07-09 06:24:15 +00:00
>PUSHW pData
2019-04-17 15:31:18 +00:00
>SYSCALL putpw
2019-04-25 15:33:56 +00:00
bcs .99
2019-10-11 13:06:33 +00:00
2019-04-25 15:33:56 +00:00
lda #0
2019-04-17 15:31:18 +00:00
sec
rts
2020-02-14 07:21:56 +00:00
2020-05-21 12:55:49 +00:00
.9 >PUSHW L.MSG.USAGE
>PUSHBI 0
2020-02-28 07:21:46 +00:00
>SYSCALL PrintF
2019-04-17 06:22:23 +00:00
lda #E.SYN
2019-04-09 15:47:33 +00:00
sec
.99 rts
*--------------------------------------
2019-04-11 15:59:57 +00:00
CS.RUN.ROOT ldy #0
2019-04-17 06:22:23 +00:00
.1 lda PW.ROOT,y
2019-04-11 15:59:57 +00:00
sta (pData),y PW
iny
cpy #S.PW
bne .1
sec
2019-04-09 15:47:33 +00:00
ror ZPbStrSecret
lda #127
sta ZPStrMax
2020-05-21 12:55:49 +00:00
>PUSHW L.MSG.ROOTPWD1
2019-04-09 15:47:33 +00:00
>PUSHBI 0
2020-02-28 07:21:46 +00:00
>SYSCALL PrintF
2019-04-11 15:59:57 +00:00
bcs .90
2019-04-09 15:47:33 +00:00
jsr CS.RUN.GetStr
2019-04-11 15:59:57 +00:00
bcs .90
2019-04-10 15:51:47 +00:00
2019-04-10 05:51:25 +00:00
>PUSHW ZPStrPtr
2020-01-24 21:53:03 +00:00
>PUSHEA.G PW+S.PW.PASSWD
>SYSCALL MD5
2020-05-21 12:55:49 +00:00
>PUSHW L.MSG.ROOTPWD2
2019-04-11 15:59:57 +00:00
>PUSHBI 0
2020-02-28 07:21:46 +00:00
>SYSCALL PrintF
2019-04-11 15:59:57 +00:00
bcs .9
jsr CS.RUN.GetStr
.90 bcs .9
>PUSHW ZPStrPtr
>PUSHW ZPStrPtr
2020-01-24 21:53:03 +00:00
>SYSCALL MD5
2019-04-11 15:59:57 +00:00
>PUSHW ZPStrPtr
2019-04-10 05:51:25 +00:00
>LEA.G PW+S.PW.PASSWD
2019-04-11 15:59:57 +00:00
>SYSCALL strcmp
bcs .99
2019-10-11 13:06:33 +00:00
2020-07-08 15:26:23 +00:00
>PUSHW pData
2019-04-11 15:59:57 +00:00
>SYSCALL putpw
bcs .9
2019-10-11 13:06:33 +00:00
2019-04-10 05:51:25 +00:00
lda #0
sec
2019-04-09 15:47:33 +00:00
.9 rts
2020-05-21 12:55:49 +00:00
.99 >PUSHW L.MSG.MISMATCH
>PUSHBI 0
2020-02-28 07:21:46 +00:00
>SYSCALL PrintF
2019-04-11 15:59:57 +00:00
lda #E.SYN
sec
rts
2019-04-09 15:47:33 +00:00
*--------------------------------------
CS.RUN.GetStr stz ZPStrLen
.1 >SYSCALL getchar
bcs .9
cmp #C.SPACE
bcc .2
ldy ZPStrLen
cpy ZPStrMax
beq .1
sta (ZPStrPtr),y
iny
sty ZPStrLen
bit ZPbStrSecret
bmi .1
>SYSCALL putchar
bra .1
2019-04-10 15:51:47 +00:00
.2 cmp #3 Ctrl-C
2019-04-09 15:47:33 +00:00
beq .9
cmp #C.CR
beq .8
cmp #C.BS
bne .1
ldy ZPStrLen
beq .1
dec ZPStrLen
bit ZPbStrSecret
bmi .1
2020-05-21 12:55:49 +00:00
>PUSHW L.MSG.BS
2019-04-09 15:47:33 +00:00
>PUSHBI 0
2020-02-28 07:21:46 +00:00
>SYSCALL PrintF
2019-04-09 15:47:33 +00:00
bra .1
2019-04-10 15:51:47 +00:00
.8 ldy ZPStrLen
lda #0
sta (ZPStrPtr),y
2020-05-21 12:55:49 +00:00
>PUSHW L.MSG.CRLF
2019-04-17 06:22:23 +00:00
>PUSHBI 0
2020-02-28 07:21:46 +00:00
>SYSCALL PrintF
2019-04-09 15:47:33 +00:00
.9 rts
*--------------------------------------
2019-04-24 15:34:11 +00:00
CS.RUN.CheckArg inc ArgIndex
lda ArgIndex
2019-04-17 06:22:23 +00:00
>SYSCALL ArgV
bcs .8
2020-07-09 11:34:07 +00:00
2019-04-17 06:22:23 +00:00
>STYA ZPStrPtr
lda (ZPStrPtr)
cmp #'-'
bne .4
2020-02-11 16:32:33 +00:00
2019-04-17 06:22:23 +00:00
ldy #1
lda (ZPStrPtr),y
2020-02-11 16:32:33 +00:00
ldx #OptionCnt-1
2020-02-11 16:32:33 +00:00
.2 cmp OptionList,x
2019-04-17 06:22:23 +00:00
beq .3
dex
2020-02-11 16:32:33 +00:00
bpl .2
2019-04-17 06:22:23 +00:00
lda #E.SYN
sec
rts
2020-02-11 16:32:33 +00:00
2019-04-17 15:31:18 +00:00
.3 txa
and #$fe
tax
jmp (J.CS.RUN.CheckArg,x)
2020-07-09 11:34:07 +00:00
*--------------------------------------
2019-04-17 06:22:23 +00:00
.4 lda ArgUsername
2019-04-24 15:34:11 +00:00
bne CS.RUN.CheckArg.9
2020-07-09 06:24:15 +00:00
2019-04-17 15:31:18 +00:00
lda pData
clc
adc #S.PW.DIR+11
2019-04-25 15:33:56 +00:00
sta ZPTmpPtr
2020-07-09 06:24:15 +00:00
2019-04-17 15:31:18 +00:00
lda pData+1
adc /S.PW.DIR+11
2019-04-25 15:33:56 +00:00
sta ZPTmpPtr+1
2020-07-09 06:24:15 +00:00
2019-04-17 15:31:18 +00:00
ldy #0
2020-07-09 06:24:15 +00:00
2019-04-17 15:31:18 +00:00
.5 lda (ZPStrPtr),y
2019-04-23 15:47:40 +00:00
sta (pData),y
2019-04-25 15:33:56 +00:00
sta (ZPTmpPtr),y
2019-04-17 15:31:18 +00:00
beq .6
2020-07-09 06:24:15 +00:00
2019-04-17 15:31:18 +00:00
iny
cpy #16
bne .5
2020-07-09 06:24:15 +00:00
2019-04-24 15:34:11 +00:00
bra CS.RUN.CheckArg.9
2020-07-09 06:24:15 +00:00
2019-04-24 15:34:11 +00:00
.6 lda #'/'
2019-04-25 15:33:56 +00:00
sta (ZPTmpPtr),y
2019-04-24 15:34:11 +00:00
lda ArgIndex
2019-04-17 06:22:23 +00:00
sta ArgUsername
2019-04-24 15:34:11 +00:00
>SYSCALL ArgV
2020-07-09 11:34:07 +00:00
>PUSHYA
>PUSHW ZPPWPtr
2019-04-24 15:34:11 +00:00
>SYSCALL GetPWName
bcc .9
2020-07-09 06:24:15 +00:00
2019-04-17 15:31:18 +00:00
bra CS.RUN.CheckArg
2020-07-09 06:24:15 +00:00
2019-04-17 15:31:18 +00:00
.8 lda ArgUsername
2019-04-24 15:34:11 +00:00
beq CS.RUN.CheckArg.9
2019-04-17 15:31:18 +00:00
clc
rts
2020-05-21 12:55:49 +00:00
2020-07-09 11:34:07 +00:00
.9 lda #E.DUPUSR
sec
rts
2019-10-11 06:40:08 +00:00
CS.RUN.CheckArg.9
lda #E.SYN
2019-04-17 06:22:23 +00:00
sec
rts
2019-04-24 15:34:11 +00:00
*--------------------------------------
CS.RUN.CheckArg.P
inc ArgIndex
lda ArgIndex
>SYSCALL ArgV
bcs CS.RUN.CheckArg.9
>PUSHYA
2020-01-24 21:53:03 +00:00
>PUSHEA.G S.PW.PASSWD
>SYSCALL MD5
2019-04-24 15:34:11 +00:00
jmp CS.RUN.CheckArg
*--------------------------------------
2019-04-17 15:31:18 +00:00
CS.RUN.CheckArg.C
2019-04-24 15:34:11 +00:00
inc ArgIndex
lda ArgIndex
>SYSCALL ArgV
bcs CS.RUN.CheckArg.9
ldx #S.PW.GECOS
bra CS.RUN.CheckArg.Next
*--------------------------------------
2019-04-17 15:31:18 +00:00
CS.RUN.CheckArg.D
2019-04-24 15:34:11 +00:00
inc ArgIndex
lda ArgIndex
>SYSCALL ArgV
bcs CS.RUN.CheckArg.9
ldx #S.PW.DIR
bra CS.RUN.CheckArg.Next
*--------------------------------------
2019-04-17 15:31:18 +00:00
CS.RUN.CheckArg.S
2019-04-24 15:34:11 +00:00
inc ArgIndex
lda ArgIndex
>SYSCALL ArgV
bcs CS.RUN.CheckArg.9
2020-07-09 11:34:07 +00:00
2019-04-24 15:34:11 +00:00
ldx #S.PW.SHELL
CS.RUN.CheckArg.Next
>STYA ZPStrPtr
2020-07-09 11:34:07 +00:00
2019-04-24 15:34:11 +00:00
* clc
txa
adc pData
2019-04-25 15:33:56 +00:00
sta ZPTmpPtr
2019-04-24 15:34:11 +00:00
lda pData+1
adc #0
2019-04-25 15:33:56 +00:00
sta ZPTmpPtr+1
2020-07-09 11:34:07 +00:00
2019-04-24 15:34:11 +00:00
ldy #$ff
2020-07-09 11:34:07 +00:00
2019-04-24 15:34:11 +00:00
.1 iny
lda (ZPStrPtr),y
2019-04-25 15:33:56 +00:00
sta (ZPTmpPtr),y
2019-04-24 15:34:11 +00:00
beq .8
2020-07-09 11:34:07 +00:00
2019-04-24 15:34:11 +00:00
cpy #64
bne .1
2020-07-09 11:34:07 +00:00
2019-04-24 15:34:11 +00:00
lda #0
2019-04-25 15:33:56 +00:00
sta (ZPTmpPtr),y
2020-07-09 11:34:07 +00:00
2019-04-24 15:34:11 +00:00
.8 jmp CS.RUN.CheckArg
2019-04-17 15:31:18 +00:00
*--------------------------------------
2020-02-29 14:06:28 +00:00
CS.RUN.MkDir >PUSHEA.G S.PW.DIR
>PUSHWI S.STAT.MODE.RO+S.STAT.MODE.RG+S.STAT.MODE.FU
2019-04-24 15:34:11 +00:00
>SYSCALL MKDir
2019-04-17 15:31:18 +00:00
rts
2019-04-17 06:22:23 +00:00
*--------------------------------------
2019-04-09 15:47:33 +00:00
* Called if option S.PS.F.EVENT enabled in Header
* Timer Event : every 10th seconds
*--------------------------------------
CS.DOEVENT sec
rts
*--------------------------------------
* Called once, when RUN exited with CS
* Put code for unloading LIB here
*--------------------------------------
CS.QUIT lda ZPhStr
beq .1
2020-02-28 07:21:46 +00:00
>SYSCALL FreeMem
2019-04-09 15:47:33 +00:00
.1 lda ZPhPW
beq .2
2020-02-28 07:21:46 +00:00
>SYSCALL FreeMem
2020-01-24 21:53:03 +00:00
.2 clc
2019-04-09 15:47:33 +00:00
rts
*--------------------------------------
CS.END
*--------------------------------------
2020-02-11 16:32:33 +00:00
OptionList .AS "CcDdPpSs"
OptionCnt .EQ *-OptionList
2019-04-17 06:22:23 +00:00
*--------------------------------------
2019-04-09 15:47:33 +00:00
* Initialized DATA
*--------------------------------------
2019-04-11 15:59:57 +00:00
MSG.USAGE .AS "Usage : USERADD username\r\n"
2019-04-12 15:41:05 +00:00
.AS " -c : Comment (GECOS)\r\n"
2019-04-11 15:59:57 +00:00
.AS " -d : Home Directory\r\n"
.AS " -p : Password\r\n"
.AS " -s : Shell\r\n"
MSG.CRLF .AZ "\r\n"
2019-04-10 05:51:25 +00:00
MSG.ROOTPWD1 .AZ "\r\nPlease enter ROOT password : "
MSG.ROOTPWD2 .AZ "\r\nPlease retype ROOT password : "
2019-04-11 15:59:57 +00:00
MSG.MISMATCH .AZ "\r\nPasswords mismatch...\r\n"
2019-04-09 15:47:33 +00:00
MSG.BS .DA #C.BS,#C.SPACE,#C.BS,#0
*--------------------------------------
2019-12-05 15:09:38 +00:00
PW.ROOT .AS "root"
2019-04-11 15:59:57 +00:00
.BS 17-4
2020-02-11 16:32:33 +00:00
.AZ "d41d8cd98f00b204e9800998ecf8427e"
2019-04-11 15:59:57 +00:00
.DA #0 UID
.DA #0 GID
.AS "Root User"
.BS 65-9
2019-12-05 15:09:38 +00:00
.AS "${ROOT}root/"
2019-04-11 15:59:57 +00:00
.BS 65-12
2019-12-05 15:09:38 +00:00
.AS "${ROOT}bin/sh"
2019-04-11 15:59:57 +00:00
.BS 65-13
2019-04-09 15:47:33 +00:00
*--------------------------------------
2019-04-17 06:22:23 +00:00
PW.DEFAULT .BS 17 NAME
2020-02-11 16:32:33 +00:00
.AZ "d41d8cd98f00b204e9800998ecf8427e"
2019-04-17 06:22:23 +00:00
.DA #0 UID
2019-04-23 15:47:40 +00:00
.DA #1 GID
2019-04-17 06:22:23 +00:00
.BS 65 GECOS
2019-12-05 15:09:38 +00:00
.AS "${ROOT}usr/"
2019-04-17 06:22:23 +00:00
.BS 65-11
2019-12-05 15:09:38 +00:00
.AS "${ROOT}bin/sh"
2019-04-17 06:22:23 +00:00
.BS 65-13
*--------------------------------------
2019-04-09 15:47:33 +00:00
* Per Process DATA segment
*--------------------------------------
.DUMMY
.OR 0
DS.START
2019-04-11 15:59:57 +00:00
PW .BS S.PW
2019-04-09 15:47:33 +00:00
DS.END
.ED
*--------------------------------------
MAN
2020-05-21 12:55:49 +00:00
SAVE usr/src/bin/useradd.s
2019-04-09 15:47:33 +00:00
ASM