?? bindinstalldlg.cpp
字號:
/* * Portions Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") * Portions Copyright (C) 2001, 2003 Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. *//* $Id: BINDInstallDlg.cpp,v 1.6.2.6.2.10 2004/05/18 01:20:04 marka Exp $ *//* * Copyright (c) 1999-2000 by Nortel Networks Corporation * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND NORTEL NETWORKS DISCLAIMS * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NORTEL NETWORKS * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS * SOFTWARE. *//* * Define this to make a standalone installer that will copy msvcrt.dll * and/or msvcrtd.dll during the install */// #define BINARIES_INSTALL/* * msvcrt.dll is the release c-runtime library for MSVC. msvcrtd.dll is the debug * c-runtime library for MSVC. If you have debug binaries you want to have DEBUG_BINARIES * defined. If you have release binaries you want to have RELEASE_BINARIES defined. * If you have both, then define them both. * Of course, you need msvcrt[d].dll present to install it! */#ifdef BINARIES_INSTALL// # define DEBUG_BINARIES// # define RELEASE_BINARIES#endif#include "stdafx.h"#include "BINDInstall.h"#include "BINDInstallDlg.h"#include "DirBrowse.h"#include <winsvc.h>#include <named/ntservice.h>#include <isc/bind_registry.h>#include <isc/ntgroups.h>#include <direct.h>#include "AccountInfo.h"#include "versioninfo.h"#define MAX_GROUPS 100#define MAX_PRIVS 50#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endiftypedef struct _xexception{ _xexception(UINT string, ...); CString resString;} Exception;_xexception::_xexception(UINT string, ...){ CString format; va_list va; format.LoadString(string); va_start(va, string); resString.FormatV(format, va); va_end(va);}typedef struct _filedata { enum FileDestinations {TargetDir, BinDir, EtcDir, WinSystem}; enum FileImportance {Trivial, Normal, Critical}; char *filename; int destination; int importance; BOOL checkVer;} FileData;const FileData installFiles[] ={#ifdef BINARIES_INSTALL# ifdef DEBUG_BINARIES {"msvcrtd.dll", FileData::WinSystem, FileData::Critical, TRUE},# endif# ifdef RELEASE_BINARIES {"msvcrt.dll", FileData::WinSystem, FileData::Critical, TRUE},# endif#endif#if _MSC_VER >= 1310 {"mfc71.dll", FileData::WinSystem, FileData::Critical, TRUE}, {"msvcr71.dll", FileData::WinSystem, FileData::Critical, TRUE},#elif _MSC_VER > 1200 {"mfc70.dll", FileData::WinSystem, FileData::Critical, TRUE}, {"msvcr70.dll", FileData::WinSystem, FileData::Critical, TRUE},#endif {"bindevt.dll", FileData::WinSystem, FileData::Normal, FALSE}, {"libbind9.dll", FileData::WinSystem, FileData::Critical, FALSE}, {"libisc.dll", FileData::WinSystem, FileData::Critical, FALSE}, {"libisccfg.dll", FileData::WinSystem, FileData::Critical, FALSE}, {"libisccc.dll", FileData::WinSystem, FileData::Critical, FALSE}, {"libdns.dll", FileData::WinSystem, FileData::Critical, FALSE}, {"liblwres.dll", FileData::WinSystem, FileData::Critical, FALSE}, {"libeay32.dll", FileData::BinDir, FileData::Critical, FALSE}, {"named.exe", FileData::BinDir, FileData::Critical, FALSE}, {"nsupdate.exe", FileData::BinDir, FileData::Normal, FALSE}, {"BINDInstall.exe", FileData::BinDir, FileData::Normal, FALSE}, {"rndc.exe", FileData::BinDir, FileData::Normal, FALSE}, {"dig.exe", FileData::BinDir, FileData::Normal, FALSE}, {"host.exe", FileData::BinDir, FileData::Normal, FALSE}, {"nslookup.exe", FileData::BinDir, FileData::Normal, FALSE}, {"rndc-confgen.exe", FileData::BinDir, FileData::Normal, FALSE}, {"dnssec-keygen.exe", FileData::BinDir, FileData::Normal, FALSE}, {"dnssec-signzone.exe", FileData::BinDir, FileData::Normal, FALSE}, {"named-checkconf.exe", FileData::BinDir, FileData::Normal, FALSE}, {"named-checkzone.exe", FileData::BinDir, FileData::Normal, FALSE}, {"readme1st.txt", FileData::BinDir, FileData::Trivial, FALSE}, {NULL, -1, -1}};/////////////////////////////////////////////////////////////////////////////// CBINDInstallDlg dialogCBINDInstallDlg::CBINDInstallDlg(CWnd* pParent /*=NULL*/) : CDialog(CBINDInstallDlg::IDD, pParent) { char buf[MAX_PATH]; //{{AFX_DATA_INIT(CBINDInstallDlg) m_targetDir = _T(""); m_version = _T(""); m_autoStart = FALSE; m_keepFiles = FALSE; m_current = _T(""); m_startOnInstall = FALSE; m_accountName = _T(""); m_accountPassword = _T(""); m_accountName = _T(""); //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); GetSystemDirectory(buf, MAX_PATH); m_winSysDir = buf; m_defaultDir = buf; m_defaultDir += "\\dns"; m_installed = FALSE; m_accountExists = FALSE; m_accountUsed = FALSE; m_serviceExists = TRUE; GetCurrentServiceAccountName(); m_currentAccount = m_accountName; if (m_accountName == "") { m_accountName = "named"; }}void CBINDInstallDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CBINDInstallDlg) DDX_Text(pDX, IDC_TARGETDIR, m_targetDir); DDX_Text(pDX, IDC_VERSION, m_version); DDX_Text(pDX, IDC_ACCOUNT_NAME, m_accountName); DDX_Text(pDX, IDC_ACCOUNT_PASSWORD, m_accountPassword); DDX_Text(pDX, IDC_ACCOUNT_PASSWORD_CONFIRM, m_accountPasswordConfirm); DDX_Check(pDX, IDC_AUTO_START, m_autoStart); DDX_Check(pDX, IDC_KEEP_FILES, m_keepFiles); DDX_Text(pDX, IDC_CURRENT, m_current); DDX_Check(pDX, IDC_START, m_startOnInstall); //}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CBINDInstallDlg, CDialog) //{{AFX_MSG_MAP(CBINDInstallDlg) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BROWSE, OnBrowse) ON_BN_CLICKED(IDC_INSTALL, OnInstall) ON_BN_CLICKED(IDC_EXIT, OnExit) ON_BN_CLICKED(IDC_UNINSTALL, OnUninstall) //}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CBINDInstallDlg message handlersBOOL CBINDInstallDlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon char filename[MAX_PATH]; char dirname[MAX_PATH]; char *fptr = &filename[0]; GetModuleFileName(NULL, filename, MAX_PATH); char *dptr = strrchr(filename,'\\'); int index = dptr - fptr; strncpy(dirname, filename, index); dirname[index] = '\0'; CString Dirname(dirname); m_currentDir = Dirname; CVersionInfo bindInst(filename); if(bindInst.IsValid()) m_version.Format(IDS_VERSION, bindInst.GetFileVersionString()); else m_version.LoadString(IDS_NO_VERSION); DWORD dwBufLen = MAX_PATH; char buf[MAX_PATH]; HKEY hKey; m_startOnInstall = CheckBINDService(); /* See if we are installed already */ if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, BIND_SUBKEY, 0, KEY_READ, &hKey) == ERROR_SUCCESS) { m_installed = TRUE; memset(buf, 0, MAX_PATH); // Get the install directory if (RegQueryValueEx(hKey, "InstallDir", NULL, NULL, (LPBYTE)buf, &dwBufLen) == ERROR_SUCCESS) if (strcmp(buf, "")) m_defaultDir = buf; RegCloseKey(hKey); } m_targetDir = m_defaultDir; // Set checkbox defaults m_autoStart = TRUE; m_keepFiles = TRUE; UpdateData(FALSE); return (TRUE); /* return(TRUE) unless you set the focus to a control */}/* * If you add a minimize button to your dialog, you will need the code below * to draw the icon. For MFC applications using the document/view model, * this is automatically done for you by the framework. */void CBINDInstallDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); }}// The system calls this to obtain the cursor to display while the user drags// the minimized window.HCURSOR CBINDInstallDlg::OnQueryDragIcon() { return((HCURSOR)m_hIcon);}void CBINDInstallDlg::OnBrowse() { CDirBrowse browse; if (browse.DoModal() == IDOK) { //m_targetDir = browse.m_selectedDir; UpdateData(FALSE); }}/* * User pressed the exit button */void CBINDInstallDlg::OnExit() { EndDialog(0); }/* * User pressed the uninstall button. Make it go. */void CBINDInstallDlg::OnUninstall() { UpdateData(); if (MsgBox(IDS_UNINSTALL, MB_YESNO) == IDYES) { if (CheckBINDService()) StopBINDService(); SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); if (!hSCManager) { MsgBox(IDS_ERR_OPEN_SCM, GetErrMessage()); return; } SC_HANDLE hService = OpenService(hSCManager, BIND_SERVICE_NAME, SERVICE_ALL_ACCESS); if (!hService && GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST){ MsgBox(IDS_ERR_OPEN_SERVICE, GetErrMessage()); return; } SERVICE_STATUS ss; QueryServiceStatus(hService, &ss); if (ss.dwCurrentState == SERVICE_RUNNING) { BOOL rc = ControlService(hService, SERVICE_CONTROL_STOP, &ss); if (rc == FALSE || ss.dwCurrentState != SERVICE_STOPPED) { MsgBox(IDS_ERR_STOP_SERVICE, GetErrMessage()); return; } } CloseServiceHandle(hService); CloseServiceHandle(hSCManager); // Directories m_etcDir = m_targetDir + "\\etc"; m_binDir = m_targetDir + "\\bin"; UninstallTags(); UnregisterMessages(TRUE); UnregisterService(TRUE); DeleteFiles(TRUE); if (m_keepFiles == FALSE) RemoveDirs(TRUE); else GetDlgItem(IDC_CREATE_DIR)->SetWindowText("Not Removed"); // Delete registry keys for named RegDeleteKey(HKEY_LOCAL_MACHINE, BIND_SESSION_SUBKEY); RegDeleteKey(HKEY_LOCAL_MACHINE, BIND_SUBKEY); RegDeleteKey(HKEY_LOCAL_MACHINE, BIND_UNINSTALL_SUBKEY); ProgramGroup(FALSE); SetCurrent(IDS_UNINSTALL_DONE); MsgBox(IDS_UNINSTALL_DONE); }}/* * User pressed the install button. Make it go. */void CBINDInstallDlg::OnInstall() { BOOL success = FALSE; if (CheckBINDService()) StopBINDService(); InstallTags(); UpdateData(); /* Check that the Passwords entered match */ if (m_accountPassword != m_accountPasswordConfirm) { MsgBox(IDS_ERR_PASSWORD); return; } /* Check the entered account name */ if (ValidateServiceAccount() == FALSE) return; /* For Registration we need to know if account was changed */ if(m_accountName != m_currentAccount) m_accountUsed = FALSE; /* Directories */ m_etcDir = m_targetDir + "\\etc"; m_binDir = m_targetDir + "\\bin";
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -