/****************************************************************/ /* Remove a user from the Weasel database */ /* */ /* Author: Peter Moylan (peter@pmoylan.org) */ /* Started: 8 June 2000 */ /* Last revised: 17 November 2020 */ /* */ /* Usage: */ /* remove username */ /* */ /* In the multidomain case, the username should be of the */ /* form user@domain. */ /* */ /* Installation: */ /* Put this file anywhere you like, but run it from the */ /* directory containing WEASEL.INI or WEASEL.TNI */ /* */ /****************************************************************/ Globals = "TNImode MultiDomain MailRoot Domains" CALL RxFuncAdd SysLoadFuncs, rexxutil, sysloadfuncs CALL SysLoadFuncs CALL CheckPrerequisites SelectTNI INI_get INI_del PARSE ARG username IF username = '' THEN DO SAY "Usage: remove username" EXIT 0 END CALL ParseDomainInfo CALL RemoveUser username EXIT 0 /****************************************************************/ /* REMOVING THE USER */ /****************************************************************/ RemoveUser: PROCEDURE expose (Globals) /* Prerequisite: the global variables TNImode, MultiDomain, */ /* MailRoot, and Domains have already been set, for example */ /* by calling ParseDomainInfo (see below). */ PARSE ARG username PARSE VAR username user'@'userdomain PARSE VAR Domains firstdomain '00'X rest IF MultiDomain & (firstdomain = '') THEN DO SAY "You don't have any domains defined" SAY "Operation failed." RETURN END /* Convert userdomain to actual domain. In the single */ /* domain case the result will be ''. */ IF MultiDomain & (userdomain = '') THEN DO SAY "No domain specified, assuming domain "firstdomain domain = firstdomain END ELSE domain = IdentifyDomain(userdomain) IF MultiDomain & (domain = '') THEN DO SAY "ERROR: domain "userdomain" does not exist" SAY "Operation failed." RETURN END domaindir = MailRoot /* Work out which file to look up. */ IF MultiDomain THEN DO domaindir = domaindir||domain||'\' INIFile = domaindir||'DOMAIN.' END ELSE INIFile = 'WEASEL.' IF TNImode THEN INIFile = INIFile||'tni' ELSE INIFile = INIFile||'ini' /* Check whether the user already exists in this domain. */ IF INI_get(INIFile, user) \= '' THEN DO CALL INI_del INIFile, user /* We still have to remove the user's mail directory. */ Nul = '00'X MailDir = domaindir||user SAY 'Mail directory is 'MailDir rc = SysFileTree(MailDir, stem, 'DO') IF (rc \= 0) | (stem.0 = 0) THEN SAY 'Directory does not exist' ELSE IF SysRmDir(MailDir) \= 0 THEN DO SAY "Could not remove user's mail directory" SAY "You should do this manually" END SAY "User "username" deleted" END ELSE DO SAY "Warning: user "username" does not exist" SAY "Operation failed." END RETURN /****************************************************************/ /* */ /* BUILDING THE MAILROOT AND THE LIST OF DOMAINS */ /* */ /* This is an initialisation procedure that sets the global */ /* variables MultiDomain, MailRoot, and Domains. For the */ /* purposes of this program those variables have values that */ /* never change, so you should call this procedure once, and */ /* then call procedure IdentifyDomain (below) as many times */ /* as you need to. */ /* */ /****************************************************************/ ParseDomainInfo: PROCEDURE expose (Globals) /* On exit, the global variable Domains contains a list of */ /* our domains, in string-of-strings format. In the */ /* single-domain case, we load the list from the "Local" */ /* list. All names are in upper case, to simplify name */ /* matching by the caller. */ /* This procedure also sets the global variables 'TNImode', */ /* 'MailRoot', and 'MultiDomain'. */ /* Figure out the mail root. */ TNImode = SelectTNI("Weasel") IF TNImode THEN INIFile = "WEASEL.TNI" ELSE INIFile = "WEASEL.INI" SAY "Using "INIFile Nul = '00'X MailRoot = INI_get(INIFile, '$SYS', 'MailRoot') j = POS(Nul,MailRoot) IF j > 0 THEN MailRoot = LEFT(MailRoot, j-1) MailRoot = TRANSLATE(STRIP(MailRoot), '\', '/') /* Get the list of domain names. */ MultiDomain = C2D(INI_get(INIFile, '$SYS', 'MultiDomainEnabled')) IF MultiDomain = '' THEN MultiDomain = 0 IF MultiDomain THEN Domains = INI_get(INIFile, '$SYS', 'Domains') ELSE Domains = INI_get(INIFile, '$SYS', 'Local') Domains = TRANSLATE(STRIP(Domains)) RETURN /****************************************************************/ /* IDENTIFYING A DOMAIN */ /****************************************************************/ IdentifyDomain: PROCEDURE expose (Globals) /* This procedure is called with a single parameter, which */ /* is the 'domain name' part of an e-mail address. We */ /* return the actual domain name, which might or might not */ /* be the same as the input parameter. In the single */ /* domain case we return the empty string, and that is not */ /* an error. In the multidomain case, an empty result */ /* means "no such domain". */ PARSE UPPER ARG name IF \Multidomain THEN RETURN '' /* From now on, we can assume the multidomain case. */ dlist = TRANSLATE(Domains) DO FOREVER PARSE VAR dlist thisdomain '00'X dlist /* We have a match if name matches the domain name. */ IF thisdomain = name THEN RETURN name /* Otherwise, we have to look up the "Local" list for */ /* this domain, unless strict domain name checking */ /* is in force. */ INIFile = MailRoot||thisdomain||"\DOMAIN." IF TNImode THEN INIFile = INIFile||'tni' ELSE INIFile = INIFile||'ini' StrictChecking = C2D(INI_get(INIfile, '$SYS', 'StrictChecking')) IF StrictChecking THEN RETURN '' LocalList = INI_get(INIFile, '$SYS', 'Local') DO FOREVER IF LEFT(LocalList, 1) = '00'X THEN RETURN '' PARSE VAR LocalList current '00'X LocalList current = TRANSLATE(STRIP(current)) IF name = current THEN RETURN thisdomain END END /****************************************************************/ /* CHECKING PREREQUISITES */ /****************************************************************/ CheckPrerequisites: PROCEDURE /* The argument is a space-separated list of prerequisite */ /* functions, for example */ /* CALL CheckPrerequisites rxu SelectTNI INI_get */ /* where (at least in this version) each list item is */ /* either 'rxu' or a function from my TNItools package. */ /* If any is missing then we exit with an error message. */ PARSE UPPER ARG funclist funclist = STRIP(funclist) needrxu = 0 needtools = 0 DO WHILE funclist \= '' PARSE VAR funclist func funclist funclist = STRIP(funclist) IF func = 'RXU' THEN DO /* Initialise RXU if not already available, fail if */ /* the RxFuncAdd operation fails. We must */ /* RxFuncQuery RxuTerm because RxuTerm does not */ /* deregister RxuInit. The RxFuncDrop is needed */ /* because RxFuncAdd seems to report failure if the */ /* function is already registered. */ IF RxFuncQuery('RxuTerm') THEN DO CALL RxFuncDrop('RxuInit') CALL RxFuncAdd 'RxuInit','RXU','RxuInit' IF result THEN DO SAY 'Cannot load RXU' needrxu = 1 END ELSE CALL RxuInit END END ELSE DO func = func||'.CMD' IF SysSearchPath('PATH', func) = '' THEN DO SAY 'ERROR: 'func' must be in your PATH' needtools = 1 END END END IF needrxu THEN SAY 'You can find RXU1a.zip at Hobbes' IF needtools THEN SAY 'Please install the GenINI package' IF needrxu | needtools THEN EXIT 1 RETURN /****************************************************************/