[a312b6b] | 1 | /********************************************************************\ |
---|
| 2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
| 3 | * * |
---|
[a338faa] | 4 | * Copyright 2002-2012 Wilmer van der Gaast and others * |
---|
[a312b6b] | 5 | \********************************************************************/ |
---|
| 6 | |
---|
| 7 | /* Storage backend that uses an XMLish format for all data. */ |
---|
| 8 | |
---|
| 9 | /* |
---|
| 10 | This program is free software; you can redistribute it and/or modify |
---|
| 11 | it under the terms of the GNU General Public License as published by |
---|
| 12 | the Free Software Foundation; either version 2 of the License, or |
---|
| 13 | (at your option) any later version. |
---|
| 14 | |
---|
| 15 | This program is distributed in the hope that it will be useful, |
---|
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 18 | GNU General Public License for more details. |
---|
| 19 | |
---|
| 20 | You should have received a copy of the GNU General Public License with |
---|
| 21 | the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; |
---|
| 22 | if not, write to the Free Software Foundation, Inc., 59 Temple Place, |
---|
| 23 | Suite 330, Boston, MA 02111-1307 USA |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #define BITLBEE_CORE |
---|
| 27 | #include "bitlbee.h" |
---|
[6e1fed7] | 28 | #include "base64.h" |
---|
[a7b5925] | 29 | #include "arc.h" |
---|
[d28f3b35] | 30 | #include "md5.h" |
---|
[a338faa] | 31 | #include "xmltree.h" |
---|
[a312b6b] | 32 | |
---|
[88d2208] | 33 | #include <glib/gstdio.h> |
---|
[47b571d] | 34 | |
---|
[c121f89] | 35 | typedef enum |
---|
| 36 | { |
---|
| 37 | XML_PASS_CHECK_ONLY = -1, |
---|
| 38 | XML_PASS_UNKNOWN = 0, |
---|
[c9f0c79] | 39 | XML_PASS_WRONG, |
---|
[c121f89] | 40 | XML_PASS_OK |
---|
| 41 | } xml_pass_st; |
---|
| 42 | |
---|
[c9f0c79] | 43 | /* To make it easier later when extending the format: */ |
---|
[a338faa] | 44 | #define XML_FORMAT_VERSION "1" |
---|
[c121f89] | 45 | |
---|
[a312b6b] | 46 | struct xml_parsedata |
---|
| 47 | { |
---|
| 48 | irc_t *irc; |
---|
[00f1e93] | 49 | char given_nick[MAX_NICK_LENGTH+1]; |
---|
[c121f89] | 50 | char *given_pass; |
---|
[a312b6b] | 51 | }; |
---|
| 52 | |
---|
[00f1e93] | 53 | static void xml_init( void ) |
---|
[c121f89] | 54 | { |
---|
[00f1e93] | 55 | if( g_access( global.conf->configdir, F_OK ) != 0 ) |
---|
| 56 | log_message( LOGLVL_WARNING, "The configuration directory `%s' does not exist. Configuration won't be saved.", global.conf->configdir ); |
---|
| 57 | else if( g_access( global.conf->configdir, F_OK ) != 0 || |
---|
| 58 | g_access( global.conf->configdir, W_OK ) != 0 ) |
---|
| 59 | log_message( LOGLVL_WARNING, "Permission problem: Can't read/write from/to `%s'.", global.conf->configdir ); |
---|
[c121f89] | 60 | } |
---|
| 61 | |
---|
[00f1e93] | 62 | static void handle_settings( struct xt_node *node, set_t **head ) |
---|
[a312b6b] | 63 | { |
---|
[00f1e93] | 64 | struct xt_node *c; |
---|
[a312b6b] | 65 | |
---|
[00f1e93] | 66 | for( c = node->children; ( c = xt_find_node( c, "setting" ) ); c = c->next ) |
---|
[a312b6b] | 67 | { |
---|
[00f1e93] | 68 | char *name = xt_find_attr( c, "name" ); |
---|
[a312b6b] | 69 | |
---|
[15581c1] | 70 | if( !name ) |
---|
| 71 | continue; |
---|
[a312b6b] | 72 | |
---|
[00f1e93] | 73 | if( strcmp( node->name, "account" ) == 0 ) |
---|
[6e1fed7] | 74 | { |
---|
[00f1e93] | 75 | set_t *s = set_find( head, name ); |
---|
| 76 | if( s && ( s->flags & ACC_SET_ONLINE_ONLY ) ) |
---|
| 77 | continue; /* U can't touch this! */ |
---|
[6e1fed7] | 78 | } |
---|
[00f1e93] | 79 | set_setstr( head, name, c->text ); |
---|
[a312b6b] | 80 | } |
---|
| 81 | } |
---|
| 82 | |
---|
[00f1e93] | 83 | static xt_status handle_account( struct xt_node *node, gpointer data ) |
---|
[a312b6b] | 84 | { |
---|
[5898ef8] | 85 | struct xml_parsedata *xd = data; |
---|
[00f1e93] | 86 | char *protocol, *handle, *server, *password = NULL, *autoconnect, *tag; |
---|
| 87 | char *pass_b64 = NULL; |
---|
| 88 | unsigned char *pass_cr = NULL; |
---|
| 89 | int pass_len; |
---|
| 90 | struct prpl *prpl = NULL; |
---|
| 91 | account_t *acc; |
---|
| 92 | struct xt_node *c; |
---|
[5898ef8] | 93 | |
---|
[00f1e93] | 94 | handle = xt_find_attr( node, "handle" ); |
---|
| 95 | pass_b64 = xt_find_attr( node, "password" ); |
---|
| 96 | server = xt_find_attr( node, "server" ); |
---|
| 97 | autoconnect = xt_find_attr( node, "autoconnect" ); |
---|
| 98 | tag = xt_find_attr( node, "tag" ); |
---|
| 99 | |
---|
| 100 | protocol = xt_find_attr( node, "protocol" ); |
---|
| 101 | if( protocol ) |
---|
| 102 | prpl = find_protocol( protocol ); |
---|
| 103 | |
---|
| 104 | if( !handle || !pass_b64 || !protocol || !prpl ) |
---|
| 105 | return XT_ABORT; |
---|
| 106 | else if( ( pass_len = base64_decode( pass_b64, (unsigned char**) &pass_cr ) ) && |
---|
| 107 | arc_decode( pass_cr, pass_len, &password, xd->given_pass ) >= 0 ) |
---|
[a312b6b] | 108 | { |
---|
[00f1e93] | 109 | acc = account_add( xd->irc->b, prpl, handle, password ); |
---|
| 110 | if( server ) |
---|
| 111 | set_setstr( &acc->set, "server", server ); |
---|
| 112 | if( autoconnect ) |
---|
| 113 | set_setstr( &acc->set, "auto_connect", autoconnect ); |
---|
| 114 | if( tag ) |
---|
| 115 | set_setstr( &acc->set, "tag", tag ); |
---|
[a312b6b] | 116 | } |
---|
[00f1e93] | 117 | else |
---|
| 118 | return XT_ABORT; |
---|
| 119 | |
---|
| 120 | g_free( pass_cr ); |
---|
| 121 | g_free( password ); |
---|
| 122 | |
---|
| 123 | handle_settings( node, &acc->set ); |
---|
| 124 | |
---|
| 125 | for( c = node->children; ( c = xt_find_node( c, "buddy" ) ); c = c->next ) |
---|
[a312b6b] | 126 | { |
---|
[c121f89] | 127 | char *handle, *nick; |
---|
| 128 | |
---|
[00f1e93] | 129 | handle = xt_find_attr( c, "handle" ); |
---|
| 130 | nick = xt_find_attr( c, "nick" ); |
---|
[c121f89] | 131 | |
---|
[00f1e93] | 132 | if( handle && nick ) |
---|
| 133 | nick_set_raw( acc, handle, nick ); |
---|
[c121f89] | 134 | else |
---|
[00f1e93] | 135 | return XT_ABORT; |
---|
| 136 | } |
---|
| 137 | return XT_HANDLED; |
---|
[a312b6b] | 138 | } |
---|
| 139 | |
---|
[00f1e93] | 140 | static xt_status handle_channel( struct xt_node *node, gpointer data ) |
---|
[a312b6b] | 141 | { |
---|
[5898ef8] | 142 | struct xml_parsedata *xd = data; |
---|
[00f1e93] | 143 | irc_channel_t *ic; |
---|
| 144 | char *name, *type; |
---|
[5898ef8] | 145 | |
---|
[00f1e93] | 146 | name = xt_find_attr( node, "name" ); |
---|
| 147 | type = xt_find_attr( node, "type" ); |
---|
[a312b6b] | 148 | |
---|
[00f1e93] | 149 | if( !name || !type ) |
---|
| 150 | return XT_ABORT; |
---|
[8320a7a] | 151 | |
---|
[00f1e93] | 152 | /* The channel may exist already, for example if it's &bitlbee. |
---|
| 153 | Also, it's possible that the user just reconnected and the |
---|
| 154 | IRC client already rejoined all channels it was in. They |
---|
| 155 | should still get the right settings. */ |
---|
| 156 | if( ( ic = irc_channel_by_name( xd->irc, name ) ) || |
---|
| 157 | ( ic = irc_channel_new( xd->irc, name ) ) ) |
---|
| 158 | set_setstr( &ic->set, "type", type ); |
---|
| 159 | |
---|
| 160 | handle_settings( node, &ic->set ); |
---|
| 161 | |
---|
| 162 | return XT_HANDLED; |
---|
[a312b6b] | 163 | } |
---|
| 164 | |
---|
[00f1e93] | 165 | static const struct xt_handler_entry handlers[] = { |
---|
| 166 | { "account", "user", handle_account, }, |
---|
| 167 | { "channel", "user", handle_channel, }, |
---|
| 168 | { NULL, NULL, NULL, }, |
---|
[a312b6b] | 169 | }; |
---|
| 170 | |
---|
[3183c21] | 171 | static storage_status_t xml_load_real( irc_t *irc, const char *my_nick, const char *password, xml_pass_st action ) |
---|
[a312b6b] | 172 | { |
---|
[00f1e93] | 173 | struct xml_parsedata xd[1]; |
---|
[15581c1] | 174 | char *fn, buf[2048]; |
---|
[c121f89] | 175 | int fd, st; |
---|
[aed00f8] | 176 | struct xt_parser *xp = NULL; |
---|
[00f1e93] | 177 | struct xt_node *node; |
---|
| 178 | storage_status_t ret = STORAGE_OTHER_ERROR; |
---|
[a312b6b] | 179 | |
---|
[c121f89] | 180 | xd->irc = irc; |
---|
[00f1e93] | 181 | strncpy( xd->given_nick, my_nick, MAX_NICK_LENGTH ); |
---|
| 182 | xd->given_nick[MAX_NICK_LENGTH] = '\0'; |
---|
[e277e80] | 183 | nick_lc( NULL, xd->given_nick ); |
---|
[dd95ce4] | 184 | xd->given_pass = (char*) password; |
---|
[a312b6b] | 185 | |
---|
[00f1e93] | 186 | fn = g_strconcat( global.conf->configdir, xd->given_nick, ".xml", NULL ); |
---|
[c121f89] | 187 | if( ( fd = open( fn, O_RDONLY ) ) < 0 ) |
---|
[a312b6b] | 188 | { |
---|
[00f1e93] | 189 | ret = STORAGE_NO_SUCH_USER; |
---|
| 190 | goto error; |
---|
[a312b6b] | 191 | } |
---|
| 192 | |
---|
[00f1e93] | 193 | xp = xt_new( handlers, xd ); |
---|
[c121f89] | 194 | while( ( st = read( fd, buf, sizeof( buf ) ) ) > 0 ) |
---|
[a312b6b] | 195 | { |
---|
[00f1e93] | 196 | st = xt_feed( xp, buf, st ); |
---|
| 197 | if( st != 1 ) |
---|
| 198 | break; |
---|
| 199 | } |
---|
| 200 | close( fd ); |
---|
| 201 | if( st != 0 ) |
---|
| 202 | goto error; |
---|
| 203 | |
---|
| 204 | node = xp->root; |
---|
| 205 | if( node == NULL || node->next != NULL || strcmp( node->name, "user" ) != 0 ) |
---|
| 206 | goto error; |
---|
| 207 | |
---|
| 208 | { |
---|
| 209 | char *nick = xt_find_attr( node, "nick" ); |
---|
| 210 | char *pass = xt_find_attr( node, "password" ); |
---|
| 211 | |
---|
| 212 | if( !nick || !pass ) |
---|
[c121f89] | 213 | { |
---|
[00f1e93] | 214 | goto error; |
---|
| 215 | } |
---|
| 216 | else if( ( st = md5_verify_password( xd->given_pass, pass ) ) != 0 ) |
---|
[c121f89] | 217 | { |
---|
[00f1e93] | 218 | ret = STORAGE_INVALID_PASSWORD; |
---|
| 219 | goto error; |
---|
[c121f89] | 220 | } |
---|
[a312b6b] | 221 | } |
---|
[c121f89] | 222 | |
---|
[84e9cea] | 223 | if( action == XML_PASS_CHECK_ONLY ) |
---|
[00f1e93] | 224 | { |
---|
| 225 | ret = STORAGE_OK; |
---|
| 226 | goto error; |
---|
| 227 | } |
---|
[84e9cea] | 228 | |
---|
[00f1e93] | 229 | /* DO NOT call xt_handle() before verifying the password! */ |
---|
[15581c1] | 230 | if( xt_handle( xp, NULL, 1 ) == XT_HANDLED ) |
---|
[00f1e93] | 231 | ret = STORAGE_OK; |
---|
[84e9cea] | 232 | |
---|
[00f1e93] | 233 | handle_settings( node, &xd->irc->b->set ); |
---|
| 234 | |
---|
| 235 | error: |
---|
[15581c1] | 236 | xt_free( xp ); |
---|
| 237 | g_free( fn ); |
---|
[00f1e93] | 238 | return ret; |
---|
[a312b6b] | 239 | } |
---|
| 240 | |
---|
[3183c21] | 241 | static storage_status_t xml_load( irc_t *irc, const char *password ) |
---|
[84e9cea] | 242 | { |
---|
[1f92a58] | 243 | return xml_load_real( irc, irc->user->nick, password, XML_PASS_UNKNOWN ); |
---|
[84e9cea] | 244 | } |
---|
| 245 | |
---|
| 246 | static storage_status_t xml_check_pass( const char *my_nick, const char *password ) |
---|
| 247 | { |
---|
[3183c21] | 248 | return xml_load_real( NULL, my_nick, password, XML_PASS_CHECK_ONLY ); |
---|
[84e9cea] | 249 | } |
---|
| 250 | |
---|
[5898ef8] | 251 | |
---|
[d219296] | 252 | static gboolean xml_generate_nick( gpointer key, gpointer value, gpointer data ); |
---|
[e222c36] | 253 | static void xml_generate_settings( struct xt_node *cur, set_t **head ); |
---|
[5b52a48] | 254 | |
---|
[a338faa] | 255 | struct xt_node *xml_generate( irc_t *irc ) |
---|
[a312b6b] | 256 | { |
---|
[a338faa] | 257 | char *pass_buf = NULL; |
---|
[5898ef8] | 258 | account_t *acc; |
---|
[6e1fed7] | 259 | md5_byte_t pass_md5[21]; |
---|
[ece2cd2] | 260 | md5_state_t md5_state; |
---|
[547ea68] | 261 | GSList *l; |
---|
[a338faa] | 262 | struct xt_node *root, *cur; |
---|
[5898ef8] | 263 | |
---|
[6e1fed7] | 264 | /* Generate a salted md5sum of the password. Use 5 bytes for the salt |
---|
| 265 | (to prevent dictionary lookups of passwords) to end up with a 21- |
---|
| 266 | byte password hash, more convenient for base64 encoding. */ |
---|
[1719464] | 267 | random_bytes( pass_md5 + 16, 5 ); |
---|
[ece2cd2] | 268 | md5_init( &md5_state ); |
---|
| 269 | md5_append( &md5_state, (md5_byte_t*) irc->password, strlen( irc->password ) ); |
---|
[6e1fed7] | 270 | md5_append( &md5_state, pass_md5 + 16, 5 ); /* Add the salt. */ |
---|
[ece2cd2] | 271 | md5_finish( &md5_state, pass_md5 ); |
---|
[6e1fed7] | 272 | /* Save the hash in base64-encoded form. */ |
---|
[3b6eadc] | 273 | pass_buf = base64_encode( pass_md5, 21 ); |
---|
[ece2cd2] | 274 | |
---|
[a338faa] | 275 | root = cur = xt_new_node( "user", NULL, NULL ); |
---|
| 276 | xt_add_attr( cur, "nick", irc->user->nick ); |
---|
| 277 | xt_add_attr( cur, "password", pass_buf ); |
---|
| 278 | xt_add_attr( cur, "version", XML_FORMAT_VERSION ); |
---|
[5898ef8] | 279 | |
---|
[6e1fed7] | 280 | g_free( pass_buf ); |
---|
| 281 | |
---|
[e222c36] | 282 | xml_generate_settings( cur, &irc->b->set ); |
---|
[5898ef8] | 283 | |
---|
[1f92a58] | 284 | for( acc = irc->b->accounts; acc; acc = acc->next ) |
---|
[5898ef8] | 285 | { |
---|
[a7b5925] | 286 | unsigned char *pass_cr; |
---|
[3b6eadc] | 287 | char *pass_b64; |
---|
[6e1fed7] | 288 | int pass_len; |
---|
| 289 | |
---|
[ddcf491f] | 290 | pass_len = arc_encode( acc->pass, strlen( acc->pass ), (unsigned char**) &pass_cr, irc->password, 12 ); |
---|
[a7b5925] | 291 | pass_b64 = base64_encode( pass_cr, pass_len ); |
---|
| 292 | g_free( pass_cr ); |
---|
[6e1fed7] | 293 | |
---|
[a338faa] | 294 | cur = xt_new_node( "account", NULL, NULL ); |
---|
| 295 | xt_add_attr( cur, "protocol", acc->prpl->name ); |
---|
| 296 | xt_add_attr( cur, "handle", acc->user ); |
---|
| 297 | xt_add_attr( cur, "password", pass_b64 ); |
---|
| 298 | xt_add_attr( cur, "autoconnect", acc->auto_connect ? "true" : "false" ); |
---|
| 299 | xt_add_attr( cur, "tag", acc->tag ); |
---|
| 300 | if( acc->server && acc->server[0] ) |
---|
| 301 | xt_add_attr( cur, "server", acc->server ); |
---|
[5898ef8] | 302 | |
---|
[a338faa] | 303 | g_free( pass_b64 ); |
---|
[5100caa] | 304 | |
---|
[5b52a48] | 305 | /* This probably looks pretty strange. g_hash_table_foreach |
---|
| 306 | is quite a PITA already (but it can't get much better in |
---|
[e31e5b8] | 307 | C without using #define, I'm afraid), and it |
---|
[5b52a48] | 308 | doesn't seem to be possible to abort the foreach on write |
---|
| 309 | errors, so instead let's use the _find function and |
---|
| 310 | return TRUE on write errors. Which means, if we found |
---|
| 311 | something, there was an error. :-) */ |
---|
[d219296] | 312 | g_hash_table_find( acc->nicks, xml_generate_nick, cur ); |
---|
[5898ef8] | 313 | |
---|
[e222c36] | 314 | xml_generate_settings( cur, &acc->set ); |
---|
| 315 | |
---|
[a338faa] | 316 | xt_add_child( root, cur ); |
---|
[5898ef8] | 317 | } |
---|
| 318 | |
---|
[547ea68] | 319 | for( l = irc->channels; l; l = l->next ) |
---|
| 320 | { |
---|
| 321 | irc_channel_t *ic = l->data; |
---|
| 322 | |
---|
[1c40aa7] | 323 | if( ic->flags & IRC_CHANNEL_TEMP ) |
---|
| 324 | continue; |
---|
| 325 | |
---|
[a338faa] | 326 | cur = xt_new_node( "channel", NULL, NULL ); |
---|
| 327 | xt_add_attr( cur, "name", ic->name ); |
---|
| 328 | xt_add_attr( cur, "type", set_getstr( &ic->set, "type" ) ); |
---|
[547ea68] | 329 | |
---|
[e222c36] | 330 | xml_generate_settings( cur, &ic->set ); |
---|
[547ea68] | 331 | |
---|
[a338faa] | 332 | xt_add_child( root, cur ); |
---|
[547ea68] | 333 | } |
---|
| 334 | |
---|
[a338faa] | 335 | return root; |
---|
| 336 | } |
---|
| 337 | |
---|
[15581c1] | 338 | static gboolean xml_generate_nick( gpointer key, gpointer value, gpointer data ) |
---|
| 339 | { |
---|
| 340 | struct xt_node *node = xt_new_node( "buddy", NULL, NULL ); |
---|
| 341 | xt_add_attr( node, "handle", key ); |
---|
| 342 | xt_add_attr( node, "nick", value ); |
---|
| 343 | xt_add_child( (struct xt_node *) data, node ); |
---|
[5898ef8] | 344 | |
---|
[15581c1] | 345 | return FALSE; |
---|
| 346 | } |
---|
| 347 | |
---|
[e222c36] | 348 | static void xml_generate_settings( struct xt_node *cur, set_t **head ) |
---|
| 349 | { |
---|
| 350 | set_t *set; |
---|
| 351 | |
---|
| 352 | for( set = *head; set; set = set->next ) |
---|
| 353 | if( set->value && !( set->flags & SET_NOSAVE ) ) |
---|
| 354 | { |
---|
| 355 | struct xt_node *xset; |
---|
| 356 | xt_add_child( cur, xset = xt_new_node( "setting", set->value, NULL ) ); |
---|
| 357 | xt_add_attr( xset, "name", set->key ); |
---|
| 358 | } |
---|
| 359 | } |
---|
| 360 | |
---|
[a338faa] | 361 | static storage_status_t xml_save( irc_t *irc, int overwrite ) |
---|
| 362 | { |
---|
[d219296] | 363 | storage_status_t ret = STORAGE_OK; |
---|
| 364 | char path[512], *path2 = NULL, *xml = NULL; |
---|
| 365 | struct xt_node *tree = NULL; |
---|
| 366 | size_t len; |
---|
[a338faa] | 367 | int fd; |
---|
| 368 | |
---|
| 369 | path2 = g_strdup( irc->user->nick ); |
---|
[e277e80] | 370 | nick_lc( NULL, path2 ); |
---|
[d219296] | 371 | g_snprintf( path, sizeof( path ) - 20, "%s%s%s", global.conf->configdir, path2, ".xml" ); |
---|
[a338faa] | 372 | g_free( path2 ); |
---|
| 373 | |
---|
| 374 | if( !overwrite && g_access( path, F_OK ) == 0 ) |
---|
| 375 | return STORAGE_ALREADY_EXISTS; |
---|
| 376 | |
---|
| 377 | strcat( path, ".XXXXXX" ); |
---|
| 378 | if( ( fd = mkstemp( path ) ) < 0 ) |
---|
| 379 | { |
---|
| 380 | irc_rootmsg( irc, "Error while opening configuration file." ); |
---|
| 381 | return STORAGE_OTHER_ERROR; |
---|
[547ea68] | 382 | } |
---|
| 383 | |
---|
[a338faa] | 384 | tree = xml_generate( irc ); |
---|
[222b440] | 385 | xml = xt_to_string_i( tree ); |
---|
[d219296] | 386 | len = strlen( xml ); |
---|
| 387 | if( write( fd, xml, len ) != len || |
---|
| 388 | fsync( fd ) != 0 || /* #559 */ |
---|
| 389 | close( fd ) != 0 ) |
---|
| 390 | goto error; |
---|
[5898ef8] | 391 | |
---|
[f277225] | 392 | path2 = g_strndup( path, strlen( path ) - 7 ); |
---|
[5898ef8] | 393 | if( rename( path, path2 ) != 0 ) |
---|
| 394 | { |
---|
| 395 | g_free( path2 ); |
---|
[d219296] | 396 | goto error; |
---|
[5898ef8] | 397 | } |
---|
| 398 | g_free( path2 ); |
---|
| 399 | |
---|
[d219296] | 400 | goto finish; |
---|
[5898ef8] | 401 | |
---|
[d219296] | 402 | error: |
---|
[e67e513] | 403 | irc_rootmsg( irc, "Write error. Disk full?" ); |
---|
[d219296] | 404 | ret = STORAGE_OTHER_ERROR; |
---|
| 405 | |
---|
| 406 | finish: |
---|
[5898ef8] | 407 | close( fd ); |
---|
[d219296] | 408 | unlink( path ); |
---|
| 409 | g_free( xml ); |
---|
| 410 | xt_free_node( tree ); |
---|
[5898ef8] | 411 | |
---|
[d219296] | 412 | return ret; |
---|
[a312b6b] | 413 | } |
---|
| 414 | |
---|
[5b52a48] | 415 | |
---|
[84e9cea] | 416 | static storage_status_t xml_remove( const char *nick, const char *password ) |
---|
| 417 | { |
---|
[e0f9170] | 418 | char s[512], *lc; |
---|
[84e9cea] | 419 | storage_status_t status; |
---|
| 420 | |
---|
| 421 | status = xml_check_pass( nick, password ); |
---|
| 422 | if( status != STORAGE_OK ) |
---|
| 423 | return status; |
---|
| 424 | |
---|
[e0f9170] | 425 | lc = g_strdup( nick ); |
---|
[e277e80] | 426 | nick_lc( NULL, lc ); |
---|
[e0f9170] | 427 | g_snprintf( s, 511, "%s%s%s", global.conf->configdir, lc, ".xml" ); |
---|
| 428 | g_free( lc ); |
---|
| 429 | |
---|
[84e9cea] | 430 | if( unlink( s ) == -1 ) |
---|
| 431 | return STORAGE_OTHER_ERROR; |
---|
| 432 | |
---|
| 433 | return STORAGE_OK; |
---|
| 434 | } |
---|
| 435 | |
---|
[a312b6b] | 436 | storage_t storage_xml = { |
---|
| 437 | .name = "xml", |
---|
| 438 | .init = xml_init, |
---|
[84e9cea] | 439 | .check_pass = xml_check_pass, |
---|
| 440 | .remove = xml_remove, |
---|
[a312b6b] | 441 | .load = xml_load, |
---|
| 442 | .save = xml_save |
---|
| 443 | }; |
---|