2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2019 linuxdaemon <linuxdaemon.irc@gmail.com>
5 * Copyright (C) 2014 Googolplexed <googol@googolplexed.net>
6 * Copyright (C) 2013, 2018-2019 Sadie Powell <sadie@witchery.services>
7 * Copyright (C) 2012-2014, 2018 Attila Molnar <attilamolnar@hush.com>
8 * Copyright (C) 2012 Robby <robby@chatbelgie.be>
9 * Copyright (C) 2012 Boleslaw Tokarski <boleslaw.tokarski@tieto.com>
10 * Copyright (C) 2010 Daniel De Graaf <danieldg@inspircd.org>
12 * This file is part of InspIRCd. InspIRCd is free software: you can
13 * redistribute it and/or modify it under the terms of the GNU General Public
14 * License as published by the Free Software Foundation, version 2.
16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include "modules/account.h"
29 class ModulePassForward : public Module
31 std::string nickrequired, forwardmsg, forwardcmd;
34 Version GetVersion() CXX11_OVERRIDE
36 return Version("Allows the /PASS password to be forwarded to a services pseudoclient such as NickServ.", VF_VENDOR);
39 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
41 ConfigTag* tag = ServerInstance->Config->ConfValue("passforward");
42 nickrequired = tag->getString("nick", "NickServ");
43 forwardmsg = tag->getString("forwardmsg", "NOTICE $nick :*** Forwarding PASS to $nickrequired");
44 forwardcmd = tag->getString("cmd", "SQUERY $nickrequired :IDENTIFY $pass", 1);
47 void FormatStr(std::string& result, const std::string& format, const LocalUser* user)
49 for (unsigned int i = 0; i < format.length(); i++)
54 if (!format.compare(i, 13, "$nickrequired", 13))
56 result.append(nickrequired);
59 else if (!format.compare(i, 5, "$nick", 5))
61 result.append(user->nick);
64 else if (!format.compare(i, 5, "$user", 5))
66 result.append(user->ident);
69 else if (!format.compare(i, 5, "$pass", 5))
71 result.append(user->password);
82 void OnPostConnect(User* ruser) CXX11_OVERRIDE
84 LocalUser* user = IS_LOCAL(ruser);
85 if (!user || user->password.empty())
88 // If the connect class requires a password, don't forward it
89 if (!user->MyClass->config->getString("password").empty())
92 AccountExtItem* actext = GetAccountExtItem();
93 if (actext && actext->get(user))
95 // User is logged in already (probably via SASL) don't forward the password
99 if (!nickrequired.empty())
101 /* Check if nick exists and its server is ulined */
102 User* u = ServerInstance->FindNick(nickrequired);
103 if (!u || !u->server->IsULine())
108 if (!forwardmsg.empty())
110 FormatStr(tmp, forwardmsg, user);
111 ServerInstance->Parser.ProcessBuffer(user, tmp);
115 FormatStr(tmp, forwardcmd, user);
116 ServerInstance->Parser.ProcessBuffer(user, tmp);
120 MODULE_INIT(ModulePassForward)