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

📄 pnoption.c

📁 vc环境下的pgp源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*____________________________________________________________________________
	Copyright (C) 1998 Network Associates, Inc.
	All rights reserved.
	
	PGPoption.c - PGPnet options property sheet handler
	

	$Id: PNoption.c,v 1.70.4.1.2.1 1999/06/29 18:46:09 pbj Exp $
____________________________________________________________________________*/

#include <windows.h>
#include <commctrl.h>
#include "resource.h"
#include "PGPnetApp.h"
#include "pgpNetIPC.h"
#include "pgpNetPaths.h"
#include "PGPcl.h"
#include "pgpClientLib.h"
#include "DurationControl.h"
#include "PGPnetHelp.h"

#include "pgpBuildFlags.h"

#include "pgpKeys.h"
#include "pgpMem.h"
#include "pgpSDKPrefs.h"

#define MINIKEMEGABYTES			4
#define MAXIKEMEGABYTES			4095
#define MAXIKEMEGABYTESDIGITS	4

#define MINIPSECMEGABYTES		4
#define MAXIPSECMEGABYTES		4095
#define MAXIPSECMEGABYTESDIGITS	4

#define MINEXPIRESECONDS		60

extern HINSTANCE			g_hinst;
extern PGPContextRef		g_context;
extern APPOPTIONSSTRUCT		g_AOS;
extern CHAR					g_szHelpFile[];				
extern BOOL					g_bReadOnly;	
extern BOOL					g_bAuthAccess;	
extern HWND					g_hwndOptions;

static DWORD aGeneralIds[] = {			// Help IDs
	IDC_EXPERTMODE,				IDH_PNOPTGEN_EXPERTMODE,
	IDC_ALLOWUNCONFIGURED,		IDH_PNOPTGEN_ALLOWUNCONFIGHOSTS,
	IDC_REQUIRESECURE,			IDH_PNOPTGEN_REQSECUREHOSTS,
	IDC_REQUIREVALIDKEY,		IDH_PNOPTGEN_REQUIREVALIDKEY,
	IDC_ENABLECACHE,			IDH_PNOPTGEN_CACHEPASSPHRASES,
	IDC_ENABLEIKETIMEEXPIRE,	IDH_PNOPTGEN_IKETIMEEXPIREENABLE,
	IDC_IKETIMEEXPIRE,			IDH_PNOPTGEN_IKETIMEEXPIRETIME,
	IDC_ENABLEIKEBYTEEXPIRE,	IDH_PNOPTGEN_IKEDATAEXPIREENABLE,
	IDC_IKEBYTES,				IDH_PNOPTGEN_IKEDATAEXPIREBYTES,
	IDC_ENABLEIPSECTIMEEXPIRE,	IDH_PNOPTGEN_IPSECTIMEEXPIREENABLE,
	IDC_IPSECTIMEEXPIRE,		IDH_PNOPTGEN_IPSECTIMEEXPIRETIME,
	IDC_ENABLEIPSECBYTEEXPIRE,	IDH_PNOPTGEN_IPSECDATAEXPIREENABLE,
	IDC_IPSECBYTES,				IDH_PNOPTGEN_IPSECDATAEXPIREBYTES,
	0,0
};

static DWORD aAuthIds[] = {			// Help IDs
	IDC_PUBRING,				IDH_PNOPTAUTH_PUBKEYRING,
	IDC_PUBRINGBROWSE,			IDH_PNOPTAUTH_BROWSEPUBKEYRING,
	IDC_SECRING,				IDH_PNOPTAUTH_SECKEYRING,
	IDC_SECRINGBROWSE,			IDH_PNOPTAUTH_BROWSESECKEYRING,
	IDC_SETTOCURRENT,			IDH_PNOPTAUTH_USEMYKEYRINGS,
    IDC_PGPKEYLIST,				IDH_PNOPTAUTH_PGPAUTHKEY, 
	IDC_CLEARPGPKEY,			IDH_PNOPTAUTH_CLEARPGPAUTHKEY,
	IDC_SELECTPGPKEY,			IDH_PNOPTAUTH_SELECTPGPAUTHKEY,
	IDC_X509KEYEDIT,			IDH_PNOPTAUTH_X509AUTHKEY,
	IDC_CLEARX509KEY,			IDH_PNOPTAUTH_CLEARX509AUTHKEY,
	IDC_SELECTX509KEY,			IDH_PNOPTAUTH_SELECTX509AUTHKEY,
	0,0
};


//	____________________________________
//
//	general options dialog proc

static BOOL CALLBACK
sGenOptionsDlgProc (
		HWND	hwnd, 
		UINT	uMsg, 
		WPARAM	wParam, 
		LPARAM	lParam)
{
	POPTIONSSTRUCT	pos;

	switch (uMsg)
	{
	case WM_INITDIALOG :
	{
		RECT		rc;
		UINT		u;
		CHAR		sz[8];

		SetWindowLong (hwnd, GWL_USERDATA, ((PROPSHEETPAGE*)lParam)->lParam);
		pos = (POPTIONSSTRUCT)GetWindowLong (hwnd, GWL_USERDATA);

		g_hwndOptions = hwnd;

		// initialize the check boxes and radio buttons
		if (g_AOS.pnconfig.bRequireValidKey)
			CheckDlgButton (hwnd, IDC_REQUIREVALIDKEY, BST_CHECKED);
		else
			CheckDlgButton (hwnd, IDC_REQUIREVALIDKEY, BST_UNCHECKED);

		if (g_AOS.pnconfig.bAllowUnconfigHost) 
		{
			CheckDlgButton (hwnd, IDC_ALLOWUNCONFIGURED, BST_CHECKED);
			EnableWindow (GetDlgItem (hwnd, IDC_REQUIRESECURE), TRUE);
		}
		else
		{
			CheckDlgButton (hwnd, IDC_ALLOWUNCONFIGURED, BST_UNCHECKED);
			EnableWindow (GetDlgItem (hwnd, IDC_REQUIRESECURE), FALSE);
		}

		if (g_AOS.pnconfig.bRequireSecure)
			CheckDlgButton (hwnd, IDC_REQUIRESECURE, BST_CHECKED);
		else
			CheckDlgButton (hwnd, IDC_REQUIRESECURE, BST_UNCHECKED);

		if (g_AOS.pnconfig.bCachePassphrases)
			CheckDlgButton (hwnd, IDC_ENABLECACHE, BST_CHECKED);
		else
			CheckDlgButton (hwnd, IDC_ENABLECACHE, BST_UNCHECKED);

		if (g_AOS.pnconfig.bExpertMode)
			CheckDlgButton (hwnd, IDC_EXPERTMODE, BST_CHECKED);
		else
			CheckDlgButton (hwnd, IDC_EXPERTMODE, BST_UNCHECKED);

		// create and initialize IKE expiration date/time picker control
		GetWindowRect (GetDlgItem (hwnd, IDC_IKETIMEEXPIRE), &rc);
		MapWindowPoints (NULL, hwnd, (LPPOINT)&rc, 2);
		pos->hwndIkeTimeExpire = CreateWindowEx (
				WS_EX_CLIENTEDGE, 
				WC_PGPDURATION, "",
				WS_CHILD|WS_TABSTOP|WS_VISIBLE,
				rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, 
				hwnd, (HMENU)IDC_IKETIMEEXPIRE, g_hinst, NULL);

		SetWindowPos (pos->hwndIkeTimeExpire, 
							GetDlgItem (hwnd, IDC_ENABLEIKETIMEEXPIRE),
							0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);

		LoadString (g_hinst, IDS_EXPIREDAYSTEXT, sz, sizeof(sz));
		SendMessage (pos->hwndIkeTimeExpire, PGP_DCM_SETTEXT, 
						(WPARAM)DAYS, (LPARAM)sz);

		LoadString (g_hinst, IDS_EXPIREHOURSTEXT, sz, sizeof(sz));
		SendMessage (pos->hwndIkeTimeExpire, PGP_DCM_SETTEXT, 
						(WPARAM)HOURS, (LPARAM)sz);

		LoadString (g_hinst, IDS_EXPIREMINSTEXT, sz, sizeof(sz));
		SendMessage (pos->hwndIkeTimeExpire, PGP_DCM_SETTEXT, 
						(WPARAM)MINS, (LPARAM)sz);

		SendMessage (pos->hwndIkeTimeExpire, PGP_DCM_SETMINDURATION, 0, 
						(LPARAM)MINEXPIRESECONDS);

		SendMessage (pos->hwndIkeTimeExpire, PGP_DCM_SETDURATION, 0, 
						(LPARAM)g_AOS.pnconfig.uIkeTimeExpiration);

		// initialize IKE time expiration on/off
		if (g_AOS.pnconfig.bIkeTimeExpiration) 
		{
			CheckDlgButton (hwnd, IDC_ENABLEIKETIMEEXPIRE, BST_CHECKED);
			EnableWindow (pos->hwndIkeTimeExpire, TRUE);
		}
		else 
		{
			CheckDlgButton (hwnd, IDC_ENABLEIKETIMEEXPIRE, BST_UNCHECKED);
			EnableWindow (pos->hwndIkeTimeExpire, FALSE);
		}

		// initialize IKE byte expiration controls
		SendDlgItemMessage (hwnd, IDC_IKEBYTESPIN, UDM_SETRANGE,
				0, (LPARAM)MAKELONG (MAXIKEMEGABYTES, MINIKEMEGABYTES));
		SendDlgItemMessage (hwnd, IDC_IKEBYTES, EM_SETLIMITTEXT, 
				MAXIKEMEGABYTESDIGITS, 0);

		u = g_AOS.pnconfig.uIkeKByteExpiration / 1024;
		SendDlgItemMessage (hwnd, IDC_IKEBYTESPIN, UDM_SETPOS,
				0, (LPARAM)MAKELONG (u, 0));

		if (g_AOS.pnconfig.bIkeKByteExpiration) 
		{
			CheckDlgButton (hwnd, IDC_ENABLEIKEBYTEEXPIRE, BST_CHECKED);
			EnableWindow (GetDlgItem (hwnd, IDC_IKEBYTES), TRUE);
			EnableWindow (GetDlgItem (hwnd, IDC_IKEBYTESPIN), TRUE);
		}
		else 
		{
			CheckDlgButton (hwnd, IDC_ENABLEIKEBYTEEXPIRE, BST_UNCHECKED);
			EnableWindow (GetDlgItem (hwnd, IDC_IKEBYTES), FALSE);
			EnableWindow (GetDlgItem (hwnd, IDC_IKEBYTESPIN), FALSE);
		}

		// create and initialize IPSEC expiration date/time picker control
		GetWindowRect (GetDlgItem (hwnd, IDC_IPSECTIMEEXPIRE), &rc);
		MapWindowPoints (NULL, hwnd, (LPPOINT)&rc, 2);
		pos->hwndIpsecTimeExpire = CreateWindowEx (
				WS_EX_CLIENTEDGE, 
				WC_PGPDURATION, "",
				WS_CHILD|WS_TABSTOP|WS_VISIBLE,
				rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, 
				hwnd, (HMENU)IDC_IPSECTIMEEXPIRE, g_hinst, NULL);
						
		SetWindowPos (pos->hwndIpsecTimeExpire, 
							GetDlgItem (hwnd, IDC_ENABLEIPSECTIMEEXPIRE),
							0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);

		LoadString (g_hinst, IDS_EXPIREDAYSTEXT, sz, sizeof(sz));
		SendMessage (pos->hwndIpsecTimeExpire, PGP_DCM_SETTEXT, 
						(WPARAM)DAYS, (LPARAM)sz);

		LoadString (g_hinst, IDS_EXPIREHOURSTEXT, sz, sizeof(sz));
		SendMessage (pos->hwndIpsecTimeExpire, PGP_DCM_SETTEXT, 
						(WPARAM)HOURS, (LPARAM)sz);

		LoadString (g_hinst, IDS_EXPIREMINSTEXT, sz, sizeof(sz));
		SendMessage (pos->hwndIpsecTimeExpire, PGP_DCM_SETTEXT, 
						(WPARAM)MINS, (LPARAM)sz);

		SendMessage (pos->hwndIpsecTimeExpire, PGP_DCM_SETMINDURATION, 0, 
						(LPARAM)MINEXPIRESECONDS);

		SendMessage (pos->hwndIpsecTimeExpire, PGP_DCM_SETDURATION, 0, 
						(LPARAM)g_AOS.pnconfig.uIpsecTimeExpiration);

		// initialize IPSEC time expiration on/off
		if (g_AOS.pnconfig.bIpsecTimeExpiration) 
		{
			CheckDlgButton (hwnd, IDC_ENABLEIPSECTIMEEXPIRE, BST_CHECKED);
			EnableWindow (pos->hwndIpsecTimeExpire, TRUE);
		}
		else 
		{
			CheckDlgButton (hwnd, IDC_ENABLEIPSECTIMEEXPIRE, BST_UNCHECKED);
			EnableWindow (pos->hwndIpsecTimeExpire, FALSE);
		}

		// initialize IPSEC byte expiration controls
		SendDlgItemMessage (hwnd, IDC_IPSECBYTESPIN, UDM_SETRANGE,
				0, (LPARAM)MAKELONG (MAXIPSECMEGABYTES, MINIPSECMEGABYTES));
		SendDlgItemMessage (hwnd, IDC_IPSECBYTES, EM_SETLIMITTEXT, 
				MAXIPSECMEGABYTESDIGITS, 0);

		u = g_AOS.pnconfig.uIpsecKByteExpiration / 1024;
		SendDlgItemMessage (hwnd, IDC_IPSECBYTESPIN, UDM_SETPOS,
				0, (LPARAM)MAKELONG (u, 0));

		if (g_AOS.pnconfig.bIpsecKByteExpiration) 
		{
			CheckDlgButton (hwnd, IDC_ENABLEIPSECBYTEEXPIRE, BST_CHECKED);
			EnableWindow (GetDlgItem (hwnd, IDC_IPSECBYTES), TRUE);
			EnableWindow (GetDlgItem (hwnd, IDC_IPSECBYTESPIN), TRUE);
		}
		else 
		{
			CheckDlgButton (hwnd, IDC_ENABLEIPSECBYTEEXPIRE, BST_UNCHECKED);
			EnableWindow (GetDlgItem (hwnd, IDC_IPSECBYTES), FALSE);
			EnableWindow (GetDlgItem (hwnd, IDC_IPSECBYTESPIN), FALSE);
		}

		// if we don't have privileges, remove the OK button
		if (g_bReadOnly)
			EnableWindow (GetDlgItem (GetParent(hwnd), IDOK), FALSE);

		return FALSE;
	}

	case WM_HELP: 
		WinHelp (((LPHELPINFO) lParam)->hItemHandle, g_szHelpFile, 
			HELP_WM_HELP, (DWORD) (LPVOID) aGeneralIds); 
		break; 
 
	case WM_CONTEXTMENU: 
		WinHelp ((HWND) wParam, g_szHelpFile, HELP_CONTEXTMENU, 
			(DWORD) (LPVOID) aGeneralIds); 
		break; 

	case WM_COMMAND :
		pos = (POPTIONSSTRUCT)GetWindowLong (hwnd, GWL_USERDATA);

		switch (LOWORD (wParam)) {
		case IDC_ALLOWUNCONFIGURED :
			if (IsDlgButtonChecked (
					hwnd, IDC_ALLOWUNCONFIGURED) == BST_CHECKED)
			{
				EnableWindow (GetDlgItem (hwnd, IDC_REQUIRESECURE), TRUE);
			}
			else
			{
				EnableWindow (GetDlgItem (hwnd, IDC_REQUIRESECURE), FALSE);
			}
			break;

		case IDC_ENABLEIKETIMEEXPIRE :
			if (IsDlgButtonChecked (
					hwnd, IDC_ENABLEIKETIMEEXPIRE) == BST_CHECKED)
				EnableWindow (pos->hwndIkeTimeExpire, TRUE);
			else
				EnableWindow (pos->hwndIkeTimeExpire, FALSE);
			break;

		case IDC_ENABLEIKEBYTEEXPIRE :
			if (IsDlgButtonChecked (
					hwnd, IDC_ENABLEIKEBYTEEXPIRE) == BST_CHECKED)
			{
				EnableWindow (GetDlgItem (hwnd, IDC_IKEBYTES), TRUE);
				EnableWindow (GetDlgItem (hwnd, IDC_IKEBYTESPIN), TRUE);
			}
			else
			{
				EnableWindow (GetDlgItem (hwnd, IDC_IKEBYTES), FALSE);
				EnableWindow (GetDlgItem (hwnd, IDC_IKEBYTESPIN), FALSE);
			}
			break;

		case IDC_ENABLEIPSECTIMEEXPIRE :
			if (IsDlgButtonChecked (
					hwnd, IDC_ENABLEIPSECTIMEEXPIRE) == BST_CHECKED)
				EnableWindow (pos->hwndIpsecTimeExpire, TRUE);
			else
				EnableWindow (pos->hwndIpsecTimeExpire, FALSE);
			break;

		case IDC_ENABLEIPSECBYTEEXPIRE :
			if (IsDlgButtonChecked (
					hwnd, IDC_ENABLEIPSECBYTEEXPIRE) == BST_CHECKED)
			{
				EnableWindow (GetDlgItem (hwnd, IDC_IPSECBYTES), TRUE);
				EnableWindow (GetDlgItem (hwnd, IDC_IPSECBYTESPIN), TRUE);
			}
			else
			{
				EnableWindow (GetDlgItem (hwnd, IDC_IPSECBYTES), FALSE);
				EnableWindow (GetDlgItem (hwnd, IDC_IPSECBYTESPIN), FALSE);
			}
			break;

		case IDC_IKEBYTES :
			if (HIWORD (wParam) == EN_KILLFOCUS)
			{
				INT	iMegaBytes = 
						GetDlgItemInt (hwnd, IDC_IKEBYTES, NULL, FALSE);

				if (iMegaBytes < MINIKEMEGABYTES)
					SetDlgItemInt (
							hwnd, IDC_IKEBYTES, MINIKEMEGABYTES, FALSE);
				else if (iMegaBytes > MAXIKEMEGABYTES)
					SetDlgItemInt (
							hwnd, IDC_IKEBYTES, MAXIKEMEGABYTES, FALSE);
			}
			break;

		case IDC_IPSECBYTES :
			if (HIWORD (wParam) == EN_KILLFOCUS)
			{
				INT	iMegaBytes = 
						GetDlgItemInt (hwnd, IDC_IPSECBYTES, NULL, FALSE);

				if (iMegaBytes < MINIPSECMEGABYTES)
					SetDlgItemInt (
							hwnd, IDC_IPSECBYTES, MINIPSECMEGABYTES, FALSE);
				else if (iMegaBytes > MAXIPSECMEGABYTES)
					SetDlgItemInt (
							hwnd, IDC_IPSECBYTES, MAXIPSECMEGABYTES, FALSE);
			}
			break;
		}
		break;
	
	case WM_NOTIFY :
	{
		LPNMHDR pnmhdr = (LPNMHDR) lParam;

		pos = (POPTIONSSTRUCT)GetWindowLong (hwnd, GWL_USERDATA);

		switch (pnmhdr->code) {

		case PSN_HELP :
			WinHelp (hwnd, g_szHelpFile, HELP_CONTEXT, IDH_PNOPTGEN_HELP); 
			break;

		case PSN_APPLY :
		{
			pos = (POPTIONSSTRUCT)GetWindowLong (hwnd, GWL_USERDATA);

			g_AOS.pnconfig.bAllowUnconfigHost =
				(IsDlgButtonChecked (
					hwnd, IDC_ALLOWUNCONFIGURED) == BST_CHECKED);

			g_AOS.pnconfig.bRequireValidKey =
				(IsDlgButtonChecked (
					hwnd, IDC_REQUIREVALIDKEY) == BST_CHECKED);

			g_AOS.pnconfig.bRequireSecure =
				(IsDlgButtonChecked (
					hwnd, IDC_REQUIRESECURE) == BST_CHECKED);

			g_AOS.pnconfig.bCachePassphrases =
				(IsDlgButtonChecked (
					hwnd, IDC_ENABLECACHE) == BST_CHECKED);

			g_AOS.pnconfig.bExpertMode =
				(IsDlgButtonChecked (
					hwnd, IDC_EXPERTMODE) == BST_CHECKED);

			SendMessage (pos->hwndIkeTimeExpire, PGP_DCM_GETDURATION, 0, 
							(LPARAM)&g_AOS.pnconfig.uIkeTimeExpiration);

			g_AOS.pnconfig.bIkeTimeExpiration =
				(IsDlgButtonChecked (
					hwnd, IDC_ENABLEIKETIMEEXPIRE) == BST_CHECKED);

			g_AOS.pnconfig.bIkeKByteExpiration =
				(IsDlgButtonChecked (
					hwnd, IDC_ENABLEIKEBYTEEXPIRE) == BST_CHECKED);

			g_AOS.pnconfig.uIkeKByteExpiration =
				GetDlgItemInt (hwnd, IDC_IKEBYTES, NULL, FALSE) * 1024;

			SendMessage (pos->hwndIpsecTimeExpire, PGP_DCM_GETDURATION, 0, 
							(LPARAM)&g_AOS.pnconfig.uIpsecTimeExpiration);

			g_AOS.pnconfig.bIpsecTimeExpiration =
				(IsDlgButtonChecked (

⌨️ 快捷键说明

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