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