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