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