| 1 |
adx |
30 |
/* |
| 2 |
michael |
2916 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
adx |
30 |
* |
| 4 |
michael |
9101 |
* Copyright (c) 1997-2020 ircd-hybrid development team |
| 5 |
adx |
30 |
* |
| 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 |
| 8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
| 9 |
|
|
* (at your option) any later version. |
| 10 |
|
|
* |
| 11 |
|
|
* This program is distributed in the hope that it will be useful, |
| 12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
|
|
* GNU General Public License for more details. |
| 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 |
michael |
4565 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 19 |
adx |
30 |
* USA |
| 20 |
|
|
*/ |
| 21 |
|
|
|
| 22 |
michael |
2916 |
/*! \file client.c |
| 23 |
|
|
* \brief Controls clients. |
| 24 |
|
|
* \version $Id$ |
| 25 |
|
|
*/ |
| 26 |
|
|
|
| 27 |
adx |
30 |
#include "stdinc.h" |
| 28 |
michael |
1011 |
#include "list.h" |
| 29 |
adx |
30 |
#include "client.h" |
| 30 |
michael |
8484 |
#include "client_svstag.h" |
| 31 |
adx |
30 |
#include "event.h" |
| 32 |
|
|
#include "hash.h" |
| 33 |
|
|
#include "irc_string.h" |
| 34 |
|
|
#include "ircd.h" |
| 35 |
|
|
#include "numeric.h" |
| 36 |
michael |
3324 |
#include "auth.h" |
| 37 |
adx |
30 |
#include "s_bsd.h" |
| 38 |
michael |
1309 |
#include "conf.h" |
| 39 |
michael |
7304 |
#include "conf_gecos.h" |
| 40 |
michael |
1309 |
#include "log.h" |
| 41 |
michael |
3347 |
#include "misc.h" |
| 42 |
|
|
#include "server.h" |
| 43 |
adx |
30 |
#include "send.h" |
| 44 |
|
|
#include "whowas.h" |
| 45 |
michael |
3347 |
#include "user.h" |
| 46 |
adx |
30 |
#include "memory.h" |
| 47 |
|
|
#include "hostmask.h" |
| 48 |
|
|
#include "listener.h" |
| 49 |
michael |
876 |
#include "watch.h" |
| 50 |
michael |
1783 |
#include "rng_mt.h" |
| 51 |
michael |
2682 |
#include "parse.h" |
| 52 |
michael |
4325 |
#include "ipcache.h" |
| 53 |
michael |
9234 |
#include "channel.h" |
| 54 |
michael |
9265 |
#include "channel_invite.h" |
| 55 |
adx |
30 |
|
| 56 |
|
|
|
| 57 |
michael |
4213 |
dlink_list listing_client_list; |
| 58 |
|
|
dlink_list unknown_list; |
| 59 |
|
|
dlink_list local_client_list; |
| 60 |
|
|
dlink_list local_server_list; |
| 61 |
|
|
dlink_list global_client_list; |
| 62 |
|
|
dlink_list global_server_list; |
| 63 |
|
|
dlink_list oper_list; |
| 64 |
|
|
|
| 65 |
|
|
static dlink_list dead_list, abort_list; |
| 66 |
adx |
30 |
static dlink_node *eac_next; /* next aborted client to exit */ |
| 67 |
|
|
|
| 68 |
|
|
|
| 69 |
|
|
/* |
| 70 |
michael |
8437 |
* client_make - create a new Client struct and set it to initial state. |
| 71 |
adx |
30 |
* |
| 72 |
|
|
* from == NULL, create local client (a client connected |
| 73 |
|
|
* to a socket). |
| 74 |
|
|
* WARNING: This leaves the client in a dangerous |
| 75 |
|
|
* state where fd == -1, dead flag is not set and |
| 76 |
|
|
* the client is on the unknown_list; therefore, |
| 77 |
|
|
* the first thing to do after calling make_client(NULL) |
| 78 |
|
|
* is setting fd to something reasonable. -adx |
| 79 |
|
|
* |
| 80 |
|
|
* from, create remote client (behind a socket |
| 81 |
|
|
* associated with the client defined by |
| 82 |
|
|
* 'from'). ('from' is a local client!!). |
| 83 |
|
|
*/ |
| 84 |
|
|
struct Client * |
| 85 |
michael |
7957 |
client_make(struct Client *from) |
| 86 |
adx |
30 |
{ |
| 87 |
michael |
9250 |
struct Client *client = xcalloc(sizeof(*client)); |
| 88 |
adx |
30 |
|
| 89 |
michael |
7797 |
if (from) |
| 90 |
michael |
9250 |
client->from = from; |
| 91 |
michael |
7797 |
else |
| 92 |
adx |
30 |
{ |
| 93 |
michael |
9250 |
client->from = client; /* 'from' of local client is self! */ |
| 94 |
|
|
client->connection = xcalloc(sizeof(*client->connection)); |
| 95 |
|
|
client->connection->last_data = event_base->time.sec_monotonic; |
| 96 |
|
|
client->connection->last_ping = event_base->time.sec_monotonic; |
| 97 |
|
|
client->connection->created_real = event_base->time.sec_real; |
| 98 |
|
|
client->connection->created_monotonic = event_base->time.sec_monotonic; |
| 99 |
|
|
client->connection->registration = REG_INIT; |
| 100 |
adx |
30 |
|
| 101 |
|
|
/* as good a place as any... */ |
| 102 |
michael |
9250 |
dlinkAdd(client, &client->connection->lclient_node, &unknown_list); |
| 103 |
adx |
30 |
} |
| 104 |
|
|
|
| 105 |
michael |
9250 |
client->idhnext = client; |
| 106 |
|
|
client->hnext = client; |
| 107 |
|
|
SetUnknown(client); |
| 108 |
|
|
strcpy(client->username, "unknown"); |
| 109 |
|
|
strcpy(client->account, "*"); |
| 110 |
adx |
30 |
|
| 111 |
michael |
9250 |
return client; |
| 112 |
adx |
30 |
} |
| 113 |
|
|
|
| 114 |
|
|
/* |
| 115 |
michael |
7957 |
* client_free |
| 116 |
adx |
30 |
* |
| 117 |
|
|
* inputs - pointer to client |
| 118 |
|
|
* output - NONE |
| 119 |
|
|
* side effects - client pointed to has its memory freed |
| 120 |
|
|
*/ |
| 121 |
|
|
static void |
| 122 |
michael |
9250 |
client_free(struct Client *client) |
| 123 |
adx |
30 |
{ |
| 124 |
michael |
9250 |
assert(!IsMe(client)); |
| 125 |
|
|
assert(client != &me); |
| 126 |
|
|
assert(client->hnext == client); |
| 127 |
|
|
assert(client->idhnext == client); |
| 128 |
michael |
8335 |
|
| 129 |
michael |
9250 |
assert(client->node.prev == NULL); |
| 130 |
|
|
assert(client->node.next == NULL); |
| 131 |
michael |
8335 |
|
| 132 |
michael |
9250 |
assert(client->lnode.prev == NULL); |
| 133 |
|
|
assert(client->lnode.next == NULL); |
| 134 |
michael |
8335 |
|
| 135 |
michael |
9250 |
assert(dlink_list_length(&client->whowas_list) == 0); |
| 136 |
|
|
assert(client->whowas_list.head == NULL); |
| 137 |
|
|
assert(client->whowas_list.tail == NULL); |
| 138 |
michael |
8335 |
|
| 139 |
michael |
9250 |
assert(dlink_list_length(&client->channel) == 0); |
| 140 |
|
|
assert(client->channel.head == NULL); |
| 141 |
|
|
assert(client->channel.tail == NULL); |
| 142 |
michael |
8335 |
|
| 143 |
michael |
9250 |
assert(dlink_list_length(&client->svstags) == 0); |
| 144 |
|
|
assert(client->svstags.head == NULL); |
| 145 |
|
|
assert(client->svstags.tail == NULL); |
| 146 |
adx |
30 |
|
| 147 |
michael |
8335 |
|
| 148 |
michael |
9250 |
xfree(client->serv); |
| 149 |
michael |
9408 |
xfree(client->tls_certfp); |
| 150 |
adx |
30 |
|
| 151 |
michael |
9250 |
if (MyConnect(client)) |
| 152 |
adx |
30 |
{ |
| 153 |
michael |
9250 |
assert(client->connection->lclient_node.prev == NULL); |
| 154 |
|
|
assert(client->connection->lclient_node.next == NULL); |
| 155 |
michael |
8335 |
|
| 156 |
michael |
9250 |
assert(client->connection->list_task == NULL); |
| 157 |
|
|
assert(client->connection->auth == NULL); |
| 158 |
michael |
8335 |
|
| 159 |
michael |
9250 |
assert(dlink_list_length(&client->connection->acceptlist) == 0); |
| 160 |
|
|
assert(client->connection->acceptlist.head == NULL); |
| 161 |
|
|
assert(client->connection->acceptlist.tail == NULL); |
| 162 |
michael |
8335 |
|
| 163 |
|
|
|
| 164 |
michael |
9250 |
assert(dlink_list_length(&client->connection->watches) == 0); |
| 165 |
|
|
assert(client->connection->watches.head == NULL); |
| 166 |
|
|
assert(client->connection->watches.tail == NULL); |
| 167 |
michael |
8335 |
|
| 168 |
michael |
9250 |
assert(dlink_list_length(&client->connection->confs) == 0); |
| 169 |
|
|
assert(client->connection->confs.head == NULL); |
| 170 |
|
|
assert(client->connection->confs.tail == NULL); |
| 171 |
michael |
8335 |
|
| 172 |
michael |
9250 |
assert(dlink_list_length(&client->connection->invited) == 0); |
| 173 |
|
|
assert(client->connection->invited.head == NULL); |
| 174 |
|
|
assert(client->connection->invited.tail == NULL); |
| 175 |
michael |
8335 |
|
| 176 |
michael |
9250 |
assert(client->connection->fd == NULL); |
| 177 |
michael |
8335 |
|
| 178 |
michael |
9250 |
assert(HasFlag(client, FLAGS_CLOSING) && IsDead(client)); |
| 179 |
adx |
30 |
|
| 180 |
|
|
/* |
| 181 |
michael |
5589 |
* Clean up extra sockets from listen {} blocks which have been discarded. |
| 182 |
adx |
30 |
*/ |
| 183 |
michael |
9250 |
if (client->connection->listener) |
| 184 |
adx |
30 |
{ |
| 185 |
michael |
9250 |
listener_release(client->connection->listener); |
| 186 |
|
|
client->connection->listener = NULL; |
| 187 |
adx |
30 |
} |
| 188 |
|
|
|
| 189 |
michael |
9250 |
dbuf_clear(&client->connection->buf_recvq); |
| 190 |
|
|
dbuf_clear(&client->connection->buf_sendq); |
| 191 |
adx |
30 |
|
| 192 |
michael |
9250 |
xfree(client->connection); |
| 193 |
|
|
client->connection = NULL; |
| 194 |
adx |
30 |
} |
| 195 |
|
|
|
| 196 |
michael |
9250 |
xfree(client); |
| 197 |
adx |
30 |
} |
| 198 |
|
|
|
| 199 |
|
|
/* check_pings_list() |
| 200 |
|
|
* |
| 201 |
|
|
* inputs - pointer to list to check |
| 202 |
|
|
* output - NONE |
| 203 |
michael |
2345 |
* side effects - |
| 204 |
adx |
30 |
*/ |
| 205 |
|
|
static void |
| 206 |
|
|
check_pings_list(dlink_list *list) |
| 207 |
|
|
{ |
| 208 |
michael |
9086 |
char buf[32]; /* 32 = sizeof("Ping timeout: 999999999 seconds") */ |
| 209 |
michael |
8437 |
dlink_node *node, *node_next; |
| 210 |
adx |
30 |
|
| 211 |
michael |
4800 |
DLINK_FOREACH_SAFE(node, node_next, list->head) |
| 212 |
adx |
30 |
{ |
| 213 |
michael |
9250 |
struct Client *client = node->data; |
| 214 |
|
|
assert(IsClient(client) || IsServer(client)); |
| 215 |
adx |
30 |
|
| 216 |
michael |
9250 |
if (IsDead(client)) |
| 217 |
michael |
8431 |
continue; /* Ignore it, it's been exited already */ |
| 218 |
adx |
30 |
|
| 219 |
michael |
9250 |
unsigned int ping = get_client_ping(&client->connection->confs); |
| 220 |
|
|
if (ping < event_base->time.sec_monotonic - client->connection->last_ping) |
| 221 |
adx |
30 |
{ |
| 222 |
michael |
9250 |
if (!HasFlag(client, FLAGS_PINGSENT)) |
| 223 |
adx |
30 |
{ |
| 224 |
michael |
2182 |
/* |
| 225 |
michael |
4298 |
* If we haven't PINGed the connection and we haven't |
| 226 |
michael |
2182 |
* heard from it in a while, PING it to make sure |
| 227 |
|
|
* it is still alive. |
| 228 |
|
|
*/ |
| 229 |
michael |
9250 |
AddFlag(client, FLAGS_PINGSENT); |
| 230 |
|
|
client->connection->last_ping = event_base->time.sec_monotonic - ping; |
| 231 |
|
|
sendto_one(client, "PING :%s", ID_or_name(&me, client)); |
| 232 |
adx |
30 |
} |
| 233 |
|
|
else |
| 234 |
|
|
{ |
| 235 |
michael |
9250 |
if (event_base->time.sec_monotonic - client->connection->last_ping >= 2 * ping) |
| 236 |
adx |
30 |
{ |
| 237 |
|
|
/* |
| 238 |
|
|
* If the client/server hasn't talked to us in 2*ping seconds |
| 239 |
|
|
* and it has a ping time, then close its connection. |
| 240 |
|
|
*/ |
| 241 |
michael |
9250 |
if (IsServer(client)) |
| 242 |
michael |
2182 |
{ |
| 243 |
michael |
6318 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, |
| 244 |
michael |
2182 |
"No response from %s, closing link", |
| 245 |
michael |
9250 |
client_get_name(client, SHOW_IP)); |
| 246 |
michael |
6318 |
sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE, |
| 247 |
michael |
2182 |
"No response from %s, closing link", |
| 248 |
michael |
9250 |
client_get_name(client, MASK_IP)); |
| 249 |
michael |
2182 |
ilog(LOG_TYPE_IRCD, "No response from %s, closing link", |
| 250 |
michael |
9250 |
client_get_name(client, SHOW_IP)); |
| 251 |
michael |
2182 |
} |
| 252 |
michael |
650 |
|
| 253 |
michael |
8923 |
snprintf(buf, sizeof(buf), "Ping timeout: %ju seconds", |
| 254 |
michael |
9250 |
(event_base->time.sec_monotonic - client->connection->last_ping)); |
| 255 |
|
|
exit_client(client, buf); |
| 256 |
adx |
30 |
} |
| 257 |
|
|
} |
| 258 |
|
|
} |
| 259 |
|
|
} |
| 260 |
|
|
} |
| 261 |
|
|
|
| 262 |
|
|
/* check_unknowns_list() |
| 263 |
|
|
* |
| 264 |
|
|
* inputs - pointer to list of unknown clients |
| 265 |
|
|
* output - NONE |
| 266 |
|
|
* side effects - unknown clients get marked for termination after n seconds |
| 267 |
|
|
*/ |
| 268 |
|
|
static void |
| 269 |
|
|
check_unknowns_list(void) |
| 270 |
|
|
{ |
| 271 |
michael |
8431 |
dlink_node *node, *node_next; |
| 272 |
adx |
30 |
|
| 273 |
michael |
4800 |
DLINK_FOREACH_SAFE(node, node_next, unknown_list.head) |
| 274 |
adx |
30 |
{ |
| 275 |
michael |
9250 |
struct Client *client = node->data; |
| 276 |
michael |
8837 |
bool exit = false; |
| 277 |
adx |
30 |
|
| 278 |
michael |
650 |
/* |
| 279 |
|
|
* Check UNKNOWN connections - if they have been in this state |
| 280 |
adx |
30 |
* for > 30s, close them. |
| 281 |
|
|
*/ |
| 282 |
michael |
9250 |
if ((event_base->time.sec_monotonic - client->connection->created_monotonic) <= 30) |
| 283 |
michael |
8837 |
continue; |
| 284 |
|
|
|
| 285 |
michael |
9250 |
if (IsHandshake(client)) |
| 286 |
michael |
8837 |
{ |
| 287 |
|
|
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, |
| 288 |
|
|
"No response from %s during handshake, closing link", |
| 289 |
michael |
9250 |
client_get_name(client, SHOW_IP)); |
| 290 |
michael |
8837 |
sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE, |
| 291 |
|
|
"No response from %s during handshake, closing link", |
| 292 |
michael |
9250 |
client_get_name(client, MASK_IP)); |
| 293 |
michael |
8837 |
ilog(LOG_TYPE_IRCD, "No response from %s during handshake, closing link", |
| 294 |
michael |
9250 |
client_get_name(client, SHOW_IP)); |
| 295 |
michael |
8837 |
exit = true; |
| 296 |
|
|
} |
| 297 |
michael |
9250 |
else if (HasFlag(client, FLAGS_FINISHED_AUTH)) |
| 298 |
michael |
8837 |
exit = true; |
| 299 |
|
|
|
| 300 |
|
|
if (exit == true) |
| 301 |
michael |
9250 |
exit_client(client, "Registration timed out"); |
| 302 |
adx |
30 |
} |
| 303 |
|
|
} |
| 304 |
|
|
|
| 305 |
michael |
4214 |
/* |
| 306 |
|
|
* check_pings - go through the local client list and check activity |
| 307 |
|
|
* kill off stuff that should die |
| 308 |
|
|
* |
| 309 |
|
|
* inputs - NOT USED (from event) |
| 310 |
|
|
* side effects - |
| 311 |
|
|
* |
| 312 |
|
|
* |
| 313 |
|
|
* A PING can be sent to clients as necessary. |
| 314 |
|
|
* |
| 315 |
|
|
* Client/Server ping outs are handled. |
| 316 |
|
|
*/ |
| 317 |
|
|
|
| 318 |
|
|
/* |
| 319 |
|
|
* Addon from adrian. We used to call this after nextping seconds, |
| 320 |
|
|
* however I've changed it to run once a second. This is only for |
| 321 |
|
|
* PING timeouts, not K/etc-line checks (thanks dianora!). Having it |
| 322 |
|
|
* run once a second makes life a lot easier - when a new client connects |
| 323 |
|
|
* and they need a ping in 4 seconds, if nextping was set to 20 seconds |
| 324 |
|
|
* we end up waiting 20 seconds. This is stupid. :-) |
| 325 |
|
|
* I will optimise (hah!) check_pings() once I've finished working on |
| 326 |
|
|
* tidying up other network IO evilnesses. |
| 327 |
|
|
* -- adrian |
| 328 |
|
|
*/ |
| 329 |
|
|
|
| 330 |
|
|
static void |
| 331 |
michael |
4439 |
check_pings(void *unused) |
| 332 |
michael |
4214 |
{ |
| 333 |
|
|
check_pings_list(&local_client_list); |
| 334 |
|
|
check_pings_list(&local_server_list); |
| 335 |
|
|
check_unknowns_list(); |
| 336 |
|
|
} |
| 337 |
|
|
|
| 338 |
adx |
30 |
/* check_conf_klines() |
| 339 |
|
|
* |
| 340 |
|
|
* inputs - NONE |
| 341 |
|
|
* output - NONE |
| 342 |
|
|
* side effects - Check all connections for a pending kline against the |
| 343 |
|
|
* client, exit the client if a kline matches. |
| 344 |
|
|
*/ |
| 345 |
michael |
2345 |
void |
| 346 |
adx |
30 |
check_conf_klines(void) |
| 347 |
michael |
2345 |
{ |
| 348 |
michael |
9086 |
dlink_node *node, *node_next; |
| 349 |
michael |
7431 |
const void *ptr; |
| 350 |
adx |
30 |
|
| 351 |
michael |
4800 |
DLINK_FOREACH_SAFE(node, node_next, local_client_list.head) |
| 352 |
adx |
30 |
{ |
| 353 |
michael |
9250 |
struct Client *client = node->data; |
| 354 |
adx |
30 |
|
| 355 |
michael |
4823 |
/* If a client is already being exited */ |
| 356 |
michael |
9250 |
if (IsDead(client)) |
| 357 |
adx |
30 |
continue; |
| 358 |
|
|
|
| 359 |
michael |
9250 |
if ((ptr = find_conf_by_address(NULL, &client->ip, CONF_DLINE, NULL, NULL, 1))) |
| 360 |
adx |
30 |
{ |
| 361 |
michael |
7304 |
const struct MaskItem *conf = ptr; |
| 362 |
michael |
9250 |
conf_try_ban(client, CLIENT_BAN_DLINE, conf->reason); |
| 363 |
michael |
5732 |
continue; /* and go examine next Client */ |
| 364 |
adx |
30 |
} |
| 365 |
|
|
|
| 366 |
michael |
9250 |
if ((ptr = find_conf_by_address(client->host, &client->ip, CONF_KLINE, |
| 367 |
|
|
client->username, NULL, 1))) |
| 368 |
adx |
30 |
{ |
| 369 |
michael |
7304 |
const struct MaskItem *conf = ptr; |
| 370 |
michael |
9250 |
conf_try_ban(client, CLIENT_BAN_KLINE, conf->reason); |
| 371 |
michael |
5732 |
continue; /* and go examine next Client */ |
| 372 |
adx |
30 |
} |
| 373 |
|
|
|
| 374 |
michael |
9250 |
if ((ptr = gecos_find(client->info, match))) |
| 375 |
adx |
30 |
{ |
| 376 |
michael |
7304 |
const struct GecosItem *conf = ptr; |
| 377 |
michael |
9250 |
conf_try_ban(client, CLIENT_BAN_XLINE, conf->reason); |
| 378 |
michael |
5732 |
continue; /* and go examine next Client */ |
| 379 |
adx |
30 |
} |
| 380 |
|
|
} |
| 381 |
|
|
|
| 382 |
michael |
5732 |
/* Also check the unknowns list for new dlines */ |
| 383 |
michael |
4800 |
DLINK_FOREACH_SAFE(node, node_next, unknown_list.head) |
| 384 |
adx |
30 |
{ |
| 385 |
michael |
9250 |
struct Client *client = node->data; |
| 386 |
adx |
30 |
|
| 387 |
michael |
8841 |
/* If a client is already being exited */ |
| 388 |
michael |
9250 |
if (IsDead(client)) |
| 389 |
michael |
8841 |
continue; |
| 390 |
|
|
|
| 391 |
michael |
9250 |
if ((ptr = find_conf_by_address(NULL, &client->ip, CONF_DLINE, NULL, NULL, 1))) |
| 392 |
adx |
30 |
{ |
| 393 |
michael |
7304 |
const struct MaskItem *conf = ptr; |
| 394 |
michael |
9250 |
conf_try_ban(client, CLIENT_BAN_DLINE, conf->reason); |
| 395 |
michael |
5732 |
continue; /* and go examine next Client */ |
| 396 |
adx |
30 |
} |
| 397 |
|
|
} |
| 398 |
|
|
} |
| 399 |
|
|
|
| 400 |
|
|
/* |
| 401 |
michael |
2813 |
* conf_try_ban |
| 402 |
adx |
30 |
* |
| 403 |
|
|
* inputs - pointer to client to ban |
| 404 |
michael |
1632 |
* - pointer to MaskItem |
| 405 |
adx |
30 |
* output - NONE |
| 406 |
michael |
9250 |
* side effects - given client is banned |
| 407 |
adx |
30 |
*/ |
| 408 |
michael |
2811 |
void |
| 409 |
michael |
9250 |
conf_try_ban(struct Client *client, int type, const char *reason) |
| 410 |
adx |
30 |
{ |
| 411 |
michael |
6943 |
char ban_type = '?'; |
| 412 |
adx |
30 |
|
| 413 |
michael |
7304 |
switch (type) |
| 414 |
adx |
30 |
{ |
| 415 |
michael |
7304 |
case CLIENT_BAN_KLINE: |
| 416 |
michael |
9250 |
if (HasFlag(client, FLAGS_EXEMPTKLINE)) |
| 417 |
michael |
2811 |
{ |
| 418 |
michael |
6318 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
| 419 |
michael |
2811 |
"KLINE over-ruled for %s, client is kline_exempt", |
| 420 |
michael |
9250 |
client_get_name(client, HIDE_IP)); |
| 421 |
michael |
2811 |
return; |
| 422 |
|
|
} |
| 423 |
|
|
|
| 424 |
michael |
5979 |
ban_type = 'K'; |
| 425 |
adx |
30 |
break; |
| 426 |
michael |
7304 |
case CLIENT_BAN_DLINE: |
| 427 |
michael |
9250 |
if (find_conf_by_address(NULL, &client->ip, CONF_EXEMPT, NULL, NULL, 1)) |
| 428 |
michael |
3929 |
return; |
| 429 |
michael |
5979 |
ban_type = 'D'; |
| 430 |
adx |
30 |
break; |
| 431 |
michael |
7304 |
case CLIENT_BAN_XLINE: |
| 432 |
michael |
9250 |
if (HasFlag(client, FLAGS_EXEMPTXLINE)) |
| 433 |
michael |
5985 |
{ |
| 434 |
michael |
6318 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
| 435 |
michael |
5985 |
"XLINE over-ruled for %s, client is xline_exempt", |
| 436 |
michael |
9250 |
client_get_name(client, HIDE_IP)); |
| 437 |
michael |
5985 |
return; |
| 438 |
|
|
} |
| 439 |
michael |
6313 |
|
| 440 |
michael |
5979 |
ban_type = 'X'; |
| 441 |
adx |
30 |
break; |
| 442 |
|
|
default: |
| 443 |
|
|
assert(0); |
| 444 |
|
|
break; |
| 445 |
|
|
} |
| 446 |
|
|
|
| 447 |
michael |
6318 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "%c-line active for %s", |
| 448 |
michael |
9250 |
ban_type, client_get_name(client, HIDE_IP)); |
| 449 |
adx |
30 |
|
| 450 |
michael |
9250 |
if (IsClient(client)) |
| 451 |
|
|
sendto_one_numeric(client, &me, ERR_YOUREBANNEDCREEP, reason); |
| 452 |
adx |
30 |
|
| 453 |
michael |
9250 |
exit_client(client, reason); |
| 454 |
adx |
30 |
} |
| 455 |
|
|
|
| 456 |
|
|
/* find_person() |
| 457 |
|
|
* |
| 458 |
|
|
* inputs - pointer to name |
| 459 |
|
|
* output - return client pointer |
| 460 |
|
|
* side effects - find person by (nick)name |
| 461 |
|
|
*/ |
| 462 |
|
|
struct Client * |
| 463 |
michael |
7345 |
find_person(const struct Client *source_p, const char *name) |
| 464 |
adx |
30 |
{ |
| 465 |
michael |
2475 |
struct Client *target_p = NULL; |
| 466 |
adx |
30 |
|
| 467 |
|
|
if (IsDigit(*name)) |
| 468 |
|
|
{ |
| 469 |
michael |
3207 |
if (IsServer(source_p->from)) |
| 470 |
michael |
2586 |
target_p = hash_find_id(name); |
| 471 |
adx |
30 |
} |
| 472 |
|
|
else |
| 473 |
michael |
2475 |
target_p = hash_find_client(name); |
| 474 |
adx |
30 |
|
| 475 |
michael |
9086 |
if (target_p && IsClient(target_p)) |
| 476 |
|
|
return target_p; |
| 477 |
|
|
|
| 478 |
|
|
return NULL; |
| 479 |
adx |
30 |
} |
| 480 |
|
|
|
| 481 |
|
|
/* |
| 482 |
michael |
2475 |
* find_chasing - find the client structure for a nick name (name) |
| 483 |
michael |
2345 |
* using history mechanism if necessary. If the client is not found, |
| 484 |
michael |
3192 |
* an error message (NO SUCH NICK) is generated. |
| 485 |
adx |
30 |
*/ |
| 486 |
|
|
struct Client * |
| 487 |
michael |
3192 |
find_chasing(struct Client *source_p, const char *name) |
| 488 |
adx |
30 |
{ |
| 489 |
michael |
4884 |
struct Client *target_p = find_person(source_p, name); |
| 490 |
adx |
30 |
|
| 491 |
michael |
4884 |
if (target_p) |
| 492 |
|
|
return target_p; |
| 493 |
adx |
30 |
|
| 494 |
michael |
2475 |
if (IsDigit(*name)) |
| 495 |
michael |
1169 |
return NULL; |
| 496 |
adx |
30 |
|
| 497 |
michael |
7464 |
target_p = whowas_get_history(name, ConfigGeneral.kill_chase_time_limit); |
| 498 |
michael |
8512 |
if (target_p == NULL) |
| 499 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, name); |
| 500 |
adx |
30 |
|
| 501 |
michael |
4884 |
return target_p; |
| 502 |
adx |
30 |
} |
| 503 |
|
|
|
| 504 |
|
|
/* |
| 505 |
michael |
7997 |
* client_get_name - Return the name of the client |
| 506 |
adx |
30 |
* for various tracking and |
| 507 |
|
|
* admin purposes. The main purpose of this function is to |
| 508 |
|
|
* return the "socket host" name of the client, if that |
| 509 |
|
|
* differs from the advertised name (other than case). |
| 510 |
|
|
* But, this can be used to any client structure. |
| 511 |
|
|
*/ |
| 512 |
|
|
const char * |
| 513 |
michael |
9250 |
client_get_name(const struct Client *client, enum addr_mask_type type) |
| 514 |
adx |
30 |
{ |
| 515 |
michael |
6963 |
static char buf[HOSTLEN * 2 + USERLEN + 4]; /* +4 for [,@,],\0 */ |
| 516 |
adx |
30 |
|
| 517 |
michael |
9250 |
if (!MyConnect(client)) |
| 518 |
|
|
return client->name; |
| 519 |
adx |
30 |
|
| 520 |
michael |
9250 |
if (IsServer(client) || IsConnecting(client) || IsHandshake(client)) |
| 521 |
michael |
1340 |
{ |
| 522 |
michael |
9250 |
if (irccmp(client->name, client->host) == 0) |
| 523 |
|
|
return client->name; |
| 524 |
michael |
1340 |
else if (ConfigServerHide.hide_server_ips) |
| 525 |
michael |
1328 |
type = MASK_IP; |
| 526 |
michael |
1340 |
} |
| 527 |
adx |
30 |
|
| 528 |
|
|
/* And finally, let's get the host information, ip or name */ |
| 529 |
michael |
1328 |
switch (type) |
| 530 |
adx |
30 |
{ |
| 531 |
|
|
case SHOW_IP: |
| 532 |
michael |
4214 |
snprintf(buf, sizeof(buf), "%s[%s@%s]", |
| 533 |
michael |
9250 |
client->name, |
| 534 |
|
|
client->username, client->sockhost); |
| 535 |
michael |
1339 |
break; |
| 536 |
adx |
30 |
case MASK_IP: |
| 537 |
michael |
9250 |
if (client->ip.ss.ss_family == AF_INET) |
| 538 |
michael |
4214 |
snprintf(buf, sizeof(buf), "%s[%s@255.255.255.255]", |
| 539 |
michael |
9250 |
client->name, client->username); |
| 540 |
michael |
1339 |
else |
| 541 |
michael |
4214 |
snprintf(buf, sizeof(buf), "%s[%s@ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]", |
| 542 |
michael |
9250 |
client->name, client->username); |
| 543 |
adx |
30 |
break; |
| 544 |
michael |
6310 |
default: /* HIDE_IP */ |
| 545 |
michael |
4214 |
snprintf(buf, sizeof(buf), "%s[%s@%s]", |
| 546 |
michael |
9250 |
client->name, |
| 547 |
|
|
client->username, client->host); |
| 548 |
adx |
30 |
} |
| 549 |
|
|
|
| 550 |
michael |
4214 |
return buf; |
| 551 |
adx |
30 |
} |
| 552 |
|
|
|
| 553 |
|
|
void |
| 554 |
|
|
free_exited_clients(void) |
| 555 |
|
|
{ |
| 556 |
michael |
8059 |
dlink_node *node, *node_next; |
| 557 |
michael |
2345 |
|
| 558 |
michael |
4800 |
DLINK_FOREACH_SAFE(node, node_next, dead_list.head) |
| 559 |
adx |
30 |
{ |
| 560 |
michael |
7957 |
client_free(node->data); |
| 561 |
michael |
4800 |
dlinkDelete(node, &dead_list); |
| 562 |
|
|
free_dlink_node(node); |
| 563 |
adx |
30 |
} |
| 564 |
|
|
} |
| 565 |
|
|
|
| 566 |
|
|
/* |
| 567 |
michael |
8393 |
* client_close_connection |
| 568 |
|
|
* Close the physical connection. This function must make |
| 569 |
michael |
9250 |
* MyConnect(client) == FALSE, and set client->from == NULL. |
| 570 |
michael |
8393 |
*/ |
| 571 |
|
|
static void |
| 572 |
michael |
9250 |
client_close_connection(struct Client *client) |
| 573 |
michael |
8393 |
{ |
| 574 |
michael |
9250 |
assert(client); |
| 575 |
michael |
8393 |
|
| 576 |
michael |
9250 |
if (!IsDead(client)) |
| 577 |
michael |
8393 |
{ |
| 578 |
michael |
8447 |
/* Attempt to flush any pending dbufs. Evil, but .. -- adrian */ |
| 579 |
|
|
/* |
| 580 |
|
|
* There is still a chance that we might send data to this socket |
| 581 |
michael |
8393 |
* even if it is marked as blocked (COMM_SELECT_READ handler is called |
| 582 |
|
|
* before COMM_SELECT_WRITE). Let's try, nothing to lose.. -adx |
| 583 |
|
|
*/ |
| 584 |
michael |
9250 |
DelFlag(client, FLAGS_BLOCKED); |
| 585 |
|
|
send_queued_write(client); |
| 586 |
michael |
8393 |
} |
| 587 |
|
|
|
| 588 |
michael |
9250 |
if (IsClient(client)) |
| 589 |
michael |
8393 |
{ |
| 590 |
|
|
++ServerStats.is_cl; |
| 591 |
michael |
9250 |
ServerStats.is_cbs += client->connection->send.bytes; |
| 592 |
|
|
ServerStats.is_cbr += client->connection->recv.bytes; |
| 593 |
|
|
ServerStats.is_cti += event_base->time.sec_monotonic - client->connection->created_monotonic; |
| 594 |
michael |
8393 |
} |
| 595 |
michael |
9250 |
else if (IsServer(client)) |
| 596 |
michael |
8393 |
{ |
| 597 |
michael |
8431 |
dlink_node *node; |
| 598 |
michael |
8393 |
|
| 599 |
|
|
++ServerStats.is_sv; |
| 600 |
michael |
9250 |
ServerStats.is_sbs += client->connection->send.bytes; |
| 601 |
|
|
ServerStats.is_sbr += client->connection->recv.bytes; |
| 602 |
|
|
ServerStats.is_sti += event_base->time.sec_monotonic - client->connection->created_monotonic; |
| 603 |
michael |
8393 |
|
| 604 |
|
|
DLINK_FOREACH(node, connect_items.head) |
| 605 |
|
|
{ |
| 606 |
|
|
struct MaskItem *conf = node->data; |
| 607 |
|
|
|
| 608 |
|
|
/* |
| 609 |
|
|
* Reset next-connect cycle of all connect{} blocks that match |
| 610 |
|
|
* this servername. |
| 611 |
|
|
*/ |
| 612 |
michael |
9250 |
if (irccmp(conf->name, client->name) == 0) |
| 613 |
michael |
8980 |
conf->until = event_base->time.sec_monotonic + conf->class->con_freq; |
| 614 |
michael |
8393 |
} |
| 615 |
|
|
} |
| 616 |
|
|
else |
| 617 |
|
|
++ServerStats.is_ni; |
| 618 |
|
|
|
| 619 |
michael |
9250 |
if (tls_isusing(&client->connection->fd->tls)) |
| 620 |
|
|
tls_shutdown(&client->connection->fd->tls); |
| 621 |
michael |
8393 |
|
| 622 |
michael |
9250 |
if (client->connection->fd) |
| 623 |
michael |
8393 |
{ |
| 624 |
michael |
9250 |
fd_close(client->connection->fd); |
| 625 |
|
|
client->connection->fd = NULL; |
| 626 |
michael |
8393 |
} |
| 627 |
|
|
|
| 628 |
michael |
9250 |
dbuf_clear(&client->connection->buf_sendq); |
| 629 |
|
|
dbuf_clear(&client->connection->buf_recvq); |
| 630 |
michael |
8393 |
|
| 631 |
michael |
9250 |
xfree(client->connection->password); |
| 632 |
|
|
client->connection->password = NULL; |
| 633 |
michael |
8393 |
|
| 634 |
michael |
9250 |
conf_detach(client, CONF_CLIENT | CONF_OPER | CONF_SERVER); |
| 635 |
michael |
8393 |
} |
| 636 |
|
|
|
| 637 |
|
|
/* |
| 638 |
adx |
30 |
* Exit one client, local or remote. Assuming all dependents have |
| 639 |
|
|
* been already removed, and socket closed for local client. |
| 640 |
|
|
* |
| 641 |
|
|
* The only messages generated are QUITs on channels. |
| 642 |
|
|
*/ |
| 643 |
|
|
static void |
| 644 |
michael |
9252 |
exit_one_client(struct Client *client, const char *comment) |
| 645 |
adx |
30 |
{ |
| 646 |
michael |
8059 |
dlink_node *node, *node_next; |
| 647 |
adx |
30 |
|
| 648 |
michael |
9252 |
assert(!IsMe(client)); |
| 649 |
|
|
assert(client != &me); |
| 650 |
adx |
30 |
|
| 651 |
michael |
9252 |
if (IsClient(client)) |
| 652 |
adx |
30 |
{ |
| 653 |
michael |
9252 |
if (HasUMode(client, UMODE_OPER)) |
| 654 |
michael |
7961 |
--Count.oper; |
| 655 |
michael |
9252 |
if (HasUMode(client, UMODE_INVISIBLE)) |
| 656 |
michael |
7961 |
--Count.invisi; |
| 657 |
|
|
|
| 658 |
michael |
9252 |
dlinkDelete(&client->lnode, &client->servptr->serv->client_list); |
| 659 |
|
|
dlinkDelete(&client->node, &global_client_list); |
| 660 |
adx |
30 |
|
| 661 |
michael |
1118 |
/* |
| 662 |
|
|
* If a person is on a channel, send a QUIT notice |
| 663 |
|
|
* to every client (person) on the same channel (so |
| 664 |
|
|
* that the client can show the "**signoff" message). |
| 665 |
|
|
* (Note: The notice is to the local clients *only*) |
| 666 |
|
|
*/ |
| 667 |
michael |
9252 |
sendto_common_channels_local(client, false, 0, 0, ":%s!%s@%s QUIT :%s", |
| 668 |
|
|
client->name, client->username, |
| 669 |
|
|
client->host, comment); |
| 670 |
michael |
4884 |
|
| 671 |
michael |
9252 |
DLINK_FOREACH_SAFE(node, node_next, client->channel.head) |
| 672 |
michael |
4800 |
remove_user_from_channel(node->data); |
| 673 |
adx |
30 |
|
| 674 |
michael |
9252 |
svstag_clear_list(&client->svstags); |
| 675 |
michael |
6942 |
|
| 676 |
michael |
9252 |
whowas_add_history(client, false); |
| 677 |
|
|
whowas_off_history(client); |
| 678 |
adx |
30 |
|
| 679 |
michael |
9252 |
watch_check_hash(client, RPL_LOGOFF); |
| 680 |
adx |
30 |
} |
| 681 |
michael |
9252 |
else if (IsServer(client)) |
| 682 |
michael |
1118 |
{ |
| 683 |
michael |
7961 |
sendto_realops_flags(UMODE_EXTERNAL, L_ALL, SEND_NOTICE, |
| 684 |
|
|
"Server %s split from %s", |
| 685 |
michael |
9252 |
client->name, client->servptr->name); |
| 686 |
michael |
7961 |
|
| 687 |
michael |
9252 |
dlinkDelete(&client->lnode, &client->servptr->serv->server_list); |
| 688 |
|
|
dlinkDelete(&client->node, &global_server_list); |
| 689 |
michael |
1118 |
} |
| 690 |
|
|
|
| 691 |
michael |
9252 |
if (client->id[0]) |
| 692 |
|
|
hash_del_id(client); |
| 693 |
michael |
4884 |
|
| 694 |
michael |
9252 |
if (client->name[0]) |
| 695 |
|
|
hash_del_client(client); |
| 696 |
adx |
30 |
|
| 697 |
michael |
9252 |
if (HasFlag(client, FLAGS_IPHASH)) |
| 698 |
michael |
8496 |
{ |
| 699 |
michael |
9252 |
DelFlag(client, FLAGS_IPHASH); |
| 700 |
|
|
ipcache_record_remove(&client->ip, MyConnect(client)); |
| 701 |
michael |
8496 |
} |
| 702 |
adx |
30 |
|
| 703 |
|
|
/* Check to see if the client isn't already on the dead list */ |
| 704 |
michael |
9252 |
assert(dlinkFind(&dead_list, client) == NULL); |
| 705 |
adx |
30 |
|
| 706 |
michael |
8431 |
/* Add to dead client dlist */ |
| 707 |
michael |
9252 |
SetDead(client); |
| 708 |
|
|
dlinkAdd(client, make_dlink_node(), &dead_list); |
| 709 |
adx |
30 |
} |
| 710 |
|
|
|
| 711 |
michael |
2345 |
/* |
| 712 |
michael |
9252 |
* Remove all clients that depend on 'client'; assumes all (S)QUITs have |
| 713 |
michael |
2345 |
* already been sent. we make sure to exit a server's dependent clients |
| 714 |
|
|
* and servers before the server itself; exit_one_client takes care of |
| 715 |
adx |
30 |
* actually removing things off llists. tweaked from +CSr31 -orabidoo |
| 716 |
|
|
*/ |
| 717 |
|
|
static void |
| 718 |
michael |
9252 |
recurse_remove_clients(struct Client *client, const char *comment) |
| 719 |
adx |
30 |
{ |
| 720 |
michael |
8059 |
dlink_node *node, *node_next; |
| 721 |
adx |
30 |
|
| 722 |
michael |
9252 |
DLINK_FOREACH_SAFE(node, node_next, client->serv->client_list.head) |
| 723 |
michael |
4800 |
exit_one_client(node->data, comment); |
| 724 |
adx |
30 |
|
| 725 |
michael |
9252 |
DLINK_FOREACH_SAFE(node, node_next, client->serv->server_list.head) |
| 726 |
adx |
30 |
{ |
| 727 |
michael |
4800 |
recurse_remove_clients(node->data, comment); |
| 728 |
|
|
exit_one_client(node->data, comment); |
| 729 |
adx |
30 |
} |
| 730 |
|
|
} |
| 731 |
|
|
|
| 732 |
|
|
/* |
| 733 |
|
|
* exit_client - exit a client of any type. Generally, you can use |
| 734 |
|
|
* this on any struct Client, regardless of its state. |
| 735 |
|
|
* |
| 736 |
|
|
* Note, you shouldn't exit remote _users_ without first doing |
| 737 |
michael |
1219 |
* AddFlag(x, FLAGS_KILLED) and propagating a kill or similar message. |
| 738 |
michael |
3171 |
* |
| 739 |
michael |
1219 |
* However, it is perfectly correct to call exit_client to force a _server_ |
| 740 |
adx |
30 |
* quit (either local or remote one). |
| 741 |
|
|
* |
| 742 |
michael |
3171 |
* |
| 743 |
adx |
30 |
* inputs: - a client pointer that is going to be exited |
| 744 |
|
|
* output: none |
| 745 |
|
|
* side effects: the client is delinked from all lists, disconnected, |
| 746 |
|
|
* and the rest of IRC network is notified of the exit. |
| 747 |
|
|
* Client memory is scheduled to be freed |
| 748 |
|
|
*/ |
| 749 |
|
|
void |
| 750 |
michael |
9252 |
exit_client(struct Client *client, const char *comment) |
| 751 |
adx |
30 |
{ |
| 752 |
michael |
9252 |
assert(!IsMe(client)); |
| 753 |
|
|
assert(client != &me); |
| 754 |
michael |
4214 |
|
| 755 |
michael |
9252 |
if (MyConnect(client)) |
| 756 |
adx |
30 |
{ |
| 757 |
michael |
9252 |
assert(client == client->from); |
| 758 |
michael |
8815 |
|
| 759 |
michael |
8059 |
/* |
| 760 |
|
|
* DO NOT REMOVE. exit_client can be called twice after a failed read/write. |
| 761 |
adx |
30 |
*/ |
| 762 |
michael |
9252 |
if (HasFlag(client, FLAGS_CLOSING)) |
| 763 |
adx |
30 |
return; |
| 764 |
|
|
|
| 765 |
michael |
9252 |
AddFlag(client, FLAGS_CLOSING); |
| 766 |
adx |
30 |
|
| 767 |
michael |
9252 |
if (client->connection->auth) |
| 768 |
michael |
8339 |
{ |
| 769 |
michael |
9252 |
auth_delete(client->connection->auth); |
| 770 |
|
|
client->connection->auth = NULL; |
| 771 |
michael |
8339 |
} |
| 772 |
adx |
30 |
|
| 773 |
michael |
9252 |
if (IsClient(client)) |
| 774 |
adx |
30 |
{ |
| 775 |
michael |
8294 |
dlink_node *node; |
| 776 |
|
|
|
| 777 |
michael |
9252 |
if (HasUMode(client, UMODE_OPER)) |
| 778 |
|
|
if ((node = dlinkFindDelete(&oper_list, client))) |
| 779 |
michael |
4800 |
free_dlink_node(node); |
| 780 |
adx |
30 |
|
| 781 |
michael |
9252 |
assert(dlinkFind(&local_client_list, client)); |
| 782 |
|
|
dlinkDelete(&client->connection->lclient_node, &local_client_list); |
| 783 |
michael |
1126 |
|
| 784 |
michael |
9252 |
if (client->connection->list_task) |
| 785 |
|
|
free_list_task(client); |
| 786 |
adx |
30 |
|
| 787 |
michael |
9265 |
invite_clear_list(&client->connection->invited); |
| 788 |
michael |
9252 |
del_all_accepts(client); |
| 789 |
|
|
watch_del_watch_list(client); |
| 790 |
michael |
5551 |
|
| 791 |
michael |
1618 |
sendto_realops_flags(UMODE_CCONN, L_ALL, SEND_NOTICE, |
| 792 |
|
|
"Client exiting: %s (%s@%s) [%s] [%s]", |
| 793 |
michael |
9252 |
client->name, client->username, client->realhost, |
| 794 |
|
|
client->sockhost, comment); |
| 795 |
michael |
4884 |
|
| 796 |
michael |
7337 |
ilog(LOG_TYPE_USER, "%s (%ju): %s!%s@%s %s %s %ju/%ju :%s", |
| 797 |
michael |
9252 |
date_ctime(client->connection->created_real), |
| 798 |
|
|
event_base->time.sec_monotonic - client->connection->created_monotonic, |
| 799 |
|
|
client->name, client->username, client->host, |
| 800 |
|
|
client->sockhost, client->account, |
| 801 |
|
|
client->connection->send.bytes >> 10, |
| 802 |
|
|
client->connection->recv.bytes >> 10, client->info); |
| 803 |
adx |
30 |
} |
| 804 |
michael |
9252 |
else if (IsServer(client)) |
| 805 |
adx |
30 |
{ |
| 806 |
michael |
9252 |
assert(dlinkFind(&local_server_list, client)); |
| 807 |
|
|
dlinkDelete(&client->connection->lclient_node, &local_server_list); |
| 808 |
michael |
8815 |
|
| 809 |
michael |
9252 |
if (!HasFlag(client, FLAGS_SQUIT)) |
| 810 |
michael |
8815 |
/* For them, we are exiting the network */ |
| 811 |
michael |
9252 |
sendto_one(client, ":%s SQUIT %s :%s", me.id, me.id, comment); |
| 812 |
adx |
30 |
} |
| 813 |
michael |
6325 |
else |
| 814 |
|
|
{ |
| 815 |
michael |
9252 |
assert(dlinkFind(&unknown_list, client)); |
| 816 |
|
|
dlinkDelete(&client->connection->lclient_node, &unknown_list); |
| 817 |
michael |
6325 |
} |
| 818 |
adx |
30 |
|
| 819 |
michael |
9252 |
sendto_one(client, "ERROR :Closing Link: %s (%s)", client->host, comment); |
| 820 |
adx |
30 |
|
| 821 |
michael |
9252 |
client_close_connection(client); |
| 822 |
adx |
30 |
} |
| 823 |
michael |
9252 |
else if (IsClient(client) && HasFlag(client->servptr, FLAGS_EOB)) |
| 824 |
michael |
1976 |
sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE, |
| 825 |
michael |
6853 |
"Client exiting at %s: %s (%s@%s) [%s] [%s]", |
| 826 |
michael |
9252 |
client->servptr->name, client->name, |
| 827 |
|
|
client->username, client->realhost, client->sockhost, comment); |
| 828 |
adx |
30 |
|
| 829 |
michael |
9252 |
if (IsServer(client)) |
| 830 |
adx |
30 |
{ |
| 831 |
michael |
9086 |
char splitstr[HOSTLEN + HOSTLEN + 2]; |
| 832 |
adx |
30 |
|
| 833 |
michael |
9252 |
assert(client->serv); |
| 834 |
|
|
assert(client->servptr); |
| 835 |
adx |
30 |
|
| 836 |
|
|
if (ConfigServerHide.hide_servers) |
| 837 |
michael |
887 |
/* |
| 838 |
michael |
8431 |
* Set netsplit message to "*.net *.split" to still show that it's a split, |
| 839 |
|
|
* but hide the servers splitting. |
| 840 |
adx |
30 |
*/ |
| 841 |
michael |
3171 |
strlcpy(splitstr, "*.net *.split", sizeof(splitstr)); |
| 842 |
adx |
30 |
else |
| 843 |
|
|
snprintf(splitstr, sizeof(splitstr), "%s %s", |
| 844 |
michael |
9252 |
client->servptr->name, client->name); |
| 845 |
adx |
30 |
|
| 846 |
michael |
9252 |
/* Send SQUIT for 'client' in every direction. 'client' is already off of local_server_list here */ |
| 847 |
|
|
if (!HasFlag(client, FLAGS_SQUIT)) |
| 848 |
|
|
sendto_server(NULL, 0, 0, "SQUIT %s :%s", client->id, comment); |
| 849 |
adx |
30 |
|
| 850 |
michael |
3171 |
/* Now exit the clients internally */ |
| 851 |
michael |
9252 |
recurse_remove_clients(client, splitstr); |
| 852 |
michael |
3171 |
|
| 853 |
michael |
9252 |
if (MyConnect(client)) |
| 854 |
adx |
30 |
{ |
| 855 |
michael |
6318 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
| 856 |
michael |
6782 |
"%s was connected for %s. %ju/%ju sendK/recvK.", |
| 857 |
michael |
9252 |
client->name, time_dissect(event_base->time.sec_monotonic - client->connection->created_monotonic), |
| 858 |
|
|
client->connection->send.bytes >> 10, |
| 859 |
|
|
client->connection->recv.bytes >> 10); |
| 860 |
michael |
6782 |
ilog(LOG_TYPE_IRCD, "%s was connected for %s. %ju/%ju sendK/recvK.", |
| 861 |
michael |
9252 |
client->name, time_dissect(event_base->time.sec_monotonic - client->connection->created_monotonic), |
| 862 |
|
|
client->connection->send.bytes >> 10, |
| 863 |
|
|
client->connection->recv.bytes >> 10); |
| 864 |
adx |
30 |
} |
| 865 |
|
|
} |
| 866 |
michael |
9252 |
else if (IsClient(client) && !HasFlag(client, FLAGS_KILLED)) |
| 867 |
|
|
sendto_server(client->from, 0, 0, ":%s QUIT :%s", client->id, comment); |
| 868 |
adx |
30 |
|
| 869 |
|
|
/* The client *better* be off all of the lists */ |
| 870 |
michael |
9252 |
assert(dlinkFind(&unknown_list, client) == NULL); |
| 871 |
|
|
assert(dlinkFind(&local_client_list, client) == NULL); |
| 872 |
|
|
assert(dlinkFind(&local_server_list, client) == NULL); |
| 873 |
|
|
assert(dlinkFind(&oper_list, client) == NULL); |
| 874 |
|
|
assert(dlinkFind(&listing_client_list, client) == NULL); |
| 875 |
|
|
assert(dlinkFind(&abort_list, client) == NULL); |
| 876 |
adx |
30 |
|
| 877 |
michael |
9252 |
exit_one_client(client, comment); |
| 878 |
adx |
30 |
} |
| 879 |
|
|
|
| 880 |
|
|
/* |
| 881 |
|
|
* dead_link_on_write - report a write error if not already dead, |
| 882 |
|
|
* mark it as dead then exit it |
| 883 |
|
|
*/ |
| 884 |
|
|
void |
| 885 |
michael |
9250 |
dead_link_on_write(struct Client *client, int ierrno) |
| 886 |
adx |
30 |
{ |
| 887 |
michael |
4800 |
dlink_node *node; |
| 888 |
adx |
30 |
|
| 889 |
michael |
9250 |
if (IsDefunct(client)) |
| 890 |
adx |
30 |
return; |
| 891 |
|
|
|
| 892 |
michael |
9250 |
dbuf_clear(&client->connection->buf_recvq); |
| 893 |
|
|
dbuf_clear(&client->connection->buf_sendq); |
| 894 |
adx |
30 |
|
| 895 |
michael |
9250 |
assert(dlinkFind(&abort_list, client) == NULL); |
| 896 |
michael |
4800 |
node = make_dlink_node(); |
| 897 |
adx |
30 |
/* don't let exit_aborted_clients() finish yet */ |
| 898 |
michael |
9250 |
dlinkAddTail(client, node, &abort_list); |
| 899 |
adx |
30 |
|
| 900 |
|
|
if (eac_next == NULL) |
| 901 |
michael |
4800 |
eac_next = node; |
| 902 |
adx |
30 |
|
| 903 |
michael |
9250 |
SetDead(client); /* You are dead my friend */ |
| 904 |
adx |
30 |
} |
| 905 |
|
|
|
| 906 |
|
|
/* |
| 907 |
|
|
* dead_link_on_read - report a read error if not already dead, |
| 908 |
|
|
* mark it as dead then exit it |
| 909 |
|
|
*/ |
| 910 |
|
|
void |
| 911 |
michael |
9250 |
dead_link_on_read(struct Client *client, int error) |
| 912 |
adx |
30 |
{ |
| 913 |
michael |
2691 |
char errmsg[IRCD_BUFSIZE]; |
| 914 |
adx |
30 |
int current_error; |
| 915 |
|
|
|
| 916 |
michael |
9250 |
if (IsDefunct(client)) |
| 917 |
adx |
30 |
return; |
| 918 |
|
|
|
| 919 |
michael |
9250 |
dbuf_clear(&client->connection->buf_recvq); |
| 920 |
|
|
dbuf_clear(&client->connection->buf_sendq); |
| 921 |
adx |
30 |
|
| 922 |
michael |
9250 |
current_error = comm_get_sockerr(client->connection->fd); |
| 923 |
adx |
30 |
|
| 924 |
michael |
9250 |
if (IsServer(client) || IsHandshake(client)) |
| 925 |
adx |
30 |
{ |
| 926 |
|
|
if (error == 0) |
| 927 |
|
|
{ |
| 928 |
michael |
6318 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, |
| 929 |
michael |
2182 |
"Server %s closed the connection", |
| 930 |
michael |
9250 |
client_get_name(client, SHOW_IP)); |
| 931 |
michael |
6318 |
sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE, |
| 932 |
michael |
2182 |
"Server %s closed the connection", |
| 933 |
michael |
9250 |
client_get_name(client, MASK_IP)); |
| 934 |
michael |
1247 |
ilog(LOG_TYPE_IRCD, "Server %s closed the connection", |
| 935 |
michael |
9250 |
client_get_name(client, SHOW_IP)); |
| 936 |
adx |
30 |
} |
| 937 |
|
|
else |
| 938 |
|
|
{ |
| 939 |
michael |
8399 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE, |
| 940 |
|
|
"Lost connection to %s: %s", |
| 941 |
michael |
9250 |
client_get_name(client, SHOW_IP), strerror(current_error)); |
| 942 |
michael |
8399 |
sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE, |
| 943 |
|
|
"Lost connection to %s: %s", |
| 944 |
michael |
9250 |
client_get_name(client, MASK_IP), strerror(current_error)); |
| 945 |
michael |
8399 |
ilog(LOG_TYPE_IRCD, "Lost connection to %s: %s", |
| 946 |
michael |
9250 |
client_get_name(client, SHOW_IP), strerror(current_error)); |
| 947 |
adx |
30 |
} |
| 948 |
|
|
|
| 949 |
michael |
6318 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
| 950 |
michael |
6569 |
"%s was connected for %s", |
| 951 |
michael |
9250 |
client->name, time_dissect(event_base->time.sec_monotonic - client->connection->created_monotonic)); |
| 952 |
adx |
30 |
} |
| 953 |
|
|
|
| 954 |
|
|
if (error == 0) |
| 955 |
|
|
strlcpy(errmsg, "Remote host closed the connection", |
| 956 |
|
|
sizeof(errmsg)); |
| 957 |
|
|
else |
| 958 |
michael |
1124 |
snprintf(errmsg, sizeof(errmsg), "Read error: %s", |
| 959 |
|
|
strerror(current_error)); |
| 960 |
adx |
30 |
|
| 961 |
michael |
9250 |
exit_client(client, errmsg); |
| 962 |
adx |
30 |
} |
| 963 |
|
|
|
| 964 |
|
|
void |
| 965 |
|
|
exit_aborted_clients(void) |
| 966 |
|
|
{ |
| 967 |
|
|
dlink_node *ptr; |
| 968 |
|
|
const char *notice; |
| 969 |
|
|
|
| 970 |
|
|
DLINK_FOREACH_SAFE(ptr, eac_next, abort_list.head) |
| 971 |
|
|
{ |
| 972 |
michael |
9250 |
struct Client *client = ptr->data; |
| 973 |
adx |
30 |
eac_next = ptr->next; |
| 974 |
|
|
|
| 975 |
michael |
8292 |
dlinkDelete(ptr, &abort_list); |
| 976 |
|
|
free_dlink_node(ptr); |
| 977 |
|
|
|
| 978 |
michael |
9250 |
if (client == NULL) |
| 979 |
adx |
30 |
{ |
| 980 |
michael |
6318 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
| 981 |
adx |
30 |
"Warning: null client on abort_list!"); |
| 982 |
|
|
continue; |
| 983 |
|
|
} |
| 984 |
|
|
|
| 985 |
michael |
9250 |
if (HasFlag(client, FLAGS_SENDQEX)) |
| 986 |
adx |
30 |
notice = "Max SendQ exceeded"; |
| 987 |
|
|
else |
| 988 |
|
|
notice = "Write error: connection closed"; |
| 989 |
|
|
|
| 990 |
michael |
9250 |
exit_client(client, notice); |
| 991 |
adx |
30 |
} |
| 992 |
|
|
} |
| 993 |
|
|
|
| 994 |
|
|
/* |
| 995 |
|
|
* accept processing, this adds a form of "caller ID" to ircd |
| 996 |
michael |
887 |
* |
| 997 |
adx |
30 |
* If a client puts themselves into "caller ID only" mode, |
| 998 |
michael |
887 |
* only clients that match a client pointer they have put on |
| 999 |
adx |
30 |
* the accept list will be allowed to message them. |
| 1000 |
|
|
* |
| 1001 |
michael |
887 |
* Diane Bruce, "Dianora" db@db.net |
| 1002 |
adx |
30 |
*/ |
| 1003 |
|
|
|
| 1004 |
michael |
887 |
void |
| 1005 |
michael |
9250 |
del_accept(struct split_nuh_item *accept_p, struct Client *client) |
| 1006 |
adx |
30 |
{ |
| 1007 |
michael |
9250 |
dlinkDelete(&accept_p->node, &client->connection->acceptlist); |
| 1008 |
adx |
30 |
|
| 1009 |
michael |
7032 |
xfree(accept_p->nickptr); |
| 1010 |
|
|
xfree(accept_p->userptr); |
| 1011 |
|
|
xfree(accept_p->hostptr); |
| 1012 |
|
|
xfree(accept_p); |
| 1013 |
michael |
887 |
} |
| 1014 |
adx |
30 |
|
| 1015 |
michael |
887 |
struct split_nuh_item * |
| 1016 |
|
|
find_accept(const char *nick, const char *user, |
| 1017 |
michael |
9250 |
const char *host, struct Client *client, |
| 1018 |
michael |
8437 |
int (*compare)(const char *, const char *)) |
| 1019 |
michael |
887 |
{ |
| 1020 |
michael |
7987 |
dlink_node *node; |
| 1021 |
adx |
30 |
|
| 1022 |
michael |
9250 |
DLINK_FOREACH(node, client->connection->acceptlist.head) |
| 1023 |
adx |
30 |
{ |
| 1024 |
michael |
4975 |
struct split_nuh_item *accept_p = node->data; |
| 1025 |
michael |
887 |
|
| 1026 |
michael |
8512 |
if (compare(accept_p->nickptr, nick) == 0 && |
| 1027 |
|
|
compare(accept_p->userptr, user) == 0 && |
| 1028 |
|
|
compare(accept_p->hostptr, host) == 0) |
| 1029 |
michael |
4975 |
return accept_p; |
| 1030 |
adx |
30 |
} |
| 1031 |
|
|
|
| 1032 |
michael |
887 |
return NULL; |
| 1033 |
adx |
30 |
} |
| 1034 |
|
|
|
| 1035 |
michael |
887 |
/* accept_message() |
| 1036 |
adx |
30 |
* |
| 1037 |
michael |
887 |
* inputs - pointer to source client |
| 1038 |
|
|
* - pointer to target client |
| 1039 |
|
|
* output - 1 if accept this message 0 if not |
| 1040 |
|
|
* side effects - See if source is on target's allow list |
| 1041 |
adx |
30 |
*/ |
| 1042 |
michael |
8656 |
bool |
| 1043 |
michael |
887 |
accept_message(struct Client *source, |
| 1044 |
|
|
struct Client *target) |
| 1045 |
adx |
30 |
{ |
| 1046 |
michael |
8059 |
dlink_node *node; |
| 1047 |
adx |
30 |
|
| 1048 |
michael |
5451 |
if (HasFlag(source, FLAGS_SERVICE) || |
| 1049 |
|
|
(HasUMode(source, UMODE_OPER) && ConfigGeneral.opers_bypass_callerid)) |
| 1050 |
michael |
8656 |
return true; |
| 1051 |
michael |
5451 |
|
| 1052 |
michael |
887 |
if (source == target || find_accept(source->name, source->username, |
| 1053 |
michael |
2363 |
source->host, target, match)) |
| 1054 |
michael |
8656 |
return true; |
| 1055 |
adx |
30 |
|
| 1056 |
michael |
4660 |
if (!HasUMode(target, UMODE_CALLERID) && HasUMode(target, UMODE_SOFTCALLERID)) |
| 1057 |
michael |
4800 |
DLINK_FOREACH(node, target->channel.head) |
| 1058 |
michael |
9081 |
if (IsMember(source, ((struct ChannelMember *)node->data)->channel)) |
| 1059 |
michael |
8656 |
return true; |
| 1060 |
adx |
30 |
|
| 1061 |
michael |
8656 |
return false; |
| 1062 |
adx |
30 |
} |
| 1063 |
|
|
|
| 1064 |
|
|
/* del_all_accepts() |
| 1065 |
|
|
* |
| 1066 |
michael |
887 |
* inputs - pointer to exiting client |
| 1067 |
|
|
* output - NONE |
| 1068 |
|
|
* side effects - Walk through given clients acceptlist and remove all entries |
| 1069 |
adx |
30 |
*/ |
| 1070 |
|
|
void |
| 1071 |
michael |
9250 |
del_all_accepts(struct Client *client) |
| 1072 |
adx |
30 |
{ |
| 1073 |
michael |
7987 |
dlink_node *node, *node_next; |
| 1074 |
adx |
30 |
|
| 1075 |
michael |
9250 |
DLINK_FOREACH_SAFE(node, node_next, client->connection->acceptlist.head) |
| 1076 |
|
|
del_accept(node->data, client); |
| 1077 |
adx |
30 |
} |
| 1078 |
michael |
1783 |
|
| 1079 |
|
|
unsigned int |
| 1080 |
michael |
5545 |
client_get_idle_time(const struct Client *source_p, |
| 1081 |
|
|
const struct Client *target_p) |
| 1082 |
michael |
1783 |
{ |
| 1083 |
|
|
unsigned int idle = 0; |
| 1084 |
michael |
8437 |
const struct ClassItem *const class = class_get_ptr(&target_p->connection->confs); |
| 1085 |
michael |
1783 |
|
| 1086 |
michael |
1785 |
if (!(class->flags & CLASS_FLAGS_FAKE_IDLE) || target_p == source_p) |
| 1087 |
michael |
8907 |
return event_base->time.sec_monotonic - target_p->connection->last_privmsg; |
| 1088 |
michael |
4884 |
|
| 1089 |
michael |
1783 |
if (HasUMode(source_p, UMODE_OPER) && |
| 1090 |
michael |
1785 |
!(class->flags & CLASS_FLAGS_HIDE_IDLE_FROM_OPERS)) |
| 1091 |
michael |
8907 |
return event_base->time.sec_monotonic - target_p->connection->last_privmsg; |
| 1092 |
michael |
1783 |
|
| 1093 |
michael |
7987 |
const unsigned int min_idle = class->min_idle; |
| 1094 |
|
|
const unsigned int max_idle = class->max_idle; |
| 1095 |
michael |
1783 |
|
| 1096 |
|
|
if (min_idle == max_idle) |
| 1097 |
|
|
return min_idle; |
| 1098 |
|
|
|
| 1099 |
|
|
if (class->flags & CLASS_FLAGS_RANDOM_IDLE) |
| 1100 |
|
|
idle = genrand_int32(); |
| 1101 |
|
|
else |
| 1102 |
michael |
8907 |
idle = event_base->time.sec_monotonic - target_p->connection->last_privmsg; |
| 1103 |
michael |
1783 |
|
| 1104 |
michael |
7870 |
if (max_idle) |
| 1105 |
|
|
idle %= max_idle; |
| 1106 |
|
|
else |
| 1107 |
michael |
1783 |
idle = 0; |
| 1108 |
|
|
|
| 1109 |
|
|
if (idle < min_idle) |
| 1110 |
|
|
idle = min_idle + (idle % (max_idle - min_idle)); |
| 1111 |
|
|
|
| 1112 |
|
|
return idle; |
| 1113 |
|
|
} |
| 1114 |
michael |
4214 |
|
| 1115 |
|
|
/* client_init() |
| 1116 |
|
|
* |
| 1117 |
|
|
* inputs - NONE |
| 1118 |
|
|
* output - NONE |
| 1119 |
|
|
* side effects - initialize client free memory |
| 1120 |
|
|
*/ |
| 1121 |
|
|
void |
| 1122 |
|
|
client_init(void) |
| 1123 |
|
|
{ |
| 1124 |
|
|
static struct event event_ping = |
| 1125 |
|
|
{ |
| 1126 |
|
|
.name = "check_pings", |
| 1127 |
|
|
.handler = check_pings, |
| 1128 |
|
|
.when = 5 |
| 1129 |
|
|
}; |
| 1130 |
|
|
|
| 1131 |
|
|
event_add(&event_ping, NULL); |
| 1132 |
|
|
} |