source: storage_text.c @ 823de9d

Last change on this file since 823de9d was 823de9d, checked in by Sven Moritz Hallberg <pesco@…>, at 2009-03-12T19:10:06Z

commit updates by ashish shukla <wahjava@…>

  • Property mode set to 100644
File size: 4.4 KB
Line 
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"
29
30static void text_init (void)
31{
32        /* Don't complain about the configuration directory anymore, leave it
33           up to the XML storage module, which uses the same directory for it
34           anyway. Nobody should be using just the text plugin anymore since
35           it's read only! */
36}
37
38static storage_status_t text_load( irc_t *irc, const char* password )
39{
40        char s[512];
41        char *line;
42        int proto;
43        char nick[MAX_NICK_LENGTH+1];
44        FILE *fp;
45        user_t *ru = user_find( irc, ROOT_NICK );
46        account_t *acc, *acc_lookup[9];
47       
48        g_snprintf( s, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts" );
49        fp = fopen( s, "r" );
50        if( !fp ) return STORAGE_NO_SUCH_USER;
51       
52        fscanf( fp, "%32[^\n]s", s );
53
54        if( checkpass( password, s ) != 0 )
55        {
56                fclose( fp );
57                return STORAGE_INVALID_PASSWORD;
58        }
59       
60        while( fscanf( fp, "%511[^\n]s", s ) > 0 )
61        {
62                fgetc( fp );
63                line = deobfucrypt( s, password );
64                if (line == NULL) return STORAGE_OTHER_ERROR;
65                root_command_string( irc, ru, line, 0 );
66                g_free( line );
67        }
68        fclose( fp );
69       
70        /* Build a list with the first listed account of every protocol
71           number. So if the user had nicks defined for a second account on
72           the same IM network, those nicks will be added to the wrong
73           account, and the user should rename those buddies again. But at
74           least from now on things will be saved properly. */
75        memset( acc_lookup, 0, sizeof( acc_lookup ) );
76        for( acc = irc->accounts; acc; acc = acc->next )
77        {
78                if( acc_lookup[0] == NULL && strcmp( acc->prpl->name, "oscar" ) == 0 )
79                        acc_lookup[0] = acc_lookup[1] = acc_lookup[3] = acc;
80                else if( acc_lookup[2] == NULL && strcmp( acc->prpl->name, "yahoo" ) == 0 )
81                        acc_lookup[2] = acc;
82                else if( acc_lookup[4] == NULL && strcmp( acc->prpl->name, "msn" ) == 0 )
83                        acc_lookup[4] = acc;
84                else if( acc_lookup[8] == NULL && strcmp( acc->prpl->name, "jabber" ) == 0 )
85                        acc_lookup[8] = acc;
86        }
87       
88        g_snprintf( s, 511, "%s%s%s", global.conf->configdir, irc->nick, ".nicks" );
89        fp = fopen( s, "r" );
90        if( !fp ) return STORAGE_NO_SUCH_USER;
91        while( fscanf( fp, "%s %d %s", s, &proto, nick ) > 0 )
92        {
93                if( proto < 0 || proto > 8 || ( acc = acc_lookup[proto] ) == NULL )
94                        continue;
95               
96                http_decode( s );
97                nick_set( acc, s, nick );
98        }
99        fclose( fp );
100       
101        return STORAGE_OK;
102}
103
104static storage_status_t text_check_pass( const char *nick, const char *password )
105{
106        char s[512];
107        FILE *fp;
108       
109        g_snprintf( s, 511, "%s%s%s", global.conf->configdir, nick, ".accounts" );
110        fp = fopen( s, "r" );
111        if (!fp)
112                return STORAGE_NO_SUCH_USER;
113
114        fscanf( fp, "%32[^\n]s", s );
115        fclose( fp );
116
117        if (checkpass( password, s) == -1)
118                return STORAGE_INVALID_PASSWORD;
119
120        return STORAGE_OK;
121}
122
123static storage_status_t text_remove( const char *nick, const char *password )
124{
125        char s[512];
126        storage_status_t status;
127
128        status = text_check_pass( nick, password );
129        if (status != STORAGE_OK)
130                return status;
131
132        g_snprintf( s, 511, "%s%s%s", global.conf->configdir, nick, ".accounts" );
133        if (unlink( s ) == -1)
134                return STORAGE_OTHER_ERROR;
135       
136        g_snprintf( s, 511, "%s%s%s", global.conf->configdir, nick, ".nicks" );
137        if (unlink( s ) == -1)
138                return STORAGE_OTHER_ERROR;
139
140        return STORAGE_OK;
141}
142
143storage_t storage_text = {
144        .name = "text",
145        .init = text_init,
146        .check_pass = text_check_pass,
147        .remove = text_remove,
148        .load = text_load
149};
Note: See TracBrowser for help on using the repository browser.