Beispiel #1
0
void CPROC ReadComplete( PCLIENT pc, void *bufptr, int sz )
{
   char *buf = (char*)bufptr;
	if( buf )
	{
		IdleFor( 500 );
		buf[sz] = 0;
		printf( "%s", buf );
		fflush( stdout );
	}
	else
	{
		buf = (char*)Allocate( 4097 );
      //SendTCP( pc, "Yes, I've connected", 12 );
	}
	ReadTCP( pc, buf, 4096 );
}
Beispiel #2
0
//----------------------------------------------------------------------------------------
// Timer for checking the timestamp
static uintptr_t CPROC countDown( PTHREAD thread )
{
	TEXTCHAR buf[45];
	uint8_t found = 0;	
	uint32_t startTime;   
	PODBC odbc;
	
	// Loop forever
	while( 1 )
	{
		// Get Current time
		startTime = timeGetTime();

		// Sleep to next timeout
		if( l.flags.bLogSleeps )
		{
			long x =  ( l.iIdleTime*(60)*(1000) ) - ( startTime - l.last_event_time );
			lprintf( WIDE("Sleep for... %d:%02d.%03d"), x / 60000, (x / 1000 ) %60, x % 1000 );
		}

		if( ( l.iIdleTime*(60)*(1000) ) > ( startTime - l.last_event_time ) )
			WakeableSleep( ( l.iIdleTime*(60)*(1000) ) - ( startTime - l.last_event_time ) );

		startTime = timeGetTime();
		// sleep some more if we got a new event

		if( ( l.iIdleTime*(60)*(1000) ) > ( startTime - l.last_event_time ) )
			continue;

		// Make connection to database
		odbc = SQLGetODBC( l.option_dsn );

		if( l.flags.bLogSleeps )
			lprintf( WIDE("woke up and user is %p (%d)"), HaveCurrentUser( odbc ), ( startTime - l.last_event_time ) );
		// If there is current user, else there is no active logins or processes to kill

		if( HaveCurrentUser( odbc ) )
		{
			uint32_t target_tick = startTime + ( l.iScreenSaverWaitTime * 1000 );
			int32_t remaining = ( target_tick - startTime );
			// Get time

			// Check last event, if timeout not hit go back to sleep until timeout will be hit
			if( remaining < 0 )
			{
				if( l.flags.bLogSleeps )
					lprintf( WIDE("Not enough time, go back and wait...") );

				// Close Connection to database
				SQLDropODBC( odbc );

				// not enough time has really passed... sleep more
				continue;
			}

			// Let hook know to update activity flag
			l.flags.countingDown = 1;			

			// Start countdown
			do
			{
				// Update time to check against
				remaining = ( target_tick - startTime );

				// Update Banner Message
				snprintf( buf, sizeof( buf ), WIDE(" The system will logout in %d.%03d seconds...")
						  , remaining / 1000, remaining % 1000 );
				BannerTopNoWait( buf );

				// Don't eat to much cpu time
				IdleFor( 200 );
				startTime = timeGetTime();
			}
			while( l.flags.countingDown && ( target_tick > startTime ) );

			// If countdown made it to 0
			if( ( target_tick < startTime ) )
			{
				uint32_t x;
				uint32_t y;
				// Logout users
				SQLCommandf( odbc , WIDE("update login_history set logout_whenstamp=now() where logout_whenstamp=11111111111111 and system_id=%d"), g.system_id );

				// Get current process list
				if ( !EnumProcesses( l.pidList2, sizeof( l.pidList2 ), &l.pidListLength2 ) )					
						lprintf( WIDE(" Getting Process List 2 Failed!") );

				// Kill Processes
				for( x = 0; x < l.pidListLength2; x++ )
				{
					// Check if process existed originally
					for( y = 0; y < l.pidListLength1; y++ )
					{
						if( l.pidList2[x] == l.pidList1[y] )
						{
							found = 1;
							break;
						}
					}

					// If did not exist originally kill the process
					if( !found )
					{
						TEXTCHAR cmd[25];
						snprintf( cmd, sizeof( cmd ), WIDE("pskill %d"), l.pidList2[x] );
						System( cmd, LogOutput, 0 );
					}

					found = 0;
				}

				// Give extra time to see Banner
				IdleFor( 500 );

				// Reset Data				
				l.flags.countingDown  = 0;				
			}			

			// Remove Banner
			RemoveBanner2Ex( NULL DBG_SRC  );
		}
		else
		{
			// fake an event, there was no user, so didn't do anything, just sleep more
			l.last_event_time = startTime;
		}

		// Close Connection to database
		SQLDropODBC( odbc );
	}

	return 0;
}