GINA.C
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:14k
源码类别:

Windows编程

开发平台:

Visual C++

  1. //+---------------------------------------------------------------------------
  2. //
  3. //  Microsoft Windows
  4. //  Copyright 1992 - 1997 Microsoft Corporation.
  5. //
  6. //  File:       gina.c
  7. //
  8. //  Contents:
  9. //
  10. //  Classes:
  11. //
  12. //  Functions:
  13. //
  14. //  History:    4-20-95   RichardW   Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "gina.h"
  18. #pragma hdrstop
  19. HINSTANCE                   hDllInstance;   // My instance, for resource loading
  20. HANDLE                      hGlobalWlx;     // Handle to tell winlogon who's calling
  21. PWLX_DISPATCH_VERSION_1_0   pWlxFuncs;      // Ptr to table of functions
  22. #define WINLOGON_APP        TEXT("Winlogon")
  23. #define USERINIT            TEXT("Userinit")
  24. #define USERINIT_DEFAULT    TEXT("Userinit.exe")
  25. //+---------------------------------------------------------------------------
  26. //
  27. //  Function:   DllMain
  28. //
  29. //  Synopsis:   DLL Entrance point
  30. //
  31. //  Arguments:  [hInstance]  --
  32. //              [dwReason]   --
  33. //              [lpReserved] --
  34. //
  35. //  History:    4-20-95   RichardW   Created
  36. //
  37. //  Notes:
  38. //
  39. //----------------------------------------------------------------------------
  40. BOOL
  41. WINAPI
  42. DllMain(
  43.     HINSTANCE       hInstance,
  44.     DWORD           dwReason,
  45.     LPVOID          lpReserved)
  46. {
  47.     switch (dwReason)
  48.     {
  49.         case DLL_PROCESS_ATTACH:
  50.             DisableThreadLibraryCalls ( hInstance );
  51.             hDllInstance = hInstance;
  52. #if DBG
  53.             InitDebugSupport();
  54. #endif
  55.         case DLL_PROCESS_DETACH:
  56.         default:
  57.             return(TRUE);
  58.     }
  59. }
  60. //+---------------------------------------------------------------------------
  61. //
  62. //  Function:   WlxNegotiate
  63. //
  64. //  Synopsis:   Negotiate version of interface with Winlogon
  65. //
  66. //  Arguments:  [dwWinlogonVersion] --
  67. //              [pdwDllVersion]     --
  68. //
  69. //  Algorithm:
  70. //
  71. //  History:    4-20-95   RichardW   Created
  72. //
  73. //  Notes:
  74. //
  75. //----------------------------------------------------------------------------
  76. BOOL
  77. WINAPI
  78. WlxNegotiate(
  79.     DWORD                   dwWinlogonVersion,
  80.     DWORD                   *pdwDllVersion
  81.     )
  82. {
  83.     if (dwWinlogonVersion < WLX_CURRENT_VERSION)
  84.     {
  85.         DebugLog((DEB_ERROR, "Unknown version: %dn", dwWinlogonVersion));
  86.         return(FALSE);
  87.     }
  88.     *pdwDllVersion = WLX_CURRENT_VERSION;
  89.     DebugLog((DEB_TRACE, "Negotiate:  successful!n"));
  90.     return(TRUE);
  91. }
  92. //+---------------------------------------------------------------------------
  93. //
  94. //  Function:   WlxInitialize
  95. //
  96. //  Synopsis:   Initialize entrypoint from winlogon
  97. //
  98. //  Arguments:  [lpWinsta]           --
  99. //              [hWlx]               --
  100. //              [pvReserved]         --
  101. //              [pWinlogonFunctions] --
  102. //              [pWlxContext]        --
  103. //
  104. //  History:    4-20-95   RichardW   Created
  105. //
  106. //  Notes:
  107. //
  108. //----------------------------------------------------------------------------
  109. BOOL
  110. WINAPI
  111. WlxInitialize(
  112.     LPWSTR                  lpWinsta,
  113.     HANDLE                  hWlx,
  114.     PVOID                   pvReserved,
  115.     PVOID                   pWinlogonFunctions,
  116.     PVOID                   *pWlxContext
  117.     )
  118. {
  119.     PGlobals  pGlobals;
  120.     pWlxFuncs = (PWLX_DISPATCH_VERSION_1_0) pWinlogonFunctions;
  121.     hGlobalWlx = hWlx;
  122.     pGlobals = LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT, sizeof(Globals));
  123.     *pWlxContext = (PVOID) pGlobals;
  124.     //
  125.     // Read from registry...
  126.     //
  127.     pGlobals->fAllowNewUser = TRUE;
  128.     pWlxFuncs->WlxUseCtrlAltDel(hWlx);
  129.     InitCommonControls();
  130.     return(TRUE);
  131. }
  132. //+---------------------------------------------------------------------------
  133. //
  134. //  Function:   WlxDisplaySASNotice
  135. //
  136. //  Synopsis:   Where we display the welcome, we're waiting dialog box
  137. //
  138. //  Arguments:  [pContext] --
  139. //
  140. //  History:    4-20-95   RichardW   Created
  141. //
  142. //  Notes:
  143. //
  144. //----------------------------------------------------------------------------
  145. VOID
  146. WINAPI
  147. WlxDisplaySASNotice(PVOID   pContext)
  148. {
  149.     int Result;
  150.     Result = pWlxFuncs->WlxDialogBoxParam(  hGlobalWlx,
  151.                                             hDllInstance,
  152.                                             (LPTSTR) MAKEINTRESOURCE(IDD_WELCOME_DLG),
  153.                                             NULL,
  154.                                             WelcomeDlgProc,
  155.                                             0 );
  156. }
  157. //+---------------------------------------------------------------------------
  158. //
  159. //  Function:   WlxLoggedOutSAS
  160. //
  161. //  Synopsis:   Called when no one logged on...
  162. //
  163. //  Arguments:  [pWlxContext]       --
  164. //              [dwSasType]         --
  165. //              [pAuthenticationId] --
  166. //              [pLogonSid]         --
  167. //              [pdwOptions]        --
  168. //              [phToken]           --
  169. //              [pMprNotifyInfo]    --
  170. //              [pProfile]          --
  171. //
  172. //  History:    4-20-95   RichardW   Created
  173. //
  174. //  Notes:
  175. //
  176. //----------------------------------------------------------------------------
  177. int
  178. WINAPI
  179. WlxLoggedOutSAS(
  180.     PVOID                   pWlxContext,
  181.     DWORD                   dwSasType,
  182.     PLUID                   pAuthenticationId,
  183.     PSID                    pLogonSid,
  184.     PDWORD                  pdwOptions,
  185.     PHANDLE                 phToken,
  186.     PWLX_MPR_NOTIFY_INFO    pMprNotifyInfo,
  187.     PVOID *                 pProfile
  188.     )
  189. {
  190.     int         result;
  191.     // PWLX_PROFILE_V1_0   pWlxProfile;
  192.     // PMiniAccount    pAccount;
  193.     PGlobals        pGlobals;
  194.     pGlobals = (PGlobals) pWlxContext;
  195.     result = pWlxFuncs->WlxDialogBoxParam(  hGlobalWlx,
  196.                                             hDllInstance,
  197.                                             (LPTSTR) MAKEINTRESOURCE(IDD_LOGON_DIALOG),
  198.                                             NULL,
  199.                                             LogonDlgProc,
  200.                                             (LPARAM) pGlobals );
  201.     if (result == WLX_SAS_ACTION_LOGON)
  202.     {
  203.         result = AttemptLogon(pGlobals, pGlobals->pAccount,
  204.                                 pLogonSid, pAuthenticationId);
  205.         if (result == WLX_SAS_ACTION_LOGON)
  206.         {
  207.             *pdwOptions = 0;
  208.             *phToken = pGlobals->hUserToken;
  209.             *pProfile = NULL;
  210.             pMprNotifyInfo->pszUserName = DupString(pGlobals->pAccount->pszUsername);
  211.             pMprNotifyInfo->pszDomain = DupString(pGlobals->pAccount->pszDomain);
  212.             pMprNotifyInfo->pszPassword = DupString(pGlobals->pAccount->pszPassword);
  213.             pMprNotifyInfo->pszOldPassword = NULL;
  214.         }
  215.     }
  216.     return(result);
  217. }
  218. //+---------------------------------------------------------------------------
  219. //
  220. //  Function:   WlxActivateUserShell
  221. //
  222. //  Synopsis:   Activates progman or whatever for the user
  223. //
  224. //  Arguments:  [pWlxContext]       --
  225. //              [pszDesktop]        --
  226. //              [pszMprLogonScript] --
  227. //              [pEnvironment]      --
  228. //
  229. //  History:    4-20-95   RichardW   Created
  230. //
  231. //  Notes:
  232. //
  233. //----------------------------------------------------------------------------
  234. BOOL
  235. WINAPI
  236. WlxActivateUserShell(
  237.     PVOID                   pWlxContext,
  238.     PWSTR                   pszDesktop,
  239.     PWSTR                   pszMprLogonScript,
  240.     PVOID                   pEnvironment
  241.     )
  242. {
  243.     // BOOL        bExec;
  244.     WCHAR       szText[MAX_PATH];
  245.     PWSTR       pszScan;
  246.     STARTUPINFO si;
  247.     PROCESS_INFORMATION pi;
  248.     PGlobals    pGlobals;
  249.     DWORD       StartCount;
  250.     pGlobals = (PGlobals) pWlxContext;
  251.     GetProfileString(WINLOGON_APP, USERINIT, USERINIT_DEFAULT, szText, MAX_PATH);
  252.     StartCount = 0;
  253.     pszScan = wcstok(szText, TEXT(","));
  254.     while (pszScan)
  255.     {
  256.         ZeroMemory(&si, sizeof(si));
  257.         si.cb = sizeof(STARTUPINFO);
  258.         si.lpTitle = pszScan;
  259.         si.dwX = si.dwY = si.dwXSize = si.dwYSize = 0L;
  260.         si.dwFlags = 0;
  261.         si.wShowWindow = SW_SHOW;   // at least let the guy see it
  262.         si.lpReserved2 = NULL;
  263.         si.cbReserved2 = 0;
  264.         si.lpDesktop = pszDesktop;
  265.         DebugLog((DEB_TRACE, "Starting '%ws' as usern", pszScan));
  266.         ImpersonateLoggedOnUser(pGlobals->hUserToken);
  267.         if (CreateProcessAsUser(pGlobals->hUserToken,   // Token to run as
  268.                             NULL,                   // App name
  269.                             pszScan,                // Command Line
  270.                             NULL,                   // Process SD
  271.                             NULL,                   // Thread SD
  272.                             FALSE,                  // No inherit
  273.                             CREATE_UNICODE_ENVIRONMENT,
  274.                             pEnvironment,
  275.                             NULL,
  276.                             &si,
  277.                             &pi))
  278.         {
  279.             StartCount++;
  280.             CloseHandle(pi.hProcess);
  281.             CloseHandle(pi.hThread);
  282.         }
  283.         RevertToSelf();
  284.         pszScan = wcstok(NULL, TEXT(","));
  285.     }
  286.     return(StartCount > 0);
  287. }
  288. //+---------------------------------------------------------------------------
  289. //
  290. //  Function:   WlxLoggedOnSAS
  291. //
  292. //  Synopsis:   Called when someone hits CAD when we're logged on
  293. //
  294. //  Arguments:  [pWlxContext] --
  295. //              [dwSasType]   --
  296. //              [pReserved]   --
  297. //
  298. //  Algorithm:
  299. //
  300. //  History:    4-20-95   RichardW   Created
  301. //
  302. //  Notes:
  303. //
  304. //----------------------------------------------------------------------------
  305. int
  306. WINAPI
  307. WlxLoggedOnSAS(
  308.     PVOID                   pWlxContext,
  309.     DWORD                   dwSasType,
  310.     PVOID                   pReserved
  311.     )
  312. {
  313.     int result;
  314.     result = pWlxFuncs->WlxDialogBoxParam(  hGlobalWlx,
  315.                                             hDllInstance,
  316.                                             (LPTSTR) MAKEINTRESOURCE(IDD_OPTIONS_DIALOG),
  317.                                             NULL,
  318.                                             OptionsDlgProc,
  319.                                             (LPARAM) pWlxContext );
  320.     return(result);
  321. }
  322. //+---------------------------------------------------------------------------
  323. //
  324. //  Function:   WlxIsLockOk
  325. //
  326. //  Synopsis:   Called to make sure that locking is ok
  327. //
  328. //  Arguments:  [pWlxContext] --
  329. //
  330. //  History:    4-20-95   RichardW   Created
  331. //
  332. //  Notes:
  333. //
  334. //----------------------------------------------------------------------------
  335. BOOL
  336. WINAPI
  337. WlxIsLockOk(
  338.     PVOID                   pWlxContext
  339.     )
  340. {
  341.     return(TRUE);
  342. }
  343. //+---------------------------------------------------------------------------
  344. //
  345. //  Function:   WlxDisplayLockedNotice
  346. //
  347. //  Synopsis:   Displays a notice while the workstation is locked
  348. //
  349. //  Arguments:  [pWlxContext] --
  350. //
  351. //  History:    4-20-95   RichardW   Created
  352. //
  353. //  Notes:
  354. //
  355. //----------------------------------------------------------------------------
  356. VOID
  357. WINAPI
  358. WlxDisplayLockedNotice(PVOID   pWlxContext)
  359. {
  360.     int Result;
  361.     Result = pWlxFuncs->WlxDialogBoxParam(  hGlobalWlx,
  362.                                             hDllInstance,
  363.                                             (LPTSTR) MAKEINTRESOURCE(IDD_WKSTA_LOCKED),
  364.                                             NULL,
  365.                                             WelcomeDlgProc,
  366.                                             0 );
  367.     return;
  368. }
  369. //+---------------------------------------------------------------------------
  370. //
  371. //  Function:   WlxWkstaLockedSAS
  372. //
  373. //  Synopsis:   Responds during an unlock attempt
  374. //
  375. //  Arguments:  [pWlxContext] --
  376. //              [dwSasType]   --
  377. //
  378. //  History:    4-20-95   RichardW   Created
  379. //
  380. //  Notes:
  381. //
  382. //----------------------------------------------------------------------------
  383. int
  384. WINAPI
  385. WlxWkstaLockedSAS(
  386.     PVOID                   pWlxContext,
  387.     DWORD                   dwSasType
  388.     )
  389. {
  390.     return(WLX_SAS_ACTION_UNLOCK_WKSTA);
  391. }
  392. //+---------------------------------------------------------------------------
  393. //
  394. //  Function:   WlxIsLogoffOk
  395. //
  396. //  Synopsis:   Called to make sure that logoff is ok
  397. //
  398. //  Arguments:  [pWlxContext] --
  399. //
  400. //  History:    4-20-95   RichardW   Created
  401. //
  402. //  Notes:
  403. //
  404. //----------------------------------------------------------------------------
  405. BOOL
  406. WINAPI
  407. WlxIsLogoffOk(
  408.     PVOID                   pWlxContext
  409.     )
  410. {
  411.     return(TRUE);
  412. }
  413. //+---------------------------------------------------------------------------
  414. //
  415. //  Function:   WlxLogoff
  416. //
  417. //  Synopsis:   Called when the user logs off
  418. //
  419. //  Arguments:  [pWlxContext] --
  420. //
  421. //  History:    4-20-95   RichardW   Created
  422. //
  423. //  Notes:
  424. //
  425. //----------------------------------------------------------------------------
  426. VOID
  427. WINAPI
  428. WlxLogoff(
  429.     PVOID                   pWlxContext
  430.     )
  431. {
  432.     PGlobals    pGlobals;
  433.     pGlobals = (PGlobals) pWlxContext;
  434.     //
  435.     // Winlogon has closed it for us..
  436.     //
  437.     pGlobals->hUserToken = NULL;
  438.     pGlobals->pAccount = NULL;
  439.     return;
  440. }
  441. //+---------------------------------------------------------------------------
  442. //
  443. //  Function:   WlxShutdown
  444. //
  445. //  Synopsis:   Called before shutdown so that we can unload/clean up.
  446. //
  447. //  Arguments:  [pWlxContext]  --
  448. //              [ShutdownType] --
  449. //
  450. //  History:    4-20-95   RichardW   Created
  451. //
  452. //  Notes:
  453. //
  454. //----------------------------------------------------------------------------
  455. VOID
  456. WINAPI
  457. WlxShutdown(
  458.     PVOID                   pWlxContext,
  459.     DWORD                   ShutdownType
  460.     )
  461. {
  462.     return;
  463. }