- Added support for MS SQL Windows authentication in configuration wizard
authorVictor Kirhenshtein <victor@netxms.org>
Thu, 24 Nov 2005 23:10:17 +0000 (23:10 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Thu, 24 Nov 2005 23:10:17 +0000 (23:10 +0000)
- Added possibility to set service account in configuration wizard
- Other minor changes

16 files changed:
.gitattributes
ChangeLog
src/install/windows/netxms.iss
src/server/netxmsd/netxmsd.cpp
src/server/netxmsd/netxmsd.h
src/server/netxmsd/winsrv.cpp
src/server/tools/nxconfig/StdAfx.h
src/server/tools/nxconfig/WinSrvPage.cpp [new file with mode: 0644]
src/server/tools/nxconfig/WinSrvPage.h [new file with mode: 0644]
src/server/tools/nxconfig/WizardWorker.cpp
src/server/tools/nxconfig/nxconfig.clw
src/server/tools/nxconfig/nxconfig.cpp
src/server/tools/nxconfig/nxconfig.dsp
src/server/tools/nxconfig/nxconfig.h
src/server/tools/nxconfig/nxconfig.rc
src/server/tools/nxconfig/resource.h

index aa82f55..54500de 100644 (file)
@@ -966,6 +966,8 @@ src/server/tools/nxconfig/StdAfx.cpp -text
 src/server/tools/nxconfig/StdAfx.h -text
 src/server/tools/nxconfig/SummaryPage.cpp -text
 src/server/tools/nxconfig/SummaryPage.h -text
+src/server/tools/nxconfig/WinSrvPage.cpp -text
+src/server/tools/nxconfig/WinSrvPage.h -text
 src/server/tools/nxconfig/WizardWorker.cpp -text
 src/server/tools/nxconfig/nxconfig.clw -text
 src/server/tools/nxconfig/nxconfig.cpp -text
index 36d3e3b..b0de948 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,8 @@
 - Implemented agent proxy
 - Windows console:
        - Fixed inconsistencies in object access control configuration
+- Added support for Windows authentication in Microsoft SQL driver
+- Server configuration wizard: added possibility to configure service account
 - Fixed issues: #61
 
 
index 3eecb9b..eb2390d 100644 (file)
@@ -3,8 +3,8 @@
 
 [Setup]
 AppName=NetXMS
-AppVerName=NetXMS 0.2.7
-AppVersion=0.2.7
+AppVerName=NetXMS 0.2.8
+AppVersion=0.2.8
 AppPublisher=NetXMS Team
 AppPublisherURL=http://www.netxms.org
 AppSupportURL=http://www.netxms.org
@@ -13,7 +13,7 @@ DefaultDirName=C:\NetXMS
 DefaultGroupName=NetXMS
 AllowNoIcons=yes
 LicenseFile=..\..\..\copying
-OutputBaseFilename=netxms-0.2.7
+OutputBaseFilename=netxms-0.2.8
 Compression=lzma
 SolidCompression=yes
 LanguageDetectionMethod=none
@@ -107,7 +107,7 @@ Filename: "{app}\bin\nxconfig.exe"; Parameters: "--create-agent-config"; Working
 Filename: "{app}\bin\nxagentd.exe"; Parameters: "-c ""{app}\etc\nxagentd.conf"" -I"; WorkingDir: "{app}\bin"; StatusMsg: "Installing agent service..."; Flags: runhidden; Components: server
 Filename: "{app}\bin\nxagentd.exe"; Parameters: "-s"; WorkingDir: "{app}\bin"; StatusMsg: "Starting agent service..."; Flags: runhidden; Components: server
 Filename: "{app}\bin\nxconfig.exe"; WorkingDir: "{app}\bin"; StatusMsg: "Running server configuration wizard..."; Components: server
-Filename: "{app}\bin\netxmsd.exe"; Parameters: "--config ""{app}\etc\netxmsd.conf"" install"; WorkingDir: "{app}\bin"; StatusMsg: "Installing core service..."; Flags: runhidden; Components: server
+;Filename: "{app}\bin\netxmsd.exe"; Parameters: "--config ""{app}\etc\netxmsd.conf"" install"; WorkingDir: "{app}\bin"; StatusMsg: "Installing core service..."; Flags: runhidden; Components: server
 Filename: "{app}\bin\netxmsd.exe"; Parameters: "start"; WorkingDir: "{app}\bin"; StatusMsg: "Starting core service..."; Flags: runhidden; Components: server
 
 [UninstallRun]
index ee58095..df386f7 100644 (file)
@@ -50,7 +50,10 @@ static char help_text[]="NetXMS Server Version " NETXMS_VERSION_STRING "\n"
                         "   --debug-objects     : Print object manager debug information.\n"
                         "   --debug-snmp        : Print SNMP debug information.\n"
                         "   --dump-sql          : Dump all SQL queries to log.\n"
-#ifndef _WIN32
+#ifdef _WIN32
+                        "   --login <user>      : Login name for service account.\n"
+                        "   --password <passwd> : Password for service account.\n"
+#else
                         "   --pid-file <file>   : Specify pid file.\n"
 #endif
                         "\n"
@@ -83,6 +86,7 @@ static char help_text[]="NetXMS Server Version " NETXMS_VERSION_STRING "\n"
 static BOOL ParseCommandLine(int argc, char *argv[])
 {
    int i;
+   TCHAR *pszLogin = NULL, *pszPassword = NULL;
 
    for(i = 1; i < argc; i++)
    {
@@ -101,11 +105,22 @@ static BOOL ParseCommandLine(int argc, char *argv[])
          i++;
          nx_strncpy(g_szConfigFile, argv[i], MAX_PATH);     // Next word should contain name of the config file
       }
-#ifndef _WIN32
+#ifdef _WIN32
+      else if (!strcmp(argv[i], "--login"))
+      {
+         i++;
+         pszLogin = argv[i];
+      }
+      else if (!strcmp(argv[i], "--password"))
+      {
+         i++;
+         pszPassword = argv[i];
+      }
+#else
       else if (!strcmp(argv[i], "--pid-file"))  // PID file
       {
          i++;
-         strcpy(g_szPIDFile, argv[i]);     // Next word should contain name of the PID file
+         nx_strncpy(g_szPIDFile, argv[i], MAX_PATH);     // Next word should contain name of the PID file
       }
 #endif
       else if (!strcmp(argv[i], "--debug-all"))
@@ -189,9 +204,17 @@ static BOOL ParseCommandLine(int argc, char *argv[])
          }
 
          if (!strcmp(argv[i], "install"))
-            InstallService(exePath, dllPath);
+         {
+            if ((pszLogin != NULL) && (pszPassword == NULL))
+               pszPassword = _T("");
+            if ((pszLogin == NULL) && (pszPassword != NULL))
+               pszPassword = NULL;
+            InstallService(exePath, dllPath, pszLogin, pszPassword);
+         }
          else
+         {
             InstallEventSource(dllPath);
+         }
          return FALSE;
       }
       else if (!strcmp(argv[i], "remove"))
index 3590716..19e2fb4 100644 (file)
 #ifdef _WIN32
 
 void InitService(void);
-void InstallService(char *execName, char *dllName);
+void InstallService(TCHAR *pszExecName, TCHAR *pszDllName,
+                    TCHAR *pszLogin, TCHAR *pszPassword);
 void RemoveService(void);
 void StartCoreService(void);
 void StopCoreService(void);
-void InstallEventSource(char *path);
+void InstallEventSource(TCHAR *pszPath);
 void RemoveEventSource(void);
 
 #endif   /* _WIN32 */
index 103cb3c..f51723e 100644 (file)
@@ -131,22 +131,26 @@ void InitService(void)
 // Create service
 //
 
-void InstallService(char *execName, char *dllName)
+void InstallService(TCHAR *pszExecName, TCHAR *pszDllName,
+                    TCHAR *pszLogin, TCHAR *pszPassword)
 {
-   SC_HANDLE mgr,service;
-   char cmdLine[MAX_PATH*2];
+   SC_HANDLE hMgr, hService;
+   TCHAR szCmdLine[MAX_PATH * 2];
 
-   mgr=OpenSCManager(NULL,NULL,GENERIC_WRITE);
-   if (mgr==NULL)
+   hMgr = OpenSCManager(NULL, NULL, GENERIC_WRITE);
+   if (hMgr == NULL)
    {
-      printf("ERROR: Cannot connect to Service Manager (%s)\n",GetSystemErrorText(GetLastError()));
+      printf("ERROR: Cannot connect to Service Manager (%s)\n",
+             GetSystemErrorText(GetLastError()));
       return;
    }
 
-   sprintf(cmdLine, "\"%s\" --config \"%s\"", execName, g_szConfigFile);
-   service = CreateService(mgr, CORE_SERVICE_NAME, "NetXMS Core", GENERIC_READ, SERVICE_WIN32_OWN_PROCESS,
-                           SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, cmdLine, NULL, NULL, NULL, NULL, NULL);
-   if (service == NULL)
+   sprintf(szCmdLine, "\"%s\" --config \"%s\"", pszExecName, g_szConfigFile);
+   hService = CreateService(hMgr, CORE_SERVICE_NAME, "NetXMS Core",
+                            GENERIC_READ, SERVICE_WIN32_OWN_PROCESS,
+                            SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
+                            szCmdLine, NULL, NULL, NULL, pszLogin, pszPassword);
+   if (hService == NULL)
    {
       DWORD code = GetLastError();
 
@@ -158,12 +162,12 @@ void InstallService(char *execName, char *dllName)
    else
    {
       printf("NetXMS Core service created successfully\n");
-      CloseServiceHandle(service);
+      CloseServiceHandle(hService);
    }
 
-   CloseServiceHandle(mgr);
+   CloseServiceHandle(hMgr);
 
-   InstallEventSource(dllName);
+   InstallEventSource(pszDllName);
 }
 
 
index bd35b9c..3047f17 100644 (file)
@@ -23,6 +23,8 @@
 #include <winsock2.h>
 #include <afxsock.h>           // MFC socket extensions
 
+#include <winsvc.h>
+
 //{{AFX_INSERT_LOCATION}}
 // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
 
diff --git a/src/server/tools/nxconfig/WinSrvPage.cpp b/src/server/tools/nxconfig/WinSrvPage.cpp
new file mode 100644 (file)
index 0000000..7d71726
--- /dev/null
@@ -0,0 +1,157 @@
+// WinSrvPage.cpp : implementation file
+//
+
+#include "stdafx.h"
+#include "nxconfig.h"
+#include "WinSrvPage.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#undef THIS_FILE
+static char THIS_FILE[] = __FILE__;
+#endif
+
+/////////////////////////////////////////////////////////////////////////////
+// CWinSrvPage property page
+
+IMPLEMENT_DYNCREATE(CWinSrvPage, CPropertyPage)
+
+CWinSrvPage::CWinSrvPage() : CPropertyPage(CWinSrvPage::IDD)
+{
+       //{{AFX_DATA_INIT(CWinSrvPage)
+               // NOTE: the ClassWizard will add member initialization here
+       //}}AFX_DATA_INIT
+}
+
+CWinSrvPage::~CWinSrvPage()
+{
+}
+
+void CWinSrvPage::DoDataExchange(CDataExchange* pDX)
+{
+       CPropertyPage::DoDataExchange(pDX);
+       //{{AFX_DATA_MAP(CWinSrvPage)
+               // NOTE: the ClassWizard will add DDX and DDV calls here
+       //}}AFX_DATA_MAP
+}
+
+
+BEGIN_MESSAGE_MAP(CWinSrvPage, CPropertyPage)
+       //{{AFX_MSG_MAP(CWinSrvPage)
+       ON_BN_CLICKED(IDC_RADIO_SYSTEM, OnRadioSystem)
+       ON_BN_CLICKED(IDC_RADIO_USER, OnRadioUser)
+       //}}AFX_MSG_MAP
+END_MESSAGE_MAP()
+
+/////////////////////////////////////////////////////////////////////////////
+// CWinSrvPage message handlers
+
+
+//
+// WM_INITDIALOG message handler
+//
+
+BOOL CWinSrvPage::OnInitDialog() 
+{
+   WIZARD_CFG_INFO *pc = &((CConfigWizard *)GetParent())->m_cfg;
+
+       CPropertyPage::OnInitDialog();
+       
+   SendDlgItemMessage(IDC_RADIO_SYSTEM, BM_SETCHECK, BST_CHECKED);
+   EnableDlgItem(this, IDC_EDIT_LOGIN, FALSE);
+   EnableDlgItem(this, IDC_EDIT_PASSWD1, FALSE);
+   EnableDlgItem(this, IDC_EDIT_PASSWD2, FALSE);
+       
+   if (strcmp(pc->m_szDBLogin, _T("*")) ||
+       (pc->m_iDBEngine != DB_ENGINE_MSSQL))
+   {
+      ::ShowWindow(::GetDlgItem(m_hWnd, IDC_ICON_WARNING), SW_HIDE);
+      ::ShowWindow(::GetDlgItem(m_hWnd, IDC_STATIC_WARNING), SW_HIDE);
+   }
+
+       return TRUE;
+}
+
+
+//
+// Handler for "Next" button
+//
+
+LRESULT CWinSrvPage::OnWizardNext() 
+{
+   WIZARD_CFG_INFO *pc = &((CConfigWizard *)GetParent())->m_cfg;
+
+   if (SendDlgItemMessage(IDC_RADIO_SYSTEM, BM_GETCHECK) == BST_CHECKED)
+   {
+      pc->m_szServiceLogin[0] = 0;
+      pc->m_szServicePassword[0] = 0;
+   }
+   else
+   {
+      TCHAR szPasswd1[MAX_DB_STRING], szPasswd2[MAX_DB_STRING];
+
+      GetDlgItemText(IDC_EDIT_LOGIN, pc->m_szServiceLogin, MAX_DB_STRING);
+      GetDlgItemText(IDC_EDIT_PASSWD1, szPasswd1, MAX_DB_STRING);
+      GetDlgItemText(IDC_EDIT_PASSWD2, szPasswd2, MAX_DB_STRING);
+      if (!strcmp(szPasswd1, szPasswd2))
+      {
+         _tcscpy(pc->m_szServicePassword, szPasswd1);
+      }
+      else
+      {
+         MessageBox(_T("Entered passwords does not match"), _T("Warning"),
+                    MB_OK | MB_ICONEXCLAMATION);
+         return -1;
+      }
+   }
+       
+       return CPropertyPage::OnWizardNext();
+}
+
+
+//
+// Handlers for radio buttons
+//
+
+void CWinSrvPage::OnRadioSystem() 
+{
+   WIZARD_CFG_INFO *pc = &((CConfigWizard *)GetParent())->m_cfg;
+
+   EnableDlgItem(this, IDC_EDIT_LOGIN, FALSE);
+   EnableDlgItem(this, IDC_EDIT_PASSWD1, FALSE);
+   EnableDlgItem(this, IDC_EDIT_PASSWD2, FALSE);
+
+   if ((!strcmp(pc->m_szDBLogin, _T("*"))) &&
+       (pc->m_iDBEngine == DB_ENGINE_MSSQL))
+   {
+      ::ShowWindow(::GetDlgItem(m_hWnd, IDC_ICON_WARNING), SW_SHOW);
+      ::ShowWindow(::GetDlgItem(m_hWnd, IDC_STATIC_WARNING), SW_SHOW);
+   }
+}
+
+void CWinSrvPage::OnRadioUser() 
+{
+   EnableDlgItem(this, IDC_EDIT_LOGIN, TRUE);
+   EnableDlgItem(this, IDC_EDIT_PASSWD1, TRUE);
+   EnableDlgItem(this, IDC_EDIT_PASSWD2, TRUE);
+
+   ::ShowWindow(::GetDlgItem(m_hWnd, IDC_ICON_WARNING), SW_HIDE);
+   ::ShowWindow(::GetDlgItem(m_hWnd, IDC_STATIC_WARNING), SW_HIDE);
+}
+
+
+//
+// Page activation handler
+//
+
+BOOL CWinSrvPage::OnSetActive() 
+{
+   WIZARD_CFG_INFO *pc = &((CConfigWizard *)GetParent())->m_cfg;
+   BOOL bShow;
+
+   bShow = ((!strcmp(pc->m_szDBLogin, _T("*"))) && (pc->m_iDBEngine == DB_ENGINE_MSSQL));
+   ::ShowWindow(::GetDlgItem(m_hWnd, IDC_ICON_WARNING), bShow ? SW_SHOW : SW_HIDE);
+   ::ShowWindow(::GetDlgItem(m_hWnd, IDC_STATIC_WARNING), bShow ? SW_SHOW : SW_HIDE);
+       
+       return CPropertyPage::OnSetActive();
+}
diff --git a/src/server/tools/nxconfig/WinSrvPage.h b/src/server/tools/nxconfig/WinSrvPage.h
new file mode 100644 (file)
index 0000000..36a3fda
--- /dev/null
@@ -0,0 +1,55 @@
+#if !defined(AFX_WINSRVPAGE_H__67137572_8E6F_4933_BBEC_645B62288FDF__INCLUDED_)
+#define AFX_WINSRVPAGE_H__67137572_8E6F_4933_BBEC_645B62288FDF__INCLUDED_
+
+#if _MSC_VER > 1000
+#pragma once
+#endif // _MSC_VER > 1000
+// WinSrvPage.h : header file
+//
+
+/////////////////////////////////////////////////////////////////////////////
+// CWinSrvPage dialog
+
+class CWinSrvPage : public CPropertyPage
+{
+       DECLARE_DYNCREATE(CWinSrvPage)
+
+// Construction
+public:
+       CWinSrvPage();
+       ~CWinSrvPage();
+
+// Dialog Data
+       //{{AFX_DATA(CWinSrvPage)
+       enum { IDD = IDD_SERVICE };
+               // NOTE - ClassWizard will add data members here.
+               //    DO NOT EDIT what you see in these blocks of generated code !
+       //}}AFX_DATA
+
+
+// Overrides
+       // ClassWizard generate virtual function overrides
+       //{{AFX_VIRTUAL(CWinSrvPage)
+       public:
+       virtual LRESULT OnWizardNext();
+       virtual BOOL OnSetActive();
+       protected:
+       virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
+       //}}AFX_VIRTUAL
+
+// Implementation
+protected:
+       // Generated message map functions
+       //{{AFX_MSG(CWinSrvPage)
+       virtual BOOL OnInitDialog();
+       afx_msg void OnRadioSystem();
+       afx_msg void OnRadioUser();
+       //}}AFX_MSG
+       DECLARE_MESSAGE_MAP()
+
+};
+
+//{{AFX_INSERT_LOCATION}}
+// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
+
+#endif // !defined(AFX_WINSRVPAGE_H__67137572_8E6F_4933_BBEC_645B62288FDF__INCLUDED_)
index f59768f..2461fdf 100644 (file)
@@ -40,6 +40,99 @@ TCHAR g_szWizardErrorText[MAX_ERROR_TEXT] = _T("Completed successfully");
 static HWND m_hStatusWnd = NULL;
 
 
+//
+// Install event source
+//
+
+static BOOL InstallEventSource(TCHAR *pszPath)
+{
+   HKEY hKey;
+   TCHAR szBuffer[256];
+   DWORD dwTypes = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
+
+   if (ERROR_SUCCESS != RegCreateKeyEx(HKEY_LOCAL_MACHINE,
+         "System\\CurrentControlSet\\Services\\EventLog\\System\\" CORE_EVENT_SOURCE,
+         0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hKey, NULL))
+   {
+      _sntprintf(g_szWizardErrorText, MAX_ERROR_TEXT, 
+                 _T("Unable to create registry key: %s"),
+                 GetSystemErrorText(GetLastError(), szBuffer, 256));
+      return FALSE;
+   }
+
+   RegSetValueEx(hKey, _T("TypesSupported"), 0, REG_DWORD,(BYTE *)&dwTypes, sizeof(DWORD));
+   RegSetValueEx(hKey, _T("EventMessageFile"), 0, REG_EXPAND_SZ,
+                 (BYTE *)pszPath, (_tcslen(pszPath) + 1) * sizeof(TCHAR));
+
+   RegCloseKey(hKey);
+   return TRUE;
+}
+
+
+//
+// Install Windows service
+//
+
+static BOOL InstallService(WIZARD_CFG_INFO *pc)
+{
+   SC_HANDLE hMgr, hService;
+   TCHAR szCmdLine[MAX_PATH * 2], *pszLogin, *pszPassword, szBuffer[256];
+   BOOL bResult = FALSE;
+
+   hMgr = OpenSCManager(NULL, NULL, GENERIC_WRITE);
+   if (hMgr == NULL)
+   {
+      _sntprintf(g_szWizardErrorText, MAX_ERROR_TEXT, 
+                 _T("Cannot connect to Service Manager: %s"),
+                 GetSystemErrorText(GetLastError(), szBuffer, 256));
+      return FALSE;
+   }
+
+   if (pc->m_szServiceLogin[0] == 0)
+   {
+      pszLogin = NULL;
+      pszPassword = NULL;
+   }
+   else
+   {
+      pszLogin = pc->m_szServiceLogin;
+      pszPassword = pc->m_szServicePassword;
+   }
+   _sntprintf(szCmdLine, MAX_PATH * 2, _T("\"%s\\bin\\netxmsd.exe\" --config \"%s\""), 
+              pc->m_szInstallDir, pc->m_szConfigFile);
+   hService = CreateService(hMgr, CORE_SERVICE_NAME, _T("NetXMS Core"),
+                            GENERIC_READ, SERVICE_WIN32_OWN_PROCESS,
+                            SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
+                            szCmdLine, NULL, NULL, NULL, pszLogin, pszPassword);
+   if (hService == NULL)
+   {
+      DWORD dwCode = GetLastError();
+
+      if (dwCode == ERROR_SERVICE_EXISTS)
+      {
+         _sntprintf(g_szWizardErrorText, MAX_ERROR_TEXT,
+                    _T("Service named '") CORE_SERVICE_NAME _T("' already exist"));
+      }
+      else
+      {
+         _sntprintf(g_szWizardErrorText, MAX_ERROR_TEXT,
+                    _T("Cannot create service: %s"),
+                    GetSystemErrorText(dwCode, szBuffer, 256));
+      }
+   }
+   else
+   {
+      CloseServiceHandle(hService);
+      bResult = TRUE;
+      _sntprintf(szCmdLine, MAX_PATH, _T("%s\\bin\\nxcore.dll"), pc->m_szInstallDir);
+   }
+
+   CloseServiceHandle(hMgr);
+
+   return bResult ? InstallEventSource(szCmdLine) : FALSE;
+}
+
+
 //
 // Execute query and set error text
 //
@@ -240,7 +333,7 @@ static BOOL CreateDBPostgreSQL(WIZARD_CFG_INFO *pc, DB_HANDLE hConn)
 
 static BOOL CreateDBMSSQL(WIZARD_CFG_INFO *pc, DB_HANDLE hConn)
 {
-   TCHAR szQuery[256];
+   TCHAR szQuery[512], *pszLogin;
    BOOL bResult;
 
    bResult = DBQueryEx(hConn, _T("USE master"));
@@ -258,20 +351,29 @@ static BOOL CreateDBMSSQL(WIZARD_CFG_INFO *pc, DB_HANDLE hConn)
 
    if (bResult)
    {
-      _stprintf(szQuery, _T("sp_addlogin @loginame = '%s', @passwd = '%s', @defdb = '%s'"),
-                pc->m_szDBLogin, pc->m_szDBPassword, pc->m_szDBName);
-      bResult = DBQueryEx(hConn, szQuery);
+      if (!strcmp(pc->m_szDBLogin, _T("*")))
+      {
+         // Use Windows authentication
+         pszLogin = pc->m_szServiceLogin;
+      }
+      else
+      {
+         _sntprintf(szQuery, 512, _T("sp_addlogin @loginame = '%s', @passwd = '%s', @defdb = '%s'"),
+                    pc->m_szDBLogin, pc->m_szDBPassword, pc->m_szDBName);
+         bResult = DBQueryEx(hConn, szQuery);
+         pszLogin = pc->m_szDBLogin;
+      }
    }
 
    if (bResult)
    {
-      _stprintf(szQuery, _T("sp_grantdbaccess @loginame = '%s'"), pc->m_szDBLogin);
+      _sntprintf(szQuery, 512, _T("sp_grantdbaccess @loginame = '%s'"), pszLogin);
       bResult = DBQueryEx(hConn, szQuery);
    }
 
    if (bResult)
    {
-      _stprintf(szQuery, _T("GRANT ALL TO %s"), pc->m_szDBLogin);
+      _stprintf(szQuery, _T("GRANT ALL TO %s"), pszLogin);
       bResult = DBQueryEx(hConn, szQuery);
    }
 
@@ -447,6 +549,14 @@ static DWORD __stdcall WorkerThread(void *pArg)
    if (hConn != NULL)
       DBDisconnect(hConn);
 
+   // Install service
+   if (bResult)
+   {
+      PostMessage(m_hStatusWnd, WM_START_STAGE, 0, (LPARAM)_T("Installing service"));
+      bResult = InstallService(pc);
+      PostMessage(m_hStatusWnd, WM_STAGE_COMPLETED, bResult, 0);
+   }
+
    // Notify UI that job is finished
    PostMessage(m_hStatusWnd, WM_JOB_FINISHED, bResult, 0);
    return 0;
index 838c272..8c937b6 100644 (file)
@@ -2,42 +2,44 @@
 
 [General Info]
 Version=1
-LastClass=CSMTPPage
+LastClass=CWinSrvPage
 LastTemplate=CPropertyPage
 NewFileInclude1=#include "stdafx.h"
 NewFileInclude2=#include "nxconfig.h"
 LastPage=0
 
-ClassCount=15
+ClassCount=16
 Class1=CNxconfigApp
 Class3=CMainFrame
 Class4=CAboutDlg
 
-ResourceCount=12
-Resource1=IDD_ODBC (English (U.S.))
-Resource2=IDR_MAINFRAME (English (U.S.))
+ResourceCount=13
+Resource1=IDD_SELECT_DB (English (U.S.))
+Resource2=IDD_CFG_FILE (English (U.S.))
 Class2=CChildView
-Resource3=IDD_INTRO (English (U.S.))
-Resource4=IDD_POLLING (English (U.S.))
+Resource3=IDD_LOG_FILE (English (U.S.))
+Resource4=IDD_FINISH (English (U.S.))
 Class5=CIntroPage
 Class6=CConfigWizard
-Resource5=IDD_CFG_FILE (English (U.S.))
+Resource5=IDD_SUMMARY (English (U.S.))
 Class7=CDBSelectPage
-Resource6=IDD_SUMMARY (English (U.S.))
+Resource6=IDD_POLLING (English (U.S.))
 Class8=CFinishPage
-Resource7=IDD_SELECT_DB (English (U.S.))
+Resource7=IDD_ODBC (English (U.S.))
 Class9=CODBCPage
 Resource8=IDD_ABOUTBOX (English (U.S.))
 Class10=CPollCfgPage
-Resource9=IDD_FINISH (English (U.S.))
+Resource9=IDD_INTRO (English (U.S.))
 Class11=CSMTPPage
-Resource10=IDD_SMTP (English (U.S.))
+Resource10=IDR_MAINFRAME (English (U.S.))
 Class12=CSummaryPage
-Resource11=IDD_PROCESSING (English (U.S.))
+Resource11=IDD_SMTP (English (U.S.))
 Class13=CProcessingPage
 Class14=CConfigFilePage
 Class15=CLoggingPage
-Resource12=IDD_LOG_FILE (English (U.S.))
+Resource12=IDD_PROCESSING (English (U.S.))
+Class16=CWinSrvPage
+Resource13=IDD_SERVICE (English (U.S.))
 
 [CLS:CNxconfigApp]
 Type=0
@@ -242,6 +244,7 @@ ImplementationFile=PollCfgPage.cpp
 BaseClass=CPropertyPage
 Filter=D
 VirtualFilter=idWC
+LastObject=CPollCfgPage
 
 [DLG:IDD_SMTP (English (U.S.))]
 Type=1
@@ -342,3 +345,27 @@ BaseClass=CPropertyPage
 Filter=D
 VirtualFilter=idWC
 
+[DLG:IDD_SERVICE (English (U.S.))]
+Type=1
+Class=CWinSrvPage
+ControlCount=11
+Control1=IDC_RADIO_SYSTEM,button,1342373897
+Control2=IDC_RADIO_USER,button,1342242825
+Control3=IDC_EDIT_LOGIN,edit,1350631552
+Control4=IDC_EDIT_PASSWD1,edit,1350631584
+Control5=IDC_EDIT_PASSWD2,edit,1350631584
+Control6=IDC_STATIC,static,1342177806
+Control7=IDC_STATIC,static,1342308352
+Control8=IDC_STATIC,static,1342308352
+Control9=IDC_STATIC,static,1342308352
+Control10=IDC_ICON_WARNING,static,1342177283
+Control11=IDC_STATIC_WARNING,static,1342308352
+
+[CLS:CWinSrvPage]
+Type=0
+HeaderFile=WinSrvPage.h
+ImplementationFile=WinSrvPage.cpp
+BaseClass=CPropertyPage
+Filter=D
+VirtualFilter=idWC
+
index 455abe8..7fd3416 100644 (file)
@@ -14,6 +14,7 @@
 #include "SummaryPage.h"
 #include "ProcessingPage.h"
 #include "ConfigFilePage.h"
+#include "WinSrvPage.h"
 #include "LoggingPage.h"
 #include "FinishPage.h"
 
@@ -154,6 +155,7 @@ void CNxconfigApp::OnFileCfgWizard()
    CPollCfgPage pgPollConfig;
    CSMTPPage pgSMTP;
    CLoggingPage pgLogging;
+   CWinSrvPage pgWinSrv;
    CSummaryPage pgSummary;
    CProcessingPage pgProcessing;
    CFinishPage pgFinish;
@@ -166,6 +168,7 @@ void CNxconfigApp::OnFileCfgWizard()
    dlg.AddPage(&pgPollConfig);
    dlg.AddPage(&pgSMTP);
    dlg.AddPage(&pgLogging);
+   dlg.AddPage(&pgWinSrv);
    dlg.AddPage(&pgSummary);
    dlg.AddPage(&pgProcessing);
    dlg.AddPage(&pgFinish);
index d6e0fe7..8a8680c 100644 (file)
@@ -175,6 +175,10 @@ SOURCE=.\tools.cpp
 # End Source File
 # Begin Source File
 
+SOURCE=.\WinSrvPage.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\WizardWorker.cpp
 # End Source File
 # End Group
@@ -261,6 +265,10 @@ SOURCE=.\SummaryPage.h
 
 SOURCE=.\tools.h
 # End Source File
+# Begin Source File
+
+SOURCE=.\WinSrvPage.h
+# End Source File
 # End Group
 # Begin Group "Resource Files"
 
index d7e4400..01c5e8a 100644 (file)
@@ -74,6 +74,8 @@ struct WIZARD_CFG_INFO
    TCHAR m_szLogFile[MAX_PATH];
    TCHAR m_szSMSDriver[MAX_PATH];
    TCHAR m_szSMSDrvParam[MAX_DB_STRING];
+   TCHAR m_szServiceLogin[MAX_DB_STRING];
+   TCHAR m_szServicePassword[MAX_DB_STRING];
 };
 
 
index 89cc614..a0339c5 100644 (file)
@@ -239,6 +239,31 @@ BEGIN
     LTEXT           "Select logging method:",IDC_STATIC,89,7,73,8
 END
 
+IDD_SERVICE DIALOGEX 0, 0, 319, 202
+STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION
+CAPTION "Windows Service Configuration"
+FONT 8, "MS Sans Serif"
+BEGIN
+    CONTROL         "&Local System account",IDC_RADIO_SYSTEM,"Button",
+                    BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,99,22,86,10
+    CONTROL         "&Custom account",IDC_RADIO_USER,"Button",
+                    BS_AUTORADIOBUTTON | WS_TABSTOP,99,39,67,10
+    EDITTEXT        IDC_EDIT_LOGIN,113,69,199,14,ES_AUTOHSCROLL
+    EDITTEXT        IDC_EDIT_PASSWD1,113,103,199,14,ES_PASSWORD | 
+                    ES_AUTOHSCROLL
+    EDITTEXT        IDC_EDIT_PASSWD2,113,122,199,14,ES_PASSWORD | 
+                    ES_AUTOHSCROLL
+    CONTROL         131,IDC_STATIC,"Static",SS_BITMAP | SS_CENTERIMAGE,7,7,
+                    75,188,WS_EX_CLIENTEDGE
+    LTEXT           "Run NetXMS core service under:",IDC_STATIC,91,7,106,8
+    LTEXT           "Login (use form DOMAIN\\USER for domain accounts)",
+                    IDC_STATIC,113,57,174,8
+    LTEXT           "Password (with verification)",IDC_STATIC,113,91,86,8
+    ICON            IDI_WARN,IDC_ICON_WARNING,99,148,20,20
+    LTEXT           "NOTE: You should use custom account if NetXMS server is configured to use Microsoft SQL with Windows authentication.",
+                    IDC_STATIC_WARNING,125,147,187,29
+END
+
 
 #ifndef _MAC
 /////////////////////////////////////////////////////////////////////////////
@@ -373,6 +398,14 @@ BEGIN
         TOPMARGIN, 7
         BOTTOMMARGIN, 195
     END
+
+    IDD_SERVICE, DIALOG
+    BEGIN
+        LEFTMARGIN, 7
+        RIGHTMARGIN, 312
+        TOPMARGIN, 7
+        BOTTOMMARGIN, 195
+    END
 END
 #endif    // APSTUDIO_INVOKED
 
index 457193d..28fc2f5 100644 (file)
@@ -21,6 +21,7 @@
 #define IDD_CFG_FILE                    143
 #define IDD_LOG_FILE                    144
 #define IDI_WARN                        145
+#define IDD_SERVICE                     146
 #define IDC_COMBO_DBDRV                 1000
 #define IDC_COMBO_DBDRV2                1001
 #define IDC_COMBO_DBENGINE              1001
 #define IDC_COMBO_PORT                  1030
 #define IDC_STATIC_PORT                 1031
 #define IDC_STATIC_DBNAME               1032
+#define IDC_RADIO_SYSTEM                1033
+#define IDC_RADIO_USER                  1034
+#define IDC_EDIT_LOGIN                  1035
+#define IDC_EDIT_PASSWD1                1036
+#define IDC_EDIT_PASSWD2                1037
+#define IDC_ICON_WARNING                1038
+#define IDC_STATIC_WARNING              1039
 #define ID_FILE_CFG_WIZARD              32771
 
 // Next default values for new objects
@@ -62,9 +70,9 @@
 #ifdef APSTUDIO_INVOKED
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_3D_CONTROLS                     1
-#define _APS_NEXT_RESOURCE_VALUE        146
+#define _APS_NEXT_RESOURCE_VALUE        147
 #define _APS_NEXT_COMMAND_VALUE         32772
-#define _APS_NEXT_CONTROL_VALUE         1033
+#define _APS_NEXT_CONTROL_VALUE         1040
 #define _APS_NEXT_SYMED_VALUE           101
 #endif
 #endif