; Copyright (C) 1995 M.J.G. Veltman; All rights reserved.;; This file is part of Vsys, a software development system for the; M680x0 microprocessor.;; Vsys is dual-licensed under the GNU Lesser General Public License and; the BSD 3Clause License.  The aim is to allow the software to be used,; published, developed, and modified in the unrestrictive style of; public scientific research, while ensuring that there is always a; copyleft branch of the software which protects free access to the; original source and to modifications within that branch.;; Vsys is free software.  You can redistribute it and/or modify it under; the terms of the GNU Lesser General Public License as published by the; Free Software Foundation, either version 3 of the License, or (at your; option) any later version.  See the file LICENSE-LGPL.txt at the top; level of this distribution, or see:;;   http://www.gnu.org/licenses/;; You can also redistribute and/or modify Vsys under the terms of the; BSD 3Clause License.  See the file LICENSE-BSD_3Clause.txt at the top; level of this distribution, or see:;;   http://opensource.org/licenses/BSD-3-Clause/;; Users who distribute the software with or without modification are; encouraged to maintain the dual-licensing system..GLOBL _main.DIRECT 2_.SET sheS=32.SET homS=32.SET LinS=160.SET hisT=512.SET CrtL=120.SET CurS=32.SET CrtE=CrtL/8.SET CurE=CurS/8.SET ComS=82		;Max Length Com.sa path..SET SheS=sheS+2.SET HomS=homS+2.SET pasS=2000		;Size of the passwd file..STRUCTURE BSS.LOCALS Point,Line,LinS,Lini,LinS,Laddr,100,Fcol,2,Linp,42.LOCALS Sinit,Pname,Eline,2,Ecnt,2,Time,tapn,pasx,32,uid,16,gid,16,gcos,80.LOCALS home,HomS,shell,SheS,buf,LinS,presult.LOCALS Init,Cnt,2,MMDDYY,hhmmss,Buf,2060,passb,2000,Passbuf,pasS.EQU bssS=.-BSS.STRUCTURE HOLY.TEXTentr: bsr _main |movel D0,-(SP) |bsr .exit;slas: .ASCIZ "/"otxt: .ASCIZ "MicroShell Version 92.\n"path: .ASCIZ "/usr/bin"qtxt: .ASCIZ "No change owner %s.\n"ptxt: .ASCIZ "Unknown Owner.\n"itxt: .ASCIZ "\n"etxt: .ASCIZ "\H\H\H\H\H\H\H\C"init: .ASCIZ ".Init"inib: .ASCIZ "/usr/bin/.Sysinit"txtc: .ASCIZ "Error %s, line %d.\n"txto: .ASCIZ "Cannot open %s.\n"ilib: .ASCIZ "/usr/lib/C\@.sa"_Rhis: .ASCIZ "/usr/lib/y.hi".EVEN;;Commands: Chown and Login;_main: pea bssS |bsr .Getmep 	.ASSUME A4=BSS movel 8(SP),A0 |movel (A0)+,A1 |movel A1,Pname0: lsll #8,D1 |moveb (A1)+,D1 |bne 0b lsrl #8,D1 |orw #0x2020,D1 cmpw #"in",D1 |beq Logi tstl (A0) |beq help cmpw #"wn",D1 |beq Chow	;chown cmpw #"rt",D1 |beq Scrt	;scrt;help: movel Pname,-(SP) |bsr .Help;Logi: .CALL Access(#0,#0) movel D0,Sinit |lea init,A0 |btst #5,D0 beq 9f |.CALL .Fabsrd(&_Rhis,&Buf,#4*hisT+8) tstl D0 |ble 13f |lea Buf,A0 |movew #-1,(A0,D0) divu #hisT+2,D0 |swap D0 |tstw D0 |bne 13f.CALL Geth(&-1,&Buf)13: lea inib,A09: movel A0,Init |btst #5,Sinit+3 |beq 10f lea buf,A0 |movel #"root",(A0)+		;Sysinit. Log in as root. movew #"\n\@",(A0) |moveq #5,D0 |bra 11f10: .CALL Wait(#10) |bsr getr |movel D0,D1	;Login. Allow 10 sec. .CALL Wait(#-1) |movel D1,D0 |bpl 11f lea etxt,A0 |bsr prme |bra nonp11: lea buf,A0 |lea (A0,D0),A10: moveb -(A1),D2 |cmpb #"\M",D2 |beq 6f cmpb #"\J",D2 |beq 6f |addqw #1,A16: clrb (A1) |.CALLBR .Password(-,&Passbuf,&pasS) lea Passbuf,A01: lea buf,A12: moveb (A0)+,D1 |beq none |cmpb #":",D1 beq 3f |cmpb (A1)+,D1 |beq 2b4: moveb (A0)+,D1 |beq none |cmpb #"\M",D1 beq 1b |cmpb #"\J",D1 |bne 4b |bra 1b;3: tstb (A1)+ |bne 4b |lea pasx,A1 |moveq #32,D0 bsr getstr |lea uid,A1 |moveq #16,D0 bsr getstr |bsr deci |moveb D0,uid lea gid,A1 |moveq #16,D0 |bsr getstr bsr deci |moveb D0,gid |lea gcos,A1 moveq #80,D0 |bsr getstr |lea home,A1 moveq #HomS,D0 |bsr getstr |lea shell,A1 moveq #SheS,D0 |bsr getstr .CALLBR Slognam(-,&buf,&3) |tstl D0 |bmi none .CALLBR Shome(-,&home,#0) |tstl D0 |bmi none moveb uid,D0 |moveb gid,D1 |lslb #5,D1 andb #0x1F,D0 |orb D0,D1 |moveb D1,uid clrb uid+1 |.CALLBR Sguid(-,&uid) |tstl D0 |bmi none .CALLBR Spath(-,&path,&1) |tstl D0 |bmi none .CALLBR Sshell(-,&shell,&2) |tstl D0 |bmi none btst #5,Sinit+3 |bne 6f |lea otxt,A0 |bsr prme;6: .CALLBR Swork(-,&home) |tstl D0 bpl 5f |.CALLBR Swork(-,&slas)5: .CALLBR Dolin(-,#0,Init);Exit: bra okxigetr: .CALLBR .Fread(-,#0,&buf,&LinS-4) |rtsChow: movel (A0)+,D1 |beq 2f |movel A0,pasx+4 .CALLBR .Password(-,&Passbuf,&pasS) .CALLBR .Gownguid(-,&Passbuf,D1,#0) movel D0,pasx |bmi 2folop: movel pasx+4,A0 |movel (A0)+,D1 |beq Exit movel A0,pasx+4 |movel D1,pasx+8 |.CALLBR Chown(-,D1,pasx) tstl D0 |bpl olop |lea qtxt,A0 |movel pasx+8,A3 bsr prme |bra olop2: lea ptxt,A1 |bra crtagetstr: movel A1,-(SP)				;Preserve A1.4: moveb (A0)+,D1 |beq 5f |cmpb #"\M",D1	;Get string of at most beq 5f |cmpb #"\J",D1 |beq 5f cmpb #":",D1 |beq 6f |subql #1,D0		; D0 chars (including bmi 4b |moveb D1,(A1)+ |bra 4b			; terminating zero) from5: subqw #1,A0					; A0 to A1. Position to after6: clrb (A1) |movel (SP)+,A1 |rts		; : or before \n.deci: movel A1,-(SP) |clrl D0 |clrl D5		;Preserve A1.0: moveb (A1)+,D5 |beq 1f cmpb #"0"-1,D5 |bls 2f cmpb #"9",D5 |bhi 2f |subb #"0",D5 mulu #10,D0 |addw D5,D0 |bra 0b2: cmpb #"\M",D5 |beq 1f |cmpb #"\J",D51: movem (SP)+,A1 |rts				;Do not ruin Cond. code.Scrt: .CALL Gcur(-,&buf,&9) |clrl D5 clrl D6 |clrl D7 |st pasx+81: movel (A0)+,D1 |beq 2f |movel D1,A1 cmpb #"-",(A1) |bne 3f |clrl Point .CALLBR Scom(-,&Point,&8) |cmpb #"-",1(A1)	;Nullify Com.sa and Crt.sa, bne 3f |.CALLBR Pcrt(-,#0) |bra 1b		; i.e. restore to build-in.3: moveb (A1)+,D4 |cmpb #"=",(A1)+ bne 4f |moveq #3,D35: cmpb culi(D3),D4 |beq 6f subqw #1,D3 |bpl 5b |bra help;culi: .ASCII 4"udlr";6: lsll #3,D3 |lea buf+8,A2 |addl D3,A2 st D5 |clrl -(A2) |clrl -(A2) |moveq #6,D37: moveb (A1)+,(A2)+ |beq 1b |subqw #1,D3 bgt 7b |bra 1b;4: tstl D6 |bne help movel D7,D6 |movel D1,D7 |bra 1b2: tstl D5 |beq 1f |.CALL Scur(-,&buf,&9)1: movel D7,pasx+4 |beq okxi |movel D6,pasx seq pasx+9 |bne 4f |movel D7,pasx		;Set pasx+9 if one argument.;4: movel pasx+4,D7 |movew #"om",D4		;Try first with prefix. bsr Npat |bgt 5f |tstb pasx+9 |bne 9f tstl D0 |beq 4b |movel pasx+4,A2 |bra crto	;Try original name if two8: tstb pasx+9 |bne 9f |bra 4b			; names were specified.5: .CALLBR Mpat(-,D7,#0,&Buf) movel pasx+4,A2 |tstl D0 |ble 8b; cmpw #ComS,D0 |bhs crto			;Found a Com.sa. .CALLBR Scom(-,&Buf,&8);9: st pasx+87: movel pasx,A2 |movel A2,D7			;Try prefix first, then cmpb #"+",(A2) |beq Exit |movew #"rt",D4	; original name. bsr Npat |bgt 6f |beq 7b |movel pasx,A2 |bra crto6: .CALLBR .Fabsrd(-,D7,&passb,&1998) movel pasx,A2 |tstl D0 |ble 7b; lea passb,A1 |st (A1,D0) |moveq #CrtE,D6		;Found a Crt.sa lea Buf,A3 |movel A3,A0 |moveq #CrtE,D51: movew #".\@",(A3)+ |clrw (A3)+ clrl (A3)+ |subqw #1,D5 |bgt 1b;nect: movel A0,A3 |addw #8,A0		;Maximum CrtE entries of 8 bytes.2: clrl D0 |clrl D5 |moveb (A1)+,D5 ble tdon |cmpb #"-",D5 |bne 5f moveb (A1)+,D5 |bset #29,D55: cmpb #"""",D5 |beq doas |cmpb #".",D5 bne 7f |moveb D5,D0 |bra puby7: cmpb #"*",D5 |bhi 4f |bne 2b		;May be decimal, hex or ascii.3: moveb (A1)+,D0 |cmpb #"\M",D0	;The notation "" implies ascii beq 2b |cmpb #"\J",D0 |bne 3b |bra 2b;neby: clrl D0 |clrl D5 |moveb (A1)+,D5	;standard sequence, cmpb #"-",D5 |bne 6f |moveb (A1)+,D5 |bset #29,D56: cmpb #"""",D5 |beq doas |cmpb #"*",D5 |bls puby	;supposedly present in4: cmpb #",",D5 |beq puby |cmpb #"""",D5	;Sequ sequence. beq doas |cmpb #"0",D5 |beq neby cmpb #"x",D5 |beq dohx;dode: cmpb #"0"-1,D5 |bls puby cmpb #"9",D5 |bhi crtr |subb #"0",D5 mulu #10,D0 |addb D5,D0 moveb (A1)+,D5 |bra dode;dohx: moveb (A1)+,D5 |cmpb #"A"-1,D5 bls 1f |andb #0xDF,D5 |subb #"A"-"9"-1,D51: cmpb #"0"-1,D5 |bls puby |subb #"0",D5 cmpb #0xF,D5 |bhi crtr |lsll #4,D0 orb D5,D0 |bra dohx;doas: moveb (A1)+,D5 |cmpb #"\\",D5		;\\ = \, \" = " bne 1f |bchg #31,D5 |beq doas			;\X = cntrl X1: cmpb #" "-1,D5 |bls crtr |cmpb #"""",D5 bne 2f |bclr #31,D5 |beq stdo2: bclr #31,D5 |beq 3f |subb #0x40,D5 |bmi crtr3: moveb D5,(A3)+ |bra doas;puby: bclr #29,D5 |beq 4f |negb D04: moveb D0,(A3)+ |clrb (A3)stdo: cmpl A0,A3 |bhi crtr cmpb #",",D5 |beq neby |subqw #1,A16: moveb (A1)+,D0 |cmpb #"\M",D0 beq 8f |cmpb #"\J",D0 |bne 6b8: tstb -1(A0) |bne crtr |subqw #1,D6 bmi crtr |bne nect |moveq #CurE,D67: tstb (A1)+ |bgt 7b;tdon: .CALLBR Gcrt(-,&Buf+256) lea Buf,A0 |lea Buf+256,A1 |moveq #CrtE,D61: cmpw #".\@",(A0) |bne 3f |addqw #8,A0 addqw #8,A1 |bra 2f3: movel (A0)+,(A1)+ |movel (A0)+,(A1)+2: subqw #1,D6 |bgt 1b .CALLBR Pcrt(-,&Buf+256) |bra ExitNpat: movel D7,A0 |tstb pasx+8			;Try /usr/lib/C.._xx.sa. bgt 3f |addqb #1,pasx+8 |bne 5f		; Second time try unchanged. cmpb #"/",(A0) |beq 2f				;Exit: path address in D7. lea buf,A3 |movel A3,D7 |lea ilib,A1 movew #ComS-6,D0 |moveq #2,D51: moveb (A1)+,(A3)+ |dbeq D0,1b |bne 2f exg A0,A1 |subqw #1,A3 |subql #1,D5 |beq 1b bmi 5f |movew D4,(A3)+ |moveb #"_",(A3)+ |bra 1b5: moveq #1,D0 |rts2: clrl D0 |rts3: moveq #-1,D0 |rtscrto: lea txto,A1 |bra crtacrtr: moveq #19,D7 |subl D6,D7 |movel D7,A3 lea txtc,A1 |movel pasx,A2crta: movem A1-A3,-(SP) |bra erro	.ENDF.Getmep: movel (SP),D0 movel 4(SP),(SP) |movel D0,4(SP)	;Getmep=Getmem with error bsr .Getmem |addqw #4,SP		; print, address to A4 and movel D0,B4 |addql #1,D0		; stack adjustement. bne 1f |pea txtAerro: bsr .Printnone: pea -1 |bsr .exitnonp: movel D0,-(SP) |bsr .exit1: rts;txtA: .ASCIZ "No memory granted.\n".EVEN .Getmem: .CALLBR Glim(#1) tstl D0 |bpl 1f |rts1: addl 4(SP),D0 |.CALL Getm(D0) rtsGlim: moveq #89,D0 |bra mostGetm: moveq #17,D0 |bra most;Dolin: moveq #94,D0 |bra most		;Pass new command line.;okxi: clrl -(SP)exix: clrl -(SP).exit: moveq #1,D0 |bra mostprme: movem *,-(SP) |.CALLBR .Print(A0,A3,D1) movem (SP)+,* |rts;.Print: pea 1 |bra mosp.Password: pea 12 |bra mosp.Gowname: pea 13 |bra mosp.Gownguid: pea 14 |bra mosp.Help: pea 15 |bra mosp;Note: if routine nr is larger than 255; consider the lower byte as an offset to the; address and the next byte as the routine nr.;mosp: movel D0,-(SP) |movel 4(SP),D0 clrl 4(SP) |cmpw #0x00FF,D0 bls 0f |moveb D0,7(SP) |lsrl #8,D00: trap #8 |addl D0,4(SP) |addql #1,D0 |bne 1f movel (SP)+,D0 |movel (SP)+,D0 |rts1: movel (SP)+,D0 |rtsScur:Scom:Shome:Spath:Sshell:Slognam: moveq #77,D0 |bra mostGcur: moveq #78,D0 |bra mostSwork: moveq #79,D0 |bra mostWait: moveq #63,D0 |bra mostGcrt: moveq #82,D0 |bra most		;Get crt.saPcrt: moveq #81,D0 |bra most		;Put crt.saSguid: moveq #83,D0 |bra mostAccess: moveq #33,D0 |bra mostMpat: moveq #71,D0 |bra mostGeth: moveq #96,D0 |bra most.Fread: moveq #3,D0 |bra most.Fopen: moveq #5,D0 |bra most.Fclose: moveq #6,D0 |bra mostmost: trap #0 |rtsChown: moveq #16,D0 |bra most.SUBR .Fabsrd(fnamad,bufadr,buflen).TEMP tapea,leng			;Read complete file. .CALL .Fopen(fnamad,#0) movel D0,tapea |bpl 1f |.RETURN1: .CALL .Fread(tapea,bufadr,buflen) move.l D0,leng |.CALL .Fclose(tapea) move.l leng,D0 |.RETURN.ENDS