2001-07-19 17:38:51 +00:00
|
|
|
/*
|
2013-07-08 23:46:07 +00:00
|
|
|
* Portions Copyright (C) 2004-2010, 2013 Internet Systems Consortium, Inc. ("ISC")
|
2004-03-05 05:14:21 +00:00
|
|
|
* Portions Copyright (C) 2001, 2003 Internet Software Consortium.
|
2001-07-19 17:38:51 +00:00
|
|
|
*
|
2007-06-18 23:47:57 +00:00
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
2001-07-19 17:38:51 +00:00
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
2004-03-05 05:14:21 +00:00
|
|
|
* 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.
|
2001-07-19 17:38:51 +00:00
|
|
|
*/
|
|
|
|
|
2010-01-07 23:48:54 +00:00
|
|
|
/* $Id: BINDInstallDlg.cpp,v 1.48 2010/01/07 23:48:54 tbox Exp $ */
|
2001-07-31 00:03:21 +00:00
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
/*
|
|
|
|
* 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>
|
2001-09-25 01:48:49 +00:00
|
|
|
#include <isc/ntgroups.h>
|
2001-07-18 05:04:46 +00:00
|
|
|
#include <direct.h>
|
2001-09-25 01:48:49 +00:00
|
|
|
#include "AccountInfo.h"
|
2001-07-18 05:04:46 +00:00
|
|
|
#include "versioninfo.h"
|
|
|
|
|
2009-07-17 06:25:45 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
#define MAX_GROUPS 100
|
|
|
|
#define MAX_PRIVS 50
|
|
|
|
|
2009-09-01 06:51:47 +00:00
|
|
|
#define LOCAL_SERVICE "NT AUTHORITY\\LocalService"
|
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
#define new DEBUG_NEW
|
|
|
|
#undef THIS_FILE
|
|
|
|
static char THIS_FILE[] = __FILE__;
|
|
|
|
#endif
|
|
|
|
|
2004-03-16 05:52:24 +00:00
|
|
|
typedef struct _xexception
|
2001-07-18 05:04:46 +00:00
|
|
|
{
|
2004-03-16 05:52:24 +00:00
|
|
|
_xexception(UINT string, ...);
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
CString resString;
|
|
|
|
} Exception;
|
|
|
|
|
2004-03-16 05:52:24 +00:00
|
|
|
_xexception::_xexception(UINT string, ...)
|
2001-07-18 05:04:46 +00:00
|
|
|
{
|
|
|
|
CString format;
|
|
|
|
va_list va;
|
|
|
|
|
|
|
|
format.LoadString(string);
|
|
|
|
|
|
|
|
va_start(va, string);
|
|
|
|
resString.FormatV(format, va);
|
|
|
|
va_end(va);
|
|
|
|
}
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
typedef struct _filedata {
|
2001-07-18 05:04:46 +00:00
|
|
|
enum FileDestinations {TargetDir, BinDir, EtcDir, WinSystem};
|
|
|
|
enum FileImportance {Trivial, Normal, Critical};
|
|
|
|
|
|
|
|
char *filename;
|
|
|
|
int destination;
|
|
|
|
int importance;
|
|
|
|
BOOL checkVer;
|
2009-08-25 06:47:06 +00:00
|
|
|
BOOL withTools;
|
2001-07-18 05:04:46 +00:00
|
|
|
} FileData;
|
|
|
|
|
|
|
|
const FileData installFiles[] =
|
|
|
|
{
|
|
|
|
#ifdef BINARIES_INSTALL
|
|
|
|
# ifdef DEBUG_BINARIES
|
2009-08-25 06:47:06 +00:00
|
|
|
{"msvcrtd.dll", FileData::WinSystem, FileData::Critical, TRUE, TRUE},
|
2001-07-18 05:04:46 +00:00
|
|
|
# endif
|
|
|
|
# ifdef RELEASE_BINARIES
|
2009-08-25 06:47:06 +00:00
|
|
|
{"msvcrt.dll", FileData::WinSystem, FileData::Critical, TRUE, TRUE},
|
2001-07-18 05:04:46 +00:00
|
|
|
# endif
|
|
|
|
#endif
|
2007-05-21 05:23:50 +00:00
|
|
|
#if _MSC_VER < 1400
|
|
|
|
#if _MSC_VER >= 1310
|
2009-08-25 06:47:06 +00:00
|
|
|
{"mfc71.dll", FileData::WinSystem, FileData::Critical, TRUE, TRUE},
|
|
|
|
{"msvcr71.dll", FileData::WinSystem, FileData::Critical, TRUE, TRUE},
|
2007-06-27 01:11:16 +00:00
|
|
|
#elif _MSC_VER > 1200 && _MSC_VER < 1310
|
2009-08-25 06:47:06 +00:00
|
|
|
{"mfc70.dll", FileData::WinSystem, FileData::Critical, TRUE, TRUE},
|
|
|
|
{"msvcr70.dll", FileData::WinSystem, FileData::Critical, TRUE, TRUE},
|
2007-05-21 05:23:50 +00:00
|
|
|
#endif
|
2004-04-19 04:16:55 +00:00
|
|
|
#endif
|
2009-08-25 06:47:06 +00:00
|
|
|
{"bindevt.dll", FileData::BinDir, FileData::Normal, FALSE, TRUE},
|
|
|
|
{"libbind9.dll", FileData::BinDir, FileData::Critical, FALSE, TRUE},
|
|
|
|
{"libisc.dll", FileData::BinDir, FileData::Critical, FALSE, TRUE},
|
|
|
|
{"libisccfg.dll", FileData::BinDir, FileData::Critical, FALSE, TRUE},
|
|
|
|
{"libisccc.dll", FileData::BinDir, FileData::Critical, FALSE, TRUE},
|
|
|
|
{"libdns.dll", FileData::BinDir, FileData::Critical, FALSE, TRUE},
|
|
|
|
{"liblwres.dll", FileData::BinDir, FileData::Critical, FALSE, TRUE},
|
|
|
|
{"libeay32.dll", FileData::BinDir, FileData::Critical, FALSE, TRUE},
|
2009-07-17 06:25:45 +00:00
|
|
|
#ifdef HAVE_LIBXML2
|
2009-08-25 06:47:06 +00:00
|
|
|
{"libxml2.dll", FileData::BinDir, FileData::Critical, FALSE, TRUE},
|
2009-07-17 06:25:45 +00:00
|
|
|
#endif
|
2009-08-25 06:47:06 +00:00
|
|
|
{"named.exe", FileData::BinDir, FileData::Critical, FALSE, FALSE},
|
|
|
|
{"nsupdate.exe", FileData::BinDir, FileData::Normal, FALSE, TRUE},
|
|
|
|
{"BINDInstall.exe", FileData::BinDir, FileData::Normal, FALSE, TRUE},
|
|
|
|
{"rndc.exe", FileData::BinDir, FileData::Normal, FALSE, FALSE},
|
|
|
|
{"dig.exe", FileData::BinDir, FileData::Normal, FALSE, TRUE},
|
|
|
|
{"host.exe", FileData::BinDir, FileData::Normal, FALSE, TRUE},
|
|
|
|
{"nslookup.exe", FileData::BinDir, FileData::Normal, FALSE, TRUE},
|
2009-12-04 21:59:24 +00:00
|
|
|
{"arpaname.exe", FileData::BinDir, FileData::Normal, FALSE, TRUE},
|
|
|
|
{"nsec3hash.exe", FileData::BinDir, FileData::Normal, FALSE, FALSE},
|
|
|
|
{"genrandom.exe", FileData::BinDir, FileData::Normal, FALSE, FALSE},
|
2009-08-25 06:47:06 +00:00
|
|
|
{"rndc-confgen.exe", FileData::BinDir, FileData::Normal, FALSE, FALSE},
|
|
|
|
{"ddns-confgen.exe", FileData::BinDir, FileData::Normal, FALSE, FALSE},
|
|
|
|
{"dnssec-keygen.exe", FileData::BinDir, FileData::Normal, FALSE, FALSE},
|
|
|
|
{"dnssec-signzone.exe", FileData::BinDir, FileData::Normal, FALSE, FALSE},
|
|
|
|
{"dnssec-dsfromkey.exe", FileData::BinDir, FileData::Normal, FALSE, FALSE},
|
2013-09-04 18:56:50 -07:00
|
|
|
{"dnssec-importkey.exe", FileData::BinDir, FileData::Normal, FALSE, FALSE},
|
2009-08-25 06:47:06 +00:00
|
|
|
{"dnssec-keyfromlabel.exe", FileData::BinDir, FileData::Normal, FALSE, FALSE},
|
|
|
|
{"dnssec-revoke.exe", FileData::BinDir, FileData::Normal, FALSE, FALSE},
|
2013-07-08 10:31:42 -07:00
|
|
|
{"dnssec-settime.exe", FileData::BinDir, FileData::Normal, FALSE, FALSE},
|
|
|
|
{"dnssec-verify.exe", FileData::BinDir, FileData::Normal, FALSE, FALSE},
|
2009-08-25 06:47:06 +00:00
|
|
|
{"named-checkconf.exe", FileData::BinDir, FileData::Normal, FALSE, FALSE},
|
|
|
|
{"named-checkzone.exe", FileData::BinDir, FileData::Normal, FALSE, FALSE},
|
|
|
|
{"named-compilezone.exe", FileData::BinDir, FileData::Normal, FALSE, FALSE},
|
2009-12-04 21:59:24 +00:00
|
|
|
{"named-journalprint.exe", FileData::BinDir, FileData::Normal, FALSE, FALSE},
|
2013-11-18 14:58:15 -08:00
|
|
|
{"named-rrchecker.exe", FileData::BinDir, FileData::Normal, FALSE, FALSE},
|
2010-01-07 21:52:12 +00:00
|
|
|
{"isc-hmax-fixup.exe", FileData::BinDir, FileData::Normal, FALSE, FALSE},
|
2009-12-04 21:59:24 +00:00
|
|
|
{"pkcs11-destroy.exe", FileData::BinDir, FileData::Normal, FALSE, FALSE},
|
|
|
|
{"pkcs11-keygen.exe", FileData::BinDir, FileData::Normal, FALSE, FALSE},
|
|
|
|
{"pkcs11-list.exe", FileData::BinDir, FileData::Normal, FALSE, FALSE},
|
2009-08-25 06:47:06 +00:00
|
|
|
{"readme1st.txt", FileData::BinDir, FileData::Trivial, FALSE, TRUE},
|
2001-07-18 05:04:46 +00:00
|
|
|
{NULL, -1, -1}
|
|
|
|
};
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CBINDInstallDlg dialog
|
|
|
|
|
|
|
|
CBINDInstallDlg::CBINDInstallDlg(CWnd* pParent /*=NULL*/)
|
2001-09-25 01:48:49 +00:00
|
|
|
: CDialog(CBINDInstallDlg::IDD, pParent) {
|
2001-07-18 05:04:46 +00:00
|
|
|
char buf[MAX_PATH];
|
|
|
|
|
|
|
|
//{{AFX_DATA_INIT(CBINDInstallDlg)
|
|
|
|
m_targetDir = _T("");
|
|
|
|
m_version = _T("");
|
2009-08-25 06:47:06 +00:00
|
|
|
m_toolsOnly = FALSE;
|
2001-07-18 05:04:46 +00:00
|
|
|
m_autoStart = FALSE;
|
|
|
|
m_keepFiles = FALSE;
|
|
|
|
m_current = _T("");
|
|
|
|
m_startOnInstall = FALSE;
|
2001-09-25 01:48:49 +00:00
|
|
|
m_accountName = _T("");
|
|
|
|
m_accountPassword = _T("");
|
|
|
|
m_accountName = _T("");
|
2001-07-18 05:04:46 +00:00
|
|
|
//}}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";
|
2001-09-25 01:48:49 +00:00
|
|
|
m_installed = FALSE;
|
|
|
|
m_accountExists = FALSE;
|
|
|
|
m_accountUsed = FALSE;
|
2001-09-26 02:22:27 +00:00
|
|
|
m_serviceExists = TRUE;
|
2001-09-25 01:48:49 +00:00
|
|
|
GetCurrentServiceAccountName();
|
2001-09-26 02:22:27 +00:00
|
|
|
m_currentAccount = m_accountName;
|
2001-09-25 01:48:49 +00:00
|
|
|
if (m_accountName == "") {
|
|
|
|
m_accountName = "named";
|
|
|
|
}
|
2001-07-18 05:04:46 +00:00
|
|
|
}
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
void CBINDInstallDlg::DoDataExchange(CDataExchange* pDX) {
|
2001-07-18 05:04:46 +00:00
|
|
|
CDialog::DoDataExchange(pDX);
|
|
|
|
//{{AFX_DATA_MAP(CBINDInstallDlg)
|
|
|
|
DDX_Text(pDX, IDC_TARGETDIR, m_targetDir);
|
|
|
|
DDX_Text(pDX, IDC_VERSION, m_version);
|
2001-09-25 01:48:49 +00:00
|
|
|
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);
|
2009-08-25 06:47:06 +00:00
|
|
|
DDX_Check(pDX, IDC_TOOLS_ONLY, m_toolsOnly);
|
2001-07-18 05:04:46 +00:00
|
|
|
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_MAP
|
|
|
|
END_MESSAGE_MAP()
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CBINDInstallDlg message handlers
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
BOOL CBINDInstallDlg::OnInitDialog() {
|
2001-07-18 05:04:46 +00:00
|
|
|
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,'\\');
|
2009-09-29 04:38:23 +00:00
|
|
|
size_t index = dptr - fptr;
|
2001-07-18 05:04:46 +00:00
|
|
|
strncpy(dirname, filename, index);
|
|
|
|
dirname[index] = '\0';
|
|
|
|
CString Dirname(dirname);
|
|
|
|
m_currentDir = Dirname;
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
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 */
|
2001-09-25 01:48:49 +00:00
|
|
|
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, BIND_SUBKEY, 0, KEY_READ, &hKey)
|
|
|
|
== ERROR_SUCCESS) {
|
|
|
|
m_installed = TRUE;
|
2001-07-18 05:04:46 +00:00
|
|
|
memset(buf, 0, MAX_PATH);
|
|
|
|
// Get the install directory
|
2001-09-25 01:48:49 +00:00
|
|
|
if (RegQueryValueEx(hKey, "InstallDir", NULL, NULL, (LPBYTE)buf,
|
|
|
|
&dwBufLen) == ERROR_SUCCESS)
|
|
|
|
if (strcmp(buf, ""))
|
2001-07-18 05:04:46 +00:00
|
|
|
m_defaultDir = buf;
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
m_targetDir = m_defaultDir;
|
|
|
|
|
|
|
|
// Set checkbox defaults
|
|
|
|
m_autoStart = TRUE;
|
|
|
|
m_keepFiles = TRUE;
|
|
|
|
|
|
|
|
UpdateData(FALSE);
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
return (TRUE); /* return(TRUE) unless you set the focus to a control */
|
2001-07-18 05:04:46 +00:00
|
|
|
}
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2001-07-18 05:04:46 +00:00
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
void CBINDInstallDlg::OnPaint() {
|
|
|
|
if (IsIconic()) {
|
2001-07-18 05:04:46 +00:00
|
|
|
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);
|
|
|
|
}
|
2001-09-25 01:48:49 +00:00
|
|
|
else {
|
2001-07-18 05:04:46 +00:00
|
|
|
CDialog::OnPaint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The system calls this to obtain the cursor to display while the user drags
|
|
|
|
// the minimized window.
|
2001-09-25 01:48:49 +00:00
|
|
|
HCURSOR CBINDInstallDlg::OnQueryDragIcon() {
|
2001-07-18 05:04:46 +00:00
|
|
|
return((HCURSOR)m_hIcon);
|
|
|
|
}
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
void CBINDInstallDlg::OnBrowse() {
|
2001-07-18 05:04:46 +00:00
|
|
|
|
|
|
|
CDirBrowse browse;
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
if (browse.DoModal() == IDOK) {
|
2001-07-18 05:04:46 +00:00
|
|
|
//m_targetDir = browse.m_selectedDir;
|
|
|
|
UpdateData(FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* User pressed the exit button
|
|
|
|
*/
|
2001-09-25 01:48:49 +00:00
|
|
|
void CBINDInstallDlg::OnExit() {
|
2008-12-14 21:33:25 +00:00
|
|
|
EndDialog(0);
|
2001-07-18 05:04:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* User pressed the uninstall button. Make it go.
|
|
|
|
*/
|
2001-09-25 01:48:49 +00:00
|
|
|
void CBINDInstallDlg::OnUninstall() {
|
2008-12-14 21:33:25 +00:00
|
|
|
UpdateData();
|
2001-07-18 05:04:46 +00:00
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
if (MsgBox(IDS_UNINSTALL, MB_YESNO) == IDYES) {
|
|
|
|
if (CheckBINDService())
|
2001-07-18 05:04:46 +00:00
|
|
|
StopBINDService();
|
|
|
|
|
2004-03-16 05:52:24 +00:00
|
|
|
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL,
|
2001-09-26 02:22:27 +00:00
|
|
|
SC_MANAGER_ALL_ACCESS);
|
2001-09-25 01:48:49 +00:00
|
|
|
if (!hSCManager) {
|
2001-07-18 05:04:46 +00:00
|
|
|
MsgBox(IDS_ERR_OPEN_SCM, GetErrMessage());
|
|
|
|
return;
|
|
|
|
}
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2004-03-16 05:52:24 +00:00
|
|
|
SC_HANDLE hService = OpenService(hSCManager, BIND_SERVICE_NAME,
|
2001-09-25 01:48:49 +00:00
|
|
|
SERVICE_ALL_ACCESS);
|
2001-09-26 02:22:27 +00:00
|
|
|
if (!hService && GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST){
|
2001-07-18 05:04:46 +00:00
|
|
|
MsgBox(IDS_ERR_OPEN_SERVICE, GetErrMessage());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SERVICE_STATUS ss;
|
|
|
|
QueryServiceStatus(hService, &ss);
|
2001-09-25 01:48:49 +00:00
|
|
|
if (ss.dwCurrentState == SERVICE_RUNNING) {
|
|
|
|
BOOL rc = ControlService(hService,
|
2008-12-14 21:33:25 +00:00
|
|
|
SERVICE_CONTROL_STOP, &ss);
|
2001-09-25 01:48:49 +00:00
|
|
|
if (rc == FALSE || ss.dwCurrentState != SERVICE_STOPPED) {
|
2001-07-18 05:04:46 +00:00
|
|
|
MsgBox(IDS_ERR_STOP_SERVICE, GetErrMessage());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
CloseServiceHandle(hService);
|
|
|
|
CloseServiceHandle(hSCManager);
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
// Directories
|
|
|
|
m_etcDir = m_targetDir + "\\etc";
|
|
|
|
m_binDir = m_targetDir + "\\bin";
|
|
|
|
|
|
|
|
UninstallTags();
|
|
|
|
UnregisterMessages(TRUE);
|
|
|
|
UnregisterService(TRUE);
|
|
|
|
DeleteFiles(TRUE);
|
2001-09-25 01:48:49 +00:00
|
|
|
if (m_keepFiles == FALSE)
|
2001-07-18 05:04:46 +00:00
|
|
|
RemoveDirs(TRUE);
|
|
|
|
else
|
|
|
|
GetDlgItem(IDC_CREATE_DIR)->SetWindowText("Not Removed");
|
|
|
|
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
// 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);
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
ProgramGroup(FALSE);
|
|
|
|
|
|
|
|
SetCurrent(IDS_UNINSTALL_DONE);
|
|
|
|
MsgBox(IDS_UNINSTALL_DONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* User pressed the install button. Make it go.
|
|
|
|
*/
|
2001-09-25 01:48:49 +00:00
|
|
|
void CBINDInstallDlg::OnInstall() {
|
2007-10-31 01:34:19 +00:00
|
|
|
#if _MSC_VER >= 1400
|
|
|
|
char Vcredist_x86[MAX_PATH];
|
|
|
|
#endif
|
2001-07-18 05:04:46 +00:00
|
|
|
BOOL success = FALSE;
|
2005-10-11 22:54:45 +00:00
|
|
|
int oldlen;
|
2001-07-18 05:04:46 +00:00
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
if (CheckBINDService())
|
2001-07-18 05:04:46 +00:00
|
|
|
StopBINDService();
|
|
|
|
|
|
|
|
InstallTags();
|
|
|
|
|
|
|
|
UpdateData();
|
|
|
|
|
2009-09-01 06:51:47 +00:00
|
|
|
if (!m_toolsOnly && m_accountName != LOCAL_SERVICE) {
|
2009-08-25 06:47:06 +00:00
|
|
|
/*
|
|
|
|
* Check that the Passwords entered match.
|
|
|
|
*/
|
|
|
|
if (m_accountPassword != m_accountPasswordConfirm) {
|
|
|
|
MsgBox(IDS_ERR_PASSWORD);
|
|
|
|
return;
|
|
|
|
}
|
2001-09-25 01:48:49 +00:00
|
|
|
|
2009-08-25 06:47:06 +00:00
|
|
|
/*
|
|
|
|
* Check that there is not leading / trailing whitespace.
|
|
|
|
* This is for compatibility with the standard password dialog.
|
|
|
|
* Passwords really should be treated as opaque blobs.
|
|
|
|
*/
|
|
|
|
oldlen = m_accountPassword.GetLength();
|
|
|
|
m_accountPassword.TrimLeft();
|
|
|
|
m_accountPassword.TrimRight();
|
|
|
|
if (m_accountPassword.GetLength() != oldlen) {
|
|
|
|
MsgBox(IDS_ERR_WHITESPACE);
|
|
|
|
return;
|
|
|
|
}
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2009-08-25 06:47:06 +00:00
|
|
|
/*
|
|
|
|
* Check the entered account name.
|
|
|
|
*/
|
|
|
|
if (ValidateServiceAccount() == FALSE)
|
|
|
|
return;
|
2001-09-25 01:48:49 +00:00
|
|
|
|
2009-08-25 06:47:06 +00:00
|
|
|
/*
|
|
|
|
* For Registration we need to know if account was changed.
|
|
|
|
*/
|
|
|
|
if (m_accountName != m_currentAccount)
|
|
|
|
m_accountUsed = FALSE;
|
2001-09-26 02:22:27 +00:00
|
|
|
|
2009-08-25 06:47:06 +00:00
|
|
|
if (m_accountUsed == FALSE && m_serviceExists == FALSE)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Check that the Password is not null.
|
|
|
|
*/
|
|
|
|
if (m_accountPassword.GetLength() == 0) {
|
|
|
|
MsgBox(IDS_ERR_NULLPASSWORD);
|
|
|
|
return;
|
|
|
|
}
|
2006-02-24 03:47:22 +00:00
|
|
|
}
|
2009-09-01 06:51:47 +00:00
|
|
|
} else if (m_accountName == LOCAL_SERVICE) {
|
|
|
|
/* The LocalService always exists. */
|
|
|
|
m_accountExists = TRUE;
|
|
|
|
if (m_accountName != m_currentAccount)
|
|
|
|
m_accountUsed = FALSE;
|
2006-02-24 03:47:22 +00:00
|
|
|
}
|
|
|
|
|
2001-09-26 02:22:27 +00:00
|
|
|
/* Directories */
|
2001-07-18 05:04:46 +00:00
|
|
|
m_etcDir = m_targetDir + "\\etc";
|
|
|
|
m_binDir = m_targetDir + "\\bin";
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
if (m_defaultDir != m_targetDir) {
|
|
|
|
if (GetFileAttributes(m_targetDir) != 0xFFFFFFFF)
|
2001-07-18 05:04:46 +00:00
|
|
|
{
|
2001-09-26 02:22:27 +00:00
|
|
|
int install = MsgBox(IDS_DIREXIST,
|
|
|
|
MB_YESNO | MB_ICONQUESTION, m_targetDir);
|
2001-09-25 01:48:49 +00:00
|
|
|
if (install == IDNO)
|
2001-07-18 05:04:46 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-09-25 01:48:49 +00:00
|
|
|
else {
|
2001-09-26 02:22:27 +00:00
|
|
|
int createDir = MsgBox(IDS_CREATEDIR,
|
|
|
|
MB_YESNO | MB_ICONQUESTION, m_targetDir);
|
2001-09-25 01:48:49 +00:00
|
|
|
if (createDir == IDNO)
|
2001-07-18 05:04:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-25 06:47:06 +00:00
|
|
|
if (!m_toolsOnly) {
|
|
|
|
if (m_accountExists == FALSE) {
|
|
|
|
success = CreateServiceAccount(m_accountName.GetBuffer(30),
|
|
|
|
m_accountPassword.GetBuffer(30));
|
|
|
|
if (success == FALSE) {
|
|
|
|
MsgBox(IDS_CREATEACCOUNT_FAILED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_accountExists = TRUE;
|
2001-09-25 01:48:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-19 04:16:55 +00:00
|
|
|
ProgramGroup(FALSE);
|
2001-07-18 05:04:46 +00:00
|
|
|
|
2007-05-21 03:42:00 +00:00
|
|
|
#if _MSC_VER >= 1400
|
|
|
|
/*
|
2007-05-21 05:23:50 +00:00
|
|
|
* Install Visual Studio libraries. As per:
|
|
|
|
* http://blogs.msdn.com/astebner/archive/2006/08/23/715755.aspx
|
|
|
|
*
|
|
|
|
* Vcredist_x86.exe /q:a /c:"msiexec /i vcredist.msi /qn /l*v %temp%\vcredist_x86.log"
|
2007-05-21 03:42:00 +00:00
|
|
|
*/
|
2007-05-21 05:52:21 +00:00
|
|
|
/*system(".\\Vcredist_x86.exe /q:a /c:\"msiexec /i vcredist.msi /qn /l*v %temp%\vcredist_x86.log\"");*/
|
2007-10-31 01:34:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Enclose full path to Vcredist_x86.exe in quotes as
|
|
|
|
* m_currentDir may contain spaces.
|
|
|
|
*/
|
|
|
|
sprintf(Vcredist_x86, "\"%s\\Vcredist_x86.exe\"",
|
|
|
|
(LPCTSTR) m_currentDir);
|
|
|
|
system(Vcredist_x86);
|
2007-05-21 03:42:00 +00:00
|
|
|
#endif
|
2001-09-25 01:48:49 +00:00
|
|
|
try {
|
2001-07-18 05:04:46 +00:00
|
|
|
CreateDirs();
|
2008-12-14 21:33:25 +00:00
|
|
|
CopyFiles();
|
2009-08-25 06:47:06 +00:00
|
|
|
if (!m_toolsOnly)
|
|
|
|
RegisterService();
|
2001-07-18 05:04:46 +00:00
|
|
|
RegisterMessages();
|
|
|
|
|
|
|
|
HKEY hKey;
|
|
|
|
|
|
|
|
/* Create a new key for named */
|
|
|
|
SetCurrent(IDS_CREATE_KEY);
|
2001-09-25 01:48:49 +00:00
|
|
|
if (RegCreateKey(HKEY_LOCAL_MACHINE, BIND_SUBKEY,
|
|
|
|
&hKey) == ERROR_SUCCESS) {
|
2001-07-18 05:04:46 +00:00
|
|
|
// Get the install directory
|
2001-09-25 01:48:49 +00:00
|
|
|
RegSetValueEx(hKey, "InstallDir", 0, REG_SZ,
|
|
|
|
(LPBYTE)(LPCTSTR)m_targetDir,
|
|
|
|
m_targetDir.GetLength());
|
2001-07-18 05:04:46 +00:00
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
SetCurrent(IDS_ADD_REMOVE);
|
2001-09-25 01:48:49 +00:00
|
|
|
if (RegCreateKey(HKEY_LOCAL_MACHINE, BIND_UNINSTALL_SUBKEY,
|
2005-10-11 22:54:45 +00:00
|
|
|
&hKey) == ERROR_SUCCESS) {
|
2001-07-18 05:04:46 +00:00
|
|
|
CString buf(BIND_DISPLAY_NAME);
|
|
|
|
|
2001-09-26 02:22:27 +00:00
|
|
|
RegSetValueEx(hKey, "DisplayName", 0, REG_SZ,
|
|
|
|
(LPBYTE)(LPCTSTR)buf, buf.GetLength());
|
2001-07-18 05:04:46 +00:00
|
|
|
|
2005-10-11 22:54:45 +00:00
|
|
|
buf.Format("%s\\BINDInstall.exe", m_binDir);
|
2001-09-26 02:22:27 +00:00
|
|
|
RegSetValueEx(hKey, "UninstallString", 0, REG_SZ,
|
|
|
|
(LPBYTE)(LPCTSTR)buf, buf.GetLength());
|
2001-07-18 05:04:46 +00:00
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2004-04-19 04:16:55 +00:00
|
|
|
ProgramGroup(FALSE);
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
if (m_startOnInstall)
|
2001-07-18 05:04:46 +00:00
|
|
|
StartBINDService();
|
|
|
|
}
|
2001-09-25 01:48:49 +00:00
|
|
|
catch(Exception e) {
|
2001-07-18 05:04:46 +00:00
|
|
|
MessageBox(e.resString);
|
|
|
|
SetCurrent(IDS_CLEANUP);
|
|
|
|
FailedInstall();
|
|
|
|
MsgBox(IDS_FAIL);
|
|
|
|
return;
|
|
|
|
}
|
2001-09-25 01:48:49 +00:00
|
|
|
catch(DWORD dw) {
|
2001-07-18 05:04:46 +00:00
|
|
|
CString msg;
|
|
|
|
msg.Format("A fatal error occured\n(%s)", GetErrMessage(dw));
|
|
|
|
MessageBox(msg);
|
|
|
|
SetCurrent(IDS_CLEANUP);
|
|
|
|
FailedInstall();
|
|
|
|
MsgBox(IDS_FAIL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetCurrent(IDS_INSTALL_DONE);
|
|
|
|
MsgBox(IDS_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Methods to do the work
|
|
|
|
*/
|
2001-09-25 01:48:49 +00:00
|
|
|
void CBINDInstallDlg::CreateDirs() {
|
2001-07-18 05:04:46 +00:00
|
|
|
/* s'OK if the directories already exist */
|
|
|
|
SetCurrent(IDS_CREATE_DIR, m_targetDir);
|
2001-09-25 01:48:49 +00:00
|
|
|
if (!CreateDirectory(m_targetDir, NULL) && GetLastError() != ERROR_ALREADY_EXISTS)
|
2001-07-18 05:04:46 +00:00
|
|
|
throw(Exception(IDS_ERR_CREATE_DIR, m_targetDir, GetErrMessage()));
|
|
|
|
|
|
|
|
SetCurrent(IDS_CREATE_DIR, m_etcDir);
|
2001-09-25 01:48:49 +00:00
|
|
|
if (!CreateDirectory(m_etcDir, NULL) && GetLastError() != ERROR_ALREADY_EXISTS)
|
2001-07-18 05:04:46 +00:00
|
|
|
throw(Exception(IDS_ERR_CREATE_DIR, m_etcDir, GetErrMessage()));
|
|
|
|
|
|
|
|
SetCurrent(IDS_CREATE_DIR, m_binDir);
|
2001-09-25 01:48:49 +00:00
|
|
|
if (!CreateDirectory(m_binDir, NULL) && GetLastError() != ERROR_ALREADY_EXISTS)
|
2001-07-18 05:04:46 +00:00
|
|
|
throw(Exception(IDS_ERR_CREATE_DIR, m_binDir, GetErrMessage()));
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
SetItemStatus(IDC_CREATE_DIR);
|
|
|
|
}
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
void CBINDInstallDlg::RemoveDirs(BOOL uninstall) {
|
|
|
|
if (!m_keepFiles) {
|
2001-07-18 05:04:46 +00:00
|
|
|
SetCurrent(IDS_REMOVE_DIR, m_binDir);
|
|
|
|
// Check for existence then remove if present
|
2001-09-25 01:48:49 +00:00
|
|
|
if (GetFileAttributes(m_binDir) != 0xFFFFFFFF)
|
2001-07-18 05:04:46 +00:00
|
|
|
RemoveDirectory(m_binDir);
|
|
|
|
|
|
|
|
SetCurrent(IDS_REMOVE_DIR, m_etcDir);
|
2001-09-25 01:48:49 +00:00
|
|
|
if (GetFileAttributes(m_etcDir) != 0xFFFFFFFF)
|
2001-07-18 05:04:46 +00:00
|
|
|
RemoveDirectory(m_etcDir);
|
|
|
|
|
|
|
|
SetCurrent(IDS_REMOVE_DIR, m_targetDir);
|
2001-09-25 01:48:49 +00:00
|
|
|
if (GetFileAttributes(m_targetDir) != 0xFFFFFFFF)
|
2001-07-18 05:04:46 +00:00
|
|
|
RemoveDirectory(m_targetDir);
|
|
|
|
}
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
if (uninstall)
|
2001-07-18 05:04:46 +00:00
|
|
|
SetItemStatus(IDC_CREATE_DIR, TRUE);
|
|
|
|
}
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
void CBINDInstallDlg::CopyFiles() {
|
2001-07-18 05:04:46 +00:00
|
|
|
CString destFile;
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
for (int i = 0; installFiles[i].filename; i++) {
|
2009-08-25 06:47:06 +00:00
|
|
|
if (m_toolsOnly && !installFiles[i].withTools)
|
|
|
|
continue;
|
2001-07-18 05:04:46 +00:00
|
|
|
SetCurrent(IDS_COPY_FILE, installFiles[i].filename);
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
destFile = DestDir(installFiles[i].destination) + "\\" +
|
|
|
|
installFiles[i].filename;
|
2001-07-18 05:04:46 +00:00
|
|
|
CString filespec = m_currentDir + "\\" + installFiles[i].filename;
|
2001-09-25 01:48:49 +00:00
|
|
|
CVersionInfo bindFile(destFile);
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
CVersionInfo origFile(filespec);
|
2001-09-25 01:48:49 +00:00
|
|
|
if (!origFile.IsValid() && installFiles[i].checkVer) {
|
|
|
|
if (MsgBox(IDS_FILE_BAD, MB_YESNO,
|
|
|
|
installFiles[i].filename) == IDNO)
|
|
|
|
throw(Exception(IDS_ERR_COPY_FILE,
|
|
|
|
installFiles[i].filename,
|
|
|
|
GetErrMessage()));
|
2001-07-18 05:04:46 +00:00
|
|
|
}
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
try {
|
2008-12-14 21:33:25 +00:00
|
|
|
/*
|
2001-09-25 01:48:49 +00:00
|
|
|
* Ignore Version checking. We need to make sure that all files get copied regardless
|
|
|
|
* of whether or not they are earlier or later versions since we cannot guarantee
|
|
|
|
* that we have either backward or forward compatibility between versions.
|
|
|
|
*/
|
2001-07-18 05:04:46 +00:00
|
|
|
bindFile.CopyFileNoVersion(origFile);
|
|
|
|
}
|
2001-09-25 01:48:49 +00:00
|
|
|
catch(...) {
|
|
|
|
if (installFiles[i].importance != FileData::Trivial) {
|
2008-12-14 21:33:25 +00:00
|
|
|
if (installFiles[i].importance ==
|
2001-09-25 01:48:49 +00:00
|
|
|
FileData::Critical ||
|
|
|
|
MsgBox(IDS_ERR_NONCRIT_FILE, MB_YESNO,
|
|
|
|
installFiles[i].filename,
|
|
|
|
GetErrMessage()) == IDNO)
|
2001-07-18 05:04:46 +00:00
|
|
|
{
|
|
|
|
SetItemStatus(IDC_COPY_FILE, FALSE);
|
2001-09-25 01:48:49 +00:00
|
|
|
throw(Exception(IDS_ERR_COPY_FILE,
|
|
|
|
installFiles[i].filename,
|
|
|
|
GetErrMessage()));
|
2001-07-18 05:04:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SetItemStatus(IDC_COPY_FILE);
|
|
|
|
}
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
void CBINDInstallDlg::DeleteFiles(BOOL uninstall) {
|
2001-07-18 05:04:46 +00:00
|
|
|
CString destFile;
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
for (int i = 0; installFiles[i].filename; i++) {
|
|
|
|
if (installFiles[i].checkVer)
|
2001-07-18 05:04:46 +00:00
|
|
|
continue;
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
destFile = DestDir(installFiles[i].destination) + "\\" +
|
|
|
|
installFiles[i].filename;
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
if (uninstall)
|
2001-07-18 05:04:46 +00:00
|
|
|
SetCurrent(IDS_DELETE_FILE, installFiles[i].filename);
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
DeleteFile(destFile);
|
|
|
|
}
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
if (!m_keepFiles) {
|
2001-07-18 05:04:46 +00:00
|
|
|
WIN32_FIND_DATA findData;
|
|
|
|
CString file = m_etcDir + "\\*.*";
|
|
|
|
BOOL rc;
|
|
|
|
HANDLE hFile;
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
hFile = FindFirstFile(file, &findData);
|
|
|
|
rc = hFile != INVALID_HANDLE_VALUE;
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
while (rc == TRUE) {
|
|
|
|
if (strcmp(findData.cFileName, ".") &&
|
|
|
|
strcmp(findData.cFileName, "..")) {
|
2001-07-18 05:04:46 +00:00
|
|
|
file = m_etcDir + "\\" + findData.cFileName;
|
|
|
|
SetCurrent(IDS_DELETE_FILE, file);
|
|
|
|
DeleteFile(file);
|
|
|
|
}
|
|
|
|
rc = FindNextFile(hFile, &findData);
|
|
|
|
}
|
|
|
|
FindClose(hFile);
|
|
|
|
}
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
if (uninstall)
|
2001-07-18 05:04:46 +00:00
|
|
|
SetItemStatus(IDC_COPY_FILE, TRUE);
|
2008-12-14 21:33:25 +00:00
|
|
|
}
|
2001-07-18 05:04:46 +00:00
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
/*
|
|
|
|
* Get the service account name out of the registry, if any
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
CBINDInstallDlg::GetCurrentServiceAccountName() {
|
|
|
|
HKEY hKey;
|
|
|
|
BOOL keyFound = FALSE;
|
2001-09-26 02:22:27 +00:00
|
|
|
char accountName[MAX_PATH];
|
|
|
|
DWORD nameLen = MAX_PATH;
|
2001-09-25 01:48:49 +00:00
|
|
|
CString Tmp;
|
|
|
|
m_accountUsed = FALSE;
|
|
|
|
|
|
|
|
memset(accountName, 0, nameLen);
|
|
|
|
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, BIND_SERVICE_SUBKEY, 0, KEY_READ,
|
2001-09-26 02:22:27 +00:00
|
|
|
&hKey) == ERROR_SUCCESS) {
|
2001-09-25 01:48:49 +00:00
|
|
|
keyFound = TRUE;
|
2001-09-26 02:22:27 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_serviceExists = FALSE;
|
|
|
|
}
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
if (keyFound == TRUE) {
|
|
|
|
/* Get the named service account, if one was specified */
|
|
|
|
if (RegQueryValueEx(hKey, "ObjectName", NULL, NULL,
|
|
|
|
(LPBYTE)accountName, &nameLen) != ERROR_SUCCESS)
|
|
|
|
keyFound = FALSE;
|
|
|
|
}
|
2001-09-26 02:22:27 +00:00
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
RegCloseKey(hKey);
|
2009-09-01 06:51:47 +00:00
|
|
|
if (keyFound == FALSE)
|
2001-09-25 01:48:49 +00:00
|
|
|
m_accountName = "";
|
2009-09-01 06:51:47 +00:00
|
|
|
else if (!strcmp(accountName, LOCAL_SERVICE)) {
|
|
|
|
m_accountName = LOCAL_SERVICE;
|
|
|
|
m_accountUsed = TRUE;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* LocalSystem is not a regular account and is equivalent
|
|
|
|
* to no account but with lots of privileges
|
|
|
|
*/
|
2001-09-25 01:48:49 +00:00
|
|
|
Tmp = accountName;
|
|
|
|
if (Tmp == ".\\LocalSystem")
|
|
|
|
m_accountName = "";
|
|
|
|
/* Found account strip any ".\" from it */
|
|
|
|
if (Tmp.Left(2) == ".\\") {
|
|
|
|
m_accountName = Tmp.Mid(2);
|
|
|
|
m_accountUsed = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-07-18 05:04:46 +00:00
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
BOOL
|
|
|
|
CBINDInstallDlg::ValidateServiceAccount() {
|
|
|
|
wchar_t *PrivList[MAX_PRIVS];
|
|
|
|
unsigned int PrivCount = 0;
|
|
|
|
char *Groups[MAX_GROUPS];
|
|
|
|
unsigned int totalGroups = 0;
|
|
|
|
int status;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
name = m_accountName.GetBuffer(30);
|
|
|
|
|
|
|
|
status = GetAccountPrivileges(name, PrivList, &PrivCount,
|
|
|
|
Groups, &totalGroups, MAX_GROUPS);
|
|
|
|
if (status == RTN_NOACCOUNT) {
|
|
|
|
m_accountExists = FALSE;
|
|
|
|
/* We need to do this in case an account was previously used */
|
|
|
|
m_accountUsed = FALSE;
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
if (status != RTN_OK) {
|
|
|
|
MsgBox(IDS_ERR_BADACCOUNT);
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_accountExists = TRUE;
|
|
|
|
if (PrivCount > 1) {
|
|
|
|
if (MsgBox(IDS_ERR_TOOPRIVED, MB_YESNO) == IDYES)
|
|
|
|
return (FALSE);
|
|
|
|
else
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
2001-09-26 02:22:27 +00:00
|
|
|
/* See if we have the correct privilege */
|
|
|
|
if (wcscmp(PrivList[0], SE_SERVICE_LOGON_PRIV) != 0) {
|
|
|
|
MsgBox(IDS_ERR_WRONGPRIV, PrivList[0]);
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
return (TRUE);
|
2001-09-25 01:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CBINDInstallDlg::RegisterService() {
|
2004-03-16 05:52:24 +00:00
|
|
|
SC_HANDLE hSCManager;
|
|
|
|
SC_HANDLE hService;
|
2009-09-01 06:51:47 +00:00
|
|
|
CString StartName;
|
2009-08-25 06:47:06 +00:00
|
|
|
|
2009-09-01 06:51:47 +00:00
|
|
|
if (m_accountName == LOCAL_SERVICE)
|
|
|
|
StartName = LOCAL_SERVICE;
|
|
|
|
else
|
|
|
|
StartName = ".\\" + m_accountName;
|
2001-09-26 02:22:27 +00:00
|
|
|
/*
|
|
|
|
* We need to change the service rather than create it
|
|
|
|
* if the service already exists. Do nothing if we are already
|
|
|
|
* using that account
|
|
|
|
*/
|
2009-09-01 06:51:47 +00:00
|
|
|
if (m_serviceExists == TRUE) {
|
|
|
|
if (m_accountUsed == FALSE) {
|
|
|
|
UpdateService(StartName);
|
2001-10-05 05:45:52 +00:00
|
|
|
SetItemStatus(IDC_REG_SERVICE);
|
2001-09-26 02:22:27 +00:00
|
|
|
return;
|
2009-09-01 06:51:47 +00:00
|
|
|
} else {
|
2001-10-05 05:45:52 +00:00
|
|
|
SetItemStatus(IDC_REG_SERVICE);
|
2001-09-26 02:22:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2001-07-18 05:04:46 +00:00
|
|
|
|
|
|
|
SetCurrent(IDS_OPEN_SCM);
|
|
|
|
hSCManager= OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
2001-09-25 01:48:49 +00:00
|
|
|
if (!hSCManager)
|
2001-07-18 05:04:46 +00:00
|
|
|
throw(Exception(IDS_ERR_OPEN_SCM, GetErrMessage()));
|
|
|
|
|
|
|
|
DWORD dwStart = SERVICE_DEMAND_START;
|
2001-09-25 01:48:49 +00:00
|
|
|
if (m_autoStart)
|
2001-07-18 05:04:46 +00:00
|
|
|
dwStart = SERVICE_AUTO_START;
|
|
|
|
|
|
|
|
DWORD dwServiceType = SERVICE_WIN32_OWN_PROCESS;
|
|
|
|
|
|
|
|
CString namedLoc;
|
|
|
|
namedLoc.Format("%s\\bin\\named.exe", m_targetDir);
|
|
|
|
|
|
|
|
SetCurrent(IDS_CREATE_SERVICE);
|
2001-09-25 01:48:49 +00:00
|
|
|
hService = CreateService(hSCManager, BIND_SERVICE_NAME,
|
|
|
|
BIND_DISPLAY_NAME, SERVICE_ALL_ACCESS, dwServiceType, dwStart,
|
2001-09-26 02:22:27 +00:00
|
|
|
SERVICE_ERROR_NORMAL, namedLoc, NULL, NULL, NULL, StartName,
|
2008-12-14 21:33:25 +00:00
|
|
|
m_accountPassword);
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
if (!hService && GetLastError() != ERROR_SERVICE_EXISTS)
|
2001-07-18 05:04:46 +00:00
|
|
|
throw(Exception(IDS_ERR_CREATE_SERVICE, GetErrMessage()));
|
|
|
|
|
2001-09-26 02:22:27 +00:00
|
|
|
if (hService)
|
|
|
|
CloseServiceHandle(hService);
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
if (hSCManager)
|
2001-07-18 05:04:46 +00:00
|
|
|
CloseServiceHandle(hSCManager);
|
|
|
|
|
2001-09-26 02:22:27 +00:00
|
|
|
SetItemStatus(IDC_REG_SERVICE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-01 06:51:47 +00:00
|
|
|
CBINDInstallDlg::UpdateService(CString StartName) {
|
2004-03-16 05:52:24 +00:00
|
|
|
SC_HANDLE hSCManager;
|
|
|
|
SC_HANDLE hService;
|
2001-09-26 02:22:27 +00:00
|
|
|
|
2009-08-25 06:47:06 +00:00
|
|
|
if(m_toolsOnly)
|
|
|
|
return;
|
|
|
|
|
2001-09-26 02:22:27 +00:00
|
|
|
SetCurrent(IDS_OPEN_SCM);
|
|
|
|
hSCManager= OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
|
|
|
if (!hSCManager) {
|
|
|
|
MsgBox(IDS_ERR_OPEN_SCM, GetErrMessage());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD dwStart = SERVICE_DEMAND_START;
|
|
|
|
if (m_autoStart)
|
|
|
|
dwStart = SERVICE_AUTO_START;
|
|
|
|
|
|
|
|
DWORD dwServiceType = SERVICE_WIN32_OWN_PROCESS;
|
|
|
|
|
|
|
|
CString namedLoc;
|
|
|
|
namedLoc.Format("%s\\bin\\named.exe", m_targetDir);
|
|
|
|
|
|
|
|
SetCurrent(IDS_OPEN_SERVICE);
|
|
|
|
hService = OpenService(hSCManager, BIND_SERVICE_NAME,
|
|
|
|
SERVICE_CHANGE_CONFIG);
|
|
|
|
if (!hService)
|
|
|
|
{
|
|
|
|
MsgBox(IDS_ERR_OPEN_SERVICE, GetErrMessage());
|
|
|
|
if (hSCManager)
|
|
|
|
CloseServiceHandle(hSCManager);
|
|
|
|
return;
|
2009-09-01 06:51:47 +00:00
|
|
|
} else {
|
2001-09-26 02:22:27 +00:00
|
|
|
if (ChangeServiceConfig(hService, dwServiceType, dwStart,
|
|
|
|
SERVICE_ERROR_NORMAL, namedLoc, NULL, NULL, NULL,
|
2009-09-01 06:51:47 +00:00
|
|
|
StartName, m_accountPassword, BIND_DISPLAY_NAME)
|
2001-09-26 02:22:27 +00:00
|
|
|
!= TRUE) {
|
|
|
|
DWORD err = GetLastError();
|
|
|
|
MsgBox(IDS_ERR_UPDATE_SERVICE, GetErrMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
if (hService)
|
2001-07-18 05:04:46 +00:00
|
|
|
CloseServiceHandle(hService);
|
|
|
|
|
2001-09-26 02:22:27 +00:00
|
|
|
if (hSCManager)
|
|
|
|
CloseServiceHandle(hSCManager);
|
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
SetItemStatus(IDC_REG_SERVICE);
|
|
|
|
}
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
void CBINDInstallDlg::UnregisterService(BOOL uninstall) {
|
2001-07-18 05:04:46 +00:00
|
|
|
BOOL rc = FALSE;
|
2004-03-16 05:52:24 +00:00
|
|
|
SC_HANDLE hSCManager;
|
|
|
|
SC_HANDLE hService;
|
2001-07-18 05:04:46 +00:00
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
while(1) {
|
2001-07-18 05:04:46 +00:00
|
|
|
SetCurrent(IDS_OPEN_SCM);
|
|
|
|
hSCManager= OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
2001-09-25 01:48:49 +00:00
|
|
|
if (!hSCManager && uninstall == TRUE) {
|
2001-07-18 05:04:46 +00:00
|
|
|
MsgBox(IDS_ERR_OPEN_SCM, GetErrMessage());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetCurrent(IDS_OPEN_SERVICE);
|
2001-09-25 01:48:49 +00:00
|
|
|
hService = OpenService(hSCManager, BIND_SERVICE_NAME,
|
|
|
|
STANDARD_RIGHTS_REQUIRED);
|
|
|
|
if (!hService && uninstall == TRUE)
|
2001-07-18 05:04:46 +00:00
|
|
|
{
|
2001-09-25 01:48:49 +00:00
|
|
|
if (GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST) {
|
2001-07-18 05:04:46 +00:00
|
|
|
MsgBox(IDS_ERR_OPEN_SERVICE, GetErrMessage());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-09-25 01:48:49 +00:00
|
|
|
else {
|
2001-07-18 05:04:46 +00:00
|
|
|
SetCurrent(IDS_REMOVE_SERVICE);
|
2001-09-25 01:48:49 +00:00
|
|
|
if (!DeleteService(hService) && uninstall == TRUE) {
|
2001-07-18 05:04:46 +00:00
|
|
|
DWORD err = GetLastError();
|
2001-09-25 01:48:49 +00:00
|
|
|
if (err != ERROR_SERVICE_MARKED_FOR_DELETE &&
|
|
|
|
err != ERROR_SERVICE_DOES_NOT_EXIST) {
|
2001-07-18 05:04:46 +00:00
|
|
|
MsgBox(IDS_ERR_REMOVE_SERVICE, GetErrMessage());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
if (hService)
|
2001-07-18 05:04:46 +00:00
|
|
|
CloseServiceHandle(hService);
|
|
|
|
|
2001-09-26 02:22:27 +00:00
|
|
|
if (hSCManager)
|
|
|
|
CloseServiceHandle(hSCManager);
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
if (uninstall)
|
2001-07-18 05:04:46 +00:00
|
|
|
SetItemStatus(IDC_REG_SERVICE, rc);
|
|
|
|
}
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
void CBINDInstallDlg::RegisterMessages() {
|
2001-07-18 05:04:46 +00:00
|
|
|
HKEY hKey;
|
|
|
|
DWORD dwData;
|
2007-10-31 00:05:36 +00:00
|
|
|
char pszMsgDLL[MAX_PATH];
|
2001-07-18 05:04:46 +00:00
|
|
|
|
2007-10-31 00:05:36 +00:00
|
|
|
sprintf(pszMsgDLL, "%s\\%s", (LPCTSTR)m_binDir, "bindevt.dll");
|
2001-07-18 05:04:46 +00:00
|
|
|
|
|
|
|
SetCurrent(IDS_REGISTER_MESSAGES);
|
|
|
|
/* Create a new key for named */
|
2001-09-25 01:48:49 +00:00
|
|
|
if (RegCreateKey(HKEY_LOCAL_MACHINE, BIND_MESSAGE_SUBKEY, &hKey)
|
|
|
|
!= ERROR_SUCCESS)
|
2001-07-18 05:04:46 +00:00
|
|
|
throw(Exception(IDS_ERR_CREATE_KEY, GetErrMessage()));
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
/* Add the Event-ID message-file name to the subkey. */
|
2001-09-25 01:48:49 +00:00
|
|
|
if (RegSetValueEx(hKey, "EventMessageFile", 0, REG_EXPAND_SZ,
|
2009-09-29 04:38:23 +00:00
|
|
|
(LPBYTE)pszMsgDLL, (DWORD)(strlen(pszMsgDLL) + 1)) != ERROR_SUCCESS)
|
2001-07-18 05:04:46 +00:00
|
|
|
throw(Exception(IDS_ERR_SET_VALUE, GetErrMessage()));
|
|
|
|
|
|
|
|
/* Set the supported types flags and addit to the subkey. */
|
|
|
|
dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
|
2001-09-25 01:48:49 +00:00
|
|
|
if (RegSetValueEx(hKey, "TypesSupported", 0, REG_DWORD,
|
|
|
|
(LPBYTE)&dwData, sizeof(DWORD)) != ERROR_SUCCESS)
|
2001-07-18 05:04:46 +00:00
|
|
|
throw(Exception(IDS_ERR_SET_VALUE, GetErrMessage()));
|
|
|
|
|
|
|
|
RegCloseKey(hKey);
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
SetItemStatus(IDC_REG_MESSAGE);
|
|
|
|
}
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
void CBINDInstallDlg::UnregisterMessages(BOOL uninstall) {
|
2001-07-18 05:04:46 +00:00
|
|
|
BOOL rc = FALSE;
|
|
|
|
HKEY hKey = NULL;
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
while(1) {
|
2001-07-18 05:04:46 +00:00
|
|
|
SetCurrent(IDS_UNREGISTER_MESSAGES);
|
|
|
|
/* Open key for Application Event Log */
|
2001-09-25 01:48:49 +00:00
|
|
|
if (RegOpenKey(HKEY_LOCAL_MACHINE, EVENTLOG_APP_SUBKEY, &hKey)
|
|
|
|
!= ERROR_SUCCESS)
|
2001-07-18 05:04:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Remove named from the list of messages sources */
|
2001-09-25 01:48:49 +00:00
|
|
|
if (RegDeleteKey(hKey, BIND_MESSAGE_NAME) != ERROR_SUCCESS)
|
2001-07-18 05:04:46 +00:00
|
|
|
break;
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
rc = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
if (hKey)
|
2001-07-18 05:04:46 +00:00
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
if (uninstall)
|
2001-07-18 05:04:46 +00:00
|
|
|
SetItemStatus(IDC_REG_MESSAGE, rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Install failed - clean up quietly
|
|
|
|
*/
|
2001-09-25 01:48:49 +00:00
|
|
|
void CBINDInstallDlg::FailedInstall() {
|
2001-07-18 05:04:46 +00:00
|
|
|
UnregisterMessages(FALSE);
|
|
|
|
UnregisterService(FALSE);
|
|
|
|
DeleteFiles(FALSE);
|
|
|
|
RemoveDirs(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the checklist tags for install
|
|
|
|
*/
|
2001-09-25 01:48:49 +00:00
|
|
|
void CBINDInstallDlg::InstallTags() {
|
2001-07-18 05:04:46 +00:00
|
|
|
CString tag;
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
tag.LoadString(IDS_INSTALL_FILE);
|
|
|
|
GetDlgItem(IDC_COPY_TAG)->SetWindowText(tag);
|
|
|
|
GetDlgItem(IDC_COPY_FILE)->SetWindowText("");
|
|
|
|
|
|
|
|
tag.LoadString(IDS_INSTALL_DIR);
|
|
|
|
GetDlgItem(IDC_DIR_TAG)->SetWindowText(tag);
|
|
|
|
GetDlgItem(IDC_CREATE_DIR)->SetWindowText("");
|
|
|
|
GetDlgItem(IDC_REG_SERVICE)->SetWindowText("");
|
|
|
|
|
|
|
|
tag.LoadString(IDS_INSTALL_SERVICE);
|
|
|
|
GetDlgItem(IDC_SERVICE_TAG)->SetWindowText(tag);
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
tag.LoadString(IDS_INSTALL_MESSAGE);
|
|
|
|
GetDlgItem(IDC_MESSAGE_TAG)->SetWindowText(tag);
|
|
|
|
GetDlgItem(IDC_REG_MESSAGE)->SetWindowText("");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the checklist tags for uninstall
|
|
|
|
*/
|
2001-09-25 01:48:49 +00:00
|
|
|
void CBINDInstallDlg::UninstallTags() {
|
2001-07-18 05:04:46 +00:00
|
|
|
CString tag;
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
tag.LoadString(IDS_UNINSTALL_FILES);
|
|
|
|
GetDlgItem(IDC_COPY_TAG)->SetWindowText(tag);
|
|
|
|
GetDlgItem(IDC_COPY_FILE)->SetWindowText("");
|
|
|
|
|
|
|
|
tag.LoadString(IDS_UNINSTALL_DIR);
|
|
|
|
GetDlgItem(IDC_DIR_TAG)->SetWindowText(tag);
|
|
|
|
GetDlgItem(IDC_CREATE_DIR)->SetWindowText("");
|
|
|
|
|
|
|
|
tag.LoadString(IDS_UNINSTALL_SERVICE);
|
|
|
|
GetDlgItem(IDC_SERVICE_TAG)->SetWindowText(tag);
|
|
|
|
GetDlgItem(IDC_REG_SERVICE)->SetWindowText("");
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
tag.LoadString(IDS_UNINSTALL_MESSAGE);
|
|
|
|
GetDlgItem(IDC_MESSAGE_TAG)->SetWindowText(tag);
|
|
|
|
GetDlgItem(IDC_REG_MESSAGE)->SetWindowText("");
|
|
|
|
}
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
void CBINDInstallDlg::SetItemStatus(UINT nID, BOOL bSuccess) {
|
2001-07-18 05:04:46 +00:00
|
|
|
GetDlgItem(nID)->SetWindowText(bSuccess == TRUE ? "Done" : "Failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the text in the current operation field - use a string table string
|
|
|
|
*/
|
2001-09-25 01:48:49 +00:00
|
|
|
void CBINDInstallDlg::SetCurrent(int id, ...) {
|
2001-07-18 05:04:46 +00:00
|
|
|
CString format;
|
|
|
|
va_list va;
|
|
|
|
char buf[128];
|
|
|
|
|
|
|
|
format.LoadString(id);
|
|
|
|
memset(buf, 0, 128);
|
|
|
|
|
|
|
|
va_start(va, id);
|
|
|
|
vsprintf(buf, format, va);
|
|
|
|
va_end(va);
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
m_current.Format("%s", buf);
|
|
|
|
UpdateData(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop the BIND service
|
|
|
|
*/
|
2001-09-25 01:48:49 +00:00
|
|
|
void CBINDInstallDlg::StopBINDService() {
|
2001-07-18 05:04:46 +00:00
|
|
|
SERVICE_STATUS svcStatus;
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
SetCurrent(IDS_STOP_SERVICE);
|
|
|
|
|
2004-03-16 05:52:24 +00:00
|
|
|
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
2001-09-25 01:48:49 +00:00
|
|
|
if (!hSCManager) {
|
2001-07-18 05:04:46 +00:00
|
|
|
MsgBox(IDS_ERR_OPEN_SCM, GetErrMessage());
|
|
|
|
}
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2004-03-16 05:52:24 +00:00
|
|
|
SC_HANDLE hBINDSvc = OpenService(hSCManager, BIND_SERVICE_NAME,
|
2001-09-25 01:48:49 +00:00
|
|
|
SERVICE_ALL_ACCESS);
|
|
|
|
if (!hBINDSvc) {
|
2001-07-18 05:04:46 +00:00
|
|
|
MsgBox(IDS_ERR_OPEN_SERVICE, GetErrMessage());
|
|
|
|
}
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
BOOL rc = ControlService(hBINDSvc, SERVICE_CONTROL_STOP, &svcStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start the BIND service
|
|
|
|
*/
|
2001-09-25 01:48:49 +00:00
|
|
|
void CBINDInstallDlg::StartBINDService() {
|
2001-07-18 05:04:46 +00:00
|
|
|
SetCurrent(IDS_START_SERVICE);
|
|
|
|
|
2004-03-16 05:52:24 +00:00
|
|
|
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
2001-09-25 01:48:49 +00:00
|
|
|
if (!hSCManager) {
|
2001-07-18 05:04:46 +00:00
|
|
|
MsgBox(IDS_ERR_OPEN_SCM, GetErrMessage());
|
|
|
|
}
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2004-03-16 05:52:24 +00:00
|
|
|
SC_HANDLE hBINDSvc = OpenService(hSCManager, BIND_SERVICE_NAME,
|
2001-09-25 01:48:49 +00:00
|
|
|
SERVICE_ALL_ACCESS);
|
|
|
|
if (!hBINDSvc) {
|
2001-07-18 05:04:46 +00:00
|
|
|
MsgBox(IDS_ERR_OPEN_SERVICE, GetErrMessage());
|
|
|
|
}
|
|
|
|
BOOL rc = StartService(hBINDSvc, 0, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check to see if the BIND service is running or not
|
|
|
|
*/
|
2001-09-25 01:48:49 +00:00
|
|
|
BOOL CBINDInstallDlg::CheckBINDService() {
|
2001-07-18 05:04:46 +00:00
|
|
|
SERVICE_STATUS svcStatus;
|
|
|
|
|
2004-03-16 05:52:24 +00:00
|
|
|
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
2001-09-25 01:48:49 +00:00
|
|
|
if (hSCManager) {
|
2004-03-16 05:52:24 +00:00
|
|
|
SC_HANDLE hBINDSvc = OpenService(hSCManager, BIND_SERVICE_NAME,
|
2001-09-25 01:48:49 +00:00
|
|
|
SERVICE_ALL_ACCESS);
|
|
|
|
if (hBINDSvc) {
|
|
|
|
BOOL rc = ControlService(hBINDSvc,
|
|
|
|
SERVICE_CONTROL_INTERROGATE, &svcStatus);
|
|
|
|
if (!rc)
|
2001-07-18 05:04:46 +00:00
|
|
|
DWORD err = GetLastError();
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
return (svcStatus.dwCurrentState == SERVICE_RUNNING);
|
2001-07-18 05:04:46 +00:00
|
|
|
}
|
|
|
|
}
|
2001-09-25 01:48:49 +00:00
|
|
|
return (FALSE);
|
2001-07-18 05:04:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-09-25 01:48:49 +00:00
|
|
|
* Display message boxes with variable args, using string table strings
|
2008-12-14 21:33:25 +00:00
|
|
|
* for the format specifiers
|
2001-07-18 05:04:46 +00:00
|
|
|
*/
|
2001-09-25 01:48:49 +00:00
|
|
|
int CBINDInstallDlg::MsgBox(int id, ...) {
|
2001-07-18 05:04:46 +00:00
|
|
|
CString format;
|
|
|
|
va_list va;
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
|
|
|
|
format.LoadString(id);
|
|
|
|
memset(buf, 0, BUFSIZ);
|
|
|
|
|
|
|
|
va_start(va, id);
|
|
|
|
vsprintf(buf, format, va);
|
|
|
|
va_end(va);
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
return (MessageBox(buf));
|
2001-07-18 05:04:46 +00:00
|
|
|
}
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
int CBINDInstallDlg::MsgBox(int id, UINT type, ...) {
|
2001-07-18 05:04:46 +00:00
|
|
|
CString format;
|
|
|
|
va_list va;
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
|
|
|
|
format.LoadString(id);
|
|
|
|
memset(buf, 0, BUFSIZ);
|
|
|
|
|
|
|
|
va_start(va, type);
|
|
|
|
vsprintf(buf, format, va);
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return(MessageBox(buf, NULL, type));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call GetLastError(), retrieve the message associated with the error
|
|
|
|
*/
|
2008-12-14 21:33:25 +00:00
|
|
|
CString CBINDInstallDlg::GetErrMessage(DWORD err) {
|
2001-07-18 05:04:46 +00:00
|
|
|
LPVOID msgBuf;
|
|
|
|
static char buf[BUFSIZ];
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
DWORD len = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
|
|
NULL, err == -1 ? GetLastError() : err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &msgBuf, 0, NULL );
|
|
|
|
|
|
|
|
|
|
|
|
strcpy(buf, (LPTSTR)msgBuf);
|
|
|
|
LocalFree(msgBuf);
|
|
|
|
/* Strip off the period and the \n */
|
|
|
|
buf[len - 3] = 0;
|
|
|
|
return(buf);
|
|
|
|
}
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
void CBINDInstallDlg::ProgramGroup(BOOL create) {
|
2001-07-18 05:04:46 +00:00
|
|
|
TCHAR path[MAX_PATH], commonPath[MAX_PATH], fileloc[MAX_PATH], linkpath[MAX_PATH];
|
2008-12-14 21:33:25 +00:00
|
|
|
HRESULT hres;
|
|
|
|
IShellLink *psl = NULL;
|
2001-07-18 05:04:46 +00:00
|
|
|
LPMALLOC pMalloc = NULL;
|
|
|
|
ITEMIDLIST *itemList = NULL;
|
|
|
|
|
|
|
|
HRESULT hr = SHGetMalloc(&pMalloc);
|
2001-09-25 01:48:49 +00:00
|
|
|
if (hr != NOERROR) {
|
2001-07-18 05:04:46 +00:00
|
|
|
MessageBox("Could not get a handle to Shell memory object");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = SHGetSpecialFolderLocation(m_hWnd, CSIDL_COMMON_PROGRAMS, &itemList);
|
2001-09-25 01:48:49 +00:00
|
|
|
if (hr != NOERROR) {
|
2001-07-18 05:04:46 +00:00
|
|
|
MessageBox("Could not get a handle to the Common Programs folder");
|
2001-09-25 01:48:49 +00:00
|
|
|
if (itemList) {
|
2001-07-18 05:04:46 +00:00
|
|
|
pMalloc->Free(itemList);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
hr = SHGetPathFromIDList(itemList, commonPath);
|
|
|
|
pMalloc->Free(itemList);
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
if (create) {
|
2001-07-18 05:04:46 +00:00
|
|
|
sprintf(path, "%s\\ISC", commonPath);
|
|
|
|
CreateDirectory(path, NULL);
|
2008-12-14 21:33:25 +00:00
|
|
|
|
2001-07-18 05:04:46 +00:00
|
|
|
sprintf(path, "%s\\ISC\\BIND", commonPath);
|
|
|
|
CreateDirectory(path, NULL);
|
|
|
|
|
|
|
|
hres = CoInitialize(NULL);
|
|
|
|
|
2008-12-14 21:33:25 +00:00
|
|
|
if (SUCCEEDED(hres)) {
|
|
|
|
// Get a pointer to the IShellLink interface.
|
|
|
|
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *)&psl);
|
2001-07-18 05:04:46 +00:00
|
|
|
if (SUCCEEDED(hres))
|
2008-12-14 21:33:25 +00:00
|
|
|
{
|
|
|
|
IPersistFile* ppf;
|
2001-07-18 05:04:46 +00:00
|
|
|
sprintf(linkpath, "%s\\BINDCtrl.lnk", path);
|
|
|
|
sprintf(fileloc, "%s\\BINDCtrl.exe", m_binDir);
|
|
|
|
|
2008-12-14 21:33:25 +00:00
|
|
|
psl->SetPath(fileloc);
|
|
|
|
psl->SetDescription("BIND Control Panel");
|
2001-07-18 05:04:46 +00:00
|
|
|
|
2008-12-14 21:33:25 +00:00
|
|
|
hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
|
|
|
|
if (SUCCEEDED(hres)) {
|
|
|
|
WCHAR wsz[MAX_PATH];
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, linkpath, -1, wsz, MAX_PATH);
|
|
|
|
hres = ppf->Save(wsz, TRUE);
|
|
|
|
ppf->Release();
|
|
|
|
}
|
2001-07-18 05:04:46 +00:00
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
if (GetFileAttributes("readme.txt") != -1) {
|
2001-07-18 05:04:46 +00:00
|
|
|
sprintf(fileloc, "%s\\Readme.txt", m_targetDir);
|
|
|
|
sprintf(linkpath, "%s\\Readme.lnk", path);
|
|
|
|
|
2008-12-14 21:33:25 +00:00
|
|
|
psl->SetPath(fileloc);
|
|
|
|
psl->SetDescription("BIND Readme");
|
2001-07-18 05:04:46 +00:00
|
|
|
|
2008-12-14 21:33:25 +00:00
|
|
|
hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
|
|
|
|
if (SUCCEEDED(hres)) {
|
|
|
|
WCHAR wsz[MAX_PATH];
|
2001-07-18 05:04:46 +00:00
|
|
|
|
2008-12-14 21:33:25 +00:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, linkpath, -1, wsz, MAX_PATH);
|
|
|
|
hres = ppf->Save(wsz, TRUE);
|
|
|
|
ppf->Release();
|
|
|
|
}
|
|
|
|
psl->Release();
|
2001-07-18 05:04:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
CoUninitialize();
|
2008-12-14 21:33:25 +00:00
|
|
|
}
|
2001-07-18 05:04:46 +00:00
|
|
|
}
|
2001-09-25 01:48:49 +00:00
|
|
|
else {
|
2001-07-18 05:04:46 +00:00
|
|
|
TCHAR filename[MAX_PATH];
|
|
|
|
WIN32_FIND_DATA fd;
|
|
|
|
|
|
|
|
sprintf(path, "%s\\ISC\\BIND", commonPath);
|
|
|
|
|
|
|
|
sprintf(filename, "%s\\*.*", path);
|
|
|
|
HANDLE hFind = FindFirstFile(filename, &fd);
|
2001-09-25 01:48:49 +00:00
|
|
|
if (hFind != INVALID_HANDLE_VALUE) {
|
|
|
|
do {
|
|
|
|
if (strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..")) {
|
2001-07-18 05:04:46 +00:00
|
|
|
sprintf(filename, "%s\\%s", path, fd.cFileName);
|
|
|
|
DeleteFile(filename);
|
|
|
|
}
|
2001-09-25 01:48:49 +00:00
|
|
|
} while (FindNextFile(hFind, &fd));
|
2001-07-18 05:04:46 +00:00
|
|
|
FindClose(hFind);
|
|
|
|
}
|
|
|
|
RemoveDirectory(path);
|
|
|
|
sprintf(path, "%s\\ISC", commonPath);
|
|
|
|
RemoveDirectory(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-25 01:48:49 +00:00
|
|
|
CString CBINDInstallDlg::DestDir(int destination) {
|
|
|
|
switch(destination) {
|
2001-07-18 05:04:46 +00:00
|
|
|
case FileData::TargetDir:
|
|
|
|
return m_targetDir;
|
|
|
|
case FileData::BinDir:
|
|
|
|
return m_binDir;
|
|
|
|
case FileData::EtcDir:
|
|
|
|
return m_etcDir;
|
|
|
|
case FileData::WinSystem:
|
|
|
|
return m_winSysDir;
|
|
|
|
}
|
|
|
|
return("");
|
|
|
|
}
|