ReactOS 0.4.15-dev-7842-g558ab78
misc.c File Reference
#include "precomp.h"
#include <ndk/sefuncs.h>
#include <debug.h>
Include dependency graph for misc.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

LPWSTR AppendBackslash (LPWSTR String)
 
PSECURITY_DESCRIPTOR CreateDefaultSecurityDescriptor (VOID)
 
BOOL LoadDynamicImports (PDYN_MODULE Module, PDYN_FUNCS DynFuncs)
 
VOID UnloadDynamicImports (PDYN_FUNCS DynFuncs)
 

Variables

SID_IDENTIFIER_AUTHORITY LocalSystemAuthority = {SECURITY_NT_AUTHORITY}
 
SID_IDENTIFIER_AUTHORITY WorldAuthority = {SECURITY_WORLD_SID_AUTHORITY}
 
DYN_MODULE DynOle32
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 31 of file misc.c.

Function Documentation

◆ AppendBackslash()

LPWSTR AppendBackslash ( LPWSTR  String)

Definition at line 40 of file misc.c.

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}
#define lstrlenW
Definition: compat.h:750
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define L(x)
Definition: ntvdm.h:50
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by CopyDirectory().

◆ CreateDefaultSecurityDescriptor()

PSECURITY_DESCRIPTOR CreateDefaultSecurityDescriptor ( VOID  )

Definition at line 57 of file misc.c.

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}
#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
SID_IDENTIFIER_AUTHORITY WorldAuthority
Definition: misc.c:35
SID_IDENTIFIER_AUTHORITY LocalSystemAuthority
Definition: misc.c:34
static const WCHAR Cleanup[]
Definition: register.c:80
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:1593
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL _Inout_ PULONG DaclSize
Definition: rtlfuncs.h:1594
#define GENERIC_ALL
Definition: nt_native.h:92
#define GENERIC_EXECUTE
Definition: nt_native.h:91
BOOL WINAPI SetSecurityDescriptorDacl(PSECURITY_DESCRIPTOR pSecurityDescriptor, BOOL bDaclPresent, PACL pDacl, BOOL bDaclDefaulted)
Definition: sec.c:262
#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
#define LMEM_FIXED
Definition: winbase.h:368
#define SECURITY_BUILTIN_DOMAIN_RID
Definition: setypes.h:581
#define SECURITY_WORLD_RID
Definition: setypes.h:541
#define SECURITY_LOCAL_SYSTEM_RID
Definition: setypes.h:574
#define SECURITY_DESCRIPTOR_REVISION
Definition: setypes.h:58
#define ACL_REVISION
Definition: setypes.h:39
#define DOMAIN_ALIAS_RID_ADMINS
Definition: setypes.h:652

Referenced by EnterCriticalPolicySection(), and RegisterGPNotification().

◆ LoadDynamicImports()

BOOL LoadDynamicImports ( PDYN_MODULE  Module,
PDYN_FUNCS  DynFuncs 
)

Definition at line 223 of file misc.c.

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}
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
#define LoadLibraryW(x)
Definition: compat.h:747
HMODULE hModule
Definition: internal.h:49
union _DYN_FUNCS::@564 fn
PVOID foo
Definition: internal.h:52
LPWSTR Library
Definition: internal.h:64
LPSTR Functions[]
Definition: internal.h:65
HANDLE HMODULE
Definition: typedefs.h:77
static GLenum _GLUfuncptr fn
Definition: wgl_font.c:159
#define ZeroMemory
Definition: winbase.h:1712
char * LPSTR
Definition: xmlstorage.h:182

Referenced by AddDesktopItemW(), and AddItemW().

◆ UnloadDynamicImports()

VOID UnloadDynamicImports ( PDYN_FUNCS  DynFuncs)

Definition at line 259 of file misc.c.

260{
261 if (DynFuncs->hModule)
262 {
263 FreeLibrary(DynFuncs->hModule);
264 DynFuncs->hModule = (HMODULE)0;
265 }
266}

Referenced by AddDesktopItemW(), and AddItemW().

Variable Documentation

◆ DynOle32

DYN_MODULE DynOle32
Initial value:
=
{
L"ole32.dll",
{
"CoInitialize",
"CoCreateInstance",
"CoUninitialize",
}
}

Definition at line 204 of file misc.c.

Referenced by AddDesktopItemW(), and AddItemW().

◆ LocalSystemAuthority

Definition at line 34 of file misc.c.

Referenced by CheckForGuestsAndAdmins(), and CreateDefaultSecurityDescriptor().

◆ WorldAuthority

Definition at line 35 of file misc.c.

Referenced by CreateDefaultSecurityDescriptor().