📄 aclui.c
字号:
/*
* ReactOS Access Control List Editor
* Copyright (C) 2004-2005 ReactOS Team
*
* 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
*/
/* $Id: aclui.c 24472 2006-10-09 15:09:50Z weiden $
*
* PROJECT: ReactOS Access Control List Editor
* FILE: lib/aclui/aclui.c
* PURPOSE: Access Control List Editor
* PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
*
* UPDATE HISTORY:
* 08/10/2004 Created
*/
#include <precomp.h>
#define NDEBUG
#include <debug.h>
HINSTANCE hDllInstance;
#define SIDN_LOOKUPSUCCEEDED (0x101)
typedef struct _SIDLOOKUPNOTIFYINFO
{
NMHDR nmh;
PSID Sid;
PSIDREQRESULT SidRequestResult;
} SIDLOOKUPNOTIFYINFO, *PSIDLOOKUPNOTIFYINFO;
static PSID
AceHeaderToSID(IN PACE_HEADER AceHeader)
{
PSID Sid = NULL;
switch (AceHeader->AceType)
{
case ACCESS_ALLOWED_ACE_TYPE:
Sid = (PSID)&((PACCESS_ALLOWED_ACE)AceHeader)->SidStart;
break;
#if 0
case ACCESS_ALLOWED_CALLBACK_ACE_TYPE:
Sid = (PSID)&((PACCESS_ALLOWED_CALLBACK_ACE)AceHeader)->SidStart;
break;
case ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE:
Sid = (PSID)&((PACCESS_ALLOWED_CALLBACK_OBJECT_ACE)AceHeader)->SidStart;
break;
#endif
case ACCESS_ALLOWED_OBJECT_ACE_TYPE:
Sid = (PSID)&((PACCESS_ALLOWED_OBJECT_ACE)AceHeader)->SidStart;
break;
case ACCESS_DENIED_ACE_TYPE:
Sid = (PSID)&((PACCESS_DENIED_ACE)AceHeader)->SidStart;
break;
#if 0
case ACCESS_DENIED_CALLBACK_ACE_TYPE:
Sid = (PSID)&((PACCESS_DENIED_CALLBACK_ACE)AceHeader)->SidStart;
break;
case ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE:
Sid = (PSID)&((PACCESS_DENIED_CALLBACK_OBJECT_ACE)AceHeader)->SidStart;
break;
#endif
case SYSTEM_AUDIT_OBJECT_ACE_TYPE:
Sid = (PSID)&((PACCESS_DENIED_OBJECT_ACE)AceHeader)->SidStart;
break;
}
return Sid;
}
static VOID
DestroySecurityPage(IN PSECURITY_PAGE sp)
{
if(sp->hiPrincipals != NULL)
{
ImageList_Destroy(sp->hiPrincipals);
}
DestroySidCacheMgr(sp->SidCacheMgr);
HeapFree(GetProcessHeap(),
0,
sp);
CoUninitialize();
}
static VOID
FreePrincipalsList(IN PSECURITY_PAGE sp,
IN PPRINCIPAL_LISTITEM *PrincipalsListHead)
{
PPRINCIPAL_LISTITEM CurItem, NextItem;
PACE_ENTRY AceEntry, NextAceEntry;
CurItem = *PrincipalsListHead;
while (CurItem != NULL)
{
/* Free all ACEs */
AceEntry = CurItem->ACEs;
while (AceEntry != NULL)
{
NextAceEntry = AceEntry->Next;
HeapFree(GetProcessHeap(),
0,
AceEntry);
AceEntry = NextAceEntry;
}
/* free the SID string if present */
if (CurItem->SidReqResult != NULL)
{
DereferenceSidReqResult(sp->SidCacheMgr,
CurItem->SidReqResult);
}
if (CurItem->DisplayString != NULL)
{
LocalFree((HLOCAL)CurItem->DisplayString);
}
/* free the ACE list item */
NextItem = CurItem->Next;
HeapFree(GetProcessHeap(),
0,
CurItem);
CurItem = NextItem;
}
*PrincipalsListHead = NULL;
}
static PACE_ENTRY
AddAceToPrincipal(IN PPRINCIPAL_LISTITEM Principal,
IN PACE_HEADER AceHeader)
{
PACE_ENTRY AceEntry, *AceLink;
AceEntry = HeapAlloc(GetProcessHeap(),
0,
sizeof(ACE_ENTRY) + AceHeader->AceSize);
if (AceEntry != NULL)
{
AceEntry->Next = NULL;
/* copy the ACE */
CopyMemory(AceEntry + 1,
AceHeader,
AceHeader->AceSize);
/* append it to the list */
AceLink = &Principal->ACEs;
while (*AceLink != NULL)
{
AceLink = &(*AceLink)->Next;
}
*AceLink = AceEntry;
}
return AceEntry;
}
static PPRINCIPAL_LISTITEM
FindSidInPrincipalsListAddAce(IN PPRINCIPAL_LISTITEM PrincipalsListHead,
IN PSID Sid,
IN PACE_HEADER AceHeader)
{
PPRINCIPAL_LISTITEM CurItem;
for (CurItem = PrincipalsListHead;
CurItem != NULL;
CurItem = CurItem->Next)
{
if (EqualSid((PSID)(CurItem + 1),
Sid))
{
if (AddAceToPrincipal(CurItem,
AceHeader) != NULL)
{
return CurItem;
}
/* unable to add the ACE to the principal */
break;
}
}
return NULL;
}
static VOID
SidLookupCompletion(IN HANDLE SidCacheMgr,
IN PSID Sid,
IN PSIDREQRESULT SidRequestResult,
IN PVOID Context)
{
PSECURITY_PAGE sp = (PSECURITY_PAGE)Context;
/* NOTE: this routine may be executed in a different thread
than the GUI! */
if (SidRequestResult != NULL)
{
SIDLOOKUPNOTIFYINFO LookupInfo;
LookupInfo.nmh.hwndFrom = sp->hWnd;
LookupInfo.nmh.idFrom = 0;
LookupInfo.nmh.code = SIDN_LOOKUPSUCCEEDED;
LookupInfo.Sid = Sid;
LookupInfo.SidRequestResult = SidRequestResult;
/* notify the page that the sid lookup succeeded */
SendMessage(sp->hWnd,
WM_NOTIFY,
(WPARAM)LookupInfo.nmh.idFrom,
(LPARAM)&LookupInfo.nmh);
}
}
static PPRINCIPAL_LISTITEM
AddPrincipalToList(IN PSECURITY_PAGE sp,
IN PSID Sid,
IN PACE_HEADER AceHeader,
OUT BOOL *LookupDeferred OPTIONAL)
{
PPRINCIPAL_LISTITEM PrincipalListItem = NULL, *PrincipalLink;
PACE_ENTRY AceEntry;
BOOL Deferred = FALSE;
if (!FindSidInPrincipalsListAddAce(sp->PrincipalsListHead,
Sid,
AceHeader))
{
DWORD SidLength;
PrincipalLink = &sp->PrincipalsListHead;
while (*PrincipalLink != NULL)
{
PrincipalLink = &(*PrincipalLink)->Next;
}
SidLength = GetLengthSid(Sid);
/* allocate the principal */
PrincipalListItem = HeapAlloc(GetProcessHeap(),
0,
sizeof(PRINCIPAL_LISTITEM) + SidLength);
if (PrincipalListItem != NULL)
{
PrincipalListItem->DisplayString = NULL;
PrincipalListItem->SidReqResult = NULL;
CopySid(SidLength,
(PSID)(PrincipalListItem + 1),
Sid);
/* allocate some memory for the ACE and copy it */
AceEntry = HeapAlloc(GetProcessHeap(),
0,
sizeof(ACE_ENTRY) + AceHeader->AceSize);
if (AceEntry != NULL)
{
AceEntry->Next = NULL;
CopyMemory(AceEntry + 1,
AceHeader,
AceHeader->AceSize);
/* add the ACE to the list */
PrincipalListItem->ACEs = AceEntry;
PrincipalListItem->Next = NULL;
/* append item to the principals list */
*PrincipalLink = PrincipalListItem;
/* lookup the SID now */
Deferred = !LookupSidCache(sp->SidCacheMgr,
Sid,
SidLookupCompletion,
sp);
}
else
{
HeapFree(GetProcessHeap(),
0,
PrincipalListItem);
PrincipalListItem = NULL;
}
}
}
if (PrincipalListItem != NULL && LookupDeferred != NULL)
{
*LookupDeferred = Deferred;
}
return PrincipalListItem;
}
static LPWSTR
GetPrincipalDisplayString(IN PPRINCIPAL_LISTITEM PrincipalListItem)
{
LPWSTR lpDisplayString = NULL;
if (PrincipalListItem->SidReqResult != NULL)
{
if (PrincipalListItem->SidReqResult->SidNameUse == SidTypeUser ||
PrincipalListItem->SidReqResult->SidNameUse == SidTypeGroup)
{
LoadAndFormatString(hDllInstance,
IDS_USERDOMAINFORMAT,
&lpDisplayString,
PrincipalListItem->SidReqResult->AccountName,
PrincipalListItem->SidReqResult->DomainName,
PrincipalListItem->SidReqResult->AccountName);
}
else
{
LoadAndFormatString(hDllInstance,
IDS_USERFORMAT,
&lpDisplayString,
PrincipalListItem->SidReqResult->AccountName);
}
}
else
{
ConvertSidToStringSid((PSID)(PrincipalListItem + 1),
&lpDisplayString);
}
return lpDisplayString;
}
static LPWSTR
GetPrincipalAccountNameString(IN PPRINCIPAL_LISTITEM PrincipalListItem)
{
LPWSTR lpDisplayString = NULL;
if (PrincipalListItem->SidReqResult != NULL)
{
LoadAndFormatString(hDllInstance,
IDS_USERFORMAT,
&lpDisplayString,
PrincipalListItem->SidReqResult->AccountName);
}
else
{
ConvertSidToStringSid((PSID)(PrincipalListItem + 1),
&lpDisplayString);
}
return lpDisplayString;
}
static VOID
CreatePrincipalListItem(OUT LVITEM *li,
IN PSECURITY_PAGE sp,
IN PPRINCIPAL_LISTITEM PrincipalListItem,
IN INT Index,
IN BOOL Selected)
{
INT ImageIndex = 2;
if (PrincipalListItem->SidReqResult != NULL)
{
switch (PrincipalListItem->SidReqResult->SidNameUse)
{
case SidTypeUser:
ImageIndex = 0;
break;
case SidTypeWellKnownGroup:
case SidTypeGroup:
ImageIndex = 1;
break;
default:
break;
}
}
li->mask = LVIF_IMAGE | LVIF_PARAM | LVIF_STATE | LVIF_TEXT;
li->iItem = Index;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -