Diff

mod_anti_spam/trie.lib.lua @ 6191:94399ad6b5ab

mod_invites_register_api: Use set_password() for password resets Previously the code relied on the (weird) behaviour of create_user(), which would update the password for a user account if it already existed. This has several issues, and we plan to deprecate this behaviour of create_user(). The larger issue is that this route does not trigger the user-password-changed event, which can be a security problem. For example, it did not disconnect existing user sessions (this occurs in mod_c2s in response to the event). Switching to set_password() is the right thing to do.
author Matthew Wild <mwild1@gmail.com>
date Thu, 06 Feb 2025 10:13:39 +0000
parent 6159:82a10e21b7f9
child 6192:76ae646563ea
line wrap: on
line diff
--- a/mod_anti_spam/trie.lib.lua	Wed Feb 05 11:04:15 2025 -0500
+++ b/mod_anti_spam/trie.lib.lua	Thu Feb 06 10:13:39 2025 +0000
@@ -120,6 +120,29 @@
 	end
 end
 
+local function find_match_in_descendents(node, item, len, i)
+	for child_byte, child_node in pairs(node) do
+		if type(child_byte) == "number" then
+			if child_node.terminal then
+				local bits = child_node.value;
+				for j = #bits, 1, -1 do
+					local b = bits[j]-((i-1)*8);
+					if b ~= 8 then
+						local mask = bit.bnot(2^b-1);
+						if bit.band(bit.bxor(c, child_byte), mask) == 0 then
+							return true;
+						end
+					end
+				end
+			else
+				
+			end
+		end
+	end
+	return false;
+end
+
+--
 function trie_methods:contains_ip(item)
 	item = item.packed;
 	local node = self.root;
@@ -132,25 +155,57 @@
 		local c = item:byte(i);
 		local child = node[c];
 		if not child then
-			for child_byte, child_node in pairs(node) do
-				if type(child_byte) == "number" and child_node.terminal then
-					local bits = child_node.value;
-					for j = #bits, 1, -1 do
-						local b = bits[j]-((i-1)*8);
-						if b ~= 8 then
-							local mask = bit.bnot(2^b-1);
-							if bit.band(bit.bxor(c, child_byte), mask) == 0 then
-								return true;
-							end
-						end
-					end
-				end
-			end
-			return false;
+			return find_match_in_descendents(node, item, len, i);
 		end
 		node = child;
 	end
 end
+--]]
+
+--[[
+function trie_methods:contains_ip(item)
+	item = item.packed
+	local node = self.root
+	local len = #item
+
+	print(string.byte(item, 1, 4))
+
+	local function search(node, index)
+		if node.terminal then
+			print("S", "TERM")
+			return true
+		end
+
+		if index > len then
+			print("S", "MAX LEN")
+			return false
+		end
+
+		local c = item:byte(index)
+		local child = node[c]
+
+		print("S", (" "):rep(index), ("item[%d] = %d, has_child = %s"):format(index, c, not not child));
+
+		if child then
+			-- Continue searching down the current path
+			return search(child, index + 1)
+		else
+			-- Check all children for a terminal node
+			for child_byte, child_node in pairs(node) do
+				if type(child_byte) == "number" and child_byte then
+					if search(child_node, index + 1) then
+						return true
+					end
+				end
+			end
+		end
+
+		return false
+	end
+
+	return search(node, 1)
+end
+--]]
 
 local function new()
 	return setmetatable({