Subversion Repositories Aucun

Rev

Rev 45 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 ixe013 1
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
 
3
 THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
4
 EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
5
 WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
6
 
7
 Copyright (C) 1996 - 2000.  Microsoft Corporation.  All rights reserved.
8
 
9
 Module:   Ginahook.c
10
 
11
 Abstract: See ReadMe.txt for more detail information about this sample.
12
 
13
 Revision: August 6, 1999.
14
 
15
-------------------------------------------------------------------------------*/
16
 
17
#define _WIN32_WINNT 0x0501
18
 
19
#include <windows.h>
20
#include <winwlx.h>
21
 
22
#include "Ginahook.h"
23
#include "GinaDlg.h"
40 ixe013 24
#include "global.h"
25
#include "debug.h"
2 ixe013 26
 
46 ixe013 27
#pragma comment
2 ixe013 28
//
29
// Location of the real MSGINA.
30
//
31
 
32
#define REALGINA_PATH      TEXT("MSGINA.DLL")
33
#define GINASTUB_VERSION   (WLX_VERSION_1_4) // Highest version supported at
34
// this point. Remember to modify
35
// this as support for newer version
36
// is added to this program.
40 ixe013 37
 
38
//Hooked instance of MSGINA
39
HINSTANCE hDll;
40
 
2 ixe013 41
//
42
// Winlogon function dispatch table.
43
//
40 ixe013 44
PVOID g_pWinlogon = NULL;
2 ixe013 45
static DWORD g_dwVersion = WLX_VERSION_1_4;
46
static HANDLE WinlogonHandle = 0;
47
 
40 ixe013 48
static MyGinaContext gAucunContext = {0};
49
MyGinaContext *pgAucunContext = &gAucunContext;
50
 
2 ixe013 51
//
52
// Pointers to the real MSGINA functions.
53
//
54
 
55
static PFWLXNEGOTIATE            pfWlxNegotiate;
56
static PFWLXINITIALIZE           pfWlxInitialize;
57
static PFWLXDISPLAYSASNOTICE     pfWlxDisplaySASNotice;
58
static PFWLXLOGGEDOUTSAS         pfWlxLoggedOutSAS;
59
static PFWLXACTIVATEUSERSHELL    pfWlxActivateUserShell;
60
static PFWLXLOGGEDONSAS          pfWlxLoggedOnSAS;
61
static PFWLXDISPLAYLOCKEDNOTICE  pfWlxDisplayLockedNotice;
62
static PFWLXWKSTALOCKEDSAS       pfWlxWkstaLockedSAS;
63
static PFWLXISLOCKOK             pfWlxIsLockOk;
64
static PFWLXISLOGOFFOK           pfWlxIsLogoffOk;
65
static PFWLXLOGOFF               pfWlxLogoff;
66
static PFWLXSHUTDOWN             pfWlxShutdown;
67
 
68
//
69
// New for version 1.1
70
//
71
static PFWLXSTARTAPPLICATION     pfWlxStartApplication  = NULL;
72
static PFWLXSCREENSAVERNOTIFY    pfWlxScreenSaverNotify = NULL;
73
 
74
//
75
// New for version 1.2 - No new GINA interface was added, except
76
//                       a new function in the dispatch table.
77
//
78
 
79
//
80
// New for version 1.3
81
//
82
static PFWLXNETWORKPROVIDERLOAD   pfWlxNetworkProviderLoad  = NULL;
83
static PFWLXDISPLAYSTATUSMESSAGE  pfWlxDisplayStatusMessage = NULL;
84
static PFWLXGETSTATUSMESSAGE      pfWlxGetStatusMessage     = NULL;
85
static PFWLXREMOVESTATUSMESSAGE   pfWlxRemoveStatusMessage  = NULL;
86
 
87
//
88
// New for version 1.4
89
//
90
static PWLXGETCONSOLESWITCHCREDENTIALS pfWlxGetConsoleSwitchCredentials = NULL;
91
static PWLXRECONNECTNOTIFY pfWlxReconnectNotify  = NULL;
92
static PWLXDISCONNECTNOTIFY pfWlxDisconnectNotify = NULL;
93
 
40 ixe013 94
PVOID GetHookedContext(PVOID pWlxContext)
95
{
96
    return ((MyGinaContext*)pWlxContext)->mHookedContext;
97
}
2 ixe013 98
//
99
// Hook into the real MSGINA.
100
//
101
 
102
BOOL MyInitialize(HINSTANCE hDll, DWORD dwWlxVersion)
103
{
23 ixe013 104
   //
105
   // Get pointers to all of the WLX functions in the real MSGINA.
106
   //
107
   pfWlxInitialize = (PFWLXINITIALIZE) GetProcAddress(hDll, "WlxInitialize");
2 ixe013 108
 
23 ixe013 109
   if (!pfWlxInitialize)
110
   {
111
      return FALSE;
112
   }
2 ixe013 113
 
23 ixe013 114
   pfWlxDisplaySASNotice = (PFWLXDISPLAYSASNOTICE) GetProcAddress(hDll, "WlxDisplaySASNotice");
2 ixe013 115
 
23 ixe013 116
   if (!pfWlxDisplaySASNotice)
117
   {
118
      return FALSE;
119
   }
2 ixe013 120
 
23 ixe013 121
   pfWlxLoggedOutSAS = (PFWLXLOGGEDOUTSAS) GetProcAddress(hDll, "WlxLoggedOutSAS");
2 ixe013 122
 
23 ixe013 123
   if (!pfWlxLoggedOutSAS)
124
   {
125
      return FALSE;
126
   }
2 ixe013 127
 
23 ixe013 128
   pfWlxActivateUserShell = (PFWLXACTIVATEUSERSHELL) GetProcAddress(hDll, "WlxActivateUserShell");
2 ixe013 129
 
23 ixe013 130
   if (!pfWlxActivateUserShell)
131
   {
132
      return FALSE;
133
   }
2 ixe013 134
 
23 ixe013 135
   pfWlxLoggedOnSAS = (PFWLXLOGGEDONSAS) GetProcAddress(hDll, "WlxLoggedOnSAS");
2 ixe013 136
 
23 ixe013 137
   if (!pfWlxLoggedOnSAS)
138
   {
139
      return FALSE;
140
   }
2 ixe013 141
 
23 ixe013 142
   pfWlxDisplayLockedNotice = (PFWLXDISPLAYLOCKEDNOTICE) GetProcAddress(hDll, "WlxDisplayLockedNotice");
2 ixe013 143
 
23 ixe013 144
   if (!pfWlxDisplayLockedNotice)
145
   {
146
      return FALSE;
147
   }
2 ixe013 148
 
23 ixe013 149
   pfWlxIsLockOk = (PFWLXISLOCKOK) GetProcAddress(hDll, "WlxIsLockOk");
2 ixe013 150
 
23 ixe013 151
   if (!pfWlxIsLockOk)
152
   {
153
      return FALSE;
154
   }
2 ixe013 155
 
23 ixe013 156
   pfWlxWkstaLockedSAS = (PFWLXWKSTALOCKEDSAS) GetProcAddress(hDll, "WlxWkstaLockedSAS");
2 ixe013 157
 
23 ixe013 158
   if (!pfWlxWkstaLockedSAS)
159
   {
160
      return FALSE;
161
   }
2 ixe013 162
 
23 ixe013 163
   pfWlxIsLogoffOk = (PFWLXISLOGOFFOK) GetProcAddress(hDll, "WlxIsLogoffOk");
2 ixe013 164
 
23 ixe013 165
   if (!pfWlxIsLogoffOk)
166
   {
167
      return FALSE;
168
   }
2 ixe013 169
 
23 ixe013 170
   pfWlxLogoff = (PFWLXLOGOFF) GetProcAddress(hDll, "WlxLogoff");
2 ixe013 171
 
23 ixe013 172
   if (!pfWlxLogoff)
173
   {
174
      return FALSE;
175
   }
2 ixe013 176
 
23 ixe013 177
   pfWlxShutdown = (PFWLXSHUTDOWN) GetProcAddress(hDll, "WlxShutdown");
2 ixe013 178
 
23 ixe013 179
   if (!pfWlxShutdown)
180
   {
181
      return FALSE;
182
   }
2 ixe013 183
 
23 ixe013 184
   //
185
   // Load functions for version 1.1 as necessary.
186
   //
187
   if (dwWlxVersion > WLX_VERSION_1_0)
188
   {
189
      pfWlxStartApplication = (PFWLXSTARTAPPLICATION) GetProcAddress(hDll, "WlxStartApplication");
2 ixe013 190
 
23 ixe013 191
      if (!pfWlxStartApplication)
192
      {
193
         return FALSE;
194
      }
2 ixe013 195
 
23 ixe013 196
      pfWlxScreenSaverNotify = (PFWLXSCREENSAVERNOTIFY) GetProcAddress(hDll, "WlxScreenSaverNotify");
2 ixe013 197
 
23 ixe013 198
      if (!pfWlxScreenSaverNotify)
199
      {
200
         return FALSE;
201
      }
202
   }
2 ixe013 203
 
23 ixe013 204
   //
205
   // Load functions for version 1.3 as necessary.
206
   //
207
   if (dwWlxVersion > WLX_VERSION_1_2)
208
   {
209
      pfWlxNetworkProviderLoad = (PFWLXNETWORKPROVIDERLOAD)GetProcAddress(hDll, "WlxNetworkProviderLoad");
2 ixe013 210
 
23 ixe013 211
      if (!pfWlxNetworkProviderLoad)
212
      {
213
         return FALSE;
214
      }
2 ixe013 215
 
23 ixe013 216
      pfWlxDisplayStatusMessage = (PFWLXDISPLAYSTATUSMESSAGE)GetProcAddress(hDll, "WlxDisplayStatusMessage");
2 ixe013 217
 
23 ixe013 218
      if (!pfWlxDisplayStatusMessage)
219
      {
220
         return FALSE;
221
      }
2 ixe013 222
 
23 ixe013 223
      pfWlxGetStatusMessage =(PFWLXGETSTATUSMESSAGE)GetProcAddress(hDll, "WlxGetStatusMessage");
224
      if (!pfWlxGetStatusMessage)
225
      {
226
         return FALSE;
227
      }
2 ixe013 228
 
23 ixe013 229
      pfWlxRemoveStatusMessage =
230
         (PFWLXREMOVESTATUSMESSAGE)
231
         GetProcAddress(hDll, "WlxRemoveStatusMessage");
232
      if (!pfWlxRemoveStatusMessage)
233
      {
234
         return FALSE;
235
      }
236
   }
237
 
238
   //
239
   // Load functions for version 1.3 as necessary.
240
   //
241
   if (dwWlxVersion > WLX_VERSION_1_3)
242
   {
243
      pfWlxGetConsoleSwitchCredentials = (PWLXGETCONSOLESWITCHCREDENTIALS) GetProcAddress(hDll, "WlxGetConsoleSwitchCredentials");
244
      if (!pfWlxGetConsoleSwitchCredentials) return FALSE;
245
 
246
      pfWlxReconnectNotify = (PWLXRECONNECTNOTIFY) GetProcAddress(hDll, "WlxReconnectNotify");
247
      if (!pfWlxReconnectNotify) return FALSE;
248
 
249
      pfWlxDisconnectNotify = (PWLXDISCONNECTNOTIFY) GetProcAddress(hDll, "WlxDisconnectNotify");
250
      if (!pfWlxDisconnectNotify) return FALSE;
251
 
252
   }
253
 
254
   //
255
   // Load functions for newer version here...
256
   //
257
 
258
   //
259
   // Everything loaded OK.
260
   //
261
   return TRUE;
2 ixe013 262
}
263
 
264
 
23 ixe013 265
BOOL WINAPI WlxNegotiate(DWORD dwWinlogonVersion, DWORD *pdwDllVersion)
2 ixe013 266
{
23 ixe013 267
   DWORD dwWlxVersion = GINASTUB_VERSION;
9 ixe013 268
 
23 ixe013 269
   //
270
   // Load MSGINA.DLL.
271
   //
272
   if (!(hDll = LoadLibrary(REALGINA_PATH)))
273
   {
274
      return FALSE;
275
   }
9 ixe013 276
 
23 ixe013 277
   //
278
   // Get pointers to WlxNegotiate function in the real MSGINA.
279
   //
280
   pfWlxNegotiate = (PFWLXNEGOTIATE) GetProcAddress(hDll, "WlxNegotiate");
281
   if (!pfWlxNegotiate)
282
   {
283
      return FALSE;
284
   }
9 ixe013 285
 
23 ixe013 286
   //
287
   // Handle older version of Winlogon.
288
   //
289
   if (dwWinlogonVersion < dwWlxVersion)
290
   {
291
      dwWlxVersion = dwWinlogonVersion;
292
   }
2 ixe013 293
 
23 ixe013 294
   //
295
   // Negotiate with MSGINA for version that we can support.
296
   //
297
   if (!pfWlxNegotiate(dwWlxVersion, &dwWlxVersion))
298
   {
299
      return FALSE;
300
   }
2 ixe013 301
 
23 ixe013 302
   //
303
   // Load the rest of the WLX functions from the real MSGINA.
304
   //
305
   if (!MyInitialize(hDll, dwWlxVersion))
306
   {
307
      return FALSE;
308
   }
2 ixe013 309
 
23 ixe013 310
   //
311
   // Inform Winlogon which version to use.
312
   //
313
   *pdwDllVersion = g_dwVersion = dwWlxVersion;
2 ixe013 314
 
23 ixe013 315
   return TRUE;
2 ixe013 316
}
317
 
318
 
45 ixe013 319
BOOL WINAPI AucunWlxInitialize(LPWSTR lpWinsta, HANDLE hWlx, PVOID pvReserved, PVOID pWinlogonFunctions, PVOID * pWlxContext)
2 ixe013 320
{
23 ixe013 321
   //
322
   // Save pointer to dispatch table.
323
   //
324
   // Note that g_pWinlogon will need to be properly casted to the
325
   // appropriate version when used to call function in the dispatch
326
   // table.
327
   //
328
   // For example, assuming we are at WLX_VERSION_1_3, we would call
329
   // WlxSasNotify() as follows:
330
   //
331
   // ((PWLX_DISPATCH_VERSION_1_3) g_pWinlogon)->WlxSasNotify(hWlx, MY_SAS);
332
   //
333
   g_pWinlogon = pWinlogonFunctions;
2 ixe013 334
 
23 ixe013 335
   WinlogonHandle = hWlx;
2 ixe013 336
 
23 ixe013 337
   //
338
   // Now hook the WlxDialogBoxParam() dispatch function.
339
   //
340
   HookWlxDialogBoxParam(g_pWinlogon, g_dwVersion);
2 ixe013 341
 
40 ixe013 342
    //* 
343
   *pWlxContext = &gAucunContext;
344
   gAucunContext.Winlogon = hWlx;
45 ixe013 345
   //return pfWlxInitialize(lpWinsta, hWlx, pvReserved, pWinlogonFunctions, &gAucunContext.mHookedContext);
346
   return WlxInitialize(lpWinsta, hWlx, pvReserved, pWinlogonFunctions, &gAucunContext.mHookedContext);
23 ixe013 347
}
2 ixe013 348
 
349
 
23 ixe013 350
VOID WINAPI WlxDisplaySASNotice(PVOID pWlxContext)
351
{
40 ixe013 352
   pfWlxDisplaySASNotice(GetHookedContext(pWlxContext));
23 ixe013 353
}
2 ixe013 354
 
355
 
45 ixe013 356
int WINAPI AucunWlxLoggedOutSAS(PVOID pWlxContext, DWORD dwSasType, PLUID pAuthenticationId, PSID pLogonSid, PDWORD pdwOptions, PHANDLE phToken, PWLX_MPR_NOTIFY_INFO pMprNotifyInfo, PVOID * pProfile)
23 ixe013 357
{
40 ixe013 358
    int result;
359
   result =  pfWlxLoggedOutSAS(GetHookedContext(pWlxContext), dwSasType, pAuthenticationId, pLogonSid, pdwOptions, phToken, pMprNotifyInfo, pProfile);
360
 
361
    if(result == WLX_SAS_ACTION_LOGON)
362
    {
363
        DuplicateToken(*phToken, SecurityIdentification, &(((MyGinaContext*)pWlxContext)->mCurrentUser));
364
    }
365
 
366
    return result;
2 ixe013 367
}
368
 
369
 
370
BOOL WINAPI WlxActivateUserShell(PVOID pWlxContext, PWSTR pszDesktopName, PWSTR pszMprLogonScript, PVOID pEnvironment)
371
{
40 ixe013 372
   return pfWlxActivateUserShell(GetHookedContext(pWlxContext), pszDesktopName, pszMprLogonScript, pEnvironment);
2 ixe013 373
}
374
 
375
 
376
int WINAPI WlxLoggedOnSAS(PVOID pWlxContext, DWORD dwSasType, PVOID pReserved)
377
{
40 ixe013 378
    return pfWlxLoggedOnSAS(GetHookedContext(pWlxContext), dwSasType, pReserved);
2 ixe013 379
}
380
 
381
 
382
VOID WINAPI WlxDisplayLockedNotice(PVOID pWlxContext)
383
{
40 ixe013 384
   pfWlxDisplayLockedNotice(GetHookedContext(pWlxContext));
2 ixe013 385
}
386
 
387
 
388
BOOL WINAPI WlxIsLockOk(PVOID pWlxContext)
389
{
40 ixe013 390
   return pfWlxIsLockOk(GetHookedContext(pWlxContext));
2 ixe013 391
}
392
 
393
 
394
int WINAPI WlxWkstaLockedSAS(PVOID pWlxContext, DWORD dwSasType)
395
{
40 ixe013 396
    int result;
397
 
398
    result = pfWlxWkstaLockedSAS(GetHookedContext(pWlxContext), dwSasType);
399
 
400
    if(result == WLX_SAS_ACTION_LOGOFF)
401
        result = WLX_SAS_ACTION_FORCE_LOGOFF;
402
 
403
    return result;
2 ixe013 404
}
405
 
406
 
407
BOOL WINAPI WlxIsLogoffOk(PVOID pWlxContext)
408
{
40 ixe013 409
   return pfWlxIsLogoffOk(GetHookedContext(pWlxContext));
2 ixe013 410
}
411
 
412
 
413
VOID WINAPI WlxLogoff(PVOID pWlxContext)
414
{
40 ixe013 415
        CloseHandle(((MyGinaContext*)pWlxContext)->mCurrentUser);
416
        ((MyGinaContext*)pWlxContext)->mCurrentUser = 0;
417
 
418
   pfWlxLogoff(GetHookedContext(pWlxContext));
2 ixe013 419
}
420
 
421
 
422
VOID WINAPI WlxShutdown(PVOID pWlxContext, DWORD ShutdownType)
423
{
40 ixe013 424
   pfWlxShutdown(GetHookedContext(pWlxContext), ShutdownType);
425
   FreeLibrary(hDll);
2 ixe013 426
}
427
 
428
 
429
//
430
// New for version 1.1
431
//
432
 
45 ixe013 433
/*
2 ixe013 434
BOOL WINAPI WlxScreenSaverNotify(PVOID  pWlxContext, BOOL * pSecure)
435
{
40 ixe013 436
   return pfWlxScreenSaverNotify(GetHookedContext(pWlxContext), pSecure);
2 ixe013 437
}
45 ixe013 438
//*/
2 ixe013 439
 
45 ixe013 440
/*
2 ixe013 441
BOOL WINAPI WlxStartApplication(PVOID pWlxContext, PWSTR pszDesktopName, PVOID pEnvironment, PWSTR pszCmdLine)
442
{
40 ixe013 443
   return pfWlxStartApplication(GetHookedContext(pWlxContext), pszDesktopName, pEnvironment, pszCmdLine);
2 ixe013 444
}
45 ixe013 445
//*/
2 ixe013 446
 
447
//
448
// New for version 1.3
449
//
45 ixe013 450
/*
2 ixe013 451
BOOL WINAPI WlxNetworkProviderLoad(PVOID pWlxContext, PWLX_MPR_NOTIFY_INFO pNprNotifyInfo)
452
{
40 ixe013 453
   return pfWlxNetworkProviderLoad(GetHookedContext(pWlxContext), pNprNotifyInfo);
2 ixe013 454
}
45 ixe013 455
//*/
2 ixe013 456
 
45 ixe013 457
/*
2 ixe013 458
BOOL WINAPI WlxDisplayStatusMessage(PVOID pWlxContext, HDESK hDesktop, DWORD dwOptions, PWSTR pTitle, PWSTR pMessage)
459
{
40 ixe013 460
   return pfWlxDisplayStatusMessage(GetHookedContext(pWlxContext), hDesktop, dwOptions, pTitle, pMessage);
2 ixe013 461
}
45 ixe013 462
//*/
2 ixe013 463
 
45 ixe013 464
/*
2 ixe013 465
BOOL WINAPI WlxGetStatusMessage(PVOID pWlxContext, DWORD * pdwOptions, PWSTR pMessage, DWORD dwBufferSize)
466
{
40 ixe013 467
   return pfWlxGetStatusMessage(GetHookedContext(pWlxContext), pdwOptions, pMessage, dwBufferSize);
2 ixe013 468
}
45 ixe013 469
//*/
2 ixe013 470
 
45 ixe013 471
/*
2 ixe013 472
BOOL WINAPI WlxRemoveStatusMessage(PVOID pWlxContext)
473
{
40 ixe013 474
   return pfWlxRemoveStatusMessage(GetHookedContext(pWlxContext));
2 ixe013 475
}
45 ixe013 476
//*/
2 ixe013 477
 
478
 
479
//
480
// New for 1.4
481
//
45 ixe013 482
/*
23 ixe013 483
BOOL WINAPI WlxGetConsoleSwitchCredentials(PVOID pWlxContext, PVOID pCredInfo)
2 ixe013 484
{
40 ixe013 485
   return pfWlxGetConsoleSwitchCredentials(GetHookedContext(pWlxContext), pCredInfo);
2 ixe013 486
}
45 ixe013 487
//*/
2 ixe013 488
 
45 ixe013 489
/*
23 ixe013 490
VOID WINAPI WlxReconnectNotify(PVOID pWlxContext)
2 ixe013 491
{
40 ixe013 492
   pfWlxReconnectNotify(GetHookedContext(pWlxContext));
2 ixe013 493
}
45 ixe013 494
//*/
2 ixe013 495
 
45 ixe013 496
/*
23 ixe013 497
VOID WINAPI WlxDisconnectNotify(PVOID pWlxContext)
2 ixe013 498
{
40 ixe013 499
   pfWlxDisconnectNotify(GetHookedContext(pWlxContext));
2 ixe013 500
}
45 ixe013 501
//*/