Commit 573969cd authored by Andy Polyakov's avatar Andy Polyakov
Browse files

Abstain from GUI calls in rand_win.c in NT service context.

parent 34be0bb1
Loading
Loading
Loading
Loading
+21 −29
Original line number Original line Diff line number Diff line
@@ -167,7 +167,7 @@ typedef DWORD (WINAPI *GETQUEUESTATUS)(UINT);


typedef HANDLE (WINAPI *CREATETOOLHELP32SNAPSHOT)(DWORD, DWORD);
typedef HANDLE (WINAPI *CREATETOOLHELP32SNAPSHOT)(DWORD, DWORD);
typedef BOOL (WINAPI *CLOSETOOLHELP32SNAPSHOT)(HANDLE);
typedef BOOL (WINAPI *CLOSETOOLHELP32SNAPSHOT)(HANDLE);
typedef BOOL (WINAPI *HEAP32FIRST)(LPHEAPENTRY32, DWORD, DWORD);
typedef BOOL (WINAPI *HEAP32FIRST)(LPHEAPENTRY32, DWORD, ULONG_PTR);
typedef BOOL (WINAPI *HEAP32NEXT)(LPHEAPENTRY32);
typedef BOOL (WINAPI *HEAP32NEXT)(LPHEAPENTRY32);
typedef BOOL (WINAPI *HEAP32LIST)(HANDLE, LPHEAPLIST32);
typedef BOOL (WINAPI *HEAP32LIST)(HANDLE, LPHEAPLIST32);
typedef BOOL (WINAPI *PROCESS32)(HANDLE, LPPROCESSENTRY32);
typedef BOOL (WINAPI *PROCESS32)(HANDLE, LPPROCESSENTRY32);
@@ -195,21 +195,8 @@ int RAND_poll(void)
	HCRYPTPROV hProvider = 0;
	HCRYPTPROV hProvider = 0;
	BYTE buf[64];
	BYTE buf[64];
	DWORD w;
	DWORD w;
	HWND h;
	int good = 0;
	int good = 0;


	HMODULE advapi, kernel, user, netapi;
	CRYPTACQUIRECONTEXTW acquire = 0;
	CRYPTGENRANDOM gen = 0;
	CRYPTRELEASECONTEXT release = 0;
#if 1 /* There was previously a problem with NETSTATGET.  Currently, this
       * section is still experimental, but if all goes well, this conditional
       * will be removed
       */
	NETSTATGET netstatget = 0;
	NETFREE netfree = 0;
#endif /* 1 */

	/* Determine the OS version we are on so we can turn off things 
	/* Determine the OS version we are on so we can turn off things 
	 * that do not work properly.
	 * that do not work properly.
	 */
	 */
@@ -246,17 +233,18 @@ int RAND_poll(void)
	 * implement own shim routine, which would accept ANSI argument
	 * implement own shim routine, which would accept ANSI argument
	 * and expand it to Unicode.
	 * and expand it to Unicode.
	 */
	 */

	{
	/* load functions dynamically - not available on all systems */
	/* load functions dynamically - not available on all systems */
	advapi = LoadLibrary(TEXT("ADVAPI32.DLL"));
	HMODULE advapi = LoadLibrary(TEXT("ADVAPI32.DLL"));
	kernel = LoadLibrary(TEXT("KERNEL32.DLL"));
	HMODULE kernel = LoadLibrary(TEXT("KERNEL32.DLL"));
	user = LoadLibrary(TEXT("USER32.DLL"));
	HMODULE user = NULL;
	netapi = LoadLibrary(TEXT("NETAPI32.DLL"));
	HMODULE netapi = LoadLibrary(TEXT("NETAPI32.DLL"));

	CRYPTACQUIRECONTEXTW acquire = NULL;
#if 1 /* There was previously a problem with NETSTATGET.  Currently, this
	CRYPTGENRANDOM gen = NULL;
       * section is still experimental, but if all goes well, this conditional
	CRYPTRELEASECONTEXT release = NULL;
       * will be removed
	NETSTATGET netstatget = NULL;
       */
	NETFREE netfree = NULL;

	if (netapi)
	if (netapi)
		{
		{
		netstatget = (NETSTATGET) GetProcAddress(netapi,"NetStatisticsGet");
		netstatget = (NETSTATGET) GetProcAddress(netapi,"NetStatisticsGet");
@@ -286,7 +274,6 @@ int RAND_poll(void)


	if (netapi)
	if (netapi)
		FreeLibrary(netapi);
		FreeLibrary(netapi);
#endif /* 1 */


        /* It appears like this can cause an exception deep within ADVAPI32.DLL
        /* It appears like this can cause an exception deep within ADVAPI32.DLL
         * at random times on Windows 2000.  Reported by Jeffrey Altman.  
         * at random times on Windows 2000.  Reported by Jeffrey Altman.  
@@ -394,7 +381,9 @@ int RAND_poll(void)
        if (advapi)
        if (advapi)
		FreeLibrary(advapi);
		FreeLibrary(advapi);


	if (user)
	if ((osverinfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
	     !OPENSSL_isservice()) &&
	    (user = LoadLibrary(TEXT("USER32.DLL"))))
		{
		{
		GETCURSORINFO cursor;
		GETCURSORINFO cursor;
		GETFOREGROUNDWINDOW win;
		GETFOREGROUNDWINDOW win;
@@ -407,7 +396,7 @@ int RAND_poll(void)
		if (win)
		if (win)
			{
			{
			/* window handle */
			/* window handle */
			h = win();
			HWND h = win();
			RAND_add(&h, sizeof(h), 0);
			RAND_add(&h, sizeof(h), 0);
			}
			}
		if (cursor)
		if (cursor)
@@ -570,6 +559,7 @@ int RAND_poll(void)


		FreeLibrary(kernel);
		FreeLibrary(kernel);
		}
		}
	}
#endif /* !OPENSSL_SYS_WINCE */
#endif /* !OPENSSL_SYS_WINCE */


	/* timer data */
	/* timer data */
@@ -633,7 +623,6 @@ int RAND_event(UINT iMsg, WPARAM wParam, LPARAM lParam)
void RAND_screen(void) /* function available for backward compatibility */
void RAND_screen(void) /* function available for backward compatibility */
{
{
	RAND_poll();
	RAND_poll();
	if (GetVersion() >= 0x80000000 || !OPENSSL_isservice())
	readscreen();
	readscreen();
}
}


@@ -710,6 +699,9 @@ static void readscreen(void)
  int		y;		/* y-coordinate of screen lines to grab */
  int		y;		/* y-coordinate of screen lines to grab */
  int		n = 16;		/* number of screen lines to grab at a time */
  int		n = 16;		/* number of screen lines to grab at a time */


  if (GetVersion() >= 0x80000000 || !OPENSSL_isservice())
    return;

  /* Create a screen DC and a memory DC compatible to screen DC */
  /* Create a screen DC and a memory DC compatible to screen DC */
  hScrDC = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
  hScrDC = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
  hMemDC = CreateCompatibleDC(hScrDC);
  hMemDC = CreateCompatibleDC(hScrDC);