00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
#include <nt.h>
00024
#include <ntlsa.h>
00025
#include "sep.h"
00026
#include <zwapi.h>
00027
#include "rmp.h"
00028
#include "adt.h"
00029
#include "adtp.h"
00030
00031
#ifdef ALLOC_PRAGMA
00032
#pragma alloc_text(INIT,SepRmInitPhase0)
00033
#pragma alloc_text(INIT,SeRmInitPhase1)
00034
#pragma alloc_text(PAGE,SepRmCommandServerThread)
00035
#pragma alloc_text(PAGE,SepRmCommandServerThreadInit)
00036
#pragma alloc_text(PAGE,SepRmComponentTestCommandWrkr)
00037
#pragma alloc_text(PAGE,SepRmSendCommandToLsaWrkr)
00038
#pragma alloc_text(PAGE,SepRmCallLsa)
00039
#endif
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 SEP_RM_COMMAND_WORKER SepRmCommandDispatch[] = {
00050
SepRmComponentTestCommandWrkr,
00051
SepRmSetAuditEventWrkr,
00052
SepRmSendCommandToLsaWrkr,
00053
SepRmComponentTestCommandWrkr,
00054
SepRmCreateLogonSessionWrkr,
00055
SepRmDeleteLogonSessionWrkr
00056 };
00057
00058
00059 BOOLEAN
00060 SeRmInitPhase1(
00061 )
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 {
00104
NTSTATUS Status;
00105 STRING RmCommandPortName;
00106 UNICODE_STRING UnicodeRmCommandPortName;
00107 OBJECT_ATTRIBUTES
ObjectAttributes;
00108 STRING LsaInitEventName;
00109 UNICODE_STRING UnicodeLsaInitEventName;
00110 OBJECT_ATTRIBUTES LsaInitEventObjectAttributes;
00111 SECURITY_DESCRIPTOR LsaInitEventSecurityDescriptor;
00112 ULONG AclSize;
00113
00114
PAGED_CODE();
00115
00116
00117
00118
00119
00120
00121
00122
RtlInitString( &RmCommandPortName,
"\\SeRmCommandPort" );
00123
Status =
RtlAnsiStringToUnicodeString(
00124 &UnicodeRmCommandPortName,
00125 &RmCommandPortName,
00126
TRUE );
ASSERT(
NT_SUCCESS(
Status) );
00127 InitializeObjectAttributes(
00128 &
ObjectAttributes,
00129 &UnicodeRmCommandPortName,
00130 0,
00131
NULL,
00132
NULL
00133 );
00134
00135
Status = ZwCreatePort(
00136 &
SepRmState.
RmCommandPortHandle,
00137 &
ObjectAttributes,
00138
sizeof(
SEP_RM_CONNECT_INFO),
00139
sizeof(RM_COMMAND_MESSAGE),
00140
sizeof(RM_COMMAND_MESSAGE) * 32
00141 );
00142
RtlFreeUnicodeString( &UnicodeRmCommandPortName );
00143
00144
if( !
NT_SUCCESS(
Status) ) {
00145
00146 KdPrint((
"Security: Rm Create Command Port failed 0x%lx\n",
Status));
00147
return FALSE;
00148 }
00149
00150
00151
00152
00153
00154
00155
Status =
RtlCreateSecurityDescriptor(
00156 &LsaInitEventSecurityDescriptor,
00157 SECURITY_DESCRIPTOR_REVISION
00158 );
00159
00160
if (!
NT_SUCCESS(
Status)) {
00161
00162 KdPrint((
"Security: Creating Lsa Init Event Desc failed 0x%lx\n",
00163
Status));
00164
return FALSE;
00165 }
00166
00167
00168
00169
00170
00171
00172
00173 AclSize =
sizeof(ACL) +
00174
sizeof(ACCESS_ALLOWED_ACE) +
00175
SeLengthSid(
SeLocalSystemSid);
00176 LsaInitEventSecurityDescriptor.Dacl =
00177
ExAllocatePoolWithTag(
PagedPool, AclSize, 'cAeS');
00178
00179
if (LsaInitEventSecurityDescriptor.Dacl ==
NULL) {
00180
00181 KdPrint((
"Security LSA: Insufficient resources to initialize\n"));
00182
return FALSE;
00183 }
00184
00185
00186
00187
00188
00189
Status =
RtlCreateAcl(
00190 LsaInitEventSecurityDescriptor.Dacl,
00191 AclSize,
00192 ACL_REVISION2
00193 );
00194
00195
if (!
NT_SUCCESS(
Status)) {
00196
00197 KdPrint((
"Security: Creating Lsa Init Event Dacl failed 0x%lx\n",
00198
Status));
00199
return FALSE;
00200 }
00201
00202
00203
00204
00205
00206
Status =
RtlAddAccessAllowedAce(
00207 LsaInitEventSecurityDescriptor.Dacl,
00208 ACL_REVISION2,
00209 GENERIC_ALL,
00210
SeLocalSystemSid
00211 );
00212
00213
if (!
NT_SUCCESS(
Status)) {
00214
00215 KdPrint((
"Security: Adding Lsa Init Event ACE failed 0x%lx\n",
00216
Status));
00217
return FALSE;
00218 }
00219
00220
00221
00222
00223
00224
RtlInitString( &LsaInitEventName,
"\\SeLsaInitEvent" );
00225
Status =
RtlAnsiStringToUnicodeString(
00226 &UnicodeLsaInitEventName,
00227 &LsaInitEventName,
00228
TRUE );
ASSERT(
NT_SUCCESS(
Status) );
00229 InitializeObjectAttributes(
00230 &LsaInitEventObjectAttributes,
00231 &UnicodeLsaInitEventName,
00232 0,
00233
NULL,
00234 &LsaInitEventSecurityDescriptor
00235 );
00236
00237
00238
00239
00240
00241
00242
00243
Status = ZwCreateEvent(
00244 &(
SepRmState.
LsaInitEventHandle),
00245 EVENT_MODIFY_STATE,
00246 &LsaInitEventObjectAttributes,
00247 NotificationEvent,
00248
FALSE);
00249
00250
RtlFreeUnicodeString( &UnicodeLsaInitEventName );
00251
00252
if (!
NT_SUCCESS(
Status)) {
00253
00254 KdPrint((
"Security: LSA init event creation failed.0x%xl\n",
00255
Status));
00256
return FALSE;
00257 }
00258
00259
00260
00261
00262
00263
ExFreePool( LsaInitEventSecurityDescriptor.Dacl );
00264
00265
00266
00267
00268
00269
00270
00271
Status =
PsCreateSystemThread(
00272 &
SepRmState.
SepRmThreadHandle,
00273 THREAD_GET_CONTEXT |
00274 THREAD_SET_CONTEXT |
00275 THREAD_SET_INFORMATION,
00276
NULL,
00277
NULL,
00278
NULL,
00279
SepRmCommandServerThread,
00280
NULL
00281 );
00282
00283
if (!
NT_SUCCESS(
Status)) {
00284
00285 KdPrint((
"Security: Rm Server Thread creation failed 0x%lx\n",
Status));
00286
return FALSE;
00287 }
00288
00289
00290
00291
00292
00293
00294
SepAdtInitializeCrashOnFail();
00295
SepAdtInitializePrivilegeAuditing();
00296
SepAdtInitializeAuditingOptions();
00297
00298
00299
00300
00301
00302 ZwClose(
SepRmState.
SepRmThreadHandle );
00303
SepRmState.
SepRmThreadHandle =
NULL;
00304
return TRUE;
00305 }
00306
00307
00308
VOID
00309 SepRmCommandServerThread(
00310 IN PVOID StartContext
00311 )
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340 {
00341
NTSTATUS Status;
00342 PRM_REPLY_MESSAGE Reply;
00343 RM_COMMAND_MESSAGE CommandMessage;
00344 RM_REPLY_MESSAGE
ReplyMessage;
00345
00346
PAGED_CODE();
00347
00348
00349
00350
00351
00352
00353
if (!
SepRmCommandServerThreadInit()) {
00354
00355 KdPrint((
"Security: Terminating Rm Command Server Thread\n"));
00356
return;
00357 }
00358
00359
00360
00361
00362
00363
00364 CommandMessage.MessageHeader.u2.ZeroInit = 0;
00365 CommandMessage.MessageHeader.u1.s1.TotalLength =
00366 (CSHORT)
sizeof(RM_COMMAND_MESSAGE);
00367 CommandMessage.MessageHeader.u1.s1.DataLength =
00368 CommandMessage.MessageHeader.u1.s1.TotalLength -
00369 (CSHORT)
sizeof(PORT_MESSAGE);
00370
00371
00372
00373
00374
00375
00376
ReplyMessage.MessageHeader.u2.ZeroInit = 0;
00377
ReplyMessage.MessageHeader.u1.s1.TotalLength =
00378 (CSHORT)
sizeof(RM_COMMAND_MESSAGE);
00379
ReplyMessage.MessageHeader.u1.s1.DataLength =
00380
ReplyMessage.MessageHeader.u1.s1.TotalLength -
00381 (CSHORT)
sizeof(PORT_MESSAGE);
00382
00383
00384
00385
00386
00387 Reply =
NULL;
00388
00389
00390
00391
00392
00393
for(;;) {
00394
00395
00396
00397
00398
00399
Status = ZwReplyWaitReceivePort(
00400
SepRmState.
RmCommandPortHandle,
00401
NULL,
00402 (PPORT_MESSAGE) Reply,
00403 (PPORT_MESSAGE) &CommandMessage
00404 );
00405
00406
if (!
NT_SUCCESS(
Status)) {
00407
00408
00409
00410
00411
00412
00413
00414
if (
Status == STATUS_UNSUCCESSFUL )
00415 {
00416
00417
00418
00419
00420 Reply =
NULL ;
00421
continue;
00422 }
00423
00424 KdPrint((
"Security: RM message receive from Lsa failed %lx\n",
00425
Status));
00426
00427 }
00428
00429
00430
00431
00432
00433
00434
if ( CommandMessage.MessageHeader.u2.s2.Type == LPC_REQUEST ) {
00435 (*(
SepRmCommandDispatch[CommandMessage.CommandNumber]))
00436 (&CommandMessage, &
ReplyMessage);
00437
00438
00439
00440
00441
00442
00443
00444
ReplyMessage.MessageHeader.ClientId =
00445 CommandMessage.MessageHeader.ClientId;
00446
ReplyMessage.MessageHeader.MessageId =
00447 CommandMessage.MessageHeader.MessageId;
00448
00449 Reply = &
ReplyMessage;
00450
00451 }
else {
00452
00453 Reply =
NULL;
00454 }
00455 }
00456
00457
00458
00459
00460
00461 StartContext;
00462 }
00463
00464
00465 BOOLEAN
00466 SepRmCommandServerThreadInit(
00467 VOID
00468 )
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492 {
00493
NTSTATUS Status;
00494 UNICODE_STRING LsaCommandPortName;
00495 PORT_MESSAGE ConnectionRequest;
00496 SECURITY_QUALITY_OF_SERVICE
DynamicQos;
00497 OBJECT_ATTRIBUTES
ObjectAttributes;
00498 PORT_VIEW ClientView;
00499 REMOTE_PORT_VIEW LsaClientView;
00500 BOOLEAN BooleanStatus =
TRUE;
00501
00502
PAGED_CODE();
00503
00504
00505
00506
00507
00508
00509
00510
SepRmLsaCallProcess =
PsGetCurrentProcess();
00511
00512
ObReferenceObject(
SepRmLsaCallProcess);
00513
00514
00515
00516
00517
00518
00519
00520
Status = ZwWaitForSingleObject(
00521
SepRmState.
LsaInitEventHandle,
00522
FALSE,
00523
NULL);
00524
00525
if ( !
NT_SUCCESS(
Status) ) {
00526
00527 KdPrint((
"Security Rm Init: Waiting for LSA Init Event failed 0x%lx\n",
Status));
00528
goto RmCommandServerThreadInitError;
00529 }
00530
00531
00532
00533
00534
00535 ZwClose(
SepRmState.
LsaInitEventHandle);
00536
00537
00538
00539
00540
00541
00542 ConnectionRequest.u1.s1.TotalLength =
sizeof(ConnectionRequest);
00543 ConnectionRequest.u1.s1.DataLength = (CSHORT)0;
00544
Status = ZwListenPort(
00545
SepRmState.
RmCommandPortHandle,
00546 &ConnectionRequest
00547 );
00548
00549
if (!
NT_SUCCESS(
Status)) {
00550
00551 KdPrint((
"Security Rm Init: Listen to Command Port failed 0x%lx\n",
00552
Status));
00553
goto RmCommandServerThreadInitError;
00554 }
00555
00556
00557
00558
00559
00560 InitializeObjectAttributes( &
ObjectAttributes,
NULL, 0,
NULL,
NULL );
00561
00562
Status = ZwOpenProcess(
00563 &
SepLsaHandle,
00564 PROCESS_VM_OPERATION | PROCESS_VM_WRITE,
00565 &
ObjectAttributes,
00566 &ConnectionRequest.ClientId
00567 );
00568
00569
if (!
NT_SUCCESS(
Status)) {
00570
00571 KdPrint((
"Security Rm Init: Open Listen to Command Port failed 0x%lx\n",
00572
Status));
00573
goto RmCommandServerThreadInitError;
00574 }
00575
00576
00577
00578
00579
00580 LsaClientView.Length =
sizeof(LsaClientView);
00581
00582
Status = ZwAcceptConnectPort(
00583 &
SepRmState.
RmCommandPortHandle,
00584
NULL,
00585 &ConnectionRequest,
00586
TRUE,
00587
NULL,
00588 &LsaClientView
00589 );
00590
00591
if (!
NT_SUCCESS(
Status)) {
00592
00593 KdPrint((
"Security Rm Init: Accept Connect to Command Port failed 0x%lx\n",
00594
Status));
00595
00596
goto RmCommandServerThreadInitError;
00597 }
00598
00599
00600
00601
00602
00603
Status = ZwCompleteConnectPort(
SepRmState.
RmCommandPortHandle);
00604
00605
if (!
NT_SUCCESS(
Status)) {
00606
00607 KdPrint((
"Security Rm Init: Complete Connect to Command Port failed 0x%lx\n",
00608
Status));
00609
goto RmCommandServerThreadInitError;
00610 }
00611
00612
00613
00614
00615
00616
00617
00618
DynamicQos.ImpersonationLevel = SecurityImpersonation;
00619
DynamicQos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
00620
DynamicQos.EffectiveOnly =
TRUE;
00621
00622
00623
00624
00625
00626
00627
SepRmState.
LsaCommandPortSectionSize.LowPart =
PAGE_SIZE;
00628
SepRmState.
LsaCommandPortSectionSize.HighPart = 0;
00629
00630
Status = ZwCreateSection(
00631 &
SepRmState.
LsaCommandPortSectionHandle,
00632 SECTION_ALL_ACCESS,
00633
NULL,
00634 &
SepRmState.
LsaCommandPortSectionSize,
00635 PAGE_READWRITE,
00636 SEC_COMMIT,
00637
NULL
00638 );
00639
00640
if (!
NT_SUCCESS(
Status)) {
00641
00642 KdPrint((
"Security Rm Init: Create Memory Section for LSA port failed: %X\n",
Status));
00643
goto RmCommandServerThreadInitError;
00644 }
00645
00646
00647
00648
00649
00650
00651
00652
00653 ClientView.Length =
sizeof(ClientView);
00654 ClientView.SectionHandle =
SepRmState.
LsaCommandPortSectionHandle;
00655 ClientView.SectionOffset = 0;
00656 ClientView.ViewSize =
SepRmState.
LsaCommandPortSectionSize.LowPart;
00657 ClientView.ViewBase = 0;
00658 ClientView.ViewRemoteBase = 0;
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
DynamicQos.ImpersonationLevel = SecurityImpersonation;
00669
DynamicQos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
00670
DynamicQos.EffectiveOnly =
TRUE;
00671
00672
00673
00674
00675
00676
00677
RtlInitUnicodeString( &LsaCommandPortName,
L"\\SeLsaCommandPort" );
00678
00679
Status = ZwConnectPort(
00680 &
SepRmState.
LsaCommandPortHandle,
00681 &LsaCommandPortName,
00682 &
DynamicQos,
00683 &ClientView,
00684
NULL,
00685
NULL,
00686
NULL,
00687
NULL
00688 );
00689
00690
if (!
NT_SUCCESS(
Status)) {
00691
00692 KdPrint((
"Security Rm Init: Connect to LSA Port failed 0x%lx\n",
Status));
00693
goto RmCommandServerThreadInitError;
00694 }
00695
00696
00697
00698
00699
00700
00701
SepRmState.
RmViewPortMemory = ClientView.ViewBase;
00702
SepRmState.
LsaCommandPortMemoryDelta =
00703 (LONG)((ULONG_PTR)ClientView.ViewRemoteBase - (ULONG_PTR) ClientView.ViewBase );
00704
SepRmState.
LsaViewPortMemory = ClientView.ViewRemoteBase;
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724 RmCommandServerThreadInitFinish:
00725
00726
00727
00728
00729
00730
00731
if (
SepRmState.
LsaCommandPortSectionHandle !=
NULL ) {
00732
00733
NtClose(
SepRmState.
LsaCommandPortSectionHandle );
00734
SepRmState.
LsaCommandPortSectionHandle =
NULL;
00735 }
00736
00737
00738
00739
00740
00741
return BooleanStatus;
00742
00743 RmCommandServerThreadInitError:
00744
00745
if (
SepRmState.
LsaCommandPortHandle !=
NULL ) {
00746
00747
NtClose(
SepRmState.
LsaCommandPortHandle );
00748
SepRmState.
LsaCommandPortHandle =
NULL;
00749 }
00750
00751 BooleanStatus =
FALSE;
00752
goto RmCommandServerThreadInitFinish;
00753 }
00754
00755
00756
00757
VOID
00758 SepRmComponentTestCommandWrkr(
00759 IN PRM_COMMAND_MESSAGE CommandMessage,
00760 OUT PRM_REPLY_MESSAGE ReplyMessage
00761 )
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795 {
00796
PAGED_CODE();
00797
00798
ReplyMessage->ReturnedStatus = STATUS_SUCCESS;
00799
00800
00801
00802
00803
00804
ASSERT( CommandMessage->CommandNumber == RmComponentTestCommand );
00805
00806 KdPrint((
"Security: RM Component Test Command Received\n"));
00807
00808
00809
00810
00811
00812
if (*((ULONG *) CommandMessage->CommandParams) !=
00813 RM_CT_COMMAND_PARAM_VALUE ) {
00814
00815
ReplyMessage->ReturnedStatus = STATUS_INVALID_PARAMETER;
00816 }
00817
00818
return;
00819 }
00820
00821
00822
00823
VOID
00824 SepRmSendCommandToLsaWrkr(
00825 IN PRM_COMMAND_MESSAGE CommandMessage,
00826 OUT PRM_REPLY_MESSAGE ReplyMessage
00827 )
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856 {
00857
00858
00859
00860
00861
00862 PVOID LsaCommandParams =
00863 ((RM_SEND_COMMAND_TO_LSA_PARAMS *)
00864 (CommandMessage->CommandParams))->LsaCommandParams;
00865 ULONG LsaCommandParamsLength =
00866 ((RM_SEND_COMMAND_TO_LSA_PARAMS *)
00867 (CommandMessage->CommandParams))->LsaCommandParamsLength;
00868
00869
PAGED_CODE();
00870
00871
if (LsaCommandParamsLength == 0) {
00872
00873 LsaCommandParams =
NULL;
00874
00875 }
00876
00877
00878
00879
00880
00881
ASSERT( CommandMessage->CommandNumber == RmSendCommandToLsaCommand );
00882
00883 KdPrint((
"Security: RM Send Command back to LSA Command Received\n"));
00884
00885
ReplyMessage->ReturnedStatus = STATUS_SUCCESS;
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
return;
00900
00901 }
00902
00903
00904
00905
00906
NTSTATUS
00907 SepRmCallLsa(
00908
PSEP_WORK_ITEM SepWorkItem
00909 )
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972 {
00973
NTSTATUS Status = STATUS_SUCCESS;
00974 LSA_COMMAND_MESSAGE CommandMessage;
00975 LSA_REPLY_MESSAGE
ReplyMessage;
00976
PSEP_LSA_WORK_ITEM WorkQueueItem;
00977 ULONG LocalListLength = 0;
00978 SIZE_T RegionSize;
00979 PVOID CopiedCommandParams =
NULL;
00980 PVOID LsaViewCopiedCommandParams =
NULL;
00981
00982
PAGED_CODE();
00983
00984
#if 0
00985
DbgPrint(
"Entering SepRmCallLsa\n");
00986
#endif
00987
00988 WorkQueueItem =
SepWorkListHead();
00989
00990
KeAttachProcess( &
SepRmLsaCallProcess->
Pcb );
00991
00992
while ( WorkQueueItem ) {
00993
00994
#if 0
00995
DbgPrint(
"Got a work item from head of queue, processing\n");
00996
#endif
00997
00998
00999
01000
01001
01002
01003
01004 CommandMessage.MessageHeader.u2.ZeroInit = 0;
01005 CommandMessage.MessageHeader.u1.s1.TotalLength =
01006 ((CSHORT) RM_COMMAND_MESSAGE_HEADER_SIZE +
01007 (CSHORT) WorkQueueItem->
CommandParamsLength);
01008 CommandMessage.MessageHeader.u1.s1.DataLength =
01009 CommandMessage.MessageHeader.u1.s1.TotalLength -
01010 (CSHORT)
sizeof(PORT_MESSAGE);
01011
01012
ReplyMessage.MessageHeader.u2.ZeroInit = 0;
01013
ReplyMessage.MessageHeader.u1.s1.DataLength = (CSHORT) WorkQueueItem->
ReplyBufferLength;
01014
ReplyMessage.MessageHeader.u1.s1.TotalLength =
01015
ReplyMessage.MessageHeader.u1.s1.DataLength +
01016 (CSHORT)
sizeof(PORT_MESSAGE);
01017
01018
01019
01020
01021
01022 CommandMessage.CommandNumber = WorkQueueItem->
CommandNumber;
01023
ReplyMessage.ReturnedStatus = STATUS_SUCCESS;
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
switch (WorkQueueItem->
CommandParamsMemoryType) {
01034
01035
case SepRmImmediateMemory:
01036
01037
01038
01039
01040
01041
01042
01043 CommandMessage.CommandParamsMemoryType = SepRmImmediateMemory;
01044
01045 RtlCopyMemory(
01046 CommandMessage.CommandParams,
01047 &WorkQueueItem->
CommandParams,
01048 WorkQueueItem->
CommandParamsLength
01049 );
01050
01051
break;
01052
01053
case SepRmPagedPoolMemory:
01054
case SepRmUnspecifiedMemory:
01055
01056
01057
01058
01059
01060
01061
01062
01063
if (WorkQueueItem->
CommandParamsLength <= LSA_MAXIMUM_COMMAND_PARAM_SIZE) {
01064
01065
01066
01067
01068
01069 CopiedCommandParams = CommandMessage.CommandParams;
01070
01071 RtlCopyMemory(
01072 CopiedCommandParams,
01073 WorkQueueItem->
CommandParams.BaseAddress,
01074 WorkQueueItem->
CommandParamsLength
01075 );
01076
01077 CommandMessage.CommandParamsMemoryType = SepRmImmediateMemory;
01078
01079 }
else {
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
if (WorkQueueItem->
CommandParamsLength <=
SEP_RM_LSA_SHARED_MEMORY_SIZE) {
01090
01091 RtlCopyMemory(
01092
SepRmState.
RmViewPortMemory,
01093 WorkQueueItem->
CommandParams.BaseAddress,
01094 WorkQueueItem->
CommandParamsLength
01095 );
01096
01097 LsaViewCopiedCommandParams =
SepRmState.
LsaViewPortMemory;
01098 CommandMessage.CommandParamsMemoryType = SepRmLsaCommandPortSharedMemory;
01099
01100 }
else {
01101
01102
Status =
SepAdtCopyToLsaSharedMemory(
01103
SepLsaHandle,
01104 WorkQueueItem->
CommandParams.BaseAddress,
01105 WorkQueueItem->
CommandParamsLength,
01106 &LsaViewCopiedCommandParams
01107 );
01108
01109
if (!
NT_SUCCESS(
Status)) {
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
break;
01120
01121 }
01122
01123 CommandMessage.CommandParamsMemoryType = SepRmLsaCustomSharedMemory;
01124 }
01125
01126
01127
01128
01129
01130
01131
01132 *((PVOID *) CommandMessage.CommandParams) =
01133 LsaViewCopiedCommandParams;
01134
01135 CommandMessage.MessageHeader.u1.s1.TotalLength =
01136 ((CSHORT) RM_COMMAND_MESSAGE_HEADER_SIZE +
01137 (CSHORT)
sizeof( LsaViewCopiedCommandParams ));
01138 CommandMessage.MessageHeader.u1.s1.DataLength =
01139 CommandMessage.MessageHeader.u1.s1.TotalLength -
01140 (CSHORT)
sizeof(PORT_MESSAGE);
01141 }
01142
01143
01144
01145
01146
01147
if (WorkQueueItem->
CommandParamsMemoryType == SepRmPagedPoolMemory) {
01148
01149
ExFreePool( WorkQueueItem->
CommandParams.BaseAddress );
01150 }
01151
01152
break;
01153
01154
default:
01155
01156
Status = STATUS_INVALID_PARAMETER;
01157
break;
01158 }
01159
01160
if (
NT_SUCCESS(
Status)) {
01161
01162
01163
01164
01165
01166
01167
Status = ZwRequestWaitReplyPort(
01168
SepRmState.
LsaCommandPortHandle,
01169 (PPORT_MESSAGE) &CommandMessage,
01170 (PPORT_MESSAGE) &
ReplyMessage
01171 );
01172
01173
01174
01175
01176
01177
01178
if (
NT_SUCCESS(
Status)) {
01179
01180
01181
01182
01183
01184
01185
01186
if (ARGUMENT_PRESENT(WorkQueueItem->
ReplyBuffer)) {
01187
01188 RtlCopyMemory(
01189 WorkQueueItem->
ReplyBuffer,
01190
ReplyMessage.ReplyBuffer,
01191 WorkQueueItem->
ReplyBufferLength
01192 );
01193 }
01194
01195
01196
01197
01198
01199
Status =
ReplyMessage.ReturnedStatus;
01200
01201
if (!
NT_SUCCESS(
Status)) {
01202 KdPrint((
"Security: Command sent from RM to LSA returned 0x%lx\n",
01203
Status));
01204 }
01205
01206 }
else {
01207
01208 KdPrint((
"Security: Sending Command RM to LSA failed 0x%lx\n",
Status));
01209 }
01210
01211
01212
01213
01214
01215
01216
01217
01218
if (CommandMessage.CommandParamsMemoryType == SepRmLsaCustomSharedMemory) {
01219
01220 RegionSize = 0;
01221
01222
Status = ZwFreeVirtualMemory(
01223
SepLsaHandle,
01224 (PVOID *) &CommandMessage.CommandParams,
01225 &RegionSize,
01226 MEM_RELEASE
01227 );
01228
01229
ASSERT(
NT_SUCCESS(
Status));
01230 }
01231
01232 }
01233
01234
01235
01236
01237
01238
01239
01240
if ( ARGUMENT_PRESENT( WorkQueueItem->
CleanupFunction)) {
01241
01242 (WorkQueueItem->
CleanupFunction)(WorkQueueItem->
CleanupParameter);
01243 }
01244
01245
01246
01247
01248
01249 WorkQueueItem =
SepDequeueWorkItem();
01250
#if 0
01251
if ( WorkQueueItem ) {
01252
DbgPrint(
"Got another item from list, going back\n");
01253 }
else {
01254
DbgPrint(
"List is empty, leaving\n");
01255 }
01256
#endif
01257
01258
01259 }
01260
01261
KeDetachProcess();
01262
01263
if ( LocalListLength >
SepLsaQueueLength ) {
01264
SepLsaQueueLength = LocalListLength;
01265 }
01266
01267
return Status;
01268 }
01269
01270
01271
01272
01273
01274 BOOLEAN
01275 SepRmInitPhase0(
01276 )
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298
01299 {
01300
01301 BOOLEAN CompletionStatus;
01302
01303
PAGED_CODE();
01304
01305 CompletionStatus =
SepRmDbInitialization();
01306
01307
return CompletionStatus;
01308 }