library/src/databases/bpdb/BP-DBStringFilters.cc
// checks if a host name is reasonable for a mariadb host connect string (must be host or ip address)
checks if a host name is reasonable for a mariadb host connect string (must be host or ip address)
checks if a host name is reasonable for a mariadb host connect string ( must be host or ip address )
BP_BOOL BP_StringIsReasonableForUsernameMariaDB(char *buffer, size_t len)
{
	if(!buffer || !len)
		return BP_FALSE;
	if(!BP_StringIsReasonablePrintableString(buffer, len, BP_FALSE, BP_FALSE))
		return BP_FALSE;
	if(strlen(buffer) != len)
		return BP_FALSE;
	if(len > 64)
		return BP_FALSE;
	BP_BUFFER_ANALYSIS_ASCII_CONFIGURATION ascii_config;
	BP_ZERO_STACK(ascii_config);
	ascii_config.count_ascii                      = BP_TRUE;
	P_BP_BUFFER_ANALYSIS buff_analysis = BP_CreateBufferAnalysis
	(
			(unsigned char *) buffer,
			(size_t) len,
			&ascii_config
	);
	if(!buff_analysis)
		return BP_FALSE;
	size_t buff_filter_ctr = 0;
	buff_filter_ctr += buff_analysis->ascii->char_counts['0'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['1'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['2'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['3'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['4'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['5'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['6'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['7'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['8'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['9'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['a'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['b'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['c'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['d'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['e'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['f'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['g'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['h'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['i'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['j'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['k'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['l'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['m'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['n'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['o'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['p'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['q'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['r'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['s'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['t'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['u'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['v'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['w'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['x'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['y'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['z'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['A'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['B'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['C'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['D'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['E'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['F'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['G'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['H'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['I'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['J'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['K'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['L'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['M'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['N'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['O'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['P'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['Q'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['R'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['S'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['T'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['U'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['V'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['W'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['X'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['Y'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['Z'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['_'];
	buff_filter_ctr += buff_analysis->ascii->char_counts['$'];
	if(buff_filter_ctr != len)
	{
		BP_DestroyBufferAnalysis(buff_analysis);
		return BP_FALSE;
	}
	BP_DestroyBufferAnalysis(buff_analysis);
	return BP_TRUE;
}
BP_BOOL BP_StringIsReasonableForUsernameMariaDB ( char * buffer , size_t len ) { if ( ! buffer || ! len ) return BP_FALSE ; if ( ! BP_StringIsReasonablePrintableString ( buffer , len , BP_FALSE , BP_FALSE ) ) return BP_FALSE ; if ( strlen ( buffer ) != len ) return BP_FALSE ; if ( len > 64 ) return BP_FALSE ; BP_BUFFER_ANALYSIS_ASCII_CONFIGURATION ascii_config ; BP_ZERO_STACK ( ascii_config ) ; ascii_config . count_ascii = BP_TRUE ; P_BP_BUFFER_ANALYSIS buff_analysis = BP_CreateBufferAnalysis ( ( unsigned char * ) buffer , ( size_t ) len , & ascii_config ) ; if ( ! buff_analysis ) return BP_FALSE ; size_t buff_filter_ctr = 0 ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; buff_filter_ctr += buff_analysis -> ascii -> char_counts [ ' ' ] ; if ( buff_filter_ctr != len ) { BP_DestroyBufferAnalysis ( buff_analysis ) ; return BP_FALSE ; } BP_DestroyBufferAnalysis ( buff_analysis ) ; return BP_TRUE ; }
checks if a host name is reasonable for a mariadb host connect string (must be host or ip address)
checks if a host name is reasonable for a mariadb host connect string ( must be host or ip address )
// attempt to verify that the string is reasonable first // check buffer // max database name length is 64 (from mysql.com section on identifiers) // create ascii configuration // zero out the structure (automagic macro) // set some flags in the structure to count ascii (we already counted invalid with our initial check) // attempt to generate analysis // ensure we h ave a buffer analysis // if the filter count matches total count, filter passes check (simple+fast check) // -- digits -- // -- lower case -- // -- upper case ------- // -- special chars ---- (underscore and dollarsign are allowed chars) // if the filter counter of all the allowed characters does not // equal our total length, we have encountered a bad string and // must exit. // destroy the buffer analysis // return indicating that the path is suitable