1 |
adx |
30 |
/* |
2 |
michael |
2916 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
2916 |
* Copyright (c) 1997-2014 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 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
19 |
|
|
* USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
/*! \file channel.c |
23 |
|
|
* \brief Responsible for managing channels, members, bans and topics |
24 |
knight |
31 |
* \version $Id$ |
25 |
adx |
30 |
*/ |
26 |
|
|
|
27 |
|
|
#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 |
|
|
#include "hash.h" |
33 |
michael |
1632 |
#include "conf.h" |
34 |
michael |
371 |
#include "hostmask.h" |
35 |
adx |
30 |
#include "irc_string.h" |
36 |
|
|
#include "ircd.h" |
37 |
|
|
#include "numeric.h" |
38 |
michael |
2916 |
#include "s_serv.h" |
39 |
adx |
30 |
#include "send.h" |
40 |
|
|
#include "event.h" |
41 |
|
|
#include "memory.h" |
42 |
michael |
1654 |
#include "mempool.h" |
43 |
michael |
1751 |
#include "s_misc.h" |
44 |
michael |
1826 |
#include "resv.h" |
45 |
adx |
30 |
|
46 |
michael |
3235 |
|
47 |
|
|
dlink_list global_channel_list; |
48 |
michael |
1654 |
mp_pool_t *ban_pool; /*! \todo ban_pool shouldn't be a global var */ |
49 |
adx |
30 |
|
50 |
michael |
3250 |
static mp_pool_t *member_pool, *channel_pool; |
51 |
adx |
30 |
static char buf[IRCD_BUFSIZE]; |
52 |
|
|
|
53 |
|
|
|
54 |
|
|
/*! \brief Initializes the channel blockheap, adds known channel CAPAB |
55 |
|
|
*/ |
56 |
|
|
void |
57 |
michael |
1798 |
channel_init(void) |
58 |
adx |
30 |
{ |
59 |
|
|
add_capability("EX", CAP_EX, 1); |
60 |
|
|
add_capability("IE", CAP_IE, 1); |
61 |
|
|
|
62 |
michael |
1654 |
channel_pool = mp_pool_new(sizeof(struct Channel), MP_CHUNK_SIZE_CHANNEL); |
63 |
|
|
ban_pool = mp_pool_new(sizeof(struct Ban), MP_CHUNK_SIZE_BAN); |
64 |
|
|
member_pool = mp_pool_new(sizeof(struct Membership), MP_CHUNK_SIZE_MEMBER); |
65 |
adx |
30 |
} |
66 |
|
|
|
67 |
michael |
3308 |
/*! \brief Adds a user to a channel by adding another link to the |
68 |
adx |
30 |
* channels member chain. |
69 |
michael |
3308 |
* \param chptr Pointer to channel to add client to |
70 |
|
|
* \param who Pointer to client (who) to add |
71 |
|
|
* \param flags Flags for chanops etc |
72 |
|
|
* \param flood_ctrl Whether to count this join in flood calculations |
73 |
adx |
30 |
*/ |
74 |
|
|
void |
75 |
|
|
add_user_to_channel(struct Channel *chptr, struct Client *who, |
76 |
|
|
unsigned int flags, int flood_ctrl) |
77 |
|
|
{ |
78 |
|
|
struct Membership *ms = NULL; |
79 |
|
|
|
80 |
|
|
if (GlobalSetOptions.joinfloodtime > 0) |
81 |
|
|
{ |
82 |
|
|
if (flood_ctrl) |
83 |
michael |
3250 |
++chptr->number_joined; |
84 |
adx |
30 |
|
85 |
|
|
chptr->number_joined -= (CurrentTime - chptr->last_join_time) * |
86 |
|
|
(((float)GlobalSetOptions.joinfloodcount) / |
87 |
|
|
(float)GlobalSetOptions.joinfloodtime); |
88 |
|
|
|
89 |
|
|
if (chptr->number_joined <= 0) |
90 |
|
|
{ |
91 |
|
|
chptr->number_joined = 0; |
92 |
|
|
ClearJoinFloodNoticed(chptr); |
93 |
|
|
} |
94 |
|
|
else if (chptr->number_joined >= GlobalSetOptions.joinfloodcount) |
95 |
|
|
{ |
96 |
|
|
chptr->number_joined = GlobalSetOptions.joinfloodcount; |
97 |
|
|
|
98 |
|
|
if (!IsSetJoinFloodNoticed(chptr)) |
99 |
|
|
{ |
100 |
|
|
SetJoinFloodNoticed(chptr); |
101 |
michael |
1618 |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
102 |
adx |
30 |
"Possible Join Flooder %s on %s target: %s", |
103 |
|
|
get_client_name(who, HIDE_IP), |
104 |
|
|
who->servptr->name, chptr->chname); |
105 |
|
|
} |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
chptr->last_join_time = CurrentTime; |
109 |
|
|
} |
110 |
|
|
|
111 |
michael |
1654 |
ms = mp_pool_get(member_pool); |
112 |
|
|
memset(ms, 0, sizeof(*ms)); |
113 |
|
|
|
114 |
adx |
30 |
ms->client_p = who; |
115 |
|
|
ms->chptr = chptr; |
116 |
|
|
ms->flags = flags; |
117 |
|
|
|
118 |
|
|
dlinkAdd(ms, &ms->channode, &chptr->members); |
119 |
|
|
dlinkAdd(ms, &ms->usernode, &who->channel); |
120 |
|
|
} |
121 |
|
|
|
122 |
michael |
3308 |
/*! \brief Deletes an user from a channel by removing a link in the |
123 |
adx |
30 |
* channels member chain. |
124 |
michael |
3308 |
* \param member Pointer to Membership struct |
125 |
adx |
30 |
*/ |
126 |
|
|
void |
127 |
|
|
remove_user_from_channel(struct Membership *member) |
128 |
|
|
{ |
129 |
|
|
struct Client *client_p = member->client_p; |
130 |
|
|
struct Channel *chptr = member->chptr; |
131 |
|
|
|
132 |
|
|
dlinkDelete(&member->channode, &chptr->members); |
133 |
|
|
dlinkDelete(&member->usernode, &client_p->channel); |
134 |
|
|
|
135 |
michael |
1654 |
mp_pool_release(member); |
136 |
adx |
30 |
|
137 |
michael |
1011 |
if (chptr->members.head == NULL) |
138 |
adx |
30 |
destroy_channel(chptr); |
139 |
|
|
} |
140 |
|
|
|
141 |
|
|
/* send_members() |
142 |
|
|
* |
143 |
|
|
* inputs - |
144 |
|
|
* output - NONE |
145 |
|
|
* side effects - |
146 |
|
|
*/ |
147 |
|
|
static void |
148 |
|
|
send_members(struct Client *client_p, struct Channel *chptr, |
149 |
michael |
3145 |
char *modebuf, char *parabuf) |
150 |
adx |
30 |
{ |
151 |
michael |
1847 |
const dlink_node *ptr = NULL; |
152 |
adx |
30 |
int tlen; /* length of text to append */ |
153 |
|
|
char *t, *start; /* temp char pointer */ |
154 |
|
|
|
155 |
michael |
1847 |
start = t = buf + snprintf(buf, sizeof(buf), ":%s SJOIN %lu %s %s %s:", |
156 |
michael |
3183 |
me.id, (unsigned long)chptr->channelts, |
157 |
michael |
3145 |
chptr->chname, modebuf, parabuf); |
158 |
adx |
30 |
|
159 |
|
|
DLINK_FOREACH(ptr, chptr->members.head) |
160 |
|
|
{ |
161 |
michael |
1847 |
const struct Membership *ms = ptr->data; |
162 |
adx |
30 |
|
163 |
michael |
3186 |
tlen = strlen(ms->client_p->id) + 1; /* nick + space */ |
164 |
adx |
30 |
|
165 |
|
|
if (ms->flags & CHFL_CHANOP) |
166 |
michael |
3250 |
++tlen; |
167 |
adx |
30 |
#ifdef HALFOPS |
168 |
michael |
3140 |
if (ms->flags & CHFL_HALFOP) |
169 |
michael |
3250 |
++tlen; |
170 |
adx |
30 |
#endif |
171 |
|
|
if (ms->flags & CHFL_VOICE) |
172 |
michael |
3250 |
++tlen; |
173 |
adx |
30 |
|
174 |
michael |
3250 |
/* |
175 |
|
|
* Space will be converted into CR, but we also need space for LF.. |
176 |
|
|
* That's why we use '- 1' here -adx |
177 |
|
|
*/ |
178 |
michael |
1330 |
if (t + tlen - buf > IRCD_BUFSIZE - 1) |
179 |
adx |
30 |
{ |
180 |
michael |
3250 |
*(t - 1) = '\0'; /* Kill the space and terminate the string */ |
181 |
adx |
30 |
sendto_one(client_p, "%s", buf); |
182 |
|
|
t = start; |
183 |
|
|
} |
184 |
|
|
|
185 |
michael |
3140 |
if (ms->flags & CHFL_CHANOP) |
186 |
|
|
*t++ = '@'; |
187 |
|
|
if (ms->flags & CHFL_HALFOP) |
188 |
|
|
*t++ = '%'; |
189 |
|
|
if (ms->flags & CHFL_VOICE) |
190 |
adx |
356 |
*t++ = '+'; |
191 |
adx |
30 |
|
192 |
michael |
3186 |
strcpy(t, ms->client_p->id); |
193 |
michael |
3135 |
|
194 |
adx |
30 |
t += strlen(t); |
195 |
|
|
*t++ = ' '; |
196 |
|
|
} |
197 |
|
|
|
198 |
michael |
3250 |
/* Should always be non-NULL unless we have a kind of persistent channels */ |
199 |
michael |
3235 |
if (chptr->members.head) |
200 |
michael |
3250 |
t--; /* Take the space out */ |
201 |
adx |
30 |
*t = '\0'; |
202 |
|
|
sendto_one(client_p, "%s", buf); |
203 |
|
|
} |
204 |
|
|
|
205 |
michael |
3308 |
/*! \brief Sends +b/+e/+I |
206 |
|
|
* \param client_p Client pointer to server |
207 |
|
|
* \param chptr Pointer to channel |
208 |
|
|
* \param top Pointer to top of mode link list to send |
209 |
|
|
* \param flag Char flag flagging type of mode. Currently this can be 'b', e' or 'I' |
210 |
adx |
30 |
*/ |
211 |
|
|
static void |
212 |
|
|
send_mode_list(struct Client *client_p, struct Channel *chptr, |
213 |
michael |
1847 |
const dlink_list *top, char flag) |
214 |
adx |
30 |
{ |
215 |
michael |
3250 |
const dlink_node *ptr = NULL; |
216 |
michael |
3215 |
char pbuf[IRCD_BUFSIZE] = ""; |
217 |
adx |
30 |
int tlen, mlen, cur_len, count = 0; |
218 |
michael |
3144 |
char *pp = pbuf; |
219 |
adx |
30 |
|
220 |
michael |
3215 |
if (top->length == 0) |
221 |
adx |
30 |
return; |
222 |
|
|
|
223 |
michael |
3135 |
mlen = snprintf(buf, sizeof(buf), ":%s BMASK %lu %s %c :", me.id, |
224 |
|
|
(unsigned long)chptr->channelts, chptr->chname, flag); |
225 |
|
|
cur_len = mlen; |
226 |
adx |
30 |
|
227 |
michael |
3250 |
DLINK_FOREACH(ptr, top->head) |
228 |
adx |
30 |
{ |
229 |
michael |
3250 |
const struct Ban *banptr = ptr->data; |
230 |
adx |
30 |
|
231 |
michael |
3135 |
tlen = banptr->len + 3; |
232 |
adx |
30 |
|
233 |
|
|
/* |
234 |
michael |
3250 |
* Send buffer and start over if we cannot fit another ban, |
235 |
adx |
30 |
* or if the target is non-ts6 and we have too many modes in |
236 |
|
|
* in this line. |
237 |
|
|
*/ |
238 |
michael |
3135 |
if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2) |
239 |
adx |
30 |
{ |
240 |
michael |
3250 |
*(pp - 1) = '\0'; /* Get rid of trailing space on buffer */ |
241 |
michael |
3135 |
sendto_one(client_p, "%s%s", buf, pbuf); |
242 |
adx |
30 |
|
243 |
michael |
3135 |
cur_len = mlen; |
244 |
adx |
30 |
pp = pbuf; |
245 |
|
|
count = 0; |
246 |
|
|
} |
247 |
|
|
|
248 |
|
|
count++; |
249 |
michael |
2296 |
pp += sprintf(pp, "%s!%s@%s ", banptr->name, banptr->user, |
250 |
michael |
1793 |
banptr->host); |
251 |
adx |
30 |
cur_len += tlen; |
252 |
|
|
} |
253 |
|
|
|
254 |
michael |
3250 |
*(pp - 1) = '\0'; /* Get rid of trailing space on buffer */ |
255 |
michael |
3135 |
sendto_one(client_p, "%s%s", buf, pbuf); |
256 |
adx |
30 |
} |
257 |
|
|
|
258 |
michael |
3308 |
/*! \brief Send "client_p" a full list of the modes for channel chptr |
259 |
|
|
* \param client_p Pointer to client client_p |
260 |
|
|
* \param chptr Pointer to channel pointer |
261 |
adx |
30 |
*/ |
262 |
|
|
void |
263 |
|
|
send_channel_modes(struct Client *client_p, struct Channel *chptr) |
264 |
|
|
{ |
265 |
michael |
3145 |
char modebuf[MODEBUFLEN] = ""; |
266 |
|
|
char parabuf[MODEBUFLEN] = ""; |
267 |
|
|
|
268 |
adx |
30 |
channel_modes(chptr, client_p, modebuf, parabuf); |
269 |
|
|
send_members(client_p, chptr, modebuf, parabuf); |
270 |
|
|
|
271 |
|
|
send_mode_list(client_p, chptr, &chptr->banlist, 'b'); |
272 |
michael |
1661 |
send_mode_list(client_p, chptr, &chptr->exceptlist, 'e'); |
273 |
|
|
send_mode_list(client_p, chptr, &chptr->invexlist, 'I'); |
274 |
adx |
30 |
} |
275 |
|
|
|
276 |
michael |
3308 |
/*! \brief Check channel name for invalid characters |
277 |
|
|
* \param name Pointer to channel name string |
278 |
|
|
* \param local Indicates whether it's a local or remote creation |
279 |
michael |
632 |
* \return 0 if invalid, 1 otherwise |
280 |
adx |
30 |
*/ |
281 |
|
|
int |
282 |
michael |
1847 |
check_channel_name(const char *name, const int local) |
283 |
adx |
30 |
{ |
284 |
michael |
632 |
const char *p = name; |
285 |
michael |
1455 |
const int max_length = local ? LOCAL_CHANNELLEN : CHANNELLEN; |
286 |
adx |
30 |
assert(name != NULL); |
287 |
|
|
|
288 |
michael |
632 |
if (!IsChanPrefix(*p)) |
289 |
|
|
return 0; |
290 |
adx |
30 |
|
291 |
db |
633 |
if (!local || !ConfigChannel.disable_fake_channels) |
292 |
michael |
632 |
{ |
293 |
|
|
while (*++p) |
294 |
db |
634 |
if (!IsChanChar(*p)) |
295 |
michael |
632 |
return 0; |
296 |
|
|
} |
297 |
|
|
else |
298 |
|
|
{ |
299 |
|
|
while (*++p) |
300 |
db |
634 |
if (!IsVisibleChanChar(*p)) |
301 |
michael |
632 |
return 0; |
302 |
|
|
} |
303 |
|
|
|
304 |
|
|
return p - name <= max_length; |
305 |
adx |
30 |
} |
306 |
|
|
|
307 |
|
|
void |
308 |
|
|
remove_ban(struct Ban *bptr, dlink_list *list) |
309 |
|
|
{ |
310 |
|
|
dlinkDelete(&bptr->node, list); |
311 |
|
|
|
312 |
|
|
MyFree(bptr->name); |
313 |
michael |
2296 |
MyFree(bptr->user); |
314 |
adx |
30 |
MyFree(bptr->host); |
315 |
|
|
MyFree(bptr->who); |
316 |
|
|
|
317 |
michael |
1654 |
mp_pool_release(bptr); |
318 |
adx |
30 |
} |
319 |
|
|
|
320 |
|
|
/* free_channel_list() |
321 |
|
|
* |
322 |
|
|
* inputs - pointer to dlink_list |
323 |
|
|
* output - NONE |
324 |
|
|
* side effects - |
325 |
|
|
*/ |
326 |
|
|
void |
327 |
|
|
free_channel_list(dlink_list *list) |
328 |
|
|
{ |
329 |
michael |
3250 |
dlink_node *ptr = NULL, *ptr_next = NULL; |
330 |
adx |
30 |
|
331 |
michael |
3250 |
DLINK_FOREACH_SAFE(ptr, ptr_next, list->head) |
332 |
adx |
30 |
remove_ban(ptr->data, list); |
333 |
|
|
|
334 |
|
|
assert(list->tail == NULL && list->head == NULL); |
335 |
|
|
} |
336 |
|
|
|
337 |
|
|
/*! \brief Get Channel block for chname (and allocate a new channel |
338 |
|
|
* block, if it didn't exist before) |
339 |
michael |
3308 |
* \param chname Channel name |
340 |
|
|
* \return Channel block |
341 |
adx |
30 |
*/ |
342 |
|
|
struct Channel * |
343 |
michael |
632 |
make_channel(const char *chname) |
344 |
adx |
30 |
{ |
345 |
|
|
struct Channel *chptr = NULL; |
346 |
|
|
|
347 |
michael |
632 |
assert(!EmptyString(chname)); |
348 |
adx |
30 |
|
349 |
michael |
1654 |
chptr = mp_pool_get(channel_pool); |
350 |
adx |
30 |
|
351 |
michael |
1654 |
memset(chptr, 0, sizeof(*chptr)); |
352 |
|
|
|
353 |
michael |
3308 |
/* Doesn't hurt to set it here */ |
354 |
michael |
632 |
chptr->channelts = CurrentTime; |
355 |
|
|
chptr->last_join_time = CurrentTime; |
356 |
adx |
30 |
|
357 |
|
|
strlcpy(chptr->chname, chname, sizeof(chptr->chname)); |
358 |
|
|
dlinkAdd(chptr, &chptr->node, &global_channel_list); |
359 |
|
|
|
360 |
|
|
hash_add_channel(chptr); |
361 |
|
|
|
362 |
|
|
return chptr; |
363 |
|
|
} |
364 |
|
|
|
365 |
michael |
3308 |
/*! \brief Walk through this channel, and destroy it. |
366 |
|
|
* \param chptr Channel pointer |
367 |
adx |
30 |
*/ |
368 |
|
|
void |
369 |
|
|
destroy_channel(struct Channel *chptr) |
370 |
|
|
{ |
371 |
|
|
dlink_node *ptr = NULL, *ptr_next = NULL; |
372 |
|
|
|
373 |
|
|
DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->invites.head) |
374 |
|
|
del_invite(chptr, ptr->data); |
375 |
|
|
|
376 |
michael |
3308 |
/* Free ban/exception/invex lists */ |
377 |
adx |
30 |
free_channel_list(&chptr->banlist); |
378 |
|
|
free_channel_list(&chptr->exceptlist); |
379 |
|
|
free_channel_list(&chptr->invexlist); |
380 |
|
|
|
381 |
|
|
dlinkDelete(&chptr->node, &global_channel_list); |
382 |
|
|
hash_del_channel(chptr); |
383 |
|
|
|
384 |
michael |
1654 |
mp_pool_release(chptr); |
385 |
adx |
30 |
} |
386 |
|
|
|
387 |
|
|
/*! |
388 |
michael |
3308 |
* \param chptr Pointer to channel |
389 |
|
|
* \return String pointer "=" if public, "@" if secret else "*" |
390 |
adx |
30 |
*/ |
391 |
|
|
static const char * |
392 |
michael |
1013 |
channel_pub_or_secret(const struct Channel *chptr) |
393 |
adx |
30 |
{ |
394 |
|
|
if (SecretChannel(chptr)) |
395 |
|
|
return "@"; |
396 |
|
|
if (PrivateChannel(chptr)) |
397 |
|
|
return "*"; |
398 |
|
|
return "="; |
399 |
|
|
} |
400 |
|
|
|
401 |
|
|
/*! \brief lists all names on given channel |
402 |
michael |
3308 |
* \param source_p Pointer to client struct requesting names |
403 |
|
|
* \param chptr Pointer to channel block |
404 |
|
|
* \param show_eon Show RPL_ENDOFNAMES numeric or not |
405 |
adx |
30 |
* (don't want it with /names with no params) |
406 |
|
|
*/ |
407 |
|
|
void |
408 |
|
|
channel_member_names(struct Client *source_p, struct Channel *chptr, |
409 |
|
|
int show_eon) |
410 |
|
|
{ |
411 |
michael |
1847 |
const dlink_node *ptr = NULL; |
412 |
michael |
3215 |
char lbuf[IRCD_BUFSIZE + 1] = ""; |
413 |
adx |
30 |
char *t = NULL, *start = NULL; |
414 |
|
|
int tlen = 0; |
415 |
|
|
int is_member = IsMember(source_p, chptr); |
416 |
michael |
1146 |
int multi_prefix = HasCap(source_p, CAP_MULTI_PREFIX) != 0; |
417 |
michael |
2910 |
int uhnames = HasCap(source_p, CAP_UHNAMES) != 0; |
418 |
adx |
30 |
|
419 |
|
|
if (PubChannel(chptr) || is_member) |
420 |
|
|
{ |
421 |
michael |
3109 |
t = lbuf + snprintf(lbuf, sizeof(lbuf), numeric_form(RPL_NAMREPLY), |
422 |
michael |
1847 |
me.name, source_p->name, |
423 |
|
|
channel_pub_or_secret(chptr), chptr->chname); |
424 |
adx |
30 |
start = t; |
425 |
|
|
|
426 |
|
|
DLINK_FOREACH(ptr, chptr->members.head) |
427 |
|
|
{ |
428 |
michael |
1847 |
const struct Membership *ms = ptr->data; |
429 |
adx |
30 |
|
430 |
michael |
1847 |
if (HasUMode(ms->client_p, UMODE_INVISIBLE) && !is_member) |
431 |
adx |
30 |
continue; |
432 |
|
|
|
433 |
michael |
2910 |
if (!uhnames) |
434 |
|
|
tlen = strlen(ms->client_p->name) + 1; /* nick + space */ |
435 |
|
|
else |
436 |
|
|
tlen = strlen(ms->client_p->name) + strlen(ms->client_p->username) + |
437 |
|
|
strlen(ms->client_p->host) + 3; |
438 |
adx |
30 |
|
439 |
michael |
506 |
if (!multi_prefix) |
440 |
|
|
{ |
441 |
|
|
if (ms->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE)) |
442 |
|
|
++tlen; |
443 |
|
|
} |
444 |
|
|
else |
445 |
|
|
{ |
446 |
|
|
if (ms->flags & CHFL_CHANOP) |
447 |
|
|
++tlen; |
448 |
|
|
if (ms->flags & CHFL_HALFOP) |
449 |
|
|
++tlen; |
450 |
|
|
if (ms->flags & CHFL_VOICE) |
451 |
|
|
++tlen; |
452 |
|
|
} |
453 |
|
|
|
454 |
adx |
675 |
if (t + tlen - lbuf > IRCD_BUFSIZE - 2) |
455 |
adx |
30 |
{ |
456 |
|
|
*(t - 1) = '\0'; |
457 |
|
|
sendto_one(source_p, "%s", lbuf); |
458 |
|
|
t = start; |
459 |
|
|
} |
460 |
|
|
|
461 |
michael |
2910 |
if (!uhnames) |
462 |
|
|
t += sprintf(t, "%s%s ", get_member_status(ms, multi_prefix), |
463 |
|
|
ms->client_p->name); |
464 |
|
|
else |
465 |
|
|
t += sprintf(t, "%s%s!%s@%s ", get_member_status(ms, multi_prefix), |
466 |
|
|
ms->client_p->name, ms->client_p->username, |
467 |
|
|
ms->client_p->host); |
468 |
adx |
30 |
} |
469 |
|
|
|
470 |
michael |
3215 |
if (tlen) |
471 |
adx |
30 |
{ |
472 |
|
|
*(t - 1) = '\0'; |
473 |
|
|
sendto_one(source_p, "%s", lbuf); |
474 |
|
|
} |
475 |
|
|
} |
476 |
|
|
|
477 |
|
|
if (show_eon) |
478 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_ENDOFNAMES, chptr->chname); |
479 |
adx |
30 |
} |
480 |
|
|
|
481 |
michael |
3308 |
/*! \brief Adds client to invite list |
482 |
|
|
* \param chptr Pointer to channel block |
483 |
|
|
* \param who Pointer to client to add invite to |
484 |
adx |
30 |
*/ |
485 |
|
|
void |
486 |
|
|
add_invite(struct Channel *chptr, struct Client *who) |
487 |
|
|
{ |
488 |
|
|
del_invite(chptr, who); |
489 |
|
|
|
490 |
|
|
/* |
491 |
michael |
3308 |
* Delete last link in chain if the list is max length |
492 |
adx |
30 |
*/ |
493 |
michael |
317 |
if (dlink_list_length(&who->localClient->invited) >= |
494 |
adx |
30 |
ConfigChannel.max_chans_per_user) |
495 |
michael |
317 |
del_invite(who->localClient->invited.tail->data, who); |
496 |
adx |
30 |
|
497 |
michael |
3308 |
/* Add client to channel invite list */ |
498 |
adx |
30 |
dlinkAdd(who, make_dlink_node(), &chptr->invites); |
499 |
|
|
|
500 |
michael |
3308 |
/* Add channel to the end of the client invite list */ |
501 |
michael |
317 |
dlinkAdd(chptr, make_dlink_node(), &who->localClient->invited); |
502 |
adx |
30 |
} |
503 |
|
|
|
504 |
|
|
/*! \brief Delete Invite block from channel invite list |
505 |
|
|
* and client invite list |
506 |
michael |
3308 |
* \param chptr Pointer to Channel struct |
507 |
|
|
* \param who Pointer to client to remove invites from |
508 |
adx |
30 |
*/ |
509 |
|
|
void |
510 |
|
|
del_invite(struct Channel *chptr, struct Client *who) |
511 |
|
|
{ |
512 |
|
|
dlink_node *ptr = NULL; |
513 |
|
|
|
514 |
michael |
317 |
if ((ptr = dlinkFindDelete(&who->localClient->invited, chptr))) |
515 |
adx |
30 |
free_dlink_node(ptr); |
516 |
|
|
|
517 |
|
|
if ((ptr = dlinkFindDelete(&chptr->invites, who))) |
518 |
|
|
free_dlink_node(ptr); |
519 |
|
|
} |
520 |
|
|
|
521 |
|
|
/* get_member_status() |
522 |
|
|
* |
523 |
|
|
* inputs - pointer to struct Membership |
524 |
|
|
* - YES if we can combine different flags |
525 |
|
|
* output - string either @, +, % or "" depending on whether |
526 |
|
|
* chanop, voiced or user |
527 |
|
|
* side effects - |
528 |
|
|
* |
529 |
|
|
* NOTE: Returned string is usually a static buffer |
530 |
|
|
* (like in get_client_name) |
531 |
|
|
*/ |
532 |
|
|
const char * |
533 |
michael |
2133 |
get_member_status(const struct Membership *ms, const int combine) |
534 |
adx |
30 |
{ |
535 |
|
|
static char buffer[4]; |
536 |
michael |
1902 |
char *p = buffer; |
537 |
adx |
30 |
|
538 |
|
|
if (ms->flags & CHFL_CHANOP) |
539 |
|
|
{ |
540 |
|
|
if (!combine) |
541 |
|
|
return "@"; |
542 |
|
|
*p++ = '@'; |
543 |
|
|
} |
544 |
|
|
|
545 |
|
|
#ifdef HALFOPS |
546 |
|
|
if (ms->flags & CHFL_HALFOP) |
547 |
|
|
{ |
548 |
|
|
if (!combine) |
549 |
|
|
return "%"; |
550 |
|
|
*p++ = '%'; |
551 |
|
|
} |
552 |
|
|
#endif |
553 |
|
|
|
554 |
|
|
if (ms->flags & CHFL_VOICE) |
555 |
|
|
*p++ = '+'; |
556 |
|
|
*p = '\0'; |
557 |
|
|
|
558 |
|
|
return buffer; |
559 |
|
|
} |
560 |
|
|
|
561 |
|
|
/*! |
562 |
michael |
3308 |
* \param who Pointer to Client to check |
563 |
|
|
* \param list Pointer to ban list to search |
564 |
adx |
30 |
* \return 1 if ban found for given n!u\@h mask, 0 otherwise |
565 |
|
|
* |
566 |
|
|
*/ |
567 |
|
|
static int |
568 |
|
|
find_bmask(const struct Client *who, const dlink_list *const list) |
569 |
|
|
{ |
570 |
|
|
const dlink_node *ptr = NULL; |
571 |
|
|
|
572 |
|
|
DLINK_FOREACH(ptr, list->head) |
573 |
|
|
{ |
574 |
michael |
1455 |
const struct Ban *bp = ptr->data; |
575 |
adx |
30 |
|
576 |
michael |
2296 |
if (!match(bp->name, who->name) && !match(bp->user, who->username)) |
577 |
michael |
371 |
{ |
578 |
|
|
switch (bp->type) |
579 |
|
|
{ |
580 |
|
|
case HM_HOST: |
581 |
michael |
1652 |
if (!match(bp->host, who->host) || !match(bp->host, who->sockhost)) |
582 |
michael |
371 |
return 1; |
583 |
|
|
break; |
584 |
|
|
case HM_IPV4: |
585 |
|
|
if (who->localClient->aftype == AF_INET) |
586 |
|
|
if (match_ipv4(&who->localClient->ip, &bp->addr, bp->bits)) |
587 |
|
|
return 1; |
588 |
|
|
break; |
589 |
|
|
#ifdef IPV6 |
590 |
|
|
case HM_IPV6: |
591 |
|
|
if (who->localClient->aftype == AF_INET6) |
592 |
|
|
if (match_ipv6(&who->localClient->ip, &bp->addr, bp->bits)) |
593 |
|
|
return 1; |
594 |
|
|
break; |
595 |
|
|
#endif |
596 |
|
|
default: |
597 |
|
|
assert(0); |
598 |
|
|
} |
599 |
|
|
} |
600 |
adx |
30 |
} |
601 |
|
|
|
602 |
|
|
return 0; |
603 |
|
|
} |
604 |
|
|
|
605 |
|
|
/*! |
606 |
michael |
3308 |
* \param chptr Pointer to channel block |
607 |
|
|
* \param who Pointer to client to check access fo |
608 |
adx |
30 |
* \return 0 if not banned, 1 otherwise |
609 |
|
|
*/ |
610 |
|
|
int |
611 |
michael |
1013 |
is_banned(const struct Channel *chptr, const struct Client *who) |
612 |
adx |
30 |
{ |
613 |
michael |
632 |
if (find_bmask(who, &chptr->banlist)) |
614 |
michael |
1495 |
if (!find_bmask(who, &chptr->exceptlist)) |
615 |
michael |
632 |
return 1; |
616 |
adx |
30 |
|
617 |
michael |
632 |
return 0; |
618 |
adx |
30 |
} |
619 |
|
|
|
620 |
michael |
3308 |
/*! Tests if a client can join a certain channel |
621 |
|
|
* \param source_p Pointer to client attempting to join |
622 |
|
|
* \param chptr Pointer to channel |
623 |
|
|
* \param key Key sent by client attempting to join if present |
624 |
adx |
30 |
* \return ERR_BANNEDFROMCHAN, ERR_INVITEONLYCHAN, ERR_CHANNELISFULL |
625 |
|
|
* or 0 if allowed to join. |
626 |
|
|
*/ |
627 |
michael |
1834 |
int |
628 |
adx |
30 |
can_join(struct Client *source_p, struct Channel *chptr, const char *key) |
629 |
|
|
{ |
630 |
michael |
2246 |
if ((chptr->mode.mode & MODE_SSLONLY) && !HasUMode(source_p, UMODE_SSL)) |
631 |
michael |
1150 |
return ERR_SSLONLYCHAN; |
632 |
|
|
|
633 |
michael |
1173 |
if ((chptr->mode.mode & MODE_REGONLY) && !HasUMode(source_p, UMODE_REGISTERED)) |
634 |
|
|
return ERR_NEEDREGGEDNICK; |
635 |
|
|
|
636 |
michael |
1219 |
if ((chptr->mode.mode & MODE_OPERONLY) && !HasUMode(source_p, UMODE_OPER)) |
637 |
michael |
1150 |
return ERR_OPERONLYCHAN; |
638 |
|
|
|
639 |
adx |
30 |
if (chptr->mode.mode & MODE_INVITEONLY) |
640 |
michael |
317 |
if (!dlinkFind(&source_p->localClient->invited, chptr)) |
641 |
michael |
1495 |
if (!find_bmask(source_p, &chptr->invexlist)) |
642 |
adx |
30 |
return ERR_INVITEONLYCHAN; |
643 |
|
|
|
644 |
michael |
1430 |
if (chptr->mode.key[0] && (!key || strcmp(chptr->mode.key, key))) |
645 |
adx |
30 |
return ERR_BADCHANNELKEY; |
646 |
|
|
|
647 |
|
|
if (chptr->mode.limit && dlink_list_length(&chptr->members) >= |
648 |
|
|
chptr->mode.limit) |
649 |
|
|
return ERR_CHANNELISFULL; |
650 |
|
|
|
651 |
michael |
2208 |
if (is_banned(chptr, source_p)) |
652 |
|
|
return ERR_BANNEDFROMCHAN; |
653 |
|
|
|
654 |
michael |
1834 |
return 0; |
655 |
adx |
30 |
} |
656 |
|
|
|
657 |
|
|
int |
658 |
michael |
1847 |
has_member_flags(const struct Membership *ms, const unsigned int flags) |
659 |
adx |
30 |
{ |
660 |
michael |
3215 |
return ms && (ms->flags & flags); |
661 |
adx |
30 |
} |
662 |
|
|
|
663 |
|
|
struct Membership * |
664 |
|
|
find_channel_link(struct Client *client_p, struct Channel *chptr) |
665 |
|
|
{ |
666 |
|
|
dlink_node *ptr = NULL; |
667 |
|
|
|
668 |
|
|
if (!IsClient(client_p)) |
669 |
|
|
return NULL; |
670 |
|
|
|
671 |
michael |
2567 |
if (dlink_list_length(&chptr->members) < dlink_list_length(&client_p->channel)) |
672 |
|
|
{ |
673 |
|
|
DLINK_FOREACH(ptr, chptr->members.head) |
674 |
|
|
if (((struct Membership *)ptr->data)->client_p == client_p) |
675 |
|
|
return ptr->data; |
676 |
|
|
} |
677 |
|
|
else |
678 |
|
|
{ |
679 |
|
|
DLINK_FOREACH(ptr, client_p->channel.head) |
680 |
|
|
if (((struct Membership *)ptr->data)->chptr == chptr) |
681 |
|
|
return ptr->data; |
682 |
|
|
} |
683 |
adx |
30 |
|
684 |
|
|
return NULL; |
685 |
|
|
} |
686 |
|
|
|
687 |
michael |
1937 |
/* |
688 |
|
|
* Basically the same functionality as in bahamut |
689 |
|
|
*/ |
690 |
|
|
static int |
691 |
|
|
msg_has_ctrls(const char *message) |
692 |
|
|
{ |
693 |
|
|
const unsigned char *p = (const unsigned char *)message; |
694 |
|
|
|
695 |
|
|
for (; *p; ++p) |
696 |
|
|
{ |
697 |
|
|
if (*p > 31 || *p == 1) |
698 |
|
|
continue; |
699 |
|
|
|
700 |
|
|
if (*p == 27) |
701 |
|
|
{ |
702 |
|
|
if (*(p + 1) == '$' || |
703 |
|
|
*(p + 1) == '(') |
704 |
|
|
{ |
705 |
|
|
++p; |
706 |
|
|
continue; |
707 |
|
|
} |
708 |
|
|
} |
709 |
|
|
|
710 |
|
|
return 1; |
711 |
|
|
} |
712 |
|
|
|
713 |
|
|
return 0; |
714 |
|
|
} |
715 |
|
|
|
716 |
michael |
3308 |
/*! Tests if a client can send to a channel |
717 |
|
|
* \param chptr Pointer to Channel struct |
718 |
|
|
* \param source_p Pointer to Client struct |
719 |
|
|
* \param ms Pointer to Membership struct (can be NULL) |
720 |
|
|
* \param message The actual message string the client wants to send |
721 |
adx |
30 |
* \return CAN_SEND_OPV if op or voiced on channel\n |
722 |
|
|
* CAN_SEND_NONOP if can send to channel but is not an op\n |
723 |
michael |
1173 |
* ERR_CANNOTSENDTOCHAN or ERR_NEEDREGGEDNICK if they cannot send to channel\n |
724 |
adx |
30 |
*/ |
725 |
|
|
int |
726 |
michael |
1937 |
can_send(struct Channel *chptr, struct Client *source_p, |
727 |
|
|
struct Membership *ms, const char *message) |
728 |
adx |
30 |
{ |
729 |
michael |
1858 |
struct MaskItem *conf = NULL; |
730 |
|
|
|
731 |
michael |
1219 |
if (IsServer(source_p) || HasFlag(source_p, FLAGS_SERVICE)) |
732 |
adx |
30 |
return CAN_SEND_OPV; |
733 |
|
|
|
734 |
michael |
565 |
if (MyClient(source_p) && !IsExemptResv(source_p)) |
735 |
michael |
1219 |
if (!(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.oper_pass_resv)) |
736 |
michael |
1858 |
if ((conf = match_find_resv(chptr->chname)) && !resv_find_exempt(source_p, conf)) |
737 |
michael |
1834 |
return ERR_CANNOTSENDTOCHAN; |
738 |
adx |
30 |
|
739 |
michael |
1944 |
if ((chptr->mode.mode & MODE_NOCTRL) && msg_has_ctrls(message)) |
740 |
|
|
return ERR_NOCTRLSONCHAN; |
741 |
|
|
if (ms || (ms = find_channel_link(source_p, chptr))) |
742 |
adx |
30 |
if (ms->flags & (CHFL_CHANOP|CHFL_HALFOP|CHFL_VOICE)) |
743 |
|
|
return CAN_SEND_OPV; |
744 |
michael |
2441 |
if (!ms && (chptr->mode.mode & MODE_NOPRIVMSGS)) |
745 |
|
|
return ERR_CANNOTSENDTOCHAN; |
746 |
michael |
1944 |
if (chptr->mode.mode & MODE_MODERATED) |
747 |
|
|
return ERR_CANNOTSENDTOCHAN; |
748 |
michael |
1954 |
if ((chptr->mode.mode & MODE_MODREG) && !HasUMode(source_p, UMODE_REGISTERED)) |
749 |
michael |
1944 |
return ERR_NEEDREGGEDNICK; |
750 |
adx |
30 |
|
751 |
michael |
3308 |
/* Cache can send if banned */ |
752 |
michael |
1944 |
if (MyClient(source_p)) |
753 |
|
|
{ |
754 |
|
|
if (ms) |
755 |
adx |
30 |
{ |
756 |
|
|
if (ms->flags & CHFL_BAN_SILENCED) |
757 |
michael |
1834 |
return ERR_CANNOTSENDTOCHAN; |
758 |
adx |
30 |
|
759 |
|
|
if (!(ms->flags & CHFL_BAN_CHECKED)) |
760 |
|
|
{ |
761 |
|
|
if (is_banned(chptr, source_p)) |
762 |
|
|
{ |
763 |
|
|
ms->flags |= (CHFL_BAN_CHECKED|CHFL_BAN_SILENCED); |
764 |
michael |
1834 |
return ERR_CANNOTSENDTOCHAN; |
765 |
adx |
30 |
} |
766 |
|
|
|
767 |
|
|
ms->flags |= CHFL_BAN_CHECKED; |
768 |
|
|
} |
769 |
|
|
} |
770 |
michael |
1944 |
else if (is_banned(chptr, source_p)) |
771 |
michael |
1941 |
return ERR_CANNOTSENDTOCHAN; |
772 |
|
|
} |
773 |
adx |
30 |
|
774 |
|
|
return CAN_SEND_NONOP; |
775 |
|
|
} |
776 |
|
|
|
777 |
|
|
/*! \brief Updates the client's oper_warn_count_down, warns the |
778 |
|
|
* IRC operators if necessary, and updates |
779 |
|
|
* join_leave_countdown as needed. |
780 |
michael |
3308 |
* \param source_p Pointer to struct Client to check |
781 |
|
|
* \param name Channel name or NULL if this is a part. |
782 |
adx |
30 |
*/ |
783 |
|
|
void |
784 |
|
|
check_spambot_warning(struct Client *source_p, const char *name) |
785 |
|
|
{ |
786 |
|
|
int t_delta = 0; |
787 |
|
|
int decrement_count = 0; |
788 |
|
|
|
789 |
|
|
if ((GlobalSetOptions.spam_num && |
790 |
|
|
(source_p->localClient->join_leave_count >= |
791 |
|
|
GlobalSetOptions.spam_num))) |
792 |
|
|
{ |
793 |
|
|
if (source_p->localClient->oper_warn_count_down > 0) |
794 |
|
|
source_p->localClient->oper_warn_count_down--; |
795 |
|
|
else |
796 |
|
|
source_p->localClient->oper_warn_count_down = 0; |
797 |
|
|
|
798 |
|
|
if (source_p->localClient->oper_warn_count_down == 0) |
799 |
|
|
{ |
800 |
michael |
3308 |
/* It's already known as a possible spambot */ |
801 |
michael |
3235 |
if (name) |
802 |
michael |
1618 |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
803 |
adx |
30 |
"User %s (%s@%s) trying to join %s is a possible spambot", |
804 |
|
|
source_p->name, source_p->username, |
805 |
|
|
source_p->host, name); |
806 |
|
|
else |
807 |
michael |
1618 |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
808 |
adx |
30 |
"User %s (%s@%s) is a possible spambot", |
809 |
|
|
source_p->name, source_p->username, |
810 |
|
|
source_p->host); |
811 |
|
|
source_p->localClient->oper_warn_count_down = OPER_SPAM_COUNTDOWN; |
812 |
|
|
} |
813 |
|
|
} |
814 |
|
|
else |
815 |
|
|
{ |
816 |
|
|
if ((t_delta = (CurrentTime - source_p->localClient->last_leave_time)) > |
817 |
|
|
JOIN_LEAVE_COUNT_EXPIRE_TIME) |
818 |
|
|
{ |
819 |
|
|
decrement_count = (t_delta / JOIN_LEAVE_COUNT_EXPIRE_TIME); |
820 |
|
|
if (decrement_count > source_p->localClient->join_leave_count) |
821 |
|
|
source_p->localClient->join_leave_count = 0; |
822 |
|
|
else |
823 |
|
|
source_p->localClient->join_leave_count -= decrement_count; |
824 |
|
|
} |
825 |
|
|
else |
826 |
|
|
{ |
827 |
|
|
if ((CurrentTime - (source_p->localClient->last_join_time)) < |
828 |
|
|
GlobalSetOptions.spam_time) |
829 |
michael |
3308 |
source_p->localClient->join_leave_count++; /* It's a possible spambot */ |
830 |
adx |
30 |
} |
831 |
|
|
|
832 |
michael |
3215 |
if (name) |
833 |
adx |
30 |
source_p->localClient->last_join_time = CurrentTime; |
834 |
|
|
else |
835 |
|
|
source_p->localClient->last_leave_time = CurrentTime; |
836 |
|
|
} |
837 |
|
|
} |
838 |
|
|
|
839 |
michael |
3308 |
/*! \brief Compares usercount and servercount against their split |
840 |
adx |
30 |
* values and adjusts splitmode accordingly |
841 |
|
|
* \param unused Unused address pointer |
842 |
|
|
*/ |
843 |
|
|
void |
844 |
|
|
check_splitmode(void *unused) |
845 |
|
|
{ |
846 |
|
|
if (splitchecking && (ConfigChannel.no_join_on_split || |
847 |
|
|
ConfigChannel.no_create_on_split)) |
848 |
|
|
{ |
849 |
|
|
const unsigned int server = dlink_list_length(&global_serv_list); |
850 |
|
|
|
851 |
|
|
if (!splitmode && ((server < split_servers) || (Count.total < split_users))) |
852 |
|
|
{ |
853 |
|
|
splitmode = 1; |
854 |
|
|
|
855 |
michael |
1618 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
856 |
adx |
30 |
"Network split, activating splitmode"); |
857 |
|
|
eventAddIsh("check_splitmode", check_splitmode, NULL, 10); |
858 |
|
|
} |
859 |
|
|
else if (splitmode && (server > split_servers) && (Count.total > split_users)) |
860 |
|
|
{ |
861 |
|
|
splitmode = 0; |
862 |
|
|
|
863 |
michael |
1618 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
864 |
adx |
30 |
"Network rejoined, deactivating splitmode"); |
865 |
|
|
eventDelete(check_splitmode, NULL); |
866 |
|
|
} |
867 |
|
|
} |
868 |
|
|
} |
869 |
|
|
|
870 |
michael |
3308 |
/*! \brief Sets the channel topic for a certain channel |
871 |
adx |
30 |
* \param chptr Pointer to struct Channel |
872 |
|
|
* \param topic The topic string |
873 |
|
|
* \param topic_info n!u\@h formatted string of the topic setter |
874 |
michael |
3308 |
* \param topicts Timestamp on the topic |
875 |
|
|
* \param local Whether the topic is set by a local client |
876 |
adx |
30 |
*/ |
877 |
|
|
void |
878 |
|
|
set_channel_topic(struct Channel *chptr, const char *topic, |
879 |
michael |
1751 |
const char *topic_info, time_t topicts, int local) |
880 |
adx |
30 |
{ |
881 |
michael |
1751 |
if (local) |
882 |
|
|
strlcpy(chptr->topic, topic, IRCD_MIN(sizeof(chptr->topic), ServerInfo.max_topic_length + 1)); |
883 |
|
|
else |
884 |
|
|
strlcpy(chptr->topic, topic, sizeof(chptr->topic)); |
885 |
|
|
|
886 |
michael |
1203 |
strlcpy(chptr->topic_info, topic_info, sizeof(chptr->topic_info)); |
887 |
michael |
2345 |
chptr->topic_time = topicts; |
888 |
adx |
30 |
} |