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