Open a file/pipe by its name :param name: the name of the file or named pipe. e.g. 'srvsvc'
(
self,
name,
mode="r",
type="pipe",
extra_create_options=[],
extra_desired_access=[],
)
| 761 | raise ValueError("Failed TreeDisconnect ! %s" % resp.NTStatus) |
| 762 | |
| 763 | def create_request( |
| 764 | self, |
| 765 | name, |
| 766 | mode="r", |
| 767 | type="pipe", |
| 768 | extra_create_options=[], |
| 769 | extra_desired_access=[], |
| 770 | ): |
| 771 | """ |
| 772 | Open a file/pipe by its name |
| 773 | |
| 774 | :param name: the name of the file or named pipe. e.g. 'srvsvc' |
| 775 | """ |
| 776 | ShareAccess = [] |
| 777 | DesiredAccess = [] |
| 778 | # Common params depending on the access |
| 779 | if "r" in mode: |
| 780 | ShareAccess.append("FILE_SHARE_READ") |
| 781 | DesiredAccess.extend(["FILE_READ_DATA", "FILE_READ_ATTRIBUTES"]) |
| 782 | if "w" in mode: |
| 783 | ShareAccess.append("FILE_SHARE_WRITE") |
| 784 | DesiredAccess.extend(["FILE_WRITE_DATA", "FILE_WRITE_ATTRIBUTES"]) |
| 785 | if "d" in mode: |
| 786 | ShareAccess.append("FILE_SHARE_DELETE") |
| 787 | # Params depending on the type |
| 788 | FileAttributes = [] |
| 789 | CreateOptions = [] |
| 790 | CreateContexts = [] |
| 791 | CreateDisposition = "FILE_OPEN" |
| 792 | if type == "folder": |
| 793 | FileAttributes.append("FILE_ATTRIBUTE_DIRECTORY") |
| 794 | CreateOptions.append("FILE_DIRECTORY_FILE") |
| 795 | elif type in ["file", "pipe"]: |
| 796 | CreateOptions = ["FILE_NON_DIRECTORY_FILE"] |
| 797 | if "r" in mode: |
| 798 | DesiredAccess.extend(["FILE_READ_EA", "READ_CONTROL", "SYNCHRONIZE"]) |
| 799 | if "w" in mode: |
| 800 | CreateDisposition = "FILE_OVERWRITE_IF" |
| 801 | DesiredAccess.append("FILE_WRITE_EA") |
| 802 | if "d" in mode: |
| 803 | DesiredAccess.append("DELETE") |
| 804 | CreateOptions.append("FILE_DELETE_ON_CLOSE") |
| 805 | if type == "file": |
| 806 | FileAttributes.append("FILE_ATTRIBUTE_NORMAL") |
| 807 | elif type: |
| 808 | raise ValueError("Unknown type: %s" % type) |
| 809 | # [MS-SMB2] 3.2.4.3.8 |
| 810 | RequestedOplockLevel = 0 |
| 811 | if self.session.Dialect >= 0x0300: |
| 812 | RequestedOplockLevel = "SMB2_OPLOCK_LEVEL_LEASE" |
| 813 | elif self.session.Dialect >= 0x0210 and type == "file": |
| 814 | RequestedOplockLevel = "SMB2_OPLOCK_LEVEL_LEASE" |
| 815 | # SMB 3.X |
| 816 | if self.session.Dialect >= 0x0300 and type in ["file", "folder"]: |
| 817 | CreateContexts.extend( |
| 818 | [ |
| 819 | # [SMB2] sect 3.2.4.3.5 |
| 820 | SMB2_Create_Context( |
no test coverage detected