(self, req)
| 14 | class SMBHandler(urllib.request.BaseHandler): |
| 15 | |
| 16 | def smb_open(self, req): |
| 17 | global USE_NTLM, MACHINE_NAME |
| 18 | |
| 19 | if not req.host: |
| 20 | raise urllib.error.URLError('SMB error: no host given') |
| 21 | host, port = splitport(req.host) |
| 22 | if port is None: |
| 23 | port = 139 |
| 24 | else: |
| 25 | port = int(port) |
| 26 | |
| 27 | # username/password handling |
| 28 | |
| 29 | user, host = splituser(host) |
| 30 | |
| 31 | if user: |
| 32 | user, passwd = splitpasswd(user) |
| 33 | else: |
| 34 | passwd = None |
| 35 | |
| 36 | host = unquote(host) |
| 37 | user = user or '' |
| 38 | |
| 39 | domain = '' |
| 40 | if ';' in user: |
| 41 | domain, user = user.split(';', 1) |
| 42 | |
| 43 | passwd = passwd or '' |
| 44 | myname = MACHINE_NAME or self.generateClientMachineName() |
| 45 | |
| 46 | server_name,host = host.split(',') if ',' in host else [None,host] |
| 47 | |
| 48 | if server_name is None: |
| 49 | n = NetBIOS() |
| 50 | |
| 51 | names = n.queryIPForName(host) |
| 52 | if names: |
| 53 | server_name = names[0] |
| 54 | else: |
| 55 | raise urllib.error.URLError('SMB error: Hostname does not reply back with its machine name') |
| 56 | |
| 57 | path, attrs = splitattr(req.selector) |
| 58 | if path.startswith('/'): |
| 59 | path = path[1:] |
| 60 | dirs = path.split('/') |
| 61 | dirs = list(map(unquote, dirs)) |
| 62 | service, path = dirs[0], '/'.join(dirs[1:]) |
| 63 | |
| 64 | try: |
| 65 | conn = SMBConnection(user, passwd, myname, server_name, domain=domain, use_ntlm_v2 = USE_NTLM) |
| 66 | conn.connect(host, port) |
| 67 | |
| 68 | headers = email.message.Message() |
| 69 | if req.data: |
| 70 | filelen = conn.storeFile(service, path, req.data) |
| 71 | |
| 72 | headers.add_header('Content-length', '0') |
| 73 | fp = BytesIO(b"") |
nothing calls this directly
no test coverage detected