ReactOS 0.4.16-dev-197-g92996da
misc.c
Go to the documentation of this file.
1/*
2 * ReactOS kernel
3 * Copyright (C) 2004 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19/*
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS system libraries
22 * FILE: dll/win32/userenv/misc.c
23 * PURPOSE: User profile code
24 * PROGRAMMER: Eric Kohl
25 */
26
27#include "precomp.h"
28
29#include <ndk/sefuncs.h>
30
31#define NDEBUG
32#include <debug.h>
33
36
37/* FUNCTIONS ***************************************************************/
38
41{
43
45 if (String[Length - 1] != L'\\')
46 {
47 String[Length] = L'\\';
48 Length++;
49 String[Length] = (WCHAR)0;
50 }
51
52 return &String[Length];
53}
54
55
58{
60 PSID AdministratorsSid = NULL;
61 PSID EveryoneSid = NULL;
62 PACL Dacl;
65
66 /* create the SYSTEM, Administrators and Everyone SIDs */
68 1,
70 0,
71 0,
72 0,
73 0,
74 0,
75 0,
76 0,
79 2,
82 0,
83 0,
84 0,
85 0,
86 0,
87 0,
88 &AdministratorsSid) ||
90 1,
92 0,
93 0,
94 0,
95 0,
96 0,
97 0,
98 0,
99 &EveryoneSid))
100 {
101 DPRINT1("Failed initializing the SIDs for the default security descriptor (0x%p, 0x%p, 0x%p)\n",
102 LocalSystemSid, AdministratorsSid, EveryoneSid);
103 goto Cleanup;
104 }
105
106 /* allocate the security descriptor and DACL */
107 DaclSize = sizeof(ACL) +
109 GetLengthSid(AdministratorsSid) +
110 GetLengthSid(EveryoneSid)) +
112 SidStart)));
113
116 if (pSD == NULL)
117 {
118 DPRINT1("Failed to allocate the default security descriptor and ACL\n");
119 goto Cleanup;
120 }
121
124 {
125 DPRINT1("Failed to initialize the default security descriptor\n");
126 goto Cleanup;
127 }
128
129 /* initialize and build the DACL */
130 Dacl = (PACL)((ULONG_PTR)pSD + sizeof(SECURITY_DESCRIPTOR));
131 if (!InitializeAcl(Dacl,
134 {
135 DPRINT1("Failed to initialize the DACL of the default security descriptor\n");
136 goto Cleanup;
137 }
138
139 /* add the SYSTEM Ace */
144 {
145 DPRINT1("Failed to add the SYSTEM ACE\n");
146 goto Cleanup;
147 }
148
149 /* add the Administrators Ace */
153 AdministratorsSid))
154 {
155 DPRINT1("Failed to add the Administrators ACE\n");
156 goto Cleanup;
157 }
158
159 /* add the Everyone Ace */
163 EveryoneSid))
164 {
165 DPRINT1("Failed to add the Everyone ACE\n");
166 goto Cleanup;
167 }
168
169 /* set the DACL */
171 TRUE,
172 Dacl,
173 FALSE))
174 {
175 DPRINT1("Failed to set the DACL of the default security descriptor\n");
176
177Cleanup:
178 if (pSD != NULL)
179 {
180 LocalFree((HLOCAL)pSD);
181 pSD = NULL;
182 }
183 }
184
185 if (LocalSystemSid != NULL)
186 {
188 }
189 if (AdministratorsSid != NULL)
190 {
191 FreeSid(AdministratorsSid);
192 }
193 if (EveryoneSid != NULL)
194 {
195 FreeSid(EveryoneSid);
196 }
197
198 return pSD;
199}
200
201/* Dynamic DLL loading interface **********************************************/
202
203/* OLE32.DLL import table */
205{
206 L"ole32.dll",
207 {
208 "CoInitialize",
209 "CoCreateInstance",
210 "CoUninitialize",
211 NULL
212 }
213};
214
215
216/*
217 * Use this function to load functions from other modules. We cannot statically
218 * link to e.g. ole32.dll because those dlls would get loaded on startup with
219 * winlogon and they may try to register classes etc when not even a window station
220 * has been created!
221 */
222BOOL
224 PDYN_FUNCS DynFuncs)
225{
226 LPSTR *fname;
227 PVOID *fn;
228
229 ZeroMemory(DynFuncs, sizeof(DYN_FUNCS));
230
231 DynFuncs->hModule = LoadLibraryW(Module->Library);
232 if (!DynFuncs->hModule)
233 {
234 return FALSE;
235 }
236
237 fn = &DynFuncs->fn.foo;
238
239 /* load the imports */
240 for (fname = Module->Functions; *fname != NULL; fname++)
241 {
242 *fn = GetProcAddress(DynFuncs->hModule, *fname);
243 if (*fn == NULL)
244 {
245 FreeLibrary(DynFuncs->hModule);
246 DynFuncs->hModule = (HMODULE)0;
247
248 return FALSE;
249 }
250
251 fn++;
252 }
253
254 return TRUE;
255}
256
257
258VOID
260{
261 if (DynFuncs->hModule)
262 {
263 FreeLibrary(DynFuncs->hModule);
264 DynFuncs->hModule = (HMODULE)0;
265 }
266}
267
268/* EOF */
#define DPRINT1
Definition: precomp.h:8
PSID LocalSystemSid
Definition: globals.c:16
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL WINAPI AllocateAndInitializeSid(PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, BYTE nSubAuthorityCount, DWORD nSubAuthority0, DWORD nSubAuthority1, DWORD nSubAuthority2, DWORD nSubAuthority3, DWORD nSubAuthority4, DWORD nSubAuthority5, DWORD nSubAuthority6, DWORD nSubAuthority7, PSID *pSid)
Definition: security.c:674
BOOL WINAPI InitializeAcl(PACL pAcl, DWORD nAclLength, DWORD dwAclRevision)
Definition: security.c:1006
BOOL WINAPI InitializeSecurityDescriptor(PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD dwRevision)
Definition: security.c:929
BOOL WINAPI AddAccessAllowedAce(PACL pAcl, DWORD dwAceRevision, DWORD AccessMask, PSID pSid)
Definition: security.c:1039
DWORD WINAPI GetLengthSid(PSID pSid)
Definition: security.c:919
PVOID WINAPI FreeSid(PSID pSid)
Definition: security.c:698
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
#define LoadLibraryW(x)
Definition: compat.h:747
#define lstrlenW
Definition: compat.h:750
SID_IDENTIFIER_AUTHORITY WorldAuthority
Definition: misc.c:35
LPWSTR AppendBackslash(LPWSTR String)
Definition: misc.c:40
PSECURITY_DESCRIPTOR CreateDefaultSecurityDescriptor(VOID)
Definition: misc.c:57
DYN_MODULE DynOle32
Definition: misc.c:204
BOOL LoadDynamicImports(PDYN_MODULE Module, PDYN_FUNCS DynFuncs)
Definition: misc.c:223
SID_IDENTIFIER_AUTHORITY LocalSystemAuthority
Definition: misc.c:34
VOID UnloadDynamicImports(PDYN_FUNCS DynFuncs)
Definition: misc.c:259
static const WCHAR Cleanup[]
Definition: register.c:80
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
struct _SECURITY_DESCRIPTOR * PSECURITY_DESCRIPTOR
Definition: security.c:98
struct _ACL ACL
struct _SECURITY_DESCRIPTOR SECURITY_DESCRIPTOR
struct _ACL * PACL
Definition: security.c:105
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL Dacl
Definition: rtlfuncs.h:1605
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL _Inout_ PULONG DaclSize
Definition: rtlfuncs.h:1606
#define GENERIC_ALL
Definition: nt_native.h:92
#define GENERIC_EXECUTE
Definition: nt_native.h:91
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define L(x)
Definition: ntvdm.h:50
BOOL WINAPI SetSecurityDescriptorDacl(PSECURITY_DESCRIPTOR pSecurityDescriptor, BOOL bDaclPresent, PACL pDacl, BOOL bDaclDefaulted)
Definition: sec.c:262
union _DYN_FUNCS::@568 fn
HMODULE hModule
Definition: internal.h:49
PVOID foo
Definition: internal.h:52
LPWSTR Library
Definition: internal.h:64
LPSTR Functions[]
Definition: internal.h:65
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG_PTR
Definition: typedefs.h:65
HANDLE HMODULE
Definition: typedefs.h:77
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
static GLenum _GLUfuncptr fn
Definition: wgl_font.c:159
#define ZeroMemory
Definition: winbase.h:1736
#define LMEM_FIXED
Definition: winbase.h:393
#define SECURITY_BUILTIN_DOMAIN_RID
Definition: setypes.h:581
#define SECURITY_WORLD_SID_AUTHORITY
Definition: setypes.h:527
#define SECURITY_WORLD_RID
Definition: setypes.h:541
#define SECURITY_LOCAL_SYSTEM_RID
Definition: setypes.h:574
#define SECURITY_NT_AUTHORITY
Definition: setypes.h:554
#define SECURITY_DESCRIPTOR_REVISION
Definition: setypes.h:58
#define ACL_REVISION
Definition: setypes.h:39
#define DOMAIN_ALIAS_RID_ADMINS
Definition: setypes.h:652
char * LPSTR
Definition: xmlstorage.h:182
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184