library/src/network/httpd/BP-HTTPdUsers.cc
// attempts to create a JSON tree containing a valid httpd user record.  (used for modifying user registry)
attempts to create a JSON tree containing a valid httpd user record.  (used for modifying user registry)
attempts to create a JSON tree containing a valid httpd user record . ( used for modifying user registry )
P_BP_JSON BP_HTTPdCreateUserJSON
(
	BP_HTTPD_USER_ACCESS             access,
	BP_HTTPD_USER_TYPE               type,
	BP_HTTPD_USER_PASSWORD_HASH_TYPE hash_type,
	char *                           username,
	char *                           password,
	char *                           email,
	char *                           bio,
	char *                           role
)
{
	if(!BP_StringIsReasonableForUsernameMariaDB(username, bpstrlen(username)))
	{
		return NULL;
	}
	if(!BP_StringIsReasonableForPasswordMariaDB(password, bpstrlen(password)))
	{
		return NULL;
	}
	if(!BP_StringIsValidEmailAddress(email))
	{
		return NULL;
	}
	if(!BP_StringIsReasonablePrintableString(bio, bpstrlen(bio), BP_FALSE, BP_FALSE))
	{
		return NULL;
	}
	if(!BP_StringIsReasonablePrintableString(role, bpstrlen(role), BP_FALSE, BP_FALSE))
	{
		return NULL;
	}
	P_BP_JSON new_user_json = BP_JSONCreate();
	if(!new_user_json)
		return NULL;
	char *user_path[20];
	BP_ZERO_STACK(user_path);
	user_path[1] = "access_level";
	switch(access)
	{
		case BP_HTTPD_USER_ACCESS_ANONYMOUS_GUEST:
			BP_JSONAddNodeByPath(new_user_json, (char **) &user_path, "anonymous_guest", bpstrlen("anonymous_guest"), BP_FALSE);
			break;
		case BP_HTTPD_USER_ACCESS_DEMIGOD:
			BP_JSONAddNodeByPath(new_user_json, (char **) &user_path, "demigod", bpstrlen("demigod"), BP_FALSE);
			break;
		case BP_HTTPD_USER_ACCESS_GOD:
			BP_JSONAddNodeByPath(new_user_json, (char **) &user_path, "god", bpstrlen("god"), BP_FALSE);
			break;
		case BP_HTTPD_USER_ACCESS_GUEST:
			BP_JSONAddNodeByPath(new_user_json, (char **) &user_path, "guest", bpstrlen("guest"), BP_FALSE);
			break;
		case BP_HTTPD_USER_ACCESS_MORTAL:
			BP_JSONAddNodeByPath(new_user_json, (char **) &user_path, "mortal", bpstrlen("mortal"), BP_FALSE);
			break;
		case BP_HTTPD_USER_ACCESS_SEMIGOD:
			BP_JSONAddNodeByPath(new_user_json, (char **) &user_path, "semigod", bpstrlen("semigod"), BP_FALSE);
			break;
		default:
			BP_JSONAddNodeByPath(new_user_json, (char **) &user_path, "invalid", bpstrlen("invalid"), BP_FALSE);
			break;
	}
	user_path[1] = "type";
	switch(type)
	{
		case BP_HTTPD_USER_TYPE_ANONYMOUS_GUEST:
			BP_JSONAddNodeByPath(new_user_json, (char **) &user_path, "anonymous_guest", bpstrlen("anonymous_guest"), BP_FALSE);
			break;
		case BP_HTTPD_USER_TYPE_LOCAL:
			BP_JSONAddNodeByPath(new_user_json, (char **) &user_path, "local", bpstrlen("local"), BP_FALSE);
			break;
		case BP_HTTPD_USER_TYPE_GLOBALDB:
			BP_JSONAddNodeByPath(new_user_json, (char **) &user_path, "globaldb", bpstrlen("globaldb"), BP_FALSE);
			break;
		default:
			BP_JSONAddNodeByPath(new_user_json, (char **) &user_path, "invalid", bpstrlen("invalid"), BP_FALSE);
			break;
	}
	user_path[1] = "hash_type";
	switch(hash_type)
	{
		case BP_HTTPD_USER_PASSWORD_HASH_TYPE_MD5:
			printf("\n [!!] MD5 User Passwords are not supported for security reasons (too easy to crack)");
			break;
		case BP_HTTPD_USER_PASSWORD_HASH_TYPE_SHA1:
			BP_JSONAddNodeByPath(new_user_json, (char **) &user_path, "sha1", bpstrlen("sha1"), BP_FALSE);
			break;
		case BP_HTTPD_USER_PASSWORD_HASH_TYPE_SHA256:
			BP_JSONAddNodeByPath(new_user_json, (char **) &user_path, "sha256", bpstrlen("sha256"), BP_FALSE);
			break;
		default:
			BP_JSONAddNodeByPath(new_user_json, (char **) &user_path, "invalid", bpstrlen("invalid"), BP_FALSE);
			break;
	}
	user_path[0] = username;
	BP_JSONAddTableByPath(new_user_json, (char **) &user_path, BP_FALSE);
	user_path[1] = "enabled";
	BP_JSONAddNodeByPath(new_user_json, (char **) &user_path, "yes", bpstrlen("yes"), BP_FALSE);
	user_path[1] = "email";
	BP_JSONAddNodeByPath(new_user_json, (char **) &user_path, email, bpstrlen(email), BP_FALSE);
	user_path[1] = "bio";
	BP_JSONAddNodeByPath(new_user_json, (char **) &user_path, bio, bpstrlen(bio), BP_FALSE);
	user_path[1] = "role";
	BP_JSONAddNodeByPath(new_user_json, (char **) &user_path, role, bpstrlen(role), BP_FALSE);
	return new_user_json;
}
P_BP_JSON BP_HTTPdCreateUserJSON ( BP_HTTPD_USER_ACCESS access , BP_HTTPD_USER_TYPE type , BP_HTTPD_USER_PASSWORD_HASH_TYPE hash_type , char * username , char * password , char * email , char * bio , char * role ) { if ( ! BP_StringIsReasonableForUsernameMariaDB ( username , bpstrlen ( username ) ) ) { return NULL ; } if ( ! BP_StringIsReasonableForPasswordMariaDB ( password , bpstrlen ( password ) ) ) { return NULL ; } if ( ! BP_StringIsValidEmailAddress ( email ) ) { return NULL ; } if ( ! BP_StringIsReasonablePrintableString ( bio , bpstrlen ( bio ) , BP_FALSE , BP_FALSE ) ) { return NULL ; } if ( ! BP_StringIsReasonablePrintableString ( role , bpstrlen ( role ) , BP_FALSE , BP_FALSE ) ) { return NULL ; } P_BP_JSON new_user_json = BP_JSONCreate ( ) ; if ( ! new_user_json ) return NULL ; char * user_path [ 20 ] ; BP_ZERO_STACK ( user_path ) ; user_path [ 1 ] = " " ; switch ( access ) { case BP_HTTPD_USER_ACCESS_ANONYMOUS_GUEST : BP_JSONAddNodeByPath ( new_user_json , ( char * * ) & user_path , " " , bpstrlen ( " " ) , BP_FALSE ) ; break ; case BP_HTTPD_USER_ACCESS_DEMIGOD : BP_JSONAddNodeByPath ( new_user_json , ( char * * ) & user_path , " " , bpstrlen ( " " ) , BP_FALSE ) ; break ; case BP_HTTPD_USER_ACCESS_GOD : BP_JSONAddNodeByPath ( new_user_json , ( char * * ) & user_path , " " , bpstrlen ( " " ) , BP_FALSE ) ; break ; case BP_HTTPD_USER_ACCESS_GUEST : BP_JSONAddNodeByPath ( new_user_json , ( char * * ) & user_path , " " , bpstrlen ( " " ) , BP_FALSE ) ; break ; case BP_HTTPD_USER_ACCESS_MORTAL : BP_JSONAddNodeByPath ( new_user_json , ( char * * ) & user_path , " " , bpstrlen ( " " ) , BP_FALSE ) ; break ; case BP_HTTPD_USER_ACCESS_SEMIGOD : BP_JSONAddNodeByPath ( new_user_json , ( char * * ) & user_path , " " , bpstrlen ( " " ) , BP_FALSE ) ; break ; default : BP_JSONAddNodeByPath ( new_user_json , ( char * * ) & user_path , " " , bpstrlen ( " " ) , BP_FALSE ) ; break ; } user_path [ 1 ] = " " ; switch ( type ) { case BP_HTTPD_USER_TYPE_ANONYMOUS_GUEST : BP_JSONAddNodeByPath ( new_user_json , ( char * * ) & user_path , " " , bpstrlen ( " " ) , BP_FALSE ) ; break ; case BP_HTTPD_USER_TYPE_LOCAL : BP_JSONAddNodeByPath ( new_user_json , ( char * * ) & user_path , " " , bpstrlen ( " " ) , BP_FALSE ) ; break ; case BP_HTTPD_USER_TYPE_GLOBALDB : BP_JSONAddNodeByPath ( new_user_json , ( char * * ) & user_path , " " , bpstrlen ( " " ) , BP_FALSE ) ; break ; default : BP_JSONAddNodeByPath ( new_user_json , ( char * * ) & user_path , " " , bpstrlen ( " " ) , BP_FALSE ) ; break ; } user_path [ 1 ] = " " ; switch ( hash_type ) { case BP_HTTPD_USER_PASSWORD_HASH_TYPE_MD5 : printf ( " \n " ) ; break ; case BP_HTTPD_USER_PASSWORD_HASH_TYPE_SHA1 : BP_JSONAddNodeByPath ( new_user_json , ( char * * ) & user_path , " " , bpstrlen ( " " ) , BP_FALSE ) ; break ; case BP_HTTPD_USER_PASSWORD_HASH_TYPE_SHA256 : BP_JSONAddNodeByPath ( new_user_json , ( char * * ) & user_path , " " , bpstrlen ( " " ) , BP_FALSE ) ; break ; default : BP_JSONAddNodeByPath ( new_user_json , ( char * * ) & user_path , " " , bpstrlen ( " " ) , BP_FALSE ) ; break ; } user_path [ 0 ] = username ; BP_JSONAddTableByPath ( new_user_json , ( char * * ) & user_path , BP_FALSE ) ; user_path [ 1 ] = " " ; BP_JSONAddNodeByPath ( new_user_json , ( char * * ) & user_path , " " , bpstrlen ( " " ) , BP_FALSE ) ; user_path [ 1 ] = " " ; BP_JSONAddNodeByPath ( new_user_json , ( char * * ) & user_path , email , bpstrlen ( email ) , BP_FALSE ) ; user_path [ 1 ] = " " ; BP_JSONAddNodeByPath ( new_user_json , ( char * * ) & user_path , bio , bpstrlen ( bio ) , BP_FALSE ) ; user_path [ 1 ] = " " ; BP_JSONAddNodeByPath ( new_user_json , ( char * * ) & user_path , role , bpstrlen ( role ) , BP_FALSE ) ; return new_user_json ; }
attempts to create a JSON tree containing a valid httpd user record.
attempts to create a JSON tree containing a valid httpd user record .
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Run Basic Checks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // check username // check password // check email // check bio // check role // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Create JSON and Add Table Entries %%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // create new json object // set path info // --- add access ------------------------- // add access level // switch on the access level and determine privilege // --- add type ------------------------------ // switch on the type // --- add hash type ------------------------- // switch on the type // md5 not supported // sha1 // sha256 // default is invalid case // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Add String Vals To JSON %%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // add user table to json // add username // add username // add bio // add role // return the JSON registry