From 53b74007317af95402b21a9b26169534ac17c54f Mon Sep 17 00:00:00 2001 From: Danny Mayer Date: Tue, 25 Sep 2001 01:48:49 +0000 Subject: [PATCH] Updated Installer to require named run in a specified account with the minimum privileges necessary to run. The account will also be used laterfor file system security and protections. --- bin/win32/BINDInstall/BINDInstall.dsp | 29 +- bin/win32/BINDInstall/BINDInstall.rc | 84 ++-- bin/win32/BINDInstall/BINDInstallDlg.cpp | 554 +++++++++++++---------- bin/win32/BINDInstall/BINDInstallDlg.h | 11 +- bin/win32/BINDInstall/resource.h | 13 +- 5 files changed, 413 insertions(+), 278 deletions(-) diff --git a/bin/win32/BINDInstall/BINDInstall.dsp b/bin/win32/BINDInstall/BINDInstall.dsp index a9002a4ca3..bd68b3087b 100644 --- a/bin/win32/BINDInstall/BINDInstall.dsp +++ b/bin/win32/BINDInstall/BINDInstall.dsp @@ -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 /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 BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x409 /d "NDEBUG" @@ -53,7 +53,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 /nologo /subsystem:windows /machine:I386 -# ADD LINK32 version.lib /nologo /subsystem:windows /pdb:none /machine:I386 /out:"..\..\..\Build\Release\BINDInstall.exe" +# ADD LINK32 version.lib netapi32.lib /nologo /subsystem:windows /pdb:none /machine:I386 /out:"..\..\..\Build\Release\BINDInstall.exe" !ELSEIF "$(CFG)" == "BINDInstall - Win32 Debug" @@ -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 /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 BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x409 /d "_DEBUG" @@ -79,7 +79,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept -# ADD LINK32 version.lib /nologo /subsystem:windows /pdb:none /debug /machine:I386 /out:"..\..\..\Build\Debug\BINDInstall.exe" +# ADD LINK32 version.lib netapi32.lib /nologo /subsystem:windows /pdb:none /debug /machine:I386 /out:"..\..\..\Build\Debug\BINDInstall.exe" !ENDIF @@ -92,6 +92,10 @@ LINK32=link.exe # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File +SOURCE=.\AccountInfo.cpp +# End Source File +# Begin Source File + SOURCE=.\BINDInstall.cpp # End Source File # Begin Source File @@ -104,6 +108,11 @@ SOURCE=.\DirBrowse.cpp # End Source File # Begin Source File +SOURCE=..\..\..\lib\isc\win32\ntgroups.c +# SUBTRACT CPP /YX /Yc /Yu +# End Source File +# Begin Source File + SOURCE=.\StdAfx.cpp # ADD CPP /Yc"stdafx.h" # End Source File @@ -117,6 +126,10 @@ SOURCE=.\VersionInfo.cpp # PROP Default_Filter "h;hpp;hxx;hm;inl" # Begin Source File +SOURCE=.\Accountinfo.h +# End Source File +# Begin Source File + SOURCE=.\BINDInstall.h # End Source File # Begin Source File @@ -129,6 +142,10 @@ SOURCE=.\DirBrowse.h # End Source File # Begin Source File +SOURCE=..\..\..\lib\isc\win32\include\isc\ntgroups.h +# End Source File +# Begin Source File + SOURCE=.\Resource.h # End Source File # Begin Source File @@ -189,6 +206,10 @@ SOURCE=.\res\clock8.ico # End Source File # Begin Source File +SOURCE=.\res\cursor1.cur +# End Source File +# Begin Source File + SOURCE=.\res\icon1.ico # End Source File # Begin Source File diff --git a/bin/win32/BINDInstall/BINDInstall.rc b/bin/win32/BINDInstall/BINDInstall.rc index fe29c97d64..f2570218e7 100644 --- a/bin/win32/BINDInstall/BINDInstall.rc +++ b/bin/win32/BINDInstall/BINDInstall.rc @@ -73,39 +73,48 @@ IDR_MAINFRAME ICON DISCARDABLE "res\\BINDInstall.ico" // Dialog // -IDD_BINDINSTALL_DIALOG DIALOGEX 0, 0, 210, 234 +IDD_BINDINSTALL_DIALOG DIALOGEX 0, 0, 210, 301 STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_APPWINDOW CAPTION "BIND 9 Installer" FONT 8, "MS Sans Serif" BEGIN - LTEXT "Target Directory:",IDC_STATIC,7,69,54,8 - EDITTEXT IDC_TARGETDIR,7,82,196,14,ES_AUTOHSCROLL - GROUPBOX "Progress",IDC_STATIC,7,157,196,70 - RTEXT "",IDC_COPY_TAG,10,191,84,8 - LTEXT "",IDC_COPY_FILE,100,191,97,8 - RTEXT "",IDC_SERVICE_TAG,10,202,84,8 - LTEXT "",IDC_REG_SERVICE,100,203,97,8 - RTEXT "",IDC_MESSAGE_TAG,10,213,84,8 + EDITTEXT IDC_TARGETDIR,7,62,196,14,ES_AUTOHSCROLL + EDITTEXT IDC_ACCOUNT_NAME,7,94,196,14,ES_AUTOHSCROLL + EDITTEXT IDC_ACCOUNT_PASSWORD,7,122,196,14,ES_PASSWORD | + ES_AUTOHSCROLL + EDITTEXT IDC_ACCOUNT_PASSWORD_CONFIRM,7,151,196,14,ES_PASSWORD | + ES_AUTOHSCROLL DEFPUSHBUTTON "&Install",IDC_INSTALL,153,7,50,14 - LTEXT "",IDC_REG_MESSAGE,100,214,97,8 - RTEXT "",IDC_DIR_TAG,10,180,84,8 PUSHBUTTON "E&xit",IDC_EXIT,153,39,50,14 CONTROL "&Automatic Startup",IDC_AUTO_START,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,14,112,72,10 - GROUPBOX "Options",IDC_STATIC,7,102,196,49 + BS_AUTOCHECKBOX | WS_TABSTOP,14,190,72,10 + CONTROL "&Keep Config Files After Uninstall",IDC_KEEP_FILES, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,200,116,10 + CONTROL "&Start BIND Service After Install",IDC_START,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,14,210,113,10 PUSHBUTTON "&Uninstall",IDC_UNINSTALL,153,23,50,14 + PUSHBUTTON "Browse",IDC_BROWSE,7,22,50,14 + LTEXT "Target Directory:",IDC_STATIC,7,53,54,8 + GROUPBOX "Progress",IDC_STATIC,7,224,196,70 + RTEXT "",IDC_COPY_TAG,14,261,78,8 + LTEXT "",IDC_COPY_FILE,105,261,90,8 + RTEXT "",IDC_SERVICE_TAG,15,271,77,8 + LTEXT "",IDC_REG_SERVICE,105,271,89,8 + RTEXT "",IDC_MESSAGE_TAG,15,281,77,8 + LTEXT "",IDC_REG_MESSAGE,105,281,88,8 + RTEXT "",IDC_DIR_TAG,15,251,77,8 + GROUPBOX "Options",IDC_STATIC,7,172,196,49 CTEXT "Version Unknown",IDC_VERSION,7,7,61,10,SS_CENTERIMAGE | SS_SUNKEN - CONTROL "&Keep Config Files After Uninstall",IDC_KEEP_FILES, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,122,116,10 - PUSHBUTTON "Browse",IDC_BROWSE,7,22,50,14 - RTEXT "Current Operation:",IDC_CURRENT_TAG,36,166,58,8 - LTEXT "",IDC_CURRENT,100,166,97,8 - LTEXT "",IDC_CREATE_DIR,100,180,97,8 - CONTROL "&Start BIND Service After Install",IDC_START,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,14,132,113,10 + RTEXT "Current Operation:",IDC_CURRENT_TAG,34,235,58,8 + LTEXT "",IDC_CURRENT,105,235,90,8 + LTEXT "",IDC_CREATE_DIR,105,251,88,8 + LTEXT "Service Account Name",IDC_STATIC,7,84,74,8 + LTEXT "Service Account Password",IDC_STATIC,7,112,86,8 + LTEXT "Confirm Service Account Password",IDC_STATIC,7,140,112, + 8 END IDD_BROWSE DIALOG DISCARDABLE 0, 0, 227, 117 @@ -130,8 +139,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,5,0,0 - PRODUCTVERSION 1,5,0,0 + FILEVERSION 2,0,0,0 + PRODUCTVERSION 2,0,0,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -149,14 +158,14 @@ BEGIN VALUE "Comments", "\0" VALUE "CompanyName", "Internet Software Consortium\0" VALUE "FileDescription", "ISC BIND Install Utility\0" - VALUE "FileVersion", "1.5.0\0" + VALUE "FileVersion", "2.0.0\0" VALUE "InternalName", "BINDInstall\0" VALUE "LegalCopyright", "Copyright © 2000\0" VALUE "LegalTrademarks", "\0" VALUE "OriginalFilename", "BINDInstall.EXE\0" VALUE "PrivateBuild", "\0" VALUE "ProductName", "ISC BIND\0" - VALUE "ProductVersion", "9.2.0\0" + VALUE "ProductVersion", "9.3.0\0" VALUE "SpecialBuild", "\0" END END @@ -181,8 +190,19 @@ BEGIN BEGIN LEFTMARGIN, 7 RIGHTMARGIN, 203 + VERTGUIDE, 14 + VERTGUIDE, 92 + VERTGUIDE, 105 TOPMARGIN, 7 - BOTTOMMARGIN, 227 + BOTTOMMARGIN, 294 + HORZGUIDE, 195 + HORZGUIDE, 205 + HORZGUIDE, 215 + HORZGUIDE, 239 + HORZGUIDE, 255 + HORZGUIDE, 265 + HORZGUIDE, 275 + HORZGUIDE, 285 END IDD_BROWSE, DIALOG @@ -196,6 +216,13 @@ END #endif // APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Cursor +// + +IDC_CURSOR1 CURSOR DISCARDABLE "res\\cursor1.cur" + ///////////////////////////////////////////////////////////////////////////// // // String Table @@ -262,6 +289,11 @@ BEGIN IDS_NO_VERSION "Version Unknown" IDS_EXISTING_NEWER "%s\nThe existing version of this file is newer than the version being installed.\nDo you wish to overwrite the existing file?" 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_CREATEACCOUNT_FAILED "Unable to Create Account for the Service." + IDS_ERR_PASSWORD "Passwords entered did not match. Please reenter password." END #endif // English (U.S.) resources diff --git a/bin/win32/BINDInstall/BINDInstallDlg.cpp b/bin/win32/BINDInstall/BINDInstallDlg.cpp index adf6100abf..f6e61d12f4 100644 --- a/bin/win32/BINDInstall/BINDInstallDlg.cpp +++ b/bin/win32/BINDInstall/BINDInstallDlg.cpp @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: BINDInstallDlg.cpp,v 1.7 2001/08/30 04:23:43 mayer Exp $ */ +/* $Id: BINDInstallDlg.cpp,v 1.8 2001/09/25 01:48:47 mayer Exp $ */ /* * Copyright (c) 1999-2000 by Nortel Networks Corporation @@ -59,9 +59,14 @@ #include #include #include +#include #include +#include "AccountInfo.h" #include "versioninfo.h" +#define MAX_GROUPS 100 +#define MAX_PRIVS 50 + #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE @@ -87,8 +92,7 @@ _exception::_exception(UINT string, ...) va_end(va); } -typedef struct _filedata -{ +typedef struct _filedata { enum FileDestinations {TargetDir, BinDir, EtcDir, WinSystem}; enum FileImportance {Trivial, Normal, Critical}; @@ -134,12 +138,12 @@ const FileData installFiles[] = {NULL, -1, -1} }; + ///////////////////////////////////////////////////////////////////////////// // CBINDInstallDlg dialog CBINDInstallDlg::CBINDInstallDlg(CWnd* pParent /*=NULL*/) - : CDialog(CBINDInstallDlg::IDD, pParent) -{ + : CDialog(CBINDInstallDlg::IDD, pParent) { char buf[MAX_PATH]; //{{AFX_DATA_INIT(CBINDInstallDlg) @@ -149,23 +153,34 @@ CBINDInstallDlg::CBINDInstallDlg(CWnd* pParent /*=NULL*/) 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); - m_reboot = FALSE; GetSystemDirectory(buf, MAX_PATH); m_winSysDir = buf; m_defaultDir = buf; m_defaultDir += "\\dns"; + m_installed = FALSE; + m_accountExists = FALSE; + m_accountUsed = FALSE; + GetCurrentServiceAccountName(); + if (m_accountName == "") { + m_accountName = "named"; + } } -void CBINDInstallDlg::DoDataExchange(CDataExchange* pDX) -{ +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); @@ -187,8 +202,7 @@ END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CBINDInstallDlg message handlers -BOOL CBINDInstallDlg::OnInitDialog() -{ +BOOL CBINDInstallDlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically @@ -206,7 +220,6 @@ BOOL CBINDInstallDlg::OnInitDialog() dirname[index] = '\0'; CString Dirname(dirname); m_currentDir = Dirname; - CVersionInfo bindInst(filename); if(bindInst.IsValid()) @@ -221,12 +234,14 @@ BOOL CBINDInstallDlg::OnInitDialog() m_startOnInstall = CheckBINDService(); /* See if we are installed already */ - if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, BIND_SUBKEY, 0, KEY_READ, &hKey) == ERROR_SUCCESS) - { + 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, "")) + if (RegQueryValueEx(hKey, "InstallDir", NULL, NULL, (LPBYTE)buf, + &dwBufLen) == ERROR_SUCCESS) + if (strcmp(buf, "")) m_defaultDir = buf; RegCloseKey(hKey); @@ -239,17 +254,17 @@ BOOL CBINDInstallDlg::OnInitDialog() UpdateData(FALSE); - return(TRUE); // return(TRUE unless you set the focus to a control + 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. +/* + * 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()) - { +void CBINDInstallDlg::OnPaint() { + if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); @@ -265,26 +280,22 @@ void CBINDInstallDlg::OnPaint() // Draw the icon dc.DrawIcon(x, y, m_hIcon); } - else - { + else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. -HCURSOR CBINDInstallDlg::OnQueryDragIcon() -{ +HCURSOR CBINDInstallDlg::OnQueryDragIcon() { return((HCURSOR)m_hIcon); } -void CBINDInstallDlg::OnBrowse() -{ +void CBINDInstallDlg::OnBrowse() { CDirBrowse browse; - if(browse.DoModal() == IDOK) - { + if (browse.DoModal() == IDOK) { //m_targetDir = browse.m_selectedDir; UpdateData(FALSE); } @@ -293,44 +304,39 @@ void CBINDInstallDlg::OnBrowse() /* * User pressed the exit button */ -void CBINDInstallDlg::OnExit() -{ +void CBINDInstallDlg::OnExit() { EndDialog(0); } /* * User pressed the uninstall button. Make it go. */ -void CBINDInstallDlg::OnUninstall() -{ +void CBINDInstallDlg::OnUninstall() { UpdateData(); - if(MsgBox(IDS_UNINSTALL, MB_YESNO) == IDYES) - { - if(CheckBINDService()) + if (MsgBox(IDS_UNINSTALL, MB_YESNO) == IDYES) { + if (CheckBINDService()) StopBINDService(); HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); - if(!hSCManager) - { + if (!hSCManager) { MsgBox(IDS_ERR_OPEN_SCM, GetErrMessage()); return; } - HANDLE hService = OpenService(hSCManager, BIND_SERVICE_NAME, SERVICE_ALL_ACCESS); - if(!hService && GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST) - { + 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) - { + 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; } @@ -347,7 +353,7 @@ void CBINDInstallDlg::OnUninstall() UnregisterMessages(TRUE); UnregisterService(TRUE); DeleteFiles(TRUE); - if(m_keepFiles == FALSE) + if (m_keepFiles == FALSE) RemoveDirs(TRUE); else GetDlgItem(IDC_CREATE_DIR)->SetWindowText("Not Removed"); @@ -368,41 +374,59 @@ void CBINDInstallDlg::OnUninstall() /* * User pressed the install button. Make it go. */ -void CBINDInstallDlg::OnInstall() -{ +void CBINDInstallDlg::OnInstall() { BOOL success = FALSE; - if(CheckBINDService()) + 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; + // Directories m_etcDir = m_targetDir + "\\etc"; m_binDir = m_targetDir + "\\bin"; - if(m_defaultDir != m_targetDir) - { - if(GetFileAttributes(m_targetDir) != 0xFFFFFFFF) + if (m_defaultDir != m_targetDir) { + if (GetFileAttributes(m_targetDir) != 0xFFFFFFFF) { - int install = MsgBox(IDS_DIREXIST, MB_YESNO | MB_ICONQUESTION, m_targetDir); - if(install == IDNO) + 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); - if(createDir == IDNO) + else { + int createDir = MsgBox(IDS_CREATEDIR, MB_YESNO | MB_ICONQUESTION, + m_targetDir); + if (createDir == IDNO) return; } } + if (m_accountExists == FALSE) { + success = CreateServiceAccount(m_accountName.GetBuffer(30), + m_accountPassword.GetBuffer(30)); + if (success == FALSE) { + MsgBox(IDS_CREATEACCOUNT_FAILED); + return; + } + m_accountExists; + } + ProgramGroup(); - try - { + try { CreateDirs(); CopyFiles(); RegisterService(); @@ -412,17 +436,19 @@ void CBINDInstallDlg::OnInstall() /* Create a new key for named */ SetCurrent(IDS_CREATE_KEY); - if(RegCreateKey(HKEY_LOCAL_MACHINE, BIND_SUBKEY, &hKey) == ERROR_SUCCESS) - { + if (RegCreateKey(HKEY_LOCAL_MACHINE, BIND_SUBKEY, + &hKey) == ERROR_SUCCESS) { // Get the install directory - RegSetValueEx(hKey, "InstallDir", 0, REG_SZ, (LPBYTE)(LPCTSTR)m_targetDir, m_targetDir.GetLength()); + RegSetValueEx(hKey, "InstallDir", 0, REG_SZ, + (LPBYTE)(LPCTSTR)m_targetDir, + m_targetDir.GetLength()); RegCloseKey(hKey); } SetCurrent(IDS_ADD_REMOVE); - if(RegCreateKey(HKEY_LOCAL_MACHINE, BIND_UNINSTALL_SUBKEY, &hKey) == ERROR_SUCCESS) - { + if (RegCreateKey(HKEY_LOCAL_MACHINE, BIND_UNINSTALL_SUBKEY, + &hKey) == ERROR_SUCCESS) { char winDir[MAX_PATH]; CString buf(BIND_DISPLAY_NAME); GetWindowsDirectory(winDir, MAX_PATH); @@ -436,19 +462,17 @@ void CBINDInstallDlg::OnInstall() ProgramGroup(); - if(m_startOnInstall && !m_reboot) + if (m_startOnInstall) StartBINDService(); } - catch(Exception e) - { + catch(Exception e) { MessageBox(e.resString); SetCurrent(IDS_CLEANUP); FailedInstall(); MsgBox(IDS_FAIL); return; } - catch(DWORD dw) - { + catch(DWORD dw) { CString msg; msg.Format("A fatal error occured\n(%s)", GetErrMessage(dw)); MessageBox(msg); @@ -460,94 +484,88 @@ void CBINDInstallDlg::OnInstall() SetCurrent(IDS_INSTALL_DONE); MsgBox(IDS_SUCCESS); - if(m_reboot) - { - if(MsgBox(IDS_REBOOT, MB_YESNO) == IDYES) - { - InitiateSystemShutdown(NULL, NULL, 0, TRUE, TRUE); - } - } } /* * Methods to do the work */ -void CBINDInstallDlg::CreateDirs() -{ +void CBINDInstallDlg::CreateDirs() { /* s'OK if the directories already exist */ SetCurrent(IDS_CREATE_DIR, m_targetDir); - if(!CreateDirectory(m_targetDir, NULL) && GetLastError() != ERROR_ALREADY_EXISTS) + if (!CreateDirectory(m_targetDir, NULL) && GetLastError() != ERROR_ALREADY_EXISTS) throw(Exception(IDS_ERR_CREATE_DIR, m_targetDir, GetErrMessage())); SetCurrent(IDS_CREATE_DIR, m_etcDir); - if(!CreateDirectory(m_etcDir, NULL) && GetLastError() != ERROR_ALREADY_EXISTS) + if (!CreateDirectory(m_etcDir, NULL) && GetLastError() != ERROR_ALREADY_EXISTS) throw(Exception(IDS_ERR_CREATE_DIR, m_etcDir, GetErrMessage())); SetCurrent(IDS_CREATE_DIR, m_binDir); - if(!CreateDirectory(m_binDir, NULL) && GetLastError() != ERROR_ALREADY_EXISTS) + if (!CreateDirectory(m_binDir, NULL) && GetLastError() != ERROR_ALREADY_EXISTS) throw(Exception(IDS_ERR_CREATE_DIR, m_binDir, GetErrMessage())); SetItemStatus(IDC_CREATE_DIR); } -void CBINDInstallDlg::RemoveDirs(BOOL uninstall) -{ - if(!m_keepFiles) - { +void CBINDInstallDlg::RemoveDirs(BOOL uninstall) { + if (!m_keepFiles) { SetCurrent(IDS_REMOVE_DIR, m_binDir); // Check for existence then remove if present - if(GetFileAttributes(m_binDir) != 0xFFFFFFFF) + if (GetFileAttributes(m_binDir) != 0xFFFFFFFF) RemoveDirectory(m_binDir); SetCurrent(IDS_REMOVE_DIR, m_etcDir); - if(GetFileAttributes(m_etcDir) != 0xFFFFFFFF) + if (GetFileAttributes(m_etcDir) != 0xFFFFFFFF) RemoveDirectory(m_etcDir); SetCurrent(IDS_REMOVE_DIR, m_targetDir); - if(GetFileAttributes(m_targetDir) != 0xFFFFFFFF) + if (GetFileAttributes(m_targetDir) != 0xFFFFFFFF) RemoveDirectory(m_targetDir); } - if(uninstall) + if (uninstall) SetItemStatus(IDC_CREATE_DIR, TRUE); } -void CBINDInstallDlg::CopyFiles() -{ +void CBINDInstallDlg::CopyFiles() { CString destFile; - for(int i = 0; installFiles[i].filename; i++) - { + for (int i = 0; installFiles[i].filename; i++) { SetCurrent(IDS_COPY_FILE, installFiles[i].filename); - destFile = DestDir(installFiles[i].destination) + "\\" + installFiles[i].filename; + destFile = DestDir(installFiles[i].destination) + "\\" + + installFiles[i].filename; CString filespec = m_currentDir + "\\" + installFiles[i].filename; - CVersionInfo bindFile(destFile); /* This file doesn't have to exist */ + CVersionInfo bindFile(destFile); CVersionInfo origFile(filespec); - 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())); + 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())); } - 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. -*/ + 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. + */ bindFile.CopyFileNoVersion(origFile); } - catch(...) - { - if(installFiles[i].importance != FileData::Trivial) - { - if(installFiles[i].importance == FileData::Critical || - MsgBox(IDS_ERR_NONCRIT_FILE, MB_YESNO, installFiles[i].filename, GetErrMessage()) == IDNO) + catch(...) { + if (installFiles[i].importance != FileData::Trivial) { + if (installFiles[i].importance == + FileData::Critical || + MsgBox(IDS_ERR_NONCRIT_FILE, MB_YESNO, + installFiles[i].filename, + GetErrMessage()) == IDNO) { SetItemStatus(IDC_COPY_FILE, FALSE); - throw(Exception(IDS_ERR_COPY_FILE, installFiles[i].filename, GetErrMessage())); + throw(Exception(IDS_ERR_COPY_FILE, + installFiles[i].filename, + GetErrMessage())); } } } @@ -556,25 +574,23 @@ void CBINDInstallDlg::CopyFiles() SetItemStatus(IDC_COPY_FILE); } -void CBINDInstallDlg::DeleteFiles(BOOL uninstall) -{ +void CBINDInstallDlg::DeleteFiles(BOOL uninstall) { CString destFile; - for(int i = 0; installFiles[i].filename; i++) - { - if(installFiles[i].checkVer) + for (int i = 0; installFiles[i].filename; i++) { + if (installFiles[i].checkVer) continue; - destFile = DestDir(installFiles[i].destination) + "\\" + installFiles[i].filename; + destFile = DestDir(installFiles[i].destination) + "\\" + + installFiles[i].filename; - if(uninstall) + if (uninstall) SetCurrent(IDS_DELETE_FILE, installFiles[i].filename); DeleteFile(destFile); } - if(!m_keepFiles) - { + if (!m_keepFiles) { WIN32_FIND_DATA findData; CString file = m_etcDir + "\\*.*"; BOOL rc; @@ -583,10 +599,9 @@ void CBINDInstallDlg::DeleteFiles(BOOL uninstall) hFile = FindFirstFile(file, &findData); rc = hFile != INVALID_HANDLE_VALUE; - while(rc == TRUE) - { - if(strcmp(findData.cFileName, ".") && strcmp(findData.cFileName, "..")) - { + while (rc == TRUE) { + if (strcmp(findData.cFileName, ".") && + strcmp(findData.cFileName, "..")) { file = m_etcDir + "\\" + findData.cFileName; SetCurrent(IDS_DELETE_FILE, file); DeleteFile(file); @@ -596,23 +611,104 @@ void CBINDInstallDlg::DeleteFiles(BOOL uninstall) FindClose(hFile); } - if(uninstall) + if (uninstall) SetItemStatus(IDC_COPY_FILE, TRUE); } +/* + * Get the service account name out of the registry, if any + */ +void +CBINDInstallDlg::GetCurrentServiceAccountName() { + HKEY hKey; + BOOL keyFound = FALSE; + char accountName[50]; + DWORD nameLen = strlen(accountName); + CString Tmp; + m_accountUsed = FALSE; -void CBINDInstallDlg::RegisterService() -{ + memset(accountName, 0, nameLen); + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, BIND_SERVICE_SUBKEY, 0, KEY_READ, + &hKey) == ERROR_SUCCESS) + keyFound = TRUE; + + 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; + } + + RegCloseKey(hKey); + if(keyFound == FALSE) + 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 */ + if (Tmp.Left(2) == ".\\") { + m_accountName = Tmp.Mid(2); + m_accountUsed = TRUE; + } + } +} + +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); + } + /* 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); +} + +void +CBINDInstallDlg::RegisterService() { HANDLE hSCManager; HANDLE hService; SetCurrent(IDS_OPEN_SCM); hSCManager= OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); - if(!hSCManager) + if (!hSCManager) throw(Exception(IDS_ERR_OPEN_SCM, GetErrMessage())); DWORD dwStart = SERVICE_DEMAND_START; - if(m_autoStart) + if (m_autoStart) dwStart = SERVICE_AUTO_START; DWORD dwServiceType = SERVICE_WIN32_OWN_PROCESS; @@ -621,55 +717,51 @@ void CBINDInstallDlg::RegisterService() namedLoc.Format("%s\\bin\\named.exe", m_targetDir); SetCurrent(IDS_CREATE_SERVICE); - hService = CreateService(hSCManager, BIND_SERVICE_NAME, BIND_DISPLAY_NAME, SERVICE_ALL_ACCESS, dwServiceType, dwStart, + hService = CreateService(hSCManager, BIND_SERVICE_NAME, + BIND_DISPLAY_NAME, SERVICE_ALL_ACCESS, dwServiceType, dwStart, SERVICE_ERROR_NORMAL, namedLoc, NULL, NULL, NULL, NULL, NULL); - if(!hService && GetLastError() != ERROR_SERVICE_EXISTS) + if (!hService && GetLastError() != ERROR_SERVICE_EXISTS) throw(Exception(IDS_ERR_CREATE_SERVICE, GetErrMessage())); - if(hSCManager) + if (hSCManager) CloseServiceHandle(hSCManager); - if(hService) + if (hService) CloseServiceHandle(hService); SetItemStatus(IDC_REG_SERVICE); } -void CBINDInstallDlg::UnregisterService(BOOL uninstall) -{ +void CBINDInstallDlg::UnregisterService(BOOL uninstall) { BOOL rc = FALSE; HANDLE hSCManager; HANDLE hService; - while(1) - { + while(1) { SetCurrent(IDS_OPEN_SCM); hSCManager= OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); - if(!hSCManager && uninstall == TRUE) - { + if (!hSCManager && uninstall == TRUE) { MsgBox(IDS_ERR_OPEN_SCM, GetErrMessage()); break; } SetCurrent(IDS_OPEN_SERVICE); - hService = OpenService(hSCManager, BIND_SERVICE_NAME, STANDARD_RIGHTS_REQUIRED); - if(!hService && uninstall == TRUE) + hService = OpenService(hSCManager, BIND_SERVICE_NAME, + STANDARD_RIGHTS_REQUIRED); + if (!hService && uninstall == TRUE) { - if(GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST) - { + if (GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST) { MsgBox(IDS_ERR_OPEN_SERVICE, GetErrMessage()); break; } } - else - { + else { SetCurrent(IDS_REMOVE_SERVICE); - if(!DeleteService(hService) && uninstall == TRUE) - { + if (!DeleteService(hService) && uninstall == TRUE) { DWORD err = GetLastError(); - if(err != ERROR_SERVICE_MARKED_FOR_DELETE && err != ERROR_SERVICE_DOES_NOT_EXIST) - { + if (err != ERROR_SERVICE_MARKED_FOR_DELETE && + err != ERROR_SERVICE_DOES_NOT_EXIST) { MsgBox(IDS_ERR_REMOVE_SERVICE, GetErrMessage()); break; } @@ -680,18 +772,17 @@ void CBINDInstallDlg::UnregisterService(BOOL uninstall) break; } - if(hSCManager) + if (hSCManager) CloseServiceHandle(hSCManager); - if(hService) + if (hService) CloseServiceHandle(hService); - if(uninstall) + if (uninstall) SetItemStatus(IDC_REG_SERVICE, rc); } -void CBINDInstallDlg::RegisterMessages() -{ +void CBINDInstallDlg::RegisterMessages() { HKEY hKey; DWORD dwData; char pszMsgDLL[MAX_PATH], buf[MAX_PATH]; @@ -701,16 +792,19 @@ void CBINDInstallDlg::RegisterMessages() SetCurrent(IDS_REGISTER_MESSAGES); /* Create a new key for named */ - if(RegCreateKey(HKEY_LOCAL_MACHINE, BIND_MESSAGE_SUBKEY, &hKey) != ERROR_SUCCESS) + if (RegCreateKey(HKEY_LOCAL_MACHINE, BIND_MESSAGE_SUBKEY, &hKey) + != ERROR_SUCCESS) throw(Exception(IDS_ERR_CREATE_KEY, GetErrMessage())); /* Add the Event-ID message-file name to the subkey. */ - if(RegSetValueEx(hKey, "EventMessageFile", 0, REG_EXPAND_SZ, (LPBYTE)pszMsgDLL, strlen(pszMsgDLL) + 1) != ERROR_SUCCESS) + if (RegSetValueEx(hKey, "EventMessageFile", 0, REG_EXPAND_SZ, + (LPBYTE)pszMsgDLL, strlen(pszMsgDLL) + 1) != ERROR_SUCCESS) 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; - if(RegSetValueEx(hKey, "TypesSupported", 0, REG_DWORD, (LPBYTE)&dwData, sizeof(DWORD)) != ERROR_SUCCESS) + if (RegSetValueEx(hKey, "TypesSupported", 0, REG_DWORD, + (LPBYTE)&dwData, sizeof(DWORD)) != ERROR_SUCCESS) throw(Exception(IDS_ERR_SET_VALUE, GetErrMessage())); RegCloseKey(hKey); @@ -718,38 +812,36 @@ void CBINDInstallDlg::RegisterMessages() SetItemStatus(IDC_REG_MESSAGE); } -void CBINDInstallDlg::UnregisterMessages(BOOL uninstall) -{ +void CBINDInstallDlg::UnregisterMessages(BOOL uninstall) { BOOL rc = FALSE; HKEY hKey = NULL; - while(1) - { + while(1) { SetCurrent(IDS_UNREGISTER_MESSAGES); /* Open key for Application Event Log */ - if(RegOpenKey(HKEY_LOCAL_MACHINE, EVENTLOG_APP_SUBKEY, &hKey) != ERROR_SUCCESS) + if (RegOpenKey(HKEY_LOCAL_MACHINE, EVENTLOG_APP_SUBKEY, &hKey) + != ERROR_SUCCESS) break; /* Remove named from the list of messages sources */ - if(RegDeleteKey(hKey, BIND_MESSAGE_NAME) != ERROR_SUCCESS) + if (RegDeleteKey(hKey, BIND_MESSAGE_NAME) != ERROR_SUCCESS) break; rc = TRUE; break; } - if(hKey) + if (hKey) RegCloseKey(hKey); - if(uninstall) + if (uninstall) SetItemStatus(IDC_REG_MESSAGE, rc); } /* * Install failed - clean up quietly */ -void CBINDInstallDlg::FailedInstall() -{ +void CBINDInstallDlg::FailedInstall() { UnregisterMessages(FALSE); UnregisterService(FALSE); DeleteFiles(FALSE); @@ -759,8 +851,7 @@ void CBINDInstallDlg::FailedInstall() /* * Set the checklist tags for install */ -void CBINDInstallDlg::InstallTags() -{ +void CBINDInstallDlg::InstallTags() { CString tag; tag.LoadString(IDS_INSTALL_FILE); @@ -783,8 +874,7 @@ void CBINDInstallDlg::InstallTags() /* * Set the checklist tags for uninstall */ -void CBINDInstallDlg::UninstallTags() -{ +void CBINDInstallDlg::UninstallTags() { CString tag; tag.LoadString(IDS_UNINSTALL_FILES); @@ -804,8 +894,7 @@ void CBINDInstallDlg::UninstallTags() GetDlgItem(IDC_REG_MESSAGE)->SetWindowText(""); } -void CBINDInstallDlg::SetItemStatus(UINT nID, BOOL bSuccess) -{ +void CBINDInstallDlg::SetItemStatus(UINT nID, BOOL bSuccess) { GetDlgItem(nID)->SetWindowText(bSuccess == TRUE ? "Done" : "Failed"); } @@ -813,8 +902,7 @@ void CBINDInstallDlg::SetItemStatus(UINT nID, BOOL bSuccess) /* * Set the text in the current operation field - use a string table string */ -void CBINDInstallDlg::SetCurrent(int id, ...) -{ +void CBINDInstallDlg::SetCurrent(int id, ...) { CString format; va_list va; char buf[128]; @@ -833,21 +921,19 @@ void CBINDInstallDlg::SetCurrent(int id, ...) /* * Stop the BIND service */ -void CBINDInstallDlg::StopBINDService() -{ +void CBINDInstallDlg::StopBINDService() { SERVICE_STATUS svcStatus; SetCurrent(IDS_STOP_SERVICE); HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); - if(!hSCManager) - { + if (!hSCManager) { MsgBox(IDS_ERR_OPEN_SCM, GetErrMessage()); } - HANDLE hBINDSvc = OpenService(hSCManager, BIND_SERVICE_NAME, SERVICE_ALL_ACCESS); - if(!hBINDSvc) - { + HANDLE hBINDSvc = OpenService(hSCManager, BIND_SERVICE_NAME, + SERVICE_ALL_ACCESS); + if (!hBINDSvc) { MsgBox(IDS_ERR_OPEN_SERVICE, GetErrMessage()); } @@ -857,19 +943,17 @@ void CBINDInstallDlg::StopBINDService() /* * Start the BIND service */ -void CBINDInstallDlg::StartBINDService() -{ +void CBINDInstallDlg::StartBINDService() { SetCurrent(IDS_START_SERVICE); HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); - if(!hSCManager) - { + if (!hSCManager) { MsgBox(IDS_ERR_OPEN_SCM, GetErrMessage()); } - HANDLE hBINDSvc = OpenService(hSCManager, BIND_SERVICE_NAME, SERVICE_ALL_ACCESS); - if(!hBINDSvc) - { + HANDLE hBINDSvc = OpenService(hSCManager, BIND_SERVICE_NAME, + SERVICE_ALL_ACCESS); + if (!hBINDSvc) { MsgBox(IDS_ERR_OPEN_SERVICE, GetErrMessage()); } BOOL rc = StartService(hBINDSvc, 0, NULL); @@ -878,31 +962,30 @@ void CBINDInstallDlg::StartBINDService() /* * Check to see if the BIND service is running or not */ -BOOL CBINDInstallDlg::CheckBINDService() -{ +BOOL CBINDInstallDlg::CheckBINDService() { SERVICE_STATUS svcStatus; HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); - if(hSCManager) - { - HANDLE hBINDSvc = OpenService(hSCManager, BIND_SERVICE_NAME, SERVICE_ALL_ACCESS); - if(hBINDSvc) - { - BOOL rc = ControlService(hBINDSvc, SERVICE_CONTROL_INTERROGATE, &svcStatus); - if(!rc) + if (hSCManager) { + HANDLE hBINDSvc = OpenService(hSCManager, BIND_SERVICE_NAME, + SERVICE_ALL_ACCESS); + if (hBINDSvc) { + BOOL rc = ControlService(hBINDSvc, + SERVICE_CONTROL_INTERROGATE, &svcStatus); + if (!rc) DWORD err = GetLastError(); - return(svcStatus.dwCurrentState == SERVICE_RUNNING); + return (svcStatus.dwCurrentState == SERVICE_RUNNING); } } - return(FALSE); + return (FALSE); } /* - * Display message boxes with variable args, using string table strings for the format specifiers + * Display message boxes with variable args, using string table strings + * for the format specifiers */ -int CBINDInstallDlg::MsgBox(int id, ...) -{ +int CBINDInstallDlg::MsgBox(int id, ...) { CString format; va_list va; char buf[BUFSIZ]; @@ -914,11 +997,10 @@ int CBINDInstallDlg::MsgBox(int id, ...) vsprintf(buf, format, va); va_end(va); - return(MessageBox(buf)); + return (MessageBox(buf)); } -int CBINDInstallDlg::MsgBox(int id, UINT type, ...) -{ +int CBINDInstallDlg::MsgBox(int id, UINT type, ...) { CString format; va_list va; char buf[BUFSIZ]; @@ -936,8 +1018,7 @@ int CBINDInstallDlg::MsgBox(int id, UINT type, ...) /* * Call GetLastError(), retrieve the message associated with the error */ -CString CBINDInstallDlg::GetErrMessage(DWORD err) -{ +CString CBINDInstallDlg::GetErrMessage(DWORD err) { LPVOID msgBuf; static char buf[BUFSIZ]; @@ -952,8 +1033,7 @@ CString CBINDInstallDlg::GetErrMessage(DWORD err) return(buf); } -void CBINDInstallDlg::ProgramGroup(BOOL create) -{ +void CBINDInstallDlg::ProgramGroup(BOOL create) { TCHAR path[MAX_PATH], commonPath[MAX_PATH], fileloc[MAX_PATH], linkpath[MAX_PATH]; HRESULT hres; IShellLink *psl = NULL; @@ -961,18 +1041,15 @@ void CBINDInstallDlg::ProgramGroup(BOOL create) ITEMIDLIST *itemList = NULL; HRESULT hr = SHGetMalloc(&pMalloc); - if(hr != NOERROR) - { + if (hr != NOERROR) { MessageBox("Could not get a handle to Shell memory object"); return; } hr = SHGetSpecialFolderLocation(m_hWnd, CSIDL_COMMON_PROGRAMS, &itemList); - if(hr != NOERROR) - { + if (hr != NOERROR) { MessageBox("Could not get a handle to the Common Programs folder"); - if(itemList) - { + if (itemList) { pMalloc->Free(itemList); } return; @@ -981,8 +1058,7 @@ void CBINDInstallDlg::ProgramGroup(BOOL create) hr = SHGetPathFromIDList(itemList, commonPath); pMalloc->Free(itemList); - if(create) - { + if (create) { sprintf(path, "%s\\ISC", commonPath); CreateDirectory(path, NULL); @@ -991,8 +1067,7 @@ void CBINDInstallDlg::ProgramGroup(BOOL create) hres = CoInitialize(NULL); - if (SUCCEEDED(hres)) - { + if (SUCCEEDED(hres)) { // Get a pointer to the IShellLink interface. hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *)&psl); if (SUCCEEDED(hres)) @@ -1005,8 +1080,7 @@ void CBINDInstallDlg::ProgramGroup(BOOL create) psl->SetDescription("BIND Control Panel"); hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf); - if (SUCCEEDED(hres)) - { + if (SUCCEEDED(hres)) { WCHAR wsz[MAX_PATH]; MultiByteToWideChar(CP_ACP, 0, linkpath, -1, wsz, MAX_PATH); @@ -1014,8 +1088,7 @@ void CBINDInstallDlg::ProgramGroup(BOOL create) ppf->Release(); } - if(GetFileAttributes("readme.txt") != -1) - { + if (GetFileAttributes("readme.txt") != -1) { sprintf(fileloc, "%s\\Readme.txt", m_targetDir); sprintf(linkpath, "%s\\Readme.lnk", path); @@ -1023,8 +1096,7 @@ void CBINDInstallDlg::ProgramGroup(BOOL create) psl->SetDescription("BIND Readme"); hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf); - if (SUCCEEDED(hres)) - { + if (SUCCEEDED(hres)) { WCHAR wsz[MAX_PATH]; MultiByteToWideChar(CP_ACP, 0, linkpath, -1, wsz, MAX_PATH); @@ -1037,8 +1109,7 @@ void CBINDInstallDlg::ProgramGroup(BOOL create) CoUninitialize(); } } - else - { + else { TCHAR filename[MAX_PATH]; WIN32_FIND_DATA fd; @@ -1046,16 +1117,13 @@ void CBINDInstallDlg::ProgramGroup(BOOL create) sprintf(filename, "%s\\*.*", path); HANDLE hFind = FindFirstFile(filename, &fd); - if(hFind != INVALID_HANDLE_VALUE) - { - do - { - if(strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..")) - { + if (hFind != INVALID_HANDLE_VALUE) { + do { + if (strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..")) { sprintf(filename, "%s\\%s", path, fd.cFileName); DeleteFile(filename); } - } while(FindNextFile(hFind, &fd)); + } while (FindNextFile(hFind, &fd)); FindClose(hFind); } RemoveDirectory(path); @@ -1064,10 +1132,8 @@ void CBINDInstallDlg::ProgramGroup(BOOL create) } } -CString CBINDInstallDlg::DestDir(int destination) -{ - switch(destination) - { +CString CBINDInstallDlg::DestDir(int destination) { + switch(destination) { case FileData::TargetDir: return m_targetDir; case FileData::BinDir: diff --git a/bin/win32/BINDInstall/BINDInstallDlg.h b/bin/win32/BINDInstall/BINDInstallDlg.h index d75de61786..0a641126e3 100644 --- a/bin/win32/BINDInstall/BINDInstallDlg.h +++ b/bin/win32/BINDInstall/BINDInstallDlg.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: BINDInstallDlg.h,v 1.3 2001/07/31 00:03:14 gson Exp $ */ +/* $Id: BINDInstallDlg.h,v 1.4 2001/09/25 01:48:48 mayer Exp $ */ /* * Copyright (c) 1999-2000 by Nortel Networks Corporation @@ -80,6 +80,8 @@ protected: void FailedInstall(); void SetItemStatus(UINT nID, BOOL bSuccess = TRUE); + void GetCurrentServiceAccountName(); + BOOL ValidateServiceAccount(); protected: CString DestDir(int destination); int MsgBox(int id, ...); @@ -94,8 +96,13 @@ protected: CString m_etcDir; CString m_binDir; CString m_winSysDir; - BOOL m_reboot; + BOOL m_installed; CString m_currentDir; + BOOL m_accountExists; + BOOL m_accountUsed; + CString m_accountName; + CString m_accountPasswordConfirm; + CString m_accountPassword; // Generated message map functions //{{AFX_MSG(CBINDInstallDlg) diff --git a/bin/win32/BINDInstall/resource.h b/bin/win32/BINDInstall/resource.h index 02f6802d7a..0a2ffec8e9 100644 --- a/bin/win32/BINDInstall/resource.h +++ b/bin/win32/BINDInstall/resource.h @@ -50,11 +50,17 @@ #define IDS_NO_VERSION 49 #define IDS_EXISTING_NEWER 50 #define IDS_FILE_BAD 51 +#define IDS_ERR_TOOPRIVED 52 +#define IDS_ERR_BADACCOUNT 53 +#define IDS_ERR_WRONGPRIV 54 +#define IDS_CREATEACCOUNT_FAILED 55 +#define IDS_ERR_PASSWORD 56 #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 IDC_TARGETDIR 1001 #define IDC_BROWSE 1002 #define IDC_DIRLIST 1004 @@ -77,14 +83,17 @@ #define IDC_DRIVES 1021 #define IDC_CURRENT 1021 #define IDC_START 1022 +#define IDC_ACCOUNT_NAME 1030 +#define IDC_ACCOUNT_PASSWORD 1031 +#define IDC_ACCOUNT_PASSWORD_CONFIRM 1032 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 142 +#define _APS_NEXT_RESOURCE_VALUE 143 #define _APS_NEXT_COMMAND_VALUE 32771 #define _APS_NEXT_CONTROL_VALUE 1027 -#define _APS_NEXT_SYMED_VALUE 101 +#define _APS_NEXT_SYMED_VALUE 104 #endif #endif