MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / from_bytes

Method from_bytes

pager_lib/smb/security_descriptors.py:233–278  ·  view source on GitHub ↗
(cls, data)

Source from the content-addressed store, hash-verified

231
232 @classmethod
233 def from_bytes(cls, data):
234 header_size = struct.calcsize(cls.HEADER_FORMAT)
235 header = data[:header_size]
236 type_, flags, size = struct.unpack(cls.HEADER_FORMAT, header)
237
238 assert len(data) >= size
239
240 body = data[header_size:size]
241 additional_data = {}
242
243 # In all ACE types, the mask immediately follows the header.
244 mask = struct.unpack('<I', body[:4])[0]
245 body = body[4:]
246
247 # All OBJECT-type ACEs contain additional flags, and two GUIDs as
248 # the following fields.
249 if type_ in (ACE_TYPE_ACCESS_ALLOWED_OBJECT,
250 ACE_TYPE_ACCESS_DENIED_OBJECT,
251 ACE_TYPE_ACCESS_ALLOWED_CALLBACK_OBJECT,
252 ACE_TYPE_ACCESS_DENIED_CALLBACK_OBJECT,
253 ACE_TYPE_SYSTEM_AUDIT_OBJECT,
254 ACE_TYPE_SYSTEM_AUDIT_CALLBACK_OBJECT):
255 additional_data['flags'] = struct.unpack('<I', body[:4])[0]
256 additional_data['object_type'] = body[4:20]
257 additional_data['inherited_object_type'] = body[20:36]
258 body = body[36:]
259
260 # Then the SID in all types.
261 sid, body = SID.from_bytes(body, return_tail=True)
262
263 # CALLBACK-type ACEs (and for some obscure reason,
264 # SYSTEM_AUDIT_OBJECT) have a final tail of application data.
265 if type_ in (ACE_TYPE_ACCESS_ALLOWED_CALLBACK,
266 ACE_TYPE_ACCESS_DENIED_CALLBACK,
267 ACE_TYPE_ACCESS_ALLOWED_CALLBACK_OBJECT,
268 ACE_TYPE_ACCESS_DENIED_CALLBACK_OBJECT,
269 ACE_TYPE_SYSTEM_AUDIT_OBJECT,
270 ACE_TYPE_SYSTEM_AUDIT_CALLBACK,
271 ACE_TYPE_SYSTEM_AUDIT_CALLBACK_OBJECT):
272 additional_data['application_data'] = body
273
274 # SYSTEM_RESOURCE_ATTRIBUTE ACEs have a tail of attribute data.
275 if type_ == ACE_TYPE_SYSTEM_RESOURCE_ATTRIBUTE:
276 additional_data['attribute_data'] = body
277
278 return cls(type_, flags, mask, sid, additional_data)
279
280
281class ACL(object):

Callers

nothing calls this directly

Calls 1

from_bytesMethod · 0.45

Tested by

no test coverage detected