summaryrefslogblamecommitdiffstats
path: root/private/os2/server/srvname.c
blob: 5f4251de1c97e9c48ac6a41bec663cb5fa7cc61e (plain) (tree)
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



















































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                                             
/*++

Copyright (c) 1989  Microsoft Corporation

Module Name:

    srvname.c

Abstract:

    This is the name space module for the OS/2 Subsystem Server

Author:

    Steve Wood (stevewo) 22-Aug-1989

Environment:

    User Mode Only

Revision History:

   Yaron Shamir (yarons) 4-Apr-91: Added Os2ComputeValidDrives, to
        fix initialization and computation of valid drives, to cope
        with new SM initialization and with redirected drives .
   Yaron Shamir (yarons) 6-May-91: changed the way we get at default
        and boot drives (matches Dos now).
   Yaron Shamir (yarons) 6-Aug-91: support named pipes.
   Yaron Shamir (yarons) 26-Aug-91: support UNC names.
   Beni Lavi (benil) 3-Mar-92: support mailslots
   Michael Jarus (mjaruss) 31-Mar-93: Remove Os2ComputeValidDrives
   Patrick Questembert (PatrickQ) 19-Mar-1995: Add COM10-16

--*/

#include "os2srv.h"
#include "os2win.h"

char * __cdecl getenv(char *varname);

PSECURITY_DESCRIPTOR securityDescriptor;

struct _INITIAL_OBJDIRS {
    PWSTR Name;
    PHANDLE Handle;
} InitialObjectDirectories[] = {
    {L"DEVICES", &Os2DevicesDirectory},
    {L"QUEUES", NULL},
    {L"SHAREMEM", NULL},
    {L"SEMAPHORES", NULL},
    {NULL, NULL}
};


struct _INITIAL_OBJDIRS Os2Drives =
        {L"DRIVES", &Os2DrivesDirectory};

HANDLE Os2NamedPipesDirectory;
HANDLE Os2UNCDirectory;
HANDLE Os2MailslotDirectory;
HANDLE Os2RegistryDirectory;

struct _INITIAL_RMT_OBJDIRS {
    PWSTR Name;
    PHANDLE Handle;
    PWSTR TargetName;
}  InitialRmtObjectDirectories[] = {
        {L"PIPE",     &Os2NamedPipesDirectory, L"\\DosDevices\\PIPE" },
        {L"UNC",      &Os2UNCDirectory,        L"\\DosDevices\\UNC" },
        {L"MAILSLOT", &Os2MailslotDirectory,   L"\\DosDevices\\MAILSLOT" },
        {NULL,       NULL,                    NULL}
};

//
// The InitialDevices table contains the values of symbolic links for
// special OS/2 files (devices).
// The first character of the Target field is used to specifiy the type
// of the device so that Od2Canonicalize() (in client\dllname.c) can
// determine and return it. Following characters are the value of the
// symbolic link which Od2Canonicalize returns as the canonicalized
// file name.
//
// Current defined types (first character of the Target field) are:
//
// @       FILE_TYPE_PSDEV
// #       FILE_TYPE_COM
// (space) FILE_TYPE_DEV
//

struct _INITIAL_DEVICES {
    PWSTR Name;
    PWSTR Target;
} InitialDevices[] = {
    {L"NUL"      , L"@@0"},
    {L"CON"      , L"@@1"},
    {L"AUX"      , L"#\\DosDevices\\COM1"},
    {L"COM1"     , L"#\\DosDevices\\COM1"},
    {L"COM2"     , L"#\\DosDevices\\COM2"},
    {L"COM3"     , L"#\\DosDevices\\COM3"},
    {L"COM4"     , L"#\\DosDevices\\COM4"},
    {L"COM5"     , L"#\\DosDevices\\COM5"},
    {L"COM6"     , L"#\\DosDevices\\COM6"},
    {L"COM7"     , L"#\\DosDevices\\COM7"},
    {L"COM8"     , L"#\\DosDevices\\COM8"},
    {L"COM9"     , L"#\\DosDevices\\COM9"},
    {L"COM10"     , L"#\\DosDevices\\COM10"},
    {L"COM11"     , L"#\\DosDevices\\COM11"},
    {L"COM12"     , L"#\\DosDevices\\COM12"},
    {L"COM13"     , L"#\\DosDevices\\COM13"},
    {L"COM14"     , L"#\\DosDevices\\COM14"},
    {L"COM15"     , L"#\\DosDevices\\COM15"},
    {L"COM16"     , L"#\\DosDevices\\COM16"},
    {L"PRN"      , L" \\DosDevices\\LPT1"},
    {L"LPT1"     , L" \\DosDevices\\LPT1"},
    {L"LPT2"     , L" \\DosDevices\\LPT2"},
    {L"LPT3"     , L" \\DosDevices\\LPT3"},
    {L"LPT4"     , L" \\DosDevices\\LPT4"},
    {L"LPT5"     , L" \\DosDevices\\LPT5"},
    {L"LPT6"     , L" \\DosDevices\\LPT6"},
    {L"LPT7"     , L" \\DosDevices\\LPT7"},
    {L"LPT8"     , L" \\DosDevices\\LPT8"},
    {L"LPT9"     , L" \\DosDevices\\LPT9"},
    {L"KBD$"     , L"@@4"},
    {L"MOUSE$"   , L"@@5"},
    {L"CLOCK$"   , L"@@6"},
    {L"SCREEN$"  , L"@@7"},
    {L"POINTER$" , L"@@8"},
    {NULL, NULL}
};

CHAR DeviceDirectoryName[] = "\\Device\\";
CHAR DeviceNameStr[] = "DEVICENAME";

//
// Information relevant for config.sys processing by the server
//
static WCHAR ConfigSysRegDir[] =
L"\\REGISTRY\\MACHINE\\SOFTWARE\\Microsoft\\OS/2 Subsystem for NT\\1.0\\config.sys";
static WCHAR ConfigSysValue[] = L"Config.Sys";

// BUGBUG - Beni, move those to GetNextDeviceNameFromConfigDotSys
static BOOLEAN ConfigDotSysWasRead = FALSE;
static ULONG FileSize = 0;
static ULONG CurrentOffset = 0;
static ANSI_STRING ConfigSysValueData_A = {0, 0, NULL};

//
// Process the config.sys file
// Returns TRUE if a line of the form:
//
// DEVICENAME=xxx [yyy]
//
// was detected in config.sys
// The string 'xxx' is returned in DeviceName
// If string 'yyy' is present its value is returned in TargetName
// Otherwise, a NUL string is returned in TargetName
//
// This routine may be called multiple time. Each time it returns the next
// DEVICENAME value string. When there are no more such values, the routine
// returns FALSE.
//
// The information read from the registry is of type REG_MULTI_SZ
// It used to be REG_SZ with CR-LF separating the lines. Therefore,
// the code accepts both lines that terminate with CR-LF and lined
// that terminate with NUL.
//
BOOLEAN
GetNextDeviceNameFromConfigDotSys(
    PSZ DeviceName,
    PSZ TargetName
    )
{
    NTSTATUS Status;
    OBJECT_ATTRIBUTES Obja;
    PSZ Name;
    PSZ TName;
    CHAR ch;
    UNICODE_STRING ConfigSysRegDir_U;
    UNICODE_STRING ConfigSysValue_U;
    UNICODE_STRING ConfigSysValueData_U;
    HANDLE ConfigSysKeyHandle;
    ULONG ResultLength;
    KEY_VALUE_PARTIAL_INFORMATION KeyValuePartialInfo;
    PKEY_VALUE_PARTIAL_INFORMATION pInfo;

    if (!ConfigDotSysWasRead)
    {
        //
        // Copy the config.sys image from the registry to memory
        //
        RtlInitUnicodeString(&ConfigSysRegDir_U, ConfigSysRegDir);
        InitializeObjectAttributes(&Obja,
                                   &ConfigSysRegDir_U,
                                   OBJ_CASE_INSENSITIVE,
                                   NULL,
                                   NULL);

        Status = NtOpenKey(&ConfigSysKeyHandle,
                           KEY_READ,
                           &Obja
                          );
        if (!NT_SUCCESS(Status))
        {
#if DBG
            IF_OS2_DEBUG(CLEANUP)
            {
                KdPrint(("OS2SRV: FAILED - NtOpenKey() of config.sys %lx\n",
                    Status));
            }
#endif
            return (FALSE);
        }
        RtlInitUnicodeString(&ConfigSysValue_U, ConfigSysValue);
        Status = NtQueryValueKey(ConfigSysKeyHandle,
                                 &ConfigSysValue_U,
                                 KeyValuePartialInformation,
                                 &KeyValuePartialInfo,
                                 sizeof(KeyValuePartialInfo),
                                 &ResultLength
                                );
        if (!NT_SUCCESS(Status) && (Status != STATUS_BUFFER_OVERFLOW))
        {
#if DBG
            IF_OS2_DEBUG(CLEANUP) {
                KdPrint(("OS2SRV: FAILED - NtQueryValueKey-1 %lx\n",
                    Status));
            }
#endif
            return (FALSE);
        }

        pInfo = (PKEY_VALUE_PARTIAL_INFORMATION)RtlAllocateHeap(Os2Heap, 0, ResultLength);
        if (pInfo == NULL)
        {
#if DBG
            IF_OS2_DEBUG(CLEANUP)
            {
                KdPrint(("OS2SRV: FAILED - RtlAllocateHeap\n"));
            }
#endif
            return (FALSE);
        }

        Status = NtQueryValueKey(ConfigSysKeyHandle,
                                 &ConfigSysValue_U,
                                 KeyValuePartialInformation,
                                 pInfo,
                                 ResultLength,
                                 &ResultLength
                                );
        NtClose(ConfigSysKeyHandle);
        if (!NT_SUCCESS(Status))
        {
#if DBG
            IF_OS2_DEBUG(CLEANUP)
            {
                KdPrint(("OS2SRV: FAILED - NtQueryValueKey %lx\n",
                    Status));
            }
#endif
            RtlFreeHeap(Os2Heap, 0, pInfo);
            return (FALSE);
        }

        //
        // The information in the registry is Unicode.
        // Convert it to ANSI. Initialize explicity the UNICODE_STRING
        // structure since the data in the registry is of type REG_MULTI_SZ
        // and hence contains embedded NULs.
        //

        ConfigSysValueData_U.Buffer = (PWSTR)pInfo->Data;
        ConfigSysValueData_U.Length = (USHORT)pInfo->DataLength - 2;
        ConfigSysValueData_U.MaximumLength = (USHORT)pInfo->DataLength;

        Status = RtlUnicodeStringToAnsiString(&ConfigSysValueData_A,
                                &ConfigSysValueData_U, TRUE);
        RtlFreeHeap(Os2Heap, 0, pInfo);
        if (!NT_SUCCESS(Status))
        {
#if DBG
            IF_OS2_DEBUG(CLEANUP)
            {
                KdPrint(("OS2SRV: FAILED - RtlUnicodeStringToAnsiString %lx\n",
                    Status));
            }
#endif
            return (FALSE);
        }

        FileSize = ConfigSysValueData_A.Length;
        CurrentOffset = 0;
        ConfigDotSysWasRead = TRUE;
    }

    while (CurrentOffset < FileSize)
    {
        // skip leading blanks
        while ((ConfigSysValueData_A.Buffer[CurrentOffset] == ' ') ||
               (ConfigSysValueData_A.Buffer[CurrentOffset] == '\t'))
        {
            CurrentOffset++;
            if (CurrentOffset >= FileSize)
            {
                RtlFreeAnsiString(&ConfigSysValueData_A);
                return (FALSE);
            }
        }
        if ((CurrentOffset + sizeof(DeviceNameStr) - 1) >= FileSize)
        {
            RtlFreeAnsiString(&ConfigSysValueData_A);
            return (FALSE);
        }
        // check if the first name in the line is DEVICENAME
        if (_strnicmp(&ConfigSysValueData_A.Buffer[CurrentOffset], DeviceNameStr, sizeof(DeviceNameStr)-1)) {
            while ((ConfigSysValueData_A.Buffer[CurrentOffset] != '\n') &&
                   (ConfigSysValueData_A.Buffer[CurrentOffset] != '\0'))
            {
                CurrentOffset++;
                if (CurrentOffset >= FileSize)
                {
                    RtlFreeAnsiString(&ConfigSysValueData_A);
                    return (FALSE);
                }
            }
            CurrentOffset++;
            continue;
        }
        CurrentOffset += sizeof(DeviceNameStr)-1;
        // skip possible blanks between DEVICENAME and =
        while ((ConfigSysValueData_A.Buffer[CurrentOffset] == ' ') ||
               (ConfigSysValueData_A.Buffer[CurrentOffset] == '\t'))
        {
            CurrentOffset++;
            if (CurrentOffset >= FileSize)
            {
                RtlFreeAnsiString(&ConfigSysValueData_A);
                return (FALSE);
            }
        }
        // verify that there is an = after the DEVICENAME
        if (ConfigSysValueData_A.Buffer[CurrentOffset] != '=')
        {
            while ((ConfigSysValueData_A.Buffer[CurrentOffset] != '\n') &&
                   (ConfigSysValueData_A.Buffer[CurrentOffset] != '\0'))
            {
                CurrentOffset++;
                if (CurrentOffset >= FileSize)
                {
                    RtlFreeAnsiString(&ConfigSysValueData_A);
                    return (FALSE);
                }
            }
            CurrentOffset++;
            continue;
        }
        else
        {
            CurrentOffset++; // skip the '='
            if (CurrentOffset >= FileSize)
            {
                RtlFreeAnsiString(&ConfigSysValueData_A);
                return (FALSE);
            }
        }
        // skip possible blanks between = and the device name
        while ((ConfigSysValueData_A.Buffer[CurrentOffset] == ' ') ||
               (ConfigSysValueData_A.Buffer[CurrentOffset] == '\t'))
        {
            CurrentOffset++;
            if (CurrentOffset >= FileSize)
            {
                RtlFreeAnsiString(&ConfigSysValueData_A);
                return (FALSE);
            }
        }
        // process the device name

        Name = DeviceName;
        while (((ch = ConfigSysValueData_A.Buffer[CurrentOffset]) != '\r') &&
               (ch != '\n') &&
               (ch != ' ') &&
               (ch != '\t') &&
               (ch != '\0')
            )
        {
            *Name++ = ch;
            CurrentOffset++;
            if (CurrentOffset >= FileSize)
            {
                *Name = '\0';
                return (TRUE);
            }
        }
        *Name = '\0';
        if (*DeviceName == '\0')
        {
            //
            // Null device name, return false
            //
            RtlFreeAnsiString(&ConfigSysValueData_A);
            return (FALSE);
        }
        // skip possible blanks and commas between the Device name and the Target name
        while ((ConfigSysValueData_A.Buffer[CurrentOffset] == ' ') ||
               (ConfigSysValueData_A.Buffer[CurrentOffset] == ',') ||
               (ConfigSysValueData_A.Buffer[CurrentOffset] == '\t'))
        {
            CurrentOffset++;
            if (CurrentOffset >= FileSize)
            {
                RtlFreeAnsiString(&ConfigSysValueData_A);
                return (FALSE);
            }
        }
        // process the device target name
        TName = TargetName;
        // first put a blank to match the rest of the devices
        *TName++ = ' ';
        while (((ch = ConfigSysValueData_A.Buffer[CurrentOffset]) != '\r') &&
               (ch != '\n') &&
               (ch != ' ') &&
               (ch != '\t') &&
               (ch != '\0')
            )
        {
            *TName++ = ch;
            CurrentOffset++;
            if (CurrentOffset >= FileSize)
            {
                *TName = '\0';
                return (TRUE);
            }
        }
        *TName = '\0';
        // did we have a target name?
        if (TName == (TargetName+1))
        {
           // No - it's only the space we had put - nullify
           *TargetName = '\0';
        }

        while ((ConfigSysValueData_A.Buffer[CurrentOffset] != '\n') &&
               (ConfigSysValueData_A.Buffer[CurrentOffset] != '\0'))
        {
            CurrentOffset++;
            if (CurrentOffset >= FileSize)
            {
                return (TRUE);
            }
        }
        CurrentOffset++;
        return (TRUE);
    }

    RtlFreeAnsiString(&ConfigSysValueData_A);
    return (FALSE);
}


NTSTATUS
Os2InitializeNameSpace( VOID )
{
    NTSTATUS Status;
    OBJECT_ATTRIBUTES ObjectAttributes;
    UNICODE_STRING DirectoryName_U;
    HANDLE DirectoryHandle;
    PHANDLE Directory;
    UNICODE_STRING LinkTarget_U, LinkName_U;
    HANDLE LinkHandle;
    CHAR localSecurityDescriptor[SECURITY_DESCRIPTOR_MIN_LENGTH];
    ULONG i;
    ANSI_STRING DeviceName_A;
    ANSI_STRING TargetDeviceName_A;
    CHAR DeviceName[32];
    CHAR TargetDeviceName[48];

    //
    // Create a root directory in the object name space that will be used
    // to contain all of the named objects created by the OS/2 Emulation
    // subsystem.
    //

    RtlInitUnicodeString( &DirectoryName_U, OS2_SS_ROOT_OBJECT_DIRECTORY );

    Status = RtlCreateSecurityDescriptor( (PSECURITY_DESCRIPTOR)
                                          &localSecurityDescriptor,
                                          SECURITY_DESCRIPTOR_REVISION );
    ASSERT( NT_SUCCESS( Status ) );
    if (! NT_SUCCESS( Status )) {
        return Status;
    }

    Status = RtlSetDaclSecurityDescriptor( (PSECURITY_DESCRIPTOR)
                                           &localSecurityDescriptor,
                                           (BOOLEAN)TRUE,
                                           (PACL) NULL,
                                           (BOOLEAN)FALSE );
    ASSERT (NT_SUCCESS(Status));
    if (! NT_SUCCESS( Status )) {
        return Status;
    }

    securityDescriptor = (PSECURITY_DESCRIPTOR) &localSecurityDescriptor;

    InitializeObjectAttributes(
                    &ObjectAttributes,
                    &DirectoryName_U,
                    OBJ_CASE_INSENSITIVE,
//                  OBJ_PERMANENT | OBJ_CASE_INSENSITIVE,
                    NULL,
                    securityDescriptor
                    );

    Status = NtOpenDirectoryObject( &Os2RootDirectory,
                                      DIRECTORY_ALL_ACCESS,
                                      &ObjectAttributes
                                    );

    if (Status == STATUS_OBJECT_NAME_NOT_FOUND)
    {
       ULONG i = 100;   // 10 seconds

#if DBG
        KdPrint(("OS2SRV: wait for os2ss to initialize\n"));
#endif
       while (Status == STATUS_OBJECT_NAME_NOT_FOUND && i > 0)
       {
            //
            // Wait 0.1 sec  for os2ss to complete initialization
            //
            Sleep (100L);
#if DBG
            KdPrint(("."));
#endif
            Status = NtOpenDirectoryObject( &Os2RootDirectory,
                                              DIRECTORY_ALL_ACCESS,
                                              &ObjectAttributes
                                            );
            i--;
       }
    }
    if (! NT_SUCCESS( Status ))
    {
#if DBG
        KdPrint(("OS2SRV: SubSystem = Can't open \\os2ss directory object\n"));
#endif
        return Status;
    }

    //
    // Make the Drives directory a symbolic link
    // of \DosDevices
    //
    RtlInitUnicodeString( &DirectoryName_U, Os2Drives.Name );
    RtlInitUnicodeString( &LinkTarget_U, L"\\DosDevices" );

    InitializeObjectAttributes( &ObjectAttributes,
                                    &DirectoryName_U,
                    //                OBJ_PERMANENT | OBJ_CASE_INSENSITIVE,
                                    OBJ_CASE_INSENSITIVE,
                                    Os2RootDirectory,
                                    securityDescriptor
                                  );
    Status = NtCreateSymbolicLinkObject( Os2Drives.Handle,
                                         SYMBOLIC_LINK_ALL_ACCESS,
                                         &ObjectAttributes,
                                         &LinkTarget_U
                                         );
    if (Status == STATUS_OBJECT_NAME_COLLISION) {
                //
                // An os2srv is already present, print out and exit
                //
#if DBG
        KdPrint(( "OS2SRV: Unable to initialize server.  An instance of OS2SRV already runs. Status == %X\n",
                  Status
                ));
#endif

        NtTerminateProcess( NtCurrentProcess(), Status );
    }

    ASSERT (NT_SUCCESS(Status));
    if (! NT_SUCCESS( Status )) {
        return Status;
    }

    for (i=0; InitialObjectDirectories[ i ].Name; i++) {
        RtlInitUnicodeString( &DirectoryName_U, InitialObjectDirectories[ i ].Name );
        Directory = InitialObjectDirectories[ i ].Handle;
        if (Directory == NULL) {
            Directory = &DirectoryHandle;
        }

        InitializeObjectAttributes( &ObjectAttributes,
                                    &DirectoryName_U,
                    //                OBJ_PERMANENT | OBJ_CASE_INSENSITIVE,
                                    OBJ_CASE_INSENSITIVE,
                                    Os2RootDirectory,
                                    securityDescriptor
                                  );
        Status = NtCreateDirectoryObject( Directory,
                                          DIRECTORY_ALL_ACCESS,
                                          &ObjectAttributes
                                        );
        ASSERT( NT_SUCCESS( Status ) );
        if (! NT_SUCCESS( Status )) {
            KdPrint(("OS2SRV: FAILED - NtCreateDirectoryObject stts= %lx\n",
                    Status));
            return Status;
        }

        if (Directory == &DirectoryHandle) {
            NtClose( DirectoryHandle );
        }
    }

    for (i=0; InitialDevices[ i ].Name; i++) {
        RtlInitUnicodeString( &LinkName_U, InitialDevices[ i ].Name );
        RtlInitUnicodeString( &LinkTarget_U, InitialDevices[ i ].Target );

        InitializeObjectAttributes( &ObjectAttributes,
                                    &LinkName_U,
                                    // OBJ_PERMANENT | OBJ_CASE_INSENSITIVE,
                                    OBJ_CASE_INSENSITIVE,
                                    Os2DevicesDirectory,
                                    securityDescriptor
                                  );
        Status = NtCreateSymbolicLinkObject( &LinkHandle,
                                             SYMBOLIC_LINK_ALL_ACCESS,
                                             &ObjectAttributes,
                                             &LinkTarget_U
                                           );
        ASSERT( NT_SUCCESS( Status ) );
        if (! NT_SUCCESS( Status )) {
            return Status;
        }

//        NtClose( LinkHandle );
    }

    //
    // Make the remote directories a symbolic link of \DosDevices\*
    //
    for (i =0; InitialRmtObjectDirectories[i].Name != NULL; i++) {
        RtlInitUnicodeString( &DirectoryName_U, InitialRmtObjectDirectories[i].Name );
        RtlInitUnicodeString( &LinkTarget_U, InitialRmtObjectDirectories[i].TargetName);

        InitializeObjectAttributes( &ObjectAttributes,
                                    &DirectoryName_U,
                                    OBJ_CASE_INSENSITIVE,
                                    // OBJ_PERMANENT | OBJ_CASE_INSENSITIVE,
                                    Os2RootDirectory,
                                    securityDescriptor
                                  );
        Status = NtCreateSymbolicLinkObject( InitialRmtObjectDirectories[i].Handle,
                                             SYMBOLIC_LINK_ALL_ACCESS,
                                             &ObjectAttributes,
                                             &LinkTarget_U
                                             );
        ASSERT( NT_SUCCESS( Status ) );
        if (! NT_SUCCESS( Status )) {
            return Status;
        }
    }

    //
    // Process config.sys for the DEVICENAME= definitions
    //

    while (GetNextDeviceNameFromConfigDotSys(DeviceName, TargetDeviceName))
    {
#if DBG
        if (TargetDeviceName[0] == '\0') {
            KdPrint(("OS2SRV: Read DEVICENAME=%s from config.sys\n", DeviceName));
        }
        else {
            KdPrint(("OS2SRV: Read DEVICENAME=%s %s from config.sys\n",
                     DeviceName, TargetDeviceName));
        }
#endif
        RtlInitAnsiString(&DeviceName_A, DeviceName);
        RtlAnsiStringToUnicodeString( &LinkName_U, &DeviceName_A, (BOOLEAN)TRUE );
        if (TargetDeviceName[0] == '\0') {
            strcpy(TargetDeviceName, DeviceDirectoryName);
            strcat(TargetDeviceName, DeviceName);
        }
        RtlInitAnsiString(&TargetDeviceName_A, TargetDeviceName);
        RtlAnsiStringToUnicodeString( &LinkTarget_U, &TargetDeviceName_A, (BOOLEAN)TRUE );

        InitializeObjectAttributes( &ObjectAttributes,
                                    &LinkName_U,
                                    OBJ_CASE_INSENSITIVE,
                                    Os2DevicesDirectory,
                                    securityDescriptor
                                  );
        Status = NtCreateSymbolicLinkObject( &LinkHandle,
                                             SYMBOLIC_LINK_ALL_ACCESS,
                                             &ObjectAttributes,
                                             &LinkTarget_U
                                           );
        RtlFreeUnicodeString(&LinkName_U);
        RtlFreeUnicodeString(&LinkTarget_U);

        if (! NT_SUCCESS( Status )) {
#if DBG
            KdPrint(("OS2SRV: Could not Link Device '%s' to target devices\n", DeviceName));
#endif
        }
    }

    return( Os2InitializeDriveLetters() );
}


BOOLEAN
Os2CheckValidCDrives(VOID)
{
    NTSTATUS Status;
    HANDLE LinkHandle;
    UNICODE_STRING DriveName_U;
    WCHAR DriveString[15] = L"\\DosDevices\\C:";
    OBJECT_ATTRIBUTES Attributes;

        //
        // compute the valid drives from scratch, since
        // redirected drives appear and disappear dynamically
        //

    RtlInitUnicodeString(&DriveName_U, DriveString);

    InitializeObjectAttributes(
                &Attributes,
                &DriveName_U,
                OBJ_CASE_INSENSITIVE,
                NULL,
                NULL);
    Status = NtOpenSymbolicLinkObject( &LinkHandle,
                                       SYMBOLIC_LINK_QUERY,
                                       &Attributes
                                 );
    if (Status != STATUS_OBJECT_NAME_NOT_FOUND) {

        NtClose( LinkHandle );
        return(TRUE);
    }
    return (FALSE);
}


NTSTATUS
Os2InitializeDriveLetters( VOID )
{
    //
    // Set the SystemDrive number from the environment
    //

    SystemRootValuePtr = getenv("SYSTEMROOT");
    if (SystemRootValuePtr == NULL) {
        SystemRootValuePtr = "C:\\";
    }
    Os2DefaultDrive = (ULONG)(RtlUpperChar(*SystemRootValuePtr) - 'A');

    Os2BootDrive = 2; // C:

    //
    // check if not C:
    //

    if (!Os2CheckValidCDrives()) {
        Os2BootDrive = 0; // A:
        if (Os2DefaultDrive == 2) {
             Os2DefaultDrive = 0; // A:
        }
    }
    return STATUS_SUCCESS;
}


NTSTATUS
Os2GetClientId( VOID )
{
    NTSTATUS Status;
    HANDLE LinkHandle;
    OBJECT_ATTRIBUTES Attributes;
    UNICODE_STRING DebugClientId_U;
    UNICODE_STRING ClientIdString_U;

        Os2DebugUserClientId.UniqueProcess = NULL;

        RtlInitUnicodeString(&DebugClientId_U, L"DebugClientId");
        InitializeObjectAttributes(
                    &Attributes,
                    &DebugClientId_U,
                    OBJ_CASE_INSENSITIVE,
                    Os2RootDirectory,
                    NULL);
        Status = NtOpenSymbolicLinkObject( &LinkHandle,
                                           SYMBOLIC_LINK_QUERY,
                                           &Attributes
                                     );

        if (!NT_SUCCESS( Status )) {
            return Status;
        }

        ClientIdString_U.Buffer = (PWSTR)&Os2DebugUserClientId;
        ClientIdString_U.Length = 0;
        ClientIdString_U.MaximumLength = sizeof( Os2DebugUserClientId );
        Status = NtQuerySymbolicLinkObject( LinkHandle,
                                            &ClientIdString_U,
                                            NULL
                                          );

        if (!NT_SUCCESS( Status )) {
            return Status;
        }

        return Status;
}