]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_banredirect.cpp
Fix segfault in m_chanprotect when OnAccessCheck is called with a null channel
[user/henk/code/inspircd.git] / src / modules / m_banredirect.cpp
index f3f68bc7ba79d72b59655d2dad66efe457ed1cf0..1a486325a9941966f9bea694da53d2b983391d7f 100644 (file)
@@ -38,12 +38,11 @@ typedef std::deque<std::string> StringDeque;
 class BanRedirect : public ModeWatcher
 {
  public:
-       BanRedirect(InspIRCd* Instance)
-       : ModeWatcher(Instance, 'b', MODETYPE_CHANNEL)
+       BanRedirect(InspIRCd* Instance) : ModeWatcher(Instance, 'b', MODETYPE_CHANNEL)
        {
        }
 
-       bool BeforeMode(User* source, User* dest, Channel* channel, std::string &param, bool adding, ModeType type, bool)
+       bool BeforeMode(User* source, User* dest, Channel* channel, std::string &param, bool adding, ModeType type)
        {
                /* nick!ident@host -> nick!ident@host
                 * nick!ident@host#chan -> nick!ident@host#chan
@@ -195,22 +194,18 @@ class BanRedirect : public ModeWatcher
 
 class ModuleBanRedirect : public Module
 {
-       BanRedirect* re;
+       BanRedirect re;
        bool nofollow;
        Module* ExceptionModule;
 
  public:
        ModuleBanRedirect(InspIRCd* Me)
-       : Module(Me)
+       : Module(Me), re(Me)
        {
-               re = new BanRedirect(Me);
                nofollow = false;
 
-               if(!ServerInstance->Modes->AddModeWatcher(re))
-               {
-                       delete re;
+               if(!ServerInstance->Modes->AddModeWatcher(&re))
                        throw ModuleException("Could not add mode watcher");
-               }
 
                OnRehash(NULL);
 
@@ -267,13 +262,13 @@ class ModuleBanRedirect : public Module
                ExceptionModule = ServerInstance->Modules->Find("m_banexception.so");
        }
 
-       virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
+       virtual ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
        {
                /* This prevents recursion when a user sets multiple ban redirects in a chain
                 * (thanks Potter)
                 */
                if (nofollow)
-                       return 0;
+                       return MOD_RES_PASSTHRU;
 
                /* Return 1 to prevent the join, 0 to allow it */
                if (chan)
@@ -293,7 +288,7 @@ class ModuleBanRedirect : public Module
                                        ListModeRequest n(this, ExceptionModule, user, chan);
                                        /* Users with ban exceptions are allowed to join without being redirected */
                                        if (n.Send())
-                                               return 0;
+                                               return MOD_RES_PASSTHRU;
                                }
 
                                std::string ipmask(user->nick);
@@ -313,7 +308,7 @@ class ModuleBanRedirect : public Module
                                                if(destchan && ServerInstance->Modules->Find("m_redirect.so") && destchan->IsModeSet('L') && !destlimit.empty() && (destchan->GetUserCounter() >= atoi(destlimit.c_str())))
                                                {
                                                        user->WriteNumeric(474, "%s %s :Cannot join channel (You are banned)", user->nick.c_str(), chan->name.c_str());
-                                                       return 1;
+                                                       return MOD_RES_ALLOW;
                                                }
                                                else
                                                {
@@ -322,19 +317,18 @@ class ModuleBanRedirect : public Module
                                                        nofollow = true;
                                                        Channel::JoinUser(ServerInstance, user, redir->targetchan.c_str(), false, "", false, ServerInstance->Time());
                                                        nofollow = false;
-                                                       return 1;
+                                                       return MOD_RES_ALLOW;
                                                }
                                        }
                                }
                        }
                }
-               return 0;
+               return MOD_RES_PASSTHRU;
        }
 
        virtual ~ModuleBanRedirect()
        {
-               ServerInstance->Modes->DelModeWatcher(re);
-               delete re;
+               ServerInstance->Modes->DelModeWatcher(&re);
        }
 
        virtual Version GetVersion()