[1ee6c18] | 1 | /********************************************************************\ |
---|
| 2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
| 3 | * * |
---|
| 4 | * Copyright 2002-2004 Wilmer van der Gaast and others * |
---|
| 5 | \********************************************************************/ |
---|
| 6 | |
---|
| 7 | /* Storage backend that uses the same file format as <=1.0 */ |
---|
| 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" |
---|
| 28 | #include "crypting.h" |
---|
[4146a07] | 29 | #ifdef _WIN32 |
---|
| 30 | # define umask _umask |
---|
| 31 | # define mode_t int |
---|
| 32 | #endif |
---|
| 33 | |
---|
| 34 | #ifndef F_OK |
---|
| 35 | #define F_OK 0 |
---|
| 36 | #endif |
---|
[1ee6c18] | 37 | |
---|
| 38 | static void text_init (void) |
---|
| 39 | { |
---|
[eeb85a8] | 40 | /* Don't complain about the configuration directory anymore, leave it |
---|
| 41 | up to the XML storage module, which uses the same directory for it |
---|
| 42 | anyway. Nobody should be using just the text plugin anymore since |
---|
| 43 | it's read only! */ |
---|
[1ee6c18] | 44 | } |
---|
| 45 | |
---|
[a1f17d4] | 46 | static storage_status_t text_load ( const char *my_nick, const char* password, irc_t *irc ) |
---|
[1ee6c18] | 47 | { |
---|
| 48 | char s[512]; |
---|
| 49 | char *line; |
---|
| 50 | int proto; |
---|
| 51 | char nick[MAX_NICK_LENGTH+1]; |
---|
| 52 | FILE *fp; |
---|
| 53 | user_t *ru = user_find( irc, ROOT_NICK ); |
---|
[7e3592e] | 54 | account_t *acc, *acc_lookup[9]; |
---|
[1ee6c18] | 55 | |
---|
[79e826a] | 56 | if( irc->status & USTATUS_IDENTIFIED ) |
---|
[1ee6c18] | 57 | return( 1 ); |
---|
| 58 | |
---|
| 59 | g_snprintf( s, 511, "%s%s%s", global.conf->configdir, my_nick, ".accounts" ); |
---|
| 60 | fp = fopen( s, "r" ); |
---|
[a1f17d4] | 61 | if( !fp ) return STORAGE_NO_SUCH_USER; |
---|
[1ee6c18] | 62 | |
---|
| 63 | fscanf( fp, "%32[^\n]s", s ); |
---|
[7cad7b4] | 64 | |
---|
[7e3592e] | 65 | if( checkpass( password, s ) != 0 ) |
---|
[1ee6c18] | 66 | { |
---|
| 67 | fclose( fp ); |
---|
[a1f17d4] | 68 | return STORAGE_INVALID_PASSWORD; |
---|
[1ee6c18] | 69 | } |
---|
| 70 | |
---|
| 71 | /* Do this now. If the user runs with AuthMode = Registered, the |
---|
| 72 | account command will not work otherwise. */ |
---|
[79e826a] | 73 | irc->status |= USTATUS_IDENTIFIED; |
---|
[1ee6c18] | 74 | |
---|
| 75 | while( fscanf( fp, "%511[^\n]s", s ) > 0 ) |
---|
| 76 | { |
---|
| 77 | fgetc( fp ); |
---|
[b73ac9c] | 78 | line = deobfucrypt( s, password ); |
---|
| 79 | if (line == NULL) return STORAGE_OTHER_ERROR; |
---|
[1ee6c18] | 80 | root_command_string( irc, ru, line, 0 ); |
---|
| 81 | g_free( line ); |
---|
| 82 | } |
---|
| 83 | fclose( fp ); |
---|
| 84 | |
---|
[7e3592e] | 85 | /* Build a list with the first listed account of every protocol |
---|
| 86 | number. So if the user had nicks defined for a second account on |
---|
| 87 | the same IM network, those nicks will be added to the wrong |
---|
| 88 | account, and the user should rename those buddies again. But at |
---|
| 89 | least from now on things will be saved properly. */ |
---|
| 90 | memset( acc_lookup, 0, sizeof( acc_lookup ) ); |
---|
| 91 | for( acc = irc->accounts; acc; acc = acc->next ) |
---|
| 92 | { |
---|
| 93 | if( acc_lookup[0] == NULL && strcmp( acc->prpl->name, "oscar" ) == 0 ) |
---|
| 94 | acc_lookup[0] = acc_lookup[1] = acc_lookup[3] = acc; |
---|
| 95 | else if( acc_lookup[2] == NULL && strcmp( acc->prpl->name, "yahoo" ) == 0 ) |
---|
| 96 | acc_lookup[2] = acc; |
---|
| 97 | else if( acc_lookup[4] == NULL && strcmp( acc->prpl->name, "msn" ) == 0 ) |
---|
| 98 | acc_lookup[4] = acc; |
---|
| 99 | else if( acc_lookup[8] == NULL && strcmp( acc->prpl->name, "jabber" ) == 0 ) |
---|
| 100 | acc_lookup[8] = acc; |
---|
| 101 | } |
---|
| 102 | |
---|
[1ee6c18] | 103 | g_snprintf( s, 511, "%s%s%s", global.conf->configdir, my_nick, ".nicks" ); |
---|
| 104 | fp = fopen( s, "r" ); |
---|
[a1f17d4] | 105 | if( !fp ) return STORAGE_NO_SUCH_USER; |
---|
[1ee6c18] | 106 | while( fscanf( fp, "%s %d %s", s, &proto, nick ) > 0 ) |
---|
| 107 | { |
---|
[34337a7] | 108 | if( proto < 0 || proto > 8 || ( acc = acc_lookup[proto] ) == NULL ) |
---|
[703f0f7] | 109 | continue; |
---|
[7e3592e] | 110 | |
---|
[1ee6c18] | 111 | http_decode( s ); |
---|
[7e3592e] | 112 | nick_set( acc, s, nick ); |
---|
[1ee6c18] | 113 | } |
---|
| 114 | fclose( fp ); |
---|
| 115 | |
---|
[a1f17d4] | 116 | return STORAGE_OK; |
---|
[1ee6c18] | 117 | } |
---|
| 118 | |
---|
[7989fcf3] | 119 | static storage_status_t text_check_pass( const char *nick, const char *password ) |
---|
[1ee6c18] | 120 | { |
---|
| 121 | char s[512]; |
---|
| 122 | FILE *fp; |
---|
| 123 | |
---|
[b73ac9c] | 124 | g_snprintf( s, 511, "%s%s%s", global.conf->configdir, nick, ".accounts" ); |
---|
[1ee6c18] | 125 | fp = fopen( s, "r" ); |
---|
[a1f17d4] | 126 | if (!fp) |
---|
| 127 | return STORAGE_NO_SUCH_USER; |
---|
[1ee6c18] | 128 | |
---|
| 129 | fscanf( fp, "%32[^\n]s", s ); |
---|
| 130 | fclose( fp ); |
---|
| 131 | |
---|
[7cad7b4] | 132 | if (checkpass( password, s) == -1) |
---|
| 133 | return STORAGE_INVALID_PASSWORD; |
---|
[a1f17d4] | 134 | |
---|
[7989fcf3] | 135 | return STORAGE_OK; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | static storage_status_t text_remove( const char *nick, const char *password ) |
---|
| 139 | { |
---|
| 140 | char s[512]; |
---|
| 141 | storage_status_t status; |
---|
| 142 | |
---|
| 143 | status = text_check_pass( nick, password ); |
---|
| 144 | if (status != STORAGE_OK) |
---|
| 145 | return status; |
---|
| 146 | |
---|
[a1f17d4] | 147 | g_snprintf( s, 511, "%s%s%s", global.conf->configdir, nick, ".accounts" ); |
---|
| 148 | if (unlink( s ) == -1) |
---|
| 149 | return STORAGE_OTHER_ERROR; |
---|
| 150 | |
---|
| 151 | g_snprintf( s, 511, "%s%s%s", global.conf->configdir, nick, ".nicks" ); |
---|
| 152 | if (unlink( s ) == -1) |
---|
| 153 | return STORAGE_OTHER_ERROR; |
---|
| 154 | |
---|
| 155 | return STORAGE_OK; |
---|
[1ee6c18] | 156 | } |
---|
| 157 | |
---|
| 158 | storage_t storage_text = { |
---|
| 159 | .name = "text", |
---|
| 160 | .init = text_init, |
---|
[7989fcf3] | 161 | .check_pass = text_check_pass, |
---|
[1ee6c18] | 162 | .remove = text_remove, |
---|
[5b52a48] | 163 | .load = text_load |
---|
[1ee6c18] | 164 | }; |
---|