⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 security.c

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
 * Regedit ACL Editor for Registry Keys
 *
 * Copyright (C) 2004 - 2006 Thomas Weidenmueller <w3seek@reactos.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <regedit.h>

#define INITGUID
#include <guiddef.h>

/* FIXME - shouldn't be defined here... */
DEFINE_GUID(IID_IRegKeySecurity, 0x965fc360, 0x16ff, 0x11d0, 0x0091, 0xcb,0x00,0xaa,0x00,0xbb,0xb7,0x23);
#if REGEDIT_IMPLEMENT_ISECURITYINFORMATION2
DEFINE_GUID(IID_IRegKeySecurity2, 0xc3ccfdb4, 0x6f88, 0x11d2, 0x00a3, 0xce,0x00,0xc0,0x4f,0xb1,0x78,0x2a);
#endif

/* FIXME: already defined in aclui.h - causing problems when compiling with MSVC/PSDK*/
#ifndef _MSC_VER
DEFINE_GUID(IID_IEffectivePermission, 0x3853dc76, 0x9f35, 0x407c, 0x0088, 0xa1,0xd1,0x93,0x44,0x36,0x5f,0xbc);
DEFINE_GUID(IID_ISecurityObjectTypeInfo, 0xfc3066eb, 0x79ef, 0x444b, 0x0091, 0x11,0xd1,0x8a,0x75,0xeb,0xf2,0xfa);
#endif

/******************************************************************************
   Implementation of the IUnknown methods of CRegKeySecurity
 ******************************************************************************/

static __inline PCRegKeySecurity
impl_from_ISecurityInformation(struct ISecurityInformation *iface)
{
    return (PCRegKeySecurity)((ULONG_PTR)iface - FIELD_OFFSET(CRegKeySecurity,
                                                              lpISecurityInformationVtbl));
}

#if REGEDIT_IMPLEMENT_ISECURITYINFORMATION2
static __inline PCRegKeySecurity
impl_from_ISecurityInformation2(struct ISecurityInformation2 *iface)
{
    return (PCRegKeySecurity)((ULONG_PTR)iface - FIELD_OFFSET(CRegKeySecurity,
                                                              lpISecurityInformation2Vtbl));
}
#endif

static __inline PCRegKeySecurity
impl_from_ISecurityObjectTypeInfo(struct ISecurityObjectTypeInfo *iface)
{
    return (PCRegKeySecurity)((ULONG_PTR)iface - FIELD_OFFSET(CRegKeySecurity,
                                                              lpISecurityObjectTypeInfoVtbl));
}

static __inline PCRegKeySecurity
impl_from_IEffectivePermission(struct IEffectivePermission *iface)
{
    return (PCRegKeySecurity)((ULONG_PTR)iface - FIELD_OFFSET(CRegKeySecurity,
                                                              lpIEffectivePermissionVtbl));
}

#define impl_to_interface(impl,iface) (struct iface *)(&(impl)->lp##iface##Vtbl)

static __inline ULONG
CRegKeySecurity_fnAddRef(PCRegKeySecurity obj)
{
    return (ULONG)InterlockedIncrement((LONG*)&obj->ref);
}

static __inline ULONG
CRegKeySecurity_fnRelease(PCRegKeySecurity obj)
{
    ULONG Ret;

    Ret = (ULONG)InterlockedDecrement((LONG*)&obj->ref);
    if (Ret == 0)
    {
        HeapFree(GetProcessHeap(),
                 0,
                 obj);
    }

    return Ret;
}

static __inline HRESULT
CRegKeySecurity_fnQueryInterface(PCRegKeySecurity obj,
                                 REFIID iid,
                                 PVOID *pvObject)
{
    PVOID pvObj = NULL;

    if (IsEqualGUID(iid,
                    &IID_IRegKeySecurity))
    {
        pvObj = (PVOID)impl_to_interface(obj,
                                         ISecurityInformation);
    }
#if REGEDIT_IMPLEMENT_ISECURITYINFORMATION2
    else if (IsEqualGUID(iid,
                         &IID_IRegKeySecurity2))
    {
        pvObj = (PVOID)impl_to_interface(obj,
                                         ISecurityInformation2);
    }
#endif
    else if (IsEqualGUID(iid,
                         &IID_IEffectivePermission))
    {
        pvObj = (PVOID)impl_to_interface(obj,
                                         IEffectivePermission);
    }
    else if (IsEqualGUID(iid,
                         &IID_ISecurityObjectTypeInfo))
    {
        pvObj = (PVOID)impl_to_interface(obj,
                                         ISecurityObjectTypeInfo);
    }

    if (pvObj == NULL)
    {
        return E_NOINTERFACE;
    }

    *pvObject = pvObj;
    CRegKeySecurity_fnAddRef(obj);

    return S_OK;
}


/******************************************************************************
   Definition of the ISecurityInformation interface
 ******************************************************************************/

/* IUnknown */
static HRESULT STDMETHODCALLTYPE
ISecurityInformation_fnQueryInterface(struct ISecurityInformation *this,
                                      REFIID iid,
                                      PVOID *pvObject);

static ULONG STDMETHODCALLTYPE
ISecurityInformation_fnAddRef(struct ISecurityInformation *this);

static ULONG STDMETHODCALLTYPE
ISecurityInformation_fnRelease(struct ISecurityInformation *this);

/* ISecurityInformation */
static HRESULT STDMETHODCALLTYPE
ISecurityInformation_fnGetObjectInformation(struct ISecurityInformation *this,
                                            PSI_OBJECT_INFO pObjectInfo);

static HRESULT STDMETHODCALLTYPE
ISecurityInformation_fnGetSecurity(struct ISecurityInformation *this,
                                   SECURITY_INFORMATION RequestedInformation,
                                   PSECURITY_DESCRIPTOR* ppSecurityDescriptor,
                                   BOOL fDefault);

static HRESULT STDMETHODCALLTYPE
ISecurityInformation_fnSetSecurity(struct ISecurityInformation *this,
                                   SECURITY_INFORMATION RequestedInformation,
                                   PSECURITY_DESCRIPTOR pSecurityDescriptor);

static HRESULT STDMETHODCALLTYPE
ISecurityInformation_fnGetAccessRights(struct ISecurityInformation *this,
                                       const GUID* pguidObjectType,
                                      DWORD dwFlags,
                                      PSI_ACCESS* ppAccess,
                                      ULONG* pcAccesses,
                                      ULONG* piDefaultAccess);

static HRESULT STDMETHODCALLTYPE
ISecurityInformation_fnMapGeneric(struct ISecurityInformation *this,
                                 const GUID* pguidObjectType,
                                 UCHAR* pAceFlags,
                                 ACCESS_MASK* pMask);

static HRESULT STDMETHODCALLTYPE
ISecurityInformation_fnGetInheritTypes(struct ISecurityInformation *this,
                                      PSI_INHERIT_TYPE* ppInheritTypes,
                                      ULONG* pcInheritTypes);
static HRESULT STDMETHODCALLTYPE
ISecurityInformation_fnPropertySheetPageCallback(struct ISecurityInformation *this,
                                                HWND hwnd,
                                                UINT uMsg,
                                                SI_PAGE_TYPE uPage);

static const struct ifaceISecurityInformationVbtl vtblISecurityInformation =
{
    /* IUnknown methods */
    ISecurityInformation_fnQueryInterface,
    ISecurityInformation_fnAddRef,
    ISecurityInformation_fnRelease,

    /* ISecurityInformation methods */
    ISecurityInformation_fnGetObjectInformation,
    ISecurityInformation_fnGetSecurity,
    ISecurityInformation_fnSetSecurity,
    ISecurityInformation_fnGetAccessRights,
    ISecurityInformation_fnMapGeneric,
    ISecurityInformation_fnGetInheritTypes,
    ISecurityInformation_fnPropertySheetPageCallback,
};

#if REGEDIT_IMPLEMENT_ISECURITYINFORMATION2
/******************************************************************************
   Definition of the ISecurityInformation2 interface
 ******************************************************************************/

/* IUnknown */
static HRESULT STDMETHODCALLTYPE
ISecurityInformation2_fnQueryInterface(struct ISecurityInformation2 *this,
                                       REFIID iid,
                                       PVOID *pvObject);

static ULONG STDMETHODCALLTYPE
ISecurityInformation2_fnAddRef(struct ISecurityInformation2 *this);

static ULONG STDMETHODCALLTYPE
ISecurityInformation2_fnRelease(struct ISecurityInformation2 *this);

/* ISecurityInformation2 */
static BOOL STDMETHODCALLTYPE
ISecurityInformation2_fnIsDaclCanonical(struct ISecurityInformation2 *this,
                                        PACL pDacl);

static HRESULT STDMETHODCALLTYPE
ISecurityInformation2_fnLookupSids(struct ISecurityInformation2 *this,
                                   ULONG cSids,
                                   PSID* rgpSids,
                                   LPDATAOBJECT* ppdo);

static const struct ifaceISecurityInformation2Vbtl vtblISecurityInformation2 =
{
    /* IUnknown methods */
    ISecurityInformation2_fnQueryInterface,
    ISecurityInformation2_fnAddRef,
    ISecurityInformation2_fnRelease,

    /* ISecurityInformation2 methods */
    ISecurityInformation2_fnIsDaclCanonical,
    ISecurityInformation2_fnLookupSids
};
#endif

/******************************************************************************
   Definition of the IEffectivePermission interface
 ******************************************************************************/

/* IUnknown */
static HRESULT STDMETHODCALLTYPE
IEffectivePermission_fnQueryInterface(struct IEffectivePermission *this,
                                      REFIID iid,
                                      PVOID *pvObject);

static ULONG STDMETHODCALLTYPE
IEffectivePermission_fnAddRef(struct IEffectivePermission *this);

static ULONG STDMETHODCALLTYPE
IEffectivePermission_fnRelease(struct IEffectivePermission *this);

/* IEffectivePermission */
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);

static const struct ifaceIEffectivePermissionVbtl vtblIEffectivePermission =
{
    /* IUnknown methods */
    IEffectivePermission_fnQueryInterface,
    IEffectivePermission_fnAddRef,
    IEffectivePermission_fnRelease,

    /* IEffectivePermissions methods */
    IEffectivePermission_fnGetEffectivePermission
};

/******************************************************************************
   Definition of the ISecurityObjectTypeInfo interface
 ******************************************************************************/

/* IUnknown */
static HRESULT STDMETHODCALLTYPE
ISecurityObjectTypeInfo_fnQueryInterface(struct ISecurityObjectTypeInfo *this,
                                         REFIID iid,
                                         PVOID *pvObject);

static ULONG STDMETHODCALLTYPE
ISecurityObjectTypeInfo_fnAddRef(struct ISecurityObjectTypeInfo *this);

static ULONG STDMETHODCALLTYPE
ISecurityObjectTypeInfo_fnRelease(struct ISecurityObjectTypeInfo *this);

/* ISecurityObjectTypeInfo */
static HRESULT STDMETHODCALLTYPE
ISecurityObjectTypeInfo_fnGetInheritSource(struct ISecurityObjectTypeInfo *this,
                                           SECURITY_INFORMATION si,
                                           PACL pACL,
                                           PINHERITED_FROM* ppInheritArray);

static const struct ifaceISecurityObjectTypeInfoVbtl vtblISecurityObjectTypeInfo =
{
    /* IUnknown methods */
    ISecurityObjectTypeInfo_fnQueryInterface,
    ISecurityObjectTypeInfo_fnAddRef,
    ISecurityObjectTypeInfo_fnRelease,

    /* ISecurityObjectTypeInfo methods */
    ISecurityObjectTypeInfo_fnGetInheritSource
};


/******************************************************************************
   Implementation of the ISecurityInformation interface
 ******************************************************************************/

static SI_ACCESS RegAccess[] = {
    {&GUID_NULL, KEY_ALL_ACCESS,         (LPWSTR)MAKEINTRESOURCE(IDS_ACCESS_FULLCONTROL),      SI_ACCESS_GENERAL | SI_ACCESS_SPECIFIC},
    {&GUID_NULL, KEY_READ,               (LPWSTR)MAKEINTRESOURCE(IDS_ACCESS_READ),             SI_ACCESS_GENERAL},
    {&GUID_NULL, KEY_QUERY_VALUE,        (LPWSTR)MAKEINTRESOURCE(IDS_ACCESS_QUERYVALUE),       SI_ACCESS_SPECIFIC},
    {&GUID_NULL, KEY_SET_VALUE,          (LPWSTR)MAKEINTRESOURCE(IDS_ACCESS_SETVALUE),         SI_ACCESS_SPECIFIC},
    {&GUID_NULL, KEY_CREATE_SUB_KEY,     (LPWSTR)MAKEINTRESOURCE(IDS_ACCESS_CREATESUBKEY),     SI_ACCESS_SPECIFIC},
    {&GUID_NULL, KEY_ENUMERATE_SUB_KEYS, (LPWSTR)MAKEINTRESOURCE(IDS_ACCESS_ENUMERATESUBKEYS), SI_ACCESS_SPECIFIC},
    {&GUID_NULL, KEY_NOTIFY,             (LPWSTR)MAKEINTRESOURCE(IDS_ACCESS_NOTIFY),           SI_ACCESS_SPECIFIC},

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -