Index: bitlbee.h
===================================================================
--- bitlbee.h	(revision d4810dff26f128061d122cf120e1e0174d9df1f2)
+++ bitlbee.h	(revision ced1e17474366772791186f865bd45d4decfcaf2)
@@ -33,5 +33,5 @@
 
 #define PACKAGE "BitlBee"
-#define BITLBEE_VERSION "1.2.2"
+#define BITLBEE_VERSION "1.2.3"
 #define VERSION BITLBEE_VERSION
 
Index: doc/CHANGES
===================================================================
--- doc/CHANGES	(revision d4810dff26f128061d122cf120e1e0174d9df1f2)
+++ doc/CHANGES	(revision ced1e17474366772791186f865bd45d4decfcaf2)
@@ -3,4 +3,11 @@
 
 http://bugs.bitlbee.org/bitlbee/timeline?daysback=90&changeset=on
+
+Version 1.2.3:
+- Fixed one more flaw similar to the previous hijacking bug, caused by incon-
+  sistent handling of the USTATUS_IDENTIFIED state. All code touching these
+  variables was reviewed and should be correct now.
+
+Finished 7 Sep 2008 
 
 Version 1.2.2:
Index: doc/user-guide/Makefile
===================================================================
--- doc/user-guide/Makefile	(revision d4810dff26f128061d122cf120e1e0174d9df1f2)
+++ doc/user-guide/Makefile	(revision ced1e17474366772791186f865bd45d4decfcaf2)
@@ -13,5 +13,5 @@
 
 %.html: %.db.xml
-	xsltproc --output $@ http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl $<
+	xsltproc --output $@ http://docbook.sourceforge.net/release/xsl/current/xhtml/docbook.xsl $<
 
 %.pdf: %.db.xml
Index: doc/user-guide/help.xml
===================================================================
--- doc/user-guide/help.xml	(revision d4810dff26f128061d122cf120e1e0174d9df1f2)
+++ doc/user-guide/help.xml	(revision ced1e17474366772791186f865bd45d4decfcaf2)
@@ -1,3 +1,3 @@
-<?xml version="1.0" encoding="iso-8859-1"?>
+<?xml version="1.0" encoding="utf-8"?>
 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
 
Index: doc/user-guide/user-guide.xml
===================================================================
--- doc/user-guide/user-guide.xml	(revision d4810dff26f128061d122cf120e1e0174d9df1f2)
+++ doc/user-guide/user-guide.xml	(revision ced1e17474366772791186f865bd45d4decfcaf2)
@@ -1,3 +1,3 @@
-<?xml version="1.0" encoding="iso-8859-1"?>
+<?xml version="1.0" encoding="utf-8"?>
 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
 
Index: irc.c
===================================================================
--- irc.c	(revision d4810dff26f128061d122cf120e1e0174d9df1f2)
+++ irc.c	(revision ced1e17474366772791186f865bd45d4decfcaf2)
@@ -38,5 +38,5 @@
 	irc_t *irc = set->data;
 	
-	if( irc->status & USTATUS_IDENTIFIED )
+	if( irc->status & USTATUS_IDENTIFIED && value )
 	{
 		irc_setpass( irc, value );
@@ -239,5 +239,5 @@
 	
 	if( irc->status & USTATUS_IDENTIFIED && set_getbool( &irc->set, "save_on_quit" ) ) 
-		if( storage_save( irc, TRUE ) != STORAGE_OK )
+		if( storage_save( irc, NULL, TRUE ) != STORAGE_OK )
 			irc_usermsg( irc, "Error while saving settings!" );
 	
Index: root_commands.c
===================================================================
--- root_commands.c	(revision d4810dff26f128061d122cf120e1e0174d9df1f2)
+++ root_commands.c	(revision ced1e17474366772791186f865bd45d4decfcaf2)
@@ -140,5 +140,5 @@
 static void cmd_identify( irc_t *irc, char **cmd )
 {
-	storage_status_t status = storage_load( irc->nick, cmd[1], irc );
+	storage_status_t status = storage_load( irc, cmd[1] );
 	char *account_on[] = { "account", "on", NULL };
 	
@@ -152,4 +152,6 @@
 	case STORAGE_OK:
 		irc_usermsg( irc, "Password accepted, settings and accounts loaded" );
+		irc_setpass( irc, cmd[1] );
+		irc->status |= USTATUS_IDENTIFIED;
 		irc_umode_set( irc, "+R", 1 );
 		if( set_getbool( &irc->set, "auto_connect" ) )
@@ -171,6 +173,5 @@
 	}
 
-	irc_setpass( irc, cmd[1] );
-	switch( storage_save( irc, FALSE )) {
+	switch( storage_save( irc, cmd[1], FALSE ) ) {
 		case STORAGE_ALREADY_EXISTS:
 			irc_usermsg( irc, "Nick is already registered" );
@@ -179,4 +180,5 @@
 		case STORAGE_OK:
 			irc_usermsg( irc, "Account successfully created" );
+			irc_setpass( irc, cmd[1] );
 			irc->status |= USTATUS_IDENTIFIED;
 			irc_umode_set( irc, "+R", 1 );
@@ -872,5 +874,7 @@
 static void cmd_save( irc_t *irc, char **cmd )
 {
-	if( storage_save( irc, TRUE ) == STORAGE_OK )
+	if( ( irc->status & USTATUS_IDENTIFIED ) == 0 )
+		irc_usermsg( irc, "Please create an account first" );
+	else if( storage_save( irc, NULL, TRUE ) == STORAGE_OK )
 		irc_usermsg( irc, "Configuration saved" );
 	else
Index: storage.c
===================================================================
--- storage.c	(revision d4810dff26f128061d122cf120e1e0174d9df1f2)
+++ storage.c	(revision ced1e17474366772791186f865bd45d4decfcaf2)
@@ -103,7 +103,10 @@
 }
 
-storage_status_t storage_load (const char *nick, const char *password, irc_t * irc)
-{
-	GList *gl;
+storage_status_t storage_load (irc_t * irc, const char *password)
+{
+	GList *gl;
+	
+	if (irc && irc->status & USTATUS_IDENTIFIED)
+		return STORAGE_OTHER_ERROR;
 	
 	/* Loop until we don't get NO_SUCH_USER */
@@ -112,9 +115,7 @@
 		storage_status_t status;
 
-		status = st->load(nick, password, irc);
-		if (status == STORAGE_OK) {
-			irc_setpass(irc, password);
+		status = st->load(irc, password);
+		if (status == STORAGE_OK)
 			return status;
-		}
 		
 		if (status != STORAGE_NO_SUCH_USER) 
@@ -125,7 +126,25 @@
 }
 
-storage_status_t storage_save (irc_t *irc, int overwrite)
-{
-	return ((storage_t *)global.storage->data)->save(irc, overwrite);
+storage_status_t storage_save (irc_t *irc, char *password, int overwrite)
+{
+	storage_status_t st;
+	
+	if (password != NULL) {
+		/* Should only use this in the "register" command. */
+		if (irc->password || overwrite)
+			return STORAGE_OTHER_ERROR;
+		
+		irc_setpass(irc, password);
+	} else if ((irc->status & USTATUS_IDENTIFIED) == 0) {
+		return STORAGE_NO_SUCH_USER;
+	}
+	
+	st = ((storage_t *)global.storage->data)->save(irc, overwrite);
+	
+	if (password != NULL) {
+		irc_setpass(irc, NULL);
+	}
+	
+	return st;
 }
 
@@ -143,6 +162,5 @@
 
 		status = st->remove(nick, password);
-		if (status != STORAGE_NO_SUCH_USER && 
-			status != STORAGE_OK)
+		if (status != STORAGE_NO_SUCH_USER && status != STORAGE_OK)
 			ret = status;
 	}
@@ -150,4 +168,7 @@
 	return ret;
 }
+
+#if 0
+Not using this yet. Test thoroughly before adding UI hooks to this function.
 
 storage_status_t storage_rename (const char *onick, const char *nnick, const char *password)
@@ -189,2 +210,3 @@
 	return STORAGE_OK;
 }
+#endif
Index: storage.h
===================================================================
--- storage.h	(revision d4810dff26f128061d122cf120e1e0174d9df1f2)
+++ storage.h	(revision ced1e17474366772791186f865bd45d4decfcaf2)
@@ -45,5 +45,5 @@
 	storage_status_t (*check_pass) (const char *nick, const char *password);
 
-	storage_status_t (*load) (const char *nick, const char *password, irc_t * irc);
+	storage_status_t (*load) (irc_t *irc, const char *password);
 	storage_status_t (*save) (irc_t *irc, int overwrite);
 	storage_status_t (*remove) (const char *nick, const char *password);
@@ -55,9 +55,9 @@
 storage_status_t storage_check_pass (const char *nick, const char *password);
 
-storage_status_t storage_load (const char *nick, const char *password, irc_t * irc);
-storage_status_t storage_save (irc_t *irc, int overwrite);
+storage_status_t storage_load (irc_t * irc, const char *password);
+storage_status_t storage_save (irc_t *irc, char *password, int overwrite);
 storage_status_t storage_remove (const char *nick, const char *password);
 
-storage_status_t storage_rename (const char *onick, const char *nnick, const char *password);
+/* storage_status_t storage_rename (const char *onick, const char *nnick, const char *password); */
 
 void register_storage_backend(storage_t *);
Index: storage_text.c
===================================================================
--- storage_text.c	(revision d4810dff26f128061d122cf120e1e0174d9df1f2)
+++ storage_text.c	(revision ced1e17474366772791186f865bd45d4decfcaf2)
@@ -44,5 +44,5 @@
 }
 
-static storage_status_t text_load ( const char *my_nick, const char* password, irc_t *irc )
+static storage_status_t text_load( irc_t *irc, const char* password )
 {
 	char s[512];
@@ -54,8 +54,5 @@
 	account_t *acc, *acc_lookup[9];
 	
-	if( irc->status & USTATUS_IDENTIFIED )
-		return( 1 );
-	
-	g_snprintf( s, 511, "%s%s%s", global.conf->configdir, my_nick, ".accounts" );
+	g_snprintf( s, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts" );
    	fp = fopen( s, "r" );
    	if( !fp ) return STORAGE_NO_SUCH_USER;
@@ -68,8 +65,4 @@
 		return STORAGE_INVALID_PASSWORD;
 	}
-	
-	/* Do this now. If the user runs with AuthMode = Registered, the
-	   account command will not work otherwise. */
-	irc->status |= USTATUS_IDENTIFIED;
 	
 	while( fscanf( fp, "%511[^\n]s", s ) > 0 )
@@ -101,5 +94,5 @@
 	}
 	
-	g_snprintf( s, 511, "%s%s%s", global.conf->configdir, my_nick, ".nicks" );
+	g_snprintf( s, 511, "%s%s%s", global.conf->configdir, irc->nick, ".nicks" );
 	fp = fopen( s, "r" );
 	if( !fp ) return STORAGE_NO_SUCH_USER;
Index: storage_xml.c
===================================================================
--- storage_xml.c	(revision d4810dff26f128061d122cf120e1e0174d9df1f2)
+++ storage_xml.c	(revision ced1e17474366772791186f865bd45d4decfcaf2)
@@ -288,5 +288,5 @@
 }
 
-static storage_status_t xml_load_real( const char *my_nick, const char *password, irc_t *irc, xml_pass_st action )
+static storage_status_t xml_load_real( irc_t *irc, const char *my_nick, const char *password, xml_pass_st action )
 {
 	GMarkupParseContext *ctx;
@@ -295,7 +295,4 @@
 	GError *gerr = NULL;
 	int fd, st;
-	
-	if( irc && irc->status & USTATUS_IDENTIFIED )
-		return( 1 );
 	
 	xd = g_new0( struct xml_parsedata, 1 );
@@ -350,12 +347,10 @@
 		return STORAGE_OK;
 	
-	irc->status |= USTATUS_IDENTIFIED;
-	
 	return STORAGE_OK;
 }
 
-static storage_status_t xml_load( const char *my_nick, const char *password, irc_t *irc )
-{
-	return xml_load_real( my_nick, password, irc, XML_PASS_UNKNOWN );
+static storage_status_t xml_load( irc_t *irc, const char *password )
+{
+	return xml_load_real( irc, irc->nick, password, XML_PASS_UNKNOWN );
 }
 
@@ -364,5 +359,5 @@
 	/* This is a little bit risky because we have to pass NULL for the
 	   irc_t argument. This *should* be fine, if I didn't miss anything... */
-	return xml_load_real( my_nick, password, NULL, XML_PASS_CHECK_ONLY );
+	return xml_load_real( NULL, my_nick, password, XML_PASS_CHECK_ONLY );
 }
 
@@ -399,10 +394,4 @@
 	md5_byte_t pass_md5[21];
 	md5_state_t md5_state;
-	
-	if( irc->password == NULL )
-	{
-		irc_usermsg( irc, "Please register yourself if you want to save your settings." );
-		return STORAGE_OTHER_ERROR;
-	}
 	
 	path2 = g_strdup( irc->nick );
