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