Changeset 6738a67 for storage_xml.c


Ignore:
Timestamp:
2008-07-16T23:22:52Z (16 years ago)
Author:
Sven Moritz Hallberg <pesco@…>
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.
Message:

merge in latest trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • storage_xml.c

    r9730d72 r6738a67  
    2929#include "arc.h"
    3030#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
    3137
    3238typedef enum
     
    8086                char *nick = xml_attr( attr_names, attr_values, "nick" );
    8187                char *pass = xml_attr( attr_names, attr_values, "password" );
    82                 md5_byte_t *pass_dec = NULL;
     88                int st;
    8389               
    8490                if( !nick || !pass )
     
    8793                                     "Missing attributes for %s element", element_name );
    8894                }
    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;
    9198                        g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
    9299                                     "Error while decoding password attribute" );
    93100                }
     101                else if( st == 0 )
     102                {
     103                        if( xd->pass_st != XML_PASS_CHECK_ONLY )
     104                                xd->pass_st = XML_PASS_OK;
     105                }
    94106                else
    95107                {
    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                }
    125112        }
    126113        else if( xd->pass_st < XML_PASS_OK )
     
    262249static void xml_init( void )
    263250{
    264         if( access( global.conf->configdir, F_OK ) != 0 )
     251        if( g_access( global.conf->configdir, F_OK ) != 0 )
    265252                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 )
    267255                log_message( LOGLVL_WARNING, "Permission problem: Can't read/write from/to `%s'.", global.conf->configdir );
    268256}
     
    391379        g_free( path2 );
    392380       
    393         if( !overwrite && access( path, F_OK ) != -1 )
     381        if( !overwrite && g_access( path, F_OK ) == 0 )
    394382                return STORAGE_ALREADY_EXISTS;
    395383       
     
    428416                int pass_len;
    429417               
    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 );
    431419                pass_b64 = base64_encode( pass_cr, pass_len );
    432420                g_free( pass_cr );
     
    499487static storage_status_t xml_remove( const char *nick, const char *password )
    500488{
    501         char s[512];
     489        char s[512], *lc;
    502490        storage_status_t status;
    503491
     
    506494                return status;
    507495
    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       
    509501        if( unlink( s ) == -1 )
    510502                return STORAGE_OTHER_ERROR;
Note: See TracChangeset for help on using the changeset viewer.