📄 security.c
字号:
{&GUID_NULL, KEY_CREATE_LINK, (LPWSTR)MAKEINTRESOURCE(IDS_ACCESS_CREATELINK), SI_ACCESS_SPECIFIC},
{&GUID_NULL, DELETE, (LPWSTR)MAKEINTRESOURCE(IDS_ACCESS_DELETE), SI_ACCESS_SPECIFIC},
{&GUID_NULL, WRITE_DAC, (LPWSTR)MAKEINTRESOURCE(IDS_ACCESS_WRITEDAC), SI_ACCESS_SPECIFIC},
{&GUID_NULL, WRITE_OWNER, (LPWSTR)MAKEINTRESOURCE(IDS_ACCESS_WRITEOWNER), SI_ACCESS_SPECIFIC},
{&GUID_NULL, READ_CONTROL, (LPWSTR)MAKEINTRESOURCE(IDS_ACCESS_READCONTROL), SI_ACCESS_SPECIFIC},
};
static const DWORD RegDefaultAccess = 1; /* KEY_READ */
static GENERIC_MAPPING RegAccessMasks = {
KEY_READ,
KEY_WRITE,
KEY_EXECUTE,
KEY_ALL_ACCESS
};
static SI_INHERIT_TYPE RegInheritTypes[] = {
{&GUID_NULL, 0, (LPWSTR)MAKEINTRESOURCE(IDS_INHERIT_THISKEYONLY)},
{&GUID_NULL, CONTAINER_INHERIT_ACE, (LPWSTR)MAKEINTRESOURCE(IDS_INHERIT_THISKEYANDSUBKEYS)},
{&GUID_NULL, INHERIT_ONLY_ACE | CONTAINER_INHERIT_ACE, (LPWSTR)MAKEINTRESOURCE(IDS_INHERIT_SUBKEYSONLY)},
};
static HRESULT STDMETHODCALLTYPE
ISecurityInformation_fnQueryInterface(struct ISecurityInformation *this,
REFIID iid,
PVOID *pvObject)
{
if (IsEqualGUID(iid,
&IID_IUnknown))
{
*pvObject = (PVOID)this;
ISecurityInformation_fnAddRef(this);
return S_OK;
}
return CRegKeySecurity_fnQueryInterface(impl_from_ISecurityInformation(this),
iid,
pvObject);
}
static ULONG STDMETHODCALLTYPE
ISecurityInformation_fnAddRef(struct ISecurityInformation *this)
{
return CRegKeySecurity_fnAddRef(impl_from_ISecurityInformation(this));
}
static ULONG STDMETHODCALLTYPE
ISecurityInformation_fnRelease(struct ISecurityInformation *this)
{
return CRegKeySecurity_fnRelease(impl_from_ISecurityInformation(this));
}
static HRESULT STDMETHODCALLTYPE
ISecurityInformation_fnGetObjectInformation(struct ISecurityInformation *this,
PSI_OBJECT_INFO pObjectInfo)
{
PCRegKeySecurity obj = impl_from_ISecurityInformation(this);
*pObjectInfo = obj->ObjectInfo;
return S_OK;
}
static HRESULT STDMETHODCALLTYPE
ISecurityInformation_fnGetSecurity(struct ISecurityInformation *this,
SECURITY_INFORMATION RequestedInformation,
PSECURITY_DESCRIPTOR* ppSecurityDescriptor,
BOOL fDefault)
{
PCRegKeySecurity obj = impl_from_ISecurityInformation(this);
LONG ErrorCode;
ErrorCode = GetNamedSecurityInfo(obj->szRegKey,
SE_REGISTRY_KEY,
RequestedInformation,
NULL,
NULL,
NULL,
NULL,
ppSecurityDescriptor);
return HRESULT_FROM_WIN32(ErrorCode);
}
static HRESULT STDMETHODCALLTYPE
ISecurityInformation_fnSetSecurity(struct ISecurityInformation *this,
SECURITY_INFORMATION RequestedInformation,
PSECURITY_DESCRIPTOR pSecurityDescriptor)
{
PCRegKeySecurity obj = impl_from_ISecurityInformation(this);
/* FIXME */
*obj->Btn = TRUE;
return S_OK;
}
static HRESULT STDMETHODCALLTYPE
ISecurityInformation_fnGetAccessRights(struct ISecurityInformation *this,
const GUID* pguidObjectType,
DWORD dwFlags,
PSI_ACCESS* ppAccess,
ULONG* pcAccesses,
ULONG* piDefaultAccess)
{
*ppAccess = RegAccess;
*pcAccesses = sizeof(RegAccess) / sizeof(RegAccess[0]);
*piDefaultAccess = RegDefaultAccess;
return S_OK;
}
static HRESULT STDMETHODCALLTYPE
ISecurityInformation_fnMapGeneric(struct ISecurityInformation *this,
const GUID* pguidObjectType,
UCHAR* pAceFlags,
ACCESS_MASK* pMask)
{
MapGenericMask(pMask,
&RegAccessMasks);
*pMask &= ~SYNCHRONIZE;
return S_OK;
}
static HRESULT STDMETHODCALLTYPE
ISecurityInformation_fnGetInheritTypes(struct ISecurityInformation *this,
PSI_INHERIT_TYPE* ppInheritTypes,
ULONG* pcInheritTypes)
{
PCRegKeySecurity obj = impl_from_ISecurityInformation(this);
/* FIXME */
if (obj->ObjectInfo.dwFlags & SI_CONTAINER)
{
*ppInheritTypes = RegInheritTypes;
*pcInheritTypes = sizeof(RegInheritTypes) / sizeof(RegInheritTypes[0]);
return S_OK;
}
return E_NOTIMPL;
}
static HRESULT STDMETHODCALLTYPE
ISecurityInformation_fnPropertySheetPageCallback(struct ISecurityInformation *this,
HWND hwnd,
UINT uMsg,
SI_PAGE_TYPE uPage)
{
return S_OK;
}
#if REGEDIT_IMPLEMENT_ISECURITYINFORMATION2
/******************************************************************************
Implementation of the ISecurityInformation2 interface
******************************************************************************/
static HRESULT STDMETHODCALLTYPE
ISecurityInformation2_fnQueryInterface(struct ISecurityInformation2 *this,
REFIID iid,
PVOID *pvObject)
{
if (IsEqualGUID(iid,
&IID_IUnknown))
{
*pvObject = (PVOID)this;
ISecurityInformation2_fnAddRef(this);
return S_OK;
}
return CRegKeySecurity_fnQueryInterface(impl_from_ISecurityInformation2(this),
iid,
pvObject);
}
static ULONG STDMETHODCALLTYPE
ISecurityInformation2_fnAddRef(struct ISecurityInformation2 *this)
{
return CRegKeySecurity_fnAddRef(impl_from_ISecurityInformation2(this));
}
static ULONG STDMETHODCALLTYPE
ISecurityInformation2_fnRelease(struct ISecurityInformation2 *this)
{
return CRegKeySecurity_fnRelease(impl_from_ISecurityInformation2(this));
}
static BOOL STDMETHODCALLTYPE
ISecurityInformation2_fnIsDaclCanonical(struct ISecurityInformation2 *this,
PACL pDacl)
{
/* FIXME */
return TRUE;
}
static HRESULT STDMETHODCALLTYPE
ISecurityInformation2_fnLookupSids(struct ISecurityInformation2 *this,
ULONG cSids,
PSID* rgpSids,
LPDATAOBJECT* ppdo)
{
/* FIXME */
return E_NOTIMPL;
}
#endif
/******************************************************************************
Implementation of the IEffectivePermission interface
******************************************************************************/
static HRESULT STDMETHODCALLTYPE
IEffectivePermission_fnQueryInterface(struct IEffectivePermission *this,
REFIID iid,
PVOID *pvObject)
{
if (IsEqualGUID(iid,
&IID_IUnknown))
{
*pvObject = (PVOID)this;
IEffectivePermission_fnAddRef(this);
return S_OK;
}
return CRegKeySecurity_fnQueryInterface(impl_from_IEffectivePermission(this),
iid,
pvObject);
}
static ULONG STDMETHODCALLTYPE
IEffectivePermission_fnAddRef(struct IEffectivePermission *this)
{
return CRegKeySecurity_fnAddRef(impl_from_IEffectivePermission(this));
}
static ULONG STDMETHODCALLTYPE
IEffectivePermission_fnRelease(struct IEffectivePermission *this)
{
return CRegKeySecurity_fnRelease(impl_from_IEffectivePermission(this));
}
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)
{
PACL Dacl = NULL;
BOOL DaclPresent, DaclDefaulted;
PACCESS_MASK GrantedAccessList;
DWORD ErrorCode = ERROR_SUCCESS;
TRUSTEE Trustee = {0};
static OBJECT_TYPE_LIST DefObjTypeList = {0};
*ppObjectTypeList = &DefObjTypeList;
*pcObjectTypeListLength = 1;
BuildTrusteeWithSid(&Trustee,
pUserSid);
if (GetSecurityDescriptorDacl(pSD,
&DaclPresent,
&Dacl,
&DaclDefaulted) && DaclPresent)
{
GrantedAccessList = (PACCESS_MASK)LocalAlloc(LMEM_FIXED,
sizeof(ACCESS_MASK));
if (GrantedAccessList == NULL)
{
goto Fail;
}
ErrorCode = GetEffectiveRightsFromAcl(Dacl,
&Trustee,
GrantedAccessList);
if (ErrorCode == ERROR_SUCCESS)
{
*ppGrantedAccessList = GrantedAccessList;
*pcGrantedAccessListLength = 1;
}
else
LocalFree((HLOCAL)GrantedAccessList);
}
else
Fail:
ErrorCode = GetLastError();
return HRESULT_FROM_WIN32(ErrorCode);
}
/******************************************************************************
Implementation of the ISecurityObjectTypeInfo interface
******************************************************************************/
static HRESULT STDMETHODCALLTYPE
ISecurityObjectTypeInfo_fnQueryInterface(struct ISecurityObjectTypeInfo *this,
REFIID iid,
PVOID *pvObject)
{
if (IsEqualGUID(iid,
&IID_IUnknown))
{
*pvObject = (PVOID)this;
ISecurityObjectTypeInfo_fnAddRef(this);
return S_OK;
}
return CRegKeySecurity_fnQueryInterface(impl_from_ISecurityObjectTypeInfo(this),
iid,
pvObject);
}
static ULONG STDMETHODCALLTYPE
ISecurityObjectTypeInfo_fnAddRef(struct ISecurityObjectTypeInfo *this)
{
return CRegKeySecurity_fnAddRef(impl_from_ISecurityObjectTypeInfo(this));
}
static ULONG STDMETHODCALLTYPE
ISecurityObjectTypeInfo_fnRelease(struct ISecurityObjectTypeInfo *this)
{
return CRegKeySecurity_fnRelease(impl_from_ISecurityObjectTypeInfo(this));
}
static HRESULT STDMETHODCALLTYPE
ISecurityObjectTypeInfo_fnGetInheritSource(struct ISecurityObjectTypeInfo *this,
SECURITY_INFORMATION si,
PACL pACL,
PINHERITED_FROM* ppInheritArray)
{
PCRegKeySecurity obj = impl_from_ISecurityObjectTypeInfo(this);
PINHERITED_FROM pif, pif2;
SIZE_T pifSize;
DWORD ErrorCode, i;
LPTSTR lpBuf;
pifSize = pACL->AceCount * sizeof(INHERITED_FROM);
pif = (PINHERITED_FROM)HeapAlloc(GetProcessHeap(),
0,
pifSize);
if (pif == NULL)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -