From 88d2208221b5128c89d65a6539c2cbcbc1fdba6e Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 24 Aug 2008 17:45:40 +0100 Subject: Now really fixing #429 by including unistd.h (which defines F_OK). --- storage_xml.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'storage_xml.c') diff --git a/storage_xml.c b/storage_xml.c index 240206f1..8b205c5a 100644 --- a/storage_xml.c +++ b/storage_xml.c @@ -30,8 +30,11 @@ #include "md5.h" #include -#if !GLIB_CHECK_VERSION(2,8,0) +#if GLIB_CHECK_VERSION(2,8,0) +#include +#else /* GLib < 2.8.0 doesn't have g_access, so just use the system access(). */ +#include #define g_access access #endif -- cgit v1.2.3 From 1917a1ec17dde7c159af5ec65d6455c3348bb250 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 30 Aug 2008 20:43:38 +0100 Subject: Added support for loading chatroom data from user .xml files. --- storage_xml.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'storage_xml.c') diff --git a/storage_xml.c b/storage_xml.c index 8b205c5a..d8c5ffb7 100644 --- a/storage_xml.c +++ b/storage_xml.c @@ -28,7 +28,6 @@ #include "base64.h" #include "arc.h" #include "md5.h" -#include #if GLIB_CHECK_VERSION(2,8,0) #include @@ -54,6 +53,8 @@ struct xml_parsedata irc_t *irc; char *current_setting; account_t *current_account; + struct chat *current_chat; + set_t **current_set_head; char *given_nick; char *given_pass; xml_pass_st pass_st; @@ -172,7 +173,16 @@ static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_na } if( ( setting = xml_attr( attr_names, attr_values, "name" ) ) ) + { + if( xd->current_chat != NULL ) + xd->current_set_head = &xd->current_chat->set; + else if( xd->current_account != NULL ) + xd->current_set_head = &xd->current_account->set; + else + xd->current_set_head = &xd->irc->set; + xd->current_setting = g_strdup( setting ); + } else g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, "Missing attributes for %s element", element_name ); @@ -194,6 +204,23 @@ static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_na "Missing attributes for %s element", element_name ); } } + else if( g_strcasecmp( element_name, "chat" ) == 0 ) + { + char *handle, *channel; + + handle = xml_attr( attr_names, attr_values, "handle" ); + channel = xml_attr( attr_names, attr_values, "channel" ); + + if( xd->current_account && handle && channel ) + { + xd->current_chat = chat_add( xd->irc, xd->current_account, handle, channel ); + } + else + { + g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, + "Missing attributes for %s element", element_name ); + } + } else { g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT, @@ -214,13 +241,16 @@ static void xml_end_element( GMarkupParseContext *ctx, const gchar *element_name { xd->current_account = NULL; } + else if( g_strcasecmp( element_name, "chat" ) == 0 ) + { + xd->current_chat = NULL; + } } static void xml_text( GMarkupParseContext *ctx, const gchar *text_orig, gsize text_len, gpointer data, GError **error ) { char text[text_len+1]; struct xml_parsedata *xd = data; - irc_t *irc = xd->irc; strncpy( text, text_orig, text_len ); text[text_len] = 0; @@ -233,8 +263,7 @@ static void xml_text( GMarkupParseContext *ctx, const gchar *text_orig, gsize te } else if( g_strcasecmp( g_markup_parse_context_get_element( ctx ), "setting" ) == 0 && xd->current_setting ) { - set_setstr( xd->current_account ? &xd->current_account->set : &irc->set, - xd->current_setting, (char*) text ); + set_setstr( xd->current_set_head, xd->current_setting, (char*) text ); g_free( xd->current_setting ); xd->current_setting = NULL; } -- cgit v1.2.3 From b84800d89604dee6fd837a2b8ab549346607e774 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 30 Aug 2008 22:30:13 +0100 Subject: Support for saving the chatroom list. Also removed the hack that was used to not save non-existent settings now that those simply aren't possible anymore. --- storage_xml.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'storage_xml.c') diff --git a/storage_xml.c b/storage_xml.c index d8c5ffb7..240bb589 100644 --- a/storage_xml.c +++ b/storage_xml.c @@ -437,7 +437,7 @@ static storage_status_t xml_save( irc_t *irc, int overwrite ) g_free( pass_buf ); for( set = irc->set; set; set = set->next ) - if( set->value && set->def ) + if( set->value ) if( !xml_printf( fd, 1, "%s\n", set->key, set->value ) ) goto write_error; @@ -446,6 +446,7 @@ static storage_status_t xml_save( irc_t *irc, int overwrite ) unsigned char *pass_cr; char *pass_b64; int pass_len; + struct chat *c; pass_len = arc_encode( acc->pass, strlen( acc->pass ), (unsigned char**) &pass_cr, irc->password, 12 ); pass_b64 = base64_encode( pass_cr, pass_len ); @@ -464,7 +465,7 @@ static storage_status_t xml_save( irc_t *irc, int overwrite ) goto write_error; for( set = acc->set; set; set = set->next ) - if( set->value && set->def && !( set->flags & ACC_SET_NOSAVE ) ) + if( set->value && !( set->flags & ACC_SET_NOSAVE ) ) if( !xml_printf( fd, 2, "%s\n", set->key, set->value ) ) goto write_error; @@ -478,6 +479,25 @@ static storage_status_t xml_save( irc_t *irc, int overwrite ) if( g_hash_table_find( acc->nicks, xml_save_nick, & fd ) ) goto write_error; + for( c = irc->chatrooms; c; c = c->next ) + { + if( c->acc != acc ) + continue; + + if( !xml_printf( fd, 2, "\n", + c->handle, c->channel, "room" ) ) + goto write_error; + + for( set = c->set; set; set = set->next ) + if( set->value && !( set->flags & ACC_SET_NOSAVE ) ) + if( !xml_printf( fd, 3, "%s\n", + set->key, set->value ) ) + goto write_error; + + if( !xml_printf( fd, 2, "\n" ) ) + goto write_error; + } + if( !xml_printf( fd, 1, "\n" ) ) goto write_error; } -- cgit v1.2.3 From 3183c21afa7700ebc4dac02367653d1398a5b14a Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 6 Sep 2008 23:59:32 +0100 Subject: Completely reviewed all uses of irc->password, irc_setpass() and USTATUS_IDENTIFIED after another account overwriting vulnerability was found by Tero Marttila. --- storage_xml.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) (limited to 'storage_xml.c') diff --git a/storage_xml.c b/storage_xml.c index 8b205c5a..bd0c1953 100644 --- a/storage_xml.c +++ b/storage_xml.c @@ -258,7 +258,7 @@ static void xml_init( void ) log_message( LOGLVL_WARNING, "Permission problem: Can't read/write from/to `%s'.", global.conf->configdir ); } -static storage_status_t xml_load_real( const char *my_nick, const char *password, irc_t *irc, xml_pass_st action ) +static storage_status_t xml_load_real( irc_t *irc, const char *my_nick, const char *password, xml_pass_st action ) { GMarkupParseContext *ctx; struct xml_parsedata *xd; @@ -266,9 +266,6 @@ static storage_status_t xml_load_real( const char *my_nick, const char *password GError *gerr = NULL; int fd, st; - if( irc && irc->status & USTATUS_IDENTIFIED ) - return( 1 ); - xd = g_new0( struct xml_parsedata, 1 ); xd->irc = irc; xd->given_nick = g_strdup( my_nick ); @@ -320,21 +317,19 @@ static storage_status_t xml_load_real( const char *my_nick, const char *password if( action == XML_PASS_CHECK_ONLY ) return STORAGE_OK; - irc->status |= USTATUS_IDENTIFIED; - return STORAGE_OK; } -static storage_status_t xml_load( const char *my_nick, const char *password, irc_t *irc ) +static storage_status_t xml_load( irc_t *irc, const char *password ) { - return xml_load_real( my_nick, password, irc, XML_PASS_UNKNOWN ); + return xml_load_real( irc, irc->nick, password, XML_PASS_UNKNOWN ); } static storage_status_t xml_check_pass( const char *my_nick, const char *password ) { /* This is a little bit risky because we have to pass NULL for the irc_t argument. This *should* be fine, if I didn't miss anything... */ - return xml_load_real( my_nick, password, NULL, XML_PASS_CHECK_ONLY ); + return xml_load_real( NULL, my_nick, password, XML_PASS_CHECK_ONLY ); } static int xml_printf( int fd, int indent, char *fmt, ... ) @@ -370,12 +365,6 @@ static storage_status_t xml_save( irc_t *irc, int overwrite ) md5_byte_t pass_md5[21]; md5_state_t md5_state; - if( irc->password == NULL ) - { - irc_usermsg( irc, "Please register yourself if you want to save your settings." ); - return STORAGE_OTHER_ERROR; - } - path2 = g_strdup( irc->nick ); nick_lc( path2 ); g_snprintf( path, sizeof( path ) - 2, "%s%s%s", global.conf->configdir, path2, ".xml" ); -- cgit v1.2.3 From 15d146925d949882037c60cab12abcbee6651fab Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 7 Sep 2008 00:10:47 +0100 Subject: Really removing the gstdio.h include now to fully fix GLib 2.4 compatibility. --- storage_xml.c | 1 - 1 file changed, 1 deletion(-) (limited to 'storage_xml.c') diff --git a/storage_xml.c b/storage_xml.c index bd0c1953..d3d0f6d6 100644 --- a/storage_xml.c +++ b/storage_xml.c @@ -28,7 +28,6 @@ #include "base64.h" #include "arc.h" #include "md5.h" -#include #if GLIB_CHECK_VERSION(2,8,0) #include -- cgit v1.2.3 From b75acf6367400ff88428618719cefbbee648b0cb Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Thu, 22 Oct 2009 22:55:23 +0100 Subject: Don't include chat.h from bitlbee.h. make install-dev doesn't install chat.h and it shouldn't ... but things broke because bitlbee.h includes it. Fixes #534. --- storage_xml.c | 1 + 1 file changed, 1 insertion(+) (limited to 'storage_xml.c') diff --git a/storage_xml.c b/storage_xml.c index b78c3661..b6745c75 100644 --- a/storage_xml.c +++ b/storage_xml.c @@ -28,6 +28,7 @@ #include "base64.h" #include "arc.h" #include "md5.h" +#include "chat.h" #if GLIB_CHECK_VERSION(2,8,0) #include -- cgit v1.2.3