From 8d7326d9e082a22d34c53b5fe60b8b5a4fe610fc Mon Sep 17 00:00:00 2001
From: Rob Swindell <rob@synchro.net>
Date: Fri, 19 Mar 2021 19:03:01 -0700
Subject: [PATCH] Refactor the get_pw() and get_ticpw() methods

First look for a linked node matching the node address string as passed,
then look for a match using the normalized address (removing .0 and @domain).
The "ALL" wildcard should not be used for password lookups.

This should fix reported issue 240.
---
 exec/load/fido_syscfg.js | 40 ++++++++++++++--------------------------
 1 file changed, 14 insertions(+), 26 deletions(-)

diff --git a/exec/load/fido_syscfg.js b/exec/load/fido_syscfg.js
index 5c92a0067c..3abee30cfc 100644
--- a/exec/load/fido_syscfg.js
+++ b/exec/load/fido_syscfg.js
@@ -80,36 +80,24 @@ function SBBSEchoCfg (fname)
 }
 SBBSEchoCfg.prototype.get_ticpw = function(node)
 {
-  if (!fidoaddr.is_valid(node)) throw 'get_ticpw: Invalid address ' + node;
-	var n = node;
-	while(n) {
-		if (this.ticpass[n] !== undefined)
-			return this.ticpass[n];
-		if (n === 'ALL')
-			break;
-		if (n.indexOf('@') !== -1)
-			n = n.replace(/@.*$/,'');
-		if (n.indexOf('ALL') !== -1)
-			n = n.replace(/[0-9]+[^0-9]ALL$/, 'ALL');
-		else
-			n = n.replace(/[0-9]+$/, 'ALL');
-	}
+	var addr = fidoaddr.parse(node);
+	if (!addr) throw new Error('get_ticpw: Invalid address ' + node);
+	if (this.ticpass[node] !== undefined)
+		return this.ticpass[node];
+	node = fidoaddr.to_str(addr);
+	if (this.ticpass[node] !== undefined)
+		return this.ticpass[node];
 	return undefined;
 };
 SBBSEchoCfg.prototype.get_pw = function(node)
 {
-  if (!fidoaddr.is_valid(node)) throw 'get_pw: Invalid address ' + node;
-	var n = node;
-	while(n) {
-		if (this.pktpass[n] !== undefined)
-			return this.pktpass[n];
-		if (n === 'ALL')
-			break;
-		if (n.indexOf('ALL') !== -1)
-			n = n.replace(/[0-9]+[^0-9]ALL$/, 'ALL');
-		else
-			n = n.replace(/[0-9]+$/, 'ALL');
-	}
+	var addr = fidoaddr.parse(node);
+	if (!addr) throw new Error('get_pw: Invalid address ' + node);
+	if (this.pktpass[node] !== undefined)
+		return this.pktpass[node];
+	node = fidoaddr.to_str(addr);
+	if (this.pktpass[node] !== undefined)
+		return this.pktpass[node];
 	return undefined;
 };
 
-- 
GitLab