]> jfr.im git - solanum.git/blobdiff - ircd/channel.c
Resolve shfit/reduce conflict in timespec production (#54)
[solanum.git] / ircd / channel.c
index 585f3be9b905e0e9b80523734698cf87f1328ee7..c09a717d12c1bf797a3a919b78cac85d90c4e0d4 100644 (file)
@@ -221,6 +221,7 @@ void
 add_user_to_channel(struct Channel *chptr, struct Client *client_p, int flags)
 {
        struct membership *msptr;
+       rb_dlink_node *p;
 
        s_assert(client_p->user != NULL);
        if(client_p->user == NULL)
@@ -232,7 +233,17 @@ add_user_to_channel(struct Channel *chptr, struct Client *client_p, int flags)
        msptr->client_p = client_p;
        msptr->flags = flags;
 
-       rb_dlinkAdd(msptr, &msptr->usernode, &client_p->user->channel);
+       RB_DLINK_FOREACH(p, client_p->user->channel.head)
+       {
+               struct membership *ms2 = p->data;
+               if (irccmp(chptr->chname, ms2->chptr->chname) < 0)
+                       break;
+       }
+       if (p == NULL)
+               rb_dlinkAddTail(msptr, &msptr->usernode, &client_p->user->channel);
+       else
+               rb_dlinkAddBefore(p, msptr, &msptr->usernode, &client_p->user->channel);
+
        rb_dlinkAdd(msptr, &msptr->channode, &chptr->members);
 
        if(MyClient(client_p))
@@ -423,6 +434,47 @@ channel_pub_or_secret(struct Channel *chptr)
        return ("*");
 }
 
+int
+iter_comm_channels_step(rb_dlink_node *pos1, rb_dlink_node *pos2,
+               struct membership **ms1, struct membership **ms2,
+               struct Channel **chptr)
+{
+       *ms1 = pos1 ? pos1->data : NULL;
+       *ms2 = pos2 ? pos2->data : NULL;
+
+       /* we're at the end */
+       if (*ms1 == NULL && *ms2 == NULL)
+               return 0;
+
+       /* one side is at the end, keep stepping the other one */
+       if (*ms1 == NULL || *ms2 == NULL)
+       {
+               *chptr = *ms1 != NULL ? (*ms1)->chptr : (*ms2)->chptr;
+               return 1;
+       }
+
+       /* common channel */
+       if ((*ms1)->chptr == (*ms2)->chptr)
+       {
+               *chptr = (*ms1)->chptr;
+               return 1;
+       }
+
+       /* null out the channel that's further ahead; we'll get to it later */
+       if (irccmp((*ms1)->chptr->chname, (*ms2)->chptr->chname) > 0)
+       {
+               *ms1 = NULL;
+               *chptr = (*ms2)->chptr;
+               return 1;
+       }
+       else
+       {
+               *ms2 = NULL;
+               *chptr = (*ms1)->chptr;
+               return 1;
+       }
+}
+
 /* channel_member_names()
  *
  * input       - channel to list, client to list to, show endofnames
@@ -537,84 +589,41 @@ del_invite(struct Channel *chptr, struct Client *who)
 static int
 is_banned_list(struct Channel *chptr, rb_dlink_list *list,
               struct Client *who, struct membership *msptr,
-              const char *s, const char *s2, const char **forward)
+              const struct matchset *ms, const char **forward)
 {
-       char src_host[NICKLEN + USERLEN + HOSTLEN + 6];
-       char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6];
-       char src_althost[NICKLEN + USERLEN + HOSTLEN + 6];
-       char src_ip4host[NICKLEN + USERLEN + HOSTLEN + 6];
-       char *s3 = NULL;
-       char *s4 = NULL;
-       struct sockaddr_in ip4;
+       struct matchset ms_;
        rb_dlink_node *ptr;
        struct Ban *actualBan = NULL;
        struct Ban *actualExcept = NULL;
 
-       if(!MyClient(who))
+       if (!MyClient(who))
                return 0;
 
-       /* if the buffers havent been built, do it here */
-       if(s == NULL)
-       {
-               sprintf(src_host, "%s!%s@%s", who->name, who->username, who->host);
-               sprintf(src_iphost, "%s!%s@%s", who->name, who->username, who->sockhost);
-
-               s = src_host;
-               s2 = src_iphost;
-       }
-       if(who->localClient->mangledhost != NULL)
-       {
-               /* if host mangling mode enabled, also check their real host */
-               if(!strcmp(who->host, who->localClient->mangledhost))
-               {
-                       sprintf(src_althost, "%s!%s@%s", who->name, who->username, who->orighost);
-                       s3 = src_althost;
-               }
-               /* if host mangling mode not enabled and no other spoof,
-                * also check the mangled form of their host */
-               else if (!IsDynSpoof(who))
-               {
-                       sprintf(src_althost, "%s!%s@%s", who->name, who->username, who->localClient->mangledhost);
-                       s3 = src_althost;
-               }
-       }
-       if(GET_SS_FAMILY(&who->localClient->ip) == AF_INET6 &&
-                       rb_ipv4_from_ipv6((const struct sockaddr_in6 *)&who->localClient->ip, &ip4))
+       if (ms == NULL)
        {
-               sprintf(src_ip4host, "%s!%s@", who->name, who->username);
-               s4 = src_ip4host + strlen(src_ip4host);
-               rb_inet_ntop_sock((struct sockaddr *)&ip4,
-                               s4, src_ip4host + sizeof src_ip4host - s4);
-               s4 = src_ip4host;
+               matchset_for_client(who, &ms_);
+               ms = &ms_;
        }
 
        RB_DLINK_FOREACH(ptr, list->head)
        {
                actualBan = ptr->data;
-               if(match(actualBan->banstr, s) ||
-                  match(actualBan->banstr, s2) ||
-                  match_cidr(actualBan->banstr, s2) ||
-                  match_extban(actualBan->banstr, who, chptr, CHFL_BAN) ||
-                  (s3 != NULL && match(actualBan->banstr, s3)) ||
-                  (s4 != NULL && (match(actualBan->banstr, s4) || match_cidr(actualBan->banstr, s4)))
-                  )
+               if (matches_mask(ms, actualBan->banstr))
                        break;
-               else
-                       actualBan = NULL;
+               if (match_extban(actualBan->banstr, who, chptr, CHFL_BAN))
+                       break;
+               actualBan = NULL;
        }
 
-       if((actualBan != NULL) && ConfigChannel.use_except)
+       if ((actualBan != NULL) && ConfigChannel.use_except)
        {
                RB_DLINK_FOREACH(ptr, chptr->exceptlist.head)
                {
                        actualExcept = ptr->data;
 
                        /* theyre exempted.. */
-                       if(match(actualExcept->banstr, s) ||
-                          match(actualExcept->banstr, s2) ||
-                          match_cidr(actualExcept->banstr, s2) ||
-                          match_extban(actualExcept->banstr, who, chptr, CHFL_EXCEPTION) ||
-                          (s3 != NULL && match(actualExcept->banstr, s3)))
+                       if (matches_mask(ms, actualExcept->banstr) ||
+                                       match_extban(actualExcept->banstr, who, chptr, CHFL_EXCEPTION))
                        {
                                /* cache the fact theyre not banned */
                                if(msptr != NULL)
@@ -660,7 +669,7 @@ is_banned_list(struct Channel *chptr, rb_dlink_list *list,
  */
 int
 is_banned(struct Channel *chptr, struct Client *who, struct membership *msptr,
-         const char *s, const char *s2, const char **forward)
+         const struct matchset *ms, const char **forward)
 {
 #if 0
        if (chptr->last_checked_client != NULL &&
@@ -676,7 +685,7 @@ is_banned(struct Channel *chptr, struct Client *who, struct membership *msptr,
 
        return chptr->last_checked_result;
 #else
-       return is_banned_list(chptr, &chptr->banlist, who, msptr, s, s2, forward);
+       return is_banned_list(chptr, &chptr->banlist, who, msptr, ms, forward);
 #endif
 }
 
@@ -689,7 +698,7 @@ is_banned(struct Channel *chptr, struct Client *who, struct membership *msptr,
  */
 int
 is_quieted(struct Channel *chptr, struct Client *who, struct membership *msptr,
-          const char *s, const char *s2)
+          const struct matchset *ms)
 {
 #if 0
        if (chptr->last_checked_client != NULL &&
@@ -705,7 +714,7 @@ is_quieted(struct Channel *chptr, struct Client *who, struct membership *msptr,
 
        return chptr->last_checked_result;
 #else
-       return is_banned_list(chptr, &chptr->quietlist, who, msptr, s, s2, NULL);
+       return is_banned_list(chptr, &chptr->quietlist, who, msptr, ms, NULL);
 #endif
 }
 
@@ -722,10 +731,7 @@ can_join(struct Client *source_p, struct Channel *chptr, const char *key, const
        rb_dlink_node *invite = NULL;
        rb_dlink_node *ptr;
        struct Ban *invex = NULL;
-       char src_host[NICKLEN + USERLEN + HOSTLEN + 6];
-       char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6];
-       char src_althost[NICKLEN + USERLEN + HOSTLEN + 6];
-       int use_althost = 0;
+       struct matchset ms;
        int i = 0;
        hook_data_channel moduledata;
 
@@ -735,26 +741,9 @@ can_join(struct Client *source_p, struct Channel *chptr, const char *key, const
        moduledata.chptr = chptr;
        moduledata.approved = 0;
 
-       sprintf(src_host, "%s!%s@%s", source_p->name, source_p->username, source_p->host);
-       sprintf(src_iphost, "%s!%s@%s", source_p->name, source_p->username, source_p->sockhost);
-       if(source_p->localClient->mangledhost != NULL)
-       {
-               /* if host mangling mode enabled, also check their real host */
-               if(!strcmp(source_p->host, source_p->localClient->mangledhost))
-               {
-                       sprintf(src_althost, "%s!%s@%s", source_p->name, source_p->username, source_p->orighost);
-                       use_althost = 1;
-               }
-               /* if host mangling mode not enabled and no other spoof,
-                * also check the mangled form of their host */
-               else if (!IsDynSpoof(source_p))
-               {
-                       sprintf(src_althost, "%s!%s@%s", source_p->name, source_p->username, source_p->localClient->mangledhost);
-                       use_althost = 1;
-               }
-       }
+       matchset_for_client(source_p, &ms);
 
-       if((is_banned(chptr, source_p, NULL, src_host, src_iphost, forward)) == CHFL_BAN)
+       if((is_banned(chptr, source_p, NULL, &ms, forward)) == CHFL_BAN)
        {
                moduledata.approved = ERR_BANNEDFROMCHAN;
                goto finish_join_check;
@@ -784,11 +773,8 @@ can_join(struct Client *source_p, struct Channel *chptr, const char *key, const
                        RB_DLINK_FOREACH(ptr, chptr->invexlist.head)
                        {
                                invex = ptr->data;
-                               if(match(invex->banstr, src_host)
-                                  || match(invex->banstr, src_iphost)
-                                  || match_cidr(invex->banstr, src_iphost)
-                                  || match_extban(invex->banstr, source_p, chptr, CHFL_INVEX)
-                                  || (use_althost && match(invex->banstr, src_althost)))
+                               if (matches_mask(&ms, invex->banstr) ||
+                                               match_extban(invex->banstr, source_p, chptr, CHFL_INVEX))
                                        break;
                        }
                        if(ptr == NULL)
@@ -879,8 +865,8 @@ can_send(struct Channel *chptr, struct Client *source_p, struct membership *mspt
                        if(can_send_banned(msptr))
                                moduledata.approved = CAN_SEND_NO;
                }
-               else if(is_banned(chptr, source_p, msptr, NULL, NULL, NULL) == CHFL_BAN
-                       || is_quieted(chptr, source_p, msptr, NULL, NULL) == CHFL_BAN)
+               else if(is_banned(chptr, source_p, msptr, NULL, NULL) == CHFL_BAN
+                       || is_quieted(chptr, source_p, msptr, NULL) == CHFL_BAN)
                        moduledata.approved = CAN_SEND_NO;
        }
 
@@ -964,14 +950,12 @@ find_bannickchange_channel(struct Client *client_p)
        struct Channel *chptr;
        struct membership *msptr;
        rb_dlink_node *ptr;
-       char src_host[NICKLEN + USERLEN + HOSTLEN + 6];
-       char src_iphost[NICKLEN + USERLEN + HOSTLEN + 6];
+       struct matchset ms;
 
        if (!MyClient(client_p))
                return NULL;
 
-       sprintf(src_host, "%s!%s@%s", client_p->name, client_p->username, client_p->host);
-       sprintf(src_iphost, "%s!%s@%s", client_p->name, client_p->username, client_p->sockhost);
+       matchset_for_client(client_p, &ms);
 
        RB_DLINK_FOREACH(ptr, client_p->user->channel.head)
        {
@@ -985,8 +969,8 @@ find_bannickchange_channel(struct Client *client_p)
                        if (can_send_banned(msptr))
                                return chptr;
                }
-               else if (is_banned(chptr, client_p, msptr, src_host, src_iphost, NULL) == CHFL_BAN
-                       || is_quieted(chptr, client_p, msptr, src_host, src_iphost) == CHFL_BAN)
+               else if (is_banned(chptr, client_p, msptr, &ms, NULL) == CHFL_BAN
+                       || is_quieted(chptr, client_p, msptr, &ms) == CHFL_BAN)
                        return chptr;
        }
        return NULL;
@@ -1190,7 +1174,7 @@ channel_modes(struct Channel *chptr, struct Client *client_p)
 
        for (i = 0; i < 256; i++)
        {
-               if(chmode_table[i].set_func == chm_hidden && (!IsOper(client_p) || !IsClient(client_p)))
+               if(chmode_table[i].set_func == chm_hidden && (!HasPrivilege(client_p, "auspex:cmodes") || !IsClient(client_p)))
                        continue;
                if(chptr->mode.mode & chmode_flags[i])
                        *mbuf++ = i;