Changeset 9c78519
- Timestamp:
- 2017-04-05T22:38:08Z (8 years ago)
- Parents:
- b1b9453
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
debian/copyright
rb1b9453 r9c78519 17 17 * lib/json.[ch] is from <https://github.com/udp/json-parser> and licensed 18 18 under the modified BSD license. 19 * reverse_lookup() from lib/misc.c is from OpenSSH and licenced under20 the BSD-3-clauselicence.19 * lib/canohost.[ch] is from OpenSSH and licenced under the BSD-3-clause 20 licence. 21 21 22 22 -
irc.c
rb1b9453 r9c78519 25 25 26 26 #include "bitlbee.h" 27 #include "canohost.h" 27 28 #include "ipc.h" 28 29 #include "dcc.h" -
irc_commands.c
rb1b9453 r9c78519 26 26 #define BITLBEE_CORE 27 27 #include "bitlbee.h" 28 #include "canohost.h" 28 29 #include "help.h" 29 30 #include "ipc.h" -
lib/Makefile
rb1b9453 r9c78519 13 13 14 14 # [SH] Program variables 15 objects = arc.o base64.o $(EVENT_HANDLER) ftutil.o http_client.o ini.o json.o json_util.o md5.o misc.o oauth.o oauth2.o proxy.o sha1.o $(SSL_CLIENT) url.o xmltree.o ns_parse.o15 objects = arc.o base64.o canohost.o $(EVENT_HANDLER) ftutil.o http_client.o ini.o json.o json_util.o md5.o misc.o oauth.o oauth2.o proxy.o sha1.o $(SSL_CLIENT) url.o xmltree.o ns_parse.o 16 16 17 17 LFLAGS += -r -
lib/misc.c
rb1b9453 r9c78519 1 /********************************************************************\1 /********************************************************************\ 2 2 * BitlBee -- An IRC to other IM-networks gateway * 3 3 * * … … 504 504 } 505 505 506 /* From OpenSSH 7.4p1 canohost.c" */507 char *reverse_lookup(const struct sockaddr *from_, const socklen_t fromlen_)508 {509 struct sockaddr_storage from;510 socklen_t fromlen;511 struct addrinfo hints, *ai, *aitop;512 char name[NI_MAXHOST], ntop2[NI_MAXHOST];513 char ntop[INET6_ADDRSTRLEN];514 515 fromlen = sizeof(from);516 memset(&from, 0, sizeof(from));517 memcpy(&from, from_, fromlen_);518 ipv64_normalise_mapped(&from, &fromlen);519 if (from.ss_family == AF_INET6) {520 fromlen = sizeof(struct sockaddr_in6);521 }522 523 if (getnameinfo((struct sockaddr *)&from, fromlen, ntop, sizeof(ntop),524 NULL, 0, NI_NUMERICHOST) != 0) {525 return NULL;526 }527 528 /* Map the IP address to a host name. */529 if (getnameinfo((struct sockaddr *)&from, fromlen, name, sizeof(name),530 NULL, 0, NI_NAMEREQD) != 0) {531 /* Host name not found. Use ip address. */532 return g_strdup(ntop);533 }534 535 /*536 * if reverse lookup result looks like a numeric hostname,537 * someone is trying to trick us by PTR record like following:538 * 1.1.1.10.in-addr.arpa. IN PTR 2.3.4.5539 */540 memset(&hints, 0, sizeof(hints));541 hints.ai_socktype = SOCK_DGRAM; /*dummy*/542 hints.ai_flags = AI_NUMERICHOST;543 if (getaddrinfo(name, NULL, &hints, &ai) == 0) {544 freeaddrinfo(ai);545 return g_strdup(ntop);546 }547 548 /* Names are stored in lowercase. */549 char *tolower = g_utf8_strdown(name, -1);550 g_snprintf(name, sizeof(name), "%s", tolower);551 g_free(tolower);552 553 /*554 * Map it back to an IP address and check that the given555 * address actually is an address of this host. This is556 * necessary because anyone with access to a name server can557 * define arbitrary names for an IP address. Mapping from558 * name to IP address can be trusted better (but can still be559 * fooled if the intruder has access to the name server of560 * the domain).561 */562 memset(&hints, 0, sizeof(hints));563 hints.ai_family = from.ss_family;564 hints.ai_socktype = SOCK_STREAM;565 if (getaddrinfo(name, NULL, &hints, &aitop) != 0) {566 return g_strdup(ntop);567 }568 /* Look for the address from the list of addresses. */569 for (ai = aitop; ai; ai = ai->ai_next) {570 if (getnameinfo(ai->ai_addr, ai->ai_addrlen, ntop2,571 sizeof(ntop2), NULL, 0, NI_NUMERICHOST) == 0 &&572 (strcmp(ntop, ntop2) == 0))573 break;574 }575 freeaddrinfo(aitop);576 /* If we reached the end of the list, the address was not there. */577 if (ai == NULL) {578 /* Address not found for the host name. */579 return g_strdup(ntop);580 }581 return g_strdup(name);582 }583 584 void585 ipv64_normalise_mapped(struct sockaddr_storage *addr, socklen_t *len)586 {587 struct sockaddr_in6 *a6 = (struct sockaddr_in6 *)addr;588 struct sockaddr_in *a4 = (struct sockaddr_in *)addr;589 struct in_addr inaddr;590 u_int16_t port;591 592 if (addr->ss_family != AF_INET6 ||593 !IN6_IS_ADDR_V4MAPPED(&a6->sin6_addr))594 return;595 596 memcpy(&inaddr, ((char *)&a6->sin6_addr) + 12, sizeof(inaddr));597 port = a6->sin6_port;598 599 memset(a4, 0, sizeof(*a4));600 601 a4->sin_family = AF_INET;602 *len = sizeof(*a4);603 memcpy(&a4->sin_addr, &inaddr, sizeof(inaddr));604 a4->sin_port = port;605 }606 607 506 char *word_wrap(const char *msg, int line_len) 608 507 { -
lib/misc.h
rb1b9453 r9c78519 141 141 G_MODULE_EXPORT void srv_free(struct ns_srv_reply **srv); 142 142 143 G_MODULE_EXPORT char *reverse_lookup(const struct sockaddr *from_, const socklen_t fromlen_);144 G_MODULE_EXPORT void ipv64_normalise_mapped(struct sockaddr_storage *addr, socklen_t *len);145 146 143 G_MODULE_EXPORT char *word_wrap(const char *msg, int line_len); 147 144 G_MODULE_EXPORT gboolean ssl_sockerr_again(void *ssl);
Note: See TracChangeset
for help on using the changeset viewer.