@@ -67,15 +67,30 @@ class SecurityAttributes
6767 explicit SecurityAttributes (MemoryPool& pool)
6868 : m_pool(pool)
6969 {
70+ attributes.nLength = sizeof (attributes);
71+ attributes.lpSecurityDescriptor = NULL ;
72+ attributes.bInheritHandle = TRUE ;
73+
74+ static bool initializing = false ;
75+
76+ // initializing == true means recursive call of SecurityAttributes constructor.
77+ // It happens if first instance throws an exception and handling code accesses
78+ // SecurityAttributes. Avoid recursion and leave null at attributes.lpSecurityDescriptor
79+ // in this case.
80+
81+ if (initializing)
82+ return ;
83+
84+ initializing = true ;
85+
7086 // Ensure that our process has the SYNCHRONIZE privilege granted to everyone
7187 PSECURITY_DESCRIPTOR pOldSD = NULL ;
7288 PACL pOldACL = NULL ;
7389
7490 // Pseudo-handles do not work on WinNT. Need real process handle.
75- HANDLE hCurrentProcess = OpenProcess (READ_CONTROL | WRITE_DAC , FALSE , GetCurrentProcessId ());
76- if (hCurrentProcess == NULL ) {
77- Firebird::system_call_failed::raise (" OpenProcess" );
78- }
91+ // hvlad: it have PROCESS_ALL_ACCESS access right since Vista, also it is not
92+ // affected by impersonation
93+ HANDLE hCurrentProcess = GetCurrentProcess ();
7994
8095 DWORD result = GetSecurityInfo (hCurrentProcess, SE_KERNEL_OBJECT , DACL_SECURITY_INFORMATION ,
8196 NULL , NULL , &pOldACL, NULL , &pOldSD);
@@ -88,10 +103,7 @@ class SecurityAttributes
88103 }
89104
90105 if (result != ERROR_SUCCESS )
91- {
92- CloseHandle (hCurrentProcess);
93106 Firebird::system_call_failed::raise (" GetSecurityInfo" , result);
94- }
95107
96108 // NULL pOldACL means all privileges. If we assign pNewACL in this case
97109 // we'll lost all privileges except assigned SYNCHRONIZE
@@ -117,19 +129,15 @@ class SecurityAttributes
117129 SetSecurityInfo (hCurrentProcess, SE_KERNEL_OBJECT , DACL_SECURITY_INFORMATION ,
118130 NULL , NULL , pNewACL, NULL );
119131
120- if (pSID) {
132+ if (pSID)
121133 FreeSid (pSID);
122- }
123- if (pNewACL) {
134+
135+ if (pNewACL)
124136 LocalFree (pNewACL);
125- }
126137 }
127138
128- CloseHandle (hCurrentProcess);
129-
130- if (pOldSD) {
139+ if (pOldSD)
131140 LocalFree (pOldSD);
132- }
133141
134142 // Create and initialize the default security descriptor
135143 // to be assigned to various IPC objects.
@@ -140,16 +148,16 @@ class SecurityAttributes
140148 PSECURITY_DESCRIPTOR p_security_desc = static_cast <PSECURITY_DESCRIPTOR >(
141149 FB_NEW_POOL (m_pool) char [SECURITY_DESCRIPTOR_MIN_LENGTH ]);
142150
143- attributes.nLength = sizeof (attributes);
144- attributes.lpSecurityDescriptor = p_security_desc;
145- attributes.bInheritHandle = TRUE ;
146-
147151 if (!InitializeSecurityDescriptor (p_security_desc, SECURITY_DESCRIPTOR_REVISION ) ||
148152 !SetSecurityDescriptorDacl (p_security_desc, TRUE , NULL , FALSE ))
149153 {
150154 delete p_security_desc;
151- attributes.lpSecurityDescriptor = NULL ;
152155 }
156+ else
157+ {
158+ attributes.lpSecurityDescriptor = p_security_desc;
159+ }
160+ initializing = false ;
153161 }
154162
155163 ~SecurityAttributes ()
0 commit comments