Beispiel #1
0
int xWrite(sqlite3_file*file, const void*buffer, int iAmt, sqlite3_int64 iOfst)
{
	struct my_file_data *my_file = (struct my_file_data*)file;
	size_t actual;
#ifdef LOG_OPERATIONS
	lprintf( "Write %s %d at %d", my_file->filename, iAmt, iOfst );
	//LogBinary( buffer, iAmt );
#endif
	{
		size_t filesize = sack_fsize( my_file->file );
		if( filesize < iOfst )
		{
			static unsigned char *filler;
			if( !filler )
			{
				filler = NewArray( unsigned char, 512 );
				MemSet( filler, 0, 512 );
			}
			sack_fseek( my_file->file, 0, SEEK_END );
			while( filesize < iOfst )
			{
				if( ( iOfst - filesize ) >= 512 )
				{
					sack_fwrite( filler, 1, 512, my_file->file );
					filesize += 512;
				}
				else
				{
					sack_fwrite( filler, 1, ( iOfst - filesize ), my_file->file );
					filesize += ( iOfst - filesize );
				}
			}
		}
	}
Beispiel #2
0
static LOGICAL CPROC ExtractFile( CTEXTSTR name )
{
    if( StrCmp( name, ".app.config" ) == 0 ) {
        FILE *file = sack_fopenEx( 0, name, "rb", l.rom );
        if( file )
        {
            size_t sz = sack_fsize( file );
            if( sz )
            {
                POINTER data = NewArray( uint8_t, sz );
                sack_fread( data, 1, sz, file );
                ProcessConfigurationInput( l.pch, data, sz, 0 );
                if( !l.target_path )
                    l.target_path = ".";
                Release( data );
            }
            sack_fclose( file );
        }
    } else {
        FILE *file;
        file = sack_fopenEx( 0, name, "rb", l.rom );
        if( file )
        {
            size_t sz = sack_fsize( file );
            if( sz )
            {
                POINTER data = NewArray( uint8_t, sz );
                sack_fread( data, 1, sz, file );

                /* this is where the file should be output */
                {
                    char target[256];
                    char *tmp;
                    snprintf( target, 256, "%s/%s", l.target_path, name );
                    tmp = (char*)pathrchr( target );
                    if( tmp ) {
                        tmp[0] = 0;
                        if( !l.prior_output_path
                                || StrCmp( l.prior_output_path, target ) ) {
                            l.prior_output_path = strdup( target );
                            MakePath( target );
                        }
                        tmp[0] = '/';
                    }
                    {
                        FILE *out;
                        out = sack_fopenEx( 0, target, "wb", sack_get_default_mount() );
                        if( out ) {
                            if( !l.first_file )
                                l.first_file = strdup( target );
                            sack_fwrite( data, 1, sz, out );
                            sack_fclose( out );
                        }
                    }
                }
                Release( data );
            }
            sack_fclose( file );
            return TRUE;
        }
    }

    return FALSE;
}
Beispiel #3
0
static int32_t loadRsaKeys( sslKeys_t *keys, LOGICAL client )
{
	uint32_t priv_key_len = 0;
	uint32_t cert_key_len = 0;
	unsigned char *CAstream = NULL;
	int32_t CAstreamLen = 0;
	int32_t rc;
	TEXTCHAR buf[256];
	TEXTCHAR privkey_buf[256];
	TEXTCHAR cert_buf[256];
	unsigned char *priv_key = NULL;
	unsigned char *cert_key = NULL;
	FILE *file;
	size_t size;
	int fileGroup = GetFileGroup( "ssl certs", "certs" );
	{

	/*
		In-memory based keys
		Build the CA list first for potential client auth usage
	*/
		int n;
		CAstreamLen = 0;
		for( n = 0; n < ( sizeof( default_certs ) / sizeof( default_certs[0] ) ); n++ )
		{
			file = sack_fopen( fileGroup, default_certs[n], "rb" );
			if( file )
			{
				size = sack_fsize( file );
				CAstreamLen += size;
				sack_fclose( file );
			}
		}
		{
			/*
			 In-memory based keys
			 Build the CA list first for potential client auth usage
			 */
			priv_key_len = 0;
			SACK_GetProfileString( "SSL/Private Key", "filename", "myprivkey.pem", privkey_buf, 256 );
			file = sack_fopen( fileGroup, privkey_buf, "rb" );
			if( file )
			{
				priv_key_len = sack_fsize( file );
				priv_key = NewArray( uint8_t, priv_key_len );

				sack_fread( priv_key, 1, priv_key_len, file );
				sack_fclose( file );
			}
			else
				priv_key = NULL;
		}

		SACK_GetProfileString( "SSL/Cert Authority Extra", "filename", "mycert.pem", cert_buf, 256 );
		file = sack_fopen( fileGroup, cert_buf, "rb" );
		if( file )
		{
			CAstreamLen += sack_fsize( file );
			sack_fclose( file );
		}

		if( CAstreamLen )
			CAstream = NewArray( uint8_t, CAstreamLen);
		CAstreamLen = 0;
		for( n = 0; n < ( sizeof( default_certs ) / sizeof( default_certs[0] ) ); n++ )
		{
			file = sack_fopen( fileGroup, default_certs[n], "rb" );
			if( file )
			{
				size = sack_fsize( file );
				CAstreamLen += sack_fread( CAstream + CAstreamLen, 1, size, file );
				//rc = matrixSslLoadRsaKeysMem(keys, NULL, 0, NULL, 0, CAstream+ CAstreamLen, size );
				//lprintf( "cert success : %d %s", rc, default_certs[n] );

				//CAstream[CAstreamLen++] = '\n';
				sack_fclose( file );
			}
		}

		file = sack_fopen( fileGroup, cert_buf, "rb" );
		if( file )
		{
			size = sack_fsize( file );
			CAstreamLen += sack_fread( CAstream + CAstreamLen, 1, size, file );
			sack_fclose( file );
		}
	}

	//if( 0 )
	{
	/*
		In-memory based keys
		Build the CA list first for potential client auth usage
	*/
		cert_key_len = 0;
		SACK_GetProfileString( "SSL/Certificate", "filename", "mycert.pem", cert_buf, 256 );
		file = sack_fopen( fileGroup, cert_buf, "rb" );
		if( file )
		{
			cert_key_len = sack_fsize( file );
			cert_key = NewArray( uint8_t, cert_key_len );

			sack_fread( cert_key, 1, cert_key_len, file );
			sack_fclose( file );
		}
		else
			cert_key = NULL;
	}

	if( cert_key_len || priv_key_len || CAstreamLen )
	{
		rc = matrixSslLoadRsaKeysMem(keys
			, cert_key, cert_key_len
			, priv_key, priv_key_len
			, CAstream, CAstreamLen );

		if (rc < 0) {
			lprintf("No certificate material loaded.  Exiting");
			//if (CAstream) {
			//	Deallocate(uint8_t*, CAstream);
			//}
			matrixSslDeleteKeys(keys);
			matrixSslClose();
		}
		if( cert_key_len )
			Release( cert_key );
		if( priv_key_len )
			Release( priv_key );
		if( CAstream )
			Release( CAstream );
		return rc;
	}
	return PS_SUCCESS;
}