From 0c900dbac20709b58305bea4ca2671b6e7434c41 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Sat, 16 May 2015 19:54:24 -0400 Subject: [PATCH] Add support for mod security --- README.md | 5 +++++ hooks.lua | 4 +++- init.lua | 27 +++++++++++++++++++++------ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 006f09e..f7042cf 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,11 @@ many distributions, for example: # # On Debian/Ubuntu: # apt-get install lua-socket +You will also need to add IRC to your trusted mods if you haven't disabled mod +security. Here's an example configuration line: + + secure.trusted_mods = irc + Settings -------- diff --git a/hooks.lua b/hooks.lua index 14e07f8..f74a628 100644 --- a/hooks.lua +++ b/hooks.lua @@ -1,8 +1,10 @@ -- This file is licensed under the terms of the BSD 2-clause license. -- See LICENSE.txt for details. +local ie = ... + -- MIME is part of LuaSocket -local b64e = require("mime").b64 +local b64e = ie.require("mime").b64 irc.hooks = {} irc.registered_hooks = {} diff --git a/init.lua b/init.lua index 7f3ac6a..2073347 100644 --- a/init.lua +++ b/init.lua @@ -3,24 +3,39 @@ local modpath = minetest.get_modpath(minetest.get_current_modname()) -package.path = +-- Handle mod security if needed +local ie, req_ie = _G, minetest.request_insecure_environment +if req_ie then ie = req_ie() end +if not ie then + error("The IRC mod requires access to insecure functions in order ".. + "to work. Please add the irc mod to your secure.trusted_mods ".. + "setting or disable the irc mod.") +end + +ie.package.path = -- To find LuaIRC's init.lua modpath.."/?/init.lua;" -- For LuaIRC to find its files ..modpath.."/?.lua;" - ..package.path + ..ie.package.path -- The build of Lua that Minetest comes with only looks for libraries under -- /usr/local/share and /usr/local/lib but LuaSocket is often installed under -- /usr/share and /usr/lib. if not rawget(_G, "jit") and package.config:sub(1, 1) == "/" then - package.path = package.path.. + ie.package.path = ie.package.path.. ";/usr/share/lua/5.1/?.lua".. ";/usr/share/lua/5.1/?/init.lua" - package.cpath = package.cpath.. + ie.package.cpath = ie.package.cpath.. ";/usr/lib/lua/5.1/?.so" end +-- Temporarily set require so that LuaIRC can access it +local old_require = require +require = ie.require +local lib = ie.require("irc") +require = old_require + irc = { version = "0.2.0", connected = false, @@ -29,7 +44,7 @@ irc = { recent_message_count = 0, joined_players = {}, modpath = modpath, - lib = require("irc"), + lib = lib, } -- Compatibility @@ -37,7 +52,7 @@ mt_irc = irc dofile(modpath.."/config.lua") dofile(modpath.."/messages.lua") -dofile(modpath.."/hooks.lua") +loadfile(modpath.."/hooks.lua")(ie) dofile(modpath.."/callback.lua") dofile(modpath.."/chatcmds.lua") dofile(modpath.."/botcmds.lua")