$ !	TKUSER.COM
$ !
$ !	User creation and DECmail-11 name database generation script
$ !	for "turnkey" RSTS/E 10.1-L system.
$ !
$ !	Parameters passed:
$ !
$ !		P1 = Administrator Full Name
$ !		P2 = Administrator Short Name
$ !		P3 = Administrator Password
$ !

$ ! Set up the environment.
$	_SET NOECHO/NOWARNING
$	_ON ERROR THEN GOTO ERROR
$	_ON CONTROL_C THEN GOTO ABORT

$ ! Set up local symbols
$	PRINT$ = "_WRITE 0"

$ ! Set up local boolean symbols
$	false = 0
$	true = .NOT. false
$	aborting = false

$START:
$	time = F$TIME()
$	PRINT$ time, "   Checking environment"
$	priv = F$PRIVILEGE("WACNT,GACNT")
$	_IF priv THEN _GOTO FILES
$	    PRINT$ "Insufficient privileges"
$	    _GOTO ABORT


$FILES:
$	time = F$TIME()
$	PRINT$ time, "   Opening user list, mail account, and user account files"
$	_OPEN/READ 1 USERS.DAT
$	_OPEN/WRITE/REPLACE 2 NAMES.DAT
$ ! Per AA-CF03A-TC, you can't actually pass the parameters into a command's
$ ! data statements. So we'll create a temporary command file, as is required.
$	_OPEN/WRITE/REPLACE 3 TKU1.COM


$ADMIN:
$ ! Handle the admin account
$	time = F$TIME()
$	PRINT$ time, "   Handle the admin account"
$ ! Symbols from parameters
$	nam = F$EDIT(P1,4 + 8 + 16 + 128)
$	eml = F$EDIT(P2,2 + 4 + 32)
$	pwd = F$EDIT(P3,4 + 8 + 128)
$	_WRITE 3 "$ CREATE/ACCOUNT/USER/NETWORK/DIALUP/PRIVILEGES=ALL/NAME=""''eml'"" [1,4]"
$	_WRITE 3 pwd
$	_WRITE 3 pwd
$	_WRITE 3 "$ EOD"


$PREFILL:
$	time = F$TIME()
$	PRINT$ time, "   Pre-fill the account files"
$	_WRITE 2 "[1,2],System Account,SYSTEM"
$	_WRITE 2 "[1,3],Operator Account,OPERATOR"
$	_WRITE 2 "[1,4],Administrator Account,ADMIN"
$	_WRITE 2 "[1,4],''nam',''eml'"
$	_WRITE 3 "$ CREATE/ACCOUNT/NOUSER [1,0]"
$	_WRITE 3 "$ CREATE/ACCOUNT/NOUSER [2,0]"
$	_WRITE 3 "$ CREATE/ACCOUNT/NOUSER [3,0]"
$	_WRITE 3 "$ CREATE/ACCOUNT/NOUSER [4,0]"


$USERS:
$	time = F$TIME()
$	PRINT$ time, "   Iterate through the user list"
$LOOP:
$	_READ/END_OF_FILE=FINAL 1 record
$ ! Find the semicolons
$	smclnA = F$INSTR(1,record,";")
$	smclnB = F$INSTR(smclnA + 1,record,";")
$	smclnC = F$INSTR(smclnB + 1,record,";")
$ ! Get the PPN, DECmail address, user's name, and password
$	ppn = F$EDIT(F$MID(record,1,smclnA-1),2 + 4)
$	eml = F$EDIT(F$MID(record,smclnA+1,smclnB-smclnA-1),2 + 4 + 32)
$	nam = F$EDIT(F$MID(record,smclnB+1,smclnC-smclnB-1),4 + 8 + 16 + 128)
$	pwd = F$EDIT(F$MID(record,smclnC+1,F$LENGTH(RECORD)-smclnC),4 + 8 + 128)
$ ! Split up the PPN
$	cmm = F$INSTR(1,ppn,",")
$	prj = F$INTEGER(F$EDIT(F$MID(ppn,2,cmm-2),2+4))
$	prg = F$INTEGER(F$EDIT(F$MID(ppn,cmm+1,F$LENGTH(ppn)-cmm-1),2+4))
$ ! Check the project numbers for access types
$TDUP:
$	_IF (prj .EQ. 2) .OR. (prj .EQ. 4) THEN _GOTO DIAL
$	    ddd = "NODIALUP"
$	    _GOTO TNET
$DIAL:
$	ddd = "DIALUP"
$	_GOTO TNET
$TNET:
$	_IF (prj .EQ. 2) .OR. (prj .EQ. 3) THEN _GOTO NETW
$	    nnn = "NONETWORK"
$	    _GOTO GRPA
$NETW:
$	nnn = "NETWORK"
$	_GOTO GRPA
$ ! Check the programmer nukmbers for user privileges
$GRPA:
$	_IF prg .LE. 5 THEN _GOTO GPADM
$	    prv = "SETPAS"
$	    _GOTO TKU
$GPADM:
$	prv = "SETPAS,GACNT,GREAD,GWRITE"
$	_GOTO TKU
$ ! Write the lines for the user account creation file
$TKU:
$	_WRITE 3 "$ CREATE/ACCOUNT/USER/''nnn'/''ddd'/PRIVILEGES=(''prv')/NAME=""''eml'"" ''ppn'"
$	_WRITE 3 pwd
$	_WRITE 3 pwd
$	_WRITE 3 "$ EOD"
$	_WRITE 2 "''ppn',''nam',''eml'"
$	_GOTO LOOP

$FINAL:
$	_WRITE 3 "$ EXIT"
$	_CLOSE 3
$	@TKU1
$	_DELETE TKU1.COM
$	_GOTO END

$ABORT:
$	aborting = true

$ERROR:
$	time = F$TIME()
$	PRINT$ time, " Unable to create turnkey users"
$	_CLOSE 3

$END:
$	time = F$TIME()
$	PRINT$ time, "   The turnkey user creation procedure is complete."
$	_CLOSE 1
$	_CLOSE 2
$	status = $SEVERITY
$	_IF aborting THEN status = 4	! Force fatal.
$	_EXIT status
