| 1 |
adx |
30 |
/* |
| 2 |
michael |
2820 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
adx |
30 |
* |
| 4 |
michael |
2820 |
* Copyright (c) 1997-2014 ircd-hybrid development team |
| 5 |
adx |
30 |
* |
| 6 |
|
|
* This program is free software; you can redistribute it and/or modify |
| 7 |
|
|
* it under the terms of the GNU General Public License as published by |
| 8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
| 9 |
|
|
* (at your option) any later version. |
| 10 |
|
|
* |
| 11 |
|
|
* This program is distributed in the hope that it will be useful, |
| 12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
|
|
* GNU General Public License for more details. |
| 15 |
|
|
* |
| 16 |
|
|
* You should have received a copy of the GNU General Public License |
| 17 |
|
|
* along with this program; if not, write to the Free Software |
| 18 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 19 |
|
|
* USA |
| 20 |
|
|
*/ |
| 21 |
|
|
|
| 22 |
michael |
2820 |
/*! \file m_mode.c |
| 23 |
|
|
* \brief Includes required functions for processing the MODE/TMODE/BMASK command. |
| 24 |
|
|
* \version $Id$ |
| 25 |
|
|
*/ |
| 26 |
|
|
|
| 27 |
adx |
30 |
#include "stdinc.h" |
| 28 |
michael |
1011 |
#include "list.h" |
| 29 |
adx |
30 |
#include "channel.h" |
| 30 |
|
|
#include "channel_mode.h" |
| 31 |
|
|
#include "client.h" |
| 32 |
|
|
#include "hash.h" |
| 33 |
|
|
#include "irc_string.h" |
| 34 |
|
|
#include "ircd.h" |
| 35 |
|
|
#include "numeric.h" |
| 36 |
|
|
#include "s_user.h" |
| 37 |
michael |
1309 |
#include "conf.h" |
| 38 |
adx |
30 |
#include "s_serv.h" |
| 39 |
|
|
#include "send.h" |
| 40 |
|
|
#include "parse.h" |
| 41 |
|
|
#include "modules.h" |
| 42 |
|
|
#include "packet.h" |
| 43 |
|
|
|
| 44 |
|
|
|
| 45 |
|
|
/* |
| 46 |
|
|
* m_mode - MODE command handler |
| 47 |
michael |
3096 |
* parv[0] - command |
| 48 |
adx |
30 |
* parv[1] - channel |
| 49 |
|
|
*/ |
| 50 |
michael |
2820 |
static int |
| 51 |
adx |
30 |
m_mode(struct Client *client_p, struct Client *source_p, |
| 52 |
|
|
int parc, char *parv[]) |
| 53 |
|
|
{ |
| 54 |
|
|
struct Channel *chptr = NULL; |
| 55 |
michael |
1895 |
struct Membership *member = NULL; |
| 56 |
|
|
char modebuf[MODEBUFLEN]; |
| 57 |
|
|
char parabuf[MODEBUFLEN]; |
| 58 |
adx |
30 |
|
| 59 |
michael |
885 |
if (EmptyString(parv[1])) |
| 60 |
adx |
30 |
{ |
| 61 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "MODE"); |
| 62 |
michael |
2820 |
return 0; |
| 63 |
adx |
30 |
} |
| 64 |
|
|
|
| 65 |
|
|
/* Now, try to find the channel in question */ |
| 66 |
|
|
if (!IsChanPrefix(*parv[1])) |
| 67 |
|
|
{ |
| 68 |
|
|
/* if here, it has to be a non-channel name */ |
| 69 |
|
|
set_user_mode(client_p, source_p, parc, parv); |
| 70 |
michael |
2820 |
return 0; |
| 71 |
adx |
30 |
} |
| 72 |
|
|
|
| 73 |
michael |
885 |
if ((chptr = hash_find_channel(parv[1])) == NULL) |
| 74 |
adx |
30 |
{ |
| 75 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[1]); |
| 76 |
michael |
2820 |
return 0; |
| 77 |
db |
848 |
} |
| 78 |
adx |
30 |
|
| 79 |
|
|
/* Now known the channel exists */ |
| 80 |
|
|
if (parc < 3) |
| 81 |
|
|
{ |
| 82 |
|
|
channel_modes(chptr, source_p, modebuf, parabuf); |
| 83 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_CHANNELMODEIS, chptr->chname, modebuf, parabuf); |
| 84 |
|
|
sendto_one_numeric(source_p, &me, RPL_CREATIONTIME, chptr->chname, chptr->channelts); |
| 85 |
michael |
2820 |
return 0; |
| 86 |
adx |
30 |
} |
| 87 |
michael |
1895 |
|
| 88 |
|
|
/* |
| 89 |
|
|
* bounce all modes from people we deop on sjoin |
| 90 |
adx |
30 |
* servers have always gotten away with murder, |
| 91 |
|
|
* including telnet servers *g* - Dianora |
| 92 |
|
|
*/ |
| 93 |
michael |
2644 |
if (IsServer(source_p) || HasFlag(source_p, FLAGS_SERVICE)) |
| 94 |
michael |
2937 |
set_channel_mode(client_p, source_p, chptr, NULL, parc - 2, parv + 2); |
| 95 |
adx |
30 |
else |
| 96 |
|
|
{ |
| 97 |
|
|
member = find_channel_link(source_p, chptr); |
| 98 |
|
|
|
| 99 |
|
|
if (!has_member_flags(member, CHFL_DEOPPED)) |
| 100 |
|
|
{ |
| 101 |
|
|
/* Finish the flood grace period... */ |
| 102 |
|
|
if (MyClient(source_p) && !IsFloodDone(source_p)) |
| 103 |
|
|
if (!((parc == 3) && (parv[2][0] == 'b') && (parv[2][1] == '\0'))) |
| 104 |
|
|
flood_endgrace(source_p); |
| 105 |
|
|
|
| 106 |
michael |
2937 |
set_channel_mode(client_p, source_p, chptr, member, parc - 2, parv + 2); |
| 107 |
adx |
30 |
} |
| 108 |
|
|
} |
| 109 |
michael |
2820 |
|
| 110 |
|
|
return 0; |
| 111 |
adx |
30 |
} |
| 112 |
|
|
|
| 113 |
|
|
/* |
| 114 |
|
|
* ms_tmode() |
| 115 |
|
|
* |
| 116 |
michael |
3096 |
* inputs - parv[0] = command |
| 117 |
adx |
30 |
* parv[1] = TS |
| 118 |
|
|
* parv[2] = channel name |
| 119 |
|
|
* parv[3] = modestring |
| 120 |
|
|
*/ |
| 121 |
michael |
2820 |
static int |
| 122 |
adx |
30 |
ms_tmode(struct Client *client_p, struct Client *source_p, int parc, char *parv[]) |
| 123 |
|
|
{ |
| 124 |
|
|
struct Channel *chptr = NULL; |
| 125 |
|
|
struct Membership *member = NULL; |
| 126 |
|
|
|
| 127 |
|
|
if ((chptr = hash_find_channel(parv[2])) == NULL) |
| 128 |
|
|
{ |
| 129 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[2]); |
| 130 |
michael |
2820 |
return 0; |
| 131 |
adx |
30 |
} |
| 132 |
|
|
|
| 133 |
|
|
if (atol(parv[1]) > chptr->channelts) |
| 134 |
michael |
2820 |
return 0; |
| 135 |
adx |
30 |
|
| 136 |
michael |
2644 |
if (IsServer(source_p) || HasFlag(source_p, FLAGS_SERVICE)) |
| 137 |
michael |
2937 |
set_channel_mode(client_p, source_p, chptr, NULL, parc - 3, parv + 3); |
| 138 |
adx |
30 |
else |
| 139 |
|
|
{ |
| 140 |
|
|
member = find_channel_link(source_p, chptr); |
| 141 |
|
|
|
| 142 |
|
|
/* XXX are we sure we just want to bail here? */ |
| 143 |
|
|
if (has_member_flags(member, CHFL_DEOPPED)) |
| 144 |
michael |
2820 |
return 0; |
| 145 |
adx |
30 |
|
| 146 |
michael |
2937 |
set_channel_mode(client_p, source_p, chptr, member, parc - 3, parv + 3); |
| 147 |
adx |
30 |
} |
| 148 |
michael |
2820 |
|
| 149 |
|
|
return 0; |
| 150 |
adx |
30 |
} |
| 151 |
|
|
|
| 152 |
|
|
/* |
| 153 |
|
|
* ms_bmask() |
| 154 |
|
|
* |
| 155 |
michael |
3096 |
* inputs - parv[0] = command |
| 156 |
adx |
30 |
* parv[1] = TS |
| 157 |
|
|
* parv[2] = channel name |
| 158 |
|
|
* parv[3] = type of ban to add ('b' 'I' or 'e') |
| 159 |
|
|
* parv[4] = space delimited list of masks to add |
| 160 |
|
|
* outputs - none |
| 161 |
|
|
* side effects - propagates unchanged bmask line to CAP_TS6 servers, |
| 162 |
|
|
* sends plain modes to the others. nothing is sent |
| 163 |
|
|
* to the server the issuing server is connected through |
| 164 |
|
|
*/ |
| 165 |
michael |
2820 |
static int |
| 166 |
adx |
30 |
ms_bmask(struct Client *client_p, struct Client *source_p, int parc, char *parv[]) |
| 167 |
|
|
{ |
| 168 |
michael |
2820 |
char modebuf[IRCD_BUFSIZE]; |
| 169 |
|
|
char parabuf[IRCD_BUFSIZE]; |
| 170 |
|
|
char banbuf[IRCD_BUFSIZE]; |
| 171 |
adx |
30 |
struct Channel *chptr; |
| 172 |
|
|
char *s, *t, *mbuf, *pbuf; |
| 173 |
michael |
3044 |
unsigned int mode_type = 0; |
| 174 |
adx |
30 |
int mlen, tlen; |
| 175 |
|
|
int modecount = 0; |
| 176 |
|
|
|
| 177 |
|
|
if ((chptr = hash_find_channel(parv[2])) == NULL) |
| 178 |
michael |
2820 |
return 0; |
| 179 |
adx |
30 |
|
| 180 |
|
|
/* TS is higher, drop it. */ |
| 181 |
|
|
if (atol(parv[1]) > chptr->channelts) |
| 182 |
michael |
2820 |
return 0; |
| 183 |
adx |
30 |
|
| 184 |
|
|
switch (*parv[3]) |
| 185 |
|
|
{ |
| 186 |
|
|
case 'b': |
| 187 |
|
|
mode_type = CHFL_BAN; |
| 188 |
|
|
break; |
| 189 |
|
|
|
| 190 |
|
|
case 'e': |
| 191 |
|
|
mode_type = CHFL_EXCEPTION; |
| 192 |
|
|
break; |
| 193 |
|
|
|
| 194 |
|
|
case 'I': |
| 195 |
|
|
mode_type = CHFL_INVEX; |
| 196 |
|
|
break; |
| 197 |
|
|
|
| 198 |
|
|
/* maybe we should just blindly propagate this? */ |
| 199 |
|
|
default: |
| 200 |
michael |
2820 |
return 0; |
| 201 |
adx |
30 |
} |
| 202 |
|
|
|
| 203 |
|
|
parabuf[0] = '\0'; |
| 204 |
|
|
s = banbuf; |
| 205 |
|
|
strlcpy(s, parv[4], sizeof(banbuf)); |
| 206 |
|
|
|
| 207 |
|
|
/* only need to construct one buffer, for non-ts6 servers */ |
| 208 |
michael |
1793 |
mlen = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s +", |
| 209 |
michael |
2560 |
(IsHidden(source_p) || ConfigServerHide.hide_servers) ? me.name : source_p->name, |
| 210 |
|
|
chptr->chname); |
| 211 |
adx |
30 |
mbuf = modebuf + mlen; |
| 212 |
|
|
pbuf = parabuf; |
| 213 |
|
|
|
| 214 |
michael |
2820 |
do |
| 215 |
|
|
{ |
| 216 |
|
|
if ((t = strchr(s, ' '))) |
| 217 |
adx |
30 |
*t++ = '\0'; |
| 218 |
|
|
tlen = strlen(s); |
| 219 |
|
|
|
| 220 |
michael |
2820 |
/* I don't even want to begin parsing this.. */ |
| 221 |
adx |
30 |
if (tlen > MODEBUFLEN) |
| 222 |
|
|
break; |
| 223 |
|
|
|
| 224 |
|
|
if (tlen && *s != ':' && add_id(source_p, chptr, s, mode_type)) |
| 225 |
|
|
{ |
| 226 |
|
|
/* this new one wont fit.. */ |
| 227 |
|
|
if (mbuf - modebuf + 2 + pbuf - parabuf + tlen > IRCD_BUFSIZE - 2 || |
| 228 |
|
|
modecount >= MAXMODEPARAMS) |
| 229 |
|
|
{ |
| 230 |
|
|
*mbuf = '\0'; |
| 231 |
|
|
*(pbuf - 1) = '\0'; |
| 232 |
|
|
|
| 233 |
michael |
1011 |
sendto_channel_local(ALL_MEMBERS, 0, chptr, "%s %s", |
| 234 |
adx |
30 |
modebuf, parabuf); |
| 235 |
|
|
mbuf = modebuf + mlen; |
| 236 |
|
|
pbuf = parabuf; |
| 237 |
|
|
modecount = 0; |
| 238 |
|
|
} |
| 239 |
|
|
|
| 240 |
|
|
*mbuf++ = parv[3][0]; |
| 241 |
michael |
1793 |
pbuf += sprintf(pbuf, "%s ", s); |
| 242 |
adx |
30 |
modecount++; |
| 243 |
|
|
} |
| 244 |
|
|
|
| 245 |
|
|
s = t; |
| 246 |
|
|
} while (s != NULL); |
| 247 |
|
|
|
| 248 |
|
|
if (modecount) |
| 249 |
|
|
{ |
| 250 |
|
|
*mbuf = *(pbuf - 1) = '\0'; |
| 251 |
michael |
1011 |
sendto_channel_local(ALL_MEMBERS, 0, chptr, "%s %s", modebuf, parabuf); |
| 252 |
adx |
30 |
} |
| 253 |
|
|
|
| 254 |
|
|
/* assumption here is that since the server sent BMASK, they are TS6, so they have an ID */ |
| 255 |
michael |
3135 |
sendto_server(client_p, NOCAPS, NOCAPS, ":%s BMASK %lu %s %s :%s", |
| 256 |
adx |
30 |
source_p->id, (unsigned long)chptr->channelts, chptr->chname, |
| 257 |
|
|
parv[3], parv[4]); |
| 258 |
michael |
2820 |
return 0; |
| 259 |
adx |
30 |
} |
| 260 |
michael |
1230 |
|
| 261 |
michael |
2820 |
static struct Message mode_msgtab = |
| 262 |
|
|
{ |
| 263 |
michael |
1230 |
"MODE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
| 264 |
michael |
2820 |
{ m_unregistered, m_mode, m_mode, m_ignore, m_mode, m_ignore } |
| 265 |
michael |
1230 |
}; |
| 266 |
|
|
|
| 267 |
michael |
2820 |
static struct Message tmode_msgtab = |
| 268 |
|
|
{ |
| 269 |
michael |
1230 |
"TMODE", 0, 0, 4, MAXPARA, MFLG_SLOW, 0, |
| 270 |
michael |
2820 |
{ m_ignore, m_ignore, ms_tmode, m_ignore, m_ignore, m_ignore } |
| 271 |
michael |
1230 |
}; |
| 272 |
|
|
|
| 273 |
michael |
2820 |
static struct Message bmask_msgtab = |
| 274 |
|
|
{ |
| 275 |
michael |
1230 |
"BMASK", 0, 0, 5, MAXPARA, MFLG_SLOW, 0, |
| 276 |
michael |
2820 |
{ m_ignore, m_ignore, ms_bmask, m_ignore, m_ignore, m_ignore } |
| 277 |
michael |
1230 |
}; |
| 278 |
|
|
|
| 279 |
|
|
static void |
| 280 |
|
|
module_init(void) |
| 281 |
|
|
{ |
| 282 |
|
|
mod_add_cmd(&mode_msgtab); |
| 283 |
|
|
mod_add_cmd(&tmode_msgtab); |
| 284 |
|
|
mod_add_cmd(&bmask_msgtab); |
| 285 |
|
|
} |
| 286 |
|
|
|
| 287 |
|
|
static void |
| 288 |
|
|
module_exit(void) |
| 289 |
|
|
{ |
| 290 |
|
|
mod_del_cmd(&mode_msgtab); |
| 291 |
|
|
mod_del_cmd(&tmode_msgtab); |
| 292 |
|
|
mod_del_cmd(&bmask_msgtab); |
| 293 |
|
|
} |
| 294 |
|
|
|
| 295 |
michael |
2820 |
struct module module_entry = |
| 296 |
|
|
{ |
| 297 |
michael |
1230 |
.node = { NULL, NULL, NULL }, |
| 298 |
|
|
.name = NULL, |
| 299 |
|
|
.version = "$Revision$", |
| 300 |
|
|
.handle = NULL, |
| 301 |
|
|
.modinit = module_init, |
| 302 |
|
|
.modexit = module_exit, |
| 303 |
|
|
.flags = MODULE_FLAG_CORE |
| 304 |
|
|
}; |