ReactOS  0.4.11-dev-745-g76daaf9
security.c
Go to the documentation of this file.
1 /*
2  * Regedit ACL Editor for Registry Keys
3  *
4  * Copyright (C) 2004 - 2006 Thomas Weidenmueller <w3seek@reactos.com>
5  *
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.
10  *
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.
15  *
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 Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "regedit.h"
22 
23 #define INITGUID
24 #include <guiddef.h>
25 
26 /* FIXME - shouldn't be defined here... */
27 DEFINE_GUID(IID_IRegKeySecurity, 0x965fc360, 0x16ff, 0x11d0, 0x0091, 0xcb,0x00,0xaa,0x00,0xbb,0xb7,0x23);
28 #if REGEDIT_IMPLEMENT_ISECURITYINFORMATION2
29 DEFINE_GUID(IID_IRegKeySecurity2, 0xc3ccfdb4, 0x6f88, 0x11d2, 0x00a3, 0xce,0x00,0xc0,0x4f,0xb1,0x78,0x2a);
30 #endif
31 
32 /* FIXME: already defined in aclui.h - causing problems when compiling with MSVC/PSDK*/
33 #ifdef _MSC_VER
34 #pragma message ("INVESTIGATE ME")
35 #endif
36 
37 #if 1 //#ifndef _MSC_VER
38 DEFINE_GUID(IID_IEffectivePermission, 0x3853dc76, 0x9f35, 0x407c, 0x0088, 0xa1,0xd1,0x93,0x44,0x36,0x5f,0xbc);
39 DEFINE_GUID(IID_ISecurityObjectTypeInfo, 0xfc3066eb, 0x79ef, 0x444b, 0x0091, 0x11,0xd1,0x8a,0x75,0xeb,0xf2,0xfa);
40 #endif
41 
42 /******************************************************************************
43  Implementation of the IUnknown methods of CRegKeySecurity
44  ******************************************************************************/
45 
46 static __inline PCRegKeySecurity
47 impl_from_ISecurityInformation(struct ISecurityInformation *iface)
48 {
50  lpISecurityInformationVtbl));
51 }
52 
53 #if REGEDIT_IMPLEMENT_ISECURITYINFORMATION2
54 static __inline PCRegKeySecurity
55 impl_from_ISecurityInformation2(struct ISecurityInformation2 *iface)
56 {
58  lpISecurityInformation2Vtbl));
59 }
60 #endif
61 
62 static __inline PCRegKeySecurity
63 impl_from_ISecurityObjectTypeInfo(struct ISecurityObjectTypeInfo *iface)
64 {
66  lpISecurityObjectTypeInfoVtbl));
67 }
68 
69 static __inline PCRegKeySecurity
70 impl_from_IEffectivePermission(struct IEffectivePermission *iface)
71 {
73  lpIEffectivePermissionVtbl));
74 }
75 
76 #define impl_to_interface(impl,iface) (struct iface *)(&(impl)->lp##iface##Vtbl)
77 
78 static __inline ULONG
80 {
81  return (ULONG)InterlockedIncrement((LONG*)&obj->ref);
82 }
83 
84 static __inline ULONG
86 {
87  ULONG Ret;
88 
89  Ret = (ULONG)InterlockedDecrement((LONG*)&obj->ref);
90  if (Ret == 0)
91  {
93  0,
94  obj);
95  }
96 
97  return Ret;
98 }
99 
100 static __inline HRESULT
102  REFIID iid,
103  PVOID *pvObject)
104 {
105  PVOID pvObj = NULL;
106 
107  if (IsEqualGUID(iid,
108  &IID_IRegKeySecurity))
109  {
110  pvObj = (PVOID)impl_to_interface(obj,
111  ISecurityInformation);
112  }
113 #if REGEDIT_IMPLEMENT_ISECURITYINFORMATION2
114  else if (IsEqualGUID(iid,
115  &IID_IRegKeySecurity2))
116  {
117  pvObj = (PVOID)impl_to_interface(obj,
118  ISecurityInformation2);
119  }
120 #endif
121  else if (IsEqualGUID(iid,
122  &IID_IEffectivePermission))
123  {
124  pvObj = (PVOID)impl_to_interface(obj,
125  IEffectivePermission);
126  }
127  else if (IsEqualGUID(iid,
128  &IID_ISecurityObjectTypeInfo))
129  {
130  pvObj = (PVOID)impl_to_interface(obj,
131  ISecurityObjectTypeInfo);
132  }
133 
134  if (pvObj == NULL)
135  {
136  return E_NOINTERFACE;
137  }
138 
139  *pvObject = pvObj;
141 
142  return S_OK;
143 }
144 
145 
146 /******************************************************************************
147  Definition of the ISecurityInformation interface
148  ******************************************************************************/
149 
150 /* IUnknown */
152 ISecurityInformation_fnQueryInterface(struct ISecurityInformation *this,
153  REFIID iid,
154  PVOID *pvObject);
155 
157 ISecurityInformation_fnAddRef(struct ISecurityInformation *this);
158 
160 ISecurityInformation_fnRelease(struct ISecurityInformation *this);
161 
162 /* ISecurityInformation */
164 ISecurityInformation_fnGetObjectInformation(struct ISecurityInformation *this,
165  PSI_OBJECT_INFO pObjectInfo);
166 
168 ISecurityInformation_fnGetSecurity(struct ISecurityInformation *this,
169  SECURITY_INFORMATION RequestedInformation,
170  PSECURITY_DESCRIPTOR* ppSecurityDescriptor,
171  BOOL fDefault);
172 
174 ISecurityInformation_fnSetSecurity(struct ISecurityInformation *this,
175  SECURITY_INFORMATION RequestedInformation,
176  PSECURITY_DESCRIPTOR pSecurityDescriptor);
177 
179 ISecurityInformation_fnGetAccessRights(struct ISecurityInformation *this,
180  const GUID* pguidObjectType,
181  DWORD dwFlags,
182  PSI_ACCESS* ppAccess,
183  ULONG* pcAccesses,
184  ULONG* piDefaultAccess);
185 
187 ISecurityInformation_fnMapGeneric(struct ISecurityInformation *this,
188  const GUID* pguidObjectType,
189  UCHAR* pAceFlags,
190  ACCESS_MASK* pMask);
191 
193 ISecurityInformation_fnGetInheritTypes(struct ISecurityInformation *this,
194  PSI_INHERIT_TYPE* ppInheritTypes,
195  ULONG* pcInheritTypes);
197 ISecurityInformation_fnPropertySheetPageCallback(struct ISecurityInformation *this,
198  HWND hwnd,
199  UINT uMsg,
200  SI_PAGE_TYPE uPage);
201 
203 {
204  /* IUnknown methods */
208 
209  /* ISecurityInformation methods */
217 };
218 
219 #if REGEDIT_IMPLEMENT_ISECURITYINFORMATION2
220 /******************************************************************************
221  Definition of the ISecurityInformation2 interface
222  ******************************************************************************/
223 
224 /* IUnknown */
226 ISecurityInformation2_fnQueryInterface(struct ISecurityInformation2 *this,
227  REFIID iid,
228  PVOID *pvObject);
229 
231 ISecurityInformation2_fnAddRef(struct ISecurityInformation2 *this);
232 
234 ISecurityInformation2_fnRelease(struct ISecurityInformation2 *this);
235 
236 /* ISecurityInformation2 */
237 static BOOL STDMETHODCALLTYPE
238 ISecurityInformation2_fnIsDaclCanonical(struct ISecurityInformation2 *this,
239  PACL pDacl);
240 
242 ISecurityInformation2_fnLookupSids(struct ISecurityInformation2 *this,
243  ULONG cSids,
244  PSID* rgpSids,
245  LPDATAOBJECT* ppdo);
246 
247 static const struct ifaceISecurityInformation2Vbtl vtblISecurityInformation2 =
248 {
249  /* IUnknown methods */
250  ISecurityInformation2_fnQueryInterface,
251  ISecurityInformation2_fnAddRef,
252  ISecurityInformation2_fnRelease,
253 
254  /* ISecurityInformation2 methods */
255  ISecurityInformation2_fnIsDaclCanonical,
256  ISecurityInformation2_fnLookupSids
257 };
258 #endif
259 
260 /******************************************************************************
261  Definition of the IEffectivePermission interface
262  ******************************************************************************/
263 
264 /* IUnknown */
266 IEffectivePermission_fnQueryInterface(struct IEffectivePermission *this,
267  REFIID iid,
268  PVOID *pvObject);
269 
271 IEffectivePermission_fnAddRef(struct IEffectivePermission *this);
272 
274 IEffectivePermission_fnRelease(struct IEffectivePermission *this);
275 
276 /* IEffectivePermission */
278 IEffectivePermission_fnGetEffectivePermission(struct IEffectivePermission *this,
279  const GUID* pguidObjectType,
280  PSID pUserSid,
281  LPCWSTR pszServerName,
283  POBJECT_TYPE_LIST* ppObjectTypeList,
284  ULONG* pcObjectTypeListLength,
285  PACCESS_MASK* ppGrantedAccessList,
286  ULONG* pcGrantedAccessListLength);
287 
289 {
290  /* IUnknown methods */
294 
295  /* IEffectivePermissions methods */
297 };
298 
299 /******************************************************************************
300  Definition of the ISecurityObjectTypeInfo interface
301  ******************************************************************************/
302 
303 /* IUnknown */
305 ISecurityObjectTypeInfo_fnQueryInterface(struct ISecurityObjectTypeInfo *this,
306  REFIID iid,
307  PVOID *pvObject);
308 
310 ISecurityObjectTypeInfo_fnAddRef(struct ISecurityObjectTypeInfo *this);
311 
313 ISecurityObjectTypeInfo_fnRelease(struct ISecurityObjectTypeInfo *this);
314 
315 /* ISecurityObjectTypeInfo */
317 ISecurityObjectTypeInfo_fnGetInheritSource(struct ISecurityObjectTypeInfo *this,
319  PACL pACL,
320  PINHERITED_FROM* ppInheritArray);
321 
323 {
324  /* IUnknown methods */
328 
329  /* ISecurityObjectTypeInfo methods */
331 };
332 
333 
334 /******************************************************************************
335  Implementation of the ISecurityInformation interface
336  ******************************************************************************/
337 
338 static SI_ACCESS RegAccess[] = {
351 };
352 
353 static const DWORD RegDefaultAccess = 1; /* KEY_READ */
354 
356  KEY_READ,
357  KEY_WRITE,
358  KEY_EXECUTE,
360 };
361 
366 };
367 
369 ISecurityInformation_fnQueryInterface(struct ISecurityInformation *this,
370  REFIID iid,
371  PVOID *pvObject)
372 {
373  if (IsEqualGUID(iid,
374  &IID_IUnknown))
375  {
376  *pvObject = (PVOID)this;
378  return S_OK;
379  }
380 
382  iid,
383  pvObject);
384 }
385 
387 ISecurityInformation_fnAddRef(struct ISecurityInformation *this)
388 {
390 }
391 
393 ISecurityInformation_fnRelease(struct ISecurityInformation *this)
394 {
396 }
397 
399 ISecurityInformation_fnGetObjectInformation(struct ISecurityInformation *this,
400  PSI_OBJECT_INFO pObjectInfo)
401 {
403 
404  *pObjectInfo = obj->ObjectInfo;
405  return S_OK;
406 }
407 
409 ISecurityInformation_fnGetSecurity(struct ISecurityInformation *this,
410  SECURITY_INFORMATION RequestedInformation,
411  PSECURITY_DESCRIPTOR* ppSecurityDescriptor,
412  BOOL fDefault)
413 {
415  LONG ErrorCode;
416 
417  ErrorCode = GetNamedSecurityInfoW(obj->szRegKey,
419  RequestedInformation,
420  NULL,
421  NULL,
422  NULL,
423  NULL,
424  ppSecurityDescriptor);
425 
426  return HRESULT_FROM_WIN32(ErrorCode);
427 }
428 
430 ISecurityInformation_fnSetSecurity(struct ISecurityInformation *this,
431  SECURITY_INFORMATION RequestedInformation,
432  PSECURITY_DESCRIPTOR pSecurityDescriptor)
433 {
435 
436  /* FIXME */
437  *obj->Btn = TRUE;
438  return S_OK;
439 }
440 
442 ISecurityInformation_fnGetAccessRights(struct ISecurityInformation *this,
443  const GUID* pguidObjectType,
444  DWORD dwFlags,
445  PSI_ACCESS* ppAccess,
446  ULONG* pcAccesses,
447  ULONG* piDefaultAccess)
448 {
449  *ppAccess = RegAccess;
450  *pcAccesses = COUNT_OF(RegAccess);
451  *piDefaultAccess = RegDefaultAccess;
452  return S_OK;
453 }
454 
456 ISecurityInformation_fnMapGeneric(struct ISecurityInformation *this,
457  const GUID* pguidObjectType,
458  UCHAR* pAceFlags,
459  ACCESS_MASK* pMask)
460 {
461  MapGenericMask(pMask,
462  &RegAccessMasks);
463  *pMask &= ~SYNCHRONIZE;
464  return S_OK;
465 }
466 
468 ISecurityInformation_fnGetInheritTypes(struct ISecurityInformation *this,
469  PSI_INHERIT_TYPE* ppInheritTypes,
470  ULONG* pcInheritTypes)
471 {
473 
474  /* FIXME */
475  if (obj->ObjectInfo.dwFlags & SI_CONTAINER)
476  {
477  *ppInheritTypes = RegInheritTypes;
478  *pcInheritTypes = COUNT_OF(RegInheritTypes);
479  return S_OK;
480  }
481 
482  return E_NOTIMPL;
483 }
484 
486 ISecurityInformation_fnPropertySheetPageCallback(struct ISecurityInformation *this,
487  HWND hwnd,
488  UINT uMsg,
489  SI_PAGE_TYPE uPage)
490 {
491  return S_OK;
492 }
493 
494 #if REGEDIT_IMPLEMENT_ISECURITYINFORMATION2
495 /******************************************************************************
496  Implementation of the ISecurityInformation2 interface
497  ******************************************************************************/
498 
500 ISecurityInformation2_fnQueryInterface(struct ISecurityInformation2 *this,
501  REFIID iid,
502  PVOID *pvObject)
503 {
504  if (IsEqualGUID(iid,
505  &IID_IUnknown))
506  {
507  *pvObject = (PVOID)this;
508  ISecurityInformation2_fnAddRef(this);
509  return S_OK;
510  }
511 
512  return CRegKeySecurity_fnQueryInterface(impl_from_ISecurityInformation2(this),
513  iid,
514  pvObject);
515 }
516 
518 ISecurityInformation2_fnAddRef(struct ISecurityInformation2 *this)
519 {
520  return CRegKeySecurity_fnAddRef(impl_from_ISecurityInformation2(this));
521 }
522 
524 ISecurityInformation2_fnRelease(struct ISecurityInformation2 *this)
525 {
526  return CRegKeySecurity_fnRelease(impl_from_ISecurityInformation2(this));
527 }
528 
529 static BOOL STDMETHODCALLTYPE
530 ISecurityInformation2_fnIsDaclCanonical(struct ISecurityInformation2 *this,
531  PACL pDacl)
532 {
533  /* FIXME */
534  return TRUE;
535 }
536 
538 ISecurityInformation2_fnLookupSids(struct ISecurityInformation2 *this,
539  ULONG cSids,
540  PSID* rgpSids,
541  LPDATAOBJECT* ppdo)
542 {
543  /* FIXME */
544  return E_NOTIMPL;
545 }
546 #endif
547 
548 /******************************************************************************
549  Implementation of the IEffectivePermission interface
550  ******************************************************************************/
551 
553 IEffectivePermission_fnQueryInterface(struct IEffectivePermission *this,
554  REFIID iid,
555  PVOID *pvObject)
556 {
557  if (IsEqualGUID(iid,
558  &IID_IUnknown))
559  {
560  *pvObject = (PVOID)this;
562  return S_OK;
563  }
564 
566  iid,
567  pvObject);
568 }
569 
571 IEffectivePermission_fnAddRef(struct IEffectivePermission *this)
572 {
574 }
575 
577 IEffectivePermission_fnRelease(struct IEffectivePermission *this)
578 {
580 }
581 
583 IEffectivePermission_fnGetEffectivePermission(struct IEffectivePermission *this,
584  const GUID* pguidObjectType,
585  PSID pUserSid,
586  LPCWSTR pszServerName,
588  POBJECT_TYPE_LIST* ppObjectTypeList,
589  ULONG* pcObjectTypeListLength,
590  PACCESS_MASK* ppGrantedAccessList,
591  ULONG* pcGrantedAccessListLength)
592 {
593  PACL Dacl = NULL;
595  PACCESS_MASK GrantedAccessList;
597  TRUSTEE Trustee = {0};
598  static OBJECT_TYPE_LIST DefObjTypeList = {0};
599 
600  *ppObjectTypeList = &DefObjTypeList;
601  *pcObjectTypeListLength = 1;
602 
603  BuildTrusteeWithSid(&Trustee,
604  pUserSid);
605 
607  &DaclPresent,
608  &Dacl,
609  &DaclDefaulted) && DaclPresent)
610  {
611  GrantedAccessList = (PACCESS_MASK)LocalAlloc(LMEM_FIXED,
612  sizeof(ACCESS_MASK));
613  if (GrantedAccessList == NULL)
614  {
615  goto Fail;
616  }
617 
618  ErrorCode = GetEffectiveRightsFromAcl(Dacl,
619  &Trustee,
620  GrantedAccessList);
621  if (ErrorCode == ERROR_SUCCESS)
622  {
623  *ppGrantedAccessList = GrantedAccessList;
624  *pcGrantedAccessListLength = 1;
625  }
626  else
627  LocalFree((HLOCAL)GrantedAccessList);
628  }
629  else
630 Fail:
631  ErrorCode = GetLastError();
632 
633  return HRESULT_FROM_WIN32(ErrorCode);
634 }
635 
636 /******************************************************************************
637  Implementation of the ISecurityObjectTypeInfo interface
638  ******************************************************************************/
639 
641 ISecurityObjectTypeInfo_fnQueryInterface(struct ISecurityObjectTypeInfo *this,
642  REFIID iid,
643  PVOID *pvObject)
644 {
645  if (IsEqualGUID(iid,
646  &IID_IUnknown))
647  {
648  *pvObject = (PVOID)this;
650  return S_OK;
651  }
652 
654  iid,
655  pvObject);
656 }
657 
659 ISecurityObjectTypeInfo_fnAddRef(struct ISecurityObjectTypeInfo *this)
660 {
662 }
663 
665 ISecurityObjectTypeInfo_fnRelease(struct ISecurityObjectTypeInfo *this)
666 {
668 }
669 
671 ISecurityObjectTypeInfo_fnGetInheritSource(struct ISecurityObjectTypeInfo *this,
673  PACL pACL,
674  PINHERITED_FROM* ppInheritArray)
675 {
677  PINHERITED_FROM pif, pif2;
678  SIZE_T pifSize;
679  DWORD ErrorCode, i;
680  LPWSTR lpBuf;
681 
682  pifSize = pACL->AceCount * sizeof(INHERITED_FROM);
683  pif = (PINHERITED_FROM)HeapAlloc(GetProcessHeap(),
684  0,
685  pifSize);
686  if (pif == NULL)
687  {
688  return E_OUTOFMEMORY;
689  }
690 
691  ErrorCode = GetInheritanceSourceW(obj->szRegKey,
693  si,
694  (obj->ObjectInfo.dwFlags & SI_CONTAINER) != 0,
695  NULL,
696  0,
697  pACL,
698  NULL,
699  &RegAccessMasks,
700  pif);
701 
702  if (ErrorCode == ERROR_SUCCESS)
703  {
704  /* Calculate the size of the buffer to return */
705  for (i = 0;
706  i < pACL->AceCount;
707  i++)
708  {
709  if (pif[i].AncestorName != NULL)
710  {
711  pifSize += (wcslen(pif[i].AncestorName) + 1) * sizeof(WCHAR);
712  }
713  }
714 
715  /* Allocate enough space for the array and the strings */
716  pif2 = (PINHERITED_FROM)LocalAlloc(LMEM_FIXED,
717  pifSize);
718  if (pif2 == NULL)
719  {
720  ErrorCode = GetLastError();
721  goto Cleanup;
722  }
723 
724  /* copy the array and strings to the buffer */
725  lpBuf = (LPWSTR)((ULONG_PTR)pif2 + (pACL->AceCount * sizeof(INHERITED_FROM)));
726  for (i = 0;
727  i < pACL->AceCount;
728  i++)
729  {
730  pif2[i].GenerationGap = pif[i].GenerationGap;
731  if (pif[i].AncestorName != NULL)
732  {
733  pif2[i].AncestorName = lpBuf;
734  wcscpy(lpBuf,
735  pif[i].AncestorName);
736  lpBuf += wcslen(pif[i].AncestorName) + 1;
737  }
738  else
739  pif2[i].AncestorName = NULL;
740  }
741 
742  /* return the newly allocated array */
743  *ppInheritArray = pif2;
744  }
745 
746 Cleanup:
748  pACL->AceCount,
749  NULL);
751  0,
752  pif);
753 
754  return HRESULT_FROM_WIN32(ErrorCode);
755 }
756 
757 /******************************************************************************
758  Implementation of the CRegKeySecurity constructor
759  ******************************************************************************/
760 
761 static PCRegKeySecurity
763  HKEY hRootKey,
764  SI_OBJECT_INFO *ObjectInfo,
765  BOOL *Btn)
766 {
768 
772  szRegKey[wcslen(lpRegKey) + 1]));
773  if (obj != NULL)
774  {
775  obj->ref = 1;
777 #if REGEDIT_IMPLEMENT_ISECURITYINFORMATION2
778  obj->lpISecurityInformation2Vtbl = &vtblISecurityInformation2;
779 #endif
782  obj->ObjectInfo = *ObjectInfo;
783  obj->Btn = Btn;
784  obj->hRootKey = hRootKey;
785  wcscpy(obj->szRegKey,
786  lpRegKey);
787  }
788  else
790 
791  return obj;
792 }
793 
794 /******************************************************************************/
795 /******************************************************************************/
796 /******************************************************************************/
797 
798 typedef struct _CHANGE_CONTEXT
799 {
803 
804 typedef BOOL (WINAPI *PEDITSECURITY)(HWND hwndOwner,
805  struct ISecurityInformation *psi);
806 
809 
810 BOOL
812 {
813  if (!(hAclUiDll = LoadLibraryW(L"aclui.dll")))
814  {
815  return FALSE;
816  }
817 
818  if (!(pfnEditSecurity = (PEDITSECURITY)GetProcAddress(hAclUiDll,
819  "EditSecurity")))
820  {
821  FreeLibrary(hAclUiDll);
822  hAclUiDll = NULL;
823  return FALSE;
824  }
825 
826  return TRUE;
827 }
828 
829 VOID
831 {
832  if (hAclUiDll != NULL)
833  {
834  FreeLibrary(hAclUiDll);
835  }
836 }
837 
838 BOOL
840  HKEY hKey,
841  LPCWSTR lpMachine,
842  LPCWSTR lpKeyName)
843 {
844  BOOL Result = FALSE;
845  LPCWSTR lphKey = NULL;
846  LPWSTR lpKeyPath = NULL;
847  PCRegKeySecurity RegKeySecurity;
848  SI_OBJECT_INFO ObjectInfo;
849  size_t lnMachine = 0, lnKeyName = 0;
850 
851  if (pfnEditSecurity == NULL)
852  {
853  return FALSE;
854  }
855 
856  if (lpMachine != NULL)
857  lnMachine = wcslen(lpMachine);
858  if (lpKeyName != NULL)
859  lnKeyName = wcslen(lpKeyName);
860 
861  /* build registry path */
862  if (lpMachine != NULL &&
863  (lpMachine[0] == L'\0' ||
864  (lpMachine[0] == L'.' && lpMachine[1] == L'.')))
865  {
866  lnMachine = 0;
867  }
868 
869  if (hKey == HKEY_CLASSES_ROOT)
870  lphKey = L"CLASSES_ROOT";
871  else if (hKey == HKEY_CURRENT_USER)
872  lphKey = L"CURRENT_USER";
873  else if (hKey == HKEY_LOCAL_MACHINE)
874  lphKey = L"MACHINE";
875  else if (hKey == HKEY_USERS)
876  lphKey = L"USERS";
877  else if (hKey == HKEY_CURRENT_CONFIG)
878  lphKey = L"CONFIG";
879  else
880  goto Cleanup;
881 
882  lpKeyPath = HeapAlloc(GetProcessHeap(),
883  0,
884  (2 + lnMachine + 1 + wcslen(lphKey) + 1 + lnKeyName) * sizeof(WCHAR));
885  if (lpKeyPath == NULL)
886  {
888  goto Cleanup;
889  }
890  lpKeyPath[0] = L'\0';
891 
892  if (lnMachine != 0)
893  {
894  wcscat(lpKeyPath,
895  L"\\\\");
896  wcscat(lpKeyPath,
897  lpMachine);
898  wcscat(lpKeyPath,
899  L"\\");
900  }
901 
902  wcscat(lpKeyPath,
903  lphKey);
904  if (lpKeyName != NULL && lpKeyName[0] != L'\0')
905  {
906  if (lpKeyName[0] != L'\\')
907  {
908  wcscat(lpKeyPath,
909  L"\\");
910  }
911 
912  wcscat(lpKeyPath,
913  lpKeyName);
914  }
915 
918  ObjectInfo.hInstance = hInst;
919  ObjectInfo.pszServerName = (LPWSTR)lpMachine;
920  ObjectInfo.pszObjectName = (LPWSTR)lpKeyName; /* FIXME */
921  ObjectInfo.pszPageTitle = (LPWSTR)lpKeyName; /* FIXME */
922 
923  if (!(RegKeySecurity = CRegKeySecurity_fnConstructor(lpKeyPath,
924  hKey,
925  &ObjectInfo,
926  &Result)))
927  {
928  goto Cleanup;
929  }
930 
931  /* display the security editor dialog */
932  pfnEditSecurity(hWndOwner,
933  impl_to_interface(RegKeySecurity,
934  ISecurityInformation));
935 
936  /* dereference the interface, it should be destroyed here */
937  CRegKeySecurity_fnRelease(RegKeySecurity);
938 
939 Cleanup:
940  if (lpKeyPath != NULL)
941  {
943  0,
944  lpKeyPath);
945  }
946 
947  return Result;
948 }
949 
950 /* EOF */
#define HKEY_USERS
Definition: winreg.h:13
DWORD *typedef PVOID
Definition: winlogon.h:61
VOID WINAPI MapGenericMask(PDWORD, PGENERIC_MAPPING)
DWORD WINAPI GetNamedSecurityInfoW(LPWSTR pObjectName, SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo, PSID *ppsidOwner, PSID *ppsidGroup, PACL *ppDacl, PACL *ppSacl, PSECURITY_DESCRIPTOR *ppSecurityDescriptor)
Definition: misc.c:1147
static const DWORD RegDefaultAccess
Definition: security.c:353
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
static HRESULT STDMETHODCALLTYPE ISecurityObjectTypeInfo_fnQueryInterface(struct ISecurityObjectTypeInfo *this, REFIID iid, PVOID *pvObject)
Definition: security.c:641
#define REFIID
Definition: guiddef.h:113
#define TRUE
Definition: types.h:120
LPWSTR pszServerName
Definition: accctrl.h:390
#define E_NOINTERFACE
Definition: winerror.h:2364
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4418
static ULONG
Definition: security.c:118
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
#define SI_CONTAINER
Definition: accctrl.h:116
static __inline PCRegKeySecurity impl_from_ISecurityObjectTypeInfo(struct ISecurityObjectTypeInfo *iface)
Definition: security.c:63
const GUID IID_IUnknown
#define ERROR_SUCCESS
Definition: deptool.c:10
_In_ BOOLEAN _In_opt_ PACL _In_opt_ BOOLEAN DaclDefaulted
Definition: rtlfuncs.h:1595
static HRESULT STDMETHODCALLTYPE ISecurityObjectTypeInfo_fnGetInheritSource(struct ISecurityObjectTypeInfo *this, SECURITY_INFORMATION si, PACL pACL, PINHERITED_FROM *ppInheritArray)
Definition: security.c:671
DWORD WINAPI GetInheritanceSourceW(LPWSTR pObjectName, SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo, BOOL Container, GUID **pObjectClassGuids OPTIONAL, DWORD GuidCount, PACL pAcl, PFN_OBJECT_MGR_FUNCTS pfnArray OPTIONAL, PGENERIC_MAPPING pGenericMapping, PINHERITED_FROMW pInheritArray)
Definition: ac.c:115
#define KEY_SET_VALUE
Definition: nt_native.h:1017
BOOL WINAPI GetSecurityDescriptorDacl(PSECURITY_DESCRIPTOR pSecurityDescriptor, LPBOOL lpbDaclPresent, PACL *pDacl, LPBOOL lpbDaclDefaulted)
Definition: sec.c:45
static const struct ifaceISecurityObjectTypeInfoVbtl vtblISecurityObjectTypeInfo
Definition: security.c:322
HANDLE HLOCAL
Definition: windef.h:244
WCHAR szRegKey[1]
Definition: security.h:153
#define IDS_ACCESS_QUERYVALUE
Definition: resource.h:175
#define impl_to_interface(impl, iface)
Definition: security.c:76
#define SI_RESET_SACL_TREE
Definition: accctrl.h:128
#define KEY_READ
Definition: nt_native.h:1023
__wchar_t WCHAR
Definition: xmlstorage.h:180
static HRESULT STDMETHODCALLTYPE IEffectivePermission_fnQueryInterface(struct IEffectivePermission *this, REFIID iid, PVOID *pvObject)
Definition: security.c:553
BOOL InitializeAclUiDll(VOID)
Definition: security.c:811
#define IDS_INHERIT_THISKEYANDSUBKEYS
Definition: resource.h:187
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define IDS_ACCESS_NOTIFY
Definition: resource.h:179
#define SI_EDIT_ALL
Definition: accctrl.h:136
#define BuildTrusteeWithSid
Definition: aclapi.h:230
UINT uMsg
Definition: precomp.h:45
SECURITY_INFORMATION PACL pACL
Definition: security.h:129
#define IDS_ACCESS_WRITEDAC
Definition: resource.h:182
static const struct ifaceIEffectivePermissionVbtl vtblIEffectivePermission
Definition: security.c:288
HANDLE HWND
Definition: compat.h:13
#define IDS_ACCESS_CREATESUBKEY
Definition: resource.h:177
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
enum _SI_PAGE_TYPE SI_PAGE_TYPE
#define SI_EDIT_PERMS
Definition: accctrl.h:113
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
#define WRITE_OWNER
Definition: nt_native.h:60
static HMODULE hAclUiDll
Definition: security.c:808
LPWSTR pszPageTitle
Definition: accctrl.h:392
SECURITY_INFORMATION si
Definition: security.h:129
static HRESULT STDMETHODCALLTYPE ISecurityInformation_fnMapGeneric(struct ISecurityInformation *this, const GUID *pguidObjectType, UCHAR *pAceFlags, ACCESS_MASK *pMask)
Definition: security.c:456
#define HKEY_CURRENT_CONFIG
Definition: winreg.h:15
#define SI_ADVANCED
Definition: accctrl.h:118
USHORT AceCount
Definition: ms-dtyp.idl:297
SECURITY_INFORMATION PACL PINHERITED_FROM * ppInheritArray
Definition: security.h:129
DWORD DWORD
Definition: winlogon.h:84
_In_ BOOLEAN DaclPresent
Definition: rtlfuncs.h:1595
static BOOL
Definition: security.c:72
#define IDS_ACCESS_SETVALUE
Definition: resource.h:176
GLsizei GLsizei GLuint * obj
Definition: glext.h:6042
#define IDS_ACCESS_READCONTROL
Definition: resource.h:184
uint32_t ULONG_PTR
Definition: typedefs.h:63
static HRESULT STDMETHODCALLTYPE ISecurityInformation_fnGetAccessRights(struct ISecurityInformation *this, const GUID *pguidObjectType, DWORD dwFlags, PSI_ACCESS *ppAccess, ULONG *pcAccesses, ULONG *piDefaultAccess)
Definition: security.c:442
static ULONG STDMETHODCALLTYPE ISecurityObjectTypeInfo_fnAddRef(struct ISecurityObjectTypeInfo *this)
Definition: security.c:659
#define IDS_ACCESS_READ
Definition: resource.h:174
struct _CHANGE_CONTEXT * PCHANGE_CONTEXT
GLenum GLclampf GLint i
Definition: glfuncs.h:14
DWORD WINAPI FreeInheritedFromArray(PINHERITED_FROMW pInheritArray, USHORT AceCnt, PFN_OBJECT_MGR_FUNCTS pfnArray OPTIONAL)
Definition: ac.c:175
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define IDS_ACCESS_CREATELINK
Definition: resource.h:180
#define FALSE
Definition: types.h:117
DWORD dwFlags
Definition: accctrl.h:388
static ULONG STDMETHODCALLTYPE IEffectivePermission_fnAddRef(struct IEffectivePermission *this)
Definition: security.c:571
long LONG
Definition: pedump.c:60
DWORD SECURITY_INFORMATION
Definition: ms-dtyp.idl:311
static HRESULT STDMETHODCALLTYPE ISecurityInformation_fnSetSecurity(struct ISecurityInformation *this, SECURITY_INFORMATION RequestedInformation, PSECURITY_DESCRIPTOR pSecurityDescriptor)
Definition: security.c:430
BOOL(WINAPI * PEDITSECURITY)(HWND hwndOwner, struct ISecurityInformation *psi)
Definition: security.c:804
const struct ifaceISecurityObjectTypeInfoVbtl * lpISecurityObjectTypeInfoVtbl
Definition: security.h:146
static HRESULT STDMETHODCALLTYPE IEffectivePermission_fnGetEffectivePermission(struct IEffectivePermission *this, const GUID *pguidObjectType, PSID pUserSid, LPCWSTR pszServerName, PSECURITY_DESCRIPTOR pSD, POBJECT_TYPE_LIST *ppObjectTypeList, ULONG *pcObjectTypeListLength, PACCESS_MASK *ppGrantedAccessList, ULONG *pcGrantedAccessListLength)
Definition: security.c:583
#define LoadLibraryW(x)
Definition: compat.h:404
smooth NULL
Definition: ftsmooth.c:416
const struct ifaceISecurityInformationVbtl * lpISecurityInformationVtbl
Definition: security.h:141
#define SI_ACCESS_SPECIFIC
Definition: accctrl.h:138
#define IDS_ACCESS_DELETE
Definition: resource.h:181
static SI_ACCESS RegAccess[]
Definition: security.c:338
const struct ifaceIEffectivePermissionVbtl * lpIEffectivePermissionVtbl
Definition: security.h:145
static ULONG STDMETHODCALLTYPE ISecurityObjectTypeInfo_fnRelease(struct ISecurityObjectTypeInfo *this)
Definition: security.c:665
LPWSTR pszObjectName
Definition: accctrl.h:391
#define SI_RESET_DACL_TREE
Definition: accctrl.h:127
#define LMEM_FIXED
Definition: winbase.h:349
#define KEY_WRITE
Definition: nt_native.h:1031
#define CONTAINER_INHERIT_ACE
Definition: setypes.h:715
static HRESULT STDMETHODCALLTYPE ISecurityInformation_fnPropertySheetPageCallback(struct ISecurityInformation *this, HWND hwnd, UINT uMsg, SI_PAGE_TYPE uPage)
Definition: security.c:486
#define IDS_ACCESS_FULLCONTROL
Definition: resource.h:173
#define COUNT_OF(a)
Definition: main.h:33
#define FreeLibrary(x)
Definition: compat.h:405
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
static __inline PCRegKeySecurity impl_from_IEffectivePermission(struct IEffectivePermission *iface)
Definition: security.c:70
static __inline ULONG CRegKeySecurity_fnRelease(PCRegKeySecurity obj)
Definition: security.c:85
static __inline PCRegKeySecurity impl_from_ISecurityInformation(struct ISecurityInformation *iface)
Definition: security.c:47
LONG HRESULT
Definition: typedefs.h:77
HANDLE HKEY
Definition: registry.h:24
static HRESULT STDMETHODCALLTYPE ISecurityInformation_fnQueryInterface(struct ISecurityInformation *this, REFIID iid, PVOID *pvObject)
Definition: security.c:369
static __inline HRESULT CRegKeySecurity_fnQueryInterface(PCRegKeySecurity obj, REFIID iid, PVOID *pvObject)
Definition: security.c:101
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
#define WRITE_DAC
Definition: nt_native.h:59
BOOL RegKeyEditPermissions(HWND hWndOwner, HKEY hKey, LPCWSTR lpMachine, LPCWSTR lpKeyName)
Definition: security.c:839
#define SetLastError(x)
Definition: compat.h:409
HINSTANCE hInstance
Definition: accctrl.h:389
struct _CRegKeySecurity * PCRegKeySecurity
struct _CHANGE_CONTEXT CHANGE_CONTEXT
static GENERIC_MAPPING RegAccessMasks
Definition: security.c:355
#define READ_CONTROL
Definition: nt_native.h:58
REFIID PVOID * pvObject
Definition: security.h:94
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL Dacl
Definition: rtlfuncs.h:1553
unsigned char UCHAR
Definition: xmlstorage.h:181
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1087
#define InterlockedDecrement
Definition: armddk.h:52
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define GUID_NULL
Definition: ks.h:106
interface IDataObject * LPDATAOBJECT
Definition: objfwd.h:21
static const WCHAR Cleanup[]
Definition: register.c:80
#define SYNCHRONIZE
Definition: nt_native.h:61
#define WINAPI
Definition: msvc.h:20
static HRESULT STDMETHODCALLTYPE ISecurityInformation_fnGetObjectInformation(struct ISecurityInformation *this, PSI_OBJECT_INFO pObjectInfo)
Definition: security.c:399
REFIID PVOID * pvObject
Definition: security.h:22
Definition: hiveinit.c:368
ULONG_PTR SIZE_T
Definition: typedefs.h:78
#define IDS_ACCESS_ENUMERATESUBKEYS
Definition: resource.h:178
#define S_OK
Definition: intsafe.h:59
HINSTANCE hInst
Definition: dxdiag.c:13
#define InterlockedIncrement
Definition: armddk.h:53
#define SI_EDIT_EFFECTIVE
Definition: accctrl.h:130
static ULONG STDMETHODCALLTYPE IEffectivePermission_fnRelease(struct IEffectivePermission *this)
Definition: security.c:577
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define KEY_CREATE_LINK
Definition: nt_native.h:1021
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define KEY_NOTIFY
Definition: nt_native.h:1020
#define E_NOTIMPL
Definition: ddrawi.h:99
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define KEY_EXECUTE
Definition: nt_native.h:1037
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
unsigned int UINT
Definition: ndis.h:50
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4024
#define SI_ACCESS_GENERAL
Definition: accctrl.h:139
static ULONG STDMETHODCALLTYPE ISecurityInformation_fnAddRef(struct ISecurityInformation *this)
Definition: security.c:387
LPWSTR KeyString
Definition: security.c:801
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define SI_OWNER_RECURSE
Definition: accctrl.h:122
static HRESULT STDMETHODCALLTYPE ISecurityInformation_fnGetSecurity(struct ISecurityInformation *this, SECURITY_INFORMATION RequestedInformation, PSECURITY_DESCRIPTOR *ppSecurityDescriptor, BOOL fDefault)
Definition: security.c:409
HANDLE HMODULE
Definition: typedefs.h:75
SI_OBJECT_INFO ObjectInfo
Definition: security.h:150
static PVOID
Definition: security.c:118
#define GetEffectiveRightsFromAcl
Definition: aclapi.h:232
static __inline ULONG CRegKeySecurity_fnAddRef(PCRegKeySecurity obj)
Definition: security.c:79
unsigned int ULONG
Definition: retypes.h:1
static PCRegKeySecurity CRegKeySecurity_fnConstructor(LPWSTR lpRegKey, HKEY hRootKey, SI_OBJECT_INFO *ObjectInfo, BOOL *Btn)
Definition: security.c:762
ACCESS_MASK * PACCESS_MASK
Definition: nt_native.h:41
#define ULONG_PTR
Definition: config.h:101
#define GetProcAddress(x, y)
Definition: compat.h:410
static SI_INHERIT_TYPE RegInheritTypes[]
Definition: security.c:362
#define INHERIT_ONLY_ACE
Definition: setypes.h:717
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
VOID UnloadAclUiDll(VOID)
Definition: security.c:830
static ULONG STDMETHODCALLTYPE ISecurityInformation_fnRelease(struct ISecurityInformation *this)
Definition: security.c:393
static PEDITSECURITY pfnEditSecurity
Definition: security.c:807
#define IDS_ACCESS_WRITEOWNER
Definition: resource.h:183
WCHAR * LPWSTR
Definition: xmlstorage.h:184
DEFINE_GUID(IID_IRegKeySecurity, 0x965fc360, 0x16ff, 0x11d0, 0x0091, 0xcb, 0x00, 0xaa, 0x00, 0xbb, 0xb7, 0x23)
#define KEY_CREATE_SUB_KEY
Definition: nt_native.h:1018
static const struct ifaceISecurityInformationVbtl vtblISecurityInformation
Definition: security.c:202
#define IDS_INHERIT_THISKEYONLY
Definition: resource.h:186
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:394
ULONG ACCESS_MASK
Definition: nt_native.h:40
static HRESULT STDMETHODCALLTYPE ISecurityInformation_fnGetInheritTypes(struct ISecurityInformation *this, PSI_INHERIT_TYPE *ppInheritTypes, ULONG *pcInheritTypes)
Definition: security.c:468
#define DELETE
Definition: nt_native.h:57
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define IDS_INHERIT_SUBKEYSONLY
Definition: resource.h:188
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019