X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmode.cpp;h=6b22587b186698d204d6700df2e4905d84bfe789;hb=7bd02d8a5dbac685d53a3f2aac9052c6ab5efa6e;hp=7b99eedb959d53572469a58d169af3929b8e583b;hpb=8e7fceba881712e481545d8908b1d6492bb5e5e5;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/mode.cpp b/src/mode.cpp index 7b99eedb9..6b22587b1 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -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; @@ -306,17 +316,12 @@ void ModeParser::Process(const char** parameters, int pcnt, User *user, bool ser { unsigned char mletter = *mode; - int MOD_RESULT = 0; - FOREACH_RESULT(I_OnRawMode, OnRawMode(user, targetchannel, *mode, "", true, 0)); - if (MOD_RESULT == ACR_DENY) - continue; - if (*mode == '+') { mode++; continue; } - + /* Ensure the user doesnt request the same mode twice, * so they cant flood themselves off out of idiocy. */ @@ -335,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++); @@ -374,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; @@ -383,28 +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 %soperator",user->nick, targetchannel->name, - ServerInstance->Config->AllowHalfop ? "(half)" : ""); - return; - } - } + SkipAccessChecks = (MOD_RESULT == ACR_ALLOW); } } else if (targetuser) @@ -489,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? */ @@ -506,52 +509,73 @@ void ModeParser::Process(const char** parameters, int pcnt, User *user, bool ser continue; } - int MOD_RESULT = 0; FOREACH_RESULT(I_OnRawMode, OnRawMode(user, targetchannel, modechar, parameter, adding, 1)); - if (MOD_RESULT == ACR_DENY) - return; - - 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; } else { - int MOD_RESULT = 0; FOREACH_RESULT(I_OnRawMode, OnRawMode(user, targetchannel, modechar, "", adding, 0)); - if (MOD_RESULT == ACR_DENY) - return; + } - /* Fix by brain: mode watchers not being called for parameterless modes */ - for (ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++) + 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) == 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 */