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

📄 accessenum.cpp

📁 查看文件可被那些用户使用,然后列出清单。进行查询。
💻 CPP
📖 第 1 页 / 共 4 页
字号:
					delete Child;
					Child = Root->FindNext( &status );
				}
			}
		}

		delete sd;
	}

	void Work()
	{
		// Enumerate files in the directory
		bool	isDir = m_Root->IsDir();

		// Get permissions
		const ACCOUNT * Account[2] = { UNDEFINED_ACCOUNT, NULL };
		Enumerate( m_Root, Account, Account, Account );

		// restore original path
		SetDlgItemText( GetParent(m_hListview), IDC_PATH, m_Root->Path() );

		CWorker::Work();
	} // Work

}; // CTraversal






bool ExportFile( HWND hListView, const TCHAR * path )
{
	HANDLE	hFile = CreateFile( path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
	if ( hFile == INVALID_HANDLE_VALUE )
		return false;

	LV_ITEM		lvi;
	DWORD		nb;

	// Mark file as unicode
#if UNICODE
	WORD uni = 0xFEFF;
	WriteFile( hFile, &uni, sizeof uni, &nb, NULL );
#endif

	// print headers
	for ( lvi.iSubItem = 0; lvi.iSubItem < sizeof(Columns)/sizeof(Columns[0])-1; ++lvi.iSubItem )  {
		WriteFile( hFile, _T("\""), sizeof(TCHAR), &nb, NULL );
		WriteFile( hFile, Columns[lvi.iSubItem].Title, _tcslen(Columns[lvi.iSubItem].Title)*sizeof(TCHAR), &nb, NULL );
		WriteFile( hFile, _T("\"\t"), 2*sizeof(TCHAR), &nb, NULL );
	}
	WriteFile( hFile, _T("\r\n"), 2*sizeof(TCHAR), &nb, NULL );

	// Get text
	int	max = ListView_GetItemCount( hListView );

	for ( lvi.iItem = 0; lvi.iItem < max; ++lvi.iItem )  {

		// Get item
		lvi.mask = TVIF_TEXT;

		for ( lvi.iSubItem = 0; lvi.iSubItem < sizeof(Columns)/sizeof(Columns[0])-1; ++lvi.iSubItem )  {

			TCHAR Item[ MAX_TEXT ];
			lvi.pszText		= Item;
			lvi.cchTextMax	= MAX_TEXT;

			if ( ! ListView_GetItem( hListView, &lvi ) )
				*Item = 0;

			for ( int i = 0; Item[i]; ++i )
				if ( Item[i] == ',' && Item[i+1] == ' ' )  {
					Item[i] = ' ';
					Item[i+1] = 0x0A;
				}

			WriteFile( hFile, _T("\""), sizeof(TCHAR), &nb, NULL );
			WriteFile( hFile, Item, _tcslen(Item)*sizeof(TCHAR), &nb, NULL );
			WriteFile( hFile, _T("\"\t"), 2*sizeof(TCHAR), &nb, NULL );
		}

		WriteFile( hFile, _T("\r\n"), 2*sizeof(TCHAR), &nb, NULL );
	}

	CloseHandle( hFile );

	return true;
}




void PrintAllRecurse( CEnumeration * parent )
{
	PSECURITY_DESCRIPTOR sd = parent->GetSecurity();
	delete sd;
	for (;;)  {
		DWORD	status;
		CEnumeration * child = parent->FindNext( &status );
		if ( child == NULL )
			break;
		PrintAllRecurse( child );
		delete child;
	}
}
void PrintAll()
{
	CFileEnumeration	file( _T("C:"), true );
	CRegEnumeration		reg( _T("SOFTWARE"), true );

	PrintAllRecurse( &reg );
	PrintAllRecurse( &file );
}








INT_PTR CALLBACK AbortDialog( HWND hDlg, UINT message, UINT wParam, LONG lParam ) 
{
	RECT	parentRc, childRc;

	switch ( message )  {
		case WM_INITDIALOG:
			GetWindowRect( GetParent(hDlg), &parentRc );
			GetWindowRect( hDlg, &childRc );
			parentRc.left = ((parentRc.left + parentRc.right) - (childRc.right - childRc.left)) / 2;
			parentRc.top  = ((parentRc.top + parentRc.bottom) - (childRc.bottom - childRc.top)) / 2;
			MoveWindow( hDlg, parentRc.left, parentRc.top, childRc.right - childRc.left, childRc.bottom - childRc.top, TRUE );
			return TRUE;

		case WM_CLOSE:
			EndDialog( hDlg, 0 );
			return TRUE;

		default:
			break;
	}
    return FALSE;

}


INT_PTR CALLBACK AboutDialog( HWND hDlg, UINT message, UINT wParam, LONG lParam ) 
{
	RECT	parentRc, childRc;
	static HWND		hLink;
	static BOOL		underline_link;
	static HFONT	hFontNormal = NULL;
	static HFONT	hFontUnderline = NULL;
	static HCURSOR	hHandCursor = NULL;
	static HCURSOR	hRegularCursor;
	LOGFONT			logfont;

	switch ( message )  {
	case WM_INITDIALOG:
		GetWindowRect( GetParent(hDlg), &parentRc );
		GetWindowRect( hDlg, &childRc );
		parentRc.left += 70;
		parentRc.top  += 60;
		MoveWindow( hDlg, parentRc.left, parentRc.top, childRc.right - childRc.left, childRc.bottom - childRc.top, TRUE );

		underline_link = TRUE;
		hLink = GetDlgItem( hDlg, IDC_LINK );

		// get link fonts
		hFontNormal = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
		GetObject( hFontNormal, sizeof logfont, &logfont); 
		logfont.lfUnderline = TRUE;
		hFontUnderline = CreateFontIndirect( &logfont );

		// get hand
		hHandCursor = LoadCursor( g.hInst, TEXT("HAND") );
		hRegularCursor = LoadCursor( NULL, IDC_ARROW );
		return TRUE;

	case WM_CTLCOLORSTATIC:
		if ( (HWND)lParam == hLink )  {
			HDC	hdc = (HDC)wParam;
			SetBkMode( hdc, TRANSPARENT );
			if ( GetSysColorBrush(26/*COLOR_HOTLIGHT*/) )
				SetTextColor( hdc, GetSysColor(26/*COLOR_HOTLIGHT*/) );
			else
				SetTextColor( hdc, RGB(0,0,255) );
			SelectObject( hdc, underline_link ? hFontUnderline : hFontNormal );
			return (LONG)GetSysColorBrush( COLOR_BTNFACE );
		}
		break;

	case WM_MOUSEMOVE: {
		POINT	pt = { LOWORD(lParam), HIWORD(lParam) };
		HWND	hChild = ChildWindowFromPoint( hDlg, pt );
		if ( underline_link == (hChild == hLink) )  {
			underline_link = !underline_link;
			InvalidateRect( hLink, NULL, FALSE );
		}
		if ( underline_link )
			SetCursor( hRegularCursor );
		else
			SetCursor( hHandCursor );
		break;
	}

	case WM_LBUTTONDOWN: {
		POINT		pt = { LOWORD(lParam), HIWORD(lParam) };
		HWND		hChild = ChildWindowFromPoint( hDlg, pt );
		if ( hChild == hLink )  {
			ShellExecute( hDlg, TEXT("open"), TEXT("http://www.sysinternals.com"), NULL, NULL, SW_SHOWNORMAL );
		} 
		break;
	}

	case WM_COMMAND:
		switch ( wParam ) {
		case IDOK:
		case IDCANCEL:
			EndDialog( hDlg, 0 );
			return TRUE;
		}
		break; 

	case WM_CLOSE:
		EndDialog( hDlg, 0 );
		return TRUE;

	default:
		break;
	}
    return FALSE;

}

INT_PTR CALLBACK FilePermDialog( HWND hDlg, UINT message, UINT wParam, LONG lParam ) 
{
	switch ( message )  {
		case WM_INITDIALOG:
			CheckDlgButton( hDlg, IDYES, g.ShowAllFiles ? BST_CHECKED : BST_UNCHECKED );
			CheckDlgButton( hDlg, IDNO, !g.ShowAllFiles ? BST_CHECKED : BST_UNCHECKED );
			return true;
		case WM_COMMAND:
			switch ( LOWORD(wParam) )  {
				case IDOK:
					g.ShowAllFiles = IsDlgButtonChecked( hDlg, IDYES ) == BST_CHECKED;
				case IDCANCEL:
					EndDialog( hDlg, 0 );
					break;
			}
			break;

	}
	return false;
}

INT_PTR CALLBACK HelpDialog( HWND hDlg, UINT message, UINT wParam, LONG lParam ) 
{
	static const TCHAR HelpText[] = 
		_T("AccessEnum displays who has access to the files and folders within a directory. Although every ")
		_T("file/directory is examined, AccessEnum displays only those with permissions that differ from ")
		_T("their parent folder, allowing you to quickly determine deviations in your security policy.")
		_T("\r\n\r\n")
		_T("AccessEnum abstracts Window's access-control model to just Read, Write and Deny permissions. ")
		_T("A file is shown as granting Write permission whether it grants just a single write right (such ")
		_T("as Write Owner) or the full suite of write rights via Full Control. Read and Deny permissions ")
		_T("are handled similarly.")
		_T("\r\n\r\n")
		_T("When AccessEnum compares a file/folder and its parent to determine whether their permissions ")
		_T("are equivalent, it looks only at whether the same set of accounts are granted Read, Write and ")
		_T("Deny access respectively. If a file grants just Write Owner access, and its parent just Delete ")
		_T("access, the two will still be considered equivalent since both allow some form of writing.")
		_T("\r\n\r\n")
		_T("AccessEnum condenses the number of accounts displayed as having access to a file/folder by ")
		_T("hiding accounts with permissions that are duplicated by a group to which the account belongs. ")
		_T("For example, if a file grants Read access to both user Bob and group Marketing, and Bob is a ")
		_T("member of the Marketing group, then only Marketing will be shown in the list of accounts having ")
		_T("Read access.")
		_T("\r\n\r\n")
		_T("AccessEnum handles files slightly differently than folders. When comparing the permissions of a ")
		_T("file to its parent the file is displayed only when its permissions are less strict than the parent ")
		_T("folder. You can change this behavior using the Options menu.");

	switch ( message )  {
		case WM_INITDIALOG:
			SetDlgItemText( hDlg, IDC_EDIT, HelpText );
			return true;
		case WM_COMMAND:
			switch ( LOWORD(wParam) )  {
				case IDOK:
				case IDCANCEL:
					EndDialog( hDlg, 0 );
					break;
			}
			break;

	}
	return false;
}



_bstr_t GetTreePath( HWND hTree, HTREEITEM hItem )
{
	_bstr_t	Path;
	for (;;)  {	
		TVITEM	tvi;
		TCHAR	Name[ MAX_UNCPATH ];
		tvi.mask		= TVIF_TEXT;
		tvi.hItem		= hItem;
		tvi.pszText		= Name;
		tvi.cchTextMax	= MAX_UNCPATH;
		TreeView_GetItem( hTree, &tvi );
		Path = Name + Path;

		hItem = TreeView_GetParent( hTree, hItem );
		if ( hItem == NULL )
			return Path;
		Path = _T("\\") + Path;
	}
}


INT_PTR CALLBACK BrowseRegDialog( HWND hDlg, UINT message, UINT wParam, LONG lParam ) 
{
	HWND				hTree;
	TVINSERTSTRUCT		tvi;
	int					i;
	NMHDR			*	nmhdr;
	HIMAGELIST			hImageList;
	static _bstr_t	*	ReturnPath;

	static const TCHAR	*	Root[] = {
		_T("HKEY_CLASSES_ROOT"),
		_T("HKEY_CURRENT_USER"),
		_T("HKEY_LOCAL_MACHINE"),
		_T("HKEY_USERS"),
		_T("HKEY_CURRENT_CONFIG")
	};

	switch ( message )  {
		case WM_INITDIALOG:
			ReturnPath = (_bstr_t *) lParam;
			hTree = GetDlgItem( hDlg, IDC_TREE );
			// create images for nodes
			hImageList = ImageList_Create( 16, 16, ILC_COLOR | ILC_MASK, 4, 4 );
			ImageList_AddIcon( hImageList, LoadIcon( g.hInst, MAKEINTRESOURCE(IDI_FOLDERCLOSED) ) );
			ImageList_AddIcon( hImageList, LoadIcon( g.hInst, MAKEINTRESOURCE(IDI_FOLDEROPEN) ) );
			TreeView_SetImageList( hTree, hImageList, TVSIL_NORMAL );
			// add root entries
			for ( i = 0; i < 5; ++i )  {
				tvi.hParent				= TVI_ROOT;
				tvi.hInsertAfter		= TVI_LAST;
				tvi.item.mask			= TVIF_TEXT | TVIF_CHILDREN | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
				tvi.item.pszText		= (TCHAR *) Root[i];
				tvi.item.cChildren		= I_CHILDRENCALLBACK;
				tvi.item.iImage			= 0;
				tvi.item.iSelectedImage	= 1;
				tvi.item.lParam			= false;	// not expanded yet
				TreeView_InsertItem( hTree, &tvi );
			}
			EnableWindow( GetDlgItem( hDlg, IDOK ), false );
			return false;

		case WM_NOTIFY:
			nmhdr = (NMHDR *) lParam;
			if ( nmhdr->code == TVN_SELCHANGED )  {
				EnableWindow( GetDlgItem( hDlg, IDOK ), true );
			}
			
			if ( nmhdr->code == TVN_GETDISPINFO )  {
				NMTVDISPINFO	*	tvnm = (NMTVDISPINFO *) nmhdr;
				if ( tvnm->item.mask & TVIF_CHILDREN )  {
					// Get number of children in key
					_bstr_t	Path = GetTreePath( GetDlgItem( hDlg, IDC_TREE ), tvnm->item.hItem );
					HKEY hKey = CRegEnumeration::OpenPath( Path, NULL );
					tvnm->item.cChildren = 0;
					RegQueryInfoKey( hKey, NULL, NULL, NULL, (DWORD *)&tvnm->item.cChildren, NULL, NULL, NULL, NULL, NULL, NULL, NULL );
					RegCloseKey( hKey );
				}
			}

			if ( nmhdr->code == TVN_ITEMEXPANDING )  {
				NMTREEVIEW *	tvnm = (NMTREEVIEW *) nmhdr;

				if ( tvnm->action == TVE_EXPAND  &&  tvnm->itemNew.lParam == 0 )  {
					// add children to parent
					hTree = GetDlgItem( hDlg, IDC_TREE );
					_bstr_t Path = GetTreePath( hTree, tvnm->itemNew.hItem );
					HKEY hKey = CRegEnumeration::OpenPath( Path, NULL );
					TCHAR	Name[ MAX_PATH ];
					for ( int i = 0; RegEnumKey( hKey, i, Name, MAX_PATH ) == 0; ++i )  {
						TVINSERTSTRUCT	tvi;
						tvi.hParent				= tvnm->itemNew.hItem;
						tvi.hInsertAfter		= TVI_LAST;
						tvi.item.mask			= TVIF_TEXT | TVIF_CHILDREN | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
						tvi.item.pszText		= Name;
						tvi.item.cChildren		= I_CHILDRENCALLBACK;
						tvi.item.iImage			= 0;
						tvi.item.iSelectedImage	= 1;
						tvi.item.lParam			= false;	// not expanded yet
						TreeView_InsertItem( hTree, &tvi );
					}
					RegCloseKey( hKey );
					// mark parent as expanded
					TVITEM	tvi;
					tvi.mask		= TVIF_CHILDREN | TVIF_PARAM;
					tvi.hItem		= tvnm->itemNew.hItem;
					tvi.cChildren	= i;
					tvi.lParam		= true;	// expanded 
					TreeView_SetItem( hTree, &tvi );
				}
			}
			break;

		case WM_COMMAND:
			switch ( LOWORD(wParam) )  {
				case IDOK:
					hTree = GetDlgItem( hDlg, IDC_TREE );
					*ReturnPath = GetTreePath( hTree, TreeView_GetSelection( hTree ) );
					EndDialog( hDlg, 1 );
					break;

				case IDCANCEL:
					EndDialog( hDlg, 0 );
					break;
			}
			break;

	}
	return false;
}

_bstr_t	GetTreeItemText( HWND hTree, int Item, int SubItem )
{
	// apparently there is no way to determine the length of the text in a list view
	TCHAR	tmp[ 64 * 1024 ];

	LVITEM	lvi;
	lvi.mask		= LVIF_TEXT;
	lvi.iItem		= Item;
	lvi.iSubItem	= SubItem;
	lvi.pszText		= tmp;
	lvi.cchTextMax	= sizeof tmp/sizeof tmp[0];

⌨️ 快捷键说明

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