ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 3135
Committed: Mon Mar 10 21:11:25 2014 UTC (11 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 53748 byte(s)
Log Message:
- Server now no longer accepts TS5 links

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2014 ircd-hybrid development team
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 * USA
20 */
21
22 /*! \file channel_mode.c
23 * \brief Controls modes on channels.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "channel.h"
30 #include "channel_mode.h"
31 #include "client.h"
32 #include "conf.h"
33 #include "hostmask.h"
34 #include "irc_string.h"
35 #include "ircd.h"
36 #include "numeric.h"
37 #include "s_serv.h"
38 #include "send.h"
39 #include "memory.h"
40 #include "mempool.h"
41 #include "parse.h"
42
43 /* 10 is a magic number in hybrid 6 NFI where it comes from -db */
44 #define BAN_FUDGE 10
45 #define NCHCAPS (sizeof(channel_capabs)/sizeof(int))
46 #define NCHCAP_COMBOS (1 << NCHCAPS)
47
48
49 static char nuh_mask[MAXPARA][IRCD_BUFSIZE];
50 /* some buffers for rebuilding channel/nick lists with ,'s */
51 static char modebuf[IRCD_BUFSIZE];
52 static char parabuf[MODEBUFLEN];
53 static struct ChModeChange mode_changes[IRCD_BUFSIZE];
54 static unsigned int mode_count;
55 static unsigned int mode_limit; /* number of modes set other than simple */
56 static unsigned int simple_modes_mask; /* bit mask of simple modes already set */
57 #ifdef HALFOPS
58 static int channel_capabs[] = { CAP_TS6, CAP_HOPS };
59 #else
60 static int channel_capabs[] = { CAP_TS6 };
61 #endif
62 static struct ChCapCombo chcap_combos[NCHCAP_COMBOS];
63 extern mp_pool_t *ban_pool;
64
65
66 /* check_string()
67 *
68 * inputs - string to check
69 * output - pointer to modified string
70 * side effects - Fixes a string so that the first white space found
71 * becomes an end of string marker (`\0`).
72 * returns the 'fixed' string or "*" if the string
73 * was NULL length or a NULL pointer.
74 */
75 static char *
76 check_string(char *s)
77 {
78 char *str = s;
79 static char star[] = "*";
80
81 if (EmptyString(str))
82 return star;
83
84 for (; *s; ++s)
85 {
86 if (IsSpace(*s))
87 {
88 *s = '\0';
89 break;
90 }
91 }
92
93 return EmptyString(str) ? star : str;
94 }
95
96 /*
97 * Ban functions to work with mode +b/e/d/I
98 */
99 /* add the specified ID to the channel.
100 * -is 8/9/00
101 */
102
103 int
104 add_id(struct Client *client_p, struct Channel *chptr, char *banid, unsigned int type)
105 {
106 dlink_list *list = NULL;
107 dlink_node *ban = NULL;
108 size_t len = 0;
109 struct Ban *ban_p = NULL;
110 unsigned int num_mask;
111 char name[NICKLEN + 1];
112 char user[USERLEN + 1];
113 char host[HOSTLEN + 1];
114 struct split_nuh_item nuh;
115
116 /* dont let local clients overflow the b/e/I lists */
117 if (MyClient(client_p))
118 {
119 num_mask = dlink_list_length(&chptr->banlist) +
120 dlink_list_length(&chptr->exceptlist) +
121 dlink_list_length(&chptr->invexlist);
122
123 if (num_mask >= ConfigChannel.max_bans)
124 {
125 sendto_one_numeric(client_p, &me, ERR_BANLISTFULL, chptr->chname, banid);
126 return 0;
127 }
128
129 collapse(banid);
130 }
131
132 nuh.nuhmask = check_string(banid);
133 nuh.nickptr = name;
134 nuh.userptr = user;
135 nuh.hostptr = host;
136
137 nuh.nicksize = sizeof(name);
138 nuh.usersize = sizeof(user);
139 nuh.hostsize = sizeof(host);
140
141 split_nuh(&nuh);
142
143 /*
144 * Re-assemble a new n!u@h and print it back to banid for sending
145 * the mode to the channel.
146 */
147 len = sprintf(banid, "%s!%s@%s", name, user, host);
148
149 switch (type)
150 {
151 case CHFL_BAN:
152 list = &chptr->banlist;
153 clear_ban_cache(chptr);
154 break;
155 case CHFL_EXCEPTION:
156 list = &chptr->exceptlist;
157 clear_ban_cache(chptr);
158 break;
159 case CHFL_INVEX:
160 list = &chptr->invexlist;
161 break;
162 default:
163 assert(0);
164 return 0;
165 }
166
167 DLINK_FOREACH(ban, list->head)
168 {
169 ban_p = ban->data;
170
171 if (!irccmp(ban_p->name, name) &&
172 !irccmp(ban_p->user, user) &&
173 !irccmp(ban_p->host, host))
174 return 0;
175 }
176
177 ban_p = mp_pool_get(ban_pool);
178 memset(ban_p, 0, sizeof(*ban_p));
179 ban_p->name = xstrdup(name);
180 ban_p->user = xstrdup(user);
181 ban_p->host = xstrdup(host);
182 ban_p->when = CurrentTime;
183 ban_p->len = len - 2; /* -2 for @ and ! */
184 ban_p->type = parse_netmask(host, &ban_p->addr, &ban_p->bits);
185
186 if (IsClient(client_p))
187 {
188 ban_p->who = MyMalloc(strlen(client_p->name) +
189 strlen(client_p->username) +
190 strlen(client_p->host) + 3);
191 sprintf(ban_p->who, "%s!%s@%s", client_p->name,
192 client_p->username, client_p->host);
193 }
194 else if (IsHidden(client_p) || (IsServer(client_p) && ConfigServerHide.hide_servers))
195 ban_p->who = xstrdup(me.name);
196 else
197 ban_p->who = xstrdup(client_p->name);
198
199 dlinkAdd(ban_p, &ban_p->node, list);
200
201 return 1;
202 }
203
204 /*
205 * inputs - pointer to channel
206 * - pointer to ban id
207 * - type of ban, i.e. ban, exception, invex
208 * output - 0 for failure, 1 for success
209 * side effects -
210 */
211 static int
212 del_id(struct Channel *chptr, char *banid, unsigned int type)
213 {
214 dlink_list *list;
215 dlink_node *ban;
216 struct Ban *banptr;
217 char name[NICKLEN + 1];
218 char user[USERLEN + 1];
219 char host[HOSTLEN + 1];
220 struct split_nuh_item nuh;
221
222 assert(banid);
223
224 nuh.nuhmask = check_string(banid);
225 nuh.nickptr = name;
226 nuh.userptr = user;
227 nuh.hostptr = host;
228
229 nuh.nicksize = sizeof(name);
230 nuh.usersize = sizeof(user);
231 nuh.hostsize = sizeof(host);
232
233 split_nuh(&nuh);
234
235 /*
236 * Re-assemble a new n!u@h and print it back to banid for sending
237 * the mode to the channel.
238 */
239 sprintf(banid, "%s!%s@%s", name, user, host);
240
241 switch (type)
242 {
243 case CHFL_BAN:
244 list = &chptr->banlist;
245 clear_ban_cache(chptr);
246 break;
247 case CHFL_EXCEPTION:
248 list = &chptr->exceptlist;
249 clear_ban_cache(chptr);
250 break;
251 case CHFL_INVEX:
252 list = &chptr->invexlist;
253 break;
254 default:
255 assert(0);
256 return 0;
257 }
258
259 DLINK_FOREACH(ban, list->head)
260 {
261 banptr = ban->data;
262
263 if (!irccmp(name, banptr->name) &&
264 !irccmp(user, banptr->user) &&
265 !irccmp(host, banptr->host))
266 {
267 remove_ban(banptr, list);
268 return 1;
269 }
270 }
271
272 return 0;
273 }
274
275 const struct mode_letter chan_modes[] =
276 {
277 { MODE_NOCTRL, 'c' },
278 { MODE_INVITEONLY, 'i' },
279 { MODE_MODERATED, 'm' },
280 { MODE_NOPRIVMSGS, 'n' },
281 { MODE_PRIVATE, 'p' },
282 { MODE_REGISTERED, 'r' },
283 { MODE_SECRET, 's' },
284 { MODE_TOPICLIMIT, 't' },
285 { MODE_MODREG, 'M' },
286 { MODE_OPERONLY, 'O' },
287 { MODE_REGONLY, 'R' },
288 { MODE_SSLONLY, 'S' },
289 { 0, '\0' }
290 };
291
292 /* channel_modes()
293 *
294 * inputs - pointer to channel
295 * - pointer to client
296 * - pointer to mode buf
297 * - pointer to parameter buf
298 * output - NONE
299 * side effects - write the "simple" list of channel modes for channel
300 * chptr onto buffer mbuf with the parameters in pbuf.
301 */
302 void
303 channel_modes(struct Channel *chptr, struct Client *client_p,
304 char *mbuf, char *pbuf)
305 {
306 const struct mode_letter *tab = chan_modes;
307
308 *mbuf++ = '+';
309 *pbuf = '\0';
310
311 for (; tab->mode; ++tab)
312 if (chptr->mode.mode & tab->mode)
313 *mbuf++ = tab->letter;
314
315 if (chptr->mode.limit)
316 {
317 *mbuf++ = 'l';
318
319 if (IsServer(client_p) || HasFlag(client_p, FLAGS_SERVICE) || IsMember(client_p, chptr))
320 pbuf += sprintf(pbuf, "%d ", chptr->mode.limit);
321 }
322
323 if (chptr->mode.key[0])
324 {
325 *mbuf++ = 'k';
326
327 if (IsServer(client_p) || HasFlag(client_p, FLAGS_SERVICE) || IsMember(client_p, chptr))
328 sprintf(pbuf, "%s ", chptr->mode.key);
329 }
330
331 *mbuf = '\0';
332 }
333
334 /* fix_key()
335 *
336 * inputs - pointer to key to clean up
337 * output - pointer to cleaned up key
338 * side effects - input string is modified
339 *
340 * stolen from Undernet's ircd -orabidoo
341 */
342 static char *
343 fix_key(char *arg)
344 {
345 unsigned char *s, *t, c;
346
347 for (s = t = (unsigned char *)arg; (c = *s); s++)
348 {
349 c &= 0x7f;
350
351 if (c != ':' && c > ' ' && c != ',')
352 *t++ = c;
353 }
354
355 *t = '\0';
356 return arg;
357 }
358
359 /* fix_key_old()
360 *
361 * inputs - pointer to key to clean up
362 * output - pointer to cleaned up key
363 * side effects - input string is modifed
364 *
365 * Here we attempt to be compatible with older non-hybrid servers.
366 * We can't back down from the ':' issue however. --Rodder
367 */
368 static char *
369 fix_key_old(char *arg)
370 {
371 unsigned char *s, *t, c;
372
373 for (s = t = (unsigned char *)arg; (c = *s); s++)
374 {
375 c &= 0x7f;
376
377 if ((c != 0x0a) && (c != ':') &&
378 (c != 0x0d) && (c != ','))
379 *t++ = c;
380 }
381
382 *t = '\0';
383 return arg;
384 }
385
386 /* bitmasks for various error returns that set_channel_mode should only return
387 * once per call -orabidoo
388 */
389
390 #define SM_ERR_NOTS 0x00000001 /* No TS on channel */
391 #define SM_ERR_NOOPS 0x00000002 /* No chan ops */
392 #define SM_ERR_UNKNOWN 0x00000004
393 #define SM_ERR_RPL_B 0x00000008
394 #define SM_ERR_RPL_E 0x00000010
395 #define SM_ERR_NOTONCHANNEL 0x00000020 /* Not on channel */
396 #define SM_ERR_RPL_I 0x00000040
397 #define SM_ERR_NOTOPER 0x00000080
398 #define SM_ERR_ONLYSERVER 0x00000100
399
400 /* Now lets do some stuff to keep track of what combinations of
401 * servers exist...
402 * Note that the number of combinations doubles each time you add
403 * something to this list. Each one is only quick if no servers use that
404 * combination, but if the numbers get too high here MODE will get too
405 * slow. I suggest if you get more than 7 here, you consider getting rid
406 * of some and merging or something. If it wasn't for irc+cs we would
407 * probably not even need to bother about most of these, but unfortunately
408 * we do. -A1kmm
409 */
410
411 /* void init_chcap_usage_counts(void)
412 *
413 * Inputs - none
414 * Output - none
415 * Side-effects - Initialises the usage counts to zero. Fills in the
416 * chcap_yes and chcap_no combination tables.
417 */
418 void
419 init_chcap_usage_counts(void)
420 {
421 unsigned long m, c, y, n;
422
423 memset(chcap_combos, 0, sizeof(chcap_combos));
424
425 /* For every possible combination */
426 for (m = 0; m < NCHCAP_COMBOS; m++)
427 {
428 /* Check each capab */
429 for (c = y = n = 0; c < NCHCAPS; c++)
430 {
431 if ((m & (1 << c)) == 0)
432 n |= channel_capabs[c];
433 else
434 y |= channel_capabs[c];
435 }
436
437 chcap_combos[m].cap_yes = y;
438 chcap_combos[m].cap_no = n;
439 }
440 }
441
442 /* void set_chcap_usage_counts(struct Client *serv_p)
443 * Input: serv_p; The client whose capabs to register.
444 * Output: none
445 * Side-effects: Increments the usage counts for the correct capab
446 * combination.
447 */
448 void
449 set_chcap_usage_counts(struct Client *serv_p)
450 {
451 int n;
452
453 for (n = 0; n < NCHCAP_COMBOS; n++)
454 {
455 if (((serv_p->localClient->caps & chcap_combos[n].cap_yes) ==
456 chcap_combos[n].cap_yes) &&
457 ((serv_p->localClient->caps & chcap_combos[n].cap_no) == 0))
458 {
459 chcap_combos[n].count++;
460 return;
461 }
462 }
463
464 /* This should be impossible -A1kmm. */
465 assert(0);
466 }
467
468 /* void set_chcap_usage_counts(struct Client *serv_p)
469 *
470 * Inputs - serv_p; The client whose capabs to register.
471 * Output - none
472 * Side-effects - Decrements the usage counts for the correct capab
473 * combination.
474 */
475 void
476 unset_chcap_usage_counts(struct Client *serv_p)
477 {
478 int n;
479
480 for (n = 0; n < NCHCAP_COMBOS; n++)
481 {
482 if ((serv_p->localClient->caps & chcap_combos[n].cap_yes) ==
483 chcap_combos[n].cap_yes &&
484 (serv_p->localClient->caps & chcap_combos[n].cap_no) == 0)
485 {
486 /* Hopefully capabs can't change dynamically or anything... */
487 assert(chcap_combos[n].count > 0);
488 chcap_combos[n].count--;
489 return;
490 }
491 }
492
493 /* This should be impossible -A1kmm. */
494 assert(0);
495 }
496
497 /* Mode functions handle mode changes for a particular mode... */
498 static void
499 chm_nosuch(struct Client *client_p, struct Client *source_p,
500 struct Channel *chptr, int parc, int *parn,
501 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
502 {
503 if (*errors & SM_ERR_UNKNOWN)
504 return;
505
506 *errors |= SM_ERR_UNKNOWN;
507 sendto_one_numeric(source_p, &me, ERR_UNKNOWNMODE, c);
508 }
509
510 static void
511 chm_simple(struct Client *client_p, struct Client *source_p, struct Channel *chptr,
512 int parc, int *parn, char **parv, int *errors, int alev, int dir,
513 char c, unsigned int d)
514 {
515 if ((alev < CHACCESS_HALFOP) ||
516 ((d == MODE_PRIVATE) && (alev < CHACCESS_CHANOP)))
517 {
518 if (!(*errors & SM_ERR_NOOPS))
519 sendto_one_numeric(source_p, &me,
520 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
521 ERR_CHANOPRIVSNEEDED, chptr->chname);
522 *errors |= SM_ERR_NOOPS;
523 return;
524 }
525
526 /* If have already dealt with this simple mode, ignore it */
527 if (simple_modes_mask & d)
528 return;
529
530 simple_modes_mask |= d;
531
532 /* setting + */
533 /* Apparently, (though no one has ever told the hybrid group directly)
534 * admins don't like redundant mode checking. ok. It would have been nice
535 * if you had have told us directly. I've left the original code snippets
536 * in place.
537 *
538 * -Dianora
539 */
540 if (dir == MODE_ADD) /* && !(chptr->mode.mode & d)) */
541 {
542 chptr->mode.mode |= d;
543
544 mode_changes[mode_count].letter = c;
545 mode_changes[mode_count].dir = MODE_ADD;
546 mode_changes[mode_count].caps = 0;
547 mode_changes[mode_count].nocaps = 0;
548 mode_changes[mode_count].id = NULL;
549 mode_changes[mode_count].mems = ALL_MEMBERS;
550 mode_changes[mode_count++].arg = NULL;
551 }
552 else if (dir == MODE_DEL) /* && (chptr->mode.mode & d)) */
553 {
554 /* setting - */
555
556 chptr->mode.mode &= ~d;
557
558 mode_changes[mode_count].letter = c;
559 mode_changes[mode_count].dir = MODE_DEL;
560 mode_changes[mode_count].caps = 0;
561 mode_changes[mode_count].nocaps = 0;
562 mode_changes[mode_count].mems = ALL_MEMBERS;
563 mode_changes[mode_count].id = NULL;
564 mode_changes[mode_count++].arg = NULL;
565 }
566 }
567
568 static void
569 chm_registered(struct Client *client_p, struct Client *source_p, struct Channel *chptr,
570 int parc, int *parn, char **parv, int *errors, int alev, int dir,
571 char c, unsigned int d)
572 {
573 if (!IsServer(source_p) && !HasFlag(source_p, FLAGS_SERVICE))
574 {
575 if (!(*errors & SM_ERR_ONLYSERVER))
576 sendto_one_numeric(source_p, &me,
577 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
578 ERR_ONLYSERVERSCANCHANGE, chptr->chname);
579 *errors |= SM_ERR_ONLYSERVER;
580 return;
581 }
582
583 /* If have already dealt with this simple mode, ignore it */
584 if (simple_modes_mask & d)
585 return;
586
587 simple_modes_mask |= d;
588
589 /* setting + */
590 /* Apparently, (though no one has ever told the hybrid group directly)
591 * admins don't like redundant mode checking. ok. It would have been nice
592 * if you had have told us directly. I've left the original code snippets
593 * in place.
594 *
595 * -Dianora
596 */
597 if (dir == MODE_ADD) /* && !(chptr->mode.mode & d)) */
598 {
599 chptr->mode.mode |= d;
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 & d)) */
610 {
611 /* setting - */
612
613 chptr->mode.mode &= ~d;
614
615 mode_changes[mode_count].letter = c;
616 mode_changes[mode_count].dir = MODE_DEL;
617 mode_changes[mode_count].caps = 0;
618 mode_changes[mode_count].nocaps = 0;
619 mode_changes[mode_count].mems = ALL_MEMBERS;
620 mode_changes[mode_count].id = NULL;
621 mode_changes[mode_count++].arg = NULL;
622 }
623 }
624
625 static void
626 chm_operonly(struct Client *client_p, struct Client *source_p, struct Channel *chptr,
627 int parc, int *parn, char **parv, int *errors, int alev, int dir,
628 char c, unsigned int d)
629 {
630 if ((alev < CHACCESS_HALFOP) ||
631 ((d == MODE_PRIVATE) && (alev < CHACCESS_CHANOP)))
632 {
633 if (!(*errors & SM_ERR_NOOPS))
634 sendto_one_numeric(source_p, &me,
635 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
636 ERR_CHANOPRIVSNEEDED, chptr->chname);
637 *errors |= SM_ERR_NOOPS;
638 return;
639 }
640 else if (MyClient(source_p) && !HasUMode(source_p, UMODE_OPER))
641 {
642 if (!(*errors & SM_ERR_NOTOPER))
643 {
644 if (alev == CHACCESS_NOTONCHAN)
645 sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->chname);
646 else
647 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
648 }
649
650 *errors |= SM_ERR_NOTOPER;
651 return;
652 }
653
654 /* If have already dealt with this simple mode, ignore it */
655 if (simple_modes_mask & d)
656 return;
657
658 simple_modes_mask |= d;
659
660 if (dir == MODE_ADD) /* && !(chptr->mode.mode & d)) */
661 {
662 chptr->mode.mode |= d;
663
664 mode_changes[mode_count].letter = c;
665 mode_changes[mode_count].dir = MODE_ADD;
666 mode_changes[mode_count].caps = 0;
667 mode_changes[mode_count].nocaps = 0;
668 mode_changes[mode_count].id = NULL;
669 mode_changes[mode_count].mems = ALL_MEMBERS;
670 mode_changes[mode_count].mems = ALL_MEMBERS;
671 mode_changes[mode_count++].arg = NULL;
672 }
673 else if (dir == MODE_DEL) /* && (chptr->mode.mode & d)) */
674 {
675 /* setting - */
676
677 chptr->mode.mode &= ~d;
678
679 mode_changes[mode_count].letter = c;
680 mode_changes[mode_count].dir = MODE_DEL;
681 mode_changes[mode_count].caps = 0;
682 mode_changes[mode_count].nocaps = 0;
683 mode_changes[mode_count].mems = ALL_MEMBERS;
684 mode_changes[mode_count].id = NULL;
685 mode_changes[mode_count++].arg = NULL;
686 }
687 }
688
689 static void
690 chm_ban(struct Client *client_p, struct Client *source_p,
691 struct Channel *chptr, int parc, int *parn,
692 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
693 {
694 char *mask = NULL;
695
696 if (dir == MODE_QUERY || parc <= *parn)
697 {
698 dlink_node *ptr = NULL;
699
700 if (*errors & SM_ERR_RPL_B)
701 return;
702
703 *errors |= SM_ERR_RPL_B;
704
705 DLINK_FOREACH(ptr, chptr->banlist.head)
706 {
707 const struct Ban *banptr = ptr->data;
708 sendto_one_numeric(source_p, &me, RPL_BANLIST, chptr->chname,
709 banptr->name, banptr->user, banptr->host,
710 banptr->who, banptr->when);
711 }
712
713 sendto_one_numeric(source_p, &me, RPL_ENDOFBANLIST, chptr->chname);
714 return;
715 }
716
717 if (alev < CHACCESS_HALFOP)
718 {
719 if (!(*errors & SM_ERR_NOOPS))
720 sendto_one_numeric(source_p, &me,
721 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
722 ERR_CHANOPRIVSNEEDED, chptr->chname);
723 *errors |= SM_ERR_NOOPS;
724 return;
725 }
726
727 if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
728 return;
729
730 mask = nuh_mask[*parn];
731 memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn]));
732 ++*parn;
733
734 if (IsServer(client_p))
735 if (strchr(mask, ' '))
736 return;
737
738 switch (dir)
739 {
740 case MODE_ADD:
741 if (!add_id(source_p, chptr, mask, CHFL_BAN))
742 return;
743 break;
744 case MODE_DEL:
745 if (!del_id(chptr, mask, CHFL_BAN))
746 return;
747 break;
748 default:
749 assert(0);
750 }
751
752 mode_changes[mode_count].letter = c;
753 mode_changes[mode_count].dir = dir;
754 mode_changes[mode_count].caps = 0;
755 mode_changes[mode_count].nocaps = 0;
756 mode_changes[mode_count].mems = ALL_MEMBERS;
757 mode_changes[mode_count].id = NULL;
758 mode_changes[mode_count++].arg = mask;
759 }
760
761 static void
762 chm_except(struct Client *client_p, struct Client *source_p,
763 struct Channel *chptr, int parc, int *parn,
764 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
765 {
766 char *mask = NULL;
767
768 if (alev < CHACCESS_HALFOP)
769 {
770 if (!(*errors & SM_ERR_NOOPS))
771 sendto_one_numeric(source_p, &me,
772 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
773 ERR_CHANOPRIVSNEEDED, chptr->chname);
774 *errors |= SM_ERR_NOOPS;
775 return;
776 }
777
778 if (dir == MODE_QUERY || parc <= *parn)
779 {
780 dlink_node *ptr = NULL;
781
782 if (*errors & SM_ERR_RPL_E)
783 return;
784
785 *errors |= SM_ERR_RPL_E;
786
787 DLINK_FOREACH(ptr, chptr->exceptlist.head)
788 {
789 const struct Ban *banptr = ptr->data;
790
791 sendto_one_numeric(source_p, &me, RPL_EXCEPTLIST, chptr->chname,
792 banptr->name, banptr->user, banptr->host,
793 banptr->who, banptr->when);
794 }
795
796 sendto_one_numeric(source_p, &me, RPL_ENDOFEXCEPTLIST, chptr->chname);
797 return;
798 }
799
800 if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
801 return;
802
803 mask = nuh_mask[*parn];
804 memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn]));
805 ++*parn;
806
807 if (IsServer(client_p))
808 if (strchr(mask, ' '))
809 return;
810
811 switch (dir)
812 {
813 case MODE_ADD:
814 if (!add_id(source_p, chptr, mask, CHFL_EXCEPTION))
815 return;
816 break;
817 case MODE_DEL:
818 if (!del_id(chptr, mask, CHFL_EXCEPTION))
819 return;
820 break;
821 default:
822 assert(0);
823 }
824
825 mode_changes[mode_count].letter = c;
826 mode_changes[mode_count].dir = dir;
827 mode_changes[mode_count].caps = 0;
828 mode_changes[mode_count].nocaps = 0;
829 mode_changes[mode_count].mems = ONLY_CHANOPS;
830 mode_changes[mode_count].id = NULL;
831 mode_changes[mode_count++].arg = mask;
832 }
833
834 static void
835 chm_invex(struct Client *client_p, struct Client *source_p,
836 struct Channel *chptr, int parc, int *parn,
837 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
838 {
839 char *mask = NULL;
840
841 if (alev < CHACCESS_HALFOP)
842 {
843 if (!(*errors & SM_ERR_NOOPS))
844 sendto_one_numeric(source_p, &me,
845 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
846 ERR_CHANOPRIVSNEEDED, chptr->chname);
847 *errors |= SM_ERR_NOOPS;
848 return;
849 }
850
851 if (dir == MODE_QUERY || parc <= *parn)
852 {
853 dlink_node *ptr = NULL;
854
855 if (*errors & SM_ERR_RPL_I)
856 return;
857
858 *errors |= SM_ERR_RPL_I;
859
860 DLINK_FOREACH(ptr, chptr->invexlist.head)
861 {
862 const struct Ban *banptr = ptr->data;
863
864 sendto_one_numeric(source_p, &me, RPL_INVITELIST, chptr->chname,
865 banptr->name, banptr->user, banptr->host,
866 banptr->who, banptr->when);
867 }
868
869 sendto_one_numeric(source_p, &me, RPL_ENDOFINVITELIST, chptr->chname);
870 return;
871 }
872
873 if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
874 return;
875
876 mask = nuh_mask[*parn];
877 memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn]));
878 ++*parn;
879
880 if (IsServer(client_p))
881 if (strchr(mask, ' '))
882 return;
883
884 switch (dir)
885 {
886 case MODE_ADD:
887 if (!add_id(source_p, chptr, mask, CHFL_INVEX))
888 return;
889 break;
890 case MODE_DEL:
891 if (!del_id(chptr, mask, CHFL_INVEX))
892 return;
893 break;
894 default:
895 assert(0);
896 }
897
898 mode_changes[mode_count].letter = c;
899 mode_changes[mode_count].dir = dir;
900 mode_changes[mode_count].caps = 0;
901 mode_changes[mode_count].nocaps = 0;
902 mode_changes[mode_count].mems = ONLY_CHANOPS;
903 mode_changes[mode_count].id = NULL;
904 mode_changes[mode_count++].arg = mask;
905 }
906
907 /*
908 * inputs - pointer to channel
909 * output - none
910 * side effects - clear ban cache
911 */
912 void
913 clear_ban_cache(struct Channel *chptr)
914 {
915 dlink_node *ptr = NULL;
916
917 DLINK_FOREACH(ptr, chptr->members.head)
918 {
919 struct Membership *ms = ptr->data;
920
921 if (MyConnect(ms->client_p))
922 ms->flags &= ~(CHFL_BAN_SILENCED|CHFL_BAN_CHECKED);
923 }
924 }
925
926 void
927 clear_ban_cache_client(struct Client *client_p)
928 {
929 dlink_node *ptr = NULL;
930
931 DLINK_FOREACH(ptr, client_p->channel.head)
932 {
933 struct Membership *ms = ptr->data;
934 ms->flags &= ~(CHFL_BAN_SILENCED|CHFL_BAN_CHECKED);
935 }
936 }
937
938 static void
939 chm_voice(struct Client *client_p, struct Client *source_p,
940 struct Channel *chptr, int parc, int *parn,
941 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
942 {
943 const char *opnick = NULL;
944 struct Client *targ_p;
945 struct Membership *member;
946
947 if (alev < CHACCESS_HALFOP)
948 {
949 if (!(*errors & SM_ERR_NOOPS))
950 sendto_one_numeric(source_p, &me,
951 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
952 ERR_CHANOPRIVSNEEDED, chptr->chname);
953 *errors |= SM_ERR_NOOPS;
954 return;
955 }
956
957 if ((dir == MODE_QUERY) || parc <= *parn)
958 return;
959
960 opnick = parv[(*parn)++];
961
962 if ((targ_p = find_chasing(source_p, opnick, NULL)) == NULL)
963 return;
964 if (!IsClient(targ_p))
965 return;
966
967 if ((member = find_channel_link(targ_p, chptr)) == NULL)
968 {
969 if (!(*errors & SM_ERR_NOTONCHANNEL))
970 sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, opnick, chptr->chname);
971 *errors |= SM_ERR_NOTONCHANNEL;
972 return;
973 }
974
975 if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
976 return;
977
978 /* no redundant mode changes */
979 if (dir == MODE_ADD && has_member_flags(member, CHFL_VOICE))
980 return;
981 if (dir == MODE_DEL && !has_member_flags(member, CHFL_VOICE))
982 return;
983
984 mode_changes[mode_count].letter = 'v';
985 mode_changes[mode_count].dir = dir;
986 mode_changes[mode_count].caps = 0;
987 mode_changes[mode_count].nocaps = 0;
988 mode_changes[mode_count].mems = ALL_MEMBERS;
989 mode_changes[mode_count].id = targ_p->id;
990 mode_changes[mode_count].arg = targ_p->name;
991 mode_changes[mode_count++].client = targ_p;
992
993 if (dir == MODE_ADD)
994 AddMemberFlag(member, CHFL_VOICE);
995 else
996 DelMemberFlag(member, CHFL_VOICE);
997 }
998
999 #ifdef HALFOPS
1000 static void
1001 chm_hop(struct Client *client_p, struct Client *source_p,
1002 struct Channel *chptr, int parc, int *parn,
1003 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
1004 {
1005 const char *opnick = NULL;
1006 struct Client *targ_p;
1007 struct Membership *member;
1008
1009 /* *sigh* - dont allow halfops to set +/-h, they could fully control a
1010 * channel if there were no ops - it doesnt solve anything.. MODE_PRIVATE
1011 * when used with MODE_SECRET is paranoid - cant use +p
1012 *
1013 * it needs to be optional per channel - but not via +p, that or remove
1014 * paranoid.. -- fl_
1015 *
1016 * +p means paranoid, it is useless for anything else on modern IRC, as
1017 * list isn't really usable. If you want to have a private channel these
1018 * days, you set it +s. Halfops can no longer remove simple modes when
1019 * +p is set (although they can set +p) so it is safe to use this to
1020 * control whether they can (de)halfop...
1021 */
1022 if (alev <
1023 ((chptr->mode.mode & MODE_PRIVATE) ? CHACCESS_CHANOP : CHACCESS_HALFOP))
1024 {
1025 if (!(*errors & SM_ERR_NOOPS))
1026 sendto_one_numeric(source_p, &me,
1027 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
1028 ERR_CHANOPRIVSNEEDED, chptr->chname);
1029 *errors |= SM_ERR_NOOPS;
1030 return;
1031 }
1032
1033 if ((dir == MODE_QUERY) || (parc <= *parn))
1034 return;
1035
1036 opnick = parv[(*parn)++];
1037
1038 if ((targ_p = find_chasing(source_p, opnick, NULL)) == NULL)
1039 return;
1040 if (!IsClient(targ_p))
1041 return;
1042
1043 if ((member = find_channel_link(targ_p, chptr)) == NULL)
1044 {
1045 if (!(*errors & SM_ERR_NOTONCHANNEL))
1046 sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, opnick, chptr->chname);
1047 *errors |= SM_ERR_NOTONCHANNEL;
1048 return;
1049 }
1050
1051 if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
1052 return;
1053
1054 /* no redundant mode changes */
1055 if (dir == MODE_ADD && has_member_flags(member, CHFL_HALFOP | CHFL_CHANOP))
1056 return;
1057 if (dir == MODE_DEL && !has_member_flags(member, CHFL_HALFOP))
1058 return;
1059
1060 mode_changes[mode_count].letter = 'h';
1061 mode_changes[mode_count].dir = dir;
1062 mode_changes[mode_count].caps = CAP_HOPS;
1063 mode_changes[mode_count].nocaps = 0;
1064 mode_changes[mode_count].mems = ALL_MEMBERS;
1065 mode_changes[mode_count].id = targ_p->id;
1066 mode_changes[mode_count].arg = targ_p->name;
1067 mode_changes[mode_count++].client = targ_p;
1068
1069 mode_changes[mode_count].letter = 'o';
1070 mode_changes[mode_count].dir = dir;
1071 mode_changes[mode_count].caps = 0;
1072 mode_changes[mode_count].nocaps = CAP_HOPS;
1073 mode_changes[mode_count].mems = ONLY_SERVERS;
1074 mode_changes[mode_count].id = targ_p->id;
1075 mode_changes[mode_count].arg = targ_p->name;
1076 mode_changes[mode_count++].client = targ_p;
1077
1078 if (dir == MODE_ADD)
1079 {
1080 AddMemberFlag(member, CHFL_HALFOP);
1081 DelMemberFlag(member, CHFL_DEOPPED);
1082 }
1083 else
1084 DelMemberFlag(member, CHFL_HALFOP);
1085 }
1086 #endif
1087
1088 static void
1089 chm_op(struct Client *client_p, struct Client *source_p,
1090 struct Channel *chptr, int parc, int *parn,
1091 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
1092 {
1093 const char *opnick = NULL;
1094 struct Client *targ_p;
1095 struct Membership *member;
1096 int caps = 0;
1097
1098 if (alev < CHACCESS_CHANOP)
1099 {
1100 if (!(*errors & SM_ERR_NOOPS))
1101 sendto_one_numeric(source_p, &me,
1102 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
1103 ERR_CHANOPRIVSNEEDED, chptr->chname);
1104 *errors |= SM_ERR_NOOPS;
1105 return;
1106 }
1107
1108 if ((dir == MODE_QUERY) || (parc <= *parn))
1109 return;
1110
1111 opnick = parv[(*parn)++];
1112
1113 if ((targ_p = find_chasing(source_p, opnick, NULL)) == NULL)
1114 return;
1115 if (!IsClient(targ_p))
1116 return;
1117
1118 if ((member = find_channel_link(targ_p, chptr)) == NULL)
1119 {
1120 if (!(*errors & SM_ERR_NOTONCHANNEL))
1121 sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, opnick, chptr->chname);
1122 *errors |= SM_ERR_NOTONCHANNEL;
1123 return;
1124 }
1125
1126 if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
1127 return;
1128
1129 /* no redundant mode changes */
1130 if (dir == MODE_ADD && has_member_flags(member, CHFL_CHANOP))
1131 return;
1132 if (dir == MODE_DEL && !has_member_flags(member, CHFL_CHANOP))
1133 {
1134 #ifdef HALFOPS
1135 if (has_member_flags(member, CHFL_HALFOP))
1136 {
1137 --*parn;
1138 chm_hop(client_p, source_p, chptr, parc, parn, parv, errors, alev,
1139 dir, c, d);
1140 }
1141 #endif
1142 return;
1143 }
1144
1145 #ifdef HALFOPS
1146 if (dir == MODE_ADD && has_member_flags(member, CHFL_HALFOP))
1147 {
1148 /* promoting from % to @ is visible only to CAP_HOPS servers */
1149 mode_changes[mode_count].letter = 'h';
1150 mode_changes[mode_count].dir = MODE_DEL;
1151 mode_changes[mode_count].caps = caps = CAP_HOPS;
1152 mode_changes[mode_count].nocaps = 0;
1153 mode_changes[mode_count].mems = ALL_MEMBERS;
1154 mode_changes[mode_count].id = NULL;
1155 mode_changes[mode_count].arg = targ_p->name;
1156 mode_changes[mode_count++].client = targ_p;
1157 }
1158 #endif
1159
1160 mode_changes[mode_count].letter = 'o';
1161 mode_changes[mode_count].dir = dir;
1162 mode_changes[mode_count].caps = caps;
1163 mode_changes[mode_count].nocaps = 0;
1164 mode_changes[mode_count].mems = ALL_MEMBERS;
1165 mode_changes[mode_count].id = targ_p->id;
1166 mode_changes[mode_count].arg = targ_p->name;
1167 mode_changes[mode_count++].client = targ_p;
1168
1169 if (dir == MODE_ADD)
1170 {
1171 AddMemberFlag(member, CHFL_CHANOP);
1172 DelMemberFlag(member, CHFL_DEOPPED | CHFL_HALFOP);
1173 }
1174 else
1175 DelMemberFlag(member, CHFL_CHANOP);
1176 }
1177
1178 static void
1179 chm_limit(struct Client *client_p, struct Client *source_p,
1180 struct Channel *chptr, int parc, int *parn,
1181 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
1182 {
1183 unsigned int i;
1184 int limit;
1185 char *lstr;
1186
1187 if (alev < CHACCESS_HALFOP)
1188 {
1189 if (!(*errors & SM_ERR_NOOPS))
1190 sendto_one_numeric(source_p, &me,
1191 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
1192 ERR_CHANOPRIVSNEEDED, chptr->chname);
1193 *errors |= SM_ERR_NOOPS;
1194 return;
1195 }
1196
1197 if (dir == MODE_QUERY)
1198 return;
1199
1200 if ((dir == MODE_ADD) && parc > *parn)
1201 {
1202 lstr = parv[(*parn)++];
1203
1204 if ((limit = atoi(lstr)) <= 0)
1205 return;
1206
1207 sprintf(lstr, "%d", limit);
1208
1209 /* if somebody sets MODE #channel +ll 1 2, accept latter --fl */
1210 for (i = 0; i < mode_count; i++)
1211 if (mode_changes[i].letter == c && mode_changes[i].dir == MODE_ADD)
1212 mode_changes[i].letter = 0;
1213
1214 mode_changes[mode_count].letter = c;
1215 mode_changes[mode_count].dir = MODE_ADD;
1216 mode_changes[mode_count].caps = 0;
1217 mode_changes[mode_count].nocaps = 0;
1218 mode_changes[mode_count].mems = ALL_MEMBERS;
1219 mode_changes[mode_count].id = NULL;
1220 mode_changes[mode_count++].arg = lstr;
1221
1222 chptr->mode.limit = limit;
1223 }
1224 else if (dir == MODE_DEL)
1225 {
1226 if (!chptr->mode.limit)
1227 return;
1228
1229 chptr->mode.limit = 0;
1230
1231 mode_changes[mode_count].letter = c;
1232 mode_changes[mode_count].dir = MODE_DEL;
1233 mode_changes[mode_count].caps = 0;
1234 mode_changes[mode_count].nocaps = 0;
1235 mode_changes[mode_count].mems = ALL_MEMBERS;
1236 mode_changes[mode_count].id = NULL;
1237 mode_changes[mode_count++].arg = NULL;
1238 }
1239 }
1240
1241 static void
1242 chm_key(struct Client *client_p, struct Client *source_p,
1243 struct Channel *chptr, int parc, int *parn,
1244 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
1245 {
1246 unsigned int i;
1247 char *key;
1248
1249 if (alev < CHACCESS_HALFOP)
1250 {
1251 if (!(*errors & SM_ERR_NOOPS))
1252 sendto_one_numeric(source_p, &me,
1253 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
1254 ERR_CHANOPRIVSNEEDED, chptr->chname);
1255 *errors |= SM_ERR_NOOPS;
1256 return;
1257 }
1258
1259 if (dir == MODE_QUERY)
1260 return;
1261
1262 if ((dir == MODE_ADD) && parc > *parn)
1263 {
1264 key = parv[(*parn)++];
1265
1266 if (MyClient(source_p))
1267 fix_key(key);
1268 else
1269 fix_key_old(key);
1270
1271 if (*key == '\0')
1272 return;
1273
1274 assert(key[0] != ' ');
1275 strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key));
1276
1277 /* if somebody does MODE #channel +kk a b, accept latter --fl */
1278 for (i = 0; i < mode_count; i++)
1279 if (mode_changes[i].letter == c && mode_changes[i].dir == MODE_ADD)
1280 mode_changes[i].letter = 0;
1281
1282 mode_changes[mode_count].letter = c;
1283 mode_changes[mode_count].dir = MODE_ADD;
1284 mode_changes[mode_count].caps = 0;
1285 mode_changes[mode_count].nocaps = 0;
1286 mode_changes[mode_count].mems = ALL_MEMBERS;
1287 mode_changes[mode_count].id = NULL;
1288 mode_changes[mode_count++].arg = chptr->mode.key;
1289 }
1290 else if (dir == MODE_DEL)
1291 {
1292 if (parc > *parn)
1293 (*parn)++;
1294
1295 if (chptr->mode.key[0] == '\0')
1296 return;
1297
1298 chptr->mode.key[0] = '\0';
1299
1300 mode_changes[mode_count].letter = c;
1301 mode_changes[mode_count].dir = MODE_DEL;
1302 mode_changes[mode_count].caps = 0;
1303 mode_changes[mode_count].nocaps = 0;
1304 mode_changes[mode_count].mems = ALL_MEMBERS;
1305 mode_changes[mode_count].id = NULL;
1306 mode_changes[mode_count++].arg = "*";
1307 }
1308 }
1309
1310 struct ChannelMode
1311 {
1312 void (*func)(struct Client *, struct Client *,
1313 struct Channel *, int, int *, char **,
1314 int *, int, int, char, unsigned int);
1315 unsigned int d;
1316 };
1317
1318 static struct ChannelMode ModeTable[256] =
1319 {
1320 { chm_nosuch, 0 }, /* 0x00 */
1321 { chm_nosuch, 0 }, /* 0x01 */
1322 { chm_nosuch, 0 }, /* 0x02 */
1323 { chm_nosuch, 0 }, /* 0x03 */
1324 { chm_nosuch, 0 }, /* 0x04 */
1325 { chm_nosuch, 0 }, /* 0x05 */
1326 { chm_nosuch, 0 }, /* 0x06 */
1327 { chm_nosuch, 0 }, /* 0x07 */
1328 { chm_nosuch, 0 }, /* 0x08 */
1329 { chm_nosuch, 0 }, /* 0x09 */
1330 { chm_nosuch, 0 }, /* 0x0a */
1331 { chm_nosuch, 0 }, /* 0x0b */
1332 { chm_nosuch, 0 }, /* 0x0c */
1333 { chm_nosuch, 0 }, /* 0x0d */
1334 { chm_nosuch, 0 }, /* 0x0e */
1335 { chm_nosuch, 0 }, /* 0x0f */
1336 { chm_nosuch, 0 }, /* 0x10 */
1337 { chm_nosuch, 0 }, /* 0x11 */
1338 { chm_nosuch, 0 }, /* 0x12 */
1339 { chm_nosuch, 0 }, /* 0x13 */
1340 { chm_nosuch, 0 }, /* 0x14 */
1341 { chm_nosuch, 0 }, /* 0x15 */
1342 { chm_nosuch, 0 }, /* 0x16 */
1343 { chm_nosuch, 0 }, /* 0x17 */
1344 { chm_nosuch, 0 }, /* 0x18 */
1345 { chm_nosuch, 0 }, /* 0x19 */
1346 { chm_nosuch, 0 }, /* 0x1a */
1347 { chm_nosuch, 0 }, /* 0x1b */
1348 { chm_nosuch, 0 }, /* 0x1c */
1349 { chm_nosuch, 0 }, /* 0x1d */
1350 { chm_nosuch, 0 }, /* 0x1e */
1351 { chm_nosuch, 0 }, /* 0x1f */
1352 { chm_nosuch, 0 }, /* 0x20 */
1353 { chm_nosuch, 0 }, /* 0x21 */
1354 { chm_nosuch, 0 }, /* 0x22 */
1355 { chm_nosuch, 0 }, /* 0x23 */
1356 { chm_nosuch, 0 }, /* 0x24 */
1357 { chm_nosuch, 0 }, /* 0x25 */
1358 { chm_nosuch, 0 }, /* 0x26 */
1359 { chm_nosuch, 0 }, /* 0x27 */
1360 { chm_nosuch, 0 }, /* 0x28 */
1361 { chm_nosuch, 0 }, /* 0x29 */
1362 { chm_nosuch, 0 }, /* 0x2a */
1363 { chm_nosuch, 0 }, /* 0x2b */
1364 { chm_nosuch, 0 }, /* 0x2c */
1365 { chm_nosuch, 0 }, /* 0x2d */
1366 { chm_nosuch, 0 }, /* 0x2e */
1367 { chm_nosuch, 0 }, /* 0x2f */
1368 { chm_nosuch, 0 }, /* 0x30 */
1369 { chm_nosuch, 0 }, /* 0x31 */
1370 { chm_nosuch, 0 }, /* 0x32 */
1371 { chm_nosuch, 0 }, /* 0x33 */
1372 { chm_nosuch, 0 }, /* 0x34 */
1373 { chm_nosuch, 0 }, /* 0x35 */
1374 { chm_nosuch, 0 }, /* 0x36 */
1375 { chm_nosuch, 0 }, /* 0x37 */
1376 { chm_nosuch, 0 }, /* 0x38 */
1377 { chm_nosuch, 0 }, /* 0x39 */
1378 { chm_nosuch, 0 }, /* 0x3a */
1379 { chm_nosuch, 0 }, /* 0x3b */
1380 { chm_nosuch, 0 }, /* 0x3c */
1381 { chm_nosuch, 0 }, /* 0x3d */
1382 { chm_nosuch, 0 }, /* 0x3e */
1383 { chm_nosuch, 0 }, /* 0x3f */
1384 { chm_nosuch, 0 }, /* @ */
1385 { chm_nosuch, 0 }, /* A */
1386 { chm_nosuch, 0 }, /* B */
1387 { chm_nosuch, 0 }, /* C */
1388 { chm_nosuch, 0 }, /* D */
1389 { chm_nosuch, 0 }, /* E */
1390 { chm_nosuch, 0 }, /* F */
1391 { chm_nosuch, 0 }, /* G */
1392 { chm_nosuch, 0 }, /* H */
1393 { chm_invex, 0 }, /* I */
1394 { chm_nosuch, 0 }, /* J */
1395 { chm_nosuch, 0 }, /* K */
1396 { chm_nosuch, 0 }, /* L */
1397 { chm_simple, MODE_MODREG}, /* M */
1398 { chm_nosuch, 0 }, /* N */
1399 { chm_operonly, MODE_OPERONLY}, /* O */
1400 { chm_nosuch, 0 }, /* P */
1401 { chm_nosuch, 0 }, /* Q */
1402 { chm_simple, MODE_REGONLY}, /* R */
1403 { chm_simple, MODE_SSLONLY}, /* S */
1404 { chm_nosuch, 0 }, /* T */
1405 { chm_nosuch, 0 }, /* U */
1406 { chm_nosuch, 0 }, /* V */
1407 { chm_nosuch, 0 }, /* W */
1408 { chm_nosuch, 0 }, /* X */
1409 { chm_nosuch, 0 }, /* Y */
1410 { chm_nosuch, 0 }, /* Z */
1411 { chm_nosuch, 0 },
1412 { chm_nosuch, 0 },
1413 { chm_nosuch, 0 },
1414 { chm_nosuch, 0 },
1415 { chm_nosuch, 0 },
1416 { chm_nosuch, 0 },
1417 { chm_nosuch, 0 }, /* a */
1418 { chm_ban, 0 }, /* b */
1419 { chm_simple, MODE_NOCTRL}, /* c */
1420 { chm_nosuch, 0 }, /* d */
1421 { chm_except, 0 }, /* e */
1422 { chm_nosuch, 0 }, /* f */
1423 { chm_nosuch, 0 }, /* g */
1424 #ifdef HALFOPS
1425 { chm_hop, 0 }, /* h */
1426 #else
1427 { chm_nosuch, 0 }, /* h */
1428 #endif
1429 { chm_simple, MODE_INVITEONLY }, /* i */
1430 { chm_nosuch, 0 }, /* j */
1431 { chm_key, 0 }, /* k */
1432 { chm_limit, 0 }, /* l */
1433 { chm_simple, MODE_MODERATED }, /* m */
1434 { chm_simple, MODE_NOPRIVMSGS }, /* n */
1435 { chm_op, 0 }, /* o */
1436 { chm_simple, MODE_PRIVATE }, /* p */
1437 { chm_nosuch, 0 }, /* q */
1438 { chm_registered, MODE_REGISTERED }, /* r */
1439 { chm_simple, MODE_SECRET }, /* s */
1440 { chm_simple, MODE_TOPICLIMIT }, /* t */
1441 { chm_nosuch, 0 }, /* u */
1442 { chm_voice, 0 }, /* v */
1443 { chm_nosuch, 0 }, /* w */
1444 { chm_nosuch, 0 }, /* x */
1445 { chm_nosuch, 0 }, /* y */
1446 { chm_nosuch, 0 }, /* z */
1447 { chm_nosuch, 0 }, /* 0x7b */
1448 { chm_nosuch, 0 }, /* 0x7c */
1449 { chm_nosuch, 0 }, /* 0x7d */
1450 { chm_nosuch, 0 }, /* 0x7e */
1451 { chm_nosuch, 0 }, /* 0x7f */
1452 { chm_nosuch, 0 }, /* 0x80 */
1453 { chm_nosuch, 0 }, /* 0x81 */
1454 { chm_nosuch, 0 }, /* 0x82 */
1455 { chm_nosuch, 0 }, /* 0x83 */
1456 { chm_nosuch, 0 }, /* 0x84 */
1457 { chm_nosuch, 0 }, /* 0x85 */
1458 { chm_nosuch, 0 }, /* 0x86 */
1459 { chm_nosuch, 0 }, /* 0x87 */
1460 { chm_nosuch, 0 }, /* 0x88 */
1461 { chm_nosuch, 0 }, /* 0x89 */
1462 { chm_nosuch, 0 }, /* 0x8a */
1463 { chm_nosuch, 0 }, /* 0x8b */
1464 { chm_nosuch, 0 }, /* 0x8c */
1465 { chm_nosuch, 0 }, /* 0x8d */
1466 { chm_nosuch, 0 }, /* 0x8e */
1467 { chm_nosuch, 0 }, /* 0x8f */
1468 { chm_nosuch, 0 }, /* 0x90 */
1469 { chm_nosuch, 0 }, /* 0x91 */
1470 { chm_nosuch, 0 }, /* 0x92 */
1471 { chm_nosuch, 0 }, /* 0x93 */
1472 { chm_nosuch, 0 }, /* 0x94 */
1473 { chm_nosuch, 0 }, /* 0x95 */
1474 { chm_nosuch, 0 }, /* 0x96 */
1475 { chm_nosuch, 0 }, /* 0x97 */
1476 { chm_nosuch, 0 }, /* 0x98 */
1477 { chm_nosuch, 0 }, /* 0x99 */
1478 { chm_nosuch, 0 }, /* 0x9a */
1479 { chm_nosuch, 0 }, /* 0x9b */
1480 { chm_nosuch, 0 }, /* 0x9c */
1481 { chm_nosuch, 0 }, /* 0x9d */
1482 { chm_nosuch, 0 }, /* 0x9e */
1483 { chm_nosuch, 0 }, /* 0x9f */
1484 { chm_nosuch, 0 }, /* 0xa0 */
1485 { chm_nosuch, 0 }, /* 0xa1 */
1486 { chm_nosuch, 0 }, /* 0xa2 */
1487 { chm_nosuch, 0 }, /* 0xa3 */
1488 { chm_nosuch, 0 }, /* 0xa4 */
1489 { chm_nosuch, 0 }, /* 0xa5 */
1490 { chm_nosuch, 0 }, /* 0xa6 */
1491 { chm_nosuch, 0 }, /* 0xa7 */
1492 { chm_nosuch, 0 }, /* 0xa8 */
1493 { chm_nosuch, 0 }, /* 0xa9 */
1494 { chm_nosuch, 0 }, /* 0xaa */
1495 { chm_nosuch, 0 }, /* 0xab */
1496 { chm_nosuch, 0 }, /* 0xac */
1497 { chm_nosuch, 0 }, /* 0xad */
1498 { chm_nosuch, 0 }, /* 0xae */
1499 { chm_nosuch, 0 }, /* 0xaf */
1500 { chm_nosuch, 0 }, /* 0xb0 */
1501 { chm_nosuch, 0 }, /* 0xb1 */
1502 { chm_nosuch, 0 }, /* 0xb2 */
1503 { chm_nosuch, 0 }, /* 0xb3 */
1504 { chm_nosuch, 0 }, /* 0xb4 */
1505 { chm_nosuch, 0 }, /* 0xb5 */
1506 { chm_nosuch, 0 }, /* 0xb6 */
1507 { chm_nosuch, 0 }, /* 0xb7 */
1508 { chm_nosuch, 0 }, /* 0xb8 */
1509 { chm_nosuch, 0 }, /* 0xb9 */
1510 { chm_nosuch, 0 }, /* 0xba */
1511 { chm_nosuch, 0 }, /* 0xbb */
1512 { chm_nosuch, 0 }, /* 0xbc */
1513 { chm_nosuch, 0 }, /* 0xbd */
1514 { chm_nosuch, 0 }, /* 0xbe */
1515 { chm_nosuch, 0 }, /* 0xbf */
1516 { chm_nosuch, 0 }, /* 0xc0 */
1517 { chm_nosuch, 0 }, /* 0xc1 */
1518 { chm_nosuch, 0 }, /* 0xc2 */
1519 { chm_nosuch, 0 }, /* 0xc3 */
1520 { chm_nosuch, 0 }, /* 0xc4 */
1521 { chm_nosuch, 0 }, /* 0xc5 */
1522 { chm_nosuch, 0 }, /* 0xc6 */
1523 { chm_nosuch, 0 }, /* 0xc7 */
1524 { chm_nosuch, 0 }, /* 0xc8 */
1525 { chm_nosuch, 0 }, /* 0xc9 */
1526 { chm_nosuch, 0 }, /* 0xca */
1527 { chm_nosuch, 0 }, /* 0xcb */
1528 { chm_nosuch, 0 }, /* 0xcc */
1529 { chm_nosuch, 0 }, /* 0xcd */
1530 { chm_nosuch, 0 }, /* 0xce */
1531 { chm_nosuch, 0 }, /* 0xcf */
1532 { chm_nosuch, 0 }, /* 0xd0 */
1533 { chm_nosuch, 0 }, /* 0xd1 */
1534 { chm_nosuch, 0 }, /* 0xd2 */
1535 { chm_nosuch, 0 }, /* 0xd3 */
1536 { chm_nosuch, 0 }, /* 0xd4 */
1537 { chm_nosuch, 0 }, /* 0xd5 */
1538 { chm_nosuch, 0 }, /* 0xd6 */
1539 { chm_nosuch, 0 }, /* 0xd7 */
1540 { chm_nosuch, 0 }, /* 0xd8 */
1541 { chm_nosuch, 0 }, /* 0xd9 */
1542 { chm_nosuch, 0 }, /* 0xda */
1543 { chm_nosuch, 0 }, /* 0xdb */
1544 { chm_nosuch, 0 }, /* 0xdc */
1545 { chm_nosuch, 0 }, /* 0xdd */
1546 { chm_nosuch, 0 }, /* 0xde */
1547 { chm_nosuch, 0 }, /* 0xdf */
1548 { chm_nosuch, 0 }, /* 0xe0 */
1549 { chm_nosuch, 0 }, /* 0xe1 */
1550 { chm_nosuch, 0 }, /* 0xe2 */
1551 { chm_nosuch, 0 }, /* 0xe3 */
1552 { chm_nosuch, 0 }, /* 0xe4 */
1553 { chm_nosuch, 0 }, /* 0xe5 */
1554 { chm_nosuch, 0 }, /* 0xe6 */
1555 { chm_nosuch, 0 }, /* 0xe7 */
1556 { chm_nosuch, 0 }, /* 0xe8 */
1557 { chm_nosuch, 0 }, /* 0xe9 */
1558 { chm_nosuch, 0 }, /* 0xea */
1559 { chm_nosuch, 0 }, /* 0xeb */
1560 { chm_nosuch, 0 }, /* 0xec */
1561 { chm_nosuch, 0 }, /* 0xed */
1562 { chm_nosuch, 0 }, /* 0xee */
1563 { chm_nosuch, 0 }, /* 0xef */
1564 { chm_nosuch, 0 }, /* 0xf0 */
1565 { chm_nosuch, 0 }, /* 0xf1 */
1566 { chm_nosuch, 0 }, /* 0xf2 */
1567 { chm_nosuch, 0 }, /* 0xf3 */
1568 { chm_nosuch, 0 }, /* 0xf4 */
1569 { chm_nosuch, 0 }, /* 0xf5 */
1570 { chm_nosuch, 0 }, /* 0xf6 */
1571 { chm_nosuch, 0 }, /* 0xf7 */
1572 { chm_nosuch, 0 }, /* 0xf8 */
1573 { chm_nosuch, 0 }, /* 0xf9 */
1574 { chm_nosuch, 0 }, /* 0xfa */
1575 { chm_nosuch, 0 }, /* 0xfb */
1576 { chm_nosuch, 0 }, /* 0xfc */
1577 { chm_nosuch, 0 }, /* 0xfd */
1578 { chm_nosuch, 0 }, /* 0xfe */
1579 { chm_nosuch, 0 }, /* 0xff */
1580 };
1581
1582 /* get_channel_access()
1583 *
1584 * inputs - pointer to Client struct
1585 * - pointer to Membership struct
1586 * output - CHACCESS_CHANOP if we should let them have
1587 * chanop level access, 0 for peon level access.
1588 * side effects - NONE
1589 */
1590 static int
1591 get_channel_access(const struct Client *source_p,
1592 const struct Membership *member)
1593 {
1594 /* Let hacked servers in for now... */
1595 if (!MyClient(source_p))
1596 return CHACCESS_CHANOP;
1597
1598 if (member == NULL)
1599 return CHACCESS_NOTONCHAN;
1600
1601 /* just to be sure.. */
1602 assert(source_p == member->client_p);
1603
1604 if (has_member_flags(member, CHFL_CHANOP))
1605 return CHACCESS_CHANOP;
1606
1607 #ifdef HALFOPS
1608 if (has_member_flags(member, CHFL_HALFOP))
1609 return CHACCESS_HALFOP;
1610 #endif
1611
1612 return CHACCESS_PEON;
1613 }
1614
1615 /* void send_cap_mode_changes(struct Client *client_p,
1616 * struct Client *source_p,
1617 * struct Channel *chptr, int cap, int nocap)
1618 * Input: The client sending(client_p), the source client(source_p),
1619 * the channel to send mode changes for(chptr)
1620 * Output: None.
1621 * Side-effects: Sends the appropriate mode changes to capable servers.
1622 *
1623 * send_cap_mode_changes() will loop the server list itself, because
1624 * at this point in time we have 4 capabs for channels, CAP_IE, CAP_EX,
1625 * and a server could support any number of these..
1626 * so we make the modebufs per server, tailoring them to each servers
1627 * specific demand. Its not very pretty, but its one of the few realistic
1628 * ways to handle having this many capabs for channel modes.. --fl_
1629 *
1630 * Reverted back to my original design, except that we now keep a count
1631 * of the number of servers which each combination as an optimisation, so
1632 * the capabs combinations which are not needed are not worked out. -A1kmm
1633 */
1634 /* rewritten to ensure parabuf < MODEBUFLEN -db */
1635
1636 static void
1637 send_cap_mode_changes(struct Client *client_p, struct Client *source_p,
1638 struct Channel *chptr, unsigned int cap, unsigned int nocap)
1639 {
1640 unsigned int i;
1641 int mbl, pbl, arglen, nc, mc;
1642 int len;
1643 const char *arg = NULL;
1644 char *parptr;
1645 int dir = MODE_QUERY;
1646
1647 mc = 0;
1648 nc = 0;
1649 pbl = 0;
1650
1651 parabuf[0] = '\0';
1652 parptr = parabuf;
1653
1654 mbl = snprintf(modebuf, sizeof(modebuf), ":%s TMODE %lu %s ", source_p->id,
1655 (unsigned long)chptr->channelts, chptr->chname);
1656
1657 /* loop the list of - modes we have */
1658 for (i = 0; i < mode_count; i++)
1659 {
1660 /* if they dont support the cap we need, or they do support a cap they
1661 * cant have, then dont add it to the modebuf.. that way they wont see
1662 * the mode
1663 */
1664 if ((mode_changes[i].letter == 0) ||
1665 ((cap & mode_changes[i].caps) != mode_changes[i].caps) ||
1666 ((nocap & mode_changes[i].nocaps) != mode_changes[i].nocaps))
1667 continue;
1668
1669 arg = mode_changes[i].id;
1670
1671 /* if we're creeping past the buf size, we need to send it and make
1672 * another line for the other modes
1673 * XXX - this could give away server topology with uids being
1674 * different lengths, but not much we can do, except possibly break
1675 * them as if they were the longest of the nick or uid at all times,
1676 * which even then won't work as we don't always know the uid -A1kmm.
1677 */
1678 if (arg != NULL)
1679 arglen = strlen(arg);
1680 else
1681 arglen = 0;
1682
1683 if ((mc == MAXMODEPARAMS) ||
1684 ((arglen + mbl + pbl + 2) > IRCD_BUFSIZE) ||
1685 (pbl + arglen + BAN_FUDGE) >= MODEBUFLEN)
1686 {
1687 if (nc != 0)
1688 sendto_server(client_p, cap, nocap, "%s %s", modebuf, parabuf);
1689 nc = 0;
1690 mc = 0;
1691
1692 mbl = snprintf(modebuf, sizeof(modebuf), ":%s TMODE %lu %s ", source_p->id,
1693 (unsigned long)chptr->channelts, chptr->chname);
1694
1695 pbl = 0;
1696 parabuf[0] = '\0';
1697 parptr = parabuf;
1698 dir = MODE_QUERY;
1699 }
1700
1701 if (dir != mode_changes[i].dir)
1702 {
1703 modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-';
1704 dir = mode_changes[i].dir;
1705 }
1706
1707 modebuf[mbl++] = mode_changes[i].letter;
1708 modebuf[mbl] = '\0';
1709 nc++;
1710
1711 if (arg != NULL)
1712 {
1713 len = sprintf(parptr, "%s ", arg);
1714 pbl += len;
1715 parptr += len;
1716 mc++;
1717 }
1718 }
1719
1720 if (pbl && parabuf[pbl - 1] == ' ')
1721 parabuf[pbl - 1] = 0;
1722
1723 if (nc != 0)
1724 sendto_server(client_p, cap, nocap, "%s %s", modebuf, parabuf);
1725 }
1726
1727 /* void send_mode_changes(struct Client *client_p,
1728 * struct Client *source_p,
1729 * struct Channel *chptr)
1730 * Input: The client sending(client_p), the source client(source_p),
1731 * the channel to send mode changes for(chptr),
1732 * mode change globals.
1733 * Output: None.
1734 * Side-effects: Sends the appropriate mode changes to other clients
1735 * and propagates to servers.
1736 */
1737 /* ensure parabuf < MODEBUFLEN -db */
1738 static void
1739 send_mode_changes(struct Client *client_p, struct Client *source_p,
1740 struct Channel *chptr)
1741 {
1742 unsigned int i;
1743 int mbl, pbl, arglen, nc, mc;
1744 int len;
1745 const char *arg = NULL;
1746 char *parptr;
1747 int dir = MODE_QUERY;
1748
1749 /* bail out if we have nothing to do... */
1750 if (!mode_count)
1751 return;
1752
1753 if (IsServer(source_p))
1754 mbl = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s ", (IsHidden(source_p) ||
1755 ConfigServerHide.hide_servers) ?
1756 me.name : source_p->name, chptr->chname);
1757 else
1758 mbl = snprintf(modebuf, sizeof(modebuf), ":%s!%s@%s MODE %s ", source_p->name,
1759 source_p->username, source_p->host, chptr->chname);
1760
1761 mc = 0;
1762 nc = 0;
1763 pbl = 0;
1764
1765 parabuf[0] = '\0';
1766 parptr = parabuf;
1767
1768 for (i = 0; i < mode_count; i++)
1769 {
1770 if (mode_changes[i].letter == 0 ||
1771 mode_changes[i].mems == NON_CHANOPS ||
1772 mode_changes[i].mems == ONLY_SERVERS)
1773 continue;
1774
1775 arg = mode_changes[i].arg;
1776 if (arg != NULL)
1777 arglen = strlen(arg);
1778 else
1779 arglen = 0;
1780
1781 if ((mc == MAXMODEPARAMS) ||
1782 ((arglen + mbl + pbl + 2) > IRCD_BUFSIZE) ||
1783 ((arglen + pbl + BAN_FUDGE) >= MODEBUFLEN))
1784 {
1785 if (mbl && modebuf[mbl - 1] == '-')
1786 modebuf[mbl - 1] = '\0';
1787
1788 if (nc != 0)
1789 sendto_channel_local(ALL_MEMBERS, 0, chptr, "%s %s", modebuf, parabuf);
1790
1791 nc = 0;
1792 mc = 0;
1793
1794 if (IsServer(source_p))
1795 mbl = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s ", (IsHidden(source_p) ||
1796 ConfigServerHide.hide_servers) ?
1797 me.name : source_p->name, chptr->chname);
1798 else
1799 mbl = snprintf(modebuf, sizeof(modebuf), ":%s!%s@%s MODE %s ", source_p->name,
1800 source_p->username, source_p->host, chptr->chname);
1801
1802 pbl = 0;
1803 parabuf[0] = '\0';
1804 parptr = parabuf;
1805 dir = MODE_QUERY;
1806 }
1807
1808 if (dir != mode_changes[i].dir)
1809 {
1810 modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-';
1811 dir = mode_changes[i].dir;
1812 }
1813
1814 modebuf[mbl++] = mode_changes[i].letter;
1815 modebuf[mbl] = '\0';
1816 nc++;
1817
1818 if (arg != NULL)
1819 {
1820 len = sprintf(parptr, "%s ", arg);
1821 pbl += len;
1822 parptr += len;
1823 mc++;
1824 }
1825 }
1826
1827 if (pbl && parabuf[pbl - 1] == ' ')
1828 parabuf[pbl - 1] = 0;
1829
1830 if (nc != 0)
1831 sendto_channel_local(ALL_MEMBERS, 0, chptr, "%s %s", modebuf, parabuf);
1832
1833 nc = 0;
1834 mc = 0;
1835
1836 /* Now send to servers... */
1837 for (i = 0; i < NCHCAP_COMBOS; i++)
1838 if (chcap_combos[i].count != 0)
1839 send_cap_mode_changes(client_p, source_p, chptr,
1840 chcap_combos[i].cap_yes,
1841 chcap_combos[i].cap_no);
1842 }
1843
1844 /* void set_channel_mode(struct Client *client_p, struct Client *source_p,
1845 * struct Channel *chptr, int parc, char **parv,
1846 * char *chname)
1847 * Input: The client we received this from, the client this originated
1848 * from, the channel, the parameter count starting at the modes,
1849 * the parameters, the channel name.
1850 * Output: None.
1851 * Side-effects: Changes the channel membership and modes appropriately,
1852 * sends the appropriate MODE messages to the appropriate
1853 * clients.
1854 */
1855 void
1856 set_channel_mode(struct Client *client_p, struct Client *source_p, struct Channel *chptr,
1857 struct Membership *member, int parc, char *parv[])
1858 {
1859 int dir = MODE_ADD;
1860 int parn = 1;
1861 int alevel, errors = 0;
1862 char *ml = parv[0], c;
1863
1864 mode_count = 0;
1865 mode_limit = 0;
1866 simple_modes_mask = 0;
1867
1868 alevel = get_channel_access(source_p, member);
1869
1870 for (; (c = *ml); ++ml)
1871 {
1872 switch (c)
1873 {
1874 case '+':
1875 dir = MODE_ADD;
1876 break;
1877 case '-':
1878 dir = MODE_DEL;
1879 break;
1880 case '=':
1881 dir = MODE_QUERY;
1882 break;
1883 default:
1884 {
1885 struct ChannelMode *tptr = &ModeTable[(unsigned char)c];
1886
1887 tptr->func(client_p, source_p, chptr, parc, &parn,
1888 parv, &errors, alevel, dir, c, tptr->d);
1889 break;
1890 }
1891 }
1892 }
1893
1894 send_mode_changes(client_p, source_p, chptr);
1895 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision