ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 1793
Committed: Sun Mar 31 14:06:08 2013 UTC (12 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 51461 byte(s)
Log Message:
- Replaced all occurrences of ircsprintf with sprintf/snprintf
  and killed sprintf_irc.(c|h)

File Contents

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

Properties

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