ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 3687
Committed: Thu May 29 16:12:37 2014 UTC (11 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 45650 byte(s)
Log Message:
- channel_mode.c:channel_modes(): replaced sprintf with strcat;
  use %u conversion specifier for unsigned ints

File Contents

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

Properties

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