Ejemplo n.º 1
0
PCLIENT ConnectToRelay( PCLIENT *pc )
{
    TEXTCHAR address[128];
    if( InProgress )
    {
        BasicMessageBox( WIDE("Request in progress"), WIDE("Please wait a moment for\n")
                         WIDE("the current operation to finish") );
        return NULL;
    }
    InProgress = TRUE;
    NetworkWait( NULL, 5, 16 );
    GetControlText( GetControl( frame, EDT_SERVER ), address, sizeof( address ) );

    *pc = OpenTCPClientEx( address, 3001, ReadComplete, ConnectionClose, NULL );
    if( !(*pc) )
    {
        BasicMessageBox( WIDE("Bad Address?"),
                         WIDE("Check the address - could not connect") );
        return NULL;
    }
    ppc_current = pc;
    {
        FILE *file = sack_fopen( 0, WIDE("LastConnection.data"), WIDE("wb") );
        if( file )
        {
            fprintf( file, WIDE("%s"), address );
            fclose( file );
        }
    }
    return *pc;
}
Ejemplo n.º 2
0
SaneWinMain( argc, argv )
{
	FILE *input;
	if( argc > 2 )
	{
		input = sack_fopen( 0, argv[2], WIDE("rb+") );
		if( input )
		{
			if( StrCaseCmpEx( argv[1], WIDE( "u" ), 1 ) == 0 )
			{
				read_ascii( input );
				ascii_to_unicode();
				write_unicode( input );
			}
			else
			{
				read_unicode( input );
				unicode_to_ascii();
				write_ascii( input );
			}
			fclose( input );
		}
		else
			printf( WIDE( "Failed to open %s" ), argv[2] );
	}
	else
	{
		printf( WIDE("Usage: %s [u/a] [filename]\n"), argv[0] );
		printf( WIDE("  u or a is unicode or ascii mode; unicode translates from ascii to unicode\n") );
		printf( WIDE("  ascii translates from unicode to ascii\n") );
		printf( WIDE("  file will be written back in-place\n") );
	}
	return 0;
}
Ejemplo n.º 3
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 );
		}
Ejemplo n.º 4
0
MasterAvatarSandboxPassword = asdf
#endif

#define MyRegion WIDE("Pantero")
//#define MyIP WIDE("0.0.0.0")
#define center_point_x 9910
#define center_point_y 9929
#define sub_uuid WIDE("bb29")
#define center_point_uuid 584

int main( void )
{
	FILE *output;
	int x, y;
   int w = 5, h = 5;
	output = sack_fopen( 0, WIDE("region.test.ini"), WIDE("wt") );
	for( x = 0; x < w; x++ )
	{
		for( y = 0; y < h; y++ )
		{
         if( (x == w/2) && (y == h/2) )
				fprintf( output, WIDE("[%s]\n"), MyRegion );
			else
				fprintf( output, WIDE("[%s:%c%c]\n"), MyRegion, 'A'+x, 'A' + y );

			fprintf( output, WIDE("RegionUUID = 2023b505-56f8-4d67-%s-b56764a68%3d\n")
					 , sub_uuid
					 , center_point_uuid+(x*h+y) - (w*h/2) );
         fprintf( output, WIDE("Location = %d,%d\n"), center_point_x + x - w/2, center_point_y+y-h/2);
			fprintf( output, WIDE("InternalAddress = 0.0.0.0\n") );

         // use ports 9000 and above, don't center on port
         fprintf( output, WIDE("InternalPort = %d\n"), 9000 + (x*h+y) );
         fprintf( output, WIDE("AllowAlternatePorts = False\n") );
         fprintf( output, WIDE("ExternalHostName = d3x0r.org\n") );
         fprintf( output, WIDE("MasterAvatarFirstName = Decker\n") );
         fprintf( output, WIDE("MasterAvatarLastName = Thornfoot\n") );
			fprintf( output, WIDE("MasterAvatarSandboxPassword = sandB0><\n") );
			fprintf( output, WIDE(";NonphysicalPrimMax = 0\n") );
			fprintf( output, WIDE(";PhysicalPrimMax = 0\n") );
			fprintf( output, WIDE("ClampPrimSize = False\n") );
			fprintf( output, WIDE(";MaxPrims = 15000\n") );
         fprintf( output, WIDE("\n") );
		}
	}
	fclose( output );
   return 0;
}
Ejemplo n.º 5
0
int GetCh( void )
{
	int ch;
	//if( g.pCurrentPlayer && g.pCurrentPlayer->flags.bRemote )
	//   return 0;
	if( !pThreadInput )
		pThreadInput = MakeThread();
	if( !inputpipe )
	{
		inputpipe = open( WIDE("stockmarket.pipe"), O_RDWR|O_CREAT|O_TRUNC, 0600 );
		ThreadTo( InputThread, 0 );
	}
	if( !save )
		save = sack_fopen( 0, WIDE("stockmarket.save"), WIDE("wt") );
	if( script )
	{
		ch = fgetc( script );
		if( ch == -1 )
		{
			fclose( script );
			script = NULL;
		}
	}
	if( !script )
	{
		ch = 0; // clear upper bits.
		lprintf( WIDE("will read 1 TEXTCHAR") );
		while( bEnque || ( read( inputpipe, &ch, 1 ) < 1 ) )
		{
			lprintf( WIDE("Waiting for input event.") );
			WakeableSleep( SLEEP_FOREVER );
			lprintf( WIDE("Input event received.") );
		}
		lprintf( WIDE("Read input.") );
	}
	if( ch == '\r' )
		fputc( '\n', save );
	else
		fputc( ch, save );
	fflush( save );
	return ch;
}
Ejemplo n.º 6
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 );

	}
}
Ejemplo n.º 7
0
int main( int argc, char **argv )
{
	FILE *input = stdin;
	PVARTEXT pvt_cmd;
	TEXTCHAR readbuf[4096];
	TEXTCHAR *buf;
	int offset = 0;
	int no_headers = 0;
	PODBC default_odbc = NULL;
	CTEXTSTR select_into;
	PLIST output = NULL;
	PLIST outputs = NULL;
	int arg_ofs = 0;
	SQLSetFeedbackHandler( ShowSQLStates );
	//SetAllocateDebug( TRUE );
	//SetAllocateLogging( TRUE );
	if( argc < 2 )
		Usage( 1 );
	else
	{
		while( argv[1+arg_ofs] && ( argv[1+arg_ofs][0] == '-' ) )
		{
			TEXTSTR tmp;
			switch( argv[1+arg_ofs][1] )
			{
			case 'n':
				no_headers = 1;
				break;
			case 'f':
				arg_ofs++;
				input = sack_fopen( 0, tmp = DupCharToText( argv[1+arg_ofs] ), WIDE("rt") );
				if( input )
					SQLSetFeedbackHandler( LogSQLStates );
				break;
			}
			if( tmp )
			{
				Deallocate( TEXTSTR, tmp );
				tmp = NULL;
			}
			arg_ofs++;
		}
		if( argv[1+arg_ofs] )
			default_odbc = ConnectToDatabase( DupCharToText( argv[1 + arg_ofs] ) );
	}
	SetHeapUnit( 4096 * 1024 ); // 4 megs expansion if needed...
	pvt_cmd = VarTextCreateExx( 10000, 50000 );


	while( (buf = readbuf), fgets( readbuf + offset
					, sizeof( readbuf ) - offset
					, input ) )
	{
		CTEXTSTR *result = NULL;
		size_t len;
		while( buf[0] == WIDE(' ') || buf[0] == WIDE('\t') )
         buf++;
		len = strlen( buf );
		if( buf[0] == WIDE('#') )
			continue;
		if( ( len > 0 ) && buf[len-1] == WIDE('\n') )
		{
			len--;
			buf[len] = 0;
		}

		if( strcmp( buf, WIDE("\\q") ) == 0 )
			break;

		if( !buf[0] && VarTextLength( pvt_cmd ) == 0 )
			continue;

		if( ( len > 0 ) && buf[len-1] == WIDE('\\') )
		{
			buf[len-1] = 0;
			len--;
			vtprintf( pvt_cmd, WIDE("%s"), buf );
			offset = 0;
			//offset = (len - 1); // read over the slash
			continue;
		}
		else
		{
			if( len > 0 )
				vtprintf( pvt_cmd, WIDE("%s"), buf );
			offset = 0;
		}

		buf = GetText( VarTextPeek( pvt_cmd ) );

		if( buf[0] == WIDE('?') )
		{
			int fields;
			int replace = 0;
			int ofs = 1;
			CTEXTSTR *columns;
			TEXTSTR *_columns;
			PVARTEXT pvt = NULL;
			if( buf[1] == WIDE('!') )
			{
				replace = 1;
				ofs = 2;
			}
			if( output )
			{
				if( !select_into || !select_into[0] )
				{
					printf( WIDE("Table name was invalid to insert into on the destination side...\'%s\'"), select_into );
					VarTextEmpty( pvt_cmd );
					continue;
				}
				pvt = VarTextCreateExx( 10000, 50000 );
			}
			if( SQLRecordQuery( default_odbc, buf + ofs, &fields, &result, &columns ) )
			{
				int count = 0;
				int first = 1;
				_columns = NewArray( TEXTSTR, fields );
				if( !no_headers )
				{
					{
						int n;
						for( n = 0; n < fields; n++ )
						{
							_columns[n] = StrDup( columns[n] );
							if( !pvt )
								fprintf( stdout, WIDE("%s%s"), n?WIDE(","):WIDE(""), columns[n] );
						}
					}
					if( !pvt )
						fprintf( stdout, WIDE("\n") );
				}
				for( ; result; FetchSQLRecord( default_odbc, &result ) )
				{
					if( pvt && first )
					{
						vtprintf( pvt, WIDE("%s into `%s` ("), replace?WIDE("replace"):WIDE("insert ignore"), select_into );
						{
							int first = 1;
							int n;
							for( n = 0; n < fields; n++ )
							{
								vtprintf( pvt, WIDE("%s`%s`"), first?WIDE(""):WIDE(","), _columns[n] );
								first = 0;
							}
						}
						vtprintf( pvt, WIDE(") values ") );
					}
					if( pvt )
					{
						vtprintf( pvt, WIDE("%s("), first?WIDE(""):WIDE(",") );
						{
							int first = 1; // private first, sorry :) parse that, Visual studio can.
							int n;
							for( n = 0; n < fields; n++ )
							{
								TEXTSTR tmp;
								vtprintf( pvt, WIDE("%s%s")
										  , first?WIDE(""):WIDE(",")
										  , result[n]?(tmp=EscapeStringOpt( result[n], TRUE)):((tmp=NULL),WIDE("NULL"))
										  );
								Release( tmp );
								first = 0;
							}
						}
						vtprintf( pvt, WIDE(")") );
					}
					else
					{
						int n;
						int first = 1;
						for( n = 0; n < fields; n++ )
						{

							fprintf( stdout, WIDE("%s%s"), first?WIDE(""):WIDE(","),result[n]?result[n]:WIDE("NULL") );
							first = 0;
						}
						fprintf( stdout, WIDE("\n") );
					}
					first = 0;
					count++;
					if( ( VarTextLength( pvt ) ) > 100000 )
					{
						PTEXT cmd;
						first = 1; // reset first to rebuild the beginning of the insert.
						printf( WIDE("Flushing at 100k characters...%d records\n"), count );
						if( pvt )
						{
							cmd = VarTextGet( pvt );
							if( cmd )
							{
								INDEX idx;
								PODBC odbc;
								LIST_FORALL( output, idx, PODBC, odbc )
								{
									if( !SQLCommand( odbc, GetText( cmd ) ) )
										printf( WIDE("Failed command to:%s\n"), (CTEXTSTR)GetLink( &outputs, idx ) );
								}
								LineRelease( cmd );
							}
						}
					}
				}
				if( !no_headers )
				{
					int n;
					for( n = 0; n < fields; n++ )
					{
						Release( _columns[n] );
					}
				}
				Release( _columns );
			}
Ejemplo n.º 8
0
int CPROC FillList( uintptr_t psv, CTEXTSTR name, POPTION_TREE_NODE ID, int flags )
{
   PLISTFILL plf = (PLISTFILL)psv;
	LISTFILL lf = *plf;
	if( StrCmp( name, WIDE(".") ) == 0 )
      return TRUE;
	lf.nLevel++;
   lf.flags.bSecondLevel = 1;
	lprintf( WIDE("%d - %s (%p)"), plf->nLevel, name, ID );
	{
		if( lf.nLevel == 1 )
		{
			if( pvtIni )
			{
				PTEXT pINI = VarTextGet( pvtIni );
				CRYPTOEncryptMemory( GetText( pINI ), GetTextSize( pINI ) );
				if( output )
				{
					fwrite( GetText(pINI), 1, GetTextSize( pINI ), output );
               LineRelease( pINI );
					fclose( output );
					output = NULL;
				}
				VarTextDestroy( &pvtIni );
			}
         // if it's this branch, then don't auto export it.
			if( StrCmp( name, WIDE("INI Store") ) == 0 )
            return TRUE;
			pvtIni = VarTextCreate();
			output = sack_fopen( 0, name, WIDE("wt") );
		}
		else if( lf.nLevel == 2 )
		{
			lprintf( WIDE("Section %s"), name );
			vtprintf( pvtSection, WIDE("%s"), name );
		}
		else if( lf.nLevel >= 3 )
		{
			POPTION_TREE_NODE ID_Value = GetOptionValueIndex( ID );
			if( ID_Value )
			{
				TEXTCHAR buffer[256];
				if( (int)GetOptionStringValue( ID_Value, buffer, sizeof( buffer ) ) > 0 )
				{
					if( VarTextPeek( pvtSection ) )
					{
						PTEXT section =VarTextGet( pvtSection );
						vtprintf( pvtIni, WIDE("[%s]\n"), GetText( section ) );
						LineRelease( section );
					}
					vtprintf( pvtIni, WIDE("%s=%s\n"), name, buffer );
				}
				else
				{
					vtprintf( pvtSection, WIDE("/%s"), name );
				}
			}
			else
			{
				vtprintf( pvtSection, WIDE("/%s"), name );
			}
		}
	}
  	EnumOptions( ID, FillList, (uintptr_t)&lf );
   //lprintf( WIDE("done with all children under this node.") );
   return TRUE;
}
Ejemplo n.º 9
0
void SetOutputFile( TEXTCHAR *file )
{
   save = sack_fopen( 0, file, WIDE("wt") );
}
Ejemplo n.º 10
0
void SetInputFile( TEXTCHAR *file )
{
   script = sack_fopen( 0, file, WIDE("rt") );
}
Ejemplo n.º 11
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;
}