X-Git-Url: https://jfr.im/git/irc/evilnet/x3.git/blobdiff_plain/ee25b1b292827f0cebabfc82ea688402a5708b9a..6b912b175d414f87e4f61ab5d2a16dd428c36355:/src/chanserv.c diff --git a/src/chanserv.c b/src/chanserv.c index 94fc934..00faf6d 100644 --- a/src/chanserv.c +++ b/src/chanserv.c @@ -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." }, @@ -440,7 +441,7 @@ static const struct message_entry msgtab[] = { { "CSMSG_HELPER_NO_ACCESS", "%s lacks access to %s but has $bsecurity override$b enabled." }, { "CSMSG_HELPER_HAS_ACCESS", "%s has $b%s$b access (%d) in %s and has $bsecurity override$b enabled." }, { "CSMSG_LAZY_SMURF_TARGET", "%s is %s ($bIRCOp$b; not logged in)." }, - { "CSMSG_SMURF_TARGET", "%s is %s ($b%s$b)." }, + { "CSMSG_SMURF_TARGET", "%s %s ($b%s$b)." }, { "CSMSG_OPERATOR_TITLE", "IRC operator" }, { "CSMSG_UC_H_TITLE", "network helper" }, { "CSMSG_LC_H_TITLE", "support helper" }, @@ -993,7 +994,7 @@ scan_user_presence(struct userData *uData, struct userNode *user) } static void -chanserv_ctcp_check(struct userNode *user, struct chanNode *channel, const char *text, UNUSED_ARG(struct userNode *bot), UNUSED_ARG(unsigned int is_notice)) +chanserv_ctcp_check(struct userNode *user, struct chanNode *channel, const char *text, UNUSED_ARG(struct userNode *bot), UNUSED_ARG(unsigned int is_notice), UNUSED_ARG(void *extra)) { unsigned int eflags, argc; char *argv[4]; @@ -3153,7 +3154,7 @@ static CHANSERV_FUNC(cmd_adduser) if (!real_actor || real_actor->access <= access_level) override = CMD_LOG_OVERRIDE; - if((actee = GetChannelAccess(channel->channel_info, handle))) + if(!(handle = modcmd_get_handle_info(user, argv[1]))) { /* 'kevin must first authenticate with AuthServ'. is sent to user */ struct userNode *unode; @@ -3198,7 +3199,7 @@ static CHANSERV_FUNC(cmd_adduser) if (duration > 0) timeq_add(accessexpiry, chanserv_expire_tempuser, actee); - reply("CSMSG_ADDED_USER", handle->handle, channel->name, user_level_name_from_level(access_level), access); + reply("CSMSG_ADDED_USER", handle->handle, channel->name, user_level_name_from_level(access_level), access_level); return 1 | override; } @@ -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?!? @@ -3933,7 +3947,8 @@ eject_user(struct userNode *user, struct chanNode *channel, unsigned int argc, c /* Truncate the ban in place if necessary; we must ensure that 'ban' is a valid ban mask before sanitizing it. */ - sanitize_ircmask(ban); + if (*ban != '~') + sanitize_ircmask(ban); if(action & ACTION_ADD_LAMER) { @@ -4192,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++; } @@ -4339,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); @@ -4470,7 +4485,7 @@ static CHANSERV_FUNC(cmd_myaccess) continue; sbuf.used = 0; string_buffer_append_printf(&sbuf, "[%s (%d", cData->channel->name, uData->access); - if(uData->flags == USER_AUTO_OP) + if(uData->flags != 0) string_buffer_append(&sbuf, ','); if(IsUserSuspended(uData)) string_buffer_append(&sbuf, 's'); @@ -4997,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) @@ -5301,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; } @@ -6983,10 +6998,6 @@ channel_multiple_option(enum charOption option, struct userNode *user, struct ch static MODCMD_FUNC(chan_opt_automode) { - if(check_user_level(channel, user, lvlInviteMe, 1, 0)) - { - reply("CSMSG_LOW_CHANNEL_ACCESS", channel->name); - } return channel_multiple_option(chAutomode, CSFUNC_ARGS); } @@ -7023,7 +7034,7 @@ static MODCMD_FUNC(chan_opt_resync) static struct svccmd_list set_shows_list; static void -handle_svccmd_unbind(struct svccmd *target) { +handle_svccmd_unbind(struct svccmd *target, UNUSED_ARG(void *extra)) { unsigned int ii; for(ii=0; iichannel_info, user->handle_info); real_actor = GetChannelAccess(channel->channel_info, user->handle_info); if(!(target = GetTrueChannelAccess(channel->channel_info, hi))) { @@ -7723,26 +7735,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")) { @@ -7834,7 +7846,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 */ @@ -7853,7 +7865,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"); @@ -8043,11 +8055,11 @@ static CHANSERV_FUNC(cmd_8ball) word3 = argc>3?argv[3]:""; /*** COLOR *****/ - if((word2) && strcasecmp(word1, "what") == 0 && strcasecmp(word2, "color") == 0) + if((word2) && strcasecmp(word1, "what") == 0 && ((strcasecmp(word2, "color") == 0) || (strcasecmp(word2, "colour") == 0))) eightball(eb, 1, accum); - else if((word3) && strcasecmp(word1, "what's") == 0 && strcasecmp(word2, "the") == 0 && strcasecmp(word3, "color") == 0) + else if((word3) && strcasecmp(word1, "what's") == 0 && strcasecmp(word2, "the") == 0 && ((strcasecmp(word2, "color") == 0) || (strcasecmp(word2, "colour") == 0))) eightball(eb, 1, accum); - else if((word3) && strcasecmp(word1, "whats") == 0 && strcasecmp(word2, "the") == 0 && strcasecmp(word3, "color") == 0) + else if((word3) && strcasecmp(word1, "whats") == 0 && strcasecmp(word2, "the") == 0 && ((strcasecmp(word2, "color") == 0) || (strcasecmp(word2, "colour") == 0))) eightball(eb, 1, accum); /*** LOCATION *****/ else if( @@ -8222,7 +8234,7 @@ chanserv_adjust_limit(void *data) } static void -handle_new_channel(struct chanNode *channel) +handle_new_channel(struct chanNode *channel, UNUSED_ARG(void *extra)) { struct chanData *cData; @@ -8250,7 +8262,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) @@ -8282,7 +8294,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) @@ -8324,7 +8336,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; @@ -8334,7 +8346,7 @@ channel_user_is_exempt(struct userNode *user, struct chanNode *channel) /* Welcome to my worst nightmare. Warning: Read (or modify) the code below at your own risk. */ static int -handle_join(struct modeNode *mNode) +handle_join(struct modeNode *mNode, UNUSED_ARG(void *extra)) { struct mod_chanmode change; struct userNode *user = mNode->user; @@ -8369,7 +8381,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."); @@ -8400,7 +8412,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) @@ -8565,7 +8577,7 @@ chanserv_autojoin_channels(struct userNode *user) } static void -handle_auth(struct userNode *user, UNUSED_ARG(struct handle_info *old_handle)) +handle_auth(struct userNode *user, UNUSED_ARG(struct handle_info *old_handle), UNUSED_ARG(void *extra)) { struct mod_chanmode change; struct userData *channel; @@ -8633,14 +8645,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; @@ -8680,7 +8692,7 @@ handle_auth(struct userNode *user, UNUSED_ARG(struct handle_info *old_handle)) } static void -handle_part(struct modeNode *mn, UNUSED_ARG(const char *reason)) +handle_part(struct modeNode *mn, UNUSED_ARG(const char *reason), UNUSED_ARG(void *extra)) { struct chanData *cData; struct userData *uData; @@ -8711,16 +8723,25 @@ 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); } } static void -handle_kick(struct userNode *kicker, struct userNode *victim, struct chanNode *channel) +handle_kick(struct userNode *kicker, struct userNode *victim, struct chanNode *channel, UNUSED_ARG(void *extra)) { struct userData *uData; @@ -8740,7 +8761,7 @@ handle_kick(struct userNode *kicker, struct userNode *victim, struct chanNode *c } static int -handle_topic(struct userNode *user, struct chanNode *channel, const char *old_topic) +handle_topic(struct userNode *user, struct chanNode *channel, const char *old_topic, UNUSED_ARG(void *extra)) { struct chanData *cData; @@ -8783,7 +8804,7 @@ handle_topic(struct userNode *user, struct chanNode *channel, const char *old_to } static void -handle_mode(struct chanNode *channel, struct userNode *user, const struct mod_chanmode *change) +handle_mode(struct chanNode *channel, struct userNode *user, const struct mod_chanmode *change, UNUSED_ARG(void *extra)) { struct mod_chanmode *bounce = NULL; unsigned int bnc, ii; @@ -8858,7 +8879,7 @@ handle_mode(struct chanNode *channel, struct userNode *user, const struct mod_ch } static void -handle_nick_change(struct userNode *user, UNUSED_ARG(const char *old_nick)) +handle_nick_change(struct userNode *user, UNUSED_ARG(const char *old_nick), UNUSED_ARG(void *extra)) { struct chanNode *channel; struct banData *bData; @@ -8882,7 +8903,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) @@ -8893,7 +8914,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); @@ -8905,7 +8926,7 @@ handle_nick_change(struct userNode *user, UNUSED_ARG(const char *old_nick)) } } -static void handle_rename(struct handle_info *handle, const char *old_handle) +static void handle_rename(struct handle_info *handle, const char *old_handle, UNUSED_ARG(void *extra)) { struct do_not_register *dnr = dict_find(handle_dnrs, old_handle, NULL); @@ -8918,7 +8939,7 @@ static void handle_rename(struct handle_info *handle, const char *old_handle) } static void -handle_unreg(UNUSED_ARG(struct userNode *user), struct handle_info *handle) +handle_unreg(UNUSED_ARG(struct userNode *user), struct handle_info *handle, UNUSED_ARG(void *extra)) { struct userNode *h_user; @@ -8933,7 +8954,7 @@ handle_unreg(UNUSED_ARG(struct userNode *user), struct handle_info *handle) } static int -handle_server_link(UNUSED_ARG(struct server *server)) +handle_server_link(UNUSED_ARG(struct server *server), UNUSED_ARG(void *extra)) { struct chanData *cData; @@ -9890,9 +9911,9 @@ chanserv_saxdb_write(struct saxdb_context *ctx) } static void -chanserv_db_cleanup(void) { +chanserv_db_cleanup(UNUSED_ARG(void *extra)) { unsigned int ii; - unreg_part_func(handle_part); + unreg_part_func(handle_part, NULL); while(channelList) unregister_channel(channelList, "terminating."); for(ii = 0; ii < chanserv_conf.support_channels.used; ++ii) @@ -9934,19 +9955,19 @@ init_chanserv(const char *nick) conf_register_reload(chanserv_conf_read); if (nick) { - reg_server_link_func(handle_server_link); - reg_new_channel_func(handle_new_channel); - reg_join_func(handle_join); - reg_part_func(handle_part); - reg_kick_func(handle_kick); - reg_topic_func(handle_topic); - reg_mode_change_func(handle_mode); - reg_nick_change_func(handle_nick_change); - reg_auth_func(handle_auth); + reg_server_link_func(handle_server_link, NULL); + reg_new_channel_func(handle_new_channel, NULL); + reg_join_func(handle_join, NULL); + reg_part_func(handle_part, NULL); + reg_kick_func(handle_kick, NULL); + reg_topic_func(handle_topic, NULL); + reg_mode_change_func(handle_mode, NULL); + reg_nick_change_func(handle_nick_change, NULL); + reg_auth_func(handle_auth, NULL); } - reg_handle_rename_func(handle_rename); - reg_unreg_func(handle_unreg); + reg_handle_rename_func(handle_rename, NULL); + reg_unreg_func(handle_unreg, NULL); handle_dnrs = dict_new(); dict_set_free_data(handle_dnrs, free); @@ -9955,7 +9976,7 @@ init_chanserv(const char *nick) mask_dnrs = dict_new(); dict_set_free_data(mask_dnrs, free); - reg_svccmd_unbind_func(handle_svccmd_unbind); + reg_svccmd_unbind_func(handle_svccmd_unbind, NULL); chanserv_module = module_register("ChanServ", CS_LOG, "chanserv.help", chanserv_expand_variable); DEFINE_COMMAND(register, 1, MODCMD_REQUIRE_AUTHED, "flags", "+acceptchan,+channel", NULL); DEFINE_COMMAND(noregister, 1, MODCMD_REQUIRE_AUTHED, "flags", "+helping", NULL); @@ -10126,7 +10147,7 @@ init_chanserv(const char *nick) const char *modes = conf_get_data("services/chanserv/modes", RECDB_QSTRING); chanserv = AddLocalUser(nick, nick, NULL, "Channel Services", modes); service_register(chanserv)->trigger = '!'; - reg_chanmsg_func('\001', chanserv, chanserv_ctcp_check); + reg_chanmsg_func('\001', chanserv, chanserv_ctcp_check, NULL); } saxdb_register("ChanServ", chanserv_saxdb_read, chanserv_saxdb_write); @@ -10155,7 +10176,7 @@ init_chanserv(const char *nick) } } - reg_exit_func(chanserv_db_cleanup); + reg_exit_func(chanserv_db_cleanup, NULL); message_register_table(msgtab); }