| 40 |
|
#include "numeric.h" |
| 41 |
|
#include "packet.h" |
| 42 |
|
#include "conf.h" |
| 43 |
< |
#include "s_serv.h" |
| 43 |
> |
#include "server.h" |
| 44 |
|
#include "log.h" |
| 45 |
< |
#include "s_user.h" |
| 45 |
> |
#include "user.h" |
| 46 |
|
#include "send.h" |
| 47 |
|
#include "memory.h" |
| 48 |
|
#include "channel.h" |
| 80 |
|
free_dlink_node(ptr); |
| 81 |
|
} |
| 82 |
|
|
| 83 |
< |
DLINK_FOREACH(ptr, global_serv_list.head) |
| 83 |
> |
DLINK_FOREACH(ptr, global_server_list.head) |
| 84 |
|
{ |
| 85 |
|
const struct Client *target_p = ptr->data; |
| 86 |
|
|
| 157 |
|
const int server, const int parc, char *parv[]) |
| 158 |
|
{ |
| 159 |
|
struct Client *target_p = NULL; |
| 160 |
< |
struct Client *target_tmp = NULL; |
| 161 |
< |
dlink_node *ptr; |
| 162 |
< |
int wilds; |
| 160 |
> |
dlink_node *ptr = NULL; |
| 161 |
|
|
| 162 |
|
/* Assume it's me, if no server */ |
| 163 |
|
if (parc <= server || EmptyString(parv[server])) |
| 164 |
|
return HUNTED_ISME; |
| 165 |
|
|
| 166 |
< |
if (!strcmp(parv[server], me.id) || !match(parv[server], me.name)) |
| 167 |
< |
return HUNTED_ISME; |
| 166 |
> |
if ((target_p = find_person(source_p, parv[server])) == NULL) |
| 167 |
> |
target_p = hash_find_server(parv[server]); |
| 168 |
|
|
| 169 |
< |
/* These are to pickup matches that would cause the following |
| 169 |
> |
/* |
| 170 |
> |
* These are to pickup matches that would cause the following |
| 171 |
|
* message to go in the wrong direction while doing quick fast |
| 172 |
|
* non-matching lookups. |
| 173 |
|
*/ |
| 175 |
– |
if (MyClient(source_p)) |
| 176 |
– |
target_p = hash_find_client(parv[server]); |
| 177 |
– |
else |
| 178 |
– |
target_p = find_person(source_p, parv[server]); |
| 179 |
– |
|
| 174 |
|
if (target_p) |
| 175 |
|
if (target_p->from == source_p->from && !MyConnect(target_p)) |
| 176 |
|
target_p = NULL; |
| 177 |
|
|
| 178 |
< |
if (target_p == NULL && (target_p = hash_find_server(parv[server]))) |
| 185 |
< |
if (target_p->from == source_p->from && !MyConnect(target_p)) |
| 186 |
< |
target_p = NULL; |
| 187 |
< |
|
| 188 |
< |
wilds = has_wildcards(parv[server]); |
| 189 |
< |
|
| 190 |
< |
/* Again, if there are no wild cards involved in the server |
| 191 |
< |
* name, use the hash lookup |
| 192 |
< |
*/ |
| 193 |
< |
if (target_p == NULL) |
| 178 |
> |
if (!target_p && has_wildcards(parv[server])) |
| 179 |
|
{ |
| 180 |
< |
if (!wilds) |
| 180 |
> |
DLINK_FOREACH(ptr, global_client_list.head) |
| 181 |
|
{ |
| 182 |
< |
if (!(target_p = hash_find_server(parv[server]))) |
| 198 |
< |
{ |
| 199 |
< |
sendto_one_numeric(source_p, &me, ERR_NOSUCHSERVER, parv[server]); |
| 200 |
< |
return HUNTED_NOSUCH; |
| 201 |
< |
} |
| 202 |
< |
} |
| 203 |
< |
else |
| 204 |
< |
{ |
| 205 |
< |
DLINK_FOREACH(ptr, global_client_list.head) |
| 206 |
< |
{ |
| 207 |
< |
target_tmp = ptr->data; |
| 182 |
> |
struct Client *tmp = ptr->data; |
| 183 |
|
|
| 184 |
< |
if (!match(parv[server], target_tmp->name)) |
| 185 |
< |
{ |
| 186 |
< |
if (target_tmp->from == source_p->from && !MyConnect(target_tmp)) |
| 187 |
< |
continue; |
| 188 |
< |
target_p = ptr->data; |
| 184 |
> |
assert(IsMe(tmp) || IsServer(tmp) || IsClient(tmp)); |
| 185 |
> |
if (!match(parv[server], tmp->name)) |
| 186 |
> |
{ |
| 187 |
> |
if (tmp->from == source_p->from && !MyConnect(tmp)) |
| 188 |
> |
continue; |
| 189 |
|
|
| 190 |
< |
if (IsRegistered(target_p) && (target_p != source_p->from)) |
| 191 |
< |
break; |
| 217 |
< |
} |
| 190 |
> |
target_p = ptr->data; |
| 191 |
> |
break; |
| 192 |
|
} |
| 193 |
|
} |
| 194 |
|
} |
| 195 |
|
|
| 196 |
|
if (target_p) |
| 197 |
|
{ |
| 198 |
< |
if (!IsRegistered(target_p)) |
| 225 |
< |
{ |
| 226 |
< |
sendto_one_numeric(source_p, &me, ERR_NOSUCHSERVER, parv[server]); |
| 227 |
< |
return HUNTED_NOSUCH; |
| 228 |
< |
} |
| 229 |
< |
|
| 198 |
> |
assert(IsMe(target_p) || IsServer(target_p) || IsClient(target_p)); |
| 199 |
|
if (IsMe(target_p) || MyClient(target_p)) |
| 200 |
|
return HUNTED_ISME; |
| 201 |
|
|
| 202 |
< |
if (match(target_p->name, parv[server])) |
| 203 |
< |
parv[server] = target_p->name; |
| 235 |
< |
|
| 236 |
< |
/* This is a little kludgy but should work... */ |
| 237 |
< |
sendto_one(target_p, command, ID_or_name(source_p, target_p), |
| 202 |
> |
parv[server] = target_p->id; |
| 203 |
> |
sendto_one(target_p, command, source_p->id, |
| 204 |
|
parv[1], parv[2], parv[3], parv[4], |
| 205 |
|
parv[5], parv[6], parv[7], parv[8]); |
| 206 |
|
return HUNTED_PASS; |
| 238 |
|
|
| 239 |
|
/* Also when already connecting! (update holdtimes) --SRB |
| 240 |
|
*/ |
| 241 |
< |
if (!conf->port ||!IsConfAllowAutoConn(conf)) |
| 241 |
> |
if (!conf->port || !IsConfAllowAutoConn(conf)) |
| 242 |
|
continue; |
| 243 |
|
|
| 244 |
|
|
| 251 |
|
if (conf->until > CurrentTime) |
| 252 |
|
continue; |
| 253 |
|
|
| 254 |
< |
if (conf->class == NULL) |
| 255 |
< |
confrq = DEFAULT_CONNECTFREQUENCY; |
| 256 |
< |
else |
| 257 |
< |
{ |
| 258 |
< |
confrq = conf->class->con_freq; |
| 293 |
< |
if (confrq < MIN_CONN_FREQ) |
| 294 |
< |
confrq = MIN_CONN_FREQ; |
| 295 |
< |
} |
| 254 |
> |
assert(conf->class); |
| 255 |
> |
|
| 256 |
> |
confrq = conf->class->con_freq; |
| 257 |
> |
if (confrq < MIN_CONN_FREQ) |
| 258 |
> |
confrq = MIN_CONN_FREQ; |
| 259 |
|
|
| 260 |
|
conf->until = CurrentTime + confrq; |
| 261 |
|
|
| 306 |
|
int |
| 307 |
|
valid_servname(const char *name) |
| 308 |
|
{ |
| 309 |
< |
unsigned int length = 0; |
| 347 |
< |
unsigned int dots = 0; |
| 309 |
> |
unsigned int dots = 0; |
| 310 |
|
const char *p = name; |
| 311 |
|
|
| 312 |
|
for (; *p; ++p) |
| 314 |
|
if (!IsServChar(*p)) |
| 315 |
|
return 0; |
| 316 |
|
|
| 355 |
– |
++length; |
| 356 |
– |
|
| 317 |
|
if (*p == '.') |
| 318 |
|
++dots; |
| 319 |
|
} |
| 320 |
|
|
| 321 |
< |
return dots && length <= HOSTLEN; |
| 321 |
> |
return dots && (p - name) <= HOSTLEN; |
| 322 |
|
} |
| 323 |
|
|
| 324 |
|
int |
| 368 |
|
if (server_conf) |
| 369 |
|
{ |
| 370 |
|
struct sockaddr_in *v4; |
| 411 |
– |
#ifdef IPV6 |
| 371 |
|
struct sockaddr_in6 *v6; |
| 372 |
< |
#endif |
| 372 |
> |
|
| 373 |
|
switch (server_conf->aftype) |
| 374 |
|
{ |
| 416 |
– |
#ifdef IPV6 |
| 375 |
|
case AF_INET6: |
| 376 |
|
v6 = (struct sockaddr_in6 *)&server_conf->addr; |
| 377 |
|
|
| 378 |
|
if (IN6_IS_ADDR_UNSPECIFIED(&v6->sin6_addr)) |
| 379 |
|
memcpy(&server_conf->addr, &client_p->localClient->ip, sizeof(struct irc_ssaddr)); |
| 380 |
|
break; |
| 423 |
– |
#endif |
| 381 |
|
case AF_INET: |
| 382 |
|
v4 = (struct sockaddr_in *)&server_conf->addr; |
| 383 |
|
|
| 402 |
|
void |
| 403 |
|
add_capability(const char *capab_name, int cap_flag, int add_to_default) |
| 404 |
|
{ |
| 405 |
< |
struct Capability *cap = MyMalloc(sizeof(*cap)); |
| 405 |
> |
struct Capability *cap = MyCalloc(sizeof(*cap)); |
| 406 |
|
|
| 407 |
|
cap->name = xstrdup(capab_name); |
| 408 |
|
cap->cap = cap_flag; |
| 476 |
|
void |
| 477 |
|
send_capabilities(struct Client *client_p, int cap_can_send) |
| 478 |
|
{ |
| 479 |
< |
char msgbuf[IRCD_BUFSIZE] = ""; |
| 480 |
< |
char *t = msgbuf; |
| 524 |
< |
int tl; |
| 525 |
< |
dlink_node *ptr = NULL; |
| 479 |
> |
char buf[IRCD_BUFSIZE] = ""; |
| 480 |
> |
const dlink_node *ptr = NULL; |
| 481 |
|
|
| 482 |
|
DLINK_FOREACH(ptr, cap_list.head) |
| 483 |
|
{ |
| 484 |
< |
struct Capability *cap = ptr->data; |
| 484 |
> |
const struct Capability *cap = ptr->data; |
| 485 |
|
|
| 486 |
|
if (cap->cap & (cap_can_send|default_server_capabs)) |
| 487 |
|
{ |
| 488 |
< |
tl = sprintf(t, "%s ", cap->name); |
| 489 |
< |
t += tl; |
| 488 |
> |
strlcat(buf, cap->name, sizeof(buf)); |
| 489 |
> |
if (ptr->next) |
| 490 |
> |
strlcat(buf, " ", sizeof(buf)); |
| 491 |
|
} |
| 492 |
|
} |
| 493 |
|
|
| 494 |
< |
*(t - 1) = '\0'; |
| 539 |
< |
sendto_one(client_p, "CAPAB :%s", msgbuf); |
| 494 |
> |
sendto_one(client_p, "CAPAB :%s", buf); |
| 495 |
|
} |
| 496 |
|
|
| 497 |
|
/* |
| 534 |
|
make_server(struct Client *client_p) |
| 535 |
|
{ |
| 536 |
|
if (client_p->serv == NULL) |
| 537 |
< |
client_p->serv = MyMalloc(sizeof(struct Server)); |
| 537 |
> |
client_p->serv = MyCalloc(sizeof(struct Server)); |
| 538 |
|
|
| 539 |
|
return client_p->serv; |
| 540 |
|
} |
| 665 |
|
strlcpy(client_p->serv->by, "AutoConn.", sizeof(client_p->serv->by)); |
| 666 |
|
|
| 667 |
|
SetConnecting(client_p); |
| 713 |
– |
dlinkAdd(client_p, &client_p->node, &global_client_list); |
| 714 |
– |
|
| 668 |
|
client_p->localClient->aftype = conf->aftype; |
| 669 |
|
|
| 670 |
|
/* Now, initiate the connection */ |
| 687 |
|
serv_connect_callback, client_p, conf->aftype, |
| 688 |
|
CONNECTTIMEOUT); |
| 689 |
|
} |
| 690 |
< |
else if (ServerInfo.specific_ipv4_vhost) |
| 690 |
> |
else if (ConfigServerInfo.specific_ipv4_vhost) |
| 691 |
|
{ |
| 692 |
|
struct irc_ssaddr ipn; |
| 693 |
|
memset(&ipn, 0, sizeof(struct irc_ssaddr)); |
| 694 |
|
ipn.ss.ss_family = AF_INET; |
| 695 |
|
ipn.ss_port = 0; |
| 696 |
< |
memcpy(&ipn, &ServerInfo.ip, sizeof(struct irc_ssaddr)); |
| 696 |
> |
memcpy(&ipn, &ConfigServerInfo.ip, sizeof(struct irc_ssaddr)); |
| 697 |
|
comm_connect_tcp(&client_p->localClient->fd, conf->host, conf->port, |
| 698 |
|
(struct sockaddr *)&ipn, ipn.ss_len, |
| 699 |
|
serv_connect_callback, client_p, conf->aftype, |
| 704 |
|
NULL, 0, serv_connect_callback, client_p, conf->aftype, |
| 705 |
|
CONNECTTIMEOUT); |
| 706 |
|
break; |
| 754 |
– |
#ifdef IPV6 |
| 707 |
|
case AF_INET6: |
| 708 |
|
{ |
| 709 |
|
struct irc_ssaddr ipn; |
| 725 |
|
serv_connect_callback, client_p, |
| 726 |
|
conf->aftype, CONNECTTIMEOUT); |
| 727 |
|
} |
| 728 |
< |
else if (ServerInfo.specific_ipv6_vhost) |
| 728 |
> |
else if (ConfigServerInfo.specific_ipv6_vhost) |
| 729 |
|
{ |
| 730 |
< |
memcpy(&ipn, &ServerInfo.ip6, sizeof(struct irc_ssaddr)); |
| 730 |
> |
memcpy(&ipn, &ConfigServerInfo.ip6, sizeof(struct irc_ssaddr)); |
| 731 |
|
ipn.ss.ss_family = AF_INET6; |
| 732 |
|
ipn.ss_port = 0; |
| 733 |
|
comm_connect_tcp(&client_p->localClient->fd, |
| 742 |
|
NULL, 0, serv_connect_callback, client_p, |
| 743 |
|
conf->aftype, CONNECTTIMEOUT); |
| 744 |
|
} |
| 793 |
– |
#endif |
| 745 |
|
} |
| 746 |
+ |
|
| 747 |
|
return 1; |
| 748 |
|
} |
| 749 |
|
|
| 826 |
|
if ((cert = SSL_get_peer_certificate(client_p->localClient->fd.ssl))) |
| 827 |
|
{ |
| 828 |
|
int res = SSL_get_verify_result(client_p->localClient->fd.ssl); |
| 829 |
< |
char buf[EVP_MAX_MD_SIZE * 2 + 1] = { '\0' }; |
| 830 |
< |
unsigned char md[EVP_MAX_MD_SIZE] = { '\0' }; |
| 829 |
> |
char buf[EVP_MAX_MD_SIZE * 2 + 1] = ""; |
| 830 |
> |
unsigned char md[EVP_MAX_MD_SIZE] = ""; |
| 831 |
|
|
| 832 |
|
if (res == X509_V_OK || res == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN || |
| 833 |
|
res == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE || |
| 834 |
|
res == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT) |
| 835 |
|
{ |
| 836 |
< |
unsigned int i = 0, n = 0; |
| 836 |
> |
unsigned int n = 0; |
| 837 |
|
|
| 838 |
< |
if (X509_digest(cert, EVP_sha256(), md, &n)) |
| 838 |
> |
if (X509_digest(cert, ConfigServerInfo.message_digest_algorithm, md, &n)) |
| 839 |
|
{ |
| 840 |
< |
for (; i < n; ++i) |
| 889 |
< |
snprintf(buf + 2 * i, 3, "%02X", md[i]); |
| 840 |
> |
binary_to_hex(md, buf, n); |
| 841 |
|
client_p->certfp = xstrdup(buf); |
| 842 |
|
} |
| 843 |
|
} |
| 853 |
|
static void |
| 854 |
|
ssl_connect_init(struct Client *client_p, struct MaskItem *conf, fde_t *fd) |
| 855 |
|
{ |
| 856 |
< |
if ((client_p->localClient->fd.ssl = SSL_new(ServerInfo.client_ctx)) == NULL) |
| 856 |
> |
if ((client_p->localClient->fd.ssl = SSL_new(ConfigServerInfo.client_ctx)) == NULL) |
| 857 |
|
{ |
| 858 |
|
ilog(LOG_TYPE_IRCD, "SSL_new() ERROR! -- %s", |
| 859 |
|
ERR_error_string(ERR_get_error(), NULL)); |
| 885 |
|
struct Client *client_p = data; |
| 886 |
|
struct MaskItem *conf = NULL; |
| 887 |
|
|
| 888 |
< |
/* First, make sure its a real client! */ |
| 888 |
> |
/* First, make sure it's a real client! */ |
| 889 |
|
assert(client_p); |
| 890 |
|
assert(&client_p->localClient->fd == fd); |
| 891 |
|
|