]> jfr.im git - solanum.git/blobdiff - src/chmode.c
Force nicklen (all flavours) to be at least 9.
[solanum.git] / src / chmode.c
index 1976765f571a128773de79ce9d050c7f660607b1..7dd8c14afa61a1b8269ed0c800bba26e0f98aa14 100644 (file)
@@ -65,6 +65,7 @@ static int mode_count;
 static int mode_limit;
 static int mode_limit_simple;
 static int mask_pos;
+static int removed_mask_pos;
 
 char cflagsbuf[256];
 char cflagsmyinfo[256];
@@ -103,20 +104,10 @@ construct_cflags_strings(void)
                 
                switch (chmode_flags[i])
                {
-                   case MODE_EXLIMIT:
+                   case MODE_FREETARGET:
                    case MODE_DISFORWARD:
                        if(ConfigChannel.use_forward)
-                       {
-                           *ptr++ = (char) i;
-                       }
-                       
-                       break;
-                   case MODE_REGONLY:
-                       if(rb_dlink_list_length(&service_list))
-                       {
-                           *ptr++ = (char) i;
-                       }
-
+                               *ptr++ = (char) i;
                        break;
                    default:
                        if(chmode_flags[i] != 0)
@@ -194,6 +185,9 @@ get_channel_access(struct Client *source_p, struct membership *msptr)
        if(!MyClient(source_p))
                return CHFL_CHANOP;
 
+       if (msptr == NULL)
+               return CHFL_PEON;
+
        moduledata.client = source_p;
        moduledata.chptr = msptr->chptr;
        moduledata.msptr = msptr;
@@ -207,12 +201,12 @@ get_channel_access(struct Client *source_p, struct membership *msptr)
 
 /* add_id()
  *
- * inputs      - client, channel, id to add, type
+ * inputs      - client, channel, id to add, type, forward
  * outputs     - 0 on failure, 1 on success
  * side effects - given id is added to the appropriate list
  */
 int
-add_id(struct Client *source_p, struct Channel *chptr, const char *banid,
+add_id(struct Client *source_p, struct Channel *chptr, const char *banid, const char *forward,
        rb_dlink_list * list, long mode_type)
 {
        struct Ban *actualBan;
@@ -256,7 +250,7 @@ add_id(struct Client *source_p, struct Channel *chptr, const char *banid,
        else
                rb_strlcpy(who, source_p->name, sizeof(who));
 
-       actualBan = allocate_ban(realban, who);
+       actualBan = allocate_ban(realban, who, forward);
        actualBan->when = rb_current_time();
 
        rb_dlinkAdd(actualBan, &actualBan->node, list);
@@ -271,17 +265,17 @@ add_id(struct Client *source_p, struct Channel *chptr, const char *banid,
 /* del_id()
  *
  * inputs      - channel, id to remove, type
- * outputs     - 0 on failure, 1 on success
- * side effects - given id is removed from the appropriate list
+ * outputs     - pointer to ban that was removed, if any
+ * side effects - given id is removed from the appropriate list and returned
  */
-int
+struct Ban *
 del_id(struct Channel *chptr, const char *banid, rb_dlink_list * list, long mode_type)
 {
        rb_dlink_node *ptr;
        struct Ban *banptr;
 
        if(EmptyString(banid))
-               return 0;
+               return NULL;
 
        RB_DLINK_FOREACH(ptr, list->head)
        {
@@ -290,17 +284,16 @@ del_id(struct Channel *chptr, const char *banid, rb_dlink_list * list, long mode
                if(irccmp(banid, banptr->banstr) == 0)
                {
                        rb_dlinkDelete(&banptr->node, list);
-                       free_ban(banptr);
 
                        /* invalidate the can_send() cache */
                        if(mode_type == CHFL_BAN || mode_type == CHFL_QUIET || mode_type == CHFL_EXCEPTION)
                                chptr->bants++;
 
-                       return 1;
+                       return banptr;
                }
        }
 
-       return 0;
+       return NULL;
 }
 
 /* check_string()
@@ -344,10 +337,11 @@ pretty_mask(const char *idmask)
 {
        static char mask_buf[BUFSIZE];
        int old_mask_pos;
-       char *nick, *user, *host;
+       char *nick, *user, *host, *forward = NULL;
        char splat[] = "*";
-       char *t, *at, *ex;
-       char ne = 0, ue = 0, he = 0;    /* save values at nick[NICKLEN], et all */
+       char *t, *at, *ex, *ex2;
+       char ne = 0, ue = 0, he = 0, fe = 0;    /* save values at nick[NICKLEN], et all */
+       char e2 = 0;                            /* save value that delimits forward channel */
        char *mask;
 
        mask = LOCAL_COPY(idmask);
@@ -373,7 +367,7 @@ pretty_mask(const char *idmask)
                return mask_buf + old_mask_pos;
        }
 
-       at = ex = NULL;
+       at = ex = ex2 = NULL;
        if((t = strchr(mask, '@')) != NULL)
        {
                at = t;
@@ -395,6 +389,15 @@ pretty_mask(const char *idmask)
                        if(*mask != '\0')
                                user = mask;
                }
+
+               if((t = strchr(host, '!')) != NULL || (t = strchr(host, '$')) != NULL)
+               {
+                       ex2 = t;
+                       e2 = *t;
+                       *t++= '\0';
+                       if (*t != '\0')
+                               forward = t;
+               }
        }
        else if((t = strchr(mask, '!')) != NULL)
        {
@@ -405,7 +408,7 @@ pretty_mask(const char *idmask)
                if(*t != '\0')
                        user = t;
        }
-       else if(strchr(mask, '.') != NULL || strchr(mask, ':') != NULL || strchr(mask, '/') != NULL)
+       else if(strchr(mask, '.') != NULL || strchr(mask, ':') != NULL)
        {
                if(*mask != '\0')
                        host = mask;
@@ -432,20 +435,32 @@ pretty_mask(const char *idmask)
                he = host[HOSTLEN];
                host[HOSTLEN] = '\0';
        }
+       if(forward && strlen(forward) > CHANNELLEN)
+       {
+               fe = forward[CHANNELLEN];
+               forward[CHANNELLEN] = '\0';
+       }
 
-       mask_pos += rb_sprintf(mask_buf + mask_pos, "%s!%s@%s", nick, user, host) + 1;
+       if (forward)
+               mask_pos += rb_sprintf(mask_buf + mask_pos, "%s!%s@%s$%s", nick, user, host, forward) + 1;
+       else
+               mask_pos += rb_sprintf(mask_buf + mask_pos, "%s!%s@%s", nick, user, host) + 1;
 
        /* restore mask, since we may need to use it again later */
        if(at)
                *at = '@';
        if(ex)
                *ex = '!';
+       if(ex2)
+               *ex2 = e2;
        if(ne)
                nick[NICKLEN - 1] = ne;
        if(ue)
                user[USERLEN] = ue;
        if(he)
                host[HOSTLEN] = he;
+       if(fe)
+               forward[CHANNELLEN] = fe;
 
        return mask_buf + old_mask_pos;
 }
@@ -533,7 +548,7 @@ chm_simple(struct Client *source_p, struct Channel *chptr,
        {
                /* if +f is disabled, ignore an attempt to set +QF locally */
                if(!ConfigChannel.use_forward && MyClient(source_p) &&
-                  (c == 'Q' || c == 'F'))
+                               (c == 'Q' || c == 'F'))
                        return;
 
                chptr->mode.mode |= mode_type;
@@ -650,8 +665,7 @@ chm_ban(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)
 {
-       const char *mask;
-       const char *raw_mask;
+       char *mask, *raw_mask, *forward;
        rb_dlink_list *list;
        rb_dlink_node *ptr;
        struct Ban *banptr;
@@ -742,10 +756,16 @@ chm_ban(struct Client *source_p, struct Channel *chptr,
 
                RB_DLINK_FOREACH(ptr, list->head)
                {
+                       char buf[BANLEN];
                        banptr = ptr->data;
+                       if(banptr->forward)
+                               rb_snprintf(buf, sizeof(buf), "%s$%s", banptr->banstr, banptr->forward);
+                       else
+                               rb_strlcpy(buf, banptr->banstr, sizeof(buf));
+
                        sendto_one(source_p, form_str(rpl_list),
                                   me.name, source_p->name, chptr->chname,
-                                  banptr->banstr, banptr->who, banptr->when);
+                                  buf, banptr->who, banptr->when);
                }
                sendto_one(source_p, form_str(rpl_endlist), me.name, source_p->name, chptr->chname);
                return;
@@ -787,6 +807,17 @@ chm_ban(struct Client *source_p, struct Channel *chptr,
        if(strlen(mask) > IRCD_MIN(BANLEN, MODEBUFLEN - 5))
                return;
 
+       /* Look for a $ after the first character.
+        * As the first character, it marks an extban; afterwards
+        * it delimits a forward channel.
+        */
+       if ((forward = strchr(mask+1, '$')) != NULL)
+       {
+               *forward++ = '\0';
+               if (*forward == '\0')
+                       forward = NULL;
+       }
+
        /* if we're adding a NEW id */
        if(dir == MODE_ADD)
        {
@@ -797,12 +828,19 @@ chm_ban(struct Client *source_p, struct Channel *chptr,
                                return;
                }
 
+               if(forward != NULL && !ConfigChannel.use_forward &&
+                               MyClient(source_p))
+                       forward = NULL;
+
                /* dont allow local clients to overflow the banlist, dont
                 * let remote servers set duplicate bans
                 */
-               if(!add_id(source_p, chptr, mask, list, mode_type))
+               if(!add_id(source_p, chptr, mask, forward, list, mode_type))
                        return;
 
+               if(forward)
+                       forward[-1]= '$';
+
                mode_changes[mode_count].letter = c;
                mode_changes[mode_count].dir = MODE_ADD;
                mode_changes[mode_count].caps = caps;
@@ -813,20 +851,33 @@ chm_ban(struct Client *source_p, struct Channel *chptr,
        }
        else if(dir == MODE_DEL)
        {
-               if(del_id(chptr, mask, list, mode_type) == 0)
+               struct Ban *removed;
+               static char buf[BANLEN * MAXMODEPARAMS];
+               int old_removed_mask_pos = removed_mask_pos;
+               if((removed = del_id(chptr, mask, list, mode_type)) == NULL)
                {
                        /* mask isn't a valid ban, check raw_mask */
-                       if(del_id(chptr, raw_mask, list, mode_type))
+                       if((removed = del_id(chptr, raw_mask, list, mode_type)) != NULL)
                                mask = raw_mask;
                }
 
+               if(removed && removed->forward)
+                       removed_mask_pos += rb_snprintf(buf, sizeof(buf), "%s$%s", removed->banstr, removed->forward);
+               else
+                       removed_mask_pos += rb_strlcpy(buf, mask, sizeof(buf));
+               if(removed)
+               {
+                       free_ban(removed);
+                       removed = NULL;
+               }
+
                mode_changes[mode_count].letter = c;
                mode_changes[mode_count].dir = MODE_DEL;
                mode_changes[mode_count].caps = caps;
                mode_changes[mode_count].nocaps = 0;
                mode_changes[mode_count].mems = mems;
                mode_changes[mode_count].id = NULL;
-               mode_changes[mode_count++].arg = mask;
+               mode_changes[mode_count++].arg = buf + old_removed_mask_pos;
        }
 }
 
@@ -882,7 +933,7 @@ chm_op(struct Client *source_p, struct Channel *chptr,
 
        if(dir == MODE_ADD)
        {
-               if(targ_p == source_p)
+               if(targ_p == source_p && mstptr->flags & CHFL_CHANOP)
                        return;
 
                mode_changes[mode_count].letter = c;
@@ -1211,7 +1262,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 = ConfigChannel.use_forward ? ALL_MEMBERS : ONLY_SERVERS;
+               mode_changes[mode_count].mems =
+                       ConfigChannel.use_forward ? ALL_MEMBERS : ONLY_SERVERS;
                mode_changes[mode_count].id = NULL;
                mode_changes[mode_count++].arg = forward;
        }
@@ -1611,6 +1663,7 @@ set_channel_mode(struct Client *client_p, struct Client *source_p,
        struct Client *fakesource_p;
 
        mask_pos = 0;
+       removed_mask_pos = 0;
        mode_count = 0;
        mode_limit = 0;
        mode_limit_simple = 0;