summaryrefslogtreecommitdiffstats
path: root/private/eventlog/server/eventlog.c
blob: e2a4b105828089be63094f7b511f028d0b8500d9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
/*++

Copyright (c) 1990  Microsoft Corporation

Module Name:

    EVENTLOG.C

Abstract:

    This file contains the main routines for the NT OS/2 Event
    Logging Service.

Author:

    Rajen Shah  (rajens)    1-Jul-1991

[Environment:]

    User Mode - Win32, except for NTSTATUS returned by some functions.

Revision History:

    26-Jan-1994     Danl
        SetUpModules:  Fixed memory leak where the buffers for the enumerated
        key names were never free'd.  Also fixed problem where the size of
        the MULTI_SZ buffer used for the "Sources" key was calculated by
        using the names in the registry, while the copying was done
        using the names in the module list.  When registry keys are deleted,
        the module list entry is retained until the next boot.  Since the
        module list is larger, it would overwrite the MULTI_SZ buffer.
    1-Nov-1993      Danl
        Make Eventlog service a DLL and attach it to services.exe.
        Pass in GlobalData to Elfmain.  This GlobalData structure contains
        all well-known SIDs and pointers to the Rpc Server (Start & Stop)
        routines.  Get rid of the service process main function.
    1-Jul-1991      RajenS
        created

--*/

//
// INCLUDES
//

#include <eventp.h>
#include <ntrpcp.h>
#include <elfcfg.h>
#include <string.h>
#include <stdlib.h>   // getenv()
#include <tstr.h>     // WCSSIZE
#include <alertmsg.h> // ALERT_ELF manifests
#include <stdio.h>    // printf

#ifdef _CAIRO_
#include <elfextrn.h>
#endif // _CAIRO_

//
// Bit Flags used for Progress Reporting in SetupDataStruct().
//
#define LOGFILE_OPENED  0x00000001
#define MODULE_LINKED   0x00000002
#define LOGFILE_LINKED  0x00000004

//
// Local Function Prorotypes
//
VOID
ElfInitMessageBoxTitle(
    VOID
    );


NTSTATUS
ElfStartRPCServer ()

/*++

Routine Description:


Arguments:



Return Value:

    NONE

Note:


--*/
{
    NTSTATUS    Status;


    ElfDbgPrint(("[ELF] Starting RPC server.\n"));

    Status = RpcpAddInterface (
                    wname_Eventlogsvc,
                    eventlog_ServerIfHandle
                    );

    if (Status != NERR_Success) {
        ElfDbgPrintNC(("[ELF] RpcpAddInterface = %u\n", Status ));

    }
    return (I_RpcMapWin32Status(Status));            // Return status to caller

}


NTSTATUS
SetUpDataStruct (
        PUNICODE_STRING     LogFileName,
        ULONG               MaxFileSize,
        ULONG               Retention,
        ULONG               GuestAccessRestriction,
        PUNICODE_STRING     ModuleName,
        HANDLE              hLogFile,
        ELF_LOG_TYPE        LogType
    )

/*++

Routine Description:

    This routine sets up the information for one module. It is called from
    ElfSetUpConfigDataStructs for each module to be configured.

    Module information is passed into this routine and a LOGMODULE structure
    is created for it.  If the logfile associated with this module doesn't
    exist, a LOGFILE structure is created for it, and added to the linked
    list of LOGFILE structures.  The LOGMODULE is associated with the LOGFILE,
    and it is added to the linked list of LOGMODULE structures.  The logfile
    is opened and mapped to memory.

    Finally, at the end, this function calls SetUpModules, which looks at
    all the subkeys in the registry under this logfile, and adds any new ones
    to the linked list, and updates the Sources MULTI_SZ for the event viewer.

Arguments:

    LogFileName - Name of log file for this module.  If this routine needs
        a copy of this name it will make one, so that the caller can free
        the name afterwards if that is desired.

    MaxFileSize - Max size of the log file.
    Retention   - Max retention for the file.
    ModuleName  - Name of module that this file is associated with.
    RegistryHandle - Handle to the root node for this LogFile's info
                     in the registry.  This is used to enumerate all the
                     modules under this key.

Return Value:

    Pointer to Module structure that is allocated in this routine.
    NTSTATUS

Note:


--*/
{
    NTSTATUS        Status = STATUS_SUCCESS;
    PLOGFILE        pLogFile=NULL;
    PLOGMODULE      pModule=NULL;
    ANSI_STRING     ModuleNameA;
    DWORD           Type;
    BOOL            bLogFileAllocatedHere=FALSE;
    PUNICODE_STRING SavedBackupFileName=NULL;
    DWORD           StringLength;
    PLOGMODULE      OldDefaultLogModule=NULL;
    DWORD           Progress = 0L;

    //
    // Argument check.
    //

    if ((LogFileName == NULL)         ||
        (LogFileName->Buffer == NULL) ||
        (ModuleName == NULL))
    {
        return(STATUS_INVALID_PARAMETER);
    }

    // If the default log file for a module is also being used by another
    // module, then we just link that same file structure with the other
    // module.
    //
    // Truncate the maximum size of the log file to a 4K boundary.
    // This is to allow for page granularity.
    //

    pLogFile = FindLogFileFromName (LogFileName);

    pModule  = ElfpAllocateBuffer (sizeof (LOGMODULE) );
    if (pModule == NULL) {
        return(STATUS_NO_MEMORY);
    }

    if (pLogFile == NULL) {

        //--------------------------------------
        // CREATE A NEW LOGFILE !!
        //--------------------------------------
        // A logfile by this name doesn't exist yet.  So we will create
        // one so that we can add the module to it.
        //

        bLogFileAllocatedHere = TRUE;

        pLogFile = ElfpAllocateBuffer (sizeof (LOGFILE) );

        if (pLogFile == NULL) {
            ElfpFreeBuffer (pModule);
            return(STATUS_NO_MEMORY);
        }

        ElfDbgPrint(("[ELF] Set up file data\n"));

        //
        // Allocate a new LogFileName that can be attached to the
        // new pLogFile structure.
        //
        StringLength = LogFileName->Length + sizeof(WCHAR);
        SavedBackupFileName = (PUNICODE_STRING) ElfpAllocateBuffer(
            sizeof(UNICODE_STRING) + StringLength);

        if (SavedBackupFileName == NULL) {
            Status = STATUS_NO_MEMORY;
            goto ErrorExit;
        }

        SavedBackupFileName->Buffer = (LPWSTR)((LPBYTE) SavedBackupFileName +
            sizeof(UNICODE_STRING));

        SavedBackupFileName->Length = LogFileName->Length;
        SavedBackupFileName->MaximumLength = (USHORT) StringLength;
        RtlMoveMemory(SavedBackupFileName->Buffer, LogFileName->Buffer,
            LogFileName->Length);
        SavedBackupFileName->Buffer[SavedBackupFileName->Length / sizeof(WCHAR)] =
            L'\0';

        //
        // This is the first user - RefCount gets incrememted below
        //
        pLogFile->RefCount = 0;
        pLogFile->FileHandle = NULL;
        pLogFile->LogFileName = SavedBackupFileName;
        pLogFile->ConfigMaxFileSize = ELFFILESIZE(MaxFileSize);
        pLogFile->Retention = Retention;


        //
        // Save away the default module name for this file
        //
        pLogFile->LogModuleName = ElfpAllocateBuffer(
            sizeof(UNICODE_STRING) + ModuleName->MaximumLength);

        if (pLogFile->LogModuleName == NULL) {
            Status = STATUS_NO_MEMORY;
            goto ErrorExit;
        }

        pLogFile->LogModuleName->MaximumLength = ModuleName->MaximumLength;
        pLogFile->LogModuleName->Buffer =
            (LPWSTR)(pLogFile->LogModuleName + 1);
        RtlCopyUnicodeString(pLogFile->LogModuleName, ModuleName);

        InitializeListHead (&pLogFile->Notifiees);


        pLogFile->NextClearMaxFileSize = pLogFile->ConfigMaxFileSize;

        RtlInitializeResource ( &pLogFile->Resource );
        LinkLogFile ( pLogFile );   // Link it in

        Progress |= LOGFILE_LINKED;

    } // endif (pLogfile == NULL)

    //--------------------------------------
    // ADD THE MODULE TO THE LOG MODULE LIST
    //--------------------------------------
    // Set up the module data structure for the default (which is
    // the same as the logfile keyname).
    //

    pLogFile->RefCount++;
    pModule->LogFile = pLogFile;
    pModule->ModuleName = (LPWSTR) ModuleName->Buffer;

    Status = RtlUnicodeStringToAnsiString (
                    &ModuleNameA,
                    ModuleName,
                    TRUE
                    );

    if (!NT_SUCCESS(Status)) {
        pLogFile->RefCount--;
        goto ErrorExit;
    }

    //
    // Link the new module in.
    //

    LinkLogModule(pModule, &ModuleNameA);

    RtlFreeAnsiString (&ModuleNameA);

    Progress |= MODULE_LINKED;

    //
    // Open up the file and map it to memory.  Impersonate the
    // caller so we can use UNC names
    //

    if (LogType == ElfBackupLog) ElfImpersonateClient();

    Status = ElfOpenLogFile (pLogFile, LogType);

    if (LogType == ElfBackupLog) ElfRevertToSelf();

    if (!NT_SUCCESS(Status)) {

        ElfDbgPrintNC(("[ELF] Couldn't open %ws for module %ws\n",
            LogFileName->Buffer, ModuleName->Buffer));

        if (LogType != ElfBackupLog) {
            ElfpCreateQueuedAlert(ALERT_ELF_LogFileNotOpened, 1,
                &(ModuleName->Buffer));
        }
        pLogFile->RefCount--;
        goto ErrorExit;
    }

    Progress |= LOGFILE_OPENED;
    //
    // If this is the application module, remember the pointer
    // to use if a module doesn't have an entry in the registry
    //

    if (!_wcsicmp(ModuleName->Buffer, ELF_DEFAULT_MODULE_NAME)) {
        OldDefaultLogModule = ElfDefaultLogModule;
        ElfDefaultLogModule = pModule;
    }

    //
    // Create the security descriptor for this logfile.  Only
    // the system and security modules are secured against
    // reads and writes by world.
    //

    if (!_wcsicmp(ModuleName->Buffer, ELF_SYSTEM_MODULE_NAME)) {
        Type = ELF_LOGFILE_SYSTEM;
    }
    else if (!_wcsicmp(ModuleName->Buffer, ELF_SECURITY_MODULE_NAME)) {
        Type = ELF_LOGFILE_SECURITY;
    }
    else {
        Type = ELF_LOGFILE_APPLICATION;
    }

    //
    // Create a Security Descriptor for this Logfile
    //   (RtlDeleteSecurityObject() can be used to free
    //    pLogFile->Sd).
    //
    Status = ElfpCreateLogFileObject(pLogFile, Type, GuestAccessRestriction);
    if (!NT_SUCCESS(Status)) {
        ElfDbgPrintNC(("[ELF] Could not create the security "
            "descriptor for logfile %ws\n", ModuleName->Buffer));

        pLogFile->RefCount--;
        goto ErrorExit;
    }

    //
    // Now that we've added the default module name, see if there are any
    // modules configured to log to this file, and if so, create the module
    // structures for them.
    //

    SetUpModules(hLogFile, pLogFile, FALSE);

    return (STATUS_SUCCESS);

ErrorExit:

    if (Progress & LOGFILE_OPENED) {
        ElfpCloseLogFile(pLogFile, ELF_LOG_CLOSE_BACKUP);
    }

    if (Progress & MODULE_LINKED) {
        UnlinkLogModule(pModule);
        DeleteAtom(pModule->ModuleAtom);
    }

    if (bLogFileAllocatedHere) {

        if (Progress & LOGFILE_LINKED) {
            UnlinkLogFile(pLogFile);
            RtlDeleteResource (&pLogFile->Resource);
        }
        if (pLogFile->LogModuleName != NULL) {
            ElfpFreeBuffer(pLogFile->LogModuleName);
        }
        if (SavedBackupFileName != NULL) {
            ElfpFreeBuffer(SavedBackupFileName);
        }
        if (pLogFile != NULL) {
            ElfpFreeBuffer(pLogFile);
        }
    }

    ElfpFreeBuffer(pModule);

    if (OldDefaultLogModule != NULL) {
        ElfDefaultLogModule = OldDefaultLogModule;
    }
    return(Status);
}

NTSTATUS
SetUpModules (
        HANDLE              hLogFile,
        PLOGFILE            pLogFile,
        BOOLEAN             bAllowDupes
    )

/*++

Routine Description:

    This routine sets up the information for all modules for a logfile.

    The subkeys under a logfile in the eventlog portion of the registry
    are enumerated.  For each unique subkey, a LOGMODULE structure is
    created.  Each new structures is added to a linked list
    of modules for that logfile.

    If there was one or more unique subkeys, meaning the list has changed
    since we last looked, then we go through the entire linked list of
    log modules, and create a MULTI_SZ list of all the modules.  This list
    is stored in the Sources value for that logfile for the event viewer
    to use.

    BUGBUG:
    NOTE:  A module is never un-linked from the linked list of log modules
    even if the registry subkey for it is removed.  This should probably
    be done sometime.  It would make the eventlog more robust.

Arguments:

    hLogFile    - Registry key for the Log File node
    pLogFile    - pointer to the log file structure
    bAllowDupes - If true, it's ok to already have a module with the same
                  name (used when processing change notify of registry)

Return Value:

    NTSTATUS - If unsuccessful, it is not a fatal error.

        Even if this status is unsuccessful, me may have been able
        to store some of the new subkeys in the LogModule list.  Also, we
        may have been able to update the Sources MULTI_SZ list.

Note:


--*/
{
    NTSTATUS    Status = STATUS_SUCCESS;
    BYTE        Buffer[ELF_MAX_REG_KEY_INFO_SIZE];
    PKEY_NODE_INFORMATION KeyBuffer = (PKEY_NODE_INFORMATION) Buffer;
    ULONG       ActualSize;
    PWCHAR      SubKeyString;
    UNICODE_STRING NewModule;
    ANSI_STRING ModuleNameA;
    PLOGMODULE  pModule;
    ULONG       Index = 0;
    ATOM        Atom;
    PWCHAR      pList;
    DWORD       ListLength = 0;
    UNICODE_STRING ListName;
    BOOLEAN     ListChanged = FALSE;
    PLIST_ENTRY  pListEntry;
#ifdef _CAIRO_
    SHORT       sCategory;
    SHORT       sSeverity;
#endif // _CAIRO_

    //
    // Create the module structures for all modules under this logfile.  We
    // don't actually need to open the key, since we don't use any information
    // stored there, it's existence is all we care about here.  Any data is
    // used by the Event Viewer (or any viewing app).  If this is used to
    // setup a backup file, hLogFile is NULL since there aren't any other
    // modules to map to this file.
    //

    while (NT_SUCCESS(Status) && hLogFile) {

        Status = NtEnumerateKey(hLogFile, Index++, KeyNodeInformation,
            KeyBuffer, ELF_MAX_REG_KEY_INFO_SIZE, & ActualSize);

        if (NT_SUCCESS(Status)) {

            //
            // It turns out the Name isn't null terminated, so we need
            // to copy it somewhere and null terminate it before we use it
            //

            SubKeyString = ElfpAllocateBuffer(KeyBuffer->NameLength +
                sizeof(WCHAR));
            if (!SubKeyString) {
                return(STATUS_NO_MEMORY);
            }

            memcpy(SubKeyString, KeyBuffer->Name, KeyBuffer->NameLength);
            SubKeyString[KeyBuffer->NameLength / sizeof(WCHAR)] = L'\0' ;

            //
            // Add the atom for this module name
            //

            RtlInitUnicodeString(&NewModule, SubKeyString);

            Status = RtlUnicodeStringToAnsiString (
                            &ModuleNameA,
                            &NewModule,
                            TRUE
                            );

            if (!NT_SUCCESS(Status)) {
                //
                // We can't continue, so we will leave the modules
                // we've linked so far, and move on in an attempt to
                // create the Sources MULTI_SZ list.
                //
                ElfpFreeBuffer(SubKeyString);
                break;
            }

            Atom = FindAtomA (ModuleNameA.Buffer);

            //
            // Make sure we've not already added one by this name
            //

#ifdef _CAIRO_
            if (pModule = FindModuleStrucFromAtom(Atom)) {
#else
            if (FindModuleStrucFromAtom(Atom)) {
#endif // _CAIRO_

                //
                // We've already encountered a module by this name.  If
                // this is init time, it's a configuration error.  Report
                // it and move on.  If we're processing a change notify
                // from the registry, this is ok, so just press on
                //
                //              ** NEW FOR CAIRO **
                //
                // Update the module alert category & severity values. i.e.,
                // only upon registry change notify.
                //

                if (!bAllowDupes) {

                    ElfDbgPrint(("[ELF] Same module exists in two log files - "
                        "%ws\n", SubKeyString));
                }

#ifdef _CAIRO_
                if (GetSourceAlertFilterFromRegistry(hLogFile,
                                                     &NewModule,
                                                     &sCategory,
                                                     &sSeverity))
                {
                    pModule->AlertCategory = sCategory;
                    pModule->AlertSeverity = sSeverity;
                }
#endif // _CAIRO_

                RtlFreeAnsiString (&ModuleNameA);
                ElfpFreeBuffer(SubKeyString);
                continue;

            }

            ListChanged = TRUE;

            pModule  = ElfpAllocateBuffer (sizeof (LOGMODULE) );
            if (!pModule) {
                ElfpFreeBuffer(SubKeyString);
                return(STATUS_NO_MEMORY);
            }

            //
            // Set up a module data structure for this module
            //

            pModule->LogFile = pLogFile;
            pModule->ModuleName = SubKeyString;

#ifdef _CAIRO_
            if (GetSourceAlertFilterFromRegistry(hLogFile,
                                                 &NewModule,
                                                 &sCategory,
                                                 &sSeverity))
            {
                pModule->AlertCategory = sCategory;
                pModule->AlertSeverity = sSeverity;
            }
            else
            {
                pModule->AlertCategory = pModule->AlertSeverity = 0;
            }
#endif // _CAIRO_

            if (NT_SUCCESS(Status)) {

                //
                // Link the new module in.
                //

                LinkLogModule(pModule, &ModuleNameA);

                RtlFreeAnsiString (&ModuleNameA);
            }
        }
    }

    if (Status == STATUS_NO_MORE_ENTRIES) {

        //
        // It's not required that there are configured modules for a log
        // file.
        //

        Status = STATUS_SUCCESS;
    }

    //
    // If the list has changed, or if we've been called during init, and not
    // as the result of a changenotify on the registry (bAllowDupes == FALSE)
    // then create the sources key
    //

    if (hLogFile && (ListChanged || !bAllowDupes)) {

        //
        // Now create a MULTI_SZ entry with all the module names for eventvwr
        //
        // STEP 1: Calculate amount of storage needed by running thru the
        //         module list, finding any module that uses this log file.
        //
        pListEntry = LogModuleHead.Flink;
        while (pListEntry != &LogModuleHead) {

            pModule = CONTAINING_RECORD (pListEntry, LOGMODULE, ModuleList);

            if (pModule->LogFile == pLogFile) {
                //
                // This one is for the log we're working on, get the
                // size of it's name.
                //
                ListLength += WCSSIZE(pModule->ModuleName);
            }
            pListEntry = pModule->ModuleList.Flink;
        }

        //
        // STEP 2:  Allocate storage for the MULTI_SZ.
        //
        pList = ElfpAllocateBuffer(ListLength + sizeof(WCHAR));

        //
        // If I can't allocate the list, just press on
        //

        if (pList) {

            //
            // STEP 3: Copy all the module names for this logfile into
            //         the MULTI_SZ string.
            //
            SubKeyString = pList; // Save this away

            pListEntry = LogModuleHead.Flink;

            while (pListEntry != &LogModuleHead) {

                pModule = CONTAINING_RECORD (
                                        pListEntry,
                                        LOGMODULE,
                                        ModuleList
                                        );

                if (pModule->LogFile == pLogFile) {

                    //
                    // This one is for the log we're working on, put it in the list
                    //

                    wcscpy(pList, pModule->ModuleName);
                    pList += wcslen(pModule->ModuleName);
                    pList++;

                }

                pListEntry = pModule->ModuleList.Flink;

            }

            *pList = L'\0'; // The terminating NULL

            RtlInitUnicodeString(&ListName, L"Sources");

            Status = NtSetValueKey(hLogFile,
                                   &ListName,
                                   0,
                                   REG_MULTI_SZ,
                                   SubKeyString,
                                   ListLength + sizeof(WCHAR)
                                   );

            ElfpFreeBuffer(SubKeyString);
        }
    }

    return(Status);

}


NTSTATUS
ElfSetUpConfigDataStructs (
        VOID
    )

/*++

Routine Description:

    This routine sets up all the necessary data structures for the eventlog
    service.  It enumerates the keys in the Logfiles registry node to
    determine what to setup.

Arguments:

    NONE

Return Value:

    NONE

Note:


--*/
{
    NTSTATUS Status = STATUS_SUCCESS;
    HANDLE hLogFile;
    OBJECT_ATTRIBUTES ObjectAttributes;
    UNICODE_STRING SubKeyName;
    PUNICODE_STRING pLogFileName = NULL;
    PUNICODE_STRING pModuleName = NULL;
    UNICODE_STRING EventlogModuleName;
    ULONG Index = 0;
    BYTE Buffer[ELF_MAX_REG_KEY_INFO_SIZE];
    PKEY_NODE_INFORMATION KeyBuffer = (PKEY_NODE_INFORMATION) Buffer;
    ULONG ActualSize;
    LOG_FILE_INFO LogFileInfo;
    PWCHAR SubKeyString;
    LPWSTR ModuleName;

    ElfDbgPrint(("[ELF] Set up config data structures\n"));

    //
    // Initialize the Atom table whose size is the maximum number of
    // module structures possible, i.e. ELF_MAX_LOG_MODULES.
    //

    if (! (InitAtomTable ( ELF_MAX_LOG_MODULES ))) {
        return (STATUS_UNSUCCESSFUL);
    }

    //
    // Get a handle to the Logfiles subkey.  If it doesn't exist, just use
    // the hard-coded defaults.
    //

    if (hEventLogNode) {

        //
        // Loop thru the subkeys under Eventlog and set up each logfile
        //

        while (NT_SUCCESS(Status)) {

            Status = NtEnumerateKey(hEventLogNode, Index++, KeyNodeInformation,
                KeyBuffer, ELF_MAX_REG_KEY_INFO_SIZE, & ActualSize);

            if (NT_SUCCESS(Status)) {

                //
                // It turns out the Name isn't null terminated, so we need
                // to copy it somewhere and null terminate it before we use it
                //

                SubKeyString = ElfpAllocateBuffer(KeyBuffer->NameLength +
                    sizeof(WCHAR));
                if (!SubKeyString) {
                    return(STATUS_NO_MEMORY);
                }

                memcpy(SubKeyString, KeyBuffer->Name, KeyBuffer->NameLength);
                SubKeyString[KeyBuffer->NameLength / sizeof(WCHAR)] = L'\0' ;

                //
                // Open the node for this logfile and extract the information
                // required by SetupDataStruct, and then call it.
                //

                RtlInitUnicodeString(&SubKeyName, SubKeyString);

                InitializeObjectAttributes(&ObjectAttributes,
                                          &SubKeyName,
                                          OBJ_CASE_INSENSITIVE,
                                          hEventLogNode,
                                          NULL
                                          );

                Status = NtOpenKey(&hLogFile, KEY_READ | KEY_SET_VALUE,
                    &ObjectAttributes);
                if (!NT_SUCCESS(Status)) {
                    //
                    // Unclear how this could happen since I just enum'ed
                    // it, but if I can't open it, I just pretend like it
                    // wasn't there to begin with.
                    //

                    ElfpFreeBuffer(SubKeyString);
                    Status = STATUS_SUCCESS; // so we don't terminate the loop
                    continue;
                }

                //
                // Get the information from the registry
                //

                Status = ReadRegistryInfo(hLogFile, &SubKeyName,
                    & LogFileInfo);

                if (NT_SUCCESS(Status)) {

                    //
                    // Now set up the actual data structures.  Failures are
                    // dealt with in the routine
                    //

                    SetUpDataStruct(LogFileInfo.LogFileName,
                                    LogFileInfo.MaxFileSize,
                                    LogFileInfo.Retention,
                                    LogFileInfo.GuestAccessRestriction,
                                    & SubKeyName,
                                    hLogFile,
                                    ElfNormalLog
                                    );

                    NtClose(hLogFile);

                }
            }

        }
    } // if (hEventLogNode)
    else {

        //
        // The information doesn't exist in the registry, set up the
        // three default logs.
        //

        pLogFileName = ElfpAllocateBuffer(sizeof(UNICODE_STRING));
        pModuleName = ElfpAllocateBuffer(sizeof(UNICODE_STRING));
        if (!pLogFileName || !pModuleName) {
            return(STATUS_NO_MEMORY);
        }
        RtlInitUnicodeString(pLogFileName,
            ELF_APPLICATION_DEFAULT_LOG_FILE);
        RtlInitUnicodeString(pModuleName, ELF_DEFAULT_MODULE_NAME);
        SetUpDataStruct(pLogFileName,
            ELF_DEFAULT_MAX_FILE_SIZE,
            ELF_DEFAULT_RETENTION_PERIOD,
            ELF_GUEST_ACCESS_UNRESTRICTED,
            pModuleName,
            NULL,
            ElfNormalLog
            );


        pLogFileName = ElfpAllocateBuffer(sizeof(UNICODE_STRING));
        pModuleName = ElfpAllocateBuffer(sizeof(UNICODE_STRING));
        if (!pLogFileName || !pModuleName) {
            return(STATUS_NO_MEMORY);
        }
        RtlInitUnicodeString(pLogFileName,
            ELF_SYSTEM_DEFAULT_LOG_FILE);
        RtlInitUnicodeString(pModuleName, ELF_SYSTEM_MODULE_NAME);
        SetUpDataStruct(pLogFileName,
            ELF_DEFAULT_MAX_FILE_SIZE,
            ELF_DEFAULT_RETENTION_PERIOD,
            ELF_GUEST_ACCESS_UNRESTRICTED,
            pModuleName,
            NULL,
            ElfNormalLog
            );


        pLogFileName = ElfpAllocateBuffer(sizeof(UNICODE_STRING));
        pModuleName = ElfpAllocateBuffer(sizeof(UNICODE_STRING));
        if (!pLogFileName || !pModuleName) {
            return(STATUS_NO_MEMORY);
        }
        RtlInitUnicodeString(pLogFileName,
            ELF_SECURITY_DEFAULT_LOG_FILE);
        RtlInitUnicodeString(pModuleName, ELF_SECURITY_MODULE_NAME);
        SetUpDataStruct(pLogFileName,
            ELF_DEFAULT_MAX_FILE_SIZE,
            ELF_DEFAULT_RETENTION_PERIOD,
            ELF_GUEST_ACCESS_UNRESTRICTED,
            pModuleName,
            NULL,
            ElfNormalLog
            );
    }

    //
    // If we just ran out of keys, that's OK (unless there weren't any at all)
    //

    if (Status == STATUS_NO_MORE_ENTRIES && Index != 1) {
        Status = STATUS_SUCCESS;
    }

    if (NT_SUCCESS(Status)) {

        //
        // Make sure we created the Application log file, since it is the
        // default.  If it wasn't created, use the first module created
        // (this is at the tail of the list since I insert them at the
        // head).  If this happens, send an alert to the admin.
        //

        if (!ElfDefaultLogModule) {
            ElfDbgPrintNC(("[ELF] No Logfile entry for Application module, "
                "default will be created\n"));

            if (IsListEmpty(&LogModuleHead)) {
                //
                // No logs were created, might as well shut down
                //

                return(STATUS_EVENTLOG_CANT_START);
            }

            ElfDefaultLogModule = CONTAINING_RECORD(LogModuleHead.Blink,
                                                    LOGMODULE,
                                                    ModuleList);

            ModuleName = L"Application";
            ElfpCreateQueuedAlert(ALERT_ELF_DefaultLogCorrupt, 1,
                &(ElfDefaultLogModule->LogFile->LogModuleName->Buffer));

        }

        //
        // Now get the Module for the Eventlog service to use.  GetModuleStruc
        // always succeeds, returning the default log if the requested one
        // isn't configured.
        //

        RtlInitUnicodeString(&EventlogModuleName, L"eventlog");
        ElfModule = GetModuleStruc(&EventlogModuleName);

    } else {

        if (pLogFileName && pModuleName) {
            ElfDbgPrintNC(("[ELF] Failure Setting up data structs for file %ws, "
                "Module %ws - %X\n", pLogFileName->Buffer, pModuleName->Buffer,
                Status));
        }
        else {
            ElfDbgPrintNC(("[ELF] Failure setting up data structs.  No logs"
                " defined in registry\n"));
        }
    }


    return (Status);

}


VOID
SVCS_ENTRY_POINT(       // (ELF_main)
    DWORD               argc,
    LPWSTR              argv[],
    PSVCS_GLOBAL_DATA   SvcsGlobalData,
    HANDLE              SvcRefHandle
    )

/*++

Routine Description:

    This is the main routine for the Event Logging Service.


Arguments:

    Command-line arguments.

Return Value:

    NONE

Note:


--*/
{

    NTSTATUS    Status;
    OBJECT_ATTRIBUTES ObjectAttributes;
    UNICODE_STRING RootRegistryNode;
    ULONG Win32Error = 0;
    ELF_REQUEST_RECORD FlushRequest;
    UNICODE_STRING ValueName;
    BYTE Buffer[ELF_MAX_REG_KEY_INFO_SIZE];
    PKEY_VALUE_FULL_INFORMATION ValueBuffer =
        (PKEY_VALUE_FULL_INFORMATION) Buffer;
    SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;

    UNREFERENCED_PARAMETER(argc);
    UNREFERENCED_PARAMETER(argv);

    ElfGlobalSvcRefHandle = SvcRefHandle;
    ElfGlobalData = SvcsGlobalData;

    //
    // Initialize the list heads for the modules and log files.
    //

    InitializeListHead ( &LogFilesHead );
    InitializeListHead ( &LogModuleHead );
    InitializeListHead ( &QueuedEventListHead );
    InitializeListHead ( &QueuedMessageListHead );

    //
    // Initialize to 0 so that we can clean up before exiting
    //

    EventFlags = 0;

    //
    //
    // Tuck away the local computer name
    //

    ComputerNameLength = 0;
    GetComputerNameW(LocalComputerName, &ComputerNameLength);
    ComputerNameLength += sizeof(WCHAR); // account for the NULL
    LocalComputerName = ElfpAllocateBuffer(ComputerNameLength * sizeof (WCHAR));
    if (!LocalComputerName ||
        !GetComputerNameW(LocalComputerName, &ComputerNameLength)) {
       ComputerNameLength = 0;
    }
    ComputerNameLength = (ComputerNameLength + 1) * sizeof(WCHAR);

    //
    // Initialize the status data.
    //
    ElInitStatus();

    // Set up control handler
    //

    ElfDbgPrint(("[ELF] Calling RegisterServiceCtrlHandler\n"));
    if ((ElfServiceStatusHandle = RegisterServiceCtrlHandler(
                                      wname_Eventlogsvc,
                                      ElfControlResponse
                                      )) == (SERVICE_STATUS_HANDLE) NULL) {

        Win32Error = GetLastError();

        //
        // If we got an error, we need to set status to uninstalled, and end the
        // thread.
        //

        ElfDbgPrintNC(("[ELF] RegisterServiceCtrlHandler = %u\n",Win32Error));
        goto cleanupandexit;
    }

    // Initialize all the status fields so that subsequent calls to
    // SetServiceStatus only need to update fields that changed.
    //

    //
    // Notify the Service Controller for the first time that we are alive
    // and is in a start pending state
    //
    //  *** UPDATE STATUS ***
    ElfStatusUpdate(STARTING);

    //
    // Get the localized title for message box popups.
    //
    ElfInitMessageBoxTitle();

    //
    // Set up the object that describes the root node for the eventlog service
    //

    RtlInitUnicodeString(&RootRegistryNode, REG_EVENTLOG_NODE_PATH);
    InitializeObjectAttributes(&ObjectAttributes,
                               &RootRegistryNode,
                               OBJ_CASE_INSENSITIVE,
                               NULL,
                               NULL
                               );
    //
    // If this fails, we'll just use the defaults
    //

    NtOpenKey(&hEventLogNode, KEY_READ | KEY_NOTIFY, &ObjectAttributes);

    //
    // See if there's a debug key
    //

    RtlInitUnicodeString(&ValueName, VALUE_DEBUG);

    NtQueryValueKey(hEventLogNode, &ValueName,
        KeyValueFullInformation, ValueBuffer,
        ELF_MAX_REG_KEY_INFO_SIZE, & ElfDebug);

    //
    // Initialize a critical section for use when adding or removing
    // LogFiles or LogModules. This must be done before we process any
    // file information.
    //

    Status = RtlInitializeCriticalSection(
                &LogFileCritSec
                );

    if ( !NT_SUCCESS(Status) ) {
        ElfDbgPrintNC(( "ELF log file crit sec init failed: %X\n", Status ));
        goto cleanupandexit;

    }
    Status = RtlInitializeCriticalSection(
                &LogModuleCritSec
                );

    if ( !NT_SUCCESS(Status) ) {
        ElfDbgPrintNC(( "ELF log file crit sec init failed: %X\n", Status ));
        goto cleanupandexit;

    }
    EventFlags |= ELF_INIT_LOGFILE_CRIT_SEC;

    Status = RtlInitializeCriticalSection(
                &QueuedEventCritSec
                );

    if ( !NT_SUCCESS(Status) ) {
        ElfDbgPrintNC(( "ELF queued event crit sec init failed: %X\n", Status ));
        goto cleanupandexit;

    }

    EventFlags |= ELF_INIT_QUEUED_EVENT_CRIT_SEC;

    Status = RtlInitializeCriticalSection(
                &QueuedMessageCritSec
                );

    if ( !NT_SUCCESS(Status) ) {
        ElfDbgPrintNC(( "ELF queued message crit sec init failed: %X\n", Status ));
        goto cleanupandexit;

    }

    EventFlags |= ELF_INIT_QUEUED_MESSAGE_CRIT_SEC;

    //
    // Initialize global anonymous logon sid for use in log ACL's.
    //

    Status = RtlAllocateAndInitializeSid(
                &NtAuthority,
                1,
                SECURITY_ANONYMOUS_LOGON_RID,
                0, 0, 0, 0, 0, 0, 0,
                &AnonymousLogonSid);

    if ( !NT_SUCCESS(Status) ) {
        ElfDbgPrintNC(("ELF anonymous log sid creation failed: %X\n",
                    Status ));
        goto cleanupandexit;
    }

    //
    // Set up the data structures for the Logfiles and Modules.
    //

    Status = ElfSetUpConfigDataStructs ();

    if ( !NT_SUCCESS(Status) ) {
        goto cleanupandexit;
    }

    //
    // Tell service controller of that we are making progress
    //
    //  *** UPDATE STATUS ***
    ElfStatusUpdate(STARTING);

    //
    // Initialize a critical section for use when adding or removing
    // context-handles (LogHandles).
    //

    Status = RtlInitializeCriticalSection(
                &LogHandleCritSec
                );

    if ( !NT_SUCCESS(Status) ) {
        ElfDbgPrintNC(( "ELF log handle crit sec init failed: %X\n", Status ));
        goto cleanupandexit;

    }
    EventFlags |= ELF_INIT_LOGHANDLE_CRIT_SEC;

    //
    // Initialize the context handle (log handle) list.
    //

    InitializeListHead( &LogHandleListHead );

    //
    // Initialize the Global Resource.
    //

    RtlInitializeResource ( &GlobalElfResource );
    EventFlags |= ELF_INIT_GLOBAL_RESOURCE;

    //
    // Tell service controller of that we are making progress
    //
    //  *** UPDATE STATUS ***
    ElfStatusUpdate(STARTING);

    //
    // Tell service controller of that we are making progress
    //
    //  *** UPDATE STATUS ***
    ElfStatusUpdate(STARTING);

    // Create a thread for watching the LPC port.
    //

    if (!StartLPCThread ()) {
        Status = STATUS_UNSUCCESSFUL;
        goto cleanupandexit;
    }
    EventFlags |= ELF_STARTED_LPC_THREAD;

    //
    // Tell service controller of that we are making progress
    //
    //  *** UPDATE STATUS ***
    ElfStatusUpdate(STARTING);

#ifdef _CAIRO_
    //
    // The eventlog service links to ALERTSYS.DLL by hand (eventlog.c) after
    // eventlog initialization, since this dll's initialization code requires
    // a running eventlog service.
    //
    // By no means, fail to start this service if something fails here.
    // It just won't be possible to raise NT events as Cairo alerts.
    //
    // BUGBUG : Should probably at least log an error.
    //          Should the service state be STARTING while this
    //          initialization is in progress?
    //

    if ((ghAlertSysDll = LoadLibrary(L"ALERTSYS.DLL")) != NULL)
    {
        //
        // Get ReportAlert API address.
        //

        if ((gpfReportAlert = (PREPORTALERT)GetProcAddress(
                                                (HMODULE)ghAlertSysDll,
                                                "ReportAlert")) == NULL)
        {
            FreeLibrary(ghAlertSysDll);
            ghAlertSysDll = NULL;
            ElfDbgPrintNC((
                "[ELF] ReportAlert GetProAddress failed, WIN32 error(%x)\n",
                GetLastError()));
        }
    }
    else
    {
        ElfDbgPrintNC((
            "[ELF] LoadLibrary of ALERTSYS.DLL failed, WIN32 error(%x)\n",
            GetLastError()));
    }

    //
    // Tell service controller of that we are making progress
    //
    //  *** UPDATE STATUS ***
    ElfStatusUpdate(STARTING);

#endif // _CAIRO_

    // Create a thread for watching for changes in the registry.
    //

    if (!ElfStartRegistryMonitor ()) {
        Status = STATUS_UNSUCCESSFUL;
        goto cleanupandexit;
    }
    EventFlags |= ELF_STARTED_REGISTRY_MONITOR;

    //
    // Write out an event that says we started
    //

    ElfpCreateElfEvent(EVENT_EventlogStarted,
                       EVENTLOG_INFORMATION_TYPE,
                       0,                    // EventCategory
                       0,                    // NumberOfStrings
                       NULL,                 // Strings
                       NULL,                 // Data
                       0,                    // Datalength
                       0                     // flags
                       );

    //
    // Write out any events that were queued up during initialization
    //

    FlushRequest.Command = ELF_COMMAND_WRITE_QUEUED;

    ElfPerformRequest(&FlushRequest);

    //
    // Tell service controller of that we are making progress
    //
    //  *** UPDATE STATUS ***
    ElfStatusUpdate(STARTING);

    //
    // Finish setting up the RPC server
    //
    // NOTE:  Now all RPC servers in services.exe share the same pipe name.
    // However, in order to support communication with version 1.0 of WinNt,
    // it is necessary for the Client Pipe name to remain the same as
    // it was in version 1.0.  Mapping to the new name is performed in
    // the Named Pipe File System code.
    //
    Status = ElfGlobalData->StartRpcServer(
                ElfGlobalData->SvcsRpcPipeName,
                eventlog_ServerIfHandle);

    if (Status != NO_ERROR) {
        ElfDbgPrint(("[ELF]StartRpcServer Failed %d\n",Status));
        goto cleanupandexit;
    }

    //
    // Tell service controller of that we are making progress
    //

    if (ElfStatusUpdate(RUNNING) == RUNNING) {
        ElfDbgPrint(("[ELF] Service Started Successfully\n"));
    }

    EventFlags |= ELF_STARTED_RPC_SERVER;

    if (GetElState() == RUNNING) {
        ElfDbgPrint(("[ELF] Service Running - main thread is returning\n"));
        return;
    }

//
// Come here if there is cleanup necessary.
//

cleanupandexit:

    ElfDbgPrint(("[ELF] Leaving the service\n"));

    if (!Win32Error) {
        Win32Error = RtlNtStatusToDosError(Status);
    }
    ElfBeginForcedShutdown(PENDING,Win32Error,Status);

    //
    // If the registry monitor has been initialized, then
    // let it do the shutdown cleanup.  All we need to do
    // here is wake it up.
    // Otherwise, this thread will do the cleanup.
    //
    if (EventFlags & ELF_STARTED_REGISTRY_MONITOR) {
        StopRegistryMonitor();
    }
    else {
        ElfpCleanUp(EventFlags);
        //
        // We should actually return here so that the DLL gets unloaded.
        // However, RPC has a problem in that it might still call our
        // context rundown routine even though we unregistered our interface.
        // So we exit thread instead.  This keeps our Dll loaded.
        //
        ExitThread(0);
    }
    return;
}

VOID
ElfInitMessageBoxTitle(
    VOID
    )

/*++

Routine Description:

    Obtains the title text for the message box used to display messages.
    If the title is successfully obtained from the message file, then
    that title is pointed to by GlobalAllocatedMsgTitle and
    GlobalMessageBoxTitle.  If unsuccessful, then GlobalMessageBoxTitle
    left pointing to the DefaultMessageBoxTitle.

    NOTE:  If successful, a buffer is allocated by this function.  The
    pointer stored in GlobalAllocatedMsgTitle and it should be freed when
    done with this buffer.

Arguments:

Return Value:

    none

--*/
{
    LPVOID      hModule;
    DWORD       msgSize;
    DWORD       status=NO_ERROR;

    GlobalAllocatedMsgTitle = NULL;

    hModule = LoadLibrary( L"netevent.dll");
    if ( hModule == NULL) {
        status = GetLastError();
        ElfDbgPrint(("LoadLibrary() fails with winError = %d\n", GetLastError()));
        return;
    }
    msgSize = FormatMessageW(
                FORMAT_MESSAGE_FROM_HMODULE |       //  dwFlags
                FORMAT_MESSAGE_ARGUMENT_ARRAY |
                FORMAT_MESSAGE_ALLOCATE_BUFFER,
                hModule,
                TITLE_EventlogMessageBox,           //  MessageId
                0,                                  //  dwLanguageId
                (LPWSTR)&GlobalAllocatedMsgTitle,   //  lpBuffer
                0,                                  //  nSize
                NULL);

    if (msgSize == 0) {
        status = GetLastError();
        ElfDbgPrint((ERROR,"Could not find MessageBox title in a message file %d\n",
        status));
    }
    else {
        GlobalMessageBoxTitle = GlobalAllocatedMsgTitle;
    }

    FreeLibrary(hModule);
    return;
}