aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bitlbee.c8
-rwxr-xr-xdebian/postinst9
-rwxr-xr-xdebian/prerm9
-rw-r--r--irc.c30
-rw-r--r--lib/misc.c38
-rw-r--r--lib/misc.h3
6 files changed, 83 insertions, 14 deletions
diff --git a/bitlbee.c b/bitlbee.c
index 625ea214..7a9a89d9 100644
--- a/bitlbee.c
+++ b/bitlbee.c
@@ -51,7 +51,8 @@ int bitlbee_daemon_init()
i = getaddrinfo( global.conf->iface, global.conf->port, &hints,
&addrinfo_bind );
- if ( i ) {
+ if( i )
+ {
log_message( LOGLVL_ERROR, "Couldn't parse address `%s': %s",
global.conf->iface, gai_strerror(i) );
return -1;
@@ -59,10 +60,11 @@ int bitlbee_daemon_init()
global.listen_socket = -1;
- for ( res = addrinfo_bind; res; res = res->ai_next ) {
+ for( res = addrinfo_bind; res; res = res->ai_next )
+ {
global.listen_socket = socket( res->ai_family, res->ai_socktype,
res->ai_protocol );
- if ( global.listen_socket < 0 )
+ if( global.listen_socket < 0 )
continue;
/* TIME_WAIT (?) sucks.. */
diff --git a/debian/postinst b/debian/postinst
index 6c99c40d..37608e47 100755
--- a/debian/postinst
+++ b/debian/postinst
@@ -45,6 +45,15 @@ EOF
## Bye-bye DebConf, we don't need you anymore.
db_stop
+## Restore the helpfile in case we weren't upgrading but just reconfiguring:
+if [ -e /usr/share/bitlbee/help.upgrading ]; then
+ if [ -e /usr/share/bitlbee/help.txt ]; then
+ rm -f /usr/share/bitlbee/help.upgrading
+ else
+ mv /usr/share/bitlbee/help.upgrading /usr/share/bitlbee/help.txt
+ fi
+fi
+
if [ -n "$2" -a "$BITLBEE_UPGRADE_DONT_RESTART" != "1" ]; then
/etc/init.d/bitlbee restart
fi
diff --git a/debian/prerm b/debian/prerm
index c02b13f4..5272e273 100755
--- a/debian/prerm
+++ b/debian/prerm
@@ -1,8 +1,13 @@
#!/bin/sh -e
if [ "$1" = "upgrade" ]; then
- ## To prevent the help function from breaking in currently running BitlBee processes
- rm -f /usr/share/bitlbee/help.txt
+ ## To prevent the help function from breaking in currently running
+ ## BitlBee processes. Have to do it like this because dpkg-reconfigure
+ ## looks a lot like an upgrade and we don't want to lose help.txt...
+ if [ -e /usr/share/bitlbee/help.txt ]; then
+ rm -f /usr/share/bitlbee/help.upgrading
+ mv /usr/share/bitlbee/help.txt /usr/share/bitlbee/help.upgrading
+ fi
else
/etc/init.d/bitlbee stop || exit 0
fi
diff --git a/irc.c b/irc.c
index 1a1f511e..0bebf9b0 100644
--- a/irc.c
+++ b/irc.c
@@ -65,26 +65,38 @@ irc_t *irc_new( int fd )
irc->channel = g_strdup( ROOT_CHAN );
if( global.conf->hostname )
+ {
irc->myhost = g_strdup( global.conf->hostname );
+ }
else if( getsockname( irc->fd, (struct sockaddr*) &sock, &socklen ) == 0 )
{
- irc->myhost = g_new0( char, NI_MAXHOST );
+ char buf[NI_MAXHOST+1];
- if (getnameinfo( (struct sockaddr *) &sock, socklen, irc->myhost,
- NI_MAXHOST, NULL, -1, 0) ) {
+ if( getnameinfo( (struct sockaddr *) &sock, socklen, buf,
+ NI_MAXHOST, NULL, -1, 0 ) == 0 )
+ {
+ irc->myhost = g_strdup( ipv6_unwrap( buf ) );
+ }
+ else
+ {
/* Rare, but possible. */
- strncpy( irc->myhost, "localhost.", NI_MAXHOST );
+ strncpy( irc->myhost, "localhost.localdomain", NI_MAXHOST );
}
}
if( getpeername( irc->fd, (struct sockaddr*) &sock, &socklen ) == 0 )
{
- irc->host = g_new0( char, NI_MAXHOST );
+ char buf[NI_MAXHOST+1];
- if ( getnameinfo( (struct sockaddr *)&sock, socklen, irc->host,
- NI_MAXHOST, NULL, -1, 0 ) ) {
+ if( getnameinfo( (struct sockaddr *)&sock, socklen, buf,
+ NI_MAXHOST, NULL, -1, 0 ) == 0 )
+ {
+ irc->host = g_strdup( ipv6_unwrap( buf ) );
+ }
+ else
+ {
/* Rare, but possible. */
- strncpy( irc->myhost, "localhost.", NI_MAXHOST );
+ strncpy( irc->host, "localhost.localdomain", NI_MAXHOST );
}
}
@@ -713,7 +725,7 @@ void irc_login( irc_t *irc )
u->online = 1;
irc_spawn( irc, u );
- irc_usermsg( irc, "Welcome to the BitlBee gateway!\n\nIf you've never used BitlBee before, please do read the help information using the \x02help\x02 command. Lots of FAQ's are answered there." );
+ irc_usermsg( irc, "Welcome to the BitlBee gateway!\n\nIf you've never used BitlBee before, please do read the help information using the \x02help\x02 command. Lots of FAQs are answered there." );
if( global.conf->runmode == RUNMODE_FORKDAEMON || global.conf->runmode == RUNMODE_DAEMON )
ipc_to_master_str( "CLIENT %s %s :%s\r\n", irc->host, irc->nick, irc->realname );
diff --git a/lib/misc.c b/lib/misc.c
index ceba9d95..c977029f 100644
--- a/lib/misc.c
+++ b/lib/misc.c
@@ -321,6 +321,44 @@ char *strip_newlines( char *source )
return source;
}
+/* Wrap an IPv4 address into IPv6 space. Not thread-safe... */
+char *ipv6_wrap( char *src )
+{
+ static char dst[64];
+ int i;
+
+ for( i = 0; src[i]; i ++ )
+ if( ( src[i] < '0' || src[i] > '9' ) && src[i] != '.' )
+ break;
+
+ /* Hmm, it's not even an IP... */
+ if( src[i] )
+ return src;
+
+ g_snprintf( dst, sizeof( dst ), "::ffff:%s", src );
+
+ return dst;
+}
+
+/* Unwrap an IPv4 address into IPv6 space. Thread-safe, because it's very simple. :-) */
+char *ipv6_unwrap( char *src )
+{
+ int i;
+
+ if( g_strncasecmp( src, "::ffff:", 7 ) != 0 )
+ return src;
+
+ for( i = 7; src[i]; i ++ )
+ if( ( src[i] < '0' || src[i] > '9' ) && src[i] != '.' )
+ break;
+
+ /* Hmm, it's not even an IP... */
+ if( src[i] )
+ return src;
+
+ return ( src + 7 );
+}
+
/* Convert from one charset to another.
from_cs, to_cs: Source and destination charsets
diff --git a/lib/misc.h b/lib/misc.h
index e32b5f12..1d76f7f2 100644
--- a/lib/misc.h
+++ b/lib/misc.h
@@ -51,6 +51,9 @@ G_MODULE_EXPORT char *escape_html( const char *html );
G_MODULE_EXPORT void http_decode( char *s );
G_MODULE_EXPORT void http_encode( char *s );
+G_MODULE_EXPORT char *ipv6_wrap( char *src );
+G_MODULE_EXPORT char *ipv6_unwrap( char *src );
+
G_MODULE_EXPORT signed int do_iconv( char *from_cs, char *to_cs, char *src, char *dst, size_t size, size_t maxbuf );
G_MODULE_EXPORT void random_bytes( unsigned char *buf, int count );