]> jfr.im git - solanum.git/blame_incremental - ircd/chmode.c
m_stats: use oper:privs for /stats O
[solanum.git] / ircd / chmode.c
... / ...
CommitLineData
1/*
2 * charybdis: A slightly useful ircd.
3 * chmode.c: channel mode management
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 * Copyright (C) 2005-2006 charybdis development team
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 */
25
26#include "stdinc.h"
27#include "channel.h"
28#include "client.h"
29#include "hash.h"
30#include "hook.h"
31#include "match.h"
32#include "ircd.h"
33#include "numeric.h"
34#include "s_serv.h" /* captab */
35#include "s_user.h"
36#include "send.h"
37#include "whowas.h"
38#include "s_conf.h" /* ConfigFileEntry, ConfigChannel */
39#include "s_newconf.h"
40#include "logger.h"
41#include "chmode.h"
42#include "s_assert.h"
43#include "parse.h"
44
45/* bitmasks for error returns, so we send once per call */
46#define SM_ERR_NOTS 0x00000001 /* No TS on channel */
47#define SM_ERR_NOOPS 0x00000002 /* No chan ops */
48#define SM_ERR_UNKNOWN 0x00000004
49#define SM_ERR_RPL_C 0x00000008
50#define SM_ERR_RPL_B 0x00000010
51#define SM_ERR_RPL_E 0x00000020
52#define SM_ERR_NOTONCHANNEL 0x00000040 /* Not on channel */
53#define SM_ERR_RPL_I 0x00000100
54#define SM_ERR_RPL_D 0x00000200
55#define SM_ERR_NOPRIVS 0x00000400
56#define SM_ERR_RPL_Q 0x00000800
57#define SM_ERR_RPL_F 0x00001000
58#define SM_ERR_MLOCK 0x00002000
59
60#define MAXMODES_SIMPLE 46 /* a-zA-Z except bqeIov */
61
62static struct ChModeChange mode_changes[BUFSIZE];
63static int mode_count;
64static int mode_limit;
65static int mode_limit_simple;
66static int mask_pos;
67static int removed_mask_pos;
68
69char cflagsbuf[256];
70char cflagsmyinfo[256];
71
72int chmode_flags[256];
73
74extern int h_get_channel_access;
75
76/* OPTIMIZE ME! -- dwr */
77void
78construct_cflags_strings(void)
79{
80 int i;
81 char *ptr = cflagsbuf;
82 char *ptr2 = cflagsmyinfo;
83
84 *ptr = '\0';
85 *ptr2 = '\0';
86
87 for(i = 0; i < 256; i++)
88 {
89 if( !(chmode_table[i].set_func == chm_ban) &&
90 !(chmode_table[i].set_func == chm_forward) &&
91 !(chmode_table[i].set_func == chm_throttle) &&
92 !(chmode_table[i].set_func == chm_key) &&
93 !(chmode_table[i].set_func == chm_limit) &&
94 !(chmode_table[i].set_func == chm_op) &&
95 !(chmode_table[i].set_func == chm_voice))
96 {
97 chmode_flags[i] = chmode_table[i].mode_type;
98 }
99 else
100 {
101 chmode_flags[i] = 0;
102 }
103
104 switch (chmode_flags[i])
105 {
106 case MODE_FREETARGET:
107 case MODE_DISFORWARD:
108 if(ConfigChannel.use_forward)
109 *ptr++ = (char) i;
110 break;
111 default:
112 if(chmode_flags[i] != 0)
113 {
114 *ptr++ = (char) i;
115 }
116 }
117
118 /* Should we leave orphaned check here? -- dwr */
119 if(!(chmode_table[i].set_func == chm_nosuch) && !(chmode_table[i].set_func == chm_orphaned))
120 {
121 *ptr2++ = (char) i;
122 }
123 }
124
125 *ptr++ = '\0';
126 *ptr2++ = '\0';
127}
128
129/*
130 * find_umode_slot
131 *
132 * inputs - NONE
133 * outputs - an available cflag bitmask or
134 * 0 if no cflags are available
135 * side effects - NONE
136 */
137static unsigned int
138find_cflag_slot(void)
139{
140 unsigned int all_cflags = 0, my_cflag = 0, i;
141
142 for (i = 0; i < 256; i++)
143 all_cflags |= chmode_flags[i];
144
145 for (my_cflag = 1; my_cflag && (all_cflags & my_cflag);
146 my_cflag <<= 1);
147
148 return my_cflag;
149}
150
151unsigned int
152cflag_add(char c_, ChannelModeFunc function)
153{
154 int c = (unsigned char)c_;
155
156 if (chmode_table[c].set_func != chm_nosuch &&
157 chmode_table[c].set_func != chm_orphaned)
158 return 0;
159
160 if (chmode_table[c].set_func == chm_nosuch)
161 chmode_table[c].mode_type = find_cflag_slot();
162 if (chmode_table[c].mode_type == 0)
163 return 0;
164 chmode_table[c].set_func = function;
165 construct_cflags_strings();
166 return chmode_table[c].mode_type;
167}
168
169void
170cflag_orphan(char c_)
171{
172 int c = (unsigned char)c_;
173
174 s_assert(chmode_flags[c] != 0);
175 chmode_table[c].set_func = chm_orphaned;
176 construct_cflags_strings();
177}
178
179int
180get_channel_access(struct Client *source_p, struct Channel *chptr, struct membership *msptr, int dir, const char *modestr)
181{
182 hook_data_channel_approval moduledata;
183
184 if(!MyClient(source_p))
185 return CHFL_CHANOP;
186
187 moduledata.client = source_p;
188 moduledata.chptr = chptr;
189 moduledata.msptr = msptr;
190 moduledata.target = NULL;
191 moduledata.approved = (msptr != NULL && is_chanop(msptr)) ? CHFL_CHANOP : CHFL_PEON;
192 moduledata.dir = dir;
193 moduledata.modestr = modestr;
194
195 call_hook(h_get_channel_access, &moduledata);
196
197 return moduledata.approved;
198}
199
200/* allow_mode_change()
201 *
202 * Checks if mlock and chanops permit a mode change.
203 *
204 * inputs - client, channel, access level, errors pointer, mode char
205 * outputs - false on failure, true on success
206 * side effects - error message sent on failure
207 */
208static bool
209allow_mode_change(struct Client *source_p, struct Channel *chptr, int alevel,
210 int *errors, char c)
211{
212 /* If this mode char is locked, don't allow local users to change it. */
213 if (MyClient(source_p) && chptr->mode_lock && strchr(chptr->mode_lock, c))
214 {
215 if (!(*errors & SM_ERR_MLOCK))
216 sendto_one_numeric(source_p,
217 ERR_MLOCKRESTRICTED,
218 form_str(ERR_MLOCKRESTRICTED),
219 chptr->chname,
220 c,
221 chptr->mode_lock);
222 *errors |= SM_ERR_MLOCK;
223 return false;
224 }
225 if(alevel < CHFL_CHANOP)
226 {
227 if(!(*errors & SM_ERR_NOOPS))
228 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
229 me.name, source_p->name, chptr->chname);
230 *errors |= SM_ERR_NOOPS;
231 return false;
232 }
233 return true;
234}
235
236/* add_id()
237 *
238 * inputs - client, channel, id to add, type, forward
239 * outputs - false on failure, true on success
240 * side effects - given id is added to the appropriate list
241 */
242bool
243add_id(struct Client *source_p, struct Channel *chptr, const char *banid, const char *forward,
244 rb_dlink_list * list, long mode_type)
245{
246 struct Ban *actualBan;
247 static char who[USERHOST_REPLYLEN];
248 char *realban = LOCAL_COPY(banid);
249 rb_dlink_node *ptr;
250
251 /* dont let local clients overflow the banlist, or set redundant
252 * bans
253 */
254 if(MyClient(source_p))
255 {
256 if((rb_dlink_list_length(&chptr->banlist) + rb_dlink_list_length(&chptr->exceptlist) + rb_dlink_list_length(&chptr->invexlist) + rb_dlink_list_length(&chptr->quietlist)) >= (unsigned long)((chptr->mode.mode & MODE_EXLIMIT) ? ConfigChannel.max_bans_large : ConfigChannel.max_bans))
257 {
258 sendto_one(source_p, form_str(ERR_BANLISTFULL),
259 me.name, source_p->name, chptr->chname, realban);
260 return false;
261 }
262
263 RB_DLINK_FOREACH(ptr, list->head)
264 {
265 actualBan = ptr->data;
266 if(mask_match(actualBan->banstr, realban))
267 return false;
268 }
269 }
270 /* dont let remotes set duplicates */
271 else
272 {
273 RB_DLINK_FOREACH(ptr, list->head)
274 {
275 actualBan = ptr->data;
276 if(!irccmp(actualBan->banstr, realban))
277 return false;
278 }
279 }
280
281
282 if(IsPerson(source_p))
283 sprintf(who, "%s!%s@%s", source_p->name, source_p->username, source_p->host);
284 else
285 rb_strlcpy(who, source_p->name, sizeof(who));
286
287 actualBan = allocate_ban(realban, who, forward);
288 actualBan->when = rb_current_time();
289
290 rb_dlinkAdd(actualBan, &actualBan->node, list);
291
292 /* invalidate the can_send() cache */
293 if(mode_type == CHFL_BAN || mode_type == CHFL_QUIET || mode_type == CHFL_EXCEPTION)
294 chptr->bants = rb_current_time();
295
296 return true;
297}
298
299/* del_id()
300 *
301 * inputs - channel, id to remove, type
302 * outputs - pointer to ban that was removed, if any
303 * side effects - given id is removed from the appropriate list and returned
304 */
305struct Ban *
306del_id(struct Channel *chptr, const char *banid, rb_dlink_list * list, long mode_type)
307{
308 rb_dlink_node *ptr;
309 struct Ban *banptr;
310
311 if(EmptyString(banid))
312 return NULL;
313
314 RB_DLINK_FOREACH(ptr, list->head)
315 {
316 banptr = ptr->data;
317
318 if(irccmp(banid, banptr->banstr) == 0)
319 {
320 rb_dlinkDelete(&banptr->node, list);
321
322 /* invalidate the can_send() cache */
323 if(mode_type == CHFL_BAN || mode_type == CHFL_QUIET || mode_type == CHFL_EXCEPTION)
324 chptr->bants = rb_current_time();
325
326 return banptr;
327 }
328 }
329
330 return NULL;
331}
332
333/* check_string()
334 *
335 * input - string to check
336 * output - pointer to 'fixed' string, or "*" if empty
337 * side effects - any white space found becomes \0
338 */
339static char *
340check_string(char *s)
341{
342 char *str = s;
343 static char splat[] = "*";
344 if(!(s && *s))
345 return splat;
346
347 for(; *s; ++s)
348 {
349 if(IsSpace(*s))
350 {
351 *s = '\0';
352 break;
353 }
354 }
355 return str;
356}
357
358/* pretty_mask()
359 *
360 * inputs - mask to pretty
361 * outputs - better version of the mask
362 * side effects - mask is chopped to limits, and transformed:
363 * x!y@z => x!y@z
364 * y@z => *!y@z
365 * x!y => x!y@*
366 * x => x!*@*
367 * z.d => *!*@z.d
368 */
369static char *
370pretty_mask(const char *idmask)
371{
372 static char mask_buf[BUFSIZE];
373 int old_mask_pos;
374 const char *nick, *user, *host, *forward = NULL;
375 char *t, *at, *ex;
376 int nl, ul, hl, fl;
377 char *mask;
378 size_t masklen;
379
380 mask = LOCAL_COPY(idmask);
381 mask = check_string(mask);
382 collapse(mask);
383 masklen = strlen(mask);
384
385 nick = user = host = "*";
386 nl = ul = hl = 1;
387 fl = 0;
388
389 if((size_t) BUFSIZE - mask_pos < masklen + 5)
390 return NULL;
391
392 old_mask_pos = mask_pos;
393
394 if (*mask == '$')
395 {
396 memcpy(mask_buf + mask_pos, mask, masklen + 1);
397 mask_pos += masklen + 1;
398 t = mask_buf + old_mask_pos + 1;
399 if (*t == '!')
400 *t = '~';
401 if (*t == '~')
402 t++;
403 *t = irctolower(*t);
404 return mask_buf + old_mask_pos;
405 }
406
407 at = ex = NULL;
408 if((t = memchr(mask, '@', masklen)) != NULL)
409 {
410 at = t;
411 t++;
412 if(*t != '\0')
413 host = t, hl = strlen(t);
414
415 if((t = memchr(mask, '!', at - mask)) != NULL)
416 {
417 ex = t;
418 t++;
419 if(at != t)
420 user = t, ul = at - t;
421 if(ex != mask)
422 nick = mask, nl = ex - mask;
423 }
424 else
425 {
426 if(at != mask)
427 user = mask, ul = at - mask;
428 }
429
430 if((t = memchr(host, '!', hl)) != NULL ||
431 (t = memchr(host, '$', hl)) != NULL)
432 {
433 t++;
434 if (host + hl != t)
435 forward = t, fl = host + hl - t;
436 hl = t - 1 - host;
437 }
438 }
439 else if((t = memchr(mask, '!', masklen)) != NULL)
440 {
441 ex = t;
442 t++;
443 if(ex != mask)
444 nick = mask, nl = ex - mask;
445 if(*t != '\0')
446 user = t, ul = strlen(t);
447 }
448 else if(memchr(mask, '.', masklen) != NULL ||
449 memchr(mask, ':', masklen) != NULL)
450 {
451 host = mask, hl = masklen;
452 }
453 else
454 {
455 if(masklen > 0)
456 nick = mask, nl = masklen;
457 }
458
459 /* truncate values to max lengths */
460 if(nl > NICKLEN - 1)
461 nl = NICKLEN - 1;
462 if(ul > USERLEN)
463 ul = USERLEN;
464 if(hl > HOSTLEN)
465 hl = HOSTLEN;
466 if(fl > CHANNELLEN)
467 fl = CHANNELLEN;
468
469 memcpy(mask_buf + mask_pos, nick, nl), mask_pos += nl;
470 mask_buf[mask_pos++] = '!';
471 memcpy(mask_buf + mask_pos, user, ul), mask_pos += ul;
472 mask_buf[mask_pos++] = '@';
473 memcpy(mask_buf + mask_pos, host, hl), mask_pos += hl;
474 if (forward) {
475 mask_buf[mask_pos++] = '$';
476 memcpy(mask_buf + mask_pos, forward, fl), mask_pos += fl;
477 }
478 mask_buf[mask_pos++] = '\0';
479
480 return mask_buf + old_mask_pos;
481}
482
483/* check_forward()
484 *
485 * input - client, channel to set mode on, target channel name
486 * output - true if forwarding should be allowed
487 * side effects - numeric sent if not allowed
488 */
489static bool
490check_forward(struct Client *source_p, struct Channel *chptr,
491 const char *forward)
492{
493 struct Channel *targptr = NULL;
494 struct membership *msptr;
495
496 if(!check_channel_name(forward) ||
497 (MyClient(source_p) && (strlen(forward) > LOC_CHANNELLEN || hash_find_resv(forward))))
498 {
499 sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), forward);
500 return false;
501 }
502 /* don't forward to inconsistent target -- jilles */
503 if(chptr->chname[0] == '#' && forward[0] == '&')
504 {
505 sendto_one_numeric(source_p, ERR_BADCHANNAME,
506 form_str(ERR_BADCHANNAME), forward);
507 return false;
508 }
509 if(MyClient(source_p) && (targptr = find_channel(forward)) == NULL)
510 {
511 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
512 form_str(ERR_NOSUCHCHANNEL), forward);
513 return false;
514 }
515 if(MyClient(source_p) && !(targptr->mode.mode & MODE_FREETARGET))
516 {
517 if((msptr = find_channel_membership(targptr, source_p)) == NULL ||
518 get_channel_access(source_p, targptr, msptr, MODE_QUERY, NULL) < CHFL_CHANOP)
519 {
520 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
521 me.name, source_p->name, targptr->chname);
522 return false;
523 }
524 }
525 return true;
526}
527
528/* fix_key()
529 *
530 * input - key to fix
531 * output - the same key, fixed
532 * side effects - anything below ascii 13 is discarded, ':' discarded,
533 * high ascii is dropped to lower half of ascii table
534 */
535static char *
536fix_key(char *arg)
537{
538 unsigned char *s, *t, c;
539
540 for(s = t = (unsigned char *) arg; (c = *s); s++)
541 {
542 c &= 0x7f;
543 if(c != ':' && c != ',' && c > ' ')
544 *t++ = c;
545 }
546
547 *t = '\0';
548 return arg;
549}
550
551/* fix_key_remote()
552 *
553 * input - key to fix
554 * ouput - the same key, fixed
555 * side effects - high ascii dropped to lower half of table,
556 * CR/LF/':' are dropped
557 */
558static char *
559fix_key_remote(char *arg)
560{
561 unsigned char *s, *t, c;
562
563 for(s = t = (unsigned char *) arg; (c = *s); s++)
564 {
565 c &= 0x7f;
566 if((c != 0x0a) && (c != ':') && (c != ',') && (c != 0x0d) && (c != ' '))
567 *t++ = c;
568 }
569
570 *t = '\0';
571 return arg;
572}
573
574/* chm_*()
575 *
576 * The handlers for each specific mode.
577 */
578void
579chm_nosuch(struct Client *source_p, struct Channel *chptr,
580 int alevel, int parc, int *parn,
581 const char **parv, int *errors, int dir, char c, long mode_type)
582{
583 if(*errors & SM_ERR_UNKNOWN)
584 return;
585 *errors |= SM_ERR_UNKNOWN;
586 sendto_one(source_p, form_str(ERR_UNKNOWNMODE), me.name, source_p->name, c);
587}
588
589void
590chm_simple(struct Client *source_p, struct Channel *chptr,
591 int alevel, int parc, int *parn,
592 const char **parv, int *errors, int dir, char c, long mode_type)
593{
594 if(!allow_mode_change(source_p, chptr, alevel, errors, c))
595 return;
596
597 if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
598 return;
599
600 /* setting + */
601 if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type))
602 {
603 /* if +f is disabled, ignore an attempt to set +QF locally */
604 if(!ConfigChannel.use_forward && MyClient(source_p) &&
605 (c == 'Q' || c == 'F'))
606 return;
607
608 chptr->mode.mode |= mode_type;
609
610 mode_changes[mode_count].letter = c;
611 mode_changes[mode_count].dir = MODE_ADD;
612 mode_changes[mode_count].id = NULL;
613 mode_changes[mode_count].mems = ALL_MEMBERS;
614 mode_changes[mode_count++].arg = NULL;
615 }
616 else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type))
617 {
618 chptr->mode.mode &= ~mode_type;
619
620 mode_changes[mode_count].letter = c;
621 mode_changes[mode_count].dir = MODE_DEL;
622 mode_changes[mode_count].mems = ALL_MEMBERS;
623 mode_changes[mode_count].id = NULL;
624 mode_changes[mode_count++].arg = NULL;
625 }
626}
627
628void
629chm_orphaned(struct Client *source_p, struct Channel *chptr,
630 int alevel, int parc, int *parn,
631 const char **parv, int *errors, int dir, char c, long mode_type)
632{
633 if(MyClient(source_p))
634 return;
635
636 if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type))
637 {
638 chptr->mode.mode |= mode_type;
639
640 mode_changes[mode_count].letter = c;
641 mode_changes[mode_count].dir = MODE_ADD;
642 mode_changes[mode_count].id = NULL;
643 mode_changes[mode_count].mems = ALL_MEMBERS;
644 mode_changes[mode_count++].arg = NULL;
645 }
646 else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type))
647 {
648 chptr->mode.mode &= ~mode_type;
649
650 mode_changes[mode_count].letter = c;
651 mode_changes[mode_count].dir = MODE_DEL;
652 mode_changes[mode_count].mems = ALL_MEMBERS;
653 mode_changes[mode_count].id = NULL;
654 mode_changes[mode_count++].arg = NULL;
655 }
656}
657
658void
659chm_hidden(struct Client *source_p, struct Channel *chptr,
660 int alevel, int parc, int *parn,
661 const char **parv, int *errors, int dir, char c, long mode_type)
662{
663 if(!IsOperGeneral(source_p) && !IsServer(source_p))
664 {
665 if(!(*errors & SM_ERR_NOPRIVS))
666 sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES));
667 *errors |= SM_ERR_NOPRIVS;
668 return;
669 }
670 if(MyClient(source_p) && !IsOperAdmin(source_p))
671 {
672 if(!(*errors & SM_ERR_NOPRIVS))
673 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
674 source_p->name, "admin");
675 *errors |= SM_ERR_NOPRIVS;
676 return;
677 }
678
679 if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
680 return;
681
682 /* setting + */
683 if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type))
684 {
685 chptr->mode.mode |= mode_type;
686
687 mode_changes[mode_count].letter = c;
688 mode_changes[mode_count].dir = MODE_ADD;
689 mode_changes[mode_count].id = NULL;
690 mode_changes[mode_count].mems = ONLY_OPERS;
691 mode_changes[mode_count++].arg = NULL;
692 }
693 else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type))
694 {
695 chptr->mode.mode &= ~mode_type;
696
697 mode_changes[mode_count].letter = c;
698 mode_changes[mode_count].dir = MODE_DEL;
699 mode_changes[mode_count].mems = ONLY_OPERS;
700 mode_changes[mode_count].id = NULL;
701 mode_changes[mode_count++].arg = NULL;
702 }
703}
704
705void
706chm_staff(struct Client *source_p, struct Channel *chptr,
707 int alevel, int parc, int *parn,
708 const char **parv, int *errors, int dir, char c, long mode_type)
709{
710 if(!IsOper(source_p) && !IsServer(source_p))
711 {
712 if(!(*errors & SM_ERR_NOPRIVS))
713 sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES));
714 *errors |= SM_ERR_NOPRIVS;
715 return;
716 }
717 if(MyClient(source_p) && !HasPrivilege(source_p, "oper:cmodes"))
718 {
719 if(!(*errors & SM_ERR_NOPRIVS))
720 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
721 source_p->name, "cmodes");
722 *errors |= SM_ERR_NOPRIVS;
723 return;
724 }
725
726 if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
727 return;
728
729 /* setting + */
730 if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type))
731 {
732 chptr->mode.mode |= mode_type;
733
734 mode_changes[mode_count].letter = c;
735 mode_changes[mode_count].dir = MODE_ADD;
736 mode_changes[mode_count].id = NULL;
737 mode_changes[mode_count].mems = ALL_MEMBERS;
738 mode_changes[mode_count++].arg = NULL;
739 }
740 else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type))
741 {
742 chptr->mode.mode &= ~mode_type;
743
744 mode_changes[mode_count].letter = c;
745 mode_changes[mode_count].dir = MODE_DEL;
746 mode_changes[mode_count].mems = ALL_MEMBERS;
747 mode_changes[mode_count].id = NULL;
748 mode_changes[mode_count++].arg = NULL;
749 }
750}
751
752void
753chm_ban(struct Client *source_p, struct Channel *chptr,
754 int alevel, int parc, int *parn,
755 const char **parv, int *errors, int dir, char c, long mode_type)
756{
757 const char *mask, *raw_mask;
758 char *forward;
759 rb_dlink_list *list;
760 rb_dlink_node *ptr;
761 struct Ban *banptr;
762 int errorval;
763 const char *rpl_list_p;
764 const char *rpl_endlist_p;
765 int mems;
766
767 switch (mode_type)
768 {
769 case CHFL_BAN:
770 list = &chptr->banlist;
771 errorval = SM_ERR_RPL_B;
772 rpl_list_p = form_str(RPL_BANLIST);
773 rpl_endlist_p = form_str(RPL_ENDOFBANLIST);
774 mems = ALL_MEMBERS;
775 break;
776
777 case CHFL_EXCEPTION:
778 /* if +e is disabled, allow all but +e locally */
779 if(!ConfigChannel.use_except && MyClient(source_p) &&
780 ((dir == MODE_ADD) && (parc > *parn)))
781 return;
782
783 list = &chptr->exceptlist;
784 errorval = SM_ERR_RPL_E;
785 rpl_list_p = form_str(RPL_EXCEPTLIST);
786 rpl_endlist_p = form_str(RPL_ENDOFEXCEPTLIST);
787
788 if(ConfigChannel.use_except || (dir == MODE_DEL))
789 mems = ONLY_CHANOPS;
790 else
791 mems = ONLY_SERVERS;
792 break;
793
794 case CHFL_INVEX:
795 /* if +I is disabled, allow all but +I locally */
796 if(!ConfigChannel.use_invex && MyClient(source_p) &&
797 (dir == MODE_ADD) && (parc > *parn))
798 return;
799
800 list = &chptr->invexlist;
801 errorval = SM_ERR_RPL_I;
802 rpl_list_p = form_str(RPL_INVITELIST);
803 rpl_endlist_p = form_str(RPL_ENDOFINVITELIST);
804
805 if(ConfigChannel.use_invex || (dir == MODE_DEL))
806 mems = ONLY_CHANOPS;
807 else
808 mems = ONLY_SERVERS;
809 break;
810
811 case CHFL_QUIET:
812 list = &chptr->quietlist;
813 errorval = SM_ERR_RPL_Q;
814 rpl_list_p = form_str(RPL_QUIETLIST);
815 rpl_endlist_p = form_str(RPL_ENDOFQUIETLIST);
816 mems = ALL_MEMBERS;
817 break;
818
819 default:
820 sendto_realops_snomask(SNO_GENERAL, L_ALL, "chm_ban() called with unknown type!");
821 return;
822 }
823
824 if(dir == 0 || parc <= *parn)
825 {
826 if((*errors & errorval) != 0)
827 return;
828 *errors |= errorval;
829
830 /* non-ops cant see +eI lists.. */
831 /* note that this is still permitted if +e/+I are mlocked. */
832 if(alevel < CHFL_CHANOP && mode_type != CHFL_BAN &&
833 mode_type != CHFL_QUIET)
834 {
835 if(!(*errors & SM_ERR_NOOPS))
836 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
837 me.name, source_p->name, chptr->chname);
838 *errors |= SM_ERR_NOOPS;
839 return;
840 }
841
842 RB_DLINK_FOREACH(ptr, list->head)
843 {
844 char buf[BANLEN];
845 banptr = ptr->data;
846 if(banptr->forward)
847 snprintf(buf, sizeof(buf), "%s$%s", banptr->banstr, banptr->forward);
848 else
849 rb_strlcpy(buf, banptr->banstr, sizeof(buf));
850
851 sendto_one(source_p, rpl_list_p,
852 me.name, source_p->name, chptr->chname,
853 buf, banptr->who, banptr->when);
854 }
855 sendto_one(source_p, rpl_endlist_p, me.name, source_p->name, chptr->chname);
856 return;
857 }
858
859 if(!allow_mode_change(source_p, chptr, alevel, errors, c))
860 return;
861
862
863 if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
864 return;
865
866 raw_mask = parv[(*parn)];
867 (*parn)++;
868
869 /* empty ban, or starts with ':' which messes up s2s, ignore it */
870 if(EmptyString(raw_mask) || *raw_mask == ':')
871 return;
872
873 if(!MyClient(source_p))
874 {
875 if(strchr(raw_mask, ' '))
876 return;
877
878 mask = raw_mask;
879 }
880 else
881 mask = pretty_mask(raw_mask);
882
883 /* we'd have problems parsing this, hyb6 does it too
884 * also make sure it will always fit on a line with channel
885 * name etc.
886 */
887 if(strlen(mask) > MIN(BANLEN, MODEBUFLEN - 5))
888 {
889 sendto_one_numeric(source_p, ERR_INVALIDBAN,
890 form_str(ERR_INVALIDBAN),
891 chptr->chname, c, raw_mask);
892 return;
893 }
894
895 /* Look for a $ after the first character.
896 * As the first character, it marks an extban; afterwards
897 * it delimits a forward channel.
898 */
899 if ((forward = strchr(mask+1, '$')) != NULL)
900 {
901 *forward++ = '\0';
902 if (*forward == '\0')
903 forward = NULL;
904 }
905
906 /* if we're adding a NEW id */
907 if(dir == MODE_ADD)
908 {
909 if (*mask == '$' && MyClient(source_p))
910 {
911 if (!valid_extban(mask, source_p, chptr, mode_type))
912 {
913 sendto_one_numeric(source_p, ERR_INVALIDBAN,
914 form_str(ERR_INVALIDBAN),
915 chptr->chname, c, raw_mask);
916 return;
917 }
918 }
919
920 /* For compatibility, only check the forward channel from
921 * local clients. Accept any forward channel from servers.
922 */
923 if(forward != NULL && MyClient(source_p))
924 {
925 /* For simplicity and future flexibility, do not
926 * allow '$' in forwarding targets.
927 */
928 if(!ConfigChannel.use_forward ||
929 strchr(forward, '$') != NULL)
930 {
931 sendto_one_numeric(source_p, ERR_INVALIDBAN,
932 form_str(ERR_INVALIDBAN),
933 chptr->chname, c, raw_mask);
934 return;
935 }
936 /* check_forward() sends its own error message */
937 if(!check_forward(source_p, chptr, forward))
938 return;
939 /* Forwards only make sense for bans. */
940 if(mode_type != CHFL_BAN)
941 {
942 sendto_one_numeric(source_p, ERR_INVALIDBAN,
943 form_str(ERR_INVALIDBAN),
944 chptr->chname, c, raw_mask);
945 return;
946 }
947 }
948
949 /* dont allow local clients to overflow the banlist, dont
950 * let remote servers set duplicate bans
951 */
952 if(!add_id(source_p, chptr, mask, forward, list, mode_type))
953 return;
954
955 if(forward)
956 forward[-1]= '$';
957
958 mode_changes[mode_count].letter = c;
959 mode_changes[mode_count].dir = MODE_ADD;
960 mode_changes[mode_count].mems = mems;
961 mode_changes[mode_count].id = NULL;
962 mode_changes[mode_count++].arg = mask;
963 }
964 else if(dir == MODE_DEL)
965 {
966 struct Ban *removed;
967 static char buf[BANLEN * MAXMODEPARAMS];
968 int old_removed_mask_pos = removed_mask_pos;
969 if((removed = del_id(chptr, mask, list, mode_type)) == NULL)
970 {
971 /* mask isn't a valid ban, check raw_mask */
972 if((removed = del_id(chptr, raw_mask, list, mode_type)) != NULL)
973 mask = raw_mask;
974 }
975
976 if(removed && removed->forward)
977 removed_mask_pos += snprintf(buf + old_removed_mask_pos, sizeof(buf), "%s$%s", removed->banstr, removed->forward) + 1;
978 else
979 removed_mask_pos += rb_strlcpy(buf + old_removed_mask_pos, mask, sizeof(buf)) + 1;
980 if(removed)
981 {
982 free_ban(removed);
983 removed = NULL;
984 }
985
986 mode_changes[mode_count].letter = c;
987 mode_changes[mode_count].dir = MODE_DEL;
988 mode_changes[mode_count].mems = mems;
989 mode_changes[mode_count].id = NULL;
990 mode_changes[mode_count++].arg = buf + old_removed_mask_pos;
991 }
992}
993
994void
995chm_op(struct Client *source_p, struct Channel *chptr,
996 int alevel, int parc, int *parn,
997 const char **parv, int *errors, int dir, char c, long mode_type)
998{
999 struct membership *mstptr;
1000 const char *opnick;
1001 struct Client *targ_p;
1002
1003 if(!allow_mode_change(source_p, chptr, alevel, errors, c))
1004 return;
1005
1006 if((dir == MODE_QUERY) || (parc <= *parn))
1007 return;
1008
1009 opnick = parv[(*parn)];
1010 (*parn)++;
1011
1012 /* empty nick */
1013 if(EmptyString(opnick))
1014 {
1015 sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*");
1016 return;
1017 }
1018
1019 if((targ_p = find_chasing(source_p, opnick, NULL)) == NULL)
1020 {
1021 return;
1022 }
1023
1024 mstptr = find_channel_membership(chptr, targ_p);
1025
1026 if(mstptr == NULL)
1027 {
1028 if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p))
1029 sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL,
1030 form_str(ERR_USERNOTINCHANNEL), opnick, chptr->chname);
1031 *errors |= SM_ERR_NOTONCHANNEL;
1032 return;
1033 }
1034
1035 if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
1036 return;
1037
1038 if(dir == MODE_ADD)
1039 {
1040 if(targ_p == source_p && mstptr->flags & CHFL_CHANOP)
1041 return;
1042
1043 mode_changes[mode_count].letter = c;
1044 mode_changes[mode_count].dir = MODE_ADD;
1045 mode_changes[mode_count].mems = ALL_MEMBERS;
1046 mode_changes[mode_count].id = targ_p->id;
1047 mode_changes[mode_count++].arg = targ_p->name;
1048
1049 mstptr->flags |= CHFL_CHANOP;
1050 }
1051 else
1052 {
1053 if(MyClient(source_p) && IsService(targ_p))
1054 {
1055 sendto_one(source_p, form_str(ERR_ISCHANSERVICE),
1056 me.name, source_p->name, targ_p->name, chptr->chname);
1057 return;
1058 }
1059
1060 mode_changes[mode_count].letter = c;
1061 mode_changes[mode_count].dir = MODE_DEL;
1062 mode_changes[mode_count].mems = ALL_MEMBERS;
1063 mode_changes[mode_count].id = targ_p->id;
1064 mode_changes[mode_count++].arg = targ_p->name;
1065
1066 mstptr->flags &= ~CHFL_CHANOP;
1067 }
1068}
1069
1070void
1071chm_voice(struct Client *source_p, struct Channel *chptr,
1072 int alevel, int parc, int *parn,
1073 const char **parv, int *errors, int dir, char c, long mode_type)
1074{
1075 struct membership *mstptr;
1076 const char *opnick;
1077 struct Client *targ_p;
1078
1079 if(!allow_mode_change(source_p, chptr, alevel, errors, c))
1080 return;
1081
1082 if((dir == MODE_QUERY) || parc <= *parn)
1083 return;
1084
1085 opnick = parv[(*parn)];
1086 (*parn)++;
1087
1088 /* empty nick */
1089 if(EmptyString(opnick))
1090 {
1091 sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*");
1092 return;
1093 }
1094
1095 if((targ_p = find_chasing(source_p, opnick, NULL)) == NULL)
1096 {
1097 return;
1098 }
1099
1100 mstptr = find_channel_membership(chptr, targ_p);
1101
1102 if(mstptr == NULL)
1103 {
1104 if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p))
1105 sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL,
1106 form_str(ERR_USERNOTINCHANNEL), opnick, chptr->chname);
1107 *errors |= SM_ERR_NOTONCHANNEL;
1108 return;
1109 }
1110
1111 if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
1112 return;
1113
1114 if(dir == MODE_ADD)
1115 {
1116 mode_changes[mode_count].letter = c;
1117 mode_changes[mode_count].dir = MODE_ADD;
1118 mode_changes[mode_count].mems = ALL_MEMBERS;
1119 mode_changes[mode_count].id = targ_p->id;
1120 mode_changes[mode_count++].arg = targ_p->name;
1121
1122 mstptr->flags |= CHFL_VOICE;
1123 }
1124 else
1125 {
1126 mode_changes[mode_count].letter = 'v';
1127 mode_changes[mode_count].dir = MODE_DEL;
1128 mode_changes[mode_count].mems = ALL_MEMBERS;
1129 mode_changes[mode_count].id = targ_p->id;
1130 mode_changes[mode_count++].arg = targ_p->name;
1131
1132 mstptr->flags &= ~CHFL_VOICE;
1133 }
1134}
1135
1136void
1137chm_limit(struct Client *source_p, struct Channel *chptr,
1138 int alevel, int parc, int *parn,
1139 const char **parv, int *errors, int dir, char c, long mode_type)
1140{
1141 const char *lstr;
1142 static char limitstr[30];
1143 int limit;
1144
1145 if(!allow_mode_change(source_p, chptr, alevel, errors, c))
1146 return;
1147
1148 if(dir == MODE_QUERY)
1149 return;
1150
1151 if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
1152 return;
1153
1154 if((dir == MODE_ADD) && parc > *parn)
1155 {
1156 lstr = parv[(*parn)];
1157 (*parn)++;
1158
1159 if(EmptyString(lstr) || (limit = atoi(lstr)) <= 0)
1160 return;
1161
1162 sprintf(limitstr, "%d", limit);
1163
1164 mode_changes[mode_count].letter = c;
1165 mode_changes[mode_count].dir = MODE_ADD;
1166 mode_changes[mode_count].mems = ALL_MEMBERS;
1167 mode_changes[mode_count].id = NULL;
1168 mode_changes[mode_count++].arg = limitstr;
1169
1170 chptr->mode.limit = limit;
1171 }
1172 else if(dir == MODE_DEL)
1173 {
1174 if(!chptr->mode.limit)
1175 return;
1176
1177 chptr->mode.limit = 0;
1178
1179 mode_changes[mode_count].letter = c;
1180 mode_changes[mode_count].dir = MODE_DEL;
1181 mode_changes[mode_count].mems = ALL_MEMBERS;
1182 mode_changes[mode_count].id = NULL;
1183 mode_changes[mode_count++].arg = NULL;
1184 }
1185}
1186
1187void
1188chm_throttle(struct Client *source_p, struct Channel *chptr,
1189 int alevel, int parc, int *parn,
1190 const char **parv, int *errors, int dir, char c, long mode_type)
1191{
1192 int joins = 0, timeslice = 0;
1193
1194 if(!allow_mode_change(source_p, chptr, alevel, errors, c))
1195 return;
1196
1197 if(dir == MODE_QUERY)
1198 return;
1199
1200 if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
1201 return;
1202
1203 if((dir == MODE_ADD) && parc > *parn)
1204 {
1205 if (sscanf(parv[(*parn)], "%d:%d", &joins, &timeslice) < 2)
1206 return;
1207
1208 if(joins <= 0 || timeslice <= 0)
1209 return;
1210
1211 mode_changes[mode_count].letter = c;
1212 mode_changes[mode_count].dir = MODE_ADD;
1213 mode_changes[mode_count].mems = ALL_MEMBERS;
1214 mode_changes[mode_count].id = NULL;
1215 mode_changes[mode_count++].arg = parv[(*parn)];
1216
1217 (*parn)++;
1218
1219 chptr->mode.join_num = joins;
1220 chptr->mode.join_time = timeslice;
1221 }
1222 else if(dir == MODE_DEL)
1223 {
1224 if(!chptr->mode.join_num)
1225 return;
1226
1227 chptr->mode.join_num = 0;
1228 chptr->mode.join_time = 0;
1229 chptr->join_count = 0;
1230 chptr->join_delta = 0;
1231
1232 mode_changes[mode_count].letter = c;
1233 mode_changes[mode_count].dir = MODE_DEL;
1234 mode_changes[mode_count].mems = ALL_MEMBERS;
1235 mode_changes[mode_count].id = NULL;
1236 mode_changes[mode_count++].arg = NULL;
1237 }
1238}
1239
1240void
1241chm_forward(struct Client *source_p, struct Channel *chptr,
1242 int alevel, int parc, int *parn,
1243 const char **parv, int *errors, int dir, char c, long mode_type)
1244{
1245 const char *forward;
1246
1247 /* if +f is disabled, ignore local attempts to set it */
1248 if(!ConfigChannel.use_forward && MyClient(source_p) &&
1249 (dir == MODE_ADD) && (parc > *parn))
1250 return;
1251
1252 if(dir == MODE_QUERY || (dir == MODE_ADD && parc <= *parn))
1253 {
1254 if (!(*errors & SM_ERR_RPL_F))
1255 {
1256 if (*chptr->mode.forward == '\0')
1257 sendto_one_notice(source_p, ":%s has no forward channel", chptr->chname);
1258 else
1259 sendto_one_notice(source_p, ":%s forward channel is %s", chptr->chname, chptr->mode.forward);
1260 *errors |= SM_ERR_RPL_F;
1261 }
1262 return;
1263 }
1264
1265#ifndef FORWARD_OPERONLY
1266 if(!allow_mode_change(source_p, chptr, alevel, errors, c))
1267 return;
1268#else
1269 if(!IsOperGeneral(source_p) && !IsServer(source_p))
1270 {
1271 if(!(*errors & SM_ERR_NOPRIVS))
1272 sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES));
1273 *errors |= SM_ERR_NOPRIVS;
1274 return;
1275 }
1276#endif
1277
1278 if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
1279 return;
1280
1281 if(dir == MODE_ADD && parc > *parn)
1282 {
1283 forward = parv[(*parn)];
1284 (*parn)++;
1285
1286 if(EmptyString(forward))
1287 return;
1288
1289 if(!check_forward(source_p, chptr, forward))
1290 return;
1291
1292 rb_strlcpy(chptr->mode.forward, forward, sizeof(chptr->mode.forward));
1293
1294 mode_changes[mode_count].letter = c;
1295 mode_changes[mode_count].dir = MODE_ADD;
1296 mode_changes[mode_count].mems =
1297 ConfigChannel.use_forward ? ALL_MEMBERS : ONLY_SERVERS;
1298 mode_changes[mode_count].id = NULL;
1299 mode_changes[mode_count++].arg = forward;
1300 }
1301 else if(dir == MODE_DEL)
1302 {
1303 if(!(*chptr->mode.forward))
1304 return;
1305
1306 *chptr->mode.forward = '\0';
1307
1308 mode_changes[mode_count].letter = c;
1309 mode_changes[mode_count].dir = MODE_DEL;
1310 mode_changes[mode_count].mems = ALL_MEMBERS;
1311 mode_changes[mode_count].id = NULL;
1312 mode_changes[mode_count++].arg = NULL;
1313 }
1314}
1315
1316void
1317chm_key(struct Client *source_p, struct Channel *chptr,
1318 int alevel, int parc, int *parn,
1319 const char **parv, int *errors, int dir, char c, long mode_type)
1320{
1321 char *key;
1322
1323 if(!allow_mode_change(source_p, chptr, alevel, errors, c))
1324 return;
1325
1326 if(dir == MODE_QUERY)
1327 return;
1328
1329 if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
1330 return;
1331
1332 if((dir == MODE_ADD) && parc > *parn)
1333 {
1334 key = LOCAL_COPY(parv[(*parn)]);
1335 (*parn)++;
1336
1337 if(MyClient(source_p))
1338 fix_key(key);
1339 else
1340 fix_key_remote(key);
1341
1342 if(EmptyString(key))
1343 return;
1344
1345 s_assert(key[0] != ' ');
1346 rb_strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key));
1347
1348 mode_changes[mode_count].letter = c;
1349 mode_changes[mode_count].dir = MODE_ADD;
1350 mode_changes[mode_count].mems = ALL_MEMBERS;
1351 mode_changes[mode_count].id = NULL;
1352 mode_changes[mode_count++].arg = chptr->mode.key;
1353 }
1354 else if(dir == MODE_DEL)
1355 {
1356 static char splat[] = "*";
1357 int i;
1358
1359 if(parc > *parn)
1360 (*parn)++;
1361
1362 if(!(*chptr->mode.key))
1363 return;
1364
1365 /* hack time. when we get a +k-k mode, the +k arg is
1366 * chptr->mode.key, which the -k sets to \0, so hunt for a
1367 * +k when we get a -k, and set the arg to splat. --anfl
1368 */
1369 for(i = 0; i < mode_count; i++)
1370 {
1371 if(mode_changes[i].letter == 'k' && mode_changes[i].dir == MODE_ADD)
1372 mode_changes[i].arg = splat;
1373 }
1374
1375 *chptr->mode.key = 0;
1376
1377 mode_changes[mode_count].letter = c;
1378 mode_changes[mode_count].dir = MODE_DEL;
1379 mode_changes[mode_count].mems = ALL_MEMBERS;
1380 mode_changes[mode_count].id = NULL;
1381 mode_changes[mode_count++].arg = "*";
1382 }
1383}
1384
1385/* *INDENT-OFF* */
1386struct ChannelMode chmode_table[256] =
1387{
1388 {chm_nosuch, 0 }, /* 0x00 */
1389 {chm_nosuch, 0 }, /* 0x01 */
1390 {chm_nosuch, 0 }, /* 0x02 */
1391 {chm_nosuch, 0 }, /* 0x03 */
1392 {chm_nosuch, 0 }, /* 0x04 */
1393 {chm_nosuch, 0 }, /* 0x05 */
1394 {chm_nosuch, 0 }, /* 0x06 */
1395 {chm_nosuch, 0 }, /* 0x07 */
1396 {chm_nosuch, 0 }, /* 0x08 */
1397 {chm_nosuch, 0 }, /* 0x09 */
1398 {chm_nosuch, 0 }, /* 0x0a */
1399 {chm_nosuch, 0 }, /* 0x0b */
1400 {chm_nosuch, 0 }, /* 0x0c */
1401 {chm_nosuch, 0 }, /* 0x0d */
1402 {chm_nosuch, 0 }, /* 0x0e */
1403 {chm_nosuch, 0 }, /* 0x0f */
1404 {chm_nosuch, 0 }, /* 0x10 */
1405 {chm_nosuch, 0 }, /* 0x11 */
1406 {chm_nosuch, 0 }, /* 0x12 */
1407 {chm_nosuch, 0 }, /* 0x13 */
1408 {chm_nosuch, 0 }, /* 0x14 */
1409 {chm_nosuch, 0 }, /* 0x15 */
1410 {chm_nosuch, 0 }, /* 0x16 */
1411 {chm_nosuch, 0 }, /* 0x17 */
1412 {chm_nosuch, 0 }, /* 0x18 */
1413 {chm_nosuch, 0 }, /* 0x19 */
1414 {chm_nosuch, 0 }, /* 0x1a */
1415 {chm_nosuch, 0 }, /* 0x1b */
1416 {chm_nosuch, 0 }, /* 0x1c */
1417 {chm_nosuch, 0 }, /* 0x1d */
1418 {chm_nosuch, 0 }, /* 0x1e */
1419 {chm_nosuch, 0 }, /* 0x1f */
1420 {chm_nosuch, 0 }, /* 0x20 */
1421 {chm_nosuch, 0 }, /* 0x21 */
1422 {chm_nosuch, 0 }, /* 0x22 */
1423 {chm_nosuch, 0 }, /* 0x23 */
1424 {chm_nosuch, 0 }, /* 0x24 */
1425 {chm_nosuch, 0 }, /* 0x25 */
1426 {chm_nosuch, 0 }, /* 0x26 */
1427 {chm_nosuch, 0 }, /* 0x27 */
1428 {chm_nosuch, 0 }, /* 0x28 */
1429 {chm_nosuch, 0 }, /* 0x29 */
1430 {chm_nosuch, 0 }, /* 0x2a */
1431 {chm_nosuch, 0 }, /* 0x2b */
1432 {chm_nosuch, 0 }, /* 0x2c */
1433 {chm_nosuch, 0 }, /* 0x2d */
1434 {chm_nosuch, 0 }, /* 0x2e */
1435 {chm_nosuch, 0 }, /* 0x2f */
1436 {chm_nosuch, 0 }, /* 0x30 */
1437 {chm_nosuch, 0 }, /* 0x31 */
1438 {chm_nosuch, 0 }, /* 0x32 */
1439 {chm_nosuch, 0 }, /* 0x33 */
1440 {chm_nosuch, 0 }, /* 0x34 */
1441 {chm_nosuch, 0 }, /* 0x35 */
1442 {chm_nosuch, 0 }, /* 0x36 */
1443 {chm_nosuch, 0 }, /* 0x37 */
1444 {chm_nosuch, 0 }, /* 0x38 */
1445 {chm_nosuch, 0 }, /* 0x39 */
1446 {chm_nosuch, 0 }, /* 0x3a */
1447 {chm_nosuch, 0 }, /* 0x3b */
1448 {chm_nosuch, 0 }, /* 0x3c */
1449 {chm_nosuch, 0 }, /* 0x3d */
1450 {chm_nosuch, 0 }, /* 0x3e */
1451 {chm_nosuch, 0 }, /* 0x3f */
1452
1453 {chm_nosuch, 0 }, /* @ */
1454 {chm_nosuch, 0 }, /* A */
1455 {chm_nosuch, 0 }, /* B */
1456 {chm_nosuch, 0 }, /* C */
1457 {chm_nosuch, 0 }, /* D */
1458 {chm_nosuch, 0 }, /* E */
1459 {chm_simple, MODE_FREETARGET }, /* F */
1460 {chm_nosuch, 0 }, /* G */
1461 {chm_nosuch, 0 }, /* H */
1462 {chm_ban, CHFL_INVEX }, /* I */
1463 {chm_nosuch, 0 }, /* J */
1464 {chm_nosuch, 0 }, /* K */
1465 {chm_staff, MODE_EXLIMIT }, /* L */
1466 {chm_nosuch, 0 }, /* M */
1467 {chm_nosuch, 0 }, /* N */
1468 {chm_nosuch, 0 }, /* O */
1469 {chm_staff, MODE_PERMANENT }, /* P */
1470 {chm_simple, MODE_DISFORWARD }, /* Q */
1471 {chm_nosuch, 0 }, /* R */
1472 {chm_nosuch, 0 }, /* S */
1473 {chm_nosuch, 0 }, /* T */
1474 {chm_nosuch, 0 }, /* U */
1475 {chm_nosuch, 0 }, /* V */
1476 {chm_nosuch, 0 }, /* W */
1477 {chm_nosuch, 0 }, /* X */
1478 {chm_nosuch, 0 }, /* Y */
1479 {chm_nosuch, 0 }, /* Z */
1480 {chm_nosuch, 0 },
1481 {chm_nosuch, 0 },
1482 {chm_nosuch, 0 },
1483 {chm_nosuch, 0 },
1484 {chm_nosuch, 0 },
1485 {chm_nosuch, 0 },
1486 {chm_nosuch, 0 }, /* a */
1487 {chm_ban, CHFL_BAN }, /* b */
1488 {chm_nosuch, 0 }, /* c */
1489 {chm_nosuch, 0 }, /* d */
1490 {chm_ban, CHFL_EXCEPTION }, /* e */
1491 {chm_forward, 0 }, /* f */
1492 {chm_simple, MODE_FREEINVITE }, /* g */
1493 {chm_nosuch, 0 }, /* h */
1494 {chm_simple, MODE_INVITEONLY }, /* i */
1495 {chm_throttle, 0 }, /* j */
1496 {chm_key, 0 }, /* k */
1497 {chm_limit, 0 }, /* l */
1498 {chm_simple, MODE_MODERATED }, /* m */
1499 {chm_simple, MODE_NOPRIVMSGS }, /* n */
1500 {chm_op, 0 }, /* o */
1501 {chm_simple, MODE_PRIVATE }, /* p */
1502 {chm_ban, CHFL_QUIET }, /* q */
1503 {chm_simple, MODE_REGONLY }, /* r */
1504 {chm_simple, MODE_SECRET }, /* s */
1505 {chm_simple, MODE_TOPICLIMIT }, /* t */
1506 {chm_nosuch, 0 }, /* u */
1507 {chm_voice, 0 }, /* v */
1508 {chm_nosuch, 0 }, /* w */
1509 {chm_nosuch, 0 }, /* x */
1510 {chm_nosuch, 0 }, /* y */
1511 {chm_simple, MODE_OPMODERATE }, /* z */
1512
1513 {chm_nosuch, 0 }, /* 0x7b */
1514 {chm_nosuch, 0 }, /* 0x7c */
1515 {chm_nosuch, 0 }, /* 0x7d */
1516 {chm_nosuch, 0 }, /* 0x7e */
1517 {chm_nosuch, 0 }, /* 0x7f */
1518
1519 {chm_nosuch, 0 }, /* 0x80 */
1520 {chm_nosuch, 0 }, /* 0x81 */
1521 {chm_nosuch, 0 }, /* 0x82 */
1522 {chm_nosuch, 0 }, /* 0x83 */
1523 {chm_nosuch, 0 }, /* 0x84 */
1524 {chm_nosuch, 0 }, /* 0x85 */
1525 {chm_nosuch, 0 }, /* 0x86 */
1526 {chm_nosuch, 0 }, /* 0x87 */
1527 {chm_nosuch, 0 }, /* 0x88 */
1528 {chm_nosuch, 0 }, /* 0x89 */
1529 {chm_nosuch, 0 }, /* 0x8a */
1530 {chm_nosuch, 0 }, /* 0x8b */
1531 {chm_nosuch, 0 }, /* 0x8c */
1532 {chm_nosuch, 0 }, /* 0x8d */
1533 {chm_nosuch, 0 }, /* 0x8e */
1534 {chm_nosuch, 0 }, /* 0x8f */
1535
1536 {chm_nosuch, 0 }, /* 0x90 */
1537 {chm_nosuch, 0 }, /* 0x91 */
1538 {chm_nosuch, 0 }, /* 0x92 */
1539 {chm_nosuch, 0 }, /* 0x93 */
1540 {chm_nosuch, 0 }, /* 0x94 */
1541 {chm_nosuch, 0 }, /* 0x95 */
1542 {chm_nosuch, 0 }, /* 0x96 */
1543 {chm_nosuch, 0 }, /* 0x97 */
1544 {chm_nosuch, 0 }, /* 0x98 */
1545 {chm_nosuch, 0 }, /* 0x99 */
1546 {chm_nosuch, 0 }, /* 0x9a */
1547 {chm_nosuch, 0 }, /* 0x9b */
1548 {chm_nosuch, 0 }, /* 0x9c */
1549 {chm_nosuch, 0 }, /* 0x9d */
1550 {chm_nosuch, 0 }, /* 0x9e */
1551 {chm_nosuch, 0 }, /* 0x9f */
1552
1553 {chm_nosuch, 0 }, /* 0xa0 */
1554 {chm_nosuch, 0 }, /* 0xa1 */
1555 {chm_nosuch, 0 }, /* 0xa2 */
1556 {chm_nosuch, 0 }, /* 0xa3 */
1557 {chm_nosuch, 0 }, /* 0xa4 */
1558 {chm_nosuch, 0 }, /* 0xa5 */
1559 {chm_nosuch, 0 }, /* 0xa6 */
1560 {chm_nosuch, 0 }, /* 0xa7 */
1561 {chm_nosuch, 0 }, /* 0xa8 */
1562 {chm_nosuch, 0 }, /* 0xa9 */
1563 {chm_nosuch, 0 }, /* 0xaa */
1564 {chm_nosuch, 0 }, /* 0xab */
1565 {chm_nosuch, 0 }, /* 0xac */
1566 {chm_nosuch, 0 }, /* 0xad */
1567 {chm_nosuch, 0 }, /* 0xae */
1568 {chm_nosuch, 0 }, /* 0xaf */
1569
1570 {chm_nosuch, 0 }, /* 0xb0 */
1571 {chm_nosuch, 0 }, /* 0xb1 */
1572 {chm_nosuch, 0 }, /* 0xb2 */
1573 {chm_nosuch, 0 }, /* 0xb3 */
1574 {chm_nosuch, 0 }, /* 0xb4 */
1575 {chm_nosuch, 0 }, /* 0xb5 */
1576 {chm_nosuch, 0 }, /* 0xb6 */
1577 {chm_nosuch, 0 }, /* 0xb7 */
1578 {chm_nosuch, 0 }, /* 0xb8 */
1579 {chm_nosuch, 0 }, /* 0xb9 */
1580 {chm_nosuch, 0 }, /* 0xba */
1581 {chm_nosuch, 0 }, /* 0xbb */
1582 {chm_nosuch, 0 }, /* 0xbc */
1583 {chm_nosuch, 0 }, /* 0xbd */
1584 {chm_nosuch, 0 }, /* 0xbe */
1585 {chm_nosuch, 0 }, /* 0xbf */
1586
1587 {chm_nosuch, 0 }, /* 0xc0 */
1588 {chm_nosuch, 0 }, /* 0xc1 */
1589 {chm_nosuch, 0 }, /* 0xc2 */
1590 {chm_nosuch, 0 }, /* 0xc3 */
1591 {chm_nosuch, 0 }, /* 0xc4 */
1592 {chm_nosuch, 0 }, /* 0xc5 */
1593 {chm_nosuch, 0 }, /* 0xc6 */
1594 {chm_nosuch, 0 }, /* 0xc7 */
1595 {chm_nosuch, 0 }, /* 0xc8 */
1596 {chm_nosuch, 0 }, /* 0xc9 */
1597 {chm_nosuch, 0 }, /* 0xca */
1598 {chm_nosuch, 0 }, /* 0xcb */
1599 {chm_nosuch, 0 }, /* 0xcc */
1600 {chm_nosuch, 0 }, /* 0xcd */
1601 {chm_nosuch, 0 }, /* 0xce */
1602 {chm_nosuch, 0 }, /* 0xcf */
1603
1604 {chm_nosuch, 0 }, /* 0xd0 */
1605 {chm_nosuch, 0 }, /* 0xd1 */
1606 {chm_nosuch, 0 }, /* 0xd2 */
1607 {chm_nosuch, 0 }, /* 0xd3 */
1608 {chm_nosuch, 0 }, /* 0xd4 */
1609 {chm_nosuch, 0 }, /* 0xd5 */
1610 {chm_nosuch, 0 }, /* 0xd6 */
1611 {chm_nosuch, 0 }, /* 0xd7 */
1612 {chm_nosuch, 0 }, /* 0xd8 */
1613 {chm_nosuch, 0 }, /* 0xd9 */
1614 {chm_nosuch, 0 }, /* 0xda */
1615 {chm_nosuch, 0 }, /* 0xdb */
1616 {chm_nosuch, 0 }, /* 0xdc */
1617 {chm_nosuch, 0 }, /* 0xdd */
1618 {chm_nosuch, 0 }, /* 0xde */
1619 {chm_nosuch, 0 }, /* 0xdf */
1620
1621 {chm_nosuch, 0 }, /* 0xe0 */
1622 {chm_nosuch, 0 }, /* 0xe1 */
1623 {chm_nosuch, 0 }, /* 0xe2 */
1624 {chm_nosuch, 0 }, /* 0xe3 */
1625 {chm_nosuch, 0 }, /* 0xe4 */
1626 {chm_nosuch, 0 }, /* 0xe5 */
1627 {chm_nosuch, 0 }, /* 0xe6 */
1628 {chm_nosuch, 0 }, /* 0xe7 */
1629 {chm_nosuch, 0 }, /* 0xe8 */
1630 {chm_nosuch, 0 }, /* 0xe9 */
1631 {chm_nosuch, 0 }, /* 0xea */
1632 {chm_nosuch, 0 }, /* 0xeb */
1633 {chm_nosuch, 0 }, /* 0xec */
1634 {chm_nosuch, 0 }, /* 0xed */
1635 {chm_nosuch, 0 }, /* 0xee */
1636 {chm_nosuch, 0 }, /* 0xef */
1637
1638 {chm_nosuch, 0 }, /* 0xf0 */
1639 {chm_nosuch, 0 }, /* 0xf1 */
1640 {chm_nosuch, 0 }, /* 0xf2 */
1641 {chm_nosuch, 0 }, /* 0xf3 */
1642 {chm_nosuch, 0 }, /* 0xf4 */
1643 {chm_nosuch, 0 }, /* 0xf5 */
1644 {chm_nosuch, 0 }, /* 0xf6 */
1645 {chm_nosuch, 0 }, /* 0xf7 */
1646 {chm_nosuch, 0 }, /* 0xf8 */
1647 {chm_nosuch, 0 }, /* 0xf9 */
1648 {chm_nosuch, 0 }, /* 0xfa */
1649 {chm_nosuch, 0 }, /* 0xfb */
1650 {chm_nosuch, 0 }, /* 0xfc */
1651 {chm_nosuch, 0 }, /* 0xfd */
1652 {chm_nosuch, 0 }, /* 0xfe */
1653 {chm_nosuch, 0 }, /* 0xff */
1654};
1655
1656/* *INDENT-ON* */
1657
1658/* set_channel_mode()
1659 *
1660 * inputs - client, source, channel, membership pointer, params
1661 * output -
1662 * side effects - channel modes/memberships are changed, MODE is issued
1663 *
1664 * Extensively modified to be hotpluggable, 03/09/06 -- nenolod
1665 */
1666void
1667set_channel_mode(struct Client *client_p, struct Client *source_p,
1668 struct Channel *chptr, struct membership *msptr, int parc, const char *parv[])
1669{
1670 static char modebuf[BUFSIZE];
1671 static char parabuf[BUFSIZE];
1672 char *mbuf;
1673 char *pbuf;
1674 int cur_len, mlen, paralen, paracount, arglen, len;
1675 int i, j, flags;
1676 int dir = MODE_QUERY;
1677 int parn = 1;
1678 int errors = 0;
1679 int alevel;
1680 const char *ml = parv[0];
1681 char c;
1682 struct Client *fakesource_p;
1683 int reauthorized = 0; /* if we change from MODE_QUERY to MODE_ADD/MODE_DEL, then reauth once, ugly but it works */
1684 int flags_list[3] = { ALL_MEMBERS, ONLY_CHANOPS, ONLY_OPERS };
1685
1686 mask_pos = 0;
1687 removed_mask_pos = 0;
1688 mode_count = 0;
1689 mode_limit = 0;
1690 mode_limit_simple = 0;
1691
1692 /* Hide connecting server on netburst -- jilles */
1693 if (ConfigServerHide.flatten_links && IsServer(source_p) && !has_id(source_p) && !HasSentEob(source_p))
1694 fakesource_p = &me;
1695 else
1696 fakesource_p = source_p;
1697
1698 alevel = get_channel_access(source_p, chptr, msptr, dir, reconstruct_parv(parc, parv));
1699
1700 for(; (c = *ml) != 0; ml++)
1701 {
1702 switch (c)
1703 {
1704 case '+':
1705 dir = MODE_ADD;
1706 if (!reauthorized)
1707 {
1708 alevel = get_channel_access(source_p, chptr, msptr, dir, reconstruct_parv(parc, parv));
1709 reauthorized = 1;
1710 }
1711 break;
1712 case '-':
1713 dir = MODE_DEL;
1714 if (!reauthorized)
1715 {
1716 alevel = get_channel_access(source_p, chptr, msptr, dir, reconstruct_parv(parc, parv));
1717 reauthorized = 1;
1718 }
1719 break;
1720 case '=':
1721 dir = MODE_QUERY;
1722 break;
1723 default:
1724 chmode_table[(unsigned char) c].set_func(fakesource_p, chptr, alevel,
1725 parc, &parn, parv,
1726 &errors, dir, c,
1727 chmode_table[(unsigned char) c].mode_type);
1728 break;
1729 }
1730 }
1731
1732 /* bail out if we have nothing to do... */
1733 if(!mode_count)
1734 return;
1735
1736 if(IsServer(source_p))
1737 mlen = sprintf(modebuf, ":%s MODE %s ", fakesource_p->name, chptr->chname);
1738 else
1739 mlen = sprintf(modebuf, ":%s!%s@%s MODE %s ",
1740 source_p->name, source_p->username,
1741 source_p->host, chptr->chname);
1742
1743 for(j = 0; j < 3; j++)
1744 {
1745 flags = flags_list[j];
1746 cur_len = mlen;
1747 mbuf = modebuf + mlen;
1748 pbuf = parabuf;
1749 parabuf[0] = '\0';
1750 paracount = paralen = 0;
1751 dir = MODE_QUERY;
1752
1753 for(i = 0; i < mode_count; i++)
1754 {
1755 if(mode_changes[i].letter == 0 || mode_changes[i].mems != flags)
1756 continue;
1757
1758 if(mode_changes[i].arg != NULL)
1759 {
1760 arglen = strlen(mode_changes[i].arg);
1761
1762 if(arglen > MODEBUFLEN - 5)
1763 continue;
1764 }
1765 else
1766 arglen = 0;
1767
1768 /* if we're creeping over MAXMODEPARAMSSERV, or over
1769 * bufsize (4 == +/-,modechar,two spaces) send now.
1770 */
1771 if(mode_changes[i].arg != NULL &&
1772 ((paracount == MAXMODEPARAMSSERV) ||
1773 ((cur_len + paralen + arglen + 4) > (BUFSIZE - 3))))
1774 {
1775 *mbuf = '\0';
1776
1777 if(cur_len > mlen)
1778 sendto_channel_local(IsServer(source_p) ? fakesource_p : source_p,
1779 flags, chptr, "%s %s", modebuf, parabuf);
1780 else
1781 continue;
1782
1783 paracount = paralen = 0;
1784 cur_len = mlen;
1785 mbuf = modebuf + mlen;
1786 pbuf = parabuf;
1787 parabuf[0] = '\0';
1788 dir = MODE_QUERY;
1789 }
1790
1791 if(dir != mode_changes[i].dir)
1792 {
1793 *mbuf++ = (mode_changes[i].dir == MODE_ADD) ? '+' : '-';
1794 cur_len++;
1795 dir = mode_changes[i].dir;
1796 }
1797
1798 *mbuf++ = mode_changes[i].letter;
1799 cur_len++;
1800
1801 if(mode_changes[i].arg != NULL)
1802 {
1803 paracount++;
1804 len = sprintf(pbuf, "%s ", mode_changes[i].arg);
1805 pbuf += len;
1806 paralen += len;
1807 }
1808 }
1809
1810 if(paralen && parabuf[paralen - 1] == ' ')
1811 parabuf[paralen - 1] = '\0';
1812
1813 *mbuf = '\0';
1814 if(cur_len > mlen)
1815 sendto_channel_local(IsServer(source_p) ? fakesource_p : source_p,
1816 flags, chptr, "%s %s", modebuf, parabuf);
1817 }
1818
1819 /* only propagate modes originating locally, or if we're hubbing */
1820 if(MyClient(source_p) || rb_dlink_list_length(&serv_list) > 1)
1821 send_cap_mode_changes(client_p, source_p, chptr, mode_changes, mode_count);
1822}
1823
1824/* set_channel_mlock()
1825 *
1826 * inputs - client, source, channel, params
1827 * output -
1828 * side effects - channel mlock is changed / MLOCK is propagated
1829 */
1830void
1831set_channel_mlock(struct Client *client_p, struct Client *source_p,
1832 struct Channel *chptr, const char *newmlock, bool propagate)
1833{
1834 rb_free(chptr->mode_lock);
1835 chptr->mode_lock = newmlock ? rb_strdup(newmlock) : NULL;
1836
1837 if (propagate)
1838 {
1839 sendto_server(client_p, NULL, CAP_TS6 | CAP_MLOCK, NOCAPS, ":%s MLOCK %ld %s :%s",
1840 source_p->id, (long) chptr->channelts, chptr->chname,
1841 chptr->mode_lock ? chptr->mode_lock : "");
1842 }
1843}