ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 3140
Committed: Wed Mar 12 19:23:20 2014 UTC (11 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 47960 byte(s)
Log Message:
- Get rid of halfop -> op rewriting for servers that don't support halfops

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

Properties

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