diff options
| author | Jelmer Vernooij <jelmer@samba.org> | 2005-12-08 17:00:08 +0100 | 
|---|---|---|
| committer | Jelmer Vernooij <jelmer@samba.org> | 2005-12-08 17:00:08 +0100 | 
| commit | 7cad7b41a0b661c38ae5f6239aaf58361788edc9 (patch) | |
| tree | 213ab238ece2ab120b7ec25f62b19224b37d6856 | |
| parent | 09adf08684c62fff0f507304ed37680137de4637 (diff) | |
Clearer seperation between crypting and generic password code
| -rw-r--r-- | commands.c | 4 | ||||
| -rw-r--r-- | crypting.c | 26 | ||||
| -rw-r--r-- | crypting.h | 3 | ||||
| -rw-r--r-- | irc.c | 18 | ||||
| -rw-r--r-- | irc.h | 1 | ||||
| -rw-r--r-- | storage_text.c | 6 | 
6 files changed, 28 insertions, 30 deletions
| @@ -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: @@ -51,8 +51,6 @@ typedef struct irc  #include <stdio.h>  #include <stdlib.h> -#define irc_usermsg -  #endif  /*\ @@ -61,21 +59,7 @@ typedef struct irc   * correctness.  \*/ -/* USE WITH CAUTION! -   Sets pass without checking */ -void setpassnc (irc_t *irc, const char *pass)  -{ -	if (irc->password) g_free (irc->password); -	 -	if (pass) { -		irc->password = g_strdup (pass); -		irc_usermsg (irc, "Password successfully changed"); -	} else { -		irc->password = NULL; -	} -} - -int setpass (irc_t *irc, const char *pass, const char* md5sum)  +int checkpass (const char *pass, const char *md5sum)  {  	md5_state_t md5state;  	md5_byte_t digest[16]; @@ -93,13 +77,11 @@ int setpass (irc_t *irc, const char *pass, const char* md5sum)  		if (digits[0] != md5sum[j]) return (-1);  		if (digits[1] != md5sum[j + 1]) return (-1);  	} -	 -	/* If pass is correct, we end up here and we set the pass */ -	setpassnc (irc, pass); -	 -	return (0); + +	return( 0 );  } +  char *hashpass (irc_t *irc) {  	md5_state_t md5state;  	md5_byte_t digest[16]; @@ -23,8 +23,7 @@    Suite 330, Boston, MA  02111-1307  USA  */ -void setpassnc (irc_t *irc, const char *pass); /* USE WITH CAUTION! */ -int setpass (irc_t *irc, const char *pass, const char* md5sum); +int checkpass (const char *password, const char *md5sum);  char *hashpass (irc_t *irc);  char *obfucrypt (irc_t *irc, char *line);  char *deobfucrypt (irc_t *irc, char *line); @@ -31,9 +31,9 @@ static gboolean irc_userping( gpointer _irc );  GSList *irc_connection_list = NULL; -char *passchange (irc_t *irc, void *set, char *value)  +static char *passchange (irc_t *irc, void *set, char *value)   { -	setpassnc (irc, value); +	irc_setpass (irc, value);  	return (NULL);  } @@ -267,6 +267,20 @@ void irc_free(irc_t * irc)  		g_main_quit( global.loop );  } +/* USE WITH CAUTION! +   Sets pass without checking */ +void irc_setpass (irc_t *irc, const char *pass)  +{ +	if (irc->password) g_free (irc->password); +	 +	if (pass) { +		irc->password = g_strdup (pass); +		irc_usermsg (irc, "Password successfully changed"); +	} else { +		irc->password = NULL; +	} +} +  int irc_process( irc_t *irc )  {  	char **lines, *temp;	 @@ -136,6 +136,7 @@ void irc_kill( irc_t *irc, user_t *u );  void irc_invite( irc_t *irc, char *nick, char *channel );  void irc_whois( irc_t *irc, char *nick );  int irc_away( irc_t *irc, char *away ); +void irc_setpass( irc_t *irc, const char *pass ); /* USE WITH CAUTION! */  int irc_send( irc_t *irc, char *nick, char *s, int flags );  int irc_privmsg( irc_t *irc, user_t *u, char *type, char *to, char *prefix, char *msg ); diff --git a/storage_text.c b/storage_text.c index 004e891c..f3ca8a38 100644 --- a/storage_text.c +++ b/storage_text.c @@ -52,7 +52,8 @@ static storage_status_t text_load ( const char *my_nick, const char* password, i     	if( !fp ) return STORAGE_NO_SUCH_USER;  	fscanf( fp, "%32[^\n]s", s ); -	if( setpass( irc, password, s ) < 0 ) + +	if (checkpass (password, s) != 0)   	{  		fclose( fp );  		return STORAGE_INVALID_PASSWORD; @@ -276,7 +277,8 @@ static storage_status_t text_check_pass( const char *nick, const char *password  	fscanf( fp, "%32[^\n]s", s );  	fclose( fp ); -	/*FIXME: Check password */ +	if (checkpass( password, s) == -1) +		return STORAGE_INVALID_PASSWORD;  	return STORAGE_OK;  } | 
