X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmode.cpp;h=e58dd67628888b63a79a17771f3fe0e4d4ea3035;hb=32a26fa539242d009ffab01e09cafdaba9270dac;hp=4aee282a29067cade6460d1d9e88c7503754f12a;hpb=ab6a7318e36bd8e0a259cd9eef3694a0f0e8684a;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/mode.cpp b/src/mode.cpp index 4aee282a2..e58dd6762 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -2,7 +2,7 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd: (C) 2002-2007 InspIRCd Development Team + * InspIRCd: (C) 2002-2008 InspIRCd Development Team * See: http://www.inspircd.org/wiki/index.php/Credits * * This program is free but copyrighted software; see @@ -14,7 +14,7 @@ /* $Core: libIRCDmode */ /* $ExtraDeps: $(RELCPPFILES) */ /* $ExtraObjects: modes/modeclasses.a */ -/* $ExtraBuild: ${MAKE} -C "modes" DIRNAME="src/modes" CC="$(CC)" $(MAKEARGS) CPPFILES="$(CPPFILES)" */ +/* $ExtraBuild: @${MAKE} -C "modes" DIRNAME="src/modes" CC="$(CC)" $(MAKEARGS) CPPFILES="$(CPPFILES)" */ #include "inspircd.h" #include "inspstring.h" @@ -54,8 +54,8 @@ /* +n (notice mask - our implementation of snomasks) */ #include "modes/umode_n.h" -ModeHandler::ModeHandler(InspIRCd* Instance, char modeletter, int parameters_on, int parameters_off, bool listmode, ModeType type, bool operonly, char mprefix) - : ServerInstance(Instance), mode(modeletter), n_params_on(parameters_on), n_params_off(parameters_off), list(listmode), m_type(type), oper(operonly), prefix(mprefix), count(0) +ModeHandler::ModeHandler(InspIRCd* Instance, char modeletter, int parameters_on, int parameters_off, bool listmode, ModeType type, bool operonly, char mprefix, char prefixrequired) + : ServerInstance(Instance), mode(modeletter), n_params_on(parameters_on), n_params_off(parameters_off), list(listmode), m_type(type), oper(operonly), prefix(mprefix), count(0), prefixneeded(prefixrequired) { } @@ -68,6 +68,16 @@ bool ModeHandler::IsListMode() return list; } +char ModeHandler::GetNeededPrefix() +{ + return prefixneeded; +} + +void ModeHandler::SetNeededPrefix(char needsprefix) +{ + prefixneeded = needsprefix; +} + unsigned int ModeHandler::GetPrefixRank() { return 0; @@ -109,12 +119,12 @@ char ModeHandler::GetModeChar() return mode; } -ModeAction ModeHandler::OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding) +ModeAction ModeHandler::OnModeChange(User*, User*, Channel*, std::string&, bool, bool) { return MODEACTION_DENY; } -ModePair ModeHandler::ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter) +ModePair ModeHandler::ModeSet(User*, User* dest, Channel* channel, const std::string&) { if (dest) { @@ -126,15 +136,15 @@ ModePair ModeHandler::ModeSet(User* source, User* dest, Channel* channel, const } } -void ModeHandler::DisplayList(User* user, Channel* channel) +void ModeHandler::DisplayList(User*, Channel*) { } -void ModeHandler::DisplayEmptyList(User* user, Channel* channel) +void ModeHandler::DisplayEmptyList(User*, Channel*) { } -bool ModeHandler::CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, Channel* channel) +bool ModeHandler::CheckTimeStamp(time_t theirs, time_t ours, const std::string&, const std::string&, Channel*) { return (ours < theirs); } @@ -157,16 +167,16 @@ ModeType ModeWatcher::GetModeType() return m_type; } -bool ModeWatcher::BeforeMode(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, ModeType type) +bool ModeWatcher::BeforeMode(User*, User*, Channel*, std::string&, bool, ModeType, bool) { return true; } -void ModeWatcher::AfterMode(User* source, User* dest, Channel* channel, const std::string ¶meter, bool adding, ModeType type) +void ModeWatcher::AfterMode(User*, User*, Channel*, const std::string&, bool, ModeType, bool) { } -User* ModeParser::SanityChecks(User *user,const char *dest,Channel *chan,int status) +User* ModeParser::SanityChecks(User *user, const char *dest, Channel *chan, int) { User *d; if ((!user) || (!dest) || (!chan) || (!*dest)) @@ -311,7 +321,7 @@ void ModeParser::Process(const char** parameters, int pcnt, User *user, bool ser mode++; continue; } - + /* Ensure the user doesnt request the same mode twice, * so they cant flood themselves off out of idiocy. */ @@ -330,6 +340,14 @@ void ModeParser::Process(const char** parameters, int pcnt, User *user, bool ser if ((mh) && (mh->IsListMode())) { + int MOD_RESULT = 0; + FOREACH_RESULT(I_OnRawMode, OnRawMode(user, targetchannel, *mode, "", true, 0)); + if (MOD_RESULT == ACR_DENY) + { + mode++; + continue; + } + if (ServerInstance->Config->HideModeLists[mletter] && (targetchannel->GetStatus(user) < STATUS_HOP)) { user->WriteServ("482 %s %s :Only half-operators and above may view the +%c list",user->nick, targetchannel->name, *mode++); @@ -369,6 +387,8 @@ void ModeParser::Process(const char** parameters, int pcnt, User *user, bool ser } else if (pcnt > 1) { + bool SkipAccessChecks = false; + if (targetchannel) { type = MODETYPE_CHANNEL; @@ -378,27 +398,14 @@ void ModeParser::Process(const char** parameters, int pcnt, User *user, bool ser * (e.g. are they a (half)op? */ - if ((IS_LOCAL(user)) && (targetchannel->GetStatus(user) < STATUS_HOP)) + if ((IS_LOCAL(user)) && (!ServerInstance->ULine(user->server)) && (!servermode)) { /* We don't have halfop */ int MOD_RESULT = 0; FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user, NULL, targetchannel, AC_GENERAL_MODE)); if (MOD_RESULT == ACR_DENY) return; - - if (MOD_RESULT == ACR_DEFAULT) - { - /* Are we a uline or is it a servermode? */ - if ((!ServerInstance->ULine(user->server)) && (!servermode)) - { - /* Not enough permission: - * NOT a uline and NOT a servermode, - * OR, NOT halfop or above. - */ - user->WriteServ("482 %s %s :You're not a channel (half)operator",user->nick, targetchannel->name); - return; - } - } + SkipAccessChecks = (MOD_RESULT == ACR_ALLOW); } } else if (targetuser) @@ -483,6 +490,8 @@ void ModeParser::Process(const char** parameters, int pcnt, User *user, bool ser if (modehandlers[handler_id]->GetModeType() == type) { + int MOD_RESULT = 0; + if (modehandlers[handler_id]->GetNumParams(adding)) { /* This mode expects a parameter, do we have any parameters left in our list to use? */ @@ -500,42 +509,73 @@ void ModeParser::Process(const char** parameters, int pcnt, User *user, bool ser continue; } - bool had_parameter = !parameter.empty(); - - for (ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++) - { - if ((*watchers)->BeforeMode(user, targetuser, targetchannel, parameter, adding, type) == false) - { - abort = true; - break; - } - /* A module whacked the parameter completely, and there was one. abort. */ - if ((had_parameter) && (parameter.empty())) - { - abort = true; - break; - } - } - - if (abort) - continue; + FOREACH_RESULT(I_OnRawMode, OnRawMode(user, targetchannel, modechar, parameter, adding, 1, servermode)); } else { - /* Fix by brain: mode watchers not being called for parameterless modes */ - for (ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++) + FOREACH_RESULT(I_OnRawMode, OnRawMode(user, targetchannel, modechar, "", adding, 0, servermode)); + } + + if (IS_LOCAL(user) && (MOD_RESULT == ACR_DENY)) + continue; + + if (!SkipAccessChecks && IS_LOCAL(user) && (MOD_RESULT != ACR_ALLOW)) + { + ServerInstance->Log(DEBUG,"Enter minimum prefix check"); + /* Check access to this mode character */ + if ((type == MODETYPE_CHANNEL) && (modehandlers[handler_id]->GetNeededPrefix())) { - if ((*watchers)->BeforeMode(user, targetuser, targetchannel, parameter, adding, type) == false) + char needed = modehandlers[handler_id]->GetNeededPrefix(); + ModeHandler* prefixmode = FindPrefix(needed); + ServerInstance->Log(DEBUG,"Needed prefix: %c", needed); + + /* If the mode defined by the handler is not '\0', but the handler for it + * cannot be found, they probably dont have the right module loaded to implement + * the prefix they want to compare the mode against, e.g. '&' for m_chanprotect. + * Revert to checking against the minimum core prefix, '%'. + */ + if (needed && !prefixmode) + prefixmode = FindPrefix('%'); + + unsigned int neededrank = prefixmode->GetPrefixRank(); + /* Compare our rank on the channel against the rank of the required prefix, + * allow if >= ours. Because mIRC and xchat throw a tizz if the modes shown + * in NAMES(X) are not in rank order, we know the most powerful mode is listed + * first, so we don't need to iterate, we just look up the first instead. + */ + std::string modestring = targetchannel->GetAllPrefixChars(user); + char ml = (modestring.empty() ? '\0' : modestring[0]); + ModeHandler* ourmode = FindPrefix(ml); + if (!ourmode || ourmode->GetPrefixRank() < neededrank) { - abort = true; - break; + /* Bog off */ + user->WriteServ("482 %s %s :You must have channel privilege %c or above to %sset channel mode %c", + user->nick, targetchannel->name, needed, adding ? "" : "un", modechar); + continue; } } + } - if (abort) - continue; + bool had_parameter = !parameter.empty(); + + for (ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++) + { + if ((*watchers)->BeforeMode(user, targetuser, targetchannel, parameter, adding, type, servermode) == false) + { + abort = true; + break; + } + /* A module whacked the parameter completely, and there was one. abort. */ + if ((had_parameter) && (parameter.empty())) + { + abort = true; + break; + } } + if (abort) + continue; + /* It's an oper only mode, check if theyre an oper. If they arent, * eat any parameter that came with the mode, and continue to next */ @@ -548,7 +588,7 @@ void ModeParser::Process(const char** parameters, int pcnt, User *user, bool ser } /* Call the handler for the mode */ - ModeAction ma = modehandlers[handler_id]->OnModeChange(user, targetuser, targetchannel, parameter, adding); + ModeAction ma = modehandlers[handler_id]->OnModeChange(user, targetuser, targetchannel, parameter, adding, servermode); if ((modehandlers[handler_id]->GetNumParams(adding)) && (parameter.empty())) { @@ -591,7 +631,7 @@ void ModeParser::Process(const char** parameters, int pcnt, User *user, bool ser /* Call all the AfterMode events in the mode watchers for this mode */ for (ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++) - (*watchers)->AfterMode(user, targetuser, targetchannel, parameter, adding, type); + (*watchers)->AfterMode(user, targetuser, targetchannel, parameter, adding, type, servermode); /* Reset the state change flag */ state_change = false; @@ -692,7 +732,7 @@ void ModeParser::CleanMask(std::string &mask) } } -bool ModeParser::AddMode(ModeHandler* mh, unsigned const char modeletter) +bool ModeParser::AddMode(ModeHandler* mh) { unsigned char mask = 0; unsigned char pos = 0; @@ -738,7 +778,7 @@ bool ModeParser::DelMode(ModeHandler* mh) switch (mh->GetModeType()) { case MODETYPE_USER: - for (user_hash::iterator i = ServerInstance->clientlist->begin(); i != ServerInstance->clientlist->end(); i++) + for (user_hash::iterator i = ServerInstance->Users->clientlist->begin(); i != ServerInstance->Users->clientlist->end(); i++) { mh->RemoveMode(i->second); } @@ -1030,31 +1070,26 @@ void ModeHandler::RemoveMode(Channel* channel) ModeParser::ModeParser(InspIRCd* Instance) : ServerInstance(Instance) { - struct Initializer + ModeHandler* modes[] = { - char modechar; - ModeHandler* handler; - }; - - Initializer modes[] = { - { 's', new ModeChannelSecret(Instance) }, - { 'p', new ModeChannelPrivate(Instance) }, - { 'm', new ModeChannelModerated(Instance) }, - { 't', new ModeChannelTopicOps(Instance) }, - { 'n', new ModeChannelNoExternal(Instance) }, - { 'i', new ModeChannelInviteOnly(Instance) }, - { 'k', new ModeChannelKey(Instance) }, - { 'l', new ModeChannelLimit(Instance) }, - { 'b', new ModeChannelBan(Instance) }, - { 'o', new ModeChannelOp(Instance) }, - { 'h', new ModeChannelHalfOp(Instance) }, - { 'v', new ModeChannelVoice(Instance) }, - { 's', new ModeUserServerNotice(Instance) }, - { 'w', new ModeUserWallops(Instance) }, - { 'i', new ModeUserInvisible(Instance) }, - { 'o', new ModeUserOperator(Instance) }, - { 'n', new ModeUserServerNoticeMask(Instance) }, - { 0, NULL } + new ModeChannelSecret(Instance), + new ModeChannelPrivate(Instance), + new ModeChannelModerated(Instance), + new ModeChannelTopicOps(Instance), + new ModeChannelNoExternal(Instance), + new ModeChannelInviteOnly(Instance), + new ModeChannelKey(Instance), + new ModeChannelLimit(Instance), + new ModeChannelBan(Instance), + new ModeChannelOp(Instance), + new ModeChannelHalfOp(Instance), + new ModeChannelVoice(Instance), + new ModeUserServerNotice(Instance), + new ModeUserWallops(Instance), + new ModeUserInvisible(Instance), + new ModeUserOperator(Instance), + new ModeUserServerNoticeMask(Instance), + NULL }; /* Clear mode list */ @@ -1065,6 +1100,6 @@ ModeParser::ModeParser(InspIRCd* Instance) : ServerInstance(Instance) LastParse.clear(); /* Initialise the RFC mode letters */ - for (int index = 0; modes[index].modechar; index++) - this->AddMode(modes[index].handler, modes[index].modechar); + for (int index = 0; modes[index]; index++) + this->AddMode(modes[index]); }