]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_loadmodule.cpp
Prevent users from sending an empty TAGMSG.
[user/henk/code/inspircd.git] / src / coremods / core_loadmodule.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2018 linuxdaemon <linuxdaemon.irc@gmail.com>
5  *   Copyright (C) 2017-2018 Sadie Powell <sadie@witchery.services>
6  *   Copyright (C) 2013-2014, 2016 Attila Molnar <attilamolnar@hush.com>
7  *   Copyright (C) 2012 Robby <robby@chatbelgie.be>
8  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
9  *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
10  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
11  *   Copyright (C) 2006, 2010 Craig Edwards <brain@inspircd.org>
12  *
13  * This file is part of InspIRCd.  InspIRCd is free software: you can
14  * redistribute it and/or modify it under the terms of the GNU General Public
15  * License as published by the Free Software Foundation, version 2.
16  *
17  * This program is distributed in the hope that it will be useful, but WITHOUT
18  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
20  * details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24  */
25
26
27 #include "inspircd.h"
28
29 /** Handle /LOADMODULE.
30  */
31 class CommandLoadmodule : public Command
32 {
33  public:
34         /** Constructor for loadmodule.
35          */
36         CommandLoadmodule ( Module* parent) : Command(parent,"LOADMODULE",1,1) { flags_needed='o'; syntax = "<modulename>"; }
37         /** Handle command.
38          * @param parameters The parameters to the command
39          * @param user The user issuing the command
40          * @return A value from CmdResult to indicate command success or failure.
41          */
42         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
43 };
44
45 /** Handle /LOADMODULE
46  */
47 CmdResult CommandLoadmodule::Handle(User* user, const Params& parameters)
48 {
49         if (ServerInstance->Modules->Load(parameters[0]))
50         {
51                 ServerInstance->SNO->WriteGlobalSno('a', "NEW MODULE: %s loaded %s",user->nick.c_str(), parameters[0].c_str());
52                 user->WriteNumeric(RPL_LOADEDMODULE, parameters[0], "Module successfully loaded.");
53                 return CMD_SUCCESS;
54         }
55         else
56         {
57                 user->WriteNumeric(ERR_CANTLOADMODULE, parameters[0], ServerInstance->Modules->LastError());
58                 return CMD_FAILURE;
59         }
60 }
61
62 /** Handle /UNLOADMODULE.
63  */
64 class CommandUnloadmodule : public Command
65 {
66  public:
67         bool allowcoreunload;
68
69         /** Constructor for unloadmodule.
70          */
71         CommandUnloadmodule(Module* parent)
72                 : Command(parent, "UNLOADMODULE", 1)
73                 , allowcoreunload(false)
74         {
75                 flags_needed = 'o';
76                 syntax = "<modulename>";
77         }
78
79         /** Handle command.
80          * @param parameters The parameters to the command
81          * @param user The user issuing the command
82          * @return A value from CmdResult to indicate command success or failure.
83          */
84         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
85 };
86
87 CmdResult CommandUnloadmodule::Handle(User* user, const Params& parameters)
88 {
89         if (!allowcoreunload && InspIRCd::Match(parameters[0], "core_*.so", ascii_case_insensitive_map))
90         {
91                 user->WriteNumeric(ERR_CANTUNLOADMODULE, parameters[0], "You cannot unload core commands!");
92                 return CMD_FAILURE;
93         }
94
95         Module* m = ServerInstance->Modules->Find(parameters[0]);
96         if (m == creator)
97         {
98                 user->WriteNumeric(ERR_CANTUNLOADMODULE, parameters[0], "You cannot unload module loading commands!");
99                 return CMD_FAILURE;
100         }
101
102         if (m && ServerInstance->Modules->Unload(m))
103         {
104                 ServerInstance->SNO->WriteGlobalSno('a', "MODULE UNLOADED: %s unloaded %s", user->nick.c_str(), parameters[0].c_str());
105                 user->WriteNumeric(RPL_UNLOADEDMODULE, parameters[0], "Module successfully unloaded.");
106         }
107         else
108         {
109                 user->WriteNumeric(ERR_CANTUNLOADMODULE, parameters[0], (m ? ServerInstance->Modules->LastError() : "No such module"));
110                 return CMD_FAILURE;
111         }
112
113         return CMD_SUCCESS;
114 }
115
116 class CoreModLoadModule : public Module
117 {
118         CommandLoadmodule cmdloadmod;
119         CommandUnloadmodule cmdunloadmod;
120
121  public:
122         CoreModLoadModule()
123                 : cmdloadmod(this), cmdunloadmod(this)
124         {
125         }
126
127         Version GetVersion() CXX11_OVERRIDE
128         {
129                 return Version("Provides the LOADMODULE and UNLOADMODULE commands", VF_VENDOR|VF_CORE);
130         }
131
132         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
133         {
134                 ConfigTag* tag = ServerInstance->Config->ConfValue("security");
135                 cmdunloadmod.allowcoreunload = tag->getBool("allowcoreunload");
136         }
137 };
138
139 MODULE_INIT(CoreModLoadModule)