]> jfr.im git - irc/evilnet/x3.git/blobdiff - src/chanserv.c
srvx sync: When MAIN_LOG is NULL, report to stderr
[irc/evilnet/x3.git] / src / chanserv.c
index cc0a92e5e2d7f36c5170b2213b1a491570e96bb5..c56a5af1fe32899f5495e5edd8e6b6884368b8d6 100644 (file)
@@ -261,6 +261,7 @@ static const struct message_entry msgtab[] = {
     { "CSMSG_NO_MATCHING_USERS", "No one in $b%s$b has a hostmask matching $b%s$b." },
     { "CSMSG_BAN_NOT_FOUND", "Sorry, no ban or LAMER found: $b%s$b." },
     { "CSMSG_BANLIST_FULL", "The $b%s$b channel ban list is $bfull$b." },
+    { "CSMSG_BAD_BAN", "The given ban $b%s$b is invalid." },
 
     { "CSMSG_INVALID_TRIM", "$b%s$b isn't a valid trim target." },
 
@@ -3780,6 +3781,7 @@ static int
 bad_channel_ban(struct chanNode *channel, struct userNode *user, const char *ban, unsigned int *victimCount, struct modeNode **victims)
 {
     unsigned int ii;
+    int b = 0;
 
     if(victimCount)
         *victimCount = 0;
@@ -3790,7 +3792,10 @@ bad_channel_ban(struct chanNode *channel, struct userNode *user, const char *ban
         if(IsService(mn->user))
             continue;
 
-        if(!user_matches_glob(mn->user, ban, MATCH_USENICK | MATCH_VISIBLE))
+        b = user_matches_glob(mn->user, ban, MATCH_USENICK | MATCH_VISIBLE, 0);
+        if (b == -1)
+            return -1;
+        else if (b == 0)
             continue;
 
         if(protect_user(mn->user, user, channel->channel_info, false))
@@ -3808,6 +3813,7 @@ eject_user(struct userNode *user, struct chanNode *channel, unsigned int argc, c
     struct userNode *victim;
     struct modeNode **victims;
     unsigned int offset, n, victimCount, duration = 0;
+    int b = 0;
     char *reason = "Bye.", *ban, *name;
     char interval[INTERVALLEN];
 
@@ -3877,10 +3883,15 @@ eject_user(struct userNode *user, struct chanNode *channel, unsigned int argc, c
         snprintf(banmask, sizeof(banmask), "*!*@%s.*", hi->handle);
         victims = alloca(sizeof(victims[0]) * channel->members.used);
 
-        if(bad_channel_ban(channel, user, banmask, &victimCount, victims))
+        b = bad_channel_ban(channel, user, banmask, &victimCount, victims);
+        if(b == 1)
         {
             reply("CSMSG_MASK_PROTECTED", banmask);
             return 0;
+        }else if(b == -1)
+        {
+            reply("CSMSG_BAD_BAN", banmask);
+            return 0;
         }
 
         if((action == ACTION_KICK) && (victimCount == 0))
@@ -3902,10 +3913,13 @@ eject_user(struct userNode *user, struct chanNode *channel, unsigned int argc, c
 
        victims = alloca(sizeof(victims[0]) * channel->members.used);
 
-        if(bad_channel_ban(channel, user, argv[1], &victimCount, victims))
-        {
-           if(cmd)
-               reply("CSMSG_MASK_PROTECTED", argv[1]);
+        b = bad_channel_ban(channel, user, argv[1], &victimCount, victims);
+        if(cmd && (b == 1)) {
+            reply("CSMSG_MASK_PROTECTED", argv[1]);
+           return 0;
+       }
+        else if(cmd && (b == -1)) {
+            reply("CSMSG_BAD_BAN", argv[1]);
            return 0;
        }
 /* If i want to ban *.nl and theres 5 of them, what is it to the bot?!? 
@@ -4193,7 +4207,7 @@ find_matching_bans(struct banList *bans, struct userNode *actee, const char *mas
         for(ii = count = 0; ii < bans->used; ++ii)
         {
             match[ii] = user_matches_glob(actee, bans->list[ii]->ban,
-                                          MATCH_USENICK | MATCH_VISIBLE);
+                                          MATCH_USENICK | MATCH_VISIBLE, 0);
             if(match[ii])
                 count++;
         }
@@ -4340,7 +4354,7 @@ unban_user(struct userNode *user, struct chanNode *channel, unsigned int argc, c
        while(ban)
        {
            if(actee)
-               for( ; ban && !user_matches_glob(actee, ban->mask, MATCH_USENICK | MATCH_VISIBLE);
+               for( ; ban && !user_matches_glob(actee, ban->mask, MATCH_USENICK | MATCH_VISIBLE, 0);
                     ban = ban->next);
            else
                for( ; ban && !match_ircglobs(mask, ban->mask);
@@ -4998,7 +5012,7 @@ static CHANSERV_FUNC(cmd_lamers)
     {
         if(search_u)
         {
-            if(!user_matches_glob(search_u, ban->mask, MATCH_USENICK | MATCH_VISIBLE))
+            if(!user_matches_glob(search_u, ban->mask, MATCH_USENICK | MATCH_VISIBLE, 0))
                 continue;
         }
        else if(search)
@@ -5302,7 +5316,7 @@ static CHANSERV_FUNC(cmd_invite)
     if (invite->handle_info && invite->handle_info->ignores->used && (argc > 1)) {
         unsigned int i;
         for (i=0; i < invite->handle_info->ignores->used; i++) {
-            if (user_matches_glob(user, invite->handle_info->ignores->list[i], MATCH_USENICK)) {
+            if (user_matches_glob(user, invite->handle_info->ignores->list[i], MATCH_USENICK, 0)) {
               reply("CSMSG_CANNOT_INVITE", argv[1], channel->name);
               return 0;
             }
@@ -7460,6 +7474,7 @@ static CHANSERV_FUNC(cmd_unsuspend)
 
     REQUIRE_PARAMS(2);
     if(!(hi = modcmd_get_handle_info(user, argv[1]))) return 0;
+    actor = GetChannelUser(channel->channel_info, user->handle_info);
     real_actor = GetChannelAccess(channel->channel_info, user->handle_info);
     if(!(target = GetTrueChannelAccess(channel->channel_info, hi)))
     {
@@ -7724,26 +7739,26 @@ static CHANSERV_FUNC(cmd_spin)
     }
     /* random time gline */
     else if (!strcasecmp(wheel, "gline")) {
-         char target[IRC_NTOP_MAX_SIZE + 3];
+         char target[HOSTLEN + 3];
          int wtime = 120 + rand() % 600;
 
          strcpy(target, "*@");
          strcat(target, user->hostname);
          send_target_message(1, channel->name, chanserv, "CSMSG_SPIN_GLINE");
 
-         gline_add(chanserv->nick, target, wtime, "Reward for spinning the wheel of misfortune!", now, now, 1, 0);
+         gline_add(chanserv->nick, target, wtime, "Reward for spinning the wheel of misfortune!", now, 1, 0);
 //         irc_kill(chanserv, user, "Reward for spinning the wheel of misfortune!");
     }
     /* random shun */
     else if (!strcasecmp(wheel, "shun")) {
-         char target[IRC_NTOP_MAX_SIZE + 3];
+         char target[HOSTLEN + 3];
          int wtime = 120 + rand() % 600;
 
          strcpy(target, "*@");
          strcat(target, user->hostname);
          send_target_message(1, channel->name, chanserv, "CSMSG_SPIN_SHUN");
 
-         shun_add(chanserv->nick, target, wtime, "Reward for spinning the wheel of misfortune!", now, now, 1);
+         shun_add(chanserv->nick, target, wtime, "Reward for spinning the wheel of misfortune!", now, 1);
     }
     /* absolutely nothing */
     else if (!strcasecmp(wheel, "nothing")) {
@@ -7835,7 +7850,7 @@ static CHANSERV_FUNC(cmd_spin)
     /* service ignore */
     else if (!strcasecmp(wheel, "svsignore")) {
          int gagged, ignoretime = 0;
-         char target[IRC_NTOP_MAX_SIZE + 13];
+         char target[HOSTLEN + 13];
 
          if(IsOper(user)) {
             /* we cant gag opers, so just verbally abuse them */
@@ -7854,7 +7869,7 @@ static CHANSERV_FUNC(cmd_spin)
     else if (!strcasecmp(wheel, "kickbanall")) {
          unsigned int count, n;
          struct modeNode *mn;
-         //char ban[IRC_NTOP_MAX_SIZE + 1];
+         //char ban[HOSTLEN + 1];
 
          send_target_message(1, channel->name, chanserv, "CSMSG_SPIN_KICKBANALL");
 
@@ -8251,7 +8266,7 @@ trace_check_bans(struct userNode *user, struct chanNode *chan)
     if (chan->channel_info) {
         for(bData = chan->channel_info->bans; bData; bData = bData->next) {
 
-            if(!user_matches_glob(user, bData->mask, MATCH_USENICK))
+            if(!user_matches_glob(user, bData->mask, MATCH_USENICK, 0))
                 continue;
 
             if(bData)
@@ -8283,7 +8298,7 @@ check_bans(struct userNode *user, const char *channel)
     {
         /* Not joining through a ban. */
         for(bData = cData->bans;
-            bData && !user_matches_glob(user, bData->mask, MATCH_USENICK);
+            bData && !user_matches_glob(user, bData->mask, MATCH_USENICK, 0);
             bData = bData->next);
 
         if(bData)
@@ -8325,7 +8340,7 @@ channel_user_is_exempt(struct userNode *user, struct chanNode *channel)
    unsigned int ii;
    for(ii = 0; ii < channel->exemptlist.used; ii++)
    {
-       if(user_matches_glob(user, channel->exemptlist.list[ii]->exempt, MATCH_USENICK))
+       if(user_matches_glob(user, channel->exemptlist.list[ii]->exempt, MATCH_USENICK, 0))
            return true;
    }
    return false;
@@ -8370,7 +8385,7 @@ handle_join(struct modeNode *mNode)
         unsigned int ii;
         for(ii = 0; ii < channel->banlist.used; ii++)
         {
-            if(user_matches_glob(user, channel->banlist.list[ii]->ban, MATCH_USENICK))
+            if(user_matches_glob(user, channel->banlist.list[ii]->ban, MATCH_USENICK, 0))
             {
                 /* Riding a netburst.  Naughty. */
                 KickChannelUser(user, channel, chanserv, "User from far side of netsplit should have been banned - bye.");
@@ -8401,7 +8416,7 @@ handle_join(struct modeNode *mNode)
         {
             /* Not joining through a ban. */
             for(bData = cData->bans;
-                bData && !user_matches_glob(user, bData->mask, MATCH_USENICK);
+                bData && !user_matches_glob(user, bData->mask, MATCH_USENICK, 0);
                 bData = bData->next);
 
             if(bData)
@@ -8634,14 +8649,14 @@ handle_auth(struct userNode *user, UNUSED_ARG(struct handle_info *old_handle))
         if(protect_user(user, chanserv, chan->channel_info, true))
             continue;
         for(jj = 0; jj < chan->banlist.used; ++jj)
-            if(user_matches_glob(user, chan->banlist.list[jj]->ban, MATCH_USENICK))
+            if(user_matches_glob(user, chan->banlist.list[jj]->ban, MATCH_USENICK, 0))
                 break;
         if(jj < chan->banlist.used)
             continue;
         for(ban = chan->channel_info->bans; ban; ban = ban->next)
         {
             char kick_reason[MAXLEN];
-            if(!user_matches_glob(user, ban->mask,MATCH_USENICK | MATCH_VISIBLE))
+            if(!user_matches_glob(user, ban->mask,MATCH_USENICK | MATCH_VISIBLE, 0))
                 continue;
             change.args[0].mode = MODE_BAN;
             change.args[0].u.hostmask = ban->mask;
@@ -8712,10 +8727,19 @@ handle_part(struct modeNode *mn, UNUSED_ARG(const char *reason))
     if(IsHelping(mn->user) && IsSupportHelper(mn->user))
     {
         unsigned int ii;
-        for(ii = 0; ii < chanserv_conf.support_channels.used; ++ii)
-             if(find_handle_in_channel(chanserv_conf.support_channels.list[ii], mn->user->handle_info, mn->user))
+        for(ii = 0; ii < chanserv_conf.support_channels.used; ++ii) {
+            struct chanNode *channel;
+            struct userNode *exclude;
+            /* When looking at the channel that is being /part'ed, we
+             * have to skip over the client that is leaving.  For
+             * other channels, we must not do that.
+             */
+            channel = chanserv_conf.support_channels.list[ii];
+            exclude = (channel == mn->channel) ? mn->user : NULL;
+            if(find_handle_in_channel(channel, mn->user->handle_info, exclude))
                 break;
-         if(ii == chanserv_conf.support_channels.used)
+        }
+        if(ii == chanserv_conf.support_channels.used)
             HANDLE_CLEAR_FLAG(mn->user->handle_info, HELPING);
     }
 }
@@ -8883,7 +8907,7 @@ handle_nick_change(struct userNode *user, UNUSED_ARG(const char *old_nick))
             continue;
         /* Look for a matching ban already on the channel. */
         for(jj = 0; jj < channel->banlist.used; ++jj)
-            if(user_matches_glob(user, channel->banlist.list[jj]->ban, MATCH_USENICK))
+            if(user_matches_glob(user, channel->banlist.list[jj]->ban, MATCH_USENICK, 0))
                 break;
         /* Need not act if we found one. */
         if(jj < channel->banlist.used)
@@ -8894,7 +8918,7 @@ handle_nick_change(struct userNode *user, UNUSED_ARG(const char *old_nick))
         /* Look for a matching ban in this channel. */
         for(bData = channel->channel_info->bans; bData; bData = bData->next)
         {
-            if(!user_matches_glob(user, bData->mask, MATCH_USENICK | MATCH_VISIBLE))
+            if(!user_matches_glob(user, bData->mask, MATCH_USENICK | MATCH_VISIBLE, 0))
                 continue;
             change.args[0].u.hostmask = bData->mask;
             mod_chanmode_announce(chanserv, channel, &change);