]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_loadmodule.cpp
Fix a copy/paste error in the http path normalising code.
[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, 2020 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)
37                 : Command(parent,"LOADMODULE", 1, 1)
38         {
39                 flags_needed = 'o';
40                 syntax = "<modulename>";
41         }
42
43         /** Handle command.
44          * @param parameters The parameters to the command
45          * @param user The user issuing the command
46          * @return A value from CmdResult to indicate command success or failure.
47          */
48         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
49 };
50
51 /** Handle /LOADMODULE
52  */
53 CmdResult CommandLoadmodule::Handle(User* user, const Params& parameters)
54 {
55         if (ServerInstance->Modules->Load(parameters[0]))
56         {
57                 ServerInstance->SNO->WriteGlobalSno('a', "NEW MODULE: %s loaded %s",user->nick.c_str(), parameters[0].c_str());
58                 user->WriteNumeric(RPL_LOADEDMODULE, parameters[0], "Module successfully loaded.");
59                 return CMD_SUCCESS;
60         }
61         else
62         {
63                 user->WriteNumeric(ERR_CANTLOADMODULE, parameters[0], ServerInstance->Modules->LastError());
64                 return CMD_FAILURE;
65         }
66 }
67
68 /** Handle /UNLOADMODULE.
69  */
70 class CommandUnloadmodule : public Command
71 {
72  public:
73         bool allowcoreunload;
74
75         /** Constructor for unloadmodule.
76          */
77         CommandUnloadmodule(Module* parent)
78                 : Command(parent, "UNLOADMODULE", 1)
79                 , allowcoreunload(false)
80         {
81                 flags_needed = 'o';
82                 syntax = "<modulename>";
83         }
84
85         /** Handle command.
86          * @param parameters The parameters to the command
87          * @param user The user issuing the command
88          * @return A value from CmdResult to indicate command success or failure.
89          */
90         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
91 };
92
93 CmdResult CommandUnloadmodule::Handle(User* user, const Params& parameters)
94 {
95         if (!allowcoreunload && InspIRCd::Match(parameters[0], "core_*.so", ascii_case_insensitive_map))
96         {
97                 user->WriteNumeric(ERR_CANTUNLOADMODULE, parameters[0], "You cannot unload core commands!");
98                 return CMD_FAILURE;
99         }
100
101         Module* m = ServerInstance->Modules->Find(parameters[0]);
102         if (m == creator)
103         {
104                 user->WriteNumeric(ERR_CANTUNLOADMODULE, parameters[0], "You cannot unload module loading commands!");
105                 return CMD_FAILURE;
106         }
107
108         if (m && ServerInstance->Modules->Unload(m))
109         {
110                 ServerInstance->SNO->WriteGlobalSno('a', "MODULE UNLOADED: %s unloaded %s", user->nick.c_str(), parameters[0].c_str());
111                 user->WriteNumeric(RPL_UNLOADEDMODULE, parameters[0], "Module successfully unloaded.");
112         }
113         else
114         {
115                 user->WriteNumeric(ERR_CANTUNLOADMODULE, parameters[0], (m ? ServerInstance->Modules->LastError() : "No such module"));
116                 return CMD_FAILURE;
117         }
118
119         return CMD_SUCCESS;
120 }
121
122 class CoreModLoadModule : public Module
123 {
124         CommandLoadmodule cmdloadmod;
125         CommandUnloadmodule cmdunloadmod;
126
127  public:
128         CoreModLoadModule()
129                 : cmdloadmod(this), cmdunloadmod(this)
130         {
131         }
132
133         Version GetVersion() CXX11_OVERRIDE
134         {
135                 return Version("Provides the LOADMODULE and UNLOADMODULE commands", VF_VENDOR|VF_CORE);
136         }
137
138         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
139         {
140                 ConfigTag* tag = ServerInstance->Config->ConfValue("security");
141                 cmdunloadmod.allowcoreunload = tag->getBool("allowcoreunload");
142         }
143 };
144
145 MODULE_INIT(CoreModLoadModule)