mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 05:57:52 +00:00
Added support for installer to change the account being used rather than uninstalling and reinstalling
This commit is contained in:
parent
a4701d3b7e
commit
7e22eec300
@ -43,7 +43,7 @@ RSC=rc.exe
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /Yu"stdafx.h" /FD /c
|
||||
# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\include" /I "..\..\..\include" /I "..\..\named\win32\include" /I "..\..\..\lib\isc\win32\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_AFXDLL" /Yu"stdafx.h" /FD /TP /c
|
||||
# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\include" /I "..\..\..\include" /I "..\..\named\win32\include" /I "..\..\..\lib\isc\win32\include" /I "..\..\..\lib\isc\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_AFXDLL" /Yu"stdafx.h" /FD /TP /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
@ -69,7 +69,7 @@ LINK32=link.exe
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /Yu"stdafx.h" /FD /GZ /c
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\include" /I "..\..\..\include" /I "..\..\named\win32\include" /I "..\..\..\lib\isc\win32\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_AFXDLL" /FR /Yu"stdafx.h" /FD /TP /GZ /c
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\include" /I "..\..\..\include" /I "..\..\named\win32\include" /I "..\..\..\lib\isc\win32\include" /I "..\..\..\lib\isc\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_AFXDLL" /FR /Yu"stdafx.h" /FD /TP /GZ /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
|
@ -131,6 +131,15 @@ BEGIN
|
||||
WS_VSCROLL | WS_TABSTOP
|
||||
END
|
||||
|
||||
IDD_DIALOG1 DIALOG DISCARDABLE 0, 0, 186, 95
|
||||
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "Dialog"
|
||||
FONT 8, "MS Sans Serif"
|
||||
BEGIN
|
||||
DEFPUSHBUTTON "OK",IDOK,129,7,50,14
|
||||
PUSHBUTTON "Cancel",IDCANCEL,129,24,50,14
|
||||
END
|
||||
|
||||
|
||||
#ifndef _MAC
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@ -212,6 +221,14 @@ BEGIN
|
||||
TOPMARGIN, 7
|
||||
BOTTOMMARGIN, 110
|
||||
END
|
||||
|
||||
IDD_DIALOG1, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 7
|
||||
RIGHTMARGIN, 179
|
||||
TOPMARGIN, 7
|
||||
BOTTOMMARGIN, 88
|
||||
END
|
||||
END
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
@ -291,9 +308,10 @@ BEGIN
|
||||
IDS_FILE_BAD "Could not retrieve version info for file %s. Do you wish to continue?\n(Continuing may overwrite a newer version of the file) "
|
||||
IDS_ERR_TOOPRIVED "Chosen account has too many privileges. Do you wish to choose a different account name?"
|
||||
IDS_ERR_BADACCOUNT "Error Validating Account. Unable to install service using this account."
|
||||
IDS_ERR_WRONGPRIV "The wrong privilege: %s was detected. The Service Logon Right privilege is required."
|
||||
IDS_ERR_WRONGPRIV "The wrong privilege: %s was detected. Only the Service Logon Right privilege should be enabled for this account."
|
||||
IDS_CREATEACCOUNT_FAILED "Unable to Create Account for the Service."
|
||||
IDS_ERR_PASSWORD "Passwords entered did not match. Please reenter password."
|
||||
IDS_ERR_UPDATE_SERVICE "Error updating service\n(%s)"
|
||||
END
|
||||
|
||||
#endif // English (U.S.) resources
|
||||
|
@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: BINDInstallDlg.cpp,v 1.8 2001/09/25 01:48:47 mayer Exp $ */
|
||||
/* $Id: BINDInstallDlg.cpp,v 1.9 2001/09/26 02:22:25 mayer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999-2000 by Nortel Networks Corporation
|
||||
@ -167,7 +167,9 @@ CBINDInstallDlg::CBINDInstallDlg(CWnd* pParent /*=NULL*/)
|
||||
m_installed = FALSE;
|
||||
m_accountExists = FALSE;
|
||||
m_accountUsed = FALSE;
|
||||
m_serviceExists = TRUE;
|
||||
GetCurrentServiceAccountName();
|
||||
m_currentAccount = m_accountName;
|
||||
if (m_accountName == "") {
|
||||
m_accountName = "named";
|
||||
}
|
||||
@ -318,7 +320,8 @@ void CBINDInstallDlg::OnUninstall() {
|
||||
if (CheckBINDService())
|
||||
StopBINDService();
|
||||
|
||||
HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||||
HANDLE hSCManager = OpenSCManager(NULL, NULL,
|
||||
SC_MANAGER_ALL_ACCESS);
|
||||
if (!hSCManager) {
|
||||
MsgBox(IDS_ERR_OPEN_SCM, GetErrMessage());
|
||||
return;
|
||||
@ -326,7 +329,7 @@ void CBINDInstallDlg::OnUninstall() {
|
||||
|
||||
HANDLE hService = OpenService(hSCManager, BIND_SERVICE_NAME,
|
||||
SERVICE_ALL_ACCESS);
|
||||
if (!hService && GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST) {
|
||||
if (!hService && GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST){
|
||||
MsgBox(IDS_ERR_OPEN_SERVICE, GetErrMessage());
|
||||
return;
|
||||
}
|
||||
@ -394,21 +397,26 @@ void CBINDInstallDlg::OnInstall() {
|
||||
if (ValidateServiceAccount() == FALSE)
|
||||
return;
|
||||
|
||||
// Directories
|
||||
|
||||
/* 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";
|
||||
|
||||
if (m_defaultDir != m_targetDir) {
|
||||
if (GetFileAttributes(m_targetDir) != 0xFFFFFFFF)
|
||||
{
|
||||
int install = MsgBox(IDS_DIREXIST, MB_YESNO | MB_ICONQUESTION,
|
||||
m_targetDir);
|
||||
int install = MsgBox(IDS_DIREXIST,
|
||||
MB_YESNO | MB_ICONQUESTION, m_targetDir);
|
||||
if (install == IDNO)
|
||||
return;
|
||||
}
|
||||
else {
|
||||
int createDir = MsgBox(IDS_CREATEDIR, MB_YESNO | MB_ICONQUESTION,
|
||||
m_targetDir);
|
||||
int createDir = MsgBox(IDS_CREATEDIR,
|
||||
MB_YESNO | MB_ICONQUESTION, m_targetDir);
|
||||
if (createDir == IDNO)
|
||||
return;
|
||||
}
|
||||
@ -421,7 +429,7 @@ void CBINDInstallDlg::OnInstall() {
|
||||
MsgBox(IDS_CREATEACCOUNT_FAILED);
|
||||
return;
|
||||
}
|
||||
m_accountExists;
|
||||
m_accountExists = TRUE;
|
||||
}
|
||||
|
||||
ProgramGroup();
|
||||
@ -453,10 +461,12 @@ void CBINDInstallDlg::OnInstall() {
|
||||
CString buf(BIND_DISPLAY_NAME);
|
||||
GetWindowsDirectory(winDir, MAX_PATH);
|
||||
|
||||
RegSetValueEx(hKey, "DisplayName", 0, REG_SZ, (LPBYTE)(LPCTSTR)buf, buf.GetLength());
|
||||
RegSetValueEx(hKey, "DisplayName", 0, REG_SZ,
|
||||
(LPBYTE)(LPCTSTR)buf, buf.GetLength());
|
||||
|
||||
buf.Format("%s\\BINDInstall.exe", winDir);
|
||||
RegSetValueEx(hKey, "UninstallString", 0, REG_SZ, (LPBYTE)(LPCTSTR)buf, buf.GetLength());
|
||||
RegSetValueEx(hKey, "UninstallString", 0, REG_SZ,
|
||||
(LPBYTE)(LPCTSTR)buf, buf.GetLength());
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
|
||||
@ -622,15 +632,19 @@ void
|
||||
CBINDInstallDlg::GetCurrentServiceAccountName() {
|
||||
HKEY hKey;
|
||||
BOOL keyFound = FALSE;
|
||||
char accountName[50];
|
||||
DWORD nameLen = strlen(accountName);
|
||||
char accountName[MAX_PATH];
|
||||
DWORD nameLen = MAX_PATH;
|
||||
CString Tmp;
|
||||
m_accountUsed = FALSE;
|
||||
|
||||
memset(accountName, 0, nameLen);
|
||||
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, BIND_SERVICE_SUBKEY, 0, KEY_READ,
|
||||
&hKey) == ERROR_SUCCESS)
|
||||
&hKey) == ERROR_SUCCESS) {
|
||||
keyFound = TRUE;
|
||||
}
|
||||
else {
|
||||
m_serviceExists = FALSE;
|
||||
}
|
||||
|
||||
if (keyFound == TRUE) {
|
||||
/* Get the named service account, if one was specified */
|
||||
@ -638,7 +652,7 @@ CBINDInstallDlg::GetCurrentServiceAccountName() {
|
||||
(LPBYTE)accountName, &nameLen) != ERROR_SUCCESS)
|
||||
keyFound = FALSE;
|
||||
}
|
||||
|
||||
|
||||
RegCloseKey(hKey);
|
||||
if(keyFound == FALSE)
|
||||
m_accountName = "";
|
||||
@ -689,18 +703,35 @@ CBINDInstallDlg::ValidateServiceAccount() {
|
||||
else
|
||||
return (TRUE);
|
||||
}
|
||||
/* See if we have the correct privilege */
|
||||
if (wcscmp(PrivList[0], SE_SERVICE_LOGON_PRIV) == 0)
|
||||
return (TRUE);
|
||||
|
||||
MsgBox(IDS_ERR_WRONGPRIV, PrivList[0]);
|
||||
return (FALSE);
|
||||
/* 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);
|
||||
}
|
||||
|
||||
void
|
||||
CBINDInstallDlg::RegisterService() {
|
||||
HANDLE hSCManager;
|
||||
HANDLE hService;
|
||||
CString StartName = ".\\" + m_accountName;
|
||||
|
||||
/*
|
||||
* 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) {
|
||||
UpdateService();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
SetCurrent(IDS_OPEN_SCM);
|
||||
hSCManager= OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||||
@ -719,17 +750,69 @@ CBINDInstallDlg::RegisterService() {
|
||||
SetCurrent(IDS_CREATE_SERVICE);
|
||||
hService = CreateService(hSCManager, BIND_SERVICE_NAME,
|
||||
BIND_DISPLAY_NAME, SERVICE_ALL_ACCESS, dwServiceType, dwStart,
|
||||
SERVICE_ERROR_NORMAL, namedLoc, NULL, NULL, NULL, NULL, NULL);
|
||||
SERVICE_ERROR_NORMAL, namedLoc, NULL, NULL, NULL, StartName,
|
||||
m_accountPassword);
|
||||
|
||||
if (!hService && GetLastError() != ERROR_SERVICE_EXISTS)
|
||||
throw(Exception(IDS_ERR_CREATE_SERVICE, GetErrMessage()));
|
||||
|
||||
if (hService)
|
||||
CloseServiceHandle(hService);
|
||||
|
||||
if (hSCManager)
|
||||
CloseServiceHandle(hSCManager);
|
||||
|
||||
SetItemStatus(IDC_REG_SERVICE);
|
||||
}
|
||||
|
||||
void
|
||||
CBINDInstallDlg::UpdateService() {
|
||||
HANDLE hSCManager;
|
||||
HANDLE hService;
|
||||
CString StartName = ".\\" + m_accountName;
|
||||
|
||||
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;
|
||||
}
|
||||
else {
|
||||
if (ChangeServiceConfig(hService, dwServiceType, dwStart,
|
||||
SERVICE_ERROR_NORMAL, namedLoc, NULL, NULL, NULL,
|
||||
StartName, m_accountPassword,BIND_DISPLAY_NAME)
|
||||
!= TRUE) {
|
||||
DWORD err = GetLastError();
|
||||
MsgBox(IDS_ERR_UPDATE_SERVICE, GetErrMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if (hService)
|
||||
CloseServiceHandle(hService);
|
||||
|
||||
if (hSCManager)
|
||||
CloseServiceHandle(hSCManager);
|
||||
|
||||
SetItemStatus(IDC_REG_SERVICE);
|
||||
}
|
||||
|
||||
@ -772,12 +855,12 @@ void CBINDInstallDlg::UnregisterService(BOOL uninstall) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (hSCManager)
|
||||
CloseServiceHandle(hSCManager);
|
||||
|
||||
if (hService)
|
||||
CloseServiceHandle(hService);
|
||||
|
||||
if (hSCManager)
|
||||
CloseServiceHandle(hSCManager);
|
||||
|
||||
if (uninstall)
|
||||
SetItemStatus(IDC_REG_SERVICE, rc);
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: BINDInstallDlg.h,v 1.4 2001/09/25 01:48:48 mayer Exp $ */
|
||||
/* $Id: BINDInstallDlg.h,v 1.5 2001/09/26 02:22:26 mayer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999-2000 by Nortel Networks Corporation
|
||||
@ -72,6 +72,7 @@ protected:
|
||||
void DeleteFiles(BOOL uninstall);
|
||||
|
||||
void RegisterService();
|
||||
void UpdateService();
|
||||
void UnregisterService(BOOL uninstall);
|
||||
|
||||
void RegisterMessages();
|
||||
@ -100,10 +101,12 @@ protected:
|
||||
CString m_currentDir;
|
||||
BOOL m_accountExists;
|
||||
BOOL m_accountUsed;
|
||||
CString m_currentAccount;
|
||||
CString m_accountName;
|
||||
CString m_accountPasswordConfirm;
|
||||
CString m_accountPassword;
|
||||
|
||||
BOOL m_serviceExists;
|
||||
|
||||
// Generated message map functions
|
||||
//{{AFX_MSG(CBINDInstallDlg)
|
||||
virtual BOOL OnInitDialog();
|
||||
|
@ -55,12 +55,14 @@
|
||||
#define IDS_ERR_WRONGPRIV 54
|
||||
#define IDS_CREATEACCOUNT_FAILED 55
|
||||
#define IDS_ERR_PASSWORD 56
|
||||
#define IDS_ERR_UPDATE_SERVICE 57
|
||||
#define IDD_BINDINSTALL_DIALOG 102
|
||||
#define IDR_MAINFRAME 128
|
||||
#define IDD_BROWSE 129
|
||||
#define IDI_CHECK 130
|
||||
#define IDI_X 132
|
||||
#define IDC_CURSOR1 142
|
||||
#define IDD_DIALOG1 143
|
||||
#define IDC_TARGETDIR 1001
|
||||
#define IDC_BROWSE 1002
|
||||
#define IDC_DIRLIST 1004
|
||||
@ -91,7 +93,7 @@
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 143
|
||||
#define _APS_NEXT_RESOURCE_VALUE 144
|
||||
#define _APS_NEXT_COMMAND_VALUE 32771
|
||||
#define _APS_NEXT_CONTROL_VALUE 1027
|
||||
#define _APS_NEXT_SYMED_VALUE 104
|
||||
|
Loading…
x
Reference in New Issue
Block a user