diff options
| -rw-r--r-- | art/motd.txt | 2 | ||||
| -rw-r--r-- | door.c | 23 | ||||
| -rw-r--r-- | kconfig.h | 2 | ||||
| -rw-r--r-- | user.c | 51 | 
4 files changed, 53 insertions, 25 deletions
diff --git a/art/motd.txt b/art/motd.txt index f2cb7b5..a589ca4 100644 --- a/art/motd.txt +++ b/art/motd.txt @@ -24,4 +24,4 @@      \__,_|_|_|\___/ \_/\_/ \___|\__,_(_)___/|_|  \__, |                                                    __/ |                                                   |___/  -Source: ftp://bbs.hacking.allowed.org/microbbs-0.2.1.tar.gz +Source: ftp://bbs.hacking.allowed.org/microbbs-0.2.2.tar.gz @@ -10,6 +10,7 @@ static int dir_door_game_selector (const struct dirent *unused)    return 1;  } +  int bbs_door_start( term_screen *ts, const char *cmd )  {  	int ret=0; @@ -86,7 +87,8 @@ int bbs_door( term_screen *ts, const char *dir_name )  			{  				sds d_name = sds_new( eps[cnt]->d_name );  				sds pathname  = sds_new( door_game_dir ); -				sds_cat( pathname, d_name ); +				pathname = sds_cat( pathname, d_name ); +				sds_free( d_name );  				//!!!possible memleak unfreed d_name? @@ -100,12 +102,10 @@ int bbs_door( term_screen *ts, const char *dir_name )  					} else  					{  						sds_free( pathname ); -						sds_free( d_name );  					}  				} else   				{  					sds_free( pathname ); -					sds_free( d_name );  				}  				free( eps[cnt] );  			} @@ -199,7 +199,22 @@ int bbs_door( term_screen *ts, const char *dir_name )  	}  	//needed special care to free sds strings -	//llist_free( dir_list ); +	//dangerous stuff as list contains sds strings then we need to call sds_free +	//not just free, maybe try to use llist_manager it should handle that +	{ +		struct ListNode *iter=dir_list->first; +		while (iter != NULL) +		{ +			if ( iter->val != NULL ) +			{ +				sds_free( iter->val ); +				iter->val = NULL; +			} +			iter = iter->next; +		} + +	} +	llist_free( dir_list );  	return ret;  } @@ -4,6 +4,8 @@  #define CONFIG_TODO_DEFAULT_FILE "todo/todo.txt"  #define CONFIG_DOORGAMES  #define CONFIG_DOOR_DEFAULT_DIR "./door/" +#define CONFIG_LOGIN +#define CONFIG_USER_DEFAULT_DIR "./users/"  #define CONFIG_ARTICLES  #define CONFIG_MOTD  #define CONFIG_CAPTCHA @@ -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;  | 
