📄 corpkey.c
字号:
/*____________________________________________________________________________
Copyright (C) 2002 PGP Corporation
All rights reserved.
$Id: CorpKey.c,v 1.13 2002/10/07 16:20:09 wjb Exp $
____________________________________________________________________________*/
#include <windows.h>
#include "PGPadmin.h"
#include <commctrl.h>
#include "resource.h"
#include "Utils.h"
#include "keydrawitem.h"
#include "PGPadminHelp.h"
#include "pgpClientLib.h"
static void sInitGUI(HWND hwndDlg, pgpConfigInfo *pConfig);
static DWORD aHelpIds[] = {
IDC_AUTOSIGNTRUST, IDH_PGPADMIN_AUTOSIGNTRUST,
IDC_METAINTRODUCER, IDH_PGPADMIN_METAINTRODUCER,
IDC_TRUSTDEPTH, IDH_PGPADMIN_TRUSTDEPTH,
IDC_CORPKEY_ID, IDH_PGPADMIN_CORPKEY_ID,
IDC_TRUSTTEXT, -1,
IDC_CORPKEYLABEL, -1,
IDC_TRUSTSPIN, -1,
0,0
};
HFONT g_hFont;
BOOL CALLBACK CorpKeyDlgProc(HWND hwndDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
BOOL bReturnCode = FALSE;
pgpConfigInfo * pConfig = NULL;
HWND hList;
g_hCurrentDlgWnd = hwndDlg;
pConfig = (pgpConfigInfo *) GetWindowLong(hwndDlg, GWL_USERDATA);
hList = GetDlgItem(hwndDlg, IDC_CORPKEY_ID);
switch(uMsg)
{
case WM_INITDIALOG:
{
CommonDlgProc(hwndDlg, uMsg, wParam, lParam);
pConfig = (pgpConfigInfo *) GetWindowLong(hwndDlg, GWL_USERDATA);
ShowKeyring(hwndDlg, IDC_CORPKEY_ID, pConfig->pgpContext,
pConfig->keyDB, NULL, TRUE, TRUE, FALSE, TRUE);
SelectKeys(hwndDlg, IDC_CORPKEY_ID, 1, &(pConfig->corpKeyID));
SendMessage(GetDlgItem(hwndDlg, IDC_TRUSTSPIN), UDM_SETRANGE, 0,
MAKELONG(8, 2));
// Property sheets use bad unicode font, so we must set
// it ourselves for listviews
g_hFont=SetUTF8Font(GetDlgItem(hwndDlg,IDC_CORPKEY_ID));
sInitGUI(hwndDlg, pConfig);
break;
}
case WM_DRAWITEM:
{
KeyDrawItem((LPDRAWITEMSTRUCT) lParam);
return TRUE;
}
case WM_DESTROY:
FreeKeyring(hwndDlg, IDC_CORPKEY_ID);
DeleteObject(g_hFont);
break;
case WM_HELP:
case WM_CONTEXTMENU:
return PGPclHtmlHelp (hwndDlg, uMsg, wParam, lParam,
(char *) kPGPclAdminHelpFile, aHelpIds);
case WM_NOTIFY:
{
LPNMHDR pnmh;
pnmh = (LPNMHDR) lParam;
switch(pnmh->code)
{
case PSN_HELP:
PGPclHtmlHelp (hwndDlg, kPGPclHelpContext, 0, 0,
(char *) kPGPclAdminHelpFile,
(DWORD *) IDH_PGPADMIN_CORPKEYDIALOG);
break;
case PSN_KILLACTIVE:
{
int nIndex;
LV_ITEM lviKey;
char szUserID[kPGPMaxUserIDSize+1];
char szErrorMsg[255];
PGPKeyID *pKeyID;
BOOL bError = FALSE;
HWND hwndCtrl;
// Check data validity
if (pConfig->bAutoSignTrustCorp &&
pConfig->bMetaIntroducerCorp)
{
if ((pConfig->nCorpKeyTrustDepth < 2) ||
(pConfig->nCorpKeyTrustDepth > 8))
{
LoadString(g_hInstance, IDS_E_DEPTHRANGE,
szErrorMsg, 254);
hwndCtrl = GetDlgItem(hwndDlg, IDC_TRUSTDEPTH);
bError = TRUE;
}
}
// Save user data for this page
nIndex = ListView_GetNextItem(hList, -1, LVNI_SELECTED);
if (nIndex > -1)
{
lviKey.mask = LVIF_PARAM | LVIF_TEXT;
lviKey.iItem = nIndex;
lviKey.iSubItem = 0;
lviKey.pszText = szUserID;
lviKey.cchTextMax = kPGPMaxUserIDSize;
ListView_GetItem(hList, &lviKey);
pKeyID = (PGPKeyID *) lviKey.lParam;
memcpy(pConfig->corpKeyID.opaqueBytes,
pKeyID->opaqueBytes, sizeof(pKeyID->opaqueBytes));
}
else if (pConfig->bAutoSignTrustCorp)
{
LoadString(g_hInstance, IDS_E_SELECTKEY, szErrorMsg,
254);
hwndCtrl = GetDlgItem(hwndDlg, IDC_CORPKEY_ID);
bError = TRUE;
}
if (bError)
{
char szTitle[255];
LoadString(g_hInstance, IDS_TITLE, szTitle, 254);
MessageBox(hwndDlg, szErrorMsg, szTitle,
MB_ICONEXCLAMATION);
SetFocus(hwndCtrl);
SetWindowLong(hwndDlg, DWL_MSGRESULT, -1);
}
bReturnCode = TRUE;
break;
}
case NM_CLICK:
case TVN_KEYDOWN:
if (pnmh->idFrom == IDC_CORPKEY_ID)
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
bReturnCode = CommonDlgProc(hwndDlg, uMsg, wParam, lParam);
break;
default:
bReturnCode = CommonDlgProc(hwndDlg, uMsg, wParam, lParam);
break;
}
break;
}
case WM_COMMAND:
if (pConfig == NULL)
break;
switch (LOWORD(wParam))
{
case IDC_AUTOSIGNTRUST:
{
if (IsDlgButtonChecked(hwndDlg, IDC_AUTOSIGNTRUST) ==
BST_CHECKED)
{
pConfig->bAutoSignTrustCorp = TRUE;
}
else
{
pConfig->bAutoSignTrustCorp = FALSE;
pConfig->bMetaIntroducerCorp = FALSE;
}
sInitGUI(hwndDlg, pConfig);
bReturnCode = TRUE;
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
break;
}
case IDC_METAINTRODUCER:
{
if (IsDlgButtonChecked(hwndDlg, IDC_METAINTRODUCER) ==
BST_CHECKED)
{
pConfig->bMetaIntroducerCorp = TRUE;
}
else
{
pConfig->bMetaIntroducerCorp = FALSE;
}
sInitGUI(hwndDlg, pConfig);
bReturnCode = TRUE;
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
break;
}
case IDC_TRUSTDEPTH:
{
char szBuffer[4];
GetWindowText(GetDlgItem(hwndDlg, IDC_TRUSTDEPTH),
szBuffer, 4);
pConfig->nCorpKeyTrustDepth = atoi(szBuffer);
bReturnCode = TRUE;
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
break;
}
}
default:
bReturnCode = CommonDlgProc(hwndDlg, uMsg, wParam, lParam);
break;
}
return(bReturnCode);
}
static void sInitGUI(HWND hwndDlg, pgpConfigInfo *pConfig)
{
char szDepth[3];
if (pConfig->bAutoSignTrustCorp)
CheckDlgButton(hwndDlg, IDC_AUTOSIGNTRUST, BST_CHECKED);
else
{
CheckDlgButton(hwndDlg, IDC_AUTOSIGNTRUST, BST_UNCHECKED);
ListView_SetItemState(GetDlgItem(hwndDlg, IDC_CORPKEY_ID), -1, 0,
LVIS_SELECTED);
}
EnableWindow(GetDlgItem(hwndDlg, IDC_METAINTRODUCER),
pConfig->bAutoSignTrustCorp);
EnableWindow(GetDlgItem(hwndDlg, IDC_CORPKEYLABEL),
pConfig->bAutoSignTrustCorp);
EnableWindow(GetDlgItem(hwndDlg, IDC_CORPKEY_ID),
pConfig->bAutoSignTrustCorp);
EnableWindow(GetDlgItem(hwndDlg, IDC_TRUSTTEXT),
pConfig->bAutoSignTrustCorp && pConfig->bMetaIntroducerCorp);
EnableWindow(GetDlgItem(hwndDlg, IDC_TRUSTDEPTH),
pConfig->bAutoSignTrustCorp && pConfig->bMetaIntroducerCorp);
if (pConfig->bMetaIntroducerCorp)
CheckDlgButton(hwndDlg, IDC_METAINTRODUCER, BST_CHECKED);
else
CheckDlgButton(hwndDlg, IDC_METAINTRODUCER, BST_UNCHECKED);
wsprintf(szDepth, "%d", pConfig->nCorpKeyTrustDepth);
SetWindowText(GetDlgItem(hwndDlg, IDC_TRUSTDEPTH), szDepth);
return;
}
/*__Editor_settings____
Local Variables:
tab-width: 4
End:
vi: ts=4 sw=4
vim: si
_____________________*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -