1 |
adx |
30 |
/* |
2 |
michael |
2916 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
7925 |
* Copyright (c) 1997-2017 ircd-hybrid development team |
5 |
adx |
30 |
* |
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 |
michael |
4564 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
adx |
30 |
* USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
michael |
2916 |
/*! \file channel_mode.c |
23 |
|
|
* \brief Controls modes on channels. |
24 |
|
|
* \version $Id$ |
25 |
|
|
*/ |
26 |
|
|
|
27 |
adx |
30 |
#include "stdinc.h" |
28 |
michael |
1011 |
#include "list.h" |
29 |
adx |
30 |
#include "channel.h" |
30 |
|
|
#include "channel_mode.h" |
31 |
|
|
#include "client.h" |
32 |
michael |
1632 |
#include "conf.h" |
33 |
michael |
371 |
#include "hostmask.h" |
34 |
adx |
30 |
#include "irc_string.h" |
35 |
|
|
#include "ircd.h" |
36 |
|
|
#include "numeric.h" |
37 |
michael |
3347 |
#include "server.h" |
38 |
adx |
30 |
#include "send.h" |
39 |
|
|
#include "memory.h" |
40 |
michael |
1654 |
#include "mempool.h" |
41 |
michael |
1243 |
#include "parse.h" |
42 |
adx |
30 |
|
43 |
|
|
|
44 |
michael |
388 |
static char nuh_mask[MAXPARA][IRCD_BUFSIZE]; |
45 |
adx |
30 |
static struct ChModeChange mode_changes[IRCD_BUFSIZE]; |
46 |
michael |
3057 |
static unsigned int mode_count; |
47 |
|
|
static unsigned int mode_limit; /* number of modes set other than simple */ |
48 |
|
|
static unsigned int simple_modes_mask; /* bit mask of simple modes already set */ |
49 |
michael |
1654 |
extern mp_pool_t *ban_pool; |
50 |
adx |
30 |
|
51 |
|
|
|
52 |
|
|
/* check_string() |
53 |
|
|
* |
54 |
|
|
* inputs - string to check |
55 |
|
|
* output - pointer to modified string |
56 |
|
|
* side effects - Fixes a string so that the first white space found |
57 |
|
|
* becomes an end of string marker (`\0`). |
58 |
|
|
* returns the 'fixed' string or "*" if the string |
59 |
|
|
* was NULL length or a NULL pointer. |
60 |
|
|
*/ |
61 |
|
|
static char * |
62 |
|
|
check_string(char *s) |
63 |
|
|
{ |
64 |
michael |
4834 |
char *const str = s; |
65 |
adx |
30 |
static char star[] = "*"; |
66 |
|
|
|
67 |
michael |
1772 |
if (EmptyString(str)) |
68 |
michael |
593 |
return star; |
69 |
adx |
30 |
|
70 |
|
|
for (; *s; ++s) |
71 |
|
|
{ |
72 |
|
|
if (IsSpace(*s)) |
73 |
|
|
{ |
74 |
|
|
*s = '\0'; |
75 |
|
|
break; |
76 |
|
|
} |
77 |
|
|
} |
78 |
|
|
|
79 |
michael |
1772 |
return EmptyString(str) ? star : str; |
80 |
adx |
30 |
} |
81 |
|
|
|
82 |
|
|
/* |
83 |
michael |
5582 |
* Ban functions to work with mode +b/e/I |
84 |
adx |
30 |
*/ |
85 |
michael |
2892 |
/* add the specified ID to the channel. |
86 |
|
|
* -is 8/9/00 |
87 |
adx |
30 |
*/ |
88 |
|
|
|
89 |
|
|
int |
90 |
michael |
3044 |
add_id(struct Client *client_p, struct Channel *chptr, char *banid, unsigned int type) |
91 |
adx |
30 |
{ |
92 |
michael |
7796 |
dlink_list *list; |
93 |
|
|
dlink_node *node; |
94 |
michael |
3215 |
char name[NICKLEN + 1] = ""; |
95 |
|
|
char user[USERLEN + 1] = ""; |
96 |
|
|
char host[HOSTLEN + 1] = ""; |
97 |
michael |
593 |
struct split_nuh_item nuh; |
98 |
adx |
30 |
|
99 |
|
|
if (MyClient(client_p)) |
100 |
|
|
{ |
101 |
michael |
3699 |
unsigned int num_mask = dlink_list_length(&chptr->banlist) + |
102 |
|
|
dlink_list_length(&chptr->exceptlist) + |
103 |
|
|
dlink_list_length(&chptr->invexlist); |
104 |
adx |
30 |
|
105 |
michael |
8045 |
/* Don't let local clients overflow the b/e/I lists */ |
106 |
|
|
if (num_mask >= ((HasCMode(chptr, MODE_EXTLIMIT)) ? ConfigChannel.max_bans_large : |
107 |
|
|
ConfigChannel.max_bans)) |
108 |
adx |
30 |
{ |
109 |
michael |
4617 |
sendto_one_numeric(client_p, &me, ERR_BANLISTFULL, chptr->name, banid); |
110 |
adx |
30 |
return 0; |
111 |
|
|
} |
112 |
|
|
|
113 |
|
|
collapse(banid); |
114 |
|
|
} |
115 |
|
|
|
116 |
michael |
593 |
nuh.nuhmask = check_string(banid); |
117 |
|
|
nuh.nickptr = name; |
118 |
|
|
nuh.userptr = user; |
119 |
|
|
nuh.hostptr = host; |
120 |
adx |
30 |
|
121 |
michael |
593 |
nuh.nicksize = sizeof(name); |
122 |
|
|
nuh.usersize = sizeof(user); |
123 |
|
|
nuh.hostsize = sizeof(host); |
124 |
|
|
|
125 |
|
|
split_nuh(&nuh); |
126 |
|
|
|
127 |
adx |
30 |
/* |
128 |
michael |
593 |
* Re-assemble a new n!u@h and print it back to banid for sending |
129 |
adx |
30 |
* the mode to the channel. |
130 |
|
|
*/ |
131 |
michael |
7796 |
size_t len = snprintf(banid, IRCD_BUFSIZE, "%s!%s@%s", name, user, host); |
132 |
adx |
30 |
|
133 |
|
|
switch (type) |
134 |
|
|
{ |
135 |
|
|
case CHFL_BAN: |
136 |
|
|
list = &chptr->banlist; |
137 |
michael |
7763 |
clear_ban_cache_list(&chptr->locmembers); |
138 |
adx |
30 |
break; |
139 |
|
|
case CHFL_EXCEPTION: |
140 |
|
|
list = &chptr->exceptlist; |
141 |
michael |
7763 |
clear_ban_cache_list(&chptr->locmembers); |
142 |
adx |
30 |
break; |
143 |
|
|
case CHFL_INVEX: |
144 |
|
|
list = &chptr->invexlist; |
145 |
|
|
break; |
146 |
|
|
default: |
147 |
michael |
7796 |
list = NULL; /* Let it crash */ |
148 |
adx |
30 |
} |
149 |
|
|
|
150 |
michael |
4801 |
DLINK_FOREACH(node, list->head) |
151 |
adx |
30 |
{ |
152 |
michael |
7796 |
const struct Ban *ban = node->data; |
153 |
michael |
2892 |
|
154 |
michael |
4816 |
if (!irccmp(ban->name, name) && |
155 |
|
|
!irccmp(ban->user, user) && |
156 |
|
|
!irccmp(ban->host, host)) |
157 |
adx |
30 |
return 0; |
158 |
|
|
} |
159 |
|
|
|
160 |
michael |
7796 |
struct Ban *ban = mp_pool_get(ban_pool); |
161 |
michael |
4816 |
ban->when = CurrentTime; |
162 |
|
|
ban->len = len - 2; /* -2 for ! + @ */ |
163 |
|
|
ban->type = parse_netmask(host, &ban->addr, &ban->bits); |
164 |
michael |
5758 |
strlcpy(ban->name, name, sizeof(ban->name)); |
165 |
|
|
strlcpy(ban->user, user, sizeof(ban->user)); |
166 |
|
|
strlcpy(ban->host, host, sizeof(ban->host)); |
167 |
michael |
3699 |
|
168 |
adx |
30 |
if (IsClient(client_p)) |
169 |
michael |
5758 |
snprintf(ban->who, sizeof(ban->who), "%s!%s@%s", client_p->name, |
170 |
|
|
client_p->username, client_p->host); |
171 |
michael |
5754 |
else if (IsHidden(client_p) || ConfigServerHide.hide_servers) |
172 |
michael |
5758 |
strlcpy(ban->who, me.name, sizeof(ban->who)); |
173 |
adx |
30 |
else |
174 |
michael |
5758 |
strlcpy(ban->who, client_p->name, sizeof(ban->who)); |
175 |
adx |
30 |
|
176 |
michael |
4816 |
dlinkAdd(ban, &ban->node, list); |
177 |
adx |
30 |
|
178 |
|
|
return 1; |
179 |
|
|
} |
180 |
|
|
|
181 |
|
|
/* |
182 |
|
|
* inputs - pointer to channel |
183 |
|
|
* - pointer to ban id |
184 |
|
|
* - type of ban, i.e. ban, exception, invex |
185 |
|
|
* output - 0 for failure, 1 for success |
186 |
|
|
* side effects - |
187 |
|
|
*/ |
188 |
|
|
static int |
189 |
michael |
3044 |
del_id(struct Channel *chptr, char *banid, unsigned int type) |
190 |
adx |
30 |
{ |
191 |
michael |
7796 |
dlink_list *list; |
192 |
|
|
dlink_node *node; |
193 |
michael |
3215 |
char name[NICKLEN + 1] = ""; |
194 |
|
|
char user[USERLEN + 1] = ""; |
195 |
|
|
char host[HOSTLEN + 1] = ""; |
196 |
michael |
593 |
struct split_nuh_item nuh; |
197 |
adx |
30 |
|
198 |
michael |
2892 |
assert(banid); |
199 |
adx |
30 |
|
200 |
michael |
593 |
nuh.nuhmask = check_string(banid); |
201 |
|
|
nuh.nickptr = name; |
202 |
|
|
nuh.userptr = user; |
203 |
|
|
nuh.hostptr = host; |
204 |
adx |
30 |
|
205 |
michael |
593 |
nuh.nicksize = sizeof(name); |
206 |
|
|
nuh.usersize = sizeof(user); |
207 |
|
|
nuh.hostsize = sizeof(host); |
208 |
|
|
|
209 |
|
|
split_nuh(&nuh); |
210 |
|
|
|
211 |
adx |
30 |
/* |
212 |
michael |
593 |
* Re-assemble a new n!u@h and print it back to banid for sending |
213 |
adx |
30 |
* the mode to the channel. |
214 |
|
|
*/ |
215 |
michael |
4825 |
snprintf(banid, IRCD_BUFSIZE, "%s!%s@%s", name, user, host); |
216 |
adx |
30 |
|
217 |
|
|
switch (type) |
218 |
|
|
{ |
219 |
|
|
case CHFL_BAN: |
220 |
|
|
list = &chptr->banlist; |
221 |
michael |
7763 |
clear_ban_cache_list(&chptr->locmembers); |
222 |
adx |
30 |
break; |
223 |
|
|
case CHFL_EXCEPTION: |
224 |
|
|
list = &chptr->exceptlist; |
225 |
michael |
7763 |
clear_ban_cache_list(&chptr->locmembers); |
226 |
adx |
30 |
break; |
227 |
|
|
case CHFL_INVEX: |
228 |
|
|
list = &chptr->invexlist; |
229 |
|
|
break; |
230 |
|
|
default: |
231 |
michael |
7796 |
list = NULL; /* Let it crash */ |
232 |
adx |
30 |
} |
233 |
|
|
|
234 |
michael |
4801 |
DLINK_FOREACH(node, list->head) |
235 |
adx |
30 |
{ |
236 |
michael |
4816 |
struct Ban *ban = node->data; |
237 |
adx |
30 |
|
238 |
michael |
4816 |
if (!irccmp(name, ban->name) && |
239 |
|
|
!irccmp(user, ban->user) && |
240 |
|
|
!irccmp(host, ban->host)) |
241 |
adx |
30 |
{ |
242 |
michael |
4816 |
remove_ban(ban, list); |
243 |
adx |
30 |
return 1; |
244 |
|
|
} |
245 |
|
|
} |
246 |
|
|
|
247 |
|
|
return 0; |
248 |
|
|
} |
249 |
|
|
|
250 |
|
|
/* channel_modes() |
251 |
|
|
* |
252 |
|
|
* inputs - pointer to channel |
253 |
|
|
* - pointer to client |
254 |
|
|
* - pointer to mode buf |
255 |
|
|
* - pointer to parameter buf |
256 |
|
|
* output - NONE |
257 |
|
|
* side effects - write the "simple" list of channel modes for channel |
258 |
|
|
* chptr onto buffer mbuf with the parameters in pbuf. |
259 |
|
|
*/ |
260 |
|
|
void |
261 |
michael |
3688 |
channel_modes(struct Channel *chptr, struct Client *client_p, char *mbuf, char *pbuf) |
262 |
adx |
30 |
{ |
263 |
|
|
*mbuf++ = '+'; |
264 |
|
|
*pbuf = '\0'; |
265 |
|
|
|
266 |
michael |
8090 |
for (const struct chan_mode *tab = cmode_tab; tab->mode; ++tab) |
267 |
michael |
8088 |
if (tab->mode && HasCMode(chptr, tab->mode)) |
268 |
michael |
1175 |
*mbuf++ = tab->letter; |
269 |
adx |
30 |
|
270 |
|
|
if (chptr->mode.limit) |
271 |
|
|
{ |
272 |
|
|
*mbuf++ = 'l'; |
273 |
|
|
|
274 |
michael |
6360 |
if (IsServer(client_p) || IsMember(client_p, chptr)) |
275 |
michael |
7356 |
pbuf += sprintf(pbuf, "%u ", chptr->mode.limit); |
276 |
adx |
30 |
} |
277 |
|
|
|
278 |
|
|
if (chptr->mode.key[0]) |
279 |
|
|
{ |
280 |
|
|
*mbuf++ = 'k'; |
281 |
|
|
|
282 |
michael |
6360 |
if (IsServer(client_p) || IsMember(client_p, chptr)) |
283 |
michael |
3693 |
sprintf(pbuf, "%s ", chptr->mode.key); |
284 |
adx |
30 |
} |
285 |
|
|
|
286 |
|
|
*mbuf = '\0'; |
287 |
|
|
} |
288 |
|
|
|
289 |
|
|
/* fix_key() |
290 |
michael |
2892 |
* |
291 |
adx |
30 |
* inputs - pointer to key to clean up |
292 |
|
|
* output - pointer to cleaned up key |
293 |
|
|
* side effects - input string is modified |
294 |
|
|
* |
295 |
|
|
* stolen from Undernet's ircd -orabidoo |
296 |
|
|
*/ |
297 |
|
|
static char * |
298 |
|
|
fix_key(char *arg) |
299 |
|
|
{ |
300 |
|
|
unsigned char *s, *t, c; |
301 |
|
|
|
302 |
michael |
8021 |
for (s = t = (unsigned char *)arg; (c = *s) && s - (unsigned char *)arg < KEYLEN; ++s) |
303 |
adx |
30 |
{ |
304 |
|
|
c &= 0x7f; |
305 |
michael |
2892 |
|
306 |
adx |
30 |
if (c != ':' && c > ' ' && c != ',') |
307 |
|
|
*t++ = c; |
308 |
|
|
} |
309 |
|
|
|
310 |
|
|
*t = '\0'; |
311 |
michael |
2892 |
return arg; |
312 |
adx |
30 |
} |
313 |
|
|
|
314 |
michael |
3149 |
/* |
315 |
|
|
* inputs - pointer to channel |
316 |
|
|
* output - none |
317 |
|
|
* side effects - clear ban cache |
318 |
|
|
*/ |
319 |
|
|
void |
320 |
michael |
7763 |
clear_ban_cache_list(dlink_list *list) |
321 |
michael |
3149 |
{ |
322 |
michael |
7763 |
dlink_node *node; |
323 |
michael |
3149 |
|
324 |
michael |
7763 |
DLINK_FOREACH(node, list->head) |
325 |
michael |
3149 |
{ |
326 |
michael |
4816 |
struct Membership *member = node->data; |
327 |
michael |
5751 |
member->flags &= ~(CHFL_BAN_SILENCED | CHFL_BAN_CHECKED); |
328 |
michael |
3149 |
} |
329 |
|
|
} |
330 |
|
|
|
331 |
michael |
3635 |
/* |
332 |
|
|
* Bitmasks for various error returns that set_channel_mode should only return |
333 |
adx |
30 |
* once per call -orabidoo |
334 |
|
|
*/ |
335 |
michael |
3635 |
enum |
336 |
|
|
{ |
337 |
|
|
SM_ERR_NOOPS = 1 << 0, /* No chan ops */ |
338 |
|
|
SM_ERR_UNKNOWN = 1 << 1, |
339 |
|
|
SM_ERR_RPL_B = 1 << 2, |
340 |
|
|
SM_ERR_RPL_E = 1 << 3, |
341 |
|
|
SM_ERR_RPL_I = 1 << 4, |
342 |
|
|
SM_ERR_NOTONCHANNEL = 1 << 5, /* Client is not on channel */ |
343 |
michael |
8050 |
SM_ERR_NOTOPER = 1 << 6, /* Only irc-operators can change that mode */ |
344 |
|
|
SM_ERR_ONLYSERVER = 1 << 7 /* Only servers or services can change that mode */ |
345 |
michael |
3635 |
}; |
346 |
adx |
30 |
|
347 |
|
|
/* Mode functions handle mode changes for a particular mode... */ |
348 |
|
|
static void |
349 |
michael |
8090 |
chm_nosuch(struct Client *source_p, struct Channel *chptr, int parc, int *parn, char **parv, |
350 |
|
|
int *errors, int alev, int dir, const struct chan_mode *mode) |
351 |
adx |
30 |
{ |
352 |
|
|
if (*errors & SM_ERR_UNKNOWN) |
353 |
|
|
return; |
354 |
|
|
|
355 |
|
|
*errors |= SM_ERR_UNKNOWN; |
356 |
michael |
8090 |
sendto_one_numeric(source_p, &me, ERR_UNKNOWNMODE, mode->letter); |
357 |
adx |
30 |
} |
358 |
|
|
|
359 |
|
|
static void |
360 |
michael |
8090 |
chm_simple(struct Client *source_p, struct Channel *chptr, int parc, int *parn, char **parv, |
361 |
|
|
int *errors, int alev, int dir, const struct chan_mode *mode) |
362 |
adx |
30 |
{ |
363 |
michael |
8090 |
if (mode->only_opers) |
364 |
adx |
30 |
{ |
365 |
michael |
8090 |
if (MyClient(source_p) && !HasUMode(source_p, UMODE_OPER)) |
366 |
|
|
{ |
367 |
|
|
if (!(*errors & SM_ERR_NOTOPER)) |
368 |
|
|
sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES); |
369 |
michael |
4883 |
|
370 |
michael |
8090 |
*errors |= SM_ERR_NOTOPER; |
371 |
|
|
return; |
372 |
|
|
} |
373 |
adx |
30 |
} |
374 |
|
|
|
375 |
michael |
8090 |
if (mode->only_servers) |
376 |
adx |
30 |
{ |
377 |
michael |
8090 |
if (!IsServer(source_p) && !HasFlag(source_p, FLAGS_SERVICE)) |
378 |
|
|
{ |
379 |
|
|
if (!(*errors & SM_ERR_ONLYSERVER)) |
380 |
|
|
sendto_one_numeric(source_p, &me, |
381 |
|
|
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
382 |
|
|
ERR_ONLYSERVERSCANCHANGE, chptr->name); |
383 |
adx |
30 |
|
384 |
michael |
8090 |
*errors |= SM_ERR_ONLYSERVER; |
385 |
|
|
return; |
386 |
|
|
} |
387 |
adx |
30 |
} |
388 |
|
|
|
389 |
michael |
5579 |
if (alev < CHACCESS_HALFOP) |
390 |
michael |
1150 |
{ |
391 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
392 |
michael |
3109 |
sendto_one_numeric(source_p, &me, |
393 |
|
|
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
394 |
michael |
4617 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
395 |
michael |
3649 |
|
396 |
michael |
1150 |
*errors |= SM_ERR_NOOPS; |
397 |
|
|
return; |
398 |
|
|
} |
399 |
michael |
3649 |
|
400 |
michael |
1150 |
/* If have already dealt with this simple mode, ignore it */ |
401 |
michael |
8090 |
if (simple_modes_mask & mode->mode) |
402 |
michael |
1150 |
return; |
403 |
|
|
|
404 |
michael |
8090 |
simple_modes_mask |= mode->mode; |
405 |
michael |
1150 |
|
406 |
michael |
8090 |
/* setting + */ |
407 |
michael |
2937 |
if (dir == MODE_ADD) /* && !(chptr->mode.mode & d)) */ |
408 |
michael |
1150 |
{ |
409 |
michael |
8090 |
AddCMode(chptr, mode->mode); |
410 |
michael |
1150 |
|
411 |
michael |
8090 |
mode_changes[mode_count].letter = mode->letter; |
412 |
michael |
3735 |
mode_changes[mode_count].arg = NULL; |
413 |
michael |
1150 |
mode_changes[mode_count].id = NULL; |
414 |
michael |
8039 |
mode_changes[mode_count].flags = 0; |
415 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
416 |
michael |
1150 |
} |
417 |
michael |
2937 |
else if (dir == MODE_DEL) /* && (chptr->mode.mode & d)) */ |
418 |
michael |
1150 |
{ |
419 |
|
|
/* setting - */ |
420 |
michael |
8090 |
DelCMode(chptr, mode->mode); |
421 |
michael |
1150 |
|
422 |
michael |
8090 |
mode_changes[mode_count].letter = mode->letter; |
423 |
michael |
3735 |
mode_changes[mode_count].arg = NULL; |
424 |
michael |
1150 |
mode_changes[mode_count].id = NULL; |
425 |
michael |
8039 |
mode_changes[mode_count].flags = 0; |
426 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
427 |
michael |
1150 |
} |
428 |
|
|
} |
429 |
|
|
|
430 |
|
|
static void |
431 |
michael |
8090 |
chm_ban(struct Client *source_p, struct Channel *chptr, int parc, int *parn, char **parv, |
432 |
|
|
int *errors, int alev, int dir, const struct chan_mode *mode) |
433 |
adx |
30 |
{ |
434 |
|
|
if (dir == MODE_QUERY || parc <= *parn) |
435 |
|
|
{ |
436 |
michael |
7796 |
dlink_node *node; |
437 |
adx |
30 |
|
438 |
|
|
if (*errors & SM_ERR_RPL_B) |
439 |
|
|
return; |
440 |
|
|
|
441 |
|
|
*errors |= SM_ERR_RPL_B; |
442 |
|
|
|
443 |
michael |
4801 |
DLINK_FOREACH(node, chptr->banlist.head) |
444 |
adx |
30 |
{ |
445 |
michael |
4816 |
const struct Ban *ban = node->data; |
446 |
michael |
8039 |
|
447 |
michael |
8043 |
if (!HasCMode(chptr, MODE_HIDEBMASKS) || alev >= CHACCESS_HALFOP) |
448 |
michael |
8039 |
sendto_one_numeric(source_p, &me, RPL_BANLIST, chptr->name, |
449 |
|
|
ban->name, ban->user, ban->host, |
450 |
|
|
ban->who, ban->when); |
451 |
adx |
30 |
} |
452 |
|
|
|
453 |
michael |
4617 |
sendto_one_numeric(source_p, &me, RPL_ENDOFBANLIST, chptr->name); |
454 |
adx |
30 |
return; |
455 |
|
|
} |
456 |
|
|
|
457 |
|
|
if (alev < CHACCESS_HALFOP) |
458 |
|
|
{ |
459 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
460 |
michael |
3109 |
sendto_one_numeric(source_p, &me, |
461 |
|
|
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
462 |
michael |
4617 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
463 |
michael |
4883 |
|
464 |
adx |
30 |
*errors |= SM_ERR_NOOPS; |
465 |
|
|
return; |
466 |
|
|
} |
467 |
|
|
|
468 |
|
|
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
469 |
|
|
return; |
470 |
|
|
|
471 |
michael |
8050 |
char *const mask = nuh_mask[*parn]; |
472 |
michael |
5746 |
strlcpy(mask, parv[*parn], sizeof(nuh_mask[*parn])); |
473 |
michael |
4790 |
++(*parn); |
474 |
michael |
388 |
|
475 |
michael |
5030 |
if (*mask == ':' || (!MyConnect(source_p) && strchr(mask, ' '))) |
476 |
|
|
return; |
477 |
adx |
30 |
|
478 |
|
|
switch (dir) |
479 |
|
|
{ |
480 |
|
|
case MODE_ADD: |
481 |
|
|
if (!add_id(source_p, chptr, mask, CHFL_BAN)) |
482 |
|
|
return; |
483 |
|
|
break; |
484 |
|
|
case MODE_DEL: |
485 |
|
|
if (!del_id(chptr, mask, CHFL_BAN)) |
486 |
|
|
return; |
487 |
|
|
break; |
488 |
|
|
default: |
489 |
|
|
assert(0); |
490 |
|
|
} |
491 |
|
|
|
492 |
michael |
8090 |
mode_changes[mode_count].letter = mode->letter; |
493 |
michael |
8017 |
mode_changes[mode_count].arg = mask; /* At this point 'mask' is no longer than NICKLEN + USERLEN + HOSTLEN + 3 */ |
494 |
michael |
3735 |
mode_changes[mode_count].id = NULL; |
495 |
michael |
8043 |
if (HasCMode(chptr, MODE_HIDEBMASKS)) |
496 |
michael |
8039 |
mode_changes[mode_count].flags = CHFL_CHANOP | CHFL_HALFOP; |
497 |
|
|
else |
498 |
|
|
mode_changes[mode_count].flags = 0; |
499 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
500 |
adx |
30 |
} |
501 |
|
|
|
502 |
|
|
static void |
503 |
michael |
8090 |
chm_except(struct Client *source_p, struct Channel *chptr, int parc, int *parn, char **parv, |
504 |
|
|
int *errors, int alev, int dir, const struct chan_mode *mode) |
505 |
adx |
30 |
{ |
506 |
|
|
if (dir == MODE_QUERY || parc <= *parn) |
507 |
|
|
{ |
508 |
michael |
7796 |
dlink_node *node; |
509 |
adx |
30 |
|
510 |
|
|
if (*errors & SM_ERR_RPL_E) |
511 |
|
|
return; |
512 |
|
|
|
513 |
|
|
*errors |= SM_ERR_RPL_E; |
514 |
|
|
|
515 |
michael |
4801 |
DLINK_FOREACH(node, chptr->exceptlist.head) |
516 |
adx |
30 |
{ |
517 |
michael |
4816 |
const struct Ban *ban = node->data; |
518 |
michael |
8039 |
|
519 |
michael |
8043 |
if (!HasCMode(chptr, MODE_HIDEBMASKS) || alev >= CHACCESS_HALFOP) |
520 |
michael |
8039 |
sendto_one_numeric(source_p, &me, RPL_EXCEPTLIST, chptr->name, |
521 |
|
|
ban->name, ban->user, ban->host, |
522 |
|
|
ban->who, ban->when); |
523 |
adx |
30 |
} |
524 |
|
|
|
525 |
michael |
4617 |
sendto_one_numeric(source_p, &me, RPL_ENDOFEXCEPTLIST, chptr->name); |
526 |
adx |
30 |
return; |
527 |
|
|
} |
528 |
|
|
|
529 |
michael |
3842 |
if (alev < CHACCESS_HALFOP) |
530 |
|
|
{ |
531 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
532 |
|
|
sendto_one_numeric(source_p, &me, |
533 |
|
|
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
534 |
michael |
4617 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
535 |
michael |
4883 |
|
536 |
michael |
3842 |
*errors |= SM_ERR_NOOPS; |
537 |
|
|
return; |
538 |
|
|
} |
539 |
|
|
|
540 |
adx |
30 |
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
541 |
|
|
return; |
542 |
|
|
|
543 |
michael |
8050 |
char *const mask = nuh_mask[*parn]; |
544 |
michael |
5746 |
strlcpy(mask, parv[*parn], sizeof(nuh_mask[*parn])); |
545 |
michael |
4790 |
++(*parn); |
546 |
adx |
30 |
|
547 |
michael |
5030 |
if (*mask == ':' || (!MyConnect(source_p) && strchr(mask, ' '))) |
548 |
|
|
return; |
549 |
adx |
30 |
|
550 |
|
|
switch (dir) |
551 |
|
|
{ |
552 |
|
|
case MODE_ADD: |
553 |
|
|
if (!add_id(source_p, chptr, mask, CHFL_EXCEPTION)) |
554 |
|
|
return; |
555 |
|
|
break; |
556 |
|
|
case MODE_DEL: |
557 |
|
|
if (!del_id(chptr, mask, CHFL_EXCEPTION)) |
558 |
|
|
return; |
559 |
|
|
break; |
560 |
|
|
default: |
561 |
|
|
assert(0); |
562 |
|
|
} |
563 |
|
|
|
564 |
michael |
8090 |
mode_changes[mode_count].letter = mode->letter; |
565 |
michael |
8017 |
mode_changes[mode_count].arg = mask; /* At this point 'mask' is no longer than NICKLEN + USERLEN + HOSTLEN + 3 */ |
566 |
michael |
3735 |
mode_changes[mode_count].id = NULL; |
567 |
michael |
8043 |
if (HasCMode(chptr, MODE_HIDEBMASKS)) |
568 |
michael |
8039 |
mode_changes[mode_count].flags = CHFL_CHANOP | CHFL_HALFOP; |
569 |
|
|
else |
570 |
|
|
mode_changes[mode_count].flags = 0; |
571 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
572 |
adx |
30 |
} |
573 |
|
|
|
574 |
|
|
static void |
575 |
michael |
8090 |
chm_invex(struct Client *source_p, struct Channel *chptr, int parc, int *parn, char **parv, |
576 |
|
|
int *errors, int alev, int dir, const struct chan_mode *mode) |
577 |
adx |
30 |
{ |
578 |
|
|
if (dir == MODE_QUERY || parc <= *parn) |
579 |
|
|
{ |
580 |
michael |
7796 |
dlink_node *node; |
581 |
adx |
30 |
|
582 |
|
|
if (*errors & SM_ERR_RPL_I) |
583 |
|
|
return; |
584 |
|
|
|
585 |
|
|
*errors |= SM_ERR_RPL_I; |
586 |
|
|
|
587 |
michael |
4801 |
DLINK_FOREACH(node, chptr->invexlist.head) |
588 |
adx |
30 |
{ |
589 |
michael |
4816 |
const struct Ban *ban = node->data; |
590 |
michael |
8039 |
|
591 |
michael |
8043 |
if (!HasCMode(chptr, MODE_HIDEBMASKS) || alev >= CHACCESS_HALFOP) |
592 |
michael |
8039 |
sendto_one_numeric(source_p, &me, RPL_INVEXLIST, chptr->name, |
593 |
|
|
ban->name, ban->user, ban->host, |
594 |
|
|
ban->who, ban->when); |
595 |
adx |
30 |
} |
596 |
|
|
|
597 |
michael |
4617 |
sendto_one_numeric(source_p, &me, RPL_ENDOFINVEXLIST, chptr->name); |
598 |
adx |
30 |
return; |
599 |
|
|
} |
600 |
|
|
|
601 |
michael |
3842 |
if (alev < CHACCESS_HALFOP) |
602 |
|
|
{ |
603 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
604 |
|
|
sendto_one_numeric(source_p, &me, |
605 |
|
|
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
606 |
michael |
4617 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
607 |
michael |
4883 |
|
608 |
michael |
3842 |
*errors |= SM_ERR_NOOPS; |
609 |
|
|
return; |
610 |
|
|
} |
611 |
|
|
|
612 |
adx |
30 |
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
613 |
|
|
return; |
614 |
|
|
|
615 |
michael |
8050 |
char *const mask = nuh_mask[*parn]; |
616 |
michael |
5746 |
strlcpy(mask, parv[*parn], sizeof(nuh_mask[*parn])); |
617 |
michael |
4790 |
++(*parn); |
618 |
adx |
30 |
|
619 |
michael |
5030 |
if (*mask == ':' || (!MyConnect(source_p) && strchr(mask, ' '))) |
620 |
|
|
return; |
621 |
adx |
30 |
|
622 |
|
|
switch (dir) |
623 |
|
|
{ |
624 |
|
|
case MODE_ADD: |
625 |
|
|
if (!add_id(source_p, chptr, mask, CHFL_INVEX)) |
626 |
|
|
return; |
627 |
|
|
break; |
628 |
|
|
case MODE_DEL: |
629 |
|
|
if (!del_id(chptr, mask, CHFL_INVEX)) |
630 |
|
|
return; |
631 |
|
|
break; |
632 |
|
|
default: |
633 |
|
|
assert(0); |
634 |
|
|
} |
635 |
|
|
|
636 |
michael |
8090 |
mode_changes[mode_count].letter = mode->letter; |
637 |
michael |
8017 |
mode_changes[mode_count].arg = mask; /* At this point 'mask' is no longer than NICKLEN + USERLEN + HOSTLEN + 3 */ |
638 |
michael |
3735 |
mode_changes[mode_count].id = NULL; |
639 |
michael |
8043 |
if (HasCMode(chptr, MODE_HIDEBMASKS)) |
640 |
michael |
8039 |
mode_changes[mode_count].flags = CHFL_CHANOP | CHFL_HALFOP; |
641 |
|
|
else |
642 |
|
|
mode_changes[mode_count].flags = 0; |
643 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
644 |
adx |
30 |
} |
645 |
|
|
|
646 |
|
|
static void |
647 |
michael |
8090 |
chm_voice(struct Client *source_p, struct Channel *chptr, int parc, int *parn, char **parv, |
648 |
|
|
int *errors, int alev, int dir, const struct chan_mode *mode) |
649 |
adx |
30 |
{ |
650 |
michael |
3143 |
struct Client *target_p; |
651 |
adx |
30 |
struct Membership *member; |
652 |
|
|
|
653 |
michael |
2951 |
if (alev < CHACCESS_HALFOP) |
654 |
adx |
30 |
{ |
655 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
656 |
michael |
3109 |
sendto_one_numeric(source_p, &me, |
657 |
|
|
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
658 |
michael |
4617 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
659 |
michael |
4883 |
|
660 |
adx |
30 |
*errors |= SM_ERR_NOOPS; |
661 |
|
|
return; |
662 |
|
|
} |
663 |
|
|
|
664 |
michael |
3670 |
if (dir == MODE_QUERY || parc <= *parn) |
665 |
adx |
30 |
return; |
666 |
|
|
|
667 |
michael |
3673 |
if ((target_p = find_chasing(source_p, parv[(*parn)++])) == NULL) |
668 |
michael |
3736 |
return; /* find_chasing sends ERR_NOSUCHNICK */ |
669 |
adx |
30 |
|
670 |
michael |
3143 |
if ((member = find_channel_link(target_p, chptr)) == NULL) |
671 |
adx |
30 |
{ |
672 |
|
|
if (!(*errors & SM_ERR_NOTONCHANNEL)) |
673 |
michael |
4617 |
sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->name); |
674 |
michael |
4883 |
|
675 |
adx |
30 |
*errors |= SM_ERR_NOTONCHANNEL; |
676 |
|
|
return; |
677 |
|
|
} |
678 |
|
|
|
679 |
|
|
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
680 |
|
|
return; |
681 |
|
|
|
682 |
michael |
6929 |
switch (dir) |
683 |
|
|
{ |
684 |
|
|
case MODE_ADD: |
685 |
|
|
if (has_member_flags(member, CHFL_VOICE)) |
686 |
|
|
return; /* No redundant mode changes */ |
687 |
michael |
4883 |
|
688 |
michael |
6929 |
AddMemberFlag(member, CHFL_VOICE); |
689 |
|
|
break; |
690 |
|
|
case MODE_DEL: |
691 |
|
|
if (!has_member_flags(member, CHFL_VOICE)) |
692 |
|
|
return; /* No redundant mode changes */ |
693 |
adx |
30 |
|
694 |
michael |
6929 |
DelMemberFlag(member, CHFL_VOICE); |
695 |
|
|
break; |
696 |
|
|
} |
697 |
|
|
|
698 |
michael |
8090 |
mode_changes[mode_count].letter = mode->letter; |
699 |
michael |
3735 |
mode_changes[mode_count].arg = target_p->name; |
700 |
|
|
mode_changes[mode_count].id = target_p->id; |
701 |
michael |
8039 |
mode_changes[mode_count].flags = 0; |
702 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
703 |
adx |
30 |
} |
704 |
|
|
|
705 |
|
|
static void |
706 |
michael |
8090 |
chm_hop(struct Client *source_p, struct Channel *chptr, int parc, int *parn, char **parv, |
707 |
|
|
int *errors, int alev, int dir, const struct chan_mode *mode) |
708 |
adx |
30 |
{ |
709 |
michael |
3143 |
struct Client *target_p; |
710 |
adx |
30 |
struct Membership *member; |
711 |
|
|
|
712 |
michael |
3714 |
if (alev < CHACCESS_CHANOP) |
713 |
adx |
30 |
{ |
714 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
715 |
michael |
3109 |
sendto_one_numeric(source_p, &me, |
716 |
|
|
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
717 |
michael |
4617 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
718 |
michael |
4883 |
|
719 |
adx |
30 |
*errors |= SM_ERR_NOOPS; |
720 |
|
|
return; |
721 |
|
|
} |
722 |
|
|
|
723 |
michael |
3670 |
if (dir == MODE_QUERY || parc <= *parn) |
724 |
adx |
30 |
return; |
725 |
|
|
|
726 |
michael |
3673 |
if ((target_p = find_chasing(source_p, parv[(*parn)++])) == NULL) |
727 |
michael |
3736 |
return; /* find_chasing sends ERR_NOSUCHNICK */ |
728 |
adx |
30 |
|
729 |
michael |
3143 |
if ((member = find_channel_link(target_p, chptr)) == NULL) |
730 |
adx |
30 |
{ |
731 |
|
|
if (!(*errors & SM_ERR_NOTONCHANNEL)) |
732 |
michael |
4617 |
sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->name); |
733 |
michael |
4883 |
|
734 |
adx |
30 |
*errors |= SM_ERR_NOTONCHANNEL; |
735 |
|
|
return; |
736 |
|
|
} |
737 |
|
|
|
738 |
|
|
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
739 |
|
|
return; |
740 |
|
|
|
741 |
michael |
6929 |
switch (dir) |
742 |
|
|
{ |
743 |
|
|
case MODE_ADD: |
744 |
|
|
if (has_member_flags(member, CHFL_HALFOP)) |
745 |
|
|
return; /* No redundant mode changes */ |
746 |
michael |
4883 |
|
747 |
michael |
6929 |
AddMemberFlag(member, CHFL_HALFOP); |
748 |
|
|
break; |
749 |
|
|
case MODE_DEL: |
750 |
|
|
if (!has_member_flags(member, CHFL_HALFOP)) |
751 |
|
|
return; /* No redundant mode changes */ |
752 |
adx |
30 |
|
753 |
michael |
6929 |
DelMemberFlag(member, CHFL_HALFOP); |
754 |
|
|
break; |
755 |
|
|
} |
756 |
|
|
|
757 |
michael |
8090 |
mode_changes[mode_count].letter = mode->letter; |
758 |
michael |
3735 |
mode_changes[mode_count].arg = target_p->name; |
759 |
|
|
mode_changes[mode_count].id = target_p->id; |
760 |
michael |
8039 |
mode_changes[mode_count].flags = 0; |
761 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
762 |
adx |
30 |
} |
763 |
|
|
|
764 |
|
|
static void |
765 |
michael |
8090 |
chm_op(struct Client *source_p, struct Channel *chptr, int parc, int *parn, char **parv, |
766 |
|
|
int *errors, int alev, int dir, const struct chan_mode *mode) |
767 |
adx |
30 |
{ |
768 |
michael |
3143 |
struct Client *target_p; |
769 |
adx |
30 |
struct Membership *member; |
770 |
|
|
|
771 |
michael |
2951 |
if (alev < CHACCESS_CHANOP) |
772 |
adx |
30 |
{ |
773 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
774 |
michael |
3109 |
sendto_one_numeric(source_p, &me, |
775 |
|
|
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
776 |
michael |
4617 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
777 |
michael |
4883 |
|
778 |
adx |
30 |
*errors |= SM_ERR_NOOPS; |
779 |
|
|
return; |
780 |
|
|
} |
781 |
|
|
|
782 |
michael |
3670 |
if (dir == MODE_QUERY || parc <= *parn) |
783 |
adx |
30 |
return; |
784 |
|
|
|
785 |
michael |
3673 |
if ((target_p = find_chasing(source_p, parv[(*parn)++])) == NULL) |
786 |
michael |
3736 |
return; /* find_chasing sends ERR_NOSUCHNICK */ |
787 |
adx |
30 |
|
788 |
michael |
3143 |
if ((member = find_channel_link(target_p, chptr)) == NULL) |
789 |
adx |
30 |
{ |
790 |
|
|
if (!(*errors & SM_ERR_NOTONCHANNEL)) |
791 |
michael |
4617 |
sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->name); |
792 |
michael |
4883 |
|
793 |
adx |
30 |
*errors |= SM_ERR_NOTONCHANNEL; |
794 |
|
|
return; |
795 |
|
|
} |
796 |
|
|
|
797 |
|
|
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
798 |
|
|
return; |
799 |
|
|
|
800 |
michael |
6929 |
switch (dir) |
801 |
|
|
{ |
802 |
|
|
case MODE_ADD: |
803 |
|
|
if (has_member_flags(member, CHFL_CHANOP)) |
804 |
|
|
return; /* No redundant mode changes */ |
805 |
michael |
4883 |
|
806 |
michael |
6929 |
AddMemberFlag(member, CHFL_CHANOP); |
807 |
|
|
break; |
808 |
|
|
case MODE_DEL: |
809 |
|
|
if (!has_member_flags(member, CHFL_CHANOP)) |
810 |
|
|
return; /* No redundant mode changes */ |
811 |
adx |
30 |
|
812 |
michael |
6929 |
DelMemberFlag(member, CHFL_CHANOP); |
813 |
|
|
break; |
814 |
|
|
} |
815 |
|
|
|
816 |
michael |
8090 |
mode_changes[mode_count].letter = mode->letter; |
817 |
michael |
3735 |
mode_changes[mode_count].arg = target_p->name; |
818 |
|
|
mode_changes[mode_count].id = target_p->id; |
819 |
michael |
8039 |
mode_changes[mode_count].flags = 0; |
820 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
821 |
adx |
30 |
} |
822 |
|
|
|
823 |
|
|
static void |
824 |
michael |
8090 |
chm_limit(struct Client *source_p, struct Channel *chptr, int parc, int *parn, char **parv, |
825 |
|
|
int *errors, int alev, int dir, const struct chan_mode *mode) |
826 |
adx |
30 |
{ |
827 |
|
|
if (alev < CHACCESS_HALFOP) |
828 |
|
|
{ |
829 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
830 |
michael |
3109 |
sendto_one_numeric(source_p, &me, |
831 |
|
|
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
832 |
michael |
4617 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
833 |
adx |
30 |
*errors |= SM_ERR_NOOPS; |
834 |
|
|
return; |
835 |
|
|
} |
836 |
|
|
|
837 |
|
|
if (dir == MODE_QUERY) |
838 |
|
|
return; |
839 |
|
|
|
840 |
michael |
3670 |
if (dir == MODE_ADD && parc > *parn) |
841 |
adx |
30 |
{ |
842 |
michael |
4834 |
char *const lstr = parv[(*parn)++]; |
843 |
michael |
6946 |
int limit = 0; |
844 |
adx |
30 |
|
845 |
michael |
3153 |
if (EmptyString(lstr) || (limit = atoi(lstr)) <= 0) |
846 |
adx |
30 |
return; |
847 |
|
|
|
848 |
michael |
1793 |
sprintf(lstr, "%d", limit); |
849 |
adx |
30 |
|
850 |
michael |
3151 |
/* If somebody sets MODE #channel +ll 1 2, accept latter --fl */ |
851 |
michael |
3670 |
for (unsigned int i = 0; i < mode_count; ++i) |
852 |
michael |
8090 |
if (mode_changes[i].letter == mode->letter && mode_changes[i].dir == MODE_ADD) |
853 |
adx |
30 |
mode_changes[i].letter = 0; |
854 |
|
|
|
855 |
michael |
8090 |
mode_changes[mode_count].letter = mode->letter; |
856 |
michael |
3735 |
mode_changes[mode_count].arg = lstr; |
857 |
adx |
30 |
mode_changes[mode_count].id = NULL; |
858 |
michael |
8039 |
mode_changes[mode_count].flags = 0; |
859 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
860 |
adx |
30 |
|
861 |
|
|
chptr->mode.limit = limit; |
862 |
|
|
} |
863 |
|
|
else if (dir == MODE_DEL) |
864 |
|
|
{ |
865 |
|
|
if (!chptr->mode.limit) |
866 |
|
|
return; |
867 |
|
|
|
868 |
|
|
chptr->mode.limit = 0; |
869 |
|
|
|
870 |
michael |
8090 |
mode_changes[mode_count].letter = mode->letter; |
871 |
michael |
3735 |
mode_changes[mode_count].arg = NULL; |
872 |
adx |
30 |
mode_changes[mode_count].id = NULL; |
873 |
michael |
8039 |
mode_changes[mode_count].flags = 0; |
874 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
875 |
adx |
30 |
} |
876 |
|
|
} |
877 |
|
|
|
878 |
|
|
static void |
879 |
michael |
8090 |
chm_key(struct Client *source_p, struct Channel *chptr, int parc, int *parn, char **parv, |
880 |
|
|
int *errors, int alev, int dir, const struct chan_mode *mode) |
881 |
adx |
30 |
{ |
882 |
|
|
if (alev < CHACCESS_HALFOP) |
883 |
|
|
{ |
884 |
|
|
if (!(*errors & SM_ERR_NOOPS)) |
885 |
michael |
3109 |
sendto_one_numeric(source_p, &me, |
886 |
|
|
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
887 |
michael |
4617 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
888 |
adx |
30 |
*errors |= SM_ERR_NOOPS; |
889 |
|
|
return; |
890 |
|
|
} |
891 |
|
|
|
892 |
|
|
if (dir == MODE_QUERY) |
893 |
|
|
return; |
894 |
|
|
|
895 |
michael |
3670 |
if (dir == MODE_ADD && parc > *parn) |
896 |
adx |
30 |
{ |
897 |
michael |
4834 |
char *const key = fix_key(parv[(*parn)++]); |
898 |
adx |
30 |
|
899 |
michael |
3153 |
if (EmptyString(key)) |
900 |
adx |
30 |
return; |
901 |
|
|
|
902 |
|
|
assert(key[0] != ' '); |
903 |
|
|
strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key)); |
904 |
|
|
|
905 |
michael |
3151 |
/* If somebody does MODE #channel +kk a b, accept latter --fl */ |
906 |
michael |
3670 |
for (unsigned int i = 0; i < mode_count; ++i) |
907 |
michael |
8090 |
if (mode_changes[i].letter == mode->letter && mode_changes[i].dir == MODE_ADD) |
908 |
adx |
30 |
mode_changes[i].letter = 0; |
909 |
|
|
|
910 |
michael |
8090 |
mode_changes[mode_count].letter = mode->letter; |
911 |
michael |
8021 |
mode_changes[mode_count].arg = key; |
912 |
adx |
30 |
mode_changes[mode_count].id = NULL; |
913 |
michael |
8039 |
mode_changes[mode_count].flags = 0; |
914 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
915 |
adx |
30 |
} |
916 |
|
|
else if (dir == MODE_DEL) |
917 |
|
|
{ |
918 |
|
|
if (parc > *parn) |
919 |
michael |
4790 |
++(*parn); |
920 |
adx |
30 |
|
921 |
|
|
if (chptr->mode.key[0] == '\0') |
922 |
|
|
return; |
923 |
|
|
|
924 |
|
|
chptr->mode.key[0] = '\0'; |
925 |
|
|
|
926 |
michael |
8090 |
mode_changes[mode_count].letter = mode->letter; |
927 |
michael |
3735 |
mode_changes[mode_count].arg = "*"; |
928 |
adx |
30 |
mode_changes[mode_count].id = NULL; |
929 |
michael |
8039 |
mode_changes[mode_count].flags = 0; |
930 |
michael |
4798 |
mode_changes[mode_count++].dir = dir; |
931 |
adx |
30 |
} |
932 |
|
|
} |
933 |
|
|
|
934 |
|
|
/* get_channel_access() |
935 |
|
|
* |
936 |
|
|
* inputs - pointer to Client struct |
937 |
|
|
* - pointer to Membership struct |
938 |
|
|
* output - CHACCESS_CHANOP if we should let them have |
939 |
|
|
* chanop level access, 0 for peon level access. |
940 |
|
|
* side effects - NONE |
941 |
|
|
*/ |
942 |
|
|
static int |
943 |
michael |
2941 |
get_channel_access(const struct Client *source_p, |
944 |
|
|
const struct Membership *member) |
945 |
adx |
30 |
{ |
946 |
|
|
/* Let hacked servers in for now... */ |
947 |
|
|
if (!MyClient(source_p)) |
948 |
michael |
4101 |
return CHACCESS_REMOTE; |
949 |
adx |
30 |
|
950 |
michael |
3235 |
if (!member) |
951 |
adx |
30 |
return CHACCESS_NOTONCHAN; |
952 |
|
|
|
953 |
michael |
3374 |
/* Just to be sure.. */ |
954 |
adx |
30 |
assert(source_p == member->client_p); |
955 |
|
|
|
956 |
|
|
if (has_member_flags(member, CHFL_CHANOP)) |
957 |
|
|
return CHACCESS_CHANOP; |
958 |
|
|
|
959 |
|
|
if (has_member_flags(member, CHFL_HALFOP)) |
960 |
|
|
return CHACCESS_HALFOP; |
961 |
|
|
|
962 |
|
|
return CHACCESS_PEON; |
963 |
|
|
} |
964 |
|
|
|
965 |
michael |
3151 |
/* send_mode_changes_server() |
966 |
michael |
3159 |
* Input: the source client(source_p), |
967 |
adx |
30 |
* the channel to send mode changes for(chptr) |
968 |
|
|
* Output: None. |
969 |
michael |
3151 |
* Side-effects: Sends the appropriate mode changes to servers. |
970 |
adx |
30 |
* |
971 |
|
|
*/ |
972 |
|
|
static void |
973 |
michael |
3150 |
send_mode_changes_server(struct Client *source_p, struct Channel *chptr) |
974 |
adx |
30 |
{ |
975 |
michael |
8015 |
char modebuf[IRCD_BUFSIZE] = ""; |
976 |
|
|
char parabuf[IRCD_BUFSIZE] = ""; |
977 |
|
|
char *parptr = parabuf; |
978 |
michael |
8041 |
unsigned int mbl = 0, pbl = 0, arglen = 0, modecount = 0, paracount = 0; |
979 |
|
|
unsigned int dir = MODE_QUERY; |
980 |
adx |
30 |
|
981 |
michael |
8015 |
mbl = snprintf(modebuf, sizeof(modebuf), ":%s TMODE %ju %s ", |
982 |
|
|
source_p->id, chptr->creationtime, chptr->name); |
983 |
adx |
30 |
|
984 |
michael |
3374 |
/* Loop the list of modes we have */ |
985 |
michael |
5546 |
for (unsigned int i = 0; i < mode_count; ++i) |
986 |
adx |
30 |
{ |
987 |
michael |
3669 |
if (mode_changes[i].letter == 0) |
988 |
adx |
30 |
continue; |
989 |
|
|
|
990 |
michael |
8015 |
const char *arg; |
991 |
michael |
3141 |
if (mode_changes[i].id) |
992 |
|
|
arg = mode_changes[i].id; |
993 |
|
|
else |
994 |
|
|
arg = mode_changes[i].arg; |
995 |
adx |
30 |
|
996 |
michael |
3215 |
if (arg) |
997 |
michael |
3141 |
arglen = strlen(arg); |
998 |
|
|
else |
999 |
|
|
arglen = 0; |
1000 |
|
|
|
1001 |
michael |
3136 |
/* |
1002 |
|
|
* If we're creeping past the buf size, we need to send it and make |
1003 |
adx |
30 |
* another line for the other modes |
1004 |
|
|
*/ |
1005 |
michael |
8013 |
if ((paracount == MAXMODEPARAMS) || |
1006 |
michael |
8015 |
((arglen + mbl + pbl + 2 /* +2 for /r/n */ ) > IRCD_BUFSIZE)) |
1007 |
adx |
30 |
{ |
1008 |
michael |
8013 |
if (modecount) |
1009 |
michael |
4963 |
sendto_server(source_p, 0, 0, "%s %s", modebuf, parabuf); |
1010 |
michael |
3215 |
|
1011 |
michael |
8013 |
modecount = 0; |
1012 |
|
|
paracount = 0; |
1013 |
adx |
30 |
|
1014 |
michael |
8015 |
mbl = snprintf(modebuf, sizeof(modebuf), ":%s TMODE %ju %s ", |
1015 |
|
|
source_p->id, chptr->creationtime, chptr->name); |
1016 |
adx |
30 |
|
1017 |
|
|
pbl = 0; |
1018 |
|
|
parabuf[0] = '\0'; |
1019 |
|
|
parptr = parabuf; |
1020 |
|
|
dir = MODE_QUERY; |
1021 |
|
|
} |
1022 |
|
|
|
1023 |
|
|
if (dir != mode_changes[i].dir) |
1024 |
|
|
{ |
1025 |
|
|
modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-'; |
1026 |
|
|
dir = mode_changes[i].dir; |
1027 |
|
|
} |
1028 |
|
|
|
1029 |
|
|
modebuf[mbl++] = mode_changes[i].letter; |
1030 |
|
|
modebuf[mbl] = '\0'; |
1031 |
michael |
8013 |
++modecount; |
1032 |
adx |
30 |
|
1033 |
michael |
3215 |
if (arg) |
1034 |
adx |
30 |
{ |
1035 |
michael |
8015 |
int len = sprintf(parptr, (pbl == 0) ? "%s" : " %s", arg); |
1036 |
adx |
30 |
pbl += len; |
1037 |
|
|
parptr += len; |
1038 |
michael |
8013 |
++paracount; |
1039 |
adx |
30 |
} |
1040 |
|
|
} |
1041 |
|
|
|
1042 |
michael |
8013 |
if (modecount) |
1043 |
michael |
4963 |
sendto_server(source_p, 0, 0, "%s %s", modebuf, parabuf); |
1044 |
adx |
30 |
} |
1045 |
|
|
|
1046 |
|
|
/* void send_mode_changes(struct Client *client_p, |
1047 |
|
|
* struct Client *source_p, |
1048 |
|
|
* struct Channel *chptr) |
1049 |
|
|
* Input: The client sending(client_p), the source client(source_p), |
1050 |
|
|
* the channel to send mode changes for(chptr), |
1051 |
|
|
* mode change globals. |
1052 |
|
|
* Output: None. |
1053 |
|
|
* Side-effects: Sends the appropriate mode changes to other clients |
1054 |
|
|
* and propagates to servers. |
1055 |
|
|
*/ |
1056 |
|
|
static void |
1057 |
michael |
5747 |
send_mode_changes_client(struct Client *source_p, struct Channel *chptr) |
1058 |
adx |
30 |
{ |
1059 |
michael |
8039 |
unsigned int flags = 0; |
1060 |
adx |
30 |
|
1061 |
michael |
8039 |
for (unsigned int pass = 2; pass--; flags = CHFL_CHANOP | CHFL_HALFOP) |
1062 |
adx |
30 |
{ |
1063 |
michael |
8039 |
char modebuf[IRCD_BUFSIZE] = ""; |
1064 |
|
|
char parabuf[IRCD_BUFSIZE] = ""; |
1065 |
|
|
char *parptr = parabuf; |
1066 |
michael |
8041 |
unsigned int mbl = 0, pbl = 0, arglen = 0, modecount = 0, paracount = 0; |
1067 |
|
|
unsigned int dir = MODE_QUERY; |
1068 |
adx |
30 |
|
1069 |
michael |
8039 |
if (IsServer(source_p)) |
1070 |
|
|
mbl = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s ", (IsHidden(source_p) || |
1071 |
|
|
ConfigServerHide.hide_servers) ? |
1072 |
|
|
me.name : source_p->name, chptr->name); |
1073 |
adx |
30 |
else |
1074 |
michael |
8039 |
mbl = snprintf(modebuf, sizeof(modebuf), ":%s!%s@%s MODE %s ", source_p->name, |
1075 |
|
|
source_p->username, source_p->host, chptr->name); |
1076 |
adx |
30 |
|
1077 |
michael |
8039 |
for (unsigned int i = 0; i < mode_count; ++i) |
1078 |
adx |
30 |
{ |
1079 |
michael |
8039 |
if (mode_changes[i].letter == 0 || mode_changes[i].flags != flags) |
1080 |
|
|
continue; |
1081 |
adx |
30 |
|
1082 |
michael |
8039 |
const char *arg = mode_changes[i].arg; |
1083 |
|
|
if (arg) |
1084 |
|
|
arglen = strlen(arg); |
1085 |
adx |
30 |
else |
1086 |
michael |
8039 |
arglen = 0; |
1087 |
adx |
30 |
|
1088 |
michael |
8039 |
if ((paracount == MAXMODEPARAMS) || |
1089 |
|
|
((arglen + mbl + pbl + 2 /* +2 for /r/n */ ) > IRCD_BUFSIZE)) |
1090 |
|
|
{ |
1091 |
|
|
if (modecount) |
1092 |
|
|
sendto_channel_local(NULL, chptr, flags, 0, 0, "%s %s", modebuf, parabuf); |
1093 |
adx |
30 |
|
1094 |
michael |
8039 |
modecount = 0; |
1095 |
|
|
paracount = 0; |
1096 |
adx |
30 |
|
1097 |
michael |
8039 |
if (IsServer(source_p)) |
1098 |
|
|
mbl = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s ", (IsHidden(source_p) || |
1099 |
|
|
ConfigServerHide.hide_servers) ? |
1100 |
|
|
me.name : source_p->name, chptr->name); |
1101 |
|
|
else |
1102 |
|
|
mbl = snprintf(modebuf, sizeof(modebuf), ":%s!%s@%s MODE %s ", source_p->name, |
1103 |
|
|
source_p->username, source_p->host, chptr->name); |
1104 |
adx |
30 |
|
1105 |
michael |
8039 |
pbl = 0; |
1106 |
|
|
parabuf[0] = '\0'; |
1107 |
|
|
parptr = parabuf; |
1108 |
|
|
dir = MODE_QUERY; |
1109 |
|
|
} |
1110 |
|
|
|
1111 |
|
|
if (dir != mode_changes[i].dir) |
1112 |
|
|
{ |
1113 |
|
|
modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-'; |
1114 |
|
|
dir = mode_changes[i].dir; |
1115 |
|
|
} |
1116 |
|
|
|
1117 |
|
|
modebuf[mbl++] = mode_changes[i].letter; |
1118 |
|
|
modebuf[mbl] = '\0'; |
1119 |
|
|
++modecount; |
1120 |
|
|
|
1121 |
|
|
if (arg) |
1122 |
|
|
{ |
1123 |
|
|
int len = sprintf(parptr, (pbl == 0) ? "%s" : " %s", arg); |
1124 |
|
|
pbl += len; |
1125 |
|
|
parptr += len; |
1126 |
|
|
++paracount; |
1127 |
|
|
} |
1128 |
adx |
30 |
} |
1129 |
michael |
8039 |
|
1130 |
|
|
if (modecount) |
1131 |
|
|
sendto_channel_local(NULL, chptr, flags, 0, 0, "%s %s", modebuf, parabuf); |
1132 |
adx |
30 |
} |
1133 |
|
|
} |
1134 |
|
|
|
1135 |
michael |
8090 |
const struct chan_mode *cmode_map[256]; |
1136 |
|
|
const struct chan_mode cmode_tab[] = |
1137 |
michael |
8088 |
{ |
1138 |
michael |
8093 |
{ .letter = 'b', .func = chm_ban }, |
1139 |
|
|
{ .letter = 'c', .mode = MODE_NOCTRL, .func = chm_simple }, |
1140 |
|
|
{ .letter = 'e', .func = chm_except }, |
1141 |
|
|
{ .letter = 'h', .func = chm_hop }, |
1142 |
|
|
{ .letter = 'i', .mode = MODE_INVITEONLY, .func = chm_simple }, |
1143 |
|
|
{ .letter = 'k', .func = chm_key }, |
1144 |
|
|
{ .letter = 'l', .func = chm_limit }, |
1145 |
|
|
{ .letter = 'm', .mode = MODE_MODERATED, .func = chm_simple }, |
1146 |
|
|
{ .letter = 'n', .mode = MODE_NOPRIVMSGS, .func = chm_simple }, |
1147 |
|
|
{ .letter = 'o', .func = chm_op }, |
1148 |
|
|
{ .letter = 'p', .mode = MODE_PRIVATE, .func = chm_simple }, |
1149 |
|
|
{ .letter = 'r', .mode = MODE_REGISTERED, .only_servers = 1, .func = chm_simple }, |
1150 |
|
|
{ .letter = 's', .mode = MODE_SECRET, .func = chm_simple }, |
1151 |
|
|
{ .letter = 't', .mode = MODE_TOPICLIMIT, .func = chm_simple }, |
1152 |
|
|
{ .letter = 'u', .mode = MODE_HIDEBMASKS, .func = chm_simple }, |
1153 |
|
|
{ .letter = 'v', .func = chm_voice }, |
1154 |
|
|
{ .letter = 'C', .mode = MODE_NOCTCP, .func = chm_simple }, |
1155 |
|
|
{ .letter = 'I', .func = chm_invex }, |
1156 |
|
|
{ .letter = 'L', .mode = MODE_EXTLIMIT, .only_opers = 1, .func = chm_simple }, |
1157 |
|
|
{ .letter = 'M', .mode = MODE_MODREG, .func = chm_simple}, |
1158 |
|
|
{ .letter = 'O', .mode = MODE_OPERONLY, .only_opers = 1, .func = chm_simple }, |
1159 |
|
|
{ .letter = 'R', .mode = MODE_REGONLY, .func = chm_simple}, |
1160 |
|
|
{ .letter = 'S', .mode = MODE_SSLONLY, .func = chm_simple}, |
1161 |
|
|
{ .letter = 'T', .mode = MODE_NONOTICE, .func = chm_simple}, |
1162 |
|
|
{ .letter = '\0', .mode = 0 } |
1163 |
michael |
8088 |
}; |
1164 |
|
|
|
1165 |
|
|
void |
1166 |
|
|
channel_mode_init(void) |
1167 |
|
|
{ |
1168 |
michael |
8090 |
for (const struct chan_mode *tab = cmode_tab; tab->letter; ++tab) |
1169 |
michael |
8088 |
cmode_map[tab->letter] = tab; |
1170 |
|
|
} |
1171 |
|
|
|
1172 |
michael |
3670 |
/* |
1173 |
michael |
3159 |
* Input: The the client this originated |
1174 |
adx |
30 |
* from, the channel, the parameter count starting at the modes, |
1175 |
|
|
* the parameters, the channel name. |
1176 |
|
|
* Output: None. |
1177 |
|
|
* Side-effects: Changes the channel membership and modes appropriately, |
1178 |
|
|
* sends the appropriate MODE messages to the appropriate |
1179 |
|
|
* clients. |
1180 |
|
|
*/ |
1181 |
|
|
void |
1182 |
michael |
3150 |
set_channel_mode(struct Client *source_p, struct Channel *chptr, |
1183 |
michael |
2937 |
struct Membership *member, int parc, char *parv[]) |
1184 |
adx |
30 |
{ |
1185 |
|
|
int dir = MODE_ADD; |
1186 |
|
|
int parn = 1; |
1187 |
michael |
3670 |
int alevel = 0, errors = 0; |
1188 |
adx |
30 |
|
1189 |
|
|
mode_count = 0; |
1190 |
|
|
mode_limit = 0; |
1191 |
|
|
simple_modes_mask = 0; |
1192 |
|
|
|
1193 |
|
|
alevel = get_channel_access(source_p, member); |
1194 |
|
|
|
1195 |
michael |
3283 |
for (const char *ml = parv[0]; *ml; ++ml) |
1196 |
adx |
30 |
{ |
1197 |
michael |
3250 |
switch (*ml) |
1198 |
adx |
30 |
{ |
1199 |
|
|
case '+': |
1200 |
|
|
dir = MODE_ADD; |
1201 |
|
|
break; |
1202 |
|
|
case '-': |
1203 |
|
|
dir = MODE_DEL; |
1204 |
|
|
break; |
1205 |
|
|
case '=': |
1206 |
|
|
dir = MODE_QUERY; |
1207 |
|
|
break; |
1208 |
|
|
default: |
1209 |
michael |
2939 |
{ |
1210 |
michael |
8090 |
const struct chan_mode *mode = cmode_map[(unsigned char)*ml]; |
1211 |
michael |
2939 |
|
1212 |
michael |
8088 |
if (mode) |
1213 |
michael |
8090 |
mode->func(source_p, chptr, parc, &parn, parv, &errors, alevel, dir, mode); |
1214 |
michael |
8088 |
else |
1215 |
michael |
8090 |
chm_nosuch(source_p, chptr, parc, &parn, parv, &errors, alevel, dir, mode); |
1216 |
adx |
30 |
break; |
1217 |
michael |
2939 |
} |
1218 |
adx |
30 |
} |
1219 |
|
|
} |
1220 |
|
|
|
1221 |
michael |
5750 |
/* Bail out if we have nothing to do... */ |
1222 |
|
|
if (!mode_count) |
1223 |
|
|
return; |
1224 |
|
|
|
1225 |
michael |
5747 |
send_mode_changes_client(source_p, chptr); |
1226 |
|
|
send_mode_changes_server(source_p, chptr); |
1227 |
adx |
30 |
} |