BINDInstallDlg.cpp revision 5ed76fa7ea83d3ce7a33d365aa3b84410c3b8773
/*
* 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.16 2004/04/19 04:16:54 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
*/
// #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
#endif
typedef struct _xexception
{
} Exception;
{
}
typedef struct _filedata {
char *filename;
int destination;
int importance;
} FileData;
const FileData installFiles[] =
{
#ifdef BINARIES_INSTALL
# ifdef DEBUG_BINARIES
# endif
# ifdef RELEASE_BINARIES
# endif
#endif
#if _MSC_VER > 1200
#endif
};
/////////////////////////////////////////////////////////////////////////////
// CBINDInstallDlg dialog
//{{AFX_DATA_INIT(CBINDInstallDlg)
m_autoStart = FALSE;
m_keepFiles = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_winSysDir = buf;
m_defaultDir = buf;
m_defaultDir += "\\dns";
m_installed = FALSE;
if (m_accountName == "") {
m_accountName = "named";
}
}
//{{AFX_DATA_MAP(CBINDInstallDlg)
//}}AFX_DATA_MAP
}
//{{AFX_MSG_MAP(CBINDInstallDlg)
//}}AFX_MSG_MAP
/////////////////////////////////////////////////////////////////////////////
// CBINDInstallDlg message handlers
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
else
/* See if we are installed already */
== ERROR_SUCCESS) {
m_installed = TRUE;
// Get the install directory
&dwBufLen) == ERROR_SUCCESS)
m_defaultDir = buf;
}
// Set checkbox defaults
m_autoStart = TRUE;
m_keepFiles = TRUE;
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
* this is automatically done for you by the framework.
*/
void CBINDInstallDlg::OnPaint() {
if (IsIconic()) {
// Center icon in client rectangle
// Draw the icon
}
else {
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
}
void CBINDInstallDlg::OnBrowse() {
//m_targetDir = browse.m_selectedDir;
}
}
/*
* User pressed the exit button
*/
void CBINDInstallDlg::OnExit() {
EndDialog(0);
}
/*
* User pressed the uninstall button. Make it go.
*/
void CBINDInstallDlg::OnUninstall() {
UpdateData();
if (CheckBINDService())
if (!hSCManager) {
return;
}
return;
}
return;
}
}
// Directories
if (m_keepFiles == FALSE)
else
// Delete registry keys for named
}
}
/*
* User pressed the install button. Make it go.
*/
void CBINDInstallDlg::OnInstall() {
if (CheckBINDService())
InstallTags();
UpdateData();
/* Check that the Passwords entered match */
if (m_accountPassword != m_accountPasswordConfirm) {
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)
/* Directories */
if (m_defaultDir != m_targetDir) {
{
return;
}
else {
return;
}
}
if (m_accountExists == FALSE) {
return;
}
}
try {
CreateDirs();
CopyFiles();
/* Create a new key for named */
&hKey) == ERROR_SUCCESS) {
// Get the install directory
m_targetDir.GetLength());
}
&hKey) == ERROR_SUCCESS) {
}
if (m_startOnInstall)
}
catch(Exception e) {
MessageBox(e.resString);
return;
}
return;
}
}
/*
* Methods to do the work
*/
void CBINDInstallDlg::CreateDirs() {
/* s'OK if the directories already exist */
}
if (!m_keepFiles) {
// Check for existence then remove if present
}
if (uninstall)
}
void CBINDInstallDlg::CopyFiles() {
for (int i = 0; installFiles[i].filename; i++) {
installFiles[i].filename;
throw(Exception(IDS_ERR_COPY_FILE,
installFiles[i].filename,
GetErrMessage()));
}
try {
/*
* 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.
*/
}
catch(...) {
if (installFiles[i].importance ==
installFiles[i].filename,
GetErrMessage()) == IDNO)
{
throw(Exception(IDS_ERR_COPY_FILE,
installFiles[i].filename,
GetErrMessage()));
}
}
}
}
}
for (int i = 0; installFiles[i].filename; i++) {
if (installFiles[i].checkVer)
continue;
installFiles[i].filename;
if (uninstall)
}
if (!m_keepFiles) {
}
}
}
if (uninstall)
}
/*
* Get the service account name out of the registry, if any
*/
void
char accountName[MAX_PATH];
&hKey) == ERROR_SUCCESS) {
}
else {
}
/* Get the named service account, if one was specified */
}
m_accountName = "";
else {
/*
* LocalSystem is not a regular account and is equivalent
* to no account but with lots of privileges
*/
Tmp = accountName;
if (Tmp == ".\\LocalSystem")
m_accountName = "";
/* Found account strip any ".\" from it */
}
}
}
unsigned int PrivCount = 0;
char *Groups[MAX_GROUPS];
unsigned int totalGroups = 0;
int status;
char *name;
if (status == RTN_NOACCOUNT) {
/* We need to do this in case an account was previously used */
return (TRUE);
}
return (FALSE);
}
if (PrivCount > 1) {
return (FALSE);
else
return (TRUE);
}
/* See if we have the correct privilege */
return (FALSE);
}
return (TRUE);
}
void
/*
* We need to change the service rather than create it
* if the service already exists. Do nothing if we are already
* using that account
*/
if(m_serviceExists == TRUE) {
if(m_accountUsed == FALSE) {
return;
}
else {
return;
}
}
if (!hSCManager)
if (m_autoStart)
if (hService)
if (hSCManager)
}
void
if (!hSCManager) {
return;
}
if (m_autoStart)
if (!hService)
{
if (hSCManager)
return;
}
else {
!= TRUE) {
}
}
if (hService)
if (hSCManager)
}
while(1) {
break;
}
{
if (GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST) {
break;
}
}
else {
if (err != ERROR_SERVICE_MARKED_FOR_DELETE &&
break;
}
}
}
break;
}
if (hService)
if (hSCManager)
if (uninstall)
}
void CBINDInstallDlg::RegisterMessages() {
/* Create a new key for named */
!= ERROR_SUCCESS)
/* Add the Event-ID message-file name to the subkey. */
/* Set the supported types flags and addit to the subkey. */
}
while(1) {
/* Open key for Application Event Log */
!= ERROR_SUCCESS)
break;
/* Remove named from the list of messages sources */
break;
break;
}
if (hKey)
if (uninstall)
}
/*
* Install failed - clean up quietly
*/
void CBINDInstallDlg::FailedInstall() {
}
/*
* Set the checklist tags for install
*/
void CBINDInstallDlg::InstallTags() {
}
/*
* Set the checklist tags for uninstall
*/
void CBINDInstallDlg::UninstallTags() {
}
}
/*
* Set the text in the current operation field - use a string table string
*/
char buf[128];
}
/*
* Stop the BIND service
*/
void CBINDInstallDlg::StopBINDService() {
if (!hSCManager) {
}
if (!hBINDSvc) {
}
}
/*
* Start the BIND service
*/
void CBINDInstallDlg::StartBINDService() {
if (!hSCManager) {
}
if (!hBINDSvc) {
}
}
/*
* Check to see if the BIND service is running or not
*/
if (hSCManager) {
if (hBINDSvc) {
if (!rc)
}
}
return (FALSE);
}
/*
* Display message boxes with variable args, using string table strings
* for the format specifiers
*/
return (MessageBox(buf));
}
}
/*
* Call GetLastError(), retrieve the message associated with the error
*/
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 );
/* Strip off the period and the \n */
return(buf);
}
MessageBox("Could not get a handle to Shell memory object");
return;
}
MessageBox("Could not get a handle to the Common Programs folder");
if (itemList) {
}
return;
}
if (create) {
// Get a pointer to the IShellLink interface.
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *)&psl);
{
}
}
}
}
}
}
else {
if (hFind != INVALID_HANDLE_VALUE) {
do {
}
}
}
}
switch(destination) {
return m_targetDir;
return m_binDir;
return m_etcDir;
return m_winSysDir;
}
return("");
}