library/src/filesystem/BP-Filesystem.cc
// Returns a file descriptor which can be used to write data to a temporary file.  It creates
// the temporary file using the correct permissions required.  Template must be something like:
//  ex.
//     /tmp/whateverdir/filewhatever-XXXXXX where the XXXXXX must be literally in the template and
//     is replaced dynamically via mkstemp.  Due to the nature of file descriptors, this function
//     has to return a non-standard error code.  It returns -1 on failure.
Returns a file descriptor which can be used to write data to a temporary file.  It creates
the temporary file using the correct permissions required.  Template must be something like:
ex.
tmp/whateverdir/filewhatever-XXXXXX where the XXXXXX must be literally in the template and
is replaced dynamically via mkstemp.  Due to the nature of file descriptors, this function
has to return a non-standard error code.  It returns -1 on failure.
Returns a file descriptor which can be used to write data to a temporary file . It creates the temporary file using the correct permissions required . Template must be something like : ex . tmp / whateverdir / filewhatever - XXXXXX where the XXXXXX must be literally in the template and is replaced dynamically via mkstemp . Due to the nature of file descriptors this function has to return a non - standard error code . It returns - 1 on failure .
int BP_FDCreateSecureTempFile(char *tmpfile_template_path)
{
	if(!tmpfile_template_path)
		return -1;
	if(!BP_StringIsReasonablePrintableString(tmpfile_template_path, bpstrlen(tmpfile_template_path), BP_FALSE, BP_FALSE))
		return -1;
	if(!strstr(tmpfile_template_path, "XXXXXX"))
	{
		printf("\n [!!] Err: Secure temporary file templates must contain XXXXXX");
		return -1;
	}
	int fd = mkstemp(tmpfile_template_path);
	if( fd == -1)
	{
		return -1;
	}
	unlink(tmpfile_template_path);
	return fd;
}
int BP_FDCreateSecureTempFile ( char * tmpfile_template_path ) { if ( ! tmpfile_template_path ) return -1 ; if ( ! BP_StringIsReasonablePrintableString ( tmpfile_template_path , bpstrlen ( tmpfile_template_path ) , BP_FALSE , BP_FALSE ) ) return -1 ; if ( ! strstr ( tmpfile_template_path , " " ) ) { printf ( " \n " ) ; return -1 ; } int fd = mkstemp ( tmpfile_template_path ) ; if ( fd == -1 ) { return -1 ; } unlink ( tmpfile_template_path ) ; return fd ; }
Returns a file descriptor which can be used to write data to a temporary file.
Returns a file descriptor which can be used to write data to a temporary file .
// ensure we have a template path // ensure the file path is reasonable // the tempfile must have XXXXXX // printf("\n Attempting to create tmpfile?: %s", tmpfile_template_path); // attempt to open temp file // check return // printf("\n Failed to create tmpfile: %s", tmpfile_template_path); // Unlink the file descriptor so that the files are // destroyed immediately after use (required for secure // temp file race-condition avoidance).  The file descriptor // will still be able to read and write from the filesystem // using the descriptor, but the file will be destroyed // securely when the descriptor closes. // return the file descriptor