X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fusers.cpp;h=1955c90295bea651cdce870dcda06ec8e93a5c8e;hb=9bc8b2602426e187c4c5ba6ff0fad0641155357a;hp=59d19adff0dec4a77ef299b9897d2f66de0062bf;hpb=3759fe0ba2420bd564abb4b034582ea0866907aa;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/users.cpp b/src/users.cpp index 59d19adff..1955c9029 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -553,7 +553,7 @@ bool userrec::HasPermission(const std::string &command) return true; // are they even an oper at all? - if (*this->oper) + if (IS_OPER(this)) { opertype_t::iterator iter_opertype = ServerInstance->Config->opertypes.find(this->oper); if (iter_opertype != ServerInstance->Config->opertypes.end()) @@ -690,8 +690,8 @@ void userrec::AddWriteBuf(const std::string &data) try { - if (data.length() > 512) - sendq.append(data.substr(0,510)).append("\r\n"); + if (data.length() > MAXBUF - 2) /* MAXBUF has a value of 514, to account for line terminators */ + sendq.append(data.substr(0,MAXBUF - 4)).append("\r\n"); /* MAXBUF-4 = 510 */ else sendq.append(data); } @@ -800,10 +800,13 @@ void userrec::UnOper() { try { - if (*this->oper) + if (IS_OPER(this)) { + // unset their oper type (what IS_OPER checks), and remove +o *this->oper = 0; this->modes[UM_OPERATOR] = 0; + + // remove them from the opers list. for (std::vector::iterator a = ServerInstance->all_opers.begin(); a < ServerInstance->all_opers.end(); a++) { if (*a == this) @@ -897,13 +900,12 @@ void userrec::AddClient(InspIRCd* Instance, int socket, int port, bool iscached, Instance->AddLocalClone(New); Instance->AddGlobalClone(New); + /* + * First class check. We do this again in FullConnect after DNS is done, and NICK/USER is recieved. + * See my note down there for why this is required. DO NOT REMOVE. :) -- w00t + */ ConnectClass* i = New->GetClass(); - - if ((!i) || (i->GetType() == CC_DENY)) - { - userrec::QuitUser(Instance, New,"Unauthorised connection"); - return; - } + New->CheckClass(); New->pingmax = i->GetPingTime(); New->nping = Instance->Time() + i->GetPingTime() + Instance->Config->dns_timeout; @@ -984,41 +986,57 @@ unsigned long userrec::LocalCloneCount() return 0; } -void userrec::FullConnect() +/* + * Check class restrictions + */ +void userrec::CheckClass() { - ServerInstance->stats->statsConnects++; - this->idle_lastmsg = ServerInstance->Time(); - ConnectClass* a = this->GetClass(); if ((!a) || (a->GetType() == CC_DENY)) { - this->muted = true; - ServerInstance->GlobalCulls.AddItem(this,"Unauthorised connection"); + userrec::QuitUser(ServerInstance, this, "Unauthorised connection"); return; } if ((!a->GetPass().empty()) && (!this->haspassed)) { - this->muted = true; - ServerInstance->GlobalCulls.AddItem(this,"Invalid password"); + userrec::QuitUser(ServerInstance, this, "Invalid password"); + return; + } + + if ((!a) || (a->GetType() == CC_DENY)) + { + userrec::QuitUser(ServerInstance, this,"Unauthorised connection"); return; } if ((a->GetMaxLocal()) && (this->LocalCloneCount() > a->GetMaxLocal())) { - this->muted = true; - ServerInstance->GlobalCulls.AddItem(this, "No more connections allowed from your host via this connect class (local)"); + userrec::QuitUser(ServerInstance, this, "No more connections allowed from your host via this connect class (local)"); ServerInstance->WriteOpers("*** WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a->GetMaxLocal(), this->GetIPString()); return; } else if ((a->GetMaxGlobal()) && (this->GlobalCloneCount() > a->GetMaxGlobal())) { - this->muted = true; - ServerInstance->GlobalCulls.AddItem(this, "No more connections allowed from your host via this connect class (global)"); - ServerInstance->WriteOpers("*** WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s",a->GetMaxGlobal(), this->GetIPString()); + userrec::QuitUser(ServerInstance, this, "No more connections allowed from your host via this connect class (global)"); + ServerInstance->WriteOpers("*** WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s", a->GetMaxGlobal(), this->GetIPString()); return; } +} + +void userrec::FullConnect() +{ + ServerInstance->stats->statsConnects++; + this->idle_lastmsg = ServerInstance->Time(); + + /* + * You may be thinking "wtf, we checked this in userrec::AddClient!" - and yes, we did, BUT. + * At the time AddClient is called, we don't have a resolved host, by here we probably do - which + * may put the user into a totally seperate class with different restrictions! so we *must* check again. + * Don't remove this! -- w00t + */ + this->CheckClass(); if (!this->exempt) { @@ -1060,6 +1078,12 @@ void userrec::FullConnect() if (ServerInstance->unregistered_count) ServerInstance->unregistered_count--; + /* Trigger LUSERS output, give modules a chance too */ + int MOD_RESULT = 0; + FOREACH_RESULT(I_OnPreCommand, OnPreCommand("LUSERS", NULL, 0, this, true, "LUSERS")); + if (!MOD_RESULT) + ServerInstance->CallCommandHandler("LUSERS", NULL, 0, this); + /* * fix 3 by brain, move registered = 7 below these so that spurious modes and host * changes dont go out onto the network and produce 'fake direction'. @@ -1070,7 +1094,7 @@ void userrec::FullConnect() FOREACH_MOD(I_OnPostConnect,OnPostConnect(this)); - ServerInstance->SNO->WriteToSnoMask('c',"Client connecting on port %d: %s!%s@%s [%s]", this->GetPort(), this->nick, this->ident, this->host, this->GetIPString()); + ServerInstance->SNO->WriteToSnoMask('c',"Client connecting on port %d: %s!%s@%s [%s] [%s]", this->GetPort(), this->nick, this->ident, this->host, this->GetIPString(), this->fullname); } /** userrec::UpdateNick() @@ -1468,10 +1492,10 @@ void userrec::WriteCommon(const std::string &text) CUList* ulist = v->first->GetUsers(); for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++) { - if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id)) + if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id)) { - already_sent[i->second->fd] = uniq_id; - i->second->Write(out); + already_sent[i->first->fd] = uniq_id; + i->first->Write(out); sent_to_at_least_one = true; } } @@ -1529,12 +1553,12 @@ void userrec::WriteCommonQuit(const std::string &normal_text, const std::string CUList *ulist = v->first->GetUsers(); for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++) { - if (this != i->second) + if (this != i->first) { - if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id)) + if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id)) { - already_sent[i->second->fd] = uniq_id; - i->second->Write(*i->second->oper ? out2 : out1); + already_sent[i->first->fd] = uniq_id; + i->first->Write(IS_OPER(i->first) ? out2 : out1); } } } @@ -1558,12 +1582,12 @@ void userrec::WriteCommonExcept(const std::string &text) CUList *ulist = v->first->GetUsers(); for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++) { - if (this != i->second) + if (this != i->first) { - if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id)) + if ((IS_LOCAL(i->first)) && (already_sent[i->first->fd] != uniq_id)) { - already_sent[i->second->fd] = uniq_id; - i->second->Write(out1); + already_sent[i->first->fd] = uniq_id; + i->first->Write(out1); } } } @@ -1573,21 +1597,10 @@ void userrec::WriteCommonExcept(const std::string &text) void userrec::WriteWallOps(const std::string &text) { - /* Does nothing if theyre not opered */ - if ((!*this->oper) && (IS_LOCAL(this))) + if (!IS_OPER(this) && IS_LOCAL(this)) return; - std::string wallop = "WALLOPS :"; - - try - { - wallop.append(text); - } - catch (...) - { - ServerInstance->Log(DEBUG,"Exception in userrec::Write() std::string::append"); - return; - } + std::string wallop = "WALLOPS :" + text; for (std::vector::const_iterator i = ServerInstance->local_users.begin(); i != ServerInstance->local_users.end(); i++) { @@ -1751,7 +1764,7 @@ std::string userrec::ChannelList(userrec* source) * If the channel is NOT private/secret OR the user shares a common channel * If the user is an oper, and the option is set. */ - if ((source == this) || (*source->oper && ServerInstance->Config->OperSpyWhois) || (((!i->first->modes[CM_PRIVATE]) && (!i->first->modes[CM_SECRET])) || (i->first->HasUser(source)))) + if ((source == this) || (IS_OPER(source) && ServerInstance->Config->OperSpyWhois) || (((!i->first->modes[CM_PRIVATE]) && (!i->first->modes[CM_SECRET])) || (i->first->HasUser(source)))) { list.append(i->first->GetPrefixChar(this)).append(i->first->name).append(" "); }