1 |
adx |
30 |
/* |
2 |
|
|
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
|
|
* client.c: Controls clients. |
4 |
|
|
* |
5 |
|
|
* Copyright (C) 2002 by the past and present ircd coders, and others. |
6 |
|
|
* |
7 |
|
|
* This program is free software; you can redistribute it and/or modify |
8 |
|
|
* it under the terms of the GNU General Public License as published by |
9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
10 |
|
|
* (at your option) any later version. |
11 |
|
|
* |
12 |
|
|
* This program is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with this program; if not, write to the Free Software |
19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
|
|
* USA |
21 |
|
|
* |
22 |
knight |
31 |
* $Id$ |
23 |
adx |
30 |
*/ |
24 |
|
|
|
25 |
|
|
#include "stdinc.h" |
26 |
michael |
1011 |
#include "list.h" |
27 |
adx |
30 |
#include "client.h" |
28 |
|
|
#include "channel_mode.h" |
29 |
|
|
#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" |
35 |
|
|
#include "numeric.h" |
36 |
|
|
#include "packet.h" |
37 |
|
|
#include "s_auth.h" |
38 |
|
|
#include "s_bsd.h" |
39 |
michael |
1309 |
#include "conf.h" |
40 |
|
|
#include "log.h" |
41 |
adx |
30 |
#include "s_misc.h" |
42 |
|
|
#include "s_serv.h" |
43 |
|
|
#include "send.h" |
44 |
|
|
#include "whowas.h" |
45 |
|
|
#include "s_user.h" |
46 |
|
|
#include "dbuf.h" |
47 |
|
|
#include "memory.h" |
48 |
|
|
#include "hostmask.h" |
49 |
|
|
#include "balloc.h" |
50 |
|
|
#include "listener.h" |
51 |
|
|
#include "irc_res.h" |
52 |
|
|
#include "userhost.h" |
53 |
michael |
876 |
#include "watch.h" |
54 |
adx |
30 |
|
55 |
|
|
dlink_list listing_client_list = { NULL, NULL, 0 }; |
56 |
|
|
/* Pointer to beginning of Client list */ |
57 |
|
|
dlink_list global_client_list = {NULL, NULL, 0}; |
58 |
|
|
/* unknown/client pointer lists */ |
59 |
|
|
dlink_list unknown_list = {NULL, NULL, 0}; |
60 |
|
|
dlink_list local_client_list = {NULL, NULL, 0}; |
61 |
|
|
dlink_list serv_list = {NULL, NULL, 0}; |
62 |
|
|
dlink_list global_serv_list = {NULL, NULL, 0}; |
63 |
|
|
dlink_list oper_list = {NULL, NULL, 0}; |
64 |
|
|
|
65 |
|
|
static EVH check_pings; |
66 |
|
|
|
67 |
|
|
static BlockHeap *client_heap = NULL; |
68 |
|
|
static BlockHeap *lclient_heap = NULL; |
69 |
|
|
|
70 |
|
|
static dlink_list dead_list = { NULL, NULL, 0}; |
71 |
|
|
static dlink_list abort_list = { NULL, NULL, 0}; |
72 |
|
|
|
73 |
|
|
static dlink_node *eac_next; /* next aborted client to exit */ |
74 |
|
|
|
75 |
|
|
static void check_pings_list(dlink_list *); |
76 |
|
|
static void check_unknowns_list(void); |
77 |
michael |
1124 |
static void ban_them(struct Client *, struct ConfItem *); |
78 |
adx |
30 |
|
79 |
|
|
|
80 |
|
|
/* init_client() |
81 |
|
|
* |
82 |
|
|
* inputs - NONE |
83 |
|
|
* output - NONE |
84 |
|
|
* side effects - initialize client free memory |
85 |
|
|
*/ |
86 |
|
|
void |
87 |
|
|
init_client(void) |
88 |
|
|
{ |
89 |
|
|
/* start off the check ping event .. -- adrian |
90 |
|
|
* Every 30 seconds is plenty -- db |
91 |
|
|
*/ |
92 |
|
|
client_heap = BlockHeapCreate("client", sizeof(struct Client), CLIENT_HEAP_SIZE); |
93 |
|
|
lclient_heap = BlockHeapCreate("local client", sizeof(struct LocalUser), LCLIENT_HEAP_SIZE); |
94 |
|
|
eventAdd("check_pings", check_pings, NULL, 5); |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
/* |
98 |
|
|
* make_client - create a new Client struct and set it to initial state. |
99 |
|
|
* |
100 |
|
|
* from == NULL, create local client (a client connected |
101 |
|
|
* to a socket). |
102 |
|
|
* WARNING: This leaves the client in a dangerous |
103 |
|
|
* state where fd == -1, dead flag is not set and |
104 |
|
|
* the client is on the unknown_list; therefore, |
105 |
|
|
* the first thing to do after calling make_client(NULL) |
106 |
|
|
* is setting fd to something reasonable. -adx |
107 |
|
|
* |
108 |
|
|
* from, create remote client (behind a socket |
109 |
|
|
* associated with the client defined by |
110 |
|
|
* 'from'). ('from' is a local client!!). |
111 |
|
|
*/ |
112 |
|
|
struct Client * |
113 |
|
|
make_client(struct Client *from) |
114 |
|
|
{ |
115 |
|
|
struct Client *client_p = BlockHeapAlloc(client_heap); |
116 |
|
|
|
117 |
|
|
if (from == NULL) |
118 |
|
|
{ |
119 |
michael |
1241 |
client_p->from = client_p; /* 'from' of local client is self! */ |
120 |
|
|
client_p->localClient = BlockHeapAlloc(lclient_heap); |
121 |
|
|
client_p->localClient->since = CurrentTime; |
122 |
|
|
client_p->localClient->lasttime = CurrentTime; |
123 |
|
|
client_p->localClient->firsttime = CurrentTime; |
124 |
|
|
client_p->localClient->registration = REG_INIT; |
125 |
adx |
30 |
|
126 |
|
|
/* as good a place as any... */ |
127 |
michael |
1126 |
dlinkAdd(client_p, &client_p->localClient->lclient_node, &unknown_list); |
128 |
adx |
30 |
} |
129 |
|
|
else |
130 |
|
|
client_p->from = from; /* 'from' of local client is self! */ |
131 |
|
|
|
132 |
michael |
1360 |
client_p->idhnext = client_p; |
133 |
adx |
30 |
client_p->hnext = client_p; |
134 |
|
|
client_p->status = STAT_UNKNOWN; |
135 |
|
|
strcpy(client_p->username, "unknown"); |
136 |
|
|
|
137 |
|
|
return client_p; |
138 |
|
|
} |
139 |
|
|
|
140 |
|
|
/* |
141 |
|
|
* free_client |
142 |
|
|
* |
143 |
|
|
* inputs - pointer to client |
144 |
|
|
* output - NONE |
145 |
|
|
* side effects - client pointed to has its memory freed |
146 |
|
|
*/ |
147 |
|
|
static void |
148 |
|
|
free_client(struct Client *client_p) |
149 |
|
|
{ |
150 |
|
|
assert(client_p != NULL); |
151 |
|
|
assert(client_p != &me); |
152 |
|
|
assert(client_p->hnext == client_p); |
153 |
michael |
1360 |
assert(client_p->idhnext == client_p); |
154 |
adx |
30 |
assert(client_p->channel.head == NULL); |
155 |
|
|
assert(dlink_list_length(&client_p->channel) == 0); |
156 |
michael |
1360 |
assert(dlink_list_length(&client_p->whowas) == 0); |
157 |
|
|
assert(!IsServer(client_p) || IsServer(client_p) && client_p->serv); |
158 |
adx |
30 |
|
159 |
|
|
MyFree(client_p->serv); |
160 |
|
|
|
161 |
|
|
if (MyConnect(client_p)) |
162 |
|
|
{ |
163 |
michael |
317 |
assert(client_p->localClient->invited.head == NULL); |
164 |
|
|
assert(dlink_list_length(&client_p->localClient->invited) == 0); |
165 |
michael |
1360 |
assert(dlink_list_length(&client_p->localClient->watches) == 0); |
166 |
adx |
30 |
assert(IsClosing(client_p) && IsDead(client_p)); |
167 |
|
|
|
168 |
|
|
MyFree(client_p->localClient->response); |
169 |
|
|
MyFree(client_p->localClient->auth_oper); |
170 |
|
|
|
171 |
|
|
/* |
172 |
|
|
* clean up extra sockets from P-lines which have been discarded. |
173 |
|
|
*/ |
174 |
|
|
if (client_p->localClient->listener) |
175 |
|
|
{ |
176 |
|
|
assert(0 < client_p->localClient->listener->ref_count); |
177 |
|
|
if (0 == --client_p->localClient->listener->ref_count && |
178 |
|
|
!client_p->localClient->listener->active) |
179 |
|
|
free_listener(client_p->localClient->listener); |
180 |
|
|
} |
181 |
|
|
|
182 |
|
|
dbuf_clear(&client_p->localClient->buf_recvq); |
183 |
|
|
dbuf_clear(&client_p->localClient->buf_sendq); |
184 |
|
|
|
185 |
|
|
BlockHeapFree(lclient_heap, client_p->localClient); |
186 |
|
|
} |
187 |
|
|
|
188 |
|
|
BlockHeapFree(client_heap, client_p); |
189 |
|
|
} |
190 |
|
|
|
191 |
|
|
/* |
192 |
|
|
* check_pings - go through the local client list and check activity |
193 |
|
|
* kill off stuff that should die |
194 |
|
|
* |
195 |
|
|
* inputs - NOT USED (from event) |
196 |
|
|
* output - next time_t when check_pings() should be called again |
197 |
|
|
* side effects - |
198 |
|
|
* |
199 |
|
|
* |
200 |
|
|
* A PING can be sent to clients as necessary. |
201 |
|
|
* |
202 |
|
|
* Client/Server ping outs are handled. |
203 |
|
|
*/ |
204 |
|
|
|
205 |
|
|
/* |
206 |
|
|
* Addon from adrian. We used to call this after nextping seconds, |
207 |
|
|
* however I've changed it to run once a second. This is only for |
208 |
|
|
* PING timeouts, not K/etc-line checks (thanks dianora!). Having it |
209 |
|
|
* run once a second makes life a lot easier - when a new client connects |
210 |
|
|
* and they need a ping in 4 seconds, if nextping was set to 20 seconds |
211 |
|
|
* we end up waiting 20 seconds. This is stupid. :-) |
212 |
|
|
* I will optimise (hah!) check_pings() once I've finished working on |
213 |
|
|
* tidying up other network IO evilnesses. |
214 |
|
|
* -- adrian |
215 |
|
|
*/ |
216 |
|
|
|
217 |
|
|
static void |
218 |
|
|
check_pings(void *notused) |
219 |
|
|
{ |
220 |
|
|
check_pings_list(&local_client_list); |
221 |
|
|
check_pings_list(&serv_list); |
222 |
|
|
check_unknowns_list(); |
223 |
|
|
} |
224 |
|
|
|
225 |
|
|
/* check_pings_list() |
226 |
|
|
* |
227 |
|
|
* inputs - pointer to list to check |
228 |
|
|
* output - NONE |
229 |
|
|
* side effects - |
230 |
|
|
*/ |
231 |
|
|
static void |
232 |
|
|
check_pings_list(dlink_list *list) |
233 |
|
|
{ |
234 |
|
|
char scratch[32]; /* way too generous but... */ |
235 |
|
|
struct Client *client_p; /* current local client_p being examined */ |
236 |
|
|
int ping, pingwarn; /* ping time value from client */ |
237 |
|
|
dlink_node *ptr, *next_ptr; |
238 |
|
|
|
239 |
|
|
DLINK_FOREACH_SAFE(ptr, next_ptr, list->head) |
240 |
|
|
{ |
241 |
|
|
client_p = ptr->data; |
242 |
|
|
|
243 |
|
|
/* |
244 |
|
|
** Note: No need to notify opers here. It's |
245 |
|
|
** already done when "FLAGS_DEADSOCKET" is set. |
246 |
|
|
*/ |
247 |
|
|
if (IsDead(client_p)) |
248 |
|
|
{ |
249 |
|
|
/* Ignore it, its been exited already */ |
250 |
|
|
continue; |
251 |
|
|
} |
252 |
|
|
|
253 |
|
|
if (!IsRegistered(client_p)) |
254 |
|
|
ping = CONNECTTIMEOUT, pingwarn = 0; |
255 |
|
|
else |
256 |
|
|
ping = get_client_ping(client_p, &pingwarn); |
257 |
|
|
|
258 |
michael |
1241 |
if (ping < CurrentTime - client_p->localClient->lasttime) |
259 |
adx |
30 |
{ |
260 |
|
|
if (!IsPingSent(client_p)) |
261 |
|
|
{ |
262 |
|
|
/* |
263 |
|
|
* if we havent PINGed the connection and we havent |
264 |
|
|
* heard from it in a while, PING it to make sure |
265 |
|
|
* it is still alive. |
266 |
|
|
*/ |
267 |
|
|
SetPingSent(client_p); |
268 |
|
|
ClearPingWarning(client_p); |
269 |
michael |
1241 |
client_p->localClient->lasttime = CurrentTime - ping; |
270 |
adx |
30 |
sendto_one(client_p, "PING :%s", ID_or_name(&me, client_p)); |
271 |
|
|
} |
272 |
|
|
else |
273 |
|
|
{ |
274 |
michael |
1241 |
if (CurrentTime - client_p->localClient->lasttime >= 2 * ping) |
275 |
adx |
30 |
{ |
276 |
|
|
/* |
277 |
|
|
* If the client/server hasn't talked to us in 2*ping seconds |
278 |
|
|
* and it has a ping time, then close its connection. |
279 |
|
|
*/ |
280 |
|
|
if (IsServer(client_p) || IsHandshake(client_p)) |
281 |
|
|
{ |
282 |
|
|
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
283 |
|
|
"No response from %s, closing link", |
284 |
|
|
get_client_name(client_p, HIDE_IP)); |
285 |
|
|
sendto_realops_flags(UMODE_ALL, L_OPER, |
286 |
|
|
"No response from %s, closing link", |
287 |
|
|
get_client_name(client_p, MASK_IP)); |
288 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "No response from %s, closing link", |
289 |
adx |
30 |
get_client_name(client_p, HIDE_IP)); |
290 |
|
|
} |
291 |
michael |
650 |
|
292 |
michael |
1124 |
snprintf(scratch, sizeof(scratch), "Ping timeout: %d seconds", |
293 |
michael |
1241 |
(int)(CurrentTime - client_p->localClient->lasttime)); |
294 |
adx |
30 |
exit_client(client_p, &me, scratch); |
295 |
|
|
} |
296 |
|
|
else if (!IsPingWarning(client_p) && pingwarn > 0 && |
297 |
|
|
(IsServer(client_p) || IsHandshake(client_p)) && |
298 |
michael |
1241 |
CurrentTime - client_p->localClient->lasttime >= ping + pingwarn) |
299 |
adx |
30 |
{ |
300 |
|
|
/* |
301 |
|
|
* If the server hasn't replied in pingwarn seconds after sending |
302 |
|
|
* the PING, notify the opers so that they are aware of the problem. |
303 |
|
|
*/ |
304 |
|
|
SetPingWarning(client_p); |
305 |
|
|
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
306 |
|
|
"Warning, no response from %s in %d seconds", |
307 |
|
|
get_client_name(client_p, HIDE_IP), pingwarn); |
308 |
|
|
sendto_realops_flags(UMODE_ALL, L_OPER, |
309 |
|
|
"Warning, no response from %s in %d seconds", |
310 |
|
|
get_client_name(client_p, MASK_IP), pingwarn); |
311 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "No response from %s in %d seconds", |
312 |
adx |
30 |
get_client_name(client_p, HIDE_IP), pingwarn); |
313 |
|
|
} |
314 |
|
|
} |
315 |
|
|
} |
316 |
|
|
} |
317 |
|
|
} |
318 |
|
|
|
319 |
|
|
/* check_unknowns_list() |
320 |
|
|
* |
321 |
|
|
* inputs - pointer to list of unknown clients |
322 |
|
|
* output - NONE |
323 |
|
|
* side effects - unknown clients get marked for termination after n seconds |
324 |
|
|
*/ |
325 |
|
|
static void |
326 |
|
|
check_unknowns_list(void) |
327 |
|
|
{ |
328 |
|
|
dlink_node *ptr, *next_ptr; |
329 |
|
|
|
330 |
|
|
DLINK_FOREACH_SAFE(ptr, next_ptr, unknown_list.head) |
331 |
|
|
{ |
332 |
|
|
struct Client *client_p = ptr->data; |
333 |
|
|
|
334 |
michael |
650 |
/* |
335 |
|
|
* Check UNKNOWN connections - if they have been in this state |
336 |
adx |
30 |
* for > 30s, close them. |
337 |
|
|
*/ |
338 |
michael |
1241 |
if (IsAuthFinished(client_p) && (CurrentTime - client_p->localClient->firsttime) > 30) |
339 |
michael |
650 |
exit_client(client_p, &me, "Registration timed out"); |
340 |
adx |
30 |
} |
341 |
|
|
} |
342 |
|
|
|
343 |
|
|
/* check_conf_klines() |
344 |
|
|
* |
345 |
|
|
* inputs - NONE |
346 |
|
|
* output - NONE |
347 |
|
|
* side effects - Check all connections for a pending kline against the |
348 |
|
|
* client, exit the client if a kline matches. |
349 |
|
|
*/ |
350 |
|
|
void |
351 |
|
|
check_conf_klines(void) |
352 |
|
|
{ |
353 |
|
|
struct Client *client_p = NULL; /* current local client_p being examined */ |
354 |
|
|
struct AccessItem *aconf = NULL; |
355 |
|
|
struct ConfItem *conf = NULL; |
356 |
|
|
dlink_node *ptr, *next_ptr; |
357 |
|
|
|
358 |
|
|
DLINK_FOREACH_SAFE(ptr, next_ptr, local_client_list.head) |
359 |
|
|
{ |
360 |
|
|
client_p = ptr->data; |
361 |
|
|
|
362 |
|
|
/* If a client is already being exited |
363 |
|
|
*/ |
364 |
|
|
if (IsDead(client_p) || !IsClient(client_p)) |
365 |
|
|
continue; |
366 |
|
|
|
367 |
|
|
/* if there is a returned struct ConfItem then kill it */ |
368 |
|
|
if ((aconf = find_dline_conf(&client_p->localClient->ip, |
369 |
|
|
client_p->localClient->aftype)) != NULL) |
370 |
|
|
{ |
371 |
|
|
if (aconf->status & CONF_EXEMPTDLINE) |
372 |
|
|
continue; |
373 |
|
|
|
374 |
|
|
conf = unmap_conf_item(aconf); |
375 |
|
|
ban_them(client_p, conf); |
376 |
|
|
continue; /* and go examine next fd/client_p */ |
377 |
|
|
} |
378 |
|
|
|
379 |
|
|
if (ConfigFileEntry.glines && (aconf = find_gline(client_p))) |
380 |
|
|
{ |
381 |
|
|
if (IsExemptKline(client_p) || |
382 |
|
|
IsExemptGline(client_p)) |
383 |
|
|
{ |
384 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
385 |
|
|
"GLINE over-ruled for %s, client is %sline_exempt", |
386 |
|
|
get_client_name(client_p, HIDE_IP), IsExemptKline(client_p) ? "k" : "g"); |
387 |
|
|
continue; |
388 |
|
|
} |
389 |
|
|
|
390 |
|
|
conf = unmap_conf_item(aconf); |
391 |
|
|
ban_them(client_p, conf); |
392 |
|
|
/* and go examine next fd/client_p */ |
393 |
|
|
continue; |
394 |
|
|
} |
395 |
|
|
|
396 |
|
|
if ((aconf = find_kill(client_p)) != NULL) |
397 |
|
|
{ |
398 |
|
|
|
399 |
|
|
/* if there is a returned struct AccessItem.. then kill it */ |
400 |
|
|
if (IsExemptKline(client_p)) |
401 |
|
|
{ |
402 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
403 |
|
|
"KLINE over-ruled for %s, client is kline_exempt", |
404 |
|
|
get_client_name(client_p, HIDE_IP)); |
405 |
|
|
continue; |
406 |
|
|
} |
407 |
|
|
|
408 |
|
|
conf = unmap_conf_item(aconf); |
409 |
|
|
ban_them(client_p, conf); |
410 |
|
|
continue; |
411 |
|
|
} |
412 |
|
|
|
413 |
|
|
/* if there is a returned struct MatchItem then kill it */ |
414 |
|
|
if ((conf = find_matching_name_conf(XLINE_TYPE, client_p->info, |
415 |
|
|
NULL, NULL, 0)) != NULL || |
416 |
|
|
(conf = find_matching_name_conf(RXLINE_TYPE, client_p->info, |
417 |
|
|
NULL, NULL, 0)) != NULL) |
418 |
|
|
{ |
419 |
|
|
ban_them(client_p, conf); |
420 |
|
|
continue; |
421 |
|
|
} |
422 |
|
|
} |
423 |
|
|
|
424 |
|
|
/* also check the unknowns list for new dlines */ |
425 |
|
|
DLINK_FOREACH_SAFE(ptr, next_ptr, unknown_list.head) |
426 |
|
|
{ |
427 |
|
|
client_p = ptr->data; |
428 |
|
|
|
429 |
|
|
if ((aconf = find_dline_conf(&client_p->localClient->ip, |
430 |
|
|
client_p->localClient->aftype))) |
431 |
|
|
{ |
432 |
|
|
if (aconf->status & CONF_EXEMPTDLINE) |
433 |
|
|
continue; |
434 |
|
|
|
435 |
|
|
exit_client(client_p, &me, "D-lined"); |
436 |
|
|
} |
437 |
|
|
} |
438 |
|
|
} |
439 |
|
|
|
440 |
|
|
/* |
441 |
|
|
* ban_them |
442 |
|
|
* |
443 |
|
|
* inputs - pointer to client to ban |
444 |
|
|
* - pointer to ConfItem |
445 |
|
|
* output - NONE |
446 |
|
|
* side effects - given client_p is banned |
447 |
|
|
*/ |
448 |
|
|
static void |
449 |
|
|
ban_them(struct Client *client_p, struct ConfItem *conf) |
450 |
|
|
{ |
451 |
|
|
const char *user_reason = NULL; /* What is sent to user */ |
452 |
|
|
struct AccessItem *aconf = NULL; |
453 |
|
|
struct MatchItem *xconf = NULL; |
454 |
|
|
const char *type_string = NULL; |
455 |
|
|
const char dline_string[] = "D-line"; |
456 |
|
|
const char kline_string[] = "K-line"; |
457 |
|
|
const char gline_string[] = "G-line"; |
458 |
|
|
const char xline_string[] = "X-line"; |
459 |
|
|
|
460 |
|
|
switch (conf->type) |
461 |
|
|
{ |
462 |
|
|
case RKLINE_TYPE: |
463 |
|
|
case KLINE_TYPE: |
464 |
|
|
type_string = kline_string; |
465 |
|
|
aconf = map_to_conf(conf); |
466 |
|
|
break; |
467 |
|
|
case DLINE_TYPE: |
468 |
|
|
type_string = dline_string; |
469 |
|
|
aconf = map_to_conf(conf); |
470 |
|
|
break; |
471 |
|
|
case GLINE_TYPE: |
472 |
|
|
type_string = gline_string; |
473 |
|
|
aconf = map_to_conf(conf); |
474 |
|
|
break; |
475 |
|
|
case RXLINE_TYPE: |
476 |
|
|
case XLINE_TYPE: |
477 |
|
|
type_string = xline_string; |
478 |
|
|
xconf = map_to_conf(conf); |
479 |
|
|
++xconf->count; |
480 |
|
|
break; |
481 |
|
|
default: |
482 |
|
|
assert(0); |
483 |
|
|
break; |
484 |
|
|
} |
485 |
|
|
|
486 |
michael |
1549 |
if (aconf != NULL) |
487 |
|
|
user_reason = aconf->reason ? aconf->reason : type_string; |
488 |
|
|
if (xconf != NULL) |
489 |
|
|
user_reason = xconf->reason ? xconf->reason : type_string; |
490 |
adx |
30 |
|
491 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, "%s active for %s", |
492 |
|
|
type_string, get_client_name(client_p, HIDE_IP)); |
493 |
|
|
|
494 |
|
|
if (IsClient(client_p)) |
495 |
|
|
sendto_one(client_p, form_str(ERR_YOUREBANNEDCREEP), |
496 |
|
|
me.name, client_p->name, user_reason); |
497 |
|
|
|
498 |
michael |
1549 |
exit_client(client_p, &me, user_reason); |
499 |
adx |
30 |
} |
500 |
|
|
|
501 |
|
|
/* update_client_exit_stats() |
502 |
|
|
* |
503 |
|
|
* input - pointer to client |
504 |
|
|
* output - NONE |
505 |
|
|
* side effects - |
506 |
|
|
*/ |
507 |
|
|
static void |
508 |
|
|
update_client_exit_stats(struct Client *client_p) |
509 |
|
|
{ |
510 |
michael |
1143 |
if (IsClient(client_p)) |
511 |
adx |
30 |
{ |
512 |
michael |
1013 |
assert(Count.total > 0); |
513 |
adx |
30 |
--Count.total; |
514 |
michael |
1219 |
if (HasUMode(client_p, UMODE_OPER)) |
515 |
adx |
30 |
--Count.oper; |
516 |
michael |
1219 |
if (HasUMode(client_p, UMODE_INVISIBLE)) |
517 |
adx |
30 |
--Count.invisi; |
518 |
|
|
} |
519 |
michael |
1143 |
else if (IsServer(client_p)) |
520 |
|
|
sendto_realops_flags(UMODE_EXTERNAL, L_ALL, "Server %s split from %s", |
521 |
|
|
client_p->name, client_p->servptr->name); |
522 |
adx |
30 |
|
523 |
|
|
if (splitchecking && !splitmode) |
524 |
|
|
check_splitmode(NULL); |
525 |
|
|
} |
526 |
|
|
|
527 |
|
|
/* find_person() |
528 |
|
|
* |
529 |
|
|
* inputs - pointer to name |
530 |
|
|
* output - return client pointer |
531 |
|
|
* side effects - find person by (nick)name |
532 |
|
|
*/ |
533 |
|
|
struct Client * |
534 |
|
|
find_person(const struct Client *client_p, const char *name) |
535 |
|
|
{ |
536 |
|
|
struct Client *c2ptr; |
537 |
|
|
|
538 |
|
|
if (IsDigit(*name)) |
539 |
|
|
{ |
540 |
|
|
if ((c2ptr = hash_find_id(name)) != NULL) |
541 |
|
|
{ |
542 |
|
|
/* invisible users shall not be found by UID guessing */ |
543 |
michael |
1219 |
if (HasUMode(c2ptr, UMODE_INVISIBLE) && !IsServer(client_p)) |
544 |
adx |
30 |
c2ptr = NULL; |
545 |
|
|
} |
546 |
|
|
} |
547 |
|
|
else |
548 |
michael |
1169 |
c2ptr = hash_find_client(name); |
549 |
adx |
30 |
|
550 |
|
|
return ((c2ptr != NULL && IsClient(c2ptr)) ? c2ptr : NULL); |
551 |
|
|
} |
552 |
|
|
|
553 |
|
|
/* |
554 |
|
|
* find_chasing - find the client structure for a nick name (user) |
555 |
|
|
* using history mechanism if necessary. If the client is not found, |
556 |
|
|
* an error message (NO SUCH NICK) is generated. If the client was found |
557 |
|
|
* through the history, chasing will be 1 and otherwise 0. |
558 |
|
|
*/ |
559 |
|
|
struct Client * |
560 |
|
|
find_chasing(struct Client *client_p, struct Client *source_p, const char *user, int *chasing) |
561 |
|
|
{ |
562 |
|
|
struct Client *who = find_person(client_p, user); |
563 |
|
|
|
564 |
|
|
if (chasing) |
565 |
|
|
*chasing = 0; |
566 |
|
|
|
567 |
|
|
if (who) |
568 |
michael |
1169 |
return who; |
569 |
adx |
30 |
|
570 |
|
|
if (IsDigit(*user)) |
571 |
michael |
1169 |
return NULL; |
572 |
adx |
30 |
|
573 |
|
|
if ((who = get_history(user, |
574 |
|
|
(time_t)ConfigFileEntry.kill_chase_time_limit)) |
575 |
|
|
== NULL) |
576 |
|
|
{ |
577 |
|
|
sendto_one(source_p, form_str(ERR_NOSUCHNICK), |
578 |
|
|
me.name, source_p->name, user); |
579 |
michael |
1169 |
return NULL; |
580 |
adx |
30 |
} |
581 |
|
|
|
582 |
|
|
if (chasing) |
583 |
|
|
*chasing = 1; |
584 |
|
|
|
585 |
michael |
1169 |
return who; |
586 |
adx |
30 |
} |
587 |
|
|
|
588 |
|
|
/* |
589 |
|
|
* get_client_name - Return the name of the client |
590 |
|
|
* for various tracking and |
591 |
|
|
* admin purposes. The main purpose of this function is to |
592 |
|
|
* return the "socket host" name of the client, if that |
593 |
|
|
* differs from the advertised name (other than case). |
594 |
|
|
* But, this can be used to any client structure. |
595 |
|
|
* |
596 |
|
|
* NOTE 1: |
597 |
|
|
* Watch out the allocation of "nbuf", if either source_p->name |
598 |
|
|
* or source_p->sockhost gets changed into pointers instead of |
599 |
|
|
* directly allocated within the structure... |
600 |
|
|
* |
601 |
|
|
* NOTE 2: |
602 |
|
|
* Function return either a pointer to the structure (source_p) or |
603 |
|
|
* to internal buffer (nbuf). *NEVER* use the returned pointer |
604 |
|
|
* to modify what it points!!! |
605 |
|
|
*/ |
606 |
|
|
const char * |
607 |
michael |
1328 |
get_client_name(const struct Client *client, enum addr_mask_type type) |
608 |
adx |
30 |
{ |
609 |
|
|
static char nbuf[HOSTLEN * 2 + USERLEN + 5]; |
610 |
|
|
|
611 |
|
|
assert(client != NULL); |
612 |
|
|
|
613 |
michael |
1340 |
if (!MyConnect(client)) |
614 |
michael |
1124 |
return client->name; |
615 |
adx |
30 |
|
616 |
michael |
1340 |
if (IsServer(client) || IsConnecting(client) || IsHandshake(client)) |
617 |
|
|
{ |
618 |
|
|
if (!irccmp(client->name, client->host)) |
619 |
|
|
return client->name; |
620 |
|
|
else if (ConfigServerHide.hide_server_ips) |
621 |
michael |
1328 |
type = MASK_IP; |
622 |
michael |
1340 |
} |
623 |
adx |
30 |
|
624 |
|
|
if (ConfigFileEntry.hide_spoof_ips) |
625 |
michael |
1328 |
if (type == SHOW_IP && IsIPSpoof(client)) |
626 |
|
|
type = MASK_IP; |
627 |
adx |
30 |
|
628 |
|
|
/* And finally, let's get the host information, ip or name */ |
629 |
michael |
1328 |
switch (type) |
630 |
adx |
30 |
{ |
631 |
|
|
case SHOW_IP: |
632 |
michael |
1339 |
snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]", |
633 |
|
|
client->name, |
634 |
|
|
client->username, client->sockhost); |
635 |
|
|
break; |
636 |
adx |
30 |
case MASK_IP: |
637 |
michael |
1339 |
if (client->localClient->aftype == AF_INET) |
638 |
|
|
snprintf(nbuf, sizeof(nbuf), "%s[%s@255.255.255.255]", |
639 |
|
|
client->name, client->username); |
640 |
|
|
else |
641 |
|
|
snprintf(nbuf, sizeof(nbuf), "%s[%s@ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]", |
642 |
|
|
client->name, client->username); |
643 |
adx |
30 |
break; |
644 |
|
|
default: |
645 |
michael |
1124 |
snprintf(nbuf, sizeof(nbuf), "%s[%s@%s]", |
646 |
|
|
client->name, |
647 |
|
|
client->username, client->host); |
648 |
adx |
30 |
} |
649 |
|
|
|
650 |
michael |
1124 |
return nbuf; |
651 |
adx |
30 |
} |
652 |
|
|
|
653 |
|
|
void |
654 |
|
|
free_exited_clients(void) |
655 |
|
|
{ |
656 |
michael |
887 |
dlink_node *ptr = NULL, *next = NULL; |
657 |
adx |
30 |
|
658 |
|
|
DLINK_FOREACH_SAFE(ptr, next, dead_list.head) |
659 |
|
|
{ |
660 |
michael |
887 |
free_client(ptr->data); |
661 |
adx |
30 |
dlinkDelete(ptr, &dead_list); |
662 |
|
|
free_dlink_node(ptr); |
663 |
|
|
} |
664 |
|
|
} |
665 |
|
|
|
666 |
|
|
/* |
667 |
|
|
* Exit one client, local or remote. Assuming all dependents have |
668 |
|
|
* been already removed, and socket closed for local client. |
669 |
|
|
* |
670 |
|
|
* The only messages generated are QUITs on channels. |
671 |
|
|
*/ |
672 |
|
|
static void |
673 |
|
|
exit_one_client(struct Client *source_p, const char *quitmsg) |
674 |
|
|
{ |
675 |
|
|
dlink_node *lp = NULL, *next_lp = NULL; |
676 |
|
|
|
677 |
|
|
assert(!IsMe(source_p)); |
678 |
|
|
|
679 |
michael |
1118 |
if (IsClient(source_p)) |
680 |
adx |
30 |
{ |
681 |
|
|
if (source_p->servptr->serv != NULL) |
682 |
michael |
889 |
dlinkDelete(&source_p->lnode, &source_p->servptr->serv->client_list); |
683 |
adx |
30 |
|
684 |
michael |
1118 |
/* |
685 |
|
|
* If a person is on a channel, send a QUIT notice |
686 |
|
|
* to every client (person) on the same channel (so |
687 |
|
|
* that the client can show the "**signoff" message). |
688 |
|
|
* (Note: The notice is to the local clients *only*) |
689 |
|
|
*/ |
690 |
adx |
30 |
sendto_common_channels_local(source_p, 0, ":%s!%s@%s QUIT :%s", |
691 |
|
|
source_p->name, source_p->username, |
692 |
|
|
source_p->host, quitmsg); |
693 |
|
|
DLINK_FOREACH_SAFE(lp, next_lp, source_p->channel.head) |
694 |
|
|
remove_user_from_channel(lp->data); |
695 |
|
|
|
696 |
|
|
add_history(source_p, 0); |
697 |
|
|
off_history(source_p); |
698 |
|
|
|
699 |
michael |
876 |
watch_check_hash(source_p, RPL_LOGOFF); |
700 |
|
|
|
701 |
michael |
889 |
if (MyConnect(source_p)) |
702 |
adx |
30 |
{ |
703 |
michael |
317 |
/* Clean up invitefield */ |
704 |
|
|
DLINK_FOREACH_SAFE(lp, next_lp, source_p->localClient->invited.head) |
705 |
|
|
del_invite(lp->data, source_p); |
706 |
michael |
887 |
|
707 |
|
|
del_all_accepts(source_p); |
708 |
michael |
317 |
} |
709 |
adx |
30 |
} |
710 |
michael |
1118 |
else if (IsServer(source_p)) |
711 |
|
|
{ |
712 |
|
|
dlinkDelete(&source_p->lnode, &source_p->servptr->serv->server_list); |
713 |
adx |
30 |
|
714 |
michael |
1118 |
if ((lp = dlinkFindDelete(&global_serv_list, source_p)) != NULL) |
715 |
|
|
free_dlink_node(lp); |
716 |
|
|
} |
717 |
|
|
|
718 |
adx |
30 |
/* Remove source_p from the client lists */ |
719 |
|
|
if (HasID(source_p)) |
720 |
|
|
hash_del_id(source_p); |
721 |
|
|
if (source_p->name[0]) |
722 |
|
|
hash_del_client(source_p); |
723 |
|
|
|
724 |
|
|
if (IsUserHostIp(source_p)) |
725 |
|
|
delete_user_host(source_p->username, source_p->host, !MyConnect(source_p)); |
726 |
|
|
|
727 |
|
|
/* remove from global client list |
728 |
|
|
* NOTE: source_p->node.next cannot be NULL if the client is added |
729 |
|
|
* to global_client_list (there is always &me at its end) |
730 |
|
|
*/ |
731 |
|
|
if (source_p != NULL && source_p->node.next != NULL) |
732 |
|
|
dlinkDelete(&source_p->node, &global_client_list); |
733 |
|
|
|
734 |
|
|
update_client_exit_stats(source_p); |
735 |
|
|
|
736 |
|
|
/* Check to see if the client isn't already on the dead list */ |
737 |
|
|
assert(dlinkFind(&dead_list, source_p) == NULL); |
738 |
|
|
|
739 |
|
|
/* add to dead client dlist */ |
740 |
|
|
SetDead(source_p); |
741 |
|
|
dlinkAdd(source_p, make_dlink_node(), &dead_list); |
742 |
|
|
} |
743 |
|
|
|
744 |
|
|
/* Recursively send QUITs and SQUITs for source_p and all its dependent clients |
745 |
|
|
* and servers to those servers that need them. A server needs the client |
746 |
|
|
* QUITs if it can't figure them out from the SQUIT (ie pre-TS4) or if it |
747 |
|
|
* isn't getting the SQUIT because of @#(*&@)# hostmasking. With TS4, once |
748 |
|
|
* a link gets a SQUIT, it doesn't need any QUIT/SQUITs for clients depending |
749 |
|
|
* on that one -orabidoo |
750 |
|
|
* |
751 |
|
|
* This is now called on each local server -adx |
752 |
|
|
*/ |
753 |
|
|
static void |
754 |
|
|
recurse_send_quits(struct Client *original_source_p, struct Client *source_p, |
755 |
|
|
struct Client *from, struct Client *to, const char *comment, |
756 |
michael |
1118 |
const char *splitstr) |
757 |
adx |
30 |
{ |
758 |
|
|
dlink_node *ptr, *next; |
759 |
|
|
struct Client *target_p; |
760 |
|
|
|
761 |
|
|
assert(to != source_p); /* should be already removed from serv_list */ |
762 |
|
|
|
763 |
|
|
/* If this server can handle quit storm (QS) removal |
764 |
|
|
* of dependents, just send the SQUIT |
765 |
|
|
*/ |
766 |
michael |
1529 |
if (!IsCapable(to, CAP_QS)) |
767 |
michael |
889 |
DLINK_FOREACH_SAFE(ptr, next, source_p->serv->client_list.head) |
768 |
adx |
30 |
{ |
769 |
|
|
target_p = ptr->data; |
770 |
|
|
sendto_one(to, ":%s QUIT :%s", target_p->name, splitstr); |
771 |
|
|
} |
772 |
|
|
|
773 |
michael |
889 |
DLINK_FOREACH_SAFE(ptr, next, source_p->serv->server_list.head) |
774 |
adx |
30 |
recurse_send_quits(original_source_p, ptr->data, from, to, |
775 |
michael |
1118 |
comment, splitstr); |
776 |
adx |
30 |
|
777 |
michael |
1529 |
if ((source_p == original_source_p && to != from) || |
778 |
|
|
!IsCapable(to, CAP_QS)) |
779 |
adx |
30 |
{ |
780 |
|
|
/* don't use a prefix here - we have to be 100% sure the message |
781 |
|
|
* will be accepted without Unknown prefix etc.. */ |
782 |
|
|
sendto_one(to, "SQUIT %s :%s", ID_or_name(source_p, to), comment); |
783 |
|
|
} |
784 |
|
|
} |
785 |
|
|
|
786 |
|
|
/* |
787 |
|
|
* Remove all clients that depend on source_p; assumes all (S)QUITs have |
788 |
|
|
* already been sent. we make sure to exit a server's dependent clients |
789 |
|
|
* and servers before the server itself; exit_one_client takes care of |
790 |
|
|
* actually removing things off llists. tweaked from +CSr31 -orabidoo |
791 |
|
|
*/ |
792 |
|
|
static void |
793 |
|
|
recurse_remove_clients(struct Client *source_p, const char *quitmsg) |
794 |
|
|
{ |
795 |
|
|
dlink_node *ptr, *next; |
796 |
|
|
|
797 |
michael |
889 |
DLINK_FOREACH_SAFE(ptr, next, source_p->serv->client_list.head) |
798 |
adx |
30 |
exit_one_client(ptr->data, quitmsg); |
799 |
|
|
|
800 |
michael |
889 |
DLINK_FOREACH_SAFE(ptr, next, source_p->serv->server_list.head) |
801 |
adx |
30 |
{ |
802 |
|
|
recurse_remove_clients(ptr->data, quitmsg); |
803 |
|
|
exit_one_client(ptr->data, quitmsg); |
804 |
|
|
} |
805 |
|
|
} |
806 |
|
|
|
807 |
|
|
/* |
808 |
|
|
** Remove *everything* that depends on source_p, from all lists, and sending |
809 |
|
|
** all necessary QUITs and SQUITs. source_p itself is still on the lists, |
810 |
|
|
** and its SQUITs have been sent except for the upstream one -orabidoo |
811 |
|
|
*/ |
812 |
|
|
static void |
813 |
|
|
remove_dependents(struct Client *source_p, struct Client *from, |
814 |
|
|
const char *comment, const char *splitstr) |
815 |
|
|
{ |
816 |
michael |
1118 |
dlink_node *ptr = NULL; |
817 |
adx |
30 |
|
818 |
|
|
DLINK_FOREACH(ptr, serv_list.head) |
819 |
michael |
1118 |
recurse_send_quits(source_p, source_p, from, ptr->data, |
820 |
|
|
comment, splitstr); |
821 |
adx |
30 |
|
822 |
|
|
recurse_remove_clients(source_p, splitstr); |
823 |
|
|
} |
824 |
|
|
|
825 |
|
|
/* |
826 |
|
|
* exit_client - exit a client of any type. Generally, you can use |
827 |
|
|
* this on any struct Client, regardless of its state. |
828 |
|
|
* |
829 |
|
|
* Note, you shouldn't exit remote _users_ without first doing |
830 |
michael |
1219 |
* AddFlag(x, FLAGS_KILLED) and propagating a kill or similar message. |
831 |
|
|
* However, it is perfectly correct to call exit_client to force a _server_ |
832 |
adx |
30 |
* quit (either local or remote one). |
833 |
|
|
* |
834 |
|
|
* inputs: - a client pointer that is going to be exited |
835 |
|
|
* - for servers, the second argument is a pointer to who |
836 |
|
|
* is firing the server. This side won't get any generated |
837 |
|
|
* messages. NEVER NULL! |
838 |
|
|
* output: none |
839 |
|
|
* side effects: the client is delinked from all lists, disconnected, |
840 |
|
|
* and the rest of IRC network is notified of the exit. |
841 |
|
|
* Client memory is scheduled to be freed |
842 |
|
|
*/ |
843 |
|
|
void |
844 |
|
|
exit_client(struct Client *source_p, struct Client *from, const char *comment) |
845 |
|
|
{ |
846 |
michael |
1118 |
dlink_node *m = NULL; |
847 |
adx |
30 |
|
848 |
|
|
if (MyConnect(source_p)) |
849 |
|
|
{ |
850 |
|
|
/* DO NOT REMOVE. exit_client can be called twice after a failed |
851 |
|
|
* read/write. |
852 |
|
|
*/ |
853 |
|
|
if (IsClosing(source_p)) |
854 |
|
|
return; |
855 |
|
|
|
856 |
|
|
SetClosing(source_p); |
857 |
|
|
|
858 |
|
|
if (IsIpHash(source_p)) |
859 |
|
|
remove_one_ip(&source_p->localClient->ip); |
860 |
|
|
|
861 |
michael |
992 |
if (source_p->localClient->auth) |
862 |
|
|
{ |
863 |
|
|
delete_auth(source_p->localClient->auth); |
864 |
|
|
source_p->localClient->auth = NULL; |
865 |
|
|
} |
866 |
adx |
30 |
|
867 |
|
|
/* This source_p could have status of one of STAT_UNKNOWN, STAT_CONNECTING |
868 |
|
|
* STAT_HANDSHAKE or STAT_UNKNOWN |
869 |
|
|
* all of which are lumped together into unknown_list |
870 |
|
|
* |
871 |
|
|
* In all above cases IsRegistered() will not be true. |
872 |
|
|
*/ |
873 |
|
|
if (!IsRegistered(source_p)) |
874 |
|
|
{ |
875 |
michael |
1126 |
assert(dlinkFind(&unknown_list, source_p)); |
876 |
|
|
|
877 |
|
|
dlinkDelete(&source_p->localClient->lclient_node, &unknown_list); |
878 |
adx |
30 |
} |
879 |
|
|
else if (IsClient(source_p)) |
880 |
|
|
{ |
881 |
michael |
1247 |
time_t on_for = CurrentTime - source_p->localClient->firsttime; |
882 |
michael |
1013 |
assert(Count.local > 0); |
883 |
adx |
30 |
Count.local--; |
884 |
|
|
|
885 |
michael |
1219 |
if (HasUMode(source_p, UMODE_OPER)) |
886 |
adx |
30 |
{ |
887 |
|
|
if ((m = dlinkFindDelete(&oper_list, source_p)) != NULL) |
888 |
|
|
free_dlink_node(m); |
889 |
|
|
} |
890 |
|
|
|
891 |
michael |
1126 |
assert(dlinkFind(&local_client_list, source_p)); |
892 |
adx |
30 |
dlinkDelete(&source_p->localClient->lclient_node, &local_client_list); |
893 |
michael |
1126 |
|
894 |
adx |
30 |
if (source_p->localClient->list_task != NULL) |
895 |
|
|
free_list_task(source_p->localClient->list_task, source_p); |
896 |
|
|
|
897 |
michael |
876 |
watch_del_watch_list(source_p); |
898 |
adx |
30 |
sendto_realops_flags(UMODE_CCONN, L_ALL, "Client exiting: %s (%s@%s) [%s] [%s]", |
899 |
|
|
source_p->name, source_p->username, source_p->host, comment, |
900 |
|
|
ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ? |
901 |
|
|
"255.255.255.255" : source_p->sockhost); |
902 |
db |
853 |
sendto_realops_flags(UMODE_CCONN_FULL, L_ALL, "CLIEXIT: %s %s %s %s 0 %s", |
903 |
|
|
source_p->name, |
904 |
|
|
source_p->username, |
905 |
|
|
source_p->host, |
906 |
db |
849 |
ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ? |
907 |
db |
853 |
"255.255.255.255" : source_p->sockhost, |
908 |
|
|
comment); |
909 |
michael |
1247 |
ilog(LOG_TYPE_USER, "%s (%3u:%02u:%02u): %s!%s@%s %llu/%llu", |
910 |
|
|
myctime(source_p->localClient->firsttime), (unsigned int)(on_for / 3600), |
911 |
|
|
(unsigned int)((on_for % 3600)/60), (unsigned int)(on_for % 60), |
912 |
|
|
source_p->name, source_p->username, source_p->host, |
913 |
|
|
source_p->localClient->send.bytes>>10, |
914 |
|
|
source_p->localClient->recv.bytes>>10); |
915 |
adx |
30 |
} |
916 |
|
|
|
917 |
|
|
/* As soon as a client is known to be a server of some sort |
918 |
|
|
* it has to be put on the serv_list, or SJOIN's to this new server |
919 |
|
|
* from the connect burst will not be seen. |
920 |
michael |
1185 |
* XXX - TBV. This is not true. The only place where we put a server on |
921 |
|
|
* serv_list is in server_estab right now after registration process. |
922 |
|
|
* And only after this, a burst is sent to the remote server, i.e. we never |
923 |
|
|
* send a burst to STAT_CONNECTING, or STAT_HANDSHAKE. This will need |
924 |
|
|
* more investigation later on, but for now, it's not a problem after all. |
925 |
adx |
30 |
*/ |
926 |
|
|
if (IsServer(source_p) || IsConnecting(source_p) || |
927 |
|
|
IsHandshake(source_p)) |
928 |
|
|
{ |
929 |
michael |
1185 |
if (dlinkFind(&serv_list, source_p)) |
930 |
adx |
30 |
{ |
931 |
michael |
1185 |
dlinkDelete(&source_p->localClient->lclient_node, &serv_list); |
932 |
adx |
30 |
unset_chcap_usage_counts(source_p); |
933 |
|
|
} |
934 |
|
|
|
935 |
|
|
if (IsServer(source_p)) |
936 |
|
|
Count.myserver--; |
937 |
|
|
} |
938 |
|
|
|
939 |
|
|
if (!IsDead(source_p)) |
940 |
|
|
{ |
941 |
|
|
if (IsServer(source_p)) |
942 |
|
|
{ |
943 |
|
|
/* for them, we are exiting the network */ |
944 |
|
|
sendto_one(source_p, ":%s SQUIT %s :%s", |
945 |
|
|
ID_or_name(from, source_p), me.name, comment); |
946 |
|
|
} |
947 |
|
|
|
948 |
|
|
sendto_one(source_p, "ERROR :Closing Link: %s (%s)", |
949 |
|
|
source_p->host, comment); |
950 |
|
|
} |
951 |
|
|
|
952 |
|
|
/* |
953 |
|
|
** Currently only server connections can have |
954 |
|
|
** depending remote clients here, but it does no |
955 |
|
|
** harm to check for all local clients. In |
956 |
|
|
** future some other clients than servers might |
957 |
|
|
** have remotes too... |
958 |
|
|
** |
959 |
|
|
** Close the Client connection first and mark it |
960 |
|
|
** so that no messages are attempted to send to it. |
961 |
|
|
** Remember it makes source_p->from == NULL. |
962 |
|
|
*/ |
963 |
|
|
close_connection(source_p); |
964 |
|
|
} |
965 |
|
|
|
966 |
|
|
if (IsServer(source_p)) |
967 |
|
|
{ |
968 |
|
|
char splitstr[HOSTLEN + HOSTLEN + 2]; |
969 |
|
|
|
970 |
|
|
/* This shouldn't ever happen */ |
971 |
|
|
assert(source_p->serv != NULL && source_p->servptr != NULL); |
972 |
|
|
|
973 |
|
|
if (ConfigServerHide.hide_servers) |
974 |
michael |
887 |
/* |
975 |
|
|
* Set netsplit message to "*.net *.split" to still show |
976 |
adx |
30 |
* that its a split, but hide the servers splitting |
977 |
|
|
*/ |
978 |
|
|
strcpy(splitstr, "*.net *.split"); |
979 |
|
|
else |
980 |
|
|
snprintf(splitstr, sizeof(splitstr), "%s %s", |
981 |
|
|
source_p->servptr->name, source_p->name); |
982 |
|
|
|
983 |
|
|
remove_dependents(source_p, from->from, comment, splitstr); |
984 |
|
|
|
985 |
|
|
if (source_p->servptr == &me) |
986 |
|
|
{ |
987 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
988 |
|
|
"%s was connected for %d seconds. %llu/%llu sendK/recvK.", |
989 |
michael |
1241 |
source_p->name, (int)(CurrentTime - source_p->localClient->firsttime), |
990 |
adx |
30 |
source_p->localClient->send.bytes >> 10, |
991 |
|
|
source_p->localClient->recv.bytes >> 10); |
992 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "%s was connected for %d seconds. %llu/%llu sendK/recvK.", |
993 |
michael |
1241 |
source_p->name, (int)(CurrentTime - source_p->localClient->firsttime), |
994 |
adx |
30 |
source_p->localClient->send.bytes >> 10, |
995 |
|
|
source_p->localClient->recv.bytes >> 10); |
996 |
|
|
} |
997 |
|
|
} |
998 |
michael |
1219 |
else if (IsClient(source_p) && !HasFlag(source_p, FLAGS_KILLED)) |
999 |
adx |
30 |
{ |
1000 |
michael |
1474 |
sendto_server(from->from, CAP_TS6, NOCAPS, |
1001 |
adx |
30 |
":%s QUIT :%s", ID(source_p), comment); |
1002 |
michael |
1474 |
sendto_server(from->from, NOCAPS, CAP_TS6, |
1003 |
adx |
30 |
":%s QUIT :%s", source_p->name, comment); |
1004 |
|
|
} |
1005 |
|
|
|
1006 |
|
|
/* The client *better* be off all of the lists */ |
1007 |
|
|
assert(dlinkFind(&unknown_list, source_p) == NULL); |
1008 |
|
|
assert(dlinkFind(&local_client_list, source_p) == NULL); |
1009 |
|
|
assert(dlinkFind(&serv_list, source_p) == NULL); |
1010 |
|
|
assert(dlinkFind(&oper_list, source_p) == NULL); |
1011 |
|
|
|
1012 |
|
|
exit_one_client(source_p, comment); |
1013 |
|
|
} |
1014 |
|
|
|
1015 |
|
|
/* |
1016 |
|
|
* dead_link_on_write - report a write error if not already dead, |
1017 |
|
|
* mark it as dead then exit it |
1018 |
|
|
*/ |
1019 |
|
|
void |
1020 |
|
|
dead_link_on_write(struct Client *client_p, int ierrno) |
1021 |
|
|
{ |
1022 |
|
|
dlink_node *ptr; |
1023 |
|
|
|
1024 |
|
|
if (IsDefunct(client_p)) |
1025 |
|
|
return; |
1026 |
|
|
|
1027 |
|
|
dbuf_clear(&client_p->localClient->buf_recvq); |
1028 |
|
|
dbuf_clear(&client_p->localClient->buf_sendq); |
1029 |
|
|
|
1030 |
|
|
assert(dlinkFind(&abort_list, client_p) == NULL); |
1031 |
|
|
ptr = make_dlink_node(); |
1032 |
|
|
/* don't let exit_aborted_clients() finish yet */ |
1033 |
|
|
dlinkAddTail(client_p, ptr, &abort_list); |
1034 |
|
|
|
1035 |
|
|
if (eac_next == NULL) |
1036 |
|
|
eac_next = ptr; |
1037 |
|
|
|
1038 |
|
|
SetDead(client_p); /* You are dead my friend */ |
1039 |
|
|
} |
1040 |
|
|
|
1041 |
|
|
/* |
1042 |
|
|
* dead_link_on_read - report a read error if not already dead, |
1043 |
|
|
* mark it as dead then exit it |
1044 |
|
|
*/ |
1045 |
|
|
void |
1046 |
|
|
dead_link_on_read(struct Client *client_p, int error) |
1047 |
|
|
{ |
1048 |
|
|
char errmsg[255]; |
1049 |
|
|
int current_error; |
1050 |
|
|
|
1051 |
|
|
if (IsDefunct(client_p)) |
1052 |
|
|
return; |
1053 |
|
|
|
1054 |
|
|
dbuf_clear(&client_p->localClient->buf_recvq); |
1055 |
|
|
dbuf_clear(&client_p->localClient->buf_sendq); |
1056 |
|
|
|
1057 |
|
|
current_error = get_sockerr(client_p->localClient->fd.fd); |
1058 |
|
|
|
1059 |
|
|
if (IsServer(client_p) || IsHandshake(client_p)) |
1060 |
|
|
{ |
1061 |
michael |
1241 |
int connected = CurrentTime - client_p->localClient->firsttime; |
1062 |
adx |
30 |
|
1063 |
|
|
if (error == 0) |
1064 |
|
|
{ |
1065 |
|
|
/* Admins get the real IP */ |
1066 |
|
|
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
1067 |
|
|
"Server %s closed the connection", |
1068 |
|
|
get_client_name(client_p, SHOW_IP)); |
1069 |
|
|
|
1070 |
|
|
/* Opers get a masked IP */ |
1071 |
|
|
sendto_realops_flags(UMODE_ALL, L_OPER, |
1072 |
|
|
"Server %s closed the connection", |
1073 |
|
|
get_client_name(client_p, MASK_IP)); |
1074 |
|
|
|
1075 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "Server %s closed the connection", |
1076 |
adx |
30 |
get_client_name(client_p, SHOW_IP)); |
1077 |
|
|
} |
1078 |
|
|
else |
1079 |
|
|
{ |
1080 |
michael |
617 |
report_error(L_ADMIN, "Lost connection to %s: %s", |
1081 |
adx |
30 |
get_client_name(client_p, SHOW_IP), current_error); |
1082 |
michael |
617 |
report_error(L_OPER, "Lost connection to %s: %s", |
1083 |
adx |
30 |
get_client_name(client_p, MASK_IP), current_error); |
1084 |
|
|
} |
1085 |
|
|
|
1086 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
1087 |
|
|
"%s had been connected for %d day%s, %2d:%02d:%02d", |
1088 |
|
|
client_p->name, connected/86400, |
1089 |
|
|
(connected/86400 == 1) ? "" : "s", |
1090 |
|
|
(connected % 86400) / 3600, (connected % 3600) / 60, |
1091 |
|
|
connected % 60); |
1092 |
|
|
} |
1093 |
|
|
|
1094 |
|
|
if (error == 0) |
1095 |
|
|
strlcpy(errmsg, "Remote host closed the connection", |
1096 |
|
|
sizeof(errmsg)); |
1097 |
|
|
else |
1098 |
michael |
1124 |
snprintf(errmsg, sizeof(errmsg), "Read error: %s", |
1099 |
|
|
strerror(current_error)); |
1100 |
adx |
30 |
|
1101 |
|
|
exit_client(client_p, &me, errmsg); |
1102 |
|
|
} |
1103 |
|
|
|
1104 |
|
|
void |
1105 |
|
|
exit_aborted_clients(void) |
1106 |
|
|
{ |
1107 |
|
|
dlink_node *ptr; |
1108 |
|
|
struct Client *target_p; |
1109 |
|
|
const char *notice; |
1110 |
|
|
|
1111 |
|
|
DLINK_FOREACH_SAFE(ptr, eac_next, abort_list.head) |
1112 |
|
|
{ |
1113 |
|
|
target_p = ptr->data; |
1114 |
|
|
eac_next = ptr->next; |
1115 |
|
|
|
1116 |
|
|
if (target_p == NULL) |
1117 |
|
|
{ |
1118 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
1119 |
|
|
"Warning: null client on abort_list!"); |
1120 |
|
|
dlinkDelete(ptr, &abort_list); |
1121 |
|
|
free_dlink_node(ptr); |
1122 |
|
|
continue; |
1123 |
|
|
} |
1124 |
|
|
|
1125 |
|
|
dlinkDelete(ptr, &abort_list); |
1126 |
|
|
|
1127 |
|
|
if (IsSendQExceeded(target_p)) |
1128 |
|
|
notice = "Max SendQ exceeded"; |
1129 |
|
|
else |
1130 |
|
|
notice = "Write error: connection closed"; |
1131 |
|
|
|
1132 |
|
|
exit_client(target_p, &me, notice); |
1133 |
|
|
free_dlink_node(ptr); |
1134 |
|
|
} |
1135 |
|
|
} |
1136 |
|
|
|
1137 |
|
|
/* |
1138 |
|
|
* accept processing, this adds a form of "caller ID" to ircd |
1139 |
michael |
887 |
* |
1140 |
adx |
30 |
* If a client puts themselves into "caller ID only" mode, |
1141 |
michael |
887 |
* only clients that match a client pointer they have put on |
1142 |
adx |
30 |
* the accept list will be allowed to message them. |
1143 |
|
|
* |
1144 |
michael |
887 |
* Diane Bruce, "Dianora" db@db.net |
1145 |
adx |
30 |
*/ |
1146 |
|
|
|
1147 |
michael |
887 |
void |
1148 |
|
|
del_accept(struct split_nuh_item *accept_p, struct Client *client_p) |
1149 |
adx |
30 |
{ |
1150 |
michael |
887 |
dlinkDelete(&accept_p->node, &client_p->localClient->acceptlist); |
1151 |
adx |
30 |
|
1152 |
michael |
887 |
MyFree(accept_p->nickptr); |
1153 |
|
|
MyFree(accept_p->userptr); |
1154 |
|
|
MyFree(accept_p->hostptr); |
1155 |
|
|
MyFree(accept_p); |
1156 |
|
|
} |
1157 |
adx |
30 |
|
1158 |
michael |
887 |
struct split_nuh_item * |
1159 |
|
|
find_accept(const char *nick, const char *user, |
1160 |
|
|
const char *host, struct Client *client_p, int do_match) |
1161 |
|
|
{ |
1162 |
|
|
dlink_node *ptr = NULL; |
1163 |
|
|
/* XXX We wouldn't need that if match() would return 0 on match */ |
1164 |
|
|
int (*cmpfunc)(const char *, const char *) = do_match ? match : irccmp; |
1165 |
adx |
30 |
|
1166 |
michael |
887 |
DLINK_FOREACH(ptr, client_p->localClient->acceptlist.head) |
1167 |
adx |
30 |
{ |
1168 |
michael |
887 |
struct split_nuh_item *accept_p = ptr->data; |
1169 |
|
|
|
1170 |
|
|
if (cmpfunc(accept_p->nickptr, nick) == do_match && |
1171 |
|
|
cmpfunc(accept_p->userptr, user) == do_match && |
1172 |
|
|
cmpfunc(accept_p->hostptr, host) == do_match) |
1173 |
|
|
return accept_p; |
1174 |
adx |
30 |
} |
1175 |
|
|
|
1176 |
michael |
887 |
return NULL; |
1177 |
adx |
30 |
} |
1178 |
|
|
|
1179 |
michael |
887 |
/* accept_message() |
1180 |
adx |
30 |
* |
1181 |
michael |
887 |
* inputs - pointer to source client |
1182 |
|
|
* - pointer to target client |
1183 |
|
|
* output - 1 if accept this message 0 if not |
1184 |
|
|
* side effects - See if source is on target's allow list |
1185 |
adx |
30 |
*/ |
1186 |
michael |
887 |
int |
1187 |
|
|
accept_message(struct Client *source, |
1188 |
|
|
struct Client *target) |
1189 |
adx |
30 |
{ |
1190 |
michael |
887 |
dlink_node *ptr = NULL; |
1191 |
adx |
30 |
|
1192 |
michael |
887 |
if (source == target || find_accept(source->name, source->username, |
1193 |
|
|
source->host, target, 1)) |
1194 |
|
|
return 1; |
1195 |
adx |
30 |
|
1196 |
michael |
1219 |
if (HasUMode(target, UMODE_SOFTCALLERID)) |
1197 |
michael |
887 |
DLINK_FOREACH(ptr, target->channel.head) |
1198 |
|
|
if (IsMember(source, ((struct Membership *)ptr->data)->chptr)) |
1199 |
|
|
return 1; |
1200 |
adx |
30 |
|
1201 |
michael |
887 |
return 0; |
1202 |
adx |
30 |
} |
1203 |
|
|
|
1204 |
|
|
/* del_all_accepts() |
1205 |
|
|
* |
1206 |
michael |
887 |
* inputs - pointer to exiting client |
1207 |
|
|
* output - NONE |
1208 |
|
|
* side effects - Walk through given clients acceptlist and remove all entries |
1209 |
adx |
30 |
*/ |
1210 |
|
|
void |
1211 |
|
|
del_all_accepts(struct Client *client_p) |
1212 |
|
|
{ |
1213 |
michael |
887 |
dlink_node *ptr = NULL, *next_ptr = NULL; |
1214 |
adx |
30 |
|
1215 |
michael |
887 |
DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->acceptlist.head) |
1216 |
|
|
del_accept(ptr->data, client_p); |
1217 |
adx |
30 |
} |