From 6865c0b099141f03a4d38be83278815ec701bbf3 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Sun, 22 Feb 2009 00:12:21 +0100 Subject: [PATCH] Add channel::only_ascii_channels config option to restrict channel names to printable ascii only. Like disable_fake_channels this only applies to joins by local users; unlike disable_fake_channels it applies to opers as well. --- doc/example.conf | 1 + doc/reference.conf | 6 ++++++ include/s_conf.h | 1 + modules/core/m_join.c | 17 +++++++++++++---- modules/m_info.c | 6 ++++++ src/newconf.c | 1 + src/s_conf.c | 1 + 7 files changed, 29 insertions(+), 4 deletions(-) diff --git a/doc/example.conf b/doc/example.conf index ed19682e..042364f3 100755 --- a/doc/example.conf +++ b/doc/example.conf @@ -317,6 +317,7 @@ channel { no_join_on_split = no; burst_topicwho = yes; kick_on_split_riding = no; + only_ascii_channels = no; }; serverhide { diff --git a/doc/reference.conf b/doc/reference.conf index 716d4f59..f23050aa 100755 --- a/doc/reference.conf +++ b/doc/reference.conf @@ -733,6 +733,12 @@ channel { * ratbox-services does. */ kick_on_split_riding = no; + + /* only ascii channels: disable local users joining channels + * containing characters outside the range 33-126 (non-printable + * or non-ASCII). + */ + only_ascii_channels = no; }; diff --git a/include/s_conf.h b/include/s_conf.h index f9b0ef72..31766467 100644 --- a/include/s_conf.h +++ b/include/s_conf.h @@ -239,6 +239,7 @@ struct config_channel_entry int default_split_user_count; int burst_topicwho; int kick_on_split_riding; + int only_ascii_channels; }; struct config_server_hide diff --git a/modules/core/m_join.c b/modules/core/m_join.c index e9f092d2..f8598d7d 100644 --- a/modules/core/m_join.c +++ b/modules/core/m_join.c @@ -990,27 +990,36 @@ do_join_0(struct Client *client_p, struct Client *source_p) static int check_channel_name_loc(struct Client *source_p, const char *name) { + const char *p; + s_assert(name != NULL); if(EmptyString(name)) return 0; if(ConfigFileEntry.disable_fake_channels && !IsOper(source_p)) { - for(; *name; ++name) + for(p = name; *p; ++p) { - if(!IsChanChar(*name) || IsFakeChanChar(*name)) + if(!IsChanChar(*p) || IsFakeChanChar(*p)) return 0; } } else { - for(; *name; ++name) + for(p = name; *p; ++p) { - if(!IsChanChar(*name)) + if(!IsChanChar(*p)) return 0; } } + if(ConfigChannel.only_ascii_channels) + { + for(p = name; *p; ++p) + if(*p < 33 || *p > 126) + return 0; + } + return 1; } diff --git a/modules/m_info.c b/modules/m_info.c index eaf920f0..3be948d3 100644 --- a/modules/m_info.c +++ b/modules/m_info.c @@ -542,6 +542,12 @@ static struct InfoStruct info_table[] = { &ConfigChannel.no_join_on_split, "Disallow joining channels when split", }, + { + "only_ascii_channels", + OUTPUT_BOOLEAN_YN, + &ConfigChannel.only_ascii_channels, + "Controls whether non-ASCII is disabled for JOIN" + }, { "use_except", OUTPUT_BOOLEAN_YN, diff --git a/src/newconf.c b/src/newconf.c index 80c59e8e..19d6317c 100644 --- a/src/newconf.c +++ b/src/newconf.c @@ -2187,6 +2187,7 @@ static struct ConfEntry conf_channel_table[] = { "max_chans_per_user", CF_INT, NULL, 0, &ConfigChannel.max_chans_per_user }, { "no_create_on_split", CF_YESNO, NULL, 0, &ConfigChannel.no_create_on_split }, { "no_join_on_split", CF_YESNO, NULL, 0, &ConfigChannel.no_join_on_split }, + { "only_ascii_channels", CF_YESNO, NULL, 0, &ConfigChannel.only_ascii_channels }, { "use_except", CF_YESNO, NULL, 0, &ConfigChannel.use_except }, { "use_invex", CF_YESNO, NULL, 0, &ConfigChannel.use_invex }, { "use_knock", CF_YESNO, NULL, 0, &ConfigChannel.use_knock }, diff --git a/src/s_conf.c b/src/s_conf.c index 13751b51..718993fc 100644 --- a/src/s_conf.c +++ b/src/s_conf.c @@ -811,6 +811,7 @@ set_default_conf(void) ConfigChannel.max_chans_per_user = 15; ConfigChannel.max_bans = 25; ConfigChannel.max_bans_large = 500; + ConfigChannel.only_ascii_channels = NO; ConfigChannel.burst_topicwho = NO; ConfigChannel.kick_on_split_riding = NO;