| 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) |
| 404 |
|
|
| 405 |
|
assert(client_p != NULL); |
| 406 |
|
|
| 410 |
– |
if (client_p == NULL) |
| 411 |
– |
return(error); |
| 412 |
– |
|
| 413 |
– |
if (strlen(name) > HOSTLEN) |
| 414 |
– |
return(-4); |
| 415 |
– |
|
| 407 |
|
/* loop through looking for all possible connect items that might work */ |
| 408 |
|
DLINK_FOREACH(ptr, server_items.head) |
| 409 |
|
{ |
| 421 |
|
match(aconf->host, client_p->sockhost)) |
| 422 |
|
{ |
| 423 |
|
error = -2; |
| 433 |
– |
{ |
| 434 |
– |
/* A NULL password is as good as a bad one */ |
| 435 |
– |
if (EmptyString(client_p->localClient->passwd)) |
| 436 |
– |
return(-2); |
| 437 |
– |
|
| 438 |
– |
/* code in s_conf.c should not have allowed this to be NULL */ |
| 439 |
– |
if (aconf->passwd == NULL) |
| 440 |
– |
return(-2); |
| 424 |
|
|
| 425 |
< |
if (IsConfEncrypted(aconf)) |
| 426 |
< |
{ |
| 427 |
< |
if (strcmp(aconf->passwd, |
| 428 |
< |
(const char *)crypt(client_p->localClient->passwd, |
| 446 |
< |
aconf->passwd)) == 0) |
| 447 |
< |
server_conf = conf; |
| 448 |
< |
} |
| 449 |
< |
else |
| 450 |
< |
{ |
| 451 |
< |
if (strcmp(aconf->passwd, client_p->localClient->passwd) == 0) |
| 452 |
< |
server_conf = conf; |
| 453 |
< |
} |
| 454 |
< |
} |
| 425 |
> |
if (!match_conf_password(client_p->localClient->passwd, aconf)) |
| 426 |
> |
return -2; |
| 427 |
> |
|
| 428 |
> |
server_conf = conf; |
| 429 |
|
} |
| 430 |
|
} |
| 431 |
|
|
| 434 |
|
|
| 435 |
|
attach_conf(client_p, server_conf); |
| 436 |
|
|
| 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 |
– |
|
| 437 |
|
server_aconf = map_to_conf(server_conf); |
| 438 |
|
|
| 439 |
|
if (!IsConfTopicBurst(server_aconf)) |
| 440 |
< |
{ |
| 486 |
< |
ClearCap(client_p, CAP_TB); |
| 487 |
< |
ClearCap(client_p, CAP_TBURST); |
| 488 |
< |
} |
| 440 |
> |
ClearCap(client_p, CAP_TB | CAP_TBURST); |
| 441 |
|
|
| 442 |
|
if (aconf != NULL) |
| 443 |
|
{ |
| 449 |
|
{ |
| 450 |
|
#ifdef IPV6 |
| 451 |
|
case AF_INET6: |
| 452 |
< |
v6 = (struct sockaddr_in6 *)&aconf->ipnum; |
| 452 |
> |
v6 = (struct sockaddr_in6 *)&aconf->addr; |
| 453 |
|
|
| 454 |
|
if (IN6_IS_ADDR_UNSPECIFIED(&v6->sin6_addr)) |
| 455 |
< |
memcpy(&aconf->ipnum, &client_p->localClient->ip, sizeof(struct irc_ssaddr)); |
| 455 |
> |
memcpy(&aconf->addr, &client_p->localClient->ip, sizeof(struct irc_ssaddr)); |
| 456 |
|
break; |
| 457 |
|
#endif |
| 458 |
|
case AF_INET: |
| 459 |
< |
v4 = (struct sockaddr_in *)&aconf->ipnum; |
| 459 |
> |
v4 = (struct sockaddr_in *)&aconf->addr; |
| 460 |
|
|
| 461 |
|
if (v4->sin_addr.s_addr == INADDR_NONE) |
| 462 |
< |
memcpy(&aconf->ipnum, &client_p->localClient->ip, sizeof(struct irc_ssaddr)); |
| 462 |
> |
memcpy(&aconf->addr, &client_p->localClient->ip, sizeof(struct irc_ssaddr)); |
| 463 |
|
break; |
| 464 |
|
} |
| 465 |
|
} |
| 642 |
|
target_p->servptr->name, target_p->info); |
| 643 |
|
} |
| 644 |
|
|
| 645 |
< |
if (IsConfAwayBurst((struct AccessItem *)map_to_conf(client_p->serv->sconf))) |
| 645 |
> |
if (IsConfAwayBurst((struct AccessItem *)map_to_conf(client_p->localClient->confs.head->data))) |
| 646 |
|
if (!EmptyString(target_p->away)) |
| 647 |
< |
sendto_one(client_p, ":%s AWAY :%s", target_p->name, |
| 647 |
> |
sendto_one(client_p, ":%s AWAY :%s", ID_or_name(target_p, client_p), |
| 648 |
|
target_p->away); |
| 649 |
|
|
| 650 |
|
} |
| 868 |
|
inpath_ip, show_capabilities(client_p)); |
| 869 |
|
} |
| 870 |
|
|
| 919 |
– |
client_p->serv->sconf = conf; |
| 920 |
– |
|
| 871 |
|
fd_note(&client_p->localClient->fd, "Server: %s", client_p->name); |
| 872 |
|
|
| 873 |
|
/* Old sendto_serv_but_one() call removed because we now |
| 1048 |
|
chptr->topic_info, |
| 1049 |
|
chptr->topic); |
| 1050 |
|
else if (IsCapable(client_p, CAP_TB)) |
| 1051 |
< |
{ |
| 1052 |
< |
if (ConfigChannel.burst_topicwho) |
| 1053 |
< |
{ |
| 1054 |
< |
sendto_one(client_p, ":%s TB %s %lu %s :%s", |
| 1105 |
< |
me.name, chptr->chname, |
| 1106 |
< |
(unsigned long)chptr->topic_time, |
| 1107 |
< |
chptr->topic_info, chptr->topic); |
| 1108 |
< |
} |
| 1109 |
< |
else |
| 1110 |
< |
{ |
| 1111 |
< |
sendto_one(client_p, ":%s TB %s %lu :%s", |
| 1112 |
< |
me.name, chptr->chname, |
| 1113 |
< |
(unsigned long)chptr->topic_time, |
| 1114 |
< |
chptr->topic); |
| 1115 |
< |
} |
| 1116 |
< |
} |
| 1051 |
> |
sendto_one(client_p, ":%s TB %s %lu %s :%s", |
| 1052 |
> |
me.name, chptr->chname, |
| 1053 |
> |
(unsigned long)chptr->topic_time, |
| 1054 |
> |
chptr->topic_info, chptr->topic); |
| 1055 |
|
} |
| 1056 |
|
} |
| 1057 |
|
|
| 1110 |
|
{ |
| 1111 |
|
struct ConfItem *conf; |
| 1112 |
|
struct Client *client_p; |
| 1113 |
< |
char buf[HOSTIPLEN]; |
| 1113 |
> |
char buf[HOSTIPLEN + 1]; |
| 1114 |
|
|
| 1115 |
|
/* conversion structs */ |
| 1116 |
|
struct sockaddr_in *v4; |
| 1117 |
|
/* Make sure aconf is useful */ |
| 1118 |
|
assert(aconf != NULL); |
| 1119 |
|
|
| 1182 |
– |
if(aconf == NULL) |
| 1183 |
– |
return (0); |
| 1184 |
– |
|
| 1120 |
|
/* XXX should be passing struct ConfItem in the first place */ |
| 1121 |
|
conf = unmap_conf_item(aconf); |
| 1122 |
|
|
| 1123 |
|
/* log */ |
| 1124 |
< |
getnameinfo((struct sockaddr *)&aconf->ipnum, aconf->ipnum.ss_len, |
| 1124 |
> |
getnameinfo((struct sockaddr *)&aconf->addr, aconf->addr.ss_len, |
| 1125 |
|
buf, sizeof(buf), NULL, 0, NI_NUMERICHOST); |
| 1126 |
< |
ilog(LOG_TYPE_IRCD, "Connect to %s[%s] @%s", aconf->user, aconf->host, |
| 1126 |
> |
ilog(LOG_TYPE_IRCD, "Connect to %s[%s] @%s", conf->name, aconf->host, |
| 1127 |
|
buf); |
| 1128 |
|
|
| 1129 |
|
/* Still processing a DNS lookup? -> exit */ |
| 1172 |
|
strlcpy(client_p->sockhost, buf, sizeof(client_p->sockhost)); |
| 1173 |
|
|
| 1174 |
|
/* create a socket for the server connection */ |
| 1175 |
< |
if (comm_open(&client_p->localClient->fd, aconf->ipnum.ss.ss_family, |
| 1175 |
> |
if (comm_open(&client_p->localClient->fd, aconf->addr.ss.ss_family, |
| 1176 |
|
SOCK_STREAM, 0, NULL) < 0) |
| 1177 |
|
{ |
| 1178 |
|
/* Eek, failure to create the socket */ |
| 1227 |
|
switch (aconf->aftype) |
| 1228 |
|
{ |
| 1229 |
|
case AF_INET: |
| 1230 |
< |
v4 = (struct sockaddr_in*)&aconf->my_ipnum; |
| 1230 |
> |
v4 = (struct sockaddr_in*)&aconf->bind; |
| 1231 |
|
if (v4->sin_addr.s_addr != 0) |
| 1232 |
|
{ |
| 1233 |
|
struct irc_ssaddr ipn; |
| 1234 |
|
memset(&ipn, 0, sizeof(struct irc_ssaddr)); |
| 1235 |
|
ipn.ss.ss_family = AF_INET; |
| 1236 |
|
ipn.ss_port = 0; |
| 1237 |
< |
memcpy(&ipn, &aconf->my_ipnum, sizeof(struct irc_ssaddr)); |
| 1237 |
> |
memcpy(&ipn, &aconf->bind, sizeof(struct irc_ssaddr)); |
| 1238 |
|
comm_connect_tcp(&client_p->localClient->fd, aconf->host, aconf->port, |
| 1239 |
|
(struct sockaddr *)&ipn, ipn.ss_len, |
| 1240 |
|
serv_connect_callback, client_p, aconf->aftype, |
| 1265 |
|
struct sockaddr_in6 *v6conf; |
| 1266 |
|
|
| 1267 |
|
memset(&ipn, 0, sizeof(struct irc_ssaddr)); |
| 1268 |
< |
v6conf = (struct sockaddr_in6 *)&aconf->my_ipnum; |
| 1268 |
> |
v6conf = (struct sockaddr_in6 *)&aconf->bind; |
| 1269 |
|
v6 = (struct sockaddr_in6 *)&ipn; |
| 1270 |
|
|
| 1271 |
|
if (memcmp(&v6conf->sin6_addr, &v6->sin6_addr, |
| 1272 |
|
sizeof(struct in6_addr)) != 0) |
| 1273 |
|
{ |
| 1274 |
< |
memcpy(&ipn, &aconf->my_ipnum, sizeof(struct irc_ssaddr)); |
| 1274 |
> |
memcpy(&ipn, &aconf->bind, sizeof(struct irc_ssaddr)); |
| 1275 |
|
ipn.ss.ss_family = AF_INET6; |
| 1276 |
|
ipn.ss_port = 0; |
| 1277 |
|
comm_connect_tcp(&client_p->localClient->fd, |
| 1369 |
|
{ |
| 1370 |
|
case SSL_ERROR_WANT_WRITE: |
| 1371 |
|
comm_setselect(&client_p->localClient->fd, COMM_SELECT_WRITE, |
| 1372 |
< |
(PF *) ssl_server_handshake, client_p, 0); |
| 1372 |
> |
(PF *)ssl_server_handshake, client_p, 0); |
| 1373 |
|
return; |
| 1374 |
|
case SSL_ERROR_WANT_READ: |
| 1375 |
|
comm_setselect(&client_p->localClient->fd, COMM_SELECT_READ, |
| 1376 |
< |
(PF *) ssl_server_handshake, client_p, 0); |
| 1376 |
> |
(PF *)ssl_server_handshake, client_p, 0); |
| 1377 |
|
return; |
| 1378 |
|
default: |
| 1379 |
+ |
{ |
| 1380 |
+ |
const char *sslerr = ERR_error_string(ERR_get_error(), NULL); |
| 1381 |
+ |
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 1382 |
+ |
"Error connecting to %s: %s", client_p->name, |
| 1383 |
+ |
sslerr ? sslerr : "unknown SSL error"); |
| 1384 |
|
exit_client(client_p, client_p, "Error during SSL handshake"); |
| 1385 |
|
return; |
| 1386 |
+ |
} |
| 1387 |
|
} |
| 1388 |
|
} |
| 1389 |
|
|