improved error handling

svn path=/trunk/; revision=18136
This commit is contained in:
Thomas Bluemel 2005-09-28 15:40:52 +00:00
parent 7d4df5c225
commit 294680db96
2 changed files with 85 additions and 58 deletions

View file

@ -1,6 +1,6 @@
/*
* ReactOS Access Control List Editor
* Copyright (C) 2004 ReactOS Team
* 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
@ -101,33 +101,41 @@ AddPrincipalToList(IN PSECURITY_PAGE sp,
SID_NAME_USE SidNameUse;
DWORD LookupResult;
PPRINCIPAL_LISTITEM AceListItem, *NextAcePtr;
AccountNameSize = 0;
DomainNameSize = 0;
/* calculate the size of the buffer we need to calculate */
if (!LookupAccountSid(sp->ServerName,
Sid,
NULL,
&AccountNameSize,
NULL,
&DomainNameSize,
&SidNameUse))
{
LookupResult = GetLastError();
if (LookupResult != ERROR_NONE_MAPPED)
{
return FALSE;
}
}
NextAcePtr = &sp->PrincipalsListHead;
for (AceListItem = sp->PrincipalsListHead; AceListItem != NULL; AceListItem = AceListItem->Next)
for (AceListItem = sp->PrincipalsListHead;
AceListItem != NULL;
AceListItem = AceListItem->Next)
{
NextAcePtr = &AceListItem->Next;
}
SidLength = GetLengthSid(Sid);
AccountNameSize = 0;
DomainNameSize = 0;
/* calculate the size of the buffer we need to calculate */
LookupAccountSid(sp->ServerName,
Sid,
NULL,
&AccountNameSize,
NULL,
&DomainNameSize,
&SidNameUse);
/* allocate the ace */
AceListItem = HeapAlloc(GetProcessHeap(),
0,
sizeof(PRINCIPAL_LISTITEM) +
SidLength +
((AccountNameSize + DomainNameSize) * sizeof(WCHAR)));
sizeof(PRINCIPAL_LISTITEM) + SidLength +
((AccountNameSize + DomainNameSize) * sizeof(WCHAR)));
if (AceListItem != NULL)
{
AceListItem->AccountName = (LPWSTR)((ULONG_PTR)(AceListItem + 1) + SidLength);
@ -236,11 +244,10 @@ AddPrincipalToList(IN PSECURITY_PAGE sp,
{
if (Domain != NULL)
{
SIZE_T Size = (AccountNameSize + DomainName->Length +
Names->Name.Length + 6) * sizeof(WCHAR);
AceListItem->DisplayString = (LPWSTR)LocalAlloc(LMEM_FIXED,
(AccountNameSize * sizeof(WCHAR)) +
(DomainName->Length + sizeof(WCHAR)) +
(Names->Name.Length + sizeof(WCHAR)) +
(4 * sizeof(WCHAR)));
Size);
if (AceListItem->DisplayString != NULL)
{
WCHAR *s;
@ -369,6 +376,7 @@ AddPrincipalListEntry(IN PSECURITY_PAGE sp,
li.state = (Selected ? LVIS_SELECTED : 0);
li.stateMask = LVIS_SELECTED;
li.pszText = (PrincipalListItem->DisplayString != NULL ? PrincipalListItem->DisplayString : PrincipalListItem->AccountName);
switch (PrincipalListItem->SidNameUse)
{
case SidTypeUser:
@ -412,7 +420,8 @@ FillPrincipalsList(IN PSECURITY_PAGE sp)
EnableRedrawWindow(sp->hWndPrincipalsList);
GetClientRect(sp->hWndPrincipalsList, &rcLvClient);
GetClientRect(sp->hWndPrincipalsList,
&rcLvClient);
ListView_SetColumnWidth(sp->hWndPrincipalsList,
0,
@ -424,8 +433,10 @@ UpdateControlStates(IN PSECURITY_PAGE sp)
{
PPRINCIPAL_LISTITEM Selected = (PPRINCIPAL_LISTITEM)ListViewGetSelectedItemData(sp->hWndPrincipalsList);
EnableWindow(sp->hBtnRemove, Selected != NULL);
EnableWindow(sp->hAceCheckList, Selected != NULL);
EnableWindow(sp->hBtnRemove,
Selected != NULL);
EnableWindow(sp->hAceCheckList,
Selected != NULL);
if (Selected != NULL)
{
@ -992,13 +1003,16 @@ SecurityPageProc(IN HWND hwndDlg,
sp->hiPrincipals,
LVSIL_SMALL);
GetClientRect(sp->hWndPrincipalsList, &rcLvClient);
GetClientRect(sp->hWndPrincipalsList,
&rcLvClient);
/* add a column to the list view */
lvc.mask = LVCF_FMT | LVCF_WIDTH;
lvc.fmt = LVCFMT_LEFT;
lvc.cx = rcLvClient.right;
ListView_InsertColumn(sp->hWndPrincipalsList, 0, &lvc);
ListView_InsertColumn(sp->hWndPrincipalsList,
0,
&lvc);
ReloadPrincipalsList(sp);
@ -1074,9 +1088,9 @@ HPROPSHEETPAGE
WINAPI
CreateSecurityPage(IN LPSECURITYINFO psi)
{
PROPSHEETPAGE psp;
PROPSHEETPAGE psp = {0};
PSECURITY_PAGE sPage;
SI_OBJECT_INFO ObjectInfo;
SI_OBJECT_INFO ObjectInfo = {0};
HRESULT hRet;
if (psi == NULL)
@ -1090,8 +1104,8 @@ CreateSecurityPage(IN LPSECURITYINFO psi)
/* get the object information from the server. Zero the structure before
because some applications seem to return SUCCESS but only seem to set the
fields they care about. */
ZeroMemory(&ObjectInfo, sizeof(ObjectInfo));
hRet = psi->lpVtbl->GetObjectInformation(psi, &ObjectInfo);
hRet = psi->lpVtbl->GetObjectInformation(psi,
&ObjectInfo);
if (FAILED(hRet))
{
@ -1127,8 +1141,6 @@ CreateSecurityPage(IN LPSECURITYINFO psi)
sPage->psi = psi;
sPage->ObjectInfo = ObjectInfo;
ZeroMemory(&psp, sizeof(psp));
psp.dwSize = sizeof(PROPSHEETPAGE);
psp.dwFlags = PSP_USECALLBACK;
psp.hInstance = hDllInstance;
@ -1169,10 +1181,10 @@ EditSecurity(IN HWND hwndOwner,
IN LPSECURITYINFO psi)
{
HRESULT hRet;
SI_OBJECT_INFO ObjectInfo;
SI_OBJECT_INFO ObjectInfo = {0};
PROPSHEETHEADER psh;
HPROPSHEETPAGE hPages[1];
LPWSTR lpCaption;
LPWSTR lpCaption = NULL;
BOOL Ret;
if (psi == NULL)
@ -1186,8 +1198,8 @@ EditSecurity(IN HWND hwndOwner,
/* get the object information from the server. Zero the structure before
because some applications seem to return SUCCESS but only seem to set the
fields they care about. */
ZeroMemory(&ObjectInfo, sizeof(ObjectInfo));
hRet = psi->lpVtbl->GetObjectInformation(psi, &ObjectInfo);
hRet = psi->lpVtbl->GetObjectInformation(psi,
&ObjectInfo);
if (FAILED(hRet))
{
@ -1213,11 +1225,17 @@ EditSecurity(IN HWND hwndOwner,
/* Set the page title to the object name, make sure the format string
has "%1" NOT "%s" because it uses FormatMessage() to automatically
allocate the right amount of memory. */
LoadAndFormatString(hDllInstance,
IDS_PSP_TITLE,
&lpCaption,
ObjectInfo.pszObjectName);
psh.pszCaption = lpCaption;
if (LoadAndFormatString(hDllInstance,
IDS_PSP_TITLE,
&lpCaption,
ObjectInfo.pszObjectName))
{
psh.pszCaption = lpCaption;
}
else
{
psh.pszCaption = ObjectInfo.pszObjectName;
}
psh.nPages = sizeof(hPages) / sizeof(HPROPSHEETPAGE);
psh.nStartPage = 0;

View file

@ -1,6 +1,6 @@
/*
* ReactOS Access Control List Editor
* Copyright (C) 2004 ReactOS Team
* 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
@ -177,7 +177,8 @@ FindCheckItem(IN PCHECKLISTWND infoPtr,
CurItem = CurItem->Next)
{
if ((CurItem->State & CIS_DISABLED) != CIS_DISABLED &&
!wcsnicmp(CurItem->Name, SearchText, Count))
!wcsnicmp(CurItem->Name,
SearchText, Count))
{
break;
}
@ -762,7 +763,8 @@ PaintControl(IN PCHECKLISTWND infoPtr,
rcUpdate,
(HBRUSH)(COLOR_WINDOW + 1));
GetClientRect(infoPtr->hSelf, &rcClient);
GetClientRect(infoPtr->hSelf,
&rcClient);
ScrollPos = GetScrollPos(infoPtr->hSelf,
SB_VERT);
@ -1204,7 +1206,8 @@ MapItemToRect(IN PCHECKLISTWND infoPtr,
RECT rcClient;
INT VisibleFirst;
GetClientRect(infoPtr->hSelf, &rcClient);
GetClientRect(infoPtr->hSelf,
&rcClient);
VisibleFirst = GetScrollPos(infoPtr->hSelf,
SB_VERT);
@ -1598,8 +1601,11 @@ CheckListWndProc(IN HWND hwnd,
nPage however also includes the partly cropped list
item at the bottom of the control */
GetClientRect(hwnd, &rcClient);
ScrollLines = max(1, (rcClient.bottom - rcClient.top) / infoPtr->ItemHeight);
GetClientRect(hwnd,
&rcClient);
ScrollLines = max(1,
(rcClient.bottom - rcClient.top) / infoPtr->ItemHeight);
if (ScrollInfo.nPos + ScrollLines <= ScrollInfo.nMax)
{
@ -1622,8 +1628,11 @@ CheckListWndProc(IN HWND hwnd,
nPage however also includes the partly cropped list
item at the bottom of the control */
GetClientRect(hwnd, &rcClient);
ScrollLines = max(1, (rcClient.bottom - rcClient.top) / infoPtr->ItemHeight);
GetClientRect(hwnd,
&rcClient);
ScrollLines = max(1,
(rcClient.bottom - rcClient.top) / infoPtr->ItemHeight);
if (ScrollInfo.nPos >= ScrollLines)
{
@ -1753,10 +1762,6 @@ CheckListWndProc(IN HWND hwnd,
}
Ret = TRUE;
}
else
{
Ret = FALSE;
}
break;
}
@ -2165,9 +2170,11 @@ CheckListWndProc(IN HWND hwnd,
if (!infoPtr->FocusVisible)
{
/* change the UI status */
SendMessage(GetAncestor(hwnd, GA_ROOT),
SendMessage(GetAncestor(hwnd,
GA_ROOT),
WM_CHANGEUISTATE,
MAKEWPARAM(UIS_INITIALIZE, UISF_HIDEFOCUS),
MAKEWPARAM(UIS_INITIALIZE,
UISF_HIDEFOCUS),
0);
}
@ -2451,7 +2458,8 @@ CheckListWndProc(IN HWND hwnd,
infoPtr->TextColor[0] = GetSysColor(COLOR_GRAYTEXT);
infoPtr->TextColor[1] = GetSysColor(COLOR_WINDOWTEXT);
GetClientRect(hwnd, &rcClient);
GetClientRect(hwnd,
&rcClient);
infoPtr->CheckBoxLeft[0] = rcClient.right - 30;
infoPtr->CheckBoxLeft[1] = rcClient.right - 15;
@ -2535,7 +2543,7 @@ CheckListWndProc(IN HWND hwnd,
}
BOOL
RegisterCheckListControl(HINSTANCE hInstance)
RegisterCheckListControl(IN HINSTANCE hInstance)
{
WNDCLASS wc;
@ -2545,7 +2553,8 @@ RegisterCheckListControl(HINSTANCE hInstance)
wc.cbWndExtra = sizeof(PCHECKLISTWND);
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(0, (LPWSTR)IDC_ARROW);
wc.hCursor = LoadCursor(NULL,
(LPWSTR)IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = L"CHECKLIST_ACLUI";