]> jfr.im git - solanum.git/blame - modules/core/m_mode.c
Enforce TS rules on MLOCKs.
[solanum.git] / modules / core / m_mode.c
CommitLineData
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
23 *
24 * $Id: m_mode.c 1006 2006-03-09 15:32:14Z nenolod $
25 */
26
27#include "stdinc.h"
212380e3
AC
28#include "channel.h"
29#include "client.h"
30#include "hash.h"
4562c604 31#include "match.h"
212380e3
AC
32#include "ircd.h"
33#include "numeric.h"
34#include "s_user.h"
35#include "s_conf.h"
36#include "s_serv.h"
4016731b 37#include "logger.h"
212380e3
AC
38#include "send.h"
39#include "msg.h"
40#include "parse.h"
41#include "modules.h"
42#include "packet.h"
212380e3
AC
43#include "s_newconf.h"
44
45static int m_mode(struct Client *, struct Client *, int, const char **);
46static int ms_mode(struct Client *, struct Client *, int, const char **);
47static int ms_tmode(struct Client *, struct Client *, int, const char **);
8727cbe8 48static int ms_mlock(struct Client *, struct Client *, int, const char **);
212380e3
AC
49static int ms_bmask(struct Client *, struct Client *, int, const char **);
50
51struct Message mode_msgtab = {
52 "MODE", 0, 0, 0, MFLG_SLOW,
53 {mg_unreg, {m_mode, 2}, {m_mode, 3}, {ms_mode, 3}, mg_ignore, {m_mode, 2}}
54};
55struct Message tmode_msgtab = {
56 "TMODE", 0, 0, 0, MFLG_SLOW,
57 {mg_ignore, mg_ignore, {ms_tmode, 4}, {ms_tmode, 4}, mg_ignore, mg_ignore}
58};
8727cbe8
AC
59struct Message mlock_msgtab = {
60 "MLOCK", 0, 0, 0, MFLG_SLOW,
6b8db2da 61 {mg_ignore, mg_ignore, {ms_mlock, 3}, {ms_mlock, 3}, mg_ignore, mg_ignore}
8727cbe8 62};
212380e3
AC
63struct Message bmask_msgtab = {
64 "BMASK", 0, 0, 0, MFLG_SLOW,
65 {mg_ignore, mg_ignore, mg_ignore, {ms_bmask, 5}, mg_ignore, mg_ignore}
66};
67
8727cbe8 68mapi_clist_av1 mode_clist[] = { &mode_msgtab, &tmode_msgtab, &mlock_msgtab, &bmask_msgtab, NULL };
212380e3
AC
69
70DECLARE_MODULE_AV1(mode, NULL, NULL, mode_clist, NULL, NULL, "$Revision: 1006 $");
71
72/*
73 * m_mode - MODE command handler
212380e3
AC
74 * parv[1] - channel
75 */
76static int
77m_mode(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
78{
79 struct Channel *chptr = NULL;
80 struct membership *msptr;
81 int n = 2;
82 const char *dest;
83 int operspy = 0;
84
85 dest = parv[1];
86
87 if(IsOperSpy(source_p) && *dest == '!')
88 {
89 dest++;
90 operspy = 1;
91
92 if(EmptyString(dest))
93 {
94 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
95 me.name, source_p->name, "MODE");
96 return 0;
97 }
98 }
99
100 /* Now, try to find the channel in question */
101 if(!IsChanPrefix(*dest))
102 {
103 /* if here, it has to be a non-channel name */
104 user_mode(client_p, source_p, parc, parv);
105 return 0;
106 }
107
108 if(!check_channel_name(dest))
109 {
110 sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[1]);
111 return 0;
112 }
113
114 chptr = find_channel(dest);
115
116 if(chptr == NULL)
117 {
118 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
119 form_str(ERR_NOSUCHCHANNEL), parv[1]);
120 return 0;
121 }
122
123 /* Now know the channel exists */
124 if(parc < n + 1)
125 {
126 if(operspy)
127 report_operspy(source_p, "MODE", chptr->chname);
128
129 sendto_one(source_p, form_str(RPL_CHANNELMODEIS),
130 me.name, source_p->name, parv[1],
131 operspy ? channel_modes(chptr, &me) : channel_modes(chptr, source_p));
132
133 sendto_one(source_p, form_str(RPL_CREATIONTIME),
134 me.name, source_p->name, parv[1], chptr->channelts);
135 }
136 else
137 {
138 msptr = find_channel_membership(chptr, source_p);
139
212380e3
AC
140 /* Finish the flood grace period... */
141 if(MyClient(source_p) && !IsFloodDone(source_p))
142 {
143 if(!((parc == 3) && (parv[2][0] == 'b') && (parv[2][1] == '\0')))
144 flood_endgrace(source_p);
145 }
146
147 set_channel_mode(client_p, source_p, chptr, msptr, parc - n, parv + n);
148 }
149
150 return 0;
151}
152
153static int
154ms_mode(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
155{
156 struct Channel *chptr;
157
158 chptr = find_channel(parv[1]);
159
160 if(chptr == NULL)
161 {
162 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
163 form_str(ERR_NOSUCHCHANNEL), parv[1]);
164 return 0;
165 }
166
167 set_channel_mode(client_p, source_p, chptr, NULL, parc - 2, parv + 2);
168
169 return 0;
170}
171
172static int
173ms_tmode(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
174{
175 struct Channel *chptr = NULL;
176 struct membership *msptr;
177
178 /* Now, try to find the channel in question */
179 if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2]))
180 {
181 sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[2]);
182 return 0;
183 }
184
185 chptr = find_channel(parv[2]);
186
187 if(chptr == NULL)
188 {
189 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
190 form_str(ERR_NOSUCHCHANNEL), parv[2]);
191 return 0;
192 }
193
194 /* TS is higher, drop it. */
195 if(atol(parv[1]) > chptr->channelts)
196 return 0;
197
198 if(IsServer(source_p))
199 {
200 set_channel_mode(client_p, source_p, chptr, NULL, parc - 3, parv + 3);
201 }
202 else
203 {
204 msptr = find_channel_membership(chptr, source_p);
205
212380e3
AC
206 set_channel_mode(client_p, source_p, chptr, msptr, parc - 3, parv + 3);
207 }
208
209 return 0;
210}
211
8727cbe8
AC
212static int
213ms_mlock(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
214{
215 struct Channel *chptr = NULL;
216
217 /* Now, try to find the channel in question */
218 if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2]))
219 {
220 sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[2]);
221 return 0;
222 }
223
224 chptr = find_channel(parv[2]);
225
226 if(chptr == NULL)
227 {
228 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
229 form_str(ERR_NOSUCHCHANNEL), parv[2]);
230 return 0;
231 }
232
233 /* TS is higher, drop it. */
234 if(atol(parv[1]) > chptr->channelts)
235 return 0;
236
237 if(IsServer(source_p))
6fb6bd15 238 set_channel_mlock(client_p, source_p, chptr, parv[3], TRUE);
8727cbe8
AC
239
240 return 0;
241}
242
212380e3
AC
243static int
244ms_bmask(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
245{
246 static char modebuf[BUFSIZE];
247 static char parabuf[BUFSIZE];
248 struct Channel *chptr;
5b96d9a6 249 rb_dlink_list *banlist;
212380e3
AC
250 const char *s;
251 char *t;
252 char *mbuf;
253 char *pbuf;
254 long mode_type;
255 int mlen;
256 int plen = 0;
257 int tlen;
258 int arglen;
259 int modecount = 0;
260 int needcap = NOCAPS;
261 int mems;
262 struct Client *fakesource_p;
263
264 if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2]))
265 return 0;
266
267 if((chptr = find_channel(parv[2])) == NULL)
268 return 0;
269
270 /* TS is higher, drop it. */
271 if(atol(parv[1]) > chptr->channelts)
272 return 0;
273
274 switch (parv[3][0])
275 {
276 case 'b':
277 banlist = &chptr->banlist;
278 mode_type = CHFL_BAN;
279 mems = ALL_MEMBERS;
280 break;
281
282 case 'e':
283 banlist = &chptr->exceptlist;
284 mode_type = CHFL_EXCEPTION;
285 needcap = CAP_EX;
286 mems = ONLY_CHANOPS;
287 break;
288
289 case 'I':
290 banlist = &chptr->invexlist;
291 mode_type = CHFL_INVEX;
292 needcap = CAP_IE;
293 mems = ONLY_CHANOPS;
294 break;
295
296 case 'q':
297 banlist = &chptr->quietlist;
298 mode_type = CHFL_QUIET;
299 mems = ALL_MEMBERS;
300 break;
301
302 /* maybe we should just blindly propagate this? */
303 default:
304 return 0;
305 }
306
307 parabuf[0] = '\0';
308 s = LOCAL_COPY(parv[4]);
309
310 /* Hide connecting server on netburst -- jilles */
311 if (ConfigServerHide.flatten_links && !HasSentEob(source_p))
312 fakesource_p = &me;
313 else
314 fakesource_p = source_p;
7cdb0a09 315 mlen = rb_sprintf(modebuf, ":%s MODE %s +", fakesource_p->name, chptr->chname);
212380e3
AC
316 mbuf = modebuf + mlen;
317 pbuf = parabuf;
318
319 while(*s == ' ')
320 s++;
321
322 /* next char isnt a space, point t to the next one */
323 if((t = strchr(s, ' ')) != NULL)
324 {
325 *t++ = '\0';
326
327 /* double spaces will break the parser */
328 while(*t == ' ')
329 t++;
330 }
331
332 /* couldve skipped spaces and got nothing.. */
333 while(!EmptyString(s))
334 {
335 /* ban with a leading ':' -- this will break the protocol */
336 if(*s == ':')
337 goto nextban;
338
339 tlen = strlen(s);
340
341 /* I dont even want to begin parsing this.. */
342 if(tlen > MODEBUFLEN)
343 break;
344
345 if(add_id(fakesource_p, chptr, s, banlist, mode_type))
346 {
347 /* this new one wont fit.. */
348 if(mlen + MAXMODEPARAMS + plen + tlen > BUFSIZE - 5 ||
349 modecount >= MAXMODEPARAMS)
350 {
351 *mbuf = '\0';
352 *(pbuf - 1) = '\0';
353 sendto_channel_local(mems, chptr, "%s %s", modebuf, parabuf);
354 sendto_server(client_p, chptr, needcap, CAP_TS6,
355 "%s %s", modebuf, parabuf);
356
357 mbuf = modebuf + mlen;
358 pbuf = parabuf;
359 plen = modecount = 0;
360 }
361
362 *mbuf++ = parv[3][0];
7cdb0a09 363 arglen = rb_sprintf(pbuf, "%s ", s);
212380e3
AC
364 pbuf += arglen;
365 plen += arglen;
366 modecount++;
367 }
368
369 nextban:
370 s = t;
371
372 if(s != NULL)
373 {
374 if((t = strchr(s, ' ')) != NULL)
375 {
376 *t++ = '\0';
377
378 while(*t == ' ')
379 t++;
380 }
381 }
382 }
383
384 if(modecount)
385 {
386 *mbuf = '\0';
387 *(pbuf - 1) = '\0';
388 sendto_channel_local(mems, chptr, "%s %s", modebuf, parabuf);
389 sendto_server(client_p, chptr, needcap, CAP_TS6, "%s %s", modebuf, parabuf);
390 }
391
392 sendto_server(client_p, chptr, CAP_TS6 | needcap, NOCAPS, ":%s BMASK %ld %s %s :%s",
393 source_p->id, (long) chptr->channelts, chptr->chname, parv[3], parv[4]);
394 return 0;
395}
396