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 |
> |
|
46 |
> |
|
47 |
> |
dlink_list global_channel_list; |
48 |
> |
mp_pool_t *ban_pool; /*! \todo ban_pool shouldn't be a global var */ |
49 |
|
|
50 |
< |
struct config_channel_entry ConfigChannel; |
51 |
< |
dlink_list global_channel_list = { NULL, NULL, 0 }; |
50 |
< |
dlink_list lazylink_channels = { NULL, NULL, 0 }; |
51 |
< |
BlockHeap *ban_heap; /*! \todo ban_heap shouldn't be a global var */ |
52 |
< |
|
53 |
< |
static BlockHeap *topic_heap = NULL; |
54 |
< |
static BlockHeap *member_heap = NULL; |
55 |
< |
static BlockHeap *channel_heap = NULL; |
50 |
> |
static mp_pool_t *member_pool = NULL; |
51 |
> |
static mp_pool_t *channel_pool = NULL; |
52 |
|
|
53 |
|
static char buf[IRCD_BUFSIZE]; |
58 |
– |
static char modebuf[MODEBUFLEN]; |
59 |
– |
static char parabuf[MODEBUFLEN]; |
54 |
|
|
55 |
|
|
56 |
|
/*! \brief Initializes the channel blockheap, adds known channel CAPAB |
57 |
|
*/ |
58 |
|
void |
59 |
< |
init_channels(void) |
59 |
> |
channel_init(void) |
60 |
|
{ |
67 |
– |
/* |
68 |
– |
* XXX - These should get moved to somwhere else once we have |
69 |
– |
* a modular channelmode system |
70 |
– |
*/ |
61 |
|
add_capability("EX", CAP_EX, 1); |
62 |
|
add_capability("IE", CAP_IE, 1); |
73 |
– |
add_capability("CHW", CAP_CHW, 1); |
63 |
|
|
64 |
< |
channel_heap = BlockHeapCreate("channel", sizeof(struct Channel), CHANNEL_HEAP_SIZE); |
65 |
< |
ban_heap = BlockHeapCreate("ban", sizeof(struct Ban), BAN_HEAP_SIZE); |
66 |
< |
topic_heap = BlockHeapCreate("topic", TOPICLEN+1 + USERHOST_REPLYLEN, TOPIC_HEAP_SIZE); |
78 |
< |
member_heap = BlockHeapCreate("member", sizeof(struct Membership), CHANNEL_HEAP_SIZE*2); |
64 |
> |
channel_pool = mp_pool_new(sizeof(struct Channel), MP_CHUNK_SIZE_CHANNEL); |
65 |
> |
ban_pool = mp_pool_new(sizeof(struct Ban), MP_CHUNK_SIZE_BAN); |
66 |
> |
member_pool = mp_pool_new(sizeof(struct Membership), MP_CHUNK_SIZE_MEMBER); |
67 |
|
} |
68 |
|
|
69 |
|
/*! \brief adds a user to a channel by adding another link to the |
100 |
|
if (!IsSetJoinFloodNoticed(chptr)) |
101 |
|
{ |
102 |
|
SetJoinFloodNoticed(chptr); |
103 |
< |
sendto_realops_flags(UMODE_BOTS, L_ALL, |
103 |
> |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
104 |
|
"Possible Join Flooder %s on %s target: %s", |
105 |
|
get_client_name(who, HIDE_IP), |
106 |
|
who->servptr->name, chptr->chname); |
110 |
|
chptr->last_join_time = CurrentTime; |
111 |
|
} |
112 |
|
|
113 |
< |
ms = BlockHeapAlloc(member_heap); |
113 |
> |
ms = mp_pool_get(member_pool); |
114 |
> |
memset(ms, 0, sizeof(*ms)); |
115 |
> |
|
116 |
|
ms->client_p = who; |
117 |
|
ms->chptr = chptr; |
118 |
|
ms->flags = flags; |
119 |
|
|
120 |
|
dlinkAdd(ms, &ms->channode, &chptr->members); |
131 |
– |
|
132 |
– |
if (MyConnect(who)) |
133 |
– |
dlinkAdd(ms, &ms->locchannode, &chptr->locmembers); |
134 |
– |
|
121 |
|
dlinkAdd(ms, &ms->usernode, &who->channel); |
122 |
|
} |
123 |
|
|
132 |
|
struct Channel *chptr = member->chptr; |
133 |
|
|
134 |
|
dlinkDelete(&member->channode, &chptr->members); |
149 |
– |
|
150 |
– |
if (MyConnect(client_p)) |
151 |
– |
dlinkDelete(&member->locchannode, &chptr->locmembers); |
152 |
– |
|
135 |
|
dlinkDelete(&member->usernode, &client_p->channel); |
136 |
|
|
137 |
< |
BlockHeapFree(member_heap, member); |
137 |
> |
mp_pool_release(member); |
138 |
|
|
139 |
< |
if (dlink_list_length(&chptr->members) == 0) |
158 |
< |
{ |
159 |
< |
assert(dlink_list_length(&chptr->locmembers) == 0); |
139 |
> |
if (chptr->members.head == NULL) |
140 |
|
destroy_channel(chptr); |
161 |
– |
} |
141 |
|
} |
142 |
|
|
143 |
|
/* send_members() |
148 |
|
*/ |
149 |
|
static void |
150 |
|
send_members(struct Client *client_p, struct Channel *chptr, |
151 |
< |
char *lmodebuf, char *lparabuf) |
151 |
> |
char *modebuf, char *parabuf) |
152 |
|
{ |
153 |
< |
struct Membership *ms; |
175 |
< |
dlink_node *ptr; |
153 |
> |
const dlink_node *ptr = NULL; |
154 |
|
int tlen; /* length of text to append */ |
155 |
|
char *t, *start; /* temp char pointer */ |
156 |
|
|
157 |
< |
start = t = buf + ircsprintf(buf, ":%s SJOIN %lu %s %s %s:", |
158 |
< |
ID_or_name(&me, client_p), |
159 |
< |
(unsigned long)chptr->channelts, |
182 |
< |
chptr->chname, lmodebuf, lparabuf); |
157 |
> |
start = t = buf + snprintf(buf, sizeof(buf), ":%s SJOIN %lu %s %s %s:", |
158 |
> |
me.id, (unsigned long)chptr->channelts, |
159 |
> |
chptr->chname, modebuf, parabuf); |
160 |
|
|
161 |
|
DLINK_FOREACH(ptr, chptr->members.head) |
162 |
|
{ |
163 |
< |
ms = ptr->data; |
163 |
> |
const struct Membership *ms = ptr->data; |
164 |
|
|
165 |
< |
tlen = strlen(IsCapable(client_p, CAP_TS6) ? |
189 |
< |
ID(ms->client_p) : ms->client_p->name) + 1; /* nick + space */ |
165 |
> |
tlen = strlen(ms->client_p->id) + 1; /* nick + space */ |
166 |
|
|
167 |
|
if (ms->flags & CHFL_CHANOP) |
168 |
|
tlen++; |
169 |
|
#ifdef HALFOPS |
170 |
< |
else if (ms->flags & CHFL_HALFOP) |
170 |
> |
if (ms->flags & CHFL_HALFOP) |
171 |
|
tlen++; |
172 |
|
#endif |
173 |
|
if (ms->flags & CHFL_VOICE) |
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 |
< |
if (t + tlen - buf > sizeof(buf) - 1) |
179 |
> |
if (t + tlen - buf > IRCD_BUFSIZE - 1) |
180 |
|
{ |
181 |
|
*(t - 1) = '\0'; /* kill the space and terminate the string */ |
182 |
|
sendto_one(client_p, "%s", buf); |
183 |
|
t = start; |
184 |
|
} |
185 |
|
|
186 |
< |
if ((ms->flags & (CHFL_CHANOP | CHFL_HALFOP))) |
187 |
< |
*t++ = (!(ms->flags & CHFL_CHANOP) && IsCapable(client_p, CAP_HOPS)) ? |
188 |
< |
'%' : '@'; |
189 |
< |
if ((ms->flags & CHFL_VOICE)) |
186 |
> |
if (ms->flags & CHFL_CHANOP) |
187 |
> |
*t++ = '@'; |
188 |
> |
if (ms->flags & CHFL_HALFOP) |
189 |
> |
*t++ = '%'; |
190 |
> |
if (ms->flags & CHFL_VOICE) |
191 |
|
*t++ = '+'; |
192 |
|
|
193 |
< |
if (IsCapable(client_p, CAP_TS6)) |
194 |
< |
strcpy(t, ID(ms->client_p)); |
218 |
< |
else |
219 |
< |
strcpy(t, ms->client_p->name); |
193 |
> |
strcpy(t, ms->client_p->id); |
194 |
> |
|
195 |
|
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) |
200 |
> |
if (chptr->members.head) |
201 |
|
t--; /* take the space out */ |
202 |
|
*t = '\0'; |
203 |
|
sendto_one(client_p, "%s", buf); |
211 |
|
*/ |
212 |
|
static void |
213 |
|
send_mode_list(struct Client *client_p, struct Channel *chptr, |
214 |
< |
dlink_list *top, char flag) |
214 |
> |
const dlink_list *top, char flag) |
215 |
|
{ |
216 |
< |
int ts5 = !IsCapable(client_p, CAP_TS6); |
217 |
< |
dlink_node *lp; |
243 |
< |
struct Ban *banptr; |
244 |
< |
char pbuf[IRCD_BUFSIZE]; |
216 |
> |
const dlink_node *lp = NULL; |
217 |
> |
char pbuf[IRCD_BUFSIZE] = ""; |
218 |
|
int tlen, mlen, cur_len, count = 0; |
219 |
< |
char *mp = NULL, *pp = pbuf; |
219 |
> |
char *pp = pbuf; |
220 |
|
|
221 |
< |
if (top == NULL || top->length == 0) |
221 |
> |
if (top->length == 0) |
222 |
|
return; |
223 |
|
|
224 |
< |
if (ts5) |
225 |
< |
mlen = ircsprintf(buf, ":%s MODE %s +", me.name, chptr->chname); |
226 |
< |
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; |
224 |
> |
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 |
|
|
228 |
|
DLINK_FOREACH(lp, top->head) |
229 |
|
{ |
230 |
< |
banptr = lp->data; |
230 |
> |
const struct Ban *banptr = lp->data; |
231 |
|
|
232 |
< |
/* must add another b/e/I letter if we use MODE */ |
266 |
< |
tlen = banptr->len + 3 + ts5; |
232 |
> |
tlen = banptr->len + 3; |
233 |
|
|
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 |
< |
if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2 || |
274 |
< |
(!IsCapable(client_p, CAP_TS6) && |
275 |
< |
(count >= MAXMODEPARAMS || pp - pbuf >= MODEBUFLEN))) |
239 |
> |
if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2) |
240 |
|
{ |
241 |
|
*(pp - 1) = '\0'; /* get rid of trailing space on buffer */ |
242 |
< |
sendto_one(client_p, "%s%s%s", buf, ts5 ? " " : "", pbuf); |
242 |
> |
sendto_one(client_p, "%s%s", buf, pbuf); |
243 |
|
|
244 |
< |
cur_len = mlen + ts5; |
281 |
< |
mp = buf + mlen; |
244 |
> |
cur_len = mlen; |
245 |
|
pp = pbuf; |
246 |
|
count = 0; |
247 |
|
} |
248 |
|
|
249 |
|
count++; |
250 |
< |
if (ts5) |
251 |
< |
{ |
289 |
< |
*mp++ = flag; |
290 |
< |
*mp = '\0'; |
291 |
< |
} |
292 |
< |
|
293 |
< |
pp += ircsprintf(pp, "%s!%s@%s ", banptr->name, banptr->username, |
294 |
< |
banptr->host); |
250 |
> |
pp += sprintf(pp, "%s!%s@%s ", banptr->name, banptr->user, |
251 |
> |
banptr->host); |
252 |
|
cur_len += tlen; |
253 |
|
} |
254 |
|
|
255 |
|
*(pp - 1) = '\0'; /* get rid of trailing space on buffer */ |
256 |
< |
sendto_one(client_p, "%s%s%s", buf, ts5 ? " " : "", pbuf); |
256 |
> |
sendto_one(client_p, "%s%s", buf, pbuf); |
257 |
|
} |
258 |
|
|
259 |
|
/*! \brief send "client_p" a full list of the modes for channel chptr |
263 |
|
void |
264 |
|
send_channel_modes(struct Client *client_p, struct Channel *chptr) |
265 |
|
{ |
266 |
< |
if (chptr->chname[0] != '#') |
267 |
< |
return; |
266 |
> |
char modebuf[MODEBUFLEN] = ""; |
267 |
> |
char parabuf[MODEBUFLEN] = ""; |
268 |
|
|
312 |
– |
*modebuf = *parabuf = '\0'; |
269 |
|
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 |
< |
|
274 |
< |
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'); |
273 |
> |
send_mode_list(client_p, chptr, &chptr->exceptlist, 'e'); |
274 |
> |
send_mode_list(client_p, chptr, &chptr->invexlist, 'I'); |
275 |
|
} |
276 |
|
|
277 |
|
/*! \brief check channel name for invalid characters |
278 |
|
* \param name pointer to channel name string |
279 |
< |
* \return TRUE (1) if name ok, FALSE (0) otherwise |
279 |
> |
* \param local indicates whether it's a local or remote creation |
280 |
> |
* \return 0 if invalid, 1 otherwise |
281 |
|
*/ |
282 |
|
int |
283 |
< |
check_channel_name(const char *name) |
283 |
> |
check_channel_name(const char *name, const int local) |
284 |
|
{ |
285 |
< |
const unsigned char *p = (const unsigned char *)name; |
285 |
> |
const char *p = name; |
286 |
> |
const int max_length = local ? LOCAL_CHANNELLEN : CHANNELLEN; |
287 |
|
assert(name != NULL); |
288 |
|
|
289 |
< |
for (; *p; ++p) |
290 |
< |
if (!IsChanChar(*p)) |
336 |
< |
return 0; |
289 |
> |
if (!IsChanPrefix(*p)) |
290 |
> |
return 0; |
291 |
|
|
292 |
< |
return 1; |
292 |
> |
if (!local || !ConfigChannel.disable_fake_channels) |
293 |
> |
{ |
294 |
> |
while (*++p) |
295 |
> |
if (!IsChanChar(*p)) |
296 |
> |
return 0; |
297 |
> |
} |
298 |
> |
else |
299 |
> |
{ |
300 |
> |
while (*++p) |
301 |
> |
if (!IsVisibleChanChar(*p)) |
302 |
> |
return 0; |
303 |
> |
} |
304 |
> |
|
305 |
> |
return p - name <= max_length; |
306 |
|
} |
307 |
|
|
308 |
|
void |
311 |
|
dlinkDelete(&bptr->node, list); |
312 |
|
|
313 |
|
MyFree(bptr->name); |
314 |
< |
MyFree(bptr->username); |
314 |
> |
MyFree(bptr->user); |
315 |
|
MyFree(bptr->host); |
316 |
|
MyFree(bptr->who); |
317 |
|
|
318 |
< |
BlockHeapFree(ban_heap, bptr); |
318 |
> |
mp_pool_release(bptr); |
319 |
|
} |
320 |
|
|
321 |
|
/* free_channel_list() |
337 |
|
|
338 |
|
/*! \brief Get Channel block for chname (and allocate a new channel |
339 |
|
* block, if it didn't exist before) |
340 |
< |
* \param client_p client pointer |
341 |
< |
* \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 |
340 |
> |
* \param chname channel name |
341 |
> |
* \return channel block |
342 |
|
*/ |
343 |
|
struct Channel * |
344 |
< |
get_or_create_channel(struct Client *client_p, const char *chname, int *isnew) |
344 |
> |
make_channel(const char *chname) |
345 |
|
{ |
346 |
|
struct Channel *chptr = NULL; |
382 |
– |
int len; |
347 |
|
|
348 |
< |
if (EmptyString(chname)) |
385 |
< |
return NULL; |
348 |
> |
assert(!EmptyString(chname)); |
349 |
|
|
350 |
< |
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 |
< |
} |
350 |
> |
chptr = mp_pool_get(channel_pool); |
351 |
|
|
352 |
< |
if ((chptr = hash_find_channel(chname)) != NULL) |
397 |
< |
{ |
398 |
< |
if (isnew != NULL) |
399 |
< |
*isnew = 0; |
352 |
> |
memset(chptr, 0, sizeof(*chptr)); |
353 |
|
|
401 |
– |
return chptr; |
402 |
– |
} |
403 |
– |
|
404 |
– |
if (isnew != NULL) |
405 |
– |
*isnew = 1; |
406 |
– |
|
407 |
– |
chptr = BlockHeapAlloc(channel_heap); |
354 |
|
/* doesn't hurt to set it here */ |
355 |
< |
chptr->channelts = chptr->last_join_time = CurrentTime; |
355 |
> |
chptr->channelts = CurrentTime; |
356 |
> |
chptr->last_join_time = CurrentTime; |
357 |
|
|
358 |
|
strlcpy(chptr->chname, chname, sizeof(chptr->chname)); |
359 |
|
dlinkAdd(chptr, &chptr->node, &global_channel_list); |
379 |
|
free_channel_list(&chptr->exceptlist); |
380 |
|
free_channel_list(&chptr->invexlist); |
381 |
|
|
435 |
– |
/* Free the topic */ |
436 |
– |
free_topic(chptr); |
437 |
– |
|
382 |
|
dlinkDelete(&chptr->node, &global_channel_list); |
383 |
|
hash_del_channel(chptr); |
384 |
|
|
385 |
< |
if (ServerInfo.hub) |
442 |
< |
if ((ptr = dlinkFindDelete(&lazylink_channels, chptr))) |
443 |
< |
free_dlink_node(ptr); |
444 |
< |
|
445 |
< |
BlockHeapFree(channel_heap, chptr); |
385 |
> |
mp_pool_release(chptr); |
386 |
|
} |
387 |
|
|
388 |
|
/*! |
390 |
|
* \return string pointer "=" if public, "@" if secret else "*" |
391 |
|
*/ |
392 |
|
static const char * |
393 |
< |
channel_pub_or_secret(struct Channel *chptr) |
393 |
> |
channel_pub_or_secret(const struct Channel *chptr) |
394 |
|
{ |
395 |
|
if (SecretChannel(chptr)) |
396 |
|
return "@"; |
409 |
|
channel_member_names(struct Client *source_p, struct Channel *chptr, |
410 |
|
int show_eon) |
411 |
|
{ |
412 |
< |
struct Client *target_p = NULL; |
413 |
< |
struct Membership *ms = NULL; |
474 |
< |
dlink_node *ptr = NULL; |
475 |
< |
char lbuf[IRCD_BUFSIZE + 1]; |
412 |
> |
const dlink_node *ptr = NULL; |
413 |
> |
char lbuf[IRCD_BUFSIZE + 1] = ""; |
414 |
|
char *t = NULL, *start = NULL; |
415 |
|
int tlen = 0; |
416 |
|
int is_member = IsMember(source_p, chptr); |
417 |
+ |
int multi_prefix = HasCap(source_p, CAP_MULTI_PREFIX) != 0; |
418 |
+ |
int uhnames = HasCap(source_p, CAP_UHNAMES) != 0; |
419 |
|
|
420 |
|
if (PubChannel(chptr) || is_member) |
421 |
|
{ |
422 |
< |
t = lbuf + ircsprintf(lbuf, form_str(RPL_NAMREPLY), |
423 |
< |
me.name, source_p->name, |
424 |
< |
channel_pub_or_secret(chptr), |
485 |
< |
chptr->chname); |
422 |
> |
t = lbuf + snprintf(lbuf, sizeof(lbuf), numeric_form(RPL_NAMREPLY), |
423 |
> |
me.name, source_p->name, |
424 |
> |
channel_pub_or_secret(chptr), chptr->chname); |
425 |
|
start = t; |
426 |
|
|
427 |
|
DLINK_FOREACH(ptr, chptr->members.head) |
428 |
|
{ |
429 |
< |
ms = ptr->data; |
491 |
< |
target_p = ms->client_p; |
429 |
> |
const struct Membership *ms = ptr->data; |
430 |
|
|
431 |
< |
if (IsInvisible(target_p) && !is_member) |
431 |
> |
if (HasUMode(ms->client_p, UMODE_INVISIBLE) && !is_member) |
432 |
|
continue; |
433 |
|
|
434 |
< |
tlen = strlen(target_p->name) + 1; /* nick + space */ |
434 |
> |
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 |
> |
|
440 |
> |
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 |
< |
if (ms->flags & (CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE)) |
499 |
< |
++tlen; |
500 |
< |
if (t + tlen - lbuf > IRCD_BUFSIZE) |
455 |
> |
if (t + tlen - lbuf > IRCD_BUFSIZE - 2) |
456 |
|
{ |
457 |
|
*(t - 1) = '\0'; |
458 |
|
sendto_one(source_p, "%s", lbuf); |
459 |
|
t = start; |
460 |
|
} |
461 |
|
|
462 |
< |
t += ircsprintf(t, "%s%s ", get_member_status(ms, NO), |
463 |
< |
target_p->name); |
462 |
> |
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 |
|
} |
470 |
|
|
471 |
< |
if (tlen != 0) |
471 |
> |
if (tlen) |
472 |
|
{ |
473 |
|
*(t - 1) = '\0'; |
474 |
|
sendto_one(source_p, "%s", lbuf); |
476 |
|
} |
477 |
|
|
478 |
|
if (show_eon) |
479 |
< |
sendto_one(source_p, form_str(RPL_ENDOFNAMES), |
520 |
< |
me.name, source_p->name, chptr->chname); |
479 |
> |
sendto_one_numeric(source_p, &me, RPL_ENDOFNAMES, chptr->chname); |
480 |
|
} |
481 |
|
|
482 |
|
/*! \brief adds client to invite list |
531 |
|
* (like in get_client_name) |
532 |
|
*/ |
533 |
|
const char * |
534 |
< |
get_member_status(const struct Membership *ms, int combine) |
534 |
> |
get_member_status(const struct Membership *ms, const int combine) |
535 |
|
{ |
536 |
|
static char buffer[4]; |
537 |
< |
char *p = NULL; |
579 |
< |
|
580 |
< |
if (ms == NULL) |
581 |
< |
return ""; |
582 |
< |
p = buffer; |
537 |
> |
char *p = buffer; |
538 |
|
|
539 |
|
if (ms->flags & CHFL_CHANOP) |
540 |
|
{ |
572 |
|
|
573 |
|
DLINK_FOREACH(ptr, list->head) |
574 |
|
{ |
575 |
< |
struct Ban *bp = ptr->data; |
575 |
> |
const struct Ban *bp = ptr->data; |
576 |
|
|
577 |
< |
if (match(bp->name, who->name) && match(bp->username, who->username)) |
577 |
> |
if (!match(bp->name, who->name) && !match(bp->user, who->username)) |
578 |
|
{ |
579 |
|
switch (bp->type) |
580 |
|
{ |
581 |
|
case HM_HOST: |
582 |
< |
if (match(bp->host, who->host) || match(bp->host, who->sockhost)) |
582 |
> |
if (!match(bp->host, who->host) || !match(bp->host, who->sockhost)) |
583 |
|
return 1; |
584 |
|
break; |
585 |
|
case HM_IPV4: |
609 |
|
* \return 0 if not banned, 1 otherwise |
610 |
|
*/ |
611 |
|
int |
612 |
< |
is_banned(struct Channel *chptr, struct Client *who) |
612 |
> |
is_banned(const struct Channel *chptr, const struct Client *who) |
613 |
|
{ |
614 |
< |
assert(IsClient(who)); |
614 |
> |
if (find_bmask(who, &chptr->banlist)) |
615 |
> |
if (!find_bmask(who, &chptr->exceptlist)) |
616 |
> |
return 1; |
617 |
|
|
618 |
< |
return find_bmask(who, &chptr->banlist) && (!ConfigChannel.use_except || |
662 |
< |
!find_bmask(who, &chptr->exceptlist)); |
618 |
> |
return 0; |
619 |
|
} |
620 |
|
|
621 |
|
/*! |
622 |
|
* \param source_p pointer to client attempting to join |
623 |
< |
* \param chptr pointer to channel |
623 |
> |
* \param chptr pointer to channel |
624 |
|
* \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. |
628 |
|
int |
629 |
|
can_join(struct Client *source_p, struct Channel *chptr, const char *key) |
630 |
|
{ |
631 |
< |
if (find_bmask(source_p, &chptr->banlist)) |
632 |
< |
if (!ConfigChannel.use_except || !find_bmask(source_p, &chptr->exceptlist)) |
633 |
< |
return ERR_BANNEDFROMCHAN; |
631 |
> |
if ((chptr->mode.mode & MODE_SSLONLY) && !HasUMode(source_p, UMODE_SSL)) |
632 |
> |
return ERR_SSLONLYCHAN; |
633 |
> |
|
634 |
> |
if ((chptr->mode.mode & MODE_REGONLY) && !HasUMode(source_p, UMODE_REGISTERED)) |
635 |
> |
return ERR_NEEDREGGEDNICK; |
636 |
> |
|
637 |
> |
if ((chptr->mode.mode & MODE_OPERONLY) && !HasUMode(source_p, UMODE_OPER)) |
638 |
> |
return ERR_OPERONLYCHAN; |
639 |
|
|
640 |
|
if (chptr->mode.mode & MODE_INVITEONLY) |
641 |
|
if (!dlinkFind(&source_p->localClient->invited, chptr)) |
642 |
< |
if (!ConfigChannel.use_invex || !find_bmask(source_p, &chptr->invexlist)) |
642 |
> |
if (!find_bmask(source_p, &chptr->invexlist)) |
643 |
|
return ERR_INVITEONLYCHAN; |
644 |
|
|
645 |
< |
if (chptr->mode.key[0] && (EmptyString(key) || irccmp(chptr->mode.key, key))) |
645 |
> |
if (chptr->mode.key[0] && (!key || strcmp(chptr->mode.key, key))) |
646 |
|
return ERR_BADCHANNELKEY; |
647 |
|
|
648 |
|
if (chptr->mode.limit && dlink_list_length(&chptr->members) >= |
649 |
|
chptr->mode.limit) |
650 |
|
return ERR_CHANNELISFULL; |
651 |
|
|
652 |
+ |
if (is_banned(chptr, source_p)) |
653 |
+ |
return ERR_BANNEDFROMCHAN; |
654 |
+ |
|
655 |
|
return 0; |
656 |
|
} |
657 |
|
|
658 |
|
int |
659 |
< |
has_member_flags(struct Membership *ms, unsigned int flags) |
659 |
> |
has_member_flags(const struct Membership *ms, const unsigned int flags) |
660 |
|
{ |
661 |
< |
if (ms != NULL) |
698 |
< |
return ms->flags & flags; |
699 |
< |
return 0; |
661 |
> |
return ms && (ms->flags & flags); |
662 |
|
} |
663 |
|
|
664 |
|
struct Membership * |
669 |
|
if (!IsClient(client_p)) |
670 |
|
return NULL; |
671 |
|
|
672 |
< |
DLINK_FOREACH(ptr, client_p->channel.head) |
673 |
< |
if (((struct Membership *)ptr->data)->chptr == chptr) |
674 |
< |
return (struct Membership *)ptr->data; |
672 |
> |
if (dlink_list_length(&chptr->members) < dlink_list_length(&client_p->channel)) |
673 |
> |
{ |
674 |
> |
DLINK_FOREACH(ptr, chptr->members.head) |
675 |
> |
if (((struct Membership *)ptr->data)->client_p == client_p) |
676 |
> |
return ptr->data; |
677 |
> |
} |
678 |
> |
else |
679 |
> |
{ |
680 |
> |
DLINK_FOREACH(ptr, client_p->channel.head) |
681 |
> |
if (((struct Membership *)ptr->data)->chptr == chptr) |
682 |
> |
return ptr->data; |
683 |
> |
} |
684 |
|
|
685 |
|
return NULL; |
686 |
|
} |
687 |
|
|
688 |
+ |
/* |
689 |
+ |
* Basically the same functionality as in bahamut |
690 |
+ |
*/ |
691 |
+ |
static int |
692 |
+ |
msg_has_ctrls(const char *message) |
693 |
+ |
{ |
694 |
+ |
const unsigned char *p = (const unsigned char *)message; |
695 |
+ |
|
696 |
+ |
for (; *p; ++p) |
697 |
+ |
{ |
698 |
+ |
if (*p > 31 || *p == 1) |
699 |
+ |
continue; |
700 |
+ |
|
701 |
+ |
if (*p == 27) |
702 |
+ |
{ |
703 |
+ |
if (*(p + 1) == '$' || |
704 |
+ |
*(p + 1) == '(') |
705 |
+ |
{ |
706 |
+ |
++p; |
707 |
+ |
continue; |
708 |
+ |
} |
709 |
+ |
} |
710 |
+ |
|
711 |
+ |
return 1; |
712 |
+ |
} |
713 |
+ |
|
714 |
+ |
return 0; |
715 |
+ |
} |
716 |
+ |
|
717 |
|
/*! |
718 |
|
* \param chptr pointer to Channel struct |
719 |
|
* \param source_p pointer to Client struct |
720 |
|
* \param ms pointer to Membership struct (can be NULL) |
721 |
|
* \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 |
< |
* CAN_SEND_NO if they cannot send to channel\n |
723 |
> |
* ERR_CANNOTSENDTOCHAN or ERR_NEEDREGGEDNICK if they cannot send to channel\n |
724 |
|
*/ |
725 |
|
int |
726 |
< |
can_send(struct Channel *chptr, struct Client *source_p, struct Membership *ms) |
726 |
> |
can_send(struct Channel *chptr, struct Client *source_p, |
727 |
> |
struct Membership *ms, const char *message) |
728 |
|
{ |
729 |
< |
if (IsServer(source_p)) |
729 |
< |
return CAN_SEND_OPV; |
729 |
> |
struct MaskItem *conf = NULL; |
730 |
|
|
731 |
< |
if (MyClient(source_p) && !IsExemptResv(source_p) && |
732 |
< |
!(IsOper(source_p) && ConfigFileEntry.oper_pass_resv) && |
733 |
< |
(!hash_find_resv(chptr->chname) == ConfigChannel.restrict_channels)) |
734 |
< |
return CAN_SEND_NO; |
731 |
> |
if (IsServer(source_p) || HasFlag(source_p, FLAGS_SERVICE)) |
732 |
> |
return CAN_SEND_OPV; |
733 |
|
|
734 |
< |
if (ms != NULL || (ms = find_channel_link(source_p, chptr))) |
735 |
< |
{ |
734 |
> |
if (MyClient(source_p) && !IsExemptResv(source_p)) |
735 |
> |
if (!(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.oper_pass_resv)) |
736 |
> |
if ((conf = match_find_resv(chptr->chname)) && !resv_find_exempt(source_p, conf)) |
737 |
> |
return ERR_CANNOTSENDTOCHAN; |
738 |
> |
|
739 |
> |
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 |
|
if (ms->flags & (CHFL_CHANOP|CHFL_HALFOP|CHFL_VOICE)) |
743 |
|
return CAN_SEND_OPV; |
744 |
+ |
if (!ms && (chptr->mode.mode & MODE_NOPRIVMSGS)) |
745 |
+ |
return ERR_CANNOTSENDTOCHAN; |
746 |
+ |
if (chptr->mode.mode & MODE_MODERATED) |
747 |
+ |
return ERR_CANNOTSENDTOCHAN; |
748 |
+ |
if ((chptr->mode.mode & MODE_MODREG) && !HasUMode(source_p, UMODE_REGISTERED)) |
749 |
+ |
return ERR_NEEDREGGEDNICK; |
750 |
|
|
751 |
< |
/* cache can send if quiet_on_ban and banned */ |
752 |
< |
if (ConfigChannel.quiet_on_ban && MyClient(source_p)) |
751 |
> |
/* cache can send if banned */ |
752 |
> |
if (MyClient(source_p)) |
753 |
> |
{ |
754 |
> |
if (ms) |
755 |
|
{ |
756 |
|
if (ms->flags & CHFL_BAN_SILENCED) |
757 |
< |
return CAN_SEND_NO; |
757 |
> |
return ERR_CANNOTSENDTOCHAN; |
758 |
|
|
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 |
< |
return CAN_SEND_NO; |
764 |
> |
return ERR_CANNOTSENDTOCHAN; |
765 |
|
} |
766 |
|
|
767 |
|
ms->flags |= CHFL_BAN_CHECKED; |
768 |
|
} |
769 |
|
} |
770 |
+ |
else if (is_banned(chptr, source_p)) |
771 |
+ |
return ERR_CANNOTSENDTOCHAN; |
772 |
|
} |
759 |
– |
else if (chptr->mode.mode & MODE_NOPRIVMSGS) |
760 |
– |
return CAN_SEND_NO; |
761 |
– |
|
762 |
– |
if (chptr->mode.mode & MODE_MODERATED) |
763 |
– |
return CAN_SEND_NO; |
773 |
|
|
774 |
|
return CAN_SEND_NONOP; |
775 |
|
} |
798 |
|
if (source_p->localClient->oper_warn_count_down == 0) |
799 |
|
{ |
800 |
|
/* Its already known as a possible spambot */ |
801 |
< |
if (name != NULL) |
802 |
< |
sendto_realops_flags(UMODE_BOTS, L_ALL, |
801 |
> |
if (name) |
802 |
> |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
803 |
|
"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 |
< |
sendto_realops_flags(UMODE_BOTS, L_ALL, |
807 |
> |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
808 |
|
"User %s (%s@%s) is a possible spambot", |
809 |
|
source_p->name, source_p->username, |
810 |
|
source_p->host); |
832 |
|
} |
833 |
|
} |
834 |
|
|
835 |
< |
if (name != NULL) |
835 |
> |
if (name) |
836 |
|
source_p->localClient->last_join_time = CurrentTime; |
837 |
|
else |
838 |
|
source_p->localClient->last_leave_time = CurrentTime; |
855 |
|
{ |
856 |
|
splitmode = 1; |
857 |
|
|
858 |
< |
sendto_realops_flags(UMODE_ALL,L_ALL, |
858 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
859 |
|
"Network split, activating splitmode"); |
860 |
|
eventAddIsh("check_splitmode", check_splitmode, NULL, 10); |
861 |
|
} |
863 |
|
{ |
864 |
|
splitmode = 0; |
865 |
|
|
866 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
866 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
867 |
|
"Network rejoined, deactivating splitmode"); |
868 |
|
eventDelete(check_splitmode, NULL); |
869 |
|
} |
870 |
|
} |
871 |
|
} |
872 |
|
|
864 |
– |
/*! \brief Allocates a new topic |
865 |
– |
* \param chptr Channel to allocate a new topic for |
866 |
– |
*/ |
867 |
– |
static void |
868 |
– |
allocate_topic(struct Channel *chptr) |
869 |
– |
{ |
870 |
– |
void *ptr = NULL; |
871 |
– |
|
872 |
– |
if (chptr == NULL) |
873 |
– |
return; |
874 |
– |
|
875 |
– |
ptr = BlockHeapAlloc(topic_heap); |
876 |
– |
|
877 |
– |
/* Basically we allocate one large block for the topic and |
878 |
– |
* the topic info. We then split it up into two and shove it |
879 |
– |
* in the chptr |
880 |
– |
*/ |
881 |
– |
chptr->topic = ptr; |
882 |
– |
chptr->topic_info = (char *)ptr + TOPICLEN+1; |
883 |
– |
*chptr->topic = '\0'; |
884 |
– |
*chptr->topic_info = '\0'; |
885 |
– |
} |
886 |
– |
|
887 |
– |
void |
888 |
– |
free_topic(struct Channel *chptr) |
889 |
– |
{ |
890 |
– |
void *ptr = NULL; |
891 |
– |
assert(chptr); |
892 |
– |
if (chptr->topic == NULL) |
893 |
– |
return; |
894 |
– |
|
895 |
– |
/* |
896 |
– |
* If you change allocate_topic you MUST change this as well |
897 |
– |
*/ |
898 |
– |
ptr = chptr->topic; |
899 |
– |
BlockHeapFree(topic_heap, ptr); |
900 |
– |
chptr->topic = NULL; |
901 |
– |
chptr->topic_info = NULL; |
902 |
– |
} |
903 |
– |
|
873 |
|
/*! \brief Sets the channel topic for chptr |
874 |
|
* \param chptr Pointer to struct Channel |
875 |
|
* \param topic The topic string |
878 |
|
*/ |
879 |
|
void |
880 |
|
set_channel_topic(struct Channel *chptr, const char *topic, |
881 |
< |
const char *topic_info, time_t topicts) |
881 |
> |
const char *topic_info, time_t topicts, int local) |
882 |
|
{ |
883 |
< |
if (!EmptyString(topic)) |
884 |
< |
{ |
916 |
< |
if (chptr->topic == NULL) |
917 |
< |
allocate_topic(chptr); |
918 |
< |
|
919 |
< |
strlcpy(chptr->topic, topic, TOPICLEN+1); |
920 |
< |
strlcpy(chptr->topic_info, topic_info, USERHOST_REPLYLEN); |
921 |
< |
chptr->topic_time = topicts; |
922 |
< |
} |
883 |
> |
if (local) |
884 |
> |
strlcpy(chptr->topic, topic, IRCD_MIN(sizeof(chptr->topic), ServerInfo.max_topic_length + 1)); |
885 |
|
else |
886 |
< |
{ |
887 |
< |
/* |
888 |
< |
* Do not reset chptr->topic_time here, it's required for |
889 |
< |
* bursting topics properly. |
928 |
< |
*/ |
929 |
< |
if (chptr->topic != NULL) |
930 |
< |
free_topic(chptr); |
931 |
< |
} |
886 |
> |
strlcpy(chptr->topic, topic, sizeof(chptr->topic)); |
887 |
> |
|
888 |
> |
strlcpy(chptr->topic_info, topic_info, sizeof(chptr->topic_info)); |
889 |
> |
chptr->topic_time = topicts; |
890 |
|
} |