📄 install.cpp
字号:
//____________________________________________________________________________
// Copyright (C) 1998 Network Associates Inc. and affiliated companies.
// All rights reserved.
//
// install.c -- install library.
// Author: Philip Nathan
//
//Id: install.c,v 1.1 1999/02/10 00:06:08 philipn Exp $_______________________
#include <windows.h>
#include "install.h"
#include <windef.h>
#include <shlobj.h>
#include <ole2.h>
#include <winsvc.h>
#include <winerror.h>
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <aclapi.h>
#include <io.h>
#include <sys\stat.h>
#include "prototype.h"
// Standard initialization function in 32-bit DLLs.
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
return (1);
}
static SECURITY_DESCRIPTOR fileSecurityDescriptor;
static SECURITY_DESCRIPTOR directorySecurityDescriptor;
//Struct for OPENFILENAME
static OPENFILENAME ofn;
//Struct for SHBrowseForFolder
static BROWSEINFO bi;
//Globals
BOOL bResult;
BOOL bRc;
enum WinVersion WvRc;
//________________________________________
//
// Callback function to hook into
// dialogs and position them centered.
UINT CALLBACK CenterOpenFileName (HWND hdlg,UINT uiMsg,
WPARAM wParam,LPARAM lParam)
{
switch(uiMsg)
{
case WM_INITDIALOG:
{
RECT rc;
// center dialog on screen
GetWindowRect(GetParent(hdlg), &rc);
SetWindowPos(GetParent(hdlg), NULL,
(GetSystemMetrics(SM_CXSCREEN) - (rc.right - rc.left))/2,
(GetSystemMetrics(SM_CYSCREEN) - (rc.bottom - rc.top))/2,
0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW );
break;
}
}
return TRUE;
}
//________________________________________
//
//
//
INT CALLBACK CenterBrowseForFolder (HWND hdlg,UINT uiMsg,
LPARAM lParam,LPARAM lpData)
{
int error;
switch(uiMsg)
{
case BFFM_INITIALIZED:
{
RECT rc;
// center dialog on screen
error = GetWindowRect(hdlg, &rc);
//if (error == 0)
// MessageBox(NULL, "ERROR", "Test", MB_OK);
error = SetWindowPos(hdlg, NULL,
(GetSystemMetrics(SM_CXSCREEN) - (rc.right - rc.left))/2,
(GetSystemMetrics(SM_CYSCREEN) - (rc.bottom - rc.top))/2,
0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
break;
}
}
return TRUE;
}
//________________________________________
//
// Function to supply us with a 95/NT
// looking Browse dialog for browseing
// to folders in Installshield
BOOL WINAPI MyBrowseForFolder32 (HWND hwnd, LPSTR lpszTitle)
{
LPMALLOC pMalloc;
LPITEMIDLIST pidlInstallDir;
char szInstallDir[MAX_PATH];
int nDirLength;
SHGetMalloc(&pMalloc);
bi.hwndOwner = hwnd;
bi.pidlRoot = NULL;
bi.pszDisplayName = szInstallDir;
bi.lpszTitle = lpszTitle;
bi.ulFlags = 0;
bi.lpfn = CenterBrowseForFolder;
bi.lParam = 0;
pidlInstallDir = SHBrowseForFolder(&bi);
if (pidlInstallDir != NULL)
{
SHGetPathFromIDList(pidlInstallDir, lpszTitle);
nDirLength = strlen(lpszTitle);
pMalloc->Free(pidlInstallDir);
return 1;
}
else
return 0;
}
//________________________________________
//
// Initialize function for
// MyGetOpenFileName32.
void MyGetOpenFileNameInit ()
{
static char *szFilter[] = {"All Files", "*.*", ""} ;
ofn.lStructSize = sizeof (OPENFILENAME) ;
ofn.hwndOwner = NULL ;
ofn.hInstance = NULL ;
ofn.lpstrFilter = szFilter [0] ;
ofn.lpstrCustomFilter = NULL ;
ofn.nMaxCustFilter = 0 ;
ofn.nFilterIndex = 0 ;
ofn.lpstrFile = NULL ; // Set in Open and Close functions
ofn.nMaxFile = _MAX_PATH ;
ofn.lpstrFileTitle = NULL ; // Set in Open and Close functions
ofn.nMaxFileTitle = _MAX_FNAME + _MAX_EXT ;
ofn.lpstrInitialDir = NULL ;
ofn.lpstrTitle = NULL ;
ofn.Flags = 0 ; // Set in Open and Close functions
ofn.nFileOffset = 0 ;
ofn.nFileExtension = 0 ;
ofn.lpstrDefExt = NULL ;
ofn.lCustData = 0L ;
ofn.lpfnHook = CenterOpenFileName;
ofn.lpTemplateName = NULL ;
//MessageBox(NULL, "In MyGetOpenFileNameInit", "Test", MB_OK);
}
//________________________________________
//
// Function to supply us with a 95/NT
// looking Browse dialog for browseing
// to files in Installshield.
BOOL WINAPI MyGetOpenFileName32(HWND hwnd, LPSTR lpstrFileFilter, \
LPSTR lpstrFileName, LPSTR lpstrDlgTitle, \
LPSTR lpstrExt)
{
MyGetOpenFileNameInit();
if (hwnd)
ofn.hwndOwner = hwnd;
if (lpstrFileFilter[0] != '\0')
ofn.lpstrFilter = lpstrFileFilter ;
ofn.lpstrFile = lpstrFileName ;
if (lpstrDlgTitle[0] != '\0')
ofn.lpstrTitle = lpstrDlgTitle ;
ofn.Flags = OFN_HIDEREADONLY | OFN_ENABLEHOOK | OFN_EXPLORER;
if (lpstrExt[0] != '\0')
ofn.lpstrDefExt = lpstrExt ;
OleInitialize(NULL);
bResult = GetOpenFileName (&ofn) ;
OleUninitialize();
return bResult;
}
//________________________________________
//
// code to start PGPmemlock driver in NT
// driver must already have been copied to
// c:\winnt\system32\drivers directory.
#define DRIVERNAME "PGPmemlock"
#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
#define UNKNOWN_ERROR 6
int PGPclStartMemLockDriver (VOID)
{
int err = UNKNOWN_ERROR;
SC_HANDLE schSCMan = NULL;
SC_HANDLE schServ = NULL;
DWORD dwErr;
BOOL bRet;
OSVERSIONINFO osid;
SERVICE_STATUS ss;
CHAR szPath[MAX_PATH];
// check if we're running under NT
osid.dwOSVersionInfoSize = sizeof (osid);
GetVersionEx (&osid);
// no => just stop here
if (osid.dwPlatformId != VER_PLATFORM_WIN32_NT) {
err = DRIVER_NOT_WINNT;
goto done;
}
// yes, 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, DRIVERNAME);
lstrcat (szPath, ".sys");
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;
}
#if PGPCERTD
//________________________________________
//
// custom DLL functions, used during
// uninstallation,
//
int UninstInitialize (HWND hwndDlg, HANDLE HInstance, LONG lReserved)
{
#define PATHTOCERTDKEY "SOFTWARE\\Network Associates\\PGP Certificate Server"
LPSTR PathToPrvRing;
LPSTR PathToPubRing;
LPSTR PathToCfgFile;
DWORD dwType;
DWORD dwSize;
LPBYTE pValue = NULL;
HKEY hMainKey = HKEY_LOCAL_MACHINE;
HKEY hOpenKey = NULL;
char* Name = "AppPath";
//Set all -master files back to READ and WRITE
PathToPrvRing = (char*)malloc (_MAX_PATH);
PathToPubRing = (char*)malloc (_MAX_PATH);
PathToCfgFile = (char*)malloc (_MAX_PATH);
if (RegOpenKeyEx(hMainKey, PATHTOCERTDKEY, 0, KEY_ALL_ACCESS, &hOpenKey)
== ERROR_SUCCESS)
{
dwSize = _MAX_PATH;
pValue = (LPBYTE) calloc(sizeof(BYTE), (DWORD)dwSize);
RegQueryValueEx(hOpenKey, Name, NULL, &dwType, pValue, &dwSize);
RegCloseKey (hOpenKey);
}
memcpy (PathToPrvRing, pValue, dwSize);
memcpy (PathToPubRing, pValue, dwSize);
memcpy (PathToCfgFile, pValue, dwSize);
strcat (PathToPrvRing, "\\etc\\PGPcertd-secring-master.skr");
strcat (PathToPubRing, "\\etc\\PGPcertd-pubring-master.pkr");
strcat (PathToCfgFile, "\\etc\\pgpcertd-master.cfg");
_chmod (PathToPrvRing, _S_IREAD | _S_IWRITE);
_chmod (PathToPubRing, _S_IREAD | _S_IWRITE);
_chmod (PathToCfgFile, _S_IREAD | _S_IWRITE);
free (PathToPrvRing);
free (PathToPubRing);
free (PathToCfgFile);
free (pValue);
//Remove IIS 4 entries
CreateIISVDir (0);
//Delete Repd and Certd services
DelSrv(0);
DelSrv(1);
return 1;
}
void UninstUnInitialize (HWND hwndDlg, HANDLE HInstance, LONG lReserved)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -