1 |
|
/* |
2 |
< |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
2 |
> |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
|
* |
4 |
< |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
4 |
> |
* Copyright (c) 1997-2014 ircd-hybrid development team |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
25 |
|
*/ |
26 |
|
|
27 |
|
#include "stdinc.h" |
28 |
< |
#include "tools.h" |
28 |
> |
#include "list.h" |
29 |
|
#include "channel.h" |
30 |
|
#include "channel_mode.h" |
31 |
|
#include "client.h" |
32 |
– |
#include "common.h" |
32 |
|
#include "hash.h" |
33 |
+ |
#include "conf.h" |
34 |
|
#include "hostmask.h" |
35 |
|
#include "irc_string.h" |
36 |
– |
#include "sprintf_irc.h" |
36 |
|
#include "ircd.h" |
38 |
– |
#include "list.h" |
37 |
|
#include "numeric.h" |
38 |
< |
#include "s_serv.h" /* captab */ |
41 |
< |
#include "s_user.h" |
38 |
> |
#include "s_serv.h" |
39 |
|
#include "send.h" |
43 |
– |
#include "s_conf.h" /* ConfigFileEntry, ConfigChannel */ |
40 |
|
#include "event.h" |
41 |
|
#include "memory.h" |
42 |
< |
#include "balloc.h" |
42 |
> |
#include "mempool.h" |
43 |
> |
#include "s_misc.h" |
44 |
> |
#include "resv.h" |
45 |
|
|
48 |
– |
struct config_channel_entry ConfigChannel; |
46 |
|
dlink_list global_channel_list = { NULL, NULL, 0 }; |
47 |
< |
dlink_list lazylink_channels = { NULL, NULL, 0 }; |
51 |
< |
BlockHeap *ban_heap; /*! \todo ban_heap shouldn't be a global var */ |
47 |
> |
mp_pool_t *ban_pool; /*! \todo ban_pool shouldn't be a global var */ |
48 |
|
|
49 |
< |
static BlockHeap *topic_heap = NULL; |
50 |
< |
static BlockHeap *member_heap = NULL; |
55 |
< |
static BlockHeap *channel_heap = NULL; |
49 |
> |
static mp_pool_t *member_pool = NULL; |
50 |
> |
static mp_pool_t *channel_pool = NULL; |
51 |
|
|
52 |
|
static char buf[IRCD_BUFSIZE]; |
58 |
– |
static char modebuf[MODEBUFLEN]; |
59 |
– |
static char parabuf[MODEBUFLEN]; |
53 |
|
|
54 |
|
|
55 |
|
/*! \brief Initializes the channel blockheap, adds known channel CAPAB |
56 |
|
*/ |
57 |
|
void |
58 |
< |
init_channels(void) |
58 |
> |
channel_init(void) |
59 |
|
{ |
67 |
– |
/* |
68 |
– |
* XXX - These should get moved to somwhere else once we have |
69 |
– |
* a modular channelmode system |
70 |
– |
*/ |
60 |
|
add_capability("EX", CAP_EX, 1); |
61 |
|
add_capability("IE", CAP_IE, 1); |
73 |
– |
add_capability("CHW", CAP_CHW, 1); |
62 |
|
|
63 |
< |
channel_heap = BlockHeapCreate("channel", sizeof(struct Channel), CHANNEL_HEAP_SIZE); |
64 |
< |
ban_heap = BlockHeapCreate("ban", sizeof(struct Ban), BAN_HEAP_SIZE); |
65 |
< |
topic_heap = BlockHeapCreate("topic", TOPICLEN+1 + USERHOST_REPLYLEN, TOPIC_HEAP_SIZE); |
78 |
< |
member_heap = BlockHeapCreate("member", sizeof(struct Membership), CHANNEL_HEAP_SIZE*2); |
63 |
> |
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 |
|
} |
67 |
|
|
68 |
|
/*! \brief adds a user to a channel by adding another link to the |
99 |
|
if (!IsSetJoinFloodNoticed(chptr)) |
100 |
|
{ |
101 |
|
SetJoinFloodNoticed(chptr); |
102 |
< |
sendto_realops_flags(UMODE_BOTS, L_ALL, |
102 |
> |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
103 |
|
"Possible Join Flooder %s on %s target: %s", |
104 |
|
get_client_name(who, HIDE_IP), |
105 |
|
who->servptr->name, chptr->chname); |
109 |
|
chptr->last_join_time = CurrentTime; |
110 |
|
} |
111 |
|
|
112 |
< |
ms = BlockHeapAlloc(member_heap); |
112 |
> |
ms = mp_pool_get(member_pool); |
113 |
> |
memset(ms, 0, sizeof(*ms)); |
114 |
> |
|
115 |
|
ms->client_p = who; |
116 |
|
ms->chptr = chptr; |
117 |
|
ms->flags = flags; |
118 |
|
|
119 |
|
dlinkAdd(ms, &ms->channode, &chptr->members); |
131 |
– |
|
132 |
– |
if (MyConnect(who)) |
133 |
– |
dlinkAdd(ms, &ms->locchannode, &chptr->locmembers); |
134 |
– |
|
120 |
|
dlinkAdd(ms, &ms->usernode, &who->channel); |
121 |
|
} |
122 |
|
|
131 |
|
struct Channel *chptr = member->chptr; |
132 |
|
|
133 |
|
dlinkDelete(&member->channode, &chptr->members); |
149 |
– |
|
150 |
– |
if (MyConnect(client_p)) |
151 |
– |
dlinkDelete(&member->locchannode, &chptr->locmembers); |
152 |
– |
|
134 |
|
dlinkDelete(&member->usernode, &client_p->channel); |
135 |
|
|
136 |
< |
BlockHeapFree(member_heap, member); |
136 |
> |
mp_pool_release(member); |
137 |
|
|
138 |
< |
if (dlink_list_length(&chptr->members) == 0) |
158 |
< |
{ |
159 |
< |
assert(dlink_list_length(&chptr->locmembers) == 0); |
138 |
> |
if (chptr->members.head == NULL) |
139 |
|
destroy_channel(chptr); |
161 |
– |
} |
140 |
|
} |
141 |
|
|
142 |
|
/* send_members() |
147 |
|
*/ |
148 |
|
static void |
149 |
|
send_members(struct Client *client_p, struct Channel *chptr, |
150 |
< |
char *lmodebuf, char *lparabuf) |
150 |
> |
char *modebuf, char *parabuf) |
151 |
|
{ |
152 |
< |
struct Membership *ms; |
175 |
< |
dlink_node *ptr; |
152 |
> |
const dlink_node *ptr = NULL; |
153 |
|
int tlen; /* length of text to append */ |
154 |
|
char *t, *start; /* temp char pointer */ |
155 |
|
|
156 |
< |
start = t = buf + ircsprintf(buf, ":%s SJOIN %lu %s %s %s:", |
157 |
< |
ID_or_name(&me, client_p), |
158 |
< |
(unsigned long)chptr->channelts, |
182 |
< |
chptr->chname, lmodebuf, lparabuf); |
156 |
> |
start = t = buf + snprintf(buf, sizeof(buf), ":%s SJOIN %lu %s %s %s:", |
157 |
> |
me.id, (unsigned long)chptr->channelts, |
158 |
> |
chptr->chname, modebuf, parabuf); |
159 |
|
|
160 |
|
DLINK_FOREACH(ptr, chptr->members.head) |
161 |
|
{ |
162 |
< |
ms = ptr->data; |
162 |
> |
const struct Membership *ms = ptr->data; |
163 |
|
|
164 |
< |
tlen = strlen(IsCapable(client_p, CAP_TS6) ? |
189 |
< |
ID(ms->client_p) : ms->client_p->name) + 1; /* nick + space */ |
164 |
> |
tlen = strlen(ms->client_p->id) + 1; /* nick + space */ |
165 |
|
|
166 |
|
if (ms->flags & CHFL_CHANOP) |
167 |
|
tlen++; |
168 |
|
#ifdef HALFOPS |
169 |
< |
else if (ms->flags & CHFL_HALFOP) |
169 |
> |
if (ms->flags & CHFL_HALFOP) |
170 |
|
tlen++; |
171 |
|
#endif |
172 |
|
if (ms->flags & CHFL_VOICE) |
175 |
|
/* space will be converted into CR, but we also need space for LF.. |
176 |
|
* That's why we use '- 1' here |
177 |
|
* -adx */ |
178 |
< |
if (t + tlen - buf > sizeof(buf) - 1) |
178 |
> |
if (t + tlen - buf > IRCD_BUFSIZE - 1) |
179 |
|
{ |
180 |
|
*(t - 1) = '\0'; /* kill the space and terminate the string */ |
181 |
|
sendto_one(client_p, "%s", buf); |
182 |
|
t = start; |
183 |
|
} |
184 |
|
|
185 |
< |
if ((ms->flags & (CHFL_CHANOP | CHFL_HALFOP))) |
186 |
< |
*t++ = (!(ms->flags & CHFL_CHANOP) && IsCapable(client_p, CAP_HOPS)) ? |
187 |
< |
'%' : '@'; |
188 |
< |
if ((ms->flags & CHFL_VOICE)) |
185 |
> |
if (ms->flags & CHFL_CHANOP) |
186 |
> |
*t++ = '@'; |
187 |
> |
if (ms->flags & CHFL_HALFOP) |
188 |
> |
*t++ = '%'; |
189 |
> |
if (ms->flags & CHFL_VOICE) |
190 |
|
*t++ = '+'; |
191 |
|
|
192 |
< |
if (IsCapable(client_p, CAP_TS6)) |
193 |
< |
strcpy(t, ID(ms->client_p)); |
218 |
< |
else |
219 |
< |
strcpy(t, ms->client_p->name); |
192 |
> |
strcpy(t, ms->client_p->id); |
193 |
> |
|
194 |
|
t += strlen(t); |
195 |
|
*t++ = ' '; |
196 |
|
} |
210 |
|
*/ |
211 |
|
static void |
212 |
|
send_mode_list(struct Client *client_p, struct Channel *chptr, |
213 |
< |
dlink_list *top, char flag) |
213 |
> |
const dlink_list *top, char flag) |
214 |
|
{ |
215 |
< |
int ts5 = !IsCapable(client_p, CAP_TS6); |
216 |
< |
dlink_node *lp; |
243 |
< |
struct Ban *banptr; |
244 |
< |
char pbuf[IRCD_BUFSIZE]; |
215 |
> |
const dlink_node *lp = NULL; |
216 |
> |
char pbuf[IRCD_BUFSIZE] = ""; |
217 |
|
int tlen, mlen, cur_len, count = 0; |
218 |
< |
char *mp = NULL, *pp = pbuf; |
218 |
> |
char *pp = pbuf; |
219 |
|
|
220 |
< |
if (top == NULL || top->length == 0) |
220 |
> |
if (top->length == 0) |
221 |
|
return; |
222 |
|
|
223 |
< |
if (ts5) |
224 |
< |
mlen = ircsprintf(buf, ":%s MODE %s +", me.name, chptr->chname); |
225 |
< |
else |
254 |
< |
mlen = ircsprintf(buf, ":%s BMASK %lu %s %c :", me.id, |
255 |
< |
(unsigned long)chptr->channelts, chptr->chname, flag); |
256 |
< |
|
257 |
< |
/* MODE needs additional one byte for space between buf and pbuf */ |
258 |
< |
cur_len = mlen + ts5; |
259 |
< |
mp = buf + mlen; |
223 |
> |
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 |
|
|
227 |
|
DLINK_FOREACH(lp, top->head) |
228 |
|
{ |
229 |
< |
banptr = lp->data; |
229 |
> |
const struct Ban *banptr = lp->data; |
230 |
|
|
231 |
< |
/* must add another b/e/I letter if we use MODE */ |
266 |
< |
tlen = banptr->len + 3 + ts5; |
231 |
> |
tlen = banptr->len + 3; |
232 |
|
|
233 |
|
/* |
234 |
|
* send buffer and start over if we cannot fit another ban, |
235 |
|
* or if the target is non-ts6 and we have too many modes in |
236 |
|
* in this line. |
237 |
|
*/ |
238 |
< |
if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2 || |
274 |
< |
(!IsCapable(client_p, CAP_TS6) && |
275 |
< |
(count >= MAXMODEPARAMS || pp - pbuf >= MODEBUFLEN))) |
238 |
> |
if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2) |
239 |
|
{ |
240 |
|
*(pp - 1) = '\0'; /* get rid of trailing space on buffer */ |
241 |
< |
sendto_one(client_p, "%s%s%s", buf, ts5 ? " " : "", pbuf); |
241 |
> |
sendto_one(client_p, "%s%s", buf, pbuf); |
242 |
|
|
243 |
< |
cur_len = mlen + ts5; |
281 |
< |
mp = buf + mlen; |
243 |
> |
cur_len = mlen; |
244 |
|
pp = pbuf; |
245 |
|
count = 0; |
246 |
|
} |
247 |
|
|
248 |
|
count++; |
249 |
< |
if (ts5) |
250 |
< |
{ |
289 |
< |
*mp++ = flag; |
290 |
< |
*mp = '\0'; |
291 |
< |
} |
292 |
< |
|
293 |
< |
pp += ircsprintf(pp, "%s!%s@%s ", banptr->name, banptr->username, |
294 |
< |
banptr->host); |
249 |
> |
pp += sprintf(pp, "%s!%s@%s ", banptr->name, banptr->user, |
250 |
> |
banptr->host); |
251 |
|
cur_len += tlen; |
252 |
|
} |
253 |
|
|
254 |
|
*(pp - 1) = '\0'; /* get rid of trailing space on buffer */ |
255 |
< |
sendto_one(client_p, "%s%s%s", buf, ts5 ? " " : "", pbuf); |
255 |
> |
sendto_one(client_p, "%s%s", buf, pbuf); |
256 |
|
} |
257 |
|
|
258 |
|
/*! \brief send "client_p" a full list of the modes for channel chptr |
262 |
|
void |
263 |
|
send_channel_modes(struct Client *client_p, struct Channel *chptr) |
264 |
|
{ |
265 |
< |
if (chptr->chname[0] != '#') |
266 |
< |
return; |
265 |
> |
char modebuf[MODEBUFLEN] = ""; |
266 |
> |
char parabuf[MODEBUFLEN] = ""; |
267 |
|
|
312 |
– |
*modebuf = *parabuf = '\0'; |
268 |
|
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 |
< |
|
273 |
< |
if (IsCapable(client_p, CAP_EX)) |
319 |
< |
send_mode_list(client_p, chptr, &chptr->exceptlist, 'e'); |
320 |
< |
if (IsCapable(client_p, CAP_IE)) |
321 |
< |
send_mode_list(client_p, chptr, &chptr->invexlist, 'I'); |
272 |
> |
send_mode_list(client_p, chptr, &chptr->exceptlist, 'e'); |
273 |
> |
send_mode_list(client_p, chptr, &chptr->invexlist, 'I'); |
274 |
|
} |
275 |
|
|
276 |
|
/*! \brief check channel name for invalid characters |
277 |
|
* \param name pointer to channel name string |
278 |
< |
* \return TRUE (1) if name ok, FALSE (0) otherwise |
278 |
> |
* \param local indicates whether it's a local or remote creation |
279 |
> |
* \return 0 if invalid, 1 otherwise |
280 |
|
*/ |
281 |
|
int |
282 |
< |
check_channel_name(const char *name) |
282 |
> |
check_channel_name(const char *name, const int local) |
283 |
|
{ |
284 |
< |
const unsigned char *p = (const unsigned char *)name; |
284 |
> |
const char *p = name; |
285 |
> |
const int max_length = local ? LOCAL_CHANNELLEN : CHANNELLEN; |
286 |
|
assert(name != NULL); |
287 |
|
|
288 |
< |
for (; *p; ++p) |
289 |
< |
if (!IsChanChar(*p)) |
336 |
< |
return 0; |
288 |
> |
if (!IsChanPrefix(*p)) |
289 |
> |
return 0; |
290 |
|
|
291 |
< |
return 1; |
291 |
> |
if (!local || !ConfigChannel.disable_fake_channels) |
292 |
> |
{ |
293 |
> |
while (*++p) |
294 |
> |
if (!IsChanChar(*p)) |
295 |
> |
return 0; |
296 |
> |
} |
297 |
> |
else |
298 |
> |
{ |
299 |
> |
while (*++p) |
300 |
> |
if (!IsVisibleChanChar(*p)) |
301 |
> |
return 0; |
302 |
> |
} |
303 |
> |
|
304 |
> |
return p - name <= max_length; |
305 |
|
} |
306 |
|
|
307 |
|
void |
310 |
|
dlinkDelete(&bptr->node, list); |
311 |
|
|
312 |
|
MyFree(bptr->name); |
313 |
< |
MyFree(bptr->username); |
313 |
> |
MyFree(bptr->user); |
314 |
|
MyFree(bptr->host); |
315 |
|
MyFree(bptr->who); |
316 |
|
|
317 |
< |
BlockHeapFree(ban_heap, bptr); |
317 |
> |
mp_pool_release(bptr); |
318 |
|
} |
319 |
|
|
320 |
|
/* free_channel_list() |
336 |
|
|
337 |
|
/*! \brief Get Channel block for chname (and allocate a new channel |
338 |
|
* block, if it didn't exist before) |
339 |
< |
* \param client_p client pointer |
340 |
< |
* \param chname channel name |
375 |
< |
* \param isnew pointer to int flag whether channel was newly created or not |
376 |
< |
* \return channel block or NULL if illegal name |
339 |
> |
* \param chname channel name |
340 |
> |
* \return channel block |
341 |
|
*/ |
342 |
|
struct Channel * |
343 |
< |
get_or_create_channel(struct Client *client_p, const char *chname, int *isnew) |
343 |
> |
make_channel(const char *chname) |
344 |
|
{ |
345 |
|
struct Channel *chptr = NULL; |
382 |
– |
int len; |
383 |
– |
|
384 |
– |
if (EmptyString(chname)) |
385 |
– |
return NULL; |
386 |
– |
|
387 |
– |
if ((len = strlen(chname)) > CHANNELLEN) |
388 |
– |
{ |
389 |
– |
if (IsServer(client_p)) |
390 |
– |
sendto_realops_flags(UMODE_DEBUG, L_ALL, |
391 |
– |
"*** Long channel name from %s (%d > %d): %s", |
392 |
– |
client_p->name, len, CHANNELLEN, chname); |
393 |
– |
return NULL; |
394 |
– |
} |
346 |
|
|
347 |
< |
if ((chptr = hash_find_channel(chname)) != NULL) |
397 |
< |
{ |
398 |
< |
if (isnew != NULL) |
399 |
< |
*isnew = 0; |
347 |
> |
assert(!EmptyString(chname)); |
348 |
|
|
349 |
< |
return chptr; |
402 |
< |
} |
349 |
> |
chptr = mp_pool_get(channel_pool); |
350 |
|
|
351 |
< |
if (isnew != NULL) |
405 |
< |
*isnew = 1; |
351 |
> |
memset(chptr, 0, sizeof(*chptr)); |
352 |
|
|
407 |
– |
chptr = BlockHeapAlloc(channel_heap); |
353 |
|
/* doesn't hurt to set it here */ |
354 |
< |
chptr->channelts = chptr->last_join_time = CurrentTime; |
354 |
> |
chptr->channelts = CurrentTime; |
355 |
> |
chptr->last_join_time = CurrentTime; |
356 |
|
|
357 |
|
strlcpy(chptr->chname, chname, sizeof(chptr->chname)); |
358 |
|
dlinkAdd(chptr, &chptr->node, &global_channel_list); |
378 |
|
free_channel_list(&chptr->exceptlist); |
379 |
|
free_channel_list(&chptr->invexlist); |
380 |
|
|
435 |
– |
/* Free the topic */ |
436 |
– |
free_topic(chptr); |
437 |
– |
|
381 |
|
dlinkDelete(&chptr->node, &global_channel_list); |
382 |
|
hash_del_channel(chptr); |
383 |
|
|
384 |
< |
if (ServerInfo.hub) |
442 |
< |
if ((ptr = dlinkFindDelete(&lazylink_channels, chptr))) |
443 |
< |
free_dlink_node(ptr); |
444 |
< |
|
445 |
< |
BlockHeapFree(channel_heap, chptr); |
384 |
> |
mp_pool_release(chptr); |
385 |
|
} |
386 |
|
|
387 |
|
/*! |
389 |
|
* \return string pointer "=" if public, "@" if secret else "*" |
390 |
|
*/ |
391 |
|
static const char * |
392 |
< |
channel_pub_or_secret(struct Channel *chptr) |
392 |
> |
channel_pub_or_secret(const struct Channel *chptr) |
393 |
|
{ |
394 |
|
if (SecretChannel(chptr)) |
395 |
|
return "@"; |
408 |
|
channel_member_names(struct Client *source_p, struct Channel *chptr, |
409 |
|
int show_eon) |
410 |
|
{ |
411 |
< |
struct Client *target_p = NULL; |
412 |
< |
struct Membership *ms = NULL; |
474 |
< |
dlink_node *ptr = NULL; |
475 |
< |
char lbuf[IRCD_BUFSIZE + 1]; |
411 |
> |
const dlink_node *ptr = NULL; |
412 |
> |
char lbuf[IRCD_BUFSIZE + 1] = ""; |
413 |
|
char *t = NULL, *start = NULL; |
414 |
|
int tlen = 0; |
415 |
|
int is_member = IsMember(source_p, chptr); |
416 |
+ |
int multi_prefix = HasCap(source_p, CAP_MULTI_PREFIX) != 0; |
417 |
+ |
int uhnames = HasCap(source_p, CAP_UHNAMES) != 0; |
418 |
|
|
419 |
|
if (PubChannel(chptr) || is_member) |
420 |
|
{ |
421 |
< |
t = lbuf + ircsprintf(lbuf, form_str(RPL_NAMREPLY), |
422 |
< |
me.name, source_p->name, |
423 |
< |
channel_pub_or_secret(chptr), |
485 |
< |
chptr->chname); |
421 |
> |
t = lbuf + snprintf(lbuf, sizeof(lbuf), numeric_form(RPL_NAMREPLY), |
422 |
> |
me.name, source_p->name, |
423 |
> |
channel_pub_or_secret(chptr), chptr->chname); |
424 |
|
start = t; |
425 |
|
|
426 |
|
DLINK_FOREACH(ptr, chptr->members.head) |
427 |
|
{ |
428 |
< |
ms = ptr->data; |
491 |
< |
target_p = ms->client_p; |
428 |
> |
const struct Membership *ms = ptr->data; |
429 |
|
|
430 |
< |
if (IsInvisible(target_p) && !is_member) |
430 |
> |
if (HasUMode(ms->client_p, UMODE_INVISIBLE) && !is_member) |
431 |
|
continue; |
432 |
|
|
433 |
< |
tlen = strlen(target_p->name) + 1; /* nick + space */ |
433 |
> |
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 |
> |
|
439 |
> |
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 |
< |
if (ms->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE)) |
499 |
< |
++tlen; |
500 |
< |
if (t + tlen - lbuf > IRCD_BUFSIZE) |
454 |
> |
if (t + tlen - lbuf > IRCD_BUFSIZE - 2) |
455 |
|
{ |
456 |
|
*(t - 1) = '\0'; |
457 |
|
sendto_one(source_p, "%s", lbuf); |
458 |
|
t = start; |
459 |
|
} |
460 |
|
|
461 |
< |
t += ircsprintf(t, "%s%s ", get_member_status(ms, NO), |
462 |
< |
target_p->name); |
461 |
> |
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 |
|
} |
469 |
|
|
470 |
< |
if (tlen != 0) |
470 |
> |
if (tlen) |
471 |
|
{ |
472 |
|
*(t - 1) = '\0'; |
473 |
|
sendto_one(source_p, "%s", lbuf); |
475 |
|
} |
476 |
|
|
477 |
|
if (show_eon) |
478 |
< |
sendto_one(source_p, form_str(RPL_ENDOFNAMES), |
520 |
< |
me.name, source_p->name, chptr->chname); |
478 |
> |
sendto_one_numeric(source_p, &me, RPL_ENDOFNAMES, chptr->chname); |
479 |
|
} |
480 |
|
|
481 |
|
/*! \brief adds client to invite list |
530 |
|
* (like in get_client_name) |
531 |
|
*/ |
532 |
|
const char * |
533 |
< |
get_member_status(const struct Membership *ms, int combine) |
533 |
> |
get_member_status(const struct Membership *ms, const int combine) |
534 |
|
{ |
535 |
|
static char buffer[4]; |
536 |
< |
char *p = NULL; |
579 |
< |
|
580 |
< |
if (ms == NULL) |
581 |
< |
return ""; |
582 |
< |
p = buffer; |
536 |
> |
char *p = buffer; |
537 |
|
|
538 |
|
if (ms->flags & CHFL_CHANOP) |
539 |
|
{ |
571 |
|
|
572 |
|
DLINK_FOREACH(ptr, list->head) |
573 |
|
{ |
574 |
< |
struct Ban *bp = ptr->data; |
574 |
> |
const struct Ban *bp = ptr->data; |
575 |
|
|
576 |
< |
if (match(bp->name, who->name) && match(bp->username, who->username)) |
576 |
> |
if (!match(bp->name, who->name) && !match(bp->user, who->username)) |
577 |
|
{ |
578 |
|
switch (bp->type) |
579 |
|
{ |
580 |
|
case HM_HOST: |
581 |
< |
if (match(bp->host, who->host) || match(bp->host, who->sockhost)) |
581 |
> |
if (!match(bp->host, who->host) || !match(bp->host, who->sockhost)) |
582 |
|
return 1; |
583 |
|
break; |
584 |
|
case HM_IPV4: |
608 |
|
* \return 0 if not banned, 1 otherwise |
609 |
|
*/ |
610 |
|
int |
611 |
< |
is_banned(struct Channel *chptr, struct Client *who) |
611 |
> |
is_banned(const struct Channel *chptr, const struct Client *who) |
612 |
|
{ |
613 |
< |
assert(IsClient(who)); |
613 |
> |
if (find_bmask(who, &chptr->banlist)) |
614 |
> |
if (!find_bmask(who, &chptr->exceptlist)) |
615 |
> |
return 1; |
616 |
|
|
617 |
< |
return find_bmask(who, &chptr->banlist) && (!ConfigChannel.use_except || |
662 |
< |
!find_bmask(who, &chptr->exceptlist)); |
617 |
> |
return 0; |
618 |
|
} |
619 |
|
|
620 |
|
/*! |
621 |
|
* \param source_p pointer to client attempting to join |
622 |
< |
* \param chptr pointer to channel |
622 |
> |
* \param chptr pointer to channel |
623 |
|
* \param key key sent by client attempting to join if present |
624 |
|
* \return ERR_BANNEDFROMCHAN, ERR_INVITEONLYCHAN, ERR_CHANNELISFULL |
625 |
|
* or 0 if allowed to join. |
627 |
|
int |
628 |
|
can_join(struct Client *source_p, struct Channel *chptr, const char *key) |
629 |
|
{ |
630 |
< |
if (find_bmask(source_p, &chptr->banlist)) |
631 |
< |
if (!ConfigChannel.use_except || !find_bmask(source_p, &chptr->exceptlist)) |
632 |
< |
return ERR_BANNEDFROMCHAN; |
630 |
> |
if ((chptr->mode.mode & MODE_SSLONLY) && !HasUMode(source_p, UMODE_SSL)) |
631 |
> |
return ERR_SSLONLYCHAN; |
632 |
> |
|
633 |
> |
if ((chptr->mode.mode & MODE_REGONLY) && !HasUMode(source_p, UMODE_REGISTERED)) |
634 |
> |
return ERR_NEEDREGGEDNICK; |
635 |
> |
|
636 |
> |
if ((chptr->mode.mode & MODE_OPERONLY) && !HasUMode(source_p, UMODE_OPER)) |
637 |
> |
return ERR_OPERONLYCHAN; |
638 |
|
|
639 |
|
if (chptr->mode.mode & MODE_INVITEONLY) |
640 |
|
if (!dlinkFind(&source_p->localClient->invited, chptr)) |
641 |
< |
if (!ConfigChannel.use_invex || !find_bmask(source_p, &chptr->invexlist)) |
641 |
> |
if (!find_bmask(source_p, &chptr->invexlist)) |
642 |
|
return ERR_INVITEONLYCHAN; |
643 |
|
|
644 |
< |
if (chptr->mode.key[0] && (EmptyString(key) || irccmp(chptr->mode.key, key))) |
644 |
> |
if (chptr->mode.key[0] && (!key || strcmp(chptr->mode.key, key))) |
645 |
|
return ERR_BADCHANNELKEY; |
646 |
|
|
647 |
|
if (chptr->mode.limit && dlink_list_length(&chptr->members) >= |
648 |
|
chptr->mode.limit) |
649 |
|
return ERR_CHANNELISFULL; |
650 |
|
|
651 |
+ |
if (is_banned(chptr, source_p)) |
652 |
+ |
return ERR_BANNEDFROMCHAN; |
653 |
+ |
|
654 |
|
return 0; |
655 |
|
} |
656 |
|
|
657 |
|
int |
658 |
< |
has_member_flags(struct Membership *ms, unsigned int flags) |
658 |
> |
has_member_flags(const struct Membership *ms, const unsigned int flags) |
659 |
|
{ |
660 |
< |
if (ms != NULL) |
698 |
< |
return ms->flags & flags; |
699 |
< |
return 0; |
660 |
> |
return ms && (ms->flags & flags); |
661 |
|
} |
662 |
|
|
663 |
|
struct Membership * |
668 |
|
if (!IsClient(client_p)) |
669 |
|
return NULL; |
670 |
|
|
671 |
< |
DLINK_FOREACH(ptr, client_p->channel.head) |
672 |
< |
if (((struct Membership *)ptr->data)->chptr == chptr) |
673 |
< |
return (struct Membership *)ptr->data; |
671 |
> |
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 |
|
|
684 |
|
return NULL; |
685 |
|
} |
686 |
|
|
687 |
+ |
/* |
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 |
|
/*! |
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 |
|
* \return CAN_SEND_OPV if op or voiced on channel\n |
721 |
|
* CAN_SEND_NONOP if can send to channel but is not an op\n |
722 |
< |
* CAN_SEND_NO if they cannot send to channel\n |
722 |
> |
* ERR_CANNOTSENDTOCHAN or ERR_NEEDREGGEDNICK if they cannot send to channel\n |
723 |
|
*/ |
724 |
|
int |
725 |
< |
can_send(struct Channel *chptr, struct Client *source_p, struct Membership *ms) |
725 |
> |
can_send(struct Channel *chptr, struct Client *source_p, |
726 |
> |
struct Membership *ms, const char *message) |
727 |
|
{ |
728 |
< |
if (IsServer(source_p)) |
729 |
< |
return CAN_SEND_OPV; |
728 |
> |
struct MaskItem *conf = NULL; |
729 |
|
|
730 |
< |
if (MyClient(source_p) && !IsExemptResv(source_p) && |
731 |
< |
!(IsOper(source_p) && ConfigFileEntry.oper_pass_resv) && |
733 |
< |
(!hash_find_resv(chptr->chname) == ConfigChannel.restrict_channels)) |
734 |
< |
return CAN_SEND_NO; |
730 |
> |
if (IsServer(source_p) || HasFlag(source_p, FLAGS_SERVICE)) |
731 |
> |
return CAN_SEND_OPV; |
732 |
|
|
733 |
< |
if (ms != NULL || (ms = find_channel_link(source_p, chptr))) |
734 |
< |
{ |
733 |
> |
if (MyClient(source_p) && !IsExemptResv(source_p)) |
734 |
> |
if (!(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.oper_pass_resv)) |
735 |
> |
if ((conf = match_find_resv(chptr->chname)) && !resv_find_exempt(source_p, conf)) |
736 |
> |
return ERR_CANNOTSENDTOCHAN; |
737 |
> |
|
738 |
> |
if ((chptr->mode.mode & MODE_NOCTRL) && msg_has_ctrls(message)) |
739 |
> |
return ERR_NOCTRLSONCHAN; |
740 |
> |
if (ms || (ms = find_channel_link(source_p, chptr))) |
741 |
|
if (ms->flags & (CHFL_CHANOP|CHFL_HALFOP|CHFL_VOICE)) |
742 |
|
return CAN_SEND_OPV; |
743 |
+ |
if (!ms && (chptr->mode.mode & MODE_NOPRIVMSGS)) |
744 |
+ |
return ERR_CANNOTSENDTOCHAN; |
745 |
+ |
if (chptr->mode.mode & MODE_MODERATED) |
746 |
+ |
return ERR_CANNOTSENDTOCHAN; |
747 |
+ |
if ((chptr->mode.mode & MODE_MODREG) && !HasUMode(source_p, UMODE_REGISTERED)) |
748 |
+ |
return ERR_NEEDREGGEDNICK; |
749 |
|
|
750 |
< |
/* cache can send if quiet_on_ban and banned */ |
751 |
< |
if (ConfigChannel.quiet_on_ban && MyClient(source_p)) |
750 |
> |
/* cache can send if banned */ |
751 |
> |
if (MyClient(source_p)) |
752 |
> |
{ |
753 |
> |
if (ms) |
754 |
|
{ |
755 |
|
if (ms->flags & CHFL_BAN_SILENCED) |
756 |
< |
return CAN_SEND_NO; |
756 |
> |
return ERR_CANNOTSENDTOCHAN; |
757 |
|
|
758 |
|
if (!(ms->flags & CHFL_BAN_CHECKED)) |
759 |
|
{ |
760 |
|
if (is_banned(chptr, source_p)) |
761 |
|
{ |
762 |
|
ms->flags |= (CHFL_BAN_CHECKED|CHFL_BAN_SILENCED); |
763 |
< |
return CAN_SEND_NO; |
763 |
> |
return ERR_CANNOTSENDTOCHAN; |
764 |
|
} |
765 |
|
|
766 |
|
ms->flags |= CHFL_BAN_CHECKED; |
767 |
|
} |
768 |
|
} |
769 |
+ |
else if (is_banned(chptr, source_p)) |
770 |
+ |
return ERR_CANNOTSENDTOCHAN; |
771 |
|
} |
772 |
|
|
760 |
– |
if (chptr->mode.mode & (MODE_MODERATED|MODE_NOPRIVMSGS)) |
761 |
– |
return CAN_SEND_NO; |
762 |
– |
|
773 |
|
return CAN_SEND_NONOP; |
774 |
|
} |
775 |
|
|
798 |
|
{ |
799 |
|
/* Its already known as a possible spambot */ |
800 |
|
if (name != NULL) |
801 |
< |
sendto_realops_flags(UMODE_BOTS, L_ALL, |
801 |
> |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
802 |
|
"User %s (%s@%s) trying to join %s is a possible spambot", |
803 |
|
source_p->name, source_p->username, |
804 |
|
source_p->host, name); |
805 |
|
else |
806 |
< |
sendto_realops_flags(UMODE_BOTS, L_ALL, |
806 |
> |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
807 |
|
"User %s (%s@%s) is a possible spambot", |
808 |
|
source_p->name, source_p->username, |
809 |
|
source_p->host); |
831 |
|
} |
832 |
|
} |
833 |
|
|
834 |
< |
if (name != NULL) |
834 |
> |
if (name) |
835 |
|
source_p->localClient->last_join_time = CurrentTime; |
836 |
|
else |
837 |
|
source_p->localClient->last_leave_time = CurrentTime; |
854 |
|
{ |
855 |
|
splitmode = 1; |
856 |
|
|
857 |
< |
sendto_realops_flags(UMODE_ALL,L_ALL, |
857 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
858 |
|
"Network split, activating splitmode"); |
859 |
|
eventAddIsh("check_splitmode", check_splitmode, NULL, 10); |
860 |
|
} |
862 |
|
{ |
863 |
|
splitmode = 0; |
864 |
|
|
865 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
865 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
866 |
|
"Network rejoined, deactivating splitmode"); |
867 |
|
eventDelete(check_splitmode, NULL); |
868 |
|
} |
869 |
|
} |
870 |
|
} |
871 |
|
|
862 |
– |
/*! \brief Allocates a new topic |
863 |
– |
* \param chptr Channel to allocate a new topic for |
864 |
– |
*/ |
865 |
– |
static void |
866 |
– |
allocate_topic(struct Channel *chptr) |
867 |
– |
{ |
868 |
– |
void *ptr = NULL; |
869 |
– |
|
870 |
– |
if (chptr == NULL) |
871 |
– |
return; |
872 |
– |
|
873 |
– |
ptr = BlockHeapAlloc(topic_heap); |
874 |
– |
|
875 |
– |
/* Basically we allocate one large block for the topic and |
876 |
– |
* the topic info. We then split it up into two and shove it |
877 |
– |
* in the chptr |
878 |
– |
*/ |
879 |
– |
chptr->topic = ptr; |
880 |
– |
chptr->topic_info = (char *)ptr + TOPICLEN+1; |
881 |
– |
*chptr->topic = '\0'; |
882 |
– |
*chptr->topic_info = '\0'; |
883 |
– |
} |
884 |
– |
|
885 |
– |
void |
886 |
– |
free_topic(struct Channel *chptr) |
887 |
– |
{ |
888 |
– |
void *ptr = NULL; |
889 |
– |
assert(chptr); |
890 |
– |
if (chptr->topic == NULL) |
891 |
– |
return; |
892 |
– |
|
893 |
– |
/* |
894 |
– |
* If you change allocate_topic you MUST change this as well |
895 |
– |
*/ |
896 |
– |
ptr = chptr->topic; |
897 |
– |
BlockHeapFree(topic_heap, ptr); |
898 |
– |
chptr->topic = NULL; |
899 |
– |
chptr->topic_info = NULL; |
900 |
– |
} |
901 |
– |
|
872 |
|
/*! \brief Sets the channel topic for chptr |
873 |
|
* \param chptr Pointer to struct Channel |
874 |
|
* \param topic The topic string |
877 |
|
*/ |
878 |
|
void |
879 |
|
set_channel_topic(struct Channel *chptr, const char *topic, |
880 |
< |
const char *topic_info, time_t topicts) |
880 |
> |
const char *topic_info, time_t topicts, int local) |
881 |
|
{ |
882 |
< |
if (!EmptyString(topic)) |
883 |
< |
{ |
914 |
< |
if (chptr->topic == NULL) |
915 |
< |
allocate_topic(chptr); |
916 |
< |
|
917 |
< |
strlcpy(chptr->topic, topic, TOPICLEN+1); |
918 |
< |
strlcpy(chptr->topic_info, topic_info, USERHOST_REPLYLEN); |
919 |
< |
chptr->topic_time = topicts; |
920 |
< |
} |
882 |
> |
if (local) |
883 |
> |
strlcpy(chptr->topic, topic, IRCD_MIN(sizeof(chptr->topic), ServerInfo.max_topic_length + 1)); |
884 |
|
else |
885 |
< |
{ |
886 |
< |
/* |
887 |
< |
* Do not reset chptr->topic_time here, it's required for |
888 |
< |
* bursting topics properly. |
926 |
< |
*/ |
927 |
< |
if (chptr->topic != NULL) |
928 |
< |
free_topic(chptr); |
929 |
< |
} |
885 |
> |
strlcpy(chptr->topic, topic, sizeof(chptr->topic)); |
886 |
> |
|
887 |
> |
strlcpy(chptr->topic_info, topic_info, sizeof(chptr->topic_info)); |
888 |
> |
chptr->topic_time = topicts; |
889 |
|
} |