]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Solanum: a slightly advanced ircd | |
3 | * chmode.c: channel mode management | |
4 | * | |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center | |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
8 | * Copyright (C) 2005-2006 charybdis development team | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License as published by | |
12 | * the Free Software Foundation; either version 2 of the License, or | |
13 | * (at your option) any later version. | |
14 | * | |
15 | * This program is distributed in the hope that it will be useful, | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | * GNU General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with this program; if not, write to the Free Software | |
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
23 | * USA | |
24 | */ | |
25 | ||
26 | #include "stdinc.h" | |
27 | #include "channel.h" | |
28 | #include "client.h" | |
29 | #include "hash.h" | |
30 | #include "hook.h" | |
31 | #include "match.h" | |
32 | #include "ircd.h" | |
33 | #include "numeric.h" | |
34 | #include "s_serv.h" /* captab */ | |
35 | #include "s_user.h" | |
36 | #include "send.h" | |
37 | #include "whowas.h" | |
38 | #include "s_conf.h" /* ConfigFileEntry, ConfigChannel */ | |
39 | #include "s_newconf.h" | |
40 | #include "logger.h" | |
41 | #include "chmode.h" | |
42 | #include "s_assert.h" | |
43 | #include "parse.h" | |
44 | #include "msgbuf.h" | |
45 | #include "packet.h" | |
46 | ||
47 | /* bitmasks for error returns, so we send once per call */ | |
48 | #define SM_ERR_NOTS 0x00000001 /* No TS on channel */ | |
49 | #define SM_ERR_NOOPS 0x00000002 /* No chan ops */ | |
50 | #define SM_ERR_UNKNOWN 0x00000004 | |
51 | #define SM_ERR_RPL_C 0x00000008 | |
52 | #define SM_ERR_RPL_B 0x00000010 | |
53 | #define SM_ERR_RPL_E 0x00000020 | |
54 | #define SM_ERR_NOTONCHANNEL 0x00000040 /* Not on channel */ | |
55 | #define SM_ERR_RPL_I 0x00000100 | |
56 | #define SM_ERR_RPL_D 0x00000200 | |
57 | #define SM_ERR_NOPRIVS 0x00000400 | |
58 | #define SM_ERR_RPL_Q 0x00000800 | |
59 | #define SM_ERR_RPL_F 0x00001000 | |
60 | #define SM_ERR_MLOCK 0x00002000 | |
61 | ||
62 | #define MAXMODES_SIMPLE 46 /* a-zA-Z except bqeIov */ | |
63 | ||
64 | static struct ChModeChange mode_changes[BUFSIZE]; | |
65 | static int mode_count; | |
66 | static int mask_pos; | |
67 | static int removed_mask_pos; | |
68 | ||
69 | char cflagsbuf[256]; | |
70 | char cflagsmyinfo[256]; | |
71 | ||
72 | int chmode_flags[256]; | |
73 | ||
74 | extern int h_get_channel_access; | |
75 | ||
76 | /* OPTIMIZE ME! -- dwr */ | |
77 | void | |
78 | construct_cflags_strings(void) | |
79 | { | |
80 | int i; | |
81 | char *ptr = cflagsbuf; | |
82 | char *ptr2 = cflagsmyinfo; | |
83 | ||
84 | *ptr = '\0'; | |
85 | *ptr2 = '\0'; | |
86 | ||
87 | for(i = 0; i < 256; i++) | |
88 | { | |
89 | if (chmode_table[i].set_func != chm_ban && | |
90 | chmode_table[i].set_func != chm_forward && | |
91 | chmode_table[i].set_func != chm_throttle && | |
92 | chmode_table[i].set_func != chm_key && | |
93 | chmode_table[i].set_func != chm_limit && | |
94 | chmode_table[i].set_func != chm_op && | |
95 | chmode_table[i].set_func != chm_voice) | |
96 | { | |
97 | chmode_flags[i] = chmode_table[i].mode_type; | |
98 | } | |
99 | else | |
100 | { | |
101 | chmode_flags[i] = 0; | |
102 | } | |
103 | ||
104 | switch (chmode_flags[i]) | |
105 | { | |
106 | case MODE_FREETARGET: | |
107 | case MODE_DISFORWARD: | |
108 | if(ConfigChannel.use_forward) | |
109 | *ptr++ = (char) i; | |
110 | break; | |
111 | default: | |
112 | if(chmode_flags[i] != 0) | |
113 | { | |
114 | *ptr++ = (char) i; | |
115 | } | |
116 | } | |
117 | ||
118 | /* Should we leave orphaned check here? -- dwr */ | |
119 | if (chmode_table[i].set_func != NULL && | |
120 | chmode_table[i].set_func != chm_orphaned) | |
121 | { | |
122 | *ptr2++ = (char) i; | |
123 | } | |
124 | } | |
125 | ||
126 | *ptr++ = '\0'; | |
127 | *ptr2++ = '\0'; | |
128 | } | |
129 | ||
130 | /* | |
131 | * find_umode_slot | |
132 | * | |
133 | * inputs - NONE | |
134 | * outputs - an available cflag bitmask or | |
135 | * 0 if no cflags are available | |
136 | * side effects - NONE | |
137 | */ | |
138 | static unsigned int | |
139 | find_cflag_slot(void) | |
140 | { | |
141 | unsigned int all_cflags = 0, my_cflag = 0, i; | |
142 | ||
143 | for (i = 0; i < 256; i++) | |
144 | all_cflags |= chmode_flags[i]; | |
145 | ||
146 | for (my_cflag = 1; my_cflag && (all_cflags & my_cflag); | |
147 | my_cflag <<= 1); | |
148 | ||
149 | return my_cflag; | |
150 | } | |
151 | ||
152 | unsigned int | |
153 | cflag_add(char c_, ChannelModeFunc function) | |
154 | { | |
155 | int c = (unsigned char)c_; | |
156 | ||
157 | if (chmode_table[c].set_func != NULL && | |
158 | chmode_table[c].set_func != chm_orphaned) | |
159 | return 0; | |
160 | ||
161 | if (chmode_table[c].set_func == NULL) | |
162 | chmode_table[c].mode_type = find_cflag_slot(); | |
163 | if (chmode_table[c].mode_type == 0) | |
164 | return 0; | |
165 | chmode_table[c].set_func = function; | |
166 | construct_cflags_strings(); | |
167 | return chmode_table[c].mode_type; | |
168 | } | |
169 | ||
170 | void | |
171 | cflag_orphan(char c_) | |
172 | { | |
173 | int c = (unsigned char)c_; | |
174 | ||
175 | s_assert(chmode_flags[c] != 0); | |
176 | chmode_table[c].set_func = chm_orphaned; | |
177 | construct_cflags_strings(); | |
178 | } | |
179 | ||
180 | int | |
181 | get_channel_access(struct Client *source_p, struct Channel *chptr, struct membership *msptr, int dir, const char *modestr) | |
182 | { | |
183 | hook_data_channel_approval moduledata; | |
184 | ||
185 | if(!MyClient(source_p)) | |
186 | return CHFL_CHANOP; | |
187 | ||
188 | moduledata.client = source_p; | |
189 | moduledata.chptr = chptr; | |
190 | moduledata.msptr = msptr; | |
191 | moduledata.target = NULL; | |
192 | moduledata.approved = (msptr != NULL && is_chanop(msptr)) ? CHFL_CHANOP : CHFL_PEON; | |
193 | moduledata.dir = dir; | |
194 | moduledata.modestr = modestr; | |
195 | ||
196 | call_hook(h_get_channel_access, &moduledata); | |
197 | ||
198 | return moduledata.approved; | |
199 | } | |
200 | ||
201 | /* allow_mode_change() | |
202 | * | |
203 | * Checks if mlock and chanops permit a mode change. | |
204 | * | |
205 | * inputs - client, channel, access level, errors pointer, mode char | |
206 | * outputs - false on failure, true on success | |
207 | * side effects - error message sent on failure | |
208 | */ | |
209 | static bool | |
210 | allow_mode_change(struct Client *source_p, struct Channel *chptr, int alevel, | |
211 | int *errors, char c) | |
212 | { | |
213 | /* If this mode char is locked, don't allow local users to change it. */ | |
214 | if (MyClient(source_p) && chptr->mode_lock && strchr(chptr->mode_lock, c)) | |
215 | { | |
216 | if (!(*errors & SM_ERR_MLOCK)) | |
217 | sendto_one_numeric(source_p, | |
218 | ERR_MLOCKRESTRICTED, | |
219 | form_str(ERR_MLOCKRESTRICTED), | |
220 | chptr->chname, | |
221 | c, | |
222 | chptr->mode_lock); | |
223 | *errors |= SM_ERR_MLOCK; | |
224 | return false; | |
225 | } | |
226 | if(alevel < CHFL_CHANOP) | |
227 | { | |
228 | if(!(*errors & SM_ERR_NOOPS)) | |
229 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
230 | me.name, source_p->name, chptr->chname); | |
231 | *errors |= SM_ERR_NOOPS; | |
232 | return false; | |
233 | } | |
234 | return true; | |
235 | } | |
236 | ||
237 | /* add_id() | |
238 | * | |
239 | * inputs - client, channel, id to add, type, forward | |
240 | * outputs - NULL on failure, allocated Ban on success | |
241 | * side effects - given id is added to the appropriate list | |
242 | */ | |
243 | struct Ban * | |
244 | add_id(struct Client *source_p, struct Channel *chptr, const char *banid, const char *forward, | |
245 | rb_dlink_list * list, long mode_type) | |
246 | { | |
247 | struct Ban *actualBan; | |
248 | static char who[USERHOST_REPLYLEN]; | |
249 | char *realban = LOCAL_COPY(banid); | |
250 | rb_dlink_node *ptr; | |
251 | ||
252 | /* dont let local clients overflow the banlist */ | |
253 | if(MyClient(source_p)) | |
254 | { | |
255 | if((rb_dlink_list_length(&chptr->banlist) + rb_dlink_list_length(&chptr->exceptlist) + rb_dlink_list_length(&chptr->invexlist) + rb_dlink_list_length(&chptr->quietlist)) >= (unsigned long)((chptr->mode.mode & MODE_EXLIMIT) ? ConfigChannel.max_bans_large : ConfigChannel.max_bans)) | |
256 | { | |
257 | sendto_one(source_p, form_str(ERR_BANLISTFULL), | |
258 | me.name, source_p->name, chptr->chname, realban); | |
259 | return NULL; | |
260 | } | |
261 | } | |
262 | ||
263 | /* don't let anyone set duplicate bans */ | |
264 | RB_DLINK_FOREACH(ptr, list->head) | |
265 | { | |
266 | actualBan = ptr->data; | |
267 | if(!irccmp(actualBan->banstr, realban)) | |
268 | return NULL; | |
269 | } | |
270 | ||
271 | if(IsPerson(source_p)) | |
272 | sprintf(who, "%s!%s@%s", source_p->name, source_p->username, source_p->host); | |
273 | else | |
274 | rb_strlcpy(who, source_p->name, sizeof(who)); | |
275 | ||
276 | actualBan = allocate_ban(realban, who, forward); | |
277 | actualBan->when = rb_current_time(); | |
278 | ||
279 | rb_dlinkAdd(actualBan, &actualBan->node, list); | |
280 | ||
281 | /* invalidate the can_send() cache */ | |
282 | if(mode_type == CHFL_BAN || mode_type == CHFL_QUIET || mode_type == CHFL_EXCEPTION) | |
283 | chptr->bants++; | |
284 | ||
285 | return actualBan; | |
286 | } | |
287 | ||
288 | /* del_id() | |
289 | * | |
290 | * inputs - channel, id to remove, type | |
291 | * outputs - pointer to ban that was removed, if any | |
292 | * side effects - given id is removed from the appropriate list and returned | |
293 | */ | |
294 | struct Ban * | |
295 | del_id(struct Channel *chptr, const char *banid, rb_dlink_list * list, long mode_type) | |
296 | { | |
297 | rb_dlink_node *ptr; | |
298 | struct Ban *banptr; | |
299 | ||
300 | if(EmptyString(banid)) | |
301 | return NULL; | |
302 | ||
303 | RB_DLINK_FOREACH(ptr, list->head) | |
304 | { | |
305 | banptr = ptr->data; | |
306 | ||
307 | if(irccmp(banid, banptr->banstr) == 0) | |
308 | { | |
309 | rb_dlinkDelete(&banptr->node, list); | |
310 | ||
311 | /* invalidate the can_send() cache */ | |
312 | if(mode_type == CHFL_BAN || mode_type == CHFL_QUIET || mode_type == CHFL_EXCEPTION) | |
313 | chptr->bants++; | |
314 | ||
315 | return banptr; | |
316 | } | |
317 | } | |
318 | ||
319 | return NULL; | |
320 | } | |
321 | ||
322 | /* check_string() | |
323 | * | |
324 | * input - string to check | |
325 | * output - pointer to 'fixed' string, or "*" if empty | |
326 | * side effects - any white space found becomes \0 | |
327 | */ | |
328 | static char * | |
329 | check_string(char *s) | |
330 | { | |
331 | char *str = s; | |
332 | static char splat[] = "*"; | |
333 | if(!(s && *s)) | |
334 | return splat; | |
335 | ||
336 | for(; *s; ++s) | |
337 | { | |
338 | if(IsSpace(*s)) | |
339 | { | |
340 | *s = '\0'; | |
341 | break; | |
342 | } | |
343 | } | |
344 | return str; | |
345 | } | |
346 | ||
347 | /* pretty_mask() | |
348 | * | |
349 | * inputs - mask to pretty | |
350 | * outputs - better version of the mask | |
351 | * side effects - mask is chopped to limits, and transformed: | |
352 | * x!y@z => x!y@z | |
353 | * y@z => *!y@z | |
354 | * x!y => x!y@* | |
355 | * x => x!*@* | |
356 | * z.d => *!*@z.d | |
357 | */ | |
358 | static char * | |
359 | pretty_mask(const char *idmask) | |
360 | { | |
361 | static char mask_buf[BUFSIZE]; | |
362 | int old_mask_pos; | |
363 | const char *nick, *user, *host, *forward = NULL; | |
364 | char *t, *at, *ex; | |
365 | int nl, ul, hl, fl; | |
366 | char *mask; | |
367 | size_t masklen; | |
368 | ||
369 | mask = LOCAL_COPY(idmask); | |
370 | mask = check_string(mask); | |
371 | collapse(mask); | |
372 | masklen = strlen(mask); | |
373 | ||
374 | nick = user = host = "*"; | |
375 | nl = ul = hl = 1; | |
376 | fl = 0; | |
377 | ||
378 | if((size_t) BUFSIZE - mask_pos < masklen + 5) | |
379 | return NULL; | |
380 | ||
381 | old_mask_pos = mask_pos; | |
382 | ||
383 | if (*mask == '$') | |
384 | { | |
385 | memcpy(mask_buf + mask_pos, mask, masklen + 1); | |
386 | mask_pos += masklen + 1; | |
387 | t = mask_buf + old_mask_pos + 1; | |
388 | if (*t == '!') | |
389 | *t = '~'; | |
390 | if (*t == '~') | |
391 | t++; | |
392 | *t = irctolower(*t); | |
393 | return mask_buf + old_mask_pos; | |
394 | } | |
395 | ||
396 | at = ex = NULL; | |
397 | if((t = memchr(mask, '@', masklen)) != NULL) | |
398 | { | |
399 | at = t; | |
400 | t++; | |
401 | if(*t != '\0') | |
402 | host = t, hl = strlen(t); | |
403 | ||
404 | if((t = memchr(mask, '!', at - mask)) != NULL) | |
405 | { | |
406 | ex = t; | |
407 | t++; | |
408 | if(at != t) | |
409 | user = t, ul = at - t; | |
410 | if(ex != mask) | |
411 | nick = mask, nl = ex - mask; | |
412 | } | |
413 | else | |
414 | { | |
415 | if(at != mask) | |
416 | user = mask, ul = at - mask; | |
417 | } | |
418 | ||
419 | if((t = memchr(host, '!', hl)) != NULL || | |
420 | (t = memchr(host, '$', hl)) != NULL) | |
421 | { | |
422 | t++; | |
423 | if (host + hl != t) | |
424 | forward = t, fl = host + hl - t; | |
425 | hl = t - 1 - host; | |
426 | } | |
427 | } | |
428 | else if((t = memchr(mask, '!', masklen)) != NULL) | |
429 | { | |
430 | ex = t; | |
431 | t++; | |
432 | if(ex != mask) | |
433 | nick = mask, nl = ex - mask; | |
434 | if(*t != '\0') | |
435 | user = t, ul = strlen(t); | |
436 | } | |
437 | else if(memchr(mask, '.', masklen) != NULL || | |
438 | memchr(mask, ':', masklen) != NULL) | |
439 | { | |
440 | host = mask, hl = masklen; | |
441 | } | |
442 | else | |
443 | { | |
444 | if(masklen > 0) | |
445 | nick = mask, nl = masklen; | |
446 | } | |
447 | ||
448 | /* truncate values to max lengths */ | |
449 | if(nl > NICKLEN - 1) | |
450 | nl = NICKLEN - 1; | |
451 | if(ul > USERLEN) | |
452 | ul = USERLEN; | |
453 | if(hl > HOSTLEN) | |
454 | hl = HOSTLEN; | |
455 | if(fl > CHANNELLEN) | |
456 | fl = CHANNELLEN; | |
457 | ||
458 | memcpy(mask_buf + mask_pos, nick, nl), mask_pos += nl; | |
459 | mask_buf[mask_pos++] = '!'; | |
460 | memcpy(mask_buf + mask_pos, user, ul), mask_pos += ul; | |
461 | mask_buf[mask_pos++] = '@'; | |
462 | memcpy(mask_buf + mask_pos, host, hl), mask_pos += hl; | |
463 | if (forward) { | |
464 | mask_buf[mask_pos++] = '$'; | |
465 | memcpy(mask_buf + mask_pos, forward, fl), mask_pos += fl; | |
466 | } | |
467 | mask_buf[mask_pos++] = '\0'; | |
468 | ||
469 | return mask_buf + old_mask_pos; | |
470 | } | |
471 | ||
472 | /* check_forward() | |
473 | * | |
474 | * input - client, channel to set mode on, target channel name | |
475 | * output - true if forwarding should be allowed | |
476 | * side effects - numeric sent if not allowed | |
477 | */ | |
478 | static bool | |
479 | check_forward(struct Client *source_p, struct Channel *chptr, | |
480 | const char *forward) | |
481 | { | |
482 | struct Channel *targptr = NULL; | |
483 | struct membership *msptr; | |
484 | ||
485 | if(!check_channel_name(forward) || | |
486 | (MyClient(source_p) && (strlen(forward) > LOC_CHANNELLEN || hash_find_resv(forward)))) | |
487 | { | |
488 | sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), forward); | |
489 | return false; | |
490 | } | |
491 | /* don't forward to inconsistent target -- jilles */ | |
492 | if(chptr->chname[0] == '#' && forward[0] == '&') | |
493 | { | |
494 | sendto_one_numeric(source_p, ERR_BADCHANNAME, | |
495 | form_str(ERR_BADCHANNAME), forward); | |
496 | return false; | |
497 | } | |
498 | if(MyClient(source_p) && (targptr = find_channel(forward)) == NULL) | |
499 | { | |
500 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
501 | form_str(ERR_NOSUCHCHANNEL), forward); | |
502 | return false; | |
503 | } | |
504 | if(MyClient(source_p) && !(targptr->mode.mode & MODE_FREETARGET)) | |
505 | { | |
506 | if((msptr = find_channel_membership(targptr, source_p)) == NULL || | |
507 | get_channel_access(source_p, targptr, msptr, MODE_QUERY, NULL) < CHFL_CHANOP) | |
508 | { | |
509 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
510 | me.name, source_p->name, targptr->chname); | |
511 | return false; | |
512 | } | |
513 | } | |
514 | return true; | |
515 | } | |
516 | ||
517 | /* fix_key() | |
518 | * | |
519 | * input - key to fix | |
520 | * output - the same key, fixed | |
521 | * side effects - anything below ascii 13 is discarded, ':' discarded, | |
522 | * high ascii is dropped to lower half of ascii table | |
523 | */ | |
524 | static char * | |
525 | fix_key(char *arg) | |
526 | { | |
527 | unsigned char *s, *t, c; | |
528 | ||
529 | for(s = t = (unsigned char *) arg; (c = *s); s++) | |
530 | { | |
531 | c &= 0x7f; | |
532 | if(c != ':' && c != ',' && c > ' ') | |
533 | *t++ = c; | |
534 | } | |
535 | ||
536 | *t = '\0'; | |
537 | return arg; | |
538 | } | |
539 | ||
540 | /* fix_key_remote() | |
541 | * | |
542 | * input - key to fix | |
543 | * ouput - the same key, fixed | |
544 | * side effects - high ascii dropped to lower half of table, | |
545 | * CR/LF/':' are dropped | |
546 | */ | |
547 | static char * | |
548 | fix_key_remote(char *arg) | |
549 | { | |
550 | unsigned char *s, *t, c; | |
551 | ||
552 | for(s = t = (unsigned char *) arg; (c = *s); s++) | |
553 | { | |
554 | c &= 0x7f; | |
555 | if((c != 0x0a) && (c != ':') && (c != ',') && (c != 0x0d) && (c != ' ')) | |
556 | *t++ = c; | |
557 | } | |
558 | ||
559 | *t = '\0'; | |
560 | return arg; | |
561 | } | |
562 | ||
563 | void | |
564 | chm_simple(struct Client *source_p, struct Channel *chptr, | |
565 | int alevel, const char *arg, int *errors, int dir, char c, long mode_type) | |
566 | { | |
567 | if(!allow_mode_change(source_p, chptr, alevel, errors, c)) | |
568 | return; | |
569 | ||
570 | /* setting + */ | |
571 | if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type)) | |
572 | { | |
573 | /* if +f is disabled, ignore an attempt to set +QF locally */ | |
574 | if(!ConfigChannel.use_forward && MyClient(source_p) && | |
575 | (c == 'Q' || c == 'F')) | |
576 | return; | |
577 | ||
578 | chptr->mode.mode |= mode_type; | |
579 | ||
580 | mode_changes[mode_count].letter = c; | |
581 | mode_changes[mode_count].dir = MODE_ADD; | |
582 | mode_changes[mode_count].id = NULL; | |
583 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
584 | mode_changes[mode_count++].arg = NULL; | |
585 | } | |
586 | else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type)) | |
587 | { | |
588 | chptr->mode.mode &= ~mode_type; | |
589 | ||
590 | mode_changes[mode_count].letter = c; | |
591 | mode_changes[mode_count].dir = MODE_DEL; | |
592 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
593 | mode_changes[mode_count].id = NULL; | |
594 | mode_changes[mode_count++].arg = NULL; | |
595 | } | |
596 | } | |
597 | ||
598 | void | |
599 | chm_orphaned(struct Client *source_p, struct Channel *chptr, | |
600 | int alevel, const char *arg, int *errors, int dir, char c, long mode_type) | |
601 | { | |
602 | if(MyClient(source_p)) | |
603 | return; | |
604 | ||
605 | if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type)) | |
606 | { | |
607 | chptr->mode.mode |= mode_type; | |
608 | ||
609 | mode_changes[mode_count].letter = c; | |
610 | mode_changes[mode_count].dir = MODE_ADD; | |
611 | mode_changes[mode_count].id = NULL; | |
612 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
613 | mode_changes[mode_count++].arg = NULL; | |
614 | } | |
615 | else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type)) | |
616 | { | |
617 | chptr->mode.mode &= ~mode_type; | |
618 | ||
619 | mode_changes[mode_count].letter = c; | |
620 | mode_changes[mode_count].dir = MODE_DEL; | |
621 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
622 | mode_changes[mode_count].id = NULL; | |
623 | mode_changes[mode_count++].arg = NULL; | |
624 | } | |
625 | } | |
626 | ||
627 | void | |
628 | chm_hidden(struct Client *source_p, struct Channel *chptr, | |
629 | int alevel, const char *arg, int *errors, int dir, char c, long mode_type) | |
630 | { | |
631 | if(MyClient(source_p) && !IsOperGeneral(source_p)) | |
632 | { | |
633 | if(!(*errors & SM_ERR_NOPRIVS)) | |
634 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES)); | |
635 | *errors |= SM_ERR_NOPRIVS; | |
636 | return; | |
637 | } | |
638 | if(MyClient(source_p) && !IsOperAdmin(source_p)) | |
639 | { | |
640 | if(!(*errors & SM_ERR_NOPRIVS)) | |
641 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, | |
642 | source_p->name, "admin"); | |
643 | *errors |= SM_ERR_NOPRIVS; | |
644 | return; | |
645 | } | |
646 | ||
647 | /* setting + */ | |
648 | if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type)) | |
649 | { | |
650 | chptr->mode.mode |= mode_type; | |
651 | ||
652 | mode_changes[mode_count].letter = c; | |
653 | mode_changes[mode_count].dir = MODE_ADD; | |
654 | mode_changes[mode_count].id = NULL; | |
655 | mode_changes[mode_count].mems = ONLY_OPERS; | |
656 | mode_changes[mode_count++].arg = NULL; | |
657 | } | |
658 | else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type)) | |
659 | { | |
660 | chptr->mode.mode &= ~mode_type; | |
661 | ||
662 | mode_changes[mode_count].letter = c; | |
663 | mode_changes[mode_count].dir = MODE_DEL; | |
664 | mode_changes[mode_count].mems = ONLY_OPERS; | |
665 | mode_changes[mode_count].id = NULL; | |
666 | mode_changes[mode_count++].arg = NULL; | |
667 | } | |
668 | } | |
669 | ||
670 | void | |
671 | chm_staff(struct Client *source_p, struct Channel *chptr, | |
672 | int alevel, const char *arg, int *errors, int dir, char c, long mode_type) | |
673 | { | |
674 | if(MyClient(source_p) && !IsOper(source_p)) | |
675 | { | |
676 | if(!(*errors & SM_ERR_NOPRIVS)) | |
677 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES)); | |
678 | *errors |= SM_ERR_NOPRIVS; | |
679 | return; | |
680 | } | |
681 | if(MyClient(source_p) && !HasPrivilege(source_p, "oper:cmodes")) | |
682 | { | |
683 | if(!(*errors & SM_ERR_NOPRIVS)) | |
684 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, | |
685 | source_p->name, "cmodes"); | |
686 | *errors |= SM_ERR_NOPRIVS; | |
687 | return; | |
688 | } | |
689 | ||
690 | /* setting + */ | |
691 | if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type)) | |
692 | { | |
693 | chptr->mode.mode |= mode_type; | |
694 | ||
695 | mode_changes[mode_count].letter = c; | |
696 | mode_changes[mode_count].dir = MODE_ADD; | |
697 | mode_changes[mode_count].id = NULL; | |
698 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
699 | mode_changes[mode_count++].arg = NULL; | |
700 | } | |
701 | else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type)) | |
702 | { | |
703 | chptr->mode.mode &= ~mode_type; | |
704 | ||
705 | mode_changes[mode_count].letter = c; | |
706 | mode_changes[mode_count].dir = MODE_DEL; | |
707 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
708 | mode_changes[mode_count].id = NULL; | |
709 | mode_changes[mode_count++].arg = NULL; | |
710 | } | |
711 | } | |
712 | ||
713 | void | |
714 | chm_ban(struct Client *source_p, struct Channel *chptr, | |
715 | int alevel, const char *arg, int *errors, int dir, char c, long mode_type) | |
716 | { | |
717 | const char *mask; | |
718 | char *forward; | |
719 | rb_dlink_list *list; | |
720 | rb_dlink_node *ptr; | |
721 | struct Ban *banptr; | |
722 | int errorval; | |
723 | const char *rpl_list_p; | |
724 | const char *rpl_endlist_p; | |
725 | int mems; | |
726 | ||
727 | switch (mode_type) | |
728 | { | |
729 | case CHFL_BAN: | |
730 | list = &chptr->banlist; | |
731 | errorval = SM_ERR_RPL_B; | |
732 | rpl_list_p = form_str(RPL_BANLIST); | |
733 | rpl_endlist_p = form_str(RPL_ENDOFBANLIST); | |
734 | mems = ALL_MEMBERS; | |
735 | break; | |
736 | ||
737 | case CHFL_EXCEPTION: | |
738 | /* if +e is disabled, allow all but +e locally */ | |
739 | if (!ConfigChannel.use_except && MyClient(source_p) && dir == MODE_ADD) | |
740 | return; | |
741 | ||
742 | list = &chptr->exceptlist; | |
743 | errorval = SM_ERR_RPL_E; | |
744 | rpl_list_p = form_str(RPL_EXCEPTLIST); | |
745 | rpl_endlist_p = form_str(RPL_ENDOFEXCEPTLIST); | |
746 | ||
747 | if(ConfigChannel.use_except || (dir == MODE_DEL)) | |
748 | mems = ONLY_CHANOPS; | |
749 | else | |
750 | mems = ONLY_SERVERS; | |
751 | break; | |
752 | ||
753 | case CHFL_INVEX: | |
754 | /* if +I is disabled, allow all but +I locally */ | |
755 | if (!ConfigChannel.use_invex && MyClient(source_p) && dir == MODE_ADD) | |
756 | return; | |
757 | ||
758 | list = &chptr->invexlist; | |
759 | errorval = SM_ERR_RPL_I; | |
760 | rpl_list_p = form_str(RPL_INVITELIST); | |
761 | rpl_endlist_p = form_str(RPL_ENDOFINVITELIST); | |
762 | ||
763 | if(ConfigChannel.use_invex || (dir == MODE_DEL)) | |
764 | mems = ONLY_CHANOPS; | |
765 | else | |
766 | mems = ONLY_SERVERS; | |
767 | break; | |
768 | ||
769 | case CHFL_QUIET: | |
770 | list = &chptr->quietlist; | |
771 | errorval = SM_ERR_RPL_Q; | |
772 | rpl_list_p = form_str(RPL_QUIETLIST); | |
773 | rpl_endlist_p = form_str(RPL_ENDOFQUIETLIST); | |
774 | mems = ALL_MEMBERS; | |
775 | break; | |
776 | ||
777 | default: | |
778 | sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "chm_ban() called with unknown type!"); | |
779 | return; | |
780 | } | |
781 | ||
782 | if (dir == MODE_QUERY) | |
783 | { | |
784 | if((*errors & errorval) != 0) | |
785 | return; | |
786 | *errors |= errorval; | |
787 | ||
788 | /* non-ops cant see +eI lists.. */ | |
789 | /* note that this is still permitted if +e/+I are mlocked. */ | |
790 | if(alevel < CHFL_CHANOP && mode_type != CHFL_BAN && | |
791 | mode_type != CHFL_QUIET) | |
792 | { | |
793 | if(!(*errors & SM_ERR_NOOPS)) | |
794 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
795 | me.name, source_p->name, chptr->chname); | |
796 | *errors |= SM_ERR_NOOPS; | |
797 | return; | |
798 | } | |
799 | ||
800 | RB_DLINK_FOREACH(ptr, list->head) | |
801 | { | |
802 | char buf[BANLEN]; | |
803 | banptr = ptr->data; | |
804 | if(banptr->forward) | |
805 | snprintf(buf, sizeof(buf), "%s$%s", banptr->banstr, banptr->forward); | |
806 | else | |
807 | rb_strlcpy(buf, banptr->banstr, sizeof(buf)); | |
808 | ||
809 | sendto_one(source_p, rpl_list_p, | |
810 | me.name, source_p->name, chptr->chname, | |
811 | buf, banptr->who, banptr->when); | |
812 | } | |
813 | sendto_one(source_p, rpl_endlist_p, me.name, source_p->name, chptr->chname); | |
814 | return; | |
815 | } | |
816 | ||
817 | if (!allow_mode_change(source_p, chptr, alevel, errors, c)) | |
818 | return; | |
819 | ||
820 | /* empty ban, or starts with ':' which messes up s2s, ignore it */ | |
821 | if (EmptyString(arg) || *arg == ':') | |
822 | return; | |
823 | ||
824 | if (!MyClient(source_p)) | |
825 | { | |
826 | if (strchr(arg, ' ')) | |
827 | return; | |
828 | ||
829 | mask = arg; | |
830 | } | |
831 | else | |
832 | mask = pretty_mask(arg); | |
833 | ||
834 | /* we'd have problems parsing this, hyb6 does it too | |
835 | * also make sure it will always fit on a line with channel | |
836 | * name etc. | |
837 | */ | |
838 | if(strlen(mask) > MIN(BANLEN, MODEBUFLEN - 5)) | |
839 | { | |
840 | sendto_one_numeric(source_p, ERR_INVALIDBAN, | |
841 | form_str(ERR_INVALIDBAN), | |
842 | chptr->chname, c, arg); | |
843 | return; | |
844 | } | |
845 | ||
846 | /* Look for a $ after the first character. | |
847 | * As the first character, it marks an extban; afterwards | |
848 | * it delimits a forward channel. | |
849 | */ | |
850 | if ((forward = strchr(mask+1, '$')) != NULL) | |
851 | { | |
852 | *forward++ = '\0'; | |
853 | if (*forward == '\0') | |
854 | forward = NULL; | |
855 | } | |
856 | ||
857 | /* if we're adding a NEW id */ | |
858 | if (dir == MODE_ADD) | |
859 | { | |
860 | if (*mask == '$' && MyClient(source_p)) | |
861 | { | |
862 | if (!valid_extban(mask, source_p, chptr, mode_type)) | |
863 | { | |
864 | sendto_one_numeric(source_p, ERR_INVALIDBAN, | |
865 | form_str(ERR_INVALIDBAN), | |
866 | chptr->chname, c, arg); | |
867 | return; | |
868 | } | |
869 | } | |
870 | ||
871 | /* For compatibility, only check the forward channel from | |
872 | * local clients. Accept any forward channel from servers. | |
873 | */ | |
874 | if (forward != NULL && MyClient(source_p)) | |
875 | { | |
876 | /* For simplicity and future flexibility, do not | |
877 | * allow '$' in forwarding targets. | |
878 | */ | |
879 | if (!ConfigChannel.use_forward || | |
880 | strchr(forward, '$') != NULL) | |
881 | { | |
882 | sendto_one_numeric(source_p, ERR_INVALIDBAN, | |
883 | form_str(ERR_INVALIDBAN), | |
884 | chptr->chname, c, arg); | |
885 | return; | |
886 | } | |
887 | /* check_forward() sends its own error message */ | |
888 | if (!check_forward(source_p, chptr, forward)) | |
889 | return; | |
890 | /* Forwards only make sense for bans. */ | |
891 | if (mode_type != CHFL_BAN) | |
892 | { | |
893 | sendto_one_numeric(source_p, ERR_INVALIDBAN, | |
894 | form_str(ERR_INVALIDBAN), | |
895 | chptr->chname, c, arg); | |
896 | return; | |
897 | } | |
898 | } | |
899 | ||
900 | /* dont allow local clients to overflow the banlist, dont | |
901 | * let remote servers set duplicate bans | |
902 | */ | |
903 | if (!add_id(source_p, chptr, mask, forward, list, mode_type)) | |
904 | return; | |
905 | ||
906 | if (forward) | |
907 | forward[-1]= '$'; | |
908 | ||
909 | mode_changes[mode_count].letter = c; | |
910 | mode_changes[mode_count].dir = MODE_ADD; | |
911 | mode_changes[mode_count].mems = mems; | |
912 | mode_changes[mode_count].id = NULL; | |
913 | mode_changes[mode_count++].arg = mask; | |
914 | } | |
915 | else if (dir == MODE_DEL) | |
916 | { | |
917 | struct Ban *removed; | |
918 | static char buf[BANLEN * MAXMODEPARAMS]; | |
919 | int old_removed_mask_pos = removed_mask_pos; | |
920 | if ((removed = del_id(chptr, mask, list, mode_type)) == NULL) | |
921 | { | |
922 | /* mask isn't a valid ban, check arg */ | |
923 | if ((removed = del_id(chptr, arg, list, mode_type)) != NULL) | |
924 | mask = arg; | |
925 | } | |
926 | ||
927 | if (removed && removed->forward) | |
928 | removed_mask_pos += snprintf(buf + old_removed_mask_pos, sizeof(buf) - old_removed_mask_pos, "%s$%s", removed->banstr, removed->forward) + 1; | |
929 | else | |
930 | removed_mask_pos += rb_strlcpy(buf + old_removed_mask_pos, removed ? removed->banstr : mask, sizeof(buf)) + 1; | |
931 | if (removed) | |
932 | { | |
933 | free_ban(removed); | |
934 | removed = NULL; | |
935 | } | |
936 | ||
937 | mode_changes[mode_count].letter = c; | |
938 | mode_changes[mode_count].dir = MODE_DEL; | |
939 | mode_changes[mode_count].mems = mems; | |
940 | mode_changes[mode_count].id = NULL; | |
941 | mode_changes[mode_count++].arg = buf + old_removed_mask_pos; | |
942 | } | |
943 | } | |
944 | ||
945 | void | |
946 | chm_op(struct Client *source_p, struct Channel *chptr, | |
947 | int alevel, const char *arg, int *errors, int dir, char c, long mode_type) | |
948 | { | |
949 | struct membership *mstptr; | |
950 | struct Client *targ_p; | |
951 | ||
952 | if(!allow_mode_change(source_p, chptr, alevel, errors, c)) | |
953 | return; | |
954 | ||
955 | /* empty nick */ | |
956 | if(EmptyString(arg)) | |
957 | { | |
958 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*"); | |
959 | return; | |
960 | } | |
961 | ||
962 | if((targ_p = find_chasing(source_p, arg, NULL)) == NULL) | |
963 | { | |
964 | return; | |
965 | } | |
966 | ||
967 | mstptr = find_channel_membership(chptr, targ_p); | |
968 | ||
969 | if(mstptr == NULL) | |
970 | { | |
971 | if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p)) | |
972 | sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, | |
973 | form_str(ERR_USERNOTINCHANNEL), arg, chptr->chname); | |
974 | *errors |= SM_ERR_NOTONCHANNEL; | |
975 | return; | |
976 | } | |
977 | ||
978 | if(dir == MODE_ADD) | |
979 | { | |
980 | if(targ_p == source_p && mstptr->flags & CHFL_CHANOP) | |
981 | return; | |
982 | ||
983 | mode_changes[mode_count].letter = c; | |
984 | mode_changes[mode_count].dir = MODE_ADD; | |
985 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
986 | mode_changes[mode_count].id = targ_p->id; | |
987 | mode_changes[mode_count++].arg = targ_p->name; | |
988 | ||
989 | mstptr->flags |= CHFL_CHANOP; | |
990 | } | |
991 | else | |
992 | { | |
993 | if(MyClient(source_p) && IsService(targ_p)) | |
994 | { | |
995 | sendto_one(source_p, form_str(ERR_ISCHANSERVICE), | |
996 | me.name, source_p->name, targ_p->name, chptr->chname); | |
997 | return; | |
998 | } | |
999 | ||
1000 | mode_changes[mode_count].letter = c; | |
1001 | mode_changes[mode_count].dir = MODE_DEL; | |
1002 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1003 | mode_changes[mode_count].id = targ_p->id; | |
1004 | mode_changes[mode_count++].arg = targ_p->name; | |
1005 | ||
1006 | mstptr->flags &= ~CHFL_CHANOP; | |
1007 | } | |
1008 | } | |
1009 | ||
1010 | void | |
1011 | chm_voice(struct Client *source_p, struct Channel *chptr, | |
1012 | int alevel, const char *arg, int *errors, int dir, char c, long mode_type) | |
1013 | { | |
1014 | struct membership *mstptr; | |
1015 | struct Client *targ_p; | |
1016 | ||
1017 | if(!allow_mode_change(source_p, chptr, alevel, errors, c)) | |
1018 | return; | |
1019 | ||
1020 | /* empty nick */ | |
1021 | if(EmptyString(arg)) | |
1022 | { | |
1023 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*"); | |
1024 | return; | |
1025 | } | |
1026 | ||
1027 | if((targ_p = find_chasing(source_p, arg, NULL)) == NULL) | |
1028 | { | |
1029 | return; | |
1030 | } | |
1031 | ||
1032 | mstptr = find_channel_membership(chptr, targ_p); | |
1033 | ||
1034 | if(mstptr == NULL) | |
1035 | { | |
1036 | if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p)) | |
1037 | sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, | |
1038 | form_str(ERR_USERNOTINCHANNEL), arg, chptr->chname); | |
1039 | *errors |= SM_ERR_NOTONCHANNEL; | |
1040 | return; | |
1041 | } | |
1042 | ||
1043 | if(dir == MODE_ADD) | |
1044 | { | |
1045 | mode_changes[mode_count].letter = c; | |
1046 | mode_changes[mode_count].dir = MODE_ADD; | |
1047 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1048 | mode_changes[mode_count].id = targ_p->id; | |
1049 | mode_changes[mode_count++].arg = targ_p->name; | |
1050 | ||
1051 | mstptr->flags |= CHFL_VOICE; | |
1052 | } | |
1053 | else | |
1054 | { | |
1055 | mode_changes[mode_count].letter = 'v'; | |
1056 | mode_changes[mode_count].dir = MODE_DEL; | |
1057 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1058 | mode_changes[mode_count].id = targ_p->id; | |
1059 | mode_changes[mode_count++].arg = targ_p->name; | |
1060 | ||
1061 | mstptr->flags &= ~CHFL_VOICE; | |
1062 | } | |
1063 | } | |
1064 | ||
1065 | void | |
1066 | chm_limit(struct Client *source_p, struct Channel *chptr, | |
1067 | int alevel, const char *arg, int *errors, int dir, char c, long mode_type) | |
1068 | { | |
1069 | static char limitstr[30]; | |
1070 | int limit; | |
1071 | ||
1072 | if (!allow_mode_change(source_p, chptr, alevel, errors, c)) | |
1073 | return; | |
1074 | ||
1075 | if (dir == MODE_ADD) | |
1076 | { | |
1077 | if (EmptyString(arg) || (limit = atoi(arg)) <= 0) | |
1078 | return; | |
1079 | ||
1080 | sprintf(limitstr, "%d", limit); | |
1081 | ||
1082 | mode_changes[mode_count].letter = c; | |
1083 | mode_changes[mode_count].dir = MODE_ADD; | |
1084 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1085 | mode_changes[mode_count].id = NULL; | |
1086 | mode_changes[mode_count++].arg = limitstr; | |
1087 | ||
1088 | chptr->mode.limit = limit; | |
1089 | } | |
1090 | else if (dir == MODE_DEL) | |
1091 | { | |
1092 | if(!chptr->mode.limit) | |
1093 | return; | |
1094 | ||
1095 | chptr->mode.limit = 0; | |
1096 | ||
1097 | mode_changes[mode_count].letter = c; | |
1098 | mode_changes[mode_count].dir = MODE_DEL; | |
1099 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1100 | mode_changes[mode_count].id = NULL; | |
1101 | mode_changes[mode_count++].arg = NULL; | |
1102 | } | |
1103 | } | |
1104 | ||
1105 | void | |
1106 | chm_throttle(struct Client *source_p, struct Channel *chptr, | |
1107 | int alevel, const char *arg, int *errors, int dir, char c, long mode_type) | |
1108 | { | |
1109 | int joins = 0, timeslice = 0; | |
1110 | ||
1111 | if (!allow_mode_change(source_p, chptr, alevel, errors, c)) | |
1112 | return; | |
1113 | ||
1114 | if (dir == MODE_ADD) | |
1115 | { | |
1116 | if (sscanf(arg, "%d:%d", &joins, ×lice) < 2) | |
1117 | return; | |
1118 | ||
1119 | if(joins <= 0 || timeslice <= 0) | |
1120 | return; | |
1121 | ||
1122 | mode_changes[mode_count].letter = c; | |
1123 | mode_changes[mode_count].dir = MODE_ADD; | |
1124 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1125 | mode_changes[mode_count].id = NULL; | |
1126 | mode_changes[mode_count++].arg = arg; | |
1127 | ||
1128 | chptr->mode.join_num = joins; | |
1129 | chptr->mode.join_time = timeslice; | |
1130 | } | |
1131 | else if(dir == MODE_DEL) | |
1132 | { | |
1133 | if(!chptr->mode.join_num) | |
1134 | return; | |
1135 | ||
1136 | chptr->mode.join_num = 0; | |
1137 | chptr->mode.join_time = 0; | |
1138 | chptr->join_count = 0; | |
1139 | chptr->join_delta = 0; | |
1140 | ||
1141 | mode_changes[mode_count].letter = c; | |
1142 | mode_changes[mode_count].dir = MODE_DEL; | |
1143 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1144 | mode_changes[mode_count].id = NULL; | |
1145 | mode_changes[mode_count++].arg = NULL; | |
1146 | } | |
1147 | } | |
1148 | ||
1149 | void | |
1150 | chm_forward(struct Client *source_p, struct Channel *chptr, | |
1151 | int alevel, const char *arg, int *errors, int dir, char c, long mode_type) | |
1152 | { | |
1153 | /* if +f is disabled, ignore local attempts to set it */ | |
1154 | if (!ConfigChannel.use_forward && MyClient(source_p) && dir == MODE_ADD) | |
1155 | return; | |
1156 | ||
1157 | if (dir == MODE_QUERY) | |
1158 | { | |
1159 | if (!(*errors & SM_ERR_RPL_F)) | |
1160 | { | |
1161 | if (*chptr->mode.forward == '\0') | |
1162 | sendto_one_notice(source_p, ":%s has no forward channel", chptr->chname); | |
1163 | else | |
1164 | sendto_one_notice(source_p, ":%s forward channel is %s", chptr->chname, chptr->mode.forward); | |
1165 | *errors |= SM_ERR_RPL_F; | |
1166 | } | |
1167 | return; | |
1168 | } | |
1169 | ||
1170 | #ifndef FORWARD_OPERONLY | |
1171 | if (!allow_mode_change(source_p, chptr, alevel, errors, c)) | |
1172 | return; | |
1173 | #else | |
1174 | if (!IsOperGeneral(source_p) && !IsServer(source_p)) | |
1175 | { | |
1176 | if(!(*errors & SM_ERR_NOPRIVS)) | |
1177 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES)); | |
1178 | *errors |= SM_ERR_NOPRIVS; | |
1179 | return; | |
1180 | } | |
1181 | #endif | |
1182 | ||
1183 | if (dir == MODE_ADD) | |
1184 | { | |
1185 | if(EmptyString(arg)) | |
1186 | return; | |
1187 | ||
1188 | if(!check_forward(source_p, chptr, arg)) | |
1189 | return; | |
1190 | ||
1191 | rb_strlcpy(chptr->mode.forward, arg, sizeof(chptr->mode.forward)); | |
1192 | ||
1193 | mode_changes[mode_count].letter = c; | |
1194 | mode_changes[mode_count].dir = MODE_ADD; | |
1195 | mode_changes[mode_count].mems = | |
1196 | ConfigChannel.use_forward ? ALL_MEMBERS : ONLY_SERVERS; | |
1197 | mode_changes[mode_count].id = NULL; | |
1198 | mode_changes[mode_count++].arg = arg; | |
1199 | } | |
1200 | else if(dir == MODE_DEL) | |
1201 | { | |
1202 | if(!(*chptr->mode.forward)) | |
1203 | return; | |
1204 | ||
1205 | *chptr->mode.forward = '\0'; | |
1206 | ||
1207 | mode_changes[mode_count].letter = c; | |
1208 | mode_changes[mode_count].dir = MODE_DEL; | |
1209 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1210 | mode_changes[mode_count].id = NULL; | |
1211 | mode_changes[mode_count++].arg = NULL; | |
1212 | } | |
1213 | } | |
1214 | ||
1215 | void | |
1216 | chm_key(struct Client *source_p, struct Channel *chptr, | |
1217 | int alevel, const char *arg, int *errors, int dir, char c, long mode_type) | |
1218 | { | |
1219 | char *key; | |
1220 | ||
1221 | if (!allow_mode_change(source_p, chptr, alevel, errors, c)) | |
1222 | return; | |
1223 | ||
1224 | if (dir == MODE_ADD) | |
1225 | { | |
1226 | key = LOCAL_COPY(arg); | |
1227 | ||
1228 | if(MyClient(source_p)) | |
1229 | fix_key(key); | |
1230 | else | |
1231 | fix_key_remote(key); | |
1232 | ||
1233 | if(EmptyString(key)) | |
1234 | return; | |
1235 | ||
1236 | s_assert(key[0] != ' '); | |
1237 | rb_strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key)); | |
1238 | ||
1239 | mode_changes[mode_count].letter = c; | |
1240 | mode_changes[mode_count].dir = MODE_ADD; | |
1241 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1242 | mode_changes[mode_count].id = NULL; | |
1243 | mode_changes[mode_count++].arg = chptr->mode.key; | |
1244 | } | |
1245 | else if(dir == MODE_DEL) | |
1246 | { | |
1247 | static char splat[] = "*"; | |
1248 | int i; | |
1249 | ||
1250 | if(!(*chptr->mode.key)) | |
1251 | return; | |
1252 | ||
1253 | /* hack time. when we get a +k-k mode, the +k arg is | |
1254 | * chptr->mode.key, which the -k sets to \0, so hunt for a | |
1255 | * +k when we get a -k, and set the arg to splat. --anfl | |
1256 | */ | |
1257 | for(i = 0; i < mode_count; i++) | |
1258 | { | |
1259 | if(mode_changes[i].letter == 'k' && mode_changes[i].dir == MODE_ADD) | |
1260 | mode_changes[i].arg = splat; | |
1261 | } | |
1262 | ||
1263 | *chptr->mode.key = 0; | |
1264 | ||
1265 | mode_changes[mode_count].letter = c; | |
1266 | mode_changes[mode_count].dir = MODE_DEL; | |
1267 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1268 | mode_changes[mode_count].id = NULL; | |
1269 | mode_changes[mode_count++].arg = "*"; | |
1270 | } | |
1271 | } | |
1272 | ||
1273 | /* *INDENT-OFF* */ | |
1274 | struct ChannelMode chmode_table[256] = | |
1275 | { | |
1276 | ['F'] = {chm_simple, MODE_FREETARGET, 0 }, | |
1277 | ['I'] = {chm_ban, CHFL_INVEX, CHM_QUERYABLE | CHM_OPS_QUERY }, | |
1278 | ['L'] = {chm_staff, MODE_EXLIMIT, 0 }, | |
1279 | ['P'] = {chm_staff, MODE_PERMANENT, 0 }, | |
1280 | ['Q'] = {chm_simple, MODE_DISFORWARD, 0 }, | |
1281 | ['b'] = {chm_ban, CHFL_BAN, CHM_QUERYABLE }, | |
1282 | ['e'] = {chm_ban, CHFL_EXCEPTION, CHM_QUERYABLE | CHM_OPS_QUERY }, | |
1283 | ['f'] = {chm_forward, 0, CHM_ARG_SET | CHM_CAN_QUERY }, /* weird because it's nonstandard and violates isupport */ | |
1284 | ['g'] = {chm_simple, MODE_FREEINVITE, 0 }, | |
1285 | ['i'] = {chm_simple, MODE_INVITEONLY, 0 }, | |
1286 | ['j'] = {chm_throttle, 0, CHM_ARG_SET }, | |
1287 | ['k'] = {chm_key, 0, CHM_QUERYABLE }, | |
1288 | ['l'] = {chm_limit, 0, CHM_ARG_SET }, | |
1289 | ['m'] = {chm_simple, MODE_MODERATED, 0 }, | |
1290 | ['n'] = {chm_simple, MODE_NOPRIVMSGS, 0 }, | |
1291 | ['o'] = {chm_op, 0, CHM_ARGS }, | |
1292 | ['p'] = {chm_simple, MODE_PRIVATE, 0 }, | |
1293 | ['q'] = {chm_ban, CHFL_QUIET, CHM_QUERYABLE }, | |
1294 | ['r'] = {chm_simple, MODE_REGONLY, 0 }, | |
1295 | ['s'] = {chm_simple, MODE_SECRET, 0 }, | |
1296 | ['t'] = {chm_simple, MODE_TOPICLIMIT, 0 }, | |
1297 | ['v'] = {chm_voice, 0, CHM_ARGS }, | |
1298 | ['z'] = {chm_simple, MODE_OPMODERATE, 0 }, | |
1299 | }; | |
1300 | ||
1301 | /* *INDENT-ON* */ | |
1302 | ||
1303 | /* set_channel_mode() | |
1304 | * | |
1305 | * inputs - client, source, channel, membership pointer, params | |
1306 | * output - | |
1307 | * side effects - channel modes/memberships are changed, MODE is issued | |
1308 | * | |
1309 | * Extensively modified to be hotpluggable, 03/09/06 -- nenolod | |
1310 | */ | |
1311 | void | |
1312 | set_channel_mode(struct Client *client_p, struct Client *source_p, | |
1313 | struct Channel *chptr, struct membership *msptr, int parc, const char *parv[]) | |
1314 | { | |
1315 | static char modebuf[BUFSIZE * 2]; /* paranoid case: 2 canonical chars per input char */ | |
1316 | static char parabuf[BUFSIZE]; | |
1317 | char *mbuf; | |
1318 | char *pbuf; | |
1319 | int cur_len, mlen, paralen, paracount, arglen, len; | |
1320 | int i, j, flags; | |
1321 | int dir = MODE_ADD; | |
1322 | bool changes = false; | |
1323 | bool privileged_query = false; | |
1324 | int parn = 1; | |
1325 | int errors = 0; | |
1326 | int alevel; | |
1327 | const char *ml = parv[0]; | |
1328 | char c; | |
1329 | struct Client *fakesource_p; | |
1330 | int flags_list[3] = { ALL_MEMBERS, ONLY_CHANOPS, ONLY_OPERS }; | |
1331 | int mode_limit = 0; | |
1332 | int mode_limit_simple = 0; | |
1333 | ||
1334 | mask_pos = 0; | |
1335 | removed_mask_pos = 0; | |
1336 | mode_count = 0; | |
1337 | ||
1338 | /* Hide connecting server on netburst -- jilles */ | |
1339 | if (ConfigServerHide.flatten_links && IsServer(source_p) && !has_id(source_p) && !HasSentEob(source_p)) | |
1340 | fakesource_p = &me; | |
1341 | else | |
1342 | fakesource_p = source_p; | |
1343 | ||
1344 | struct modeset { | |
1345 | const struct ChannelMode *cm; | |
1346 | const char *arg; | |
1347 | int dir; | |
1348 | char mode; | |
1349 | }; | |
1350 | ||
1351 | static struct modeset modesets[MAXMODEPARAMS + MAXMODES_SIMPLE]; | |
1352 | struct modeset *ms = modesets, *mend; | |
1353 | char canon_op = '\0'; | |
1354 | ||
1355 | mbuf = modebuf; | |
1356 | ||
1357 | for (ml = parv[0]; *ml != 0 && ms - modesets < ARRAY_SIZE(modesets); ml++) | |
1358 | { | |
1359 | c = *ml; | |
1360 | switch (c) | |
1361 | { | |
1362 | case '+': | |
1363 | dir = MODE_ADD; | |
1364 | break; | |
1365 | case '-': | |
1366 | dir = MODE_DEL; | |
1367 | break; | |
1368 | case '=': | |
1369 | dir = MODE_QUERY; | |
1370 | break; | |
1371 | default: | |
1372 | { | |
1373 | int effective_dir = dir; | |
1374 | const struct ChannelMode *cm = &chmode_table[(unsigned char) c]; | |
1375 | bool use_arg = dir == MODE_ADD ? cm->flags & CHM_ARG_SET : | |
1376 | dir == MODE_DEL ? cm->flags & CHM_ARG_DEL : | |
1377 | false; | |
1378 | if (cm->set_func == NULL) | |
1379 | { | |
1380 | sendto_one(source_p, form_str(ERR_UNKNOWNMODE), me.name, source_p->name, c); | |
1381 | return; | |
1382 | } | |
1383 | if (use_arg && parn >= parc) | |
1384 | { | |
1385 | if (!(cm->flags & CHM_CAN_QUERY)) | |
1386 | { | |
1387 | sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MODE"); | |
1388 | return; | |
1389 | } | |
1390 | effective_dir = MODE_QUERY; | |
1391 | use_arg = false; | |
1392 | } | |
1393 | ||
1394 | if (effective_dir == MODE_QUERY && !(cm->flags & CHM_CAN_QUERY)) | |
1395 | { | |
1396 | /* XXX this currently replicates traditional behaviour and just | |
1397 | * does nothing for a query on a mode with no query. would it be | |
1398 | * good to send an error here? | |
1399 | */ | |
1400 | continue; | |
1401 | } | |
1402 | ||
1403 | if (MyClient(source_p)) | |
1404 | { | |
1405 | if (use_arg && ++mode_limit > MAXMODEPARAMS) | |
1406 | continue; | |
1407 | if (!use_arg && ++mode_limit_simple > MAXMODES_SIMPLE) | |
1408 | continue; | |
1409 | } | |
1410 | ||
1411 | char op = effective_dir == MODE_ADD ? '+' : | |
1412 | effective_dir == MODE_DEL ? '-' : | |
1413 | '='; | |
1414 | ||
1415 | if (op != canon_op) | |
1416 | *mbuf++ = canon_op = op; | |
1417 | ||
1418 | *mbuf++ = c; | |
1419 | ||
1420 | if (effective_dir != MODE_QUERY) | |
1421 | changes = true; | |
1422 | if (effective_dir == MODE_QUERY && cm->flags & CHM_OPS_QUERY) | |
1423 | privileged_query = true; | |
1424 | ||
1425 | ms->cm = cm; | |
1426 | ms->dir = effective_dir; | |
1427 | if (use_arg) | |
1428 | ms->arg = parv[parn++]; | |
1429 | else | |
1430 | ms->arg = NULL; | |
1431 | ms->mode = c; | |
1432 | ms++; | |
1433 | } | |
1434 | } | |
1435 | } | |
1436 | ||
1437 | /* this will happen on something like MODE +-=++-. | |
1438 | * we'd have caught that with the if !mode_count | |
1439 | * later on, but this saves an override notice | |
1440 | */ | |
1441 | if (ms == modesets) | |
1442 | return; | |
1443 | ||
1444 | if (parn < parc) | |
1445 | { | |
1446 | /* XXX we could reject excess params here */ | |
1447 | } | |
1448 | ||
1449 | /* Finish the flood grace period if we were asked to do anything */ | |
1450 | if (changes && MyClient(source_p) && !IsFloodDone(source_p)) | |
1451 | { | |
1452 | flood_endgrace(source_p); | |
1453 | } | |
1454 | ||
1455 | mend = ms; | |
1456 | ||
1457 | if (parn > 1) | |
1458 | { | |
1459 | strcpy(mbuf, " "); | |
1460 | rb_strlcat(modebuf, reconstruct_parv(parn - 1, parv + 1), sizeof modebuf); | |
1461 | } | |
1462 | else | |
1463 | { | |
1464 | *mbuf = '\0'; | |
1465 | } | |
1466 | int access_dir = privileged_query ? MODE_OP_QUERY : | |
1467 | changes ? MODE_ADD : | |
1468 | MODE_QUERY; | |
1469 | alevel = get_channel_access(source_p, chptr, msptr, access_dir, modebuf); | |
1470 | ||
1471 | for (ms = modesets; ms < mend; ms++) | |
1472 | { | |
1473 | ChannelModeFunc *set_func = ms->cm->set_func; | |
1474 | set_func(fakesource_p, chptr, alevel, ms->arg, &errors, ms->dir, ms->mode, ms->cm->mode_type); | |
1475 | } | |
1476 | ||
1477 | /* bail out if we have nothing to do... */ | |
1478 | if (!mode_count) | |
1479 | return; | |
1480 | ||
1481 | if (IsServer(source_p)) | |
1482 | mlen = sprintf(modebuf, ":%s MODE %s ", fakesource_p->name, chptr->chname); | |
1483 | else | |
1484 | mlen = sprintf(modebuf, ":%s!%s@%s MODE %s ", | |
1485 | source_p->name, source_p->username, | |
1486 | source_p->host, chptr->chname); | |
1487 | ||
1488 | for(j = 0; j < 3; j++) | |
1489 | { | |
1490 | int send_flags = flags = flags_list[j]; | |
1491 | const char *priv = NULL; | |
1492 | if (flags == ONLY_OPERS) | |
1493 | { | |
1494 | send_flags = ALL_MEMBERS; | |
1495 | priv = "auspex:cmodes"; | |
1496 | } | |
1497 | cur_len = mlen; | |
1498 | mbuf = modebuf + mlen; | |
1499 | pbuf = parabuf; | |
1500 | parabuf[0] = '\0'; | |
1501 | paracount = paralen = 0; | |
1502 | dir = MODE_QUERY; | |
1503 | ||
1504 | for(i = 0; i < mode_count; i++) | |
1505 | { | |
1506 | if(mode_changes[i].letter == 0 || mode_changes[i].mems != flags) | |
1507 | continue; | |
1508 | ||
1509 | if(mode_changes[i].arg != NULL) | |
1510 | { | |
1511 | arglen = strlen(mode_changes[i].arg); | |
1512 | ||
1513 | if(arglen > MODEBUFLEN - 5) | |
1514 | continue; | |
1515 | } | |
1516 | else | |
1517 | arglen = 0; | |
1518 | ||
1519 | /* if we're creeping over MAXMODEPARAMSSERV, or over | |
1520 | * bufsize (4 == +/-,modechar,two spaces) send now. | |
1521 | */ | |
1522 | if(mode_changes[i].arg != NULL && | |
1523 | ((paracount == MAXMODEPARAMSSERV) || | |
1524 | ((cur_len + paralen + arglen + 4) > (BUFSIZE - 3)))) | |
1525 | { | |
1526 | *mbuf = '\0'; | |
1527 | ||
1528 | if(cur_len > mlen) | |
1529 | sendto_channel_local_priv(IsServer(source_p) ? fakesource_p : source_p, | |
1530 | send_flags, priv, chptr, "%s %s", modebuf, parabuf); | |
1531 | else | |
1532 | continue; | |
1533 | ||
1534 | paracount = paralen = 0; | |
1535 | cur_len = mlen; | |
1536 | mbuf = modebuf + mlen; | |
1537 | pbuf = parabuf; | |
1538 | parabuf[0] = '\0'; | |
1539 | dir = MODE_QUERY; | |
1540 | } | |
1541 | ||
1542 | if(dir != mode_changes[i].dir) | |
1543 | { | |
1544 | *mbuf++ = (mode_changes[i].dir == MODE_ADD) ? '+' : '-'; | |
1545 | cur_len++; | |
1546 | dir = mode_changes[i].dir; | |
1547 | } | |
1548 | ||
1549 | *mbuf++ = mode_changes[i].letter; | |
1550 | cur_len++; | |
1551 | ||
1552 | if(mode_changes[i].arg != NULL) | |
1553 | { | |
1554 | paracount++; | |
1555 | len = sprintf(pbuf, "%s ", mode_changes[i].arg); | |
1556 | pbuf += len; | |
1557 | paralen += len; | |
1558 | } | |
1559 | } | |
1560 | ||
1561 | if(paralen && parabuf[paralen - 1] == ' ') | |
1562 | parabuf[paralen - 1] = '\0'; | |
1563 | ||
1564 | *mbuf = '\0'; | |
1565 | if(cur_len > mlen) | |
1566 | sendto_channel_local_priv(IsServer(source_p) ? fakesource_p : source_p, | |
1567 | send_flags, priv, chptr, "%s %s", modebuf, parabuf); | |
1568 | } | |
1569 | ||
1570 | /* only propagate modes originating locally, or if we're hubbing */ | |
1571 | if(MyClient(source_p) || rb_dlink_list_length(&serv_list) > 1) | |
1572 | send_cap_mode_changes(client_p, source_p, chptr, mode_changes, mode_count); | |
1573 | } | |
1574 | ||
1575 | /* set_channel_mlock() | |
1576 | * | |
1577 | * inputs - client, source, channel, params | |
1578 | * output - | |
1579 | * side effects - channel mlock is changed / MLOCK is propagated | |
1580 | */ | |
1581 | void | |
1582 | set_channel_mlock(struct Client *client_p, struct Client *source_p, | |
1583 | struct Channel *chptr, const char *newmlock, bool propagate) | |
1584 | { | |
1585 | rb_free(chptr->mode_lock); | |
1586 | chptr->mode_lock = newmlock ? rb_strdup(newmlock) : NULL; | |
1587 | ||
1588 | if (propagate) | |
1589 | { | |
1590 | sendto_server(client_p, NULL, CAP_TS6 | CAP_MLOCK, NOCAPS, ":%s MLOCK %ld %s :%s", | |
1591 | source_p->id, (long) chptr->channelts, chptr->chname, | |
1592 | chptr->mode_lock ? chptr->mode_lock : ""); | |
1593 | } | |
1594 | } |