This issue is linked with #347 and #348.
I propose adding a function to smbclient to facilitate the retrieval of a security descriptor:
def function get_security_descriptor(path, file_type: FileType = "file") -> SMB2CreateSDBuffer:
def get_sd(fd: Open, info: int) -> SMB2CreateSDBuffer:
""" Get the Security Descriptor for the opened file. """
query_req = SMB2QueryInfoRequest()
query_req['info_type'] = InfoType.SMB2_0_INFO_SECURITY
query_req['output_buffer_length'] = 65535
query_req['additional_information'] = info
query_req['file_id'] = fd.file_id
req = fd.connection.send(query_req, sid=fd.tree_connect.session.session_id, tid=fd.tree_connect.tree_connect_id)
resp = fd.connection.receive(req)
query_resp = SMB2QueryInfoResponse()
query_resp.unpack(resp['data'].get_value())
security_descriptor = SMB2CreateSDBuffer()
security_descriptor.unpack(query_resp['buffer'].get_value())
return security_descriptor
with smbclient.open_file(
path,
mode='rb',
buffering=0,
file_type=file_type,
desired_access=FilePipePrinterAccessMask.READ_CONTROL
) as file:
return get_sd(file.fd, InfoAdditionalInformation.OWNER_SECURTIY_INFORMATION | InfoAdditionalInformation.DACL_SECURITY_INFORMATION)
This issue is linked with #347 and #348.
I propose adding a function to smbclient to facilitate the retrieval of a security descriptor: