clavlist.c

来自「PGP8.0源码 请认真阅读您的文件包然后写出其具体功能」· C语言 代码 · 共 1,349 行 · 第 1/3 页

C
1,349
字号
/*____________________________________________________________________________
	Copyright (C) 2002 PGP Corporation
	All rights reserved.

	CLavlist.c -	get AVlist either from prefs or from dialog

	$Id: CLavlist.c,v 1.28 2002/10/31 04:13:35 pbj Exp $
____________________________________________________________________________*/
#include "pgpPFLConfig.h"

// project header files
#include "PGPclx.h"

// compiler definitions
#define PGP_VERISIGN_NAMES	1	// <- 1 forces VeriSign requests to use
								// F,M,L names instead of CommonName

// constant definitions
#define	MAX_AV							20
#define INITIAL_ATTRIBUTE_COLUMNWIDTH	128
#define SCROLLBAR_WIDTH					16

#define OFFSET_FIRST		2
#define OFFSET_OTHER		6

// external globals
extern HINSTANCE g_hInst;

// typedefs
typedef struct {
	PGPContextRef		context;
	PGPKeyServerClass	serverclass;
	PGPUInt32			uRequestType;
	PGPBoolean			bRequestGUI;
	PGPBoolean			bHideCancel;
	PGPAttributeValue*	selectedpair;
	PGPAttributeValue*	pAVListStart;
	PGPAttributeValue*	pAVListEnd;
} AVLISTSTRUCT, *PAVLISTSTRUCT;

// local globals
static DWORD aAVlistIds[] = {			// Help IDs
	IDC_CATYPE,		IDH_PGPCLAV_CATYPE,
	IDC_AVLIST,		IDH_PGPCLAV_AVLIST,
	IDC_NEWAV,		IDH_PGPCLAV_ADDAV,
	IDC_EDITAV,		IDH_PGPCLAV_EDITAV,
	IDC_REMOVEAV,	IDH_PGPCLAV_REMOVEAV,
	IDC_CRS,		IDH_PGPCLAV_CRSREQUEST,
	IDC_PKCS10,		IDH_PGPCLAV_PKCS10REQUEST,
	0,0
};

static DWORD aAVeditIds[] = {			// Help IDs
	IDC_ATTRIBUTELIST,	IDH_PGPCLAV_ATTRIBUTE,
	IDC_VALUE,			IDH_PGPCLAV_VALUE,
	0,0
};



//	___________________________________________________
//
//	fill the AV list with CommonName and Email attributes

static PGPError
sAppendClassAVPairs (
		PGPContextRef		context,
		HWND				hwnd,
		PGPKeyServerClass	serverclass,
		PGPAttributeValue**	ppAVcur)
{
	PGPError	err					= kPGPError_NoErr;
	LPSTR		pszPhrase			= NULL;

	CHAR		sz[256];
	PGPSize		size;

	switch (serverclass) {
	case kPGPKeyServerClass_Verisign :
		// add challenge attribute
		PGPclMessageBox (hwnd, IDS_CAPTIONINFO, 
				IDS_CHALLENGEWARNING, MB_OK|MB_ICONINFORMATION);
		LoadString (g_hInst, IDS_CHALLENGEPROMPT, sz, sizeof(sz));
		err = PGPclGetConfirmationPhrase (context, hwnd, sz,
					kInvalidPGPKeyDBRef, 1, 0, &pszPhrase);
		if (IsntPGPError (err))
		{
			size = lstrlen (pszPhrase);
			(*ppAVcur)->value.pointervalue = PGPNewData (
					PGPPeekContextMemoryMgr (context), size+1,
					kPGPMemoryMgrFlags_Clear);
			if ((*ppAVcur)->value.pointervalue)
			{
				(*ppAVcur)->attribute = kPGPAVAttribute_Challenge;
				(*ppAVcur)->size = size;
				pgpCopyMemory (
						pszPhrase, (*ppAVcur)->value.pointervalue, size);
				++(*ppAVcur);
			}
		}
		if (pszPhrase)
			PGPclFreePhrase (pszPhrase);

		return err;

	default :
		return err;
	}
}


//	___________________________________________________
//
//	fill the AV list with attributes common for all requests

static PGPError
sCreateCommonAVPairs (
		PGPContextRef		context,
		PGPKeyServerClass	serverclass,
		PGPKeyDBObjRef		userid,
		PGPAttributeValue**	ppAVcur)
{
	PGPError			err			= kPGPError_NoErr;
	PGPByte*			pName;
	PGPSize				size;

	// first compute those attributes based on the userid
	if (PGPKeyDBObjRefIsValid (userid))
	{
		// get the "common name" attribute from the userid
		err = PGPGetKeyDBObjDataProperty (
				userid, kPGPUserIDProperty_CommonName, NULL, 0, &size);

		if (size > 0)
		{
			pName = PGPNewData (PGPPeekContextMemoryMgr (context),
								size+1, kPGPMemoryMgrFlags_Clear);

			if (pName)
			{
				err = PGPGetKeyDBObjDataProperty (
						userid, kPGPUserIDProperty_CommonName,
						pName, size, &size);

				if (IsntPGPError (err))
				{
#if PGP_VERISIGN_NAMES
					if (serverclass == kPGPKeyServerClass_Verisign)
					{
						CHAR* pFirstName;
						CHAR* pMiddleName;
						CHAR* pLastName;

						PGPclParseCommonName (PGPPeekContextMemoryMgr (context),
							pName, &pFirstName, &pMiddleName, &pLastName);

						if (pFirstName)
						{
							(*ppAVcur)->attribute =
										kPGPAVAttribute_MailFirstName;
							(*ppAVcur)->size = lstrlen (pFirstName);
							(*ppAVcur)->value.pointervalue = pFirstName;
							++(*ppAVcur);
						}

						if (pMiddleName)
						{
							// note: middlename is really middle initial
							(*ppAVcur)->attribute =
										kPGPAVAttribute_MailMiddleName;
							(*ppAVcur)->size = 1;
							(*ppAVcur)->value.pointervalue = pMiddleName;
							pMiddleName[1] = '\0';
							++(*ppAVcur);
						}

						if (pLastName)
						{
							(*ppAVcur)->attribute =
										kPGPAVAttribute_MailLastName;
							(*ppAVcur)->size = lstrlen (pLastName);
							(*ppAVcur)->value.pointervalue = pLastName;
							++(*ppAVcur);
						}

						PGPFreeData (pName);
					}
					else
#endif //PGP_VERISIGN_NAMES
					{
						(*ppAVcur)->attribute = kPGPAVAttribute_CommonName;
						(*ppAVcur)->size = size;
						(*ppAVcur)->value.pointervalue = pName;
						++(*ppAVcur);
					}
				}
			}
			else
				err = kPGPError_OutOfMemory;
		}
		else
			err = kPGPError_InvalidProperty;
		CKERR;

		// get the "email" attribute from the userid
		err = PGPGetKeyDBObjDataProperty (
				userid, kPGPUserIDProperty_EmailAddress, NULL, 0, &size);

		if (size > 0)
		{
			(*ppAVcur)->value.pointervalue = PGPNewData (
					PGPPeekContextMemoryMgr (context), size+1,
					kPGPMemoryMgrFlags_Clear);

			if ((*ppAVcur)->value.pointervalue)
			{
				err = PGPGetKeyDBObjDataProperty (
						userid, kPGPUserIDProperty_EmailAddress,
						(*ppAVcur)->value.pointervalue, size, &size);

				if (IsntPGPError (err))
				{
					if (serverclass == kPGPKeyServerClass_Microsoft)
						(*ppAVcur)->attribute = kPGPAVAttribute_RFC822Name;
					else
						(*ppAVcur)->attribute = kPGPAVAttribute_Email;
					(*ppAVcur)->size = size;
					++(*ppAVcur);
				}
			}
			else
				err = kPGPError_OutOfMemory;
		}
		else
			err = kPGPError_InvalidProperty;
		CKERR;
	}

done:
	return err;
}


//	___________________________________________________
//
//	fill the AV list with default attributes for the specified server class

static PGPError
sCreateDefaultAVPairs (
		PGPContextRef		context,
		PGPKeyServerClass	serverclass,
		PGPAttributeValue**	ppAVcur)
{
	PGPError	err				= kPGPError_NoErr;
	CHAR		vs_certtype[]	= "end-user";
	PGPSize		size;

	// add class-specific attributes
	switch (serverclass) {
	case kPGPKeyServerClass_NetToolsCA :
		break;

	case kPGPKeyServerClass_Verisign :
		size = lstrlen (vs_certtype);
		(*ppAVcur)->value.pointervalue = PGPNewData (
					PGPPeekContextMemoryMgr (context), size+1,
					kPGPMemoryMgrFlags_Clear);
		if ((*ppAVcur)->value.pointervalue)
		{
			(*ppAVcur)->attribute = kPGPAVAttribute_CertType;
			(*ppAVcur)->size = size;
			pgpCopyMemory (
					vs_certtype, (*ppAVcur)->value.pointervalue, size);
			++(*ppAVcur);
		}

		(*ppAVcur)->attribute = kPGPAVAttribute_OrganizationName;
		(*ppAVcur)->size = 0;
		(*ppAVcur)->value.pointervalue = NULL;
		++(*ppAVcur);

		(*ppAVcur)->attribute = kPGPAVAttribute_OrganizationalUnitName;
		(*ppAVcur)->size = 0;
		(*ppAVcur)->value.pointervalue = NULL;
		++(*ppAVcur);

		break;

	case kPGPKeyServerClass_Entrust :
		break;

	case kPGPKeyServerClass_Netscape :
		break;

	case kPGPKeyServerClass_Microsoft :
		break;

	default :
		break;
	}

	return err;
}


//	___________________________________________________
//
//	get the display string for the attribute of an AV pair

PGPError PGPclExport
PGPclGetAVListAttributeString (
		PGPAVAttribute	attr,
		LPSTR			psz,
		UINT			uLen)
{
	UINT	uids	= 0;

	switch (attr) {

	case kPGPAVAttribute_CommonName :
		uids = IDS_AVCOMMONNAME;
		break;
	case kPGPAVAttribute_Email :
		uids = IDS_AVEMAIL;
		break;
	case kPGPAVAttribute_OrganizationName :
		uids = IDS_AVORGNAME;
		break;
	case kPGPAVAttribute_OrganizationalUnitName :
		uids = IDS_AVORGUNITNAME;
		break;
	case kPGPAVAttribute_Country :
		uids = IDS_AVCOUNTRY;
		break;
	case kPGPAVAttribute_Locality :
		uids = IDS_AVLOCALITY;
		break;
	case kPGPAVAttribute_State :
		uids = IDS_AVSTATE;
		break;
	case kPGPAVAttribute_StreetAddress :
		uids = IDS_AVSTREET;
		break;
	case kPGPAVAttribute_PostalCode :
		uids = IDS_AVPOSTAL;
		break;
	case kPGPAVAttribute_POBOX :
		uids = IDS_AVPOBOX;
		break;
	case kPGPAVAttribute_TelephoneNumber :
		uids = IDS_AVTELEPHONE;
		break;
	case kPGPAVAttribute_Initials :
		uids = IDS_AVINITIALS;
		break;
	case kPGPAVAttribute_DNSName :
		uids = IDS_AVDNSNAME;
		break;
	case kPGPAVAttribute_IPAddress :
		uids = IDS_AVIPADDRESS;
		break;
	case kPGPAVAttribute_RFC822Name :
		uids = IDS_AVRFC822NAME;
		break;

	// Verisign-specific
	case kPGPAVAttribute_MailFirstName :
		uids = IDS_AVFIRSTNAME;
		break;
	case kPGPAVAttribute_MailMiddleName :
		uids = IDS_AVMIDDLENAME;
		break;
	case kPGPAVAttribute_MailLastName :
		uids = IDS_AVLASTNAME;
		break;
	case kPGPAVAttribute_CertType :
		uids = IDS_AVCERTTYPE;
		break;
	}

	psz[0] = '\0';
	if (uids)
	{
		LoadString (g_hInst, uids, psz, uLen);
		return kPGPError_NoErr;
	}
	else
		return kPGPError_ItemNotFound;
}

//	___________________________________________________
//
//	get the display string for the value of an AV pair

static VOID
sGetValueString (
		PGPAttributeValue*	pAV,
		LPSTR				psz,
		UINT				uLen)
{
	PGPSize		size;

	if (pAV->value.pointervalue)
	{
		size = min(pAV->size +1, uLen -1);
		lstrcpyn (psz, pAV->value.pointervalue, size);
		psz[size] = '\0';
	}
	else
		psz[0] = '\0';
}


//	___________________________________________________
//
//	insert the attribute into the list

static VOID
sInsertAttribute (
		HWND			hwnd,
		PAVLISTSTRUCT	pavls,
		PGPAVAttribute	attr)
{
	PGPAttributeValue*	pAV;
	CHAR				sz[128];
	INT					index;

	if (pavls)
	{
		for (pAV=pavls->pAVListStart; pAV<pavls->pAVListEnd; pAV++)
		{
			if (pAV->attribute == attr)
				return;
		}
	}

	PGPclGetAVListAttributeString (attr, sz, sizeof(sz));
	index = SendDlgItemMessage (hwnd, IDC_ATTRIBUTELIST,
							CB_ADDSTRING, 0, (LPARAM)sz);
	SendDlgItemMessage (hwnd, IDC_ATTRIBUTELIST,
							CB_SETITEMDATA, (WPARAM)index, (LPARAM)attr);
}


//	___________________________________________________
//
//	Initialize the AV list listview control

static BOOL
sInitAVPairDialog (

⌨️ 快捷键说明

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