/** ban_check_mask - Checks if the current user in ban checking (ban_ip, etc) matches the specified n!u@h mask -or- run an extended ban. * @param sptr Client to check (can be remote client) * @param chptr Channel to check * @param banstr Mask string to check user * @param type Type of ban to check for (BANCHK_*) * @param no_extbans 0 to check extbans, nonzero to disable extban checking. * @returns Nonzero if the mask/extban succeeds. Zero if it doesn't. * @comments This is basically extracting the mask and extban check from is_banned_with_nick, but with being a bit more strict in what an extban is. * Strange things could happen if this is called outside standard ban checking. */ inline int ban_check_mask(aClient *sptr, aChannel *chptr, char *banstr, int type, int no_extbans) { Extban *extban = NULL; if (!no_extbans && banstr[0] == '~' && banstr[1] != '\0' && banstr[2] == ':') { /* Is an extended ban. */ extban = findmod_by_bantype(banstr[1]); if (!extban) { return 0; } else { return extban->is_banned(sptr, chptr, banstr, type); } } else { /* Is a n!u@h mask. */ return extban_is_banned_helper(banstr); } }
/** is_banned_with_nick - Check if a user is banned on a channel. * @param sptr Client to check (can be remote client) * @param chptr Channel to check * @param type Type of ban to check for (BANCHK_*) * @param nick Nick of the user * @returns A pointer to the ban struct if banned, otherwise NULL. */ Ban *is_banned_with_nick(aClient *sptr, aChannel *chptr, int type, char *nick) { Ban *tmp, *tmp2; char *s; static char realhost[NICKLEN + USERLEN + HOSTLEN + 24]; static char cloakhost[NICKLEN + USERLEN + HOSTLEN + 24]; static char virthost[NICKLEN + USERLEN + HOSTLEN + 24]; static char nuip[NICKLEN + USERLEN + HOSTLEN + 24]; int dovirt = 0, mine = 0; Extban *extban; if (!IsPerson(sptr) || !chptr->banlist) return NULL; ban_realhost = realhost; ban_ip = ban_virthost = ban_cloakhost = NULL; if (MyConnect(sptr)) { mine = 1; make_nick_user_host_r(nuip, nick, sptr->user->username, GetIP(sptr)); ban_ip = nuip; make_nick_user_host_r(cloakhost, nick, sptr->user->username, sptr->user->cloakedhost); ban_cloakhost = cloakhost; } if (IsSetHost(sptr) && strcmp(sptr->user->realhost, sptr->user->virthost)) { dovirt = 1; make_nick_user_host_r(virthost, nick, sptr->user->username, sptr->user->virthost); ban_virthost = virthost; } make_nick_user_host_r(realhost, nick, sptr->user->username, sptr->user->realhost); /* We now check +b first, if a +b is found we then see if there is a +e. * If a +e was found we return NULL, if not, we return the ban. */ for (tmp = chptr->banlist; tmp; tmp = tmp->next) { if (*tmp->banstr == '~') { extban = findmod_by_bantype(tmp->banstr[1]); if (!extban) continue; if (!extban->is_banned(sptr, chptr, tmp->banstr, type)) continue; } else { if ((match(tmp->banstr, realhost) == 0) || (dovirt && (match(tmp->banstr, virthost) == 0)) || (mine && (match(tmp->banstr, nuip) == 0)) || (mine && (match(tmp->banstr, cloakhost) == 0)) ) { /* matches.. do nothing */ } else continue; } /* Ban found, now check for +e */ for (tmp2 = chptr->exlist; tmp2; tmp2 = tmp2->next) { if (*tmp2->banstr == '~') { extban = findmod_by_bantype(tmp2->banstr[1]); if (!extban) continue; if (extban->is_banned(sptr, chptr, tmp2->banstr, type)) return NULL; } else { if ((match(tmp2->banstr, realhost) == 0) || (dovirt && (match(tmp2->banstr, virthost) == 0)) || (mine && (match(tmp2->banstr, nuip) == 0)) || (mine && (match(tmp2->banstr, cloakhost) == 0)) ) return NULL; } } break; /* ban found and not on except */ } return (tmp); }