diff options
Diffstat (limited to 'user.c')
-rw-r--r-- | user.c | 51 |
1 files changed, 31 insertions, 20 deletions
@@ -84,7 +84,7 @@ int bbs_login( term_screen *ts ) { sds lg = sds_new("Loged in as "); sds usrn = sds_new( username_buf ); - sds_cat( lg, usrn ); + lg = sds_cat( lg, usrn ); bbs_log( NULL, lg ); sds_free( lg ); sds_free( usrn ); @@ -99,9 +99,10 @@ exit_login: //just for full fill libc example static int dir_username_selector (const struct dirent *unused) { - return 1; + return 1; } + static int user_cfg_handler( void *user, const char *section, const char *name, const char *value ) { @@ -117,6 +118,7 @@ static int user_cfg_handler( void *user, const char *section, const char *name, } + int bbs_login_auth( const char *dir, const char *username, const char *password ) { int ret=-1; @@ -130,42 +132,52 @@ int bbs_login_auth( const char *dir, const char *username, const char *password sds crct_fn = sds_new( username ); sds crct_postfix = sds_new( ".user" ); sds srch_f = sds_empty(); - sds_cat( srch_f, crct_dir ); - sds_cat( srch_f, crct_fn ); - sds_cat( srch_f, crct_postfix ); + srch_f = sds_cat( srch_f, crct_dir ); + srch_f = sds_cat( srch_f, crct_fn ); + srch_f = sds_cat( srch_f, crct_postfix ); + sds_free( crct_dir ); + sds_free( crct_fn ); + sds_free( crct_postfix ); //check dir for username pass n = scandir( dir, &eps, dir_username_selector, alphasort ); - if ( n < 0 ) return -1;//mem leak + if ( n < 0 ) + { + //if there is more stuff to be fried rearrange this block and resource + //unitilisation code + sds_free( srch_f ); + return -1;//mem leak + } for ( cnt=0; cnt<n; cnt++ ) { sds file_name = sds_new( eps[cnt]->d_name ); sds path_dir = sds_new( dir ); - sds path_name = sds_new( "" ); - sds_cat( path_name, path_dir ); - sds_cat( path_name, file_name ); + sds path_name = sds_empty( ); + path_name = sds_cat( path_name, path_dir ); + path_name = sds_cat( path_name, file_name ); //config file exist //PRINT("%s || %s \n", path_name, srch_f ); sleep( 3 ); - if ( sds_cmp( path_name, srch_f ) == 0 ) + if ( (sds_cmp( path_name, srch_f ) == 0) + && (found_file == 0) ) { - cnt = n; - found_file = 1; } - //sds_free( file_name ); - //sds_free( path_dir ); - //sds_free( path_name ); - //free( eps[cnt] ); + sds_free( file_name ); + sds_free( path_dir ); + sds_free( path_name ); + free( eps[cnt] ); } - //free( eps ); + free( eps ); //not good style //now we have patch and just open file and check if password match if ( found_file ) { user_config_file cfg; + + memset( &cfg, 0, sizeof(cfg) ); if ( ini_parse( srch_f, user_cfg_handler, &cfg ) < 0 ) { } else @@ -182,11 +194,10 @@ int bbs_login_auth( const char *dir, const char *username, const char *password //ERROR("InCorrect pass!\n");sleep(3); } } + if ( cfg.password != NULL ) + free( cfg.password ); } - sds_free( crct_dir ); - sds_free( crct_fn ); - sds_free( crct_postfix ); sds_free( srch_f ); return ret; |