library/src/network/httpd/BP-HTTPdUsers.cc
// Attempt to load user tables via JSON file.
Attempt to load user tables via JSON file.
Attempt to load user tables via JSON file .
BP_ERROR_T BP_HTTPdUserLoadFromJSONFile(P_BP_HTTPD_SESSION httpd, char *path_to_json_file)
{
	if(!path_to_json_file)
		return ERR_FAILURE;
	if(!BP_StringIsReasonableForUnixEXT4Filename(path_to_json_file, bpstrlen(path_to_json_file), BP_TRUE))
		return ERR_FAILURE;
	char json_file_sha1[60];
	BP_ZERO_STACK(json_file_sha1);
	BP_FileSHA1Contents(path_to_json_file, (char *) &json_file_sha1);
	if(bpstrlen(json_file_sha1) != 40)
	{
		printf("\n [!!] Error: Failed to generate SHA1 sum for user json file: (file len: %zu)", bpstrlen(json_file_sha1));
		return ERR_FAILURE;
	}
	BP_FILE_LOAD_EXTRA_INFO load_extra_info;
	BP_ZERO_STACK(load_extra_info);
	load_extra_info.check_contents_sha1 = BP_TRUE;
	char * file_load = BP_FileGetContents(path_to_json_file, &load_extra_info);
	if(!file_load)
	{
		printf("\n [!!] Error: Failed to load user json file.  Could not read file into memory.");
		return ERR_FAILURE;
	}
	if(load_extra_info.sha1_sum_generated_ok != BP_TRUE)
	{
		bpfree(file_load);
		printf("\n [!!] SHA1 sum failed when loading user json file.  Potential TOCTOU tampering detected.");
		return ERR_FAILURE;
	}
	if(!BP_StringsMatchAsReasonableStrings((char *) &load_extra_info.sha1_sum, (char *) &json_file_sha1))
	{
		bpfree(file_load);
		printf("\n [!!] SHA1 sum mismatch when loading user json file.  Potential TOCTOU tampering detected.");
		return ERR_FAILURE;
	}
	%%
	%%
	BP_ERROR_T load_status = BP_HTTPdUserLoadFromJSONBuffer
	(
		httpd,
		file_load
	);
	if(!load_status)
	{
		bpfree(file_load);
		printf("\n [!!] Error: Failed to add users from JSON buffer.");
		return ERR_FAILURE;
	}
	return ERR_SUCCESS;
}
BP_ERROR_T BP_HTTPdUserLoadFromJSONFile ( P_BP_HTTPD_SESSION httpd , char * path_to_json_file ) { if ( ! path_to_json_file ) return ERR_FAILURE ; if ( ! BP_StringIsReasonableForUnixEXT4Filename ( path_to_json_file , bpstrlen ( path_to_json_file ) , BP_TRUE ) ) return ERR_FAILURE ; char json_file_sha1 [ 60 ] ; BP_ZERO_STACK ( json_file_sha1 ) ; BP_FileSHA1Contents ( path_to_json_file , ( char * ) & json_file_sha1 ) ; if ( bpstrlen ( json_file_sha1 ) != 40 ) { printf ( " \n " , bpstrlen ( json_file_sha1 ) ) ; return ERR_FAILURE ; } BP_FILE_LOAD_EXTRA_INFO load_extra_info ; BP_ZERO_STACK ( load_extra_info ) ; load_extra_info . check_contents_sha1 = BP_TRUE ; char * file_load = BP_FileGetContents ( path_to_json_file , & load_extra_info ) ; if ( ! file_load ) { printf ( " \n " ) ; return ERR_FAILURE ; } if ( load_extra_info . sha1_sum_generated_ok != BP_TRUE ) { bpfree ( file_load ) ; printf ( " \n " ) ; return ERR_FAILURE ; } if ( ! BP_StringsMatchAsReasonableStrings ( ( char * ) & load_extra_info . sha1_sum , ( char * ) & json_file_sha1 ) ) { bpfree ( file_load ) ; printf ( " \n " ) ; return ERR_FAILURE ; } BP_ERROR_T load_status = BP_HTTPdUserLoadFromJSONBuffer ( httpd , file_load ) ; if ( ! load_status ) { bpfree ( file_load ) ; printf ( " \n " ) ; return ERR_FAILURE ; } return ERR_SUCCESS ; }
Attempt to load user tables via JSON file.
Attempt to load user tables via JSON file .
// ensure there's a json file to load from // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Run Secure Load Steps %%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // create space to hold sha1 // attempt to sha1 contents // setup local extra info structure // mark flag to create sha1 content during content retrieval // attempt to actually load buffer // if the file failed to load // check to ensure that sha1 sum generated ok // ensure hashes match // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Attempt to Load Users from JSON Directly %%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // load from json buffer // load status // destroy the loaded file before exiting // return indicating success