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

📄 cpgpdiskmounterimpwin32.cpp

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 CPP
字号:
/*____________________________________________________________________________
		Copyright (C) 2002 PGP Corporation
        All rights reserved.

        $Id: CPGPdiskMounterImpWin32.cpp,v 1.28 2002/11/20 16:49:00 pbj Exp $
____________________________________________________________________________*/

#include "pgpClassesConfig.h"

#include "CArray.h"
#include "CFile.h"
#include "CSecureString.h"

#include "CMessageBox.h"
#include "COpenFileDialog.h"
#include "CPath.h"
#include "UWinVersion.h"

#include "UCommonStrings.h"
#include "CPGPclPrefs.h"
#include "CPGPdiskEngine.h"

#include "CPassphraseDialog.h"
#include "CPGPdiskChooser.h"
#include "CPGPdiskMounterImpWin32.h"
#include "PGPdiskUIPriv.h"
#include "SClaimedCommand.h"
#include "UEditMount.h"
#include "UMountPoint.h"

#include "pgpClientErrors.h"

#include "pgplnlib.h"

_USING_PGP

// Class CPGPdiskMounterImpWin32 member functions

void 
CPGPdiskMounterImpWin32::AskMount(
	const CPGPdiskContext&	context, 
	const char				*path, 
	void					*parentWnd, 
	const CPGPdiskUser		*pUseThisUser, 
	PGPBoolean				tryCache)
{
	using namespace UCommonStrings;
	pgpAssertStrValid(path);

	// Need valid parentWnd window.
	HWND	hwndParent	= static_cast<HWND>(parentWnd);

	if (IsNull(hwndParent))
		hwndParent = CWindow::GetDesktopWindow();

	if (!PGPlnPGPdiskEnabled())
	{
//		CMessageBox	messageBox;
//		messageBox.Display(Get(kTellNoDiskLicense), 
//			Get(kGenericMsgBoxTitle), hwndParent);

		PGPclNoLicense(hwndParent,kPGPclPGPdisk);

		THROW_PGPERROR(kPGPError_UserAbort);
	}

	// Need valid path.
	CPath	cpath(path);
	cpath.Canonicalize(kPGPdiskFileExtension);

	// Check uniqueness of current command.
	SClaimedCommand	command(CCommandClaimer::kMountDisk, cpath);

	// If the PGPdisk file is mounted already, show its window.
	CPGPdiskDiskSet		diskSet(context);
	CPGPdiskDiskIter	diskIter(diskSet);
	CPGPdiskDisk		disk;
/*
	if (diskIter.SearchOnPath(cpath, disk) || 
		diskIter.SearchOnRoot(cpath, disk))
	{
		CPath	root;
		disk.GetRoot(root);

		try
		{
			CPGPclPrefs	prefs(context.PGPclPrefs());

			if (prefs.GetBoolean(kPGPPrefDiskBrowseAfterMount))
				root.Browse();
		}
		catch (CComboError&) { }

//		root.Browse();
		THROW_PGPERROR(kPGPError_UserAbort);
	}*/

	// Novell idiocy?
	if (UWinVersion::IsWin95Compatible() && 
		CFile::IsFileInUseByWriter(cpath))
	{
		CString	fileSys;
		cpath.GetVolumeFileSys(fileSys);

		if ((fileSys == "DOS") || (fileSys == "NWFS"))
		{
			CMessageBox	messageBox;
			messageBox.Display(Get(kTellMustRemountNovellDisk), 
				Get(kGenericMsgBoxTitle), hwndParent);

			THROW_PGPERROR(kPGPError_UserAbort);
		}
		// the else case is handled by the PGPdiskEngine...
	}

	// Should we force a read-only mount?
	PGPBoolean	forceReadOnly	= UEditMount::ShouldWeForceReadOnly(cpath, 
		hwndParent);

	// Open the PGPdisk.
	disk.Open(context, cpath, TRUE);

	// Check for additional incompatibilities.
	if (!forceReadOnly)
		forceReadOnly = IsDangerOfHangWithReadWrite(cpath, hwndParent);

	// Check for in-progress re-encryptions.
	UEditMount::DetectAndHandleInProgressReEncrypts(context, disk, cpath, 
		hwndParent);

	// Check for wiped PGPdisks.
	UEditMount::DetectAndHandleWipedPGPdisks(context, disk, cpath, 
		hwndParent);

	// Check for older PGPdisks.
	UEditMount::DetectAndHandleOldPGPdisks(context, disk, cpath, hwndParent, 
		forceReadOnly);

	// Get the passphrase.
	CommonString	passStr;
	CPGPdiskUserSet	userSet;
	CString			passSubString;

	if (IsntNull(pUseThisUser))
	{
		userSet.CreateSingleton(*pUseThisUser);

		passStr = kSinglePassUserText;
		pUseThisUser->GetUserName(passSubString);
	}
	else
	{
		disk.ExportUserSet(userSet);

		CPath	fileName;
		cpath.GetDisplayFileName(fileName);

		passStr = kSinglePassMountText;
		passSubString = fileName;
	}

	// check for cached private keys
	CPGPdiskUserIter	userIter(userSet);
	CPGPdiskUser		user;
	PGPBoolean			useCachedPKUser	= FALSE;

	while (tryCache && userIter.Next(user))
	{
		if (user.HasPublicKey())
		{
			try
			{
				user.EnableCiphering(disk, NULL, 0);
				useCachedPKUser = TRUE;
				break;
			}
			catch (CComboError&) { }
		}
	}

	// get information for mount
	PGPBoolean	readOnly;
	CPath		root;

	if (useCachedPKUser)
	{
		// Added forceReadOnly so that cached PK users will mount
		// disks correctly -wjb
		readOnly = user.IsReadOnly() || forceReadOnly;

		disk.GetDefaultRoot(root);
		UMountPoint::FixWarnRoot(root, FALSE, TRUE);
	}
	else
	{
		CPassphraseDialog	anyPassDlg;

		anyPassDlg.AskForPassphrase(disk, userSet, hwndParent, user, 
			Get(passStr), passSubString, TRUE, forceReadOnly, forceReadOnly);

		readOnly = anyPassDlg.ReadOnly();
		root = anyPassDlg.Root();
	}

	// attempt the actual mount
	disk.Close();

	try
	{
		diskSet.Mount(cpath, user, root, readOnly, disk);
	}
	// Second chance ADK users on NTFS 65DISKFIX -wjb
	catch (CComboError& error)
	{
		if (error.pgpErr == kPGPClientError_DiskTriedReadOnlyNTFS)
		{
			CPGPKey	adkKey;
			CPGPKeyID adkKeyID;
			CPGPKeyID userKeyID;
			
			if (!(context.IsThereADK()))
			{
				throw;
			}

			context.GetADK(adkKey);

			adkKey.GetKeyID(adkKeyID);	
			user.GetPGPKeyID(userKeyID);

			if (userKeyID.IsEqual(adkKeyID))
			{
				readOnly=FALSE;

				error.pgpErr=kPGPError_NoErr;

				user.SetIsReadOnly(FALSE);

				diskSet.Mount(cpath, user, root, readOnly, disk);
			}
			else
			{
				throw;
			}
		}
	}
	// End ADK testing
}

void 
CPGPdiskMounterImpWin32::MountStartupDisks(
	const CPGPdiskContext&	context, 
	void					*parentWnd)
{
	using namespace UCommonStrings;

	// need valid parentWnd window
	HWND	hwndParent	= static_cast<HWND>(parentWnd);

	if (IsNull(hwndParent))
		hwndParent = CWindow::GetDesktopWindow();

	// check uniqueness of current command.
	SClaimedCommand	command(CCommandClaimer::kMountStartupDisks, NULL);

	// get startup paths
	CPGPclPrefs	clPrefs(context.PGPclPrefs());
	CString		pathGlob;

	clPrefs.GetString(kPGPPrefDiskMountAtStartupPaths, pathGlob);

	CArray<CPath>	pathArray;
	PGPUInt32		numPaths;

	UEditMount::GetStartupPathArray(pathGlob, pathArray, numPaths);

	// validate the paths
	CArray<CPath>	newPathArray;
	PGPUInt32		i, newNumPaths	= 0;
	
	for (i = 0; i < numPaths; i++)
	{
		PGPBoolean	isValid		= FALSE;
		PGPBoolean	unmarkIt	= FALSE;

		CPath	curPath	= pathArray[i];

		try {
			curPath.Canonicalize(kPGPdiskFileExtension);
			isValid = TRUE;
		}
		catch (CComboError&) { }

		if (!isValid)
		{
			// it's bad, complain
			CString	warnPhrase;
			warnPhrase.Format(Get(kTellBadMountStartupPath), curPath);

			CMessageBox	messageBox;
			CMessageBox::Button	result	= messageBox.Display(
				warnPhrase, Get(kGenericMsgBoxTitle), NULL, 
				CMessageBox::kWarningTone, CMessageBox::kYesNoCancelStyle, 
				CMessageBox::kYesButton);

			if (result == CMessageBox::kYesButton)
			{
				try
				{
					CPGPdiskChooser	diskChooser;

					diskChooser.AskChoose(context, curPath, NULL, NULL, 
						hwndParent);

					isValid = TRUE;
				}
				catch (CComboError&) { }
			}
			else if (result == CMessageBox::kNoButton)
			{
				unmarkIt = TRUE;
			}
		}

		if (isValid)
		{
			// it's good or been made good, perform the mount
			try
			{
				AskMount(context, curPath, hwndParent, NULL, TRUE);
			}
			catch (CComboError& error)
			{
				ReportError(kTellDiskMountFailed, kGenericMsgBoxTitle, error);
			}
		}

		if (!unmarkIt)
		{
			// keep this one around
			newPathArray.Resize(newNumPaths + 1);
			newPathArray[newNumPaths++] = curPath;
		}
	}

	// reglob
	UEditMount::MakeStartupPathGlob(newPathArray, newNumPaths, pathGlob);

	// update the pref
	clPrefs.Open();	// refresh prefref
	clPrefs.SetString(kPGPPrefDiskMountAtStartupPaths, pathGlob);
	clPrefs.Flush();
}

PGPBoolean 
CPGPdiskMounterImpWin32::IsDangerOfHangWithReadWrite(
	const CPath&	path, 
	HWND			parentWnd)
{
	PGPBoolean	isDanger	= FALSE;

	// If path is UNC and server name is local computer, force
	// read-only at this point (obscure incompatibility).

	if (path.IsUNCPath() && UWinVersion::IsWinNT4Compatible())
	{
		CPath	server;
		path.GetServerPart(server);

		CString		computerName;
		DWORD		maxCNSize	= MAX_COMPUTERNAME_LENGTH + 1;

		GetComputerName(computerName.GetBuffer(maxCNSize), &maxCNSize);

		if (server.CompareNoCase(computerName))
		{
			using namespace UCommonStrings;

			CMessageBox	messageBox;
			messageBox.Display(Get(kTellForceROOnLoopback), 
				Get(kGenericMsgBoxTitle), parentWnd, 
				CMessageBox::kWarningTone);

			isDanger = TRUE;
		}
	}
	

	return isDanger;
}

⌨️ 快捷键说明

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