Esempio n. 1
0
void SSPassword::loadPasswordDLL(void)
{
	HKEY hKey;

	if (runningOnNT)
	{
		return;
	}

	if (hInstPwdDLL)
	{
		unloadPasswordDLL();
	}

	// look in registry to see if password turned on, otherwise don't
	// bother to load password handler DLL
	if (RegOpenKey(HKEY_CURRENT_USER, REGSTR_PATH_SCREENSAVE, &hKey) ==
		ERROR_SUCCESS)
	{
		DWORD dwVal,dwSize=sizeof(dwVal);

		if ((RegQueryValueEx(hKey, REGSTR_VALUE_USESCRPASSWORD,
			NULL,NULL,(BYTE *) &dwVal,&dwSize) == ERROR_SUCCESS)
			&& dwVal)
		{

			// try to load the DLL that contains password proc.
			hInstPwdDLL = LoadLibrary(_UC("PASSWORD.CPL"));
			if (hInstPwdDLL)
			{
				verifyPasswordProc = (VERIFYPWDPROC) GetProcAddress(hInstPwdDLL,
					"VerifyScreenSavePwd");

				if (verifyPasswordProc)
				{
					hogMachine(TRUE);
				}
				else
				{
					unloadPasswordDLL();
				}
			}
		}

		RegCloseKey(hKey);
	}
}
Esempio n. 2
0
void SSPassword::unloadPasswordDLL(void)
{
	if (runningOnNT)
	{
		return;
	}

	if (hInstPwdDLL)
	{
		FreeLibrary(hInstPwdDLL);
		hInstPwdDLL = NULL;

		if(verifyPasswordProc)
		{
			verifyPasswordProc = NULL;
			hogMachine(FALSE);
		}
	}
}
Esempio n. 3
0
static void doSaver (HWND hwndParent)
{
  HDC hdc;
  MSG msg;
  HWND hwnd;
  WNDCLASS cls;
  HANDLE hOther;
  RECT rcParent;
  int nx, ny, cx, cy;
  PSTR pszWindowTitle;
  UINT uExStyle, uStyle;

  // Define screensaver¡¯s window class.

  cls.style = CS_OWNDC | CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW;
  cls.lpfnWndProc = (WNDPROC) RealScreenSaverProc;
  cls.cbClsExtra = 0;
  cls.cbWndExtra = 0;
  cls.hInstance = g_hinstance;
  cls.hIcon = LoadIcon (g_hinstance, MAKEINTRESOURCE(ID_APP));
  cls.hCursor = NULL;
  cls.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
  cls.lpszMenuName = NULL;
  cls.lpszClassName = g_szClassName;

  // If hwndParent is not NULL, we are running in preview mode. Otherwise, we
  // are running in saver mode.

  if (hwndParent != NULL)
  {
    // Specify appropriate title for preview mode screensaver window.

    pszWindowTitle = "Preview";

    // Get the parent window rectangle.

    GetClientRect (hwndParent, &rcParent);

    // Compute width and position information for preview window, relative to
    // the parent window.

    cx = rcParent.right;
    cy = rcParent.bottom;
    nx = 0;
    ny = 0;

    // No extended style required for preview window, which is a child of its
    // non-desktop parent window.

    uExStyle = 0;

    // Set the preview window style -- child window, visible, exclude the
    // area occupied by child windows when drawing in parent window.

    uStyle = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN;
  }
  else
  {
    // Specify appropriate title for saver mode screensaver window.

    pszWindowTitle = "Screen Saver";

    // Search for existing screensaver window.

    hOther = FindWindow (g_szClassName, pszWindowTitle);

    // If this window exists, make it the foreground window and return. We
    // don¡¯t execute more than one screensaver at the same time. What would
    // be the point of doing that?
	  
    if (hOther != NULL && IsWindow ((HWND) hOther))
    {
      SetForegroundWindow (hOther);
      return;
    }

    // Get the desktop window rectangle.

    hdc = GetDC (HWND_DESKTOP);
    GetClipBox (hdc, &rcParent);
    ReleaseDC (HWND_DESKTOP, hdc);

    // Compute width and position information for screensaver window,
    // relative to the desktop window -- the entire screen.

    cx = rcParent.right - rcParent.left;
    cy = rcParent.bottom - rcParent.top;
    nx = rcParent.left;
    ny = rcParent.top;

    // The screensaver window occupies the entire screen and must be the
    // topmost window -- no other window can be located on top of the
    // screensaver window.

    uExStyle = WS_EX_TOPMOST;

    // Set the screensaver window style -- popup, visible, exclude the area
    // occupied by child windows when drawing in parent window, clip child
    // windows relative to each other.

    uStyle = WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  }

  // Attempt to register the screensaver¡¯s window class.

  if (!RegisterClass (&cls))
    return;

  if (g_fOnWin95)
  {
    // Load the password DLL (found in password.cpl -- a DLL with a .cpl
    // file extension.

    loadPwdDLL ();

    // Register the QueryCancelAutoPlay message with Windows.

    uShellMessage = RegisterWindowMessage ("QueryCancelAutoPlay");
  }

  // Disable the Alt+Tab, Ctrl+Alt+Delete, and Windows keys.

  hogMachine (TRUE);

  // Create either preview mode or saver mode screensaver window.

  hwnd = CreateWindowEx (uExStyle, g_szClassName, pszWindowTitle, uStyle,
             nx, ny, cx, cy, hwndParent, NULL, g_hinstance, NULL);

  // If we were successful ...

  if (hwnd)
  {
    // Either a preview window or a window occupying the entire desktop has
    // been created. In the latter case, make that window the foreground
    // window. Nothing can supersede a window occuping the entire desktop.

    if (g_scrmode != smPreview)
      SetForegroundWindow (hwnd);

    // Enter the screensaver¡¯s message loop. Loop ends when
    // RealScreenSaverProc() responds to the WM_DESTROY message by calling
    // PostQuitMessage (0).

    while (GetMessage (&msg, NULL, 0, 0))
    {
     TranslateMessage (&msg);
     DispatchMessage (&msg);
    }
  }

  // Enable the Alt+Tab, Ctrl+Alt+Delete, and Windows keys.

  hogMachine (FALSE);

  if (g_fOnWin95)
  {
    // Unload the password DLL.

    unloadPwdDLL ();
  }
}
Esempio n. 4
0
int WINAPI WinMain (HINSTANCE hinstance, HINSTANCE hinstancePrev,
          LPSTR lpszCmdLine, int iCmdShow)
{
  char     *pch;
  HWND     hwnd;
  OSVERSIONINFO osvi;

  // Obtain version number and determine if running Windows operating system
  // belongs to the Windows 95/98/ME family. Set the g_fOnWin95 flag to true
  // for Windows 95/98/ME family.
  
  osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  if (GetVersionEx (&osvi) || osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
    g_fOnWin95 = TRUE;

  // If an exception occurs within the body of the following try statement, we
  // must handle that exception in the __except handler. That handler invokes
  // hogMachine() with a FALSE argument to re-enable the Alt+Tab, Windows, and
  // Ctrl+Alt+Delete keys.

  __try
  {
    // Save instance handle for later access in doConfig() and doSaver().

    g_hinstance = hinstance;

    // Obtain the command line.

    pch = GetCommandLine ();

    // Process the command line. Example: "c:\bc45\projects\pscl\pscl.scr" /S
    // In some cases, there may not be double quotes.

    if (*pch == '\"')
    {
      // Skip open double quote.

      pch++;

      // Skip all characters until end of command line or close double
      // quote encountered.

      while (*pch != '\0' && *pch != '\"')
       pch++;
    }
    else
    {
      // Skip all characters until end of command line or space
      // encountered.

      while (*pch != '\0' && *pch != ' ')
       pch++;
    }

    // If *pch is not \0 (end of command line), it is either a double quote
    // or a space. Skip past this character.

    if (*pch != '\0')
      pch++;

    // Consume all intervening spaces.

    while (*pch == ' ')
     pch++;

    // If *pch is \0, no arguments were passed to the screensaver. Establish
    // smConfig as the screensaver mode, with the foreground window as the
    // parent window handle.

    if (*pch == '\0')
    {
      g_scrmode = smConfig;
      hwnd = GetForegroundWindow ();
    }
    else
    {
      // If we found an option, skip over option indicator.

      if (*pch == '-' || *pch == '/')
        pch++;

      // Detect valid option characters.

      if (*pch == 'a' || *pch == 'A')
      {
        // Establish smPassword as the screensaver mode.

        g_scrmode = smPassword;

        // Skip over option character.

        pch++;

        // Skip intervening spaces or colons.

        while (*pch == ' ' || *pch == ':')
         pch++;

        // Save handle argument as the parent window handle.

        hwnd = (HWND) atoi (pch);
      }
      else
      if (*pch == 'c' || *pch == 'C')
      {
        // Establish smConfig as the screensaver mode.

        g_scrmode = smConfig;

        // Skip over option character.

        pch++;

        // Skip intervening spaces or colons.

        while (*pch == ' ' || *pch ==':')
         pch++;

        // If nothing follows the option character (except for spaces and
        // colons), use the foreground window¡¯s handle as the parent
        // window handle. Otherwise, save the handle argument as the
        // parent window handle.

        if (*pch == '\0')
          hwnd = GetForegroundWindow ();
        else
          hwnd = (HWND) atoi (pch);
      }
      else
      if (*pch == 'p' || *pch == 'P' || *pch == 'l' || *pch == 'L')
      {
        // Establish smPreview as the screensaver mode.

        g_scrmode = smPreview;

        // Skip over option character.

        pch++;

        // Skip intervening spaces or colons.

        while (*pch == ' ' || *pch == ':')
         pch++;

        // Save handle argument as the parent window handle.

        hwnd = (HWND) atoi (pch);
      }
      else
      if (*pch == 's' || *pch == 'S')
      {
        // Establish smSaver as the screensaver mode.

        g_scrmode = smSaver;
      }
    }

    // Invoke appropriate screensaver entry point based on screensaver mode.

    if (g_scrmode == smConfig)
      doConfig (hwnd);
    else
    if (g_scrmode == smPassword)
      doChangePwd (hwnd);
    else
    if (g_scrmode == smPreview)
      doSaver (hwnd);
    else
    if (g_scrmode == smSaver)
      doSaver (NULL);
  }
  __except (EXCEPTION_EXECUTE_HANDLER)
  {
    hogMachine (FALSE);
  }

  return 0;
}