]> jfr.im git - solanum.git/blobdiff - src/chmode.c
Include forward channels when bursting bans to servers.
[solanum.git] / src / chmode.c
index 375deabb640e129a8fd66b7d90b4120a2de2f90b..8177b3ec845701a9a818d4205cea545471189dd8 100644 (file)
@@ -104,16 +104,10 @@ construct_cflags_strings(void)
                 
                switch (chmode_flags[i])
                {
-                   case MODE_EXLIMIT:
+                   case MODE_FREETARGET:
                    case MODE_DISFORWARD:
-                       /* TODO FIXME: make use_forward work again */
-                       *ptr++ = (char) i;
-                   case MODE_REGONLY:
-                       if(rb_dlink_list_length(&service_list))
-                       {
-                           *ptr++ = (char) i;
-                       }
-
+                       if(ConfigChannel.use_forward)
+                               *ptr++ = (char) i;
                        break;
                    default:
                        if(chmode_flags[i] != 0)
@@ -471,6 +465,51 @@ pretty_mask(const char *idmask)
        return mask_buf + old_mask_pos;
 }
 
+/* check_forward()
+ *
+ * input       - client, channel to set mode on, target channel name
+ * output      - true if forwarding should be allowed
+ * side effects - numeric sent if not allowed
+ */
+static int
+check_forward(struct Client *source_p, struct Channel *chptr,
+               const char *forward)
+{
+       struct Channel *targptr;
+       struct membership *msptr;
+
+       if(!check_channel_name(forward) ||
+                       (MyClient(source_p) && (strlen(forward) > LOC_CHANNELLEN || hash_find_resv(forward))))
+       {
+               sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), forward);
+               return 0;
+       }
+       /* don't forward to inconsistent target -- jilles */
+       if(chptr->chname[0] == '#' && forward[0] == '&')
+       {
+               sendto_one_numeric(source_p, ERR_BADCHANNAME,
+                                  form_str(ERR_BADCHANNAME), forward);
+               return 0;
+       }
+       if(MyClient(source_p) && (targptr = find_channel(forward)) == NULL)
+       {
+               sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
+                                  form_str(ERR_NOSUCHCHANNEL), forward);
+               return 0;
+       }
+       if(MyClient(source_p) && !(targptr->mode.mode & MODE_FREETARGET))
+       {
+               if((msptr = find_channel_membership(targptr, source_p)) == NULL ||
+                       get_channel_access(source_p, msptr) != CHFL_CHANOP)
+               {
+                       sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
+                                  me.name, source_p->name, targptr->chname);
+                       return 0;
+               }
+       }
+       return 1;
+}
+
 /* fix_key()
  *
  * input       - key to fix
@@ -552,6 +591,11 @@ chm_simple(struct Client *source_p, struct Channel *chptr,
        /* setting + */
        if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type))
        {
+               /* if +f is disabled, ignore an attempt to set +QF locally */
+               if(!ConfigChannel.use_forward && MyClient(source_p) &&
+                               (c == 'Q' || c == 'F'))
+                       return;
+
                chptr->mode.mode |= mode_type;
 
                mode_changes[mode_count].letter = c;
@@ -801,6 +845,18 @@ chm_ban(struct Client *source_p, struct Channel *chptr,
        else
                mask = pretty_mask(raw_mask);
 
+       /* we'd have problems parsing this, hyb6 does it too
+        * also make sure it will always fit on a line with channel
+        * name etc.
+        */
+       if(strlen(mask) > IRCD_MIN(BANLEN, MODEBUFLEN - 5))
+       {
+               sendto_one_numeric(source_p, ERR_INVALIDBAN,
+                               form_str(ERR_INVALIDBAN),
+                               chptr->chname, c, raw_mask);
+               return;
+       }
+
        /* Look for a $ after the first character.
         * As the first character, it marks an extban; afterwards
         * it delimits a forward channel.
@@ -812,21 +868,47 @@ chm_ban(struct Client *source_p, struct Channel *chptr,
                        forward = NULL;
        }
 
-       /* we'd have problems parsing this, hyb6 does it too
-        * also make sure it will always fit on a line with channel
-        * name etc.
-        */
-       if(strlen(mask) > IRCD_MIN(BANLEN, MODEBUFLEN - 5))
-               return;
-
        /* if we're adding a NEW id */
        if(dir == MODE_ADD)
        {
                if (*mask == '$' && MyClient(source_p))
                {
                        if (!valid_extban(mask, source_p, chptr, mode_type))
-                               /* XXX perhaps return an error message here */
+                       {
+                               sendto_one_numeric(source_p, ERR_INVALIDBAN,
+                                               form_str(ERR_INVALIDBAN),
+                                               chptr->chname, c, raw_mask);
+                               return;
+                       }
+               }
+
+               /* For compatibility, only check the forward channel from
+                * local clients. Accept any forward channel from servers.
+                */
+               if(forward != NULL && MyClient(source_p))
+               {
+                       /* For simplicity and future flexibility, do not
+                        * allow '$' in forwarding targets.
+                        */
+                       if(!ConfigChannel.use_forward ||
+                                       strchr(forward, '$') != NULL)
+                       {
+                               sendto_one_numeric(source_p, ERR_INVALIDBAN,
+                                               form_str(ERR_INVALIDBAN),
+                                               chptr->chname, c, raw_mask);
                                return;
+                       }
+                       /* check_forward() sends its own error message */
+                       if(!check_forward(source_p, chptr, forward))
+                               return;
+                       /* Forwards only make sense for bans. */
+                       if(mode_type != CHFL_BAN)
+                       {
+                               sendto_one_numeric(source_p, ERR_INVALIDBAN,
+                                               form_str(ERR_INVALIDBAN),
+                                               chptr->chname, c, raw_mask);
+                               return;
+                       }
                }
 
                /* dont allow local clients to overflow the banlist, dont
@@ -859,9 +941,9 @@ chm_ban(struct Client *source_p, struct Channel *chptr,
                }
 
                if(removed && removed->forward)
-                       removed_mask_pos += rb_snprintf(buf, sizeof(buf), "%s$%s", removed->banstr, removed->forward);
+                       removed_mask_pos += rb_snprintf(buf + old_removed_mask_pos, sizeof(buf), "%s$%s", removed->banstr, removed->forward) + 1;
                else
-                       removed_mask_pos += rb_strlcpy(buf, mask, sizeof(buf));
+                       removed_mask_pos += rb_strlcpy(buf + old_removed_mask_pos, mask, sizeof(buf)) + 1;
                if(removed)
                {
                        free_ban(removed);
@@ -1172,10 +1254,13 @@ chm_forward(struct Client *source_p, struct Channel *chptr,
        int alevel, int parc, int *parn,
        const char **parv, int *errors, int dir, char c, long mode_type)
 {
-       struct Channel *targptr = NULL;
-       struct membership *msptr;
        const char *forward;
 
+       /* if +f is disabled, ignore local attempts to set it */
+       if(!ConfigChannel.use_forward && MyClient(source_p) &&
+          (dir == MODE_ADD) && (parc > *parn))
+               return;
+
        if(dir == MODE_QUERY || (dir == MODE_ADD && parc <= *parn))
        {
                if (!(*errors & SM_ERR_RPL_F))
@@ -1218,35 +1303,9 @@ chm_forward(struct Client *source_p, struct Channel *chptr,
 
                if(EmptyString(forward))
                        return;
-               if(!check_channel_name(forward) ||
-                               (MyClient(source_p) && (strlen(forward) > LOC_CHANNELLEN || hash_find_resv(forward))))
-               {
-                       sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), forward);
-                       return;
-               }
-               /* don't forward to inconsistent target -- jilles */
-               if(chptr->chname[0] == '#' && forward[0] == '&')
-               {
-                       sendto_one_numeric(source_p, ERR_BADCHANNAME,
-                                          form_str(ERR_BADCHANNAME), forward);
-                       return;
-               }
-               if(MyClient(source_p) && (targptr = find_channel(forward)) == NULL)
-               {
-                       sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
-                                          form_str(ERR_NOSUCHCHANNEL), forward);
+
+               if(!check_forward(source_p, chptr, forward))
                        return;
-               }
-               if(MyClient(source_p) && !(targptr->mode.mode & MODE_FREETARGET))
-               {
-                       if((msptr = find_channel_membership(targptr, source_p)) == NULL ||
-                               get_channel_access(source_p, msptr) != CHFL_CHANOP)
-                       {
-                               sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
-                                          me.name, source_p->name, targptr->chname);
-                               return;
-                       }
-               }
 
                rb_strlcpy(chptr->mode.forward, forward, sizeof(chptr->mode.forward));
 
@@ -1254,7 +1313,8 @@ chm_forward(struct Client *source_p, struct Channel *chptr,
                mode_changes[mode_count].dir = MODE_ADD;
                mode_changes[mode_count].caps = 0;
                mode_changes[mode_count].nocaps = 0;
-               mode_changes[mode_count].mems = ALL_MEMBERS;
+               mode_changes[mode_count].mems =
+                       ConfigChannel.use_forward ? ALL_MEMBERS : ONLY_SERVERS;
                mode_changes[mode_count].id = NULL;
                mode_changes[mode_count++].arg = forward;
        }