Пример #1
0
	void OnNotify() override
	{
		for (std::map<Anope::string, LDAPService *>::iterator it = this->LDAPServices.begin(); it != this->LDAPServices.end(); ++it)
		{
			LDAPService *s = it->second;

			LDAPService::query_queue results;
			s->Lock();
			results.swap(s->results);
			s->Unlock();

			for (unsigned int i = 0; i < results.size(); ++i)
			{
				LDAPRequest *req = results[i];
				LDAPInterface *li = req->inter;
				LDAPResult *r = req->result;

				if (li != NULL)
				{
					if (!r->getError().empty())
					{
						logger.Log("Error running LDAP query: {0}", r->getError());
						li->OnError(*r);
					}
					else
						li->OnResult(*r);
				}

				delete req;
			}
		}
	}
Пример #2
0
	void OnResult(const LDAPResult &r)
	{
		std::map<LDAPQuery, Anope::string>::iterator it = this->requests.find(r.id);
		if (it == this->requests.end())
			return;
		User *u = finduser(it->second);
		this->requests.erase(it);


		if (!u || !u->Account())
			return;

		try
		{
			const LDAPAttributes &attr = r.get(0);

			const Anope::string &opertype = attr.get(opertype_attribute);

			OperType *ot = OperType::Find(opertype);
			if (ot != NULL && (u->Account()->o == NULL || ot != u->Account()->o->ot))
			{
				Oper *o = u->Account()->o;
				if (o != NULL && my_opers.count(o) > 0)
				{
					my_opers.erase(o);
					delete o;
				}
				o = new Oper(u->nick, ot);
				my_opers.insert(o);
				u->Account()->o = o;
				Log() << "m_ldap_oper: Tied " << u->nick << " (" << u->Account()->display << ") to opertype " << ot->GetName();
			}
		}
		catch (const LDAPException &ex)
		{
			if (u->Account()->o != NULL)
			{
				if (my_opers.count(u->Account()->o) > 0)
				{
					my_opers.erase(u->Account()->o);
					delete u->Account()->o;
				}
				u->Account()->o = NULL;

				Log() << "m_ldap_oper: Removed services operator from " << u->nick << " (" << u->Account()->display << ")";
			}
		}
	}
Пример #3
0
    void OnResult(const LDAPResult &r) override
    {
        if (!u || !u->Account())
            return;

        NickServ::Account *nc = u->Account();

        try
        {
            const LDAPAttributes &attr = r.get(0);

            const Anope::string &opertype = attr.get(opertype_attribute);

            OperType *ot = OperType::Find(opertype);
            if (ot != NULL && (nc->o == NULL || ot != nc->o->ot))
            {
                Oper *o = nc->o;
                if (o != NULL && my_opers.count(o) > 0)
                {
                    my_opers.erase(o);
                    delete o;
                }
                o = new Oper(u->nick, ot);
                my_opers.insert(o);
                nc->o = o;

                Log(this->owner) << "Tied " << u->nick << " (" << nc->GetDisplay() << ") to opertype " << ot->GetName();
            }
        }
        catch (const LDAPException &ex)
        {
            if (nc->o != NULL)
            {
                if (my_opers.count(nc->o) > 0)
                {
                    my_opers.erase(nc->o);
                    delete nc->o;
                }
                nc->o = NULL;

                Log(this->owner) << "Removed services operator from " << u->nick << " (" << nc->GetDisplay() << ")";
            }
        }
    }
Пример #4
0
	void OnResult(const LDAPResult &r) override
	{
		if (!ii->lprov)
			return;

		switch (r.type)
		{
			case QUERY_SEARCH:
			{
				if (!r.empty())
				{
					try
					{
						const LDAPAttributes &attr = r.get(0);
						ii->dn = attr.get("dn");
						Log(LOG_DEBUG) << "m_ldap_authenticationn: binding as " << ii->dn;

						ii->lprov->Bind(new IdentifyInterface(this->owner, ii), ii->dn, ii->req->GetPassword());
						ii = NULL;
					}
					catch (const LDAPException &ex)
					{
						Log(this->owner) << "Error binding after search: " << ex.GetReason();
					}
				}
				break;
			}
			case QUERY_BIND:
			{
				if (ii->admin_bind)
				{
					Anope::string sf = search_filter.replace_all_cs("%account", ii->req->GetAccount()).replace_all_cs("%object_class", object_class);
					try
					{
						Log(LOG_DEBUG) << "m_ldap_authentication: searching for " << sf;
						ii->lprov->Search(new IdentifyInterface(this->owner, ii), basedn, sf);
						ii->admin_bind = false;
						ii = NULL;
					}
					catch (const LDAPException &ex)
					{
						Log(this->owner) << "Unable to search for " << sf << ": " << ex.GetReason();
					}
				}
				else
				{
					NickServ::Nick *na = NickServ::FindNick(ii->req->GetAccount());
					if (na == NULL)
					{
						na = new NickServ::Nick(ii->req->GetAccount(), new NickServ::Account(ii->req->GetAccount()));
						na->SetLastRealname(ii->user ? ii->user->realname : ii->req->GetAccount());
						NickServ::Event::OnNickRegister(&NickServ::Event::NickRegister::OnNickRegister, ii->user, na, ii->req->GetPassword());;
						ServiceBot *NickServ = Config->GetClient("NickServ");
						if (ii->user && NickServ)
							ii->user->SendMessage(NickServ, _("Your account \002%s\002 has been successfully created."), na->GetNick().c_str());
					}
					// encrypt and store the password in the nickcore
					Anope::Encrypt(ii->req->GetPassword(), na->GetAccount()->pass);

					na->GetAccount()->Extend<Anope::string>("m_ldap_authentication_dn", ii->dn);
					ii->req->Success(me);
				}
				break;
			}
			default:
				break;
		}
	}