home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / winbase / security / winnt / ginastub / ginastub.c next >
Encoding:
C/C++ Source or Header  |  1997-10-05  |  8.6 KB  |  408 lines

  1. /*++
  2.  
  3. Copyright 1996 - 1997 Microsoft Corporation
  4.  
  5. Module Name:
  6.  
  7.     ginastub.c
  8.  
  9. Abstract:
  10.  
  11.     This sample illustrates a pass-thru "stub" gina which can be used
  12.     in some cases to simplify gina development.
  13.  
  14.     A common use for a gina is to implement code which requires the
  15.     credentials of the user logging onto the workstation.  The credentials
  16.     may be required for syncronization with foreign account databases
  17.     or custom authentication activities.
  18.  
  19.     In this example case, it is possible to implement a simple gina
  20.     stub layer which simply passes control for the required functions
  21.     to the previously installed gina, and captures the interesting
  22.     parameters from that gina.  In this scenario, the existing functionality
  23.     in the existent gina is retained.  In addition, the development time
  24.     is reduced drastically, as existing functionality does not need to
  25.     be duplicated.
  26.  
  27.     When dealing with credentials, take steps to maintain the security
  28.     of the credentials.  For instance, if transporting credentials over
  29.     a network, be sure to encrypt the credentials.
  30.  
  31. Author:
  32.  
  33.     Scott Field (sfield)    18-Jul-96
  34.  
  35. --*/
  36.  
  37. #include <windows.h>
  38. #include <stdio.h>
  39. #include <winwlx.h>
  40.  
  41. #include "ginastub.h"
  42.  
  43. //
  44. // Location of the real msgina.
  45. //
  46.  
  47. #define REALGINA_PATH   TEXT("MSGINA.DLL")
  48.  
  49.  
  50. //
  51. // winlogon function dispatch table
  52. //
  53.  
  54. PWLX_DISPATCH_VERSION_1_0 g_pWinlogon;
  55.  
  56. //
  57. // Functions pointers to the real msgina which we will call.
  58. //
  59.  
  60. PGWLXNEGOTIATE GWlxNegotiate;
  61. PGWLXINITIALIZE GWlxInitialize;
  62. PGWLXDISPLAYSASNOTICE GWlxDisplaySASNotice;
  63. PGWLXLOGGEDOUTSAS GWlxLoggedOutSAS;
  64. PGWLXACTIVATEUSERSHELL GWlxActivateUserShell;
  65. PGWLXLOGGEDONSAS GWlxLoggedOnSAS;
  66. PGWLXDISPLAYLOCKEDNOTICE GWlxDisplayLockedNotice;
  67. PGWLXWKSTALOCKEDSAS GWlxWkstaLockedSAS;
  68. PGWLXISLOCKOK GWlxIsLockOk;
  69. PGWLXISLOGOFFOK GWlxIsLogoffOk;
  70. PGWLXLOGOFF GWlxLogoff;
  71. PGWLXSHUTDOWN GWlxShutdown;
  72.  
  73. //
  74. // NEW for version 1.1
  75. //
  76.  
  77. PGWLXSTARTAPPLICATION GWlxStartApplication;
  78. PGWLXSCREENSAVERNOTIFY GWlxScreenSaverNotify;
  79.  
  80. //
  81. // hook into the real GINA.
  82. //
  83.  
  84. BOOL
  85. MyInitialize( void )
  86. {
  87.     HINSTANCE hDll;
  88.  
  89.     //
  90.     // Load MSGINA.DLL.
  91.     //
  92.     if( !(hDll = LoadLibrary( REALGINA_PATH )) ) {
  93.         return FALSE;
  94.     }
  95.  
  96.     //
  97.     // Get pointers to all of the WLX functions in the real MSGINA.
  98.     //
  99.     GWlxNegotiate = (PGWLXNEGOTIATE)GetProcAddress( hDll, "WlxNegotiate" );
  100.     if( !GWlxNegotiate ) {
  101.         return FALSE;
  102.     }
  103.  
  104.     GWlxInitialize = (PGWLXINITIALIZE)GetProcAddress( hDll, "WlxInitialize" );
  105.     if( !GWlxInitialize ) {
  106.         return FALSE;
  107.     }
  108.  
  109.     GWlxDisplaySASNotice =
  110.         (PGWLXDISPLAYSASNOTICE)GetProcAddress( hDll, "WlxDisplaySASNotice" );
  111.     if( !GWlxDisplaySASNotice ) {
  112.         return FALSE;
  113.     }
  114.  
  115.     GWlxLoggedOutSAS =
  116.         (PGWLXLOGGEDOUTSAS)GetProcAddress( hDll, "WlxLoggedOutSAS" );
  117.     if( !GWlxLoggedOutSAS ) {
  118.         return FALSE;
  119.     }
  120.  
  121.     GWlxActivateUserShell =
  122.         (PGWLXACTIVATEUSERSHELL)GetProcAddress( hDll, "WlxActivateUserShell" );
  123.     if( !GWlxActivateUserShell ) {
  124.         return FALSE;
  125.     }
  126.  
  127.     GWlxLoggedOnSAS =
  128.         (PGWLXLOGGEDONSAS)GetProcAddress( hDll, "WlxLoggedOnSAS" );
  129.     if( !GWlxLoggedOnSAS ) {
  130.         return FALSE;
  131.     }
  132.  
  133.     GWlxDisplayLockedNotice =
  134.         (PGWLXDISPLAYLOCKEDNOTICE)GetProcAddress(
  135.                                         hDll,
  136.                                         "WlxDisplayLockedNotice" );
  137.     if( !GWlxDisplayLockedNotice ) {
  138.         return FALSE;
  139.     }
  140.  
  141.     GWlxIsLockOk = (PGWLXISLOCKOK)GetProcAddress( hDll, "WlxIsLockOk" );
  142.     if( !GWlxIsLockOk ) {
  143.         return FALSE;
  144.     }
  145.  
  146.     GWlxWkstaLockedSAS =
  147.         (PGWLXWKSTALOCKEDSAS)GetProcAddress( hDll, "WlxWkstaLockedSAS" );
  148.     if( !GWlxWkstaLockedSAS ) {
  149.         return FALSE;
  150.     }
  151.  
  152.     GWlxIsLogoffOk = (PGWLXISLOGOFFOK)GetProcAddress( hDll, "WlxIsLogoffOk" );
  153.     if( !GWlxIsLogoffOk ) {
  154.         return FALSE;
  155.     }
  156.  
  157.     GWlxLogoff = (PGWLXLOGOFF)GetProcAddress( hDll, "WlxLogoff" );
  158.     if( !GWlxLogoff ) {
  159.         return FALSE;
  160.     }
  161.  
  162.     GWlxShutdown = (PGWLXSHUTDOWN)GetProcAddress( hDll, "WlxShutdown" );
  163.     if( !GWlxShutdown ) {
  164.         return FALSE;
  165.     }
  166.  
  167.     //
  168.     // we don't check for failure here because these don't exist for
  169.     // gina's implemented prior to Windows NT 4.0
  170.     //
  171.  
  172.     GWlxStartApplication = (PGWLXSTARTAPPLICATION) GetProcAddress( hDll, "WlxStartApplication" );
  173.     GWlxScreenSaverNotify = (PGWLXSCREENSAVERNOTIFY) GetProcAddress( hDll, "WlxScreenSaverNotify" );
  174.  
  175.     //
  176.     // Everything loaded ok.  Return success.
  177.     //
  178.     return TRUE;
  179. }
  180.  
  181.  
  182. BOOL
  183. WINAPI
  184. WlxNegotiate(
  185.     DWORD       dwWinlogonVersion,
  186.     DWORD       *pdwDllVersion)
  187. {
  188.     if( !MyInitialize() )
  189.         return FALSE;
  190.  
  191.     return GWlxNegotiate( dwWinlogonVersion, pdwDllVersion );
  192. }
  193.  
  194.  
  195. BOOL
  196. WINAPI
  197. WlxInitialize(
  198.     LPWSTR      lpWinsta,
  199.     HANDLE      hWlx,
  200.     PVOID       pvReserved,
  201.     PVOID       pWinlogonFunctions,
  202.     PVOID       *pWlxContext)
  203. {
  204.     return GWlxInitialize(
  205.                 lpWinsta,
  206.                 hWlx,
  207.                 pvReserved,
  208.                 pWinlogonFunctions,
  209.                 pWlxContext
  210.                 );
  211. }
  212.  
  213.  
  214. VOID
  215. WINAPI
  216. WlxDisplaySASNotice(
  217.     PVOID   pWlxContext)
  218. {
  219.     GWlxDisplaySASNotice( pWlxContext );
  220. }
  221.  
  222.  
  223. int
  224. WINAPI
  225. WlxLoggedOutSAS(
  226.     PVOID           pWlxContext,
  227.     DWORD           dwSasType,
  228.     PLUID           pAuthenticationId,
  229.     PSID            pLogonSid,
  230.     PDWORD          pdwOptions,
  231.     PHANDLE         phToken,
  232.     PWLX_MPR_NOTIFY_INFO    pMprNotifyInfo,
  233.     PVOID           *pProfile)
  234. {
  235.     int iRet;
  236.  
  237.     iRet = GWlxLoggedOutSAS(
  238.                 pWlxContext,
  239.                 dwSasType,
  240.                 pAuthenticationId,
  241.                 pLogonSid,
  242.                 pdwOptions,
  243.                 phToken,
  244.                 pMprNotifyInfo,
  245.                 pProfile
  246.                 );
  247.  
  248.     if(iRet == WLX_SAS_ACTION_LOGON) {
  249.         //
  250.         // copy pMprNotifyInfo and pLogonSid for later use
  251.         //
  252.  
  253.         // pMprNotifyInfo->pszUserName
  254.         // pMprNotifyInfo->pszDomain
  255.         // pMprNotifyInfo->pszPassword
  256.         // pMprNotifyInfo->pszOldPassword
  257.  
  258.     }
  259.  
  260.     return iRet;
  261. }
  262.  
  263.  
  264. BOOL
  265. WINAPI
  266. WlxActivateUserShell(
  267.     PVOID           pWlxContext,
  268.     PWSTR           pszDesktopName,
  269.     PWSTR           pszMprLogonScript,
  270.     PVOID           pEnvironment)
  271. {
  272.     return GWlxActivateUserShell(
  273.                 pWlxContext,
  274.                 pszDesktopName,
  275.                 pszMprLogonScript,
  276.                 pEnvironment
  277.                 );
  278. }
  279.  
  280.  
  281. int
  282. WINAPI
  283. WlxLoggedOnSAS(
  284.     PVOID           pWlxContext,
  285.     DWORD           dwSasType,
  286.     PVOID           pReserved)
  287. {
  288.     return GWlxLoggedOnSAS( pWlxContext, dwSasType, pReserved );
  289. }
  290.  
  291. VOID
  292. WINAPI
  293. WlxDisplayLockedNotice(
  294.     PVOID           pWlxContext )
  295. {
  296.     GWlxDisplayLockedNotice( pWlxContext );
  297. }
  298.  
  299.  
  300. BOOL
  301. WINAPI
  302. WlxIsLockOk(
  303.     PVOID           pWlxContext)
  304. {
  305.     return GWlxIsLockOk( pWlxContext );
  306. }
  307.  
  308.  
  309. int
  310. WINAPI
  311. WlxWkstaLockedSAS(
  312.     PVOID           pWlxContext,
  313.     DWORD           dwSasType )
  314. {
  315.     return GWlxWkstaLockedSAS( pWlxContext, dwSasType );
  316. }
  317.  
  318. BOOL
  319. WINAPI
  320. WlxIsLogoffOk(
  321.     PVOID pWlxContext
  322.     )
  323. {
  324.     BOOL bSuccess;
  325.  
  326.     bSuccess = GWlxIsLogoffOk( pWlxContext );
  327.  
  328.     if(bSuccess) {
  329.  
  330.         //
  331.         // if it's ok to logoff, finish with the stored credentials
  332.         // and scrub the buffers
  333.         //
  334.  
  335.     }
  336.  
  337.     return bSuccess;
  338. }
  339.  
  340.  
  341. VOID
  342. WINAPI
  343. WlxLogoff(
  344.     PVOID pWlxContext
  345.     )
  346. {
  347.     GWlxLogoff( pWlxContext );
  348. }
  349.  
  350.  
  351. VOID
  352. WINAPI
  353. WlxShutdown(
  354.     PVOID pWlxContext,
  355.     DWORD ShutdownType
  356.     )
  357. {
  358.     GWlxShutdown( pWlxContext, ShutdownType );
  359. }
  360.  
  361.  
  362. //
  363. // NEW for version 1.1
  364. //
  365.  
  366. BOOL
  367. WINAPI
  368. WlxScreenSaverNotify(
  369.     PVOID                   pWlxContext,
  370.     BOOL *                  pSecure
  371.     )
  372. {
  373.     if(GWlxScreenSaverNotify != NULL)
  374.         return GWlxScreenSaverNotify( pWlxContext, pSecure );
  375.  
  376.     //
  377.     // if not exported, return something intelligent
  378.     //
  379.  
  380.     *pSecure = TRUE;
  381.  
  382.     return TRUE;
  383. }
  384.  
  385. BOOL
  386. WINAPI
  387. WlxStartApplication(
  388.     PVOID                   pWlxContext,
  389.     PWSTR                   pszDesktopName,
  390.     PVOID                   pEnvironment,
  391.     PWSTR                   pszCmdLine
  392.     )
  393. {
  394.     if(GWlxStartApplication != NULL)
  395.         return GWlxStartApplication(
  396.             pWlxContext,
  397.             pszDesktopName,
  398.             pEnvironment,
  399.             pszCmdLine
  400.             );
  401.  
  402.     //
  403.     // if not exported, return something intelligent
  404.     //
  405.  
  406. }
  407.  
  408.