ReactOS  0.4.14-dev-376-gaedba84
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 {
42  ULONG Length;
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 }
static WCHAR String[]
Definition: stringtable.c:55
#define lstrlenW
Definition: compat.h:415
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
static const WCHAR L[]
Definition: oid.c:1250
unsigned int ULONG
Definition: retypes.h:1

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,
77  &LocalSystemSid) ||
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 
115  (SIZE_T)DaclSize + sizeof(SECURITY_DESCRIPTOR));
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,
132  (DWORD)DaclSize,
133  ACL_REVISION))
134  {
135  DPRINT1("Failed to initialize the DACL of the default security descriptor\n");
136  goto Cleanup;
137  }
138 
139  /* add the SYSTEM Ace */
141  ACL_REVISION,
142  GENERIC_ALL,
144  {
145  DPRINT1("Failed to add the SYSTEM ACE\n");
146  goto Cleanup;
147  }
148 
149  /* add the Administrators Ace */
151  ACL_REVISION,
152  GENERIC_ALL,
153  AdministratorsSid))
154  {
155  DPRINT1("Failed to add the Administrators ACE\n");
156  goto Cleanup;
157  }
158 
159  /* add the Everyone Ace */
161  ACL_REVISION,
163  EveryoneSid))
164  {
165  DPRINT1("Failed to add the Everyone ACE\n");
166  goto Cleanup;
167  }
168 
169  /* set the DACL */
170  if (!SetSecurityDescriptorDacl(pSD,
171  TRUE,
172  Dacl,
173  FALSE))
174  {
175  DPRINT1("Failed to set the DACL of the default security descriptor\n");
176 
177 Cleanup:
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 }
struct _SECURITY_DESCRIPTOR * PSECURITY_DESCRIPTOR
Definition: security.c:97
#define GENERIC_ALL
Definition: nt_native.h:92
#define SECURITY_LOCAL_SYSTEM_RID
Definition: setypes.h:546
#define TRUE
Definition: types.h:120
BOOL WINAPI InitializeAcl(PACL pAcl, DWORD nAclLength, DWORD dwAclRevision)
Definition: security.c:885
BOOL WINAPI InitializeSecurityDescriptor(PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD dwRevision)
Definition: security.c:808
BOOL WINAPI AddAccessAllowedAce(PACL pAcl, DWORD dwAceRevision, DWORD AccessMask, PSID pSid)
Definition: security.c:918
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define SECURITY_DESCRIPTOR_REVISION
Definition: setypes.h:58
PVOID WINAPI FreeSid(PSID pSid)
Definition: security.c:577
struct _ACL ACL
smooth NULL
Definition: ftsmooth.c:416
struct _ACL * PACL
Definition: security.c:104
#define LMEM_FIXED
Definition: winbase.h:349
#define SECURITY_BUILTIN_DOMAIN_RID
Definition: setypes.h:553
DWORD WINAPI GetLengthSid(PSID pSid)
Definition: security.c:798
PSID LocalSystemSid
Definition: globals.c:16
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SECURITY_WORLD_RID
Definition: setypes.h:513
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL Dacl
Definition: rtlfuncs.h:1553
static const WCHAR Cleanup[]
Definition: register.c:80
struct _SECURITY_DESCRIPTOR SECURITY_DESCRIPTOR
ULONG_PTR SIZE_T
Definition: typedefs.h:78
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
BOOL WINAPI SetSecurityDescriptorDacl(PSECURITY_DESCRIPTOR pSecurityDescriptor, BOOL bDaclPresent, PACL pDacl, BOOL bDaclDefaulted)
Definition: sec.c:262
#define DPRINT1
Definition: precomp.h:8
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL _Inout_ PULONG DaclSize
Definition: rtlfuncs.h:1553
#define ACL_REVISION
Definition: setypes.h:39
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
SID_IDENTIFIER_AUTHORITY WorldAuthority
Definition: misc.c:35
#define GENERIC_EXECUTE
Definition: nt_native.h:91
#define DOMAIN_ALIAS_RID_ADMINS
Definition: setypes.h:624
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:553
SID_IDENTIFIER_AUTHORITY LocalSystemAuthority
Definition: misc.c:34

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 TRUE
Definition: types.h:120
static GLenum _GLUfuncptr fn
Definition: wgl_font.c:159
#define ZeroMemory
Definition: winbase.h:1642
char * LPSTR
Definition: xmlstorage.h:182
LPWSTR Library
Definition: internal.h:64
#define LoadLibraryW(x)
Definition: compat.h:412
smooth NULL
Definition: ftsmooth.c:416
LPSTR Functions[]
Definition: internal.h:65
#define FreeLibrary(x)
Definition: compat.h:413
PVOID foo
Definition: internal.h:52
HANDLE HMODULE
Definition: typedefs.h:75
#define GetProcAddress(x, y)
Definition: compat.h:418
HMODULE hModule
Definition: internal.h:49
union _DYN_FUNCS::@549 fn

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 }
#define FreeLibrary(x)
Definition: compat.h:413
HANDLE HMODULE
Definition: typedefs.h:75
HMODULE hModule
Definition: internal.h:49

Referenced by AddDesktopItemW(), and AddItemW().

Variable Documentation

◆ DynOle32

DYN_MODULE DynOle32
Initial value:
=
{
L"ole32.dll",
{
"CoInitialize",
"CoCreateInstance",
"CoUninitialize",
}
}
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR L[]
Definition: oid.c:1250

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().