Example #1
0
	void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
	{
		const Anope::string &nick = params[0];
		const Anope::string &pass = params.size() > 1 ? params[1] : "";

		User *user = User::Find(nick, true);

		if (user && source.GetUser() == user)
		{
			source.Reply(_("You can't %s yourself!"), source.command.lower().c_str());
			return;
		}

		NickServ::Nick *na = NickServ::FindNick(nick);

		if (!na)
		{
			source.Reply(_("\002{0}\002 isn't registered."), nick);
			return;
		}

		if (na->GetAccount()->HasFieldS("NS_SUSPENDED"))
		{
			source.Reply(_("\002{0}\002 is suspended."), na->GetNick());
			return;
		}

		bool ok = false;
		if (source.GetAccount() == na->GetAccount())
			ok = true;
		else if (!na->GetAccount()->HasFieldS("NS_SECURE") && source.GetUser() && na->GetAccount()->IsOnAccess(source.GetUser()))
			ok = true;

		if (certservice && source.GetUser() && certservice->Matches(source.GetUser(), na->GetAccount()))
			ok = true;

		if (ok == false && !pass.empty())
		{
			NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSRecoverRequestListener(source, this, na->GetNick(), pass), owner, na->GetNick(), pass);
			Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, source.GetUser(), req);
			req->Dispatch();
		}
		else
		{
			NSRecoverRequestListener req(source, this, na->GetNick(), pass);

			if (ok)
				req.OnSuccess(nullptr);
			else
				req.OnFail(nullptr);
		}
	}
Example #2
0
    bool DoCheckAuthentication(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request)
    {
        Anope::string username = request.data.size() > 0 ? request.data[0] : "";
        Anope::string password = request.data.size() > 1 ? request.data[1] : "";

        if (username.empty() || password.empty() || !NickServ::service)
            request.reply("error", "Invalid parameters");
        else
        {
            NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new XMLRPCIdentifyRequest(request, client, iface), me, username, password);
            EventManager::Get()->Dispatch(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req);
            req->Dispatch();
            return false;
        }

        return true;
    }
Example #3
0
	void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
	{
		User *u = source.GetUser();

		Anope::string nick;
		if (params.empty())
		{
			NickServ::Account* core = u->Account();
			if (core)
				nick = core->GetDisplay();
		}
		else
			nick = params[0];

		if (nick.empty())
		{
			this->SendSyntax(source);
			return;
		}

		const Anope::string &pass = params.size() > 1 ? params[1] : "";

		if (Anope::ReadOnly)
		{
			source.Reply(_("Sorry, nickname grouping is temporarily disabled."));
			return;
		}

		if (!IRCD->IsNickValid(u->nick))
		{
			source.Reply(_("\002{0}\002 may not be registered."), u->nick);
			return;
		}

		if (Config->GetModule("nickserv")->Get<bool>("restrictopernicks"))
			for (Oper *o : Serialize::GetObjects<Oper *>())
			{
				if (!u->HasMode("OPER") && u->nick.find_ci(o->GetName()) != Anope::string::npos)
				{
					source.Reply(_("\002{0}\002 may not be registered because it is too similar to an operator nick."), u->nick);
					return;
				}
			}

		NickServ::Nick *target, *na = NickServ::FindNick(u->nick);
		const Anope::string &guestnick = Config->GetModule("nickserv")->Get<Anope::string>("guestnickprefix", "Guest");
		time_t reg_delay = Config->GetModule("nickserv")->Get<time_t>("regdelay");
		unsigned maxaliases = Config->GetModule(this->GetOwner())->Get<unsigned>("maxaliases");
		if (!(target = NickServ::FindNick(nick)))
		{
			source.Reply(_("\002{0}\002 isn't registered."), nick);
			return;
		}

		if (Anope::CurTime < u->lastnickreg + reg_delay)
		{
			source.Reply(_("Please wait \002{0}\002 seconds before using the \002{1}\002 command again."), (reg_delay + u->lastnickreg) - Anope::CurTime, source.command);
			return;
		}

		if (target->GetAccount()->HasFieldS("NS_SUSPENDED"))
		{
			Log(LOG_COMMAND, source, this) << "and tried to group to suspended nick " << target->GetNick();
			source.Reply(_("\002{0}\002 is suspended."), target->GetNick());
			return;
		}

		if (na && Config->GetModule(this->GetOwner())->Get<bool>("nogroupchange"))
		{
			source.Reply(_("Your nick is already registered."));
			return;
		}

		if (na && target->GetAccount() == na->GetAccount())
		{
			source.Reply(_("You are already a member of the group of \002{0}\002."), target->GetNick());
			return;
		}

		if (na && na->GetAccount() != u->Account())
		{
			source.Reply(_("\002{0}\002 is already registered."), na->GetNick());
			return;
		}

		if (na && Config->GetModule(this->GetOwner())->Get<bool>("nogroupchange"))
		{
			source.Reply(_("You are already registered."));
			return;
		}

		if (maxaliases && target->GetAccount()->GetRefs<NickServ::Nick *>().size() >= maxaliases && !target->GetAccount()->IsServicesOper())
		{
			source.Reply(_("There are too many nicknames in your group."));
			return;
		}

		if (u->nick.length() <= guestnick.length() + 7 &&
			u->nick.length() >= guestnick.length() + 1 &&
			!u->nick.find_ci(guestnick) && !u->nick.substr(guestnick.length()).find_first_not_of("1234567890"))
		{
			source.Reply(_("\002{0}\002 may not be registered."), u->nick);
			return;
		}

		bool ok = false;
		if (!na && u->Account() == target->GetAccount())
			ok = true;

		if (certservice && certservice->Matches(u, target->GetAccount()))
			ok = true;

		if (ok == false && !pass.empty())
		{
			NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSGroupRequestListener(source, this, u->nick, target), this->GetOwner(), target->GetAccount()->GetDisplay(), pass);
			EventManager::Get()->Dispatch(&Event::CheckAuthentication::OnCheckAuthentication, source.GetUser(), req);
			req->Dispatch();
		}
		else
		{
			NSGroupRequestListener req(source, this, u->nick, target);

			if (ok)
				req.OnSuccess(nullptr);
			else
				req.OnFail(nullptr);
		}
	}