From b54f0df57bfef48dc34f407ac388afcc8a83c6b7 Mon Sep 17 00:00:00 2001
From: Jon Neverland <jon@jonnev.se>
Date: Tue, 8 Aug 2017 12:33:33 +0200
Subject: [PATCH] Remove need for secure.enable_security (#7)

With changes in lua-matrix mod now works with only secure.trusted_mods
---
 README.md  | 10 +++++++---
 init.lua   |  9 ++++++++-
 lua-matrix |  2 +-
 3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index c2d764d..c05860d 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
 # Matrix mod for Minetest
 
 
-This mod creates a bridge between a [Matrix](https://matrix.org) channel and the in-game chat.  
+This mod creates a bridge between a [Matrix](https://matrix.org) channel and the in-game chat.
 The code is shamelessly based on the [irc](https://github.com/minetest-mods/irc) mod and examples from [lua-matrix](https://github.com/aperezdc/lua-matrix).
 
 
@@ -20,6 +20,8 @@ luarocks-5.1 install lua-cjson
 brew install openssl
 luarocks-5.1 install cqueues CRYPTO_DIR=/usr/local/opt/openssl/ OPENSSL_DIR=/usr/local/opt/openssl #https://github.com/wahern/cqueues/wiki/Installation-on-OSX#via-brew
 luarocks-5.1 install luaossl CRYPTO_DIR=/usr/local/opt/openssl/ OPENSSL_DIR=/usr/local/opt/openssl
+luarocks-5.1 install luasocket
+luarocks-5.1 install luasec OPENSSL_DIR=/usr/local/opt/openssl
 export MATRIX_API_HTTP_CLIENT=luasocket
 ```
 
@@ -30,15 +32,17 @@ Tested on 16.04.
 ```bash
 apt-get install lua5.1 luarocks lua-sec
 luarocks install lua-cjson
+luarocks install luasocket
+luarocks install luasec
 export MATRIX_API_HTTP_CLIENT=luasocket
 ```
 
 You might need to prepend `sudo` to first and second commands.
 
-For the moment you need to disabled mod security for lua-matrix to work. This will hopefully change.
+For the moment you need to add `matrix` to `secure.trusted_mods` for lua-matrix to work. This will hopefully change.
 
 ```
-secure.enable_security = false
+secure.trusted_mods = matrix
 ```
 
 [wiki]: https://wiki.minetest.net/Installing_mods
diff --git a/init.lua b/init.lua
index d835a28..64c6fab 100644
--- a/init.lua
+++ b/init.lua
@@ -8,7 +8,7 @@ local ie, req_ie = _G, minetest.request_insecure_environment
 if req_ie then ie = req_ie() end
 if not ie then
   error("The Matrix mod requires access to insecure functions in order "..
-    "to work. Please disable mod security. This will hopefully change.")
+    "to work. Please add matrix to secure.trusted_mods.")
 end
 
 ie.package.path =
@@ -29,6 +29,10 @@ local function eprintf(fmt, ...)
   minetest.log("info", fmt:format(...))
 end
 
+-- Temporarily set require so that LuaIRC can access it
+local old_require = require
+require = ie.require
+
 local client = require("matrix").client(matrix.config.server..":"..matrix.config.port)
 
 local start_ts = os.time() * 1000
@@ -139,3 +143,6 @@ function matrix.say(message)
     end
   end
 end
+
+-- Restore old (safe) functions
+require = old_require
diff --git a/lua-matrix b/lua-matrix
index 2946b55..151355a 160000
--- a/lua-matrix
+++ b/lua-matrix
@@ -1 +1 @@
-Subproject commit 2946b558101a22dd0770a2548f938ada86475256
+Subproject commit 151355a7904640b98eef6dd59e43adefc0d178ea
-- 
GitLab