From e3fb6789b0004c7162efde679632bf094b7b0eec Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 18 Dec 2005 17:10:24 +0100 Subject: Initial work on a SSPI SSL backend --- protocols/ssl_sspi.c | 210 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 210 insertions(+) create mode 100644 protocols/ssl_sspi.c (limited to 'protocols') diff --git a/protocols/ssl_sspi.c b/protocols/ssl_sspi.c new file mode 100644 index 00000000..2129f07b --- /dev/null +++ b/protocols/ssl_sspi.c @@ -0,0 +1,210 @@ + /********************************************************************\ + * BitlBee -- An IRC to other IM-networks gateway * + * * + * Copyright 2002-2004 Wilmer van der Gaast and others * + \********************************************************************/ + +/* SSL module - SSPI backend */ + +/* Copyright (C) 2005 Jelmer Vernooij */ + +/* + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License with + the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; + if not, write to the Free Software Foundation, Inc., 59 Temple Place, + Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "ssl_client.h" +#include +#define SECURITY_WIN32 +#include +#include +#include + +static gboolean initialized = FALSE; +int ssl_errno; + +struct scd +{ + int fd; + SslInputFunction func; + gpointer data; + gboolean established; + int inpa; + CredHandle cred; /* SSL credentials */ + CtxtHandle context; /* SSL context */ + SecPkgContext_StreamSizes sizes; +}; + +static void ssl_connected( gpointer data, gint source, GaimInputCondition cond ); + +void sspi_global_init( void ) +{ + /* FIXME */ +} + +void sspi_global_deinit( void ) +{ + /* FIXME */ +} + +void *ssl_connect( char *host, int port, SslInputFunction func, gpointer data ) +{ + struct scd *conn = g_new0( struct scd, 1 ); + SCHANNEL_CRED ssl_cred; + TimeStamp timestamp; + + conn->fd = proxy_connect( host, port, ssl_connected, conn ); + conn->func = func; + conn->data = data; + conn->inpa = -1; + + if( conn->fd < 0 ) + { + g_free( conn ); + return( NULL ); + } + + if( !initialized ) + { + sspi_global_init(); + initialized = TRUE; + atexit( sspi_global_deinit ); + } + + conn->context = NULL; + + memset(&ssl_cred, 0, sizeof(SCHANNEL_CRED)); + ssl_cred.dwVersion = SCHANNEL_CRED_VERSION; + ssl_cred.grbitEnabledProtocols = SP_PROT_SSL3_CLIENT; + + SECURITY_STATUS st = AcquireCredentialsHandle(NULL, UNISP_NAME, SECPKG_CRED_OUTBOUND, NULL, &ssl_cred, NULL, NULL, &conn->cred, ×tamp); + + InitializeSecurityContext(&conn->cred, &conn->context, host, FIXME, 1, FIXME); + + QueryContextAttributes(&conn->context, SECPKG_ATTR_STREAM_SIZES, &conn->sizes); + + + return( conn ); +} + +int ssl_read( void *conn, char *retdata, int len ) +{ + struct scd *scd = conn; + SecBufferDesc msg; + SecBuffer buf[4]; + int ret = -1, i; + char *data = g_malloc(scd->sizes.cbHeader + scd->sizes.cbMaximumMessage + scd->sizes.cbTrailer); + + /* FIXME: Try to read some data */ + + msg.ulVersion = SECBUFFER_VERSION; + msg.cBuffers = 4; + msg.pBuffers = buf; + + buf[0].BufferType = SECBUFFER_DATA; + buf[0].cbBuffer = len; + buf[0].pvBuffer = data; + + buf[1].BufferType = SECBUFFER_EMPTY; + buf[2].BufferType = SECBUFFER_EMPTY; + buf[3].BufferType = SECBUFFER_EMPTY; + + SECURITY_STATUS st = DecryptMessage(&scd->context, &msg, 0, NULL); + + for (i = 0; i < 4; i++) { + if (buf[i].BufferType == SECBUFFER_DATA) { + memcpy(retdata, buf[i].pvBuffer, len); + ret = len; + } + } + + g_free(data); + return( -1 ); +} + +int ssl_write( void *conn, const char *userdata, int len ) +{ + struct scd *scd = conn; + SecBuffer buf[4]; + SecBufferDesc msg; + char *data; + int ret; + + msg.ulVersion = SECBUFFER_VERSION; + msg.cBuffers = 4; + msg.pBuffers = buf; + + data = g_malloc(scd->sizes.cbHeader + scd->sizes.cbMaximumMessage + scd->sizes.cbTrailer); + memcpy(data + scd->sizes.cbHeader, userdata, len); + + buf[0].BufferType = SECBUFFER_STREAM_HEADER; + buf[0].cbBuffer = scd->sizes.cbHeader; + buf[0].pvBuffer = data; + + buf[1].BufferType = SECBUFFER_DATA; + buf[1].cbBuffer = len; + buf[1].pvBuffer = data + scd->sizes.cbHeader; + + buf[2].BufferType = SECBUFFER_STREAM_TRAILER; + buf[2].cbBuffer = scd->sizes.cbTrailer; + buf[2].pvBuffer = data + scd->sizes.cbHeader + len; + buf[3].BufferType = SECBUFFER_EMPTY; + + SECURITY_STATUS st = EncryptMessage(&scd->context, 0, &msg, 0); + + ret = send(scd->fd, data, + buf[0].cbBuffer + buf[1].cbBuffer + buf[2].cbBuffer, 0); + + g_free(data); + + return ret; +} + +void ssl_disconnect( void *conn ) +{ + struct scd *scd = conn; + + SecBufferDesc msg; + SecBuffer buf; + DWORD dw; + + dw = SCHANNEL_SHUTDOWN; + buf.cbBuffer = sizeof(dw); + buf.BufferType = SECBUFFER_TOKEN; + buf.pvBuffer = &dw; + + msg.ulVersion = SECBUFFER_VERSION; + msg.cBuffers = 1; + msg.pBuffers = &buf; + + SECURITY_STATUS st = ApplyControlToken(&scd->context, &msg); + + if (st != SEC_E_OK) { + /* FIXME */ + } + + /* FIXME: call InitializeSecurityContext(Schannel), passing + * in empty buffers*/ + + DeleteSecurityContext(&scd->context); + + closesocket( scd->fd ); + g_free(scd); +} + +int ssl_getfd( void *conn ) +{ + return( ((struct scd*)conn)->fd ); +} -- cgit v1.2.3 From 80c1e4d9e8c82a83499d6b66cdf3a95d15bf0fa1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 25 May 2006 01:31:20 +0200 Subject: #ifdef out some Win32-incompatible code blocks --- protocols/ssl_sspi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'protocols') diff --git a/protocols/ssl_sspi.c b/protocols/ssl_sspi.c index 2129f07b..0529b4ec 100644 --- a/protocols/ssl_sspi.c +++ b/protocols/ssl_sspi.c @@ -38,7 +38,7 @@ int ssl_errno; struct scd { int fd; - SslInputFunction func; + ssl_input_function func; gpointer data; gboolean established; int inpa; @@ -59,7 +59,7 @@ void sspi_global_deinit( void ) /* FIXME */ } -void *ssl_connect( char *host, int port, SslInputFunction func, gpointer data ) +void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data ) { struct scd *conn = g_new0( struct scd, 1 ); SCHANNEL_CRED ssl_cred; -- cgit v1.2.3 From 51a4ffb83d6fbe23f1c2b8499cc78584e7213812 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 25 May 2006 11:55:00 +0200 Subject: Some more work on SSL on Windows --- protocols/ssl_sspi.c | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'protocols') diff --git a/protocols/ssl_sspi.c b/protocols/ssl_sspi.c index 0529b4ec..c6d7def9 100644 --- a/protocols/ssl_sspi.c +++ b/protocols/ssl_sspi.c @@ -64,6 +64,13 @@ void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data struct scd *conn = g_new0( struct scd, 1 ); SCHANNEL_CRED ssl_cred; TimeStamp timestamp; + SecBuffer ibuf[2],obuf[1]; + SecBufferDesc ibufs,obufs; + ULONG req = ISC_REQ_REPLAY_DETECT | ISC_REQ_SEQUENCE_DETECT | + ISC_REQ_CONFIDENTIALITY | ISC_REQ_USE_SESSION_KEY | + ISC_REQ_ALLOCATE_MEMORY | ISC_REQ_STREAM | ISC_REQ_EXTENDED_ERROR | + ISC_REQ_MANUAL_CRED_VALIDATION; + ULONG a; conn->fd = proxy_connect( host, port, ssl_connected, conn ); conn->func = func; @@ -83,17 +90,42 @@ void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data atexit( sspi_global_deinit ); } - conn->context = NULL; - memset(&ssl_cred, 0, sizeof(SCHANNEL_CRED)); ssl_cred.dwVersion = SCHANNEL_CRED_VERSION; ssl_cred.grbitEnabledProtocols = SP_PROT_SSL3_CLIENT; SECURITY_STATUS st = AcquireCredentialsHandle(NULL, UNISP_NAME, SECPKG_CRED_OUTBOUND, NULL, &ssl_cred, NULL, NULL, &conn->cred, ×tamp); + + if (st != SEC_E_OK) + return NULL; + + do { + /* initialize buffers */ + ibuf[0].cbBuffer = size; ibuf[0].pvBuffer = buf; + ibuf[1].cbBuffer = 0; ibuf[1].pvBuffer = NIL; + obuf[0].cbBuffer = 0; obuf[0].pvBuffer = NIL; + ibuf[0].BufferType = obuf[0].BufferType = SECBUFFER_TOKEN; + ibuf[1].BufferType = SECBUFFER_EMPTY; + + /* initialize buffer descriptors */ + ibufs.ulVersion = obufs.ulVersion = SECBUFFER_VERSION; + ibufs.cBuffers = 2; obufs.cBuffers = 1; + ibufs.pBuffers = ibuf; obufs.pBuffers = obuf; + + st = InitializeSecurityContext(&conn->cred, size?&conn->context:NULL, host, req, 0, SECURITY_NETWORK_DREP, size?&ibufs:NULL, 0, &conn->context, &obufs, &a, ×tamp); + if (obuf[0].pvBuffer && obuf[0].cbBuffer) { + send(conn->fd, obuf[0].pvBuffer, obuf[0].cbBuffer, 0); + } + + switch (st) { + case SEC_I_INCOMPLETE_CREDENTIALS: + break; + case SEC_I_CONTINUE_NEEDED: + + } - InitializeSecurityContext(&conn->cred, &conn->context, host, FIXME, 1, FIXME); - QueryContextAttributes(&conn->context, SECPKG_ATTR_STREAM_SIZES, &conn->sizes); + QueryContextAttributes(&conn->context, SECPKG_ATTR_STREAM_SIZES, &conn->sizes); return( conn ); @@ -200,6 +232,8 @@ void ssl_disconnect( void *conn ) DeleteSecurityContext(&scd->context); + FreeCredentialHandle(&scd->cred); + closesocket( scd->fd ); g_free(scd); } -- cgit v1.2.3 From 1cda4f348372a755d99b291e6f4f9973a949f441 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 26 May 2006 17:02:09 +0200 Subject: Fix some unresolved symbols. --- protocols/oscar/AUTHORS | 2 -- protocols/ssl_sspi.c | 81 ++++++++++++++++++++++++++++++++----------------- 2 files changed, 53 insertions(+), 30 deletions(-) (limited to 'protocols') diff --git a/protocols/oscar/AUTHORS b/protocols/oscar/AUTHORS index 5ca13988..51e8768d 100644 --- a/protocols/oscar/AUTHORS +++ b/protocols/oscar/AUTHORS @@ -27,5 +27,3 @@ N: Brock Wilcox H: awwaiid E: awwaiid@auk.cx D: Figured out original password roasting - - diff --git a/protocols/ssl_sspi.c b/protocols/ssl_sspi.c index 110f0af2..a16423b1 100644 --- a/protocols/ssl_sspi.c +++ b/protocols/ssl_sspi.c @@ -31,6 +31,7 @@ #include #include #include +#include "sock.h" static gboolean initialized = FALSE; int ssl_errno; @@ -41,52 +42,59 @@ struct scd ssl_input_function func; gpointer data; gboolean established; - int inpa; CredHandle cred; /* SSL credentials */ CtxtHandle context; /* SSL context */ SecPkgContext_StreamSizes sizes; + + char *host; + + char *pending_raw_data; + gsize pending_raw_data_len; + char *pending_data; + gsize pending_data_len; }; static void ssl_connected(gpointer, gint, GaimInputCondition); -void sspi_global_init( void ) +void sspi_global_init(void) { /* FIXME */ } -void sspi_global_deinit( void ) +void sspi_global_deinit(void) { /* FIXME */ } -void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data ) +void *ssl_connect(char *host, int port, ssl_input_function func, gpointer data) { - struct scd *conn = g_new0( struct scd, 1 ); + struct scd *conn = g_new0(struct scd, 1); - conn->fd = proxy_connect( host, port, ssl_connected, conn ); + conn->fd = proxy_connect(host, port, ssl_connected, conn); + sock_make_nonblocking(conn->fd); conn->func = func; conn->data = data; - conn->inpa = -1; + conn->host = g_strdup(host); - if( conn->fd < 0 ) + if (conn->fd < 0) { - g_free( conn ); - return( NULL ); + g_free(conn); + return NULL; } - if( !initialized ) + if (!initialized) { sspi_global_init(); initialized = TRUE; - atexit( sspi_global_deinit ); + atexit(sspi_global_deinit); } return conn; } -static void ssl_connected(gpointer data, gint fd, GaimInputCondition cond) +static void ssl_connected(gpointer _conn, gint fd, GaimInputCondition cond) { - struct scd *conn = data; + struct scd *conn = _conn; SCHANNEL_CRED ssl_cred; TimeStamp timestamp; SecBuffer ibuf[2],obuf[1]; @@ -96,6 +104,8 @@ static void ssl_connected(gpointer data, gint fd, GaimInputCondition cond) ISC_REQ_ALLOCATE_MEMORY | ISC_REQ_STREAM | ISC_REQ_EXTENDED_ERROR | ISC_REQ_MANUAL_CRED_VALIDATION; ULONG a; + gsize size = 0; + gchar *data = NULL; memset(&ssl_cred, 0, sizeof(SCHANNEL_CRED)); ssl_cred.dwVersion = SCHANNEL_CRED_VERSION; @@ -104,13 +114,13 @@ static void ssl_connected(gpointer data, gint fd, GaimInputCondition cond) SECURITY_STATUS st = AcquireCredentialsHandle(NULL, UNISP_NAME, SECPKG_CRED_OUTBOUND, NULL, &ssl_cred, NULL, NULL, &conn->cred, ×tamp); if (st != SEC_E_OK) { - conn->func( conn->data, NULL, cond ); + conn->func(conn->data, NULL, cond); return; - + } do { /* initialize buffers */ - ibuf[0].cbBuffer = size; ibuf[0].pvBuffer = buf; + ibuf[0].cbBuffer = size; ibuf[0].pvBuffer = data; ibuf[1].cbBuffer = 0; ibuf[1].pvBuffer = NULL; obuf[0].cbBuffer = 0; obuf[0].pvBuffer = NULL; ibuf[0].BufferType = obuf[0].BufferType = SECBUFFER_TOKEN; @@ -121,8 +131,9 @@ static void ssl_connected(gpointer data, gint fd, GaimInputCondition cond) ibufs.cBuffers = 2; obufs.cBuffers = 1; ibufs.pBuffers = ibuf; obufs.pBuffers = obuf; - st = InitializeSecurityContext(&conn->cred, size?&conn->context:NULL, host, req, 0, SECURITY_NETWORK_DREP, size?&ibufs:NULL, 0, &conn->context, &obufs, &a, ×tamp); + st = InitializeSecurityContext(&conn->cred, size?&conn->context:NULL, conn->host, req, 0, SECURITY_NETWORK_DREP, size?&ibufs:NULL, 0, &conn->context, &obufs, &a, ×tamp); if (obuf[0].pvBuffer && obuf[0].cbBuffer) { + /* FIXME: Check return value */ send(conn->fd, obuf[0].pvBuffer, obuf[0].cbBuffer, 0); } @@ -130,17 +141,20 @@ static void ssl_connected(gpointer data, gint fd, GaimInputCondition cond) case SEC_I_INCOMPLETE_CREDENTIALS: break; case SEC_I_CONTINUE_NEEDED: - + break; + case SEC_E_INCOMPLETE_MESSAGE: + break; + case SEC_E_OK: + break; } - QueryContextAttributes(&conn->context, SECPKG_ATTR_STREAM_SIZES, &conn->sizes); } while (1); - conn->func( conn->data, conn, cond ); + conn->func(conn->data, conn, cond); } -int ssl_read( void *conn, char *retdata, int len ) +int ssl_read(void *conn, char *retdata, int len) { struct scd *scd = conn; SecBufferDesc msg; @@ -164,6 +178,11 @@ int ssl_read( void *conn, char *retdata, int len ) SECURITY_STATUS st = DecryptMessage(&scd->context, &msg, 0, NULL); + if (st != SEC_E_OK) { + /* FIXME */ + return -1; + } + for (i = 0; i < 4; i++) { if (buf[i].BufferType == SECBUFFER_DATA) { memcpy(retdata, buf[i].pvBuffer, len); @@ -172,10 +191,10 @@ int ssl_read( void *conn, char *retdata, int len ) } g_free(data); - return( -1 ); + return -1; } -int ssl_write( void *conn, const char *userdata, int len ) +int ssl_write(void *conn, const char *userdata, int len) { struct scd *scd = conn; SecBuffer buf[4]; @@ -213,7 +232,7 @@ int ssl_write( void *conn, const char *userdata, int len ) return ret; } -void ssl_disconnect( void *conn ) +void ssl_disconnect(void *conn) { struct scd *scd = conn; @@ -243,11 +262,17 @@ void ssl_disconnect( void *conn ) FreeCredentialsHandle(&scd->cred); - closesocket( scd->fd ); + closesocket(scd->fd); + g_free(scd->host); g_free(scd); } -int ssl_getfd( void *conn ) +int ssl_getfd(void *conn) +{ + return ((struct scd*)conn)->fd; +} + +GaimInputCondition ssl_getdirection( void *conn ) { - return( ((struct scd*)conn)->fd ); + return GAIM_INPUT_WRITE; /* FIXME: or GAIM_INPUT_READ */ } -- cgit v1.2.3 From fcc2da97bcfa5e0d704179fae9c4ed59cbaf79c5 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 26 May 2006 17:46:51 +0200 Subject: Remove unnecessary Windows-specific code. --- protocols/yahoo/libyahoo2.c | 2 -- protocols/yahoo/yahoo_httplib.c | 2 -- 2 files changed, 4 deletions(-) (limited to 'protocols') diff --git a/protocols/yahoo/libyahoo2.c b/protocols/yahoo/libyahoo2.c index c691f18b..967ba681 100644 --- a/protocols/yahoo/libyahoo2.c +++ b/protocols/yahoo/libyahoo2.c @@ -68,8 +68,6 @@ char *strchr (), *strrchr (); #ifdef __MINGW32__ # include -# define write(a,b,c) send(a,b,c,0) -# define read(a,b,c) recv(a,b,c,0) #endif #include diff --git a/protocols/yahoo/yahoo_httplib.c b/protocols/yahoo/yahoo_httplib.c index dbbe2a84..1b084992 100644 --- a/protocols/yahoo/yahoo_httplib.c +++ b/protocols/yahoo/yahoo_httplib.c @@ -50,8 +50,6 @@ char *strchr (), *strrchr (); #include "yahoo_debug.h" #ifdef __MINGW32__ # include -# define write(a,b,c) send(a,b,c,0) -# define read(a,b,c) recv(a,b,c,0) # define snprintf _snprintf #endif -- cgit v1.2.3 From 21e5d4981de057bae5261720021757d893061652 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 10 Jun 2008 05:16:15 +0200 Subject: Move SSPI SSL implementation to same directory as other SSL backends. --- protocols/ssl_sspi.c | 278 --------------------------------------------------- 1 file changed, 278 deletions(-) delete mode 100644 protocols/ssl_sspi.c (limited to 'protocols') diff --git a/protocols/ssl_sspi.c b/protocols/ssl_sspi.c deleted file mode 100644 index a16423b1..00000000 --- a/protocols/ssl_sspi.c +++ /dev/null @@ -1,278 +0,0 @@ - /********************************************************************\ - * BitlBee -- An IRC to other IM-networks gateway * - * * - * Copyright 2002-2004 Wilmer van der Gaast and others * - \********************************************************************/ - -/* SSL module - SSPI backend */ - -/* Copyright (C) 2005 Jelmer Vernooij */ - -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License with - the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; - if not, write to the Free Software Foundation, Inc., 59 Temple Place, - Suite 330, Boston, MA 02111-1307 USA -*/ - -#include "ssl_client.h" -#include -#define SECURITY_WIN32 -#include -#include -#include -#include "sock.h" - -static gboolean initialized = FALSE; -int ssl_errno; - -struct scd -{ - int fd; - ssl_input_function func; - gpointer data; - gboolean established; - CredHandle cred; /* SSL credentials */ - CtxtHandle context; /* SSL context */ - SecPkgContext_StreamSizes sizes; - - char *host; - - char *pending_raw_data; - gsize pending_raw_data_len; - char *pending_data; - gsize pending_data_len; -}; - -static void ssl_connected(gpointer, gint, GaimInputCondition); - -void sspi_global_init(void) -{ - /* FIXME */ -} - -void sspi_global_deinit(void) -{ - /* FIXME */ -} - -void *ssl_connect(char *host, int port, ssl_input_function func, gpointer data) -{ - struct scd *conn = g_new0(struct scd, 1); - - conn->fd = proxy_connect(host, port, ssl_connected, conn); - sock_make_nonblocking(conn->fd); - conn->func = func; - conn->data = data; - conn->host = g_strdup(host); - - if (conn->fd < 0) - { - g_free(conn); - return NULL; - } - - if (!initialized) - { - sspi_global_init(); - initialized = TRUE; - atexit(sspi_global_deinit); - } - - return conn; -} - -static void ssl_connected(gpointer _conn, gint fd, GaimInputCondition cond) -{ - struct scd *conn = _conn; - SCHANNEL_CRED ssl_cred; - TimeStamp timestamp; - SecBuffer ibuf[2],obuf[1]; - SecBufferDesc ibufs,obufs; - ULONG req = ISC_REQ_REPLAY_DETECT | ISC_REQ_SEQUENCE_DETECT | - ISC_REQ_CONFIDENTIALITY | ISC_REQ_USE_SESSION_KEY | - ISC_REQ_ALLOCATE_MEMORY | ISC_REQ_STREAM | ISC_REQ_EXTENDED_ERROR | - ISC_REQ_MANUAL_CRED_VALIDATION; - ULONG a; - gsize size = 0; - gchar *data = NULL; - - memset(&ssl_cred, 0, sizeof(SCHANNEL_CRED)); - ssl_cred.dwVersion = SCHANNEL_CRED_VERSION; - ssl_cred.grbitEnabledProtocols = SP_PROT_SSL3_CLIENT; - - SECURITY_STATUS st = AcquireCredentialsHandle(NULL, UNISP_NAME, SECPKG_CRED_OUTBOUND, NULL, &ssl_cred, NULL, NULL, &conn->cred, ×tamp); - - if (st != SEC_E_OK) { - conn->func(conn->data, NULL, cond); - return; - } - - do { - /* initialize buffers */ - ibuf[0].cbBuffer = size; ibuf[0].pvBuffer = data; - ibuf[1].cbBuffer = 0; ibuf[1].pvBuffer = NULL; - obuf[0].cbBuffer = 0; obuf[0].pvBuffer = NULL; - ibuf[0].BufferType = obuf[0].BufferType = SECBUFFER_TOKEN; - ibuf[1].BufferType = SECBUFFER_EMPTY; - - /* initialize buffer descriptors */ - ibufs.ulVersion = obufs.ulVersion = SECBUFFER_VERSION; - ibufs.cBuffers = 2; obufs.cBuffers = 1; - ibufs.pBuffers = ibuf; obufs.pBuffers = obuf; - - st = InitializeSecurityContext(&conn->cred, size?&conn->context:NULL, conn->host, req, 0, SECURITY_NETWORK_DREP, size?&ibufs:NULL, 0, &conn->context, &obufs, &a, ×tamp); - if (obuf[0].pvBuffer && obuf[0].cbBuffer) { - /* FIXME: Check return value */ - send(conn->fd, obuf[0].pvBuffer, obuf[0].cbBuffer, 0); - } - - switch (st) { - case SEC_I_INCOMPLETE_CREDENTIALS: - break; - case SEC_I_CONTINUE_NEEDED: - break; - case SEC_E_INCOMPLETE_MESSAGE: - break; - case SEC_E_OK: - break; - } - - QueryContextAttributes(&conn->context, SECPKG_ATTR_STREAM_SIZES, &conn->sizes); - } while (1); - - conn->func(conn->data, conn, cond); -} - -int ssl_read(void *conn, char *retdata, int len) -{ - struct scd *scd = conn; - SecBufferDesc msg; - SecBuffer buf[4]; - int ret = -1, i; - char *data = g_malloc(scd->sizes.cbHeader + scd->sizes.cbMaximumMessage + scd->sizes.cbTrailer); - - /* FIXME: Try to read some data */ - - msg.ulVersion = SECBUFFER_VERSION; - msg.cBuffers = 4; - msg.pBuffers = buf; - - buf[0].BufferType = SECBUFFER_DATA; - buf[0].cbBuffer = len; - buf[0].pvBuffer = data; - - buf[1].BufferType = SECBUFFER_EMPTY; - buf[2].BufferType = SECBUFFER_EMPTY; - buf[3].BufferType = SECBUFFER_EMPTY; - - SECURITY_STATUS st = DecryptMessage(&scd->context, &msg, 0, NULL); - - if (st != SEC_E_OK) { - /* FIXME */ - return -1; - } - - for (i = 0; i < 4; i++) { - if (buf[i].BufferType == SECBUFFER_DATA) { - memcpy(retdata, buf[i].pvBuffer, len); - ret = len; - } - } - - g_free(data); - return -1; -} - -int ssl_write(void *conn, const char *userdata, int len) -{ - struct scd *scd = conn; - SecBuffer buf[4]; - SecBufferDesc msg; - char *data; - int ret; - - msg.ulVersion = SECBUFFER_VERSION; - msg.cBuffers = 4; - msg.pBuffers = buf; - - data = g_malloc(scd->sizes.cbHeader + scd->sizes.cbMaximumMessage + scd->sizes.cbTrailer); - memcpy(data + scd->sizes.cbHeader, userdata, len); - - buf[0].BufferType = SECBUFFER_STREAM_HEADER; - buf[0].cbBuffer = scd->sizes.cbHeader; - buf[0].pvBuffer = data; - - buf[1].BufferType = SECBUFFER_DATA; - buf[1].cbBuffer = len; - buf[1].pvBuffer = data + scd->sizes.cbHeader; - - buf[2].BufferType = SECBUFFER_STREAM_TRAILER; - buf[2].cbBuffer = scd->sizes.cbTrailer; - buf[2].pvBuffer = data + scd->sizes.cbHeader + len; - buf[3].BufferType = SECBUFFER_EMPTY; - - SECURITY_STATUS st = EncryptMessage(&scd->context, 0, &msg, 0); - - ret = send(scd->fd, data, - buf[0].cbBuffer + buf[1].cbBuffer + buf[2].cbBuffer, 0); - - g_free(data); - - return ret; -} - -void ssl_disconnect(void *conn) -{ - struct scd *scd = conn; - - SecBufferDesc msg; - SecBuffer buf; - DWORD dw; - - dw = SCHANNEL_SHUTDOWN; - buf.cbBuffer = sizeof(dw); - buf.BufferType = SECBUFFER_TOKEN; - buf.pvBuffer = &dw; - - msg.ulVersion = SECBUFFER_VERSION; - msg.cBuffers = 1; - msg.pBuffers = &buf; - - SECURITY_STATUS st = ApplyControlToken(&scd->context, &msg); - - if (st != SEC_E_OK) { - /* FIXME */ - } - - /* FIXME: call InitializeSecurityContext(Schannel), passing - * in empty buffers*/ - - DeleteSecurityContext(&scd->context); - - FreeCredentialsHandle(&scd->cred); - - closesocket(scd->fd); - g_free(scd->host); - g_free(scd); -} - -int ssl_getfd(void *conn) -{ - return ((struct scd*)conn)->fd; -} - -GaimInputCondition ssl_getdirection( void *conn ) -{ - return GAIM_INPUT_WRITE; /* FIXME: or GAIM_INPUT_READ */ -} -- cgit v1.2.3 From 52df5dfbe4761c26326083bef9daa80af9716858 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 14 Jun 2008 02:19:12 +0100 Subject: This seems to fix the Yahoo! logoff code. I have no idea why this was broken (on purpose) in libyahoo2, but this fix seems to work and at least Valgrind is still happy. And I actually see myself log off now, and the fd is actually cleaned up properly. --- protocols/yahoo/libyahoo2.c | 11 ++++------- protocols/yahoo/yahoo.c | 4 ---- 2 files changed, 4 insertions(+), 11 deletions(-) (limited to 'protocols') diff --git a/protocols/yahoo/libyahoo2.c b/protocols/yahoo/libyahoo2.c index 80d88a85..897ba27b 100644 --- a/protocols/yahoo/libyahoo2.c +++ b/protocols/yahoo/libyahoo2.c @@ -380,7 +380,6 @@ static void del_from_list(struct yahoo_data *yd) } /* call repeatedly to get the next one */ -/* static struct yahoo_input_data * find_input_by_id(int id) { YList *l; @@ -391,7 +390,6 @@ static struct yahoo_input_data * find_input_by_id(int id) } return NULL; } -*/ static struct yahoo_input_data * find_input_by_id_and_webcam_user(int id, const char * who) { @@ -796,6 +794,7 @@ static int yahoo_send_data(int fd, void *data, int len) void yahoo_close(int id) { struct yahoo_data *yd = find_conn_by_id(id); + if(!yd) return; @@ -3165,7 +3164,7 @@ int yahoo_write_ready(int id, int fd, void *data) struct data_queue *tx; LOG(("write callback: id=%d fd=%d data=%p", id, fd, data)); - if(!yid || !yid->txqueues) + if(!yid || !yid->txqueues || !find_conn_by_id(id)) return -2; tx = yid->txqueues->data; @@ -3841,11 +3840,9 @@ void yahoo_logoff(int id) } } - -/* do { + do { yahoo_input_close(yid); - } while((yid = find_input_by_id(id)));*/ - + } while((yid = find_input_by_id(id))); } void yahoo_get_list(int id) diff --git a/protocols/yahoo/yahoo.c b/protocols/yahoo/yahoo.c index ab30df4d..c84685e9 100644 --- a/protocols/yahoo/yahoo.c +++ b/protocols/yahoo/yahoo.c @@ -453,10 +453,6 @@ gboolean byahoo_write_ready_callback( gpointer data, gint source, b_input_condit { struct byahoo_write_ready_data *d = data; - if( !byahoo_get_ic_by_id( d->id ) ) - /* WTF doesn't libyahoo clean this up? */ - return FALSE; - yahoo_write_ready( d->id, d->fd, d->data ); return FALSE; -- cgit v1.2.3 From 5ec4129afd5d47d7cea5d9cb455a364c17c8a8fa Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 15 Jun 2008 01:04:27 +0100 Subject: Added parsing of Jabber chatroom invitations. --- protocols/jabber/message.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'protocols') diff --git a/protocols/jabber/message.c b/protocols/jabber/message.c index fab62a91..6cb67d42 100644 --- a/protocols/jabber/message.c +++ b/protocols/jabber/message.c @@ -48,6 +48,23 @@ xt_status jabber_pkt_message( struct xt_node *node, gpointer data ) else /* "chat", "normal", "headline", no-type or whatever. Should all be pretty similar. */ { GString *fullmsg = g_string_new( "" ); + + for( c = node->children; ( c = xt_find_node( c, "x" ) ); c = c->next ) + { + char *ns = xt_find_attr( c, "xmlns" ), *room; + struct xt_node *inv, *reason; + + if( strcmp( ns, XMLNS_MUC_USER ) == 0 && + ( inv = xt_find_node( c->children, "invite" ) ) ) + { + room = from; + from = xt_find_attr( inv, "from" ) ? : from; + + g_string_append_printf( fullmsg, "<< \002BitlBee\002 - Invitation to chatroom %s >>\n", room ); + if( ( reason = xt_find_node( inv->children, "reason" ) ) && reason->text_len > 0 ) + g_string_append( fullmsg, reason->text ); + } + } if( ( s = strchr( from, '/' ) ) ) { -- cgit v1.2.3 From 7f697401c8261459ce60c985ae1423db7b22c79b Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 15 Jun 2008 19:11:47 +0100 Subject: Using a port list instead of a single range for the allowed Jabber port numbers, adding 80 and 443. Partially closes #265. --- protocols/jabber/jabber.c | 32 +++++++++++++++++++++++++++----- protocols/jabber/jabber.h | 4 ---- 2 files changed, 27 insertions(+), 9 deletions(-) (limited to 'protocols') diff --git a/protocols/jabber/jabber.c b/protocols/jabber/jabber.c index 0e23b4d4..52a87d5d 100644 --- a/protocols/jabber/jabber.c +++ b/protocols/jabber/jabber.c @@ -36,11 +36,30 @@ GSList *jabber_connections; +/* First enty is the default */ +static const int jabber_port_list[] = { + 5222, + 5223, + 5220, + 5221, + 5224, + 5225, + 5226, + 5227, + 5228, + 5229, + 80, + 443, + 0 +}; + static void jabber_init( account_t *acc ) { set_t *s; + char str[16]; - s = set_add( &acc->set, "port", JABBER_PORT_DEFAULT, set_eval_int, acc ); + g_snprintf( str, sizeof( str ), "%d", jabber_port_list[0] ); + s = set_add( &acc->set, "port", str, set_eval_int, acc ); s->flags |= ACC_SET_OFFLINE_ONLY; s = set_add( &acc->set, "priority", "0", set_eval_priority, acc ); @@ -71,6 +90,7 @@ static void jabber_login( account_t *acc ) struct jabber_data *jd = g_new0( struct jabber_data, 1 ); struct ns_srv_reply *srv = NULL; char *connect_to, *s; + int i; /* For now this is needed in the _connected() handlers if using GLib event handling, to make sure we're not handling events @@ -176,11 +196,13 @@ static void jabber_login( account_t *acc ) imcb_log( ic, "Connecting" ); - if( set_getint( &acc->set, "port" ) < JABBER_PORT_MIN || - set_getint( &acc->set, "port" ) > JABBER_PORT_MAX ) + for( i = 0; jabber_port_list[i] > 0; i ++ ) + if( set_getint( &acc->set, "port" ) == jabber_port_list[i] ) + break; + + if( jabber_port_list[i] == 0 ) { - imcb_log( ic, "Incorrect port number, must be in the %d-%d range", - JABBER_PORT_MIN, JABBER_PORT_MAX ); + imcb_log( ic, "Illegal port number" ); imc_logout( ic, FALSE ); return; } diff --git a/protocols/jabber/jabber.h b/protocols/jabber/jabber.h index 1ff0e8dd..023cf0f9 100644 --- a/protocols/jabber/jabber.h +++ b/protocols/jabber/jabber.h @@ -134,10 +134,6 @@ struct jabber_chat #define JABBER_XMLCONSOLE_HANDLE "xmlconsole" -#define JABBER_PORT_DEFAULT "5222" -#define JABBER_PORT_MIN 5220 -#define JABBER_PORT_MAX 5229 - /* Prefixes to use for packet IDs (mainly for IQ packets ATM). Usually the first one should be used, but when storing a packet in the cache, a "special" kind of ID is assigned to make it easier later to figure out -- cgit v1.2.3 From 3e6764ab9c8ebd99683fd3c153161d96b32e05de Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 22 Jun 2008 00:34:11 +0100 Subject: Added jabber_util unittests (buddy_add/_by_jid only ATM). --- protocols/jabber/jabber_util.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'protocols') diff --git a/protocols/jabber/jabber_util.c b/protocols/jabber/jabber_util.c index 518624f6..78d1009c 100644 --- a/protocols/jabber/jabber_util.c +++ b/protocols/jabber/jabber_util.c @@ -524,7 +524,9 @@ int jabber_buddy_remove( struct im_connection *ic, char *full_jid_ ) /* If there's only one item in the list (and if the resource matches), removing it is simple. (And the hash reference should be removed too!) */ - if( bud->next == NULL && ( ( s == NULL || bud->resource == NULL ) || g_strcasecmp( bud->resource, s + 1 ) == 0 ) ) + if( bud->next == NULL && + ( ( s == NULL && bud->resource == NULL ) || + ( bud->resource && s && g_strcasecmp( bud->resource, s + 1 ) == 0 ) ) ) { g_hash_table_remove( jd->buddies, bud->bare_jid ); g_free( bud->bare_jid ); -- cgit v1.2.3 From 98de2cca016d458ad2980c59f334fae10164b3bb Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 22 Jun 2008 00:51:18 +0100 Subject: Now preserving case in JID resources, and handling them with case sensitivity since apparently that's how the RFC wants it. (While the rest of the JID should be case IN-sensitive. Consistency is hard to find these days...) Also extended the unittests a little bit. Closes #422. --- protocols/jabber/jabber_util.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'protocols') diff --git a/protocols/jabber/jabber_util.c b/protocols/jabber/jabber_util.c index 78d1009c..44dc5984 100644 --- a/protocols/jabber/jabber_util.c +++ b/protocols/jabber/jabber_util.c @@ -289,8 +289,13 @@ char *jabber_normalize( const char *orig ) len = strlen( orig ); new = g_new( char, len + 1 ); - for( i = 0; i < len; i ++ ) + + /* So it turns out the /resource part is case sensitive. Yeah, and + it's Unicode but feck Unicode. :-P So stop once we see a slash. */ + for( i = 0; i < len && orig[i] != '/' ; i ++ ) new[i] = tolower( orig[i] ); + for( ; orig[i]; i ++ ) + new[i] = orig[i]; new[i] = 0; return new; @@ -333,7 +338,7 @@ struct jabber_buddy *jabber_buddy_add( struct im_connection *ic, char *full_jid_ for( bi = bud; bi; bi = bi->next ) { /* Check for dupes. */ - if( g_strcasecmp( bi->resource, s + 1 ) == 0 ) + if( strcmp( bi->resource, s + 1 ) == 0 ) { *s = '/'; g_free( new ); @@ -386,7 +391,7 @@ struct jabber_buddy *jabber_buddy_by_jid( struct im_connection *ic, char *jid_, if( ( s = strchr( jid, '/' ) ) ) { - int none_found = 0; + int bare_exists = 0; *s = 0; if( ( bud = g_hash_table_lookup( jd->buddies, jid ) ) ) @@ -409,21 +414,19 @@ struct jabber_buddy *jabber_buddy_by_jid( struct im_connection *ic, char *jid_, /* See if there's an exact match. */ for( ; bud; bud = bud->next ) - if( g_strcasecmp( bud->resource, s + 1 ) == 0 ) + if( strcmp( bud->resource, s + 1 ) == 0 ) break; } else { - /* This hack is there to make sure that O_CREAT will - work if there's already another resouce present - for this JID, even if it's an unknown buddy. This - is done to handle conferences properly. */ - none_found = 1; - /* TODO(wilmer): Find out what I was thinking when I - wrote this??? And then fix it. This makes me sad... */ + /* This variable tells the if down here that the bare + JID already exists and we should feel free to add + more resources, if the caller asked for that. */ + bare_exists = 1; } - if( bud == NULL && ( flags & GET_BUDDY_CREAT ) && ( imcb_find_buddy( ic, jid ) || !none_found ) ) + if( bud == NULL && ( flags & GET_BUDDY_CREAT ) && + ( !bare_exists || imcb_find_buddy( ic, jid ) ) ) { *s = '/'; bud = jabber_buddy_add( ic, jid ); @@ -448,7 +451,7 @@ struct jabber_buddy *jabber_buddy_by_jid( struct im_connection *ic, char *jid_, else if( bud->resource && ( flags & GET_BUDDY_EXACT ) ) /* We want an exact match, so in thise case there shouldn't be a /resource. */ return NULL; - else if( ( bud->resource == NULL || bud->next == NULL ) ) + else if( bud->resource == NULL || bud->next == NULL ) /* No need for selection if there's only one option. */ return bud; else if( flags & GET_BUDDY_FIRST ) @@ -526,7 +529,7 @@ int jabber_buddy_remove( struct im_connection *ic, char *full_jid_ ) should be removed too!) */ if( bud->next == NULL && ( ( s == NULL && bud->resource == NULL ) || - ( bud->resource && s && g_strcasecmp( bud->resource, s + 1 ) == 0 ) ) ) + ( bud->resource && s && strcmp( bud->resource, s + 1 ) == 0 ) ) ) { g_hash_table_remove( jd->buddies, bud->bare_jid ); g_free( bud->bare_jid ); @@ -549,7 +552,7 @@ int jabber_buddy_remove( struct im_connection *ic, char *full_jid_ ) else { for( bi = bud, prev = NULL; bi; bi = (prev=bi)->next ) - if( g_strcasecmp( bi->resource, s + 1 ) == 0 ) + if( strcmp( bi->resource, s + 1 ) == 0 ) break; g_free( full_jid ); -- cgit v1.2.3 From 424e66361e985d05e47a7af42e81cd32b09dd6e2 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 22 Jun 2008 10:32:46 +0100 Subject: Partial fix for #419: Moved normalize() and some other stuff to OSCAR becuase it's the only place where it's used, and using this to strip spaces from all screennames before sending them to BitlBee. --- protocols/nogaim.h | 5 ---- protocols/oscar/oscar.c | 80 ++++++++++++++++++++++++++++++++++--------------- 2 files changed, 56 insertions(+), 29 deletions(-) (limited to 'protocols') diff --git a/protocols/nogaim.h b/protocols/nogaim.h index bdd8bae2..9fe843b5 100644 --- a/protocols/nogaim.h +++ b/protocols/nogaim.h @@ -44,11 +44,6 @@ #include "query.h" #include "md5.h" -#define BUF_LEN MSG_LEN -#define BUF_LONG ( BUF_LEN * 2 ) -#define MSG_LEN 2048 -#define BUF_LEN MSG_LEN - #define BUDDY_ALIAS_MAXLEN 388 /* because MSN names can be 387 characters */ #define WEBSITE "http://www.bitlbee.org/" diff --git a/protocols/oscar/oscar.c b/protocols/oscar/oscar.c index 7738c31f..819ec27d 100644 --- a/protocols/oscar/oscar.c +++ b/protocols/oscar/oscar.c @@ -60,6 +60,9 @@ #define OSCAR_GROUP "Friends" +#define BUF_LEN 2048 +#define BUF_LONG ( BUF_LEN * 2 ) + /* Don't know if support for UTF8 is really working. For now it's UTF16 here. static int gaim_caps = AIM_CAPS_UTF8; */ @@ -240,6 +243,32 @@ static char *msgerrreason[] = { }; static int msgerrreasonlen = 25; +/* Hurray, this function is NOT thread-safe \o/ */ +static char *normalize(const char *s) +{ + static char buf[BUF_LEN]; + char *t, *u; + int x = 0; + + g_return_val_if_fail((s != NULL), NULL); + + u = t = g_strdup(s); + + strcpy(t, s); + g_strdown(t); + + while (*t && (x < BUF_LEN - 1)) { + if (*t != ' ' && *t != '!') { + buf[x] = *t; + x++; + } + t++; + } + buf[x] = '\0'; + g_free(u); + return buf; +} + static gboolean oscar_callback(gpointer data, gint source, b_input_condition condition) { aim_conn_t *conn = (aim_conn_t *)data; @@ -1001,13 +1030,13 @@ static int gaim_parse_oncoming(aim_session_t *sess, aim_frame_t *fr, ...) { g_hash_table_insert(od->ips, uin, (gpointer) (long) info->icqinfo.ipaddr); } - tmp = g_strdup(normalize(ic->acc->user)); - if (!strcmp(tmp, normalize(info->sn))) + if (!aim_sncmp(tmp, normalize(info->sn))) g_snprintf(ic->displayname, sizeof(ic->displayname), "%s", info->sn); - g_free(tmp); - imcb_buddy_status(ic, info->sn, flags, state_string, NULL); - /* imcb_buddy_times(ic, info->sn, signon, time_idle); */ + tmp = normalize(info->sn); + imcb_buddy_status(ic, tmp, flags, state_string, NULL); + /* imcb_buddy_times(ic, tmp, signon, time_idle); */ + return 1; } @@ -1021,7 +1050,7 @@ static int gaim_parse_offgoing(aim_session_t *sess, aim_frame_t *fr, ...) { info = va_arg(ap, aim_userinfo_t *); va_end(ap); - imcb_buddy_status(ic, info->sn, 0, NULL, NULL ); + imcb_buddy_status(ic, normalize(info->sn), 0, NULL, NULL ); return 1; } @@ -1077,7 +1106,7 @@ static int incomingim_chan1(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_ } strip_linefeed(tmp); - imcb_buddy_msg(ic, userinfo->sn, tmp, flags, 0); + imcb_buddy_msg(ic, normalize(userinfo->sn), tmp, flags, 0); g_free(tmp); return 1; @@ -1176,7 +1205,7 @@ static int incomingim_chan4(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_ uin = g_strdup_printf("%u", args->uin); message = g_strdup(args->msg); strip_linefeed(message); - imcb_buddy_msg(ic, uin, message, 0, 0); + imcb_buddy_msg(ic, normalize(uin), message, 0, 0); g_free(uin); g_free(message); } break; @@ -1195,7 +1224,7 @@ static int incomingim_chan4(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_ } strip_linefeed(message); - imcb_buddy_msg(ic, uin, message, 0, 0); + imcb_buddy_msg(ic, normalize(uin), message, 0, 0); g_free(uin); g_free(m); g_free(message); @@ -1470,7 +1499,7 @@ static int gaim_chat_join(aim_session_t *sess, aim_frame_t *fr, ...) { return 1; for (i = 0; i < count; i++) - imcb_chat_add_buddy(c->cnv, info[i].sn); + imcb_chat_add_buddy(c->cnv, normalize(info[i].sn)); return 1; } @@ -1493,7 +1522,7 @@ static int gaim_chat_leave(aim_session_t *sess, aim_frame_t *fr, ...) { return 1; for (i = 0; i < count; i++) - imcb_chat_remove_buddy(c->cnv, info[i].sn, NULL); + imcb_chat_remove_buddy(c->cnv, normalize(info[i].sn), NULL); return 1; } @@ -1544,7 +1573,7 @@ static int gaim_chat_incoming_msg(aim_session_t *sess, aim_frame_t *fr, ...) { tmp = g_malloc(BUF_LONG); g_snprintf(tmp, BUF_LONG, "%s", msg); - imcb_chat_msg(ccon->cnv, info->sn, tmp, 0, 0); + imcb_chat_msg(ccon->cnv, normalize(info->sn), tmp, 0, 0); g_free(tmp); return 1; @@ -1757,7 +1786,7 @@ static int gaim_offlinemsg(aim_session_t *sess, aim_frame_t *fr, ...) { time_t t = get_time(msg->year, msg->month, msg->day, msg->hour, msg->minute, 0); g_snprintf(sender, sizeof(sender), "%u", msg->sender); strip_linefeed(dialog_msg); - imcb_buddy_msg(ic, sender, dialog_msg, 0, t); + imcb_buddy_msg(ic, normalize(sender), dialog_msg, 0, t); g_free(dialog_msg); } break; @@ -1778,7 +1807,7 @@ static int gaim_offlinemsg(aim_session_t *sess, aim_frame_t *fr, ...) { } strip_linefeed(dialog_msg); - imcb_buddy_msg(ic, sender, dialog_msg, 0, t); + imcb_buddy_msg(ic, normalize(sender), dialog_msg, 0, t); g_free(dialog_msg); g_free(m); } break; @@ -2016,23 +2045,26 @@ static int gaim_ssi_parselist(aim_session_t *sess, aim_frame_t *fr, ...) { struct im_connection *ic = sess->aux_data; struct aim_ssi_item *curitem; int tmp; + char *nrm; /* Add from server list to local list */ tmp = 0; for (curitem=sess->ssi.items; curitem; curitem=curitem->next) { switch (curitem->type) { case 0x0000: /* Buddy */ - if ((curitem->name) && (!imcb_find_buddy(ic, curitem->name))) { + nrm = normalize(curitem->name); + + if ((curitem->name) && (!imcb_find_buddy(ic, nrm))) { char *realname = NULL; if (curitem->data && aim_gettlv(curitem->data, 0x0131, 1)) realname = aim_gettlv_str(curitem->data, 0x0131, 1); - imcb_add_buddy(ic, curitem->name, NULL); + imcb_add_buddy(ic, nrm, NULL); if (realname) { - imcb_buddy_nick_hint(ic, curitem->name, realname); - imcb_rename_buddy(ic, curitem->name, realname); + imcb_buddy_nick_hint(ic, nrm, realname); + imcb_rename_buddy(ic, nrm, realname); g_free(realname); } } @@ -2044,7 +2076,7 @@ static int gaim_ssi_parselist(aim_session_t *sess, aim_frame_t *fr, ...) { for (list=ic->permit; (list && aim_sncmp(curitem->name, list->data)); list=list->next); if (!list) { char *name; - name = g_strdup(normalize(curitem->name)); + name = g_strdup(nrm); ic->permit = g_slist_append(ic->permit, name); tmp++; } @@ -2057,7 +2089,7 @@ static int gaim_ssi_parselist(aim_session_t *sess, aim_frame_t *fr, ...) { for (list=ic->deny; (list && aim_sncmp(curitem->name, list->data)); list=list->next); if (!list) { char *name; - name = g_strdup(normalize(curitem->name)); + name = g_strdup(nrm); ic->deny = g_slist_append(ic->deny, name); tmp++; } @@ -2119,7 +2151,7 @@ static int gaim_ssi_parseack( aim_session_t *sess, aim_frame_t *fr, ... ) st = aimbs_get16( &fr->data ); if( st == 0x00 ) { - imcb_add_buddy( sess->aux_data, list, NULL ); + imcb_add_buddy( sess->aux_data, normalize(list), NULL ); } else if( st == 0x0E ) { @@ -2449,15 +2481,15 @@ int gaim_parsemtn(aim_session_t *sess, aim_frame_t *fr, ...) if(type2 == 0x0002) { /* User is typing */ - imcb_buddy_typing(ic, sn, OPT_TYPING); + imcb_buddy_typing(ic, normalize(sn), OPT_TYPING); } else if (type2 == 0x0001) { /* User has typed something, but is not actively typing (stale) */ - imcb_buddy_typing(ic, sn, OPT_THINKING); + imcb_buddy_typing(ic, normalize(sn), OPT_THINKING); } else { /* User has stopped typing */ - imcb_buddy_typing(ic, sn, 0); + imcb_buddy_typing(ic, normalize(sn), 0); } return 1; -- cgit v1.2.3 From c801d25cc574279566b35c3a9fce96962521670a Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 22 Jun 2008 11:05:33 +0100 Subject: Fixed bug in [devel,394]. --- protocols/oscar/oscar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'protocols') diff --git a/protocols/oscar/oscar.c b/protocols/oscar/oscar.c index 819ec27d..1bd221b4 100644 --- a/protocols/oscar/oscar.c +++ b/protocols/oscar/oscar.c @@ -1030,7 +1030,7 @@ static int gaim_parse_oncoming(aim_session_t *sess, aim_frame_t *fr, ...) { g_hash_table_insert(od->ips, uin, (gpointer) (long) info->icqinfo.ipaddr); } - if (!aim_sncmp(tmp, normalize(info->sn))) + if (!aim_sncmp(ic->acc->user, info->sn)) g_snprintf(ic->displayname, sizeof(ic->displayname), "%s", info->sn); tmp = normalize(info->sn); -- cgit v1.2.3 From de823359bee02853be86b75ddc8272812502ff5d Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 22 Jun 2008 13:26:19 +0100 Subject: Another fixup after [devel,394]. Clearly I'm not a morning person. --- protocols/oscar/oscar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'protocols') diff --git a/protocols/oscar/oscar.c b/protocols/oscar/oscar.c index 1bd221b4..a3b4a071 100644 --- a/protocols/oscar/oscar.c +++ b/protocols/oscar/oscar.c @@ -2050,10 +2050,10 @@ static int gaim_ssi_parselist(aim_session_t *sess, aim_frame_t *fr, ...) { /* Add from server list to local list */ tmp = 0; for (curitem=sess->ssi.items; curitem; curitem=curitem->next) { + nrm = normalize(curitem->name); + switch (curitem->type) { case 0x0000: /* Buddy */ - nrm = normalize(curitem->name); - if ((curitem->name) && (!imcb_find_buddy(ic, nrm))) { char *realname = NULL; -- cgit v1.2.3 From fab3d2d497e2819c142859a3698e85372e58df14 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 22 Jun 2008 14:02:15 +0100 Subject: Shut up a "mostly harmless" warning (this NULL would never actually be dereferenced as far as I can see). --- protocols/oscar/oscar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'protocols') diff --git a/protocols/oscar/oscar.c b/protocols/oscar/oscar.c index a3b4a071..36e03166 100644 --- a/protocols/oscar/oscar.c +++ b/protocols/oscar/oscar.c @@ -2050,7 +2050,7 @@ static int gaim_ssi_parselist(aim_session_t *sess, aim_frame_t *fr, ...) { /* Add from server list to local list */ tmp = 0; for (curitem=sess->ssi.items; curitem; curitem=curitem->next) { - nrm = normalize(curitem->name); + nrm = curitem->name ? normalize(curitem->name) : NULL; switch (curitem->type) { case 0x0000: /* Buddy */ -- cgit v1.2.3 From 89d736a169cbff4520dcbb475aa7269b2cf4b837 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 22 Jun 2008 20:21:06 +0100 Subject: From the department of over-engineering, now cached packet IDs are full MD5 hashes instead of a known MD5 hash with a number. Just to make it harder to confuse BitlBee by sending it faked responses to packets. --- protocols/jabber/jabber.c | 24 +++++++++--------------- protocols/jabber/jabber.h | 2 +- protocols/jabber/jabber_util.c | 24 +++++++++++++++++++++--- 3 files changed, 31 insertions(+), 19 deletions(-) (limited to 'protocols') diff --git a/protocols/jabber/jabber.c b/protocols/jabber/jabber.c index 52a87d5d..c9c1d0a0 100644 --- a/protocols/jabber/jabber.c +++ b/protocols/jabber/jabber.c @@ -32,7 +32,6 @@ #include "bitlbee.h" #include "jabber.h" #include "md5.h" -#include "base64.h" GSList *jabber_connections; @@ -240,24 +239,20 @@ static void jabber_login( account_t *acc ) jabber_generate_id_hash( jd ); } +/* This generates an unfinished md5_state_t variable. Every time we generate + an ID, we finish the state by adding a sequence number and take the hash. */ static void jabber_generate_id_hash( struct jabber_data *jd ) { - md5_state_t id_hash; - md5_byte_t binbuf[16]; + md5_byte_t binbuf[4]; char *s; - md5_init( &id_hash ); - md5_append( &id_hash, (unsigned char *) jd->username, strlen( jd->username ) ); - md5_append( &id_hash, (unsigned char *) jd->server, strlen( jd->server ) ); + md5_init( &jd->cached_id_prefix ); + md5_append( &jd->cached_id_prefix, (unsigned char *) jd->username, strlen( jd->username ) ); + md5_append( &jd->cached_id_prefix, (unsigned char *) jd->server, strlen( jd->server ) ); s = set_getstr( &jd->ic->acc->set, "resource" ); - md5_append( &id_hash, (unsigned char *) s, strlen( s ) ); - random_bytes( binbuf, 16 ); - md5_append( &id_hash, binbuf, 16 ); - md5_finish( &id_hash, binbuf ); - - s = base64_encode( binbuf, 9 ); - jd->cached_id_prefix = g_strdup_printf( "%s%s", JABBER_CACHED_ID, s ); - g_free( s ); + md5_append( &jd->cached_id_prefix, (unsigned char *) s, strlen( s ) ); + random_bytes( binbuf, 4 ); + md5_append( &jd->cached_id_prefix, binbuf, 4 ); } static void jabber_logout( struct im_connection *ic ) @@ -288,7 +283,6 @@ static void jabber_logout( struct im_connection *ic ) xt_free( jd->xt ); - g_free( jd->cached_id_prefix ); g_free( jd->away_message ); g_free( jd->username ); g_free( jd ); diff --git a/protocols/jabber/jabber.h b/protocols/jabber/jabber.h index 023cf0f9..904bf0c4 100644 --- a/protocols/jabber/jabber.h +++ b/protocols/jabber/jabber.h @@ -85,7 +85,7 @@ struct jabber_data struct jabber_away_state *away_state; char *away_message; - char *cached_id_prefix; + md5_state_t cached_id_prefix; GHashTable *node_cache; GHashTable *buddies; }; diff --git a/protocols/jabber/jabber_util.c b/protocols/jabber/jabber_util.c index 44dc5984..1bee5009 100644 --- a/protocols/jabber/jabber_util.c +++ b/protocols/jabber/jabber_util.c @@ -22,6 +22,8 @@ \***************************************************************************/ #include "jabber.h" +#include "md5.h" +#include "base64.h" static unsigned int next_id = 1; @@ -133,11 +135,21 @@ void jabber_cache_add( struct im_connection *ic, struct xt_node *node, jabber_ca { struct jabber_data *jd = ic->proto_data; struct jabber_cache_entry *entry = g_new0( struct jabber_cache_entry, 1 ); - char *id; + md5_state_t id_hash; + md5_byte_t id_sum[16]; + char *id, *asc_hash; - id = g_strdup_printf( "%s%05x", jd->cached_id_prefix, ( next_id++ ) & 0xfffff ); + next_id ++; + + id_hash = jd->cached_id_prefix; + md5_append( &id_hash, (md5_byte_t*) &next_id, sizeof( next_id ) ); + md5_finish( &id_hash, id_sum ); + asc_hash = base64_encode( id_sum, 12 ); + + id = g_strdup_printf( "%s%s", JABBER_CACHED_ID, asc_hash ); xt_add_attr( node, "id", id ); g_free( id ); + g_free( asc_hash ); entry->node = node; entry->func = func; @@ -183,7 +195,7 @@ xt_status jabber_cache_handle_packet( struct im_connection *ic, struct xt_node * char *s; if( ( s = xt_find_attr( node, "id" ) ) == NULL || - strncmp( s, jd->cached_id_prefix, strlen( jd->cached_id_prefix ) ) != 0 ) + strncmp( s, JABBER_CACHED_ID, strlen( JABBER_CACHED_ID ) ) != 0 ) { /* Silently ignore it, without an ID (or a non-cache ID) we don't know how to handle the packet and we @@ -195,8 +207,14 @@ xt_status jabber_cache_handle_packet( struct im_connection *ic, struct xt_node * if( entry == NULL ) { + /* + There's no longer an easy way to see if we generated this + one or someone else, and there's a ten-minute timeout anyway, + so meh. + imcb_log( ic, "Warning: Received %s-%s packet with unknown/expired ID %s!", node->name, xt_find_attr( node, "type" ) ? : "(no type)", s ); + */ } else if( entry->func ) { -- cgit v1.2.3 From dfbb0563ac250c65f74b7bb3f49ca8d2ccc9e9c8 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Tue, 24 Jun 2008 10:01:29 +0100 Subject: Never use yahoo_close() directly, always use yahoo_logoff(). --- protocols/yahoo/yahoo.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'protocols') diff --git a/protocols/yahoo/yahoo.c b/protocols/yahoo/yahoo.c index c84685e9..197d76a1 100644 --- a/protocols/yahoo/yahoo.c +++ b/protocols/yahoo/yahoo.c @@ -162,10 +162,7 @@ static void byahoo_logout( struct im_connection *ic ) } g_slist_free( yd->buddygroups ); - if( yd->logged_in ) - yahoo_logoff( yd->y2_id ); - else - yahoo_close( yd->y2_id ); + yahoo_logoff( yd->y2_id ); g_free( yd ); } -- cgit v1.2.3 From 1145964911d0d7dd5145de6f7b9d4ed8aeeacd79 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 29 Jun 2008 12:11:50 +0100 Subject: Fixed two memory leaks in the MSN module. --- protocols/msn/ns.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'protocols') diff --git a/protocols/msn/ns.c b/protocols/msn/ns.c index ffaa90a7..fe48f96d 100644 --- a/protocols/msn/ns.c +++ b/protocols/msn/ns.c @@ -277,11 +277,25 @@ static int msn_ns_command( gpointer data, char **cmd, int num_parts ) { if( num_parts == 5 ) { - md->buddycount = atoi( cmd[3] ); - md->groupcount = atoi( cmd[4] ); - if( md->groupcount > 0 ) + int i, groupcount; + + groupcount = atoi( cmd[4] ); + if( groupcount > 0 ) + { + /* valgrind says this is leaking memory, I'm guessing + that this happens during server redirects. */ + if( md->grouplist ) + { + for( i = 0; i < md->groupcount; i ++ ) + g_free( md->grouplist[i] ); + g_free( md->grouplist ); + } + + md->groupcount = groupcount; md->grouplist = g_new0( char *, md->groupcount ); + } + md->buddycount = atoi( cmd[3] ); if( !*cmd[3] || md->buddycount == 0 ) msn_logged_in( ic ); } @@ -664,6 +678,9 @@ static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int { imcb_log( ic, "INBOX contains %s new messages, plus %s messages in other folders.", inbox, folders ); } + + g_free( inbox ); + g_free( folders ); } else if( g_strncasecmp( ct, "text/x-msmsgsemailnotification", 30 ) == 0 ) { -- cgit v1.2.3 From 718e05f842c1af043eb4efded8b0afe429377f70 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Tue, 29 Jul 2008 00:44:58 +0100 Subject: ext_yahoo_error() shouldn't close the connection if the error is fatal, the caller will do it already. --- protocols/yahoo/yahoo.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'protocols') diff --git a/protocols/yahoo/yahoo.c b/protocols/yahoo/yahoo.c index 197d76a1..8d9e95d8 100644 --- a/protocols/yahoo/yahoo.c +++ b/protocols/yahoo/yahoo.c @@ -664,9 +664,6 @@ void ext_yahoo_error( int id, const char *err, int fatal, int num ) struct im_connection *ic = byahoo_get_ic_by_id( id ); imcb_error( ic, "%s", err ); - - if( fatal ) - imc_logout( ic, TRUE ); } /* TODO: Clear up the mess of inp and d structures */ -- cgit v1.2.3