9
9
*
10
10
*
11
11
* IDENTIFICATION
12
- * $PostgreSQL: pgsql/src/port/exec.c,v 1.63 2009/06/11 14:49:15 momjian Exp $
12
+ * $PostgreSQL: pgsql/src/port/exec.c,v 1.64 2009/07/27 08:46:10 mha Exp $
13
13
*
14
14
*-------------------------------------------------------------------------
15
15
*/
@@ -56,7 +56,7 @@ static int resolve_symlinks(char *path);
56
56
static char * pipe_read_line (char * cmd , char * line , int maxsize );
57
57
58
58
#ifdef WIN32
59
- static BOOL GetUserSid ( PSID * ppSidUser , HANDLE hToken );
59
+ static BOOL GetTokenUser ( HANDLE hToken , PTOKEN_USER * ppTokenUser );
60
60
#endif
61
61
62
62
/*
@@ -697,7 +697,7 @@ AddUserToDacl(HANDLE hProcess)
697
697
DWORD dwTokenInfoLength = 0 ;
698
698
HANDLE hToken = NULL ;
699
699
PACL pacl = NULL ;
700
- PSID psidUser = NULL ;
700
+ PTOKEN_USER pTokenUser = NULL ;
701
701
TOKEN_DEFAULT_DACL tddNew ;
702
702
TOKEN_DEFAULT_DACL * ptdd = NULL ;
703
703
TOKEN_INFORMATION_CLASS tic = TokenDefaultDacl ;
@@ -744,15 +744,19 @@ AddUserToDacl(HANDLE hProcess)
744
744
goto cleanup ;
745
745
}
746
746
747
- /* Get the SID for the current user. We need to add this to the ACL. */
748
- if (!GetUserSid (& psidUser , hToken ))
747
+ /*
748
+ * Get the user token for the current user, which provides us with the
749
+ * SID that is needed for creating the ACL.
750
+ */
751
+ if (!GetTokenUser (hToken , & pTokenUser ))
749
752
{
750
- log_error ("could not get user SID : %lu" , GetLastError ());
753
+ log_error ("could not get user token : %lu" , GetLastError ());
751
754
goto cleanup ;
752
755
}
753
756
754
757
/* Figure out the size of the new ACL */
755
- dwNewAclSize = asi .AclBytesInUse + sizeof (ACCESS_ALLOWED_ACE ) + GetLengthSid (psidUser ) - sizeof (DWORD );
758
+ dwNewAclSize = asi .AclBytesInUse + sizeof (ACCESS_ALLOWED_ACE ) +
759
+ GetLengthSid (pTokenUser -> User .Sid ) - sizeof (DWORD );
756
760
757
761
/* Allocate the ACL buffer & initialize it */
758
762
pacl = (PACL ) LocalAlloc (LPTR , dwNewAclSize );
@@ -785,7 +789,7 @@ AddUserToDacl(HANDLE hProcess)
785
789
}
786
790
787
791
/* Add the new ACE for the current user */
788
- if (!AddAccessAllowedAce (pacl , ACL_REVISION , GENERIC_ALL , psidUser ))
792
+ if (!AddAccessAllowedAce (pacl , ACL_REVISION , GENERIC_ALL , pTokenUser -> User . Sid ))
789
793
{
790
794
log_error ("could not add access allowed ACE: %lu" , GetLastError ());
791
795
goto cleanup ;
@@ -803,8 +807,8 @@ AddUserToDacl(HANDLE hProcess)
803
807
ret = TRUE;
804
808
805
809
cleanup :
806
- if (psidUser )
807
- FreeSid ( psidUser );
810
+ if (pTokenUser )
811
+ LocalFree (( HLOCAL ) pTokenUser );
808
812
809
813
if (pacl )
810
814
LocalFree ((HLOCAL ) pacl );
@@ -819,28 +823,31 @@ AddUserToDacl(HANDLE hProcess)
819
823
}
820
824
821
825
/*
822
- * GetUserSid*PSID *ppSidUser, HANDLE hToken)
826
+ * GetTokenUser(HANDLE hToken, PTOKEN_USER *ppTokenUser)
827
+ *
828
+ * Get the users token information from a process token.
823
829
*
824
- * Get the SID for the current user
830
+ * The caller of this function is responsible for calling LocalFree() on the
831
+ * returned TOKEN_USER memory.
825
832
*/
826
833
static BOOL
827
- GetUserSid ( PSID * ppSidUser , HANDLE hToken )
834
+ GetTokenUser ( HANDLE hToken , PTOKEN_USER * ppTokenUser )
828
835
{
829
836
DWORD dwLength ;
830
- PTOKEN_USER pTokenUser = NULL ;
831
837
838
+ * ppTokenUser = NULL ;
832
839
833
840
if (!GetTokenInformation (hToken ,
834
841
TokenUser ,
835
- pTokenUser ,
842
+ NULL ,
836
843
0 ,
837
844
& dwLength ))
838
845
{
839
846
if (GetLastError () == ERROR_INSUFFICIENT_BUFFER )
840
847
{
841
- pTokenUser = (PTOKEN_USER ) HeapAlloc ( GetProcessHeap (), HEAP_ZERO_MEMORY , dwLength );
848
+ * ppTokenUser = (PTOKEN_USER ) LocalAlloc ( LPTR , dwLength );
842
849
843
- if (pTokenUser == NULL )
850
+ if (* ppTokenUser == NULL )
844
851
{
845
852
log_error ("could not allocate %lu bytes of memory" , dwLength );
846
853
return FALSE;
@@ -855,18 +862,18 @@ GetUserSid(PSID *ppSidUser, HANDLE hToken)
855
862
856
863
if (!GetTokenInformation (hToken ,
857
864
TokenUser ,
858
- pTokenUser ,
865
+ * ppTokenUser ,
859
866
dwLength ,
860
867
& dwLength ))
861
868
{
862
- HeapFree ( GetProcessHeap (), 0 , pTokenUser );
863
- pTokenUser = NULL ;
869
+ LocalFree ( * ppTokenUser );
870
+ * ppTokenUser = NULL ;
864
871
865
872
log_error ("could not get token information: %lu" , GetLastError ());
866
873
return FALSE;
867
874
}
868
875
869
- * ppSidUser = pTokenUser -> User . Sid ;
876
+ /* Memory in *ppTokenUser is LocalFree():d by the caller */
870
877
return TRUE;
871
878
}
872
879
0 commit comments