summaryrefslogtreecommitdiffstats
path: root/private/os2/client/dllcnfg.c
blob: c8b1c92df1e6ee0e66bde8827f3f8f36037dedaa (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
/*++

Copyright (c) 1989  Microsoft Corporation

Module Name:

    dllcnfg.c

Abstract:

    This module contains the code related to the processing of
    CONFIG.SYS in the client.

Author:

    Ofer Porat (oferp) 4-Jan-1993

Environment:

    User Mode only

Revision History:

    This code was originally in dllinit.c.

--*/

#define INCL_OS2V20_ALL
#include "os2dll.h"
#include "os2win.h"


static BOOLEAN Od2ConfigDotSysCreated = FALSE;
static ULONG Od2ConfigSysAllowedAccess;

static CHAR Od2CanonicalDiskConfigDotSys[] = "\\OS2SS\\DRIVES\\C:\\CONFIG.SYS";
static CHAR Od2CanonicalConfigDotSys[MAX_PATH] = "\\OS2SS\\DRIVES\\";

VOID
Ow2ConfigSysPopup(
    VOID
    );

BOOLEAN
Od2FileIsConfigSys(
    IN OUT PANSI_STRING FileName_A,
    IN ULONG AccessMode,
    OUT PNTSTATUS ResultStatus
    )

/*++

Routine Description:

    This routine checks to see if the user wants to access the config.sys file.  If so,
    a message is sent to the server requesting creation of this file.  If the file is
    created, the file name is changed to the internal name of os2conf.nt.  Some
    bookkeeping information about the usage of config.sys is also kept internally.
    The request to the server is sent only once for the entire process.  Additional
    requests for access to config.sys will simply modify the name, since the file
    already exists.  A popup is generated if the user requests READWRITE access
    when he doesn't have the privilege.  Internal info is kept on what kind of
    access to config.sys is allowed, so additional calls can be processed without
    further messages to the server.

    Revision (2/10/93):
        if CLIENT_POPUP_ON_READ is true (defined in inc\os2ssrtl.h) then we also
        generate a popup on read access requests, so the user knows he can't write.
        this is in case the editor doesn't inform him that he can't write.

Arguments:

    FileName_A -- supplies the name of the user's file.  If this is C:\CONFIG.SYS, and
            the file is successfully created, the name will be modified to the name
            of os2config.nt (= <systemdir>\os2\os2conf.nt).

    AccessMode -- the desired access to the file.  either OPEN_ACCESS_READONLY or
            OPEN_ACCESS_READWRITE.  If the desired access can't be granted,
            ResultStatus will be STATUS_ACCESS_DENIED, and the file won't be created.

    ResultStatus -- returns an NT error code that may describe many errors possible
            during the creation attempt.

Return Value:

    FALSE -- FileName_A is not "C:\CONFIG.SYS".  The name is not modified and ResultStatus
             is STATUS_OBJECT_TYPE_MISMATCH.

    TRUE -- FileName_A is "C:\CONFIG.SYS".  ResultStatus indicates if the operation was
            successful.  If it was, the name is modified to that of os2conf.nt.

--*/

{
    OS2_API_MSG m;
    POS2_CONFIGSYS_MSG a = &m.u.CreateConfigSysRequest;
    NTSTATUS Status;
    ULONG StringLen;
    PSZ NameBuffer;

    if (_stricmp(FileName_A->Buffer, Od2CanonicalDiskConfigDotSys) != 0) {
        *ResultStatus = STATUS_OBJECT_TYPE_MISMATCH;
        return(FALSE);
    }

    //
    // Special handling of c:\config.sys
    // opening this file is mapped to the OS/2 SS config.sys
    //

    //
    // Check the parameter
    //

    if (AccessMode != OPEN_ACCESS_READONLY &&
        AccessMode != OPEN_ACCESS_READWRITE) {
        *ResultStatus = STATUS_INVALID_PARAMETER;
        return(TRUE);
    }

    if (!Od2ConfigDotSysCreated) {
        do {        // A 1-time loop to allow break upon error

#if OS2CONF_NAME_OPT
            if (GetSystemDirectoryA(Od2CanonicalConfigDotSys + FILE_PREFIX_LENGTH, MAX_PATH) == 0) {
#if DBG
                IF_OD2_DEBUG(MISC) {
                    KdPrint(("Od2FileIsConfigSys: Cannot obtain name of system directory\n"));
                }
#endif
                Status = STATUS_UNEXPECTED_IO_ERROR;
                break;
            }
#else
            strcpy(Od2CanonicalConfigDotSys + FILE_PREFIX_LENGTH, "C:");
#endif

            strcat(Od2CanonicalConfigDotSys, OS2CONF_NAMEA);

            //
            // Now call the server to do the work
            //

            a->RequiredAccess = AccessMode;

            Od2CallSubsystem(&m, NULL, Os2CreateConfigSys, sizeof(*a));

            Od2ConfigSysAllowedAccess = a->AllowedAccess;
            Status = a->ReturnStatus;

            if (!NT_SUCCESS(Status)) {
#if DBG
                IF_OD2_DEBUG(MISC) {
                    KdPrint(("Od2FileIsConfigSys: server os2conf.nt creator failed, Status = %lx\n", Status));
                }
#endif
                if (Status == STATUS_ACCESS_DENIED &&
                    AccessMode == OPEN_ACCESS_READWRITE &&
                    Od2ConfigSysAllowedAccess == OPEN_ACCESS_READONLY) {

                        Ow2ConfigSysPopup();
                }

                break;
            }

#if CLIENT_POPUP_ON_READ
            if (Od2ConfigSysAllowedAccess == OPEN_ACCESS_READONLY) {
                Ow2ConfigSysPopup();
            }
#endif
            Od2ConfigDotSysCreated = TRUE;

        } while (FALSE);

        if (!NT_SUCCESS(Status)) {
            *ResultStatus = Status;
            return(TRUE);
        }

    } else {
        if (Od2ConfigSysAllowedAccess == OPEN_ACCESS_READONLY) {
#if CLIENT_POPUP_ON_READ
            Ow2ConfigSysPopup();
#endif
            if (AccessMode == OPEN_ACCESS_READWRITE) {
#if !CLIENT_POPUP_ON_READ
                Ow2ConfigSysPopup();
#endif
#if DBG
                IF_OD2_DEBUG(MISC) {
                    KdPrint(("Od2FileIsConfigSys: denying write access to os2conf.nt\n"));
                }
#endif
                *ResultStatus = STATUS_ACCESS_DENIED;
                return(TRUE);
            }
        }
    }

    //
    // We now replace the file name with our own file name.
    // We assume that the name is on Od2Heap.  This is fine since
    // that's where Od2Canonicalize gets it from.  We allocate a new
    // buffer from the same heap.
    //

    StringLen = strlen(Od2CanonicalConfigDotSys) + 1;
    NameBuffer = (PSZ)RtlAllocateHeap(Od2Heap, 0, StringLen);

    if (NameBuffer == NULL) {
#if DBG
        IF_OD2_DEBUG(MISC) {
            KdPrint(("Od2FileIsConfigSys: Cannot allocate space for canoncial name\n"));
        }
#endif
        *ResultStatus = STATUS_NO_MEMORY;
        return(TRUE);
    }

    RtlMoveMemory(NameBuffer, Od2CanonicalConfigDotSys, StringLen);
    RtlFreeHeap(Od2Heap, 0, FileName_A->Buffer);
    Od2InitMBString(FileName_A, NameBuffer);

    *ResultStatus = STATUS_SUCCESS;
    return (TRUE);
}