! ----- DELETE_USER_DIRECTORY.FUN ----- ! ! ----- SUBROUTINE TO DELETE THE DIRECTORY TREE FOR A USERNAME ----- ! ! ---------- PASSED: ---------- ! ! ----- THE_DEVICE = Root Directory device to be removed ! ----- DEVICE_LENGTH = Length of THE_DEVICE ! ! ----- DIRECTORY_NAME = Root Directory name to be removed ! ----- DIRECTORY_NAME_LENGTH = Length of DIRECTORY_NAME ! ! ----- Last Change 07/06/93 by Brian Lomasky ----- ! SUB DELETE_USER_DIRECTORY %INCLUDE "NUSER.INC" %INCLUDE "$PRVDEF" %FROM %LIBRARY "SYS$LIBRARY:BASIC$STARLET.TLB" DECLARE STRING DIR_NAME ! DIRECTORY NAME LESS BRACKETS DECLARE LONG LOCAL_STATUS ! LOCAL SYSTEM SERVICE STATUS DECLARE LONG TEMP_LONG ! TEMPORARY LONGWORD VARIABLE DECLARE STRING TEMP_STRING ! TEMPORARY STRING EXTERNAL LONG FUNCTION CHANGE_UIC(WORD, & WORD) ! CHANGE YOUR UIC EXTERNAL LONG FUNCTION & LIB$DELETE_FILE ! DELETE FILE EXTERNAL LONG FUNCTION SET_PROTECTION(STRING, & WORD) ! SET FILE PROTECTION EXTERNAL LONG SPRIV ! SET/RESET PROCESS PRIVILEGES EXTERNAL LONG FUNCTION & SYS$CMEXEC ! CHANGE MODE TO EXECUTIVE EXTERNAL WORD FUNCTION VALID_FILE( & STRING) ! TRUE IF PASSED FILESPEC EXISTS MAP (PRIV1) LONG PRV_ADR(1%) ! PRIVILEGE BIT SETTINGS MAP (PRIV2) LONG ENABLE_FLAG ! ENABLE/DISABLE PRIV FLAG PRINT "Removing user's home directory tree..." DIR_NAME = LEFT(DIRECTORY_NAME, DIRECTORY_NAME_LENGTH) DIR_NAME = RIGHT(DIR_NAME, 2%) IF LEFT(DIR_NAME, 1%) = "[" DIR_NAME = LEFT(DIR_NAME, LEN(DIR_NAME) - 1%) & IF RIGHT(DIR_NAME, LEN(DIR_NAME)) = "]" ! ----- DONE IF THE DIRECTORY DOES NOT EXIST ----- TEMP_STRING = LEFT(THE_DEVICE, DEVICE_LENGTH) + & "[000000]" + DIR_NAME + ".DIR" EXIT SUB IF NOT VALID_FILE(TEMP_STRING) ! ----- CHANGE UIC TO THE USER'S UIC ----- LOCAL_STATUS = CHANGE_UIC(OCT_UIC_GROUP, OCT_UIC_MEMBER) IF LOCAL_STATUS <> SS$_NORMAL THEN PRINT "DELETE_USER_DIRECTORY Error for CHANGE_UIC" CALL LIB$STOP(LOCAL_STATUS BY VALUE) END IF ! ----- REMOVE USER'S HOME DIRECTORY AND ANY FILES IT ----- ! ----- CONTAINS (MUST BE DONE NON-PRIVILEGED SO AS TO ----- ! ----- AVOID DELETION OF CRITICAL SYSTEM FILES THAT THE ----- ! ----- USER MAY HAVE CREATED AN ALIAS FOR (EXCEPT FOR ANY ----- ! ----- LOGIN.COM;32767 THAT WE MIGHT'VE CREATED)) ----- TEMP_STRING = LEFT(THE_DEVICE, DEVICE_LENGTH) + & "[" + DIR_NAME + "]LOGIN.COM;32767" IF VALID_FILE(TEMP_STRING) THEN ! ----- SET S:RE,O:RE,G:RE,W:RWED PROTECTION ----- ! ----- ON THE LOGIN.COM;32767 FILE ----- ! ----- (2730% IS X'0AAA'W) ----- LOCAL_STATUS = SET_PROTECTION(TEMP_STRING, 2730%) IF LOCAL_STATUS <> SS$_NORMAL THEN PRINT "Warning - " + NUM1$(LOCAL_STATUS)& + " error while setting" + & " protection on " + & TEMP_STRING + BEL END IF LOCAL_STATUS = LIB$DELETE_FILE(TEMP_STRING) IF LOCAL_STATUS <> SS$_NORMAL THEN PRINT "Warning - " + NUM1$(LOCAL_STATUS)& + " error while deleting " + & TEMP_STRING + BEL END IF END IF ! ----- TURN OFF ALL PRIVILEGES WHICH MIGHT CAUSE A ----- ! ----- SYSTEM FILE TO BE ACCIDENTLY DELETED ----- PRV_ADR(0%) = PRV$M_BYPASS OR PRV$M_SYSPRV PRV_ADR(1%) = 0% ENABLE_FLAG = 0% ! SET FLAG TO DISABLE PRIVS LOCAL_STATUS = SYS$CMEXEC(SPRIV,) IF LOCAL_STATUS <> SS$_NORMAL THEN PRINT "DELETE_USER_DIRECTORY Error for SYS$CMEXEC (2)" ! ----- TRY TO CHANGE UIC BACK TO MY OWN UIC ----- TEMP_LONG = CHANGE_UIC(MY_UIC_GROUP, MY_UIC_MEMBER) IF TEMP_LONG <> SS$_NORMAL THEN PRINT "DELETE_USER_DIRECTORY Error " + & NUM1$(TEMP_LONG) + & " for CHANGE_UIC (1)" END IF CALL LIB$STOP(LOCAL_STATUS BY VALUE) END IF TEMP_STRING = LEFT(THE_DEVICE, DEVICE_LENGTH) + & "[" + DIR_NAME + "...]*.*;*" ! ----- SET S:RE,O:RWED,G:RE,W:RE PROTECTION ON THE ----- ! ----- DIRECTORY TREE (-22006% IS X'AA0A'W) ----- LOCAL_STATUS = SET_PROTECTION(TEMP_STRING, -22006%) IF LOCAL_STATUS <> SS$_NORMAL THEN PRINT "Warning - " + NUM1$(LOCAL_STATUS) + & " error while setting protection on " + & TEMP_STRING + BEL END IF ! ----- ASSUME THAT USER HAS NO MORE THAN 8 LEVELS OF ----- ! ----- DIRECTORIES ----- CALL LIB$DELETE_FILE(TEMP_STRING) CALL LIB$DELETE_FILE(TEMP_STRING) CALL LIB$DELETE_FILE(TEMP_STRING) CALL LIB$DELETE_FILE(TEMP_STRING) CALL LIB$DELETE_FILE(TEMP_STRING) CALL LIB$DELETE_FILE(TEMP_STRING) CALL LIB$DELETE_FILE(TEMP_STRING) CALL LIB$DELETE_FILE(TEMP_STRING) ! ----- TURN BACK ON THE BYPASS AND SYSPRV PRIVILEGES ----- PRV_ADR(0%) = PRV$M_BYPASS OR PRV$M_SYSPRV PRV_ADR(1%) = 0% ENABLE_FLAG = 1% ! SET FLAG TO ENABLE PRIVS LOCAL_STATUS = SYS$CMEXEC(SPRIV,) IF LOCAL_STATUS <> SS$_NORMAL THEN PRINT "DELETE_USER_DIRECTORY Error for SYS$CMEXEC (3)" ! ----- TRY TO CHANGE UIC BACK TO MY OWN UIC ----- TEMP_LONG = CHANGE_UIC(MY_UIC_GROUP, MY_UIC_MEMBER) IF TEMP_LONG <> SS$_NORMAL THEN PRINT "DELETE_USER_DIRECTORY Error " + & NUM1$(TEMP_LONG) + & " for CHANGE_UIC (2)" END IF CALL LIB$STOP(LOCAL_STATUS BY VALUE) END IF ! ----- CHANGE UIC BACK TO MY OWN UIC ----- LOCAL_STATUS = CHANGE_UIC(MY_UIC_GROUP, MY_UIC_MEMBER) IF LOCAL_STATUS <> SS$_NORMAL THEN PRINT "DELETE_USER_DIRECTORY Error for CHANGE_UIC (3)" CALL LIB$STOP(LOCAL_STATUS BY VALUE) END IF ! ----- LASTLY, DELETE THE ROOT DIRECTORY ----- TEMP_STRING = LEFT(THE_DEVICE, DEVICE_LENGTH) + & "[000000]" + DIR_NAME + ".DIR" LOCAL_STATUS = LIB$DELETE_FILE(TEMP_STRING) IF LOCAL_STATUS <> SS$_NORMAL THEN PRINT "Warning - " + NUM1$(LOCAL_STATUS) + & " error while deleting user's directory" + BEL END IF END SUB