Changeset 7a9d968 for irc_commands.c


Ignore:
Timestamp:
2018-03-10T11:30:39Z (7 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Children:
5447c59
Parents:
3f44e43 (diff), 4a9c6b0 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into HEAD

File:
1 edited

Legend:

Unmodified
Added
Removed
  • irc_commands.c

    r3f44e43 r7a9d968  
    2626#define BITLBEE_CORE
    2727#include "bitlbee.h"
     28#include "canohost.h"
    2829#include "help.h"
    2930#include "ipc.h"
     
    5758                irc_check_login(irc);
    5859        }
     60}
     61
     62/* http://www.haproxy.org/download/1.8/doc/proxy-protocol.txt
     63
     64   This isn't actually IRC, it's used by for example stunnel4 to indicate
     65   the origin of the secured counterpart of the connection. It'll go wrong
     66   with arguments starting with : like for example "::1" but I guess I'm
     67   okay with that. */
     68static void irc_cmd_proxy(irc_t *irc, char **cmd)
     69{
     70        struct addrinfo hints, *ai;
     71        struct sockaddr_storage sock;
     72        socklen_t socklen = sizeof(sock);
     73
     74        if (getpeername(irc->fd, (struct sockaddr*) &sock, &socklen) != 0) {
     75                return;
     76        }
     77
     78        ipv64_normalise_mapped(&sock, &socklen);
     79
     80        /* Only accept PROXY "command" on localhost sockets. */
     81        if (!((sock.ss_family == AF_INET &&
     82               ntohl(((struct sockaddr_in*)&sock)->sin_addr.s_addr) == INADDR_LOOPBACK) ||
     83              (sock.ss_family == AF_INET6 &&
     84               IN6_IS_ADDR_LOOPBACK(&((struct sockaddr_in6*)&sock)->sin6_addr)))) {
     85                return;
     86        }
     87
     88        /* And only once. Do this with a pretty dumb regex-match for
     89           now, maybe better to use some sort of flag.. */
     90        if (!g_regex_match_simple("^(ip6-)?localhost(.(localdomain.?)?)?$", irc->user->host, 0, 0)) {
     91                return;
     92        }
     93       
     94        memset(&hints, 0, sizeof(hints));
     95        hints.ai_flags = AI_NUMERICHOST;
     96        if (getaddrinfo(cmd[2], NULL, &hints, &ai) != 0) {
     97                return;
     98        }
     99       
     100        irc_set_hosts(irc, ai->ai_addr, ai->ai_addrlen);
     101        freeaddrinfo(ai);
    59102}
    60103
     
    808851        { "cap",         1, irc_cmd_cap,         0 },
    809852        { "pass",        1, irc_cmd_pass,        0 },
     853        { "proxy",       5, irc_cmd_proxy,       IRC_CMD_PRE_LOGIN },
    810854        { "user",        4, irc_cmd_user,        IRC_CMD_PRE_LOGIN },
    811855        { "nick",        1, irc_cmd_nick,        0 },
Note: See TracChangeset for help on using the changeset viewer.