]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * m_mode.c: Sets a user or channel mode. | |
4 | * | |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center | |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
22 | * USA | |
212380e3 AC |
23 | */ |
24 | ||
25 | #include "stdinc.h" | |
212380e3 AC |
26 | #include "channel.h" |
27 | #include "client.h" | |
28 | #include "hash.h" | |
4562c604 | 29 | #include "match.h" |
212380e3 AC |
30 | #include "ircd.h" |
31 | #include "numeric.h" | |
32 | #include "s_user.h" | |
33 | #include "s_conf.h" | |
34 | #include "s_serv.h" | |
4016731b | 35 | #include "logger.h" |
212380e3 AC |
36 | #include "send.h" |
37 | #include "msg.h" | |
38 | #include "parse.h" | |
39 | #include "modules.h" | |
40 | #include "packet.h" | |
212380e3 AC |
41 | #include "s_newconf.h" |
42 | ||
eeabf33a EM |
43 | static const char mode_desc[] = |
44 | "Provides the MODE and MLOCK client and server commands, and TS6 server-to-server TMODE and BMASK commands"; | |
45 | ||
3c7d6fcc EM |
46 | static void m_mode(struct MsgBuf *, struct Client *, struct Client *, int, const char **); |
47 | static void ms_mode(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
48 | static void ms_tmode(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
49 | static void ms_mlock(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
50 | static void ms_bmask(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
212380e3 AC |
51 | |
52 | struct Message mode_msgtab = { | |
7baa37a9 | 53 | "MODE", 0, 0, 0, 0, |
212380e3 AC |
54 | {mg_unreg, {m_mode, 2}, {m_mode, 3}, {ms_mode, 3}, mg_ignore, {m_mode, 2}} |
55 | }; | |
56 | struct Message tmode_msgtab = { | |
7baa37a9 | 57 | "TMODE", 0, 0, 0, 0, |
212380e3 AC |
58 | {mg_ignore, mg_ignore, {ms_tmode, 4}, {ms_tmode, 4}, mg_ignore, mg_ignore} |
59 | }; | |
8727cbe8 | 60 | struct Message mlock_msgtab = { |
7baa37a9 | 61 | "MLOCK", 0, 0, 0, 0, |
6b8db2da | 62 | {mg_ignore, mg_ignore, {ms_mlock, 3}, {ms_mlock, 3}, mg_ignore, mg_ignore} |
8727cbe8 | 63 | }; |
212380e3 | 64 | struct Message bmask_msgtab = { |
7baa37a9 | 65 | "BMASK", 0, 0, 0, 0, |
212380e3 AC |
66 | {mg_ignore, mg_ignore, mg_ignore, {ms_bmask, 5}, mg_ignore, mg_ignore} |
67 | }; | |
68 | ||
8727cbe8 | 69 | mapi_clist_av1 mode_clist[] = { &mode_msgtab, &tmode_msgtab, &mlock_msgtab, &bmask_msgtab, NULL }; |
212380e3 | 70 | |
ee6dcb05 | 71 | DECLARE_MODULE_AV2(mode, NULL, NULL, mode_clist, NULL, NULL, NULL, NULL, mode_desc); |
212380e3 AC |
72 | |
73 | /* | |
74 | * m_mode - MODE command handler | |
212380e3 AC |
75 | * parv[1] - channel |
76 | */ | |
3c7d6fcc | 77 | static void |
428ca87b | 78 | m_mode(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
79 | { |
80 | struct Channel *chptr = NULL; | |
81 | struct membership *msptr; | |
82 | int n = 2; | |
83 | const char *dest; | |
84 | int operspy = 0; | |
85 | ||
86 | dest = parv[1]; | |
87 | ||
88 | if(IsOperSpy(source_p) && *dest == '!') | |
89 | { | |
90 | dest++; | |
91 | operspy = 1; | |
92 | ||
93 | if(EmptyString(dest)) | |
94 | { | |
95 | sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), | |
96 | me.name, source_p->name, "MODE"); | |
3c7d6fcc | 97 | return; |
212380e3 AC |
98 | } |
99 | } | |
100 | ||
101 | /* Now, try to find the channel in question */ | |
102 | if(!IsChanPrefix(*dest)) | |
103 | { | |
104 | /* if here, it has to be a non-channel name */ | |
105 | user_mode(client_p, source_p, parc, parv); | |
3c7d6fcc | 106 | return; |
212380e3 AC |
107 | } |
108 | ||
109 | if(!check_channel_name(dest)) | |
110 | { | |
111 | sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[1]); | |
3c7d6fcc | 112 | return; |
212380e3 AC |
113 | } |
114 | ||
115 | chptr = find_channel(dest); | |
116 | ||
117 | if(chptr == NULL) | |
118 | { | |
119 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
120 | form_str(ERR_NOSUCHCHANNEL), parv[1]); | |
3c7d6fcc | 121 | return; |
212380e3 AC |
122 | } |
123 | ||
124 | /* Now know the channel exists */ | |
125 | if(parc < n + 1) | |
126 | { | |
127 | if(operspy) | |
128 | report_operspy(source_p, "MODE", chptr->chname); | |
129 | ||
130 | sendto_one(source_p, form_str(RPL_CHANNELMODEIS), | |
131 | me.name, source_p->name, parv[1], | |
132 | operspy ? channel_modes(chptr, &me) : channel_modes(chptr, source_p)); | |
133 | ||
134 | sendto_one(source_p, form_str(RPL_CREATIONTIME), | |
135 | me.name, source_p->name, parv[1], chptr->channelts); | |
136 | } | |
137 | else | |
138 | { | |
139 | msptr = find_channel_membership(chptr, source_p); | |
140 | ||
212380e3 AC |
141 | /* Finish the flood grace period... */ |
142 | if(MyClient(source_p) && !IsFloodDone(source_p)) | |
143 | { | |
c7b2fd3d | 144 | if(!((parc == 3) && (parv[2][0] == 'b' || parv[2][0] == 'q') && (parv[2][1] == '\0'))) |
212380e3 AC |
145 | flood_endgrace(source_p); |
146 | } | |
147 | ||
148 | set_channel_mode(client_p, source_p, chptr, msptr, parc - n, parv + n); | |
149 | } | |
212380e3 AC |
150 | } |
151 | ||
3c7d6fcc | 152 | static void |
428ca87b | 153 | ms_mode(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
154 | { |
155 | struct Channel *chptr; | |
156 | ||
157 | chptr = find_channel(parv[1]); | |
158 | ||
159 | if(chptr == NULL) | |
160 | { | |
161 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
162 | form_str(ERR_NOSUCHCHANNEL), parv[1]); | |
3c7d6fcc | 163 | return; |
212380e3 AC |
164 | } |
165 | ||
166 | set_channel_mode(client_p, source_p, chptr, NULL, parc - 2, parv + 2); | |
212380e3 AC |
167 | } |
168 | ||
3c7d6fcc | 169 | static void |
428ca87b | 170 | ms_tmode(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
171 | { |
172 | struct Channel *chptr = NULL; | |
173 | struct membership *msptr; | |
174 | ||
175 | /* Now, try to find the channel in question */ | |
176 | if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2])) | |
177 | { | |
178 | sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[2]); | |
3c7d6fcc | 179 | return; |
212380e3 AC |
180 | } |
181 | ||
182 | chptr = find_channel(parv[2]); | |
183 | ||
184 | if(chptr == NULL) | |
185 | { | |
186 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
187 | form_str(ERR_NOSUCHCHANNEL), parv[2]); | |
3c7d6fcc | 188 | return; |
212380e3 AC |
189 | } |
190 | ||
191 | /* TS is higher, drop it. */ | |
192 | if(atol(parv[1]) > chptr->channelts) | |
3c7d6fcc | 193 | return; |
212380e3 AC |
194 | |
195 | if(IsServer(source_p)) | |
196 | { | |
197 | set_channel_mode(client_p, source_p, chptr, NULL, parc - 3, parv + 3); | |
198 | } | |
199 | else | |
200 | { | |
201 | msptr = find_channel_membership(chptr, source_p); | |
202 | ||
212380e3 AC |
203 | set_channel_mode(client_p, source_p, chptr, msptr, parc - 3, parv + 3); |
204 | } | |
212380e3 AC |
205 | } |
206 | ||
3c7d6fcc | 207 | static void |
428ca87b | 208 | ms_mlock(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
8727cbe8 AC |
209 | { |
210 | struct Channel *chptr = NULL; | |
211 | ||
212 | /* Now, try to find the channel in question */ | |
213 | if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2])) | |
214 | { | |
215 | sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[2]); | |
3c7d6fcc | 216 | return; |
8727cbe8 AC |
217 | } |
218 | ||
219 | chptr = find_channel(parv[2]); | |
220 | ||
221 | if(chptr == NULL) | |
222 | { | |
223 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
224 | form_str(ERR_NOSUCHCHANNEL), parv[2]); | |
3c7d6fcc | 225 | return; |
8727cbe8 AC |
226 | } |
227 | ||
228 | /* TS is higher, drop it. */ | |
229 | if(atol(parv[1]) > chptr->channelts) | |
3c7d6fcc | 230 | return; |
8727cbe8 AC |
231 | |
232 | if(IsServer(source_p)) | |
07554369 | 233 | set_channel_mlock(client_p, source_p, chptr, parv[3], true); |
8727cbe8 AC |
234 | } |
235 | ||
d1316b19 JT |
236 | static void |
237 | possibly_remove_lower_forward(struct Client *fakesource_p, int mems, | |
238 | struct Channel *chptr, rb_dlink_list *banlist, int mchar, | |
239 | const char *mask, const char *forward) | |
240 | { | |
241 | struct Ban *actualBan; | |
242 | rb_dlink_node *ptr; | |
243 | ||
244 | RB_DLINK_FOREACH(ptr, banlist->head) | |
245 | { | |
246 | actualBan = ptr->data; | |
247 | if(!irccmp(actualBan->banstr, mask) && | |
248 | (actualBan->forward == NULL || | |
249 | irccmp(actualBan->forward, forward) < 0)) | |
250 | { | |
251 | sendto_channel_local(mems, chptr, ":%s MODE %s -%c %s%s%s", | |
252 | fakesource_p->name, | |
253 | chptr->chname, | |
254 | mchar, | |
255 | actualBan->banstr, | |
256 | actualBan->forward ? "$" : "", | |
257 | actualBan->forward ? actualBan->forward : ""); | |
258 | rb_dlinkDelete(&actualBan->node, banlist); | |
259 | free_ban(actualBan); | |
260 | return; | |
261 | } | |
262 | } | |
263 | } | |
264 | ||
3c7d6fcc | 265 | static void |
428ca87b | 266 | ms_bmask(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
267 | { |
268 | static char modebuf[BUFSIZE]; | |
269 | static char parabuf[BUFSIZE]; | |
270 | struct Channel *chptr; | |
5b96d9a6 | 271 | rb_dlink_list *banlist; |
765d839d | 272 | char *s, *forward; |
212380e3 AC |
273 | char *t; |
274 | char *mbuf; | |
275 | char *pbuf; | |
276 | long mode_type; | |
277 | int mlen; | |
278 | int plen = 0; | |
279 | int tlen; | |
280 | int arglen; | |
281 | int modecount = 0; | |
282 | int needcap = NOCAPS; | |
283 | int mems; | |
284 | struct Client *fakesource_p; | |
285 | ||
286 | if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2])) | |
3c7d6fcc | 287 | return; |
212380e3 AC |
288 | |
289 | if((chptr = find_channel(parv[2])) == NULL) | |
3c7d6fcc | 290 | return; |
212380e3 AC |
291 | |
292 | /* TS is higher, drop it. */ | |
293 | if(atol(parv[1]) > chptr->channelts) | |
3c7d6fcc | 294 | return; |
212380e3 AC |
295 | |
296 | switch (parv[3][0]) | |
297 | { | |
298 | case 'b': | |
299 | banlist = &chptr->banlist; | |
300 | mode_type = CHFL_BAN; | |
301 | mems = ALL_MEMBERS; | |
302 | break; | |
303 | ||
304 | case 'e': | |
305 | banlist = &chptr->exceptlist; | |
306 | mode_type = CHFL_EXCEPTION; | |
307 | needcap = CAP_EX; | |
308 | mems = ONLY_CHANOPS; | |
309 | break; | |
310 | ||
311 | case 'I': | |
312 | banlist = &chptr->invexlist; | |
313 | mode_type = CHFL_INVEX; | |
314 | needcap = CAP_IE; | |
315 | mems = ONLY_CHANOPS; | |
316 | break; | |
317 | ||
318 | case 'q': | |
319 | banlist = &chptr->quietlist; | |
320 | mode_type = CHFL_QUIET; | |
321 | mems = ALL_MEMBERS; | |
322 | break; | |
323 | ||
324 | /* maybe we should just blindly propagate this? */ | |
325 | default: | |
3c7d6fcc | 326 | return; |
212380e3 AC |
327 | } |
328 | ||
329 | parabuf[0] = '\0'; | |
330 | s = LOCAL_COPY(parv[4]); | |
331 | ||
332 | /* Hide connecting server on netburst -- jilles */ | |
333 | if (ConfigServerHide.flatten_links && !HasSentEob(source_p)) | |
334 | fakesource_p = &me; | |
335 | else | |
336 | fakesource_p = source_p; | |
5203cba5 | 337 | mlen = sprintf(modebuf, ":%s MODE %s +", fakesource_p->name, chptr->chname); |
212380e3 AC |
338 | mbuf = modebuf + mlen; |
339 | pbuf = parabuf; | |
340 | ||
341 | while(*s == ' ') | |
342 | s++; | |
343 | ||
344 | /* next char isnt a space, point t to the next one */ | |
345 | if((t = strchr(s, ' ')) != NULL) | |
346 | { | |
347 | *t++ = '\0'; | |
348 | ||
349 | /* double spaces will break the parser */ | |
350 | while(*t == ' ') | |
351 | t++; | |
352 | } | |
353 | ||
354 | /* couldve skipped spaces and got nothing.. */ | |
355 | while(!EmptyString(s)) | |
356 | { | |
357 | /* ban with a leading ':' -- this will break the protocol */ | |
358 | if(*s == ':') | |
359 | goto nextban; | |
360 | ||
361 | tlen = strlen(s); | |
362 | ||
363 | /* I dont even want to begin parsing this.. */ | |
364 | if(tlen > MODEBUFLEN) | |
365 | break; | |
366 | ||
765d839d EM |
367 | if((forward = strchr(s+1, '$')) != NULL) |
368 | { | |
369 | *forward++ = '\0'; | |
370 | if(*forward == '\0') | |
23f6b63a | 371 | tlen--, forward = NULL; |
fea6157d JT |
372 | else |
373 | possibly_remove_lower_forward(fakesource_p, | |
374 | mems, chptr, banlist, | |
375 | parv[3][0], s, forward); | |
765d839d EM |
376 | } |
377 | ||
378 | if(add_id(fakesource_p, chptr, s, forward, banlist, mode_type)) | |
212380e3 AC |
379 | { |
380 | /* this new one wont fit.. */ | |
381 | if(mlen + MAXMODEPARAMS + plen + tlen > BUFSIZE - 5 || | |
382 | modecount >= MAXMODEPARAMS) | |
383 | { | |
384 | *mbuf = '\0'; | |
385 | *(pbuf - 1) = '\0'; | |
386 | sendto_channel_local(mems, chptr, "%s %s", modebuf, parabuf); | |
212380e3 AC |
387 | |
388 | mbuf = modebuf + mlen; | |
389 | pbuf = parabuf; | |
390 | plen = modecount = 0; | |
391 | } | |
392 | ||
23f6b63a JT |
393 | if (forward != NULL) |
394 | forward[-1] = '$'; | |
395 | ||
212380e3 | 396 | *mbuf++ = parv[3][0]; |
5203cba5 | 397 | arglen = sprintf(pbuf, "%s ", s); |
212380e3 AC |
398 | pbuf += arglen; |
399 | plen += arglen; | |
400 | modecount++; | |
401 | } | |
402 | ||
403 | nextban: | |
404 | s = t; | |
405 | ||
406 | if(s != NULL) | |
407 | { | |
408 | if((t = strchr(s, ' ')) != NULL) | |
409 | { | |
410 | *t++ = '\0'; | |
411 | ||
412 | while(*t == ' ') | |
413 | t++; | |
414 | } | |
415 | } | |
416 | } | |
417 | ||
418 | if(modecount) | |
419 | { | |
420 | *mbuf = '\0'; | |
421 | *(pbuf - 1) = '\0'; | |
422 | sendto_channel_local(mems, chptr, "%s %s", modebuf, parabuf); | |
212380e3 AC |
423 | } |
424 | ||
425 | sendto_server(client_p, chptr, CAP_TS6 | needcap, NOCAPS, ":%s BMASK %ld %s %s :%s", | |
426 | source_p->id, (long) chptr->channelts, chptr->chname, parv[3], parv[4]); | |
212380e3 | 427 | } |