ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

wlx.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:       See COPYING in the top level directory
00003  * PROJECT:         ReactOS Winlogon
00004  * FILE:            base/system/winlogon/wlx.c
00005  * PURPOSE:         Logon
00006  * PROGRAMMERS:     Thomas Weidenmueller (w3seek@users.sourceforge.net)
00007  *                  Ge van Geldorp (gvg@reactos.com)
00008  *                  Hervé Poussineau (hpoussin@reactos.org)
00009  */
00010 
00011 /* INCLUDES *****************************************************************/
00012 
00013 #include "winlogon.h"
00014 
00015 #include <wine/debug.h>
00016 
00017 WINE_DEFAULT_DEBUG_CHANNEL(winlogon);
00018 
00019 #define DESKTOP_ALL (DESKTOP_READOBJECTS | DESKTOP_CREATEWINDOW | \
00020     DESKTOP_CREATEMENU | DESKTOP_HOOKCONTROL | DESKTOP_JOURNALRECORD | \
00021     DESKTOP_JOURNALPLAYBACK | DESKTOP_ENUMERATE | DESKTOP_WRITEOBJECTS | \
00022     DESKTOP_SWITCHDESKTOP | STANDARD_RIGHTS_REQUIRED)
00023 
00024 #define WINSTA_ALL (WINSTA_ENUMDESKTOPS | WINSTA_READATTRIBUTES | \
00025     WINSTA_ACCESSCLIPBOARD | WINSTA_CREATEDESKTOP | \
00026     WINSTA_WRITEATTRIBUTES | WINSTA_ACCESSGLOBALATOMS | \
00027     WINSTA_EXITWINDOWS | WINSTA_ENUMERATE | WINSTA_READSCREEN | \
00028     STANDARD_RIGHTS_REQUIRED)
00029 
00030 #define GENERIC_ACCESS (GENERIC_READ | GENERIC_WRITE | \
00031     GENERIC_EXECUTE | GENERIC_ALL)
00032 
00033 /* GLOBALS ******************************************************************/
00034 
00035 static DLGPROC PreviousWindowProc;
00036 static UINT_PTR IdTimer;
00037 
00038 /* FUNCTIONS ****************************************************************/
00039 
00040 static INT_PTR CALLBACK
00041 DefaultWlxWindowProc(
00042     IN HWND hwndDlg,
00043     IN UINT uMsg,
00044     IN WPARAM wParam,
00045     IN LPARAM lParam)
00046 {
00047     if (uMsg == WM_TIMER && (UINT_PTR)wParam == IdTimer)
00048     {
00049         EndDialog(hwndDlg, -1);
00050         KillTimer(hwndDlg, IdTimer);
00051         return TRUE;
00052     }
00053     else if (uMsg == WM_INITDIALOG)
00054     {
00055         IdTimer = SetTimer(hwndDlg, 0, WLSession->DialogTimeout * 1000, NULL);
00056         return PreviousWindowProc(hwndDlg, uMsg, wParam, lParam);
00057     }
00058     else if (uMsg == WM_NCDESTROY)
00059     {
00060         BOOL ret;
00061         ret = PreviousWindowProc(hwndDlg, uMsg, wParam, lParam);
00062         PreviousWindowProc = NULL;
00063         return ret;
00064     }
00065     else
00066     {
00067         return PreviousWindowProc(hwndDlg, uMsg, wParam, lParam);
00068     }
00069 }
00070 
00071 /*
00072  * @implemented
00073  */
00074 VOID WINAPI
00075 WlxUseCtrlAltDel(
00076     HANDLE hWlx)
00077 {
00078     ULONG_PTR OldValue;
00079 
00080     TRACE("WlxUseCtrlAltDel()\n");
00081 
00082     WlxSetOption(hWlx, WLX_OPTION_USE_CTRL_ALT_DEL, TRUE, &OldValue);
00083 }
00084 
00085 /*
00086  * @implemented
00087  */
00088 VOID WINAPI
00089 WlxSetContextPointer(
00090     HANDLE hWlx,
00091     PVOID pWlxContext)
00092 {
00093     ULONG_PTR OldValue;
00094 
00095     TRACE("WlxSetContextPointer(%p)\n", pWlxContext);
00096 
00097     WlxSetOption(hWlx, WLX_OPTION_CONTEXT_POINTER, (ULONG_PTR)pWlxContext, &OldValue);
00098 }
00099 
00100 /*
00101  * @implemented
00102  */
00103 VOID WINAPI
00104 WlxSasNotify(
00105     HANDLE hWlx,
00106     DWORD dwSasType)
00107 {
00108     PWLSESSION Session = (PWLSESSION)hWlx;
00109 
00110     TRACE("WlxSasNotify(0x%lx)\n", dwSasType);
00111 
00112     if (dwSasType == WLX_SAS_TYPE_CTRL_ALT_DEL || dwSasType > WLX_SAS_TYPE_MAX_MSFT_VALUE)
00113         PostMessageW(Session->SASWindow, WLX_WM_SAS, dwSasType, 0);
00114 }
00115 
00116 /*
00117  * @implemented
00118  */
00119 BOOL WINAPI
00120 WlxSetTimeout(
00121     HANDLE hWlx,
00122     DWORD Timeout)
00123 {
00124     PWLSESSION Session = (PWLSESSION)hWlx;
00125 
00126     TRACE("WlxSetTimeout(%lu)\n", Timeout);
00127 
00128     Session->DialogTimeout = Timeout;
00129     return TRUE;
00130 }
00131 
00132 /*
00133  * @unimplemented
00134  */
00135 int WINAPI
00136 WlxAssignShellProtection(
00137     HANDLE hWlx,
00138     HANDLE hToken,
00139     HANDLE hProcess,
00140     HANDLE hThread)
00141 {
00142     UNREFERENCED_PARAMETER(hWlx);
00143     UNREFERENCED_PARAMETER(hToken);
00144     UNREFERENCED_PARAMETER(hProcess);
00145     UNREFERENCED_PARAMETER(hThread);
00146 
00147     UNIMPLEMENTED;
00148     return 0;
00149 }
00150 
00151 /*
00152  * @implemented
00153  */
00154 int WINAPI
00155 WlxMessageBox(
00156     HANDLE hWlx,
00157     HWND hwndOwner,
00158     LPWSTR lpszText,
00159     LPWSTR lpszTitle,
00160     UINT fuStyle)
00161 {
00162     UNREFERENCED_PARAMETER(hWlx);
00163 
00164     TRACE("WlxMessageBox()\n");
00165     /* FIXME: Provide a custom window proc to be able to handle timeout */
00166     return MessageBoxW(hwndOwner, lpszText, lpszTitle, fuStyle);
00167 }
00168 
00169 /*
00170  * @implemented
00171  */
00172 int WINAPI
00173 WlxDialogBox(
00174     HANDLE hWlx,
00175     HANDLE hInst,
00176     LPWSTR lpszTemplate,
00177     HWND hwndOwner,
00178     DLGPROC dlgprc)
00179 {
00180     UNREFERENCED_PARAMETER(hWlx);
00181 
00182     TRACE("WlxDialogBox()\n");
00183 
00184     if (PreviousWindowProc != NULL)
00185         return -1;
00186     PreviousWindowProc = dlgprc;
00187     return (int)DialogBoxW((HINSTANCE) hInst, lpszTemplate, hwndOwner, DefaultWlxWindowProc);
00188 }
00189 
00190 /*
00191  * @implemented
00192  */
00193 int WINAPI
00194 WlxDialogBoxParam(
00195     HANDLE hWlx,
00196     HANDLE hInst,
00197     LPWSTR lpszTemplate,
00198     HWND hwndOwner,
00199     DLGPROC dlgprc,
00200     LPARAM dwInitParam)
00201 {
00202     UNREFERENCED_PARAMETER(hWlx);
00203 
00204     TRACE("WlxDialogBoxParam()\n");
00205 
00206     if (PreviousWindowProc != NULL)
00207         return -1;
00208     PreviousWindowProc = dlgprc;
00209     return (int)DialogBoxParamW(hInst, lpszTemplate, hwndOwner, DefaultWlxWindowProc, dwInitParam);
00210 }
00211 
00212 /*
00213  * @implemented
00214  */
00215 int WINAPI
00216 WlxDialogBoxIndirect(
00217     HANDLE hWlx,
00218     HANDLE hInst,
00219     LPCDLGTEMPLATE hDialogTemplate,
00220     HWND hwndOwner,
00221     DLGPROC dlgprc)
00222 {
00223     UNREFERENCED_PARAMETER(hWlx);
00224 
00225     TRACE("WlxDialogBoxIndirect()\n");
00226 
00227     if (PreviousWindowProc != NULL)
00228         return -1;
00229     PreviousWindowProc = dlgprc;
00230     return (int)DialogBoxIndirectW(hInst, hDialogTemplate, hwndOwner, DefaultWlxWindowProc);
00231 }
00232 
00233 /*
00234  * @implemented
00235  */
00236 int WINAPI
00237 WlxDialogBoxIndirectParam(
00238     HANDLE hWlx,
00239     HANDLE hInst,
00240     LPCDLGTEMPLATE hDialogTemplate,
00241     HWND hwndOwner,
00242     DLGPROC dlgprc,
00243     LPARAM dwInitParam)
00244 {
00245     UNREFERENCED_PARAMETER(hWlx);
00246 
00247     TRACE("WlxDialogBoxIndirectParam()\n");
00248 
00249     if (PreviousWindowProc != NULL)
00250         return -1;
00251     PreviousWindowProc = dlgprc;
00252     return (int)DialogBoxIndirectParamW(hInst, hDialogTemplate, hwndOwner, DefaultWlxWindowProc, dwInitParam);
00253 }
00254 
00255 /*
00256  * @implemented
00257  */
00258 int WINAPI
00259 WlxSwitchDesktopToUser(
00260     HANDLE hWlx)
00261 {
00262     PWLSESSION Session = (PWLSESSION)hWlx;
00263 
00264     TRACE("WlxSwitchDesktopToUser()\n");
00265 
00266     return (int)SwitchDesktop(Session->ApplicationDesktop);
00267 }
00268 
00269 /*
00270  * @implemented
00271  */
00272 int WINAPI
00273 WlxSwitchDesktopToWinlogon(
00274     HANDLE hWlx)
00275 {
00276     PWLSESSION Session = (PWLSESSION)hWlx;
00277 
00278     TRACE("WlxSwitchDesktopToWinlogon()\n");
00279 
00280     return (int)SwitchDesktop(Session->WinlogonDesktop);
00281 }
00282 
00283 /*
00284  * @unimplemented
00285  */
00286 int WINAPI
00287 WlxChangePasswordNotify(
00288     HANDLE hWlx,
00289     PWLX_MPR_NOTIFY_INFO pMprInfo,
00290     DWORD dwChangeInfo)
00291 {
00292     UNREFERENCED_PARAMETER(hWlx);
00293     UNREFERENCED_PARAMETER(pMprInfo);
00294     UNREFERENCED_PARAMETER(dwChangeInfo);
00295 
00296     UNIMPLEMENTED;
00297     return 0;
00298 }
00299 
00300 /*
00301  * @unimplemented
00302  */
00303 BOOL WINAPI
00304 WlxGetSourceDesktop(
00305     HANDLE hWlx,
00306     PWLX_DESKTOP* ppDesktop)
00307 {
00308     UNREFERENCED_PARAMETER(hWlx);
00309     UNREFERENCED_PARAMETER(ppDesktop);
00310 
00311     UNIMPLEMENTED;
00312     return FALSE;
00313 }
00314 
00315 /*
00316  * @unimplemented
00317  */
00318 BOOL WINAPI
00319 WlxSetReturnDesktop(
00320     HANDLE hWlx,
00321     PWLX_DESKTOP pDesktop)
00322 {
00323     UNREFERENCED_PARAMETER(hWlx);
00324     UNREFERENCED_PARAMETER(pDesktop);
00325 
00326     UNIMPLEMENTED;
00327     return FALSE;
00328 }
00329 
00330 /*
00331  * @unimplemented
00332  */
00333 BOOL WINAPI
00334 WlxCreateUserDesktop(
00335     HANDLE hWlx,
00336     HANDLE hToken,
00337     DWORD Flags,
00338     PWSTR pszDesktopName,
00339     PWLX_DESKTOP* ppDesktop)
00340 {
00341     UNREFERENCED_PARAMETER(hWlx);
00342     UNREFERENCED_PARAMETER(hToken);
00343     UNREFERENCED_PARAMETER(Flags);
00344     UNREFERENCED_PARAMETER(pszDesktopName);
00345     UNREFERENCED_PARAMETER(ppDesktop);
00346 
00347     UNIMPLEMENTED;
00348     return FALSE;
00349 }
00350 
00351 /*
00352  * @unimplemented
00353  */
00354 int WINAPI
00355 WlxChangePasswordNotifyEx(
00356     HANDLE hWlx,
00357     PWLX_MPR_NOTIFY_INFO pMprInfo,
00358     DWORD dwChangeInfo,
00359     PWSTR ProviderName,
00360     PVOID Reserved)
00361 {
00362     UNREFERENCED_PARAMETER(hWlx);
00363     UNREFERENCED_PARAMETER(pMprInfo);
00364     UNREFERENCED_PARAMETER(dwChangeInfo);
00365     UNREFERENCED_PARAMETER(ProviderName);
00366     UNREFERENCED_PARAMETER(Reserved);
00367 
00368     UNIMPLEMENTED;
00369     return 0;
00370 }
00371 
00372 /*
00373  * @unimplemented
00374  */
00375 BOOL WINAPI
00376 WlxCloseUserDesktop(
00377     HANDLE hWlx,
00378     PWLX_DESKTOP pDesktop,
00379     HANDLE hToken)
00380 {
00381     UNREFERENCED_PARAMETER(hWlx);
00382     UNREFERENCED_PARAMETER(pDesktop);
00383     UNREFERENCED_PARAMETER(hToken);
00384 
00385     UNIMPLEMENTED;
00386     return FALSE;
00387 }
00388 
00389 /*
00390  * @implemented
00391  */
00392 BOOL WINAPI
00393 WlxSetOption(
00394     HANDLE hWlx,
00395     DWORD Option,
00396     ULONG_PTR Value,
00397     ULONG_PTR* OldValue)
00398 {
00399     PWLSESSION Session = (PWLSESSION)hWlx;
00400 
00401     TRACE("WlxSetOption(%lu)\n", Option);
00402 
00403     switch (Option)
00404     {
00405         case WLX_OPTION_USE_CTRL_ALT_DEL:
00406             *OldValue = (ULONG_PTR)Session->Gina.UseCtrlAltDelete;
00407             Session->Gina.UseCtrlAltDelete = (BOOL)Value;
00408             return TRUE;
00409         case WLX_OPTION_CONTEXT_POINTER:
00410             *OldValue = (ULONG_PTR)Session->Gina.Context;
00411             Session->Gina.Context = (PVOID)Value;
00412             return TRUE;
00413         case WLX_OPTION_USE_SMART_CARD:
00414             UNIMPLEMENTED;
00415             return FALSE;
00416     }
00417 
00418     return FALSE;
00419 }
00420 
00421 /*
00422  * @implemented
00423  */
00424 BOOL WINAPI
00425 WlxGetOption(
00426     HANDLE hWlx,
00427     DWORD Option,
00428     ULONG_PTR* Value)
00429 {
00430     PWLSESSION Session = (PWLSESSION)hWlx;
00431 
00432     TRACE("WlxGetOption(%lu)\n", Option);
00433 
00434     switch (Option)
00435     {
00436         case WLX_OPTION_USE_CTRL_ALT_DEL:
00437             *Value = (ULONG_PTR)Session->Gina.UseCtrlAltDelete;
00438             return TRUE;
00439         case WLX_OPTION_CONTEXT_POINTER:
00440         {
00441             *Value = (ULONG_PTR)Session->Gina.Context;
00442             return TRUE;
00443         }
00444         case WLX_OPTION_USE_SMART_CARD:
00445         case WLX_OPTION_SMART_CARD_PRESENT:
00446         case WLX_OPTION_SMART_CARD_INFO:
00447             UNIMPLEMENTED;
00448             return FALSE;
00449         case WLX_OPTION_DISPATCH_TABLE_SIZE:
00450         {
00451             switch (Session->Gina.Version)
00452             {
00453                 case WLX_VERSION_1_0:
00454                     *Value = sizeof(WLX_DISPATCH_VERSION_1_0);
00455                     break;
00456                 case WLX_VERSION_1_1:
00457                     *Value = sizeof(WLX_DISPATCH_VERSION_1_1);
00458                     break;
00459                 case WLX_VERSION_1_2:
00460                     *Value = sizeof(WLX_DISPATCH_VERSION_1_2);
00461                     break;
00462                 case WLX_VERSION_1_3:
00463                     *Value = sizeof(WLX_DISPATCH_VERSION_1_3);
00464                     break;
00465                 case WLX_VERSION_1_4:
00466                     *Value = sizeof(WLX_DISPATCH_VERSION_1_4);
00467                     break;
00468                 default:
00469                     return FALSE;
00470             }
00471             return TRUE;
00472         }
00473     }
00474 
00475     return FALSE;
00476 }
00477 
00478 /*
00479  * @unimplemented
00480  */
00481 VOID WINAPI
00482 WlxWin31Migrate(
00483     HANDLE hWlx)
00484 {
00485     UNREFERENCED_PARAMETER(hWlx);
00486 
00487     UNIMPLEMENTED;
00488 }
00489 
00490 /*
00491  * @unimplemented
00492  */
00493 BOOL WINAPI
00494 WlxQueryClientCredentials(
00495     PWLX_CLIENT_CREDENTIALS_INFO_V1_0 pCred)
00496 {
00497     UNREFERENCED_PARAMETER(pCred);
00498 
00499     UNIMPLEMENTED;
00500     return FALSE;
00501 }
00502 
00503 /*
00504  * @unimplemented
00505  */
00506 BOOL WINAPI
00507 WlxQueryInetConnectorCredentials(
00508     PWLX_CLIENT_CREDENTIALS_INFO_V1_0 pCred)
00509 {
00510     UNREFERENCED_PARAMETER(pCred);
00511 
00512     UNIMPLEMENTED;
00513     return FALSE;
00514 }
00515 
00516 /*
00517  * @unimplemented
00518  */
00519 BOOL WINAPI
00520 WlxDisconnect(VOID)
00521 {
00522     UNIMPLEMENTED;
00523     return FALSE;
00524 }
00525 
00526 /*
00527  * @unimplemented
00528  */
00529 DWORD WINAPI
00530 WlxQueryTerminalServicesData(
00531     HANDLE hWlx,
00532     PWLX_TERMINAL_SERVICES_DATA pTSData,
00533     WCHAR* UserName,
00534     WCHAR* Domain)
00535 {
00536     UNREFERENCED_PARAMETER(hWlx);
00537     UNREFERENCED_PARAMETER(pTSData);
00538     UNREFERENCED_PARAMETER(UserName);
00539     UNREFERENCED_PARAMETER(Domain);
00540 
00541     UNIMPLEMENTED;
00542     return 0;
00543 }
00544 
00545 /*
00546  * @unimplemented
00547  */
00548 DWORD WINAPI
00549 WlxQueryConsoleSwitchCredentials(
00550     PWLX_CONSOLESWITCH_CREDENTIALS_INFO_V1_0 pCred)
00551 {
00552     UNREFERENCED_PARAMETER(pCred);
00553 
00554     UNIMPLEMENTED;
00555     return 0;
00556 }
00557 
00558 /*
00559  * @unimplemented
00560  */
00561 BOOL WINAPI
00562 WlxQueryTsLogonCredentials(
00563     PWLX_CLIENT_CREDENTIALS_INFO_V2_0 pCred)
00564 {
00565     UNREFERENCED_PARAMETER(pCred);
00566 
00567     UNIMPLEMENTED;
00568     return FALSE;
00569 }
00570 
00571 static
00572 WLX_DISPATCH_VERSION_1_4 FunctionTable = {
00573     WlxUseCtrlAltDel,
00574     WlxSetContextPointer,
00575     WlxSasNotify,
00576     WlxSetTimeout,
00577     WlxAssignShellProtection,
00578     WlxMessageBox,
00579     WlxDialogBox,
00580     WlxDialogBoxParam,
00581     WlxDialogBoxIndirect,
00582     WlxDialogBoxIndirectParam,
00583     WlxSwitchDesktopToUser,
00584     WlxSwitchDesktopToWinlogon,
00585     WlxChangePasswordNotify,
00586     WlxGetSourceDesktop,
00587     WlxSetReturnDesktop,
00588     WlxCreateUserDesktop,
00589     WlxChangePasswordNotifyEx,
00590     WlxCloseUserDesktop,
00591     WlxSetOption,
00592     WlxGetOption,
00593     WlxWin31Migrate,
00594     WlxQueryClientCredentials,
00595     WlxQueryInetConnectorCredentials,
00596     WlxDisconnect,
00597     WlxQueryTerminalServicesData,
00598     WlxQueryConsoleSwitchCredentials,
00599     WlxQueryTsLogonCredentials
00600 };
00601 
00602 /******************************************************************************/
00603 
00604 static BOOL
00605 GetGinaPath(
00606     OUT LPWSTR Path,
00607     IN DWORD Len)
00608 {
00609     LONG Status;
00610     DWORD Type, Size;
00611     HKEY hKey;
00612 
00613     Status = RegOpenKeyExW(
00614         HKEY_LOCAL_MACHINE,
00615         L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon",
00616         0,
00617         KEY_QUERY_VALUE,
00618         &hKey);
00619     if (Status != ERROR_SUCCESS)
00620     {
00621         /* Default value */
00622         wcsncpy(Path, L"msgina.dll", Len);
00623         return TRUE;
00624     }
00625 
00626     Size = Len * sizeof(WCHAR);
00627     Status = RegQueryValueExW(
00628         hKey,
00629         L"GinaDLL",
00630         NULL,
00631         &Type,
00632         (LPBYTE)Path,
00633         &Size);
00634     if (Status != ERROR_SUCCESS || Type != REG_SZ || Size == 0)
00635         wcsncpy(Path, L"msgina.dll", Len);
00636     RegCloseKey(hKey);
00637     return TRUE;
00638 }
00639 
00640 static BOOL WINAPI
00641 DefaultWlxScreenSaverNotify(
00642     IN PVOID pWlxContext,
00643     IN OUT BOOL *pSecure)
00644 {
00645     if (*pSecure)
00646         *pSecure = WLSession->Gina.Functions.WlxIsLogoffOk(pWlxContext);
00647     return TRUE;
00648 }
00649 
00650 static BOOL
00651 LoadGina(
00652     IN OUT PGINAFUNCTIONS Functions,
00653     OUT DWORD *DllVersion,
00654     OUT HMODULE *GinaInstance)
00655 {
00656     HMODULE hGina = NULL;
00657     WCHAR GinaDll[MAX_PATH + 1];
00658     BOOL ret = FALSE;
00659 
00660     GinaDll[0] = '\0';
00661     if (!GetGinaPath(GinaDll, MAX_PATH))
00662         goto cleanup;
00663     /* Terminate string */
00664     GinaDll[MAX_PATH] = '\0';
00665 
00666     hGina = LoadLibraryW(GinaDll);
00667     if (!hGina)
00668         goto cleanup;
00669 
00670     Functions->WlxNegotiate = (PFWLXNEGOTIATE)GetProcAddress(hGina, "WlxNegotiate");
00671     Functions->WlxInitialize = (PFWLXINITIALIZE)GetProcAddress(hGina, "WlxInitialize");
00672 
00673     if (!Functions->WlxInitialize)
00674         goto cleanup;
00675 
00676     if (!Functions->WlxNegotiate)
00677     {
00678         /* Assume current version */
00679         *DllVersion = WLX_CURRENT_VERSION;
00680     }
00681     else
00682     {
00683         TRACE("About to negociate with Gina %S. Winlogon uses version %x\n",
00684             GinaDll, WLX_CURRENT_VERSION);
00685         if (!Functions->WlxNegotiate(WLX_CURRENT_VERSION, DllVersion))
00686             goto cleanup;
00687     }
00688 
00689     TRACE("Gina uses WLX_VERSION %lx\n", *DllVersion);
00690 
00691     if (*DllVersion >= WLX_VERSION_1_0)
00692     {
00693         Functions->WlxActivateUserShell = (PFWLXACTIVATEUSERSHELL)GetProcAddress(hGina, "WlxActivateUserShell");
00694         if (!Functions->WlxActivateUserShell) goto cleanup;
00695         Functions->WlxDisplayLockedNotice = (PFWLXDISPLAYLOCKEDNOTICE)GetProcAddress(hGina, "WlxDisplayLockedNotice");
00696         if (!Functions->WlxDisplayLockedNotice) goto cleanup;
00697         Functions->WlxDisplaySASNotice = (PFWLXDISPLAYSASNOTICE)GetProcAddress(hGina, "WlxDisplaySASNotice");
00698         if (!Functions->WlxDisplaySASNotice) goto cleanup;
00699         Functions->WlxIsLockOk = (PFWLXISLOCKOK)GetProcAddress(hGina, "WlxIsLockOk");
00700         if (!Functions->WlxIsLockOk) goto cleanup;
00701         Functions->WlxIsLogoffOk = (PFWLXISLOGOFFOK)GetProcAddress(hGina, "WlxIsLogoffOk");
00702         if (!Functions->WlxIsLogoffOk) goto cleanup;
00703         Functions->WlxLoggedOnSAS = (PFWLXLOGGEDONSAS)GetProcAddress(hGina, "WlxLoggedOnSAS");
00704         if (!Functions->WlxLoggedOnSAS) goto cleanup;
00705         Functions->WlxLoggedOutSAS = (PFWLXLOGGEDOUTSAS)GetProcAddress(hGina, "WlxLoggedOutSAS");
00706         if (!Functions->WlxLoggedOutSAS) goto cleanup;
00707         Functions->WlxLogoff = (PFWLXLOGOFF)GetProcAddress(hGina, "WlxLogoff");
00708         if (!Functions->WlxLogoff) goto cleanup;
00709         Functions->WlxShutdown = (PFWLXSHUTDOWN)GetProcAddress(hGina, "WlxShutdown");
00710         if (!Functions->WlxShutdown) goto cleanup;
00711         Functions->WlxWkstaLockedSAS = (PFWLXWKSTALOCKEDSAS)GetProcAddress(hGina, "WlxWkstaLockedSAS");
00712         if (!Functions->WlxWkstaLockedSAS) goto cleanup;
00713     }
00714 
00715     if (*DllVersion >= WLX_VERSION_1_1)
00716     {
00717         Functions->WlxScreenSaverNotify = (PFWLXSCREENSAVERNOTIFY)GetProcAddress(hGina, "WlxScreenSaverNotify");
00718         Functions->WlxStartApplication = (PFWLXSTARTAPPLICATION)GetProcAddress(hGina, "WlxStartApplication");
00719     }
00720 
00721     if (*DllVersion >= WLX_VERSION_1_3)
00722     {
00723         Functions->WlxDisplayStatusMessage = (PFWLXDISPLAYSTATUSMESSAGE)GetProcAddress(hGina, "WlxDisplayStatusMessage");
00724         if (!Functions->WlxDisplayStatusMessage) goto cleanup;
00725         Functions->WlxGetStatusMessage = (PFWLXGETSTATUSMESSAGE)GetProcAddress(hGina, "WlxGetStatusMessage");
00726         if (!Functions->WlxGetStatusMessage) goto cleanup;
00727         Functions->WlxNetworkProviderLoad = (PFWLXNETWORKPROVIDERLOAD)GetProcAddress(hGina, "WlxNetworkProviderLoad");
00728         if (!Functions->WlxNetworkProviderLoad) goto cleanup;
00729         Functions->WlxRemoveStatusMessage = (PFWLXREMOVESTATUSMESSAGE)GetProcAddress(hGina, "WlxRemoveStatusMessage");
00730         if (!Functions->WlxRemoveStatusMessage) goto cleanup;
00731     }
00732 
00733     /* Provide some default functions */
00734     if (!Functions->WlxScreenSaverNotify)
00735         Functions->WlxScreenSaverNotify = DefaultWlxScreenSaverNotify;
00736 
00737     ret = TRUE;
00738 
00739 cleanup:
00740     if (!ret)
00741     {
00742         if (hGina)
00743             FreeLibrary(hGina);
00744     }
00745     else
00746         *GinaInstance = hGina;
00747     return ret;
00748 }
00749 
00750 BOOL
00751 GinaInit(
00752     IN OUT PWLSESSION Session)
00753 {
00754     DWORD GinaDllVersion;
00755 
00756     if (!LoadGina(&Session->Gina.Functions, &GinaDllVersion, &Session->Gina.hDllInstance))
00757         return FALSE;
00758 
00759     Session->Gina.Context = NULL;
00760     Session->Gina.Version = GinaDllVersion;
00761     Session->Gina.UseCtrlAltDelete = FALSE;
00762     Session->SuppressStatus = FALSE;
00763     PreviousWindowProc = NULL;
00764 
00765     TRACE("Calling WlxInitialize(\"%S\")\n", Session->InteractiveWindowStationName);
00766     return Session->Gina.Functions.WlxInitialize(
00767         Session->InteractiveWindowStationName,
00768         (HANDLE)Session,
00769         NULL,
00770         (PVOID)&FunctionTable,
00771         &Session->Gina.Context);
00772 }
00773 
00774 BOOL
00775 AddAceToWindowStation(
00776     IN HWINSTA WinSta,
00777     IN PSID Sid)
00778 {
00779     DWORD AclSize;
00780     SECURITY_INFORMATION SecurityInformation;
00781     PACL pDefaultAcl = NULL;
00782     PSECURITY_DESCRIPTOR WinstaSd = NULL;
00783     PACCESS_ALLOWED_ACE Ace = NULL;
00784     BOOL Ret = FALSE;
00785 
00786     /* Allocate space for an ACL */
00787     AclSize = sizeof(ACL)
00788         + 2 * (FIELD_OFFSET(ACCESS_ALLOWED_ACE, SidStart) + GetLengthSid(Sid));
00789     pDefaultAcl = HeapAlloc(GetProcessHeap(), 0, AclSize);
00790     if (!pDefaultAcl)
00791     {
00792         ERR("WL: HeapAlloc() failed\n");
00793         goto cleanup;
00794     }
00795 
00796     /* Initialize it */
00797     if (!InitializeAcl(pDefaultAcl, AclSize, ACL_REVISION))
00798     {
00799         ERR("WL: InitializeAcl() failed (error %lu)\n", GetLastError());
00800         goto cleanup;
00801     }
00802 
00803     /* Initialize new security descriptor */
00804     WinstaSd = HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH);
00805     if (!InitializeSecurityDescriptor(WinstaSd, SECURITY_DESCRIPTOR_REVISION))
00806     {
00807         ERR("WL: InitializeSecurityDescriptor() failed (error %lu)\n", GetLastError());
00808         goto cleanup;
00809     }
00810 
00811     /* Allocate memory for access allowed ACE */
00812     Ace = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ACCESS_ALLOWED_ACE)+
00813         GetLengthSid(Sid) - sizeof(DWORD));
00814 
00815     /* Create the first ACE for the window station */
00816     Ace->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
00817     Ace->Header.AceFlags = CONTAINER_INHERIT_ACE | INHERIT_ONLY_ACE | OBJECT_INHERIT_ACE;
00818     Ace->Header.AceSize = sizeof(ACCESS_ALLOWED_ACE) + GetLengthSid(Sid) - sizeof(DWORD);
00819     Ace->Mask = GENERIC_ACCESS;
00820 
00821     /* Copy the sid */
00822     if (!CopySid(GetLengthSid(Sid), &Ace->SidStart, Sid))
00823     {
00824         ERR("WL: CopySid() failed (error %lu)\n", GetLastError());
00825         goto cleanup;
00826     }
00827 
00828     /* Add the first ACE */
00829     if (!AddAce(pDefaultAcl, ACL_REVISION, MAXDWORD, (LPVOID)Ace, Ace->Header.AceSize))
00830     {
00831         ERR("WL: AddAce() failed (error %lu)\n", GetLastError());
00832         goto cleanup;
00833     }
00834 
00835     /* Add the second ACE to the end of ACL */
00836     Ace->Header.AceFlags = NO_PROPAGATE_INHERIT_ACE;
00837     Ace->Mask = WINSTA_ALL;
00838     if (!AddAce(pDefaultAcl, ACL_REVISION, MAXDWORD, (LPVOID)Ace, Ace->Header.AceSize))
00839     {
00840         ERR("WL: AddAce() failed (error %lu)\n", GetLastError());
00841         goto cleanup;
00842     }
00843 
00844     /* Add ACL to winsta's security descriptor */
00845     if (!SetSecurityDescriptorDacl(WinstaSd, TRUE, pDefaultAcl, FALSE))
00846     {
00847         ERR("WL: SetSecurityDescriptorDacl() failed (error %lu)\n", GetLastError());
00848         goto cleanup;
00849     }
00850 
00851     /* Apply security to the window station */
00852     SecurityInformation = DACL_SECURITY_INFORMATION;
00853     if (!SetUserObjectSecurity(WinSta, &SecurityInformation, WinstaSd))
00854     {
00855         ERR("WL: SetUserObjectSecurity() failed (error %lu)\n", GetLastError());
00856         goto cleanup;
00857     }
00858 
00859     /* Indicate success */
00860     Ret = TRUE;
00861 
00862 cleanup:
00863     /* Free allocated stuff */
00864     if (pDefaultAcl) HeapFree(GetProcessHeap(), 0, pDefaultAcl);
00865     if (WinstaSd) HeapFree(GetProcessHeap(), 0, WinstaSd);
00866     if (Ace) HeapFree(GetProcessHeap(), 0, Ace);
00867 
00868     return Ret;
00869 }
00870 
00871 BOOL
00872 AddAceToDesktop(
00873     IN HDESK Desktop,
00874     IN PSID WinlogonSid,
00875     IN PSID UserSid)
00876 {
00877     DWORD AclSize;
00878     SECURITY_INFORMATION SecurityInformation;
00879     PACL Acl = NULL;
00880     PSECURITY_DESCRIPTOR DesktopSd = NULL;
00881     BOOL Ret = FALSE;
00882 
00883     /* Allocate ACL */
00884     AclSize = sizeof(ACL)
00885         + FIELD_OFFSET(ACCESS_ALLOWED_ACE, SidStart) + GetLengthSid(WinlogonSid);
00886 
00887     /* Take user's sid into account */
00888     if (UserSid)
00889         AclSize += FIELD_OFFSET(ACCESS_ALLOWED_ACE, SidStart) + GetLengthSid(UserSid);
00890 
00891     Acl = HeapAlloc(GetProcessHeap(), 0, AclSize);
00892     if (!Acl)
00893     {
00894         ERR("WL: HeapAlloc() failed\n");
00895         goto cleanup;
00896     }
00897 
00898     /* Initialize ACL */
00899     if (!InitializeAcl(Acl, AclSize, ACL_REVISION))
00900     {
00901         ERR("WL: InitializeAcl() failed (error %lu)\n", GetLastError());
00902         goto cleanup;
00903     }
00904 
00905     /* Add full desktop access ACE for winlogon */
00906     if (!AddAccessAllowedAce(Acl, ACL_REVISION, DESKTOP_ALL, WinlogonSid))
00907     {
00908         ERR("WL: AddAccessAllowedAce() failed (error %lu)\n", GetLastError());
00909         goto cleanup;
00910     }
00911 
00912     /* Add full desktop access ACE for a user (if provided) */
00913     if (UserSid && !AddAccessAllowedAce(Acl, ACL_REVISION, DESKTOP_ALL, UserSid))
00914     {
00915         ERR("WL: AddAccessAllowedAce() failed (error %lu)\n", GetLastError());
00916         goto cleanup;
00917     }
00918 
00919     /* Initialize new security descriptor */
00920     DesktopSd = HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH);
00921     if (!InitializeSecurityDescriptor(DesktopSd, SECURITY_DESCRIPTOR_REVISION))
00922     {
00923         ERR("WL: InitializeSecurityDescriptor() failed (error %lu)\n", GetLastError());
00924         goto cleanup;
00925     }
00926 
00927     /* Add ACL to the security descriptor */
00928     if (!SetSecurityDescriptorDacl(DesktopSd, TRUE, Acl, FALSE))
00929     {
00930         ERR("WL: SetSecurityDescriptorDacl() failed (error %lu)\n", GetLastError());
00931         goto cleanup;
00932     }
00933 
00934     /* Apply security to the window station */
00935     SecurityInformation = DACL_SECURITY_INFORMATION;
00936     if (!SetUserObjectSecurity(Desktop, &SecurityInformation, DesktopSd))
00937     {
00938         ERR("WL: SetUserObjectSecurity() failed (error %lu)\n", GetLastError());
00939         goto cleanup;
00940     }
00941 
00942     /* Indicate success */
00943     Ret = TRUE;
00944 
00945 cleanup:
00946     /* Free allocated stuff */
00947     if (Acl) HeapFree(GetProcessHeap(), 0, Acl);
00948     if (DesktopSd) HeapFree(GetProcessHeap(), 0, DesktopSd);
00949 
00950     return Ret;
00951 }
00952 
00953 BOOL
00954 CreateWindowStationAndDesktops(
00955     IN OUT PWLSESSION Session)
00956 {
00957     BYTE LocalSystemBuffer[SECURITY_MAX_SID_SIZE];
00958     BYTE InteractiveBuffer[SECURITY_MAX_SID_SIZE];
00959     PSID pLocalSystemSid = (PSID)&LocalSystemBuffer;
00960     PSID pInteractiveSid = (PSID)InteractiveBuffer;
00961     DWORD SidSize, AclSize;
00962     PACL pDefaultAcl = NULL;
00963     PACL pUserDesktopAcl = NULL;
00964     SECURITY_DESCRIPTOR DefaultSecurityDescriptor;
00965     SECURITY_ATTRIBUTES DefaultSecurity;
00966     SECURITY_DESCRIPTOR UserDesktopSecurityDescriptor;
00967     SECURITY_ATTRIBUTES UserDesktopSecurity;
00968     BOOL ret = FALSE;
00969 
00970     /*
00971      * Prepare information for ACLs we will apply
00972      */
00973     SidSize = SECURITY_MAX_SID_SIZE;
00974     if (!CreateWellKnownSid(WinLocalSystemSid, NULL, pLocalSystemSid, &SidSize))
00975     {
00976         ERR("WL: CreateWellKnownSid() failed (error %lu)\n", GetLastError());
00977         goto cleanup;
00978     }
00979     SidSize = SECURITY_MAX_SID_SIZE;
00980     if (!CreateWellKnownSid(WinInteractiveSid, NULL, pInteractiveSid, &SidSize))
00981     {
00982         ERR("WL: CreateWellKnownSid() failed (error %lu)\n", GetLastError());
00983         goto cleanup;
00984     }
00985 
00986     AclSize = sizeof(ACL)
00987         + FIELD_OFFSET(ACCESS_ALLOWED_ACE, SidStart) + GetLengthSid(pLocalSystemSid)
00988         + FIELD_OFFSET(ACCESS_ALLOWED_ACE, SidStart) + GetLengthSid(pInteractiveSid);
00989     pDefaultAcl = HeapAlloc(GetProcessHeap(), 0, AclSize);
00990     pUserDesktopAcl = HeapAlloc(GetProcessHeap(), 0, AclSize);
00991     if (!pDefaultAcl || !pUserDesktopAcl)
00992     {
00993         ERR("WL: HeapAlloc() failed\n");
00994         goto cleanup;
00995     }
00996 
00997     if (!InitializeAcl(pDefaultAcl, AclSize, ACL_REVISION)
00998      || !InitializeAcl(pUserDesktopAcl, AclSize, ACL_REVISION))
00999     {
01000         ERR("WL: InitializeAcl() failed (error %lu)\n", GetLastError());
01001         goto cleanup;
01002     }
01003 
01004     /*
01005      * Create default ACL (window station, winlogon desktop, screen saver desktop)
01006      */
01007     if (!AddAccessAllowedAce(pDefaultAcl, ACL_REVISION, GENERIC_ALL, pLocalSystemSid)
01008      || !AddAccessAllowedAce(pDefaultAcl, ACL_REVISION, GENERIC_READ, pInteractiveSid))
01009     {
01010         ERR("WL: AddAccessAllowedAce() failed (error %lu)\n", GetLastError());
01011         goto cleanup;
01012     }
01013 
01014     /*
01015      * Create the default security descriptor
01016      */
01017     if (!InitializeSecurityDescriptor(&DefaultSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION))
01018     {
01019         ERR("WL: InitializeSecurityDescriptor() failed (error %lu)\n", GetLastError());
01020         goto cleanup;
01021     }
01022 
01023     if (!SetSecurityDescriptorDacl(&DefaultSecurityDescriptor, TRUE, pDefaultAcl, FALSE))
01024     {
01025         ERR("WL: SetSecurityDescriptorDacl() failed (error %lu)\n", GetLastError());
01026         goto cleanup;
01027     }
01028 
01029     DefaultSecurity.nLength = sizeof(SECURITY_ATTRIBUTES);
01030     DefaultSecurity.lpSecurityDescriptor = &DefaultSecurityDescriptor;
01031     DefaultSecurity.bInheritHandle = TRUE;
01032 
01033     /*
01034      * Create user desktop ACL
01035      */
01036     if (!AddAccessAllowedAce(pUserDesktopAcl, ACL_REVISION, GENERIC_ALL, pLocalSystemSid)
01037      || !AddAccessAllowedAce(pUserDesktopAcl, ACL_REVISION, GENERIC_ALL, pInteractiveSid))
01038     {
01039         ERR("WL: AddAccessAllowedAce() failed (error %lu)\n", GetLastError());
01040         goto cleanup;
01041     }
01042 
01043     /*
01044      * Create the user desktop security descriptor
01045      */
01046     if (!InitializeSecurityDescriptor(&UserDesktopSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION))
01047     {
01048         ERR("WL: InitializeSecurityDescriptor() failed (error %lu)\n", GetLastError());
01049         goto cleanup;
01050     }
01051 
01052     if (!SetSecurityDescriptorDacl(&UserDesktopSecurityDescriptor, TRUE, pUserDesktopAcl, FALSE))
01053     {
01054         ERR("WL: SetSecurityDescriptorDacl() failed (error %lu)\n", GetLastError());
01055         goto cleanup;
01056     }
01057 
01058     UserDesktopSecurity.nLength = sizeof(SECURITY_ATTRIBUTES);
01059     UserDesktopSecurity.lpSecurityDescriptor = &UserDesktopSecurityDescriptor;
01060     UserDesktopSecurity.bInheritHandle = TRUE;
01061 
01062     /*
01063      * Create the interactive window station
01064      */
01065     Session->InteractiveWindowStationName = L"WinSta0";
01066     Session->InteractiveWindowStation = CreateWindowStationW(
01067         Session->InteractiveWindowStationName,
01068         0,
01069         GENERIC_ALL,
01070         &DefaultSecurity);
01071     if (!Session->InteractiveWindowStation)
01072     {
01073         ERR("WL: Failed to create window station (%lu)\n", GetLastError());
01074         goto cleanup;
01075     }
01076     if (!SetProcessWindowStation(Session->InteractiveWindowStation))
01077     {
01078         ERR("WL: SetProcessWindowStation() failed (error %lu)\n", GetLastError());
01079         goto cleanup;
01080     }
01081 
01082     /*
01083      * Create the application desktop
01084      */
01085     Session->ApplicationDesktop = CreateDesktopW(
01086         L"Default",
01087         NULL,
01088         NULL,
01089         0, /* FIXME: Add DF_ALLOWOTHERACCOUNTHOOK flag? */
01090         GENERIC_ALL,
01091         &UserDesktopSecurity);
01092     if (!Session->ApplicationDesktop)
01093     {
01094         ERR("WL: Failed to create Default desktop (%lu)\n", GetLastError());
01095         goto cleanup;
01096     }
01097 
01098     /*
01099      * Create the winlogon desktop
01100      */
01101     Session->WinlogonDesktop = CreateDesktopW(
01102         L"Winlogon",
01103         NULL,
01104         NULL,
01105         0,
01106         GENERIC_ALL,
01107         &DefaultSecurity);
01108     if (!Session->WinlogonDesktop)
01109     {
01110         ERR("WL: Failed to create Winlogon desktop (%lu)\n", GetLastError());
01111         goto cleanup;
01112     }
01113 
01114     /*
01115      * Create the screen saver desktop
01116      */
01117     Session->ScreenSaverDesktop = CreateDesktopW(
01118         L"Screen-Saver",
01119         NULL,
01120         NULL,
01121         0,
01122         GENERIC_ALL,
01123         &DefaultSecurity);
01124     if(!Session->ScreenSaverDesktop)
01125     {
01126         ERR("WL: Failed to create Screen-Saver desktop (%lu)\n", GetLastError());
01127         goto cleanup;
01128     }
01129 
01130     /* FIXME: big HACK */
01131     CloseDesktop(Session->WinlogonDesktop);
01132     CloseDesktop(Session->ScreenSaverDesktop);
01133     Session->WinlogonDesktop = OpenDesktopW(L"Default", 0, FALSE, GENERIC_ALL);
01134     Session->ScreenSaverDesktop = OpenDesktopW(L"Default", 0, FALSE, GENERIC_ALL);
01135 
01136     /*
01137      * Switch to winlogon desktop
01138     */
01139     if (!SetThreadDesktop(Session->WinlogonDesktop) ||
01140         !SwitchDesktop(Session->WinlogonDesktop))
01141     {
01142         ERR("WL: Cannot switch to Winlogon desktop (%lu)\n", GetLastError());
01143         goto cleanup;
01144     }
01145 
01146     ret = TRUE;
01147 
01148 cleanup:
01149     if (!ret)
01150     {
01151         if (Session->ApplicationDesktop)
01152         {
01153             CloseDesktop(Session->ApplicationDesktop);
01154             Session->ApplicationDesktop = NULL;
01155         }
01156         if (Session->WinlogonDesktop)
01157         {
01158             CloseDesktop(Session->WinlogonDesktop);
01159             Session->WinlogonDesktop = NULL;
01160         }
01161         if (Session->ScreenSaverDesktop)
01162         {
01163             CloseDesktop(Session->ScreenSaverDesktop);
01164             Session->ScreenSaverDesktop = NULL;
01165         }
01166         if (Session->InteractiveWindowStation)
01167         {
01168             CloseWindowStation(Session->InteractiveWindowStation);
01169             Session->InteractiveWindowStation = NULL;
01170         }
01171     }
01172     HeapFree(GetProcessHeap(), 0, pDefaultAcl);
01173     HeapFree(GetProcessHeap(), 0, pUserDesktopAcl);
01174     return ret;
01175 }

Generated on Fri May 25 2012 04:17:04 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.