| 43 |
|
#include "numeric.h" |
| 44 |
|
#include "packet.h" |
| 45 |
|
#include "irc_res.h" |
| 46 |
< |
#include "s_conf.h" |
| 46 |
> |
#include "conf.h" |
| 47 |
|
#include "s_serv.h" |
| 48 |
< |
#include "s_log.h" |
| 48 |
> |
#include "log.h" |
| 49 |
|
#include "s_misc.h" |
| 50 |
|
#include "s_user.h" |
| 51 |
|
#include "send.h" |
| 62 |
|
|
| 63 |
|
static CNCB serv_connect_callback; |
| 64 |
|
|
| 65 |
– |
static void start_io(struct Client *); |
| 65 |
|
static void burst_members(struct Client *, struct Channel *); |
| 66 |
|
|
| 67 |
|
/* |
| 81 |
|
MessageFileLine *newMessageLine = 0; |
| 82 |
|
MessageFile *MessageFileptr; |
| 83 |
|
const char *p; |
| 84 |
< |
FBFILE *file; |
| 84 |
> |
FILE *file; |
| 85 |
|
char buff[512]; |
| 86 |
|
dlink_node *ptr; |
| 87 |
|
|
| 88 |
|
MessageFileptr = &ConfigFileEntry.linksfile; |
| 89 |
|
|
| 90 |
< |
if ((file = fbopen(MessageFileptr->fileName, "w")) == NULL) |
| 90 |
> |
if ((file = fopen(MessageFileptr->fileName, "w")) == NULL) |
| 91 |
|
return; |
| 92 |
|
|
| 93 |
|
for (mptr = MessageFileptr->contentsOfFile; mptr; mptr = next_mptr) |
| 101 |
|
|
| 102 |
|
DLINK_FOREACH(ptr, global_serv_list.head) |
| 103 |
|
{ |
| 104 |
< |
size_t nbytes = 0; |
| 106 |
< |
struct Client *target_p = ptr->data; |
| 104 |
> |
const struct Client *target_p = ptr->data; |
| 105 |
|
|
| 106 |
|
/* skip ourselves, we send ourselves in /links */ |
| 107 |
|
if (IsMe(target_p)) |
| 132 |
|
*/ |
| 133 |
|
assert(strlen(target_p->name) + strlen(me.name) + 6 + strlen(p) <= |
| 134 |
|
MESSAGELINELEN); |
| 135 |
< |
ircsprintf(newMessageLine->line, "%s %s :1 %s", |
| 136 |
< |
target_p->name, me.name, p); |
| 135 |
> |
snprintf(newMessageLine->line, sizeof(newMessageLine->line), "%s %s :1 %s", |
| 136 |
> |
target_p->name, me.name, p); |
| 137 |
|
newMessageLine->next = NULL; |
| 138 |
|
|
| 139 |
|
if (MessageFileptr->contentsOfFile) |
| 148 |
|
currentMessageLine = newMessageLine; |
| 149 |
|
} |
| 150 |
|
|
| 151 |
< |
nbytes = ircsprintf(buff, "%s %s :1 %s\n", target_p->name, me.name, p); |
| 152 |
< |
fbputs(buff, file, nbytes); |
| 151 |
> |
snprintf(buff, sizeof(buff), "%s %s :1 %s\n", target_p->name, me.name, p); |
| 152 |
> |
fputs(buff, file); |
| 153 |
|
} |
| 154 |
|
|
| 155 |
< |
fbclose(file); |
| 155 |
> |
fclose(file); |
| 156 |
|
} |
| 157 |
|
|
| 158 |
|
/* hunt_server() |
| 183 |
|
dlink_node *ptr; |
| 184 |
|
int wilds; |
| 185 |
|
|
| 186 |
< |
/* Assume it's me, if no server |
| 187 |
< |
*/ |
| 188 |
< |
if (parc <= server || EmptyString(parv[server]) || |
| 189 |
< |
match(me.name, parv[server]) || |
| 190 |
< |
match(parv[server], me.name) || |
| 191 |
< |
!strcmp(parv[server], me.id)) |
| 194 |
< |
return(HUNTED_ISME); |
| 186 |
> |
/* Assume it's me, if no server */ |
| 187 |
> |
if (parc <= server || EmptyString(parv[server])) |
| 188 |
> |
return HUNTED_ISME; |
| 189 |
> |
|
| 190 |
> |
if (!strcmp(parv[server], me.id) || match(parv[server], me.name)) |
| 191 |
> |
return HUNTED_ISME; |
| 192 |
|
|
| 193 |
|
/* These are to pickup matches that would cause the following |
| 194 |
|
* message to go in the wrong direction while doing quick fast |
| 208 |
|
target_p = NULL; |
| 209 |
|
|
| 210 |
|
collapse(parv[server]); |
| 211 |
< |
wilds = (strchr(parv[server], '?') || strchr(parv[server], '*')); |
| 211 |
> |
wilds = has_wildcards(parv[server]); |
| 212 |
|
|
| 213 |
|
/* Again, if there are no wild cards involved in the server |
| 214 |
|
* name, use the hash lookup |
| 324 |
|
confrq = DEFAULT_CONNECTFREQUENCY; |
| 325 |
|
else |
| 326 |
|
{ |
| 327 |
< |
confrq = ConFreq(cltmp); |
| 328 |
< |
if (confrq < MIN_CONN_FREQ ) |
| 327 |
> |
confrq = cltmp->con_freq; |
| 328 |
> |
if (confrq < MIN_CONN_FREQ) |
| 329 |
|
confrq = MIN_CONN_FREQ; |
| 330 |
|
} |
| 331 |
|
|
| 337 |
|
if (hash_find_server(conf->name) != NULL) |
| 338 |
|
continue; |
| 339 |
|
|
| 340 |
< |
if (CurrUserCount(cltmp) < MaxTotal(cltmp)) |
| 340 |
> |
if (cltmp->curr_user_count < cltmp->max_total) |
| 341 |
|
{ |
| 342 |
|
/* Go to the end of the list, if not already last */ |
| 343 |
|
if (ptr->next != NULL) |
| 457 |
|
|
| 458 |
|
attach_conf(client_p, server_conf); |
| 459 |
|
|
| 463 |
– |
/* Now find all leaf or hub config items for this server */ |
| 464 |
– |
DLINK_FOREACH(ptr, hub_items.head) |
| 465 |
– |
{ |
| 466 |
– |
conf = ptr->data; |
| 467 |
– |
|
| 468 |
– |
if (!match(name, conf->name)) |
| 469 |
– |
continue; |
| 470 |
– |
attach_conf(client_p, conf); |
| 471 |
– |
} |
| 472 |
– |
|
| 473 |
– |
DLINK_FOREACH(ptr, leaf_items.head) |
| 474 |
– |
{ |
| 475 |
– |
conf = ptr->data; |
| 476 |
– |
|
| 477 |
– |
if (!match(name, conf->name)) |
| 478 |
– |
continue; |
| 479 |
– |
attach_conf(client_p, conf); |
| 480 |
– |
} |
| 481 |
– |
|
| 460 |
|
server_aconf = map_to_conf(server_conf); |
| 461 |
|
|
| 462 |
|
if (!IsConfTopicBurst(server_aconf)) |
| 475 |
|
{ |
| 476 |
|
#ifdef IPV6 |
| 477 |
|
case AF_INET6: |
| 478 |
< |
v6 = (struct sockaddr_in6 *)&aconf->ipnum; |
| 478 |
> |
v6 = (struct sockaddr_in6 *)&aconf->addr; |
| 479 |
|
|
| 480 |
|
if (IN6_IS_ADDR_UNSPECIFIED(&v6->sin6_addr)) |
| 481 |
< |
memcpy(&aconf->ipnum, &client_p->localClient->ip, sizeof(struct irc_ssaddr)); |
| 481 |
> |
memcpy(&aconf->addr, &client_p->localClient->ip, sizeof(struct irc_ssaddr)); |
| 482 |
|
break; |
| 483 |
|
#endif |
| 484 |
|
case AF_INET: |
| 485 |
< |
v4 = (struct sockaddr_in *)&aconf->ipnum; |
| 485 |
> |
v4 = (struct sockaddr_in *)&aconf->addr; |
| 486 |
|
|
| 487 |
|
if (v4->sin_addr.s_addr == INADDR_NONE) |
| 488 |
< |
memcpy(&aconf->ipnum, &client_p->localClient->ip, sizeof(struct irc_ssaddr)); |
| 488 |
> |
memcpy(&aconf->addr, &client_p->localClient->ip, sizeof(struct irc_ssaddr)); |
| 489 |
|
break; |
| 490 |
|
} |
| 491 |
|
} |
| 668 |
|
target_p->servptr->name, target_p->info); |
| 669 |
|
} |
| 670 |
|
|
| 671 |
< |
if (IsConfAwayBurst((struct AccessItem *)map_to_conf(client_p->serv->sconf))) |
| 671 |
> |
if (IsConfAwayBurst((struct AccessItem *)map_to_conf(client_p->localClient->confs.head->data))) |
| 672 |
|
if (!EmptyString(target_p->away)) |
| 673 |
|
sendto_one(client_p, ":%s AWAY :%s", target_p->name, |
| 674 |
|
target_p->away); |
| 735 |
|
const char *inpath; |
| 736 |
|
static char inpath_ip[HOSTLEN * 2 + USERLEN + 6]; |
| 737 |
|
dlink_node *ptr; |
| 738 |
+ |
#ifdef HAVE_LIBCRYPTO |
| 739 |
+ |
const COMP_METHOD *compression = NULL, *expansion = NULL; |
| 740 |
+ |
#endif |
| 741 |
|
|
| 742 |
|
assert(client_p != NULL); |
| 743 |
|
|
| 855 |
|
AddFlag(client_p, FLAGS_SERVICE); |
| 856 |
|
|
| 857 |
|
/* Show the real host/IP to admins */ |
| 858 |
+ |
#ifdef HAVE_LIBCRYPTO |
| 859 |
|
if (client_p->localClient->fd.ssl) |
| 860 |
|
{ |
| 861 |
+ |
compression = SSL_get_current_compression(client_p->localClient->fd.ssl); |
| 862 |
+ |
expansion = SSL_get_current_expansion(client_p->localClient->fd.ssl); |
| 863 |
+ |
|
| 864 |
|
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
| 865 |
< |
"Link with %s established: [SSL: %s] (Capabilities: %s)", |
| 865 |
> |
"Link with %s established: [SSL: %s, Compression/Expansion method: %s/%s] (Capabilities: %s)", |
| 866 |
|
inpath_ip, ssl_get_cipher(client_p->localClient->fd.ssl), |
| 867 |
+ |
compression ? SSL_COMP_get_name(compression) : "NONE", |
| 868 |
+ |
expansion ? SSL_COMP_get_name(expansion) : "NONE", |
| 869 |
|
show_capabilities(client_p)); |
| 870 |
|
/* Now show the masked hostname/IP to opers */ |
| 871 |
|
sendto_realops_flags(UMODE_ALL, L_OPER, |
| 872 |
< |
"Link with %s established: [SSL: %s] (Capabilities: %s)", |
| 872 |
> |
"Link with %s established: [SSL: %s, Compression/Expansion method: %s/%s] (Capabilities: %s)", |
| 873 |
|
inpath, ssl_get_cipher(client_p->localClient->fd.ssl), |
| 874 |
+ |
compression ? SSL_COMP_get_name(compression) : "NONE", |
| 875 |
+ |
expansion ? SSL_COMP_get_name(expansion) : "NONE", |
| 876 |
|
show_capabilities(client_p)); |
| 877 |
< |
ilog(LOG_TYPE_IRCD, "Link with %s established: [SSL: %s] (Capabilities: %s)", |
| 877 |
> |
ilog(LOG_TYPE_IRCD, "Link with %s established: [SSL: %s, Compression/Expansion method: %s/%s] (Capabilities: %s)", |
| 878 |
|
inpath_ip, ssl_get_cipher(client_p->localClient->fd.ssl), |
| 879 |
+ |
compression ? SSL_COMP_get_name(compression) : "NONE", |
| 880 |
+ |
expansion ? SSL_COMP_get_name(expansion) : "NONE", |
| 881 |
|
show_capabilities(client_p)); |
| 882 |
|
} |
| 883 |
|
else |
| 884 |
+ |
#endif |
| 885 |
|
{ |
| 886 |
|
sendto_realops_flags(UMODE_ALL, L_ADMIN, |
| 887 |
|
"Link with %s established: (Capabilities: %s)", |
| 894 |
|
inpath_ip, show_capabilities(client_p)); |
| 895 |
|
} |
| 896 |
|
|
| 905 |
– |
client_p->serv->sconf = conf; |
| 906 |
– |
|
| 897 |
|
fd_note(&client_p->localClient->fd, "Server: %s", client_p->name); |
| 898 |
|
|
| 899 |
|
/* Old sendto_serv_but_one() call removed because we now |
| 1074 |
|
chptr->topic_info, |
| 1075 |
|
chptr->topic); |
| 1076 |
|
else if (IsCapable(client_p, CAP_TB)) |
| 1077 |
< |
{ |
| 1078 |
< |
if (ConfigChannel.burst_topicwho) |
| 1079 |
< |
{ |
| 1080 |
< |
sendto_one(client_p, ":%s TB %s %lu %s :%s", |
| 1091 |
< |
me.name, chptr->chname, |
| 1092 |
< |
(unsigned long)chptr->topic_time, |
| 1093 |
< |
chptr->topic_info, chptr->topic); |
| 1094 |
< |
} |
| 1095 |
< |
else |
| 1096 |
< |
{ |
| 1097 |
< |
sendto_one(client_p, ":%s TB %s %lu :%s", |
| 1098 |
< |
me.name, chptr->chname, |
| 1099 |
< |
(unsigned long)chptr->topic_time, |
| 1100 |
< |
chptr->topic); |
| 1101 |
< |
} |
| 1102 |
< |
} |
| 1077 |
> |
sendto_one(client_p, ":%s TB %s %lu %s :%s", |
| 1078 |
> |
me.name, chptr->chname, |
| 1079 |
> |
(unsigned long)chptr->topic_time, |
| 1080 |
> |
chptr->topic_info, chptr->topic); |
| 1081 |
|
} |
| 1082 |
|
} |
| 1083 |
|
|
| 1136 |
|
{ |
| 1137 |
|
struct ConfItem *conf; |
| 1138 |
|
struct Client *client_p; |
| 1139 |
< |
char buf[HOSTIPLEN]; |
| 1139 |
> |
char buf[HOSTIPLEN + 1]; |
| 1140 |
|
|
| 1141 |
|
/* conversion structs */ |
| 1142 |
|
struct sockaddr_in *v4; |
| 1143 |
|
/* Make sure aconf is useful */ |
| 1144 |
|
assert(aconf != NULL); |
| 1145 |
|
|
| 1168 |
– |
if(aconf == NULL) |
| 1169 |
– |
return (0); |
| 1170 |
– |
|
| 1146 |
|
/* XXX should be passing struct ConfItem in the first place */ |
| 1147 |
|
conf = unmap_conf_item(aconf); |
| 1148 |
|
|
| 1149 |
|
/* log */ |
| 1150 |
< |
getnameinfo((struct sockaddr *)&aconf->ipnum, aconf->ipnum.ss_len, |
| 1150 |
> |
getnameinfo((struct sockaddr *)&aconf->addr, aconf->addr.ss_len, |
| 1151 |
|
buf, sizeof(buf), NULL, 0, NI_NUMERICHOST); |
| 1152 |
< |
ilog(LOG_TYPE_IRCD, "Connect to %s[%s] @%s", aconf->user, aconf->host, |
| 1152 |
> |
ilog(LOG_TYPE_IRCD, "Connect to %s[%s] @%s", conf->name, aconf->host, |
| 1153 |
|
buf); |
| 1154 |
|
|
| 1155 |
|
/* Still processing a DNS lookup? -> exit */ |
| 1198 |
|
strlcpy(client_p->sockhost, buf, sizeof(client_p->sockhost)); |
| 1199 |
|
|
| 1200 |
|
/* create a socket for the server connection */ |
| 1201 |
< |
if (comm_open(&client_p->localClient->fd, aconf->ipnum.ss.ss_family, |
| 1201 |
> |
if (comm_open(&client_p->localClient->fd, aconf->addr.ss.ss_family, |
| 1202 |
|
SOCK_STREAM, 0, NULL) < 0) |
| 1203 |
|
{ |
| 1204 |
|
/* Eek, failure to create the socket */ |
| 1253 |
|
switch (aconf->aftype) |
| 1254 |
|
{ |
| 1255 |
|
case AF_INET: |
| 1256 |
< |
v4 = (struct sockaddr_in*)&aconf->my_ipnum; |
| 1256 |
> |
v4 = (struct sockaddr_in*)&aconf->bind; |
| 1257 |
|
if (v4->sin_addr.s_addr != 0) |
| 1258 |
|
{ |
| 1259 |
|
struct irc_ssaddr ipn; |
| 1260 |
|
memset(&ipn, 0, sizeof(struct irc_ssaddr)); |
| 1261 |
|
ipn.ss.ss_family = AF_INET; |
| 1262 |
|
ipn.ss_port = 0; |
| 1263 |
< |
memcpy(&ipn, &aconf->my_ipnum, sizeof(struct irc_ssaddr)); |
| 1263 |
> |
memcpy(&ipn, &aconf->bind, sizeof(struct irc_ssaddr)); |
| 1264 |
|
comm_connect_tcp(&client_p->localClient->fd, aconf->host, aconf->port, |
| 1265 |
|
(struct sockaddr *)&ipn, ipn.ss_len, |
| 1266 |
|
serv_connect_callback, client_p, aconf->aftype, |
| 1291 |
|
struct sockaddr_in6 *v6conf; |
| 1292 |
|
|
| 1293 |
|
memset(&ipn, 0, sizeof(struct irc_ssaddr)); |
| 1294 |
< |
v6conf = (struct sockaddr_in6 *)&aconf->my_ipnum; |
| 1294 |
> |
v6conf = (struct sockaddr_in6 *)&aconf->bind; |
| 1295 |
|
v6 = (struct sockaddr_in6 *)&ipn; |
| 1296 |
|
|
| 1297 |
|
if (memcmp(&v6conf->sin6_addr, &v6->sin6_addr, |
| 1298 |
|
sizeof(struct in6_addr)) != 0) |
| 1299 |
|
{ |
| 1300 |
< |
memcpy(&ipn, &aconf->my_ipnum, sizeof(struct irc_ssaddr)); |
| 1300 |
> |
memcpy(&ipn, &aconf->bind, sizeof(struct irc_ssaddr)); |
| 1301 |
|
ipn.ss.ss_family = AF_INET6; |
| 1302 |
|
ipn.ss_port = 0; |
| 1303 |
|
comm_connect_tcp(&client_p->localClient->fd, |
| 1382 |
|
} |
| 1383 |
|
|
| 1384 |
|
static void |
| 1385 |
< |
ssl_server_handshake(struct Client *client_p) |
| 1385 |
> |
ssl_server_handshake(fde_t *fd, struct Client *client_p) |
| 1386 |
|
{ |
| 1387 |
|
int ret; |
| 1388 |
|
int err; |
| 1395 |
|
{ |
| 1396 |
|
case SSL_ERROR_WANT_WRITE: |
| 1397 |
|
comm_setselect(&client_p->localClient->fd, COMM_SELECT_WRITE, |
| 1398 |
< |
(PF *) ssl_server_handshake, client_p, 0); |
| 1398 |
> |
(PF *)ssl_server_handshake, client_p, 0); |
| 1399 |
|
return; |
| 1400 |
|
case SSL_ERROR_WANT_READ: |
| 1401 |
|
comm_setselect(&client_p->localClient->fd, COMM_SELECT_READ, |
| 1402 |
< |
(PF *) ssl_server_handshake, client_p, 0); |
| 1402 |
> |
(PF *)ssl_server_handshake, client_p, 0); |
| 1403 |
|
return; |
| 1404 |
|
default: |
| 1405 |
+ |
{ |
| 1406 |
+ |
const char *sslerr = ERR_error_string(ERR_get_error(), NULL); |
| 1407 |
+ |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 1408 |
+ |
"Error connecting to %s: %s", client_p->name, |
| 1409 |
+ |
sslerr ? sslerr : "unknown SSL error"); |
| 1410 |
|
exit_client(client_p, client_p, "Error during SSL handshake"); |
| 1411 |
|
return; |
| 1412 |
+ |
} |
| 1413 |
|
} |
| 1414 |
|
} |
| 1415 |
|
|
| 1417 |
|
} |
| 1418 |
|
|
| 1419 |
|
static void |
| 1420 |
< |
ssl_connect_init(struct Client *client_p, fde_t *fd) |
| 1420 |
> |
ssl_connect_init(struct Client *client_p, struct AccessItem *aconf, fde_t *fd) |
| 1421 |
|
{ |
| 1422 |
|
if ((client_p->localClient->fd.ssl = SSL_new(ServerInfo.client_ctx)) == NULL) |
| 1423 |
|
{ |
| 1429 |
|
} |
| 1430 |
|
|
| 1431 |
|
SSL_set_fd(fd->ssl, fd->fd); |
| 1432 |
< |
ssl_server_handshake(client_p); |
| 1432 |
> |
|
| 1433 |
> |
if (!EmptyString(aconf->cipher_list)) |
| 1434 |
> |
SSL_set_cipher_list(client_p->localClient->fd.ssl, aconf->cipher_list); |
| 1435 |
> |
|
| 1436 |
> |
ssl_server_handshake(NULL, client_p); |
| 1437 |
|
} |
| 1438 |
|
#endif |
| 1439 |
|
|
| 1507 |
|
#ifdef HAVE_LIBCRYPTO |
| 1508 |
|
if (IsConfSSL(aconf)) |
| 1509 |
|
{ |
| 1510 |
< |
ssl_connect_init(client_p, fd); |
| 1510 |
> |
ssl_connect_init(client_p, aconf, fd); |
| 1511 |
|
return; |
| 1512 |
|
} |
| 1513 |
|
#endif |