/[svn]/ircd-hybrid/trunk/src/channel_mode.c
ViewVC logotype

Contents of /ircd-hybrid/trunk/src/channel_mode.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1654 - (show annotations)
Fri Nov 16 19:39:37 2012 UTC (7 years, 7 months ago) by michael
File MIME type: text/x-chdr
File size: 51582 byte(s)
- Implemented memory pool allocator which basically is taken from Tor's
  mempool allocator for Tor cells
- Fixed compile warnings in conf_class.c
- ./configure --enable-assert works again

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

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28