]>
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), | |
5c01fc8b | 135 | me.name, source_p->name, parv[1], (long long)chptr->channelts); |
212380e3 AC |
136 | } |
137 | else | |
138 | { | |
139 | msptr = find_channel_membership(chptr, source_p); | |
140 | ||
212380e3 AC |
141 | set_channel_mode(client_p, source_p, chptr, msptr, parc - n, parv + n); |
142 | } | |
212380e3 AC |
143 | } |
144 | ||
3c7d6fcc | 145 | static void |
428ca87b | 146 | ms_mode(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
147 | { |
148 | struct Channel *chptr; | |
149 | ||
150 | chptr = find_channel(parv[1]); | |
151 | ||
152 | if(chptr == NULL) | |
153 | { | |
154 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
155 | form_str(ERR_NOSUCHCHANNEL), parv[1]); | |
3c7d6fcc | 156 | return; |
212380e3 AC |
157 | } |
158 | ||
159 | set_channel_mode(client_p, source_p, chptr, NULL, parc - 2, parv + 2); | |
212380e3 AC |
160 | } |
161 | ||
3c7d6fcc | 162 | static void |
428ca87b | 163 | ms_tmode(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
164 | { |
165 | struct Channel *chptr = NULL; | |
166 | struct membership *msptr; | |
167 | ||
168 | /* Now, try to find the channel in question */ | |
169 | if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2])) | |
170 | { | |
171 | sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[2]); | |
3c7d6fcc | 172 | return; |
212380e3 AC |
173 | } |
174 | ||
175 | chptr = find_channel(parv[2]); | |
176 | ||
177 | if(chptr == NULL) | |
178 | { | |
179 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
180 | form_str(ERR_NOSUCHCHANNEL), parv[2]); | |
3c7d6fcc | 181 | return; |
212380e3 AC |
182 | } |
183 | ||
184 | /* TS is higher, drop it. */ | |
185 | if(atol(parv[1]) > chptr->channelts) | |
3c7d6fcc | 186 | return; |
212380e3 AC |
187 | |
188 | if(IsServer(source_p)) | |
189 | { | |
190 | set_channel_mode(client_p, source_p, chptr, NULL, parc - 3, parv + 3); | |
191 | } | |
192 | else | |
193 | { | |
194 | msptr = find_channel_membership(chptr, source_p); | |
195 | ||
212380e3 AC |
196 | set_channel_mode(client_p, source_p, chptr, msptr, parc - 3, parv + 3); |
197 | } | |
212380e3 AC |
198 | } |
199 | ||
3c7d6fcc | 200 | static void |
428ca87b | 201 | ms_mlock(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
8727cbe8 AC |
202 | { |
203 | struct Channel *chptr = NULL; | |
204 | ||
205 | /* Now, try to find the channel in question */ | |
206 | if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2])) | |
207 | { | |
208 | sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[2]); | |
3c7d6fcc | 209 | return; |
8727cbe8 AC |
210 | } |
211 | ||
212 | chptr = find_channel(parv[2]); | |
213 | ||
214 | if(chptr == NULL) | |
215 | { | |
216 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
217 | form_str(ERR_NOSUCHCHANNEL), parv[2]); | |
3c7d6fcc | 218 | return; |
8727cbe8 AC |
219 | } |
220 | ||
221 | /* TS is higher, drop it. */ | |
222 | if(atol(parv[1]) > chptr->channelts) | |
3c7d6fcc | 223 | return; |
8727cbe8 AC |
224 | |
225 | if(IsServer(source_p)) | |
07554369 | 226 | set_channel_mlock(client_p, source_p, chptr, parv[3], true); |
8727cbe8 AC |
227 | } |
228 | ||
d1316b19 JT |
229 | static void |
230 | possibly_remove_lower_forward(struct Client *fakesource_p, int mems, | |
231 | struct Channel *chptr, rb_dlink_list *banlist, int mchar, | |
232 | const char *mask, const char *forward) | |
233 | { | |
234 | struct Ban *actualBan; | |
235 | rb_dlink_node *ptr; | |
236 | ||
237 | RB_DLINK_FOREACH(ptr, banlist->head) | |
238 | { | |
239 | actualBan = ptr->data; | |
240 | if(!irccmp(actualBan->banstr, mask) && | |
241 | (actualBan->forward == NULL || | |
242 | irccmp(actualBan->forward, forward) < 0)) | |
243 | { | |
4b1cce65 | 244 | sendto_channel_local(fakesource_p, mems, chptr, ":%s MODE %s -%c %s%s%s", |
d1316b19 JT |
245 | fakesource_p->name, |
246 | chptr->chname, | |
247 | mchar, | |
248 | actualBan->banstr, | |
249 | actualBan->forward ? "$" : "", | |
250 | actualBan->forward ? actualBan->forward : ""); | |
251 | rb_dlinkDelete(&actualBan->node, banlist); | |
252 | free_ban(actualBan); | |
253 | return; | |
254 | } | |
255 | } | |
256 | } | |
257 | ||
3c7d6fcc | 258 | static void |
428ca87b | 259 | ms_bmask(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
260 | { |
261 | static char modebuf[BUFSIZE]; | |
262 | static char parabuf[BUFSIZE]; | |
263 | struct Channel *chptr; | |
5b96d9a6 | 264 | rb_dlink_list *banlist; |
765d839d | 265 | char *s, *forward; |
212380e3 AC |
266 | char *t; |
267 | char *mbuf; | |
268 | char *pbuf; | |
269 | long mode_type; | |
270 | int mlen; | |
271 | int plen = 0; | |
272 | int tlen; | |
273 | int arglen; | |
274 | int modecount = 0; | |
275 | int needcap = NOCAPS; | |
276 | int mems; | |
277 | struct Client *fakesource_p; | |
278 | ||
279 | if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2])) | |
3c7d6fcc | 280 | return; |
212380e3 AC |
281 | |
282 | if((chptr = find_channel(parv[2])) == NULL) | |
3c7d6fcc | 283 | return; |
212380e3 AC |
284 | |
285 | /* TS is higher, drop it. */ | |
286 | if(atol(parv[1]) > chptr->channelts) | |
3c7d6fcc | 287 | return; |
212380e3 AC |
288 | |
289 | switch (parv[3][0]) | |
290 | { | |
291 | case 'b': | |
292 | banlist = &chptr->banlist; | |
293 | mode_type = CHFL_BAN; | |
294 | mems = ALL_MEMBERS; | |
295 | break; | |
296 | ||
297 | case 'e': | |
298 | banlist = &chptr->exceptlist; | |
299 | mode_type = CHFL_EXCEPTION; | |
300 | needcap = CAP_EX; | |
301 | mems = ONLY_CHANOPS; | |
302 | break; | |
303 | ||
304 | case 'I': | |
305 | banlist = &chptr->invexlist; | |
306 | mode_type = CHFL_INVEX; | |
307 | needcap = CAP_IE; | |
308 | mems = ONLY_CHANOPS; | |
309 | break; | |
310 | ||
311 | case 'q': | |
312 | banlist = &chptr->quietlist; | |
313 | mode_type = CHFL_QUIET; | |
314 | mems = ALL_MEMBERS; | |
315 | break; | |
316 | ||
317 | /* maybe we should just blindly propagate this? */ | |
318 | default: | |
3c7d6fcc | 319 | return; |
212380e3 AC |
320 | } |
321 | ||
322 | parabuf[0] = '\0'; | |
323 | s = LOCAL_COPY(parv[4]); | |
324 | ||
325 | /* Hide connecting server on netburst -- jilles */ | |
326 | if (ConfigServerHide.flatten_links && !HasSentEob(source_p)) | |
327 | fakesource_p = &me; | |
328 | else | |
329 | fakesource_p = source_p; | |
5203cba5 | 330 | mlen = sprintf(modebuf, ":%s MODE %s +", fakesource_p->name, chptr->chname); |
212380e3 AC |
331 | mbuf = modebuf + mlen; |
332 | pbuf = parabuf; | |
333 | ||
334 | while(*s == ' ') | |
335 | s++; | |
336 | ||
337 | /* next char isnt a space, point t to the next one */ | |
338 | if((t = strchr(s, ' ')) != NULL) | |
339 | { | |
340 | *t++ = '\0'; | |
341 | ||
342 | /* double spaces will break the parser */ | |
343 | while(*t == ' ') | |
344 | t++; | |
345 | } | |
346 | ||
347 | /* couldve skipped spaces and got nothing.. */ | |
348 | while(!EmptyString(s)) | |
349 | { | |
350 | /* ban with a leading ':' -- this will break the protocol */ | |
351 | if(*s == ':') | |
352 | goto nextban; | |
353 | ||
354 | tlen = strlen(s); | |
355 | ||
356 | /* I dont even want to begin parsing this.. */ | |
357 | if(tlen > MODEBUFLEN) | |
358 | break; | |
359 | ||
765d839d EM |
360 | if((forward = strchr(s+1, '$')) != NULL) |
361 | { | |
362 | *forward++ = '\0'; | |
363 | if(*forward == '\0') | |
23f6b63a | 364 | tlen--, forward = NULL; |
fea6157d JT |
365 | else |
366 | possibly_remove_lower_forward(fakesource_p, | |
367 | mems, chptr, banlist, | |
368 | parv[3][0], s, forward); | |
765d839d EM |
369 | } |
370 | ||
371 | if(add_id(fakesource_p, chptr, s, forward, banlist, mode_type)) | |
212380e3 AC |
372 | { |
373 | /* this new one wont fit.. */ | |
374 | if(mlen + MAXMODEPARAMS + plen + tlen > BUFSIZE - 5 || | |
375 | modecount >= MAXMODEPARAMS) | |
376 | { | |
377 | *mbuf = '\0'; | |
378 | *(pbuf - 1) = '\0'; | |
4b1cce65 | 379 | sendto_channel_local(fakesource_p, mems, chptr, "%s %s", modebuf, parabuf); |
212380e3 AC |
380 | |
381 | mbuf = modebuf + mlen; | |
382 | pbuf = parabuf; | |
383 | plen = modecount = 0; | |
384 | } | |
385 | ||
23f6b63a JT |
386 | if (forward != NULL) |
387 | forward[-1] = '$'; | |
388 | ||
212380e3 | 389 | *mbuf++ = parv[3][0]; |
5203cba5 | 390 | arglen = sprintf(pbuf, "%s ", s); |
212380e3 AC |
391 | pbuf += arglen; |
392 | plen += arglen; | |
393 | modecount++; | |
394 | } | |
395 | ||
396 | nextban: | |
397 | s = t; | |
398 | ||
399 | if(s != NULL) | |
400 | { | |
401 | if((t = strchr(s, ' ')) != NULL) | |
402 | { | |
403 | *t++ = '\0'; | |
404 | ||
405 | while(*t == ' ') | |
406 | t++; | |
407 | } | |
408 | } | |
409 | } | |
410 | ||
411 | if(modecount) | |
412 | { | |
413 | *mbuf = '\0'; | |
414 | *(pbuf - 1) = '\0'; | |
4b1cce65 | 415 | sendto_channel_local(fakesource_p, mems, chptr, "%s %s", modebuf, parabuf); |
212380e3 AC |
416 | } |
417 | ||
418 | sendto_server(client_p, chptr, CAP_TS6 | needcap, NOCAPS, ":%s BMASK %ld %s %s :%s", | |
419 | source_p->id, (long) chptr->channelts, chptr->chname, parv[3], parv[4]); | |
212380e3 | 420 | } |