| 30 |
|
#include "fdlist.h" |
| 31 |
|
#include "s_bsd.h" |
| 32 |
|
#include "client.h" |
| 33 |
– |
#include "common.h" |
| 33 |
|
#include "dbuf.h" |
| 34 |
|
#include "event.h" |
| 35 |
|
#include "irc_string.h" |
| 37 |
– |
#include "irc_getnameinfo.h" |
| 38 |
– |
#include "irc_getaddrinfo.h" |
| 36 |
|
#include "ircd.h" |
| 37 |
|
#include "listener.h" |
| 38 |
|
#include "numeric.h" |
| 39 |
|
#include "packet.h" |
| 40 |
|
#include "irc_res.h" |
| 44 |
– |
#include "inet_misc.h" |
| 41 |
|
#include "restart.h" |
| 42 |
|
#include "s_auth.h" |
| 43 |
< |
#include "s_conf.h" |
| 44 |
< |
#include "s_log.h" |
| 43 |
> |
#include "conf.h" |
| 44 |
> |
#include "log.h" |
| 45 |
|
#include "s_serv.h" |
| 46 |
|
#include "send.h" |
| 47 |
|
#include "memory.h" |
| 129 |
|
{ |
| 130 |
|
who = (who) ? who : ""; |
| 131 |
|
|
| 132 |
< |
sendto_realops_flags(UMODE_DEBUG, level, text, who, strerror(error)); |
| 133 |
< |
log_oper_action(LOG_IOERR_TYPE, NULL, "%s %s %s\n", who, text, strerror(error)); |
| 134 |
< |
ilog(L_ERROR, text, who, strerror(error)); |
| 132 |
> |
sendto_realops_flags(UMODE_DEBUG, level, SEND_NOTICE, |
| 133 |
> |
text, who, strerror(error)); |
| 134 |
> |
ilog(LOG_TYPE_IRCD, text, who, strerror(error)); |
| 135 |
|
} |
| 136 |
|
|
| 137 |
|
/* |
| 177 |
|
void |
| 178 |
|
close_connection(struct Client *client_p) |
| 179 |
|
{ |
| 180 |
< |
struct ConfItem *conf; |
| 185 |
< |
struct AccessItem *aconf; |
| 186 |
< |
struct ClassItem *aclass; |
| 180 |
> |
dlink_node *ptr = NULL; |
| 181 |
|
|
| 182 |
< |
assert(NULL != client_p); |
| 182 |
> |
assert(client_p); |
| 183 |
|
|
| 184 |
|
if (!IsDead(client_p)) |
| 185 |
|
{ |
| 192 |
|
send_queued_write(client_p); |
| 193 |
|
} |
| 194 |
|
|
| 195 |
< |
if (IsServer(client_p)) |
| 195 |
> |
if (IsClient(client_p)) |
| 196 |
> |
{ |
| 197 |
> |
++ServerStats.is_cl; |
| 198 |
> |
ServerStats.is_cbs += client_p->localClient->send.bytes; |
| 199 |
> |
ServerStats.is_cbr += client_p->localClient->recv.bytes; |
| 200 |
> |
ServerStats.is_cti += CurrentTime - client_p->localClient->firsttime; |
| 201 |
> |
} |
| 202 |
> |
else if (IsServer(client_p)) |
| 203 |
|
{ |
| 204 |
|
++ServerStats.is_sv; |
| 205 |
|
ServerStats.is_sbs += client_p->localClient->send.bytes; |
| 206 |
|
ServerStats.is_sbr += client_p->localClient->recv.bytes; |
| 207 |
< |
ServerStats.is_sti += CurrentTime - client_p->firsttime; |
| 207 |
> |
ServerStats.is_sti += CurrentTime - client_p->localClient->firsttime; |
| 208 |
|
|
| 209 |
< |
/* XXX Does this even make any sense at all anymore? |
| 209 |
< |
* scheduling a 'quick' reconnect could cause a pile of |
| 210 |
< |
* nick collides under TSora protocol... -db |
| 211 |
< |
*/ |
| 212 |
< |
/* |
| 213 |
< |
* If the connection has been up for a long amount of time, schedule |
| 214 |
< |
* a 'quick' reconnect, else reset the next-connect cycle. |
| 215 |
< |
*/ |
| 216 |
< |
if ((conf = find_conf_exact(SERVER_TYPE, client_p->name, |
| 217 |
< |
client_p->username, client_p->host))) |
| 209 |
> |
DLINK_FOREACH(ptr, server_items.head) |
| 210 |
|
{ |
| 211 |
+ |
struct MaskItem *conf = ptr->data; |
| 212 |
+ |
|
| 213 |
+ |
if (irccmp(conf->name, client_p->name)) |
| 214 |
+ |
continue; |
| 215 |
+ |
|
| 216 |
|
/* |
| 217 |
< |
* Reschedule a faster reconnect, if this was a automatically |
| 218 |
< |
* connected configuration entry. (Note that if we have had |
| 222 |
< |
* a rehash in between, the status has been changed to |
| 223 |
< |
* CONF_ILLEGAL). But only do this if it was a "good" link. |
| 217 |
> |
* Reset next-connect cycle of all connect{} blocks that match |
| 218 |
> |
* this servername. |
| 219 |
|
*/ |
| 220 |
< |
aconf = map_to_conf(conf); |
| 226 |
< |
aclass = map_to_conf(aconf->class_ptr); |
| 227 |
< |
aconf->hold = time(NULL); |
| 228 |
< |
aconf->hold += (aconf->hold - client_p->since > HANGONGOODLINK) ? |
| 229 |
< |
HANGONRETRYDELAY : ConFreq(aclass); |
| 220 |
> |
conf->until = CurrentTime + conf->class->con_freq; |
| 221 |
|
} |
| 222 |
|
} |
| 232 |
– |
else if (IsClient(client_p)) |
| 233 |
– |
{ |
| 234 |
– |
++ServerStats.is_cl; |
| 235 |
– |
ServerStats.is_cbs += client_p->localClient->send.bytes; |
| 236 |
– |
ServerStats.is_cbr += client_p->localClient->recv.bytes; |
| 237 |
– |
ServerStats.is_cti += CurrentTime - client_p->firsttime; |
| 238 |
– |
} |
| 223 |
|
else |
| 224 |
|
++ServerStats.is_ni; |
| 225 |
|
|
| 235 |
|
if (client_p->localClient->fd.flags.open) |
| 236 |
|
fd_close(&client_p->localClient->fd); |
| 237 |
|
|
| 254 |
– |
if (HasServlink(client_p)) |
| 255 |
– |
{ |
| 256 |
– |
if (client_p->localClient->ctrlfd.flags.open) |
| 257 |
– |
fd_close(&client_p->localClient->ctrlfd); |
| 258 |
– |
} |
| 259 |
– |
|
| 238 |
|
dbuf_clear(&client_p->localClient->buf_sendq); |
| 239 |
|
dbuf_clear(&client_p->localClient->buf_recvq); |
| 240 |
|
|
| 241 |
|
MyFree(client_p->localClient->passwd); |
| 242 |
< |
detach_conf(client_p, CONF_TYPE); |
| 242 |
> |
detach_conf(client_p, CONF_CLIENT|CONF_OPER|CONF_SERVER); |
| 243 |
|
client_p->from = NULL; /* ...this should catch them! >:) --msa */ |
| 244 |
|
} |
| 245 |
|
|
| 246 |
+ |
/* Base16 encoding is: |
| 247 |
+ |
* Copyright (c) 2001-2004, Roger Dingledine |
| 248 |
+ |
* Copyright (c) 2004-2007, Roger Dingledine, Nick Mathewson |
| 249 |
+ |
* |
| 250 |
+ |
* Redistribution and use in source and binary forms, with or without |
| 251 |
+ |
* modification, are permitted provided that the following conditions are |
| 252 |
+ |
* met: |
| 253 |
+ |
* |
| 254 |
+ |
* Redistributions of source code must retain the above copyright |
| 255 |
+ |
* notice, this list of conditions and the following disclaimer. |
| 256 |
+ |
|
| 257 |
+ |
* Redistributions in binary form must reproduce the above copyright notice, |
| 258 |
+ |
* this list of conditions and the following disclaimer |
| 259 |
+ |
* in the documentation and/or other materials provided with the distribution. |
| 260 |
+ |
* |
| 261 |
+ |
* Neither the names of the copyright owners nor the names of its |
| 262 |
+ |
* contributors may be used to endorse or promote products derived from |
| 263 |
+ |
* this software without specific prior written permission. |
| 264 |
+ |
|
| 265 |
+ |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 266 |
+ |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 267 |
+ |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 268 |
+ |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 269 |
+ |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 270 |
+ |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 271 |
+ |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 272 |
+ |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 273 |
+ |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 274 |
+ |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 275 |
+ |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 276 |
+ |
*/ |
| 277 |
+ |
static void |
| 278 |
+ |
base16_encode(char *dest, size_t destlen, const char *src, size_t srclen) |
| 279 |
+ |
{ |
| 280 |
+ |
const char *end; |
| 281 |
+ |
char *cp; |
| 282 |
+ |
|
| 283 |
+ |
assert(destlen >= srclen * 2 + 1); |
| 284 |
+ |
|
| 285 |
+ |
cp = dest; |
| 286 |
+ |
end = src + srclen; |
| 287 |
+ |
|
| 288 |
+ |
while (src < end) |
| 289 |
+ |
{ |
| 290 |
+ |
*cp++ = "0123456789ABCDEF"[(*(const uint8_t *)src) >> 4]; |
| 291 |
+ |
*cp++ = "0123456789ABCDEF"[(*(const uint8_t *)src) & 0xf]; |
| 292 |
+ |
++src; |
| 293 |
+ |
} |
| 294 |
+ |
|
| 295 |
+ |
*cp = '\0'; |
| 296 |
+ |
} |
| 297 |
+ |
|
| 298 |
|
#ifdef HAVE_LIBCRYPTO |
| 299 |
|
/* |
| 300 |
|
* ssl_handshake - let OpenSSL initialize the protocol. Register for |
| 303 |
|
static void |
| 304 |
|
ssl_handshake(int fd, struct Client *client_p) |
| 305 |
|
{ |
| 306 |
+ |
X509 *cert = NULL; |
| 307 |
|
int ret = SSL_accept(client_p->localClient->fd.ssl); |
| 308 |
+ |
int err = SSL_get_error(client_p->localClient->fd.ssl, ret); |
| 309 |
+ |
|
| 310 |
+ |
ilog(LOG_TYPE_IRCD, "SSL Error %d %s", err, ERR_error_string(err, NULL)); |
| 311 |
+ |
|
| 312 |
+ |
if ((cert = SSL_get_peer_certificate(client_p->localClient->fd.ssl))) |
| 313 |
+ |
{ |
| 314 |
+ |
int res = SSL_get_verify_result(client_p->localClient->fd.ssl); |
| 315 |
+ |
char buf[SHA_DIGEST_LENGTH * 2 + 1] = { '\0' }; |
| 316 |
+ |
|
| 317 |
+ |
if (res == X509_V_OK || res == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN || |
| 318 |
+ |
res == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE || |
| 319 |
+ |
res == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT) |
| 320 |
+ |
{ |
| 321 |
+ |
base16_encode(buf, sizeof(buf), |
| 322 |
+ |
(const char *)cert->sha1_hash, sizeof(cert->sha1_hash)); |
| 323 |
+ |
client_p->certfp = xstrdup(buf); |
| 324 |
+ |
} |
| 325 |
+ |
else |
| 326 |
+ |
ilog(LOG_TYPE_IRCD, "Client %s!%s@%s gave bad SSL client certificate: %d", |
| 327 |
+ |
client_p->name, client_p->username, client_p->host, res); |
| 328 |
+ |
X509_free(cert); |
| 329 |
+ |
} |
| 330 |
|
|
| 331 |
|
if (ret <= 0) |
| 332 |
+ |
{ |
| 333 |
|
switch (SSL_get_error(client_p->localClient->fd.ssl, ret)) |
| 334 |
|
{ |
| 335 |
|
case SSL_ERROR_WANT_WRITE: |
| 346 |
|
exit_client(client_p, client_p, "Error during SSL handshake"); |
| 347 |
|
return; |
| 348 |
|
} |
| 349 |
+ |
} |
| 350 |
|
|
| 351 |
< |
execute_callback(auth_cb, client_p); |
| 351 |
> |
start_auth(client_p); |
| 352 |
|
} |
| 353 |
|
#endif |
| 354 |
|
|
| 362 |
|
void |
| 363 |
|
add_connection(struct Listener *listener, struct irc_ssaddr *irn, int fd) |
| 364 |
|
{ |
| 365 |
< |
struct Client *new_client; |
| 311 |
< |
|
| 312 |
< |
assert(NULL != listener); |
| 313 |
< |
|
| 314 |
< |
new_client = make_client(NULL); |
| 365 |
> |
struct Client *new_client = make_client(NULL); |
| 366 |
|
|
| 367 |
|
fd_open(&new_client->localClient->fd, fd, 1, |
| 368 |
|
(listener->flags & LISTENER_SSL) ? |
| 369 |
|
"Incoming SSL connection" : "Incoming connection"); |
| 370 |
|
|
| 371 |
< |
/* |
| 371 |
> |
/* |
| 372 |
|
* copy address to 'sockhost' as a string, copy it to host too |
| 373 |
|
* so we have something valid to put into error messages... |
| 374 |
|
*/ |
| 375 |
|
memcpy(&new_client->localClient->ip, irn, sizeof(struct irc_ssaddr)); |
| 376 |
|
|
| 377 |
< |
irc_getnameinfo((struct sockaddr*)&new_client->localClient->ip, |
| 378 |
< |
new_client->localClient->ip.ss_len, new_client->sockhost, |
| 379 |
< |
sizeof(new_client->sockhost), NULL, 0, NI_NUMERICHOST); |
| 377 |
> |
getnameinfo((struct sockaddr *)&new_client->localClient->ip, |
| 378 |
> |
new_client->localClient->ip.ss_len, new_client->sockhost, |
| 379 |
> |
sizeof(new_client->sockhost), NULL, 0, NI_NUMERICHOST); |
| 380 |
|
new_client->localClient->aftype = new_client->localClient->ip.ss.ss_family; |
| 330 |
– |
#ifdef IPV6 |
| 331 |
– |
if (new_client->sockhost[0] == ':') |
| 332 |
– |
strlcat(new_client->host, "0", HOSTLEN+1); |
| 381 |
|
|
| 382 |
< |
if (new_client->localClient->aftype == AF_INET6 && |
| 383 |
< |
ConfigFileEntry.dot_in_ip6_addr == 1) |
| 382 |
> |
#ifdef HAVE_LIBGEOIP |
| 383 |
> |
/* XXX IPV6 SUPPORT XXX */ |
| 384 |
> |
if (irn->ss.ss_family == AF_INET && geoip_ctx) |
| 385 |
|
{ |
| 386 |
< |
strlcat(new_client->host, new_client->sockhost,HOSTLEN+1); |
| 387 |
< |
strlcat(new_client->host, ".", HOSTLEN+1); |
| 386 |
> |
const struct sockaddr_in *v4 = (const struct sockaddr_in *)&new_client->localClient->ip; |
| 387 |
> |
new_client->localClient->country_id = GeoIP_id_by_ipnum(geoip_ctx, (unsigned long)ntohl(v4->sin_addr.s_addr)); |
| 388 |
|
} |
| 340 |
– |
else |
| 389 |
|
#endif |
| 390 |
< |
strlcat(new_client->host, new_client->sockhost,HOSTLEN+1); |
| 390 |
> |
|
| 391 |
> |
if (new_client->sockhost[0] == ':' && new_client->sockhost[1] == ':') |
| 392 |
> |
{ |
| 393 |
> |
strlcpy(new_client->host, "0", sizeof(new_client->host)); |
| 394 |
> |
strlcpy(new_client->host+1, new_client->sockhost, sizeof(new_client->host)-1); |
| 395 |
> |
memmove(new_client->sockhost+1, new_client->sockhost, sizeof(new_client->sockhost)-1); |
| 396 |
> |
new_client->sockhost[0] = '0'; |
| 397 |
> |
} |
| 398 |
> |
else |
| 399 |
> |
strlcpy(new_client->host, new_client->sockhost, sizeof(new_client->host)); |
| 400 |
|
|
| 401 |
|
new_client->localClient->listener = listener; |
| 402 |
|
++listener->ref_count; |
| 406 |
|
{ |
| 407 |
|
if ((new_client->localClient->fd.ssl = SSL_new(ServerInfo.server_ctx)) == NULL) |
| 408 |
|
{ |
| 409 |
< |
ilog(L_CRIT, "SSL_new() ERROR! -- %s", |
| 409 |
> |
ilog(LOG_TYPE_IRCD, "SSL_new() ERROR! -- %s", |
| 410 |
|
ERR_error_string(ERR_get_error(), NULL)); |
| 411 |
|
|
| 412 |
|
SetDead(new_client); |
| 419 |
|
} |
| 420 |
|
else |
| 421 |
|
#endif |
| 422 |
< |
execute_callback(auth_cb, new_client); |
| 422 |
> |
start_auth(new_client); |
| 423 |
|
} |
| 424 |
|
|
| 425 |
|
/* |
| 583 |
|
|
| 584 |
|
snprintf(portname, sizeof(portname), "%d", port); |
| 585 |
|
|
| 586 |
< |
if (irc_getaddrinfo(host, portname, &hints, &res)) |
| 586 |
> |
if (getaddrinfo(host, portname, &hints, &res)) |
| 587 |
|
{ |
| 588 |
|
/* Send the DNS request, for the next level */ |
| 589 |
|
if (aftype == AF_INET6) |
| 599 |
|
memcpy(&fd->connect.hostaddr, res->ai_addr, res->ai_addrlen); |
| 600 |
|
fd->connect.hostaddr.ss_len = res->ai_addrlen; |
| 601 |
|
fd->connect.hostaddr.ss.ss_family = res->ai_family; |
| 602 |
< |
irc_freeaddrinfo(res); |
| 602 |
> |
freeaddrinfo(res); |
| 603 |
|
comm_settimeout(fd, timeout*1000, comm_connect_timeout, NULL); |
| 604 |
|
comm_connect_tryconnect(fd, NULL); |
| 605 |
|
} |
| 809 |
|
|
| 810 |
|
/* |
| 811 |
|
* remove_ipv6_mapping() - Removes IPv4-In-IPv6 mapping from an address |
| 812 |
< |
* This function should really inspect the struct itself rather than relying |
| 756 |
< |
* on inet_pton and inet_ntop. OSes with IPv6 mapping listening on both |
| 812 |
> |
* OSes with IPv6 mapping listening on both |
| 813 |
|
* AF_INET and AF_INET6 map AF_INET connections inside AF_INET6 structures |
| 814 |
|
* |
| 815 |
|
*/ |
| 819 |
|
{ |
| 820 |
|
if (addr->ss.ss_family == AF_INET6) |
| 821 |
|
{ |
| 822 |
< |
struct sockaddr_in6 *v6; |
| 767 |
< |
|
| 768 |
< |
v6 = (struct sockaddr_in6*)addr; |
| 769 |
< |
if (IN6_IS_ADDR_V4MAPPED(&v6->sin6_addr)) |
| 822 |
> |
if (IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)addr)->sin6_addr)) |
| 823 |
|
{ |
| 824 |
< |
char v4ip[HOSTIPLEN]; |
| 825 |
< |
struct sockaddr_in *v4 = (struct sockaddr_in*)addr; |
| 826 |
< |
inetntop(AF_INET6, &v6->sin6_addr, v4ip, HOSTIPLEN); |
| 827 |
< |
inet_pton(AF_INET, v4ip, &v4->sin_addr); |
| 824 |
> |
struct sockaddr_in6 v6; |
| 825 |
> |
struct sockaddr_in *v4 = (struct sockaddr_in *)addr; |
| 826 |
> |
|
| 827 |
> |
memcpy(&v6, addr, sizeof(v6)); |
| 828 |
> |
memset(v4, 0, sizeof(struct sockaddr_in)); |
| 829 |
> |
memcpy(&v4->sin_addr, &v6.sin6_addr.s6_addr[12], sizeof(v4->sin_addr)); |
| 830 |
> |
|
| 831 |
|
addr->ss.ss_family = AF_INET; |
| 832 |
|
addr->ss_len = sizeof(struct sockaddr_in); |
| 833 |
|
} |