3 * initwkdll.c - Load the well known DLLs
5 * ReactOS Operating System
7 * --------------------------------------------------------------------
9 * This software is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
14 * This software is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this software; see the file COPYING.LIB. If not, write
21 * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
24 * --------------------------------------------------------------------
32 static NTSTATUS STDCALL
33 SmpKnownDllsQueryRoutine(PWSTR ValueName
,
40 OBJECT_ATTRIBUTES ObjectAttributes
;
41 IO_STATUS_BLOCK IoStatusBlock
;
42 UNICODE_STRING ImageName
;
47 DPRINT("ValueName '%S' Type %lu Length %lu\n", ValueName
, ValueType
, ValueLength
);
48 DPRINT("ValueData '%S' Context %p EntryContext %p\n", (PWSTR
)ValueData
, Context
, EntryContext
);
50 /* Ignore the 'DllDirectory' value */
51 if (!_wcsicmp(ValueName
, L
"DllDirectory"))
52 return STATUS_SUCCESS
;
54 /* Open the DLL image file */
55 RtlInitUnicodeString(&ImageName
,
57 InitializeObjectAttributes(&ObjectAttributes
,
62 Status
= NtOpenFile(&FileHandle
,
63 SYNCHRONIZE
| FILE_EXECUTE
| FILE_READ_DATA
,
67 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_NON_DIRECTORY_FILE
);
68 if (!NT_SUCCESS(Status
))
70 DPRINT1("NtOpenFile() failed (Status %lx)\n", Status
);
71 return STATUS_SUCCESS
;
74 DPRINT("Opened file %wZ successfully\n", &ImageName
);
76 /* Check for valid image checksum */
77 Status
= LdrVerifyImageMatchesChecksum (FileHandle
,
81 if (Status
== STATUS_IMAGE_CHECKSUM_MISMATCH
)
83 /* Raise a hard error (crash the system/BSOD) */
84 NtRaiseHardError (Status
,
91 else if (!NT_SUCCESS(Status
))
93 DPRINT1("Failed to check the image checksum\n");
95 NtClose(SectionHandle
);
98 return STATUS_SUCCESS
;
101 InitializeObjectAttributes(&ObjectAttributes
,
103 OBJ_CASE_INSENSITIVE
| OBJ_PERMANENT
,
104 (HANDLE
)EntryContext
,
106 Status
= NtCreateSection(&SectionHandle
,
113 if (NT_SUCCESS(Status
))
115 DPRINT("Created section successfully\n");
116 NtClose(SectionHandle
);
121 return STATUS_SUCCESS
;
126 SmLoadKnownDlls(VOID
)
128 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
129 OBJECT_ATTRIBUTES ObjectAttributes
;
130 IO_STATUS_BLOCK IoStatusBlock
;
131 UNICODE_STRING DllDosPath
;
132 UNICODE_STRING DllNtPath
;
134 HANDLE ObjectDirHandle
;
135 HANDLE FileDirHandle
;
136 HANDLE SymlinkHandle
;
140 DPRINT("SM: loading well-known DLLs\n");
142 DPRINT("SmLoadKnownDlls() called\n");
144 /* Create 'KnownDlls' object directory */
145 RtlInitUnicodeString(&Name
,
147 InitializeObjectAttributes(&ObjectAttributes
,
149 OBJ_PERMANENT
| OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
,
152 Status
= NtCreateDirectoryObject(&ObjectDirHandle
,
153 DIRECTORY_ALL_ACCESS
,
155 if (!NT_SUCCESS(Status
))
157 DPRINT1("NtCreateDirectoryObject() failed (Status %lx)\n", Status
);
161 RtlInitUnicodeString(&DllDosPath
, NULL
);
163 RtlZeroMemory(&QueryTable
,
166 QueryTable
[0].Name
= L
"DllDirectory";
167 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
;
168 QueryTable
[0].EntryContext
= &DllDosPath
;
170 Status
= RtlQueryRegistryValues(RTL_REGISTRY_CONTROL
,
171 L
"\\Session Manager\\KnownDlls",
174 SmSystemEnvironment
);
175 if (!NT_SUCCESS(Status
))
177 DPRINT1("RtlQueryRegistryValues() failed (Status %lx)\n", Status
);
181 DPRINT("DllDosPath: '%wZ'\n", &DllDosPath
);
183 if (!RtlDosPathNameToNtPathName_U(DllDosPath
.Buffer
,
188 DPRINT1("RtlDosPathNameToNtPathName_U() failed\n");
189 return STATUS_OBJECT_NAME_INVALID
;
192 DPRINT("DllNtPath: '%wZ'\n", &DllNtPath
);
194 /* Open the dll path directory */
195 InitializeObjectAttributes(&ObjectAttributes
,
197 OBJ_CASE_INSENSITIVE
,
200 Status
= NtOpenFile(&FileDirHandle
,
201 SYNCHRONIZE
| FILE_READ_DATA
,
204 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
205 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_DIRECTORY_FILE
);
206 if (!NT_SUCCESS(Status
))
208 DPRINT1("NtOpenFile(%wZ) failed (Status %lx)\n", &DllNtPath
, Status
);
212 /* Link 'KnownDllPath' the dll path directory */
213 RtlInitUnicodeString(&Name
,
215 InitializeObjectAttributes(&ObjectAttributes
,
217 OBJ_PERMANENT
| OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
,
220 Status
= NtCreateSymbolicLinkObject(&SymlinkHandle
,
221 SYMBOLIC_LINK_ALL_ACCESS
,
224 if (!NT_SUCCESS(Status
))
226 DPRINT1("NtCreateSymbolicLink() failed (Status %lx)\n", Status
);
230 NtClose(SymlinkHandle
);
232 RtlZeroMemory(&QueryTable
,
235 QueryTable
[0].QueryRoutine
= SmpKnownDllsQueryRoutine
;
236 QueryTable
[0].EntryContext
= ObjectDirHandle
;
238 Status
= RtlQueryRegistryValues(RTL_REGISTRY_CONTROL
,
239 L
"\\Session Manager\\KnownDlls",
241 (PVOID
)FileDirHandle
,
243 if (!NT_SUCCESS(Status
))
245 DPRINT1("RtlQueryRegistryValues() failed (Status %lx)\n", Status
);
248 DPRINT("SmLoadKnownDlls() done\n");