From 8076227918765dac664cbc75060254da084caa98 Mon Sep 17 00:00:00 2001 From: LeMagnesium Date: Sun, 5 Jul 2015 15:31:21 +0200 Subject: [PATCH] Updated IRC to handle mod security - Solves part of #47 --- mods/irc/README.md | 5 ++++ mods/irc/hooks.lua | 4 +++- mods/irc/init.lua | 29 +++++++++++++++++------ other_things/irc-old-save/hooks.lua | 6 +++-- other_things/irc-old-save/init.lua | 36 +++++++++++++++++++---------- worlds/minetestforfun/news.txt | 1 + 6 files changed, 59 insertions(+), 22 deletions(-) diff --git a/mods/irc/README.md b/mods/irc/README.md index 006f09eb..f7042cfe 100755 --- a/mods/irc/README.md +++ b/mods/irc/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/mods/irc/hooks.lua b/mods/irc/hooks.lua index d64fe88a..c27ba5d9 100755 --- a/mods/irc/hooks.lua +++ b/mods/irc/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/mods/irc/init.lua b/mods/irc/init.lua index c3033767..1f67353f 100755 --- a/mods/irc/init.lua +++ b/mods/irc/init.lua @@ -3,25 +3,40 @@ 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 ..";/usr/lib/*/lua/5.1/socket/*.so" -- 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.. - ";/usr/lib/lua/5.1/?.so" +if not rawget(_G, "jit") and package.config:sub(1, 1) == "/" then + ie.package.path = ie.package.path.. 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, @@ -30,7 +45,7 @@ irc = { recent_message_count = 0, joined_players = {}, modpath = modpath, - lib = require("irc"), + lib = lib, } -- Compatibility @@ -38,7 +53,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") diff --git a/other_things/irc-old-save/hooks.lua b/other_things/irc-old-save/hooks.lua index 9a735eba..c27ba5d9 100755 --- a/other_things/irc-old-save/hooks.lua +++ b/other_things/irc-old-save/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 = {} @@ -252,7 +254,7 @@ function irc.hooks.preregister(conn) conn:send("CAP REQ sasl") conn:send("AUTHENTICATE PLAIN") conn:send("AUTHENTICATE "..authString) - --LuaIRC will send CAP END + conn:send("CAP END") end diff --git a/other_things/irc-old-save/init.lua b/other_things/irc-old-save/init.lua index c93bcf9f..1f67353f 100755 --- a/other_things/irc-old-save/init.lua +++ b/other_things/irc-old-save/init.lua @@ -3,25 +3,40 @@ 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 + ..";/usr/lib/*/lua/5.1/socket/*.so" -- 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.. +if not rawget(_G, "jit") and package.config:sub(1, 1) == "/" then + ie.package.path = ie.package.path.. ";/usr/share/lua/5.1/?.lua".. ";/usr/share/lua/5.1/?/init.lua" - package.cpath = package.cpath.. - -- ";/usr/lib/lua/5.1/?.so" - ";/usr/lib/x86_64-linux-gnu/lua/5.1/?.so" +if not rawget(_G, "jit") and package.config:sub(1, 1) == "/" then + ie.package.path = ie.package.path.. 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, @@ -30,7 +45,7 @@ irc = { recent_message_count = 0, joined_players = {}, modpath = modpath, - lib = require("irc"), + lib = lib, } -- Compatibility @@ -38,7 +53,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") @@ -104,9 +119,6 @@ function irc:connect() return end - print("== This is a debug line, please check for it ==") - print(self.config.NSPass) - print("=== DEBUG FINISHED ===") if self.config.NSPass then self:say("NickServ", "IDENTIFY "..self.config.NSPass) end diff --git a/worlds/minetestforfun/news.txt b/worlds/minetestforfun/news.txt index 6b3e91b6..2b735ffd 100755 --- a/worlds/minetestforfun/news.txt +++ b/worlds/minetestforfun/news.txt @@ -12,6 +12,7 @@ NPC pour qu'il devienne dressé. Cliquer-droit sur lui le fera alternativement s suivre. ---xx/07/2015--- (Remerciements : LeMagnesium/Mg, Obani, mgl512/Le_Docteur, Gael-de-Sailly, crabman77/crabman) +MAJ de "irc" (prise en charge de la sécurité des mods) MAJ de "money" (utilisation d'une version plus récente et optimisée, nouvelles textures) MAJ de "3d_armor" (nombreux bugfixs, ajout d'un paramètre de "poids" augmentant la faim en fonction de l'armure portée, les valeurs seront disponibles sur le site bientôt) MAJ de "nether" (crashfix de la nourriture du nether)