Changes in / [c9e9c9c:0515063]
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
debian/copyright
rc9e9c9c r0515063 17 17 * lib/json.[ch] is from <https://github.com/udp/json-parser> and licensed 18 18 under the modified BSD license. 19 * lib/canohost.[ch] is from OpenSSH and licenced under the BSD-3-clause 20 licence. 19 21 20 22 -
irc.c
rc9e9c9c r0515063 25 25 26 26 #include "bitlbee.h" 27 #include "canohost.h" 27 28 #include "ipc.h" 28 29 #include "dcc.h" … … 41 42 { 42 43 irc_t *irc; 43 struct sockaddr_storage sock;44 socklen_t socklen = sizeof(sock);45 char *host = NULL, *myhost = NULL;46 44 irc_user_t *iu; 47 45 GSList *l; … … 64 62 irc->iconv = (GIConv) - 1; 65 63 irc->oconv = (GIConv) - 1; 66 67 if (global.conf->hostname) {68 myhost = g_strdup(global.conf->hostname);69 } else if (getsockname(irc->fd, (struct sockaddr*) &sock, &socklen) == 0) {70 char buf[NI_MAXHOST + 1];71 72 if (getnameinfo((struct sockaddr *) &sock, socklen, buf,73 NI_MAXHOST, NULL, 0, 0) == 0) {74 myhost = g_strdup(ipv6_unwrap(buf));75 }76 }77 78 if (getpeername(irc->fd, (struct sockaddr*) &sock, &socklen) == 0) {79 char buf[NI_MAXHOST + 1];80 81 if (getnameinfo((struct sockaddr *) &sock, socklen, buf,82 NI_MAXHOST, NULL, 0, 0) == 0) {83 host = g_strdup(ipv6_unwrap(buf));84 }85 }86 87 if (host == NULL) {88 host = g_strdup("localhost.localdomain");89 }90 if (myhost == NULL) {91 myhost = g_strdup("localhost.localdomain");92 }93 64 94 65 if (global.conf->ping_interval > 0 && global.conf->ping_timeout > 0) { … … 138 109 139 110 irc->root = iu = irc_user_new(irc, ROOT_NICK); 140 iu->host = g_strdup(myhost);141 111 iu->fullname = g_strdup(ROOT_FN); 142 112 iu->f = &irc_user_root_funcs; 143 113 144 114 iu = irc_user_new(irc, NS_NICK); 145 iu->host = g_strdup(myhost);146 115 iu->fullname = g_strdup(ROOT_FN); 147 116 iu->f = &irc_user_root_funcs; 148 117 149 118 irc->user = g_new0(irc_user_t, 1); 150 irc->user->host = g_strdup(host); 119 120 irc_set_hosts(irc, NULL, 0); 151 121 152 122 conf_loaddefaults(irc); … … 164 134 } 165 135 166 g_free(myhost);167 g_free(host);168 169 136 /* libpurple doesn't like fork()s after initializing itself, so this 170 137 is the right moment to initialize it. */ … … 186 153 187 154 return irc; 155 } 156 157 void irc_set_hosts(irc_t *irc, const struct sockaddr *remote_addr, const socklen_t remote_addrlen) 158 { 159 struct sockaddr_storage sock; 160 socklen_t socklen = sizeof(sock); 161 char *host = NULL, *myhost = NULL; 162 struct irc_user *iu; 163 164 if (global.conf->hostname) { 165 myhost = g_strdup(global.conf->hostname); 166 } else if (getsockname(irc->fd, (struct sockaddr*) &sock, &socklen) == 0) { 167 myhost = reverse_lookup((struct sockaddr*) &sock, socklen); 168 } 169 170 if (remote_addrlen > 0) { 171 host = reverse_lookup(remote_addr, remote_addrlen); 172 } else if (getpeername(irc->fd, (struct sockaddr*) &sock, &socklen) == 0) { 173 host = reverse_lookup((struct sockaddr*) &sock, socklen); 174 } 175 176 if (myhost == NULL) { 177 myhost = g_strdup("localhost.localdomain"); 178 } 179 if (host == NULL) { 180 host = g_strdup("localhost.localdomain"); 181 } 182 183 if (irc->root->host != irc->root->nick) { 184 g_free(irc->root->host); 185 } 186 irc->root->host = g_strdup(myhost); 187 if ((iu = irc_user_by_name(irc, NS_NICK))) { 188 if (iu->host != iu->nick) { 189 g_free(iu->host); 190 } 191 iu->host = g_strdup(myhost); 192 } 193 194 if (irc->user->host != irc->user->nick) { 195 g_free(irc->user->host); 196 } 197 irc->user->host = g_strdup(host); 198 199 g_free(myhost); 200 g_free(host); 188 201 } 189 202 -
irc.h
rc9e9c9c r0515063 26 26 #ifndef _IRC_H 27 27 #define _IRC_H 28 29 #include <sys/socket.h> 28 30 29 31 #define IRC_MAX_LINE 512 … … 271 273 272 274 irc_t *irc_new(int fd); 275 void irc_set_hosts(irc_t *irc, const struct sockaddr *remote_addr, const socklen_t remote_addrlen); 273 276 void irc_abort(irc_t *irc, int immed, char *format, ...) G_GNUC_PRINTF(3, 4); 274 277 void irc_free(irc_t *irc); -
irc_commands.c
rc9e9c9c r0515063 26 26 #define BITLBEE_CORE 27 27 #include "bitlbee.h" 28 #include "canohost.h" 28 29 #include "help.h" 29 30 #include "ipc.h" … … 57 58 irc_check_login(irc); 58 59 } 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. */ 68 static 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); 59 102 } 60 103 … … 808 851 { "cap", 1, irc_cmd_cap, 0 }, 809 852 { "pass", 1, irc_cmd_pass, 0 }, 853 { "proxy", 5, irc_cmd_proxy, IRC_CMD_PRE_LOGIN }, 810 854 { "user", 4, irc_cmd_user, IRC_CMD_PRE_LOGIN }, 811 855 { "nick", 1, irc_cmd_nick, 0 }, -
lib/Makefile
rc9e9c9c r0515063 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
rc9e9c9c r0515063 1 /********************************************************************\1 /********************************************************************\ 2 2 * BitlBee -- An IRC to other IM-networks gateway * 3 3 * * … … 335 335 } 336 336 337 /* Wrap an IPv4 address into IPv6 space. Not thread-safe... */338 char *ipv6_wrap(char *src)339 {340 static char dst[64];341 int i;342 343 for (i = 0; src[i]; i++) {344 if ((src[i] < '0' || src[i] > '9') && src[i] != '.') {345 break;346 }347 }348 349 /* Hmm, it's not even an IP... */350 if (src[i]) {351 return src;352 }353 354 g_snprintf(dst, sizeof(dst), "::ffff:%s", src);355 356 return dst;357 }358 359 /* Unwrap an IPv4 address into IPv6 space. Thread-safe, because it's very simple. :-) */360 char *ipv6_unwrap(char *src)361 {362 int i;363 364 if (g_strncasecmp(src, "::ffff:", 7) != 0) {365 return src;366 }367 368 for (i = 7; src[i]; i++) {369 if ((src[i] < '0' || src[i] > '9') && src[i] != '.') {370 break;371 }372 }373 374 /* Hmm, it's not even an IP... */375 if (src[i]) {376 return src;377 }378 379 return (src + 7);380 }381 382 337 /* Convert from one charset to another. 383 338 -
lib/misc.h
rc9e9c9c r0515063 29 29 #include <gmodule.h> 30 30 #include <time.h> 31 #include <sys/socket.h> 31 32 32 33 struct ns_srv_reply { … … 130 131 G_MODULE_EXPORT void http_encode(char *s); 131 132 132 G_MODULE_EXPORT char *ipv6_wrap(char *src);133 G_MODULE_EXPORT char *ipv6_unwrap(char *src);134 135 133 G_MODULE_EXPORT signed int do_iconv(char *from_cs, char *to_cs, char *src, char *dst, size_t size, size_t maxbuf); 136 134
Note: See TracChangeset
for help on using the changeset viewer.