pgpclientlib.c
来自「PGP8.0源码 请认真阅读您的文件包然后写出其具体功能」· C语言 代码 · 共 803 行 · 第 1/2 页
C
803 行
/*____________________________________________________________________________
Copyright (C) 2002 PGP Corporation
All rights reserved.
$Id: PGPclientLib.c,v 1.60 2002/10/31 04:13:35 pbj Exp $
____________________________________________________________________________*/
#include "pgpPFLConfig.h"
// project header files
#include "PGPclx.h"
#include "TreeList.h"
#include "DurationControl.h"
#include "IPAddressControl.h"
#include "pgpImageList.h"
#include "pgpFileSpec.h"
#include "pgpRandomPool.h"
#include <zmouse.h>
#include <ole2.h>
#include <time.h>
#include <winsock2.h>
#include <shlwapi.h>
#define IMPORTDLGCLASS ("PGPDLGCLASS")
// DLL globals
UINT g_uRefCount = 0;
PGPContextRef g_context = kInvalidPGPContextRef;
HINSTANCE g_hInst = NULL;
HIMAGELIST g_hilKeys = NULL;
HIMAGELIST g_hilClientLib = NULL;
SHGetFolderPathProc g_fpSHGetFolderPath = NULL;
UINT g_uMouseWheelMessage = 0;
BOOL s_bWinsockInitialized = FALSE;
BOOL s_bLocalSDK = FALSE;
BOOL g_bUnicodeOS = FALSE;
// prototype from pgpPassCach.h
// this function is only needed when using the SDK in local mode
void pgpPassphraseCacheRemoveClient ( PGPUInt32 id );
// ___________________________________________________
//
// Register window class for selective import dialog
// This allows setting the icon to the PGPkeys icon
static VOID
sRegisterSelectiveImportClass (VOID)
{
WNDCLASSEX wc;
// class 0x8002 is the "hardwired" class of standard dialogs
wc.cbSize = sizeof (WNDCLASSEX);
GetClassInfoEx (NULL, MAKEINTRESOURCE(0x8002), &wc);
wc.lpszClassName = IMPORTDLGCLASS;
wc.hIcon = LoadIcon (g_hInst, MAKEINTRESOURCE(IDI_KEYICON));
wc.hInstance = g_hInst;
RegisterClassEx (&wc);
}
// ____________________________________________________________
//
// explicit link to the SHFOLDER.DLL library
PGPError
CLLoadSHFolderGetPath (
LPSTR pszSHFolderPath)
{
if (IsNull (g_fpSHGetFolderPath))
{
HMODULE hmod;
if (IsntNull (pszSHFolderPath))
hmod = LoadLibrary (pszSHFolderPath);
else
hmod = LoadLibrary ("SHFOLDER.DLL");
if (IsNull (hmod))
return kPGPError_Win32_InvalidSHFolder;
if (hmod)
{
g_fpSHGetFolderPath = (SHGetFolderPathProc)
GetProcAddress (hmod, "SHGetFolderPathA");
if (IsNull (g_fpSHGetFolderPath))
return kPGPError_Win32_InvalidSHFolder;
}
}
return kPGPError_NoErr;
}
// ____________________________________________________________
//
// check if proper version of COMCTL32.DLL is installed
#define MIN_MAJORVERSION 4
#define MIN_MINORVERSION 70
static PGPError
sCheckComctl32Version (VOID)
{
PGPError err = kPGPError_NoErr;
HINSTANCE hComCtl;
hComCtl = LoadLibrary ("comctl32.dll");
if (hComCtl)
{
FARPROC pDllGetVersion;
pDllGetVersion = GetProcAddress (hComCtl, "DllGetVersion");
if (pDllGetVersion)
{
DLLVERSIONINFO dvi;
LONG hr; // this should be an HRESULT
ZeroMemory (&dvi, sizeof(dvi));
dvi.cbSize = sizeof(dvi);
hr = (LONG)(*pDllGetVersion)(&dvi);
if (!(hr & 0x01)) // HRESULT returns error in bit 0
{
if (dvi.dwMajorVersion < MIN_MAJORVERSION)
err = kPGPError_Win32_InvalidComctl32;
else if (dvi.dwMajorVersion == MIN_MAJORVERSION)
{
if (dvi.dwMinorVersion < MIN_MINORVERSION)
err = kPGPError_Win32_InvalidComctl32;
}
}
else
err = kPGPError_Win32_InvalidComctl32;
}
else
err = kPGPError_Win32_InvalidComctl32;
FreeLibrary(hComCtl);
}
else
err = kPGPError_Win32_InvalidComctl32;
return err;
}
// ____________________________________________________________
//
// load appropriate imagelists for display
static VOID
sInitImageLists (VOID)
{
HDC hdc;
HBITMAP hbmp;
INT iNumBits;
// create imagelist and load the appropriate bitmaps based on
// current display capabilities.
hdc = GetDC (NULL); // DC for desktop
iNumBits = GetDeviceCaps (hdc, BITSPIXEL) * GetDeviceCaps (hdc, PLANES);
ReleaseDC (NULL, hdc);
if (iNumBits <= 8)
{
g_hilClientLib = ImageList_Create (16, 16,
ILC_COLOR|ILC_MASK, NUM_CLIENTLIB_ICONS, 0);
hbmp = LoadBitmap (g_hInst, MAKEINTRESOURCE (IDB_IMAGES4));
ImageList_AddMasked (g_hilClientLib, hbmp, RGB(255, 0, 255));
DeleteObject (hbmp);
g_hilKeys = ImageList_Create (16, 16,
ILC_COLOR|ILC_MASK, NUM_IMAGELIST_ICONS, 0);
hbmp = LoadBitmap (g_hInst, MAKEINTRESOURCE (IDB_KEYICONS4BIT));
ImageList_AddMasked (g_hilKeys, hbmp, RGB(255, 0, 255));
DeleteObject (hbmp);
}
else
{
g_hilClientLib = ImageList_Create (16, 16,
ILC_COLOR24|ILC_MASK, NUM_CLIENTLIB_ICONS, 0);
hbmp = LoadBitmap (g_hInst, MAKEINTRESOURCE (IDB_IMAGES24));
ImageList_AddMasked (g_hilClientLib, hbmp, RGB(255, 0, 255));
DeleteObject (hbmp);
g_hilKeys = ImageList_Create (16, 16,
ILC_COLOR24|ILC_MASK, NUM_IMAGELIST_ICONS, 0);
hbmp = LoadBitmap (g_hInst, MAKEINTRESOURCE (IDB_KEYICONS24BIT));
ImageList_AddMasked (g_hilKeys, hbmp, RGB(255, 0, 255));
DeleteObject (hbmp);
}
}
// ____________________________________________________________
//
// check if current date is beyond supported range
static PGPError
sCheckCurrentDate (VOID)
{
PGPError err = kPGPError_NoErr;
time_t tTimeNow;
time (&tTimeNow);
if (tTimeNow <= 0)
err = kPGPError_Win32_InvalidCurrentDate;
return err;
}
// ____________________________________________________________
//
// Dialog procedure for driver warning dialog
static BOOL CALLBACK
sDriverWarnDlgProc (
HWND hDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch(uMsg) {
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND :
switch(LOWORD (wParam)) {
case IDOK :
if (IsDlgButtonChecked (hDlg, IDC_NOMOREWARNINGS) == BST_CHECKED)
EndDialog (hDlg, 2);
else
EndDialog (hDlg, 1);
break;
case IDCANCEL :
EndDialog (hDlg, 0);
break;
}
return TRUE;
}
return FALSE;
}
//________________________________________
//
// code to start PGPsdk driver in NT
// driver must already have been copied to
// c:\winnt\system32\drivers directory and
// appropriate registry entries created
#define DRIVERNAME "PGPsdkDriver"
#define DRIVERFILENAME "PGPsdk.sys"
#define DRIVER_NO_ERROR 0
#define DRIVER_NOT_WINNT 1
#define DRIVER_ACCESS_ERROR 2
#define DRIVER_CREATE_FAIL 3
#define DRIVER_ALREADY_STARTED 4
#define DRIVER_MISC_ERROR 5
static PGPError
sStartUtilDriver (VOID)
{
PGPError err = kPGPError_UnknownError;
SC_HANDLE schSCMan = NULL;
SC_HANDLE schServ = NULL;
DWORD dwErr;
BOOL bRet;
PGPclWindowsFamily family;
SERVICE_STATUS ss;
CHAR szPath[MAX_PATH];
// check if we're running under NT
PGPclGetWindowsVersion (&family, NULL, NULL);
if (family != kPGPclWindowsFamilyNT)
{
err = DRIVER_NOT_WINNT;
goto done;
}
// open service control manager
schSCMan = OpenSCManager (NULL, NULL, SC_MANAGER_CREATE_SERVICE);
if (schSCMan == NULL)
{
dwErr = GetLastError();
if (dwErr == ERROR_ACCESS_DENIED)
{
err = DRIVER_ACCESS_ERROR;
goto done;
}
else
{
err = DRIVER_MISC_ERROR;
goto done;
}
}
// OK, success open of service control manager
else {
// try to open service
schServ = OpenService (schSCMan, DRIVERNAME,
SERVICE_START|SERVICE_QUERY_STATUS);
if (schServ == NULL)
{
// couldn't open service
dwErr = GetLastError ();
if (dwErr != ERROR_SERVICE_DOES_NOT_EXIST)
{
err = DRIVER_MISC_ERROR;
goto done;
}
// try to create new service ...
GetSystemDirectory (szPath, sizeof(szPath));
if (szPath[lstrlen (szPath) -1] != '\\')
lstrcat (szPath, "\\");
lstrcat (szPath, "drivers\\");
lstrcat (szPath, DRIVERFILENAME);
schServ = CreateService (schSCMan, DRIVERNAME, DRIVERNAME,
SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER,
SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
szPath, NULL, NULL, NULL, NULL, NULL);
if (schServ == NULL)
{
err = DRIVER_CREATE_FAIL;
goto done;
}
}
bRet = QueryServiceStatus (schServ, &ss);
if (!bRet)
{
err = DRIVER_MISC_ERROR;
goto done;
}
if (ss.dwCurrentState == SERVICE_STOPPED)
{
bRet = StartService (schServ, 0, NULL);
if (!bRet) {
dwErr = GetLastError ();
err = DRIVER_MISC_ERROR;
goto done;
}
}
else
{
err = DRIVER_ALREADY_STARTED;
goto done;
}
}
err = DRIVER_NO_ERROR;
done :
// cleanup service handle
if (schServ)
CloseServiceHandle (schServ);
// clean up service control manager
if (schSCMan)
CloseServiceHandle (schSCMan);
return err;
}
// ____________________________________________________________
//
// check if page-locking driver is working by attempting to lock memory
static PGPError
sCheckMemoryLockingDriver (VOID)
{
PGPError err = kPGPError_NoErr;
PGPContextRef context = kInvalidPGPContextRef;
PGPPrefRef prefs = kInvalidPGPPrefRef;
PGPBoolean bWarn = TRUE;
PGPFlags flags = 0;
LPVOID pmem = NULL;
INT iret = 0;
err = PGPNewContext (kPGPsdkAPIVersion, &context); CKERR;
pmem = PGPNewSecureData (PGPPeekContextMemoryMgr (context), 32, 0);
if (!pmem)
{
err = kPGPError_OutOfMemory;
goto done;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?