📄 lnexpire.c
字号:
/*____________________________________________________________________________
Copyright (C) 2002 PGP Corporation
All rights reserved.
CLexpire.c - product timeout routines
$Id: LNexpire.c,v 1.12.2.1 2002/11/26 11:36:28 wprice Exp $
____________________________________________________________________________*/
#include "pgpPFLConfig.h"
// project header files
#include <windows.h>
#include <time.h>
// PGP build flags
#include "pgpBuild.h"
// PGP SDK header files
#include "pgpUserInterface.h"
#include "pgpBase.h"
#include "pgpErrors.h"
#include "pgpClientPrefs.h"
#include "..\..\..\libs2\shared\pgpLicenseNumber.h"
// PGP client header files
#include "pgpWin32Errors.h"
#include "pgpClientLib.h"
#include "pgpLnLib.h"
// system header files
#include <assert.h>
#if PGP_BETA
#ifndef PGP_BETA_DAYS
#error "beta period not defined"
#else
#if !PGP_BETA_DAYS
#error "invalid beta period"
#endif
#endif
#endif
// used to translate compile date
static CHAR s_szMonths[14][4] = {"\0",
"JAN", "FEB", "MAR", "APR",
"MAY", "JUN", "JUL", "AUG",
"SEP", "OCT", "NOV", "DEC", "\0"};
// ____________________________________
//
// translate month string to integer
static unsigned short
sFindMonth (
LPSTR pszMonthName)
{
INT iMonthNum = 0;
INT i;
assert (pszMonthName);
for (i = 1; s_szMonths[i][0] && !iMonthNum; ++i)
{
if (stricmp (s_szMonths[i], pszMonthName) == 0)
iMonthNum = i;
}
return (iMonthNum);
}
// ____________________________________
//
// translate date string to integers
static void
sTranslateDate (
INT* piMonth,
INT* piDay,
INT* piYear,
LPSTR pszDateString)
{
LPSTR pszBlockStart, pszBlockEnd, pszTempBuffer;
assert (pszDateString);
assert (piYear);
assert (piDay);
assert (piMonth);
*piMonth = *piDay = *piYear = 0;
if (pszTempBuffer = malloc ((strlen(pszDateString) + 1) * sizeof(char)))
{
lstrcpy (pszTempBuffer, pszDateString);
pszBlockStart = pszBlockEnd = pszTempBuffer;
while (pszBlockEnd && *pszBlockEnd && !isspace(*pszBlockEnd))
++pszBlockEnd;
if (pszBlockEnd && *pszBlockEnd)
{
*pszBlockEnd = '\0';
*piMonth = sFindMonth (pszBlockStart);
pszBlockStart = ++pszBlockEnd;
while (pszBlockStart && *pszBlockStart && isspace(*pszBlockStart))
++pszBlockStart;
pszBlockEnd = pszBlockStart;
while (pszBlockEnd && *pszBlockEnd && !isspace(*pszBlockEnd))
++pszBlockEnd;
if (pszBlockEnd && *pszBlockEnd)
{
*pszBlockEnd = '\0';
*piDay = atoi(pszBlockStart);
pszBlockStart = ++pszBlockEnd;
*piYear = atoi(pszBlockStart);
}
}
free (pszTempBuffer);
}
}
// ____________________________________
//
// test if beta period has expired
PGPError
PGPlnBetaTimeOut (time_t *timeEnd)
{
INT iMonth, iDay, iYear;
struct tm tm, *ptm;
time_t timeNow, timeOut;
//Get the compile date, in usable form:
sTranslateDate (&iMonth, &iDay, &iYear, __DATE__);
//Seed the tm structure with the current time:
time (&timeNow);
ptm = localtime (&timeNow);
memcpy (&tm, ptm, sizeof(tm));
//Set the dates to the compile time:
tm.tm_mon = iMonth - 1;
tm.tm_mday = iDay;
tm.tm_year = iYear - 1900;
//Turn the compile time into number of secs since 1/1/1970:
timeOut = mktime (&tm);
//Increment it plus the number of days in the beta timeout times the
timeOut += PGP_BETA_DAYS * 24*60*60; //number of seconds in a day
*timeEnd = timeOut;
return kPGPError_NoErr;
}
// ____________________________________
//
// test if eval or beta period has expired and display
// nag and timed-out messages appropriately
PGPError
PGPlnIsExpired (
HWND hwnd,
PGPlnExpType index)
{
BOOL bOperation;
INT iDays;
#if PGP_BETA
time_t timeNow, timeOut;
time (&timeNow);
PGPlnBetaTimeOut (&timeOut);
if (timeNow > timeOut)
{
PGPclDisplayTimeoutMessage (hwnd, TRUE, 0, FALSE);
return kPGPError_FeatureNotAvailable;
}
#endif // PGP_BETA
// if not been authorized, then we can't be expired
if (!PGPlnWasAuthorized ())
return kPGPError_NoErr;
iDays = PGPlnLicenseDays ();
switch (index) {
case kPGPlnModuleGraceExpiration :
case kPGPlnOperationGraceExpiration :
if (iDays <= 0)
{
INT iGraceDays = iDays + PGP_LICENSEGRACEPERIOD;
bOperation = (index == kPGPlnOperationGraceExpiration);
if (iGraceDays <= 0)
{
PGPclDisplayTimeoutMessage (hwnd, FALSE, 0, bOperation);
return kPGPError_Win32_Expired;
}
else
{
PGPclDisplayTimeoutMessage (hwnd, FALSE, iGraceDays, bOperation);
return kPGPError_NoErr;
}
}
break;
case kPGPlnModuleStandardExpiration :
case kPGPlnOperationStandardExpiration :
if (iDays <= 0)
{
bOperation = (index == kPGPlnOperationStandardExpiration);
PGPclDisplayTimeoutMessage (hwnd, FALSE, 0, bOperation);
return kPGPError_Win32_Expired;
}
break;
case kPGPlnModuleStandardExpirationNoMessage :
case kPGPlnDiskWriteExpiration :
if (iDays <= 0)
return kPGPError_Win32_Expired;
break;
case kPGPlnModuleGraceExpirationNoMessage :
if (iDays <= 0)
{
if ((iDays + PGP_LICENSEGRACEPERIOD) <= 0)
return kPGPError_Win32_Expired;
}
break;
default :
return kPGPError_Win32_Expired;
}
return kPGPError_NoErr;
}
// ____________________________________
//
// License code wrapper functions
typedef struct
{
PGPBoolean bPGPIsAuthorized;
PGPBoolean bPGPWasAuthorized;
PGPBoolean bPGPDiskLicense;
PGPBoolean bPGPMailLicense;
PGPBoolean bPGPEvaluationLicense;
PGPBoolean bPGPDesktopLicense;
PGPBoolean bPGPEnterpriseLicense;
PGPByte* pszPGPname;
PGPByte* pszPGPcorp;
PGPUInt8 uPGPproductID;
PGPInt32 iPGPlicenseDays;
PGPUInt32 uPGPnumlicenses;
PGPUInt32 uPGPserialNumber;
time_t ttCheckTime;
char szName[512];
char szCorp[512];
} LICENSESHARED;
HANDLE hLicenseMutex=NULL;
LICENSESHARED *lns=NULL;
HANDLE hShared=NULL;
static LICENSESHARED*
LNGetSharedMem(HANDLE *hMapObject)
{
void *mem;
hLicenseMutex = CreateMutex(NULL, FALSE, "PGP LN Mutex");
*hMapObject=CreateFileMapping
((HANDLE)0xFFFFFFFF,
NULL,
PAGE_READWRITE,
0,
sizeof(LICENSESHARED),
"PGPLNSharedMemory");
if(*hMapObject==NULL)
return NULL;
mem=MapViewOfFile(*hMapObject,FILE_MAP_WRITE,0,0,0);
return mem;
}
static void
LNReleaseSharedMem(LICENSESHARED *lnShared,HANDLE hMapObject)
{
UnmapViewOfFile(lnShared);
CloseHandle(hMapObject);
CloseHandle(hLicenseMutex);
}
PGPError
PGPlnLicenseName(PGPByte *buffer,PGPSize len)
{
assert (lns);
if (lns == NULL)
PGPlnLicenseCheck (NULL);
WaitForSingleObject(hLicenseMutex,INFINITE);
memcpy(buffer,lns->szName,min(len,strlen(lns->szName)+1));
ReleaseMutex(hLicenseMutex);
buffer[len-1]=0;
return kPGPError_NoErr;
}
PGPError
PGPlnLicenseCorp(PGPByte *buffer,PGPSize len)
{
assert (lns);
if (lns == NULL)
PGPlnLicenseCheck (NULL);
WaitForSingleObject(hLicenseMutex,INFINITE);
memcpy(buffer,lns->szCorp,min(len,strlen(lns->szCorp)+1));
ReleaseMutex(hLicenseMutex);
buffer[len-1]=0;
return kPGPError_NoErr;
}
PGPUInt8
PGPlnLicenseProductID()
{
PGPUInt8 uPGPproductID;
assert (lns);
if (lns == NULL)
PGPlnLicenseCheck (NULL);
WaitForSingleObject(hLicenseMutex,INFINITE);
uPGPproductID=lns->uPGPproductID;
ReleaseMutex(hLicenseMutex);
return uPGPproductID;
}
PGPInt32
PGPlnLicenseDays()
{
PGPInt32 iPGPlicenseDays;
assert (lns);
if (lns == NULL)
PGPlnLicenseCheck (NULL);
WaitForSingleObject(hLicenseMutex,INFINITE);
iPGPlicenseDays=lns->iPGPlicenseDays;
ReleaseMutex(hLicenseMutex);
return iPGPlicenseDays;
}
PGPUInt32
PGPlnLicenseQuantity()
{
PGPUInt32 uPGPnumlicenses;
assert (lns);
if (lns == NULL)
PGPlnLicenseCheck (NULL);
WaitForSingleObject(hLicenseMutex,INFINITE);
uPGPnumlicenses=lns->uPGPnumlicenses;
ReleaseMutex(hLicenseMutex);
return uPGPnumlicenses;
}
PGPUInt32
PGPlnLicenseSerial()
{
PGPUInt32 uPGPserialNumber;
assert (lns);
if (lns == NULL)
PGPlnLicenseCheck (NULL);
WaitForSingleObject(hLicenseMutex,INFINITE);
uPGPserialNumber=lns->uPGPserialNumber;
ReleaseMutex(hLicenseMutex);
return uPGPserialNumber;
}
PGPBoolean
PGPlnEnterprise()
{
PGPBoolean bPGPEnterpriseLicense;
assert (lns);
if (lns == NULL)
PGPlnLicenseCheck (NULL);
WaitForSingleObject(hLicenseMutex,INFINITE);
bPGPEnterpriseLicense=lns->bPGPEnterpriseLicense;
ReleaseMutex(hLicenseMutex);
return bPGPEnterpriseLicense;
}
PGPBoolean
PGPlnPGPdiskEnabled()
{
PGPBoolean bPGPDiskLicense;
assert (lns);
if (lns == NULL)
PGPlnLicenseCheck (NULL);
WaitForSingleObject(hLicenseMutex,INFINITE);
bPGPDiskLicense=lns->bPGPDiskLicense;
ReleaseMutex(hLicenseMutex);
return bPGPDiskLicense;
}
PGPBoolean
PGPlnPGPmailEnabled()
{
PGPBoolean bPGPMailLicense;
assert (lns);
if (lns == NULL)
PGPlnLicenseCheck (NULL);
WaitForSingleObject(hLicenseMutex,INFINITE);
bPGPMailLicense=lns->bPGPMailLicense;
ReleaseMutex(hLicenseMutex);
return bPGPMailLicense;
}
PGPBoolean
PGPlnEvaluation()
{
PGPBoolean bPGPEvaluationLicense;
assert (lns);
if (lns == NULL)
PGPlnLicenseCheck (NULL);
WaitForSingleObject(hLicenseMutex,INFINITE);
bPGPEvaluationLicense=lns->bPGPEvaluationLicense;
ReleaseMutex(hLicenseMutex);
return bPGPEvaluationLicense;
}
PGPBoolean
PGPlnDesktop()
{
PGPBoolean bPGPDesktopLicense;
assert (lns);
if (lns == NULL)
PGPlnLicenseCheck (NULL);
WaitForSingleObject(hLicenseMutex,INFINITE);
bPGPDesktopLicense=lns->bPGPDesktopLicense;
ReleaseMutex(hLicenseMutex);
return bPGPDesktopLicense;
}
PGPBoolean
PGPlnIsAuthorized()
{
PGPBoolean bPGPIsAuthorized;
assert (lns);
if (lns == NULL)
PGPlnLicenseCheck (NULL);
WaitForSingleObject(hLicenseMutex,INFINITE);
bPGPIsAuthorized=lns->bPGPIsAuthorized;
ReleaseMutex(hLicenseMutex);
return bPGPIsAuthorized;
}
PGPBoolean
PGPlnWasAuthorized()
{
PGPBoolean bPGPWasAuthorized;
assert (lns);
if (lns == NULL)
PGPlnLicenseCheck (NULL);
WaitForSingleObject(hLicenseMutex,INFINITE);
bPGPWasAuthorized=lns->bPGPWasAuthorized;
ReleaseMutex(hLicenseMutex);
return bPGPWasAuthorized;
}
PGPError
PGPlnLicenseCheckLite (
PGPContextRef context)
{
if(lns==NULL)
return PGPlnLicenseCheck (context);
else
return kPGPError_NoErr;
}
PGPError
PGPlnLicenseCheck (
PGPContextRef context)
{
PGPError err = kPGPError_BadParams;
PGPPrefRef prefs;
PGPLicenseNumberRef ln;
PGPSize lasize,lnsize;
int len;
PGPLicenseAuthorizationRef la;
PGPByte *lain,*lnin,*name,*corp,flags;
err=kPGPError_NoErr;
if(lns==NULL)
lns=LNGetSharedMem(&hShared);
if (context == NULL)
return err;
WaitForSingleObject(hLicenseMutex,INFINITE);
lns->bPGPIsAuthorized=FALSE;
lns->bPGPWasAuthorized=FALSE;
lns->bPGPDiskLicense=FALSE;
lns->bPGPMailLicense=FALSE;
lns->bPGPEvaluationLicense=FALSE;
lns->bPGPEnterpriseLicense=FALSE;
lns->bPGPDesktopLicense=FALSE;
lns->uPGPproductID=0;
lns->iPGPlicenseDays=-(0x7fffffff);
lns->uPGPnumlicenses=0;
lns->uPGPserialNumber=0;
lns->ttCheckTime=0;
strcpy(lns->szName,"None");
strcpy(lns->szCorp,"None");
// For BETA and such when there are no license numbers
#if (!PGP_LICENSENUMBERS)
lns->bPGPIsAuthorized=TRUE;
lns->bPGPWasAuthorized=TRUE;
lns->bPGPDiskLicense=TRUE;
lns->bPGPMailLicense=TRUE;
lns->bPGPEnterpriseLicense=TRUE;
lns->bPGPDesktopLicense=TRUE;
lns->uPGPnumlicenses=1;
#else
err=PGPclPeekClientLibPrefRefs (&prefs,NULL);
if(IsntPGPError(err))
{
lnsize=0;
err=PGPGetPrefData(prefs, kPGPPrefLicenseNumber, &lnsize, &lnin); // Includes NULL
if((IsntPGPError(err))&&(lnsize!=0))
{
lnin[lnsize-1]=0; // NULL terminate just in case
err=PGPLNImportBase32(context,lnin,&ln);
if(IsntPGPError(err))
{
lasize=0;
err=PGPGetPrefData(prefs, kPGPPrefLicenseAuthorization, &lasize, &lain); // Includes NULL
if((IsntPGPError(err))&&(lasize!=0))
{
lain[lasize-1]=0;
err=PGPLAImportBase64(context,lain,&la);
if(IsntPGPError(err))
{
err=PGPGetPrefStringAlloc (prefs,kPGPPrefLicenseName,&name);
if(IsntPGPError(err))
{
err=PGPGetPrefStringAlloc (prefs,kPGPPrefLicenseCompany,&corp);
if(IsntPGPError(err))
{
PGPLNGetProductID(context,ln,&(lns->uPGPproductID));
if (lns->uPGPproductID == PGPPRODUCTID)
{
err=PGPLAVerify(context,ln,la,name,corp);
if ((IsntPGPError(err)) ||
(err == kPGPError_KeyExpired))
{
lns->bPGPWasAuthorized=TRUE;
if (IsntPGPError (err))
lns->bPGPIsAuthorized=TRUE;
len=min(strlen(name),511);
memcpy(lns->szName,name,len);
lns->szName[len]=0;
len=min(strlen(corp),511);
memcpy(lns->szCorp,corp,len);
lns->szCorp[len]=0;
PGPLNGetFlags(context,ln,&flags);
PGPLNGetNumLicenses(context,ln,&(lns->uPGPnumlicenses));
PGPLNGetSN(context,ln,&(lns->uPGPserialNumber));
lns->ttCheckTime=time(NULL);
PGPLADaysLeft(context,ln,la,&(lns->iPGPlicenseDays));
lns->bPGPEnterpriseLicense=
((flags&kPGPLicenseNumberFlag_Enterprise)==kPGPLicenseNumberFlag_Enterprise);
lns->bPGPDesktopLicense=
((flags&kPGPLicenseNumberFlag_Desktop)==kPGPLicenseNumberFlag_Desktop);
lns->bPGPDiskLicense=
((flags&kPGPLicenseNumberFlag_Disk)==kPGPLicenseNumberFlag_Disk);
lns->bPGPMailLicense=
((flags&kPGPLicenseNumberFlag_Mail)==kPGPLicenseNumberFlag_Mail);
lns->bPGPEvaluationLicense=
((flags&kPGPLicenseNumberFlag_Evaluation)==kPGPLicenseNumberFlag_Evaluation);
}
}
if(corp)
PGPFreeData(corp);
}
if(name)
PGPFreeData(name);
}
PGPLAFree(la);
}
PGPFreeData(lain);
}
PGPLNFree(ln);
}
PGPFreeData(lnin);
}
}
#endif
ReleaseMutex(hLicenseMutex);
return err;
}
PGPError
PGPlnLicenseFree (
PGPContextRef context)
{
if (lns != NULL)
LNReleaseSharedMem(lns,hShared);
hLicenseMutex=lns=hShared=NULL;
return kPGPError_NoErr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -