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