dmime/tests: Add more GetTrack() tests.
[wine.git] / dlls / wbemprox / security.c
blob3ad7321a60ca24c84cad1b5c2247b67cc7a1bbc9
1 /*
2 * __SystemSecurity implementation
4 * Copyright 2014 Vincent Povirk for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wbemcli.h"
28 #include "iads.h"
30 #include "wine/debug.h"
31 #include "wbemprox_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
35 static HRESULT to_byte_array( void *data, DWORD size, VARIANT *var )
37 SAFEARRAY *sa;
38 void *sadata;
39 HRESULT hr;
41 if (!(sa = SafeArrayCreateVector( VT_UI1, 0, size ))) return E_OUTOFMEMORY;
43 hr = SafeArrayAccessData( sa, &sadata );
45 if (SUCCEEDED(hr))
47 memcpy( sadata, data, size );
49 SafeArrayUnaccessData( sa );
51 else
53 SafeArrayDestroy( sa );
54 return hr;
57 set_variant( VT_UI1|VT_ARRAY, 0, sa, var );
58 return S_OK;
61 static HRESULT get_sd( SECURITY_DESCRIPTOR **sd, DWORD *size )
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;
77 sid_size = sizeof(sid_admin_buffer);
78 CreateWellKnownSid( WinBuiltinAdministratorsSid, NULL, sid_admin, &sid_size );
80 sid_size = sizeof(sid_network_buffer);
81 CreateWellKnownSid( WinNetworkServiceSid, NULL, sid_network, &sid_size );
83 sid_size = sizeof(sid_local_buffer);
84 CreateWellKnownSid( WinLocalServiceSid, NULL, sid_local, &sid_size );
86 sid_size = sizeof(sid_users_buffer);
87 CreateWellKnownSid( WinAuthenticatedUserSid, NULL, sid_users, &sid_size );
89 InitializeAcl( acl, sizeof(acl_buffer), ACL_REVISION );
91 AddAccessAllowedAceEx( acl, ACL_REVISION, CONTAINER_INHERIT_ACE|INHERITED_ACE,
92 ADS_RIGHT_DS_CREATE_CHILD|ADS_RIGHT_DS_DELETE_CHILD|ADS_RIGHT_ACTRL_DS_LIST|ADS_RIGHT_DS_SELF|
93 ADS_RIGHT_DS_READ_PROP|ADS_RIGHT_DS_WRITE_PROP|READ_CONTROL|WRITE_DAC,
94 sid_admin );
96 AddAccessAllowedAceEx( acl, ACL_REVISION, CONTAINER_INHERIT_ACE|INHERITED_ACE,
97 ADS_RIGHT_DS_CREATE_CHILD|ADS_RIGHT_DS_DELETE_CHILD|ADS_RIGHT_DS_READ_PROP,
98 sid_network );
100 AddAccessAllowedAceEx( acl, ACL_REVISION, CONTAINER_INHERIT_ACE|INHERITED_ACE,
101 ADS_RIGHT_DS_CREATE_CHILD|ADS_RIGHT_DS_DELETE_CHILD|ADS_RIGHT_DS_READ_PROP,
102 sid_local );
104 AddAccessAllowedAceEx( acl, ACL_REVISION, CONTAINER_INHERIT_ACE|INHERITED_ACE,
105 ADS_RIGHT_DS_CREATE_CHILD|ADS_RIGHT_DS_DELETE_CHILD|ADS_RIGHT_DS_READ_PROP,
106 sid_users );
108 InitializeSecurityDescriptor( &absolute_sd, SECURITY_DESCRIPTOR_REVISION );
110 SetSecurityDescriptorOwner( &absolute_sd, sid_admin, TRUE );
111 SetSecurityDescriptorGroup( &absolute_sd, sid_admin, TRUE );
112 SetSecurityDescriptorDacl( &absolute_sd, TRUE, acl, TRUE );
114 *size = GetSecurityDescriptorLength( &absolute_sd );
116 *sd = HeapAlloc( GetProcessHeap(), 0, *size );
117 if (!*sd)
118 hr = E_OUTOFMEMORY;
120 if (SUCCEEDED(hr))
122 if (!MakeSelfRelativeSD(&absolute_sd, *sd, size)) {
123 HeapFree( GetProcessHeap(), 0, *sd );
124 *sd = NULL;
125 hr = E_FAIL;
129 return hr;
132 HRESULT security_get_sd( IWbemClassObject *obj, IWbemClassObject *in, IWbemClassObject **out )
134 VARIANT var_sd, retval;
135 IWbemClassObject *sig, *out_params = NULL;
136 HRESULT hr, ret;
137 SECURITY_DESCRIPTOR *sd;
138 DWORD sd_size;
140 TRACE("%p, %p\n", in, out);
142 hr = create_signature( class_systemsecurityW, method_getsdW, PARAM_OUT, &sig );
144 if (SUCCEEDED(hr))
146 hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
148 IWbemClassObject_Release( sig );
151 if (SUCCEEDED(hr))
153 ret = get_sd( &sd, &sd_size );
155 if (SUCCEEDED(ret))
157 VariantInit( &var_sd );
159 hr = to_byte_array( sd, sd_size, &var_sd );
161 if (SUCCEEDED(hr))
162 hr = IWbemClassObject_Put( out_params, param_sdW, 0, &var_sd, CIM_UINT8|CIM_FLAG_ARRAY );
164 HeapFree( GetProcessHeap(), 0, sd );
165 VariantClear( &var_sd );
168 if (SUCCEEDED(hr))
170 set_variant( VT_UI4, ret, NULL, &retval );
171 hr = IWbemClassObject_Put( out_params, param_returnvalueW, 0, &retval, CIM_UINT32 );
174 if (SUCCEEDED(hr) && out)
176 *out = out_params;
177 IWbemClassObject_AddRef( out_params );
180 IWbemClassObject_Release( out_params );
183 return hr;
187 HRESULT security_set_sd( IWbemClassObject *obj, IWbemClassObject *in, IWbemClassObject **out )
189 VARIANT retval;
190 IWbemClassObject *sig, *out_params = NULL;
191 HRESULT hr;
193 FIXME("stub\n");
195 hr = create_signature( class_systemsecurityW, method_setsdW, PARAM_OUT, &sig );
197 if (SUCCEEDED(hr))
199 hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
201 IWbemClassObject_Release( sig );
204 if (SUCCEEDED(hr))
206 set_variant( VT_UI4, S_OK, NULL, &retval );
207 hr = IWbemClassObject_Put( out_params, param_returnvalueW, 0, &retval, CIM_UINT32 );
209 if (SUCCEEDED(hr) && out)
211 *out = out_params;
212 IWbemClassObject_AddRef( out_params );
215 IWbemClassObject_Release( out_params );
218 return hr;