]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Backpatch the inheritable-ACE patch for Win32 to 8.2 as well, except
authorMagnus Hagander <magnus@hagander.net>
Sun, 15 Nov 2009 09:08:46 +0000 (09:08 +0000)
committerMagnus Hagander <magnus@hagander.net>
Sun, 15 Nov 2009 09:08:46 +0000 (09:08 +0000)
for the pg_regress part which did not support admin execution in 8.2.

src/bin/initdb/initdb.c
src/bin/pg_ctl/pg_ctl.c
src/include/port.h
src/port/exec.c

index f965f0b2a5f8c2286218a30fcffc45afded61de3..1b00dd3b44a67786eb052c873eafebdb07f63940 100644 (file)
@@ -42,7 +42,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  * Portions taken from FreeBSD.
  *
- * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.125.2.3 2009/03/31 18:58:34 mha Exp $
+ * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.125.2.4 2009/11/15 09:08:45 mha Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -2336,6 +2336,10 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION * processInfo)
                return 0;
        }
 
+#ifndef __CYGWIN__
+    AddUserToTokenDacl(restrictedToken);
+#endif
+
        if (!CreateProcessAsUser(restrictedToken,
                                                NULL,
                                                cmd,
@@ -2353,10 +2357,6 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION * processInfo)
                return 0;
        }
 
-#ifndef __CYGWIN__
-       AddUserToDacl(processInfo->hProcess);
-#endif
-
        return ResumeThread(processInfo->hThread);
 }
 #endif
index 1ed2d2ab800f25302ac3060f5d33036175824c8a..1f5c4d62a7b10baada44e8b86debaa7f9cf428ec 100644 (file)
@@ -4,7 +4,7 @@
  *
  * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.74.2.7 2009/09/02 02:41:13 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.74.2.8 2009/11/15 09:08:46 mha Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1349,6 +1349,10 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION * processInfo)
                return 0;
        }
 
+#ifndef __CYGWIN__
+    AddUserToTokenDacl(restrictedToken);
+#endif
+
        r = CreateProcessAsUser(restrictedToken, NULL, cmd, NULL, NULL, TRUE, CREATE_SUSPENDED, NULL, NULL, &si, processInfo);
 
        Kernel32Handle = LoadLibrary("KERNEL32.DLL");
@@ -1429,10 +1433,6 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION * processInfo)
                }
        }
 
-#ifndef __CYGWIN__
-    AddUserToDacl(processInfo->hProcess);
-#endif
-    
        CloseHandle(restrictedToken);
 
        ResumeThread(processInfo->hThread);
index 0d7775094efc07f16eee629132d10805124e1ac7..404bd80535e784c96c8a71049ff3e84b41728ca6 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/port.h,v 1.106.2.6 2008/04/16 14:24:38 adunstan Exp $
+ * $PostgreSQL: pgsql/src/include/port.h,v 1.106.2.7 2009/11/15 09:08:46 mha Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -76,7 +76,7 @@ extern int find_other_exec(const char *argv0, const char *target,
 
 /* Windows security token manipulation (in exec.c) */
 #ifdef WIN32
-extern BOOL AddUserToDacl(HANDLE hProcess);
+extern BOOL AddUserToTokenDacl(HANDLE hToken);
 #endif
 
 
index 5e7fb3e5b4885721e026aeccf3850c2e2ca7ca08..65a7c491e8cd4d5101ecdefa89d5c64944070bf7 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/port/exec.c,v 1.43.2.2 2008/03/31 01:32:17 tgl Exp $
+ *       $PostgreSQL: pgsql/src/port/exec.c,v 1.43.2.3 2009/11/15 09:08:46 mha Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -649,11 +649,10 @@ set_pglocale_pgservice(const char *argv0, const char *app)
 #ifdef WIN32
 
 /*
- * AddUserToDacl(HANDLE hProcess)
+ * AddUserToTokenDacl(HANDLE hToken)
  *
- * This function adds the current user account to the default DACL
- * which gets attached to the restricted token used when we create
- * a restricted process.
+ * This function adds the current user account to the restricted
+ * token used when we create a restricted process.
  *
  * This is required because of some security changes in Windows
  * that appeared in patches to XP/2K3 and in Vista/2008.
@@ -666,13 +665,13 @@ set_pglocale_pgservice(const char *argv0, const char *app)
  * and CreateProcess() calls when running as Administrator.
  *
  * This function fixes this problem by modifying the DACL of the
- * specified process and explicitly re-adding the current user account.
- * This is still secure because the Administrator account inherits it's
- * privileges from the Administrators group - it doesn't have any of
- * it's own.
+ * token the process will use, and explicitly re-adding the current
+ * user account.  This is still secure because the Administrator account
+ * inherits its privileges from the Administrators group - it doesn't
+ * have any of its own.
  */
 BOOL
-AddUserToDacl(HANDLE hProcess)
+AddUserToTokenDacl(HANDLE hToken)
 {
        int                     i;
        ACL_SIZE_INFORMATION asi;
@@ -681,7 +680,6 @@ AddUserToDacl(HANDLE hProcess)
        DWORD           dwSize = 0;
        DWORD           dwTokenInfoLength = 0;
        DWORD           dwResult = 0;
-       HANDLE          hToken = NULL;
        PACL            pacl = NULL;
        PSID            psidUser = NULL;
        TOKEN_DEFAULT_DACL tddNew;
@@ -689,13 +687,6 @@ AddUserToDacl(HANDLE hProcess)
        TOKEN_INFORMATION_CLASS tic = TokenDefaultDacl;
        BOOL            ret = FALSE;
 
-       /* Get the token for the process */
-       if (!OpenProcessToken(hProcess, TOKEN_QUERY | TOKEN_ADJUST_DEFAULT, &hToken))
-       {
-               log_error("could not open process token: %ui", GetLastError());
-               goto cleanup;
-       }
-
        /* Figure out the buffer size for the DACL info */
        if (!GetTokenInformation(hToken, tic, (LPVOID) NULL, dwTokenInfoLength, &dwSize))
        {
@@ -771,7 +762,7 @@ AddUserToDacl(HANDLE hProcess)
        }
 
        /* Add the new ACE for the current user */
-       if (!AddAccessAllowedAce(pacl, ACL_REVISION, GENERIC_ALL, psidUser))
+       if (!AddAccessAllowedAceEx(pacl, ACL_REVISION, OBJECT_INHERIT_ACE, GENERIC_ALL, psidUser))
        {
                log_error("could not add access allowed ACE: %ui", GetLastError());
                goto cleanup;
@@ -798,9 +789,6 @@ cleanup:
        if (ptdd)
                LocalFree((HLOCAL) ptdd);
 
-       if (hToken)
-               CloseHandle(hToken);
-
        return ret;
 }