[5ebff60] | 1 | /********************************************************************\ |
---|
[a312b6b] | 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; |
---|
[6f10697] | 22 | if not, write to the Free Software Foundation, Inc., 51 Franklin St., |
---|
| 23 | Fifth Floor, Boston, MA 02110-1301 USA |
---|
[a312b6b] | 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 | |
---|
[5ebff60] | 35 | typedef enum { |
---|
[c121f89] | 36 | XML_PASS_CHECK_ONLY = -1, |
---|
| 37 | XML_PASS_UNKNOWN = 0, |
---|
[c9f0c79] | 38 | XML_PASS_WRONG, |
---|
[c121f89] | 39 | XML_PASS_OK |
---|
| 40 | } xml_pass_st; |
---|
| 41 | |
---|
[c9f0c79] | 42 | /* To make it easier later when extending the format: */ |
---|
[a338faa] | 43 | #define XML_FORMAT_VERSION "1" |
---|
[c121f89] | 44 | |
---|
[5ebff60] | 45 | struct xml_parsedata { |
---|
[a312b6b] | 46 | irc_t *irc; |
---|
[5ebff60] | 47 | char given_nick[MAX_NICK_LENGTH + 1]; |
---|
[c121f89] | 48 | char *given_pass; |
---|
[a312b6b] | 49 | }; |
---|
| 50 | |
---|
[5ebff60] | 51 | static void xml_init(void) |
---|
[c121f89] | 52 | { |
---|
[5ebff60] | 53 | if (g_access(global.conf->configdir, F_OK) != 0) { |
---|
| 54 | log_message(LOGLVL_WARNING, |
---|
| 55 | "The configuration directory `%s' does not exist. Configuration won't be saved.", |
---|
| 56 | 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'.", |
---|
| 60 | global.conf->configdir); |
---|
| 61 | } |
---|
[c121f89] | 62 | } |
---|
| 63 | |
---|
[5ebff60] | 64 | static void handle_settings(struct xt_node *node, set_t **head) |
---|
[a312b6b] | 65 | { |
---|
[00f1e93] | 66 | struct xt_node *c; |
---|
[5ebff60] | 67 | |
---|
| 68 | for (c = node->children; (c = xt_find_node(c, "setting")); c = c->next) { |
---|
| 69 | char *name = xt_find_attr(c, "name"); |
---|
| 70 | |
---|
| 71 | if (!name) { |
---|
[15581c1] | 72 | continue; |
---|
[5ebff60] | 73 | } |
---|
| 74 | |
---|
| 75 | if (strcmp(node->name, "account") == 0) { |
---|
| 76 | set_t *s = set_find(head, name); |
---|
| 77 | if (s && (s->flags & ACC_SET_ONLINE_ONLY)) { |
---|
[00f1e93] | 78 | continue; /* U can't touch this! */ |
---|
[5ebff60] | 79 | } |
---|
[6e1fed7] | 80 | } |
---|
[5ebff60] | 81 | set_setstr(head, name, c->text); |
---|
[a312b6b] | 82 | } |
---|
| 83 | } |
---|
| 84 | |
---|
[5ebff60] | 85 | static xt_status handle_account(struct xt_node *node, gpointer data) |
---|
[a312b6b] | 86 | { |
---|
[5898ef8] | 87 | struct xml_parsedata *xd = data; |
---|
[00f1e93] | 88 | char *protocol, *handle, *server, *password = NULL, *autoconnect, *tag; |
---|
| 89 | char *pass_b64 = NULL; |
---|
| 90 | unsigned char *pass_cr = NULL; |
---|
[1783ab6] | 91 | int pass_len, local = 0; |
---|
[00f1e93] | 92 | struct prpl *prpl = NULL; |
---|
| 93 | account_t *acc; |
---|
| 94 | struct xt_node *c; |
---|
[5ebff60] | 95 | |
---|
| 96 | handle = xt_find_attr(node, "handle"); |
---|
| 97 | pass_b64 = xt_find_attr(node, "password"); |
---|
| 98 | server = xt_find_attr(node, "server"); |
---|
| 99 | autoconnect = xt_find_attr(node, "autoconnect"); |
---|
| 100 | tag = xt_find_attr(node, "tag"); |
---|
| 101 | |
---|
| 102 | protocol = xt_find_attr(node, "protocol"); |
---|
| 103 | if (protocol) { |
---|
| 104 | prpl = find_protocol(protocol); |
---|
[7320610] | 105 | if (!prpl) { |
---|
| 106 | irc_rootmsg(xd->irc, "Error loading user config: Protocol not found: `%s'", protocol); |
---|
| 107 | return XT_ABORT; |
---|
| 108 | } |
---|
[5ebff60] | 109 | local = protocol_account_islocal(protocol); |
---|
[1783ab6] | 110 | } |
---|
[5ebff60] | 111 | |
---|
| 112 | if (!handle || !pass_b64 || !protocol || !prpl) { |
---|
[00f1e93] | 113 | return XT_ABORT; |
---|
[5ebff60] | 114 | } else if ((pass_len = base64_decode(pass_b64, (unsigned char **) &pass_cr)) && |
---|
| 115 | arc_decode(pass_cr, pass_len, &password, xd->given_pass) >= 0) { |
---|
| 116 | acc = account_add(xd->irc->b, prpl, handle, password); |
---|
| 117 | if (server) { |
---|
| 118 | set_setstr(&acc->set, "server", server); |
---|
| 119 | } |
---|
| 120 | if (autoconnect) { |
---|
| 121 | set_setstr(&acc->set, "auto_connect", autoconnect); |
---|
| 122 | } |
---|
| 123 | if (tag) { |
---|
| 124 | set_setstr(&acc->set, "tag", tag); |
---|
| 125 | } |
---|
| 126 | if (local) { |
---|
[1783ab6] | 127 | acc->flags |= ACC_FLAG_LOCAL; |
---|
[5ebff60] | 128 | } |
---|
| 129 | } else { |
---|
[098a75b] | 130 | g_free(pass_cr); |
---|
| 131 | g_free(password); |
---|
[00f1e93] | 132 | return XT_ABORT; |
---|
[5ebff60] | 133 | } |
---|
| 134 | |
---|
| 135 | g_free(pass_cr); |
---|
| 136 | g_free(password); |
---|
| 137 | |
---|
| 138 | handle_settings(node, &acc->set); |
---|
| 139 | |
---|
| 140 | for (c = node->children; (c = xt_find_node(c, "buddy")); c = c->next) { |
---|
[c121f89] | 141 | char *handle, *nick; |
---|
[5ebff60] | 142 | |
---|
| 143 | handle = xt_find_attr(c, "handle"); |
---|
| 144 | nick = xt_find_attr(c, "nick"); |
---|
| 145 | |
---|
| 146 | if (handle && nick) { |
---|
| 147 | nick_set_raw(acc, handle, nick); |
---|
| 148 | } else { |
---|
[00f1e93] | 149 | return XT_ABORT; |
---|
[5ebff60] | 150 | } |
---|
| 151 | } |
---|
[00f1e93] | 152 | return XT_HANDLED; |
---|
[a312b6b] | 153 | } |
---|
| 154 | |
---|
[5ebff60] | 155 | static xt_status handle_channel(struct xt_node *node, gpointer data) |
---|
[a312b6b] | 156 | { |
---|
[5898ef8] | 157 | struct xml_parsedata *xd = data; |
---|
[00f1e93] | 158 | irc_channel_t *ic; |
---|
| 159 | char *name, *type; |
---|
[5ebff60] | 160 | |
---|
| 161 | name = xt_find_attr(node, "name"); |
---|
| 162 | type = xt_find_attr(node, "type"); |
---|
| 163 | |
---|
| 164 | if (!name || !type) { |
---|
[00f1e93] | 165 | return XT_ABORT; |
---|
[5ebff60] | 166 | } |
---|
| 167 | |
---|
[00f1e93] | 168 | /* The channel may exist already, for example if it's &bitlbee. |
---|
| 169 | Also, it's possible that the user just reconnected and the |
---|
| 170 | IRC client already rejoined all channels it was in. They |
---|
| 171 | should still get the right settings. */ |
---|
[5ebff60] | 172 | if ((ic = irc_channel_by_name(xd->irc, name)) || |
---|
| 173 | (ic = irc_channel_new(xd->irc, name))) { |
---|
| 174 | set_setstr(&ic->set, "type", type); |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | handle_settings(node, &ic->set); |
---|
| 178 | |
---|
[00f1e93] | 179 | return XT_HANDLED; |
---|
[a312b6b] | 180 | } |
---|
| 181 | |
---|
[00f1e93] | 182 | static const struct xt_handler_entry handlers[] = { |
---|
| 183 | { "account", "user", handle_account, }, |
---|
| 184 | { "channel", "user", handle_channel, }, |
---|
| 185 | { NULL, NULL, NULL, }, |
---|
[a312b6b] | 186 | }; |
---|
| 187 | |
---|
[5ebff60] | 188 | static storage_status_t xml_load_real(irc_t *irc, const char *my_nick, const char *password, xml_pass_st action) |
---|
[a312b6b] | 189 | { |
---|
[00f1e93] | 190 | struct xml_parsedata xd[1]; |
---|
[15581c1] | 191 | char *fn, buf[2048]; |
---|
[c121f89] | 192 | int fd, st; |
---|
[aed00f8] | 193 | struct xt_parser *xp = NULL; |
---|
[00f1e93] | 194 | struct xt_node *node; |
---|
| 195 | storage_status_t ret = STORAGE_OTHER_ERROR; |
---|
[5ebff60] | 196 | |
---|
[c121f89] | 197 | xd->irc = irc; |
---|
[5ebff60] | 198 | strncpy(xd->given_nick, my_nick, MAX_NICK_LENGTH); |
---|
[00f1e93] | 199 | xd->given_nick[MAX_NICK_LENGTH] = '\0'; |
---|
[5ebff60] | 200 | nick_lc(NULL, xd->given_nick); |
---|
| 201 | xd->given_pass = (char *) password; |
---|
| 202 | |
---|
| 203 | fn = g_strconcat(global.conf->configdir, xd->given_nick, ".xml", NULL); |
---|
| 204 | if ((fd = open(fn, O_RDONLY)) < 0) { |
---|
[7320610] | 205 | if (errno == ENOENT) { |
---|
| 206 | ret = STORAGE_NO_SUCH_USER; |
---|
| 207 | } else { |
---|
| 208 | irc_rootmsg(irc, "Error loading user config: %s", g_strerror(errno)); |
---|
| 209 | } |
---|
[00f1e93] | 210 | goto error; |
---|
[a312b6b] | 211 | } |
---|
[5ebff60] | 212 | |
---|
| 213 | xp = xt_new(handlers, xd); |
---|
| 214 | while ((st = read(fd, buf, sizeof(buf))) > 0) { |
---|
| 215 | st = xt_feed(xp, buf, st); |
---|
| 216 | if (st != 1) { |
---|
[00f1e93] | 217 | break; |
---|
[5ebff60] | 218 | } |
---|
[00f1e93] | 219 | } |
---|
[5ebff60] | 220 | close(fd); |
---|
| 221 | if (st != 0) { |
---|
[00f1e93] | 222 | goto error; |
---|
[5ebff60] | 223 | } |
---|
| 224 | |
---|
[00f1e93] | 225 | node = xp->root; |
---|
[5ebff60] | 226 | if (node == NULL || node->next != NULL || strcmp(node->name, "user") != 0) { |
---|
[00f1e93] | 227 | goto error; |
---|
[5ebff60] | 228 | } |
---|
| 229 | |
---|
[00f1e93] | 230 | { |
---|
[5ebff60] | 231 | char *nick = xt_find_attr(node, "nick"); |
---|
| 232 | char *pass = xt_find_attr(node, "password"); |
---|
| 233 | |
---|
| 234 | if (!nick || !pass) { |
---|
[00f1e93] | 235 | goto error; |
---|
[5ebff60] | 236 | } else if ((st = md5_verify_password(xd->given_pass, pass)) != 0) { |
---|
[00f1e93] | 237 | ret = STORAGE_INVALID_PASSWORD; |
---|
| 238 | goto error; |
---|
[c121f89] | 239 | } |
---|
[a312b6b] | 240 | } |
---|
[5ebff60] | 241 | |
---|
| 242 | if (action == XML_PASS_CHECK_ONLY) { |
---|
[00f1e93] | 243 | ret = STORAGE_OK; |
---|
| 244 | goto error; |
---|
| 245 | } |
---|
[5ebff60] | 246 | |
---|
[00f1e93] | 247 | /* DO NOT call xt_handle() before verifying the password! */ |
---|
[5ebff60] | 248 | if (xt_handle(xp, NULL, 1) == XT_HANDLED) { |
---|
[00f1e93] | 249 | ret = STORAGE_OK; |
---|
[5ebff60] | 250 | } |
---|
| 251 | |
---|
| 252 | handle_settings(node, &xd->irc->b->set); |
---|
| 253 | |
---|
[00f1e93] | 254 | error: |
---|
[5ebff60] | 255 | xt_free(xp); |
---|
| 256 | g_free(fn); |
---|
[00f1e93] | 257 | return ret; |
---|
[a312b6b] | 258 | } |
---|
| 259 | |
---|
[5ebff60] | 260 | static storage_status_t xml_load(irc_t *irc, const char *password) |
---|
[84e9cea] | 261 | { |
---|
[5ebff60] | 262 | return xml_load_real(irc, irc->user->nick, password, XML_PASS_UNKNOWN); |
---|
[84e9cea] | 263 | } |
---|
| 264 | |
---|
[5ebff60] | 265 | static storage_status_t xml_check_pass(const char *my_nick, const char *password) |
---|
[84e9cea] | 266 | { |
---|
[5ebff60] | 267 | return xml_load_real(NULL, my_nick, password, XML_PASS_CHECK_ONLY); |
---|
[84e9cea] | 268 | } |
---|
| 269 | |
---|
[5898ef8] | 270 | |
---|
[5ebff60] | 271 | static void xml_generate_settings(struct xt_node *cur, set_t **head); |
---|
[5b52a48] | 272 | |
---|
[5ebff60] | 273 | struct xt_node *xml_generate(irc_t *irc) |
---|
[a312b6b] | 274 | { |
---|
[a338faa] | 275 | char *pass_buf = NULL; |
---|
[5898ef8] | 276 | account_t *acc; |
---|
[6e1fed7] | 277 | md5_byte_t pass_md5[21]; |
---|
[ece2cd2] | 278 | md5_state_t md5_state; |
---|
[547ea68] | 279 | GSList *l; |
---|
[a338faa] | 280 | struct xt_node *root, *cur; |
---|
[5ebff60] | 281 | |
---|
[6e1fed7] | 282 | /* Generate a salted md5sum of the password. Use 5 bytes for the salt |
---|
| 283 | (to prevent dictionary lookups of passwords) to end up with a 21- |
---|
| 284 | byte password hash, more convenient for base64 encoding. */ |
---|
[5ebff60] | 285 | random_bytes(pass_md5 + 16, 5); |
---|
| 286 | md5_init(&md5_state); |
---|
| 287 | md5_append(&md5_state, (md5_byte_t *) irc->password, strlen(irc->password)); |
---|
| 288 | md5_append(&md5_state, pass_md5 + 16, 5); /* Add the salt. */ |
---|
| 289 | md5_finish(&md5_state, pass_md5); |
---|
[6e1fed7] | 290 | /* Save the hash in base64-encoded form. */ |
---|
[5ebff60] | 291 | pass_buf = base64_encode(pass_md5, 21); |
---|
| 292 | |
---|
| 293 | root = cur = xt_new_node("user", NULL, NULL); |
---|
| 294 | xt_add_attr(cur, "nick", irc->user->nick); |
---|
| 295 | xt_add_attr(cur, "password", pass_buf); |
---|
| 296 | xt_add_attr(cur, "version", XML_FORMAT_VERSION); |
---|
| 297 | |
---|
| 298 | g_free(pass_buf); |
---|
| 299 | |
---|
| 300 | xml_generate_settings(cur, &irc->b->set); |
---|
| 301 | |
---|
| 302 | for (acc = irc->b->accounts; acc; acc = acc->next) { |
---|
[d5c55ac] | 303 | GHashTableIter iter; |
---|
| 304 | gpointer key, value; |
---|
[a7b5925] | 305 | unsigned char *pass_cr; |
---|
[3b6eadc] | 306 | char *pass_b64; |
---|
[6e1fed7] | 307 | int pass_len; |
---|
[5ebff60] | 308 | |
---|
| 309 | pass_len = arc_encode(acc->pass, strlen(acc->pass), (unsigned char **) &pass_cr, irc->password, 12); |
---|
| 310 | pass_b64 = base64_encode(pass_cr, pass_len); |
---|
| 311 | g_free(pass_cr); |
---|
| 312 | |
---|
| 313 | cur = xt_new_node("account", NULL, NULL); |
---|
| 314 | xt_add_attr(cur, "protocol", acc->prpl->name); |
---|
| 315 | xt_add_attr(cur, "handle", acc->user); |
---|
| 316 | xt_add_attr(cur, "password", pass_b64); |
---|
| 317 | xt_add_attr(cur, "autoconnect", acc->auto_connect ? "true" : "false"); |
---|
| 318 | xt_add_attr(cur, "tag", acc->tag); |
---|
| 319 | if (acc->server && acc->server[0]) { |
---|
| 320 | xt_add_attr(cur, "server", acc->server); |
---|
| 321 | } |
---|
| 322 | |
---|
| 323 | g_free(pass_b64); |
---|
| 324 | |
---|
[d5c55ac] | 325 | g_hash_table_iter_init(&iter, acc->nicks); |
---|
| 326 | while (g_hash_table_iter_next(&iter, &key, &value)) { |
---|
| 327 | struct xt_node *node = xt_new_node("buddy", NULL, NULL); |
---|
| 328 | xt_add_attr(node, "handle", key); |
---|
| 329 | xt_add_attr(node, "nick", value); |
---|
| 330 | xt_add_child(cur, node); |
---|
| 331 | } |
---|
[5ebff60] | 332 | |
---|
| 333 | xml_generate_settings(cur, &acc->set); |
---|
| 334 | |
---|
| 335 | xt_add_child(root, cur); |
---|
[5898ef8] | 336 | } |
---|
[5ebff60] | 337 | |
---|
| 338 | for (l = irc->channels; l; l = l->next) { |
---|
[547ea68] | 339 | irc_channel_t *ic = l->data; |
---|
[5ebff60] | 340 | |
---|
| 341 | if (ic->flags & IRC_CHANNEL_TEMP) { |
---|
[1c40aa7] | 342 | continue; |
---|
[5ebff60] | 343 | } |
---|
| 344 | |
---|
| 345 | cur = xt_new_node("channel", NULL, NULL); |
---|
| 346 | xt_add_attr(cur, "name", ic->name); |
---|
| 347 | xt_add_attr(cur, "type", set_getstr(&ic->set, "type")); |
---|
| 348 | |
---|
| 349 | xml_generate_settings(cur, &ic->set); |
---|
| 350 | |
---|
| 351 | xt_add_child(root, cur); |
---|
[547ea68] | 352 | } |
---|
[5ebff60] | 353 | |
---|
[a338faa] | 354 | return root; |
---|
| 355 | } |
---|
| 356 | |
---|
[5ebff60] | 357 | static void xml_generate_settings(struct xt_node *cur, set_t **head) |
---|
[e222c36] | 358 | { |
---|
| 359 | set_t *set; |
---|
[5ebff60] | 360 | |
---|
| 361 | for (set = *head; set; set = set->next) { |
---|
| 362 | if (set->value && !(set->flags & SET_NOSAVE)) { |
---|
[e222c36] | 363 | struct xt_node *xset; |
---|
[5ebff60] | 364 | xt_add_child(cur, xset = xt_new_node("setting", set->value, NULL)); |
---|
| 365 | xt_add_attr(xset, "name", set->key); |
---|
[e222c36] | 366 | } |
---|
[5ebff60] | 367 | } |
---|
[e222c36] | 368 | } |
---|
| 369 | |
---|
[5ebff60] | 370 | static storage_status_t xml_save(irc_t *irc, int overwrite) |
---|
[a338faa] | 371 | { |
---|
[d219296] | 372 | storage_status_t ret = STORAGE_OK; |
---|
| 373 | char path[512], *path2 = NULL, *xml = NULL; |
---|
| 374 | struct xt_node *tree = NULL; |
---|
| 375 | size_t len; |
---|
[a338faa] | 376 | int fd; |
---|
[5ebff60] | 377 | |
---|
| 378 | path2 = g_strdup(irc->user->nick); |
---|
| 379 | nick_lc(NULL, path2); |
---|
| 380 | g_snprintf(path, sizeof(path) - 20, "%s%s%s", global.conf->configdir, path2, ".xml"); |
---|
| 381 | g_free(path2); |
---|
| 382 | |
---|
| 383 | if (!overwrite && g_access(path, F_OK) == 0) { |
---|
[a338faa] | 384 | return STORAGE_ALREADY_EXISTS; |
---|
[5ebff60] | 385 | } |
---|
| 386 | |
---|
| 387 | strcat(path, ".XXXXXX"); |
---|
| 388 | if ((fd = mkstemp(path)) < 0) { |
---|
[7320610] | 389 | goto error; |
---|
[547ea68] | 390 | } |
---|
[5ebff60] | 391 | |
---|
| 392 | tree = xml_generate(irc); |
---|
| 393 | xml = xt_to_string_i(tree); |
---|
| 394 | len = strlen(xml); |
---|
| 395 | if (write(fd, xml, len) != len || |
---|
| 396 | fsync(fd) != 0 || /* #559 */ |
---|
| 397 | close(fd) != 0) { |
---|
[d219296] | 398 | goto error; |
---|
[5ebff60] | 399 | } |
---|
| 400 | |
---|
| 401 | path2 = g_strndup(path, strlen(path) - 7); |
---|
| 402 | if (rename(path, path2) != 0) { |
---|
| 403 | g_free(path2); |
---|
[d219296] | 404 | goto error; |
---|
[5898ef8] | 405 | } |
---|
[5ebff60] | 406 | g_free(path2); |
---|
| 407 | |
---|
[d219296] | 408 | goto finish; |
---|
[5898ef8] | 409 | |
---|
[d219296] | 410 | error: |
---|
[7320610] | 411 | irc_rootmsg(irc, "Write error: %s", g_strerror(errno)); |
---|
[d219296] | 412 | ret = STORAGE_OTHER_ERROR; |
---|
| 413 | |
---|
[5ebff60] | 414 | finish: |
---|
| 415 | close(fd); |
---|
| 416 | unlink(path); |
---|
| 417 | g_free(xml); |
---|
| 418 | xt_free_node(tree); |
---|
| 419 | |
---|
[d219296] | 420 | return ret; |
---|
[a312b6b] | 421 | } |
---|
| 422 | |
---|
[5b52a48] | 423 | |
---|
[5ebff60] | 424 | static storage_status_t xml_remove(const char *nick, const char *password) |
---|
[84e9cea] | 425 | { |
---|
[e0f9170] | 426 | char s[512], *lc; |
---|
[84e9cea] | 427 | storage_status_t status; |
---|
| 428 | |
---|
[5ebff60] | 429 | status = xml_check_pass(nick, password); |
---|
| 430 | if (status != STORAGE_OK) { |
---|
[84e9cea] | 431 | return status; |
---|
[5ebff60] | 432 | } |
---|
| 433 | |
---|
| 434 | lc = g_strdup(nick); |
---|
| 435 | nick_lc(NULL, lc); |
---|
| 436 | g_snprintf(s, 511, "%s%s%s", global.conf->configdir, lc, ".xml"); |
---|
| 437 | g_free(lc); |
---|
[84e9cea] | 438 | |
---|
[5ebff60] | 439 | if (unlink(s) == -1) { |
---|
[84e9cea] | 440 | return STORAGE_OTHER_ERROR; |
---|
[5ebff60] | 441 | } |
---|
| 442 | |
---|
[84e9cea] | 443 | return STORAGE_OK; |
---|
| 444 | } |
---|
| 445 | |
---|
[a312b6b] | 446 | storage_t storage_xml = { |
---|
| 447 | .name = "xml", |
---|
| 448 | .init = xml_init, |
---|
[84e9cea] | 449 | .check_pass = xml_check_pass, |
---|
| 450 | .remove = xml_remove, |
---|
[a312b6b] | 451 | .load = xml_load, |
---|
| 452 | .save = xml_save |
---|
| 453 | }; |
---|