From 1ee6c18cfb5eb03f33a5938b37e357dd3fd2c164 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 8 Dec 2005 14:41:53 +0100 Subject: Add abstraction layer for storage --- commands.c | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) (limited to 'commands.c') diff --git a/commands.c b/commands.c index 504a9345..1fe6cae3 100644 --- a/commands.c +++ b/commands.c @@ -85,7 +85,7 @@ int cmd_help( irc_t *irc, char **cmd ) int cmd_identify( irc_t *irc, char **cmd ) { - int checkie = bitlbee_load( irc, cmd[1] ); + int checkie = global.storage->load( irc->nick, cmd[1], irc ); if( checkie == -1 ) { @@ -109,22 +109,13 @@ int cmd_identify( irc_t *irc, char **cmd ) int cmd_register( irc_t *irc, char **cmd ) { - int checkie; - char path[512]; - if( global.conf->authmode == AUTHMODE_REGISTERED ) { irc_usermsg( irc, "This server does not allow registering new accounts" ); return( 0 ); } - - g_snprintf( path, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts" ); - checkie = access( path, F_OK ); - - g_snprintf( path, 511, "%s%s%s", global.conf->configdir, irc->nick, ".nicks" ); - checkie += access( path, F_OK ); - - if( checkie == -2 ) + + if( !global.storage->exists( irc->nick )) { setpassnc( irc, cmd[1] ); root_command_string( irc, user_find( irc, irc->mynick ), "save", 0 ); @@ -140,30 +131,19 @@ int cmd_register( irc_t *irc, char **cmd ) int cmd_drop( irc_t *irc, char **cmd ) { - char s[512]; - FILE *fp; - - g_snprintf( s, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts" ); - fp = fopen( s, "r" ); - if( !fp ) + if( ! global.storage->exists (irc->nick) ) { irc_usermsg( irc, "That account does not exist" ); return( 0 ); } - - fscanf( fp, "%32[^\n]s", s ); - fclose( fp ); - if( setpass( irc, cmd[1], s ) < 0 ) + + if ( global.storage->check_pass (irc->nick, cmd[1]) ) { - irc_usermsg( irc, "Incorrect password" ); + irc_usermsg( irc, "Password invalid" ); return( 0 ); } - g_snprintf( s, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts" ); - unlink( s ); - - g_snprintf( s, 511, "%s%s%s", global.conf->configdir, irc->nick, ".nicks" ); - unlink( s ); + global.storage->remove (irc->nick); setpassnc( irc, NULL ); irc_usermsg( irc, "Files belonging to account `%s' removed", irc->nick ); @@ -633,7 +613,7 @@ int cmd_set( irc_t *irc, char **cmd ) int cmd_save( irc_t *irc, char **cmd ) { - if( bitlbee_save( irc ) ) + if( global.storage->save( irc ) ) irc_usermsg( irc, "Configuration saved" ); else irc_usermsg( irc, "Configuration could not be saved!" ); -- cgit v1.2.3 From a1f17d45fae99428c8024168b55b4279c59ac867 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 8 Dec 2005 15:14:28 +0100 Subject: Simplify storage API a bit --- commands.c | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) (limited to 'commands.c') diff --git a/commands.c b/commands.c index 1fe6cae3..be13ff49 100644 --- a/commands.c +++ b/commands.c @@ -115,15 +115,19 @@ int cmd_register( irc_t *irc, char **cmd ) return( 0 ); } - if( !global.storage->exists( irc->nick )) - { - setpassnc( irc, cmd[1] ); - root_command_string( irc, user_find( irc, irc->mynick ), "save", 0 ); - irc->status = USTATUS_IDENTIFIED; - } - else - { - irc_usermsg( irc, "Nick is already registered" ); + setpassnc( irc, cmd[1] ); + switch( global.storage->save( irc, FALSE )) { + case STORAGE_ALREADY_EXISTS: + irc_usermsg( irc, "Nick is already registered" ); + break; + + case STORAGE_OK: + irc->status = USTATUS_IDENTIFIED; + break; + + default: + irc_usermsg( irc, "Error registering" ); + break; } return( 0 ); @@ -131,24 +135,24 @@ int cmd_register( irc_t *irc, char **cmd ) int cmd_drop( irc_t *irc, char **cmd ) { - if( ! global.storage->exists (irc->nick) ) - { + storage_status_t status; + + status = global.storage->remove (irc->nick, cmd[1]); + switch (status) { + case STORAGE_NO_SUCH_USER: irc_usermsg( irc, "That account does not exist" ); return( 0 ); - } - - if ( global.storage->check_pass (irc->nick, cmd[1]) ) - { + case STORAGE_INVALID_PASSWORD: irc_usermsg( irc, "Password invalid" ); return( 0 ); + case STORAGE_OK: + setpassnc( irc, NULL ); + irc_usermsg( irc, "Account `%s' removed", irc->nick ); + return( 0 ); + default: + irc_usermsg( irc, "Error: '%d'", status ); + return( 0 ); } - - global.storage->remove (irc->nick); - - setpassnc( irc, NULL ); - irc_usermsg( irc, "Files belonging to account `%s' removed", irc->nick ); - - return( 0 ); } int cmd_account( irc_t *irc, char **cmd ) @@ -613,7 +617,7 @@ int cmd_set( irc_t *irc, char **cmd ) int cmd_save( irc_t *irc, char **cmd ) { - if( global.storage->save( irc ) ) + if( global.storage->save( irc, TRUE ) ) irc_usermsg( irc, "Configuration saved" ); else irc_usermsg( irc, "Configuration could not be saved!" ); -- cgit v1.2.3 From 09adf08684c62fff0f507304ed37680137de4637 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 8 Dec 2005 16:31:25 +0100 Subject: Couple of small bugfixes --- commands.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'commands.c') diff --git a/commands.c b/commands.c index be13ff49..4f2b6b85 100644 --- a/commands.c +++ b/commands.c @@ -85,23 +85,21 @@ int cmd_help( irc_t *irc, char **cmd ) int cmd_identify( irc_t *irc, char **cmd ) { - int checkie = global.storage->load( irc->nick, cmd[1], irc ); + storage_status_t status = global.storage->load( irc->nick, cmd[1], irc ); - if( checkie == -1 ) - { + switch (status) { + case STORAGE_INVALID_PASSWORD: irc_usermsg( irc, "Incorrect password" ); - } - else if( checkie == 0 ) - { + break; + case STORAGE_NO_SUCH_USER: irc_usermsg( irc, "The nick is (probably) not registered" ); - } - else if( checkie == 1 ) - { + break; + case STORAGE_OK: irc_usermsg( irc, "Password accepted" ); - } - else - { + break; + default: irc_usermsg( irc, "Something very weird happened" ); + break; } return( 0 ); @@ -617,7 +615,7 @@ int cmd_set( irc_t *irc, char **cmd ) int cmd_save( irc_t *irc, char **cmd ) { - if( global.storage->save( irc, TRUE ) ) + if( global.storage->save( irc, TRUE ) == STORAGE_OK ) irc_usermsg( irc, "Configuration saved" ); else irc_usermsg( irc, "Configuration could not be saved!" ); -- cgit v1.2.3 From 7cad7b41a0b661c38ae5f6239aaf58361788edc9 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 8 Dec 2005 17:00:08 +0100 Subject: Clearer seperation between crypting and generic password code --- commands.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'commands.c') diff --git a/commands.c b/commands.c index 4f2b6b85..2877aa4b 100644 --- a/commands.c +++ b/commands.c @@ -113,7 +113,7 @@ int cmd_register( irc_t *irc, char **cmd ) return( 0 ); } - setpassnc( irc, cmd[1] ); + irc_setpass( irc, cmd[1] ); switch( global.storage->save( irc, FALSE )) { case STORAGE_ALREADY_EXISTS: irc_usermsg( irc, "Nick is already registered" ); @@ -144,7 +144,7 @@ int cmd_drop( irc_t *irc, char **cmd ) irc_usermsg( irc, "Password invalid" ); return( 0 ); case STORAGE_OK: - setpassnc( irc, NULL ); + irc_setpass( irc, NULL ); irc_usermsg( irc, "Account `%s' removed", irc->nick ); return( 0 ); default: -- cgit v1.2.3 From ab49fdcec9a09df839ec488e570672f2dd904dc7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 10 Dec 2005 15:50:49 +0100 Subject: Use helper functions rather then the backends directly. This will be used for transparent upgrade support later on. --- commands.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'commands.c') diff --git a/commands.c b/commands.c index 2877aa4b..7695d679 100644 --- a/commands.c +++ b/commands.c @@ -85,7 +85,7 @@ int cmd_help( irc_t *irc, char **cmd ) int cmd_identify( irc_t *irc, char **cmd ) { - storage_status_t status = global.storage->load( irc->nick, cmd[1], irc ); + storage_status_t status = storage_load( irc->nick, cmd[1], irc ); switch (status) { case STORAGE_INVALID_PASSWORD: @@ -114,7 +114,7 @@ int cmd_register( irc_t *irc, char **cmd ) } irc_setpass( irc, cmd[1] ); - switch( global.storage->save( irc, FALSE )) { + switch( storage_save( irc, FALSE )) { case STORAGE_ALREADY_EXISTS: irc_usermsg( irc, "Nick is already registered" ); break; @@ -135,7 +135,7 @@ int cmd_drop( irc_t *irc, char **cmd ) { storage_status_t status; - status = global.storage->remove (irc->nick, cmd[1]); + status = storage_remove (irc->nick, cmd[1]); switch (status) { case STORAGE_NO_SUCH_USER: irc_usermsg( irc, "That account does not exist" ); @@ -615,7 +615,7 @@ int cmd_set( irc_t *irc, char **cmd ) int cmd_save( irc_t *irc, char **cmd ) { - if( global.storage->save( irc, TRUE ) == STORAGE_OK ) + if( storage_save( irc, TRUE ) == STORAGE_OK ) irc_usermsg( irc, "Configuration saved" ); else irc_usermsg( irc, "Configuration could not be saved!" ); -- cgit v1.2.3 From b73ac9c35fb53203b8d0668251dfb66096883863 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 14 Dec 2005 00:05:27 +0100 Subject: Add support for 'primary' and 'migrate' account storages. Fix two bugs in the text storage backend that were introduced by my previous changes. --- commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'commands.c') diff --git a/commands.c b/commands.c index 7695d679..27a84ee1 100644 --- a/commands.c +++ b/commands.c @@ -101,7 +101,7 @@ int cmd_identify( irc_t *irc, char **cmd ) irc_usermsg( irc, "Something very weird happened" ); break; } - + return( 0 ); } -- cgit v1.2.3