1 |
|
/* |
2 |
|
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
|
* |
4 |
< |
* Copyright (c) 1997-2015 ircd-hybrid development team |
4 |
> |
* Copyright (c) 1997-2016 ircd-hybrid development team |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
35 |
|
#include "auth.h" |
36 |
|
#include "s_bsd.h" |
37 |
|
#include "conf.h" |
38 |
+ |
#include "conf_gecos.h" |
39 |
|
#include "log.h" |
40 |
|
#include "misc.h" |
41 |
|
#include "server.h" |
125 |
|
assert(client_p->idhnext == client_p); |
126 |
|
assert(client_p->channel.head == NULL); |
127 |
|
assert(dlink_list_length(&client_p->channel) == 0); |
128 |
< |
assert(dlink_list_length(&client_p->whowas) == 0); |
128 |
> |
assert(dlink_list_length(&client_p->whowas_list) == 0); |
129 |
|
assert(dlink_list_length(&client_p->svstags) == 0); |
130 |
|
|
131 |
< |
MyFree(client_p->serv); |
132 |
< |
MyFree(client_p->certfp); |
131 |
> |
xfree(client_p->serv); |
132 |
> |
xfree(client_p->certfp); |
133 |
|
|
134 |
|
if (MyConnect(client_p)) |
135 |
|
{ |
138 |
|
assert(dlink_list_length(&client_p->connection->watches) == 0); |
139 |
|
assert(HasFlag(client_p, FLAGS_CLOSING) && IsDead(client_p)); |
140 |
|
|
140 |
– |
MyFree(client_p->connection->challenge_response); |
141 |
– |
client_p->connection->challenge_response = NULL; |
142 |
– |
MyFree(client_p->connection->challenge_operator); |
143 |
– |
client_p->connection->challenge_operator = NULL; |
144 |
– |
|
141 |
|
/* |
142 |
|
* Clean up extra sockets from listen {} blocks which have been discarded. |
143 |
|
*/ |
158 |
|
|
159 |
|
void |
160 |
|
client_attach_svstag(struct Client *client_p, unsigned int numeric, |
161 |
< |
const char *umodes, const char *const tag) |
161 |
> |
const char *umodes, const char *tag) |
162 |
|
{ |
167 |
– |
struct ServicesTag *svstag = NULL; |
163 |
|
const struct user_modes *tab = NULL; |
164 |
|
|
165 |
|
if (numeric >= ERR_LAST_ERR_MSG || *umodes != '+') |
166 |
|
return; |
167 |
|
|
168 |
< |
svstag = MyCalloc(sizeof(*svstag)); |
168 |
> |
struct ServicesTag *svstag = xcalloc(sizeof(*svstag)); |
169 |
|
svstag->numeric = numeric; |
170 |
|
svstag->tag = xstrdup(tag); |
171 |
|
|
182 |
|
void |
183 |
|
client_clear_svstags(struct Client *client_p) |
184 |
|
{ |
185 |
< |
dlink_node *node = NULL, *node_next = NULL; |
191 |
< |
|
192 |
< |
DLINK_FOREACH_SAFE(node, node_next, client_p->svstags.head) |
185 |
> |
while (client_p->svstags.head) |
186 |
|
{ |
187 |
< |
struct ServicesTag *svstag = node->data; |
187 |
> |
struct ServicesTag *svstag = client_p->svstags.head->data; |
188 |
|
|
189 |
|
dlinkDelete(&svstag->node, &client_p->svstags); |
190 |
< |
MyFree(svstag->tag); |
191 |
< |
MyFree(svstag); |
190 |
> |
xfree(svstag->tag); |
191 |
> |
xfree(svstag); |
192 |
|
} |
193 |
|
} |
194 |
|
|
201 |
|
static void |
202 |
|
check_pings_list(dlink_list *list) |
203 |
|
{ |
204 |
< |
char buf[IRCD_BUFSIZE] = ""; |
205 |
< |
int ping = 0; /* ping time value from client */ |
204 |
> |
char buf[32] = ""; /* 32 = sizeof("Ping timeout: 999999999 seconds") */ |
205 |
> |
unsigned int ping = 0; /* ping time value from client */ |
206 |
|
dlink_node *node = NULL, *node_next = NULL; |
207 |
|
|
208 |
|
DLINK_FOREACH_SAFE(node, node_next, list->head) |
250 |
|
get_client_name(client_p, SHOW_IP)); |
251 |
|
} |
252 |
|
|
253 |
< |
snprintf(buf, sizeof(buf), "Ping timeout: %d seconds", |
254 |
< |
(int)(CurrentTime - client_p->connection->lasttime)); |
253 |
> |
snprintf(buf, sizeof(buf), "Ping timeout: %ji seconds", |
254 |
> |
(CurrentTime - client_p->connection->lasttime)); |
255 |
|
exit_client(client_p, buf); |
256 |
|
} |
257 |
|
} |
288 |
|
* kill off stuff that should die |
289 |
|
* |
290 |
|
* inputs - NOT USED (from event) |
298 |
– |
* output - next time_t when check_pings() should be called again |
291 |
|
* side effects - |
292 |
|
* |
293 |
|
* |
326 |
|
void |
327 |
|
check_conf_klines(void) |
328 |
|
{ |
337 |
– |
struct MaskItem *conf = NULL; |
329 |
|
dlink_node *node = NULL, *node_next = NULL; |
330 |
+ |
const void *ptr; |
331 |
|
|
332 |
|
DLINK_FOREACH_SAFE(node, node_next, local_client_list.head) |
333 |
|
{ |
337 |
|
if (IsDead(client_p)) |
338 |
|
continue; |
339 |
|
|
340 |
< |
if ((conf = find_conf_by_address(NULL, &client_p->connection->ip, CONF_DLINE, |
341 |
< |
client_p->connection->aftype, NULL, NULL, 1))) |
340 |
> |
if ((ptr = find_conf_by_address(NULL, &client_p->connection->ip, CONF_DLINE, |
341 |
> |
client_p->connection->aftype, NULL, NULL, 1))) |
342 |
|
{ |
343 |
< |
conf_try_ban(client_p, conf); |
343 |
> |
const struct MaskItem *conf = ptr; |
344 |
> |
conf_try_ban(client_p, CLIENT_BAN_DLINE, conf->reason); |
345 |
|
continue; /* and go examine next Client */ |
346 |
|
} |
347 |
|
|
348 |
< |
if ((conf = find_conf_by_address(client_p->host, &client_p->connection->ip, |
349 |
< |
CONF_KLINE, client_p->connection->aftype, |
350 |
< |
client_p->username, NULL, 1))) |
348 |
> |
if ((ptr = find_conf_by_address(client_p->host, &client_p->connection->ip, |
349 |
> |
CONF_KLINE, client_p->connection->aftype, |
350 |
> |
client_p->username, NULL, 1))) |
351 |
|
{ |
352 |
< |
conf_try_ban(client_p, conf); |
352 |
> |
const struct MaskItem *conf = ptr; |
353 |
> |
conf_try_ban(client_p, CLIENT_BAN_KLINE, conf->reason); |
354 |
|
continue; /* and go examine next Client */ |
355 |
|
} |
356 |
|
|
357 |
< |
if ((conf = find_matching_name_conf(CONF_XLINE, client_p->info, |
364 |
< |
NULL, NULL, 0))) |
357 |
> |
if ((ptr = gecos_find(client_p->info, match))) |
358 |
|
{ |
359 |
< |
conf_try_ban(client_p, conf); |
359 |
> |
const struct GecosItem *conf = ptr; |
360 |
> |
conf_try_ban(client_p, CLIENT_BAN_XLINE, conf->reason); |
361 |
|
continue; /* and go examine next Client */ |
362 |
|
} |
363 |
|
} |
367 |
|
{ |
368 |
|
struct Client *client_p = node->data; |
369 |
|
|
370 |
< |
if ((conf = find_conf_by_address(NULL, &client_p->connection->ip, CONF_DLINE, |
371 |
< |
client_p->connection->aftype, NULL, NULL, 1))) |
370 |
> |
if ((ptr = find_conf_by_address(NULL, &client_p->connection->ip, CONF_DLINE, |
371 |
> |
client_p->connection->aftype, NULL, NULL, 1))) |
372 |
|
{ |
373 |
< |
conf_try_ban(client_p, conf); |
373 |
> |
const struct MaskItem *conf = ptr; |
374 |
> |
conf_try_ban(client_p, CLIENT_BAN_DLINE, conf->reason); |
375 |
|
continue; /* and go examine next Client */ |
376 |
|
} |
377 |
|
} |
386 |
|
* side effects - given client_p is banned |
387 |
|
*/ |
388 |
|
void |
389 |
< |
conf_try_ban(struct Client *client_p, struct MaskItem *conf) |
389 |
> |
conf_try_ban(struct Client *client_p, int type, const char *reason) |
390 |
|
{ |
391 |
< |
char ban_type = '\0'; |
391 |
> |
char ban_type = '?'; |
392 |
|
|
393 |
< |
switch (conf->type) |
393 |
> |
switch (type) |
394 |
|
{ |
395 |
< |
case CONF_KLINE: |
395 |
> |
case CLIENT_BAN_KLINE: |
396 |
|
if (HasFlag(client_p, FLAGS_EXEMPTKLINE)) |
397 |
|
{ |
398 |
|
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
403 |
|
|
404 |
|
ban_type = 'K'; |
405 |
|
break; |
406 |
< |
case CONF_DLINE: |
406 |
> |
case CLIENT_BAN_DLINE: |
407 |
|
if (find_conf_by_address(NULL, &client_p->connection->ip, CONF_EXEMPT, |
408 |
|
client_p->connection->aftype, NULL, NULL, 1)) |
409 |
|
return; |
410 |
|
ban_type = 'D'; |
411 |
|
break; |
412 |
< |
case CONF_XLINE: |
412 |
> |
case CLIENT_BAN_XLINE: |
413 |
|
if (HasFlag(client_p, FLAGS_EXEMPTXLINE)) |
414 |
|
{ |
415 |
|
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
419 |
|
} |
420 |
|
|
421 |
|
ban_type = 'X'; |
427 |
– |
++conf->count; |
422 |
|
break; |
423 |
|
default: |
424 |
|
assert(0); |
429 |
|
ban_type, get_client_name(client_p, HIDE_IP)); |
430 |
|
|
431 |
|
if (IsClient(client_p)) |
432 |
< |
sendto_one_numeric(client_p, &me, ERR_YOUREBANNEDCREEP, conf->reason); |
432 |
> |
sendto_one_numeric(client_p, &me, ERR_YOUREBANNEDCREEP, reason); |
433 |
|
|
434 |
< |
exit_client(client_p, conf->reason); |
434 |
> |
exit_client(client_p, reason); |
435 |
|
} |
436 |
|
|
437 |
|
/* update_client_exit_stats() |
466 |
|
* side effects - find person by (nick)name |
467 |
|
*/ |
468 |
|
struct Client * |
469 |
< |
find_person(const struct Client *const source_p, const char *name) |
469 |
> |
find_person(const struct Client *source_p, const char *name) |
470 |
|
{ |
471 |
|
struct Client *target_p = NULL; |
472 |
|
|
497 |
|
if (IsDigit(*name)) |
498 |
|
return NULL; |
499 |
|
|
500 |
< |
target_p = whowas_get_history(name, (time_t)ConfigGeneral.kill_chase_time_limit); |
500 |
> |
target_p = whowas_get_history(name, ConfigGeneral.kill_chase_time_limit); |
501 |
|
|
502 |
|
if (!target_p) |
503 |
|
{ |
529 |
|
const char * |
530 |
|
get_client_name(const struct Client *client_p, enum addr_mask_type type) |
531 |
|
{ |
532 |
< |
static char buf[HOSTLEN * 2 + USERLEN + 5]; |
532 |
> |
static char buf[HOSTLEN * 2 + USERLEN + 4]; /* +4 for [,@,],\0 */ |
533 |
|
|
534 |
|
if (!MyConnect(client_p)) |
535 |
|
return client_p->name; |
605 |
|
* that the client can show the "**signoff" message). |
606 |
|
* (Note: The notice is to the local clients *only*) |
607 |
|
*/ |
608 |
< |
sendto_common_channels_local(source_p, 0, 0, ":%s!%s@%s QUIT :%s", |
608 |
> |
sendto_common_channels_local(source_p, 0, 0, 0, ":%s!%s@%s QUIT :%s", |
609 |
|
source_p->name, source_p->username, |
610 |
|
source_p->host, comment); |
611 |
|
|
612 |
|
DLINK_FOREACH_SAFE(node, node_next, source_p->channel.head) |
613 |
|
remove_user_from_channel(node->data); |
614 |
|
|
615 |
+ |
client_clear_svstags(source_p); |
616 |
+ |
|
617 |
|
whowas_add_history(source_p, 0); |
618 |
|
whowas_off_history(source_p); |
619 |
|
|
642 |
|
hash_del_client(source_p); |
643 |
|
|
644 |
|
if (HasFlag(source_p, FLAGS_USERHOST)) |
645 |
< |
userhost_del(source_p->username, source_p->host, !MyConnect(source_p)); |
645 |
> |
userhost_del(source_p->sockhost, !MyConnect(source_p)); |
646 |
|
|
647 |
|
update_client_exit_stats(source_p); |
648 |
|
|
720 |
|
|
721 |
|
if (IsClient(source_p)) |
722 |
|
{ |
727 |
– |
time_t on_for = CurrentTime - source_p->connection->firsttime; |
728 |
– |
|
723 |
|
assert(Count.local > 0); |
724 |
|
|
725 |
|
--Count.local; |
735 |
|
free_list_task(source_p); |
736 |
|
|
737 |
|
watch_del_watch_list(source_p); |
744 |
– |
client_clear_svstags(source_p); |
738 |
|
|
739 |
|
sendto_realops_flags(UMODE_CCONN, L_ALL, SEND_NOTICE, |
740 |
|
"Client exiting: %s (%s@%s) [%s] [%s]", |
741 |
< |
source_p->name, source_p->username, source_p->host, comment, |
742 |
< |
source_p->sockhost); |
741 |
> |
source_p->name, source_p->username, source_p->host, |
742 |
> |
source_p->sockhost, comment); |
743 |
|
|
744 |
< |
ilog(LOG_TYPE_USER, "%s (%3u:%02u:%02u): %s!%s@%s %llu/%llu", |
745 |
< |
date_ctime(source_p->connection->firsttime), (unsigned int)(on_for / 3600), |
746 |
< |
(unsigned int)((on_for % 3600)/60), (unsigned int)(on_for % 60), |
744 |
> |
ilog(LOG_TYPE_USER, "%s (%ju): %s!%s@%s %s %s %ju/%ju :%s", |
745 |
> |
date_ctime(source_p->connection->firsttime), |
746 |
> |
CurrentTime - source_p->connection->firsttime, |
747 |
|
source_p->name, source_p->username, source_p->host, |
748 |
< |
source_p->connection->send.bytes>>10, |
749 |
< |
source_p->connection->recv.bytes>>10); |
748 |
> |
source_p->sockhost, source_p->account, |
749 |
> |
source_p->connection->send.bytes >> 10, |
750 |
> |
source_p->connection->recv.bytes >> 10, source_p->info); |
751 |
|
} |
752 |
|
else if (IsServer(source_p)) |
753 |
|
{ |
784 |
|
} |
785 |
|
else if (IsClient(source_p) && HasFlag(source_p->servptr, FLAGS_EOB)) |
786 |
|
sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE, |
787 |
< |
"Client exiting at %s: %s (%s@%s) [%s]", |
787 |
> |
"Client exiting at %s: %s (%s@%s) [%s] [%s]", |
788 |
|
source_p->servptr->name, source_p->name, |
789 |
< |
source_p->username, source_p->host, comment); |
789 |
> |
source_p->username, source_p->host, source_p->sockhost, comment); |
790 |
|
|
791 |
|
if (IsServer(source_p)) |
792 |
|
{ |
814 |
|
|
815 |
|
if (MyConnect(source_p)) |
816 |
|
{ |
823 |
– |
int connected = CurrentTime - source_p->connection->firsttime; |
817 |
|
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
818 |
< |
"%s was connected for %d day%s, %2d:%02d:%02d. %llu/%llu sendK/recvK.", |
819 |
< |
source_p->name, connected/86400, (connected/86400 == 1) ? "" : "s", |
827 |
< |
(connected % 86400) / 3600, (connected % 3600) / 60, connected % 60, |
818 |
> |
"%s was connected for %s. %ju/%ju sendK/recvK.", |
819 |
> |
source_p->name, time_dissect(CurrentTime - source_p->connection->firsttime), |
820 |
|
source_p->connection->send.bytes >> 10, |
821 |
|
source_p->connection->recv.bytes >> 10); |
822 |
< |
ilog(LOG_TYPE_IRCD, "%s was connected for %d day%s, %2d:%02d:%02d. %llu/%llu sendK/recvK.", |
823 |
< |
source_p->name, connected/86400, (connected/86400 == 1) ? "" : "s", |
832 |
< |
(connected % 86400) / 3600, (connected % 3600) / 60, connected % 60, |
822 |
> |
ilog(LOG_TYPE_IRCD, "%s was connected for %s. %ju/%ju sendK/recvK.", |
823 |
> |
source_p->name, time_dissect(CurrentTime - source_p->connection->firsttime), |
824 |
|
source_p->connection->send.bytes >> 10, |
825 |
|
source_p->connection->recv.bytes >> 10); |
826 |
|
} |
884 |
|
|
885 |
|
if (IsServer(client_p) || IsHandshake(client_p)) |
886 |
|
{ |
896 |
– |
int connected = CurrentTime - client_p->connection->firsttime; |
897 |
– |
|
887 |
|
if (error == 0) |
888 |
|
{ |
889 |
|
/* Admins get the real IP */ |
908 |
|
} |
909 |
|
|
910 |
|
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
911 |
< |
"%s was connected for %d day%s, %2d:%02d:%02d", |
912 |
< |
client_p->name, connected/86400, |
924 |
< |
(connected/86400 == 1) ? "" : "s", |
925 |
< |
(connected % 86400) / 3600, (connected % 3600) / 60, |
926 |
< |
connected % 60); |
911 |
> |
"%s was connected for %s", |
912 |
> |
client_p->name, time_dissect(CurrentTime - client_p->connection->firsttime)); |
913 |
|
} |
914 |
|
|
915 |
|
if (error == 0) |
970 |
|
{ |
971 |
|
dlinkDelete(&accept_p->node, &client_p->connection->acceptlist); |
972 |
|
|
973 |
< |
MyFree(accept_p->nickptr); |
974 |
< |
MyFree(accept_p->userptr); |
975 |
< |
MyFree(accept_p->hostptr); |
976 |
< |
MyFree(accept_p); |
973 |
> |
xfree(accept_p->nickptr); |
974 |
> |
xfree(accept_p->userptr); |
975 |
> |
xfree(accept_p->hostptr); |
976 |
> |
xfree(accept_p); |
977 |
|
} |
978 |
|
|
979 |
|
struct split_nuh_item * |