This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git


The following commit(s) were added to refs/heads/master by this push:
     new 602ca54  Fix DAEMON-411 Correct ' interact with desktop' configuration
602ca54 is described below

commit 602ca54360f2bcc7bd0993c754101dfac6f09697
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Nov 21 21:49:39 2019 +0000

    Fix DAEMON-411 Correct ' interact with desktop' configuration
    
    Multiple issues:
    - No error message if specified with wrong user (has to be LocalSystem)
    - Didn't configure option when set when installing new service
    - Made option available with wrong users in GUI
    - Failed to save option correctly when setting option was only change
      made in GUI
    
    Signed-off-by: Mark Thomas <ma...@apache.org>
---
 src/changes/changes.xml                   |  7 +++++++
 src/native/windows/apps/prunmgr/prunmgr.c | 21 ++++++++++++---------
 src/native/windows/apps/prunsrv/prunsrv.c | 17 +++++++++++++++--
 src/native/windows/src/service.c          | 14 ++++++++++----
 src/site/xdoc/procrun.xml                 |  2 +-
 5 files changed, 45 insertions(+), 16 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 03bb314..c0d2c53 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -42,6 +42,13 @@
       <action issue="DAEMON-414" type="fix" dev="ggregory" due-to="Gary 
Gregory">
         prunsrv uses its log is before it is initialized.
       </action>
+      <action issue="DAEMON-411" type="fix" dev="markt">
+        Procrun. Correct multiple issues related to enabling a service to
+        interact with the desktop. Provide a better error message if this 
option
+        is used with an invalid user, install the service with the option
+        enabled if requested and correctly save the setting if it is enabled in
+        the GUI. 
+      </action>
     </release>
     <release version="1.2.2" date="2019-10-04" description="Bug fix release">
       <action issue="DAEMON-408" type="fix" dev="markt">
diff --git a/src/native/windows/apps/prunmgr/prunmgr.c 
b/src/native/windows/apps/prunmgr/prunmgr.c
index 14d6e99..b8b7ba1 100644
--- a/src/native/windows/apps/prunmgr/prunmgr.c
+++ b/src/native/windows/apps/prunmgr/prunmgr.c
@@ -735,7 +735,7 @@ INT_PTR CALLBACK __logonProperty(HWND hDlg,
         case WM_INITDIALOG:
             {
                 BOOL           bNamedAccount = FALSE;
-                BOOL           bLocalServiceAccount = FALSE;
+                BOOL           bLocalSystemAccount = FALSE;
 
                 startPage = 1;
                 if (!bpropCentered)
@@ -748,29 +748,32 @@ INT_PTR CALLBACK __logonProperty(HWND hDlg,
 
                 // LocalService
                 if (lstrcmpiW(_currentEntry->szObjectName, STAT_SERVICE) == 0) 
{
-                       CheckRadioButton(hDlg, IDC_PPSLLSRV, IDC_PPSLUA, 
IDC_PPSLLSRV);
+                    CheckRadioButton(hDlg, IDC_PPSLLSRV, IDC_PPSLUA, 
IDC_PPSLLSRV);
+                    SetDlgItemTextW(hDlg, IDC_PPSLUSER, STAT_SERVICE);
                 }
                 // NetworkService
                 else if (lstrcmpiW(_currentEntry->szObjectName, 
STAT_NET_SERVICE) == 0) {
-                       CheckRadioButton(hDlg, IDC_PPSLLSRV, IDC_PPSLUA, 
IDC_PPSLNSRV);
+                    CheckRadioButton(hDlg, IDC_PPSLLSRV, IDC_PPSLUA, 
IDC_PPSLNSRV);
+                    SetDlgItemTextW(hDlg, IDC_PPSLUSER, STAT_NET_SERVICE);
                 }
                 // LocalSystem
                 else if (lstrcmpiW(_currentEntry->szObjectName, STAT_SYSTEM) 
== 0) {
-                       CheckRadioButton(hDlg, IDC_PPSLLSRV, IDC_PPSLUA, 
IDC_PPSLLSYS);
-                       bLocalServiceAccount = TRUE;
+                    CheckRadioButton(hDlg, IDC_PPSLLSRV, IDC_PPSLUA, 
IDC_PPSLLSYS);
+                    SetDlgItemTextW(hDlg, IDC_PPSLUSER, STAT_SYSTEM);
+                    bLocalSystemAccount = TRUE;
                     if (_currentEntry->lpConfig->dwServiceType & 
SERVICE_INTERACTIVE_PROCESS) {
                         CheckDlgButton(hDlg, IDC_PPSLID, BST_CHECKED);
                     }
                 }
                 else {
-                       bNamedAccount = TRUE;
+                    bNamedAccount = TRUE;
                     CheckRadioButton(hDlg, IDC_PPSLLSYS, IDC_PPSLUA, 
IDC_PPSLUA);
                     SetDlgItemTextW(hDlg, IDC_PPSLUSER, 
_currentEntry->szObjectName);
                     SetDlgItemTextW(hDlg, IDC_PPSLPASS, EMPTY_PASSWORD);
                     SetDlgItemTextW(hDlg, IDC_PPSLCPASS, EMPTY_PASSWORD);
                 }
 
-                EnableWindow(GetDlgItem(hDlg, IDC_PPSLID), 
!bLocalServiceAccount);
+                EnableWindow(GetDlgItem(hDlg, IDC_PPSLID), 
bLocalSystemAccount);
                 EnableWindow(GetDlgItem(hDlg, IDC_PPSLUSER), bNamedAccount);
                 EnableWindow(GetDlgItem(hDlg, IDC_PPSLBROWSE), bNamedAccount);
                 EnableWindow(GetDlgItem(hDlg, IDL_PPSLPASS), bNamedAccount);
@@ -785,7 +788,7 @@ INT_PTR CALLBACK __logonProperty(HWND hDlg,
                     SetDlgItemTextW(hDlg, IDC_PPSLUSER, STAT_SERVICE);
                     SetDlgItemTextW(hDlg, IDC_PPSLPASS, L"");
                     SetDlgItemTextW(hDlg, IDC_PPSLCPASS, L"");
-                    EnableWindow(GetDlgItem(hDlg, IDC_PPSLID), TRUE);
+                    EnableWindow(GetDlgItem(hDlg, IDC_PPSLID), FALSE);
                     EnableWindow(GetDlgItem(hDlg, IDC_PPSLUSER), FALSE);
                     EnableWindow(GetDlgItem(hDlg, IDC_PPSLBROWSE), FALSE);
                     EnableWindow(GetDlgItem(hDlg, IDL_PPSLPASS), FALSE);
@@ -806,7 +809,7 @@ INT_PTR CALLBACK __logonProperty(HWND hDlg,
                     SetDlgItemTextW(hDlg, IDC_PPSLUSER, STAT_NET_SERVICE);
                     SetDlgItemTextW(hDlg, IDC_PPSLPASS, L"");
                     SetDlgItemTextW(hDlg, IDC_PPSLCPASS, L"");
-                    EnableWindow(GetDlgItem(hDlg, IDC_PPSLID), TRUE);
+                    EnableWindow(GetDlgItem(hDlg, IDC_PPSLID), FALSE);
                     EnableWindow(GetDlgItem(hDlg, IDC_PPSLUSER), FALSE);
                     EnableWindow(GetDlgItem(hDlg, IDC_PPSLBROWSE), FALSE);
                     EnableWindow(GetDlgItem(hDlg, IDL_PPSLPASS), FALSE);
diff --git a/src/native/windows/apps/prunsrv/prunsrv.c 
b/src/native/windows/apps/prunsrv/prunsrv.c
index bf2d12c..d854664 100644
--- a/src/native/windows/apps/prunsrv/prunsrv.c
+++ b/src/native/windows/apps/prunsrv/prunsrv.c
@@ -630,8 +630,21 @@ static BOOL docmdInstallService(LPAPXCMDLINE lpCmdline)
         dwStart = SERVICE_AUTO_START;
     /* Check the service type */
     if ((ST_TYPE & APXCMDOPT_FOUND) &&
-        lstrcmpiW(SO_TYPE, STYPE_INTERACTIVE) == 0)
-        dwType |= SERVICE_INTERACTIVE_PROCESS;
+        lstrcmpiW(SO_TYPE, STYPE_INTERACTIVE) == 0) {
+
+        // Need to run as LocalSystem to set the interactive flag
+        LPCWSTR su = NULL;
+        if (ST_SUSER & APXCMDOPT_FOUND) {
+            su = SO_SUSER;
+        }
+        if (su && lstrcmpiW(su, L"LocalSystem") == 0) {
+            dwType |= SERVICE_INTERACTIVE_PROCESS;
+        } else {
+            apxLogWrite(APXLOG_MARK_ERROR
+                    "The parameter '--Type interactive' is only valid with 
'--ServiceUser LocalSystem'");
+            return FALSE;
+        }
+    }
 
     /* Check if --Install is provided */
     if (!IS_VALID_STRING(SO_INSTALL)) {
diff --git a/src/native/windows/src/service.c b/src/native/windows/src/service.c
index 7d1925e..78d9a38 100644
--- a/src/native/windows/src/service.c
+++ b/src/native/windows/src/service.c
@@ -238,10 +238,8 @@ apxServiceSetNames(APXHANDLE hService,
     /* Check if the ServiceOpen has been called */
     if (IS_INVALID_HANDLE(lpService->hService))
         return FALSE;
-    if (szUsername || szPassword)
-        dwServiceType = SERVICE_WIN32_OWN_PROCESS;
     if (!ChangeServiceConfigW(lpService->hService,
-                              dwServiceType,
+                              SERVICE_NO_CHANGE,
                               SERVICE_NO_CHANGE,
                               SERVICE_NO_CHANGE,
                               szImagePath,
@@ -584,6 +582,7 @@ apxServiceInstall(APXHANDLE hService, LPCWSTR szServiceName,
                   DWORD dwStartType)
 {
     LPAPXSERVICE   lpService;
+    LPCWSTR szServiceUser = L"NT Authority\\LocalService";
 
     if (hService->dwType != APXHANDLE_TYPE_SERVICE)
         return FALSE;
@@ -610,6 +609,13 @@ apxServiceInstall(APXHANDLE hService, LPCWSTR 
szServiceName,
                                            L"Tcpip\0Afd\0", NULL);
     else
         lpDependencies = L"Tcpip\0Afd\0";
+
+    if ((dwServiceType & SERVICE_INTERACTIVE_PROCESS) == 
SERVICE_INTERACTIVE_PROCESS) {
+        // Caller is responsible for checking the user is set appropriately
+        // for an interactive service (will use LocalSystem)
+        szServiceUser = NULL;
+    }
+
     lpService->hService = CreateServiceW(lpService->hManager,
                                          szServiceName,
                                          szDisplayName,
@@ -621,7 +627,7 @@ apxServiceInstall(APXHANDLE hService, LPCWSTR szServiceName,
                                          NULL,
                                          NULL,
                                          lpDependencies,
-                                         L"NT Authority\\LocalService",
+                                         szServiceUser,
                                          NULL);
 
     if (IS_INVALID_HANDLE(lpService->hService)) {
diff --git a/src/site/xdoc/procrun.xml b/src/site/xdoc/procrun.xml
index 70217b1..c6d039e 100644
--- a/src/site/xdoc/procrun.xml
+++ b/src/site/xdoc/procrun.xml
@@ -318,7 +318,7 @@ will add the new value(s) to any existing value(s).
     <td>--Type</td>
     <td></td>
     <td>Service type can be <b>interactive</b> to allow the service to 
interact with the desktop.
-    Use this option only with Local system accounts.</td>
+    This option can only be used with the <i>LocalSystem</i> account.</td>
     </tr>
     <tr>
     <td>++DependsOn</td>

Reply via email to