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 2009/12/11 08:26:50 UTC

svn commit: r889520 - in /commons/proper/daemon/trunk/src/native/nt/procrun: apps/prunsrv/prunsrv.c include/registry.h src/registry.c

Author: mturk
Date: Fri Dec 11 07:26:49 2009
New Revision: 889520

URL: http://svn.apache.org/viewvc?rev=889520&view=rev
Log:
Apply the patch from Jesse Morris (DAEMON-131)

Modified:
    commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.c
    commons/proper/daemon/trunk/src/native/nt/procrun/include/registry.h
    commons/proper/daemon/trunk/src/native/nt/procrun/src/registry.c

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.c?rev=889520&r1=889519&r2=889520&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.c (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.c Fri Dec 11 07:26:49 2009
@@ -642,7 +642,7 @@
     }
     if (rv) {
         /* Delete all service registry settings */
-        apxDeleteRegistryW(PRG_REGROOT, lpCmdline->szApplication, TRUE);
+        apxDeleteRegistryW(PRG_REGROOT, lpCmdline->szApplication, KREG_WOW6432, TRUE);
         apxLogWrite(APXLOG_MARK_DEBUG "Service %S deleted",
                     lpCmdline->szApplication);
     }

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/include/registry.h
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/include/registry.h?rev=889520&r1=889519&r2=889520&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/include/registry.h (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/include/registry.h Fri Dec 11 07:26:49 2009
@@ -43,12 +43,13 @@
 #endif
 
 /** Delete the process registry keys
+ *  samDesired only needs to be KREG_WOW6432 or 0
  */
 BOOL      apxDeleteRegistryA(LPCSTR szRoot, LPCSTR szKeyName,
-                            BOOL bDeleteEmpty);
+                            REGSAM samDesired, BOOL bDeleteEmptyRoot);
 
 BOOL      apxDeleteRegistryW(LPCWSTR szRoot, LPCWSTR szKeyName,
-                            BOOL bDeleteEmpty);
+                            REGSAM samDesired, BOOL bDeleteEmptyRoot);
 
 #ifdef _UNICODE
 #define apxDeleteRegistry   apxDeleteRegistryW

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/src/registry.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/src/registry.c?rev=889520&r1=889519&r2=889520&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/src/registry.c (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/src/registry.c Fri Dec 11 07:26:49 2009
@@ -815,39 +815,86 @@
 }
 
 
+LONG apxDeleteRegistryRecursive(HKEY hKeyRoot, LPCWSTR szSubKey) {
+    LONG rc = ERROR_SUCCESS;
+    DWORD dwSize = 0;
+    WCHAR szName[SIZ_BUFLEN];
+    HKEY hKey = NULL;
+
+    if (ERROR_SUCCESS == RegDeleteKey(hKeyRoot, szSubKey)) {
+        return ERROR_SUCCESS;
+    }
+
+    rc = RegOpenKeyExW(hKeyRoot, szSubKey, 0, KEY_ENUMERATE_SUB_KEYS | DELETE, &hKey);
+    if (rc != ERROR_SUCCESS) {
+        if (rc == ERROR_FILE_NOT_FOUND) {
+            return ERROR_SUCCESS;
+        } else {
+            return rc;
+        }
+    }
+    while (rc == ERROR_SUCCESS) {
+        dwSize = SIZ_BUFLEN;
+        rc = RegEnumKeyExW(hKey, 0, szName, &dwSize, NULL, NULL, NULL, NULL );
+       
+        if (rc == ERROR_NO_MORE_ITEMS) {           
+            rc = RegDeleteKeyW(hKeyRoot, szSubKey);
+            break;
+        } else {
+            rc = apxDeleteRegistryRecursive(hKey, szName);
+            if (rc != ERROR_SUCCESS) {
+                break;   // abort when we start failing
+            }
+        }
+    }    
+    RegCloseKey(hKey);
+    return rc;
+}
+
+
 BOOL
 apxDeleteRegistryW(LPCWSTR szRoot,
                    LPCWSTR szKeyName,
-                   BOOL bDeleteEmpty)
+                   REGSAM samDesired,
+                   BOOL bDeleteEmptyRoot)
 {
     WCHAR     buff[SIZ_BUFLEN];
-    BOOL      rv;
+    LONG      rc = ERROR_SUCCESS;
+    HKEY      hKey = NULL;
+    BOOL      rv = TRUE;
+    HKEY      hives[] = {HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER, NULL}, *hive = NULL;
 
     if (!szKeyName || lstrlenW(szKeyName) > SIZ_RESMAX)
         return FALSE;
     if (szRoot && lstrlenW(szRoot) > SIZ_RESMAX)
         return FALSE;
 
-    lstrcpyW(buff, REGSOFTWARE_ROOT);
     if (szRoot)
-        lstrcatW(buff, szRoot);
+        lstrcpyW(buff, szRoot);
     else
-        lstrcatW(buff, REGAPACHE_ROOT);
+        lstrcpyW(buff, REGAPACHE_ROOT);
     lstrcatW(buff, REGSEPARATOR);
-    lstrcatW(buff, szKeyName);
-
-    rv = SHDeleteKeyW(HKEY_LOCAL_MACHINE, buff);
-    rv += SHDeleteKeyW(HKEY_CURRENT_USER, buff);
 
-    if (bDeleteEmpty) {
-        lstrcpyW(buff, REGSOFTWARE_ROOT);
-        if (szRoot)
-            lstrcatW(buff, szRoot);
-        else
-            lstrcatW(buff, REGAPACHE_ROOT);
+    for (hive = &hives[0]; *hive; hive++) {
+        HKEY hkeySoftware = NULL;
 
-        SHDeleteEmptyKeyW(HKEY_LOCAL_MACHINE, buff);
-        SHDeleteEmptyKeyW(HKEY_CURRENT_USER, buff);
+        rc = RegOpenKeyExW(*hive, REGSOFTWARE_ROOT, 0, KEY_READ | samDesired, &hkeySoftware);
+        if (rc != ERROR_SUCCESS) {
+            rv = FALSE;
+        } else {
+            rc = RegOpenKeyExW(hkeySoftware, buff, 0, samDesired | KEY_ENUMERATE_SUB_KEYS | DELETE, &hKey);
+            if (rc == ERROR_SUCCESS) {
+                rc = apxDeleteRegistryRecursive(hKey, szKeyName);
+                RegCloseKey(hKey);
+                hKey = NULL;
+                rv |= (rc == ERROR_SUCCESS);
+            }
+            if (bDeleteEmptyRoot) {  
+                // will fail if there are subkeys, just like we want
+                RegDeleteKeyW(hkeySoftware, buff);
+            }
+            RegCloseKey(hkeySoftware);
+        } 
     }
     return rv;
 }
@@ -855,7 +902,8 @@
 BOOL
 apxDeleteRegistryA(LPCSTR szRoot,
                    LPCSTR szKeyName,
-                   BOOL bDeleteEmpty)
+                   REGSAM samDesired,
+                   BOOL bDeleteEmptyRoot)
 {
     WCHAR    wcRoot[SIZ_RESLEN];
     WCHAR    wcKey[SIZ_RESLEN];
@@ -866,7 +914,7 @@
     }
     AsciiToWide(szKeyName, wcKey);
 
-    return apxDeleteRegistryW(wsRoot, wcKey, bDeleteEmpty);
+    return apxDeleteRegistryW(wsRoot, wcKey, samDesired, bDeleteEmptyRoot);
 }