Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 #include <Windows.h> | 1 #include <Windows.h> |
2 #include <Lmcons.h> | 2 #include <Lmcons.h> |
3 #include <Sddl.h> | 3 #include <Sddl.h> |
4 #include <aclapi.h> | 4 #include <aclapi.h> |
5 #include <strsafe.h> | 5 #include <strsafe.h> |
6 | 6 |
7 #include "AutoHandle.h" | 7 #include "AutoHandle.h" |
8 #include "Communication.h" | 8 #include "Communication.h" |
9 #include "Utils.h" | 9 #include "Utils.h" |
10 | 10 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 PACL acl = 0; | 101 PACL acl = 0; |
102 if (SetEntriesInAcl(2, explicitAccess, 0, &acl) != ERROR_SUCCESS) | 102 if (SetEntriesInAcl(2, explicitAccess, 0, &acl) != ERROR_SUCCESS) |
103 return std::auto_ptr<SECURITY_DESCRIPTOR>(0); | 103 return std::auto_ptr<SECURITY_DESCRIPTOR>(0); |
104 | 104 |
105 // NOTE: This only references the acl, not copies it. | 105 // NOTE: This only references the acl, not copies it. |
106 // DO NOT release the ACL before it's actually used | 106 // DO NOT release the ACL before it's actually used |
107 if (!SetSecurityDescriptorDacl(securityDescriptor.get(), TRUE, acl, FALSE) ) | 107 if (!SetSecurityDescriptorDacl(securityDescriptor.get(), TRUE, acl, FALSE) ) |
108 return std::auto_ptr<SECURITY_DESCRIPTOR>(0); | 108 return std::auto_ptr<SECURITY_DESCRIPTOR>(0); |
109 } | 109 } |
110 | 110 |
111 // Create a dummy security descriptor with low integrirty preset and reffere nce its SACL in ours | 111 // Create a dummy security descriptor with low integrirty preset and referen ce its SACL in ours |
Felix Dahlke
2014/07/16 14:40:03
s/refference/reference/
Oleksandr
2014/07/17 17:32:48
Um. Refference is meant to be a verb here.
On 201
Felix Dahlke
2014/07/18 12:40:57
But it's still one f too many! :)
Oleksandr
2014/07/18 12:48:34
Oh. Totally missread your correction.
On 2014/07/
| |
112 LPCWSTR accessControlEntry = L"S:(ML;;NW;;;LW)"; | 112 LPCWSTR accessControlEntry = L"S:(ML;;NW;;;LW)"; |
113 PSECURITY_DESCRIPTOR dummySecurityDescriptorLow; | 113 PSECURITY_DESCRIPTOR dummySecurityDescriptorLow; |
114 ConvertStringSecurityDescriptorToSecurityDescriptorW(accessControlEntry, SDD L_REVISION_1, &dummySecurityDescriptorLow, 0); | 114 ConvertStringSecurityDescriptorToSecurityDescriptorW(accessControlEntry, SDD L_REVISION_1, &dummySecurityDescriptorLow, 0); |
115 std::tr1::shared_ptr<SECURITY_DESCRIPTOR> sharedDummySecurityDescriptor(stat ic_cast<SECURITY_DESCRIPTOR*>(dummySecurityDescriptorLow), LocalFree); // Just t o simplify cleanup | 115 std::tr1::shared_ptr<SECURITY_DESCRIPTOR> sharedDummySecurityDescriptor(stat ic_cast<SECURITY_DESCRIPTOR*>(dummySecurityDescriptorLow), LocalFree); // Just t o simplify cleanup |
116 | 116 |
117 DWORD sdSize, saclSize, daclSize, ownerSize, primaryGroupSize; | 117 DWORD sdSize(0), saclSize(0), daclSize(0), ownerSize(0), primaryGroupSize(0) ; |
Felix Dahlke
2014/07/16 14:40:03
Shouldn't we initialise all the sizes to 0 here? S
| |
118 MakeAbsoluteSD(dummySecurityDescriptorLow, 0, &sdSize, 0, &daclSize, 0, &sac lSize, 0, &ownerSize, 0, &primaryGroupSize); | 118 MakeAbsoluteSD(dummySecurityDescriptorLow, 0, &sdSize, 0, &daclSize, 0, &sac lSize, 0, &ownerSize, 0, &primaryGroupSize); |
119 if ((saclSize == 0) || (sdSize == 0)) | 119 if (saclSize == 0 || sdSize == 0) |
Felix Dahlke
2014/07/16 14:40:03
Redundant parentheses around both comparisons.
| |
120 { | 120 { |
121 DWORD err = GetLastError(); | |
Felix Dahlke
2014/07/16 14:40:03
Unused variable.
| |
122 return std::auto_ptr<SECURITY_DESCRIPTOR>(0); | 121 return std::auto_ptr<SECURITY_DESCRIPTOR>(0); |
123 } | 122 } |
124 // Will be released later | 123 // Will be released later |
125 PACL sacl = (PACL) new byte[saclSize]; | 124 PACL sacl = static_cast<PACL>(malloc(saclSize)); |
Felix Dahlke
2014/07/16 14:40:03
I'd actually find malloc more intuitive here. byte
| |
126 std::auto_ptr<SECURITY_DESCRIPTOR> absoluteDummySecurityDescriptorLow((SECUR ITY_DESCRIPTOR*) new byte[sdSize]); | 125 std::auto_ptr<SECURITY_DESCRIPTOR> absoluteDummySecurityDescriptorLow(static _cast<SECURITY_DESCRIPTOR*>(malloc(sdSize))); |
127 daclSize = 0; | 126 daclSize = 0; |
128 ownerSize = 0; | 127 ownerSize = 0; |
129 primaryGroupSize = 0; | 128 primaryGroupSize = 0; |
130 BOOL res = MakeAbsoluteSD(dummySecurityDescriptorLow, absoluteDummySecurityD escriptorLow.get(), &sdSize, 0, &daclSize, sacl, &saclSize, 0, &ownerSize, 0, &p rimaryGroupSize); | 129 BOOL res = MakeAbsoluteSD(dummySecurityDescriptorLow, absoluteDummySecurityD escriptorLow.get(), &sdSize, 0, &daclSize, sacl, &saclSize, 0, &ownerSize, 0, &p rimaryGroupSize); |
131 if ((res == 0) || (absoluteDummySecurityDescriptorLow.get() == 0) || (saclSi ze == 0)) | 130 if (res == 0 || absoluteDummySecurityDescriptorLow.get() == 0 || saclSize == 0) |
Felix Dahlke
2014/07/16 14:40:03
Redundant parentheses here as well.
Also, !res wo
| |
132 { | 131 { |
133 DWORD err = GetLastError(); | |
Felix Dahlke
2014/07/16 14:40:03
Also unused.
| |
134 return std::auto_ptr<SECURITY_DESCRIPTOR>(0); | 132 return std::auto_ptr<SECURITY_DESCRIPTOR>(0); |
135 } | 133 } |
136 | 134 |
137 // NOTE: This only references the acl, not copies it. | 135 // NOTE: This only references the acl, not copies it. |
138 // DO NOT release the ACL before it's actually used | 136 // DO NOT release the ACL before it's actually used |
139 if (!SetSecurityDescriptorSacl(securityDescriptor.get(), TRUE, sacl, FALSE)) | 137 if (!SetSecurityDescriptorSacl(securityDescriptor.get(), TRUE, sacl, FALSE)) |
140 { | 138 { |
141 DWORD err = GetLastError(); | |
142 return std::auto_ptr<SECURITY_DESCRIPTOR>(0); | 139 return std::auto_ptr<SECURITY_DESCRIPTOR>(0); |
143 } | 140 } |
144 | 141 |
145 return securityDescriptor; | 142 return securityDescriptor; |
146 } | 143 } |
147 } | 144 } |
148 | 145 |
149 const std::wstring Communication::pipeName = L"\\\\.\\pipe\\adblockplusengine_" + GetUserName(); | 146 const std::wstring Communication::pipeName = L"\\\\.\\pipe\\adblockplusengine_" + GetUserName(); |
150 | 147 |
151 void Communication::InputBuffer::CheckType(Communication::ValueType expectedType ) | 148 void Communication::InputBuffer::CheckType(Communication::ValueType expectedType ) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 { | 188 { |
192 BOOL aclPresent = FALSE; | 189 BOOL aclPresent = FALSE; |
193 BOOL aclDefaulted = FALSE; | 190 BOOL aclDefaulted = FALSE; |
194 PACL acl = 0; | 191 PACL acl = 0; |
195 GetSecurityDescriptorDacl(securityDescriptor, &aclPresent, &acl, &aclDefaulted ); | 192 GetSecurityDescriptorDacl(securityDescriptor, &aclPresent, &acl, &aclDefaulted ); |
196 if (aclPresent) | 193 if (aclPresent) |
197 { | 194 { |
198 LocalFree(acl); | 195 LocalFree(acl); |
199 } | 196 } |
200 aclPresent = FALSE; | 197 aclPresent = FALSE; |
201 aclDefaulted = false; | 198 aclDefaulted = FALSE; |
Felix Dahlke
2014/07/16 14:40:03
Should also be that Windows FALSE macro for consis
| |
202 acl = 0; | 199 acl = 0; |
203 GetSecurityDescriptorSacl(securityDescriptor, &aclPresent, &acl, &aclDefaulted ); | 200 GetSecurityDescriptorSacl(securityDescriptor, &aclPresent, &acl, &aclDefaulted ); |
204 if (aclPresent) | 201 if (aclPresent) |
205 { | 202 { |
206 delete acl; | 203 free(acl); |
Felix Dahlke
2014/07/16 14:40:03
You need to use delete[], since it was allocated u
| |
207 } | 204 } |
208 delete securityDescriptor; | 205 free(securityDescriptor); |
209 } | 206 } |
210 | 207 |
211 Communication::Pipe::Pipe(const std::wstring& pipeName, Communication::Pipe::Mod e mode) | 208 Communication::Pipe::Pipe(const std::wstring& pipeName, Communication::Pipe::Mod e mode) |
212 { | 209 { |
213 pipe = INVALID_HANDLE_VALUE; | 210 pipe = INVALID_HANDLE_VALUE; |
214 if (mode == MODE_CREATE) | 211 if (mode == MODE_CREATE) |
215 { | 212 { |
216 SECURITY_ATTRIBUTES securityAttributes = {}; | 213 SECURITY_ATTRIBUTES securityAttributes = {}; |
217 securityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES); | 214 securityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES); |
218 securityAttributes.bInheritHandle = TRUE; | 215 securityAttributes.bInheritHandle = TRUE; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 return Communication::InputBuffer(stream.str()); | 292 return Communication::InputBuffer(stream.str()); |
296 } | 293 } |
297 | 294 |
298 void Communication::Pipe::WriteMessage(Communication::OutputBuffer& message) | 295 void Communication::Pipe::WriteMessage(Communication::OutputBuffer& message) |
299 { | 296 { |
300 DWORD bytesWritten; | 297 DWORD bytesWritten; |
301 std::string data = message.Get(); | 298 std::string data = message.Get(); |
302 if (!WriteFile(pipe, data.c_str(), static_cast<DWORD>(data.length()), &bytesWr itten, 0)) | 299 if (!WriteFile(pipe, data.c_str(), static_cast<DWORD>(data.length()), &bytesWr itten, 0)) |
303 throw std::runtime_error("Failed to write to pipe"); | 300 throw std::runtime_error("Failed to write to pipe"); |
304 } | 301 } |
LEFT | RIGHT |