| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
* client.c: Controls clients. |
| 4 |
* |
| 5 |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
* (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 20 |
* USA |
| 21 |
* |
| 22 |
* $Id$ |
| 23 |
*/ |
| 24 |
|
| 25 |
#include "stdinc.h" |
| 26 |
#include "client.h" |
| 27 |
#include "channel_mode.h" |
| 28 |
#include "common.h" |
| 29 |
#include "hash.h" |
| 30 |
#include "ircd.h" |
| 31 |
#include "s_gline.h" |
| 32 |
#include "numeric.h" |
| 33 |
#include "packet.h" |
| 34 |
#include "s_auth.h" |
| 35 |
#include "s_conf.h" |
| 36 |
#include "parse_aline.h" |
| 37 |
#include "s_serv.h" |
| 38 |
#include "send.h" |
| 39 |
#include "whowas.h" |
| 40 |
#include "s_user.h" |
| 41 |
#include "hostmask.h" |
| 42 |
#include "listener.h" |
| 43 |
#include "userhost.h" |
| 44 |
#include "s_stats.h" |
| 45 |
|
| 46 |
dlink_list listing_client_list = { NULL, NULL, 0 }; |
| 47 |
/* Pointer to beginning of Client list */ |
| 48 |
dlink_list global_client_list = {NULL, NULL, 0}; |
| 49 |
/* unknown/client pointer lists */ |
| 50 |
dlink_list unknown_list = {NULL, NULL, 0}; |
| 51 |
dlink_list local_client_list = {NULL, NULL, 0}; |
| 52 |
dlink_list serv_list = {NULL, NULL, 0}; |
| 53 |
dlink_list global_serv_list = {NULL, NULL, 0}; |
| 54 |
dlink_list oper_list = {NULL, NULL, 0}; |
| 55 |
|
| 56 |
static EVH check_pings; |
| 57 |
|
| 58 |
static BlockHeap *client_heap = NULL; |
| 59 |
static BlockHeap *lclient_heap = NULL; |
| 60 |
|
| 61 |
static dlink_list dead_list = { NULL, NULL, 0}; |
| 62 |
static dlink_list abort_list = { NULL, NULL, 0}; |
| 63 |
|
| 64 |
static dlink_node *eac_next; /* next aborted client to exit */ |
| 65 |
|
| 66 |
static void check_pings_list(dlink_list *); |
| 67 |
static void check_unknowns_list(void); |
| 68 |
static void close_connection(struct Client *); |
| 69 |
static void ban_them(struct Client *client_p, struct ConfItem *conf); |
| 70 |
|
| 71 |
|
| 72 |
/* init_client() |
| 73 |
* |
| 74 |
* inputs - NONE |
| 75 |
* output - NONE |
| 76 |
* side effects - initialize client free memory |
| 77 |
*/ |
| 78 |
void |
| 79 |
init_client(void) |
| 80 |
{ |
| 81 |
/* start off the check ping event .. -- adrian |
| 82 |
* Every 30 seconds is plenty -- db |
| 83 |
*/ |
| 84 |
client_heap = BlockHeapCreate("client", sizeof(struct Client), CLIENT_HEAP_SIZE); |
| 85 |
lclient_heap = BlockHeapCreate("local client", sizeof(struct LocalUser), LCLIENT_HEAP_SIZE); |
| 86 |
eventAdd("check_pings", check_pings, NULL, 5); |
| 87 |
} |
| 88 |
|
| 89 |
/* |
| 90 |
* make_client - create a new Client struct and set it to initial state. |
| 91 |
* |
| 92 |
* from == NULL, create local client (a client connected |
| 93 |
* to a socket). |
| 94 |
* WARNING: This leaves the client in a dangerous |
| 95 |
* state where fd == -1, dead flag is not set and |
| 96 |
* the client is on the unknown_list; therefore, |
| 97 |
* the first thing to do after calling make_client(NULL) |
| 98 |
* is setting fd to something reasonable. -adx |
| 99 |
* |
| 100 |
* from, create remote client (behind a socket |
| 101 |
* associated with the client defined by |
| 102 |
* 'from'). ('from' is a local client!!). |
| 103 |
*/ |
| 104 |
struct Client * |
| 105 |
make_client(struct Client *from) |
| 106 |
{ |
| 107 |
struct Client *client_p = BlockHeapAlloc(client_heap); |
| 108 |
|
| 109 |
if (from == NULL) |
| 110 |
{ |
| 111 |
client_p->from = client_p; /* 'from' of local client is self! */ |
| 112 |
client_p->since = client_p->lasttime = client_p->firsttime = CurrentTime; |
| 113 |
|
| 114 |
client_p->localClient = BlockHeapAlloc(lclient_heap); |
| 115 |
/* as good a place as any... */ |
| 116 |
dlinkAdd(client_p, make_dlink_node(), &unknown_list); |
| 117 |
} |
| 118 |
else |
| 119 |
client_p->from = from; /* 'from' of local client is self! */ |
| 120 |
|
| 121 |
client_p->hnext = client_p; |
| 122 |
client_p->status = STAT_UNKNOWN; |
| 123 |
strcpy(client_p->username, "unknown"); |
| 124 |
|
| 125 |
return client_p; |
| 126 |
} |
| 127 |
|
| 128 |
/* |
| 129 |
* free_client |
| 130 |
* |
| 131 |
* inputs - pointer to client |
| 132 |
* output - NONE |
| 133 |
* side effects - client pointed to has its memory freed |
| 134 |
*/ |
| 135 |
static void |
| 136 |
free_client(struct Client *client_p) |
| 137 |
{ |
| 138 |
assert(client_p != NULL); |
| 139 |
assert(client_p != &me); |
| 140 |
assert(client_p->hnext == client_p); |
| 141 |
assert(client_p->invited.head == NULL); |
| 142 |
assert(client_p->channel.head == NULL); |
| 143 |
assert(dlink_list_length(&client_p->invited) == 0); |
| 144 |
assert(dlink_list_length(&client_p->channel) == 0); |
| 145 |
|
| 146 |
MyFree(client_p->away); |
| 147 |
MyFree(client_p->serv); |
| 148 |
|
| 149 |
if (MyConnect(client_p)) |
| 150 |
{ |
| 151 |
assert(IsClosing(client_p) && IsDead(client_p)); |
| 152 |
|
| 153 |
MyFree(client_p->localClient->response); |
| 154 |
MyFree(client_p->localClient->auth_oper); |
| 155 |
|
| 156 |
/* |
| 157 |
* clean up extra sockets from P-lines which have been discarded. |
| 158 |
*/ |
| 159 |
if (client_p->localClient->listener) |
| 160 |
{ |
| 161 |
assert(0 < client_p->localClient->listener->ref_count); |
| 162 |
if (0 == --client_p->localClient->listener->ref_count && |
| 163 |
!client_p->localClient->listener->active) |
| 164 |
free_listener(client_p->localClient->listener); |
| 165 |
} |
| 166 |
|
| 167 |
dbuf_clear(&client_p->localClient->buf_recvq); |
| 168 |
dbuf_clear(&client_p->localClient->buf_sendq); |
| 169 |
|
| 170 |
BlockHeapFree(lclient_heap, client_p->localClient); |
| 171 |
} |
| 172 |
|
| 173 |
BlockHeapFree(client_heap, client_p); |
| 174 |
} |
| 175 |
|
| 176 |
/* |
| 177 |
* check_pings - go through the local client list and check activity |
| 178 |
* kill off stuff that should die |
| 179 |
* |
| 180 |
* inputs - NOT USED (from event) |
| 181 |
* output - next time_t when check_pings() should be called again |
| 182 |
* side effects - |
| 183 |
* |
| 184 |
* |
| 185 |
* A PING can be sent to clients as necessary. |
| 186 |
* |
| 187 |
* Client/Server ping outs are handled. |
| 188 |
*/ |
| 189 |
|
| 190 |
/* |
| 191 |
* Addon from adrian. We used to call this after nextping seconds, |
| 192 |
* however I've changed it to run once a second. This is only for |
| 193 |
* PING timeouts, not K/etc-line checks (thanks dianora!). Having it |
| 194 |
* run once a second makes life a lot easier - when a new client connects |
| 195 |
* and they need a ping in 4 seconds, if nextping was set to 20 seconds |
| 196 |
* we end up waiting 20 seconds. This is stupid. :-) |
| 197 |
* I will optimise (hah!) check_pings() once I've finished working on |
| 198 |
* tidying up other network IO evilnesses. |
| 199 |
* -- adrian |
| 200 |
*/ |
| 201 |
|
| 202 |
static void |
| 203 |
check_pings(void *notused) |
| 204 |
{ |
| 205 |
check_pings_list(&local_client_list); |
| 206 |
check_pings_list(&serv_list); |
| 207 |
check_unknowns_list(); |
| 208 |
} |
| 209 |
|
| 210 |
/* check_pings_list() |
| 211 |
* |
| 212 |
* inputs - pointer to list to check |
| 213 |
* output - NONE |
| 214 |
* side effects - |
| 215 |
*/ |
| 216 |
static void |
| 217 |
check_pings_list(dlink_list *list) |
| 218 |
{ |
| 219 |
char scratch[32]; /* way too generous but... */ |
| 220 |
struct Client *client_p; /* current local client_p being examined */ |
| 221 |
int ping, pingwarn; /* ping time value from client */ |
| 222 |
dlink_node *ptr, *next_ptr; |
| 223 |
|
| 224 |
DLINK_FOREACH_SAFE(ptr, next_ptr, list->head) |
| 225 |
{ |
| 226 |
client_p = ptr->data; |
| 227 |
|
| 228 |
/* |
| 229 |
** Note: No need to notify opers here. It's |
| 230 |
** already done when "FLAGS_DEADSOCKET" is set. |
| 231 |
*/ |
| 232 |
if (IsDead(client_p)) |
| 233 |
{ |
| 234 |
/* Ignore it, its been exited already */ |
| 235 |
continue; |
| 236 |
} |
| 237 |
|
| 238 |
if (client_p->localClient->reject_delay > 0) |
| 239 |
{ |
| 240 |
if (client_p->localClient->reject_delay <= CurrentTime) |
| 241 |
exit_client(client_p, &me, "Rejected"); |
| 242 |
continue; |
| 243 |
} |
| 244 |
|
| 245 |
if (GlobalSetOptions.idletime && IsClient(client_p)) |
| 246 |
{ |
| 247 |
if (!IsExemptKline(client_p) && !IsOper(client_p) && |
| 248 |
!IsIdlelined(client_p) && |
| 249 |
((CurrentTime - client_p->localClient->last) > GlobalSetOptions.idletime)) |
| 250 |
{ |
| 251 |
struct ConfItem *conf; |
| 252 |
struct AccessItem *aconf; |
| 253 |
|
| 254 |
conf = make_conf_item(KLINE_TYPE); |
| 255 |
aconf = &conf->conf.AccessItem; |
| 256 |
|
| 257 |
DupString(aconf->host, client_p->host); |
| 258 |
DupString(aconf->reason, "idle exceeder"); |
| 259 |
DupString(aconf->user, client_p->username); |
| 260 |
aconf->hold = CurrentTime + 60; |
| 261 |
add_temp_line(conf); |
| 262 |
|
| 263 |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 264 |
"Idle time limit exceeded for %s - temp k-lining", |
| 265 |
get_client_name(client_p, HIDE_IP)); |
| 266 |
exit_client(client_p, &me, aconf->reason); |
| 267 |
continue; |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
if (!IsRegistered(client_p)) |
| 272 |
ping = CONNECTTIMEOUT, pingwarn = 0; |
| 273 |
else |
| 274 |
ping = get_client_ping(client_p, &pingwarn); |
| 275 |
|
| 276 |
if (ping < CurrentTime - client_p->lasttime) |
| 277 |
{ |
| 278 |
if (!IsPingSent(client_p)) |
| 279 |
{ |
| 280 |
/* |
| 281 |
* if we havent PINGed the connection and we havent |
| 282 |
* heard from it in a while, PING it to make sure |
| 283 |
* it is still alive. |
| 284 |
*/ |
| 285 |
SetPingSent(client_p); |
| 286 |
ClearPingWarning(client_p); |
| 287 |
client_p->lasttime = CurrentTime - ping; |
| 288 |
sendto_one(client_p, "PING :%s", ID_or_name(&me, client_p)); |
| 289 |
} |
| 290 |
else |
| 291 |
{ |
| 292 |
if (CurrentTime - client_p->lasttime >= 2 * ping) |
| 293 |
{ |
| 294 |
/* |
| 295 |
* If the client/server hasn't talked to us in 2*ping seconds |
| 296 |
* and it has a ping time, then close its connection. |
| 297 |
*/ |
| 298 |
if (IsServer(client_p) || IsHandshake(client_p)) |
| 299 |
{ |
| 300 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
| 301 |
"No response from %s, closing link", |
| 302 |
get_client_name(client_p, HIDE_IP)); |
| 303 |
sendto_realops_flags(UMODE_ALL, L_OPER, |
| 304 |
"No response from %s, closing link", |
| 305 |
get_client_name(client_p, MASK_IP)); |
| 306 |
ilog(L_NOTICE, "No response from %s, closing link", |
| 307 |
get_client_name(client_p, HIDE_IP)); |
| 308 |
} |
| 309 |
ircsprintf(scratch, "Ping timeout: %d seconds", |
| 310 |
(int)(CurrentTime - client_p->lasttime)); |
| 311 |
|
| 312 |
exit_client(client_p, &me, scratch); |
| 313 |
} |
| 314 |
else if (!IsPingWarning(client_p) && pingwarn > 0 && |
| 315 |
(IsServer(client_p) || IsHandshake(client_p)) && |
| 316 |
CurrentTime - client_p->lasttime >= ping + pingwarn) |
| 317 |
{ |
| 318 |
/* |
| 319 |
* If the server hasn't replied in pingwarn seconds after sending |
| 320 |
* the PING, notify the opers so that they are aware of the problem. |
| 321 |
*/ |
| 322 |
SetPingWarning(client_p); |
| 323 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
| 324 |
"Warning, no response from %s in %d seconds", |
| 325 |
get_client_name(client_p, HIDE_IP), pingwarn); |
| 326 |
sendto_realops_flags(UMODE_ALL, L_OPER, |
| 327 |
"Warning, no response from %s in %d seconds", |
| 328 |
get_client_name(client_p, MASK_IP), pingwarn); |
| 329 |
ilog(L_NOTICE, "No response from %s in %d seconds", |
| 330 |
get_client_name(client_p, HIDE_IP), pingwarn); |
| 331 |
} |
| 332 |
} |
| 333 |
} |
| 334 |
} |
| 335 |
} |
| 336 |
|
| 337 |
/* check_unknowns_list() |
| 338 |
* |
| 339 |
* inputs - pointer to list of unknown clients |
| 340 |
* output - NONE |
| 341 |
* side effects - unknown clients get marked for termination after n seconds |
| 342 |
*/ |
| 343 |
static void |
| 344 |
check_unknowns_list(void) |
| 345 |
{ |
| 346 |
dlink_node *ptr, *next_ptr; |
| 347 |
|
| 348 |
DLINK_FOREACH_SAFE(ptr, next_ptr, unknown_list.head) |
| 349 |
{ |
| 350 |
struct Client *client_p = ptr->data; |
| 351 |
|
| 352 |
if (client_p->localClient->reject_delay > 0) |
| 353 |
{ |
| 354 |
if (client_p->localClient->reject_delay <= CurrentTime) |
| 355 |
exit_client(client_p, &me, "Rejected"); |
| 356 |
continue; |
| 357 |
} |
| 358 |
|
| 359 |
/* Check UNKNOWN connections - if they have been in this state |
| 360 |
* for > 30s, close them. |
| 361 |
*/ |
| 362 |
if (client_p->firsttime ? ((CurrentTime - client_p->firsttime) > 30) : 0) |
| 363 |
exit_client(client_p, &me, "Connection timed out"); |
| 364 |
} |
| 365 |
} |
| 366 |
|
| 367 |
/* check_conf_klines() |
| 368 |
* |
| 369 |
* inputs - NONE |
| 370 |
* output - NONE |
| 371 |
* side effects - Check all connections for a pending kline against the |
| 372 |
* client, exit the client if a kline matches. |
| 373 |
*/ |
| 374 |
void |
| 375 |
check_conf_klines(void) |
| 376 |
{ |
| 377 |
struct Client *client_p = NULL; /* current local client_p being examined */ |
| 378 |
struct AccessItem *aconf = NULL; |
| 379 |
struct ConfItem *conf = NULL; |
| 380 |
dlink_node *ptr, *next_ptr; |
| 381 |
|
| 382 |
DLINK_FOREACH_SAFE(ptr, next_ptr, local_client_list.head) |
| 383 |
{ |
| 384 |
client_p = ptr->data; |
| 385 |
|
| 386 |
/* If a client is already being exited |
| 387 |
*/ |
| 388 |
if (IsDead(client_p) || !IsClient(client_p)) |
| 389 |
continue; |
| 390 |
|
| 391 |
/* if there is a returned struct ConfItem then kill it */ |
| 392 |
if ((aconf = find_dline_conf(&client_p->localClient->ip, |
| 393 |
client_p->localClient->aftype)) != NULL) |
| 394 |
{ |
| 395 |
if (aconf->status & CONF_EXEMPTDLINE) |
| 396 |
continue; |
| 397 |
|
| 398 |
conf = aconf->conf_ptr; |
| 399 |
ban_them(client_p, conf); |
| 400 |
continue; /* and go examine next fd/client_p */ |
| 401 |
} |
| 402 |
|
| 403 |
if (ConfigFileEntry.glines && (aconf = find_gline(client_p))) |
| 404 |
{ |
| 405 |
if (IsExemptKline(client_p) || |
| 406 |
IsExemptGline(client_p)) |
| 407 |
{ |
| 408 |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 409 |
"GLINE over-ruled for %s, client is %sline_exempt", |
| 410 |
get_client_name(client_p, HIDE_IP), IsExemptKline(client_p) ? "k" : "g"); |
| 411 |
continue; |
| 412 |
} |
| 413 |
|
| 414 |
conf = aconf->conf_ptr; |
| 415 |
ban_them(client_p, conf); |
| 416 |
/* and go examine next fd/client_p */ |
| 417 |
continue; |
| 418 |
} |
| 419 |
|
| 420 |
if ((aconf = find_kill(client_p)) != NULL) |
| 421 |
{ |
| 422 |
|
| 423 |
/* if there is a returned struct AccessItem.. then kill it */ |
| 424 |
if (IsExemptKline(client_p)) |
| 425 |
{ |
| 426 |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 427 |
"KLINE over-ruled for %s, client is kline_exempt", |
| 428 |
get_client_name(client_p, HIDE_IP)); |
| 429 |
continue; |
| 430 |
} |
| 431 |
|
| 432 |
conf = aconf->conf_ptr; |
| 433 |
ban_them(client_p, conf); |
| 434 |
continue; |
| 435 |
} |
| 436 |
|
| 437 |
/* if there is a returned struct MatchItem then kill it */ |
| 438 |
if ((conf = find_matching_name_conf(XLINE_TYPE, client_p->info, |
| 439 |
NULL, NULL, 0)) != NULL || |
| 440 |
(conf = find_matching_name_conf(RXLINE_TYPE, client_p->info, |
| 441 |
NULL, NULL, 0)) != NULL) |
| 442 |
{ |
| 443 |
ban_them(client_p, conf); |
| 444 |
continue; |
| 445 |
} |
| 446 |
} |
| 447 |
|
| 448 |
/* also check the unknowns list for new dlines */ |
| 449 |
DLINK_FOREACH_SAFE(ptr, next_ptr, unknown_list.head) |
| 450 |
{ |
| 451 |
client_p = ptr->data; |
| 452 |
|
| 453 |
if ((aconf = find_dline_conf(&client_p->localClient->ip, |
| 454 |
client_p->localClient->aftype))) |
| 455 |
{ |
| 456 |
if (aconf->status & CONF_EXEMPTDLINE) |
| 457 |
continue; |
| 458 |
|
| 459 |
exit_client(client_p, &me, "D-lined"); |
| 460 |
} |
| 461 |
} |
| 462 |
} |
| 463 |
|
| 464 |
/* |
| 465 |
* ban_them |
| 466 |
* |
| 467 |
* inputs - pointer to client to ban |
| 468 |
* - pointer to ConfItem |
| 469 |
* output - NONE |
| 470 |
* side effects - given client_p is banned |
| 471 |
*/ |
| 472 |
static void |
| 473 |
ban_them(struct Client *client_p, struct ConfItem *conf) |
| 474 |
{ |
| 475 |
const char *user_reason = NULL; /* What is sent to user */ |
| 476 |
const char *channel_reason = NULL; /* What is sent to channel */ |
| 477 |
struct AccessItem *aconf = NULL; |
| 478 |
struct MatchItem *xconf = NULL; |
| 479 |
const char *type_string = NULL; |
| 480 |
const char dline_string[] = "D-line"; |
| 481 |
const char kline_string[] = "K-line"; |
| 482 |
const char gline_string[] = "G-line"; |
| 483 |
const char xline_string[] = "X-line"; |
| 484 |
|
| 485 |
switch (conf->type) |
| 486 |
{ |
| 487 |
case RKLINE_TYPE: |
| 488 |
case KLINE_TYPE: |
| 489 |
type_string = kline_string; |
| 490 |
aconf = &conf->conf.AccessItem; |
| 491 |
break; |
| 492 |
case DLINE_TYPE: |
| 493 |
type_string = dline_string; |
| 494 |
aconf = &conf->conf.AccessItem; |
| 495 |
break; |
| 496 |
case GLINE_TYPE: |
| 497 |
type_string = gline_string; |
| 498 |
aconf = &conf->conf.AccessItem; |
| 499 |
break; |
| 500 |
case RXLINE_TYPE: |
| 501 |
case XLINE_TYPE: |
| 502 |
type_string = xline_string; |
| 503 |
xconf = &conf->conf.MatchItem; |
| 504 |
++xconf->count; |
| 505 |
break; |
| 506 |
default: |
| 507 |
assert(0); |
| 508 |
break; |
| 509 |
} |
| 510 |
|
| 511 |
if (ConfigFileEntry.kline_with_reason) |
| 512 |
{ |
| 513 |
if (aconf != NULL) |
| 514 |
user_reason = aconf->reason ? aconf->reason : type_string; |
| 515 |
if (xconf != NULL) |
| 516 |
user_reason = xconf->reason ? xconf->reason : type_string; |
| 517 |
} |
| 518 |
else |
| 519 |
user_reason = type_string; |
| 520 |
|
| 521 |
if (ConfigFileEntry.kline_reason != NULL) |
| 522 |
channel_reason = ConfigFileEntry.kline_reason; |
| 523 |
else |
| 524 |
channel_reason = user_reason; |
| 525 |
|
| 526 |
sendto_realops_flags(UMODE_ALL, L_ALL, "%s active for %s", |
| 527 |
type_string, get_client_name(client_p, HIDE_IP)); |
| 528 |
|
| 529 |
if (IsClient(client_p)) |
| 530 |
sendto_one(client_p, form_str(ERR_YOUREBANNEDCREEP), |
| 531 |
me.name, client_p->name, user_reason); |
| 532 |
|
| 533 |
exit_client(client_p, &me, channel_reason); |
| 534 |
} |
| 535 |
|
| 536 |
/* update_client_exit_stats() |
| 537 |
* |
| 538 |
* input - pointer to client |
| 539 |
* output - NONE |
| 540 |
* side effects - |
| 541 |
*/ |
| 542 |
static void |
| 543 |
update_client_exit_stats(struct Client *client_p) |
| 544 |
{ |
| 545 |
if (IsServer(client_p)) |
| 546 |
{ |
| 547 |
sendto_realops_flags(UMODE_EXTERNAL, L_ALL, |
| 548 |
"Server %s split from %s", |
| 549 |
client_p->name, client_p->servptr->name); |
| 550 |
} |
| 551 |
else if (IsClient(client_p)) |
| 552 |
{ |
| 553 |
--Count.total; |
| 554 |
if (IsOper(client_p)) |
| 555 |
--Count.oper; |
| 556 |
if (IsInvisible(client_p)) |
| 557 |
--Count.invisi; |
| 558 |
} |
| 559 |
|
| 560 |
if (splitchecking && !splitmode) |
| 561 |
check_splitmode(NULL); |
| 562 |
} |
| 563 |
|
| 564 |
/* find_person() |
| 565 |
* |
| 566 |
* inputs - pointer to name |
| 567 |
* output - return client pointer |
| 568 |
* side effects - find person by (nick)name |
| 569 |
*/ |
| 570 |
/* XXX - ugly wrapper */ |
| 571 |
struct Client * |
| 572 |
find_person(const struct Client *client_p, const char *name) |
| 573 |
{ |
| 574 |
struct Client *c2ptr; |
| 575 |
|
| 576 |
if (IsDigit(*name)) |
| 577 |
{ |
| 578 |
if ((c2ptr = hash_find_id(name)) != NULL) |
| 579 |
{ |
| 580 |
/* invisible users shall not be found by UID guessing */ |
| 581 |
if (IsInvisible(c2ptr) && !IsServer(client_p)) |
| 582 |
c2ptr = NULL; |
| 583 |
} |
| 584 |
} |
| 585 |
else |
| 586 |
c2ptr = find_client(name); |
| 587 |
|
| 588 |
return ((c2ptr != NULL && IsClient(c2ptr)) ? c2ptr : NULL); |
| 589 |
} |
| 590 |
|
| 591 |
/* |
| 592 |
* find_chasing - find the client structure for a nick name (user) |
| 593 |
* using history mechanism if necessary. If the client is not found, |
| 594 |
* an error message (NO SUCH NICK) is generated. If the client was found |
| 595 |
* through the history, chasing will be 1 and otherwise 0. |
| 596 |
*/ |
| 597 |
struct Client * |
| 598 |
find_chasing(struct Client *client_p, struct Client *source_p, const char *user, int *chasing) |
| 599 |
{ |
| 600 |
struct Client *who = find_person(client_p, user); |
| 601 |
|
| 602 |
if (chasing) |
| 603 |
*chasing = 0; |
| 604 |
|
| 605 |
if (who) |
| 606 |
return(who); |
| 607 |
|
| 608 |
if (IsDigit(*user)) |
| 609 |
return(NULL); |
| 610 |
|
| 611 |
if ((who = get_history(user, |
| 612 |
(time_t)ConfigFileEntry.kill_chase_time_limit)) |
| 613 |
== NULL) |
| 614 |
{ |
| 615 |
sendto_one(source_p, form_str(ERR_NOSUCHNICK), |
| 616 |
me.name, source_p->name, user); |
| 617 |
return(NULL); |
| 618 |
} |
| 619 |
|
| 620 |
if (chasing) |
| 621 |
*chasing = 1; |
| 622 |
|
| 623 |
return(who); |
| 624 |
} |
| 625 |
|
| 626 |
/* |
| 627 |
* get_client_name - Return the name of the client |
| 628 |
* for various tracking and |
| 629 |
* admin purposes. The main purpose of this function is to |
| 630 |
* return the "socket host" name of the client, if that |
| 631 |
* differs from the advertised name (other than case). |
| 632 |
* But, this can be used to any client structure. |
| 633 |
* |
| 634 |
* NOTE 1: |
| 635 |
* Watch out the allocation of "nbuf", if either source_p->name |
| 636 |
* or source_p->sockhost gets changed into pointers instead of |
| 637 |
* directly allocated within the structure... |
| 638 |
* |
| 639 |
* NOTE 2: |
| 640 |
* Function return either a pointer to the structure (source_p) or |
| 641 |
* to internal buffer (nbuf). *NEVER* use the returned pointer |
| 642 |
* to modify what it points!!! |
| 643 |
*/ |
| 644 |
const char * |
| 645 |
get_client_name(struct Client *client, int showip) |
| 646 |
{ |
| 647 |
static char nbuf[HOSTLEN * 2 + USERLEN + 5]; |
| 648 |
|
| 649 |
assert(client != NULL); |
| 650 |
|
| 651 |
if (irccmp(client->name, client->host) == 0) |
| 652 |
return(client->name); |
| 653 |
|
| 654 |
if (ConfigServerHide.hide_server_ips) |
| 655 |
if (IsServer(client) || IsConnecting(client) || IsHandshake(client)) |
| 656 |
showip = MASK_IP; |
| 657 |
|
| 658 |
if (ConfigFileEntry.hide_spoof_ips) |
| 659 |
if (showip == SHOW_IP && IsIPSpoof(client)) |
| 660 |
showip = MASK_IP; |
| 661 |
|
| 662 |
/* And finally, let's get the host information, ip or name */ |
| 663 |
switch (showip) |
| 664 |
{ |
| 665 |
case SHOW_IP: |
| 666 |
if (MyConnect(client)) |
| 667 |
{ |
| 668 |
ircsprintf(nbuf, "%s[%s@%s]", client->name, client->username, |
| 669 |
client->sockhost); |
| 670 |
break; |
| 671 |
} |
| 672 |
case MASK_IP: |
| 673 |
ircsprintf(nbuf, "%s[%s@255.255.255.255]", client->name, |
| 674 |
client->username); |
| 675 |
break; |
| 676 |
default: |
| 677 |
ircsprintf(nbuf, "%s[%s@%s]", client->name, client->username, |
| 678 |
client->host); |
| 679 |
} |
| 680 |
|
| 681 |
return(nbuf); |
| 682 |
} |
| 683 |
|
| 684 |
void |
| 685 |
free_exited_clients(void) |
| 686 |
{ |
| 687 |
dlink_node *ptr, *next; |
| 688 |
struct Client *target_p; |
| 689 |
|
| 690 |
DLINK_FOREACH_SAFE(ptr, next, dead_list.head) |
| 691 |
{ |
| 692 |
target_p = ptr->data; |
| 693 |
|
| 694 |
if (ptr->data == NULL) |
| 695 |
{ |
| 696 |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 697 |
"Warning: null client on dead_list!"); |
| 698 |
dlinkDelete(ptr, &dead_list); |
| 699 |
free_dlink_node(ptr); |
| 700 |
continue; |
| 701 |
} |
| 702 |
|
| 703 |
free_client(target_p); |
| 704 |
dlinkDelete(ptr, &dead_list); |
| 705 |
free_dlink_node(ptr); |
| 706 |
} |
| 707 |
} |
| 708 |
|
| 709 |
/* |
| 710 |
* Exit one client, local or remote. Assuming all dependents have |
| 711 |
* been already removed, and socket closed for local client. |
| 712 |
* |
| 713 |
* The only messages generated are QUITs on channels. |
| 714 |
*/ |
| 715 |
static void |
| 716 |
exit_one_client(struct Client *source_p, const char *quitmsg) |
| 717 |
{ |
| 718 |
dlink_node *lp = NULL, *next_lp = NULL; |
| 719 |
|
| 720 |
assert(!IsMe(source_p)); |
| 721 |
|
| 722 |
if (IsServer(source_p)) |
| 723 |
{ |
| 724 |
dlinkDelete(&source_p->lnode, &source_p->servptr->serv->servers); |
| 725 |
|
| 726 |
if ((lp = dlinkFindDelete(&global_serv_list, source_p)) != NULL) |
| 727 |
free_dlink_node(lp); |
| 728 |
|
| 729 |
if (!MyConnect(source_p)) |
| 730 |
{ |
| 731 |
source_p->from->serv->dep_servers--; |
| 732 |
assert(source_p->from->serv->dep_servers > 0); |
| 733 |
} |
| 734 |
} |
| 735 |
else if (IsClient(source_p)) |
| 736 |
{ |
| 737 |
if (source_p->servptr->serv != NULL) |
| 738 |
dlinkDelete(&source_p->lnode, &source_p->servptr->serv->users); |
| 739 |
|
| 740 |
/* If a person is on a channel, send a QUIT notice |
| 741 |
** to every client (person) on the same channel (so |
| 742 |
** that the client can show the "**signoff" message). |
| 743 |
** (Note: The notice is to the local clients *only*) |
| 744 |
*/ |
| 745 |
sendto_common_channels_local(source_p, 0, ":%s!%s@%s QUIT :%s", |
| 746 |
source_p->name, source_p->username, |
| 747 |
source_p->host, quitmsg); |
| 748 |
DLINK_FOREACH_SAFE(lp, next_lp, source_p->channel.head) |
| 749 |
remove_user_from_channel(lp->data); |
| 750 |
|
| 751 |
/* Clean up invitefield */ |
| 752 |
DLINK_FOREACH_SAFE(lp, next_lp, source_p->invited.head) |
| 753 |
del_invite(lp->data, source_p); |
| 754 |
|
| 755 |
/* Clean up allow lists */ |
| 756 |
del_all_accepts(source_p); |
| 757 |
add_history(source_p, 0); |
| 758 |
off_history(source_p); |
| 759 |
|
| 760 |
assert(source_p->whowas.head == NULL); |
| 761 |
assert(source_p->whowas.tail == NULL); |
| 762 |
|
| 763 |
if (!MyConnect(source_p)) |
| 764 |
{ |
| 765 |
source_p->from->serv->dep_users--; |
| 766 |
assert(source_p->from->serv->dep_users >= 0); |
| 767 |
} |
| 768 |
} |
| 769 |
|
| 770 |
/* Remove source_p from the client lists */ |
| 771 |
if (HasID(source_p)) |
| 772 |
hash_del_id(source_p); |
| 773 |
if (source_p->name[0]) |
| 774 |
hash_del_client(source_p); |
| 775 |
|
| 776 |
if (IsUserHostIp(source_p)) |
| 777 |
delete_user_host(source_p->username, source_p->host, !MyConnect(source_p)); |
| 778 |
|
| 779 |
/* remove from global client list |
| 780 |
* NOTE: source_p->node.next cannot be NULL if the client is added |
| 781 |
* to global_client_list (there is always &me at its end) |
| 782 |
*/ |
| 783 |
if (source_p != NULL && source_p->node.next != NULL) |
| 784 |
dlinkDelete(&source_p->node, &global_client_list); |
| 785 |
|
| 786 |
update_client_exit_stats(source_p); |
| 787 |
|
| 788 |
/* Check to see if the client isn't already on the dead list */ |
| 789 |
assert(dlinkFind(&dead_list, source_p) == NULL); |
| 790 |
|
| 791 |
/* add to dead client dlist */ |
| 792 |
SetDead(source_p); |
| 793 |
dlinkAdd(source_p, make_dlink_node(), &dead_list); |
| 794 |
} |
| 795 |
|
| 796 |
/* Recursively send QUITs and SQUITs for source_p and all its dependent clients |
| 797 |
* and servers to those servers that need them. A server needs the client |
| 798 |
* QUITs if it can't figure them out from the SQUIT (ie pre-TS4) or if it |
| 799 |
* isn't getting the SQUIT because of @#(*&@)# hostmasking. With TS4, once |
| 800 |
* a link gets a SQUIT, it doesn't need any QUIT/SQUITs for clients depending |
| 801 |
* on that one -orabidoo |
| 802 |
* |
| 803 |
* This is now called on each local server -adx |
| 804 |
*/ |
| 805 |
static void |
| 806 |
recurse_send_quits(struct Client *original_source_p, struct Client *source_p, |
| 807 |
struct Client *from, struct Client *to, const char *comment, |
| 808 |
const char *splitstr, const char *myname) |
| 809 |
{ |
| 810 |
dlink_node *ptr, *next; |
| 811 |
struct Client *target_p; |
| 812 |
int hidden = match(myname, source_p->name); |
| 813 |
|
| 814 |
assert(to != source_p); /* should be already removed from serv_list */ |
| 815 |
|
| 816 |
/* If this server can handle quit storm (QS) removal |
| 817 |
* of dependents, just send the SQUIT |
| 818 |
* |
| 819 |
* Always check *all* dependent servers if some of them are |
| 820 |
* hidden behind fakename. If so, send out the QUITs -adx |
| 821 |
*/ |
| 822 |
if (hidden || !IsCapable(to, CAP_QS)) |
| 823 |
DLINK_FOREACH_SAFE(ptr, next, source_p->serv->users.head) |
| 824 |
{ |
| 825 |
target_p = ptr->data; |
| 826 |
sendto_one(to, ":%s QUIT :%s", target_p->name, splitstr); |
| 827 |
} |
| 828 |
|
| 829 |
DLINK_FOREACH_SAFE(ptr, next, source_p->serv->servers.head) |
| 830 |
recurse_send_quits(original_source_p, ptr->data, from, to, |
| 831 |
comment, splitstr, myname); |
| 832 |
|
| 833 |
if (!hidden && ((source_p == original_source_p && to != from) || |
| 834 |
!IsCapable(to, CAP_QS))) |
| 835 |
{ |
| 836 |
/* don't use a prefix here - we have to be 100% sure the message |
| 837 |
* will be accepted without Unknown prefix etc.. */ |
| 838 |
sendto_one(to, "SQUIT %s :%s", ID_or_name(source_p, to), comment); |
| 839 |
} |
| 840 |
} |
| 841 |
|
| 842 |
/* |
| 843 |
* Remove all clients that depend on source_p; assumes all (S)QUITs have |
| 844 |
* already been sent. we make sure to exit a server's dependent clients |
| 845 |
* and servers before the server itself; exit_one_client takes care of |
| 846 |
* actually removing things off llists. tweaked from +CSr31 -orabidoo |
| 847 |
*/ |
| 848 |
static void |
| 849 |
recurse_remove_clients(struct Client *source_p, const char *quitmsg) |
| 850 |
{ |
| 851 |
dlink_node *ptr, *next; |
| 852 |
|
| 853 |
DLINK_FOREACH_SAFE(ptr, next, source_p->serv->users.head) |
| 854 |
exit_one_client(ptr->data, quitmsg); |
| 855 |
|
| 856 |
DLINK_FOREACH_SAFE(ptr, next, source_p->serv->servers.head) |
| 857 |
{ |
| 858 |
recurse_remove_clients(ptr->data, quitmsg); |
| 859 |
exit_one_client(ptr->data, quitmsg); |
| 860 |
} |
| 861 |
|
| 862 |
assert(source_p->serv->dep_servers == 1); |
| 863 |
assert(source_p->serv->dep_users == 0); |
| 864 |
} |
| 865 |
|
| 866 |
/* |
| 867 |
** Remove *everything* that depends on source_p, from all lists, and sending |
| 868 |
** all necessary QUITs and SQUITs. source_p itself is still on the lists, |
| 869 |
** and its SQUITs have been sent except for the upstream one -orabidoo |
| 870 |
*/ |
| 871 |
static void |
| 872 |
remove_dependents(struct Client *source_p, struct Client *from, |
| 873 |
const char *comment, const char *splitstr) |
| 874 |
{ |
| 875 |
struct Client *to; |
| 876 |
struct ConfItem *conf; |
| 877 |
struct AccessItem *aconf; |
| 878 |
static char myname[HOSTLEN+1]; |
| 879 |
dlink_node *ptr; |
| 880 |
|
| 881 |
DLINK_FOREACH(ptr, serv_list.head) |
| 882 |
{ |
| 883 |
to = ptr->data; |
| 884 |
|
| 885 |
if ((conf = to->serv->sconf) != NULL) |
| 886 |
{ |
| 887 |
aconf = &conf->conf.AccessItem; |
| 888 |
strlcpy(myname, my_name_for_link(aconf), sizeof(myname)); |
| 889 |
} |
| 890 |
else |
| 891 |
strlcpy(myname, me.name, sizeof(myname)); |
| 892 |
recurse_send_quits(source_p, source_p, from, to, |
| 893 |
comment, splitstr, myname); |
| 894 |
} |
| 895 |
|
| 896 |
recurse_remove_clients(source_p, splitstr); |
| 897 |
} |
| 898 |
|
| 899 |
/* |
| 900 |
* exit_client - exit a client of any type. Generally, you can use |
| 901 |
* this on any struct Client, regardless of its state. |
| 902 |
* |
| 903 |
* Note, you shouldn't exit remote _users_ without first doing |
| 904 |
* SetKilled and propagating a kill or similar message. However, |
| 905 |
* it is perfectly correct to call exit_client to force a _server_ |
| 906 |
* quit (either local or remote one). |
| 907 |
* |
| 908 |
* inputs: - a client pointer that is going to be exited |
| 909 |
* - for servers, the second argument is a pointer to who |
| 910 |
* is firing the server. This side won't get any generated |
| 911 |
* messages. NEVER NULL! |
| 912 |
* output: none |
| 913 |
* side effects: the client is delinked from all lists, disconnected, |
| 914 |
* and the rest of IRC network is notified of the exit. |
| 915 |
* Client memory is scheduled to be freed |
| 916 |
*/ |
| 917 |
void |
| 918 |
exit_client(struct Client *source_p, struct Client *from, const char *comment) |
| 919 |
{ |
| 920 |
dlink_node *m; |
| 921 |
|
| 922 |
if (MyConnect(source_p)) |
| 923 |
{ |
| 924 |
/* DO NOT REMOVE. exit_client can be called twice after a failed |
| 925 |
* read/write. |
| 926 |
*/ |
| 927 |
if (IsClosing(source_p)) |
| 928 |
return; |
| 929 |
|
| 930 |
SetClosing(source_p); |
| 931 |
|
| 932 |
if (IsIpHash(source_p)) |
| 933 |
remove_one_ip(&source_p->localClient->ip); |
| 934 |
|
| 935 |
delete_auth(source_p); |
| 936 |
|
| 937 |
/* This source_p could have status of one of STAT_UNKNOWN, STAT_CONNECTING |
| 938 |
* STAT_HANDSHAKE or STAT_UNKNOWN |
| 939 |
* all of which are lumped together into unknown_list |
| 940 |
* |
| 941 |
* In all above cases IsRegistered() will not be true. |
| 942 |
*/ |
| 943 |
if (!IsRegistered(source_p)) |
| 944 |
{ |
| 945 |
if ((m = dlinkFindDelete(&unknown_list, source_p)) != NULL) |
| 946 |
free_dlink_node(m); |
| 947 |
} |
| 948 |
else if (IsClient(source_p)) |
| 949 |
{ |
| 950 |
Count.local--; |
| 951 |
|
| 952 |
if (IsOper(source_p)) |
| 953 |
{ |
| 954 |
if ((m = dlinkFindDelete(&oper_list, source_p)) != NULL) |
| 955 |
free_dlink_node(m); |
| 956 |
} |
| 957 |
|
| 958 |
dlinkDelete(&source_p->localClient->lclient_node, &local_client_list); |
| 959 |
if (source_p->localClient->list_task != NULL) |
| 960 |
free_list_task(source_p->localClient->list_task, source_p); |
| 961 |
|
| 962 |
sendto_realops_flags(UMODE_CCONN, L_ALL, "Client exiting: %s (%s@%s) [%s] [%s]", |
| 963 |
source_p->name, source_p->username, source_p->host, comment, |
| 964 |
ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ? |
| 965 |
"255.255.255.255" : source_p->sockhost); |
| 966 |
} |
| 967 |
|
| 968 |
/* As soon as a client is known to be a server of some sort |
| 969 |
* it has to be put on the serv_list, or SJOIN's to this new server |
| 970 |
* from the connect burst will not be seen. |
| 971 |
*/ |
| 972 |
if (IsServer(source_p) || IsConnecting(source_p) || |
| 973 |
IsHandshake(source_p)) |
| 974 |
{ |
| 975 |
if ((m = dlinkFindDelete(&serv_list, source_p)) != NULL) |
| 976 |
{ |
| 977 |
free_dlink_node(m); |
| 978 |
unset_chcap_usage_counts(source_p); |
| 979 |
} |
| 980 |
|
| 981 |
if (IsServer(source_p)) |
| 982 |
{ |
| 983 |
Count.myserver--; |
| 984 |
if (ServerInfo.hub) |
| 985 |
remove_lazylink_flags(source_p->localClient->serverMask); |
| 986 |
else |
| 987 |
uplink = NULL; |
| 988 |
} |
| 989 |
} |
| 990 |
|
| 991 |
log_user_exit(source_p); |
| 992 |
|
| 993 |
if (!IsDead(source_p)) |
| 994 |
{ |
| 995 |
if (IsServer(source_p)) |
| 996 |
{ |
| 997 |
/* for them, we are exiting the network */ |
| 998 |
sendto_one(source_p, ":%s SQUIT %s :%s", |
| 999 |
ID_or_name(from, source_p), me.name, comment); |
| 1000 |
} |
| 1001 |
|
| 1002 |
sendto_one(source_p, "ERROR :Closing Link: %s (%s)", |
| 1003 |
source_p->host, comment); |
| 1004 |
} |
| 1005 |
|
| 1006 |
/* |
| 1007 |
** Currently only server connections can have |
| 1008 |
** depending remote clients here, but it does no |
| 1009 |
** harm to check for all local clients. In |
| 1010 |
** future some other clients than servers might |
| 1011 |
** have remotes too... |
| 1012 |
** |
| 1013 |
** Close the Client connection first and mark it |
| 1014 |
** so that no messages are attempted to send to it. |
| 1015 |
** Remember it makes source_p->from == NULL. |
| 1016 |
*/ |
| 1017 |
close_connection(source_p); |
| 1018 |
} |
| 1019 |
|
| 1020 |
if (IsServer(source_p)) |
| 1021 |
{ |
| 1022 |
char splitstr[HOSTLEN + HOSTLEN + 2]; |
| 1023 |
|
| 1024 |
/* This shouldn't ever happen */ |
| 1025 |
assert(source_p->serv != NULL && source_p->servptr != NULL); |
| 1026 |
|
| 1027 |
if (ConfigServerHide.hide_servers) |
| 1028 |
/* set netsplit message to "*.net *.split" to still show |
| 1029 |
* that its a split, but hide the servers splitting |
| 1030 |
*/ |
| 1031 |
strcpy(splitstr, "*.net *.split"); |
| 1032 |
else |
| 1033 |
snprintf(splitstr, sizeof(splitstr), "%s %s", |
| 1034 |
source_p->servptr->name, source_p->name); |
| 1035 |
|
| 1036 |
remove_dependents(source_p, from->from, comment, splitstr); |
| 1037 |
|
| 1038 |
if (source_p->servptr == &me) |
| 1039 |
{ |
| 1040 |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 1041 |
"%s was connected for %d seconds. %llu/%llu sendK/recvK.", |
| 1042 |
source_p->name, (int)(CurrentTime - source_p->firsttime), |
| 1043 |
source_p->localClient->send.bytes >> 10, |
| 1044 |
source_p->localClient->recv.bytes >> 10); |
| 1045 |
ilog(L_NOTICE, "%s was connected for %d seconds. %llu/%llu sendK/recvK.", |
| 1046 |
source_p->name, (int)(CurrentTime - source_p->firsttime), |
| 1047 |
source_p->localClient->send.bytes >> 10, |
| 1048 |
source_p->localClient->recv.bytes >> 10); |
| 1049 |
} |
| 1050 |
} |
| 1051 |
else if (IsClient(source_p) && !IsKilled(source_p)) |
| 1052 |
{ |
| 1053 |
sendto_server(NULL, source_p, NULL, CAP_TS6, NOCAPS, NOFLAGS, |
| 1054 |
":%s QUIT :%s", ID(source_p), comment); |
| 1055 |
sendto_server(NULL, source_p, NULL, NOCAPS, CAP_TS6, NOFLAGS, |
| 1056 |
":%s QUIT :%s", source_p->name, comment); |
| 1057 |
} |
| 1058 |
|
| 1059 |
/* The client *better* be off all of the lists */ |
| 1060 |
assert(dlinkFind(&unknown_list, source_p) == NULL); |
| 1061 |
assert(dlinkFind(&local_client_list, source_p) == NULL); |
| 1062 |
assert(dlinkFind(&serv_list, source_p) == NULL); |
| 1063 |
assert(dlinkFind(&oper_list, source_p) == NULL); |
| 1064 |
|
| 1065 |
exit_one_client(source_p, comment); |
| 1066 |
} |
| 1067 |
|
| 1068 |
/* |
| 1069 |
* close_connection |
| 1070 |
* Close the physical connection. This function must make |
| 1071 |
* MyConnect(client_p) == FALSE, and set client_p->from == NULL. |
| 1072 |
*/ |
| 1073 |
static void |
| 1074 |
close_connection(struct Client *client_p) |
| 1075 |
{ |
| 1076 |
struct ConfItem *conf; |
| 1077 |
struct AccessItem *aconf; |
| 1078 |
struct ClassItem *aclass; |
| 1079 |
|
| 1080 |
assert(NULL != client_p); |
| 1081 |
|
| 1082 |
if (IsServer(client_p)) |
| 1083 |
{ |
| 1084 |
ServerStats->is_sv++; |
| 1085 |
ServerStats->is_sbs += client_p->localClient->send.bytes; |
| 1086 |
ServerStats->is_sbr += client_p->localClient->recv.bytes; |
| 1087 |
ServerStats->is_sti += CurrentTime - client_p->firsttime; |
| 1088 |
|
| 1089 |
/* XXX Does this even make any sense at all anymore? |
| 1090 |
* scheduling a 'quick' reconnect could cause a pile of |
| 1091 |
* nick collides under TSora protocol... -db |
| 1092 |
*/ |
| 1093 |
/* |
| 1094 |
* If the connection has been up for a long amount of time, schedule |
| 1095 |
* a 'quick' reconnect, else reset the next-connect cycle. |
| 1096 |
*/ |
| 1097 |
if ((conf = find_exact_name_conf(SERVER_TYPE, |
| 1098 |
client_p->name, client_p->username, |
| 1099 |
client_p->host))) |
| 1100 |
{ |
| 1101 |
/* |
| 1102 |
* Reschedule a faster reconnect, if this was a automatically |
| 1103 |
* connected configuration entry. (Note that if we have had |
| 1104 |
* a rehash in between, the status has been changed to |
| 1105 |
* CONF_ILLEGAL). But only do this if it was a "good" link. |
| 1106 |
*/ |
| 1107 |
aconf = &conf->conf.AccessItem; |
| 1108 |
aclass = &((struct ConfItem *)aconf->class_ptr)->conf.ClassItem; |
| 1109 |
aconf->hold = time(NULL); |
| 1110 |
aconf->hold += (aconf->hold - client_p->since > HANGONGOODLINK) ? |
| 1111 |
HANGONRETRYDELAY : ConFreq(aclass); |
| 1112 |
if (nextconnect > aconf->hold) |
| 1113 |
nextconnect = aconf->hold; |
| 1114 |
} |
| 1115 |
} |
| 1116 |
else if (IsClient(client_p)) |
| 1117 |
{ |
| 1118 |
ServerStats->is_cl++; |
| 1119 |
ServerStats->is_cbs += client_p->localClient->send.bytes; |
| 1120 |
ServerStats->is_cbr += client_p->localClient->recv.bytes; |
| 1121 |
ServerStats->is_cti += CurrentTime - client_p->firsttime; |
| 1122 |
} |
| 1123 |
else |
| 1124 |
ServerStats->is_ni++; |
| 1125 |
|
| 1126 |
if (!IsDead(client_p)) |
| 1127 |
{ |
| 1128 |
/* attempt to flush any pending dbufs. Evil, but .. -- adrian */ |
| 1129 |
/* there is still a chance that we might send data to this socket |
| 1130 |
* even if it is marked as blocked (COMM_SELECT_READ handler is called |
| 1131 |
* before COMM_SELECT_WRITE). Let's try, nothing to lose.. -adx |
| 1132 |
*/ |
| 1133 |
ClearSendqBlocked(client_p); |
| 1134 |
send_queued_write(client_p); |
| 1135 |
} |
| 1136 |
|
| 1137 |
#ifdef HAVE_LIBCRYPTO |
| 1138 |
if (client_p->localClient->fd.ssl) |
| 1139 |
SSL_shutdown(client_p->localClient->fd.ssl); |
| 1140 |
#endif |
| 1141 |
if (client_p->localClient->fd.flags.open) |
| 1142 |
fd_close(&client_p->localClient->fd); |
| 1143 |
|
| 1144 |
if (HasServlink(client_p)) |
| 1145 |
{ |
| 1146 |
if (client_p->localClient->ctrlfd.flags.open) |
| 1147 |
fd_close(&client_p->localClient->ctrlfd); |
| 1148 |
} |
| 1149 |
|
| 1150 |
dbuf_clear(&client_p->localClient->buf_sendq); |
| 1151 |
dbuf_clear(&client_p->localClient->buf_recvq); |
| 1152 |
|
| 1153 |
MyFree(client_p->localClient->passwd); |
| 1154 |
detach_conf(client_p, CONF_TYPE); |
| 1155 |
client_p->from = NULL; /* ...this should catch them! >:) --msa */ |
| 1156 |
} |
| 1157 |
|
| 1158 |
/* |
| 1159 |
* report_error - report an error from an errno. |
| 1160 |
* Record error to log and also send a copy to all *LOCAL* opers online. |
| 1161 |
* |
| 1162 |
* text is a *format* string for outputing error. It must |
| 1163 |
* contain only two '%s', the first will be replaced |
| 1164 |
* by the sockhost from the client_p, and the latter will |
| 1165 |
* be taken from sys_errlist[errno]. |
| 1166 |
* |
| 1167 |
* client_p if not NULL, is the *LOCAL* client associated with |
| 1168 |
* the error. |
| 1169 |
* |
| 1170 |
* Cannot use perror() within daemon. stderr is closed in |
| 1171 |
* ircd and cannot be used. And, worse yet, it might have |
| 1172 |
* been reassigned to a normal connection... |
| 1173 |
* |
| 1174 |
* Actually stderr is still there IFF ircd was run with -s --Rodder |
| 1175 |
*/ |
| 1176 |
void |
| 1177 |
report_error(int level, const char* text, const char* who, int error) |
| 1178 |
{ |
| 1179 |
who = (who) ? who : ""; |
| 1180 |
|
| 1181 |
sendto_realops_flags(UMODE_DEBUG, level, text, who, strerror(error)); |
| 1182 |
log_oper_action(LOG_IOERR_TYPE, NULL, "%s %s %s\n", who, text, strerror(error)); |
| 1183 |
ilog(L_ERROR, text, who, strerror(error)); |
| 1184 |
} |
| 1185 |
|
| 1186 |
/* |
| 1187 |
* dead_link_on_write - report a write error if not already dead, |
| 1188 |
* mark it as dead then exit it |
| 1189 |
*/ |
| 1190 |
void |
| 1191 |
dead_link_on_write(struct Client *client_p, int ierrno) |
| 1192 |
{ |
| 1193 |
dlink_node *ptr; |
| 1194 |
|
| 1195 |
if (IsDefunct(client_p)) |
| 1196 |
return; |
| 1197 |
|
| 1198 |
dbuf_clear(&client_p->localClient->buf_recvq); |
| 1199 |
dbuf_clear(&client_p->localClient->buf_sendq); |
| 1200 |
|
| 1201 |
assert(dlinkFind(&abort_list, client_p) == NULL); |
| 1202 |
ptr = make_dlink_node(); |
| 1203 |
/* don't let exit_aborted_clients() finish yet */ |
| 1204 |
dlinkAddTail(client_p, ptr, &abort_list); |
| 1205 |
|
| 1206 |
if (eac_next == NULL) |
| 1207 |
eac_next = ptr; |
| 1208 |
|
| 1209 |
SetDead(client_p); /* You are dead my friend */ |
| 1210 |
} |
| 1211 |
|
| 1212 |
/* |
| 1213 |
* dead_link_on_read - report a read error if not already dead, |
| 1214 |
* mark it as dead then exit it |
| 1215 |
*/ |
| 1216 |
void |
| 1217 |
dead_link_on_read(struct Client *client_p, int error) |
| 1218 |
{ |
| 1219 |
char errmsg[255]; |
| 1220 |
int current_error; |
| 1221 |
|
| 1222 |
if (IsDefunct(client_p)) |
| 1223 |
return; |
| 1224 |
|
| 1225 |
dbuf_clear(&client_p->localClient->buf_recvq); |
| 1226 |
dbuf_clear(&client_p->localClient->buf_sendq); |
| 1227 |
|
| 1228 |
current_error = get_sockerr(client_p->localClient->fd.fd); |
| 1229 |
|
| 1230 |
if (IsServer(client_p) || IsHandshake(client_p)) |
| 1231 |
{ |
| 1232 |
int connected = CurrentTime - client_p->firsttime; |
| 1233 |
|
| 1234 |
if (error == 0) |
| 1235 |
{ |
| 1236 |
/* Admins get the real IP */ |
| 1237 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
| 1238 |
"Server %s closed the connection", |
| 1239 |
get_client_name(client_p, SHOW_IP)); |
| 1240 |
|
| 1241 |
/* Opers get a masked IP */ |
| 1242 |
sendto_realops_flags(UMODE_ALL, L_OPER, |
| 1243 |
"Server %s closed the connection", |
| 1244 |
get_client_name(client_p, MASK_IP)); |
| 1245 |
|
| 1246 |
ilog(L_NOTICE, "Server %s closed the connection", |
| 1247 |
get_client_name(client_p, SHOW_IP)); |
| 1248 |
} |
| 1249 |
else |
| 1250 |
{ |
| 1251 |
report_error(L_ADMIN, "Lost connection to %s: %d", |
| 1252 |
get_client_name(client_p, SHOW_IP), current_error); |
| 1253 |
report_error(L_OPER, "Lost connection to %s: %d", |
| 1254 |
get_client_name(client_p, MASK_IP), current_error); |
| 1255 |
} |
| 1256 |
|
| 1257 |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 1258 |
"%s had been connected for %d day%s, %2d:%02d:%02d", |
| 1259 |
client_p->name, connected/86400, |
| 1260 |
(connected/86400 == 1) ? "" : "s", |
| 1261 |
(connected % 86400) / 3600, (connected % 3600) / 60, |
| 1262 |
connected % 60); |
| 1263 |
} |
| 1264 |
|
| 1265 |
if (error == 0) |
| 1266 |
strlcpy(errmsg, "Remote host closed the connection", |
| 1267 |
sizeof(errmsg)); |
| 1268 |
else |
| 1269 |
ircsprintf(errmsg, "Read error: %s", |
| 1270 |
strerror(current_error)); |
| 1271 |
|
| 1272 |
exit_client(client_p, &me, errmsg); |
| 1273 |
} |
| 1274 |
|
| 1275 |
void |
| 1276 |
exit_aborted_clients(void) |
| 1277 |
{ |
| 1278 |
dlink_node *ptr; |
| 1279 |
struct Client *target_p; |
| 1280 |
const char *notice; |
| 1281 |
|
| 1282 |
DLINK_FOREACH_SAFE(ptr, eac_next, abort_list.head) |
| 1283 |
{ |
| 1284 |
target_p = ptr->data; |
| 1285 |
eac_next = ptr->next; |
| 1286 |
|
| 1287 |
if (target_p == NULL) |
| 1288 |
{ |
| 1289 |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 1290 |
"Warning: null client on abort_list!"); |
| 1291 |
dlinkDelete(ptr, &abort_list); |
| 1292 |
free_dlink_node(ptr); |
| 1293 |
continue; |
| 1294 |
} |
| 1295 |
|
| 1296 |
dlinkDelete(ptr, &abort_list); |
| 1297 |
|
| 1298 |
if (IsSendQExceeded(target_p)) |
| 1299 |
notice = "Max SendQ exceeded"; |
| 1300 |
else |
| 1301 |
notice = "Write error: connection closed"; |
| 1302 |
|
| 1303 |
exit_client(target_p, &me, notice); |
| 1304 |
free_dlink_node(ptr); |
| 1305 |
} |
| 1306 |
} |
| 1307 |
|
| 1308 |
/* |
| 1309 |
* accept processing, this adds a form of "caller ID" to ircd |
| 1310 |
* |
| 1311 |
* If a client puts themselves into "caller ID only" mode, |
| 1312 |
* only clients that match a client pointer they have put on |
| 1313 |
* the accept list will be allowed to message them. |
| 1314 |
* |
| 1315 |
* [ source.on_allow_list ] -> [ target1 ] -> [ target2 ] |
| 1316 |
* |
| 1317 |
* [target.allow_list] -> [ source1 ] -> [source2 ] |
| 1318 |
* |
| 1319 |
* i.e. a target will have a link list of source pointers it will allow |
| 1320 |
* each source client then has a back pointer pointing back |
| 1321 |
* to the client that has it on its accept list. |
| 1322 |
* This allows for exit_one_client to remove these now bogus entries |
| 1323 |
* from any client having an accept on them. |
| 1324 |
*/ |
| 1325 |
|
| 1326 |
/* accept_message() |
| 1327 |
* |
| 1328 |
* inputs - pointer to source client |
| 1329 |
* - pointer to target client |
| 1330 |
* output - 1 if accept this message 0 if not |
| 1331 |
* side effects - See if source is on target's allow list |
| 1332 |
*/ |
| 1333 |
int |
| 1334 |
accept_message(struct Client *source, struct Client *target) |
| 1335 |
{ |
| 1336 |
dlink_node *ptr; |
| 1337 |
|
| 1338 |
DLINK_FOREACH(ptr, target->allow_list.head) |
| 1339 |
{ |
| 1340 |
struct Client *target_p = ptr->data; |
| 1341 |
|
| 1342 |
if (source == target_p) |
| 1343 |
return (1); |
| 1344 |
} |
| 1345 |
|
| 1346 |
if (IsSoftCallerId(target)) |
| 1347 |
{ |
| 1348 |
DLINK_FOREACH(ptr, target->channel.head) |
| 1349 |
if (IsMember(source, ptr->data)) |
| 1350 |
return (1); |
| 1351 |
} |
| 1352 |
|
| 1353 |
return (0); |
| 1354 |
} |
| 1355 |
|
| 1356 |
/* del_from_accept() |
| 1357 |
* |
| 1358 |
* inputs - pointer to source client |
| 1359 |
* - pointer to target client |
| 1360 |
* output - NONE |
| 1361 |
* side effects - Delete's source pointer to targets allow list |
| 1362 |
* |
| 1363 |
* Walk through the target's accept list, remove if source is found, |
| 1364 |
* Then walk through the source's on_accept_list remove target if found. |
| 1365 |
*/ |
| 1366 |
void |
| 1367 |
del_from_accept(struct Client *source, struct Client *target) |
| 1368 |
{ |
| 1369 |
dlink_node *ptr; |
| 1370 |
dlink_node *ptr2; |
| 1371 |
dlink_node *next_ptr; |
| 1372 |
dlink_node *next_ptr2; |
| 1373 |
struct Client *target_p; |
| 1374 |
|
| 1375 |
DLINK_FOREACH_SAFE(ptr, next_ptr, target->allow_list.head) |
| 1376 |
{ |
| 1377 |
target_p = ptr->data; |
| 1378 |
|
| 1379 |
if (source == target_p) |
| 1380 |
{ |
| 1381 |
dlinkDelete(ptr, &target->allow_list); |
| 1382 |
free_dlink_node(ptr); |
| 1383 |
|
| 1384 |
DLINK_FOREACH_SAFE(ptr2, next_ptr2, source->on_allow_list.head) |
| 1385 |
{ |
| 1386 |
target_p = ptr2->data; |
| 1387 |
|
| 1388 |
if (target == target_p) |
| 1389 |
{ |
| 1390 |
dlinkDelete(ptr2, &source->on_allow_list); |
| 1391 |
free_dlink_node(ptr2); |
| 1392 |
} |
| 1393 |
} |
| 1394 |
} |
| 1395 |
} |
| 1396 |
} |
| 1397 |
|
| 1398 |
/* del_all_accepts() |
| 1399 |
* |
| 1400 |
* inputs - pointer to exiting client |
| 1401 |
* output - NONE |
| 1402 |
* side effects - Walk through given clients allow_list and on_allow_list |
| 1403 |
* remove all references to this client |
| 1404 |
*/ |
| 1405 |
void |
| 1406 |
del_all_accepts(struct Client *client_p) |
| 1407 |
{ |
| 1408 |
dlink_node *ptr, *next_ptr; |
| 1409 |
|
| 1410 |
DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->allow_list.head) |
| 1411 |
del_from_accept(ptr->data, client_p); |
| 1412 |
|
| 1413 |
DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->on_allow_list.head) |
| 1414 |
del_from_accept(client_p, ptr->data); |
| 1415 |
} |
| 1416 |
|
| 1417 |
/* del_all_their_accepts() |
| 1418 |
* |
| 1419 |
* inputs - pointer to exiting client |
| 1420 |
* output - NONE |
| 1421 |
* side effects - Walk through given clients on_allow_list |
| 1422 |
* remove all references to this client, |
| 1423 |
* allow this client to keep their own allow_list |
| 1424 |
*/ |
| 1425 |
void |
| 1426 |
del_all_their_accepts(struct Client *client_p) |
| 1427 |
{ |
| 1428 |
dlink_node *ptr, *next_ptr; |
| 1429 |
|
| 1430 |
DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->on_allow_list.head) |
| 1431 |
del_from_accept(client_p, ptr->data); |
| 1432 |
} |
| 1433 |
|
| 1434 |
/* set_initial_nick() |
| 1435 |
* |
| 1436 |
* inputs |
| 1437 |
* output |
| 1438 |
* side effects - |
| 1439 |
* |
| 1440 |
* This function is only called to set up an initially registering |
| 1441 |
* client. |
| 1442 |
*/ |
| 1443 |
void |
| 1444 |
set_initial_nick(struct Client *client_p, struct Client *source_p, |
| 1445 |
const char *nick) |
| 1446 |
{ |
| 1447 |
char buf[USERLEN + 1]; |
| 1448 |
|
| 1449 |
/* Client setting NICK the first time */ |
| 1450 |
|
| 1451 |
/* This had to be copied here to avoid problems.. */ |
| 1452 |
source_p->tsinfo = CurrentTime; |
| 1453 |
|
| 1454 |
if (source_p->name[0]) |
| 1455 |
hash_del_client(source_p); |
| 1456 |
|
| 1457 |
strlcpy(source_p->name, nick, sizeof(source_p->name)); |
| 1458 |
hash_add_client(source_p); |
| 1459 |
|
| 1460 |
/* fd_desc is long enough */ |
| 1461 |
fd_note(&client_p->localClient->fd, "Nick: %s", nick); |
| 1462 |
|
| 1463 |
/* They have the nick they want now.. */ |
| 1464 |
client_p->localClient->llname[0] = '\0'; |
| 1465 |
|
| 1466 |
if (source_p->flags & FLAGS_GOTUSER) |
| 1467 |
{ |
| 1468 |
strlcpy(buf, source_p->username, sizeof(buf)); |
| 1469 |
|
| 1470 |
/* |
| 1471 |
* USER already received, now we have NICK. |
| 1472 |
* *NOTE* For servers "NICK" *must* precede the |
| 1473 |
* user message (giving USER before NICK is possible |
| 1474 |
* only for local client connection!). register_user |
| 1475 |
* may reject the client and call exit_client for it |
| 1476 |
* --must test this and exit m_nick too!!! |
| 1477 |
*/ |
| 1478 |
register_local_user(client_p, source_p, nick, buf); |
| 1479 |
} |
| 1480 |
} |
| 1481 |
|
| 1482 |
/* change_local_nick() |
| 1483 |
* |
| 1484 |
* inputs - pointer to server |
| 1485 |
* - pointer to client |
| 1486 |
* - nick |
| 1487 |
* output - |
| 1488 |
* side effects - changes nick of a LOCAL user |
| 1489 |
*/ |
| 1490 |
void |
| 1491 |
change_local_nick(struct Client *client_p, struct Client *source_p, const char *nick) |
| 1492 |
{ |
| 1493 |
/* |
| 1494 |
** Client just changing his/her nick. If he/she is |
| 1495 |
** on a channel, send note of change to all clients |
| 1496 |
** on that channel. Propagate notice to other servers. |
| 1497 |
*/ |
| 1498 |
if ((source_p->localClient->last_nick_change + |
| 1499 |
ConfigFileEntry.max_nick_time) < CurrentTime) |
| 1500 |
source_p->localClient->number_of_nick_changes = 0; |
| 1501 |
source_p->localClient->last_nick_change = CurrentTime; |
| 1502 |
source_p->localClient->number_of_nick_changes++; |
| 1503 |
|
| 1504 |
if ((ConfigFileEntry.anti_nick_flood && |
| 1505 |
(source_p->localClient->number_of_nick_changes |
| 1506 |
<= ConfigFileEntry.max_nick_changes)) || |
| 1507 |
!ConfigFileEntry.anti_nick_flood || |
| 1508 |
(IsOper(source_p) && ConfigFileEntry.no_oper_flood)) |
| 1509 |
{ |
| 1510 |
if (irccmp(source_p->name, nick)) |
| 1511 |
source_p->tsinfo = CurrentTime; |
| 1512 |
|
| 1513 |
/* XXX - the format of this notice should eventually be changed |
| 1514 |
* to either %s[%s@%s], or even better would be get_client_name() -bill |
| 1515 |
*/ |
| 1516 |
sendto_realops_flags(UMODE_NCHANGE, L_ALL, "Nick change: From %s to %s [%s@%s]", |
| 1517 |
source_p->name, nick, source_p->username, source_p->host); |
| 1518 |
sendto_common_channels_local(source_p, 1, ":%s!%s@%s NICK :%s", |
| 1519 |
source_p->name, source_p->username, |
| 1520 |
source_p->host, nick); |
| 1521 |
|
| 1522 |
add_history(source_p, 1); |
| 1523 |
|
| 1524 |
/* Only hubs care about lazy link nicks not being sent on yet |
| 1525 |
* lazylink leafs/leafs always send their nicks up to hub, |
| 1526 |
* hence must always propagate nick changes. |
| 1527 |
* hubs might not propagate a nick change, if the leaf |
| 1528 |
* does not know about that client yet. |
| 1529 |
*/ |
| 1530 |
sendto_server(client_p, source_p, NULL, CAP_TS6, NOCAPS, NOFLAGS, |
| 1531 |
":%s NICK %s :%lu", |
| 1532 |
ID(source_p), nick, (unsigned long)source_p->tsinfo); |
| 1533 |
sendto_server(client_p, source_p, NULL, NOCAPS, CAP_TS6, NOFLAGS, |
| 1534 |
":%s NICK %s :%lu", |
| 1535 |
source_p->name, nick, (unsigned long)source_p->tsinfo); |
| 1536 |
} |
| 1537 |
else |
| 1538 |
{ |
| 1539 |
sendto_one(source_p, form_str(ERR_NICKTOOFAST), |
| 1540 |
me.name, source_p->name, source_p->name, |
| 1541 |
nick, ConfigFileEntry.max_nick_time); |
| 1542 |
return; |
| 1543 |
} |
| 1544 |
|
| 1545 |
/* Finally, add to hash */ |
| 1546 |
if (source_p->name[0]) |
| 1547 |
hash_del_client(source_p); |
| 1548 |
|
| 1549 |
strcpy(source_p->name, nick); |
| 1550 |
hash_add_client(source_p); |
| 1551 |
|
| 1552 |
/* Make sure everyone that has this client on its accept list |
| 1553 |
* loses that reference. |
| 1554 |
*/ |
| 1555 |
del_all_their_accepts(source_p); |
| 1556 |
|
| 1557 |
/* fd_desc is long enough */ |
| 1558 |
fd_note(&client_p->localClient->fd, "Nick: %s", nick); |
| 1559 |
} |
| 1560 |
|
| 1561 |
/* log_user_exit() |
| 1562 |
* |
| 1563 |
* inputs - pointer to connecting client |
| 1564 |
* output - NONE |
| 1565 |
* side effects - Current exiting client is logged to |
| 1566 |
* either SYSLOG or to file. |
| 1567 |
*/ |
| 1568 |
void |
| 1569 |
log_user_exit(struct Client *source_p) |
| 1570 |
{ |
| 1571 |
time_t on_for = CurrentTime - source_p->firsttime; |
| 1572 |
#ifdef SYSLOG_USERS |
| 1573 |
if (IsClient(source_p)) |
| 1574 |
{ |
| 1575 |
ilog(L_INFO, "%s (%3ld:%02ld:%02ld): %s!%s@%s %llu/%llu\n", |
| 1576 |
myctime(source_p->firsttime), |
| 1577 |
(signed long) on_for / 3600, |
| 1578 |
(signed long) (on_for % 3600)/60, |
| 1579 |
(signed long) on_for % 60, |
| 1580 |
source_p->name, source_p->username, source_p->host, |
| 1581 |
source_p->localClient->send.bytes>>10, |
| 1582 |
source_p->localClient->recv.bytes>>10); |
| 1583 |
} |
| 1584 |
#else |
| 1585 |
{ |
| 1586 |
char linebuf[BUFSIZ]; |
| 1587 |
|
| 1588 |
/* |
| 1589 |
* This conditional makes the logfile active only after |
| 1590 |
* it's been created - thus logging can be turned off by |
| 1591 |
* removing the file. |
| 1592 |
* -Taner |
| 1593 |
*/ |
| 1594 |
if (IsClient(source_p)) |
| 1595 |
{ |
| 1596 |
if (user_log_fb == NULL) |
| 1597 |
{ |
| 1598 |
if ((ConfigLoggingEntry.userlog[0] != '\0') && |
| 1599 |
(user_log_fb = fbopen(ConfigLoggingEntry.userlog, "r")) != NULL) |
| 1600 |
{ |
| 1601 |
fbclose(user_log_fb); |
| 1602 |
user_log_fb = fbopen(ConfigLoggingEntry.userlog, "a"); |
| 1603 |
} |
| 1604 |
} |
| 1605 |
|
| 1606 |
if (user_log_fb != NULL) |
| 1607 |
{ |
| 1608 |
size_t nbytes = ircsprintf(linebuf, |
| 1609 |
"%s (%3ld:%02ld:%02ld): %s!%s@%s %llu/%llu\n", |
| 1610 |
myctime(source_p->firsttime), |
| 1611 |
(signed long) on_for / 3600, |
| 1612 |
(signed long) (on_for % 3600)/60, |
| 1613 |
(signed long) on_for % 60, |
| 1614 |
source_p->name, source_p->username, source_p->host, |
| 1615 |
source_p->localClient->send.bytes>>10, |
| 1616 |
source_p->localClient->recv.bytes>>10); |
| 1617 |
fbputs(linebuf, user_log_fb, nbytes); |
| 1618 |
} |
| 1619 |
} |
| 1620 |
} |
| 1621 |
#endif |
| 1622 |
} |
| 1623 |
|
| 1624 |
|
| 1625 |
/* log_oper_action() |
| 1626 |
* |
| 1627 |
* inputs - type of oper log entry |
| 1628 |
* - pointer to oper |
| 1629 |
* - const char *pattern == format string |
| 1630 |
* - var args for format string |
| 1631 |
* output - none |
| 1632 |
* side effects - corresponding log is written to, if its present. |
| 1633 |
* |
| 1634 |
* rewritten sept 5 2005 - Dianora |
| 1635 |
*/ |
| 1636 |
void |
| 1637 |
log_oper_action(int log_type, const struct Client *source_p, |
| 1638 |
const char *pattern, ...) |
| 1639 |
{ |
| 1640 |
va_list args; |
| 1641 |
char linebuf[IRCD_BUFSIZE]; |
| 1642 |
FBFILE *log_fb; |
| 1643 |
char *logfile; |
| 1644 |
const char *log_message; |
| 1645 |
size_t nbytes; |
| 1646 |
size_t n_preamble; |
| 1647 |
char *p; |
| 1648 |
|
| 1649 |
switch(log_type) |
| 1650 |
{ |
| 1651 |
case LOG_OPER_TYPE: |
| 1652 |
logfile = ConfigLoggingEntry.operlog; |
| 1653 |
log_message = "OPER"; |
| 1654 |
break; |
| 1655 |
case LOG_FAILED_OPER_TYPE: |
| 1656 |
logfile = ConfigLoggingEntry.failed_operlog; |
| 1657 |
log_message = "FAILED OPER"; |
| 1658 |
break; |
| 1659 |
case LOG_KLINE_TYPE: |
| 1660 |
logfile = ConfigLoggingEntry.klinelog; |
| 1661 |
log_message = "KLINE"; |
| 1662 |
break; |
| 1663 |
case LOG_RKLINE_TYPE: |
| 1664 |
logfile = ConfigLoggingEntry.klinelog; |
| 1665 |
log_message = "RKLINE"; |
| 1666 |
break; |
| 1667 |
case LOG_DLINE_TYPE: |
| 1668 |
logfile = ConfigLoggingEntry.klinelog; |
| 1669 |
log_message = "DLINE"; |
| 1670 |
break; |
| 1671 |
case LOG_TEMP_DLINE_TYPE: |
| 1672 |
logfile = ConfigLoggingEntry.klinelog; |
| 1673 |
log_message = "TEMP DLINE"; |
| 1674 |
break; |
| 1675 |
case LOG_TEMP_KLINE_TYPE: |
| 1676 |
logfile = ConfigLoggingEntry.klinelog; |
| 1677 |
log_message = "TEMP KLINE"; |
| 1678 |
break; |
| 1679 |
case LOG_GLINE_TYPE: |
| 1680 |
logfile = ConfigLoggingEntry.glinelog; |
| 1681 |
log_message = "GLINE"; |
| 1682 |
break; |
| 1683 |
case LOG_KILL_TYPE: |
| 1684 |
logfile = ConfigLoggingEntry.killlog; |
| 1685 |
log_message = "KILL"; |
| 1686 |
break; |
| 1687 |
case LOG_IOERR_TYPE: |
| 1688 |
logfile = ConfigLoggingEntry.ioerrlog; |
| 1689 |
log_message = "IO ERR"; |
| 1690 |
break; |
| 1691 |
default: |
| 1692 |
return; |
| 1693 |
} |
| 1694 |
|
| 1695 |
if (*logfile == '\0') |
| 1696 |
return; |
| 1697 |
|
| 1698 |
p = linebuf; |
| 1699 |
if (source_p != NULL) |
| 1700 |
{ |
| 1701 |
n_preamble = ircsprintf(linebuf, "%s %s by (%s!%s@%s) :", |
| 1702 |
myctime(CurrentTime), log_message, |
| 1703 |
source_p->name, source_p->username, source_p->host); |
| 1704 |
|
| 1705 |
} |
| 1706 |
else |
| 1707 |
{ |
| 1708 |
n_preamble = ircsprintf(linebuf, "%s %s :", |
| 1709 |
myctime(CurrentTime), log_message); |
| 1710 |
} |
| 1711 |
|
| 1712 |
p += n_preamble; |
| 1713 |
|
| 1714 |
if ((log_fb = fbopen(logfile, "r")) != NULL) |
| 1715 |
{ |
| 1716 |
fbclose(log_fb); |
| 1717 |
log_fb = fbopen(logfile, "a"); |
| 1718 |
if (log_fb == NULL) |
| 1719 |
return; |
| 1720 |
va_start(args, pattern); |
| 1721 |
/* XXX add check for IRCD_BUFSIZE-(n_preamble+1) < 0 ? -db */ |
| 1722 |
nbytes = vsnprintf(p, IRCD_BUFSIZE-(n_preamble+1), pattern, args); |
| 1723 |
nbytes += n_preamble; |
| 1724 |
va_end(args); |
| 1725 |
fbputs(linebuf, log_fb, nbytes); |
| 1726 |
fbclose(log_fb); |
| 1727 |
} |
| 1728 |
} |