Changeset 6738a67 for storage_xml.c
- Timestamp:
- 2008-07-16T23:22:52Z (16 years ago)
- Branches:
- master
- Children:
- 9b55485
- Parents:
- 9730d72 (diff), 6a78c0e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
storage_xml.c
r9730d72 r6738a67 29 29 #include "arc.h" 30 30 #include "md5.h" 31 #include <glib/gstdio.h> 32 33 #if !GLIB_CHECK_VERSION(2,8,0) 34 /* GLib < 2.8.0 doesn't have g_access, so just use the system access(). */ 35 #define g_access access 36 #endif 31 37 32 38 typedef enum … … 80 86 char *nick = xml_attr( attr_names, attr_values, "nick" ); 81 87 char *pass = xml_attr( attr_names, attr_values, "password" ); 82 md5_byte_t *pass_dec = NULL;88 int st; 83 89 84 90 if( !nick || !pass ) … … 87 93 "Missing attributes for %s element", element_name ); 88 94 } 89 else if( base64_decode( pass, &pass_dec ) != 21 ) 90 { 95 else if( ( st = md5_verify_password( xd->given_pass, pass ) ) == -1 ) 96 { 97 xd->pass_st = XML_PASS_WRONG; 91 98 g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, 92 99 "Error while decoding password attribute" ); 93 100 } 101 else if( st == 0 ) 102 { 103 if( xd->pass_st != XML_PASS_CHECK_ONLY ) 104 xd->pass_st = XML_PASS_OK; 105 } 94 106 else 95 107 { 96 md5_byte_t pass_md5[16]; 97 md5_state_t md5_state; 98 int i; 99 100 md5_init( &md5_state ); 101 md5_append( &md5_state, (md5_byte_t*) xd->given_pass, strlen( xd->given_pass ) ); 102 md5_append( &md5_state, (md5_byte_t*) pass_dec + 16, 5 ); /* Hmmm, salt! */ 103 md5_finish( &md5_state, pass_md5 ); 104 105 for( i = 0; i < 16; i ++ ) 106 { 107 if( pass_dec[i] != pass_md5[i] ) 108 { 109 xd->pass_st = XML_PASS_WRONG; 110 g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, 111 "Password mismatch" ); 112 break; 113 } 114 } 115 116 /* If we reached the end of the loop, it was a match! */ 117 if( i == 16 ) 118 { 119 if( xd->pass_st != XML_PASS_CHECK_ONLY ) 120 xd->pass_st = XML_PASS_OK; 121 } 122 } 123 124 g_free( pass_dec ); 108 xd->pass_st = XML_PASS_WRONG; 109 g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, 110 "Password mismatch" ); 111 } 125 112 } 126 113 else if( xd->pass_st < XML_PASS_OK ) … … 262 249 static void xml_init( void ) 263 250 { 264 if( access( global.conf->configdir, F_OK ) != 0 )251 if( g_access( global.conf->configdir, F_OK ) != 0 ) 265 252 log_message( LOGLVL_WARNING, "The configuration directory `%s' does not exist. Configuration won't be saved.", global.conf->configdir ); 266 else if( access( global.conf->configdir, R_OK ) != 0 || access( global.conf->configdir, W_OK ) != 0 ) 253 else if( g_access( global.conf->configdir, F_OK ) != 0 || 254 g_access( global.conf->configdir, W_OK ) != 0 ) 267 255 log_message( LOGLVL_WARNING, "Permission problem: Can't read/write from/to `%s'.", global.conf->configdir ); 268 256 } … … 391 379 g_free( path2 ); 392 380 393 if( !overwrite && access( path, F_OK ) != -1)381 if( !overwrite && g_access( path, F_OK ) == 0 ) 394 382 return STORAGE_ALREADY_EXISTS; 395 383 … … 428 416 int pass_len; 429 417 430 pass_len = arc_encode( acc->pass, strlen( acc->pass ), (unsigned char**) &pass_cr, irc->password );418 pass_len = arc_encode( acc->pass, strlen( acc->pass ), (unsigned char**) &pass_cr, irc->password, 12 ); 431 419 pass_b64 = base64_encode( pass_cr, pass_len ); 432 420 g_free( pass_cr ); … … 499 487 static storage_status_t xml_remove( const char *nick, const char *password ) 500 488 { 501 char s[512] ;489 char s[512], *lc; 502 490 storage_status_t status; 503 491 … … 506 494 return status; 507 495 508 g_snprintf( s, 511, "%s%s%s", global.conf->configdir, nick, ".xml" ); 496 lc = g_strdup( nick ); 497 nick_lc( lc ); 498 g_snprintf( s, 511, "%s%s%s", global.conf->configdir, lc, ".xml" ); 499 g_free( lc ); 500 509 501 if( unlink( s ) == -1 ) 510 502 return STORAGE_OTHER_ERROR;
Note: See TracChangeset
for help on using the changeset viewer.