ReactOS  0.4.15-dev-1068-g467feb9
security.c File Reference
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "wbemcli.h"
#include "iads.h"
#include "wine/debug.h"
#include "wbemprox_private.h"
Include dependency graph for security.c:

Go to the source code of this file.

Macros

#define COBJMACROS
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (wbemprox)
 
static HRESULT to_byte_array (void *data, DWORD size, VARIANT *var)
 
static HRESULT get_sd (SECURITY_DESCRIPTOR **sd, DWORD *size)
 
HRESULT security_get_sd (IWbemClassObject *obj, IWbemClassObject *in, IWbemClassObject **out)
 
HRESULT security_set_sd (IWbemClassObject *obj, IWbemClassObject *in, IWbemClassObject **out)
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 21 of file security.c.

Function Documentation

◆ get_sd()

static HRESULT get_sd ( SECURITY_DESCRIPTOR **  sd,
DWORD size 
)
static

Definition at line 61 of file security.c.

62 {
63  BYTE sid_admin_buffer[SECURITY_MAX_SID_SIZE];
64  SID *sid_admin = (SID*)sid_admin_buffer;
65  BYTE sid_network_buffer[SECURITY_MAX_SID_SIZE];
66  SID *sid_network = (SID*)sid_network_buffer;
67  BYTE sid_local_buffer[SECURITY_MAX_SID_SIZE];
68  SID *sid_local = (SID*)sid_local_buffer;
69  BYTE sid_users_buffer[SECURITY_MAX_SID_SIZE];
70  SID *sid_users = (SID*)sid_users_buffer;
71  BYTE acl_buffer[sizeof(ACL) + 4 * (sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD) + SECURITY_MAX_SID_SIZE)];
72  ACL *acl = (ACL*)acl_buffer;
73  DWORD sid_size;
74  SECURITY_DESCRIPTOR absolute_sd;
75  HRESULT hr = S_OK;
76 
77  sid_size = sizeof(sid_admin_buffer);
78  CreateWellKnownSid( WinBuiltinAdministratorsSid, NULL, sid_admin, &sid_size );
79 
80  sid_size = sizeof(sid_network_buffer);
81  CreateWellKnownSid( WinNetworkServiceSid, NULL, sid_network, &sid_size );
82 
83  sid_size = sizeof(sid_local_buffer);
84  CreateWellKnownSid( WinLocalServiceSid, NULL, sid_local, &sid_size );
85 
86  sid_size = sizeof(sid_users_buffer);
87  CreateWellKnownSid( WinAuthenticatedUserSid, NULL, sid_users, &sid_size );
88 
89  InitializeAcl( acl, sizeof(acl_buffer), ACL_REVISION );
90 
94  sid_admin );
95 
98  sid_network );
99 
102  sid_local );
103 
106  sid_users );
107 
109 
110  SetSecurityDescriptorOwner( &absolute_sd, sid_admin, TRUE );
111  SetSecurityDescriptorGroup( &absolute_sd, sid_admin, TRUE );
112  SetSecurityDescriptorDacl( &absolute_sd, TRUE, acl, TRUE );
113 
114  *size = GetSecurityDescriptorLength( &absolute_sd );
115 
116  *sd = HeapAlloc( GetProcessHeap(), 0, *size );
117  if (!*sd)
118  hr = E_OUTOFMEMORY;
119 
120  if (SUCCEEDED(hr))
121  {
122  if (!MakeSelfRelativeSD(&absolute_sd, *sd, size)) {
123  HeapFree( GetProcessHeap(), 0, *sd );
124  *sd = NULL;
125  hr = E_FAIL;
126  }
127  }
128 
129  return hr;
130 }
static DWORD
Definition: security.c:70
BOOL WINAPI MakeSelfRelativeSD(PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor, PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor, LPDWORD lpdwBufferLength)
Definition: sec.c:214
BOOL WINAPI SetSecurityDescriptorDacl(PSECURITY_DESCRIPTOR pSecurityDescriptor, BOOL bDaclPresent, PACL pDacl, BOOL bDaclDefaulted)
Definition: sec.c:262
#define SECURITY_MAX_SID_SIZE
Definition: setypes.h:458
HRESULT hr
Definition: shlfolder.c:183
BOOL WINAPI InitializeAcl(PACL pAcl, DWORD nAclLength, DWORD dwAclRevision)
Definition: security.c:885
#define TRUE
Definition: types.h:120
BOOL WINAPI InitializeSecurityDescriptor(PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD dwRevision)
Definition: security.c:808
BOOL WINAPI AddAccessAllowedAceEx(PACL pAcl, DWORD dwAceRevision, DWORD AceFlags, DWORD AccessMask, PSID pSid)
Definition: security.c:942
#define E_FAIL
Definition: ddrawi.h:102
BOOL WINAPI SetSecurityDescriptorOwner(PSECURITY_DESCRIPTOR pSecurityDescriptor, PSID pOwner, BOOL bOwnerDefaulted)
Definition: sec.c:312
#define SECURITY_DESCRIPTOR_REVISION
Definition: setypes.h:58
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
BOOL WINAPI SetSecurityDescriptorGroup(PSECURITY_DESCRIPTOR pSecurityDescriptor, PSID pGroup, BOOL bGroupDefaulted)
Definition: sec.c:288
struct _ACL ACL
smooth NULL
Definition: ftsmooth.c:416
#define CONTAINER_INHERIT_ACE
Definition: setypes.h:715
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:484
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LONG HRESULT
Definition: typedefs.h:79
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WRITE_DAC
Definition: nt_native.h:59
#define READ_CONTROL
Definition: nt_native.h:58
static const WCHAR sd[]
Definition: suminfo.c:287
unsigned char BYTE
Definition: xxhash.c:193
DWORD WINAPI GetSecurityDescriptorLength(PSECURITY_DESCRIPTOR)
#define S_OK
Definition: intsafe.h:51
#define INHERITED_ACE
Definition: ph.h:47
#define ACL_REVISION
Definition: setypes.h:39
BOOL WINAPI CreateWellKnownSid(IN WELL_KNOWN_SID_TYPE WellKnownSidType, IN PSID DomainSid OPTIONAL, OUT PSID pSid, IN OUT DWORD *cbSid)
Definition: security.c:601
#define HeapFree(x, y, z)
Definition: compat.h:483
#define SUCCEEDED(hr)
Definition: intsafe.h:49

Referenced by AddPrinterW(), security_get_sd(), and SetPrinterW().

◆ security_get_sd()

HRESULT security_get_sd ( IWbemClassObject obj,
IWbemClassObject in,
IWbemClassObject **  out 
)

Definition at line 132 of file security.c.

133 {
134  VARIANT var_sd, retval;
136  HRESULT hr, ret;
138  DWORD sd_size;
139 
140  TRACE("%p, %p\n", in, out);
141 
143 
144  if (SUCCEEDED(hr))
145  {
146  hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
147 
148  IWbemClassObject_Release( sig );
149  }
150 
151  if (SUCCEEDED(hr))
152  {
153  ret = get_sd( &sd, &sd_size );
154 
155  if (SUCCEEDED(ret))
156  {
157  VariantInit( &var_sd );
158 
159  hr = to_byte_array( sd, sd_size, &var_sd );
160 
161  if (SUCCEEDED(hr))
162  hr = IWbemClassObject_Put( out_params, param_sdW, 0, &var_sd, CIM_UINT8|CIM_FLAG_ARRAY );
163 
164  HeapFree( GetProcessHeap(), 0, sd );
165  VariantClear( &var_sd );
166  }
167 
168  if (SUCCEEDED(hr))
169  {
170  set_variant( VT_UI4, ret, NULL, &retval );
171  hr = IWbemClassObject_Put( out_params, param_returnvalueW, 0, &retval, CIM_UINT32 );
172  }
173 
174  if (SUCCEEDED(hr) && out)
175  {
176  *out = out_params;
177  IWbemClassObject_AddRef( out_params );
178  }
179 
180  IWbemClassObject_Release( out_params );
181  }
182 
183  return hr;
184 }
static HRESULT get_sd(SECURITY_DESCRIPTOR **sd, DWORD *size)
Definition: security.c:61
static const WCHAR method_getsdW[]
HRESULT hr
Definition: shlfolder.c:183
static const WCHAR class_systemsecurityW[]
static HRESULT to_byte_array(void *data, DWORD size, VARIANT *var)
Definition: security.c:35
void WINAPI VariantInit(VARIANTARG *pVarg)
Definition: variant.c:568
smooth NULL
Definition: ftsmooth.c:416
void set_variant(VARTYPE type, LONGLONG val, void *val_ptr, VARIANT *ret)
Definition: query.c:1093
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:484
LONG HRESULT
Definition: typedefs.h:79
static FILE * out
Definition: regtests2xml.c:44
static void out_params(void)
Definition: nanoxwin.c:1413
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR sd[]
Definition: suminfo.c:287
int ret
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:648
static const WCHAR param_sdW[]
GLuint in
Definition: glext.h:9616
HRESULT create_signature(const WCHAR *class, const WCHAR *method, enum param_direction dir, IWbemClassObject **sig)
Definition: class.c:819
static const WCHAR param_returnvalueW[]
#define HeapFree(x, y, z)
Definition: compat.h:483
#define SUCCEEDED(hr)
Definition: intsafe.h:49

◆ security_set_sd()

HRESULT security_set_sd ( IWbemClassObject obj,
IWbemClassObject in,
IWbemClassObject **  out 
)

Definition at line 187 of file security.c.

188 {
189  VARIANT retval;
191  HRESULT hr;
192 
193  FIXME("stub\n");
194 
196 
197  if (SUCCEEDED(hr))
198  {
199  hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
200 
201  IWbemClassObject_Release( sig );
202  }
203 
204  if (SUCCEEDED(hr))
205  {
206  set_variant( VT_UI4, S_OK, NULL, &retval );
207  hr = IWbemClassObject_Put( out_params, param_returnvalueW, 0, &retval, CIM_UINT32 );
208 
209  if (SUCCEEDED(hr) && out)
210  {
211  *out = out_params;
212  IWbemClassObject_AddRef( out_params );
213  }
214 
215  IWbemClassObject_Release( out_params );
216  }
217 
218  return hr;
219 }
HRESULT hr
Definition: shlfolder.c:183
static const WCHAR class_systemsecurityW[]
#define FIXME(fmt,...)
Definition: debug.h:111
smooth NULL
Definition: ftsmooth.c:416
void set_variant(VARTYPE type, LONGLONG val, void *val_ptr, VARIANT *ret)
Definition: query.c:1093
static const WCHAR method_setsdW[]
LONG HRESULT
Definition: typedefs.h:79
static FILE * out
Definition: regtests2xml.c:44
static void out_params(void)
Definition: nanoxwin.c:1413
#define S_OK
Definition: intsafe.h:51
HRESULT create_signature(const WCHAR *class, const WCHAR *method, enum param_direction dir, IWbemClassObject **sig)
Definition: class.c:819
static const WCHAR param_returnvalueW[]
#define SUCCEEDED(hr)
Definition: intsafe.h:49

◆ to_byte_array()

static HRESULT to_byte_array ( void data,
DWORD  size,
VARIANT var 
)
static

Definition at line 35 of file security.c.

36 {
37  SAFEARRAY *sa;
38  void *sadata;
39  HRESULT hr;
40 
41  if (!(sa = SafeArrayCreateVector( VT_UI1, 0, size ))) return E_OUTOFMEMORY;
42 
43  hr = SafeArrayAccessData( sa, &sadata );
44 
45  if (SUCCEEDED(hr))
46  {
47  memcpy( sadata, data, size );
48 
50  }
51  else
52  {
54  return hr;
55  }
56 
58  return S_OK;
59 }
const char * var
Definition: shader.c:5666
HRESULT hr
Definition: shlfolder.c:183
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
HRESULT WINAPI SafeArrayAccessData(SAFEARRAY *psa, void **ppvData)
Definition: safearray.c:1137
void set_variant(VARTYPE type, LONGLONG val, void *val_ptr, VARIANT *ret)
Definition: query.c:1093
GLsizeiptr size
Definition: glext.h:5919
LONG HRESULT
Definition: typedefs.h:79
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
HRESULT WINAPI SafeArrayDestroy(SAFEARRAY *psa)
Definition: safearray.c:1347
SAFEARRAY *WINAPI SafeArrayCreateVector(VARTYPE vt, LONG lLbound, ULONG cElements)
Definition: safearray.c:677
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define S_OK
Definition: intsafe.h:51
static struct sockaddr_in sa
Definition: adnsresfilter.c:69
HRESULT WINAPI SafeArrayUnaccessData(SAFEARRAY *psa)
Definition: safearray.c:1168
#define SUCCEEDED(hr)
Definition: intsafe.h:49

Referenced by security_get_sd().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( wbemprox  )