1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2018 linuxdaemon <linuxdaemon.irc@gmail.com>
5  *   Copyright (C) 2018 Sadie Powell <sadie@witchery.services>
6  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
7  *   Copyright (C) 2012, 2014-2016, 2018 Attila Molnar <attilamolnar@hush.com>
8  *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
9  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
10  *   Copyright (C) 2008, 2010 Craig Edwards <brain@inspircd.org>
11  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
12  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
13  *
14  * This file is part of InspIRCd.  InspIRCd is free software: you can
15  * redistribute it and/or modify it under the terms of the GNU General Public
16  * License as published by the Free Software Foundation, version 2.
17  *
18  * This program is distributed in the hope that it will be useful, but WITHOUT
19  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
21  * details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
25  */
26 
27 
28 #include "inspircd.h"
29 #include "exitcodes.h"
30 #include "core_oper.h"
31 
CommandDie(Module * parent,std::string & hashref)32 CommandDie::CommandDie(Module* parent, std::string& hashref)
33 	: Command(parent, "DIE", 1, 1)
34 	, hash(hashref)
35 {
36 	flags_needed = 'o';
37 	syntax = "<servername>";
38 }
39 
SendError(const std::string & message)40 void DieRestart::SendError(const std::string& message)
41 {
42 	ClientProtocol::Messages::Error errormsg(message);
43 	ClientProtocol::Event errorevent(ServerInstance->GetRFCEvents().error, errormsg);
44 	const UserManager::LocalList& list = ServerInstance->Users.GetLocalUsers();
45 	for (UserManager::LocalList::const_iterator i = list.begin(); i != list.end(); ++i)
46 	{
47 		LocalUser* user = *i;
48 		if (user->registered == REG_ALL)
49 		{
50 			user->WriteNotice(message);
51 		}
52 		else
53 		{
54 			// Unregistered connections receive ERROR, not a NOTICE
55 			user->Send(errorevent);
56 		}
57 	}
58 }
59 
60 /** Handle /DIE
61  */
Handle(User * user,const Params & parameters)62 CmdResult CommandDie::Handle(User* user, const Params& parameters)
63 {
64 	if (ServerInstance->PassCompare(user, password, parameters[0], hash))
65 	{
66 		{
67 			std::string diebuf = "*** DIE command from " + user->GetFullHost() + ". Terminating.";
68 			ServerInstance->Logs->Log(MODNAME, LOG_SPARSE, diebuf);
69 			DieRestart::SendError(diebuf);
70 		}
71 
72 		ServerInstance->Exit(EXIT_STATUS_DIE);
73 	}
74 	else
75 	{
76 		ServerInstance->Logs->Log(MODNAME, LOG_SPARSE, "Failed /DIE command from %s", user->GetFullRealHost().c_str());
77 		ServerInstance->SNO->WriteGlobalSno('a', "Failed DIE command from %s.", user->GetFullRealHost().c_str());
78 		return CMD_FAILURE;
79 	}
80 	return CMD_SUCCESS;
81 }
82