9
9
*
10
10
*
11
11
* IDENTIFICATION
12
- * $PostgreSQL: pgsql/src/port/exec.c,v 1.64 2009/07/27 08:46:10 mha Exp $
12
+ * $PostgreSQL: pgsql/src/port/exec.c,v 1.65 2009/11/14 15:39:36 mha Exp $
13
13
*
14
14
*-------------------------------------------------------------------------
15
15
*/
@@ -664,11 +664,10 @@ set_pglocale_pgservice(const char *argv0, const char *app)
664
664
#ifdef WIN32
665
665
666
666
/*
667
- * AddUserToDacl (HANDLE hProcess )
667
+ * AddUserToTokenDacl (HANDLE hToken )
668
668
*
669
- * This function adds the current user account to the default DACL
670
- * which gets attached to the restricted token used when we create
671
- * a restricted process.
669
+ * This function adds the current user account to the restricted
670
+ * token used when we create a restricted process.
672
671
*
673
672
* This is required because of some security changes in Windows
674
673
* that appeared in patches to XP/2K3 and in Vista/2008.
@@ -681,35 +680,27 @@ set_pglocale_pgservice(const char *argv0, const char *app)
681
680
* and CreateProcess() calls when running as Administrator.
682
681
*
683
682
* This function fixes this problem by modifying the DACL of the
684
- * specified process and explicitly re-adding the current user account.
685
- * This is still secure because the Administrator account inherits it's
686
- * privileges from the Administrators group - it doesn't have any of
687
- * it's own.
683
+ * token the process will use, and explicitly re-adding the current
684
+ * user account. This is still secure because the Administrator account
685
+ * inherits its privileges from the Administrators group - it doesn't
686
+ * have any of its own.
688
687
*/
689
688
BOOL
690
- AddUserToDacl (HANDLE hProcess )
689
+ AddUserToTokenDacl (HANDLE hToken )
691
690
{
692
691
int i ;
693
692
ACL_SIZE_INFORMATION asi ;
694
693
ACCESS_ALLOWED_ACE * pace ;
695
694
DWORD dwNewAclSize ;
696
695
DWORD dwSize = 0 ;
697
696
DWORD dwTokenInfoLength = 0 ;
698
- HANDLE hToken = NULL ;
699
697
PACL pacl = NULL ;
700
698
PTOKEN_USER pTokenUser = NULL ;
701
699
TOKEN_DEFAULT_DACL tddNew ;
702
700
TOKEN_DEFAULT_DACL * ptdd = NULL ;
703
701
TOKEN_INFORMATION_CLASS tic = TokenDefaultDacl ;
704
702
BOOL ret = FALSE;
705
703
706
- /* Get the token for the process */
707
- if (!OpenProcessToken (hProcess , TOKEN_QUERY | TOKEN_ADJUST_DEFAULT , & hToken ))
708
- {
709
- log_error ("could not open process token: %lu" , GetLastError ());
710
- goto cleanup ;
711
- }
712
-
713
704
/* Figure out the buffer size for the DACL info */
714
705
if (!GetTokenInformation (hToken , tic , (LPVOID ) NULL , dwTokenInfoLength , & dwSize ))
715
706
{
@@ -789,7 +780,7 @@ AddUserToDacl(HANDLE hProcess)
789
780
}
790
781
791
782
/* Add the new ACE for the current user */
792
- if (!AddAccessAllowedAce (pacl , ACL_REVISION , GENERIC_ALL , pTokenUser -> User .Sid ))
783
+ if (!AddAccessAllowedAceEx (pacl , ACL_REVISION , OBJECT_INHERIT_ACE , GENERIC_ALL , pTokenUser -> User .Sid ))
793
784
{
794
785
log_error ("could not add access allowed ACE: %lu" , GetLastError ());
795
786
goto cleanup ;
@@ -816,9 +807,6 @@ AddUserToDacl(HANDLE hProcess)
816
807
if (ptdd )
817
808
LocalFree ((HLOCAL ) ptdd );
818
809
819
- if (hToken )
820
- CloseHandle (hToken );
821
-
822
810
return ret ;
823
811
}
824
812
0 commit comments