Esempio n. 1
0
static void CPROC CheckFiles( uintptr_t psv )
{
	INDEX idx;
	struct input_file *file;
	if( l.flags.bLog )
		lprintf( WIDE("Check Files...") );
	LIST_FORALL( l.files, idx, struct input_file*, file )
	{
		FILE *input;
		static TEXTCHAR buf[256];
		if( l.flags.bLog )
			lprintf( WIDE("check %s"), file->filename );
		input = sack_fopen( 0, file->filename, WIDE("rt") );
		if( input )
		{
			INDEX var_idx = 0;
			while( fgets( buf, sizeof( buf ), input ) )
			{
				size_t end;
				struct variable_tracker *var =(struct variable_tracker*)GetLink( &file->vars, var_idx );
				//lprintf( WIDE("buf .. %s"), buf );
				while( ( end = strlen(buf) ) && ( buf[end-1] == '\n' ) )
					buf[end-1] = 0;
				if( l.flags.bLog )
					lprintf( WIDE("Content %p %s"), var, buf );
				if( !var )
				{
					TEXTCHAR tmp_name[128];
					snprintf( tmp_name, sizeof( tmp_name ), WIDE("<File %s.%d>"), file->varname, var_idx+1 );
					var = New( struct variable_tracker );
					var->var_content = StrDup( buf );
					var->var_name = StrDup( tmp_name );
					lprintf( WIDE("Newvar %s=%s"), tmp_name, buf );
					var->variable = CreateLabelVariable( tmp_name, LABEL_TYPE_STRING, &var->var_content );
					SetLink( &file->vars, var_idx, var );
				}
				else
				{
					if( StrCmp( var->var_content, buf ) )
					{
						Release( var->var_content );
						var->var_content = StrDup( buf );
						lprintf( WIDE("Change var %s=%s"), var->var_name, buf );
 						LabelVariableChanged( var->variable );
					}
				}

				var_idx++;
			}
			sack_fclose( input );
		}
Esempio n. 2
0
int xClose(sqlite3_file*file)
{
	struct my_file_data *my_file = (struct my_file_data*)file;
	if( my_file->file )
	{
		sack_fclose( my_file->file );
#ifdef LOG_OPERATIONS
		lprintf( "Close %s", my_file->filename );
#endif
	}
	if( my_file->temp )
	{
		sack_unlinkEx( 0, my_file->filename, my_file->mount );
#ifdef LOG_OPERATIONS
		lprintf( "unlink temp file : %s", my_file->filename );
#endif
	}
	return SQLITE_OK;
}
Esempio n. 3
0
SaneWinMain( argc, argv )
{
	if( argc > 1 )
	{
		TEXTSTR result;
		uint8_t* buf;
		size_t length;
		FILE *file = sack_fopen( 0, argv[1], "rb" );
		length = sack_fseek( file, 0, SEEK_END );
		buf = NewArray( uint8_t, length );
		sack_fseek( file, 0, SEEK_SET );
		sack_fread( buf, 1, length, file );
		sack_fclose( file );
		result = SRG_EncryptData( buf, length );
		{
			int wrote = 0;
			while( result[wrote] )
			{
				wrote += printf( "%.80s", result + wrote );
				if( result[wrote] )
					printf("\\\n" );
			}
		}
		{
			size_t testlen;
			uint8_t* testbuf;
			SRG_DecryptData( result, &testbuf, &testlen );
			if( testlen != length )
				printf( "\n length fail \n" );
			if( MemCmp( testbuf, buf, testlen ) )
				printf( "\nFAIL\n" );
			Release( testbuf );
		}
		Release( buf );
		Release( result );

	}
}
Esempio n. 4
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;
}
Esempio n. 5
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;
}