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