diff options
-rw-r--r-- | bitlbee.c | 95 | ||||
-rw-r--r-- | conf.c | 23 | ||||
-rw-r--r-- | conf.h | 4 | ||||
-rwxr-xr-x | configure | 7 | ||||
-rw-r--r-- | crypting.h | 6 | ||||
-rwxr-xr-x | debian/postinst | 9 | ||||
-rwxr-xr-x | debian/prerm | 9 | ||||
-rw-r--r-- | doc/user-guide/commands.xml | 2 | ||||
-rw-r--r-- | help.h | 2 | ||||
-rw-r--r-- | irc.c | 76 | ||||
-rw-r--r-- | lib/misc.c | 2 | ||||
-rw-r--r-- | lib/proxy.c | 4 | ||||
-rw-r--r-- | protocols/jabber/io.c | 9 | ||||
-rw-r--r-- | protocols/jabber/presence.c | 5 | ||||
-rw-r--r-- | protocols/jabber/xmltree.c | 2 | ||||
-rw-r--r-- | protocols/nogaim.c | 6 | ||||
-rw-r--r-- | protocols/oscar/oscar.c | 11 | ||||
-rw-r--r-- | storage.h | 2 |
18 files changed, 113 insertions, 161 deletions
@@ -37,72 +37,53 @@ static gboolean bitlbee_io_new_client( gpointer data, gint fd, b_input_condition int bitlbee_daemon_init() { -#ifdef IPV6 - int use_ipv6 = 1; - struct sockaddr_in6 listen_addr6; -#endif - struct sockaddr_in listen_addr; + struct addrinfo *res, hints, *addrinfo_bind; int i; FILE *fp; log_link( LOGLVL_ERROR, LOGOUTPUT_SYSLOG ); log_link( LOGLVL_WARNING, LOGOUTPUT_SYSLOG ); -#ifdef IPV6 - if( ( global.listen_socket = socket( AF_INET6, SOCK_STREAM, 0 ) ) == -1 ) - { - use_ipv6 = 0; -#endif - global.listen_socket = socket( AF_INET, SOCK_STREAM, 0 ); -#ifdef IPV6 - } -#endif - if( global.listen_socket == -1 ) - { - log_error( "socket" ); - return( -1 ); - } - - /* TIME_WAIT (?) sucks.. */ - i = 1; - setsockopt( global.listen_socket, SOL_SOCKET, SO_REUSEADDR, &i, sizeof( i ) ); - -#ifdef IPV6 - memset( &listen_addr6, 0, sizeof( listen_addr6 ) ); - memset( &listen_addr, 0, sizeof( listen_addr ) ); - listen_addr6.sin6_family = AF_INET6; - listen_addr6.sin6_port = htons( global.conf->port ); - if( ( i = inet_pton( AF_INET6, ipv6_wrap( global.conf->iface ), &listen_addr6.sin6_addr ) ) != 1 ) - { - /* Forget about IPv6 in this function. */ - use_ipv6 = 0; -#endif - listen_addr.sin_family = AF_INET; - listen_addr.sin_port = htons( global.conf->port ); - if( strcmp( global.conf->iface, "::" ) == 0 ) - i = inet_pton( AF_INET, "0.0.0.0", &listen_addr.sin_addr ); - else - i = inet_pton( AF_INET, global.conf->iface, &listen_addr.sin_addr ); -#ifdef IPV6 - } -#endif - - if( i != 1 ) + memset( &hints, 0, sizeof( hints ) ); + hints.ai_family = PF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = AI_ADDRCONFIG | AI_PASSIVE; + + i = getaddrinfo( global.conf->iface, global.conf->port, &hints, + &addrinfo_bind ); + if( i ) { - log_message( LOGLVL_ERROR, "Couldn't parse address `%s'", global.conf->iface ); - return( -1 ); + log_message( LOGLVL_ERROR, "Couldn't parse address `%s': %s", + global.conf->iface, gai_strerror(i) ); + return -1; } - -#ifdef IPV6 - if( !use_ipv6 || ( i = bind( global.listen_socket, (struct sockaddr *) &listen_addr6, sizeof( listen_addr6 ) ) ) == -1 ) -#endif - i = bind( global.listen_socket, (struct sockaddr *) &listen_addr, sizeof( listen_addr ) ); - if( i == -1 ) + + global.listen_socket = -1; + + for( res = addrinfo_bind; res; res = res->ai_next ) { - log_error( "bind" ); - return( -1 ); + global.listen_socket = socket( res->ai_family, res->ai_socktype, + res->ai_protocol ); + if( global.listen_socket < 0 ) + continue; + + /* TIME_WAIT (?) sucks.. */ + i = 1; + setsockopt( global.listen_socket, SOL_SOCKET, SO_REUSEADDR, &i, + sizeof( i ) ); + + i = bind( global.listen_socket, res->ai_addr, res->ai_addrlen ); + if( i == -1 ) + { + log_error( "bind" ); + return( -1 ); + } + + break; } - + + freeaddrinfo( addrinfo_bind ); + i = listen( global.listen_socket, 10 ); if( i == -1 ) { @@ -124,7 +105,7 @@ int bitlbee_daemon_init() else if( i != 0 ) exit( 0 ); -// chdir( "/" ); + chdir( "/" ); /* Sometimes std* are already closed (for example when we're in a RESTARTed BitlBee process. So let's only close TTY-fds. */ @@ -46,12 +46,8 @@ conf_t *conf_load( int argc, char *argv[] ) conf = g_new0( conf_t, 1 ); -#ifdef IPV6 - conf->iface = "::"; -#else - conf->iface = "0.0.0.0"; -#endif - conf->port = 6667; + conf->iface = NULL; + conf->port = "6667"; conf->nofork = 0; conf->verbose = 0; conf->primary_storage = "xml"; @@ -88,12 +84,8 @@ conf_t *conf_load( int argc, char *argv[] ) } else if( opt == 'p' ) { - if( ( sscanf( optarg, "%d", &i ) != 1 ) || ( i <= 0 ) || ( i > 65535 ) ) - { - fprintf( stderr, "Invalid port number: %s\n", optarg ); - return( NULL ); - } - conf->port = i; + g_free( conf->port ); + conf->port = g_strdup( optarg ); } else if( opt == 'P' ) { @@ -203,12 +195,7 @@ static int conf_loadini( conf_t *conf, char *file ) } else if( g_strcasecmp( ini->key, "daemonport" ) == 0 ) { - if( ( sscanf( ini->value, "%d", &i ) != 1 ) || ( i <= 0 ) || ( i > 65535 ) ) - { - fprintf( stderr, "Invalid port number: %s\n", ini->value ); - return( 0 ); - } - conf->port = i; + conf->port = g_strdup( ini->value ); } else if( g_strcasecmp( ini->key, "authmode" ) == 0 ) { @@ -32,7 +32,7 @@ typedef enum authmode { AUTHMODE_OPEN, AUTHMODE_CLOSED, AUTHMODE_REGISTERED } au typedef struct conf { char *iface; - signed int port; + char *port; int nofork; int verbose; runmode_t runmode; @@ -50,7 +50,7 @@ typedef struct conf int ping_timeout; } conf_t; -conf_t *conf_load( int argc, char *argv[] ); +G_GNUC_MALLOC conf_t *conf_load( int argc, char *argv[] ); void conf_loaddefaults( irc_t *irc ); #endif @@ -29,7 +29,6 @@ debug=0 strip=1 gcov=0 plugins=1 -ipv6=1 events=glib ldap=0 @@ -71,8 +70,6 @@ Option Description Default --gcov=0/1 Disable/enable test coverage reporting $gcov --plugins=0/1 Disable/enable plugins support $plugins ---ipv6=0/1 IPv6 socket support $ipv6 - --events=... Event handler (glib, libevent) $events --ssl=... SSL library to use (gnutls, nss, openssl, bogus, auto) $ssl @@ -134,10 +131,6 @@ cat<<EOF>config.h #define CPU "$cpu" EOF -if [ "$ipv6" = "1" ]; then - echo '#define IPV6' >> config.h -fi - if [ "$debug" = "1" ]; then [ -z "$CFLAGS" ] && CFLAGS=-g echo 'DEBUG=1' >> Makefile.settings @@ -24,6 +24,6 @@ */ int checkpass (const char *password, const char *md5sum); -char *hashpass (const char *password); -char *obfucrypt (char *line, const char *password); -char *deobfucrypt (char *line, const char *password); +G_GNUC_MALLOC char *hashpass (const char *password); +G_GNUC_MALLOC char *obfucrypt (char *line, const char *password); +G_GNUC_MALLOC char *deobfucrypt (char *line, const char *password); 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/doc/user-guide/commands.xml b/doc/user-guide/commands.xml index 8f97558f..1e890c1c 100644 --- a/doc/user-guide/commands.xml +++ b/doc/user-guide/commands.xml @@ -835,7 +835,7 @@ <bitlbee-command name="join_chat"> <short-description>Join a named groupchat/conference room</short-description> - <syntax>import_buddies <connection> <room name> [<channel name>] [<room nickname>] [<password>]</syntax> + <syntax>join_chat <connection> <room name> [<channel name>] [<room nickname>] [<password>]</syntax> <description> <para> @@ -42,7 +42,7 @@ typedef struct help struct help *next; } help_t; -help_t *help_init( help_t **help, const char *helpfile ); +G_GNUC_MALLOC help_t *help_init( help_t **help, const char *helpfile ); char *help_get( help_t **help, char *string ); #endif @@ -44,14 +44,8 @@ static char *passchange( set_t *set, char *value ) irc_t *irc_new( int fd ) { irc_t *irc; - struct hostent *peer; - unsigned int i; - char buf[128]; -#ifdef IPV6 - struct sockaddr_in6 sock6[1]; - unsigned int i6; -#endif - struct sockaddr_in sock[1]; + struct sockaddr_storage sock; + socklen_t socklen = sizeof( sock ); irc = g_new0( irc_t, 1 ); @@ -70,54 +64,42 @@ irc_t *irc_new( int fd ) irc->mynick = g_strdup( ROOT_NICK ); irc->channel = g_strdup( ROOT_CHAN ); - i = sizeof( *sock ); -#ifdef IPV6 - i6 = sizeof( *sock6 ); -#endif - if( global.conf->hostname ) - irc->myhost = g_strdup( global.conf->hostname ); -#ifdef IPV6 - else if( getsockname( irc->fd, (struct sockaddr*) sock6, &i6 ) == 0 && sock6->sin6_family == AF_INET6 ) { - if( ( peer = gethostbyaddr( (char*) &sock6->sin6_addr, sizeof( sock6->sin6_addr ), AF_INET6 ) ) ) - irc->myhost = g_strdup( peer->h_name ); - else if( inet_ntop( AF_INET6, &sock6->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL ) - irc->myhost = g_strdup( ipv6_unwrap( buf ) ); + irc->myhost = g_strdup( global.conf->hostname ); } -#endif - else if( getsockname( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INET ) + else if( getsockname( irc->fd, (struct sockaddr*) &sock, &socklen ) == 0 ) { - if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INET ) ) ) - irc->myhost = g_strdup( peer->h_name ); - else if( inet_ntop( AF_INET, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL ) - irc->myhost = g_strdup( buf ); + char buf[NI_MAXHOST+1]; + + 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.localdomain", NI_MAXHOST ); + } } - i = sizeof( *sock ); -#ifdef IPV6 - i6 = sizeof( *sock6 ); - if( getpeername( irc->fd, (struct sockaddr*) sock6, &i6 ) == 0 && sock6->sin6_family == AF_INET6 ) + if( getpeername( irc->fd, (struct sockaddr*) &sock, &socklen ) == 0 ) { - if( ( peer = gethostbyaddr( (char*) &sock6->sin6_addr, sizeof( sock6->sin6_addr ), AF_INET6 ) ) ) - irc->host = g_strdup( peer->h_name ); - else if( inet_ntop( AF_INET6, &sock6->sin6_addr, buf, sizeof( buf ) - 1 ) != NULL ) + char buf[NI_MAXHOST+1]; + + if( getnameinfo( (struct sockaddr *)&sock, socklen, buf, + NI_MAXHOST, NULL, -1, 0 ) == 0 ) + { irc->host = g_strdup( ipv6_unwrap( buf ) ); - } - else -#endif - if( getpeername( irc->fd, (struct sockaddr*) sock, &i ) == 0 && sock->sin_family == AF_INET ) - { - if( ( peer = gethostbyaddr( (char*) &sock->sin_addr, sizeof( sock->sin_addr ), AF_INET ) ) ) - irc->host = g_strdup( peer->h_name ); - else if( inet_ntop( AF_INET, &sock->sin_addr, buf, sizeof( buf ) - 1 ) != NULL ) - irc->host = g_strdup( buf ); + } + else + { + /* Rare, but possible. */ + strncpy( irc->host, "localhost.localdomain", NI_MAXHOST ); + } } - /* Rare, but possible. */ - if( !irc->host ) irc->host = g_strdup( "localhost." ); - if( !irc->myhost ) irc->myhost = g_strdup( "localhost." ); - if( global.conf->ping_interval > 0 && global.conf->ping_timeout > 0 ) irc->ping_source_id = b_timeout_add( global.conf->ping_interval * 1000, irc_userping, irc ); @@ -743,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 ); @@ -321,7 +321,6 @@ char *strip_newlines( char *source ) return source; } -#ifdef IPV6 /* Wrap an IPv4 address into IPv6 space. Not thread-safe... */ char *ipv6_wrap( char *src ) { @@ -359,7 +358,6 @@ char *ipv6_unwrap( char *src ) return ( src + 7 ); } -#endif /* Convert from one charset to another. diff --git a/lib/proxy.c b/lib/proxy.c index 7911b06f..dff5d0a4 100644 --- a/lib/proxy.c +++ b/lib/proxy.c @@ -210,7 +210,7 @@ static gboolean http_canwrite(gpointer data, gint source, b_input_condition cond return FALSE; } - if (proxyuser && *proxyuser) { + if (strlen(proxyuser) > 0) { char *t1, *t2; t1 = g_strdup_printf("%s:%s", proxyuser, proxypass); t2 = tobase64(t1); @@ -538,7 +538,7 @@ int proxy_connect(const char *host, int port, b_event_handler func, gpointer dat phb->func = func; phb->data = data; - if ((proxytype == PROXY_NONE) || !proxyhost || !proxyhost[0] || !proxyport || (proxyport == -1)) + if ((proxytype == PROXY_NONE) || strlen(proxyhost) > 0 || !proxyport || (proxyport == -1)) return proxy_connect_none(host, port, phb); else if (proxytype == PROXY_HTTP) return proxy_connect_http(host, port, phb); diff --git a/protocols/jabber/io.c b/protocols/jabber/io.c index cf71ff87..61cd142e 100644 --- a/protocols/jabber/io.c +++ b/protocols/jabber/io.c @@ -469,14 +469,6 @@ static xt_status jabber_pkt_stream_error( struct xt_node *node, gpointer data ) return XT_ABORT; } -static xt_status jabber_pkt_misc( struct xt_node *node, gpointer data ) -{ - printf( "Received unknown packet:\n" ); - xt_print( node ); - - return XT_HANDLED; -} - static xt_status jabber_xmlconsole( struct xt_node *node, gpointer data ) { struct im_connection *ic = data; @@ -508,7 +500,6 @@ static const struct xt_handler_entry jabber_handlers[] = { { "challenge", "stream:stream", sasl_pkt_challenge }, { "success", "stream:stream", sasl_pkt_result }, { "failure", "stream:stream", sasl_pkt_result }, - { NULL, "stream:stream", jabber_pkt_misc }, { NULL, NULL, NULL } }; diff --git a/protocols/jabber/presence.c b/protocols/jabber/presence.c index cbfcedae..71a044b5 100644 --- a/protocols/jabber/presence.c +++ b/protocols/jabber/presence.c @@ -169,11 +169,6 @@ xt_status jabber_pkt_presence( struct xt_node *node, gpointer data ) } /* What else to do with it? */ } - else - { - printf( "Received PRES from %s:\n", from ); - xt_print( node ); - } return XT_HANDLED; } diff --git a/protocols/jabber/xmltree.c b/protocols/jabber/xmltree.c index b1edd55d..62549eb5 100644 --- a/protocols/jabber/xmltree.c +++ b/protocols/jabber/xmltree.c @@ -304,6 +304,7 @@ char *xt_to_string( struct xt_node *node ) return real; } +#ifdef DEBUG void xt_print( struct xt_node *node ) { int i; @@ -354,6 +355,7 @@ void xt_print( struct xt_node *node ) /* Non-empty tag is now finished. */ printf( "</%s>\n", node->name ); } +#endif struct xt_node *xt_dup( struct xt_node *node ) { diff --git a/protocols/nogaim.c b/protocols/nogaim.c index 3307b0f5..d1aceb1a 100644 --- a/protocols/nogaim.c +++ b/protocols/nogaim.c @@ -35,7 +35,7 @@ #include "nogaim.h" #include <ctype.h> -static int remove_chat_buddy_silent( struct groupchat *b, char *handle ); +static int remove_chat_buddy_silent( struct groupchat *b, const char *handle ); GSList *connections; @@ -577,7 +577,7 @@ void imcb_buddy_status( struct im_connection *ic, const char *handle, int flags, /* Remove him/her from the groupchats to prevent PART messages after he/she QUIT already */ for( c = ic->groupchats; c; c = c->next ) - remove_chat_buddy_silent( c, (char*) handle ); + remove_chat_buddy_silent( c, handle ); } if( flags & OPT_AWAY ) @@ -848,7 +848,7 @@ void imcb_chat_remove_buddy( struct groupchat *b, char *handle, char *reason ) irc_part( b->ic->irc, u, b->channel ); } -static int remove_chat_buddy_silent( struct groupchat *b, char *handle ) +static int remove_chat_buddy_silent( struct groupchat *b, const char *handle ) { GList *i; diff --git a/protocols/oscar/oscar.c b/protocols/oscar/oscar.c index 4d18e832..96983738 100644 --- a/protocols/oscar/oscar.c +++ b/protocols/oscar/oscar.c @@ -1065,8 +1065,17 @@ static int incomingim_chan1(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_ } else { g_snprintf(tmp, BUF_LONG, "%s", args->msg); } - } else + } else if (args->mpmsg.numparts == 0) { g_snprintf(tmp, BUF_LONG, "%s", args->msg); + } else { + int i; + + *tmp = 0; + for (i = 0; i < args->mpmsg.numparts; i ++) { + g_strlcat(tmp, (char*) args->mpmsg.parts[i].data, BUF_LONG); + g_strlcat(tmp, "\n", BUF_LONG); + } + } strip_linefeed(tmp); imcb_buddy_msg(ic, userinfo->sn, tmp, flags, 0); @@ -61,6 +61,6 @@ storage_status_t storage_remove (const char *nick, const char *password); storage_status_t storage_rename (const char *onick, const char *nnick, const char *password); void register_storage_backend(storage_t *); -GList *storage_init(const char *primary, char **migrate); +G_GNUC_MALLOC GList *storage_init(const char *primary, char **migrate); #endif /* __STORAGE_H__ */ |