You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2011/11/03 10:33:34 UTC

svn commit: r1197021 - in /commons/proper/daemon/trunk: RELEASE-NOTES.txt src/native/windows/src/private.h src/native/windows/src/registry.c src/native/windows/src/service.c

Author: mturk
Date: Thu Nov  3 09:33:33 2011
New Revision: 1197021

URL: http://svn.apache.org/viewvc?rev=1197021&view=rev
Log:
DAEMON-215: Make sure we pass SERVICE_WIN32_OWN_PROCESS when setting the username/password

Modified:
    commons/proper/daemon/trunk/RELEASE-NOTES.txt
    commons/proper/daemon/trunk/src/native/windows/src/private.h
    commons/proper/daemon/trunk/src/native/windows/src/registry.c
    commons/proper/daemon/trunk/src/native/windows/src/service.c

Modified: commons/proper/daemon/trunk/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/RELEASE-NOTES.txt?rev=1197021&r1=1197020&r2=1197021&view=diff
==============================================================================
--- commons/proper/daemon/trunk/RELEASE-NOTES.txt (original)
+++ commons/proper/daemon/trunk/RELEASE-NOTES.txt Thu Nov  3 09:33:33 2011
@@ -80,7 +80,7 @@ NEW FEATURES:
 
 BUG FIXES:
 
-1.0.8: DAEMON-218, DAEMON-220, DAEMON-222, DAEMON-223, DAEMON-224
+1.0.8: DAEMON-215, DAEMON-218, DAEMON-220, DAEMON-222, DAEMON-223, DAEMON-224
 
 1.0.7: DAEMON-211, DAEMON-214
 

Modified: commons/proper/daemon/trunk/src/native/windows/src/private.h
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/windows/src/private.h?rev=1197021&r1=1197020&r2=1197021&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/windows/src/private.h (original)
+++ commons/proper/daemon/trunk/src/native/windows/src/private.h Thu Nov  3 09:33:33 2011
@@ -253,8 +253,6 @@ typedef struct APXREGENUM {
 } APXREGENUM, *LPAPXREGENUM;
 
 BOOL    apxRegistryEnumServices(LPAPXREGENUM lpEnum, LPAPXSERVENTRY lpEntry);
-
-BOOL    apxSetServiceDescriptionW(LPCWSTR szServiceName, LPCWSTR szDescription);
 BOOL    apxGetServiceDescriptionW(LPCWSTR szServiceName, LPWSTR szDescription,
                                   DWORD dwDescriptionLength);
 BOOL    apxGetServiceUserW(LPCWSTR szServiceName, LPWSTR szUser,

Modified: commons/proper/daemon/trunk/src/native/windows/src/registry.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/windows/src/registry.c?rev=1197021&r1=1197020&r2=1197021&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/windows/src/registry.c (original)
+++ commons/proper/daemon/trunk/src/native/windows/src/registry.c Thu Nov  3 09:33:33 2011
@@ -1062,32 +1062,6 @@ BOOL apxRegistryEnumServices(LPAPXREGENU
     return TRUE;
 }
 
-/* We could use the ChangeServiceConfig2 on WIN2K+
- * For now use the registry.
- */
-BOOL apxSetServiceDescriptionW(LPCWSTR szServiceName, LPCWSTR szDescription)
-{
-    HKEY  hKey;
-    WCHAR wcName[SIZ_RESLEN];
-    DWORD rc;
-
-    if (lstrlenW(szServiceName) > SIZ_RESMAX)
-        return FALSE;
-    lstrcpyW(wcName, REGSERVICE_ROOT);
-    lstrcatW(wcName, szServiceName);
-
-    rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wcName, 0, KEY_WRITE, &hKey);
-    if (rc != ERROR_SUCCESS) {
-        return FALSE;
-    }
-
-    rc = RegSetValueExW(hKey, REGDESCRIPTION, 0, REG_SZ, (CONST BYTE *)szDescription,
-                        (lstrlenW(szDescription) + 1) * sizeof(WCHAR));
-    SAFE_CLOSE_KEY(hKey);
-
-    return rc == ERROR_SUCCESS;
-}
-
 BOOL apxGetServiceDescriptionW(LPCWSTR szServiceName, LPWSTR szDescription,
                                DWORD dwDescriptionLength)
 {

Modified: commons/proper/daemon/trunk/src/native/windows/src/service.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/windows/src/service.c?rev=1197021&r1=1197020&r2=1197021&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/windows/src/service.c (original)
+++ commons/proper/daemon/trunk/src/native/windows/src/service.c Thu Nov  3 09:33:33 2011
@@ -23,11 +23,6 @@
         (h) = NULL;                                     \
     }
 
-#define CHANGE_SERVICE(h, b, u, p, d)   \
-    ChangeServiceConfigW(h, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE,   \
-                         SERVICE_NO_CHANGE,b,NULL,NULL,NULL,        \
-                         u,p,d)
-
 typedef struct APXSERVICE {
     /* Are we a service manager or we are the service itself */
     BOOL            bManagerMode;
@@ -197,6 +192,7 @@ apxServiceSetNames(APXHANDLE hService,
                    LPCWSTR szPassword)
 {
     LPAPXSERVICE lpService;
+    DWORD dwServiceType = SERVICE_NO_CHANGE;
 
     if (hService->dwType != APXHANDLE_TYPE_SERVICE)
         return FALSE;
@@ -208,17 +204,28 @@ apxServiceSetNames(APXHANDLE hService,
     /* Check if the ServiceOpen has been called */
     if (IS_INVALID_HANDLE(lpService->hService))
         return FALSE;
-    if (!CHANGE_SERVICE(lpService->hService,
-                                        szImagePath,
-                                        szUsername,
-                                        szPassword,
-                                        szDisplayName)) {
+    if (szUsername || szPassword)
+        dwServiceType = SERVICE_WIN32_OWN_PROCESS;
+    if (!ChangeServiceConfigW(lpService->hService,
+                              dwServiceType,
+                              SERVICE_NO_CHANGE,
+                              SERVICE_NO_CHANGE,
+                              szImagePath,
+                              NULL,
+                              NULL,
+                              NULL,
+                              szUsername,
+                              szPassword,
+                              szDisplayName)) {
         apxLogWrite(APXLOG_MARK_SYSERR);
         return FALSE;
     }
     if (szDescription) {
-        return apxSetServiceDescriptionW(lpService->stServiceEntry.szServiceName,
-                                         szDescription);
+        SERVICE_DESCRIPTIONW desc;
+        desc.lpDescription = (LPWSTR)szDescription;
+        return ChangeServiceConfig2(lpService->hService,
+                                    SERVICE_CONFIG_DESCRIPTION,
+                                    &desc);
     }
     return TRUE;
 }