1 |
|
/* |
2 |
< |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
< |
* client.c: Controls clients. |
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 |
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 |
< |
* $Id$ |
20 |
> |
*/ |
21 |
> |
|
22 |
> |
/*! \file client.c |
23 |
> |
* \brief Controls clients. |
24 |
> |
* \version $Id$ |
25 |
|
*/ |
26 |
|
|
27 |
|
#include "stdinc.h" |
28 |
|
#include "list.h" |
29 |
|
#include "client.h" |
28 |
– |
#include "channel_mode.h" |
30 |
|
#include "event.h" |
30 |
– |
#include "fdlist.h" |
31 |
|
#include "hash.h" |
32 |
|
#include "irc_string.h" |
33 |
|
#include "ircd.h" |
34 |
– |
#include "s_gline.h" |
34 |
|
#include "numeric.h" |
35 |
< |
#include "packet.h" |
37 |
< |
#include "s_auth.h" |
35 |
> |
#include "auth.h" |
36 |
|
#include "s_bsd.h" |
37 |
|
#include "conf.h" |
38 |
|
#include "log.h" |
39 |
< |
#include "s_misc.h" |
40 |
< |
#include "s_serv.h" |
39 |
> |
#include "misc.h" |
40 |
> |
#include "server.h" |
41 |
|
#include "send.h" |
42 |
|
#include "whowas.h" |
43 |
< |
#include "s_user.h" |
46 |
< |
#include "dbuf.h" |
43 |
> |
#include "user.h" |
44 |
|
#include "memory.h" |
45 |
+ |
#include "mempool.h" |
46 |
|
#include "hostmask.h" |
49 |
– |
#include "balloc.h" |
47 |
|
#include "listener.h" |
51 |
– |
#include "irc_res.h" |
48 |
|
#include "userhost.h" |
49 |
|
#include "watch.h" |
50 |
+ |
#include "rng_mt.h" |
51 |
+ |
#include "parse.h" |
52 |
|
|
53 |
|
dlink_list listing_client_list = { NULL, NULL, 0 }; |
54 |
|
/* Pointer to beginning of Client list */ |
60 |
|
dlink_list global_serv_list = {NULL, NULL, 0}; |
61 |
|
dlink_list oper_list = {NULL, NULL, 0}; |
62 |
|
|
63 |
< |
static EVH check_pings; |
63 |
> |
static void check_pings(void *); |
64 |
|
|
65 |
< |
static BlockHeap *client_heap = NULL; |
66 |
< |
static BlockHeap *lclient_heap = NULL; |
65 |
> |
static mp_pool_t *client_pool = NULL; |
66 |
> |
static mp_pool_t *lclient_pool = NULL; |
67 |
|
|
68 |
|
static dlink_list dead_list = { NULL, NULL, 0}; |
69 |
|
static dlink_list abort_list = { NULL, NULL, 0}; |
72 |
|
|
73 |
|
static void check_pings_list(dlink_list *); |
74 |
|
static void check_unknowns_list(void); |
77 |
– |
static void ban_them(struct Client *, struct MaskItem *); |
75 |
|
|
76 |
|
|
77 |
< |
/* init_client() |
77 |
> |
/* client_init() |
78 |
|
* |
79 |
|
* inputs - NONE |
80 |
|
* output - NONE |
81 |
|
* side effects - initialize client free memory |
82 |
|
*/ |
83 |
|
void |
84 |
< |
init_client(void) |
84 |
> |
client_init(void) |
85 |
|
{ |
86 |
< |
/* start off the check ping event .. -- adrian |
87 |
< |
* Every 30 seconds is plenty -- db |
88 |
< |
*/ |
89 |
< |
client_heap = BlockHeapCreate("client", sizeof(struct Client), CLIENT_HEAP_SIZE); |
90 |
< |
lclient_heap = BlockHeapCreate("local client", sizeof(struct LocalUser), LCLIENT_HEAP_SIZE); |
91 |
< |
eventAdd("check_pings", check_pings, NULL, 5); |
86 |
> |
static struct event event_ping = |
87 |
> |
{ |
88 |
> |
.name = "check_pings", |
89 |
> |
.handler = check_pings, |
90 |
> |
.when = 5 |
91 |
> |
}; |
92 |
> |
|
93 |
> |
client_pool = mp_pool_new(sizeof(struct Client), MP_CHUNK_SIZE_CLIENT); |
94 |
> |
lclient_pool = mp_pool_new(sizeof(struct LocalUser), MP_CHUNK_SIZE_LCLIENT); |
95 |
> |
event_add(&event_ping, NULL); |
96 |
|
} |
97 |
|
|
98 |
|
/* |
113 |
|
struct Client * |
114 |
|
make_client(struct Client *from) |
115 |
|
{ |
116 |
< |
struct Client *client_p = BlockHeapAlloc(client_heap); |
116 |
> |
struct Client *client_p = mp_pool_get(client_pool); |
117 |
|
|
118 |
< |
if (from == NULL) |
118 |
> |
if (!from) |
119 |
|
{ |
120 |
|
client_p->from = client_p; /* 'from' of local client is self! */ |
121 |
< |
client_p->localClient = BlockHeapAlloc(lclient_heap); |
121 |
> |
client_p->localClient = mp_pool_get(lclient_pool); |
122 |
|
client_p->localClient->since = CurrentTime; |
123 |
|
client_p->localClient->lasttime = CurrentTime; |
124 |
|
client_p->localClient->firsttime = CurrentTime; |
132 |
|
|
133 |
|
client_p->idhnext = client_p; |
134 |
|
client_p->hnext = client_p; |
135 |
< |
client_p->status = STAT_UNKNOWN; |
135 |
> |
SetUnknown(client_p); |
136 |
|
strcpy(client_p->username, "unknown"); |
137 |
|
strcpy(client_p->svid, "0"); |
138 |
|
|
149 |
|
static void |
150 |
|
free_client(struct Client *client_p) |
151 |
|
{ |
152 |
< |
assert(client_p != NULL); |
152 |
> |
assert(client_p); |
153 |
|
assert(client_p != &me); |
154 |
|
assert(client_p->hnext == client_p); |
155 |
|
assert(client_p->idhnext == client_p); |
156 |
|
assert(client_p->channel.head == NULL); |
157 |
|
assert(dlink_list_length(&client_p->channel) == 0); |
158 |
|
assert(dlink_list_length(&client_p->whowas) == 0); |
159 |
< |
assert(!IsServer(client_p) || IsServer(client_p) && client_p->serv); |
159 |
> |
assert(!IsServer(client_p) || client_p->serv); |
160 |
|
|
161 |
|
MyFree(client_p->serv); |
162 |
+ |
MyFree(client_p->certfp); |
163 |
|
|
164 |
|
if (MyConnect(client_p)) |
165 |
|
{ |
166 |
|
assert(client_p->localClient->invited.head == NULL); |
167 |
|
assert(dlink_list_length(&client_p->localClient->invited) == 0); |
168 |
< |
assert(dlink_list_length(&client_p->localClient->watches) == 0); |
168 |
> |
assert(dlink_list_length(&client_p->localClient->watches) == 0); |
169 |
|
assert(IsClosing(client_p) && IsDead(client_p)); |
170 |
|
|
171 |
|
MyFree(client_p->localClient->response); |
178 |
|
{ |
179 |
|
assert(0 < client_p->localClient->listener->ref_count); |
180 |
|
if (0 == --client_p->localClient->listener->ref_count && |
181 |
< |
!client_p->localClient->listener->active) |
181 |
> |
!client_p->localClient->listener->active) |
182 |
|
free_listener(client_p->localClient->listener); |
183 |
|
} |
184 |
|
|
185 |
|
dbuf_clear(&client_p->localClient->buf_recvq); |
186 |
|
dbuf_clear(&client_p->localClient->buf_sendq); |
187 |
|
|
188 |
< |
BlockHeapFree(lclient_heap, client_p->localClient); |
188 |
> |
mp_pool_release(client_p->localClient); |
189 |
|
} |
190 |
|
|
191 |
< |
BlockHeapFree(client_heap, client_p); |
191 |
> |
mp_pool_release(client_p); |
192 |
|
} |
193 |
|
|
194 |
|
/* |
197 |
|
* |
198 |
|
* inputs - NOT USED (from event) |
199 |
|
* output - next time_t when check_pings() should be called again |
200 |
< |
* side effects - |
200 |
> |
* side effects - |
201 |
|
* |
202 |
|
* |
203 |
|
* A PING can be sent to clients as necessary. |
219 |
|
|
220 |
|
static void |
221 |
|
check_pings(void *notused) |
222 |
< |
{ |
222 |
> |
{ |
223 |
|
check_pings_list(&local_client_list); |
224 |
|
check_pings_list(&serv_list); |
225 |
|
check_unknowns_list(); |
229 |
|
* |
230 |
|
* inputs - pointer to list to check |
231 |
|
* output - NONE |
232 |
< |
* side effects - |
232 |
> |
* side effects - |
233 |
|
*/ |
234 |
|
static void |
235 |
|
check_pings_list(dlink_list *list) |
236 |
|
{ |
237 |
< |
char scratch[32]; /* way too generous but... */ |
237 |
> |
char scratch[IRCD_BUFSIZE]; |
238 |
|
int ping = 0; /* ping time value from client */ |
239 |
|
dlink_node *ptr = NULL, *next_ptr = NULL; |
240 |
|
|
249 |
|
if (IsDead(client_p)) |
250 |
|
{ |
251 |
|
/* Ignore it, its been exited already */ |
252 |
< |
continue; |
252 |
> |
continue; |
253 |
|
} |
254 |
|
|
255 |
|
if (!IsRegistered(client_p)) |
261 |
|
{ |
262 |
|
if (!IsPingSent(client_p)) |
263 |
|
{ |
264 |
< |
/* |
265 |
< |
* if we havent PINGed the connection and we havent |
266 |
< |
* heard from it in a while, PING it to make sure |
267 |
< |
* it is still alive. |
268 |
< |
*/ |
269 |
< |
SetPingSent(client_p); |
270 |
< |
client_p->localClient->lasttime = CurrentTime - ping; |
271 |
< |
sendto_one(client_p, "PING :%s", ID_or_name(&me, client_p)); |
264 |
> |
/* |
265 |
> |
* if we havent PINGed the connection and we havent |
266 |
> |
* heard from it in a while, PING it to make sure |
267 |
> |
* it is still alive. |
268 |
> |
*/ |
269 |
> |
SetPingSent(client_p); |
270 |
> |
client_p->localClient->lasttime = CurrentTime - ping; |
271 |
> |
sendto_one(client_p, "PING :%s", ID_or_name(&me, client_p)); |
272 |
|
} |
273 |
|
else |
274 |
|
{ |
279 |
|
* and it has a ping time, then close its connection. |
280 |
|
*/ |
281 |
|
if (IsServer(client_p) || IsHandshake(client_p)) |
282 |
< |
{ |
283 |
< |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
284 |
< |
"No response from %s, closing link", |
285 |
< |
get_client_name(client_p, HIDE_IP)); |
286 |
< |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
287 |
< |
"No response from %s, closing link", |
288 |
< |
get_client_name(client_p, MASK_IP)); |
289 |
< |
ilog(LOG_TYPE_IRCD, "No response from %s, closing link", |
290 |
< |
get_client_name(client_p, HIDE_IP)); |
291 |
< |
} |
282 |
> |
{ |
283 |
> |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
284 |
> |
"No response from %s, closing link", |
285 |
> |
get_client_name(client_p, HIDE_IP)); |
286 |
> |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
287 |
> |
"No response from %s, closing link", |
288 |
> |
get_client_name(client_p, MASK_IP)); |
289 |
> |
ilog(LOG_TYPE_IRCD, "No response from %s, closing link", |
290 |
> |
get_client_name(client_p, HIDE_IP)); |
291 |
> |
} |
292 |
|
|
293 |
|
snprintf(scratch, sizeof(scratch), "Ping timeout: %d seconds", |
294 |
|
(int)(CurrentTime - client_p->localClient->lasttime)); |
295 |
< |
exit_client(client_p, &me, scratch); |
295 |
> |
exit_client(client_p, scratch); |
296 |
|
} |
297 |
|
} |
298 |
|
} |
308 |
|
static void |
309 |
|
check_unknowns_list(void) |
310 |
|
{ |
311 |
< |
dlink_node *ptr, *next_ptr; |
311 |
> |
dlink_node *ptr = NULL, *ptr_next = NULL; |
312 |
|
|
313 |
< |
DLINK_FOREACH_SAFE(ptr, next_ptr, unknown_list.head) |
313 |
> |
DLINK_FOREACH_SAFE(ptr, ptr_next, unknown_list.head) |
314 |
|
{ |
315 |
|
struct Client *client_p = ptr->data; |
316 |
|
|
319 |
|
* for > 30s, close them. |
320 |
|
*/ |
321 |
|
if (IsAuthFinished(client_p) && (CurrentTime - client_p->localClient->firsttime) > 30) |
322 |
< |
exit_client(client_p, &me, "Registration timed out"); |
322 |
> |
exit_client(client_p, "Registration timed out"); |
323 |
|
} |
324 |
|
} |
325 |
|
|
330 |
|
* side effects - Check all connections for a pending kline against the |
331 |
|
* client, exit the client if a kline matches. |
332 |
|
*/ |
333 |
< |
void |
333 |
> |
void |
334 |
|
check_conf_klines(void) |
335 |
< |
{ |
334 |
< |
struct Client *client_p = NULL; /* current local client_p being examined */ |
335 |
> |
{ |
336 |
|
struct MaskItem *conf = NULL; |
337 |
< |
dlink_node *ptr, *next_ptr; |
337 |
> |
dlink_node *ptr = NULL, *ptr_next = NULL; |
338 |
|
|
339 |
< |
DLINK_FOREACH_SAFE(ptr, next_ptr, local_client_list.head) |
339 |
> |
DLINK_FOREACH_SAFE(ptr, ptr_next, local_client_list.head) |
340 |
|
{ |
341 |
< |
client_p = ptr->data; |
341 |
> |
struct Client *client_p = ptr->data; |
342 |
|
|
343 |
|
/* If a client is already being exited |
344 |
|
*/ |
345 |
|
if (IsDead(client_p) || !IsClient(client_p)) |
346 |
|
continue; |
347 |
|
|
348 |
< |
if ((conf = find_dline_conf(&client_p->localClient->ip, |
349 |
< |
client_p->localClient->aftype)) != NULL) |
348 |
> |
if ((conf = find_conf_by_address(NULL, &client_p->localClient->ip, CONF_DLINE, |
349 |
> |
client_p->localClient->aftype, NULL, NULL, 1))) |
350 |
|
{ |
351 |
< |
if (conf->type == CONF_EXEMPT) |
351 |
< |
continue; |
352 |
< |
|
353 |
< |
ban_them(client_p, conf); |
351 |
> |
conf_try_ban(client_p, conf); |
352 |
|
continue; /* and go examine next fd/client_p */ |
353 |
|
} |
354 |
|
|
355 |
< |
if (ConfigFileEntry.glines && (conf = find_gline(client_p))) |
355 |
> |
if (ConfigFileEntry.glines) |
356 |
|
{ |
357 |
< |
if (IsExemptKline(client_p) || |
358 |
< |
IsExemptGline(client_p)) |
357 |
> |
if ((conf = find_conf_by_address(client_p->host, &client_p->localClient->ip, |
358 |
> |
CONF_GLINE, client_p->localClient->aftype, |
359 |
> |
client_p->username, NULL, 1))) |
360 |
|
{ |
361 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
362 |
< |
"GLINE over-ruled for %s, client is %sline_exempt", |
364 |
< |
get_client_name(client_p, HIDE_IP), IsExemptKline(client_p) ? "k" : "g"); |
361 |
> |
conf_try_ban(client_p, conf); |
362 |
> |
/* and go examine next fd/client_p */ |
363 |
|
continue; |
364 |
|
} |
365 |
+ |
} |
366 |
|
|
367 |
< |
ban_them(client_p, conf); |
368 |
< |
/* and go examine next fd/client_p */ |
369 |
< |
continue; |
371 |
< |
} |
372 |
< |
|
373 |
< |
if ((conf = find_kill(client_p)) != NULL) |
367 |
> |
if ((conf = find_conf_by_address(client_p->host, &client_p->localClient->ip, |
368 |
> |
CONF_KLINE, client_p->localClient->aftype, |
369 |
> |
client_p->username, NULL, 1))) |
370 |
|
{ |
371 |
< |
if (IsExemptKline(client_p)) |
372 |
< |
{ |
377 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
378 |
< |
"KLINE over-ruled for %s, client is kline_exempt", |
379 |
< |
get_client_name(client_p, HIDE_IP)); |
380 |
< |
continue; |
381 |
< |
} |
382 |
< |
|
383 |
< |
ban_them(client_p, conf); |
384 |
< |
continue; |
371 |
> |
conf_try_ban(client_p, conf); |
372 |
> |
continue; |
373 |
|
} |
374 |
|
|
375 |
|
if ((conf = find_matching_name_conf(CONF_XLINE, client_p->info, |
376 |
< |
NULL, NULL, 0)) != NULL || |
389 |
< |
(conf = find_matching_name_conf(CONF_RXLINE, client_p->info, |
390 |
< |
NULL, NULL, 0)) != NULL) |
376 |
> |
NULL, NULL, 0))) |
377 |
|
{ |
378 |
< |
ban_them(client_p, conf); |
378 |
> |
conf_try_ban(client_p, conf); |
379 |
|
continue; |
380 |
|
} |
381 |
|
} |
382 |
|
|
383 |
|
/* also check the unknowns list for new dlines */ |
384 |
< |
DLINK_FOREACH_SAFE(ptr, next_ptr, unknown_list.head) |
384 |
> |
DLINK_FOREACH_SAFE(ptr, ptr_next, unknown_list.head) |
385 |
|
{ |
386 |
< |
client_p = ptr->data; |
386 |
> |
struct Client *client_p = ptr->data; |
387 |
|
|
388 |
< |
if ((conf = find_dline_conf(&client_p->localClient->ip, |
389 |
< |
client_p->localClient->aftype))) |
388 |
> |
if ((conf = find_conf_by_address(NULL, &client_p->localClient->ip, CONF_DLINE, |
389 |
> |
client_p->localClient->aftype, NULL, NULL, 1))) |
390 |
|
{ |
391 |
< |
if (conf->type == CONF_EXEMPT) |
392 |
< |
continue; |
407 |
< |
|
408 |
< |
exit_client(client_p, &me, "D-lined"); |
391 |
> |
conf_try_ban(client_p, conf); |
392 |
> |
continue; /* and go examine next fd/client_p */ |
393 |
|
} |
394 |
|
} |
395 |
|
} |
396 |
|
|
397 |
|
/* |
398 |
< |
* ban_them |
398 |
> |
* conf_try_ban |
399 |
|
* |
400 |
|
* inputs - pointer to client to ban |
401 |
|
* - pointer to MaskItem |
402 |
|
* output - NONE |
403 |
|
* side effects - given client_p is banned |
404 |
|
*/ |
405 |
< |
static void |
406 |
< |
ban_them(struct Client *client_p, struct MaskItem *conf) |
405 |
> |
void |
406 |
> |
conf_try_ban(struct Client *client_p, struct MaskItem *conf) |
407 |
|
{ |
408 |
< |
const char *user_reason = NULL; /* What is sent to user */ |
408 |
> |
const char *user_reason = NULL; /* What is sent to user */ |
409 |
|
const char *type_string = NULL; |
410 |
|
const char dline_string[] = "D-line"; |
411 |
|
const char kline_string[] = "K-line"; |
414 |
|
|
415 |
|
switch (conf->type) |
416 |
|
{ |
433 |
– |
case CONF_RKLINE: |
417 |
|
case CONF_KLINE: |
418 |
+ |
if (IsExemptKline(client_p)) |
419 |
+ |
{ |
420 |
+ |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
421 |
+ |
"KLINE over-ruled for %s, client is kline_exempt", |
422 |
+ |
get_client_name(client_p, HIDE_IP)); |
423 |
+ |
return; |
424 |
+ |
} |
425 |
+ |
|
426 |
|
type_string = kline_string; |
427 |
|
break; |
428 |
|
case CONF_DLINE: |
429 |
+ |
if (find_conf_by_address(NULL, &client_p->localClient->ip, CONF_EXEMPT, |
430 |
+ |
client_p->localClient->aftype, NULL, NULL, 1)) |
431 |
+ |
return; |
432 |
|
type_string = dline_string; |
433 |
|
break; |
434 |
|
case CONF_GLINE: |
435 |
+ |
if (IsExemptKline(client_p) || |
436 |
+ |
IsExemptGline(client_p)) |
437 |
+ |
{ |
438 |
+ |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
439 |
+ |
"GLINE over-ruled for %s, client is %sline_exempt", |
440 |
+ |
get_client_name(client_p, HIDE_IP), IsExemptKline(client_p) ? "k" : "g"); |
441 |
+ |
return; |
442 |
+ |
} |
443 |
+ |
|
444 |
|
type_string = gline_string; |
445 |
|
break; |
443 |
– |
case CONF_RXLINE: |
446 |
|
case CONF_XLINE: |
447 |
|
type_string = xline_string; |
448 |
|
++conf->count; |
458 |
|
type_string, get_client_name(client_p, HIDE_IP)); |
459 |
|
|
460 |
|
if (IsClient(client_p)) |
461 |
< |
sendto_one(client_p, form_str(ERR_YOUREBANNEDCREEP), |
460 |
< |
me.name, client_p->name, user_reason); |
461 |
> |
sendto_one_numeric(client_p, &me, ERR_YOUREBANNEDCREEP, user_reason); |
462 |
|
|
463 |
< |
exit_client(client_p, &me, user_reason); |
463 |
> |
exit_client(client_p, user_reason); |
464 |
|
} |
465 |
|
|
466 |
|
/* update_client_exit_stats() |
467 |
|
* |
468 |
|
* input - pointer to client |
469 |
|
* output - NONE |
470 |
< |
* side effects - |
470 |
> |
* side effects - |
471 |
|
*/ |
472 |
|
static void |
473 |
|
update_client_exit_stats(struct Client *client_p) |
497 |
|
* side effects - find person by (nick)name |
498 |
|
*/ |
499 |
|
struct Client * |
500 |
< |
find_person(const struct Client *client_p, const char *name) |
500 |
> |
find_person(const struct Client *const source_p, const char *name) |
501 |
|
{ |
502 |
< |
struct Client *c2ptr = NULL; |
502 |
> |
struct Client *target_p = NULL; |
503 |
|
|
504 |
|
if (IsDigit(*name)) |
505 |
|
{ |
506 |
< |
if ((c2ptr = hash_find_id(name)) != NULL) |
507 |
< |
{ |
507 |
< |
/* invisible users shall not be found by UID guessing */ |
508 |
< |
if (HasUMode(c2ptr, UMODE_INVISIBLE)) |
509 |
< |
if (!IsServer(client_p) && !HasFlag(client_p, FLAGS_SERVICE)) |
510 |
< |
c2ptr = NULL; |
511 |
< |
} |
506 |
> |
if (IsServer(source_p->from)) |
507 |
> |
target_p = hash_find_id(name); |
508 |
|
} |
509 |
|
else |
510 |
< |
c2ptr = hash_find_client(name); |
510 |
> |
target_p = hash_find_client(name); |
511 |
|
|
512 |
< |
return ((c2ptr != NULL && IsClient(c2ptr)) ? c2ptr : NULL); |
512 |
> |
return (target_p && IsClient(target_p)) ? target_p : NULL; |
513 |
|
} |
514 |
|
|
515 |
|
/* |
516 |
< |
* find_chasing - find the client structure for a nick name (user) |
517 |
< |
* using history mechanism if necessary. If the client is not found, |
518 |
< |
* an error message (NO SUCH NICK) is generated. If the client was found |
523 |
< |
* through the history, chasing will be 1 and otherwise 0. |
516 |
> |
* find_chasing - find the client structure for a nick name (name) |
517 |
> |
* using history mechanism if necessary. If the client is not found, |
518 |
> |
* an error message (NO SUCH NICK) is generated. |
519 |
|
*/ |
520 |
|
struct Client * |
521 |
< |
find_chasing(struct Client *client_p, struct Client *source_p, const char *user, int *chasing) |
521 |
> |
find_chasing(struct Client *source_p, const char *name) |
522 |
|
{ |
523 |
< |
struct Client *who = find_person(client_p, user); |
529 |
< |
|
530 |
< |
if (chasing) |
531 |
< |
*chasing = 0; |
523 |
> |
struct Client *who = find_person(source_p, name); |
524 |
|
|
525 |
|
if (who) |
526 |
|
return who; |
527 |
|
|
528 |
< |
if (IsDigit(*user)) |
528 |
> |
if (IsDigit(*name)) |
529 |
|
return NULL; |
530 |
|
|
531 |
< |
if ((who = get_history(user, |
532 |
< |
(time_t)ConfigFileEntry.kill_chase_time_limit)) |
533 |
< |
== NULL) |
531 |
> |
if ((who = whowas_get_history(name, |
532 |
> |
(time_t)ConfigFileEntry.kill_chase_time_limit)) |
533 |
> |
== NULL) |
534 |
|
{ |
535 |
< |
sendto_one(source_p, form_str(ERR_NOSUCHNICK), |
544 |
< |
me.name, source_p->name, user); |
535 |
> |
sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, name); |
536 |
|
return NULL; |
537 |
|
} |
538 |
|
|
548 |
– |
if (chasing) |
549 |
– |
*chasing = 1; |
550 |
– |
|
539 |
|
return who; |
540 |
|
} |
541 |
|
|
558 |
|
* to modify what it points!!! |
559 |
|
*/ |
560 |
|
const char * |
561 |
< |
get_client_name(const struct Client *client, enum addr_mask_type type) |
561 |
> |
get_client_name(const struct Client *client_p, enum addr_mask_type type) |
562 |
|
{ |
563 |
|
static char nbuf[HOSTLEN * 2 + USERLEN + 5]; |
564 |
|
|
565 |
< |
assert(client != NULL); |
565 |
> |
assert(client_p); |
566 |
|
|
567 |
< |
if (!MyConnect(client)) |
568 |
< |
return client->name; |
567 |
> |
if (!MyConnect(client_p)) |
568 |
> |
return client_p->name; |
569 |
|
|
570 |
< |
if (IsServer(client) || IsConnecting(client) || IsHandshake(client)) |
570 |
> |
if (IsServer(client_p) || IsConnecting(client_p) || IsHandshake(client_p)) |
571 |
|
{ |
572 |
< |
if (!irccmp(client->name, client->host)) |
573 |
< |
return client->name; |
572 |
> |
if (!irccmp(client_p->name, client_p->host)) |
573 |
> |
return client_p->name; |
574 |
|
else if (ConfigServerHide.hide_server_ips) |
575 |
|
type = MASK_IP; |
576 |
|
} |
577 |
|
|
578 |
|
if (ConfigFileEntry.hide_spoof_ips) |
579 |
< |
if (type == SHOW_IP && IsIPSpoof(client)) |
579 |
> |
if (IsIPSpoof(client_p) && type == SHOW_IP) |
580 |
|
type = MASK_IP; |
581 |
|
|
582 |
|
/* And finally, let's get the host information, ip or name */ |
584 |
|
{ |
585 |
|
case SHOW_IP: |
586 |
|
snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]", |
587 |
< |
client->name, |
588 |
< |
client->username, client->sockhost); |
587 |
> |
client_p->name, |
588 |
> |
client_p->username, client_p->sockhost); |
589 |
|
break; |
590 |
|
case MASK_IP: |
591 |
< |
if (client->localClient->aftype == AF_INET) |
591 |
> |
if (client_p->localClient->aftype == AF_INET) |
592 |
|
snprintf(nbuf, sizeof(nbuf), "%s[%s@255.255.255.255]", |
593 |
< |
client->name, client->username); |
593 |
> |
client_p->name, client_p->username); |
594 |
|
else |
595 |
|
snprintf(nbuf, sizeof(nbuf), "%s[%s@ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]", |
596 |
< |
client->name, client->username); |
596 |
> |
client_p->name, client_p->username); |
597 |
|
break; |
598 |
|
default: |
599 |
|
snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]", |
600 |
< |
client->name, |
601 |
< |
client->username, client->host); |
600 |
> |
client_p->name, |
601 |
> |
client_p->username, client_p->host); |
602 |
|
} |
603 |
|
|
604 |
|
return nbuf; |
608 |
|
free_exited_clients(void) |
609 |
|
{ |
610 |
|
dlink_node *ptr = NULL, *next = NULL; |
611 |
< |
|
611 |
> |
|
612 |
|
DLINK_FOREACH_SAFE(ptr, next, dead_list.head) |
613 |
|
{ |
614 |
|
free_client(ptr->data); |
626 |
|
static void |
627 |
|
exit_one_client(struct Client *source_p, const char *quitmsg) |
628 |
|
{ |
629 |
< |
dlink_node *lp = NULL, *next_lp = NULL; |
629 |
> |
dlink_node *ptr = NULL, *ptr_next = NULL; |
630 |
|
|
631 |
|
assert(!IsMe(source_p)); |
632 |
|
|
633 |
|
if (IsClient(source_p)) |
634 |
|
{ |
635 |
< |
if (source_p->servptr->serv != NULL) |
648 |
< |
dlinkDelete(&source_p->lnode, &source_p->servptr->serv->client_list); |
635 |
> |
dlinkDelete(&source_p->lnode, &source_p->servptr->serv->client_list); |
636 |
|
|
637 |
|
/* |
638 |
|
* If a person is on a channel, send a QUIT notice |
640 |
|
* that the client can show the "**signoff" message). |
641 |
|
* (Note: The notice is to the local clients *only*) |
642 |
|
*/ |
643 |
< |
sendto_common_channels_local(source_p, 0, ":%s!%s@%s QUIT :%s", |
643 |
> |
sendto_common_channels_local(source_p, 0, 0, ":%s!%s@%s QUIT :%s", |
644 |
|
source_p->name, source_p->username, |
645 |
|
source_p->host, quitmsg); |
646 |
< |
DLINK_FOREACH_SAFE(lp, next_lp, source_p->channel.head) |
647 |
< |
remove_user_from_channel(lp->data); |
646 |
> |
DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->channel.head) |
647 |
> |
remove_user_from_channel(ptr->data); |
648 |
|
|
649 |
< |
add_history(source_p, 0); |
650 |
< |
off_history(source_p); |
649 |
> |
whowas_add_history(source_p, 0); |
650 |
> |
whowas_off_history(source_p); |
651 |
|
|
652 |
|
watch_check_hash(source_p, RPL_LOGOFF); |
653 |
|
|
654 |
|
if (MyConnect(source_p)) |
655 |
|
{ |
656 |
|
/* Clean up invitefield */ |
657 |
< |
DLINK_FOREACH_SAFE(lp, next_lp, source_p->localClient->invited.head) |
658 |
< |
del_invite(lp->data, source_p); |
657 |
> |
DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->localClient->invited.head) |
658 |
> |
del_invite(ptr->data, source_p); |
659 |
|
|
660 |
|
del_all_accepts(source_p); |
661 |
|
} |
664 |
|
{ |
665 |
|
dlinkDelete(&source_p->lnode, &source_p->servptr->serv->server_list); |
666 |
|
|
667 |
< |
if ((lp = dlinkFindDelete(&global_serv_list, source_p)) != NULL) |
668 |
< |
free_dlink_node(lp); |
667 |
> |
if ((ptr = dlinkFindDelete(&global_serv_list, source_p))) |
668 |
> |
free_dlink_node(ptr); |
669 |
|
} |
670 |
|
|
671 |
|
/* Remove source_p from the client lists */ |
672 |
< |
if (HasID(source_p)) |
672 |
> |
if (source_p->id[0]) |
673 |
|
hash_del_id(source_p); |
674 |
|
if (source_p->name[0]) |
675 |
|
hash_del_client(source_p); |
677 |
|
if (IsUserHostIp(source_p)) |
678 |
|
delete_user_host(source_p->username, source_p->host, !MyConnect(source_p)); |
679 |
|
|
680 |
< |
/* remove from global client list |
694 |
< |
* NOTE: source_p->node.next cannot be NULL if the client is added |
695 |
< |
* to global_client_list (there is always &me at its end) |
696 |
< |
*/ |
697 |
< |
if (source_p != NULL && source_p->node.next != NULL) |
680 |
> |
if (source_p->node.next) |
681 |
|
dlinkDelete(&source_p->node, &global_client_list); |
682 |
|
|
683 |
|
update_client_exit_stats(source_p); |
690 |
|
dlinkAdd(source_p, make_dlink_node(), &dead_list); |
691 |
|
} |
692 |
|
|
693 |
< |
/* Recursively send QUITs and SQUITs for source_p and all its dependent clients |
711 |
< |
* and servers to those servers that need them. A server needs the client |
712 |
< |
* QUITs if it can't figure them out from the SQUIT (ie pre-TS4) or if it |
713 |
< |
* isn't getting the SQUIT because of @#(*&@)# hostmasking. With TS4, once |
714 |
< |
* a link gets a SQUIT, it doesn't need any QUIT/SQUITs for clients depending |
715 |
< |
* on that one -orabidoo |
716 |
< |
* |
717 |
< |
* This is now called on each local server -adx |
718 |
< |
*/ |
719 |
< |
static void |
720 |
< |
recurse_send_quits(struct Client *original_source_p, struct Client *source_p, |
721 |
< |
struct Client *from, struct Client *to, const char *comment, |
722 |
< |
const char *splitstr) |
723 |
< |
{ |
724 |
< |
dlink_node *ptr, *next; |
725 |
< |
struct Client *target_p; |
726 |
< |
|
727 |
< |
assert(to != source_p); /* should be already removed from serv_list */ |
728 |
< |
|
729 |
< |
/* If this server can handle quit storm (QS) removal |
730 |
< |
* of dependents, just send the SQUIT |
731 |
< |
*/ |
732 |
< |
if (!IsCapable(to, CAP_QS)) |
733 |
< |
DLINK_FOREACH_SAFE(ptr, next, source_p->serv->client_list.head) |
734 |
< |
{ |
735 |
< |
target_p = ptr->data; |
736 |
< |
sendto_one(to, ":%s QUIT :%s", target_p->name, splitstr); |
737 |
< |
} |
738 |
< |
|
739 |
< |
DLINK_FOREACH_SAFE(ptr, next, source_p->serv->server_list.head) |
740 |
< |
recurse_send_quits(original_source_p, ptr->data, from, to, |
741 |
< |
comment, splitstr); |
742 |
< |
|
743 |
< |
if ((source_p == original_source_p && to != from) || |
744 |
< |
!IsCapable(to, CAP_QS)) |
745 |
< |
{ |
746 |
< |
/* don't use a prefix here - we have to be 100% sure the message |
747 |
< |
* will be accepted without Unknown prefix etc.. */ |
748 |
< |
sendto_one(to, "SQUIT %s :%s", ID_or_name(source_p, to), comment); |
749 |
< |
} |
750 |
< |
} |
751 |
< |
|
752 |
< |
/* |
693 |
> |
/* |
694 |
|
* Remove all clients that depend on source_p; assumes all (S)QUITs have |
695 |
< |
* already been sent. we make sure to exit a server's dependent clients |
696 |
< |
* and servers before the server itself; exit_one_client takes care of |
695 |
> |
* already been sent. we make sure to exit a server's dependent clients |
696 |
> |
* and servers before the server itself; exit_one_client takes care of |
697 |
|
* actually removing things off llists. tweaked from +CSr31 -orabidoo |
698 |
|
*/ |
699 |
|
static void |
700 |
|
recurse_remove_clients(struct Client *source_p, const char *quitmsg) |
701 |
|
{ |
702 |
< |
dlink_node *ptr, *next; |
702 |
> |
dlink_node *ptr = NULL, *ptr_next = NULL; |
703 |
|
|
704 |
< |
DLINK_FOREACH_SAFE(ptr, next, source_p->serv->client_list.head) |
704 |
> |
DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->serv->client_list.head) |
705 |
|
exit_one_client(ptr->data, quitmsg); |
706 |
|
|
707 |
< |
DLINK_FOREACH_SAFE(ptr, next, source_p->serv->server_list.head) |
707 |
> |
DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->serv->server_list.head) |
708 |
|
{ |
709 |
|
recurse_remove_clients(ptr->data, quitmsg); |
710 |
|
exit_one_client(ptr->data, quitmsg); |
712 |
|
} |
713 |
|
|
714 |
|
/* |
774 |
– |
** Remove *everything* that depends on source_p, from all lists, and sending |
775 |
– |
** all necessary QUITs and SQUITs. source_p itself is still on the lists, |
776 |
– |
** and its SQUITs have been sent except for the upstream one -orabidoo |
777 |
– |
*/ |
778 |
– |
static void |
779 |
– |
remove_dependents(struct Client *source_p, struct Client *from, |
780 |
– |
const char *comment, const char *splitstr) |
781 |
– |
{ |
782 |
– |
dlink_node *ptr = NULL; |
783 |
– |
|
784 |
– |
DLINK_FOREACH(ptr, serv_list.head) |
785 |
– |
recurse_send_quits(source_p, source_p, from, ptr->data, |
786 |
– |
comment, splitstr); |
787 |
– |
|
788 |
– |
recurse_remove_clients(source_p, splitstr); |
789 |
– |
} |
790 |
– |
|
791 |
– |
/* |
715 |
|
* exit_client - exit a client of any type. Generally, you can use |
716 |
|
* this on any struct Client, regardless of its state. |
717 |
|
* |
718 |
|
* Note, you shouldn't exit remote _users_ without first doing |
719 |
|
* AddFlag(x, FLAGS_KILLED) and propagating a kill or similar message. |
720 |
+ |
* |
721 |
|
* However, it is perfectly correct to call exit_client to force a _server_ |
722 |
|
* quit (either local or remote one). |
723 |
|
* |
724 |
+ |
* |
725 |
|
* inputs: - a client pointer that is going to be exited |
801 |
– |
* - for servers, the second argument is a pointer to who |
802 |
– |
* is firing the server. This side won't get any generated |
803 |
– |
* messages. NEVER NULL! |
726 |
|
* output: none |
727 |
|
* side effects: the client is delinked from all lists, disconnected, |
728 |
|
* and the rest of IRC network is notified of the exit. |
729 |
|
* Client memory is scheduled to be freed |
730 |
|
*/ |
731 |
|
void |
732 |
< |
exit_client(struct Client *source_p, struct Client *from, const char *comment) |
732 |
> |
exit_client(struct Client *source_p, const char *comment) |
733 |
|
{ |
734 |
|
dlink_node *m = NULL; |
735 |
|
|
746 |
|
if (IsIpHash(source_p)) |
747 |
|
remove_one_ip(&source_p->localClient->ip); |
748 |
|
|
749 |
< |
if (source_p->localClient->auth) |
828 |
< |
{ |
829 |
< |
delete_auth(source_p->localClient->auth); |
830 |
< |
source_p->localClient->auth = NULL; |
831 |
< |
} |
749 |
> |
delete_auth(&source_p->localClient->auth); |
750 |
|
|
751 |
|
/* |
752 |
|
* This source_p could have status of one of STAT_UNKNOWN, STAT_CONNECTING |
768 |
|
Count.local--; |
769 |
|
|
770 |
|
if (HasUMode(source_p, UMODE_OPER)) |
771 |
< |
if ((m = dlinkFindDelete(&oper_list, source_p)) != NULL) |
771 |
> |
if ((m = dlinkFindDelete(&oper_list, source_p))) |
772 |
|
free_dlink_node(m); |
773 |
|
|
774 |
|
assert(dlinkFind(&local_client_list, source_p)); |
775 |
|
dlinkDelete(&source_p->localClient->lclient_node, &local_client_list); |
776 |
|
|
777 |
< |
if (source_p->localClient->list_task != NULL) |
778 |
< |
free_list_task(source_p->localClient->list_task, source_p); |
777 |
> |
if (source_p->localClient->list_task) |
778 |
> |
free_list_task(source_p); |
779 |
|
|
780 |
|
watch_del_watch_list(source_p); |
781 |
|
sendto_realops_flags(UMODE_CCONN, L_ALL, SEND_NOTICE, |
783 |
|
source_p->name, source_p->username, source_p->host, comment, |
784 |
|
ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ? |
785 |
|
"255.255.255.255" : source_p->sockhost); |
868 |
– |
sendto_realops_flags(UMODE_CCONN_FULL, L_ALL, SEND_NOTICE, |
869 |
– |
"CLIEXIT: %s %s %s %s 0 %s", |
870 |
– |
source_p->name, |
871 |
– |
source_p->username, |
872 |
– |
source_p->host, |
873 |
– |
ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ? |
874 |
– |
"255.255.255.255" : source_p->sockhost, |
875 |
– |
comment); |
786 |
|
ilog(LOG_TYPE_USER, "%s (%3u:%02u:%02u): %s!%s@%s %llu/%llu", |
787 |
|
myctime(source_p->localClient->firsttime), (unsigned int)(on_for / 3600), |
788 |
|
(unsigned int)((on_for % 3600)/60), (unsigned int)(on_for % 60), |
797 |
|
|
798 |
|
assert(dlinkFind(&serv_list, source_p)); |
799 |
|
dlinkDelete(&source_p->localClient->lclient_node, &serv_list); |
890 |
– |
unset_chcap_usage_counts(source_p); |
800 |
|
} |
801 |
|
|
802 |
|
if (!IsDead(source_p)) |
803 |
|
{ |
804 |
|
if (IsServer(source_p)) |
805 |
|
{ |
806 |
< |
/* for them, we are exiting the network */ |
807 |
< |
sendto_one(source_p, ":%s SQUIT %s :%s", |
808 |
< |
ID_or_name(from, source_p), me.name, comment); |
806 |
> |
if (!HasFlag(source_p, FLAGS_SQUIT)) |
807 |
> |
{ |
808 |
> |
/* for them, we are exiting the network */ |
809 |
> |
sendto_one(source_p, ":%s SQUIT %s :%s", |
810 |
> |
me.id, me.id, comment); |
811 |
> |
} |
812 |
|
} |
813 |
|
|
814 |
|
sendto_one(source_p, "ERROR :Closing Link: %s (%s)", |
815 |
|
source_p->host, comment); |
816 |
|
} |
817 |
|
|
906 |
– |
/* |
907 |
– |
** Currently only server connections can have |
908 |
– |
** depending remote clients here, but it does no |
909 |
– |
** harm to check for all local clients. In |
910 |
– |
** future some other clients than servers might |
911 |
– |
** have remotes too... |
912 |
– |
** |
913 |
– |
** Close the Client connection first and mark it |
914 |
– |
** so that no messages are attempted to send to it. |
915 |
– |
** Remember it makes source_p->from == NULL. |
916 |
– |
*/ |
818 |
|
close_connection(source_p); |
819 |
|
} |
820 |
+ |
else if (IsClient(source_p) && HasFlag(source_p->servptr, FLAGS_EOB)) |
821 |
+ |
sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE, |
822 |
+ |
"Client exiting at %s: %s (%s@%s) [%s]", |
823 |
+ |
source_p->servptr->name, source_p->name, |
824 |
+ |
source_p->username, source_p->host, comment); |
825 |
|
|
826 |
|
if (IsServer(source_p)) |
827 |
|
{ |
828 |
< |
char splitstr[HOSTLEN + HOSTLEN + 2]; |
828 |
> |
char splitstr[HOSTLEN + HOSTLEN + 2] = ""; |
829 |
|
|
830 |
|
/* This shouldn't ever happen */ |
831 |
< |
assert(source_p->serv != NULL && source_p->servptr != NULL); |
831 |
> |
assert(source_p->serv && source_p->servptr); |
832 |
|
|
833 |
|
if (ConfigServerHide.hide_servers) |
834 |
|
/* |
835 |
< |
* Set netsplit message to "*.net *.split" to still show |
835 |
> |
* Set netsplit message to "*.net *.split" to still show |
836 |
|
* that its a split, but hide the servers splitting |
837 |
|
*/ |
838 |
< |
strcpy(splitstr, "*.net *.split"); |
838 |
> |
strlcpy(splitstr, "*.net *.split", sizeof(splitstr)); |
839 |
|
else |
840 |
|
snprintf(splitstr, sizeof(splitstr), "%s %s", |
841 |
|
source_p->servptr->name, source_p->name); |
842 |
|
|
843 |
< |
remove_dependents(source_p, from->from, comment, splitstr); |
843 |
> |
/* Send SQUIT for source_p in every direction. source_p is already off of serv_list here */ |
844 |
> |
if (!HasFlag(source_p, FLAGS_SQUIT)) |
845 |
> |
sendto_server(NULL, NOCAPS, NOCAPS, "SQUIT %s :%s", source_p->id, comment); |
846 |
> |
|
847 |
> |
/* Now exit the clients internally */ |
848 |
> |
recurse_remove_clients(source_p, splitstr); |
849 |
|
|
850 |
< |
if (source_p->servptr == &me) |
850 |
> |
if (MyConnect(source_p)) |
851 |
|
{ |
852 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
853 |
|
"%s was connected for %d seconds. %llu/%llu sendK/recvK.", |
855 |
|
source_p->localClient->send.bytes >> 10, |
856 |
|
source_p->localClient->recv.bytes >> 10); |
857 |
|
ilog(LOG_TYPE_IRCD, "%s was connected for %d seconds. %llu/%llu sendK/recvK.", |
858 |
< |
source_p->name, (int)(CurrentTime - source_p->localClient->firsttime), |
858 |
> |
source_p->name, (int)(CurrentTime - source_p->localClient->firsttime), |
859 |
|
source_p->localClient->send.bytes >> 10, |
860 |
|
source_p->localClient->recv.bytes >> 10); |
861 |
|
} |
862 |
|
} |
863 |
|
else if (IsClient(source_p) && !HasFlag(source_p, FLAGS_KILLED)) |
864 |
< |
{ |
865 |
< |
sendto_server(from->from, CAP_TS6, NOCAPS, |
955 |
< |
":%s QUIT :%s", ID(source_p), comment); |
956 |
< |
sendto_server(from->from, NOCAPS, CAP_TS6, |
957 |
< |
":%s QUIT :%s", source_p->name, comment); |
958 |
< |
} |
864 |
> |
sendto_server(source_p->from, NOCAPS, NOCAPS, ":%s QUIT :%s", |
865 |
> |
source_p->id, comment); |
866 |
|
|
867 |
|
/* The client *better* be off all of the lists */ |
868 |
|
assert(dlinkFind(&unknown_list, source_p) == NULL); |
906 |
|
void |
907 |
|
dead_link_on_read(struct Client *client_p, int error) |
908 |
|
{ |
909 |
< |
char errmsg[255]; |
909 |
> |
char errmsg[IRCD_BUFSIZE]; |
910 |
|
int current_error; |
911 |
|
|
912 |
|
if (IsDefunct(client_p)) |
920 |
|
if (IsServer(client_p) || IsHandshake(client_p)) |
921 |
|
{ |
922 |
|
int connected = CurrentTime - client_p->localClient->firsttime; |
923 |
< |
|
923 |
> |
|
924 |
|
if (error == 0) |
925 |
|
{ |
926 |
|
/* Admins get the real IP */ |
927 |
|
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
928 |
< |
"Server %s closed the connection", |
929 |
< |
get_client_name(client_p, SHOW_IP)); |
928 |
> |
"Server %s closed the connection", |
929 |
> |
get_client_name(client_p, SHOW_IP)); |
930 |
|
|
931 |
|
/* Opers get a masked IP */ |
932 |
|
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
933 |
< |
"Server %s closed the connection", |
934 |
< |
get_client_name(client_p, MASK_IP)); |
933 |
> |
"Server %s closed the connection", |
934 |
> |
get_client_name(client_p, MASK_IP)); |
935 |
|
|
936 |
|
ilog(LOG_TYPE_IRCD, "Server %s closed the connection", |
937 |
< |
get_client_name(client_p, SHOW_IP)); |
937 |
> |
get_client_name(client_p, SHOW_IP)); |
938 |
|
} |
939 |
|
else |
940 |
|
{ |
941 |
|
report_error(L_ADMIN, "Lost connection to %s: %s", |
942 |
< |
get_client_name(client_p, SHOW_IP), current_error); |
942 |
> |
get_client_name(client_p, SHOW_IP), current_error); |
943 |
|
report_error(L_OPER, "Lost connection to %s: %s", |
944 |
< |
get_client_name(client_p, MASK_IP), current_error); |
944 |
> |
get_client_name(client_p, MASK_IP), current_error); |
945 |
|
} |
946 |
|
|
947 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
948 |
< |
"%s had been connected for %d day%s, %2d:%02d:%02d", |
949 |
< |
client_p->name, connected/86400, |
950 |
< |
(connected/86400 == 1) ? "" : "s", |
951 |
< |
(connected % 86400) / 3600, (connected % 3600) / 60, |
952 |
< |
connected % 60); |
948 |
> |
"%s had been connected for %d day%s, %2d:%02d:%02d", |
949 |
> |
client_p->name, connected/86400, |
950 |
> |
(connected/86400 == 1) ? "" : "s", |
951 |
> |
(connected % 86400) / 3600, (connected % 3600) / 60, |
952 |
> |
connected % 60); |
953 |
|
} |
954 |
|
|
955 |
|
if (error == 0) |
959 |
|
snprintf(errmsg, sizeof(errmsg), "Read error: %s", |
960 |
|
strerror(current_error)); |
961 |
|
|
962 |
< |
exit_client(client_p, &me, errmsg); |
962 |
> |
exit_client(client_p, errmsg); |
963 |
|
} |
964 |
|
|
965 |
|
void |
990 |
|
else |
991 |
|
notice = "Write error: connection closed"; |
992 |
|
|
993 |
< |
exit_client(target_p, &me, notice); |
993 |
> |
exit_client(target_p, notice); |
994 |
|
free_dlink_node(ptr); |
995 |
|
} |
996 |
|
} |
1018 |
|
|
1019 |
|
struct split_nuh_item * |
1020 |
|
find_accept(const char *nick, const char *user, |
1021 |
< |
const char *host, struct Client *client_p, int do_match) |
1021 |
> |
const char *host, struct Client *client_p, |
1022 |
> |
int (*cmpfunc)(const char *, const char *)) |
1023 |
|
{ |
1024 |
|
dlink_node *ptr = NULL; |
1117 |
– |
/* XXX We wouldn't need that if match() would return 0 on match */ |
1118 |
– |
int (*cmpfunc)(const char *, const char *) = do_match ? match : irccmp; |
1025 |
|
|
1026 |
|
DLINK_FOREACH(ptr, client_p->localClient->acceptlist.head) |
1027 |
|
{ |
1028 |
|
struct split_nuh_item *accept_p = ptr->data; |
1029 |
|
|
1030 |
< |
if (cmpfunc(accept_p->nickptr, nick) == do_match && |
1031 |
< |
cmpfunc(accept_p->userptr, user) == do_match && |
1032 |
< |
cmpfunc(accept_p->hostptr, host) == do_match) |
1030 |
> |
if (!cmpfunc(accept_p->nickptr, nick) && |
1031 |
> |
!cmpfunc(accept_p->userptr, user) && |
1032 |
> |
!cmpfunc(accept_p->hostptr, host)) |
1033 |
|
return accept_p; |
1034 |
|
} |
1035 |
|
|
1050 |
|
dlink_node *ptr = NULL; |
1051 |
|
|
1052 |
|
if (source == target || find_accept(source->name, source->username, |
1053 |
< |
source->host, target, 1)) |
1053 |
> |
source->host, target, match)) |
1054 |
|
return 1; |
1055 |
|
|
1056 |
|
if (HasUMode(target, UMODE_SOFTCALLERID)) |
1070 |
|
void |
1071 |
|
del_all_accepts(struct Client *client_p) |
1072 |
|
{ |
1073 |
< |
dlink_node *ptr = NULL, *next_ptr = NULL; |
1073 |
> |
dlink_node *ptr = NULL, *ptr_next = NULL; |
1074 |
|
|
1075 |
< |
DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->acceptlist.head) |
1075 |
> |
DLINK_FOREACH_SAFE(ptr, ptr_next, client_p->localClient->acceptlist.head) |
1076 |
|
del_accept(ptr->data, client_p); |
1077 |
|
} |
1078 |
+ |
|
1079 |
+ |
unsigned int |
1080 |
+ |
idle_time_get(const struct Client *source_p, const struct Client *target_p) |
1081 |
+ |
{ |
1082 |
+ |
unsigned int idle = 0; |
1083 |
+ |
unsigned int min_idle = 0; |
1084 |
+ |
unsigned int max_idle = 0; |
1085 |
+ |
const struct ClassItem *class = get_class_ptr(&target_p->localClient->confs); |
1086 |
+ |
|
1087 |
+ |
if (!(class->flags & CLASS_FLAGS_FAKE_IDLE) || target_p == source_p) |
1088 |
+ |
return CurrentTime - target_p->localClient->last_privmsg; |
1089 |
+ |
if (HasUMode(source_p, UMODE_OPER) && |
1090 |
+ |
!(class->flags & CLASS_FLAGS_HIDE_IDLE_FROM_OPERS)) |
1091 |
+ |
return CurrentTime - target_p->localClient->last_privmsg; |
1092 |
+ |
|
1093 |
+ |
min_idle = class->min_idle; |
1094 |
+ |
max_idle = class->max_idle; |
1095 |
+ |
|
1096 |
+ |
if (min_idle == max_idle) |
1097 |
+ |
return min_idle; |
1098 |
+ |
|
1099 |
+ |
if (class->flags & CLASS_FLAGS_RANDOM_IDLE) |
1100 |
+ |
idle = genrand_int32(); |
1101 |
+ |
else |
1102 |
+ |
idle = CurrentTime - target_p->localClient->last_privmsg; |
1103 |
+ |
|
1104 |
+ |
if (!max_idle) |
1105 |
+ |
idle = 0; |
1106 |
+ |
else |
1107 |
+ |
idle %= max_idle; |
1108 |
+ |
|
1109 |
+ |
if (idle < min_idle) |
1110 |
+ |
idle = min_idle + (idle % (max_idle - min_idle)); |
1111 |
+ |
|
1112 |
+ |
return idle; |
1113 |
+ |
} |